Favivon - Correção

This commit is contained in:
2026-05-30 19:59:39 -03:00
parent 76ddaa815d
commit d7dfd221f0
32859 changed files with 5459654 additions and 404 deletions
+244
View File
@@ -0,0 +1,244 @@
'use strict';
var objectSpread2 = require('./objectSpread2-2ccd0bad.cjs.prod.js');
var triangle_dist_maathTriangle = require('./triangle-9e5a8229.cjs.prod.js');
var THREE = require('three');
var misc_dist_maathMisc = require('./misc-023d073b.cjs.prod.js');
var vector2_dist_maathVector2 = require('./vector2-49e42f03.cjs.prod.js');
var vector3_dist_maathVector3 = require('./vector3-4bbdb053.cjs.prod.js');
function swizzle(buffer) {
var stride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
var swizzle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "xyz";
var o = {
x: 0,
y: 0,
z: 0
};
for (var _i = 0; _i < buffer.length; _i += stride) {
o.x = buffer[_i];
o.y = buffer[_i + 1];
o.z = buffer[_i + 2];
var _swizzle$split = swizzle.split(""),
_swizzle$split2 = triangle_dist_maathTriangle._slicedToArray(_swizzle$split, 3),
x = _swizzle$split2[0],
y = _swizzle$split2[1],
z = _swizzle$split2[2]; // TODO Fix this ugly type
buffer[_i] = o[x];
buffer[_i + 1] = o[y];
if (stride === 3) {
buffer[_i + 2] = o[z];
}
}
return buffer;
}
/**
* @param buffer A stride 2 points buffer
* @param valueGenerator A function that returns the value of the z axis at index i
* @returns
*/
function addAxis(buffer, size) {
var valueGenerator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
return Math.random();
};
var newSize = size + 1;
var newBuffer = new Float32Array(buffer.length / size * newSize);
for (var _i2 = 0; _i2 < buffer.length; _i2 += size) {
var _j = _i2 / size * newSize;
newBuffer[_j] = buffer[_i2];
newBuffer[_j + 1] = buffer[_i2 + 1];
if (size === 2) {
newBuffer[_j + 2] = valueGenerator(_j);
}
if (size === 3) {
newBuffer[_j + 2] = buffer[_i2 + 2];
newBuffer[_j + 3] = valueGenerator(_j);
}
}
return newBuffer;
}
/**
* Lerps bufferA and bufferB into final
*
* @param bufferA
* @param bufferB
* @param final
* @param t
*/
function lerp(bufferA, bufferB, _final, t) {
for (var _i3 = 0; _i3 < bufferA.length; _i3++) {
_final[_i3] = misc_dist_maathMisc.lerp(bufferA[_i3], bufferB[_i3], t);
}
} // TODO add stride
// TODO Fix types & vectors
/**
*
* Translate all points in the passed buffer by the passed translactionVector.
*
* @param buffer
* @param translationVector
* @returns
*/
function translate(buffer, translationVector) {
var stride = translationVector.length;
for (var _i4 = 0; _i4 < buffer.length; _i4 += stride) {
buffer[_i4] += translationVector[0];
buffer[_i4 + 1] += translationVector[1];
buffer[_i4 + 2] += translationVector[2];
}
return buffer;
} // TODO add stride
// TODO remove quaternion & vector3 dependencies
function rotate(buffer, rotation) {
var defaultRotation = {
center: [0, 0, 0],
q: new THREE.Quaternion().identity()
};
var v = new THREE.Vector3();
var _defaultRotation$rota = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultRotation), rotation),
q = _defaultRotation$rota.q,
center = _defaultRotation$rota.center;
for (var _i5 = 0; _i5 < buffer.length; _i5 += 3) {
v.set(buffer[_i5] - center[0], buffer[_i5 + 1] - center[1], buffer[_i5 + 2] - center[2]);
v.applyQuaternion(q);
buffer[_i5] = v.x + center[0];
buffer[_i5 + 1] = v.y + center[1];
buffer[_i5 + 2] = v.z + center[1];
}
return buffer;
}
function map(buffer, stride, callback) {
for (var _i6 = 0, _j2 = 0; _i6 < buffer.length; _i6 += stride, _j2++) {
if (stride === 3) {
var res = callback([buffer[_i6], buffer[_i6 + 1], buffer[_i6 + 2]], _j2);
buffer.set(res, _i6);
} else {
buffer.set(callback([buffer[_i6], buffer[_i6 + 1]], _j2), _i6);
}
}
return buffer;
}
/**
* Reduces passed buffer
*/
function reduce(b, stride, callback, acc) {
for (var _i7 = 0, _j3 = 0; _i7 < b.length; _i7 += stride, _j3++) {
if (stride === 2) {
acc = callback(acc, [b[_i7], b[_i7 + 1]], _j3);
} else {
acc = callback(acc, [b[_i7], b[_i7 + 1], b[_i7 + 2]], _j3);
}
}
return acc;
}
function expand(b, stride, opts) {
var defaultExpandOptions = {
center: [0, 0, 0]
};
var _defaultExpandOptions = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultExpandOptions), opts),
center = _defaultExpandOptions.center,
distance = _defaultExpandOptions.distance;
for (var _i8 = 0; _i8 < b.length; _i8 += stride) {
/**
* 1. translate to origin (subtract the scaling center)
* 2. scale by the correct amount (multiply by a constant)
* 2. translate from origin (add the scaling center)
*/
b[_i8] = (b[_i8] - center[0]) * (1 + distance) + center[0];
b[_i8 + 1] = (b[_i8 + 1] - center[1]) * (1 + distance) + center[1];
if (stride === 3) {
b[_i8 + 2] = (b[_i8 + 2] - center[1]) * (1 + distance) + center[2];
}
}
return b;
}
function center(myBuffer, stride) {
return reduce(myBuffer, stride, function (acc, point) {
if (stride === 3) {
// some type hacking is necessary to avoid type errors going from [n, n] => [n, n, n]
// but it's not an actual problem, as this path would always get a v3
acc = vector3_dist_maathVector3.add(acc, point);
} else {
acc = vector2_dist_maathVector2.add(acc, point);
}
return acc;
}, vector2_dist_maathVector2.zero());
}
function sort(myBuffer, stride, callback) {
// 1. make an array of the correct size
var indices = Int16Array.from({
length: myBuffer.length / stride
}, function (_, i) {
return i;
}); // 2. sort the indices array
indices.sort(function (a, b) {
var pa = myBuffer.slice(a * stride, a * stride + stride);
var pb = myBuffer.slice(b * stride, b * stride + stride);
return callback(pa, pb);
}); // 3. make a copy of the original array to fetch indices from
var prevBuffer = myBuffer.slice(0); // 4. mutate the passed array
for (var _i9 = 0; _i9 < indices.length; _i9++) {
var _j4 = indices[_i9];
myBuffer.set(prevBuffer.slice(_j4 * stride, _j4 * stride + stride), _i9 * 3);
}
return myBuffer;
}
var buffer = /*#__PURE__*/Object.freeze({
__proto__: null,
swizzle: swizzle,
addAxis: addAxis,
lerp: lerp,
translate: translate,
rotate: rotate,
map: map,
reduce: reduce,
expand: expand,
center: center,
sort: sort
});
exports.addAxis = addAxis;
exports.buffer = buffer;
exports.center = center;
exports.expand = expand;
exports.lerp = lerp;
exports.map = map;
exports.reduce = reduce;
exports.rotate = rotate;
exports.sort = sort;
exports.swizzle = swizzle;
exports.translate = translate;
+232
View File
@@ -0,0 +1,232 @@
import { _ as _objectSpread2 } from './objectSpread2-284232a6.esm.js';
import { _ as _slicedToArray } from './triangle-b62b9067.esm.js';
import { Quaternion, Vector3 } from 'three';
import { l as lerp$1 } from './misc-19a3ec46.esm.js';
import { z as zero, a as add$1 } from './vector2-d2bf51f1.esm.js';
import { a as add } from './vector3-0a088b7f.esm.js';
function swizzle(buffer) {
var stride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
var swizzle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "xyz";
var o = {
x: 0,
y: 0,
z: 0
};
for (var _i = 0; _i < buffer.length; _i += stride) {
o.x = buffer[_i];
o.y = buffer[_i + 1];
o.z = buffer[_i + 2];
var _swizzle$split = swizzle.split(""),
_swizzle$split2 = _slicedToArray(_swizzle$split, 3),
x = _swizzle$split2[0],
y = _swizzle$split2[1],
z = _swizzle$split2[2]; // TODO Fix this ugly type
buffer[_i] = o[x];
buffer[_i + 1] = o[y];
if (stride === 3) {
buffer[_i + 2] = o[z];
}
}
return buffer;
}
/**
* @param buffer A stride 2 points buffer
* @param valueGenerator A function that returns the value of the z axis at index i
* @returns
*/
function addAxis(buffer, size) {
var valueGenerator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
return Math.random();
};
var newSize = size + 1;
var newBuffer = new Float32Array(buffer.length / size * newSize);
for (var _i2 = 0; _i2 < buffer.length; _i2 += size) {
var _j = _i2 / size * newSize;
newBuffer[_j] = buffer[_i2];
newBuffer[_j + 1] = buffer[_i2 + 1];
if (size === 2) {
newBuffer[_j + 2] = valueGenerator(_j);
}
if (size === 3) {
newBuffer[_j + 2] = buffer[_i2 + 2];
newBuffer[_j + 3] = valueGenerator(_j);
}
}
return newBuffer;
}
/**
* Lerps bufferA and bufferB into final
*
* @param bufferA
* @param bufferB
* @param final
* @param t
*/
function lerp(bufferA, bufferB, _final, t) {
for (var _i3 = 0; _i3 < bufferA.length; _i3++) {
_final[_i3] = lerp$1(bufferA[_i3], bufferB[_i3], t);
}
} // TODO add stride
// TODO Fix types & vectors
/**
*
* Translate all points in the passed buffer by the passed translactionVector.
*
* @param buffer
* @param translationVector
* @returns
*/
function translate(buffer, translationVector) {
var stride = translationVector.length;
for (var _i4 = 0; _i4 < buffer.length; _i4 += stride) {
buffer[_i4] += translationVector[0];
buffer[_i4 + 1] += translationVector[1];
buffer[_i4 + 2] += translationVector[2];
}
return buffer;
} // TODO add stride
// TODO remove quaternion & vector3 dependencies
function rotate(buffer, rotation) {
var defaultRotation = {
center: [0, 0, 0],
q: new Quaternion().identity()
};
var v = new Vector3();
var _defaultRotation$rota = _objectSpread2(_objectSpread2({}, defaultRotation), rotation),
q = _defaultRotation$rota.q,
center = _defaultRotation$rota.center;
for (var _i5 = 0; _i5 < buffer.length; _i5 += 3) {
v.set(buffer[_i5] - center[0], buffer[_i5 + 1] - center[1], buffer[_i5 + 2] - center[2]);
v.applyQuaternion(q);
buffer[_i5] = v.x + center[0];
buffer[_i5 + 1] = v.y + center[1];
buffer[_i5 + 2] = v.z + center[1];
}
return buffer;
}
function map(buffer, stride, callback) {
for (var _i6 = 0, _j2 = 0; _i6 < buffer.length; _i6 += stride, _j2++) {
if (stride === 3) {
var res = callback([buffer[_i6], buffer[_i6 + 1], buffer[_i6 + 2]], _j2);
buffer.set(res, _i6);
} else {
buffer.set(callback([buffer[_i6], buffer[_i6 + 1]], _j2), _i6);
}
}
return buffer;
}
/**
* Reduces passed buffer
*/
function reduce(b, stride, callback, acc) {
for (var _i7 = 0, _j3 = 0; _i7 < b.length; _i7 += stride, _j3++) {
if (stride === 2) {
acc = callback(acc, [b[_i7], b[_i7 + 1]], _j3);
} else {
acc = callback(acc, [b[_i7], b[_i7 + 1], b[_i7 + 2]], _j3);
}
}
return acc;
}
function expand(b, stride, opts) {
var defaultExpandOptions = {
center: [0, 0, 0]
};
var _defaultExpandOptions = _objectSpread2(_objectSpread2({}, defaultExpandOptions), opts),
center = _defaultExpandOptions.center,
distance = _defaultExpandOptions.distance;
for (var _i8 = 0; _i8 < b.length; _i8 += stride) {
/**
* 1. translate to origin (subtract the scaling center)
* 2. scale by the correct amount (multiply by a constant)
* 2. translate from origin (add the scaling center)
*/
b[_i8] = (b[_i8] - center[0]) * (1 + distance) + center[0];
b[_i8 + 1] = (b[_i8 + 1] - center[1]) * (1 + distance) + center[1];
if (stride === 3) {
b[_i8 + 2] = (b[_i8 + 2] - center[1]) * (1 + distance) + center[2];
}
}
return b;
}
function center(myBuffer, stride) {
return reduce(myBuffer, stride, function (acc, point) {
if (stride === 3) {
// some type hacking is necessary to avoid type errors going from [n, n] => [n, n, n]
// but it's not an actual problem, as this path would always get a v3
acc = add(acc, point);
} else {
acc = add$1(acc, point);
}
return acc;
}, zero());
}
function sort(myBuffer, stride, callback) {
// 1. make an array of the correct size
var indices = Int16Array.from({
length: myBuffer.length / stride
}, function (_, i) {
return i;
}); // 2. sort the indices array
indices.sort(function (a, b) {
var pa = myBuffer.slice(a * stride, a * stride + stride);
var pb = myBuffer.slice(b * stride, b * stride + stride);
return callback(pa, pb);
}); // 3. make a copy of the original array to fetch indices from
var prevBuffer = myBuffer.slice(0); // 4. mutate the passed array
for (var _i9 = 0; _i9 < indices.length; _i9++) {
var _j4 = indices[_i9];
myBuffer.set(prevBuffer.slice(_j4 * stride, _j4 * stride + stride), _i9 * 3);
}
return myBuffer;
}
var buffer = /*#__PURE__*/Object.freeze({
__proto__: null,
swizzle: swizzle,
addAxis: addAxis,
lerp: lerp,
translate: translate,
rotate: rotate,
map: map,
reduce: reduce,
expand: expand,
center: center,
sort: sort
});
export { addAxis as a, buffer as b, reduce as c, center as d, expand as e, sort as f, lerp as l, map as m, rotate as r, swizzle as s, translate as t };
+244
View File
@@ -0,0 +1,244 @@
'use strict';
var objectSpread2 = require('./objectSpread2-32cd2c34.cjs.dev.js');
var triangle_dist_maathTriangle = require('./triangle-33ffdfef.cjs.dev.js');
var THREE = require('three');
var misc_dist_maathMisc = require('./misc-fce4d494.cjs.dev.js');
var vector2_dist_maathVector2 = require('./vector2-f44fd63e.cjs.dev.js');
var vector3_dist_maathVector3 = require('./vector3-5e723d1a.cjs.dev.js');
function swizzle(buffer) {
var stride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
var swizzle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "xyz";
var o = {
x: 0,
y: 0,
z: 0
};
for (var _i = 0; _i < buffer.length; _i += stride) {
o.x = buffer[_i];
o.y = buffer[_i + 1];
o.z = buffer[_i + 2];
var _swizzle$split = swizzle.split(""),
_swizzle$split2 = triangle_dist_maathTriangle._slicedToArray(_swizzle$split, 3),
x = _swizzle$split2[0],
y = _swizzle$split2[1],
z = _swizzle$split2[2]; // TODO Fix this ugly type
buffer[_i] = o[x];
buffer[_i + 1] = o[y];
if (stride === 3) {
buffer[_i + 2] = o[z];
}
}
return buffer;
}
/**
* @param buffer A stride 2 points buffer
* @param valueGenerator A function that returns the value of the z axis at index i
* @returns
*/
function addAxis(buffer, size) {
var valueGenerator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
return Math.random();
};
var newSize = size + 1;
var newBuffer = new Float32Array(buffer.length / size * newSize);
for (var _i2 = 0; _i2 < buffer.length; _i2 += size) {
var _j = _i2 / size * newSize;
newBuffer[_j] = buffer[_i2];
newBuffer[_j + 1] = buffer[_i2 + 1];
if (size === 2) {
newBuffer[_j + 2] = valueGenerator(_j);
}
if (size === 3) {
newBuffer[_j + 2] = buffer[_i2 + 2];
newBuffer[_j + 3] = valueGenerator(_j);
}
}
return newBuffer;
}
/**
* Lerps bufferA and bufferB into final
*
* @param bufferA
* @param bufferB
* @param final
* @param t
*/
function lerp(bufferA, bufferB, _final, t) {
for (var _i3 = 0; _i3 < bufferA.length; _i3++) {
_final[_i3] = misc_dist_maathMisc.lerp(bufferA[_i3], bufferB[_i3], t);
}
} // TODO add stride
// TODO Fix types & vectors
/**
*
* Translate all points in the passed buffer by the passed translactionVector.
*
* @param buffer
* @param translationVector
* @returns
*/
function translate(buffer, translationVector) {
var stride = translationVector.length;
for (var _i4 = 0; _i4 < buffer.length; _i4 += stride) {
buffer[_i4] += translationVector[0];
buffer[_i4 + 1] += translationVector[1];
buffer[_i4 + 2] += translationVector[2];
}
return buffer;
} // TODO add stride
// TODO remove quaternion & vector3 dependencies
function rotate(buffer, rotation) {
var defaultRotation = {
center: [0, 0, 0],
q: new THREE.Quaternion().identity()
};
var v = new THREE.Vector3();
var _defaultRotation$rota = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultRotation), rotation),
q = _defaultRotation$rota.q,
center = _defaultRotation$rota.center;
for (var _i5 = 0; _i5 < buffer.length; _i5 += 3) {
v.set(buffer[_i5] - center[0], buffer[_i5 + 1] - center[1], buffer[_i5 + 2] - center[2]);
v.applyQuaternion(q);
buffer[_i5] = v.x + center[0];
buffer[_i5 + 1] = v.y + center[1];
buffer[_i5 + 2] = v.z + center[1];
}
return buffer;
}
function map(buffer, stride, callback) {
for (var _i6 = 0, _j2 = 0; _i6 < buffer.length; _i6 += stride, _j2++) {
if (stride === 3) {
var res = callback([buffer[_i6], buffer[_i6 + 1], buffer[_i6 + 2]], _j2);
buffer.set(res, _i6);
} else {
buffer.set(callback([buffer[_i6], buffer[_i6 + 1]], _j2), _i6);
}
}
return buffer;
}
/**
* Reduces passed buffer
*/
function reduce(b, stride, callback, acc) {
for (var _i7 = 0, _j3 = 0; _i7 < b.length; _i7 += stride, _j3++) {
if (stride === 2) {
acc = callback(acc, [b[_i7], b[_i7 + 1]], _j3);
} else {
acc = callback(acc, [b[_i7], b[_i7 + 1], b[_i7 + 2]], _j3);
}
}
return acc;
}
function expand(b, stride, opts) {
var defaultExpandOptions = {
center: [0, 0, 0]
};
var _defaultExpandOptions = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultExpandOptions), opts),
center = _defaultExpandOptions.center,
distance = _defaultExpandOptions.distance;
for (var _i8 = 0; _i8 < b.length; _i8 += stride) {
/**
* 1. translate to origin (subtract the scaling center)
* 2. scale by the correct amount (multiply by a constant)
* 2. translate from origin (add the scaling center)
*/
b[_i8] = (b[_i8] - center[0]) * (1 + distance) + center[0];
b[_i8 + 1] = (b[_i8 + 1] - center[1]) * (1 + distance) + center[1];
if (stride === 3) {
b[_i8 + 2] = (b[_i8 + 2] - center[1]) * (1 + distance) + center[2];
}
}
return b;
}
function center(myBuffer, stride) {
return reduce(myBuffer, stride, function (acc, point) {
if (stride === 3) {
// some type hacking is necessary to avoid type errors going from [n, n] => [n, n, n]
// but it's not an actual problem, as this path would always get a v3
acc = vector3_dist_maathVector3.add(acc, point);
} else {
acc = vector2_dist_maathVector2.add(acc, point);
}
return acc;
}, vector2_dist_maathVector2.zero());
}
function sort(myBuffer, stride, callback) {
// 1. make an array of the correct size
var indices = Int16Array.from({
length: myBuffer.length / stride
}, function (_, i) {
return i;
}); // 2. sort the indices array
indices.sort(function (a, b) {
var pa = myBuffer.slice(a * stride, a * stride + stride);
var pb = myBuffer.slice(b * stride, b * stride + stride);
return callback(pa, pb);
}); // 3. make a copy of the original array to fetch indices from
var prevBuffer = myBuffer.slice(0); // 4. mutate the passed array
for (var _i9 = 0; _i9 < indices.length; _i9++) {
var _j4 = indices[_i9];
myBuffer.set(prevBuffer.slice(_j4 * stride, _j4 * stride + stride), _i9 * 3);
}
return myBuffer;
}
var buffer = /*#__PURE__*/Object.freeze({
__proto__: null,
swizzle: swizzle,
addAxis: addAxis,
lerp: lerp,
translate: translate,
rotate: rotate,
map: map,
reduce: reduce,
expand: expand,
center: center,
sort: sort
});
exports.addAxis = addAxis;
exports.buffer = buffer;
exports.center = center;
exports.expand = expand;
exports.lerp = lerp;
exports.map = map;
exports.reduce = reduce;
exports.rotate = rotate;
exports.sort = sort;
exports.swizzle = swizzle;
exports.translate = translate;
+9
View File
@@ -0,0 +1,9 @@
'use strict';
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
exports._classCallCheck = _classCallCheck;
+7
View File
@@ -0,0 +1,7 @@
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
export { _classCallCheck as _ };
+9
View File
@@ -0,0 +1,9 @@
'use strict';
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
exports._classCallCheck = _classCallCheck;
+57
View File
@@ -0,0 +1,57 @@
/**
* Conventions:
* 1. try to avoid threejs dependencies, TBD how to solve them
* 2. use overload signatures to support stride 2 and 3 with ok typing
*/
import { Quaternion } from "three";
import type { TypedArray, MyVector2, MyVector3 } from "./ctypes";
import * as v2 from "./vector2";
import * as v3 from "./vector3";
export declare function swizzle(buffer: TypedArray, stride?: number, swizzle?: string): TypedArray;
/**
* @param buffer A stride 2 points buffer
* @param valueGenerator A function that returns the value of the z axis at index i
* @returns
*/
export declare function addAxis(buffer: TypedArray, size: number, valueGenerator?: (j: number) => number): TypedArray;
/**
* Lerps bufferA and bufferB into final
*
* @param bufferA
* @param bufferB
* @param final
* @param t
*/
export declare function lerp(bufferA: TypedArray, bufferB: TypedArray, final: TypedArray, t: number): void;
/**
*
* Translate all points in the passed buffer by the passed translactionVector.
*
* @param buffer
* @param translationVector
* @returns
*/
export declare function translate(buffer: TypedArray, translationVector: MyVector2 | MyVector3): TypedArray;
export declare function rotate(buffer: TypedArray, rotation: {
q: Quaternion;
center?: number[];
}): TypedArray;
export declare function map(buffer: TypedArray, stride: 2, fn: (v: v2.V2, i: number) => number[]): TypedArray;
export declare function map(buffer: TypedArray, stride: 3, fn: (v: v3.V3, i: number) => number[]): TypedArray;
/**
* Reduces passed buffer
*/
declare type IReduceCallback<T> = (final: T, point: v2.V2, i: number) => T;
export declare function reduce<T>(b: TypedArray, stride: 2, callback: IReduceCallback<T>, acc: T): T;
export declare function reduce<T>(b: TypedArray, stride: 3, callback: IReduceCallback<T>, acc: T): T;
declare type ExpandOptions = {
center?: [number, number];
distance: number;
};
export declare function expand(b: TypedArray, stride: 2 | 3, opts: ExpandOptions): TypedArray;
export declare function center(myBuffer: TypedArray, stride: 2): v2.V2;
export declare function center(myBuffer: TypedArray, stride: 3): v3.V3;
declare type ISortingCallback<T> = (a: T, b: T) => number;
export declare function sort(myBuffer: TypedArray, stride: 2, callback: ISortingCallback<v2.V2>): TypedArray;
export declare function sort(myBuffer: TypedArray, stride: 3, callback: ISortingCallback<v3.V3>): TypedArray;
export {};
+5
View File
@@ -0,0 +1,5 @@
import { Vector2 } from "three";
export declare type TypedArray = Float32Array | Float64Array;
export declare type MyVector2 = number[];
export declare type MyVector3 = number[];
export declare type Triangle = [MyVector2, MyVector2, MyVector2] | Vector2[];
+94
View File
@@ -0,0 +1,94 @@
import { Vector2, Vector3, Vector4, Euler, Color, Matrix4, Quaternion, Spherical, ColorRepresentation } from "three";
export declare const rsqw: (t: number, delta?: number, a?: number, f?: number) => number;
export declare const exp: (t: number) => number;
export declare const linear: (t: number) => number;
export declare const sine: {
in: (x: number) => number;
out: (x: number) => number;
inOut: (x: number) => number;
};
export declare const cubic: {
in: (x: number) => number;
out: (x: number) => number;
inOut: (x: number) => number;
};
export declare const quint: {
in: (x: number) => number;
out: (x: number) => number;
inOut: (x: number) => number;
};
export declare const circ: {
in: (x: number) => number;
out: (x: number) => number;
inOut: (x: number) => number;
};
export declare const quart: {
in: (t: number) => number;
out: (t: number) => number;
inOut: (t: number) => number;
};
export declare const expo: {
in: (x: number) => number;
out: (x: number) => number;
inOut: (x: number) => number;
};
/**
* Damp, based on Game Programming Gems 4 Chapter 1.10
* Return value indicates whether the animation is still running.
*/
export declare function damp(
/** The object */
current: {
[key: string]: any;
},
/** The key to animate */
prop: string,
/** To goal value */
target: number,
/** Approximate time to reach the target. A smaller value will reach the target faster. */
smoothTime?: number,
/** Frame delta, for refreshrate independence */
delta?: number,
/** Optionally allows you to clamp the maximum speed. If smoothTime is 0.25s and looks OK
* going between two close points but not for points far apart as it'll move very rapid,
* then a maxSpeed of e.g. 1 which will clamp the speed to 1 unit per second, it may now
* take much longer than smoothTime to reach the target if it is far away. */
maxSpeed?: number,
/** Easing function */
easing?: (t: number) => number,
/** End of animation precision */
eps?: number): boolean;
export declare function dampLookAt(current: THREE.Object3D, target: number | [x: number, y: number, z: number] | Vector3, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): void;
/**
* DampAngle, with a shortest-path
*/
export declare function dampAngle(current: {
[key: string]: any;
}, prop: string, target: number, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
export declare function damp2(current: Vector2, target: number | [x: number, y: number] | Vector2, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
export declare function damp3(current: Vector3, target: number | [x: number, y: number, z: number] | Vector3, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
export declare function damp4(current: Vector4, target: number | [x: number, y: number, z: number, w: number] | Vector4, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
declare type EulerOrder = "XYZ" | "YXZ" | "ZXY" | "ZYX" | "YZX" | "XZY";
export declare function dampE(current: Euler, target: [x: number, y: number, z: number, order?: EulerOrder] | Euler, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
export declare function dampC(current: Color, target: ColorRepresentation | [r: number, g: number, b: number], smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
export declare function dampQ(current: Quaternion, target: [x: number, y: number, z: number, w: number] | Quaternion, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
export declare function dampS(current: Spherical, target: [radius: number, phi: number, theta: number] | Spherical, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
export declare function dampM(current: Matrix4, target: [
n11: number,
n12: number,
n13: number,
n14: number,
n21: number,
n22: number,
n23: number,
n24: number,
n31: number,
n32: number,
n33: number,
n34: number,
n41: number,
n42: number,
n43: number,
n44: number
] | Matrix4, smoothTime?: number, delta?: number, maxSpeed?: number, easing?: (t: number) => number, eps?: number): boolean;
export {};
+13
View File
@@ -0,0 +1,13 @@
import * as THREE from "three";
export declare class RoundedPlaneGeometry extends THREE.BufferGeometry {
parameters: {
width: number;
height: number;
radius: number;
segments: number;
};
constructor(width?: number, height?: number, radius?: number, segments?: number);
}
export declare function applyCylindricalUV(bufferGeometry: THREE.BufferGeometry): THREE.BufferGeometry;
export declare function applySphereUV(bufferGeometry: THREE.BufferGeometry): THREE.BufferGeometry;
export declare function applyBoxUV(bufferGeometry: THREE.BufferGeometry): THREE.BufferGeometry;
+10
View File
@@ -0,0 +1,10 @@
export * as buffer from "./buffer";
export * as random from "./random";
export * as easing from "./easing";
export * as geometry from "./geometry";
export * as matrix from "./matrix";
export * as misc from "./misc";
export * as three from "./three";
export * as triangle from "./triangle";
export * as vector2 from "./vector2";
export * as vector3 from "./vector3";
+57
View File
@@ -0,0 +1,57 @@
import { Matrix3, Matrix4 } from "three";
/**
*
* @param terms
*
* | a b |
* | c d |
*
* @returns {number} determinant
*/
export declare function determinant2(...terms: number[]): number;
/**
*
* @param terms
*
* | a b c |
* | d e f |
* | g h i |
*
* @returns {number} determinant
*/
export declare function determinant3(...terms: number[]): number;
/**
*
* @param terms
*
* | a b c g |
* | h i j k |
* | l m n o |
*
* @returns {number} determinant
*/
export declare function determinant4(...terms: number[]): void;
/**
*
* Get the determinant of matrix m without row r and col c
*
* @param {matrix} m Starter matrix
* @param r row to remove
* @param c col to remove
*
* | a b c |
* m = | d e f |
* | g h i |
*
* getMinor(m, 1, 1) would result in this determinant
*
* | a c |
* | g i |
*
* @returns {number} determinant
*/
export declare function getMinor(matrix: Matrix4, r: number, c: number): number;
/**
*
*/
export declare function matrixSum3(m1: Matrix3, m2: Matrix3): Matrix3;
+96
View File
@@ -0,0 +1,96 @@
import { Matrix3, Plane, Vector2, Vector3 } from "three";
import type { TypedArray } from "./ctypes";
import { V3 } from "./vector3";
import { V2 } from "./vector2";
/**
* Clamps a value between a range.
*/
export declare function clamp(value: number, min: number, max: number): number;
export declare function repeat(t: number, length: number): number;
export declare function deltaAngle(current: number, target: number): number;
/**
* Converts degrees to radians.
*/
export declare function degToRad(degrees: number): number;
/**
* Converts radians to degrees.
*/
export declare function radToDeg(radians: number): number;
export declare function fibonacciOnSphere(buffer: TypedArray, { radius }: {
radius?: number | undefined;
}): void;
export declare function vectorEquals(a: any, b: any, eps?: number): boolean;
/**
* Sorts vectors in lexicographic order, works with both v2 and v3
*
* Use as:
* const sorted = arrayOfVectors.sort(lexicographicOrder)
*/
export declare function lexicographic(a: Vector2 | Vector3, b: Vector2 | Vector3): number;
/**
* Convex Hull
*
* Returns an array of 2D Vectors representing the convex hull of a set of 2D Vectors
*/
/**
* Calculate the convex hull of a set of points
*/
export declare function convexHull(_points: Vector2[]): Vector2[];
export declare function remap(x: number, [low1, high1]: number[], [low2, high2]: number[]): number;
/**
*
* https://www.desmos.com/calculator/vsnmlaljdu
*
* Ease-in-out, goes to -Infinite before 0 and Infinite after 1
*
* @param t
* @returns
*/
export declare function fade(t: number): number;
/**
*
* Returns the result of linearly interpolating between input A and input B by input T.
*
* @param v0
* @param v1
* @param t
* @returns
*/
export declare function lerp(v0: number, v1: number, t: number): number;
/**
*
* Returns the linear parameter that produces the interpolant specified by input T within the range of input A to input B.
*
* @param v0
* @param v1
* @param t
* @returns
*/
export declare function inverseLerp(v0: number, v1: number, t: number): number;
/**
*
*/
export declare function normalize(x: number, y: number, z: number): number[];
/**
*
*/
export declare function pointOnCubeToPointOnSphere(x: number, y: number, z: number): number[];
/**
* Give two unit vectors a and b, returns the transformation matrix that rotates a onto b.
*
* */
export declare function rotateVectorOnVector(a: Vector3, b: Vector3): Matrix3;
export declare function pointToCoordinate(x: number, y: number, z: number): number[];
export declare function coordinateToPoint(lat: number, lon: number): number[];
/**
* Given a plane and a segment, return the intersection point if it exists or null it doesn't.
*/
export declare function planeSegmentIntersection(plane: Plane, segment: Vector3[]): null | Vector3;
/**
* Given a plane and a point, return the distance.
*/
export declare function pointToPlaneDistance(p: Vector3, plane: Plane): number;
export declare function getIndexFrom3D(coords: V3, sides: V3): number;
export declare function get3DFromIndex(index: number, size: V3): V3;
export declare function getIndexFrom2D(coords: V2, size: V2): number;
export declare function get2DFromIndex(index: number, columns: number): V2;
+70
View File
@@ -0,0 +1,70 @@
import type { TypedArray } from "../ctypes";
export declare class FlashGen {
nextBurstTime: number;
nextFlashEndTime: number;
flashesDone: number;
isFlashing: boolean;
currentCount: number;
flashIntensity: number;
isDecaying: boolean;
autoBurst: boolean;
decaySpeed: number;
minInterval: number;
maxInterval: number;
minDuration: number;
maxDuration: number;
count: number;
constructor(props: {
decaySpeed?: number;
minInterval?: number;
maxInterval?: number;
minDuration?: number;
maxDuration?: number;
count?: number;
});
scheduleNextBurst(currentTime: number): void;
burst(): void;
update(currentTime: number, delta: number): number;
}
export declare class Generator {
seed: string | number;
constructor(seed: string | number);
init: (seed: number | string) => void;
value: () => number;
}
/***
* [3D] Sphere
*/
declare type Sphere = {
radius?: number;
center?: number[];
};
export declare function onSphere(buffer: TypedArray, sphere?: Sphere, rng?: Generator): TypedArray;
export declare function inSphere(buffer: TypedArray, sphere?: Sphere, rng?: Generator): TypedArray;
/***
* [2D] Circle
*/
declare type Circle = {
radius?: number;
center?: number[];
};
export declare function inCircle(buffer: TypedArray, circle?: Circle, rng?: Generator): TypedArray;
export declare function onCircle(buffer: TypedArray, circle?: Circle, rng?: Generator): TypedArray;
/**
* [2D] Plane
*/
declare type Rect = {
sides: number | number[];
};
export declare function inRect<T extends TypedArray>(buffer: T, rect?: Rect, rng?: Generator): T;
export declare function onRect(buffer: TypedArray, rect?: Rect, rng?: Generator): TypedArray;
/***
* [3D] Box
*/
export declare function inBox(buffer: TypedArray, box?: Box, rng?: Generator): TypedArray;
declare type Box = {
sides?: number[] | number;
center?: number[];
};
export declare function onBox(buffer: TypedArray, box?: Box, rng?: Generator): TypedArray;
export * as noise from "./noise";
+5
View File
@@ -0,0 +1,5 @@
export declare const seed: (seed: number) => void;
export declare const simplex2: (xin: number, yin: number) => number;
export declare const simplex3: (xin: number, yin: number, zin: number) => number;
export declare const perlin2: (x: number, y: number) => number;
export declare const perlin3: (x: number, y: number, z: number) => number;
+14
View File
@@ -0,0 +1,14 @@
import type { TypedArray } from "./ctypes";
import { Vector2, Vector3 } from "three";
/**
* Helpers for converting buffers to and from Three.js objects
*/
export declare function bufferToVectors(buffer: TypedArray, stride: 3): Vector3[];
export declare function bufferToVectors(buffer: TypedArray, stride: 2): Vector2[];
/**
* Transforms a passed Vector2 or Vector3 array to a points buffer
*
* @param vectorArray
* @returns
*/
export declare function vectorsToBuffer(vectorArray: Vector2[] | Vector3[]): Float32Array;
+73
View File
@@ -0,0 +1,73 @@
import { Vector2 } from "three";
import type { Triangle } from "./ctypes";
/**
*
* @param point
*
* @param triangle
*
* @returns {boolean} true if the point is in the triangle
*
* TODO: Find explainer
*/
export declare function isPointInTriangle(point: number[], triangle: Triangle): boolean;
export declare function triangleDeterminant(triangle: Triangle): number;
/**
* Uses triangle area determinant to check if 3 points are collinear.
* If they are, they can't make a triangle, so the determinant will be 0!
*
* 0 1 2
* ─────■─────■─────■
*
*
* Fun fact, you can use this same determinant to check the order of the points in the triangle
*
* NOTE: Should this use a buffer instead? NOTE: Should this use a buffer instead? [x0, y0, x1, y1, x2, y2]?
*
*/
export declare function arePointsCollinear(points: Triangle): boolean;
export declare function isTriangleClockwise(triangle: Triangle): boolean;
/**
The circumcircle is a circle touching all the vertices of a triangle or polygon.
┌───┐
│ B │
└───┘
.───●───.
,─' ╲ '─.
,' ╲ `.
╱ ╱ ╲ ╲
; ╲ :
│ ╱ ╲ │
│ ╱ ╲ │
: ╲ ;
╲ ╱ ╲ ╱
┌───┐ ●─────────────────● ┌───┐
│ A │ `. ,' │ C │
└───┘ '─. ,─' └───┘
`─────'
*/
/**
*
* @param triangle
*
* @returns {number} circumcircle
*/
export declare function getCircumcircle(triangle: Triangle): {
x: number;
y: number;
r: number;
} | null;
export declare function isPointInCircumcircle(point: number[], triangle: Triangle): boolean;
/**
▕ ▏
right left
* NOTE: Should this use a buffer instead? [x0, y0, x1, y1]?
*/
export declare function doThreePointsMakeARight(points: Triangle | Vector2[]): boolean;
+23
View File
@@ -0,0 +1,23 @@
/**
*
*/
export declare type V2 = [x: number, y: number];
export declare function zero(): V2;
export declare function one(): V2;
export declare function add(a: V2, b: V2): V2;
export declare function addValue(a: V2, n: number): V2;
export declare function sub(a: V2, b: V2): V2;
export declare function subValue(a: V2, n: number): V2;
export declare function scale(a: V2, n: number): V2;
export declare function dot(a: V2, b: V2): number;
/**
* Calculate the squared length of a vector.
* Use this when comparing two vectors instead of length, as it's more efficient (no sqrt)
*/
export declare function lengthSqr(a: V2): number;
/**
* Calculate the length of a vector.
* If you only need to compare lenghts, consider using the more efficient lengthSqr
*/
export declare function length(a: V2): number;
export declare function distance(a: V2, b: V2): number;
+24
View File
@@ -0,0 +1,24 @@
/**
*
*/
export declare type V3 = [x: number, y: number, z: number];
export declare function zero(): V3;
export declare function one(): V3;
export declare function add(a: V3, b: V3): V3;
export declare function addValue(a: V3, n: number): V3;
export declare function sub(a: V3, b: V3): V3;
export declare function subValue(a: V3, n: number): V3;
export declare function scale(a: V3, n: number): V3;
export declare function dot(a: V3, b: V3): number;
export declare function cross(a: V3, b: V3): V3;
/**
* Calculate the squared length of a vector.
* Use this when comparing two vectors instead of length, as it's more efficient (no sqrt)
*/
export declare function lengthSqr(a: V3): number;
/**
* Calculate the length of a vector.
* If you only need to compare lenghts, consider using the more efficient lengthSqr
*/
export declare function length(a: V3): number;
export declare function distance(a: V3, b: V3): number;
+348
View File
@@ -0,0 +1,348 @@
import { a as _toConsumableArray } from './triangle-b62b9067.esm.js';
import { Color, Vector3, Quaternion, Matrix4, Vector2, Vector4, Euler, Spherical } from 'three';
import { d as deltaAngle } from './misc-19a3ec46.esm.js';
var rsqw = function rsqw(t) {
var delta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.01;
var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
var f = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1 / (2 * Math.PI);
return a / Math.atan(1 / delta) * Math.atan(Math.sin(2 * Math.PI * t * f) / delta);
};
var exp = function exp(t) {
return 1 / (1 + t + 0.48 * t * t + 0.235 * t * t * t);
};
var linear = function linear(t) {
return t;
};
var sine = {
"in": function _in(x) {
return 1 - Math.cos(x * Math.PI / 2);
},
out: function out(x) {
return Math.sin(x * Math.PI / 2);
},
inOut: function inOut(x) {
return -(Math.cos(Math.PI * x) - 1) / 2;
}
};
var cubic = {
"in": function _in(x) {
return x * x * x;
},
out: function out(x) {
return 1 - Math.pow(1 - x, 3);
},
inOut: function inOut(x) {
return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
}
};
var quint = {
"in": function _in(x) {
return x * x * x * x * x;
},
out: function out(x) {
return 1 - Math.pow(1 - x, 5);
},
inOut: function inOut(x) {
return x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2;
}
};
var circ = {
"in": function _in(x) {
return 1 - Math.sqrt(1 - Math.pow(x, 2));
},
out: function out(x) {
return Math.sqrt(1 - Math.pow(x - 1, 2));
},
inOut: function inOut(x) {
return x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
}
};
var quart = {
"in": function _in(t) {
return t * t * t * t;
},
out: function out(t) {
return 1 - --t * t * t * t;
},
inOut: function inOut(t) {
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
}
};
var expo = {
"in": function _in(x) {
return x === 0 ? 0 : Math.pow(2, 10 * x - 10);
},
out: function out(x) {
return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
},
inOut: function inOut(x) {
return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2;
}
};
/**
* Damp, based on Game Programming Gems 4 Chapter 1.10
* Return value indicates whether the animation is still running.
*/
function damp(
/** The object */
current,
/** The key to animate */
prop,
/** To goal value */
target) {
var smoothTime = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.25;
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0.01;
var maxSpeed = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : Infinity;
var easing = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : exp;
var eps = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 0.001;
var vel = "velocity_" + prop;
if (current.__damp === undefined) current.__damp = {};
if (current.__damp[vel] === undefined) current.__damp[vel] = 0;
if (Math.abs(current[prop] - target) <= eps) {
current[prop] = target;
return false;
}
smoothTime = Math.max(0.0001, smoothTime);
var omega = 2 / smoothTime;
var t = easing(omega * delta);
var change = current[prop] - target;
var originalTo = target; // Clamp maximum maxSpeed
var maxChange = maxSpeed * smoothTime;
change = Math.min(Math.max(change, -maxChange), maxChange);
target = current[prop] - change;
var temp = (current.__damp[vel] + omega * change) * delta;
current.__damp[vel] = (current.__damp[vel] - omega * temp) * t;
var output = target + (change + temp) * t; // Prevent overshooting
if (originalTo - current[prop] > 0.0 === output > originalTo) {
output = originalTo;
current.__damp[vel] = (output - originalTo) / delta;
}
current[prop] = output;
return true;
}
/**
* DampLookAt
*/
var isCamera = function isCamera(v) {
return v && v.isCamera;
};
var isLight = function isLight(v) {
return v && v.isLight;
};
var vl3d = /*@__PURE__*/new Vector3();
var _q1 = /*@__PURE__*/new Quaternion();
var _q2 = /*@__PURE__*/new Quaternion();
var _m1 = /*@__PURE__*/new Matrix4();
var _position = /*@__PURE__*/new Vector3();
function dampLookAt(current, target, smoothTime, delta, maxSpeed, easing, eps) {
// This method does not support objects having non-uniformly-scaled parent(s)
if (typeof target === "number") vl3d.setScalar(target);else if (Array.isArray(target)) vl3d.set(target[0], target[1], target[2]);else vl3d.copy(target);
var parent = current.parent;
current.updateWorldMatrix(true, false);
_position.setFromMatrixPosition(current.matrixWorld);
if (isCamera(current) || isLight(current)) _m1.lookAt(_position, vl3d, current.up);else _m1.lookAt(vl3d, _position, current.up);
dampQ(current.quaternion, _q2.setFromRotationMatrix(_m1), smoothTime, delta, maxSpeed, easing, eps);
if (parent) {
_m1.extractRotation(parent.matrixWorld);
_q1.setFromRotationMatrix(_m1);
dampQ(current.quaternion, _q2.copy(current.quaternion).premultiply(_q1.invert()), smoothTime, delta, maxSpeed, easing, eps);
}
}
/**
* DampAngle, with a shortest-path
*/
function dampAngle(current, prop, target, smoothTime, delta, maxSpeed, easing, eps) {
return damp(current, prop, current[prop] + deltaAngle(current[prop], target), smoothTime, delta, maxSpeed, easing, eps);
}
/**
* Vector2D Damp
*/
var v2d = /*@__PURE__*/new Vector2();
var a2, b2;
function damp2(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v2d.setScalar(target);else if (Array.isArray(target)) v2d.set(target[0], target[1]);else v2d.copy(target);
a2 = damp(current, "x", v2d.x, smoothTime, delta, maxSpeed, easing, eps);
b2 = damp(current, "y", v2d.y, smoothTime, delta, maxSpeed, easing, eps);
return a2 || b2;
}
/**
* Vector3D Damp
*/
var v3d = /*@__PURE__*/new Vector3();
var a3, b3, c3;
function damp3(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v3d.setScalar(target);else if (Array.isArray(target)) v3d.set(target[0], target[1], target[2]);else v3d.copy(target);
a3 = damp(current, "x", v3d.x, smoothTime, delta, maxSpeed, easing, eps);
b3 = damp(current, "y", v3d.y, smoothTime, delta, maxSpeed, easing, eps);
c3 = damp(current, "z", v3d.z, smoothTime, delta, maxSpeed, easing, eps);
return a3 || b3 || c3;
}
/**
* Vector4D Damp
*/
var v4d = /*@__PURE__*/new Vector4();
var a4, b4, c4, d4;
function damp4(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v4d.setScalar(target);else if (Array.isArray(target)) v4d.set(target[0], target[1], target[2], target[3]);else v4d.copy(target);
a4 = damp(current, "x", v4d.x, smoothTime, delta, maxSpeed, easing, eps);
b4 = damp(current, "y", v4d.y, smoothTime, delta, maxSpeed, easing, eps);
c4 = damp(current, "z", v4d.z, smoothTime, delta, maxSpeed, easing, eps);
d4 = damp(current, "w", v4d.w, smoothTime, delta, maxSpeed, easing, eps);
return a4 || b4 || c4 || d4;
}
/**
* Euler Damp
*/
var rot = /*@__PURE__*/new Euler();
var aE, bE, cE;
function dampE(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (Array.isArray(target)) rot.set(target[0], target[1], target[2], target[3]);else rot.copy(target);
aE = dampAngle(current, "x", rot.x, smoothTime, delta, maxSpeed, easing, eps);
bE = dampAngle(current, "y", rot.y, smoothTime, delta, maxSpeed, easing, eps);
cE = dampAngle(current, "z", rot.z, smoothTime, delta, maxSpeed, easing, eps);
return aE || bE || cE;
}
/**
* Color Damp
*/
var col = /*@__PURE__*/new Color();
var aC, bC, cC;
function dampC(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (target instanceof Color) col.copy(target);else if (Array.isArray(target)) col.setRGB(target[0], target[1], target[2]);else col.set(target);
aC = damp(current, "r", col.r, smoothTime, delta, maxSpeed, easing, eps);
bC = damp(current, "g", col.g, smoothTime, delta, maxSpeed, easing, eps);
cC = damp(current, "b", col.b, smoothTime, delta, maxSpeed, easing, eps);
return aC || bC || cC;
}
/**
* Quaternion Damp
* https://gist.github.com/maxattack/4c7b4de00f5c1b95a33b
* Copyright 2016 Max Kaufmann (max.kaufmann@gmail.com)
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var qt = /*@__PURE__*/new Quaternion();
var v4result = /*@__PURE__*/new Vector4();
var v4velocity = /*@__PURE__*/new Vector4();
var v4error = /*@__PURE__*/new Vector4();
var aQ, bQ, cQ, dQ;
function dampQ(current, target, smoothTime, delta, maxSpeed, easing, eps) {
var cur = current;
if (Array.isArray(target)) qt.set(target[0], target[1], target[2], target[3]);else qt.copy(target);
var multi = current.dot(qt) > 0 ? 1 : -1;
qt.x *= multi;
qt.y *= multi;
qt.z *= multi;
qt.w *= multi;
aQ = damp(current, "x", qt.x, smoothTime, delta, maxSpeed, easing, eps);
bQ = damp(current, "y", qt.y, smoothTime, delta, maxSpeed, easing, eps);
cQ = damp(current, "z", qt.z, smoothTime, delta, maxSpeed, easing, eps);
dQ = damp(current, "w", qt.w, smoothTime, delta, maxSpeed, easing, eps); // smooth damp (nlerp approx)
v4result.set(current.x, current.y, current.z, current.w).normalize();
v4velocity.set(cur.__damp.velocity_x, cur.__damp.velocity_y, cur.__damp.velocity_z, cur.__damp.velocity_w); // ensure deriv is tangent
v4error.copy(v4result).multiplyScalar(v4velocity.dot(v4result) / v4result.dot(v4result));
cur.__damp.velocity_x -= v4error.x;
cur.__damp.velocity_y -= v4error.y;
cur.__damp.velocity_z -= v4error.z;
cur.__damp.velocity_w -= v4error.w;
current.set(v4result.x, v4result.y, v4result.z, v4result.w);
return aQ || bQ || cQ || dQ;
}
/**
* Spherical Damp
*/
var spherical = /*@__PURE__*/new Spherical();
var aS, bS, cS;
function dampS(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (Array.isArray(target)) spherical.set(target[0], target[1], target[2]);else spherical.copy(target);
aS = damp(current, "radius", spherical.radius, smoothTime, delta, maxSpeed, easing, eps);
bS = dampAngle(current, "phi", spherical.phi, smoothTime, delta, maxSpeed, easing, eps);
cS = dampAngle(current, "theta", spherical.theta, smoothTime, delta, maxSpeed, easing, eps);
return aS || bS || cS;
}
/**
* Matrix4 Damp
*/
var mat = /*@__PURE__*/new Matrix4();
var mPos = /*@__PURE__*/new Vector3();
var mRot = /*@__PURE__*/new Quaternion();
var mSca = /*@__PURE__*/new Vector3();
var aM, bM, cM;
function dampM(current, target, smoothTime, delta, maxSpeed, easing, eps) {
var cur = current;
if (cur.__damp === undefined) {
cur.__damp = {
position: new Vector3(),
rotation: new Quaternion(),
scale: new Vector3()
};
current.decompose(cur.__damp.position, cur.__damp.rotation, cur.__damp.scale);
}
if (Array.isArray(target)) mat.set.apply(mat, _toConsumableArray(target));else mat.copy(target);
mat.decompose(mPos, mRot, mSca);
aM = damp3(cur.__damp.position, mPos, smoothTime, delta, maxSpeed, easing, eps);
bM = dampQ(cur.__damp.rotation, mRot, smoothTime, delta, maxSpeed, easing, eps);
cM = damp3(cur.__damp.scale, mSca, smoothTime, delta, maxSpeed, easing, eps);
current.compose(cur.__damp.position, cur.__damp.rotation, cur.__damp.scale);
return aM || bM || cM;
}
var easing = /*#__PURE__*/Object.freeze({
__proto__: null,
rsqw: rsqw,
exp: exp,
linear: linear,
sine: sine,
cubic: cubic,
quint: quint,
circ: circ,
quart: quart,
expo: expo,
damp: damp,
dampLookAt: dampLookAt,
dampAngle: dampAngle,
damp2: damp2,
damp3: damp3,
damp4: damp4,
dampE: dampE,
dampC: dampC,
dampQ: dampQ,
dampS: dampS,
dampM: dampM
});
export { exp as a, circ as b, cubic as c, quart as d, easing as e, expo as f, damp as g, dampLookAt as h, dampAngle as i, damp2 as j, damp3 as k, linear as l, damp4 as m, dampE as n, dampC as o, dampQ as p, quint as q, rsqw as r, sine as s, dampS as t, dampM as u };
+370
View File
@@ -0,0 +1,370 @@
'use strict';
var triangle_dist_maathTriangle = require('./triangle-33ffdfef.cjs.dev.js');
var THREE = require('three');
var misc_dist_maathMisc = require('./misc-fce4d494.cjs.dev.js');
var rsqw = function rsqw(t) {
var delta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.01;
var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
var f = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1 / (2 * Math.PI);
return a / Math.atan(1 / delta) * Math.atan(Math.sin(2 * Math.PI * t * f) / delta);
};
var exp = function exp(t) {
return 1 / (1 + t + 0.48 * t * t + 0.235 * t * t * t);
};
var linear = function linear(t) {
return t;
};
var sine = {
"in": function _in(x) {
return 1 - Math.cos(x * Math.PI / 2);
},
out: function out(x) {
return Math.sin(x * Math.PI / 2);
},
inOut: function inOut(x) {
return -(Math.cos(Math.PI * x) - 1) / 2;
}
};
var cubic = {
"in": function _in(x) {
return x * x * x;
},
out: function out(x) {
return 1 - Math.pow(1 - x, 3);
},
inOut: function inOut(x) {
return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
}
};
var quint = {
"in": function _in(x) {
return x * x * x * x * x;
},
out: function out(x) {
return 1 - Math.pow(1 - x, 5);
},
inOut: function inOut(x) {
return x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2;
}
};
var circ = {
"in": function _in(x) {
return 1 - Math.sqrt(1 - Math.pow(x, 2));
},
out: function out(x) {
return Math.sqrt(1 - Math.pow(x - 1, 2));
},
inOut: function inOut(x) {
return x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
}
};
var quart = {
"in": function _in(t) {
return t * t * t * t;
},
out: function out(t) {
return 1 - --t * t * t * t;
},
inOut: function inOut(t) {
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
}
};
var expo = {
"in": function _in(x) {
return x === 0 ? 0 : Math.pow(2, 10 * x - 10);
},
out: function out(x) {
return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
},
inOut: function inOut(x) {
return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2;
}
};
/**
* Damp, based on Game Programming Gems 4 Chapter 1.10
* Return value indicates whether the animation is still running.
*/
function damp(
/** The object */
current,
/** The key to animate */
prop,
/** To goal value */
target) {
var smoothTime = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.25;
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0.01;
var maxSpeed = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : Infinity;
var easing = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : exp;
var eps = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 0.001;
var vel = "velocity_" + prop;
if (current.__damp === undefined) current.__damp = {};
if (current.__damp[vel] === undefined) current.__damp[vel] = 0;
if (Math.abs(current[prop] - target) <= eps) {
current[prop] = target;
return false;
}
smoothTime = Math.max(0.0001, smoothTime);
var omega = 2 / smoothTime;
var t = easing(omega * delta);
var change = current[prop] - target;
var originalTo = target; // Clamp maximum maxSpeed
var maxChange = maxSpeed * smoothTime;
change = Math.min(Math.max(change, -maxChange), maxChange);
target = current[prop] - change;
var temp = (current.__damp[vel] + omega * change) * delta;
current.__damp[vel] = (current.__damp[vel] - omega * temp) * t;
var output = target + (change + temp) * t; // Prevent overshooting
if (originalTo - current[prop] > 0.0 === output > originalTo) {
output = originalTo;
current.__damp[vel] = (output - originalTo) / delta;
}
current[prop] = output;
return true;
}
/**
* DampLookAt
*/
var isCamera = function isCamera(v) {
return v && v.isCamera;
};
var isLight = function isLight(v) {
return v && v.isLight;
};
var vl3d = /*@__PURE__*/new THREE.Vector3();
var _q1 = /*@__PURE__*/new THREE.Quaternion();
var _q2 = /*@__PURE__*/new THREE.Quaternion();
var _m1 = /*@__PURE__*/new THREE.Matrix4();
var _position = /*@__PURE__*/new THREE.Vector3();
function dampLookAt(current, target, smoothTime, delta, maxSpeed, easing, eps) {
// This method does not support objects having non-uniformly-scaled parent(s)
if (typeof target === "number") vl3d.setScalar(target);else if (Array.isArray(target)) vl3d.set(target[0], target[1], target[2]);else vl3d.copy(target);
var parent = current.parent;
current.updateWorldMatrix(true, false);
_position.setFromMatrixPosition(current.matrixWorld);
if (isCamera(current) || isLight(current)) _m1.lookAt(_position, vl3d, current.up);else _m1.lookAt(vl3d, _position, current.up);
dampQ(current.quaternion, _q2.setFromRotationMatrix(_m1), smoothTime, delta, maxSpeed, easing, eps);
if (parent) {
_m1.extractRotation(parent.matrixWorld);
_q1.setFromRotationMatrix(_m1);
dampQ(current.quaternion, _q2.copy(current.quaternion).premultiply(_q1.invert()), smoothTime, delta, maxSpeed, easing, eps);
}
}
/**
* DampAngle, with a shortest-path
*/
function dampAngle(current, prop, target, smoothTime, delta, maxSpeed, easing, eps) {
return damp(current, prop, current[prop] + misc_dist_maathMisc.deltaAngle(current[prop], target), smoothTime, delta, maxSpeed, easing, eps);
}
/**
* Vector2D Damp
*/
var v2d = /*@__PURE__*/new THREE.Vector2();
var a2, b2;
function damp2(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v2d.setScalar(target);else if (Array.isArray(target)) v2d.set(target[0], target[1]);else v2d.copy(target);
a2 = damp(current, "x", v2d.x, smoothTime, delta, maxSpeed, easing, eps);
b2 = damp(current, "y", v2d.y, smoothTime, delta, maxSpeed, easing, eps);
return a2 || b2;
}
/**
* Vector3D Damp
*/
var v3d = /*@__PURE__*/new THREE.Vector3();
var a3, b3, c3;
function damp3(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v3d.setScalar(target);else if (Array.isArray(target)) v3d.set(target[0], target[1], target[2]);else v3d.copy(target);
a3 = damp(current, "x", v3d.x, smoothTime, delta, maxSpeed, easing, eps);
b3 = damp(current, "y", v3d.y, smoothTime, delta, maxSpeed, easing, eps);
c3 = damp(current, "z", v3d.z, smoothTime, delta, maxSpeed, easing, eps);
return a3 || b3 || c3;
}
/**
* Vector4D Damp
*/
var v4d = /*@__PURE__*/new THREE.Vector4();
var a4, b4, c4, d4;
function damp4(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v4d.setScalar(target);else if (Array.isArray(target)) v4d.set(target[0], target[1], target[2], target[3]);else v4d.copy(target);
a4 = damp(current, "x", v4d.x, smoothTime, delta, maxSpeed, easing, eps);
b4 = damp(current, "y", v4d.y, smoothTime, delta, maxSpeed, easing, eps);
c4 = damp(current, "z", v4d.z, smoothTime, delta, maxSpeed, easing, eps);
d4 = damp(current, "w", v4d.w, smoothTime, delta, maxSpeed, easing, eps);
return a4 || b4 || c4 || d4;
}
/**
* Euler Damp
*/
var rot = /*@__PURE__*/new THREE.Euler();
var aE, bE, cE;
function dampE(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (Array.isArray(target)) rot.set(target[0], target[1], target[2], target[3]);else rot.copy(target);
aE = dampAngle(current, "x", rot.x, smoothTime, delta, maxSpeed, easing, eps);
bE = dampAngle(current, "y", rot.y, smoothTime, delta, maxSpeed, easing, eps);
cE = dampAngle(current, "z", rot.z, smoothTime, delta, maxSpeed, easing, eps);
return aE || bE || cE;
}
/**
* Color Damp
*/
var col = /*@__PURE__*/new THREE.Color();
var aC, bC, cC;
function dampC(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (target instanceof THREE.Color) col.copy(target);else if (Array.isArray(target)) col.setRGB(target[0], target[1], target[2]);else col.set(target);
aC = damp(current, "r", col.r, smoothTime, delta, maxSpeed, easing, eps);
bC = damp(current, "g", col.g, smoothTime, delta, maxSpeed, easing, eps);
cC = damp(current, "b", col.b, smoothTime, delta, maxSpeed, easing, eps);
return aC || bC || cC;
}
/**
* Quaternion Damp
* https://gist.github.com/maxattack/4c7b4de00f5c1b95a33b
* Copyright 2016 Max Kaufmann (max.kaufmann@gmail.com)
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var qt = /*@__PURE__*/new THREE.Quaternion();
var v4result = /*@__PURE__*/new THREE.Vector4();
var v4velocity = /*@__PURE__*/new THREE.Vector4();
var v4error = /*@__PURE__*/new THREE.Vector4();
var aQ, bQ, cQ, dQ;
function dampQ(current, target, smoothTime, delta, maxSpeed, easing, eps) {
var cur = current;
if (Array.isArray(target)) qt.set(target[0], target[1], target[2], target[3]);else qt.copy(target);
var multi = current.dot(qt) > 0 ? 1 : -1;
qt.x *= multi;
qt.y *= multi;
qt.z *= multi;
qt.w *= multi;
aQ = damp(current, "x", qt.x, smoothTime, delta, maxSpeed, easing, eps);
bQ = damp(current, "y", qt.y, smoothTime, delta, maxSpeed, easing, eps);
cQ = damp(current, "z", qt.z, smoothTime, delta, maxSpeed, easing, eps);
dQ = damp(current, "w", qt.w, smoothTime, delta, maxSpeed, easing, eps); // smooth damp (nlerp approx)
v4result.set(current.x, current.y, current.z, current.w).normalize();
v4velocity.set(cur.__damp.velocity_x, cur.__damp.velocity_y, cur.__damp.velocity_z, cur.__damp.velocity_w); // ensure deriv is tangent
v4error.copy(v4result).multiplyScalar(v4velocity.dot(v4result) / v4result.dot(v4result));
cur.__damp.velocity_x -= v4error.x;
cur.__damp.velocity_y -= v4error.y;
cur.__damp.velocity_z -= v4error.z;
cur.__damp.velocity_w -= v4error.w;
current.set(v4result.x, v4result.y, v4result.z, v4result.w);
return aQ || bQ || cQ || dQ;
}
/**
* Spherical Damp
*/
var spherical = /*@__PURE__*/new THREE.Spherical();
var aS, bS, cS;
function dampS(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (Array.isArray(target)) spherical.set(target[0], target[1], target[2]);else spherical.copy(target);
aS = damp(current, "radius", spherical.radius, smoothTime, delta, maxSpeed, easing, eps);
bS = dampAngle(current, "phi", spherical.phi, smoothTime, delta, maxSpeed, easing, eps);
cS = dampAngle(current, "theta", spherical.theta, smoothTime, delta, maxSpeed, easing, eps);
return aS || bS || cS;
}
/**
* Matrix4 Damp
*/
var mat = /*@__PURE__*/new THREE.Matrix4();
var mPos = /*@__PURE__*/new THREE.Vector3();
var mRot = /*@__PURE__*/new THREE.Quaternion();
var mSca = /*@__PURE__*/new THREE.Vector3();
var aM, bM, cM;
function dampM(current, target, smoothTime, delta, maxSpeed, easing, eps) {
var cur = current;
if (cur.__damp === undefined) {
cur.__damp = {
position: new THREE.Vector3(),
rotation: new THREE.Quaternion(),
scale: new THREE.Vector3()
};
current.decompose(cur.__damp.position, cur.__damp.rotation, cur.__damp.scale);
}
if (Array.isArray(target)) mat.set.apply(mat, triangle_dist_maathTriangle._toConsumableArray(target));else mat.copy(target);
mat.decompose(mPos, mRot, mSca);
aM = damp3(cur.__damp.position, mPos, smoothTime, delta, maxSpeed, easing, eps);
bM = dampQ(cur.__damp.rotation, mRot, smoothTime, delta, maxSpeed, easing, eps);
cM = damp3(cur.__damp.scale, mSca, smoothTime, delta, maxSpeed, easing, eps);
current.compose(cur.__damp.position, cur.__damp.rotation, cur.__damp.scale);
return aM || bM || cM;
}
var easing = /*#__PURE__*/Object.freeze({
__proto__: null,
rsqw: rsqw,
exp: exp,
linear: linear,
sine: sine,
cubic: cubic,
quint: quint,
circ: circ,
quart: quart,
expo: expo,
damp: damp,
dampLookAt: dampLookAt,
dampAngle: dampAngle,
damp2: damp2,
damp3: damp3,
damp4: damp4,
dampE: dampE,
dampC: dampC,
dampQ: dampQ,
dampS: dampS,
dampM: dampM
});
exports.circ = circ;
exports.cubic = cubic;
exports.damp = damp;
exports.damp2 = damp2;
exports.damp3 = damp3;
exports.damp4 = damp4;
exports.dampAngle = dampAngle;
exports.dampC = dampC;
exports.dampE = dampE;
exports.dampLookAt = dampLookAt;
exports.dampM = dampM;
exports.dampQ = dampQ;
exports.dampS = dampS;
exports.easing = easing;
exports.exp = exp;
exports.expo = expo;
exports.linear = linear;
exports.quart = quart;
exports.quint = quint;
exports.rsqw = rsqw;
exports.sine = sine;
+370
View File
@@ -0,0 +1,370 @@
'use strict';
var triangle_dist_maathTriangle = require('./triangle-9e5a8229.cjs.prod.js');
var THREE = require('three');
var misc_dist_maathMisc = require('./misc-023d073b.cjs.prod.js');
var rsqw = function rsqw(t) {
var delta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.01;
var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
var f = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1 / (2 * Math.PI);
return a / Math.atan(1 / delta) * Math.atan(Math.sin(2 * Math.PI * t * f) / delta);
};
var exp = function exp(t) {
return 1 / (1 + t + 0.48 * t * t + 0.235 * t * t * t);
};
var linear = function linear(t) {
return t;
};
var sine = {
"in": function _in(x) {
return 1 - Math.cos(x * Math.PI / 2);
},
out: function out(x) {
return Math.sin(x * Math.PI / 2);
},
inOut: function inOut(x) {
return -(Math.cos(Math.PI * x) - 1) / 2;
}
};
var cubic = {
"in": function _in(x) {
return x * x * x;
},
out: function out(x) {
return 1 - Math.pow(1 - x, 3);
},
inOut: function inOut(x) {
return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
}
};
var quint = {
"in": function _in(x) {
return x * x * x * x * x;
},
out: function out(x) {
return 1 - Math.pow(1 - x, 5);
},
inOut: function inOut(x) {
return x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2;
}
};
var circ = {
"in": function _in(x) {
return 1 - Math.sqrt(1 - Math.pow(x, 2));
},
out: function out(x) {
return Math.sqrt(1 - Math.pow(x - 1, 2));
},
inOut: function inOut(x) {
return x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
}
};
var quart = {
"in": function _in(t) {
return t * t * t * t;
},
out: function out(t) {
return 1 - --t * t * t * t;
},
inOut: function inOut(t) {
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
}
};
var expo = {
"in": function _in(x) {
return x === 0 ? 0 : Math.pow(2, 10 * x - 10);
},
out: function out(x) {
return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
},
inOut: function inOut(x) {
return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2;
}
};
/**
* Damp, based on Game Programming Gems 4 Chapter 1.10
* Return value indicates whether the animation is still running.
*/
function damp(
/** The object */
current,
/** The key to animate */
prop,
/** To goal value */
target) {
var smoothTime = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.25;
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0.01;
var maxSpeed = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : Infinity;
var easing = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : exp;
var eps = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 0.001;
var vel = "velocity_" + prop;
if (current.__damp === undefined) current.__damp = {};
if (current.__damp[vel] === undefined) current.__damp[vel] = 0;
if (Math.abs(current[prop] - target) <= eps) {
current[prop] = target;
return false;
}
smoothTime = Math.max(0.0001, smoothTime);
var omega = 2 / smoothTime;
var t = easing(omega * delta);
var change = current[prop] - target;
var originalTo = target; // Clamp maximum maxSpeed
var maxChange = maxSpeed * smoothTime;
change = Math.min(Math.max(change, -maxChange), maxChange);
target = current[prop] - change;
var temp = (current.__damp[vel] + omega * change) * delta;
current.__damp[vel] = (current.__damp[vel] - omega * temp) * t;
var output = target + (change + temp) * t; // Prevent overshooting
if (originalTo - current[prop] > 0.0 === output > originalTo) {
output = originalTo;
current.__damp[vel] = (output - originalTo) / delta;
}
current[prop] = output;
return true;
}
/**
* DampLookAt
*/
var isCamera = function isCamera(v) {
return v && v.isCamera;
};
var isLight = function isLight(v) {
return v && v.isLight;
};
var vl3d = /*@__PURE__*/new THREE.Vector3();
var _q1 = /*@__PURE__*/new THREE.Quaternion();
var _q2 = /*@__PURE__*/new THREE.Quaternion();
var _m1 = /*@__PURE__*/new THREE.Matrix4();
var _position = /*@__PURE__*/new THREE.Vector3();
function dampLookAt(current, target, smoothTime, delta, maxSpeed, easing, eps) {
// This method does not support objects having non-uniformly-scaled parent(s)
if (typeof target === "number") vl3d.setScalar(target);else if (Array.isArray(target)) vl3d.set(target[0], target[1], target[2]);else vl3d.copy(target);
var parent = current.parent;
current.updateWorldMatrix(true, false);
_position.setFromMatrixPosition(current.matrixWorld);
if (isCamera(current) || isLight(current)) _m1.lookAt(_position, vl3d, current.up);else _m1.lookAt(vl3d, _position, current.up);
dampQ(current.quaternion, _q2.setFromRotationMatrix(_m1), smoothTime, delta, maxSpeed, easing, eps);
if (parent) {
_m1.extractRotation(parent.matrixWorld);
_q1.setFromRotationMatrix(_m1);
dampQ(current.quaternion, _q2.copy(current.quaternion).premultiply(_q1.invert()), smoothTime, delta, maxSpeed, easing, eps);
}
}
/**
* DampAngle, with a shortest-path
*/
function dampAngle(current, prop, target, smoothTime, delta, maxSpeed, easing, eps) {
return damp(current, prop, current[prop] + misc_dist_maathMisc.deltaAngle(current[prop], target), smoothTime, delta, maxSpeed, easing, eps);
}
/**
* Vector2D Damp
*/
var v2d = /*@__PURE__*/new THREE.Vector2();
var a2, b2;
function damp2(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v2d.setScalar(target);else if (Array.isArray(target)) v2d.set(target[0], target[1]);else v2d.copy(target);
a2 = damp(current, "x", v2d.x, smoothTime, delta, maxSpeed, easing, eps);
b2 = damp(current, "y", v2d.y, smoothTime, delta, maxSpeed, easing, eps);
return a2 || b2;
}
/**
* Vector3D Damp
*/
var v3d = /*@__PURE__*/new THREE.Vector3();
var a3, b3, c3;
function damp3(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v3d.setScalar(target);else if (Array.isArray(target)) v3d.set(target[0], target[1], target[2]);else v3d.copy(target);
a3 = damp(current, "x", v3d.x, smoothTime, delta, maxSpeed, easing, eps);
b3 = damp(current, "y", v3d.y, smoothTime, delta, maxSpeed, easing, eps);
c3 = damp(current, "z", v3d.z, smoothTime, delta, maxSpeed, easing, eps);
return a3 || b3 || c3;
}
/**
* Vector4D Damp
*/
var v4d = /*@__PURE__*/new THREE.Vector4();
var a4, b4, c4, d4;
function damp4(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (typeof target === "number") v4d.setScalar(target);else if (Array.isArray(target)) v4d.set(target[0], target[1], target[2], target[3]);else v4d.copy(target);
a4 = damp(current, "x", v4d.x, smoothTime, delta, maxSpeed, easing, eps);
b4 = damp(current, "y", v4d.y, smoothTime, delta, maxSpeed, easing, eps);
c4 = damp(current, "z", v4d.z, smoothTime, delta, maxSpeed, easing, eps);
d4 = damp(current, "w", v4d.w, smoothTime, delta, maxSpeed, easing, eps);
return a4 || b4 || c4 || d4;
}
/**
* Euler Damp
*/
var rot = /*@__PURE__*/new THREE.Euler();
var aE, bE, cE;
function dampE(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (Array.isArray(target)) rot.set(target[0], target[1], target[2], target[3]);else rot.copy(target);
aE = dampAngle(current, "x", rot.x, smoothTime, delta, maxSpeed, easing, eps);
bE = dampAngle(current, "y", rot.y, smoothTime, delta, maxSpeed, easing, eps);
cE = dampAngle(current, "z", rot.z, smoothTime, delta, maxSpeed, easing, eps);
return aE || bE || cE;
}
/**
* Color Damp
*/
var col = /*@__PURE__*/new THREE.Color();
var aC, bC, cC;
function dampC(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (target instanceof THREE.Color) col.copy(target);else if (Array.isArray(target)) col.setRGB(target[0], target[1], target[2]);else col.set(target);
aC = damp(current, "r", col.r, smoothTime, delta, maxSpeed, easing, eps);
bC = damp(current, "g", col.g, smoothTime, delta, maxSpeed, easing, eps);
cC = damp(current, "b", col.b, smoothTime, delta, maxSpeed, easing, eps);
return aC || bC || cC;
}
/**
* Quaternion Damp
* https://gist.github.com/maxattack/4c7b4de00f5c1b95a33b
* Copyright 2016 Max Kaufmann (max.kaufmann@gmail.com)
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var qt = /*@__PURE__*/new THREE.Quaternion();
var v4result = /*@__PURE__*/new THREE.Vector4();
var v4velocity = /*@__PURE__*/new THREE.Vector4();
var v4error = /*@__PURE__*/new THREE.Vector4();
var aQ, bQ, cQ, dQ;
function dampQ(current, target, smoothTime, delta, maxSpeed, easing, eps) {
var cur = current;
if (Array.isArray(target)) qt.set(target[0], target[1], target[2], target[3]);else qt.copy(target);
var multi = current.dot(qt) > 0 ? 1 : -1;
qt.x *= multi;
qt.y *= multi;
qt.z *= multi;
qt.w *= multi;
aQ = damp(current, "x", qt.x, smoothTime, delta, maxSpeed, easing, eps);
bQ = damp(current, "y", qt.y, smoothTime, delta, maxSpeed, easing, eps);
cQ = damp(current, "z", qt.z, smoothTime, delta, maxSpeed, easing, eps);
dQ = damp(current, "w", qt.w, smoothTime, delta, maxSpeed, easing, eps); // smooth damp (nlerp approx)
v4result.set(current.x, current.y, current.z, current.w).normalize();
v4velocity.set(cur.__damp.velocity_x, cur.__damp.velocity_y, cur.__damp.velocity_z, cur.__damp.velocity_w); // ensure deriv is tangent
v4error.copy(v4result).multiplyScalar(v4velocity.dot(v4result) / v4result.dot(v4result));
cur.__damp.velocity_x -= v4error.x;
cur.__damp.velocity_y -= v4error.y;
cur.__damp.velocity_z -= v4error.z;
cur.__damp.velocity_w -= v4error.w;
current.set(v4result.x, v4result.y, v4result.z, v4result.w);
return aQ || bQ || cQ || dQ;
}
/**
* Spherical Damp
*/
var spherical = /*@__PURE__*/new THREE.Spherical();
var aS, bS, cS;
function dampS(current, target, smoothTime, delta, maxSpeed, easing, eps) {
if (Array.isArray(target)) spherical.set(target[0], target[1], target[2]);else spherical.copy(target);
aS = damp(current, "radius", spherical.radius, smoothTime, delta, maxSpeed, easing, eps);
bS = dampAngle(current, "phi", spherical.phi, smoothTime, delta, maxSpeed, easing, eps);
cS = dampAngle(current, "theta", spherical.theta, smoothTime, delta, maxSpeed, easing, eps);
return aS || bS || cS;
}
/**
* Matrix4 Damp
*/
var mat = /*@__PURE__*/new THREE.Matrix4();
var mPos = /*@__PURE__*/new THREE.Vector3();
var mRot = /*@__PURE__*/new THREE.Quaternion();
var mSca = /*@__PURE__*/new THREE.Vector3();
var aM, bM, cM;
function dampM(current, target, smoothTime, delta, maxSpeed, easing, eps) {
var cur = current;
if (cur.__damp === undefined) {
cur.__damp = {
position: new THREE.Vector3(),
rotation: new THREE.Quaternion(),
scale: new THREE.Vector3()
};
current.decompose(cur.__damp.position, cur.__damp.rotation, cur.__damp.scale);
}
if (Array.isArray(target)) mat.set.apply(mat, triangle_dist_maathTriangle._toConsumableArray(target));else mat.copy(target);
mat.decompose(mPos, mRot, mSca);
aM = damp3(cur.__damp.position, mPos, smoothTime, delta, maxSpeed, easing, eps);
bM = dampQ(cur.__damp.rotation, mRot, smoothTime, delta, maxSpeed, easing, eps);
cM = damp3(cur.__damp.scale, mSca, smoothTime, delta, maxSpeed, easing, eps);
current.compose(cur.__damp.position, cur.__damp.rotation, cur.__damp.scale);
return aM || bM || cM;
}
var easing = /*#__PURE__*/Object.freeze({
__proto__: null,
rsqw: rsqw,
exp: exp,
linear: linear,
sine: sine,
cubic: cubic,
quint: quint,
circ: circ,
quart: quart,
expo: expo,
damp: damp,
dampLookAt: dampLookAt,
dampAngle: dampAngle,
damp2: damp2,
damp3: damp3,
damp4: damp4,
dampE: dampE,
dampC: dampC,
dampQ: dampQ,
dampS: dampS,
dampM: dampM
});
exports.circ = circ;
exports.cubic = cubic;
exports.damp = damp;
exports.damp2 = damp2;
exports.damp3 = damp3;
exports.damp4 = damp4;
exports.dampAngle = dampAngle;
exports.dampC = dampC;
exports.dampE = dampE;
exports.dampLookAt = dampLookAt;
exports.dampM = dampM;
exports.dampQ = dampQ;
exports.dampS = dampS;
exports.easing = easing;
exports.exp = exp;
exports.expo = expo;
exports.linear = linear;
exports.quart = quart;
exports.quint = quint;
exports.rsqw = rsqw;
exports.sine = sine;
+355
View File
@@ -0,0 +1,355 @@
import { _ as _classCallCheck } from './classCallCheck-9098b006.esm.js';
import { _ as _setPrototypeOf, a as _isNativeReflectConstruct } from './isNativeReflectConstruct-5594d075.esm.js';
import * as THREE from 'three';
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
var RoundedPlaneGeometry = /*#__PURE__*/function (_THREE$BufferGeometry) {
_inherits(RoundedPlaneGeometry, _THREE$BufferGeometry);
var _super = _createSuper(RoundedPlaneGeometry);
function RoundedPlaneGeometry() {
var _this;
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var radius = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.2;
var segments = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 16;
_classCallCheck(this, RoundedPlaneGeometry);
_this = _super.call(this);
_this.parameters = {
width: width,
height: height,
radius: radius,
segments: segments
}; // helper const's
var wi = width / 2 - radius; // inner width
var hi = height / 2 - radius; // inner height
var ul = radius / width; // u left
var ur = (width - radius) / width; // u right
var vl = radius / height; // v low
var vh = (height - radius) / height; // v high
var positions = [wi, hi, 0, -wi, hi, 0, -wi, -hi, 0, wi, -hi, 0];
var uvs = [ur, vh, ul, vh, ul, vl, ur, vl];
var n = [3 * (segments + 1) + 3, 3 * (segments + 1) + 4, segments + 4, segments + 5, 2 * (segments + 1) + 4, 2, 1, 2 * (segments + 1) + 3, 3, 4 * (segments + 1) + 3, 4, 0];
var indices = [n[0], n[1], n[2], n[0], n[2], n[3], n[4], n[5], n[6], n[4], n[6], n[7], n[8], n[9], n[10], n[8], n[10], n[11]];
var phi, cos, sin, xc, yc, uc, vc, idx;
for (var i = 0; i < 4; i++) {
xc = i < 1 || i > 2 ? wi : -wi;
yc = i < 2 ? hi : -hi;
uc = i < 1 || i > 2 ? ur : ul;
vc = i < 2 ? vh : vl;
for (var j = 0; j <= segments; j++) {
phi = Math.PI / 2 * (i + j / segments);
cos = Math.cos(phi);
sin = Math.sin(phi);
positions.push(xc + radius * cos, yc + radius * sin, 0);
uvs.push(uc + ul * cos, vc + vl * sin);
if (j < segments) {
idx = (segments + 1) * i + j + 4;
indices.push(i, idx, idx + 1);
}
}
}
_this.setIndex(new THREE.BufferAttribute(new Uint32Array(indices), 1));
_this.setAttribute("position", new THREE.BufferAttribute(new Float32Array(positions), 3));
_this.setAttribute("uv", new THREE.BufferAttribute(new Float32Array(uvs), 2));
return _this;
}
return RoundedPlaneGeometry;
}(THREE.BufferGeometry); // Author: https://stackoverflow.com/users/128511/gman
// https://stackoverflow.com/questions/34958072/programmatically-generate-simple-uv-mapping-for-models
function applyCylindricalUV(bufferGeometry) {
var uvs = [];
for (var i = 0; i < bufferGeometry.attributes.position.array.length / 3; i++) {
var x = bufferGeometry.attributes.position.array[i * 3 + 0];
var y = bufferGeometry.attributes.position.array[i * 3 + 1];
var z = bufferGeometry.attributes.position.array[i * 3 + 2];
uvs.push(Math.atan2(x, z) / Math.PI * 0.5 + 0.5, y / Math.PI * 0.5 + 0.5);
}
if (bufferGeometry.attributes.uv) delete bufferGeometry.attributes.uv;
bufferGeometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
} // Author: https://stackoverflow.com/users/268905/knee-cola
// https://stackoverflow.com/questions/20774648/three-js-generate-uv-coordinate
function applySphereUV(bufferGeometry) {
var uvs = [];
var vertices = [];
for (var i = 0; i < bufferGeometry.attributes.position.array.length / 3; i++) {
var x = bufferGeometry.attributes.position.array[i * 3 + 0];
var y = bufferGeometry.attributes.position.array[i * 3 + 1];
var z = bufferGeometry.attributes.position.array[i * 3 + 2];
vertices.push(new THREE.Vector3(x, y, z));
}
var polarVertices = vertices.map(cartesian2polar);
for (var _i = 0; _i < polarVertices.length / 3; _i++) {
var tri = new THREE.Triangle(vertices[_i * 3 + 0], vertices[_i * 3 + 1], vertices[_i * 3 + 2]);
var normal = tri.getNormal(new THREE.Vector3());
for (var f = 0; f < 3; f++) {
var vertex = polarVertices[_i * 3 + f];
if (vertex.theta === 0 && (vertex.phi === 0 || vertex.phi === Math.PI)) {
var alignedVertice = vertex.phi === 0 ? _i * 3 + 1 : _i * 3 + 0;
vertex = {
r: vertex.r,
phi: vertex.phi,
theta: polarVertices[alignedVertice].theta
};
}
if (vertex.theta === Math.PI && cartesian2polar(normal).theta < Math.PI / 2) {
vertex.theta = -Math.PI;
}
var canvasPoint = polar2canvas(vertex);
uvs.push(1 - canvasPoint.x, 1 - canvasPoint.y);
}
}
if (bufferGeometry.attributes.uv) delete bufferGeometry.attributes.uv;
bufferGeometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
}
function cartesian2polar(position) {
var r = Math.sqrt(position.x * position.x + position.z * position.z + position.y * position.y);
return {
r: r,
phi: Math.acos(position.y / r),
theta: Math.atan2(position.z, position.x)
};
}
function polar2canvas(polarPoint) {
return {
y: polarPoint.phi / Math.PI,
x: (polarPoint.theta + Math.PI) / (2 * Math.PI)
};
} // Author: Alex Khoroshylov (https://stackoverflow.com/users/8742287/alex-khoroshylov)
// https://stackoverflow.com/questions/20774648/three-js-generate-uv-coordinate
function applyBoxUV(bufferGeometry) {
bufferGeometry.computeBoundingBox();
var bboxSize = bufferGeometry.boundingBox.getSize(new THREE.Vector3());
var boxSize = Math.min(bboxSize.x, bboxSize.y, bboxSize.z);
var boxGeometry = new THREE.BoxGeometry(boxSize, boxSize, boxSize);
var cube = new THREE.Mesh(boxGeometry);
cube.rotation.set(0, 0, 0);
cube.updateWorldMatrix(true, false);
var transformMatrix = cube.matrix.clone().invert();
var uvBbox = new THREE.Box3(new THREE.Vector3(-boxSize / 2, -boxSize / 2, -boxSize / 2), new THREE.Vector3(boxSize / 2, boxSize / 2, boxSize / 2));
_applyBoxUV(bufferGeometry, transformMatrix, uvBbox, boxSize);
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
}
function _applyBoxUV(geom, transformMatrix, bbox, bbox_max_size) {
var coords = [];
coords.length = 2 * geom.attributes.position.array.length / 3; //maps 3 verts of 1 face on the better side of the cube
//side of the cube can be XY, XZ or YZ
var makeUVs = function makeUVs(v0, v1, v2) {
//pre-rotate the model so that cube sides match world axis
v0.applyMatrix4(transformMatrix);
v1.applyMatrix4(transformMatrix);
v2.applyMatrix4(transformMatrix); //get normal of the face, to know into which cube side it maps better
var n = new THREE.Vector3();
n.crossVectors(v1.clone().sub(v0), v1.clone().sub(v2)).normalize();
n.x = Math.abs(n.x);
n.y = Math.abs(n.y);
n.z = Math.abs(n.z);
var uv0 = new THREE.Vector2();
var uv1 = new THREE.Vector2();
var uv2 = new THREE.Vector2(); // xz mapping
if (n.y > n.x && n.y > n.z) {
uv0.x = (v0.x - bbox.min.x) / bbox_max_size;
uv0.y = (bbox.max.z - v0.z) / bbox_max_size;
uv1.x = (v1.x - bbox.min.x) / bbox_max_size;
uv1.y = (bbox.max.z - v1.z) / bbox_max_size;
uv2.x = (v2.x - bbox.min.x) / bbox_max_size;
uv2.y = (bbox.max.z - v2.z) / bbox_max_size;
} else if (n.x > n.y && n.x > n.z) {
uv0.x = (v0.z - bbox.min.z) / bbox_max_size;
uv0.y = (v0.y - bbox.min.y) / bbox_max_size;
uv1.x = (v1.z - bbox.min.z) / bbox_max_size;
uv1.y = (v1.y - bbox.min.y) / bbox_max_size;
uv2.x = (v2.z - bbox.min.z) / bbox_max_size;
uv2.y = (v2.y - bbox.min.y) / bbox_max_size;
} else if (n.z > n.y && n.z > n.x) {
uv0.x = (v0.x - bbox.min.x) / bbox_max_size;
uv0.y = (v0.y - bbox.min.y) / bbox_max_size;
uv1.x = (v1.x - bbox.min.x) / bbox_max_size;
uv1.y = (v1.y - bbox.min.y) / bbox_max_size;
uv2.x = (v2.x - bbox.min.x) / bbox_max_size;
uv2.y = (v2.y - bbox.min.y) / bbox_max_size;
}
return {
uv0: uv0,
uv1: uv1,
uv2: uv2
};
};
if (geom.index) {
// is it indexed buffer geometry?
for (var vi = 0; vi < geom.index.array.length; vi += 3) {
var idx0 = geom.index.array[vi];
var idx1 = geom.index.array[vi + 1];
var idx2 = geom.index.array[vi + 2];
var vx0 = geom.attributes.position.array[3 * idx0];
var vy0 = geom.attributes.position.array[3 * idx0 + 1];
var vz0 = geom.attributes.position.array[3 * idx0 + 2];
var vx1 = geom.attributes.position.array[3 * idx1];
var vy1 = geom.attributes.position.array[3 * idx1 + 1];
var vz1 = geom.attributes.position.array[3 * idx1 + 2];
var vx2 = geom.attributes.position.array[3 * idx2];
var vy2 = geom.attributes.position.array[3 * idx2 + 1];
var vz2 = geom.attributes.position.array[3 * idx2 + 2];
var v0 = new THREE.Vector3(vx0, vy0, vz0);
var v1 = new THREE.Vector3(vx1, vy1, vz1);
var v2 = new THREE.Vector3(vx2, vy2, vz2);
var uvs = makeUVs(v0, v1, v2);
coords[2 * idx0] = uvs.uv0.x;
coords[2 * idx0 + 1] = uvs.uv0.y;
coords[2 * idx1] = uvs.uv1.x;
coords[2 * idx1 + 1] = uvs.uv1.y;
coords[2 * idx2] = uvs.uv2.x;
coords[2 * idx2 + 1] = uvs.uv2.y;
}
} else {
for (var _vi = 0; _vi < geom.attributes.position.array.length; _vi += 9) {
var _vx = geom.attributes.position.array[_vi];
var _vy = geom.attributes.position.array[_vi + 1];
var _vz = geom.attributes.position.array[_vi + 2];
var _vx2 = geom.attributes.position.array[_vi + 3];
var _vy2 = geom.attributes.position.array[_vi + 4];
var _vz2 = geom.attributes.position.array[_vi + 5];
var _vx3 = geom.attributes.position.array[_vi + 6];
var _vy3 = geom.attributes.position.array[_vi + 7];
var _vz3 = geom.attributes.position.array[_vi + 8];
var _v = new THREE.Vector3(_vx, _vy, _vz);
var _v2 = new THREE.Vector3(_vx2, _vy2, _vz2);
var _v3 = new THREE.Vector3(_vx3, _vy3, _vz3);
var _uvs = makeUVs(_v, _v2, _v3);
var _idx = _vi / 3;
var _idx2 = _idx + 1;
var _idx3 = _idx + 2;
coords[2 * _idx] = _uvs.uv0.x;
coords[2 * _idx + 1] = _uvs.uv0.y;
coords[2 * _idx2] = _uvs.uv1.x;
coords[2 * _idx2 + 1] = _uvs.uv1.y;
coords[2 * _idx3] = _uvs.uv2.x;
coords[2 * _idx3 + 1] = _uvs.uv2.y;
}
}
if (geom.attributes.uv) delete geom.attributes.uv;
geom.setAttribute("uv", new THREE.Float32BufferAttribute(coords, 2));
}
var geometry = /*#__PURE__*/Object.freeze({
__proto__: null,
RoundedPlaneGeometry: RoundedPlaneGeometry,
applyCylindricalUV: applyCylindricalUV,
applySphereUV: applySphereUV,
applyBoxUV: applyBoxUV
});
export { RoundedPlaneGeometry as R, applyCylindricalUV as a, applySphereUV as b, applyBoxUV as c, geometry as g };
+381
View File
@@ -0,0 +1,381 @@
'use strict';
var classCallCheck = require('./classCallCheck-eaf0efc7.cjs.dev.js');
var isNativeReflectConstruct = require('./isNativeReflectConstruct-ddc4ebc1.cjs.dev.js');
var THREE = require('three');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) isNativeReflectConstruct._setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = isNativeReflectConstruct._isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
var RoundedPlaneGeometry = /*#__PURE__*/function (_THREE$BufferGeometry) {
_inherits(RoundedPlaneGeometry, _THREE$BufferGeometry);
var _super = _createSuper(RoundedPlaneGeometry);
function RoundedPlaneGeometry() {
var _this;
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var radius = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.2;
var segments = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 16;
classCallCheck._classCallCheck(this, RoundedPlaneGeometry);
_this = _super.call(this);
_this.parameters = {
width: width,
height: height,
radius: radius,
segments: segments
}; // helper const's
var wi = width / 2 - radius; // inner width
var hi = height / 2 - radius; // inner height
var ul = radius / width; // u left
var ur = (width - radius) / width; // u right
var vl = radius / height; // v low
var vh = (height - radius) / height; // v high
var positions = [wi, hi, 0, -wi, hi, 0, -wi, -hi, 0, wi, -hi, 0];
var uvs = [ur, vh, ul, vh, ul, vl, ur, vl];
var n = [3 * (segments + 1) + 3, 3 * (segments + 1) + 4, segments + 4, segments + 5, 2 * (segments + 1) + 4, 2, 1, 2 * (segments + 1) + 3, 3, 4 * (segments + 1) + 3, 4, 0];
var indices = [n[0], n[1], n[2], n[0], n[2], n[3], n[4], n[5], n[6], n[4], n[6], n[7], n[8], n[9], n[10], n[8], n[10], n[11]];
var phi, cos, sin, xc, yc, uc, vc, idx;
for (var i = 0; i < 4; i++) {
xc = i < 1 || i > 2 ? wi : -wi;
yc = i < 2 ? hi : -hi;
uc = i < 1 || i > 2 ? ur : ul;
vc = i < 2 ? vh : vl;
for (var j = 0; j <= segments; j++) {
phi = Math.PI / 2 * (i + j / segments);
cos = Math.cos(phi);
sin = Math.sin(phi);
positions.push(xc + radius * cos, yc + radius * sin, 0);
uvs.push(uc + ul * cos, vc + vl * sin);
if (j < segments) {
idx = (segments + 1) * i + j + 4;
indices.push(i, idx, idx + 1);
}
}
}
_this.setIndex(new THREE__namespace.BufferAttribute(new Uint32Array(indices), 1));
_this.setAttribute("position", new THREE__namespace.BufferAttribute(new Float32Array(positions), 3));
_this.setAttribute("uv", new THREE__namespace.BufferAttribute(new Float32Array(uvs), 2));
return _this;
}
return RoundedPlaneGeometry;
}(THREE__namespace.BufferGeometry); // Author: https://stackoverflow.com/users/128511/gman
// https://stackoverflow.com/questions/34958072/programmatically-generate-simple-uv-mapping-for-models
function applyCylindricalUV(bufferGeometry) {
var uvs = [];
for (var i = 0; i < bufferGeometry.attributes.position.array.length / 3; i++) {
var x = bufferGeometry.attributes.position.array[i * 3 + 0];
var y = bufferGeometry.attributes.position.array[i * 3 + 1];
var z = bufferGeometry.attributes.position.array[i * 3 + 2];
uvs.push(Math.atan2(x, z) / Math.PI * 0.5 + 0.5, y / Math.PI * 0.5 + 0.5);
}
if (bufferGeometry.attributes.uv) delete bufferGeometry.attributes.uv;
bufferGeometry.setAttribute("uv", new THREE__namespace.Float32BufferAttribute(uvs, 2));
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
} // Author: https://stackoverflow.com/users/268905/knee-cola
// https://stackoverflow.com/questions/20774648/three-js-generate-uv-coordinate
function applySphereUV(bufferGeometry) {
var uvs = [];
var vertices = [];
for (var i = 0; i < bufferGeometry.attributes.position.array.length / 3; i++) {
var x = bufferGeometry.attributes.position.array[i * 3 + 0];
var y = bufferGeometry.attributes.position.array[i * 3 + 1];
var z = bufferGeometry.attributes.position.array[i * 3 + 2];
vertices.push(new THREE__namespace.Vector3(x, y, z));
}
var polarVertices = vertices.map(cartesian2polar);
for (var _i = 0; _i < polarVertices.length / 3; _i++) {
var tri = new THREE__namespace.Triangle(vertices[_i * 3 + 0], vertices[_i * 3 + 1], vertices[_i * 3 + 2]);
var normal = tri.getNormal(new THREE__namespace.Vector3());
for (var f = 0; f < 3; f++) {
var vertex = polarVertices[_i * 3 + f];
if (vertex.theta === 0 && (vertex.phi === 0 || vertex.phi === Math.PI)) {
var alignedVertice = vertex.phi === 0 ? _i * 3 + 1 : _i * 3 + 0;
vertex = {
r: vertex.r,
phi: vertex.phi,
theta: polarVertices[alignedVertice].theta
};
}
if (vertex.theta === Math.PI && cartesian2polar(normal).theta < Math.PI / 2) {
vertex.theta = -Math.PI;
}
var canvasPoint = polar2canvas(vertex);
uvs.push(1 - canvasPoint.x, 1 - canvasPoint.y);
}
}
if (bufferGeometry.attributes.uv) delete bufferGeometry.attributes.uv;
bufferGeometry.setAttribute("uv", new THREE__namespace.Float32BufferAttribute(uvs, 2));
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
}
function cartesian2polar(position) {
var r = Math.sqrt(position.x * position.x + position.z * position.z + position.y * position.y);
return {
r: r,
phi: Math.acos(position.y / r),
theta: Math.atan2(position.z, position.x)
};
}
function polar2canvas(polarPoint) {
return {
y: polarPoint.phi / Math.PI,
x: (polarPoint.theta + Math.PI) / (2 * Math.PI)
};
} // Author: Alex Khoroshylov (https://stackoverflow.com/users/8742287/alex-khoroshylov)
// https://stackoverflow.com/questions/20774648/three-js-generate-uv-coordinate
function applyBoxUV(bufferGeometry) {
bufferGeometry.computeBoundingBox();
var bboxSize = bufferGeometry.boundingBox.getSize(new THREE__namespace.Vector3());
var boxSize = Math.min(bboxSize.x, bboxSize.y, bboxSize.z);
var boxGeometry = new THREE__namespace.BoxGeometry(boxSize, boxSize, boxSize);
var cube = new THREE__namespace.Mesh(boxGeometry);
cube.rotation.set(0, 0, 0);
cube.updateWorldMatrix(true, false);
var transformMatrix = cube.matrix.clone().invert();
var uvBbox = new THREE__namespace.Box3(new THREE__namespace.Vector3(-boxSize / 2, -boxSize / 2, -boxSize / 2), new THREE__namespace.Vector3(boxSize / 2, boxSize / 2, boxSize / 2));
_applyBoxUV(bufferGeometry, transformMatrix, uvBbox, boxSize);
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
}
function _applyBoxUV(geom, transformMatrix, bbox, bbox_max_size) {
var coords = [];
coords.length = 2 * geom.attributes.position.array.length / 3; //maps 3 verts of 1 face on the better side of the cube
//side of the cube can be XY, XZ or YZ
var makeUVs = function makeUVs(v0, v1, v2) {
//pre-rotate the model so that cube sides match world axis
v0.applyMatrix4(transformMatrix);
v1.applyMatrix4(transformMatrix);
v2.applyMatrix4(transformMatrix); //get normal of the face, to know into which cube side it maps better
var n = new THREE__namespace.Vector3();
n.crossVectors(v1.clone().sub(v0), v1.clone().sub(v2)).normalize();
n.x = Math.abs(n.x);
n.y = Math.abs(n.y);
n.z = Math.abs(n.z);
var uv0 = new THREE__namespace.Vector2();
var uv1 = new THREE__namespace.Vector2();
var uv2 = new THREE__namespace.Vector2(); // xz mapping
if (n.y > n.x && n.y > n.z) {
uv0.x = (v0.x - bbox.min.x) / bbox_max_size;
uv0.y = (bbox.max.z - v0.z) / bbox_max_size;
uv1.x = (v1.x - bbox.min.x) / bbox_max_size;
uv1.y = (bbox.max.z - v1.z) / bbox_max_size;
uv2.x = (v2.x - bbox.min.x) / bbox_max_size;
uv2.y = (bbox.max.z - v2.z) / bbox_max_size;
} else if (n.x > n.y && n.x > n.z) {
uv0.x = (v0.z - bbox.min.z) / bbox_max_size;
uv0.y = (v0.y - bbox.min.y) / bbox_max_size;
uv1.x = (v1.z - bbox.min.z) / bbox_max_size;
uv1.y = (v1.y - bbox.min.y) / bbox_max_size;
uv2.x = (v2.z - bbox.min.z) / bbox_max_size;
uv2.y = (v2.y - bbox.min.y) / bbox_max_size;
} else if (n.z > n.y && n.z > n.x) {
uv0.x = (v0.x - bbox.min.x) / bbox_max_size;
uv0.y = (v0.y - bbox.min.y) / bbox_max_size;
uv1.x = (v1.x - bbox.min.x) / bbox_max_size;
uv1.y = (v1.y - bbox.min.y) / bbox_max_size;
uv2.x = (v2.x - bbox.min.x) / bbox_max_size;
uv2.y = (v2.y - bbox.min.y) / bbox_max_size;
}
return {
uv0: uv0,
uv1: uv1,
uv2: uv2
};
};
if (geom.index) {
// is it indexed buffer geometry?
for (var vi = 0; vi < geom.index.array.length; vi += 3) {
var idx0 = geom.index.array[vi];
var idx1 = geom.index.array[vi + 1];
var idx2 = geom.index.array[vi + 2];
var vx0 = geom.attributes.position.array[3 * idx0];
var vy0 = geom.attributes.position.array[3 * idx0 + 1];
var vz0 = geom.attributes.position.array[3 * idx0 + 2];
var vx1 = geom.attributes.position.array[3 * idx1];
var vy1 = geom.attributes.position.array[3 * idx1 + 1];
var vz1 = geom.attributes.position.array[3 * idx1 + 2];
var vx2 = geom.attributes.position.array[3 * idx2];
var vy2 = geom.attributes.position.array[3 * idx2 + 1];
var vz2 = geom.attributes.position.array[3 * idx2 + 2];
var v0 = new THREE__namespace.Vector3(vx0, vy0, vz0);
var v1 = new THREE__namespace.Vector3(vx1, vy1, vz1);
var v2 = new THREE__namespace.Vector3(vx2, vy2, vz2);
var uvs = makeUVs(v0, v1, v2);
coords[2 * idx0] = uvs.uv0.x;
coords[2 * idx0 + 1] = uvs.uv0.y;
coords[2 * idx1] = uvs.uv1.x;
coords[2 * idx1 + 1] = uvs.uv1.y;
coords[2 * idx2] = uvs.uv2.x;
coords[2 * idx2 + 1] = uvs.uv2.y;
}
} else {
for (var _vi = 0; _vi < geom.attributes.position.array.length; _vi += 9) {
var _vx = geom.attributes.position.array[_vi];
var _vy = geom.attributes.position.array[_vi + 1];
var _vz = geom.attributes.position.array[_vi + 2];
var _vx2 = geom.attributes.position.array[_vi + 3];
var _vy2 = geom.attributes.position.array[_vi + 4];
var _vz2 = geom.attributes.position.array[_vi + 5];
var _vx3 = geom.attributes.position.array[_vi + 6];
var _vy3 = geom.attributes.position.array[_vi + 7];
var _vz3 = geom.attributes.position.array[_vi + 8];
var _v = new THREE__namespace.Vector3(_vx, _vy, _vz);
var _v2 = new THREE__namespace.Vector3(_vx2, _vy2, _vz2);
var _v3 = new THREE__namespace.Vector3(_vx3, _vy3, _vz3);
var _uvs = makeUVs(_v, _v2, _v3);
var _idx = _vi / 3;
var _idx2 = _idx + 1;
var _idx3 = _idx + 2;
coords[2 * _idx] = _uvs.uv0.x;
coords[2 * _idx + 1] = _uvs.uv0.y;
coords[2 * _idx2] = _uvs.uv1.x;
coords[2 * _idx2 + 1] = _uvs.uv1.y;
coords[2 * _idx3] = _uvs.uv2.x;
coords[2 * _idx3 + 1] = _uvs.uv2.y;
}
}
if (geom.attributes.uv) delete geom.attributes.uv;
geom.setAttribute("uv", new THREE__namespace.Float32BufferAttribute(coords, 2));
}
var geometry = /*#__PURE__*/Object.freeze({
__proto__: null,
RoundedPlaneGeometry: RoundedPlaneGeometry,
applyCylindricalUV: applyCylindricalUV,
applySphereUV: applySphereUV,
applyBoxUV: applyBoxUV
});
exports.RoundedPlaneGeometry = RoundedPlaneGeometry;
exports.applyBoxUV = applyBoxUV;
exports.applyCylindricalUV = applyCylindricalUV;
exports.applySphereUV = applySphereUV;
exports.geometry = geometry;
+381
View File
@@ -0,0 +1,381 @@
'use strict';
var classCallCheck = require('./classCallCheck-839aeb3a.cjs.prod.js');
var isNativeReflectConstruct = require('./isNativeReflectConstruct-9acebf01.cjs.prod.js');
var THREE = require('three');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) isNativeReflectConstruct._setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = isNativeReflectConstruct._isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
var RoundedPlaneGeometry = /*#__PURE__*/function (_THREE$BufferGeometry) {
_inherits(RoundedPlaneGeometry, _THREE$BufferGeometry);
var _super = _createSuper(RoundedPlaneGeometry);
function RoundedPlaneGeometry() {
var _this;
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var radius = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.2;
var segments = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 16;
classCallCheck._classCallCheck(this, RoundedPlaneGeometry);
_this = _super.call(this);
_this.parameters = {
width: width,
height: height,
radius: radius,
segments: segments
}; // helper const's
var wi = width / 2 - radius; // inner width
var hi = height / 2 - radius; // inner height
var ul = radius / width; // u left
var ur = (width - radius) / width; // u right
var vl = radius / height; // v low
var vh = (height - radius) / height; // v high
var positions = [wi, hi, 0, -wi, hi, 0, -wi, -hi, 0, wi, -hi, 0];
var uvs = [ur, vh, ul, vh, ul, vl, ur, vl];
var n = [3 * (segments + 1) + 3, 3 * (segments + 1) + 4, segments + 4, segments + 5, 2 * (segments + 1) + 4, 2, 1, 2 * (segments + 1) + 3, 3, 4 * (segments + 1) + 3, 4, 0];
var indices = [n[0], n[1], n[2], n[0], n[2], n[3], n[4], n[5], n[6], n[4], n[6], n[7], n[8], n[9], n[10], n[8], n[10], n[11]];
var phi, cos, sin, xc, yc, uc, vc, idx;
for (var i = 0; i < 4; i++) {
xc = i < 1 || i > 2 ? wi : -wi;
yc = i < 2 ? hi : -hi;
uc = i < 1 || i > 2 ? ur : ul;
vc = i < 2 ? vh : vl;
for (var j = 0; j <= segments; j++) {
phi = Math.PI / 2 * (i + j / segments);
cos = Math.cos(phi);
sin = Math.sin(phi);
positions.push(xc + radius * cos, yc + radius * sin, 0);
uvs.push(uc + ul * cos, vc + vl * sin);
if (j < segments) {
idx = (segments + 1) * i + j + 4;
indices.push(i, idx, idx + 1);
}
}
}
_this.setIndex(new THREE__namespace.BufferAttribute(new Uint32Array(indices), 1));
_this.setAttribute("position", new THREE__namespace.BufferAttribute(new Float32Array(positions), 3));
_this.setAttribute("uv", new THREE__namespace.BufferAttribute(new Float32Array(uvs), 2));
return _this;
}
return RoundedPlaneGeometry;
}(THREE__namespace.BufferGeometry); // Author: https://stackoverflow.com/users/128511/gman
// https://stackoverflow.com/questions/34958072/programmatically-generate-simple-uv-mapping-for-models
function applyCylindricalUV(bufferGeometry) {
var uvs = [];
for (var i = 0; i < bufferGeometry.attributes.position.array.length / 3; i++) {
var x = bufferGeometry.attributes.position.array[i * 3 + 0];
var y = bufferGeometry.attributes.position.array[i * 3 + 1];
var z = bufferGeometry.attributes.position.array[i * 3 + 2];
uvs.push(Math.atan2(x, z) / Math.PI * 0.5 + 0.5, y / Math.PI * 0.5 + 0.5);
}
if (bufferGeometry.attributes.uv) delete bufferGeometry.attributes.uv;
bufferGeometry.setAttribute("uv", new THREE__namespace.Float32BufferAttribute(uvs, 2));
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
} // Author: https://stackoverflow.com/users/268905/knee-cola
// https://stackoverflow.com/questions/20774648/three-js-generate-uv-coordinate
function applySphereUV(bufferGeometry) {
var uvs = [];
var vertices = [];
for (var i = 0; i < bufferGeometry.attributes.position.array.length / 3; i++) {
var x = bufferGeometry.attributes.position.array[i * 3 + 0];
var y = bufferGeometry.attributes.position.array[i * 3 + 1];
var z = bufferGeometry.attributes.position.array[i * 3 + 2];
vertices.push(new THREE__namespace.Vector3(x, y, z));
}
var polarVertices = vertices.map(cartesian2polar);
for (var _i = 0; _i < polarVertices.length / 3; _i++) {
var tri = new THREE__namespace.Triangle(vertices[_i * 3 + 0], vertices[_i * 3 + 1], vertices[_i * 3 + 2]);
var normal = tri.getNormal(new THREE__namespace.Vector3());
for (var f = 0; f < 3; f++) {
var vertex = polarVertices[_i * 3 + f];
if (vertex.theta === 0 && (vertex.phi === 0 || vertex.phi === Math.PI)) {
var alignedVertice = vertex.phi === 0 ? _i * 3 + 1 : _i * 3 + 0;
vertex = {
r: vertex.r,
phi: vertex.phi,
theta: polarVertices[alignedVertice].theta
};
}
if (vertex.theta === Math.PI && cartesian2polar(normal).theta < Math.PI / 2) {
vertex.theta = -Math.PI;
}
var canvasPoint = polar2canvas(vertex);
uvs.push(1 - canvasPoint.x, 1 - canvasPoint.y);
}
}
if (bufferGeometry.attributes.uv) delete bufferGeometry.attributes.uv;
bufferGeometry.setAttribute("uv", new THREE__namespace.Float32BufferAttribute(uvs, 2));
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
}
function cartesian2polar(position) {
var r = Math.sqrt(position.x * position.x + position.z * position.z + position.y * position.y);
return {
r: r,
phi: Math.acos(position.y / r),
theta: Math.atan2(position.z, position.x)
};
}
function polar2canvas(polarPoint) {
return {
y: polarPoint.phi / Math.PI,
x: (polarPoint.theta + Math.PI) / (2 * Math.PI)
};
} // Author: Alex Khoroshylov (https://stackoverflow.com/users/8742287/alex-khoroshylov)
// https://stackoverflow.com/questions/20774648/three-js-generate-uv-coordinate
function applyBoxUV(bufferGeometry) {
bufferGeometry.computeBoundingBox();
var bboxSize = bufferGeometry.boundingBox.getSize(new THREE__namespace.Vector3());
var boxSize = Math.min(bboxSize.x, bboxSize.y, bboxSize.z);
var boxGeometry = new THREE__namespace.BoxGeometry(boxSize, boxSize, boxSize);
var cube = new THREE__namespace.Mesh(boxGeometry);
cube.rotation.set(0, 0, 0);
cube.updateWorldMatrix(true, false);
var transformMatrix = cube.matrix.clone().invert();
var uvBbox = new THREE__namespace.Box3(new THREE__namespace.Vector3(-boxSize / 2, -boxSize / 2, -boxSize / 2), new THREE__namespace.Vector3(boxSize / 2, boxSize / 2, boxSize / 2));
_applyBoxUV(bufferGeometry, transformMatrix, uvBbox, boxSize);
bufferGeometry.attributes.uv.needsUpdate = true;
return bufferGeometry;
}
function _applyBoxUV(geom, transformMatrix, bbox, bbox_max_size) {
var coords = [];
coords.length = 2 * geom.attributes.position.array.length / 3; //maps 3 verts of 1 face on the better side of the cube
//side of the cube can be XY, XZ or YZ
var makeUVs = function makeUVs(v0, v1, v2) {
//pre-rotate the model so that cube sides match world axis
v0.applyMatrix4(transformMatrix);
v1.applyMatrix4(transformMatrix);
v2.applyMatrix4(transformMatrix); //get normal of the face, to know into which cube side it maps better
var n = new THREE__namespace.Vector3();
n.crossVectors(v1.clone().sub(v0), v1.clone().sub(v2)).normalize();
n.x = Math.abs(n.x);
n.y = Math.abs(n.y);
n.z = Math.abs(n.z);
var uv0 = new THREE__namespace.Vector2();
var uv1 = new THREE__namespace.Vector2();
var uv2 = new THREE__namespace.Vector2(); // xz mapping
if (n.y > n.x && n.y > n.z) {
uv0.x = (v0.x - bbox.min.x) / bbox_max_size;
uv0.y = (bbox.max.z - v0.z) / bbox_max_size;
uv1.x = (v1.x - bbox.min.x) / bbox_max_size;
uv1.y = (bbox.max.z - v1.z) / bbox_max_size;
uv2.x = (v2.x - bbox.min.x) / bbox_max_size;
uv2.y = (bbox.max.z - v2.z) / bbox_max_size;
} else if (n.x > n.y && n.x > n.z) {
uv0.x = (v0.z - bbox.min.z) / bbox_max_size;
uv0.y = (v0.y - bbox.min.y) / bbox_max_size;
uv1.x = (v1.z - bbox.min.z) / bbox_max_size;
uv1.y = (v1.y - bbox.min.y) / bbox_max_size;
uv2.x = (v2.z - bbox.min.z) / bbox_max_size;
uv2.y = (v2.y - bbox.min.y) / bbox_max_size;
} else if (n.z > n.y && n.z > n.x) {
uv0.x = (v0.x - bbox.min.x) / bbox_max_size;
uv0.y = (v0.y - bbox.min.y) / bbox_max_size;
uv1.x = (v1.x - bbox.min.x) / bbox_max_size;
uv1.y = (v1.y - bbox.min.y) / bbox_max_size;
uv2.x = (v2.x - bbox.min.x) / bbox_max_size;
uv2.y = (v2.y - bbox.min.y) / bbox_max_size;
}
return {
uv0: uv0,
uv1: uv1,
uv2: uv2
};
};
if (geom.index) {
// is it indexed buffer geometry?
for (var vi = 0; vi < geom.index.array.length; vi += 3) {
var idx0 = geom.index.array[vi];
var idx1 = geom.index.array[vi + 1];
var idx2 = geom.index.array[vi + 2];
var vx0 = geom.attributes.position.array[3 * idx0];
var vy0 = geom.attributes.position.array[3 * idx0 + 1];
var vz0 = geom.attributes.position.array[3 * idx0 + 2];
var vx1 = geom.attributes.position.array[3 * idx1];
var vy1 = geom.attributes.position.array[3 * idx1 + 1];
var vz1 = geom.attributes.position.array[3 * idx1 + 2];
var vx2 = geom.attributes.position.array[3 * idx2];
var vy2 = geom.attributes.position.array[3 * idx2 + 1];
var vz2 = geom.attributes.position.array[3 * idx2 + 2];
var v0 = new THREE__namespace.Vector3(vx0, vy0, vz0);
var v1 = new THREE__namespace.Vector3(vx1, vy1, vz1);
var v2 = new THREE__namespace.Vector3(vx2, vy2, vz2);
var uvs = makeUVs(v0, v1, v2);
coords[2 * idx0] = uvs.uv0.x;
coords[2 * idx0 + 1] = uvs.uv0.y;
coords[2 * idx1] = uvs.uv1.x;
coords[2 * idx1 + 1] = uvs.uv1.y;
coords[2 * idx2] = uvs.uv2.x;
coords[2 * idx2 + 1] = uvs.uv2.y;
}
} else {
for (var _vi = 0; _vi < geom.attributes.position.array.length; _vi += 9) {
var _vx = geom.attributes.position.array[_vi];
var _vy = geom.attributes.position.array[_vi + 1];
var _vz = geom.attributes.position.array[_vi + 2];
var _vx2 = geom.attributes.position.array[_vi + 3];
var _vy2 = geom.attributes.position.array[_vi + 4];
var _vz2 = geom.attributes.position.array[_vi + 5];
var _vx3 = geom.attributes.position.array[_vi + 6];
var _vy3 = geom.attributes.position.array[_vi + 7];
var _vz3 = geom.attributes.position.array[_vi + 8];
var _v = new THREE__namespace.Vector3(_vx, _vy, _vz);
var _v2 = new THREE__namespace.Vector3(_vx2, _vy2, _vz2);
var _v3 = new THREE__namespace.Vector3(_vx3, _vy3, _vz3);
var _uvs = makeUVs(_v, _v2, _v3);
var _idx = _vi / 3;
var _idx2 = _idx + 1;
var _idx3 = _idx + 2;
coords[2 * _idx] = _uvs.uv0.x;
coords[2 * _idx + 1] = _uvs.uv0.y;
coords[2 * _idx2] = _uvs.uv1.x;
coords[2 * _idx2 + 1] = _uvs.uv1.y;
coords[2 * _idx3] = _uvs.uv2.x;
coords[2 * _idx3 + 1] = _uvs.uv2.y;
}
}
if (geom.attributes.uv) delete geom.attributes.uv;
geom.setAttribute("uv", new THREE__namespace.Float32BufferAttribute(coords, 2));
}
var geometry = /*#__PURE__*/Object.freeze({
__proto__: null,
RoundedPlaneGeometry: RoundedPlaneGeometry,
applyCylindricalUV: applyCylindricalUV,
applySphereUV: applySphereUV,
applyBoxUV: applyBoxUV
});
exports.RoundedPlaneGeometry = RoundedPlaneGeometry;
exports.applyBoxUV = applyBoxUV;
exports.applyCylindricalUV = applyCylindricalUV;
exports.applySphereUV = applySphereUV;
exports.geometry = geometry;
+691
View File
@@ -0,0 +1,691 @@
import { a as _defineProperty, _ as _objectSpread2 } from './objectSpread2-284232a6.esm.js';
import { _ as _classCallCheck } from './classCallCheck-9098b006.esm.js';
import { l as lerp, f as fade } from './misc-19a3ec46.esm.js';
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
/*
* A speed-improved perlin and simplex noise algorithms for 2D.
*
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
* Better rank ordering method by Stefan Gustavson in 2012.
* Converted to Javascript by Joseph Gentle.
*
* Version 2012-03-09
*
* This code was placed in the public domain by its original author,
* Stefan Gustavson. You may use it as you see fit, but
* attribution is appreciated.
*
*/
var Grad = function Grad(x, y, z) {
var _this = this;
_classCallCheck(this, Grad);
_defineProperty(this, "dot2", function (x, y) {
return _this.x * x + _this.y * y;
});
_defineProperty(this, "dot3", function (x, y, z) {
return _this.x * x + _this.y * y + _this.z * z;
});
this.x = x;
this.y = y;
this.z = z;
};
var grad3 = [new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0), new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1), new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)];
var p = [151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180]; // To remove the need for index wrapping, double the permutation table length
var perm = new Array(512);
var gradP = new Array(512); // This isn't a very good seeding function, but it works ok. It supports 2^16
// different seed values. Write something better if you need more seeds.
var seed = function seed(_seed) {
if (_seed > 0 && _seed < 1) {
// Scale the seed out
_seed *= 65536;
}
_seed = Math.floor(_seed);
if (_seed < 256) {
_seed |= _seed << 8;
}
for (var i = 0; i < 256; i++) {
var v;
if (i & 1) {
v = p[i] ^ _seed & 255;
} else {
v = p[i] ^ _seed >> 8 & 255;
}
perm[i] = perm[i + 256] = v;
gradP[i] = gradP[i + 256] = grad3[v % 12];
}
};
seed(0);
/*
for(var i=0; i<256; i++) {
perm[i] = perm[i + 256] = p[i];
gradP[i] = gradP[i + 256] = grad3[perm[i] % 12];
}*/
// Skewing and unskewing factors for 2, 3, and 4 dimensions
var F2 = 0.5 * (Math.sqrt(3) - 1);
var G2 = (3 - Math.sqrt(3)) / 6;
var F3 = 1 / 3;
var G3 = 1 / 6; // 2D simplex noise
var simplex2 = function simplex2(xin, yin) {
var n0, n1, n2; // Noise contributions from the three corners
// Skew the input space to determine which simplex cell we're in
var s = (xin + yin) * F2; // Hairy factor for 2D
var i = Math.floor(xin + s);
var j = Math.floor(yin + s);
var t = (i + j) * G2;
var x0 = xin - i + t; // The x,y distances from the cell origin, unskewed.
var y0 = yin - j + t; // For the 2D case, the simplex shape is an equilateral triangle.
// Determine which simplex we are in.
var i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
if (x0 > y0) {
// lower triangle, XY order: (0,0)->(1,0)->(1,1)
i1 = 1;
j1 = 0;
} else {
// upper triangle, YX order: (0,0)->(0,1)->(1,1)
i1 = 0;
j1 = 1;
} // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
// c = (3-sqrt(3))/6
var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
var y1 = y0 - j1 + G2;
var x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords
var y2 = y0 - 1 + 2 * G2; // Work out the hashed gradient indices of the three simplex corners
i &= 255;
j &= 255;
var gi0 = gradP[i + perm[j]];
var gi1 = gradP[i + i1 + perm[j + j1]];
var gi2 = gradP[i + 1 + perm[j + 1]]; // Calculate the contribution from the three corners
var t0 = 0.5 - x0 * x0 - y0 * y0;
if (t0 < 0) {
n0 = 0;
} else {
t0 *= t0;
n0 = t0 * t0 * gi0.dot2(x0, y0); // (x,y) of grad3 used for 2D gradient
}
var t1 = 0.5 - x1 * x1 - y1 * y1;
if (t1 < 0) {
n1 = 0;
} else {
t1 *= t1;
n1 = t1 * t1 * gi1.dot2(x1, y1);
}
var t2 = 0.5 - x2 * x2 - y2 * y2;
if (t2 < 0) {
n2 = 0;
} else {
t2 *= t2;
n2 = t2 * t2 * gi2.dot2(x2, y2);
} // Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 70 * (n0 + n1 + n2);
}; // 3D simplex noise
var simplex3 = function simplex3(xin, yin, zin) {
var n0, n1, n2, n3; // Noise contributions from the four corners
// Skew the input space to determine which simplex cell we're in
var s = (xin + yin + zin) * F3; // Hairy factor for 2D
var i = Math.floor(xin + s);
var j = Math.floor(yin + s);
var k = Math.floor(zin + s);
var t = (i + j + k) * G3;
var x0 = xin - i + t; // The x,y distances from the cell origin, unskewed.
var y0 = yin - j + t;
var z0 = zin - k + t; // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
// Determine which simplex we are in.
var i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
var i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
if (x0 >= y0) {
if (y0 >= z0) {
i1 = 1;
j1 = 0;
k1 = 0;
i2 = 1;
j2 = 1;
k2 = 0;
} else if (x0 >= z0) {
i1 = 1;
j1 = 0;
k1 = 0;
i2 = 1;
j2 = 0;
k2 = 1;
} else {
i1 = 0;
j1 = 0;
k1 = 1;
i2 = 1;
j2 = 0;
k2 = 1;
}
} else {
if (y0 < z0) {
i1 = 0;
j1 = 0;
k1 = 1;
i2 = 0;
j2 = 1;
k2 = 1;
} else if (x0 < z0) {
i1 = 0;
j1 = 1;
k1 = 0;
i2 = 0;
j2 = 1;
k2 = 1;
} else {
i1 = 0;
j1 = 1;
k1 = 0;
i2 = 1;
j2 = 1;
k2 = 0;
}
} // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
// c = 1/6.
var x1 = x0 - i1 + G3; // Offsets for second corner
var y1 = y0 - j1 + G3;
var z1 = z0 - k1 + G3;
var x2 = x0 - i2 + 2 * G3; // Offsets for third corner
var y2 = y0 - j2 + 2 * G3;
var z2 = z0 - k2 + 2 * G3;
var x3 = x0 - 1 + 3 * G3; // Offsets for fourth corner
var y3 = y0 - 1 + 3 * G3;
var z3 = z0 - 1 + 3 * G3; // Work out the hashed gradient indices of the four simplex corners
i &= 255;
j &= 255;
k &= 255;
var gi0 = gradP[i + perm[j + perm[k]]];
var gi1 = gradP[i + i1 + perm[j + j1 + perm[k + k1]]];
var gi2 = gradP[i + i2 + perm[j + j2 + perm[k + k2]]];
var gi3 = gradP[i + 1 + perm[j + 1 + perm[k + 1]]]; // Calculate the contribution from the four corners
var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
if (t0 < 0) {
n0 = 0;
} else {
t0 *= t0;
n0 = t0 * t0 * gi0.dot3(x0, y0, z0); // (x,y) of grad3 used for 2D gradient
}
var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
if (t1 < 0) {
n1 = 0;
} else {
t1 *= t1;
n1 = t1 * t1 * gi1.dot3(x1, y1, z1);
}
var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
if (t2 < 0) {
n2 = 0;
} else {
t2 *= t2;
n2 = t2 * t2 * gi2.dot3(x2, y2, z2);
}
var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
if (t3 < 0) {
n3 = 0;
} else {
t3 *= t3;
n3 = t3 * t3 * gi3.dot3(x3, y3, z3);
} // Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 32 * (n0 + n1 + n2 + n3);
}; // ##### Perlin noise stuff
// 2D Perlin Noise
var perlin2 = function perlin2(x, y) {
// Find unit grid cell containing point
var X = Math.floor(x),
Y = Math.floor(y); // Get relative xy coordinates of point within that cell
x = x - X;
y = y - Y; // Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255;
Y = Y & 255; // Calculate noise contributions from each of the four corners
var n00 = gradP[X + perm[Y]].dot2(x, y);
var n01 = gradP[X + perm[Y + 1]].dot2(x, y - 1);
var n10 = gradP[X + 1 + perm[Y]].dot2(x - 1, y);
var n11 = gradP[X + 1 + perm[Y + 1]].dot2(x - 1, y - 1); // Compute the fade curve value for x
var u = fade(x); // Interpolate the four results
return lerp(lerp(n00, n10, u), lerp(n01, n11, u), fade(y));
}; // 3D Perlin Noise
var perlin3 = function perlin3(x, y, z) {
// Find unit grid cell containing point
var X = Math.floor(x),
Y = Math.floor(y),
Z = Math.floor(z); // Get relative xyz coordinates of point within that cell
x = x - X;
y = y - Y;
z = z - Z; // Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255;
Y = Y & 255;
Z = Z & 255; // Calculate noise contributions from each of the eight corners
var n000 = gradP[X + perm[Y + perm[Z]]].dot3(x, y, z);
var n001 = gradP[X + perm[Y + perm[Z + 1]]].dot3(x, y, z - 1);
var n010 = gradP[X + perm[Y + 1 + perm[Z]]].dot3(x, y - 1, z);
var n011 = gradP[X + perm[Y + 1 + perm[Z + 1]]].dot3(x, y - 1, z - 1);
var n100 = gradP[X + 1 + perm[Y + perm[Z]]].dot3(x - 1, y, z);
var n101 = gradP[X + 1 + perm[Y + perm[Z + 1]]].dot3(x - 1, y, z - 1);
var n110 = gradP[X + 1 + perm[Y + 1 + perm[Z]]].dot3(x - 1, y - 1, z);
var n111 = gradP[X + 1 + perm[Y + 1 + perm[Z + 1]]].dot3(x - 1, y - 1, z - 1); // Compute the fade curve value for x, y, z
var u = fade(x);
var v = fade(y);
var w = fade(z); // Interpolate
return lerp(lerp(lerp(n000, n100, u), lerp(n001, n101, u), w), lerp(lerp(n010, n110, u), lerp(n011, n111, u), w), v);
};
var noise = /*#__PURE__*/Object.freeze({
__proto__: null,
seed: seed,
simplex2: simplex2,
simplex3: simplex3,
perlin2: perlin2,
perlin3: perlin3
});
var TAU = Math.PI * 2;
var FlashGen = /*#__PURE__*/function () {
function FlashGen(props) {
_classCallCheck(this, FlashGen);
_defineProperty(this, "nextBurstTime", 0);
_defineProperty(this, "nextFlashEndTime", 0);
_defineProperty(this, "flashesDone", 0);
_defineProperty(this, "isFlashing", false);
_defineProperty(this, "currentCount", 0);
_defineProperty(this, "flashIntensity", 0);
_defineProperty(this, "isDecaying", false);
_defineProperty(this, "autoBurst", true);
_defineProperty(this, "decaySpeed", 40);
_defineProperty(this, "minInterval", 5000);
_defineProperty(this, "maxInterval", 10000);
_defineProperty(this, "minDuration", 50);
_defineProperty(this, "maxDuration", 300);
_defineProperty(this, "count", 5);
Object.assign(this, props);
}
_createClass(FlashGen, [{
key: "scheduleNextBurst",
value: function scheduleNextBurst(currentTime) {
var burstInterval = Math.random() * (this.maxInterval - this.minInterval) + this.minInterval;
this.nextBurstTime = currentTime + burstInterval / 1000;
this.flashesDone = 0;
this.isFlashing = false;
}
}, {
key: "burst",
value: function burst() {
this.nextBurstTime = 0;
this.flashesDone = 0;
this.isFlashing = false;
}
}, {
key: "update",
value: function update(currentTime, delta) {
if (currentTime > this.nextBurstTime && this.currentCount === 0) {
this.currentCount = Math.floor(Math.random() * this.count) + 1;
}
if (this.flashesDone < this.currentCount && currentTime > this.nextBurstTime) {
if (!this.isFlashing) {
this.isFlashing = true;
this.flashIntensity = 1;
var flashDuration = Math.random() * (this.maxDuration - this.minDuration) + this.minDuration;
this.nextFlashEndTime = currentTime + flashDuration / 1000;
} else if (this.isFlashing && currentTime > this.nextFlashEndTime) {
this.isFlashing = false;
this.isDecaying = true;
this.flashesDone++;
if (this.flashesDone >= this.currentCount) {
this.currentCount = 0;
if (this.autoBurst) this.scheduleNextBurst(currentTime);
}
}
}
if (this.isDecaying) {
this.flashIntensity -= delta * this.decaySpeed;
this.flashIntensity = Math.max(0, Math.min(1, this.flashIntensity));
if (this.flashIntensity <= 0) {
this.isDecaying = false;
this.flashIntensity = 0;
}
}
return this.flashIntensity;
}
}]);
return FlashGen;
}(); // Credits @kchapelier https://github.com/kchapelier/wavefunctioncollapse/blob/master/example/lcg.js#L22-L30
function normalizeSeed(seed) {
if (typeof seed === "number") {
seed = Math.abs(seed);
} else if (typeof seed === "string") {
var string = seed;
seed = 0;
for (var i = 0; i < string.length; i++) {
seed = (seed + (i + 1) * (string.charCodeAt(i) % 96)) % 2147483647;
}
}
if (seed === 0) {
seed = 311;
}
return seed;
}
function lcgRandom(seed) {
var state = normalizeSeed(seed);
return function () {
var result = state * 48271 % 2147483647;
state = result;
return result / 2147483647;
};
}
var Generator = function Generator(_seed) {
var _this = this;
_classCallCheck(this, Generator);
_defineProperty(this, "seed", 0);
_defineProperty(this, "init", function (seed) {
_this.seed = seed;
_this.value = lcgRandom(seed);
});
_defineProperty(this, "value", lcgRandom(this.seed));
this.init(_seed);
};
var defaultGen = new Generator(Math.random());
/***
* [3D] Sphere
*/
var defaultSphere = {
radius: 1,
center: [0, 0, 0]
}; // random on surface of sphere
// - https://twitter.com/fermatslibrary/status/1430932503578226688
// - https://mathworld.wolfram.com/SpherePointPicking.html
function onSphere(buffer, sphere) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultSphere$sphere = _objectSpread2(_objectSpread2({}, defaultSphere), sphere),
radius = _defaultSphere$sphere.radius,
center = _defaultSphere$sphere.center;
for (var i = 0; i < buffer.length; i += 3) {
var u = rng.value();
var v = rng.value();
var theta = Math.acos(2 * v - 1);
var phi = TAU * u;
buffer[i] = Math.sin(theta) * Math.cos(phi) * radius + center[0];
buffer[i + 1] = Math.sin(theta) * Math.sin(phi) * radius + center[1];
buffer[i + 2] = Math.cos(theta) * radius + center[2];
}
return buffer;
} // from "Another Method" https://datagenetics.com/blog/january32020/index.html
function inSphere(buffer, sphere) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultSphere$sphere2 = _objectSpread2(_objectSpread2({}, defaultSphere), sphere),
radius = _defaultSphere$sphere2.radius,
center = _defaultSphere$sphere2.center;
for (var i = 0; i < buffer.length; i += 3) {
var u = Math.pow(rng.value(), 1 / 3);
var x = rng.value() * 2 - 1;
var y = rng.value() * 2 - 1;
var z = rng.value() * 2 - 1;
var mag = Math.sqrt(x * x + y * y + z * z);
x = u * x / mag;
y = u * y / mag;
z = u * z / mag;
buffer[i] = x * radius + center[0];
buffer[i + 1] = y * radius + center[1];
buffer[i + 2] = z * radius + center[2];
}
return buffer;
}
/***
* [2D] Circle
*/
var defaultCircle = {
radius: 1,
center: [0, 0]
}; // random circle https://stackoverflow.com/a/50746409
function inCircle(buffer, circle) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultCircle$circle = _objectSpread2(_objectSpread2({}, defaultCircle), circle),
radius = _defaultCircle$circle.radius,
center = _defaultCircle$circle.center;
for (var i = 0; i < buffer.length; i += 2) {
var r = radius * Math.sqrt(rng.value());
var theta = rng.value() * TAU;
buffer[i] = Math.sin(theta) * r + center[0];
buffer[i + 1] = Math.cos(theta) * r + center[1];
}
return buffer;
}
function onCircle(buffer, circle) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultCircle$circle2 = _objectSpread2(_objectSpread2({}, defaultCircle), circle),
radius = _defaultCircle$circle2.radius,
center = _defaultCircle$circle2.center;
for (var i = 0; i < buffer.length; i += 2) {
var theta = rng.value() * TAU;
buffer[i] = Math.sin(theta) * radius + center[0];
buffer[i + 1] = Math.cos(theta) * radius + center[1];
}
return buffer;
}
/**
* [2D] Plane
*/
var defaultRect = {
sides: 1,
center: [0, 0]
};
function inRect(buffer, rect) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultRect$rect = _objectSpread2(_objectSpread2({}, defaultRect), rect),
sides = _defaultRect$rect.sides,
center = _defaultRect$rect.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
for (var i = 0; i < buffer.length; i += 2) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
}
return buffer;
}
function onRect(buffer, rect) {
return buffer;
}
/***
* [3D] Box
*/
function inBox(buffer, box) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultBox$box = _objectSpread2(_objectSpread2({}, defaultBox), box),
sides = _defaultBox$box.sides,
center = _defaultBox$box.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
var sideZ = typeof sides === "number" ? sides : sides[2];
for (var i = 0; i < buffer.length; i += 3) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
buffer[i + 2] = (rng.value() - 0.5) * sideZ + center[2];
}
return buffer;
}
var defaultBox = {
sides: 1,
center: [0, 0, 0]
};
function onBox(buffer, box) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultBox$box2 = _objectSpread2(_objectSpread2({}, defaultBox), box),
sides = _defaultBox$box2.sides,
center = _defaultBox$box2.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
var sideZ = typeof sides === "number" ? sides : sides[2];
for (var i = 0; i < buffer.length; i += 3) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
buffer[i + 2] = (rng.value() - 0.5) * sideZ + center[2];
}
return buffer;
}
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
FlashGen: FlashGen,
Generator: Generator,
onSphere: onSphere,
inSphere: inSphere,
inCircle: inCircle,
onCircle: onCircle,
inRect: inRect,
onRect: onRect,
inBox: inBox,
onBox: onBox,
noise: noise
});
export { FlashGen as F, Generator as G, inSphere as a, inCircle as b, onCircle as c, inRect as d, onRect as e, inBox as f, onBox as g, index as i, noise as n, onSphere as o };
+704
View File
@@ -0,0 +1,704 @@
'use strict';
var objectSpread2 = require('./objectSpread2-32cd2c34.cjs.dev.js');
var classCallCheck = require('./classCallCheck-eaf0efc7.cjs.dev.js');
var misc_dist_maathMisc = require('./misc-fce4d494.cjs.dev.js');
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
/*
* A speed-improved perlin and simplex noise algorithms for 2D.
*
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
* Better rank ordering method by Stefan Gustavson in 2012.
* Converted to Javascript by Joseph Gentle.
*
* Version 2012-03-09
*
* This code was placed in the public domain by its original author,
* Stefan Gustavson. You may use it as you see fit, but
* attribution is appreciated.
*
*/
var Grad = function Grad(x, y, z) {
var _this = this;
classCallCheck._classCallCheck(this, Grad);
objectSpread2._defineProperty(this, "dot2", function (x, y) {
return _this.x * x + _this.y * y;
});
objectSpread2._defineProperty(this, "dot3", function (x, y, z) {
return _this.x * x + _this.y * y + _this.z * z;
});
this.x = x;
this.y = y;
this.z = z;
};
var grad3 = [new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0), new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1), new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)];
var p = [151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180]; // To remove the need for index wrapping, double the permutation table length
var perm = new Array(512);
var gradP = new Array(512); // This isn't a very good seeding function, but it works ok. It supports 2^16
// different seed values. Write something better if you need more seeds.
var seed = function seed(_seed) {
if (_seed > 0 && _seed < 1) {
// Scale the seed out
_seed *= 65536;
}
_seed = Math.floor(_seed);
if (_seed < 256) {
_seed |= _seed << 8;
}
for (var i = 0; i < 256; i++) {
var v;
if (i & 1) {
v = p[i] ^ _seed & 255;
} else {
v = p[i] ^ _seed >> 8 & 255;
}
perm[i] = perm[i + 256] = v;
gradP[i] = gradP[i + 256] = grad3[v % 12];
}
};
seed(0);
/*
for(var i=0; i<256; i++) {
perm[i] = perm[i + 256] = p[i];
gradP[i] = gradP[i + 256] = grad3[perm[i] % 12];
}*/
// Skewing and unskewing factors for 2, 3, and 4 dimensions
var F2 = 0.5 * (Math.sqrt(3) - 1);
var G2 = (3 - Math.sqrt(3)) / 6;
var F3 = 1 / 3;
var G3 = 1 / 6; // 2D simplex noise
var simplex2 = function simplex2(xin, yin) {
var n0, n1, n2; // Noise contributions from the three corners
// Skew the input space to determine which simplex cell we're in
var s = (xin + yin) * F2; // Hairy factor for 2D
var i = Math.floor(xin + s);
var j = Math.floor(yin + s);
var t = (i + j) * G2;
var x0 = xin - i + t; // The x,y distances from the cell origin, unskewed.
var y0 = yin - j + t; // For the 2D case, the simplex shape is an equilateral triangle.
// Determine which simplex we are in.
var i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
if (x0 > y0) {
// lower triangle, XY order: (0,0)->(1,0)->(1,1)
i1 = 1;
j1 = 0;
} else {
// upper triangle, YX order: (0,0)->(0,1)->(1,1)
i1 = 0;
j1 = 1;
} // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
// c = (3-sqrt(3))/6
var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
var y1 = y0 - j1 + G2;
var x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords
var y2 = y0 - 1 + 2 * G2; // Work out the hashed gradient indices of the three simplex corners
i &= 255;
j &= 255;
var gi0 = gradP[i + perm[j]];
var gi1 = gradP[i + i1 + perm[j + j1]];
var gi2 = gradP[i + 1 + perm[j + 1]]; // Calculate the contribution from the three corners
var t0 = 0.5 - x0 * x0 - y0 * y0;
if (t0 < 0) {
n0 = 0;
} else {
t0 *= t0;
n0 = t0 * t0 * gi0.dot2(x0, y0); // (x,y) of grad3 used for 2D gradient
}
var t1 = 0.5 - x1 * x1 - y1 * y1;
if (t1 < 0) {
n1 = 0;
} else {
t1 *= t1;
n1 = t1 * t1 * gi1.dot2(x1, y1);
}
var t2 = 0.5 - x2 * x2 - y2 * y2;
if (t2 < 0) {
n2 = 0;
} else {
t2 *= t2;
n2 = t2 * t2 * gi2.dot2(x2, y2);
} // Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 70 * (n0 + n1 + n2);
}; // 3D simplex noise
var simplex3 = function simplex3(xin, yin, zin) {
var n0, n1, n2, n3; // Noise contributions from the four corners
// Skew the input space to determine which simplex cell we're in
var s = (xin + yin + zin) * F3; // Hairy factor for 2D
var i = Math.floor(xin + s);
var j = Math.floor(yin + s);
var k = Math.floor(zin + s);
var t = (i + j + k) * G3;
var x0 = xin - i + t; // The x,y distances from the cell origin, unskewed.
var y0 = yin - j + t;
var z0 = zin - k + t; // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
// Determine which simplex we are in.
var i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
var i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
if (x0 >= y0) {
if (y0 >= z0) {
i1 = 1;
j1 = 0;
k1 = 0;
i2 = 1;
j2 = 1;
k2 = 0;
} else if (x0 >= z0) {
i1 = 1;
j1 = 0;
k1 = 0;
i2 = 1;
j2 = 0;
k2 = 1;
} else {
i1 = 0;
j1 = 0;
k1 = 1;
i2 = 1;
j2 = 0;
k2 = 1;
}
} else {
if (y0 < z0) {
i1 = 0;
j1 = 0;
k1 = 1;
i2 = 0;
j2 = 1;
k2 = 1;
} else if (x0 < z0) {
i1 = 0;
j1 = 1;
k1 = 0;
i2 = 0;
j2 = 1;
k2 = 1;
} else {
i1 = 0;
j1 = 1;
k1 = 0;
i2 = 1;
j2 = 1;
k2 = 0;
}
} // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
// c = 1/6.
var x1 = x0 - i1 + G3; // Offsets for second corner
var y1 = y0 - j1 + G3;
var z1 = z0 - k1 + G3;
var x2 = x0 - i2 + 2 * G3; // Offsets for third corner
var y2 = y0 - j2 + 2 * G3;
var z2 = z0 - k2 + 2 * G3;
var x3 = x0 - 1 + 3 * G3; // Offsets for fourth corner
var y3 = y0 - 1 + 3 * G3;
var z3 = z0 - 1 + 3 * G3; // Work out the hashed gradient indices of the four simplex corners
i &= 255;
j &= 255;
k &= 255;
var gi0 = gradP[i + perm[j + perm[k]]];
var gi1 = gradP[i + i1 + perm[j + j1 + perm[k + k1]]];
var gi2 = gradP[i + i2 + perm[j + j2 + perm[k + k2]]];
var gi3 = gradP[i + 1 + perm[j + 1 + perm[k + 1]]]; // Calculate the contribution from the four corners
var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
if (t0 < 0) {
n0 = 0;
} else {
t0 *= t0;
n0 = t0 * t0 * gi0.dot3(x0, y0, z0); // (x,y) of grad3 used for 2D gradient
}
var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
if (t1 < 0) {
n1 = 0;
} else {
t1 *= t1;
n1 = t1 * t1 * gi1.dot3(x1, y1, z1);
}
var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
if (t2 < 0) {
n2 = 0;
} else {
t2 *= t2;
n2 = t2 * t2 * gi2.dot3(x2, y2, z2);
}
var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
if (t3 < 0) {
n3 = 0;
} else {
t3 *= t3;
n3 = t3 * t3 * gi3.dot3(x3, y3, z3);
} // Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 32 * (n0 + n1 + n2 + n3);
}; // ##### Perlin noise stuff
// 2D Perlin Noise
var perlin2 = function perlin2(x, y) {
// Find unit grid cell containing point
var X = Math.floor(x),
Y = Math.floor(y); // Get relative xy coordinates of point within that cell
x = x - X;
y = y - Y; // Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255;
Y = Y & 255; // Calculate noise contributions from each of the four corners
var n00 = gradP[X + perm[Y]].dot2(x, y);
var n01 = gradP[X + perm[Y + 1]].dot2(x, y - 1);
var n10 = gradP[X + 1 + perm[Y]].dot2(x - 1, y);
var n11 = gradP[X + 1 + perm[Y + 1]].dot2(x - 1, y - 1); // Compute the fade curve value for x
var u = misc_dist_maathMisc.fade(x); // Interpolate the four results
return misc_dist_maathMisc.lerp(misc_dist_maathMisc.lerp(n00, n10, u), misc_dist_maathMisc.lerp(n01, n11, u), misc_dist_maathMisc.fade(y));
}; // 3D Perlin Noise
var perlin3 = function perlin3(x, y, z) {
// Find unit grid cell containing point
var X = Math.floor(x),
Y = Math.floor(y),
Z = Math.floor(z); // Get relative xyz coordinates of point within that cell
x = x - X;
y = y - Y;
z = z - Z; // Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255;
Y = Y & 255;
Z = Z & 255; // Calculate noise contributions from each of the eight corners
var n000 = gradP[X + perm[Y + perm[Z]]].dot3(x, y, z);
var n001 = gradP[X + perm[Y + perm[Z + 1]]].dot3(x, y, z - 1);
var n010 = gradP[X + perm[Y + 1 + perm[Z]]].dot3(x, y - 1, z);
var n011 = gradP[X + perm[Y + 1 + perm[Z + 1]]].dot3(x, y - 1, z - 1);
var n100 = gradP[X + 1 + perm[Y + perm[Z]]].dot3(x - 1, y, z);
var n101 = gradP[X + 1 + perm[Y + perm[Z + 1]]].dot3(x - 1, y, z - 1);
var n110 = gradP[X + 1 + perm[Y + 1 + perm[Z]]].dot3(x - 1, y - 1, z);
var n111 = gradP[X + 1 + perm[Y + 1 + perm[Z + 1]]].dot3(x - 1, y - 1, z - 1); // Compute the fade curve value for x, y, z
var u = misc_dist_maathMisc.fade(x);
var v = misc_dist_maathMisc.fade(y);
var w = misc_dist_maathMisc.fade(z); // Interpolate
return misc_dist_maathMisc.lerp(misc_dist_maathMisc.lerp(misc_dist_maathMisc.lerp(n000, n100, u), misc_dist_maathMisc.lerp(n001, n101, u), w), misc_dist_maathMisc.lerp(misc_dist_maathMisc.lerp(n010, n110, u), misc_dist_maathMisc.lerp(n011, n111, u), w), v);
};
var noise = /*#__PURE__*/Object.freeze({
__proto__: null,
seed: seed,
simplex2: simplex2,
simplex3: simplex3,
perlin2: perlin2,
perlin3: perlin3
});
var TAU = Math.PI * 2;
var FlashGen = /*#__PURE__*/function () {
function FlashGen(props) {
classCallCheck._classCallCheck(this, FlashGen);
objectSpread2._defineProperty(this, "nextBurstTime", 0);
objectSpread2._defineProperty(this, "nextFlashEndTime", 0);
objectSpread2._defineProperty(this, "flashesDone", 0);
objectSpread2._defineProperty(this, "isFlashing", false);
objectSpread2._defineProperty(this, "currentCount", 0);
objectSpread2._defineProperty(this, "flashIntensity", 0);
objectSpread2._defineProperty(this, "isDecaying", false);
objectSpread2._defineProperty(this, "autoBurst", true);
objectSpread2._defineProperty(this, "decaySpeed", 40);
objectSpread2._defineProperty(this, "minInterval", 5000);
objectSpread2._defineProperty(this, "maxInterval", 10000);
objectSpread2._defineProperty(this, "minDuration", 50);
objectSpread2._defineProperty(this, "maxDuration", 300);
objectSpread2._defineProperty(this, "count", 5);
Object.assign(this, props);
}
_createClass(FlashGen, [{
key: "scheduleNextBurst",
value: function scheduleNextBurst(currentTime) {
var burstInterval = Math.random() * (this.maxInterval - this.minInterval) + this.minInterval;
this.nextBurstTime = currentTime + burstInterval / 1000;
this.flashesDone = 0;
this.isFlashing = false;
}
}, {
key: "burst",
value: function burst() {
this.nextBurstTime = 0;
this.flashesDone = 0;
this.isFlashing = false;
}
}, {
key: "update",
value: function update(currentTime, delta) {
if (currentTime > this.nextBurstTime && this.currentCount === 0) {
this.currentCount = Math.floor(Math.random() * this.count) + 1;
}
if (this.flashesDone < this.currentCount && currentTime > this.nextBurstTime) {
if (!this.isFlashing) {
this.isFlashing = true;
this.flashIntensity = 1;
var flashDuration = Math.random() * (this.maxDuration - this.minDuration) + this.minDuration;
this.nextFlashEndTime = currentTime + flashDuration / 1000;
} else if (this.isFlashing && currentTime > this.nextFlashEndTime) {
this.isFlashing = false;
this.isDecaying = true;
this.flashesDone++;
if (this.flashesDone >= this.currentCount) {
this.currentCount = 0;
if (this.autoBurst) this.scheduleNextBurst(currentTime);
}
}
}
if (this.isDecaying) {
this.flashIntensity -= delta * this.decaySpeed;
this.flashIntensity = Math.max(0, Math.min(1, this.flashIntensity));
if (this.flashIntensity <= 0) {
this.isDecaying = false;
this.flashIntensity = 0;
}
}
return this.flashIntensity;
}
}]);
return FlashGen;
}(); // Credits @kchapelier https://github.com/kchapelier/wavefunctioncollapse/blob/master/example/lcg.js#L22-L30
function normalizeSeed(seed) {
if (typeof seed === "number") {
seed = Math.abs(seed);
} else if (typeof seed === "string") {
var string = seed;
seed = 0;
for (var i = 0; i < string.length; i++) {
seed = (seed + (i + 1) * (string.charCodeAt(i) % 96)) % 2147483647;
}
}
if (seed === 0) {
seed = 311;
}
return seed;
}
function lcgRandom(seed) {
var state = normalizeSeed(seed);
return function () {
var result = state * 48271 % 2147483647;
state = result;
return result / 2147483647;
};
}
var Generator = function Generator(_seed) {
var _this = this;
classCallCheck._classCallCheck(this, Generator);
objectSpread2._defineProperty(this, "seed", 0);
objectSpread2._defineProperty(this, "init", function (seed) {
_this.seed = seed;
_this.value = lcgRandom(seed);
});
objectSpread2._defineProperty(this, "value", lcgRandom(this.seed));
this.init(_seed);
};
var defaultGen = new Generator(Math.random());
/***
* [3D] Sphere
*/
var defaultSphere = {
radius: 1,
center: [0, 0, 0]
}; // random on surface of sphere
// - https://twitter.com/fermatslibrary/status/1430932503578226688
// - https://mathworld.wolfram.com/SpherePointPicking.html
function onSphere(buffer, sphere) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultSphere$sphere = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultSphere), sphere),
radius = _defaultSphere$sphere.radius,
center = _defaultSphere$sphere.center;
for (var i = 0; i < buffer.length; i += 3) {
var u = rng.value();
var v = rng.value();
var theta = Math.acos(2 * v - 1);
var phi = TAU * u;
buffer[i] = Math.sin(theta) * Math.cos(phi) * radius + center[0];
buffer[i + 1] = Math.sin(theta) * Math.sin(phi) * radius + center[1];
buffer[i + 2] = Math.cos(theta) * radius + center[2];
}
return buffer;
} // from "Another Method" https://datagenetics.com/blog/january32020/index.html
function inSphere(buffer, sphere) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultSphere$sphere2 = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultSphere), sphere),
radius = _defaultSphere$sphere2.radius,
center = _defaultSphere$sphere2.center;
for (var i = 0; i < buffer.length; i += 3) {
var u = Math.pow(rng.value(), 1 / 3);
var x = rng.value() * 2 - 1;
var y = rng.value() * 2 - 1;
var z = rng.value() * 2 - 1;
var mag = Math.sqrt(x * x + y * y + z * z);
x = u * x / mag;
y = u * y / mag;
z = u * z / mag;
buffer[i] = x * radius + center[0];
buffer[i + 1] = y * radius + center[1];
buffer[i + 2] = z * radius + center[2];
}
return buffer;
}
/***
* [2D] Circle
*/
var defaultCircle = {
radius: 1,
center: [0, 0]
}; // random circle https://stackoverflow.com/a/50746409
function inCircle(buffer, circle) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultCircle$circle = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultCircle), circle),
radius = _defaultCircle$circle.radius,
center = _defaultCircle$circle.center;
for (var i = 0; i < buffer.length; i += 2) {
var r = radius * Math.sqrt(rng.value());
var theta = rng.value() * TAU;
buffer[i] = Math.sin(theta) * r + center[0];
buffer[i + 1] = Math.cos(theta) * r + center[1];
}
return buffer;
}
function onCircle(buffer, circle) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultCircle$circle2 = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultCircle), circle),
radius = _defaultCircle$circle2.radius,
center = _defaultCircle$circle2.center;
for (var i = 0; i < buffer.length; i += 2) {
var theta = rng.value() * TAU;
buffer[i] = Math.sin(theta) * radius + center[0];
buffer[i + 1] = Math.cos(theta) * radius + center[1];
}
return buffer;
}
/**
* [2D] Plane
*/
var defaultRect = {
sides: 1,
center: [0, 0]
};
function inRect(buffer, rect) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultRect$rect = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultRect), rect),
sides = _defaultRect$rect.sides,
center = _defaultRect$rect.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
for (var i = 0; i < buffer.length; i += 2) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
}
return buffer;
}
function onRect(buffer, rect) {
return buffer;
}
/***
* [3D] Box
*/
function inBox(buffer, box) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultBox$box = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultBox), box),
sides = _defaultBox$box.sides,
center = _defaultBox$box.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
var sideZ = typeof sides === "number" ? sides : sides[2];
for (var i = 0; i < buffer.length; i += 3) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
buffer[i + 2] = (rng.value() - 0.5) * sideZ + center[2];
}
return buffer;
}
var defaultBox = {
sides: 1,
center: [0, 0, 0]
};
function onBox(buffer, box) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultBox$box2 = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultBox), box),
sides = _defaultBox$box2.sides,
center = _defaultBox$box2.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
var sideZ = typeof sides === "number" ? sides : sides[2];
for (var i = 0; i < buffer.length; i += 3) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
buffer[i + 2] = (rng.value() - 0.5) * sideZ + center[2];
}
return buffer;
}
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
FlashGen: FlashGen,
Generator: Generator,
onSphere: onSphere,
inSphere: inSphere,
inCircle: inCircle,
onCircle: onCircle,
inRect: inRect,
onRect: onRect,
inBox: inBox,
onBox: onBox,
noise: noise
});
exports.FlashGen = FlashGen;
exports.Generator = Generator;
exports.inBox = inBox;
exports.inCircle = inCircle;
exports.inRect = inRect;
exports.inSphere = inSphere;
exports.index = index;
exports.noise = noise;
exports.onBox = onBox;
exports.onCircle = onCircle;
exports.onRect = onRect;
exports.onSphere = onSphere;
+704
View File
@@ -0,0 +1,704 @@
'use strict';
var objectSpread2 = require('./objectSpread2-2ccd0bad.cjs.prod.js');
var classCallCheck = require('./classCallCheck-839aeb3a.cjs.prod.js');
var misc_dist_maathMisc = require('./misc-023d073b.cjs.prod.js');
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
/*
* A speed-improved perlin and simplex noise algorithms for 2D.
*
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
* Better rank ordering method by Stefan Gustavson in 2012.
* Converted to Javascript by Joseph Gentle.
*
* Version 2012-03-09
*
* This code was placed in the public domain by its original author,
* Stefan Gustavson. You may use it as you see fit, but
* attribution is appreciated.
*
*/
var Grad = function Grad(x, y, z) {
var _this = this;
classCallCheck._classCallCheck(this, Grad);
objectSpread2._defineProperty(this, "dot2", function (x, y) {
return _this.x * x + _this.y * y;
});
objectSpread2._defineProperty(this, "dot3", function (x, y, z) {
return _this.x * x + _this.y * y + _this.z * z;
});
this.x = x;
this.y = y;
this.z = z;
};
var grad3 = [new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0), new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1), new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)];
var p = [151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180]; // To remove the need for index wrapping, double the permutation table length
var perm = new Array(512);
var gradP = new Array(512); // This isn't a very good seeding function, but it works ok. It supports 2^16
// different seed values. Write something better if you need more seeds.
var seed = function seed(_seed) {
if (_seed > 0 && _seed < 1) {
// Scale the seed out
_seed *= 65536;
}
_seed = Math.floor(_seed);
if (_seed < 256) {
_seed |= _seed << 8;
}
for (var i = 0; i < 256; i++) {
var v;
if (i & 1) {
v = p[i] ^ _seed & 255;
} else {
v = p[i] ^ _seed >> 8 & 255;
}
perm[i] = perm[i + 256] = v;
gradP[i] = gradP[i + 256] = grad3[v % 12];
}
};
seed(0);
/*
for(var i=0; i<256; i++) {
perm[i] = perm[i + 256] = p[i];
gradP[i] = gradP[i + 256] = grad3[perm[i] % 12];
}*/
// Skewing and unskewing factors for 2, 3, and 4 dimensions
var F2 = 0.5 * (Math.sqrt(3) - 1);
var G2 = (3 - Math.sqrt(3)) / 6;
var F3 = 1 / 3;
var G3 = 1 / 6; // 2D simplex noise
var simplex2 = function simplex2(xin, yin) {
var n0, n1, n2; // Noise contributions from the three corners
// Skew the input space to determine which simplex cell we're in
var s = (xin + yin) * F2; // Hairy factor for 2D
var i = Math.floor(xin + s);
var j = Math.floor(yin + s);
var t = (i + j) * G2;
var x0 = xin - i + t; // The x,y distances from the cell origin, unskewed.
var y0 = yin - j + t; // For the 2D case, the simplex shape is an equilateral triangle.
// Determine which simplex we are in.
var i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
if (x0 > y0) {
// lower triangle, XY order: (0,0)->(1,0)->(1,1)
i1 = 1;
j1 = 0;
} else {
// upper triangle, YX order: (0,0)->(0,1)->(1,1)
i1 = 0;
j1 = 1;
} // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
// c = (3-sqrt(3))/6
var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
var y1 = y0 - j1 + G2;
var x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords
var y2 = y0 - 1 + 2 * G2; // Work out the hashed gradient indices of the three simplex corners
i &= 255;
j &= 255;
var gi0 = gradP[i + perm[j]];
var gi1 = gradP[i + i1 + perm[j + j1]];
var gi2 = gradP[i + 1 + perm[j + 1]]; // Calculate the contribution from the three corners
var t0 = 0.5 - x0 * x0 - y0 * y0;
if (t0 < 0) {
n0 = 0;
} else {
t0 *= t0;
n0 = t0 * t0 * gi0.dot2(x0, y0); // (x,y) of grad3 used for 2D gradient
}
var t1 = 0.5 - x1 * x1 - y1 * y1;
if (t1 < 0) {
n1 = 0;
} else {
t1 *= t1;
n1 = t1 * t1 * gi1.dot2(x1, y1);
}
var t2 = 0.5 - x2 * x2 - y2 * y2;
if (t2 < 0) {
n2 = 0;
} else {
t2 *= t2;
n2 = t2 * t2 * gi2.dot2(x2, y2);
} // Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 70 * (n0 + n1 + n2);
}; // 3D simplex noise
var simplex3 = function simplex3(xin, yin, zin) {
var n0, n1, n2, n3; // Noise contributions from the four corners
// Skew the input space to determine which simplex cell we're in
var s = (xin + yin + zin) * F3; // Hairy factor for 2D
var i = Math.floor(xin + s);
var j = Math.floor(yin + s);
var k = Math.floor(zin + s);
var t = (i + j + k) * G3;
var x0 = xin - i + t; // The x,y distances from the cell origin, unskewed.
var y0 = yin - j + t;
var z0 = zin - k + t; // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
// Determine which simplex we are in.
var i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
var i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
if (x0 >= y0) {
if (y0 >= z0) {
i1 = 1;
j1 = 0;
k1 = 0;
i2 = 1;
j2 = 1;
k2 = 0;
} else if (x0 >= z0) {
i1 = 1;
j1 = 0;
k1 = 0;
i2 = 1;
j2 = 0;
k2 = 1;
} else {
i1 = 0;
j1 = 0;
k1 = 1;
i2 = 1;
j2 = 0;
k2 = 1;
}
} else {
if (y0 < z0) {
i1 = 0;
j1 = 0;
k1 = 1;
i2 = 0;
j2 = 1;
k2 = 1;
} else if (x0 < z0) {
i1 = 0;
j1 = 1;
k1 = 0;
i2 = 0;
j2 = 1;
k2 = 1;
} else {
i1 = 0;
j1 = 1;
k1 = 0;
i2 = 1;
j2 = 1;
k2 = 0;
}
} // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
// c = 1/6.
var x1 = x0 - i1 + G3; // Offsets for second corner
var y1 = y0 - j1 + G3;
var z1 = z0 - k1 + G3;
var x2 = x0 - i2 + 2 * G3; // Offsets for third corner
var y2 = y0 - j2 + 2 * G3;
var z2 = z0 - k2 + 2 * G3;
var x3 = x0 - 1 + 3 * G3; // Offsets for fourth corner
var y3 = y0 - 1 + 3 * G3;
var z3 = z0 - 1 + 3 * G3; // Work out the hashed gradient indices of the four simplex corners
i &= 255;
j &= 255;
k &= 255;
var gi0 = gradP[i + perm[j + perm[k]]];
var gi1 = gradP[i + i1 + perm[j + j1 + perm[k + k1]]];
var gi2 = gradP[i + i2 + perm[j + j2 + perm[k + k2]]];
var gi3 = gradP[i + 1 + perm[j + 1 + perm[k + 1]]]; // Calculate the contribution from the four corners
var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
if (t0 < 0) {
n0 = 0;
} else {
t0 *= t0;
n0 = t0 * t0 * gi0.dot3(x0, y0, z0); // (x,y) of grad3 used for 2D gradient
}
var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
if (t1 < 0) {
n1 = 0;
} else {
t1 *= t1;
n1 = t1 * t1 * gi1.dot3(x1, y1, z1);
}
var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
if (t2 < 0) {
n2 = 0;
} else {
t2 *= t2;
n2 = t2 * t2 * gi2.dot3(x2, y2, z2);
}
var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
if (t3 < 0) {
n3 = 0;
} else {
t3 *= t3;
n3 = t3 * t3 * gi3.dot3(x3, y3, z3);
} // Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 32 * (n0 + n1 + n2 + n3);
}; // ##### Perlin noise stuff
// 2D Perlin Noise
var perlin2 = function perlin2(x, y) {
// Find unit grid cell containing point
var X = Math.floor(x),
Y = Math.floor(y); // Get relative xy coordinates of point within that cell
x = x - X;
y = y - Y; // Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255;
Y = Y & 255; // Calculate noise contributions from each of the four corners
var n00 = gradP[X + perm[Y]].dot2(x, y);
var n01 = gradP[X + perm[Y + 1]].dot2(x, y - 1);
var n10 = gradP[X + 1 + perm[Y]].dot2(x - 1, y);
var n11 = gradP[X + 1 + perm[Y + 1]].dot2(x - 1, y - 1); // Compute the fade curve value for x
var u = misc_dist_maathMisc.fade(x); // Interpolate the four results
return misc_dist_maathMisc.lerp(misc_dist_maathMisc.lerp(n00, n10, u), misc_dist_maathMisc.lerp(n01, n11, u), misc_dist_maathMisc.fade(y));
}; // 3D Perlin Noise
var perlin3 = function perlin3(x, y, z) {
// Find unit grid cell containing point
var X = Math.floor(x),
Y = Math.floor(y),
Z = Math.floor(z); // Get relative xyz coordinates of point within that cell
x = x - X;
y = y - Y;
z = z - Z; // Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255;
Y = Y & 255;
Z = Z & 255; // Calculate noise contributions from each of the eight corners
var n000 = gradP[X + perm[Y + perm[Z]]].dot3(x, y, z);
var n001 = gradP[X + perm[Y + perm[Z + 1]]].dot3(x, y, z - 1);
var n010 = gradP[X + perm[Y + 1 + perm[Z]]].dot3(x, y - 1, z);
var n011 = gradP[X + perm[Y + 1 + perm[Z + 1]]].dot3(x, y - 1, z - 1);
var n100 = gradP[X + 1 + perm[Y + perm[Z]]].dot3(x - 1, y, z);
var n101 = gradP[X + 1 + perm[Y + perm[Z + 1]]].dot3(x - 1, y, z - 1);
var n110 = gradP[X + 1 + perm[Y + 1 + perm[Z]]].dot3(x - 1, y - 1, z);
var n111 = gradP[X + 1 + perm[Y + 1 + perm[Z + 1]]].dot3(x - 1, y - 1, z - 1); // Compute the fade curve value for x, y, z
var u = misc_dist_maathMisc.fade(x);
var v = misc_dist_maathMisc.fade(y);
var w = misc_dist_maathMisc.fade(z); // Interpolate
return misc_dist_maathMisc.lerp(misc_dist_maathMisc.lerp(misc_dist_maathMisc.lerp(n000, n100, u), misc_dist_maathMisc.lerp(n001, n101, u), w), misc_dist_maathMisc.lerp(misc_dist_maathMisc.lerp(n010, n110, u), misc_dist_maathMisc.lerp(n011, n111, u), w), v);
};
var noise = /*#__PURE__*/Object.freeze({
__proto__: null,
seed: seed,
simplex2: simplex2,
simplex3: simplex3,
perlin2: perlin2,
perlin3: perlin3
});
var TAU = Math.PI * 2;
var FlashGen = /*#__PURE__*/function () {
function FlashGen(props) {
classCallCheck._classCallCheck(this, FlashGen);
objectSpread2._defineProperty(this, "nextBurstTime", 0);
objectSpread2._defineProperty(this, "nextFlashEndTime", 0);
objectSpread2._defineProperty(this, "flashesDone", 0);
objectSpread2._defineProperty(this, "isFlashing", false);
objectSpread2._defineProperty(this, "currentCount", 0);
objectSpread2._defineProperty(this, "flashIntensity", 0);
objectSpread2._defineProperty(this, "isDecaying", false);
objectSpread2._defineProperty(this, "autoBurst", true);
objectSpread2._defineProperty(this, "decaySpeed", 40);
objectSpread2._defineProperty(this, "minInterval", 5000);
objectSpread2._defineProperty(this, "maxInterval", 10000);
objectSpread2._defineProperty(this, "minDuration", 50);
objectSpread2._defineProperty(this, "maxDuration", 300);
objectSpread2._defineProperty(this, "count", 5);
Object.assign(this, props);
}
_createClass(FlashGen, [{
key: "scheduleNextBurst",
value: function scheduleNextBurst(currentTime) {
var burstInterval = Math.random() * (this.maxInterval - this.minInterval) + this.minInterval;
this.nextBurstTime = currentTime + burstInterval / 1000;
this.flashesDone = 0;
this.isFlashing = false;
}
}, {
key: "burst",
value: function burst() {
this.nextBurstTime = 0;
this.flashesDone = 0;
this.isFlashing = false;
}
}, {
key: "update",
value: function update(currentTime, delta) {
if (currentTime > this.nextBurstTime && this.currentCount === 0) {
this.currentCount = Math.floor(Math.random() * this.count) + 1;
}
if (this.flashesDone < this.currentCount && currentTime > this.nextBurstTime) {
if (!this.isFlashing) {
this.isFlashing = true;
this.flashIntensity = 1;
var flashDuration = Math.random() * (this.maxDuration - this.minDuration) + this.minDuration;
this.nextFlashEndTime = currentTime + flashDuration / 1000;
} else if (this.isFlashing && currentTime > this.nextFlashEndTime) {
this.isFlashing = false;
this.isDecaying = true;
this.flashesDone++;
if (this.flashesDone >= this.currentCount) {
this.currentCount = 0;
if (this.autoBurst) this.scheduleNextBurst(currentTime);
}
}
}
if (this.isDecaying) {
this.flashIntensity -= delta * this.decaySpeed;
this.flashIntensity = Math.max(0, Math.min(1, this.flashIntensity));
if (this.flashIntensity <= 0) {
this.isDecaying = false;
this.flashIntensity = 0;
}
}
return this.flashIntensity;
}
}]);
return FlashGen;
}(); // Credits @kchapelier https://github.com/kchapelier/wavefunctioncollapse/blob/master/example/lcg.js#L22-L30
function normalizeSeed(seed) {
if (typeof seed === "number") {
seed = Math.abs(seed);
} else if (typeof seed === "string") {
var string = seed;
seed = 0;
for (var i = 0; i < string.length; i++) {
seed = (seed + (i + 1) * (string.charCodeAt(i) % 96)) % 2147483647;
}
}
if (seed === 0) {
seed = 311;
}
return seed;
}
function lcgRandom(seed) {
var state = normalizeSeed(seed);
return function () {
var result = state * 48271 % 2147483647;
state = result;
return result / 2147483647;
};
}
var Generator = function Generator(_seed) {
var _this = this;
classCallCheck._classCallCheck(this, Generator);
objectSpread2._defineProperty(this, "seed", 0);
objectSpread2._defineProperty(this, "init", function (seed) {
_this.seed = seed;
_this.value = lcgRandom(seed);
});
objectSpread2._defineProperty(this, "value", lcgRandom(this.seed));
this.init(_seed);
};
var defaultGen = new Generator(Math.random());
/***
* [3D] Sphere
*/
var defaultSphere = {
radius: 1,
center: [0, 0, 0]
}; // random on surface of sphere
// - https://twitter.com/fermatslibrary/status/1430932503578226688
// - https://mathworld.wolfram.com/SpherePointPicking.html
function onSphere(buffer, sphere) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultSphere$sphere = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultSphere), sphere),
radius = _defaultSphere$sphere.radius,
center = _defaultSphere$sphere.center;
for (var i = 0; i < buffer.length; i += 3) {
var u = rng.value();
var v = rng.value();
var theta = Math.acos(2 * v - 1);
var phi = TAU * u;
buffer[i] = Math.sin(theta) * Math.cos(phi) * radius + center[0];
buffer[i + 1] = Math.sin(theta) * Math.sin(phi) * radius + center[1];
buffer[i + 2] = Math.cos(theta) * radius + center[2];
}
return buffer;
} // from "Another Method" https://datagenetics.com/blog/january32020/index.html
function inSphere(buffer, sphere) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultSphere$sphere2 = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultSphere), sphere),
radius = _defaultSphere$sphere2.radius,
center = _defaultSphere$sphere2.center;
for (var i = 0; i < buffer.length; i += 3) {
var u = Math.pow(rng.value(), 1 / 3);
var x = rng.value() * 2 - 1;
var y = rng.value() * 2 - 1;
var z = rng.value() * 2 - 1;
var mag = Math.sqrt(x * x + y * y + z * z);
x = u * x / mag;
y = u * y / mag;
z = u * z / mag;
buffer[i] = x * radius + center[0];
buffer[i + 1] = y * radius + center[1];
buffer[i + 2] = z * radius + center[2];
}
return buffer;
}
/***
* [2D] Circle
*/
var defaultCircle = {
radius: 1,
center: [0, 0]
}; // random circle https://stackoverflow.com/a/50746409
function inCircle(buffer, circle) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultCircle$circle = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultCircle), circle),
radius = _defaultCircle$circle.radius,
center = _defaultCircle$circle.center;
for (var i = 0; i < buffer.length; i += 2) {
var r = radius * Math.sqrt(rng.value());
var theta = rng.value() * TAU;
buffer[i] = Math.sin(theta) * r + center[0];
buffer[i + 1] = Math.cos(theta) * r + center[1];
}
return buffer;
}
function onCircle(buffer, circle) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultCircle$circle2 = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultCircle), circle),
radius = _defaultCircle$circle2.radius,
center = _defaultCircle$circle2.center;
for (var i = 0; i < buffer.length; i += 2) {
var theta = rng.value() * TAU;
buffer[i] = Math.sin(theta) * radius + center[0];
buffer[i + 1] = Math.cos(theta) * radius + center[1];
}
return buffer;
}
/**
* [2D] Plane
*/
var defaultRect = {
sides: 1,
center: [0, 0]
};
function inRect(buffer, rect) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultRect$rect = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultRect), rect),
sides = _defaultRect$rect.sides,
center = _defaultRect$rect.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
for (var i = 0; i < buffer.length; i += 2) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
}
return buffer;
}
function onRect(buffer, rect) {
return buffer;
}
/***
* [3D] Box
*/
function inBox(buffer, box) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultBox$box = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultBox), box),
sides = _defaultBox$box.sides,
center = _defaultBox$box.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
var sideZ = typeof sides === "number" ? sides : sides[2];
for (var i = 0; i < buffer.length; i += 3) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
buffer[i + 2] = (rng.value() - 0.5) * sideZ + center[2];
}
return buffer;
}
var defaultBox = {
sides: 1,
center: [0, 0, 0]
};
function onBox(buffer, box) {
var rng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGen;
var _defaultBox$box2 = objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, defaultBox), box),
sides = _defaultBox$box2.sides,
center = _defaultBox$box2.center;
var sideX = typeof sides === "number" ? sides : sides[0];
var sideY = typeof sides === "number" ? sides : sides[1];
var sideZ = typeof sides === "number" ? sides : sides[2];
for (var i = 0; i < buffer.length; i += 3) {
buffer[i] = (rng.value() - 0.5) * sideX + center[0];
buffer[i + 1] = (rng.value() - 0.5) * sideY + center[1];
buffer[i + 2] = (rng.value() - 0.5) * sideZ + center[2];
}
return buffer;
}
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
FlashGen: FlashGen,
Generator: Generator,
onSphere: onSphere,
inSphere: inSphere,
inCircle: inCircle,
onCircle: onCircle,
inRect: inRect,
onRect: onRect,
inBox: inBox,
onBox: onBox,
noise: noise
});
exports.FlashGen = FlashGen;
exports.Generator = Generator;
exports.inBox = inBox;
exports.inCircle = inCircle;
exports.inRect = inRect;
exports.inSphere = inSphere;
exports.index = index;
exports.noise = noise;
exports.onBox = onBox;
exports.onCircle = onCircle;
exports.onRect = onRect;
exports.onSphere = onSphere;
+23
View File
@@ -0,0 +1,23 @@
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
export { _setPrototypeOf as _, _isNativeReflectConstruct as a };
+26
View File
@@ -0,0 +1,26 @@
'use strict';
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
exports._isNativeReflectConstruct = _isNativeReflectConstruct;
exports._setPrototypeOf = _setPrototypeOf;
+26
View File
@@ -0,0 +1,26 @@
'use strict';
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
exports._isNativeReflectConstruct = _isNativeReflectConstruct;
exports._setPrototypeOf = _setPrototypeOf;
+1
View File
@@ -0,0 +1 @@
export * from "./declarations/src/index";
+31
View File
@@ -0,0 +1,31 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var buffer_dist_maathBuffer = require('./buffer-6b4e8456.cjs.dev.js');
var random_dist_maathRandom = require('./index-26fb8954.cjs.dev.js');
var easing_dist_maathEasing = require('./easing-104c3902.cjs.dev.js');
var geometry_dist_maathGeometry = require('./geometry-358de1c4.cjs.dev.js');
var matrix_dist_maathMatrix = require('./matrix-fb190f60.cjs.dev.js');
var misc_dist_maathMisc = require('./misc-fce4d494.cjs.dev.js');
var three_dist_maathThree = require('./three-87cc244e.cjs.dev.js');
var triangle_dist_maathTriangle = require('./triangle-33ffdfef.cjs.dev.js');
var vector2_dist_maathVector2 = require('./vector2-f44fd63e.cjs.dev.js');
var vector3_dist_maathVector3 = require('./vector3-5e723d1a.cjs.dev.js');
require('./objectSpread2-32cd2c34.cjs.dev.js');
require('three');
require('./classCallCheck-eaf0efc7.cjs.dev.js');
require('./isNativeReflectConstruct-ddc4ebc1.cjs.dev.js');
exports.buffer = buffer_dist_maathBuffer.buffer;
exports.random = random_dist_maathRandom.index;
exports.easing = easing_dist_maathEasing.easing;
exports.geometry = geometry_dist_maathGeometry.geometry;
exports.matrix = matrix_dist_maathMatrix.matrix;
exports.misc = misc_dist_maathMisc.misc;
exports.three = three_dist_maathThree.three;
exports.triangle = triangle_dist_maathTriangle.triangle;
exports.vector2 = vector2_dist_maathVector2.vector2;
exports.vector3 = vector3_dist_maathVector3.vector3;
+7
View File
@@ -0,0 +1,7 @@
'use strict';
if (process.env.NODE_ENV === "production") {
module.exports = require("./maath.cjs.prod.js");
} else {
module.exports = require("./maath.cjs.dev.js");
}
+31
View File
@@ -0,0 +1,31 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var buffer_dist_maathBuffer = require('./buffer-19702ccb.cjs.prod.js');
var random_dist_maathRandom = require('./index-b2e9bacc.cjs.prod.js');
var easing_dist_maathEasing = require('./easing-da79d042.cjs.prod.js');
var geometry_dist_maathGeometry = require('./geometry-8cc85b2d.cjs.prod.js');
var matrix_dist_maathMatrix = require('./matrix-e0b2acc5.cjs.prod.js');
var misc_dist_maathMisc = require('./misc-023d073b.cjs.prod.js');
var three_dist_maathThree = require('./three-225cfce4.cjs.prod.js');
var triangle_dist_maathTriangle = require('./triangle-9e5a8229.cjs.prod.js');
var vector2_dist_maathVector2 = require('./vector2-49e42f03.cjs.prod.js');
var vector3_dist_maathVector3 = require('./vector3-4bbdb053.cjs.prod.js');
require('./objectSpread2-2ccd0bad.cjs.prod.js');
require('three');
require('./classCallCheck-839aeb3a.cjs.prod.js');
require('./isNativeReflectConstruct-9acebf01.cjs.prod.js');
exports.buffer = buffer_dist_maathBuffer.buffer;
exports.random = random_dist_maathRandom.index;
exports.easing = easing_dist_maathEasing.easing;
exports.geometry = geometry_dist_maathGeometry.geometry;
exports.matrix = matrix_dist_maathMatrix.matrix;
exports.misc = misc_dist_maathMisc.misc;
exports.three = three_dist_maathThree.three;
exports.triangle = triangle_dist_maathTriangle.triangle;
exports.vector2 = vector2_dist_maathVector2.vector2;
exports.vector3 = vector3_dist_maathVector3.vector3;
+14
View File
@@ -0,0 +1,14 @@
export { b as buffer } from './buffer-59a95d05.esm.js';
export { i as random } from './index-0332b2ed.esm.js';
export { e as easing } from './easing-0f4db1c0.esm.js';
export { g as geometry } from './geometry-0fb11825.esm.js';
export { m as matrix } from './matrix-baa530bf.esm.js';
export { m as misc } from './misc-19a3ec46.esm.js';
export { t as three } from './three-eb2ad8c0.esm.js';
export { t as triangle } from './triangle-b62b9067.esm.js';
export { v as vector2 } from './vector2-d2bf51f1.esm.js';
export { v as vector3 } from './vector3-0a088b7f.esm.js';
import './objectSpread2-284232a6.esm.js';
import 'three';
import './classCallCheck-9098b006.esm.js';
import './isNativeReflectConstruct-5594d075.esm.js';
+147
View File
@@ -0,0 +1,147 @@
import { Matrix3 } from 'three';
/**
*
* @param terms
*
* | a b |
* | c d |
*
* @returns {number} determinant
*/
function determinant2() {
for (var _len = arguments.length, terms = new Array(_len), _key = 0; _key < _len; _key++) {
terms[_key] = arguments[_key];
}
var a = terms[0],
b = terms[1],
c = terms[2],
d = terms[3];
return a * d - b * c;
}
/**
*
* @param terms
*
* | a b c |
* | d e f |
* | g h i |
*
* @returns {number} determinant
*/
function determinant3() {
for (var _len2 = arguments.length, terms = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
terms[_key2] = arguments[_key2];
}
var a = terms[0],
b = terms[1],
c = terms[2],
d = terms[3],
e = terms[4],
f = terms[5],
g = terms[6],
h = terms[7],
i = terms[8];
return a * e * i + b * f * g + c * d * h - c * e * g - b * d * i - a * f * h;
}
/**
*
* @param terms
*
* | a b c g |
* | h i j k |
* | l m n o |
*
* @returns {number} determinant
*/
function determinant4() {
for (var _len3 = arguments.length, terms = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
terms[_key3] = arguments[_key3];
}
terms[0];
terms[1];
terms[2];
terms[3];
terms[4];
terms[5];
terms[6];
terms[7];
terms[8];
terms[9];
terms[10];
terms[11];
terms[12];
terms[13];
terms[14]; // TODO
}
/**
*
* Get the determinant of matrix m without row r and col c
*
* @param {matrix} m Starter matrix
* @param r row to remove
* @param c col to remove
*
* | a b c |
* m = | d e f |
* | g h i |
*
* getMinor(m, 1, 1) would result in this determinant
*
* | a c |
* | g i |
*
* @returns {number} determinant
*/
function getMinor(matrix, r, c) {
var _matrixTranspose = matrix.clone().transpose();
var x = [];
var l = _matrixTranspose.elements.length;
var n = Math.sqrt(l);
for (var i = 0; i < l; i++) {
var element = _matrixTranspose.elements[i];
var row = Math.floor(i / n);
var col = i % n;
if (row !== r - 1 && col !== c - 1) {
x.push(element);
}
}
return determinant3.apply(void 0, x);
}
/**
*
*/
function matrixSum3(m1, m2) {
var sum = [];
var m1Array = m1.toArray();
var m2Array = m2.toArray();
for (var i = 0; i < m1Array.length; i++) {
sum[i] = m1Array[i] + m2Array[i];
}
return new Matrix3().fromArray(sum);
}
var matrix = /*#__PURE__*/Object.freeze({
__proto__: null,
determinant2: determinant2,
determinant3: determinant3,
determinant4: determinant4,
getMinor: getMinor,
matrixSum3: matrixSum3
});
export { matrixSum3 as a, determinant2 as b, determinant4 as c, determinant3 as d, getMinor as g, matrix as m };
+154
View File
@@ -0,0 +1,154 @@
'use strict';
var THREE = require('three');
/**
*
* @param terms
*
* | a b |
* | c d |
*
* @returns {number} determinant
*/
function determinant2() {
for (var _len = arguments.length, terms = new Array(_len), _key = 0; _key < _len; _key++) {
terms[_key] = arguments[_key];
}
var a = terms[0],
b = terms[1],
c = terms[2],
d = terms[3];
return a * d - b * c;
}
/**
*
* @param terms
*
* | a b c |
* | d e f |
* | g h i |
*
* @returns {number} determinant
*/
function determinant3() {
for (var _len2 = arguments.length, terms = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
terms[_key2] = arguments[_key2];
}
var a = terms[0],
b = terms[1],
c = terms[2],
d = terms[3],
e = terms[4],
f = terms[5],
g = terms[6],
h = terms[7],
i = terms[8];
return a * e * i + b * f * g + c * d * h - c * e * g - b * d * i - a * f * h;
}
/**
*
* @param terms
*
* | a b c g |
* | h i j k |
* | l m n o |
*
* @returns {number} determinant
*/
function determinant4() {
for (var _len3 = arguments.length, terms = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
terms[_key3] = arguments[_key3];
}
terms[0];
terms[1];
terms[2];
terms[3];
terms[4];
terms[5];
terms[6];
terms[7];
terms[8];
terms[9];
terms[10];
terms[11];
terms[12];
terms[13];
terms[14]; // TODO
}
/**
*
* Get the determinant of matrix m without row r and col c
*
* @param {matrix} m Starter matrix
* @param r row to remove
* @param c col to remove
*
* | a b c |
* m = | d e f |
* | g h i |
*
* getMinor(m, 1, 1) would result in this determinant
*
* | a c |
* | g i |
*
* @returns {number} determinant
*/
function getMinor(matrix, r, c) {
var _matrixTranspose = matrix.clone().transpose();
var x = [];
var l = _matrixTranspose.elements.length;
var n = Math.sqrt(l);
for (var i = 0; i < l; i++) {
var element = _matrixTranspose.elements[i];
var row = Math.floor(i / n);
var col = i % n;
if (row !== r - 1 && col !== c - 1) {
x.push(element);
}
}
return determinant3.apply(void 0, x);
}
/**
*
*/
function matrixSum3(m1, m2) {
var sum = [];
var m1Array = m1.toArray();
var m2Array = m2.toArray();
for (var i = 0; i < m1Array.length; i++) {
sum[i] = m1Array[i] + m2Array[i];
}
return new THREE.Matrix3().fromArray(sum);
}
var matrix = /*#__PURE__*/Object.freeze({
__proto__: null,
determinant2: determinant2,
determinant3: determinant3,
determinant4: determinant4,
getMinor: getMinor,
matrixSum3: matrixSum3
});
exports.determinant2 = determinant2;
exports.determinant3 = determinant3;
exports.determinant4 = determinant4;
exports.getMinor = getMinor;
exports.matrix = matrix;
exports.matrixSum3 = matrixSum3;
+154
View File
@@ -0,0 +1,154 @@
'use strict';
var THREE = require('three');
/**
*
* @param terms
*
* | a b |
* | c d |
*
* @returns {number} determinant
*/
function determinant2() {
for (var _len = arguments.length, terms = new Array(_len), _key = 0; _key < _len; _key++) {
terms[_key] = arguments[_key];
}
var a = terms[0],
b = terms[1],
c = terms[2],
d = terms[3];
return a * d - b * c;
}
/**
*
* @param terms
*
* | a b c |
* | d e f |
* | g h i |
*
* @returns {number} determinant
*/
function determinant3() {
for (var _len2 = arguments.length, terms = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
terms[_key2] = arguments[_key2];
}
var a = terms[0],
b = terms[1],
c = terms[2],
d = terms[3],
e = terms[4],
f = terms[5],
g = terms[6],
h = terms[7],
i = terms[8];
return a * e * i + b * f * g + c * d * h - c * e * g - b * d * i - a * f * h;
}
/**
*
* @param terms
*
* | a b c g |
* | h i j k |
* | l m n o |
*
* @returns {number} determinant
*/
function determinant4() {
for (var _len3 = arguments.length, terms = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
terms[_key3] = arguments[_key3];
}
terms[0];
terms[1];
terms[2];
terms[3];
terms[4];
terms[5];
terms[6];
terms[7];
terms[8];
terms[9];
terms[10];
terms[11];
terms[12];
terms[13];
terms[14]; // TODO
}
/**
*
* Get the determinant of matrix m without row r and col c
*
* @param {matrix} m Starter matrix
* @param r row to remove
* @param c col to remove
*
* | a b c |
* m = | d e f |
* | g h i |
*
* getMinor(m, 1, 1) would result in this determinant
*
* | a c |
* | g i |
*
* @returns {number} determinant
*/
function getMinor(matrix, r, c) {
var _matrixTranspose = matrix.clone().transpose();
var x = [];
var l = _matrixTranspose.elements.length;
var n = Math.sqrt(l);
for (var i = 0; i < l; i++) {
var element = _matrixTranspose.elements[i];
var row = Math.floor(i / n);
var col = i % n;
if (row !== r - 1 && col !== c - 1) {
x.push(element);
}
}
return determinant3.apply(void 0, x);
}
/**
*
*/
function matrixSum3(m1, m2) {
var sum = [];
var m1Array = m1.toArray();
var m2Array = m2.toArray();
for (var i = 0; i < m1Array.length; i++) {
sum[i] = m1Array[i] + m2Array[i];
}
return new THREE.Matrix3().fromArray(sum);
}
var matrix = /*#__PURE__*/Object.freeze({
__proto__: null,
determinant2: determinant2,
determinant3: determinant3,
determinant4: determinant4,
getMinor: getMinor,
matrixSum3: matrixSum3
});
exports.determinant2 = determinant2;
exports.determinant3 = determinant3;
exports.determinant4 = determinant4;
exports.getMinor = getMinor;
exports.matrix = matrix;
exports.matrixSum3 = matrixSum3;
+340
View File
@@ -0,0 +1,340 @@
'use strict';
var triangle_dist_maathTriangle = require('./triangle-9e5a8229.cjs.prod.js');
var THREE = require('three');
var matrix_dist_maathMatrix = require('./matrix-e0b2acc5.cjs.prod.js');
/**
* Clamps a value between a range.
*/
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
} // Loops the value t, so that it is never larger than length and never smaller than 0.
function repeat(t, length) {
return clamp(t - Math.floor(t / length) * length, 0, length);
} // Calculates the shortest difference between two given angles.
function deltaAngle(current, target) {
var delta = repeat(target - current, Math.PI * 2);
if (delta > Math.PI) delta -= Math.PI * 2;
return delta;
}
/**
* Converts degrees to radians.
*/
function degToRad(degrees) {
return degrees / 180 * Math.PI;
}
/**
* Converts radians to degrees.
*/
function radToDeg(radians) {
return radians * 180 / Math.PI;
} // adapted from https://gist.github.com/stephanbogner/a5f50548a06bec723dcb0991dcbb0856 by https://twitter.com/st_phan
function fibonacciOnSphere(buffer, _ref) {
var _ref$radius = _ref.radius,
radius = _ref$radius === void 0 ? 1 : _ref$radius;
var samples = buffer.length / 3;
var offset = 2 / samples;
var increment = Math.PI * (3 - 2.2360679775);
for (var i = 0; i < buffer.length; i += 3) {
var y = i * offset - 1 + offset / 2;
var distance = Math.sqrt(1 - Math.pow(y, 2));
var phi = i % samples * increment;
var x = Math.cos(phi) * distance;
var z = Math.sin(phi) * distance;
buffer[i] = x * radius;
buffer[i + 1] = y * radius;
buffer[i + 2] = z * radius;
}
} // @ts-ignore
function vectorEquals(a, b) {
var eps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Number.EPSILON;
return Math.abs(a.x - b.x) < eps && Math.abs(a.y - b.y) < eps && Math.abs(a.z - b.z) < eps;
}
/**
* Sorts vectors in lexicographic order, works with both v2 and v3
*
* Use as:
* const sorted = arrayOfVectors.sort(lexicographicOrder)
*/
// https://en.wikipedia.org/wiki/Lexicographic_order
function lexicographic(a, b) {
if (a.x === b.x) {
// do a check to see if points is 3D,
// in which case add y eq check and sort by z
if (typeof a.z !== "undefined") {
if (a.y === b.y) {
return a.z - b.z;
}
}
return a.y - b.y;
}
return a.x - b.x;
}
/**
* Convex Hull
*
* Returns an array of 2D Vectors representing the convex hull of a set of 2D Vectors
*/
/**
* Calculate the convex hull of a set of points
*/
function convexHull(_points) {
var points = _points.sort(lexicographic); // put p1 and p2 in a list lUpper with p1 as the first point
var lUpper = [points[0], points[1]]; // for i <- 3 to n
for (var i = 2; i < points.length; i++) {
lUpper.push(points[i]); // while lUpper contains more than 2 points and the last three points in lUpper do not make a right turn
while (lUpper.length > 2 && triangle_dist_maathTriangle.doThreePointsMakeARight(triangle_dist_maathTriangle._toConsumableArray(lUpper.slice(-3)))) {
// delete the middle of the last three points from lUpper
lUpper.splice(lUpper.length - 2, 1);
}
} // put pn and pn-1 in a list lLower with pn as the first point
var lLower = [points[points.length - 1], points[points.length - 2]]; // for (i <- n - 2 downto 1)
for (var _i = points.length - 3; _i >= 0; _i--) {
// append pi to lLower
lLower.push(points[_i]); // while lLower contains more than 2 points and the last three points in lLower do not make a right turn
while (lLower.length > 2 && triangle_dist_maathTriangle.doThreePointsMakeARight(triangle_dist_maathTriangle._toConsumableArray(lLower.slice(-3)))) {
// delete the middle of the last three points from lLower
lLower.splice(lLower.length - 2, 1);
}
} // remove the first and last point from lLower to avoid duplication of the points where the upper and lower hull meet
lLower.splice(0, 1);
lLower.splice(lLower.length - 1, 1); // prettier-ignore
var c = [].concat(lUpper, lLower);
return c;
}
function remap(x, _ref2, _ref3) {
var _ref4 = triangle_dist_maathTriangle._slicedToArray(_ref2, 2),
low1 = _ref4[0],
high1 = _ref4[1];
var _ref5 = triangle_dist_maathTriangle._slicedToArray(_ref3, 2),
low2 = _ref5[0],
high2 = _ref5[1];
return low2 + (x - low1) * (high2 - low2) / (high1 - low1);
}
/**
*
* https://www.desmos.com/calculator/vsnmlaljdu
*
* Ease-in-out, goes to -Infinite before 0 and Infinite after 1
*
* @param t
* @returns
*/
function fade(t) {
return t * t * t * (t * (t * 6 - 15) + 10);
}
/**
*
* Returns the result of linearly interpolating between input A and input B by input T.
*
* @param v0
* @param v1
* @param t
* @returns
*/
function lerp(v0, v1, t) {
return v0 * (1 - t) + v1 * t;
}
/**
*
* Returns the linear parameter that produces the interpolant specified by input T within the range of input A to input B.
*
* @param v0
* @param v1
* @param t
* @returns
*/
function inverseLerp(v0, v1, t) {
return (t - v0) / (v1 - v0);
}
/**
*
*/
function normalize(x, y, z) {
var m = Math.sqrt(x * x + y * y + z * z);
return [x / m, y / m, z / m];
}
/**
*
*/
function pointOnCubeToPointOnSphere(x, y, z) {
var x2 = x * x;
var y2 = y * y;
var z2 = z * z;
var nx = x * Math.sqrt(1 - (y2 + z2) / 2 + y2 * z2 / 3);
var ny = y * Math.sqrt(1 - (z2 + x2) / 2 + z2 * x2 / 3);
var nz = z * Math.sqrt(1 - (x2 + y2) / 2 + x2 * y2 / 3);
return [nx, ny, nz];
} // https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d
/**
* Give two unit vectors a and b, returns the transformation matrix that rotates a onto b.
*
* */
function rotateVectorOnVector(a, b) {
var v = new THREE.Vector3().crossVectors(a, b);
var c = a.dot(b);
var i = new THREE.Matrix3().identity(); // skew-symmetric cross-product matrix of 𝑣 https://en.wikipedia.org/wiki/Skew-symmetric_matrix
// prettier-ignore
var vx = new THREE.Matrix3().set(0, -v.z, v.y, v.z, 0, -v.x, -v.y, v.x, 0);
var vxsquared = new THREE.Matrix3().multiplyMatrices(vx, vx).multiplyScalar(1 / (1 + c));
var _final = matrix_dist_maathMatrix.matrixSum3(matrix_dist_maathMatrix.matrixSum3(i, vx), vxsquared);
return _final;
} // calculate latitude and longitude (in radians) from point on unit sphere
function pointToCoordinate(x, y, z) {
var lat = Math.asin(y);
var lon = Math.atan2(x, -z);
return [lat, lon];
} // calculate point on unit sphere given latitude and logitude in radians
function coordinateToPoint(lat, lon) {
var y = Math.sin(lat);
var r = Math.cos(lat);
var x = Math.sin(lon) * r;
var z = -Math.cos(lon) * r;
return [x, y, z];
}
/**
* Given a plane and a segment, return the intersection point if it exists or null it doesn't.
*/
function planeSegmentIntersection(plane, segment) {
var _segment = triangle_dist_maathTriangle._slicedToArray(segment, 2),
a = _segment[0],
b = _segment[1];
var matrix = rotateVectorOnVector(plane.normal, new THREE.Vector3(0, 1, 0));
var t = inverseLerp(a.clone().applyMatrix3(matrix).y, b.clone().applyMatrix3(matrix).y, 0);
return new THREE.Vector3().lerpVectors(a, b, t);
}
/**
* Given a plane and a point, return the distance.
*/
function pointToPlaneDistance(p, plane) {
var d = plane.normal.dot(p); // TODO
return d;
}
function getIndexFrom3D(coords, sides) {
var _coords = triangle_dist_maathTriangle._slicedToArray(coords, 3),
ix = _coords[0],
iy = _coords[1],
iz = _coords[2];
var _sides = triangle_dist_maathTriangle._slicedToArray(sides, 2),
rx = _sides[0],
ry = _sides[1];
return iz * rx * ry + iy * rx + ix;
}
function get3DFromIndex(index, size) {
var _size = triangle_dist_maathTriangle._slicedToArray(size, 2),
rx = _size[0],
ry = _size[1];
var a = rx * ry;
var z = index / a;
var b = index - a * z;
var y = b / rx;
var x = b % rx;
return [x, y, z];
}
function getIndexFrom2D(coords, size) {
return coords[0] + size[0] * coords[1];
}
function get2DFromIndex(index, columns) {
var x = index % columns;
var y = Math.floor(index / columns);
return [x, y];
}
var misc = /*#__PURE__*/Object.freeze({
__proto__: null,
clamp: clamp,
repeat: repeat,
deltaAngle: deltaAngle,
degToRad: degToRad,
radToDeg: radToDeg,
fibonacciOnSphere: fibonacciOnSphere,
vectorEquals: vectorEquals,
lexicographic: lexicographic,
convexHull: convexHull,
remap: remap,
fade: fade,
lerp: lerp,
inverseLerp: inverseLerp,
normalize: normalize,
pointOnCubeToPointOnSphere: pointOnCubeToPointOnSphere,
rotateVectorOnVector: rotateVectorOnVector,
pointToCoordinate: pointToCoordinate,
coordinateToPoint: coordinateToPoint,
planeSegmentIntersection: planeSegmentIntersection,
pointToPlaneDistance: pointToPlaneDistance,
getIndexFrom3D: getIndexFrom3D,
get3DFromIndex: get3DFromIndex,
getIndexFrom2D: getIndexFrom2D,
get2DFromIndex: get2DFromIndex
});
exports.clamp = clamp;
exports.convexHull = convexHull;
exports.coordinateToPoint = coordinateToPoint;
exports.degToRad = degToRad;
exports.deltaAngle = deltaAngle;
exports.fade = fade;
exports.fibonacciOnSphere = fibonacciOnSphere;
exports.get2DFromIndex = get2DFromIndex;
exports.get3DFromIndex = get3DFromIndex;
exports.getIndexFrom2D = getIndexFrom2D;
exports.getIndexFrom3D = getIndexFrom3D;
exports.inverseLerp = inverseLerp;
exports.lerp = lerp;
exports.lexicographic = lexicographic;
exports.misc = misc;
exports.normalize = normalize;
exports.planeSegmentIntersection = planeSegmentIntersection;
exports.pointOnCubeToPointOnSphere = pointOnCubeToPointOnSphere;
exports.pointToCoordinate = pointToCoordinate;
exports.pointToPlaneDistance = pointToPlaneDistance;
exports.radToDeg = radToDeg;
exports.remap = remap;
exports.repeat = repeat;
exports.rotateVectorOnVector = rotateVectorOnVector;
exports.vectorEquals = vectorEquals;
+314
View File
@@ -0,0 +1,314 @@
import { d as doThreePointsMakeARight, a as _toConsumableArray, _ as _slicedToArray } from './triangle-b62b9067.esm.js';
import { Vector3, Matrix3 } from 'three';
import { a as matrixSum3 } from './matrix-baa530bf.esm.js';
/**
* Clamps a value between a range.
*/
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
} // Loops the value t, so that it is never larger than length and never smaller than 0.
function repeat(t, length) {
return clamp(t - Math.floor(t / length) * length, 0, length);
} // Calculates the shortest difference between two given angles.
function deltaAngle(current, target) {
var delta = repeat(target - current, Math.PI * 2);
if (delta > Math.PI) delta -= Math.PI * 2;
return delta;
}
/**
* Converts degrees to radians.
*/
function degToRad(degrees) {
return degrees / 180 * Math.PI;
}
/**
* Converts radians to degrees.
*/
function radToDeg(radians) {
return radians * 180 / Math.PI;
} // adapted from https://gist.github.com/stephanbogner/a5f50548a06bec723dcb0991dcbb0856 by https://twitter.com/st_phan
function fibonacciOnSphere(buffer, _ref) {
var _ref$radius = _ref.radius,
radius = _ref$radius === void 0 ? 1 : _ref$radius;
var samples = buffer.length / 3;
var offset = 2 / samples;
var increment = Math.PI * (3 - 2.2360679775);
for (var i = 0; i < buffer.length; i += 3) {
var y = i * offset - 1 + offset / 2;
var distance = Math.sqrt(1 - Math.pow(y, 2));
var phi = i % samples * increment;
var x = Math.cos(phi) * distance;
var z = Math.sin(phi) * distance;
buffer[i] = x * radius;
buffer[i + 1] = y * radius;
buffer[i + 2] = z * radius;
}
} // @ts-ignore
function vectorEquals(a, b) {
var eps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Number.EPSILON;
return Math.abs(a.x - b.x) < eps && Math.abs(a.y - b.y) < eps && Math.abs(a.z - b.z) < eps;
}
/**
* Sorts vectors in lexicographic order, works with both v2 and v3
*
* Use as:
* const sorted = arrayOfVectors.sort(lexicographicOrder)
*/
// https://en.wikipedia.org/wiki/Lexicographic_order
function lexicographic(a, b) {
if (a.x === b.x) {
// do a check to see if points is 3D,
// in which case add y eq check and sort by z
if (typeof a.z !== "undefined") {
if (a.y === b.y) {
return a.z - b.z;
}
}
return a.y - b.y;
}
return a.x - b.x;
}
/**
* Convex Hull
*
* Returns an array of 2D Vectors representing the convex hull of a set of 2D Vectors
*/
/**
* Calculate the convex hull of a set of points
*/
function convexHull(_points) {
var points = _points.sort(lexicographic); // put p1 and p2 in a list lUpper with p1 as the first point
var lUpper = [points[0], points[1]]; // for i <- 3 to n
for (var i = 2; i < points.length; i++) {
lUpper.push(points[i]); // while lUpper contains more than 2 points and the last three points in lUpper do not make a right turn
while (lUpper.length > 2 && doThreePointsMakeARight(_toConsumableArray(lUpper.slice(-3)))) {
// delete the middle of the last three points from lUpper
lUpper.splice(lUpper.length - 2, 1);
}
} // put pn and pn-1 in a list lLower with pn as the first point
var lLower = [points[points.length - 1], points[points.length - 2]]; // for (i <- n - 2 downto 1)
for (var _i = points.length - 3; _i >= 0; _i--) {
// append pi to lLower
lLower.push(points[_i]); // while lLower contains more than 2 points and the last three points in lLower do not make a right turn
while (lLower.length > 2 && doThreePointsMakeARight(_toConsumableArray(lLower.slice(-3)))) {
// delete the middle of the last three points from lLower
lLower.splice(lLower.length - 2, 1);
}
} // remove the first and last point from lLower to avoid duplication of the points where the upper and lower hull meet
lLower.splice(0, 1);
lLower.splice(lLower.length - 1, 1); // prettier-ignore
var c = [].concat(lUpper, lLower);
return c;
}
function remap(x, _ref2, _ref3) {
var _ref4 = _slicedToArray(_ref2, 2),
low1 = _ref4[0],
high1 = _ref4[1];
var _ref5 = _slicedToArray(_ref3, 2),
low2 = _ref5[0],
high2 = _ref5[1];
return low2 + (x - low1) * (high2 - low2) / (high1 - low1);
}
/**
*
* https://www.desmos.com/calculator/vsnmlaljdu
*
* Ease-in-out, goes to -Infinite before 0 and Infinite after 1
*
* @param t
* @returns
*/
function fade(t) {
return t * t * t * (t * (t * 6 - 15) + 10);
}
/**
*
* Returns the result of linearly interpolating between input A and input B by input T.
*
* @param v0
* @param v1
* @param t
* @returns
*/
function lerp(v0, v1, t) {
return v0 * (1 - t) + v1 * t;
}
/**
*
* Returns the linear parameter that produces the interpolant specified by input T within the range of input A to input B.
*
* @param v0
* @param v1
* @param t
* @returns
*/
function inverseLerp(v0, v1, t) {
return (t - v0) / (v1 - v0);
}
/**
*
*/
function normalize(x, y, z) {
var m = Math.sqrt(x * x + y * y + z * z);
return [x / m, y / m, z / m];
}
/**
*
*/
function pointOnCubeToPointOnSphere(x, y, z) {
var x2 = x * x;
var y2 = y * y;
var z2 = z * z;
var nx = x * Math.sqrt(1 - (y2 + z2) / 2 + y2 * z2 / 3);
var ny = y * Math.sqrt(1 - (z2 + x2) / 2 + z2 * x2 / 3);
var nz = z * Math.sqrt(1 - (x2 + y2) / 2 + x2 * y2 / 3);
return [nx, ny, nz];
} // https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d
/**
* Give two unit vectors a and b, returns the transformation matrix that rotates a onto b.
*
* */
function rotateVectorOnVector(a, b) {
var v = new Vector3().crossVectors(a, b);
var c = a.dot(b);
var i = new Matrix3().identity(); // skew-symmetric cross-product matrix of 𝑣 https://en.wikipedia.org/wiki/Skew-symmetric_matrix
// prettier-ignore
var vx = new Matrix3().set(0, -v.z, v.y, v.z, 0, -v.x, -v.y, v.x, 0);
var vxsquared = new Matrix3().multiplyMatrices(vx, vx).multiplyScalar(1 / (1 + c));
var _final = matrixSum3(matrixSum3(i, vx), vxsquared);
return _final;
} // calculate latitude and longitude (in radians) from point on unit sphere
function pointToCoordinate(x, y, z) {
var lat = Math.asin(y);
var lon = Math.atan2(x, -z);
return [lat, lon];
} // calculate point on unit sphere given latitude and logitude in radians
function coordinateToPoint(lat, lon) {
var y = Math.sin(lat);
var r = Math.cos(lat);
var x = Math.sin(lon) * r;
var z = -Math.cos(lon) * r;
return [x, y, z];
}
/**
* Given a plane and a segment, return the intersection point if it exists or null it doesn't.
*/
function planeSegmentIntersection(plane, segment) {
var _segment = _slicedToArray(segment, 2),
a = _segment[0],
b = _segment[1];
var matrix = rotateVectorOnVector(plane.normal, new Vector3(0, 1, 0));
var t = inverseLerp(a.clone().applyMatrix3(matrix).y, b.clone().applyMatrix3(matrix).y, 0);
return new Vector3().lerpVectors(a, b, t);
}
/**
* Given a plane and a point, return the distance.
*/
function pointToPlaneDistance(p, plane) {
var d = plane.normal.dot(p); // TODO
return d;
}
function getIndexFrom3D(coords, sides) {
var _coords = _slicedToArray(coords, 3),
ix = _coords[0],
iy = _coords[1],
iz = _coords[2];
var _sides = _slicedToArray(sides, 2),
rx = _sides[0],
ry = _sides[1];
return iz * rx * ry + iy * rx + ix;
}
function get3DFromIndex(index, size) {
var _size = _slicedToArray(size, 2),
rx = _size[0],
ry = _size[1];
var a = rx * ry;
var z = index / a;
var b = index - a * z;
var y = b / rx;
var x = b % rx;
return [x, y, z];
}
function getIndexFrom2D(coords, size) {
return coords[0] + size[0] * coords[1];
}
function get2DFromIndex(index, columns) {
var x = index % columns;
var y = Math.floor(index / columns);
return [x, y];
}
var misc = /*#__PURE__*/Object.freeze({
__proto__: null,
clamp: clamp,
repeat: repeat,
deltaAngle: deltaAngle,
degToRad: degToRad,
radToDeg: radToDeg,
fibonacciOnSphere: fibonacciOnSphere,
vectorEquals: vectorEquals,
lexicographic: lexicographic,
convexHull: convexHull,
remap: remap,
fade: fade,
lerp: lerp,
inverseLerp: inverseLerp,
normalize: normalize,
pointOnCubeToPointOnSphere: pointOnCubeToPointOnSphere,
rotateVectorOnVector: rotateVectorOnVector,
pointToCoordinate: pointToCoordinate,
coordinateToPoint: coordinateToPoint,
planeSegmentIntersection: planeSegmentIntersection,
pointToPlaneDistance: pointToPlaneDistance,
getIndexFrom3D: getIndexFrom3D,
get3DFromIndex: get3DFromIndex,
getIndexFrom2D: getIndexFrom2D,
get2DFromIndex: get2DFromIndex
});
export { degToRad as a, radToDeg as b, clamp as c, deltaAngle as d, fibonacciOnSphere as e, fade as f, lexicographic as g, convexHull as h, remap as i, inverseLerp as j, rotateVectorOnVector as k, lerp as l, misc as m, normalize as n, pointToCoordinate as o, pointOnCubeToPointOnSphere as p, coordinateToPoint as q, repeat as r, planeSegmentIntersection as s, pointToPlaneDistance as t, getIndexFrom3D as u, vectorEquals as v, get3DFromIndex as w, getIndexFrom2D as x, get2DFromIndex as y };
+340
View File
@@ -0,0 +1,340 @@
'use strict';
var triangle_dist_maathTriangle = require('./triangle-33ffdfef.cjs.dev.js');
var THREE = require('three');
var matrix_dist_maathMatrix = require('./matrix-fb190f60.cjs.dev.js');
/**
* Clamps a value between a range.
*/
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
} // Loops the value t, so that it is never larger than length and never smaller than 0.
function repeat(t, length) {
return clamp(t - Math.floor(t / length) * length, 0, length);
} // Calculates the shortest difference between two given angles.
function deltaAngle(current, target) {
var delta = repeat(target - current, Math.PI * 2);
if (delta > Math.PI) delta -= Math.PI * 2;
return delta;
}
/**
* Converts degrees to radians.
*/
function degToRad(degrees) {
return degrees / 180 * Math.PI;
}
/**
* Converts radians to degrees.
*/
function radToDeg(radians) {
return radians * 180 / Math.PI;
} // adapted from https://gist.github.com/stephanbogner/a5f50548a06bec723dcb0991dcbb0856 by https://twitter.com/st_phan
function fibonacciOnSphere(buffer, _ref) {
var _ref$radius = _ref.radius,
radius = _ref$radius === void 0 ? 1 : _ref$radius;
var samples = buffer.length / 3;
var offset = 2 / samples;
var increment = Math.PI * (3 - 2.2360679775);
for (var i = 0; i < buffer.length; i += 3) {
var y = i * offset - 1 + offset / 2;
var distance = Math.sqrt(1 - Math.pow(y, 2));
var phi = i % samples * increment;
var x = Math.cos(phi) * distance;
var z = Math.sin(phi) * distance;
buffer[i] = x * radius;
buffer[i + 1] = y * radius;
buffer[i + 2] = z * radius;
}
} // @ts-ignore
function vectorEquals(a, b) {
var eps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Number.EPSILON;
return Math.abs(a.x - b.x) < eps && Math.abs(a.y - b.y) < eps && Math.abs(a.z - b.z) < eps;
}
/**
* Sorts vectors in lexicographic order, works with both v2 and v3
*
* Use as:
* const sorted = arrayOfVectors.sort(lexicographicOrder)
*/
// https://en.wikipedia.org/wiki/Lexicographic_order
function lexicographic(a, b) {
if (a.x === b.x) {
// do a check to see if points is 3D,
// in which case add y eq check and sort by z
if (typeof a.z !== "undefined") {
if (a.y === b.y) {
return a.z - b.z;
}
}
return a.y - b.y;
}
return a.x - b.x;
}
/**
* Convex Hull
*
* Returns an array of 2D Vectors representing the convex hull of a set of 2D Vectors
*/
/**
* Calculate the convex hull of a set of points
*/
function convexHull(_points) {
var points = _points.sort(lexicographic); // put p1 and p2 in a list lUpper with p1 as the first point
var lUpper = [points[0], points[1]]; // for i <- 3 to n
for (var i = 2; i < points.length; i++) {
lUpper.push(points[i]); // while lUpper contains more than 2 points and the last three points in lUpper do not make a right turn
while (lUpper.length > 2 && triangle_dist_maathTriangle.doThreePointsMakeARight(triangle_dist_maathTriangle._toConsumableArray(lUpper.slice(-3)))) {
// delete the middle of the last three points from lUpper
lUpper.splice(lUpper.length - 2, 1);
}
} // put pn and pn-1 in a list lLower with pn as the first point
var lLower = [points[points.length - 1], points[points.length - 2]]; // for (i <- n - 2 downto 1)
for (var _i = points.length - 3; _i >= 0; _i--) {
// append pi to lLower
lLower.push(points[_i]); // while lLower contains more than 2 points and the last three points in lLower do not make a right turn
while (lLower.length > 2 && triangle_dist_maathTriangle.doThreePointsMakeARight(triangle_dist_maathTriangle._toConsumableArray(lLower.slice(-3)))) {
// delete the middle of the last three points from lLower
lLower.splice(lLower.length - 2, 1);
}
} // remove the first and last point from lLower to avoid duplication of the points where the upper and lower hull meet
lLower.splice(0, 1);
lLower.splice(lLower.length - 1, 1); // prettier-ignore
var c = [].concat(lUpper, lLower);
return c;
}
function remap(x, _ref2, _ref3) {
var _ref4 = triangle_dist_maathTriangle._slicedToArray(_ref2, 2),
low1 = _ref4[0],
high1 = _ref4[1];
var _ref5 = triangle_dist_maathTriangle._slicedToArray(_ref3, 2),
low2 = _ref5[0],
high2 = _ref5[1];
return low2 + (x - low1) * (high2 - low2) / (high1 - low1);
}
/**
*
* https://www.desmos.com/calculator/vsnmlaljdu
*
* Ease-in-out, goes to -Infinite before 0 and Infinite after 1
*
* @param t
* @returns
*/
function fade(t) {
return t * t * t * (t * (t * 6 - 15) + 10);
}
/**
*
* Returns the result of linearly interpolating between input A and input B by input T.
*
* @param v0
* @param v1
* @param t
* @returns
*/
function lerp(v0, v1, t) {
return v0 * (1 - t) + v1 * t;
}
/**
*
* Returns the linear parameter that produces the interpolant specified by input T within the range of input A to input B.
*
* @param v0
* @param v1
* @param t
* @returns
*/
function inverseLerp(v0, v1, t) {
return (t - v0) / (v1 - v0);
}
/**
*
*/
function normalize(x, y, z) {
var m = Math.sqrt(x * x + y * y + z * z);
return [x / m, y / m, z / m];
}
/**
*
*/
function pointOnCubeToPointOnSphere(x, y, z) {
var x2 = x * x;
var y2 = y * y;
var z2 = z * z;
var nx = x * Math.sqrt(1 - (y2 + z2) / 2 + y2 * z2 / 3);
var ny = y * Math.sqrt(1 - (z2 + x2) / 2 + z2 * x2 / 3);
var nz = z * Math.sqrt(1 - (x2 + y2) / 2 + x2 * y2 / 3);
return [nx, ny, nz];
} // https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d
/**
* Give two unit vectors a and b, returns the transformation matrix that rotates a onto b.
*
* */
function rotateVectorOnVector(a, b) {
var v = new THREE.Vector3().crossVectors(a, b);
var c = a.dot(b);
var i = new THREE.Matrix3().identity(); // skew-symmetric cross-product matrix of 𝑣 https://en.wikipedia.org/wiki/Skew-symmetric_matrix
// prettier-ignore
var vx = new THREE.Matrix3().set(0, -v.z, v.y, v.z, 0, -v.x, -v.y, v.x, 0);
var vxsquared = new THREE.Matrix3().multiplyMatrices(vx, vx).multiplyScalar(1 / (1 + c));
var _final = matrix_dist_maathMatrix.matrixSum3(matrix_dist_maathMatrix.matrixSum3(i, vx), vxsquared);
return _final;
} // calculate latitude and longitude (in radians) from point on unit sphere
function pointToCoordinate(x, y, z) {
var lat = Math.asin(y);
var lon = Math.atan2(x, -z);
return [lat, lon];
} // calculate point on unit sphere given latitude and logitude in radians
function coordinateToPoint(lat, lon) {
var y = Math.sin(lat);
var r = Math.cos(lat);
var x = Math.sin(lon) * r;
var z = -Math.cos(lon) * r;
return [x, y, z];
}
/**
* Given a plane and a segment, return the intersection point if it exists or null it doesn't.
*/
function planeSegmentIntersection(plane, segment) {
var _segment = triangle_dist_maathTriangle._slicedToArray(segment, 2),
a = _segment[0],
b = _segment[1];
var matrix = rotateVectorOnVector(plane.normal, new THREE.Vector3(0, 1, 0));
var t = inverseLerp(a.clone().applyMatrix3(matrix).y, b.clone().applyMatrix3(matrix).y, 0);
return new THREE.Vector3().lerpVectors(a, b, t);
}
/**
* Given a plane and a point, return the distance.
*/
function pointToPlaneDistance(p, plane) {
var d = plane.normal.dot(p); // TODO
return d;
}
function getIndexFrom3D(coords, sides) {
var _coords = triangle_dist_maathTriangle._slicedToArray(coords, 3),
ix = _coords[0],
iy = _coords[1],
iz = _coords[2];
var _sides = triangle_dist_maathTriangle._slicedToArray(sides, 2),
rx = _sides[0],
ry = _sides[1];
return iz * rx * ry + iy * rx + ix;
}
function get3DFromIndex(index, size) {
var _size = triangle_dist_maathTriangle._slicedToArray(size, 2),
rx = _size[0],
ry = _size[1];
var a = rx * ry;
var z = index / a;
var b = index - a * z;
var y = b / rx;
var x = b % rx;
return [x, y, z];
}
function getIndexFrom2D(coords, size) {
return coords[0] + size[0] * coords[1];
}
function get2DFromIndex(index, columns) {
var x = index % columns;
var y = Math.floor(index / columns);
return [x, y];
}
var misc = /*#__PURE__*/Object.freeze({
__proto__: null,
clamp: clamp,
repeat: repeat,
deltaAngle: deltaAngle,
degToRad: degToRad,
radToDeg: radToDeg,
fibonacciOnSphere: fibonacciOnSphere,
vectorEquals: vectorEquals,
lexicographic: lexicographic,
convexHull: convexHull,
remap: remap,
fade: fade,
lerp: lerp,
inverseLerp: inverseLerp,
normalize: normalize,
pointOnCubeToPointOnSphere: pointOnCubeToPointOnSphere,
rotateVectorOnVector: rotateVectorOnVector,
pointToCoordinate: pointToCoordinate,
coordinateToPoint: coordinateToPoint,
planeSegmentIntersection: planeSegmentIntersection,
pointToPlaneDistance: pointToPlaneDistance,
getIndexFrom3D: getIndexFrom3D,
get3DFromIndex: get3DFromIndex,
getIndexFrom2D: getIndexFrom2D,
get2DFromIndex: get2DFromIndex
});
exports.clamp = clamp;
exports.convexHull = convexHull;
exports.coordinateToPoint = coordinateToPoint;
exports.degToRad = degToRad;
exports.deltaAngle = deltaAngle;
exports.fade = fade;
exports.fibonacciOnSphere = fibonacciOnSphere;
exports.get2DFromIndex = get2DFromIndex;
exports.get3DFromIndex = get3DFromIndex;
exports.getIndexFrom2D = getIndexFrom2D;
exports.getIndexFrom3D = getIndexFrom3D;
exports.inverseLerp = inverseLerp;
exports.lerp = lerp;
exports.lexicographic = lexicographic;
exports.misc = misc;
exports.normalize = normalize;
exports.planeSegmentIntersection = planeSegmentIntersection;
exports.pointOnCubeToPointOnSphere = pointOnCubeToPointOnSphere;
exports.pointToCoordinate = pointToCoordinate;
exports.pointToPlaneDistance = pointToPlaneDistance;
exports.radToDeg = radToDeg;
exports.remap = remap;
exports.repeat = repeat;
exports.rotateVectorOnVector = rotateVectorOnVector;
exports.vectorEquals = vectorEquals;
+54
View File
@@ -0,0 +1,54 @@
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
export { _objectSpread2 as _, _defineProperty as a };
+57
View File
@@ -0,0 +1,57 @@
'use strict';
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
exports._defineProperty = _defineProperty;
exports._objectSpread2 = _objectSpread2;
+57
View File
@@ -0,0 +1,57 @@
'use strict';
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
exports._defineProperty = _defineProperty;
exports._objectSpread2 = _objectSpread2;
+63
View File
@@ -0,0 +1,63 @@
'use strict';
var THREE = require('three');
/**
* Helpers for converting buffers to and from Three.js objects
*/
/**
* Convents passed buffer of passed stride to an array of vectors with the correct length.
*
* @param buffer
* @param stride
* @returns
*/
function bufferToVectors(buffer) {
var stride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
var p = [];
for (var i = 0, j = 0; i < buffer.length; i += stride, j++) {
if (stride === 3) {
p[j] = new THREE.Vector3(buffer[i], buffer[i + 1], buffer[i + 2]);
} else {
p[j] = new THREE.Vector2(buffer[i], buffer[i + 1]);
}
}
return p;
}
/**
* Transforms a passed Vector2 or Vector3 array to a points buffer
*
* @param vectorArray
* @returns
*/
function vectorsToBuffer(vectorArray) {
var l = vectorArray.length;
var stride = vectorArray[0].hasOwnProperty("z") ? 3 : 2;
var buffer = new Float32Array(l * stride);
for (var i = 0; i < l; i++) {
var j = i * stride;
buffer[j] = vectorArray[i].x;
buffer[j + 1] = vectorArray[i].y;
if (stride === 3) {
buffer[j + 2] = vectorArray[i].z;
}
}
return buffer;
}
var three = /*#__PURE__*/Object.freeze({
__proto__: null,
bufferToVectors: bufferToVectors,
vectorsToBuffer: vectorsToBuffer
});
exports.bufferToVectors = bufferToVectors;
exports.three = three;
exports.vectorsToBuffer = vectorsToBuffer;
+63
View File
@@ -0,0 +1,63 @@
'use strict';
var THREE = require('three');
/**
* Helpers for converting buffers to and from Three.js objects
*/
/**
* Convents passed buffer of passed stride to an array of vectors with the correct length.
*
* @param buffer
* @param stride
* @returns
*/
function bufferToVectors(buffer) {
var stride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
var p = [];
for (var i = 0, j = 0; i < buffer.length; i += stride, j++) {
if (stride === 3) {
p[j] = new THREE.Vector3(buffer[i], buffer[i + 1], buffer[i + 2]);
} else {
p[j] = new THREE.Vector2(buffer[i], buffer[i + 1]);
}
}
return p;
}
/**
* Transforms a passed Vector2 or Vector3 array to a points buffer
*
* @param vectorArray
* @returns
*/
function vectorsToBuffer(vectorArray) {
var l = vectorArray.length;
var stride = vectorArray[0].hasOwnProperty("z") ? 3 : 2;
var buffer = new Float32Array(l * stride);
for (var i = 0; i < l; i++) {
var j = i * stride;
buffer[j] = vectorArray[i].x;
buffer[j + 1] = vectorArray[i].y;
if (stride === 3) {
buffer[j + 2] = vectorArray[i].z;
}
}
return buffer;
}
var three = /*#__PURE__*/Object.freeze({
__proto__: null,
bufferToVectors: bufferToVectors,
vectorsToBuffer: vectorsToBuffer
});
exports.bufferToVectors = bufferToVectors;
exports.three = three;
exports.vectorsToBuffer = vectorsToBuffer;
+59
View File
@@ -0,0 +1,59 @@
import { Vector3, Vector2 } from 'three';
/**
* Helpers for converting buffers to and from Three.js objects
*/
/**
* Convents passed buffer of passed stride to an array of vectors with the correct length.
*
* @param buffer
* @param stride
* @returns
*/
function bufferToVectors(buffer) {
var stride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
var p = [];
for (var i = 0, j = 0; i < buffer.length; i += stride, j++) {
if (stride === 3) {
p[j] = new Vector3(buffer[i], buffer[i + 1], buffer[i + 2]);
} else {
p[j] = new Vector2(buffer[i], buffer[i + 1]);
}
}
return p;
}
/**
* Transforms a passed Vector2 or Vector3 array to a points buffer
*
* @param vectorArray
* @returns
*/
function vectorsToBuffer(vectorArray) {
var l = vectorArray.length;
var stride = vectorArray[0].hasOwnProperty("z") ? 3 : 2;
var buffer = new Float32Array(l * stride);
for (var i = 0; i < l; i++) {
var j = i * stride;
buffer[j] = vectorArray[i].x;
buffer[j + 1] = vectorArray[i].y;
if (stride === 3) {
buffer[j + 2] = vectorArray[i].z;
}
}
return buffer;
}
var three = /*#__PURE__*/Object.freeze({
__proto__: null,
bufferToVectors: bufferToVectors,
vectorsToBuffer: vectorsToBuffer
});
export { bufferToVectors as b, three as t, vectorsToBuffer as v };
+333
View File
@@ -0,0 +1,333 @@
'use strict';
var isNativeReflectConstruct = require('./isNativeReflectConstruct-ddc4ebc1.cjs.dev.js');
var THREE = require('three');
var matrix_dist_maathMatrix = require('./matrix-fb190f60.cjs.dev.js');
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _construct(Parent, args, Class) {
if (isNativeReflectConstruct._isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) isNativeReflectConstruct._setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
/**
*
* @param point
*
* @param triangle
*
* @returns {boolean} true if the point is in the triangle
*
* TODO: Find explainer
*/
function isPointInTriangle(point, triangle) {
var _triangle$ = _slicedToArray(triangle[0], 2),
ax = _triangle$[0],
ay = _triangle$[1];
var _triangle$2 = _slicedToArray(triangle[1], 2),
bx = _triangle$2[0],
by = _triangle$2[1];
var _triangle$3 = _slicedToArray(triangle[2], 2),
cx = _triangle$3[0],
cy = _triangle$3[1];
var _point = _slicedToArray(point, 2),
px = _point[0],
py = _point[1]; // TODO Sub with static calc
var matrix = new THREE.Matrix4(); // prettier-ignore
matrix.set(ax, ay, ax * ax + ay * ay, 1, bx, by, bx * bx + by * by, 1, cx, cy, cx * cx + cy * cy, 1, px, py, px * px + py * py, 1);
return matrix.determinant() <= 0;
}
function triangleDeterminant(triangle) {
var _triangle$4 = _slicedToArray(triangle[0], 2),
x1 = _triangle$4[0],
y1 = _triangle$4[1];
var _triangle$5 = _slicedToArray(triangle[1], 2),
x2 = _triangle$5[0],
y2 = _triangle$5[1];
var _triangle$6 = _slicedToArray(triangle[2], 2),
x3 = _triangle$6[0],
y3 = _triangle$6[1]; // prettier-ignore
return matrix_dist_maathMatrix.determinant3(x1, y1, 1, x2, y2, 1, x3, y3, 1);
}
/**
* Uses triangle area determinant to check if 3 points are collinear.
* If they are, they can't make a triangle, so the determinant will be 0!
*
* 0 1 2
* ─────■─────■─────■
*
*
* Fun fact, you can use this same determinant to check the order of the points in the triangle
*
* NOTE: Should this use a buffer instead? NOTE: Should this use a buffer instead? [x0, y0, x1, y1, x2, y2]?
*
*/
function arePointsCollinear(points) {
return triangleDeterminant(points) === 0;
} // TODO This is the same principle as the prev function, find a way to make it have sense
function isTriangleClockwise(triangle) {
return triangleDeterminant(triangle) < 0;
}
/**
The circumcircle is a circle touching all the vertices of a triangle or polygon.
┌───┐
│ B │
└───┘
.───●───.
,─' ╲ '─.
,' ╲ `.
╱ ╱ ╲ ╲
; ╱ ╲ :
│ ╱ ╲ │
│ ╱ ╲ │
: ╱ ╲ ;
╲ ╱ ╲ ╱
┌───┐ ●─────────────────● ┌───┐
│ A │ `. ,' │ C │
└───┘ '─. ,─' └───┘
`─────'
*/
/**
*
* @param triangle
*
* @returns {number} circumcircle
*/
// https://math.stackexchange.com/a/1460096
function getCircumcircle(triangle) {
// TS-TODO the next few lines are ignored because the types aren't current to the change in vectors (that can now be iterated)
// @ts-ignore
var _triangle$7 = _slicedToArray(triangle[0], 2),
ax = _triangle$7[0],
ay = _triangle$7[1]; // @ts-ignore
var _triangle$8 = _slicedToArray(triangle[1], 2),
bx = _triangle$8[0],
by = _triangle$8[1]; // @ts-ignore
var _triangle$9 = _slicedToArray(triangle[2], 2),
cx = _triangle$9[0],
cy = _triangle$9[1];
if (arePointsCollinear(triangle)) return null; // points are collinear
var m = new THREE.Matrix4(); // prettier-ignore
m.set(1, 1, 1, 1, ax * ax + ay * ay, ax, ay, 1, bx * bx + by * by, bx, by, 1, cx * cx + cy * cy, cx, cy, 1);
var m11 = matrix_dist_maathMatrix.getMinor(m, 1, 1);
var m13 = matrix_dist_maathMatrix.getMinor(m, 1, 3);
var m12 = matrix_dist_maathMatrix.getMinor(m, 1, 2);
var m14 = matrix_dist_maathMatrix.getMinor(m, 1, 4);
var x0 = 0.5 * (m12 / m11);
var y0 = 0.5 * (m13 / m11);
var r2 = x0 * x0 + y0 * y0 + m14 / m11;
return {
x: Math.abs(x0) === 0 ? 0 : x0,
y: Math.abs(y0) === 0 ? 0 : -y0,
r: Math.sqrt(r2)
};
} // https://stackoverflow.com/questions/39984709/how-can-i-check-wether-a-point-is-inside-the-circumcircle-of-3-points
function isPointInCircumcircle(point, triangle) {
var _ref = Array.isArray(triangle[0]) ? triangle[0] : triangle[0].toArray(),
_ref2 = _slicedToArray(_ref, 2),
ax = _ref2[0],
ay = _ref2[1];
var _ref3 = Array.isArray(triangle[1]) ? triangle[1] : triangle[1].toArray(),
_ref4 = _slicedToArray(_ref3, 2),
bx = _ref4[0],
by = _ref4[1];
var _ref5 = Array.isArray(triangle[2]) ? triangle[2] : triangle[2].toArray(),
_ref6 = _slicedToArray(_ref5, 2),
cx = _ref6[0],
cy = _ref6[1];
var _point2 = _slicedToArray(point, 2),
px = _point2[0],
py = _point2[1];
if (arePointsCollinear(triangle)) throw new Error("Collinear points don't form a triangle");
/**
| ax-px, ay-py, (ax-px)² + (ay-py)² |
det = | bx-px, by-py, (bx-px)² + (by-py)² |
| cx-px, cy-py, (cx-px)² + (cy-py)² |
*/
var x1mpx = ax - px;
var aympy = ay - py;
var bxmpx = bx - px;
var bympy = by - py;
var cxmpx = cx - px;
var cympy = cy - py; // prettier-ignore
var d = matrix_dist_maathMatrix.determinant3(x1mpx, aympy, x1mpx * x1mpx + aympy * aympy, bxmpx, bympy, bxmpx * bxmpx + bympy * bympy, cxmpx, cympy, cxmpx * cxmpx + cympy * cympy); // if d is 0, the point is on C
if (d === 0) {
return true;
}
return !isTriangleClockwise(triangle) ? d > 0 : d < 0;
} // From https://algorithmtutor.com/Computational-Geometry/Determining-if-two-consecutive-segments-turn-left-or-right/
var mv1 = new THREE.Vector2();
var mv2 = new THREE.Vector2();
/**
▕ ▏
right left
* NOTE: Should this use a buffer instead? [x0, y0, x1, y1]?
*/
function doThreePointsMakeARight(points) {
var _points$map = points.map(function (p) {
if (Array.isArray(p)) {
return _construct(THREE.Vector2, _toConsumableArray(p));
}
return p;
}),
_points$map2 = _slicedToArray(_points$map, 3),
p1 = _points$map2[0],
p2 = _points$map2[1],
p3 = _points$map2[2];
if (arePointsCollinear(points)) return false; // @ts-ignore
var p2p1 = mv1.subVectors(p2, p1); // @ts-ignore
var p3p1 = mv2.subVectors(p3, p1);
var cross = p3p1.cross(p2p1);
return cross > 0;
}
var triangle = /*#__PURE__*/Object.freeze({
__proto__: null,
isPointInTriangle: isPointInTriangle,
triangleDeterminant: triangleDeterminant,
arePointsCollinear: arePointsCollinear,
isTriangleClockwise: isTriangleClockwise,
getCircumcircle: getCircumcircle,
isPointInCircumcircle: isPointInCircumcircle,
doThreePointsMakeARight: doThreePointsMakeARight
});
exports._slicedToArray = _slicedToArray;
exports._toConsumableArray = _toConsumableArray;
exports.arePointsCollinear = arePointsCollinear;
exports.doThreePointsMakeARight = doThreePointsMakeARight;
exports.getCircumcircle = getCircumcircle;
exports.isPointInCircumcircle = isPointInCircumcircle;
exports.isPointInTriangle = isPointInTriangle;
exports.isTriangleClockwise = isTriangleClockwise;
exports.triangle = triangle;
exports.triangleDeterminant = triangleDeterminant;
+333
View File
@@ -0,0 +1,333 @@
'use strict';
var isNativeReflectConstruct = require('./isNativeReflectConstruct-9acebf01.cjs.prod.js');
var THREE = require('three');
var matrix_dist_maathMatrix = require('./matrix-e0b2acc5.cjs.prod.js');
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _construct(Parent, args, Class) {
if (isNativeReflectConstruct._isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) isNativeReflectConstruct._setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
/**
*
* @param point
*
* @param triangle
*
* @returns {boolean} true if the point is in the triangle
*
* TODO: Find explainer
*/
function isPointInTriangle(point, triangle) {
var _triangle$ = _slicedToArray(triangle[0], 2),
ax = _triangle$[0],
ay = _triangle$[1];
var _triangle$2 = _slicedToArray(triangle[1], 2),
bx = _triangle$2[0],
by = _triangle$2[1];
var _triangle$3 = _slicedToArray(triangle[2], 2),
cx = _triangle$3[0],
cy = _triangle$3[1];
var _point = _slicedToArray(point, 2),
px = _point[0],
py = _point[1]; // TODO Sub with static calc
var matrix = new THREE.Matrix4(); // prettier-ignore
matrix.set(ax, ay, ax * ax + ay * ay, 1, bx, by, bx * bx + by * by, 1, cx, cy, cx * cx + cy * cy, 1, px, py, px * px + py * py, 1);
return matrix.determinant() <= 0;
}
function triangleDeterminant(triangle) {
var _triangle$4 = _slicedToArray(triangle[0], 2),
x1 = _triangle$4[0],
y1 = _triangle$4[1];
var _triangle$5 = _slicedToArray(triangle[1], 2),
x2 = _triangle$5[0],
y2 = _triangle$5[1];
var _triangle$6 = _slicedToArray(triangle[2], 2),
x3 = _triangle$6[0],
y3 = _triangle$6[1]; // prettier-ignore
return matrix_dist_maathMatrix.determinant3(x1, y1, 1, x2, y2, 1, x3, y3, 1);
}
/**
* Uses triangle area determinant to check if 3 points are collinear.
* If they are, they can't make a triangle, so the determinant will be 0!
*
* 0 1 2
* ─────■─────■─────■
*
*
* Fun fact, you can use this same determinant to check the order of the points in the triangle
*
* NOTE: Should this use a buffer instead? NOTE: Should this use a buffer instead? [x0, y0, x1, y1, x2, y2]?
*
*/
function arePointsCollinear(points) {
return triangleDeterminant(points) === 0;
} // TODO This is the same principle as the prev function, find a way to make it have sense
function isTriangleClockwise(triangle) {
return triangleDeterminant(triangle) < 0;
}
/**
The circumcircle is a circle touching all the vertices of a triangle or polygon.
┌───┐
│ B │
└───┘
.───●───.
,─' ╲ '─.
,' ╲ `.
╱ ╱ ╲ ╲
; ╱ ╲ :
│ ╱ ╲ │
│ ╱ ╲ │
: ╱ ╲ ;
╲ ╱ ╲ ╱
┌───┐ ●─────────────────● ┌───┐
│ A │ `. ,' │ C │
└───┘ '─. ,─' └───┘
`─────'
*/
/**
*
* @param triangle
*
* @returns {number} circumcircle
*/
// https://math.stackexchange.com/a/1460096
function getCircumcircle(triangle) {
// TS-TODO the next few lines are ignored because the types aren't current to the change in vectors (that can now be iterated)
// @ts-ignore
var _triangle$7 = _slicedToArray(triangle[0], 2),
ax = _triangle$7[0],
ay = _triangle$7[1]; // @ts-ignore
var _triangle$8 = _slicedToArray(triangle[1], 2),
bx = _triangle$8[0],
by = _triangle$8[1]; // @ts-ignore
var _triangle$9 = _slicedToArray(triangle[2], 2),
cx = _triangle$9[0],
cy = _triangle$9[1];
if (arePointsCollinear(triangle)) return null; // points are collinear
var m = new THREE.Matrix4(); // prettier-ignore
m.set(1, 1, 1, 1, ax * ax + ay * ay, ax, ay, 1, bx * bx + by * by, bx, by, 1, cx * cx + cy * cy, cx, cy, 1);
var m11 = matrix_dist_maathMatrix.getMinor(m, 1, 1);
var m13 = matrix_dist_maathMatrix.getMinor(m, 1, 3);
var m12 = matrix_dist_maathMatrix.getMinor(m, 1, 2);
var m14 = matrix_dist_maathMatrix.getMinor(m, 1, 4);
var x0 = 0.5 * (m12 / m11);
var y0 = 0.5 * (m13 / m11);
var r2 = x0 * x0 + y0 * y0 + m14 / m11;
return {
x: Math.abs(x0) === 0 ? 0 : x0,
y: Math.abs(y0) === 0 ? 0 : -y0,
r: Math.sqrt(r2)
};
} // https://stackoverflow.com/questions/39984709/how-can-i-check-wether-a-point-is-inside-the-circumcircle-of-3-points
function isPointInCircumcircle(point, triangle) {
var _ref = Array.isArray(triangle[0]) ? triangle[0] : triangle[0].toArray(),
_ref2 = _slicedToArray(_ref, 2),
ax = _ref2[0],
ay = _ref2[1];
var _ref3 = Array.isArray(triangle[1]) ? triangle[1] : triangle[1].toArray(),
_ref4 = _slicedToArray(_ref3, 2),
bx = _ref4[0],
by = _ref4[1];
var _ref5 = Array.isArray(triangle[2]) ? triangle[2] : triangle[2].toArray(),
_ref6 = _slicedToArray(_ref5, 2),
cx = _ref6[0],
cy = _ref6[1];
var _point2 = _slicedToArray(point, 2),
px = _point2[0],
py = _point2[1];
if (arePointsCollinear(triangle)) throw new Error("Collinear points don't form a triangle");
/**
| ax-px, ay-py, (ax-px)² + (ay-py)² |
det = | bx-px, by-py, (bx-px)² + (by-py)² |
| cx-px, cy-py, (cx-px)² + (cy-py)² |
*/
var x1mpx = ax - px;
var aympy = ay - py;
var bxmpx = bx - px;
var bympy = by - py;
var cxmpx = cx - px;
var cympy = cy - py; // prettier-ignore
var d = matrix_dist_maathMatrix.determinant3(x1mpx, aympy, x1mpx * x1mpx + aympy * aympy, bxmpx, bympy, bxmpx * bxmpx + bympy * bympy, cxmpx, cympy, cxmpx * cxmpx + cympy * cympy); // if d is 0, the point is on C
if (d === 0) {
return true;
}
return !isTriangleClockwise(triangle) ? d > 0 : d < 0;
} // From https://algorithmtutor.com/Computational-Geometry/Determining-if-two-consecutive-segments-turn-left-or-right/
var mv1 = new THREE.Vector2();
var mv2 = new THREE.Vector2();
/**
▕ ▏
right left
* NOTE: Should this use a buffer instead? [x0, y0, x1, y1]?
*/
function doThreePointsMakeARight(points) {
var _points$map = points.map(function (p) {
if (Array.isArray(p)) {
return _construct(THREE.Vector2, _toConsumableArray(p));
}
return p;
}),
_points$map2 = _slicedToArray(_points$map, 3),
p1 = _points$map2[0],
p2 = _points$map2[1],
p3 = _points$map2[2];
if (arePointsCollinear(points)) return false; // @ts-ignore
var p2p1 = mv1.subVectors(p2, p1); // @ts-ignore
var p3p1 = mv2.subVectors(p3, p1);
var cross = p3p1.cross(p2p1);
return cross > 0;
}
var triangle = /*#__PURE__*/Object.freeze({
__proto__: null,
isPointInTriangle: isPointInTriangle,
triangleDeterminant: triangleDeterminant,
arePointsCollinear: arePointsCollinear,
isTriangleClockwise: isTriangleClockwise,
getCircumcircle: getCircumcircle,
isPointInCircumcircle: isPointInCircumcircle,
doThreePointsMakeARight: doThreePointsMakeARight
});
exports._slicedToArray = _slicedToArray;
exports._toConsumableArray = _toConsumableArray;
exports.arePointsCollinear = arePointsCollinear;
exports.doThreePointsMakeARight = doThreePointsMakeARight;
exports.getCircumcircle = getCircumcircle;
exports.isPointInCircumcircle = isPointInCircumcircle;
exports.isPointInTriangle = isPointInTriangle;
exports.isTriangleClockwise = isTriangleClockwise;
exports.triangle = triangle;
exports.triangleDeterminant = triangleDeterminant;
+322
View File
@@ -0,0 +1,322 @@
import { a as _isNativeReflectConstruct, _ as _setPrototypeOf } from './isNativeReflectConstruct-5594d075.esm.js';
import { Vector2, Matrix4 } from 'three';
import { d as determinant3, g as getMinor } from './matrix-baa530bf.esm.js';
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
/**
*
* @param point
*
* @param triangle
*
* @returns {boolean} true if the point is in the triangle
*
* TODO: Find explainer
*/
function isPointInTriangle(point, triangle) {
var _triangle$ = _slicedToArray(triangle[0], 2),
ax = _triangle$[0],
ay = _triangle$[1];
var _triangle$2 = _slicedToArray(triangle[1], 2),
bx = _triangle$2[0],
by = _triangle$2[1];
var _triangle$3 = _slicedToArray(triangle[2], 2),
cx = _triangle$3[0],
cy = _triangle$3[1];
var _point = _slicedToArray(point, 2),
px = _point[0],
py = _point[1]; // TODO Sub with static calc
var matrix = new Matrix4(); // prettier-ignore
matrix.set(ax, ay, ax * ax + ay * ay, 1, bx, by, bx * bx + by * by, 1, cx, cy, cx * cx + cy * cy, 1, px, py, px * px + py * py, 1);
return matrix.determinant() <= 0;
}
function triangleDeterminant(triangle) {
var _triangle$4 = _slicedToArray(triangle[0], 2),
x1 = _triangle$4[0],
y1 = _triangle$4[1];
var _triangle$5 = _slicedToArray(triangle[1], 2),
x2 = _triangle$5[0],
y2 = _triangle$5[1];
var _triangle$6 = _slicedToArray(triangle[2], 2),
x3 = _triangle$6[0],
y3 = _triangle$6[1]; // prettier-ignore
return determinant3(x1, y1, 1, x2, y2, 1, x3, y3, 1);
}
/**
* Uses triangle area determinant to check if 3 points are collinear.
* If they are, they can't make a triangle, so the determinant will be 0!
*
* 0 1 2
* ─────■─────■─────■
*
*
* Fun fact, you can use this same determinant to check the order of the points in the triangle
*
* NOTE: Should this use a buffer instead? NOTE: Should this use a buffer instead? [x0, y0, x1, y1, x2, y2]?
*
*/
function arePointsCollinear(points) {
return triangleDeterminant(points) === 0;
} // TODO This is the same principle as the prev function, find a way to make it have sense
function isTriangleClockwise(triangle) {
return triangleDeterminant(triangle) < 0;
}
/**
The circumcircle is a circle touching all the vertices of a triangle or polygon.
┌───┐
│ B │
└───┘
.───●───.
,─' ╲ '─.
,' ╲ `.
╱ ╱ ╲ ╲
; ╱ ╲ :
│ ╱ ╲ │
│ ╱ ╲ │
: ╱ ╲ ;
╲ ╱ ╲ ╱
┌───┐ ●─────────────────● ┌───┐
│ A │ `. ,' │ C │
└───┘ '─. ,─' └───┘
`─────'
*/
/**
*
* @param triangle
*
* @returns {number} circumcircle
*/
// https://math.stackexchange.com/a/1460096
function getCircumcircle(triangle) {
// TS-TODO the next few lines are ignored because the types aren't current to the change in vectors (that can now be iterated)
// @ts-ignore
var _triangle$7 = _slicedToArray(triangle[0], 2),
ax = _triangle$7[0],
ay = _triangle$7[1]; // @ts-ignore
var _triangle$8 = _slicedToArray(triangle[1], 2),
bx = _triangle$8[0],
by = _triangle$8[1]; // @ts-ignore
var _triangle$9 = _slicedToArray(triangle[2], 2),
cx = _triangle$9[0],
cy = _triangle$9[1];
if (arePointsCollinear(triangle)) return null; // points are collinear
var m = new Matrix4(); // prettier-ignore
m.set(1, 1, 1, 1, ax * ax + ay * ay, ax, ay, 1, bx * bx + by * by, bx, by, 1, cx * cx + cy * cy, cx, cy, 1);
var m11 = getMinor(m, 1, 1);
var m13 = getMinor(m, 1, 3);
var m12 = getMinor(m, 1, 2);
var m14 = getMinor(m, 1, 4);
var x0 = 0.5 * (m12 / m11);
var y0 = 0.5 * (m13 / m11);
var r2 = x0 * x0 + y0 * y0 + m14 / m11;
return {
x: Math.abs(x0) === 0 ? 0 : x0,
y: Math.abs(y0) === 0 ? 0 : -y0,
r: Math.sqrt(r2)
};
} // https://stackoverflow.com/questions/39984709/how-can-i-check-wether-a-point-is-inside-the-circumcircle-of-3-points
function isPointInCircumcircle(point, triangle) {
var _ref = Array.isArray(triangle[0]) ? triangle[0] : triangle[0].toArray(),
_ref2 = _slicedToArray(_ref, 2),
ax = _ref2[0],
ay = _ref2[1];
var _ref3 = Array.isArray(triangle[1]) ? triangle[1] : triangle[1].toArray(),
_ref4 = _slicedToArray(_ref3, 2),
bx = _ref4[0],
by = _ref4[1];
var _ref5 = Array.isArray(triangle[2]) ? triangle[2] : triangle[2].toArray(),
_ref6 = _slicedToArray(_ref5, 2),
cx = _ref6[0],
cy = _ref6[1];
var _point2 = _slicedToArray(point, 2),
px = _point2[0],
py = _point2[1];
if (arePointsCollinear(triangle)) throw new Error("Collinear points don't form a triangle");
/**
| ax-px, ay-py, (ax-px)² + (ay-py)² |
det = | bx-px, by-py, (bx-px)² + (by-py)² |
| cx-px, cy-py, (cx-px)² + (cy-py)² |
*/
var x1mpx = ax - px;
var aympy = ay - py;
var bxmpx = bx - px;
var bympy = by - py;
var cxmpx = cx - px;
var cympy = cy - py; // prettier-ignore
var d = determinant3(x1mpx, aympy, x1mpx * x1mpx + aympy * aympy, bxmpx, bympy, bxmpx * bxmpx + bympy * bympy, cxmpx, cympy, cxmpx * cxmpx + cympy * cympy); // if d is 0, the point is on C
if (d === 0) {
return true;
}
return !isTriangleClockwise(triangle) ? d > 0 : d < 0;
} // From https://algorithmtutor.com/Computational-Geometry/Determining-if-two-consecutive-segments-turn-left-or-right/
var mv1 = new Vector2();
var mv2 = new Vector2();
/**
▕ ▏
right left
* NOTE: Should this use a buffer instead? [x0, y0, x1, y1]?
*/
function doThreePointsMakeARight(points) {
var _points$map = points.map(function (p) {
if (Array.isArray(p)) {
return _construct(Vector2, _toConsumableArray(p));
}
return p;
}),
_points$map2 = _slicedToArray(_points$map, 3),
p1 = _points$map2[0],
p2 = _points$map2[1],
p3 = _points$map2[2];
if (arePointsCollinear(points)) return false; // @ts-ignore
var p2p1 = mv1.subVectors(p2, p1); // @ts-ignore
var p3p1 = mv2.subVectors(p3, p1);
var cross = p3p1.cross(p2p1);
return cross > 0;
}
var triangle = /*#__PURE__*/Object.freeze({
__proto__: null,
isPointInTriangle: isPointInTriangle,
triangleDeterminant: triangleDeterminant,
arePointsCollinear: arePointsCollinear,
isTriangleClockwise: isTriangleClockwise,
getCircumcircle: getCircumcircle,
isPointInCircumcircle: isPointInCircumcircle,
doThreePointsMakeARight: doThreePointsMakeARight
});
export { _slicedToArray as _, _toConsumableArray as a, triangleDeterminant as b, arePointsCollinear as c, doThreePointsMakeARight as d, isTriangleClockwise as e, isPointInCircumcircle as f, getCircumcircle as g, isPointInTriangle as i, triangle as t };
+76
View File
@@ -0,0 +1,76 @@
'use strict';
/**
*
*/
function zero() {
return [0, 0];
}
function one() {
return [1, 1];
}
function add(a, b) {
return [a[0] + b[0], a[1] + b[1]];
}
function addValue(a, n) {
return [a[0] + n, a[1] + n];
}
function sub(a, b) {
return [a[0] - b[0], a[1] - b[1]];
}
function subValue(a, n) {
return [a[0] - n, a[1] - n];
}
function scale(a, n) {
return [a[0] * n, a[1] * n];
}
function dot(a, b) {
return a[0] * b[0] + a[1] * b[1];
}
/**
* Calculate the squared length of a vector.
* Use this when comparing two vectors instead of length, as it's more efficient (no sqrt)
*/
function lengthSqr(a) {
return a[0] * a[0] + a[1] * a[1];
}
/**
* Calculate the length of a vector.
* If you only need to compare lenghts, consider using the more efficient lengthSqr
*/
function length(a) {
return Math.sqrt(a[0] * a[0] + a[1] * a[1]);
}
function distance(a, b) {
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
}
var vector2 = /*#__PURE__*/Object.freeze({
__proto__: null,
zero: zero,
one: one,
add: add,
addValue: addValue,
sub: sub,
subValue: subValue,
scale: scale,
dot: dot,
lengthSqr: lengthSqr,
length: length,
distance: distance
});
exports.add = add;
exports.addValue = addValue;
exports.distance = distance;
exports.dot = dot;
exports.length = length;
exports.lengthSqr = lengthSqr;
exports.one = one;
exports.scale = scale;
exports.sub = sub;
exports.subValue = subValue;
exports.vector2 = vector2;
exports.zero = zero;
+63
View File
@@ -0,0 +1,63 @@
/**
*
*/
function zero() {
return [0, 0];
}
function one() {
return [1, 1];
}
function add(a, b) {
return [a[0] + b[0], a[1] + b[1]];
}
function addValue(a, n) {
return [a[0] + n, a[1] + n];
}
function sub(a, b) {
return [a[0] - b[0], a[1] - b[1]];
}
function subValue(a, n) {
return [a[0] - n, a[1] - n];
}
function scale(a, n) {
return [a[0] * n, a[1] * n];
}
function dot(a, b) {
return a[0] * b[0] + a[1] * b[1];
}
/**
* Calculate the squared length of a vector.
* Use this when comparing two vectors instead of length, as it's more efficient (no sqrt)
*/
function lengthSqr(a) {
return a[0] * a[0] + a[1] * a[1];
}
/**
* Calculate the length of a vector.
* If you only need to compare lenghts, consider using the more efficient lengthSqr
*/
function length(a) {
return Math.sqrt(a[0] * a[0] + a[1] * a[1]);
}
function distance(a, b) {
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
}
var vector2 = /*#__PURE__*/Object.freeze({
__proto__: null,
zero: zero,
one: one,
add: add,
addValue: addValue,
sub: sub,
subValue: subValue,
scale: scale,
dot: dot,
lengthSqr: lengthSqr,
length: length,
distance: distance
});
export { add as a, addValue as b, subValue as c, scale as d, dot as e, length as f, distance as g, lengthSqr as l, one as o, sub as s, vector2 as v, zero as z };
+76
View File
@@ -0,0 +1,76 @@
'use strict';
/**
*
*/
function zero() {
return [0, 0];
}
function one() {
return [1, 1];
}
function add(a, b) {
return [a[0] + b[0], a[1] + b[1]];
}
function addValue(a, n) {
return [a[0] + n, a[1] + n];
}
function sub(a, b) {
return [a[0] - b[0], a[1] - b[1]];
}
function subValue(a, n) {
return [a[0] - n, a[1] - n];
}
function scale(a, n) {
return [a[0] * n, a[1] * n];
}
function dot(a, b) {
return a[0] * b[0] + a[1] * b[1];
}
/**
* Calculate the squared length of a vector.
* Use this when comparing two vectors instead of length, as it's more efficient (no sqrt)
*/
function lengthSqr(a) {
return a[0] * a[0] + a[1] * a[1];
}
/**
* Calculate the length of a vector.
* If you only need to compare lenghts, consider using the more efficient lengthSqr
*/
function length(a) {
return Math.sqrt(a[0] * a[0] + a[1] * a[1]);
}
function distance(a, b) {
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
}
var vector2 = /*#__PURE__*/Object.freeze({
__proto__: null,
zero: zero,
one: one,
add: add,
addValue: addValue,
sub: sub,
subValue: subValue,
scale: scale,
dot: dot,
lengthSqr: lengthSqr,
length: length,
distance: distance
});
exports.add = add;
exports.addValue = addValue;
exports.distance = distance;
exports.dot = dot;
exports.length = length;
exports.lengthSqr = lengthSqr;
exports.one = one;
exports.scale = scale;
exports.sub = sub;
exports.subValue = subValue;
exports.vector2 = vector2;
exports.zero = zero;
+70
View File
@@ -0,0 +1,70 @@
/**
*
*/
function zero() {
return [0, 0, 0];
}
function one() {
return [1, 1, 1];
}
function add(a, b) {
return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
}
function addValue(a, n) {
return [a[0] + n, a[1] + n, a[2] + n];
}
function sub(a, b) {
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
}
function subValue(a, n) {
return [a[0] - n, a[1] - n, a[2] - n];
}
function scale(a, n) {
return [a[0] * n, a[1] * n, a[2] * n];
}
function dot(a, b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
function cross(a, b) {
var x = a[1] * b[2] - a[2] * b[1];
var y = a[2] * b[0] - a[0] * b[2];
var z = a[0] * b[1] - a[1] * b[0];
return [x, y, z];
}
/**
* Calculate the squared length of a vector.
* Use this when comparing two vectors instead of length, as it's more efficient (no sqrt)
*/
function lengthSqr(a) {
return a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
}
/**
* Calculate the length of a vector.
* If you only need to compare lenghts, consider using the more efficient lengthSqr
*/
function length(a) {
return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
}
function distance(a, b) {
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]));
}
var vector3 = /*#__PURE__*/Object.freeze({
__proto__: null,
zero: zero,
one: one,
add: add,
addValue: addValue,
sub: sub,
subValue: subValue,
scale: scale,
dot: dot,
cross: cross,
lengthSqr: lengthSqr,
length: length,
distance: distance
});
export { add as a, addValue as b, subValue as c, scale as d, dot as e, cross as f, length as g, distance as h, lengthSqr as l, one as o, sub as s, vector3 as v, zero as z };
+84
View File
@@ -0,0 +1,84 @@
'use strict';
/**
*
*/
function zero() {
return [0, 0, 0];
}
function one() {
return [1, 1, 1];
}
function add(a, b) {
return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
}
function addValue(a, n) {
return [a[0] + n, a[1] + n, a[2] + n];
}
function sub(a, b) {
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
}
function subValue(a, n) {
return [a[0] - n, a[1] - n, a[2] - n];
}
function scale(a, n) {
return [a[0] * n, a[1] * n, a[2] * n];
}
function dot(a, b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
function cross(a, b) {
var x = a[1] * b[2] - a[2] * b[1];
var y = a[2] * b[0] - a[0] * b[2];
var z = a[0] * b[1] - a[1] * b[0];
return [x, y, z];
}
/**
* Calculate the squared length of a vector.
* Use this when comparing two vectors instead of length, as it's more efficient (no sqrt)
*/
function lengthSqr(a) {
return a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
}
/**
* Calculate the length of a vector.
* If you only need to compare lenghts, consider using the more efficient lengthSqr
*/
function length(a) {
return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
}
function distance(a, b) {
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]));
}
var vector3 = /*#__PURE__*/Object.freeze({
__proto__: null,
zero: zero,
one: one,
add: add,
addValue: addValue,
sub: sub,
subValue: subValue,
scale: scale,
dot: dot,
cross: cross,
lengthSqr: lengthSqr,
length: length,
distance: distance
});
exports.add = add;
exports.addValue = addValue;
exports.cross = cross;
exports.distance = distance;
exports.dot = dot;
exports.length = length;
exports.lengthSqr = lengthSqr;
exports.one = one;
exports.scale = scale;
exports.sub = sub;
exports.subValue = subValue;
exports.vector3 = vector3;
exports.zero = zero;
+84
View File
@@ -0,0 +1,84 @@
'use strict';
/**
*
*/
function zero() {
return [0, 0, 0];
}
function one() {
return [1, 1, 1];
}
function add(a, b) {
return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
}
function addValue(a, n) {
return [a[0] + n, a[1] + n, a[2] + n];
}
function sub(a, b) {
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
}
function subValue(a, n) {
return [a[0] - n, a[1] - n, a[2] - n];
}
function scale(a, n) {
return [a[0] * n, a[1] * n, a[2] * n];
}
function dot(a, b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
function cross(a, b) {
var x = a[1] * b[2] - a[2] * b[1];
var y = a[2] * b[0] - a[0] * b[2];
var z = a[0] * b[1] - a[1] * b[0];
return [x, y, z];
}
/**
* Calculate the squared length of a vector.
* Use this when comparing two vectors instead of length, as it's more efficient (no sqrt)
*/
function lengthSqr(a) {
return a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
}
/**
* Calculate the length of a vector.
* If you only need to compare lenghts, consider using the more efficient lengthSqr
*/
function length(a) {
return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
}
function distance(a, b) {
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]));
}
var vector3 = /*#__PURE__*/Object.freeze({
__proto__: null,
zero: zero,
one: one,
add: add,
addValue: addValue,
sub: sub,
subValue: subValue,
scale: scale,
dot: dot,
cross: cross,
lengthSqr: lengthSqr,
length: length,
distance: distance
});
exports.add = add;
exports.addValue = addValue;
exports.cross = cross;
exports.distance = distance;
exports.dot = dot;
exports.length = length;
exports.lengthSqr = lengthSqr;
exports.one = one;
exports.scale = scale;
exports.sub = sub;
exports.subValue = subValue;
exports.vector3 = vector3;
exports.zero = zero;