46845 lines
1.9 MiB
46845 lines
1.9 MiB
var __defProp = Object.defineProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, {
|
|
get: all[name],
|
|
enumerable: true,
|
|
configurable: true,
|
|
set: (newValue) => all[name] = () => newValue
|
|
});
|
|
};
|
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
|
|
// node_modules/three/build/three.core.js
|
|
class EventDispatcher {
|
|
addEventListener(type, listener) {
|
|
if (this._listeners === undefined)
|
|
this._listeners = {};
|
|
const listeners = this._listeners;
|
|
if (listeners[type] === undefined) {
|
|
listeners[type] = [];
|
|
}
|
|
if (listeners[type].indexOf(listener) === -1) {
|
|
listeners[type].push(listener);
|
|
}
|
|
}
|
|
hasEventListener(type, listener) {
|
|
const listeners = this._listeners;
|
|
if (listeners === undefined)
|
|
return false;
|
|
return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
|
|
}
|
|
removeEventListener(type, listener) {
|
|
const listeners = this._listeners;
|
|
if (listeners === undefined)
|
|
return;
|
|
const listenerArray = listeners[type];
|
|
if (listenerArray !== undefined) {
|
|
const index = listenerArray.indexOf(listener);
|
|
if (index !== -1) {
|
|
listenerArray.splice(index, 1);
|
|
}
|
|
}
|
|
}
|
|
dispatchEvent(event) {
|
|
const listeners = this._listeners;
|
|
if (listeners === undefined)
|
|
return;
|
|
const listenerArray = listeners[event.type];
|
|
if (listenerArray !== undefined) {
|
|
event.target = this;
|
|
const array = listenerArray.slice(0);
|
|
for (let i = 0, l = array.length;i < l; i++) {
|
|
array[i].call(this, event);
|
|
}
|
|
event.target = null;
|
|
}
|
|
}
|
|
}
|
|
function generateUUID() {
|
|
const d0 = Math.random() * 4294967295 | 0;
|
|
const d1 = Math.random() * 4294967295 | 0;
|
|
const d2 = Math.random() * 4294967295 | 0;
|
|
const d3 = Math.random() * 4294967295 | 0;
|
|
const uuid = _lut[d0 & 255] + _lut[d0 >> 8 & 255] + _lut[d0 >> 16 & 255] + _lut[d0 >> 24 & 255] + "-" + _lut[d1 & 255] + _lut[d1 >> 8 & 255] + "-" + _lut[d1 >> 16 & 15 | 64] + _lut[d1 >> 24 & 255] + "-" + _lut[d2 & 63 | 128] + _lut[d2 >> 8 & 255] + "-" + _lut[d2 >> 16 & 255] + _lut[d2 >> 24 & 255] + _lut[d3 & 255] + _lut[d3 >> 8 & 255] + _lut[d3 >> 16 & 255] + _lut[d3 >> 24 & 255];
|
|
return uuid.toLowerCase();
|
|
}
|
|
function clamp(value, min, max) {
|
|
return Math.max(min, Math.min(max, value));
|
|
}
|
|
function euclideanModulo(n, m) {
|
|
return (n % m + m) % m;
|
|
}
|
|
function mapLinear(x, a1, a2, b1, b2) {
|
|
return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
|
|
}
|
|
function inverseLerp(x, y, value) {
|
|
if (x !== y) {
|
|
return (value - x) / (y - x);
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
function lerp(x, y, t) {
|
|
return (1 - t) * x + t * y;
|
|
}
|
|
function damp(x, y, lambda, dt) {
|
|
return lerp(x, y, 1 - Math.exp(-lambda * dt));
|
|
}
|
|
function pingpong(x, length = 1) {
|
|
return length - Math.abs(euclideanModulo(x, length * 2) - length);
|
|
}
|
|
function smoothstep(x, min, max) {
|
|
if (x <= min)
|
|
return 0;
|
|
if (x >= max)
|
|
return 1;
|
|
x = (x - min) / (max - min);
|
|
return x * x * (3 - 2 * x);
|
|
}
|
|
function smootherstep(x, min, max) {
|
|
if (x <= min)
|
|
return 0;
|
|
if (x >= max)
|
|
return 1;
|
|
x = (x - min) / (max - min);
|
|
return x * x * x * (x * (x * 6 - 15) + 10);
|
|
}
|
|
function randInt(low, high) {
|
|
return low + Math.floor(Math.random() * (high - low + 1));
|
|
}
|
|
function randFloat(low, high) {
|
|
return low + Math.random() * (high - low);
|
|
}
|
|
function randFloatSpread(range) {
|
|
return range * (0.5 - Math.random());
|
|
}
|
|
function seededRandom(s) {
|
|
if (s !== undefined)
|
|
_seed = s;
|
|
let t = _seed += 1831565813;
|
|
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
}
|
|
function degToRad(degrees) {
|
|
return degrees * DEG2RAD;
|
|
}
|
|
function radToDeg(radians) {
|
|
return radians * RAD2DEG;
|
|
}
|
|
function isPowerOfTwo(value) {
|
|
return (value & value - 1) === 0 && value !== 0;
|
|
}
|
|
function ceilPowerOfTwo(value) {
|
|
return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
|
|
}
|
|
function floorPowerOfTwo(value) {
|
|
return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
|
|
}
|
|
function setQuaternionFromProperEuler(q, a, b, c, order) {
|
|
const cos = Math.cos;
|
|
const sin = Math.sin;
|
|
const c2 = cos(b / 2);
|
|
const s2 = sin(b / 2);
|
|
const c13 = cos((a + c) / 2);
|
|
const s13 = sin((a + c) / 2);
|
|
const c1_3 = cos((a - c) / 2);
|
|
const s1_3 = sin((a - c) / 2);
|
|
const c3_1 = cos((c - a) / 2);
|
|
const s3_1 = sin((c - a) / 2);
|
|
switch (order) {
|
|
case "XYX":
|
|
q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
|
|
break;
|
|
case "YZY":
|
|
q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
|
|
break;
|
|
case "ZXZ":
|
|
q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
|
|
break;
|
|
case "XZX":
|
|
q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
|
|
break;
|
|
case "YXY":
|
|
q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
|
|
break;
|
|
case "ZYZ":
|
|
q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
|
|
break;
|
|
default:
|
|
console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: " + order);
|
|
}
|
|
}
|
|
function denormalize(value, array) {
|
|
switch (array.constructor) {
|
|
case Float32Array:
|
|
return value;
|
|
case Uint32Array:
|
|
return value / 4294967295;
|
|
case Uint16Array:
|
|
return value / 65535;
|
|
case Uint8Array:
|
|
return value / 255;
|
|
case Int32Array:
|
|
return Math.max(value / 2147483647, -1);
|
|
case Int16Array:
|
|
return Math.max(value / 32767, -1);
|
|
case Int8Array:
|
|
return Math.max(value / 127, -1);
|
|
default:
|
|
throw new Error("Invalid component type.");
|
|
}
|
|
}
|
|
function normalize(value, array) {
|
|
switch (array.constructor) {
|
|
case Float32Array:
|
|
return value;
|
|
case Uint32Array:
|
|
return Math.round(value * 4294967295);
|
|
case Uint16Array:
|
|
return Math.round(value * 65535);
|
|
case Uint8Array:
|
|
return Math.round(value * 255);
|
|
case Int32Array:
|
|
return Math.round(value * 2147483647);
|
|
case Int16Array:
|
|
return Math.round(value * 32767);
|
|
case Int8Array:
|
|
return Math.round(value * 127);
|
|
default:
|
|
throw new Error("Invalid component type.");
|
|
}
|
|
}
|
|
|
|
class Matrix3 {
|
|
constructor(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
|
|
Matrix3.prototype.isMatrix3 = true;
|
|
this.elements = [
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
];
|
|
if (n11 !== undefined) {
|
|
this.set(n11, n12, n13, n21, n22, n23, n31, n32, n33);
|
|
}
|
|
}
|
|
set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
|
|
const te = this.elements;
|
|
te[0] = n11;
|
|
te[1] = n21;
|
|
te[2] = n31;
|
|
te[3] = n12;
|
|
te[4] = n22;
|
|
te[5] = n32;
|
|
te[6] = n13;
|
|
te[7] = n23;
|
|
te[8] = n33;
|
|
return this;
|
|
}
|
|
identity() {
|
|
this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
copy(m) {
|
|
const te = this.elements;
|
|
const me = m.elements;
|
|
te[0] = me[0];
|
|
te[1] = me[1];
|
|
te[2] = me[2];
|
|
te[3] = me[3];
|
|
te[4] = me[4];
|
|
te[5] = me[5];
|
|
te[6] = me[6];
|
|
te[7] = me[7];
|
|
te[8] = me[8];
|
|
return this;
|
|
}
|
|
extractBasis(xAxis, yAxis, zAxis) {
|
|
xAxis.setFromMatrix3Column(this, 0);
|
|
yAxis.setFromMatrix3Column(this, 1);
|
|
zAxis.setFromMatrix3Column(this, 2);
|
|
return this;
|
|
}
|
|
setFromMatrix4(m) {
|
|
const me = m.elements;
|
|
this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
|
|
return this;
|
|
}
|
|
multiply(m) {
|
|
return this.multiplyMatrices(this, m);
|
|
}
|
|
premultiply(m) {
|
|
return this.multiplyMatrices(m, this);
|
|
}
|
|
multiplyMatrices(a, b) {
|
|
const ae = a.elements;
|
|
const be = b.elements;
|
|
const te = this.elements;
|
|
const a11 = ae[0], a12 = ae[3], a13 = ae[6];
|
|
const a21 = ae[1], a22 = ae[4], a23 = ae[7];
|
|
const a31 = ae[2], a32 = ae[5], a33 = ae[8];
|
|
const b11 = be[0], b12 = be[3], b13 = be[6];
|
|
const b21 = be[1], b22 = be[4], b23 = be[7];
|
|
const b31 = be[2], b32 = be[5], b33 = be[8];
|
|
te[0] = a11 * b11 + a12 * b21 + a13 * b31;
|
|
te[3] = a11 * b12 + a12 * b22 + a13 * b32;
|
|
te[6] = a11 * b13 + a12 * b23 + a13 * b33;
|
|
te[1] = a21 * b11 + a22 * b21 + a23 * b31;
|
|
te[4] = a21 * b12 + a22 * b22 + a23 * b32;
|
|
te[7] = a21 * b13 + a22 * b23 + a23 * b33;
|
|
te[2] = a31 * b11 + a32 * b21 + a33 * b31;
|
|
te[5] = a31 * b12 + a32 * b22 + a33 * b32;
|
|
te[8] = a31 * b13 + a32 * b23 + a33 * b33;
|
|
return this;
|
|
}
|
|
multiplyScalar(s) {
|
|
const te = this.elements;
|
|
te[0] *= s;
|
|
te[3] *= s;
|
|
te[6] *= s;
|
|
te[1] *= s;
|
|
te[4] *= s;
|
|
te[7] *= s;
|
|
te[2] *= s;
|
|
te[5] *= s;
|
|
te[8] *= s;
|
|
return this;
|
|
}
|
|
determinant() {
|
|
const te = this.elements;
|
|
const a = te[0], b = te[1], c = te[2], d = te[3], e = te[4], f = te[5], g = te[6], h = te[7], i = te[8];
|
|
return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
|
|
}
|
|
invert() {
|
|
const te = this.elements, n11 = te[0], n21 = te[1], n31 = te[2], n12 = te[3], n22 = te[4], n32 = te[5], n13 = te[6], n23 = te[7], n33 = te[8], t11 = n33 * n22 - n32 * n23, t12 = n32 * n13 - n33 * n12, t13 = n23 * n12 - n22 * n13, det = n11 * t11 + n21 * t12 + n31 * t13;
|
|
if (det === 0)
|
|
return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
const detInv = 1 / det;
|
|
te[0] = t11 * detInv;
|
|
te[1] = (n31 * n23 - n33 * n21) * detInv;
|
|
te[2] = (n32 * n21 - n31 * n22) * detInv;
|
|
te[3] = t12 * detInv;
|
|
te[4] = (n33 * n11 - n31 * n13) * detInv;
|
|
te[5] = (n31 * n12 - n32 * n11) * detInv;
|
|
te[6] = t13 * detInv;
|
|
te[7] = (n21 * n13 - n23 * n11) * detInv;
|
|
te[8] = (n22 * n11 - n21 * n12) * detInv;
|
|
return this;
|
|
}
|
|
transpose() {
|
|
let tmp;
|
|
const m = this.elements;
|
|
tmp = m[1];
|
|
m[1] = m[3];
|
|
m[3] = tmp;
|
|
tmp = m[2];
|
|
m[2] = m[6];
|
|
m[6] = tmp;
|
|
tmp = m[5];
|
|
m[5] = m[7];
|
|
m[7] = tmp;
|
|
return this;
|
|
}
|
|
getNormalMatrix(matrix4) {
|
|
return this.setFromMatrix4(matrix4).invert().transpose();
|
|
}
|
|
transposeIntoArray(r) {
|
|
const m = this.elements;
|
|
r[0] = m[0];
|
|
r[1] = m[3];
|
|
r[2] = m[6];
|
|
r[3] = m[1];
|
|
r[4] = m[4];
|
|
r[5] = m[7];
|
|
r[6] = m[2];
|
|
r[7] = m[5];
|
|
r[8] = m[8];
|
|
return this;
|
|
}
|
|
setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
|
|
const c = Math.cos(rotation);
|
|
const s = Math.sin(rotation);
|
|
this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
|
|
return this;
|
|
}
|
|
scale(sx, sy) {
|
|
this.premultiply(_m3.makeScale(sx, sy));
|
|
return this;
|
|
}
|
|
rotate(theta) {
|
|
this.premultiply(_m3.makeRotation(-theta));
|
|
return this;
|
|
}
|
|
translate(tx, ty) {
|
|
this.premultiply(_m3.makeTranslation(tx, ty));
|
|
return this;
|
|
}
|
|
makeTranslation(x, y) {
|
|
if (x.isVector2) {
|
|
this.set(1, 0, x.x, 0, 1, x.y, 0, 0, 1);
|
|
} else {
|
|
this.set(1, 0, x, 0, 1, y, 0, 0, 1);
|
|
}
|
|
return this;
|
|
}
|
|
makeRotation(theta) {
|
|
const c = Math.cos(theta);
|
|
const s = Math.sin(theta);
|
|
this.set(c, -s, 0, s, c, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
makeScale(x, y) {
|
|
this.set(x, 0, 0, 0, y, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
equals(matrix) {
|
|
const te = this.elements;
|
|
const me = matrix.elements;
|
|
for (let i = 0;i < 9; i++) {
|
|
if (te[i] !== me[i])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
for (let i = 0;i < 9; i++) {
|
|
this.elements[i] = array[i + offset];
|
|
}
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
const te = this.elements;
|
|
array[offset] = te[0];
|
|
array[offset + 1] = te[1];
|
|
array[offset + 2] = te[2];
|
|
array[offset + 3] = te[3];
|
|
array[offset + 4] = te[4];
|
|
array[offset + 5] = te[5];
|
|
array[offset + 6] = te[6];
|
|
array[offset + 7] = te[7];
|
|
array[offset + 8] = te[8];
|
|
return array;
|
|
}
|
|
clone() {
|
|
return new this.constructor().fromArray(this.elements);
|
|
}
|
|
}
|
|
function arrayNeedsUint32(array) {
|
|
for (let i = array.length - 1;i >= 0; --i) {
|
|
if (array[i] >= 65535)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
function getTypedArray(type, buffer) {
|
|
return new TYPED_ARRAYS[type](buffer);
|
|
}
|
|
function createElementNS(name) {
|
|
return document.createElementNS("http://www.w3.org/1999/xhtml", name);
|
|
}
|
|
function createCanvasElement() {
|
|
const canvas = createElementNS("canvas");
|
|
canvas.style.display = "block";
|
|
return canvas;
|
|
}
|
|
function warnOnce(message) {
|
|
if (message in _cache)
|
|
return;
|
|
_cache[message] = true;
|
|
console.warn(message);
|
|
}
|
|
function probeAsync(gl, sync, interval) {
|
|
return new Promise(function(resolve, reject) {
|
|
function probe() {
|
|
switch (gl.clientWaitSync(sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0)) {
|
|
case gl.WAIT_FAILED:
|
|
reject();
|
|
break;
|
|
case gl.TIMEOUT_EXPIRED:
|
|
setTimeout(probe, interval);
|
|
break;
|
|
default:
|
|
resolve();
|
|
}
|
|
}
|
|
setTimeout(probe, interval);
|
|
});
|
|
}
|
|
function toNormalizedProjectionMatrix(projectionMatrix) {
|
|
const m = projectionMatrix.elements;
|
|
m[2] = 0.5 * m[2] + 0.5 * m[3];
|
|
m[6] = 0.5 * m[6] + 0.5 * m[7];
|
|
m[10] = 0.5 * m[10] + 0.5 * m[11];
|
|
m[14] = 0.5 * m[14] + 0.5 * m[15];
|
|
}
|
|
function toReversedProjectionMatrix(projectionMatrix) {
|
|
const m = projectionMatrix.elements;
|
|
const isPerspectiveMatrix = m[11] === -1;
|
|
if (isPerspectiveMatrix) {
|
|
m[10] = -m[10] - 1;
|
|
m[14] = -m[14];
|
|
} else {
|
|
m[10] = -m[10];
|
|
m[14] = -m[14] + 1;
|
|
}
|
|
}
|
|
function createColorManagement() {
|
|
const ColorManagement = {
|
|
enabled: true,
|
|
workingColorSpace: LinearSRGBColorSpace,
|
|
spaces: {},
|
|
convert: function(color, sourceColorSpace, targetColorSpace) {
|
|
if (this.enabled === false || sourceColorSpace === targetColorSpace || !sourceColorSpace || !targetColorSpace) {
|
|
return color;
|
|
}
|
|
if (this.spaces[sourceColorSpace].transfer === SRGBTransfer) {
|
|
color.r = SRGBToLinear(color.r);
|
|
color.g = SRGBToLinear(color.g);
|
|
color.b = SRGBToLinear(color.b);
|
|
}
|
|
if (this.spaces[sourceColorSpace].primaries !== this.spaces[targetColorSpace].primaries) {
|
|
color.applyMatrix3(this.spaces[sourceColorSpace].toXYZ);
|
|
color.applyMatrix3(this.spaces[targetColorSpace].fromXYZ);
|
|
}
|
|
if (this.spaces[targetColorSpace].transfer === SRGBTransfer) {
|
|
color.r = LinearToSRGB(color.r);
|
|
color.g = LinearToSRGB(color.g);
|
|
color.b = LinearToSRGB(color.b);
|
|
}
|
|
return color;
|
|
},
|
|
fromWorkingColorSpace: function(color, targetColorSpace) {
|
|
return this.convert(color, this.workingColorSpace, targetColorSpace);
|
|
},
|
|
toWorkingColorSpace: function(color, sourceColorSpace) {
|
|
return this.convert(color, sourceColorSpace, this.workingColorSpace);
|
|
},
|
|
getPrimaries: function(colorSpace) {
|
|
return this.spaces[colorSpace].primaries;
|
|
},
|
|
getTransfer: function(colorSpace) {
|
|
if (colorSpace === NoColorSpace)
|
|
return LinearTransfer;
|
|
return this.spaces[colorSpace].transfer;
|
|
},
|
|
getLuminanceCoefficients: function(target, colorSpace = this.workingColorSpace) {
|
|
return target.fromArray(this.spaces[colorSpace].luminanceCoefficients);
|
|
},
|
|
define: function(colorSpaces) {
|
|
Object.assign(this.spaces, colorSpaces);
|
|
},
|
|
_getMatrix: function(targetMatrix, sourceColorSpace, targetColorSpace) {
|
|
return targetMatrix.copy(this.spaces[sourceColorSpace].toXYZ).multiply(this.spaces[targetColorSpace].fromXYZ);
|
|
},
|
|
_getDrawingBufferColorSpace: function(colorSpace) {
|
|
return this.spaces[colorSpace].outputColorSpaceConfig.drawingBufferColorSpace;
|
|
},
|
|
_getUnpackColorSpace: function(colorSpace = this.workingColorSpace) {
|
|
return this.spaces[colorSpace].workingColorSpaceConfig.unpackColorSpace;
|
|
}
|
|
};
|
|
const REC709_PRIMARIES = [0.64, 0.33, 0.3, 0.6, 0.15, 0.06];
|
|
const REC709_LUMINANCE_COEFFICIENTS = [0.2126, 0.7152, 0.0722];
|
|
const D65 = [0.3127, 0.329];
|
|
ColorManagement.define({
|
|
[LinearSRGBColorSpace]: {
|
|
primaries: REC709_PRIMARIES,
|
|
whitePoint: D65,
|
|
transfer: LinearTransfer,
|
|
toXYZ: LINEAR_REC709_TO_XYZ,
|
|
fromXYZ: XYZ_TO_LINEAR_REC709,
|
|
luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
|
|
workingColorSpaceConfig: { unpackColorSpace: SRGBColorSpace },
|
|
outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
|
|
},
|
|
[SRGBColorSpace]: {
|
|
primaries: REC709_PRIMARIES,
|
|
whitePoint: D65,
|
|
transfer: SRGBTransfer,
|
|
toXYZ: LINEAR_REC709_TO_XYZ,
|
|
fromXYZ: XYZ_TO_LINEAR_REC709,
|
|
luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
|
|
outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
|
|
}
|
|
});
|
|
return ColorManagement;
|
|
}
|
|
function SRGBToLinear(c) {
|
|
return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
|
|
}
|
|
function LinearToSRGB(c) {
|
|
return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
|
|
}
|
|
|
|
class ImageUtils {
|
|
static getDataURL(image) {
|
|
if (/^data:/i.test(image.src)) {
|
|
return image.src;
|
|
}
|
|
if (typeof HTMLCanvasElement === "undefined") {
|
|
return image.src;
|
|
}
|
|
let canvas;
|
|
if (image instanceof HTMLCanvasElement) {
|
|
canvas = image;
|
|
} else {
|
|
if (_canvas === undefined)
|
|
_canvas = createElementNS("canvas");
|
|
_canvas.width = image.width;
|
|
_canvas.height = image.height;
|
|
const context = _canvas.getContext("2d");
|
|
if (image instanceof ImageData) {
|
|
context.putImageData(image, 0, 0);
|
|
} else {
|
|
context.drawImage(image, 0, 0, image.width, image.height);
|
|
}
|
|
canvas = _canvas;
|
|
}
|
|
return canvas.toDataURL("image/png");
|
|
}
|
|
static sRGBToLinear(image) {
|
|
if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
const canvas = createElementNS("canvas");
|
|
canvas.width = image.width;
|
|
canvas.height = image.height;
|
|
const context = canvas.getContext("2d");
|
|
context.drawImage(image, 0, 0, image.width, image.height);
|
|
const imageData = context.getImageData(0, 0, image.width, image.height);
|
|
const data = imageData.data;
|
|
for (let i = 0;i < data.length; i++) {
|
|
data[i] = SRGBToLinear(data[i] / 255) * 255;
|
|
}
|
|
context.putImageData(imageData, 0, 0);
|
|
return canvas;
|
|
} else if (image.data) {
|
|
const data = image.data.slice(0);
|
|
for (let i = 0;i < data.length; i++) {
|
|
if (data instanceof Uint8Array || data instanceof Uint8ClampedArray) {
|
|
data[i] = Math.floor(SRGBToLinear(data[i] / 255) * 255);
|
|
} else {
|
|
data[i] = SRGBToLinear(data[i]);
|
|
}
|
|
}
|
|
return {
|
|
data,
|
|
width: image.width,
|
|
height: image.height
|
|
};
|
|
} else {
|
|
console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.");
|
|
return image;
|
|
}
|
|
}
|
|
}
|
|
|
|
class Source {
|
|
constructor(data = null) {
|
|
this.isSource = true;
|
|
Object.defineProperty(this, "id", { value: _sourceId++ });
|
|
this.uuid = generateUUID();
|
|
this.data = data;
|
|
this.dataReady = true;
|
|
this.version = 0;
|
|
}
|
|
set needsUpdate(value) {
|
|
if (value === true)
|
|
this.version++;
|
|
}
|
|
toJSON(meta) {
|
|
const isRootObject = meta === undefined || typeof meta === "string";
|
|
if (!isRootObject && meta.images[this.uuid] !== undefined) {
|
|
return meta.images[this.uuid];
|
|
}
|
|
const output = {
|
|
uuid: this.uuid,
|
|
url: ""
|
|
};
|
|
const data = this.data;
|
|
if (data !== null) {
|
|
let url;
|
|
if (Array.isArray(data)) {
|
|
url = [];
|
|
for (let i = 0, l = data.length;i < l; i++) {
|
|
if (data[i].isDataTexture) {
|
|
url.push(serializeImage(data[i].image));
|
|
} else {
|
|
url.push(serializeImage(data[i]));
|
|
}
|
|
}
|
|
} else {
|
|
url = serializeImage(data);
|
|
}
|
|
output.url = url;
|
|
}
|
|
if (!isRootObject) {
|
|
meta.images[this.uuid] = output;
|
|
}
|
|
return output;
|
|
}
|
|
}
|
|
function serializeImage(image) {
|
|
if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
return ImageUtils.getDataURL(image);
|
|
} else {
|
|
if (image.data) {
|
|
return {
|
|
data: Array.from(image.data),
|
|
width: image.width,
|
|
height: image.height,
|
|
type: image.data.constructor.name
|
|
};
|
|
} else {
|
|
console.warn("THREE.Texture: Unable to serialize Texture.");
|
|
return {};
|
|
}
|
|
}
|
|
}
|
|
|
|
class Box3 {
|
|
constructor(min = new Vector3(Infinity, Infinity, Infinity), max = new Vector3(-Infinity, -Infinity, -Infinity)) {
|
|
this.isBox3 = true;
|
|
this.min = min;
|
|
this.max = max;
|
|
}
|
|
set(min, max) {
|
|
this.min.copy(min);
|
|
this.max.copy(max);
|
|
return this;
|
|
}
|
|
setFromArray(array) {
|
|
this.makeEmpty();
|
|
for (let i = 0, il = array.length;i < il; i += 3) {
|
|
this.expandByPoint(_vector$b.fromArray(array, i));
|
|
}
|
|
return this;
|
|
}
|
|
setFromBufferAttribute(attribute) {
|
|
this.makeEmpty();
|
|
for (let i = 0, il = attribute.count;i < il; i++) {
|
|
this.expandByPoint(_vector$b.fromBufferAttribute(attribute, i));
|
|
}
|
|
return this;
|
|
}
|
|
setFromPoints(points) {
|
|
this.makeEmpty();
|
|
for (let i = 0, il = points.length;i < il; i++) {
|
|
this.expandByPoint(points[i]);
|
|
}
|
|
return this;
|
|
}
|
|
setFromCenterAndSize(center, size) {
|
|
const halfSize = _vector$b.copy(size).multiplyScalar(0.5);
|
|
this.min.copy(center).sub(halfSize);
|
|
this.max.copy(center).add(halfSize);
|
|
return this;
|
|
}
|
|
setFromObject(object, precise = false) {
|
|
this.makeEmpty();
|
|
return this.expandByObject(object, precise);
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
copy(box) {
|
|
this.min.copy(box.min);
|
|
this.max.copy(box.max);
|
|
return this;
|
|
}
|
|
makeEmpty() {
|
|
this.min.x = this.min.y = this.min.z = Infinity;
|
|
this.max.x = this.max.y = this.max.z = -Infinity;
|
|
return this;
|
|
}
|
|
isEmpty() {
|
|
return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
|
|
}
|
|
getCenter(target) {
|
|
return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
|
|
}
|
|
getSize(target) {
|
|
return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
|
|
}
|
|
expandByPoint(point) {
|
|
this.min.min(point);
|
|
this.max.max(point);
|
|
return this;
|
|
}
|
|
expandByVector(vector) {
|
|
this.min.sub(vector);
|
|
this.max.add(vector);
|
|
return this;
|
|
}
|
|
expandByScalar(scalar) {
|
|
this.min.addScalar(-scalar);
|
|
this.max.addScalar(scalar);
|
|
return this;
|
|
}
|
|
expandByObject(object, precise = false) {
|
|
object.updateWorldMatrix(false, false);
|
|
const geometry = object.geometry;
|
|
if (geometry !== undefined) {
|
|
const positionAttribute = geometry.getAttribute("position");
|
|
if (precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true) {
|
|
for (let i = 0, l = positionAttribute.count;i < l; i++) {
|
|
if (object.isMesh === true) {
|
|
object.getVertexPosition(i, _vector$b);
|
|
} else {
|
|
_vector$b.fromBufferAttribute(positionAttribute, i);
|
|
}
|
|
_vector$b.applyMatrix4(object.matrixWorld);
|
|
this.expandByPoint(_vector$b);
|
|
}
|
|
} else {
|
|
if (object.boundingBox !== undefined) {
|
|
if (object.boundingBox === null) {
|
|
object.computeBoundingBox();
|
|
}
|
|
_box$4.copy(object.boundingBox);
|
|
} else {
|
|
if (geometry.boundingBox === null) {
|
|
geometry.computeBoundingBox();
|
|
}
|
|
_box$4.copy(geometry.boundingBox);
|
|
}
|
|
_box$4.applyMatrix4(object.matrixWorld);
|
|
this.union(_box$4);
|
|
}
|
|
}
|
|
const children = object.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
this.expandByObject(children[i], precise);
|
|
}
|
|
return this;
|
|
}
|
|
containsPoint(point) {
|
|
return point.x >= this.min.x && point.x <= this.max.x && point.y >= this.min.y && point.y <= this.max.y && point.z >= this.min.z && point.z <= this.max.z;
|
|
}
|
|
containsBox(box) {
|
|
return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
|
|
}
|
|
getParameter(point, target) {
|
|
return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
|
|
}
|
|
intersectsBox(box) {
|
|
return box.max.x >= this.min.x && box.min.x <= this.max.x && box.max.y >= this.min.y && box.min.y <= this.max.y && box.max.z >= this.min.z && box.min.z <= this.max.z;
|
|
}
|
|
intersectsSphere(sphere) {
|
|
this.clampPoint(sphere.center, _vector$b);
|
|
return _vector$b.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
|
|
}
|
|
intersectsPlane(plane) {
|
|
let min, max;
|
|
if (plane.normal.x > 0) {
|
|
min = plane.normal.x * this.min.x;
|
|
max = plane.normal.x * this.max.x;
|
|
} else {
|
|
min = plane.normal.x * this.max.x;
|
|
max = plane.normal.x * this.min.x;
|
|
}
|
|
if (plane.normal.y > 0) {
|
|
min += plane.normal.y * this.min.y;
|
|
max += plane.normal.y * this.max.y;
|
|
} else {
|
|
min += plane.normal.y * this.max.y;
|
|
max += plane.normal.y * this.min.y;
|
|
}
|
|
if (plane.normal.z > 0) {
|
|
min += plane.normal.z * this.min.z;
|
|
max += plane.normal.z * this.max.z;
|
|
} else {
|
|
min += plane.normal.z * this.max.z;
|
|
max += plane.normal.z * this.min.z;
|
|
}
|
|
return min <= -plane.constant && max >= -plane.constant;
|
|
}
|
|
intersectsTriangle(triangle) {
|
|
if (this.isEmpty()) {
|
|
return false;
|
|
}
|
|
this.getCenter(_center);
|
|
_extents.subVectors(this.max, _center);
|
|
_v0$2.subVectors(triangle.a, _center);
|
|
_v1$7.subVectors(triangle.b, _center);
|
|
_v2$4.subVectors(triangle.c, _center);
|
|
_f0.subVectors(_v1$7, _v0$2);
|
|
_f1.subVectors(_v2$4, _v1$7);
|
|
_f2.subVectors(_v0$2, _v2$4);
|
|
let axes = [
|
|
0,
|
|
-_f0.z,
|
|
_f0.y,
|
|
0,
|
|
-_f1.z,
|
|
_f1.y,
|
|
0,
|
|
-_f2.z,
|
|
_f2.y,
|
|
_f0.z,
|
|
0,
|
|
-_f0.x,
|
|
_f1.z,
|
|
0,
|
|
-_f1.x,
|
|
_f2.z,
|
|
0,
|
|
-_f2.x,
|
|
-_f0.y,
|
|
_f0.x,
|
|
0,
|
|
-_f1.y,
|
|
_f1.x,
|
|
0,
|
|
-_f2.y,
|
|
_f2.x,
|
|
0
|
|
];
|
|
if (!satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents)) {
|
|
return false;
|
|
}
|
|
axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
|
|
if (!satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents)) {
|
|
return false;
|
|
}
|
|
_triangleNormal.crossVectors(_f0, _f1);
|
|
axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
|
|
return satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents);
|
|
}
|
|
clampPoint(point, target) {
|
|
return target.copy(point).clamp(this.min, this.max);
|
|
}
|
|
distanceToPoint(point) {
|
|
return this.clampPoint(point, _vector$b).distanceTo(point);
|
|
}
|
|
getBoundingSphere(target) {
|
|
if (this.isEmpty()) {
|
|
target.makeEmpty();
|
|
} else {
|
|
this.getCenter(target.center);
|
|
target.radius = this.getSize(_vector$b).length() * 0.5;
|
|
}
|
|
return target;
|
|
}
|
|
intersect(box) {
|
|
this.min.max(box.min);
|
|
this.max.min(box.max);
|
|
if (this.isEmpty())
|
|
this.makeEmpty();
|
|
return this;
|
|
}
|
|
union(box) {
|
|
this.min.min(box.min);
|
|
this.max.max(box.max);
|
|
return this;
|
|
}
|
|
applyMatrix4(matrix) {
|
|
if (this.isEmpty())
|
|
return this;
|
|
_points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix);
|
|
_points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix);
|
|
_points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix);
|
|
_points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix);
|
|
_points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix);
|
|
_points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix);
|
|
_points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix);
|
|
_points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix);
|
|
this.setFromPoints(_points);
|
|
return this;
|
|
}
|
|
translate(offset) {
|
|
this.min.add(offset);
|
|
this.max.add(offset);
|
|
return this;
|
|
}
|
|
equals(box) {
|
|
return box.min.equals(this.min) && box.max.equals(this.max);
|
|
}
|
|
}
|
|
function satForAxes(axes, v0, v1, v2, extents) {
|
|
for (let i = 0, j = axes.length - 3;i <= j; i += 3) {
|
|
_testAxis.fromArray(axes, i);
|
|
const r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z);
|
|
const p0 = v0.dot(_testAxis);
|
|
const p1 = v1.dot(_testAxis);
|
|
const p2 = v2.dot(_testAxis);
|
|
if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
class Sphere {
|
|
constructor(center = new Vector3, radius = -1) {
|
|
this.isSphere = true;
|
|
this.center = center;
|
|
this.radius = radius;
|
|
}
|
|
set(center, radius) {
|
|
this.center.copy(center);
|
|
this.radius = radius;
|
|
return this;
|
|
}
|
|
setFromPoints(points, optionalCenter) {
|
|
const center = this.center;
|
|
if (optionalCenter !== undefined) {
|
|
center.copy(optionalCenter);
|
|
} else {
|
|
_box$3.setFromPoints(points).getCenter(center);
|
|
}
|
|
let maxRadiusSq = 0;
|
|
for (let i = 0, il = points.length;i < il; i++) {
|
|
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
|
|
}
|
|
this.radius = Math.sqrt(maxRadiusSq);
|
|
return this;
|
|
}
|
|
copy(sphere) {
|
|
this.center.copy(sphere.center);
|
|
this.radius = sphere.radius;
|
|
return this;
|
|
}
|
|
isEmpty() {
|
|
return this.radius < 0;
|
|
}
|
|
makeEmpty() {
|
|
this.center.set(0, 0, 0);
|
|
this.radius = -1;
|
|
return this;
|
|
}
|
|
containsPoint(point) {
|
|
return point.distanceToSquared(this.center) <= this.radius * this.radius;
|
|
}
|
|
distanceToPoint(point) {
|
|
return point.distanceTo(this.center) - this.radius;
|
|
}
|
|
intersectsSphere(sphere) {
|
|
const radiusSum = this.radius + sphere.radius;
|
|
return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
|
|
}
|
|
intersectsBox(box) {
|
|
return box.intersectsSphere(this);
|
|
}
|
|
intersectsPlane(plane) {
|
|
return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
|
|
}
|
|
clampPoint(point, target) {
|
|
const deltaLengthSq = this.center.distanceToSquared(point);
|
|
target.copy(point);
|
|
if (deltaLengthSq > this.radius * this.radius) {
|
|
target.sub(this.center).normalize();
|
|
target.multiplyScalar(this.radius).add(this.center);
|
|
}
|
|
return target;
|
|
}
|
|
getBoundingBox(target) {
|
|
if (this.isEmpty()) {
|
|
target.makeEmpty();
|
|
return target;
|
|
}
|
|
target.set(this.center, this.center);
|
|
target.expandByScalar(this.radius);
|
|
return target;
|
|
}
|
|
applyMatrix4(matrix) {
|
|
this.center.applyMatrix4(matrix);
|
|
this.radius = this.radius * matrix.getMaxScaleOnAxis();
|
|
return this;
|
|
}
|
|
translate(offset) {
|
|
this.center.add(offset);
|
|
return this;
|
|
}
|
|
expandByPoint(point) {
|
|
if (this.isEmpty()) {
|
|
this.center.copy(point);
|
|
this.radius = 0;
|
|
return this;
|
|
}
|
|
_v1$6.subVectors(point, this.center);
|
|
const lengthSq = _v1$6.lengthSq();
|
|
if (lengthSq > this.radius * this.radius) {
|
|
const length = Math.sqrt(lengthSq);
|
|
const delta = (length - this.radius) * 0.5;
|
|
this.center.addScaledVector(_v1$6, delta / length);
|
|
this.radius += delta;
|
|
}
|
|
return this;
|
|
}
|
|
union(sphere) {
|
|
if (sphere.isEmpty()) {
|
|
return this;
|
|
}
|
|
if (this.isEmpty()) {
|
|
this.copy(sphere);
|
|
return this;
|
|
}
|
|
if (this.center.equals(sphere.center) === true) {
|
|
this.radius = Math.max(this.radius, sphere.radius);
|
|
} else {
|
|
_v2$3.subVectors(sphere.center, this.center).setLength(sphere.radius);
|
|
this.expandByPoint(_v1$6.copy(sphere.center).add(_v2$3));
|
|
this.expandByPoint(_v1$6.copy(sphere.center).sub(_v2$3));
|
|
}
|
|
return this;
|
|
}
|
|
equals(sphere) {
|
|
return sphere.center.equals(this.center) && sphere.radius === this.radius;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
}
|
|
|
|
class Ray {
|
|
constructor(origin = new Vector3, direction = new Vector3(0, 0, -1)) {
|
|
this.origin = origin;
|
|
this.direction = direction;
|
|
}
|
|
set(origin, direction) {
|
|
this.origin.copy(origin);
|
|
this.direction.copy(direction);
|
|
return this;
|
|
}
|
|
copy(ray) {
|
|
this.origin.copy(ray.origin);
|
|
this.direction.copy(ray.direction);
|
|
return this;
|
|
}
|
|
at(t, target) {
|
|
return target.copy(this.origin).addScaledVector(this.direction, t);
|
|
}
|
|
lookAt(v) {
|
|
this.direction.copy(v).sub(this.origin).normalize();
|
|
return this;
|
|
}
|
|
recast(t) {
|
|
this.origin.copy(this.at(t, _vector$a));
|
|
return this;
|
|
}
|
|
closestPointToPoint(point, target) {
|
|
target.subVectors(point, this.origin);
|
|
const directionDistance = target.dot(this.direction);
|
|
if (directionDistance < 0) {
|
|
return target.copy(this.origin);
|
|
}
|
|
return target.copy(this.origin).addScaledVector(this.direction, directionDistance);
|
|
}
|
|
distanceToPoint(point) {
|
|
return Math.sqrt(this.distanceSqToPoint(point));
|
|
}
|
|
distanceSqToPoint(point) {
|
|
const directionDistance = _vector$a.subVectors(point, this.origin).dot(this.direction);
|
|
if (directionDistance < 0) {
|
|
return this.origin.distanceToSquared(point);
|
|
}
|
|
_vector$a.copy(this.origin).addScaledVector(this.direction, directionDistance);
|
|
return _vector$a.distanceToSquared(point);
|
|
}
|
|
distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
|
|
_segCenter.copy(v0).add(v1).multiplyScalar(0.5);
|
|
_segDir.copy(v1).sub(v0).normalize();
|
|
_diff.copy(this.origin).sub(_segCenter);
|
|
const segExtent = v0.distanceTo(v1) * 0.5;
|
|
const a01 = -this.direction.dot(_segDir);
|
|
const b0 = _diff.dot(this.direction);
|
|
const b1 = -_diff.dot(_segDir);
|
|
const c = _diff.lengthSq();
|
|
const det = Math.abs(1 - a01 * a01);
|
|
let s0, s1, sqrDist, extDet;
|
|
if (det > 0) {
|
|
s0 = a01 * b1 - b0;
|
|
s1 = a01 * b0 - b1;
|
|
extDet = segExtent * det;
|
|
if (s0 >= 0) {
|
|
if (s1 >= -extDet) {
|
|
if (s1 <= extDet) {
|
|
const invDet = 1 / det;
|
|
s0 *= invDet;
|
|
s1 *= invDet;
|
|
sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
|
|
} else {
|
|
s1 = segExtent;
|
|
s0 = Math.max(0, -(a01 * s1 + b0));
|
|
sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
|
|
}
|
|
} else {
|
|
s1 = -segExtent;
|
|
s0 = Math.max(0, -(a01 * s1 + b0));
|
|
sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
|
|
}
|
|
} else {
|
|
if (s1 <= -extDet) {
|
|
s0 = Math.max(0, -(-a01 * segExtent + b0));
|
|
s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
|
|
sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
|
|
} else if (s1 <= extDet) {
|
|
s0 = 0;
|
|
s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
|
|
sqrDist = s1 * (s1 + 2 * b1) + c;
|
|
} else {
|
|
s0 = Math.max(0, -(a01 * segExtent + b0));
|
|
s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
|
|
sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
|
|
}
|
|
}
|
|
} else {
|
|
s1 = a01 > 0 ? -segExtent : segExtent;
|
|
s0 = Math.max(0, -(a01 * s1 + b0));
|
|
sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
|
|
}
|
|
if (optionalPointOnRay) {
|
|
optionalPointOnRay.copy(this.origin).addScaledVector(this.direction, s0);
|
|
}
|
|
if (optionalPointOnSegment) {
|
|
optionalPointOnSegment.copy(_segCenter).addScaledVector(_segDir, s1);
|
|
}
|
|
return sqrDist;
|
|
}
|
|
intersectSphere(sphere, target) {
|
|
_vector$a.subVectors(sphere.center, this.origin);
|
|
const tca = _vector$a.dot(this.direction);
|
|
const d2 = _vector$a.dot(_vector$a) - tca * tca;
|
|
const radius2 = sphere.radius * sphere.radius;
|
|
if (d2 > radius2)
|
|
return null;
|
|
const thc = Math.sqrt(radius2 - d2);
|
|
const t0 = tca - thc;
|
|
const t1 = tca + thc;
|
|
if (t1 < 0)
|
|
return null;
|
|
if (t0 < 0)
|
|
return this.at(t1, target);
|
|
return this.at(t0, target);
|
|
}
|
|
intersectsSphere(sphere) {
|
|
return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
|
|
}
|
|
distanceToPlane(plane) {
|
|
const denominator = plane.normal.dot(this.direction);
|
|
if (denominator === 0) {
|
|
if (plane.distanceToPoint(this.origin) === 0) {
|
|
return 0;
|
|
}
|
|
return null;
|
|
}
|
|
const t = -(this.origin.dot(plane.normal) + plane.constant) / denominator;
|
|
return t >= 0 ? t : null;
|
|
}
|
|
intersectPlane(plane, target) {
|
|
const t = this.distanceToPlane(plane);
|
|
if (t === null) {
|
|
return null;
|
|
}
|
|
return this.at(t, target);
|
|
}
|
|
intersectsPlane(plane) {
|
|
const distToPoint = plane.distanceToPoint(this.origin);
|
|
if (distToPoint === 0) {
|
|
return true;
|
|
}
|
|
const denominator = plane.normal.dot(this.direction);
|
|
if (denominator * distToPoint < 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
intersectBox(box, target) {
|
|
let tmin, tmax, tymin, tymax, tzmin, tzmax;
|
|
const invdirx = 1 / this.direction.x, invdiry = 1 / this.direction.y, invdirz = 1 / this.direction.z;
|
|
const origin = this.origin;
|
|
if (invdirx >= 0) {
|
|
tmin = (box.min.x - origin.x) * invdirx;
|
|
tmax = (box.max.x - origin.x) * invdirx;
|
|
} else {
|
|
tmin = (box.max.x - origin.x) * invdirx;
|
|
tmax = (box.min.x - origin.x) * invdirx;
|
|
}
|
|
if (invdiry >= 0) {
|
|
tymin = (box.min.y - origin.y) * invdiry;
|
|
tymax = (box.max.y - origin.y) * invdiry;
|
|
} else {
|
|
tymin = (box.max.y - origin.y) * invdiry;
|
|
tymax = (box.min.y - origin.y) * invdiry;
|
|
}
|
|
if (tmin > tymax || tymin > tmax)
|
|
return null;
|
|
if (tymin > tmin || isNaN(tmin))
|
|
tmin = tymin;
|
|
if (tymax < tmax || isNaN(tmax))
|
|
tmax = tymax;
|
|
if (invdirz >= 0) {
|
|
tzmin = (box.min.z - origin.z) * invdirz;
|
|
tzmax = (box.max.z - origin.z) * invdirz;
|
|
} else {
|
|
tzmin = (box.max.z - origin.z) * invdirz;
|
|
tzmax = (box.min.z - origin.z) * invdirz;
|
|
}
|
|
if (tmin > tzmax || tzmin > tmax)
|
|
return null;
|
|
if (tzmin > tmin || tmin !== tmin)
|
|
tmin = tzmin;
|
|
if (tzmax < tmax || tmax !== tmax)
|
|
tmax = tzmax;
|
|
if (tmax < 0)
|
|
return null;
|
|
return this.at(tmin >= 0 ? tmin : tmax, target);
|
|
}
|
|
intersectsBox(box) {
|
|
return this.intersectBox(box, _vector$a) !== null;
|
|
}
|
|
intersectTriangle(a, b, c, backfaceCulling, target) {
|
|
_edge1.subVectors(b, a);
|
|
_edge2.subVectors(c, a);
|
|
_normal$1.crossVectors(_edge1, _edge2);
|
|
let DdN = this.direction.dot(_normal$1);
|
|
let sign;
|
|
if (DdN > 0) {
|
|
if (backfaceCulling)
|
|
return null;
|
|
sign = 1;
|
|
} else if (DdN < 0) {
|
|
sign = -1;
|
|
DdN = -DdN;
|
|
} else {
|
|
return null;
|
|
}
|
|
_diff.subVectors(this.origin, a);
|
|
const DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2));
|
|
if (DdQxE2 < 0) {
|
|
return null;
|
|
}
|
|
const DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff));
|
|
if (DdE1xQ < 0) {
|
|
return null;
|
|
}
|
|
if (DdQxE2 + DdE1xQ > DdN) {
|
|
return null;
|
|
}
|
|
const QdN = -sign * _diff.dot(_normal$1);
|
|
if (QdN < 0) {
|
|
return null;
|
|
}
|
|
return this.at(QdN / DdN, target);
|
|
}
|
|
applyMatrix4(matrix4) {
|
|
this.origin.applyMatrix4(matrix4);
|
|
this.direction.transformDirection(matrix4);
|
|
return this;
|
|
}
|
|
equals(ray) {
|
|
return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
}
|
|
|
|
class Matrix4 {
|
|
constructor(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
|
|
Matrix4.prototype.isMatrix4 = true;
|
|
this.elements = [
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
];
|
|
if (n11 !== undefined) {
|
|
this.set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44);
|
|
}
|
|
}
|
|
set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
|
|
const te = this.elements;
|
|
te[0] = n11;
|
|
te[4] = n12;
|
|
te[8] = n13;
|
|
te[12] = n14;
|
|
te[1] = n21;
|
|
te[5] = n22;
|
|
te[9] = n23;
|
|
te[13] = n24;
|
|
te[2] = n31;
|
|
te[6] = n32;
|
|
te[10] = n33;
|
|
te[14] = n34;
|
|
te[3] = n41;
|
|
te[7] = n42;
|
|
te[11] = n43;
|
|
te[15] = n44;
|
|
return this;
|
|
}
|
|
identity() {
|
|
this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new Matrix4().fromArray(this.elements);
|
|
}
|
|
copy(m) {
|
|
const te = this.elements;
|
|
const me = m.elements;
|
|
te[0] = me[0];
|
|
te[1] = me[1];
|
|
te[2] = me[2];
|
|
te[3] = me[3];
|
|
te[4] = me[4];
|
|
te[5] = me[5];
|
|
te[6] = me[6];
|
|
te[7] = me[7];
|
|
te[8] = me[8];
|
|
te[9] = me[9];
|
|
te[10] = me[10];
|
|
te[11] = me[11];
|
|
te[12] = me[12];
|
|
te[13] = me[13];
|
|
te[14] = me[14];
|
|
te[15] = me[15];
|
|
return this;
|
|
}
|
|
copyPosition(m) {
|
|
const te = this.elements, me = m.elements;
|
|
te[12] = me[12];
|
|
te[13] = me[13];
|
|
te[14] = me[14];
|
|
return this;
|
|
}
|
|
setFromMatrix3(m) {
|
|
const me = m.elements;
|
|
this.set(me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
extractBasis(xAxis, yAxis, zAxis) {
|
|
xAxis.setFromMatrixColumn(this, 0);
|
|
yAxis.setFromMatrixColumn(this, 1);
|
|
zAxis.setFromMatrixColumn(this, 2);
|
|
return this;
|
|
}
|
|
makeBasis(xAxis, yAxis, zAxis) {
|
|
this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
extractRotation(m) {
|
|
const te = this.elements;
|
|
const me = m.elements;
|
|
const scaleX = 1 / _v1$5.setFromMatrixColumn(m, 0).length();
|
|
const scaleY = 1 / _v1$5.setFromMatrixColumn(m, 1).length();
|
|
const scaleZ = 1 / _v1$5.setFromMatrixColumn(m, 2).length();
|
|
te[0] = me[0] * scaleX;
|
|
te[1] = me[1] * scaleX;
|
|
te[2] = me[2] * scaleX;
|
|
te[3] = 0;
|
|
te[4] = me[4] * scaleY;
|
|
te[5] = me[5] * scaleY;
|
|
te[6] = me[6] * scaleY;
|
|
te[7] = 0;
|
|
te[8] = me[8] * scaleZ;
|
|
te[9] = me[9] * scaleZ;
|
|
te[10] = me[10] * scaleZ;
|
|
te[11] = 0;
|
|
te[12] = 0;
|
|
te[13] = 0;
|
|
te[14] = 0;
|
|
te[15] = 1;
|
|
return this;
|
|
}
|
|
makeRotationFromEuler(euler) {
|
|
const te = this.elements;
|
|
const { x, y, z } = euler;
|
|
const a = Math.cos(x), b = Math.sin(x);
|
|
const c = Math.cos(y), d = Math.sin(y);
|
|
const e = Math.cos(z), f = Math.sin(z);
|
|
if (euler.order === "XYZ") {
|
|
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
te[0] = c * e;
|
|
te[4] = -c * f;
|
|
te[8] = d;
|
|
te[1] = af + be * d;
|
|
te[5] = ae - bf * d;
|
|
te[9] = -b * c;
|
|
te[2] = bf - ae * d;
|
|
te[6] = be + af * d;
|
|
te[10] = a * c;
|
|
} else if (euler.order === "YXZ") {
|
|
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
te[0] = ce + df * b;
|
|
te[4] = de * b - cf;
|
|
te[8] = a * d;
|
|
te[1] = a * f;
|
|
te[5] = a * e;
|
|
te[9] = -b;
|
|
te[2] = cf * b - de;
|
|
te[6] = df + ce * b;
|
|
te[10] = a * c;
|
|
} else if (euler.order === "ZXY") {
|
|
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
te[0] = ce - df * b;
|
|
te[4] = -a * f;
|
|
te[8] = de + cf * b;
|
|
te[1] = cf + de * b;
|
|
te[5] = a * e;
|
|
te[9] = df - ce * b;
|
|
te[2] = -a * d;
|
|
te[6] = b;
|
|
te[10] = a * c;
|
|
} else if (euler.order === "ZYX") {
|
|
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
te[0] = c * e;
|
|
te[4] = be * d - af;
|
|
te[8] = ae * d + bf;
|
|
te[1] = c * f;
|
|
te[5] = bf * d + ae;
|
|
te[9] = af * d - be;
|
|
te[2] = -d;
|
|
te[6] = b * c;
|
|
te[10] = a * c;
|
|
} else if (euler.order === "YZX") {
|
|
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
te[0] = c * e;
|
|
te[4] = bd - ac * f;
|
|
te[8] = bc * f + ad;
|
|
te[1] = f;
|
|
te[5] = a * e;
|
|
te[9] = -b * e;
|
|
te[2] = -d * e;
|
|
te[6] = ad * f + bc;
|
|
te[10] = ac - bd * f;
|
|
} else if (euler.order === "XZY") {
|
|
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
te[0] = c * e;
|
|
te[4] = -f;
|
|
te[8] = d * e;
|
|
te[1] = ac * f + bd;
|
|
te[5] = a * e;
|
|
te[9] = ad * f - bc;
|
|
te[2] = bc * f - ad;
|
|
te[6] = b * e;
|
|
te[10] = bd * f + ac;
|
|
}
|
|
te[3] = 0;
|
|
te[7] = 0;
|
|
te[11] = 0;
|
|
te[12] = 0;
|
|
te[13] = 0;
|
|
te[14] = 0;
|
|
te[15] = 1;
|
|
return this;
|
|
}
|
|
makeRotationFromQuaternion(q) {
|
|
return this.compose(_zero, q, _one);
|
|
}
|
|
lookAt(eye, target, up) {
|
|
const te = this.elements;
|
|
_z.subVectors(eye, target);
|
|
if (_z.lengthSq() === 0) {
|
|
_z.z = 1;
|
|
}
|
|
_z.normalize();
|
|
_x.crossVectors(up, _z);
|
|
if (_x.lengthSq() === 0) {
|
|
if (Math.abs(up.z) === 1) {
|
|
_z.x += 0.0001;
|
|
} else {
|
|
_z.z += 0.0001;
|
|
}
|
|
_z.normalize();
|
|
_x.crossVectors(up, _z);
|
|
}
|
|
_x.normalize();
|
|
_y.crossVectors(_z, _x);
|
|
te[0] = _x.x;
|
|
te[4] = _y.x;
|
|
te[8] = _z.x;
|
|
te[1] = _x.y;
|
|
te[5] = _y.y;
|
|
te[9] = _z.y;
|
|
te[2] = _x.z;
|
|
te[6] = _y.z;
|
|
te[10] = _z.z;
|
|
return this;
|
|
}
|
|
multiply(m) {
|
|
return this.multiplyMatrices(this, m);
|
|
}
|
|
premultiply(m) {
|
|
return this.multiplyMatrices(m, this);
|
|
}
|
|
multiplyMatrices(a, b) {
|
|
const ae = a.elements;
|
|
const be = b.elements;
|
|
const te = this.elements;
|
|
const a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
|
|
const a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
|
|
const a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
|
|
const a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
|
|
const b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
|
|
const b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
|
|
const b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
|
|
const b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
|
|
te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
|
|
te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
|
|
te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
|
|
te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
|
|
te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
|
|
te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
|
te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
|
te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
|
te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
|
te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
|
te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
|
te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
|
te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
|
te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
|
te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
|
te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
|
return this;
|
|
}
|
|
multiplyScalar(s) {
|
|
const te = this.elements;
|
|
te[0] *= s;
|
|
te[4] *= s;
|
|
te[8] *= s;
|
|
te[12] *= s;
|
|
te[1] *= s;
|
|
te[5] *= s;
|
|
te[9] *= s;
|
|
te[13] *= s;
|
|
te[2] *= s;
|
|
te[6] *= s;
|
|
te[10] *= s;
|
|
te[14] *= s;
|
|
te[3] *= s;
|
|
te[7] *= s;
|
|
te[11] *= s;
|
|
te[15] *= s;
|
|
return this;
|
|
}
|
|
determinant() {
|
|
const te = this.elements;
|
|
const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
|
|
const n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
|
|
const n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
|
|
const n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
|
|
return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
|
|
}
|
|
transpose() {
|
|
const te = this.elements;
|
|
let tmp;
|
|
tmp = te[1];
|
|
te[1] = te[4];
|
|
te[4] = tmp;
|
|
tmp = te[2];
|
|
te[2] = te[8];
|
|
te[8] = tmp;
|
|
tmp = te[6];
|
|
te[6] = te[9];
|
|
te[9] = tmp;
|
|
tmp = te[3];
|
|
te[3] = te[12];
|
|
te[12] = tmp;
|
|
tmp = te[7];
|
|
te[7] = te[13];
|
|
te[13] = tmp;
|
|
tmp = te[11];
|
|
te[11] = te[14];
|
|
te[14] = tmp;
|
|
return this;
|
|
}
|
|
setPosition(x, y, z) {
|
|
const te = this.elements;
|
|
if (x.isVector3) {
|
|
te[12] = x.x;
|
|
te[13] = x.y;
|
|
te[14] = x.z;
|
|
} else {
|
|
te[12] = x;
|
|
te[13] = y;
|
|
te[14] = z;
|
|
}
|
|
return this;
|
|
}
|
|
invert() {
|
|
const te = this.elements, n11 = te[0], n21 = te[1], n31 = te[2], n41 = te[3], n12 = te[4], n22 = te[5], n32 = te[6], n42 = te[7], n13 = te[8], n23 = te[9], n33 = te[10], n43 = te[11], n14 = te[12], n24 = te[13], n34 = te[14], n44 = te[15], t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44, t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44, t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44, t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
|
|
const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
|
|
if (det === 0)
|
|
return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
const detInv = 1 / det;
|
|
te[0] = t11 * detInv;
|
|
te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
|
|
te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
|
|
te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
|
|
te[4] = t12 * detInv;
|
|
te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
|
|
te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
|
|
te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
|
|
te[8] = t13 * detInv;
|
|
te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
|
|
te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
|
|
te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
|
|
te[12] = t14 * detInv;
|
|
te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
|
|
te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
|
|
te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
|
|
return this;
|
|
}
|
|
scale(v) {
|
|
const te = this.elements;
|
|
const { x, y, z } = v;
|
|
te[0] *= x;
|
|
te[4] *= y;
|
|
te[8] *= z;
|
|
te[1] *= x;
|
|
te[5] *= y;
|
|
te[9] *= z;
|
|
te[2] *= x;
|
|
te[6] *= y;
|
|
te[10] *= z;
|
|
te[3] *= x;
|
|
te[7] *= y;
|
|
te[11] *= z;
|
|
return this;
|
|
}
|
|
getMaxScaleOnAxis() {
|
|
const te = this.elements;
|
|
const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
|
|
const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
|
|
const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
|
|
return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
|
|
}
|
|
makeTranslation(x, y, z) {
|
|
if (x.isVector3) {
|
|
this.set(1, 0, 0, x.x, 0, 1, 0, x.y, 0, 0, 1, x.z, 0, 0, 0, 1);
|
|
} else {
|
|
this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
|
|
}
|
|
return this;
|
|
}
|
|
makeRotationX(theta) {
|
|
const c = Math.cos(theta), s = Math.sin(theta);
|
|
this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
makeRotationY(theta) {
|
|
const c = Math.cos(theta), s = Math.sin(theta);
|
|
this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
makeRotationZ(theta) {
|
|
const c = Math.cos(theta), s = Math.sin(theta);
|
|
this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
makeRotationAxis(axis, angle) {
|
|
const c = Math.cos(angle);
|
|
const s = Math.sin(angle);
|
|
const t = 1 - c;
|
|
const { x, y, z } = axis;
|
|
const tx = t * x, ty = t * y;
|
|
this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
makeScale(x, y, z) {
|
|
this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
makeShear(xy, xz, yx, yz, zx, zy) {
|
|
this.set(1, yx, zx, 0, xy, 1, zy, 0, xz, yz, 1, 0, 0, 0, 0, 1);
|
|
return this;
|
|
}
|
|
compose(position, quaternion, scale) {
|
|
const te = this.elements;
|
|
const { _x: x, _y: y, _z: z, _w: w } = quaternion;
|
|
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
const xx = x * x2, xy = x * y2, xz = x * z2;
|
|
const yy = y * y2, yz = y * z2, zz = z * z2;
|
|
const wx = w * x2, wy = w * y2, wz = w * z2;
|
|
const { x: sx, y: sy, z: sz } = scale;
|
|
te[0] = (1 - (yy + zz)) * sx;
|
|
te[1] = (xy + wz) * sx;
|
|
te[2] = (xz - wy) * sx;
|
|
te[3] = 0;
|
|
te[4] = (xy - wz) * sy;
|
|
te[5] = (1 - (xx + zz)) * sy;
|
|
te[6] = (yz + wx) * sy;
|
|
te[7] = 0;
|
|
te[8] = (xz + wy) * sz;
|
|
te[9] = (yz - wx) * sz;
|
|
te[10] = (1 - (xx + yy)) * sz;
|
|
te[11] = 0;
|
|
te[12] = position.x;
|
|
te[13] = position.y;
|
|
te[14] = position.z;
|
|
te[15] = 1;
|
|
return this;
|
|
}
|
|
decompose(position, quaternion, scale) {
|
|
const te = this.elements;
|
|
let sx = _v1$5.set(te[0], te[1], te[2]).length();
|
|
const sy = _v1$5.set(te[4], te[5], te[6]).length();
|
|
const sz = _v1$5.set(te[8], te[9], te[10]).length();
|
|
const det = this.determinant();
|
|
if (det < 0)
|
|
sx = -sx;
|
|
position.x = te[12];
|
|
position.y = te[13];
|
|
position.z = te[14];
|
|
_m1$2.copy(this);
|
|
const invSX = 1 / sx;
|
|
const invSY = 1 / sy;
|
|
const invSZ = 1 / sz;
|
|
_m1$2.elements[0] *= invSX;
|
|
_m1$2.elements[1] *= invSX;
|
|
_m1$2.elements[2] *= invSX;
|
|
_m1$2.elements[4] *= invSY;
|
|
_m1$2.elements[5] *= invSY;
|
|
_m1$2.elements[6] *= invSY;
|
|
_m1$2.elements[8] *= invSZ;
|
|
_m1$2.elements[9] *= invSZ;
|
|
_m1$2.elements[10] *= invSZ;
|
|
quaternion.setFromRotationMatrix(_m1$2);
|
|
scale.x = sx;
|
|
scale.y = sy;
|
|
scale.z = sz;
|
|
return this;
|
|
}
|
|
makePerspective(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) {
|
|
const te = this.elements;
|
|
const x = 2 * near / (right - left);
|
|
const y = 2 * near / (top - bottom);
|
|
const a = (right + left) / (right - left);
|
|
const b = (top + bottom) / (top - bottom);
|
|
let c, d;
|
|
if (coordinateSystem === WebGLCoordinateSystem) {
|
|
c = -(far + near) / (far - near);
|
|
d = -2 * far * near / (far - near);
|
|
} else if (coordinateSystem === WebGPUCoordinateSystem) {
|
|
c = -far / (far - near);
|
|
d = -far * near / (far - near);
|
|
} else {
|
|
throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: " + coordinateSystem);
|
|
}
|
|
te[0] = x;
|
|
te[4] = 0;
|
|
te[8] = a;
|
|
te[12] = 0;
|
|
te[1] = 0;
|
|
te[5] = y;
|
|
te[9] = b;
|
|
te[13] = 0;
|
|
te[2] = 0;
|
|
te[6] = 0;
|
|
te[10] = c;
|
|
te[14] = d;
|
|
te[3] = 0;
|
|
te[7] = 0;
|
|
te[11] = -1;
|
|
te[15] = 0;
|
|
return this;
|
|
}
|
|
makeOrthographic(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) {
|
|
const te = this.elements;
|
|
const w = 1 / (right - left);
|
|
const h = 1 / (top - bottom);
|
|
const p = 1 / (far - near);
|
|
const x = (right + left) * w;
|
|
const y = (top + bottom) * h;
|
|
let z, zInv;
|
|
if (coordinateSystem === WebGLCoordinateSystem) {
|
|
z = (far + near) * p;
|
|
zInv = -2 * p;
|
|
} else if (coordinateSystem === WebGPUCoordinateSystem) {
|
|
z = near * p;
|
|
zInv = -1 * p;
|
|
} else {
|
|
throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: " + coordinateSystem);
|
|
}
|
|
te[0] = 2 * w;
|
|
te[4] = 0;
|
|
te[8] = 0;
|
|
te[12] = -x;
|
|
te[1] = 0;
|
|
te[5] = 2 * h;
|
|
te[9] = 0;
|
|
te[13] = -y;
|
|
te[2] = 0;
|
|
te[6] = 0;
|
|
te[10] = zInv;
|
|
te[14] = -z;
|
|
te[3] = 0;
|
|
te[7] = 0;
|
|
te[11] = 0;
|
|
te[15] = 1;
|
|
return this;
|
|
}
|
|
equals(matrix) {
|
|
const te = this.elements;
|
|
const me = matrix.elements;
|
|
for (let i = 0;i < 16; i++) {
|
|
if (te[i] !== me[i])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
for (let i = 0;i < 16; i++) {
|
|
this.elements[i] = array[i + offset];
|
|
}
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
const te = this.elements;
|
|
array[offset] = te[0];
|
|
array[offset + 1] = te[1];
|
|
array[offset + 2] = te[2];
|
|
array[offset + 3] = te[3];
|
|
array[offset + 4] = te[4];
|
|
array[offset + 5] = te[5];
|
|
array[offset + 6] = te[6];
|
|
array[offset + 7] = te[7];
|
|
array[offset + 8] = te[8];
|
|
array[offset + 9] = te[9];
|
|
array[offset + 10] = te[10];
|
|
array[offset + 11] = te[11];
|
|
array[offset + 12] = te[12];
|
|
array[offset + 13] = te[13];
|
|
array[offset + 14] = te[14];
|
|
array[offset + 15] = te[15];
|
|
return array;
|
|
}
|
|
}
|
|
|
|
class Layers {
|
|
constructor() {
|
|
this.mask = 1 | 0;
|
|
}
|
|
set(channel) {
|
|
this.mask = (1 << channel | 0) >>> 0;
|
|
}
|
|
enable(channel) {
|
|
this.mask |= 1 << channel | 0;
|
|
}
|
|
enableAll() {
|
|
this.mask = 4294967295 | 0;
|
|
}
|
|
toggle(channel) {
|
|
this.mask ^= 1 << channel | 0;
|
|
}
|
|
disable(channel) {
|
|
this.mask &= ~(1 << channel | 0);
|
|
}
|
|
disableAll() {
|
|
this.mask = 0;
|
|
}
|
|
test(layers) {
|
|
return (this.mask & layers.mask) !== 0;
|
|
}
|
|
isEnabled(channel) {
|
|
return (this.mask & (1 << channel | 0)) !== 0;
|
|
}
|
|
}
|
|
|
|
class Triangle {
|
|
constructor(a = new Vector3, b = new Vector3, c = new Vector3) {
|
|
this.a = a;
|
|
this.b = b;
|
|
this.c = c;
|
|
}
|
|
static getNormal(a, b, c, target) {
|
|
target.subVectors(c, b);
|
|
_v0$1.subVectors(a, b);
|
|
target.cross(_v0$1);
|
|
const targetLengthSq = target.lengthSq();
|
|
if (targetLengthSq > 0) {
|
|
return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
|
|
}
|
|
return target.set(0, 0, 0);
|
|
}
|
|
static getBarycoord(point, a, b, c, target) {
|
|
_v0$1.subVectors(c, a);
|
|
_v1$3.subVectors(b, a);
|
|
_v2$2.subVectors(point, a);
|
|
const dot00 = _v0$1.dot(_v0$1);
|
|
const dot01 = _v0$1.dot(_v1$3);
|
|
const dot02 = _v0$1.dot(_v2$2);
|
|
const dot11 = _v1$3.dot(_v1$3);
|
|
const dot12 = _v1$3.dot(_v2$2);
|
|
const denom = dot00 * dot11 - dot01 * dot01;
|
|
if (denom === 0) {
|
|
target.set(0, 0, 0);
|
|
return null;
|
|
}
|
|
const invDenom = 1 / denom;
|
|
const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
|
|
const v = (dot00 * dot12 - dot01 * dot02) * invDenom;
|
|
return target.set(1 - u - v, v, u);
|
|
}
|
|
static containsPoint(point, a, b, c) {
|
|
if (this.getBarycoord(point, a, b, c, _v3$2) === null) {
|
|
return false;
|
|
}
|
|
return _v3$2.x >= 0 && _v3$2.y >= 0 && _v3$2.x + _v3$2.y <= 1;
|
|
}
|
|
static getInterpolation(point, p1, p2, p3, v1, v2, v3, target) {
|
|
if (this.getBarycoord(point, p1, p2, p3, _v3$2) === null) {
|
|
target.x = 0;
|
|
target.y = 0;
|
|
if ("z" in target)
|
|
target.z = 0;
|
|
if ("w" in target)
|
|
target.w = 0;
|
|
return null;
|
|
}
|
|
target.setScalar(0);
|
|
target.addScaledVector(v1, _v3$2.x);
|
|
target.addScaledVector(v2, _v3$2.y);
|
|
target.addScaledVector(v3, _v3$2.z);
|
|
return target;
|
|
}
|
|
static getInterpolatedAttribute(attr, i1, i2, i3, barycoord, target) {
|
|
_v40.setScalar(0);
|
|
_v41.setScalar(0);
|
|
_v42.setScalar(0);
|
|
_v40.fromBufferAttribute(attr, i1);
|
|
_v41.fromBufferAttribute(attr, i2);
|
|
_v42.fromBufferAttribute(attr, i3);
|
|
target.setScalar(0);
|
|
target.addScaledVector(_v40, barycoord.x);
|
|
target.addScaledVector(_v41, barycoord.y);
|
|
target.addScaledVector(_v42, barycoord.z);
|
|
return target;
|
|
}
|
|
static isFrontFacing(a, b, c, direction) {
|
|
_v0$1.subVectors(c, b);
|
|
_v1$3.subVectors(a, b);
|
|
return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
|
|
}
|
|
set(a, b, c) {
|
|
this.a.copy(a);
|
|
this.b.copy(b);
|
|
this.c.copy(c);
|
|
return this;
|
|
}
|
|
setFromPointsAndIndices(points, i0, i1, i2) {
|
|
this.a.copy(points[i0]);
|
|
this.b.copy(points[i1]);
|
|
this.c.copy(points[i2]);
|
|
return this;
|
|
}
|
|
setFromAttributeAndIndices(attribute, i0, i1, i2) {
|
|
this.a.fromBufferAttribute(attribute, i0);
|
|
this.b.fromBufferAttribute(attribute, i1);
|
|
this.c.fromBufferAttribute(attribute, i2);
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
copy(triangle) {
|
|
this.a.copy(triangle.a);
|
|
this.b.copy(triangle.b);
|
|
this.c.copy(triangle.c);
|
|
return this;
|
|
}
|
|
getArea() {
|
|
_v0$1.subVectors(this.c, this.b);
|
|
_v1$3.subVectors(this.a, this.b);
|
|
return _v0$1.cross(_v1$3).length() * 0.5;
|
|
}
|
|
getMidpoint(target) {
|
|
return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
|
|
}
|
|
getNormal(target) {
|
|
return Triangle.getNormal(this.a, this.b, this.c, target);
|
|
}
|
|
getPlane(target) {
|
|
return target.setFromCoplanarPoints(this.a, this.b, this.c);
|
|
}
|
|
getBarycoord(point, target) {
|
|
return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
|
|
}
|
|
getInterpolation(point, v1, v2, v3, target) {
|
|
return Triangle.getInterpolation(point, this.a, this.b, this.c, v1, v2, v3, target);
|
|
}
|
|
containsPoint(point) {
|
|
return Triangle.containsPoint(point, this.a, this.b, this.c);
|
|
}
|
|
isFrontFacing(direction) {
|
|
return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
|
|
}
|
|
intersectsBox(box) {
|
|
return box.intersectsTriangle(this);
|
|
}
|
|
closestPointToPoint(p, target) {
|
|
const a = this.a, b = this.b, c = this.c;
|
|
let v, w;
|
|
_vab.subVectors(b, a);
|
|
_vac.subVectors(c, a);
|
|
_vap.subVectors(p, a);
|
|
const d1 = _vab.dot(_vap);
|
|
const d2 = _vac.dot(_vap);
|
|
if (d1 <= 0 && d2 <= 0) {
|
|
return target.copy(a);
|
|
}
|
|
_vbp.subVectors(p, b);
|
|
const d3 = _vab.dot(_vbp);
|
|
const d4 = _vac.dot(_vbp);
|
|
if (d3 >= 0 && d4 <= d3) {
|
|
return target.copy(b);
|
|
}
|
|
const vc = d1 * d4 - d3 * d2;
|
|
if (vc <= 0 && d1 >= 0 && d3 <= 0) {
|
|
v = d1 / (d1 - d3);
|
|
return target.copy(a).addScaledVector(_vab, v);
|
|
}
|
|
_vcp.subVectors(p, c);
|
|
const d5 = _vab.dot(_vcp);
|
|
const d6 = _vac.dot(_vcp);
|
|
if (d6 >= 0 && d5 <= d6) {
|
|
return target.copy(c);
|
|
}
|
|
const vb = d5 * d2 - d1 * d6;
|
|
if (vb <= 0 && d2 >= 0 && d6 <= 0) {
|
|
w = d2 / (d2 - d6);
|
|
return target.copy(a).addScaledVector(_vac, w);
|
|
}
|
|
const va = d3 * d6 - d5 * d4;
|
|
if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
|
|
_vbc.subVectors(c, b);
|
|
w = (d4 - d3) / (d4 - d3 + (d5 - d6));
|
|
return target.copy(b).addScaledVector(_vbc, w);
|
|
}
|
|
const denom = 1 / (va + vb + vc);
|
|
v = vb * denom;
|
|
w = vc * denom;
|
|
return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
|
|
}
|
|
equals(triangle) {
|
|
return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
|
|
}
|
|
}
|
|
function hue2rgb(p, q, t) {
|
|
if (t < 0)
|
|
t += 1;
|
|
if (t > 1)
|
|
t -= 1;
|
|
if (t < 1 / 6)
|
|
return p + (q - p) * 6 * t;
|
|
if (t < 1 / 2)
|
|
return q;
|
|
if (t < 2 / 3)
|
|
return p + (q - p) * 6 * (2 / 3 - t);
|
|
return p;
|
|
}
|
|
function _generateTables() {
|
|
const buffer = new ArrayBuffer(4);
|
|
const floatView = new Float32Array(buffer);
|
|
const uint32View = new Uint32Array(buffer);
|
|
const baseTable = new Uint32Array(512);
|
|
const shiftTable = new Uint32Array(512);
|
|
for (let i = 0;i < 256; ++i) {
|
|
const e = i - 127;
|
|
if (e < -27) {
|
|
baseTable[i] = 0;
|
|
baseTable[i | 256] = 32768;
|
|
shiftTable[i] = 24;
|
|
shiftTable[i | 256] = 24;
|
|
} else if (e < -14) {
|
|
baseTable[i] = 1024 >> -e - 14;
|
|
baseTable[i | 256] = 1024 >> -e - 14 | 32768;
|
|
shiftTable[i] = -e - 1;
|
|
shiftTable[i | 256] = -e - 1;
|
|
} else if (e <= 15) {
|
|
baseTable[i] = e + 15 << 10;
|
|
baseTable[i | 256] = e + 15 << 10 | 32768;
|
|
shiftTable[i] = 13;
|
|
shiftTable[i | 256] = 13;
|
|
} else if (e < 128) {
|
|
baseTable[i] = 31744;
|
|
baseTable[i | 256] = 64512;
|
|
shiftTable[i] = 24;
|
|
shiftTable[i | 256] = 24;
|
|
} else {
|
|
baseTable[i] = 31744;
|
|
baseTable[i | 256] = 64512;
|
|
shiftTable[i] = 13;
|
|
shiftTable[i | 256] = 13;
|
|
}
|
|
}
|
|
const mantissaTable = new Uint32Array(2048);
|
|
const exponentTable = new Uint32Array(64);
|
|
const offsetTable = new Uint32Array(64);
|
|
for (let i = 1;i < 1024; ++i) {
|
|
let m = i << 13;
|
|
let e = 0;
|
|
while ((m & 8388608) === 0) {
|
|
m <<= 1;
|
|
e -= 8388608;
|
|
}
|
|
m &= -8388609;
|
|
e += 947912704;
|
|
mantissaTable[i] = m | e;
|
|
}
|
|
for (let i = 1024;i < 2048; ++i) {
|
|
mantissaTable[i] = 939524096 + (i - 1024 << 13);
|
|
}
|
|
for (let i = 1;i < 31; ++i) {
|
|
exponentTable[i] = i << 23;
|
|
}
|
|
exponentTable[31] = 1199570944;
|
|
exponentTable[32] = 2147483648;
|
|
for (let i = 33;i < 63; ++i) {
|
|
exponentTable[i] = 2147483648 + (i - 32 << 23);
|
|
}
|
|
exponentTable[63] = 3347054592;
|
|
for (let i = 1;i < 64; ++i) {
|
|
if (i !== 32) {
|
|
offsetTable[i] = 1024;
|
|
}
|
|
}
|
|
return {
|
|
floatView,
|
|
uint32View,
|
|
baseTable,
|
|
shiftTable,
|
|
mantissaTable,
|
|
exponentTable,
|
|
offsetTable
|
|
};
|
|
}
|
|
function toHalfFloat(val) {
|
|
if (Math.abs(val) > 65504)
|
|
console.warn("THREE.DataUtils.toHalfFloat(): Value out of range.");
|
|
val = clamp(val, -65504, 65504);
|
|
_tables.floatView[0] = val;
|
|
const f = _tables.uint32View[0];
|
|
const e = f >> 23 & 511;
|
|
return _tables.baseTable[e] + ((f & 8388607) >> _tables.shiftTable[e]);
|
|
}
|
|
function fromHalfFloat(val) {
|
|
const m = val >> 10;
|
|
_tables.uint32View[0] = _tables.mantissaTable[_tables.offsetTable[m] + (val & 1023)] + _tables.exponentTable[m];
|
|
return _tables.floatView[0];
|
|
}
|
|
|
|
class BufferAttribute {
|
|
constructor(array, itemSize, normalized = false) {
|
|
if (Array.isArray(array)) {
|
|
throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");
|
|
}
|
|
this.isBufferAttribute = true;
|
|
Object.defineProperty(this, "id", { value: _id$2++ });
|
|
this.name = "";
|
|
this.array = array;
|
|
this.itemSize = itemSize;
|
|
this.count = array !== undefined ? array.length / itemSize : 0;
|
|
this.normalized = normalized;
|
|
this.usage = StaticDrawUsage;
|
|
this.updateRanges = [];
|
|
this.gpuType = FloatType;
|
|
this.version = 0;
|
|
}
|
|
onUploadCallback() {}
|
|
set needsUpdate(value) {
|
|
if (value === true)
|
|
this.version++;
|
|
}
|
|
setUsage(value) {
|
|
this.usage = value;
|
|
return this;
|
|
}
|
|
addUpdateRange(start, count) {
|
|
this.updateRanges.push({ start, count });
|
|
}
|
|
clearUpdateRanges() {
|
|
this.updateRanges.length = 0;
|
|
}
|
|
copy(source) {
|
|
this.name = source.name;
|
|
this.array = new source.array.constructor(source.array);
|
|
this.itemSize = source.itemSize;
|
|
this.count = source.count;
|
|
this.normalized = source.normalized;
|
|
this.usage = source.usage;
|
|
this.gpuType = source.gpuType;
|
|
return this;
|
|
}
|
|
copyAt(index1, attribute, index2) {
|
|
index1 *= this.itemSize;
|
|
index2 *= attribute.itemSize;
|
|
for (let i = 0, l = this.itemSize;i < l; i++) {
|
|
this.array[index1 + i] = attribute.array[index2 + i];
|
|
}
|
|
return this;
|
|
}
|
|
copyArray(array) {
|
|
this.array.set(array);
|
|
return this;
|
|
}
|
|
applyMatrix3(m) {
|
|
if (this.itemSize === 2) {
|
|
for (let i = 0, l = this.count;i < l; i++) {
|
|
_vector2$1.fromBufferAttribute(this, i);
|
|
_vector2$1.applyMatrix3(m);
|
|
this.setXY(i, _vector2$1.x, _vector2$1.y);
|
|
}
|
|
} else if (this.itemSize === 3) {
|
|
for (let i = 0, l = this.count;i < l; i++) {
|
|
_vector$9.fromBufferAttribute(this, i);
|
|
_vector$9.applyMatrix3(m);
|
|
this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
applyMatrix4(m) {
|
|
for (let i = 0, l = this.count;i < l; i++) {
|
|
_vector$9.fromBufferAttribute(this, i);
|
|
_vector$9.applyMatrix4(m);
|
|
this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
|
|
}
|
|
return this;
|
|
}
|
|
applyNormalMatrix(m) {
|
|
for (let i = 0, l = this.count;i < l; i++) {
|
|
_vector$9.fromBufferAttribute(this, i);
|
|
_vector$9.applyNormalMatrix(m);
|
|
this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
|
|
}
|
|
return this;
|
|
}
|
|
transformDirection(m) {
|
|
for (let i = 0, l = this.count;i < l; i++) {
|
|
_vector$9.fromBufferAttribute(this, i);
|
|
_vector$9.transformDirection(m);
|
|
this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
|
|
}
|
|
return this;
|
|
}
|
|
set(value, offset = 0) {
|
|
this.array.set(value, offset);
|
|
return this;
|
|
}
|
|
getComponent(index, component) {
|
|
let value = this.array[index * this.itemSize + component];
|
|
if (this.normalized)
|
|
value = denormalize(value, this.array);
|
|
return value;
|
|
}
|
|
setComponent(index, component, value) {
|
|
if (this.normalized)
|
|
value = normalize(value, this.array);
|
|
this.array[index * this.itemSize + component] = value;
|
|
return this;
|
|
}
|
|
getX(index) {
|
|
let x = this.array[index * this.itemSize];
|
|
if (this.normalized)
|
|
x = denormalize(x, this.array);
|
|
return x;
|
|
}
|
|
setX(index, x) {
|
|
if (this.normalized)
|
|
x = normalize(x, this.array);
|
|
this.array[index * this.itemSize] = x;
|
|
return this;
|
|
}
|
|
getY(index) {
|
|
let y = this.array[index * this.itemSize + 1];
|
|
if (this.normalized)
|
|
y = denormalize(y, this.array);
|
|
return y;
|
|
}
|
|
setY(index, y) {
|
|
if (this.normalized)
|
|
y = normalize(y, this.array);
|
|
this.array[index * this.itemSize + 1] = y;
|
|
return this;
|
|
}
|
|
getZ(index) {
|
|
let z = this.array[index * this.itemSize + 2];
|
|
if (this.normalized)
|
|
z = denormalize(z, this.array);
|
|
return z;
|
|
}
|
|
setZ(index, z) {
|
|
if (this.normalized)
|
|
z = normalize(z, this.array);
|
|
this.array[index * this.itemSize + 2] = z;
|
|
return this;
|
|
}
|
|
getW(index) {
|
|
let w = this.array[index * this.itemSize + 3];
|
|
if (this.normalized)
|
|
w = denormalize(w, this.array);
|
|
return w;
|
|
}
|
|
setW(index, w) {
|
|
if (this.normalized)
|
|
w = normalize(w, this.array);
|
|
this.array[index * this.itemSize + 3] = w;
|
|
return this;
|
|
}
|
|
setXY(index, x, y) {
|
|
index *= this.itemSize;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
}
|
|
this.array[index + 0] = x;
|
|
this.array[index + 1] = y;
|
|
return this;
|
|
}
|
|
setXYZ(index, x, y, z) {
|
|
index *= this.itemSize;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
z = normalize(z, this.array);
|
|
}
|
|
this.array[index + 0] = x;
|
|
this.array[index + 1] = y;
|
|
this.array[index + 2] = z;
|
|
return this;
|
|
}
|
|
setXYZW(index, x, y, z, w) {
|
|
index *= this.itemSize;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
z = normalize(z, this.array);
|
|
w = normalize(w, this.array);
|
|
}
|
|
this.array[index + 0] = x;
|
|
this.array[index + 1] = y;
|
|
this.array[index + 2] = z;
|
|
this.array[index + 3] = w;
|
|
return this;
|
|
}
|
|
onUpload(callback) {
|
|
this.onUploadCallback = callback;
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor(this.array, this.itemSize).copy(this);
|
|
}
|
|
toJSON() {
|
|
const data = {
|
|
itemSize: this.itemSize,
|
|
type: this.array.constructor.name,
|
|
array: Array.from(this.array),
|
|
normalized: this.normalized
|
|
};
|
|
if (this.name !== "")
|
|
data.name = this.name;
|
|
if (this.usage !== StaticDrawUsage)
|
|
data.usage = this.usage;
|
|
return data;
|
|
}
|
|
}
|
|
function checkIntersection$1(object, material, raycaster, ray, pA, pB, pC, point) {
|
|
let intersect;
|
|
if (material.side === BackSide) {
|
|
intersect = ray.intersectTriangle(pC, pB, pA, true, point);
|
|
} else {
|
|
intersect = ray.intersectTriangle(pA, pB, pC, material.side === FrontSide, point);
|
|
}
|
|
if (intersect === null)
|
|
return null;
|
|
_intersectionPointWorld.copy(point);
|
|
_intersectionPointWorld.applyMatrix4(object.matrixWorld);
|
|
const distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
|
|
if (distance < raycaster.near || distance > raycaster.far)
|
|
return null;
|
|
return {
|
|
distance,
|
|
point: _intersectionPointWorld.clone(),
|
|
object
|
|
};
|
|
}
|
|
function checkGeometryIntersection(object, material, raycaster, ray, uv, uv1, normal, a, b, c) {
|
|
object.getVertexPosition(a, _vA$1);
|
|
object.getVertexPosition(b, _vB$1);
|
|
object.getVertexPosition(c, _vC$1);
|
|
const intersection = checkIntersection$1(object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint);
|
|
if (intersection) {
|
|
const barycoord = new Vector3;
|
|
Triangle.getBarycoord(_intersectionPoint, _vA$1, _vB$1, _vC$1, barycoord);
|
|
if (uv) {
|
|
intersection.uv = Triangle.getInterpolatedAttribute(uv, a, b, c, barycoord, new Vector2);
|
|
}
|
|
if (uv1) {
|
|
intersection.uv1 = Triangle.getInterpolatedAttribute(uv1, a, b, c, barycoord, new Vector2);
|
|
}
|
|
if (normal) {
|
|
intersection.normal = Triangle.getInterpolatedAttribute(normal, a, b, c, barycoord, new Vector3);
|
|
if (intersection.normal.dot(ray.direction) > 0) {
|
|
intersection.normal.multiplyScalar(-1);
|
|
}
|
|
}
|
|
const face = {
|
|
a,
|
|
b,
|
|
c,
|
|
normal: new Vector3,
|
|
materialIndex: 0
|
|
};
|
|
Triangle.getNormal(_vA$1, _vB$1, _vC$1, face.normal);
|
|
intersection.face = face;
|
|
intersection.barycoord = barycoord;
|
|
}
|
|
return intersection;
|
|
}
|
|
function cloneUniforms(src) {
|
|
const dst = {};
|
|
for (const u in src) {
|
|
dst[u] = {};
|
|
for (const p in src[u]) {
|
|
const property = src[u][p];
|
|
if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture || property.isQuaternion)) {
|
|
if (property.isRenderTargetTexture) {
|
|
console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().");
|
|
dst[u][p] = null;
|
|
} else {
|
|
dst[u][p] = property.clone();
|
|
}
|
|
} else if (Array.isArray(property)) {
|
|
dst[u][p] = property.slice();
|
|
} else {
|
|
dst[u][p] = property;
|
|
}
|
|
}
|
|
}
|
|
return dst;
|
|
}
|
|
function mergeUniforms(uniforms) {
|
|
const merged = {};
|
|
for (let u = 0;u < uniforms.length; u++) {
|
|
const tmp = cloneUniforms(uniforms[u]);
|
|
for (const p in tmp) {
|
|
merged[p] = tmp[p];
|
|
}
|
|
}
|
|
return merged;
|
|
}
|
|
function cloneUniformsGroups(src) {
|
|
const dst = [];
|
|
for (let u = 0;u < src.length; u++) {
|
|
dst.push(src[u].clone());
|
|
}
|
|
return dst;
|
|
}
|
|
function getUnlitUniformColorSpace(renderer) {
|
|
const currentRenderTarget = renderer.getRenderTarget();
|
|
if (currentRenderTarget === null) {
|
|
return renderer.outputColorSpace;
|
|
}
|
|
if (currentRenderTarget.isXRRenderTarget === true) {
|
|
return currentRenderTarget.texture.colorSpace;
|
|
}
|
|
return ColorManagement.workingColorSpace;
|
|
}
|
|
|
|
class WebXRController {
|
|
constructor() {
|
|
this._targetRay = null;
|
|
this._grip = null;
|
|
this._hand = null;
|
|
}
|
|
getHandSpace() {
|
|
if (this._hand === null) {
|
|
this._hand = new Group;
|
|
this._hand.matrixAutoUpdate = false;
|
|
this._hand.visible = false;
|
|
this._hand.joints = {};
|
|
this._hand.inputState = { pinching: false };
|
|
}
|
|
return this._hand;
|
|
}
|
|
getTargetRaySpace() {
|
|
if (this._targetRay === null) {
|
|
this._targetRay = new Group;
|
|
this._targetRay.matrixAutoUpdate = false;
|
|
this._targetRay.visible = false;
|
|
this._targetRay.hasLinearVelocity = false;
|
|
this._targetRay.linearVelocity = new Vector3;
|
|
this._targetRay.hasAngularVelocity = false;
|
|
this._targetRay.angularVelocity = new Vector3;
|
|
}
|
|
return this._targetRay;
|
|
}
|
|
getGripSpace() {
|
|
if (this._grip === null) {
|
|
this._grip = new Group;
|
|
this._grip.matrixAutoUpdate = false;
|
|
this._grip.visible = false;
|
|
this._grip.hasLinearVelocity = false;
|
|
this._grip.linearVelocity = new Vector3;
|
|
this._grip.hasAngularVelocity = false;
|
|
this._grip.angularVelocity = new Vector3;
|
|
}
|
|
return this._grip;
|
|
}
|
|
dispatchEvent(event) {
|
|
if (this._targetRay !== null) {
|
|
this._targetRay.dispatchEvent(event);
|
|
}
|
|
if (this._grip !== null) {
|
|
this._grip.dispatchEvent(event);
|
|
}
|
|
if (this._hand !== null) {
|
|
this._hand.dispatchEvent(event);
|
|
}
|
|
return this;
|
|
}
|
|
connect(inputSource) {
|
|
if (inputSource && inputSource.hand) {
|
|
const hand = this._hand;
|
|
if (hand) {
|
|
for (const inputjoint of inputSource.hand.values()) {
|
|
this._getHandJoint(hand, inputjoint);
|
|
}
|
|
}
|
|
}
|
|
this.dispatchEvent({ type: "connected", data: inputSource });
|
|
return this;
|
|
}
|
|
disconnect(inputSource) {
|
|
this.dispatchEvent({ type: "disconnected", data: inputSource });
|
|
if (this._targetRay !== null) {
|
|
this._targetRay.visible = false;
|
|
}
|
|
if (this._grip !== null) {
|
|
this._grip.visible = false;
|
|
}
|
|
if (this._hand !== null) {
|
|
this._hand.visible = false;
|
|
}
|
|
return this;
|
|
}
|
|
update(inputSource, frame, referenceSpace) {
|
|
let inputPose = null;
|
|
let gripPose = null;
|
|
let handPose = null;
|
|
const targetRay = this._targetRay;
|
|
const grip = this._grip;
|
|
const hand = this._hand;
|
|
if (inputSource && frame.session.visibilityState !== "visible-blurred") {
|
|
if (hand && inputSource.hand) {
|
|
handPose = true;
|
|
for (const inputjoint of inputSource.hand.values()) {
|
|
const jointPose = frame.getJointPose(inputjoint, referenceSpace);
|
|
const joint = this._getHandJoint(hand, inputjoint);
|
|
if (jointPose !== null) {
|
|
joint.matrix.fromArray(jointPose.transform.matrix);
|
|
joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
|
|
joint.matrixWorldNeedsUpdate = true;
|
|
joint.jointRadius = jointPose.radius;
|
|
}
|
|
joint.visible = jointPose !== null;
|
|
}
|
|
const indexTip = hand.joints["index-finger-tip"];
|
|
const thumbTip = hand.joints["thumb-tip"];
|
|
const distance = indexTip.position.distanceTo(thumbTip.position);
|
|
const distanceToPinch = 0.02;
|
|
const threshold = 0.005;
|
|
if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
|
|
hand.inputState.pinching = false;
|
|
this.dispatchEvent({
|
|
type: "pinchend",
|
|
handedness: inputSource.handedness,
|
|
target: this
|
|
});
|
|
} else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
|
|
hand.inputState.pinching = true;
|
|
this.dispatchEvent({
|
|
type: "pinchstart",
|
|
handedness: inputSource.handedness,
|
|
target: this
|
|
});
|
|
}
|
|
} else {
|
|
if (grip !== null && inputSource.gripSpace) {
|
|
gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
|
|
if (gripPose !== null) {
|
|
grip.matrix.fromArray(gripPose.transform.matrix);
|
|
grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
|
|
grip.matrixWorldNeedsUpdate = true;
|
|
if (gripPose.linearVelocity) {
|
|
grip.hasLinearVelocity = true;
|
|
grip.linearVelocity.copy(gripPose.linearVelocity);
|
|
} else {
|
|
grip.hasLinearVelocity = false;
|
|
}
|
|
if (gripPose.angularVelocity) {
|
|
grip.hasAngularVelocity = true;
|
|
grip.angularVelocity.copy(gripPose.angularVelocity);
|
|
} else {
|
|
grip.hasAngularVelocity = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (targetRay !== null) {
|
|
inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
|
|
if (inputPose === null && gripPose !== null) {
|
|
inputPose = gripPose;
|
|
}
|
|
if (inputPose !== null) {
|
|
targetRay.matrix.fromArray(inputPose.transform.matrix);
|
|
targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
|
|
targetRay.matrixWorldNeedsUpdate = true;
|
|
if (inputPose.linearVelocity) {
|
|
targetRay.hasLinearVelocity = true;
|
|
targetRay.linearVelocity.copy(inputPose.linearVelocity);
|
|
} else {
|
|
targetRay.hasLinearVelocity = false;
|
|
}
|
|
if (inputPose.angularVelocity) {
|
|
targetRay.hasAngularVelocity = true;
|
|
targetRay.angularVelocity.copy(inputPose.angularVelocity);
|
|
} else {
|
|
targetRay.hasAngularVelocity = false;
|
|
}
|
|
this.dispatchEvent(_moveEvent);
|
|
}
|
|
}
|
|
}
|
|
if (targetRay !== null) {
|
|
targetRay.visible = inputPose !== null;
|
|
}
|
|
if (grip !== null) {
|
|
grip.visible = gripPose !== null;
|
|
}
|
|
if (hand !== null) {
|
|
hand.visible = handPose !== null;
|
|
}
|
|
return this;
|
|
}
|
|
_getHandJoint(hand, inputjoint) {
|
|
if (hand.joints[inputjoint.jointName] === undefined) {
|
|
const joint = new Group;
|
|
joint.matrixAutoUpdate = false;
|
|
joint.visible = false;
|
|
hand.joints[inputjoint.jointName] = joint;
|
|
hand.add(joint);
|
|
}
|
|
return hand.joints[inputjoint.jointName];
|
|
}
|
|
}
|
|
|
|
class FogExp2 {
|
|
constructor(color, density = 0.00025) {
|
|
this.isFogExp2 = true;
|
|
this.name = "";
|
|
this.color = new Color(color);
|
|
this.density = density;
|
|
}
|
|
clone() {
|
|
return new FogExp2(this.color, this.density);
|
|
}
|
|
toJSON() {
|
|
return {
|
|
type: "FogExp2",
|
|
name: this.name,
|
|
color: this.color.getHex(),
|
|
density: this.density
|
|
};
|
|
}
|
|
}
|
|
|
|
class Fog {
|
|
constructor(color, near = 1, far = 1000) {
|
|
this.isFog = true;
|
|
this.name = "";
|
|
this.color = new Color(color);
|
|
this.near = near;
|
|
this.far = far;
|
|
}
|
|
clone() {
|
|
return new Fog(this.color, this.near, this.far);
|
|
}
|
|
toJSON() {
|
|
return {
|
|
type: "Fog",
|
|
name: this.name,
|
|
color: this.color.getHex(),
|
|
near: this.near,
|
|
far: this.far
|
|
};
|
|
}
|
|
}
|
|
|
|
class InterleavedBuffer {
|
|
constructor(array, stride) {
|
|
this.isInterleavedBuffer = true;
|
|
this.array = array;
|
|
this.stride = stride;
|
|
this.count = array !== undefined ? array.length / stride : 0;
|
|
this.usage = StaticDrawUsage;
|
|
this.updateRanges = [];
|
|
this.version = 0;
|
|
this.uuid = generateUUID();
|
|
}
|
|
onUploadCallback() {}
|
|
set needsUpdate(value) {
|
|
if (value === true)
|
|
this.version++;
|
|
}
|
|
setUsage(value) {
|
|
this.usage = value;
|
|
return this;
|
|
}
|
|
addUpdateRange(start, count) {
|
|
this.updateRanges.push({ start, count });
|
|
}
|
|
clearUpdateRanges() {
|
|
this.updateRanges.length = 0;
|
|
}
|
|
copy(source) {
|
|
this.array = new source.array.constructor(source.array);
|
|
this.count = source.count;
|
|
this.stride = source.stride;
|
|
this.usage = source.usage;
|
|
return this;
|
|
}
|
|
copyAt(index1, attribute, index2) {
|
|
index1 *= this.stride;
|
|
index2 *= attribute.stride;
|
|
for (let i = 0, l = this.stride;i < l; i++) {
|
|
this.array[index1 + i] = attribute.array[index2 + i];
|
|
}
|
|
return this;
|
|
}
|
|
set(value, offset = 0) {
|
|
this.array.set(value, offset);
|
|
return this;
|
|
}
|
|
clone(data) {
|
|
if (data.arrayBuffers === undefined) {
|
|
data.arrayBuffers = {};
|
|
}
|
|
if (this.array.buffer._uuid === undefined) {
|
|
this.array.buffer._uuid = generateUUID();
|
|
}
|
|
if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
|
|
data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
|
|
}
|
|
const array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
|
|
const ib = new this.constructor(array, this.stride);
|
|
ib.setUsage(this.usage);
|
|
return ib;
|
|
}
|
|
onUpload(callback) {
|
|
this.onUploadCallback = callback;
|
|
return this;
|
|
}
|
|
toJSON(data) {
|
|
if (data.arrayBuffers === undefined) {
|
|
data.arrayBuffers = {};
|
|
}
|
|
if (this.array.buffer._uuid === undefined) {
|
|
this.array.buffer._uuid = generateUUID();
|
|
}
|
|
if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
|
|
data.arrayBuffers[this.array.buffer._uuid] = Array.from(new Uint32Array(this.array.buffer));
|
|
}
|
|
return {
|
|
uuid: this.uuid,
|
|
buffer: this.array.buffer._uuid,
|
|
type: this.array.constructor.name,
|
|
stride: this.stride
|
|
};
|
|
}
|
|
}
|
|
|
|
class InterleavedBufferAttribute {
|
|
constructor(interleavedBuffer, itemSize, offset, normalized = false) {
|
|
this.isInterleavedBufferAttribute = true;
|
|
this.name = "";
|
|
this.data = interleavedBuffer;
|
|
this.itemSize = itemSize;
|
|
this.offset = offset;
|
|
this.normalized = normalized;
|
|
}
|
|
get count() {
|
|
return this.data.count;
|
|
}
|
|
get array() {
|
|
return this.data.array;
|
|
}
|
|
set needsUpdate(value) {
|
|
this.data.needsUpdate = value;
|
|
}
|
|
applyMatrix4(m) {
|
|
for (let i = 0, l = this.data.count;i < l; i++) {
|
|
_vector$7.fromBufferAttribute(this, i);
|
|
_vector$7.applyMatrix4(m);
|
|
this.setXYZ(i, _vector$7.x, _vector$7.y, _vector$7.z);
|
|
}
|
|
return this;
|
|
}
|
|
applyNormalMatrix(m) {
|
|
for (let i = 0, l = this.count;i < l; i++) {
|
|
_vector$7.fromBufferAttribute(this, i);
|
|
_vector$7.applyNormalMatrix(m);
|
|
this.setXYZ(i, _vector$7.x, _vector$7.y, _vector$7.z);
|
|
}
|
|
return this;
|
|
}
|
|
transformDirection(m) {
|
|
for (let i = 0, l = this.count;i < l; i++) {
|
|
_vector$7.fromBufferAttribute(this, i);
|
|
_vector$7.transformDirection(m);
|
|
this.setXYZ(i, _vector$7.x, _vector$7.y, _vector$7.z);
|
|
}
|
|
return this;
|
|
}
|
|
getComponent(index, component) {
|
|
let value = this.array[index * this.data.stride + this.offset + component];
|
|
if (this.normalized)
|
|
value = denormalize(value, this.array);
|
|
return value;
|
|
}
|
|
setComponent(index, component, value) {
|
|
if (this.normalized)
|
|
value = normalize(value, this.array);
|
|
this.data.array[index * this.data.stride + this.offset + component] = value;
|
|
return this;
|
|
}
|
|
setX(index, x) {
|
|
if (this.normalized)
|
|
x = normalize(x, this.array);
|
|
this.data.array[index * this.data.stride + this.offset] = x;
|
|
return this;
|
|
}
|
|
setY(index, y) {
|
|
if (this.normalized)
|
|
y = normalize(y, this.array);
|
|
this.data.array[index * this.data.stride + this.offset + 1] = y;
|
|
return this;
|
|
}
|
|
setZ(index, z) {
|
|
if (this.normalized)
|
|
z = normalize(z, this.array);
|
|
this.data.array[index * this.data.stride + this.offset + 2] = z;
|
|
return this;
|
|
}
|
|
setW(index, w) {
|
|
if (this.normalized)
|
|
w = normalize(w, this.array);
|
|
this.data.array[index * this.data.stride + this.offset + 3] = w;
|
|
return this;
|
|
}
|
|
getX(index) {
|
|
let x = this.data.array[index * this.data.stride + this.offset];
|
|
if (this.normalized)
|
|
x = denormalize(x, this.array);
|
|
return x;
|
|
}
|
|
getY(index) {
|
|
let y = this.data.array[index * this.data.stride + this.offset + 1];
|
|
if (this.normalized)
|
|
y = denormalize(y, this.array);
|
|
return y;
|
|
}
|
|
getZ(index) {
|
|
let z = this.data.array[index * this.data.stride + this.offset + 2];
|
|
if (this.normalized)
|
|
z = denormalize(z, this.array);
|
|
return z;
|
|
}
|
|
getW(index) {
|
|
let w = this.data.array[index * this.data.stride + this.offset + 3];
|
|
if (this.normalized)
|
|
w = denormalize(w, this.array);
|
|
return w;
|
|
}
|
|
setXY(index, x, y) {
|
|
index = index * this.data.stride + this.offset;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
}
|
|
this.data.array[index + 0] = x;
|
|
this.data.array[index + 1] = y;
|
|
return this;
|
|
}
|
|
setXYZ(index, x, y, z) {
|
|
index = index * this.data.stride + this.offset;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
z = normalize(z, this.array);
|
|
}
|
|
this.data.array[index + 0] = x;
|
|
this.data.array[index + 1] = y;
|
|
this.data.array[index + 2] = z;
|
|
return this;
|
|
}
|
|
setXYZW(index, x, y, z, w) {
|
|
index = index * this.data.stride + this.offset;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
z = normalize(z, this.array);
|
|
w = normalize(w, this.array);
|
|
}
|
|
this.data.array[index + 0] = x;
|
|
this.data.array[index + 1] = y;
|
|
this.data.array[index + 2] = z;
|
|
this.data.array[index + 3] = w;
|
|
return this;
|
|
}
|
|
clone(data) {
|
|
if (data === undefined) {
|
|
console.log("THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");
|
|
const array = [];
|
|
for (let i = 0;i < this.count; i++) {
|
|
const index = i * this.data.stride + this.offset;
|
|
for (let j = 0;j < this.itemSize; j++) {
|
|
array.push(this.data.array[index + j]);
|
|
}
|
|
}
|
|
return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
|
|
} else {
|
|
if (data.interleavedBuffers === undefined) {
|
|
data.interleavedBuffers = {};
|
|
}
|
|
if (data.interleavedBuffers[this.data.uuid] === undefined) {
|
|
data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
|
|
}
|
|
return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
|
|
}
|
|
}
|
|
toJSON(data) {
|
|
if (data === undefined) {
|
|
console.log("THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");
|
|
const array = [];
|
|
for (let i = 0;i < this.count; i++) {
|
|
const index = i * this.data.stride + this.offset;
|
|
for (let j = 0;j < this.itemSize; j++) {
|
|
array.push(this.data.array[index + j]);
|
|
}
|
|
}
|
|
return {
|
|
itemSize: this.itemSize,
|
|
type: this.array.constructor.name,
|
|
array,
|
|
normalized: this.normalized
|
|
};
|
|
} else {
|
|
if (data.interleavedBuffers === undefined) {
|
|
data.interleavedBuffers = {};
|
|
}
|
|
if (data.interleavedBuffers[this.data.uuid] === undefined) {
|
|
data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
|
|
}
|
|
return {
|
|
isInterleavedBufferAttribute: true,
|
|
itemSize: this.itemSize,
|
|
data: this.data.uuid,
|
|
offset: this.offset,
|
|
normalized: this.normalized
|
|
};
|
|
}
|
|
}
|
|
}
|
|
function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
|
|
_alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale);
|
|
if (sin !== undefined) {
|
|
_rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
|
|
_rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
|
|
} else {
|
|
_rotatedPosition.copy(_alignedPosition);
|
|
}
|
|
vertexPosition.copy(mvPosition);
|
|
vertexPosition.x += _rotatedPosition.x;
|
|
vertexPosition.y += _rotatedPosition.y;
|
|
vertexPosition.applyMatrix4(_viewWorldMatrix);
|
|
}
|
|
|
|
class Skeleton {
|
|
constructor(bones = [], boneInverses = []) {
|
|
this.uuid = generateUUID();
|
|
this.bones = bones.slice(0);
|
|
this.boneInverses = boneInverses;
|
|
this.boneMatrices = null;
|
|
this.boneTexture = null;
|
|
this.init();
|
|
}
|
|
init() {
|
|
const bones = this.bones;
|
|
const boneInverses = this.boneInverses;
|
|
this.boneMatrices = new Float32Array(bones.length * 16);
|
|
if (boneInverses.length === 0) {
|
|
this.calculateInverses();
|
|
} else {
|
|
if (bones.length !== boneInverses.length) {
|
|
console.warn("THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.");
|
|
this.boneInverses = [];
|
|
for (let i = 0, il = this.bones.length;i < il; i++) {
|
|
this.boneInverses.push(new Matrix4);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
calculateInverses() {
|
|
this.boneInverses.length = 0;
|
|
for (let i = 0, il = this.bones.length;i < il; i++) {
|
|
const inverse = new Matrix4;
|
|
if (this.bones[i]) {
|
|
inverse.copy(this.bones[i].matrixWorld).invert();
|
|
}
|
|
this.boneInverses.push(inverse);
|
|
}
|
|
}
|
|
pose() {
|
|
for (let i = 0, il = this.bones.length;i < il; i++) {
|
|
const bone = this.bones[i];
|
|
if (bone) {
|
|
bone.matrixWorld.copy(this.boneInverses[i]).invert();
|
|
}
|
|
}
|
|
for (let i = 0, il = this.bones.length;i < il; i++) {
|
|
const bone = this.bones[i];
|
|
if (bone) {
|
|
if (bone.parent && bone.parent.isBone) {
|
|
bone.matrix.copy(bone.parent.matrixWorld).invert();
|
|
bone.matrix.multiply(bone.matrixWorld);
|
|
} else {
|
|
bone.matrix.copy(bone.matrixWorld);
|
|
}
|
|
bone.matrix.decompose(bone.position, bone.quaternion, bone.scale);
|
|
}
|
|
}
|
|
}
|
|
update() {
|
|
const bones = this.bones;
|
|
const boneInverses = this.boneInverses;
|
|
const boneMatrices = this.boneMatrices;
|
|
const boneTexture = this.boneTexture;
|
|
for (let i = 0, il = bones.length;i < il; i++) {
|
|
const matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
|
|
_offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
|
|
_offsetMatrix.toArray(boneMatrices, i * 16);
|
|
}
|
|
if (boneTexture !== null) {
|
|
boneTexture.needsUpdate = true;
|
|
}
|
|
}
|
|
clone() {
|
|
return new Skeleton(this.bones, this.boneInverses);
|
|
}
|
|
computeBoneTexture() {
|
|
let size = Math.sqrt(this.bones.length * 4);
|
|
size = Math.ceil(size / 4) * 4;
|
|
size = Math.max(size, 4);
|
|
const boneMatrices = new Float32Array(size * size * 4);
|
|
boneMatrices.set(this.boneMatrices);
|
|
const boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
|
|
boneTexture.needsUpdate = true;
|
|
this.boneMatrices = boneMatrices;
|
|
this.boneTexture = boneTexture;
|
|
return this;
|
|
}
|
|
getBoneByName(name) {
|
|
for (let i = 0, il = this.bones.length;i < il; i++) {
|
|
const bone = this.bones[i];
|
|
if (bone.name === name) {
|
|
return bone;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
dispose() {
|
|
if (this.boneTexture !== null) {
|
|
this.boneTexture.dispose();
|
|
this.boneTexture = null;
|
|
}
|
|
}
|
|
fromJSON(json, bones) {
|
|
this.uuid = json.uuid;
|
|
for (let i = 0, l = json.bones.length;i < l; i++) {
|
|
const uuid = json.bones[i];
|
|
let bone = bones[uuid];
|
|
if (bone === undefined) {
|
|
console.warn("THREE.Skeleton: No bone found with UUID:", uuid);
|
|
bone = new Bone;
|
|
}
|
|
this.bones.push(bone);
|
|
this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
|
|
}
|
|
this.init();
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = {
|
|
metadata: {
|
|
version: 4.6,
|
|
type: "Skeleton",
|
|
generator: "Skeleton.toJSON"
|
|
},
|
|
bones: [],
|
|
boneInverses: []
|
|
};
|
|
data.uuid = this.uuid;
|
|
const bones = this.bones;
|
|
const boneInverses = this.boneInverses;
|
|
for (let i = 0, l = bones.length;i < l; i++) {
|
|
const bone = bones[i];
|
|
data.bones.push(bone.uuid);
|
|
const boneInverse = boneInverses[i];
|
|
data.boneInverses.push(boneInverse.toArray());
|
|
}
|
|
return data;
|
|
}
|
|
}
|
|
|
|
class Plane {
|
|
constructor(normal = new Vector3(1, 0, 0), constant = 0) {
|
|
this.isPlane = true;
|
|
this.normal = normal;
|
|
this.constant = constant;
|
|
}
|
|
set(normal, constant) {
|
|
this.normal.copy(normal);
|
|
this.constant = constant;
|
|
return this;
|
|
}
|
|
setComponents(x, y, z, w) {
|
|
this.normal.set(x, y, z);
|
|
this.constant = w;
|
|
return this;
|
|
}
|
|
setFromNormalAndCoplanarPoint(normal, point) {
|
|
this.normal.copy(normal);
|
|
this.constant = -point.dot(this.normal);
|
|
return this;
|
|
}
|
|
setFromCoplanarPoints(a, b, c) {
|
|
const normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize();
|
|
this.setFromNormalAndCoplanarPoint(normal, a);
|
|
return this;
|
|
}
|
|
copy(plane) {
|
|
this.normal.copy(plane.normal);
|
|
this.constant = plane.constant;
|
|
return this;
|
|
}
|
|
normalize() {
|
|
const inverseNormalLength = 1 / this.normal.length();
|
|
this.normal.multiplyScalar(inverseNormalLength);
|
|
this.constant *= inverseNormalLength;
|
|
return this;
|
|
}
|
|
negate() {
|
|
this.constant *= -1;
|
|
this.normal.negate();
|
|
return this;
|
|
}
|
|
distanceToPoint(point) {
|
|
return this.normal.dot(point) + this.constant;
|
|
}
|
|
distanceToSphere(sphere) {
|
|
return this.distanceToPoint(sphere.center) - sphere.radius;
|
|
}
|
|
projectPoint(point, target) {
|
|
return target.copy(point).addScaledVector(this.normal, -this.distanceToPoint(point));
|
|
}
|
|
intersectLine(line, target) {
|
|
const direction = line.delta(_vector1);
|
|
const denominator = this.normal.dot(direction);
|
|
if (denominator === 0) {
|
|
if (this.distanceToPoint(line.start) === 0) {
|
|
return target.copy(line.start);
|
|
}
|
|
return null;
|
|
}
|
|
const t = -(line.start.dot(this.normal) + this.constant) / denominator;
|
|
if (t < 0 || t > 1) {
|
|
return null;
|
|
}
|
|
return target.copy(line.start).addScaledVector(direction, t);
|
|
}
|
|
intersectsLine(line) {
|
|
const startSign = this.distanceToPoint(line.start);
|
|
const endSign = this.distanceToPoint(line.end);
|
|
return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
|
|
}
|
|
intersectsBox(box) {
|
|
return box.intersectsPlane(this);
|
|
}
|
|
intersectsSphere(sphere) {
|
|
return sphere.intersectsPlane(this);
|
|
}
|
|
coplanarPoint(target) {
|
|
return target.copy(this.normal).multiplyScalar(-this.constant);
|
|
}
|
|
applyMatrix4(matrix, optionalNormalMatrix) {
|
|
const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
|
|
const referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
|
|
const normal = this.normal.applyMatrix3(normalMatrix).normalize();
|
|
this.constant = -referencePoint.dot(normal);
|
|
return this;
|
|
}
|
|
translate(offset) {
|
|
this.constant -= offset.dot(this.normal);
|
|
return this;
|
|
}
|
|
equals(plane) {
|
|
return plane.normal.equals(this.normal) && plane.constant === this.constant;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
}
|
|
|
|
class Frustum {
|
|
constructor(p0 = new Plane, p1 = new Plane, p2 = new Plane, p3 = new Plane, p4 = new Plane, p5 = new Plane) {
|
|
this.planes = [p0, p1, p2, p3, p4, p5];
|
|
}
|
|
set(p0, p1, p2, p3, p4, p5) {
|
|
const planes = this.planes;
|
|
planes[0].copy(p0);
|
|
planes[1].copy(p1);
|
|
planes[2].copy(p2);
|
|
planes[3].copy(p3);
|
|
planes[4].copy(p4);
|
|
planes[5].copy(p5);
|
|
return this;
|
|
}
|
|
copy(frustum) {
|
|
const planes = this.planes;
|
|
for (let i = 0;i < 6; i++) {
|
|
planes[i].copy(frustum.planes[i]);
|
|
}
|
|
return this;
|
|
}
|
|
setFromProjectionMatrix(m, coordinateSystem = WebGLCoordinateSystem) {
|
|
const planes = this.planes;
|
|
const me = m.elements;
|
|
const me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
|
|
const me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
|
|
const me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
|
|
const me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
|
|
planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
|
|
planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
|
|
planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
|
|
planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
|
|
planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
|
|
if (coordinateSystem === WebGLCoordinateSystem) {
|
|
planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
|
|
} else if (coordinateSystem === WebGPUCoordinateSystem) {
|
|
planes[5].setComponents(me2, me6, me10, me14).normalize();
|
|
} else {
|
|
throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: " + coordinateSystem);
|
|
}
|
|
return this;
|
|
}
|
|
intersectsObject(object) {
|
|
if (object.boundingSphere !== undefined) {
|
|
if (object.boundingSphere === null)
|
|
object.computeBoundingSphere();
|
|
_sphere$3.copy(object.boundingSphere).applyMatrix4(object.matrixWorld);
|
|
} else {
|
|
const geometry = object.geometry;
|
|
if (geometry.boundingSphere === null)
|
|
geometry.computeBoundingSphere();
|
|
_sphere$3.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
|
|
}
|
|
return this.intersectsSphere(_sphere$3);
|
|
}
|
|
intersectsSprite(sprite) {
|
|
_sphere$3.center.set(0, 0, 0);
|
|
_sphere$3.radius = 0.7071067811865476;
|
|
_sphere$3.applyMatrix4(sprite.matrixWorld);
|
|
return this.intersectsSphere(_sphere$3);
|
|
}
|
|
intersectsSphere(sphere) {
|
|
const planes = this.planes;
|
|
const center = sphere.center;
|
|
const negRadius = -sphere.radius;
|
|
for (let i = 0;i < 6; i++) {
|
|
const distance = planes[i].distanceToPoint(center);
|
|
if (distance < negRadius) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
intersectsBox(box) {
|
|
const planes = this.planes;
|
|
for (let i = 0;i < 6; i++) {
|
|
const plane = planes[i];
|
|
_vector$6.x = plane.normal.x > 0 ? box.max.x : box.min.x;
|
|
_vector$6.y = plane.normal.y > 0 ? box.max.y : box.min.y;
|
|
_vector$6.z = plane.normal.z > 0 ? box.max.z : box.min.z;
|
|
if (plane.distanceToPoint(_vector$6) < 0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
containsPoint(point) {
|
|
const planes = this.planes;
|
|
for (let i = 0;i < 6; i++) {
|
|
if (planes[i].distanceToPoint(point) < 0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
}
|
|
function ascIdSort(a, b) {
|
|
return a - b;
|
|
}
|
|
function sortOpaque(a, b) {
|
|
return a.z - b.z;
|
|
}
|
|
function sortTransparent(a, b) {
|
|
return b.z - a.z;
|
|
}
|
|
|
|
class MultiDrawRenderList {
|
|
constructor() {
|
|
this.index = 0;
|
|
this.pool = [];
|
|
this.list = [];
|
|
}
|
|
push(start, count, z, index) {
|
|
const pool = this.pool;
|
|
const list = this.list;
|
|
if (this.index >= pool.length) {
|
|
pool.push({
|
|
start: -1,
|
|
count: -1,
|
|
z: -1,
|
|
index: -1
|
|
});
|
|
}
|
|
const item = pool[this.index];
|
|
list.push(item);
|
|
this.index++;
|
|
item.start = start;
|
|
item.count = count;
|
|
item.z = z;
|
|
item.index = index;
|
|
}
|
|
reset() {
|
|
this.list.length = 0;
|
|
this.index = 0;
|
|
}
|
|
}
|
|
function copyAttributeData(src, target, targetOffset = 0) {
|
|
const itemSize = target.itemSize;
|
|
if (src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor) {
|
|
const vertexCount = src.count;
|
|
for (let i = 0;i < vertexCount; i++) {
|
|
for (let c = 0;c < itemSize; c++) {
|
|
target.setComponent(i + targetOffset, c, src.getComponent(i, c));
|
|
}
|
|
}
|
|
} else {
|
|
target.array.set(src.array, targetOffset * itemSize);
|
|
}
|
|
target.needsUpdate = true;
|
|
}
|
|
function copyArrayContents(src, target) {
|
|
if (src.constructor !== target.constructor) {
|
|
const len = Math.min(src.length, target.length);
|
|
for (let i = 0;i < len; i++) {
|
|
target[i] = src[i];
|
|
}
|
|
} else {
|
|
const len = Math.min(src.length, target.length);
|
|
target.set(new src.constructor(src.buffer, 0, len));
|
|
}
|
|
}
|
|
function checkIntersection(object, raycaster, ray, thresholdSq, a, b, i) {
|
|
const positionAttribute = object.geometry.attributes.position;
|
|
_vStart.fromBufferAttribute(positionAttribute, a);
|
|
_vEnd.fromBufferAttribute(positionAttribute, b);
|
|
const distSq = ray.distanceSqToSegment(_vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment);
|
|
if (distSq > thresholdSq)
|
|
return;
|
|
_intersectPointOnRay.applyMatrix4(object.matrixWorld);
|
|
const distance = raycaster.ray.origin.distanceTo(_intersectPointOnRay);
|
|
if (distance < raycaster.near || distance > raycaster.far)
|
|
return;
|
|
return {
|
|
distance,
|
|
point: _intersectPointOnSegment.clone().applyMatrix4(object.matrixWorld),
|
|
index: i,
|
|
face: null,
|
|
faceIndex: null,
|
|
barycoord: null,
|
|
object
|
|
};
|
|
}
|
|
function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
|
|
const rayPointDistanceSq = _ray.distanceSqToPoint(point);
|
|
if (rayPointDistanceSq < localThresholdSq) {
|
|
const intersectPoint = new Vector3;
|
|
_ray.closestPointToPoint(point, intersectPoint);
|
|
intersectPoint.applyMatrix4(matrixWorld);
|
|
const distance = raycaster.ray.origin.distanceTo(intersectPoint);
|
|
if (distance < raycaster.near || distance > raycaster.far)
|
|
return;
|
|
intersects.push({
|
|
distance,
|
|
distanceToRay: Math.sqrt(rayPointDistanceSq),
|
|
point: intersectPoint,
|
|
index,
|
|
face: null,
|
|
faceIndex: null,
|
|
barycoord: null,
|
|
object
|
|
});
|
|
}
|
|
}
|
|
|
|
class Curve {
|
|
constructor() {
|
|
this.type = "Curve";
|
|
this.arcLengthDivisions = 200;
|
|
}
|
|
getPoint() {
|
|
console.warn("THREE.Curve: .getPoint() not implemented.");
|
|
return null;
|
|
}
|
|
getPointAt(u, optionalTarget) {
|
|
const t = this.getUtoTmapping(u);
|
|
return this.getPoint(t, optionalTarget);
|
|
}
|
|
getPoints(divisions = 5) {
|
|
const points = [];
|
|
for (let d = 0;d <= divisions; d++) {
|
|
points.push(this.getPoint(d / divisions));
|
|
}
|
|
return points;
|
|
}
|
|
getSpacedPoints(divisions = 5) {
|
|
const points = [];
|
|
for (let d = 0;d <= divisions; d++) {
|
|
points.push(this.getPointAt(d / divisions));
|
|
}
|
|
return points;
|
|
}
|
|
getLength() {
|
|
const lengths = this.getLengths();
|
|
return lengths[lengths.length - 1];
|
|
}
|
|
getLengths(divisions = this.arcLengthDivisions) {
|
|
if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
|
|
return this.cacheArcLengths;
|
|
}
|
|
this.needsUpdate = false;
|
|
const cache = [];
|
|
let current, last = this.getPoint(0);
|
|
let sum = 0;
|
|
cache.push(0);
|
|
for (let p = 1;p <= divisions; p++) {
|
|
current = this.getPoint(p / divisions);
|
|
sum += current.distanceTo(last);
|
|
cache.push(sum);
|
|
last = current;
|
|
}
|
|
this.cacheArcLengths = cache;
|
|
return cache;
|
|
}
|
|
updateArcLengths() {
|
|
this.needsUpdate = true;
|
|
this.getLengths();
|
|
}
|
|
getUtoTmapping(u, distance) {
|
|
const arcLengths = this.getLengths();
|
|
let i = 0;
|
|
const il = arcLengths.length;
|
|
let targetArcLength;
|
|
if (distance) {
|
|
targetArcLength = distance;
|
|
} else {
|
|
targetArcLength = u * arcLengths[il - 1];
|
|
}
|
|
let low = 0, high = il - 1, comparison;
|
|
while (low <= high) {
|
|
i = Math.floor(low + (high - low) / 2);
|
|
comparison = arcLengths[i] - targetArcLength;
|
|
if (comparison < 0) {
|
|
low = i + 1;
|
|
} else if (comparison > 0) {
|
|
high = i - 1;
|
|
} else {
|
|
high = i;
|
|
break;
|
|
}
|
|
}
|
|
i = high;
|
|
if (arcLengths[i] === targetArcLength) {
|
|
return i / (il - 1);
|
|
}
|
|
const lengthBefore = arcLengths[i];
|
|
const lengthAfter = arcLengths[i + 1];
|
|
const segmentLength = lengthAfter - lengthBefore;
|
|
const segmentFraction = (targetArcLength - lengthBefore) / segmentLength;
|
|
const t = (i + segmentFraction) / (il - 1);
|
|
return t;
|
|
}
|
|
getTangent(t, optionalTarget) {
|
|
const delta = 0.0001;
|
|
let t1 = t - delta;
|
|
let t2 = t + delta;
|
|
if (t1 < 0)
|
|
t1 = 0;
|
|
if (t2 > 1)
|
|
t2 = 1;
|
|
const pt1 = this.getPoint(t1);
|
|
const pt2 = this.getPoint(t2);
|
|
const tangent = optionalTarget || (pt1.isVector2 ? new Vector2 : new Vector3);
|
|
tangent.copy(pt2).sub(pt1).normalize();
|
|
return tangent;
|
|
}
|
|
getTangentAt(u, optionalTarget) {
|
|
const t = this.getUtoTmapping(u);
|
|
return this.getTangent(t, optionalTarget);
|
|
}
|
|
computeFrenetFrames(segments, closed) {
|
|
const normal = new Vector3;
|
|
const tangents = [];
|
|
const normals = [];
|
|
const binormals = [];
|
|
const vec = new Vector3;
|
|
const mat = new Matrix4;
|
|
for (let i = 0;i <= segments; i++) {
|
|
const u = i / segments;
|
|
tangents[i] = this.getTangentAt(u, new Vector3);
|
|
}
|
|
normals[0] = new Vector3;
|
|
binormals[0] = new Vector3;
|
|
let min = Number.MAX_VALUE;
|
|
const tx = Math.abs(tangents[0].x);
|
|
const ty = Math.abs(tangents[0].y);
|
|
const tz = Math.abs(tangents[0].z);
|
|
if (tx <= min) {
|
|
min = tx;
|
|
normal.set(1, 0, 0);
|
|
}
|
|
if (ty <= min) {
|
|
min = ty;
|
|
normal.set(0, 1, 0);
|
|
}
|
|
if (tz <= min) {
|
|
normal.set(0, 0, 1);
|
|
}
|
|
vec.crossVectors(tangents[0], normal).normalize();
|
|
normals[0].crossVectors(tangents[0], vec);
|
|
binormals[0].crossVectors(tangents[0], normals[0]);
|
|
for (let i = 1;i <= segments; i++) {
|
|
normals[i] = normals[i - 1].clone();
|
|
binormals[i] = binormals[i - 1].clone();
|
|
vec.crossVectors(tangents[i - 1], tangents[i]);
|
|
if (vec.length() > Number.EPSILON) {
|
|
vec.normalize();
|
|
const theta = Math.acos(clamp(tangents[i - 1].dot(tangents[i]), -1, 1));
|
|
normals[i].applyMatrix4(mat.makeRotationAxis(vec, theta));
|
|
}
|
|
binormals[i].crossVectors(tangents[i], normals[i]);
|
|
}
|
|
if (closed === true) {
|
|
let theta = Math.acos(clamp(normals[0].dot(normals[segments]), -1, 1));
|
|
theta /= segments;
|
|
if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
|
|
theta = -theta;
|
|
}
|
|
for (let i = 1;i <= segments; i++) {
|
|
normals[i].applyMatrix4(mat.makeRotationAxis(tangents[i], theta * i));
|
|
binormals[i].crossVectors(tangents[i], normals[i]);
|
|
}
|
|
}
|
|
return {
|
|
tangents,
|
|
normals,
|
|
binormals
|
|
};
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
copy(source) {
|
|
this.arcLengthDivisions = source.arcLengthDivisions;
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = {
|
|
metadata: {
|
|
version: 4.6,
|
|
type: "Curve",
|
|
generator: "Curve.toJSON"
|
|
}
|
|
};
|
|
data.arcLengthDivisions = this.arcLengthDivisions;
|
|
data.type = this.type;
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
this.arcLengthDivisions = json.arcLengthDivisions;
|
|
return this;
|
|
}
|
|
}
|
|
function CubicPoly() {
|
|
let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
|
|
function init(x0, x1, t0, t1) {
|
|
c0 = x0;
|
|
c1 = t0;
|
|
c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
|
|
c3 = 2 * x0 - 2 * x1 + t0 + t1;
|
|
}
|
|
return {
|
|
initCatmullRom: function(x0, x1, x2, x3, tension) {
|
|
init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
|
|
},
|
|
initNonuniformCatmullRom: function(x0, x1, x2, x3, dt0, dt1, dt2) {
|
|
let t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
|
|
let t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2;
|
|
t1 *= dt1;
|
|
t2 *= dt1;
|
|
init(x1, x2, t1, t2);
|
|
},
|
|
calc: function(t) {
|
|
const t2 = t * t;
|
|
const t3 = t2 * t;
|
|
return c0 + c1 * t + c2 * t2 + c3 * t3;
|
|
}
|
|
};
|
|
}
|
|
function CatmullRom(t, p0, p1, p2, p3) {
|
|
const v0 = (p2 - p0) * 0.5;
|
|
const v1 = (p3 - p1) * 0.5;
|
|
const t2 = t * t;
|
|
const t3 = t * t2;
|
|
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
|
|
}
|
|
function QuadraticBezierP0(t, p) {
|
|
const k = 1 - t;
|
|
return k * k * p;
|
|
}
|
|
function QuadraticBezierP1(t, p) {
|
|
return 2 * (1 - t) * t * p;
|
|
}
|
|
function QuadraticBezierP2(t, p) {
|
|
return t * t * p;
|
|
}
|
|
function QuadraticBezier(t, p0, p1, p2) {
|
|
return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
|
|
}
|
|
function CubicBezierP0(t, p) {
|
|
const k = 1 - t;
|
|
return k * k * k * p;
|
|
}
|
|
function CubicBezierP1(t, p) {
|
|
const k = 1 - t;
|
|
return 3 * k * k * t * p;
|
|
}
|
|
function CubicBezierP2(t, p) {
|
|
return 3 * (1 - t) * t * t * p;
|
|
}
|
|
function CubicBezierP3(t, p) {
|
|
return t * t * t * p;
|
|
}
|
|
function CubicBezier(t, p0, p1, p2, p3) {
|
|
return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
|
|
}
|
|
function linkedList(data, start, end, dim, clockwise) {
|
|
let i, last;
|
|
if (clockwise === signedArea(data, start, end, dim) > 0) {
|
|
for (i = start;i < end; i += dim)
|
|
last = insertNode(i, data[i], data[i + 1], last);
|
|
} else {
|
|
for (i = end - dim;i >= start; i -= dim)
|
|
last = insertNode(i, data[i], data[i + 1], last);
|
|
}
|
|
if (last && equals(last, last.next)) {
|
|
removeNode(last);
|
|
last = last.next;
|
|
}
|
|
return last;
|
|
}
|
|
function filterPoints(start, end) {
|
|
if (!start)
|
|
return start;
|
|
if (!end)
|
|
end = start;
|
|
let p = start, again;
|
|
do {
|
|
again = false;
|
|
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
removeNode(p);
|
|
p = end = p.prev;
|
|
if (p === p.next)
|
|
break;
|
|
again = true;
|
|
} else {
|
|
p = p.next;
|
|
}
|
|
} while (again || p !== end);
|
|
return end;
|
|
}
|
|
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
if (!ear)
|
|
return;
|
|
if (!pass && invSize)
|
|
indexCurve(ear, minX, minY, invSize);
|
|
let stop = ear, prev, next;
|
|
while (ear.prev !== ear.next) {
|
|
prev = ear.prev;
|
|
next = ear.next;
|
|
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
triangles.push(prev.i / dim | 0);
|
|
triangles.push(ear.i / dim | 0);
|
|
triangles.push(next.i / dim | 0);
|
|
removeNode(ear);
|
|
ear = next.next;
|
|
stop = next.next;
|
|
continue;
|
|
}
|
|
ear = next;
|
|
if (ear === stop) {
|
|
if (!pass) {
|
|
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
} else if (pass === 1) {
|
|
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
} else if (pass === 2) {
|
|
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
function isEar(ear) {
|
|
const a = ear.prev, b = ear, c = ear.next;
|
|
if (area(a, b, c) >= 0)
|
|
return false;
|
|
const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
|
|
const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx, y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy, x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx, y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
|
|
let p = c.next;
|
|
while (p !== a) {
|
|
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
return false;
|
|
p = p.next;
|
|
}
|
|
return true;
|
|
}
|
|
function isEarHashed(ear, minX, minY, invSize) {
|
|
const a = ear.prev, b = ear, c = ear.next;
|
|
if (area(a, b, c) >= 0)
|
|
return false;
|
|
const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
|
|
const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx, y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy, x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx, y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
|
|
const minZ = zOrder(x0, y0, minX, minY, invSize), maxZ = zOrder(x1, y1, minX, minY, invSize);
|
|
let { prevZ: p, nextZ: n } = ear;
|
|
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
return false;
|
|
p = p.prevZ;
|
|
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
return false;
|
|
n = n.nextZ;
|
|
}
|
|
while (p && p.z >= minZ) {
|
|
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
return false;
|
|
p = p.prevZ;
|
|
}
|
|
while (n && n.z <= maxZ) {
|
|
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
return false;
|
|
n = n.nextZ;
|
|
}
|
|
return true;
|
|
}
|
|
function cureLocalIntersections(start, triangles, dim) {
|
|
let p = start;
|
|
do {
|
|
const a = p.prev, b = p.next.next;
|
|
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
triangles.push(a.i / dim | 0);
|
|
triangles.push(p.i / dim | 0);
|
|
triangles.push(b.i / dim | 0);
|
|
removeNode(p);
|
|
removeNode(p.next);
|
|
p = start = b;
|
|
}
|
|
p = p.next;
|
|
} while (p !== start);
|
|
return filterPoints(p);
|
|
}
|
|
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
let a = start;
|
|
do {
|
|
let b = a.next.next;
|
|
while (b !== a.prev) {
|
|
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
let c = splitPolygon(a, b);
|
|
a = filterPoints(a, a.next);
|
|
c = filterPoints(c, c.next);
|
|
earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
|
|
earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
|
|
return;
|
|
}
|
|
b = b.next;
|
|
}
|
|
a = a.next;
|
|
} while (a !== start);
|
|
}
|
|
function eliminateHoles(data, holeIndices, outerNode, dim) {
|
|
const queue = [];
|
|
let i, len, start, end, list;
|
|
for (i = 0, len = holeIndices.length;i < len; i++) {
|
|
start = holeIndices[i] * dim;
|
|
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
|
list = linkedList(data, start, end, dim, false);
|
|
if (list === list.next)
|
|
list.steiner = true;
|
|
queue.push(getLeftmost(list));
|
|
}
|
|
queue.sort(compareX);
|
|
for (i = 0;i < queue.length; i++) {
|
|
outerNode = eliminateHole(queue[i], outerNode);
|
|
}
|
|
return outerNode;
|
|
}
|
|
function compareX(a, b) {
|
|
return a.x - b.x;
|
|
}
|
|
function eliminateHole(hole, outerNode) {
|
|
const bridge = findHoleBridge(hole, outerNode);
|
|
if (!bridge) {
|
|
return outerNode;
|
|
}
|
|
const bridgeReverse = splitPolygon(bridge, hole);
|
|
filterPoints(bridgeReverse, bridgeReverse.next);
|
|
return filterPoints(bridge, bridge.next);
|
|
}
|
|
function findHoleBridge(hole, outerNode) {
|
|
let p = outerNode, qx = -Infinity, m;
|
|
const { x: hx, y: hy } = hole;
|
|
do {
|
|
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
if (x <= hx && x > qx) {
|
|
qx = x;
|
|
m = p.x < p.next.x ? p : p.next;
|
|
if (x === hx)
|
|
return m;
|
|
}
|
|
}
|
|
p = p.next;
|
|
} while (p !== outerNode);
|
|
if (!m)
|
|
return null;
|
|
const stop = m, mx = m.x, my = m.y;
|
|
let tanMin = Infinity, tan;
|
|
p = m;
|
|
do {
|
|
if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
|
tan = Math.abs(hy - p.y) / (hx - p.x);
|
|
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
m = p;
|
|
tanMin = tan;
|
|
}
|
|
}
|
|
p = p.next;
|
|
} while (p !== stop);
|
|
return m;
|
|
}
|
|
function sectorContainsSector(m, p) {
|
|
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
}
|
|
function indexCurve(start, minX, minY, invSize) {
|
|
let p = start;
|
|
do {
|
|
if (p.z === 0)
|
|
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
p.prevZ = p.prev;
|
|
p.nextZ = p.next;
|
|
p = p.next;
|
|
} while (p !== start);
|
|
p.prevZ.nextZ = null;
|
|
p.prevZ = null;
|
|
sortLinked(p);
|
|
}
|
|
function sortLinked(list) {
|
|
let i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
|
|
do {
|
|
p = list;
|
|
list = null;
|
|
tail = null;
|
|
numMerges = 0;
|
|
while (p) {
|
|
numMerges++;
|
|
q = p;
|
|
pSize = 0;
|
|
for (i = 0;i < inSize; i++) {
|
|
pSize++;
|
|
q = q.nextZ;
|
|
if (!q)
|
|
break;
|
|
}
|
|
qSize = inSize;
|
|
while (pSize > 0 || qSize > 0 && q) {
|
|
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
e = p;
|
|
p = p.nextZ;
|
|
pSize--;
|
|
} else {
|
|
e = q;
|
|
q = q.nextZ;
|
|
qSize--;
|
|
}
|
|
if (tail)
|
|
tail.nextZ = e;
|
|
else
|
|
list = e;
|
|
e.prevZ = tail;
|
|
tail = e;
|
|
}
|
|
p = q;
|
|
}
|
|
tail.nextZ = null;
|
|
inSize *= 2;
|
|
} while (numMerges > 1);
|
|
return list;
|
|
}
|
|
function zOrder(x, y, minX, minY, invSize) {
|
|
x = (x - minX) * invSize | 0;
|
|
y = (y - minY) * invSize | 0;
|
|
x = (x | x << 8) & 16711935;
|
|
x = (x | x << 4) & 252645135;
|
|
x = (x | x << 2) & 858993459;
|
|
x = (x | x << 1) & 1431655765;
|
|
y = (y | y << 8) & 16711935;
|
|
y = (y | y << 4) & 252645135;
|
|
y = (y | y << 2) & 858993459;
|
|
y = (y | y << 1) & 1431655765;
|
|
return x | y << 1;
|
|
}
|
|
function getLeftmost(start) {
|
|
let p = start, leftmost = start;
|
|
do {
|
|
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
|
|
leftmost = p;
|
|
p = p.next;
|
|
} while (p !== start);
|
|
return leftmost;
|
|
}
|
|
function pointInTriangle(ax, ay, bx, by, cx, cy, px2, py2) {
|
|
return (cx - px2) * (ay - py2) >= (ax - px2) * (cy - py2) && (ax - px2) * (by - py2) >= (bx - px2) * (ay - py2) && (bx - px2) * (cy - py2) >= (cx - px2) * (by - py2);
|
|
}
|
|
function isValidDiagonal(a, b) {
|
|
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
|
|
}
|
|
function area(p, q, r) {
|
|
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
}
|
|
function equals(p1, p2) {
|
|
return p1.x === p2.x && p1.y === p2.y;
|
|
}
|
|
function intersects(p1, q1, p2, q2) {
|
|
const o1 = sign(area(p1, q1, p2));
|
|
const o2 = sign(area(p1, q1, q2));
|
|
const o3 = sign(area(p2, q2, p1));
|
|
const o4 = sign(area(p2, q2, q1));
|
|
if (o1 !== o2 && o3 !== o4)
|
|
return true;
|
|
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
return true;
|
|
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
return true;
|
|
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
return true;
|
|
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
return true;
|
|
return false;
|
|
}
|
|
function onSegment(p, q, r) {
|
|
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
|
|
}
|
|
function sign(num) {
|
|
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
}
|
|
function intersectsPolygon(a, b) {
|
|
let p = a;
|
|
do {
|
|
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
|
|
return true;
|
|
p = p.next;
|
|
} while (p !== a);
|
|
return false;
|
|
}
|
|
function locallyInside(a, b) {
|
|
return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
|
}
|
|
function middleInside(a, b) {
|
|
let p = a, inside = false;
|
|
const px2 = (a.x + b.x) / 2, py2 = (a.y + b.y) / 2;
|
|
do {
|
|
if (p.y > py2 !== p.next.y > py2 && p.next.y !== p.y && px2 < (p.next.x - p.x) * (py2 - p.y) / (p.next.y - p.y) + p.x)
|
|
inside = !inside;
|
|
p = p.next;
|
|
} while (p !== a);
|
|
return inside;
|
|
}
|
|
function splitPolygon(a, b) {
|
|
const a2 = new Node2(a.i, a.x, a.y), b2 = new Node2(b.i, b.x, b.y), an = a.next, bp = b.prev;
|
|
a.next = b;
|
|
b.prev = a;
|
|
a2.next = an;
|
|
an.prev = a2;
|
|
b2.next = a2;
|
|
a2.prev = b2;
|
|
bp.next = b2;
|
|
b2.prev = bp;
|
|
return b2;
|
|
}
|
|
function insertNode(i, x, y, last) {
|
|
const p = new Node2(i, x, y);
|
|
if (!last) {
|
|
p.prev = p;
|
|
p.next = p;
|
|
} else {
|
|
p.next = last.next;
|
|
p.prev = last;
|
|
last.next.prev = p;
|
|
last.next = p;
|
|
}
|
|
return p;
|
|
}
|
|
function removeNode(p) {
|
|
p.next.prev = p.prev;
|
|
p.prev.next = p.next;
|
|
if (p.prevZ)
|
|
p.prevZ.nextZ = p.nextZ;
|
|
if (p.nextZ)
|
|
p.nextZ.prevZ = p.prevZ;
|
|
}
|
|
function Node2(i, x, y) {
|
|
this.i = i;
|
|
this.x = x;
|
|
this.y = y;
|
|
this.prev = null;
|
|
this.next = null;
|
|
this.z = 0;
|
|
this.prevZ = null;
|
|
this.nextZ = null;
|
|
this.steiner = false;
|
|
}
|
|
function signedArea(data, start, end, dim) {
|
|
let sum = 0;
|
|
for (let i = start, j = end - dim;i < end; i += dim) {
|
|
sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
|
|
j = i;
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
class ShapeUtils {
|
|
static area(contour) {
|
|
const n = contour.length;
|
|
let a = 0;
|
|
for (let p = n - 1, q = 0;q < n; p = q++) {
|
|
a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
|
|
}
|
|
return a * 0.5;
|
|
}
|
|
static isClockWise(pts) {
|
|
return ShapeUtils.area(pts) < 0;
|
|
}
|
|
static triangulateShape(contour, holes) {
|
|
const vertices = [];
|
|
const holeIndices = [];
|
|
const faces = [];
|
|
removeDupEndPts(contour);
|
|
addContour(vertices, contour);
|
|
let holeIndex = contour.length;
|
|
holes.forEach(removeDupEndPts);
|
|
for (let i = 0;i < holes.length; i++) {
|
|
holeIndices.push(holeIndex);
|
|
holeIndex += holes[i].length;
|
|
addContour(vertices, holes[i]);
|
|
}
|
|
const triangles = Earcut.triangulate(vertices, holeIndices);
|
|
for (let i = 0;i < triangles.length; i += 3) {
|
|
faces.push(triangles.slice(i, i + 3));
|
|
}
|
|
return faces;
|
|
}
|
|
}
|
|
function removeDupEndPts(points) {
|
|
const l = points.length;
|
|
if (l > 2 && points[l - 1].equals(points[0])) {
|
|
points.pop();
|
|
}
|
|
}
|
|
function addContour(vertices, contour) {
|
|
for (let i = 0;i < contour.length; i++) {
|
|
vertices.push(contour[i].x);
|
|
vertices.push(contour[i].y);
|
|
}
|
|
}
|
|
function toJSON$1(shapes, options, data) {
|
|
data.shapes = [];
|
|
if (Array.isArray(shapes)) {
|
|
for (let i = 0, l = shapes.length;i < l; i++) {
|
|
const shape = shapes[i];
|
|
data.shapes.push(shape.uuid);
|
|
}
|
|
} else {
|
|
data.shapes.push(shapes.uuid);
|
|
}
|
|
data.options = Object.assign({}, options);
|
|
if (options.extrudePath !== undefined)
|
|
data.options.extrudePath = options.extrudePath.toJSON();
|
|
return data;
|
|
}
|
|
function toJSON(shapes, data) {
|
|
data.shapes = [];
|
|
if (Array.isArray(shapes)) {
|
|
for (let i = 0, l = shapes.length;i < l; i++) {
|
|
const shape = shapes[i];
|
|
data.shapes.push(shape.uuid);
|
|
}
|
|
} else {
|
|
data.shapes.push(shapes.uuid);
|
|
}
|
|
return data;
|
|
}
|
|
function isUniqueEdge(start, end, edges) {
|
|
const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
|
|
const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`;
|
|
if (edges.has(hash1) === true || edges.has(hash2) === true) {
|
|
return false;
|
|
} else {
|
|
edges.add(hash1);
|
|
edges.add(hash2);
|
|
return true;
|
|
}
|
|
}
|
|
function convertArray(array, type, forceClone) {
|
|
if (!array || !forceClone && array.constructor === type)
|
|
return array;
|
|
if (typeof type.BYTES_PER_ELEMENT === "number") {
|
|
return new type(array);
|
|
}
|
|
return Array.prototype.slice.call(array);
|
|
}
|
|
function isTypedArray(object) {
|
|
return ArrayBuffer.isView(object) && !(object instanceof DataView);
|
|
}
|
|
function getKeyframeOrder(times) {
|
|
function compareTime(i, j) {
|
|
return times[i] - times[j];
|
|
}
|
|
const n = times.length;
|
|
const result = new Array(n);
|
|
for (let i = 0;i !== n; ++i)
|
|
result[i] = i;
|
|
result.sort(compareTime);
|
|
return result;
|
|
}
|
|
function sortedArray(values, stride, order) {
|
|
const nValues = values.length;
|
|
const result = new values.constructor(nValues);
|
|
for (let i = 0, dstOffset = 0;dstOffset !== nValues; ++i) {
|
|
const srcOffset = order[i] * stride;
|
|
for (let j = 0;j !== stride; ++j) {
|
|
result[dstOffset++] = values[srcOffset + j];
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
function flattenJSON(jsonKeys, times, values, valuePropertyName) {
|
|
let i = 1, key = jsonKeys[0];
|
|
while (key !== undefined && key[valuePropertyName] === undefined) {
|
|
key = jsonKeys[i++];
|
|
}
|
|
if (key === undefined)
|
|
return;
|
|
let value = key[valuePropertyName];
|
|
if (value === undefined)
|
|
return;
|
|
if (Array.isArray(value)) {
|
|
do {
|
|
value = key[valuePropertyName];
|
|
if (value !== undefined) {
|
|
times.push(key.time);
|
|
values.push.apply(values, value);
|
|
}
|
|
key = jsonKeys[i++];
|
|
} while (key !== undefined);
|
|
} else if (value.toArray !== undefined) {
|
|
do {
|
|
value = key[valuePropertyName];
|
|
if (value !== undefined) {
|
|
times.push(key.time);
|
|
value.toArray(values, values.length);
|
|
}
|
|
key = jsonKeys[i++];
|
|
} while (key !== undefined);
|
|
} else {
|
|
do {
|
|
value = key[valuePropertyName];
|
|
if (value !== undefined) {
|
|
times.push(key.time);
|
|
values.push(value);
|
|
}
|
|
key = jsonKeys[i++];
|
|
} while (key !== undefined);
|
|
}
|
|
}
|
|
function subclip(sourceClip, name, startFrame, endFrame, fps = 30) {
|
|
const clip = sourceClip.clone();
|
|
clip.name = name;
|
|
const tracks = [];
|
|
for (let i = 0;i < clip.tracks.length; ++i) {
|
|
const track = clip.tracks[i];
|
|
const valueSize = track.getValueSize();
|
|
const times = [];
|
|
const values = [];
|
|
for (let j = 0;j < track.times.length; ++j) {
|
|
const frame = track.times[j] * fps;
|
|
if (frame < startFrame || frame >= endFrame)
|
|
continue;
|
|
times.push(track.times[j]);
|
|
for (let k = 0;k < valueSize; ++k) {
|
|
values.push(track.values[j * valueSize + k]);
|
|
}
|
|
}
|
|
if (times.length === 0)
|
|
continue;
|
|
track.times = convertArray(times, track.times.constructor);
|
|
track.values = convertArray(values, track.values.constructor);
|
|
tracks.push(track);
|
|
}
|
|
clip.tracks = tracks;
|
|
let minStartTime = Infinity;
|
|
for (let i = 0;i < clip.tracks.length; ++i) {
|
|
if (minStartTime > clip.tracks[i].times[0]) {
|
|
minStartTime = clip.tracks[i].times[0];
|
|
}
|
|
}
|
|
for (let i = 0;i < clip.tracks.length; ++i) {
|
|
clip.tracks[i].shift(-1 * minStartTime);
|
|
}
|
|
clip.resetDuration();
|
|
return clip;
|
|
}
|
|
function makeClipAdditive(targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30) {
|
|
if (fps <= 0)
|
|
fps = 30;
|
|
const numTracks = referenceClip.tracks.length;
|
|
const referenceTime = referenceFrame / fps;
|
|
for (let i = 0;i < numTracks; ++i) {
|
|
const referenceTrack = referenceClip.tracks[i];
|
|
const referenceTrackType = referenceTrack.ValueTypeName;
|
|
if (referenceTrackType === "bool" || referenceTrackType === "string")
|
|
continue;
|
|
const targetTrack = targetClip.tracks.find(function(track) {
|
|
return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
|
|
});
|
|
if (targetTrack === undefined)
|
|
continue;
|
|
let referenceOffset = 0;
|
|
const referenceValueSize = referenceTrack.getValueSize();
|
|
if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
|
referenceOffset = referenceValueSize / 3;
|
|
}
|
|
let targetOffset = 0;
|
|
const targetValueSize = targetTrack.getValueSize();
|
|
if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
|
targetOffset = targetValueSize / 3;
|
|
}
|
|
const lastIndex = referenceTrack.times.length - 1;
|
|
let referenceValue;
|
|
if (referenceTime <= referenceTrack.times[0]) {
|
|
const startIndex = referenceOffset;
|
|
const endIndex = referenceValueSize - referenceOffset;
|
|
referenceValue = referenceTrack.values.slice(startIndex, endIndex);
|
|
} else if (referenceTime >= referenceTrack.times[lastIndex]) {
|
|
const startIndex = lastIndex * referenceValueSize + referenceOffset;
|
|
const endIndex = startIndex + referenceValueSize - referenceOffset;
|
|
referenceValue = referenceTrack.values.slice(startIndex, endIndex);
|
|
} else {
|
|
const interpolant = referenceTrack.createInterpolant();
|
|
const startIndex = referenceOffset;
|
|
const endIndex = referenceValueSize - referenceOffset;
|
|
interpolant.evaluate(referenceTime);
|
|
referenceValue = interpolant.resultBuffer.slice(startIndex, endIndex);
|
|
}
|
|
if (referenceTrackType === "quaternion") {
|
|
const referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
|
|
referenceQuat.toArray(referenceValue);
|
|
}
|
|
const numTimes = targetTrack.times.length;
|
|
for (let j = 0;j < numTimes; ++j) {
|
|
const valueStart = j * targetValueSize + targetOffset;
|
|
if (referenceTrackType === "quaternion") {
|
|
Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
|
|
} else {
|
|
const valueEnd = targetValueSize - targetOffset * 2;
|
|
for (let k = 0;k < valueEnd; ++k) {
|
|
targetTrack.values[valueStart + k] -= referenceValue[k];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
targetClip.blendMode = AdditiveAnimationBlendMode;
|
|
return targetClip;
|
|
}
|
|
|
|
class Interpolant {
|
|
constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
|
this.parameterPositions = parameterPositions;
|
|
this._cachedIndex = 0;
|
|
this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
|
|
this.sampleValues = sampleValues;
|
|
this.valueSize = sampleSize;
|
|
this.settings = null;
|
|
this.DefaultSettings_ = {};
|
|
}
|
|
evaluate(t) {
|
|
const pp = this.parameterPositions;
|
|
let i1 = this._cachedIndex, t1 = pp[i1], t0 = pp[i1 - 1];
|
|
validate_interval: {
|
|
seek: {
|
|
let right;
|
|
linear_scan: {
|
|
forward_scan:
|
|
if (!(t < t1)) {
|
|
for (let giveUpAt = i1 + 2;; ) {
|
|
if (t1 === undefined) {
|
|
if (t < t0)
|
|
break forward_scan;
|
|
i1 = pp.length;
|
|
this._cachedIndex = i1;
|
|
return this.copySampleValue_(i1 - 1);
|
|
}
|
|
if (i1 === giveUpAt)
|
|
break;
|
|
t0 = t1;
|
|
t1 = pp[++i1];
|
|
if (t < t1) {
|
|
break seek;
|
|
}
|
|
}
|
|
right = pp.length;
|
|
break linear_scan;
|
|
}
|
|
if (!(t >= t0)) {
|
|
const t1global = pp[1];
|
|
if (t < t1global) {
|
|
i1 = 2;
|
|
t0 = t1global;
|
|
}
|
|
for (let giveUpAt = i1 - 2;; ) {
|
|
if (t0 === undefined) {
|
|
this._cachedIndex = 0;
|
|
return this.copySampleValue_(0);
|
|
}
|
|
if (i1 === giveUpAt)
|
|
break;
|
|
t1 = t0;
|
|
t0 = pp[--i1 - 1];
|
|
if (t >= t0) {
|
|
break seek;
|
|
}
|
|
}
|
|
right = i1;
|
|
i1 = 0;
|
|
break linear_scan;
|
|
}
|
|
break validate_interval;
|
|
}
|
|
while (i1 < right) {
|
|
const mid = i1 + right >>> 1;
|
|
if (t < pp[mid]) {
|
|
right = mid;
|
|
} else {
|
|
i1 = mid + 1;
|
|
}
|
|
}
|
|
t1 = pp[i1];
|
|
t0 = pp[i1 - 1];
|
|
if (t0 === undefined) {
|
|
this._cachedIndex = 0;
|
|
return this.copySampleValue_(0);
|
|
}
|
|
if (t1 === undefined) {
|
|
i1 = pp.length;
|
|
this._cachedIndex = i1;
|
|
return this.copySampleValue_(i1 - 1);
|
|
}
|
|
}
|
|
this._cachedIndex = i1;
|
|
this.intervalChanged_(i1, t0, t1);
|
|
}
|
|
return this.interpolate_(i1, t0, t, t1);
|
|
}
|
|
getSettings_() {
|
|
return this.settings || this.DefaultSettings_;
|
|
}
|
|
copySampleValue_(index) {
|
|
const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, offset = index * stride;
|
|
for (let i = 0;i !== stride; ++i) {
|
|
result[i] = values[offset + i];
|
|
}
|
|
return result;
|
|
}
|
|
interpolate_() {
|
|
throw new Error("call to abstract method");
|
|
}
|
|
intervalChanged_() {}
|
|
}
|
|
|
|
class KeyframeTrack {
|
|
constructor(name, times, values, interpolation) {
|
|
if (name === undefined)
|
|
throw new Error("THREE.KeyframeTrack: track name is undefined");
|
|
if (times === undefined || times.length === 0)
|
|
throw new Error("THREE.KeyframeTrack: no keyframes in track named " + name);
|
|
this.name = name;
|
|
this.times = convertArray(times, this.TimeBufferType);
|
|
this.values = convertArray(values, this.ValueBufferType);
|
|
this.setInterpolation(interpolation || this.DefaultInterpolation);
|
|
}
|
|
static toJSON(track) {
|
|
const trackType = track.constructor;
|
|
let json;
|
|
if (trackType.toJSON !== this.toJSON) {
|
|
json = trackType.toJSON(track);
|
|
} else {
|
|
json = {
|
|
name: track.name,
|
|
times: convertArray(track.times, Array),
|
|
values: convertArray(track.values, Array)
|
|
};
|
|
const interpolation = track.getInterpolation();
|
|
if (interpolation !== track.DefaultInterpolation) {
|
|
json.interpolation = interpolation;
|
|
}
|
|
}
|
|
json.type = track.ValueTypeName;
|
|
return json;
|
|
}
|
|
InterpolantFactoryMethodDiscrete(result) {
|
|
return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
|
|
}
|
|
InterpolantFactoryMethodLinear(result) {
|
|
return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
|
|
}
|
|
InterpolantFactoryMethodSmooth(result) {
|
|
return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
|
|
}
|
|
setInterpolation(interpolation) {
|
|
let factoryMethod;
|
|
switch (interpolation) {
|
|
case InterpolateDiscrete:
|
|
factoryMethod = this.InterpolantFactoryMethodDiscrete;
|
|
break;
|
|
case InterpolateLinear:
|
|
factoryMethod = this.InterpolantFactoryMethodLinear;
|
|
break;
|
|
case InterpolateSmooth:
|
|
factoryMethod = this.InterpolantFactoryMethodSmooth;
|
|
break;
|
|
}
|
|
if (factoryMethod === undefined) {
|
|
const message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
|
|
if (this.createInterpolant === undefined) {
|
|
if (interpolation !== this.DefaultInterpolation) {
|
|
this.setInterpolation(this.DefaultInterpolation);
|
|
} else {
|
|
throw new Error(message);
|
|
}
|
|
}
|
|
console.warn("THREE.KeyframeTrack:", message);
|
|
return this;
|
|
}
|
|
this.createInterpolant = factoryMethod;
|
|
return this;
|
|
}
|
|
getInterpolation() {
|
|
switch (this.createInterpolant) {
|
|
case this.InterpolantFactoryMethodDiscrete:
|
|
return InterpolateDiscrete;
|
|
case this.InterpolantFactoryMethodLinear:
|
|
return InterpolateLinear;
|
|
case this.InterpolantFactoryMethodSmooth:
|
|
return InterpolateSmooth;
|
|
}
|
|
}
|
|
getValueSize() {
|
|
return this.values.length / this.times.length;
|
|
}
|
|
shift(timeOffset) {
|
|
if (timeOffset !== 0) {
|
|
const times = this.times;
|
|
for (let i = 0, n = times.length;i !== n; ++i) {
|
|
times[i] += timeOffset;
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
scale(timeScale) {
|
|
if (timeScale !== 1) {
|
|
const times = this.times;
|
|
for (let i = 0, n = times.length;i !== n; ++i) {
|
|
times[i] *= timeScale;
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
trim(startTime, endTime) {
|
|
const times = this.times, nKeys = times.length;
|
|
let from = 0, to = nKeys - 1;
|
|
while (from !== nKeys && times[from] < startTime) {
|
|
++from;
|
|
}
|
|
while (to !== -1 && times[to] > endTime) {
|
|
--to;
|
|
}
|
|
++to;
|
|
if (from !== 0 || to !== nKeys) {
|
|
if (from >= to) {
|
|
to = Math.max(to, 1);
|
|
from = to - 1;
|
|
}
|
|
const stride = this.getValueSize();
|
|
this.times = times.slice(from, to);
|
|
this.values = this.values.slice(from * stride, to * stride);
|
|
}
|
|
return this;
|
|
}
|
|
validate() {
|
|
let valid = true;
|
|
const valueSize = this.getValueSize();
|
|
if (valueSize - Math.floor(valueSize) !== 0) {
|
|
console.error("THREE.KeyframeTrack: Invalid value size in track.", this);
|
|
valid = false;
|
|
}
|
|
const times = this.times, values = this.values, nKeys = times.length;
|
|
if (nKeys === 0) {
|
|
console.error("THREE.KeyframeTrack: Track is empty.", this);
|
|
valid = false;
|
|
}
|
|
let prevTime = null;
|
|
for (let i = 0;i !== nKeys; i++) {
|
|
const currTime = times[i];
|
|
if (typeof currTime === "number" && isNaN(currTime)) {
|
|
console.error("THREE.KeyframeTrack: Time is not a valid number.", this, i, currTime);
|
|
valid = false;
|
|
break;
|
|
}
|
|
if (prevTime !== null && prevTime > currTime) {
|
|
console.error("THREE.KeyframeTrack: Out of order keys.", this, i, currTime, prevTime);
|
|
valid = false;
|
|
break;
|
|
}
|
|
prevTime = currTime;
|
|
}
|
|
if (values !== undefined) {
|
|
if (isTypedArray(values)) {
|
|
for (let i = 0, n = values.length;i !== n; ++i) {
|
|
const value = values[i];
|
|
if (isNaN(value)) {
|
|
console.error("THREE.KeyframeTrack: Value is not a valid number.", this, i, value);
|
|
valid = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return valid;
|
|
}
|
|
optimize() {
|
|
const times = this.times.slice(), values = this.values.slice(), stride = this.getValueSize(), smoothInterpolation = this.getInterpolation() === InterpolateSmooth, lastIndex = times.length - 1;
|
|
let writeIndex = 1;
|
|
for (let i = 1;i < lastIndex; ++i) {
|
|
let keep = false;
|
|
const time = times[i];
|
|
const timeNext = times[i + 1];
|
|
if (time !== timeNext && (i !== 1 || time !== times[0])) {
|
|
if (!smoothInterpolation) {
|
|
const offset = i * stride, offsetP = offset - stride, offsetN = offset + stride;
|
|
for (let j = 0;j !== stride; ++j) {
|
|
const value = values[offset + j];
|
|
if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
|
|
keep = true;
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
keep = true;
|
|
}
|
|
}
|
|
if (keep) {
|
|
if (i !== writeIndex) {
|
|
times[writeIndex] = times[i];
|
|
const readOffset = i * stride, writeOffset = writeIndex * stride;
|
|
for (let j = 0;j !== stride; ++j) {
|
|
values[writeOffset + j] = values[readOffset + j];
|
|
}
|
|
}
|
|
++writeIndex;
|
|
}
|
|
}
|
|
if (lastIndex > 0) {
|
|
times[writeIndex] = times[lastIndex];
|
|
for (let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0;j !== stride; ++j) {
|
|
values[writeOffset + j] = values[readOffset + j];
|
|
}
|
|
++writeIndex;
|
|
}
|
|
if (writeIndex !== times.length) {
|
|
this.times = times.slice(0, writeIndex);
|
|
this.values = values.slice(0, writeIndex * stride);
|
|
} else {
|
|
this.times = times;
|
|
this.values = values;
|
|
}
|
|
return this;
|
|
}
|
|
clone() {
|
|
const times = this.times.slice();
|
|
const values = this.values.slice();
|
|
const TypedKeyframeTrack = this.constructor;
|
|
const track = new TypedKeyframeTrack(this.name, times, values);
|
|
track.createInterpolant = this.createInterpolant;
|
|
return track;
|
|
}
|
|
}
|
|
|
|
class AnimationClip {
|
|
constructor(name = "", duration = -1, tracks = [], blendMode = NormalAnimationBlendMode) {
|
|
this.name = name;
|
|
this.tracks = tracks;
|
|
this.duration = duration;
|
|
this.blendMode = blendMode;
|
|
this.uuid = generateUUID();
|
|
if (this.duration < 0) {
|
|
this.resetDuration();
|
|
}
|
|
}
|
|
static parse(json) {
|
|
const tracks = [], jsonTracks = json.tracks, frameTime = 1 / (json.fps || 1);
|
|
for (let i = 0, n = jsonTracks.length;i !== n; ++i) {
|
|
tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
|
|
}
|
|
const clip = new this(json.name, json.duration, tracks, json.blendMode);
|
|
clip.uuid = json.uuid;
|
|
return clip;
|
|
}
|
|
static toJSON(clip) {
|
|
const tracks = [], clipTracks = clip.tracks;
|
|
const json = {
|
|
name: clip.name,
|
|
duration: clip.duration,
|
|
tracks,
|
|
uuid: clip.uuid,
|
|
blendMode: clip.blendMode
|
|
};
|
|
for (let i = 0, n = clipTracks.length;i !== n; ++i) {
|
|
tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
|
|
}
|
|
return json;
|
|
}
|
|
static CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
|
|
const numMorphTargets = morphTargetSequence.length;
|
|
const tracks = [];
|
|
for (let i = 0;i < numMorphTargets; i++) {
|
|
let times = [];
|
|
let values = [];
|
|
times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
|
|
values.push(0, 1, 0);
|
|
const order = getKeyframeOrder(times);
|
|
times = sortedArray(times, 1, order);
|
|
values = sortedArray(values, 1, order);
|
|
if (!noLoop && times[0] === 0) {
|
|
times.push(numMorphTargets);
|
|
values.push(values[0]);
|
|
}
|
|
tracks.push(new NumberKeyframeTrack(".morphTargetInfluences[" + morphTargetSequence[i].name + "]", times, values).scale(1 / fps));
|
|
}
|
|
return new this(name, -1, tracks);
|
|
}
|
|
static findByName(objectOrClipArray, name) {
|
|
let clipArray = objectOrClipArray;
|
|
if (!Array.isArray(objectOrClipArray)) {
|
|
const o = objectOrClipArray;
|
|
clipArray = o.geometry && o.geometry.animations || o.animations;
|
|
}
|
|
for (let i = 0;i < clipArray.length; i++) {
|
|
if (clipArray[i].name === name) {
|
|
return clipArray[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
static CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
|
|
const animationToMorphTargets = {};
|
|
const pattern = /^([\w-]*?)([\d]+)$/;
|
|
for (let i = 0, il = morphTargets.length;i < il; i++) {
|
|
const morphTarget = morphTargets[i];
|
|
const parts = morphTarget.name.match(pattern);
|
|
if (parts && parts.length > 1) {
|
|
const name = parts[1];
|
|
let animationMorphTargets = animationToMorphTargets[name];
|
|
if (!animationMorphTargets) {
|
|
animationToMorphTargets[name] = animationMorphTargets = [];
|
|
}
|
|
animationMorphTargets.push(morphTarget);
|
|
}
|
|
}
|
|
const clips = [];
|
|
for (const name in animationToMorphTargets) {
|
|
clips.push(this.CreateFromMorphTargetSequence(name, animationToMorphTargets[name], fps, noLoop));
|
|
}
|
|
return clips;
|
|
}
|
|
static parseAnimation(animation, bones) {
|
|
if (!animation) {
|
|
console.error("THREE.AnimationClip: No animation in JSONLoader data.");
|
|
return null;
|
|
}
|
|
const addNonemptyTrack = function(trackType, trackName, animationKeys, propertyName, destTracks) {
|
|
if (animationKeys.length !== 0) {
|
|
const times = [];
|
|
const values = [];
|
|
flattenJSON(animationKeys, times, values, propertyName);
|
|
if (times.length !== 0) {
|
|
destTracks.push(new trackType(trackName, times, values));
|
|
}
|
|
}
|
|
};
|
|
const tracks = [];
|
|
const clipName = animation.name || "default";
|
|
const fps = animation.fps || 30;
|
|
const blendMode = animation.blendMode;
|
|
let duration = animation.length || -1;
|
|
const hierarchyTracks = animation.hierarchy || [];
|
|
for (let h = 0;h < hierarchyTracks.length; h++) {
|
|
const animationKeys = hierarchyTracks[h].keys;
|
|
if (!animationKeys || animationKeys.length === 0)
|
|
continue;
|
|
if (animationKeys[0].morphTargets) {
|
|
const morphTargetNames = {};
|
|
let k;
|
|
for (k = 0;k < animationKeys.length; k++) {
|
|
if (animationKeys[k].morphTargets) {
|
|
for (let m = 0;m < animationKeys[k].morphTargets.length; m++) {
|
|
morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
|
|
}
|
|
}
|
|
}
|
|
for (const morphTargetName in morphTargetNames) {
|
|
const times = [];
|
|
const values = [];
|
|
for (let m = 0;m !== animationKeys[k].morphTargets.length; ++m) {
|
|
const animationKey = animationKeys[k];
|
|
times.push(animationKey.time);
|
|
values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
|
|
}
|
|
tracks.push(new NumberKeyframeTrack(".morphTargetInfluence[" + morphTargetName + "]", times, values));
|
|
}
|
|
duration = morphTargetNames.length * fps;
|
|
} else {
|
|
const boneName = ".bones[" + bones[h].name + "]";
|
|
addNonemptyTrack(VectorKeyframeTrack, boneName + ".position", animationKeys, "pos", tracks);
|
|
addNonemptyTrack(QuaternionKeyframeTrack, boneName + ".quaternion", animationKeys, "rot", tracks);
|
|
addNonemptyTrack(VectorKeyframeTrack, boneName + ".scale", animationKeys, "scl", tracks);
|
|
}
|
|
}
|
|
if (tracks.length === 0) {
|
|
return null;
|
|
}
|
|
const clip = new this(clipName, duration, tracks, blendMode);
|
|
return clip;
|
|
}
|
|
resetDuration() {
|
|
const tracks = this.tracks;
|
|
let duration = 0;
|
|
for (let i = 0, n = tracks.length;i !== n; ++i) {
|
|
const track = this.tracks[i];
|
|
duration = Math.max(duration, track.times[track.times.length - 1]);
|
|
}
|
|
this.duration = duration;
|
|
return this;
|
|
}
|
|
trim() {
|
|
for (let i = 0;i < this.tracks.length; i++) {
|
|
this.tracks[i].trim(0, this.duration);
|
|
}
|
|
return this;
|
|
}
|
|
validate() {
|
|
let valid = true;
|
|
for (let i = 0;i < this.tracks.length; i++) {
|
|
valid = valid && this.tracks[i].validate();
|
|
}
|
|
return valid;
|
|
}
|
|
optimize() {
|
|
for (let i = 0;i < this.tracks.length; i++) {
|
|
this.tracks[i].optimize();
|
|
}
|
|
return this;
|
|
}
|
|
clone() {
|
|
const tracks = [];
|
|
for (let i = 0;i < this.tracks.length; i++) {
|
|
tracks.push(this.tracks[i].clone());
|
|
}
|
|
return new this.constructor(this.name, this.duration, tracks, this.blendMode);
|
|
}
|
|
toJSON() {
|
|
return this.constructor.toJSON(this);
|
|
}
|
|
}
|
|
function getTrackTypeForValueTypeName(typeName) {
|
|
switch (typeName.toLowerCase()) {
|
|
case "scalar":
|
|
case "double":
|
|
case "float":
|
|
case "number":
|
|
case "integer":
|
|
return NumberKeyframeTrack;
|
|
case "vector":
|
|
case "vector2":
|
|
case "vector3":
|
|
case "vector4":
|
|
return VectorKeyframeTrack;
|
|
case "color":
|
|
return ColorKeyframeTrack;
|
|
case "quaternion":
|
|
return QuaternionKeyframeTrack;
|
|
case "bool":
|
|
case "boolean":
|
|
return BooleanKeyframeTrack;
|
|
case "string":
|
|
return StringKeyframeTrack;
|
|
}
|
|
throw new Error("THREE.KeyframeTrack: Unsupported typeName: " + typeName);
|
|
}
|
|
function parseKeyframeTrack(json) {
|
|
if (json.type === undefined) {
|
|
throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");
|
|
}
|
|
const trackType = getTrackTypeForValueTypeName(json.type);
|
|
if (json.times === undefined) {
|
|
const times = [], values = [];
|
|
flattenJSON(json.keys, times, values, "value");
|
|
json.times = times;
|
|
json.values = values;
|
|
}
|
|
if (trackType.parse !== undefined) {
|
|
return trackType.parse(json);
|
|
} else {
|
|
return new trackType(json.name, json.times, json.values, json.interpolation);
|
|
}
|
|
}
|
|
|
|
class LoadingManager {
|
|
constructor(onLoad, onProgress, onError) {
|
|
const scope = this;
|
|
let isLoading = false;
|
|
let itemsLoaded = 0;
|
|
let itemsTotal = 0;
|
|
let urlModifier = undefined;
|
|
const handlers = [];
|
|
this.onStart = undefined;
|
|
this.onLoad = onLoad;
|
|
this.onProgress = onProgress;
|
|
this.onError = onError;
|
|
this.itemStart = function(url) {
|
|
itemsTotal++;
|
|
if (isLoading === false) {
|
|
if (scope.onStart !== undefined) {
|
|
scope.onStart(url, itemsLoaded, itemsTotal);
|
|
}
|
|
}
|
|
isLoading = true;
|
|
};
|
|
this.itemEnd = function(url) {
|
|
itemsLoaded++;
|
|
if (scope.onProgress !== undefined) {
|
|
scope.onProgress(url, itemsLoaded, itemsTotal);
|
|
}
|
|
if (itemsLoaded === itemsTotal) {
|
|
isLoading = false;
|
|
if (scope.onLoad !== undefined) {
|
|
scope.onLoad();
|
|
}
|
|
}
|
|
};
|
|
this.itemError = function(url) {
|
|
if (scope.onError !== undefined) {
|
|
scope.onError(url);
|
|
}
|
|
};
|
|
this.resolveURL = function(url) {
|
|
if (urlModifier) {
|
|
return urlModifier(url);
|
|
}
|
|
return url;
|
|
};
|
|
this.setURLModifier = function(transform) {
|
|
urlModifier = transform;
|
|
return this;
|
|
};
|
|
this.addHandler = function(regex, loader) {
|
|
handlers.push(regex, loader);
|
|
return this;
|
|
};
|
|
this.removeHandler = function(regex) {
|
|
const index = handlers.indexOf(regex);
|
|
if (index !== -1) {
|
|
handlers.splice(index, 2);
|
|
}
|
|
return this;
|
|
};
|
|
this.getHandler = function(file) {
|
|
for (let i = 0, l = handlers.length;i < l; i += 2) {
|
|
const regex = handlers[i];
|
|
const loader = handlers[i + 1];
|
|
if (regex.global)
|
|
regex.lastIndex = 0;
|
|
if (regex.test(file)) {
|
|
return loader;
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
}
|
|
}
|
|
|
|
class Loader {
|
|
constructor(manager) {
|
|
this.manager = manager !== undefined ? manager : DefaultLoadingManager;
|
|
this.crossOrigin = "anonymous";
|
|
this.withCredentials = false;
|
|
this.path = "";
|
|
this.resourcePath = "";
|
|
this.requestHeader = {};
|
|
}
|
|
load() {}
|
|
loadAsync(url, onProgress) {
|
|
const scope = this;
|
|
return new Promise(function(resolve, reject) {
|
|
scope.load(url, resolve, onProgress, reject);
|
|
});
|
|
}
|
|
parse() {}
|
|
setCrossOrigin(crossOrigin) {
|
|
this.crossOrigin = crossOrigin;
|
|
return this;
|
|
}
|
|
setWithCredentials(value) {
|
|
this.withCredentials = value;
|
|
return this;
|
|
}
|
|
setPath(path) {
|
|
this.path = path;
|
|
return this;
|
|
}
|
|
setResourcePath(resourcePath) {
|
|
this.resourcePath = resourcePath;
|
|
return this;
|
|
}
|
|
setRequestHeader(requestHeader) {
|
|
this.requestHeader = requestHeader;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
class LightShadow {
|
|
constructor(camera) {
|
|
this.camera = camera;
|
|
this.intensity = 1;
|
|
this.bias = 0;
|
|
this.normalBias = 0;
|
|
this.radius = 1;
|
|
this.blurSamples = 8;
|
|
this.mapSize = new Vector2(512, 512);
|
|
this.map = null;
|
|
this.mapPass = null;
|
|
this.matrix = new Matrix4;
|
|
this.autoUpdate = true;
|
|
this.needsUpdate = false;
|
|
this._frustum = new Frustum;
|
|
this._frameExtents = new Vector2(1, 1);
|
|
this._viewportCount = 1;
|
|
this._viewports = [
|
|
new Vector4(0, 0, 1, 1)
|
|
];
|
|
}
|
|
getViewportCount() {
|
|
return this._viewportCount;
|
|
}
|
|
getFrustum() {
|
|
return this._frustum;
|
|
}
|
|
updateMatrices(light) {
|
|
const shadowCamera = this.camera;
|
|
const shadowMatrix = this.matrix;
|
|
_lightPositionWorld$1.setFromMatrixPosition(light.matrixWorld);
|
|
shadowCamera.position.copy(_lightPositionWorld$1);
|
|
_lookTarget$1.setFromMatrixPosition(light.target.matrixWorld);
|
|
shadowCamera.lookAt(_lookTarget$1);
|
|
shadowCamera.updateMatrixWorld();
|
|
_projScreenMatrix$1.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
|
|
this._frustum.setFromProjectionMatrix(_projScreenMatrix$1);
|
|
shadowMatrix.set(0.5, 0, 0, 0.5, 0, 0.5, 0, 0.5, 0, 0, 0.5, 0.5, 0, 0, 0, 1);
|
|
shadowMatrix.multiply(_projScreenMatrix$1);
|
|
}
|
|
getViewport(viewportIndex) {
|
|
return this._viewports[viewportIndex];
|
|
}
|
|
getFrameExtents() {
|
|
return this._frameExtents;
|
|
}
|
|
dispose() {
|
|
if (this.map) {
|
|
this.map.dispose();
|
|
}
|
|
if (this.mapPass) {
|
|
this.mapPass.dispose();
|
|
}
|
|
}
|
|
copy(source) {
|
|
this.camera = source.camera.clone();
|
|
this.intensity = source.intensity;
|
|
this.bias = source.bias;
|
|
this.radius = source.radius;
|
|
this.mapSize.copy(source.mapSize);
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
toJSON() {
|
|
const object = {};
|
|
if (this.intensity !== 1)
|
|
object.intensity = this.intensity;
|
|
if (this.bias !== 0)
|
|
object.bias = this.bias;
|
|
if (this.normalBias !== 0)
|
|
object.normalBias = this.normalBias;
|
|
if (this.radius !== 1)
|
|
object.radius = this.radius;
|
|
if (this.mapSize.x !== 512 || this.mapSize.y !== 512)
|
|
object.mapSize = this.mapSize.toArray();
|
|
object.camera = this.camera.toJSON(false).object;
|
|
delete object.camera.matrix;
|
|
return object;
|
|
}
|
|
}
|
|
|
|
class SphericalHarmonics3 {
|
|
constructor() {
|
|
this.isSphericalHarmonics3 = true;
|
|
this.coefficients = [];
|
|
for (let i = 0;i < 9; i++) {
|
|
this.coefficients.push(new Vector3);
|
|
}
|
|
}
|
|
set(coefficients) {
|
|
for (let i = 0;i < 9; i++) {
|
|
this.coefficients[i].copy(coefficients[i]);
|
|
}
|
|
return this;
|
|
}
|
|
zero() {
|
|
for (let i = 0;i < 9; i++) {
|
|
this.coefficients[i].set(0, 0, 0);
|
|
}
|
|
return this;
|
|
}
|
|
getAt(normal, target) {
|
|
const { x, y, z } = normal;
|
|
const coeff = this.coefficients;
|
|
target.copy(coeff[0]).multiplyScalar(0.282095);
|
|
target.addScaledVector(coeff[1], 0.488603 * y);
|
|
target.addScaledVector(coeff[2], 0.488603 * z);
|
|
target.addScaledVector(coeff[3], 0.488603 * x);
|
|
target.addScaledVector(coeff[4], 1.092548 * (x * y));
|
|
target.addScaledVector(coeff[5], 1.092548 * (y * z));
|
|
target.addScaledVector(coeff[6], 0.315392 * (3 * z * z - 1));
|
|
target.addScaledVector(coeff[7], 1.092548 * (x * z));
|
|
target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
|
|
return target;
|
|
}
|
|
getIrradianceAt(normal, target) {
|
|
const { x, y, z } = normal;
|
|
const coeff = this.coefficients;
|
|
target.copy(coeff[0]).multiplyScalar(0.886227);
|
|
target.addScaledVector(coeff[1], 2 * 0.511664 * y);
|
|
target.addScaledVector(coeff[2], 2 * 0.511664 * z);
|
|
target.addScaledVector(coeff[3], 2 * 0.511664 * x);
|
|
target.addScaledVector(coeff[4], 2 * 0.429043 * x * y);
|
|
target.addScaledVector(coeff[5], 2 * 0.429043 * y * z);
|
|
target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708);
|
|
target.addScaledVector(coeff[7], 2 * 0.429043 * x * z);
|
|
target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y));
|
|
return target;
|
|
}
|
|
add(sh) {
|
|
for (let i = 0;i < 9; i++) {
|
|
this.coefficients[i].add(sh.coefficients[i]);
|
|
}
|
|
return this;
|
|
}
|
|
addScaledSH(sh, s) {
|
|
for (let i = 0;i < 9; i++) {
|
|
this.coefficients[i].addScaledVector(sh.coefficients[i], s);
|
|
}
|
|
return this;
|
|
}
|
|
scale(s) {
|
|
for (let i = 0;i < 9; i++) {
|
|
this.coefficients[i].multiplyScalar(s);
|
|
}
|
|
return this;
|
|
}
|
|
lerp(sh, alpha) {
|
|
for (let i = 0;i < 9; i++) {
|
|
this.coefficients[i].lerp(sh.coefficients[i], alpha);
|
|
}
|
|
return this;
|
|
}
|
|
equals(sh) {
|
|
for (let i = 0;i < 9; i++) {
|
|
if (!this.coefficients[i].equals(sh.coefficients[i])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
copy(sh) {
|
|
return this.set(sh.coefficients);
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
const coefficients = this.coefficients;
|
|
for (let i = 0;i < 9; i++) {
|
|
coefficients[i].fromArray(array, offset + i * 3);
|
|
}
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
const coefficients = this.coefficients;
|
|
for (let i = 0;i < 9; i++) {
|
|
coefficients[i].toArray(array, offset + i * 3);
|
|
}
|
|
return array;
|
|
}
|
|
static getBasisAt(normal, shBasis) {
|
|
const { x, y, z } = normal;
|
|
shBasis[0] = 0.282095;
|
|
shBasis[1] = 0.488603 * y;
|
|
shBasis[2] = 0.488603 * z;
|
|
shBasis[3] = 0.488603 * x;
|
|
shBasis[4] = 1.092548 * x * y;
|
|
shBasis[5] = 1.092548 * y * z;
|
|
shBasis[6] = 0.315392 * (3 * z * z - 1);
|
|
shBasis[7] = 1.092548 * x * z;
|
|
shBasis[8] = 0.546274 * (x * x - y * y);
|
|
}
|
|
}
|
|
|
|
class LoaderUtils {
|
|
static decodeText(array) {
|
|
console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.");
|
|
if (typeof TextDecoder !== "undefined") {
|
|
return new TextDecoder().decode(array);
|
|
}
|
|
let s = "";
|
|
for (let i = 0, il = array.length;i < il; i++) {
|
|
s += String.fromCharCode(array[i]);
|
|
}
|
|
try {
|
|
return decodeURIComponent(escape(s));
|
|
} catch (e) {
|
|
return s;
|
|
}
|
|
}
|
|
static extractUrlBase(url) {
|
|
const index = url.lastIndexOf("/");
|
|
if (index === -1)
|
|
return "./";
|
|
return url.slice(0, index + 1);
|
|
}
|
|
static resolveURL(url, path) {
|
|
if (typeof url !== "string" || url === "")
|
|
return "";
|
|
if (/^https?:\/\//i.test(path) && /^\//.test(url)) {
|
|
path = path.replace(/(^https?:\/\/[^\/]+).*/i, "$1");
|
|
}
|
|
if (/^(https?:)?\/\//i.test(url))
|
|
return url;
|
|
if (/^data:.*,.*$/i.test(url))
|
|
return url;
|
|
if (/^blob:.*$/i.test(url))
|
|
return url;
|
|
return path + url;
|
|
}
|
|
}
|
|
|
|
class AudioContext {
|
|
static getContext() {
|
|
if (_context === undefined) {
|
|
_context = new (window.AudioContext || window.webkitAudioContext);
|
|
}
|
|
return _context;
|
|
}
|
|
static setContext(value) {
|
|
_context = value;
|
|
}
|
|
}
|
|
|
|
class StereoCamera {
|
|
constructor() {
|
|
this.type = "StereoCamera";
|
|
this.aspect = 1;
|
|
this.eyeSep = 0.064;
|
|
this.cameraL = new PerspectiveCamera;
|
|
this.cameraL.layers.enable(1);
|
|
this.cameraL.matrixAutoUpdate = false;
|
|
this.cameraR = new PerspectiveCamera;
|
|
this.cameraR.layers.enable(2);
|
|
this.cameraR.matrixAutoUpdate = false;
|
|
this._cache = {
|
|
focus: null,
|
|
fov: null,
|
|
aspect: null,
|
|
near: null,
|
|
far: null,
|
|
zoom: null,
|
|
eyeSep: null
|
|
};
|
|
}
|
|
update(camera) {
|
|
const cache = this._cache;
|
|
const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov || cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near || cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
|
|
if (needsUpdate) {
|
|
cache.focus = camera.focus;
|
|
cache.fov = camera.fov;
|
|
cache.aspect = camera.aspect * this.aspect;
|
|
cache.near = camera.near;
|
|
cache.far = camera.far;
|
|
cache.zoom = camera.zoom;
|
|
cache.eyeSep = this.eyeSep;
|
|
_projectionMatrix.copy(camera.projectionMatrix);
|
|
const eyeSepHalf = cache.eyeSep / 2;
|
|
const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
|
|
const ymax = cache.near * Math.tan(DEG2RAD * cache.fov * 0.5) / cache.zoom;
|
|
let xmin, xmax;
|
|
_eyeLeft.elements[12] = -eyeSepHalf;
|
|
_eyeRight.elements[12] = eyeSepHalf;
|
|
xmin = -ymax * cache.aspect + eyeSepOnProjection;
|
|
xmax = ymax * cache.aspect + eyeSepOnProjection;
|
|
_projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
|
|
_projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
|
|
this.cameraL.projectionMatrix.copy(_projectionMatrix);
|
|
xmin = -ymax * cache.aspect - eyeSepOnProjection;
|
|
xmax = ymax * cache.aspect - eyeSepOnProjection;
|
|
_projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
|
|
_projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
|
|
this.cameraR.projectionMatrix.copy(_projectionMatrix);
|
|
}
|
|
this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
|
|
this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
|
|
}
|
|
}
|
|
|
|
class Clock {
|
|
constructor(autoStart = true) {
|
|
this.autoStart = autoStart;
|
|
this.startTime = 0;
|
|
this.oldTime = 0;
|
|
this.elapsedTime = 0;
|
|
this.running = false;
|
|
}
|
|
start() {
|
|
this.startTime = now();
|
|
this.oldTime = this.startTime;
|
|
this.elapsedTime = 0;
|
|
this.running = true;
|
|
}
|
|
stop() {
|
|
this.getElapsedTime();
|
|
this.running = false;
|
|
this.autoStart = false;
|
|
}
|
|
getElapsedTime() {
|
|
this.getDelta();
|
|
return this.elapsedTime;
|
|
}
|
|
getDelta() {
|
|
let diff = 0;
|
|
if (this.autoStart && !this.running) {
|
|
this.start();
|
|
return 0;
|
|
}
|
|
if (this.running) {
|
|
const newTime = now();
|
|
diff = (newTime - this.oldTime) / 1000;
|
|
this.oldTime = newTime;
|
|
this.elapsedTime += diff;
|
|
}
|
|
return diff;
|
|
}
|
|
}
|
|
function now() {
|
|
return performance.now();
|
|
}
|
|
|
|
class AudioAnalyser {
|
|
constructor(audio, fftSize = 2048) {
|
|
this.analyser = audio.context.createAnalyser();
|
|
this.analyser.fftSize = fftSize;
|
|
this.data = new Uint8Array(this.analyser.frequencyBinCount);
|
|
audio.getOutput().connect(this.analyser);
|
|
}
|
|
getFrequencyData() {
|
|
this.analyser.getByteFrequencyData(this.data);
|
|
return this.data;
|
|
}
|
|
getAverageFrequency() {
|
|
let value = 0;
|
|
const data = this.getFrequencyData();
|
|
for (let i = 0;i < data.length; i++) {
|
|
value += data[i];
|
|
}
|
|
return value / data.length;
|
|
}
|
|
}
|
|
|
|
class PropertyMixer {
|
|
constructor(binding, typeName, valueSize) {
|
|
this.binding = binding;
|
|
this.valueSize = valueSize;
|
|
let mixFunction, mixFunctionAdditive, setIdentity;
|
|
switch (typeName) {
|
|
case "quaternion":
|
|
mixFunction = this._slerp;
|
|
mixFunctionAdditive = this._slerpAdditive;
|
|
setIdentity = this._setAdditiveIdentityQuaternion;
|
|
this.buffer = new Float64Array(valueSize * 6);
|
|
this._workIndex = 5;
|
|
break;
|
|
case "string":
|
|
case "bool":
|
|
mixFunction = this._select;
|
|
mixFunctionAdditive = this._select;
|
|
setIdentity = this._setAdditiveIdentityOther;
|
|
this.buffer = new Array(valueSize * 5);
|
|
break;
|
|
default:
|
|
mixFunction = this._lerp;
|
|
mixFunctionAdditive = this._lerpAdditive;
|
|
setIdentity = this._setAdditiveIdentityNumeric;
|
|
this.buffer = new Float64Array(valueSize * 5);
|
|
}
|
|
this._mixBufferRegion = mixFunction;
|
|
this._mixBufferRegionAdditive = mixFunctionAdditive;
|
|
this._setIdentity = setIdentity;
|
|
this._origIndex = 3;
|
|
this._addIndex = 4;
|
|
this.cumulativeWeight = 0;
|
|
this.cumulativeWeightAdditive = 0;
|
|
this.useCount = 0;
|
|
this.referenceCount = 0;
|
|
}
|
|
accumulate(accuIndex, weight) {
|
|
const buffer = this.buffer, stride = this.valueSize, offset = accuIndex * stride + stride;
|
|
let currentWeight = this.cumulativeWeight;
|
|
if (currentWeight === 0) {
|
|
for (let i = 0;i !== stride; ++i) {
|
|
buffer[offset + i] = buffer[i];
|
|
}
|
|
currentWeight = weight;
|
|
} else {
|
|
currentWeight += weight;
|
|
const mix = weight / currentWeight;
|
|
this._mixBufferRegion(buffer, offset, 0, mix, stride);
|
|
}
|
|
this.cumulativeWeight = currentWeight;
|
|
}
|
|
accumulateAdditive(weight) {
|
|
const buffer = this.buffer, stride = this.valueSize, offset = stride * this._addIndex;
|
|
if (this.cumulativeWeightAdditive === 0) {
|
|
this._setIdentity();
|
|
}
|
|
this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
|
|
this.cumulativeWeightAdditive += weight;
|
|
}
|
|
apply(accuIndex) {
|
|
const stride = this.valueSize, buffer = this.buffer, offset = accuIndex * stride + stride, weight = this.cumulativeWeight, weightAdditive = this.cumulativeWeightAdditive, binding = this.binding;
|
|
this.cumulativeWeight = 0;
|
|
this.cumulativeWeightAdditive = 0;
|
|
if (weight < 1) {
|
|
const originalValueOffset = stride * this._origIndex;
|
|
this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
|
|
}
|
|
if (weightAdditive > 0) {
|
|
this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
|
|
}
|
|
for (let i = stride, e = stride + stride;i !== e; ++i) {
|
|
if (buffer[i] !== buffer[i + stride]) {
|
|
binding.setValue(buffer, offset);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
saveOriginalState() {
|
|
const binding = this.binding;
|
|
const buffer = this.buffer, stride = this.valueSize, originalValueOffset = stride * this._origIndex;
|
|
binding.getValue(buffer, originalValueOffset);
|
|
for (let i = stride, e = originalValueOffset;i !== e; ++i) {
|
|
buffer[i] = buffer[originalValueOffset + i % stride];
|
|
}
|
|
this._setIdentity();
|
|
this.cumulativeWeight = 0;
|
|
this.cumulativeWeightAdditive = 0;
|
|
}
|
|
restoreOriginalState() {
|
|
const originalValueOffset = this.valueSize * 3;
|
|
this.binding.setValue(this.buffer, originalValueOffset);
|
|
}
|
|
_setAdditiveIdentityNumeric() {
|
|
const startIndex = this._addIndex * this.valueSize;
|
|
const endIndex = startIndex + this.valueSize;
|
|
for (let i = startIndex;i < endIndex; i++) {
|
|
this.buffer[i] = 0;
|
|
}
|
|
}
|
|
_setAdditiveIdentityQuaternion() {
|
|
this._setAdditiveIdentityNumeric();
|
|
this.buffer[this._addIndex * this.valueSize + 3] = 1;
|
|
}
|
|
_setAdditiveIdentityOther() {
|
|
const startIndex = this._origIndex * this.valueSize;
|
|
const targetIndex = this._addIndex * this.valueSize;
|
|
for (let i = 0;i < this.valueSize; i++) {
|
|
this.buffer[targetIndex + i] = this.buffer[startIndex + i];
|
|
}
|
|
}
|
|
_select(buffer, dstOffset, srcOffset, t, stride) {
|
|
if (t >= 0.5) {
|
|
for (let i = 0;i !== stride; ++i) {
|
|
buffer[dstOffset + i] = buffer[srcOffset + i];
|
|
}
|
|
}
|
|
}
|
|
_slerp(buffer, dstOffset, srcOffset, t) {
|
|
Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
|
|
}
|
|
_slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
|
|
const workOffset = this._workIndex * stride;
|
|
Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset);
|
|
Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
|
|
}
|
|
_lerp(buffer, dstOffset, srcOffset, t, stride) {
|
|
const s = 1 - t;
|
|
for (let i = 0;i !== stride; ++i) {
|
|
const j = dstOffset + i;
|
|
buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
|
|
}
|
|
}
|
|
_lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
|
|
for (let i = 0;i !== stride; ++i) {
|
|
const j = dstOffset + i;
|
|
buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
|
|
}
|
|
}
|
|
}
|
|
|
|
class Composite {
|
|
constructor(targetGroup, path, optionalParsedPath) {
|
|
const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
|
|
this._targetGroup = targetGroup;
|
|
this._bindings = targetGroup.subscribe_(path, parsedPath);
|
|
}
|
|
getValue(array, offset) {
|
|
this.bind();
|
|
const firstValidIndex = this._targetGroup.nCachedObjects_, binding = this._bindings[firstValidIndex];
|
|
if (binding !== undefined)
|
|
binding.getValue(array, offset);
|
|
}
|
|
setValue(array, offset) {
|
|
const bindings = this._bindings;
|
|
for (let i = this._targetGroup.nCachedObjects_, n = bindings.length;i !== n; ++i) {
|
|
bindings[i].setValue(array, offset);
|
|
}
|
|
}
|
|
bind() {
|
|
const bindings = this._bindings;
|
|
for (let i = this._targetGroup.nCachedObjects_, n = bindings.length;i !== n; ++i) {
|
|
bindings[i].bind();
|
|
}
|
|
}
|
|
unbind() {
|
|
const bindings = this._bindings;
|
|
for (let i = this._targetGroup.nCachedObjects_, n = bindings.length;i !== n; ++i) {
|
|
bindings[i].unbind();
|
|
}
|
|
}
|
|
}
|
|
|
|
class PropertyBinding {
|
|
constructor(rootNode, path, parsedPath) {
|
|
this.path = path;
|
|
this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
|
|
this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName);
|
|
this.rootNode = rootNode;
|
|
this.getValue = this._getValue_unbound;
|
|
this.setValue = this._setValue_unbound;
|
|
}
|
|
static create(root, path, parsedPath) {
|
|
if (!(root && root.isAnimationObjectGroup)) {
|
|
return new PropertyBinding(root, path, parsedPath);
|
|
} else {
|
|
return new PropertyBinding.Composite(root, path, parsedPath);
|
|
}
|
|
}
|
|
static sanitizeNodeName(name) {
|
|
return name.replace(/\s/g, "_").replace(_reservedRe, "");
|
|
}
|
|
static parseTrackName(trackName) {
|
|
const matches = _trackRe.exec(trackName);
|
|
if (matches === null) {
|
|
throw new Error("PropertyBinding: Cannot parse trackName: " + trackName);
|
|
}
|
|
const results = {
|
|
nodeName: matches[2],
|
|
objectName: matches[3],
|
|
objectIndex: matches[4],
|
|
propertyName: matches[5],
|
|
propertyIndex: matches[6]
|
|
};
|
|
const lastDot = results.nodeName && results.nodeName.lastIndexOf(".");
|
|
if (lastDot !== undefined && lastDot !== -1) {
|
|
const objectName = results.nodeName.substring(lastDot + 1);
|
|
if (_supportedObjectNames.indexOf(objectName) !== -1) {
|
|
results.nodeName = results.nodeName.substring(0, lastDot);
|
|
results.objectName = objectName;
|
|
}
|
|
}
|
|
if (results.propertyName === null || results.propertyName.length === 0) {
|
|
throw new Error("PropertyBinding: can not parse propertyName from trackName: " + trackName);
|
|
}
|
|
return results;
|
|
}
|
|
static findNode(root, nodeName) {
|
|
if (nodeName === undefined || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
|
|
return root;
|
|
}
|
|
if (root.skeleton) {
|
|
const bone = root.skeleton.getBoneByName(nodeName);
|
|
if (bone !== undefined) {
|
|
return bone;
|
|
}
|
|
}
|
|
if (root.children) {
|
|
const searchNodeSubtree = function(children) {
|
|
for (let i = 0;i < children.length; i++) {
|
|
const childNode = children[i];
|
|
if (childNode.name === nodeName || childNode.uuid === nodeName) {
|
|
return childNode;
|
|
}
|
|
const result = searchNodeSubtree(childNode.children);
|
|
if (result)
|
|
return result;
|
|
}
|
|
return null;
|
|
};
|
|
const subTreeNode = searchNodeSubtree(root.children);
|
|
if (subTreeNode) {
|
|
return subTreeNode;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
_getValue_unavailable() {}
|
|
_setValue_unavailable() {}
|
|
_getValue_direct(buffer, offset) {
|
|
buffer[offset] = this.targetObject[this.propertyName];
|
|
}
|
|
_getValue_array(buffer, offset) {
|
|
const source = this.resolvedProperty;
|
|
for (let i = 0, n = source.length;i !== n; ++i) {
|
|
buffer[offset++] = source[i];
|
|
}
|
|
}
|
|
_getValue_arrayElement(buffer, offset) {
|
|
buffer[offset] = this.resolvedProperty[this.propertyIndex];
|
|
}
|
|
_getValue_toArray(buffer, offset) {
|
|
this.resolvedProperty.toArray(buffer, offset);
|
|
}
|
|
_setValue_direct(buffer, offset) {
|
|
this.targetObject[this.propertyName] = buffer[offset];
|
|
}
|
|
_setValue_direct_setNeedsUpdate(buffer, offset) {
|
|
this.targetObject[this.propertyName] = buffer[offset];
|
|
this.targetObject.needsUpdate = true;
|
|
}
|
|
_setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
|
|
this.targetObject[this.propertyName] = buffer[offset];
|
|
this.targetObject.matrixWorldNeedsUpdate = true;
|
|
}
|
|
_setValue_array(buffer, offset) {
|
|
const dest = this.resolvedProperty;
|
|
for (let i = 0, n = dest.length;i !== n; ++i) {
|
|
dest[i] = buffer[offset++];
|
|
}
|
|
}
|
|
_setValue_array_setNeedsUpdate(buffer, offset) {
|
|
const dest = this.resolvedProperty;
|
|
for (let i = 0, n = dest.length;i !== n; ++i) {
|
|
dest[i] = buffer[offset++];
|
|
}
|
|
this.targetObject.needsUpdate = true;
|
|
}
|
|
_setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
|
|
const dest = this.resolvedProperty;
|
|
for (let i = 0, n = dest.length;i !== n; ++i) {
|
|
dest[i] = buffer[offset++];
|
|
}
|
|
this.targetObject.matrixWorldNeedsUpdate = true;
|
|
}
|
|
_setValue_arrayElement(buffer, offset) {
|
|
this.resolvedProperty[this.propertyIndex] = buffer[offset];
|
|
}
|
|
_setValue_arrayElement_setNeedsUpdate(buffer, offset) {
|
|
this.resolvedProperty[this.propertyIndex] = buffer[offset];
|
|
this.targetObject.needsUpdate = true;
|
|
}
|
|
_setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
|
|
this.resolvedProperty[this.propertyIndex] = buffer[offset];
|
|
this.targetObject.matrixWorldNeedsUpdate = true;
|
|
}
|
|
_setValue_fromArray(buffer, offset) {
|
|
this.resolvedProperty.fromArray(buffer, offset);
|
|
}
|
|
_setValue_fromArray_setNeedsUpdate(buffer, offset) {
|
|
this.resolvedProperty.fromArray(buffer, offset);
|
|
this.targetObject.needsUpdate = true;
|
|
}
|
|
_setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
|
|
this.resolvedProperty.fromArray(buffer, offset);
|
|
this.targetObject.matrixWorldNeedsUpdate = true;
|
|
}
|
|
_getValue_unbound(targetArray, offset) {
|
|
this.bind();
|
|
this.getValue(targetArray, offset);
|
|
}
|
|
_setValue_unbound(sourceArray, offset) {
|
|
this.bind();
|
|
this.setValue(sourceArray, offset);
|
|
}
|
|
bind() {
|
|
let targetObject = this.node;
|
|
const parsedPath = this.parsedPath;
|
|
const objectName = parsedPath.objectName;
|
|
const propertyName = parsedPath.propertyName;
|
|
let propertyIndex = parsedPath.propertyIndex;
|
|
if (!targetObject) {
|
|
targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName);
|
|
this.node = targetObject;
|
|
}
|
|
this.getValue = this._getValue_unavailable;
|
|
this.setValue = this._setValue_unavailable;
|
|
if (!targetObject) {
|
|
console.warn("THREE.PropertyBinding: No target node found for track: " + this.path + ".");
|
|
return;
|
|
}
|
|
if (objectName) {
|
|
let objectIndex = parsedPath.objectIndex;
|
|
switch (objectName) {
|
|
case "materials":
|
|
if (!targetObject.material) {
|
|
console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.", this);
|
|
return;
|
|
}
|
|
if (!targetObject.material.materials) {
|
|
console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.", this);
|
|
return;
|
|
}
|
|
targetObject = targetObject.material.materials;
|
|
break;
|
|
case "bones":
|
|
if (!targetObject.skeleton) {
|
|
console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.", this);
|
|
return;
|
|
}
|
|
targetObject = targetObject.skeleton.bones;
|
|
for (let i = 0;i < targetObject.length; i++) {
|
|
if (targetObject[i].name === objectIndex) {
|
|
objectIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case "map":
|
|
if ("map" in targetObject) {
|
|
targetObject = targetObject.map;
|
|
break;
|
|
}
|
|
if (!targetObject.material) {
|
|
console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.", this);
|
|
return;
|
|
}
|
|
if (!targetObject.material.map) {
|
|
console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.", this);
|
|
return;
|
|
}
|
|
targetObject = targetObject.material.map;
|
|
break;
|
|
default:
|
|
if (targetObject[objectName] === undefined) {
|
|
console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.", this);
|
|
return;
|
|
}
|
|
targetObject = targetObject[objectName];
|
|
}
|
|
if (objectIndex !== undefined) {
|
|
if (targetObject[objectIndex] === undefined) {
|
|
console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.", this, targetObject);
|
|
return;
|
|
}
|
|
targetObject = targetObject[objectIndex];
|
|
}
|
|
}
|
|
const nodeProperty = targetObject[propertyName];
|
|
if (nodeProperty === undefined) {
|
|
const nodeName = parsedPath.nodeName;
|
|
console.error("THREE.PropertyBinding: Trying to update property for track: " + nodeName + "." + propertyName + " but it wasn't found.", targetObject);
|
|
return;
|
|
}
|
|
let versioning = this.Versioning.None;
|
|
this.targetObject = targetObject;
|
|
if (targetObject.isMaterial === true) {
|
|
versioning = this.Versioning.NeedsUpdate;
|
|
} else if (targetObject.isObject3D === true) {
|
|
versioning = this.Versioning.MatrixWorldNeedsUpdate;
|
|
}
|
|
let bindingType = this.BindingType.Direct;
|
|
if (propertyIndex !== undefined) {
|
|
if (propertyName === "morphTargetInfluences") {
|
|
if (!targetObject.geometry) {
|
|
console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.", this);
|
|
return;
|
|
}
|
|
if (!targetObject.geometry.morphAttributes) {
|
|
console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.", this);
|
|
return;
|
|
}
|
|
if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
|
|
propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
|
|
}
|
|
}
|
|
bindingType = this.BindingType.ArrayElement;
|
|
this.resolvedProperty = nodeProperty;
|
|
this.propertyIndex = propertyIndex;
|
|
} else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
|
|
bindingType = this.BindingType.HasFromToArray;
|
|
this.resolvedProperty = nodeProperty;
|
|
} else if (Array.isArray(nodeProperty)) {
|
|
bindingType = this.BindingType.EntireArray;
|
|
this.resolvedProperty = nodeProperty;
|
|
} else {
|
|
this.propertyName = propertyName;
|
|
}
|
|
this.getValue = this.GetterByBindingType[bindingType];
|
|
this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
|
|
}
|
|
unbind() {
|
|
this.node = null;
|
|
this.getValue = this._getValue_unbound;
|
|
this.setValue = this._setValue_unbound;
|
|
}
|
|
}
|
|
|
|
class AnimationObjectGroup {
|
|
constructor() {
|
|
this.isAnimationObjectGroup = true;
|
|
this.uuid = generateUUID();
|
|
this._objects = Array.prototype.slice.call(arguments);
|
|
this.nCachedObjects_ = 0;
|
|
const indices = {};
|
|
this._indicesByUUID = indices;
|
|
for (let i = 0, n = arguments.length;i !== n; ++i) {
|
|
indices[arguments[i].uuid] = i;
|
|
}
|
|
this._paths = [];
|
|
this._parsedPaths = [];
|
|
this._bindings = [];
|
|
this._bindingsIndicesByPath = {};
|
|
const scope = this;
|
|
this.stats = {
|
|
objects: {
|
|
get total() {
|
|
return scope._objects.length;
|
|
},
|
|
get inUse() {
|
|
return this.total - scope.nCachedObjects_;
|
|
}
|
|
},
|
|
get bindingsPerObject() {
|
|
return scope._bindings.length;
|
|
}
|
|
};
|
|
}
|
|
add() {
|
|
const objects = this._objects, indicesByUUID = this._indicesByUUID, paths = this._paths, parsedPaths = this._parsedPaths, bindings = this._bindings, nBindings = bindings.length;
|
|
let knownObject = undefined, nObjects = objects.length, nCachedObjects = this.nCachedObjects_;
|
|
for (let i = 0, n = arguments.length;i !== n; ++i) {
|
|
const object = arguments[i], uuid = object.uuid;
|
|
let index = indicesByUUID[uuid];
|
|
if (index === undefined) {
|
|
index = nObjects++;
|
|
indicesByUUID[uuid] = index;
|
|
objects.push(object);
|
|
for (let j = 0, m = nBindings;j !== m; ++j) {
|
|
bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
|
|
}
|
|
} else if (index < nCachedObjects) {
|
|
knownObject = objects[index];
|
|
const firstActiveIndex = --nCachedObjects, lastCachedObject = objects[firstActiveIndex];
|
|
indicesByUUID[lastCachedObject.uuid] = index;
|
|
objects[index] = lastCachedObject;
|
|
indicesByUUID[uuid] = firstActiveIndex;
|
|
objects[firstActiveIndex] = object;
|
|
for (let j = 0, m = nBindings;j !== m; ++j) {
|
|
const bindingsForPath = bindings[j], lastCached = bindingsForPath[firstActiveIndex];
|
|
let binding = bindingsForPath[index];
|
|
bindingsForPath[index] = lastCached;
|
|
if (binding === undefined) {
|
|
binding = new PropertyBinding(object, paths[j], parsedPaths[j]);
|
|
}
|
|
bindingsForPath[firstActiveIndex] = binding;
|
|
}
|
|
} else if (objects[index] !== knownObject) {
|
|
console.error("THREE.AnimationObjectGroup: Different objects with the same UUID " + "detected. Clean the caches or recreate your infrastructure when reloading scenes.");
|
|
}
|
|
}
|
|
this.nCachedObjects_ = nCachedObjects;
|
|
}
|
|
remove() {
|
|
const objects = this._objects, indicesByUUID = this._indicesByUUID, bindings = this._bindings, nBindings = bindings.length;
|
|
let nCachedObjects = this.nCachedObjects_;
|
|
for (let i = 0, n = arguments.length;i !== n; ++i) {
|
|
const object = arguments[i], uuid = object.uuid, index = indicesByUUID[uuid];
|
|
if (index !== undefined && index >= nCachedObjects) {
|
|
const lastCachedIndex = nCachedObjects++, firstActiveObject = objects[lastCachedIndex];
|
|
indicesByUUID[firstActiveObject.uuid] = index;
|
|
objects[index] = firstActiveObject;
|
|
indicesByUUID[uuid] = lastCachedIndex;
|
|
objects[lastCachedIndex] = object;
|
|
for (let j = 0, m = nBindings;j !== m; ++j) {
|
|
const bindingsForPath = bindings[j], firstActive = bindingsForPath[lastCachedIndex], binding = bindingsForPath[index];
|
|
bindingsForPath[index] = firstActive;
|
|
bindingsForPath[lastCachedIndex] = binding;
|
|
}
|
|
}
|
|
}
|
|
this.nCachedObjects_ = nCachedObjects;
|
|
}
|
|
uncache() {
|
|
const objects = this._objects, indicesByUUID = this._indicesByUUID, bindings = this._bindings, nBindings = bindings.length;
|
|
let nCachedObjects = this.nCachedObjects_, nObjects = objects.length;
|
|
for (let i = 0, n = arguments.length;i !== n; ++i) {
|
|
const object = arguments[i], uuid = object.uuid, index = indicesByUUID[uuid];
|
|
if (index !== undefined) {
|
|
delete indicesByUUID[uuid];
|
|
if (index < nCachedObjects) {
|
|
const firstActiveIndex = --nCachedObjects, lastCachedObject = objects[firstActiveIndex], lastIndex = --nObjects, lastObject = objects[lastIndex];
|
|
indicesByUUID[lastCachedObject.uuid] = index;
|
|
objects[index] = lastCachedObject;
|
|
indicesByUUID[lastObject.uuid] = firstActiveIndex;
|
|
objects[firstActiveIndex] = lastObject;
|
|
objects.pop();
|
|
for (let j = 0, m = nBindings;j !== m; ++j) {
|
|
const bindingsForPath = bindings[j], lastCached = bindingsForPath[firstActiveIndex], last = bindingsForPath[lastIndex];
|
|
bindingsForPath[index] = lastCached;
|
|
bindingsForPath[firstActiveIndex] = last;
|
|
bindingsForPath.pop();
|
|
}
|
|
} else {
|
|
const lastIndex = --nObjects, lastObject = objects[lastIndex];
|
|
if (lastIndex > 0) {
|
|
indicesByUUID[lastObject.uuid] = index;
|
|
}
|
|
objects[index] = lastObject;
|
|
objects.pop();
|
|
for (let j = 0, m = nBindings;j !== m; ++j) {
|
|
const bindingsForPath = bindings[j];
|
|
bindingsForPath[index] = bindingsForPath[lastIndex];
|
|
bindingsForPath.pop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.nCachedObjects_ = nCachedObjects;
|
|
}
|
|
subscribe_(path, parsedPath) {
|
|
const indicesByPath = this._bindingsIndicesByPath;
|
|
let index = indicesByPath[path];
|
|
const bindings = this._bindings;
|
|
if (index !== undefined)
|
|
return bindings[index];
|
|
const paths = this._paths, parsedPaths = this._parsedPaths, objects = this._objects, nObjects = objects.length, nCachedObjects = this.nCachedObjects_, bindingsForPath = new Array(nObjects);
|
|
index = bindings.length;
|
|
indicesByPath[path] = index;
|
|
paths.push(path);
|
|
parsedPaths.push(parsedPath);
|
|
bindings.push(bindingsForPath);
|
|
for (let i = nCachedObjects, n = objects.length;i !== n; ++i) {
|
|
const object = objects[i];
|
|
bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
|
|
}
|
|
return bindingsForPath;
|
|
}
|
|
unsubscribe_(path) {
|
|
const indicesByPath = this._bindingsIndicesByPath, index = indicesByPath[path];
|
|
if (index !== undefined) {
|
|
const paths = this._paths, parsedPaths = this._parsedPaths, bindings = this._bindings, lastBindingsIndex = bindings.length - 1, lastBindings = bindings[lastBindingsIndex], lastBindingsPath = path[lastBindingsIndex];
|
|
indicesByPath[lastBindingsPath] = index;
|
|
bindings[index] = lastBindings;
|
|
bindings.pop();
|
|
parsedPaths[index] = parsedPaths[lastBindingsIndex];
|
|
parsedPaths.pop();
|
|
paths[index] = paths[lastBindingsIndex];
|
|
paths.pop();
|
|
}
|
|
}
|
|
}
|
|
|
|
class AnimationAction {
|
|
constructor(mixer, clip, localRoot = null, blendMode = clip.blendMode) {
|
|
this._mixer = mixer;
|
|
this._clip = clip;
|
|
this._localRoot = localRoot;
|
|
this.blendMode = blendMode;
|
|
const tracks = clip.tracks, nTracks = tracks.length, interpolants = new Array(nTracks);
|
|
const interpolantSettings = {
|
|
endingStart: ZeroCurvatureEnding,
|
|
endingEnd: ZeroCurvatureEnding
|
|
};
|
|
for (let i = 0;i !== nTracks; ++i) {
|
|
const interpolant = tracks[i].createInterpolant(null);
|
|
interpolants[i] = interpolant;
|
|
interpolant.settings = interpolantSettings;
|
|
}
|
|
this._interpolantSettings = interpolantSettings;
|
|
this._interpolants = interpolants;
|
|
this._propertyBindings = new Array(nTracks);
|
|
this._cacheIndex = null;
|
|
this._byClipCacheIndex = null;
|
|
this._timeScaleInterpolant = null;
|
|
this._weightInterpolant = null;
|
|
this.loop = LoopRepeat;
|
|
this._loopCount = -1;
|
|
this._startTime = null;
|
|
this.time = 0;
|
|
this.timeScale = 1;
|
|
this._effectiveTimeScale = 1;
|
|
this.weight = 1;
|
|
this._effectiveWeight = 1;
|
|
this.repetitions = Infinity;
|
|
this.paused = false;
|
|
this.enabled = true;
|
|
this.clampWhenFinished = false;
|
|
this.zeroSlopeAtStart = true;
|
|
this.zeroSlopeAtEnd = true;
|
|
}
|
|
play() {
|
|
this._mixer._activateAction(this);
|
|
return this;
|
|
}
|
|
stop() {
|
|
this._mixer._deactivateAction(this);
|
|
return this.reset();
|
|
}
|
|
reset() {
|
|
this.paused = false;
|
|
this.enabled = true;
|
|
this.time = 0;
|
|
this._loopCount = -1;
|
|
this._startTime = null;
|
|
return this.stopFading().stopWarping();
|
|
}
|
|
isRunning() {
|
|
return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
|
|
}
|
|
isScheduled() {
|
|
return this._mixer._isActiveAction(this);
|
|
}
|
|
startAt(time) {
|
|
this._startTime = time;
|
|
return this;
|
|
}
|
|
setLoop(mode, repetitions) {
|
|
this.loop = mode;
|
|
this.repetitions = repetitions;
|
|
return this;
|
|
}
|
|
setEffectiveWeight(weight) {
|
|
this.weight = weight;
|
|
this._effectiveWeight = this.enabled ? weight : 0;
|
|
return this.stopFading();
|
|
}
|
|
getEffectiveWeight() {
|
|
return this._effectiveWeight;
|
|
}
|
|
fadeIn(duration) {
|
|
return this._scheduleFading(duration, 0, 1);
|
|
}
|
|
fadeOut(duration) {
|
|
return this._scheduleFading(duration, 1, 0);
|
|
}
|
|
crossFadeFrom(fadeOutAction, duration, warp) {
|
|
fadeOutAction.fadeOut(duration);
|
|
this.fadeIn(duration);
|
|
if (warp) {
|
|
const fadeInDuration = this._clip.duration, fadeOutDuration = fadeOutAction._clip.duration, startEndRatio = fadeOutDuration / fadeInDuration, endStartRatio = fadeInDuration / fadeOutDuration;
|
|
fadeOutAction.warp(1, startEndRatio, duration);
|
|
this.warp(endStartRatio, 1, duration);
|
|
}
|
|
return this;
|
|
}
|
|
crossFadeTo(fadeInAction, duration, warp) {
|
|
return fadeInAction.crossFadeFrom(this, duration, warp);
|
|
}
|
|
stopFading() {
|
|
const weightInterpolant = this._weightInterpolant;
|
|
if (weightInterpolant !== null) {
|
|
this._weightInterpolant = null;
|
|
this._mixer._takeBackControlInterpolant(weightInterpolant);
|
|
}
|
|
return this;
|
|
}
|
|
setEffectiveTimeScale(timeScale) {
|
|
this.timeScale = timeScale;
|
|
this._effectiveTimeScale = this.paused ? 0 : timeScale;
|
|
return this.stopWarping();
|
|
}
|
|
getEffectiveTimeScale() {
|
|
return this._effectiveTimeScale;
|
|
}
|
|
setDuration(duration) {
|
|
this.timeScale = this._clip.duration / duration;
|
|
return this.stopWarping();
|
|
}
|
|
syncWith(action) {
|
|
this.time = action.time;
|
|
this.timeScale = action.timeScale;
|
|
return this.stopWarping();
|
|
}
|
|
halt(duration) {
|
|
return this.warp(this._effectiveTimeScale, 0, duration);
|
|
}
|
|
warp(startTimeScale, endTimeScale, duration) {
|
|
const mixer = this._mixer, now2 = mixer.time, timeScale = this.timeScale;
|
|
let interpolant = this._timeScaleInterpolant;
|
|
if (interpolant === null) {
|
|
interpolant = mixer._lendControlInterpolant();
|
|
this._timeScaleInterpolant = interpolant;
|
|
}
|
|
const { parameterPositions: times, sampleValues: values } = interpolant;
|
|
times[0] = now2;
|
|
times[1] = now2 + duration;
|
|
values[0] = startTimeScale / timeScale;
|
|
values[1] = endTimeScale / timeScale;
|
|
return this;
|
|
}
|
|
stopWarping() {
|
|
const timeScaleInterpolant = this._timeScaleInterpolant;
|
|
if (timeScaleInterpolant !== null) {
|
|
this._timeScaleInterpolant = null;
|
|
this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
|
|
}
|
|
return this;
|
|
}
|
|
getMixer() {
|
|
return this._mixer;
|
|
}
|
|
getClip() {
|
|
return this._clip;
|
|
}
|
|
getRoot() {
|
|
return this._localRoot || this._mixer._root;
|
|
}
|
|
_update(time, deltaTime, timeDirection, accuIndex) {
|
|
if (!this.enabled) {
|
|
this._updateWeight(time);
|
|
return;
|
|
}
|
|
const startTime = this._startTime;
|
|
if (startTime !== null) {
|
|
const timeRunning = (time - startTime) * timeDirection;
|
|
if (timeRunning < 0 || timeDirection === 0) {
|
|
deltaTime = 0;
|
|
} else {
|
|
this._startTime = null;
|
|
deltaTime = timeDirection * timeRunning;
|
|
}
|
|
}
|
|
deltaTime *= this._updateTimeScale(time);
|
|
const clipTime = this._updateTime(deltaTime);
|
|
const weight = this._updateWeight(time);
|
|
if (weight > 0) {
|
|
const interpolants = this._interpolants;
|
|
const propertyMixers = this._propertyBindings;
|
|
switch (this.blendMode) {
|
|
case AdditiveAnimationBlendMode:
|
|
for (let j = 0, m = interpolants.length;j !== m; ++j) {
|
|
interpolants[j].evaluate(clipTime);
|
|
propertyMixers[j].accumulateAdditive(weight);
|
|
}
|
|
break;
|
|
case NormalAnimationBlendMode:
|
|
default:
|
|
for (let j = 0, m = interpolants.length;j !== m; ++j) {
|
|
interpolants[j].evaluate(clipTime);
|
|
propertyMixers[j].accumulate(accuIndex, weight);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_updateWeight(time) {
|
|
let weight = 0;
|
|
if (this.enabled) {
|
|
weight = this.weight;
|
|
const interpolant = this._weightInterpolant;
|
|
if (interpolant !== null) {
|
|
const interpolantValue = interpolant.evaluate(time)[0];
|
|
weight *= interpolantValue;
|
|
if (time > interpolant.parameterPositions[1]) {
|
|
this.stopFading();
|
|
if (interpolantValue === 0) {
|
|
this.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this._effectiveWeight = weight;
|
|
return weight;
|
|
}
|
|
_updateTimeScale(time) {
|
|
let timeScale = 0;
|
|
if (!this.paused) {
|
|
timeScale = this.timeScale;
|
|
const interpolant = this._timeScaleInterpolant;
|
|
if (interpolant !== null) {
|
|
const interpolantValue = interpolant.evaluate(time)[0];
|
|
timeScale *= interpolantValue;
|
|
if (time > interpolant.parameterPositions[1]) {
|
|
this.stopWarping();
|
|
if (timeScale === 0) {
|
|
this.paused = true;
|
|
} else {
|
|
this.timeScale = timeScale;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this._effectiveTimeScale = timeScale;
|
|
return timeScale;
|
|
}
|
|
_updateTime(deltaTime) {
|
|
const duration = this._clip.duration;
|
|
const loop = this.loop;
|
|
let time = this.time + deltaTime;
|
|
let loopCount = this._loopCount;
|
|
const pingPong = loop === LoopPingPong;
|
|
if (deltaTime === 0) {
|
|
if (loopCount === -1)
|
|
return time;
|
|
return pingPong && (loopCount & 1) === 1 ? duration - time : time;
|
|
}
|
|
if (loop === LoopOnce) {
|
|
if (loopCount === -1) {
|
|
this._loopCount = 0;
|
|
this._setEndings(true, true, false);
|
|
}
|
|
handle_stop: {
|
|
if (time >= duration) {
|
|
time = duration;
|
|
} else if (time < 0) {
|
|
time = 0;
|
|
} else {
|
|
this.time = time;
|
|
break handle_stop;
|
|
}
|
|
if (this.clampWhenFinished)
|
|
this.paused = true;
|
|
else
|
|
this.enabled = false;
|
|
this.time = time;
|
|
this._mixer.dispatchEvent({
|
|
type: "finished",
|
|
action: this,
|
|
direction: deltaTime < 0 ? -1 : 1
|
|
});
|
|
}
|
|
} else {
|
|
if (loopCount === -1) {
|
|
if (deltaTime >= 0) {
|
|
loopCount = 0;
|
|
this._setEndings(true, this.repetitions === 0, pingPong);
|
|
} else {
|
|
this._setEndings(this.repetitions === 0, true, pingPong);
|
|
}
|
|
}
|
|
if (time >= duration || time < 0) {
|
|
const loopDelta = Math.floor(time / duration);
|
|
time -= duration * loopDelta;
|
|
loopCount += Math.abs(loopDelta);
|
|
const pending = this.repetitions - loopCount;
|
|
if (pending <= 0) {
|
|
if (this.clampWhenFinished)
|
|
this.paused = true;
|
|
else
|
|
this.enabled = false;
|
|
time = deltaTime > 0 ? duration : 0;
|
|
this.time = time;
|
|
this._mixer.dispatchEvent({
|
|
type: "finished",
|
|
action: this,
|
|
direction: deltaTime > 0 ? 1 : -1
|
|
});
|
|
} else {
|
|
if (pending === 1) {
|
|
const atStart = deltaTime < 0;
|
|
this._setEndings(atStart, !atStart, pingPong);
|
|
} else {
|
|
this._setEndings(false, false, pingPong);
|
|
}
|
|
this._loopCount = loopCount;
|
|
this.time = time;
|
|
this._mixer.dispatchEvent({
|
|
type: "loop",
|
|
action: this,
|
|
loopDelta
|
|
});
|
|
}
|
|
} else {
|
|
this.time = time;
|
|
}
|
|
if (pingPong && (loopCount & 1) === 1) {
|
|
return duration - time;
|
|
}
|
|
}
|
|
return time;
|
|
}
|
|
_setEndings(atStart, atEnd, pingPong) {
|
|
const settings = this._interpolantSettings;
|
|
if (pingPong) {
|
|
settings.endingStart = ZeroSlopeEnding;
|
|
settings.endingEnd = ZeroSlopeEnding;
|
|
} else {
|
|
if (atStart) {
|
|
settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
|
|
} else {
|
|
settings.endingStart = WrapAroundEnding;
|
|
}
|
|
if (atEnd) {
|
|
settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
|
|
} else {
|
|
settings.endingEnd = WrapAroundEnding;
|
|
}
|
|
}
|
|
}
|
|
_scheduleFading(duration, weightNow, weightThen) {
|
|
const mixer = this._mixer, now2 = mixer.time;
|
|
let interpolant = this._weightInterpolant;
|
|
if (interpolant === null) {
|
|
interpolant = mixer._lendControlInterpolant();
|
|
this._weightInterpolant = interpolant;
|
|
}
|
|
const { parameterPositions: times, sampleValues: values } = interpolant;
|
|
times[0] = now2;
|
|
values[0] = weightNow;
|
|
times[1] = now2 + duration;
|
|
values[1] = weightThen;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
class Uniform {
|
|
constructor(value) {
|
|
this.value = value;
|
|
}
|
|
clone() {
|
|
return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
|
|
}
|
|
}
|
|
|
|
class GLBufferAttribute {
|
|
constructor(buffer, type, itemSize, elementSize, count) {
|
|
this.isGLBufferAttribute = true;
|
|
this.name = "";
|
|
this.buffer = buffer;
|
|
this.type = type;
|
|
this.itemSize = itemSize;
|
|
this.elementSize = elementSize;
|
|
this.count = count;
|
|
this.version = 0;
|
|
}
|
|
set needsUpdate(value) {
|
|
if (value === true)
|
|
this.version++;
|
|
}
|
|
setBuffer(buffer) {
|
|
this.buffer = buffer;
|
|
return this;
|
|
}
|
|
setType(type, elementSize) {
|
|
this.type = type;
|
|
this.elementSize = elementSize;
|
|
return this;
|
|
}
|
|
setItemSize(itemSize) {
|
|
this.itemSize = itemSize;
|
|
return this;
|
|
}
|
|
setCount(count) {
|
|
this.count = count;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
class Raycaster {
|
|
constructor(origin, direction, near = 0, far = Infinity) {
|
|
this.ray = new Ray(origin, direction);
|
|
this.near = near;
|
|
this.far = far;
|
|
this.camera = null;
|
|
this.layers = new Layers;
|
|
this.params = {
|
|
Mesh: {},
|
|
Line: { threshold: 1 },
|
|
LOD: {},
|
|
Points: { threshold: 1 },
|
|
Sprite: {}
|
|
};
|
|
}
|
|
set(origin, direction) {
|
|
this.ray.set(origin, direction);
|
|
}
|
|
setFromCamera(coords, camera) {
|
|
if (camera.isPerspectiveCamera) {
|
|
this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
|
|
this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
|
|
this.camera = camera;
|
|
} else if (camera.isOrthographicCamera) {
|
|
this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera);
|
|
this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
|
|
this.camera = camera;
|
|
} else {
|
|
console.error("THREE.Raycaster: Unsupported camera type: " + camera.type);
|
|
}
|
|
}
|
|
setFromXRController(controller) {
|
|
_matrix.identity().extractRotation(controller.matrixWorld);
|
|
this.ray.origin.setFromMatrixPosition(controller.matrixWorld);
|
|
this.ray.direction.set(0, 0, -1).applyMatrix4(_matrix);
|
|
return this;
|
|
}
|
|
intersectObject(object, recursive = true, intersects2 = []) {
|
|
intersect(object, this, intersects2, recursive);
|
|
intersects2.sort(ascSort);
|
|
return intersects2;
|
|
}
|
|
intersectObjects(objects, recursive = true, intersects2 = []) {
|
|
for (let i = 0, l = objects.length;i < l; i++) {
|
|
intersect(objects[i], this, intersects2, recursive);
|
|
}
|
|
intersects2.sort(ascSort);
|
|
return intersects2;
|
|
}
|
|
}
|
|
function ascSort(a, b) {
|
|
return a.distance - b.distance;
|
|
}
|
|
function intersect(object, raycaster, intersects2, recursive) {
|
|
let propagate = true;
|
|
if (object.layers.test(raycaster.layers)) {
|
|
const result = object.raycast(raycaster, intersects2);
|
|
if (result === false)
|
|
propagate = false;
|
|
}
|
|
if (propagate === true && recursive === true) {
|
|
const children = object.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
intersect(children[i], raycaster, intersects2, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
class Spherical {
|
|
constructor(radius = 1, phi = 0, theta = 0) {
|
|
this.radius = radius;
|
|
this.phi = phi;
|
|
this.theta = theta;
|
|
return this;
|
|
}
|
|
set(radius, phi, theta) {
|
|
this.radius = radius;
|
|
this.phi = phi;
|
|
this.theta = theta;
|
|
return this;
|
|
}
|
|
copy(other) {
|
|
this.radius = other.radius;
|
|
this.phi = other.phi;
|
|
this.theta = other.theta;
|
|
return this;
|
|
}
|
|
makeSafe() {
|
|
const EPS = 0.000001;
|
|
this.phi = clamp(this.phi, EPS, Math.PI - EPS);
|
|
return this;
|
|
}
|
|
setFromVector3(v) {
|
|
return this.setFromCartesianCoords(v.x, v.y, v.z);
|
|
}
|
|
setFromCartesianCoords(x, y, z) {
|
|
this.radius = Math.sqrt(x * x + y * y + z * z);
|
|
if (this.radius === 0) {
|
|
this.theta = 0;
|
|
this.phi = 0;
|
|
} else {
|
|
this.theta = Math.atan2(x, z);
|
|
this.phi = Math.acos(clamp(y / this.radius, -1, 1));
|
|
}
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
}
|
|
|
|
class Cylindrical {
|
|
constructor(radius = 1, theta = 0, y = 0) {
|
|
this.radius = radius;
|
|
this.theta = theta;
|
|
this.y = y;
|
|
return this;
|
|
}
|
|
set(radius, theta, y) {
|
|
this.radius = radius;
|
|
this.theta = theta;
|
|
this.y = y;
|
|
return this;
|
|
}
|
|
copy(other) {
|
|
this.radius = other.radius;
|
|
this.theta = other.theta;
|
|
this.y = other.y;
|
|
return this;
|
|
}
|
|
setFromVector3(v) {
|
|
return this.setFromCartesianCoords(v.x, v.y, v.z);
|
|
}
|
|
setFromCartesianCoords(x, y, z) {
|
|
this.radius = Math.sqrt(x * x + z * z);
|
|
this.theta = Math.atan2(x, z);
|
|
this.y = y;
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
}
|
|
|
|
class Matrix2 {
|
|
constructor(n11, n12, n21, n22) {
|
|
Matrix2.prototype.isMatrix2 = true;
|
|
this.elements = [
|
|
1,
|
|
0,
|
|
0,
|
|
1
|
|
];
|
|
if (n11 !== undefined) {
|
|
this.set(n11, n12, n21, n22);
|
|
}
|
|
}
|
|
identity() {
|
|
this.set(1, 0, 0, 1);
|
|
return this;
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
for (let i = 0;i < 4; i++) {
|
|
this.elements[i] = array[i + offset];
|
|
}
|
|
return this;
|
|
}
|
|
set(n11, n12, n21, n22) {
|
|
const te = this.elements;
|
|
te[0] = n11;
|
|
te[2] = n12;
|
|
te[1] = n21;
|
|
te[3] = n22;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
class Box2 {
|
|
constructor(min = new Vector2(Infinity, Infinity), max = new Vector2(-Infinity, -Infinity)) {
|
|
this.isBox2 = true;
|
|
this.min = min;
|
|
this.max = max;
|
|
}
|
|
set(min, max) {
|
|
this.min.copy(min);
|
|
this.max.copy(max);
|
|
return this;
|
|
}
|
|
setFromPoints(points) {
|
|
this.makeEmpty();
|
|
for (let i = 0, il = points.length;i < il; i++) {
|
|
this.expandByPoint(points[i]);
|
|
}
|
|
return this;
|
|
}
|
|
setFromCenterAndSize(center, size) {
|
|
const halfSize = _vector$4.copy(size).multiplyScalar(0.5);
|
|
this.min.copy(center).sub(halfSize);
|
|
this.max.copy(center).add(halfSize);
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
copy(box) {
|
|
this.min.copy(box.min);
|
|
this.max.copy(box.max);
|
|
return this;
|
|
}
|
|
makeEmpty() {
|
|
this.min.x = this.min.y = Infinity;
|
|
this.max.x = this.max.y = -Infinity;
|
|
return this;
|
|
}
|
|
isEmpty() {
|
|
return this.max.x < this.min.x || this.max.y < this.min.y;
|
|
}
|
|
getCenter(target) {
|
|
return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
|
|
}
|
|
getSize(target) {
|
|
return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
|
|
}
|
|
expandByPoint(point) {
|
|
this.min.min(point);
|
|
this.max.max(point);
|
|
return this;
|
|
}
|
|
expandByVector(vector) {
|
|
this.min.sub(vector);
|
|
this.max.add(vector);
|
|
return this;
|
|
}
|
|
expandByScalar(scalar) {
|
|
this.min.addScalar(-scalar);
|
|
this.max.addScalar(scalar);
|
|
return this;
|
|
}
|
|
containsPoint(point) {
|
|
return point.x >= this.min.x && point.x <= this.max.x && point.y >= this.min.y && point.y <= this.max.y;
|
|
}
|
|
containsBox(box) {
|
|
return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y;
|
|
}
|
|
getParameter(point, target) {
|
|
return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y));
|
|
}
|
|
intersectsBox(box) {
|
|
return box.max.x >= this.min.x && box.min.x <= this.max.x && box.max.y >= this.min.y && box.min.y <= this.max.y;
|
|
}
|
|
clampPoint(point, target) {
|
|
return target.copy(point).clamp(this.min, this.max);
|
|
}
|
|
distanceToPoint(point) {
|
|
return this.clampPoint(point, _vector$4).distanceTo(point);
|
|
}
|
|
intersect(box) {
|
|
this.min.max(box.min);
|
|
this.max.min(box.max);
|
|
if (this.isEmpty())
|
|
this.makeEmpty();
|
|
return this;
|
|
}
|
|
union(box) {
|
|
this.min.min(box.min);
|
|
this.max.max(box.max);
|
|
return this;
|
|
}
|
|
translate(offset) {
|
|
this.min.add(offset);
|
|
this.max.add(offset);
|
|
return this;
|
|
}
|
|
equals(box) {
|
|
return box.min.equals(this.min) && box.max.equals(this.max);
|
|
}
|
|
}
|
|
|
|
class Line3 {
|
|
constructor(start = new Vector3, end = new Vector3) {
|
|
this.start = start;
|
|
this.end = end;
|
|
}
|
|
set(start, end) {
|
|
this.start.copy(start);
|
|
this.end.copy(end);
|
|
return this;
|
|
}
|
|
copy(line) {
|
|
this.start.copy(line.start);
|
|
this.end.copy(line.end);
|
|
return this;
|
|
}
|
|
getCenter(target) {
|
|
return target.addVectors(this.start, this.end).multiplyScalar(0.5);
|
|
}
|
|
delta(target) {
|
|
return target.subVectors(this.end, this.start);
|
|
}
|
|
distanceSq() {
|
|
return this.start.distanceToSquared(this.end);
|
|
}
|
|
distance() {
|
|
return this.start.distanceTo(this.end);
|
|
}
|
|
at(t, target) {
|
|
return this.delta(target).multiplyScalar(t).add(this.start);
|
|
}
|
|
closestPointToPointParameter(point, clampToLine) {
|
|
_startP.subVectors(point, this.start);
|
|
_startEnd.subVectors(this.end, this.start);
|
|
const startEnd2 = _startEnd.dot(_startEnd);
|
|
const startEnd_startP = _startEnd.dot(_startP);
|
|
let t = startEnd_startP / startEnd2;
|
|
if (clampToLine) {
|
|
t = clamp(t, 0, 1);
|
|
}
|
|
return t;
|
|
}
|
|
closestPointToPoint(point, clampToLine, target) {
|
|
const t = this.closestPointToPointParameter(point, clampToLine);
|
|
return this.delta(target).multiplyScalar(t).add(this.start);
|
|
}
|
|
applyMatrix4(matrix) {
|
|
this.start.applyMatrix4(matrix);
|
|
this.end.applyMatrix4(matrix);
|
|
return this;
|
|
}
|
|
equals(line) {
|
|
return line.start.equals(this.start) && line.end.equals(this.end);
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
}
|
|
function getBoneList(object) {
|
|
const boneList = [];
|
|
if (object.isBone === true) {
|
|
boneList.push(object);
|
|
}
|
|
for (let i = 0;i < object.children.length; i++) {
|
|
boneList.push.apply(boneList, getBoneList(object.children[i]));
|
|
}
|
|
return boneList;
|
|
}
|
|
function setPoint(point, pointMap, geometry, camera, x, y, z) {
|
|
_vector.set(x, y, z).unproject(camera);
|
|
const points = pointMap[point];
|
|
if (points !== undefined) {
|
|
const position = geometry.getAttribute("position");
|
|
for (let i = 0, l = points.length;i < l; i++) {
|
|
position.setXYZ(points[i], _vector.x, _vector.y, _vector.z);
|
|
}
|
|
}
|
|
}
|
|
|
|
class ShapePath {
|
|
constructor() {
|
|
this.type = "ShapePath";
|
|
this.color = new Color;
|
|
this.subPaths = [];
|
|
this.currentPath = null;
|
|
}
|
|
moveTo(x, y) {
|
|
this.currentPath = new Path;
|
|
this.subPaths.push(this.currentPath);
|
|
this.currentPath.moveTo(x, y);
|
|
return this;
|
|
}
|
|
lineTo(x, y) {
|
|
this.currentPath.lineTo(x, y);
|
|
return this;
|
|
}
|
|
quadraticCurveTo(aCPx, aCPy, aX, aY) {
|
|
this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
|
|
return this;
|
|
}
|
|
bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
|
|
this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
|
|
return this;
|
|
}
|
|
splineThru(pts) {
|
|
this.currentPath.splineThru(pts);
|
|
return this;
|
|
}
|
|
toShapes(isCCW) {
|
|
function toShapesNoHoles(inSubpaths) {
|
|
const shapes2 = [];
|
|
for (let i = 0, l = inSubpaths.length;i < l; i++) {
|
|
const tmpPath2 = inSubpaths[i];
|
|
const tmpShape2 = new Shape;
|
|
tmpShape2.curves = tmpPath2.curves;
|
|
shapes2.push(tmpShape2);
|
|
}
|
|
return shapes2;
|
|
}
|
|
function isPointInsidePolygon(inPt, inPolygon) {
|
|
const polyLen = inPolygon.length;
|
|
let inside = false;
|
|
for (let p = polyLen - 1, q = 0;q < polyLen; p = q++) {
|
|
let edgeLowPt = inPolygon[p];
|
|
let edgeHighPt = inPolygon[q];
|
|
let edgeDx = edgeHighPt.x - edgeLowPt.x;
|
|
let edgeDy = edgeHighPt.y - edgeLowPt.y;
|
|
if (Math.abs(edgeDy) > Number.EPSILON) {
|
|
if (edgeDy < 0) {
|
|
edgeLowPt = inPolygon[q];
|
|
edgeDx = -edgeDx;
|
|
edgeHighPt = inPolygon[p];
|
|
edgeDy = -edgeDy;
|
|
}
|
|
if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y)
|
|
continue;
|
|
if (inPt.y === edgeLowPt.y) {
|
|
if (inPt.x === edgeLowPt.x)
|
|
return true;
|
|
} else {
|
|
const perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
|
|
if (perpEdge === 0)
|
|
return true;
|
|
if (perpEdge < 0)
|
|
continue;
|
|
inside = !inside;
|
|
}
|
|
} else {
|
|
if (inPt.y !== edgeLowPt.y)
|
|
continue;
|
|
if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x)
|
|
return true;
|
|
}
|
|
}
|
|
return inside;
|
|
}
|
|
const isClockWise = ShapeUtils.isClockWise;
|
|
const subPaths = this.subPaths;
|
|
if (subPaths.length === 0)
|
|
return [];
|
|
let solid, tmpPath, tmpShape;
|
|
const shapes = [];
|
|
if (subPaths.length === 1) {
|
|
tmpPath = subPaths[0];
|
|
tmpShape = new Shape;
|
|
tmpShape.curves = tmpPath.curves;
|
|
shapes.push(tmpShape);
|
|
return shapes;
|
|
}
|
|
let holesFirst = !isClockWise(subPaths[0].getPoints());
|
|
holesFirst = isCCW ? !holesFirst : holesFirst;
|
|
const betterShapeHoles = [];
|
|
const newShapes = [];
|
|
let newShapeHoles = [];
|
|
let mainIdx = 0;
|
|
let tmpPoints;
|
|
newShapes[mainIdx] = undefined;
|
|
newShapeHoles[mainIdx] = [];
|
|
for (let i = 0, l = subPaths.length;i < l; i++) {
|
|
tmpPath = subPaths[i];
|
|
tmpPoints = tmpPath.getPoints();
|
|
solid = isClockWise(tmpPoints);
|
|
solid = isCCW ? !solid : solid;
|
|
if (solid) {
|
|
if (!holesFirst && newShapes[mainIdx])
|
|
mainIdx++;
|
|
newShapes[mainIdx] = { s: new Shape, p: tmpPoints };
|
|
newShapes[mainIdx].s.curves = tmpPath.curves;
|
|
if (holesFirst)
|
|
mainIdx++;
|
|
newShapeHoles[mainIdx] = [];
|
|
} else {
|
|
newShapeHoles[mainIdx].push({ h: tmpPath, p: tmpPoints[0] });
|
|
}
|
|
}
|
|
if (!newShapes[0])
|
|
return toShapesNoHoles(subPaths);
|
|
if (newShapes.length > 1) {
|
|
let ambiguous = false;
|
|
let toChange = 0;
|
|
for (let sIdx = 0, sLen = newShapes.length;sIdx < sLen; sIdx++) {
|
|
betterShapeHoles[sIdx] = [];
|
|
}
|
|
for (let sIdx = 0, sLen = newShapes.length;sIdx < sLen; sIdx++) {
|
|
const sho = newShapeHoles[sIdx];
|
|
for (let hIdx = 0;hIdx < sho.length; hIdx++) {
|
|
const ho = sho[hIdx];
|
|
let hole_unassigned = true;
|
|
for (let s2Idx = 0;s2Idx < newShapes.length; s2Idx++) {
|
|
if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
|
|
if (sIdx !== s2Idx)
|
|
toChange++;
|
|
if (hole_unassigned) {
|
|
hole_unassigned = false;
|
|
betterShapeHoles[s2Idx].push(ho);
|
|
} else {
|
|
ambiguous = true;
|
|
}
|
|
}
|
|
}
|
|
if (hole_unassigned) {
|
|
betterShapeHoles[sIdx].push(ho);
|
|
}
|
|
}
|
|
}
|
|
if (toChange > 0 && ambiguous === false) {
|
|
newShapeHoles = betterShapeHoles;
|
|
}
|
|
}
|
|
let tmpHoles;
|
|
for (let i = 0, il = newShapes.length;i < il; i++) {
|
|
tmpShape = newShapes[i].s;
|
|
shapes.push(tmpShape);
|
|
tmpHoles = newShapeHoles[i];
|
|
for (let j = 0, jl = tmpHoles.length;j < jl; j++) {
|
|
tmpShape.holes.push(tmpHoles[j].h);
|
|
}
|
|
}
|
|
return shapes;
|
|
}
|
|
}
|
|
function contain(texture, aspect2) {
|
|
const imageAspect = texture.image && texture.image.width ? texture.image.width / texture.image.height : 1;
|
|
if (imageAspect > aspect2) {
|
|
texture.repeat.x = 1;
|
|
texture.repeat.y = imageAspect / aspect2;
|
|
texture.offset.x = 0;
|
|
texture.offset.y = (1 - texture.repeat.y) / 2;
|
|
} else {
|
|
texture.repeat.x = aspect2 / imageAspect;
|
|
texture.repeat.y = 1;
|
|
texture.offset.x = (1 - texture.repeat.x) / 2;
|
|
texture.offset.y = 0;
|
|
}
|
|
return texture;
|
|
}
|
|
function cover(texture, aspect2) {
|
|
const imageAspect = texture.image && texture.image.width ? texture.image.width / texture.image.height : 1;
|
|
if (imageAspect > aspect2) {
|
|
texture.repeat.x = aspect2 / imageAspect;
|
|
texture.repeat.y = 1;
|
|
texture.offset.x = (1 - texture.repeat.x) / 2;
|
|
texture.offset.y = 0;
|
|
} else {
|
|
texture.repeat.x = 1;
|
|
texture.repeat.y = imageAspect / aspect2;
|
|
texture.offset.x = 0;
|
|
texture.offset.y = (1 - texture.repeat.y) / 2;
|
|
}
|
|
return texture;
|
|
}
|
|
function fill(texture) {
|
|
texture.repeat.x = 1;
|
|
texture.repeat.y = 1;
|
|
texture.offset.x = 0;
|
|
texture.offset.y = 0;
|
|
return texture;
|
|
}
|
|
function getByteLength(width, height, format, type) {
|
|
const typeByteLength = getTextureTypeByteLength(type);
|
|
switch (format) {
|
|
case AlphaFormat:
|
|
return width * height;
|
|
case LuminanceFormat:
|
|
return width * height;
|
|
case LuminanceAlphaFormat:
|
|
return width * height * 2;
|
|
case RedFormat:
|
|
return width * height / typeByteLength.components * typeByteLength.byteLength;
|
|
case RedIntegerFormat:
|
|
return width * height / typeByteLength.components * typeByteLength.byteLength;
|
|
case RGFormat:
|
|
return width * height * 2 / typeByteLength.components * typeByteLength.byteLength;
|
|
case RGIntegerFormat:
|
|
return width * height * 2 / typeByteLength.components * typeByteLength.byteLength;
|
|
case RGBFormat:
|
|
return width * height * 3 / typeByteLength.components * typeByteLength.byteLength;
|
|
case RGBAFormat:
|
|
return width * height * 4 / typeByteLength.components * typeByteLength.byteLength;
|
|
case RGBAIntegerFormat:
|
|
return width * height * 4 / typeByteLength.components * typeByteLength.byteLength;
|
|
case RGB_S3TC_DXT1_Format:
|
|
case RGBA_S3TC_DXT1_Format:
|
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
|
|
case RGBA_S3TC_DXT3_Format:
|
|
case RGBA_S3TC_DXT5_Format:
|
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
|
|
case RGB_PVRTC_2BPPV1_Format:
|
|
case RGBA_PVRTC_2BPPV1_Format:
|
|
return Math.max(width, 16) * Math.max(height, 8) / 4;
|
|
case RGB_PVRTC_4BPPV1_Format:
|
|
case RGBA_PVRTC_4BPPV1_Format:
|
|
return Math.max(width, 8) * Math.max(height, 8) / 2;
|
|
case RGB_ETC1_Format:
|
|
case RGB_ETC2_Format:
|
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
|
|
case RGBA_ETC2_EAC_Format:
|
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
|
|
case RGBA_ASTC_4x4_Format:
|
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
|
|
case RGBA_ASTC_5x4_Format:
|
|
return Math.floor((width + 4) / 5) * Math.floor((height + 3) / 4) * 16;
|
|
case RGBA_ASTC_5x5_Format:
|
|
return Math.floor((width + 4) / 5) * Math.floor((height + 4) / 5) * 16;
|
|
case RGBA_ASTC_6x5_Format:
|
|
return Math.floor((width + 5) / 6) * Math.floor((height + 4) / 5) * 16;
|
|
case RGBA_ASTC_6x6_Format:
|
|
return Math.floor((width + 5) / 6) * Math.floor((height + 5) / 6) * 16;
|
|
case RGBA_ASTC_8x5_Format:
|
|
return Math.floor((width + 7) / 8) * Math.floor((height + 4) / 5) * 16;
|
|
case RGBA_ASTC_8x6_Format:
|
|
return Math.floor((width + 7) / 8) * Math.floor((height + 5) / 6) * 16;
|
|
case RGBA_ASTC_8x8_Format:
|
|
return Math.floor((width + 7) / 8) * Math.floor((height + 7) / 8) * 16;
|
|
case RGBA_ASTC_10x5_Format:
|
|
return Math.floor((width + 9) / 10) * Math.floor((height + 4) / 5) * 16;
|
|
case RGBA_ASTC_10x6_Format:
|
|
return Math.floor((width + 9) / 10) * Math.floor((height + 5) / 6) * 16;
|
|
case RGBA_ASTC_10x8_Format:
|
|
return Math.floor((width + 9) / 10) * Math.floor((height + 7) / 8) * 16;
|
|
case RGBA_ASTC_10x10_Format:
|
|
return Math.floor((width + 9) / 10) * Math.floor((height + 9) / 10) * 16;
|
|
case RGBA_ASTC_12x10_Format:
|
|
return Math.floor((width + 11) / 12) * Math.floor((height + 9) / 10) * 16;
|
|
case RGBA_ASTC_12x12_Format:
|
|
return Math.floor((width + 11) / 12) * Math.floor((height + 11) / 12) * 16;
|
|
case RGBA_BPTC_Format:
|
|
case RGB_BPTC_SIGNED_Format:
|
|
case RGB_BPTC_UNSIGNED_Format:
|
|
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16;
|
|
case RED_RGTC1_Format:
|
|
case SIGNED_RED_RGTC1_Format:
|
|
return Math.ceil(width / 4) * Math.ceil(height / 4) * 8;
|
|
case RED_GREEN_RGTC2_Format:
|
|
case SIGNED_RED_GREEN_RGTC2_Format:
|
|
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16;
|
|
}
|
|
throw new Error(`Unable to determine texture byte length for ${format} format.`);
|
|
}
|
|
function getTextureTypeByteLength(type) {
|
|
switch (type) {
|
|
case UnsignedByteType:
|
|
case ByteType:
|
|
return { byteLength: 1, components: 1 };
|
|
case UnsignedShortType:
|
|
case ShortType:
|
|
case HalfFloatType:
|
|
return { byteLength: 2, components: 1 };
|
|
case UnsignedShort4444Type:
|
|
case UnsignedShort5551Type:
|
|
return { byteLength: 2, components: 4 };
|
|
case UnsignedIntType:
|
|
case IntType:
|
|
case FloatType:
|
|
return { byteLength: 4, components: 1 };
|
|
case UnsignedInt5999Type:
|
|
return { byteLength: 4, components: 3 };
|
|
}
|
|
throw new Error(`Unknown texture type ${type}.`);
|
|
}
|
|
var REVISION = "173", MOUSE, TOUCH, CullFaceNone = 0, CullFaceBack = 1, CullFaceFront = 2, CullFaceFrontBack = 3, BasicShadowMap = 0, PCFShadowMap = 1, PCFSoftShadowMap = 2, VSMShadowMap = 3, FrontSide = 0, BackSide = 1, DoubleSide = 2, NoBlending = 0, NormalBlending = 1, AdditiveBlending = 2, SubtractiveBlending = 3, MultiplyBlending = 4, CustomBlending = 5, AddEquation = 100, SubtractEquation = 101, ReverseSubtractEquation = 102, MinEquation = 103, MaxEquation = 104, ZeroFactor = 200, OneFactor = 201, SrcColorFactor = 202, OneMinusSrcColorFactor = 203, SrcAlphaFactor = 204, OneMinusSrcAlphaFactor = 205, DstAlphaFactor = 206, OneMinusDstAlphaFactor = 207, DstColorFactor = 208, OneMinusDstColorFactor = 209, SrcAlphaSaturateFactor = 210, ConstantColorFactor = 211, OneMinusConstantColorFactor = 212, ConstantAlphaFactor = 213, OneMinusConstantAlphaFactor = 214, NeverDepth = 0, AlwaysDepth = 1, LessDepth = 2, LessEqualDepth = 3, EqualDepth = 4, GreaterEqualDepth = 5, GreaterDepth = 6, NotEqualDepth = 7, MultiplyOperation = 0, MixOperation = 1, AddOperation = 2, NoToneMapping = 0, LinearToneMapping = 1, ReinhardToneMapping = 2, CineonToneMapping = 3, ACESFilmicToneMapping = 4, CustomToneMapping = 5, AgXToneMapping = 6, NeutralToneMapping = 7, AttachedBindMode = "attached", DetachedBindMode = "detached", UVMapping = 300, CubeReflectionMapping = 301, CubeRefractionMapping = 302, EquirectangularReflectionMapping = 303, EquirectangularRefractionMapping = 304, CubeUVReflectionMapping = 306, RepeatWrapping = 1000, ClampToEdgeWrapping = 1001, MirroredRepeatWrapping = 1002, NearestFilter = 1003, NearestMipmapNearestFilter = 1004, NearestMipMapNearestFilter = 1004, NearestMipmapLinearFilter = 1005, NearestMipMapLinearFilter = 1005, LinearFilter = 1006, LinearMipmapNearestFilter = 1007, LinearMipMapNearestFilter = 1007, LinearMipmapLinearFilter = 1008, LinearMipMapLinearFilter = 1008, UnsignedByteType = 1009, ByteType = 1010, ShortType = 1011, UnsignedShortType = 1012, IntType = 1013, UnsignedIntType = 1014, FloatType = 1015, HalfFloatType = 1016, UnsignedShort4444Type = 1017, UnsignedShort5551Type = 1018, UnsignedInt248Type = 1020, UnsignedInt5999Type = 35902, AlphaFormat = 1021, RGBFormat = 1022, RGBAFormat = 1023, LuminanceFormat = 1024, LuminanceAlphaFormat = 1025, DepthFormat = 1026, DepthStencilFormat = 1027, RedFormat = 1028, RedIntegerFormat = 1029, RGFormat = 1030, RGIntegerFormat = 1031, RGBIntegerFormat = 1032, RGBAIntegerFormat = 1033, RGB_S3TC_DXT1_Format = 33776, RGBA_S3TC_DXT1_Format = 33777, RGBA_S3TC_DXT3_Format = 33778, RGBA_S3TC_DXT5_Format = 33779, RGB_PVRTC_4BPPV1_Format = 35840, RGB_PVRTC_2BPPV1_Format = 35841, RGBA_PVRTC_4BPPV1_Format = 35842, RGBA_PVRTC_2BPPV1_Format = 35843, RGB_ETC1_Format = 36196, RGB_ETC2_Format = 37492, RGBA_ETC2_EAC_Format = 37496, RGBA_ASTC_4x4_Format = 37808, RGBA_ASTC_5x4_Format = 37809, RGBA_ASTC_5x5_Format = 37810, RGBA_ASTC_6x5_Format = 37811, RGBA_ASTC_6x6_Format = 37812, RGBA_ASTC_8x5_Format = 37813, RGBA_ASTC_8x6_Format = 37814, RGBA_ASTC_8x8_Format = 37815, RGBA_ASTC_10x5_Format = 37816, RGBA_ASTC_10x6_Format = 37817, RGBA_ASTC_10x8_Format = 37818, RGBA_ASTC_10x10_Format = 37819, RGBA_ASTC_12x10_Format = 37820, RGBA_ASTC_12x12_Format = 37821, RGBA_BPTC_Format = 36492, RGB_BPTC_SIGNED_Format = 36494, RGB_BPTC_UNSIGNED_Format = 36495, RED_RGTC1_Format = 36283, SIGNED_RED_RGTC1_Format = 36284, RED_GREEN_RGTC2_Format = 36285, SIGNED_RED_GREEN_RGTC2_Format = 36286, LoopOnce = 2200, LoopRepeat = 2201, LoopPingPong = 2202, InterpolateDiscrete = 2300, InterpolateLinear = 2301, InterpolateSmooth = 2302, ZeroCurvatureEnding = 2400, ZeroSlopeEnding = 2401, WrapAroundEnding = 2402, NormalAnimationBlendMode = 2500, AdditiveAnimationBlendMode = 2501, TrianglesDrawMode = 0, TriangleStripDrawMode = 1, TriangleFanDrawMode = 2, BasicDepthPacking = 3200, RGBADepthPacking = 3201, RGBDepthPacking = 3202, RGDepthPacking = 3203, TangentSpaceNormalMap = 0, ObjectSpaceNormalMap = 1, NoColorSpace = "", SRGBColorSpace = "srgb", LinearSRGBColorSpace = "srgb-linear", LinearTransfer = "linear", SRGBTransfer = "srgb", ZeroStencilOp = 0, KeepStencilOp = 7680, ReplaceStencilOp = 7681, IncrementStencilOp = 7682, DecrementStencilOp = 7683, IncrementWrapStencilOp = 34055, DecrementWrapStencilOp = 34056, InvertStencilOp = 5386, NeverStencilFunc = 512, LessStencilFunc = 513, EqualStencilFunc = 514, LessEqualStencilFunc = 515, GreaterStencilFunc = 516, NotEqualStencilFunc = 517, GreaterEqualStencilFunc = 518, AlwaysStencilFunc = 519, NeverCompare = 512, LessCompare = 513, EqualCompare = 514, LessEqualCompare = 515, GreaterCompare = 516, NotEqualCompare = 517, GreaterEqualCompare = 518, AlwaysCompare = 519, StaticDrawUsage = 35044, DynamicDrawUsage = 35048, StreamDrawUsage = 35040, StaticReadUsage = 35045, DynamicReadUsage = 35049, StreamReadUsage = 35041, StaticCopyUsage = 35046, DynamicCopyUsage = 35050, StreamCopyUsage = 35042, GLSL1 = "100", GLSL3 = "300 es", WebGLCoordinateSystem = 2000, WebGPUCoordinateSystem = 2001, TimestampQuery, _lut, _seed = 1234567, DEG2RAD, RAD2DEG, MathUtils, Vector2, _m3, TYPED_ARRAYS, _cache, LINEAR_REC709_TO_XYZ, XYZ_TO_LINEAR_REC709, ColorManagement, _canvas, _sourceId = 0, _textureId = 0, Texture, Vector4, RenderTarget, WebGLRenderTarget, DataArrayTexture, WebGLArrayRenderTarget, Data3DTexture, WebGL3DRenderTarget, Quaternion, Vector3, _vector$c, _quaternion$4, _points, _vector$b, _box$4, _v0$2, _v1$7, _v2$4, _f0, _f1, _f2, _center, _extents, _triangleNormal, _testAxis, _box$3, _v1$6, _v2$3, _vector$a, _segCenter, _segDir, _diff, _edge1, _edge2, _normal$1, _v1$5, _m1$2, _zero, _one, _x, _y, _z, _matrix$2, _quaternion$3, Euler, _object3DId = 0, _v1$4, _q1, _m1$1, _target, _position$3, _scale$2, _quaternion$2, _xAxis, _yAxis, _zAxis, _addedEvent, _removedEvent, _childaddedEvent, _childremovedEvent, Object3D, _v0$1, _v1$3, _v2$2, _v3$2, _vab, _vac, _vbc, _vap, _vbp, _vcp, _v40, _v41, _v42, _colorKeywords, _hslA, _hslB, Color, _color, _materialId = 0, Material, MeshBasicMaterial, _tables, DataUtils, _vector$9, _vector2$1, _id$2 = 0, Int8BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Int16BufferAttribute, Uint16BufferAttribute, Int32BufferAttribute, Uint32BufferAttribute, Float16BufferAttribute, Float32BufferAttribute, _id$1 = 0, _m1, _obj, _offset, _box$2, _boxMorphTargets, _vector$8, BufferGeometry, _inverseMatrix$3, _ray$3, _sphere$6, _sphereHitAt, _vA$1, _vB$1, _vC$1, _tempA, _morphA, _intersectionPoint, _intersectionPointWorld, Mesh, BoxGeometry, UniformsUtils, default_vertex = `void main() {
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
}`, default_fragment = `void main() {
|
|
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
|
|
}`, ShaderMaterial, Camera, _v3$1, _minTarget, _maxTarget, PerspectiveCamera, fov = -90, aspect = 1, CubeCamera, CubeTexture, WebGLCubeRenderTarget, Group, _moveEvent, Scene, _vector$7, SpriteMaterial, _geometry, _intersectPoint, _worldScale, _mvPosition, _alignedPosition, _rotatedPosition, _viewWorldMatrix, _vA, _vB, _vC, _uvA, _uvB, _uvC, Sprite, _v1$2, _v2$1, LOD, _basePosition, _skinIndex, _skinWeight, _vector3, _matrix4, _vertex, _sphere$5, _inverseMatrix$2, _ray$2, SkinnedMesh, Bone, DataTexture, _offsetMatrix, _identityMatrix, InstancedBufferAttribute, _instanceLocalMatrix, _instanceWorldMatrix, _instanceIntersects, _box3, _identity, _mesh$1, _sphere$4, InstancedMesh, _vector1, _vector2, _normalMatrix, _sphere$3, _vector$6, _matrix$1, _whiteColor, _frustum, _box$1, _sphere$2, _vector$5, _forward, _temp, _renderList, _mesh, _batchIntersects, BatchedMesh, LineBasicMaterial, _vStart, _vEnd, _inverseMatrix$1, _ray$1, _sphere$1, _intersectPointOnRay, _intersectPointOnSegment, Line, _start, _end, LineSegments, LineLoop, PointsMaterial, _inverseMatrix, _ray, _sphere, _position$2, Points, VideoTexture, VideoFrameTexture, FramebufferTexture, CompressedTexture, CompressedArrayTexture, CompressedCubeTexture, CanvasTexture, DepthTexture, EllipseCurve, ArcCurve, tmp, px, py, pz, CatmullRomCurve3, CubicBezierCurve, CubicBezierCurve3, LineCurve, LineCurve3, QuadraticBezierCurve, QuadraticBezierCurve3, SplineCurve, Curves, CurvePath, Path, LatheGeometry, CapsuleGeometry, CircleGeometry, CylinderGeometry, ConeGeometry, PolyhedronGeometry, DodecahedronGeometry, _v0, _v1$1, _normal, _triangle, EdgesGeometry, Shape, Earcut, ExtrudeGeometry, WorldUVGenerator, IcosahedronGeometry, OctahedronGeometry, PlaneGeometry, RingGeometry, ShapeGeometry, SphereGeometry, TetrahedronGeometry, TorusGeometry, TorusKnotGeometry, TubeGeometry, WireframeGeometry, Geometries, ShadowMaterial, RawShaderMaterial, MeshStandardMaterial, MeshPhysicalMaterial, MeshPhongMaterial, MeshToonMaterial, MeshNormalMaterial, MeshLambertMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshMatcapMaterial, LineDashedMaterial, AnimationUtils, CubicInterpolant, LinearInterpolant, DiscreteInterpolant, BooleanKeyframeTrack, ColorKeyframeTrack, NumberKeyframeTrack, QuaternionLinearInterpolant, QuaternionKeyframeTrack, StringKeyframeTrack, VectorKeyframeTrack, Cache, DefaultLoadingManager, loading, HttpError, FileLoader, AnimationLoader, CompressedTextureLoader, ImageLoader, CubeTextureLoader, DataTextureLoader, TextureLoader, Light, HemisphereLight, _projScreenMatrix$1, _lightPositionWorld$1, _lookTarget$1, SpotLightShadow, SpotLight, _projScreenMatrix, _lightPositionWorld, _lookTarget, PointLightShadow, PointLight, OrthographicCamera, DirectionalLightShadow, DirectionalLight, AmbientLight, RectAreaLight, LightProbe, MaterialLoader, InstancedBufferGeometry, BufferGeometryLoader, ObjectLoader, TEXTURE_MAPPING, TEXTURE_WRAPPING, TEXTURE_FILTER, ImageBitmapLoader, _context, AudioLoader, _eyeRight, _eyeLeft, _projectionMatrix, ArrayCamera, _position$1, _quaternion$1, _scale$1, _orientation$1, AudioListener, Audio, _position, _quaternion, _scale, _orientation, PositionalAudio, _RESERVED_CHARS_RE = "\\[\\]\\.:\\/", _reservedRe, _wordChar, _wordCharOrDot, _directoryRe, _nodeRe, _objectRe, _propertyRe, _trackRe, _supportedObjectNames, _controlInterpolantsResultBuffer, AnimationMixer, RenderTarget3D, RenderTargetArray, _id = 0, UniformsGroup, InstancedInterleavedBuffer, _matrix, _vector$4, _startP, _startEnd, _vector$3, SpotLightHelper, _vector$2, _boneMatrix, _matrixWorldInv, SkeletonHelper, PointLightHelper, _vector$1, _color1, _color2, HemisphereLightHelper, GridHelper, PolarGridHelper, _v1, _v2, _v3, DirectionalLightHelper, _vector, _camera, CameraHelper, _box, BoxHelper, Box3Helper, PlaneHelper, _axis, _lineGeometry, _coneGeometry, ArrowHelper, AxesHelper, Controls, TextureUtils;
|
|
var init_three_core = __esm(() => {
|
|
MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
|
|
TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
|
|
TimestampQuery = {
|
|
COMPUTE: "compute",
|
|
RENDER: "render"
|
|
};
|
|
_lut = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
|
|
DEG2RAD = Math.PI / 180;
|
|
RAD2DEG = 180 / Math.PI;
|
|
MathUtils = {
|
|
DEG2RAD,
|
|
RAD2DEG,
|
|
generateUUID,
|
|
clamp,
|
|
euclideanModulo,
|
|
mapLinear,
|
|
inverseLerp,
|
|
lerp,
|
|
damp,
|
|
pingpong,
|
|
smoothstep,
|
|
smootherstep,
|
|
randInt,
|
|
randFloat,
|
|
randFloatSpread,
|
|
seededRandom,
|
|
degToRad,
|
|
radToDeg,
|
|
isPowerOfTwo,
|
|
ceilPowerOfTwo,
|
|
floorPowerOfTwo,
|
|
setQuaternionFromProperEuler,
|
|
normalize,
|
|
denormalize
|
|
};
|
|
Vector2 = class Vector2 {
|
|
constructor(x = 0, y = 0) {
|
|
Vector2.prototype.isVector2 = true;
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
get width() {
|
|
return this.x;
|
|
}
|
|
set width(value) {
|
|
this.x = value;
|
|
}
|
|
get height() {
|
|
return this.y;
|
|
}
|
|
set height(value) {
|
|
this.y = value;
|
|
}
|
|
set(x, y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
return this;
|
|
}
|
|
setScalar(scalar) {
|
|
this.x = scalar;
|
|
this.y = scalar;
|
|
return this;
|
|
}
|
|
setX(x) {
|
|
this.x = x;
|
|
return this;
|
|
}
|
|
setY(y) {
|
|
this.y = y;
|
|
return this;
|
|
}
|
|
setComponent(index, value) {
|
|
switch (index) {
|
|
case 0:
|
|
this.x = value;
|
|
break;
|
|
case 1:
|
|
this.y = value;
|
|
break;
|
|
default:
|
|
throw new Error("index is out of range: " + index);
|
|
}
|
|
return this;
|
|
}
|
|
getComponent(index) {
|
|
switch (index) {
|
|
case 0:
|
|
return this.x;
|
|
case 1:
|
|
return this.y;
|
|
default:
|
|
throw new Error("index is out of range: " + index);
|
|
}
|
|
}
|
|
clone() {
|
|
return new this.constructor(this.x, this.y);
|
|
}
|
|
copy(v) {
|
|
this.x = v.x;
|
|
this.y = v.y;
|
|
return this;
|
|
}
|
|
add(v) {
|
|
this.x += v.x;
|
|
this.y += v.y;
|
|
return this;
|
|
}
|
|
addScalar(s) {
|
|
this.x += s;
|
|
this.y += s;
|
|
return this;
|
|
}
|
|
addVectors(a, b) {
|
|
this.x = a.x + b.x;
|
|
this.y = a.y + b.y;
|
|
return this;
|
|
}
|
|
addScaledVector(v, s) {
|
|
this.x += v.x * s;
|
|
this.y += v.y * s;
|
|
return this;
|
|
}
|
|
sub(v) {
|
|
this.x -= v.x;
|
|
this.y -= v.y;
|
|
return this;
|
|
}
|
|
subScalar(s) {
|
|
this.x -= s;
|
|
this.y -= s;
|
|
return this;
|
|
}
|
|
subVectors(a, b) {
|
|
this.x = a.x - b.x;
|
|
this.y = a.y - b.y;
|
|
return this;
|
|
}
|
|
multiply(v) {
|
|
this.x *= v.x;
|
|
this.y *= v.y;
|
|
return this;
|
|
}
|
|
multiplyScalar(scalar) {
|
|
this.x *= scalar;
|
|
this.y *= scalar;
|
|
return this;
|
|
}
|
|
divide(v) {
|
|
this.x /= v.x;
|
|
this.y /= v.y;
|
|
return this;
|
|
}
|
|
divideScalar(scalar) {
|
|
return this.multiplyScalar(1 / scalar);
|
|
}
|
|
applyMatrix3(m) {
|
|
const x = this.x, y = this.y;
|
|
const e = m.elements;
|
|
this.x = e[0] * x + e[3] * y + e[6];
|
|
this.y = e[1] * x + e[4] * y + e[7];
|
|
return this;
|
|
}
|
|
min(v) {
|
|
this.x = Math.min(this.x, v.x);
|
|
this.y = Math.min(this.y, v.y);
|
|
return this;
|
|
}
|
|
max(v) {
|
|
this.x = Math.max(this.x, v.x);
|
|
this.y = Math.max(this.y, v.y);
|
|
return this;
|
|
}
|
|
clamp(min, max) {
|
|
this.x = clamp(this.x, min.x, max.x);
|
|
this.y = clamp(this.y, min.y, max.y);
|
|
return this;
|
|
}
|
|
clampScalar(minVal, maxVal) {
|
|
this.x = clamp(this.x, minVal, maxVal);
|
|
this.y = clamp(this.y, minVal, maxVal);
|
|
return this;
|
|
}
|
|
clampLength(min, max) {
|
|
const length = this.length();
|
|
return this.divideScalar(length || 1).multiplyScalar(clamp(length, min, max));
|
|
}
|
|
floor() {
|
|
this.x = Math.floor(this.x);
|
|
this.y = Math.floor(this.y);
|
|
return this;
|
|
}
|
|
ceil() {
|
|
this.x = Math.ceil(this.x);
|
|
this.y = Math.ceil(this.y);
|
|
return this;
|
|
}
|
|
round() {
|
|
this.x = Math.round(this.x);
|
|
this.y = Math.round(this.y);
|
|
return this;
|
|
}
|
|
roundToZero() {
|
|
this.x = Math.trunc(this.x);
|
|
this.y = Math.trunc(this.y);
|
|
return this;
|
|
}
|
|
negate() {
|
|
this.x = -this.x;
|
|
this.y = -this.y;
|
|
return this;
|
|
}
|
|
dot(v) {
|
|
return this.x * v.x + this.y * v.y;
|
|
}
|
|
cross(v) {
|
|
return this.x * v.y - this.y * v.x;
|
|
}
|
|
lengthSq() {
|
|
return this.x * this.x + this.y * this.y;
|
|
}
|
|
length() {
|
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
}
|
|
manhattanLength() {
|
|
return Math.abs(this.x) + Math.abs(this.y);
|
|
}
|
|
normalize() {
|
|
return this.divideScalar(this.length() || 1);
|
|
}
|
|
angle() {
|
|
const angle = Math.atan2(-this.y, -this.x) + Math.PI;
|
|
return angle;
|
|
}
|
|
angleTo(v) {
|
|
const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
|
|
if (denominator === 0)
|
|
return Math.PI / 2;
|
|
const theta = this.dot(v) / denominator;
|
|
return Math.acos(clamp(theta, -1, 1));
|
|
}
|
|
distanceTo(v) {
|
|
return Math.sqrt(this.distanceToSquared(v));
|
|
}
|
|
distanceToSquared(v) {
|
|
const dx = this.x - v.x, dy = this.y - v.y;
|
|
return dx * dx + dy * dy;
|
|
}
|
|
manhattanDistanceTo(v) {
|
|
return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
|
|
}
|
|
setLength(length) {
|
|
return this.normalize().multiplyScalar(length);
|
|
}
|
|
lerp(v, alpha) {
|
|
this.x += (v.x - this.x) * alpha;
|
|
this.y += (v.y - this.y) * alpha;
|
|
return this;
|
|
}
|
|
lerpVectors(v1, v2, alpha) {
|
|
this.x = v1.x + (v2.x - v1.x) * alpha;
|
|
this.y = v1.y + (v2.y - v1.y) * alpha;
|
|
return this;
|
|
}
|
|
equals(v) {
|
|
return v.x === this.x && v.y === this.y;
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
this.x = array[offset];
|
|
this.y = array[offset + 1];
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
array[offset] = this.x;
|
|
array[offset + 1] = this.y;
|
|
return array;
|
|
}
|
|
fromBufferAttribute(attribute, index) {
|
|
this.x = attribute.getX(index);
|
|
this.y = attribute.getY(index);
|
|
return this;
|
|
}
|
|
rotateAround(center, angle) {
|
|
const c = Math.cos(angle), s = Math.sin(angle);
|
|
const x = this.x - center.x;
|
|
const y = this.y - center.y;
|
|
this.x = x * c - y * s + center.x;
|
|
this.y = x * s + y * c + center.y;
|
|
return this;
|
|
}
|
|
random() {
|
|
this.x = Math.random();
|
|
this.y = Math.random();
|
|
return this;
|
|
}
|
|
*[Symbol.iterator]() {
|
|
yield this.x;
|
|
yield this.y;
|
|
}
|
|
};
|
|
_m3 = /* @__PURE__ */ new Matrix3;
|
|
TYPED_ARRAYS = {
|
|
Int8Array,
|
|
Uint8Array,
|
|
Uint8ClampedArray,
|
|
Int16Array,
|
|
Uint16Array,
|
|
Int32Array,
|
|
Uint32Array,
|
|
Float32Array,
|
|
Float64Array
|
|
};
|
|
_cache = {};
|
|
LINEAR_REC709_TO_XYZ = /* @__PURE__ */ new Matrix3().set(0.4123908, 0.3575843, 0.1804808, 0.212639, 0.7151687, 0.0721923, 0.0193308, 0.1191948, 0.9505322);
|
|
XYZ_TO_LINEAR_REC709 = /* @__PURE__ */ new Matrix3().set(3.2409699, -1.5373832, -0.4986108, -0.9692436, 1.8759675, 0.0415551, 0.0556301, -0.203977, 1.0569715);
|
|
ColorManagement = /* @__PURE__ */ createColorManagement();
|
|
Texture = class Texture extends EventDispatcher {
|
|
constructor(image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace) {
|
|
super();
|
|
this.isTexture = true;
|
|
Object.defineProperty(this, "id", { value: _textureId++ });
|
|
this.uuid = generateUUID();
|
|
this.name = "";
|
|
this.source = new Source(image);
|
|
this.mipmaps = [];
|
|
this.mapping = mapping;
|
|
this.channel = 0;
|
|
this.wrapS = wrapS;
|
|
this.wrapT = wrapT;
|
|
this.magFilter = magFilter;
|
|
this.minFilter = minFilter;
|
|
this.anisotropy = anisotropy;
|
|
this.format = format;
|
|
this.internalFormat = null;
|
|
this.type = type;
|
|
this.offset = new Vector2(0, 0);
|
|
this.repeat = new Vector2(1, 1);
|
|
this.center = new Vector2(0, 0);
|
|
this.rotation = 0;
|
|
this.matrixAutoUpdate = true;
|
|
this.matrix = new Matrix3;
|
|
this.generateMipmaps = true;
|
|
this.premultiplyAlpha = false;
|
|
this.flipY = true;
|
|
this.unpackAlignment = 4;
|
|
this.colorSpace = colorSpace;
|
|
this.userData = {};
|
|
this.version = 0;
|
|
this.onUpdate = null;
|
|
this.renderTarget = null;
|
|
this.isRenderTargetTexture = false;
|
|
this.pmremVersion = 0;
|
|
}
|
|
get image() {
|
|
return this.source.data;
|
|
}
|
|
set image(value = null) {
|
|
this.source.data = value;
|
|
}
|
|
updateMatrix() {
|
|
this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
copy(source) {
|
|
this.name = source.name;
|
|
this.source = source.source;
|
|
this.mipmaps = source.mipmaps.slice(0);
|
|
this.mapping = source.mapping;
|
|
this.channel = source.channel;
|
|
this.wrapS = source.wrapS;
|
|
this.wrapT = source.wrapT;
|
|
this.magFilter = source.magFilter;
|
|
this.minFilter = source.minFilter;
|
|
this.anisotropy = source.anisotropy;
|
|
this.format = source.format;
|
|
this.internalFormat = source.internalFormat;
|
|
this.type = source.type;
|
|
this.offset.copy(source.offset);
|
|
this.repeat.copy(source.repeat);
|
|
this.center.copy(source.center);
|
|
this.rotation = source.rotation;
|
|
this.matrixAutoUpdate = source.matrixAutoUpdate;
|
|
this.matrix.copy(source.matrix);
|
|
this.generateMipmaps = source.generateMipmaps;
|
|
this.premultiplyAlpha = source.premultiplyAlpha;
|
|
this.flipY = source.flipY;
|
|
this.unpackAlignment = source.unpackAlignment;
|
|
this.colorSpace = source.colorSpace;
|
|
this.renderTarget = source.renderTarget;
|
|
this.isRenderTargetTexture = source.isRenderTargetTexture;
|
|
this.userData = JSON.parse(JSON.stringify(source.userData));
|
|
this.needsUpdate = true;
|
|
return this;
|
|
}
|
|
toJSON(meta) {
|
|
const isRootObject = meta === undefined || typeof meta === "string";
|
|
if (!isRootObject && meta.textures[this.uuid] !== undefined) {
|
|
return meta.textures[this.uuid];
|
|
}
|
|
const output = {
|
|
metadata: {
|
|
version: 4.6,
|
|
type: "Texture",
|
|
generator: "Texture.toJSON"
|
|
},
|
|
uuid: this.uuid,
|
|
name: this.name,
|
|
image: this.source.toJSON(meta).uuid,
|
|
mapping: this.mapping,
|
|
channel: this.channel,
|
|
repeat: [this.repeat.x, this.repeat.y],
|
|
offset: [this.offset.x, this.offset.y],
|
|
center: [this.center.x, this.center.y],
|
|
rotation: this.rotation,
|
|
wrap: [this.wrapS, this.wrapT],
|
|
format: this.format,
|
|
internalFormat: this.internalFormat,
|
|
type: this.type,
|
|
colorSpace: this.colorSpace,
|
|
minFilter: this.minFilter,
|
|
magFilter: this.magFilter,
|
|
anisotropy: this.anisotropy,
|
|
flipY: this.flipY,
|
|
generateMipmaps: this.generateMipmaps,
|
|
premultiplyAlpha: this.premultiplyAlpha,
|
|
unpackAlignment: this.unpackAlignment
|
|
};
|
|
if (Object.keys(this.userData).length > 0)
|
|
output.userData = this.userData;
|
|
if (!isRootObject) {
|
|
meta.textures[this.uuid] = output;
|
|
}
|
|
return output;
|
|
}
|
|
dispose() {
|
|
this.dispatchEvent({ type: "dispose" });
|
|
}
|
|
transformUv(uv) {
|
|
if (this.mapping !== UVMapping)
|
|
return uv;
|
|
uv.applyMatrix3(this.matrix);
|
|
if (uv.x < 0 || uv.x > 1) {
|
|
switch (this.wrapS) {
|
|
case RepeatWrapping:
|
|
uv.x = uv.x - Math.floor(uv.x);
|
|
break;
|
|
case ClampToEdgeWrapping:
|
|
uv.x = uv.x < 0 ? 0 : 1;
|
|
break;
|
|
case MirroredRepeatWrapping:
|
|
if (Math.abs(Math.floor(uv.x) % 2) === 1) {
|
|
uv.x = Math.ceil(uv.x) - uv.x;
|
|
} else {
|
|
uv.x = uv.x - Math.floor(uv.x);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (uv.y < 0 || uv.y > 1) {
|
|
switch (this.wrapT) {
|
|
case RepeatWrapping:
|
|
uv.y = uv.y - Math.floor(uv.y);
|
|
break;
|
|
case ClampToEdgeWrapping:
|
|
uv.y = uv.y < 0 ? 0 : 1;
|
|
break;
|
|
case MirroredRepeatWrapping:
|
|
if (Math.abs(Math.floor(uv.y) % 2) === 1) {
|
|
uv.y = Math.ceil(uv.y) - uv.y;
|
|
} else {
|
|
uv.y = uv.y - Math.floor(uv.y);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (this.flipY) {
|
|
uv.y = 1 - uv.y;
|
|
}
|
|
return uv;
|
|
}
|
|
set needsUpdate(value) {
|
|
if (value === true) {
|
|
this.version++;
|
|
this.source.needsUpdate = true;
|
|
}
|
|
}
|
|
set needsPMREMUpdate(value) {
|
|
if (value === true) {
|
|
this.pmremVersion++;
|
|
}
|
|
}
|
|
};
|
|
Texture.DEFAULT_IMAGE = null;
|
|
Texture.DEFAULT_MAPPING = UVMapping;
|
|
Texture.DEFAULT_ANISOTROPY = 1;
|
|
Vector4 = class Vector4 {
|
|
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
Vector4.prototype.isVector4 = true;
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
this.w = w;
|
|
}
|
|
get width() {
|
|
return this.z;
|
|
}
|
|
set width(value) {
|
|
this.z = value;
|
|
}
|
|
get height() {
|
|
return this.w;
|
|
}
|
|
set height(value) {
|
|
this.w = value;
|
|
}
|
|
set(x, y, z, w) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
this.w = w;
|
|
return this;
|
|
}
|
|
setScalar(scalar) {
|
|
this.x = scalar;
|
|
this.y = scalar;
|
|
this.z = scalar;
|
|
this.w = scalar;
|
|
return this;
|
|
}
|
|
setX(x) {
|
|
this.x = x;
|
|
return this;
|
|
}
|
|
setY(y) {
|
|
this.y = y;
|
|
return this;
|
|
}
|
|
setZ(z) {
|
|
this.z = z;
|
|
return this;
|
|
}
|
|
setW(w) {
|
|
this.w = w;
|
|
return this;
|
|
}
|
|
setComponent(index, value) {
|
|
switch (index) {
|
|
case 0:
|
|
this.x = value;
|
|
break;
|
|
case 1:
|
|
this.y = value;
|
|
break;
|
|
case 2:
|
|
this.z = value;
|
|
break;
|
|
case 3:
|
|
this.w = value;
|
|
break;
|
|
default:
|
|
throw new Error("index is out of range: " + index);
|
|
}
|
|
return this;
|
|
}
|
|
getComponent(index) {
|
|
switch (index) {
|
|
case 0:
|
|
return this.x;
|
|
case 1:
|
|
return this.y;
|
|
case 2:
|
|
return this.z;
|
|
case 3:
|
|
return this.w;
|
|
default:
|
|
throw new Error("index is out of range: " + index);
|
|
}
|
|
}
|
|
clone() {
|
|
return new this.constructor(this.x, this.y, this.z, this.w);
|
|
}
|
|
copy(v) {
|
|
this.x = v.x;
|
|
this.y = v.y;
|
|
this.z = v.z;
|
|
this.w = v.w !== undefined ? v.w : 1;
|
|
return this;
|
|
}
|
|
add(v) {
|
|
this.x += v.x;
|
|
this.y += v.y;
|
|
this.z += v.z;
|
|
this.w += v.w;
|
|
return this;
|
|
}
|
|
addScalar(s) {
|
|
this.x += s;
|
|
this.y += s;
|
|
this.z += s;
|
|
this.w += s;
|
|
return this;
|
|
}
|
|
addVectors(a, b) {
|
|
this.x = a.x + b.x;
|
|
this.y = a.y + b.y;
|
|
this.z = a.z + b.z;
|
|
this.w = a.w + b.w;
|
|
return this;
|
|
}
|
|
addScaledVector(v, s) {
|
|
this.x += v.x * s;
|
|
this.y += v.y * s;
|
|
this.z += v.z * s;
|
|
this.w += v.w * s;
|
|
return this;
|
|
}
|
|
sub(v) {
|
|
this.x -= v.x;
|
|
this.y -= v.y;
|
|
this.z -= v.z;
|
|
this.w -= v.w;
|
|
return this;
|
|
}
|
|
subScalar(s) {
|
|
this.x -= s;
|
|
this.y -= s;
|
|
this.z -= s;
|
|
this.w -= s;
|
|
return this;
|
|
}
|
|
subVectors(a, b) {
|
|
this.x = a.x - b.x;
|
|
this.y = a.y - b.y;
|
|
this.z = a.z - b.z;
|
|
this.w = a.w - b.w;
|
|
return this;
|
|
}
|
|
multiply(v) {
|
|
this.x *= v.x;
|
|
this.y *= v.y;
|
|
this.z *= v.z;
|
|
this.w *= v.w;
|
|
return this;
|
|
}
|
|
multiplyScalar(scalar) {
|
|
this.x *= scalar;
|
|
this.y *= scalar;
|
|
this.z *= scalar;
|
|
this.w *= scalar;
|
|
return this;
|
|
}
|
|
applyMatrix4(m) {
|
|
const x = this.x, y = this.y, z = this.z, w = this.w;
|
|
const e = m.elements;
|
|
this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
|
|
this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
|
|
this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
|
|
this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
|
|
return this;
|
|
}
|
|
divide(v) {
|
|
this.x /= v.x;
|
|
this.y /= v.y;
|
|
this.z /= v.z;
|
|
this.w /= v.w;
|
|
return this;
|
|
}
|
|
divideScalar(scalar) {
|
|
return this.multiplyScalar(1 / scalar);
|
|
}
|
|
setAxisAngleFromQuaternion(q) {
|
|
this.w = 2 * Math.acos(q.w);
|
|
const s = Math.sqrt(1 - q.w * q.w);
|
|
if (s < 0.0001) {
|
|
this.x = 1;
|
|
this.y = 0;
|
|
this.z = 0;
|
|
} else {
|
|
this.x = q.x / s;
|
|
this.y = q.y / s;
|
|
this.z = q.z / s;
|
|
}
|
|
return this;
|
|
}
|
|
setAxisAngleFromRotationMatrix(m) {
|
|
let angle, x, y, z;
|
|
const epsilon = 0.01, epsilon2 = 0.1, te = m.elements, m11 = te[0], m12 = te[4], m13 = te[8], m21 = te[1], m22 = te[5], m23 = te[9], m31 = te[2], m32 = te[6], m33 = te[10];
|
|
if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
|
|
if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
|
|
this.set(1, 0, 0, 0);
|
|
return this;
|
|
}
|
|
angle = Math.PI;
|
|
const xx = (m11 + 1) / 2;
|
|
const yy = (m22 + 1) / 2;
|
|
const zz = (m33 + 1) / 2;
|
|
const xy = (m12 + m21) / 4;
|
|
const xz = (m13 + m31) / 4;
|
|
const yz = (m23 + m32) / 4;
|
|
if (xx > yy && xx > zz) {
|
|
if (xx < epsilon) {
|
|
x = 0;
|
|
y = 0.707106781;
|
|
z = 0.707106781;
|
|
} else {
|
|
x = Math.sqrt(xx);
|
|
y = xy / x;
|
|
z = xz / x;
|
|
}
|
|
} else if (yy > zz) {
|
|
if (yy < epsilon) {
|
|
x = 0.707106781;
|
|
y = 0;
|
|
z = 0.707106781;
|
|
} else {
|
|
y = Math.sqrt(yy);
|
|
x = xy / y;
|
|
z = yz / y;
|
|
}
|
|
} else {
|
|
if (zz < epsilon) {
|
|
x = 0.707106781;
|
|
y = 0.707106781;
|
|
z = 0;
|
|
} else {
|
|
z = Math.sqrt(zz);
|
|
x = xz / z;
|
|
y = yz / z;
|
|
}
|
|
}
|
|
this.set(x, y, z, angle);
|
|
return this;
|
|
}
|
|
let s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12));
|
|
if (Math.abs(s) < 0.001)
|
|
s = 1;
|
|
this.x = (m32 - m23) / s;
|
|
this.y = (m13 - m31) / s;
|
|
this.z = (m21 - m12) / s;
|
|
this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
|
|
return this;
|
|
}
|
|
setFromMatrixPosition(m) {
|
|
const e = m.elements;
|
|
this.x = e[12];
|
|
this.y = e[13];
|
|
this.z = e[14];
|
|
this.w = e[15];
|
|
return this;
|
|
}
|
|
min(v) {
|
|
this.x = Math.min(this.x, v.x);
|
|
this.y = Math.min(this.y, v.y);
|
|
this.z = Math.min(this.z, v.z);
|
|
this.w = Math.min(this.w, v.w);
|
|
return this;
|
|
}
|
|
max(v) {
|
|
this.x = Math.max(this.x, v.x);
|
|
this.y = Math.max(this.y, v.y);
|
|
this.z = Math.max(this.z, v.z);
|
|
this.w = Math.max(this.w, v.w);
|
|
return this;
|
|
}
|
|
clamp(min, max) {
|
|
this.x = clamp(this.x, min.x, max.x);
|
|
this.y = clamp(this.y, min.y, max.y);
|
|
this.z = clamp(this.z, min.z, max.z);
|
|
this.w = clamp(this.w, min.w, max.w);
|
|
return this;
|
|
}
|
|
clampScalar(minVal, maxVal) {
|
|
this.x = clamp(this.x, minVal, maxVal);
|
|
this.y = clamp(this.y, minVal, maxVal);
|
|
this.z = clamp(this.z, minVal, maxVal);
|
|
this.w = clamp(this.w, minVal, maxVal);
|
|
return this;
|
|
}
|
|
clampLength(min, max) {
|
|
const length = this.length();
|
|
return this.divideScalar(length || 1).multiplyScalar(clamp(length, min, max));
|
|
}
|
|
floor() {
|
|
this.x = Math.floor(this.x);
|
|
this.y = Math.floor(this.y);
|
|
this.z = Math.floor(this.z);
|
|
this.w = Math.floor(this.w);
|
|
return this;
|
|
}
|
|
ceil() {
|
|
this.x = Math.ceil(this.x);
|
|
this.y = Math.ceil(this.y);
|
|
this.z = Math.ceil(this.z);
|
|
this.w = Math.ceil(this.w);
|
|
return this;
|
|
}
|
|
round() {
|
|
this.x = Math.round(this.x);
|
|
this.y = Math.round(this.y);
|
|
this.z = Math.round(this.z);
|
|
this.w = Math.round(this.w);
|
|
return this;
|
|
}
|
|
roundToZero() {
|
|
this.x = Math.trunc(this.x);
|
|
this.y = Math.trunc(this.y);
|
|
this.z = Math.trunc(this.z);
|
|
this.w = Math.trunc(this.w);
|
|
return this;
|
|
}
|
|
negate() {
|
|
this.x = -this.x;
|
|
this.y = -this.y;
|
|
this.z = -this.z;
|
|
this.w = -this.w;
|
|
return this;
|
|
}
|
|
dot(v) {
|
|
return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
|
|
}
|
|
lengthSq() {
|
|
return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
|
|
}
|
|
length() {
|
|
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
|
|
}
|
|
manhattanLength() {
|
|
return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
|
|
}
|
|
normalize() {
|
|
return this.divideScalar(this.length() || 1);
|
|
}
|
|
setLength(length) {
|
|
return this.normalize().multiplyScalar(length);
|
|
}
|
|
lerp(v, alpha) {
|
|
this.x += (v.x - this.x) * alpha;
|
|
this.y += (v.y - this.y) * alpha;
|
|
this.z += (v.z - this.z) * alpha;
|
|
this.w += (v.w - this.w) * alpha;
|
|
return this;
|
|
}
|
|
lerpVectors(v1, v2, alpha) {
|
|
this.x = v1.x + (v2.x - v1.x) * alpha;
|
|
this.y = v1.y + (v2.y - v1.y) * alpha;
|
|
this.z = v1.z + (v2.z - v1.z) * alpha;
|
|
this.w = v1.w + (v2.w - v1.w) * alpha;
|
|
return this;
|
|
}
|
|
equals(v) {
|
|
return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
this.x = array[offset];
|
|
this.y = array[offset + 1];
|
|
this.z = array[offset + 2];
|
|
this.w = array[offset + 3];
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
array[offset] = this.x;
|
|
array[offset + 1] = this.y;
|
|
array[offset + 2] = this.z;
|
|
array[offset + 3] = this.w;
|
|
return array;
|
|
}
|
|
fromBufferAttribute(attribute, index) {
|
|
this.x = attribute.getX(index);
|
|
this.y = attribute.getY(index);
|
|
this.z = attribute.getZ(index);
|
|
this.w = attribute.getW(index);
|
|
return this;
|
|
}
|
|
random() {
|
|
this.x = Math.random();
|
|
this.y = Math.random();
|
|
this.z = Math.random();
|
|
this.w = Math.random();
|
|
return this;
|
|
}
|
|
*[Symbol.iterator]() {
|
|
yield this.x;
|
|
yield this.y;
|
|
yield this.z;
|
|
yield this.w;
|
|
}
|
|
};
|
|
RenderTarget = class RenderTarget extends EventDispatcher {
|
|
constructor(width = 1, height = 1, options = {}) {
|
|
super();
|
|
this.isRenderTarget = true;
|
|
this.width = width;
|
|
this.height = height;
|
|
this.depth = 1;
|
|
this.scissor = new Vector4(0, 0, width, height);
|
|
this.scissorTest = false;
|
|
this.viewport = new Vector4(0, 0, width, height);
|
|
const image = { width, height, depth: 1 };
|
|
options = Object.assign({
|
|
generateMipmaps: false,
|
|
internalFormat: null,
|
|
minFilter: LinearFilter,
|
|
depthBuffer: true,
|
|
stencilBuffer: false,
|
|
resolveDepthBuffer: true,
|
|
resolveStencilBuffer: true,
|
|
depthTexture: null,
|
|
samples: 0,
|
|
count: 1
|
|
}, options);
|
|
const texture = new Texture(image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace);
|
|
texture.flipY = false;
|
|
texture.generateMipmaps = options.generateMipmaps;
|
|
texture.internalFormat = options.internalFormat;
|
|
this.textures = [];
|
|
const count = options.count;
|
|
for (let i = 0;i < count; i++) {
|
|
this.textures[i] = texture.clone();
|
|
this.textures[i].isRenderTargetTexture = true;
|
|
this.textures[i].renderTarget = this;
|
|
}
|
|
this.depthBuffer = options.depthBuffer;
|
|
this.stencilBuffer = options.stencilBuffer;
|
|
this.resolveDepthBuffer = options.resolveDepthBuffer;
|
|
this.resolveStencilBuffer = options.resolveStencilBuffer;
|
|
this._depthTexture = null;
|
|
this.depthTexture = options.depthTexture;
|
|
this.samples = options.samples;
|
|
}
|
|
get texture() {
|
|
return this.textures[0];
|
|
}
|
|
set texture(value) {
|
|
this.textures[0] = value;
|
|
}
|
|
set depthTexture(current) {
|
|
if (this._depthTexture !== null)
|
|
this._depthTexture.renderTarget = null;
|
|
if (current !== null)
|
|
current.renderTarget = this;
|
|
this._depthTexture = current;
|
|
}
|
|
get depthTexture() {
|
|
return this._depthTexture;
|
|
}
|
|
setSize(width, height, depth = 1) {
|
|
if (this.width !== width || this.height !== height || this.depth !== depth) {
|
|
this.width = width;
|
|
this.height = height;
|
|
this.depth = depth;
|
|
for (let i = 0, il = this.textures.length;i < il; i++) {
|
|
this.textures[i].image.width = width;
|
|
this.textures[i].image.height = height;
|
|
this.textures[i].image.depth = depth;
|
|
}
|
|
this.dispose();
|
|
}
|
|
this.viewport.set(0, 0, width, height);
|
|
this.scissor.set(0, 0, width, height);
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
copy(source) {
|
|
this.width = source.width;
|
|
this.height = source.height;
|
|
this.depth = source.depth;
|
|
this.scissor.copy(source.scissor);
|
|
this.scissorTest = source.scissorTest;
|
|
this.viewport.copy(source.viewport);
|
|
this.textures.length = 0;
|
|
for (let i = 0, il = source.textures.length;i < il; i++) {
|
|
this.textures[i] = source.textures[i].clone();
|
|
this.textures[i].isRenderTargetTexture = true;
|
|
this.textures[i].renderTarget = this;
|
|
}
|
|
const image = Object.assign({}, source.texture.image);
|
|
this.texture.source = new Source(image);
|
|
this.depthBuffer = source.depthBuffer;
|
|
this.stencilBuffer = source.stencilBuffer;
|
|
this.resolveDepthBuffer = source.resolveDepthBuffer;
|
|
this.resolveStencilBuffer = source.resolveStencilBuffer;
|
|
if (source.depthTexture !== null)
|
|
this.depthTexture = source.depthTexture.clone();
|
|
this.samples = source.samples;
|
|
return this;
|
|
}
|
|
dispose() {
|
|
this.dispatchEvent({ type: "dispose" });
|
|
}
|
|
};
|
|
WebGLRenderTarget = class WebGLRenderTarget extends RenderTarget {
|
|
constructor(width = 1, height = 1, options = {}) {
|
|
super(width, height, options);
|
|
this.isWebGLRenderTarget = true;
|
|
}
|
|
};
|
|
DataArrayTexture = class DataArrayTexture extends Texture {
|
|
constructor(data = null, width = 1, height = 1, depth = 1) {
|
|
super(null);
|
|
this.isDataArrayTexture = true;
|
|
this.image = { data, width, height, depth };
|
|
this.magFilter = NearestFilter;
|
|
this.minFilter = NearestFilter;
|
|
this.wrapR = ClampToEdgeWrapping;
|
|
this.generateMipmaps = false;
|
|
this.flipY = false;
|
|
this.unpackAlignment = 1;
|
|
this.layerUpdates = new Set;
|
|
}
|
|
addLayerUpdate(layerIndex) {
|
|
this.layerUpdates.add(layerIndex);
|
|
}
|
|
clearLayerUpdates() {
|
|
this.layerUpdates.clear();
|
|
}
|
|
};
|
|
WebGLArrayRenderTarget = class WebGLArrayRenderTarget extends WebGLRenderTarget {
|
|
constructor(width = 1, height = 1, depth = 1, options = {}) {
|
|
super(width, height, options);
|
|
this.isWebGLArrayRenderTarget = true;
|
|
this.depth = depth;
|
|
this.texture = new DataArrayTexture(null, width, height, depth);
|
|
this.texture.isRenderTargetTexture = true;
|
|
}
|
|
};
|
|
Data3DTexture = class Data3DTexture extends Texture {
|
|
constructor(data = null, width = 1, height = 1, depth = 1) {
|
|
super(null);
|
|
this.isData3DTexture = true;
|
|
this.image = { data, width, height, depth };
|
|
this.magFilter = NearestFilter;
|
|
this.minFilter = NearestFilter;
|
|
this.wrapR = ClampToEdgeWrapping;
|
|
this.generateMipmaps = false;
|
|
this.flipY = false;
|
|
this.unpackAlignment = 1;
|
|
}
|
|
};
|
|
WebGL3DRenderTarget = class WebGL3DRenderTarget extends WebGLRenderTarget {
|
|
constructor(width = 1, height = 1, depth = 1, options = {}) {
|
|
super(width, height, options);
|
|
this.isWebGL3DRenderTarget = true;
|
|
this.depth = depth;
|
|
this.texture = new Data3DTexture(null, width, height, depth);
|
|
this.texture.isRenderTargetTexture = true;
|
|
}
|
|
};
|
|
Quaternion = class Quaternion {
|
|
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
this.isQuaternion = true;
|
|
this._x = x;
|
|
this._y = y;
|
|
this._z = z;
|
|
this._w = w;
|
|
}
|
|
static slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
|
|
let x0 = src0[srcOffset0 + 0], y0 = src0[srcOffset0 + 1], z0 = src0[srcOffset0 + 2], w0 = src0[srcOffset0 + 3];
|
|
const x1 = src1[srcOffset1 + 0], y1 = src1[srcOffset1 + 1], z1 = src1[srcOffset1 + 2], w1 = src1[srcOffset1 + 3];
|
|
if (t === 0) {
|
|
dst[dstOffset + 0] = x0;
|
|
dst[dstOffset + 1] = y0;
|
|
dst[dstOffset + 2] = z0;
|
|
dst[dstOffset + 3] = w0;
|
|
return;
|
|
}
|
|
if (t === 1) {
|
|
dst[dstOffset + 0] = x1;
|
|
dst[dstOffset + 1] = y1;
|
|
dst[dstOffset + 2] = z1;
|
|
dst[dstOffset + 3] = w1;
|
|
return;
|
|
}
|
|
if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
|
|
let s = 1 - t;
|
|
const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1, dir = cos >= 0 ? 1 : -1, sqrSin = 1 - cos * cos;
|
|
if (sqrSin > Number.EPSILON) {
|
|
const sin = Math.sqrt(sqrSin), len = Math.atan2(sin, cos * dir);
|
|
s = Math.sin(s * len) / sin;
|
|
t = Math.sin(t * len) / sin;
|
|
}
|
|
const tDir = t * dir;
|
|
x0 = x0 * s + x1 * tDir;
|
|
y0 = y0 * s + y1 * tDir;
|
|
z0 = z0 * s + z1 * tDir;
|
|
w0 = w0 * s + w1 * tDir;
|
|
if (s === 1 - t) {
|
|
const f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
|
|
x0 *= f;
|
|
y0 *= f;
|
|
z0 *= f;
|
|
w0 *= f;
|
|
}
|
|
}
|
|
dst[dstOffset] = x0;
|
|
dst[dstOffset + 1] = y0;
|
|
dst[dstOffset + 2] = z0;
|
|
dst[dstOffset + 3] = w0;
|
|
}
|
|
static multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
|
|
const x0 = src0[srcOffset0];
|
|
const y0 = src0[srcOffset0 + 1];
|
|
const z0 = src0[srcOffset0 + 2];
|
|
const w0 = src0[srcOffset0 + 3];
|
|
const x1 = src1[srcOffset1];
|
|
const y1 = src1[srcOffset1 + 1];
|
|
const z1 = src1[srcOffset1 + 2];
|
|
const w1 = src1[srcOffset1 + 3];
|
|
dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
|
|
dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
|
|
dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
|
|
dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
|
|
return dst;
|
|
}
|
|
get x() {
|
|
return this._x;
|
|
}
|
|
set x(value) {
|
|
this._x = value;
|
|
this._onChangeCallback();
|
|
}
|
|
get y() {
|
|
return this._y;
|
|
}
|
|
set y(value) {
|
|
this._y = value;
|
|
this._onChangeCallback();
|
|
}
|
|
get z() {
|
|
return this._z;
|
|
}
|
|
set z(value) {
|
|
this._z = value;
|
|
this._onChangeCallback();
|
|
}
|
|
get w() {
|
|
return this._w;
|
|
}
|
|
set w(value) {
|
|
this._w = value;
|
|
this._onChangeCallback();
|
|
}
|
|
set(x, y, z, w) {
|
|
this._x = x;
|
|
this._y = y;
|
|
this._z = z;
|
|
this._w = w;
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor(this._x, this._y, this._z, this._w);
|
|
}
|
|
copy(quaternion) {
|
|
this._x = quaternion.x;
|
|
this._y = quaternion.y;
|
|
this._z = quaternion.z;
|
|
this._w = quaternion.w;
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
setFromEuler(euler, update = true) {
|
|
const { _x: x, _y: y, _z: z, _order: order } = euler;
|
|
const cos = Math.cos;
|
|
const sin = Math.sin;
|
|
const c1 = cos(x / 2);
|
|
const c2 = cos(y / 2);
|
|
const c3 = cos(z / 2);
|
|
const s1 = sin(x / 2);
|
|
const s2 = sin(y / 2);
|
|
const s3 = sin(z / 2);
|
|
switch (order) {
|
|
case "XYZ":
|
|
this._x = s1 * c2 * c3 + c1 * s2 * s3;
|
|
this._y = c1 * s2 * c3 - s1 * c2 * s3;
|
|
this._z = c1 * c2 * s3 + s1 * s2 * c3;
|
|
this._w = c1 * c2 * c3 - s1 * s2 * s3;
|
|
break;
|
|
case "YXZ":
|
|
this._x = s1 * c2 * c3 + c1 * s2 * s3;
|
|
this._y = c1 * s2 * c3 - s1 * c2 * s3;
|
|
this._z = c1 * c2 * s3 - s1 * s2 * c3;
|
|
this._w = c1 * c2 * c3 + s1 * s2 * s3;
|
|
break;
|
|
case "ZXY":
|
|
this._x = s1 * c2 * c3 - c1 * s2 * s3;
|
|
this._y = c1 * s2 * c3 + s1 * c2 * s3;
|
|
this._z = c1 * c2 * s3 + s1 * s2 * c3;
|
|
this._w = c1 * c2 * c3 - s1 * s2 * s3;
|
|
break;
|
|
case "ZYX":
|
|
this._x = s1 * c2 * c3 - c1 * s2 * s3;
|
|
this._y = c1 * s2 * c3 + s1 * c2 * s3;
|
|
this._z = c1 * c2 * s3 - s1 * s2 * c3;
|
|
this._w = c1 * c2 * c3 + s1 * s2 * s3;
|
|
break;
|
|
case "YZX":
|
|
this._x = s1 * c2 * c3 + c1 * s2 * s3;
|
|
this._y = c1 * s2 * c3 + s1 * c2 * s3;
|
|
this._z = c1 * c2 * s3 - s1 * s2 * c3;
|
|
this._w = c1 * c2 * c3 - s1 * s2 * s3;
|
|
break;
|
|
case "XZY":
|
|
this._x = s1 * c2 * c3 - c1 * s2 * s3;
|
|
this._y = c1 * s2 * c3 - s1 * c2 * s3;
|
|
this._z = c1 * c2 * s3 + s1 * s2 * c3;
|
|
this._w = c1 * c2 * c3 + s1 * s2 * s3;
|
|
break;
|
|
default:
|
|
console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + order);
|
|
}
|
|
if (update === true)
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
setFromAxisAngle(axis, angle) {
|
|
const halfAngle = angle / 2, s = Math.sin(halfAngle);
|
|
this._x = axis.x * s;
|
|
this._y = axis.y * s;
|
|
this._z = axis.z * s;
|
|
this._w = Math.cos(halfAngle);
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
setFromRotationMatrix(m) {
|
|
const te = m.elements, m11 = te[0], m12 = te[4], m13 = te[8], m21 = te[1], m22 = te[5], m23 = te[9], m31 = te[2], m32 = te[6], m33 = te[10], trace = m11 + m22 + m33;
|
|
if (trace > 0) {
|
|
const s = 0.5 / Math.sqrt(trace + 1);
|
|
this._w = 0.25 / s;
|
|
this._x = (m32 - m23) * s;
|
|
this._y = (m13 - m31) * s;
|
|
this._z = (m21 - m12) * s;
|
|
} else if (m11 > m22 && m11 > m33) {
|
|
const s = 2 * Math.sqrt(1 + m11 - m22 - m33);
|
|
this._w = (m32 - m23) / s;
|
|
this._x = 0.25 * s;
|
|
this._y = (m12 + m21) / s;
|
|
this._z = (m13 + m31) / s;
|
|
} else if (m22 > m33) {
|
|
const s = 2 * Math.sqrt(1 + m22 - m11 - m33);
|
|
this._w = (m13 - m31) / s;
|
|
this._x = (m12 + m21) / s;
|
|
this._y = 0.25 * s;
|
|
this._z = (m23 + m32) / s;
|
|
} else {
|
|
const s = 2 * Math.sqrt(1 + m33 - m11 - m22);
|
|
this._w = (m21 - m12) / s;
|
|
this._x = (m13 + m31) / s;
|
|
this._y = (m23 + m32) / s;
|
|
this._z = 0.25 * s;
|
|
}
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
setFromUnitVectors(vFrom, vTo) {
|
|
let r = vFrom.dot(vTo) + 1;
|
|
if (r < Number.EPSILON) {
|
|
r = 0;
|
|
if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
|
|
this._x = -vFrom.y;
|
|
this._y = vFrom.x;
|
|
this._z = 0;
|
|
this._w = r;
|
|
} else {
|
|
this._x = 0;
|
|
this._y = -vFrom.z;
|
|
this._z = vFrom.y;
|
|
this._w = r;
|
|
}
|
|
} else {
|
|
this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
|
|
this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
|
|
this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
|
|
this._w = r;
|
|
}
|
|
return this.normalize();
|
|
}
|
|
angleTo(q) {
|
|
return 2 * Math.acos(Math.abs(clamp(this.dot(q), -1, 1)));
|
|
}
|
|
rotateTowards(q, step) {
|
|
const angle = this.angleTo(q);
|
|
if (angle === 0)
|
|
return this;
|
|
const t = Math.min(1, step / angle);
|
|
this.slerp(q, t);
|
|
return this;
|
|
}
|
|
identity() {
|
|
return this.set(0, 0, 0, 1);
|
|
}
|
|
invert() {
|
|
return this.conjugate();
|
|
}
|
|
conjugate() {
|
|
this._x *= -1;
|
|
this._y *= -1;
|
|
this._z *= -1;
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
dot(v) {
|
|
return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
|
|
}
|
|
lengthSq() {
|
|
return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
|
|
}
|
|
length() {
|
|
return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
|
|
}
|
|
normalize() {
|
|
let l = this.length();
|
|
if (l === 0) {
|
|
this._x = 0;
|
|
this._y = 0;
|
|
this._z = 0;
|
|
this._w = 1;
|
|
} else {
|
|
l = 1 / l;
|
|
this._x = this._x * l;
|
|
this._y = this._y * l;
|
|
this._z = this._z * l;
|
|
this._w = this._w * l;
|
|
}
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
multiply(q) {
|
|
return this.multiplyQuaternions(this, q);
|
|
}
|
|
premultiply(q) {
|
|
return this.multiplyQuaternions(q, this);
|
|
}
|
|
multiplyQuaternions(a, b) {
|
|
const { _x: qax, _y: qay, _z: qaz, _w: qaw } = a;
|
|
const { _x: qbx, _y: qby, _z: qbz, _w: qbw } = b;
|
|
this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
|
|
this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
|
|
this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
|
|
this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
slerp(qb, t) {
|
|
if (t === 0)
|
|
return this;
|
|
if (t === 1)
|
|
return this.copy(qb);
|
|
const x = this._x, y = this._y, z = this._z, w = this._w;
|
|
let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
|
|
if (cosHalfTheta < 0) {
|
|
this._w = -qb._w;
|
|
this._x = -qb._x;
|
|
this._y = -qb._y;
|
|
this._z = -qb._z;
|
|
cosHalfTheta = -cosHalfTheta;
|
|
} else {
|
|
this.copy(qb);
|
|
}
|
|
if (cosHalfTheta >= 1) {
|
|
this._w = w;
|
|
this._x = x;
|
|
this._y = y;
|
|
this._z = z;
|
|
return this;
|
|
}
|
|
const sqrSinHalfTheta = 1 - cosHalfTheta * cosHalfTheta;
|
|
if (sqrSinHalfTheta <= Number.EPSILON) {
|
|
const s = 1 - t;
|
|
this._w = s * w + t * this._w;
|
|
this._x = s * x + t * this._x;
|
|
this._y = s * y + t * this._y;
|
|
this._z = s * z + t * this._z;
|
|
this.normalize();
|
|
return this;
|
|
}
|
|
const sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
|
|
const halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
|
|
const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta, ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
|
|
this._w = w * ratioA + this._w * ratioB;
|
|
this._x = x * ratioA + this._x * ratioB;
|
|
this._y = y * ratioA + this._y * ratioB;
|
|
this._z = z * ratioA + this._z * ratioB;
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
slerpQuaternions(qa, qb, t) {
|
|
return this.copy(qa).slerp(qb, t);
|
|
}
|
|
random() {
|
|
const theta1 = 2 * Math.PI * Math.random();
|
|
const theta2 = 2 * Math.PI * Math.random();
|
|
const x0 = Math.random();
|
|
const r1 = Math.sqrt(1 - x0);
|
|
const r2 = Math.sqrt(x0);
|
|
return this.set(r1 * Math.sin(theta1), r1 * Math.cos(theta1), r2 * Math.sin(theta2), r2 * Math.cos(theta2));
|
|
}
|
|
equals(quaternion) {
|
|
return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
this._x = array[offset];
|
|
this._y = array[offset + 1];
|
|
this._z = array[offset + 2];
|
|
this._w = array[offset + 3];
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
array[offset] = this._x;
|
|
array[offset + 1] = this._y;
|
|
array[offset + 2] = this._z;
|
|
array[offset + 3] = this._w;
|
|
return array;
|
|
}
|
|
fromBufferAttribute(attribute, index) {
|
|
this._x = attribute.getX(index);
|
|
this._y = attribute.getY(index);
|
|
this._z = attribute.getZ(index);
|
|
this._w = attribute.getW(index);
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
return this.toArray();
|
|
}
|
|
_onChange(callback) {
|
|
this._onChangeCallback = callback;
|
|
return this;
|
|
}
|
|
_onChangeCallback() {}
|
|
*[Symbol.iterator]() {
|
|
yield this._x;
|
|
yield this._y;
|
|
yield this._z;
|
|
yield this._w;
|
|
}
|
|
};
|
|
Vector3 = class Vector3 {
|
|
constructor(x = 0, y = 0, z = 0) {
|
|
Vector3.prototype.isVector3 = true;
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
}
|
|
set(x, y, z) {
|
|
if (z === undefined)
|
|
z = this.z;
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
return this;
|
|
}
|
|
setScalar(scalar) {
|
|
this.x = scalar;
|
|
this.y = scalar;
|
|
this.z = scalar;
|
|
return this;
|
|
}
|
|
setX(x) {
|
|
this.x = x;
|
|
return this;
|
|
}
|
|
setY(y) {
|
|
this.y = y;
|
|
return this;
|
|
}
|
|
setZ(z) {
|
|
this.z = z;
|
|
return this;
|
|
}
|
|
setComponent(index, value) {
|
|
switch (index) {
|
|
case 0:
|
|
this.x = value;
|
|
break;
|
|
case 1:
|
|
this.y = value;
|
|
break;
|
|
case 2:
|
|
this.z = value;
|
|
break;
|
|
default:
|
|
throw new Error("index is out of range: " + index);
|
|
}
|
|
return this;
|
|
}
|
|
getComponent(index) {
|
|
switch (index) {
|
|
case 0:
|
|
return this.x;
|
|
case 1:
|
|
return this.y;
|
|
case 2:
|
|
return this.z;
|
|
default:
|
|
throw new Error("index is out of range: " + index);
|
|
}
|
|
}
|
|
clone() {
|
|
return new this.constructor(this.x, this.y, this.z);
|
|
}
|
|
copy(v) {
|
|
this.x = v.x;
|
|
this.y = v.y;
|
|
this.z = v.z;
|
|
return this;
|
|
}
|
|
add(v) {
|
|
this.x += v.x;
|
|
this.y += v.y;
|
|
this.z += v.z;
|
|
return this;
|
|
}
|
|
addScalar(s) {
|
|
this.x += s;
|
|
this.y += s;
|
|
this.z += s;
|
|
return this;
|
|
}
|
|
addVectors(a, b) {
|
|
this.x = a.x + b.x;
|
|
this.y = a.y + b.y;
|
|
this.z = a.z + b.z;
|
|
return this;
|
|
}
|
|
addScaledVector(v, s) {
|
|
this.x += v.x * s;
|
|
this.y += v.y * s;
|
|
this.z += v.z * s;
|
|
return this;
|
|
}
|
|
sub(v) {
|
|
this.x -= v.x;
|
|
this.y -= v.y;
|
|
this.z -= v.z;
|
|
return this;
|
|
}
|
|
subScalar(s) {
|
|
this.x -= s;
|
|
this.y -= s;
|
|
this.z -= s;
|
|
return this;
|
|
}
|
|
subVectors(a, b) {
|
|
this.x = a.x - b.x;
|
|
this.y = a.y - b.y;
|
|
this.z = a.z - b.z;
|
|
return this;
|
|
}
|
|
multiply(v) {
|
|
this.x *= v.x;
|
|
this.y *= v.y;
|
|
this.z *= v.z;
|
|
return this;
|
|
}
|
|
multiplyScalar(scalar) {
|
|
this.x *= scalar;
|
|
this.y *= scalar;
|
|
this.z *= scalar;
|
|
return this;
|
|
}
|
|
multiplyVectors(a, b) {
|
|
this.x = a.x * b.x;
|
|
this.y = a.y * b.y;
|
|
this.z = a.z * b.z;
|
|
return this;
|
|
}
|
|
applyEuler(euler) {
|
|
return this.applyQuaternion(_quaternion$4.setFromEuler(euler));
|
|
}
|
|
applyAxisAngle(axis, angle) {
|
|
return this.applyQuaternion(_quaternion$4.setFromAxisAngle(axis, angle));
|
|
}
|
|
applyMatrix3(m) {
|
|
const x = this.x, y = this.y, z = this.z;
|
|
const e = m.elements;
|
|
this.x = e[0] * x + e[3] * y + e[6] * z;
|
|
this.y = e[1] * x + e[4] * y + e[7] * z;
|
|
this.z = e[2] * x + e[5] * y + e[8] * z;
|
|
return this;
|
|
}
|
|
applyNormalMatrix(m) {
|
|
return this.applyMatrix3(m).normalize();
|
|
}
|
|
applyMatrix4(m) {
|
|
const x = this.x, y = this.y, z = this.z;
|
|
const e = m.elements;
|
|
const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
|
|
this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
|
|
this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
|
|
this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
|
|
return this;
|
|
}
|
|
applyQuaternion(q) {
|
|
const vx = this.x, vy = this.y, vz = this.z;
|
|
const { x: qx, y: qy, z: qz, w: qw } = q;
|
|
const tx = 2 * (qy * vz - qz * vy);
|
|
const ty = 2 * (qz * vx - qx * vz);
|
|
const tz = 2 * (qx * vy - qy * vx);
|
|
this.x = vx + qw * tx + qy * tz - qz * ty;
|
|
this.y = vy + qw * ty + qz * tx - qx * tz;
|
|
this.z = vz + qw * tz + qx * ty - qy * tx;
|
|
return this;
|
|
}
|
|
project(camera) {
|
|
return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
|
|
}
|
|
unproject(camera) {
|
|
return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
|
|
}
|
|
transformDirection(m) {
|
|
const x = this.x, y = this.y, z = this.z;
|
|
const e = m.elements;
|
|
this.x = e[0] * x + e[4] * y + e[8] * z;
|
|
this.y = e[1] * x + e[5] * y + e[9] * z;
|
|
this.z = e[2] * x + e[6] * y + e[10] * z;
|
|
return this.normalize();
|
|
}
|
|
divide(v) {
|
|
this.x /= v.x;
|
|
this.y /= v.y;
|
|
this.z /= v.z;
|
|
return this;
|
|
}
|
|
divideScalar(scalar) {
|
|
return this.multiplyScalar(1 / scalar);
|
|
}
|
|
min(v) {
|
|
this.x = Math.min(this.x, v.x);
|
|
this.y = Math.min(this.y, v.y);
|
|
this.z = Math.min(this.z, v.z);
|
|
return this;
|
|
}
|
|
max(v) {
|
|
this.x = Math.max(this.x, v.x);
|
|
this.y = Math.max(this.y, v.y);
|
|
this.z = Math.max(this.z, v.z);
|
|
return this;
|
|
}
|
|
clamp(min, max) {
|
|
this.x = clamp(this.x, min.x, max.x);
|
|
this.y = clamp(this.y, min.y, max.y);
|
|
this.z = clamp(this.z, min.z, max.z);
|
|
return this;
|
|
}
|
|
clampScalar(minVal, maxVal) {
|
|
this.x = clamp(this.x, minVal, maxVal);
|
|
this.y = clamp(this.y, minVal, maxVal);
|
|
this.z = clamp(this.z, minVal, maxVal);
|
|
return this;
|
|
}
|
|
clampLength(min, max) {
|
|
const length = this.length();
|
|
return this.divideScalar(length || 1).multiplyScalar(clamp(length, min, max));
|
|
}
|
|
floor() {
|
|
this.x = Math.floor(this.x);
|
|
this.y = Math.floor(this.y);
|
|
this.z = Math.floor(this.z);
|
|
return this;
|
|
}
|
|
ceil() {
|
|
this.x = Math.ceil(this.x);
|
|
this.y = Math.ceil(this.y);
|
|
this.z = Math.ceil(this.z);
|
|
return this;
|
|
}
|
|
round() {
|
|
this.x = Math.round(this.x);
|
|
this.y = Math.round(this.y);
|
|
this.z = Math.round(this.z);
|
|
return this;
|
|
}
|
|
roundToZero() {
|
|
this.x = Math.trunc(this.x);
|
|
this.y = Math.trunc(this.y);
|
|
this.z = Math.trunc(this.z);
|
|
return this;
|
|
}
|
|
negate() {
|
|
this.x = -this.x;
|
|
this.y = -this.y;
|
|
this.z = -this.z;
|
|
return this;
|
|
}
|
|
dot(v) {
|
|
return this.x * v.x + this.y * v.y + this.z * v.z;
|
|
}
|
|
lengthSq() {
|
|
return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
}
|
|
length() {
|
|
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
}
|
|
manhattanLength() {
|
|
return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
|
|
}
|
|
normalize() {
|
|
return this.divideScalar(this.length() || 1);
|
|
}
|
|
setLength(length) {
|
|
return this.normalize().multiplyScalar(length);
|
|
}
|
|
lerp(v, alpha) {
|
|
this.x += (v.x - this.x) * alpha;
|
|
this.y += (v.y - this.y) * alpha;
|
|
this.z += (v.z - this.z) * alpha;
|
|
return this;
|
|
}
|
|
lerpVectors(v1, v2, alpha) {
|
|
this.x = v1.x + (v2.x - v1.x) * alpha;
|
|
this.y = v1.y + (v2.y - v1.y) * alpha;
|
|
this.z = v1.z + (v2.z - v1.z) * alpha;
|
|
return this;
|
|
}
|
|
cross(v) {
|
|
return this.crossVectors(this, v);
|
|
}
|
|
crossVectors(a, b) {
|
|
const { x: ax, y: ay, z: az } = a;
|
|
const { x: bx, y: by, z: bz } = b;
|
|
this.x = ay * bz - az * by;
|
|
this.y = az * bx - ax * bz;
|
|
this.z = ax * by - ay * bx;
|
|
return this;
|
|
}
|
|
projectOnVector(v) {
|
|
const denominator = v.lengthSq();
|
|
if (denominator === 0)
|
|
return this.set(0, 0, 0);
|
|
const scalar = v.dot(this) / denominator;
|
|
return this.copy(v).multiplyScalar(scalar);
|
|
}
|
|
projectOnPlane(planeNormal) {
|
|
_vector$c.copy(this).projectOnVector(planeNormal);
|
|
return this.sub(_vector$c);
|
|
}
|
|
reflect(normal) {
|
|
return this.sub(_vector$c.copy(normal).multiplyScalar(2 * this.dot(normal)));
|
|
}
|
|
angleTo(v) {
|
|
const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
|
|
if (denominator === 0)
|
|
return Math.PI / 2;
|
|
const theta = this.dot(v) / denominator;
|
|
return Math.acos(clamp(theta, -1, 1));
|
|
}
|
|
distanceTo(v) {
|
|
return Math.sqrt(this.distanceToSquared(v));
|
|
}
|
|
distanceToSquared(v) {
|
|
const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
|
|
return dx * dx + dy * dy + dz * dz;
|
|
}
|
|
manhattanDistanceTo(v) {
|
|
return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
|
|
}
|
|
setFromSpherical(s) {
|
|
return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
|
|
}
|
|
setFromSphericalCoords(radius, phi, theta) {
|
|
const sinPhiRadius = Math.sin(phi) * radius;
|
|
this.x = sinPhiRadius * Math.sin(theta);
|
|
this.y = Math.cos(phi) * radius;
|
|
this.z = sinPhiRadius * Math.cos(theta);
|
|
return this;
|
|
}
|
|
setFromCylindrical(c) {
|
|
return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
|
|
}
|
|
setFromCylindricalCoords(radius, theta, y) {
|
|
this.x = radius * Math.sin(theta);
|
|
this.y = y;
|
|
this.z = radius * Math.cos(theta);
|
|
return this;
|
|
}
|
|
setFromMatrixPosition(m) {
|
|
const e = m.elements;
|
|
this.x = e[12];
|
|
this.y = e[13];
|
|
this.z = e[14];
|
|
return this;
|
|
}
|
|
setFromMatrixScale(m) {
|
|
const sx = this.setFromMatrixColumn(m, 0).length();
|
|
const sy = this.setFromMatrixColumn(m, 1).length();
|
|
const sz = this.setFromMatrixColumn(m, 2).length();
|
|
this.x = sx;
|
|
this.y = sy;
|
|
this.z = sz;
|
|
return this;
|
|
}
|
|
setFromMatrixColumn(m, index) {
|
|
return this.fromArray(m.elements, index * 4);
|
|
}
|
|
setFromMatrix3Column(m, index) {
|
|
return this.fromArray(m.elements, index * 3);
|
|
}
|
|
setFromEuler(e) {
|
|
this.x = e._x;
|
|
this.y = e._y;
|
|
this.z = e._z;
|
|
return this;
|
|
}
|
|
setFromColor(c) {
|
|
this.x = c.r;
|
|
this.y = c.g;
|
|
this.z = c.b;
|
|
return this;
|
|
}
|
|
equals(v) {
|
|
return v.x === this.x && v.y === this.y && v.z === this.z;
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
this.x = array[offset];
|
|
this.y = array[offset + 1];
|
|
this.z = array[offset + 2];
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
array[offset] = this.x;
|
|
array[offset + 1] = this.y;
|
|
array[offset + 2] = this.z;
|
|
return array;
|
|
}
|
|
fromBufferAttribute(attribute, index) {
|
|
this.x = attribute.getX(index);
|
|
this.y = attribute.getY(index);
|
|
this.z = attribute.getZ(index);
|
|
return this;
|
|
}
|
|
random() {
|
|
this.x = Math.random();
|
|
this.y = Math.random();
|
|
this.z = Math.random();
|
|
return this;
|
|
}
|
|
randomDirection() {
|
|
const theta = Math.random() * Math.PI * 2;
|
|
const u = Math.random() * 2 - 1;
|
|
const c = Math.sqrt(1 - u * u);
|
|
this.x = c * Math.cos(theta);
|
|
this.y = u;
|
|
this.z = c * Math.sin(theta);
|
|
return this;
|
|
}
|
|
*[Symbol.iterator]() {
|
|
yield this.x;
|
|
yield this.y;
|
|
yield this.z;
|
|
}
|
|
};
|
|
_vector$c = /* @__PURE__ */ new Vector3;
|
|
_quaternion$4 = /* @__PURE__ */ new Quaternion;
|
|
_points = [
|
|
/* @__PURE__ */ new Vector3,
|
|
/* @__PURE__ */ new Vector3,
|
|
/* @__PURE__ */ new Vector3,
|
|
/* @__PURE__ */ new Vector3,
|
|
/* @__PURE__ */ new Vector3,
|
|
/* @__PURE__ */ new Vector3,
|
|
/* @__PURE__ */ new Vector3,
|
|
/* @__PURE__ */ new Vector3
|
|
];
|
|
_vector$b = /* @__PURE__ */ new Vector3;
|
|
_box$4 = /* @__PURE__ */ new Box3;
|
|
_v0$2 = /* @__PURE__ */ new Vector3;
|
|
_v1$7 = /* @__PURE__ */ new Vector3;
|
|
_v2$4 = /* @__PURE__ */ new Vector3;
|
|
_f0 = /* @__PURE__ */ new Vector3;
|
|
_f1 = /* @__PURE__ */ new Vector3;
|
|
_f2 = /* @__PURE__ */ new Vector3;
|
|
_center = /* @__PURE__ */ new Vector3;
|
|
_extents = /* @__PURE__ */ new Vector3;
|
|
_triangleNormal = /* @__PURE__ */ new Vector3;
|
|
_testAxis = /* @__PURE__ */ new Vector3;
|
|
_box$3 = /* @__PURE__ */ new Box3;
|
|
_v1$6 = /* @__PURE__ */ new Vector3;
|
|
_v2$3 = /* @__PURE__ */ new Vector3;
|
|
_vector$a = /* @__PURE__ */ new Vector3;
|
|
_segCenter = /* @__PURE__ */ new Vector3;
|
|
_segDir = /* @__PURE__ */ new Vector3;
|
|
_diff = /* @__PURE__ */ new Vector3;
|
|
_edge1 = /* @__PURE__ */ new Vector3;
|
|
_edge2 = /* @__PURE__ */ new Vector3;
|
|
_normal$1 = /* @__PURE__ */ new Vector3;
|
|
_v1$5 = /* @__PURE__ */ new Vector3;
|
|
_m1$2 = /* @__PURE__ */ new Matrix4;
|
|
_zero = /* @__PURE__ */ new Vector3(0, 0, 0);
|
|
_one = /* @__PURE__ */ new Vector3(1, 1, 1);
|
|
_x = /* @__PURE__ */ new Vector3;
|
|
_y = /* @__PURE__ */ new Vector3;
|
|
_z = /* @__PURE__ */ new Vector3;
|
|
_matrix$2 = /* @__PURE__ */ new Matrix4;
|
|
_quaternion$3 = /* @__PURE__ */ new Quaternion;
|
|
Euler = class Euler {
|
|
constructor(x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER) {
|
|
this.isEuler = true;
|
|
this._x = x;
|
|
this._y = y;
|
|
this._z = z;
|
|
this._order = order;
|
|
}
|
|
get x() {
|
|
return this._x;
|
|
}
|
|
set x(value) {
|
|
this._x = value;
|
|
this._onChangeCallback();
|
|
}
|
|
get y() {
|
|
return this._y;
|
|
}
|
|
set y(value) {
|
|
this._y = value;
|
|
this._onChangeCallback();
|
|
}
|
|
get z() {
|
|
return this._z;
|
|
}
|
|
set z(value) {
|
|
this._z = value;
|
|
this._onChangeCallback();
|
|
}
|
|
get order() {
|
|
return this._order;
|
|
}
|
|
set order(value) {
|
|
this._order = value;
|
|
this._onChangeCallback();
|
|
}
|
|
set(x, y, z, order = this._order) {
|
|
this._x = x;
|
|
this._y = y;
|
|
this._z = z;
|
|
this._order = order;
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor(this._x, this._y, this._z, this._order);
|
|
}
|
|
copy(euler) {
|
|
this._x = euler._x;
|
|
this._y = euler._y;
|
|
this._z = euler._z;
|
|
this._order = euler._order;
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
setFromRotationMatrix(m, order = this._order, update = true) {
|
|
const te = m.elements;
|
|
const m11 = te[0], m12 = te[4], m13 = te[8];
|
|
const m21 = te[1], m22 = te[5], m23 = te[9];
|
|
const m31 = te[2], m32 = te[6], m33 = te[10];
|
|
switch (order) {
|
|
case "XYZ":
|
|
this._y = Math.asin(clamp(m13, -1, 1));
|
|
if (Math.abs(m13) < 0.9999999) {
|
|
this._x = Math.atan2(-m23, m33);
|
|
this._z = Math.atan2(-m12, m11);
|
|
} else {
|
|
this._x = Math.atan2(m32, m22);
|
|
this._z = 0;
|
|
}
|
|
break;
|
|
case "YXZ":
|
|
this._x = Math.asin(-clamp(m23, -1, 1));
|
|
if (Math.abs(m23) < 0.9999999) {
|
|
this._y = Math.atan2(m13, m33);
|
|
this._z = Math.atan2(m21, m22);
|
|
} else {
|
|
this._y = Math.atan2(-m31, m11);
|
|
this._z = 0;
|
|
}
|
|
break;
|
|
case "ZXY":
|
|
this._x = Math.asin(clamp(m32, -1, 1));
|
|
if (Math.abs(m32) < 0.9999999) {
|
|
this._y = Math.atan2(-m31, m33);
|
|
this._z = Math.atan2(-m12, m22);
|
|
} else {
|
|
this._y = 0;
|
|
this._z = Math.atan2(m21, m11);
|
|
}
|
|
break;
|
|
case "ZYX":
|
|
this._y = Math.asin(-clamp(m31, -1, 1));
|
|
if (Math.abs(m31) < 0.9999999) {
|
|
this._x = Math.atan2(m32, m33);
|
|
this._z = Math.atan2(m21, m11);
|
|
} else {
|
|
this._x = 0;
|
|
this._z = Math.atan2(-m12, m22);
|
|
}
|
|
break;
|
|
case "YZX":
|
|
this._z = Math.asin(clamp(m21, -1, 1));
|
|
if (Math.abs(m21) < 0.9999999) {
|
|
this._x = Math.atan2(-m23, m22);
|
|
this._y = Math.atan2(-m31, m11);
|
|
} else {
|
|
this._x = 0;
|
|
this._y = Math.atan2(m13, m33);
|
|
}
|
|
break;
|
|
case "XZY":
|
|
this._z = Math.asin(-clamp(m12, -1, 1));
|
|
if (Math.abs(m12) < 0.9999999) {
|
|
this._x = Math.atan2(m32, m22);
|
|
this._y = Math.atan2(m13, m11);
|
|
} else {
|
|
this._x = Math.atan2(-m23, m33);
|
|
this._y = 0;
|
|
}
|
|
break;
|
|
default:
|
|
console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: " + order);
|
|
}
|
|
this._order = order;
|
|
if (update === true)
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
setFromQuaternion(q, order, update) {
|
|
_matrix$2.makeRotationFromQuaternion(q);
|
|
return this.setFromRotationMatrix(_matrix$2, order, update);
|
|
}
|
|
setFromVector3(v, order = this._order) {
|
|
return this.set(v.x, v.y, v.z, order);
|
|
}
|
|
reorder(newOrder) {
|
|
_quaternion$3.setFromEuler(this);
|
|
return this.setFromQuaternion(_quaternion$3, newOrder);
|
|
}
|
|
equals(euler) {
|
|
return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
|
|
}
|
|
fromArray(array) {
|
|
this._x = array[0];
|
|
this._y = array[1];
|
|
this._z = array[2];
|
|
if (array[3] !== undefined)
|
|
this._order = array[3];
|
|
this._onChangeCallback();
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
array[offset] = this._x;
|
|
array[offset + 1] = this._y;
|
|
array[offset + 2] = this._z;
|
|
array[offset + 3] = this._order;
|
|
return array;
|
|
}
|
|
_onChange(callback) {
|
|
this._onChangeCallback = callback;
|
|
return this;
|
|
}
|
|
_onChangeCallback() {}
|
|
*[Symbol.iterator]() {
|
|
yield this._x;
|
|
yield this._y;
|
|
yield this._z;
|
|
yield this._order;
|
|
}
|
|
};
|
|
Euler.DEFAULT_ORDER = "XYZ";
|
|
_v1$4 = /* @__PURE__ */ new Vector3;
|
|
_q1 = /* @__PURE__ */ new Quaternion;
|
|
_m1$1 = /* @__PURE__ */ new Matrix4;
|
|
_target = /* @__PURE__ */ new Vector3;
|
|
_position$3 = /* @__PURE__ */ new Vector3;
|
|
_scale$2 = /* @__PURE__ */ new Vector3;
|
|
_quaternion$2 = /* @__PURE__ */ new Quaternion;
|
|
_xAxis = /* @__PURE__ */ new Vector3(1, 0, 0);
|
|
_yAxis = /* @__PURE__ */ new Vector3(0, 1, 0);
|
|
_zAxis = /* @__PURE__ */ new Vector3(0, 0, 1);
|
|
_addedEvent = { type: "added" };
|
|
_removedEvent = { type: "removed" };
|
|
_childaddedEvent = { type: "childadded", child: null };
|
|
_childremovedEvent = { type: "childremoved", child: null };
|
|
Object3D = class Object3D extends EventDispatcher {
|
|
constructor() {
|
|
super();
|
|
this.isObject3D = true;
|
|
Object.defineProperty(this, "id", { value: _object3DId++ });
|
|
this.uuid = generateUUID();
|
|
this.name = "";
|
|
this.type = "Object3D";
|
|
this.parent = null;
|
|
this.children = [];
|
|
this.up = Object3D.DEFAULT_UP.clone();
|
|
const position = new Vector3;
|
|
const rotation = new Euler;
|
|
const quaternion = new Quaternion;
|
|
const scale = new Vector3(1, 1, 1);
|
|
function onRotationChange() {
|
|
quaternion.setFromEuler(rotation, false);
|
|
}
|
|
function onQuaternionChange() {
|
|
rotation.setFromQuaternion(quaternion, undefined, false);
|
|
}
|
|
rotation._onChange(onRotationChange);
|
|
quaternion._onChange(onQuaternionChange);
|
|
Object.defineProperties(this, {
|
|
position: {
|
|
configurable: true,
|
|
enumerable: true,
|
|
value: position
|
|
},
|
|
rotation: {
|
|
configurable: true,
|
|
enumerable: true,
|
|
value: rotation
|
|
},
|
|
quaternion: {
|
|
configurable: true,
|
|
enumerable: true,
|
|
value: quaternion
|
|
},
|
|
scale: {
|
|
configurable: true,
|
|
enumerable: true,
|
|
value: scale
|
|
},
|
|
modelViewMatrix: {
|
|
value: new Matrix4
|
|
},
|
|
normalMatrix: {
|
|
value: new Matrix3
|
|
}
|
|
});
|
|
this.matrix = new Matrix4;
|
|
this.matrixWorld = new Matrix4;
|
|
this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;
|
|
this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE;
|
|
this.matrixWorldNeedsUpdate = false;
|
|
this.layers = new Layers;
|
|
this.visible = true;
|
|
this.castShadow = false;
|
|
this.receiveShadow = false;
|
|
this.frustumCulled = true;
|
|
this.renderOrder = 0;
|
|
this.animations = [];
|
|
this.userData = {};
|
|
}
|
|
onBeforeShadow() {}
|
|
onAfterShadow() {}
|
|
onBeforeRender() {}
|
|
onAfterRender() {}
|
|
applyMatrix4(matrix) {
|
|
if (this.matrixAutoUpdate)
|
|
this.updateMatrix();
|
|
this.matrix.premultiply(matrix);
|
|
this.matrix.decompose(this.position, this.quaternion, this.scale);
|
|
}
|
|
applyQuaternion(q) {
|
|
this.quaternion.premultiply(q);
|
|
return this;
|
|
}
|
|
setRotationFromAxisAngle(axis, angle) {
|
|
this.quaternion.setFromAxisAngle(axis, angle);
|
|
}
|
|
setRotationFromEuler(euler) {
|
|
this.quaternion.setFromEuler(euler, true);
|
|
}
|
|
setRotationFromMatrix(m) {
|
|
this.quaternion.setFromRotationMatrix(m);
|
|
}
|
|
setRotationFromQuaternion(q) {
|
|
this.quaternion.copy(q);
|
|
}
|
|
rotateOnAxis(axis, angle) {
|
|
_q1.setFromAxisAngle(axis, angle);
|
|
this.quaternion.multiply(_q1);
|
|
return this;
|
|
}
|
|
rotateOnWorldAxis(axis, angle) {
|
|
_q1.setFromAxisAngle(axis, angle);
|
|
this.quaternion.premultiply(_q1);
|
|
return this;
|
|
}
|
|
rotateX(angle) {
|
|
return this.rotateOnAxis(_xAxis, angle);
|
|
}
|
|
rotateY(angle) {
|
|
return this.rotateOnAxis(_yAxis, angle);
|
|
}
|
|
rotateZ(angle) {
|
|
return this.rotateOnAxis(_zAxis, angle);
|
|
}
|
|
translateOnAxis(axis, distance) {
|
|
_v1$4.copy(axis).applyQuaternion(this.quaternion);
|
|
this.position.add(_v1$4.multiplyScalar(distance));
|
|
return this;
|
|
}
|
|
translateX(distance) {
|
|
return this.translateOnAxis(_xAxis, distance);
|
|
}
|
|
translateY(distance) {
|
|
return this.translateOnAxis(_yAxis, distance);
|
|
}
|
|
translateZ(distance) {
|
|
return this.translateOnAxis(_zAxis, distance);
|
|
}
|
|
localToWorld(vector) {
|
|
this.updateWorldMatrix(true, false);
|
|
return vector.applyMatrix4(this.matrixWorld);
|
|
}
|
|
worldToLocal(vector) {
|
|
this.updateWorldMatrix(true, false);
|
|
return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
|
|
}
|
|
lookAt(x, y, z) {
|
|
if (x.isVector3) {
|
|
_target.copy(x);
|
|
} else {
|
|
_target.set(x, y, z);
|
|
}
|
|
const parent = this.parent;
|
|
this.updateWorldMatrix(true, false);
|
|
_position$3.setFromMatrixPosition(this.matrixWorld);
|
|
if (this.isCamera || this.isLight) {
|
|
_m1$1.lookAt(_position$3, _target, this.up);
|
|
} else {
|
|
_m1$1.lookAt(_target, _position$3, this.up);
|
|
}
|
|
this.quaternion.setFromRotationMatrix(_m1$1);
|
|
if (parent) {
|
|
_m1$1.extractRotation(parent.matrixWorld);
|
|
_q1.setFromRotationMatrix(_m1$1);
|
|
this.quaternion.premultiply(_q1.invert());
|
|
}
|
|
}
|
|
add(object) {
|
|
if (arguments.length > 1) {
|
|
for (let i = 0;i < arguments.length; i++) {
|
|
this.add(arguments[i]);
|
|
}
|
|
return this;
|
|
}
|
|
if (object === this) {
|
|
console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
|
|
return this;
|
|
}
|
|
if (object && object.isObject3D) {
|
|
object.removeFromParent();
|
|
object.parent = this;
|
|
this.children.push(object);
|
|
object.dispatchEvent(_addedEvent);
|
|
_childaddedEvent.child = object;
|
|
this.dispatchEvent(_childaddedEvent);
|
|
_childaddedEvent.child = null;
|
|
} else {
|
|
console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
|
|
}
|
|
return this;
|
|
}
|
|
remove(object) {
|
|
if (arguments.length > 1) {
|
|
for (let i = 0;i < arguments.length; i++) {
|
|
this.remove(arguments[i]);
|
|
}
|
|
return this;
|
|
}
|
|
const index = this.children.indexOf(object);
|
|
if (index !== -1) {
|
|
object.parent = null;
|
|
this.children.splice(index, 1);
|
|
object.dispatchEvent(_removedEvent);
|
|
_childremovedEvent.child = object;
|
|
this.dispatchEvent(_childremovedEvent);
|
|
_childremovedEvent.child = null;
|
|
}
|
|
return this;
|
|
}
|
|
removeFromParent() {
|
|
const parent = this.parent;
|
|
if (parent !== null) {
|
|
parent.remove(this);
|
|
}
|
|
return this;
|
|
}
|
|
clear() {
|
|
return this.remove(...this.children);
|
|
}
|
|
attach(object) {
|
|
this.updateWorldMatrix(true, false);
|
|
_m1$1.copy(this.matrixWorld).invert();
|
|
if (object.parent !== null) {
|
|
object.parent.updateWorldMatrix(true, false);
|
|
_m1$1.multiply(object.parent.matrixWorld);
|
|
}
|
|
object.applyMatrix4(_m1$1);
|
|
object.removeFromParent();
|
|
object.parent = this;
|
|
this.children.push(object);
|
|
object.updateWorldMatrix(false, true);
|
|
object.dispatchEvent(_addedEvent);
|
|
_childaddedEvent.child = object;
|
|
this.dispatchEvent(_childaddedEvent);
|
|
_childaddedEvent.child = null;
|
|
return this;
|
|
}
|
|
getObjectById(id) {
|
|
return this.getObjectByProperty("id", id);
|
|
}
|
|
getObjectByName(name) {
|
|
return this.getObjectByProperty("name", name);
|
|
}
|
|
getObjectByProperty(name, value) {
|
|
if (this[name] === value)
|
|
return this;
|
|
for (let i = 0, l = this.children.length;i < l; i++) {
|
|
const child = this.children[i];
|
|
const object = child.getObjectByProperty(name, value);
|
|
if (object !== undefined) {
|
|
return object;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
getObjectsByProperty(name, value, result = []) {
|
|
if (this[name] === value)
|
|
result.push(this);
|
|
const children = this.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
children[i].getObjectsByProperty(name, value, result);
|
|
}
|
|
return result;
|
|
}
|
|
getWorldPosition(target) {
|
|
this.updateWorldMatrix(true, false);
|
|
return target.setFromMatrixPosition(this.matrixWorld);
|
|
}
|
|
getWorldQuaternion(target) {
|
|
this.updateWorldMatrix(true, false);
|
|
this.matrixWorld.decompose(_position$3, target, _scale$2);
|
|
return target;
|
|
}
|
|
getWorldScale(target) {
|
|
this.updateWorldMatrix(true, false);
|
|
this.matrixWorld.decompose(_position$3, _quaternion$2, target);
|
|
return target;
|
|
}
|
|
getWorldDirection(target) {
|
|
this.updateWorldMatrix(true, false);
|
|
const e = this.matrixWorld.elements;
|
|
return target.set(e[8], e[9], e[10]).normalize();
|
|
}
|
|
raycast() {}
|
|
traverse(callback) {
|
|
callback(this);
|
|
const children = this.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
children[i].traverse(callback);
|
|
}
|
|
}
|
|
traverseVisible(callback) {
|
|
if (this.visible === false)
|
|
return;
|
|
callback(this);
|
|
const children = this.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
children[i].traverseVisible(callback);
|
|
}
|
|
}
|
|
traverseAncestors(callback) {
|
|
const parent = this.parent;
|
|
if (parent !== null) {
|
|
callback(parent);
|
|
parent.traverseAncestors(callback);
|
|
}
|
|
}
|
|
updateMatrix() {
|
|
this.matrix.compose(this.position, this.quaternion, this.scale);
|
|
this.matrixWorldNeedsUpdate = true;
|
|
}
|
|
updateMatrixWorld(force) {
|
|
if (this.matrixAutoUpdate)
|
|
this.updateMatrix();
|
|
if (this.matrixWorldNeedsUpdate || force) {
|
|
if (this.matrixWorldAutoUpdate === true) {
|
|
if (this.parent === null) {
|
|
this.matrixWorld.copy(this.matrix);
|
|
} else {
|
|
this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
|
|
}
|
|
}
|
|
this.matrixWorldNeedsUpdate = false;
|
|
force = true;
|
|
}
|
|
const children = this.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
const child = children[i];
|
|
child.updateMatrixWorld(force);
|
|
}
|
|
}
|
|
updateWorldMatrix(updateParents, updateChildren) {
|
|
const parent = this.parent;
|
|
if (updateParents === true && parent !== null) {
|
|
parent.updateWorldMatrix(true, false);
|
|
}
|
|
if (this.matrixAutoUpdate)
|
|
this.updateMatrix();
|
|
if (this.matrixWorldAutoUpdate === true) {
|
|
if (this.parent === null) {
|
|
this.matrixWorld.copy(this.matrix);
|
|
} else {
|
|
this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
|
|
}
|
|
}
|
|
if (updateChildren === true) {
|
|
const children = this.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
const child = children[i];
|
|
child.updateWorldMatrix(false, true);
|
|
}
|
|
}
|
|
}
|
|
toJSON(meta) {
|
|
const isRootObject = meta === undefined || typeof meta === "string";
|
|
const output = {};
|
|
if (isRootObject) {
|
|
meta = {
|
|
geometries: {},
|
|
materials: {},
|
|
textures: {},
|
|
images: {},
|
|
shapes: {},
|
|
skeletons: {},
|
|
animations: {},
|
|
nodes: {}
|
|
};
|
|
output.metadata = {
|
|
version: 4.6,
|
|
type: "Object",
|
|
generator: "Object3D.toJSON"
|
|
};
|
|
}
|
|
const object = {};
|
|
object.uuid = this.uuid;
|
|
object.type = this.type;
|
|
if (this.name !== "")
|
|
object.name = this.name;
|
|
if (this.castShadow === true)
|
|
object.castShadow = true;
|
|
if (this.receiveShadow === true)
|
|
object.receiveShadow = true;
|
|
if (this.visible === false)
|
|
object.visible = false;
|
|
if (this.frustumCulled === false)
|
|
object.frustumCulled = false;
|
|
if (this.renderOrder !== 0)
|
|
object.renderOrder = this.renderOrder;
|
|
if (Object.keys(this.userData).length > 0)
|
|
object.userData = this.userData;
|
|
object.layers = this.layers.mask;
|
|
object.matrix = this.matrix.toArray();
|
|
object.up = this.up.toArray();
|
|
if (this.matrixAutoUpdate === false)
|
|
object.matrixAutoUpdate = false;
|
|
if (this.isInstancedMesh) {
|
|
object.type = "InstancedMesh";
|
|
object.count = this.count;
|
|
object.instanceMatrix = this.instanceMatrix.toJSON();
|
|
if (this.instanceColor !== null)
|
|
object.instanceColor = this.instanceColor.toJSON();
|
|
}
|
|
if (this.isBatchedMesh) {
|
|
object.type = "BatchedMesh";
|
|
object.perObjectFrustumCulled = this.perObjectFrustumCulled;
|
|
object.sortObjects = this.sortObjects;
|
|
object.drawRanges = this._drawRanges;
|
|
object.reservedRanges = this._reservedRanges;
|
|
object.visibility = this._visibility;
|
|
object.active = this._active;
|
|
object.bounds = this._bounds.map((bound) => ({
|
|
boxInitialized: bound.boxInitialized,
|
|
boxMin: bound.box.min.toArray(),
|
|
boxMax: bound.box.max.toArray(),
|
|
sphereInitialized: bound.sphereInitialized,
|
|
sphereRadius: bound.sphere.radius,
|
|
sphereCenter: bound.sphere.center.toArray()
|
|
}));
|
|
object.maxInstanceCount = this._maxInstanceCount;
|
|
object.maxVertexCount = this._maxVertexCount;
|
|
object.maxIndexCount = this._maxIndexCount;
|
|
object.geometryInitialized = this._geometryInitialized;
|
|
object.geometryCount = this._geometryCount;
|
|
object.matricesTexture = this._matricesTexture.toJSON(meta);
|
|
if (this._colorsTexture !== null)
|
|
object.colorsTexture = this._colorsTexture.toJSON(meta);
|
|
if (this.boundingSphere !== null) {
|
|
object.boundingSphere = {
|
|
center: object.boundingSphere.center.toArray(),
|
|
radius: object.boundingSphere.radius
|
|
};
|
|
}
|
|
if (this.boundingBox !== null) {
|
|
object.boundingBox = {
|
|
min: object.boundingBox.min.toArray(),
|
|
max: object.boundingBox.max.toArray()
|
|
};
|
|
}
|
|
}
|
|
function serialize(library, element) {
|
|
if (library[element.uuid] === undefined) {
|
|
library[element.uuid] = element.toJSON(meta);
|
|
}
|
|
return element.uuid;
|
|
}
|
|
if (this.isScene) {
|
|
if (this.background) {
|
|
if (this.background.isColor) {
|
|
object.background = this.background.toJSON();
|
|
} else if (this.background.isTexture) {
|
|
object.background = this.background.toJSON(meta).uuid;
|
|
}
|
|
}
|
|
if (this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true) {
|
|
object.environment = this.environment.toJSON(meta).uuid;
|
|
}
|
|
} else if (this.isMesh || this.isLine || this.isPoints) {
|
|
object.geometry = serialize(meta.geometries, this.geometry);
|
|
const parameters = this.geometry.parameters;
|
|
if (parameters !== undefined && parameters.shapes !== undefined) {
|
|
const shapes = parameters.shapes;
|
|
if (Array.isArray(shapes)) {
|
|
for (let i = 0, l = shapes.length;i < l; i++) {
|
|
const shape = shapes[i];
|
|
serialize(meta.shapes, shape);
|
|
}
|
|
} else {
|
|
serialize(meta.shapes, shapes);
|
|
}
|
|
}
|
|
}
|
|
if (this.isSkinnedMesh) {
|
|
object.bindMode = this.bindMode;
|
|
object.bindMatrix = this.bindMatrix.toArray();
|
|
if (this.skeleton !== undefined) {
|
|
serialize(meta.skeletons, this.skeleton);
|
|
object.skeleton = this.skeleton.uuid;
|
|
}
|
|
}
|
|
if (this.material !== undefined) {
|
|
if (Array.isArray(this.material)) {
|
|
const uuids = [];
|
|
for (let i = 0, l = this.material.length;i < l; i++) {
|
|
uuids.push(serialize(meta.materials, this.material[i]));
|
|
}
|
|
object.material = uuids;
|
|
} else {
|
|
object.material = serialize(meta.materials, this.material);
|
|
}
|
|
}
|
|
if (this.children.length > 0) {
|
|
object.children = [];
|
|
for (let i = 0;i < this.children.length; i++) {
|
|
object.children.push(this.children[i].toJSON(meta).object);
|
|
}
|
|
}
|
|
if (this.animations.length > 0) {
|
|
object.animations = [];
|
|
for (let i = 0;i < this.animations.length; i++) {
|
|
const animation = this.animations[i];
|
|
object.animations.push(serialize(meta.animations, animation));
|
|
}
|
|
}
|
|
if (isRootObject) {
|
|
const geometries = extractFromCache(meta.geometries);
|
|
const materials = extractFromCache(meta.materials);
|
|
const textures = extractFromCache(meta.textures);
|
|
const images = extractFromCache(meta.images);
|
|
const shapes = extractFromCache(meta.shapes);
|
|
const skeletons = extractFromCache(meta.skeletons);
|
|
const animations = extractFromCache(meta.animations);
|
|
const nodes = extractFromCache(meta.nodes);
|
|
if (geometries.length > 0)
|
|
output.geometries = geometries;
|
|
if (materials.length > 0)
|
|
output.materials = materials;
|
|
if (textures.length > 0)
|
|
output.textures = textures;
|
|
if (images.length > 0)
|
|
output.images = images;
|
|
if (shapes.length > 0)
|
|
output.shapes = shapes;
|
|
if (skeletons.length > 0)
|
|
output.skeletons = skeletons;
|
|
if (animations.length > 0)
|
|
output.animations = animations;
|
|
if (nodes.length > 0)
|
|
output.nodes = nodes;
|
|
}
|
|
output.object = object;
|
|
return output;
|
|
function extractFromCache(cache) {
|
|
const values = [];
|
|
for (const key in cache) {
|
|
const data = cache[key];
|
|
delete data.metadata;
|
|
values.push(data);
|
|
}
|
|
return values;
|
|
}
|
|
}
|
|
clone(recursive) {
|
|
return new this.constructor().copy(this, recursive);
|
|
}
|
|
copy(source, recursive = true) {
|
|
this.name = source.name;
|
|
this.up.copy(source.up);
|
|
this.position.copy(source.position);
|
|
this.rotation.order = source.rotation.order;
|
|
this.quaternion.copy(source.quaternion);
|
|
this.scale.copy(source.scale);
|
|
this.matrix.copy(source.matrix);
|
|
this.matrixWorld.copy(source.matrixWorld);
|
|
this.matrixAutoUpdate = source.matrixAutoUpdate;
|
|
this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate;
|
|
this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
|
|
this.layers.mask = source.layers.mask;
|
|
this.visible = source.visible;
|
|
this.castShadow = source.castShadow;
|
|
this.receiveShadow = source.receiveShadow;
|
|
this.frustumCulled = source.frustumCulled;
|
|
this.renderOrder = source.renderOrder;
|
|
this.animations = source.animations.slice();
|
|
this.userData = JSON.parse(JSON.stringify(source.userData));
|
|
if (recursive === true) {
|
|
for (let i = 0;i < source.children.length; i++) {
|
|
const child = source.children[i];
|
|
this.add(child.clone());
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
Object3D.DEFAULT_UP = /* @__PURE__ */ new Vector3(0, 1, 0);
|
|
Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true;
|
|
Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;
|
|
_v0$1 = /* @__PURE__ */ new Vector3;
|
|
_v1$3 = /* @__PURE__ */ new Vector3;
|
|
_v2$2 = /* @__PURE__ */ new Vector3;
|
|
_v3$2 = /* @__PURE__ */ new Vector3;
|
|
_vab = /* @__PURE__ */ new Vector3;
|
|
_vac = /* @__PURE__ */ new Vector3;
|
|
_vbc = /* @__PURE__ */ new Vector3;
|
|
_vap = /* @__PURE__ */ new Vector3;
|
|
_vbp = /* @__PURE__ */ new Vector3;
|
|
_vcp = /* @__PURE__ */ new Vector3;
|
|
_v40 = /* @__PURE__ */ new Vector4;
|
|
_v41 = /* @__PURE__ */ new Vector4;
|
|
_v42 = /* @__PURE__ */ new Vector4;
|
|
_colorKeywords = {
|
|
aliceblue: 15792383,
|
|
antiquewhite: 16444375,
|
|
aqua: 65535,
|
|
aquamarine: 8388564,
|
|
azure: 15794175,
|
|
beige: 16119260,
|
|
bisque: 16770244,
|
|
black: 0,
|
|
blanchedalmond: 16772045,
|
|
blue: 255,
|
|
blueviolet: 9055202,
|
|
brown: 10824234,
|
|
burlywood: 14596231,
|
|
cadetblue: 6266528,
|
|
chartreuse: 8388352,
|
|
chocolate: 13789470,
|
|
coral: 16744272,
|
|
cornflowerblue: 6591981,
|
|
cornsilk: 16775388,
|
|
crimson: 14423100,
|
|
cyan: 65535,
|
|
darkblue: 139,
|
|
darkcyan: 35723,
|
|
darkgoldenrod: 12092939,
|
|
darkgray: 11119017,
|
|
darkgreen: 25600,
|
|
darkgrey: 11119017,
|
|
darkkhaki: 12433259,
|
|
darkmagenta: 9109643,
|
|
darkolivegreen: 5597999,
|
|
darkorange: 16747520,
|
|
darkorchid: 10040012,
|
|
darkred: 9109504,
|
|
darksalmon: 15308410,
|
|
darkseagreen: 9419919,
|
|
darkslateblue: 4734347,
|
|
darkslategray: 3100495,
|
|
darkslategrey: 3100495,
|
|
darkturquoise: 52945,
|
|
darkviolet: 9699539,
|
|
deeppink: 16716947,
|
|
deepskyblue: 49151,
|
|
dimgray: 6908265,
|
|
dimgrey: 6908265,
|
|
dodgerblue: 2003199,
|
|
firebrick: 11674146,
|
|
floralwhite: 16775920,
|
|
forestgreen: 2263842,
|
|
fuchsia: 16711935,
|
|
gainsboro: 14474460,
|
|
ghostwhite: 16316671,
|
|
gold: 16766720,
|
|
goldenrod: 14329120,
|
|
gray: 8421504,
|
|
green: 32768,
|
|
greenyellow: 11403055,
|
|
grey: 8421504,
|
|
honeydew: 15794160,
|
|
hotpink: 16738740,
|
|
indianred: 13458524,
|
|
indigo: 4915330,
|
|
ivory: 16777200,
|
|
khaki: 15787660,
|
|
lavender: 15132410,
|
|
lavenderblush: 16773365,
|
|
lawngreen: 8190976,
|
|
lemonchiffon: 16775885,
|
|
lightblue: 11393254,
|
|
lightcoral: 15761536,
|
|
lightcyan: 14745599,
|
|
lightgoldenrodyellow: 16448210,
|
|
lightgray: 13882323,
|
|
lightgreen: 9498256,
|
|
lightgrey: 13882323,
|
|
lightpink: 16758465,
|
|
lightsalmon: 16752762,
|
|
lightseagreen: 2142890,
|
|
lightskyblue: 8900346,
|
|
lightslategray: 7833753,
|
|
lightslategrey: 7833753,
|
|
lightsteelblue: 11584734,
|
|
lightyellow: 16777184,
|
|
lime: 65280,
|
|
limegreen: 3329330,
|
|
linen: 16445670,
|
|
magenta: 16711935,
|
|
maroon: 8388608,
|
|
mediumaquamarine: 6737322,
|
|
mediumblue: 205,
|
|
mediumorchid: 12211667,
|
|
mediumpurple: 9662683,
|
|
mediumseagreen: 3978097,
|
|
mediumslateblue: 8087790,
|
|
mediumspringgreen: 64154,
|
|
mediumturquoise: 4772300,
|
|
mediumvioletred: 13047173,
|
|
midnightblue: 1644912,
|
|
mintcream: 16121850,
|
|
mistyrose: 16770273,
|
|
moccasin: 16770229,
|
|
navajowhite: 16768685,
|
|
navy: 128,
|
|
oldlace: 16643558,
|
|
olive: 8421376,
|
|
olivedrab: 7048739,
|
|
orange: 16753920,
|
|
orangered: 16729344,
|
|
orchid: 14315734,
|
|
palegoldenrod: 15657130,
|
|
palegreen: 10025880,
|
|
paleturquoise: 11529966,
|
|
palevioletred: 14381203,
|
|
papayawhip: 16773077,
|
|
peachpuff: 16767673,
|
|
peru: 13468991,
|
|
pink: 16761035,
|
|
plum: 14524637,
|
|
powderblue: 11591910,
|
|
purple: 8388736,
|
|
rebeccapurple: 6697881,
|
|
red: 16711680,
|
|
rosybrown: 12357519,
|
|
royalblue: 4286945,
|
|
saddlebrown: 9127187,
|
|
salmon: 16416882,
|
|
sandybrown: 16032864,
|
|
seagreen: 3050327,
|
|
seashell: 16774638,
|
|
sienna: 10506797,
|
|
silver: 12632256,
|
|
skyblue: 8900331,
|
|
slateblue: 6970061,
|
|
slategray: 7372944,
|
|
slategrey: 7372944,
|
|
snow: 16775930,
|
|
springgreen: 65407,
|
|
steelblue: 4620980,
|
|
tan: 13808780,
|
|
teal: 32896,
|
|
thistle: 14204888,
|
|
tomato: 16737095,
|
|
turquoise: 4251856,
|
|
violet: 15631086,
|
|
wheat: 16113331,
|
|
white: 16777215,
|
|
whitesmoke: 16119285,
|
|
yellow: 16776960,
|
|
yellowgreen: 10145074
|
|
};
|
|
_hslA = { h: 0, s: 0, l: 0 };
|
|
_hslB = { h: 0, s: 0, l: 0 };
|
|
Color = class Color {
|
|
constructor(r, g, b) {
|
|
this.isColor = true;
|
|
this.r = 1;
|
|
this.g = 1;
|
|
this.b = 1;
|
|
return this.set(r, g, b);
|
|
}
|
|
set(r, g, b) {
|
|
if (g === undefined && b === undefined) {
|
|
const value = r;
|
|
if (value && value.isColor) {
|
|
this.copy(value);
|
|
} else if (typeof value === "number") {
|
|
this.setHex(value);
|
|
} else if (typeof value === "string") {
|
|
this.setStyle(value);
|
|
}
|
|
} else {
|
|
this.setRGB(r, g, b);
|
|
}
|
|
return this;
|
|
}
|
|
setScalar(scalar) {
|
|
this.r = scalar;
|
|
this.g = scalar;
|
|
this.b = scalar;
|
|
return this;
|
|
}
|
|
setHex(hex, colorSpace = SRGBColorSpace) {
|
|
hex = Math.floor(hex);
|
|
this.r = (hex >> 16 & 255) / 255;
|
|
this.g = (hex >> 8 & 255) / 255;
|
|
this.b = (hex & 255) / 255;
|
|
ColorManagement.toWorkingColorSpace(this, colorSpace);
|
|
return this;
|
|
}
|
|
setRGB(r, g, b, colorSpace = ColorManagement.workingColorSpace) {
|
|
this.r = r;
|
|
this.g = g;
|
|
this.b = b;
|
|
ColorManagement.toWorkingColorSpace(this, colorSpace);
|
|
return this;
|
|
}
|
|
setHSL(h, s, l, colorSpace = ColorManagement.workingColorSpace) {
|
|
h = euclideanModulo(h, 1);
|
|
s = clamp(s, 0, 1);
|
|
l = clamp(l, 0, 1);
|
|
if (s === 0) {
|
|
this.r = this.g = this.b = l;
|
|
} else {
|
|
const p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
|
|
const q = 2 * l - p;
|
|
this.r = hue2rgb(q, p, h + 1 / 3);
|
|
this.g = hue2rgb(q, p, h);
|
|
this.b = hue2rgb(q, p, h - 1 / 3);
|
|
}
|
|
ColorManagement.toWorkingColorSpace(this, colorSpace);
|
|
return this;
|
|
}
|
|
setStyle(style, colorSpace = SRGBColorSpace) {
|
|
function handleAlpha(string) {
|
|
if (string === undefined)
|
|
return;
|
|
if (parseFloat(string) < 1) {
|
|
console.warn("THREE.Color: Alpha component of " + style + " will be ignored.");
|
|
}
|
|
}
|
|
let m;
|
|
if (m = /^(\w+)\(([^\)]*)\)/.exec(style)) {
|
|
let color;
|
|
const name = m[1];
|
|
const components = m[2];
|
|
switch (name) {
|
|
case "rgb":
|
|
case "rgba":
|
|
if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
|
|
handleAlpha(color[4]);
|
|
return this.setRGB(Math.min(255, parseInt(color[1], 10)) / 255, Math.min(255, parseInt(color[2], 10)) / 255, Math.min(255, parseInt(color[3], 10)) / 255, colorSpace);
|
|
}
|
|
if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
|
|
handleAlpha(color[4]);
|
|
return this.setRGB(Math.min(100, parseInt(color[1], 10)) / 100, Math.min(100, parseInt(color[2], 10)) / 100, Math.min(100, parseInt(color[3], 10)) / 100, colorSpace);
|
|
}
|
|
break;
|
|
case "hsl":
|
|
case "hsla":
|
|
if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
|
|
handleAlpha(color[4]);
|
|
return this.setHSL(parseFloat(color[1]) / 360, parseFloat(color[2]) / 100, parseFloat(color[3]) / 100, colorSpace);
|
|
}
|
|
break;
|
|
default:
|
|
console.warn("THREE.Color: Unknown color model " + style);
|
|
}
|
|
} else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
|
|
const hex = m[1];
|
|
const size = hex.length;
|
|
if (size === 3) {
|
|
return this.setRGB(parseInt(hex.charAt(0), 16) / 15, parseInt(hex.charAt(1), 16) / 15, parseInt(hex.charAt(2), 16) / 15, colorSpace);
|
|
} else if (size === 6) {
|
|
return this.setHex(parseInt(hex, 16), colorSpace);
|
|
} else {
|
|
console.warn("THREE.Color: Invalid hex color " + style);
|
|
}
|
|
} else if (style && style.length > 0) {
|
|
return this.setColorName(style, colorSpace);
|
|
}
|
|
return this;
|
|
}
|
|
setColorName(style, colorSpace = SRGBColorSpace) {
|
|
const hex = _colorKeywords[style.toLowerCase()];
|
|
if (hex !== undefined) {
|
|
this.setHex(hex, colorSpace);
|
|
} else {
|
|
console.warn("THREE.Color: Unknown color " + style);
|
|
}
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor(this.r, this.g, this.b);
|
|
}
|
|
copy(color) {
|
|
this.r = color.r;
|
|
this.g = color.g;
|
|
this.b = color.b;
|
|
return this;
|
|
}
|
|
copySRGBToLinear(color) {
|
|
this.r = SRGBToLinear(color.r);
|
|
this.g = SRGBToLinear(color.g);
|
|
this.b = SRGBToLinear(color.b);
|
|
return this;
|
|
}
|
|
copyLinearToSRGB(color) {
|
|
this.r = LinearToSRGB(color.r);
|
|
this.g = LinearToSRGB(color.g);
|
|
this.b = LinearToSRGB(color.b);
|
|
return this;
|
|
}
|
|
convertSRGBToLinear() {
|
|
this.copySRGBToLinear(this);
|
|
return this;
|
|
}
|
|
convertLinearToSRGB() {
|
|
this.copyLinearToSRGB(this);
|
|
return this;
|
|
}
|
|
getHex(colorSpace = SRGBColorSpace) {
|
|
ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace);
|
|
return Math.round(clamp(_color.r * 255, 0, 255)) * 65536 + Math.round(clamp(_color.g * 255, 0, 255)) * 256 + Math.round(clamp(_color.b * 255, 0, 255));
|
|
}
|
|
getHexString(colorSpace = SRGBColorSpace) {
|
|
return ("000000" + this.getHex(colorSpace).toString(16)).slice(-6);
|
|
}
|
|
getHSL(target, colorSpace = ColorManagement.workingColorSpace) {
|
|
ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace);
|
|
const { r, g, b } = _color;
|
|
const max = Math.max(r, g, b);
|
|
const min = Math.min(r, g, b);
|
|
let hue, saturation;
|
|
const lightness = (min + max) / 2;
|
|
if (min === max) {
|
|
hue = 0;
|
|
saturation = 0;
|
|
} else {
|
|
const delta = max - min;
|
|
saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
|
|
switch (max) {
|
|
case r:
|
|
hue = (g - b) / delta + (g < b ? 6 : 0);
|
|
break;
|
|
case g:
|
|
hue = (b - r) / delta + 2;
|
|
break;
|
|
case b:
|
|
hue = (r - g) / delta + 4;
|
|
break;
|
|
}
|
|
hue /= 6;
|
|
}
|
|
target.h = hue;
|
|
target.s = saturation;
|
|
target.l = lightness;
|
|
return target;
|
|
}
|
|
getRGB(target, colorSpace = ColorManagement.workingColorSpace) {
|
|
ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace);
|
|
target.r = _color.r;
|
|
target.g = _color.g;
|
|
target.b = _color.b;
|
|
return target;
|
|
}
|
|
getStyle(colorSpace = SRGBColorSpace) {
|
|
ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace);
|
|
const { r, g, b } = _color;
|
|
if (colorSpace !== SRGBColorSpace) {
|
|
return `color(${colorSpace} ${r.toFixed(3)} ${g.toFixed(3)} ${b.toFixed(3)})`;
|
|
}
|
|
return `rgb(${Math.round(r * 255)},${Math.round(g * 255)},${Math.round(b * 255)})`;
|
|
}
|
|
offsetHSL(h, s, l) {
|
|
this.getHSL(_hslA);
|
|
return this.setHSL(_hslA.h + h, _hslA.s + s, _hslA.l + l);
|
|
}
|
|
add(color) {
|
|
this.r += color.r;
|
|
this.g += color.g;
|
|
this.b += color.b;
|
|
return this;
|
|
}
|
|
addColors(color1, color2) {
|
|
this.r = color1.r + color2.r;
|
|
this.g = color1.g + color2.g;
|
|
this.b = color1.b + color2.b;
|
|
return this;
|
|
}
|
|
addScalar(s) {
|
|
this.r += s;
|
|
this.g += s;
|
|
this.b += s;
|
|
return this;
|
|
}
|
|
sub(color) {
|
|
this.r = Math.max(0, this.r - color.r);
|
|
this.g = Math.max(0, this.g - color.g);
|
|
this.b = Math.max(0, this.b - color.b);
|
|
return this;
|
|
}
|
|
multiply(color) {
|
|
this.r *= color.r;
|
|
this.g *= color.g;
|
|
this.b *= color.b;
|
|
return this;
|
|
}
|
|
multiplyScalar(s) {
|
|
this.r *= s;
|
|
this.g *= s;
|
|
this.b *= s;
|
|
return this;
|
|
}
|
|
lerp(color, alpha) {
|
|
this.r += (color.r - this.r) * alpha;
|
|
this.g += (color.g - this.g) * alpha;
|
|
this.b += (color.b - this.b) * alpha;
|
|
return this;
|
|
}
|
|
lerpColors(color1, color2, alpha) {
|
|
this.r = color1.r + (color2.r - color1.r) * alpha;
|
|
this.g = color1.g + (color2.g - color1.g) * alpha;
|
|
this.b = color1.b + (color2.b - color1.b) * alpha;
|
|
return this;
|
|
}
|
|
lerpHSL(color, alpha) {
|
|
this.getHSL(_hslA);
|
|
color.getHSL(_hslB);
|
|
const h = lerp(_hslA.h, _hslB.h, alpha);
|
|
const s = lerp(_hslA.s, _hslB.s, alpha);
|
|
const l = lerp(_hslA.l, _hslB.l, alpha);
|
|
this.setHSL(h, s, l);
|
|
return this;
|
|
}
|
|
setFromVector3(v) {
|
|
this.r = v.x;
|
|
this.g = v.y;
|
|
this.b = v.z;
|
|
return this;
|
|
}
|
|
applyMatrix3(m) {
|
|
const r = this.r, g = this.g, b = this.b;
|
|
const e = m.elements;
|
|
this.r = e[0] * r + e[3] * g + e[6] * b;
|
|
this.g = e[1] * r + e[4] * g + e[7] * b;
|
|
this.b = e[2] * r + e[5] * g + e[8] * b;
|
|
return this;
|
|
}
|
|
equals(c) {
|
|
return c.r === this.r && c.g === this.g && c.b === this.b;
|
|
}
|
|
fromArray(array, offset = 0) {
|
|
this.r = array[offset];
|
|
this.g = array[offset + 1];
|
|
this.b = array[offset + 2];
|
|
return this;
|
|
}
|
|
toArray(array = [], offset = 0) {
|
|
array[offset] = this.r;
|
|
array[offset + 1] = this.g;
|
|
array[offset + 2] = this.b;
|
|
return array;
|
|
}
|
|
fromBufferAttribute(attribute, index) {
|
|
this.r = attribute.getX(index);
|
|
this.g = attribute.getY(index);
|
|
this.b = attribute.getZ(index);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
return this.getHex();
|
|
}
|
|
*[Symbol.iterator]() {
|
|
yield this.r;
|
|
yield this.g;
|
|
yield this.b;
|
|
}
|
|
};
|
|
_color = /* @__PURE__ */ new Color;
|
|
Color.NAMES = _colorKeywords;
|
|
Material = class Material extends EventDispatcher {
|
|
constructor() {
|
|
super();
|
|
this.isMaterial = true;
|
|
Object.defineProperty(this, "id", { value: _materialId++ });
|
|
this.uuid = generateUUID();
|
|
this.name = "";
|
|
this.type = "Material";
|
|
this.blending = NormalBlending;
|
|
this.side = FrontSide;
|
|
this.vertexColors = false;
|
|
this.opacity = 1;
|
|
this.transparent = false;
|
|
this.alphaHash = false;
|
|
this.blendSrc = SrcAlphaFactor;
|
|
this.blendDst = OneMinusSrcAlphaFactor;
|
|
this.blendEquation = AddEquation;
|
|
this.blendSrcAlpha = null;
|
|
this.blendDstAlpha = null;
|
|
this.blendEquationAlpha = null;
|
|
this.blendColor = new Color(0, 0, 0);
|
|
this.blendAlpha = 0;
|
|
this.depthFunc = LessEqualDepth;
|
|
this.depthTest = true;
|
|
this.depthWrite = true;
|
|
this.stencilWriteMask = 255;
|
|
this.stencilFunc = AlwaysStencilFunc;
|
|
this.stencilRef = 0;
|
|
this.stencilFuncMask = 255;
|
|
this.stencilFail = KeepStencilOp;
|
|
this.stencilZFail = KeepStencilOp;
|
|
this.stencilZPass = KeepStencilOp;
|
|
this.stencilWrite = false;
|
|
this.clippingPlanes = null;
|
|
this.clipIntersection = false;
|
|
this.clipShadows = false;
|
|
this.shadowSide = null;
|
|
this.colorWrite = true;
|
|
this.precision = null;
|
|
this.polygonOffset = false;
|
|
this.polygonOffsetFactor = 0;
|
|
this.polygonOffsetUnits = 0;
|
|
this.dithering = false;
|
|
this.alphaToCoverage = false;
|
|
this.premultipliedAlpha = false;
|
|
this.forceSinglePass = false;
|
|
this.visible = true;
|
|
this.toneMapped = true;
|
|
this.userData = {};
|
|
this.version = 0;
|
|
this._alphaTest = 0;
|
|
}
|
|
get alphaTest() {
|
|
return this._alphaTest;
|
|
}
|
|
set alphaTest(value) {
|
|
if (this._alphaTest > 0 !== value > 0) {
|
|
this.version++;
|
|
}
|
|
this._alphaTest = value;
|
|
}
|
|
onBeforeRender() {}
|
|
onBeforeCompile() {}
|
|
customProgramCacheKey() {
|
|
return this.onBeforeCompile.toString();
|
|
}
|
|
setValues(values) {
|
|
if (values === undefined)
|
|
return;
|
|
for (const key in values) {
|
|
const newValue = values[key];
|
|
if (newValue === undefined) {
|
|
console.warn(`THREE.Material: parameter '${key}' has value of undefined.`);
|
|
continue;
|
|
}
|
|
const currentValue = this[key];
|
|
if (currentValue === undefined) {
|
|
console.warn(`THREE.Material: '${key}' is not a property of THREE.${this.type}.`);
|
|
continue;
|
|
}
|
|
if (currentValue && currentValue.isColor) {
|
|
currentValue.set(newValue);
|
|
} else if (currentValue && currentValue.isVector3 && (newValue && newValue.isVector3)) {
|
|
currentValue.copy(newValue);
|
|
} else {
|
|
this[key] = newValue;
|
|
}
|
|
}
|
|
}
|
|
toJSON(meta) {
|
|
const isRootObject = meta === undefined || typeof meta === "string";
|
|
if (isRootObject) {
|
|
meta = {
|
|
textures: {},
|
|
images: {}
|
|
};
|
|
}
|
|
const data = {
|
|
metadata: {
|
|
version: 4.6,
|
|
type: "Material",
|
|
generator: "Material.toJSON"
|
|
}
|
|
};
|
|
data.uuid = this.uuid;
|
|
data.type = this.type;
|
|
if (this.name !== "")
|
|
data.name = this.name;
|
|
if (this.color && this.color.isColor)
|
|
data.color = this.color.getHex();
|
|
if (this.roughness !== undefined)
|
|
data.roughness = this.roughness;
|
|
if (this.metalness !== undefined)
|
|
data.metalness = this.metalness;
|
|
if (this.sheen !== undefined)
|
|
data.sheen = this.sheen;
|
|
if (this.sheenColor && this.sheenColor.isColor)
|
|
data.sheenColor = this.sheenColor.getHex();
|
|
if (this.sheenRoughness !== undefined)
|
|
data.sheenRoughness = this.sheenRoughness;
|
|
if (this.emissive && this.emissive.isColor)
|
|
data.emissive = this.emissive.getHex();
|
|
if (this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1)
|
|
data.emissiveIntensity = this.emissiveIntensity;
|
|
if (this.specular && this.specular.isColor)
|
|
data.specular = this.specular.getHex();
|
|
if (this.specularIntensity !== undefined)
|
|
data.specularIntensity = this.specularIntensity;
|
|
if (this.specularColor && this.specularColor.isColor)
|
|
data.specularColor = this.specularColor.getHex();
|
|
if (this.shininess !== undefined)
|
|
data.shininess = this.shininess;
|
|
if (this.clearcoat !== undefined)
|
|
data.clearcoat = this.clearcoat;
|
|
if (this.clearcoatRoughness !== undefined)
|
|
data.clearcoatRoughness = this.clearcoatRoughness;
|
|
if (this.clearcoatMap && this.clearcoatMap.isTexture) {
|
|
data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
|
|
}
|
|
if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
|
|
data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
|
|
}
|
|
if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
|
|
data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
|
|
data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
|
|
}
|
|
if (this.dispersion !== undefined)
|
|
data.dispersion = this.dispersion;
|
|
if (this.iridescence !== undefined)
|
|
data.iridescence = this.iridescence;
|
|
if (this.iridescenceIOR !== undefined)
|
|
data.iridescenceIOR = this.iridescenceIOR;
|
|
if (this.iridescenceThicknessRange !== undefined)
|
|
data.iridescenceThicknessRange = this.iridescenceThicknessRange;
|
|
if (this.iridescenceMap && this.iridescenceMap.isTexture) {
|
|
data.iridescenceMap = this.iridescenceMap.toJSON(meta).uuid;
|
|
}
|
|
if (this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture) {
|
|
data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON(meta).uuid;
|
|
}
|
|
if (this.anisotropy !== undefined)
|
|
data.anisotropy = this.anisotropy;
|
|
if (this.anisotropyRotation !== undefined)
|
|
data.anisotropyRotation = this.anisotropyRotation;
|
|
if (this.anisotropyMap && this.anisotropyMap.isTexture) {
|
|
data.anisotropyMap = this.anisotropyMap.toJSON(meta).uuid;
|
|
}
|
|
if (this.map && this.map.isTexture)
|
|
data.map = this.map.toJSON(meta).uuid;
|
|
if (this.matcap && this.matcap.isTexture)
|
|
data.matcap = this.matcap.toJSON(meta).uuid;
|
|
if (this.alphaMap && this.alphaMap.isTexture)
|
|
data.alphaMap = this.alphaMap.toJSON(meta).uuid;
|
|
if (this.lightMap && this.lightMap.isTexture) {
|
|
data.lightMap = this.lightMap.toJSON(meta).uuid;
|
|
data.lightMapIntensity = this.lightMapIntensity;
|
|
}
|
|
if (this.aoMap && this.aoMap.isTexture) {
|
|
data.aoMap = this.aoMap.toJSON(meta).uuid;
|
|
data.aoMapIntensity = this.aoMapIntensity;
|
|
}
|
|
if (this.bumpMap && this.bumpMap.isTexture) {
|
|
data.bumpMap = this.bumpMap.toJSON(meta).uuid;
|
|
data.bumpScale = this.bumpScale;
|
|
}
|
|
if (this.normalMap && this.normalMap.isTexture) {
|
|
data.normalMap = this.normalMap.toJSON(meta).uuid;
|
|
data.normalMapType = this.normalMapType;
|
|
data.normalScale = this.normalScale.toArray();
|
|
}
|
|
if (this.displacementMap && this.displacementMap.isTexture) {
|
|
data.displacementMap = this.displacementMap.toJSON(meta).uuid;
|
|
data.displacementScale = this.displacementScale;
|
|
data.displacementBias = this.displacementBias;
|
|
}
|
|
if (this.roughnessMap && this.roughnessMap.isTexture)
|
|
data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
|
|
if (this.metalnessMap && this.metalnessMap.isTexture)
|
|
data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
|
|
if (this.emissiveMap && this.emissiveMap.isTexture)
|
|
data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
|
|
if (this.specularMap && this.specularMap.isTexture)
|
|
data.specularMap = this.specularMap.toJSON(meta).uuid;
|
|
if (this.specularIntensityMap && this.specularIntensityMap.isTexture)
|
|
data.specularIntensityMap = this.specularIntensityMap.toJSON(meta).uuid;
|
|
if (this.specularColorMap && this.specularColorMap.isTexture)
|
|
data.specularColorMap = this.specularColorMap.toJSON(meta).uuid;
|
|
if (this.envMap && this.envMap.isTexture) {
|
|
data.envMap = this.envMap.toJSON(meta).uuid;
|
|
if (this.combine !== undefined)
|
|
data.combine = this.combine;
|
|
}
|
|
if (this.envMapRotation !== undefined)
|
|
data.envMapRotation = this.envMapRotation.toArray();
|
|
if (this.envMapIntensity !== undefined)
|
|
data.envMapIntensity = this.envMapIntensity;
|
|
if (this.reflectivity !== undefined)
|
|
data.reflectivity = this.reflectivity;
|
|
if (this.refractionRatio !== undefined)
|
|
data.refractionRatio = this.refractionRatio;
|
|
if (this.gradientMap && this.gradientMap.isTexture) {
|
|
data.gradientMap = this.gradientMap.toJSON(meta).uuid;
|
|
}
|
|
if (this.transmission !== undefined)
|
|
data.transmission = this.transmission;
|
|
if (this.transmissionMap && this.transmissionMap.isTexture)
|
|
data.transmissionMap = this.transmissionMap.toJSON(meta).uuid;
|
|
if (this.thickness !== undefined)
|
|
data.thickness = this.thickness;
|
|
if (this.thicknessMap && this.thicknessMap.isTexture)
|
|
data.thicknessMap = this.thicknessMap.toJSON(meta).uuid;
|
|
if (this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity)
|
|
data.attenuationDistance = this.attenuationDistance;
|
|
if (this.attenuationColor !== undefined)
|
|
data.attenuationColor = this.attenuationColor.getHex();
|
|
if (this.size !== undefined)
|
|
data.size = this.size;
|
|
if (this.shadowSide !== null)
|
|
data.shadowSide = this.shadowSide;
|
|
if (this.sizeAttenuation !== undefined)
|
|
data.sizeAttenuation = this.sizeAttenuation;
|
|
if (this.blending !== NormalBlending)
|
|
data.blending = this.blending;
|
|
if (this.side !== FrontSide)
|
|
data.side = this.side;
|
|
if (this.vertexColors === true)
|
|
data.vertexColors = true;
|
|
if (this.opacity < 1)
|
|
data.opacity = this.opacity;
|
|
if (this.transparent === true)
|
|
data.transparent = true;
|
|
if (this.blendSrc !== SrcAlphaFactor)
|
|
data.blendSrc = this.blendSrc;
|
|
if (this.blendDst !== OneMinusSrcAlphaFactor)
|
|
data.blendDst = this.blendDst;
|
|
if (this.blendEquation !== AddEquation)
|
|
data.blendEquation = this.blendEquation;
|
|
if (this.blendSrcAlpha !== null)
|
|
data.blendSrcAlpha = this.blendSrcAlpha;
|
|
if (this.blendDstAlpha !== null)
|
|
data.blendDstAlpha = this.blendDstAlpha;
|
|
if (this.blendEquationAlpha !== null)
|
|
data.blendEquationAlpha = this.blendEquationAlpha;
|
|
if (this.blendColor && this.blendColor.isColor)
|
|
data.blendColor = this.blendColor.getHex();
|
|
if (this.blendAlpha !== 0)
|
|
data.blendAlpha = this.blendAlpha;
|
|
if (this.depthFunc !== LessEqualDepth)
|
|
data.depthFunc = this.depthFunc;
|
|
if (this.depthTest === false)
|
|
data.depthTest = this.depthTest;
|
|
if (this.depthWrite === false)
|
|
data.depthWrite = this.depthWrite;
|
|
if (this.colorWrite === false)
|
|
data.colorWrite = this.colorWrite;
|
|
if (this.stencilWriteMask !== 255)
|
|
data.stencilWriteMask = this.stencilWriteMask;
|
|
if (this.stencilFunc !== AlwaysStencilFunc)
|
|
data.stencilFunc = this.stencilFunc;
|
|
if (this.stencilRef !== 0)
|
|
data.stencilRef = this.stencilRef;
|
|
if (this.stencilFuncMask !== 255)
|
|
data.stencilFuncMask = this.stencilFuncMask;
|
|
if (this.stencilFail !== KeepStencilOp)
|
|
data.stencilFail = this.stencilFail;
|
|
if (this.stencilZFail !== KeepStencilOp)
|
|
data.stencilZFail = this.stencilZFail;
|
|
if (this.stencilZPass !== KeepStencilOp)
|
|
data.stencilZPass = this.stencilZPass;
|
|
if (this.stencilWrite === true)
|
|
data.stencilWrite = this.stencilWrite;
|
|
if (this.rotation !== undefined && this.rotation !== 0)
|
|
data.rotation = this.rotation;
|
|
if (this.polygonOffset === true)
|
|
data.polygonOffset = true;
|
|
if (this.polygonOffsetFactor !== 0)
|
|
data.polygonOffsetFactor = this.polygonOffsetFactor;
|
|
if (this.polygonOffsetUnits !== 0)
|
|
data.polygonOffsetUnits = this.polygonOffsetUnits;
|
|
if (this.linewidth !== undefined && this.linewidth !== 1)
|
|
data.linewidth = this.linewidth;
|
|
if (this.dashSize !== undefined)
|
|
data.dashSize = this.dashSize;
|
|
if (this.gapSize !== undefined)
|
|
data.gapSize = this.gapSize;
|
|
if (this.scale !== undefined)
|
|
data.scale = this.scale;
|
|
if (this.dithering === true)
|
|
data.dithering = true;
|
|
if (this.alphaTest > 0)
|
|
data.alphaTest = this.alphaTest;
|
|
if (this.alphaHash === true)
|
|
data.alphaHash = true;
|
|
if (this.alphaToCoverage === true)
|
|
data.alphaToCoverage = true;
|
|
if (this.premultipliedAlpha === true)
|
|
data.premultipliedAlpha = true;
|
|
if (this.forceSinglePass === true)
|
|
data.forceSinglePass = true;
|
|
if (this.wireframe === true)
|
|
data.wireframe = true;
|
|
if (this.wireframeLinewidth > 1)
|
|
data.wireframeLinewidth = this.wireframeLinewidth;
|
|
if (this.wireframeLinecap !== "round")
|
|
data.wireframeLinecap = this.wireframeLinecap;
|
|
if (this.wireframeLinejoin !== "round")
|
|
data.wireframeLinejoin = this.wireframeLinejoin;
|
|
if (this.flatShading === true)
|
|
data.flatShading = true;
|
|
if (this.visible === false)
|
|
data.visible = false;
|
|
if (this.toneMapped === false)
|
|
data.toneMapped = false;
|
|
if (this.fog === false)
|
|
data.fog = false;
|
|
if (Object.keys(this.userData).length > 0)
|
|
data.userData = this.userData;
|
|
function extractFromCache(cache) {
|
|
const values = [];
|
|
for (const key in cache) {
|
|
const data2 = cache[key];
|
|
delete data2.metadata;
|
|
values.push(data2);
|
|
}
|
|
return values;
|
|
}
|
|
if (isRootObject) {
|
|
const textures = extractFromCache(meta.textures);
|
|
const images = extractFromCache(meta.images);
|
|
if (textures.length > 0)
|
|
data.textures = textures;
|
|
if (images.length > 0)
|
|
data.images = images;
|
|
}
|
|
return data;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
copy(source) {
|
|
this.name = source.name;
|
|
this.blending = source.blending;
|
|
this.side = source.side;
|
|
this.vertexColors = source.vertexColors;
|
|
this.opacity = source.opacity;
|
|
this.transparent = source.transparent;
|
|
this.blendSrc = source.blendSrc;
|
|
this.blendDst = source.blendDst;
|
|
this.blendEquation = source.blendEquation;
|
|
this.blendSrcAlpha = source.blendSrcAlpha;
|
|
this.blendDstAlpha = source.blendDstAlpha;
|
|
this.blendEquationAlpha = source.blendEquationAlpha;
|
|
this.blendColor.copy(source.blendColor);
|
|
this.blendAlpha = source.blendAlpha;
|
|
this.depthFunc = source.depthFunc;
|
|
this.depthTest = source.depthTest;
|
|
this.depthWrite = source.depthWrite;
|
|
this.stencilWriteMask = source.stencilWriteMask;
|
|
this.stencilFunc = source.stencilFunc;
|
|
this.stencilRef = source.stencilRef;
|
|
this.stencilFuncMask = source.stencilFuncMask;
|
|
this.stencilFail = source.stencilFail;
|
|
this.stencilZFail = source.stencilZFail;
|
|
this.stencilZPass = source.stencilZPass;
|
|
this.stencilWrite = source.stencilWrite;
|
|
const srcPlanes = source.clippingPlanes;
|
|
let dstPlanes = null;
|
|
if (srcPlanes !== null) {
|
|
const n = srcPlanes.length;
|
|
dstPlanes = new Array(n);
|
|
for (let i = 0;i !== n; ++i) {
|
|
dstPlanes[i] = srcPlanes[i].clone();
|
|
}
|
|
}
|
|
this.clippingPlanes = dstPlanes;
|
|
this.clipIntersection = source.clipIntersection;
|
|
this.clipShadows = source.clipShadows;
|
|
this.shadowSide = source.shadowSide;
|
|
this.colorWrite = source.colorWrite;
|
|
this.precision = source.precision;
|
|
this.polygonOffset = source.polygonOffset;
|
|
this.polygonOffsetFactor = source.polygonOffsetFactor;
|
|
this.polygonOffsetUnits = source.polygonOffsetUnits;
|
|
this.dithering = source.dithering;
|
|
this.alphaTest = source.alphaTest;
|
|
this.alphaHash = source.alphaHash;
|
|
this.alphaToCoverage = source.alphaToCoverage;
|
|
this.premultipliedAlpha = source.premultipliedAlpha;
|
|
this.forceSinglePass = source.forceSinglePass;
|
|
this.visible = source.visible;
|
|
this.toneMapped = source.toneMapped;
|
|
this.userData = JSON.parse(JSON.stringify(source.userData));
|
|
return this;
|
|
}
|
|
dispose() {
|
|
this.dispatchEvent({ type: "dispose" });
|
|
}
|
|
set needsUpdate(value) {
|
|
if (value === true)
|
|
this.version++;
|
|
}
|
|
onBuild() {
|
|
console.warn("Material: onBuild() has been removed.");
|
|
}
|
|
};
|
|
MeshBasicMaterial = class MeshBasicMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshBasicMaterial = true;
|
|
this.type = "MeshBasicMaterial";
|
|
this.color = new Color(16777215);
|
|
this.map = null;
|
|
this.lightMap = null;
|
|
this.lightMapIntensity = 1;
|
|
this.aoMap = null;
|
|
this.aoMapIntensity = 1;
|
|
this.specularMap = null;
|
|
this.alphaMap = null;
|
|
this.envMap = null;
|
|
this.envMapRotation = new Euler;
|
|
this.combine = MultiplyOperation;
|
|
this.reflectivity = 1;
|
|
this.refractionRatio = 0.98;
|
|
this.wireframe = false;
|
|
this.wireframeLinewidth = 1;
|
|
this.wireframeLinecap = "round";
|
|
this.wireframeLinejoin = "round";
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.color.copy(source.color);
|
|
this.map = source.map;
|
|
this.lightMap = source.lightMap;
|
|
this.lightMapIntensity = source.lightMapIntensity;
|
|
this.aoMap = source.aoMap;
|
|
this.aoMapIntensity = source.aoMapIntensity;
|
|
this.specularMap = source.specularMap;
|
|
this.alphaMap = source.alphaMap;
|
|
this.envMap = source.envMap;
|
|
this.envMapRotation.copy(source.envMapRotation);
|
|
this.combine = source.combine;
|
|
this.reflectivity = source.reflectivity;
|
|
this.refractionRatio = source.refractionRatio;
|
|
this.wireframe = source.wireframe;
|
|
this.wireframeLinewidth = source.wireframeLinewidth;
|
|
this.wireframeLinecap = source.wireframeLinecap;
|
|
this.wireframeLinejoin = source.wireframeLinejoin;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
_tables = /* @__PURE__ */ _generateTables();
|
|
DataUtils = {
|
|
toHalfFloat,
|
|
fromHalfFloat
|
|
};
|
|
_vector$9 = /* @__PURE__ */ new Vector3;
|
|
_vector2$1 = /* @__PURE__ */ new Vector2;
|
|
Int8BufferAttribute = class Int8BufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Int8Array(array), itemSize, normalized);
|
|
}
|
|
};
|
|
Uint8BufferAttribute = class Uint8BufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Uint8Array(array), itemSize, normalized);
|
|
}
|
|
};
|
|
Uint8ClampedBufferAttribute = class Uint8ClampedBufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Uint8ClampedArray(array), itemSize, normalized);
|
|
}
|
|
};
|
|
Int16BufferAttribute = class Int16BufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Int16Array(array), itemSize, normalized);
|
|
}
|
|
};
|
|
Uint16BufferAttribute = class Uint16BufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Uint16Array(array), itemSize, normalized);
|
|
}
|
|
};
|
|
Int32BufferAttribute = class Int32BufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Int32Array(array), itemSize, normalized);
|
|
}
|
|
};
|
|
Uint32BufferAttribute = class Uint32BufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Uint32Array(array), itemSize, normalized);
|
|
}
|
|
};
|
|
Float16BufferAttribute = class Float16BufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Uint16Array(array), itemSize, normalized);
|
|
this.isFloat16BufferAttribute = true;
|
|
}
|
|
getX(index) {
|
|
let x = fromHalfFloat(this.array[index * this.itemSize]);
|
|
if (this.normalized)
|
|
x = denormalize(x, this.array);
|
|
return x;
|
|
}
|
|
setX(index, x) {
|
|
if (this.normalized)
|
|
x = normalize(x, this.array);
|
|
this.array[index * this.itemSize] = toHalfFloat(x);
|
|
return this;
|
|
}
|
|
getY(index) {
|
|
let y = fromHalfFloat(this.array[index * this.itemSize + 1]);
|
|
if (this.normalized)
|
|
y = denormalize(y, this.array);
|
|
return y;
|
|
}
|
|
setY(index, y) {
|
|
if (this.normalized)
|
|
y = normalize(y, this.array);
|
|
this.array[index * this.itemSize + 1] = toHalfFloat(y);
|
|
return this;
|
|
}
|
|
getZ(index) {
|
|
let z = fromHalfFloat(this.array[index * this.itemSize + 2]);
|
|
if (this.normalized)
|
|
z = denormalize(z, this.array);
|
|
return z;
|
|
}
|
|
setZ(index, z) {
|
|
if (this.normalized)
|
|
z = normalize(z, this.array);
|
|
this.array[index * this.itemSize + 2] = toHalfFloat(z);
|
|
return this;
|
|
}
|
|
getW(index) {
|
|
let w = fromHalfFloat(this.array[index * this.itemSize + 3]);
|
|
if (this.normalized)
|
|
w = denormalize(w, this.array);
|
|
return w;
|
|
}
|
|
setW(index, w) {
|
|
if (this.normalized)
|
|
w = normalize(w, this.array);
|
|
this.array[index * this.itemSize + 3] = toHalfFloat(w);
|
|
return this;
|
|
}
|
|
setXY(index, x, y) {
|
|
index *= this.itemSize;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
}
|
|
this.array[index + 0] = toHalfFloat(x);
|
|
this.array[index + 1] = toHalfFloat(y);
|
|
return this;
|
|
}
|
|
setXYZ(index, x, y, z) {
|
|
index *= this.itemSize;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
z = normalize(z, this.array);
|
|
}
|
|
this.array[index + 0] = toHalfFloat(x);
|
|
this.array[index + 1] = toHalfFloat(y);
|
|
this.array[index + 2] = toHalfFloat(z);
|
|
return this;
|
|
}
|
|
setXYZW(index, x, y, z, w) {
|
|
index *= this.itemSize;
|
|
if (this.normalized) {
|
|
x = normalize(x, this.array);
|
|
y = normalize(y, this.array);
|
|
z = normalize(z, this.array);
|
|
w = normalize(w, this.array);
|
|
}
|
|
this.array[index + 0] = toHalfFloat(x);
|
|
this.array[index + 1] = toHalfFloat(y);
|
|
this.array[index + 2] = toHalfFloat(z);
|
|
this.array[index + 3] = toHalfFloat(w);
|
|
return this;
|
|
}
|
|
};
|
|
Float32BufferAttribute = class Float32BufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized) {
|
|
super(new Float32Array(array), itemSize, normalized);
|
|
}
|
|
};
|
|
_m1 = /* @__PURE__ */ new Matrix4;
|
|
_obj = /* @__PURE__ */ new Object3D;
|
|
_offset = /* @__PURE__ */ new Vector3;
|
|
_box$2 = /* @__PURE__ */ new Box3;
|
|
_boxMorphTargets = /* @__PURE__ */ new Box3;
|
|
_vector$8 = /* @__PURE__ */ new Vector3;
|
|
BufferGeometry = class BufferGeometry extends EventDispatcher {
|
|
constructor() {
|
|
super();
|
|
this.isBufferGeometry = true;
|
|
Object.defineProperty(this, "id", { value: _id$1++ });
|
|
this.uuid = generateUUID();
|
|
this.name = "";
|
|
this.type = "BufferGeometry";
|
|
this.index = null;
|
|
this.indirect = null;
|
|
this.attributes = {};
|
|
this.morphAttributes = {};
|
|
this.morphTargetsRelative = false;
|
|
this.groups = [];
|
|
this.boundingBox = null;
|
|
this.boundingSphere = null;
|
|
this.drawRange = { start: 0, count: Infinity };
|
|
this.userData = {};
|
|
}
|
|
getIndex() {
|
|
return this.index;
|
|
}
|
|
setIndex(index) {
|
|
if (Array.isArray(index)) {
|
|
this.index = new ((arrayNeedsUint32(index)) ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
|
|
} else {
|
|
this.index = index;
|
|
}
|
|
return this;
|
|
}
|
|
setIndirect(indirect) {
|
|
this.indirect = indirect;
|
|
return this;
|
|
}
|
|
getIndirect() {
|
|
return this.indirect;
|
|
}
|
|
getAttribute(name) {
|
|
return this.attributes[name];
|
|
}
|
|
setAttribute(name, attribute) {
|
|
this.attributes[name] = attribute;
|
|
return this;
|
|
}
|
|
deleteAttribute(name) {
|
|
delete this.attributes[name];
|
|
return this;
|
|
}
|
|
hasAttribute(name) {
|
|
return this.attributes[name] !== undefined;
|
|
}
|
|
addGroup(start, count, materialIndex = 0) {
|
|
this.groups.push({
|
|
start,
|
|
count,
|
|
materialIndex
|
|
});
|
|
}
|
|
clearGroups() {
|
|
this.groups = [];
|
|
}
|
|
setDrawRange(start, count) {
|
|
this.drawRange.start = start;
|
|
this.drawRange.count = count;
|
|
}
|
|
applyMatrix4(matrix) {
|
|
const position = this.attributes.position;
|
|
if (position !== undefined) {
|
|
position.applyMatrix4(matrix);
|
|
position.needsUpdate = true;
|
|
}
|
|
const normal = this.attributes.normal;
|
|
if (normal !== undefined) {
|
|
const normalMatrix = new Matrix3().getNormalMatrix(matrix);
|
|
normal.applyNormalMatrix(normalMatrix);
|
|
normal.needsUpdate = true;
|
|
}
|
|
const tangent = this.attributes.tangent;
|
|
if (tangent !== undefined) {
|
|
tangent.transformDirection(matrix);
|
|
tangent.needsUpdate = true;
|
|
}
|
|
if (this.boundingBox !== null) {
|
|
this.computeBoundingBox();
|
|
}
|
|
if (this.boundingSphere !== null) {
|
|
this.computeBoundingSphere();
|
|
}
|
|
return this;
|
|
}
|
|
applyQuaternion(q) {
|
|
_m1.makeRotationFromQuaternion(q);
|
|
this.applyMatrix4(_m1);
|
|
return this;
|
|
}
|
|
rotateX(angle) {
|
|
_m1.makeRotationX(angle);
|
|
this.applyMatrix4(_m1);
|
|
return this;
|
|
}
|
|
rotateY(angle) {
|
|
_m1.makeRotationY(angle);
|
|
this.applyMatrix4(_m1);
|
|
return this;
|
|
}
|
|
rotateZ(angle) {
|
|
_m1.makeRotationZ(angle);
|
|
this.applyMatrix4(_m1);
|
|
return this;
|
|
}
|
|
translate(x, y, z) {
|
|
_m1.makeTranslation(x, y, z);
|
|
this.applyMatrix4(_m1);
|
|
return this;
|
|
}
|
|
scale(x, y, z) {
|
|
_m1.makeScale(x, y, z);
|
|
this.applyMatrix4(_m1);
|
|
return this;
|
|
}
|
|
lookAt(vector) {
|
|
_obj.lookAt(vector);
|
|
_obj.updateMatrix();
|
|
this.applyMatrix4(_obj.matrix);
|
|
return this;
|
|
}
|
|
center() {
|
|
this.computeBoundingBox();
|
|
this.boundingBox.getCenter(_offset).negate();
|
|
this.translate(_offset.x, _offset.y, _offset.z);
|
|
return this;
|
|
}
|
|
setFromPoints(points) {
|
|
const positionAttribute = this.getAttribute("position");
|
|
if (positionAttribute === undefined) {
|
|
const position = [];
|
|
for (let i = 0, l = points.length;i < l; i++) {
|
|
const point = points[i];
|
|
position.push(point.x, point.y, point.z || 0);
|
|
}
|
|
this.setAttribute("position", new Float32BufferAttribute(position, 3));
|
|
} else {
|
|
const l = Math.min(points.length, positionAttribute.count);
|
|
for (let i = 0;i < l; i++) {
|
|
const point = points[i];
|
|
positionAttribute.setXYZ(i, point.x, point.y, point.z || 0);
|
|
}
|
|
if (points.length > positionAttribute.count) {
|
|
console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.");
|
|
}
|
|
positionAttribute.needsUpdate = true;
|
|
}
|
|
return this;
|
|
}
|
|
computeBoundingBox() {
|
|
if (this.boundingBox === null) {
|
|
this.boundingBox = new Box3;
|
|
}
|
|
const position = this.attributes.position;
|
|
const morphAttributesPosition = this.morphAttributes.position;
|
|
if (position && position.isGLBufferAttribute) {
|
|
console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.", this);
|
|
this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(Infinity, Infinity, Infinity));
|
|
return;
|
|
}
|
|
if (position !== undefined) {
|
|
this.boundingBox.setFromBufferAttribute(position);
|
|
if (morphAttributesPosition) {
|
|
for (let i = 0, il = morphAttributesPosition.length;i < il; i++) {
|
|
const morphAttribute = morphAttributesPosition[i];
|
|
_box$2.setFromBufferAttribute(morphAttribute);
|
|
if (this.morphTargetsRelative) {
|
|
_vector$8.addVectors(this.boundingBox.min, _box$2.min);
|
|
this.boundingBox.expandByPoint(_vector$8);
|
|
_vector$8.addVectors(this.boundingBox.max, _box$2.max);
|
|
this.boundingBox.expandByPoint(_vector$8);
|
|
} else {
|
|
this.boundingBox.expandByPoint(_box$2.min);
|
|
this.boundingBox.expandByPoint(_box$2.max);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
this.boundingBox.makeEmpty();
|
|
}
|
|
if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
|
|
console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
|
|
}
|
|
}
|
|
computeBoundingSphere() {
|
|
if (this.boundingSphere === null) {
|
|
this.boundingSphere = new Sphere;
|
|
}
|
|
const position = this.attributes.position;
|
|
const morphAttributesPosition = this.morphAttributes.position;
|
|
if (position && position.isGLBufferAttribute) {
|
|
console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.", this);
|
|
this.boundingSphere.set(new Vector3, Infinity);
|
|
return;
|
|
}
|
|
if (position) {
|
|
const center = this.boundingSphere.center;
|
|
_box$2.setFromBufferAttribute(position);
|
|
if (morphAttributesPosition) {
|
|
for (let i = 0, il = morphAttributesPosition.length;i < il; i++) {
|
|
const morphAttribute = morphAttributesPosition[i];
|
|
_boxMorphTargets.setFromBufferAttribute(morphAttribute);
|
|
if (this.morphTargetsRelative) {
|
|
_vector$8.addVectors(_box$2.min, _boxMorphTargets.min);
|
|
_box$2.expandByPoint(_vector$8);
|
|
_vector$8.addVectors(_box$2.max, _boxMorphTargets.max);
|
|
_box$2.expandByPoint(_vector$8);
|
|
} else {
|
|
_box$2.expandByPoint(_boxMorphTargets.min);
|
|
_box$2.expandByPoint(_boxMorphTargets.max);
|
|
}
|
|
}
|
|
}
|
|
_box$2.getCenter(center);
|
|
let maxRadiusSq = 0;
|
|
for (let i = 0, il = position.count;i < il; i++) {
|
|
_vector$8.fromBufferAttribute(position, i);
|
|
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$8));
|
|
}
|
|
if (morphAttributesPosition) {
|
|
for (let i = 0, il = morphAttributesPosition.length;i < il; i++) {
|
|
const morphAttribute = morphAttributesPosition[i];
|
|
const morphTargetsRelative = this.morphTargetsRelative;
|
|
for (let j = 0, jl = morphAttribute.count;j < jl; j++) {
|
|
_vector$8.fromBufferAttribute(morphAttribute, j);
|
|
if (morphTargetsRelative) {
|
|
_offset.fromBufferAttribute(position, j);
|
|
_vector$8.add(_offset);
|
|
}
|
|
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$8));
|
|
}
|
|
}
|
|
}
|
|
this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
|
|
if (isNaN(this.boundingSphere.radius)) {
|
|
console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
|
|
}
|
|
}
|
|
}
|
|
computeTangents() {
|
|
const index = this.index;
|
|
const attributes = this.attributes;
|
|
if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
|
|
console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");
|
|
return;
|
|
}
|
|
const positionAttribute = attributes.position;
|
|
const normalAttribute = attributes.normal;
|
|
const uvAttribute = attributes.uv;
|
|
if (this.hasAttribute("tangent") === false) {
|
|
this.setAttribute("tangent", new BufferAttribute(new Float32Array(4 * positionAttribute.count), 4));
|
|
}
|
|
const tangentAttribute = this.getAttribute("tangent");
|
|
const tan1 = [], tan2 = [];
|
|
for (let i = 0;i < positionAttribute.count; i++) {
|
|
tan1[i] = new Vector3;
|
|
tan2[i] = new Vector3;
|
|
}
|
|
const vA = new Vector3, vB = new Vector3, vC = new Vector3, uvA = new Vector2, uvB = new Vector2, uvC = new Vector2, sdir = new Vector3, tdir = new Vector3;
|
|
function handleTriangle(a, b, c) {
|
|
vA.fromBufferAttribute(positionAttribute, a);
|
|
vB.fromBufferAttribute(positionAttribute, b);
|
|
vC.fromBufferAttribute(positionAttribute, c);
|
|
uvA.fromBufferAttribute(uvAttribute, a);
|
|
uvB.fromBufferAttribute(uvAttribute, b);
|
|
uvC.fromBufferAttribute(uvAttribute, c);
|
|
vB.sub(vA);
|
|
vC.sub(vA);
|
|
uvB.sub(uvA);
|
|
uvC.sub(uvA);
|
|
const r = 1 / (uvB.x * uvC.y - uvC.x * uvB.y);
|
|
if (!isFinite(r))
|
|
return;
|
|
sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
|
|
tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
|
|
tan1[a].add(sdir);
|
|
tan1[b].add(sdir);
|
|
tan1[c].add(sdir);
|
|
tan2[a].add(tdir);
|
|
tan2[b].add(tdir);
|
|
tan2[c].add(tdir);
|
|
}
|
|
let groups = this.groups;
|
|
if (groups.length === 0) {
|
|
groups = [{
|
|
start: 0,
|
|
count: index.count
|
|
}];
|
|
}
|
|
for (let i = 0, il = groups.length;i < il; ++i) {
|
|
const group = groups[i];
|
|
const start = group.start;
|
|
const count = group.count;
|
|
for (let j = start, jl = start + count;j < jl; j += 3) {
|
|
handleTriangle(index.getX(j + 0), index.getX(j + 1), index.getX(j + 2));
|
|
}
|
|
}
|
|
const tmp = new Vector3, tmp2 = new Vector3;
|
|
const n = new Vector3, n2 = new Vector3;
|
|
function handleVertex(v) {
|
|
n.fromBufferAttribute(normalAttribute, v);
|
|
n2.copy(n);
|
|
const t = tan1[v];
|
|
tmp.copy(t);
|
|
tmp.sub(n.multiplyScalar(n.dot(t))).normalize();
|
|
tmp2.crossVectors(n2, t);
|
|
const test = tmp2.dot(tan2[v]);
|
|
const w = test < 0 ? -1 : 1;
|
|
tangentAttribute.setXYZW(v, tmp.x, tmp.y, tmp.z, w);
|
|
}
|
|
for (let i = 0, il = groups.length;i < il; ++i) {
|
|
const group = groups[i];
|
|
const start = group.start;
|
|
const count = group.count;
|
|
for (let j = start, jl = start + count;j < jl; j += 3) {
|
|
handleVertex(index.getX(j + 0));
|
|
handleVertex(index.getX(j + 1));
|
|
handleVertex(index.getX(j + 2));
|
|
}
|
|
}
|
|
}
|
|
computeVertexNormals() {
|
|
const index = this.index;
|
|
const positionAttribute = this.getAttribute("position");
|
|
if (positionAttribute !== undefined) {
|
|
let normalAttribute = this.getAttribute("normal");
|
|
if (normalAttribute === undefined) {
|
|
normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
|
|
this.setAttribute("normal", normalAttribute);
|
|
} else {
|
|
for (let i = 0, il = normalAttribute.count;i < il; i++) {
|
|
normalAttribute.setXYZ(i, 0, 0, 0);
|
|
}
|
|
}
|
|
const pA = new Vector3, pB = new Vector3, pC = new Vector3;
|
|
const nA = new Vector3, nB = new Vector3, nC = new Vector3;
|
|
const cb = new Vector3, ab = new Vector3;
|
|
if (index) {
|
|
for (let i = 0, il = index.count;i < il; i += 3) {
|
|
const vA = index.getX(i + 0);
|
|
const vB = index.getX(i + 1);
|
|
const vC = index.getX(i + 2);
|
|
pA.fromBufferAttribute(positionAttribute, vA);
|
|
pB.fromBufferAttribute(positionAttribute, vB);
|
|
pC.fromBufferAttribute(positionAttribute, vC);
|
|
cb.subVectors(pC, pB);
|
|
ab.subVectors(pA, pB);
|
|
cb.cross(ab);
|
|
nA.fromBufferAttribute(normalAttribute, vA);
|
|
nB.fromBufferAttribute(normalAttribute, vB);
|
|
nC.fromBufferAttribute(normalAttribute, vC);
|
|
nA.add(cb);
|
|
nB.add(cb);
|
|
nC.add(cb);
|
|
normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
|
|
normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
|
|
normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
|
|
}
|
|
} else {
|
|
for (let i = 0, il = positionAttribute.count;i < il; i += 3) {
|
|
pA.fromBufferAttribute(positionAttribute, i + 0);
|
|
pB.fromBufferAttribute(positionAttribute, i + 1);
|
|
pC.fromBufferAttribute(positionAttribute, i + 2);
|
|
cb.subVectors(pC, pB);
|
|
ab.subVectors(pA, pB);
|
|
cb.cross(ab);
|
|
normalAttribute.setXYZ(i + 0, cb.x, cb.y, cb.z);
|
|
normalAttribute.setXYZ(i + 1, cb.x, cb.y, cb.z);
|
|
normalAttribute.setXYZ(i + 2, cb.x, cb.y, cb.z);
|
|
}
|
|
}
|
|
this.normalizeNormals();
|
|
normalAttribute.needsUpdate = true;
|
|
}
|
|
}
|
|
normalizeNormals() {
|
|
const normals = this.attributes.normal;
|
|
for (let i = 0, il = normals.count;i < il; i++) {
|
|
_vector$8.fromBufferAttribute(normals, i);
|
|
_vector$8.normalize();
|
|
normals.setXYZ(i, _vector$8.x, _vector$8.y, _vector$8.z);
|
|
}
|
|
}
|
|
toNonIndexed() {
|
|
function convertBufferAttribute(attribute, indices2) {
|
|
const array = attribute.array;
|
|
const itemSize = attribute.itemSize;
|
|
const normalized = attribute.normalized;
|
|
const array2 = new array.constructor(indices2.length * itemSize);
|
|
let index = 0, index2 = 0;
|
|
for (let i = 0, l = indices2.length;i < l; i++) {
|
|
if (attribute.isInterleavedBufferAttribute) {
|
|
index = indices2[i] * attribute.data.stride + attribute.offset;
|
|
} else {
|
|
index = indices2[i] * itemSize;
|
|
}
|
|
for (let j = 0;j < itemSize; j++) {
|
|
array2[index2++] = array[index++];
|
|
}
|
|
}
|
|
return new BufferAttribute(array2, itemSize, normalized);
|
|
}
|
|
if (this.index === null) {
|
|
console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.");
|
|
return this;
|
|
}
|
|
const geometry2 = new BufferGeometry;
|
|
const indices = this.index.array;
|
|
const attributes = this.attributes;
|
|
for (const name in attributes) {
|
|
const attribute = attributes[name];
|
|
const newAttribute = convertBufferAttribute(attribute, indices);
|
|
geometry2.setAttribute(name, newAttribute);
|
|
}
|
|
const morphAttributes = this.morphAttributes;
|
|
for (const name in morphAttributes) {
|
|
const morphArray = [];
|
|
const morphAttribute = morphAttributes[name];
|
|
for (let i = 0, il = morphAttribute.length;i < il; i++) {
|
|
const attribute = morphAttribute[i];
|
|
const newAttribute = convertBufferAttribute(attribute, indices);
|
|
morphArray.push(newAttribute);
|
|
}
|
|
geometry2.morphAttributes[name] = morphArray;
|
|
}
|
|
geometry2.morphTargetsRelative = this.morphTargetsRelative;
|
|
const groups = this.groups;
|
|
for (let i = 0, l = groups.length;i < l; i++) {
|
|
const group = groups[i];
|
|
geometry2.addGroup(group.start, group.count, group.materialIndex);
|
|
}
|
|
return geometry2;
|
|
}
|
|
toJSON() {
|
|
const data = {
|
|
metadata: {
|
|
version: 4.6,
|
|
type: "BufferGeometry",
|
|
generator: "BufferGeometry.toJSON"
|
|
}
|
|
};
|
|
data.uuid = this.uuid;
|
|
data.type = this.type;
|
|
if (this.name !== "")
|
|
data.name = this.name;
|
|
if (Object.keys(this.userData).length > 0)
|
|
data.userData = this.userData;
|
|
if (this.parameters !== undefined) {
|
|
const parameters = this.parameters;
|
|
for (const key in parameters) {
|
|
if (parameters[key] !== undefined)
|
|
data[key] = parameters[key];
|
|
}
|
|
return data;
|
|
}
|
|
data.data = { attributes: {} };
|
|
const index = this.index;
|
|
if (index !== null) {
|
|
data.data.index = {
|
|
type: index.array.constructor.name,
|
|
array: Array.prototype.slice.call(index.array)
|
|
};
|
|
}
|
|
const attributes = this.attributes;
|
|
for (const key in attributes) {
|
|
const attribute = attributes[key];
|
|
data.data.attributes[key] = attribute.toJSON(data.data);
|
|
}
|
|
const morphAttributes = {};
|
|
let hasMorphAttributes = false;
|
|
for (const key in this.morphAttributes) {
|
|
const attributeArray = this.morphAttributes[key];
|
|
const array = [];
|
|
for (let i = 0, il = attributeArray.length;i < il; i++) {
|
|
const attribute = attributeArray[i];
|
|
array.push(attribute.toJSON(data.data));
|
|
}
|
|
if (array.length > 0) {
|
|
morphAttributes[key] = array;
|
|
hasMorphAttributes = true;
|
|
}
|
|
}
|
|
if (hasMorphAttributes) {
|
|
data.data.morphAttributes = morphAttributes;
|
|
data.data.morphTargetsRelative = this.morphTargetsRelative;
|
|
}
|
|
const groups = this.groups;
|
|
if (groups.length > 0) {
|
|
data.data.groups = JSON.parse(JSON.stringify(groups));
|
|
}
|
|
const boundingSphere = this.boundingSphere;
|
|
if (boundingSphere !== null) {
|
|
data.data.boundingSphere = {
|
|
center: boundingSphere.center.toArray(),
|
|
radius: boundingSphere.radius
|
|
};
|
|
}
|
|
return data;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
copy(source) {
|
|
this.index = null;
|
|
this.attributes = {};
|
|
this.morphAttributes = {};
|
|
this.groups = [];
|
|
this.boundingBox = null;
|
|
this.boundingSphere = null;
|
|
const data = {};
|
|
this.name = source.name;
|
|
const index = source.index;
|
|
if (index !== null) {
|
|
this.setIndex(index.clone(data));
|
|
}
|
|
const attributes = source.attributes;
|
|
for (const name in attributes) {
|
|
const attribute = attributes[name];
|
|
this.setAttribute(name, attribute.clone(data));
|
|
}
|
|
const morphAttributes = source.morphAttributes;
|
|
for (const name in morphAttributes) {
|
|
const array = [];
|
|
const morphAttribute = morphAttributes[name];
|
|
for (let i = 0, l = morphAttribute.length;i < l; i++) {
|
|
array.push(morphAttribute[i].clone(data));
|
|
}
|
|
this.morphAttributes[name] = array;
|
|
}
|
|
this.morphTargetsRelative = source.morphTargetsRelative;
|
|
const groups = source.groups;
|
|
for (let i = 0, l = groups.length;i < l; i++) {
|
|
const group = groups[i];
|
|
this.addGroup(group.start, group.count, group.materialIndex);
|
|
}
|
|
const boundingBox = source.boundingBox;
|
|
if (boundingBox !== null) {
|
|
this.boundingBox = boundingBox.clone();
|
|
}
|
|
const boundingSphere = source.boundingSphere;
|
|
if (boundingSphere !== null) {
|
|
this.boundingSphere = boundingSphere.clone();
|
|
}
|
|
this.drawRange.start = source.drawRange.start;
|
|
this.drawRange.count = source.drawRange.count;
|
|
this.userData = source.userData;
|
|
return this;
|
|
}
|
|
dispose() {
|
|
this.dispatchEvent({ type: "dispose" });
|
|
}
|
|
};
|
|
_inverseMatrix$3 = /* @__PURE__ */ new Matrix4;
|
|
_ray$3 = /* @__PURE__ */ new Ray;
|
|
_sphere$6 = /* @__PURE__ */ new Sphere;
|
|
_sphereHitAt = /* @__PURE__ */ new Vector3;
|
|
_vA$1 = /* @__PURE__ */ new Vector3;
|
|
_vB$1 = /* @__PURE__ */ new Vector3;
|
|
_vC$1 = /* @__PURE__ */ new Vector3;
|
|
_tempA = /* @__PURE__ */ new Vector3;
|
|
_morphA = /* @__PURE__ */ new Vector3;
|
|
_intersectionPoint = /* @__PURE__ */ new Vector3;
|
|
_intersectionPointWorld = /* @__PURE__ */ new Vector3;
|
|
Mesh = class Mesh extends Object3D {
|
|
constructor(geometry = new BufferGeometry, material = new MeshBasicMaterial) {
|
|
super();
|
|
this.isMesh = true;
|
|
this.type = "Mesh";
|
|
this.geometry = geometry;
|
|
this.material = material;
|
|
this.updateMorphTargets();
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
if (source.morphTargetInfluences !== undefined) {
|
|
this.morphTargetInfluences = source.morphTargetInfluences.slice();
|
|
}
|
|
if (source.morphTargetDictionary !== undefined) {
|
|
this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
|
|
}
|
|
this.material = Array.isArray(source.material) ? source.material.slice() : source.material;
|
|
this.geometry = source.geometry;
|
|
return this;
|
|
}
|
|
updateMorphTargets() {
|
|
const geometry = this.geometry;
|
|
const morphAttributes = geometry.morphAttributes;
|
|
const keys = Object.keys(morphAttributes);
|
|
if (keys.length > 0) {
|
|
const morphAttribute = morphAttributes[keys[0]];
|
|
if (morphAttribute !== undefined) {
|
|
this.morphTargetInfluences = [];
|
|
this.morphTargetDictionary = {};
|
|
for (let m = 0, ml = morphAttribute.length;m < ml; m++) {
|
|
const name = morphAttribute[m].name || String(m);
|
|
this.morphTargetInfluences.push(0);
|
|
this.morphTargetDictionary[name] = m;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
getVertexPosition(index, target) {
|
|
const geometry = this.geometry;
|
|
const position = geometry.attributes.position;
|
|
const morphPosition = geometry.morphAttributes.position;
|
|
const morphTargetsRelative = geometry.morphTargetsRelative;
|
|
target.fromBufferAttribute(position, index);
|
|
const morphInfluences = this.morphTargetInfluences;
|
|
if (morphPosition && morphInfluences) {
|
|
_morphA.set(0, 0, 0);
|
|
for (let i = 0, il = morphPosition.length;i < il; i++) {
|
|
const influence = morphInfluences[i];
|
|
const morphAttribute = morphPosition[i];
|
|
if (influence === 0)
|
|
continue;
|
|
_tempA.fromBufferAttribute(morphAttribute, index);
|
|
if (morphTargetsRelative) {
|
|
_morphA.addScaledVector(_tempA, influence);
|
|
} else {
|
|
_morphA.addScaledVector(_tempA.sub(target), influence);
|
|
}
|
|
}
|
|
target.add(_morphA);
|
|
}
|
|
return target;
|
|
}
|
|
raycast(raycaster, intersects) {
|
|
const geometry = this.geometry;
|
|
const material = this.material;
|
|
const matrixWorld = this.matrixWorld;
|
|
if (material === undefined)
|
|
return;
|
|
if (geometry.boundingSphere === null)
|
|
geometry.computeBoundingSphere();
|
|
_sphere$6.copy(geometry.boundingSphere);
|
|
_sphere$6.applyMatrix4(matrixWorld);
|
|
_ray$3.copy(raycaster.ray).recast(raycaster.near);
|
|
if (_sphere$6.containsPoint(_ray$3.origin) === false) {
|
|
if (_ray$3.intersectSphere(_sphere$6, _sphereHitAt) === null)
|
|
return;
|
|
if (_ray$3.origin.distanceToSquared(_sphereHitAt) > (raycaster.far - raycaster.near) ** 2)
|
|
return;
|
|
}
|
|
_inverseMatrix$3.copy(matrixWorld).invert();
|
|
_ray$3.copy(raycaster.ray).applyMatrix4(_inverseMatrix$3);
|
|
if (geometry.boundingBox !== null) {
|
|
if (_ray$3.intersectsBox(geometry.boundingBox) === false)
|
|
return;
|
|
}
|
|
this._computeIntersections(raycaster, intersects, _ray$3);
|
|
}
|
|
_computeIntersections(raycaster, intersects, rayLocalSpace) {
|
|
let intersection;
|
|
const geometry = this.geometry;
|
|
const material = this.material;
|
|
const index = geometry.index;
|
|
const position = geometry.attributes.position;
|
|
const uv = geometry.attributes.uv;
|
|
const uv1 = geometry.attributes.uv1;
|
|
const normal = geometry.attributes.normal;
|
|
const groups = geometry.groups;
|
|
const drawRange = geometry.drawRange;
|
|
if (index !== null) {
|
|
if (Array.isArray(material)) {
|
|
for (let i = 0, il = groups.length;i < il; i++) {
|
|
const group = groups[i];
|
|
const groupMaterial = material[group.materialIndex];
|
|
const start = Math.max(group.start, drawRange.start);
|
|
const end = Math.min(index.count, Math.min(group.start + group.count, drawRange.start + drawRange.count));
|
|
for (let j = start, jl = end;j < jl; j += 3) {
|
|
const a = index.getX(j);
|
|
const b = index.getX(j + 1);
|
|
const c = index.getX(j + 2);
|
|
intersection = checkGeometryIntersection(this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c);
|
|
if (intersection) {
|
|
intersection.faceIndex = Math.floor(j / 3);
|
|
intersection.face.materialIndex = group.materialIndex;
|
|
intersects.push(intersection);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
const start = Math.max(0, drawRange.start);
|
|
const end = Math.min(index.count, drawRange.start + drawRange.count);
|
|
for (let i = start, il = end;i < il; i += 3) {
|
|
const a = index.getX(i);
|
|
const b = index.getX(i + 1);
|
|
const c = index.getX(i + 2);
|
|
intersection = checkGeometryIntersection(this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c);
|
|
if (intersection) {
|
|
intersection.faceIndex = Math.floor(i / 3);
|
|
intersects.push(intersection);
|
|
}
|
|
}
|
|
}
|
|
} else if (position !== undefined) {
|
|
if (Array.isArray(material)) {
|
|
for (let i = 0, il = groups.length;i < il; i++) {
|
|
const group = groups[i];
|
|
const groupMaterial = material[group.materialIndex];
|
|
const start = Math.max(group.start, drawRange.start);
|
|
const end = Math.min(position.count, Math.min(group.start + group.count, drawRange.start + drawRange.count));
|
|
for (let j = start, jl = end;j < jl; j += 3) {
|
|
const a = j;
|
|
const b = j + 1;
|
|
const c = j + 2;
|
|
intersection = checkGeometryIntersection(this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c);
|
|
if (intersection) {
|
|
intersection.faceIndex = Math.floor(j / 3);
|
|
intersection.face.materialIndex = group.materialIndex;
|
|
intersects.push(intersection);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
const start = Math.max(0, drawRange.start);
|
|
const end = Math.min(position.count, drawRange.start + drawRange.count);
|
|
for (let i = start, il = end;i < il; i += 3) {
|
|
const a = i;
|
|
const b = i + 1;
|
|
const c = i + 2;
|
|
intersection = checkGeometryIntersection(this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c);
|
|
if (intersection) {
|
|
intersection.faceIndex = Math.floor(i / 3);
|
|
intersects.push(intersection);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
BoxGeometry = class BoxGeometry extends BufferGeometry {
|
|
constructor(width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1) {
|
|
super();
|
|
this.type = "BoxGeometry";
|
|
this.parameters = {
|
|
width,
|
|
height,
|
|
depth,
|
|
widthSegments,
|
|
heightSegments,
|
|
depthSegments
|
|
};
|
|
const scope = this;
|
|
widthSegments = Math.floor(widthSegments);
|
|
heightSegments = Math.floor(heightSegments);
|
|
depthSegments = Math.floor(depthSegments);
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
let numberOfVertices = 0;
|
|
let groupStart = 0;
|
|
buildPlane("z", "y", "x", -1, -1, depth, height, width, depthSegments, heightSegments, 0);
|
|
buildPlane("z", "y", "x", 1, -1, depth, height, -width, depthSegments, heightSegments, 1);
|
|
buildPlane("x", "z", "y", 1, 1, width, depth, height, widthSegments, depthSegments, 2);
|
|
buildPlane("x", "z", "y", 1, -1, width, depth, -height, widthSegments, depthSegments, 3);
|
|
buildPlane("x", "y", "z", 1, -1, width, height, depth, widthSegments, heightSegments, 4);
|
|
buildPlane("x", "y", "z", -1, -1, width, height, -depth, widthSegments, heightSegments, 5);
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
function buildPlane(u, v, w, udir, vdir, width2, height2, depth2, gridX, gridY, materialIndex) {
|
|
const segmentWidth = width2 / gridX;
|
|
const segmentHeight = height2 / gridY;
|
|
const widthHalf = width2 / 2;
|
|
const heightHalf = height2 / 2;
|
|
const depthHalf = depth2 / 2;
|
|
const gridX1 = gridX + 1;
|
|
const gridY1 = gridY + 1;
|
|
let vertexCounter = 0;
|
|
let groupCount = 0;
|
|
const vector = new Vector3;
|
|
for (let iy = 0;iy < gridY1; iy++) {
|
|
const y = iy * segmentHeight - heightHalf;
|
|
for (let ix = 0;ix < gridX1; ix++) {
|
|
const x = ix * segmentWidth - widthHalf;
|
|
vector[u] = x * udir;
|
|
vector[v] = y * vdir;
|
|
vector[w] = depthHalf;
|
|
vertices.push(vector.x, vector.y, vector.z);
|
|
vector[u] = 0;
|
|
vector[v] = 0;
|
|
vector[w] = depth2 > 0 ? 1 : -1;
|
|
normals.push(vector.x, vector.y, vector.z);
|
|
uvs.push(ix / gridX);
|
|
uvs.push(1 - iy / gridY);
|
|
vertexCounter += 1;
|
|
}
|
|
}
|
|
for (let iy = 0;iy < gridY; iy++) {
|
|
for (let ix = 0;ix < gridX; ix++) {
|
|
const a = numberOfVertices + ix + gridX1 * iy;
|
|
const b = numberOfVertices + ix + gridX1 * (iy + 1);
|
|
const c = numberOfVertices + (ix + 1) + gridX1 * (iy + 1);
|
|
const d = numberOfVertices + (ix + 1) + gridX1 * iy;
|
|
indices.push(a, b, d);
|
|
indices.push(b, c, d);
|
|
groupCount += 6;
|
|
}
|
|
}
|
|
scope.addGroup(groupStart, groupCount, materialIndex);
|
|
groupStart += groupCount;
|
|
numberOfVertices += vertexCounter;
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new BoxGeometry(data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
|
|
}
|
|
};
|
|
UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
|
|
ShaderMaterial = class ShaderMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isShaderMaterial = true;
|
|
this.type = "ShaderMaterial";
|
|
this.defines = {};
|
|
this.uniforms = {};
|
|
this.uniformsGroups = [];
|
|
this.vertexShader = default_vertex;
|
|
this.fragmentShader = default_fragment;
|
|
this.linewidth = 1;
|
|
this.wireframe = false;
|
|
this.wireframeLinewidth = 1;
|
|
this.fog = false;
|
|
this.lights = false;
|
|
this.clipping = false;
|
|
this.forceSinglePass = true;
|
|
this.extensions = {
|
|
clipCullDistance: false,
|
|
multiDraw: false
|
|
};
|
|
this.defaultAttributeValues = {
|
|
color: [1, 1, 1],
|
|
uv: [0, 0],
|
|
uv1: [0, 0]
|
|
};
|
|
this.index0AttributeName = undefined;
|
|
this.uniformsNeedUpdate = false;
|
|
this.glslVersion = null;
|
|
if (parameters !== undefined) {
|
|
this.setValues(parameters);
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.fragmentShader = source.fragmentShader;
|
|
this.vertexShader = source.vertexShader;
|
|
this.uniforms = cloneUniforms(source.uniforms);
|
|
this.uniformsGroups = cloneUniformsGroups(source.uniformsGroups);
|
|
this.defines = Object.assign({}, source.defines);
|
|
this.wireframe = source.wireframe;
|
|
this.wireframeLinewidth = source.wireframeLinewidth;
|
|
this.fog = source.fog;
|
|
this.lights = source.lights;
|
|
this.clipping = source.clipping;
|
|
this.extensions = Object.assign({}, source.extensions);
|
|
this.glslVersion = source.glslVersion;
|
|
return this;
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
data.glslVersion = this.glslVersion;
|
|
data.uniforms = {};
|
|
for (const name in this.uniforms) {
|
|
const uniform = this.uniforms[name];
|
|
const value = uniform.value;
|
|
if (value && value.isTexture) {
|
|
data.uniforms[name] = {
|
|
type: "t",
|
|
value: value.toJSON(meta).uuid
|
|
};
|
|
} else if (value && value.isColor) {
|
|
data.uniforms[name] = {
|
|
type: "c",
|
|
value: value.getHex()
|
|
};
|
|
} else if (value && value.isVector2) {
|
|
data.uniforms[name] = {
|
|
type: "v2",
|
|
value: value.toArray()
|
|
};
|
|
} else if (value && value.isVector3) {
|
|
data.uniforms[name] = {
|
|
type: "v3",
|
|
value: value.toArray()
|
|
};
|
|
} else if (value && value.isVector4) {
|
|
data.uniforms[name] = {
|
|
type: "v4",
|
|
value: value.toArray()
|
|
};
|
|
} else if (value && value.isMatrix3) {
|
|
data.uniforms[name] = {
|
|
type: "m3",
|
|
value: value.toArray()
|
|
};
|
|
} else if (value && value.isMatrix4) {
|
|
data.uniforms[name] = {
|
|
type: "m4",
|
|
value: value.toArray()
|
|
};
|
|
} else {
|
|
data.uniforms[name] = {
|
|
value
|
|
};
|
|
}
|
|
}
|
|
if (Object.keys(this.defines).length > 0)
|
|
data.defines = this.defines;
|
|
data.vertexShader = this.vertexShader;
|
|
data.fragmentShader = this.fragmentShader;
|
|
data.lights = this.lights;
|
|
data.clipping = this.clipping;
|
|
const extensions = {};
|
|
for (const key in this.extensions) {
|
|
if (this.extensions[key] === true)
|
|
extensions[key] = true;
|
|
}
|
|
if (Object.keys(extensions).length > 0)
|
|
data.extensions = extensions;
|
|
return data;
|
|
}
|
|
};
|
|
Camera = class Camera extends Object3D {
|
|
constructor() {
|
|
super();
|
|
this.isCamera = true;
|
|
this.type = "Camera";
|
|
this.matrixWorldInverse = new Matrix4;
|
|
this.projectionMatrix = new Matrix4;
|
|
this.projectionMatrixInverse = new Matrix4;
|
|
this.coordinateSystem = WebGLCoordinateSystem;
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.matrixWorldInverse.copy(source.matrixWorldInverse);
|
|
this.projectionMatrix.copy(source.projectionMatrix);
|
|
this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
|
|
this.coordinateSystem = source.coordinateSystem;
|
|
return this;
|
|
}
|
|
getWorldDirection(target) {
|
|
return super.getWorldDirection(target).negate();
|
|
}
|
|
updateMatrixWorld(force) {
|
|
super.updateMatrixWorld(force);
|
|
this.matrixWorldInverse.copy(this.matrixWorld).invert();
|
|
}
|
|
updateWorldMatrix(updateParents, updateChildren) {
|
|
super.updateWorldMatrix(updateParents, updateChildren);
|
|
this.matrixWorldInverse.copy(this.matrixWorld).invert();
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
};
|
|
_v3$1 = /* @__PURE__ */ new Vector3;
|
|
_minTarget = /* @__PURE__ */ new Vector2;
|
|
_maxTarget = /* @__PURE__ */ new Vector2;
|
|
PerspectiveCamera = class PerspectiveCamera extends Camera {
|
|
constructor(fov = 50, aspect = 1, near = 0.1, far = 2000) {
|
|
super();
|
|
this.isPerspectiveCamera = true;
|
|
this.type = "PerspectiveCamera";
|
|
this.fov = fov;
|
|
this.zoom = 1;
|
|
this.near = near;
|
|
this.far = far;
|
|
this.focus = 10;
|
|
this.aspect = aspect;
|
|
this.view = null;
|
|
this.filmGauge = 35;
|
|
this.filmOffset = 0;
|
|
this.updateProjectionMatrix();
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.fov = source.fov;
|
|
this.zoom = source.zoom;
|
|
this.near = source.near;
|
|
this.far = source.far;
|
|
this.focus = source.focus;
|
|
this.aspect = source.aspect;
|
|
this.view = source.view === null ? null : Object.assign({}, source.view);
|
|
this.filmGauge = source.filmGauge;
|
|
this.filmOffset = source.filmOffset;
|
|
return this;
|
|
}
|
|
setFocalLength(focalLength) {
|
|
const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
|
|
this.fov = RAD2DEG * 2 * Math.atan(vExtentSlope);
|
|
this.updateProjectionMatrix();
|
|
}
|
|
getFocalLength() {
|
|
const vExtentSlope = Math.tan(DEG2RAD * 0.5 * this.fov);
|
|
return 0.5 * this.getFilmHeight() / vExtentSlope;
|
|
}
|
|
getEffectiveFOV() {
|
|
return RAD2DEG * 2 * Math.atan(Math.tan(DEG2RAD * 0.5 * this.fov) / this.zoom);
|
|
}
|
|
getFilmWidth() {
|
|
return this.filmGauge * Math.min(this.aspect, 1);
|
|
}
|
|
getFilmHeight() {
|
|
return this.filmGauge / Math.max(this.aspect, 1);
|
|
}
|
|
getViewBounds(distance, minTarget, maxTarget) {
|
|
_v3$1.set(-1, -1, 0.5).applyMatrix4(this.projectionMatrixInverse);
|
|
minTarget.set(_v3$1.x, _v3$1.y).multiplyScalar(-distance / _v3$1.z);
|
|
_v3$1.set(1, 1, 0.5).applyMatrix4(this.projectionMatrixInverse);
|
|
maxTarget.set(_v3$1.x, _v3$1.y).multiplyScalar(-distance / _v3$1.z);
|
|
}
|
|
getViewSize(distance, target) {
|
|
this.getViewBounds(distance, _minTarget, _maxTarget);
|
|
return target.subVectors(_maxTarget, _minTarget);
|
|
}
|
|
setViewOffset(fullWidth, fullHeight, x, y, width, height) {
|
|
this.aspect = fullWidth / fullHeight;
|
|
if (this.view === null) {
|
|
this.view = {
|
|
enabled: true,
|
|
fullWidth: 1,
|
|
fullHeight: 1,
|
|
offsetX: 0,
|
|
offsetY: 0,
|
|
width: 1,
|
|
height: 1
|
|
};
|
|
}
|
|
this.view.enabled = true;
|
|
this.view.fullWidth = fullWidth;
|
|
this.view.fullHeight = fullHeight;
|
|
this.view.offsetX = x;
|
|
this.view.offsetY = y;
|
|
this.view.width = width;
|
|
this.view.height = height;
|
|
this.updateProjectionMatrix();
|
|
}
|
|
clearViewOffset() {
|
|
if (this.view !== null) {
|
|
this.view.enabled = false;
|
|
}
|
|
this.updateProjectionMatrix();
|
|
}
|
|
updateProjectionMatrix() {
|
|
const near = this.near;
|
|
let top = near * Math.tan(DEG2RAD * 0.5 * this.fov) / this.zoom;
|
|
let height = 2 * top;
|
|
let width = this.aspect * height;
|
|
let left = -0.5 * width;
|
|
const view = this.view;
|
|
if (this.view !== null && this.view.enabled) {
|
|
const { fullWidth, fullHeight } = view;
|
|
left += view.offsetX * width / fullWidth;
|
|
top -= view.offsetY * height / fullHeight;
|
|
width *= view.width / fullWidth;
|
|
height *= view.height / fullHeight;
|
|
}
|
|
const skew = this.filmOffset;
|
|
if (skew !== 0)
|
|
left += near * skew / this.getFilmWidth();
|
|
this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far, this.coordinateSystem);
|
|
this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
data.object.fov = this.fov;
|
|
data.object.zoom = this.zoom;
|
|
data.object.near = this.near;
|
|
data.object.far = this.far;
|
|
data.object.focus = this.focus;
|
|
data.object.aspect = this.aspect;
|
|
if (this.view !== null)
|
|
data.object.view = Object.assign({}, this.view);
|
|
data.object.filmGauge = this.filmGauge;
|
|
data.object.filmOffset = this.filmOffset;
|
|
return data;
|
|
}
|
|
};
|
|
CubeCamera = class CubeCamera extends Object3D {
|
|
constructor(near, far, renderTarget) {
|
|
super();
|
|
this.type = "CubeCamera";
|
|
this.renderTarget = renderTarget;
|
|
this.coordinateSystem = null;
|
|
this.activeMipmapLevel = 0;
|
|
const cameraPX = new PerspectiveCamera(fov, aspect, near, far);
|
|
cameraPX.layers = this.layers;
|
|
this.add(cameraPX);
|
|
const cameraNX = new PerspectiveCamera(fov, aspect, near, far);
|
|
cameraNX.layers = this.layers;
|
|
this.add(cameraNX);
|
|
const cameraPY = new PerspectiveCamera(fov, aspect, near, far);
|
|
cameraPY.layers = this.layers;
|
|
this.add(cameraPY);
|
|
const cameraNY = new PerspectiveCamera(fov, aspect, near, far);
|
|
cameraNY.layers = this.layers;
|
|
this.add(cameraNY);
|
|
const cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
|
|
cameraPZ.layers = this.layers;
|
|
this.add(cameraPZ);
|
|
const cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
|
|
cameraNZ.layers = this.layers;
|
|
this.add(cameraNZ);
|
|
}
|
|
updateCoordinateSystem() {
|
|
const coordinateSystem = this.coordinateSystem;
|
|
const cameras = this.children.concat();
|
|
const [cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ] = cameras;
|
|
for (const camera of cameras)
|
|
this.remove(camera);
|
|
if (coordinateSystem === WebGLCoordinateSystem) {
|
|
cameraPX.up.set(0, 1, 0);
|
|
cameraPX.lookAt(1, 0, 0);
|
|
cameraNX.up.set(0, 1, 0);
|
|
cameraNX.lookAt(-1, 0, 0);
|
|
cameraPY.up.set(0, 0, -1);
|
|
cameraPY.lookAt(0, 1, 0);
|
|
cameraNY.up.set(0, 0, 1);
|
|
cameraNY.lookAt(0, -1, 0);
|
|
cameraPZ.up.set(0, 1, 0);
|
|
cameraPZ.lookAt(0, 0, 1);
|
|
cameraNZ.up.set(0, 1, 0);
|
|
cameraNZ.lookAt(0, 0, -1);
|
|
} else if (coordinateSystem === WebGPUCoordinateSystem) {
|
|
cameraPX.up.set(0, -1, 0);
|
|
cameraPX.lookAt(-1, 0, 0);
|
|
cameraNX.up.set(0, -1, 0);
|
|
cameraNX.lookAt(1, 0, 0);
|
|
cameraPY.up.set(0, 0, 1);
|
|
cameraPY.lookAt(0, 1, 0);
|
|
cameraNY.up.set(0, 0, -1);
|
|
cameraNY.lookAt(0, -1, 0);
|
|
cameraPZ.up.set(0, -1, 0);
|
|
cameraPZ.lookAt(0, 0, 1);
|
|
cameraNZ.up.set(0, -1, 0);
|
|
cameraNZ.lookAt(0, 0, -1);
|
|
} else {
|
|
throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: " + coordinateSystem);
|
|
}
|
|
for (const camera of cameras) {
|
|
this.add(camera);
|
|
camera.updateMatrixWorld();
|
|
}
|
|
}
|
|
update(renderer, scene) {
|
|
if (this.parent === null)
|
|
this.updateMatrixWorld();
|
|
const { renderTarget, activeMipmapLevel } = this;
|
|
if (this.coordinateSystem !== renderer.coordinateSystem) {
|
|
this.coordinateSystem = renderer.coordinateSystem;
|
|
this.updateCoordinateSystem();
|
|
}
|
|
const [cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ] = this.children;
|
|
const currentRenderTarget = renderer.getRenderTarget();
|
|
const currentActiveCubeFace = renderer.getActiveCubeFace();
|
|
const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
const currentXrEnabled = renderer.xr.enabled;
|
|
renderer.xr.enabled = false;
|
|
const generateMipmaps = renderTarget.texture.generateMipmaps;
|
|
renderTarget.texture.generateMipmaps = false;
|
|
renderer.setRenderTarget(renderTarget, 0, activeMipmapLevel);
|
|
renderer.render(scene, cameraPX);
|
|
renderer.setRenderTarget(renderTarget, 1, activeMipmapLevel);
|
|
renderer.render(scene, cameraNX);
|
|
renderer.setRenderTarget(renderTarget, 2, activeMipmapLevel);
|
|
renderer.render(scene, cameraPY);
|
|
renderer.setRenderTarget(renderTarget, 3, activeMipmapLevel);
|
|
renderer.render(scene, cameraNY);
|
|
renderer.setRenderTarget(renderTarget, 4, activeMipmapLevel);
|
|
renderer.render(scene, cameraPZ);
|
|
renderTarget.texture.generateMipmaps = generateMipmaps;
|
|
renderer.setRenderTarget(renderTarget, 5, activeMipmapLevel);
|
|
renderer.render(scene, cameraNZ);
|
|
renderer.setRenderTarget(currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel);
|
|
renderer.xr.enabled = currentXrEnabled;
|
|
renderTarget.texture.needsPMREMUpdate = true;
|
|
}
|
|
};
|
|
CubeTexture = class CubeTexture extends Texture {
|
|
constructor(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace) {
|
|
images = images !== undefined ? images : [];
|
|
mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
|
|
super(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace);
|
|
this.isCubeTexture = true;
|
|
this.flipY = false;
|
|
}
|
|
get images() {
|
|
return this.image;
|
|
}
|
|
set images(value) {
|
|
this.image = value;
|
|
}
|
|
};
|
|
WebGLCubeRenderTarget = class WebGLCubeRenderTarget extends WebGLRenderTarget {
|
|
constructor(size = 1, options = {}) {
|
|
super(size, size, options);
|
|
this.isWebGLCubeRenderTarget = true;
|
|
const image = { width: size, height: size, depth: 1 };
|
|
const images = [image, image, image, image, image, image];
|
|
this.texture = new CubeTexture(images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace);
|
|
this.texture.isRenderTargetTexture = true;
|
|
this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
|
|
this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
|
|
}
|
|
fromEquirectangularTexture(renderer, texture) {
|
|
this.texture.type = texture.type;
|
|
this.texture.colorSpace = texture.colorSpace;
|
|
this.texture.generateMipmaps = texture.generateMipmaps;
|
|
this.texture.minFilter = texture.minFilter;
|
|
this.texture.magFilter = texture.magFilter;
|
|
const shader = {
|
|
uniforms: {
|
|
tEquirect: { value: null }
|
|
},
|
|
vertexShader: `
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
|
|
|
|
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
|
|
|
|
}
|
|
|
|
void main() {
|
|
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
|
|
}
|
|
`,
|
|
fragmentShader: `
|
|
|
|
uniform sampler2D tEquirect;
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
#include <common>
|
|
|
|
void main() {
|
|
|
|
vec3 direction = normalize( vWorldDirection );
|
|
|
|
vec2 sampleUV = equirectUv( direction );
|
|
|
|
gl_FragColor = texture2D( tEquirect, sampleUV );
|
|
|
|
}
|
|
`
|
|
};
|
|
const geometry = new BoxGeometry(5, 5, 5);
|
|
const material = new ShaderMaterial({
|
|
name: "CubemapFromEquirect",
|
|
uniforms: cloneUniforms(shader.uniforms),
|
|
vertexShader: shader.vertexShader,
|
|
fragmentShader: shader.fragmentShader,
|
|
side: BackSide,
|
|
blending: NoBlending
|
|
});
|
|
material.uniforms.tEquirect.value = texture;
|
|
const mesh = new Mesh(geometry, material);
|
|
const currentMinFilter = texture.minFilter;
|
|
if (texture.minFilter === LinearMipmapLinearFilter)
|
|
texture.minFilter = LinearFilter;
|
|
const camera = new CubeCamera(1, 10, this);
|
|
camera.update(renderer, mesh);
|
|
texture.minFilter = currentMinFilter;
|
|
mesh.geometry.dispose();
|
|
mesh.material.dispose();
|
|
return this;
|
|
}
|
|
clear(renderer, color, depth, stencil) {
|
|
const currentRenderTarget = renderer.getRenderTarget();
|
|
for (let i = 0;i < 6; i++) {
|
|
renderer.setRenderTarget(this, i);
|
|
renderer.clear(color, depth, stencil);
|
|
}
|
|
renderer.setRenderTarget(currentRenderTarget);
|
|
}
|
|
};
|
|
Group = class Group extends Object3D {
|
|
constructor() {
|
|
super();
|
|
this.isGroup = true;
|
|
this.type = "Group";
|
|
}
|
|
};
|
|
_moveEvent = { type: "move" };
|
|
Scene = class Scene extends Object3D {
|
|
constructor() {
|
|
super();
|
|
this.isScene = true;
|
|
this.type = "Scene";
|
|
this.background = null;
|
|
this.environment = null;
|
|
this.fog = null;
|
|
this.backgroundBlurriness = 0;
|
|
this.backgroundIntensity = 1;
|
|
this.backgroundRotation = new Euler;
|
|
this.environmentIntensity = 1;
|
|
this.environmentRotation = new Euler;
|
|
this.overrideMaterial = null;
|
|
if (typeof __THREE_DEVTOOLS__ !== "undefined") {
|
|
__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", { detail: this }));
|
|
}
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
if (source.background !== null)
|
|
this.background = source.background.clone();
|
|
if (source.environment !== null)
|
|
this.environment = source.environment.clone();
|
|
if (source.fog !== null)
|
|
this.fog = source.fog.clone();
|
|
this.backgroundBlurriness = source.backgroundBlurriness;
|
|
this.backgroundIntensity = source.backgroundIntensity;
|
|
this.backgroundRotation.copy(source.backgroundRotation);
|
|
this.environmentIntensity = source.environmentIntensity;
|
|
this.environmentRotation.copy(source.environmentRotation);
|
|
if (source.overrideMaterial !== null)
|
|
this.overrideMaterial = source.overrideMaterial.clone();
|
|
this.matrixAutoUpdate = source.matrixAutoUpdate;
|
|
return this;
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
if (this.fog !== null)
|
|
data.object.fog = this.fog.toJSON();
|
|
if (this.backgroundBlurriness > 0)
|
|
data.object.backgroundBlurriness = this.backgroundBlurriness;
|
|
if (this.backgroundIntensity !== 1)
|
|
data.object.backgroundIntensity = this.backgroundIntensity;
|
|
data.object.backgroundRotation = this.backgroundRotation.toArray();
|
|
if (this.environmentIntensity !== 1)
|
|
data.object.environmentIntensity = this.environmentIntensity;
|
|
data.object.environmentRotation = this.environmentRotation.toArray();
|
|
return data;
|
|
}
|
|
};
|
|
_vector$7 = /* @__PURE__ */ new Vector3;
|
|
SpriteMaterial = class SpriteMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isSpriteMaterial = true;
|
|
this.type = "SpriteMaterial";
|
|
this.color = new Color(16777215);
|
|
this.map = null;
|
|
this.alphaMap = null;
|
|
this.rotation = 0;
|
|
this.sizeAttenuation = true;
|
|
this.transparent = true;
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.color.copy(source.color);
|
|
this.map = source.map;
|
|
this.alphaMap = source.alphaMap;
|
|
this.rotation = source.rotation;
|
|
this.sizeAttenuation = source.sizeAttenuation;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
_intersectPoint = /* @__PURE__ */ new Vector3;
|
|
_worldScale = /* @__PURE__ */ new Vector3;
|
|
_mvPosition = /* @__PURE__ */ new Vector3;
|
|
_alignedPosition = /* @__PURE__ */ new Vector2;
|
|
_rotatedPosition = /* @__PURE__ */ new Vector2;
|
|
_viewWorldMatrix = /* @__PURE__ */ new Matrix4;
|
|
_vA = /* @__PURE__ */ new Vector3;
|
|
_vB = /* @__PURE__ */ new Vector3;
|
|
_vC = /* @__PURE__ */ new Vector3;
|
|
_uvA = /* @__PURE__ */ new Vector2;
|
|
_uvB = /* @__PURE__ */ new Vector2;
|
|
_uvC = /* @__PURE__ */ new Vector2;
|
|
Sprite = class Sprite extends Object3D {
|
|
constructor(material = new SpriteMaterial) {
|
|
super();
|
|
this.isSprite = true;
|
|
this.type = "Sprite";
|
|
if (_geometry === undefined) {
|
|
_geometry = new BufferGeometry;
|
|
const float32Array = new Float32Array([
|
|
-0.5,
|
|
-0.5,
|
|
0,
|
|
0,
|
|
0,
|
|
0.5,
|
|
-0.5,
|
|
0,
|
|
1,
|
|
0,
|
|
0.5,
|
|
0.5,
|
|
0,
|
|
1,
|
|
1,
|
|
-0.5,
|
|
0.5,
|
|
0,
|
|
0,
|
|
1
|
|
]);
|
|
const interleavedBuffer = new InterleavedBuffer(float32Array, 5);
|
|
_geometry.setIndex([0, 1, 2, 0, 2, 3]);
|
|
_geometry.setAttribute("position", new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
|
|
_geometry.setAttribute("uv", new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
|
|
}
|
|
this.geometry = _geometry;
|
|
this.material = material;
|
|
this.center = new Vector2(0.5, 0.5);
|
|
}
|
|
raycast(raycaster, intersects) {
|
|
if (raycaster.camera === null) {
|
|
console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
|
|
}
|
|
_worldScale.setFromMatrixScale(this.matrixWorld);
|
|
_viewWorldMatrix.copy(raycaster.camera.matrixWorld);
|
|
this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
|
|
_mvPosition.setFromMatrixPosition(this.modelViewMatrix);
|
|
if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
|
|
_worldScale.multiplyScalar(-_mvPosition.z);
|
|
}
|
|
const rotation = this.material.rotation;
|
|
let sin, cos;
|
|
if (rotation !== 0) {
|
|
cos = Math.cos(rotation);
|
|
sin = Math.sin(rotation);
|
|
}
|
|
const center = this.center;
|
|
transformVertex(_vA.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
|
transformVertex(_vB.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
|
transformVertex(_vC.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
|
_uvA.set(0, 0);
|
|
_uvB.set(1, 0);
|
|
_uvC.set(1, 1);
|
|
let intersect = raycaster.ray.intersectTriangle(_vA, _vB, _vC, false, _intersectPoint);
|
|
if (intersect === null) {
|
|
transformVertex(_vB.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
|
_uvB.set(0, 1);
|
|
intersect = raycaster.ray.intersectTriangle(_vA, _vC, _vB, false, _intersectPoint);
|
|
if (intersect === null) {
|
|
return;
|
|
}
|
|
}
|
|
const distance = raycaster.ray.origin.distanceTo(_intersectPoint);
|
|
if (distance < raycaster.near || distance > raycaster.far)
|
|
return;
|
|
intersects.push({
|
|
distance,
|
|
point: _intersectPoint.clone(),
|
|
uv: Triangle.getInterpolation(_intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2),
|
|
face: null,
|
|
object: this
|
|
});
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
if (source.center !== undefined)
|
|
this.center.copy(source.center);
|
|
this.material = source.material;
|
|
return this;
|
|
}
|
|
};
|
|
_v1$2 = /* @__PURE__ */ new Vector3;
|
|
_v2$1 = /* @__PURE__ */ new Vector3;
|
|
LOD = class LOD extends Object3D {
|
|
constructor() {
|
|
super();
|
|
this._currentLevel = 0;
|
|
this.type = "LOD";
|
|
Object.defineProperties(this, {
|
|
levels: {
|
|
enumerable: true,
|
|
value: []
|
|
},
|
|
isLOD: {
|
|
value: true
|
|
}
|
|
});
|
|
this.autoUpdate = true;
|
|
}
|
|
copy(source) {
|
|
super.copy(source, false);
|
|
const levels = source.levels;
|
|
for (let i = 0, l = levels.length;i < l; i++) {
|
|
const level = levels[i];
|
|
this.addLevel(level.object.clone(), level.distance, level.hysteresis);
|
|
}
|
|
this.autoUpdate = source.autoUpdate;
|
|
return this;
|
|
}
|
|
addLevel(object, distance = 0, hysteresis = 0) {
|
|
distance = Math.abs(distance);
|
|
const levels = this.levels;
|
|
let l;
|
|
for (l = 0;l < levels.length; l++) {
|
|
if (distance < levels[l].distance) {
|
|
break;
|
|
}
|
|
}
|
|
levels.splice(l, 0, { distance, hysteresis, object });
|
|
this.add(object);
|
|
return this;
|
|
}
|
|
removeLevel(distance) {
|
|
const levels = this.levels;
|
|
for (let i = 0;i < levels.length; i++) {
|
|
if (levels[i].distance === distance) {
|
|
const removedElements = levels.splice(i, 1);
|
|
this.remove(removedElements[0].object);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
getCurrentLevel() {
|
|
return this._currentLevel;
|
|
}
|
|
getObjectForDistance(distance) {
|
|
const levels = this.levels;
|
|
if (levels.length > 0) {
|
|
let i, l;
|
|
for (i = 1, l = levels.length;i < l; i++) {
|
|
let levelDistance = levels[i].distance;
|
|
if (levels[i].object.visible) {
|
|
levelDistance -= levelDistance * levels[i].hysteresis;
|
|
}
|
|
if (distance < levelDistance) {
|
|
break;
|
|
}
|
|
}
|
|
return levels[i - 1].object;
|
|
}
|
|
return null;
|
|
}
|
|
raycast(raycaster, intersects) {
|
|
const levels = this.levels;
|
|
if (levels.length > 0) {
|
|
_v1$2.setFromMatrixPosition(this.matrixWorld);
|
|
const distance = raycaster.ray.origin.distanceTo(_v1$2);
|
|
this.getObjectForDistance(distance).raycast(raycaster, intersects);
|
|
}
|
|
}
|
|
update(camera) {
|
|
const levels = this.levels;
|
|
if (levels.length > 1) {
|
|
_v1$2.setFromMatrixPosition(camera.matrixWorld);
|
|
_v2$1.setFromMatrixPosition(this.matrixWorld);
|
|
const distance = _v1$2.distanceTo(_v2$1) / camera.zoom;
|
|
levels[0].object.visible = true;
|
|
let i, l;
|
|
for (i = 1, l = levels.length;i < l; i++) {
|
|
let levelDistance = levels[i].distance;
|
|
if (levels[i].object.visible) {
|
|
levelDistance -= levelDistance * levels[i].hysteresis;
|
|
}
|
|
if (distance >= levelDistance) {
|
|
levels[i - 1].object.visible = false;
|
|
levels[i].object.visible = true;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
this._currentLevel = i - 1;
|
|
for (;i < l; i++) {
|
|
levels[i].object.visible = false;
|
|
}
|
|
}
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
if (this.autoUpdate === false)
|
|
data.object.autoUpdate = false;
|
|
data.object.levels = [];
|
|
const levels = this.levels;
|
|
for (let i = 0, l = levels.length;i < l; i++) {
|
|
const level = levels[i];
|
|
data.object.levels.push({
|
|
object: level.object.uuid,
|
|
distance: level.distance,
|
|
hysteresis: level.hysteresis
|
|
});
|
|
}
|
|
return data;
|
|
}
|
|
};
|
|
_basePosition = /* @__PURE__ */ new Vector3;
|
|
_skinIndex = /* @__PURE__ */ new Vector4;
|
|
_skinWeight = /* @__PURE__ */ new Vector4;
|
|
_vector3 = /* @__PURE__ */ new Vector3;
|
|
_matrix4 = /* @__PURE__ */ new Matrix4;
|
|
_vertex = /* @__PURE__ */ new Vector3;
|
|
_sphere$5 = /* @__PURE__ */ new Sphere;
|
|
_inverseMatrix$2 = /* @__PURE__ */ new Matrix4;
|
|
_ray$2 = /* @__PURE__ */ new Ray;
|
|
SkinnedMesh = class SkinnedMesh extends Mesh {
|
|
constructor(geometry, material) {
|
|
super(geometry, material);
|
|
this.isSkinnedMesh = true;
|
|
this.type = "SkinnedMesh";
|
|
this.bindMode = AttachedBindMode;
|
|
this.bindMatrix = new Matrix4;
|
|
this.bindMatrixInverse = new Matrix4;
|
|
this.boundingBox = null;
|
|
this.boundingSphere = null;
|
|
}
|
|
computeBoundingBox() {
|
|
const geometry = this.geometry;
|
|
if (this.boundingBox === null) {
|
|
this.boundingBox = new Box3;
|
|
}
|
|
this.boundingBox.makeEmpty();
|
|
const positionAttribute = geometry.getAttribute("position");
|
|
for (let i = 0;i < positionAttribute.count; i++) {
|
|
this.getVertexPosition(i, _vertex);
|
|
this.boundingBox.expandByPoint(_vertex);
|
|
}
|
|
}
|
|
computeBoundingSphere() {
|
|
const geometry = this.geometry;
|
|
if (this.boundingSphere === null) {
|
|
this.boundingSphere = new Sphere;
|
|
}
|
|
this.boundingSphere.makeEmpty();
|
|
const positionAttribute = geometry.getAttribute("position");
|
|
for (let i = 0;i < positionAttribute.count; i++) {
|
|
this.getVertexPosition(i, _vertex);
|
|
this.boundingSphere.expandByPoint(_vertex);
|
|
}
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.bindMode = source.bindMode;
|
|
this.bindMatrix.copy(source.bindMatrix);
|
|
this.bindMatrixInverse.copy(source.bindMatrixInverse);
|
|
this.skeleton = source.skeleton;
|
|
if (source.boundingBox !== null)
|
|
this.boundingBox = source.boundingBox.clone();
|
|
if (source.boundingSphere !== null)
|
|
this.boundingSphere = source.boundingSphere.clone();
|
|
return this;
|
|
}
|
|
raycast(raycaster, intersects) {
|
|
const material = this.material;
|
|
const matrixWorld = this.matrixWorld;
|
|
if (material === undefined)
|
|
return;
|
|
if (this.boundingSphere === null)
|
|
this.computeBoundingSphere();
|
|
_sphere$5.copy(this.boundingSphere);
|
|
_sphere$5.applyMatrix4(matrixWorld);
|
|
if (raycaster.ray.intersectsSphere(_sphere$5) === false)
|
|
return;
|
|
_inverseMatrix$2.copy(matrixWorld).invert();
|
|
_ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
|
|
if (this.boundingBox !== null) {
|
|
if (_ray$2.intersectsBox(this.boundingBox) === false)
|
|
return;
|
|
}
|
|
this._computeIntersections(raycaster, intersects, _ray$2);
|
|
}
|
|
getVertexPosition(index, target) {
|
|
super.getVertexPosition(index, target);
|
|
this.applyBoneTransform(index, target);
|
|
return target;
|
|
}
|
|
bind(skeleton, bindMatrix) {
|
|
this.skeleton = skeleton;
|
|
if (bindMatrix === undefined) {
|
|
this.updateMatrixWorld(true);
|
|
this.skeleton.calculateInverses();
|
|
bindMatrix = this.matrixWorld;
|
|
}
|
|
this.bindMatrix.copy(bindMatrix);
|
|
this.bindMatrixInverse.copy(bindMatrix).invert();
|
|
}
|
|
pose() {
|
|
this.skeleton.pose();
|
|
}
|
|
normalizeSkinWeights() {
|
|
const vector = new Vector4;
|
|
const skinWeight = this.geometry.attributes.skinWeight;
|
|
for (let i = 0, l = skinWeight.count;i < l; i++) {
|
|
vector.fromBufferAttribute(skinWeight, i);
|
|
const scale = 1 / vector.manhattanLength();
|
|
if (scale !== Infinity) {
|
|
vector.multiplyScalar(scale);
|
|
} else {
|
|
vector.set(1, 0, 0, 0);
|
|
}
|
|
skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
|
|
}
|
|
}
|
|
updateMatrixWorld(force) {
|
|
super.updateMatrixWorld(force);
|
|
if (this.bindMode === AttachedBindMode) {
|
|
this.bindMatrixInverse.copy(this.matrixWorld).invert();
|
|
} else if (this.bindMode === DetachedBindMode) {
|
|
this.bindMatrixInverse.copy(this.bindMatrix).invert();
|
|
} else {
|
|
console.warn("THREE.SkinnedMesh: Unrecognized bindMode: " + this.bindMode);
|
|
}
|
|
}
|
|
applyBoneTransform(index, vector) {
|
|
const skeleton = this.skeleton;
|
|
const geometry = this.geometry;
|
|
_skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
|
|
_skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
|
|
_basePosition.copy(vector).applyMatrix4(this.bindMatrix);
|
|
vector.set(0, 0, 0);
|
|
for (let i = 0;i < 4; i++) {
|
|
const weight = _skinWeight.getComponent(i);
|
|
if (weight !== 0) {
|
|
const boneIndex = _skinIndex.getComponent(i);
|
|
_matrix4.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
|
|
vector.addScaledVector(_vector3.copy(_basePosition).applyMatrix4(_matrix4), weight);
|
|
}
|
|
}
|
|
return vector.applyMatrix4(this.bindMatrixInverse);
|
|
}
|
|
};
|
|
Bone = class Bone extends Object3D {
|
|
constructor() {
|
|
super();
|
|
this.isBone = true;
|
|
this.type = "Bone";
|
|
}
|
|
};
|
|
DataTexture = class DataTexture extends Texture {
|
|
constructor(data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace) {
|
|
super(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace);
|
|
this.isDataTexture = true;
|
|
this.image = { data, width, height };
|
|
this.generateMipmaps = false;
|
|
this.flipY = false;
|
|
this.unpackAlignment = 1;
|
|
}
|
|
};
|
|
_offsetMatrix = /* @__PURE__ */ new Matrix4;
|
|
_identityMatrix = /* @__PURE__ */ new Matrix4;
|
|
InstancedBufferAttribute = class InstancedBufferAttribute extends BufferAttribute {
|
|
constructor(array, itemSize, normalized, meshPerAttribute = 1) {
|
|
super(array, itemSize, normalized);
|
|
this.isInstancedBufferAttribute = true;
|
|
this.meshPerAttribute = meshPerAttribute;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.meshPerAttribute = source.meshPerAttribute;
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.meshPerAttribute = this.meshPerAttribute;
|
|
data.isInstancedBufferAttribute = true;
|
|
return data;
|
|
}
|
|
};
|
|
_instanceLocalMatrix = /* @__PURE__ */ new Matrix4;
|
|
_instanceWorldMatrix = /* @__PURE__ */ new Matrix4;
|
|
_instanceIntersects = [];
|
|
_box3 = /* @__PURE__ */ new Box3;
|
|
_identity = /* @__PURE__ */ new Matrix4;
|
|
_mesh$1 = /* @__PURE__ */ new Mesh;
|
|
_sphere$4 = /* @__PURE__ */ new Sphere;
|
|
InstancedMesh = class InstancedMesh extends Mesh {
|
|
constructor(geometry, material, count) {
|
|
super(geometry, material);
|
|
this.isInstancedMesh = true;
|
|
this.instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
|
|
this.instanceColor = null;
|
|
this.morphTexture = null;
|
|
this.count = count;
|
|
this.boundingBox = null;
|
|
this.boundingSphere = null;
|
|
for (let i = 0;i < count; i++) {
|
|
this.setMatrixAt(i, _identity);
|
|
}
|
|
}
|
|
computeBoundingBox() {
|
|
const geometry = this.geometry;
|
|
const count = this.count;
|
|
if (this.boundingBox === null) {
|
|
this.boundingBox = new Box3;
|
|
}
|
|
if (geometry.boundingBox === null) {
|
|
geometry.computeBoundingBox();
|
|
}
|
|
this.boundingBox.makeEmpty();
|
|
for (let i = 0;i < count; i++) {
|
|
this.getMatrixAt(i, _instanceLocalMatrix);
|
|
_box3.copy(geometry.boundingBox).applyMatrix4(_instanceLocalMatrix);
|
|
this.boundingBox.union(_box3);
|
|
}
|
|
}
|
|
computeBoundingSphere() {
|
|
const geometry = this.geometry;
|
|
const count = this.count;
|
|
if (this.boundingSphere === null) {
|
|
this.boundingSphere = new Sphere;
|
|
}
|
|
if (geometry.boundingSphere === null) {
|
|
geometry.computeBoundingSphere();
|
|
}
|
|
this.boundingSphere.makeEmpty();
|
|
for (let i = 0;i < count; i++) {
|
|
this.getMatrixAt(i, _instanceLocalMatrix);
|
|
_sphere$4.copy(geometry.boundingSphere).applyMatrix4(_instanceLocalMatrix);
|
|
this.boundingSphere.union(_sphere$4);
|
|
}
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.instanceMatrix.copy(source.instanceMatrix);
|
|
if (source.morphTexture !== null)
|
|
this.morphTexture = source.morphTexture.clone();
|
|
if (source.instanceColor !== null)
|
|
this.instanceColor = source.instanceColor.clone();
|
|
this.count = source.count;
|
|
if (source.boundingBox !== null)
|
|
this.boundingBox = source.boundingBox.clone();
|
|
if (source.boundingSphere !== null)
|
|
this.boundingSphere = source.boundingSphere.clone();
|
|
return this;
|
|
}
|
|
getColorAt(index, color) {
|
|
color.fromArray(this.instanceColor.array, index * 3);
|
|
}
|
|
getMatrixAt(index, matrix) {
|
|
matrix.fromArray(this.instanceMatrix.array, index * 16);
|
|
}
|
|
getMorphAt(index, object) {
|
|
const objectInfluences = object.morphTargetInfluences;
|
|
const array = this.morphTexture.source.data.data;
|
|
const len = objectInfluences.length + 1;
|
|
const dataIndex = index * len + 1;
|
|
for (let i = 0;i < objectInfluences.length; i++) {
|
|
objectInfluences[i] = array[dataIndex + i];
|
|
}
|
|
}
|
|
raycast(raycaster, intersects) {
|
|
const matrixWorld = this.matrixWorld;
|
|
const raycastTimes = this.count;
|
|
_mesh$1.geometry = this.geometry;
|
|
_mesh$1.material = this.material;
|
|
if (_mesh$1.material === undefined)
|
|
return;
|
|
if (this.boundingSphere === null)
|
|
this.computeBoundingSphere();
|
|
_sphere$4.copy(this.boundingSphere);
|
|
_sphere$4.applyMatrix4(matrixWorld);
|
|
if (raycaster.ray.intersectsSphere(_sphere$4) === false)
|
|
return;
|
|
for (let instanceId = 0;instanceId < raycastTimes; instanceId++) {
|
|
this.getMatrixAt(instanceId, _instanceLocalMatrix);
|
|
_instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix);
|
|
_mesh$1.matrixWorld = _instanceWorldMatrix;
|
|
_mesh$1.raycast(raycaster, _instanceIntersects);
|
|
for (let i = 0, l = _instanceIntersects.length;i < l; i++) {
|
|
const intersect = _instanceIntersects[i];
|
|
intersect.instanceId = instanceId;
|
|
intersect.object = this;
|
|
intersects.push(intersect);
|
|
}
|
|
_instanceIntersects.length = 0;
|
|
}
|
|
}
|
|
setColorAt(index, color) {
|
|
if (this.instanceColor === null) {
|
|
this.instanceColor = new InstancedBufferAttribute(new Float32Array(this.instanceMatrix.count * 3).fill(1), 3);
|
|
}
|
|
color.toArray(this.instanceColor.array, index * 3);
|
|
}
|
|
setMatrixAt(index, matrix) {
|
|
matrix.toArray(this.instanceMatrix.array, index * 16);
|
|
}
|
|
setMorphAt(index, object) {
|
|
const objectInfluences = object.morphTargetInfluences;
|
|
const len = objectInfluences.length + 1;
|
|
if (this.morphTexture === null) {
|
|
this.morphTexture = new DataTexture(new Float32Array(len * this.count), len, this.count, RedFormat, FloatType);
|
|
}
|
|
const array = this.morphTexture.source.data.data;
|
|
let morphInfluencesSum = 0;
|
|
for (let i = 0;i < objectInfluences.length; i++) {
|
|
morphInfluencesSum += objectInfluences[i];
|
|
}
|
|
const morphBaseInfluence = this.geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
|
|
const dataIndex = len * index;
|
|
array[dataIndex] = morphBaseInfluence;
|
|
array.set(objectInfluences, dataIndex + 1);
|
|
}
|
|
updateMorphTargets() {}
|
|
dispose() {
|
|
this.dispatchEvent({ type: "dispose" });
|
|
if (this.morphTexture !== null) {
|
|
this.morphTexture.dispose();
|
|
this.morphTexture = null;
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
_vector1 = /* @__PURE__ */ new Vector3;
|
|
_vector2 = /* @__PURE__ */ new Vector3;
|
|
_normalMatrix = /* @__PURE__ */ new Matrix3;
|
|
_sphere$3 = /* @__PURE__ */ new Sphere;
|
|
_vector$6 = /* @__PURE__ */ new Vector3;
|
|
_matrix$1 = /* @__PURE__ */ new Matrix4;
|
|
_whiteColor = /* @__PURE__ */ new Color(1, 1, 1);
|
|
_frustum = /* @__PURE__ */ new Frustum;
|
|
_box$1 = /* @__PURE__ */ new Box3;
|
|
_sphere$2 = /* @__PURE__ */ new Sphere;
|
|
_vector$5 = /* @__PURE__ */ new Vector3;
|
|
_forward = /* @__PURE__ */ new Vector3;
|
|
_temp = /* @__PURE__ */ new Vector3;
|
|
_renderList = /* @__PURE__ */ new MultiDrawRenderList;
|
|
_mesh = /* @__PURE__ */ new Mesh;
|
|
_batchIntersects = [];
|
|
BatchedMesh = class BatchedMesh extends Mesh {
|
|
get maxInstanceCount() {
|
|
return this._maxInstanceCount;
|
|
}
|
|
get instanceCount() {
|
|
return this._instanceInfo.length - this._availableInstanceIds.length;
|
|
}
|
|
get unusedVertexCount() {
|
|
return this._maxVertexCount - this._nextVertexStart;
|
|
}
|
|
get unusedIndexCount() {
|
|
return this._maxIndexCount - this._nextIndexStart;
|
|
}
|
|
constructor(maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material) {
|
|
super(new BufferGeometry, material);
|
|
this.isBatchedMesh = true;
|
|
this.perObjectFrustumCulled = true;
|
|
this.sortObjects = true;
|
|
this.boundingBox = null;
|
|
this.boundingSphere = null;
|
|
this.customSort = null;
|
|
this._instanceInfo = [];
|
|
this._geometryInfo = [];
|
|
this._availableInstanceIds = [];
|
|
this._availableGeometryIds = [];
|
|
this._nextIndexStart = 0;
|
|
this._nextVertexStart = 0;
|
|
this._geometryCount = 0;
|
|
this._visibilityChanged = true;
|
|
this._geometryInitialized = false;
|
|
this._maxInstanceCount = maxInstanceCount;
|
|
this._maxVertexCount = maxVertexCount;
|
|
this._maxIndexCount = maxIndexCount;
|
|
this._multiDrawCounts = new Int32Array(maxInstanceCount);
|
|
this._multiDrawStarts = new Int32Array(maxInstanceCount);
|
|
this._multiDrawCount = 0;
|
|
this._multiDrawInstances = null;
|
|
this._matricesTexture = null;
|
|
this._indirectTexture = null;
|
|
this._colorsTexture = null;
|
|
this._initMatricesTexture();
|
|
this._initIndirectTexture();
|
|
}
|
|
_initMatricesTexture() {
|
|
let size = Math.sqrt(this._maxInstanceCount * 4);
|
|
size = Math.ceil(size / 4) * 4;
|
|
size = Math.max(size, 4);
|
|
const matricesArray = new Float32Array(size * size * 4);
|
|
const matricesTexture = new DataTexture(matricesArray, size, size, RGBAFormat, FloatType);
|
|
this._matricesTexture = matricesTexture;
|
|
}
|
|
_initIndirectTexture() {
|
|
let size = Math.sqrt(this._maxInstanceCount);
|
|
size = Math.ceil(size);
|
|
const indirectArray = new Uint32Array(size * size);
|
|
const indirectTexture = new DataTexture(indirectArray, size, size, RedIntegerFormat, UnsignedIntType);
|
|
this._indirectTexture = indirectTexture;
|
|
}
|
|
_initColorsTexture() {
|
|
let size = Math.sqrt(this._maxInstanceCount);
|
|
size = Math.ceil(size);
|
|
const colorsArray = new Float32Array(size * size * 4).fill(1);
|
|
const colorsTexture = new DataTexture(colorsArray, size, size, RGBAFormat, FloatType);
|
|
colorsTexture.colorSpace = ColorManagement.workingColorSpace;
|
|
this._colorsTexture = colorsTexture;
|
|
}
|
|
_initializeGeometry(reference) {
|
|
const geometry = this.geometry;
|
|
const maxVertexCount = this._maxVertexCount;
|
|
const maxIndexCount = this._maxIndexCount;
|
|
if (this._geometryInitialized === false) {
|
|
for (const attributeName in reference.attributes) {
|
|
const srcAttribute = reference.getAttribute(attributeName);
|
|
const { array, itemSize, normalized } = srcAttribute;
|
|
const dstArray = new array.constructor(maxVertexCount * itemSize);
|
|
const dstAttribute = new BufferAttribute(dstArray, itemSize, normalized);
|
|
geometry.setAttribute(attributeName, dstAttribute);
|
|
}
|
|
if (reference.getIndex() !== null) {
|
|
const indexArray = maxVertexCount > 65535 ? new Uint32Array(maxIndexCount) : new Uint16Array(maxIndexCount);
|
|
geometry.setIndex(new BufferAttribute(indexArray, 1));
|
|
}
|
|
this._geometryInitialized = true;
|
|
}
|
|
}
|
|
_validateGeometry(geometry) {
|
|
const batchGeometry = this.geometry;
|
|
if (Boolean(geometry.getIndex()) !== Boolean(batchGeometry.getIndex())) {
|
|
throw new Error('THREE.BatchedMesh: All geometries must consistently have "index".');
|
|
}
|
|
for (const attributeName in batchGeometry.attributes) {
|
|
if (!geometry.hasAttribute(attributeName)) {
|
|
throw new Error(`THREE.BatchedMesh: Added geometry missing "${attributeName}". All geometries must have consistent attributes.`);
|
|
}
|
|
const srcAttribute = geometry.getAttribute(attributeName);
|
|
const dstAttribute = batchGeometry.getAttribute(attributeName);
|
|
if (srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized) {
|
|
throw new Error("THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.");
|
|
}
|
|
}
|
|
}
|
|
validateInstanceId(instanceId) {
|
|
const instanceInfo = this._instanceInfo;
|
|
if (instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[instanceId].active === false) {
|
|
throw new Error(`THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.`);
|
|
}
|
|
}
|
|
validateGeometryId(geometryId) {
|
|
const geometryInfoList = this._geometryInfo;
|
|
if (geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[geometryId].active === false) {
|
|
throw new Error(`THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.`);
|
|
}
|
|
}
|
|
setCustomSort(func) {
|
|
this.customSort = func;
|
|
return this;
|
|
}
|
|
computeBoundingBox() {
|
|
if (this.boundingBox === null) {
|
|
this.boundingBox = new Box3;
|
|
}
|
|
const boundingBox = this.boundingBox;
|
|
const instanceInfo = this._instanceInfo;
|
|
boundingBox.makeEmpty();
|
|
for (let i = 0, l = instanceInfo.length;i < l; i++) {
|
|
if (instanceInfo[i].active === false)
|
|
continue;
|
|
const geometryId = instanceInfo[i].geometryIndex;
|
|
this.getMatrixAt(i, _matrix$1);
|
|
this.getBoundingBoxAt(geometryId, _box$1).applyMatrix4(_matrix$1);
|
|
boundingBox.union(_box$1);
|
|
}
|
|
}
|
|
computeBoundingSphere() {
|
|
if (this.boundingSphere === null) {
|
|
this.boundingSphere = new Sphere;
|
|
}
|
|
const boundingSphere = this.boundingSphere;
|
|
const instanceInfo = this._instanceInfo;
|
|
boundingSphere.makeEmpty();
|
|
for (let i = 0, l = instanceInfo.length;i < l; i++) {
|
|
if (instanceInfo[i].active === false)
|
|
continue;
|
|
const geometryId = instanceInfo[i].geometryIndex;
|
|
this.getMatrixAt(i, _matrix$1);
|
|
this.getBoundingSphereAt(geometryId, _sphere$2).applyMatrix4(_matrix$1);
|
|
boundingSphere.union(_sphere$2);
|
|
}
|
|
}
|
|
addInstance(geometryId) {
|
|
const atCapacity = this._instanceInfo.length >= this.maxInstanceCount;
|
|
if (atCapacity && this._availableInstanceIds.length === 0) {
|
|
throw new Error("THREE.BatchedMesh: Maximum item count reached.");
|
|
}
|
|
const instanceInfo = {
|
|
visible: true,
|
|
active: true,
|
|
geometryIndex: geometryId
|
|
};
|
|
let drawId = null;
|
|
if (this._availableInstanceIds.length > 0) {
|
|
this._availableInstanceIds.sort(ascIdSort);
|
|
drawId = this._availableInstanceIds.shift();
|
|
this._instanceInfo[drawId] = instanceInfo;
|
|
} else {
|
|
drawId = this._instanceInfo.length;
|
|
this._instanceInfo.push(instanceInfo);
|
|
}
|
|
const matricesTexture = this._matricesTexture;
|
|
_matrix$1.identity().toArray(matricesTexture.image.data, drawId * 16);
|
|
matricesTexture.needsUpdate = true;
|
|
const colorsTexture = this._colorsTexture;
|
|
if (colorsTexture) {
|
|
_whiteColor.toArray(colorsTexture.image.data, drawId * 4);
|
|
colorsTexture.needsUpdate = true;
|
|
}
|
|
this._visibilityChanged = true;
|
|
return drawId;
|
|
}
|
|
addGeometry(geometry, reservedVertexCount = -1, reservedIndexCount = -1) {
|
|
this._initializeGeometry(geometry);
|
|
this._validateGeometry(geometry);
|
|
const geometryInfo = {
|
|
vertexStart: -1,
|
|
vertexCount: -1,
|
|
reservedVertexCount: -1,
|
|
indexStart: -1,
|
|
indexCount: -1,
|
|
reservedIndexCount: -1,
|
|
start: -1,
|
|
count: -1,
|
|
boundingBox: null,
|
|
boundingSphere: null,
|
|
active: true
|
|
};
|
|
const geometryInfoList = this._geometryInfo;
|
|
geometryInfo.vertexStart = this._nextVertexStart;
|
|
geometryInfo.reservedVertexCount = reservedVertexCount === -1 ? geometry.getAttribute("position").count : reservedVertexCount;
|
|
const index = geometry.getIndex();
|
|
const hasIndex = index !== null;
|
|
if (hasIndex) {
|
|
geometryInfo.indexStart = this._nextIndexStart;
|
|
geometryInfo.reservedIndexCount = reservedIndexCount === -1 ? index.count : reservedIndexCount;
|
|
}
|
|
if (geometryInfo.indexStart !== -1 && geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount || geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount) {
|
|
throw new Error("THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.");
|
|
}
|
|
let geometryId;
|
|
if (this._availableGeometryIds.length > 0) {
|
|
this._availableGeometryIds.sort(ascIdSort);
|
|
geometryId = this._availableGeometryIds.shift();
|
|
geometryInfoList[geometryId] = geometryInfo;
|
|
} else {
|
|
geometryId = this._geometryCount;
|
|
this._geometryCount++;
|
|
geometryInfoList.push(geometryInfo);
|
|
}
|
|
this.setGeometryAt(geometryId, geometry);
|
|
this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount;
|
|
this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
|
|
return geometryId;
|
|
}
|
|
setGeometryAt(geometryId, geometry) {
|
|
if (geometryId >= this._geometryCount) {
|
|
throw new Error("THREE.BatchedMesh: Maximum geometry count reached.");
|
|
}
|
|
this._validateGeometry(geometry);
|
|
const batchGeometry = this.geometry;
|
|
const hasIndex = batchGeometry.getIndex() !== null;
|
|
const dstIndex = batchGeometry.getIndex();
|
|
const srcIndex = geometry.getIndex();
|
|
const geometryInfo = this._geometryInfo[geometryId];
|
|
if (hasIndex && srcIndex.count > geometryInfo.reservedIndexCount || geometry.attributes.position.count > geometryInfo.reservedVertexCount) {
|
|
throw new Error("THREE.BatchedMesh: Reserved space not large enough for provided geometry.");
|
|
}
|
|
const vertexStart = geometryInfo.vertexStart;
|
|
const reservedVertexCount = geometryInfo.reservedVertexCount;
|
|
geometryInfo.vertexCount = geometry.getAttribute("position").count;
|
|
for (const attributeName in batchGeometry.attributes) {
|
|
const srcAttribute = geometry.getAttribute(attributeName);
|
|
const dstAttribute = batchGeometry.getAttribute(attributeName);
|
|
copyAttributeData(srcAttribute, dstAttribute, vertexStart);
|
|
const itemSize = srcAttribute.itemSize;
|
|
for (let i = srcAttribute.count, l = reservedVertexCount;i < l; i++) {
|
|
const index = vertexStart + i;
|
|
for (let c = 0;c < itemSize; c++) {
|
|
dstAttribute.setComponent(index, c, 0);
|
|
}
|
|
}
|
|
dstAttribute.needsUpdate = true;
|
|
dstAttribute.addUpdateRange(vertexStart * itemSize, reservedVertexCount * itemSize);
|
|
}
|
|
if (hasIndex) {
|
|
const indexStart = geometryInfo.indexStart;
|
|
const reservedIndexCount = geometryInfo.reservedIndexCount;
|
|
geometryInfo.indexCount = geometry.getIndex().count;
|
|
for (let i = 0;i < srcIndex.count; i++) {
|
|
dstIndex.setX(indexStart + i, vertexStart + srcIndex.getX(i));
|
|
}
|
|
for (let i = srcIndex.count, l = reservedIndexCount;i < l; i++) {
|
|
dstIndex.setX(indexStart + i, vertexStart);
|
|
}
|
|
dstIndex.needsUpdate = true;
|
|
dstIndex.addUpdateRange(indexStart, geometryInfo.reservedIndexCount);
|
|
}
|
|
geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart;
|
|
geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount;
|
|
geometryInfo.boundingBox = null;
|
|
if (geometry.boundingBox !== null) {
|
|
geometryInfo.boundingBox = geometry.boundingBox.clone();
|
|
}
|
|
geometryInfo.boundingSphere = null;
|
|
if (geometry.boundingSphere !== null) {
|
|
geometryInfo.boundingSphere = geometry.boundingSphere.clone();
|
|
}
|
|
this._visibilityChanged = true;
|
|
return geometryId;
|
|
}
|
|
deleteGeometry(geometryId) {
|
|
const geometryInfoList = this._geometryInfo;
|
|
if (geometryId >= geometryInfoList.length || geometryInfoList[geometryId].active === false) {
|
|
return this;
|
|
}
|
|
const instanceInfo = this._instanceInfo;
|
|
for (let i = 0, l = instanceInfo.length;i < l; i++) {
|
|
if (instanceInfo[i].active && instanceInfo[i].geometryIndex === geometryId) {
|
|
this.deleteInstance(i);
|
|
}
|
|
}
|
|
geometryInfoList[geometryId].active = false;
|
|
this._availableGeometryIds.push(geometryId);
|
|
this._visibilityChanged = true;
|
|
return this;
|
|
}
|
|
deleteInstance(instanceId) {
|
|
this.validateInstanceId(instanceId);
|
|
this._instanceInfo[instanceId].active = false;
|
|
this._availableInstanceIds.push(instanceId);
|
|
this._visibilityChanged = true;
|
|
return this;
|
|
}
|
|
optimize() {
|
|
let nextVertexStart = 0;
|
|
let nextIndexStart = 0;
|
|
const geometryInfoList = this._geometryInfo;
|
|
const indices = geometryInfoList.map((e, i) => i).sort((a, b) => {
|
|
return geometryInfoList[a].vertexStart - geometryInfoList[b].vertexStart;
|
|
});
|
|
const geometry = this.geometry;
|
|
for (let i = 0, l = geometryInfoList.length;i < l; i++) {
|
|
const index = indices[i];
|
|
const geometryInfo = geometryInfoList[index];
|
|
if (geometryInfo.active === false) {
|
|
continue;
|
|
}
|
|
if (geometry.index !== null) {
|
|
if (geometryInfo.indexStart !== nextIndexStart) {
|
|
const { indexStart, vertexStart, reservedIndexCount } = geometryInfo;
|
|
const index2 = geometry.index;
|
|
const array = index2.array;
|
|
const elementDelta = nextVertexStart - vertexStart;
|
|
for (let j = indexStart;j < indexStart + reservedIndexCount; j++) {
|
|
array[j] = array[j] + elementDelta;
|
|
}
|
|
index2.array.copyWithin(nextIndexStart, indexStart, indexStart + reservedIndexCount);
|
|
index2.addUpdateRange(nextIndexStart, reservedIndexCount);
|
|
geometryInfo.indexStart = nextIndexStart;
|
|
}
|
|
nextIndexStart += geometryInfo.reservedIndexCount;
|
|
}
|
|
if (geometryInfo.vertexStart !== nextVertexStart) {
|
|
const { vertexStart, reservedVertexCount } = geometryInfo;
|
|
const attributes = geometry.attributes;
|
|
for (const key in attributes) {
|
|
const attribute = attributes[key];
|
|
const { array, itemSize } = attribute;
|
|
array.copyWithin(nextVertexStart * itemSize, vertexStart * itemSize, (vertexStart + reservedVertexCount) * itemSize);
|
|
attribute.addUpdateRange(nextVertexStart * itemSize, reservedVertexCount * itemSize);
|
|
}
|
|
geometryInfo.vertexStart = nextVertexStart;
|
|
}
|
|
nextVertexStart += geometryInfo.reservedVertexCount;
|
|
geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart;
|
|
this._nextIndexStart = geometry.index ? geometryInfo.indexStart + geometryInfo.reservedIndexCount : 0;
|
|
this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
|
|
}
|
|
return this;
|
|
}
|
|
getBoundingBoxAt(geometryId, target) {
|
|
if (geometryId >= this._geometryCount) {
|
|
return null;
|
|
}
|
|
const geometry = this.geometry;
|
|
const geometryInfo = this._geometryInfo[geometryId];
|
|
if (geometryInfo.boundingBox === null) {
|
|
const box = new Box3;
|
|
const index = geometry.index;
|
|
const position = geometry.attributes.position;
|
|
for (let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count;i < l; i++) {
|
|
let iv = i;
|
|
if (index) {
|
|
iv = index.getX(iv);
|
|
}
|
|
box.expandByPoint(_vector$5.fromBufferAttribute(position, iv));
|
|
}
|
|
geometryInfo.boundingBox = box;
|
|
}
|
|
target.copy(geometryInfo.boundingBox);
|
|
return target;
|
|
}
|
|
getBoundingSphereAt(geometryId, target) {
|
|
if (geometryId >= this._geometryCount) {
|
|
return null;
|
|
}
|
|
const geometry = this.geometry;
|
|
const geometryInfo = this._geometryInfo[geometryId];
|
|
if (geometryInfo.boundingSphere === null) {
|
|
const sphere = new Sphere;
|
|
this.getBoundingBoxAt(geometryId, _box$1);
|
|
_box$1.getCenter(sphere.center);
|
|
const index = geometry.index;
|
|
const position = geometry.attributes.position;
|
|
let maxRadiusSq = 0;
|
|
for (let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count;i < l; i++) {
|
|
let iv = i;
|
|
if (index) {
|
|
iv = index.getX(iv);
|
|
}
|
|
_vector$5.fromBufferAttribute(position, iv);
|
|
maxRadiusSq = Math.max(maxRadiusSq, sphere.center.distanceToSquared(_vector$5));
|
|
}
|
|
sphere.radius = Math.sqrt(maxRadiusSq);
|
|
geometryInfo.boundingSphere = sphere;
|
|
}
|
|
target.copy(geometryInfo.boundingSphere);
|
|
return target;
|
|
}
|
|
setMatrixAt(instanceId, matrix) {
|
|
this.validateInstanceId(instanceId);
|
|
const matricesTexture = this._matricesTexture;
|
|
const matricesArray = this._matricesTexture.image.data;
|
|
matrix.toArray(matricesArray, instanceId * 16);
|
|
matricesTexture.needsUpdate = true;
|
|
return this;
|
|
}
|
|
getMatrixAt(instanceId, matrix) {
|
|
this.validateInstanceId(instanceId);
|
|
return matrix.fromArray(this._matricesTexture.image.data, instanceId * 16);
|
|
}
|
|
setColorAt(instanceId, color) {
|
|
this.validateInstanceId(instanceId);
|
|
if (this._colorsTexture === null) {
|
|
this._initColorsTexture();
|
|
}
|
|
color.toArray(this._colorsTexture.image.data, instanceId * 4);
|
|
this._colorsTexture.needsUpdate = true;
|
|
return this;
|
|
}
|
|
getColorAt(instanceId, color) {
|
|
this.validateInstanceId(instanceId);
|
|
return color.fromArray(this._colorsTexture.image.data, instanceId * 4);
|
|
}
|
|
setVisibleAt(instanceId, value) {
|
|
this.validateInstanceId(instanceId);
|
|
if (this._instanceInfo[instanceId].visible === value) {
|
|
return this;
|
|
}
|
|
this._instanceInfo[instanceId].visible = value;
|
|
this._visibilityChanged = true;
|
|
return this;
|
|
}
|
|
getVisibleAt(instanceId) {
|
|
this.validateInstanceId(instanceId);
|
|
return this._instanceInfo[instanceId].visible;
|
|
}
|
|
setGeometryIdAt(instanceId, geometryId) {
|
|
this.validateInstanceId(instanceId);
|
|
this.validateGeometryId(geometryId);
|
|
this._instanceInfo[instanceId].geometryIndex = geometryId;
|
|
return this;
|
|
}
|
|
getGeometryIdAt(instanceId) {
|
|
this.validateInstanceId(instanceId);
|
|
return this._instanceInfo[instanceId].geometryIndex;
|
|
}
|
|
getGeometryRangeAt(geometryId, target = {}) {
|
|
this.validateGeometryId(geometryId);
|
|
const geometryInfo = this._geometryInfo[geometryId];
|
|
target.vertexStart = geometryInfo.vertexStart;
|
|
target.vertexCount = geometryInfo.vertexCount;
|
|
target.reservedVertexCount = geometryInfo.reservedVertexCount;
|
|
target.indexStart = geometryInfo.indexStart;
|
|
target.indexCount = geometryInfo.indexCount;
|
|
target.reservedIndexCount = geometryInfo.reservedIndexCount;
|
|
target.start = geometryInfo.start;
|
|
target.count = geometryInfo.count;
|
|
return target;
|
|
}
|
|
setInstanceCount(maxInstanceCount) {
|
|
const availableInstanceIds = this._availableInstanceIds;
|
|
const instanceInfo = this._instanceInfo;
|
|
availableInstanceIds.sort(ascIdSort);
|
|
while (availableInstanceIds[availableInstanceIds.length - 1] === instanceInfo.length) {
|
|
instanceInfo.pop();
|
|
availableInstanceIds.pop();
|
|
}
|
|
if (maxInstanceCount < instanceInfo.length) {
|
|
throw new Error(`BatchedMesh: Instance ids outside the range ${maxInstanceCount} are being used. Cannot shrink instance count.`);
|
|
}
|
|
const multiDrawCounts = new Int32Array(maxInstanceCount);
|
|
const multiDrawStarts = new Int32Array(maxInstanceCount);
|
|
copyArrayContents(this._multiDrawCounts, multiDrawCounts);
|
|
copyArrayContents(this._multiDrawStarts, multiDrawStarts);
|
|
this._multiDrawCounts = multiDrawCounts;
|
|
this._multiDrawStarts = multiDrawStarts;
|
|
this._maxInstanceCount = maxInstanceCount;
|
|
const indirectTexture = this._indirectTexture;
|
|
const matricesTexture = this._matricesTexture;
|
|
const colorsTexture = this._colorsTexture;
|
|
indirectTexture.dispose();
|
|
this._initIndirectTexture();
|
|
copyArrayContents(indirectTexture.image.data, this._indirectTexture.image.data);
|
|
matricesTexture.dispose();
|
|
this._initMatricesTexture();
|
|
copyArrayContents(matricesTexture.image.data, this._matricesTexture.image.data);
|
|
if (colorsTexture) {
|
|
colorsTexture.dispose();
|
|
this._initColorsTexture();
|
|
copyArrayContents(colorsTexture.image.data, this._colorsTexture.image.data);
|
|
}
|
|
}
|
|
setGeometrySize(maxVertexCount, maxIndexCount) {
|
|
const validRanges = [...this._geometryInfo].filter((info) => info.active);
|
|
const requiredVertexLength = Math.max(...validRanges.map((range) => range.vertexStart + range.reservedVertexCount));
|
|
if (requiredVertexLength > maxVertexCount) {
|
|
throw new Error(`BatchedMesh: Geometry vertex values are being used outside the range ${maxIndexCount}. Cannot shrink further.`);
|
|
}
|
|
if (this.geometry.index) {
|
|
const requiredIndexLength = Math.max(...validRanges.map((range) => range.indexStart + range.reservedIndexCount));
|
|
if (requiredIndexLength > maxIndexCount) {
|
|
throw new Error(`BatchedMesh: Geometry index values are being used outside the range ${maxIndexCount}. Cannot shrink further.`);
|
|
}
|
|
}
|
|
const oldGeometry = this.geometry;
|
|
oldGeometry.dispose();
|
|
this._maxVertexCount = maxVertexCount;
|
|
this._maxIndexCount = maxIndexCount;
|
|
if (this._geometryInitialized) {
|
|
this._geometryInitialized = false;
|
|
this.geometry = new BufferGeometry;
|
|
this._initializeGeometry(oldGeometry);
|
|
}
|
|
const geometry = this.geometry;
|
|
if (oldGeometry.index) {
|
|
copyArrayContents(oldGeometry.index.array, geometry.index.array);
|
|
}
|
|
for (const key in oldGeometry.attributes) {
|
|
copyArrayContents(oldGeometry.attributes[key].array, geometry.attributes[key].array);
|
|
}
|
|
}
|
|
raycast(raycaster, intersects) {
|
|
const instanceInfo = this._instanceInfo;
|
|
const geometryInfoList = this._geometryInfo;
|
|
const matrixWorld = this.matrixWorld;
|
|
const batchGeometry = this.geometry;
|
|
_mesh.material = this.material;
|
|
_mesh.geometry.index = batchGeometry.index;
|
|
_mesh.geometry.attributes = batchGeometry.attributes;
|
|
if (_mesh.geometry.boundingBox === null) {
|
|
_mesh.geometry.boundingBox = new Box3;
|
|
}
|
|
if (_mesh.geometry.boundingSphere === null) {
|
|
_mesh.geometry.boundingSphere = new Sphere;
|
|
}
|
|
for (let i = 0, l = instanceInfo.length;i < l; i++) {
|
|
if (!instanceInfo[i].visible || !instanceInfo[i].active) {
|
|
continue;
|
|
}
|
|
const geometryId = instanceInfo[i].geometryIndex;
|
|
const geometryInfo = geometryInfoList[geometryId];
|
|
_mesh.geometry.setDrawRange(geometryInfo.start, geometryInfo.count);
|
|
this.getMatrixAt(i, _mesh.matrixWorld).premultiply(matrixWorld);
|
|
this.getBoundingBoxAt(geometryId, _mesh.geometry.boundingBox);
|
|
this.getBoundingSphereAt(geometryId, _mesh.geometry.boundingSphere);
|
|
_mesh.raycast(raycaster, _batchIntersects);
|
|
for (let j = 0, l2 = _batchIntersects.length;j < l2; j++) {
|
|
const intersect = _batchIntersects[j];
|
|
intersect.object = this;
|
|
intersect.batchId = i;
|
|
intersects.push(intersect);
|
|
}
|
|
_batchIntersects.length = 0;
|
|
}
|
|
_mesh.material = null;
|
|
_mesh.geometry.index = null;
|
|
_mesh.geometry.attributes = {};
|
|
_mesh.geometry.setDrawRange(0, Infinity);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.geometry = source.geometry.clone();
|
|
this.perObjectFrustumCulled = source.perObjectFrustumCulled;
|
|
this.sortObjects = source.sortObjects;
|
|
this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null;
|
|
this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null;
|
|
this._geometryInfo = source._geometryInfo.map((info) => ({
|
|
...info,
|
|
boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null,
|
|
boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null
|
|
}));
|
|
this._instanceInfo = source._instanceInfo.map((info) => ({ ...info }));
|
|
this._maxInstanceCount = source._maxInstanceCount;
|
|
this._maxVertexCount = source._maxVertexCount;
|
|
this._maxIndexCount = source._maxIndexCount;
|
|
this._geometryInitialized = source._geometryInitialized;
|
|
this._geometryCount = source._geometryCount;
|
|
this._multiDrawCounts = source._multiDrawCounts.slice();
|
|
this._multiDrawStarts = source._multiDrawStarts.slice();
|
|
this._matricesTexture = source._matricesTexture.clone();
|
|
this._matricesTexture.image.data = this._matricesTexture.image.data.slice();
|
|
if (this._colorsTexture !== null) {
|
|
this._colorsTexture = source._colorsTexture.clone();
|
|
this._colorsTexture.image.data = this._colorsTexture.image.data.slice();
|
|
}
|
|
return this;
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this._matricesTexture.dispose();
|
|
this._matricesTexture = null;
|
|
this._indirectTexture.dispose();
|
|
this._indirectTexture = null;
|
|
if (this._colorsTexture !== null) {
|
|
this._colorsTexture.dispose();
|
|
this._colorsTexture = null;
|
|
}
|
|
return this;
|
|
}
|
|
onBeforeRender(renderer, scene, camera, geometry, material) {
|
|
if (!this._visibilityChanged && !this.perObjectFrustumCulled && !this.sortObjects) {
|
|
return;
|
|
}
|
|
const index = geometry.getIndex();
|
|
const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;
|
|
const instanceInfo = this._instanceInfo;
|
|
const multiDrawStarts = this._multiDrawStarts;
|
|
const multiDrawCounts = this._multiDrawCounts;
|
|
const geometryInfoList = this._geometryInfo;
|
|
const perObjectFrustumCulled = this.perObjectFrustumCulled;
|
|
const indirectTexture = this._indirectTexture;
|
|
const indirectArray = indirectTexture.image.data;
|
|
if (perObjectFrustumCulled) {
|
|
_matrix$1.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse).multiply(this.matrixWorld);
|
|
_frustum.setFromProjectionMatrix(_matrix$1, renderer.coordinateSystem);
|
|
}
|
|
let multiDrawCount = 0;
|
|
if (this.sortObjects) {
|
|
_matrix$1.copy(this.matrixWorld).invert();
|
|
_vector$5.setFromMatrixPosition(camera.matrixWorld).applyMatrix4(_matrix$1);
|
|
_forward.set(0, 0, -1).transformDirection(camera.matrixWorld).transformDirection(_matrix$1);
|
|
for (let i = 0, l = instanceInfo.length;i < l; i++) {
|
|
if (instanceInfo[i].visible && instanceInfo[i].active) {
|
|
const geometryId = instanceInfo[i].geometryIndex;
|
|
this.getMatrixAt(i, _matrix$1);
|
|
this.getBoundingSphereAt(geometryId, _sphere$2).applyMatrix4(_matrix$1);
|
|
let culled = false;
|
|
if (perObjectFrustumCulled) {
|
|
culled = !_frustum.intersectsSphere(_sphere$2);
|
|
}
|
|
if (!culled) {
|
|
const geometryInfo = geometryInfoList[geometryId];
|
|
const z = _temp.subVectors(_sphere$2.center, _vector$5).dot(_forward);
|
|
_renderList.push(geometryInfo.start, geometryInfo.count, z, i);
|
|
}
|
|
}
|
|
}
|
|
const list = _renderList.list;
|
|
const customSort = this.customSort;
|
|
if (customSort === null) {
|
|
list.sort(material.transparent ? sortTransparent : sortOpaque);
|
|
} else {
|
|
customSort.call(this, list, camera);
|
|
}
|
|
for (let i = 0, l = list.length;i < l; i++) {
|
|
const item = list[i];
|
|
multiDrawStarts[multiDrawCount] = item.start * bytesPerElement;
|
|
multiDrawCounts[multiDrawCount] = item.count;
|
|
indirectArray[multiDrawCount] = item.index;
|
|
multiDrawCount++;
|
|
}
|
|
_renderList.reset();
|
|
} else {
|
|
for (let i = 0, l = instanceInfo.length;i < l; i++) {
|
|
if (instanceInfo[i].visible && instanceInfo[i].active) {
|
|
const geometryId = instanceInfo[i].geometryIndex;
|
|
let culled = false;
|
|
if (perObjectFrustumCulled) {
|
|
this.getMatrixAt(i, _matrix$1);
|
|
this.getBoundingSphereAt(geometryId, _sphere$2).applyMatrix4(_matrix$1);
|
|
culled = !_frustum.intersectsSphere(_sphere$2);
|
|
}
|
|
if (!culled) {
|
|
const geometryInfo = geometryInfoList[geometryId];
|
|
multiDrawStarts[multiDrawCount] = geometryInfo.start * bytesPerElement;
|
|
multiDrawCounts[multiDrawCount] = geometryInfo.count;
|
|
indirectArray[multiDrawCount] = i;
|
|
multiDrawCount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
indirectTexture.needsUpdate = true;
|
|
this._multiDrawCount = multiDrawCount;
|
|
this._visibilityChanged = false;
|
|
}
|
|
onBeforeShadow(renderer, object, camera, shadowCamera, geometry, depthMaterial) {
|
|
this.onBeforeRender(renderer, null, shadowCamera, geometry, depthMaterial);
|
|
}
|
|
};
|
|
LineBasicMaterial = class LineBasicMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isLineBasicMaterial = true;
|
|
this.type = "LineBasicMaterial";
|
|
this.color = new Color(16777215);
|
|
this.map = null;
|
|
this.linewidth = 1;
|
|
this.linecap = "round";
|
|
this.linejoin = "round";
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.color.copy(source.color);
|
|
this.map = source.map;
|
|
this.linewidth = source.linewidth;
|
|
this.linecap = source.linecap;
|
|
this.linejoin = source.linejoin;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
_vStart = /* @__PURE__ */ new Vector3;
|
|
_vEnd = /* @__PURE__ */ new Vector3;
|
|
_inverseMatrix$1 = /* @__PURE__ */ new Matrix4;
|
|
_ray$1 = /* @__PURE__ */ new Ray;
|
|
_sphere$1 = /* @__PURE__ */ new Sphere;
|
|
_intersectPointOnRay = /* @__PURE__ */ new Vector3;
|
|
_intersectPointOnSegment = /* @__PURE__ */ new Vector3;
|
|
Line = class Line extends Object3D {
|
|
constructor(geometry = new BufferGeometry, material = new LineBasicMaterial) {
|
|
super();
|
|
this.isLine = true;
|
|
this.type = "Line";
|
|
this.geometry = geometry;
|
|
this.material = material;
|
|
this.updateMorphTargets();
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.material = Array.isArray(source.material) ? source.material.slice() : source.material;
|
|
this.geometry = source.geometry;
|
|
return this;
|
|
}
|
|
computeLineDistances() {
|
|
const geometry = this.geometry;
|
|
if (geometry.index === null) {
|
|
const positionAttribute = geometry.attributes.position;
|
|
const lineDistances = [0];
|
|
for (let i = 1, l = positionAttribute.count;i < l; i++) {
|
|
_vStart.fromBufferAttribute(positionAttribute, i - 1);
|
|
_vEnd.fromBufferAttribute(positionAttribute, i);
|
|
lineDistances[i] = lineDistances[i - 1];
|
|
lineDistances[i] += _vStart.distanceTo(_vEnd);
|
|
}
|
|
geometry.setAttribute("lineDistance", new Float32BufferAttribute(lineDistances, 1));
|
|
} else {
|
|
console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");
|
|
}
|
|
return this;
|
|
}
|
|
raycast(raycaster, intersects) {
|
|
const geometry = this.geometry;
|
|
const matrixWorld = this.matrixWorld;
|
|
const threshold = raycaster.params.Line.threshold;
|
|
const drawRange = geometry.drawRange;
|
|
if (geometry.boundingSphere === null)
|
|
geometry.computeBoundingSphere();
|
|
_sphere$1.copy(geometry.boundingSphere);
|
|
_sphere$1.applyMatrix4(matrixWorld);
|
|
_sphere$1.radius += threshold;
|
|
if (raycaster.ray.intersectsSphere(_sphere$1) === false)
|
|
return;
|
|
_inverseMatrix$1.copy(matrixWorld).invert();
|
|
_ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
|
|
const localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
|
|
const localThresholdSq = localThreshold * localThreshold;
|
|
const step = this.isLineSegments ? 2 : 1;
|
|
const index = geometry.index;
|
|
const attributes = geometry.attributes;
|
|
const positionAttribute = attributes.position;
|
|
if (index !== null) {
|
|
const start = Math.max(0, drawRange.start);
|
|
const end = Math.min(index.count, drawRange.start + drawRange.count);
|
|
for (let i = start, l = end - 1;i < l; i += step) {
|
|
const a = index.getX(i);
|
|
const b = index.getX(i + 1);
|
|
const intersect = checkIntersection(this, raycaster, _ray$1, localThresholdSq, a, b, i);
|
|
if (intersect) {
|
|
intersects.push(intersect);
|
|
}
|
|
}
|
|
if (this.isLineLoop) {
|
|
const a = index.getX(end - 1);
|
|
const b = index.getX(start);
|
|
const intersect = checkIntersection(this, raycaster, _ray$1, localThresholdSq, a, b, end - 1);
|
|
if (intersect) {
|
|
intersects.push(intersect);
|
|
}
|
|
}
|
|
} else {
|
|
const start = Math.max(0, drawRange.start);
|
|
const end = Math.min(positionAttribute.count, drawRange.start + drawRange.count);
|
|
for (let i = start, l = end - 1;i < l; i += step) {
|
|
const intersect = checkIntersection(this, raycaster, _ray$1, localThresholdSq, i, i + 1, i);
|
|
if (intersect) {
|
|
intersects.push(intersect);
|
|
}
|
|
}
|
|
if (this.isLineLoop) {
|
|
const intersect = checkIntersection(this, raycaster, _ray$1, localThresholdSq, end - 1, start, end - 1);
|
|
if (intersect) {
|
|
intersects.push(intersect);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
updateMorphTargets() {
|
|
const geometry = this.geometry;
|
|
const morphAttributes = geometry.morphAttributes;
|
|
const keys = Object.keys(morphAttributes);
|
|
if (keys.length > 0) {
|
|
const morphAttribute = morphAttributes[keys[0]];
|
|
if (morphAttribute !== undefined) {
|
|
this.morphTargetInfluences = [];
|
|
this.morphTargetDictionary = {};
|
|
for (let m = 0, ml = morphAttribute.length;m < ml; m++) {
|
|
const name = morphAttribute[m].name || String(m);
|
|
this.morphTargetInfluences.push(0);
|
|
this.morphTargetDictionary[name] = m;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
_start = /* @__PURE__ */ new Vector3;
|
|
_end = /* @__PURE__ */ new Vector3;
|
|
LineSegments = class LineSegments extends Line {
|
|
constructor(geometry, material) {
|
|
super(geometry, material);
|
|
this.isLineSegments = true;
|
|
this.type = "LineSegments";
|
|
}
|
|
computeLineDistances() {
|
|
const geometry = this.geometry;
|
|
if (geometry.index === null) {
|
|
const positionAttribute = geometry.attributes.position;
|
|
const lineDistances = [];
|
|
for (let i = 0, l = positionAttribute.count;i < l; i += 2) {
|
|
_start.fromBufferAttribute(positionAttribute, i);
|
|
_end.fromBufferAttribute(positionAttribute, i + 1);
|
|
lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
|
|
lineDistances[i + 1] = lineDistances[i] + _start.distanceTo(_end);
|
|
}
|
|
geometry.setAttribute("lineDistance", new Float32BufferAttribute(lineDistances, 1));
|
|
} else {
|
|
console.warn("THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
LineLoop = class LineLoop extends Line {
|
|
constructor(geometry, material) {
|
|
super(geometry, material);
|
|
this.isLineLoop = true;
|
|
this.type = "LineLoop";
|
|
}
|
|
};
|
|
PointsMaterial = class PointsMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isPointsMaterial = true;
|
|
this.type = "PointsMaterial";
|
|
this.color = new Color(16777215);
|
|
this.map = null;
|
|
this.alphaMap = null;
|
|
this.size = 1;
|
|
this.sizeAttenuation = true;
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.color.copy(source.color);
|
|
this.map = source.map;
|
|
this.alphaMap = source.alphaMap;
|
|
this.size = source.size;
|
|
this.sizeAttenuation = source.sizeAttenuation;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
_inverseMatrix = /* @__PURE__ */ new Matrix4;
|
|
_ray = /* @__PURE__ */ new Ray;
|
|
_sphere = /* @__PURE__ */ new Sphere;
|
|
_position$2 = /* @__PURE__ */ new Vector3;
|
|
Points = class Points extends Object3D {
|
|
constructor(geometry = new BufferGeometry, material = new PointsMaterial) {
|
|
super();
|
|
this.isPoints = true;
|
|
this.type = "Points";
|
|
this.geometry = geometry;
|
|
this.material = material;
|
|
this.updateMorphTargets();
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.material = Array.isArray(source.material) ? source.material.slice() : source.material;
|
|
this.geometry = source.geometry;
|
|
return this;
|
|
}
|
|
raycast(raycaster, intersects) {
|
|
const geometry = this.geometry;
|
|
const matrixWorld = this.matrixWorld;
|
|
const threshold = raycaster.params.Points.threshold;
|
|
const drawRange = geometry.drawRange;
|
|
if (geometry.boundingSphere === null)
|
|
geometry.computeBoundingSphere();
|
|
_sphere.copy(geometry.boundingSphere);
|
|
_sphere.applyMatrix4(matrixWorld);
|
|
_sphere.radius += threshold;
|
|
if (raycaster.ray.intersectsSphere(_sphere) === false)
|
|
return;
|
|
_inverseMatrix.copy(matrixWorld).invert();
|
|
_ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix);
|
|
const localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
|
|
const localThresholdSq = localThreshold * localThreshold;
|
|
const index = geometry.index;
|
|
const attributes = geometry.attributes;
|
|
const positionAttribute = attributes.position;
|
|
if (index !== null) {
|
|
const start = Math.max(0, drawRange.start);
|
|
const end = Math.min(index.count, drawRange.start + drawRange.count);
|
|
for (let i = start, il = end;i < il; i++) {
|
|
const a = index.getX(i);
|
|
_position$2.fromBufferAttribute(positionAttribute, a);
|
|
testPoint(_position$2, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
|
|
}
|
|
} else {
|
|
const start = Math.max(0, drawRange.start);
|
|
const end = Math.min(positionAttribute.count, drawRange.start + drawRange.count);
|
|
for (let i = start, l = end;i < l; i++) {
|
|
_position$2.fromBufferAttribute(positionAttribute, i);
|
|
testPoint(_position$2, i, localThresholdSq, matrixWorld, raycaster, intersects, this);
|
|
}
|
|
}
|
|
}
|
|
updateMorphTargets() {
|
|
const geometry = this.geometry;
|
|
const morphAttributes = geometry.morphAttributes;
|
|
const keys = Object.keys(morphAttributes);
|
|
if (keys.length > 0) {
|
|
const morphAttribute = morphAttributes[keys[0]];
|
|
if (morphAttribute !== undefined) {
|
|
this.morphTargetInfluences = [];
|
|
this.morphTargetDictionary = {};
|
|
for (let m = 0, ml = morphAttribute.length;m < ml; m++) {
|
|
const name = morphAttribute[m].name || String(m);
|
|
this.morphTargetInfluences.push(0);
|
|
this.morphTargetDictionary[name] = m;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
VideoTexture = class VideoTexture extends Texture {
|
|
constructor(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
|
|
super(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
|
|
this.isVideoTexture = true;
|
|
this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
|
|
this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
|
|
this.generateMipmaps = false;
|
|
const scope = this;
|
|
function updateVideo() {
|
|
scope.needsUpdate = true;
|
|
video.requestVideoFrameCallback(updateVideo);
|
|
}
|
|
if ("requestVideoFrameCallback" in video) {
|
|
video.requestVideoFrameCallback(updateVideo);
|
|
}
|
|
}
|
|
clone() {
|
|
return new this.constructor(this.image).copy(this);
|
|
}
|
|
update() {
|
|
const video = this.image;
|
|
const hasVideoFrameCallback = "requestVideoFrameCallback" in video;
|
|
if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
|
|
this.needsUpdate = true;
|
|
}
|
|
}
|
|
};
|
|
VideoFrameTexture = class VideoFrameTexture extends VideoTexture {
|
|
constructor(mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
|
|
super({}, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
|
|
this.isVideoFrameTexture = true;
|
|
}
|
|
update() {}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
setFrame(frame) {
|
|
this.image = frame;
|
|
this.needsUpdate = true;
|
|
}
|
|
};
|
|
FramebufferTexture = class FramebufferTexture extends Texture {
|
|
constructor(width, height) {
|
|
super({ width, height });
|
|
this.isFramebufferTexture = true;
|
|
this.magFilter = NearestFilter;
|
|
this.minFilter = NearestFilter;
|
|
this.generateMipmaps = false;
|
|
this.needsUpdate = true;
|
|
}
|
|
};
|
|
CompressedTexture = class CompressedTexture extends Texture {
|
|
constructor(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace) {
|
|
super(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace);
|
|
this.isCompressedTexture = true;
|
|
this.image = { width, height };
|
|
this.mipmaps = mipmaps;
|
|
this.flipY = false;
|
|
this.generateMipmaps = false;
|
|
}
|
|
};
|
|
CompressedArrayTexture = class CompressedArrayTexture extends CompressedTexture {
|
|
constructor(mipmaps, width, height, depth, format, type) {
|
|
super(mipmaps, width, height, format, type);
|
|
this.isCompressedArrayTexture = true;
|
|
this.image.depth = depth;
|
|
this.wrapR = ClampToEdgeWrapping;
|
|
this.layerUpdates = new Set;
|
|
}
|
|
addLayerUpdate(layerIndex) {
|
|
this.layerUpdates.add(layerIndex);
|
|
}
|
|
clearLayerUpdates() {
|
|
this.layerUpdates.clear();
|
|
}
|
|
};
|
|
CompressedCubeTexture = class CompressedCubeTexture extends CompressedTexture {
|
|
constructor(images, format, type) {
|
|
super(undefined, images[0].width, images[0].height, format, type, CubeReflectionMapping);
|
|
this.isCompressedCubeTexture = true;
|
|
this.isCubeTexture = true;
|
|
this.image = images;
|
|
}
|
|
};
|
|
CanvasTexture = class CanvasTexture extends Texture {
|
|
constructor(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
|
|
super(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
|
|
this.isCanvasTexture = true;
|
|
this.needsUpdate = true;
|
|
}
|
|
};
|
|
DepthTexture = class DepthTexture extends Texture {
|
|
constructor(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat) {
|
|
if (format !== DepthFormat && format !== DepthStencilFormat) {
|
|
throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");
|
|
}
|
|
if (type === undefined && format === DepthFormat)
|
|
type = UnsignedIntType;
|
|
if (type === undefined && format === DepthStencilFormat)
|
|
type = UnsignedInt248Type;
|
|
super(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
|
|
this.isDepthTexture = true;
|
|
this.image = { width, height };
|
|
this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
|
|
this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
|
|
this.flipY = false;
|
|
this.generateMipmaps = false;
|
|
this.compareFunction = null;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.compareFunction = source.compareFunction;
|
|
return this;
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
if (this.compareFunction !== null)
|
|
data.compareFunction = this.compareFunction;
|
|
return data;
|
|
}
|
|
};
|
|
EllipseCurve = class EllipseCurve extends Curve {
|
|
constructor(aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0) {
|
|
super();
|
|
this.isEllipseCurve = true;
|
|
this.type = "EllipseCurve";
|
|
this.aX = aX;
|
|
this.aY = aY;
|
|
this.xRadius = xRadius;
|
|
this.yRadius = yRadius;
|
|
this.aStartAngle = aStartAngle;
|
|
this.aEndAngle = aEndAngle;
|
|
this.aClockwise = aClockwise;
|
|
this.aRotation = aRotation;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector2) {
|
|
const point = optionalTarget;
|
|
const twoPi = Math.PI * 2;
|
|
let deltaAngle = this.aEndAngle - this.aStartAngle;
|
|
const samePoints = Math.abs(deltaAngle) < Number.EPSILON;
|
|
while (deltaAngle < 0)
|
|
deltaAngle += twoPi;
|
|
while (deltaAngle > twoPi)
|
|
deltaAngle -= twoPi;
|
|
if (deltaAngle < Number.EPSILON) {
|
|
if (samePoints) {
|
|
deltaAngle = 0;
|
|
} else {
|
|
deltaAngle = twoPi;
|
|
}
|
|
}
|
|
if (this.aClockwise === true && !samePoints) {
|
|
if (deltaAngle === twoPi) {
|
|
deltaAngle = -twoPi;
|
|
} else {
|
|
deltaAngle = deltaAngle - twoPi;
|
|
}
|
|
}
|
|
const angle = this.aStartAngle + t * deltaAngle;
|
|
let x = this.aX + this.xRadius * Math.cos(angle);
|
|
let y = this.aY + this.yRadius * Math.sin(angle);
|
|
if (this.aRotation !== 0) {
|
|
const cos = Math.cos(this.aRotation);
|
|
const sin = Math.sin(this.aRotation);
|
|
const tx = x - this.aX;
|
|
const ty = y - this.aY;
|
|
x = tx * cos - ty * sin + this.aX;
|
|
y = tx * sin + ty * cos + this.aY;
|
|
}
|
|
return point.set(x, y);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.aX = source.aX;
|
|
this.aY = source.aY;
|
|
this.xRadius = source.xRadius;
|
|
this.yRadius = source.yRadius;
|
|
this.aStartAngle = source.aStartAngle;
|
|
this.aEndAngle = source.aEndAngle;
|
|
this.aClockwise = source.aClockwise;
|
|
this.aRotation = source.aRotation;
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.aX = this.aX;
|
|
data.aY = this.aY;
|
|
data.xRadius = this.xRadius;
|
|
data.yRadius = this.yRadius;
|
|
data.aStartAngle = this.aStartAngle;
|
|
data.aEndAngle = this.aEndAngle;
|
|
data.aClockwise = this.aClockwise;
|
|
data.aRotation = this.aRotation;
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.aX = json.aX;
|
|
this.aY = json.aY;
|
|
this.xRadius = json.xRadius;
|
|
this.yRadius = json.yRadius;
|
|
this.aStartAngle = json.aStartAngle;
|
|
this.aEndAngle = json.aEndAngle;
|
|
this.aClockwise = json.aClockwise;
|
|
this.aRotation = json.aRotation;
|
|
return this;
|
|
}
|
|
};
|
|
ArcCurve = class ArcCurve extends EllipseCurve {
|
|
constructor(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
|
|
super(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
|
|
this.isArcCurve = true;
|
|
this.type = "ArcCurve";
|
|
}
|
|
};
|
|
tmp = /* @__PURE__ */ new Vector3;
|
|
px = /* @__PURE__ */ new CubicPoly;
|
|
py = /* @__PURE__ */ new CubicPoly;
|
|
pz = /* @__PURE__ */ new CubicPoly;
|
|
CatmullRomCurve3 = class CatmullRomCurve3 extends Curve {
|
|
constructor(points = [], closed = false, curveType = "centripetal", tension = 0.5) {
|
|
super();
|
|
this.isCatmullRomCurve3 = true;
|
|
this.type = "CatmullRomCurve3";
|
|
this.points = points;
|
|
this.closed = closed;
|
|
this.curveType = curveType;
|
|
this.tension = tension;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector3) {
|
|
const point = optionalTarget;
|
|
const points = this.points;
|
|
const l = points.length;
|
|
const p = (l - (this.closed ? 0 : 1)) * t;
|
|
let intPoint = Math.floor(p);
|
|
let weight = p - intPoint;
|
|
if (this.closed) {
|
|
intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
|
|
} else if (weight === 0 && intPoint === l - 1) {
|
|
intPoint = l - 2;
|
|
weight = 1;
|
|
}
|
|
let p0, p3;
|
|
if (this.closed || intPoint > 0) {
|
|
p0 = points[(intPoint - 1) % l];
|
|
} else {
|
|
tmp.subVectors(points[0], points[1]).add(points[0]);
|
|
p0 = tmp;
|
|
}
|
|
const p1 = points[intPoint % l];
|
|
const p2 = points[(intPoint + 1) % l];
|
|
if (this.closed || intPoint + 2 < l) {
|
|
p3 = points[(intPoint + 2) % l];
|
|
} else {
|
|
tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
|
|
p3 = tmp;
|
|
}
|
|
if (this.curveType === "centripetal" || this.curveType === "chordal") {
|
|
const pow = this.curveType === "chordal" ? 0.5 : 0.25;
|
|
let dt0 = Math.pow(p0.distanceToSquared(p1), pow);
|
|
let dt1 = Math.pow(p1.distanceToSquared(p2), pow);
|
|
let dt2 = Math.pow(p2.distanceToSquared(p3), pow);
|
|
if (dt1 < 0.0001)
|
|
dt1 = 1;
|
|
if (dt0 < 0.0001)
|
|
dt0 = dt1;
|
|
if (dt2 < 0.0001)
|
|
dt2 = dt1;
|
|
px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
|
|
py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
|
|
pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
|
|
} else if (this.curveType === "catmullrom") {
|
|
px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
|
|
py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
|
|
pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
|
|
}
|
|
point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
|
|
return point;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.points = [];
|
|
for (let i = 0, l = source.points.length;i < l; i++) {
|
|
const point = source.points[i];
|
|
this.points.push(point.clone());
|
|
}
|
|
this.closed = source.closed;
|
|
this.curveType = source.curveType;
|
|
this.tension = source.tension;
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.points = [];
|
|
for (let i = 0, l = this.points.length;i < l; i++) {
|
|
const point = this.points[i];
|
|
data.points.push(point.toArray());
|
|
}
|
|
data.closed = this.closed;
|
|
data.curveType = this.curveType;
|
|
data.tension = this.tension;
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.points = [];
|
|
for (let i = 0, l = json.points.length;i < l; i++) {
|
|
const point = json.points[i];
|
|
this.points.push(new Vector3().fromArray(point));
|
|
}
|
|
this.closed = json.closed;
|
|
this.curveType = json.curveType;
|
|
this.tension = json.tension;
|
|
return this;
|
|
}
|
|
};
|
|
CubicBezierCurve = class CubicBezierCurve extends Curve {
|
|
constructor(v0 = new Vector2, v1 = new Vector2, v2 = new Vector2, v3 = new Vector2) {
|
|
super();
|
|
this.isCubicBezierCurve = true;
|
|
this.type = "CubicBezierCurve";
|
|
this.v0 = v0;
|
|
this.v1 = v1;
|
|
this.v2 = v2;
|
|
this.v3 = v3;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector2) {
|
|
const point = optionalTarget;
|
|
const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
|
|
point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
|
|
return point;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.v0.copy(source.v0);
|
|
this.v1.copy(source.v1);
|
|
this.v2.copy(source.v2);
|
|
this.v3.copy(source.v3);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.v0 = this.v0.toArray();
|
|
data.v1 = this.v1.toArray();
|
|
data.v2 = this.v2.toArray();
|
|
data.v3 = this.v3.toArray();
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.v0.fromArray(json.v0);
|
|
this.v1.fromArray(json.v1);
|
|
this.v2.fromArray(json.v2);
|
|
this.v3.fromArray(json.v3);
|
|
return this;
|
|
}
|
|
};
|
|
CubicBezierCurve3 = class CubicBezierCurve3 extends Curve {
|
|
constructor(v0 = new Vector3, v1 = new Vector3, v2 = new Vector3, v3 = new Vector3) {
|
|
super();
|
|
this.isCubicBezierCurve3 = true;
|
|
this.type = "CubicBezierCurve3";
|
|
this.v0 = v0;
|
|
this.v1 = v1;
|
|
this.v2 = v2;
|
|
this.v3 = v3;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector3) {
|
|
const point = optionalTarget;
|
|
const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
|
|
point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y), CubicBezier(t, v0.z, v1.z, v2.z, v3.z));
|
|
return point;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.v0.copy(source.v0);
|
|
this.v1.copy(source.v1);
|
|
this.v2.copy(source.v2);
|
|
this.v3.copy(source.v3);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.v0 = this.v0.toArray();
|
|
data.v1 = this.v1.toArray();
|
|
data.v2 = this.v2.toArray();
|
|
data.v3 = this.v3.toArray();
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.v0.fromArray(json.v0);
|
|
this.v1.fromArray(json.v1);
|
|
this.v2.fromArray(json.v2);
|
|
this.v3.fromArray(json.v3);
|
|
return this;
|
|
}
|
|
};
|
|
LineCurve = class LineCurve extends Curve {
|
|
constructor(v1 = new Vector2, v2 = new Vector2) {
|
|
super();
|
|
this.isLineCurve = true;
|
|
this.type = "LineCurve";
|
|
this.v1 = v1;
|
|
this.v2 = v2;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector2) {
|
|
const point = optionalTarget;
|
|
if (t === 1) {
|
|
point.copy(this.v2);
|
|
} else {
|
|
point.copy(this.v2).sub(this.v1);
|
|
point.multiplyScalar(t).add(this.v1);
|
|
}
|
|
return point;
|
|
}
|
|
getPointAt(u, optionalTarget) {
|
|
return this.getPoint(u, optionalTarget);
|
|
}
|
|
getTangent(t, optionalTarget = new Vector2) {
|
|
return optionalTarget.subVectors(this.v2, this.v1).normalize();
|
|
}
|
|
getTangentAt(u, optionalTarget) {
|
|
return this.getTangent(u, optionalTarget);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.v1.copy(source.v1);
|
|
this.v2.copy(source.v2);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.v1 = this.v1.toArray();
|
|
data.v2 = this.v2.toArray();
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.v1.fromArray(json.v1);
|
|
this.v2.fromArray(json.v2);
|
|
return this;
|
|
}
|
|
};
|
|
LineCurve3 = class LineCurve3 extends Curve {
|
|
constructor(v1 = new Vector3, v2 = new Vector3) {
|
|
super();
|
|
this.isLineCurve3 = true;
|
|
this.type = "LineCurve3";
|
|
this.v1 = v1;
|
|
this.v2 = v2;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector3) {
|
|
const point = optionalTarget;
|
|
if (t === 1) {
|
|
point.copy(this.v2);
|
|
} else {
|
|
point.copy(this.v2).sub(this.v1);
|
|
point.multiplyScalar(t).add(this.v1);
|
|
}
|
|
return point;
|
|
}
|
|
getPointAt(u, optionalTarget) {
|
|
return this.getPoint(u, optionalTarget);
|
|
}
|
|
getTangent(t, optionalTarget = new Vector3) {
|
|
return optionalTarget.subVectors(this.v2, this.v1).normalize();
|
|
}
|
|
getTangentAt(u, optionalTarget) {
|
|
return this.getTangent(u, optionalTarget);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.v1.copy(source.v1);
|
|
this.v2.copy(source.v2);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.v1 = this.v1.toArray();
|
|
data.v2 = this.v2.toArray();
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.v1.fromArray(json.v1);
|
|
this.v2.fromArray(json.v2);
|
|
return this;
|
|
}
|
|
};
|
|
QuadraticBezierCurve = class QuadraticBezierCurve extends Curve {
|
|
constructor(v0 = new Vector2, v1 = new Vector2, v2 = new Vector2) {
|
|
super();
|
|
this.isQuadraticBezierCurve = true;
|
|
this.type = "QuadraticBezierCurve";
|
|
this.v0 = v0;
|
|
this.v1 = v1;
|
|
this.v2 = v2;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector2) {
|
|
const point = optionalTarget;
|
|
const v0 = this.v0, v1 = this.v1, v2 = this.v2;
|
|
point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
|
|
return point;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.v0.copy(source.v0);
|
|
this.v1.copy(source.v1);
|
|
this.v2.copy(source.v2);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.v0 = this.v0.toArray();
|
|
data.v1 = this.v1.toArray();
|
|
data.v2 = this.v2.toArray();
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.v0.fromArray(json.v0);
|
|
this.v1.fromArray(json.v1);
|
|
this.v2.fromArray(json.v2);
|
|
return this;
|
|
}
|
|
};
|
|
QuadraticBezierCurve3 = class QuadraticBezierCurve3 extends Curve {
|
|
constructor(v0 = new Vector3, v1 = new Vector3, v2 = new Vector3) {
|
|
super();
|
|
this.isQuadraticBezierCurve3 = true;
|
|
this.type = "QuadraticBezierCurve3";
|
|
this.v0 = v0;
|
|
this.v1 = v1;
|
|
this.v2 = v2;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector3) {
|
|
const point = optionalTarget;
|
|
const v0 = this.v0, v1 = this.v1, v2 = this.v2;
|
|
point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y), QuadraticBezier(t, v0.z, v1.z, v2.z));
|
|
return point;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.v0.copy(source.v0);
|
|
this.v1.copy(source.v1);
|
|
this.v2.copy(source.v2);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.v0 = this.v0.toArray();
|
|
data.v1 = this.v1.toArray();
|
|
data.v2 = this.v2.toArray();
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.v0.fromArray(json.v0);
|
|
this.v1.fromArray(json.v1);
|
|
this.v2.fromArray(json.v2);
|
|
return this;
|
|
}
|
|
};
|
|
SplineCurve = class SplineCurve extends Curve {
|
|
constructor(points = []) {
|
|
super();
|
|
this.isSplineCurve = true;
|
|
this.type = "SplineCurve";
|
|
this.points = points;
|
|
}
|
|
getPoint(t, optionalTarget = new Vector2) {
|
|
const point = optionalTarget;
|
|
const points = this.points;
|
|
const p = (points.length - 1) * t;
|
|
const intPoint = Math.floor(p);
|
|
const weight = p - intPoint;
|
|
const p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
|
|
const p1 = points[intPoint];
|
|
const p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
|
|
const p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
|
|
point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
|
|
return point;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.points = [];
|
|
for (let i = 0, l = source.points.length;i < l; i++) {
|
|
const point = source.points[i];
|
|
this.points.push(point.clone());
|
|
}
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.points = [];
|
|
for (let i = 0, l = this.points.length;i < l; i++) {
|
|
const point = this.points[i];
|
|
data.points.push(point.toArray());
|
|
}
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.points = [];
|
|
for (let i = 0, l = json.points.length;i < l; i++) {
|
|
const point = json.points[i];
|
|
this.points.push(new Vector2().fromArray(point));
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
Curves = /* @__PURE__ */ Object.freeze({
|
|
__proto__: null,
|
|
ArcCurve,
|
|
CatmullRomCurve3,
|
|
CubicBezierCurve,
|
|
CubicBezierCurve3,
|
|
EllipseCurve,
|
|
LineCurve,
|
|
LineCurve3,
|
|
QuadraticBezierCurve,
|
|
QuadraticBezierCurve3,
|
|
SplineCurve
|
|
});
|
|
CurvePath = class CurvePath extends Curve {
|
|
constructor() {
|
|
super();
|
|
this.type = "CurvePath";
|
|
this.curves = [];
|
|
this.autoClose = false;
|
|
}
|
|
add(curve) {
|
|
this.curves.push(curve);
|
|
}
|
|
closePath() {
|
|
const startPoint = this.curves[0].getPoint(0);
|
|
const endPoint = this.curves[this.curves.length - 1].getPoint(1);
|
|
if (!startPoint.equals(endPoint)) {
|
|
const lineType = startPoint.isVector2 === true ? "LineCurve" : "LineCurve3";
|
|
this.curves.push(new Curves[lineType](endPoint, startPoint));
|
|
}
|
|
return this;
|
|
}
|
|
getPoint(t, optionalTarget) {
|
|
const d = t * this.getLength();
|
|
const curveLengths = this.getCurveLengths();
|
|
let i = 0;
|
|
while (i < curveLengths.length) {
|
|
if (curveLengths[i] >= d) {
|
|
const diff = curveLengths[i] - d;
|
|
const curve = this.curves[i];
|
|
const segmentLength = curve.getLength();
|
|
const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
|
|
return curve.getPointAt(u, optionalTarget);
|
|
}
|
|
i++;
|
|
}
|
|
return null;
|
|
}
|
|
getLength() {
|
|
const lens = this.getCurveLengths();
|
|
return lens[lens.length - 1];
|
|
}
|
|
updateArcLengths() {
|
|
this.needsUpdate = true;
|
|
this.cacheLengths = null;
|
|
this.getCurveLengths();
|
|
}
|
|
getCurveLengths() {
|
|
if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
|
|
return this.cacheLengths;
|
|
}
|
|
const lengths = [];
|
|
let sums = 0;
|
|
for (let i = 0, l = this.curves.length;i < l; i++) {
|
|
sums += this.curves[i].getLength();
|
|
lengths.push(sums);
|
|
}
|
|
this.cacheLengths = lengths;
|
|
return lengths;
|
|
}
|
|
getSpacedPoints(divisions = 40) {
|
|
const points = [];
|
|
for (let i = 0;i <= divisions; i++) {
|
|
points.push(this.getPoint(i / divisions));
|
|
}
|
|
if (this.autoClose) {
|
|
points.push(points[0]);
|
|
}
|
|
return points;
|
|
}
|
|
getPoints(divisions = 12) {
|
|
const points = [];
|
|
let last;
|
|
for (let i = 0, curves = this.curves;i < curves.length; i++) {
|
|
const curve = curves[i];
|
|
const resolution = curve.isEllipseCurve ? divisions * 2 : curve.isLineCurve || curve.isLineCurve3 ? 1 : curve.isSplineCurve ? divisions * curve.points.length : divisions;
|
|
const pts = curve.getPoints(resolution);
|
|
for (let j = 0;j < pts.length; j++) {
|
|
const point = pts[j];
|
|
if (last && last.equals(point))
|
|
continue;
|
|
points.push(point);
|
|
last = point;
|
|
}
|
|
}
|
|
if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
|
|
points.push(points[0]);
|
|
}
|
|
return points;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.curves = [];
|
|
for (let i = 0, l = source.curves.length;i < l; i++) {
|
|
const curve = source.curves[i];
|
|
this.curves.push(curve.clone());
|
|
}
|
|
this.autoClose = source.autoClose;
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.autoClose = this.autoClose;
|
|
data.curves = [];
|
|
for (let i = 0, l = this.curves.length;i < l; i++) {
|
|
const curve = this.curves[i];
|
|
data.curves.push(curve.toJSON());
|
|
}
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.autoClose = json.autoClose;
|
|
this.curves = [];
|
|
for (let i = 0, l = json.curves.length;i < l; i++) {
|
|
const curve = json.curves[i];
|
|
this.curves.push(new Curves[curve.type]().fromJSON(curve));
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
Path = class Path extends CurvePath {
|
|
constructor(points) {
|
|
super();
|
|
this.type = "Path";
|
|
this.currentPoint = new Vector2;
|
|
if (points) {
|
|
this.setFromPoints(points);
|
|
}
|
|
}
|
|
setFromPoints(points) {
|
|
this.moveTo(points[0].x, points[0].y);
|
|
for (let i = 1, l = points.length;i < l; i++) {
|
|
this.lineTo(points[i].x, points[i].y);
|
|
}
|
|
return this;
|
|
}
|
|
moveTo(x, y) {
|
|
this.currentPoint.set(x, y);
|
|
return this;
|
|
}
|
|
lineTo(x, y) {
|
|
const curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
|
|
this.curves.push(curve);
|
|
this.currentPoint.set(x, y);
|
|
return this;
|
|
}
|
|
quadraticCurveTo(aCPx, aCPy, aX, aY) {
|
|
const curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
|
|
this.curves.push(curve);
|
|
this.currentPoint.set(aX, aY);
|
|
return this;
|
|
}
|
|
bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
|
|
const curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
|
|
this.curves.push(curve);
|
|
this.currentPoint.set(aX, aY);
|
|
return this;
|
|
}
|
|
splineThru(pts) {
|
|
const npts = [this.currentPoint.clone()].concat(pts);
|
|
const curve = new SplineCurve(npts);
|
|
this.curves.push(curve);
|
|
this.currentPoint.copy(pts[pts.length - 1]);
|
|
return this;
|
|
}
|
|
arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
|
|
const x0 = this.currentPoint.x;
|
|
const y0 = this.currentPoint.y;
|
|
this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
|
|
return this;
|
|
}
|
|
absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
|
|
this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
|
|
return this;
|
|
}
|
|
ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
|
|
const x0 = this.currentPoint.x;
|
|
const y0 = this.currentPoint.y;
|
|
this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
|
|
return this;
|
|
}
|
|
absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
|
|
const curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
|
|
if (this.curves.length > 0) {
|
|
const firstPoint = curve.getPoint(0);
|
|
if (!firstPoint.equals(this.currentPoint)) {
|
|
this.lineTo(firstPoint.x, firstPoint.y);
|
|
}
|
|
}
|
|
this.curves.push(curve);
|
|
const lastPoint = curve.getPoint(1);
|
|
this.currentPoint.copy(lastPoint);
|
|
return this;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.currentPoint.copy(source.currentPoint);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.currentPoint = this.currentPoint.toArray();
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.currentPoint.fromArray(json.currentPoint);
|
|
return this;
|
|
}
|
|
};
|
|
LatheGeometry = class LatheGeometry extends BufferGeometry {
|
|
constructor(points = [new Vector2(0, -0.5), new Vector2(0.5, 0), new Vector2(0, 0.5)], segments = 12, phiStart = 0, phiLength = Math.PI * 2) {
|
|
super();
|
|
this.type = "LatheGeometry";
|
|
this.parameters = {
|
|
points,
|
|
segments,
|
|
phiStart,
|
|
phiLength
|
|
};
|
|
segments = Math.floor(segments);
|
|
phiLength = clamp(phiLength, 0, Math.PI * 2);
|
|
const indices = [];
|
|
const vertices = [];
|
|
const uvs = [];
|
|
const initNormals = [];
|
|
const normals = [];
|
|
const inverseSegments = 1 / segments;
|
|
const vertex = new Vector3;
|
|
const uv = new Vector2;
|
|
const normal = new Vector3;
|
|
const curNormal = new Vector3;
|
|
const prevNormal = new Vector3;
|
|
let dx = 0;
|
|
let dy = 0;
|
|
for (let j = 0;j <= points.length - 1; j++) {
|
|
switch (j) {
|
|
case 0:
|
|
dx = points[j + 1].x - points[j].x;
|
|
dy = points[j + 1].y - points[j].y;
|
|
normal.x = dy * 1;
|
|
normal.y = -dx;
|
|
normal.z = dy * 0;
|
|
prevNormal.copy(normal);
|
|
normal.normalize();
|
|
initNormals.push(normal.x, normal.y, normal.z);
|
|
break;
|
|
case points.length - 1:
|
|
initNormals.push(prevNormal.x, prevNormal.y, prevNormal.z);
|
|
break;
|
|
default:
|
|
dx = points[j + 1].x - points[j].x;
|
|
dy = points[j + 1].y - points[j].y;
|
|
normal.x = dy * 1;
|
|
normal.y = -dx;
|
|
normal.z = dy * 0;
|
|
curNormal.copy(normal);
|
|
normal.x += prevNormal.x;
|
|
normal.y += prevNormal.y;
|
|
normal.z += prevNormal.z;
|
|
normal.normalize();
|
|
initNormals.push(normal.x, normal.y, normal.z);
|
|
prevNormal.copy(curNormal);
|
|
}
|
|
}
|
|
for (let i = 0;i <= segments; i++) {
|
|
const phi = phiStart + i * inverseSegments * phiLength;
|
|
const sin = Math.sin(phi);
|
|
const cos = Math.cos(phi);
|
|
for (let j = 0;j <= points.length - 1; j++) {
|
|
vertex.x = points[j].x * sin;
|
|
vertex.y = points[j].y;
|
|
vertex.z = points[j].x * cos;
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
uv.x = i / segments;
|
|
uv.y = j / (points.length - 1);
|
|
uvs.push(uv.x, uv.y);
|
|
const x = initNormals[3 * j + 0] * sin;
|
|
const y = initNormals[3 * j + 1];
|
|
const z = initNormals[3 * j + 0] * cos;
|
|
normals.push(x, y, z);
|
|
}
|
|
}
|
|
for (let i = 0;i < segments; i++) {
|
|
for (let j = 0;j < points.length - 1; j++) {
|
|
const base = j + i * points.length;
|
|
const a = base;
|
|
const b = base + points.length;
|
|
const c = base + points.length + 1;
|
|
const d = base + 1;
|
|
indices.push(a, b, d);
|
|
indices.push(c, d, b);
|
|
}
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new LatheGeometry(data.points, data.segments, data.phiStart, data.phiLength);
|
|
}
|
|
};
|
|
CapsuleGeometry = class CapsuleGeometry extends LatheGeometry {
|
|
constructor(radius = 1, length = 1, capSegments = 4, radialSegments = 8) {
|
|
const path = new Path;
|
|
path.absarc(0, -length / 2, radius, Math.PI * 1.5, 0);
|
|
path.absarc(0, length / 2, radius, 0, Math.PI * 0.5);
|
|
super(path.getPoints(capSegments), radialSegments);
|
|
this.type = "CapsuleGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
length,
|
|
capSegments,
|
|
radialSegments
|
|
};
|
|
}
|
|
static fromJSON(data) {
|
|
return new CapsuleGeometry(data.radius, data.length, data.capSegments, data.radialSegments);
|
|
}
|
|
};
|
|
CircleGeometry = class CircleGeometry extends BufferGeometry {
|
|
constructor(radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2) {
|
|
super();
|
|
this.type = "CircleGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
segments,
|
|
thetaStart,
|
|
thetaLength
|
|
};
|
|
segments = Math.max(3, segments);
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
const vertex = new Vector3;
|
|
const uv = new Vector2;
|
|
vertices.push(0, 0, 0);
|
|
normals.push(0, 0, 1);
|
|
uvs.push(0.5, 0.5);
|
|
for (let s = 0, i = 3;s <= segments; s++, i += 3) {
|
|
const segment = thetaStart + s / segments * thetaLength;
|
|
vertex.x = radius * Math.cos(segment);
|
|
vertex.y = radius * Math.sin(segment);
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
normals.push(0, 0, 1);
|
|
uv.x = (vertices[i] / radius + 1) / 2;
|
|
uv.y = (vertices[i + 1] / radius + 1) / 2;
|
|
uvs.push(uv.x, uv.y);
|
|
}
|
|
for (let i = 1;i <= segments; i++) {
|
|
indices.push(i, i + 1, 0);
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new CircleGeometry(data.radius, data.segments, data.thetaStart, data.thetaLength);
|
|
}
|
|
};
|
|
CylinderGeometry = class CylinderGeometry extends BufferGeometry {
|
|
constructor(radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2) {
|
|
super();
|
|
this.type = "CylinderGeometry";
|
|
this.parameters = {
|
|
radiusTop,
|
|
radiusBottom,
|
|
height,
|
|
radialSegments,
|
|
heightSegments,
|
|
openEnded,
|
|
thetaStart,
|
|
thetaLength
|
|
};
|
|
const scope = this;
|
|
radialSegments = Math.floor(radialSegments);
|
|
heightSegments = Math.floor(heightSegments);
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
let index = 0;
|
|
const indexArray = [];
|
|
const halfHeight = height / 2;
|
|
let groupStart = 0;
|
|
generateTorso();
|
|
if (openEnded === false) {
|
|
if (radiusTop > 0)
|
|
generateCap(true);
|
|
if (radiusBottom > 0)
|
|
generateCap(false);
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
function generateTorso() {
|
|
const normal = new Vector3;
|
|
const vertex = new Vector3;
|
|
let groupCount = 0;
|
|
const slope = (radiusBottom - radiusTop) / height;
|
|
for (let y = 0;y <= heightSegments; y++) {
|
|
const indexRow = [];
|
|
const v = y / heightSegments;
|
|
const radius = v * (radiusBottom - radiusTop) + radiusTop;
|
|
for (let x = 0;x <= radialSegments; x++) {
|
|
const u = x / radialSegments;
|
|
const theta = u * thetaLength + thetaStart;
|
|
const sinTheta = Math.sin(theta);
|
|
const cosTheta = Math.cos(theta);
|
|
vertex.x = radius * sinTheta;
|
|
vertex.y = -v * height + halfHeight;
|
|
vertex.z = radius * cosTheta;
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
normal.set(sinTheta, slope, cosTheta).normalize();
|
|
normals.push(normal.x, normal.y, normal.z);
|
|
uvs.push(u, 1 - v);
|
|
indexRow.push(index++);
|
|
}
|
|
indexArray.push(indexRow);
|
|
}
|
|
for (let x = 0;x < radialSegments; x++) {
|
|
for (let y = 0;y < heightSegments; y++) {
|
|
const a = indexArray[y][x];
|
|
const b = indexArray[y + 1][x];
|
|
const c = indexArray[y + 1][x + 1];
|
|
const d = indexArray[y][x + 1];
|
|
if (radiusTop > 0 || y !== 0) {
|
|
indices.push(a, b, d);
|
|
groupCount += 3;
|
|
}
|
|
if (radiusBottom > 0 || y !== heightSegments - 1) {
|
|
indices.push(b, c, d);
|
|
groupCount += 3;
|
|
}
|
|
}
|
|
}
|
|
scope.addGroup(groupStart, groupCount, 0);
|
|
groupStart += groupCount;
|
|
}
|
|
function generateCap(top) {
|
|
const centerIndexStart = index;
|
|
const uv = new Vector2;
|
|
const vertex = new Vector3;
|
|
let groupCount = 0;
|
|
const radius = top === true ? radiusTop : radiusBottom;
|
|
const sign = top === true ? 1 : -1;
|
|
for (let x = 1;x <= radialSegments; x++) {
|
|
vertices.push(0, halfHeight * sign, 0);
|
|
normals.push(0, sign, 0);
|
|
uvs.push(0.5, 0.5);
|
|
index++;
|
|
}
|
|
const centerIndexEnd = index;
|
|
for (let x = 0;x <= radialSegments; x++) {
|
|
const u = x / radialSegments;
|
|
const theta = u * thetaLength + thetaStart;
|
|
const cosTheta = Math.cos(theta);
|
|
const sinTheta = Math.sin(theta);
|
|
vertex.x = radius * sinTheta;
|
|
vertex.y = halfHeight * sign;
|
|
vertex.z = radius * cosTheta;
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
normals.push(0, sign, 0);
|
|
uv.x = cosTheta * 0.5 + 0.5;
|
|
uv.y = sinTheta * 0.5 * sign + 0.5;
|
|
uvs.push(uv.x, uv.y);
|
|
index++;
|
|
}
|
|
for (let x = 0;x < radialSegments; x++) {
|
|
const c = centerIndexStart + x;
|
|
const i = centerIndexEnd + x;
|
|
if (top === true) {
|
|
indices.push(i, i + 1, c);
|
|
} else {
|
|
indices.push(i + 1, i, c);
|
|
}
|
|
groupCount += 3;
|
|
}
|
|
scope.addGroup(groupStart, groupCount, top === true ? 1 : 2);
|
|
groupStart += groupCount;
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new CylinderGeometry(data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
|
|
}
|
|
};
|
|
ConeGeometry = class ConeGeometry extends CylinderGeometry {
|
|
constructor(radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2) {
|
|
super(0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength);
|
|
this.type = "ConeGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
height,
|
|
radialSegments,
|
|
heightSegments,
|
|
openEnded,
|
|
thetaStart,
|
|
thetaLength
|
|
};
|
|
}
|
|
static fromJSON(data) {
|
|
return new ConeGeometry(data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
|
|
}
|
|
};
|
|
PolyhedronGeometry = class PolyhedronGeometry extends BufferGeometry {
|
|
constructor(vertices = [], indices = [], radius = 1, detail = 0) {
|
|
super();
|
|
this.type = "PolyhedronGeometry";
|
|
this.parameters = {
|
|
vertices,
|
|
indices,
|
|
radius,
|
|
detail
|
|
};
|
|
const vertexBuffer = [];
|
|
const uvBuffer = [];
|
|
subdivide(detail);
|
|
applyRadius(radius);
|
|
generateUVs();
|
|
this.setAttribute("position", new Float32BufferAttribute(vertexBuffer, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(vertexBuffer.slice(), 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvBuffer, 2));
|
|
if (detail === 0) {
|
|
this.computeVertexNormals();
|
|
} else {
|
|
this.normalizeNormals();
|
|
}
|
|
function subdivide(detail2) {
|
|
const a = new Vector3;
|
|
const b = new Vector3;
|
|
const c = new Vector3;
|
|
for (let i = 0;i < indices.length; i += 3) {
|
|
getVertexByIndex(indices[i + 0], a);
|
|
getVertexByIndex(indices[i + 1], b);
|
|
getVertexByIndex(indices[i + 2], c);
|
|
subdivideFace(a, b, c, detail2);
|
|
}
|
|
}
|
|
function subdivideFace(a, b, c, detail2) {
|
|
const cols = detail2 + 1;
|
|
const v = [];
|
|
for (let i = 0;i <= cols; i++) {
|
|
v[i] = [];
|
|
const aj = a.clone().lerp(c, i / cols);
|
|
const bj = b.clone().lerp(c, i / cols);
|
|
const rows = cols - i;
|
|
for (let j = 0;j <= rows; j++) {
|
|
if (j === 0 && i === cols) {
|
|
v[i][j] = aj;
|
|
} else {
|
|
v[i][j] = aj.clone().lerp(bj, j / rows);
|
|
}
|
|
}
|
|
}
|
|
for (let i = 0;i < cols; i++) {
|
|
for (let j = 0;j < 2 * (cols - i) - 1; j++) {
|
|
const k = Math.floor(j / 2);
|
|
if (j % 2 === 0) {
|
|
pushVertex(v[i][k + 1]);
|
|
pushVertex(v[i + 1][k]);
|
|
pushVertex(v[i][k]);
|
|
} else {
|
|
pushVertex(v[i][k + 1]);
|
|
pushVertex(v[i + 1][k + 1]);
|
|
pushVertex(v[i + 1][k]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function applyRadius(radius2) {
|
|
const vertex = new Vector3;
|
|
for (let i = 0;i < vertexBuffer.length; i += 3) {
|
|
vertex.x = vertexBuffer[i + 0];
|
|
vertex.y = vertexBuffer[i + 1];
|
|
vertex.z = vertexBuffer[i + 2];
|
|
vertex.normalize().multiplyScalar(radius2);
|
|
vertexBuffer[i + 0] = vertex.x;
|
|
vertexBuffer[i + 1] = vertex.y;
|
|
vertexBuffer[i + 2] = vertex.z;
|
|
}
|
|
}
|
|
function generateUVs() {
|
|
const vertex = new Vector3;
|
|
for (let i = 0;i < vertexBuffer.length; i += 3) {
|
|
vertex.x = vertexBuffer[i + 0];
|
|
vertex.y = vertexBuffer[i + 1];
|
|
vertex.z = vertexBuffer[i + 2];
|
|
const u = azimuth(vertex) / 2 / Math.PI + 0.5;
|
|
const v = inclination(vertex) / Math.PI + 0.5;
|
|
uvBuffer.push(u, 1 - v);
|
|
}
|
|
correctUVs();
|
|
correctSeam();
|
|
}
|
|
function correctSeam() {
|
|
for (let i = 0;i < uvBuffer.length; i += 6) {
|
|
const x0 = uvBuffer[i + 0];
|
|
const x1 = uvBuffer[i + 2];
|
|
const x2 = uvBuffer[i + 4];
|
|
const max = Math.max(x0, x1, x2);
|
|
const min = Math.min(x0, x1, x2);
|
|
if (max > 0.9 && min < 0.1) {
|
|
if (x0 < 0.2)
|
|
uvBuffer[i + 0] += 1;
|
|
if (x1 < 0.2)
|
|
uvBuffer[i + 2] += 1;
|
|
if (x2 < 0.2)
|
|
uvBuffer[i + 4] += 1;
|
|
}
|
|
}
|
|
}
|
|
function pushVertex(vertex) {
|
|
vertexBuffer.push(vertex.x, vertex.y, vertex.z);
|
|
}
|
|
function getVertexByIndex(index, vertex) {
|
|
const stride = index * 3;
|
|
vertex.x = vertices[stride + 0];
|
|
vertex.y = vertices[stride + 1];
|
|
vertex.z = vertices[stride + 2];
|
|
}
|
|
function correctUVs() {
|
|
const a = new Vector3;
|
|
const b = new Vector3;
|
|
const c = new Vector3;
|
|
const centroid = new Vector3;
|
|
const uvA = new Vector2;
|
|
const uvB = new Vector2;
|
|
const uvC = new Vector2;
|
|
for (let i = 0, j = 0;i < vertexBuffer.length; i += 9, j += 6) {
|
|
a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
|
|
b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
|
|
c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
|
|
uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
|
|
uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
|
|
uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
|
|
centroid.copy(a).add(b).add(c).divideScalar(3);
|
|
const azi = azimuth(centroid);
|
|
correctUV(uvA, j + 0, a, azi);
|
|
correctUV(uvB, j + 2, b, azi);
|
|
correctUV(uvC, j + 4, c, azi);
|
|
}
|
|
}
|
|
function correctUV(uv, stride, vector, azimuth2) {
|
|
if (azimuth2 < 0 && uv.x === 1) {
|
|
uvBuffer[stride] = uv.x - 1;
|
|
}
|
|
if (vector.x === 0 && vector.z === 0) {
|
|
uvBuffer[stride] = azimuth2 / 2 / Math.PI + 0.5;
|
|
}
|
|
}
|
|
function azimuth(vector) {
|
|
return Math.atan2(vector.z, -vector.x);
|
|
}
|
|
function inclination(vector) {
|
|
return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new PolyhedronGeometry(data.vertices, data.indices, data.radius, data.details);
|
|
}
|
|
};
|
|
DodecahedronGeometry = class DodecahedronGeometry extends PolyhedronGeometry {
|
|
constructor(radius = 1, detail = 0) {
|
|
const t = (1 + Math.sqrt(5)) / 2;
|
|
const r = 1 / t;
|
|
const vertices = [
|
|
-1,
|
|
-1,
|
|
-1,
|
|
-1,
|
|
-1,
|
|
1,
|
|
-1,
|
|
1,
|
|
-1,
|
|
-1,
|
|
1,
|
|
1,
|
|
1,
|
|
-1,
|
|
-1,
|
|
1,
|
|
-1,
|
|
1,
|
|
1,
|
|
1,
|
|
-1,
|
|
1,
|
|
1,
|
|
1,
|
|
0,
|
|
-r,
|
|
-t,
|
|
0,
|
|
-r,
|
|
t,
|
|
0,
|
|
r,
|
|
-t,
|
|
0,
|
|
r,
|
|
t,
|
|
-r,
|
|
-t,
|
|
0,
|
|
-r,
|
|
t,
|
|
0,
|
|
r,
|
|
-t,
|
|
0,
|
|
r,
|
|
t,
|
|
0,
|
|
-t,
|
|
0,
|
|
-r,
|
|
t,
|
|
0,
|
|
-r,
|
|
-t,
|
|
0,
|
|
r,
|
|
t,
|
|
0,
|
|
r
|
|
];
|
|
const indices = [
|
|
3,
|
|
11,
|
|
7,
|
|
3,
|
|
7,
|
|
15,
|
|
3,
|
|
15,
|
|
13,
|
|
7,
|
|
19,
|
|
17,
|
|
7,
|
|
17,
|
|
6,
|
|
7,
|
|
6,
|
|
15,
|
|
17,
|
|
4,
|
|
8,
|
|
17,
|
|
8,
|
|
10,
|
|
17,
|
|
10,
|
|
6,
|
|
8,
|
|
0,
|
|
16,
|
|
8,
|
|
16,
|
|
2,
|
|
8,
|
|
2,
|
|
10,
|
|
0,
|
|
12,
|
|
1,
|
|
0,
|
|
1,
|
|
18,
|
|
0,
|
|
18,
|
|
16,
|
|
6,
|
|
10,
|
|
2,
|
|
6,
|
|
2,
|
|
13,
|
|
6,
|
|
13,
|
|
15,
|
|
2,
|
|
16,
|
|
18,
|
|
2,
|
|
18,
|
|
3,
|
|
2,
|
|
3,
|
|
13,
|
|
18,
|
|
1,
|
|
9,
|
|
18,
|
|
9,
|
|
11,
|
|
18,
|
|
11,
|
|
3,
|
|
4,
|
|
14,
|
|
12,
|
|
4,
|
|
12,
|
|
0,
|
|
4,
|
|
0,
|
|
8,
|
|
11,
|
|
9,
|
|
5,
|
|
11,
|
|
5,
|
|
19,
|
|
11,
|
|
19,
|
|
7,
|
|
19,
|
|
5,
|
|
14,
|
|
19,
|
|
14,
|
|
4,
|
|
19,
|
|
4,
|
|
17,
|
|
1,
|
|
12,
|
|
14,
|
|
1,
|
|
14,
|
|
5,
|
|
1,
|
|
5,
|
|
9
|
|
];
|
|
super(vertices, indices, radius, detail);
|
|
this.type = "DodecahedronGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
detail
|
|
};
|
|
}
|
|
static fromJSON(data) {
|
|
return new DodecahedronGeometry(data.radius, data.detail);
|
|
}
|
|
};
|
|
_v0 = /* @__PURE__ */ new Vector3;
|
|
_v1$1 = /* @__PURE__ */ new Vector3;
|
|
_normal = /* @__PURE__ */ new Vector3;
|
|
_triangle = /* @__PURE__ */ new Triangle;
|
|
EdgesGeometry = class EdgesGeometry extends BufferGeometry {
|
|
constructor(geometry = null, thresholdAngle = 1) {
|
|
super();
|
|
this.type = "EdgesGeometry";
|
|
this.parameters = {
|
|
geometry,
|
|
thresholdAngle
|
|
};
|
|
if (geometry !== null) {
|
|
const precisionPoints = 4;
|
|
const precision = Math.pow(10, precisionPoints);
|
|
const thresholdDot = Math.cos(DEG2RAD * thresholdAngle);
|
|
const indexAttr = geometry.getIndex();
|
|
const positionAttr = geometry.getAttribute("position");
|
|
const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
|
|
const indexArr = [0, 0, 0];
|
|
const vertKeys = ["a", "b", "c"];
|
|
const hashes = new Array(3);
|
|
const edgeData = {};
|
|
const vertices = [];
|
|
for (let i = 0;i < indexCount; i += 3) {
|
|
if (indexAttr) {
|
|
indexArr[0] = indexAttr.getX(i);
|
|
indexArr[1] = indexAttr.getX(i + 1);
|
|
indexArr[2] = indexAttr.getX(i + 2);
|
|
} else {
|
|
indexArr[0] = i;
|
|
indexArr[1] = i + 1;
|
|
indexArr[2] = i + 2;
|
|
}
|
|
const { a, b, c } = _triangle;
|
|
a.fromBufferAttribute(positionAttr, indexArr[0]);
|
|
b.fromBufferAttribute(positionAttr, indexArr[1]);
|
|
c.fromBufferAttribute(positionAttr, indexArr[2]);
|
|
_triangle.getNormal(_normal);
|
|
hashes[0] = `${Math.round(a.x * precision)},${Math.round(a.y * precision)},${Math.round(a.z * precision)}`;
|
|
hashes[1] = `${Math.round(b.x * precision)},${Math.round(b.y * precision)},${Math.round(b.z * precision)}`;
|
|
hashes[2] = `${Math.round(c.x * precision)},${Math.round(c.y * precision)},${Math.round(c.z * precision)}`;
|
|
if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
|
|
continue;
|
|
}
|
|
for (let j = 0;j < 3; j++) {
|
|
const jNext = (j + 1) % 3;
|
|
const vecHash0 = hashes[j];
|
|
const vecHash1 = hashes[jNext];
|
|
const v0 = _triangle[vertKeys[j]];
|
|
const v1 = _triangle[vertKeys[jNext]];
|
|
const hash = `${vecHash0}_${vecHash1}`;
|
|
const reverseHash = `${vecHash1}_${vecHash0}`;
|
|
if (reverseHash in edgeData && edgeData[reverseHash]) {
|
|
if (_normal.dot(edgeData[reverseHash].normal) <= thresholdDot) {
|
|
vertices.push(v0.x, v0.y, v0.z);
|
|
vertices.push(v1.x, v1.y, v1.z);
|
|
}
|
|
edgeData[reverseHash] = null;
|
|
} else if (!(hash in edgeData)) {
|
|
edgeData[hash] = {
|
|
index0: indexArr[j],
|
|
index1: indexArr[jNext],
|
|
normal: _normal.clone()
|
|
};
|
|
}
|
|
}
|
|
}
|
|
for (const key in edgeData) {
|
|
if (edgeData[key]) {
|
|
const { index0, index1 } = edgeData[key];
|
|
_v0.fromBufferAttribute(positionAttr, index0);
|
|
_v1$1.fromBufferAttribute(positionAttr, index1);
|
|
vertices.push(_v0.x, _v0.y, _v0.z);
|
|
vertices.push(_v1$1.x, _v1$1.y, _v1$1.z);
|
|
}
|
|
}
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
};
|
|
Shape = class Shape extends Path {
|
|
constructor(points) {
|
|
super(points);
|
|
this.uuid = generateUUID();
|
|
this.type = "Shape";
|
|
this.holes = [];
|
|
}
|
|
getPointsHoles(divisions) {
|
|
const holesPts = [];
|
|
for (let i = 0, l = this.holes.length;i < l; i++) {
|
|
holesPts[i] = this.holes[i].getPoints(divisions);
|
|
}
|
|
return holesPts;
|
|
}
|
|
extractPoints(divisions) {
|
|
return {
|
|
shape: this.getPoints(divisions),
|
|
holes: this.getPointsHoles(divisions)
|
|
};
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.holes = [];
|
|
for (let i = 0, l = source.holes.length;i < l; i++) {
|
|
const hole = source.holes[i];
|
|
this.holes.push(hole.clone());
|
|
}
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.uuid = this.uuid;
|
|
data.holes = [];
|
|
for (let i = 0, l = this.holes.length;i < l; i++) {
|
|
const hole = this.holes[i];
|
|
data.holes.push(hole.toJSON());
|
|
}
|
|
return data;
|
|
}
|
|
fromJSON(json) {
|
|
super.fromJSON(json);
|
|
this.uuid = json.uuid;
|
|
this.holes = [];
|
|
for (let i = 0, l = json.holes.length;i < l; i++) {
|
|
const hole = json.holes[i];
|
|
this.holes.push(new Path().fromJSON(hole));
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
Earcut = {
|
|
triangulate: function(data, holeIndices, dim = 2) {
|
|
const hasHoles = holeIndices && holeIndices.length;
|
|
const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
|
let outerNode = linkedList(data, 0, outerLen, dim, true);
|
|
const triangles = [];
|
|
if (!outerNode || outerNode.next === outerNode.prev)
|
|
return triangles;
|
|
let minX, minY, maxX, maxY, x, y, invSize;
|
|
if (hasHoles)
|
|
outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
|
|
if (data.length > 80 * dim) {
|
|
minX = maxX = data[0];
|
|
minY = maxY = data[1];
|
|
for (let i = dim;i < outerLen; i += dim) {
|
|
x = data[i];
|
|
y = data[i + 1];
|
|
if (x < minX)
|
|
minX = x;
|
|
if (y < minY)
|
|
minY = y;
|
|
if (x > maxX)
|
|
maxX = x;
|
|
if (y > maxY)
|
|
maxY = y;
|
|
}
|
|
invSize = Math.max(maxX - minX, maxY - minY);
|
|
invSize = invSize !== 0 ? 32767 / invSize : 0;
|
|
}
|
|
earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
|
|
return triangles;
|
|
}
|
|
};
|
|
ExtrudeGeometry = class ExtrudeGeometry extends BufferGeometry {
|
|
constructor(shapes = new Shape([new Vector2(0.5, 0.5), new Vector2(-0.5, 0.5), new Vector2(-0.5, -0.5), new Vector2(0.5, -0.5)]), options = {}) {
|
|
super();
|
|
this.type = "ExtrudeGeometry";
|
|
this.parameters = {
|
|
shapes,
|
|
options
|
|
};
|
|
shapes = Array.isArray(shapes) ? shapes : [shapes];
|
|
const scope = this;
|
|
const verticesArray = [];
|
|
const uvArray = [];
|
|
for (let i = 0, l = shapes.length;i < l; i++) {
|
|
const shape = shapes[i];
|
|
addShape(shape);
|
|
}
|
|
this.setAttribute("position", new Float32BufferAttribute(verticesArray, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvArray, 2));
|
|
this.computeVertexNormals();
|
|
function addShape(shape) {
|
|
const placeholder = [];
|
|
const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
|
|
const steps = options.steps !== undefined ? options.steps : 1;
|
|
const depth = options.depth !== undefined ? options.depth : 1;
|
|
let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
|
|
let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 0.2;
|
|
let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 0.1;
|
|
let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
|
|
let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
|
|
const extrudePath = options.extrudePath;
|
|
const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
|
|
let extrudePts, extrudeByPath = false;
|
|
let splineTube, binormal, normal, position2;
|
|
if (extrudePath) {
|
|
extrudePts = extrudePath.getSpacedPoints(steps);
|
|
extrudeByPath = true;
|
|
bevelEnabled = false;
|
|
splineTube = extrudePath.computeFrenetFrames(steps, false);
|
|
binormal = new Vector3;
|
|
normal = new Vector3;
|
|
position2 = new Vector3;
|
|
}
|
|
if (!bevelEnabled) {
|
|
bevelSegments = 0;
|
|
bevelThickness = 0;
|
|
bevelSize = 0;
|
|
bevelOffset = 0;
|
|
}
|
|
const shapePoints = shape.extractPoints(curveSegments);
|
|
let vertices = shapePoints.shape;
|
|
const holes = shapePoints.holes;
|
|
const reverse = !ShapeUtils.isClockWise(vertices);
|
|
if (reverse) {
|
|
vertices = vertices.reverse();
|
|
for (let h = 0, hl = holes.length;h < hl; h++) {
|
|
const ahole = holes[h];
|
|
if (ShapeUtils.isClockWise(ahole)) {
|
|
holes[h] = ahole.reverse();
|
|
}
|
|
}
|
|
}
|
|
const faces = ShapeUtils.triangulateShape(vertices, holes);
|
|
const contour = vertices;
|
|
for (let h = 0, hl = holes.length;h < hl; h++) {
|
|
const ahole = holes[h];
|
|
vertices = vertices.concat(ahole);
|
|
}
|
|
function scalePt2(pt, vec, size) {
|
|
if (!vec)
|
|
console.error("THREE.ExtrudeGeometry: vec does not exist");
|
|
return pt.clone().addScaledVector(vec, size);
|
|
}
|
|
const vlen = vertices.length, flen = faces.length;
|
|
function getBevelVec(inPt, inPrev, inNext) {
|
|
let v_trans_x, v_trans_y, shrink_by;
|
|
const v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
|
|
const v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
|
|
const v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y;
|
|
const collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
|
|
if (Math.abs(collinear0) > Number.EPSILON) {
|
|
const v_prev_len = Math.sqrt(v_prev_lensq);
|
|
const v_next_len = Math.sqrt(v_next_x * v_next_x + v_next_y * v_next_y);
|
|
const ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
|
|
const ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
|
|
const ptNextShift_x = inNext.x - v_next_y / v_next_len;
|
|
const ptNextShift_y = inNext.y + v_next_x / v_next_len;
|
|
const sf = ((ptNextShift_x - ptPrevShift_x) * v_next_y - (ptNextShift_y - ptPrevShift_y) * v_next_x) / (v_prev_x * v_next_y - v_prev_y * v_next_x);
|
|
v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
|
|
v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y;
|
|
const v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
|
|
if (v_trans_lensq <= 2) {
|
|
return new Vector2(v_trans_x, v_trans_y);
|
|
} else {
|
|
shrink_by = Math.sqrt(v_trans_lensq / 2);
|
|
}
|
|
} else {
|
|
let direction_eq = false;
|
|
if (v_prev_x > Number.EPSILON) {
|
|
if (v_next_x > Number.EPSILON) {
|
|
direction_eq = true;
|
|
}
|
|
} else {
|
|
if (v_prev_x < -Number.EPSILON) {
|
|
if (v_next_x < -Number.EPSILON) {
|
|
direction_eq = true;
|
|
}
|
|
} else {
|
|
if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
|
|
direction_eq = true;
|
|
}
|
|
}
|
|
}
|
|
if (direction_eq) {
|
|
v_trans_x = -v_prev_y;
|
|
v_trans_y = v_prev_x;
|
|
shrink_by = Math.sqrt(v_prev_lensq);
|
|
} else {
|
|
v_trans_x = v_prev_x;
|
|
v_trans_y = v_prev_y;
|
|
shrink_by = Math.sqrt(v_prev_lensq / 2);
|
|
}
|
|
}
|
|
return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
|
|
}
|
|
const contourMovements = [];
|
|
for (let i = 0, il = contour.length, j = il - 1, k = i + 1;i < il; i++, j++, k++) {
|
|
if (j === il)
|
|
j = 0;
|
|
if (k === il)
|
|
k = 0;
|
|
contourMovements[i] = getBevelVec(contour[i], contour[j], contour[k]);
|
|
}
|
|
const holesMovements = [];
|
|
let oneHoleMovements, verticesMovements = contourMovements.concat();
|
|
for (let h = 0, hl = holes.length;h < hl; h++) {
|
|
const ahole = holes[h];
|
|
oneHoleMovements = [];
|
|
for (let i = 0, il = ahole.length, j = il - 1, k = i + 1;i < il; i++, j++, k++) {
|
|
if (j === il)
|
|
j = 0;
|
|
if (k === il)
|
|
k = 0;
|
|
oneHoleMovements[i] = getBevelVec(ahole[i], ahole[j], ahole[k]);
|
|
}
|
|
holesMovements.push(oneHoleMovements);
|
|
verticesMovements = verticesMovements.concat(oneHoleMovements);
|
|
}
|
|
for (let b = 0;b < bevelSegments; b++) {
|
|
const t = b / bevelSegments;
|
|
const z = bevelThickness * Math.cos(t * Math.PI / 2);
|
|
const bs2 = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset;
|
|
for (let i = 0, il = contour.length;i < il; i++) {
|
|
const vert = scalePt2(contour[i], contourMovements[i], bs2);
|
|
v(vert.x, vert.y, -z);
|
|
}
|
|
for (let h = 0, hl = holes.length;h < hl; h++) {
|
|
const ahole = holes[h];
|
|
oneHoleMovements = holesMovements[h];
|
|
for (let i = 0, il = ahole.length;i < il; i++) {
|
|
const vert = scalePt2(ahole[i], oneHoleMovements[i], bs2);
|
|
v(vert.x, vert.y, -z);
|
|
}
|
|
}
|
|
}
|
|
const bs = bevelSize + bevelOffset;
|
|
for (let i = 0;i < vlen; i++) {
|
|
const vert = bevelEnabled ? scalePt2(vertices[i], verticesMovements[i], bs) : vertices[i];
|
|
if (!extrudeByPath) {
|
|
v(vert.x, vert.y, 0);
|
|
} else {
|
|
normal.copy(splineTube.normals[0]).multiplyScalar(vert.x);
|
|
binormal.copy(splineTube.binormals[0]).multiplyScalar(vert.y);
|
|
position2.copy(extrudePts[0]).add(normal).add(binormal);
|
|
v(position2.x, position2.y, position2.z);
|
|
}
|
|
}
|
|
for (let s = 1;s <= steps; s++) {
|
|
for (let i = 0;i < vlen; i++) {
|
|
const vert = bevelEnabled ? scalePt2(vertices[i], verticesMovements[i], bs) : vertices[i];
|
|
if (!extrudeByPath) {
|
|
v(vert.x, vert.y, depth / steps * s);
|
|
} else {
|
|
normal.copy(splineTube.normals[s]).multiplyScalar(vert.x);
|
|
binormal.copy(splineTube.binormals[s]).multiplyScalar(vert.y);
|
|
position2.copy(extrudePts[s]).add(normal).add(binormal);
|
|
v(position2.x, position2.y, position2.z);
|
|
}
|
|
}
|
|
}
|
|
for (let b = bevelSegments - 1;b >= 0; b--) {
|
|
const t = b / bevelSegments;
|
|
const z = bevelThickness * Math.cos(t * Math.PI / 2);
|
|
const bs2 = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset;
|
|
for (let i = 0, il = contour.length;i < il; i++) {
|
|
const vert = scalePt2(contour[i], contourMovements[i], bs2);
|
|
v(vert.x, vert.y, depth + z);
|
|
}
|
|
for (let h = 0, hl = holes.length;h < hl; h++) {
|
|
const ahole = holes[h];
|
|
oneHoleMovements = holesMovements[h];
|
|
for (let i = 0, il = ahole.length;i < il; i++) {
|
|
const vert = scalePt2(ahole[i], oneHoleMovements[i], bs2);
|
|
if (!extrudeByPath) {
|
|
v(vert.x, vert.y, depth + z);
|
|
} else {
|
|
v(vert.x, vert.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + z);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
buildLidFaces();
|
|
buildSideFaces();
|
|
function buildLidFaces() {
|
|
const start = verticesArray.length / 3;
|
|
if (bevelEnabled) {
|
|
let layer = 0;
|
|
let offset = vlen * layer;
|
|
for (let i = 0;i < flen; i++) {
|
|
const face = faces[i];
|
|
f3(face[2] + offset, face[1] + offset, face[0] + offset);
|
|
}
|
|
layer = steps + bevelSegments * 2;
|
|
offset = vlen * layer;
|
|
for (let i = 0;i < flen; i++) {
|
|
const face = faces[i];
|
|
f3(face[0] + offset, face[1] + offset, face[2] + offset);
|
|
}
|
|
} else {
|
|
for (let i = 0;i < flen; i++) {
|
|
const face = faces[i];
|
|
f3(face[2], face[1], face[0]);
|
|
}
|
|
for (let i = 0;i < flen; i++) {
|
|
const face = faces[i];
|
|
f3(face[0] + vlen * steps, face[1] + vlen * steps, face[2] + vlen * steps);
|
|
}
|
|
}
|
|
scope.addGroup(start, verticesArray.length / 3 - start, 0);
|
|
}
|
|
function buildSideFaces() {
|
|
const start = verticesArray.length / 3;
|
|
let layeroffset = 0;
|
|
sidewalls(contour, layeroffset);
|
|
layeroffset += contour.length;
|
|
for (let h = 0, hl = holes.length;h < hl; h++) {
|
|
const ahole = holes[h];
|
|
sidewalls(ahole, layeroffset);
|
|
layeroffset += ahole.length;
|
|
}
|
|
scope.addGroup(start, verticesArray.length / 3 - start, 1);
|
|
}
|
|
function sidewalls(contour2, layeroffset) {
|
|
let i = contour2.length;
|
|
while (--i >= 0) {
|
|
const j = i;
|
|
let k = i - 1;
|
|
if (k < 0)
|
|
k = contour2.length - 1;
|
|
for (let s = 0, sl = steps + bevelSegments * 2;s < sl; s++) {
|
|
const slen1 = vlen * s;
|
|
const slen2 = vlen * (s + 1);
|
|
const a = layeroffset + j + slen1, b = layeroffset + k + slen1, c = layeroffset + k + slen2, d = layeroffset + j + slen2;
|
|
f4(a, b, c, d);
|
|
}
|
|
}
|
|
}
|
|
function v(x, y, z) {
|
|
placeholder.push(x);
|
|
placeholder.push(y);
|
|
placeholder.push(z);
|
|
}
|
|
function f3(a, b, c) {
|
|
addVertex(a);
|
|
addVertex(b);
|
|
addVertex(c);
|
|
const nextIndex = verticesArray.length / 3;
|
|
const uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
|
|
addUV(uvs[0]);
|
|
addUV(uvs[1]);
|
|
addUV(uvs[2]);
|
|
}
|
|
function f4(a, b, c, d) {
|
|
addVertex(a);
|
|
addVertex(b);
|
|
addVertex(d);
|
|
addVertex(b);
|
|
addVertex(c);
|
|
addVertex(d);
|
|
const nextIndex = verticesArray.length / 3;
|
|
const uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
|
|
addUV(uvs[0]);
|
|
addUV(uvs[1]);
|
|
addUV(uvs[3]);
|
|
addUV(uvs[1]);
|
|
addUV(uvs[2]);
|
|
addUV(uvs[3]);
|
|
}
|
|
function addVertex(index) {
|
|
verticesArray.push(placeholder[index * 3 + 0]);
|
|
verticesArray.push(placeholder[index * 3 + 1]);
|
|
verticesArray.push(placeholder[index * 3 + 2]);
|
|
}
|
|
function addUV(vector2) {
|
|
uvArray.push(vector2.x);
|
|
uvArray.push(vector2.y);
|
|
}
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
const shapes = this.parameters.shapes;
|
|
const options = this.parameters.options;
|
|
return toJSON$1(shapes, options, data);
|
|
}
|
|
static fromJSON(data, shapes) {
|
|
const geometryShapes = [];
|
|
for (let j = 0, jl = data.shapes.length;j < jl; j++) {
|
|
const shape = shapes[data.shapes[j]];
|
|
geometryShapes.push(shape);
|
|
}
|
|
const extrudePath = data.options.extrudePath;
|
|
if (extrudePath !== undefined) {
|
|
data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
|
|
}
|
|
return new ExtrudeGeometry(geometryShapes, data.options);
|
|
}
|
|
};
|
|
WorldUVGenerator = {
|
|
generateTopUV: function(geometry, vertices, indexA, indexB, indexC) {
|
|
const a_x = vertices[indexA * 3];
|
|
const a_y = vertices[indexA * 3 + 1];
|
|
const b_x = vertices[indexB * 3];
|
|
const b_y = vertices[indexB * 3 + 1];
|
|
const c_x = vertices[indexC * 3];
|
|
const c_y = vertices[indexC * 3 + 1];
|
|
return [
|
|
new Vector2(a_x, a_y),
|
|
new Vector2(b_x, b_y),
|
|
new Vector2(c_x, c_y)
|
|
];
|
|
},
|
|
generateSideWallUV: function(geometry, vertices, indexA, indexB, indexC, indexD) {
|
|
const a_x = vertices[indexA * 3];
|
|
const a_y = vertices[indexA * 3 + 1];
|
|
const a_z = vertices[indexA * 3 + 2];
|
|
const b_x = vertices[indexB * 3];
|
|
const b_y = vertices[indexB * 3 + 1];
|
|
const b_z = vertices[indexB * 3 + 2];
|
|
const c_x = vertices[indexC * 3];
|
|
const c_y = vertices[indexC * 3 + 1];
|
|
const c_z = vertices[indexC * 3 + 2];
|
|
const d_x = vertices[indexD * 3];
|
|
const d_y = vertices[indexD * 3 + 1];
|
|
const d_z = vertices[indexD * 3 + 2];
|
|
if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
|
|
return [
|
|
new Vector2(a_x, 1 - a_z),
|
|
new Vector2(b_x, 1 - b_z),
|
|
new Vector2(c_x, 1 - c_z),
|
|
new Vector2(d_x, 1 - d_z)
|
|
];
|
|
} else {
|
|
return [
|
|
new Vector2(a_y, 1 - a_z),
|
|
new Vector2(b_y, 1 - b_z),
|
|
new Vector2(c_y, 1 - c_z),
|
|
new Vector2(d_y, 1 - d_z)
|
|
];
|
|
}
|
|
}
|
|
};
|
|
IcosahedronGeometry = class IcosahedronGeometry extends PolyhedronGeometry {
|
|
constructor(radius = 1, detail = 0) {
|
|
const t = (1 + Math.sqrt(5)) / 2;
|
|
const vertices = [
|
|
-1,
|
|
t,
|
|
0,
|
|
1,
|
|
t,
|
|
0,
|
|
-1,
|
|
-t,
|
|
0,
|
|
1,
|
|
-t,
|
|
0,
|
|
0,
|
|
-1,
|
|
t,
|
|
0,
|
|
1,
|
|
t,
|
|
0,
|
|
-1,
|
|
-t,
|
|
0,
|
|
1,
|
|
-t,
|
|
t,
|
|
0,
|
|
-1,
|
|
t,
|
|
0,
|
|
1,
|
|
-t,
|
|
0,
|
|
-1,
|
|
-t,
|
|
0,
|
|
1
|
|
];
|
|
const indices = [
|
|
0,
|
|
11,
|
|
5,
|
|
0,
|
|
5,
|
|
1,
|
|
0,
|
|
1,
|
|
7,
|
|
0,
|
|
7,
|
|
10,
|
|
0,
|
|
10,
|
|
11,
|
|
1,
|
|
5,
|
|
9,
|
|
5,
|
|
11,
|
|
4,
|
|
11,
|
|
10,
|
|
2,
|
|
10,
|
|
7,
|
|
6,
|
|
7,
|
|
1,
|
|
8,
|
|
3,
|
|
9,
|
|
4,
|
|
3,
|
|
4,
|
|
2,
|
|
3,
|
|
2,
|
|
6,
|
|
3,
|
|
6,
|
|
8,
|
|
3,
|
|
8,
|
|
9,
|
|
4,
|
|
9,
|
|
5,
|
|
2,
|
|
4,
|
|
11,
|
|
6,
|
|
2,
|
|
10,
|
|
8,
|
|
6,
|
|
7,
|
|
9,
|
|
8,
|
|
1
|
|
];
|
|
super(vertices, indices, radius, detail);
|
|
this.type = "IcosahedronGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
detail
|
|
};
|
|
}
|
|
static fromJSON(data) {
|
|
return new IcosahedronGeometry(data.radius, data.detail);
|
|
}
|
|
};
|
|
OctahedronGeometry = class OctahedronGeometry extends PolyhedronGeometry {
|
|
constructor(radius = 1, detail = 0) {
|
|
const vertices = [
|
|
1,
|
|
0,
|
|
0,
|
|
-1,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
-1,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
-1
|
|
];
|
|
const indices = [
|
|
0,
|
|
2,
|
|
4,
|
|
0,
|
|
4,
|
|
3,
|
|
0,
|
|
3,
|
|
5,
|
|
0,
|
|
5,
|
|
2,
|
|
1,
|
|
2,
|
|
5,
|
|
1,
|
|
5,
|
|
3,
|
|
1,
|
|
3,
|
|
4,
|
|
1,
|
|
4,
|
|
2
|
|
];
|
|
super(vertices, indices, radius, detail);
|
|
this.type = "OctahedronGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
detail
|
|
};
|
|
}
|
|
static fromJSON(data) {
|
|
return new OctahedronGeometry(data.radius, data.detail);
|
|
}
|
|
};
|
|
PlaneGeometry = class PlaneGeometry extends BufferGeometry {
|
|
constructor(width = 1, height = 1, widthSegments = 1, heightSegments = 1) {
|
|
super();
|
|
this.type = "PlaneGeometry";
|
|
this.parameters = {
|
|
width,
|
|
height,
|
|
widthSegments,
|
|
heightSegments
|
|
};
|
|
const width_half = width / 2;
|
|
const height_half = height / 2;
|
|
const gridX = Math.floor(widthSegments);
|
|
const gridY = Math.floor(heightSegments);
|
|
const gridX1 = gridX + 1;
|
|
const gridY1 = gridY + 1;
|
|
const segment_width = width / gridX;
|
|
const segment_height = height / gridY;
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
for (let iy = 0;iy < gridY1; iy++) {
|
|
const y = iy * segment_height - height_half;
|
|
for (let ix = 0;ix < gridX1; ix++) {
|
|
const x = ix * segment_width - width_half;
|
|
vertices.push(x, -y, 0);
|
|
normals.push(0, 0, 1);
|
|
uvs.push(ix / gridX);
|
|
uvs.push(1 - iy / gridY);
|
|
}
|
|
}
|
|
for (let iy = 0;iy < gridY; iy++) {
|
|
for (let ix = 0;ix < gridX; ix++) {
|
|
const a = ix + gridX1 * iy;
|
|
const b = ix + gridX1 * (iy + 1);
|
|
const c = ix + 1 + gridX1 * (iy + 1);
|
|
const d = ix + 1 + gridX1 * iy;
|
|
indices.push(a, b, d);
|
|
indices.push(b, c, d);
|
|
}
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new PlaneGeometry(data.width, data.height, data.widthSegments, data.heightSegments);
|
|
}
|
|
};
|
|
RingGeometry = class RingGeometry extends BufferGeometry {
|
|
constructor(innerRadius = 0.5, outerRadius = 1, thetaSegments = 32, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2) {
|
|
super();
|
|
this.type = "RingGeometry";
|
|
this.parameters = {
|
|
innerRadius,
|
|
outerRadius,
|
|
thetaSegments,
|
|
phiSegments,
|
|
thetaStart,
|
|
thetaLength
|
|
};
|
|
thetaSegments = Math.max(3, thetaSegments);
|
|
phiSegments = Math.max(1, phiSegments);
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
let radius = innerRadius;
|
|
const radiusStep = (outerRadius - innerRadius) / phiSegments;
|
|
const vertex = new Vector3;
|
|
const uv = new Vector2;
|
|
for (let j = 0;j <= phiSegments; j++) {
|
|
for (let i = 0;i <= thetaSegments; i++) {
|
|
const segment = thetaStart + i / thetaSegments * thetaLength;
|
|
vertex.x = radius * Math.cos(segment);
|
|
vertex.y = radius * Math.sin(segment);
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
normals.push(0, 0, 1);
|
|
uv.x = (vertex.x / outerRadius + 1) / 2;
|
|
uv.y = (vertex.y / outerRadius + 1) / 2;
|
|
uvs.push(uv.x, uv.y);
|
|
}
|
|
radius += radiusStep;
|
|
}
|
|
for (let j = 0;j < phiSegments; j++) {
|
|
const thetaSegmentLevel = j * (thetaSegments + 1);
|
|
for (let i = 0;i < thetaSegments; i++) {
|
|
const segment = i + thetaSegmentLevel;
|
|
const a = segment;
|
|
const b = segment + thetaSegments + 1;
|
|
const c = segment + thetaSegments + 2;
|
|
const d = segment + 1;
|
|
indices.push(a, b, d);
|
|
indices.push(b, c, d);
|
|
}
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new RingGeometry(data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
|
|
}
|
|
};
|
|
ShapeGeometry = class ShapeGeometry extends BufferGeometry {
|
|
constructor(shapes = new Shape([new Vector2(0, 0.5), new Vector2(-0.5, -0.5), new Vector2(0.5, -0.5)]), curveSegments = 12) {
|
|
super();
|
|
this.type = "ShapeGeometry";
|
|
this.parameters = {
|
|
shapes,
|
|
curveSegments
|
|
};
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
let groupStart = 0;
|
|
let groupCount = 0;
|
|
if (Array.isArray(shapes) === false) {
|
|
addShape(shapes);
|
|
} else {
|
|
for (let i = 0;i < shapes.length; i++) {
|
|
addShape(shapes[i]);
|
|
this.addGroup(groupStart, groupCount, i);
|
|
groupStart += groupCount;
|
|
groupCount = 0;
|
|
}
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
function addShape(shape) {
|
|
const indexOffset = vertices.length / 3;
|
|
const points = shape.extractPoints(curveSegments);
|
|
let shapeVertices = points.shape;
|
|
const shapeHoles = points.holes;
|
|
if (ShapeUtils.isClockWise(shapeVertices) === false) {
|
|
shapeVertices = shapeVertices.reverse();
|
|
}
|
|
for (let i = 0, l = shapeHoles.length;i < l; i++) {
|
|
const shapeHole = shapeHoles[i];
|
|
if (ShapeUtils.isClockWise(shapeHole) === true) {
|
|
shapeHoles[i] = shapeHole.reverse();
|
|
}
|
|
}
|
|
const faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles);
|
|
for (let i = 0, l = shapeHoles.length;i < l; i++) {
|
|
const shapeHole = shapeHoles[i];
|
|
shapeVertices = shapeVertices.concat(shapeHole);
|
|
}
|
|
for (let i = 0, l = shapeVertices.length;i < l; i++) {
|
|
const vertex = shapeVertices[i];
|
|
vertices.push(vertex.x, vertex.y, 0);
|
|
normals.push(0, 0, 1);
|
|
uvs.push(vertex.x, vertex.y);
|
|
}
|
|
for (let i = 0, l = faces.length;i < l; i++) {
|
|
const face = faces[i];
|
|
const a = face[0] + indexOffset;
|
|
const b = face[1] + indexOffset;
|
|
const c = face[2] + indexOffset;
|
|
indices.push(a, b, c);
|
|
groupCount += 3;
|
|
}
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
const shapes = this.parameters.shapes;
|
|
return toJSON(shapes, data);
|
|
}
|
|
static fromJSON(data, shapes) {
|
|
const geometryShapes = [];
|
|
for (let j = 0, jl = data.shapes.length;j < jl; j++) {
|
|
const shape = shapes[data.shapes[j]];
|
|
geometryShapes.push(shape);
|
|
}
|
|
return new ShapeGeometry(geometryShapes, data.curveSegments);
|
|
}
|
|
};
|
|
SphereGeometry = class SphereGeometry extends BufferGeometry {
|
|
constructor(radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI) {
|
|
super();
|
|
this.type = "SphereGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
widthSegments,
|
|
heightSegments,
|
|
phiStart,
|
|
phiLength,
|
|
thetaStart,
|
|
thetaLength
|
|
};
|
|
widthSegments = Math.max(3, Math.floor(widthSegments));
|
|
heightSegments = Math.max(2, Math.floor(heightSegments));
|
|
const thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
|
|
let index = 0;
|
|
const grid = [];
|
|
const vertex = new Vector3;
|
|
const normal = new Vector3;
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
for (let iy = 0;iy <= heightSegments; iy++) {
|
|
const verticesRow = [];
|
|
const v = iy / heightSegments;
|
|
let uOffset = 0;
|
|
if (iy === 0 && thetaStart === 0) {
|
|
uOffset = 0.5 / widthSegments;
|
|
} else if (iy === heightSegments && thetaEnd === Math.PI) {
|
|
uOffset = -0.5 / widthSegments;
|
|
}
|
|
for (let ix = 0;ix <= widthSegments; ix++) {
|
|
const u = ix / widthSegments;
|
|
vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
|
|
vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
|
|
vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
normal.copy(vertex).normalize();
|
|
normals.push(normal.x, normal.y, normal.z);
|
|
uvs.push(u + uOffset, 1 - v);
|
|
verticesRow.push(index++);
|
|
}
|
|
grid.push(verticesRow);
|
|
}
|
|
for (let iy = 0;iy < heightSegments; iy++) {
|
|
for (let ix = 0;ix < widthSegments; ix++) {
|
|
const a = grid[iy][ix + 1];
|
|
const b = grid[iy][ix];
|
|
const c = grid[iy + 1][ix];
|
|
const d = grid[iy + 1][ix + 1];
|
|
if (iy !== 0 || thetaStart > 0)
|
|
indices.push(a, b, d);
|
|
if (iy !== heightSegments - 1 || thetaEnd < Math.PI)
|
|
indices.push(b, c, d);
|
|
}
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new SphereGeometry(data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
|
|
}
|
|
};
|
|
TetrahedronGeometry = class TetrahedronGeometry extends PolyhedronGeometry {
|
|
constructor(radius = 1, detail = 0) {
|
|
const vertices = [
|
|
1,
|
|
1,
|
|
1,
|
|
-1,
|
|
-1,
|
|
1,
|
|
-1,
|
|
1,
|
|
-1,
|
|
1,
|
|
-1,
|
|
-1
|
|
];
|
|
const indices = [
|
|
2,
|
|
1,
|
|
0,
|
|
0,
|
|
3,
|
|
2,
|
|
1,
|
|
3,
|
|
0,
|
|
2,
|
|
3,
|
|
1
|
|
];
|
|
super(vertices, indices, radius, detail);
|
|
this.type = "TetrahedronGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
detail
|
|
};
|
|
}
|
|
static fromJSON(data) {
|
|
return new TetrahedronGeometry(data.radius, data.detail);
|
|
}
|
|
};
|
|
TorusGeometry = class TorusGeometry extends BufferGeometry {
|
|
constructor(radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2) {
|
|
super();
|
|
this.type = "TorusGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
tube,
|
|
radialSegments,
|
|
tubularSegments,
|
|
arc
|
|
};
|
|
radialSegments = Math.floor(radialSegments);
|
|
tubularSegments = Math.floor(tubularSegments);
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
const center = new Vector3;
|
|
const vertex = new Vector3;
|
|
const normal = new Vector3;
|
|
for (let j = 0;j <= radialSegments; j++) {
|
|
for (let i = 0;i <= tubularSegments; i++) {
|
|
const u = i / tubularSegments * arc;
|
|
const v = j / radialSegments * Math.PI * 2;
|
|
vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
|
|
vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
|
|
vertex.z = tube * Math.sin(v);
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
center.x = radius * Math.cos(u);
|
|
center.y = radius * Math.sin(u);
|
|
normal.subVectors(vertex, center).normalize();
|
|
normals.push(normal.x, normal.y, normal.z);
|
|
uvs.push(i / tubularSegments);
|
|
uvs.push(j / radialSegments);
|
|
}
|
|
}
|
|
for (let j = 1;j <= radialSegments; j++) {
|
|
for (let i = 1;i <= tubularSegments; i++) {
|
|
const a = (tubularSegments + 1) * j + i - 1;
|
|
const b = (tubularSegments + 1) * (j - 1) + i - 1;
|
|
const c = (tubularSegments + 1) * (j - 1) + i;
|
|
const d = (tubularSegments + 1) * j + i;
|
|
indices.push(a, b, d);
|
|
indices.push(b, c, d);
|
|
}
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new TorusGeometry(data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
|
|
}
|
|
};
|
|
TorusKnotGeometry = class TorusKnotGeometry extends BufferGeometry {
|
|
constructor(radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3) {
|
|
super();
|
|
this.type = "TorusKnotGeometry";
|
|
this.parameters = {
|
|
radius,
|
|
tube,
|
|
tubularSegments,
|
|
radialSegments,
|
|
p,
|
|
q
|
|
};
|
|
tubularSegments = Math.floor(tubularSegments);
|
|
radialSegments = Math.floor(radialSegments);
|
|
const indices = [];
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
const vertex = new Vector3;
|
|
const normal = new Vector3;
|
|
const P1 = new Vector3;
|
|
const P2 = new Vector3;
|
|
const B = new Vector3;
|
|
const T = new Vector3;
|
|
const N = new Vector3;
|
|
for (let i = 0;i <= tubularSegments; ++i) {
|
|
const u = i / tubularSegments * p * Math.PI * 2;
|
|
calculatePositionOnCurve(u, p, q, radius, P1);
|
|
calculatePositionOnCurve(u + 0.01, p, q, radius, P2);
|
|
T.subVectors(P2, P1);
|
|
N.addVectors(P2, P1);
|
|
B.crossVectors(T, N);
|
|
N.crossVectors(B, T);
|
|
B.normalize();
|
|
N.normalize();
|
|
for (let j = 0;j <= radialSegments; ++j) {
|
|
const v = j / radialSegments * Math.PI * 2;
|
|
const cx = -tube * Math.cos(v);
|
|
const cy = tube * Math.sin(v);
|
|
vertex.x = P1.x + (cx * N.x + cy * B.x);
|
|
vertex.y = P1.y + (cx * N.y + cy * B.y);
|
|
vertex.z = P1.z + (cx * N.z + cy * B.z);
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
normal.subVectors(vertex, P1).normalize();
|
|
normals.push(normal.x, normal.y, normal.z);
|
|
uvs.push(i / tubularSegments);
|
|
uvs.push(j / radialSegments);
|
|
}
|
|
}
|
|
for (let j = 1;j <= tubularSegments; j++) {
|
|
for (let i = 1;i <= radialSegments; i++) {
|
|
const a = (radialSegments + 1) * (j - 1) + (i - 1);
|
|
const b = (radialSegments + 1) * j + (i - 1);
|
|
const c = (radialSegments + 1) * j + i;
|
|
const d = (radialSegments + 1) * (j - 1) + i;
|
|
indices.push(a, b, d);
|
|
indices.push(b, c, d);
|
|
}
|
|
}
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
function calculatePositionOnCurve(u, p2, q2, radius2, position) {
|
|
const cu = Math.cos(u);
|
|
const su = Math.sin(u);
|
|
const quOverP = q2 / p2 * u;
|
|
const cs = Math.cos(quOverP);
|
|
position.x = radius2 * (2 + cs) * 0.5 * cu;
|
|
position.y = radius2 * (2 + cs) * su * 0.5;
|
|
position.z = radius2 * Math.sin(quOverP) * 0.5;
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
static fromJSON(data) {
|
|
return new TorusKnotGeometry(data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
|
|
}
|
|
};
|
|
TubeGeometry = class TubeGeometry extends BufferGeometry {
|
|
constructor(path = new QuadraticBezierCurve3(new Vector3(-1, -1, 0), new Vector3(-1, 1, 0), new Vector3(1, 1, 0)), tubularSegments = 64, radius = 1, radialSegments = 8, closed = false) {
|
|
super();
|
|
this.type = "TubeGeometry";
|
|
this.parameters = {
|
|
path,
|
|
tubularSegments,
|
|
radius,
|
|
radialSegments,
|
|
closed
|
|
};
|
|
const frames = path.computeFrenetFrames(tubularSegments, closed);
|
|
this.tangents = frames.tangents;
|
|
this.normals = frames.normals;
|
|
this.binormals = frames.binormals;
|
|
const vertex = new Vector3;
|
|
const normal = new Vector3;
|
|
const uv = new Vector2;
|
|
let P = new Vector3;
|
|
const vertices = [];
|
|
const normals = [];
|
|
const uvs = [];
|
|
const indices = [];
|
|
generateBufferData();
|
|
this.setIndex(indices);
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
this.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
this.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
function generateBufferData() {
|
|
for (let i = 0;i < tubularSegments; i++) {
|
|
generateSegment(i);
|
|
}
|
|
generateSegment(closed === false ? tubularSegments : 0);
|
|
generateUVs();
|
|
generateIndices();
|
|
}
|
|
function generateSegment(i) {
|
|
P = path.getPointAt(i / tubularSegments, P);
|
|
const N = frames.normals[i];
|
|
const B = frames.binormals[i];
|
|
for (let j = 0;j <= radialSegments; j++) {
|
|
const v = j / radialSegments * Math.PI * 2;
|
|
const sin = Math.sin(v);
|
|
const cos = -Math.cos(v);
|
|
normal.x = cos * N.x + sin * B.x;
|
|
normal.y = cos * N.y + sin * B.y;
|
|
normal.z = cos * N.z + sin * B.z;
|
|
normal.normalize();
|
|
normals.push(normal.x, normal.y, normal.z);
|
|
vertex.x = P.x + radius * normal.x;
|
|
vertex.y = P.y + radius * normal.y;
|
|
vertex.z = P.z + radius * normal.z;
|
|
vertices.push(vertex.x, vertex.y, vertex.z);
|
|
}
|
|
}
|
|
function generateIndices() {
|
|
for (let j = 1;j <= tubularSegments; j++) {
|
|
for (let i = 1;i <= radialSegments; i++) {
|
|
const a = (radialSegments + 1) * (j - 1) + (i - 1);
|
|
const b = (radialSegments + 1) * j + (i - 1);
|
|
const c = (radialSegments + 1) * j + i;
|
|
const d = (radialSegments + 1) * (j - 1) + i;
|
|
indices.push(a, b, d);
|
|
indices.push(b, c, d);
|
|
}
|
|
}
|
|
}
|
|
function generateUVs() {
|
|
for (let i = 0;i <= tubularSegments; i++) {
|
|
for (let j = 0;j <= radialSegments; j++) {
|
|
uv.x = i / tubularSegments;
|
|
uv.y = j / radialSegments;
|
|
uvs.push(uv.x, uv.y);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.path = this.parameters.path.toJSON();
|
|
return data;
|
|
}
|
|
static fromJSON(data) {
|
|
return new TubeGeometry(new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
|
|
}
|
|
};
|
|
WireframeGeometry = class WireframeGeometry extends BufferGeometry {
|
|
constructor(geometry = null) {
|
|
super();
|
|
this.type = "WireframeGeometry";
|
|
this.parameters = {
|
|
geometry
|
|
};
|
|
if (geometry !== null) {
|
|
const vertices = [];
|
|
const edges = new Set;
|
|
const start = new Vector3;
|
|
const end = new Vector3;
|
|
if (geometry.index !== null) {
|
|
const position = geometry.attributes.position;
|
|
const indices = geometry.index;
|
|
let groups = geometry.groups;
|
|
if (groups.length === 0) {
|
|
groups = [{ start: 0, count: indices.count, materialIndex: 0 }];
|
|
}
|
|
for (let o = 0, ol = groups.length;o < ol; ++o) {
|
|
const group = groups[o];
|
|
const groupStart = group.start;
|
|
const groupCount = group.count;
|
|
for (let i = groupStart, l = groupStart + groupCount;i < l; i += 3) {
|
|
for (let j = 0;j < 3; j++) {
|
|
const index1 = indices.getX(i + j);
|
|
const index2 = indices.getX(i + (j + 1) % 3);
|
|
start.fromBufferAttribute(position, index1);
|
|
end.fromBufferAttribute(position, index2);
|
|
if (isUniqueEdge(start, end, edges) === true) {
|
|
vertices.push(start.x, start.y, start.z);
|
|
vertices.push(end.x, end.y, end.z);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
const position = geometry.attributes.position;
|
|
for (let i = 0, l = position.count / 3;i < l; i++) {
|
|
for (let j = 0;j < 3; j++) {
|
|
const index1 = 3 * i + j;
|
|
const index2 = 3 * i + (j + 1) % 3;
|
|
start.fromBufferAttribute(position, index1);
|
|
end.fromBufferAttribute(position, index2);
|
|
if (isUniqueEdge(start, end, edges) === true) {
|
|
vertices.push(start.x, start.y, start.z);
|
|
vertices.push(end.x, end.y, end.z);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
}
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.parameters = Object.assign({}, source.parameters);
|
|
return this;
|
|
}
|
|
};
|
|
Geometries = /* @__PURE__ */ Object.freeze({
|
|
__proto__: null,
|
|
BoxGeometry,
|
|
CapsuleGeometry,
|
|
CircleGeometry,
|
|
ConeGeometry,
|
|
CylinderGeometry,
|
|
DodecahedronGeometry,
|
|
EdgesGeometry,
|
|
ExtrudeGeometry,
|
|
IcosahedronGeometry,
|
|
LatheGeometry,
|
|
OctahedronGeometry,
|
|
PlaneGeometry,
|
|
PolyhedronGeometry,
|
|
RingGeometry,
|
|
ShapeGeometry,
|
|
SphereGeometry,
|
|
TetrahedronGeometry,
|
|
TorusGeometry,
|
|
TorusKnotGeometry,
|
|
TubeGeometry,
|
|
WireframeGeometry
|
|
});
|
|
ShadowMaterial = class ShadowMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isShadowMaterial = true;
|
|
this.type = "ShadowMaterial";
|
|
this.color = new Color(0);
|
|
this.transparent = true;
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.color.copy(source.color);
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
RawShaderMaterial = class RawShaderMaterial extends ShaderMaterial {
|
|
constructor(parameters) {
|
|
super(parameters);
|
|
this.isRawShaderMaterial = true;
|
|
this.type = "RawShaderMaterial";
|
|
}
|
|
};
|
|
MeshStandardMaterial = class MeshStandardMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshStandardMaterial = true;
|
|
this.type = "MeshStandardMaterial";
|
|
this.defines = { STANDARD: "" };
|
|
this.color = new Color(16777215);
|
|
this.roughness = 1;
|
|
this.metalness = 0;
|
|
this.map = null;
|
|
this.lightMap = null;
|
|
this.lightMapIntensity = 1;
|
|
this.aoMap = null;
|
|
this.aoMapIntensity = 1;
|
|
this.emissive = new Color(0);
|
|
this.emissiveIntensity = 1;
|
|
this.emissiveMap = null;
|
|
this.bumpMap = null;
|
|
this.bumpScale = 1;
|
|
this.normalMap = null;
|
|
this.normalMapType = TangentSpaceNormalMap;
|
|
this.normalScale = new Vector2(1, 1);
|
|
this.displacementMap = null;
|
|
this.displacementScale = 1;
|
|
this.displacementBias = 0;
|
|
this.roughnessMap = null;
|
|
this.metalnessMap = null;
|
|
this.alphaMap = null;
|
|
this.envMap = null;
|
|
this.envMapRotation = new Euler;
|
|
this.envMapIntensity = 1;
|
|
this.wireframe = false;
|
|
this.wireframeLinewidth = 1;
|
|
this.wireframeLinecap = "round";
|
|
this.wireframeLinejoin = "round";
|
|
this.flatShading = false;
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.defines = { STANDARD: "" };
|
|
this.color.copy(source.color);
|
|
this.roughness = source.roughness;
|
|
this.metalness = source.metalness;
|
|
this.map = source.map;
|
|
this.lightMap = source.lightMap;
|
|
this.lightMapIntensity = source.lightMapIntensity;
|
|
this.aoMap = source.aoMap;
|
|
this.aoMapIntensity = source.aoMapIntensity;
|
|
this.emissive.copy(source.emissive);
|
|
this.emissiveMap = source.emissiveMap;
|
|
this.emissiveIntensity = source.emissiveIntensity;
|
|
this.bumpMap = source.bumpMap;
|
|
this.bumpScale = source.bumpScale;
|
|
this.normalMap = source.normalMap;
|
|
this.normalMapType = source.normalMapType;
|
|
this.normalScale.copy(source.normalScale);
|
|
this.displacementMap = source.displacementMap;
|
|
this.displacementScale = source.displacementScale;
|
|
this.displacementBias = source.displacementBias;
|
|
this.roughnessMap = source.roughnessMap;
|
|
this.metalnessMap = source.metalnessMap;
|
|
this.alphaMap = source.alphaMap;
|
|
this.envMap = source.envMap;
|
|
this.envMapRotation.copy(source.envMapRotation);
|
|
this.envMapIntensity = source.envMapIntensity;
|
|
this.wireframe = source.wireframe;
|
|
this.wireframeLinewidth = source.wireframeLinewidth;
|
|
this.wireframeLinecap = source.wireframeLinecap;
|
|
this.wireframeLinejoin = source.wireframeLinejoin;
|
|
this.flatShading = source.flatShading;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
MeshPhysicalMaterial = class MeshPhysicalMaterial extends MeshStandardMaterial {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshPhysicalMaterial = true;
|
|
this.defines = {
|
|
STANDARD: "",
|
|
PHYSICAL: ""
|
|
};
|
|
this.type = "MeshPhysicalMaterial";
|
|
this.anisotropyRotation = 0;
|
|
this.anisotropyMap = null;
|
|
this.clearcoatMap = null;
|
|
this.clearcoatRoughness = 0;
|
|
this.clearcoatRoughnessMap = null;
|
|
this.clearcoatNormalScale = new Vector2(1, 1);
|
|
this.clearcoatNormalMap = null;
|
|
this.ior = 1.5;
|
|
Object.defineProperty(this, "reflectivity", {
|
|
get: function() {
|
|
return clamp(2.5 * (this.ior - 1) / (this.ior + 1), 0, 1);
|
|
},
|
|
set: function(reflectivity) {
|
|
this.ior = (1 + 0.4 * reflectivity) / (1 - 0.4 * reflectivity);
|
|
}
|
|
});
|
|
this.iridescenceMap = null;
|
|
this.iridescenceIOR = 1.3;
|
|
this.iridescenceThicknessRange = [100, 400];
|
|
this.iridescenceThicknessMap = null;
|
|
this.sheenColor = new Color(0);
|
|
this.sheenColorMap = null;
|
|
this.sheenRoughness = 1;
|
|
this.sheenRoughnessMap = null;
|
|
this.transmissionMap = null;
|
|
this.thickness = 0;
|
|
this.thicknessMap = null;
|
|
this.attenuationDistance = Infinity;
|
|
this.attenuationColor = new Color(1, 1, 1);
|
|
this.specularIntensity = 1;
|
|
this.specularIntensityMap = null;
|
|
this.specularColor = new Color(1, 1, 1);
|
|
this.specularColorMap = null;
|
|
this._anisotropy = 0;
|
|
this._clearcoat = 0;
|
|
this._dispersion = 0;
|
|
this._iridescence = 0;
|
|
this._sheen = 0;
|
|
this._transmission = 0;
|
|
this.setValues(parameters);
|
|
}
|
|
get anisotropy() {
|
|
return this._anisotropy;
|
|
}
|
|
set anisotropy(value) {
|
|
if (this._anisotropy > 0 !== value > 0) {
|
|
this.version++;
|
|
}
|
|
this._anisotropy = value;
|
|
}
|
|
get clearcoat() {
|
|
return this._clearcoat;
|
|
}
|
|
set clearcoat(value) {
|
|
if (this._clearcoat > 0 !== value > 0) {
|
|
this.version++;
|
|
}
|
|
this._clearcoat = value;
|
|
}
|
|
get iridescence() {
|
|
return this._iridescence;
|
|
}
|
|
set iridescence(value) {
|
|
if (this._iridescence > 0 !== value > 0) {
|
|
this.version++;
|
|
}
|
|
this._iridescence = value;
|
|
}
|
|
get dispersion() {
|
|
return this._dispersion;
|
|
}
|
|
set dispersion(value) {
|
|
if (this._dispersion > 0 !== value > 0) {
|
|
this.version++;
|
|
}
|
|
this._dispersion = value;
|
|
}
|
|
get sheen() {
|
|
return this._sheen;
|
|
}
|
|
set sheen(value) {
|
|
if (this._sheen > 0 !== value > 0) {
|
|
this.version++;
|
|
}
|
|
this._sheen = value;
|
|
}
|
|
get transmission() {
|
|
return this._transmission;
|
|
}
|
|
set transmission(value) {
|
|
if (this._transmission > 0 !== value > 0) {
|
|
this.version++;
|
|
}
|
|
this._transmission = value;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.defines = {
|
|
STANDARD: "",
|
|
PHYSICAL: ""
|
|
};
|
|
this.anisotropy = source.anisotropy;
|
|
this.anisotropyRotation = source.anisotropyRotation;
|
|
this.anisotropyMap = source.anisotropyMap;
|
|
this.clearcoat = source.clearcoat;
|
|
this.clearcoatMap = source.clearcoatMap;
|
|
this.clearcoatRoughness = source.clearcoatRoughness;
|
|
this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
|
|
this.clearcoatNormalMap = source.clearcoatNormalMap;
|
|
this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
|
|
this.dispersion = source.dispersion;
|
|
this.ior = source.ior;
|
|
this.iridescence = source.iridescence;
|
|
this.iridescenceMap = source.iridescenceMap;
|
|
this.iridescenceIOR = source.iridescenceIOR;
|
|
this.iridescenceThicknessRange = [...source.iridescenceThicknessRange];
|
|
this.iridescenceThicknessMap = source.iridescenceThicknessMap;
|
|
this.sheen = source.sheen;
|
|
this.sheenColor.copy(source.sheenColor);
|
|
this.sheenColorMap = source.sheenColorMap;
|
|
this.sheenRoughness = source.sheenRoughness;
|
|
this.sheenRoughnessMap = source.sheenRoughnessMap;
|
|
this.transmission = source.transmission;
|
|
this.transmissionMap = source.transmissionMap;
|
|
this.thickness = source.thickness;
|
|
this.thicknessMap = source.thicknessMap;
|
|
this.attenuationDistance = source.attenuationDistance;
|
|
this.attenuationColor.copy(source.attenuationColor);
|
|
this.specularIntensity = source.specularIntensity;
|
|
this.specularIntensityMap = source.specularIntensityMap;
|
|
this.specularColor.copy(source.specularColor);
|
|
this.specularColorMap = source.specularColorMap;
|
|
return this;
|
|
}
|
|
};
|
|
MeshPhongMaterial = class MeshPhongMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshPhongMaterial = true;
|
|
this.type = "MeshPhongMaterial";
|
|
this.color = new Color(16777215);
|
|
this.specular = new Color(1118481);
|
|
this.shininess = 30;
|
|
this.map = null;
|
|
this.lightMap = null;
|
|
this.lightMapIntensity = 1;
|
|
this.aoMap = null;
|
|
this.aoMapIntensity = 1;
|
|
this.emissive = new Color(0);
|
|
this.emissiveIntensity = 1;
|
|
this.emissiveMap = null;
|
|
this.bumpMap = null;
|
|
this.bumpScale = 1;
|
|
this.normalMap = null;
|
|
this.normalMapType = TangentSpaceNormalMap;
|
|
this.normalScale = new Vector2(1, 1);
|
|
this.displacementMap = null;
|
|
this.displacementScale = 1;
|
|
this.displacementBias = 0;
|
|
this.specularMap = null;
|
|
this.alphaMap = null;
|
|
this.envMap = null;
|
|
this.envMapRotation = new Euler;
|
|
this.combine = MultiplyOperation;
|
|
this.reflectivity = 1;
|
|
this.refractionRatio = 0.98;
|
|
this.wireframe = false;
|
|
this.wireframeLinewidth = 1;
|
|
this.wireframeLinecap = "round";
|
|
this.wireframeLinejoin = "round";
|
|
this.flatShading = false;
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.color.copy(source.color);
|
|
this.specular.copy(source.specular);
|
|
this.shininess = source.shininess;
|
|
this.map = source.map;
|
|
this.lightMap = source.lightMap;
|
|
this.lightMapIntensity = source.lightMapIntensity;
|
|
this.aoMap = source.aoMap;
|
|
this.aoMapIntensity = source.aoMapIntensity;
|
|
this.emissive.copy(source.emissive);
|
|
this.emissiveMap = source.emissiveMap;
|
|
this.emissiveIntensity = source.emissiveIntensity;
|
|
this.bumpMap = source.bumpMap;
|
|
this.bumpScale = source.bumpScale;
|
|
this.normalMap = source.normalMap;
|
|
this.normalMapType = source.normalMapType;
|
|
this.normalScale.copy(source.normalScale);
|
|
this.displacementMap = source.displacementMap;
|
|
this.displacementScale = source.displacementScale;
|
|
this.displacementBias = source.displacementBias;
|
|
this.specularMap = source.specularMap;
|
|
this.alphaMap = source.alphaMap;
|
|
this.envMap = source.envMap;
|
|
this.envMapRotation.copy(source.envMapRotation);
|
|
this.combine = source.combine;
|
|
this.reflectivity = source.reflectivity;
|
|
this.refractionRatio = source.refractionRatio;
|
|
this.wireframe = source.wireframe;
|
|
this.wireframeLinewidth = source.wireframeLinewidth;
|
|
this.wireframeLinecap = source.wireframeLinecap;
|
|
this.wireframeLinejoin = source.wireframeLinejoin;
|
|
this.flatShading = source.flatShading;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
MeshToonMaterial = class MeshToonMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshToonMaterial = true;
|
|
this.defines = { TOON: "" };
|
|
this.type = "MeshToonMaterial";
|
|
this.color = new Color(16777215);
|
|
this.map = null;
|
|
this.gradientMap = null;
|
|
this.lightMap = null;
|
|
this.lightMapIntensity = 1;
|
|
this.aoMap = null;
|
|
this.aoMapIntensity = 1;
|
|
this.emissive = new Color(0);
|
|
this.emissiveIntensity = 1;
|
|
this.emissiveMap = null;
|
|
this.bumpMap = null;
|
|
this.bumpScale = 1;
|
|
this.normalMap = null;
|
|
this.normalMapType = TangentSpaceNormalMap;
|
|
this.normalScale = new Vector2(1, 1);
|
|
this.displacementMap = null;
|
|
this.displacementScale = 1;
|
|
this.displacementBias = 0;
|
|
this.alphaMap = null;
|
|
this.wireframe = false;
|
|
this.wireframeLinewidth = 1;
|
|
this.wireframeLinecap = "round";
|
|
this.wireframeLinejoin = "round";
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.color.copy(source.color);
|
|
this.map = source.map;
|
|
this.gradientMap = source.gradientMap;
|
|
this.lightMap = source.lightMap;
|
|
this.lightMapIntensity = source.lightMapIntensity;
|
|
this.aoMap = source.aoMap;
|
|
this.aoMapIntensity = source.aoMapIntensity;
|
|
this.emissive.copy(source.emissive);
|
|
this.emissiveMap = source.emissiveMap;
|
|
this.emissiveIntensity = source.emissiveIntensity;
|
|
this.bumpMap = source.bumpMap;
|
|
this.bumpScale = source.bumpScale;
|
|
this.normalMap = source.normalMap;
|
|
this.normalMapType = source.normalMapType;
|
|
this.normalScale.copy(source.normalScale);
|
|
this.displacementMap = source.displacementMap;
|
|
this.displacementScale = source.displacementScale;
|
|
this.displacementBias = source.displacementBias;
|
|
this.alphaMap = source.alphaMap;
|
|
this.wireframe = source.wireframe;
|
|
this.wireframeLinewidth = source.wireframeLinewidth;
|
|
this.wireframeLinecap = source.wireframeLinecap;
|
|
this.wireframeLinejoin = source.wireframeLinejoin;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
MeshNormalMaterial = class MeshNormalMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshNormalMaterial = true;
|
|
this.type = "MeshNormalMaterial";
|
|
this.bumpMap = null;
|
|
this.bumpScale = 1;
|
|
this.normalMap = null;
|
|
this.normalMapType = TangentSpaceNormalMap;
|
|
this.normalScale = new Vector2(1, 1);
|
|
this.displacementMap = null;
|
|
this.displacementScale = 1;
|
|
this.displacementBias = 0;
|
|
this.wireframe = false;
|
|
this.wireframeLinewidth = 1;
|
|
this.flatShading = false;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.bumpMap = source.bumpMap;
|
|
this.bumpScale = source.bumpScale;
|
|
this.normalMap = source.normalMap;
|
|
this.normalMapType = source.normalMapType;
|
|
this.normalScale.copy(source.normalScale);
|
|
this.displacementMap = source.displacementMap;
|
|
this.displacementScale = source.displacementScale;
|
|
this.displacementBias = source.displacementBias;
|
|
this.wireframe = source.wireframe;
|
|
this.wireframeLinewidth = source.wireframeLinewidth;
|
|
this.flatShading = source.flatShading;
|
|
return this;
|
|
}
|
|
};
|
|
MeshLambertMaterial = class MeshLambertMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshLambertMaterial = true;
|
|
this.type = "MeshLambertMaterial";
|
|
this.color = new Color(16777215);
|
|
this.map = null;
|
|
this.lightMap = null;
|
|
this.lightMapIntensity = 1;
|
|
this.aoMap = null;
|
|
this.aoMapIntensity = 1;
|
|
this.emissive = new Color(0);
|
|
this.emissiveIntensity = 1;
|
|
this.emissiveMap = null;
|
|
this.bumpMap = null;
|
|
this.bumpScale = 1;
|
|
this.normalMap = null;
|
|
this.normalMapType = TangentSpaceNormalMap;
|
|
this.normalScale = new Vector2(1, 1);
|
|
this.displacementMap = null;
|
|
this.displacementScale = 1;
|
|
this.displacementBias = 0;
|
|
this.specularMap = null;
|
|
this.alphaMap = null;
|
|
this.envMap = null;
|
|
this.envMapRotation = new Euler;
|
|
this.combine = MultiplyOperation;
|
|
this.reflectivity = 1;
|
|
this.refractionRatio = 0.98;
|
|
this.wireframe = false;
|
|
this.wireframeLinewidth = 1;
|
|
this.wireframeLinecap = "round";
|
|
this.wireframeLinejoin = "round";
|
|
this.flatShading = false;
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.color.copy(source.color);
|
|
this.map = source.map;
|
|
this.lightMap = source.lightMap;
|
|
this.lightMapIntensity = source.lightMapIntensity;
|
|
this.aoMap = source.aoMap;
|
|
this.aoMapIntensity = source.aoMapIntensity;
|
|
this.emissive.copy(source.emissive);
|
|
this.emissiveMap = source.emissiveMap;
|
|
this.emissiveIntensity = source.emissiveIntensity;
|
|
this.bumpMap = source.bumpMap;
|
|
this.bumpScale = source.bumpScale;
|
|
this.normalMap = source.normalMap;
|
|
this.normalMapType = source.normalMapType;
|
|
this.normalScale.copy(source.normalScale);
|
|
this.displacementMap = source.displacementMap;
|
|
this.displacementScale = source.displacementScale;
|
|
this.displacementBias = source.displacementBias;
|
|
this.specularMap = source.specularMap;
|
|
this.alphaMap = source.alphaMap;
|
|
this.envMap = source.envMap;
|
|
this.envMapRotation.copy(source.envMapRotation);
|
|
this.combine = source.combine;
|
|
this.reflectivity = source.reflectivity;
|
|
this.refractionRatio = source.refractionRatio;
|
|
this.wireframe = source.wireframe;
|
|
this.wireframeLinewidth = source.wireframeLinewidth;
|
|
this.wireframeLinecap = source.wireframeLinecap;
|
|
this.wireframeLinejoin = source.wireframeLinejoin;
|
|
this.flatShading = source.flatShading;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
MeshDepthMaterial = class MeshDepthMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshDepthMaterial = true;
|
|
this.type = "MeshDepthMaterial";
|
|
this.depthPacking = BasicDepthPacking;
|
|
this.map = null;
|
|
this.alphaMap = null;
|
|
this.displacementMap = null;
|
|
this.displacementScale = 1;
|
|
this.displacementBias = 0;
|
|
this.wireframe = false;
|
|
this.wireframeLinewidth = 1;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.depthPacking = source.depthPacking;
|
|
this.map = source.map;
|
|
this.alphaMap = source.alphaMap;
|
|
this.displacementMap = source.displacementMap;
|
|
this.displacementScale = source.displacementScale;
|
|
this.displacementBias = source.displacementBias;
|
|
this.wireframe = source.wireframe;
|
|
this.wireframeLinewidth = source.wireframeLinewidth;
|
|
return this;
|
|
}
|
|
};
|
|
MeshDistanceMaterial = class MeshDistanceMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshDistanceMaterial = true;
|
|
this.type = "MeshDistanceMaterial";
|
|
this.map = null;
|
|
this.alphaMap = null;
|
|
this.displacementMap = null;
|
|
this.displacementScale = 1;
|
|
this.displacementBias = 0;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.map = source.map;
|
|
this.alphaMap = source.alphaMap;
|
|
this.displacementMap = source.displacementMap;
|
|
this.displacementScale = source.displacementScale;
|
|
this.displacementBias = source.displacementBias;
|
|
return this;
|
|
}
|
|
};
|
|
MeshMatcapMaterial = class MeshMatcapMaterial extends Material {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isMeshMatcapMaterial = true;
|
|
this.defines = { MATCAP: "" };
|
|
this.type = "MeshMatcapMaterial";
|
|
this.color = new Color(16777215);
|
|
this.matcap = null;
|
|
this.map = null;
|
|
this.bumpMap = null;
|
|
this.bumpScale = 1;
|
|
this.normalMap = null;
|
|
this.normalMapType = TangentSpaceNormalMap;
|
|
this.normalScale = new Vector2(1, 1);
|
|
this.displacementMap = null;
|
|
this.displacementScale = 1;
|
|
this.displacementBias = 0;
|
|
this.alphaMap = null;
|
|
this.flatShading = false;
|
|
this.fog = true;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.defines = { MATCAP: "" };
|
|
this.color.copy(source.color);
|
|
this.matcap = source.matcap;
|
|
this.map = source.map;
|
|
this.bumpMap = source.bumpMap;
|
|
this.bumpScale = source.bumpScale;
|
|
this.normalMap = source.normalMap;
|
|
this.normalMapType = source.normalMapType;
|
|
this.normalScale.copy(source.normalScale);
|
|
this.displacementMap = source.displacementMap;
|
|
this.displacementScale = source.displacementScale;
|
|
this.displacementBias = source.displacementBias;
|
|
this.alphaMap = source.alphaMap;
|
|
this.flatShading = source.flatShading;
|
|
this.fog = source.fog;
|
|
return this;
|
|
}
|
|
};
|
|
LineDashedMaterial = class LineDashedMaterial extends LineBasicMaterial {
|
|
constructor(parameters) {
|
|
super();
|
|
this.isLineDashedMaterial = true;
|
|
this.type = "LineDashedMaterial";
|
|
this.scale = 1;
|
|
this.dashSize = 3;
|
|
this.gapSize = 1;
|
|
this.setValues(parameters);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.scale = source.scale;
|
|
this.dashSize = source.dashSize;
|
|
this.gapSize = source.gapSize;
|
|
return this;
|
|
}
|
|
};
|
|
AnimationUtils = {
|
|
convertArray,
|
|
isTypedArray,
|
|
getKeyframeOrder,
|
|
sortedArray,
|
|
flattenJSON,
|
|
subclip,
|
|
makeClipAdditive
|
|
};
|
|
CubicInterpolant = class CubicInterpolant extends Interpolant {
|
|
constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
|
super(parameterPositions, sampleValues, sampleSize, resultBuffer);
|
|
this._weightPrev = -0;
|
|
this._offsetPrev = -0;
|
|
this._weightNext = -0;
|
|
this._offsetNext = -0;
|
|
this.DefaultSettings_ = {
|
|
endingStart: ZeroCurvatureEnding,
|
|
endingEnd: ZeroCurvatureEnding
|
|
};
|
|
}
|
|
intervalChanged_(i1, t0, t1) {
|
|
const pp = this.parameterPositions;
|
|
let iPrev = i1 - 2, iNext = i1 + 1, tPrev = pp[iPrev], tNext = pp[iNext];
|
|
if (tPrev === undefined) {
|
|
switch (this.getSettings_().endingStart) {
|
|
case ZeroSlopeEnding:
|
|
iPrev = i1;
|
|
tPrev = 2 * t0 - t1;
|
|
break;
|
|
case WrapAroundEnding:
|
|
iPrev = pp.length - 2;
|
|
tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
|
|
break;
|
|
default:
|
|
iPrev = i1;
|
|
tPrev = t1;
|
|
}
|
|
}
|
|
if (tNext === undefined) {
|
|
switch (this.getSettings_().endingEnd) {
|
|
case ZeroSlopeEnding:
|
|
iNext = i1;
|
|
tNext = 2 * t1 - t0;
|
|
break;
|
|
case WrapAroundEnding:
|
|
iNext = 1;
|
|
tNext = t1 + pp[1] - pp[0];
|
|
break;
|
|
default:
|
|
iNext = i1 - 1;
|
|
tNext = t0;
|
|
}
|
|
}
|
|
const halfDt = (t1 - t0) * 0.5, stride = this.valueSize;
|
|
this._weightPrev = halfDt / (t0 - tPrev);
|
|
this._weightNext = halfDt / (tNext - t1);
|
|
this._offsetPrev = iPrev * stride;
|
|
this._offsetNext = iNext * stride;
|
|
}
|
|
interpolate_(i1, t0, t, t1) {
|
|
const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, o1 = i1 * stride, o0 = o1 - stride, oP = this._offsetPrev, oN = this._offsetNext, wP = this._weightPrev, wN = this._weightNext, p = (t - t0) / (t1 - t0), pp = p * p, ppp = pp * p;
|
|
const sP = -wP * ppp + 2 * wP * pp - wP * p;
|
|
const s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
|
|
const s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
|
|
const sN = wN * ppp - wN * pp;
|
|
for (let i = 0;i !== stride; ++i) {
|
|
result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
LinearInterpolant = class LinearInterpolant extends Interpolant {
|
|
constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
|
super(parameterPositions, sampleValues, sampleSize, resultBuffer);
|
|
}
|
|
interpolate_(i1, t0, t, t1) {
|
|
const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, offset1 = i1 * stride, offset0 = offset1 - stride, weight1 = (t - t0) / (t1 - t0), weight0 = 1 - weight1;
|
|
for (let i = 0;i !== stride; ++i) {
|
|
result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
DiscreteInterpolant = class DiscreteInterpolant extends Interpolant {
|
|
constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
|
super(parameterPositions, sampleValues, sampleSize, resultBuffer);
|
|
}
|
|
interpolate_(i1) {
|
|
return this.copySampleValue_(i1 - 1);
|
|
}
|
|
};
|
|
KeyframeTrack.prototype.TimeBufferType = Float32Array;
|
|
KeyframeTrack.prototype.ValueBufferType = Float32Array;
|
|
KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
|
|
BooleanKeyframeTrack = class BooleanKeyframeTrack extends KeyframeTrack {
|
|
constructor(name, times, values) {
|
|
super(name, times, values);
|
|
}
|
|
};
|
|
BooleanKeyframeTrack.prototype.ValueTypeName = "bool";
|
|
BooleanKeyframeTrack.prototype.ValueBufferType = Array;
|
|
BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
|
|
BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
|
|
BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
|
|
ColorKeyframeTrack = class ColorKeyframeTrack extends KeyframeTrack {
|
|
};
|
|
ColorKeyframeTrack.prototype.ValueTypeName = "color";
|
|
NumberKeyframeTrack = class NumberKeyframeTrack extends KeyframeTrack {
|
|
};
|
|
NumberKeyframeTrack.prototype.ValueTypeName = "number";
|
|
QuaternionLinearInterpolant = class QuaternionLinearInterpolant extends Interpolant {
|
|
constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
|
super(parameterPositions, sampleValues, sampleSize, resultBuffer);
|
|
}
|
|
interpolate_(i1, t0, t, t1) {
|
|
const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, alpha = (t - t0) / (t1 - t0);
|
|
let offset = i1 * stride;
|
|
for (let end = offset + stride;offset !== end; offset += 4) {
|
|
Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
QuaternionKeyframeTrack = class QuaternionKeyframeTrack extends KeyframeTrack {
|
|
InterpolantFactoryMethodLinear(result) {
|
|
return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
|
|
}
|
|
};
|
|
QuaternionKeyframeTrack.prototype.ValueTypeName = "quaternion";
|
|
QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
|
|
StringKeyframeTrack = class StringKeyframeTrack extends KeyframeTrack {
|
|
constructor(name, times, values) {
|
|
super(name, times, values);
|
|
}
|
|
};
|
|
StringKeyframeTrack.prototype.ValueTypeName = "string";
|
|
StringKeyframeTrack.prototype.ValueBufferType = Array;
|
|
StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
|
|
StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
|
|
StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
|
|
VectorKeyframeTrack = class VectorKeyframeTrack extends KeyframeTrack {
|
|
};
|
|
VectorKeyframeTrack.prototype.ValueTypeName = "vector";
|
|
Cache = {
|
|
enabled: false,
|
|
files: {},
|
|
add: function(key, file) {
|
|
if (this.enabled === false)
|
|
return;
|
|
this.files[key] = file;
|
|
},
|
|
get: function(key) {
|
|
if (this.enabled === false)
|
|
return;
|
|
return this.files[key];
|
|
},
|
|
remove: function(key) {
|
|
delete this.files[key];
|
|
},
|
|
clear: function() {
|
|
this.files = {};
|
|
}
|
|
};
|
|
DefaultLoadingManager = /* @__PURE__ */ new LoadingManager;
|
|
Loader.DEFAULT_MATERIAL_NAME = "__DEFAULT";
|
|
loading = {};
|
|
HttpError = class HttpError extends Error {
|
|
constructor(message, response) {
|
|
super(message);
|
|
this.response = response;
|
|
}
|
|
};
|
|
FileLoader = class FileLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
if (url === undefined)
|
|
url = "";
|
|
if (this.path !== undefined)
|
|
url = this.path + url;
|
|
url = this.manager.resolveURL(url);
|
|
const cached = Cache.get(url);
|
|
if (cached !== undefined) {
|
|
this.manager.itemStart(url);
|
|
setTimeout(() => {
|
|
if (onLoad)
|
|
onLoad(cached);
|
|
this.manager.itemEnd(url);
|
|
}, 0);
|
|
return cached;
|
|
}
|
|
if (loading[url] !== undefined) {
|
|
loading[url].push({
|
|
onLoad,
|
|
onProgress,
|
|
onError
|
|
});
|
|
return;
|
|
}
|
|
loading[url] = [];
|
|
loading[url].push({
|
|
onLoad,
|
|
onProgress,
|
|
onError
|
|
});
|
|
const req = new Request(url, {
|
|
headers: new Headers(this.requestHeader),
|
|
credentials: this.withCredentials ? "include" : "same-origin"
|
|
});
|
|
const mimeType = this.mimeType;
|
|
const responseType = this.responseType;
|
|
fetch(req).then((response) => {
|
|
if (response.status === 200 || response.status === 0) {
|
|
if (response.status === 0) {
|
|
console.warn("THREE.FileLoader: HTTP Status 0 received.");
|
|
}
|
|
if (typeof ReadableStream === "undefined" || response.body === undefined || response.body.getReader === undefined) {
|
|
return response;
|
|
}
|
|
const callbacks = loading[url];
|
|
const reader = response.body.getReader();
|
|
const contentLength = response.headers.get("X-File-Size") || response.headers.get("Content-Length");
|
|
const total = contentLength ? parseInt(contentLength) : 0;
|
|
const lengthComputable = total !== 0;
|
|
let loaded = 0;
|
|
const stream = new ReadableStream({
|
|
start(controller) {
|
|
readData();
|
|
function readData() {
|
|
reader.read().then(({ done, value }) => {
|
|
if (done) {
|
|
controller.close();
|
|
} else {
|
|
loaded += value.byteLength;
|
|
const event = new ProgressEvent("progress", { lengthComputable, loaded, total });
|
|
for (let i = 0, il = callbacks.length;i < il; i++) {
|
|
const callback = callbacks[i];
|
|
if (callback.onProgress)
|
|
callback.onProgress(event);
|
|
}
|
|
controller.enqueue(value);
|
|
readData();
|
|
}
|
|
}, (e) => {
|
|
controller.error(e);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
return new Response(stream);
|
|
} else {
|
|
throw new HttpError(`fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`, response);
|
|
}
|
|
}).then((response) => {
|
|
switch (responseType) {
|
|
case "arraybuffer":
|
|
return response.arrayBuffer();
|
|
case "blob":
|
|
return response.blob();
|
|
case "document":
|
|
return response.text().then((text) => {
|
|
const parser = new DOMParser;
|
|
return parser.parseFromString(text, mimeType);
|
|
});
|
|
case "json":
|
|
return response.json();
|
|
default:
|
|
if (mimeType === undefined) {
|
|
return response.text();
|
|
} else {
|
|
const re = /charset="?([^;"\s]*)"?/i;
|
|
const exec = re.exec(mimeType);
|
|
const label = exec && exec[1] ? exec[1].toLowerCase() : undefined;
|
|
const decoder = new TextDecoder(label);
|
|
return response.arrayBuffer().then((ab) => decoder.decode(ab));
|
|
}
|
|
}
|
|
}).then((data) => {
|
|
Cache.add(url, data);
|
|
const callbacks = loading[url];
|
|
delete loading[url];
|
|
for (let i = 0, il = callbacks.length;i < il; i++) {
|
|
const callback = callbacks[i];
|
|
if (callback.onLoad)
|
|
callback.onLoad(data);
|
|
}
|
|
}).catch((err) => {
|
|
const callbacks = loading[url];
|
|
if (callbacks === undefined) {
|
|
this.manager.itemError(url);
|
|
throw err;
|
|
}
|
|
delete loading[url];
|
|
for (let i = 0, il = callbacks.length;i < il; i++) {
|
|
const callback = callbacks[i];
|
|
if (callback.onError)
|
|
callback.onError(err);
|
|
}
|
|
this.manager.itemError(url);
|
|
}).finally(() => {
|
|
this.manager.itemEnd(url);
|
|
});
|
|
this.manager.itemStart(url);
|
|
}
|
|
setResponseType(value) {
|
|
this.responseType = value;
|
|
return this;
|
|
}
|
|
setMimeType(value) {
|
|
this.mimeType = value;
|
|
return this;
|
|
}
|
|
};
|
|
AnimationLoader = class AnimationLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
const scope = this;
|
|
const loader = new FileLoader(this.manager);
|
|
loader.setPath(this.path);
|
|
loader.setRequestHeader(this.requestHeader);
|
|
loader.setWithCredentials(this.withCredentials);
|
|
loader.load(url, function(text) {
|
|
try {
|
|
onLoad(scope.parse(JSON.parse(text)));
|
|
} catch (e) {
|
|
if (onError) {
|
|
onError(e);
|
|
} else {
|
|
console.error(e);
|
|
}
|
|
scope.manager.itemError(url);
|
|
}
|
|
}, onProgress, onError);
|
|
}
|
|
parse(json) {
|
|
const animations = [];
|
|
for (let i = 0;i < json.length; i++) {
|
|
const clip = AnimationClip.parse(json[i]);
|
|
animations.push(clip);
|
|
}
|
|
return animations;
|
|
}
|
|
};
|
|
CompressedTextureLoader = class CompressedTextureLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
const scope = this;
|
|
const images = [];
|
|
const texture = new CompressedTexture;
|
|
const loader = new FileLoader(this.manager);
|
|
loader.setPath(this.path);
|
|
loader.setResponseType("arraybuffer");
|
|
loader.setRequestHeader(this.requestHeader);
|
|
loader.setWithCredentials(scope.withCredentials);
|
|
let loaded = 0;
|
|
function loadTexture(i) {
|
|
loader.load(url[i], function(buffer) {
|
|
const texDatas = scope.parse(buffer, true);
|
|
images[i] = {
|
|
width: texDatas.width,
|
|
height: texDatas.height,
|
|
format: texDatas.format,
|
|
mipmaps: texDatas.mipmaps
|
|
};
|
|
loaded += 1;
|
|
if (loaded === 6) {
|
|
if (texDatas.mipmapCount === 1)
|
|
texture.minFilter = LinearFilter;
|
|
texture.image = images;
|
|
texture.format = texDatas.format;
|
|
texture.needsUpdate = true;
|
|
if (onLoad)
|
|
onLoad(texture);
|
|
}
|
|
}, onProgress, onError);
|
|
}
|
|
if (Array.isArray(url)) {
|
|
for (let i = 0, il = url.length;i < il; ++i) {
|
|
loadTexture(i);
|
|
}
|
|
} else {
|
|
loader.load(url, function(buffer) {
|
|
const texDatas = scope.parse(buffer, true);
|
|
if (texDatas.isCubemap) {
|
|
const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
|
|
for (let f = 0;f < faces; f++) {
|
|
images[f] = { mipmaps: [] };
|
|
for (let i = 0;i < texDatas.mipmapCount; i++) {
|
|
images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + i]);
|
|
images[f].format = texDatas.format;
|
|
images[f].width = texDatas.width;
|
|
images[f].height = texDatas.height;
|
|
}
|
|
}
|
|
texture.image = images;
|
|
} else {
|
|
texture.image.width = texDatas.width;
|
|
texture.image.height = texDatas.height;
|
|
texture.mipmaps = texDatas.mipmaps;
|
|
}
|
|
if (texDatas.mipmapCount === 1) {
|
|
texture.minFilter = LinearFilter;
|
|
}
|
|
texture.format = texDatas.format;
|
|
texture.needsUpdate = true;
|
|
if (onLoad)
|
|
onLoad(texture);
|
|
}, onProgress, onError);
|
|
}
|
|
return texture;
|
|
}
|
|
};
|
|
ImageLoader = class ImageLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
if (this.path !== undefined)
|
|
url = this.path + url;
|
|
url = this.manager.resolveURL(url);
|
|
const scope = this;
|
|
const cached = Cache.get(url);
|
|
if (cached !== undefined) {
|
|
scope.manager.itemStart(url);
|
|
setTimeout(function() {
|
|
if (onLoad)
|
|
onLoad(cached);
|
|
scope.manager.itemEnd(url);
|
|
}, 0);
|
|
return cached;
|
|
}
|
|
const image = createElementNS("img");
|
|
function onImageLoad() {
|
|
removeEventListeners();
|
|
Cache.add(url, this);
|
|
if (onLoad)
|
|
onLoad(this);
|
|
scope.manager.itemEnd(url);
|
|
}
|
|
function onImageError(event) {
|
|
removeEventListeners();
|
|
if (onError)
|
|
onError(event);
|
|
scope.manager.itemError(url);
|
|
scope.manager.itemEnd(url);
|
|
}
|
|
function removeEventListeners() {
|
|
image.removeEventListener("load", onImageLoad, false);
|
|
image.removeEventListener("error", onImageError, false);
|
|
}
|
|
image.addEventListener("load", onImageLoad, false);
|
|
image.addEventListener("error", onImageError, false);
|
|
if (url.slice(0, 5) !== "data:") {
|
|
if (this.crossOrigin !== undefined)
|
|
image.crossOrigin = this.crossOrigin;
|
|
}
|
|
scope.manager.itemStart(url);
|
|
image.src = url;
|
|
return image;
|
|
}
|
|
};
|
|
CubeTextureLoader = class CubeTextureLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(urls, onLoad, onProgress, onError) {
|
|
const texture = new CubeTexture;
|
|
texture.colorSpace = SRGBColorSpace;
|
|
const loader = new ImageLoader(this.manager);
|
|
loader.setCrossOrigin(this.crossOrigin);
|
|
loader.setPath(this.path);
|
|
let loaded = 0;
|
|
function loadTexture(i) {
|
|
loader.load(urls[i], function(image) {
|
|
texture.images[i] = image;
|
|
loaded++;
|
|
if (loaded === 6) {
|
|
texture.needsUpdate = true;
|
|
if (onLoad)
|
|
onLoad(texture);
|
|
}
|
|
}, undefined, onError);
|
|
}
|
|
for (let i = 0;i < urls.length; ++i) {
|
|
loadTexture(i);
|
|
}
|
|
return texture;
|
|
}
|
|
};
|
|
DataTextureLoader = class DataTextureLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
const scope = this;
|
|
const texture = new DataTexture;
|
|
const loader = new FileLoader(this.manager);
|
|
loader.setResponseType("arraybuffer");
|
|
loader.setRequestHeader(this.requestHeader);
|
|
loader.setPath(this.path);
|
|
loader.setWithCredentials(scope.withCredentials);
|
|
loader.load(url, function(buffer) {
|
|
let texData;
|
|
try {
|
|
texData = scope.parse(buffer);
|
|
} catch (error) {
|
|
if (onError !== undefined) {
|
|
onError(error);
|
|
} else {
|
|
console.error(error);
|
|
return;
|
|
}
|
|
}
|
|
if (texData.image !== undefined) {
|
|
texture.image = texData.image;
|
|
} else if (texData.data !== undefined) {
|
|
texture.image.width = texData.width;
|
|
texture.image.height = texData.height;
|
|
texture.image.data = texData.data;
|
|
}
|
|
texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
|
|
texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
|
|
texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
|
|
texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
|
|
texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
|
|
if (texData.colorSpace !== undefined) {
|
|
texture.colorSpace = texData.colorSpace;
|
|
}
|
|
if (texData.flipY !== undefined) {
|
|
texture.flipY = texData.flipY;
|
|
}
|
|
if (texData.format !== undefined) {
|
|
texture.format = texData.format;
|
|
}
|
|
if (texData.type !== undefined) {
|
|
texture.type = texData.type;
|
|
}
|
|
if (texData.mipmaps !== undefined) {
|
|
texture.mipmaps = texData.mipmaps;
|
|
texture.minFilter = LinearMipmapLinearFilter;
|
|
}
|
|
if (texData.mipmapCount === 1) {
|
|
texture.minFilter = LinearFilter;
|
|
}
|
|
if (texData.generateMipmaps !== undefined) {
|
|
texture.generateMipmaps = texData.generateMipmaps;
|
|
}
|
|
texture.needsUpdate = true;
|
|
if (onLoad)
|
|
onLoad(texture, texData);
|
|
}, onProgress, onError);
|
|
return texture;
|
|
}
|
|
};
|
|
TextureLoader = class TextureLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
const texture = new Texture;
|
|
const loader = new ImageLoader(this.manager);
|
|
loader.setCrossOrigin(this.crossOrigin);
|
|
loader.setPath(this.path);
|
|
loader.load(url, function(image) {
|
|
texture.image = image;
|
|
texture.needsUpdate = true;
|
|
if (onLoad !== undefined) {
|
|
onLoad(texture);
|
|
}
|
|
}, onProgress, onError);
|
|
return texture;
|
|
}
|
|
};
|
|
Light = class Light extends Object3D {
|
|
constructor(color, intensity = 1) {
|
|
super();
|
|
this.isLight = true;
|
|
this.type = "Light";
|
|
this.color = new Color(color);
|
|
this.intensity = intensity;
|
|
}
|
|
dispose() {}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.color.copy(source.color);
|
|
this.intensity = source.intensity;
|
|
return this;
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
data.object.color = this.color.getHex();
|
|
data.object.intensity = this.intensity;
|
|
if (this.groundColor !== undefined)
|
|
data.object.groundColor = this.groundColor.getHex();
|
|
if (this.distance !== undefined)
|
|
data.object.distance = this.distance;
|
|
if (this.angle !== undefined)
|
|
data.object.angle = this.angle;
|
|
if (this.decay !== undefined)
|
|
data.object.decay = this.decay;
|
|
if (this.penumbra !== undefined)
|
|
data.object.penumbra = this.penumbra;
|
|
if (this.shadow !== undefined)
|
|
data.object.shadow = this.shadow.toJSON();
|
|
if (this.target !== undefined)
|
|
data.object.target = this.target.uuid;
|
|
return data;
|
|
}
|
|
};
|
|
HemisphereLight = class HemisphereLight extends Light {
|
|
constructor(skyColor, groundColor, intensity) {
|
|
super(skyColor, intensity);
|
|
this.isHemisphereLight = true;
|
|
this.type = "HemisphereLight";
|
|
this.position.copy(Object3D.DEFAULT_UP);
|
|
this.updateMatrix();
|
|
this.groundColor = new Color(groundColor);
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.groundColor.copy(source.groundColor);
|
|
return this;
|
|
}
|
|
};
|
|
_projScreenMatrix$1 = /* @__PURE__ */ new Matrix4;
|
|
_lightPositionWorld$1 = /* @__PURE__ */ new Vector3;
|
|
_lookTarget$1 = /* @__PURE__ */ new Vector3;
|
|
SpotLightShadow = class SpotLightShadow extends LightShadow {
|
|
constructor() {
|
|
super(new PerspectiveCamera(50, 1, 0.5, 500));
|
|
this.isSpotLightShadow = true;
|
|
this.focus = 1;
|
|
}
|
|
updateMatrices(light) {
|
|
const camera = this.camera;
|
|
const fov2 = RAD2DEG * 2 * light.angle * this.focus;
|
|
const aspect2 = this.mapSize.width / this.mapSize.height;
|
|
const far = light.distance || camera.far;
|
|
if (fov2 !== camera.fov || aspect2 !== camera.aspect || far !== camera.far) {
|
|
camera.fov = fov2;
|
|
camera.aspect = aspect2;
|
|
camera.far = far;
|
|
camera.updateProjectionMatrix();
|
|
}
|
|
super.updateMatrices(light);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.focus = source.focus;
|
|
return this;
|
|
}
|
|
};
|
|
SpotLight = class SpotLight extends Light {
|
|
constructor(color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 2) {
|
|
super(color, intensity);
|
|
this.isSpotLight = true;
|
|
this.type = "SpotLight";
|
|
this.position.copy(Object3D.DEFAULT_UP);
|
|
this.updateMatrix();
|
|
this.target = new Object3D;
|
|
this.distance = distance;
|
|
this.angle = angle;
|
|
this.penumbra = penumbra;
|
|
this.decay = decay;
|
|
this.map = null;
|
|
this.shadow = new SpotLightShadow;
|
|
}
|
|
get power() {
|
|
return this.intensity * Math.PI;
|
|
}
|
|
set power(power) {
|
|
this.intensity = power / Math.PI;
|
|
}
|
|
dispose() {
|
|
this.shadow.dispose();
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.distance = source.distance;
|
|
this.angle = source.angle;
|
|
this.penumbra = source.penumbra;
|
|
this.decay = source.decay;
|
|
this.target = source.target.clone();
|
|
this.shadow = source.shadow.clone();
|
|
return this;
|
|
}
|
|
};
|
|
_projScreenMatrix = /* @__PURE__ */ new Matrix4;
|
|
_lightPositionWorld = /* @__PURE__ */ new Vector3;
|
|
_lookTarget = /* @__PURE__ */ new Vector3;
|
|
PointLightShadow = class PointLightShadow extends LightShadow {
|
|
constructor() {
|
|
super(new PerspectiveCamera(90, 1, 0.5, 500));
|
|
this.isPointLightShadow = true;
|
|
this._frameExtents = new Vector2(4, 2);
|
|
this._viewportCount = 6;
|
|
this._viewports = [
|
|
new Vector4(2, 1, 1, 1),
|
|
new Vector4(0, 1, 1, 1),
|
|
new Vector4(3, 1, 1, 1),
|
|
new Vector4(1, 1, 1, 1),
|
|
new Vector4(3, 0, 1, 1),
|
|
new Vector4(1, 0, 1, 1)
|
|
];
|
|
this._cubeDirections = [
|
|
new Vector3(1, 0, 0),
|
|
new Vector3(-1, 0, 0),
|
|
new Vector3(0, 0, 1),
|
|
new Vector3(0, 0, -1),
|
|
new Vector3(0, 1, 0),
|
|
new Vector3(0, -1, 0)
|
|
];
|
|
this._cubeUps = [
|
|
new Vector3(0, 1, 0),
|
|
new Vector3(0, 1, 0),
|
|
new Vector3(0, 1, 0),
|
|
new Vector3(0, 1, 0),
|
|
new Vector3(0, 0, 1),
|
|
new Vector3(0, 0, -1)
|
|
];
|
|
}
|
|
updateMatrices(light, viewportIndex = 0) {
|
|
const camera = this.camera;
|
|
const shadowMatrix = this.matrix;
|
|
const far = light.distance || camera.far;
|
|
if (far !== camera.far) {
|
|
camera.far = far;
|
|
camera.updateProjectionMatrix();
|
|
}
|
|
_lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
|
|
camera.position.copy(_lightPositionWorld);
|
|
_lookTarget.copy(camera.position);
|
|
_lookTarget.add(this._cubeDirections[viewportIndex]);
|
|
camera.up.copy(this._cubeUps[viewportIndex]);
|
|
camera.lookAt(_lookTarget);
|
|
camera.updateMatrixWorld();
|
|
shadowMatrix.makeTranslation(-_lightPositionWorld.x, -_lightPositionWorld.y, -_lightPositionWorld.z);
|
|
_projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
this._frustum.setFromProjectionMatrix(_projScreenMatrix);
|
|
}
|
|
};
|
|
PointLight = class PointLight extends Light {
|
|
constructor(color, intensity, distance = 0, decay = 2) {
|
|
super(color, intensity);
|
|
this.isPointLight = true;
|
|
this.type = "PointLight";
|
|
this.distance = distance;
|
|
this.decay = decay;
|
|
this.shadow = new PointLightShadow;
|
|
}
|
|
get power() {
|
|
return this.intensity * 4 * Math.PI;
|
|
}
|
|
set power(power) {
|
|
this.intensity = power / (4 * Math.PI);
|
|
}
|
|
dispose() {
|
|
this.shadow.dispose();
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.distance = source.distance;
|
|
this.decay = source.decay;
|
|
this.shadow = source.shadow.clone();
|
|
return this;
|
|
}
|
|
};
|
|
OrthographicCamera = class OrthographicCamera extends Camera {
|
|
constructor(left = -1, right = 1, top = 1, bottom = -1, near = 0.1, far = 2000) {
|
|
super();
|
|
this.isOrthographicCamera = true;
|
|
this.type = "OrthographicCamera";
|
|
this.zoom = 1;
|
|
this.view = null;
|
|
this.left = left;
|
|
this.right = right;
|
|
this.top = top;
|
|
this.bottom = bottom;
|
|
this.near = near;
|
|
this.far = far;
|
|
this.updateProjectionMatrix();
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.left = source.left;
|
|
this.right = source.right;
|
|
this.top = source.top;
|
|
this.bottom = source.bottom;
|
|
this.near = source.near;
|
|
this.far = source.far;
|
|
this.zoom = source.zoom;
|
|
this.view = source.view === null ? null : Object.assign({}, source.view);
|
|
return this;
|
|
}
|
|
setViewOffset(fullWidth, fullHeight, x, y, width, height) {
|
|
if (this.view === null) {
|
|
this.view = {
|
|
enabled: true,
|
|
fullWidth: 1,
|
|
fullHeight: 1,
|
|
offsetX: 0,
|
|
offsetY: 0,
|
|
width: 1,
|
|
height: 1
|
|
};
|
|
}
|
|
this.view.enabled = true;
|
|
this.view.fullWidth = fullWidth;
|
|
this.view.fullHeight = fullHeight;
|
|
this.view.offsetX = x;
|
|
this.view.offsetY = y;
|
|
this.view.width = width;
|
|
this.view.height = height;
|
|
this.updateProjectionMatrix();
|
|
}
|
|
clearViewOffset() {
|
|
if (this.view !== null) {
|
|
this.view.enabled = false;
|
|
}
|
|
this.updateProjectionMatrix();
|
|
}
|
|
updateProjectionMatrix() {
|
|
const dx = (this.right - this.left) / (2 * this.zoom);
|
|
const dy = (this.top - this.bottom) / (2 * this.zoom);
|
|
const cx = (this.right + this.left) / 2;
|
|
const cy = (this.top + this.bottom) / 2;
|
|
let left = cx - dx;
|
|
let right = cx + dx;
|
|
let top = cy + dy;
|
|
let bottom = cy - dy;
|
|
if (this.view !== null && this.view.enabled) {
|
|
const scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
|
|
const scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
|
|
left += scaleW * this.view.offsetX;
|
|
right = left + scaleW * this.view.width;
|
|
top -= scaleH * this.view.offsetY;
|
|
bottom = top - scaleH * this.view.height;
|
|
}
|
|
this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far, this.coordinateSystem);
|
|
this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
data.object.zoom = this.zoom;
|
|
data.object.left = this.left;
|
|
data.object.right = this.right;
|
|
data.object.top = this.top;
|
|
data.object.bottom = this.bottom;
|
|
data.object.near = this.near;
|
|
data.object.far = this.far;
|
|
if (this.view !== null)
|
|
data.object.view = Object.assign({}, this.view);
|
|
return data;
|
|
}
|
|
};
|
|
DirectionalLightShadow = class DirectionalLightShadow extends LightShadow {
|
|
constructor() {
|
|
super(new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
|
|
this.isDirectionalLightShadow = true;
|
|
}
|
|
};
|
|
DirectionalLight = class DirectionalLight extends Light {
|
|
constructor(color, intensity) {
|
|
super(color, intensity);
|
|
this.isDirectionalLight = true;
|
|
this.type = "DirectionalLight";
|
|
this.position.copy(Object3D.DEFAULT_UP);
|
|
this.updateMatrix();
|
|
this.target = new Object3D;
|
|
this.shadow = new DirectionalLightShadow;
|
|
}
|
|
dispose() {
|
|
this.shadow.dispose();
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.target = source.target.clone();
|
|
this.shadow = source.shadow.clone();
|
|
return this;
|
|
}
|
|
};
|
|
AmbientLight = class AmbientLight extends Light {
|
|
constructor(color, intensity) {
|
|
super(color, intensity);
|
|
this.isAmbientLight = true;
|
|
this.type = "AmbientLight";
|
|
}
|
|
};
|
|
RectAreaLight = class RectAreaLight extends Light {
|
|
constructor(color, intensity, width = 10, height = 10) {
|
|
super(color, intensity);
|
|
this.isRectAreaLight = true;
|
|
this.type = "RectAreaLight";
|
|
this.width = width;
|
|
this.height = height;
|
|
}
|
|
get power() {
|
|
return this.intensity * this.width * this.height * Math.PI;
|
|
}
|
|
set power(power) {
|
|
this.intensity = power / (this.width * this.height * Math.PI);
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.width = source.width;
|
|
this.height = source.height;
|
|
return this;
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
data.object.width = this.width;
|
|
data.object.height = this.height;
|
|
return data;
|
|
}
|
|
};
|
|
LightProbe = class LightProbe extends Light {
|
|
constructor(sh = new SphericalHarmonics3, intensity = 1) {
|
|
super(undefined, intensity);
|
|
this.isLightProbe = true;
|
|
this.sh = sh;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.sh.copy(source.sh);
|
|
return this;
|
|
}
|
|
fromJSON(json) {
|
|
this.intensity = json.intensity;
|
|
this.sh.fromArray(json.sh);
|
|
return this;
|
|
}
|
|
toJSON(meta) {
|
|
const data = super.toJSON(meta);
|
|
data.object.sh = this.sh.toArray();
|
|
return data;
|
|
}
|
|
};
|
|
MaterialLoader = class MaterialLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
this.textures = {};
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
const scope = this;
|
|
const loader = new FileLoader(scope.manager);
|
|
loader.setPath(scope.path);
|
|
loader.setRequestHeader(scope.requestHeader);
|
|
loader.setWithCredentials(scope.withCredentials);
|
|
loader.load(url, function(text) {
|
|
try {
|
|
onLoad(scope.parse(JSON.parse(text)));
|
|
} catch (e) {
|
|
if (onError) {
|
|
onError(e);
|
|
} else {
|
|
console.error(e);
|
|
}
|
|
scope.manager.itemError(url);
|
|
}
|
|
}, onProgress, onError);
|
|
}
|
|
parse(json) {
|
|
const textures = this.textures;
|
|
function getTexture(name) {
|
|
if (textures[name] === undefined) {
|
|
console.warn("THREE.MaterialLoader: Undefined texture", name);
|
|
}
|
|
return textures[name];
|
|
}
|
|
const material = this.createMaterialFromType(json.type);
|
|
if (json.uuid !== undefined)
|
|
material.uuid = json.uuid;
|
|
if (json.name !== undefined)
|
|
material.name = json.name;
|
|
if (json.color !== undefined && material.color !== undefined)
|
|
material.color.setHex(json.color);
|
|
if (json.roughness !== undefined)
|
|
material.roughness = json.roughness;
|
|
if (json.metalness !== undefined)
|
|
material.metalness = json.metalness;
|
|
if (json.sheen !== undefined)
|
|
material.sheen = json.sheen;
|
|
if (json.sheenColor !== undefined)
|
|
material.sheenColor = new Color().setHex(json.sheenColor);
|
|
if (json.sheenRoughness !== undefined)
|
|
material.sheenRoughness = json.sheenRoughness;
|
|
if (json.emissive !== undefined && material.emissive !== undefined)
|
|
material.emissive.setHex(json.emissive);
|
|
if (json.specular !== undefined && material.specular !== undefined)
|
|
material.specular.setHex(json.specular);
|
|
if (json.specularIntensity !== undefined)
|
|
material.specularIntensity = json.specularIntensity;
|
|
if (json.specularColor !== undefined && material.specularColor !== undefined)
|
|
material.specularColor.setHex(json.specularColor);
|
|
if (json.shininess !== undefined)
|
|
material.shininess = json.shininess;
|
|
if (json.clearcoat !== undefined)
|
|
material.clearcoat = json.clearcoat;
|
|
if (json.clearcoatRoughness !== undefined)
|
|
material.clearcoatRoughness = json.clearcoatRoughness;
|
|
if (json.dispersion !== undefined)
|
|
material.dispersion = json.dispersion;
|
|
if (json.iridescence !== undefined)
|
|
material.iridescence = json.iridescence;
|
|
if (json.iridescenceIOR !== undefined)
|
|
material.iridescenceIOR = json.iridescenceIOR;
|
|
if (json.iridescenceThicknessRange !== undefined)
|
|
material.iridescenceThicknessRange = json.iridescenceThicknessRange;
|
|
if (json.transmission !== undefined)
|
|
material.transmission = json.transmission;
|
|
if (json.thickness !== undefined)
|
|
material.thickness = json.thickness;
|
|
if (json.attenuationDistance !== undefined)
|
|
material.attenuationDistance = json.attenuationDistance;
|
|
if (json.attenuationColor !== undefined && material.attenuationColor !== undefined)
|
|
material.attenuationColor.setHex(json.attenuationColor);
|
|
if (json.anisotropy !== undefined)
|
|
material.anisotropy = json.anisotropy;
|
|
if (json.anisotropyRotation !== undefined)
|
|
material.anisotropyRotation = json.anisotropyRotation;
|
|
if (json.fog !== undefined)
|
|
material.fog = json.fog;
|
|
if (json.flatShading !== undefined)
|
|
material.flatShading = json.flatShading;
|
|
if (json.blending !== undefined)
|
|
material.blending = json.blending;
|
|
if (json.combine !== undefined)
|
|
material.combine = json.combine;
|
|
if (json.side !== undefined)
|
|
material.side = json.side;
|
|
if (json.shadowSide !== undefined)
|
|
material.shadowSide = json.shadowSide;
|
|
if (json.opacity !== undefined)
|
|
material.opacity = json.opacity;
|
|
if (json.transparent !== undefined)
|
|
material.transparent = json.transparent;
|
|
if (json.alphaTest !== undefined)
|
|
material.alphaTest = json.alphaTest;
|
|
if (json.alphaHash !== undefined)
|
|
material.alphaHash = json.alphaHash;
|
|
if (json.depthFunc !== undefined)
|
|
material.depthFunc = json.depthFunc;
|
|
if (json.depthTest !== undefined)
|
|
material.depthTest = json.depthTest;
|
|
if (json.depthWrite !== undefined)
|
|
material.depthWrite = json.depthWrite;
|
|
if (json.colorWrite !== undefined)
|
|
material.colorWrite = json.colorWrite;
|
|
if (json.blendSrc !== undefined)
|
|
material.blendSrc = json.blendSrc;
|
|
if (json.blendDst !== undefined)
|
|
material.blendDst = json.blendDst;
|
|
if (json.blendEquation !== undefined)
|
|
material.blendEquation = json.blendEquation;
|
|
if (json.blendSrcAlpha !== undefined)
|
|
material.blendSrcAlpha = json.blendSrcAlpha;
|
|
if (json.blendDstAlpha !== undefined)
|
|
material.blendDstAlpha = json.blendDstAlpha;
|
|
if (json.blendEquationAlpha !== undefined)
|
|
material.blendEquationAlpha = json.blendEquationAlpha;
|
|
if (json.blendColor !== undefined && material.blendColor !== undefined)
|
|
material.blendColor.setHex(json.blendColor);
|
|
if (json.blendAlpha !== undefined)
|
|
material.blendAlpha = json.blendAlpha;
|
|
if (json.stencilWriteMask !== undefined)
|
|
material.stencilWriteMask = json.stencilWriteMask;
|
|
if (json.stencilFunc !== undefined)
|
|
material.stencilFunc = json.stencilFunc;
|
|
if (json.stencilRef !== undefined)
|
|
material.stencilRef = json.stencilRef;
|
|
if (json.stencilFuncMask !== undefined)
|
|
material.stencilFuncMask = json.stencilFuncMask;
|
|
if (json.stencilFail !== undefined)
|
|
material.stencilFail = json.stencilFail;
|
|
if (json.stencilZFail !== undefined)
|
|
material.stencilZFail = json.stencilZFail;
|
|
if (json.stencilZPass !== undefined)
|
|
material.stencilZPass = json.stencilZPass;
|
|
if (json.stencilWrite !== undefined)
|
|
material.stencilWrite = json.stencilWrite;
|
|
if (json.wireframe !== undefined)
|
|
material.wireframe = json.wireframe;
|
|
if (json.wireframeLinewidth !== undefined)
|
|
material.wireframeLinewidth = json.wireframeLinewidth;
|
|
if (json.wireframeLinecap !== undefined)
|
|
material.wireframeLinecap = json.wireframeLinecap;
|
|
if (json.wireframeLinejoin !== undefined)
|
|
material.wireframeLinejoin = json.wireframeLinejoin;
|
|
if (json.rotation !== undefined)
|
|
material.rotation = json.rotation;
|
|
if (json.linewidth !== undefined)
|
|
material.linewidth = json.linewidth;
|
|
if (json.dashSize !== undefined)
|
|
material.dashSize = json.dashSize;
|
|
if (json.gapSize !== undefined)
|
|
material.gapSize = json.gapSize;
|
|
if (json.scale !== undefined)
|
|
material.scale = json.scale;
|
|
if (json.polygonOffset !== undefined)
|
|
material.polygonOffset = json.polygonOffset;
|
|
if (json.polygonOffsetFactor !== undefined)
|
|
material.polygonOffsetFactor = json.polygonOffsetFactor;
|
|
if (json.polygonOffsetUnits !== undefined)
|
|
material.polygonOffsetUnits = json.polygonOffsetUnits;
|
|
if (json.dithering !== undefined)
|
|
material.dithering = json.dithering;
|
|
if (json.alphaToCoverage !== undefined)
|
|
material.alphaToCoverage = json.alphaToCoverage;
|
|
if (json.premultipliedAlpha !== undefined)
|
|
material.premultipliedAlpha = json.premultipliedAlpha;
|
|
if (json.forceSinglePass !== undefined)
|
|
material.forceSinglePass = json.forceSinglePass;
|
|
if (json.visible !== undefined)
|
|
material.visible = json.visible;
|
|
if (json.toneMapped !== undefined)
|
|
material.toneMapped = json.toneMapped;
|
|
if (json.userData !== undefined)
|
|
material.userData = json.userData;
|
|
if (json.vertexColors !== undefined) {
|
|
if (typeof json.vertexColors === "number") {
|
|
material.vertexColors = json.vertexColors > 0 ? true : false;
|
|
} else {
|
|
material.vertexColors = json.vertexColors;
|
|
}
|
|
}
|
|
if (json.uniforms !== undefined) {
|
|
for (const name in json.uniforms) {
|
|
const uniform = json.uniforms[name];
|
|
material.uniforms[name] = {};
|
|
switch (uniform.type) {
|
|
case "t":
|
|
material.uniforms[name].value = getTexture(uniform.value);
|
|
break;
|
|
case "c":
|
|
material.uniforms[name].value = new Color().setHex(uniform.value);
|
|
break;
|
|
case "v2":
|
|
material.uniforms[name].value = new Vector2().fromArray(uniform.value);
|
|
break;
|
|
case "v3":
|
|
material.uniforms[name].value = new Vector3().fromArray(uniform.value);
|
|
break;
|
|
case "v4":
|
|
material.uniforms[name].value = new Vector4().fromArray(uniform.value);
|
|
break;
|
|
case "m3":
|
|
material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
|
|
break;
|
|
case "m4":
|
|
material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
|
|
break;
|
|
default:
|
|
material.uniforms[name].value = uniform.value;
|
|
}
|
|
}
|
|
}
|
|
if (json.defines !== undefined)
|
|
material.defines = json.defines;
|
|
if (json.vertexShader !== undefined)
|
|
material.vertexShader = json.vertexShader;
|
|
if (json.fragmentShader !== undefined)
|
|
material.fragmentShader = json.fragmentShader;
|
|
if (json.glslVersion !== undefined)
|
|
material.glslVersion = json.glslVersion;
|
|
if (json.extensions !== undefined) {
|
|
for (const key in json.extensions) {
|
|
material.extensions[key] = json.extensions[key];
|
|
}
|
|
}
|
|
if (json.lights !== undefined)
|
|
material.lights = json.lights;
|
|
if (json.clipping !== undefined)
|
|
material.clipping = json.clipping;
|
|
if (json.size !== undefined)
|
|
material.size = json.size;
|
|
if (json.sizeAttenuation !== undefined)
|
|
material.sizeAttenuation = json.sizeAttenuation;
|
|
if (json.map !== undefined)
|
|
material.map = getTexture(json.map);
|
|
if (json.matcap !== undefined)
|
|
material.matcap = getTexture(json.matcap);
|
|
if (json.alphaMap !== undefined)
|
|
material.alphaMap = getTexture(json.alphaMap);
|
|
if (json.bumpMap !== undefined)
|
|
material.bumpMap = getTexture(json.bumpMap);
|
|
if (json.bumpScale !== undefined)
|
|
material.bumpScale = json.bumpScale;
|
|
if (json.normalMap !== undefined)
|
|
material.normalMap = getTexture(json.normalMap);
|
|
if (json.normalMapType !== undefined)
|
|
material.normalMapType = json.normalMapType;
|
|
if (json.normalScale !== undefined) {
|
|
let normalScale = json.normalScale;
|
|
if (Array.isArray(normalScale) === false) {
|
|
normalScale = [normalScale, normalScale];
|
|
}
|
|
material.normalScale = new Vector2().fromArray(normalScale);
|
|
}
|
|
if (json.displacementMap !== undefined)
|
|
material.displacementMap = getTexture(json.displacementMap);
|
|
if (json.displacementScale !== undefined)
|
|
material.displacementScale = json.displacementScale;
|
|
if (json.displacementBias !== undefined)
|
|
material.displacementBias = json.displacementBias;
|
|
if (json.roughnessMap !== undefined)
|
|
material.roughnessMap = getTexture(json.roughnessMap);
|
|
if (json.metalnessMap !== undefined)
|
|
material.metalnessMap = getTexture(json.metalnessMap);
|
|
if (json.emissiveMap !== undefined)
|
|
material.emissiveMap = getTexture(json.emissiveMap);
|
|
if (json.emissiveIntensity !== undefined)
|
|
material.emissiveIntensity = json.emissiveIntensity;
|
|
if (json.specularMap !== undefined)
|
|
material.specularMap = getTexture(json.specularMap);
|
|
if (json.specularIntensityMap !== undefined)
|
|
material.specularIntensityMap = getTexture(json.specularIntensityMap);
|
|
if (json.specularColorMap !== undefined)
|
|
material.specularColorMap = getTexture(json.specularColorMap);
|
|
if (json.envMap !== undefined)
|
|
material.envMap = getTexture(json.envMap);
|
|
if (json.envMapRotation !== undefined)
|
|
material.envMapRotation.fromArray(json.envMapRotation);
|
|
if (json.envMapIntensity !== undefined)
|
|
material.envMapIntensity = json.envMapIntensity;
|
|
if (json.reflectivity !== undefined)
|
|
material.reflectivity = json.reflectivity;
|
|
if (json.refractionRatio !== undefined)
|
|
material.refractionRatio = json.refractionRatio;
|
|
if (json.lightMap !== undefined)
|
|
material.lightMap = getTexture(json.lightMap);
|
|
if (json.lightMapIntensity !== undefined)
|
|
material.lightMapIntensity = json.lightMapIntensity;
|
|
if (json.aoMap !== undefined)
|
|
material.aoMap = getTexture(json.aoMap);
|
|
if (json.aoMapIntensity !== undefined)
|
|
material.aoMapIntensity = json.aoMapIntensity;
|
|
if (json.gradientMap !== undefined)
|
|
material.gradientMap = getTexture(json.gradientMap);
|
|
if (json.clearcoatMap !== undefined)
|
|
material.clearcoatMap = getTexture(json.clearcoatMap);
|
|
if (json.clearcoatRoughnessMap !== undefined)
|
|
material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
|
|
if (json.clearcoatNormalMap !== undefined)
|
|
material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
|
|
if (json.clearcoatNormalScale !== undefined)
|
|
material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
|
|
if (json.iridescenceMap !== undefined)
|
|
material.iridescenceMap = getTexture(json.iridescenceMap);
|
|
if (json.iridescenceThicknessMap !== undefined)
|
|
material.iridescenceThicknessMap = getTexture(json.iridescenceThicknessMap);
|
|
if (json.transmissionMap !== undefined)
|
|
material.transmissionMap = getTexture(json.transmissionMap);
|
|
if (json.thicknessMap !== undefined)
|
|
material.thicknessMap = getTexture(json.thicknessMap);
|
|
if (json.anisotropyMap !== undefined)
|
|
material.anisotropyMap = getTexture(json.anisotropyMap);
|
|
if (json.sheenColorMap !== undefined)
|
|
material.sheenColorMap = getTexture(json.sheenColorMap);
|
|
if (json.sheenRoughnessMap !== undefined)
|
|
material.sheenRoughnessMap = getTexture(json.sheenRoughnessMap);
|
|
return material;
|
|
}
|
|
setTextures(value) {
|
|
this.textures = value;
|
|
return this;
|
|
}
|
|
createMaterialFromType(type) {
|
|
return MaterialLoader.createMaterialFromType(type);
|
|
}
|
|
static createMaterialFromType(type) {
|
|
const materialLib = {
|
|
ShadowMaterial,
|
|
SpriteMaterial,
|
|
RawShaderMaterial,
|
|
ShaderMaterial,
|
|
PointsMaterial,
|
|
MeshPhysicalMaterial,
|
|
MeshStandardMaterial,
|
|
MeshPhongMaterial,
|
|
MeshToonMaterial,
|
|
MeshNormalMaterial,
|
|
MeshLambertMaterial,
|
|
MeshDepthMaterial,
|
|
MeshDistanceMaterial,
|
|
MeshBasicMaterial,
|
|
MeshMatcapMaterial,
|
|
LineDashedMaterial,
|
|
LineBasicMaterial,
|
|
Material
|
|
};
|
|
return new materialLib[type];
|
|
}
|
|
};
|
|
InstancedBufferGeometry = class InstancedBufferGeometry extends BufferGeometry {
|
|
constructor() {
|
|
super();
|
|
this.isInstancedBufferGeometry = true;
|
|
this.type = "InstancedBufferGeometry";
|
|
this.instanceCount = Infinity;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.instanceCount = source.instanceCount;
|
|
return this;
|
|
}
|
|
toJSON() {
|
|
const data = super.toJSON();
|
|
data.instanceCount = this.instanceCount;
|
|
data.isInstancedBufferGeometry = true;
|
|
return data;
|
|
}
|
|
};
|
|
BufferGeometryLoader = class BufferGeometryLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
const scope = this;
|
|
const loader = new FileLoader(scope.manager);
|
|
loader.setPath(scope.path);
|
|
loader.setRequestHeader(scope.requestHeader);
|
|
loader.setWithCredentials(scope.withCredentials);
|
|
loader.load(url, function(text) {
|
|
try {
|
|
onLoad(scope.parse(JSON.parse(text)));
|
|
} catch (e) {
|
|
if (onError) {
|
|
onError(e);
|
|
} else {
|
|
console.error(e);
|
|
}
|
|
scope.manager.itemError(url);
|
|
}
|
|
}, onProgress, onError);
|
|
}
|
|
parse(json) {
|
|
const interleavedBufferMap = {};
|
|
const arrayBufferMap = {};
|
|
function getInterleavedBuffer(json2, uuid) {
|
|
if (interleavedBufferMap[uuid] !== undefined)
|
|
return interleavedBufferMap[uuid];
|
|
const interleavedBuffers = json2.interleavedBuffers;
|
|
const interleavedBuffer = interleavedBuffers[uuid];
|
|
const buffer = getArrayBuffer(json2, interleavedBuffer.buffer);
|
|
const array = getTypedArray(interleavedBuffer.type, buffer);
|
|
const ib = new InterleavedBuffer(array, interleavedBuffer.stride);
|
|
ib.uuid = interleavedBuffer.uuid;
|
|
interleavedBufferMap[uuid] = ib;
|
|
return ib;
|
|
}
|
|
function getArrayBuffer(json2, uuid) {
|
|
if (arrayBufferMap[uuid] !== undefined)
|
|
return arrayBufferMap[uuid];
|
|
const arrayBuffers = json2.arrayBuffers;
|
|
const arrayBuffer = arrayBuffers[uuid];
|
|
const ab = new Uint32Array(arrayBuffer).buffer;
|
|
arrayBufferMap[uuid] = ab;
|
|
return ab;
|
|
}
|
|
const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry : new BufferGeometry;
|
|
const index = json.data.index;
|
|
if (index !== undefined) {
|
|
const typedArray = getTypedArray(index.type, index.array);
|
|
geometry.setIndex(new BufferAttribute(typedArray, 1));
|
|
}
|
|
const attributes = json.data.attributes;
|
|
for (const key in attributes) {
|
|
const attribute = attributes[key];
|
|
let bufferAttribute;
|
|
if (attribute.isInterleavedBufferAttribute) {
|
|
const interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
|
|
bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
|
|
} else {
|
|
const typedArray = getTypedArray(attribute.type, attribute.array);
|
|
const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
|
|
bufferAttribute = new bufferAttributeConstr(typedArray, attribute.itemSize, attribute.normalized);
|
|
}
|
|
if (attribute.name !== undefined)
|
|
bufferAttribute.name = attribute.name;
|
|
if (attribute.usage !== undefined)
|
|
bufferAttribute.setUsage(attribute.usage);
|
|
geometry.setAttribute(key, bufferAttribute);
|
|
}
|
|
const morphAttributes = json.data.morphAttributes;
|
|
if (morphAttributes) {
|
|
for (const key in morphAttributes) {
|
|
const attributeArray = morphAttributes[key];
|
|
const array = [];
|
|
for (let i = 0, il = attributeArray.length;i < il; i++) {
|
|
const attribute = attributeArray[i];
|
|
let bufferAttribute;
|
|
if (attribute.isInterleavedBufferAttribute) {
|
|
const interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
|
|
bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
|
|
} else {
|
|
const typedArray = getTypedArray(attribute.type, attribute.array);
|
|
bufferAttribute = new BufferAttribute(typedArray, attribute.itemSize, attribute.normalized);
|
|
}
|
|
if (attribute.name !== undefined)
|
|
bufferAttribute.name = attribute.name;
|
|
array.push(bufferAttribute);
|
|
}
|
|
geometry.morphAttributes[key] = array;
|
|
}
|
|
}
|
|
const morphTargetsRelative = json.data.morphTargetsRelative;
|
|
if (morphTargetsRelative) {
|
|
geometry.morphTargetsRelative = true;
|
|
}
|
|
const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
|
|
if (groups !== undefined) {
|
|
for (let i = 0, n = groups.length;i !== n; ++i) {
|
|
const group = groups[i];
|
|
geometry.addGroup(group.start, group.count, group.materialIndex);
|
|
}
|
|
}
|
|
const boundingSphere = json.data.boundingSphere;
|
|
if (boundingSphere !== undefined) {
|
|
const center = new Vector3;
|
|
if (boundingSphere.center !== undefined) {
|
|
center.fromArray(boundingSphere.center);
|
|
}
|
|
geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
|
|
}
|
|
if (json.name)
|
|
geometry.name = json.name;
|
|
if (json.userData)
|
|
geometry.userData = json.userData;
|
|
return geometry;
|
|
}
|
|
};
|
|
ObjectLoader = class ObjectLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
const scope = this;
|
|
const path = this.path === "" ? LoaderUtils.extractUrlBase(url) : this.path;
|
|
this.resourcePath = this.resourcePath || path;
|
|
const loader = new FileLoader(this.manager);
|
|
loader.setPath(this.path);
|
|
loader.setRequestHeader(this.requestHeader);
|
|
loader.setWithCredentials(this.withCredentials);
|
|
loader.load(url, function(text) {
|
|
let json = null;
|
|
try {
|
|
json = JSON.parse(text);
|
|
} catch (error) {
|
|
if (onError !== undefined)
|
|
onError(error);
|
|
console.error("THREE:ObjectLoader: Can't parse " + url + ".", error.message);
|
|
return;
|
|
}
|
|
const metadata = json.metadata;
|
|
if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === "geometry") {
|
|
if (onError !== undefined)
|
|
onError(new Error("THREE.ObjectLoader: Can't load " + url));
|
|
console.error("THREE.ObjectLoader: Can't load " + url);
|
|
return;
|
|
}
|
|
scope.parse(json, onLoad);
|
|
}, onProgress, onError);
|
|
}
|
|
async loadAsync(url, onProgress) {
|
|
const scope = this;
|
|
const path = this.path === "" ? LoaderUtils.extractUrlBase(url) : this.path;
|
|
this.resourcePath = this.resourcePath || path;
|
|
const loader = new FileLoader(this.manager);
|
|
loader.setPath(this.path);
|
|
loader.setRequestHeader(this.requestHeader);
|
|
loader.setWithCredentials(this.withCredentials);
|
|
const text = await loader.loadAsync(url, onProgress);
|
|
const json = JSON.parse(text);
|
|
const metadata = json.metadata;
|
|
if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === "geometry") {
|
|
throw new Error("THREE.ObjectLoader: Can't load " + url);
|
|
}
|
|
return await scope.parseAsync(json);
|
|
}
|
|
parse(json, onLoad) {
|
|
const animations = this.parseAnimations(json.animations);
|
|
const shapes = this.parseShapes(json.shapes);
|
|
const geometries = this.parseGeometries(json.geometries, shapes);
|
|
const images = this.parseImages(json.images, function() {
|
|
if (onLoad !== undefined)
|
|
onLoad(object);
|
|
});
|
|
const textures = this.parseTextures(json.textures, images);
|
|
const materials = this.parseMaterials(json.materials, textures);
|
|
const object = this.parseObject(json.object, geometries, materials, textures, animations);
|
|
const skeletons = this.parseSkeletons(json.skeletons, object);
|
|
this.bindSkeletons(object, skeletons);
|
|
this.bindLightTargets(object);
|
|
if (onLoad !== undefined) {
|
|
let hasImages = false;
|
|
for (const uuid in images) {
|
|
if (images[uuid].data instanceof HTMLImageElement) {
|
|
hasImages = true;
|
|
break;
|
|
}
|
|
}
|
|
if (hasImages === false)
|
|
onLoad(object);
|
|
}
|
|
return object;
|
|
}
|
|
async parseAsync(json) {
|
|
const animations = this.parseAnimations(json.animations);
|
|
const shapes = this.parseShapes(json.shapes);
|
|
const geometries = this.parseGeometries(json.geometries, shapes);
|
|
const images = await this.parseImagesAsync(json.images);
|
|
const textures = this.parseTextures(json.textures, images);
|
|
const materials = this.parseMaterials(json.materials, textures);
|
|
const object = this.parseObject(json.object, geometries, materials, textures, animations);
|
|
const skeletons = this.parseSkeletons(json.skeletons, object);
|
|
this.bindSkeletons(object, skeletons);
|
|
this.bindLightTargets(object);
|
|
return object;
|
|
}
|
|
parseShapes(json) {
|
|
const shapes = {};
|
|
if (json !== undefined) {
|
|
for (let i = 0, l = json.length;i < l; i++) {
|
|
const shape = new Shape().fromJSON(json[i]);
|
|
shapes[shape.uuid] = shape;
|
|
}
|
|
}
|
|
return shapes;
|
|
}
|
|
parseSkeletons(json, object) {
|
|
const skeletons = {};
|
|
const bones = {};
|
|
object.traverse(function(child) {
|
|
if (child.isBone)
|
|
bones[child.uuid] = child;
|
|
});
|
|
if (json !== undefined) {
|
|
for (let i = 0, l = json.length;i < l; i++) {
|
|
const skeleton = new Skeleton().fromJSON(json[i], bones);
|
|
skeletons[skeleton.uuid] = skeleton;
|
|
}
|
|
}
|
|
return skeletons;
|
|
}
|
|
parseGeometries(json, shapes) {
|
|
const geometries = {};
|
|
if (json !== undefined) {
|
|
const bufferGeometryLoader = new BufferGeometryLoader;
|
|
for (let i = 0, l = json.length;i < l; i++) {
|
|
let geometry;
|
|
const data = json[i];
|
|
switch (data.type) {
|
|
case "BufferGeometry":
|
|
case "InstancedBufferGeometry":
|
|
geometry = bufferGeometryLoader.parse(data);
|
|
break;
|
|
case "Geometry":
|
|
if ("THREE" in window && "LegacyJSONLoader" in THREE) {
|
|
var geometryLoader = new THREE.LegacyJSONLoader;
|
|
geometry = geometryLoader.parse(data, this.resourcePath).geometry;
|
|
} else {
|
|
console.error('THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".');
|
|
}
|
|
break;
|
|
default:
|
|
if (data.type in Geometries) {
|
|
geometry = Geometries[data.type].fromJSON(data, shapes);
|
|
} else {
|
|
console.warn(`THREE.ObjectLoader: Unsupported geometry type "${data.type}"`);
|
|
}
|
|
}
|
|
geometry.uuid = data.uuid;
|
|
if (data.name !== undefined)
|
|
geometry.name = data.name;
|
|
if (data.userData !== undefined)
|
|
geometry.userData = data.userData;
|
|
geometries[data.uuid] = geometry;
|
|
}
|
|
}
|
|
return geometries;
|
|
}
|
|
parseMaterials(json, textures) {
|
|
const cache = {};
|
|
const materials = {};
|
|
if (json !== undefined) {
|
|
const loader = new MaterialLoader;
|
|
loader.setTextures(textures);
|
|
for (let i = 0, l = json.length;i < l; i++) {
|
|
const data = json[i];
|
|
if (cache[data.uuid] === undefined) {
|
|
cache[data.uuid] = loader.parse(data);
|
|
}
|
|
materials[data.uuid] = cache[data.uuid];
|
|
}
|
|
}
|
|
return materials;
|
|
}
|
|
parseAnimations(json) {
|
|
const animations = {};
|
|
if (json !== undefined) {
|
|
for (let i = 0;i < json.length; i++) {
|
|
const data = json[i];
|
|
const clip = AnimationClip.parse(data);
|
|
animations[clip.uuid] = clip;
|
|
}
|
|
}
|
|
return animations;
|
|
}
|
|
parseImages(json, onLoad) {
|
|
const scope = this;
|
|
const images = {};
|
|
let loader;
|
|
function loadImage(url) {
|
|
scope.manager.itemStart(url);
|
|
return loader.load(url, function() {
|
|
scope.manager.itemEnd(url);
|
|
}, undefined, function() {
|
|
scope.manager.itemError(url);
|
|
scope.manager.itemEnd(url);
|
|
});
|
|
}
|
|
function deserializeImage(image) {
|
|
if (typeof image === "string") {
|
|
const url = image;
|
|
const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
|
|
return loadImage(path);
|
|
} else {
|
|
if (image.data) {
|
|
return {
|
|
data: getTypedArray(image.type, image.data),
|
|
width: image.width,
|
|
height: image.height
|
|
};
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
if (json !== undefined && json.length > 0) {
|
|
const manager = new LoadingManager(onLoad);
|
|
loader = new ImageLoader(manager);
|
|
loader.setCrossOrigin(this.crossOrigin);
|
|
for (let i = 0, il = json.length;i < il; i++) {
|
|
const image = json[i];
|
|
const url = image.url;
|
|
if (Array.isArray(url)) {
|
|
const imageArray = [];
|
|
for (let j = 0, jl = url.length;j < jl; j++) {
|
|
const currentUrl = url[j];
|
|
const deserializedImage = deserializeImage(currentUrl);
|
|
if (deserializedImage !== null) {
|
|
if (deserializedImage instanceof HTMLImageElement) {
|
|
imageArray.push(deserializedImage);
|
|
} else {
|
|
imageArray.push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
|
|
}
|
|
}
|
|
}
|
|
images[image.uuid] = new Source(imageArray);
|
|
} else {
|
|
const deserializedImage = deserializeImage(image.url);
|
|
images[image.uuid] = new Source(deserializedImage);
|
|
}
|
|
}
|
|
}
|
|
return images;
|
|
}
|
|
async parseImagesAsync(json) {
|
|
const scope = this;
|
|
const images = {};
|
|
let loader;
|
|
async function deserializeImage(image) {
|
|
if (typeof image === "string") {
|
|
const url = image;
|
|
const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
|
|
return await loader.loadAsync(path);
|
|
} else {
|
|
if (image.data) {
|
|
return {
|
|
data: getTypedArray(image.type, image.data),
|
|
width: image.width,
|
|
height: image.height
|
|
};
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
if (json !== undefined && json.length > 0) {
|
|
loader = new ImageLoader(this.manager);
|
|
loader.setCrossOrigin(this.crossOrigin);
|
|
for (let i = 0, il = json.length;i < il; i++) {
|
|
const image = json[i];
|
|
const url = image.url;
|
|
if (Array.isArray(url)) {
|
|
const imageArray = [];
|
|
for (let j = 0, jl = url.length;j < jl; j++) {
|
|
const currentUrl = url[j];
|
|
const deserializedImage = await deserializeImage(currentUrl);
|
|
if (deserializedImage !== null) {
|
|
if (deserializedImage instanceof HTMLImageElement) {
|
|
imageArray.push(deserializedImage);
|
|
} else {
|
|
imageArray.push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
|
|
}
|
|
}
|
|
}
|
|
images[image.uuid] = new Source(imageArray);
|
|
} else {
|
|
const deserializedImage = await deserializeImage(image.url);
|
|
images[image.uuid] = new Source(deserializedImage);
|
|
}
|
|
}
|
|
}
|
|
return images;
|
|
}
|
|
parseTextures(json, images) {
|
|
function parseConstant(value, type) {
|
|
if (typeof value === "number")
|
|
return value;
|
|
console.warn("THREE.ObjectLoader.parseTexture: Constant should be in numeric form.", value);
|
|
return type[value];
|
|
}
|
|
const textures = {};
|
|
if (json !== undefined) {
|
|
for (let i = 0, l = json.length;i < l; i++) {
|
|
const data = json[i];
|
|
if (data.image === undefined) {
|
|
console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
|
|
}
|
|
if (images[data.image] === undefined) {
|
|
console.warn("THREE.ObjectLoader: Undefined image", data.image);
|
|
}
|
|
const source = images[data.image];
|
|
const image = source.data;
|
|
let texture;
|
|
if (Array.isArray(image)) {
|
|
texture = new CubeTexture;
|
|
if (image.length === 6)
|
|
texture.needsUpdate = true;
|
|
} else {
|
|
if (image && image.data) {
|
|
texture = new DataTexture;
|
|
} else {
|
|
texture = new Texture;
|
|
}
|
|
if (image)
|
|
texture.needsUpdate = true;
|
|
}
|
|
texture.source = source;
|
|
texture.uuid = data.uuid;
|
|
if (data.name !== undefined)
|
|
texture.name = data.name;
|
|
if (data.mapping !== undefined)
|
|
texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
|
|
if (data.channel !== undefined)
|
|
texture.channel = data.channel;
|
|
if (data.offset !== undefined)
|
|
texture.offset.fromArray(data.offset);
|
|
if (data.repeat !== undefined)
|
|
texture.repeat.fromArray(data.repeat);
|
|
if (data.center !== undefined)
|
|
texture.center.fromArray(data.center);
|
|
if (data.rotation !== undefined)
|
|
texture.rotation = data.rotation;
|
|
if (data.wrap !== undefined) {
|
|
texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
|
|
texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
|
|
}
|
|
if (data.format !== undefined)
|
|
texture.format = data.format;
|
|
if (data.internalFormat !== undefined)
|
|
texture.internalFormat = data.internalFormat;
|
|
if (data.type !== undefined)
|
|
texture.type = data.type;
|
|
if (data.colorSpace !== undefined)
|
|
texture.colorSpace = data.colorSpace;
|
|
if (data.minFilter !== undefined)
|
|
texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
|
|
if (data.magFilter !== undefined)
|
|
texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
|
|
if (data.anisotropy !== undefined)
|
|
texture.anisotropy = data.anisotropy;
|
|
if (data.flipY !== undefined)
|
|
texture.flipY = data.flipY;
|
|
if (data.generateMipmaps !== undefined)
|
|
texture.generateMipmaps = data.generateMipmaps;
|
|
if (data.premultiplyAlpha !== undefined)
|
|
texture.premultiplyAlpha = data.premultiplyAlpha;
|
|
if (data.unpackAlignment !== undefined)
|
|
texture.unpackAlignment = data.unpackAlignment;
|
|
if (data.compareFunction !== undefined)
|
|
texture.compareFunction = data.compareFunction;
|
|
if (data.userData !== undefined)
|
|
texture.userData = data.userData;
|
|
textures[data.uuid] = texture;
|
|
}
|
|
}
|
|
return textures;
|
|
}
|
|
parseObject(data, geometries, materials, textures, animations) {
|
|
let object;
|
|
function getGeometry(name) {
|
|
if (geometries[name] === undefined) {
|
|
console.warn("THREE.ObjectLoader: Undefined geometry", name);
|
|
}
|
|
return geometries[name];
|
|
}
|
|
function getMaterial(name) {
|
|
if (name === undefined)
|
|
return;
|
|
if (Array.isArray(name)) {
|
|
const array = [];
|
|
for (let i = 0, l = name.length;i < l; i++) {
|
|
const uuid = name[i];
|
|
if (materials[uuid] === undefined) {
|
|
console.warn("THREE.ObjectLoader: Undefined material", uuid);
|
|
}
|
|
array.push(materials[uuid]);
|
|
}
|
|
return array;
|
|
}
|
|
if (materials[name] === undefined) {
|
|
console.warn("THREE.ObjectLoader: Undefined material", name);
|
|
}
|
|
return materials[name];
|
|
}
|
|
function getTexture(uuid) {
|
|
if (textures[uuid] === undefined) {
|
|
console.warn("THREE.ObjectLoader: Undefined texture", uuid);
|
|
}
|
|
return textures[uuid];
|
|
}
|
|
let geometry, material;
|
|
switch (data.type) {
|
|
case "Scene":
|
|
object = new Scene;
|
|
if (data.background !== undefined) {
|
|
if (Number.isInteger(data.background)) {
|
|
object.background = new Color(data.background);
|
|
} else {
|
|
object.background = getTexture(data.background);
|
|
}
|
|
}
|
|
if (data.environment !== undefined) {
|
|
object.environment = getTexture(data.environment);
|
|
}
|
|
if (data.fog !== undefined) {
|
|
if (data.fog.type === "Fog") {
|
|
object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
|
|
} else if (data.fog.type === "FogExp2") {
|
|
object.fog = new FogExp2(data.fog.color, data.fog.density);
|
|
}
|
|
if (data.fog.name !== "") {
|
|
object.fog.name = data.fog.name;
|
|
}
|
|
}
|
|
if (data.backgroundBlurriness !== undefined)
|
|
object.backgroundBlurriness = data.backgroundBlurriness;
|
|
if (data.backgroundIntensity !== undefined)
|
|
object.backgroundIntensity = data.backgroundIntensity;
|
|
if (data.backgroundRotation !== undefined)
|
|
object.backgroundRotation.fromArray(data.backgroundRotation);
|
|
if (data.environmentIntensity !== undefined)
|
|
object.environmentIntensity = data.environmentIntensity;
|
|
if (data.environmentRotation !== undefined)
|
|
object.environmentRotation.fromArray(data.environmentRotation);
|
|
break;
|
|
case "PerspectiveCamera":
|
|
object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
|
|
if (data.focus !== undefined)
|
|
object.focus = data.focus;
|
|
if (data.zoom !== undefined)
|
|
object.zoom = data.zoom;
|
|
if (data.filmGauge !== undefined)
|
|
object.filmGauge = data.filmGauge;
|
|
if (data.filmOffset !== undefined)
|
|
object.filmOffset = data.filmOffset;
|
|
if (data.view !== undefined)
|
|
object.view = Object.assign({}, data.view);
|
|
break;
|
|
case "OrthographicCamera":
|
|
object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
|
|
if (data.zoom !== undefined)
|
|
object.zoom = data.zoom;
|
|
if (data.view !== undefined)
|
|
object.view = Object.assign({}, data.view);
|
|
break;
|
|
case "AmbientLight":
|
|
object = new AmbientLight(data.color, data.intensity);
|
|
break;
|
|
case "DirectionalLight":
|
|
object = new DirectionalLight(data.color, data.intensity);
|
|
object.target = data.target || "";
|
|
break;
|
|
case "PointLight":
|
|
object = new PointLight(data.color, data.intensity, data.distance, data.decay);
|
|
break;
|
|
case "RectAreaLight":
|
|
object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
|
|
break;
|
|
case "SpotLight":
|
|
object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
|
|
object.target = data.target || "";
|
|
break;
|
|
case "HemisphereLight":
|
|
object = new HemisphereLight(data.color, data.groundColor, data.intensity);
|
|
break;
|
|
case "LightProbe":
|
|
object = new LightProbe().fromJSON(data);
|
|
break;
|
|
case "SkinnedMesh":
|
|
geometry = getGeometry(data.geometry);
|
|
material = getMaterial(data.material);
|
|
object = new SkinnedMesh(geometry, material);
|
|
if (data.bindMode !== undefined)
|
|
object.bindMode = data.bindMode;
|
|
if (data.bindMatrix !== undefined)
|
|
object.bindMatrix.fromArray(data.bindMatrix);
|
|
if (data.skeleton !== undefined)
|
|
object.skeleton = data.skeleton;
|
|
break;
|
|
case "Mesh":
|
|
geometry = getGeometry(data.geometry);
|
|
material = getMaterial(data.material);
|
|
object = new Mesh(geometry, material);
|
|
break;
|
|
case "InstancedMesh":
|
|
geometry = getGeometry(data.geometry);
|
|
material = getMaterial(data.material);
|
|
const count = data.count;
|
|
const instanceMatrix = data.instanceMatrix;
|
|
const instanceColor = data.instanceColor;
|
|
object = new InstancedMesh(geometry, material, count);
|
|
object.instanceMatrix = new InstancedBufferAttribute(new Float32Array(instanceMatrix.array), 16);
|
|
if (instanceColor !== undefined)
|
|
object.instanceColor = new InstancedBufferAttribute(new Float32Array(instanceColor.array), instanceColor.itemSize);
|
|
break;
|
|
case "BatchedMesh":
|
|
geometry = getGeometry(data.geometry);
|
|
material = getMaterial(data.material);
|
|
object = new BatchedMesh(data.maxInstanceCount, data.maxVertexCount, data.maxIndexCount, material);
|
|
object.geometry = geometry;
|
|
object.perObjectFrustumCulled = data.perObjectFrustumCulled;
|
|
object.sortObjects = data.sortObjects;
|
|
object._drawRanges = data.drawRanges;
|
|
object._reservedRanges = data.reservedRanges;
|
|
object._visibility = data.visibility;
|
|
object._active = data.active;
|
|
object._bounds = data.bounds.map((bound) => {
|
|
const box = new Box3;
|
|
box.min.fromArray(bound.boxMin);
|
|
box.max.fromArray(bound.boxMax);
|
|
const sphere = new Sphere;
|
|
sphere.radius = bound.sphereRadius;
|
|
sphere.center.fromArray(bound.sphereCenter);
|
|
return {
|
|
boxInitialized: bound.boxInitialized,
|
|
box,
|
|
sphereInitialized: bound.sphereInitialized,
|
|
sphere
|
|
};
|
|
});
|
|
object._maxInstanceCount = data.maxInstanceCount;
|
|
object._maxVertexCount = data.maxVertexCount;
|
|
object._maxIndexCount = data.maxIndexCount;
|
|
object._geometryInitialized = data.geometryInitialized;
|
|
object._geometryCount = data.geometryCount;
|
|
object._matricesTexture = getTexture(data.matricesTexture.uuid);
|
|
if (data.colorsTexture !== undefined)
|
|
object._colorsTexture = getTexture(data.colorsTexture.uuid);
|
|
break;
|
|
case "LOD":
|
|
object = new LOD;
|
|
break;
|
|
case "Line":
|
|
object = new Line(getGeometry(data.geometry), getMaterial(data.material));
|
|
break;
|
|
case "LineLoop":
|
|
object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
|
|
break;
|
|
case "LineSegments":
|
|
object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
|
|
break;
|
|
case "PointCloud":
|
|
case "Points":
|
|
object = new Points(getGeometry(data.geometry), getMaterial(data.material));
|
|
break;
|
|
case "Sprite":
|
|
object = new Sprite(getMaterial(data.material));
|
|
break;
|
|
case "Group":
|
|
object = new Group;
|
|
break;
|
|
case "Bone":
|
|
object = new Bone;
|
|
break;
|
|
default:
|
|
object = new Object3D;
|
|
}
|
|
object.uuid = data.uuid;
|
|
if (data.name !== undefined)
|
|
object.name = data.name;
|
|
if (data.matrix !== undefined) {
|
|
object.matrix.fromArray(data.matrix);
|
|
if (data.matrixAutoUpdate !== undefined)
|
|
object.matrixAutoUpdate = data.matrixAutoUpdate;
|
|
if (object.matrixAutoUpdate)
|
|
object.matrix.decompose(object.position, object.quaternion, object.scale);
|
|
} else {
|
|
if (data.position !== undefined)
|
|
object.position.fromArray(data.position);
|
|
if (data.rotation !== undefined)
|
|
object.rotation.fromArray(data.rotation);
|
|
if (data.quaternion !== undefined)
|
|
object.quaternion.fromArray(data.quaternion);
|
|
if (data.scale !== undefined)
|
|
object.scale.fromArray(data.scale);
|
|
}
|
|
if (data.up !== undefined)
|
|
object.up.fromArray(data.up);
|
|
if (data.castShadow !== undefined)
|
|
object.castShadow = data.castShadow;
|
|
if (data.receiveShadow !== undefined)
|
|
object.receiveShadow = data.receiveShadow;
|
|
if (data.shadow) {
|
|
if (data.shadow.intensity !== undefined)
|
|
object.shadow.intensity = data.shadow.intensity;
|
|
if (data.shadow.bias !== undefined)
|
|
object.shadow.bias = data.shadow.bias;
|
|
if (data.shadow.normalBias !== undefined)
|
|
object.shadow.normalBias = data.shadow.normalBias;
|
|
if (data.shadow.radius !== undefined)
|
|
object.shadow.radius = data.shadow.radius;
|
|
if (data.shadow.mapSize !== undefined)
|
|
object.shadow.mapSize.fromArray(data.shadow.mapSize);
|
|
if (data.shadow.camera !== undefined)
|
|
object.shadow.camera = this.parseObject(data.shadow.camera);
|
|
}
|
|
if (data.visible !== undefined)
|
|
object.visible = data.visible;
|
|
if (data.frustumCulled !== undefined)
|
|
object.frustumCulled = data.frustumCulled;
|
|
if (data.renderOrder !== undefined)
|
|
object.renderOrder = data.renderOrder;
|
|
if (data.userData !== undefined)
|
|
object.userData = data.userData;
|
|
if (data.layers !== undefined)
|
|
object.layers.mask = data.layers;
|
|
if (data.children !== undefined) {
|
|
const children = data.children;
|
|
for (let i = 0;i < children.length; i++) {
|
|
object.add(this.parseObject(children[i], geometries, materials, textures, animations));
|
|
}
|
|
}
|
|
if (data.animations !== undefined) {
|
|
const objectAnimations = data.animations;
|
|
for (let i = 0;i < objectAnimations.length; i++) {
|
|
const uuid = objectAnimations[i];
|
|
object.animations.push(animations[uuid]);
|
|
}
|
|
}
|
|
if (data.type === "LOD") {
|
|
if (data.autoUpdate !== undefined)
|
|
object.autoUpdate = data.autoUpdate;
|
|
const levels = data.levels;
|
|
for (let l = 0;l < levels.length; l++) {
|
|
const level = levels[l];
|
|
const child = object.getObjectByProperty("uuid", level.object);
|
|
if (child !== undefined) {
|
|
object.addLevel(child, level.distance, level.hysteresis);
|
|
}
|
|
}
|
|
}
|
|
return object;
|
|
}
|
|
bindSkeletons(object, skeletons) {
|
|
if (Object.keys(skeletons).length === 0)
|
|
return;
|
|
object.traverse(function(child) {
|
|
if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
|
|
const skeleton = skeletons[child.skeleton];
|
|
if (skeleton === undefined) {
|
|
console.warn("THREE.ObjectLoader: No skeleton found with UUID:", child.skeleton);
|
|
} else {
|
|
child.bind(skeleton, child.bindMatrix);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
bindLightTargets(object) {
|
|
object.traverse(function(child) {
|
|
if (child.isDirectionalLight || child.isSpotLight) {
|
|
const uuid = child.target;
|
|
const target = object.getObjectByProperty("uuid", uuid);
|
|
if (target !== undefined) {
|
|
child.target = target;
|
|
} else {
|
|
child.target = new Object3D;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
};
|
|
TEXTURE_MAPPING = {
|
|
UVMapping,
|
|
CubeReflectionMapping,
|
|
CubeRefractionMapping,
|
|
EquirectangularReflectionMapping,
|
|
EquirectangularRefractionMapping,
|
|
CubeUVReflectionMapping
|
|
};
|
|
TEXTURE_WRAPPING = {
|
|
RepeatWrapping,
|
|
ClampToEdgeWrapping,
|
|
MirroredRepeatWrapping
|
|
};
|
|
TEXTURE_FILTER = {
|
|
NearestFilter,
|
|
NearestMipmapNearestFilter,
|
|
NearestMipmapLinearFilter,
|
|
LinearFilter,
|
|
LinearMipmapNearestFilter,
|
|
LinearMipmapLinearFilter
|
|
};
|
|
ImageBitmapLoader = class ImageBitmapLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
this.isImageBitmapLoader = true;
|
|
if (typeof createImageBitmap === "undefined") {
|
|
console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported.");
|
|
}
|
|
if (typeof fetch === "undefined") {
|
|
console.warn("THREE.ImageBitmapLoader: fetch() not supported.");
|
|
}
|
|
this.options = { premultiplyAlpha: "none" };
|
|
}
|
|
setOptions(options) {
|
|
this.options = options;
|
|
return this;
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
if (url === undefined)
|
|
url = "";
|
|
if (this.path !== undefined)
|
|
url = this.path + url;
|
|
url = this.manager.resolveURL(url);
|
|
const scope = this;
|
|
const cached = Cache.get(url);
|
|
if (cached !== undefined) {
|
|
scope.manager.itemStart(url);
|
|
if (cached.then) {
|
|
cached.then((imageBitmap) => {
|
|
if (onLoad)
|
|
onLoad(imageBitmap);
|
|
scope.manager.itemEnd(url);
|
|
}).catch((e) => {
|
|
if (onError)
|
|
onError(e);
|
|
});
|
|
return;
|
|
}
|
|
setTimeout(function() {
|
|
if (onLoad)
|
|
onLoad(cached);
|
|
scope.manager.itemEnd(url);
|
|
}, 0);
|
|
return cached;
|
|
}
|
|
const fetchOptions = {};
|
|
fetchOptions.credentials = this.crossOrigin === "anonymous" ? "same-origin" : "include";
|
|
fetchOptions.headers = this.requestHeader;
|
|
const promise = fetch(url, fetchOptions).then(function(res) {
|
|
return res.blob();
|
|
}).then(function(blob) {
|
|
return createImageBitmap(blob, Object.assign(scope.options, { colorSpaceConversion: "none" }));
|
|
}).then(function(imageBitmap) {
|
|
Cache.add(url, imageBitmap);
|
|
if (onLoad)
|
|
onLoad(imageBitmap);
|
|
scope.manager.itemEnd(url);
|
|
return imageBitmap;
|
|
}).catch(function(e) {
|
|
if (onError)
|
|
onError(e);
|
|
Cache.remove(url);
|
|
scope.manager.itemError(url);
|
|
scope.manager.itemEnd(url);
|
|
});
|
|
Cache.add(url, promise);
|
|
scope.manager.itemStart(url);
|
|
}
|
|
};
|
|
AudioLoader = class AudioLoader extends Loader {
|
|
constructor(manager) {
|
|
super(manager);
|
|
}
|
|
load(url, onLoad, onProgress, onError) {
|
|
const scope = this;
|
|
const loader = new FileLoader(this.manager);
|
|
loader.setResponseType("arraybuffer");
|
|
loader.setPath(this.path);
|
|
loader.setRequestHeader(this.requestHeader);
|
|
loader.setWithCredentials(this.withCredentials);
|
|
loader.load(url, function(buffer) {
|
|
try {
|
|
const bufferCopy = buffer.slice(0);
|
|
const context = AudioContext.getContext();
|
|
context.decodeAudioData(bufferCopy, function(audioBuffer) {
|
|
onLoad(audioBuffer);
|
|
}).catch(handleError);
|
|
} catch (e) {
|
|
handleError(e);
|
|
}
|
|
}, onProgress, onError);
|
|
function handleError(e) {
|
|
if (onError) {
|
|
onError(e);
|
|
} else {
|
|
console.error(e);
|
|
}
|
|
scope.manager.itemError(url);
|
|
}
|
|
}
|
|
};
|
|
_eyeRight = /* @__PURE__ */ new Matrix4;
|
|
_eyeLeft = /* @__PURE__ */ new Matrix4;
|
|
_projectionMatrix = /* @__PURE__ */ new Matrix4;
|
|
ArrayCamera = class ArrayCamera extends PerspectiveCamera {
|
|
constructor(array = []) {
|
|
super();
|
|
this.isArrayCamera = true;
|
|
this.cameras = array;
|
|
this.index = 0;
|
|
}
|
|
};
|
|
_position$1 = /* @__PURE__ */ new Vector3;
|
|
_quaternion$1 = /* @__PURE__ */ new Quaternion;
|
|
_scale$1 = /* @__PURE__ */ new Vector3;
|
|
_orientation$1 = /* @__PURE__ */ new Vector3;
|
|
AudioListener = class AudioListener extends Object3D {
|
|
constructor() {
|
|
super();
|
|
this.type = "AudioListener";
|
|
this.context = AudioContext.getContext();
|
|
this.gain = this.context.createGain();
|
|
this.gain.connect(this.context.destination);
|
|
this.filter = null;
|
|
this.timeDelta = 0;
|
|
this._clock = new Clock;
|
|
}
|
|
getInput() {
|
|
return this.gain;
|
|
}
|
|
removeFilter() {
|
|
if (this.filter !== null) {
|
|
this.gain.disconnect(this.filter);
|
|
this.filter.disconnect(this.context.destination);
|
|
this.gain.connect(this.context.destination);
|
|
this.filter = null;
|
|
}
|
|
return this;
|
|
}
|
|
getFilter() {
|
|
return this.filter;
|
|
}
|
|
setFilter(value) {
|
|
if (this.filter !== null) {
|
|
this.gain.disconnect(this.filter);
|
|
this.filter.disconnect(this.context.destination);
|
|
} else {
|
|
this.gain.disconnect(this.context.destination);
|
|
}
|
|
this.filter = value;
|
|
this.gain.connect(this.filter);
|
|
this.filter.connect(this.context.destination);
|
|
return this;
|
|
}
|
|
getMasterVolume() {
|
|
return this.gain.gain.value;
|
|
}
|
|
setMasterVolume(value) {
|
|
this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
|
|
return this;
|
|
}
|
|
updateMatrixWorld(force) {
|
|
super.updateMatrixWorld(force);
|
|
const listener = this.context.listener;
|
|
const up = this.up;
|
|
this.timeDelta = this._clock.getDelta();
|
|
this.matrixWorld.decompose(_position$1, _quaternion$1, _scale$1);
|
|
_orientation$1.set(0, 0, -1).applyQuaternion(_quaternion$1);
|
|
if (listener.positionX) {
|
|
const endTime = this.context.currentTime + this.timeDelta;
|
|
listener.positionX.linearRampToValueAtTime(_position$1.x, endTime);
|
|
listener.positionY.linearRampToValueAtTime(_position$1.y, endTime);
|
|
listener.positionZ.linearRampToValueAtTime(_position$1.z, endTime);
|
|
listener.forwardX.linearRampToValueAtTime(_orientation$1.x, endTime);
|
|
listener.forwardY.linearRampToValueAtTime(_orientation$1.y, endTime);
|
|
listener.forwardZ.linearRampToValueAtTime(_orientation$1.z, endTime);
|
|
listener.upX.linearRampToValueAtTime(up.x, endTime);
|
|
listener.upY.linearRampToValueAtTime(up.y, endTime);
|
|
listener.upZ.linearRampToValueAtTime(up.z, endTime);
|
|
} else {
|
|
listener.setPosition(_position$1.x, _position$1.y, _position$1.z);
|
|
listener.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z, up.x, up.y, up.z);
|
|
}
|
|
}
|
|
};
|
|
Audio = class Audio extends Object3D {
|
|
constructor(listener) {
|
|
super();
|
|
this.type = "Audio";
|
|
this.listener = listener;
|
|
this.context = listener.context;
|
|
this.gain = this.context.createGain();
|
|
this.gain.connect(listener.getInput());
|
|
this.autoplay = false;
|
|
this.buffer = null;
|
|
this.detune = 0;
|
|
this.loop = false;
|
|
this.loopStart = 0;
|
|
this.loopEnd = 0;
|
|
this.offset = 0;
|
|
this.duration = undefined;
|
|
this.playbackRate = 1;
|
|
this.isPlaying = false;
|
|
this.hasPlaybackControl = true;
|
|
this.source = null;
|
|
this.sourceType = "empty";
|
|
this._startedAt = 0;
|
|
this._progress = 0;
|
|
this._connected = false;
|
|
this.filters = [];
|
|
}
|
|
getOutput() {
|
|
return this.gain;
|
|
}
|
|
setNodeSource(audioNode) {
|
|
this.hasPlaybackControl = false;
|
|
this.sourceType = "audioNode";
|
|
this.source = audioNode;
|
|
this.connect();
|
|
return this;
|
|
}
|
|
setMediaElementSource(mediaElement) {
|
|
this.hasPlaybackControl = false;
|
|
this.sourceType = "mediaNode";
|
|
this.source = this.context.createMediaElementSource(mediaElement);
|
|
this.connect();
|
|
return this;
|
|
}
|
|
setMediaStreamSource(mediaStream) {
|
|
this.hasPlaybackControl = false;
|
|
this.sourceType = "mediaStreamNode";
|
|
this.source = this.context.createMediaStreamSource(mediaStream);
|
|
this.connect();
|
|
return this;
|
|
}
|
|
setBuffer(audioBuffer) {
|
|
this.buffer = audioBuffer;
|
|
this.sourceType = "buffer";
|
|
if (this.autoplay)
|
|
this.play();
|
|
return this;
|
|
}
|
|
play(delay = 0) {
|
|
if (this.isPlaying === true) {
|
|
console.warn("THREE.Audio: Audio is already playing.");
|
|
return;
|
|
}
|
|
if (this.hasPlaybackControl === false) {
|
|
console.warn("THREE.Audio: this Audio has no playback control.");
|
|
return;
|
|
}
|
|
this._startedAt = this.context.currentTime + delay;
|
|
const source = this.context.createBufferSource();
|
|
source.buffer = this.buffer;
|
|
source.loop = this.loop;
|
|
source.loopStart = this.loopStart;
|
|
source.loopEnd = this.loopEnd;
|
|
source.onended = this.onEnded.bind(this);
|
|
source.start(this._startedAt, this._progress + this.offset, this.duration);
|
|
this.isPlaying = true;
|
|
this.source = source;
|
|
this.setDetune(this.detune);
|
|
this.setPlaybackRate(this.playbackRate);
|
|
return this.connect();
|
|
}
|
|
pause() {
|
|
if (this.hasPlaybackControl === false) {
|
|
console.warn("THREE.Audio: this Audio has no playback control.");
|
|
return;
|
|
}
|
|
if (this.isPlaying === true) {
|
|
this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
|
|
if (this.loop === true) {
|
|
this._progress = this._progress % (this.duration || this.buffer.duration);
|
|
}
|
|
this.source.stop();
|
|
this.source.onended = null;
|
|
this.isPlaying = false;
|
|
}
|
|
return this;
|
|
}
|
|
stop(delay = 0) {
|
|
if (this.hasPlaybackControl === false) {
|
|
console.warn("THREE.Audio: this Audio has no playback control.");
|
|
return;
|
|
}
|
|
this._progress = 0;
|
|
if (this.source !== null) {
|
|
this.source.stop(this.context.currentTime + delay);
|
|
this.source.onended = null;
|
|
}
|
|
this.isPlaying = false;
|
|
return this;
|
|
}
|
|
connect() {
|
|
if (this.filters.length > 0) {
|
|
this.source.connect(this.filters[0]);
|
|
for (let i = 1, l = this.filters.length;i < l; i++) {
|
|
this.filters[i - 1].connect(this.filters[i]);
|
|
}
|
|
this.filters[this.filters.length - 1].connect(this.getOutput());
|
|
} else {
|
|
this.source.connect(this.getOutput());
|
|
}
|
|
this._connected = true;
|
|
return this;
|
|
}
|
|
disconnect() {
|
|
if (this._connected === false) {
|
|
return;
|
|
}
|
|
if (this.filters.length > 0) {
|
|
this.source.disconnect(this.filters[0]);
|
|
for (let i = 1, l = this.filters.length;i < l; i++) {
|
|
this.filters[i - 1].disconnect(this.filters[i]);
|
|
}
|
|
this.filters[this.filters.length - 1].disconnect(this.getOutput());
|
|
} else {
|
|
this.source.disconnect(this.getOutput());
|
|
}
|
|
this._connected = false;
|
|
return this;
|
|
}
|
|
getFilters() {
|
|
return this.filters;
|
|
}
|
|
setFilters(value) {
|
|
if (!value)
|
|
value = [];
|
|
if (this._connected === true) {
|
|
this.disconnect();
|
|
this.filters = value.slice();
|
|
this.connect();
|
|
} else {
|
|
this.filters = value.slice();
|
|
}
|
|
return this;
|
|
}
|
|
setDetune(value) {
|
|
this.detune = value;
|
|
if (this.isPlaying === true && this.source.detune !== undefined) {
|
|
this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
|
|
}
|
|
return this;
|
|
}
|
|
getDetune() {
|
|
return this.detune;
|
|
}
|
|
getFilter() {
|
|
return this.getFilters()[0];
|
|
}
|
|
setFilter(filter) {
|
|
return this.setFilters(filter ? [filter] : []);
|
|
}
|
|
setPlaybackRate(value) {
|
|
if (this.hasPlaybackControl === false) {
|
|
console.warn("THREE.Audio: this Audio has no playback control.");
|
|
return;
|
|
}
|
|
this.playbackRate = value;
|
|
if (this.isPlaying === true) {
|
|
this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
|
|
}
|
|
return this;
|
|
}
|
|
getPlaybackRate() {
|
|
return this.playbackRate;
|
|
}
|
|
onEnded() {
|
|
this.isPlaying = false;
|
|
this._progress = 0;
|
|
}
|
|
getLoop() {
|
|
if (this.hasPlaybackControl === false) {
|
|
console.warn("THREE.Audio: this Audio has no playback control.");
|
|
return false;
|
|
}
|
|
return this.loop;
|
|
}
|
|
setLoop(value) {
|
|
if (this.hasPlaybackControl === false) {
|
|
console.warn("THREE.Audio: this Audio has no playback control.");
|
|
return;
|
|
}
|
|
this.loop = value;
|
|
if (this.isPlaying === true) {
|
|
this.source.loop = this.loop;
|
|
}
|
|
return this;
|
|
}
|
|
setLoopStart(value) {
|
|
this.loopStart = value;
|
|
return this;
|
|
}
|
|
setLoopEnd(value) {
|
|
this.loopEnd = value;
|
|
return this;
|
|
}
|
|
getVolume() {
|
|
return this.gain.gain.value;
|
|
}
|
|
setVolume(value) {
|
|
this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
|
|
return this;
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
if (source.sourceType !== "buffer") {
|
|
console.warn("THREE.Audio: Audio source type cannot be copied.");
|
|
return this;
|
|
}
|
|
this.autoplay = source.autoplay;
|
|
this.buffer = source.buffer;
|
|
this.detune = source.detune;
|
|
this.loop = source.loop;
|
|
this.loopStart = source.loopStart;
|
|
this.loopEnd = source.loopEnd;
|
|
this.offset = source.offset;
|
|
this.duration = source.duration;
|
|
this.playbackRate = source.playbackRate;
|
|
this.hasPlaybackControl = source.hasPlaybackControl;
|
|
this.sourceType = source.sourceType;
|
|
this.filters = source.filters.slice();
|
|
return this;
|
|
}
|
|
clone(recursive) {
|
|
return new this.constructor(this.listener).copy(this, recursive);
|
|
}
|
|
};
|
|
_position = /* @__PURE__ */ new Vector3;
|
|
_quaternion = /* @__PURE__ */ new Quaternion;
|
|
_scale = /* @__PURE__ */ new Vector3;
|
|
_orientation = /* @__PURE__ */ new Vector3;
|
|
PositionalAudio = class PositionalAudio extends Audio {
|
|
constructor(listener) {
|
|
super(listener);
|
|
this.panner = this.context.createPanner();
|
|
this.panner.panningModel = "HRTF";
|
|
this.panner.connect(this.gain);
|
|
}
|
|
connect() {
|
|
super.connect();
|
|
this.panner.connect(this.gain);
|
|
}
|
|
disconnect() {
|
|
super.disconnect();
|
|
this.panner.disconnect(this.gain);
|
|
}
|
|
getOutput() {
|
|
return this.panner;
|
|
}
|
|
getRefDistance() {
|
|
return this.panner.refDistance;
|
|
}
|
|
setRefDistance(value) {
|
|
this.panner.refDistance = value;
|
|
return this;
|
|
}
|
|
getRolloffFactor() {
|
|
return this.panner.rolloffFactor;
|
|
}
|
|
setRolloffFactor(value) {
|
|
this.panner.rolloffFactor = value;
|
|
return this;
|
|
}
|
|
getDistanceModel() {
|
|
return this.panner.distanceModel;
|
|
}
|
|
setDistanceModel(value) {
|
|
this.panner.distanceModel = value;
|
|
return this;
|
|
}
|
|
getMaxDistance() {
|
|
return this.panner.maxDistance;
|
|
}
|
|
setMaxDistance(value) {
|
|
this.panner.maxDistance = value;
|
|
return this;
|
|
}
|
|
setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
|
|
this.panner.coneInnerAngle = coneInnerAngle;
|
|
this.panner.coneOuterAngle = coneOuterAngle;
|
|
this.panner.coneOuterGain = coneOuterGain;
|
|
return this;
|
|
}
|
|
updateMatrixWorld(force) {
|
|
super.updateMatrixWorld(force);
|
|
if (this.hasPlaybackControl === true && this.isPlaying === false)
|
|
return;
|
|
this.matrixWorld.decompose(_position, _quaternion, _scale);
|
|
_orientation.set(0, 0, 1).applyQuaternion(_quaternion);
|
|
const panner = this.panner;
|
|
if (panner.positionX) {
|
|
const endTime = this.context.currentTime + this.listener.timeDelta;
|
|
panner.positionX.linearRampToValueAtTime(_position.x, endTime);
|
|
panner.positionY.linearRampToValueAtTime(_position.y, endTime);
|
|
panner.positionZ.linearRampToValueAtTime(_position.z, endTime);
|
|
panner.orientationX.linearRampToValueAtTime(_orientation.x, endTime);
|
|
panner.orientationY.linearRampToValueAtTime(_orientation.y, endTime);
|
|
panner.orientationZ.linearRampToValueAtTime(_orientation.z, endTime);
|
|
} else {
|
|
panner.setPosition(_position.x, _position.y, _position.z);
|
|
panner.setOrientation(_orientation.x, _orientation.y, _orientation.z);
|
|
}
|
|
}
|
|
};
|
|
_reservedRe = new RegExp("[" + _RESERVED_CHARS_RE + "]", "g");
|
|
_wordChar = "[^" + _RESERVED_CHARS_RE + "]";
|
|
_wordCharOrDot = "[^" + _RESERVED_CHARS_RE.replace("\\.", "") + "]";
|
|
_directoryRe = /* @__PURE__ */ /((?:WC+[\/:])*)/.source.replace("WC", _wordChar);
|
|
_nodeRe = /* @__PURE__ */ /(WCOD+)?/.source.replace("WCOD", _wordCharOrDot);
|
|
_objectRe = /* @__PURE__ */ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC", _wordChar);
|
|
_propertyRe = /* @__PURE__ */ /\.(WC+)(?:\[(.+)\])?/.source.replace("WC", _wordChar);
|
|
_trackRe = new RegExp("" + "^" + _directoryRe + _nodeRe + _objectRe + _propertyRe + "$");
|
|
_supportedObjectNames = ["material", "materials", "bones", "map"];
|
|
PropertyBinding.Composite = Composite;
|
|
PropertyBinding.prototype.BindingType = {
|
|
Direct: 0,
|
|
EntireArray: 1,
|
|
ArrayElement: 2,
|
|
HasFromToArray: 3
|
|
};
|
|
PropertyBinding.prototype.Versioning = {
|
|
None: 0,
|
|
NeedsUpdate: 1,
|
|
MatrixWorldNeedsUpdate: 2
|
|
};
|
|
PropertyBinding.prototype.GetterByBindingType = [
|
|
PropertyBinding.prototype._getValue_direct,
|
|
PropertyBinding.prototype._getValue_array,
|
|
PropertyBinding.prototype._getValue_arrayElement,
|
|
PropertyBinding.prototype._getValue_toArray
|
|
];
|
|
PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [
|
|
[
|
|
PropertyBinding.prototype._setValue_direct,
|
|
PropertyBinding.prototype._setValue_direct_setNeedsUpdate,
|
|
PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate
|
|
],
|
|
[
|
|
PropertyBinding.prototype._setValue_array,
|
|
PropertyBinding.prototype._setValue_array_setNeedsUpdate,
|
|
PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate
|
|
],
|
|
[
|
|
PropertyBinding.prototype._setValue_arrayElement,
|
|
PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate,
|
|
PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate
|
|
],
|
|
[
|
|
PropertyBinding.prototype._setValue_fromArray,
|
|
PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate,
|
|
PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate
|
|
]
|
|
];
|
|
_controlInterpolantsResultBuffer = new Float32Array(1);
|
|
AnimationMixer = class AnimationMixer extends EventDispatcher {
|
|
constructor(root) {
|
|
super();
|
|
this._root = root;
|
|
this._initMemoryManager();
|
|
this._accuIndex = 0;
|
|
this.time = 0;
|
|
this.timeScale = 1;
|
|
}
|
|
_bindAction(action, prototypeAction) {
|
|
const root = action._localRoot || this._root, tracks = action._clip.tracks, nTracks = tracks.length, bindings = action._propertyBindings, interpolants = action._interpolants, rootUuid = root.uuid, bindingsByRoot = this._bindingsByRootAndName;
|
|
let bindingsByName = bindingsByRoot[rootUuid];
|
|
if (bindingsByName === undefined) {
|
|
bindingsByName = {};
|
|
bindingsByRoot[rootUuid] = bindingsByName;
|
|
}
|
|
for (let i = 0;i !== nTracks; ++i) {
|
|
const track = tracks[i], trackName = track.name;
|
|
let binding = bindingsByName[trackName];
|
|
if (binding !== undefined) {
|
|
++binding.referenceCount;
|
|
bindings[i] = binding;
|
|
} else {
|
|
binding = bindings[i];
|
|
if (binding !== undefined) {
|
|
if (binding._cacheIndex === null) {
|
|
++binding.referenceCount;
|
|
this._addInactiveBinding(binding, rootUuid, trackName);
|
|
}
|
|
continue;
|
|
}
|
|
const path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
|
|
binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
|
|
++binding.referenceCount;
|
|
this._addInactiveBinding(binding, rootUuid, trackName);
|
|
bindings[i] = binding;
|
|
}
|
|
interpolants[i].resultBuffer = binding.buffer;
|
|
}
|
|
}
|
|
_activateAction(action) {
|
|
if (!this._isActiveAction(action)) {
|
|
if (action._cacheIndex === null) {
|
|
const rootUuid = (action._localRoot || this._root).uuid, clipUuid = action._clip.uuid, actionsForClip = this._actionsByClip[clipUuid];
|
|
this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
|
|
this._addInactiveAction(action, clipUuid, rootUuid);
|
|
}
|
|
const bindings = action._propertyBindings;
|
|
for (let i = 0, n = bindings.length;i !== n; ++i) {
|
|
const binding = bindings[i];
|
|
if (binding.useCount++ === 0) {
|
|
this._lendBinding(binding);
|
|
binding.saveOriginalState();
|
|
}
|
|
}
|
|
this._lendAction(action);
|
|
}
|
|
}
|
|
_deactivateAction(action) {
|
|
if (this._isActiveAction(action)) {
|
|
const bindings = action._propertyBindings;
|
|
for (let i = 0, n = bindings.length;i !== n; ++i) {
|
|
const binding = bindings[i];
|
|
if (--binding.useCount === 0) {
|
|
binding.restoreOriginalState();
|
|
this._takeBackBinding(binding);
|
|
}
|
|
}
|
|
this._takeBackAction(action);
|
|
}
|
|
}
|
|
_initMemoryManager() {
|
|
this._actions = [];
|
|
this._nActiveActions = 0;
|
|
this._actionsByClip = {};
|
|
this._bindings = [];
|
|
this._nActiveBindings = 0;
|
|
this._bindingsByRootAndName = {};
|
|
this._controlInterpolants = [];
|
|
this._nActiveControlInterpolants = 0;
|
|
const scope = this;
|
|
this.stats = {
|
|
actions: {
|
|
get total() {
|
|
return scope._actions.length;
|
|
},
|
|
get inUse() {
|
|
return scope._nActiveActions;
|
|
}
|
|
},
|
|
bindings: {
|
|
get total() {
|
|
return scope._bindings.length;
|
|
},
|
|
get inUse() {
|
|
return scope._nActiveBindings;
|
|
}
|
|
},
|
|
controlInterpolants: {
|
|
get total() {
|
|
return scope._controlInterpolants.length;
|
|
},
|
|
get inUse() {
|
|
return scope._nActiveControlInterpolants;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
_isActiveAction(action) {
|
|
const index = action._cacheIndex;
|
|
return index !== null && index < this._nActiveActions;
|
|
}
|
|
_addInactiveAction(action, clipUuid, rootUuid) {
|
|
const actions = this._actions, actionsByClip = this._actionsByClip;
|
|
let actionsForClip = actionsByClip[clipUuid];
|
|
if (actionsForClip === undefined) {
|
|
actionsForClip = {
|
|
knownActions: [action],
|
|
actionByRoot: {}
|
|
};
|
|
action._byClipCacheIndex = 0;
|
|
actionsByClip[clipUuid] = actionsForClip;
|
|
} else {
|
|
const knownActions = actionsForClip.knownActions;
|
|
action._byClipCacheIndex = knownActions.length;
|
|
knownActions.push(action);
|
|
}
|
|
action._cacheIndex = actions.length;
|
|
actions.push(action);
|
|
actionsForClip.actionByRoot[rootUuid] = action;
|
|
}
|
|
_removeInactiveAction(action) {
|
|
const actions = this._actions, lastInactiveAction = actions[actions.length - 1], cacheIndex = action._cacheIndex;
|
|
lastInactiveAction._cacheIndex = cacheIndex;
|
|
actions[cacheIndex] = lastInactiveAction;
|
|
actions.pop();
|
|
action._cacheIndex = null;
|
|
const clipUuid = action._clip.uuid, actionsByClip = this._actionsByClip, actionsForClip = actionsByClip[clipUuid], knownActionsForClip = actionsForClip.knownActions, lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1], byClipCacheIndex = action._byClipCacheIndex;
|
|
lastKnownAction._byClipCacheIndex = byClipCacheIndex;
|
|
knownActionsForClip[byClipCacheIndex] = lastKnownAction;
|
|
knownActionsForClip.pop();
|
|
action._byClipCacheIndex = null;
|
|
const actionByRoot = actionsForClip.actionByRoot, rootUuid = (action._localRoot || this._root).uuid;
|
|
delete actionByRoot[rootUuid];
|
|
if (knownActionsForClip.length === 0) {
|
|
delete actionsByClip[clipUuid];
|
|
}
|
|
this._removeInactiveBindingsForAction(action);
|
|
}
|
|
_removeInactiveBindingsForAction(action) {
|
|
const bindings = action._propertyBindings;
|
|
for (let i = 0, n = bindings.length;i !== n; ++i) {
|
|
const binding = bindings[i];
|
|
if (--binding.referenceCount === 0) {
|
|
this._removeInactiveBinding(binding);
|
|
}
|
|
}
|
|
}
|
|
_lendAction(action) {
|
|
const actions = this._actions, prevIndex = action._cacheIndex, lastActiveIndex = this._nActiveActions++, firstInactiveAction = actions[lastActiveIndex];
|
|
action._cacheIndex = lastActiveIndex;
|
|
actions[lastActiveIndex] = action;
|
|
firstInactiveAction._cacheIndex = prevIndex;
|
|
actions[prevIndex] = firstInactiveAction;
|
|
}
|
|
_takeBackAction(action) {
|
|
const actions = this._actions, prevIndex = action._cacheIndex, firstInactiveIndex = --this._nActiveActions, lastActiveAction = actions[firstInactiveIndex];
|
|
action._cacheIndex = firstInactiveIndex;
|
|
actions[firstInactiveIndex] = action;
|
|
lastActiveAction._cacheIndex = prevIndex;
|
|
actions[prevIndex] = lastActiveAction;
|
|
}
|
|
_addInactiveBinding(binding, rootUuid, trackName) {
|
|
const bindingsByRoot = this._bindingsByRootAndName, bindings = this._bindings;
|
|
let bindingByName = bindingsByRoot[rootUuid];
|
|
if (bindingByName === undefined) {
|
|
bindingByName = {};
|
|
bindingsByRoot[rootUuid] = bindingByName;
|
|
}
|
|
bindingByName[trackName] = binding;
|
|
binding._cacheIndex = bindings.length;
|
|
bindings.push(binding);
|
|
}
|
|
_removeInactiveBinding(binding) {
|
|
const bindings = this._bindings, propBinding = binding.binding, rootUuid = propBinding.rootNode.uuid, trackName = propBinding.path, bindingsByRoot = this._bindingsByRootAndName, bindingByName = bindingsByRoot[rootUuid], lastInactiveBinding = bindings[bindings.length - 1], cacheIndex = binding._cacheIndex;
|
|
lastInactiveBinding._cacheIndex = cacheIndex;
|
|
bindings[cacheIndex] = lastInactiveBinding;
|
|
bindings.pop();
|
|
delete bindingByName[trackName];
|
|
if (Object.keys(bindingByName).length === 0) {
|
|
delete bindingsByRoot[rootUuid];
|
|
}
|
|
}
|
|
_lendBinding(binding) {
|
|
const bindings = this._bindings, prevIndex = binding._cacheIndex, lastActiveIndex = this._nActiveBindings++, firstInactiveBinding = bindings[lastActiveIndex];
|
|
binding._cacheIndex = lastActiveIndex;
|
|
bindings[lastActiveIndex] = binding;
|
|
firstInactiveBinding._cacheIndex = prevIndex;
|
|
bindings[prevIndex] = firstInactiveBinding;
|
|
}
|
|
_takeBackBinding(binding) {
|
|
const bindings = this._bindings, prevIndex = binding._cacheIndex, firstInactiveIndex = --this._nActiveBindings, lastActiveBinding = bindings[firstInactiveIndex];
|
|
binding._cacheIndex = firstInactiveIndex;
|
|
bindings[firstInactiveIndex] = binding;
|
|
lastActiveBinding._cacheIndex = prevIndex;
|
|
bindings[prevIndex] = lastActiveBinding;
|
|
}
|
|
_lendControlInterpolant() {
|
|
const interpolants = this._controlInterpolants, lastActiveIndex = this._nActiveControlInterpolants++;
|
|
let interpolant = interpolants[lastActiveIndex];
|
|
if (interpolant === undefined) {
|
|
interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, _controlInterpolantsResultBuffer);
|
|
interpolant.__cacheIndex = lastActiveIndex;
|
|
interpolants[lastActiveIndex] = interpolant;
|
|
}
|
|
return interpolant;
|
|
}
|
|
_takeBackControlInterpolant(interpolant) {
|
|
const interpolants = this._controlInterpolants, prevIndex = interpolant.__cacheIndex, firstInactiveIndex = --this._nActiveControlInterpolants, lastActiveInterpolant = interpolants[firstInactiveIndex];
|
|
interpolant.__cacheIndex = firstInactiveIndex;
|
|
interpolants[firstInactiveIndex] = interpolant;
|
|
lastActiveInterpolant.__cacheIndex = prevIndex;
|
|
interpolants[prevIndex] = lastActiveInterpolant;
|
|
}
|
|
clipAction(clip, optionalRoot, blendMode) {
|
|
const root = optionalRoot || this._root, rootUuid = root.uuid;
|
|
let clipObject = typeof clip === "string" ? AnimationClip.findByName(root, clip) : clip;
|
|
const clipUuid = clipObject !== null ? clipObject.uuid : clip;
|
|
const actionsForClip = this._actionsByClip[clipUuid];
|
|
let prototypeAction = null;
|
|
if (blendMode === undefined) {
|
|
if (clipObject !== null) {
|
|
blendMode = clipObject.blendMode;
|
|
} else {
|
|
blendMode = NormalAnimationBlendMode;
|
|
}
|
|
}
|
|
if (actionsForClip !== undefined) {
|
|
const existingAction = actionsForClip.actionByRoot[rootUuid];
|
|
if (existingAction !== undefined && existingAction.blendMode === blendMode) {
|
|
return existingAction;
|
|
}
|
|
prototypeAction = actionsForClip.knownActions[0];
|
|
if (clipObject === null)
|
|
clipObject = prototypeAction._clip;
|
|
}
|
|
if (clipObject === null)
|
|
return null;
|
|
const newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
|
|
this._bindAction(newAction, prototypeAction);
|
|
this._addInactiveAction(newAction, clipUuid, rootUuid);
|
|
return newAction;
|
|
}
|
|
existingAction(clip, optionalRoot) {
|
|
const root = optionalRoot || this._root, rootUuid = root.uuid, clipObject = typeof clip === "string" ? AnimationClip.findByName(root, clip) : clip, clipUuid = clipObject ? clipObject.uuid : clip, actionsForClip = this._actionsByClip[clipUuid];
|
|
if (actionsForClip !== undefined) {
|
|
return actionsForClip.actionByRoot[rootUuid] || null;
|
|
}
|
|
return null;
|
|
}
|
|
stopAllAction() {
|
|
const actions = this._actions, nActions = this._nActiveActions;
|
|
for (let i = nActions - 1;i >= 0; --i) {
|
|
actions[i].stop();
|
|
}
|
|
return this;
|
|
}
|
|
update(deltaTime) {
|
|
deltaTime *= this.timeScale;
|
|
const actions = this._actions, nActions = this._nActiveActions, time = this.time += deltaTime, timeDirection = Math.sign(deltaTime), accuIndex = this._accuIndex ^= 1;
|
|
for (let i = 0;i !== nActions; ++i) {
|
|
const action = actions[i];
|
|
action._update(time, deltaTime, timeDirection, accuIndex);
|
|
}
|
|
const bindings = this._bindings, nBindings = this._nActiveBindings;
|
|
for (let i = 0;i !== nBindings; ++i) {
|
|
bindings[i].apply(accuIndex);
|
|
}
|
|
return this;
|
|
}
|
|
setTime(timeInSeconds) {
|
|
this.time = 0;
|
|
for (let i = 0;i < this._actions.length; i++) {
|
|
this._actions[i].time = 0;
|
|
}
|
|
return this.update(timeInSeconds);
|
|
}
|
|
getRoot() {
|
|
return this._root;
|
|
}
|
|
uncacheClip(clip) {
|
|
const actions = this._actions, clipUuid = clip.uuid, actionsByClip = this._actionsByClip, actionsForClip = actionsByClip[clipUuid];
|
|
if (actionsForClip !== undefined) {
|
|
const actionsToRemove = actionsForClip.knownActions;
|
|
for (let i = 0, n = actionsToRemove.length;i !== n; ++i) {
|
|
const action = actionsToRemove[i];
|
|
this._deactivateAction(action);
|
|
const cacheIndex = action._cacheIndex, lastInactiveAction = actions[actions.length - 1];
|
|
action._cacheIndex = null;
|
|
action._byClipCacheIndex = null;
|
|
lastInactiveAction._cacheIndex = cacheIndex;
|
|
actions[cacheIndex] = lastInactiveAction;
|
|
actions.pop();
|
|
this._removeInactiveBindingsForAction(action);
|
|
}
|
|
delete actionsByClip[clipUuid];
|
|
}
|
|
}
|
|
uncacheRoot(root) {
|
|
const rootUuid = root.uuid, actionsByClip = this._actionsByClip;
|
|
for (const clipUuid in actionsByClip) {
|
|
const actionByRoot = actionsByClip[clipUuid].actionByRoot, action = actionByRoot[rootUuid];
|
|
if (action !== undefined) {
|
|
this._deactivateAction(action);
|
|
this._removeInactiveAction(action);
|
|
}
|
|
}
|
|
const bindingsByRoot = this._bindingsByRootAndName, bindingByName = bindingsByRoot[rootUuid];
|
|
if (bindingByName !== undefined) {
|
|
for (const trackName in bindingByName) {
|
|
const binding = bindingByName[trackName];
|
|
binding.restoreOriginalState();
|
|
this._removeInactiveBinding(binding);
|
|
}
|
|
}
|
|
}
|
|
uncacheAction(clip, optionalRoot) {
|
|
const action = this.existingAction(clip, optionalRoot);
|
|
if (action !== null) {
|
|
this._deactivateAction(action);
|
|
this._removeInactiveAction(action);
|
|
}
|
|
}
|
|
};
|
|
RenderTarget3D = class RenderTarget3D extends RenderTarget {
|
|
constructor(width = 1, height = 1, depth = 1, options = {}) {
|
|
super(width, height, options);
|
|
this.isRenderTarget3D = true;
|
|
this.depth = depth;
|
|
this.texture = new Data3DTexture(null, width, height, depth);
|
|
this.texture.isRenderTargetTexture = true;
|
|
}
|
|
};
|
|
RenderTargetArray = class RenderTargetArray extends RenderTarget {
|
|
constructor(width = 1, height = 1, depth = 1, options = {}) {
|
|
super(width, height, options);
|
|
this.isRenderTargetArray = true;
|
|
this.depth = depth;
|
|
this.texture = new DataArrayTexture(null, width, height, depth);
|
|
this.texture.isRenderTargetTexture = true;
|
|
}
|
|
};
|
|
UniformsGroup = class UniformsGroup extends EventDispatcher {
|
|
constructor() {
|
|
super();
|
|
this.isUniformsGroup = true;
|
|
Object.defineProperty(this, "id", { value: _id++ });
|
|
this.name = "";
|
|
this.usage = StaticDrawUsage;
|
|
this.uniforms = [];
|
|
}
|
|
add(uniform) {
|
|
this.uniforms.push(uniform);
|
|
return this;
|
|
}
|
|
remove(uniform) {
|
|
const index = this.uniforms.indexOf(uniform);
|
|
if (index !== -1)
|
|
this.uniforms.splice(index, 1);
|
|
return this;
|
|
}
|
|
setName(name) {
|
|
this.name = name;
|
|
return this;
|
|
}
|
|
setUsage(value) {
|
|
this.usage = value;
|
|
return this;
|
|
}
|
|
dispose() {
|
|
this.dispatchEvent({ type: "dispose" });
|
|
return this;
|
|
}
|
|
copy(source) {
|
|
this.name = source.name;
|
|
this.usage = source.usage;
|
|
const uniformsSource = source.uniforms;
|
|
this.uniforms.length = 0;
|
|
for (let i = 0, l = uniformsSource.length;i < l; i++) {
|
|
const uniforms = Array.isArray(uniformsSource[i]) ? uniformsSource[i] : [uniformsSource[i]];
|
|
for (let j = 0;j < uniforms.length; j++) {
|
|
this.uniforms.push(uniforms[j].clone());
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
};
|
|
InstancedInterleavedBuffer = class InstancedInterleavedBuffer extends InterleavedBuffer {
|
|
constructor(array, stride, meshPerAttribute = 1) {
|
|
super(array, stride);
|
|
this.isInstancedInterleavedBuffer = true;
|
|
this.meshPerAttribute = meshPerAttribute;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.meshPerAttribute = source.meshPerAttribute;
|
|
return this;
|
|
}
|
|
clone(data) {
|
|
const ib = super.clone(data);
|
|
ib.meshPerAttribute = this.meshPerAttribute;
|
|
return ib;
|
|
}
|
|
toJSON(data) {
|
|
const json = super.toJSON(data);
|
|
json.isInstancedInterleavedBuffer = true;
|
|
json.meshPerAttribute = this.meshPerAttribute;
|
|
return json;
|
|
}
|
|
};
|
|
_matrix = /* @__PURE__ */ new Matrix4;
|
|
_vector$4 = /* @__PURE__ */ new Vector2;
|
|
_startP = /* @__PURE__ */ new Vector3;
|
|
_startEnd = /* @__PURE__ */ new Vector3;
|
|
_vector$3 = /* @__PURE__ */ new Vector3;
|
|
SpotLightHelper = class SpotLightHelper extends Object3D {
|
|
constructor(light, color) {
|
|
super();
|
|
this.light = light;
|
|
this.matrixAutoUpdate = false;
|
|
this.color = color;
|
|
this.type = "SpotLightHelper";
|
|
const geometry = new BufferGeometry;
|
|
const positions = [
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
-1,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
-1,
|
|
1
|
|
];
|
|
for (let i = 0, j = 1, l = 32;i < l; i++, j++) {
|
|
const p1 = i / l * Math.PI * 2;
|
|
const p2 = j / l * Math.PI * 2;
|
|
positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
|
|
}
|
|
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
const material = new LineBasicMaterial({ fog: false, toneMapped: false });
|
|
this.cone = new LineSegments(geometry, material);
|
|
this.add(this.cone);
|
|
this.update();
|
|
}
|
|
dispose() {
|
|
this.cone.geometry.dispose();
|
|
this.cone.material.dispose();
|
|
}
|
|
update() {
|
|
this.light.updateWorldMatrix(true, false);
|
|
this.light.target.updateWorldMatrix(true, false);
|
|
if (this.parent) {
|
|
this.parent.updateWorldMatrix(true);
|
|
this.matrix.copy(this.parent.matrixWorld).invert().multiply(this.light.matrixWorld);
|
|
} else {
|
|
this.matrix.copy(this.light.matrixWorld);
|
|
}
|
|
this.matrixWorld.copy(this.light.matrixWorld);
|
|
const coneLength = this.light.distance ? this.light.distance : 1000;
|
|
const coneWidth = coneLength * Math.tan(this.light.angle);
|
|
this.cone.scale.set(coneWidth, coneWidth, coneLength);
|
|
_vector$3.setFromMatrixPosition(this.light.target.matrixWorld);
|
|
this.cone.lookAt(_vector$3);
|
|
if (this.color !== undefined) {
|
|
this.cone.material.color.set(this.color);
|
|
} else {
|
|
this.cone.material.color.copy(this.light.color);
|
|
}
|
|
}
|
|
};
|
|
_vector$2 = /* @__PURE__ */ new Vector3;
|
|
_boneMatrix = /* @__PURE__ */ new Matrix4;
|
|
_matrixWorldInv = /* @__PURE__ */ new Matrix4;
|
|
SkeletonHelper = class SkeletonHelper extends LineSegments {
|
|
constructor(object) {
|
|
const bones = getBoneList(object);
|
|
const geometry = new BufferGeometry;
|
|
const vertices = [];
|
|
const colors = [];
|
|
const color1 = new Color(0, 0, 1);
|
|
const color2 = new Color(0, 1, 0);
|
|
for (let i = 0;i < bones.length; i++) {
|
|
const bone = bones[i];
|
|
if (bone.parent && bone.parent.isBone) {
|
|
vertices.push(0, 0, 0);
|
|
vertices.push(0, 0, 0);
|
|
colors.push(color1.r, color1.g, color1.b);
|
|
colors.push(color2.r, color2.g, color2.b);
|
|
}
|
|
}
|
|
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
geometry.setAttribute("color", new Float32BufferAttribute(colors, 3));
|
|
const material = new LineBasicMaterial({ vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true });
|
|
super(geometry, material);
|
|
this.isSkeletonHelper = true;
|
|
this.type = "SkeletonHelper";
|
|
this.root = object;
|
|
this.bones = bones;
|
|
this.matrix = object.matrixWorld;
|
|
this.matrixAutoUpdate = false;
|
|
}
|
|
updateMatrixWorld(force) {
|
|
const bones = this.bones;
|
|
const geometry = this.geometry;
|
|
const position = geometry.getAttribute("position");
|
|
_matrixWorldInv.copy(this.root.matrixWorld).invert();
|
|
for (let i = 0, j = 0;i < bones.length; i++) {
|
|
const bone = bones[i];
|
|
if (bone.parent && bone.parent.isBone) {
|
|
_boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
|
|
_vector$2.setFromMatrixPosition(_boneMatrix);
|
|
position.setXYZ(j, _vector$2.x, _vector$2.y, _vector$2.z);
|
|
_boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
|
|
_vector$2.setFromMatrixPosition(_boneMatrix);
|
|
position.setXYZ(j + 1, _vector$2.x, _vector$2.y, _vector$2.z);
|
|
j += 2;
|
|
}
|
|
}
|
|
geometry.getAttribute("position").needsUpdate = true;
|
|
super.updateMatrixWorld(force);
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
}
|
|
};
|
|
PointLightHelper = class PointLightHelper extends Mesh {
|
|
constructor(light, sphereSize, color) {
|
|
const geometry = new SphereGeometry(sphereSize, 4, 2);
|
|
const material = new MeshBasicMaterial({ wireframe: true, fog: false, toneMapped: false });
|
|
super(geometry, material);
|
|
this.light = light;
|
|
this.color = color;
|
|
this.type = "PointLightHelper";
|
|
this.matrix = this.light.matrixWorld;
|
|
this.matrixAutoUpdate = false;
|
|
this.update();
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
}
|
|
update() {
|
|
this.light.updateWorldMatrix(true, false);
|
|
if (this.color !== undefined) {
|
|
this.material.color.set(this.color);
|
|
} else {
|
|
this.material.color.copy(this.light.color);
|
|
}
|
|
}
|
|
};
|
|
_vector$1 = /* @__PURE__ */ new Vector3;
|
|
_color1 = /* @__PURE__ */ new Color;
|
|
_color2 = /* @__PURE__ */ new Color;
|
|
HemisphereLightHelper = class HemisphereLightHelper extends Object3D {
|
|
constructor(light, size, color) {
|
|
super();
|
|
this.light = light;
|
|
this.matrix = light.matrixWorld;
|
|
this.matrixAutoUpdate = false;
|
|
this.color = color;
|
|
this.type = "HemisphereLightHelper";
|
|
const geometry = new OctahedronGeometry(size);
|
|
geometry.rotateY(Math.PI * 0.5);
|
|
this.material = new MeshBasicMaterial({ wireframe: true, fog: false, toneMapped: false });
|
|
if (this.color === undefined)
|
|
this.material.vertexColors = true;
|
|
const position = geometry.getAttribute("position");
|
|
const colors = new Float32Array(position.count * 3);
|
|
geometry.setAttribute("color", new BufferAttribute(colors, 3));
|
|
this.add(new Mesh(geometry, this.material));
|
|
this.update();
|
|
}
|
|
dispose() {
|
|
this.children[0].geometry.dispose();
|
|
this.children[0].material.dispose();
|
|
}
|
|
update() {
|
|
const mesh = this.children[0];
|
|
if (this.color !== undefined) {
|
|
this.material.color.set(this.color);
|
|
} else {
|
|
const colors = mesh.geometry.getAttribute("color");
|
|
_color1.copy(this.light.color);
|
|
_color2.copy(this.light.groundColor);
|
|
for (let i = 0, l = colors.count;i < l; i++) {
|
|
const color = i < l / 2 ? _color1 : _color2;
|
|
colors.setXYZ(i, color.r, color.g, color.b);
|
|
}
|
|
colors.needsUpdate = true;
|
|
}
|
|
this.light.updateWorldMatrix(true, false);
|
|
mesh.lookAt(_vector$1.setFromMatrixPosition(this.light.matrixWorld).negate());
|
|
}
|
|
};
|
|
GridHelper = class GridHelper extends LineSegments {
|
|
constructor(size = 10, divisions = 10, color1 = 4473924, color2 = 8947848) {
|
|
color1 = new Color(color1);
|
|
color2 = new Color(color2);
|
|
const center = divisions / 2;
|
|
const step = size / divisions;
|
|
const halfSize = size / 2;
|
|
const vertices = [], colors = [];
|
|
for (let i = 0, j = 0, k = -halfSize;i <= divisions; i++, k += step) {
|
|
vertices.push(-halfSize, 0, k, halfSize, 0, k);
|
|
vertices.push(k, 0, -halfSize, k, 0, halfSize);
|
|
const color = i === center ? color1 : color2;
|
|
color.toArray(colors, j);
|
|
j += 3;
|
|
color.toArray(colors, j);
|
|
j += 3;
|
|
color.toArray(colors, j);
|
|
j += 3;
|
|
color.toArray(colors, j);
|
|
j += 3;
|
|
}
|
|
const geometry = new BufferGeometry;
|
|
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
geometry.setAttribute("color", new Float32BufferAttribute(colors, 3));
|
|
const material = new LineBasicMaterial({ vertexColors: true, toneMapped: false });
|
|
super(geometry, material);
|
|
this.type = "GridHelper";
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
}
|
|
};
|
|
PolarGridHelper = class PolarGridHelper extends LineSegments {
|
|
constructor(radius = 10, sectors = 16, rings = 8, divisions = 64, color1 = 4473924, color2 = 8947848) {
|
|
color1 = new Color(color1);
|
|
color2 = new Color(color2);
|
|
const vertices = [];
|
|
const colors = [];
|
|
if (sectors > 1) {
|
|
for (let i = 0;i < sectors; i++) {
|
|
const v = i / sectors * (Math.PI * 2);
|
|
const x = Math.sin(v) * radius;
|
|
const z = Math.cos(v) * radius;
|
|
vertices.push(0, 0, 0);
|
|
vertices.push(x, 0, z);
|
|
const color = i & 1 ? color1 : color2;
|
|
colors.push(color.r, color.g, color.b);
|
|
colors.push(color.r, color.g, color.b);
|
|
}
|
|
}
|
|
for (let i = 0;i < rings; i++) {
|
|
const color = i & 1 ? color1 : color2;
|
|
const r = radius - radius / rings * i;
|
|
for (let j = 0;j < divisions; j++) {
|
|
let v = j / divisions * (Math.PI * 2);
|
|
let x = Math.sin(v) * r;
|
|
let z = Math.cos(v) * r;
|
|
vertices.push(x, 0, z);
|
|
colors.push(color.r, color.g, color.b);
|
|
v = (j + 1) / divisions * (Math.PI * 2);
|
|
x = Math.sin(v) * r;
|
|
z = Math.cos(v) * r;
|
|
vertices.push(x, 0, z);
|
|
colors.push(color.r, color.g, color.b);
|
|
}
|
|
}
|
|
const geometry = new BufferGeometry;
|
|
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
geometry.setAttribute("color", new Float32BufferAttribute(colors, 3));
|
|
const material = new LineBasicMaterial({ vertexColors: true, toneMapped: false });
|
|
super(geometry, material);
|
|
this.type = "PolarGridHelper";
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
}
|
|
};
|
|
_v1 = /* @__PURE__ */ new Vector3;
|
|
_v2 = /* @__PURE__ */ new Vector3;
|
|
_v3 = /* @__PURE__ */ new Vector3;
|
|
DirectionalLightHelper = class DirectionalLightHelper extends Object3D {
|
|
constructor(light, size, color) {
|
|
super();
|
|
this.light = light;
|
|
this.matrix = light.matrixWorld;
|
|
this.matrixAutoUpdate = false;
|
|
this.color = color;
|
|
this.type = "DirectionalLightHelper";
|
|
if (size === undefined)
|
|
size = 1;
|
|
let geometry = new BufferGeometry;
|
|
geometry.setAttribute("position", new Float32BufferAttribute([
|
|
-size,
|
|
size,
|
|
0,
|
|
size,
|
|
size,
|
|
0,
|
|
size,
|
|
-size,
|
|
0,
|
|
-size,
|
|
-size,
|
|
0,
|
|
-size,
|
|
size,
|
|
0
|
|
], 3));
|
|
const material = new LineBasicMaterial({ fog: false, toneMapped: false });
|
|
this.lightPlane = new Line(geometry, material);
|
|
this.add(this.lightPlane);
|
|
geometry = new BufferGeometry;
|
|
geometry.setAttribute("position", new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
|
|
this.targetLine = new Line(geometry, material);
|
|
this.add(this.targetLine);
|
|
this.update();
|
|
}
|
|
dispose() {
|
|
this.lightPlane.geometry.dispose();
|
|
this.lightPlane.material.dispose();
|
|
this.targetLine.geometry.dispose();
|
|
this.targetLine.material.dispose();
|
|
}
|
|
update() {
|
|
this.light.updateWorldMatrix(true, false);
|
|
this.light.target.updateWorldMatrix(true, false);
|
|
_v1.setFromMatrixPosition(this.light.matrixWorld);
|
|
_v2.setFromMatrixPosition(this.light.target.matrixWorld);
|
|
_v3.subVectors(_v2, _v1);
|
|
this.lightPlane.lookAt(_v2);
|
|
if (this.color !== undefined) {
|
|
this.lightPlane.material.color.set(this.color);
|
|
this.targetLine.material.color.set(this.color);
|
|
} else {
|
|
this.lightPlane.material.color.copy(this.light.color);
|
|
this.targetLine.material.color.copy(this.light.color);
|
|
}
|
|
this.targetLine.lookAt(_v2);
|
|
this.targetLine.scale.z = _v3.length();
|
|
}
|
|
};
|
|
_vector = /* @__PURE__ */ new Vector3;
|
|
_camera = /* @__PURE__ */ new Camera;
|
|
CameraHelper = class CameraHelper extends LineSegments {
|
|
constructor(camera) {
|
|
const geometry = new BufferGeometry;
|
|
const material = new LineBasicMaterial({ color: 16777215, vertexColors: true, toneMapped: false });
|
|
const vertices = [];
|
|
const colors = [];
|
|
const pointMap = {};
|
|
addLine("n1", "n2");
|
|
addLine("n2", "n4");
|
|
addLine("n4", "n3");
|
|
addLine("n3", "n1");
|
|
addLine("f1", "f2");
|
|
addLine("f2", "f4");
|
|
addLine("f4", "f3");
|
|
addLine("f3", "f1");
|
|
addLine("n1", "f1");
|
|
addLine("n2", "f2");
|
|
addLine("n3", "f3");
|
|
addLine("n4", "f4");
|
|
addLine("p", "n1");
|
|
addLine("p", "n2");
|
|
addLine("p", "n3");
|
|
addLine("p", "n4");
|
|
addLine("u1", "u2");
|
|
addLine("u2", "u3");
|
|
addLine("u3", "u1");
|
|
addLine("c", "t");
|
|
addLine("p", "c");
|
|
addLine("cn1", "cn2");
|
|
addLine("cn3", "cn4");
|
|
addLine("cf1", "cf2");
|
|
addLine("cf3", "cf4");
|
|
function addLine(a, b) {
|
|
addPoint(a);
|
|
addPoint(b);
|
|
}
|
|
function addPoint(id) {
|
|
vertices.push(0, 0, 0);
|
|
colors.push(0, 0, 0);
|
|
if (pointMap[id] === undefined) {
|
|
pointMap[id] = [];
|
|
}
|
|
pointMap[id].push(vertices.length / 3 - 1);
|
|
}
|
|
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
geometry.setAttribute("color", new Float32BufferAttribute(colors, 3));
|
|
super(geometry, material);
|
|
this.type = "CameraHelper";
|
|
this.camera = camera;
|
|
if (this.camera.updateProjectionMatrix)
|
|
this.camera.updateProjectionMatrix();
|
|
this.matrix = camera.matrixWorld;
|
|
this.matrixAutoUpdate = false;
|
|
this.pointMap = pointMap;
|
|
this.update();
|
|
const colorFrustum = new Color(16755200);
|
|
const colorCone = new Color(16711680);
|
|
const colorUp = new Color(43775);
|
|
const colorTarget = new Color(16777215);
|
|
const colorCross = new Color(3355443);
|
|
this.setColors(colorFrustum, colorCone, colorUp, colorTarget, colorCross);
|
|
}
|
|
setColors(frustum, cone, up, target, cross) {
|
|
const geometry = this.geometry;
|
|
const colorAttribute = geometry.getAttribute("color");
|
|
colorAttribute.setXYZ(0, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(1, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(2, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(3, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(4, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(5, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(6, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(7, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(8, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(9, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(10, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(11, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(12, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(13, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(14, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(15, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(16, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(17, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(18, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(19, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(20, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(21, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(22, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(23, frustum.r, frustum.g, frustum.b);
|
|
colorAttribute.setXYZ(24, cone.r, cone.g, cone.b);
|
|
colorAttribute.setXYZ(25, cone.r, cone.g, cone.b);
|
|
colorAttribute.setXYZ(26, cone.r, cone.g, cone.b);
|
|
colorAttribute.setXYZ(27, cone.r, cone.g, cone.b);
|
|
colorAttribute.setXYZ(28, cone.r, cone.g, cone.b);
|
|
colorAttribute.setXYZ(29, cone.r, cone.g, cone.b);
|
|
colorAttribute.setXYZ(30, cone.r, cone.g, cone.b);
|
|
colorAttribute.setXYZ(31, cone.r, cone.g, cone.b);
|
|
colorAttribute.setXYZ(32, up.r, up.g, up.b);
|
|
colorAttribute.setXYZ(33, up.r, up.g, up.b);
|
|
colorAttribute.setXYZ(34, up.r, up.g, up.b);
|
|
colorAttribute.setXYZ(35, up.r, up.g, up.b);
|
|
colorAttribute.setXYZ(36, up.r, up.g, up.b);
|
|
colorAttribute.setXYZ(37, up.r, up.g, up.b);
|
|
colorAttribute.setXYZ(38, target.r, target.g, target.b);
|
|
colorAttribute.setXYZ(39, target.r, target.g, target.b);
|
|
colorAttribute.setXYZ(40, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(41, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(42, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(43, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(44, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(45, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(46, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(47, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(48, cross.r, cross.g, cross.b);
|
|
colorAttribute.setXYZ(49, cross.r, cross.g, cross.b);
|
|
colorAttribute.needsUpdate = true;
|
|
}
|
|
update() {
|
|
const geometry = this.geometry;
|
|
const pointMap = this.pointMap;
|
|
const w = 1, h = 1;
|
|
_camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse);
|
|
const nearZ = this.camera.coordinateSystem === WebGLCoordinateSystem ? -1 : 0;
|
|
setPoint("c", pointMap, geometry, _camera, 0, 0, nearZ);
|
|
setPoint("t", pointMap, geometry, _camera, 0, 0, 1);
|
|
setPoint("n1", pointMap, geometry, _camera, -1, -1, nearZ);
|
|
setPoint("n2", pointMap, geometry, _camera, w, -1, nearZ);
|
|
setPoint("n3", pointMap, geometry, _camera, -1, h, nearZ);
|
|
setPoint("n4", pointMap, geometry, _camera, w, h, nearZ);
|
|
setPoint("f1", pointMap, geometry, _camera, -1, -1, 1);
|
|
setPoint("f2", pointMap, geometry, _camera, w, -1, 1);
|
|
setPoint("f3", pointMap, geometry, _camera, -1, h, 1);
|
|
setPoint("f4", pointMap, geometry, _camera, w, h, 1);
|
|
setPoint("u1", pointMap, geometry, _camera, w * 0.7, h * 1.1, nearZ);
|
|
setPoint("u2", pointMap, geometry, _camera, -1 * 0.7, h * 1.1, nearZ);
|
|
setPoint("u3", pointMap, geometry, _camera, 0, h * 2, nearZ);
|
|
setPoint("cf1", pointMap, geometry, _camera, -1, 0, 1);
|
|
setPoint("cf2", pointMap, geometry, _camera, w, 0, 1);
|
|
setPoint("cf3", pointMap, geometry, _camera, 0, -1, 1);
|
|
setPoint("cf4", pointMap, geometry, _camera, 0, h, 1);
|
|
setPoint("cn1", pointMap, geometry, _camera, -1, 0, nearZ);
|
|
setPoint("cn2", pointMap, geometry, _camera, w, 0, nearZ);
|
|
setPoint("cn3", pointMap, geometry, _camera, 0, -1, nearZ);
|
|
setPoint("cn4", pointMap, geometry, _camera, 0, h, nearZ);
|
|
geometry.getAttribute("position").needsUpdate = true;
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
}
|
|
};
|
|
_box = /* @__PURE__ */ new Box3;
|
|
BoxHelper = class BoxHelper extends LineSegments {
|
|
constructor(object, color = 16776960) {
|
|
const indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
|
|
const positions = new Float32Array(8 * 3);
|
|
const geometry = new BufferGeometry;
|
|
geometry.setIndex(new BufferAttribute(indices, 1));
|
|
geometry.setAttribute("position", new BufferAttribute(positions, 3));
|
|
super(geometry, new LineBasicMaterial({ color, toneMapped: false }));
|
|
this.object = object;
|
|
this.type = "BoxHelper";
|
|
this.matrixAutoUpdate = false;
|
|
this.update();
|
|
}
|
|
update(object) {
|
|
if (object !== undefined) {
|
|
console.warn("THREE.BoxHelper: .update() has no longer arguments.");
|
|
}
|
|
if (this.object !== undefined) {
|
|
_box.setFromObject(this.object);
|
|
}
|
|
if (_box.isEmpty())
|
|
return;
|
|
const min = _box.min;
|
|
const max = _box.max;
|
|
const position = this.geometry.attributes.position;
|
|
const array = position.array;
|
|
array[0] = max.x;
|
|
array[1] = max.y;
|
|
array[2] = max.z;
|
|
array[3] = min.x;
|
|
array[4] = max.y;
|
|
array[5] = max.z;
|
|
array[6] = min.x;
|
|
array[7] = min.y;
|
|
array[8] = max.z;
|
|
array[9] = max.x;
|
|
array[10] = min.y;
|
|
array[11] = max.z;
|
|
array[12] = max.x;
|
|
array[13] = max.y;
|
|
array[14] = min.z;
|
|
array[15] = min.x;
|
|
array[16] = max.y;
|
|
array[17] = min.z;
|
|
array[18] = min.x;
|
|
array[19] = min.y;
|
|
array[20] = min.z;
|
|
array[21] = max.x;
|
|
array[22] = min.y;
|
|
array[23] = min.z;
|
|
position.needsUpdate = true;
|
|
this.geometry.computeBoundingSphere();
|
|
}
|
|
setFromObject(object) {
|
|
this.object = object;
|
|
this.update();
|
|
return this;
|
|
}
|
|
copy(source, recursive) {
|
|
super.copy(source, recursive);
|
|
this.object = source.object;
|
|
return this;
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
}
|
|
};
|
|
Box3Helper = class Box3Helper extends LineSegments {
|
|
constructor(box, color = 16776960) {
|
|
const indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
|
|
const positions = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1];
|
|
const geometry = new BufferGeometry;
|
|
geometry.setIndex(new BufferAttribute(indices, 1));
|
|
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
super(geometry, new LineBasicMaterial({ color, toneMapped: false }));
|
|
this.box = box;
|
|
this.type = "Box3Helper";
|
|
this.geometry.computeBoundingSphere();
|
|
}
|
|
updateMatrixWorld(force) {
|
|
const box = this.box;
|
|
if (box.isEmpty())
|
|
return;
|
|
box.getCenter(this.position);
|
|
box.getSize(this.scale);
|
|
this.scale.multiplyScalar(0.5);
|
|
super.updateMatrixWorld(force);
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
}
|
|
};
|
|
PlaneHelper = class PlaneHelper extends Line {
|
|
constructor(plane, size = 1, hex = 16776960) {
|
|
const color = hex;
|
|
const positions = [1, -1, 0, -1, 1, 0, -1, -1, 0, 1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0, 1, 1, 0];
|
|
const geometry = new BufferGeometry;
|
|
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
geometry.computeBoundingSphere();
|
|
super(geometry, new LineBasicMaterial({ color, toneMapped: false }));
|
|
this.type = "PlaneHelper";
|
|
this.plane = plane;
|
|
this.size = size;
|
|
const positions2 = [1, 1, 0, -1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, -1, 0];
|
|
const geometry2 = new BufferGeometry;
|
|
geometry2.setAttribute("position", new Float32BufferAttribute(positions2, 3));
|
|
geometry2.computeBoundingSphere();
|
|
this.add(new Mesh(geometry2, new MeshBasicMaterial({ color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false })));
|
|
}
|
|
updateMatrixWorld(force) {
|
|
this.position.set(0, 0, 0);
|
|
this.scale.set(0.5 * this.size, 0.5 * this.size, 1);
|
|
this.lookAt(this.plane.normal);
|
|
this.translateZ(-this.plane.constant);
|
|
super.updateMatrixWorld(force);
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
this.children[0].geometry.dispose();
|
|
this.children[0].material.dispose();
|
|
}
|
|
};
|
|
_axis = /* @__PURE__ */ new Vector3;
|
|
ArrowHelper = class ArrowHelper extends Object3D {
|
|
constructor(dir = new Vector3(0, 0, 1), origin = new Vector3(0, 0, 0), length = 1, color = 16776960, headLength = length * 0.2, headWidth = headLength * 0.2) {
|
|
super();
|
|
this.type = "ArrowHelper";
|
|
if (_lineGeometry === undefined) {
|
|
_lineGeometry = new BufferGeometry;
|
|
_lineGeometry.setAttribute("position", new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
|
|
_coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
|
|
_coneGeometry.translate(0, -0.5, 0);
|
|
}
|
|
this.position.copy(origin);
|
|
this.line = new Line(_lineGeometry, new LineBasicMaterial({ color, toneMapped: false }));
|
|
this.line.matrixAutoUpdate = false;
|
|
this.add(this.line);
|
|
this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({ color, toneMapped: false }));
|
|
this.cone.matrixAutoUpdate = false;
|
|
this.add(this.cone);
|
|
this.setDirection(dir);
|
|
this.setLength(length, headLength, headWidth);
|
|
}
|
|
setDirection(dir) {
|
|
if (dir.y > 0.99999) {
|
|
this.quaternion.set(0, 0, 0, 1);
|
|
} else if (dir.y < -0.99999) {
|
|
this.quaternion.set(1, 0, 0, 0);
|
|
} else {
|
|
_axis.set(dir.z, 0, -dir.x).normalize();
|
|
const radians = Math.acos(dir.y);
|
|
this.quaternion.setFromAxisAngle(_axis, radians);
|
|
}
|
|
}
|
|
setLength(length, headLength = length * 0.2, headWidth = headLength * 0.2) {
|
|
this.line.scale.set(1, Math.max(0.0001, length - headLength), 1);
|
|
this.line.updateMatrix();
|
|
this.cone.scale.set(headWidth, headLength, headWidth);
|
|
this.cone.position.y = length;
|
|
this.cone.updateMatrix();
|
|
}
|
|
setColor(color) {
|
|
this.line.material.color.set(color);
|
|
this.cone.material.color.set(color);
|
|
}
|
|
copy(source) {
|
|
super.copy(source, false);
|
|
this.line.copy(source.line);
|
|
this.cone.copy(source.cone);
|
|
return this;
|
|
}
|
|
dispose() {
|
|
this.line.geometry.dispose();
|
|
this.line.material.dispose();
|
|
this.cone.geometry.dispose();
|
|
this.cone.material.dispose();
|
|
}
|
|
};
|
|
AxesHelper = class AxesHelper extends LineSegments {
|
|
constructor(size = 1) {
|
|
const vertices = [
|
|
0,
|
|
0,
|
|
0,
|
|
size,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
size,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
size
|
|
];
|
|
const colors = [
|
|
1,
|
|
0,
|
|
0,
|
|
1,
|
|
0.6,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0.6,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0.6,
|
|
1
|
|
];
|
|
const geometry = new BufferGeometry;
|
|
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
|
geometry.setAttribute("color", new Float32BufferAttribute(colors, 3));
|
|
const material = new LineBasicMaterial({ vertexColors: true, toneMapped: false });
|
|
super(geometry, material);
|
|
this.type = "AxesHelper";
|
|
}
|
|
setColors(xAxisColor, yAxisColor, zAxisColor) {
|
|
const color = new Color;
|
|
const array = this.geometry.attributes.color.array;
|
|
color.set(xAxisColor);
|
|
color.toArray(array, 0);
|
|
color.toArray(array, 3);
|
|
color.set(yAxisColor);
|
|
color.toArray(array, 6);
|
|
color.toArray(array, 9);
|
|
color.set(zAxisColor);
|
|
color.toArray(array, 12);
|
|
color.toArray(array, 15);
|
|
this.geometry.attributes.color.needsUpdate = true;
|
|
return this;
|
|
}
|
|
dispose() {
|
|
this.geometry.dispose();
|
|
this.material.dispose();
|
|
}
|
|
};
|
|
Controls = class Controls extends EventDispatcher {
|
|
constructor(object, domElement = null) {
|
|
super();
|
|
this.object = object;
|
|
this.domElement = domElement;
|
|
this.enabled = true;
|
|
this.state = -1;
|
|
this.keys = {};
|
|
this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };
|
|
this.touches = { ONE: null, TWO: null };
|
|
}
|
|
connect() {}
|
|
disconnect() {}
|
|
dispose() {}
|
|
update() {}
|
|
};
|
|
TextureUtils = {
|
|
contain,
|
|
cover,
|
|
fill,
|
|
getByteLength
|
|
};
|
|
if (typeof __THREE_DEVTOOLS__ !== "undefined") {
|
|
__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register", { detail: {
|
|
revision: REVISION
|
|
} }));
|
|
}
|
|
if (typeof window !== "undefined") {
|
|
if (window.__THREE__) {
|
|
console.warn("WARNING: Multiple instances of Three.js being imported.");
|
|
} else {
|
|
window.__THREE__ = REVISION;
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/three/build/three.module.js
|
|
var exports_three_module = {};
|
|
__export(exports_three_module, {
|
|
createCanvasElement: () => createCanvasElement,
|
|
ZeroStencilOp: () => ZeroStencilOp,
|
|
ZeroSlopeEnding: () => ZeroSlopeEnding,
|
|
ZeroFactor: () => ZeroFactor,
|
|
ZeroCurvatureEnding: () => ZeroCurvatureEnding,
|
|
WrapAroundEnding: () => WrapAroundEnding,
|
|
WireframeGeometry: () => WireframeGeometry,
|
|
WebXRController: () => WebXRController,
|
|
WebGPUCoordinateSystem: () => WebGPUCoordinateSystem,
|
|
WebGLUtils: () => WebGLUtils,
|
|
WebGLRenderer: () => WebGLRenderer,
|
|
WebGLRenderTarget: () => WebGLRenderTarget,
|
|
WebGLCubeRenderTarget: () => WebGLCubeRenderTarget,
|
|
WebGLCoordinateSystem: () => WebGLCoordinateSystem,
|
|
WebGLArrayRenderTarget: () => WebGLArrayRenderTarget,
|
|
WebGL3DRenderTarget: () => WebGL3DRenderTarget,
|
|
VideoTexture: () => VideoTexture,
|
|
VideoFrameTexture: () => VideoFrameTexture,
|
|
VectorKeyframeTrack: () => VectorKeyframeTrack,
|
|
Vector4: () => Vector4,
|
|
Vector3: () => Vector3,
|
|
Vector2: () => Vector2,
|
|
VSMShadowMap: () => VSMShadowMap,
|
|
UnsignedShortType: () => UnsignedShortType,
|
|
UnsignedShort5551Type: () => UnsignedShort5551Type,
|
|
UnsignedShort4444Type: () => UnsignedShort4444Type,
|
|
UnsignedIntType: () => UnsignedIntType,
|
|
UnsignedInt5999Type: () => UnsignedInt5999Type,
|
|
UnsignedInt248Type: () => UnsignedInt248Type,
|
|
UnsignedByteType: () => UnsignedByteType,
|
|
UniformsUtils: () => UniformsUtils,
|
|
UniformsLib: () => UniformsLib,
|
|
UniformsGroup: () => UniformsGroup,
|
|
Uniform: () => Uniform,
|
|
Uint8ClampedBufferAttribute: () => Uint8ClampedBufferAttribute,
|
|
Uint8BufferAttribute: () => Uint8BufferAttribute,
|
|
Uint32BufferAttribute: () => Uint32BufferAttribute,
|
|
Uint16BufferAttribute: () => Uint16BufferAttribute,
|
|
UVMapping: () => UVMapping,
|
|
TubeGeometry: () => TubeGeometry,
|
|
TrianglesDrawMode: () => TrianglesDrawMode,
|
|
TriangleStripDrawMode: () => TriangleStripDrawMode,
|
|
TriangleFanDrawMode: () => TriangleFanDrawMode,
|
|
Triangle: () => Triangle,
|
|
TorusKnotGeometry: () => TorusKnotGeometry,
|
|
TorusGeometry: () => TorusGeometry,
|
|
TimestampQuery: () => TimestampQuery,
|
|
TextureUtils: () => TextureUtils,
|
|
TextureLoader: () => TextureLoader,
|
|
Texture: () => Texture,
|
|
TetrahedronGeometry: () => TetrahedronGeometry,
|
|
TangentSpaceNormalMap: () => TangentSpaceNormalMap,
|
|
TOUCH: () => TOUCH,
|
|
SubtractiveBlending: () => SubtractiveBlending,
|
|
SubtractEquation: () => SubtractEquation,
|
|
StringKeyframeTrack: () => StringKeyframeTrack,
|
|
StreamReadUsage: () => StreamReadUsage,
|
|
StreamDrawUsage: () => StreamDrawUsage,
|
|
StreamCopyUsage: () => StreamCopyUsage,
|
|
StereoCamera: () => StereoCamera,
|
|
StaticReadUsage: () => StaticReadUsage,
|
|
StaticDrawUsage: () => StaticDrawUsage,
|
|
StaticCopyUsage: () => StaticCopyUsage,
|
|
SrcColorFactor: () => SrcColorFactor,
|
|
SrcAlphaSaturateFactor: () => SrcAlphaSaturateFactor,
|
|
SrcAlphaFactor: () => SrcAlphaFactor,
|
|
SpriteMaterial: () => SpriteMaterial,
|
|
Sprite: () => Sprite,
|
|
SpotLightHelper: () => SpotLightHelper,
|
|
SpotLight: () => SpotLight,
|
|
SplineCurve: () => SplineCurve,
|
|
SphericalHarmonics3: () => SphericalHarmonics3,
|
|
Spherical: () => Spherical,
|
|
SphereGeometry: () => SphereGeometry,
|
|
Sphere: () => Sphere,
|
|
Source: () => Source,
|
|
SkinnedMesh: () => SkinnedMesh,
|
|
SkeletonHelper: () => SkeletonHelper,
|
|
Skeleton: () => Skeleton,
|
|
ShortType: () => ShortType,
|
|
ShapeUtils: () => ShapeUtils,
|
|
ShapePath: () => ShapePath,
|
|
ShapeGeometry: () => ShapeGeometry,
|
|
Shape: () => Shape,
|
|
ShadowMaterial: () => ShadowMaterial,
|
|
ShaderMaterial: () => ShaderMaterial,
|
|
ShaderLib: () => ShaderLib,
|
|
ShaderChunk: () => ShaderChunk,
|
|
Scene: () => Scene,
|
|
SRGBTransfer: () => SRGBTransfer,
|
|
SRGBColorSpace: () => SRGBColorSpace,
|
|
SIGNED_RED_RGTC1_Format: () => SIGNED_RED_RGTC1_Format,
|
|
SIGNED_RED_GREEN_RGTC2_Format: () => SIGNED_RED_GREEN_RGTC2_Format,
|
|
RingGeometry: () => RingGeometry,
|
|
ReverseSubtractEquation: () => ReverseSubtractEquation,
|
|
ReplaceStencilOp: () => ReplaceStencilOp,
|
|
RepeatWrapping: () => RepeatWrapping,
|
|
RenderTargetArray: () => RenderTargetArray,
|
|
RenderTarget3D: () => RenderTarget3D,
|
|
RenderTarget: () => RenderTarget,
|
|
ReinhardToneMapping: () => ReinhardToneMapping,
|
|
RedIntegerFormat: () => RedIntegerFormat,
|
|
RedFormat: () => RedFormat,
|
|
RectAreaLight: () => RectAreaLight,
|
|
Raycaster: () => Raycaster,
|
|
Ray: () => Ray,
|
|
RawShaderMaterial: () => RawShaderMaterial,
|
|
RGIntegerFormat: () => RGIntegerFormat,
|
|
RGFormat: () => RGFormat,
|
|
RGDepthPacking: () => RGDepthPacking,
|
|
RGB_S3TC_DXT1_Format: () => RGB_S3TC_DXT1_Format,
|
|
RGB_PVRTC_4BPPV1_Format: () => RGB_PVRTC_4BPPV1_Format,
|
|
RGB_PVRTC_2BPPV1_Format: () => RGB_PVRTC_2BPPV1_Format,
|
|
RGB_ETC2_Format: () => RGB_ETC2_Format,
|
|
RGB_ETC1_Format: () => RGB_ETC1_Format,
|
|
RGB_BPTC_UNSIGNED_Format: () => RGB_BPTC_UNSIGNED_Format,
|
|
RGB_BPTC_SIGNED_Format: () => RGB_BPTC_SIGNED_Format,
|
|
RGBIntegerFormat: () => RGBIntegerFormat,
|
|
RGBFormat: () => RGBFormat,
|
|
RGBDepthPacking: () => RGBDepthPacking,
|
|
RGBA_S3TC_DXT5_Format: () => RGBA_S3TC_DXT5_Format,
|
|
RGBA_S3TC_DXT3_Format: () => RGBA_S3TC_DXT3_Format,
|
|
RGBA_S3TC_DXT1_Format: () => RGBA_S3TC_DXT1_Format,
|
|
RGBA_PVRTC_4BPPV1_Format: () => RGBA_PVRTC_4BPPV1_Format,
|
|
RGBA_PVRTC_2BPPV1_Format: () => RGBA_PVRTC_2BPPV1_Format,
|
|
RGBA_ETC2_EAC_Format: () => RGBA_ETC2_EAC_Format,
|
|
RGBA_BPTC_Format: () => RGBA_BPTC_Format,
|
|
RGBA_ASTC_8x8_Format: () => RGBA_ASTC_8x8_Format,
|
|
RGBA_ASTC_8x6_Format: () => RGBA_ASTC_8x6_Format,
|
|
RGBA_ASTC_8x5_Format: () => RGBA_ASTC_8x5_Format,
|
|
RGBA_ASTC_6x6_Format: () => RGBA_ASTC_6x6_Format,
|
|
RGBA_ASTC_6x5_Format: () => RGBA_ASTC_6x5_Format,
|
|
RGBA_ASTC_5x5_Format: () => RGBA_ASTC_5x5_Format,
|
|
RGBA_ASTC_5x4_Format: () => RGBA_ASTC_5x4_Format,
|
|
RGBA_ASTC_4x4_Format: () => RGBA_ASTC_4x4_Format,
|
|
RGBA_ASTC_12x12_Format: () => RGBA_ASTC_12x12_Format,
|
|
RGBA_ASTC_12x10_Format: () => RGBA_ASTC_12x10_Format,
|
|
RGBA_ASTC_10x8_Format: () => RGBA_ASTC_10x8_Format,
|
|
RGBA_ASTC_10x6_Format: () => RGBA_ASTC_10x6_Format,
|
|
RGBA_ASTC_10x5_Format: () => RGBA_ASTC_10x5_Format,
|
|
RGBA_ASTC_10x10_Format: () => RGBA_ASTC_10x10_Format,
|
|
RGBAIntegerFormat: () => RGBAIntegerFormat,
|
|
RGBAFormat: () => RGBAFormat,
|
|
RGBADepthPacking: () => RGBADepthPacking,
|
|
REVISION: () => REVISION,
|
|
RED_RGTC1_Format: () => RED_RGTC1_Format,
|
|
RED_GREEN_RGTC2_Format: () => RED_GREEN_RGTC2_Format,
|
|
QuaternionLinearInterpolant: () => QuaternionLinearInterpolant,
|
|
QuaternionKeyframeTrack: () => QuaternionKeyframeTrack,
|
|
Quaternion: () => Quaternion,
|
|
QuadraticBezierCurve3: () => QuadraticBezierCurve3,
|
|
QuadraticBezierCurve: () => QuadraticBezierCurve,
|
|
PropertyMixer: () => PropertyMixer,
|
|
PropertyBinding: () => PropertyBinding,
|
|
PositionalAudio: () => PositionalAudio,
|
|
PolyhedronGeometry: () => PolyhedronGeometry,
|
|
PolarGridHelper: () => PolarGridHelper,
|
|
PointsMaterial: () => PointsMaterial,
|
|
Points: () => Points,
|
|
PointLightHelper: () => PointLightHelper,
|
|
PointLight: () => PointLight,
|
|
PlaneHelper: () => PlaneHelper,
|
|
PlaneGeometry: () => PlaneGeometry,
|
|
Plane: () => Plane,
|
|
PerspectiveCamera: () => PerspectiveCamera,
|
|
Path: () => Path,
|
|
PMREMGenerator: () => PMREMGenerator,
|
|
PCFSoftShadowMap: () => PCFSoftShadowMap,
|
|
PCFShadowMap: () => PCFShadowMap,
|
|
OrthographicCamera: () => OrthographicCamera,
|
|
OneMinusSrcColorFactor: () => OneMinusSrcColorFactor,
|
|
OneMinusSrcAlphaFactor: () => OneMinusSrcAlphaFactor,
|
|
OneMinusDstColorFactor: () => OneMinusDstColorFactor,
|
|
OneMinusDstAlphaFactor: () => OneMinusDstAlphaFactor,
|
|
OneMinusConstantColorFactor: () => OneMinusConstantColorFactor,
|
|
OneMinusConstantAlphaFactor: () => OneMinusConstantAlphaFactor,
|
|
OneFactor: () => OneFactor,
|
|
OctahedronGeometry: () => OctahedronGeometry,
|
|
ObjectSpaceNormalMap: () => ObjectSpaceNormalMap,
|
|
ObjectLoader: () => ObjectLoader,
|
|
Object3D: () => Object3D,
|
|
NumberKeyframeTrack: () => NumberKeyframeTrack,
|
|
NotEqualStencilFunc: () => NotEqualStencilFunc,
|
|
NotEqualDepth: () => NotEqualDepth,
|
|
NotEqualCompare: () => NotEqualCompare,
|
|
NormalBlending: () => NormalBlending,
|
|
NormalAnimationBlendMode: () => NormalAnimationBlendMode,
|
|
NoToneMapping: () => NoToneMapping,
|
|
NoColorSpace: () => NoColorSpace,
|
|
NoBlending: () => NoBlending,
|
|
NeverStencilFunc: () => NeverStencilFunc,
|
|
NeverDepth: () => NeverDepth,
|
|
NeverCompare: () => NeverCompare,
|
|
NeutralToneMapping: () => NeutralToneMapping,
|
|
NearestMipmapNearestFilter: () => NearestMipmapNearestFilter,
|
|
NearestMipmapLinearFilter: () => NearestMipmapLinearFilter,
|
|
NearestMipMapNearestFilter: () => NearestMipMapNearestFilter,
|
|
NearestMipMapLinearFilter: () => NearestMipMapLinearFilter,
|
|
NearestFilter: () => NearestFilter,
|
|
MultiplyOperation: () => MultiplyOperation,
|
|
MultiplyBlending: () => MultiplyBlending,
|
|
MixOperation: () => MixOperation,
|
|
MirroredRepeatWrapping: () => MirroredRepeatWrapping,
|
|
MinEquation: () => MinEquation,
|
|
MeshToonMaterial: () => MeshToonMaterial,
|
|
MeshStandardMaterial: () => MeshStandardMaterial,
|
|
MeshPhysicalMaterial: () => MeshPhysicalMaterial,
|
|
MeshPhongMaterial: () => MeshPhongMaterial,
|
|
MeshNormalMaterial: () => MeshNormalMaterial,
|
|
MeshMatcapMaterial: () => MeshMatcapMaterial,
|
|
MeshLambertMaterial: () => MeshLambertMaterial,
|
|
MeshDistanceMaterial: () => MeshDistanceMaterial,
|
|
MeshDepthMaterial: () => MeshDepthMaterial,
|
|
MeshBasicMaterial: () => MeshBasicMaterial,
|
|
Mesh: () => Mesh,
|
|
MaxEquation: () => MaxEquation,
|
|
Matrix4: () => Matrix4,
|
|
Matrix3: () => Matrix3,
|
|
Matrix2: () => Matrix2,
|
|
MathUtils: () => MathUtils,
|
|
MaterialLoader: () => MaterialLoader,
|
|
Material: () => Material,
|
|
MOUSE: () => MOUSE,
|
|
LuminanceFormat: () => LuminanceFormat,
|
|
LuminanceAlphaFormat: () => LuminanceAlphaFormat,
|
|
LoopRepeat: () => LoopRepeat,
|
|
LoopPingPong: () => LoopPingPong,
|
|
LoopOnce: () => LoopOnce,
|
|
LoadingManager: () => LoadingManager,
|
|
LoaderUtils: () => LoaderUtils,
|
|
Loader: () => Loader,
|
|
LinearTransfer: () => LinearTransfer,
|
|
LinearToneMapping: () => LinearToneMapping,
|
|
LinearSRGBColorSpace: () => LinearSRGBColorSpace,
|
|
LinearMipmapNearestFilter: () => LinearMipmapNearestFilter,
|
|
LinearMipmapLinearFilter: () => LinearMipmapLinearFilter,
|
|
LinearMipMapNearestFilter: () => LinearMipMapNearestFilter,
|
|
LinearMipMapLinearFilter: () => LinearMipMapLinearFilter,
|
|
LinearInterpolant: () => LinearInterpolant,
|
|
LinearFilter: () => LinearFilter,
|
|
LineSegments: () => LineSegments,
|
|
LineLoop: () => LineLoop,
|
|
LineDashedMaterial: () => LineDashedMaterial,
|
|
LineCurve3: () => LineCurve3,
|
|
LineCurve: () => LineCurve,
|
|
LineBasicMaterial: () => LineBasicMaterial,
|
|
Line3: () => Line3,
|
|
Line: () => Line,
|
|
LightProbe: () => LightProbe,
|
|
Light: () => Light,
|
|
LessStencilFunc: () => LessStencilFunc,
|
|
LessEqualStencilFunc: () => LessEqualStencilFunc,
|
|
LessEqualDepth: () => LessEqualDepth,
|
|
LessEqualCompare: () => LessEqualCompare,
|
|
LessDepth: () => LessDepth,
|
|
LessCompare: () => LessCompare,
|
|
Layers: () => Layers,
|
|
LatheGeometry: () => LatheGeometry,
|
|
LOD: () => LOD,
|
|
KeyframeTrack: () => KeyframeTrack,
|
|
KeepStencilOp: () => KeepStencilOp,
|
|
InvertStencilOp: () => InvertStencilOp,
|
|
InterpolateSmooth: () => InterpolateSmooth,
|
|
InterpolateLinear: () => InterpolateLinear,
|
|
InterpolateDiscrete: () => InterpolateDiscrete,
|
|
Interpolant: () => Interpolant,
|
|
InterleavedBufferAttribute: () => InterleavedBufferAttribute,
|
|
InterleavedBuffer: () => InterleavedBuffer,
|
|
IntType: () => IntType,
|
|
Int8BufferAttribute: () => Int8BufferAttribute,
|
|
Int32BufferAttribute: () => Int32BufferAttribute,
|
|
Int16BufferAttribute: () => Int16BufferAttribute,
|
|
InstancedMesh: () => InstancedMesh,
|
|
InstancedInterleavedBuffer: () => InstancedInterleavedBuffer,
|
|
InstancedBufferGeometry: () => InstancedBufferGeometry,
|
|
InstancedBufferAttribute: () => InstancedBufferAttribute,
|
|
IncrementWrapStencilOp: () => IncrementWrapStencilOp,
|
|
IncrementStencilOp: () => IncrementStencilOp,
|
|
ImageUtils: () => ImageUtils,
|
|
ImageLoader: () => ImageLoader,
|
|
ImageBitmapLoader: () => ImageBitmapLoader,
|
|
IcosahedronGeometry: () => IcosahedronGeometry,
|
|
HemisphereLightHelper: () => HemisphereLightHelper,
|
|
HemisphereLight: () => HemisphereLight,
|
|
HalfFloatType: () => HalfFloatType,
|
|
Group: () => Group,
|
|
GridHelper: () => GridHelper,
|
|
GreaterStencilFunc: () => GreaterStencilFunc,
|
|
GreaterEqualStencilFunc: () => GreaterEqualStencilFunc,
|
|
GreaterEqualDepth: () => GreaterEqualDepth,
|
|
GreaterEqualCompare: () => GreaterEqualCompare,
|
|
GreaterDepth: () => GreaterDepth,
|
|
GreaterCompare: () => GreaterCompare,
|
|
GLSL3: () => GLSL3,
|
|
GLSL1: () => GLSL1,
|
|
GLBufferAttribute: () => GLBufferAttribute,
|
|
Frustum: () => Frustum,
|
|
FrontSide: () => FrontSide,
|
|
FramebufferTexture: () => FramebufferTexture,
|
|
FogExp2: () => FogExp2,
|
|
Fog: () => Fog,
|
|
FloatType: () => FloatType,
|
|
Float32BufferAttribute: () => Float32BufferAttribute,
|
|
Float16BufferAttribute: () => Float16BufferAttribute,
|
|
FileLoader: () => FileLoader,
|
|
ExtrudeGeometry: () => ExtrudeGeometry,
|
|
EventDispatcher: () => EventDispatcher,
|
|
Euler: () => Euler,
|
|
EquirectangularRefractionMapping: () => EquirectangularRefractionMapping,
|
|
EquirectangularReflectionMapping: () => EquirectangularReflectionMapping,
|
|
EqualStencilFunc: () => EqualStencilFunc,
|
|
EqualDepth: () => EqualDepth,
|
|
EqualCompare: () => EqualCompare,
|
|
EllipseCurve: () => EllipseCurve,
|
|
EdgesGeometry: () => EdgesGeometry,
|
|
DynamicReadUsage: () => DynamicReadUsage,
|
|
DynamicDrawUsage: () => DynamicDrawUsage,
|
|
DynamicCopyUsage: () => DynamicCopyUsage,
|
|
DstColorFactor: () => DstColorFactor,
|
|
DstAlphaFactor: () => DstAlphaFactor,
|
|
DoubleSide: () => DoubleSide,
|
|
DodecahedronGeometry: () => DodecahedronGeometry,
|
|
DiscreteInterpolant: () => DiscreteInterpolant,
|
|
DirectionalLightHelper: () => DirectionalLightHelper,
|
|
DirectionalLight: () => DirectionalLight,
|
|
DetachedBindMode: () => DetachedBindMode,
|
|
DepthTexture: () => DepthTexture,
|
|
DepthStencilFormat: () => DepthStencilFormat,
|
|
DepthFormat: () => DepthFormat,
|
|
DefaultLoadingManager: () => DefaultLoadingManager,
|
|
DecrementWrapStencilOp: () => DecrementWrapStencilOp,
|
|
DecrementStencilOp: () => DecrementStencilOp,
|
|
DataUtils: () => DataUtils,
|
|
DataTextureLoader: () => DataTextureLoader,
|
|
DataTexture: () => DataTexture,
|
|
DataArrayTexture: () => DataArrayTexture,
|
|
Data3DTexture: () => Data3DTexture,
|
|
Cylindrical: () => Cylindrical,
|
|
CylinderGeometry: () => CylinderGeometry,
|
|
CustomToneMapping: () => CustomToneMapping,
|
|
CustomBlending: () => CustomBlending,
|
|
CurvePath: () => CurvePath,
|
|
Curve: () => Curve,
|
|
CullFaceNone: () => CullFaceNone,
|
|
CullFaceFrontBack: () => CullFaceFrontBack,
|
|
CullFaceFront: () => CullFaceFront,
|
|
CullFaceBack: () => CullFaceBack,
|
|
CubicInterpolant: () => CubicInterpolant,
|
|
CubicBezierCurve3: () => CubicBezierCurve3,
|
|
CubicBezierCurve: () => CubicBezierCurve,
|
|
CubeUVReflectionMapping: () => CubeUVReflectionMapping,
|
|
CubeTextureLoader: () => CubeTextureLoader,
|
|
CubeTexture: () => CubeTexture,
|
|
CubeRefractionMapping: () => CubeRefractionMapping,
|
|
CubeReflectionMapping: () => CubeReflectionMapping,
|
|
CubeCamera: () => CubeCamera,
|
|
Controls: () => Controls,
|
|
ConstantColorFactor: () => ConstantColorFactor,
|
|
ConstantAlphaFactor: () => ConstantAlphaFactor,
|
|
ConeGeometry: () => ConeGeometry,
|
|
CompressedTextureLoader: () => CompressedTextureLoader,
|
|
CompressedTexture: () => CompressedTexture,
|
|
CompressedCubeTexture: () => CompressedCubeTexture,
|
|
CompressedArrayTexture: () => CompressedArrayTexture,
|
|
ColorManagement: () => ColorManagement,
|
|
ColorKeyframeTrack: () => ColorKeyframeTrack,
|
|
Color: () => Color,
|
|
Clock: () => Clock,
|
|
ClampToEdgeWrapping: () => ClampToEdgeWrapping,
|
|
CircleGeometry: () => CircleGeometry,
|
|
CineonToneMapping: () => CineonToneMapping,
|
|
CatmullRomCurve3: () => CatmullRomCurve3,
|
|
CapsuleGeometry: () => CapsuleGeometry,
|
|
CanvasTexture: () => CanvasTexture,
|
|
CameraHelper: () => CameraHelper,
|
|
Camera: () => Camera,
|
|
Cache: () => Cache,
|
|
ByteType: () => ByteType,
|
|
BufferGeometryLoader: () => BufferGeometryLoader,
|
|
BufferGeometry: () => BufferGeometry,
|
|
BufferAttribute: () => BufferAttribute,
|
|
BoxHelper: () => BoxHelper,
|
|
BoxGeometry: () => BoxGeometry,
|
|
Box3Helper: () => Box3Helper,
|
|
Box3: () => Box3,
|
|
Box2: () => Box2,
|
|
BooleanKeyframeTrack: () => BooleanKeyframeTrack,
|
|
Bone: () => Bone,
|
|
BatchedMesh: () => BatchedMesh,
|
|
BasicShadowMap: () => BasicShadowMap,
|
|
BasicDepthPacking: () => BasicDepthPacking,
|
|
BackSide: () => BackSide,
|
|
AxesHelper: () => AxesHelper,
|
|
AudioLoader: () => AudioLoader,
|
|
AudioListener: () => AudioListener,
|
|
AudioContext: () => AudioContext,
|
|
AudioAnalyser: () => AudioAnalyser,
|
|
Audio: () => Audio,
|
|
AttachedBindMode: () => AttachedBindMode,
|
|
ArrowHelper: () => ArrowHelper,
|
|
ArrayCamera: () => ArrayCamera,
|
|
ArcCurve: () => ArcCurve,
|
|
AnimationUtils: () => AnimationUtils,
|
|
AnimationObjectGroup: () => AnimationObjectGroup,
|
|
AnimationMixer: () => AnimationMixer,
|
|
AnimationLoader: () => AnimationLoader,
|
|
AnimationClip: () => AnimationClip,
|
|
AnimationAction: () => AnimationAction,
|
|
AmbientLight: () => AmbientLight,
|
|
AlwaysStencilFunc: () => AlwaysStencilFunc,
|
|
AlwaysDepth: () => AlwaysDepth,
|
|
AlwaysCompare: () => AlwaysCompare,
|
|
AlphaFormat: () => AlphaFormat,
|
|
AgXToneMapping: () => AgXToneMapping,
|
|
AdditiveBlending: () => AdditiveBlending,
|
|
AdditiveAnimationBlendMode: () => AdditiveAnimationBlendMode,
|
|
AddOperation: () => AddOperation,
|
|
AddEquation: () => AddEquation,
|
|
ACESFilmicToneMapping: () => ACESFilmicToneMapping
|
|
});
|
|
function WebGLAnimation() {
|
|
let context = null;
|
|
let isAnimating = false;
|
|
let animationLoop = null;
|
|
let requestId = null;
|
|
function onAnimationFrame(time, frame) {
|
|
animationLoop(time, frame);
|
|
requestId = context.requestAnimationFrame(onAnimationFrame);
|
|
}
|
|
return {
|
|
start: function() {
|
|
if (isAnimating === true)
|
|
return;
|
|
if (animationLoop === null)
|
|
return;
|
|
requestId = context.requestAnimationFrame(onAnimationFrame);
|
|
isAnimating = true;
|
|
},
|
|
stop: function() {
|
|
context.cancelAnimationFrame(requestId);
|
|
isAnimating = false;
|
|
},
|
|
setAnimationLoop: function(callback) {
|
|
animationLoop = callback;
|
|
},
|
|
setContext: function(value) {
|
|
context = value;
|
|
}
|
|
};
|
|
}
|
|
function WebGLAttributes(gl) {
|
|
const buffers = new WeakMap;
|
|
function createBuffer(attribute, bufferType) {
|
|
const array = attribute.array;
|
|
const usage = attribute.usage;
|
|
const size = array.byteLength;
|
|
const buffer = gl.createBuffer();
|
|
gl.bindBuffer(bufferType, buffer);
|
|
gl.bufferData(bufferType, array, usage);
|
|
attribute.onUploadCallback();
|
|
let type;
|
|
if (array instanceof Float32Array) {
|
|
type = gl.FLOAT;
|
|
} else if (array instanceof Uint16Array) {
|
|
if (attribute.isFloat16BufferAttribute) {
|
|
type = gl.HALF_FLOAT;
|
|
} else {
|
|
type = gl.UNSIGNED_SHORT;
|
|
}
|
|
} else if (array instanceof Int16Array) {
|
|
type = gl.SHORT;
|
|
} else if (array instanceof Uint32Array) {
|
|
type = gl.UNSIGNED_INT;
|
|
} else if (array instanceof Int32Array) {
|
|
type = gl.INT;
|
|
} else if (array instanceof Int8Array) {
|
|
type = gl.BYTE;
|
|
} else if (array instanceof Uint8Array) {
|
|
type = gl.UNSIGNED_BYTE;
|
|
} else if (array instanceof Uint8ClampedArray) {
|
|
type = gl.UNSIGNED_BYTE;
|
|
} else {
|
|
throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: " + array);
|
|
}
|
|
return {
|
|
buffer,
|
|
type,
|
|
bytesPerElement: array.BYTES_PER_ELEMENT,
|
|
version: attribute.version,
|
|
size
|
|
};
|
|
}
|
|
function updateBuffer(buffer, attribute, bufferType) {
|
|
const array = attribute.array;
|
|
const updateRanges = attribute.updateRanges;
|
|
gl.bindBuffer(bufferType, buffer);
|
|
if (updateRanges.length === 0) {
|
|
gl.bufferSubData(bufferType, 0, array);
|
|
} else {
|
|
updateRanges.sort((a, b) => a.start - b.start);
|
|
let mergeIndex = 0;
|
|
for (let i = 1;i < updateRanges.length; i++) {
|
|
const previousRange = updateRanges[mergeIndex];
|
|
const range = updateRanges[i];
|
|
if (range.start <= previousRange.start + previousRange.count + 1) {
|
|
previousRange.count = Math.max(previousRange.count, range.start + range.count - previousRange.start);
|
|
} else {
|
|
++mergeIndex;
|
|
updateRanges[mergeIndex] = range;
|
|
}
|
|
}
|
|
updateRanges.length = mergeIndex + 1;
|
|
for (let i = 0, l = updateRanges.length;i < l; i++) {
|
|
const range = updateRanges[i];
|
|
gl.bufferSubData(bufferType, range.start * array.BYTES_PER_ELEMENT, array, range.start, range.count);
|
|
}
|
|
attribute.clearUpdateRanges();
|
|
}
|
|
attribute.onUploadCallback();
|
|
}
|
|
function get(attribute) {
|
|
if (attribute.isInterleavedBufferAttribute)
|
|
attribute = attribute.data;
|
|
return buffers.get(attribute);
|
|
}
|
|
function remove(attribute) {
|
|
if (attribute.isInterleavedBufferAttribute)
|
|
attribute = attribute.data;
|
|
const data = buffers.get(attribute);
|
|
if (data) {
|
|
gl.deleteBuffer(data.buffer);
|
|
buffers.delete(attribute);
|
|
}
|
|
}
|
|
function update(attribute, bufferType) {
|
|
if (attribute.isInterleavedBufferAttribute)
|
|
attribute = attribute.data;
|
|
if (attribute.isGLBufferAttribute) {
|
|
const cached = buffers.get(attribute);
|
|
if (!cached || cached.version < attribute.version) {
|
|
buffers.set(attribute, {
|
|
buffer: attribute.buffer,
|
|
type: attribute.type,
|
|
bytesPerElement: attribute.elementSize,
|
|
version: attribute.version
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
const data = buffers.get(attribute);
|
|
if (data === undefined) {
|
|
buffers.set(attribute, createBuffer(attribute, bufferType));
|
|
} else if (data.version < attribute.version) {
|
|
if (data.size !== attribute.array.byteLength) {
|
|
throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");
|
|
}
|
|
updateBuffer(data.buffer, attribute, bufferType);
|
|
data.version = attribute.version;
|
|
}
|
|
}
|
|
return {
|
|
get,
|
|
remove,
|
|
update
|
|
};
|
|
}
|
|
function WebGLBackground(renderer, cubemaps, cubeuvmaps, state, objects, alpha, premultipliedAlpha) {
|
|
const clearColor = new Color(0);
|
|
let clearAlpha = alpha === true ? 0 : 1;
|
|
let planeMesh;
|
|
let boxMesh;
|
|
let currentBackground = null;
|
|
let currentBackgroundVersion = 0;
|
|
let currentTonemapping = null;
|
|
function getBackground(scene) {
|
|
let background = scene.isScene === true ? scene.background : null;
|
|
if (background && background.isTexture) {
|
|
const usePMREM = scene.backgroundBlurriness > 0;
|
|
background = (usePMREM ? cubeuvmaps : cubemaps).get(background);
|
|
}
|
|
return background;
|
|
}
|
|
function render(scene) {
|
|
let forceClear = false;
|
|
const background = getBackground(scene);
|
|
if (background === null) {
|
|
setClear(clearColor, clearAlpha);
|
|
} else if (background && background.isColor) {
|
|
setClear(background, 1);
|
|
forceClear = true;
|
|
}
|
|
const environmentBlendMode = renderer.xr.getEnvironmentBlendMode();
|
|
if (environmentBlendMode === "additive") {
|
|
state.buffers.color.setClear(0, 0, 0, 1, premultipliedAlpha);
|
|
} else if (environmentBlendMode === "alpha-blend") {
|
|
state.buffers.color.setClear(0, 0, 0, 0, premultipliedAlpha);
|
|
}
|
|
if (renderer.autoClear || forceClear) {
|
|
state.buffers.depth.setTest(true);
|
|
state.buffers.depth.setMask(true);
|
|
state.buffers.color.setMask(true);
|
|
renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
|
|
}
|
|
}
|
|
function addToRenderList(renderList, scene) {
|
|
const background = getBackground(scene);
|
|
if (background && (background.isCubeTexture || background.mapping === CubeUVReflectionMapping)) {
|
|
if (boxMesh === undefined) {
|
|
boxMesh = new Mesh(new BoxGeometry(1e4, 1e4, 1e4), new ShaderMaterial({
|
|
name: "BackgroundCubeMaterial",
|
|
uniforms: cloneUniforms(ShaderLib.backgroundCube.uniforms),
|
|
vertexShader: ShaderLib.backgroundCube.vertexShader,
|
|
fragmentShader: ShaderLib.backgroundCube.fragmentShader,
|
|
side: BackSide,
|
|
depthTest: false,
|
|
depthWrite: false,
|
|
fog: false
|
|
}));
|
|
boxMesh.geometry.deleteAttribute("normal");
|
|
boxMesh.geometry.deleteAttribute("uv");
|
|
boxMesh.onBeforeRender = function(renderer2, scene2, camera) {
|
|
this.matrixWorld.copyPosition(camera.matrixWorld);
|
|
};
|
|
Object.defineProperty(boxMesh.material, "envMap", {
|
|
get: function() {
|
|
return this.uniforms.envMap.value;
|
|
}
|
|
});
|
|
objects.update(boxMesh);
|
|
}
|
|
_e1$1.copy(scene.backgroundRotation);
|
|
_e1$1.x *= -1;
|
|
_e1$1.y *= -1;
|
|
_e1$1.z *= -1;
|
|
if (background.isCubeTexture && background.isRenderTargetTexture === false) {
|
|
_e1$1.y *= -1;
|
|
_e1$1.z *= -1;
|
|
}
|
|
boxMesh.material.uniforms.envMap.value = background;
|
|
boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background.isRenderTargetTexture === false ? -1 : 1;
|
|
boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness;
|
|
boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;
|
|
boxMesh.material.uniforms.backgroundRotation.value.setFromMatrix4(_m1$12.makeRotationFromEuler(_e1$1));
|
|
boxMesh.material.toneMapped = ColorManagement.getTransfer(background.colorSpace) !== SRGBTransfer;
|
|
if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
|
|
boxMesh.material.needsUpdate = true;
|
|
currentBackground = background;
|
|
currentBackgroundVersion = background.version;
|
|
currentTonemapping = renderer.toneMapping;
|
|
}
|
|
boxMesh.layers.enableAll();
|
|
renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
|
|
} else if (background && background.isTexture) {
|
|
if (planeMesh === undefined) {
|
|
planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
|
|
name: "BackgroundMaterial",
|
|
uniforms: cloneUniforms(ShaderLib.background.uniforms),
|
|
vertexShader: ShaderLib.background.vertexShader,
|
|
fragmentShader: ShaderLib.background.fragmentShader,
|
|
side: FrontSide,
|
|
depthTest: false,
|
|
depthWrite: false,
|
|
fog: false
|
|
}));
|
|
planeMesh.geometry.deleteAttribute("normal");
|
|
Object.defineProperty(planeMesh.material, "map", {
|
|
get: function() {
|
|
return this.uniforms.t2D.value;
|
|
}
|
|
});
|
|
objects.update(planeMesh);
|
|
}
|
|
planeMesh.material.uniforms.t2D.value = background;
|
|
planeMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;
|
|
planeMesh.material.toneMapped = ColorManagement.getTransfer(background.colorSpace) !== SRGBTransfer;
|
|
if (background.matrixAutoUpdate === true) {
|
|
background.updateMatrix();
|
|
}
|
|
planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
|
|
if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
|
|
planeMesh.material.needsUpdate = true;
|
|
currentBackground = background;
|
|
currentBackgroundVersion = background.version;
|
|
currentTonemapping = renderer.toneMapping;
|
|
}
|
|
planeMesh.layers.enableAll();
|
|
renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
|
|
}
|
|
}
|
|
function setClear(color, alpha2) {
|
|
color.getRGB(_rgb, getUnlitUniformColorSpace(renderer));
|
|
state.buffers.color.setClear(_rgb.r, _rgb.g, _rgb.b, alpha2, premultipliedAlpha);
|
|
}
|
|
function dispose() {
|
|
if (boxMesh !== undefined) {
|
|
boxMesh.geometry.dispose();
|
|
boxMesh.material.dispose();
|
|
boxMesh = undefined;
|
|
}
|
|
if (planeMesh !== undefined) {
|
|
planeMesh.geometry.dispose();
|
|
planeMesh.material.dispose();
|
|
planeMesh = undefined;
|
|
}
|
|
}
|
|
return {
|
|
getClearColor: function() {
|
|
return clearColor;
|
|
},
|
|
setClearColor: function(color, alpha2 = 1) {
|
|
clearColor.set(color);
|
|
clearAlpha = alpha2;
|
|
setClear(clearColor, clearAlpha);
|
|
},
|
|
getClearAlpha: function() {
|
|
return clearAlpha;
|
|
},
|
|
setClearAlpha: function(alpha2) {
|
|
clearAlpha = alpha2;
|
|
setClear(clearColor, clearAlpha);
|
|
},
|
|
render,
|
|
addToRenderList,
|
|
dispose
|
|
};
|
|
}
|
|
function WebGLBindingStates(gl, attributes) {
|
|
const maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
const bindingStates = {};
|
|
const defaultState = createBindingState(null);
|
|
let currentState = defaultState;
|
|
let forceUpdate = false;
|
|
function setup(object, material, program, geometry, index) {
|
|
let updateBuffers = false;
|
|
const state = getBindingState(geometry, program, material);
|
|
if (currentState !== state) {
|
|
currentState = state;
|
|
bindVertexArrayObject(currentState.object);
|
|
}
|
|
updateBuffers = needsUpdate(object, geometry, program, index);
|
|
if (updateBuffers)
|
|
saveCache(object, geometry, program, index);
|
|
if (index !== null) {
|
|
attributes.update(index, gl.ELEMENT_ARRAY_BUFFER);
|
|
}
|
|
if (updateBuffers || forceUpdate) {
|
|
forceUpdate = false;
|
|
setupVertexAttributes(object, material, program, geometry);
|
|
if (index !== null) {
|
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, attributes.get(index).buffer);
|
|
}
|
|
}
|
|
}
|
|
function createVertexArrayObject() {
|
|
return gl.createVertexArray();
|
|
}
|
|
function bindVertexArrayObject(vao) {
|
|
return gl.bindVertexArray(vao);
|
|
}
|
|
function deleteVertexArrayObject(vao) {
|
|
return gl.deleteVertexArray(vao);
|
|
}
|
|
function getBindingState(geometry, program, material) {
|
|
const wireframe = material.wireframe === true;
|
|
let programMap = bindingStates[geometry.id];
|
|
if (programMap === undefined) {
|
|
programMap = {};
|
|
bindingStates[geometry.id] = programMap;
|
|
}
|
|
let stateMap = programMap[program.id];
|
|
if (stateMap === undefined) {
|
|
stateMap = {};
|
|
programMap[program.id] = stateMap;
|
|
}
|
|
let state = stateMap[wireframe];
|
|
if (state === undefined) {
|
|
state = createBindingState(createVertexArrayObject());
|
|
stateMap[wireframe] = state;
|
|
}
|
|
return state;
|
|
}
|
|
function createBindingState(vao) {
|
|
const newAttributes = [];
|
|
const enabledAttributes = [];
|
|
const attributeDivisors = [];
|
|
for (let i = 0;i < maxVertexAttributes; i++) {
|
|
newAttributes[i] = 0;
|
|
enabledAttributes[i] = 0;
|
|
attributeDivisors[i] = 0;
|
|
}
|
|
return {
|
|
geometry: null,
|
|
program: null,
|
|
wireframe: false,
|
|
newAttributes,
|
|
enabledAttributes,
|
|
attributeDivisors,
|
|
object: vao,
|
|
attributes: {},
|
|
index: null
|
|
};
|
|
}
|
|
function needsUpdate(object, geometry, program, index) {
|
|
const cachedAttributes = currentState.attributes;
|
|
const geometryAttributes = geometry.attributes;
|
|
let attributesNum = 0;
|
|
const programAttributes = program.getAttributes();
|
|
for (const name in programAttributes) {
|
|
const programAttribute = programAttributes[name];
|
|
if (programAttribute.location >= 0) {
|
|
const cachedAttribute = cachedAttributes[name];
|
|
let geometryAttribute = geometryAttributes[name];
|
|
if (geometryAttribute === undefined) {
|
|
if (name === "instanceMatrix" && object.instanceMatrix)
|
|
geometryAttribute = object.instanceMatrix;
|
|
if (name === "instanceColor" && object.instanceColor)
|
|
geometryAttribute = object.instanceColor;
|
|
}
|
|
if (cachedAttribute === undefined)
|
|
return true;
|
|
if (cachedAttribute.attribute !== geometryAttribute)
|
|
return true;
|
|
if (geometryAttribute && cachedAttribute.data !== geometryAttribute.data)
|
|
return true;
|
|
attributesNum++;
|
|
}
|
|
}
|
|
if (currentState.attributesNum !== attributesNum)
|
|
return true;
|
|
if (currentState.index !== index)
|
|
return true;
|
|
return false;
|
|
}
|
|
function saveCache(object, geometry, program, index) {
|
|
const cache = {};
|
|
const attributes2 = geometry.attributes;
|
|
let attributesNum = 0;
|
|
const programAttributes = program.getAttributes();
|
|
for (const name in programAttributes) {
|
|
const programAttribute = programAttributes[name];
|
|
if (programAttribute.location >= 0) {
|
|
let attribute = attributes2[name];
|
|
if (attribute === undefined) {
|
|
if (name === "instanceMatrix" && object.instanceMatrix)
|
|
attribute = object.instanceMatrix;
|
|
if (name === "instanceColor" && object.instanceColor)
|
|
attribute = object.instanceColor;
|
|
}
|
|
const data = {};
|
|
data.attribute = attribute;
|
|
if (attribute && attribute.data) {
|
|
data.data = attribute.data;
|
|
}
|
|
cache[name] = data;
|
|
attributesNum++;
|
|
}
|
|
}
|
|
currentState.attributes = cache;
|
|
currentState.attributesNum = attributesNum;
|
|
currentState.index = index;
|
|
}
|
|
function initAttributes() {
|
|
const newAttributes = currentState.newAttributes;
|
|
for (let i = 0, il = newAttributes.length;i < il; i++) {
|
|
newAttributes[i] = 0;
|
|
}
|
|
}
|
|
function enableAttribute(attribute) {
|
|
enableAttributeAndDivisor(attribute, 0);
|
|
}
|
|
function enableAttributeAndDivisor(attribute, meshPerAttribute) {
|
|
const newAttributes = currentState.newAttributes;
|
|
const enabledAttributes = currentState.enabledAttributes;
|
|
const attributeDivisors = currentState.attributeDivisors;
|
|
newAttributes[attribute] = 1;
|
|
if (enabledAttributes[attribute] === 0) {
|
|
gl.enableVertexAttribArray(attribute);
|
|
enabledAttributes[attribute] = 1;
|
|
}
|
|
if (attributeDivisors[attribute] !== meshPerAttribute) {
|
|
gl.vertexAttribDivisor(attribute, meshPerAttribute);
|
|
attributeDivisors[attribute] = meshPerAttribute;
|
|
}
|
|
}
|
|
function disableUnusedAttributes() {
|
|
const newAttributes = currentState.newAttributes;
|
|
const enabledAttributes = currentState.enabledAttributes;
|
|
for (let i = 0, il = enabledAttributes.length;i < il; i++) {
|
|
if (enabledAttributes[i] !== newAttributes[i]) {
|
|
gl.disableVertexAttribArray(i);
|
|
enabledAttributes[i] = 0;
|
|
}
|
|
}
|
|
}
|
|
function vertexAttribPointer(index, size, type, normalized, stride, offset, integer) {
|
|
if (integer === true) {
|
|
gl.vertexAttribIPointer(index, size, type, stride, offset);
|
|
} else {
|
|
gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
|
|
}
|
|
}
|
|
function setupVertexAttributes(object, material, program, geometry) {
|
|
initAttributes();
|
|
const geometryAttributes = geometry.attributes;
|
|
const programAttributes = program.getAttributes();
|
|
const materialDefaultAttributeValues = material.defaultAttributeValues;
|
|
for (const name in programAttributes) {
|
|
const programAttribute = programAttributes[name];
|
|
if (programAttribute.location >= 0) {
|
|
let geometryAttribute = geometryAttributes[name];
|
|
if (geometryAttribute === undefined) {
|
|
if (name === "instanceMatrix" && object.instanceMatrix)
|
|
geometryAttribute = object.instanceMatrix;
|
|
if (name === "instanceColor" && object.instanceColor)
|
|
geometryAttribute = object.instanceColor;
|
|
}
|
|
if (geometryAttribute !== undefined) {
|
|
const normalized = geometryAttribute.normalized;
|
|
const size = geometryAttribute.itemSize;
|
|
const attribute = attributes.get(geometryAttribute);
|
|
if (attribute === undefined)
|
|
continue;
|
|
const buffer = attribute.buffer;
|
|
const type = attribute.type;
|
|
const bytesPerElement = attribute.bytesPerElement;
|
|
const integer = type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType;
|
|
if (geometryAttribute.isInterleavedBufferAttribute) {
|
|
const data = geometryAttribute.data;
|
|
const stride = data.stride;
|
|
const offset = geometryAttribute.offset;
|
|
if (data.isInstancedInterleavedBuffer) {
|
|
for (let i = 0;i < programAttribute.locationSize; i++) {
|
|
enableAttributeAndDivisor(programAttribute.location + i, data.meshPerAttribute);
|
|
}
|
|
if (object.isInstancedMesh !== true && geometry._maxInstanceCount === undefined) {
|
|
geometry._maxInstanceCount = data.meshPerAttribute * data.count;
|
|
}
|
|
} else {
|
|
for (let i = 0;i < programAttribute.locationSize; i++) {
|
|
enableAttribute(programAttribute.location + i);
|
|
}
|
|
}
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
for (let i = 0;i < programAttribute.locationSize; i++) {
|
|
vertexAttribPointer(programAttribute.location + i, size / programAttribute.locationSize, type, normalized, stride * bytesPerElement, (offset + size / programAttribute.locationSize * i) * bytesPerElement, integer);
|
|
}
|
|
} else {
|
|
if (geometryAttribute.isInstancedBufferAttribute) {
|
|
for (let i = 0;i < programAttribute.locationSize; i++) {
|
|
enableAttributeAndDivisor(programAttribute.location + i, geometryAttribute.meshPerAttribute);
|
|
}
|
|
if (object.isInstancedMesh !== true && geometry._maxInstanceCount === undefined) {
|
|
geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
|
|
}
|
|
} else {
|
|
for (let i = 0;i < programAttribute.locationSize; i++) {
|
|
enableAttribute(programAttribute.location + i);
|
|
}
|
|
}
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
for (let i = 0;i < programAttribute.locationSize; i++) {
|
|
vertexAttribPointer(programAttribute.location + i, size / programAttribute.locationSize, type, normalized, size * bytesPerElement, size / programAttribute.locationSize * i * bytesPerElement, integer);
|
|
}
|
|
}
|
|
} else if (materialDefaultAttributeValues !== undefined) {
|
|
const value = materialDefaultAttributeValues[name];
|
|
if (value !== undefined) {
|
|
switch (value.length) {
|
|
case 2:
|
|
gl.vertexAttrib2fv(programAttribute.location, value);
|
|
break;
|
|
case 3:
|
|
gl.vertexAttrib3fv(programAttribute.location, value);
|
|
break;
|
|
case 4:
|
|
gl.vertexAttrib4fv(programAttribute.location, value);
|
|
break;
|
|
default:
|
|
gl.vertexAttrib1fv(programAttribute.location, value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
disableUnusedAttributes();
|
|
}
|
|
function dispose() {
|
|
reset();
|
|
for (const geometryId in bindingStates) {
|
|
const programMap = bindingStates[geometryId];
|
|
for (const programId in programMap) {
|
|
const stateMap = programMap[programId];
|
|
for (const wireframe in stateMap) {
|
|
deleteVertexArrayObject(stateMap[wireframe].object);
|
|
delete stateMap[wireframe];
|
|
}
|
|
delete programMap[programId];
|
|
}
|
|
delete bindingStates[geometryId];
|
|
}
|
|
}
|
|
function releaseStatesOfGeometry(geometry) {
|
|
if (bindingStates[geometry.id] === undefined)
|
|
return;
|
|
const programMap = bindingStates[geometry.id];
|
|
for (const programId in programMap) {
|
|
const stateMap = programMap[programId];
|
|
for (const wireframe in stateMap) {
|
|
deleteVertexArrayObject(stateMap[wireframe].object);
|
|
delete stateMap[wireframe];
|
|
}
|
|
delete programMap[programId];
|
|
}
|
|
delete bindingStates[geometry.id];
|
|
}
|
|
function releaseStatesOfProgram(program) {
|
|
for (const geometryId in bindingStates) {
|
|
const programMap = bindingStates[geometryId];
|
|
if (programMap[program.id] === undefined)
|
|
continue;
|
|
const stateMap = programMap[program.id];
|
|
for (const wireframe in stateMap) {
|
|
deleteVertexArrayObject(stateMap[wireframe].object);
|
|
delete stateMap[wireframe];
|
|
}
|
|
delete programMap[program.id];
|
|
}
|
|
}
|
|
function reset() {
|
|
resetDefaultState();
|
|
forceUpdate = true;
|
|
if (currentState === defaultState)
|
|
return;
|
|
currentState = defaultState;
|
|
bindVertexArrayObject(currentState.object);
|
|
}
|
|
function resetDefaultState() {
|
|
defaultState.geometry = null;
|
|
defaultState.program = null;
|
|
defaultState.wireframe = false;
|
|
}
|
|
return {
|
|
setup,
|
|
reset,
|
|
resetDefaultState,
|
|
dispose,
|
|
releaseStatesOfGeometry,
|
|
releaseStatesOfProgram,
|
|
initAttributes,
|
|
enableAttribute,
|
|
disableUnusedAttributes
|
|
};
|
|
}
|
|
function WebGLBufferRenderer(gl, extensions, info) {
|
|
let mode;
|
|
function setMode(value) {
|
|
mode = value;
|
|
}
|
|
function render(start, count) {
|
|
gl.drawArrays(mode, start, count);
|
|
info.update(count, mode, 1);
|
|
}
|
|
function renderInstances(start, count, primcount) {
|
|
if (primcount === 0)
|
|
return;
|
|
gl.drawArraysInstanced(mode, start, count, primcount);
|
|
info.update(count, mode, primcount);
|
|
}
|
|
function renderMultiDraw(starts, counts, drawCount) {
|
|
if (drawCount === 0)
|
|
return;
|
|
const extension = extensions.get("WEBGL_multi_draw");
|
|
extension.multiDrawArraysWEBGL(mode, starts, 0, counts, 0, drawCount);
|
|
let elementCount = 0;
|
|
for (let i = 0;i < drawCount; i++) {
|
|
elementCount += counts[i];
|
|
}
|
|
info.update(elementCount, mode, 1);
|
|
}
|
|
function renderMultiDrawInstances(starts, counts, drawCount, primcount) {
|
|
if (drawCount === 0)
|
|
return;
|
|
const extension = extensions.get("WEBGL_multi_draw");
|
|
if (extension === null) {
|
|
for (let i = 0;i < starts.length; i++) {
|
|
renderInstances(starts[i], counts[i], primcount[i]);
|
|
}
|
|
} else {
|
|
extension.multiDrawArraysInstancedWEBGL(mode, starts, 0, counts, 0, primcount, 0, drawCount);
|
|
let elementCount = 0;
|
|
for (let i = 0;i < drawCount; i++) {
|
|
elementCount += counts[i] * primcount[i];
|
|
}
|
|
info.update(elementCount, mode, 1);
|
|
}
|
|
}
|
|
this.setMode = setMode;
|
|
this.render = render;
|
|
this.renderInstances = renderInstances;
|
|
this.renderMultiDraw = renderMultiDraw;
|
|
this.renderMultiDrawInstances = renderMultiDrawInstances;
|
|
}
|
|
function WebGLCapabilities(gl, extensions, parameters, utils) {
|
|
let maxAnisotropy;
|
|
function getMaxAnisotropy() {
|
|
if (maxAnisotropy !== undefined)
|
|
return maxAnisotropy;
|
|
if (extensions.has("EXT_texture_filter_anisotropic") === true) {
|
|
const extension = extensions.get("EXT_texture_filter_anisotropic");
|
|
maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
|
|
} else {
|
|
maxAnisotropy = 0;
|
|
}
|
|
return maxAnisotropy;
|
|
}
|
|
function textureFormatReadable(textureFormat) {
|
|
if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_FORMAT)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
function textureTypeReadable(textureType) {
|
|
const halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has("EXT_color_buffer_half_float") || extensions.has("EXT_color_buffer_float"));
|
|
if (textureType !== UnsignedByteType && utils.convert(textureType) !== gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_TYPE) && textureType !== FloatType && !halfFloatSupportedByExt) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
function getMaxPrecision(precision2) {
|
|
if (precision2 === "highp") {
|
|
if (gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT).precision > 0 && gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0) {
|
|
return "highp";
|
|
}
|
|
precision2 = "mediump";
|
|
}
|
|
if (precision2 === "mediump") {
|
|
if (gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT).precision > 0 && gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0) {
|
|
return "mediump";
|
|
}
|
|
}
|
|
return "lowp";
|
|
}
|
|
let precision = parameters.precision !== undefined ? parameters.precision : "highp";
|
|
const maxPrecision = getMaxPrecision(precision);
|
|
if (maxPrecision !== precision) {
|
|
console.warn("THREE.WebGLRenderer:", precision, "not supported, using", maxPrecision, "instead.");
|
|
precision = maxPrecision;
|
|
}
|
|
const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
|
|
const reverseDepthBuffer = parameters.reverseDepthBuffer === true && extensions.has("EXT_clip_control");
|
|
const maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
|
|
const maxVertexTextures = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
|
const maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
const maxCubemapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
|
|
const maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
const maxVertexUniforms = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
const maxVaryings = gl.getParameter(gl.MAX_VARYING_VECTORS);
|
|
const maxFragmentUniforms = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
|
|
const vertexTextures = maxVertexTextures > 0;
|
|
const maxSamples = gl.getParameter(gl.MAX_SAMPLES);
|
|
return {
|
|
isWebGL2: true,
|
|
getMaxAnisotropy,
|
|
getMaxPrecision,
|
|
textureFormatReadable,
|
|
textureTypeReadable,
|
|
precision,
|
|
logarithmicDepthBuffer,
|
|
reverseDepthBuffer,
|
|
maxTextures,
|
|
maxVertexTextures,
|
|
maxTextureSize,
|
|
maxCubemapSize,
|
|
maxAttributes,
|
|
maxVertexUniforms,
|
|
maxVaryings,
|
|
maxFragmentUniforms,
|
|
vertexTextures,
|
|
maxSamples
|
|
};
|
|
}
|
|
function WebGLClipping(properties) {
|
|
const scope = this;
|
|
let globalState = null, numGlobalPlanes = 0, localClippingEnabled = false, renderingShadows = false;
|
|
const plane = new Plane, viewNormalMatrix = new Matrix3, uniform = { value: null, needsUpdate: false };
|
|
this.uniform = uniform;
|
|
this.numPlanes = 0;
|
|
this.numIntersection = 0;
|
|
this.init = function(planes, enableLocalClipping) {
|
|
const enabled = planes.length !== 0 || enableLocalClipping || numGlobalPlanes !== 0 || localClippingEnabled;
|
|
localClippingEnabled = enableLocalClipping;
|
|
numGlobalPlanes = planes.length;
|
|
return enabled;
|
|
};
|
|
this.beginShadows = function() {
|
|
renderingShadows = true;
|
|
projectPlanes(null);
|
|
};
|
|
this.endShadows = function() {
|
|
renderingShadows = false;
|
|
};
|
|
this.setGlobalState = function(planes, camera) {
|
|
globalState = projectPlanes(planes, camera, 0);
|
|
};
|
|
this.setState = function(material, camera, useCache) {
|
|
const { clippingPlanes: planes, clipIntersection, clipShadows } = material;
|
|
const materialProperties = properties.get(material);
|
|
if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
|
|
if (renderingShadows) {
|
|
projectPlanes(null);
|
|
} else {
|
|
resetGlobalState();
|
|
}
|
|
} else {
|
|
const nGlobal = renderingShadows ? 0 : numGlobalPlanes, lGlobal = nGlobal * 4;
|
|
let dstArray = materialProperties.clippingState || null;
|
|
uniform.value = dstArray;
|
|
dstArray = projectPlanes(planes, camera, lGlobal, useCache);
|
|
for (let i = 0;i !== lGlobal; ++i) {
|
|
dstArray[i] = globalState[i];
|
|
}
|
|
materialProperties.clippingState = dstArray;
|
|
this.numIntersection = clipIntersection ? this.numPlanes : 0;
|
|
this.numPlanes += nGlobal;
|
|
}
|
|
};
|
|
function resetGlobalState() {
|
|
if (uniform.value !== globalState) {
|
|
uniform.value = globalState;
|
|
uniform.needsUpdate = numGlobalPlanes > 0;
|
|
}
|
|
scope.numPlanes = numGlobalPlanes;
|
|
scope.numIntersection = 0;
|
|
}
|
|
function projectPlanes(planes, camera, dstOffset, skipTransform) {
|
|
const nPlanes = planes !== null ? planes.length : 0;
|
|
let dstArray = null;
|
|
if (nPlanes !== 0) {
|
|
dstArray = uniform.value;
|
|
if (skipTransform !== true || dstArray === null) {
|
|
const flatSize = dstOffset + nPlanes * 4, viewMatrix = camera.matrixWorldInverse;
|
|
viewNormalMatrix.getNormalMatrix(viewMatrix);
|
|
if (dstArray === null || dstArray.length < flatSize) {
|
|
dstArray = new Float32Array(flatSize);
|
|
}
|
|
for (let i = 0, i4 = dstOffset;i !== nPlanes; ++i, i4 += 4) {
|
|
plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
|
|
plane.normal.toArray(dstArray, i4);
|
|
dstArray[i4 + 3] = plane.constant;
|
|
}
|
|
}
|
|
uniform.value = dstArray;
|
|
uniform.needsUpdate = true;
|
|
}
|
|
scope.numPlanes = nPlanes;
|
|
scope.numIntersection = 0;
|
|
return dstArray;
|
|
}
|
|
}
|
|
function WebGLCubeMaps(renderer) {
|
|
let cubemaps = new WeakMap;
|
|
function mapTextureMapping(texture, mapping) {
|
|
if (mapping === EquirectangularReflectionMapping) {
|
|
texture.mapping = CubeReflectionMapping;
|
|
} else if (mapping === EquirectangularRefractionMapping) {
|
|
texture.mapping = CubeRefractionMapping;
|
|
}
|
|
return texture;
|
|
}
|
|
function get(texture) {
|
|
if (texture && texture.isTexture) {
|
|
const mapping = texture.mapping;
|
|
if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
|
|
if (cubemaps.has(texture)) {
|
|
const cubemap = cubemaps.get(texture).texture;
|
|
return mapTextureMapping(cubemap, texture.mapping);
|
|
} else {
|
|
const image = texture.image;
|
|
if (image && image.height > 0) {
|
|
const renderTarget = new WebGLCubeRenderTarget(image.height);
|
|
renderTarget.fromEquirectangularTexture(renderer, texture);
|
|
cubemaps.set(texture, renderTarget);
|
|
texture.addEventListener("dispose", onTextureDispose);
|
|
return mapTextureMapping(renderTarget.texture, texture.mapping);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return texture;
|
|
}
|
|
function onTextureDispose(event) {
|
|
const texture = event.target;
|
|
texture.removeEventListener("dispose", onTextureDispose);
|
|
const cubemap = cubemaps.get(texture);
|
|
if (cubemap !== undefined) {
|
|
cubemaps.delete(texture);
|
|
cubemap.dispose();
|
|
}
|
|
}
|
|
function dispose() {
|
|
cubemaps = new WeakMap;
|
|
}
|
|
return {
|
|
get,
|
|
dispose
|
|
};
|
|
}
|
|
|
|
class PMREMGenerator {
|
|
constructor(renderer) {
|
|
this._renderer = renderer;
|
|
this._pingPongRenderTarget = null;
|
|
this._lodMax = 0;
|
|
this._cubeSize = 0;
|
|
this._lodPlanes = [];
|
|
this._sizeLods = [];
|
|
this._sigmas = [];
|
|
this._blurMaterial = null;
|
|
this._cubemapMaterial = null;
|
|
this._equirectMaterial = null;
|
|
this._compileMaterial(this._blurMaterial);
|
|
}
|
|
fromScene(scene, sigma = 0, near = 0.1, far = 100) {
|
|
_oldTarget = this._renderer.getRenderTarget();
|
|
_oldActiveCubeFace = this._renderer.getActiveCubeFace();
|
|
_oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
|
|
_oldXrEnabled = this._renderer.xr.enabled;
|
|
this._renderer.xr.enabled = false;
|
|
this._setSize(256);
|
|
const cubeUVRenderTarget = this._allocateTargets();
|
|
cubeUVRenderTarget.depthBuffer = true;
|
|
this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
|
|
if (sigma > 0) {
|
|
this._blur(cubeUVRenderTarget, 0, 0, sigma);
|
|
}
|
|
this._applyPMREM(cubeUVRenderTarget);
|
|
this._cleanup(cubeUVRenderTarget);
|
|
return cubeUVRenderTarget;
|
|
}
|
|
fromEquirectangular(equirectangular, renderTarget = null) {
|
|
return this._fromTexture(equirectangular, renderTarget);
|
|
}
|
|
fromCubemap(cubemap, renderTarget = null) {
|
|
return this._fromTexture(cubemap, renderTarget);
|
|
}
|
|
compileCubemapShader() {
|
|
if (this._cubemapMaterial === null) {
|
|
this._cubemapMaterial = _getCubemapMaterial();
|
|
this._compileMaterial(this._cubemapMaterial);
|
|
}
|
|
}
|
|
compileEquirectangularShader() {
|
|
if (this._equirectMaterial === null) {
|
|
this._equirectMaterial = _getEquirectMaterial();
|
|
this._compileMaterial(this._equirectMaterial);
|
|
}
|
|
}
|
|
dispose() {
|
|
this._dispose();
|
|
if (this._cubemapMaterial !== null)
|
|
this._cubemapMaterial.dispose();
|
|
if (this._equirectMaterial !== null)
|
|
this._equirectMaterial.dispose();
|
|
}
|
|
_setSize(cubeSize) {
|
|
this._lodMax = Math.floor(Math.log2(cubeSize));
|
|
this._cubeSize = Math.pow(2, this._lodMax);
|
|
}
|
|
_dispose() {
|
|
if (this._blurMaterial !== null)
|
|
this._blurMaterial.dispose();
|
|
if (this._pingPongRenderTarget !== null)
|
|
this._pingPongRenderTarget.dispose();
|
|
for (let i = 0;i < this._lodPlanes.length; i++) {
|
|
this._lodPlanes[i].dispose();
|
|
}
|
|
}
|
|
_cleanup(outputTarget) {
|
|
this._renderer.setRenderTarget(_oldTarget, _oldActiveCubeFace, _oldActiveMipmapLevel);
|
|
this._renderer.xr.enabled = _oldXrEnabled;
|
|
outputTarget.scissorTest = false;
|
|
_setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
|
|
}
|
|
_fromTexture(texture, renderTarget) {
|
|
if (texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping) {
|
|
this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width);
|
|
} else {
|
|
this._setSize(texture.image.width / 4);
|
|
}
|
|
_oldTarget = this._renderer.getRenderTarget();
|
|
_oldActiveCubeFace = this._renderer.getActiveCubeFace();
|
|
_oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
|
|
_oldXrEnabled = this._renderer.xr.enabled;
|
|
this._renderer.xr.enabled = false;
|
|
const cubeUVRenderTarget = renderTarget || this._allocateTargets();
|
|
this._textureToCubeUV(texture, cubeUVRenderTarget);
|
|
this._applyPMREM(cubeUVRenderTarget);
|
|
this._cleanup(cubeUVRenderTarget);
|
|
return cubeUVRenderTarget;
|
|
}
|
|
_allocateTargets() {
|
|
const width = 3 * Math.max(this._cubeSize, 16 * 7);
|
|
const height = 4 * this._cubeSize;
|
|
const params = {
|
|
magFilter: LinearFilter,
|
|
minFilter: LinearFilter,
|
|
generateMipmaps: false,
|
|
type: HalfFloatType,
|
|
format: RGBAFormat,
|
|
colorSpace: LinearSRGBColorSpace,
|
|
depthBuffer: false
|
|
};
|
|
const cubeUVRenderTarget = _createRenderTarget(width, height, params);
|
|
if (this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width || this._pingPongRenderTarget.height !== height) {
|
|
if (this._pingPongRenderTarget !== null) {
|
|
this._dispose();
|
|
}
|
|
this._pingPongRenderTarget = _createRenderTarget(width, height, params);
|
|
const { _lodMax } = this;
|
|
({ sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas } = _createPlanes(_lodMax));
|
|
this._blurMaterial = _getBlurShader(_lodMax, width, height);
|
|
}
|
|
return cubeUVRenderTarget;
|
|
}
|
|
_compileMaterial(material) {
|
|
const tmpMesh = new Mesh(this._lodPlanes[0], material);
|
|
this._renderer.compile(tmpMesh, _flatCamera);
|
|
}
|
|
_sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
|
|
const fov2 = 90;
|
|
const aspect2 = 1;
|
|
const cubeCamera = new PerspectiveCamera(fov2, aspect2, near, far);
|
|
const upSign = [1, -1, 1, 1, 1, 1];
|
|
const forwardSign = [1, 1, 1, -1, -1, -1];
|
|
const renderer = this._renderer;
|
|
const originalAutoClear = renderer.autoClear;
|
|
const toneMapping = renderer.toneMapping;
|
|
renderer.getClearColor(_clearColor);
|
|
renderer.toneMapping = NoToneMapping;
|
|
renderer.autoClear = false;
|
|
const backgroundMaterial = new MeshBasicMaterial({
|
|
name: "PMREM.Background",
|
|
side: BackSide,
|
|
depthWrite: false,
|
|
depthTest: false
|
|
});
|
|
const backgroundBox = new Mesh(new BoxGeometry, backgroundMaterial);
|
|
let useSolidColor = false;
|
|
const background = scene.background;
|
|
if (background) {
|
|
if (background.isColor) {
|
|
backgroundMaterial.color.copy(background);
|
|
scene.background = null;
|
|
useSolidColor = true;
|
|
}
|
|
} else {
|
|
backgroundMaterial.color.copy(_clearColor);
|
|
useSolidColor = true;
|
|
}
|
|
for (let i = 0;i < 6; i++) {
|
|
const col = i % 3;
|
|
if (col === 0) {
|
|
cubeCamera.up.set(0, upSign[i], 0);
|
|
cubeCamera.lookAt(forwardSign[i], 0, 0);
|
|
} else if (col === 1) {
|
|
cubeCamera.up.set(0, 0, upSign[i]);
|
|
cubeCamera.lookAt(0, forwardSign[i], 0);
|
|
} else {
|
|
cubeCamera.up.set(0, upSign[i], 0);
|
|
cubeCamera.lookAt(0, 0, forwardSign[i]);
|
|
}
|
|
const size = this._cubeSize;
|
|
_setViewport(cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size);
|
|
renderer.setRenderTarget(cubeUVRenderTarget);
|
|
if (useSolidColor) {
|
|
renderer.render(backgroundBox, cubeCamera);
|
|
}
|
|
renderer.render(scene, cubeCamera);
|
|
}
|
|
backgroundBox.geometry.dispose();
|
|
backgroundBox.material.dispose();
|
|
renderer.toneMapping = toneMapping;
|
|
renderer.autoClear = originalAutoClear;
|
|
scene.background = background;
|
|
}
|
|
_textureToCubeUV(texture, cubeUVRenderTarget) {
|
|
const renderer = this._renderer;
|
|
const isCubeTexture = texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping;
|
|
if (isCubeTexture) {
|
|
if (this._cubemapMaterial === null) {
|
|
this._cubemapMaterial = _getCubemapMaterial();
|
|
}
|
|
this._cubemapMaterial.uniforms.flipEnvMap.value = texture.isRenderTargetTexture === false ? -1 : 1;
|
|
} else {
|
|
if (this._equirectMaterial === null) {
|
|
this._equirectMaterial = _getEquirectMaterial();
|
|
}
|
|
}
|
|
const material = isCubeTexture ? this._cubemapMaterial : this._equirectMaterial;
|
|
const mesh = new Mesh(this._lodPlanes[0], material);
|
|
const uniforms = material.uniforms;
|
|
uniforms["envMap"].value = texture;
|
|
const size = this._cubeSize;
|
|
_setViewport(cubeUVRenderTarget, 0, 0, 3 * size, 2 * size);
|
|
renderer.setRenderTarget(cubeUVRenderTarget);
|
|
renderer.render(mesh, _flatCamera);
|
|
}
|
|
_applyPMREM(cubeUVRenderTarget) {
|
|
const renderer = this._renderer;
|
|
const autoClear = renderer.autoClear;
|
|
renderer.autoClear = false;
|
|
const n = this._lodPlanes.length;
|
|
for (let i = 1;i < n; i++) {
|
|
const sigma = Math.sqrt(this._sigmas[i] * this._sigmas[i] - this._sigmas[i - 1] * this._sigmas[i - 1]);
|
|
const poleAxis = _axisDirections[(n - i - 1) % _axisDirections.length];
|
|
this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
|
|
}
|
|
renderer.autoClear = autoClear;
|
|
}
|
|
_blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
|
|
const pingPongRenderTarget = this._pingPongRenderTarget;
|
|
this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, "latitudinal", poleAxis);
|
|
this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, "longitudinal", poleAxis);
|
|
}
|
|
_halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
|
|
const renderer = this._renderer;
|
|
const blurMaterial = this._blurMaterial;
|
|
if (direction !== "latitudinal" && direction !== "longitudinal") {
|
|
console.error("blur direction must be either latitudinal or longitudinal!");
|
|
}
|
|
const STANDARD_DEVIATIONS = 3;
|
|
const blurMesh = new Mesh(this._lodPlanes[lodOut], blurMaterial);
|
|
const blurUniforms = blurMaterial.uniforms;
|
|
const pixels = this._sizeLods[lodIn] - 1;
|
|
const radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
|
|
const sigmaPixels = sigmaRadians / radiansPerPixel;
|
|
const samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
|
|
if (samples > MAX_SAMPLES) {
|
|
console.warn(`sigmaRadians, ${sigmaRadians}, is too large and will clip, as it requested ${samples} samples when the maximum is set to ${MAX_SAMPLES}`);
|
|
}
|
|
const weights = [];
|
|
let sum = 0;
|
|
for (let i = 0;i < MAX_SAMPLES; ++i) {
|
|
const x2 = i / sigmaPixels;
|
|
const weight = Math.exp(-x2 * x2 / 2);
|
|
weights.push(weight);
|
|
if (i === 0) {
|
|
sum += weight;
|
|
} else if (i < samples) {
|
|
sum += 2 * weight;
|
|
}
|
|
}
|
|
for (let i = 0;i < weights.length; i++) {
|
|
weights[i] = weights[i] / sum;
|
|
}
|
|
blurUniforms["envMap"].value = targetIn.texture;
|
|
blurUniforms["samples"].value = samples;
|
|
blurUniforms["weights"].value = weights;
|
|
blurUniforms["latitudinal"].value = direction === "latitudinal";
|
|
if (poleAxis) {
|
|
blurUniforms["poleAxis"].value = poleAxis;
|
|
}
|
|
const { _lodMax } = this;
|
|
blurUniforms["dTheta"].value = radiansPerPixel;
|
|
blurUniforms["mipInt"].value = _lodMax - lodIn;
|
|
const outputSize = this._sizeLods[lodOut];
|
|
const x = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0);
|
|
const y = 4 * (this._cubeSize - outputSize);
|
|
_setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
|
|
renderer.setRenderTarget(targetOut);
|
|
renderer.render(blurMesh, _flatCamera);
|
|
}
|
|
}
|
|
function _createPlanes(lodMax) {
|
|
const lodPlanes = [];
|
|
const sizeLods = [];
|
|
const sigmas = [];
|
|
let lod = lodMax;
|
|
const totalLods = lodMax - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
|
|
for (let i = 0;i < totalLods; i++) {
|
|
const sizeLod = Math.pow(2, lod);
|
|
sizeLods.push(sizeLod);
|
|
let sigma = 1 / sizeLod;
|
|
if (i > lodMax - LOD_MIN) {
|
|
sigma = EXTRA_LOD_SIGMA[i - lodMax + LOD_MIN - 1];
|
|
} else if (i === 0) {
|
|
sigma = 0;
|
|
}
|
|
sigmas.push(sigma);
|
|
const texelSize = 1 / (sizeLod - 2);
|
|
const min = -texelSize;
|
|
const max = 1 + texelSize;
|
|
const uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
|
|
const cubeFaces = 6;
|
|
const vertices = 6;
|
|
const positionSize = 3;
|
|
const uvSize = 2;
|
|
const faceIndexSize = 1;
|
|
const position = new Float32Array(positionSize * vertices * cubeFaces);
|
|
const uv = new Float32Array(uvSize * vertices * cubeFaces);
|
|
const faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
|
|
for (let face = 0;face < cubeFaces; face++) {
|
|
const x = face % 3 * 2 / 3 - 1;
|
|
const y = face > 2 ? 0 : -1;
|
|
const coordinates = [
|
|
x,
|
|
y,
|
|
0,
|
|
x + 2 / 3,
|
|
y,
|
|
0,
|
|
x + 2 / 3,
|
|
y + 1,
|
|
0,
|
|
x,
|
|
y,
|
|
0,
|
|
x + 2 / 3,
|
|
y + 1,
|
|
0,
|
|
x,
|
|
y + 1,
|
|
0
|
|
];
|
|
position.set(coordinates, positionSize * vertices * face);
|
|
uv.set(uv1, uvSize * vertices * face);
|
|
const fill2 = [face, face, face, face, face, face];
|
|
faceIndex.set(fill2, faceIndexSize * vertices * face);
|
|
}
|
|
const planes = new BufferGeometry;
|
|
planes.setAttribute("position", new BufferAttribute(position, positionSize));
|
|
planes.setAttribute("uv", new BufferAttribute(uv, uvSize));
|
|
planes.setAttribute("faceIndex", new BufferAttribute(faceIndex, faceIndexSize));
|
|
lodPlanes.push(planes);
|
|
if (lod > LOD_MIN) {
|
|
lod--;
|
|
}
|
|
}
|
|
return { lodPlanes, sizeLods, sigmas };
|
|
}
|
|
function _createRenderTarget(width, height, params) {
|
|
const cubeUVRenderTarget = new WebGLRenderTarget(width, height, params);
|
|
cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
|
|
cubeUVRenderTarget.texture.name = "PMREM.cubeUv";
|
|
cubeUVRenderTarget.scissorTest = true;
|
|
return cubeUVRenderTarget;
|
|
}
|
|
function _setViewport(target, x, y, width, height) {
|
|
target.viewport.set(x, y, width, height);
|
|
target.scissor.set(x, y, width, height);
|
|
}
|
|
function _getBlurShader(lodMax, width, height) {
|
|
const weights = new Float32Array(MAX_SAMPLES);
|
|
const poleAxis = new Vector3(0, 1, 0);
|
|
const shaderMaterial = new ShaderMaterial({
|
|
name: "SphericalGaussianBlur",
|
|
defines: {
|
|
n: MAX_SAMPLES,
|
|
CUBEUV_TEXEL_WIDTH: 1 / width,
|
|
CUBEUV_TEXEL_HEIGHT: 1 / height,
|
|
CUBEUV_MAX_MIP: `${lodMax}.0`
|
|
},
|
|
uniforms: {
|
|
envMap: { value: null },
|
|
samples: { value: 1 },
|
|
weights: { value: weights },
|
|
latitudinal: { value: false },
|
|
dTheta: { value: 0 },
|
|
mipInt: { value: 0 },
|
|
poleAxis: { value: poleAxis }
|
|
},
|
|
vertexShader: _getCommonVertexShader(),
|
|
fragmentShader: `
|
|
|
|
precision mediump float;
|
|
precision mediump int;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
uniform sampler2D envMap;
|
|
uniform int samples;
|
|
uniform float weights[ n ];
|
|
uniform bool latitudinal;
|
|
uniform float dTheta;
|
|
uniform float mipInt;
|
|
uniform vec3 poleAxis;
|
|
|
|
#define ENVMAP_TYPE_CUBE_UV
|
|
#include <cube_uv_reflection_fragment>
|
|
|
|
vec3 getSample( float theta, vec3 axis ) {
|
|
|
|
float cosTheta = cos( theta );
|
|
// Rodrigues' axis-angle rotation
|
|
vec3 sampleDirection = vOutputDirection * cosTheta
|
|
+ cross( axis, vOutputDirection ) * sin( theta )
|
|
+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
|
|
|
|
return bilinearCubeUV( envMap, sampleDirection, mipInt );
|
|
|
|
}
|
|
|
|
void main() {
|
|
|
|
vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
|
|
|
|
if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
|
|
|
|
axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
|
|
|
|
}
|
|
|
|
axis = normalize( axis );
|
|
|
|
gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
|
|
gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
|
|
|
|
for ( int i = 1; i < n; i++ ) {
|
|
|
|
if ( i >= samples ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
float theta = dTheta * float( i );
|
|
gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
|
|
gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
|
|
|
|
}
|
|
|
|
}
|
|
`,
|
|
blending: NoBlending,
|
|
depthTest: false,
|
|
depthWrite: false
|
|
});
|
|
return shaderMaterial;
|
|
}
|
|
function _getEquirectMaterial() {
|
|
return new ShaderMaterial({
|
|
name: "EquirectangularToCubeUV",
|
|
uniforms: {
|
|
envMap: { value: null }
|
|
},
|
|
vertexShader: _getCommonVertexShader(),
|
|
fragmentShader: `
|
|
|
|
precision mediump float;
|
|
precision mediump int;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
uniform sampler2D envMap;
|
|
|
|
#include <common>
|
|
|
|
void main() {
|
|
|
|
vec3 outputDirection = normalize( vOutputDirection );
|
|
vec2 uv = equirectUv( outputDirection );
|
|
|
|
gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );
|
|
|
|
}
|
|
`,
|
|
blending: NoBlending,
|
|
depthTest: false,
|
|
depthWrite: false
|
|
});
|
|
}
|
|
function _getCubemapMaterial() {
|
|
return new ShaderMaterial({
|
|
name: "CubemapToCubeUV",
|
|
uniforms: {
|
|
envMap: { value: null },
|
|
flipEnvMap: { value: -1 }
|
|
},
|
|
vertexShader: _getCommonVertexShader(),
|
|
fragmentShader: `
|
|
|
|
precision mediump float;
|
|
precision mediump int;
|
|
|
|
uniform float flipEnvMap;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
uniform samplerCube envMap;
|
|
|
|
void main() {
|
|
|
|
gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );
|
|
|
|
}
|
|
`,
|
|
blending: NoBlending,
|
|
depthTest: false,
|
|
depthWrite: false
|
|
});
|
|
}
|
|
function _getCommonVertexShader() {
|
|
return `
|
|
|
|
precision mediump float;
|
|
precision mediump int;
|
|
|
|
attribute float faceIndex;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
// RH coordinate system; PMREM face-indexing convention
|
|
vec3 getDirection( vec2 uv, float face ) {
|
|
|
|
uv = 2.0 * uv - 1.0;
|
|
|
|
vec3 direction = vec3( uv, 1.0 );
|
|
|
|
if ( face == 0.0 ) {
|
|
|
|
direction = direction.zyx; // ( 1, v, u ) pos x
|
|
|
|
} else if ( face == 1.0 ) {
|
|
|
|
direction = direction.xzy;
|
|
direction.xz *= -1.0; // ( -u, 1, -v ) pos y
|
|
|
|
} else if ( face == 2.0 ) {
|
|
|
|
direction.x *= -1.0; // ( -u, v, 1 ) pos z
|
|
|
|
} else if ( face == 3.0 ) {
|
|
|
|
direction = direction.zyx;
|
|
direction.xz *= -1.0; // ( -1, v, -u ) neg x
|
|
|
|
} else if ( face == 4.0 ) {
|
|
|
|
direction = direction.xzy;
|
|
direction.xy *= -1.0; // ( -u, -1, v ) neg y
|
|
|
|
} else if ( face == 5.0 ) {
|
|
|
|
direction.z *= -1.0; // ( u, v, -1 ) neg z
|
|
|
|
}
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
void main() {
|
|
|
|
vOutputDirection = getDirection( uv, faceIndex );
|
|
gl_Position = vec4( position, 1.0 );
|
|
|
|
}
|
|
`;
|
|
}
|
|
function WebGLCubeUVMaps(renderer) {
|
|
let cubeUVmaps = new WeakMap;
|
|
let pmremGenerator = null;
|
|
function get(texture) {
|
|
if (texture && texture.isTexture) {
|
|
const mapping = texture.mapping;
|
|
const isEquirectMap = mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping;
|
|
const isCubeMap = mapping === CubeReflectionMapping || mapping === CubeRefractionMapping;
|
|
if (isEquirectMap || isCubeMap) {
|
|
let renderTarget = cubeUVmaps.get(texture);
|
|
const currentPMREMVersion = renderTarget !== undefined ? renderTarget.texture.pmremVersion : 0;
|
|
if (texture.isRenderTargetTexture && texture.pmremVersion !== currentPMREMVersion) {
|
|
if (pmremGenerator === null)
|
|
pmremGenerator = new PMREMGenerator(renderer);
|
|
renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture, renderTarget) : pmremGenerator.fromCubemap(texture, renderTarget);
|
|
renderTarget.texture.pmremVersion = texture.pmremVersion;
|
|
cubeUVmaps.set(texture, renderTarget);
|
|
return renderTarget.texture;
|
|
} else {
|
|
if (renderTarget !== undefined) {
|
|
return renderTarget.texture;
|
|
} else {
|
|
const image = texture.image;
|
|
if (isEquirectMap && image && image.height > 0 || isCubeMap && image && isCubeTextureComplete(image)) {
|
|
if (pmremGenerator === null)
|
|
pmremGenerator = new PMREMGenerator(renderer);
|
|
renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture) : pmremGenerator.fromCubemap(texture);
|
|
renderTarget.texture.pmremVersion = texture.pmremVersion;
|
|
cubeUVmaps.set(texture, renderTarget);
|
|
texture.addEventListener("dispose", onTextureDispose);
|
|
return renderTarget.texture;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return texture;
|
|
}
|
|
function isCubeTextureComplete(image) {
|
|
let count = 0;
|
|
const length = 6;
|
|
for (let i = 0;i < length; i++) {
|
|
if (image[i] !== undefined)
|
|
count++;
|
|
}
|
|
return count === length;
|
|
}
|
|
function onTextureDispose(event) {
|
|
const texture = event.target;
|
|
texture.removeEventListener("dispose", onTextureDispose);
|
|
const cubemapUV = cubeUVmaps.get(texture);
|
|
if (cubemapUV !== undefined) {
|
|
cubeUVmaps.delete(texture);
|
|
cubemapUV.dispose();
|
|
}
|
|
}
|
|
function dispose() {
|
|
cubeUVmaps = new WeakMap;
|
|
if (pmremGenerator !== null) {
|
|
pmremGenerator.dispose();
|
|
pmremGenerator = null;
|
|
}
|
|
}
|
|
return {
|
|
get,
|
|
dispose
|
|
};
|
|
}
|
|
function WebGLExtensions(gl) {
|
|
const extensions = {};
|
|
function getExtension(name) {
|
|
if (extensions[name] !== undefined) {
|
|
return extensions[name];
|
|
}
|
|
let extension;
|
|
switch (name) {
|
|
case "WEBGL_depth_texture":
|
|
extension = gl.getExtension("WEBGL_depth_texture") || gl.getExtension("MOZ_WEBGL_depth_texture") || gl.getExtension("WEBKIT_WEBGL_depth_texture");
|
|
break;
|
|
case "EXT_texture_filter_anisotropic":
|
|
extension = gl.getExtension("EXT_texture_filter_anisotropic") || gl.getExtension("MOZ_EXT_texture_filter_anisotropic") || gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic");
|
|
break;
|
|
case "WEBGL_compressed_texture_s3tc":
|
|
extension = gl.getExtension("WEBGL_compressed_texture_s3tc") || gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");
|
|
break;
|
|
case "WEBGL_compressed_texture_pvrtc":
|
|
extension = gl.getExtension("WEBGL_compressed_texture_pvrtc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");
|
|
break;
|
|
default:
|
|
extension = gl.getExtension(name);
|
|
}
|
|
extensions[name] = extension;
|
|
return extension;
|
|
}
|
|
return {
|
|
has: function(name) {
|
|
return getExtension(name) !== null;
|
|
},
|
|
init: function() {
|
|
getExtension("EXT_color_buffer_float");
|
|
getExtension("WEBGL_clip_cull_distance");
|
|
getExtension("OES_texture_float_linear");
|
|
getExtension("EXT_color_buffer_half_float");
|
|
getExtension("WEBGL_multisampled_render_to_texture");
|
|
getExtension("WEBGL_render_shared_exponent");
|
|
},
|
|
get: function(name) {
|
|
const extension = getExtension(name);
|
|
if (extension === null) {
|
|
warnOnce("THREE.WebGLRenderer: " + name + " extension not supported.");
|
|
}
|
|
return extension;
|
|
}
|
|
};
|
|
}
|
|
function WebGLGeometries(gl, attributes, info, bindingStates) {
|
|
const geometries = {};
|
|
const wireframeAttributes = new WeakMap;
|
|
function onGeometryDispose(event) {
|
|
const geometry = event.target;
|
|
if (geometry.index !== null) {
|
|
attributes.remove(geometry.index);
|
|
}
|
|
for (const name in geometry.attributes) {
|
|
attributes.remove(geometry.attributes[name]);
|
|
}
|
|
geometry.removeEventListener("dispose", onGeometryDispose);
|
|
delete geometries[geometry.id];
|
|
const attribute = wireframeAttributes.get(geometry);
|
|
if (attribute) {
|
|
attributes.remove(attribute);
|
|
wireframeAttributes.delete(geometry);
|
|
}
|
|
bindingStates.releaseStatesOfGeometry(geometry);
|
|
if (geometry.isInstancedBufferGeometry === true) {
|
|
delete geometry._maxInstanceCount;
|
|
}
|
|
info.memory.geometries--;
|
|
}
|
|
function get(object, geometry) {
|
|
if (geometries[geometry.id] === true)
|
|
return geometry;
|
|
geometry.addEventListener("dispose", onGeometryDispose);
|
|
geometries[geometry.id] = true;
|
|
info.memory.geometries++;
|
|
return geometry;
|
|
}
|
|
function update(geometry) {
|
|
const geometryAttributes = geometry.attributes;
|
|
for (const name in geometryAttributes) {
|
|
attributes.update(geometryAttributes[name], gl.ARRAY_BUFFER);
|
|
}
|
|
}
|
|
function updateWireframeAttribute(geometry) {
|
|
const indices = [];
|
|
const geometryIndex = geometry.index;
|
|
const geometryPosition = geometry.attributes.position;
|
|
let version = 0;
|
|
if (geometryIndex !== null) {
|
|
const array = geometryIndex.array;
|
|
version = geometryIndex.version;
|
|
for (let i = 0, l = array.length;i < l; i += 3) {
|
|
const a = array[i + 0];
|
|
const b = array[i + 1];
|
|
const c = array[i + 2];
|
|
indices.push(a, b, b, c, c, a);
|
|
}
|
|
} else if (geometryPosition !== undefined) {
|
|
const array = geometryPosition.array;
|
|
version = geometryPosition.version;
|
|
for (let i = 0, l = array.length / 3 - 1;i < l; i += 3) {
|
|
const a = i + 0;
|
|
const b = i + 1;
|
|
const c = i + 2;
|
|
indices.push(a, b, b, c, c, a);
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
const attribute = new ((arrayNeedsUint32(indices)) ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
|
|
attribute.version = version;
|
|
const previousAttribute = wireframeAttributes.get(geometry);
|
|
if (previousAttribute)
|
|
attributes.remove(previousAttribute);
|
|
wireframeAttributes.set(geometry, attribute);
|
|
}
|
|
function getWireframeAttribute(geometry) {
|
|
const currentAttribute = wireframeAttributes.get(geometry);
|
|
if (currentAttribute) {
|
|
const geometryIndex = geometry.index;
|
|
if (geometryIndex !== null) {
|
|
if (currentAttribute.version < geometryIndex.version) {
|
|
updateWireframeAttribute(geometry);
|
|
}
|
|
}
|
|
} else {
|
|
updateWireframeAttribute(geometry);
|
|
}
|
|
return wireframeAttributes.get(geometry);
|
|
}
|
|
return {
|
|
get,
|
|
update,
|
|
getWireframeAttribute
|
|
};
|
|
}
|
|
function WebGLIndexedBufferRenderer(gl, extensions, info) {
|
|
let mode;
|
|
function setMode(value) {
|
|
mode = value;
|
|
}
|
|
let type, bytesPerElement;
|
|
function setIndex(value) {
|
|
type = value.type;
|
|
bytesPerElement = value.bytesPerElement;
|
|
}
|
|
function render(start, count) {
|
|
gl.drawElements(mode, count, type, start * bytesPerElement);
|
|
info.update(count, mode, 1);
|
|
}
|
|
function renderInstances(start, count, primcount) {
|
|
if (primcount === 0)
|
|
return;
|
|
gl.drawElementsInstanced(mode, count, type, start * bytesPerElement, primcount);
|
|
info.update(count, mode, primcount);
|
|
}
|
|
function renderMultiDraw(starts, counts, drawCount) {
|
|
if (drawCount === 0)
|
|
return;
|
|
const extension = extensions.get("WEBGL_multi_draw");
|
|
extension.multiDrawElementsWEBGL(mode, counts, 0, type, starts, 0, drawCount);
|
|
let elementCount = 0;
|
|
for (let i = 0;i < drawCount; i++) {
|
|
elementCount += counts[i];
|
|
}
|
|
info.update(elementCount, mode, 1);
|
|
}
|
|
function renderMultiDrawInstances(starts, counts, drawCount, primcount) {
|
|
if (drawCount === 0)
|
|
return;
|
|
const extension = extensions.get("WEBGL_multi_draw");
|
|
if (extension === null) {
|
|
for (let i = 0;i < starts.length; i++) {
|
|
renderInstances(starts[i] / bytesPerElement, counts[i], primcount[i]);
|
|
}
|
|
} else {
|
|
extension.multiDrawElementsInstancedWEBGL(mode, counts, 0, type, starts, 0, primcount, 0, drawCount);
|
|
let elementCount = 0;
|
|
for (let i = 0;i < drawCount; i++) {
|
|
elementCount += counts[i] * primcount[i];
|
|
}
|
|
info.update(elementCount, mode, 1);
|
|
}
|
|
}
|
|
this.setMode = setMode;
|
|
this.setIndex = setIndex;
|
|
this.render = render;
|
|
this.renderInstances = renderInstances;
|
|
this.renderMultiDraw = renderMultiDraw;
|
|
this.renderMultiDrawInstances = renderMultiDrawInstances;
|
|
}
|
|
function WebGLInfo(gl) {
|
|
const memory = {
|
|
geometries: 0,
|
|
textures: 0
|
|
};
|
|
const render = {
|
|
frame: 0,
|
|
calls: 0,
|
|
triangles: 0,
|
|
points: 0,
|
|
lines: 0
|
|
};
|
|
function update(count, mode, instanceCount) {
|
|
render.calls++;
|
|
switch (mode) {
|
|
case gl.TRIANGLES:
|
|
render.triangles += instanceCount * (count / 3);
|
|
break;
|
|
case gl.LINES:
|
|
render.lines += instanceCount * (count / 2);
|
|
break;
|
|
case gl.LINE_STRIP:
|
|
render.lines += instanceCount * (count - 1);
|
|
break;
|
|
case gl.LINE_LOOP:
|
|
render.lines += instanceCount * count;
|
|
break;
|
|
case gl.POINTS:
|
|
render.points += instanceCount * count;
|
|
break;
|
|
default:
|
|
console.error("THREE.WebGLInfo: Unknown draw mode:", mode);
|
|
break;
|
|
}
|
|
}
|
|
function reset() {
|
|
render.calls = 0;
|
|
render.triangles = 0;
|
|
render.points = 0;
|
|
render.lines = 0;
|
|
}
|
|
return {
|
|
memory,
|
|
render,
|
|
programs: null,
|
|
autoReset: true,
|
|
reset,
|
|
update
|
|
};
|
|
}
|
|
function WebGLMorphtargets(gl, capabilities, textures) {
|
|
const morphTextures = new WeakMap;
|
|
const morph = new Vector4;
|
|
function update(object, geometry, program) {
|
|
const objectInfluences = object.morphTargetInfluences;
|
|
const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;
|
|
const morphTargetsCount = morphAttribute !== undefined ? morphAttribute.length : 0;
|
|
let entry = morphTextures.get(geometry);
|
|
if (entry === undefined || entry.count !== morphTargetsCount) {
|
|
let disposeTexture = function() {
|
|
texture.dispose();
|
|
morphTextures.delete(geometry);
|
|
geometry.removeEventListener("dispose", disposeTexture);
|
|
};
|
|
if (entry !== undefined)
|
|
entry.texture.dispose();
|
|
const hasMorphPosition = geometry.morphAttributes.position !== undefined;
|
|
const hasMorphNormals = geometry.morphAttributes.normal !== undefined;
|
|
const hasMorphColors = geometry.morphAttributes.color !== undefined;
|
|
const morphTargets = geometry.morphAttributes.position || [];
|
|
const morphNormals = geometry.morphAttributes.normal || [];
|
|
const morphColors = geometry.morphAttributes.color || [];
|
|
let vertexDataCount = 0;
|
|
if (hasMorphPosition === true)
|
|
vertexDataCount = 1;
|
|
if (hasMorphNormals === true)
|
|
vertexDataCount = 2;
|
|
if (hasMorphColors === true)
|
|
vertexDataCount = 3;
|
|
let width = geometry.attributes.position.count * vertexDataCount;
|
|
let height = 1;
|
|
if (width > capabilities.maxTextureSize) {
|
|
height = Math.ceil(width / capabilities.maxTextureSize);
|
|
width = capabilities.maxTextureSize;
|
|
}
|
|
const buffer = new Float32Array(width * height * 4 * morphTargetsCount);
|
|
const texture = new DataArrayTexture(buffer, width, height, morphTargetsCount);
|
|
texture.type = FloatType;
|
|
texture.needsUpdate = true;
|
|
const vertexDataStride = vertexDataCount * 4;
|
|
for (let i = 0;i < morphTargetsCount; i++) {
|
|
const morphTarget = morphTargets[i];
|
|
const morphNormal = morphNormals[i];
|
|
const morphColor = morphColors[i];
|
|
const offset = width * height * 4 * i;
|
|
for (let j = 0;j < morphTarget.count; j++) {
|
|
const stride = j * vertexDataStride;
|
|
if (hasMorphPosition === true) {
|
|
morph.fromBufferAttribute(morphTarget, j);
|
|
buffer[offset + stride + 0] = morph.x;
|
|
buffer[offset + stride + 1] = morph.y;
|
|
buffer[offset + stride + 2] = morph.z;
|
|
buffer[offset + stride + 3] = 0;
|
|
}
|
|
if (hasMorphNormals === true) {
|
|
morph.fromBufferAttribute(morphNormal, j);
|
|
buffer[offset + stride + 4] = morph.x;
|
|
buffer[offset + stride + 5] = morph.y;
|
|
buffer[offset + stride + 6] = morph.z;
|
|
buffer[offset + stride + 7] = 0;
|
|
}
|
|
if (hasMorphColors === true) {
|
|
morph.fromBufferAttribute(morphColor, j);
|
|
buffer[offset + stride + 8] = morph.x;
|
|
buffer[offset + stride + 9] = morph.y;
|
|
buffer[offset + stride + 10] = morph.z;
|
|
buffer[offset + stride + 11] = morphColor.itemSize === 4 ? morph.w : 1;
|
|
}
|
|
}
|
|
}
|
|
entry = {
|
|
count: morphTargetsCount,
|
|
texture,
|
|
size: new Vector2(width, height)
|
|
};
|
|
morphTextures.set(geometry, entry);
|
|
geometry.addEventListener("dispose", disposeTexture);
|
|
}
|
|
if (object.isInstancedMesh === true && object.morphTexture !== null) {
|
|
program.getUniforms().setValue(gl, "morphTexture", object.morphTexture, textures);
|
|
} else {
|
|
let morphInfluencesSum = 0;
|
|
for (let i = 0;i < objectInfluences.length; i++) {
|
|
morphInfluencesSum += objectInfluences[i];
|
|
}
|
|
const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
|
|
program.getUniforms().setValue(gl, "morphTargetBaseInfluence", morphBaseInfluence);
|
|
program.getUniforms().setValue(gl, "morphTargetInfluences", objectInfluences);
|
|
}
|
|
program.getUniforms().setValue(gl, "morphTargetsTexture", entry.texture, textures);
|
|
program.getUniforms().setValue(gl, "morphTargetsTextureSize", entry.size);
|
|
}
|
|
return {
|
|
update
|
|
};
|
|
}
|
|
|
|
class WebGLMultiview {
|
|
constructor(renderer, extensions, gl) {
|
|
this.renderer = renderer;
|
|
this.DEFAULT_NUMVIEWS = 2;
|
|
this.maxNumViews = 0;
|
|
this.gl = gl;
|
|
this.extensions = extensions;
|
|
this.available = this.extensions.has("OCULUS_multiview");
|
|
if (this.available) {
|
|
const extension = this.extensions.get("OCULUS_multiview");
|
|
this.maxNumViews = this.gl.getParameter(extension.MAX_VIEWS_OVR);
|
|
this.mat4 = [];
|
|
this.mat3 = [];
|
|
this.cameraArray = [];
|
|
for (var i = 0;i < this.maxNumViews; i++) {
|
|
this.mat4[i] = new Matrix4;
|
|
this.mat3[i] = new Matrix3;
|
|
}
|
|
}
|
|
}
|
|
getCameraArray(camera) {
|
|
if (camera.isArrayCamera)
|
|
return camera.cameras;
|
|
this.cameraArray[0] = camera;
|
|
return this.cameraArray;
|
|
}
|
|
updateCameraProjectionMatricesUniform(camera, uniforms) {
|
|
var cameras = this.getCameraArray(camera);
|
|
for (var i = 0;i < cameras.length; i++) {
|
|
this.mat4[i].copy(cameras[i].projectionMatrix);
|
|
}
|
|
uniforms.setValue(this.gl, "projectionMatrices", this.mat4);
|
|
}
|
|
updateCameraViewMatricesUniform(camera, uniforms) {
|
|
var cameras = this.getCameraArray(camera);
|
|
for (var i = 0;i < cameras.length; i++) {
|
|
this.mat4[i].copy(cameras[i].matrixWorldInverse);
|
|
}
|
|
uniforms.setValue(this.gl, "viewMatrices", this.mat4);
|
|
}
|
|
updateObjectMatricesUniforms(object, camera, uniforms) {
|
|
var cameras = this.getCameraArray(camera);
|
|
for (var i = 0;i < cameras.length; i++) {
|
|
this.mat4[i].multiplyMatrices(cameras[i].matrixWorldInverse, object.matrixWorld);
|
|
this.mat3[i].getNormalMatrix(this.mat4[i]);
|
|
}
|
|
uniforms.setValue(this.gl, "modelViewMatrices", this.mat4);
|
|
uniforms.setValue(this.gl, "normalMatrices", this.mat3);
|
|
}
|
|
}
|
|
function WebGLObjects(gl, geometries, attributes, info) {
|
|
let updateMap = new WeakMap;
|
|
function update(object) {
|
|
const frame = info.render.frame;
|
|
const geometry = object.geometry;
|
|
const buffergeometry = geometries.get(object, geometry);
|
|
if (updateMap.get(buffergeometry) !== frame) {
|
|
geometries.update(buffergeometry);
|
|
updateMap.set(buffergeometry, frame);
|
|
}
|
|
if (object.isInstancedMesh) {
|
|
if (object.hasEventListener("dispose", onInstancedMeshDispose) === false) {
|
|
object.addEventListener("dispose", onInstancedMeshDispose);
|
|
}
|
|
if (updateMap.get(object) !== frame) {
|
|
attributes.update(object.instanceMatrix, gl.ARRAY_BUFFER);
|
|
if (object.instanceColor !== null) {
|
|
attributes.update(object.instanceColor, gl.ARRAY_BUFFER);
|
|
}
|
|
updateMap.set(object, frame);
|
|
}
|
|
}
|
|
if (object.isSkinnedMesh) {
|
|
const skeleton = object.skeleton;
|
|
if (updateMap.get(skeleton) !== frame) {
|
|
skeleton.update();
|
|
updateMap.set(skeleton, frame);
|
|
}
|
|
}
|
|
return buffergeometry;
|
|
}
|
|
function dispose() {
|
|
updateMap = new WeakMap;
|
|
}
|
|
function onInstancedMeshDispose(event) {
|
|
const instancedMesh = event.target;
|
|
instancedMesh.removeEventListener("dispose", onInstancedMeshDispose);
|
|
attributes.remove(instancedMesh.instanceMatrix);
|
|
if (instancedMesh.instanceColor !== null)
|
|
attributes.remove(instancedMesh.instanceColor);
|
|
}
|
|
return {
|
|
update,
|
|
dispose
|
|
};
|
|
}
|
|
function flatten(array, nBlocks, blockSize) {
|
|
const firstElem = array[0];
|
|
if (firstElem <= 0 || firstElem > 0)
|
|
return array;
|
|
const n = nBlocks * blockSize;
|
|
let r = arrayCacheF32[n];
|
|
if (r === undefined) {
|
|
r = new Float32Array(n);
|
|
arrayCacheF32[n] = r;
|
|
}
|
|
if (nBlocks !== 0) {
|
|
firstElem.toArray(r, 0);
|
|
for (let i = 1, offset = 0;i !== nBlocks; ++i) {
|
|
offset += blockSize;
|
|
array[i].toArray(r, offset);
|
|
}
|
|
}
|
|
return r;
|
|
}
|
|
function arraysEqual(a, b) {
|
|
if (a.length !== b.length)
|
|
return false;
|
|
for (let i = 0, l = a.length;i < l; i++) {
|
|
if (a[i] !== b[i])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
function copyArray(a, b) {
|
|
for (let i = 0, l = b.length;i < l; i++) {
|
|
a[i] = b[i];
|
|
}
|
|
}
|
|
function allocTexUnits(textures, n) {
|
|
let r = arrayCacheI32[n];
|
|
if (r === undefined) {
|
|
r = new Int32Array(n);
|
|
arrayCacheI32[n] = r;
|
|
}
|
|
for (let i = 0;i !== n; ++i) {
|
|
r[i] = textures.allocateTextureUnit();
|
|
}
|
|
return r;
|
|
}
|
|
function setValueV1f(gl, v) {
|
|
const cache = this.cache;
|
|
if (cache[0] === v)
|
|
return;
|
|
gl.uniform1f(this.addr, v);
|
|
cache[0] = v;
|
|
}
|
|
function setValueV2f(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y) {
|
|
gl.uniform2f(this.addr, v.x, v.y);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform2fv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueV3f(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
|
|
gl.uniform3f(this.addr, v.x, v.y, v.z);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
cache[2] = v.z;
|
|
}
|
|
} else if (v.r !== undefined) {
|
|
if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
|
|
gl.uniform3f(this.addr, v.r, v.g, v.b);
|
|
cache[0] = v.r;
|
|
cache[1] = v.g;
|
|
cache[2] = v.b;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform3fv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueV4f(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
|
|
gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
cache[2] = v.z;
|
|
cache[3] = v.w;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform4fv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueM2(gl, v) {
|
|
const cache = this.cache;
|
|
const elements = v.elements;
|
|
if (elements === undefined) {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniformMatrix2fv(this.addr, false, v);
|
|
copyArray(cache, v);
|
|
} else {
|
|
if (arraysEqual(cache, elements))
|
|
return;
|
|
mat2array.set(elements);
|
|
gl.uniformMatrix2fv(this.addr, false, mat2array);
|
|
copyArray(cache, elements);
|
|
}
|
|
}
|
|
function setValueM3(gl, v) {
|
|
const cache = this.cache;
|
|
const elements = v.elements;
|
|
if (elements === undefined) {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniformMatrix3fv(this.addr, false, v);
|
|
copyArray(cache, v);
|
|
} else {
|
|
if (arraysEqual(cache, elements))
|
|
return;
|
|
mat3array.set(elements);
|
|
gl.uniformMatrix3fv(this.addr, false, mat3array);
|
|
copyArray(cache, elements);
|
|
}
|
|
}
|
|
function setValueM4(gl, v) {
|
|
const cache = this.cache;
|
|
const elements = v.elements;
|
|
if (elements === undefined) {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniformMatrix4fv(this.addr, false, v);
|
|
copyArray(cache, v);
|
|
} else {
|
|
if (arraysEqual(cache, elements))
|
|
return;
|
|
mat4array.set(elements);
|
|
gl.uniformMatrix4fv(this.addr, false, mat4array);
|
|
copyArray(cache, elements);
|
|
}
|
|
}
|
|
function setValueV1i(gl, v) {
|
|
const cache = this.cache;
|
|
if (cache[0] === v)
|
|
return;
|
|
gl.uniform1i(this.addr, v);
|
|
cache[0] = v;
|
|
}
|
|
function setValueV2i(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y) {
|
|
gl.uniform2i(this.addr, v.x, v.y);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform2iv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueV3i(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
|
|
gl.uniform3i(this.addr, v.x, v.y, v.z);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
cache[2] = v.z;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform3iv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueV4i(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
|
|
gl.uniform4i(this.addr, v.x, v.y, v.z, v.w);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
cache[2] = v.z;
|
|
cache[3] = v.w;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform4iv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueV1ui(gl, v) {
|
|
const cache = this.cache;
|
|
if (cache[0] === v)
|
|
return;
|
|
gl.uniform1ui(this.addr, v);
|
|
cache[0] = v;
|
|
}
|
|
function setValueV2ui(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y) {
|
|
gl.uniform2ui(this.addr, v.x, v.y);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform2uiv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueV3ui(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
|
|
gl.uniform3ui(this.addr, v.x, v.y, v.z);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
cache[2] = v.z;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform3uiv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueV4ui(gl, v) {
|
|
const cache = this.cache;
|
|
if (v.x !== undefined) {
|
|
if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
|
|
gl.uniform4ui(this.addr, v.x, v.y, v.z, v.w);
|
|
cache[0] = v.x;
|
|
cache[1] = v.y;
|
|
cache[2] = v.z;
|
|
cache[3] = v.w;
|
|
}
|
|
} else {
|
|
if (arraysEqual(cache, v))
|
|
return;
|
|
gl.uniform4uiv(this.addr, v);
|
|
copyArray(cache, v);
|
|
}
|
|
}
|
|
function setValueT1(gl, v, textures) {
|
|
const cache = this.cache;
|
|
const unit = textures.allocateTextureUnit();
|
|
if (cache[0] !== unit) {
|
|
gl.uniform1i(this.addr, unit);
|
|
cache[0] = unit;
|
|
}
|
|
let emptyTexture2D;
|
|
if (this.type === gl.SAMPLER_2D_SHADOW) {
|
|
emptyShadowTexture.compareFunction = LessEqualCompare;
|
|
emptyTexture2D = emptyShadowTexture;
|
|
} else {
|
|
emptyTexture2D = emptyTexture;
|
|
}
|
|
textures.setTexture2D(v || emptyTexture2D, unit);
|
|
}
|
|
function setValueT3D1(gl, v, textures) {
|
|
const cache = this.cache;
|
|
const unit = textures.allocateTextureUnit();
|
|
if (cache[0] !== unit) {
|
|
gl.uniform1i(this.addr, unit);
|
|
cache[0] = unit;
|
|
}
|
|
textures.setTexture3D(v || empty3dTexture, unit);
|
|
}
|
|
function setValueT6(gl, v, textures) {
|
|
const cache = this.cache;
|
|
const unit = textures.allocateTextureUnit();
|
|
if (cache[0] !== unit) {
|
|
gl.uniform1i(this.addr, unit);
|
|
cache[0] = unit;
|
|
}
|
|
textures.setTextureCube(v || emptyCubeTexture, unit);
|
|
}
|
|
function setValueT2DArray1(gl, v, textures) {
|
|
const cache = this.cache;
|
|
const unit = textures.allocateTextureUnit();
|
|
if (cache[0] !== unit) {
|
|
gl.uniform1i(this.addr, unit);
|
|
cache[0] = unit;
|
|
}
|
|
textures.setTexture2DArray(v || emptyArrayTexture, unit);
|
|
}
|
|
function getSingularSetter(type) {
|
|
switch (type) {
|
|
case 5126:
|
|
return setValueV1f;
|
|
case 35664:
|
|
return setValueV2f;
|
|
case 35665:
|
|
return setValueV3f;
|
|
case 35666:
|
|
return setValueV4f;
|
|
case 35674:
|
|
return setValueM2;
|
|
case 35675:
|
|
return setValueM3;
|
|
case 35676:
|
|
return setValueM4;
|
|
case 5124:
|
|
case 35670:
|
|
return setValueV1i;
|
|
case 35667:
|
|
case 35671:
|
|
return setValueV2i;
|
|
case 35668:
|
|
case 35672:
|
|
return setValueV3i;
|
|
case 35669:
|
|
case 35673:
|
|
return setValueV4i;
|
|
case 5125:
|
|
return setValueV1ui;
|
|
case 36294:
|
|
return setValueV2ui;
|
|
case 36295:
|
|
return setValueV3ui;
|
|
case 36296:
|
|
return setValueV4ui;
|
|
case 35678:
|
|
case 36198:
|
|
case 36298:
|
|
case 36306:
|
|
case 35682:
|
|
return setValueT1;
|
|
case 35679:
|
|
case 36299:
|
|
case 36307:
|
|
return setValueT3D1;
|
|
case 35680:
|
|
case 36300:
|
|
case 36308:
|
|
case 36293:
|
|
return setValueT6;
|
|
case 36289:
|
|
case 36303:
|
|
case 36311:
|
|
case 36292:
|
|
return setValueT2DArray1;
|
|
}
|
|
}
|
|
function setValueV1fArray(gl, v) {
|
|
gl.uniform1fv(this.addr, v);
|
|
}
|
|
function setValueV2fArray(gl, v) {
|
|
const data = flatten(v, this.size, 2);
|
|
gl.uniform2fv(this.addr, data);
|
|
}
|
|
function setValueV3fArray(gl, v) {
|
|
const data = flatten(v, this.size, 3);
|
|
gl.uniform3fv(this.addr, data);
|
|
}
|
|
function setValueV4fArray(gl, v) {
|
|
const data = flatten(v, this.size, 4);
|
|
gl.uniform4fv(this.addr, data);
|
|
}
|
|
function setValueM2Array(gl, v) {
|
|
const data = flatten(v, this.size, 4);
|
|
gl.uniformMatrix2fv(this.addr, false, data);
|
|
}
|
|
function setValueM3Array(gl, v) {
|
|
const data = flatten(v, this.size, 9);
|
|
gl.uniformMatrix3fv(this.addr, false, data);
|
|
}
|
|
function setValueM4Array(gl, v) {
|
|
const data = flatten(v, this.size, 16);
|
|
gl.uniformMatrix4fv(this.addr, false, data);
|
|
}
|
|
function setValueV1iArray(gl, v) {
|
|
gl.uniform1iv(this.addr, v);
|
|
}
|
|
function setValueV2iArray(gl, v) {
|
|
gl.uniform2iv(this.addr, v);
|
|
}
|
|
function setValueV3iArray(gl, v) {
|
|
gl.uniform3iv(this.addr, v);
|
|
}
|
|
function setValueV4iArray(gl, v) {
|
|
gl.uniform4iv(this.addr, v);
|
|
}
|
|
function setValueV1uiArray(gl, v) {
|
|
gl.uniform1uiv(this.addr, v);
|
|
}
|
|
function setValueV2uiArray(gl, v) {
|
|
gl.uniform2uiv(this.addr, v);
|
|
}
|
|
function setValueV3uiArray(gl, v) {
|
|
gl.uniform3uiv(this.addr, v);
|
|
}
|
|
function setValueV4uiArray(gl, v) {
|
|
gl.uniform4uiv(this.addr, v);
|
|
}
|
|
function setValueT1Array(gl, v, textures) {
|
|
const cache = this.cache;
|
|
const n = v.length;
|
|
const units = allocTexUnits(textures, n);
|
|
if (!arraysEqual(cache, units)) {
|
|
gl.uniform1iv(this.addr, units);
|
|
copyArray(cache, units);
|
|
}
|
|
for (let i = 0;i !== n; ++i) {
|
|
textures.setTexture2D(v[i] || emptyTexture, units[i]);
|
|
}
|
|
}
|
|
function setValueT3DArray(gl, v, textures) {
|
|
const cache = this.cache;
|
|
const n = v.length;
|
|
const units = allocTexUnits(textures, n);
|
|
if (!arraysEqual(cache, units)) {
|
|
gl.uniform1iv(this.addr, units);
|
|
copyArray(cache, units);
|
|
}
|
|
for (let i = 0;i !== n; ++i) {
|
|
textures.setTexture3D(v[i] || empty3dTexture, units[i]);
|
|
}
|
|
}
|
|
function setValueT6Array(gl, v, textures) {
|
|
const cache = this.cache;
|
|
const n = v.length;
|
|
const units = allocTexUnits(textures, n);
|
|
if (!arraysEqual(cache, units)) {
|
|
gl.uniform1iv(this.addr, units);
|
|
copyArray(cache, units);
|
|
}
|
|
for (let i = 0;i !== n; ++i) {
|
|
textures.setTextureCube(v[i] || emptyCubeTexture, units[i]);
|
|
}
|
|
}
|
|
function setValueT2DArrayArray(gl, v, textures) {
|
|
const cache = this.cache;
|
|
const n = v.length;
|
|
const units = allocTexUnits(textures, n);
|
|
if (!arraysEqual(cache, units)) {
|
|
gl.uniform1iv(this.addr, units);
|
|
copyArray(cache, units);
|
|
}
|
|
for (let i = 0;i !== n; ++i) {
|
|
textures.setTexture2DArray(v[i] || emptyArrayTexture, units[i]);
|
|
}
|
|
}
|
|
function getPureArraySetter(type) {
|
|
switch (type) {
|
|
case 5126:
|
|
return setValueV1fArray;
|
|
case 35664:
|
|
return setValueV2fArray;
|
|
case 35665:
|
|
return setValueV3fArray;
|
|
case 35666:
|
|
return setValueV4fArray;
|
|
case 35674:
|
|
return setValueM2Array;
|
|
case 35675:
|
|
return setValueM3Array;
|
|
case 35676:
|
|
return setValueM4Array;
|
|
case 5124:
|
|
case 35670:
|
|
return setValueV1iArray;
|
|
case 35667:
|
|
case 35671:
|
|
return setValueV2iArray;
|
|
case 35668:
|
|
case 35672:
|
|
return setValueV3iArray;
|
|
case 35669:
|
|
case 35673:
|
|
return setValueV4iArray;
|
|
case 5125:
|
|
return setValueV1uiArray;
|
|
case 36294:
|
|
return setValueV2uiArray;
|
|
case 36295:
|
|
return setValueV3uiArray;
|
|
case 36296:
|
|
return setValueV4uiArray;
|
|
case 35678:
|
|
case 36198:
|
|
case 36298:
|
|
case 36306:
|
|
case 35682:
|
|
return setValueT1Array;
|
|
case 35679:
|
|
case 36299:
|
|
case 36307:
|
|
return setValueT3DArray;
|
|
case 35680:
|
|
case 36300:
|
|
case 36308:
|
|
case 36293:
|
|
return setValueT6Array;
|
|
case 36289:
|
|
case 36303:
|
|
case 36311:
|
|
case 36292:
|
|
return setValueT2DArrayArray;
|
|
}
|
|
}
|
|
|
|
class SingleUniform {
|
|
constructor(id, activeInfo, addr) {
|
|
this.id = id;
|
|
this.addr = addr;
|
|
this.cache = [];
|
|
this.type = activeInfo.type;
|
|
this.setValue = getSingularSetter(activeInfo.type);
|
|
}
|
|
}
|
|
|
|
class PureArrayUniform {
|
|
constructor(id, activeInfo, addr) {
|
|
this.id = id;
|
|
this.addr = addr;
|
|
this.cache = [];
|
|
this.type = activeInfo.type;
|
|
this.size = activeInfo.size;
|
|
this.setValue = getPureArraySetter(activeInfo.type);
|
|
}
|
|
}
|
|
|
|
class StructuredUniform {
|
|
constructor(id) {
|
|
this.id = id;
|
|
this.seq = [];
|
|
this.map = {};
|
|
}
|
|
setValue(gl, value, textures) {
|
|
const seq = this.seq;
|
|
for (let i = 0, n = seq.length;i !== n; ++i) {
|
|
const u = seq[i];
|
|
u.setValue(gl, value[u.id], textures);
|
|
}
|
|
}
|
|
}
|
|
function addUniform(container, uniformObject) {
|
|
container.seq.push(uniformObject);
|
|
container.map[uniformObject.id] = uniformObject;
|
|
}
|
|
function parseUniform(activeInfo, addr, container) {
|
|
const path = activeInfo.name, pathLength = path.length;
|
|
RePathPart.lastIndex = 0;
|
|
while (true) {
|
|
const match = RePathPart.exec(path), matchEnd = RePathPart.lastIndex;
|
|
let id = match[1];
|
|
const idIsIndex = match[2] === "]", subscript = match[3];
|
|
if (idIsIndex)
|
|
id = id | 0;
|
|
if (subscript === undefined || subscript === "[" && matchEnd + 2 === pathLength) {
|
|
addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
|
|
break;
|
|
} else {
|
|
const map = container.map;
|
|
let next = map[id];
|
|
if (next === undefined) {
|
|
next = new StructuredUniform(id);
|
|
addUniform(container, next);
|
|
}
|
|
container = next;
|
|
}
|
|
}
|
|
}
|
|
|
|
class WebGLUniforms {
|
|
constructor(gl, program) {
|
|
this.seq = [];
|
|
this.map = {};
|
|
const n = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
|
for (let i = 0;i < n; ++i) {
|
|
const info = gl.getActiveUniform(program, i), addr = gl.getUniformLocation(program, info.name);
|
|
parseUniform(info, addr, this);
|
|
}
|
|
}
|
|
setValue(gl, name, value, textures) {
|
|
const u = this.map[name];
|
|
if (u !== undefined)
|
|
u.setValue(gl, value, textures);
|
|
}
|
|
setOptional(gl, object, name) {
|
|
const v = object[name];
|
|
if (v !== undefined)
|
|
this.setValue(gl, name, v);
|
|
}
|
|
static upload(gl, seq, values, textures) {
|
|
for (let i = 0, n = seq.length;i !== n; ++i) {
|
|
const u = seq[i], v = values[u.id];
|
|
if (v.needsUpdate !== false) {
|
|
u.setValue(gl, v.value, textures);
|
|
}
|
|
}
|
|
}
|
|
static seqWithValue(seq, values) {
|
|
const r = [];
|
|
for (let i = 0, n = seq.length;i !== n; ++i) {
|
|
const u = seq[i];
|
|
if (u.id in values)
|
|
r.push(u);
|
|
}
|
|
return r;
|
|
}
|
|
}
|
|
function WebGLShader(gl, type, string) {
|
|
const shader = gl.createShader(type);
|
|
gl.shaderSource(shader, string);
|
|
gl.compileShader(shader);
|
|
return shader;
|
|
}
|
|
function handleSource(string, errorLine) {
|
|
const lines = string.split(`
|
|
`);
|
|
const lines2 = [];
|
|
const from = Math.max(errorLine - 6, 0);
|
|
const to = Math.min(errorLine + 6, lines.length);
|
|
for (let i = from;i < to; i++) {
|
|
const line = i + 1;
|
|
lines2.push(`${line === errorLine ? ">" : " "} ${line}: ${lines[i]}`);
|
|
}
|
|
return lines2.join(`
|
|
`);
|
|
}
|
|
function getEncodingComponents(colorSpace) {
|
|
ColorManagement._getMatrix(_m0, ColorManagement.workingColorSpace, colorSpace);
|
|
const encodingMatrix = `mat3( ${_m0.elements.map((v) => v.toFixed(4))} )`;
|
|
switch (ColorManagement.getTransfer(colorSpace)) {
|
|
case LinearTransfer:
|
|
return [encodingMatrix, "LinearTransferOETF"];
|
|
case SRGBTransfer:
|
|
return [encodingMatrix, "sRGBTransferOETF"];
|
|
default:
|
|
console.warn("THREE.WebGLProgram: Unsupported color space: ", colorSpace);
|
|
return [encodingMatrix, "LinearTransferOETF"];
|
|
}
|
|
}
|
|
function getShaderErrors(gl, shader, type) {
|
|
const status = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
|
const errors = gl.getShaderInfoLog(shader).trim();
|
|
if (status && errors === "")
|
|
return "";
|
|
const errorMatches = /ERROR: 0:(\d+)/.exec(errors);
|
|
if (errorMatches) {
|
|
const errorLine = parseInt(errorMatches[1]);
|
|
return type.toUpperCase() + `
|
|
|
|
` + errors + `
|
|
|
|
` + handleSource(gl.getShaderSource(shader), errorLine);
|
|
} else {
|
|
return errors;
|
|
}
|
|
}
|
|
function getTexelEncodingFunction(functionName, colorSpace) {
|
|
const components = getEncodingComponents(colorSpace);
|
|
return [
|
|
`vec4 ${functionName}( vec4 value ) {`,
|
|
` return ${components[1]}( vec4( value.rgb * ${components[0]}, value.a ) );`,
|
|
"}"
|
|
].join(`
|
|
`);
|
|
}
|
|
function getToneMappingFunction(functionName, toneMapping) {
|
|
let toneMappingName;
|
|
switch (toneMapping) {
|
|
case LinearToneMapping:
|
|
toneMappingName = "Linear";
|
|
break;
|
|
case ReinhardToneMapping:
|
|
toneMappingName = "Reinhard";
|
|
break;
|
|
case CineonToneMapping:
|
|
toneMappingName = "Cineon";
|
|
break;
|
|
case ACESFilmicToneMapping:
|
|
toneMappingName = "ACESFilmic";
|
|
break;
|
|
case AgXToneMapping:
|
|
toneMappingName = "AgX";
|
|
break;
|
|
case NeutralToneMapping:
|
|
toneMappingName = "Neutral";
|
|
break;
|
|
case CustomToneMapping:
|
|
toneMappingName = "Custom";
|
|
break;
|
|
default:
|
|
console.warn("THREE.WebGLProgram: Unsupported toneMapping:", toneMapping);
|
|
toneMappingName = "Linear";
|
|
}
|
|
return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
|
|
}
|
|
function getLuminanceFunction() {
|
|
ColorManagement.getLuminanceCoefficients(_v02);
|
|
const r = _v02.x.toFixed(4);
|
|
const g = _v02.y.toFixed(4);
|
|
const b = _v02.z.toFixed(4);
|
|
return [
|
|
"float luminance( const in vec3 rgb ) {",
|
|
` const vec3 weights = vec3( ${r}, ${g}, ${b} );`,
|
|
"\treturn dot( weights, rgb );",
|
|
"}"
|
|
].join(`
|
|
`);
|
|
}
|
|
function generateVertexExtensions(parameters) {
|
|
const chunks = [
|
|
parameters.extensionClipCullDistance ? "#extension GL_ANGLE_clip_cull_distance : require" : "",
|
|
parameters.extensionMultiDraw ? "#extension GL_ANGLE_multi_draw : require" : ""
|
|
];
|
|
return chunks.filter(filterEmptyLine).join(`
|
|
`);
|
|
}
|
|
function generateDefines(defines) {
|
|
const chunks = [];
|
|
for (const name in defines) {
|
|
const value = defines[name];
|
|
if (value === false)
|
|
continue;
|
|
chunks.push("#define " + name + " " + value);
|
|
}
|
|
return chunks.join(`
|
|
`);
|
|
}
|
|
function fetchAttributeLocations(gl, program) {
|
|
const attributes = {};
|
|
const n = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
|
|
for (let i = 0;i < n; i++) {
|
|
const info = gl.getActiveAttrib(program, i);
|
|
const name = info.name;
|
|
let locationSize = 1;
|
|
if (info.type === gl.FLOAT_MAT2)
|
|
locationSize = 2;
|
|
if (info.type === gl.FLOAT_MAT3)
|
|
locationSize = 3;
|
|
if (info.type === gl.FLOAT_MAT4)
|
|
locationSize = 4;
|
|
attributes[name] = {
|
|
type: info.type,
|
|
location: gl.getAttribLocation(program, name),
|
|
locationSize
|
|
};
|
|
}
|
|
return attributes;
|
|
}
|
|
function filterEmptyLine(string) {
|
|
return string !== "";
|
|
}
|
|
function replaceLightNums(string, parameters) {
|
|
const numSpotLightCoords = parameters.numSpotLightShadows + parameters.numSpotLightMaps - parameters.numSpotLightShadowsWithMaps;
|
|
return string.replace(/NUM_DIR_LIGHTS/g, parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g, parameters.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g, parameters.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g, numSpotLightCoords).replace(/NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g, parameters.numPointLights).replace(/NUM_HEMI_LIGHTS/g, parameters.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g, parameters.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows);
|
|
}
|
|
function replaceClippingPlaneNums(string, parameters) {
|
|
return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
|
|
}
|
|
function resolveIncludes(string) {
|
|
return string.replace(includePattern, includeReplacer);
|
|
}
|
|
function includeReplacer(match, include) {
|
|
let string = ShaderChunk[include];
|
|
if (string === undefined) {
|
|
const newInclude = shaderChunkMap.get(include);
|
|
if (newInclude !== undefined) {
|
|
string = ShaderChunk[newInclude];
|
|
console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.', include, newInclude);
|
|
} else {
|
|
throw new Error("Can not resolve #include <" + include + ">");
|
|
}
|
|
}
|
|
return resolveIncludes(string);
|
|
}
|
|
function unrollLoops(string) {
|
|
return string.replace(unrollLoopPattern, loopReplacer);
|
|
}
|
|
function loopReplacer(match, start, end, snippet) {
|
|
let string = "";
|
|
for (let i = parseInt(start);i < parseInt(end); i++) {
|
|
string += snippet.replace(/\[\s*i\s*\]/g, "[ " + i + " ]").replace(/UNROLLED_LOOP_INDEX/g, i);
|
|
}
|
|
return string;
|
|
}
|
|
function generatePrecision(parameters) {
|
|
let precisionstring = `precision ${parameters.precision} float;
|
|
precision ${parameters.precision} int;
|
|
precision ${parameters.precision} sampler2D;
|
|
precision ${parameters.precision} samplerCube;
|
|
precision ${parameters.precision} sampler3D;
|
|
precision ${parameters.precision} sampler2DArray;
|
|
precision ${parameters.precision} sampler2DShadow;
|
|
precision ${parameters.precision} samplerCubeShadow;
|
|
precision ${parameters.precision} sampler2DArrayShadow;
|
|
precision ${parameters.precision} isampler2D;
|
|
precision ${parameters.precision} isampler3D;
|
|
precision ${parameters.precision} isamplerCube;
|
|
precision ${parameters.precision} isampler2DArray;
|
|
precision ${parameters.precision} usampler2D;
|
|
precision ${parameters.precision} usampler3D;
|
|
precision ${parameters.precision} usamplerCube;
|
|
precision ${parameters.precision} usampler2DArray;
|
|
`;
|
|
if (parameters.precision === "highp") {
|
|
precisionstring += `
|
|
#define HIGH_PRECISION`;
|
|
} else if (parameters.precision === "mediump") {
|
|
precisionstring += `
|
|
#define MEDIUM_PRECISION`;
|
|
} else if (parameters.precision === "lowp") {
|
|
precisionstring += `
|
|
#define LOW_PRECISION`;
|
|
}
|
|
return precisionstring;
|
|
}
|
|
function generateShadowMapTypeDefine(parameters) {
|
|
let shadowMapTypeDefine = "SHADOWMAP_TYPE_BASIC";
|
|
if (parameters.shadowMapType === PCFShadowMap) {
|
|
shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF";
|
|
} else if (parameters.shadowMapType === PCFSoftShadowMap) {
|
|
shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF_SOFT";
|
|
} else if (parameters.shadowMapType === VSMShadowMap) {
|
|
shadowMapTypeDefine = "SHADOWMAP_TYPE_VSM";
|
|
}
|
|
return shadowMapTypeDefine;
|
|
}
|
|
function generateEnvMapTypeDefine(parameters) {
|
|
let envMapTypeDefine = "ENVMAP_TYPE_CUBE";
|
|
if (parameters.envMap) {
|
|
switch (parameters.envMapMode) {
|
|
case CubeReflectionMapping:
|
|
case CubeRefractionMapping:
|
|
envMapTypeDefine = "ENVMAP_TYPE_CUBE";
|
|
break;
|
|
case CubeUVReflectionMapping:
|
|
envMapTypeDefine = "ENVMAP_TYPE_CUBE_UV";
|
|
break;
|
|
}
|
|
}
|
|
return envMapTypeDefine;
|
|
}
|
|
function generateEnvMapModeDefine(parameters) {
|
|
let envMapModeDefine = "ENVMAP_MODE_REFLECTION";
|
|
if (parameters.envMap) {
|
|
switch (parameters.envMapMode) {
|
|
case CubeRefractionMapping:
|
|
envMapModeDefine = "ENVMAP_MODE_REFRACTION";
|
|
break;
|
|
}
|
|
}
|
|
return envMapModeDefine;
|
|
}
|
|
function generateEnvMapBlendingDefine(parameters) {
|
|
let envMapBlendingDefine = "ENVMAP_BLENDING_NONE";
|
|
if (parameters.envMap) {
|
|
switch (parameters.combine) {
|
|
case MultiplyOperation:
|
|
envMapBlendingDefine = "ENVMAP_BLENDING_MULTIPLY";
|
|
break;
|
|
case MixOperation:
|
|
envMapBlendingDefine = "ENVMAP_BLENDING_MIX";
|
|
break;
|
|
case AddOperation:
|
|
envMapBlendingDefine = "ENVMAP_BLENDING_ADD";
|
|
break;
|
|
}
|
|
}
|
|
return envMapBlendingDefine;
|
|
}
|
|
function generateCubeUVSize(parameters) {
|
|
const imageHeight = parameters.envMapCubeUVHeight;
|
|
if (imageHeight === null)
|
|
return null;
|
|
const maxMip = Math.log2(imageHeight) - 2;
|
|
const texelHeight = 1 / imageHeight;
|
|
const texelWidth = 1 / (3 * Math.max(Math.pow(2, maxMip), 7 * 16));
|
|
return { texelWidth, texelHeight, maxMip };
|
|
}
|
|
function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
|
|
const gl = renderer.getContext();
|
|
const defines = parameters.defines;
|
|
let vertexShader = parameters.vertexShader;
|
|
let fragmentShader = parameters.fragmentShader;
|
|
const shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
|
|
const envMapTypeDefine = generateEnvMapTypeDefine(parameters);
|
|
const envMapModeDefine = generateEnvMapModeDefine(parameters);
|
|
const envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
|
|
const envMapCubeUVSize = generateCubeUVSize(parameters);
|
|
const customVertexExtensions = generateVertexExtensions(parameters);
|
|
const customDefines = generateDefines(defines);
|
|
const program = gl.createProgram();
|
|
let prefixVertex, prefixFragment;
|
|
let versionString = parameters.glslVersion ? "#version " + parameters.glslVersion + `
|
|
` : "";
|
|
const numMultiviewViews = parameters.numMultiviewViews;
|
|
if (parameters.isRawShaderMaterial) {
|
|
prefixVertex = [
|
|
"#define SHADER_TYPE " + parameters.shaderType,
|
|
"#define SHADER_NAME " + parameters.shaderName,
|
|
customDefines
|
|
].filter(filterEmptyLine).join(`
|
|
`);
|
|
if (prefixVertex.length > 0) {
|
|
prefixVertex += `
|
|
`;
|
|
}
|
|
prefixFragment = [
|
|
"#define SHADER_TYPE " + parameters.shaderType,
|
|
"#define SHADER_NAME " + parameters.shaderName,
|
|
customDefines
|
|
].filter(filterEmptyLine).join(`
|
|
`);
|
|
if (prefixFragment.length > 0) {
|
|
prefixFragment += `
|
|
`;
|
|
}
|
|
} else {
|
|
prefixVertex = [
|
|
generatePrecision(parameters),
|
|
"#define SHADER_TYPE " + parameters.shaderType,
|
|
"#define SHADER_NAME " + parameters.shaderName,
|
|
customDefines,
|
|
parameters.extensionClipCullDistance ? "#define USE_CLIP_DISTANCE" : "",
|
|
parameters.batching ? "#define USE_BATCHING" : "",
|
|
parameters.batchingColor ? "#define USE_BATCHING_COLOR" : "",
|
|
parameters.instancing ? "#define USE_INSTANCING" : "",
|
|
parameters.instancingColor ? "#define USE_INSTANCING_COLOR" : "",
|
|
parameters.instancingMorph ? "#define USE_INSTANCING_MORPH" : "",
|
|
parameters.useFog && parameters.fog ? "#define USE_FOG" : "",
|
|
parameters.useFog && parameters.fogExp2 ? "#define FOG_EXP2" : "",
|
|
parameters.map ? "#define USE_MAP" : "",
|
|
parameters.envMap ? "#define USE_ENVMAP" : "",
|
|
parameters.envMap ? "#define " + envMapModeDefine : "",
|
|
parameters.lightMap ? "#define USE_LIGHTMAP" : "",
|
|
parameters.aoMap ? "#define USE_AOMAP" : "",
|
|
parameters.bumpMap ? "#define USE_BUMPMAP" : "",
|
|
parameters.normalMap ? "#define USE_NORMALMAP" : "",
|
|
parameters.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "",
|
|
parameters.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "",
|
|
parameters.displacementMap ? "#define USE_DISPLACEMENTMAP" : "",
|
|
parameters.emissiveMap ? "#define USE_EMISSIVEMAP" : "",
|
|
parameters.anisotropy ? "#define USE_ANISOTROPY" : "",
|
|
parameters.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "",
|
|
parameters.clearcoatMap ? "#define USE_CLEARCOATMAP" : "",
|
|
parameters.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "",
|
|
parameters.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "",
|
|
parameters.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "",
|
|
parameters.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "",
|
|
parameters.specularMap ? "#define USE_SPECULARMAP" : "",
|
|
parameters.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "",
|
|
parameters.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "",
|
|
parameters.roughnessMap ? "#define USE_ROUGHNESSMAP" : "",
|
|
parameters.metalnessMap ? "#define USE_METALNESSMAP" : "",
|
|
parameters.alphaMap ? "#define USE_ALPHAMAP" : "",
|
|
parameters.alphaHash ? "#define USE_ALPHAHASH" : "",
|
|
parameters.transmission ? "#define USE_TRANSMISSION" : "",
|
|
parameters.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "",
|
|
parameters.thicknessMap ? "#define USE_THICKNESSMAP" : "",
|
|
parameters.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "",
|
|
parameters.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "",
|
|
parameters.mapUv ? "#define MAP_UV " + parameters.mapUv : "",
|
|
parameters.alphaMapUv ? "#define ALPHAMAP_UV " + parameters.alphaMapUv : "",
|
|
parameters.lightMapUv ? "#define LIGHTMAP_UV " + parameters.lightMapUv : "",
|
|
parameters.aoMapUv ? "#define AOMAP_UV " + parameters.aoMapUv : "",
|
|
parameters.emissiveMapUv ? "#define EMISSIVEMAP_UV " + parameters.emissiveMapUv : "",
|
|
parameters.bumpMapUv ? "#define BUMPMAP_UV " + parameters.bumpMapUv : "",
|
|
parameters.normalMapUv ? "#define NORMALMAP_UV " + parameters.normalMapUv : "",
|
|
parameters.displacementMapUv ? "#define DISPLACEMENTMAP_UV " + parameters.displacementMapUv : "",
|
|
parameters.metalnessMapUv ? "#define METALNESSMAP_UV " + parameters.metalnessMapUv : "",
|
|
parameters.roughnessMapUv ? "#define ROUGHNESSMAP_UV " + parameters.roughnessMapUv : "",
|
|
parameters.anisotropyMapUv ? "#define ANISOTROPYMAP_UV " + parameters.anisotropyMapUv : "",
|
|
parameters.clearcoatMapUv ? "#define CLEARCOATMAP_UV " + parameters.clearcoatMapUv : "",
|
|
parameters.clearcoatNormalMapUv ? "#define CLEARCOAT_NORMALMAP_UV " + parameters.clearcoatNormalMapUv : "",
|
|
parameters.clearcoatRoughnessMapUv ? "#define CLEARCOAT_ROUGHNESSMAP_UV " + parameters.clearcoatRoughnessMapUv : "",
|
|
parameters.iridescenceMapUv ? "#define IRIDESCENCEMAP_UV " + parameters.iridescenceMapUv : "",
|
|
parameters.iridescenceThicknessMapUv ? "#define IRIDESCENCE_THICKNESSMAP_UV " + parameters.iridescenceThicknessMapUv : "",
|
|
parameters.sheenColorMapUv ? "#define SHEEN_COLORMAP_UV " + parameters.sheenColorMapUv : "",
|
|
parameters.sheenRoughnessMapUv ? "#define SHEEN_ROUGHNESSMAP_UV " + parameters.sheenRoughnessMapUv : "",
|
|
parameters.specularMapUv ? "#define SPECULARMAP_UV " + parameters.specularMapUv : "",
|
|
parameters.specularColorMapUv ? "#define SPECULAR_COLORMAP_UV " + parameters.specularColorMapUv : "",
|
|
parameters.specularIntensityMapUv ? "#define SPECULAR_INTENSITYMAP_UV " + parameters.specularIntensityMapUv : "",
|
|
parameters.transmissionMapUv ? "#define TRANSMISSIONMAP_UV " + parameters.transmissionMapUv : "",
|
|
parameters.thicknessMapUv ? "#define THICKNESSMAP_UV " + parameters.thicknessMapUv : "",
|
|
parameters.vertexTangents && parameters.flatShading === false ? "#define USE_TANGENT" : "",
|
|
parameters.vertexColors ? "#define USE_COLOR" : "",
|
|
parameters.vertexAlphas ? "#define USE_COLOR_ALPHA" : "",
|
|
parameters.vertexUv1s ? "#define USE_UV1" : "",
|
|
parameters.vertexUv2s ? "#define USE_UV2" : "",
|
|
parameters.vertexUv3s ? "#define USE_UV3" : "",
|
|
parameters.pointsUvs ? "#define USE_POINTS_UV" : "",
|
|
parameters.flatShading ? "#define FLAT_SHADED" : "",
|
|
parameters.skinning ? "#define USE_SKINNING" : "",
|
|
parameters.morphTargets ? "#define USE_MORPHTARGETS" : "",
|
|
parameters.morphNormals && parameters.flatShading === false ? "#define USE_MORPHNORMALS" : "",
|
|
parameters.morphColors ? "#define USE_MORPHCOLORS" : "",
|
|
parameters.morphTargetsCount > 0 ? "#define MORPHTARGETS_TEXTURE_STRIDE " + parameters.morphTextureStride : "",
|
|
parameters.morphTargetsCount > 0 ? "#define MORPHTARGETS_COUNT " + parameters.morphTargetsCount : "",
|
|
parameters.doubleSided ? "#define DOUBLE_SIDED" : "",
|
|
parameters.flipSided ? "#define FLIP_SIDED" : "",
|
|
parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
|
|
parameters.shadowMapEnabled ? "#define " + shadowMapTypeDefine : "",
|
|
parameters.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "",
|
|
parameters.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "",
|
|
parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
|
|
parameters.reverseDepthBuffer ? "#define USE_REVERSEDEPTHBUF" : "",
|
|
"uniform mat4 modelMatrix;",
|
|
"uniform mat4 modelViewMatrix;",
|
|
"uniform mat4 projectionMatrix;",
|
|
"uniform mat4 viewMatrix;",
|
|
"uniform mat3 normalMatrix;",
|
|
"uniform vec3 cameraPosition;",
|
|
"uniform bool isOrthographic;",
|
|
"#ifdef USE_INSTANCING",
|
|
"\tattribute mat4 instanceMatrix;",
|
|
"#endif",
|
|
"#ifdef USE_INSTANCING_COLOR",
|
|
"\tattribute vec3 instanceColor;",
|
|
"#endif",
|
|
"#ifdef USE_INSTANCING_MORPH",
|
|
"\tuniform sampler2D morphTexture;",
|
|
"#endif",
|
|
"attribute vec3 position;",
|
|
"attribute vec3 normal;",
|
|
"attribute vec2 uv;",
|
|
"#ifdef USE_UV1",
|
|
"\tattribute vec2 uv1;",
|
|
"#endif",
|
|
"#ifdef USE_UV2",
|
|
"\tattribute vec2 uv2;",
|
|
"#endif",
|
|
"#ifdef USE_UV3",
|
|
"\tattribute vec2 uv3;",
|
|
"#endif",
|
|
"#ifdef USE_TANGENT",
|
|
"\tattribute vec4 tangent;",
|
|
"#endif",
|
|
"#if defined( USE_COLOR_ALPHA )",
|
|
"\tattribute vec4 color;",
|
|
"#elif defined( USE_COLOR )",
|
|
"\tattribute vec3 color;",
|
|
"#endif",
|
|
"#ifdef USE_SKINNING",
|
|
"\tattribute vec4 skinIndex;",
|
|
"\tattribute vec4 skinWeight;",
|
|
"#endif",
|
|
`
|
|
`
|
|
].filter(filterEmptyLine).join(`
|
|
`);
|
|
prefixFragment = [
|
|
generatePrecision(parameters),
|
|
"#define SHADER_TYPE " + parameters.shaderType,
|
|
"#define SHADER_NAME " + parameters.shaderName,
|
|
customDefines,
|
|
parameters.useFog && parameters.fog ? "#define USE_FOG" : "",
|
|
parameters.useFog && parameters.fogExp2 ? "#define FOG_EXP2" : "",
|
|
parameters.alphaToCoverage ? "#define ALPHA_TO_COVERAGE" : "",
|
|
parameters.map ? "#define USE_MAP" : "",
|
|
parameters.matcap ? "#define USE_MATCAP" : "",
|
|
parameters.envMap ? "#define USE_ENVMAP" : "",
|
|
parameters.envMap ? "#define " + envMapTypeDefine : "",
|
|
parameters.envMap ? "#define " + envMapModeDefine : "",
|
|
parameters.envMap ? "#define " + envMapBlendingDefine : "",
|
|
envMapCubeUVSize ? "#define CUBEUV_TEXEL_WIDTH " + envMapCubeUVSize.texelWidth : "",
|
|
envMapCubeUVSize ? "#define CUBEUV_TEXEL_HEIGHT " + envMapCubeUVSize.texelHeight : "",
|
|
envMapCubeUVSize ? "#define CUBEUV_MAX_MIP " + envMapCubeUVSize.maxMip + ".0" : "",
|
|
parameters.lightMap ? "#define USE_LIGHTMAP" : "",
|
|
parameters.aoMap ? "#define USE_AOMAP" : "",
|
|
parameters.bumpMap ? "#define USE_BUMPMAP" : "",
|
|
parameters.normalMap ? "#define USE_NORMALMAP" : "",
|
|
parameters.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "",
|
|
parameters.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "",
|
|
parameters.emissiveMap ? "#define USE_EMISSIVEMAP" : "",
|
|
parameters.anisotropy ? "#define USE_ANISOTROPY" : "",
|
|
parameters.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "",
|
|
parameters.clearcoat ? "#define USE_CLEARCOAT" : "",
|
|
parameters.clearcoatMap ? "#define USE_CLEARCOATMAP" : "",
|
|
parameters.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "",
|
|
parameters.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "",
|
|
parameters.dispersion ? "#define USE_DISPERSION" : "",
|
|
parameters.iridescence ? "#define USE_IRIDESCENCE" : "",
|
|
parameters.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "",
|
|
parameters.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "",
|
|
parameters.specularMap ? "#define USE_SPECULARMAP" : "",
|
|
parameters.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "",
|
|
parameters.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "",
|
|
parameters.roughnessMap ? "#define USE_ROUGHNESSMAP" : "",
|
|
parameters.metalnessMap ? "#define USE_METALNESSMAP" : "",
|
|
parameters.alphaMap ? "#define USE_ALPHAMAP" : "",
|
|
parameters.alphaTest ? "#define USE_ALPHATEST" : "",
|
|
parameters.alphaHash ? "#define USE_ALPHAHASH" : "",
|
|
parameters.sheen ? "#define USE_SHEEN" : "",
|
|
parameters.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "",
|
|
parameters.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "",
|
|
parameters.transmission ? "#define USE_TRANSMISSION" : "",
|
|
parameters.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "",
|
|
parameters.thicknessMap ? "#define USE_THICKNESSMAP" : "",
|
|
parameters.vertexTangents && parameters.flatShading === false ? "#define USE_TANGENT" : "",
|
|
parameters.vertexColors || parameters.instancingColor || parameters.batchingColor ? "#define USE_COLOR" : "",
|
|
parameters.vertexAlphas ? "#define USE_COLOR_ALPHA" : "",
|
|
parameters.vertexUv1s ? "#define USE_UV1" : "",
|
|
parameters.vertexUv2s ? "#define USE_UV2" : "",
|
|
parameters.vertexUv3s ? "#define USE_UV3" : "",
|
|
parameters.pointsUvs ? "#define USE_POINTS_UV" : "",
|
|
parameters.gradientMap ? "#define USE_GRADIENTMAP" : "",
|
|
parameters.flatShading ? "#define FLAT_SHADED" : "",
|
|
parameters.doubleSided ? "#define DOUBLE_SIDED" : "",
|
|
parameters.flipSided ? "#define FLIP_SIDED" : "",
|
|
parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
|
|
parameters.shadowMapEnabled ? "#define " + shadowMapTypeDefine : "",
|
|
parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : "",
|
|
parameters.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "",
|
|
parameters.decodeVideoTexture ? "#define DECODE_VIDEO_TEXTURE" : "",
|
|
parameters.decodeVideoTextureEmissive ? "#define DECODE_VIDEO_TEXTURE_EMISSIVE" : "",
|
|
parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
|
|
parameters.reverseDepthBuffer ? "#define USE_REVERSEDEPTHBUF" : "",
|
|
"uniform mat4 viewMatrix;",
|
|
"uniform vec3 cameraPosition;",
|
|
"uniform bool isOrthographic;",
|
|
parameters.toneMapping !== NoToneMapping ? "#define TONE_MAPPING" : "",
|
|
parameters.toneMapping !== NoToneMapping ? ShaderChunk["tonemapping_pars_fragment"] : "",
|
|
parameters.toneMapping !== NoToneMapping ? getToneMappingFunction("toneMapping", parameters.toneMapping) : "",
|
|
parameters.dithering ? "#define DITHERING" : "",
|
|
parameters.opaque ? "#define OPAQUE" : "",
|
|
ShaderChunk["colorspace_pars_fragment"],
|
|
getTexelEncodingFunction("linearToOutputTexel", parameters.outputColorSpace),
|
|
getLuminanceFunction(),
|
|
parameters.useDepthPacking ? "#define DEPTH_PACKING " + parameters.depthPacking : "",
|
|
`
|
|
`
|
|
].filter(filterEmptyLine).join(`
|
|
`);
|
|
}
|
|
vertexShader = resolveIncludes(vertexShader);
|
|
vertexShader = replaceLightNums(vertexShader, parameters);
|
|
vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
|
|
fragmentShader = resolveIncludes(fragmentShader);
|
|
fragmentShader = replaceLightNums(fragmentShader, parameters);
|
|
fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
|
|
vertexShader = unrollLoops(vertexShader);
|
|
fragmentShader = unrollLoops(fragmentShader);
|
|
if (parameters.isRawShaderMaterial !== true) {
|
|
versionString = `#version 300 es
|
|
`;
|
|
prefixVertex = [
|
|
customVertexExtensions,
|
|
"#define attribute in",
|
|
"#define varying out",
|
|
"#define texture2D texture"
|
|
].join(`
|
|
`) + `
|
|
` + prefixVertex;
|
|
prefixFragment = [
|
|
"#define varying in",
|
|
parameters.glslVersion === GLSL3 ? "" : "layout(location = 0) out highp vec4 pc_fragColor;",
|
|
parameters.glslVersion === GLSL3 ? "" : "#define gl_FragColor pc_fragColor",
|
|
"#define gl_FragDepthEXT gl_FragDepth",
|
|
"#define texture2D texture",
|
|
"#define textureCube texture",
|
|
"#define texture2DProj textureProj",
|
|
"#define texture2DLodEXT textureLod",
|
|
"#define texture2DProjLodEXT textureProjLod",
|
|
"#define textureCubeLodEXT textureLod",
|
|
"#define texture2DGradEXT textureGrad",
|
|
"#define texture2DProjGradEXT textureProjGrad",
|
|
"#define textureCubeGradEXT textureGrad"
|
|
].join(`
|
|
`) + `
|
|
` + prefixFragment;
|
|
if (numMultiviewViews > 0) {
|
|
prefixVertex = [
|
|
"#extension GL_OVR_multiview : require",
|
|
"layout(num_views = " + numMultiviewViews + ") in;",
|
|
"#define VIEW_ID gl_ViewID_OVR"
|
|
].join(`
|
|
`) + `
|
|
` + prefixVertex;
|
|
prefixVertex = prefixVertex.replace([
|
|
"uniform mat4 modelViewMatrix;",
|
|
"uniform mat4 projectionMatrix;",
|
|
"uniform mat4 viewMatrix;",
|
|
"uniform mat3 normalMatrix;"
|
|
].join(`
|
|
`), [
|
|
"uniform mat4 modelViewMatrices[" + numMultiviewViews + "];",
|
|
"uniform mat4 projectionMatrices[" + numMultiviewViews + "];",
|
|
"uniform mat4 viewMatrices[" + numMultiviewViews + "];",
|
|
"uniform mat3 normalMatrices[" + numMultiviewViews + "];",
|
|
"#define modelViewMatrix modelViewMatrices[VIEW_ID]",
|
|
"#define projectionMatrix projectionMatrices[VIEW_ID]",
|
|
"#define viewMatrix viewMatrices[VIEW_ID]",
|
|
"#define normalMatrix normalMatrices[VIEW_ID]"
|
|
].join(`
|
|
`));
|
|
prefixFragment = [
|
|
"#extension GL_OVR_multiview : require",
|
|
"#define VIEW_ID gl_ViewID_OVR"
|
|
].join(`
|
|
`) + `
|
|
` + prefixFragment;
|
|
prefixFragment = prefixFragment.replace("uniform mat4 viewMatrix;", [
|
|
"uniform mat4 viewMatrices[" + numMultiviewViews + "];",
|
|
"#define viewMatrix viewMatrices[VIEW_ID]"
|
|
].join(`
|
|
`));
|
|
}
|
|
}
|
|
const vertexGlsl = versionString + prefixVertex + vertexShader;
|
|
const fragmentGlsl = versionString + prefixFragment + fragmentShader;
|
|
const glVertexShader = WebGLShader(gl, gl.VERTEX_SHADER, vertexGlsl);
|
|
const glFragmentShader = WebGLShader(gl, gl.FRAGMENT_SHADER, fragmentGlsl);
|
|
gl.attachShader(program, glVertexShader);
|
|
gl.attachShader(program, glFragmentShader);
|
|
if (parameters.index0AttributeName !== undefined) {
|
|
gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
|
|
} else if (parameters.morphTargets === true) {
|
|
gl.bindAttribLocation(program, 0, "position");
|
|
}
|
|
gl.linkProgram(program);
|
|
function onFirstUse(self2) {
|
|
if (renderer.debug.checkShaderErrors) {
|
|
const programLog = gl.getProgramInfoLog(program).trim();
|
|
const vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
|
|
const fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
|
|
let runnable = true;
|
|
let haveDiagnostics = true;
|
|
if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) {
|
|
runnable = false;
|
|
if (typeof renderer.debug.onShaderError === "function") {
|
|
renderer.debug.onShaderError(gl, program, glVertexShader, glFragmentShader);
|
|
} else {
|
|
const vertexErrors = getShaderErrors(gl, glVertexShader, "vertex");
|
|
const fragmentErrors = getShaderErrors(gl, glFragmentShader, "fragment");
|
|
console.error("THREE.WebGLProgram: Shader Error " + gl.getError() + " - " + "VALIDATE_STATUS " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + `
|
|
|
|
` + "Material Name: " + self2.name + `
|
|
` + "Material Type: " + self2.type + `
|
|
|
|
` + "Program Info Log: " + programLog + `
|
|
` + vertexErrors + `
|
|
` + fragmentErrors);
|
|
}
|
|
} else if (programLog !== "") {
|
|
console.warn("THREE.WebGLProgram: Program Info Log:", programLog);
|
|
} else if (vertexLog === "" || fragmentLog === "") {
|
|
haveDiagnostics = false;
|
|
}
|
|
if (haveDiagnostics) {
|
|
self2.diagnostics = {
|
|
runnable,
|
|
programLog,
|
|
vertexShader: {
|
|
log: vertexLog,
|
|
prefix: prefixVertex
|
|
},
|
|
fragmentShader: {
|
|
log: fragmentLog,
|
|
prefix: prefixFragment
|
|
}
|
|
};
|
|
}
|
|
}
|
|
gl.deleteShader(glVertexShader);
|
|
gl.deleteShader(glFragmentShader);
|
|
cachedUniforms = new WebGLUniforms(gl, program);
|
|
cachedAttributes = fetchAttributeLocations(gl, program);
|
|
}
|
|
let cachedUniforms;
|
|
this.getUniforms = function() {
|
|
if (cachedUniforms === undefined) {
|
|
onFirstUse(this);
|
|
}
|
|
return cachedUniforms;
|
|
};
|
|
let cachedAttributes;
|
|
this.getAttributes = function() {
|
|
if (cachedAttributes === undefined) {
|
|
onFirstUse(this);
|
|
}
|
|
return cachedAttributes;
|
|
};
|
|
let programReady = parameters.rendererExtensionParallelShaderCompile === false;
|
|
this.isReady = function() {
|
|
if (programReady === false) {
|
|
programReady = gl.getProgramParameter(program, COMPLETION_STATUS_KHR);
|
|
}
|
|
return programReady;
|
|
};
|
|
this.destroy = function() {
|
|
bindingStates.releaseStatesOfProgram(this);
|
|
gl.deleteProgram(program);
|
|
this.program = undefined;
|
|
};
|
|
this.type = parameters.shaderType;
|
|
this.name = parameters.shaderName;
|
|
this.id = programIdCount++;
|
|
this.cacheKey = cacheKey;
|
|
this.usedTimes = 1;
|
|
this.program = program;
|
|
this.vertexShader = glVertexShader;
|
|
this.fragmentShader = glFragmentShader;
|
|
this.numMultiviewViews = numMultiviewViews;
|
|
return this;
|
|
}
|
|
|
|
class WebGLShaderCache {
|
|
constructor() {
|
|
this.shaderCache = new Map;
|
|
this.materialCache = new Map;
|
|
}
|
|
update(material) {
|
|
const vertexShader = material.vertexShader;
|
|
const fragmentShader = material.fragmentShader;
|
|
const vertexShaderStage = this._getShaderStage(vertexShader);
|
|
const fragmentShaderStage = this._getShaderStage(fragmentShader);
|
|
const materialShaders = this._getShaderCacheForMaterial(material);
|
|
if (materialShaders.has(vertexShaderStage) === false) {
|
|
materialShaders.add(vertexShaderStage);
|
|
vertexShaderStage.usedTimes++;
|
|
}
|
|
if (materialShaders.has(fragmentShaderStage) === false) {
|
|
materialShaders.add(fragmentShaderStage);
|
|
fragmentShaderStage.usedTimes++;
|
|
}
|
|
return this;
|
|
}
|
|
remove(material) {
|
|
const materialShaders = this.materialCache.get(material);
|
|
for (const shaderStage of materialShaders) {
|
|
shaderStage.usedTimes--;
|
|
if (shaderStage.usedTimes === 0)
|
|
this.shaderCache.delete(shaderStage.code);
|
|
}
|
|
this.materialCache.delete(material);
|
|
return this;
|
|
}
|
|
getVertexShaderID(material) {
|
|
return this._getShaderStage(material.vertexShader).id;
|
|
}
|
|
getFragmentShaderID(material) {
|
|
return this._getShaderStage(material.fragmentShader).id;
|
|
}
|
|
dispose() {
|
|
this.shaderCache.clear();
|
|
this.materialCache.clear();
|
|
}
|
|
_getShaderCacheForMaterial(material) {
|
|
const cache = this.materialCache;
|
|
let set = cache.get(material);
|
|
if (set === undefined) {
|
|
set = new Set;
|
|
cache.set(material, set);
|
|
}
|
|
return set;
|
|
}
|
|
_getShaderStage(code) {
|
|
const cache = this.shaderCache;
|
|
let stage = cache.get(code);
|
|
if (stage === undefined) {
|
|
stage = new WebGLShaderStage(code);
|
|
cache.set(code, stage);
|
|
}
|
|
return stage;
|
|
}
|
|
}
|
|
|
|
class WebGLShaderStage {
|
|
constructor(code) {
|
|
this.id = _id2++;
|
|
this.code = code;
|
|
this.usedTimes = 0;
|
|
}
|
|
}
|
|
function WebGLPrograms(renderer, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping) {
|
|
const _programLayers = new Layers;
|
|
const _customShaders = new WebGLShaderCache;
|
|
const _activeChannels = new Set;
|
|
const programs = [];
|
|
const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
|
|
const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures;
|
|
let precision = capabilities.precision;
|
|
const shaderIDs = {
|
|
MeshDepthMaterial: "depth",
|
|
MeshDistanceMaterial: "distanceRGBA",
|
|
MeshNormalMaterial: "normal",
|
|
MeshBasicMaterial: "basic",
|
|
MeshLambertMaterial: "lambert",
|
|
MeshPhongMaterial: "phong",
|
|
MeshToonMaterial: "toon",
|
|
MeshStandardMaterial: "physical",
|
|
MeshPhysicalMaterial: "physical",
|
|
MeshMatcapMaterial: "matcap",
|
|
LineBasicMaterial: "basic",
|
|
LineDashedMaterial: "dashed",
|
|
PointsMaterial: "points",
|
|
ShadowMaterial: "shadow",
|
|
SpriteMaterial: "sprite"
|
|
};
|
|
function getChannel(value) {
|
|
_activeChannels.add(value);
|
|
if (value === 0)
|
|
return "uv";
|
|
return `uv${value}`;
|
|
}
|
|
function getParameters(material, lights, shadows, scene, object) {
|
|
const fog = scene.fog;
|
|
const geometry = object.geometry;
|
|
const environment = material.isMeshStandardMaterial ? scene.environment : null;
|
|
const envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || environment);
|
|
const envMapCubeUVHeight = !!envMap && envMap.mapping === CubeUVReflectionMapping ? envMap.image.height : null;
|
|
const shaderID = shaderIDs[material.type];
|
|
if (material.precision !== null) {
|
|
precision = capabilities.getMaxPrecision(material.precision);
|
|
if (precision !== material.precision) {
|
|
console.warn("THREE.WebGLProgram.getParameters:", material.precision, "not supported, using", precision, "instead.");
|
|
}
|
|
}
|
|
const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;
|
|
const morphTargetsCount = morphAttribute !== undefined ? morphAttribute.length : 0;
|
|
let morphTextureStride = 0;
|
|
if (geometry.morphAttributes.position !== undefined)
|
|
morphTextureStride = 1;
|
|
if (geometry.morphAttributes.normal !== undefined)
|
|
morphTextureStride = 2;
|
|
if (geometry.morphAttributes.color !== undefined)
|
|
morphTextureStride = 3;
|
|
let vertexShader, fragmentShader;
|
|
let customVertexShaderID, customFragmentShaderID;
|
|
if (shaderID) {
|
|
const shader = ShaderLib[shaderID];
|
|
vertexShader = shader.vertexShader;
|
|
fragmentShader = shader.fragmentShader;
|
|
} else {
|
|
vertexShader = material.vertexShader;
|
|
fragmentShader = material.fragmentShader;
|
|
_customShaders.update(material);
|
|
customVertexShaderID = _customShaders.getVertexShaderID(material);
|
|
customFragmentShaderID = _customShaders.getFragmentShaderID(material);
|
|
}
|
|
const currentRenderTarget = renderer.getRenderTarget();
|
|
const reverseDepthBuffer = renderer.state.buffers.depth.getReversed();
|
|
const numMultiviewViews = currentRenderTarget && currentRenderTarget.isWebGLMultiviewRenderTarget ? currentRenderTarget.numViews : 0;
|
|
const IS_INSTANCEDMESH = object.isInstancedMesh === true;
|
|
const IS_BATCHEDMESH = object.isBatchedMesh === true;
|
|
const HAS_MAP = !!material.map;
|
|
const HAS_MATCAP = !!material.matcap;
|
|
const HAS_ENVMAP = !!envMap;
|
|
const HAS_AOMAP = !!material.aoMap;
|
|
const HAS_LIGHTMAP = !!material.lightMap;
|
|
const HAS_BUMPMAP = !!material.bumpMap;
|
|
const HAS_NORMALMAP = !!material.normalMap;
|
|
const HAS_DISPLACEMENTMAP = !!material.displacementMap;
|
|
const HAS_EMISSIVEMAP = !!material.emissiveMap;
|
|
const HAS_METALNESSMAP = !!material.metalnessMap;
|
|
const HAS_ROUGHNESSMAP = !!material.roughnessMap;
|
|
const HAS_ANISOTROPY = material.anisotropy > 0;
|
|
const HAS_CLEARCOAT = material.clearcoat > 0;
|
|
const HAS_DISPERSION = material.dispersion > 0;
|
|
const HAS_IRIDESCENCE = material.iridescence > 0;
|
|
const HAS_SHEEN = material.sheen > 0;
|
|
const HAS_TRANSMISSION = material.transmission > 0;
|
|
const HAS_ANISOTROPYMAP = HAS_ANISOTROPY && !!material.anisotropyMap;
|
|
const HAS_CLEARCOATMAP = HAS_CLEARCOAT && !!material.clearcoatMap;
|
|
const HAS_CLEARCOAT_NORMALMAP = HAS_CLEARCOAT && !!material.clearcoatNormalMap;
|
|
const HAS_CLEARCOAT_ROUGHNESSMAP = HAS_CLEARCOAT && !!material.clearcoatRoughnessMap;
|
|
const HAS_IRIDESCENCEMAP = HAS_IRIDESCENCE && !!material.iridescenceMap;
|
|
const HAS_IRIDESCENCE_THICKNESSMAP = HAS_IRIDESCENCE && !!material.iridescenceThicknessMap;
|
|
const HAS_SHEEN_COLORMAP = HAS_SHEEN && !!material.sheenColorMap;
|
|
const HAS_SHEEN_ROUGHNESSMAP = HAS_SHEEN && !!material.sheenRoughnessMap;
|
|
const HAS_SPECULARMAP = !!material.specularMap;
|
|
const HAS_SPECULAR_COLORMAP = !!material.specularColorMap;
|
|
const HAS_SPECULAR_INTENSITYMAP = !!material.specularIntensityMap;
|
|
const HAS_TRANSMISSIONMAP = HAS_TRANSMISSION && !!material.transmissionMap;
|
|
const HAS_THICKNESSMAP = HAS_TRANSMISSION && !!material.thicknessMap;
|
|
const HAS_GRADIENTMAP = !!material.gradientMap;
|
|
const HAS_ALPHAMAP = !!material.alphaMap;
|
|
const HAS_ALPHATEST = material.alphaTest > 0;
|
|
const HAS_ALPHAHASH = !!material.alphaHash;
|
|
const HAS_EXTENSIONS = !!material.extensions;
|
|
let toneMapping = NoToneMapping;
|
|
if (material.toneMapped) {
|
|
if (currentRenderTarget === null || currentRenderTarget.isXRRenderTarget === true) {
|
|
toneMapping = renderer.toneMapping;
|
|
}
|
|
}
|
|
const parameters = {
|
|
shaderID,
|
|
shaderType: material.type,
|
|
shaderName: material.name,
|
|
vertexShader,
|
|
fragmentShader,
|
|
defines: material.defines,
|
|
customVertexShaderID,
|
|
customFragmentShaderID,
|
|
isRawShaderMaterial: material.isRawShaderMaterial === true,
|
|
glslVersion: material.glslVersion,
|
|
precision,
|
|
batching: IS_BATCHEDMESH,
|
|
batchingColor: IS_BATCHEDMESH && object._colorsTexture !== null,
|
|
instancing: IS_INSTANCEDMESH,
|
|
instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null,
|
|
instancingMorph: IS_INSTANCEDMESH && object.morphTexture !== null,
|
|
supportsVertexTextures: SUPPORTS_VERTEX_TEXTURES,
|
|
numMultiviewViews,
|
|
outputColorSpace: currentRenderTarget === null ? renderer.outputColorSpace : currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace,
|
|
alphaToCoverage: !!material.alphaToCoverage,
|
|
map: HAS_MAP,
|
|
matcap: HAS_MATCAP,
|
|
envMap: HAS_ENVMAP,
|
|
envMapMode: HAS_ENVMAP && envMap.mapping,
|
|
envMapCubeUVHeight,
|
|
aoMap: HAS_AOMAP,
|
|
lightMap: HAS_LIGHTMAP,
|
|
bumpMap: HAS_BUMPMAP,
|
|
normalMap: HAS_NORMALMAP,
|
|
displacementMap: SUPPORTS_VERTEX_TEXTURES && HAS_DISPLACEMENTMAP,
|
|
emissiveMap: HAS_EMISSIVEMAP,
|
|
normalMapObjectSpace: HAS_NORMALMAP && material.normalMapType === ObjectSpaceNormalMap,
|
|
normalMapTangentSpace: HAS_NORMALMAP && material.normalMapType === TangentSpaceNormalMap,
|
|
metalnessMap: HAS_METALNESSMAP,
|
|
roughnessMap: HAS_ROUGHNESSMAP,
|
|
anisotropy: HAS_ANISOTROPY,
|
|
anisotropyMap: HAS_ANISOTROPYMAP,
|
|
clearcoat: HAS_CLEARCOAT,
|
|
clearcoatMap: HAS_CLEARCOATMAP,
|
|
clearcoatNormalMap: HAS_CLEARCOAT_NORMALMAP,
|
|
clearcoatRoughnessMap: HAS_CLEARCOAT_ROUGHNESSMAP,
|
|
dispersion: HAS_DISPERSION,
|
|
iridescence: HAS_IRIDESCENCE,
|
|
iridescenceMap: HAS_IRIDESCENCEMAP,
|
|
iridescenceThicknessMap: HAS_IRIDESCENCE_THICKNESSMAP,
|
|
sheen: HAS_SHEEN,
|
|
sheenColorMap: HAS_SHEEN_COLORMAP,
|
|
sheenRoughnessMap: HAS_SHEEN_ROUGHNESSMAP,
|
|
specularMap: HAS_SPECULARMAP,
|
|
specularColorMap: HAS_SPECULAR_COLORMAP,
|
|
specularIntensityMap: HAS_SPECULAR_INTENSITYMAP,
|
|
transmission: HAS_TRANSMISSION,
|
|
transmissionMap: HAS_TRANSMISSIONMAP,
|
|
thicknessMap: HAS_THICKNESSMAP,
|
|
gradientMap: HAS_GRADIENTMAP,
|
|
opaque: material.transparent === false && material.blending === NormalBlending && material.alphaToCoverage === false,
|
|
alphaMap: HAS_ALPHAMAP,
|
|
alphaTest: HAS_ALPHATEST,
|
|
alphaHash: HAS_ALPHAHASH,
|
|
combine: material.combine,
|
|
mapUv: HAS_MAP && getChannel(material.map.channel),
|
|
aoMapUv: HAS_AOMAP && getChannel(material.aoMap.channel),
|
|
lightMapUv: HAS_LIGHTMAP && getChannel(material.lightMap.channel),
|
|
bumpMapUv: HAS_BUMPMAP && getChannel(material.bumpMap.channel),
|
|
normalMapUv: HAS_NORMALMAP && getChannel(material.normalMap.channel),
|
|
displacementMapUv: HAS_DISPLACEMENTMAP && getChannel(material.displacementMap.channel),
|
|
emissiveMapUv: HAS_EMISSIVEMAP && getChannel(material.emissiveMap.channel),
|
|
metalnessMapUv: HAS_METALNESSMAP && getChannel(material.metalnessMap.channel),
|
|
roughnessMapUv: HAS_ROUGHNESSMAP && getChannel(material.roughnessMap.channel),
|
|
anisotropyMapUv: HAS_ANISOTROPYMAP && getChannel(material.anisotropyMap.channel),
|
|
clearcoatMapUv: HAS_CLEARCOATMAP && getChannel(material.clearcoatMap.channel),
|
|
clearcoatNormalMapUv: HAS_CLEARCOAT_NORMALMAP && getChannel(material.clearcoatNormalMap.channel),
|
|
clearcoatRoughnessMapUv: HAS_CLEARCOAT_ROUGHNESSMAP && getChannel(material.clearcoatRoughnessMap.channel),
|
|
iridescenceMapUv: HAS_IRIDESCENCEMAP && getChannel(material.iridescenceMap.channel),
|
|
iridescenceThicknessMapUv: HAS_IRIDESCENCE_THICKNESSMAP && getChannel(material.iridescenceThicknessMap.channel),
|
|
sheenColorMapUv: HAS_SHEEN_COLORMAP && getChannel(material.sheenColorMap.channel),
|
|
sheenRoughnessMapUv: HAS_SHEEN_ROUGHNESSMAP && getChannel(material.sheenRoughnessMap.channel),
|
|
specularMapUv: HAS_SPECULARMAP && getChannel(material.specularMap.channel),
|
|
specularColorMapUv: HAS_SPECULAR_COLORMAP && getChannel(material.specularColorMap.channel),
|
|
specularIntensityMapUv: HAS_SPECULAR_INTENSITYMAP && getChannel(material.specularIntensityMap.channel),
|
|
transmissionMapUv: HAS_TRANSMISSIONMAP && getChannel(material.transmissionMap.channel),
|
|
thicknessMapUv: HAS_THICKNESSMAP && getChannel(material.thicknessMap.channel),
|
|
alphaMapUv: HAS_ALPHAMAP && getChannel(material.alphaMap.channel),
|
|
vertexTangents: !!geometry.attributes.tangent && (HAS_NORMALMAP || HAS_ANISOTROPY),
|
|
vertexColors: material.vertexColors,
|
|
vertexAlphas: material.vertexColors === true && !!geometry.attributes.color && geometry.attributes.color.itemSize === 4,
|
|
pointsUvs: object.isPoints === true && !!geometry.attributes.uv && (HAS_MAP || HAS_ALPHAMAP),
|
|
fog: !!fog,
|
|
useFog: material.fog === true,
|
|
fogExp2: !!fog && fog.isFogExp2,
|
|
flatShading: material.flatShading === true,
|
|
sizeAttenuation: material.sizeAttenuation === true,
|
|
logarithmicDepthBuffer,
|
|
reverseDepthBuffer,
|
|
skinning: object.isSkinnedMesh === true,
|
|
morphTargets: geometry.morphAttributes.position !== undefined,
|
|
morphNormals: geometry.morphAttributes.normal !== undefined,
|
|
morphColors: geometry.morphAttributes.color !== undefined,
|
|
morphTargetsCount,
|
|
morphTextureStride,
|
|
numDirLights: lights.directional.length,
|
|
numPointLights: lights.point.length,
|
|
numSpotLights: lights.spot.length,
|
|
numSpotLightMaps: lights.spotLightMap.length,
|
|
numRectAreaLights: lights.rectArea.length,
|
|
numHemiLights: lights.hemi.length,
|
|
numDirLightShadows: lights.directionalShadowMap.length,
|
|
numPointLightShadows: lights.pointShadowMap.length,
|
|
numSpotLightShadows: lights.spotShadowMap.length,
|
|
numSpotLightShadowsWithMaps: lights.numSpotLightShadowsWithMaps,
|
|
numLightProbes: lights.numLightProbes,
|
|
numClippingPlanes: clipping.numPlanes,
|
|
numClipIntersection: clipping.numIntersection,
|
|
dithering: material.dithering,
|
|
shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
|
|
shadowMapType: renderer.shadowMap.type,
|
|
toneMapping,
|
|
decodeVideoTexture: HAS_MAP && material.map.isVideoTexture === true && ColorManagement.getTransfer(material.map.colorSpace) === SRGBTransfer,
|
|
decodeVideoTextureEmissive: HAS_EMISSIVEMAP && material.emissiveMap.isVideoTexture === true && ColorManagement.getTransfer(material.emissiveMap.colorSpace) === SRGBTransfer,
|
|
premultipliedAlpha: material.premultipliedAlpha,
|
|
doubleSided: material.side === DoubleSide,
|
|
flipSided: material.side === BackSide,
|
|
useDepthPacking: material.depthPacking >= 0,
|
|
depthPacking: material.depthPacking || 0,
|
|
index0AttributeName: material.index0AttributeName,
|
|
extensionClipCullDistance: HAS_EXTENSIONS && material.extensions.clipCullDistance === true && extensions.has("WEBGL_clip_cull_distance"),
|
|
extensionMultiDraw: (HAS_EXTENSIONS && material.extensions.multiDraw === true || IS_BATCHEDMESH) && extensions.has("WEBGL_multi_draw"),
|
|
rendererExtensionParallelShaderCompile: extensions.has("KHR_parallel_shader_compile"),
|
|
customProgramCacheKey: material.customProgramCacheKey()
|
|
};
|
|
parameters.vertexUv1s = _activeChannels.has(1);
|
|
parameters.vertexUv2s = _activeChannels.has(2);
|
|
parameters.vertexUv3s = _activeChannels.has(3);
|
|
_activeChannels.clear();
|
|
return parameters;
|
|
}
|
|
function getProgramCacheKey(parameters) {
|
|
const array = [];
|
|
if (parameters.shaderID) {
|
|
array.push(parameters.shaderID);
|
|
} else {
|
|
array.push(parameters.customVertexShaderID);
|
|
array.push(parameters.customFragmentShaderID);
|
|
}
|
|
if (parameters.defines !== undefined) {
|
|
for (const name in parameters.defines) {
|
|
array.push(name);
|
|
array.push(parameters.defines[name]);
|
|
}
|
|
}
|
|
if (parameters.isRawShaderMaterial === false) {
|
|
getProgramCacheKeyParameters(array, parameters);
|
|
getProgramCacheKeyBooleans(array, parameters);
|
|
array.push(renderer.outputColorSpace);
|
|
}
|
|
array.push(parameters.customProgramCacheKey);
|
|
return array.join();
|
|
}
|
|
function getProgramCacheKeyParameters(array, parameters) {
|
|
array.push(parameters.precision);
|
|
array.push(parameters.outputColorSpace);
|
|
array.push(parameters.envMapMode);
|
|
array.push(parameters.envMapCubeUVHeight);
|
|
array.push(parameters.mapUv);
|
|
array.push(parameters.alphaMapUv);
|
|
array.push(parameters.lightMapUv);
|
|
array.push(parameters.aoMapUv);
|
|
array.push(parameters.bumpMapUv);
|
|
array.push(parameters.normalMapUv);
|
|
array.push(parameters.displacementMapUv);
|
|
array.push(parameters.emissiveMapUv);
|
|
array.push(parameters.metalnessMapUv);
|
|
array.push(parameters.roughnessMapUv);
|
|
array.push(parameters.anisotropyMapUv);
|
|
array.push(parameters.clearcoatMapUv);
|
|
array.push(parameters.clearcoatNormalMapUv);
|
|
array.push(parameters.clearcoatRoughnessMapUv);
|
|
array.push(parameters.iridescenceMapUv);
|
|
array.push(parameters.iridescenceThicknessMapUv);
|
|
array.push(parameters.sheenColorMapUv);
|
|
array.push(parameters.sheenRoughnessMapUv);
|
|
array.push(parameters.specularMapUv);
|
|
array.push(parameters.specularColorMapUv);
|
|
array.push(parameters.specularIntensityMapUv);
|
|
array.push(parameters.transmissionMapUv);
|
|
array.push(parameters.thicknessMapUv);
|
|
array.push(parameters.combine);
|
|
array.push(parameters.fogExp2);
|
|
array.push(parameters.sizeAttenuation);
|
|
array.push(parameters.morphTargetsCount);
|
|
array.push(parameters.morphAttributeCount);
|
|
array.push(parameters.numDirLights);
|
|
array.push(parameters.numPointLights);
|
|
array.push(parameters.numSpotLights);
|
|
array.push(parameters.numSpotLightMaps);
|
|
array.push(parameters.numHemiLights);
|
|
array.push(parameters.numRectAreaLights);
|
|
array.push(parameters.numDirLightShadows);
|
|
array.push(parameters.numPointLightShadows);
|
|
array.push(parameters.numSpotLightShadows);
|
|
array.push(parameters.numSpotLightShadowsWithMaps);
|
|
array.push(parameters.numLightProbes);
|
|
array.push(parameters.shadowMapType);
|
|
array.push(parameters.toneMapping);
|
|
array.push(parameters.numClippingPlanes);
|
|
array.push(parameters.numClipIntersection);
|
|
array.push(parameters.depthPacking);
|
|
}
|
|
function getProgramCacheKeyBooleans(array, parameters) {
|
|
_programLayers.disableAll();
|
|
if (parameters.supportsVertexTextures)
|
|
_programLayers.enable(0);
|
|
if (parameters.instancing)
|
|
_programLayers.enable(1);
|
|
if (parameters.instancingColor)
|
|
_programLayers.enable(2);
|
|
if (parameters.instancingMorph)
|
|
_programLayers.enable(3);
|
|
if (parameters.matcap)
|
|
_programLayers.enable(4);
|
|
if (parameters.envMap)
|
|
_programLayers.enable(5);
|
|
if (parameters.normalMapObjectSpace)
|
|
_programLayers.enable(6);
|
|
if (parameters.normalMapTangentSpace)
|
|
_programLayers.enable(7);
|
|
if (parameters.clearcoat)
|
|
_programLayers.enable(8);
|
|
if (parameters.iridescence)
|
|
_programLayers.enable(9);
|
|
if (parameters.alphaTest)
|
|
_programLayers.enable(10);
|
|
if (parameters.vertexColors)
|
|
_programLayers.enable(11);
|
|
if (parameters.vertexAlphas)
|
|
_programLayers.enable(12);
|
|
if (parameters.vertexUv1s)
|
|
_programLayers.enable(13);
|
|
if (parameters.vertexUv2s)
|
|
_programLayers.enable(14);
|
|
if (parameters.vertexUv3s)
|
|
_programLayers.enable(15);
|
|
if (parameters.vertexTangents)
|
|
_programLayers.enable(16);
|
|
if (parameters.anisotropy)
|
|
_programLayers.enable(17);
|
|
if (parameters.alphaHash)
|
|
_programLayers.enable(18);
|
|
if (parameters.batching)
|
|
_programLayers.enable(19);
|
|
if (parameters.dispersion)
|
|
_programLayers.enable(20);
|
|
if (parameters.batchingColor)
|
|
_programLayers.enable(21);
|
|
array.push(_programLayers.mask);
|
|
_programLayers.disableAll();
|
|
if (parameters.fog)
|
|
_programLayers.enable(0);
|
|
if (parameters.useFog)
|
|
_programLayers.enable(1);
|
|
if (parameters.flatShading)
|
|
_programLayers.enable(2);
|
|
if (parameters.logarithmicDepthBuffer)
|
|
_programLayers.enable(3);
|
|
if (parameters.reverseDepthBuffer)
|
|
_programLayers.enable(4);
|
|
if (parameters.skinning)
|
|
_programLayers.enable(5);
|
|
if (parameters.morphTargets)
|
|
_programLayers.enable(6);
|
|
if (parameters.morphNormals)
|
|
_programLayers.enable(7);
|
|
if (parameters.morphColors)
|
|
_programLayers.enable(8);
|
|
if (parameters.premultipliedAlpha)
|
|
_programLayers.enable(9);
|
|
if (parameters.shadowMapEnabled)
|
|
_programLayers.enable(10);
|
|
if (parameters.doubleSided)
|
|
_programLayers.enable(11);
|
|
if (parameters.flipSided)
|
|
_programLayers.enable(12);
|
|
if (parameters.useDepthPacking)
|
|
_programLayers.enable(13);
|
|
if (parameters.dithering)
|
|
_programLayers.enable(14);
|
|
if (parameters.transmission)
|
|
_programLayers.enable(15);
|
|
if (parameters.sheen)
|
|
_programLayers.enable(16);
|
|
if (parameters.opaque)
|
|
_programLayers.enable(17);
|
|
if (parameters.pointsUvs)
|
|
_programLayers.enable(18);
|
|
if (parameters.decodeVideoTexture)
|
|
_programLayers.enable(19);
|
|
if (parameters.decodeVideoTextureEmissive)
|
|
_programLayers.enable(20);
|
|
if (parameters.alphaToCoverage)
|
|
_programLayers.enable(21);
|
|
if (parameters.numMultiviewViews)
|
|
_programLayers.enable(21);
|
|
array.push(_programLayers.mask);
|
|
}
|
|
function getUniforms(material) {
|
|
const shaderID = shaderIDs[material.type];
|
|
let uniforms;
|
|
if (shaderID) {
|
|
const shader = ShaderLib[shaderID];
|
|
uniforms = UniformsUtils.clone(shader.uniforms);
|
|
} else {
|
|
uniforms = material.uniforms;
|
|
}
|
|
return uniforms;
|
|
}
|
|
function acquireProgram(parameters, cacheKey) {
|
|
let program;
|
|
for (let p = 0, pl = programs.length;p < pl; p++) {
|
|
const preexistingProgram = programs[p];
|
|
if (preexistingProgram.cacheKey === cacheKey) {
|
|
program = preexistingProgram;
|
|
++program.usedTimes;
|
|
break;
|
|
}
|
|
}
|
|
if (program === undefined) {
|
|
program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
|
|
programs.push(program);
|
|
}
|
|
return program;
|
|
}
|
|
function releaseProgram(program) {
|
|
if (--program.usedTimes === 0) {
|
|
const i = programs.indexOf(program);
|
|
programs[i] = programs[programs.length - 1];
|
|
programs.pop();
|
|
program.destroy();
|
|
}
|
|
}
|
|
function releaseShaderCache(material) {
|
|
_customShaders.remove(material);
|
|
}
|
|
function dispose() {
|
|
_customShaders.dispose();
|
|
}
|
|
return {
|
|
getParameters,
|
|
getProgramCacheKey,
|
|
getUniforms,
|
|
acquireProgram,
|
|
releaseProgram,
|
|
releaseShaderCache,
|
|
programs,
|
|
dispose
|
|
};
|
|
}
|
|
function WebGLProperties() {
|
|
let properties = new WeakMap;
|
|
function has(object) {
|
|
return properties.has(object);
|
|
}
|
|
function get(object) {
|
|
let map = properties.get(object);
|
|
if (map === undefined) {
|
|
map = {};
|
|
properties.set(object, map);
|
|
}
|
|
return map;
|
|
}
|
|
function remove(object) {
|
|
properties.delete(object);
|
|
}
|
|
function update(object, key, value) {
|
|
properties.get(object)[key] = value;
|
|
}
|
|
function dispose() {
|
|
properties = new WeakMap;
|
|
}
|
|
return {
|
|
has,
|
|
get,
|
|
remove,
|
|
update,
|
|
dispose
|
|
};
|
|
}
|
|
function painterSortStable(a, b) {
|
|
if (a.groupOrder !== b.groupOrder) {
|
|
return a.groupOrder - b.groupOrder;
|
|
} else if (a.renderOrder !== b.renderOrder) {
|
|
return a.renderOrder - b.renderOrder;
|
|
} else if (a.material.id !== b.material.id) {
|
|
return a.material.id - b.material.id;
|
|
} else if (a.z !== b.z) {
|
|
return a.z - b.z;
|
|
} else {
|
|
return a.id - b.id;
|
|
}
|
|
}
|
|
function reversePainterSortStable(a, b) {
|
|
if (a.groupOrder !== b.groupOrder) {
|
|
return a.groupOrder - b.groupOrder;
|
|
} else if (a.renderOrder !== b.renderOrder) {
|
|
return a.renderOrder - b.renderOrder;
|
|
} else if (a.z !== b.z) {
|
|
return b.z - a.z;
|
|
} else {
|
|
return a.id - b.id;
|
|
}
|
|
}
|
|
function WebGLRenderList() {
|
|
const renderItems = [];
|
|
let renderItemsIndex = 0;
|
|
const opaque = [];
|
|
const transmissive = [];
|
|
const transparent = [];
|
|
function init() {
|
|
renderItemsIndex = 0;
|
|
opaque.length = 0;
|
|
transmissive.length = 0;
|
|
transparent.length = 0;
|
|
}
|
|
function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
|
|
let renderItem = renderItems[renderItemsIndex];
|
|
if (renderItem === undefined) {
|
|
renderItem = {
|
|
id: object.id,
|
|
object,
|
|
geometry,
|
|
material,
|
|
groupOrder,
|
|
renderOrder: object.renderOrder,
|
|
z,
|
|
group
|
|
};
|
|
renderItems[renderItemsIndex] = renderItem;
|
|
} else {
|
|
renderItem.id = object.id;
|
|
renderItem.object = object;
|
|
renderItem.geometry = geometry;
|
|
renderItem.material = material;
|
|
renderItem.groupOrder = groupOrder;
|
|
renderItem.renderOrder = object.renderOrder;
|
|
renderItem.z = z;
|
|
renderItem.group = group;
|
|
}
|
|
renderItemsIndex++;
|
|
return renderItem;
|
|
}
|
|
function push(object, geometry, material, groupOrder, z, group) {
|
|
const renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
|
|
if (material.transmission > 0) {
|
|
transmissive.push(renderItem);
|
|
} else if (material.transparent === true) {
|
|
transparent.push(renderItem);
|
|
} else {
|
|
opaque.push(renderItem);
|
|
}
|
|
}
|
|
function unshift(object, geometry, material, groupOrder, z, group) {
|
|
const renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
|
|
if (material.transmission > 0) {
|
|
transmissive.unshift(renderItem);
|
|
} else if (material.transparent === true) {
|
|
transparent.unshift(renderItem);
|
|
} else {
|
|
opaque.unshift(renderItem);
|
|
}
|
|
}
|
|
function sort(customOpaqueSort, customTransparentSort) {
|
|
if (opaque.length > 1)
|
|
opaque.sort(customOpaqueSort || painterSortStable);
|
|
if (transmissive.length > 1)
|
|
transmissive.sort(customTransparentSort || reversePainterSortStable);
|
|
if (transparent.length > 1)
|
|
transparent.sort(customTransparentSort || reversePainterSortStable);
|
|
}
|
|
function finish() {
|
|
for (let i = renderItemsIndex, il = renderItems.length;i < il; i++) {
|
|
const renderItem = renderItems[i];
|
|
if (renderItem.id === null)
|
|
break;
|
|
renderItem.id = null;
|
|
renderItem.object = null;
|
|
renderItem.geometry = null;
|
|
renderItem.material = null;
|
|
renderItem.group = null;
|
|
}
|
|
}
|
|
return {
|
|
opaque,
|
|
transmissive,
|
|
transparent,
|
|
init,
|
|
push,
|
|
unshift,
|
|
finish,
|
|
sort
|
|
};
|
|
}
|
|
function WebGLRenderLists() {
|
|
let lists = new WeakMap;
|
|
function get(scene, renderCallDepth) {
|
|
const listArray = lists.get(scene);
|
|
let list;
|
|
if (listArray === undefined) {
|
|
list = new WebGLRenderList;
|
|
lists.set(scene, [list]);
|
|
} else {
|
|
if (renderCallDepth >= listArray.length) {
|
|
list = new WebGLRenderList;
|
|
listArray.push(list);
|
|
} else {
|
|
list = listArray[renderCallDepth];
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
function dispose() {
|
|
lists = new WeakMap;
|
|
}
|
|
return {
|
|
get,
|
|
dispose
|
|
};
|
|
}
|
|
function UniformsCache() {
|
|
const lights = {};
|
|
return {
|
|
get: function(light) {
|
|
if (lights[light.id] !== undefined) {
|
|
return lights[light.id];
|
|
}
|
|
let uniforms;
|
|
switch (light.type) {
|
|
case "DirectionalLight":
|
|
uniforms = {
|
|
direction: new Vector3,
|
|
color: new Color
|
|
};
|
|
break;
|
|
case "SpotLight":
|
|
uniforms = {
|
|
position: new Vector3,
|
|
direction: new Vector3,
|
|
color: new Color,
|
|
distance: 0,
|
|
coneCos: 0,
|
|
penumbraCos: 0,
|
|
decay: 0
|
|
};
|
|
break;
|
|
case "PointLight":
|
|
uniforms = {
|
|
position: new Vector3,
|
|
color: new Color,
|
|
distance: 0,
|
|
decay: 0
|
|
};
|
|
break;
|
|
case "HemisphereLight":
|
|
uniforms = {
|
|
direction: new Vector3,
|
|
skyColor: new Color,
|
|
groundColor: new Color
|
|
};
|
|
break;
|
|
case "RectAreaLight":
|
|
uniforms = {
|
|
color: new Color,
|
|
position: new Vector3,
|
|
halfWidth: new Vector3,
|
|
halfHeight: new Vector3
|
|
};
|
|
break;
|
|
}
|
|
lights[light.id] = uniforms;
|
|
return uniforms;
|
|
}
|
|
};
|
|
}
|
|
function ShadowUniformsCache() {
|
|
const lights = {};
|
|
return {
|
|
get: function(light) {
|
|
if (lights[light.id] !== undefined) {
|
|
return lights[light.id];
|
|
}
|
|
let uniforms;
|
|
switch (light.type) {
|
|
case "DirectionalLight":
|
|
uniforms = {
|
|
shadowIntensity: 1,
|
|
shadowBias: 0,
|
|
shadowNormalBias: 0,
|
|
shadowRadius: 1,
|
|
shadowMapSize: new Vector2
|
|
};
|
|
break;
|
|
case "SpotLight":
|
|
uniforms = {
|
|
shadowIntensity: 1,
|
|
shadowBias: 0,
|
|
shadowNormalBias: 0,
|
|
shadowRadius: 1,
|
|
shadowMapSize: new Vector2
|
|
};
|
|
break;
|
|
case "PointLight":
|
|
uniforms = {
|
|
shadowIntensity: 1,
|
|
shadowBias: 0,
|
|
shadowNormalBias: 0,
|
|
shadowRadius: 1,
|
|
shadowMapSize: new Vector2,
|
|
shadowCameraNear: 1,
|
|
shadowCameraFar: 1000
|
|
};
|
|
break;
|
|
}
|
|
lights[light.id] = uniforms;
|
|
return uniforms;
|
|
}
|
|
};
|
|
}
|
|
function shadowCastingAndTexturingLightsFirst(lightA, lightB) {
|
|
return (lightB.castShadow ? 2 : 0) - (lightA.castShadow ? 2 : 0) + (lightB.map ? 1 : 0) - (lightA.map ? 1 : 0);
|
|
}
|
|
function WebGLLights(extensions) {
|
|
const cache = new UniformsCache;
|
|
const shadowCache = ShadowUniformsCache();
|
|
const state = {
|
|
version: 0,
|
|
hash: {
|
|
directionalLength: -1,
|
|
pointLength: -1,
|
|
spotLength: -1,
|
|
rectAreaLength: -1,
|
|
hemiLength: -1,
|
|
numDirectionalShadows: -1,
|
|
numPointShadows: -1,
|
|
numSpotShadows: -1,
|
|
numSpotMaps: -1,
|
|
numLightProbes: -1
|
|
},
|
|
ambient: [0, 0, 0],
|
|
probe: [],
|
|
directional: [],
|
|
directionalShadow: [],
|
|
directionalShadowMap: [],
|
|
directionalShadowMatrix: [],
|
|
spot: [],
|
|
spotLightMap: [],
|
|
spotShadow: [],
|
|
spotShadowMap: [],
|
|
spotLightMatrix: [],
|
|
rectArea: [],
|
|
rectAreaLTC1: null,
|
|
rectAreaLTC2: null,
|
|
point: [],
|
|
pointShadow: [],
|
|
pointShadowMap: [],
|
|
pointShadowMatrix: [],
|
|
hemi: [],
|
|
numSpotLightShadowsWithMaps: 0,
|
|
numLightProbes: 0
|
|
};
|
|
for (let i = 0;i < 9; i++)
|
|
state.probe.push(new Vector3);
|
|
const vector3 = new Vector3;
|
|
const matrix4 = new Matrix4;
|
|
const matrix42 = new Matrix4;
|
|
function setup(lights) {
|
|
let r = 0, g = 0, b = 0;
|
|
for (let i = 0;i < 9; i++)
|
|
state.probe[i].set(0, 0, 0);
|
|
let directionalLength = 0;
|
|
let pointLength = 0;
|
|
let spotLength = 0;
|
|
let rectAreaLength = 0;
|
|
let hemiLength = 0;
|
|
let numDirectionalShadows = 0;
|
|
let numPointShadows = 0;
|
|
let numSpotShadows = 0;
|
|
let numSpotMaps = 0;
|
|
let numSpotShadowsWithMaps = 0;
|
|
let numLightProbes = 0;
|
|
lights.sort(shadowCastingAndTexturingLightsFirst);
|
|
for (let i = 0, l = lights.length;i < l; i++) {
|
|
const light = lights[i];
|
|
const color = light.color;
|
|
const intensity = light.intensity;
|
|
const distance = light.distance;
|
|
const shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
|
|
if (light.isAmbientLight) {
|
|
r += color.r * intensity;
|
|
g += color.g * intensity;
|
|
b += color.b * intensity;
|
|
} else if (light.isLightProbe) {
|
|
for (let j = 0;j < 9; j++) {
|
|
state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
|
|
}
|
|
numLightProbes++;
|
|
} else if (light.isDirectionalLight) {
|
|
const uniforms = cache.get(light);
|
|
uniforms.color.copy(light.color).multiplyScalar(light.intensity);
|
|
if (light.castShadow) {
|
|
const shadow = light.shadow;
|
|
const shadowUniforms = shadowCache.get(light);
|
|
shadowUniforms.shadowIntensity = shadow.intensity;
|
|
shadowUniforms.shadowBias = shadow.bias;
|
|
shadowUniforms.shadowNormalBias = shadow.normalBias;
|
|
shadowUniforms.shadowRadius = shadow.radius;
|
|
shadowUniforms.shadowMapSize = shadow.mapSize;
|
|
state.directionalShadow[directionalLength] = shadowUniforms;
|
|
state.directionalShadowMap[directionalLength] = shadowMap;
|
|
state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
|
|
numDirectionalShadows++;
|
|
}
|
|
state.directional[directionalLength] = uniforms;
|
|
directionalLength++;
|
|
} else if (light.isSpotLight) {
|
|
const uniforms = cache.get(light);
|
|
uniforms.position.setFromMatrixPosition(light.matrixWorld);
|
|
uniforms.color.copy(color).multiplyScalar(intensity);
|
|
uniforms.distance = distance;
|
|
uniforms.coneCos = Math.cos(light.angle);
|
|
uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
|
|
uniforms.decay = light.decay;
|
|
state.spot[spotLength] = uniforms;
|
|
const shadow = light.shadow;
|
|
if (light.map) {
|
|
state.spotLightMap[numSpotMaps] = light.map;
|
|
numSpotMaps++;
|
|
shadow.updateMatrices(light);
|
|
if (light.castShadow)
|
|
numSpotShadowsWithMaps++;
|
|
}
|
|
state.spotLightMatrix[spotLength] = shadow.matrix;
|
|
if (light.castShadow) {
|
|
const shadowUniforms = shadowCache.get(light);
|
|
shadowUniforms.shadowIntensity = shadow.intensity;
|
|
shadowUniforms.shadowBias = shadow.bias;
|
|
shadowUniforms.shadowNormalBias = shadow.normalBias;
|
|
shadowUniforms.shadowRadius = shadow.radius;
|
|
shadowUniforms.shadowMapSize = shadow.mapSize;
|
|
state.spotShadow[spotLength] = shadowUniforms;
|
|
state.spotShadowMap[spotLength] = shadowMap;
|
|
numSpotShadows++;
|
|
}
|
|
spotLength++;
|
|
} else if (light.isRectAreaLight) {
|
|
const uniforms = cache.get(light);
|
|
uniforms.color.copy(color).multiplyScalar(intensity);
|
|
uniforms.halfWidth.set(light.width * 0.5, 0, 0);
|
|
uniforms.halfHeight.set(0, light.height * 0.5, 0);
|
|
state.rectArea[rectAreaLength] = uniforms;
|
|
rectAreaLength++;
|
|
} else if (light.isPointLight) {
|
|
const uniforms = cache.get(light);
|
|
uniforms.color.copy(light.color).multiplyScalar(light.intensity);
|
|
uniforms.distance = light.distance;
|
|
uniforms.decay = light.decay;
|
|
if (light.castShadow) {
|
|
const shadow = light.shadow;
|
|
const shadowUniforms = shadowCache.get(light);
|
|
shadowUniforms.shadowIntensity = shadow.intensity;
|
|
shadowUniforms.shadowBias = shadow.bias;
|
|
shadowUniforms.shadowNormalBias = shadow.normalBias;
|
|
shadowUniforms.shadowRadius = shadow.radius;
|
|
shadowUniforms.shadowMapSize = shadow.mapSize;
|
|
shadowUniforms.shadowCameraNear = shadow.camera.near;
|
|
shadowUniforms.shadowCameraFar = shadow.camera.far;
|
|
state.pointShadow[pointLength] = shadowUniforms;
|
|
state.pointShadowMap[pointLength] = shadowMap;
|
|
state.pointShadowMatrix[pointLength] = light.shadow.matrix;
|
|
numPointShadows++;
|
|
}
|
|
state.point[pointLength] = uniforms;
|
|
pointLength++;
|
|
} else if (light.isHemisphereLight) {
|
|
const uniforms = cache.get(light);
|
|
uniforms.skyColor.copy(light.color).multiplyScalar(intensity);
|
|
uniforms.groundColor.copy(light.groundColor).multiplyScalar(intensity);
|
|
state.hemi[hemiLength] = uniforms;
|
|
hemiLength++;
|
|
}
|
|
}
|
|
if (rectAreaLength > 0) {
|
|
if (extensions.has("OES_texture_float_linear") === true) {
|
|
state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
|
|
state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
|
|
} else {
|
|
state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
|
|
state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
|
|
}
|
|
}
|
|
state.ambient[0] = r;
|
|
state.ambient[1] = g;
|
|
state.ambient[2] = b;
|
|
const hash = state.hash;
|
|
if (hash.directionalLength !== directionalLength || hash.pointLength !== pointLength || hash.spotLength !== spotLength || hash.rectAreaLength !== rectAreaLength || hash.hemiLength !== hemiLength || hash.numDirectionalShadows !== numDirectionalShadows || hash.numPointShadows !== numPointShadows || hash.numSpotShadows !== numSpotShadows || hash.numSpotMaps !== numSpotMaps || hash.numLightProbes !== numLightProbes) {
|
|
state.directional.length = directionalLength;
|
|
state.spot.length = spotLength;
|
|
state.rectArea.length = rectAreaLength;
|
|
state.point.length = pointLength;
|
|
state.hemi.length = hemiLength;
|
|
state.directionalShadow.length = numDirectionalShadows;
|
|
state.directionalShadowMap.length = numDirectionalShadows;
|
|
state.pointShadow.length = numPointShadows;
|
|
state.pointShadowMap.length = numPointShadows;
|
|
state.spotShadow.length = numSpotShadows;
|
|
state.spotShadowMap.length = numSpotShadows;
|
|
state.directionalShadowMatrix.length = numDirectionalShadows;
|
|
state.pointShadowMatrix.length = numPointShadows;
|
|
state.spotLightMatrix.length = numSpotShadows + numSpotMaps - numSpotShadowsWithMaps;
|
|
state.spotLightMap.length = numSpotMaps;
|
|
state.numSpotLightShadowsWithMaps = numSpotShadowsWithMaps;
|
|
state.numLightProbes = numLightProbes;
|
|
hash.directionalLength = directionalLength;
|
|
hash.pointLength = pointLength;
|
|
hash.spotLength = spotLength;
|
|
hash.rectAreaLength = rectAreaLength;
|
|
hash.hemiLength = hemiLength;
|
|
hash.numDirectionalShadows = numDirectionalShadows;
|
|
hash.numPointShadows = numPointShadows;
|
|
hash.numSpotShadows = numSpotShadows;
|
|
hash.numSpotMaps = numSpotMaps;
|
|
hash.numLightProbes = numLightProbes;
|
|
state.version = nextVersion++;
|
|
}
|
|
}
|
|
function setupView(lights, camera) {
|
|
let directionalLength = 0;
|
|
let pointLength = 0;
|
|
let spotLength = 0;
|
|
let rectAreaLength = 0;
|
|
let hemiLength = 0;
|
|
const viewMatrix = camera.matrixWorldInverse;
|
|
for (let i = 0, l = lights.length;i < l; i++) {
|
|
const light = lights[i];
|
|
if (light.isDirectionalLight) {
|
|
const uniforms = state.directional[directionalLength];
|
|
uniforms.direction.setFromMatrixPosition(light.matrixWorld);
|
|
vector3.setFromMatrixPosition(light.target.matrixWorld);
|
|
uniforms.direction.sub(vector3);
|
|
uniforms.direction.transformDirection(viewMatrix);
|
|
directionalLength++;
|
|
} else if (light.isSpotLight) {
|
|
const uniforms = state.spot[spotLength];
|
|
uniforms.position.setFromMatrixPosition(light.matrixWorld);
|
|
uniforms.position.applyMatrix4(viewMatrix);
|
|
uniforms.direction.setFromMatrixPosition(light.matrixWorld);
|
|
vector3.setFromMatrixPosition(light.target.matrixWorld);
|
|
uniforms.direction.sub(vector3);
|
|
uniforms.direction.transformDirection(viewMatrix);
|
|
spotLength++;
|
|
} else if (light.isRectAreaLight) {
|
|
const uniforms = state.rectArea[rectAreaLength];
|
|
uniforms.position.setFromMatrixPosition(light.matrixWorld);
|
|
uniforms.position.applyMatrix4(viewMatrix);
|
|
matrix42.identity();
|
|
matrix4.copy(light.matrixWorld);
|
|
matrix4.premultiply(viewMatrix);
|
|
matrix42.extractRotation(matrix4);
|
|
uniforms.halfWidth.set(light.width * 0.5, 0, 0);
|
|
uniforms.halfHeight.set(0, light.height * 0.5, 0);
|
|
uniforms.halfWidth.applyMatrix4(matrix42);
|
|
uniforms.halfHeight.applyMatrix4(matrix42);
|
|
rectAreaLength++;
|
|
} else if (light.isPointLight) {
|
|
const uniforms = state.point[pointLength];
|
|
uniforms.position.setFromMatrixPosition(light.matrixWorld);
|
|
uniforms.position.applyMatrix4(viewMatrix);
|
|
pointLength++;
|
|
} else if (light.isHemisphereLight) {
|
|
const uniforms = state.hemi[hemiLength];
|
|
uniforms.direction.setFromMatrixPosition(light.matrixWorld);
|
|
uniforms.direction.transformDirection(viewMatrix);
|
|
hemiLength++;
|
|
}
|
|
}
|
|
}
|
|
return {
|
|
setup,
|
|
setupView,
|
|
state
|
|
};
|
|
}
|
|
function WebGLRenderState(extensions) {
|
|
const lights = new WebGLLights(extensions);
|
|
const lightsArray = [];
|
|
const shadowsArray = [];
|
|
function init(camera) {
|
|
state.camera = camera;
|
|
lightsArray.length = 0;
|
|
shadowsArray.length = 0;
|
|
}
|
|
function pushLight(light) {
|
|
lightsArray.push(light);
|
|
}
|
|
function pushShadow(shadowLight) {
|
|
shadowsArray.push(shadowLight);
|
|
}
|
|
function setupLights() {
|
|
lights.setup(lightsArray);
|
|
}
|
|
function setupLightsView(camera) {
|
|
lights.setupView(lightsArray, camera);
|
|
}
|
|
const state = {
|
|
lightsArray,
|
|
shadowsArray,
|
|
camera: null,
|
|
lights,
|
|
transmissionRenderTarget: {}
|
|
};
|
|
return {
|
|
init,
|
|
state,
|
|
setupLights,
|
|
setupLightsView,
|
|
pushLight,
|
|
pushShadow
|
|
};
|
|
}
|
|
function WebGLRenderStates(extensions) {
|
|
let renderStates = new WeakMap;
|
|
function get(scene, renderCallDepth = 0) {
|
|
const renderStateArray = renderStates.get(scene);
|
|
let renderState;
|
|
if (renderStateArray === undefined) {
|
|
renderState = new WebGLRenderState(extensions);
|
|
renderStates.set(scene, [renderState]);
|
|
} else {
|
|
if (renderCallDepth >= renderStateArray.length) {
|
|
renderState = new WebGLRenderState(extensions);
|
|
renderStateArray.push(renderState);
|
|
} else {
|
|
renderState = renderStateArray[renderCallDepth];
|
|
}
|
|
}
|
|
return renderState;
|
|
}
|
|
function dispose() {
|
|
renderStates = new WeakMap;
|
|
}
|
|
return {
|
|
get,
|
|
dispose
|
|
};
|
|
}
|
|
function WebGLShadowMap(renderer, objects, capabilities) {
|
|
let _frustum2 = new Frustum;
|
|
const _shadowMapSize = new Vector2, _viewportSize = new Vector2, _viewport = new Vector4, _depthMaterial = new MeshDepthMaterial({ depthPacking: RGBADepthPacking }), _distanceMaterial = new MeshDistanceMaterial, _materialCache = {}, _maxTextureSize = capabilities.maxTextureSize;
|
|
const shadowSide = { [FrontSide]: BackSide, [BackSide]: FrontSide, [DoubleSide]: DoubleSide };
|
|
const shadowMaterialVertical = new ShaderMaterial({
|
|
defines: {
|
|
VSM_SAMPLES: 8
|
|
},
|
|
uniforms: {
|
|
shadow_pass: { value: null },
|
|
resolution: { value: new Vector2 },
|
|
radius: { value: 4 }
|
|
},
|
|
vertexShader: vertex,
|
|
fragmentShader: fragment
|
|
});
|
|
const shadowMaterialHorizontal = shadowMaterialVertical.clone();
|
|
shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
|
|
const fullScreenTri = new BufferGeometry;
|
|
fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
|
|
const fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
|
|
const scope = this;
|
|
this.enabled = false;
|
|
this.autoUpdate = true;
|
|
this.needsUpdate = false;
|
|
this.type = PCFShadowMap;
|
|
let _previousType = this.type;
|
|
this.render = function(lights, scene, camera) {
|
|
if (scope.enabled === false)
|
|
return;
|
|
if (scope.autoUpdate === false && scope.needsUpdate === false)
|
|
return;
|
|
if (lights.length === 0)
|
|
return;
|
|
const currentRenderTarget = renderer.getRenderTarget();
|
|
const activeCubeFace = renderer.getActiveCubeFace();
|
|
const activeMipmapLevel = renderer.getActiveMipmapLevel();
|
|
const _state = renderer.state;
|
|
_state.setBlending(NoBlending);
|
|
_state.buffers.color.setClear(1, 1, 1, 1);
|
|
_state.buffers.depth.setTest(true);
|
|
_state.setScissorTest(false);
|
|
const toVSM = _previousType !== VSMShadowMap && this.type === VSMShadowMap;
|
|
const fromVSM = _previousType === VSMShadowMap && this.type !== VSMShadowMap;
|
|
for (let i = 0, il = lights.length;i < il; i++) {
|
|
const light = lights[i];
|
|
const shadow = light.shadow;
|
|
if (shadow === undefined) {
|
|
console.warn("THREE.WebGLShadowMap:", light, "has no shadow.");
|
|
continue;
|
|
}
|
|
if (shadow.autoUpdate === false && shadow.needsUpdate === false)
|
|
continue;
|
|
_shadowMapSize.copy(shadow.mapSize);
|
|
const shadowFrameExtents = shadow.getFrameExtents();
|
|
_shadowMapSize.multiply(shadowFrameExtents);
|
|
_viewportSize.copy(shadow.mapSize);
|
|
if (_shadowMapSize.x > _maxTextureSize || _shadowMapSize.y > _maxTextureSize) {
|
|
if (_shadowMapSize.x > _maxTextureSize) {
|
|
_viewportSize.x = Math.floor(_maxTextureSize / shadowFrameExtents.x);
|
|
_shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
|
|
shadow.mapSize.x = _viewportSize.x;
|
|
}
|
|
if (_shadowMapSize.y > _maxTextureSize) {
|
|
_viewportSize.y = Math.floor(_maxTextureSize / shadowFrameExtents.y);
|
|
_shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
|
|
shadow.mapSize.y = _viewportSize.y;
|
|
}
|
|
}
|
|
if (shadow.map === null || toVSM === true || fromVSM === true) {
|
|
const pars = this.type !== VSMShadowMap ? { minFilter: NearestFilter, magFilter: NearestFilter } : {};
|
|
if (shadow.map !== null) {
|
|
shadow.map.dispose();
|
|
}
|
|
shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
|
|
shadow.map.texture.name = light.name + ".shadowMap";
|
|
shadow.camera.updateProjectionMatrix();
|
|
}
|
|
renderer.setRenderTarget(shadow.map);
|
|
renderer.clear();
|
|
const viewportCount = shadow.getViewportCount();
|
|
for (let vp = 0;vp < viewportCount; vp++) {
|
|
const viewport = shadow.getViewport(vp);
|
|
_viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
|
|
_state.viewport(_viewport);
|
|
shadow.updateMatrices(light, vp);
|
|
_frustum2 = shadow.getFrustum();
|
|
renderObject(scene, camera, shadow.camera, light, this.type);
|
|
}
|
|
if (shadow.isPointLightShadow !== true && this.type === VSMShadowMap) {
|
|
VSMPass(shadow, camera);
|
|
}
|
|
shadow.needsUpdate = false;
|
|
}
|
|
_previousType = this.type;
|
|
scope.needsUpdate = false;
|
|
renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
|
|
};
|
|
function VSMPass(shadow, camera) {
|
|
const geometry = objects.update(fullScreenMesh);
|
|
if (shadowMaterialVertical.defines.VSM_SAMPLES !== shadow.blurSamples) {
|
|
shadowMaterialVertical.defines.VSM_SAMPLES = shadow.blurSamples;
|
|
shadowMaterialHorizontal.defines.VSM_SAMPLES = shadow.blurSamples;
|
|
shadowMaterialVertical.needsUpdate = true;
|
|
shadowMaterialHorizontal.needsUpdate = true;
|
|
}
|
|
if (shadow.mapPass === null) {
|
|
shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y);
|
|
}
|
|
shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
|
|
shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
|
|
shadowMaterialVertical.uniforms.radius.value = shadow.radius;
|
|
renderer.setRenderTarget(shadow.mapPass);
|
|
renderer.clear();
|
|
renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null);
|
|
shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
|
|
shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
|
|
shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
|
|
renderer.setRenderTarget(shadow.map);
|
|
renderer.clear();
|
|
renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
|
|
}
|
|
function getDepthMaterial(object, material, light, type) {
|
|
let result = null;
|
|
const customMaterial = light.isPointLight === true ? object.customDistanceMaterial : object.customDepthMaterial;
|
|
if (customMaterial !== undefined) {
|
|
result = customMaterial;
|
|
} else {
|
|
result = light.isPointLight === true ? _distanceMaterial : _depthMaterial;
|
|
if (renderer.localClippingEnabled && material.clipShadows === true && Array.isArray(material.clippingPlanes) && material.clippingPlanes.length !== 0 || material.displacementMap && material.displacementScale !== 0 || material.alphaMap && material.alphaTest > 0 || material.map && material.alphaTest > 0) {
|
|
const keyA = result.uuid, keyB = material.uuid;
|
|
let materialsForVariant = _materialCache[keyA];
|
|
if (materialsForVariant === undefined) {
|
|
materialsForVariant = {};
|
|
_materialCache[keyA] = materialsForVariant;
|
|
}
|
|
let cachedMaterial = materialsForVariant[keyB];
|
|
if (cachedMaterial === undefined) {
|
|
cachedMaterial = result.clone();
|
|
materialsForVariant[keyB] = cachedMaterial;
|
|
material.addEventListener("dispose", onMaterialDispose);
|
|
}
|
|
result = cachedMaterial;
|
|
}
|
|
}
|
|
result.visible = material.visible;
|
|
result.wireframe = material.wireframe;
|
|
if (type === VSMShadowMap) {
|
|
result.side = material.shadowSide !== null ? material.shadowSide : material.side;
|
|
} else {
|
|
result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
|
|
}
|
|
result.alphaMap = material.alphaMap;
|
|
result.alphaTest = material.alphaTest;
|
|
result.map = material.map;
|
|
result.clipShadows = material.clipShadows;
|
|
result.clippingPlanes = material.clippingPlanes;
|
|
result.clipIntersection = material.clipIntersection;
|
|
result.displacementMap = material.displacementMap;
|
|
result.displacementScale = material.displacementScale;
|
|
result.displacementBias = material.displacementBias;
|
|
result.wireframeLinewidth = material.wireframeLinewidth;
|
|
result.linewidth = material.linewidth;
|
|
if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
|
|
const materialProperties = renderer.properties.get(result);
|
|
materialProperties.light = light;
|
|
}
|
|
return result;
|
|
}
|
|
function renderObject(object, camera, shadowCamera, light, type) {
|
|
if (object.visible === false)
|
|
return;
|
|
const visible = object.layers.test(camera.layers);
|
|
if (visible && (object.isMesh || object.isLine || object.isPoints)) {
|
|
if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum2.intersectsObject(object))) {
|
|
object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
|
|
const geometry = objects.update(object);
|
|
const material = object.material;
|
|
if (Array.isArray(material)) {
|
|
const groups = geometry.groups;
|
|
for (let k = 0, kl = groups.length;k < kl; k++) {
|
|
const group = groups[k];
|
|
const groupMaterial = material[group.materialIndex];
|
|
if (groupMaterial && groupMaterial.visible) {
|
|
const depthMaterial = getDepthMaterial(object, groupMaterial, light, type);
|
|
object.onBeforeShadow(renderer, object, camera, shadowCamera, geometry, depthMaterial, group);
|
|
renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
|
|
object.onAfterShadow(renderer, object, camera, shadowCamera, geometry, depthMaterial, group);
|
|
}
|
|
}
|
|
} else if (material.visible) {
|
|
const depthMaterial = getDepthMaterial(object, material, light, type);
|
|
object.onBeforeShadow(renderer, object, camera, shadowCamera, geometry, depthMaterial, null);
|
|
renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, null);
|
|
object.onAfterShadow(renderer, object, camera, shadowCamera, geometry, depthMaterial, null);
|
|
}
|
|
}
|
|
}
|
|
const children = object.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
renderObject(children[i], camera, shadowCamera, light, type);
|
|
}
|
|
}
|
|
function onMaterialDispose(event) {
|
|
const material = event.target;
|
|
material.removeEventListener("dispose", onMaterialDispose);
|
|
for (const id in _materialCache) {
|
|
const cache = _materialCache[id];
|
|
const uuid = event.target.uuid;
|
|
if (uuid in cache) {
|
|
const shadowMaterial = cache[uuid];
|
|
shadowMaterial.dispose();
|
|
delete cache[uuid];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function WebGLState(gl, extensions) {
|
|
function ColorBuffer() {
|
|
let locked = false;
|
|
const color = new Vector4;
|
|
let currentColorMask = null;
|
|
const currentColorClear = new Vector4(0, 0, 0, 0);
|
|
return {
|
|
setMask: function(colorMask) {
|
|
if (currentColorMask !== colorMask && !locked) {
|
|
gl.colorMask(colorMask, colorMask, colorMask, colorMask);
|
|
currentColorMask = colorMask;
|
|
}
|
|
},
|
|
setLocked: function(lock) {
|
|
locked = lock;
|
|
},
|
|
setClear: function(r, g, b, a, premultipliedAlpha) {
|
|
if (premultipliedAlpha === true) {
|
|
r *= a;
|
|
g *= a;
|
|
b *= a;
|
|
}
|
|
color.set(r, g, b, a);
|
|
if (currentColorClear.equals(color) === false) {
|
|
gl.clearColor(r, g, b, a);
|
|
currentColorClear.copy(color);
|
|
}
|
|
},
|
|
reset: function() {
|
|
locked = false;
|
|
currentColorMask = null;
|
|
currentColorClear.set(-1, 0, 0, 0);
|
|
}
|
|
};
|
|
}
|
|
function DepthBuffer() {
|
|
let locked = false;
|
|
let reversed = false;
|
|
let currentDepthMask = null;
|
|
let currentDepthFunc = null;
|
|
let currentDepthClear = null;
|
|
return {
|
|
setReversed: function(value) {
|
|
if (reversed !== value) {
|
|
const ext = extensions.get("EXT_clip_control");
|
|
if (reversed) {
|
|
ext.clipControlEXT(ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT);
|
|
} else {
|
|
ext.clipControlEXT(ext.LOWER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT);
|
|
}
|
|
const oldDepth = currentDepthClear;
|
|
currentDepthClear = null;
|
|
this.setClear(oldDepth);
|
|
}
|
|
reversed = value;
|
|
},
|
|
getReversed: function() {
|
|
return reversed;
|
|
},
|
|
setTest: function(depthTest) {
|
|
if (depthTest) {
|
|
enable(gl.DEPTH_TEST);
|
|
} else {
|
|
disable(gl.DEPTH_TEST);
|
|
}
|
|
},
|
|
setMask: function(depthMask) {
|
|
if (currentDepthMask !== depthMask && !locked) {
|
|
gl.depthMask(depthMask);
|
|
currentDepthMask = depthMask;
|
|
}
|
|
},
|
|
setFunc: function(depthFunc) {
|
|
if (reversed)
|
|
depthFunc = reversedFuncs[depthFunc];
|
|
if (currentDepthFunc !== depthFunc) {
|
|
switch (depthFunc) {
|
|
case NeverDepth:
|
|
gl.depthFunc(gl.NEVER);
|
|
break;
|
|
case AlwaysDepth:
|
|
gl.depthFunc(gl.ALWAYS);
|
|
break;
|
|
case LessDepth:
|
|
gl.depthFunc(gl.LESS);
|
|
break;
|
|
case LessEqualDepth:
|
|
gl.depthFunc(gl.LEQUAL);
|
|
break;
|
|
case EqualDepth:
|
|
gl.depthFunc(gl.EQUAL);
|
|
break;
|
|
case GreaterEqualDepth:
|
|
gl.depthFunc(gl.GEQUAL);
|
|
break;
|
|
case GreaterDepth:
|
|
gl.depthFunc(gl.GREATER);
|
|
break;
|
|
case NotEqualDepth:
|
|
gl.depthFunc(gl.NOTEQUAL);
|
|
break;
|
|
default:
|
|
gl.depthFunc(gl.LEQUAL);
|
|
}
|
|
currentDepthFunc = depthFunc;
|
|
}
|
|
},
|
|
setLocked: function(lock) {
|
|
locked = lock;
|
|
},
|
|
setClear: function(depth) {
|
|
if (currentDepthClear !== depth) {
|
|
if (reversed) {
|
|
depth = 1 - depth;
|
|
}
|
|
gl.clearDepth(depth);
|
|
currentDepthClear = depth;
|
|
}
|
|
},
|
|
reset: function() {
|
|
locked = false;
|
|
currentDepthMask = null;
|
|
currentDepthFunc = null;
|
|
currentDepthClear = null;
|
|
reversed = false;
|
|
}
|
|
};
|
|
}
|
|
function StencilBuffer() {
|
|
let locked = false;
|
|
let currentStencilMask = null;
|
|
let currentStencilFunc = null;
|
|
let currentStencilRef = null;
|
|
let currentStencilFuncMask = null;
|
|
let currentStencilFail = null;
|
|
let currentStencilZFail = null;
|
|
let currentStencilZPass = null;
|
|
let currentStencilClear = null;
|
|
return {
|
|
setTest: function(stencilTest) {
|
|
if (!locked) {
|
|
if (stencilTest) {
|
|
enable(gl.STENCIL_TEST);
|
|
} else {
|
|
disable(gl.STENCIL_TEST);
|
|
}
|
|
}
|
|
},
|
|
setMask: function(stencilMask) {
|
|
if (currentStencilMask !== stencilMask && !locked) {
|
|
gl.stencilMask(stencilMask);
|
|
currentStencilMask = stencilMask;
|
|
}
|
|
},
|
|
setFunc: function(stencilFunc, stencilRef, stencilMask) {
|
|
if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
|
|
gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
|
|
currentStencilFunc = stencilFunc;
|
|
currentStencilRef = stencilRef;
|
|
currentStencilFuncMask = stencilMask;
|
|
}
|
|
},
|
|
setOp: function(stencilFail, stencilZFail, stencilZPass) {
|
|
if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
|
|
gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
|
|
currentStencilFail = stencilFail;
|
|
currentStencilZFail = stencilZFail;
|
|
currentStencilZPass = stencilZPass;
|
|
}
|
|
},
|
|
setLocked: function(lock) {
|
|
locked = lock;
|
|
},
|
|
setClear: function(stencil) {
|
|
if (currentStencilClear !== stencil) {
|
|
gl.clearStencil(stencil);
|
|
currentStencilClear = stencil;
|
|
}
|
|
},
|
|
reset: function() {
|
|
locked = false;
|
|
currentStencilMask = null;
|
|
currentStencilFunc = null;
|
|
currentStencilRef = null;
|
|
currentStencilFuncMask = null;
|
|
currentStencilFail = null;
|
|
currentStencilZFail = null;
|
|
currentStencilZPass = null;
|
|
currentStencilClear = null;
|
|
}
|
|
};
|
|
}
|
|
const colorBuffer = new ColorBuffer;
|
|
const depthBuffer = new DepthBuffer;
|
|
const stencilBuffer = new StencilBuffer;
|
|
const uboBindings = new WeakMap;
|
|
const uboProgramMap = new WeakMap;
|
|
let enabledCapabilities = {};
|
|
let currentBoundFramebuffers = {};
|
|
let currentDrawbuffers = new WeakMap;
|
|
let defaultDrawbuffers = [];
|
|
let currentProgram = null;
|
|
let currentBlendingEnabled = false;
|
|
let currentBlending = null;
|
|
let currentBlendEquation = null;
|
|
let currentBlendSrc = null;
|
|
let currentBlendDst = null;
|
|
let currentBlendEquationAlpha = null;
|
|
let currentBlendSrcAlpha = null;
|
|
let currentBlendDstAlpha = null;
|
|
let currentBlendColor = new Color(0, 0, 0);
|
|
let currentBlendAlpha = 0;
|
|
let currentPremultipledAlpha = false;
|
|
let currentFlipSided = null;
|
|
let currentCullFace = null;
|
|
let currentLineWidth = null;
|
|
let currentPolygonOffsetFactor = null;
|
|
let currentPolygonOffsetUnits = null;
|
|
const maxTextures = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
|
|
let lineWidthAvailable = false;
|
|
let version = 0;
|
|
const glVersion = gl.getParameter(gl.VERSION);
|
|
if (glVersion.indexOf("WebGL") !== -1) {
|
|
version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
|
|
lineWidthAvailable = version >= 1;
|
|
} else if (glVersion.indexOf("OpenGL ES") !== -1) {
|
|
version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
|
|
lineWidthAvailable = version >= 2;
|
|
}
|
|
let currentTextureSlot = null;
|
|
let currentBoundTextures = {};
|
|
const scissorParam = gl.getParameter(gl.SCISSOR_BOX);
|
|
const viewportParam = gl.getParameter(gl.VIEWPORT);
|
|
const currentScissor = new Vector4().fromArray(scissorParam);
|
|
const currentViewport = new Vector4().fromArray(viewportParam);
|
|
function createTexture(type, target, count, dimensions) {
|
|
const data = new Uint8Array(4);
|
|
const texture = gl.createTexture();
|
|
gl.bindTexture(type, texture);
|
|
gl.texParameteri(type, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
gl.texParameteri(type, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
for (let i = 0;i < count; i++) {
|
|
if (type === gl.TEXTURE_3D || type === gl.TEXTURE_2D_ARRAY) {
|
|
gl.texImage3D(target, 0, gl.RGBA, 1, 1, dimensions, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
} else {
|
|
gl.texImage2D(target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
}
|
|
}
|
|
return texture;
|
|
}
|
|
const emptyTextures = {};
|
|
emptyTextures[gl.TEXTURE_2D] = createTexture(gl.TEXTURE_2D, gl.TEXTURE_2D, 1);
|
|
emptyTextures[gl.TEXTURE_CUBE_MAP] = createTexture(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6);
|
|
emptyTextures[gl.TEXTURE_2D_ARRAY] = createTexture(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_2D_ARRAY, 1, 1);
|
|
emptyTextures[gl.TEXTURE_3D] = createTexture(gl.TEXTURE_3D, gl.TEXTURE_3D, 1, 1);
|
|
colorBuffer.setClear(0, 0, 0, 1);
|
|
depthBuffer.setClear(1);
|
|
stencilBuffer.setClear(0);
|
|
enable(gl.DEPTH_TEST);
|
|
depthBuffer.setFunc(LessEqualDepth);
|
|
setFlipSided(false);
|
|
setCullFace(CullFaceBack);
|
|
enable(gl.CULL_FACE);
|
|
setBlending(NoBlending);
|
|
function enable(id) {
|
|
if (enabledCapabilities[id] !== true) {
|
|
gl.enable(id);
|
|
enabledCapabilities[id] = true;
|
|
}
|
|
}
|
|
function disable(id) {
|
|
if (enabledCapabilities[id] !== false) {
|
|
gl.disable(id);
|
|
enabledCapabilities[id] = false;
|
|
}
|
|
}
|
|
function bindFramebuffer(target, framebuffer) {
|
|
if (currentBoundFramebuffers[target] !== framebuffer) {
|
|
gl.bindFramebuffer(target, framebuffer);
|
|
currentBoundFramebuffers[target] = framebuffer;
|
|
if (target === gl.DRAW_FRAMEBUFFER) {
|
|
currentBoundFramebuffers[gl.FRAMEBUFFER] = framebuffer;
|
|
}
|
|
if (target === gl.FRAMEBUFFER) {
|
|
currentBoundFramebuffers[gl.DRAW_FRAMEBUFFER] = framebuffer;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
function drawBuffers(renderTarget, framebuffer) {
|
|
let drawBuffers2 = defaultDrawbuffers;
|
|
let needsUpdate = false;
|
|
if (renderTarget) {
|
|
drawBuffers2 = currentDrawbuffers.get(framebuffer);
|
|
if (drawBuffers2 === undefined) {
|
|
drawBuffers2 = [];
|
|
currentDrawbuffers.set(framebuffer, drawBuffers2);
|
|
}
|
|
const textures = renderTarget.textures;
|
|
if (drawBuffers2.length !== textures.length || drawBuffers2[0] !== gl.COLOR_ATTACHMENT0) {
|
|
for (let i = 0, il = textures.length;i < il; i++) {
|
|
drawBuffers2[i] = gl.COLOR_ATTACHMENT0 + i;
|
|
}
|
|
drawBuffers2.length = textures.length;
|
|
needsUpdate = true;
|
|
}
|
|
} else {
|
|
if (drawBuffers2[0] !== gl.BACK) {
|
|
drawBuffers2[0] = gl.BACK;
|
|
needsUpdate = true;
|
|
}
|
|
}
|
|
if (needsUpdate) {
|
|
gl.drawBuffers(drawBuffers2);
|
|
}
|
|
}
|
|
function useProgram(program) {
|
|
if (currentProgram !== program) {
|
|
gl.useProgram(program);
|
|
currentProgram = program;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
const equationToGL = {
|
|
[AddEquation]: gl.FUNC_ADD,
|
|
[SubtractEquation]: gl.FUNC_SUBTRACT,
|
|
[ReverseSubtractEquation]: gl.FUNC_REVERSE_SUBTRACT
|
|
};
|
|
equationToGL[MinEquation] = gl.MIN;
|
|
equationToGL[MaxEquation] = gl.MAX;
|
|
const factorToGL = {
|
|
[ZeroFactor]: gl.ZERO,
|
|
[OneFactor]: gl.ONE,
|
|
[SrcColorFactor]: gl.SRC_COLOR,
|
|
[SrcAlphaFactor]: gl.SRC_ALPHA,
|
|
[SrcAlphaSaturateFactor]: gl.SRC_ALPHA_SATURATE,
|
|
[DstColorFactor]: gl.DST_COLOR,
|
|
[DstAlphaFactor]: gl.DST_ALPHA,
|
|
[OneMinusSrcColorFactor]: gl.ONE_MINUS_SRC_COLOR,
|
|
[OneMinusSrcAlphaFactor]: gl.ONE_MINUS_SRC_ALPHA,
|
|
[OneMinusDstColorFactor]: gl.ONE_MINUS_DST_COLOR,
|
|
[OneMinusDstAlphaFactor]: gl.ONE_MINUS_DST_ALPHA,
|
|
[ConstantColorFactor]: gl.CONSTANT_COLOR,
|
|
[OneMinusConstantColorFactor]: gl.ONE_MINUS_CONSTANT_COLOR,
|
|
[ConstantAlphaFactor]: gl.CONSTANT_ALPHA,
|
|
[OneMinusConstantAlphaFactor]: gl.ONE_MINUS_CONSTANT_ALPHA
|
|
};
|
|
function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, blendColor, blendAlpha, premultipliedAlpha) {
|
|
if (blending === NoBlending) {
|
|
if (currentBlendingEnabled === true) {
|
|
disable(gl.BLEND);
|
|
currentBlendingEnabled = false;
|
|
}
|
|
return;
|
|
}
|
|
if (currentBlendingEnabled === false) {
|
|
enable(gl.BLEND);
|
|
currentBlendingEnabled = true;
|
|
}
|
|
if (blending !== CustomBlending) {
|
|
if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
|
|
if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
|
|
gl.blendEquation(gl.FUNC_ADD);
|
|
currentBlendEquation = AddEquation;
|
|
currentBlendEquationAlpha = AddEquation;
|
|
}
|
|
if (premultipliedAlpha) {
|
|
switch (blending) {
|
|
case NormalBlending:
|
|
gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
break;
|
|
case AdditiveBlending:
|
|
gl.blendFunc(gl.ONE, gl.ONE);
|
|
break;
|
|
case SubtractiveBlending:
|
|
gl.blendFuncSeparate(gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE);
|
|
break;
|
|
case MultiplyBlending:
|
|
gl.blendFuncSeparate(gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA);
|
|
break;
|
|
default:
|
|
console.error("THREE.WebGLState: Invalid blending: ", blending);
|
|
break;
|
|
}
|
|
} else {
|
|
switch (blending) {
|
|
case NormalBlending:
|
|
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
break;
|
|
case AdditiveBlending:
|
|
gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
|
|
break;
|
|
case SubtractiveBlending:
|
|
gl.blendFuncSeparate(gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE);
|
|
break;
|
|
case MultiplyBlending:
|
|
gl.blendFunc(gl.ZERO, gl.SRC_COLOR);
|
|
break;
|
|
default:
|
|
console.error("THREE.WebGLState: Invalid blending: ", blending);
|
|
break;
|
|
}
|
|
}
|
|
currentBlendSrc = null;
|
|
currentBlendDst = null;
|
|
currentBlendSrcAlpha = null;
|
|
currentBlendDstAlpha = null;
|
|
currentBlendColor.set(0, 0, 0);
|
|
currentBlendAlpha = 0;
|
|
currentBlending = blending;
|
|
currentPremultipledAlpha = premultipliedAlpha;
|
|
}
|
|
return;
|
|
}
|
|
blendEquationAlpha = blendEquationAlpha || blendEquation;
|
|
blendSrcAlpha = blendSrcAlpha || blendSrc;
|
|
blendDstAlpha = blendDstAlpha || blendDst;
|
|
if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
|
|
gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
|
|
currentBlendEquation = blendEquation;
|
|
currentBlendEquationAlpha = blendEquationAlpha;
|
|
}
|
|
if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
|
|
gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
|
|
currentBlendSrc = blendSrc;
|
|
currentBlendDst = blendDst;
|
|
currentBlendSrcAlpha = blendSrcAlpha;
|
|
currentBlendDstAlpha = blendDstAlpha;
|
|
}
|
|
if (blendColor.equals(currentBlendColor) === false || blendAlpha !== currentBlendAlpha) {
|
|
gl.blendColor(blendColor.r, blendColor.g, blendColor.b, blendAlpha);
|
|
currentBlendColor.copy(blendColor);
|
|
currentBlendAlpha = blendAlpha;
|
|
}
|
|
currentBlending = blending;
|
|
currentPremultipledAlpha = false;
|
|
}
|
|
function setMaterial(material, frontFaceCW) {
|
|
material.side === DoubleSide ? disable(gl.CULL_FACE) : enable(gl.CULL_FACE);
|
|
let flipSided = material.side === BackSide;
|
|
if (frontFaceCW)
|
|
flipSided = !flipSided;
|
|
setFlipSided(flipSided);
|
|
material.blending === NormalBlending && material.transparent === false ? setBlending(NoBlending) : setBlending(material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.blendColor, material.blendAlpha, material.premultipliedAlpha);
|
|
depthBuffer.setFunc(material.depthFunc);
|
|
depthBuffer.setTest(material.depthTest);
|
|
depthBuffer.setMask(material.depthWrite);
|
|
colorBuffer.setMask(material.colorWrite);
|
|
const stencilWrite = material.stencilWrite;
|
|
stencilBuffer.setTest(stencilWrite);
|
|
if (stencilWrite) {
|
|
stencilBuffer.setMask(material.stencilWriteMask);
|
|
stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
|
|
stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
|
|
}
|
|
setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
|
|
material.alphaToCoverage === true ? enable(gl.SAMPLE_ALPHA_TO_COVERAGE) : disable(gl.SAMPLE_ALPHA_TO_COVERAGE);
|
|
}
|
|
function setFlipSided(flipSided) {
|
|
if (currentFlipSided !== flipSided) {
|
|
if (flipSided) {
|
|
gl.frontFace(gl.CW);
|
|
} else {
|
|
gl.frontFace(gl.CCW);
|
|
}
|
|
currentFlipSided = flipSided;
|
|
}
|
|
}
|
|
function setCullFace(cullFace) {
|
|
if (cullFace !== CullFaceNone) {
|
|
enable(gl.CULL_FACE);
|
|
if (cullFace !== currentCullFace) {
|
|
if (cullFace === CullFaceBack) {
|
|
gl.cullFace(gl.BACK);
|
|
} else if (cullFace === CullFaceFront) {
|
|
gl.cullFace(gl.FRONT);
|
|
} else {
|
|
gl.cullFace(gl.FRONT_AND_BACK);
|
|
}
|
|
}
|
|
} else {
|
|
disable(gl.CULL_FACE);
|
|
}
|
|
currentCullFace = cullFace;
|
|
}
|
|
function setLineWidth(width) {
|
|
if (width !== currentLineWidth) {
|
|
if (lineWidthAvailable)
|
|
gl.lineWidth(width);
|
|
currentLineWidth = width;
|
|
}
|
|
}
|
|
function setPolygonOffset(polygonOffset, factor, units) {
|
|
if (polygonOffset) {
|
|
enable(gl.POLYGON_OFFSET_FILL);
|
|
if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
|
|
gl.polygonOffset(factor, units);
|
|
currentPolygonOffsetFactor = factor;
|
|
currentPolygonOffsetUnits = units;
|
|
}
|
|
} else {
|
|
disable(gl.POLYGON_OFFSET_FILL);
|
|
}
|
|
}
|
|
function setScissorTest(scissorTest) {
|
|
if (scissorTest) {
|
|
enable(gl.SCISSOR_TEST);
|
|
} else {
|
|
disable(gl.SCISSOR_TEST);
|
|
}
|
|
}
|
|
function activeTexture(webglSlot) {
|
|
if (webglSlot === undefined)
|
|
webglSlot = gl.TEXTURE0 + maxTextures - 1;
|
|
if (currentTextureSlot !== webglSlot) {
|
|
gl.activeTexture(webglSlot);
|
|
currentTextureSlot = webglSlot;
|
|
}
|
|
}
|
|
function bindTexture(webglType, webglTexture, webglSlot) {
|
|
if (webglSlot === undefined) {
|
|
if (currentTextureSlot === null) {
|
|
webglSlot = gl.TEXTURE0 + maxTextures - 1;
|
|
} else {
|
|
webglSlot = currentTextureSlot;
|
|
}
|
|
}
|
|
let boundTexture = currentBoundTextures[webglSlot];
|
|
if (boundTexture === undefined) {
|
|
boundTexture = { type: undefined, texture: undefined };
|
|
currentBoundTextures[webglSlot] = boundTexture;
|
|
}
|
|
if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
|
|
if (currentTextureSlot !== webglSlot) {
|
|
gl.activeTexture(webglSlot);
|
|
currentTextureSlot = webglSlot;
|
|
}
|
|
gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
|
|
boundTexture.type = webglType;
|
|
boundTexture.texture = webglTexture;
|
|
}
|
|
}
|
|
function unbindTexture() {
|
|
const boundTexture = currentBoundTextures[currentTextureSlot];
|
|
if (boundTexture !== undefined && boundTexture.type !== undefined) {
|
|
gl.bindTexture(boundTexture.type, null);
|
|
boundTexture.type = undefined;
|
|
boundTexture.texture = undefined;
|
|
}
|
|
}
|
|
function compressedTexImage2D() {
|
|
try {
|
|
gl.compressedTexImage2D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function compressedTexImage3D() {
|
|
try {
|
|
gl.compressedTexImage3D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function texSubImage2D() {
|
|
try {
|
|
gl.texSubImage2D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function texSubImage3D() {
|
|
try {
|
|
gl.texSubImage3D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function compressedTexSubImage2D() {
|
|
try {
|
|
gl.compressedTexSubImage2D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function compressedTexSubImage3D() {
|
|
try {
|
|
gl.compressedTexSubImage3D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function texStorage2D() {
|
|
try {
|
|
gl.texStorage2D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function texStorage3D() {
|
|
try {
|
|
gl.texStorage3D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function texImage2D() {
|
|
try {
|
|
gl.texImage2D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function texImage3D() {
|
|
try {
|
|
gl.texImage3D.apply(gl, arguments);
|
|
} catch (error) {
|
|
console.error("THREE.WebGLState:", error);
|
|
}
|
|
}
|
|
function scissor(scissor2) {
|
|
if (currentScissor.equals(scissor2) === false) {
|
|
gl.scissor(scissor2.x, scissor2.y, scissor2.z, scissor2.w);
|
|
currentScissor.copy(scissor2);
|
|
}
|
|
}
|
|
function viewport(viewport2) {
|
|
if (currentViewport.equals(viewport2) === false) {
|
|
gl.viewport(viewport2.x, viewport2.y, viewport2.z, viewport2.w);
|
|
currentViewport.copy(viewport2);
|
|
}
|
|
}
|
|
function updateUBOMapping(uniformsGroup, program) {
|
|
let mapping = uboProgramMap.get(program);
|
|
if (mapping === undefined) {
|
|
mapping = new WeakMap;
|
|
uboProgramMap.set(program, mapping);
|
|
}
|
|
let blockIndex = mapping.get(uniformsGroup);
|
|
if (blockIndex === undefined) {
|
|
blockIndex = gl.getUniformBlockIndex(program, uniformsGroup.name);
|
|
mapping.set(uniformsGroup, blockIndex);
|
|
}
|
|
}
|
|
function uniformBlockBinding(uniformsGroup, program) {
|
|
const mapping = uboProgramMap.get(program);
|
|
const blockIndex = mapping.get(uniformsGroup);
|
|
if (uboBindings.get(program) !== blockIndex) {
|
|
gl.uniformBlockBinding(program, blockIndex, uniformsGroup.__bindingPointIndex);
|
|
uboBindings.set(program, blockIndex);
|
|
}
|
|
}
|
|
function reset() {
|
|
gl.disable(gl.BLEND);
|
|
gl.disable(gl.CULL_FACE);
|
|
gl.disable(gl.DEPTH_TEST);
|
|
gl.disable(gl.POLYGON_OFFSET_FILL);
|
|
gl.disable(gl.SCISSOR_TEST);
|
|
gl.disable(gl.STENCIL_TEST);
|
|
gl.disable(gl.SAMPLE_ALPHA_TO_COVERAGE);
|
|
gl.blendEquation(gl.FUNC_ADD);
|
|
gl.blendFunc(gl.ONE, gl.ZERO);
|
|
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
|
gl.blendColor(0, 0, 0, 0);
|
|
gl.colorMask(true, true, true, true);
|
|
gl.clearColor(0, 0, 0, 0);
|
|
gl.depthMask(true);
|
|
gl.depthFunc(gl.LESS);
|
|
depthBuffer.setReversed(false);
|
|
gl.clearDepth(1);
|
|
gl.stencilMask(4294967295);
|
|
gl.stencilFunc(gl.ALWAYS, 0, 4294967295);
|
|
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
|
gl.clearStencil(0);
|
|
gl.cullFace(gl.BACK);
|
|
gl.frontFace(gl.CCW);
|
|
gl.polygonOffset(0, 0);
|
|
gl.activeTexture(gl.TEXTURE0);
|
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
|
|
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
|
|
gl.useProgram(null);
|
|
gl.lineWidth(1);
|
|
gl.scissor(0, 0, gl.canvas.width, gl.canvas.height);
|
|
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
|
|
enabledCapabilities = {};
|
|
currentTextureSlot = null;
|
|
currentBoundTextures = {};
|
|
currentBoundFramebuffers = {};
|
|
currentDrawbuffers = new WeakMap;
|
|
defaultDrawbuffers = [];
|
|
currentProgram = null;
|
|
currentBlendingEnabled = false;
|
|
currentBlending = null;
|
|
currentBlendEquation = null;
|
|
currentBlendSrc = null;
|
|
currentBlendDst = null;
|
|
currentBlendEquationAlpha = null;
|
|
currentBlendSrcAlpha = null;
|
|
currentBlendDstAlpha = null;
|
|
currentBlendColor = new Color(0, 0, 0);
|
|
currentBlendAlpha = 0;
|
|
currentPremultipledAlpha = false;
|
|
currentFlipSided = null;
|
|
currentCullFace = null;
|
|
currentLineWidth = null;
|
|
currentPolygonOffsetFactor = null;
|
|
currentPolygonOffsetUnits = null;
|
|
currentScissor.set(0, 0, gl.canvas.width, gl.canvas.height);
|
|
currentViewport.set(0, 0, gl.canvas.width, gl.canvas.height);
|
|
colorBuffer.reset();
|
|
depthBuffer.reset();
|
|
stencilBuffer.reset();
|
|
}
|
|
return {
|
|
buffers: {
|
|
color: colorBuffer,
|
|
depth: depthBuffer,
|
|
stencil: stencilBuffer
|
|
},
|
|
enable,
|
|
disable,
|
|
bindFramebuffer,
|
|
drawBuffers,
|
|
useProgram,
|
|
setBlending,
|
|
setMaterial,
|
|
setFlipSided,
|
|
setCullFace,
|
|
setLineWidth,
|
|
setPolygonOffset,
|
|
setScissorTest,
|
|
activeTexture,
|
|
bindTexture,
|
|
unbindTexture,
|
|
compressedTexImage2D,
|
|
compressedTexImage3D,
|
|
texImage2D,
|
|
texImage3D,
|
|
updateUBOMapping,
|
|
uniformBlockBinding,
|
|
texStorage2D,
|
|
texStorage3D,
|
|
texSubImage2D,
|
|
texSubImage3D,
|
|
compressedTexSubImage2D,
|
|
compressedTexSubImage3D,
|
|
scissor,
|
|
viewport,
|
|
reset
|
|
};
|
|
}
|
|
function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
|
|
const multisampledRTTExt = extensions.has("WEBGL_multisampled_render_to_texture") ? extensions.get("WEBGL_multisampled_render_to_texture") : null;
|
|
const supportsInvalidateFramebuffer = typeof navigator === "undefined" ? false : /OculusBrowser/g.test(navigator.userAgent);
|
|
const multiviewExt = extensions.has("OCULUS_multiview") ? extensions.get("OCULUS_multiview") : null;
|
|
const _imageDimensions = new Vector2;
|
|
const _videoTextures = new WeakMap;
|
|
let _canvas2;
|
|
const _sources = new WeakMap;
|
|
let _deferredUploads = [];
|
|
let _deferTextureUploads = false;
|
|
let useOffscreenCanvas = false;
|
|
try {
|
|
useOffscreenCanvas = typeof OffscreenCanvas !== "undefined" && new OffscreenCanvas(1, 1).getContext("2d") !== null;
|
|
} catch (err) {}
|
|
function createCanvas(width, height) {
|
|
return useOffscreenCanvas ? new OffscreenCanvas(width, height) : createElementNS("canvas");
|
|
}
|
|
function resizeImage(image, needsNewCanvas, maxSize) {
|
|
let scale = 1;
|
|
const dimensions = getDimensions(image);
|
|
if (dimensions.width > maxSize || dimensions.height > maxSize) {
|
|
scale = maxSize / Math.max(dimensions.width, dimensions.height);
|
|
}
|
|
if (scale < 1) {
|
|
if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap || typeof VideoFrame !== "undefined" && image instanceof VideoFrame) {
|
|
const width = Math.floor(scale * dimensions.width);
|
|
const height = Math.floor(scale * dimensions.height);
|
|
if (_canvas2 === undefined)
|
|
_canvas2 = createCanvas(width, height);
|
|
const canvas = needsNewCanvas ? createCanvas(width, height) : _canvas2;
|
|
canvas.width = width;
|
|
canvas.height = height;
|
|
const context = canvas.getContext("2d");
|
|
context.drawImage(image, 0, 0, width, height);
|
|
console.warn("THREE.WebGLRenderer: Texture has been resized from (" + dimensions.width + "x" + dimensions.height + ") to (" + width + "x" + height + ").");
|
|
return canvas;
|
|
} else {
|
|
if ("data" in image) {
|
|
console.warn("THREE.WebGLRenderer: Image in DataTexture is too big (" + dimensions.width + "x" + dimensions.height + ").");
|
|
}
|
|
return image;
|
|
}
|
|
}
|
|
return image;
|
|
}
|
|
function textureNeedsGenerateMipmaps(texture) {
|
|
return texture.generateMipmaps;
|
|
}
|
|
function generateMipmap(target) {
|
|
_gl.generateMipmap(target);
|
|
}
|
|
function getTargetType(texture) {
|
|
if (texture.isWebGLCubeRenderTarget)
|
|
return _gl.TEXTURE_CUBE_MAP;
|
|
if (texture.isWebGL3DRenderTarget)
|
|
return _gl.TEXTURE_3D;
|
|
if (texture.isWebGLArrayRenderTarget || texture.isCompressedArrayTexture)
|
|
return _gl.TEXTURE_2D_ARRAY;
|
|
return _gl.TEXTURE_2D;
|
|
}
|
|
function getInternalFormat(internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false) {
|
|
if (internalFormatName !== null) {
|
|
if (_gl[internalFormatName] !== undefined)
|
|
return _gl[internalFormatName];
|
|
console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '" + internalFormatName + "'");
|
|
}
|
|
let internalFormat = glFormat;
|
|
if (glFormat === _gl.RED) {
|
|
if (glType === _gl.FLOAT)
|
|
internalFormat = _gl.R32F;
|
|
if (glType === _gl.HALF_FLOAT)
|
|
internalFormat = _gl.R16F;
|
|
if (glType === _gl.UNSIGNED_BYTE)
|
|
internalFormat = _gl.R8;
|
|
}
|
|
if (glFormat === _gl.RED_INTEGER) {
|
|
if (glType === _gl.UNSIGNED_BYTE)
|
|
internalFormat = _gl.R8UI;
|
|
if (glType === _gl.UNSIGNED_SHORT)
|
|
internalFormat = _gl.R16UI;
|
|
if (glType === _gl.UNSIGNED_INT)
|
|
internalFormat = _gl.R32UI;
|
|
if (glType === _gl.BYTE)
|
|
internalFormat = _gl.R8I;
|
|
if (glType === _gl.SHORT)
|
|
internalFormat = _gl.R16I;
|
|
if (glType === _gl.INT)
|
|
internalFormat = _gl.R32I;
|
|
}
|
|
if (glFormat === _gl.RG) {
|
|
if (glType === _gl.FLOAT)
|
|
internalFormat = _gl.RG32F;
|
|
if (glType === _gl.HALF_FLOAT)
|
|
internalFormat = _gl.RG16F;
|
|
if (glType === _gl.UNSIGNED_BYTE)
|
|
internalFormat = _gl.RG8;
|
|
}
|
|
if (glFormat === _gl.RG_INTEGER) {
|
|
if (glType === _gl.UNSIGNED_BYTE)
|
|
internalFormat = _gl.RG8UI;
|
|
if (glType === _gl.UNSIGNED_SHORT)
|
|
internalFormat = _gl.RG16UI;
|
|
if (glType === _gl.UNSIGNED_INT)
|
|
internalFormat = _gl.RG32UI;
|
|
if (glType === _gl.BYTE)
|
|
internalFormat = _gl.RG8I;
|
|
if (glType === _gl.SHORT)
|
|
internalFormat = _gl.RG16I;
|
|
if (glType === _gl.INT)
|
|
internalFormat = _gl.RG32I;
|
|
}
|
|
if (glFormat === _gl.RGB_INTEGER) {
|
|
if (glType === _gl.UNSIGNED_BYTE)
|
|
internalFormat = _gl.RGB8UI;
|
|
if (glType === _gl.UNSIGNED_SHORT)
|
|
internalFormat = _gl.RGB16UI;
|
|
if (glType === _gl.UNSIGNED_INT)
|
|
internalFormat = _gl.RGB32UI;
|
|
if (glType === _gl.BYTE)
|
|
internalFormat = _gl.RGB8I;
|
|
if (glType === _gl.SHORT)
|
|
internalFormat = _gl.RGB16I;
|
|
if (glType === _gl.INT)
|
|
internalFormat = _gl.RGB32I;
|
|
}
|
|
if (glFormat === _gl.RGBA_INTEGER) {
|
|
if (glType === _gl.UNSIGNED_BYTE)
|
|
internalFormat = _gl.RGBA8UI;
|
|
if (glType === _gl.UNSIGNED_SHORT)
|
|
internalFormat = _gl.RGBA16UI;
|
|
if (glType === _gl.UNSIGNED_INT)
|
|
internalFormat = _gl.RGBA32UI;
|
|
if (glType === _gl.BYTE)
|
|
internalFormat = _gl.RGBA8I;
|
|
if (glType === _gl.SHORT)
|
|
internalFormat = _gl.RGBA16I;
|
|
if (glType === _gl.INT)
|
|
internalFormat = _gl.RGBA32I;
|
|
}
|
|
if (glFormat === _gl.RGB) {
|
|
if (glType === _gl.UNSIGNED_INT_5_9_9_9_REV)
|
|
internalFormat = _gl.RGB9_E5;
|
|
}
|
|
if (glFormat === _gl.RGBA) {
|
|
const transfer = forceLinearTransfer ? LinearTransfer : ColorManagement.getTransfer(colorSpace);
|
|
if (glType === _gl.FLOAT)
|
|
internalFormat = _gl.RGBA32F;
|
|
if (glType === _gl.HALF_FLOAT)
|
|
internalFormat = _gl.RGBA16F;
|
|
if (glType === _gl.UNSIGNED_BYTE)
|
|
internalFormat = transfer === SRGBTransfer ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
|
|
if (glType === _gl.UNSIGNED_SHORT_4_4_4_4)
|
|
internalFormat = _gl.RGBA4;
|
|
if (glType === _gl.UNSIGNED_SHORT_5_5_5_1)
|
|
internalFormat = _gl.RGB5_A1;
|
|
}
|
|
if (internalFormat === _gl.R16F || internalFormat === _gl.R32F || internalFormat === _gl.RG16F || internalFormat === _gl.RG32F || internalFormat === _gl.RGBA16F || internalFormat === _gl.RGBA32F) {
|
|
extensions.get("EXT_color_buffer_float");
|
|
}
|
|
return internalFormat;
|
|
}
|
|
function getInternalDepthFormat(useStencil, depthType) {
|
|
let glInternalFormat;
|
|
if (useStencil) {
|
|
if (depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type) {
|
|
glInternalFormat = _gl.DEPTH24_STENCIL8;
|
|
} else if (depthType === FloatType) {
|
|
glInternalFormat = _gl.DEPTH32F_STENCIL8;
|
|
} else if (depthType === UnsignedShortType) {
|
|
glInternalFormat = _gl.DEPTH24_STENCIL8;
|
|
console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.");
|
|
}
|
|
} else {
|
|
if (depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type) {
|
|
glInternalFormat = _gl.DEPTH_COMPONENT24;
|
|
} else if (depthType === FloatType) {
|
|
glInternalFormat = _gl.DEPTH_COMPONENT32F;
|
|
} else if (depthType === UnsignedShortType) {
|
|
glInternalFormat = _gl.DEPTH_COMPONENT16;
|
|
}
|
|
}
|
|
return glInternalFormat;
|
|
}
|
|
function getMipLevels(texture, image) {
|
|
if (textureNeedsGenerateMipmaps(texture) === true || texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
|
|
return Math.log2(Math.max(image.width, image.height)) + 1;
|
|
} else if (texture.mipmaps !== undefined && texture.mipmaps.length > 0) {
|
|
return texture.mipmaps.length;
|
|
} else if (texture.isCompressedTexture && Array.isArray(texture.image)) {
|
|
return image.mipmaps.length;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}
|
|
function onTextureDispose(event) {
|
|
const texture = event.target;
|
|
texture.removeEventListener("dispose", onTextureDispose);
|
|
deallocateTexture(texture);
|
|
if (texture.isVideoTexture) {
|
|
_videoTextures.delete(texture);
|
|
}
|
|
}
|
|
function onRenderTargetDispose(event) {
|
|
const renderTarget = event.target;
|
|
renderTarget.removeEventListener("dispose", onRenderTargetDispose);
|
|
deallocateRenderTarget(renderTarget);
|
|
}
|
|
function deallocateTexture(texture) {
|
|
const textureProperties = properties.get(texture);
|
|
if (textureProperties.__webglInit === undefined)
|
|
return;
|
|
const source = texture.source;
|
|
const webglTextures = _sources.get(source);
|
|
if (webglTextures) {
|
|
const webglTexture = webglTextures[textureProperties.__cacheKey];
|
|
webglTexture.usedTimes--;
|
|
if (webglTexture.usedTimes === 0) {
|
|
deleteTexture(texture);
|
|
}
|
|
if (Object.keys(webglTextures).length === 0) {
|
|
_sources.delete(source);
|
|
}
|
|
}
|
|
properties.remove(texture);
|
|
}
|
|
function deleteTexture(texture) {
|
|
const textureProperties = properties.get(texture);
|
|
_gl.deleteTexture(textureProperties.__webglTexture);
|
|
const source = texture.source;
|
|
const webglTextures = _sources.get(source);
|
|
delete webglTextures[textureProperties.__cacheKey];
|
|
info.memory.textures--;
|
|
}
|
|
function deallocateRenderTarget(renderTarget) {
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
if (renderTarget.depthTexture) {
|
|
renderTarget.depthTexture.dispose();
|
|
properties.remove(renderTarget.depthTexture);
|
|
}
|
|
if (renderTarget.isWebGLCubeRenderTarget) {
|
|
for (let i = 0;i < 6; i++) {
|
|
if (Array.isArray(renderTargetProperties.__webglFramebuffer[i])) {
|
|
for (let level = 0;level < renderTargetProperties.__webglFramebuffer[i].length; level++)
|
|
_gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i][level]);
|
|
} else {
|
|
_gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
|
|
}
|
|
if (renderTargetProperties.__webglDepthbuffer)
|
|
_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
|
|
}
|
|
} else {
|
|
if (Array.isArray(renderTargetProperties.__webglFramebuffer)) {
|
|
for (let level = 0;level < renderTargetProperties.__webglFramebuffer.length; level++)
|
|
_gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[level]);
|
|
} else {
|
|
_gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
|
|
}
|
|
if (renderTargetProperties.__webglDepthbuffer)
|
|
_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
|
|
if (renderTargetProperties.__webglMultisampledFramebuffer)
|
|
_gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
|
|
if (renderTargetProperties.__webglColorRenderbuffer) {
|
|
for (let i = 0;i < renderTargetProperties.__webglColorRenderbuffer.length; i++) {
|
|
if (renderTargetProperties.__webglColorRenderbuffer[i])
|
|
_gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer[i]);
|
|
}
|
|
}
|
|
if (renderTargetProperties.__webglDepthRenderbuffer)
|
|
_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
|
|
}
|
|
const textures = renderTarget.textures;
|
|
for (let i = 0, il = textures.length;i < il; i++) {
|
|
const attachmentProperties = properties.get(textures[i]);
|
|
if (attachmentProperties.__webglTexture) {
|
|
_gl.deleteTexture(attachmentProperties.__webglTexture);
|
|
info.memory.textures--;
|
|
}
|
|
properties.remove(textures[i]);
|
|
}
|
|
properties.remove(renderTarget);
|
|
}
|
|
let textureUnits = 0;
|
|
function resetTextureUnits() {
|
|
textureUnits = 0;
|
|
}
|
|
function allocateTextureUnit() {
|
|
const textureUnit = textureUnits;
|
|
if (textureUnit >= capabilities.maxTextures) {
|
|
console.warn("THREE.WebGLTextures: Trying to use " + textureUnit + " texture units while this GPU supports only " + capabilities.maxTextures);
|
|
}
|
|
textureUnits += 1;
|
|
return textureUnit;
|
|
}
|
|
function getTextureCacheKey(texture) {
|
|
const array = [];
|
|
array.push(texture.wrapS);
|
|
array.push(texture.wrapT);
|
|
array.push(texture.wrapR || 0);
|
|
array.push(texture.magFilter);
|
|
array.push(texture.minFilter);
|
|
array.push(texture.anisotropy);
|
|
array.push(texture.internalFormat);
|
|
array.push(texture.format);
|
|
array.push(texture.type);
|
|
array.push(texture.generateMipmaps);
|
|
array.push(texture.premultiplyAlpha);
|
|
array.push(texture.flipY);
|
|
array.push(texture.unpackAlignment);
|
|
array.push(texture.colorSpace);
|
|
return array.join();
|
|
}
|
|
function setTexture2D(texture, slot) {
|
|
const textureProperties = properties.get(texture);
|
|
if (texture.isVideoTexture)
|
|
updateVideoTexture(texture);
|
|
if (texture.isRenderTargetTexture === false && texture.version > 0 && textureProperties.__version !== texture.version) {
|
|
const image = texture.image;
|
|
if (image === null) {
|
|
console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");
|
|
} else if (image.complete === false) {
|
|
console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");
|
|
} else {
|
|
if (uploadTexture(textureProperties, texture, slot)) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
state.bindTexture(_gl.TEXTURE_2D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot);
|
|
}
|
|
function setTexture2DArray(texture, slot) {
|
|
const textureProperties = properties.get(texture);
|
|
if (texture.version > 0 && textureProperties.__version !== texture.version) {
|
|
uploadTexture(textureProperties, texture, slot);
|
|
return;
|
|
}
|
|
state.bindTexture(_gl.TEXTURE_2D_ARRAY, textureProperties.__webglTexture, _gl.TEXTURE0 + slot);
|
|
}
|
|
function setTexture3D(texture, slot) {
|
|
const textureProperties = properties.get(texture);
|
|
if (texture.version > 0 && textureProperties.__version !== texture.version) {
|
|
uploadTexture(textureProperties, texture, slot);
|
|
return;
|
|
}
|
|
state.bindTexture(_gl.TEXTURE_3D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot);
|
|
}
|
|
function setTextureCube(texture, slot) {
|
|
const textureProperties = properties.get(texture);
|
|
if (texture.version > 0 && textureProperties.__version !== texture.version) {
|
|
uploadCubeTexture(textureProperties, texture, slot);
|
|
return;
|
|
}
|
|
state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot);
|
|
}
|
|
const wrappingToGL = {
|
|
[RepeatWrapping]: _gl.REPEAT,
|
|
[ClampToEdgeWrapping]: _gl.CLAMP_TO_EDGE,
|
|
[MirroredRepeatWrapping]: _gl.MIRRORED_REPEAT
|
|
};
|
|
const filterToGL = {
|
|
[NearestFilter]: _gl.NEAREST,
|
|
[NearestMipmapNearestFilter]: _gl.NEAREST_MIPMAP_NEAREST,
|
|
[NearestMipmapLinearFilter]: _gl.NEAREST_MIPMAP_LINEAR,
|
|
[LinearFilter]: _gl.LINEAR,
|
|
[LinearMipmapNearestFilter]: _gl.LINEAR_MIPMAP_NEAREST,
|
|
[LinearMipmapLinearFilter]: _gl.LINEAR_MIPMAP_LINEAR
|
|
};
|
|
const compareToGL = {
|
|
[NeverCompare]: _gl.NEVER,
|
|
[AlwaysCompare]: _gl.ALWAYS,
|
|
[LessCompare]: _gl.LESS,
|
|
[LessEqualCompare]: _gl.LEQUAL,
|
|
[EqualCompare]: _gl.EQUAL,
|
|
[GreaterEqualCompare]: _gl.GEQUAL,
|
|
[GreaterCompare]: _gl.GREATER,
|
|
[NotEqualCompare]: _gl.NOTEQUAL
|
|
};
|
|
function setTextureParameters(textureType, texture) {
|
|
if (texture.type === FloatType && extensions.has("OES_texture_float_linear") === false && (texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter || texture.minFilter === LinearFilter || texture.minFilter === LinearMipmapNearestFilter || texture.minFilter === NearestMipmapLinearFilter || texture.minFilter === LinearMipmapLinearFilter)) {
|
|
console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device.");
|
|
}
|
|
_gl.texParameteri(textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[texture.wrapS]);
|
|
_gl.texParameteri(textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[texture.wrapT]);
|
|
if (textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY) {
|
|
_gl.texParameteri(textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[texture.wrapR]);
|
|
}
|
|
_gl.texParameteri(textureType, _gl.TEXTURE_MAG_FILTER, filterToGL[texture.magFilter]);
|
|
_gl.texParameteri(textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[texture.minFilter]);
|
|
if (texture.compareFunction) {
|
|
_gl.texParameteri(textureType, _gl.TEXTURE_COMPARE_MODE, _gl.COMPARE_REF_TO_TEXTURE);
|
|
_gl.texParameteri(textureType, _gl.TEXTURE_COMPARE_FUNC, compareToGL[texture.compareFunction]);
|
|
}
|
|
if (extensions.has("EXT_texture_filter_anisotropic") === true) {
|
|
if (texture.magFilter === NearestFilter)
|
|
return;
|
|
if (texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter)
|
|
return;
|
|
if (texture.type === FloatType && extensions.has("OES_texture_float_linear") === false)
|
|
return;
|
|
if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
|
|
const extension = extensions.get("EXT_texture_filter_anisotropic");
|
|
_gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
|
|
properties.get(texture).__currentAnisotropy = texture.anisotropy;
|
|
}
|
|
}
|
|
}
|
|
function initTexture(textureProperties, texture) {
|
|
let forceUpload = false;
|
|
if (textureProperties.__webglInit === undefined) {
|
|
textureProperties.__webglInit = true;
|
|
texture.addEventListener("dispose", onTextureDispose);
|
|
}
|
|
const source = texture.source;
|
|
let webglTextures = _sources.get(source);
|
|
if (webglTextures === undefined) {
|
|
webglTextures = {};
|
|
_sources.set(source, webglTextures);
|
|
}
|
|
const textureCacheKey = getTextureCacheKey(texture);
|
|
if (textureCacheKey !== textureProperties.__cacheKey) {
|
|
if (webglTextures[textureCacheKey] === undefined) {
|
|
webglTextures[textureCacheKey] = {
|
|
texture: _gl.createTexture(),
|
|
usedTimes: 0
|
|
};
|
|
info.memory.textures++;
|
|
forceUpload = true;
|
|
}
|
|
webglTextures[textureCacheKey].usedTimes++;
|
|
const webglTexture = webglTextures[textureProperties.__cacheKey];
|
|
if (webglTexture !== undefined) {
|
|
webglTextures[textureProperties.__cacheKey].usedTimes--;
|
|
if (webglTexture.usedTimes === 0) {
|
|
deleteTexture(texture);
|
|
}
|
|
}
|
|
textureProperties.__cacheKey = textureCacheKey;
|
|
textureProperties.__webglTexture = webglTextures[textureCacheKey].texture;
|
|
}
|
|
return forceUpload;
|
|
}
|
|
function setDeferTextureUploads(deferFlag) {
|
|
_deferTextureUploads = deferFlag;
|
|
}
|
|
function runDeferredUploads() {
|
|
const previousDeferSetting = _deferTextureUploads;
|
|
_deferTextureUploads = false;
|
|
for (const upload of _deferredUploads) {
|
|
uploadTexture(upload.textureProperties, upload.texture, upload.slot);
|
|
upload.texture.isPendingDeferredUpload = false;
|
|
}
|
|
_deferredUploads = [];
|
|
_deferTextureUploads = previousDeferSetting;
|
|
}
|
|
function uploadTexture(textureProperties, texture, slot) {
|
|
if (_deferTextureUploads) {
|
|
if (!texture.isPendingDeferredUpload) {
|
|
texture.isPendingDeferredUpload = true;
|
|
_deferredUploads.push({ textureProperties, texture, slot });
|
|
}
|
|
return false;
|
|
}
|
|
let textureType = _gl.TEXTURE_2D;
|
|
if (texture.isDataArrayTexture || texture.isCompressedArrayTexture)
|
|
textureType = _gl.TEXTURE_2D_ARRAY;
|
|
if (texture.isData3DTexture)
|
|
textureType = _gl.TEXTURE_3D;
|
|
const forceUpload = initTexture(textureProperties, texture);
|
|
const source = texture.source;
|
|
state.bindTexture(textureType, textureProperties.__webglTexture, _gl.TEXTURE0 + slot);
|
|
const sourceProperties = properties.get(source);
|
|
if (source.version !== sourceProperties.__version || forceUpload === true) {
|
|
state.activeTexture(_gl.TEXTURE0 + slot);
|
|
const workingPrimaries = ColorManagement.getPrimaries(ColorManagement.workingColorSpace);
|
|
const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries(texture.colorSpace);
|
|
const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;
|
|
_gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);
|
|
_gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha);
|
|
_gl.pixelStorei(_gl.UNPACK_ALIGNMENT, texture.unpackAlignment);
|
|
_gl.pixelStorei(_gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion);
|
|
let image = resizeImage(texture.image, false, capabilities.maxTextureSize);
|
|
image = verifyColorSpace(texture, image);
|
|
const glFormat = utils.convert(texture.format, texture.colorSpace);
|
|
const glType = utils.convert(texture.type);
|
|
let glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture);
|
|
setTextureParameters(textureType, texture);
|
|
let mipmap;
|
|
const mipmaps = texture.mipmaps;
|
|
const useTexStorage = texture.isVideoTexture !== true;
|
|
const allocateMemory = sourceProperties.__version === undefined || forceUpload === true;
|
|
const dataReady = source.dataReady;
|
|
const levels = getMipLevels(texture, image);
|
|
if (texture.isDepthTexture) {
|
|
glInternalFormat = getInternalDepthFormat(texture.format === DepthStencilFormat, texture.type);
|
|
if (allocateMemory) {
|
|
if (useTexStorage) {
|
|
state.texStorage2D(_gl.TEXTURE_2D, 1, glInternalFormat, image.width, image.height);
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
|
|
}
|
|
}
|
|
} else if (texture.isDataTexture) {
|
|
if (mipmaps.length > 0) {
|
|
if (useTexStorage && allocateMemory) {
|
|
state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height);
|
|
}
|
|
for (let i = 0, il = mipmaps.length;i < il; i++) {
|
|
mipmap = mipmaps[i];
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
|
|
}
|
|
}
|
|
texture.generateMipmaps = false;
|
|
} else {
|
|
if (useTexStorage) {
|
|
if (allocateMemory) {
|
|
state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height);
|
|
}
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, glFormat, glType, image.data);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
|
|
}
|
|
}
|
|
} else if (texture.isCompressedTexture) {
|
|
if (texture.isCompressedArrayTexture) {
|
|
if (useTexStorage && allocateMemory) {
|
|
state.texStorage3D(_gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height, image.depth);
|
|
}
|
|
for (let i = 0, il = mipmaps.length;i < il; i++) {
|
|
mipmap = mipmaps[i];
|
|
if (texture.format !== RGBAFormat) {
|
|
if (glFormat !== null) {
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
if (texture.layerUpdates.size > 0) {
|
|
const layerByteLength = getByteLength(mipmap.width, mipmap.height, texture.format, texture.type);
|
|
for (const layerIndex of texture.layerUpdates) {
|
|
const layerData = mipmap.data.subarray(layerIndex * layerByteLength / mipmap.data.BYTES_PER_ELEMENT, (layerIndex + 1) * layerByteLength / mipmap.data.BYTES_PER_ELEMENT);
|
|
state.compressedTexSubImage3D(_gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, layerData);
|
|
}
|
|
texture.clearLayerUpdates();
|
|
} else {
|
|
state.compressedTexSubImage3D(_gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data);
|
|
}
|
|
}
|
|
} else {
|
|
state.compressedTexImage3D(_gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, mipmap.data, 0, 0);
|
|
}
|
|
} else {
|
|
console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");
|
|
}
|
|
} else {
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage3D(_gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, glType, mipmap.data);
|
|
}
|
|
} else {
|
|
state.texImage3D(_gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, glFormat, glType, mipmap.data);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if (useTexStorage && allocateMemory) {
|
|
state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height);
|
|
}
|
|
for (let i = 0, il = mipmaps.length;i < il; i++) {
|
|
mipmap = mipmaps[i];
|
|
if (texture.format !== RGBAFormat) {
|
|
if (glFormat !== null) {
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.compressedTexSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data);
|
|
}
|
|
} else {
|
|
state.compressedTexImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
|
|
}
|
|
} else {
|
|
console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");
|
|
}
|
|
} else {
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if (texture.isDataArrayTexture) {
|
|
if (useTexStorage) {
|
|
if (allocateMemory) {
|
|
state.texStorage3D(_gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, image.width, image.height, image.depth);
|
|
}
|
|
if (dataReady) {
|
|
if (texture.layerUpdates.size > 0) {
|
|
const layerByteLength = getByteLength(image.width, image.height, texture.format, texture.type);
|
|
for (const layerIndex of texture.layerUpdates) {
|
|
const layerData = image.data.subarray(layerIndex * layerByteLength / image.data.BYTES_PER_ELEMENT, (layerIndex + 1) * layerByteLength / image.data.BYTES_PER_ELEMENT);
|
|
state.texSubImage3D(_gl.TEXTURE_2D_ARRAY, 0, 0, 0, layerIndex, image.width, image.height, 1, glFormat, glType, layerData);
|
|
}
|
|
texture.clearLayerUpdates();
|
|
} else {
|
|
state.texSubImage3D(_gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data);
|
|
}
|
|
}
|
|
} else {
|
|
state.texImage3D(_gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
|
|
}
|
|
} else if (texture.isData3DTexture) {
|
|
if (useTexStorage) {
|
|
if (allocateMemory) {
|
|
state.texStorage3D(_gl.TEXTURE_3D, levels, glInternalFormat, image.width, image.height, image.depth);
|
|
}
|
|
if (dataReady) {
|
|
state.texSubImage3D(_gl.TEXTURE_3D, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data);
|
|
}
|
|
} else {
|
|
state.texImage3D(_gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
|
|
}
|
|
} else if (texture.isFramebufferTexture) {
|
|
if (allocateMemory) {
|
|
if (useTexStorage) {
|
|
state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height);
|
|
} else {
|
|
let { width, height } = image;
|
|
for (let i = 0;i < levels; i++) {
|
|
state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, width, height, 0, glFormat, glType, null);
|
|
width >>= 1;
|
|
height >>= 1;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if (mipmaps.length > 0) {
|
|
if (useTexStorage && allocateMemory) {
|
|
const dimensions = getDimensions(mipmaps[0]);
|
|
state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, dimensions.width, dimensions.height);
|
|
}
|
|
for (let i = 0, il = mipmaps.length;i < il; i++) {
|
|
mipmap = mipmaps[i];
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, glFormat, glType, mipmap);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap);
|
|
}
|
|
}
|
|
texture.generateMipmaps = false;
|
|
} else {
|
|
if (useTexStorage) {
|
|
if (allocateMemory) {
|
|
const dimensions = getDimensions(image);
|
|
state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, dimensions.width, dimensions.height);
|
|
}
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_2D, 0, 0, 0, glFormat, glType, image);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image);
|
|
}
|
|
}
|
|
}
|
|
if (textureNeedsGenerateMipmaps(texture)) {
|
|
generateMipmap(textureType);
|
|
}
|
|
sourceProperties.__version = source.version;
|
|
if (texture.onUpdate)
|
|
texture.onUpdate(texture);
|
|
}
|
|
textureProperties.__version = texture.version;
|
|
return true;
|
|
}
|
|
function uploadCubeTexture(textureProperties, texture, slot) {
|
|
if (texture.image.length !== 6)
|
|
return;
|
|
const forceUpload = initTexture(textureProperties, texture);
|
|
const source = texture.source;
|
|
state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot);
|
|
const sourceProperties = properties.get(source);
|
|
if (source.version !== sourceProperties.__version || forceUpload === true) {
|
|
state.activeTexture(_gl.TEXTURE0 + slot);
|
|
const workingPrimaries = ColorManagement.getPrimaries(ColorManagement.workingColorSpace);
|
|
const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries(texture.colorSpace);
|
|
const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;
|
|
_gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);
|
|
_gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha);
|
|
_gl.pixelStorei(_gl.UNPACK_ALIGNMENT, texture.unpackAlignment);
|
|
_gl.pixelStorei(_gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion);
|
|
const isCompressed = texture.isCompressedTexture || texture.image[0].isCompressedTexture;
|
|
const isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
|
|
const cubeImage = [];
|
|
for (let i = 0;i < 6; i++) {
|
|
if (!isCompressed && !isDataTexture) {
|
|
cubeImage[i] = resizeImage(texture.image[i], true, capabilities.maxCubemapSize);
|
|
} else {
|
|
cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
|
|
}
|
|
cubeImage[i] = verifyColorSpace(texture, cubeImage[i]);
|
|
}
|
|
const image = cubeImage[0], glFormat = utils.convert(texture.format, texture.colorSpace), glType = utils.convert(texture.type), glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace);
|
|
const useTexStorage = texture.isVideoTexture !== true;
|
|
const allocateMemory = sourceProperties.__version === undefined || forceUpload === true;
|
|
const dataReady = source.dataReady;
|
|
let levels = getMipLevels(texture, image);
|
|
setTextureParameters(_gl.TEXTURE_CUBE_MAP, texture);
|
|
let mipmaps;
|
|
if (isCompressed) {
|
|
if (useTexStorage && allocateMemory) {
|
|
state.texStorage2D(_gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, image.width, image.height);
|
|
}
|
|
for (let i = 0;i < 6; i++) {
|
|
mipmaps = cubeImage[i].mipmaps;
|
|
for (let j = 0;j < mipmaps.length; j++) {
|
|
const mipmap = mipmaps[j];
|
|
if (texture.format !== RGBAFormat) {
|
|
if (glFormat !== null) {
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.compressedTexSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data);
|
|
}
|
|
} else {
|
|
state.compressedTexImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
|
|
}
|
|
} else {
|
|
console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()");
|
|
}
|
|
} else {
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
mipmaps = texture.mipmaps;
|
|
if (useTexStorage && allocateMemory) {
|
|
if (mipmaps.length > 0)
|
|
levels++;
|
|
const dimensions = getDimensions(cubeImage[0]);
|
|
state.texStorage2D(_gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, dimensions.width, dimensions.height);
|
|
}
|
|
for (let i = 0;i < 6; i++) {
|
|
if (isDataTexture) {
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, cubeImage[i].width, cubeImage[i].height, glFormat, glType, cubeImage[i].data);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, cubeImage[i].width, cubeImage[i].height, 0, glFormat, glType, cubeImage[i].data);
|
|
}
|
|
for (let j = 0;j < mipmaps.length; j++) {
|
|
const mipmap = mipmaps[j];
|
|
const mipmapImage = mipmap.image[i].image;
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, mipmapImage.width, mipmapImage.height, glFormat, glType, mipmapImage.data);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
|
|
}
|
|
}
|
|
} else {
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, glFormat, glType, cubeImage[i]);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[i]);
|
|
}
|
|
for (let j = 0;j < mipmaps.length; j++) {
|
|
const mipmap = mipmaps[j];
|
|
if (useTexStorage) {
|
|
if (dataReady) {
|
|
state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, glFormat, glType, mipmap.image[i]);
|
|
}
|
|
} else {
|
|
state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (textureNeedsGenerateMipmaps(texture)) {
|
|
generateMipmap(_gl.TEXTURE_CUBE_MAP);
|
|
}
|
|
sourceProperties.__version = source.version;
|
|
if (texture.onUpdate)
|
|
texture.onUpdate(texture);
|
|
}
|
|
textureProperties.__version = texture.version;
|
|
}
|
|
function setupFrameBufferTexture(framebuffer, renderTarget, texture, attachment, textureTarget, level) {
|
|
const glFormat = utils.convert(texture.format, texture.colorSpace);
|
|
const glType = utils.convert(texture.type);
|
|
const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace);
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
const textureProperties = properties.get(texture);
|
|
textureProperties.__renderTarget = renderTarget;
|
|
if (!renderTargetProperties.__hasExternalTextures) {
|
|
const width = Math.max(1, renderTarget.width >> level);
|
|
const height = Math.max(1, renderTarget.height >> level);
|
|
if (renderTarget.isWebGLMultiviewRenderTarget === true) {
|
|
state.texStorage3D(_gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.numViews);
|
|
} else if (textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY) {
|
|
state.texImage3D(textureTarget, level, glInternalFormat, width, height, renderTarget.depth, 0, glFormat, glType, null);
|
|
} else {
|
|
state.texImage2D(textureTarget, level, glInternalFormat, width, height, 0, glFormat, glType, null);
|
|
}
|
|
}
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
|
|
const multisampled = useMultisampledRTT(renderTarget);
|
|
if (renderTarget.isWebGLMultiviewRenderTarget === true) {
|
|
if (multisampled) {
|
|
multiviewExt.framebufferTextureMultisampleMultiviewOVR(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, 0, getRenderTargetSamples(renderTarget), 0, renderTarget.numViews);
|
|
} else {
|
|
multiviewExt.framebufferTextureMultiviewOVR(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, 0, 0, renderTarget.numViews);
|
|
}
|
|
} else if (textureTarget === _gl.TEXTURE_2D || textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z) {
|
|
if (multisampled) {
|
|
multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, 0, getRenderTargetSamples(renderTarget));
|
|
} else {
|
|
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, level);
|
|
}
|
|
}
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, null);
|
|
}
|
|
function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
|
|
_gl.bindRenderbuffer(_gl.RENDERBUFFER, renderbuffer);
|
|
if (renderTarget.isWebGLMultiviewRenderTarget === true) {
|
|
const useMultisample = useMultisampledRTT(renderTarget);
|
|
const numViews = renderTarget.numViews;
|
|
const depthTexture = renderTarget.depthTexture;
|
|
let glInternalFormat = _gl.DEPTH_COMPONENT24;
|
|
let glDepthAttachment = _gl.DEPTH_ATTACHMENT;
|
|
if (depthTexture && depthTexture.isDepthTexture) {
|
|
if (depthTexture.type === FloatType) {
|
|
glInternalFormat = _gl.DEPTH_COMPONENT32F;
|
|
} else if (depthTexture.type === UnsignedInt248Type) {
|
|
glInternalFormat = _gl.DEPTH24_STENCIL8;
|
|
glDepthAttachment = _gl.DEPTH_STENCIL_ATTACHMENT;
|
|
}
|
|
}
|
|
let depthStencilTexture = properties.get(renderTarget.depthTexture).__webglTexture;
|
|
if (depthStencilTexture === undefined) {
|
|
depthStencilTexture = _gl.createTexture();
|
|
_gl.bindTexture(_gl.TEXTURE_2D_ARRAY, depthStencilTexture);
|
|
_gl.texStorage3D(_gl.TEXTURE_2D_ARRAY, 1, glInternalFormat, renderTarget.width, renderTarget.height, numViews);
|
|
}
|
|
if (useMultisample) {
|
|
multiviewExt.framebufferTextureMultisampleMultiviewOVR(_gl.FRAMEBUFFER, glDepthAttachment, depthStencilTexture, 0, getRenderTargetSamples(renderTarget), 0, numViews);
|
|
} else {
|
|
multiviewExt.framebufferTextureMultiviewOVR(_gl.FRAMEBUFFER, glDepthAttachment, depthStencilTexture, 0, 0, numViews);
|
|
}
|
|
} else if (renderTarget.depthBuffer) {
|
|
const depthTexture = renderTarget.depthTexture;
|
|
const depthType = depthTexture && depthTexture.isDepthTexture ? depthTexture.type : null;
|
|
const glInternalFormat = getInternalDepthFormat(renderTarget.stencilBuffer, depthType);
|
|
const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
|
|
const samples = getRenderTargetSamples(renderTarget);
|
|
const isUseMultisampledRTT = useMultisampledRTT(renderTarget);
|
|
if (isUseMultisampledRTT) {
|
|
multisampledRTTExt.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
} else if (isMultisample) {
|
|
_gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
} else {
|
|
_gl.renderbufferStorage(_gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
}
|
|
_gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer);
|
|
} else {
|
|
const textures = renderTarget.textures;
|
|
for (let i = 0;i < textures.length; i++) {
|
|
const texture = textures[i];
|
|
const glFormat = utils.convert(texture.format, texture.colorSpace);
|
|
const glType = utils.convert(texture.type);
|
|
const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace);
|
|
const samples = getRenderTargetSamples(renderTarget);
|
|
if (isMultisample && useMultisampledRTT(renderTarget) === false) {
|
|
_gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
} else if (useMultisampledRTT(renderTarget)) {
|
|
multisampledRTTExt.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
} else {
|
|
_gl.renderbufferStorage(_gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
}
|
|
}
|
|
}
|
|
_gl.bindRenderbuffer(_gl.RENDERBUFFER, null);
|
|
}
|
|
function setupDepthTexture(framebuffer, renderTarget) {
|
|
const isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
|
|
if (isCube)
|
|
throw new Error("Depth Texture with cube render targets is not supported");
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
|
|
if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
|
|
throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");
|
|
}
|
|
const textureProperties = properties.get(renderTarget.depthTexture);
|
|
textureProperties.__renderTarget = renderTarget;
|
|
if (!textureProperties.__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
|
|
renderTarget.depthTexture.image.width = renderTarget.width;
|
|
renderTarget.depthTexture.image.height = renderTarget.height;
|
|
renderTarget.depthTexture.needsUpdate = true;
|
|
}
|
|
if (renderTarget.depthTexture.image.depth != 1) {
|
|
setTexture2DArray(renderTarget.depthTexture, 0);
|
|
} else {
|
|
setTexture2D(renderTarget.depthTexture, 0);
|
|
}
|
|
const webglDepthTexture = textureProperties.__webglTexture;
|
|
const samples = getRenderTargetSamples(renderTarget);
|
|
if (renderTarget.isWebGLMultiviewRenderTarget === true) {
|
|
const useMultisample = useMultisampledRTT(renderTarget);
|
|
const numViews = renderTarget.numViews;
|
|
if (renderTarget.depthTexture.format === DepthFormat) {
|
|
if (useMultisample) {
|
|
multiviewExt.framebufferTextureMultisampleMultiviewOVR(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, webglDepthTexture, 0, samples, 0, numViews);
|
|
} else {
|
|
multiviewExt.framebufferTextureMultiviewOVR(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, webglDepthTexture, 0, 0, numViews);
|
|
}
|
|
} else if (renderTarget.depthTexture.format === DepthStencilFormat) {
|
|
if (useMultisample) {
|
|
multiviewExt.framebufferTextureMultisampleMultiviewOVR(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, webglDepthTexture, 0, samples, 0, numViews);
|
|
} else {
|
|
multiviewExt.framebufferTextureMultiviewOVR(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, webglDepthTexture, 0, 0, numViews);
|
|
}
|
|
} else {
|
|
throw new Error("Unknown depthTexture format");
|
|
}
|
|
} else {
|
|
if (renderTarget.depthTexture.format === DepthFormat) {
|
|
if (useMultisampledRTT(renderTarget)) {
|
|
multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples);
|
|
} else {
|
|
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0);
|
|
}
|
|
} else if (renderTarget.depthTexture.format === DepthStencilFormat) {
|
|
if (useMultisampledRTT(renderTarget)) {
|
|
multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples);
|
|
} else {
|
|
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0);
|
|
}
|
|
} else {
|
|
throw new Error("Unknown depthTexture format");
|
|
}
|
|
}
|
|
}
|
|
function setupDepthRenderbuffer(renderTarget) {
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
const isCube = renderTarget.isWebGLCubeRenderTarget === true;
|
|
if (renderTargetProperties.__boundDepthTexture !== renderTarget.depthTexture) {
|
|
const depthTexture = renderTarget.depthTexture;
|
|
if (renderTargetProperties.__depthDisposeCallback) {
|
|
renderTargetProperties.__depthDisposeCallback();
|
|
}
|
|
if (depthTexture) {
|
|
const disposeEvent = () => {
|
|
delete renderTargetProperties.__boundDepthTexture;
|
|
delete renderTargetProperties.__depthDisposeCallback;
|
|
depthTexture.removeEventListener("dispose", disposeEvent);
|
|
};
|
|
depthTexture.addEventListener("dispose", disposeEvent);
|
|
renderTargetProperties.__depthDisposeCallback = disposeEvent;
|
|
}
|
|
renderTargetProperties.__boundDepthTexture = depthTexture;
|
|
}
|
|
if (renderTarget.depthTexture && !renderTargetProperties.__autoAllocateDepthBuffer) {
|
|
if (isCube)
|
|
throw new Error("target.depthTexture not supported in Cube render targets");
|
|
setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
|
|
} else {
|
|
if (isCube) {
|
|
renderTargetProperties.__webglDepthbuffer = [];
|
|
for (let i = 0;i < 6; i++) {
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[i]);
|
|
if (renderTargetProperties.__webglDepthbuffer[i] === undefined) {
|
|
renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
|
|
setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
|
|
} else {
|
|
const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
|
|
const renderbuffer = renderTargetProperties.__webglDepthbuffer[i];
|
|
_gl.bindRenderbuffer(_gl.RENDERBUFFER, renderbuffer);
|
|
_gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer);
|
|
}
|
|
}
|
|
} else {
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer);
|
|
if (renderTargetProperties.__webglDepthbuffer === undefined) {
|
|
renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
|
|
setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
|
|
} else {
|
|
const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
|
|
const renderbuffer = renderTargetProperties.__webglDepthbuffer;
|
|
_gl.bindRenderbuffer(_gl.RENDERBUFFER, renderbuffer);
|
|
_gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer);
|
|
}
|
|
}
|
|
}
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, null);
|
|
}
|
|
function rebindTextures(renderTarget, colorTexture, depthTexture) {
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
if (colorTexture !== undefined) {
|
|
setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, renderTarget.texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, 0);
|
|
}
|
|
if (depthTexture !== undefined) {
|
|
setupDepthRenderbuffer(renderTarget);
|
|
}
|
|
}
|
|
function setupRenderTarget(renderTarget) {
|
|
const texture = renderTarget.texture;
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
const textureProperties = properties.get(texture);
|
|
renderTarget.addEventListener("dispose", onRenderTargetDispose);
|
|
const textures = renderTarget.textures;
|
|
const isCube = renderTarget.isWebGLCubeRenderTarget === true;
|
|
const isMultipleRenderTargets = textures.length > 1;
|
|
if (!isMultipleRenderTargets) {
|
|
if (textureProperties.__webglTexture === undefined) {
|
|
textureProperties.__webglTexture = _gl.createTexture();
|
|
}
|
|
textureProperties.__version = texture.version;
|
|
info.memory.textures++;
|
|
}
|
|
if (isCube) {
|
|
renderTargetProperties.__webglFramebuffer = [];
|
|
for (let i = 0;i < 6; i++) {
|
|
if (texture.mipmaps && texture.mipmaps.length > 0) {
|
|
renderTargetProperties.__webglFramebuffer[i] = [];
|
|
for (let level = 0;level < texture.mipmaps.length; level++) {
|
|
renderTargetProperties.__webglFramebuffer[i][level] = _gl.createFramebuffer();
|
|
}
|
|
} else {
|
|
renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
|
|
}
|
|
}
|
|
} else {
|
|
if (texture.mipmaps && texture.mipmaps.length > 0) {
|
|
renderTargetProperties.__webglFramebuffer = [];
|
|
for (let level = 0;level < texture.mipmaps.length; level++) {
|
|
renderTargetProperties.__webglFramebuffer[level] = _gl.createFramebuffer();
|
|
}
|
|
} else {
|
|
renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
|
|
}
|
|
if (isMultipleRenderTargets) {
|
|
for (let i = 0, il = textures.length;i < il; i++) {
|
|
const attachmentProperties = properties.get(textures[i]);
|
|
if (attachmentProperties.__webglTexture === undefined) {
|
|
attachmentProperties.__webglTexture = _gl.createTexture();
|
|
info.memory.textures++;
|
|
}
|
|
}
|
|
}
|
|
if (renderTarget.samples > 0 && useMultisampledRTT(renderTarget) === false) {
|
|
renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
|
|
renderTargetProperties.__webglColorRenderbuffer = [];
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer);
|
|
for (let i = 0;i < textures.length; i++) {
|
|
const texture2 = textures[i];
|
|
renderTargetProperties.__webglColorRenderbuffer[i] = _gl.createRenderbuffer();
|
|
_gl.bindRenderbuffer(_gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]);
|
|
const glFormat = utils.convert(texture2.format, texture2.colorSpace);
|
|
const glType = utils.convert(texture2.type);
|
|
const glInternalFormat = getInternalFormat(texture2.internalFormat, glFormat, glType, texture2.colorSpace, renderTarget.isXRRenderTarget === true);
|
|
const samples = getRenderTargetSamples(renderTarget);
|
|
_gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
_gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]);
|
|
}
|
|
_gl.bindRenderbuffer(_gl.RENDERBUFFER, null);
|
|
if (renderTarget.depthBuffer) {
|
|
renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
|
|
setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
|
|
}
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, null);
|
|
}
|
|
}
|
|
if (isCube) {
|
|
state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture);
|
|
setTextureParameters(_gl.TEXTURE_CUBE_MAP, texture);
|
|
for (let i = 0;i < 6; i++) {
|
|
if (texture.mipmaps && texture.mipmaps.length > 0) {
|
|
for (let level = 0;level < texture.mipmaps.length; level++) {
|
|
setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[i][level], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level);
|
|
}
|
|
} else {
|
|
setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[i], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0);
|
|
}
|
|
}
|
|
if (textureNeedsGenerateMipmaps(texture)) {
|
|
generateMipmap(_gl.TEXTURE_CUBE_MAP);
|
|
}
|
|
state.unbindTexture();
|
|
} else if (isMultipleRenderTargets) {
|
|
for (let i = 0, il = textures.length;i < il; i++) {
|
|
const attachment = textures[i];
|
|
const attachmentProperties = properties.get(attachment);
|
|
state.bindTexture(_gl.TEXTURE_2D, attachmentProperties.__webglTexture);
|
|
setTextureParameters(_gl.TEXTURE_2D, attachment);
|
|
setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, 0);
|
|
if (textureNeedsGenerateMipmaps(attachment)) {
|
|
generateMipmap(_gl.TEXTURE_2D);
|
|
}
|
|
}
|
|
state.unbindTexture();
|
|
} else {
|
|
let glTextureType = _gl.TEXTURE_2D;
|
|
if (renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget) {
|
|
glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;
|
|
}
|
|
if (renderTarget.isWebGLMultiviewRenderTarget === true) {
|
|
glTextureType = _gl.TEXTURE_2D_ARRAY;
|
|
}
|
|
state.bindTexture(glTextureType, textureProperties.__webglTexture);
|
|
setTextureParameters(glTextureType, texture);
|
|
if (texture.mipmaps && texture.mipmaps.length > 0) {
|
|
for (let level = 0;level < texture.mipmaps.length; level++) {
|
|
setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[level], renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, level);
|
|
}
|
|
} else {
|
|
setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, 0);
|
|
}
|
|
if (textureNeedsGenerateMipmaps(texture)) {
|
|
generateMipmap(glTextureType);
|
|
}
|
|
state.unbindTexture();
|
|
}
|
|
if (renderTarget.depthBuffer || renderTarget.isWebGLMultiviewRenderTarget === true) {
|
|
this.setupDepthRenderbuffer(renderTarget);
|
|
}
|
|
}
|
|
function updateRenderTargetMipmap(renderTarget) {
|
|
const textures = renderTarget.textures;
|
|
for (let i = 0, il = textures.length;i < il; i++) {
|
|
const texture = textures[i];
|
|
if (textureNeedsGenerateMipmaps(texture)) {
|
|
const targetType = getTargetType(renderTarget);
|
|
const webglTexture = properties.get(texture).__webglTexture;
|
|
state.bindTexture(targetType, webglTexture);
|
|
generateMipmap(targetType);
|
|
state.unbindTexture();
|
|
}
|
|
}
|
|
}
|
|
const invalidationArrayRead = [];
|
|
const invalidationArrayDraw = [];
|
|
function updateMultisampleRenderTarget(renderTarget) {
|
|
if (renderTarget.samples > 0) {
|
|
if (useMultisampledRTT(renderTarget) === false) {
|
|
const textures = renderTarget.textures;
|
|
const width = renderTarget.width;
|
|
const height = renderTarget.height;
|
|
let mask = _gl.COLOR_BUFFER_BIT;
|
|
const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
const isMultipleRenderTargets = textures.length > 1;
|
|
if (isMultipleRenderTargets) {
|
|
for (let i = 0;i < textures.length; i++) {
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer);
|
|
_gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, null);
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer);
|
|
_gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, null, 0);
|
|
}
|
|
}
|
|
state.bindFramebuffer(_gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer);
|
|
state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer);
|
|
for (let i = 0;i < textures.length; i++) {
|
|
if (renderTarget.resolveDepthBuffer) {
|
|
if (renderTarget.depthBuffer)
|
|
mask |= _gl.DEPTH_BUFFER_BIT;
|
|
if (renderTarget.stencilBuffer && renderTarget.resolveStencilBuffer)
|
|
mask |= _gl.STENCIL_BUFFER_BIT;
|
|
}
|
|
if (isMultipleRenderTargets) {
|
|
_gl.framebufferRenderbuffer(_gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]);
|
|
const webglTexture = properties.get(textures[i]).__webglTexture;
|
|
_gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, webglTexture, 0);
|
|
}
|
|
_gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST);
|
|
if (supportsInvalidateFramebuffer === true) {
|
|
invalidationArrayRead.length = 0;
|
|
invalidationArrayDraw.length = 0;
|
|
invalidationArrayRead.push(_gl.COLOR_ATTACHMENT0 + i);
|
|
if (renderTarget.depthBuffer && renderTarget.resolveDepthBuffer === false) {
|
|
invalidationArrayRead.push(depthStyle);
|
|
invalidationArrayDraw.push(depthStyle);
|
|
_gl.invalidateFramebuffer(_gl.DRAW_FRAMEBUFFER, invalidationArrayDraw);
|
|
}
|
|
_gl.invalidateFramebuffer(_gl.READ_FRAMEBUFFER, invalidationArrayRead);
|
|
}
|
|
}
|
|
state.bindFramebuffer(_gl.READ_FRAMEBUFFER, null);
|
|
state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, null);
|
|
if (isMultipleRenderTargets) {
|
|
for (let i = 0;i < textures.length; i++) {
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer);
|
|
_gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]);
|
|
const webglTexture = properties.get(textures[i]).__webglTexture;
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer);
|
|
_gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, webglTexture, 0);
|
|
}
|
|
}
|
|
state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer);
|
|
} else {
|
|
if (renderTarget.depthBuffer && renderTarget.resolveDepthBuffer === false && supportsInvalidateFramebuffer) {
|
|
const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
|
|
_gl.invalidateFramebuffer(_gl.DRAW_FRAMEBUFFER, [depthStyle]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function getRenderTargetSamples(renderTarget) {
|
|
return Math.min(capabilities.maxSamples, renderTarget.samples);
|
|
}
|
|
function useMultisampledRTT(renderTarget) {
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
return renderTarget.samples > 0 && extensions.has("WEBGL_multisampled_render_to_texture") === true && renderTargetProperties.__useRenderToTexture !== false;
|
|
}
|
|
function updateVideoTexture(texture) {
|
|
const frame = info.render.frame;
|
|
if (_videoTextures.get(texture) !== frame) {
|
|
_videoTextures.set(texture, frame);
|
|
texture.update();
|
|
}
|
|
}
|
|
function verifyColorSpace(texture, image) {
|
|
const colorSpace = texture.colorSpace;
|
|
const format = texture.format;
|
|
const type = texture.type;
|
|
if (texture.isCompressedTexture === true || texture.isVideoTexture === true)
|
|
return image;
|
|
if (colorSpace !== LinearSRGBColorSpace && colorSpace !== NoColorSpace) {
|
|
if (ColorManagement.getTransfer(colorSpace) === SRGBTransfer) {
|
|
if (format !== RGBAFormat || type !== UnsignedByteType) {
|
|
console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.");
|
|
}
|
|
} else {
|
|
console.error("THREE.WebGLTextures: Unsupported texture color space:", colorSpace);
|
|
}
|
|
}
|
|
return image;
|
|
}
|
|
function getDimensions(image) {
|
|
if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement) {
|
|
_imageDimensions.width = image.naturalWidth || image.width;
|
|
_imageDimensions.height = image.naturalHeight || image.height;
|
|
} else if (typeof VideoFrame !== "undefined" && image instanceof VideoFrame) {
|
|
_imageDimensions.width = image.displayWidth;
|
|
_imageDimensions.height = image.displayHeight;
|
|
} else {
|
|
_imageDimensions.width = image.width;
|
|
_imageDimensions.height = image.height;
|
|
}
|
|
return _imageDimensions;
|
|
}
|
|
this.allocateTextureUnit = allocateTextureUnit;
|
|
this.resetTextureUnits = resetTextureUnits;
|
|
this.setTexture2D = setTexture2D;
|
|
this.setTexture2DArray = setTexture2DArray;
|
|
this.setTexture3D = setTexture3D;
|
|
this.setTextureCube = setTextureCube;
|
|
this.rebindTextures = rebindTextures;
|
|
this.uploadTexture = uploadTexture;
|
|
this.setupRenderTarget = setupRenderTarget;
|
|
this.updateRenderTargetMipmap = updateRenderTargetMipmap;
|
|
this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
|
|
this.setupDepthTexture = setupDepthTexture;
|
|
this.setupDepthRenderbuffer = setupDepthRenderbuffer;
|
|
this.setupFrameBufferTexture = setupFrameBufferTexture;
|
|
this.useMultisampledRTT = useMultisampledRTT;
|
|
this.runDeferredUploads = runDeferredUploads;
|
|
this.setDeferTextureUploads = setDeferTextureUploads;
|
|
}
|
|
function WebGLUtils(gl, extensions) {
|
|
function convert(p, colorSpace = NoColorSpace) {
|
|
let extension;
|
|
const transfer = ColorManagement.getTransfer(colorSpace);
|
|
if (p === UnsignedByteType)
|
|
return gl.UNSIGNED_BYTE;
|
|
if (p === UnsignedShort4444Type)
|
|
return gl.UNSIGNED_SHORT_4_4_4_4;
|
|
if (p === UnsignedShort5551Type)
|
|
return gl.UNSIGNED_SHORT_5_5_5_1;
|
|
if (p === UnsignedInt5999Type)
|
|
return gl.UNSIGNED_INT_5_9_9_9_REV;
|
|
if (p === ByteType)
|
|
return gl.BYTE;
|
|
if (p === ShortType)
|
|
return gl.SHORT;
|
|
if (p === UnsignedShortType)
|
|
return gl.UNSIGNED_SHORT;
|
|
if (p === IntType)
|
|
return gl.INT;
|
|
if (p === UnsignedIntType)
|
|
return gl.UNSIGNED_INT;
|
|
if (p === FloatType)
|
|
return gl.FLOAT;
|
|
if (p === HalfFloatType)
|
|
return gl.HALF_FLOAT;
|
|
if (p === AlphaFormat)
|
|
return gl.ALPHA;
|
|
if (p === RGBFormat)
|
|
return gl.RGB;
|
|
if (p === RGBAFormat)
|
|
return gl.RGBA;
|
|
if (p === LuminanceFormat)
|
|
return gl.LUMINANCE;
|
|
if (p === LuminanceAlphaFormat)
|
|
return gl.LUMINANCE_ALPHA;
|
|
if (p === DepthFormat)
|
|
return gl.DEPTH_COMPONENT;
|
|
if (p === DepthStencilFormat)
|
|
return gl.DEPTH_STENCIL;
|
|
if (p === RedFormat)
|
|
return gl.RED;
|
|
if (p === RedIntegerFormat)
|
|
return gl.RED_INTEGER;
|
|
if (p === RGFormat)
|
|
return gl.RG;
|
|
if (p === RGIntegerFormat)
|
|
return gl.RG_INTEGER;
|
|
if (p === RGBAIntegerFormat)
|
|
return gl.RGBA_INTEGER;
|
|
if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
|
|
if (transfer === SRGBTransfer) {
|
|
extension = extensions.get("WEBGL_compressed_texture_s3tc_srgb");
|
|
if (extension !== null) {
|
|
if (p === RGB_S3TC_DXT1_Format)
|
|
return extension.COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
|
if (p === RGBA_S3TC_DXT1_Format)
|
|
return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
|
|
if (p === RGBA_S3TC_DXT3_Format)
|
|
return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
|
|
if (p === RGBA_S3TC_DXT5_Format)
|
|
return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
|
} else {
|
|
return null;
|
|
}
|
|
} else {
|
|
extension = extensions.get("WEBGL_compressed_texture_s3tc");
|
|
if (extension !== null) {
|
|
if (p === RGB_S3TC_DXT1_Format)
|
|
return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
|
|
if (p === RGBA_S3TC_DXT1_Format)
|
|
return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
|
if (p === RGBA_S3TC_DXT3_Format)
|
|
return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
|
if (p === RGBA_S3TC_DXT5_Format)
|
|
return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
|
|
extension = extensions.get("WEBGL_compressed_texture_pvrtc");
|
|
if (extension !== null) {
|
|
if (p === RGB_PVRTC_4BPPV1_Format)
|
|
return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
|
|
if (p === RGB_PVRTC_2BPPV1_Format)
|
|
return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
|
|
if (p === RGBA_PVRTC_4BPPV1_Format)
|
|
return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
|
|
if (p === RGBA_PVRTC_2BPPV1_Format)
|
|
return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
if (p === RGB_ETC1_Format || p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
|
|
extension = extensions.get("WEBGL_compressed_texture_etc");
|
|
if (extension !== null) {
|
|
if (p === RGB_ETC1_Format || p === RGB_ETC2_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
|
|
if (p === RGBA_ETC2_EAC_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
if (p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format || p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format || p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format || p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format || p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format) {
|
|
extension = extensions.get("WEBGL_compressed_texture_astc");
|
|
if (extension !== null) {
|
|
if (p === RGBA_ASTC_4x4_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR;
|
|
if (p === RGBA_ASTC_5x4_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR;
|
|
if (p === RGBA_ASTC_5x5_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR;
|
|
if (p === RGBA_ASTC_6x5_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR;
|
|
if (p === RGBA_ASTC_6x6_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR;
|
|
if (p === RGBA_ASTC_8x5_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR;
|
|
if (p === RGBA_ASTC_8x6_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR;
|
|
if (p === RGBA_ASTC_8x8_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR;
|
|
if (p === RGBA_ASTC_10x5_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR;
|
|
if (p === RGBA_ASTC_10x6_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR;
|
|
if (p === RGBA_ASTC_10x8_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR;
|
|
if (p === RGBA_ASTC_10x10_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR;
|
|
if (p === RGBA_ASTC_12x10_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR;
|
|
if (p === RGBA_ASTC_12x12_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
if (p === RGBA_BPTC_Format || p === RGB_BPTC_SIGNED_Format || p === RGB_BPTC_UNSIGNED_Format) {
|
|
extension = extensions.get("EXT_texture_compression_bptc");
|
|
if (extension !== null) {
|
|
if (p === RGBA_BPTC_Format)
|
|
return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT;
|
|
if (p === RGB_BPTC_SIGNED_Format)
|
|
return extension.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;
|
|
if (p === RGB_BPTC_UNSIGNED_Format)
|
|
return extension.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
if (p === RED_RGTC1_Format || p === SIGNED_RED_RGTC1_Format || p === RED_GREEN_RGTC2_Format || p === SIGNED_RED_GREEN_RGTC2_Format) {
|
|
extension = extensions.get("EXT_texture_compression_rgtc");
|
|
if (extension !== null) {
|
|
if (p === RGBA_BPTC_Format)
|
|
return extension.COMPRESSED_RED_RGTC1_EXT;
|
|
if (p === SIGNED_RED_RGTC1_Format)
|
|
return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT;
|
|
if (p === RED_GREEN_RGTC2_Format)
|
|
return extension.COMPRESSED_RED_GREEN_RGTC2_EXT;
|
|
if (p === SIGNED_RED_GREEN_RGTC2_Format)
|
|
return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
if (p === UnsignedInt248Type)
|
|
return gl.UNSIGNED_INT_24_8;
|
|
return gl[p] !== undefined ? gl[p] : null;
|
|
}
|
|
return { convert };
|
|
}
|
|
|
|
class WebXRDepthSensing {
|
|
constructor() {
|
|
this.texture = null;
|
|
this.mesh = null;
|
|
this.depthNear = 0;
|
|
this.depthFar = 0;
|
|
}
|
|
init(renderer, depthData, renderState) {
|
|
if (this.texture === null) {
|
|
const texture = new Texture;
|
|
const texProps = renderer.properties.get(texture);
|
|
texProps.__webglTexture = depthData.texture;
|
|
if (depthData.depthNear !== renderState.depthNear || depthData.depthFar !== renderState.depthFar) {
|
|
this.depthNear = depthData.depthNear;
|
|
this.depthFar = depthData.depthFar;
|
|
}
|
|
this.texture = texture;
|
|
}
|
|
}
|
|
getMesh(cameraXR) {
|
|
if (this.texture !== null) {
|
|
if (this.mesh === null) {
|
|
const viewport = cameraXR.cameras[0].viewport;
|
|
const material = new ShaderMaterial({
|
|
vertexShader: _occlusion_vertex,
|
|
fragmentShader: _occlusion_fragment,
|
|
uniforms: {
|
|
depthColor: { value: this.texture },
|
|
depthWidth: { value: viewport.z },
|
|
depthHeight: { value: viewport.w }
|
|
}
|
|
});
|
|
this.mesh = new Mesh(new PlaneGeometry(20, 20), material);
|
|
}
|
|
}
|
|
return this.mesh;
|
|
}
|
|
reset() {
|
|
this.texture = null;
|
|
this.mesh = null;
|
|
}
|
|
getDepthTexture() {
|
|
return this.texture;
|
|
}
|
|
}
|
|
function WebGLMaterials(renderer, properties) {
|
|
function refreshTransformUniform(map, uniform) {
|
|
if (map.matrixAutoUpdate === true) {
|
|
map.updateMatrix();
|
|
}
|
|
uniform.value.copy(map.matrix);
|
|
}
|
|
function refreshFogUniforms(uniforms, fog) {
|
|
fog.color.getRGB(uniforms.fogColor.value, getUnlitUniformColorSpace(renderer));
|
|
if (fog.isFog) {
|
|
uniforms.fogNear.value = fog.near;
|
|
uniforms.fogFar.value = fog.far;
|
|
} else if (fog.isFogExp2) {
|
|
uniforms.fogDensity.value = fog.density;
|
|
}
|
|
}
|
|
function refreshMaterialUniforms(uniforms, material, pixelRatio, height, transmissionRenderTarget) {
|
|
if (material.isMeshBasicMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
} else if (material.isMeshLambertMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
} else if (material.isMeshToonMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
refreshUniformsToon(uniforms, material);
|
|
} else if (material.isMeshPhongMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
refreshUniformsPhong(uniforms, material);
|
|
} else if (material.isMeshStandardMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
refreshUniformsStandard(uniforms, material);
|
|
if (material.isMeshPhysicalMaterial) {
|
|
refreshUniformsPhysical(uniforms, material, transmissionRenderTarget);
|
|
}
|
|
} else if (material.isMeshMatcapMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
refreshUniformsMatcap(uniforms, material);
|
|
} else if (material.isMeshDepthMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
} else if (material.isMeshDistanceMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
refreshUniformsDistance(uniforms, material);
|
|
} else if (material.isMeshNormalMaterial) {
|
|
refreshUniformsCommon(uniforms, material);
|
|
} else if (material.isLineBasicMaterial) {
|
|
refreshUniformsLine(uniforms, material);
|
|
if (material.isLineDashedMaterial) {
|
|
refreshUniformsDash(uniforms, material);
|
|
}
|
|
} else if (material.isPointsMaterial) {
|
|
refreshUniformsPoints(uniforms, material, pixelRatio, height);
|
|
} else if (material.isSpriteMaterial) {
|
|
refreshUniformsSprites(uniforms, material);
|
|
} else if (material.isShadowMaterial) {
|
|
uniforms.color.value.copy(material.color);
|
|
uniforms.opacity.value = material.opacity;
|
|
} else if (material.isShaderMaterial) {
|
|
material.uniformsNeedUpdate = false;
|
|
}
|
|
}
|
|
function refreshUniformsCommon(uniforms, material) {
|
|
uniforms.opacity.value = material.opacity;
|
|
if (material.color) {
|
|
uniforms.diffuse.value.copy(material.color);
|
|
}
|
|
if (material.emissive) {
|
|
uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
|
|
}
|
|
if (material.map) {
|
|
uniforms.map.value = material.map;
|
|
refreshTransformUniform(material.map, uniforms.mapTransform);
|
|
}
|
|
if (material.alphaMap) {
|
|
uniforms.alphaMap.value = material.alphaMap;
|
|
refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform);
|
|
}
|
|
if (material.bumpMap) {
|
|
uniforms.bumpMap.value = material.bumpMap;
|
|
refreshTransformUniform(material.bumpMap, uniforms.bumpMapTransform);
|
|
uniforms.bumpScale.value = material.bumpScale;
|
|
if (material.side === BackSide) {
|
|
uniforms.bumpScale.value *= -1;
|
|
}
|
|
}
|
|
if (material.normalMap) {
|
|
uniforms.normalMap.value = material.normalMap;
|
|
refreshTransformUniform(material.normalMap, uniforms.normalMapTransform);
|
|
uniforms.normalScale.value.copy(material.normalScale);
|
|
if (material.side === BackSide) {
|
|
uniforms.normalScale.value.negate();
|
|
}
|
|
}
|
|
if (material.displacementMap) {
|
|
uniforms.displacementMap.value = material.displacementMap;
|
|
refreshTransformUniform(material.displacementMap, uniforms.displacementMapTransform);
|
|
uniforms.displacementScale.value = material.displacementScale;
|
|
uniforms.displacementBias.value = material.displacementBias;
|
|
}
|
|
if (material.emissiveMap) {
|
|
uniforms.emissiveMap.value = material.emissiveMap;
|
|
refreshTransformUniform(material.emissiveMap, uniforms.emissiveMapTransform);
|
|
}
|
|
if (material.specularMap) {
|
|
uniforms.specularMap.value = material.specularMap;
|
|
refreshTransformUniform(material.specularMap, uniforms.specularMapTransform);
|
|
}
|
|
if (material.alphaTest > 0) {
|
|
uniforms.alphaTest.value = material.alphaTest;
|
|
}
|
|
const materialProperties = properties.get(material);
|
|
const envMap = materialProperties.envMap;
|
|
const envMapRotation = materialProperties.envMapRotation;
|
|
if (envMap) {
|
|
uniforms.envMap.value = envMap;
|
|
_e1.copy(envMapRotation);
|
|
_e1.x *= -1;
|
|
_e1.y *= -1;
|
|
_e1.z *= -1;
|
|
if (envMap.isCubeTexture && envMap.isRenderTargetTexture === false) {
|
|
_e1.y *= -1;
|
|
_e1.z *= -1;
|
|
}
|
|
uniforms.envMapRotation.value.setFromMatrix4(_m12.makeRotationFromEuler(_e1));
|
|
uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap.isRenderTargetTexture === false ? -1 : 1;
|
|
uniforms.reflectivity.value = material.reflectivity;
|
|
uniforms.ior.value = material.ior;
|
|
uniforms.refractionRatio.value = material.refractionRatio;
|
|
}
|
|
if (material.lightMap) {
|
|
uniforms.lightMap.value = material.lightMap;
|
|
uniforms.lightMapIntensity.value = material.lightMapIntensity;
|
|
refreshTransformUniform(material.lightMap, uniforms.lightMapTransform);
|
|
}
|
|
if (material.aoMap) {
|
|
uniforms.aoMap.value = material.aoMap;
|
|
uniforms.aoMapIntensity.value = material.aoMapIntensity;
|
|
refreshTransformUniform(material.aoMap, uniforms.aoMapTransform);
|
|
}
|
|
}
|
|
function refreshUniformsLine(uniforms, material) {
|
|
uniforms.diffuse.value.copy(material.color);
|
|
uniforms.opacity.value = material.opacity;
|
|
if (material.map) {
|
|
uniforms.map.value = material.map;
|
|
refreshTransformUniform(material.map, uniforms.mapTransform);
|
|
}
|
|
}
|
|
function refreshUniformsDash(uniforms, material) {
|
|
uniforms.dashSize.value = material.dashSize;
|
|
uniforms.totalSize.value = material.dashSize + material.gapSize;
|
|
uniforms.scale.value = material.scale;
|
|
}
|
|
function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
|
|
uniforms.diffuse.value.copy(material.color);
|
|
uniforms.opacity.value = material.opacity;
|
|
uniforms.size.value = material.size * pixelRatio;
|
|
uniforms.scale.value = height * 0.5;
|
|
if (material.map) {
|
|
uniforms.map.value = material.map;
|
|
refreshTransformUniform(material.map, uniforms.uvTransform);
|
|
}
|
|
if (material.alphaMap) {
|
|
uniforms.alphaMap.value = material.alphaMap;
|
|
refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform);
|
|
}
|
|
if (material.alphaTest > 0) {
|
|
uniforms.alphaTest.value = material.alphaTest;
|
|
}
|
|
}
|
|
function refreshUniformsSprites(uniforms, material) {
|
|
uniforms.diffuse.value.copy(material.color);
|
|
uniforms.opacity.value = material.opacity;
|
|
uniforms.rotation.value = material.rotation;
|
|
if (material.map) {
|
|
uniforms.map.value = material.map;
|
|
refreshTransformUniform(material.map, uniforms.mapTransform);
|
|
}
|
|
if (material.alphaMap) {
|
|
uniforms.alphaMap.value = material.alphaMap;
|
|
refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform);
|
|
}
|
|
if (material.alphaTest > 0) {
|
|
uniforms.alphaTest.value = material.alphaTest;
|
|
}
|
|
}
|
|
function refreshUniformsPhong(uniforms, material) {
|
|
uniforms.specular.value.copy(material.specular);
|
|
uniforms.shininess.value = Math.max(material.shininess, 0.0001);
|
|
}
|
|
function refreshUniformsToon(uniforms, material) {
|
|
if (material.gradientMap) {
|
|
uniforms.gradientMap.value = material.gradientMap;
|
|
}
|
|
}
|
|
function refreshUniformsStandard(uniforms, material) {
|
|
uniforms.metalness.value = material.metalness;
|
|
if (material.metalnessMap) {
|
|
uniforms.metalnessMap.value = material.metalnessMap;
|
|
refreshTransformUniform(material.metalnessMap, uniforms.metalnessMapTransform);
|
|
}
|
|
uniforms.roughness.value = material.roughness;
|
|
if (material.roughnessMap) {
|
|
uniforms.roughnessMap.value = material.roughnessMap;
|
|
refreshTransformUniform(material.roughnessMap, uniforms.roughnessMapTransform);
|
|
}
|
|
if (material.envMap) {
|
|
uniforms.envMapIntensity.value = material.envMapIntensity;
|
|
}
|
|
}
|
|
function refreshUniformsPhysical(uniforms, material, transmissionRenderTarget) {
|
|
uniforms.ior.value = material.ior;
|
|
if (material.sheen > 0) {
|
|
uniforms.sheenColor.value.copy(material.sheenColor).multiplyScalar(material.sheen);
|
|
uniforms.sheenRoughness.value = material.sheenRoughness;
|
|
if (material.sheenColorMap) {
|
|
uniforms.sheenColorMap.value = material.sheenColorMap;
|
|
refreshTransformUniform(material.sheenColorMap, uniforms.sheenColorMapTransform);
|
|
}
|
|
if (material.sheenRoughnessMap) {
|
|
uniforms.sheenRoughnessMap.value = material.sheenRoughnessMap;
|
|
refreshTransformUniform(material.sheenRoughnessMap, uniforms.sheenRoughnessMapTransform);
|
|
}
|
|
}
|
|
if (material.clearcoat > 0) {
|
|
uniforms.clearcoat.value = material.clearcoat;
|
|
uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
|
|
if (material.clearcoatMap) {
|
|
uniforms.clearcoatMap.value = material.clearcoatMap;
|
|
refreshTransformUniform(material.clearcoatMap, uniforms.clearcoatMapTransform);
|
|
}
|
|
if (material.clearcoatRoughnessMap) {
|
|
uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
|
|
refreshTransformUniform(material.clearcoatRoughnessMap, uniforms.clearcoatRoughnessMapTransform);
|
|
}
|
|
if (material.clearcoatNormalMap) {
|
|
uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
|
|
refreshTransformUniform(material.clearcoatNormalMap, uniforms.clearcoatNormalMapTransform);
|
|
uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
|
|
if (material.side === BackSide) {
|
|
uniforms.clearcoatNormalScale.value.negate();
|
|
}
|
|
}
|
|
}
|
|
if (material.dispersion > 0) {
|
|
uniforms.dispersion.value = material.dispersion;
|
|
}
|
|
if (material.iridescence > 0) {
|
|
uniforms.iridescence.value = material.iridescence;
|
|
uniforms.iridescenceIOR.value = material.iridescenceIOR;
|
|
uniforms.iridescenceThicknessMinimum.value = material.iridescenceThicknessRange[0];
|
|
uniforms.iridescenceThicknessMaximum.value = material.iridescenceThicknessRange[1];
|
|
if (material.iridescenceMap) {
|
|
uniforms.iridescenceMap.value = material.iridescenceMap;
|
|
refreshTransformUniform(material.iridescenceMap, uniforms.iridescenceMapTransform);
|
|
}
|
|
if (material.iridescenceThicknessMap) {
|
|
uniforms.iridescenceThicknessMap.value = material.iridescenceThicknessMap;
|
|
refreshTransformUniform(material.iridescenceThicknessMap, uniforms.iridescenceThicknessMapTransform);
|
|
}
|
|
}
|
|
if (material.transmission > 0) {
|
|
uniforms.transmission.value = material.transmission;
|
|
uniforms.transmissionSamplerMap.value = transmissionRenderTarget.texture;
|
|
uniforms.transmissionSamplerSize.value.set(transmissionRenderTarget.width, transmissionRenderTarget.height);
|
|
if (material.transmissionMap) {
|
|
uniforms.transmissionMap.value = material.transmissionMap;
|
|
refreshTransformUniform(material.transmissionMap, uniforms.transmissionMapTransform);
|
|
}
|
|
uniforms.thickness.value = material.thickness;
|
|
if (material.thicknessMap) {
|
|
uniforms.thicknessMap.value = material.thicknessMap;
|
|
refreshTransformUniform(material.thicknessMap, uniforms.thicknessMapTransform);
|
|
}
|
|
uniforms.attenuationDistance.value = material.attenuationDistance;
|
|
uniforms.attenuationColor.value.copy(material.attenuationColor);
|
|
}
|
|
if (material.anisotropy > 0) {
|
|
uniforms.anisotropyVector.value.set(material.anisotropy * Math.cos(material.anisotropyRotation), material.anisotropy * Math.sin(material.anisotropyRotation));
|
|
if (material.anisotropyMap) {
|
|
uniforms.anisotropyMap.value = material.anisotropyMap;
|
|
refreshTransformUniform(material.anisotropyMap, uniforms.anisotropyMapTransform);
|
|
}
|
|
}
|
|
uniforms.specularIntensity.value = material.specularIntensity;
|
|
uniforms.specularColor.value.copy(material.specularColor);
|
|
if (material.specularColorMap) {
|
|
uniforms.specularColorMap.value = material.specularColorMap;
|
|
refreshTransformUniform(material.specularColorMap, uniforms.specularColorMapTransform);
|
|
}
|
|
if (material.specularIntensityMap) {
|
|
uniforms.specularIntensityMap.value = material.specularIntensityMap;
|
|
refreshTransformUniform(material.specularIntensityMap, uniforms.specularIntensityMapTransform);
|
|
}
|
|
}
|
|
function refreshUniformsMatcap(uniforms, material) {
|
|
if (material.matcap) {
|
|
uniforms.matcap.value = material.matcap;
|
|
}
|
|
}
|
|
function refreshUniformsDistance(uniforms, material) {
|
|
const light = properties.get(material).light;
|
|
uniforms.referencePosition.value.setFromMatrixPosition(light.matrixWorld);
|
|
uniforms.nearDistance.value = light.shadow.camera.near;
|
|
uniforms.farDistance.value = light.shadow.camera.far;
|
|
}
|
|
return {
|
|
refreshFogUniforms,
|
|
refreshMaterialUniforms
|
|
};
|
|
}
|
|
function WebGLUniformsGroups(gl, info, capabilities, state) {
|
|
let buffers = {};
|
|
let updateList = {};
|
|
let allocatedBindingPoints = [];
|
|
const maxBindingPoints = gl.getParameter(gl.MAX_UNIFORM_BUFFER_BINDINGS);
|
|
function bind(uniformsGroup, program) {
|
|
const webglProgram = program.program;
|
|
state.uniformBlockBinding(uniformsGroup, webglProgram);
|
|
}
|
|
function update(uniformsGroup, program) {
|
|
let buffer = buffers[uniformsGroup.id];
|
|
if (buffer === undefined) {
|
|
prepareUniformsGroup(uniformsGroup);
|
|
buffer = createBuffer(uniformsGroup);
|
|
buffers[uniformsGroup.id] = buffer;
|
|
uniformsGroup.addEventListener("dispose", onUniformsGroupsDispose);
|
|
}
|
|
const webglProgram = program.program;
|
|
state.updateUBOMapping(uniformsGroup, webglProgram);
|
|
const frame = info.render.frame;
|
|
if (updateList[uniformsGroup.id] !== frame) {
|
|
updateBufferData(uniformsGroup);
|
|
updateList[uniformsGroup.id] = frame;
|
|
}
|
|
}
|
|
function createBuffer(uniformsGroup) {
|
|
const bindingPointIndex = allocateBindingPointIndex();
|
|
uniformsGroup.__bindingPointIndex = bindingPointIndex;
|
|
const buffer = gl.createBuffer();
|
|
const size = uniformsGroup.__size;
|
|
const usage = uniformsGroup.usage;
|
|
gl.bindBuffer(gl.UNIFORM_BUFFER, buffer);
|
|
gl.bufferData(gl.UNIFORM_BUFFER, size, usage);
|
|
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPointIndex, buffer);
|
|
return buffer;
|
|
}
|
|
function allocateBindingPointIndex() {
|
|
for (let i = 0;i < maxBindingPoints; i++) {
|
|
if (allocatedBindingPoints.indexOf(i) === -1) {
|
|
allocatedBindingPoints.push(i);
|
|
return i;
|
|
}
|
|
}
|
|
console.error("THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached.");
|
|
return 0;
|
|
}
|
|
function updateBufferData(uniformsGroup) {
|
|
const buffer = buffers[uniformsGroup.id];
|
|
const uniforms = uniformsGroup.uniforms;
|
|
const cache = uniformsGroup.__cache;
|
|
gl.bindBuffer(gl.UNIFORM_BUFFER, buffer);
|
|
for (let i = 0, il = uniforms.length;i < il; i++) {
|
|
const uniformArray = Array.isArray(uniforms[i]) ? uniforms[i] : [uniforms[i]];
|
|
for (let j = 0, jl = uniformArray.length;j < jl; j++) {
|
|
const uniform = uniformArray[j];
|
|
if (hasUniformChanged(uniform, i, j, cache) === true) {
|
|
const offset = uniform.__offset;
|
|
const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value];
|
|
let arrayOffset = 0;
|
|
for (let k = 0;k < values.length; k++) {
|
|
const value = values[k];
|
|
const info2 = getUniformSize(value);
|
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
uniform.__data[0] = value;
|
|
gl.bufferSubData(gl.UNIFORM_BUFFER, offset + arrayOffset, uniform.__data);
|
|
} else if (value.isMatrix3) {
|
|
uniform.__data[0] = value.elements[0];
|
|
uniform.__data[1] = value.elements[1];
|
|
uniform.__data[2] = value.elements[2];
|
|
uniform.__data[3] = 0;
|
|
uniform.__data[4] = value.elements[3];
|
|
uniform.__data[5] = value.elements[4];
|
|
uniform.__data[6] = value.elements[5];
|
|
uniform.__data[7] = 0;
|
|
uniform.__data[8] = value.elements[6];
|
|
uniform.__data[9] = value.elements[7];
|
|
uniform.__data[10] = value.elements[8];
|
|
uniform.__data[11] = 0;
|
|
} else {
|
|
value.toArray(uniform.__data, arrayOffset);
|
|
arrayOffset += info2.storage / Float32Array.BYTES_PER_ELEMENT;
|
|
}
|
|
}
|
|
gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data);
|
|
}
|
|
}
|
|
}
|
|
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
}
|
|
function hasUniformChanged(uniform, index, indexArray, cache) {
|
|
const value = uniform.value;
|
|
const indexString = index + "_" + indexArray;
|
|
if (cache[indexString] === undefined) {
|
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
cache[indexString] = value;
|
|
} else {
|
|
cache[indexString] = value.clone();
|
|
}
|
|
return true;
|
|
} else {
|
|
const cachedObject = cache[indexString];
|
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
if (cachedObject !== value) {
|
|
cache[indexString] = value;
|
|
return true;
|
|
}
|
|
} else {
|
|
if (cachedObject.equals(value) === false) {
|
|
cachedObject.copy(value);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
function prepareUniformsGroup(uniformsGroup) {
|
|
const uniforms = uniformsGroup.uniforms;
|
|
let offset = 0;
|
|
const chunkSize = 16;
|
|
for (let i = 0, l = uniforms.length;i < l; i++) {
|
|
const uniformArray = Array.isArray(uniforms[i]) ? uniforms[i] : [uniforms[i]];
|
|
for (let j = 0, jl = uniformArray.length;j < jl; j++) {
|
|
const uniform = uniformArray[j];
|
|
const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value];
|
|
for (let k = 0, kl = values.length;k < kl; k++) {
|
|
const value = values[k];
|
|
const info2 = getUniformSize(value);
|
|
const chunkOffset2 = offset % chunkSize;
|
|
const chunkPadding = chunkOffset2 % info2.boundary;
|
|
const chunkStart = chunkOffset2 + chunkPadding;
|
|
offset += chunkPadding;
|
|
if (chunkStart !== 0 && chunkSize - chunkStart < info2.storage) {
|
|
offset += chunkSize - chunkStart;
|
|
}
|
|
uniform.__data = new Float32Array(info2.storage / Float32Array.BYTES_PER_ELEMENT);
|
|
uniform.__offset = offset;
|
|
offset += info2.storage;
|
|
}
|
|
}
|
|
}
|
|
const chunkOffset = offset % chunkSize;
|
|
if (chunkOffset > 0)
|
|
offset += chunkSize - chunkOffset;
|
|
uniformsGroup.__size = offset;
|
|
uniformsGroup.__cache = {};
|
|
return this;
|
|
}
|
|
function getUniformSize(value) {
|
|
const info2 = {
|
|
boundary: 0,
|
|
storage: 0
|
|
};
|
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
info2.boundary = 4;
|
|
info2.storage = 4;
|
|
} else if (value.isVector2) {
|
|
info2.boundary = 8;
|
|
info2.storage = 8;
|
|
} else if (value.isVector3 || value.isColor) {
|
|
info2.boundary = 16;
|
|
info2.storage = 12;
|
|
} else if (value.isVector4) {
|
|
info2.boundary = 16;
|
|
info2.storage = 16;
|
|
} else if (value.isMatrix3) {
|
|
info2.boundary = 48;
|
|
info2.storage = 48;
|
|
} else if (value.isMatrix4) {
|
|
info2.boundary = 64;
|
|
info2.storage = 64;
|
|
} else if (value.isTexture) {
|
|
console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group.");
|
|
} else {
|
|
console.warn("THREE.WebGLRenderer: Unsupported uniform value type.", value);
|
|
}
|
|
return info2;
|
|
}
|
|
function onUniformsGroupsDispose(event) {
|
|
const uniformsGroup = event.target;
|
|
uniformsGroup.removeEventListener("dispose", onUniformsGroupsDispose);
|
|
const index = allocatedBindingPoints.indexOf(uniformsGroup.__bindingPointIndex);
|
|
allocatedBindingPoints.splice(index, 1);
|
|
gl.deleteBuffer(buffers[uniformsGroup.id]);
|
|
delete buffers[uniformsGroup.id];
|
|
delete updateList[uniformsGroup.id];
|
|
}
|
|
function dispose() {
|
|
for (const id in buffers) {
|
|
gl.deleteBuffer(buffers[id]);
|
|
}
|
|
allocatedBindingPoints = [];
|
|
buffers = {};
|
|
updateList = {};
|
|
}
|
|
return {
|
|
bind,
|
|
update,
|
|
dispose
|
|
};
|
|
}
|
|
|
|
class WebGLRenderer {
|
|
constructor(parameters = {}) {
|
|
const {
|
|
canvas = createCanvasElement(),
|
|
context = null,
|
|
depth = true,
|
|
stencil = false,
|
|
alpha = false,
|
|
antialias = false,
|
|
premultipliedAlpha = true,
|
|
preserveDrawingBuffer = false,
|
|
powerPreference = "default",
|
|
failIfMajorPerformanceCaveat = false,
|
|
reverseDepthBuffer = false,
|
|
multiviewStereo = false
|
|
} = parameters;
|
|
this.isWebGLRenderer = true;
|
|
let _alpha;
|
|
if (context !== null) {
|
|
if (typeof WebGLRenderingContext !== "undefined" && context instanceof WebGLRenderingContext) {
|
|
throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");
|
|
}
|
|
_alpha = context.getContextAttributes().alpha;
|
|
} else {
|
|
_alpha = alpha;
|
|
}
|
|
const uintClearColor = new Uint32Array(4);
|
|
const intClearColor = new Int32Array(4);
|
|
let currentRenderList = null;
|
|
let currentRenderState = null;
|
|
const renderListStack = [];
|
|
const renderStateStack = [];
|
|
this.domElement = canvas;
|
|
this.debug = {
|
|
checkShaderErrors: true,
|
|
onShaderError: null
|
|
};
|
|
this.autoClear = true;
|
|
this.autoClearColor = true;
|
|
this.autoClearDepth = true;
|
|
this.autoClearStencil = true;
|
|
this.sortObjects = true;
|
|
this.clippingPlanes = [];
|
|
this.localClippingEnabled = false;
|
|
this._outputColorSpace = SRGBColorSpace;
|
|
this.toneMapping = NoToneMapping;
|
|
this.toneMappingExposure = 1;
|
|
const _this = this;
|
|
let _isContextLost = false;
|
|
let _currentActiveCubeFace = 0;
|
|
let _currentActiveMipmapLevel = 0;
|
|
let _currentRenderTarget = null;
|
|
let _currentMaterialId = -1;
|
|
let _currentCamera = null;
|
|
const _currentViewport = new Vector4;
|
|
const _currentScissor = new Vector4;
|
|
let _currentScissorTest = null;
|
|
const _currentClearColor = new Color(0);
|
|
let _currentClearAlpha = 0;
|
|
let _width = canvas.width;
|
|
let _height = canvas.height;
|
|
let _pixelRatio = 1;
|
|
let _opaqueSort = null;
|
|
let _transparentSort = null;
|
|
const _viewport = new Vector4(0, 0, _width, _height);
|
|
const _scissor = new Vector4(0, 0, _width, _height);
|
|
let _scissorTest = false;
|
|
const _frustum2 = new Frustum;
|
|
let _clippingEnabled = false;
|
|
let _localClippingEnabled = false;
|
|
this.transmissionResolutionScale = 1;
|
|
const _currentProjectionMatrix = new Matrix4;
|
|
const _projScreenMatrix2 = new Matrix4;
|
|
const _vector32 = new Vector3;
|
|
const _vector4 = new Vector4;
|
|
const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
|
|
let _renderBackground = false;
|
|
function getTargetPixelRatio() {
|
|
return _currentRenderTarget === null ? _pixelRatio : 1;
|
|
}
|
|
let _gl = context;
|
|
function getContext(contextName, contextAttributes) {
|
|
return canvas.getContext(contextName, contextAttributes);
|
|
}
|
|
try {
|
|
const contextAttributes = {
|
|
alpha: true,
|
|
depth,
|
|
stencil,
|
|
antialias,
|
|
premultipliedAlpha,
|
|
preserveDrawingBuffer,
|
|
powerPreference,
|
|
failIfMajorPerformanceCaveat
|
|
};
|
|
if ("setAttribute" in canvas)
|
|
canvas.setAttribute("data-engine", `three.js r${REVISION}`);
|
|
canvas.addEventListener("webglcontextlost", onContextLost, false);
|
|
canvas.addEventListener("webglcontextrestored", onContextRestore, false);
|
|
canvas.addEventListener("webglcontextcreationerror", onContextCreationError, false);
|
|
if (_gl === null) {
|
|
const contextName = "webgl2";
|
|
_gl = getContext(contextName, contextAttributes);
|
|
if (_gl === null) {
|
|
if (getContext(contextName)) {
|
|
throw new Error("Error creating WebGL context with your selected attributes.");
|
|
} else {
|
|
throw new Error("Error creating WebGL context.");
|
|
}
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error("THREE.WebGLRenderer: " + error.message);
|
|
throw error;
|
|
}
|
|
let extensions, capabilities, state, info;
|
|
let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects;
|
|
let programCache, materials, renderLists, renderStates, clipping, shadowMap;
|
|
let multiview;
|
|
let background, morphtargets, bufferRenderer, indexedBufferRenderer;
|
|
let utils, bindingStates, uniformsGroups;
|
|
function initGLContext() {
|
|
extensions = new WebGLExtensions(_gl);
|
|
extensions.init();
|
|
utils = new WebGLUtils(_gl, extensions);
|
|
capabilities = new WebGLCapabilities(_gl, extensions, parameters, utils);
|
|
state = new WebGLState(_gl, extensions);
|
|
if (capabilities.reverseDepthBuffer && reverseDepthBuffer) {
|
|
state.buffers.depth.setReversed(true);
|
|
}
|
|
info = new WebGLInfo(_gl);
|
|
properties = new WebGLProperties;
|
|
textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
|
|
cubemaps = new WebGLCubeMaps(_this);
|
|
cubeuvmaps = new WebGLCubeUVMaps(_this);
|
|
attributes = new WebGLAttributes(_gl);
|
|
bindingStates = new WebGLBindingStates(_gl, attributes);
|
|
geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
|
|
objects = new WebGLObjects(_gl, geometries, attributes, info);
|
|
morphtargets = new WebGLMorphtargets(_gl, capabilities, textures);
|
|
clipping = new WebGLClipping(properties);
|
|
programCache = new WebGLPrograms(_this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping);
|
|
materials = new WebGLMaterials(_this, properties);
|
|
renderLists = new WebGLRenderLists;
|
|
renderStates = new WebGLRenderStates(extensions);
|
|
background = new WebGLBackground(_this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha);
|
|
multiview = new WebGLMultiview(_this, extensions, _gl);
|
|
shadowMap = new WebGLShadowMap(_this, objects, capabilities);
|
|
uniformsGroups = new WebGLUniformsGroups(_gl, info, capabilities, state);
|
|
bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info);
|
|
indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info);
|
|
info.programs = programCache.programs;
|
|
_this.capabilities = capabilities;
|
|
_this.extensions = extensions;
|
|
_this.properties = properties;
|
|
_this.renderLists = renderLists;
|
|
_this.shadowMap = shadowMap;
|
|
_this.state = state;
|
|
_this.info = info;
|
|
}
|
|
initGLContext();
|
|
const xr = new WebXRManager(_this, _gl);
|
|
this.xr = xr;
|
|
this.getContext = function() {
|
|
return _gl;
|
|
};
|
|
this.getContextAttributes = function() {
|
|
return _gl.getContextAttributes();
|
|
};
|
|
this.forceContextLoss = function() {
|
|
const extension = extensions.get("WEBGL_lose_context");
|
|
if (extension)
|
|
extension.loseContext();
|
|
};
|
|
this.forceContextRestore = function() {
|
|
const extension = extensions.get("WEBGL_lose_context");
|
|
if (extension)
|
|
extension.restoreContext();
|
|
};
|
|
this.getPixelRatio = function() {
|
|
return _pixelRatio;
|
|
};
|
|
this.setPixelRatio = function(value) {
|
|
if (value === undefined)
|
|
return;
|
|
_pixelRatio = value;
|
|
this.setSize(_width, _height, false);
|
|
};
|
|
this.getSize = function(target) {
|
|
return target.set(_width, _height);
|
|
};
|
|
this.setSize = function(width, height, updateStyle = true) {
|
|
if (xr.isPresenting) {
|
|
console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");
|
|
return;
|
|
}
|
|
_width = width;
|
|
_height = height;
|
|
canvas.width = Math.floor(width * _pixelRatio);
|
|
canvas.height = Math.floor(height * _pixelRatio);
|
|
if (updateStyle === true) {
|
|
canvas.style.width = width + "px";
|
|
canvas.style.height = height + "px";
|
|
}
|
|
this.setViewport(0, 0, width, height);
|
|
};
|
|
this.getDrawingBufferSize = function(target) {
|
|
return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
|
|
};
|
|
this.setDrawingBufferSize = function(width, height, pixelRatio) {
|
|
_width = width;
|
|
_height = height;
|
|
_pixelRatio = pixelRatio;
|
|
canvas.width = Math.floor(width * pixelRatio);
|
|
canvas.height = Math.floor(height * pixelRatio);
|
|
this.setViewport(0, 0, width, height);
|
|
};
|
|
this.getCurrentViewport = function(target) {
|
|
return target.copy(_currentViewport);
|
|
};
|
|
this.getViewport = function(target) {
|
|
return target.copy(_viewport);
|
|
};
|
|
this.setViewport = function(x, y, width, height) {
|
|
if (x.isVector4) {
|
|
_viewport.set(x.x, x.y, x.z, x.w);
|
|
} else {
|
|
_viewport.set(x, y, width, height);
|
|
}
|
|
state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).round());
|
|
};
|
|
this.getScissor = function(target) {
|
|
return target.copy(_scissor);
|
|
};
|
|
this.setScissor = function(x, y, width, height) {
|
|
if (x.isVector4) {
|
|
_scissor.set(x.x, x.y, x.z, x.w);
|
|
} else {
|
|
_scissor.set(x, y, width, height);
|
|
}
|
|
state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).round());
|
|
};
|
|
this.getScissorTest = function() {
|
|
return _scissorTest;
|
|
};
|
|
this.setScissorTest = function(boolean) {
|
|
state.setScissorTest(_scissorTest = boolean);
|
|
};
|
|
this.setOpaqueSort = function(method) {
|
|
_opaqueSort = method;
|
|
};
|
|
this.setTransparentSort = function(method) {
|
|
_transparentSort = method;
|
|
};
|
|
this.getClearColor = function(target) {
|
|
return target.copy(background.getClearColor());
|
|
};
|
|
this.setClearColor = function() {
|
|
background.setClearColor.apply(background, arguments);
|
|
};
|
|
this.getClearAlpha = function() {
|
|
return background.getClearAlpha();
|
|
};
|
|
this.setClearAlpha = function() {
|
|
background.setClearAlpha.apply(background, arguments);
|
|
};
|
|
this.clear = function(color = true, depth2 = true, stencil2 = true) {
|
|
let bits = 0;
|
|
if (color) {
|
|
let isIntegerFormat = false;
|
|
if (_currentRenderTarget !== null) {
|
|
const targetFormat = _currentRenderTarget.texture.format;
|
|
isIntegerFormat = targetFormat === RGBAIntegerFormat || targetFormat === RGIntegerFormat || targetFormat === RedIntegerFormat;
|
|
}
|
|
if (isIntegerFormat) {
|
|
const targetType = _currentRenderTarget.texture.type;
|
|
const isUnsignedType = targetType === UnsignedByteType || targetType === UnsignedIntType || targetType === UnsignedShortType || targetType === UnsignedInt248Type || targetType === UnsignedShort4444Type || targetType === UnsignedShort5551Type;
|
|
const clearColor = background.getClearColor();
|
|
const a = background.getClearAlpha();
|
|
const r = clearColor.r;
|
|
const g = clearColor.g;
|
|
const b = clearColor.b;
|
|
if (isUnsignedType) {
|
|
uintClearColor[0] = r;
|
|
uintClearColor[1] = g;
|
|
uintClearColor[2] = b;
|
|
uintClearColor[3] = a;
|
|
_gl.clearBufferuiv(_gl.COLOR, 0, uintClearColor);
|
|
} else {
|
|
intClearColor[0] = r;
|
|
intClearColor[1] = g;
|
|
intClearColor[2] = b;
|
|
intClearColor[3] = a;
|
|
_gl.clearBufferiv(_gl.COLOR, 0, intClearColor);
|
|
}
|
|
} else {
|
|
bits |= _gl.COLOR_BUFFER_BIT;
|
|
}
|
|
}
|
|
if (depth2) {
|
|
bits |= _gl.DEPTH_BUFFER_BIT;
|
|
}
|
|
if (stencil2) {
|
|
bits |= _gl.STENCIL_BUFFER_BIT;
|
|
this.state.buffers.stencil.setMask(4294967295);
|
|
}
|
|
_gl.clear(bits);
|
|
};
|
|
this.clearColor = function() {
|
|
this.clear(true, false, false);
|
|
};
|
|
this.clearDepth = function() {
|
|
this.clear(false, true, false);
|
|
};
|
|
this.clearStencil = function() {
|
|
this.clear(false, false, true);
|
|
};
|
|
this.dispose = function() {
|
|
canvas.removeEventListener("webglcontextlost", onContextLost, false);
|
|
canvas.removeEventListener("webglcontextrestored", onContextRestore, false);
|
|
canvas.removeEventListener("webglcontextcreationerror", onContextCreationError, false);
|
|
background.dispose();
|
|
renderLists.dispose();
|
|
renderStates.dispose();
|
|
properties.dispose();
|
|
cubemaps.dispose();
|
|
cubeuvmaps.dispose();
|
|
objects.dispose();
|
|
bindingStates.dispose();
|
|
uniformsGroups.dispose();
|
|
programCache.dispose();
|
|
xr.dispose();
|
|
xr.removeEventListener("sessionstart", onXRSessionStart);
|
|
xr.removeEventListener("sessionend", onXRSessionEnd);
|
|
animation.stop();
|
|
};
|
|
function onContextLost(event) {
|
|
event.preventDefault();
|
|
console.log("THREE.WebGLRenderer: Context Lost.");
|
|
_isContextLost = true;
|
|
}
|
|
function onContextRestore() {
|
|
console.log("THREE.WebGLRenderer: Context Restored.");
|
|
_isContextLost = false;
|
|
const infoAutoReset = info.autoReset;
|
|
const shadowMapEnabled = shadowMap.enabled;
|
|
const shadowMapAutoUpdate = shadowMap.autoUpdate;
|
|
const shadowMapNeedsUpdate = shadowMap.needsUpdate;
|
|
const shadowMapType = shadowMap.type;
|
|
initGLContext();
|
|
info.autoReset = infoAutoReset;
|
|
shadowMap.enabled = shadowMapEnabled;
|
|
shadowMap.autoUpdate = shadowMapAutoUpdate;
|
|
shadowMap.needsUpdate = shadowMapNeedsUpdate;
|
|
shadowMap.type = shadowMapType;
|
|
}
|
|
function onContextCreationError(event) {
|
|
console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ", event.statusMessage);
|
|
}
|
|
function onMaterialDispose(event) {
|
|
const material = event.target;
|
|
material.removeEventListener("dispose", onMaterialDispose);
|
|
deallocateMaterial(material);
|
|
}
|
|
function deallocateMaterial(material) {
|
|
releaseMaterialProgramReferences(material);
|
|
properties.remove(material);
|
|
}
|
|
function releaseMaterialProgramReferences(material) {
|
|
const programs = properties.get(material).programs;
|
|
if (programs !== undefined) {
|
|
programs.forEach(function(program) {
|
|
programCache.releaseProgram(program);
|
|
});
|
|
if (material.isShaderMaterial) {
|
|
programCache.releaseShaderCache(material);
|
|
}
|
|
}
|
|
}
|
|
this.renderBufferDirect = function(camera, scene, geometry, material, object, group) {
|
|
if (scene === null)
|
|
scene = _emptyScene;
|
|
const frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
|
|
const program = setProgram(camera, scene, geometry, material, object);
|
|
state.setMaterial(material, frontFaceCW);
|
|
let index = geometry.index;
|
|
let rangeFactor = 1;
|
|
if (material.wireframe === true) {
|
|
index = geometries.getWireframeAttribute(geometry);
|
|
if (index === undefined)
|
|
return;
|
|
rangeFactor = 2;
|
|
}
|
|
const drawRange = geometry.drawRange;
|
|
const position = geometry.attributes.position;
|
|
let drawStart = drawRange.start * rangeFactor;
|
|
let drawEnd = (drawRange.start + drawRange.count) * rangeFactor;
|
|
if (group !== null) {
|
|
drawStart = Math.max(drawStart, group.start * rangeFactor);
|
|
drawEnd = Math.min(drawEnd, (group.start + group.count) * rangeFactor);
|
|
}
|
|
if (index !== null) {
|
|
drawStart = Math.max(drawStart, 0);
|
|
drawEnd = Math.min(drawEnd, index.count);
|
|
} else if (position !== undefined && position !== null) {
|
|
drawStart = Math.max(drawStart, 0);
|
|
drawEnd = Math.min(drawEnd, position.count);
|
|
}
|
|
const drawCount = drawEnd - drawStart;
|
|
if (drawCount < 0 || drawCount === Infinity)
|
|
return;
|
|
bindingStates.setup(object, material, program, geometry, index);
|
|
let attribute;
|
|
let renderer = bufferRenderer;
|
|
if (index !== null) {
|
|
attribute = attributes.get(index);
|
|
renderer = indexedBufferRenderer;
|
|
renderer.setIndex(attribute);
|
|
}
|
|
if (object.isMesh) {
|
|
if (material.wireframe === true) {
|
|
state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
|
|
renderer.setMode(_gl.LINES);
|
|
} else {
|
|
renderer.setMode(_gl.TRIANGLES);
|
|
}
|
|
} else if (object.isLine) {
|
|
let lineWidth = material.linewidth;
|
|
if (lineWidth === undefined)
|
|
lineWidth = 1;
|
|
state.setLineWidth(lineWidth * getTargetPixelRatio());
|
|
if (object.isLineSegments) {
|
|
renderer.setMode(_gl.LINES);
|
|
} else if (object.isLineLoop) {
|
|
renderer.setMode(_gl.LINE_LOOP);
|
|
} else {
|
|
renderer.setMode(_gl.LINE_STRIP);
|
|
}
|
|
} else if (object.isPoints) {
|
|
renderer.setMode(_gl.POINTS);
|
|
} else if (object.isSprite) {
|
|
renderer.setMode(_gl.TRIANGLES);
|
|
}
|
|
if (object.isBatchedMesh) {
|
|
if (object._multiDrawInstances !== null) {
|
|
renderer.renderMultiDrawInstances(object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances);
|
|
} else {
|
|
if (!extensions.get("WEBGL_multi_draw")) {
|
|
const starts = object._multiDrawStarts;
|
|
const counts = object._multiDrawCounts;
|
|
const drawCount2 = object._multiDrawCount;
|
|
const bytesPerElement = index ? attributes.get(index).bytesPerElement : 1;
|
|
const uniforms = properties.get(material).currentProgram.getUniforms();
|
|
for (let i = 0;i < drawCount2; i++) {
|
|
uniforms.setValue(_gl, "_gl_DrawID", i);
|
|
renderer.render(starts[i] / bytesPerElement, counts[i]);
|
|
}
|
|
} else {
|
|
renderer.renderMultiDraw(object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount);
|
|
}
|
|
}
|
|
} else if (object.isInstancedMesh) {
|
|
renderer.renderInstances(drawStart, drawCount, object.count);
|
|
} else if (geometry.isInstancedBufferGeometry) {
|
|
const maxInstanceCount = geometry._maxInstanceCount !== undefined ? geometry._maxInstanceCount : Infinity;
|
|
const instanceCount = Math.min(geometry.instanceCount, maxInstanceCount);
|
|
renderer.renderInstances(drawStart, drawCount, instanceCount);
|
|
} else {
|
|
renderer.render(drawStart, drawCount);
|
|
}
|
|
};
|
|
function prepareMaterial(material, scene, object) {
|
|
if (material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false) {
|
|
material.side = BackSide;
|
|
material.needsUpdate = true;
|
|
getProgram(material, scene, object);
|
|
material.side = FrontSide;
|
|
material.needsUpdate = true;
|
|
getProgram(material, scene, object);
|
|
material.side = DoubleSide;
|
|
} else {
|
|
getProgram(material, scene, object);
|
|
}
|
|
}
|
|
this.compile = function(scene, camera, targetScene = null) {
|
|
if (targetScene === null)
|
|
targetScene = scene;
|
|
currentRenderState = renderStates.get(targetScene);
|
|
currentRenderState.init(camera);
|
|
renderStateStack.push(currentRenderState);
|
|
targetScene.traverseVisible(function(object) {
|
|
if (object.isLight && object.layers.test(camera.layers)) {
|
|
currentRenderState.pushLight(object);
|
|
if (object.castShadow) {
|
|
currentRenderState.pushShadow(object);
|
|
}
|
|
}
|
|
});
|
|
if (scene !== targetScene) {
|
|
scene.traverseVisible(function(object) {
|
|
if (object.isLight && object.layers.test(camera.layers)) {
|
|
currentRenderState.pushLight(object);
|
|
if (object.castShadow) {
|
|
currentRenderState.pushShadow(object);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
currentRenderState.setupLights();
|
|
const materials2 = new Set;
|
|
scene.traverse(function(object) {
|
|
if (!(object.isMesh || object.isPoints || object.isLine || object.isSprite)) {
|
|
return;
|
|
}
|
|
const material = object.material;
|
|
if (material) {
|
|
if (Array.isArray(material)) {
|
|
for (let i = 0;i < material.length; i++) {
|
|
const material2 = material[i];
|
|
prepareMaterial(material2, targetScene, object);
|
|
materials2.add(material2);
|
|
}
|
|
} else {
|
|
prepareMaterial(material, targetScene, object);
|
|
materials2.add(material);
|
|
}
|
|
}
|
|
});
|
|
renderStateStack.pop();
|
|
currentRenderState = null;
|
|
return materials2;
|
|
};
|
|
this.compileAsync = function(scene, camera, targetScene = null) {
|
|
const materials2 = this.compile(scene, camera, targetScene);
|
|
return new Promise((resolve) => {
|
|
function checkMaterialsReady() {
|
|
materials2.forEach(function(material) {
|
|
const materialProperties = properties.get(material);
|
|
const program = materialProperties.currentProgram;
|
|
if (program.isReady()) {
|
|
materials2.delete(material);
|
|
}
|
|
});
|
|
if (materials2.size === 0) {
|
|
resolve(scene);
|
|
return;
|
|
}
|
|
setTimeout(checkMaterialsReady, 10);
|
|
}
|
|
if (extensions.get("KHR_parallel_shader_compile") !== null) {
|
|
checkMaterialsReady();
|
|
} else {
|
|
setTimeout(checkMaterialsReady, 10);
|
|
}
|
|
});
|
|
};
|
|
let onAnimationFrameCallback = null;
|
|
function onAnimationFrame(time) {
|
|
if (onAnimationFrameCallback)
|
|
onAnimationFrameCallback(time);
|
|
}
|
|
function onXRSessionStart() {
|
|
animation.stop();
|
|
}
|
|
function onXRSessionEnd() {
|
|
animation.start();
|
|
}
|
|
const animation = new WebGLAnimation;
|
|
animation.setAnimationLoop(onAnimationFrame);
|
|
if (typeof self !== "undefined")
|
|
animation.setContext(self);
|
|
this.setAnimationLoop = function(callback) {
|
|
onAnimationFrameCallback = callback;
|
|
xr.setAnimationLoop(callback);
|
|
callback === null ? animation.stop() : animation.start();
|
|
};
|
|
xr.addEventListener("sessionstart", onXRSessionStart);
|
|
xr.addEventListener("sessionend", onXRSessionEnd);
|
|
this.render = function(scene, camera) {
|
|
if (camera !== undefined && camera.isCamera !== true) {
|
|
console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");
|
|
return;
|
|
}
|
|
if (_isContextLost === true)
|
|
return;
|
|
if (scene.matrixWorldAutoUpdate === true)
|
|
scene.updateMatrixWorld();
|
|
if (camera.parent === null && camera.matrixWorldAutoUpdate === true)
|
|
camera.updateMatrixWorld();
|
|
if (xr.enabled === true && xr.isPresenting === true) {
|
|
if (xr.cameraAutoUpdate === true)
|
|
xr.updateCamera(camera);
|
|
camera = xr.getCamera();
|
|
}
|
|
if (scene.isScene === true)
|
|
scene.onBeforeRender(_this, scene, camera, _currentRenderTarget);
|
|
currentRenderState = renderStates.get(scene, renderStateStack.length);
|
|
currentRenderState.init(camera);
|
|
renderStateStack.push(currentRenderState);
|
|
_projScreenMatrix2.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
_frustum2.setFromProjectionMatrix(_projScreenMatrix2);
|
|
_localClippingEnabled = this.localClippingEnabled;
|
|
_clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled);
|
|
currentRenderList = renderLists.get(scene, renderListStack.length);
|
|
currentRenderList.init();
|
|
renderListStack.push(currentRenderList);
|
|
if (xr.enabled === true && xr.isPresenting === true) {
|
|
const depthSensingMesh = _this.xr.getDepthSensingMesh();
|
|
if (depthSensingMesh !== null) {
|
|
projectObject(depthSensingMesh, camera, -Infinity, _this.sortObjects);
|
|
}
|
|
}
|
|
projectObject(scene, camera, 0, _this.sortObjects);
|
|
currentRenderList.finish();
|
|
if (_this.sortObjects === true) {
|
|
currentRenderList.sort(_opaqueSort, _transparentSort);
|
|
}
|
|
_renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
|
|
if (_renderBackground) {
|
|
background.addToRenderList(currentRenderList, scene);
|
|
}
|
|
this.info.render.frame++;
|
|
if (_clippingEnabled === true)
|
|
clipping.beginShadows();
|
|
const shadowsArray = currentRenderState.state.shadowsArray;
|
|
shadowMap.render(shadowsArray, scene, camera);
|
|
if (_clippingEnabled === true)
|
|
clipping.endShadows();
|
|
if (this.info.autoReset === true)
|
|
this.info.reset();
|
|
const opaqueObjects = currentRenderList.opaque;
|
|
const transmissiveObjects = currentRenderList.transmissive;
|
|
currentRenderState.setupLights();
|
|
if (camera.isArrayCamera) {
|
|
const cameras = camera.cameras;
|
|
if (transmissiveObjects.length > 0) {
|
|
for (let i = 0, l = cameras.length;i < l; i++) {
|
|
const camera2 = cameras[i];
|
|
renderTransmissionPass(opaqueObjects, transmissiveObjects, scene, camera2);
|
|
}
|
|
}
|
|
if (_renderBackground)
|
|
background.render(scene);
|
|
if (xr.enabled && xr.isMultiview) {
|
|
textures.setDeferTextureUploads(true);
|
|
renderScene(currentRenderList, scene, camera, camera.cameras[0].viewport);
|
|
} else {
|
|
for (let i = 0, l = cameras.length;i < l; i++) {
|
|
const camera2 = cameras[i];
|
|
renderScene(currentRenderList, scene, camera2, camera2.viewport);
|
|
}
|
|
}
|
|
} else {
|
|
if (transmissiveObjects.length > 0)
|
|
renderTransmissionPass(opaqueObjects, transmissiveObjects, scene, camera);
|
|
if (_renderBackground)
|
|
background.render(scene);
|
|
renderScene(currentRenderList, scene, camera);
|
|
}
|
|
if (_currentRenderTarget !== null && _currentActiveMipmapLevel === 0) {
|
|
textures.updateMultisampleRenderTarget(_currentRenderTarget);
|
|
textures.updateRenderTargetMipmap(_currentRenderTarget);
|
|
}
|
|
if (scene.isScene === true)
|
|
scene.onAfterRender(_this, scene, camera);
|
|
bindingStates.resetDefaultState();
|
|
_currentMaterialId = -1;
|
|
_currentCamera = null;
|
|
renderStateStack.pop();
|
|
if (renderStateStack.length > 0) {
|
|
currentRenderState = renderStateStack[renderStateStack.length - 1];
|
|
if (_clippingEnabled === true)
|
|
clipping.setGlobalState(_this.clippingPlanes, currentRenderState.state.camera);
|
|
} else {
|
|
currentRenderState = null;
|
|
}
|
|
renderListStack.pop();
|
|
if (renderListStack.length > 0) {
|
|
currentRenderList = renderListStack[renderListStack.length - 1];
|
|
} else {
|
|
currentRenderList = null;
|
|
}
|
|
};
|
|
function projectObject(object, camera, groupOrder, sortObjects) {
|
|
if (object.visible === false)
|
|
return;
|
|
const visible = object.layers.test(camera.layers);
|
|
if (visible) {
|
|
if (object.isGroup) {
|
|
groupOrder = object.renderOrder;
|
|
} else if (object.isLOD) {
|
|
if (object.autoUpdate === true)
|
|
object.update(camera);
|
|
} else if (object.isLight) {
|
|
currentRenderState.pushLight(object);
|
|
if (object.castShadow) {
|
|
currentRenderState.pushShadow(object);
|
|
}
|
|
} else if (object.isSprite) {
|
|
if (!object.frustumCulled || _frustum2.intersectsSprite(object)) {
|
|
if (sortObjects) {
|
|
_vector4.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix2);
|
|
}
|
|
const geometry = objects.update(object);
|
|
const material = object.material;
|
|
if (material.visible) {
|
|
currentRenderList.push(object, geometry, material, groupOrder, _vector4.z, null);
|
|
}
|
|
}
|
|
} else if (object.isMesh || object.isLine || object.isPoints) {
|
|
if (!object.frustumCulled || _frustum2.intersectsObject(object)) {
|
|
const geometry = objects.update(object);
|
|
const material = object.material;
|
|
if (sortObjects) {
|
|
if (object.boundingSphere !== undefined) {
|
|
if (object.boundingSphere === null)
|
|
object.computeBoundingSphere();
|
|
_vector4.copy(object.boundingSphere.center);
|
|
} else {
|
|
if (geometry.boundingSphere === null)
|
|
geometry.computeBoundingSphere();
|
|
_vector4.copy(geometry.boundingSphere.center);
|
|
}
|
|
_vector4.applyMatrix4(object.matrixWorld).applyMatrix4(_projScreenMatrix2);
|
|
}
|
|
if (Array.isArray(material)) {
|
|
const groups = geometry.groups;
|
|
for (let i = 0, l = groups.length;i < l; i++) {
|
|
const group = groups[i];
|
|
const groupMaterial = material[group.materialIndex];
|
|
if (groupMaterial && groupMaterial.visible) {
|
|
currentRenderList.push(object, geometry, groupMaterial, groupOrder, _vector4.z, group);
|
|
}
|
|
}
|
|
} else if (material.visible) {
|
|
currentRenderList.push(object, geometry, material, groupOrder, _vector4.z, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const children = object.children;
|
|
for (let i = 0, l = children.length;i < l; i++) {
|
|
projectObject(children[i], camera, groupOrder, sortObjects);
|
|
}
|
|
}
|
|
function renderScene(currentRenderList2, scene, camera, viewport) {
|
|
const opaqueObjects = currentRenderList2.opaque;
|
|
const transmissiveObjects = currentRenderList2.transmissive;
|
|
const transparentObjects = currentRenderList2.transparent;
|
|
currentRenderState.setupLightsView(camera);
|
|
if (_clippingEnabled === true)
|
|
clipping.setGlobalState(_this.clippingPlanes, camera);
|
|
if (viewport)
|
|
state.viewport(_currentViewport.copy(viewport));
|
|
if (opaqueObjects.length > 0)
|
|
renderObjects(opaqueObjects, scene, camera);
|
|
if (transmissiveObjects.length > 0)
|
|
renderObjects(transmissiveObjects, scene, camera);
|
|
if (transparentObjects.length > 0)
|
|
renderObjects(transparentObjects, scene, camera);
|
|
state.buffers.depth.setTest(true);
|
|
state.buffers.depth.setMask(true);
|
|
state.buffers.color.setMask(true);
|
|
state.setPolygonOffset(false);
|
|
}
|
|
function renderTransmissionPass(opaqueObjects, transmissiveObjects, scene, camera) {
|
|
const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
|
|
if (overrideMaterial !== null) {
|
|
return;
|
|
}
|
|
if (currentRenderState.state.transmissionRenderTarget[camera.id] === undefined) {
|
|
currentRenderState.state.transmissionRenderTarget[camera.id] = new WebGLRenderTarget(1, 1, {
|
|
generateMipmaps: true,
|
|
type: extensions.has("EXT_color_buffer_half_float") || extensions.has("EXT_color_buffer_float") ? HalfFloatType : UnsignedByteType,
|
|
minFilter: LinearMipmapLinearFilter,
|
|
samples: 4,
|
|
stencilBuffer: stencil,
|
|
resolveDepthBuffer: false,
|
|
resolveStencilBuffer: false,
|
|
colorSpace: ColorManagement.workingColorSpace
|
|
});
|
|
}
|
|
const transmissionRenderTarget = currentRenderState.state.transmissionRenderTarget[camera.id];
|
|
const activeViewport = camera.viewport || _currentViewport;
|
|
transmissionRenderTarget.setSize(activeViewport.z * _this.transmissionResolutionScale, activeViewport.w * _this.transmissionResolutionScale);
|
|
const currentRenderTarget = _this.getRenderTarget();
|
|
_this.setRenderTarget(transmissionRenderTarget);
|
|
_this.getClearColor(_currentClearColor);
|
|
_currentClearAlpha = _this.getClearAlpha();
|
|
if (_currentClearAlpha < 1)
|
|
_this.setClearColor(16777215, 0.5);
|
|
_this.clear();
|
|
if (_renderBackground)
|
|
background.render(scene);
|
|
const currentToneMapping = _this.toneMapping;
|
|
_this.toneMapping = NoToneMapping;
|
|
const currentCameraViewport = camera.viewport;
|
|
if (camera.viewport !== undefined)
|
|
camera.viewport = undefined;
|
|
currentRenderState.setupLightsView(camera);
|
|
if (_clippingEnabled === true)
|
|
clipping.setGlobalState(_this.clippingPlanes, camera);
|
|
renderObjects(opaqueObjects, scene, camera);
|
|
textures.updateMultisampleRenderTarget(transmissionRenderTarget);
|
|
textures.updateRenderTargetMipmap(transmissionRenderTarget);
|
|
if (extensions.has("WEBGL_multisampled_render_to_texture") === false) {
|
|
let renderTargetNeedsUpdate = false;
|
|
for (let i = 0, l = transmissiveObjects.length;i < l; i++) {
|
|
const renderItem = transmissiveObjects[i];
|
|
const object = renderItem.object;
|
|
const geometry = renderItem.geometry;
|
|
const material = renderItem.material;
|
|
const group = renderItem.group;
|
|
if (material.side === DoubleSide && object.layers.test(camera.layers)) {
|
|
const currentSide = material.side;
|
|
material.side = BackSide;
|
|
material.needsUpdate = true;
|
|
renderObject(object, scene, camera, geometry, material, group);
|
|
material.side = currentSide;
|
|
material.needsUpdate = true;
|
|
renderTargetNeedsUpdate = true;
|
|
}
|
|
}
|
|
if (renderTargetNeedsUpdate === true) {
|
|
textures.updateMultisampleRenderTarget(transmissionRenderTarget);
|
|
textures.updateRenderTargetMipmap(transmissionRenderTarget);
|
|
}
|
|
}
|
|
_this.setRenderTarget(currentRenderTarget);
|
|
_this.setClearColor(_currentClearColor, _currentClearAlpha);
|
|
if (currentCameraViewport !== undefined)
|
|
camera.viewport = currentCameraViewport;
|
|
_this.toneMapping = currentToneMapping;
|
|
}
|
|
function renderObjects(renderList, scene, camera) {
|
|
const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
|
|
for (let i = 0, l = renderList.length;i < l; i++) {
|
|
const renderItem = renderList[i];
|
|
const object = renderItem.object;
|
|
const geometry = renderItem.geometry;
|
|
const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
|
|
const group = renderItem.group;
|
|
if (object.layers.test(camera.layers)) {
|
|
renderObject(object, scene, camera, geometry, material, group);
|
|
}
|
|
}
|
|
}
|
|
function renderObject(object, scene, camera, geometry, material, group) {
|
|
object.onBeforeRender(_this, scene, camera, geometry, material, group);
|
|
object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
|
|
object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
|
|
material.onBeforeRender(_this, scene, camera, geometry, object, group);
|
|
if (material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false) {
|
|
material.side = BackSide;
|
|
material.needsUpdate = true;
|
|
_this.renderBufferDirect(camera, scene, geometry, material, object, group);
|
|
material.side = FrontSide;
|
|
material.needsUpdate = true;
|
|
_this.renderBufferDirect(camera, scene, geometry, material, object, group);
|
|
material.side = DoubleSide;
|
|
} else {
|
|
_this.renderBufferDirect(camera, scene, geometry, material, object, group);
|
|
}
|
|
object.onAfterRender(_this, scene, camera, geometry, material, group);
|
|
}
|
|
function getProgram(material, scene, object) {
|
|
if (scene.isScene !== true)
|
|
scene = _emptyScene;
|
|
const materialProperties = properties.get(material);
|
|
const lights = currentRenderState.state.lights;
|
|
const shadowsArray = currentRenderState.state.shadowsArray;
|
|
const lightsStateVersion = lights.state.version;
|
|
const parameters2 = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
|
|
const programCacheKey = programCache.getProgramCacheKey(parameters2);
|
|
let programs = materialProperties.programs;
|
|
materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
|
|
materialProperties.fog = scene.fog;
|
|
materialProperties.envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || materialProperties.environment);
|
|
materialProperties.envMapRotation = materialProperties.environment !== null && material.envMap === null ? scene.environmentRotation : material.envMapRotation;
|
|
if (programs === undefined) {
|
|
material.addEventListener("dispose", onMaterialDispose);
|
|
programs = new Map;
|
|
materialProperties.programs = programs;
|
|
}
|
|
let program = programs.get(programCacheKey);
|
|
if (program !== undefined) {
|
|
if (materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion) {
|
|
updateCommonMaterialProperties(material, parameters2);
|
|
return program;
|
|
}
|
|
} else {
|
|
parameters2.uniforms = programCache.getUniforms(material);
|
|
material.onBeforeCompile(parameters2, _this);
|
|
program = programCache.acquireProgram(parameters2, programCacheKey);
|
|
programs.set(programCacheKey, program);
|
|
materialProperties.uniforms = parameters2.uniforms;
|
|
}
|
|
const uniforms = materialProperties.uniforms;
|
|
if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
|
|
uniforms.clippingPlanes = clipping.uniform;
|
|
}
|
|
updateCommonMaterialProperties(material, parameters2);
|
|
materialProperties.needsLights = materialNeedsLights(material);
|
|
materialProperties.lightsStateVersion = lightsStateVersion;
|
|
if (materialProperties.needsLights) {
|
|
uniforms.ambientLightColor.value = lights.state.ambient;
|
|
uniforms.lightProbe.value = lights.state.probe;
|
|
uniforms.directionalLights.value = lights.state.directional;
|
|
uniforms.directionalLightShadows.value = lights.state.directionalShadow;
|
|
uniforms.spotLights.value = lights.state.spot;
|
|
uniforms.spotLightShadows.value = lights.state.spotShadow;
|
|
uniforms.rectAreaLights.value = lights.state.rectArea;
|
|
uniforms.ltc_1.value = lights.state.rectAreaLTC1;
|
|
uniforms.ltc_2.value = lights.state.rectAreaLTC2;
|
|
uniforms.pointLights.value = lights.state.point;
|
|
uniforms.pointLightShadows.value = lights.state.pointShadow;
|
|
uniforms.hemisphereLights.value = lights.state.hemi;
|
|
uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
|
|
uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
|
|
uniforms.spotShadowMap.value = lights.state.spotShadowMap;
|
|
uniforms.spotLightMatrix.value = lights.state.spotLightMatrix;
|
|
uniforms.spotLightMap.value = lights.state.spotLightMap;
|
|
uniforms.pointShadowMap.value = lights.state.pointShadowMap;
|
|
uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
|
|
}
|
|
materialProperties.currentProgram = program;
|
|
materialProperties.uniformsList = null;
|
|
return program;
|
|
}
|
|
function getUniformList(materialProperties) {
|
|
if (materialProperties.uniformsList === null) {
|
|
const progUniforms = materialProperties.currentProgram.getUniforms();
|
|
materialProperties.uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, materialProperties.uniforms);
|
|
}
|
|
return materialProperties.uniformsList;
|
|
}
|
|
function updateCommonMaterialProperties(material, parameters2) {
|
|
const materialProperties = properties.get(material);
|
|
materialProperties.outputColorSpace = parameters2.outputColorSpace;
|
|
materialProperties.batching = parameters2.batching;
|
|
materialProperties.batchingColor = parameters2.batchingColor;
|
|
materialProperties.instancing = parameters2.instancing;
|
|
materialProperties.instancingColor = parameters2.instancingColor;
|
|
materialProperties.instancingMorph = parameters2.instancingMorph;
|
|
materialProperties.skinning = parameters2.skinning;
|
|
materialProperties.morphTargets = parameters2.morphTargets;
|
|
materialProperties.morphNormals = parameters2.morphNormals;
|
|
materialProperties.morphColors = parameters2.morphColors;
|
|
materialProperties.morphTargetsCount = parameters2.morphTargetsCount;
|
|
materialProperties.numClippingPlanes = parameters2.numClippingPlanes;
|
|
materialProperties.numIntersection = parameters2.numClipIntersection;
|
|
materialProperties.vertexAlphas = parameters2.vertexAlphas;
|
|
materialProperties.vertexTangents = parameters2.vertexTangents;
|
|
materialProperties.toneMapping = parameters2.toneMapping;
|
|
materialProperties.numMultiviewViews = parameters2.numMultiviewViews;
|
|
}
|
|
function setProgram(camera, scene, geometry, material, object) {
|
|
if (scene.isScene !== true)
|
|
scene = _emptyScene;
|
|
textures.resetTextureUnits();
|
|
const fog = scene.fog;
|
|
const environment = material.isMeshStandardMaterial ? scene.environment : null;
|
|
const colorSpace = _currentRenderTarget === null ? _this.outputColorSpace : _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace;
|
|
const envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || environment);
|
|
const vertexAlphas = material.vertexColors === true && !!geometry.attributes.color && geometry.attributes.color.itemSize === 4;
|
|
const vertexTangents = !!geometry.attributes.tangent && (!!material.normalMap || material.anisotropy > 0);
|
|
const morphTargets = !!geometry.morphAttributes.position;
|
|
const morphNormals = !!geometry.morphAttributes.normal;
|
|
const morphColors = !!geometry.morphAttributes.color;
|
|
let toneMapping = NoToneMapping;
|
|
if (material.toneMapped) {
|
|
if (_currentRenderTarget === null || _currentRenderTarget.isXRRenderTarget === true) {
|
|
toneMapping = _this.toneMapping;
|
|
}
|
|
}
|
|
const numMultiviewViews = _currentRenderTarget && _currentRenderTarget.isWebGLMultiviewRenderTarget ? _currentRenderTarget.numViews : 0;
|
|
const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;
|
|
const morphTargetsCount = morphAttribute !== undefined ? morphAttribute.length : 0;
|
|
const materialProperties = properties.get(material);
|
|
const lights = currentRenderState.state.lights;
|
|
if (_clippingEnabled === true) {
|
|
if (_localClippingEnabled === true || camera !== _currentCamera) {
|
|
const useCache = camera === _currentCamera && material.id === _currentMaterialId;
|
|
clipping.setState(material, camera, useCache);
|
|
}
|
|
}
|
|
let needsProgramChange = false;
|
|
if (material.version === materialProperties.__version) {
|
|
if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.outputColorSpace !== colorSpace) {
|
|
needsProgramChange = true;
|
|
} else if (object.isBatchedMesh && materialProperties.batching === false) {
|
|
needsProgramChange = true;
|
|
} else if (!object.isBatchedMesh && materialProperties.batching === true) {
|
|
needsProgramChange = true;
|
|
} else if (object.isBatchedMesh && materialProperties.batchingColor === true && object.colorTexture === null) {
|
|
needsProgramChange = true;
|
|
} else if (object.isBatchedMesh && materialProperties.batchingColor === false && object.colorTexture !== null) {
|
|
needsProgramChange = true;
|
|
} else if (object.isInstancedMesh && materialProperties.instancing === false) {
|
|
needsProgramChange = true;
|
|
} else if (!object.isInstancedMesh && materialProperties.instancing === true) {
|
|
needsProgramChange = true;
|
|
} else if (object.isSkinnedMesh && materialProperties.skinning === false) {
|
|
needsProgramChange = true;
|
|
} else if (!object.isSkinnedMesh && materialProperties.skinning === true) {
|
|
needsProgramChange = true;
|
|
} else if (object.isInstancedMesh && materialProperties.instancingColor === true && object.instanceColor === null) {
|
|
needsProgramChange = true;
|
|
} else if (object.isInstancedMesh && materialProperties.instancingColor === false && object.instanceColor !== null) {
|
|
needsProgramChange = true;
|
|
} else if (object.isInstancedMesh && materialProperties.instancingMorph === true && object.morphTexture === null) {
|
|
needsProgramChange = true;
|
|
} else if (object.isInstancedMesh && materialProperties.instancingMorph === false && object.morphTexture !== null) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.envMap !== envMap) {
|
|
needsProgramChange = true;
|
|
} else if (material.fog === true && materialProperties.fog !== fog) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.vertexAlphas !== vertexAlphas) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.vertexTangents !== vertexTangents) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.morphTargets !== morphTargets) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.morphNormals !== morphNormals) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.morphColors !== morphColors) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.toneMapping !== toneMapping) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.morphTargetsCount !== morphTargetsCount) {
|
|
needsProgramChange = true;
|
|
} else if (materialProperties.numMultiviewViews !== numMultiviewViews) {
|
|
needsProgramChange = true;
|
|
}
|
|
} else {
|
|
needsProgramChange = true;
|
|
materialProperties.__version = material.version;
|
|
}
|
|
let program = materialProperties.currentProgram;
|
|
if (needsProgramChange === true) {
|
|
program = getProgram(material, scene, object);
|
|
}
|
|
let refreshProgram = false;
|
|
let refreshMaterial = false;
|
|
let refreshLights = false;
|
|
const p_uniforms = program.getUniforms(), m_uniforms = materialProperties.uniforms;
|
|
if (state.useProgram(program.program)) {
|
|
refreshProgram = true;
|
|
refreshMaterial = true;
|
|
refreshLights = true;
|
|
}
|
|
if (material.id !== _currentMaterialId) {
|
|
_currentMaterialId = material.id;
|
|
refreshMaterial = true;
|
|
}
|
|
if (refreshProgram || _currentCamera !== camera) {
|
|
if (program.numMultiviewViews > 0) {
|
|
multiview.updateCameraProjectionMatricesUniform(camera, p_uniforms);
|
|
multiview.updateCameraViewMatricesUniform(camera, p_uniforms);
|
|
} else {
|
|
const reverseDepthBuffer2 = state.buffers.depth.getReversed();
|
|
if (reverseDepthBuffer2) {
|
|
_currentProjectionMatrix.copy(camera.projectionMatrix);
|
|
toNormalizedProjectionMatrix(_currentProjectionMatrix);
|
|
toReversedProjectionMatrix(_currentProjectionMatrix);
|
|
p_uniforms.setValue(_gl, "projectionMatrix", _currentProjectionMatrix);
|
|
} else {
|
|
p_uniforms.setValue(_gl, "projectionMatrix", camera.projectionMatrix);
|
|
}
|
|
p_uniforms.setValue(_gl, "viewMatrix", camera.matrixWorldInverse);
|
|
}
|
|
const uCamPos = p_uniforms.map.cameraPosition;
|
|
if (uCamPos !== undefined) {
|
|
uCamPos.setValue(_gl, _vector32.setFromMatrixPosition(camera.matrixWorld));
|
|
}
|
|
if (capabilities.logarithmicDepthBuffer) {
|
|
p_uniforms.setValue(_gl, "logDepthBufFC", 2 / (Math.log(camera.far + 1) / Math.LN2));
|
|
}
|
|
if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
|
|
p_uniforms.setValue(_gl, "isOrthographic", camera.isOrthographicCamera === true);
|
|
}
|
|
if (_currentCamera !== camera) {
|
|
_currentCamera = camera;
|
|
refreshMaterial = true;
|
|
refreshLights = true;
|
|
}
|
|
}
|
|
if (object.isSkinnedMesh) {
|
|
p_uniforms.setOptional(_gl, object, "bindMatrix");
|
|
p_uniforms.setOptional(_gl, object, "bindMatrixInverse");
|
|
const skeleton = object.skeleton;
|
|
if (skeleton) {
|
|
if (skeleton.boneTexture === null)
|
|
skeleton.computeBoneTexture();
|
|
p_uniforms.setValue(_gl, "boneTexture", skeleton.boneTexture, textures);
|
|
}
|
|
}
|
|
if (object.isBatchedMesh) {
|
|
p_uniforms.setOptional(_gl, object, "batchingTexture");
|
|
p_uniforms.setValue(_gl, "batchingTexture", object._matricesTexture, textures);
|
|
p_uniforms.setOptional(_gl, object, "batchingIdTexture");
|
|
p_uniforms.setValue(_gl, "batchingIdTexture", object._indirectTexture, textures);
|
|
p_uniforms.setOptional(_gl, object, "batchingColorTexture");
|
|
if (object._colorsTexture !== null) {
|
|
p_uniforms.setValue(_gl, "batchingColorTexture", object._colorsTexture, textures);
|
|
}
|
|
}
|
|
const morphAttributes = geometry.morphAttributes;
|
|
if (morphAttributes.position !== undefined || morphAttributes.normal !== undefined || morphAttributes.color !== undefined) {
|
|
morphtargets.update(object, geometry, program);
|
|
}
|
|
if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
|
|
materialProperties.receiveShadow = object.receiveShadow;
|
|
p_uniforms.setValue(_gl, "receiveShadow", object.receiveShadow);
|
|
}
|
|
if (material.isMeshGouraudMaterial && material.envMap !== null) {
|
|
m_uniforms.envMap.value = envMap;
|
|
m_uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap.isRenderTargetTexture === false ? -1 : 1;
|
|
}
|
|
if (material.isMeshStandardMaterial && material.envMap === null && scene.environment !== null) {
|
|
m_uniforms.envMapIntensity.value = scene.environmentIntensity;
|
|
}
|
|
if (refreshMaterial) {
|
|
p_uniforms.setValue(_gl, "toneMappingExposure", _this.toneMappingExposure);
|
|
if (materialProperties.needsLights) {
|
|
markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
|
|
}
|
|
if (fog && material.fog === true) {
|
|
materials.refreshFogUniforms(m_uniforms, fog);
|
|
}
|
|
materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height, currentRenderState.state.transmissionRenderTarget[camera.id]);
|
|
WebGLUniforms.upload(_gl, getUniformList(materialProperties), m_uniforms, textures);
|
|
}
|
|
if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
|
|
WebGLUniforms.upload(_gl, getUniformList(materialProperties), m_uniforms, textures);
|
|
material.uniformsNeedUpdate = false;
|
|
}
|
|
if (material.isSpriteMaterial) {
|
|
p_uniforms.setValue(_gl, "center", object.center);
|
|
}
|
|
if (program.numMultiviewViews > 0) {
|
|
multiview.updateObjectMatricesUniforms(object, camera, p_uniforms);
|
|
} else {
|
|
p_uniforms.setValue(_gl, "modelViewMatrix", object.modelViewMatrix);
|
|
p_uniforms.setValue(_gl, "normalMatrix", object.normalMatrix);
|
|
}
|
|
p_uniforms.setValue(_gl, "modelMatrix", object.matrixWorld);
|
|
if (material.isShaderMaterial || material.isRawShaderMaterial) {
|
|
const groups = material.uniformsGroups;
|
|
for (let i = 0, l = groups.length;i < l; i++) {
|
|
const group = groups[i];
|
|
uniformsGroups.update(group, program);
|
|
uniformsGroups.bind(group, program);
|
|
}
|
|
}
|
|
return program;
|
|
}
|
|
function markUniformsLightsNeedsUpdate(uniforms, value) {
|
|
uniforms.ambientLightColor.needsUpdate = value;
|
|
uniforms.lightProbe.needsUpdate = value;
|
|
uniforms.directionalLights.needsUpdate = value;
|
|
uniforms.directionalLightShadows.needsUpdate = value;
|
|
uniforms.pointLights.needsUpdate = value;
|
|
uniforms.pointLightShadows.needsUpdate = value;
|
|
uniforms.spotLights.needsUpdate = value;
|
|
uniforms.spotLightShadows.needsUpdate = value;
|
|
uniforms.rectAreaLights.needsUpdate = value;
|
|
uniforms.hemisphereLights.needsUpdate = value;
|
|
}
|
|
function materialNeedsLights(material) {
|
|
return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
|
|
}
|
|
this.setTexture2D = function() {
|
|
var warned = false;
|
|
return function setTexture2D(texture, slot) {
|
|
if (texture && texture.isWebGLRenderTarget) {
|
|
if (!warned) {
|
|
console.warn("THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead.");
|
|
warned = true;
|
|
}
|
|
texture = texture.texture;
|
|
}
|
|
textures.setTexture2D(texture, slot);
|
|
};
|
|
}();
|
|
this.getActiveCubeFace = function() {
|
|
return _currentActiveCubeFace;
|
|
};
|
|
this.getActiveMipmapLevel = function() {
|
|
return _currentActiveMipmapLevel;
|
|
};
|
|
this.getRenderTarget = function() {
|
|
return _currentRenderTarget;
|
|
};
|
|
this.setRenderTargetTextures = function(renderTarget, colorTexture, depthTexture) {
|
|
properties.get(renderTarget.texture).__webglTexture = colorTexture;
|
|
properties.get(renderTarget.depthTexture).__webglTexture = depthTexture;
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
renderTargetProperties.__hasExternalTextures = true;
|
|
renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === undefined;
|
|
if (!renderTargetProperties.__autoAllocateDepthBuffer && (!_currentRenderTarget || !_currentRenderTarget.isWebGLMultiviewRenderTarget)) {
|
|
if (extensions.has("WEBGL_multisampled_render_to_texture") === true) {
|
|
console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided");
|
|
renderTargetProperties.__useRenderToTexture = false;
|
|
}
|
|
}
|
|
};
|
|
this.setRenderTargetFramebuffer = function(renderTarget, defaultFramebuffer) {
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
renderTargetProperties.__webglFramebuffer = defaultFramebuffer;
|
|
renderTargetProperties.__useDefaultFramebuffer = defaultFramebuffer === undefined;
|
|
};
|
|
const _scratchFrameBuffer = _gl.createFramebuffer();
|
|
this.setRenderTarget = function(renderTarget, activeCubeFace = 0, activeMipmapLevel = 0) {
|
|
if (renderTarget === null && this.xr.isPresenting) {
|
|
renderTarget = this.xr.getRenderTarget();
|
|
}
|
|
_currentRenderTarget = renderTarget;
|
|
_currentActiveCubeFace = activeCubeFace;
|
|
_currentActiveMipmapLevel = activeMipmapLevel;
|
|
let useDefaultFramebuffer = true;
|
|
let framebuffer = null;
|
|
let isCube = false;
|
|
let isRenderTarget3D = false;
|
|
if (renderTarget) {
|
|
const renderTargetProperties = properties.get(renderTarget);
|
|
if (renderTargetProperties.__useDefaultFramebuffer !== undefined) {
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, null);
|
|
useDefaultFramebuffer = false;
|
|
} else if (renderTargetProperties.__webglFramebuffer === undefined) {
|
|
textures.setupRenderTarget(renderTarget);
|
|
} else if (renderTargetProperties.__hasExternalTextures) {
|
|
textures.rebindTextures(renderTarget, properties.get(renderTarget.texture).__webglTexture, properties.get(renderTarget.depthTexture).__webglTexture);
|
|
} else if (renderTarget.depthBuffer) {
|
|
const depthTexture = renderTarget.depthTexture;
|
|
if (renderTargetProperties.__boundDepthTexture !== depthTexture) {
|
|
if (depthTexture !== null && properties.has(depthTexture) && (renderTarget.width !== depthTexture.image.width || renderTarget.height !== depthTexture.image.height)) {
|
|
throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");
|
|
}
|
|
textures.setupDepthRenderbuffer(renderTarget);
|
|
}
|
|
}
|
|
const texture = renderTarget.texture;
|
|
if (texture.isData3DTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture) {
|
|
isRenderTarget3D = true;
|
|
}
|
|
const __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
|
|
if (renderTarget.isWebGLCubeRenderTarget) {
|
|
if (Array.isArray(__webglFramebuffer[activeCubeFace])) {
|
|
framebuffer = __webglFramebuffer[activeCubeFace][activeMipmapLevel];
|
|
} else {
|
|
framebuffer = __webglFramebuffer[activeCubeFace];
|
|
}
|
|
isCube = true;
|
|
} else if (renderTarget.samples > 0 && textures.useMultisampledRTT(renderTarget) === false) {
|
|
framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
|
|
} else {
|
|
if (Array.isArray(__webglFramebuffer)) {
|
|
framebuffer = __webglFramebuffer[activeMipmapLevel];
|
|
} else {
|
|
framebuffer = __webglFramebuffer;
|
|
}
|
|
}
|
|
_currentViewport.copy(renderTarget.viewport);
|
|
_currentScissor.copy(renderTarget.scissor);
|
|
_currentScissorTest = renderTarget.scissorTest;
|
|
} else {
|
|
_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
|
|
_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
|
|
_currentScissorTest = _scissorTest;
|
|
}
|
|
if (activeMipmapLevel !== 0) {
|
|
framebuffer = _scratchFrameBuffer;
|
|
}
|
|
const framebufferBound = state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
|
|
if (framebufferBound && useDefaultFramebuffer) {
|
|
state.drawBuffers(renderTarget, framebuffer);
|
|
}
|
|
state.viewport(_currentViewport);
|
|
state.scissor(_currentScissor);
|
|
state.setScissorTest(_currentScissorTest);
|
|
if (isCube) {
|
|
const textureProperties = properties.get(renderTarget.texture);
|
|
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
|
|
} else if (isRenderTarget3D) {
|
|
const textureProperties = properties.get(renderTarget.texture);
|
|
const layer = activeCubeFace;
|
|
_gl.framebufferTextureLayer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel, layer);
|
|
} else if (renderTarget !== null && activeMipmapLevel !== 0) {
|
|
const textureProperties = properties.get(renderTarget.texture);
|
|
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, textureProperties.__webglTexture, activeMipmapLevel);
|
|
}
|
|
_currentMaterialId = -1;
|
|
};
|
|
this.readRenderTargetPixels = function(renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
|
|
if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
|
|
console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");
|
|
return;
|
|
}
|
|
let framebuffer = properties.get(renderTarget).__webglFramebuffer;
|
|
if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
|
|
framebuffer = framebuffer[activeCubeFaceIndex];
|
|
}
|
|
if (framebuffer) {
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
|
|
try {
|
|
const texture = renderTarget.texture;
|
|
const textureFormat = texture.format;
|
|
const textureType = texture.type;
|
|
if (!capabilities.textureFormatReadable(textureFormat)) {
|
|
console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");
|
|
return;
|
|
}
|
|
if (!capabilities.textureTypeReadable(textureType)) {
|
|
console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");
|
|
return;
|
|
}
|
|
if (x >= 0 && x <= renderTarget.width - width && (y >= 0 && y <= renderTarget.height - height)) {
|
|
_gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
|
|
}
|
|
} finally {
|
|
const framebuffer2 = _currentRenderTarget !== null ? properties.get(_currentRenderTarget).__webglFramebuffer : null;
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer2);
|
|
}
|
|
}
|
|
};
|
|
this.readRenderTargetPixelsAsync = async function(renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
|
|
if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
|
|
throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");
|
|
}
|
|
let framebuffer = properties.get(renderTarget).__webglFramebuffer;
|
|
if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
|
|
framebuffer = framebuffer[activeCubeFaceIndex];
|
|
}
|
|
if (framebuffer) {
|
|
const texture = renderTarget.texture;
|
|
const textureFormat = texture.format;
|
|
const textureType = texture.type;
|
|
if (!capabilities.textureFormatReadable(textureFormat)) {
|
|
throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");
|
|
}
|
|
if (!capabilities.textureTypeReadable(textureType)) {
|
|
throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");
|
|
}
|
|
if (x >= 0 && x <= renderTarget.width - width && (y >= 0 && y <= renderTarget.height - height)) {
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
|
|
const glBuffer = _gl.createBuffer();
|
|
_gl.bindBuffer(_gl.PIXEL_PACK_BUFFER, glBuffer);
|
|
_gl.bufferData(_gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ);
|
|
_gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), 0);
|
|
const currFramebuffer = _currentRenderTarget !== null ? properties.get(_currentRenderTarget).__webglFramebuffer : null;
|
|
state.bindFramebuffer(_gl.FRAMEBUFFER, currFramebuffer);
|
|
const sync = _gl.fenceSync(_gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
|
|
_gl.flush();
|
|
await probeAsync(_gl, sync, 4);
|
|
_gl.bindBuffer(_gl.PIXEL_PACK_BUFFER, glBuffer);
|
|
_gl.getBufferSubData(_gl.PIXEL_PACK_BUFFER, 0, buffer);
|
|
_gl.deleteBuffer(glBuffer);
|
|
_gl.deleteSync(sync);
|
|
return buffer;
|
|
} else {
|
|
throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.");
|
|
}
|
|
}
|
|
};
|
|
this.copyFramebufferToTexture = function(texture, position = null, level = 0) {
|
|
if (texture.isTexture !== true) {
|
|
warnOnce("WebGLRenderer: copyFramebufferToTexture function signature has changed.");
|
|
position = arguments[0] || null;
|
|
texture = arguments[1];
|
|
}
|
|
const levelScale = Math.pow(2, -level);
|
|
const width = Math.floor(texture.image.width * levelScale);
|
|
const height = Math.floor(texture.image.height * levelScale);
|
|
const x = position !== null ? position.x : 0;
|
|
const y = position !== null ? position.y : 0;
|
|
textures.setTexture2D(texture, 0);
|
|
_gl.copyTexSubImage2D(_gl.TEXTURE_2D, level, 0, 0, x, y, width, height);
|
|
state.unbindTexture();
|
|
};
|
|
const _srcFramebuffer = _gl.createFramebuffer();
|
|
const _dstFramebuffer = _gl.createFramebuffer();
|
|
this.copyTextureToTexture = function(srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = null) {
|
|
if (srcTexture.isTexture !== true) {
|
|
warnOnce("WebGLRenderer: copyTextureToTexture function signature has changed.");
|
|
dstPosition = arguments[0] || null;
|
|
srcTexture = arguments[1];
|
|
dstTexture = arguments[2];
|
|
dstLevel = arguments[3] || 0;
|
|
srcRegion = null;
|
|
}
|
|
if (dstLevel === null) {
|
|
if (srcLevel !== 0) {
|
|
warnOnce("WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels.");
|
|
dstLevel = srcLevel;
|
|
srcLevel = 0;
|
|
} else {
|
|
dstLevel = 0;
|
|
}
|
|
}
|
|
let width, height, depth2, minX, minY, minZ;
|
|
let dstX, dstY, dstZ;
|
|
const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[dstLevel] : srcTexture.image;
|
|
if (srcRegion !== null) {
|
|
width = srcRegion.max.x - srcRegion.min.x;
|
|
height = srcRegion.max.y - srcRegion.min.y;
|
|
depth2 = srcRegion.isBox3 ? srcRegion.max.z - srcRegion.min.z : 1;
|
|
minX = srcRegion.min.x;
|
|
minY = srcRegion.min.y;
|
|
minZ = srcRegion.isBox3 ? srcRegion.min.z : 0;
|
|
} else {
|
|
const levelScale = Math.pow(2, -srcLevel);
|
|
width = Math.floor(image.width * levelScale);
|
|
height = Math.floor(image.height * levelScale);
|
|
if (srcTexture.isDataArrayTexture) {
|
|
depth2 = image.depth;
|
|
} else if (srcTexture.isData3DTexture) {
|
|
depth2 = Math.floor(image.depth * levelScale);
|
|
} else {
|
|
depth2 = 1;
|
|
}
|
|
minX = 0;
|
|
minY = 0;
|
|
minZ = 0;
|
|
}
|
|
if (dstPosition !== null) {
|
|
dstX = dstPosition.x;
|
|
dstY = dstPosition.y;
|
|
dstZ = dstPosition.z;
|
|
} else {
|
|
dstX = 0;
|
|
dstY = 0;
|
|
dstZ = 0;
|
|
}
|
|
const glFormat = utils.convert(dstTexture.format);
|
|
const glType = utils.convert(dstTexture.type);
|
|
let glTarget;
|
|
if (dstTexture.isData3DTexture) {
|
|
textures.setTexture3D(dstTexture, 0);
|
|
glTarget = _gl.TEXTURE_3D;
|
|
} else if (dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture) {
|
|
textures.setTexture2DArray(dstTexture, 0);
|
|
glTarget = _gl.TEXTURE_2D_ARRAY;
|
|
} else {
|
|
textures.setTexture2D(dstTexture, 0);
|
|
glTarget = _gl.TEXTURE_2D;
|
|
}
|
|
_gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY);
|
|
_gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha);
|
|
_gl.pixelStorei(_gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment);
|
|
const currentUnpackRowLen = _gl.getParameter(_gl.UNPACK_ROW_LENGTH);
|
|
const currentUnpackImageHeight = _gl.getParameter(_gl.UNPACK_IMAGE_HEIGHT);
|
|
const currentUnpackSkipPixels = _gl.getParameter(_gl.UNPACK_SKIP_PIXELS);
|
|
const currentUnpackSkipRows = _gl.getParameter(_gl.UNPACK_SKIP_ROWS);
|
|
const currentUnpackSkipImages = _gl.getParameter(_gl.UNPACK_SKIP_IMAGES);
|
|
_gl.pixelStorei(_gl.UNPACK_ROW_LENGTH, image.width);
|
|
_gl.pixelStorei(_gl.UNPACK_IMAGE_HEIGHT, image.height);
|
|
_gl.pixelStorei(_gl.UNPACK_SKIP_PIXELS, minX);
|
|
_gl.pixelStorei(_gl.UNPACK_SKIP_ROWS, minY);
|
|
_gl.pixelStorei(_gl.UNPACK_SKIP_IMAGES, minZ);
|
|
const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture;
|
|
const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture;
|
|
if (srcTexture.isDepthTexture) {
|
|
const srcTextureProperties = properties.get(srcTexture);
|
|
const dstTextureProperties = properties.get(dstTexture);
|
|
const srcRenderTargetProperties = properties.get(srcTextureProperties.__renderTarget);
|
|
const dstRenderTargetProperties = properties.get(dstTextureProperties.__renderTarget);
|
|
state.bindFramebuffer(_gl.READ_FRAMEBUFFER, srcRenderTargetProperties.__webglFramebuffer);
|
|
state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, dstRenderTargetProperties.__webglFramebuffer);
|
|
for (let i = 0;i < depth2; i++) {
|
|
if (isSrc3D) {
|
|
_gl.framebufferTextureLayer(_gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get(srcTexture).__webglTexture, srcLevel, minZ + i);
|
|
_gl.framebufferTextureLayer(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get(dstTexture).__webglTexture, dstLevel, dstZ + i);
|
|
}
|
|
_gl.blitFramebuffer(minX, minY, width, height, dstX, dstY, width, height, _gl.DEPTH_BUFFER_BIT, _gl.NEAREST);
|
|
}
|
|
state.bindFramebuffer(_gl.READ_FRAMEBUFFER, null);
|
|
state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, null);
|
|
} else if (srcLevel !== 0 || srcTexture.isRenderTargetTexture || properties.has(srcTexture)) {
|
|
const srcTextureProperties = properties.get(srcTexture);
|
|
const dstTextureProperties = properties.get(dstTexture);
|
|
state.bindFramebuffer(_gl.READ_FRAMEBUFFER, _srcFramebuffer);
|
|
state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, _dstFramebuffer);
|
|
for (let i = 0;i < depth2; i++) {
|
|
if (isSrc3D) {
|
|
_gl.framebufferTextureLayer(_gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, srcTextureProperties.__webglTexture, srcLevel, minZ + i);
|
|
} else {
|
|
_gl.framebufferTexture2D(_gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, srcTextureProperties.__webglTexture, srcLevel);
|
|
}
|
|
if (isDst3D) {
|
|
_gl.framebufferTextureLayer(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, dstTextureProperties.__webglTexture, dstLevel, dstZ + i);
|
|
} else {
|
|
_gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, dstTextureProperties.__webglTexture, dstLevel);
|
|
}
|
|
if (srcLevel !== 0) {
|
|
_gl.blitFramebuffer(minX, minY, width, height, dstX, dstY, width, height, _gl.COLOR_BUFFER_BIT, _gl.NEAREST);
|
|
} else if (isDst3D) {
|
|
_gl.copyTexSubImage3D(glTarget, dstLevel, dstX, dstY, dstZ + i, minX, minY, width, height);
|
|
} else {
|
|
_gl.copyTexSubImage2D(glTarget, dstLevel, dstX, dstY, minX, minY, width, height);
|
|
}
|
|
}
|
|
state.bindFramebuffer(_gl.READ_FRAMEBUFFER, null);
|
|
state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, null);
|
|
} else {
|
|
if (isDst3D) {
|
|
if (srcTexture.isDataTexture || srcTexture.isData3DTexture) {
|
|
_gl.texSubImage3D(glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth2, glFormat, glType, image.data);
|
|
} else if (dstTexture.isCompressedArrayTexture) {
|
|
_gl.compressedTexSubImage3D(glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth2, glFormat, image.data);
|
|
} else {
|
|
_gl.texSubImage3D(glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth2, glFormat, glType, image);
|
|
}
|
|
} else {
|
|
if (srcTexture.isDataTexture) {
|
|
_gl.texSubImage2D(_gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image.data);
|
|
} else if (srcTexture.isCompressedTexture) {
|
|
_gl.compressedTexSubImage2D(_gl.TEXTURE_2D, dstLevel, dstX, dstY, image.width, image.height, glFormat, image.data);
|
|
} else {
|
|
_gl.texSubImage2D(_gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image);
|
|
}
|
|
}
|
|
}
|
|
_gl.pixelStorei(_gl.UNPACK_ROW_LENGTH, currentUnpackRowLen);
|
|
_gl.pixelStorei(_gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight);
|
|
_gl.pixelStorei(_gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels);
|
|
_gl.pixelStorei(_gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows);
|
|
_gl.pixelStorei(_gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages);
|
|
if (dstLevel === 0 && dstTexture.generateMipmaps) {
|
|
_gl.generateMipmap(glTarget);
|
|
}
|
|
state.unbindTexture();
|
|
};
|
|
this.copyTextureToTexture3D = function(srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0) {
|
|
if (srcTexture.isTexture !== true) {
|
|
warnOnce("WebGLRenderer: copyTextureToTexture3D function signature has changed.");
|
|
srcRegion = arguments[0] || null;
|
|
dstPosition = arguments[1] || null;
|
|
srcTexture = arguments[2];
|
|
dstTexture = arguments[3];
|
|
level = arguments[4] || 0;
|
|
}
|
|
warnOnce('WebGLRenderer: copyTextureToTexture3D function has been deprecated. Use "copyTextureToTexture" instead.');
|
|
return this.copyTextureToTexture(srcTexture, dstTexture, srcRegion, dstPosition, level);
|
|
};
|
|
this.initRenderTarget = function(target) {
|
|
if (properties.get(target).__webglFramebuffer === undefined) {
|
|
textures.setupRenderTarget(target);
|
|
}
|
|
};
|
|
this.initTexture = function(texture) {
|
|
if (texture.isCubeTexture) {
|
|
textures.setTextureCube(texture, 0);
|
|
} else if (texture.isData3DTexture) {
|
|
textures.setTexture3D(texture, 0);
|
|
} else if (texture.isDataArrayTexture || texture.isCompressedArrayTexture) {
|
|
textures.setTexture2DArray(texture, 0);
|
|
} else {
|
|
textures.setTexture2D(texture, 0);
|
|
}
|
|
state.unbindTexture();
|
|
};
|
|
this.resetState = function() {
|
|
_currentActiveCubeFace = 0;
|
|
_currentActiveMipmapLevel = 0;
|
|
_currentRenderTarget = null;
|
|
state.reset();
|
|
bindingStates.reset();
|
|
};
|
|
if (typeof __THREE_DEVTOOLS__ !== "undefined") {
|
|
__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", { detail: this }));
|
|
}
|
|
}
|
|
get coordinateSystem() {
|
|
return WebGLCoordinateSystem;
|
|
}
|
|
get outputColorSpace() {
|
|
return this._outputColorSpace;
|
|
}
|
|
set outputColorSpace(colorSpace) {
|
|
this._outputColorSpace = colorSpace;
|
|
const gl = this.getContext();
|
|
gl.drawingBufferColorspace = ColorManagement._getDrawingBufferColorSpace(colorSpace);
|
|
gl.unpackColorSpace = ColorManagement._getUnpackColorSpace();
|
|
}
|
|
}
|
|
var alphahash_fragment = `#ifdef USE_ALPHAHASH
|
|
if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
|
|
#endif`, alphahash_pars_fragment = `#ifdef USE_ALPHAHASH
|
|
const float ALPHA_HASH_SCALE = 0.05;
|
|
float hash2D( vec2 value ) {
|
|
return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
|
|
}
|
|
float hash3D( vec3 value ) {
|
|
return hash2D( vec2( hash2D( value.xy ), value.z ) );
|
|
}
|
|
float getAlphaHashThreshold( vec3 position ) {
|
|
float maxDeriv = max(
|
|
length( dFdx( position.xyz ) ),
|
|
length( dFdy( position.xyz ) )
|
|
);
|
|
float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
|
|
vec2 pixScales = vec2(
|
|
exp2( floor( log2( pixScale ) ) ),
|
|
exp2( ceil( log2( pixScale ) ) )
|
|
);
|
|
vec2 alpha = vec2(
|
|
hash3D( floor( pixScales.x * position.xyz ) ),
|
|
hash3D( floor( pixScales.y * position.xyz ) )
|
|
);
|
|
float lerpFactor = fract( log2( pixScale ) );
|
|
float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
|
|
float a = min( lerpFactor, 1.0 - lerpFactor );
|
|
vec3 cases = vec3(
|
|
x * x / ( 2.0 * a * ( 1.0 - a ) ),
|
|
( x - 0.5 * a ) / ( 1.0 - a ),
|
|
1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
|
|
);
|
|
float threshold = ( x < ( 1.0 - a ) )
|
|
? ( ( x < a ) ? cases.x : cases.y )
|
|
: cases.z;
|
|
return clamp( threshold , 1.0e-6, 1.0 );
|
|
}
|
|
#endif`, alphamap_fragment = `#ifdef USE_ALPHAMAP
|
|
diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
|
|
#endif`, alphamap_pars_fragment = `#ifdef USE_ALPHAMAP
|
|
uniform sampler2D alphaMap;
|
|
#endif`, alphatest_fragment = `#ifdef USE_ALPHATEST
|
|
#ifdef ALPHA_TO_COVERAGE
|
|
diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
|
|
if ( diffuseColor.a == 0.0 ) discard;
|
|
#else
|
|
if ( diffuseColor.a < alphaTest ) discard;
|
|
#endif
|
|
#endif`, alphatest_pars_fragment = `#ifdef USE_ALPHATEST
|
|
uniform float alphaTest;
|
|
#endif`, aomap_fragment = `#ifdef USE_AOMAP
|
|
float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
|
|
reflectedLight.indirectDiffuse *= ambientOcclusion;
|
|
#if defined( USE_CLEARCOAT )
|
|
clearcoatSpecularIndirect *= ambientOcclusion;
|
|
#endif
|
|
#if defined( USE_SHEEN )
|
|
sheenSpecularIndirect *= ambientOcclusion;
|
|
#endif
|
|
#if defined( USE_ENVMAP ) && defined( STANDARD )
|
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
|
|
#endif
|
|
#endif`, aomap_pars_fragment = `#ifdef USE_AOMAP
|
|
uniform sampler2D aoMap;
|
|
uniform float aoMapIntensity;
|
|
#endif`, batching_pars_vertex = `#ifdef USE_BATCHING
|
|
#if ! defined( GL_ANGLE_multi_draw )
|
|
#define gl_DrawID _gl_DrawID
|
|
uniform int _gl_DrawID;
|
|
#endif
|
|
uniform highp sampler2D batchingTexture;
|
|
uniform highp usampler2D batchingIdTexture;
|
|
mat4 getBatchingMatrix( const in float i ) {
|
|
int size = textureSize( batchingTexture, 0 ).x;
|
|
int j = int( i ) * 4;
|
|
int x = j % size;
|
|
int y = j / size;
|
|
vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
|
|
vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
|
|
vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
|
|
vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
|
|
return mat4( v1, v2, v3, v4 );
|
|
}
|
|
float getIndirectIndex( const in int i ) {
|
|
int size = textureSize( batchingIdTexture, 0 ).x;
|
|
int x = i % size;
|
|
int y = i / size;
|
|
return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );
|
|
}
|
|
#endif
|
|
#ifdef USE_BATCHING_COLOR
|
|
uniform sampler2D batchingColorTexture;
|
|
vec3 getBatchingColor( const in float i ) {
|
|
int size = textureSize( batchingColorTexture, 0 ).x;
|
|
int j = int( i );
|
|
int x = j % size;
|
|
int y = j / size;
|
|
return texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;
|
|
}
|
|
#endif`, batching_vertex = `#ifdef USE_BATCHING
|
|
mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
|
|
#endif`, begin_vertex = `vec3 transformed = vec3( position );
|
|
#ifdef USE_ALPHAHASH
|
|
vPosition = vec3( position );
|
|
#endif`, beginnormal_vertex = `vec3 objectNormal = vec3( normal );
|
|
#ifdef USE_TANGENT
|
|
vec3 objectTangent = vec3( tangent.xyz );
|
|
#endif`, bsdfs = `float G_BlinnPhong_Implicit( ) {
|
|
return 0.25;
|
|
}
|
|
float D_BlinnPhong( const in float shininess, const in float dotNH ) {
|
|
return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
|
|
}
|
|
vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float dotVH = saturate( dot( viewDir, halfDir ) );
|
|
vec3 F = F_Schlick( specularColor, 1.0, dotVH );
|
|
float G = G_BlinnPhong_Implicit( );
|
|
float D = D_BlinnPhong( shininess, dotNH );
|
|
return F * ( G * D );
|
|
} // validated`, iridescence_fragment = `#ifdef USE_IRIDESCENCE
|
|
const mat3 XYZ_TO_REC709 = mat3(
|
|
3.2404542, -0.9692660, 0.0556434,
|
|
-1.5371385, 1.8760108, -0.2040259,
|
|
-0.4985314, 0.0415560, 1.0572252
|
|
);
|
|
vec3 Fresnel0ToIor( vec3 fresnel0 ) {
|
|
vec3 sqrtF0 = sqrt( fresnel0 );
|
|
return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
|
|
}
|
|
vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
|
|
return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
|
|
}
|
|
float IorToFresnel0( float transmittedIor, float incidentIor ) {
|
|
return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
|
|
}
|
|
vec3 evalSensitivity( float OPD, vec3 shift ) {
|
|
float phase = 2.0 * PI * OPD * 1.0e-9;
|
|
vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
|
|
vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
|
|
vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
|
|
vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
|
|
xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );
|
|
xyz /= 1.0685e-7;
|
|
vec3 rgb = XYZ_TO_REC709 * xyz;
|
|
return rgb;
|
|
}
|
|
vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
|
|
vec3 I;
|
|
float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
|
|
float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
|
|
float cosTheta2Sq = 1.0 - sinTheta2Sq;
|
|
if ( cosTheta2Sq < 0.0 ) {
|
|
return vec3( 1.0 );
|
|
}
|
|
float cosTheta2 = sqrt( cosTheta2Sq );
|
|
float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
|
|
float R12 = F_Schlick( R0, 1.0, cosTheta1 );
|
|
float T121 = 1.0 - R12;
|
|
float phi12 = 0.0;
|
|
if ( iridescenceIOR < outsideIOR ) phi12 = PI;
|
|
float phi21 = PI - phi12;
|
|
vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
|
|
vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
|
|
vec3 phi23 = vec3( 0.0 );
|
|
if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
|
|
if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
|
|
if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
|
|
float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
|
|
vec3 phi = vec3( phi21 ) + phi23;
|
|
vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
|
|
vec3 r123 = sqrt( R123 );
|
|
vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
|
|
vec3 C0 = R12 + Rs;
|
|
I = C0;
|
|
vec3 Cm = Rs - T121;
|
|
for ( int m = 1; m <= 2; ++ m ) {
|
|
Cm *= r123;
|
|
vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
|
|
I += Cm * Sm;
|
|
}
|
|
return max( I, vec3( 0.0 ) );
|
|
}
|
|
#endif`, bumpmap_pars_fragment = `#ifdef USE_BUMPMAP
|
|
uniform sampler2D bumpMap;
|
|
uniform float bumpScale;
|
|
vec2 dHdxy_fwd() {
|
|
vec2 dSTdx = dFdx( vBumpMapUv );
|
|
vec2 dSTdy = dFdy( vBumpMapUv );
|
|
float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
|
|
float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
|
|
float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
|
|
return vec2( dBx, dBy );
|
|
}
|
|
vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
|
|
vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
|
|
vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
|
|
vec3 vN = surf_norm;
|
|
vec3 R1 = cross( vSigmaY, vN );
|
|
vec3 R2 = cross( vN, vSigmaX );
|
|
float fDet = dot( vSigmaX, R1 ) * faceDirection;
|
|
vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
|
|
return normalize( abs( fDet ) * surf_norm - vGrad );
|
|
}
|
|
#endif`, clipping_planes_fragment = `#if NUM_CLIPPING_PLANES > 0
|
|
vec4 plane;
|
|
#ifdef ALPHA_TO_COVERAGE
|
|
float distanceToPlane, distanceGradient;
|
|
float clipOpacity = 1.0;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
|
|
plane = clippingPlanes[ i ];
|
|
distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
|
|
distanceGradient = fwidth( distanceToPlane ) / 2.0;
|
|
clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
|
|
if ( clipOpacity == 0.0 ) discard;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
|
|
float unionClipOpacity = 1.0;
|
|
#pragma unroll_loop_start
|
|
for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
|
|
plane = clippingPlanes[ i ];
|
|
distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
|
|
distanceGradient = fwidth( distanceToPlane ) / 2.0;
|
|
unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
|
|
}
|
|
#pragma unroll_loop_end
|
|
clipOpacity *= 1.0 - unionClipOpacity;
|
|
#endif
|
|
diffuseColor.a *= clipOpacity;
|
|
if ( diffuseColor.a == 0.0 ) discard;
|
|
#else
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
|
|
plane = clippingPlanes[ i ];
|
|
if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
|
|
bool clipped = true;
|
|
#pragma unroll_loop_start
|
|
for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
|
|
plane = clippingPlanes[ i ];
|
|
clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
|
|
}
|
|
#pragma unroll_loop_end
|
|
if ( clipped ) discard;
|
|
#endif
|
|
#endif
|
|
#endif`, clipping_planes_pars_fragment = `#if NUM_CLIPPING_PLANES > 0
|
|
varying vec3 vClipPosition;
|
|
uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
|
|
#endif`, clipping_planes_pars_vertex = `#if NUM_CLIPPING_PLANES > 0
|
|
varying vec3 vClipPosition;
|
|
#endif`, clipping_planes_vertex = `#if NUM_CLIPPING_PLANES > 0
|
|
vClipPosition = - mvPosition.xyz;
|
|
#endif`, color_fragment = `#if defined( USE_COLOR_ALPHA )
|
|
diffuseColor *= vColor;
|
|
#elif defined( USE_COLOR )
|
|
diffuseColor.rgb *= vColor;
|
|
#endif`, color_pars_fragment = `#if defined( USE_COLOR_ALPHA )
|
|
varying vec4 vColor;
|
|
#elif defined( USE_COLOR )
|
|
varying vec3 vColor;
|
|
#endif`, color_pars_vertex = `#if defined( USE_COLOR_ALPHA )
|
|
varying vec4 vColor;
|
|
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
|
|
varying vec3 vColor;
|
|
#endif`, color_vertex = `#if defined( USE_COLOR_ALPHA )
|
|
vColor = vec4( 1.0 );
|
|
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
|
|
vColor = vec3( 1.0 );
|
|
#endif
|
|
#ifdef USE_COLOR
|
|
vColor *= color;
|
|
#endif
|
|
#ifdef USE_INSTANCING_COLOR
|
|
vColor.xyz *= instanceColor.xyz;
|
|
#endif
|
|
#ifdef USE_BATCHING_COLOR
|
|
vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );
|
|
vColor.xyz *= batchingColor.xyz;
|
|
#endif`, common = `#define PI 3.141592653589793
|
|
#define PI2 6.283185307179586
|
|
#define PI_HALF 1.5707963267948966
|
|
#define RECIPROCAL_PI 0.3183098861837907
|
|
#define RECIPROCAL_PI2 0.15915494309189535
|
|
#define EPSILON 1e-6
|
|
#ifndef saturate
|
|
#define saturate( a ) clamp( a, 0.0, 1.0 )
|
|
#endif
|
|
#define whiteComplement( a ) ( 1.0 - saturate( a ) )
|
|
float pow2( const in float x ) { return x*x; }
|
|
vec3 pow2( const in vec3 x ) { return x*x; }
|
|
float pow3( const in float x ) { return x*x*x; }
|
|
float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
|
|
float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
|
|
float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
|
|
highp float rand( const in vec2 uv ) {
|
|
const highp float a = 12.9898, b = 78.233, c = 43758.5453;
|
|
highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
|
|
return fract( sin( sn ) * c );
|
|
}
|
|
#ifdef HIGH_PRECISION
|
|
float precisionSafeLength( vec3 v ) { return length( v ); }
|
|
#else
|
|
float precisionSafeLength( vec3 v ) {
|
|
float maxComponent = max3( abs( v ) );
|
|
return length( v / maxComponent ) * maxComponent;
|
|
}
|
|
#endif
|
|
struct IncidentLight {
|
|
vec3 color;
|
|
vec3 direction;
|
|
bool visible;
|
|
};
|
|
struct ReflectedLight {
|
|
vec3 directDiffuse;
|
|
vec3 directSpecular;
|
|
vec3 indirectDiffuse;
|
|
vec3 indirectSpecular;
|
|
};
|
|
#ifdef USE_ALPHAHASH
|
|
varying vec3 vPosition;
|
|
#endif
|
|
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
|
|
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
|
|
}
|
|
vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
|
|
return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
|
|
}
|
|
mat3 transposeMat3( const in mat3 m ) {
|
|
mat3 tmp;
|
|
tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
|
|
tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
|
|
tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
|
|
return tmp;
|
|
}
|
|
bool isPerspectiveMatrix( mat4 m ) {
|
|
return m[ 2 ][ 3 ] == - 1.0;
|
|
}
|
|
vec2 equirectUv( in vec3 dir ) {
|
|
float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
|
|
float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
|
|
return vec2( u, v );
|
|
}
|
|
vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
|
|
return RECIPROCAL_PI * diffuseColor;
|
|
}
|
|
vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
|
|
float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
|
|
return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
|
|
}
|
|
float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
|
|
float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
|
|
return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
|
|
} // validated`, cube_uv_reflection_fragment = `#ifdef ENVMAP_TYPE_CUBE_UV
|
|
#define cubeUV_minMipLevel 4.0
|
|
#define cubeUV_minTileSize 16.0
|
|
float getFace( vec3 direction ) {
|
|
vec3 absDirection = abs( direction );
|
|
float face = - 1.0;
|
|
if ( absDirection.x > absDirection.z ) {
|
|
if ( absDirection.x > absDirection.y )
|
|
face = direction.x > 0.0 ? 0.0 : 3.0;
|
|
else
|
|
face = direction.y > 0.0 ? 1.0 : 4.0;
|
|
} else {
|
|
if ( absDirection.z > absDirection.y )
|
|
face = direction.z > 0.0 ? 2.0 : 5.0;
|
|
else
|
|
face = direction.y > 0.0 ? 1.0 : 4.0;
|
|
}
|
|
return face;
|
|
}
|
|
vec2 getUV( vec3 direction, float face ) {
|
|
vec2 uv;
|
|
if ( face == 0.0 ) {
|
|
uv = vec2( direction.z, direction.y ) / abs( direction.x );
|
|
} else if ( face == 1.0 ) {
|
|
uv = vec2( - direction.x, - direction.z ) / abs( direction.y );
|
|
} else if ( face == 2.0 ) {
|
|
uv = vec2( - direction.x, direction.y ) / abs( direction.z );
|
|
} else if ( face == 3.0 ) {
|
|
uv = vec2( - direction.z, direction.y ) / abs( direction.x );
|
|
} else if ( face == 4.0 ) {
|
|
uv = vec2( - direction.x, direction.z ) / abs( direction.y );
|
|
} else {
|
|
uv = vec2( direction.x, direction.y ) / abs( direction.z );
|
|
}
|
|
return 0.5 * ( uv + 1.0 );
|
|
}
|
|
vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {
|
|
float face = getFace( direction );
|
|
float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );
|
|
mipInt = max( mipInt, cubeUV_minMipLevel );
|
|
float faceSize = exp2( mipInt );
|
|
highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;
|
|
if ( face > 2.0 ) {
|
|
uv.y += faceSize;
|
|
face -= 3.0;
|
|
}
|
|
uv.x += face * faceSize;
|
|
uv.x += filterInt * 3.0 * cubeUV_minTileSize;
|
|
uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );
|
|
uv.x *= CUBEUV_TEXEL_WIDTH;
|
|
uv.y *= CUBEUV_TEXEL_HEIGHT;
|
|
#ifdef texture2DGradEXT
|
|
return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;
|
|
#else
|
|
return texture2D( envMap, uv ).rgb;
|
|
#endif
|
|
}
|
|
#define cubeUV_r0 1.0
|
|
#define cubeUV_m0 - 2.0
|
|
#define cubeUV_r1 0.8
|
|
#define cubeUV_m1 - 1.0
|
|
#define cubeUV_r4 0.4
|
|
#define cubeUV_m4 2.0
|
|
#define cubeUV_r5 0.305
|
|
#define cubeUV_m5 3.0
|
|
#define cubeUV_r6 0.21
|
|
#define cubeUV_m6 4.0
|
|
float roughnessToMip( float roughness ) {
|
|
float mip = 0.0;
|
|
if ( roughness >= cubeUV_r1 ) {
|
|
mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;
|
|
} else if ( roughness >= cubeUV_r4 ) {
|
|
mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;
|
|
} else if ( roughness >= cubeUV_r5 ) {
|
|
mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;
|
|
} else if ( roughness >= cubeUV_r6 ) {
|
|
mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;
|
|
} else {
|
|
mip = - 2.0 * log2( 1.16 * roughness ); }
|
|
return mip;
|
|
}
|
|
vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
|
|
float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
|
|
float mipF = fract( mip );
|
|
float mipInt = floor( mip );
|
|
vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );
|
|
if ( mipF == 0.0 ) {
|
|
return vec4( color0, 1.0 );
|
|
} else {
|
|
vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );
|
|
return vec4( mix( color0, color1, mipF ), 1.0 );
|
|
}
|
|
}
|
|
#endif`, defaultnormal_vertex = `vec3 transformedNormal = objectNormal;
|
|
#ifdef USE_TANGENT
|
|
vec3 transformedTangent = objectTangent;
|
|
#endif
|
|
#ifdef USE_BATCHING
|
|
mat3 bm = mat3( batchingMatrix );
|
|
transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
|
|
transformedNormal = bm * transformedNormal;
|
|
#ifdef USE_TANGENT
|
|
transformedTangent = bm * transformedTangent;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_INSTANCING
|
|
mat3 im = mat3( instanceMatrix );
|
|
transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
|
|
transformedNormal = im * transformedNormal;
|
|
#ifdef USE_TANGENT
|
|
transformedTangent = im * transformedTangent;
|
|
#endif
|
|
#endif
|
|
transformedNormal = normalMatrix * transformedNormal;
|
|
#ifdef FLIP_SIDED
|
|
transformedNormal = - transformedNormal;
|
|
#endif
|
|
#ifdef USE_TANGENT
|
|
transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
|
|
#ifdef FLIP_SIDED
|
|
transformedTangent = - transformedTangent;
|
|
#endif
|
|
#endif`, displacementmap_pars_vertex = `#ifdef USE_DISPLACEMENTMAP
|
|
uniform sampler2D displacementMap;
|
|
uniform float displacementScale;
|
|
uniform float displacementBias;
|
|
#endif`, displacementmap_vertex = `#ifdef USE_DISPLACEMENTMAP
|
|
transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
|
|
#endif`, emissivemap_fragment = `#ifdef USE_EMISSIVEMAP
|
|
vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
|
|
#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
|
|
emissiveColor = sRGBTransferEOTF( emissiveColor );
|
|
#endif
|
|
totalEmissiveRadiance *= emissiveColor.rgb;
|
|
#endif`, emissivemap_pars_fragment = `#ifdef USE_EMISSIVEMAP
|
|
uniform sampler2D emissiveMap;
|
|
#endif`, colorspace_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );", colorspace_pars_fragment = `vec4 LinearTransferOETF( in vec4 value ) {
|
|
return value;
|
|
}
|
|
vec4 sRGBTransferEOTF( in vec4 value ) {
|
|
return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
|
|
}
|
|
vec4 sRGBTransferOETF( in vec4 value ) {
|
|
return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
|
|
}`, envmap_fragment = `#ifdef USE_ENVMAP
|
|
#ifdef ENV_WORLDPOS
|
|
vec3 cameraToFrag;
|
|
if ( isOrthographic ) {
|
|
cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
|
|
} else {
|
|
cameraToFrag = normalize( vWorldPosition - cameraPosition );
|
|
}
|
|
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
#ifdef ENVMAP_MODE_REFLECTION
|
|
vec3 reflectVec = reflect( cameraToFrag, worldNormal );
|
|
#else
|
|
vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
|
|
#endif
|
|
#else
|
|
vec3 reflectVec = vReflect;
|
|
#endif
|
|
#ifdef ENVMAP_TYPE_CUBE
|
|
vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
|
|
#else
|
|
vec4 envColor = vec4( 0.0 );
|
|
#endif
|
|
#ifdef ENVMAP_BLENDING_MULTIPLY
|
|
outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
|
|
#elif defined( ENVMAP_BLENDING_MIX )
|
|
outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
|
|
#elif defined( ENVMAP_BLENDING_ADD )
|
|
outgoingLight += envColor.xyz * specularStrength * reflectivity;
|
|
#endif
|
|
#endif`, envmap_common_pars_fragment = `#ifdef USE_ENVMAP
|
|
uniform float envMapIntensity;
|
|
uniform float flipEnvMap;
|
|
uniform mat3 envMapRotation;
|
|
#ifdef ENVMAP_TYPE_CUBE
|
|
uniform samplerCube envMap;
|
|
#else
|
|
uniform sampler2D envMap;
|
|
#endif
|
|
|
|
#endif`, envmap_pars_fragment = `#ifdef USE_ENVMAP
|
|
uniform float reflectivity;
|
|
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
|
|
#define ENV_WORLDPOS
|
|
#endif
|
|
#ifdef ENV_WORLDPOS
|
|
varying vec3 vWorldPosition;
|
|
uniform float refractionRatio;
|
|
#else
|
|
varying vec3 vReflect;
|
|
#endif
|
|
#endif`, envmap_pars_vertex = `#ifdef USE_ENVMAP
|
|
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
|
|
#define ENV_WORLDPOS
|
|
#endif
|
|
#ifdef ENV_WORLDPOS
|
|
|
|
varying vec3 vWorldPosition;
|
|
#else
|
|
varying vec3 vReflect;
|
|
uniform float refractionRatio;
|
|
#endif
|
|
#endif`, envmap_vertex = `#ifdef USE_ENVMAP
|
|
#ifdef ENV_WORLDPOS
|
|
vWorldPosition = worldPosition.xyz;
|
|
#else
|
|
vec3 cameraToVertex;
|
|
if ( isOrthographic ) {
|
|
cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
|
|
} else {
|
|
cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
|
|
}
|
|
vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
|
|
#ifdef ENVMAP_MODE_REFLECTION
|
|
vReflect = reflect( cameraToVertex, worldNormal );
|
|
#else
|
|
vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
|
|
#endif
|
|
#endif
|
|
#endif`, fog_vertex = `#ifdef USE_FOG
|
|
vFogDepth = - mvPosition.z;
|
|
#endif`, fog_pars_vertex = `#ifdef USE_FOG
|
|
varying float vFogDepth;
|
|
#endif`, fog_fragment = `#ifdef USE_FOG
|
|
#ifdef FOG_EXP2
|
|
float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
|
|
#else
|
|
float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
|
|
#endif
|
|
gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
|
|
#endif`, fog_pars_fragment = `#ifdef USE_FOG
|
|
uniform vec3 fogColor;
|
|
varying float vFogDepth;
|
|
#ifdef FOG_EXP2
|
|
uniform float fogDensity;
|
|
#else
|
|
uniform float fogNear;
|
|
uniform float fogFar;
|
|
#endif
|
|
#endif`, gradientmap_pars_fragment = `#ifdef USE_GRADIENTMAP
|
|
uniform sampler2D gradientMap;
|
|
#endif
|
|
vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
|
|
float dotNL = dot( normal, lightDirection );
|
|
vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
|
|
#ifdef USE_GRADIENTMAP
|
|
return vec3( texture2D( gradientMap, coord ).r );
|
|
#else
|
|
vec2 fw = fwidth( coord ) * 0.5;
|
|
return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
|
|
#endif
|
|
}`, lightmap_pars_fragment = `#ifdef USE_LIGHTMAP
|
|
uniform sampler2D lightMap;
|
|
uniform float lightMapIntensity;
|
|
#endif`, lights_lambert_fragment = `LambertMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;
|
|
material.specularStrength = specularStrength;`, lights_lambert_pars_fragment = `varying vec3 vViewPosition;
|
|
struct LambertMaterial {
|
|
vec3 diffuseColor;
|
|
float specularStrength;
|
|
};
|
|
void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
|
|
float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
|
|
vec3 irradiance = dotNL * directLight.color;
|
|
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
|
|
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
#define RE_Direct RE_Direct_Lambert
|
|
#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`, lights_pars_begin = `uniform bool receiveShadow;
|
|
uniform vec3 ambientLightColor;
|
|
#if defined( USE_LIGHT_PROBES )
|
|
uniform vec3 lightProbe[ 9 ];
|
|
#endif
|
|
vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
|
|
float x = normal.x, y = normal.y, z = normal.z;
|
|
vec3 result = shCoefficients[ 0 ] * 0.886227;
|
|
result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
|
|
result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
|
|
result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
|
|
result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
|
|
result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
|
|
result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
|
|
result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
|
|
result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
|
|
return result;
|
|
}
|
|
vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
|
|
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
|
|
return irradiance;
|
|
}
|
|
vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
|
|
vec3 irradiance = ambientLightColor;
|
|
return irradiance;
|
|
}
|
|
float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
|
|
float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
|
|
if ( cutoffDistance > 0.0 ) {
|
|
distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
|
|
}
|
|
return distanceFalloff;
|
|
}
|
|
float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
|
|
return smoothstep( coneCosine, penumbraCosine, angleCosine );
|
|
}
|
|
#if NUM_DIR_LIGHTS > 0
|
|
struct DirectionalLight {
|
|
vec3 direction;
|
|
vec3 color;
|
|
};
|
|
uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
|
|
void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
|
|
light.color = directionalLight.color;
|
|
light.direction = directionalLight.direction;
|
|
light.visible = true;
|
|
}
|
|
#endif
|
|
#if NUM_POINT_LIGHTS > 0
|
|
struct PointLight {
|
|
vec3 position;
|
|
vec3 color;
|
|
float distance;
|
|
float decay;
|
|
};
|
|
uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
|
|
void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
|
|
vec3 lVector = pointLight.position - geometryPosition;
|
|
light.direction = normalize( lVector );
|
|
float lightDistance = length( lVector );
|
|
light.color = pointLight.color;
|
|
light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
|
|
light.visible = ( light.color != vec3( 0.0 ) );
|
|
}
|
|
#endif
|
|
#if NUM_SPOT_LIGHTS > 0
|
|
struct SpotLight {
|
|
vec3 position;
|
|
vec3 direction;
|
|
vec3 color;
|
|
float distance;
|
|
float decay;
|
|
float coneCos;
|
|
float penumbraCos;
|
|
};
|
|
uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
|
|
void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
|
|
vec3 lVector = spotLight.position - geometryPosition;
|
|
light.direction = normalize( lVector );
|
|
float angleCos = dot( light.direction, spotLight.direction );
|
|
float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
|
|
if ( spotAttenuation > 0.0 ) {
|
|
float lightDistance = length( lVector );
|
|
light.color = spotLight.color * spotAttenuation;
|
|
light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
|
|
light.visible = ( light.color != vec3( 0.0 ) );
|
|
} else {
|
|
light.color = vec3( 0.0 );
|
|
light.visible = false;
|
|
}
|
|
}
|
|
#endif
|
|
#if NUM_RECT_AREA_LIGHTS > 0
|
|
struct RectAreaLight {
|
|
vec3 color;
|
|
vec3 position;
|
|
vec3 halfWidth;
|
|
vec3 halfHeight;
|
|
};
|
|
uniform sampler2D ltc_1; uniform sampler2D ltc_2;
|
|
uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
|
|
#endif
|
|
#if NUM_HEMI_LIGHTS > 0
|
|
struct HemisphereLight {
|
|
vec3 direction;
|
|
vec3 skyColor;
|
|
vec3 groundColor;
|
|
};
|
|
uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
|
|
vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
|
|
float dotNL = dot( normal, hemiLight.direction );
|
|
float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
|
|
vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
|
|
return irradiance;
|
|
}
|
|
#endif`, envmap_physical_pars_fragment = `#ifdef USE_ENVMAP
|
|
vec3 getIBLIrradiance( const in vec3 normal ) {
|
|
#ifdef ENVMAP_TYPE_CUBE_UV
|
|
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );
|
|
return PI * envMapColor.rgb * envMapIntensity;
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
|
|
#ifdef ENVMAP_TYPE_CUBE_UV
|
|
vec3 reflectVec = reflect( - viewDir, normal );
|
|
reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
|
|
reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
|
|
vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
|
|
return envMapColor.rgb * envMapIntensity;
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
#ifdef USE_ANISOTROPY
|
|
vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
|
|
#ifdef ENVMAP_TYPE_CUBE_UV
|
|
vec3 bentNormal = cross( bitangent, viewDir );
|
|
bentNormal = normalize( cross( bentNormal, bitangent ) );
|
|
bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
|
|
return getIBLRadiance( viewDir, bentNormal, roughness );
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
#endif
|
|
#endif`, lights_toon_fragment = `ToonMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;`, lights_toon_pars_fragment = `varying vec3 vViewPosition;
|
|
struct ToonMaterial {
|
|
vec3 diffuseColor;
|
|
};
|
|
void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
|
|
vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
|
|
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
|
|
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
#define RE_Direct RE_Direct_Toon
|
|
#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`, lights_phong_fragment = `BlinnPhongMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;
|
|
material.specularColor = specular;
|
|
material.specularShininess = shininess;
|
|
material.specularStrength = specularStrength;`, lights_phong_pars_fragment = `varying vec3 vViewPosition;
|
|
struct BlinnPhongMaterial {
|
|
vec3 diffuseColor;
|
|
vec3 specularColor;
|
|
float specularShininess;
|
|
float specularStrength;
|
|
};
|
|
void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
|
|
float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
|
|
vec3 irradiance = dotNL * directLight.color;
|
|
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
|
|
}
|
|
void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
|
|
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
#define RE_Direct RE_Direct_BlinnPhong
|
|
#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`, lights_physical_fragment = `PhysicalMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
|
|
vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
|
|
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
|
|
material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;
|
|
material.roughness = min( material.roughness, 1.0 );
|
|
#ifdef IOR
|
|
material.ior = ior;
|
|
#ifdef USE_SPECULAR
|
|
float specularIntensityFactor = specularIntensity;
|
|
vec3 specularColorFactor = specularColor;
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
|
|
#endif
|
|
material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
|
|
#else
|
|
float specularIntensityFactor = 1.0;
|
|
vec3 specularColorFactor = vec3( 1.0 );
|
|
material.specularF90 = 1.0;
|
|
#endif
|
|
material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );
|
|
#else
|
|
material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
|
|
material.specularF90 = 1.0;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
material.clearcoat = clearcoat;
|
|
material.clearcoatRoughness = clearcoatRoughness;
|
|
material.clearcoatF0 = vec3( 0.04 );
|
|
material.clearcoatF90 = 1.0;
|
|
#ifdef USE_CLEARCOATMAP
|
|
material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
|
|
#endif
|
|
material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
|
|
material.clearcoatRoughness += geometryRoughness;
|
|
material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
|
|
#endif
|
|
#ifdef USE_DISPERSION
|
|
material.dispersion = dispersion;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
material.iridescence = iridescence;
|
|
material.iridescenceIOR = iridescenceIOR;
|
|
#ifdef USE_IRIDESCENCEMAP
|
|
material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
|
|
#else
|
|
material.iridescenceThickness = iridescenceThicknessMaximum;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
material.sheenColor = sheenColor;
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
|
|
#endif
|
|
material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_ANISOTROPY
|
|
#ifdef USE_ANISOTROPYMAP
|
|
mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
|
|
vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
|
|
vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
|
|
#else
|
|
vec2 anisotropyV = anisotropyVector;
|
|
#endif
|
|
material.anisotropy = length( anisotropyV );
|
|
if( material.anisotropy == 0.0 ) {
|
|
anisotropyV = vec2( 1.0, 0.0 );
|
|
} else {
|
|
anisotropyV /= material.anisotropy;
|
|
material.anisotropy = saturate( material.anisotropy );
|
|
}
|
|
material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
|
|
material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
|
|
material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
|
|
#endif`, lights_physical_pars_fragment = `struct PhysicalMaterial {
|
|
vec3 diffuseColor;
|
|
float roughness;
|
|
vec3 specularColor;
|
|
float specularF90;
|
|
float dispersion;
|
|
#ifdef USE_CLEARCOAT
|
|
float clearcoat;
|
|
float clearcoatRoughness;
|
|
vec3 clearcoatF0;
|
|
float clearcoatF90;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
float iridescence;
|
|
float iridescenceIOR;
|
|
float iridescenceThickness;
|
|
vec3 iridescenceFresnel;
|
|
vec3 iridescenceF0;
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
vec3 sheenColor;
|
|
float sheenRoughness;
|
|
#endif
|
|
#ifdef IOR
|
|
float ior;
|
|
#endif
|
|
#ifdef USE_TRANSMISSION
|
|
float transmission;
|
|
float transmissionAlpha;
|
|
float thickness;
|
|
float attenuationDistance;
|
|
vec3 attenuationColor;
|
|
#endif
|
|
#ifdef USE_ANISOTROPY
|
|
float anisotropy;
|
|
float alphaT;
|
|
vec3 anisotropyT;
|
|
vec3 anisotropyB;
|
|
#endif
|
|
};
|
|
vec3 clearcoatSpecularDirect = vec3( 0.0 );
|
|
vec3 clearcoatSpecularIndirect = vec3( 0.0 );
|
|
vec3 sheenSpecularDirect = vec3( 0.0 );
|
|
vec3 sheenSpecularIndirect = vec3(0.0 );
|
|
vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
|
|
float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
|
|
float x2 = x * x;
|
|
float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
|
|
return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
|
|
}
|
|
float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
|
|
float a2 = pow2( alpha );
|
|
float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
|
|
float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
|
|
return 0.5 / max( gv + gl, EPSILON );
|
|
}
|
|
float D_GGX( const in float alpha, const in float dotNH ) {
|
|
float a2 = pow2( alpha );
|
|
float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
|
|
return RECIPROCAL_PI * a2 / pow2( denom );
|
|
}
|
|
#ifdef USE_ANISOTROPY
|
|
float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {
|
|
float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
|
|
float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
|
|
float v = 0.5 / ( gv + gl );
|
|
return saturate(v);
|
|
}
|
|
float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
|
|
float a2 = alphaT * alphaB;
|
|
highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
|
|
highp float v2 = dot( v, v );
|
|
float w2 = a2 / v2;
|
|
return RECIPROCAL_PI * a2 * pow2 ( w2 );
|
|
}
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
|
|
vec3 f0 = material.clearcoatF0;
|
|
float f90 = material.clearcoatF90;
|
|
float roughness = material.clearcoatRoughness;
|
|
float alpha = pow2( roughness );
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNL = saturate( dot( normal, lightDir ) );
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float dotVH = saturate( dot( viewDir, halfDir ) );
|
|
vec3 F = F_Schlick( f0, f90, dotVH );
|
|
float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
|
|
float D = D_GGX( alpha, dotNH );
|
|
return F * ( V * D );
|
|
}
|
|
#endif
|
|
vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
|
|
vec3 f0 = material.specularColor;
|
|
float f90 = material.specularF90;
|
|
float roughness = material.roughness;
|
|
float alpha = pow2( roughness );
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNL = saturate( dot( normal, lightDir ) );
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float dotVH = saturate( dot( viewDir, halfDir ) );
|
|
vec3 F = F_Schlick( f0, f90, dotVH );
|
|
#ifdef USE_IRIDESCENCE
|
|
F = mix( F, material.iridescenceFresnel, material.iridescence );
|
|
#endif
|
|
#ifdef USE_ANISOTROPY
|
|
float dotTL = dot( material.anisotropyT, lightDir );
|
|
float dotTV = dot( material.anisotropyT, viewDir );
|
|
float dotTH = dot( material.anisotropyT, halfDir );
|
|
float dotBL = dot( material.anisotropyB, lightDir );
|
|
float dotBV = dot( material.anisotropyB, viewDir );
|
|
float dotBH = dot( material.anisotropyB, halfDir );
|
|
float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
|
|
float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );
|
|
#else
|
|
float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
|
|
float D = D_GGX( alpha, dotNH );
|
|
#endif
|
|
return F * ( V * D );
|
|
}
|
|
vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
|
|
const float LUT_SIZE = 64.0;
|
|
const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
|
|
const float LUT_BIAS = 0.5 / LUT_SIZE;
|
|
float dotNV = saturate( dot( N, V ) );
|
|
vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
|
|
uv = uv * LUT_SCALE + LUT_BIAS;
|
|
return uv;
|
|
}
|
|
float LTC_ClippedSphereFormFactor( const in vec3 f ) {
|
|
float l = length( f );
|
|
return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
|
|
}
|
|
vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
|
|
float x = dot( v1, v2 );
|
|
float y = abs( x );
|
|
float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
|
|
float b = 3.4175940 + ( 4.1616724 + y ) * y;
|
|
float v = a / b;
|
|
float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
|
|
return cross( v1, v2 ) * theta_sintheta;
|
|
}
|
|
vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
|
|
vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
|
|
vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
|
|
vec3 lightNormal = cross( v1, v2 );
|
|
if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
|
|
vec3 T1, T2;
|
|
T1 = normalize( V - N * dot( V, N ) );
|
|
T2 = - cross( N, T1 );
|
|
mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
|
|
vec3 coords[ 4 ];
|
|
coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
|
|
coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
|
|
coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
|
|
coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
|
|
coords[ 0 ] = normalize( coords[ 0 ] );
|
|
coords[ 1 ] = normalize( coords[ 1 ] );
|
|
coords[ 2 ] = normalize( coords[ 2 ] );
|
|
coords[ 3 ] = normalize( coords[ 3 ] );
|
|
vec3 vectorFormFactor = vec3( 0.0 );
|
|
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
|
|
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
|
|
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
|
|
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
|
|
float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
|
|
return vec3( result );
|
|
}
|
|
#if defined( USE_SHEEN )
|
|
float D_Charlie( float roughness, float dotNH ) {
|
|
float alpha = pow2( roughness );
|
|
float invAlpha = 1.0 / alpha;
|
|
float cos2h = dotNH * dotNH;
|
|
float sin2h = max( 1.0 - cos2h, 0.0078125 );
|
|
return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
|
|
}
|
|
float V_Neubelt( float dotNV, float dotNL ) {
|
|
return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
|
|
}
|
|
vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNL = saturate( dot( normal, lightDir ) );
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float D = D_Charlie( sheenRoughness, dotNH );
|
|
float V = V_Neubelt( dotNV, dotNL );
|
|
return sheenColor * ( D * V );
|
|
}
|
|
#endif
|
|
float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float r2 = roughness * roughness;
|
|
float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;
|
|
float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;
|
|
float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );
|
|
return saturate( DG * RECIPROCAL_PI );
|
|
}
|
|
vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
|
|
const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
|
|
vec4 r = roughness * c0 + c1;
|
|
float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
|
|
vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;
|
|
return fab;
|
|
}
|
|
vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
|
|
vec2 fab = DFGApprox( normal, viewDir, roughness );
|
|
return specularColor * fab.x + specularF90 * fab.y;
|
|
}
|
|
#ifdef USE_IRIDESCENCE
|
|
void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
|
|
#else
|
|
void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
|
|
#endif
|
|
vec2 fab = DFGApprox( normal, viewDir, roughness );
|
|
#ifdef USE_IRIDESCENCE
|
|
vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
|
|
#else
|
|
vec3 Fr = specularColor;
|
|
#endif
|
|
vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
|
|
float Ess = fab.x + fab.y;
|
|
float Ems = 1.0 - Ess;
|
|
vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
|
|
singleScatter += FssEss;
|
|
multiScatter += Fms * Ems;
|
|
}
|
|
#if NUM_RECT_AREA_LIGHTS > 0
|
|
void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
|
|
vec3 normal = geometryNormal;
|
|
vec3 viewDir = geometryViewDir;
|
|
vec3 position = geometryPosition;
|
|
vec3 lightPos = rectAreaLight.position;
|
|
vec3 halfWidth = rectAreaLight.halfWidth;
|
|
vec3 halfHeight = rectAreaLight.halfHeight;
|
|
vec3 lightColor = rectAreaLight.color;
|
|
float roughness = material.roughness;
|
|
vec3 rectCoords[ 4 ];
|
|
rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
|
|
rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
|
|
rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
|
|
vec2 uv = LTC_Uv( normal, viewDir, roughness );
|
|
vec4 t1 = texture2D( ltc_1, uv );
|
|
vec4 t2 = texture2D( ltc_2, uv );
|
|
mat3 mInv = mat3(
|
|
vec3( t1.x, 0, t1.y ),
|
|
vec3( 0, 1, 0 ),
|
|
vec3( t1.z, 0, t1.w )
|
|
);
|
|
vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
|
|
reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
|
|
reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
|
|
}
|
|
#endif
|
|
void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
|
|
float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
|
|
vec3 irradiance = dotNL * directLight.color;
|
|
#ifdef USE_CLEARCOAT
|
|
float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
|
|
vec3 ccIrradiance = dotNLcc * directLight.color;
|
|
clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
|
|
#endif
|
|
reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );
|
|
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
|
|
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
|
|
#ifdef USE_CLEARCOAT
|
|
clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
|
|
#endif
|
|
vec3 singleScattering = vec3( 0.0 );
|
|
vec3 multiScattering = vec3( 0.0 );
|
|
vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
|
|
#ifdef USE_IRIDESCENCE
|
|
computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );
|
|
#else
|
|
computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );
|
|
#endif
|
|
vec3 totalScattering = singleScattering + multiScattering;
|
|
vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
reflectedLight.indirectSpecular += radiance * singleScattering;
|
|
reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;
|
|
reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
|
|
}
|
|
#define RE_Direct RE_Direct_Physical
|
|
#define RE_Direct_RectArea RE_Direct_RectArea_Physical
|
|
#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
|
|
#define RE_IndirectSpecular RE_IndirectSpecular_Physical
|
|
float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
|
|
return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
|
|
}`, lights_fragment_begin = `
|
|
vec3 geometryPosition = - vViewPosition;
|
|
vec3 geometryNormal = normal;
|
|
vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
|
|
vec3 geometryClearcoatNormal = vec3( 0.0 );
|
|
#ifdef USE_CLEARCOAT
|
|
geometryClearcoatNormal = clearcoatNormal;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
float dotNVi = saturate( dot( normal, geometryViewDir ) );
|
|
if ( material.iridescenceThickness == 0.0 ) {
|
|
material.iridescence = 0.0;
|
|
} else {
|
|
material.iridescence = saturate( material.iridescence );
|
|
}
|
|
if ( material.iridescence > 0.0 ) {
|
|
material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
|
|
material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );
|
|
}
|
|
#endif
|
|
IncidentLight directLight;
|
|
#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
|
|
PointLight pointLight;
|
|
#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
|
|
PointLightShadow pointLightShadow;
|
|
#endif
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
|
|
pointLight = pointLights[ i ];
|
|
getPointLightInfo( pointLight, geometryPosition, directLight );
|
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
|
|
pointLightShadow = pointLightShadows[ i ];
|
|
directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
|
|
#endif
|
|
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
|
|
SpotLight spotLight;
|
|
vec4 spotColor;
|
|
vec3 spotLightCoord;
|
|
bool inSpotLightMap;
|
|
#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
|
|
SpotLightShadow spotLightShadow;
|
|
#endif
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
|
|
spotLight = spotLights[ i ];
|
|
getSpotLightInfo( spotLight, geometryPosition, directLight );
|
|
#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
|
|
#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
|
|
#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
|
|
#else
|
|
#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
|
|
#endif
|
|
#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
|
|
spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
|
|
inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
|
|
spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
|
|
directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
|
|
#endif
|
|
#undef SPOT_LIGHT_MAP_INDEX
|
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
spotLightShadow = spotLightShadows[ i ];
|
|
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
|
|
#endif
|
|
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
|
|
DirectionalLight directionalLight;
|
|
#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
|
|
DirectionalLightShadow directionalLightShadow;
|
|
#endif
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
|
directionalLight = directionalLights[ i ];
|
|
getDirectionalLightInfo( directionalLight, directLight );
|
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
|
directionalLightShadow = directionalLightShadows[ i ];
|
|
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
#endif
|
|
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
|
|
RectAreaLight rectAreaLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
|
|
rectAreaLight = rectAreaLights[ i ];
|
|
RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if defined( RE_IndirectDiffuse )
|
|
vec3 iblIrradiance = vec3( 0.0 );
|
|
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
|
|
#if defined( USE_LIGHT_PROBES )
|
|
irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
|
|
#endif
|
|
#if ( NUM_HEMI_LIGHTS > 0 )
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
|
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#endif
|
|
#if defined( RE_IndirectSpecular )
|
|
vec3 radiance = vec3( 0.0 );
|
|
vec3 clearcoatRadiance = vec3( 0.0 );
|
|
#endif`, lights_fragment_maps = `#if defined( RE_IndirectDiffuse )
|
|
#ifdef USE_LIGHTMAP
|
|
vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
|
|
vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
|
|
irradiance += lightMapIrradiance;
|
|
#endif
|
|
#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
|
|
iblIrradiance += getIBLIrradiance( geometryNormal );
|
|
#endif
|
|
#endif
|
|
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
#ifdef USE_ANISOTROPY
|
|
radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
|
|
#else
|
|
radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
|
|
#endif
|
|
#endif`, lights_fragment_end = `#if defined( RE_IndirectDiffuse )
|
|
RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
#endif
|
|
#if defined( RE_IndirectSpecular )
|
|
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
#endif`, logdepthbuf_fragment = `#if defined( USE_LOGDEPTHBUF )
|
|
gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
|
|
#endif`, logdepthbuf_pars_fragment = `#if defined( USE_LOGDEPTHBUF )
|
|
uniform float logDepthBufFC;
|
|
varying float vFragDepth;
|
|
varying float vIsPerspective;
|
|
#endif`, logdepthbuf_pars_vertex = `#ifdef USE_LOGDEPTHBUF
|
|
varying float vFragDepth;
|
|
varying float vIsPerspective;
|
|
#endif`, logdepthbuf_vertex = `#ifdef USE_LOGDEPTHBUF
|
|
vFragDepth = 1.0 + gl_Position.w;
|
|
vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
|
|
#endif`, map_fragment = `#ifdef USE_MAP
|
|
vec4 sampledDiffuseColor = texture2D( map, vMapUv );
|
|
#ifdef DECODE_VIDEO_TEXTURE
|
|
sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
|
|
#endif
|
|
diffuseColor *= sampledDiffuseColor;
|
|
#endif`, map_pars_fragment = `#ifdef USE_MAP
|
|
uniform sampler2D map;
|
|
#endif`, map_particle_fragment = `#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
|
|
#if defined( USE_POINTS_UV )
|
|
vec2 uv = vUv;
|
|
#else
|
|
vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_MAP
|
|
diffuseColor *= texture2D( map, uv );
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
diffuseColor.a *= texture2D( alphaMap, uv ).g;
|
|
#endif`, map_particle_pars_fragment = `#if defined( USE_POINTS_UV )
|
|
varying vec2 vUv;
|
|
#else
|
|
#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
|
|
uniform mat3 uvTransform;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_MAP
|
|
uniform sampler2D map;
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
uniform sampler2D alphaMap;
|
|
#endif`, metalnessmap_fragment = `float metalnessFactor = metalness;
|
|
#ifdef USE_METALNESSMAP
|
|
vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
|
|
metalnessFactor *= texelMetalness.b;
|
|
#endif`, metalnessmap_pars_fragment = `#ifdef USE_METALNESSMAP
|
|
uniform sampler2D metalnessMap;
|
|
#endif`, morphinstance_vertex = `#ifdef USE_INSTANCING_MORPH
|
|
float morphTargetInfluences[ MORPHTARGETS_COUNT ];
|
|
float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
|
|
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
|
|
morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
|
|
}
|
|
#endif`, morphcolor_vertex = `#if defined( USE_MORPHCOLORS )
|
|
vColor *= morphTargetBaseInfluence;
|
|
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
|
|
#if defined( USE_COLOR_ALPHA )
|
|
if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
|
|
#elif defined( USE_COLOR )
|
|
if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
|
|
#endif
|
|
}
|
|
#endif`, morphnormal_vertex = `#ifdef USE_MORPHNORMALS
|
|
objectNormal *= morphTargetBaseInfluence;
|
|
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
|
|
if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
|
|
}
|
|
#endif`, morphtarget_pars_vertex = `#ifdef USE_MORPHTARGETS
|
|
#ifndef USE_INSTANCING_MORPH
|
|
uniform float morphTargetBaseInfluence;
|
|
uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
|
|
#endif
|
|
uniform sampler2DArray morphTargetsTexture;
|
|
uniform ivec2 morphTargetsTextureSize;
|
|
vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
|
|
int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
|
|
int y = texelIndex / morphTargetsTextureSize.x;
|
|
int x = texelIndex - y * morphTargetsTextureSize.x;
|
|
ivec3 morphUV = ivec3( x, y, morphTargetIndex );
|
|
return texelFetch( morphTargetsTexture, morphUV, 0 );
|
|
}
|
|
#endif`, morphtarget_vertex = `#ifdef USE_MORPHTARGETS
|
|
transformed *= morphTargetBaseInfluence;
|
|
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
|
|
if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
|
|
}
|
|
#endif`, normal_fragment_begin = `float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
|
|
#ifdef FLAT_SHADED
|
|
vec3 fdx = dFdx( vViewPosition );
|
|
vec3 fdy = dFdy( vViewPosition );
|
|
vec3 normal = normalize( cross( fdx, fdy ) );
|
|
#else
|
|
vec3 normal = normalize( vNormal );
|
|
#ifdef DOUBLE_SIDED
|
|
normal *= faceDirection;
|
|
#endif
|
|
#endif
|
|
#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
|
|
#ifdef USE_TANGENT
|
|
mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
|
|
#else
|
|
mat3 tbn = getTangentFrame( - vViewPosition, normal,
|
|
#if defined( USE_NORMALMAP )
|
|
vNormalMapUv
|
|
#elif defined( USE_CLEARCOAT_NORMALMAP )
|
|
vClearcoatNormalMapUv
|
|
#else
|
|
vUv
|
|
#endif
|
|
);
|
|
#endif
|
|
#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
|
|
tbn[0] *= faceDirection;
|
|
tbn[1] *= faceDirection;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
#ifdef USE_TANGENT
|
|
mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
|
|
#else
|
|
mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
|
|
#endif
|
|
#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
|
|
tbn2[0] *= faceDirection;
|
|
tbn2[1] *= faceDirection;
|
|
#endif
|
|
#endif
|
|
vec3 nonPerturbedNormal = normal;`, normal_fragment_maps = `#ifdef USE_NORMALMAP_OBJECTSPACE
|
|
normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
|
|
#ifdef FLIP_SIDED
|
|
normal = - normal;
|
|
#endif
|
|
#ifdef DOUBLE_SIDED
|
|
normal = normal * faceDirection;
|
|
#endif
|
|
normal = normalize( normalMatrix * normal );
|
|
#elif defined( USE_NORMALMAP_TANGENTSPACE )
|
|
vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
|
|
mapN.xy *= normalScale;
|
|
normal = normalize( tbn * mapN );
|
|
#elif defined( USE_BUMPMAP )
|
|
normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
|
|
#endif`, normal_pars_fragment = `#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#ifdef USE_TANGENT
|
|
varying vec3 vTangent;
|
|
varying vec3 vBitangent;
|
|
#endif
|
|
#endif`, normal_pars_vertex = `#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#ifdef USE_TANGENT
|
|
varying vec3 vTangent;
|
|
varying vec3 vBitangent;
|
|
#endif
|
|
#endif`, normal_vertex = `#ifndef FLAT_SHADED
|
|
vNormal = normalize( transformedNormal );
|
|
#ifdef USE_TANGENT
|
|
vTangent = normalize( transformedTangent );
|
|
vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
|
|
#endif
|
|
#endif`, normalmap_pars_fragment = `#ifdef USE_NORMALMAP
|
|
uniform sampler2D normalMap;
|
|
uniform vec2 normalScale;
|
|
#endif
|
|
#ifdef USE_NORMALMAP_OBJECTSPACE
|
|
uniform mat3 normalMatrix;
|
|
#endif
|
|
#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
|
|
mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
|
|
vec3 q0 = dFdx( eye_pos.xyz );
|
|
vec3 q1 = dFdy( eye_pos.xyz );
|
|
vec2 st0 = dFdx( uv.st );
|
|
vec2 st1 = dFdy( uv.st );
|
|
vec3 N = surf_norm;
|
|
vec3 q1perp = cross( q1, N );
|
|
vec3 q0perp = cross( N, q0 );
|
|
vec3 T = q1perp * st0.x + q0perp * st1.x;
|
|
vec3 B = q1perp * st0.y + q0perp * st1.y;
|
|
float det = max( dot( T, T ), dot( B, B ) );
|
|
float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
|
|
return mat3( T * scale, B * scale, N );
|
|
}
|
|
#endif`, clearcoat_normal_fragment_begin = `#ifdef USE_CLEARCOAT
|
|
vec3 clearcoatNormal = nonPerturbedNormal;
|
|
#endif`, clearcoat_normal_fragment_maps = `#ifdef USE_CLEARCOAT_NORMALMAP
|
|
vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
|
|
clearcoatMapN.xy *= clearcoatNormalScale;
|
|
clearcoatNormal = normalize( tbn2 * clearcoatMapN );
|
|
#endif`, clearcoat_pars_fragment = `#ifdef USE_CLEARCOATMAP
|
|
uniform sampler2D clearcoatMap;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
uniform sampler2D clearcoatNormalMap;
|
|
uniform vec2 clearcoatNormalScale;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
uniform sampler2D clearcoatRoughnessMap;
|
|
#endif`, iridescence_pars_fragment = `#ifdef USE_IRIDESCENCEMAP
|
|
uniform sampler2D iridescenceMap;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
uniform sampler2D iridescenceThicknessMap;
|
|
#endif`, opaque_fragment = `#ifdef OPAQUE
|
|
diffuseColor.a = 1.0;
|
|
#endif
|
|
#ifdef USE_TRANSMISSION
|
|
diffuseColor.a *= material.transmissionAlpha;
|
|
#endif
|
|
gl_FragColor = vec4( outgoingLight, diffuseColor.a );`, packing = `vec3 packNormalToRGB( const in vec3 normal ) {
|
|
return normalize( normal ) * 0.5 + 0.5;
|
|
}
|
|
vec3 unpackRGBToNormal( const in vec3 rgb ) {
|
|
return 2.0 * rgb.xyz - 1.0;
|
|
}
|
|
const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;
|
|
const float Inv255 = 1. / 255.;
|
|
const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );
|
|
const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );
|
|
const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );
|
|
const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );
|
|
vec4 packDepthToRGBA( const in float v ) {
|
|
if( v <= 0.0 )
|
|
return vec4( 0., 0., 0., 0. );
|
|
if( v >= 1.0 )
|
|
return vec4( 1., 1., 1., 1. );
|
|
float vuf;
|
|
float af = modf( v * PackFactors.a, vuf );
|
|
float bf = modf( vuf * ShiftRight8, vuf );
|
|
float gf = modf( vuf * ShiftRight8, vuf );
|
|
return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );
|
|
}
|
|
vec3 packDepthToRGB( const in float v ) {
|
|
if( v <= 0.0 )
|
|
return vec3( 0., 0., 0. );
|
|
if( v >= 1.0 )
|
|
return vec3( 1., 1., 1. );
|
|
float vuf;
|
|
float bf = modf( v * PackFactors.b, vuf );
|
|
float gf = modf( vuf * ShiftRight8, vuf );
|
|
return vec3( vuf * Inv255, gf * PackUpscale, bf );
|
|
}
|
|
vec2 packDepthToRG( const in float v ) {
|
|
if( v <= 0.0 )
|
|
return vec2( 0., 0. );
|
|
if( v >= 1.0 )
|
|
return vec2( 1., 1. );
|
|
float vuf;
|
|
float gf = modf( v * 256., vuf );
|
|
return vec2( vuf * Inv255, gf );
|
|
}
|
|
float unpackRGBAToDepth( const in vec4 v ) {
|
|
return dot( v, UnpackFactors4 );
|
|
}
|
|
float unpackRGBToDepth( const in vec3 v ) {
|
|
return dot( v, UnpackFactors3 );
|
|
}
|
|
float unpackRGToDepth( const in vec2 v ) {
|
|
return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;
|
|
}
|
|
vec4 pack2HalfToRGBA( const in vec2 v ) {
|
|
vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
|
|
return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
|
|
}
|
|
vec2 unpackRGBATo2Half( const in vec4 v ) {
|
|
return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
|
|
}
|
|
float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
|
|
return ( viewZ + near ) / ( near - far );
|
|
}
|
|
float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
|
|
return depth * ( near - far ) - near;
|
|
}
|
|
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
|
|
return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
|
|
}
|
|
float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
|
|
return ( near * far ) / ( ( far - near ) * depth - far );
|
|
}`, premultiplied_alpha_fragment = `#ifdef PREMULTIPLIED_ALPHA
|
|
gl_FragColor.rgb *= gl_FragColor.a;
|
|
#endif`, project_vertex = `vec4 mvPosition = vec4( transformed, 1.0 );
|
|
#ifdef USE_BATCHING
|
|
mvPosition = batchingMatrix * mvPosition;
|
|
#endif
|
|
#ifdef USE_INSTANCING
|
|
mvPosition = instanceMatrix * mvPosition;
|
|
#endif
|
|
mvPosition = modelViewMatrix * mvPosition;
|
|
gl_Position = projectionMatrix * mvPosition;`, dithering_fragment = `#ifdef DITHERING
|
|
gl_FragColor.rgb = dithering( gl_FragColor.rgb );
|
|
#endif`, dithering_pars_fragment = `#ifdef DITHERING
|
|
vec3 dithering( vec3 color ) {
|
|
float grid_position = rand( gl_FragCoord.xy );
|
|
vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
|
|
dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
|
|
return color + dither_shift_RGB;
|
|
}
|
|
#endif`, roughnessmap_fragment = `float roughnessFactor = roughness;
|
|
#ifdef USE_ROUGHNESSMAP
|
|
vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
|
|
roughnessFactor *= texelRoughness.g;
|
|
#endif`, roughnessmap_pars_fragment = `#ifdef USE_ROUGHNESSMAP
|
|
uniform sampler2D roughnessMap;
|
|
#endif`, shadowmap_pars_fragment = `#if NUM_SPOT_LIGHT_COORDS > 0
|
|
varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_MAPS > 0
|
|
uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
|
|
#endif
|
|
#ifdef USE_SHADOWMAP
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
|
|
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
|
|
struct DirectionalLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_SHADOWS > 0
|
|
uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
struct SpotLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
|
|
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
|
|
struct PointLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
float shadowCameraNear;
|
|
float shadowCameraFar;
|
|
};
|
|
uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
|
|
#endif
|
|
float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
|
|
return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
|
|
}
|
|
vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
|
|
return unpackRGBATo2Half( texture2D( shadow, uv ) );
|
|
}
|
|
float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
|
|
float occlusion = 1.0;
|
|
vec2 distribution = texture2DDistribution( shadow, uv );
|
|
float hard_shadow = step( compare , distribution.x );
|
|
if (hard_shadow != 1.0 ) {
|
|
float distance = compare - distribution.x ;
|
|
float variance = max( 0.00000, distribution.y * distribution.y );
|
|
float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );
|
|
}
|
|
return occlusion;
|
|
}
|
|
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
|
|
float shadow = 1.0;
|
|
shadowCoord.xyz /= shadowCoord.w;
|
|
shadowCoord.z += shadowBias;
|
|
bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
|
|
bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
|
|
if ( frustumTest ) {
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
|
|
float dx0 = - texelSize.x * shadowRadius;
|
|
float dy0 = - texelSize.y * shadowRadius;
|
|
float dx1 = + texelSize.x * shadowRadius;
|
|
float dy1 = + texelSize.y * shadowRadius;
|
|
float dx2 = dx0 / 2.0;
|
|
float dy2 = dy0 / 2.0;
|
|
float dx3 = dx1 / 2.0;
|
|
float dy3 = dy1 / 2.0;
|
|
shadow = (
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
|
|
) * ( 1.0 / 17.0 );
|
|
#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
|
|
vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
|
|
float dx = texelSize.x;
|
|
float dy = texelSize.y;
|
|
vec2 uv = shadowCoord.xy;
|
|
vec2 f = fract( uv * shadowMapSize + 0.5 );
|
|
uv -= f * texelSize;
|
|
shadow = (
|
|
texture2DCompare( shadowMap, uv, shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
|
|
texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
|
|
mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
|
|
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
|
|
f.x ) +
|
|
mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
|
|
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
|
|
f.x ) +
|
|
mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
|
|
texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
|
|
f.y ) +
|
|
mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
|
|
texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
|
|
f.y ) +
|
|
mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
|
|
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
|
|
f.x ),
|
|
mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
|
|
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
|
|
f.x ),
|
|
f.y )
|
|
) * ( 1.0 / 9.0 );
|
|
#elif defined( SHADOWMAP_TYPE_VSM )
|
|
shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
|
|
#else
|
|
shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
|
|
#endif
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
vec2 cubeToUV( vec3 v, float texelSizeY ) {
|
|
vec3 absV = abs( v );
|
|
float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
|
|
absV *= scaleToCube;
|
|
v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
|
|
vec2 planar = v.xy;
|
|
float almostATexel = 1.5 * texelSizeY;
|
|
float almostOne = 1.0 - almostATexel;
|
|
if ( absV.z >= almostOne ) {
|
|
if ( v.z > 0.0 )
|
|
planar.x = 4.0 - v.x;
|
|
} else if ( absV.x >= almostOne ) {
|
|
float signX = sign( v.x );
|
|
planar.x = v.z * signX + 2.0 * signX;
|
|
} else if ( absV.y >= almostOne ) {
|
|
float signY = sign( v.y );
|
|
planar.x = v.x + 2.0 * signY + 2.0;
|
|
planar.y = v.z * signY - 2.0;
|
|
}
|
|
return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
|
|
}
|
|
float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
|
|
float shadow = 1.0;
|
|
vec3 lightToPosition = shadowCoord.xyz;
|
|
|
|
float lightToPositionLength = length( lightToPosition );
|
|
if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {
|
|
float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias;
|
|
vec3 bd3D = normalize( lightToPosition );
|
|
vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
|
|
#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
|
|
vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
|
|
shadow = (
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
|
|
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
|
|
) * ( 1.0 / 9.0 );
|
|
#else
|
|
shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
|
|
#endif
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#endif`, shadowmap_pars_vertex = `#if NUM_SPOT_LIGHT_COORDS > 0
|
|
uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
|
|
varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
|
|
#endif
|
|
#ifdef USE_SHADOWMAP
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
|
|
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
|
|
struct DirectionalLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_SHADOWS > 0
|
|
struct SpotLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
|
|
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
|
|
struct PointLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
float shadowCameraNear;
|
|
float shadowCameraFar;
|
|
};
|
|
uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
|
|
#endif
|
|
#endif`, shadowmap_vertex = `#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
|
|
vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
|
|
vec4 shadowWorldPosition;
|
|
#endif
|
|
#if defined( USE_SHADOWMAP )
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
|
|
shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
|
|
vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
|
|
shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
|
|
vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_COORDS > 0
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
|
|
shadowWorldPosition = worldPosition;
|
|
#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
|
|
#endif
|
|
vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif`, shadowmask_pars_fragment = `float getShadowMask() {
|
|
float shadow = 1.0;
|
|
#ifdef USE_SHADOWMAP
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
DirectionalLightShadow directionalLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
|
|
directionalLight = directionalLightShadows[ i ];
|
|
shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_SHADOWS > 0
|
|
SpotLightShadow spotLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
|
|
spotLight = spotLightShadows[ i ];
|
|
shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
PointLightShadow pointLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
|
|
pointLight = pointLightShadows[ i ];
|
|
shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#endif
|
|
return shadow;
|
|
}`, skinbase_vertex = `#ifdef USE_SKINNING
|
|
mat4 boneMatX = getBoneMatrix( skinIndex.x );
|
|
mat4 boneMatY = getBoneMatrix( skinIndex.y );
|
|
mat4 boneMatZ = getBoneMatrix( skinIndex.z );
|
|
mat4 boneMatW = getBoneMatrix( skinIndex.w );
|
|
#endif`, skinning_pars_vertex = `#ifdef USE_SKINNING
|
|
uniform mat4 bindMatrix;
|
|
uniform mat4 bindMatrixInverse;
|
|
uniform highp sampler2D boneTexture;
|
|
mat4 getBoneMatrix( const in float i ) {
|
|
int size = textureSize( boneTexture, 0 ).x;
|
|
int j = int( i ) * 4;
|
|
int x = j % size;
|
|
int y = j / size;
|
|
vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
|
|
vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
|
|
vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
|
|
vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
|
|
return mat4( v1, v2, v3, v4 );
|
|
}
|
|
#endif`, skinning_vertex = `#ifdef USE_SKINNING
|
|
vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
|
|
vec4 skinned = vec4( 0.0 );
|
|
skinned += boneMatX * skinVertex * skinWeight.x;
|
|
skinned += boneMatY * skinVertex * skinWeight.y;
|
|
skinned += boneMatZ * skinVertex * skinWeight.z;
|
|
skinned += boneMatW * skinVertex * skinWeight.w;
|
|
transformed = ( bindMatrixInverse * skinned ).xyz;
|
|
#endif`, skinnormal_vertex = `#ifdef USE_SKINNING
|
|
mat4 skinMatrix = mat4( 0.0 );
|
|
skinMatrix += skinWeight.x * boneMatX;
|
|
skinMatrix += skinWeight.y * boneMatY;
|
|
skinMatrix += skinWeight.z * boneMatZ;
|
|
skinMatrix += skinWeight.w * boneMatW;
|
|
skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
|
|
objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
|
|
#ifdef USE_TANGENT
|
|
objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
|
|
#endif
|
|
#endif`, specularmap_fragment = `float specularStrength;
|
|
#ifdef USE_SPECULARMAP
|
|
vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
|
|
specularStrength = texelSpecular.r;
|
|
#else
|
|
specularStrength = 1.0;
|
|
#endif`, specularmap_pars_fragment = `#ifdef USE_SPECULARMAP
|
|
uniform sampler2D specularMap;
|
|
#endif`, tonemapping_fragment = `#if defined( TONE_MAPPING )
|
|
gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
|
|
#endif`, tonemapping_pars_fragment = `#ifndef saturate
|
|
#define saturate( a ) clamp( a, 0.0, 1.0 )
|
|
#endif
|
|
uniform float toneMappingExposure;
|
|
vec3 LinearToneMapping( vec3 color ) {
|
|
return saturate( toneMappingExposure * color );
|
|
}
|
|
vec3 ReinhardToneMapping( vec3 color ) {
|
|
color *= toneMappingExposure;
|
|
return saturate( color / ( vec3( 1.0 ) + color ) );
|
|
}
|
|
vec3 CineonToneMapping( vec3 color ) {
|
|
color *= toneMappingExposure;
|
|
color = max( vec3( 0.0 ), color - 0.004 );
|
|
return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
|
|
}
|
|
vec3 RRTAndODTFit( vec3 v ) {
|
|
vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
|
|
vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
|
|
return a / b;
|
|
}
|
|
vec3 ACESFilmicToneMapping( vec3 color ) {
|
|
const mat3 ACESInputMat = mat3(
|
|
vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),
|
|
vec3( 0.04823, 0.01566, 0.83777 )
|
|
);
|
|
const mat3 ACESOutputMat = mat3(
|
|
vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),
|
|
vec3( -0.07367, -0.00605, 1.07602 )
|
|
);
|
|
color *= toneMappingExposure / 0.6;
|
|
color = ACESInputMat * color;
|
|
color = RRTAndODTFit( color );
|
|
color = ACESOutputMat * color;
|
|
return saturate( color );
|
|
}
|
|
const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
|
|
vec3( 1.6605, - 0.1246, - 0.0182 ),
|
|
vec3( - 0.5876, 1.1329, - 0.1006 ),
|
|
vec3( - 0.0728, - 0.0083, 1.1187 )
|
|
);
|
|
const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
|
|
vec3( 0.6274, 0.0691, 0.0164 ),
|
|
vec3( 0.3293, 0.9195, 0.0880 ),
|
|
vec3( 0.0433, 0.0113, 0.8956 )
|
|
);
|
|
vec3 agxDefaultContrastApprox( vec3 x ) {
|
|
vec3 x2 = x * x;
|
|
vec3 x4 = x2 * x2;
|
|
return + 15.5 * x4 * x2
|
|
- 40.14 * x4 * x
|
|
+ 31.96 * x4
|
|
- 6.868 * x2 * x
|
|
+ 0.4298 * x2
|
|
+ 0.1191 * x
|
|
- 0.00232;
|
|
}
|
|
vec3 AgXToneMapping( vec3 color ) {
|
|
const mat3 AgXInsetMatrix = mat3(
|
|
vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
|
|
vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
|
|
vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
|
|
);
|
|
const mat3 AgXOutsetMatrix = mat3(
|
|
vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
|
|
vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
|
|
vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
|
|
);
|
|
const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069;
|
|
color *= toneMappingExposure;
|
|
color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
|
|
color = AgXInsetMatrix * color;
|
|
color = max( color, 1e-10 ); color = log2( color );
|
|
color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );
|
|
color = clamp( color, 0.0, 1.0 );
|
|
color = agxDefaultContrastApprox( color );
|
|
color = AgXOutsetMatrix * color;
|
|
color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );
|
|
color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
|
|
color = clamp( color, 0.0, 1.0 );
|
|
return color;
|
|
}
|
|
vec3 NeutralToneMapping( vec3 color ) {
|
|
const float StartCompression = 0.8 - 0.04;
|
|
const float Desaturation = 0.15;
|
|
color *= toneMappingExposure;
|
|
float x = min( color.r, min( color.g, color.b ) );
|
|
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
|
|
color -= offset;
|
|
float peak = max( color.r, max( color.g, color.b ) );
|
|
if ( peak < StartCompression ) return color;
|
|
float d = 1. - StartCompression;
|
|
float newPeak = 1. - d * d / ( peak + d - StartCompression );
|
|
color *= newPeak / peak;
|
|
float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
|
|
return mix( color, vec3( newPeak ), g );
|
|
}
|
|
vec3 CustomToneMapping( vec3 color ) { return color; }`, transmission_fragment = `#ifdef USE_TRANSMISSION
|
|
material.transmission = transmission;
|
|
material.transmissionAlpha = 1.0;
|
|
material.thickness = thickness;
|
|
material.attenuationDistance = attenuationDistance;
|
|
material.attenuationColor = attenuationColor;
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
|
|
#endif
|
|
vec3 pos = vWorldPosition;
|
|
vec3 v = normalize( cameraPosition - pos );
|
|
vec3 n = inverseTransformDirection( normal, viewMatrix );
|
|
vec4 transmitted = getIBLVolumeRefraction(
|
|
n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
|
|
pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
|
|
material.attenuationColor, material.attenuationDistance );
|
|
material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
|
|
totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
|
|
#endif`, transmission_pars_fragment = `#ifdef USE_TRANSMISSION
|
|
uniform float transmission;
|
|
uniform float thickness;
|
|
uniform float attenuationDistance;
|
|
uniform vec3 attenuationColor;
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
uniform sampler2D transmissionMap;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
uniform sampler2D thicknessMap;
|
|
#endif
|
|
uniform vec2 transmissionSamplerSize;
|
|
uniform sampler2D transmissionSamplerMap;
|
|
uniform mat4 modelMatrix;
|
|
uniform mat4 projectionMatrix;
|
|
varying vec3 vWorldPosition;
|
|
float w0( float a ) {
|
|
return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
|
|
}
|
|
float w1( float a ) {
|
|
return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );
|
|
}
|
|
float w2( float a ){
|
|
return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
|
|
}
|
|
float w3( float a ) {
|
|
return ( 1.0 / 6.0 ) * ( a * a * a );
|
|
}
|
|
float g0( float a ) {
|
|
return w0( a ) + w1( a );
|
|
}
|
|
float g1( float a ) {
|
|
return w2( a ) + w3( a );
|
|
}
|
|
float h0( float a ) {
|
|
return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
|
|
}
|
|
float h1( float a ) {
|
|
return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
|
|
}
|
|
vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
|
|
uv = uv * texelSize.zw + 0.5;
|
|
vec2 iuv = floor( uv );
|
|
vec2 fuv = fract( uv );
|
|
float g0x = g0( fuv.x );
|
|
float g1x = g1( fuv.x );
|
|
float h0x = h0( fuv.x );
|
|
float h1x = h1( fuv.x );
|
|
float h0y = h0( fuv.y );
|
|
float h1y = h1( fuv.y );
|
|
vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
|
|
vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
|
|
vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
|
|
vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
|
|
return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
|
|
g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
|
|
}
|
|
vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
|
|
vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
|
|
vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
|
|
vec2 fLodSizeInv = 1.0 / fLodSize;
|
|
vec2 cLodSizeInv = 1.0 / cLodSize;
|
|
vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
|
|
vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
|
|
return mix( fSample, cSample, fract( lod ) );
|
|
}
|
|
vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
|
|
vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
|
|
vec3 modelScale;
|
|
modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
|
|
modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
|
|
modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
|
|
return normalize( refractionVector ) * thickness * modelScale;
|
|
}
|
|
float applyIorToRoughness( const in float roughness, const in float ior ) {
|
|
return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
|
|
}
|
|
vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
|
|
float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
|
|
return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
|
|
}
|
|
vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
|
|
if ( isinf( attenuationDistance ) ) {
|
|
return vec3( 1.0 );
|
|
} else {
|
|
vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
|
|
vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;
|
|
}
|
|
}
|
|
vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
|
|
const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
|
|
const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
|
|
const in vec3 attenuationColor, const in float attenuationDistance ) {
|
|
vec4 transmittedLight;
|
|
vec3 transmittance;
|
|
#ifdef USE_DISPERSION
|
|
float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
|
|
vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
|
|
for ( int i = 0; i < 3; i ++ ) {
|
|
vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
|
|
vec3 refractedRayExit = position + transmissionRay;
|
|
vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
|
|
vec2 refractionCoords = ndcPos.xy / ndcPos.w;
|
|
refractionCoords += 1.0;
|
|
refractionCoords /= 2.0;
|
|
vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
|
|
transmittedLight[ i ] = transmissionSample[ i ];
|
|
transmittedLight.a += transmissionSample.a;
|
|
transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
|
|
}
|
|
transmittedLight.a /= 3.0;
|
|
#else
|
|
vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
|
|
vec3 refractedRayExit = position + transmissionRay;
|
|
vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
|
|
vec2 refractionCoords = ndcPos.xy / ndcPos.w;
|
|
refractionCoords += 1.0;
|
|
refractionCoords /= 2.0;
|
|
transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
|
|
transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
|
|
#endif
|
|
vec3 attenuatedColor = transmittance * transmittedLight.rgb;
|
|
vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
|
|
float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
|
|
return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
|
|
}
|
|
#endif`, uv_pars_fragment = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
varying vec2 vUv;
|
|
#endif
|
|
#ifdef USE_MAP
|
|
varying vec2 vMapUv;
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
varying vec2 vAlphaMapUv;
|
|
#endif
|
|
#ifdef USE_LIGHTMAP
|
|
varying vec2 vLightMapUv;
|
|
#endif
|
|
#ifdef USE_AOMAP
|
|
varying vec2 vAoMapUv;
|
|
#endif
|
|
#ifdef USE_BUMPMAP
|
|
varying vec2 vBumpMapUv;
|
|
#endif
|
|
#ifdef USE_NORMALMAP
|
|
varying vec2 vNormalMapUv;
|
|
#endif
|
|
#ifdef USE_EMISSIVEMAP
|
|
varying vec2 vEmissiveMapUv;
|
|
#endif
|
|
#ifdef USE_METALNESSMAP
|
|
varying vec2 vMetalnessMapUv;
|
|
#endif
|
|
#ifdef USE_ROUGHNESSMAP
|
|
varying vec2 vRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_ANISOTROPYMAP
|
|
varying vec2 vAnisotropyMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOATMAP
|
|
varying vec2 vClearcoatMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
varying vec2 vClearcoatNormalMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
varying vec2 vClearcoatRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCEMAP
|
|
varying vec2 vIridescenceMapUv;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
varying vec2 vIridescenceThicknessMapUv;
|
|
#endif
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
varying vec2 vSheenColorMapUv;
|
|
#endif
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
varying vec2 vSheenRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULARMAP
|
|
varying vec2 vSpecularMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
varying vec2 vSpecularColorMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
varying vec2 vSpecularIntensityMapUv;
|
|
#endif
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
uniform mat3 transmissionMapTransform;
|
|
varying vec2 vTransmissionMapUv;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
uniform mat3 thicknessMapTransform;
|
|
varying vec2 vThicknessMapUv;
|
|
#endif`, uv_pars_vertex = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
varying vec2 vUv;
|
|
#endif
|
|
#ifdef USE_MAP
|
|
uniform mat3 mapTransform;
|
|
varying vec2 vMapUv;
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
uniform mat3 alphaMapTransform;
|
|
varying vec2 vAlphaMapUv;
|
|
#endif
|
|
#ifdef USE_LIGHTMAP
|
|
uniform mat3 lightMapTransform;
|
|
varying vec2 vLightMapUv;
|
|
#endif
|
|
#ifdef USE_AOMAP
|
|
uniform mat3 aoMapTransform;
|
|
varying vec2 vAoMapUv;
|
|
#endif
|
|
#ifdef USE_BUMPMAP
|
|
uniform mat3 bumpMapTransform;
|
|
varying vec2 vBumpMapUv;
|
|
#endif
|
|
#ifdef USE_NORMALMAP
|
|
uniform mat3 normalMapTransform;
|
|
varying vec2 vNormalMapUv;
|
|
#endif
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
uniform mat3 displacementMapTransform;
|
|
varying vec2 vDisplacementMapUv;
|
|
#endif
|
|
#ifdef USE_EMISSIVEMAP
|
|
uniform mat3 emissiveMapTransform;
|
|
varying vec2 vEmissiveMapUv;
|
|
#endif
|
|
#ifdef USE_METALNESSMAP
|
|
uniform mat3 metalnessMapTransform;
|
|
varying vec2 vMetalnessMapUv;
|
|
#endif
|
|
#ifdef USE_ROUGHNESSMAP
|
|
uniform mat3 roughnessMapTransform;
|
|
varying vec2 vRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_ANISOTROPYMAP
|
|
uniform mat3 anisotropyMapTransform;
|
|
varying vec2 vAnisotropyMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOATMAP
|
|
uniform mat3 clearcoatMapTransform;
|
|
varying vec2 vClearcoatMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
uniform mat3 clearcoatNormalMapTransform;
|
|
varying vec2 vClearcoatNormalMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
uniform mat3 clearcoatRoughnessMapTransform;
|
|
varying vec2 vClearcoatRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
uniform mat3 sheenColorMapTransform;
|
|
varying vec2 vSheenColorMapUv;
|
|
#endif
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
uniform mat3 sheenRoughnessMapTransform;
|
|
varying vec2 vSheenRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCEMAP
|
|
uniform mat3 iridescenceMapTransform;
|
|
varying vec2 vIridescenceMapUv;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
uniform mat3 iridescenceThicknessMapTransform;
|
|
varying vec2 vIridescenceThicknessMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULARMAP
|
|
uniform mat3 specularMapTransform;
|
|
varying vec2 vSpecularMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
uniform mat3 specularColorMapTransform;
|
|
varying vec2 vSpecularColorMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
uniform mat3 specularIntensityMapTransform;
|
|
varying vec2 vSpecularIntensityMapUv;
|
|
#endif
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
uniform mat3 transmissionMapTransform;
|
|
varying vec2 vTransmissionMapUv;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
uniform mat3 thicknessMapTransform;
|
|
varying vec2 vThicknessMapUv;
|
|
#endif`, uv_vertex = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
vUv = vec3( uv, 1 ).xy;
|
|
#endif
|
|
#ifdef USE_MAP
|
|
vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_LIGHTMAP
|
|
vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_AOMAP
|
|
vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_BUMPMAP
|
|
vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_NORMALMAP
|
|
vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_EMISSIVEMAP
|
|
vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_METALNESSMAP
|
|
vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_ROUGHNESSMAP
|
|
vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_ANISOTROPYMAP
|
|
vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_CLEARCOATMAP
|
|
vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCEMAP
|
|
vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SPECULARMAP
|
|
vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
|
|
#endif`, worldpos_vertex = `#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
|
|
vec4 worldPosition = vec4( transformed, 1.0 );
|
|
#ifdef USE_BATCHING
|
|
worldPosition = batchingMatrix * worldPosition;
|
|
#endif
|
|
#ifdef USE_INSTANCING
|
|
worldPosition = instanceMatrix * worldPosition;
|
|
#endif
|
|
worldPosition = modelMatrix * worldPosition;
|
|
#endif`, vertex$h = `varying vec2 vUv;
|
|
uniform mat3 uvTransform;
|
|
void main() {
|
|
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
|
|
gl_Position = vec4( position.xy, 1.0, 1.0 );
|
|
}`, fragment$h = `uniform sampler2D t2D;
|
|
uniform float backgroundIntensity;
|
|
varying vec2 vUv;
|
|
void main() {
|
|
vec4 texColor = texture2D( t2D, vUv );
|
|
#ifdef DECODE_VIDEO_TEXTURE
|
|
texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
|
|
#endif
|
|
texColor.rgb *= backgroundIntensity;
|
|
gl_FragColor = texColor;
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`, vertex$g = `varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
gl_Position.z = gl_Position.w;
|
|
}`, fragment$g = `#ifdef ENVMAP_TYPE_CUBE
|
|
uniform samplerCube envMap;
|
|
#elif defined( ENVMAP_TYPE_CUBE_UV )
|
|
uniform sampler2D envMap;
|
|
#endif
|
|
uniform float flipEnvMap;
|
|
uniform float backgroundBlurriness;
|
|
uniform float backgroundIntensity;
|
|
uniform mat3 backgroundRotation;
|
|
varying vec3 vWorldDirection;
|
|
#include <cube_uv_reflection_fragment>
|
|
void main() {
|
|
#ifdef ENVMAP_TYPE_CUBE
|
|
vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );
|
|
#elif defined( ENVMAP_TYPE_CUBE_UV )
|
|
vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );
|
|
#else
|
|
vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );
|
|
#endif
|
|
texColor.rgb *= backgroundIntensity;
|
|
gl_FragColor = texColor;
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`, vertex$f = `varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
gl_Position.z = gl_Position.w;
|
|
}`, fragment$f = `uniform samplerCube tCube;
|
|
uniform float tFlip;
|
|
uniform float opacity;
|
|
varying vec3 vWorldDirection;
|
|
void main() {
|
|
vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
|
|
gl_FragColor = texColor;
|
|
gl_FragColor.a *= opacity;
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`, vertex$e = `#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
varying vec2 vHighPrecisionZW;
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <morphinstance_vertex>
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vHighPrecisionZW = gl_Position.zw;
|
|
}`, fragment$e = `#if DEPTH_PACKING == 3200
|
|
uniform float opacity;
|
|
#endif
|
|
#include <common>
|
|
#include <packing>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
varying vec2 vHighPrecisionZW;
|
|
void main() {
|
|
vec4 diffuseColor = vec4( 1.0 );
|
|
#include <clipping_planes_fragment>
|
|
#if DEPTH_PACKING == 3200
|
|
diffuseColor.a = opacity;
|
|
#endif
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
|
|
#if DEPTH_PACKING == 3200
|
|
gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
|
|
#elif DEPTH_PACKING == 3201
|
|
gl_FragColor = packDepthToRGBA( fragCoordZ );
|
|
#elif DEPTH_PACKING == 3202
|
|
gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
|
|
#elif DEPTH_PACKING == 3203
|
|
gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
|
|
#endif
|
|
}`, vertex$d = `#define DISTANCE
|
|
varying vec3 vWorldPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <morphinstance_vertex>
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vWorldPosition = worldPosition.xyz;
|
|
}`, fragment$d = `#define DISTANCE
|
|
uniform vec3 referencePosition;
|
|
uniform float nearDistance;
|
|
uniform float farDistance;
|
|
varying vec3 vWorldPosition;
|
|
#include <common>
|
|
#include <packing>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main () {
|
|
vec4 diffuseColor = vec4( 1.0 );
|
|
#include <clipping_planes_fragment>
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
float dist = length( vWorldPosition - referencePosition );
|
|
dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
|
|
dist = saturate( dist );
|
|
gl_FragColor = packDepthToRGBA( dist );
|
|
}`, vertex$c = `varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
}`, fragment$c = `uniform sampler2D tEquirect;
|
|
varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vec3 direction = normalize( vWorldDirection );
|
|
vec2 sampleUV = equirectUv( direction );
|
|
gl_FragColor = texture2D( tEquirect, sampleUV );
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`, vertex$b = `uniform float scale;
|
|
attribute float lineDistance;
|
|
varying float vLineDistance;
|
|
#include <common>
|
|
#include <uv_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
vLineDistance = scale * lineDistance;
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
}`, fragment$b = `uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
uniform float dashSize;
|
|
uniform float totalSize;
|
|
varying float vLineDistance;
|
|
#include <common>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
if ( mod( vLineDistance, totalSize ) > dashSize ) {
|
|
discard;
|
|
}
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
}`, vertex$a = `#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <fog_vertex>
|
|
}`, fragment$a = `uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#endif
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
#ifdef USE_LIGHTMAP
|
|
vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
|
|
reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
|
|
#else
|
|
reflectedLight.indirectDiffuse += vec3( 1.0 );
|
|
#endif
|
|
#include <aomap_fragment>
|
|
reflectedLight.indirectDiffuse *= diffuseColor.rgb;
|
|
vec3 outgoingLight = reflectedLight.indirectDiffuse;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`, vertex$9 = `#define LAMBERT
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`, fragment$9 = `#define LAMBERT
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <packing>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_lambert_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_lambert_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`, vertex$8 = `#define MATCAP
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
}`, fragment$8 = `#define MATCAP
|
|
uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
uniform sampler2D matcap;
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <normal_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
vec3 viewDir = normalize( vViewPosition );
|
|
vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
|
|
vec3 y = cross( viewDir, x );
|
|
vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;
|
|
#ifdef USE_MATCAP
|
|
vec4 matcapColor = texture2D( matcap, uv );
|
|
#else
|
|
vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );
|
|
#endif
|
|
vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`, vertex$7 = `#define NORMAL
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
varying vec3 vViewPosition;
|
|
#endif
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
vViewPosition = - mvPosition.xyz;
|
|
#endif
|
|
}`, fragment$7 = `#define NORMAL
|
|
uniform float opacity;
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
varying vec3 vViewPosition;
|
|
#endif
|
|
#include <packing>
|
|
#include <uv_pars_fragment>
|
|
#include <normal_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
gl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );
|
|
#ifdef OPAQUE
|
|
gl_FragColor.a = 1.0;
|
|
#endif
|
|
}`, vertex$6 = `#define PHONG
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`, fragment$6 = `#define PHONG
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform vec3 specular;
|
|
uniform float shininess;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <packing>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_phong_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_phong_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`, vertex$5 = `#define STANDARD
|
|
varying vec3 vViewPosition;
|
|
#ifdef USE_TRANSMISSION
|
|
varying vec3 vWorldPosition;
|
|
#endif
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
#ifdef USE_TRANSMISSION
|
|
vWorldPosition = worldPosition.xyz;
|
|
#endif
|
|
}`, fragment$5 = `#define STANDARD
|
|
#ifdef PHYSICAL
|
|
#define IOR
|
|
#define USE_SPECULAR
|
|
#endif
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform float roughness;
|
|
uniform float metalness;
|
|
uniform float opacity;
|
|
#ifdef IOR
|
|
uniform float ior;
|
|
#endif
|
|
#ifdef USE_SPECULAR
|
|
uniform float specularIntensity;
|
|
uniform vec3 specularColor;
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
uniform sampler2D specularColorMap;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
uniform sampler2D specularIntensityMap;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
uniform float clearcoat;
|
|
uniform float clearcoatRoughness;
|
|
#endif
|
|
#ifdef USE_DISPERSION
|
|
uniform float dispersion;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
uniform float iridescence;
|
|
uniform float iridescenceIOR;
|
|
uniform float iridescenceThicknessMinimum;
|
|
uniform float iridescenceThicknessMaximum;
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
uniform vec3 sheenColor;
|
|
uniform float sheenRoughness;
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
uniform sampler2D sheenColorMap;
|
|
#endif
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
uniform sampler2D sheenRoughnessMap;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_ANISOTROPY
|
|
uniform vec2 anisotropyVector;
|
|
#ifdef USE_ANISOTROPYMAP
|
|
uniform sampler2D anisotropyMap;
|
|
#endif
|
|
#endif
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <packing>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <iridescence_fragment>
|
|
#include <cube_uv_reflection_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_physical_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_physical_pars_fragment>
|
|
#include <transmission_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <clearcoat_pars_fragment>
|
|
#include <iridescence_pars_fragment>
|
|
#include <roughnessmap_pars_fragment>
|
|
#include <metalnessmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <roughnessmap_fragment>
|
|
#include <metalnessmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <clearcoat_normal_fragment_begin>
|
|
#include <clearcoat_normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_physical_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
|
|
vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
|
|
#include <transmission_fragment>
|
|
vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
|
|
#ifdef USE_SHEEN
|
|
float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
|
|
outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
|
|
vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
|
|
outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
|
|
#endif
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`, vertex$4 = `#define TOON
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`, fragment$4 = `#define TOON
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <packing>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <gradientmap_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_toon_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_toon_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`, vertex$3 = `uniform float size;
|
|
uniform float scale;
|
|
#include <common>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
#ifdef USE_POINTS_UV
|
|
varying vec2 vUv;
|
|
uniform mat3 uvTransform;
|
|
#endif
|
|
void main() {
|
|
#ifdef USE_POINTS_UV
|
|
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
|
|
#endif
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <project_vertex>
|
|
gl_PointSize = size;
|
|
#ifdef USE_SIZEATTENUATION
|
|
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
|
|
if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
|
|
#endif
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <fog_vertex>
|
|
}`, fragment$3 = `uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <color_pars_fragment>
|
|
#include <map_particle_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_particle_fragment>
|
|
#include <color_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
}`, vertex$2 = `#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
void main() {
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`, fragment$2 = `uniform vec3 color;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <packing>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <shadowmask_pars_fragment>
|
|
void main() {
|
|
#include <logdepthbuf_fragment>
|
|
gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
}`, vertex$1 = `uniform float rotation;
|
|
uniform vec2 center;
|
|
#include <common>
|
|
#include <uv_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
vec4 mvPosition = modelViewMatrix[ 3 ];
|
|
vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );
|
|
#ifndef USE_SIZEATTENUATION
|
|
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
|
|
if ( isPerspective ) scale *= - mvPosition.z;
|
|
#endif
|
|
vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
|
|
vec2 rotatedPosition;
|
|
rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
|
|
rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
|
|
mvPosition.xy += rotatedPosition;
|
|
gl_Position = projectionMatrix * mvPosition;
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
}`, fragment$1 = `uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
}`, ShaderChunk, UniformsLib, ShaderLib, _rgb, _e1$1, _m1$12, LOD_MIN = 4, EXTRA_LOD_SIGMA, MAX_SAMPLES = 20, _flatCamera, _clearColor, _oldTarget = null, _oldActiveCubeFace = 0, _oldActiveMipmapLevel = 0, _oldXrEnabled = false, PHI, INV_PHI, _axisDirections, emptyTexture, emptyShadowTexture, emptyArrayTexture, empty3dTexture, emptyCubeTexture, arrayCacheF32, arrayCacheI32, mat4array, mat3array, mat2array, RePathPart, COMPLETION_STATUS_KHR = 37297, programIdCount = 0, _m0, _v02, includePattern, shaderChunkMap, unrollLoopPattern, _id2 = 0, nextVersion = 0, vertex = `void main() {
|
|
gl_Position = vec4( position, 1.0 );
|
|
}`, fragment = `uniform sampler2D shadow_pass;
|
|
uniform vec2 resolution;
|
|
uniform float radius;
|
|
#include <packing>
|
|
void main() {
|
|
const float samples = float( VSM_SAMPLES );
|
|
float mean = 0.0;
|
|
float squared_mean = 0.0;
|
|
float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );
|
|
float uvStart = samples <= 1.0 ? 0.0 : - 1.0;
|
|
for ( float i = 0.0; i < samples; i ++ ) {
|
|
float uvOffset = uvStart + i * uvStride;
|
|
#ifdef HORIZONTAL_PASS
|
|
vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );
|
|
mean += distribution.x;
|
|
squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
|
|
#else
|
|
float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );
|
|
mean += depth;
|
|
squared_mean += depth * depth;
|
|
#endif
|
|
}
|
|
mean = mean / samples;
|
|
squared_mean = squared_mean / samples;
|
|
float std_dev = sqrt( squared_mean - mean * mean );
|
|
gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );
|
|
}`, reversedFuncs, WebGLMultiviewRenderTarget, _occlusion_vertex = `
|
|
void main() {
|
|
|
|
gl_Position = vec4( position, 1.0 );
|
|
|
|
}`, _occlusion_fragment = `
|
|
uniform sampler2DArray depthColor;
|
|
uniform float depthWidth;
|
|
uniform float depthHeight;
|
|
|
|
void main() {
|
|
|
|
vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );
|
|
|
|
if ( coord.x >= 1.0 ) {
|
|
|
|
gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;
|
|
|
|
} else {
|
|
|
|
gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;
|
|
|
|
}
|
|
|
|
}`, WebXRManager, _e1, _m12;
|
|
var init_three_module = __esm(() => {
|
|
init_three_core();
|
|
init_three_core();
|
|
ShaderChunk = {
|
|
alphahash_fragment,
|
|
alphahash_pars_fragment,
|
|
alphamap_fragment,
|
|
alphamap_pars_fragment,
|
|
alphatest_fragment,
|
|
alphatest_pars_fragment,
|
|
aomap_fragment,
|
|
aomap_pars_fragment,
|
|
batching_pars_vertex,
|
|
batching_vertex,
|
|
begin_vertex,
|
|
beginnormal_vertex,
|
|
bsdfs,
|
|
iridescence_fragment,
|
|
bumpmap_pars_fragment,
|
|
clipping_planes_fragment,
|
|
clipping_planes_pars_fragment,
|
|
clipping_planes_pars_vertex,
|
|
clipping_planes_vertex,
|
|
color_fragment,
|
|
color_pars_fragment,
|
|
color_pars_vertex,
|
|
color_vertex,
|
|
common,
|
|
cube_uv_reflection_fragment,
|
|
defaultnormal_vertex,
|
|
displacementmap_pars_vertex,
|
|
displacementmap_vertex,
|
|
emissivemap_fragment,
|
|
emissivemap_pars_fragment,
|
|
colorspace_fragment,
|
|
colorspace_pars_fragment,
|
|
envmap_fragment,
|
|
envmap_common_pars_fragment,
|
|
envmap_pars_fragment,
|
|
envmap_pars_vertex,
|
|
envmap_physical_pars_fragment,
|
|
envmap_vertex,
|
|
fog_vertex,
|
|
fog_pars_vertex,
|
|
fog_fragment,
|
|
fog_pars_fragment,
|
|
gradientmap_pars_fragment,
|
|
lightmap_pars_fragment,
|
|
lights_lambert_fragment,
|
|
lights_lambert_pars_fragment,
|
|
lights_pars_begin,
|
|
lights_toon_fragment,
|
|
lights_toon_pars_fragment,
|
|
lights_phong_fragment,
|
|
lights_phong_pars_fragment,
|
|
lights_physical_fragment,
|
|
lights_physical_pars_fragment,
|
|
lights_fragment_begin,
|
|
lights_fragment_maps,
|
|
lights_fragment_end,
|
|
logdepthbuf_fragment,
|
|
logdepthbuf_pars_fragment,
|
|
logdepthbuf_pars_vertex,
|
|
logdepthbuf_vertex,
|
|
map_fragment,
|
|
map_pars_fragment,
|
|
map_particle_fragment,
|
|
map_particle_pars_fragment,
|
|
metalnessmap_fragment,
|
|
metalnessmap_pars_fragment,
|
|
morphinstance_vertex,
|
|
morphcolor_vertex,
|
|
morphnormal_vertex,
|
|
morphtarget_pars_vertex,
|
|
morphtarget_vertex,
|
|
normal_fragment_begin,
|
|
normal_fragment_maps,
|
|
normal_pars_fragment,
|
|
normal_pars_vertex,
|
|
normal_vertex,
|
|
normalmap_pars_fragment,
|
|
clearcoat_normal_fragment_begin,
|
|
clearcoat_normal_fragment_maps,
|
|
clearcoat_pars_fragment,
|
|
iridescence_pars_fragment,
|
|
opaque_fragment,
|
|
packing,
|
|
premultiplied_alpha_fragment,
|
|
project_vertex,
|
|
dithering_fragment,
|
|
dithering_pars_fragment,
|
|
roughnessmap_fragment,
|
|
roughnessmap_pars_fragment,
|
|
shadowmap_pars_fragment,
|
|
shadowmap_pars_vertex,
|
|
shadowmap_vertex,
|
|
shadowmask_pars_fragment,
|
|
skinbase_vertex,
|
|
skinning_pars_vertex,
|
|
skinning_vertex,
|
|
skinnormal_vertex,
|
|
specularmap_fragment,
|
|
specularmap_pars_fragment,
|
|
tonemapping_fragment,
|
|
tonemapping_pars_fragment,
|
|
transmission_fragment,
|
|
transmission_pars_fragment,
|
|
uv_pars_fragment,
|
|
uv_pars_vertex,
|
|
uv_vertex,
|
|
worldpos_vertex,
|
|
background_vert: vertex$h,
|
|
background_frag: fragment$h,
|
|
backgroundCube_vert: vertex$g,
|
|
backgroundCube_frag: fragment$g,
|
|
cube_vert: vertex$f,
|
|
cube_frag: fragment$f,
|
|
depth_vert: vertex$e,
|
|
depth_frag: fragment$e,
|
|
distanceRGBA_vert: vertex$d,
|
|
distanceRGBA_frag: fragment$d,
|
|
equirect_vert: vertex$c,
|
|
equirect_frag: fragment$c,
|
|
linedashed_vert: vertex$b,
|
|
linedashed_frag: fragment$b,
|
|
meshbasic_vert: vertex$a,
|
|
meshbasic_frag: fragment$a,
|
|
meshlambert_vert: vertex$9,
|
|
meshlambert_frag: fragment$9,
|
|
meshmatcap_vert: vertex$8,
|
|
meshmatcap_frag: fragment$8,
|
|
meshnormal_vert: vertex$7,
|
|
meshnormal_frag: fragment$7,
|
|
meshphong_vert: vertex$6,
|
|
meshphong_frag: fragment$6,
|
|
meshphysical_vert: vertex$5,
|
|
meshphysical_frag: fragment$5,
|
|
meshtoon_vert: vertex$4,
|
|
meshtoon_frag: fragment$4,
|
|
points_vert: vertex$3,
|
|
points_frag: fragment$3,
|
|
shadow_vert: vertex$2,
|
|
shadow_frag: fragment$2,
|
|
sprite_vert: vertex$1,
|
|
sprite_frag: fragment$1
|
|
};
|
|
UniformsLib = {
|
|
common: {
|
|
diffuse: { value: /* @__PURE__ */ new Color(16777215) },
|
|
opacity: { value: 1 },
|
|
map: { value: null },
|
|
mapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
alphaMap: { value: null },
|
|
alphaMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
alphaTest: { value: 0 }
|
|
},
|
|
specularmap: {
|
|
specularMap: { value: null },
|
|
specularMapTransform: { value: /* @__PURE__ */ new Matrix3 }
|
|
},
|
|
envmap: {
|
|
envMap: { value: null },
|
|
envMapRotation: { value: /* @__PURE__ */ new Matrix3 },
|
|
flipEnvMap: { value: -1 },
|
|
reflectivity: { value: 1 },
|
|
ior: { value: 1.5 },
|
|
refractionRatio: { value: 0.98 }
|
|
},
|
|
aomap: {
|
|
aoMap: { value: null },
|
|
aoMapIntensity: { value: 1 },
|
|
aoMapTransform: { value: /* @__PURE__ */ new Matrix3 }
|
|
},
|
|
lightmap: {
|
|
lightMap: { value: null },
|
|
lightMapIntensity: { value: 1 },
|
|
lightMapTransform: { value: /* @__PURE__ */ new Matrix3 }
|
|
},
|
|
bumpmap: {
|
|
bumpMap: { value: null },
|
|
bumpMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
bumpScale: { value: 1 }
|
|
},
|
|
normalmap: {
|
|
normalMap: { value: null },
|
|
normalMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
normalScale: { value: /* @__PURE__ */ new Vector2(1, 1) }
|
|
},
|
|
displacementmap: {
|
|
displacementMap: { value: null },
|
|
displacementMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
displacementScale: { value: 1 },
|
|
displacementBias: { value: 0 }
|
|
},
|
|
emissivemap: {
|
|
emissiveMap: { value: null },
|
|
emissiveMapTransform: { value: /* @__PURE__ */ new Matrix3 }
|
|
},
|
|
metalnessmap: {
|
|
metalnessMap: { value: null },
|
|
metalnessMapTransform: { value: /* @__PURE__ */ new Matrix3 }
|
|
},
|
|
roughnessmap: {
|
|
roughnessMap: { value: null },
|
|
roughnessMapTransform: { value: /* @__PURE__ */ new Matrix3 }
|
|
},
|
|
gradientmap: {
|
|
gradientMap: { value: null }
|
|
},
|
|
fog: {
|
|
fogDensity: { value: 0.00025 },
|
|
fogNear: { value: 1 },
|
|
fogFar: { value: 2000 },
|
|
fogColor: { value: /* @__PURE__ */ new Color(16777215) }
|
|
},
|
|
lights: {
|
|
ambientLightColor: { value: [] },
|
|
lightProbe: { value: [] },
|
|
directionalLights: { value: [], properties: {
|
|
direction: {},
|
|
color: {}
|
|
} },
|
|
directionalLightShadows: { value: [], properties: {
|
|
shadowIntensity: 1,
|
|
shadowBias: {},
|
|
shadowNormalBias: {},
|
|
shadowRadius: {},
|
|
shadowMapSize: {}
|
|
} },
|
|
directionalShadowMap: { value: [] },
|
|
directionalShadowMatrix: { value: [] },
|
|
spotLights: { value: [], properties: {
|
|
color: {},
|
|
position: {},
|
|
direction: {},
|
|
distance: {},
|
|
coneCos: {},
|
|
penumbraCos: {},
|
|
decay: {}
|
|
} },
|
|
spotLightShadows: { value: [], properties: {
|
|
shadowIntensity: 1,
|
|
shadowBias: {},
|
|
shadowNormalBias: {},
|
|
shadowRadius: {},
|
|
shadowMapSize: {}
|
|
} },
|
|
spotLightMap: { value: [] },
|
|
spotShadowMap: { value: [] },
|
|
spotLightMatrix: { value: [] },
|
|
pointLights: { value: [], properties: {
|
|
color: {},
|
|
position: {},
|
|
decay: {},
|
|
distance: {}
|
|
} },
|
|
pointLightShadows: { value: [], properties: {
|
|
shadowIntensity: 1,
|
|
shadowBias: {},
|
|
shadowNormalBias: {},
|
|
shadowRadius: {},
|
|
shadowMapSize: {},
|
|
shadowCameraNear: {},
|
|
shadowCameraFar: {}
|
|
} },
|
|
pointShadowMap: { value: [] },
|
|
pointShadowMatrix: { value: [] },
|
|
hemisphereLights: { value: [], properties: {
|
|
direction: {},
|
|
skyColor: {},
|
|
groundColor: {}
|
|
} },
|
|
rectAreaLights: { value: [], properties: {
|
|
color: {},
|
|
position: {},
|
|
width: {},
|
|
height: {}
|
|
} },
|
|
ltc_1: { value: null },
|
|
ltc_2: { value: null }
|
|
},
|
|
points: {
|
|
diffuse: { value: /* @__PURE__ */ new Color(16777215) },
|
|
opacity: { value: 1 },
|
|
size: { value: 1 },
|
|
scale: { value: 1 },
|
|
map: { value: null },
|
|
alphaMap: { value: null },
|
|
alphaMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
alphaTest: { value: 0 },
|
|
uvTransform: { value: /* @__PURE__ */ new Matrix3 }
|
|
},
|
|
sprite: {
|
|
diffuse: { value: /* @__PURE__ */ new Color(16777215) },
|
|
opacity: { value: 1 },
|
|
center: { value: /* @__PURE__ */ new Vector2(0.5, 0.5) },
|
|
rotation: { value: 0 },
|
|
map: { value: null },
|
|
mapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
alphaMap: { value: null },
|
|
alphaMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
alphaTest: { value: 0 }
|
|
}
|
|
};
|
|
ShaderLib = {
|
|
basic: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.specularmap,
|
|
UniformsLib.envmap,
|
|
UniformsLib.aomap,
|
|
UniformsLib.lightmap,
|
|
UniformsLib.fog
|
|
]),
|
|
vertexShader: ShaderChunk.meshbasic_vert,
|
|
fragmentShader: ShaderChunk.meshbasic_frag
|
|
},
|
|
lambert: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.specularmap,
|
|
UniformsLib.envmap,
|
|
UniformsLib.aomap,
|
|
UniformsLib.lightmap,
|
|
UniformsLib.emissivemap,
|
|
UniformsLib.bumpmap,
|
|
UniformsLib.normalmap,
|
|
UniformsLib.displacementmap,
|
|
UniformsLib.fog,
|
|
UniformsLib.lights,
|
|
{
|
|
emissive: { value: /* @__PURE__ */ new Color(0) }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.meshlambert_vert,
|
|
fragmentShader: ShaderChunk.meshlambert_frag
|
|
},
|
|
phong: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.specularmap,
|
|
UniformsLib.envmap,
|
|
UniformsLib.aomap,
|
|
UniformsLib.lightmap,
|
|
UniformsLib.emissivemap,
|
|
UniformsLib.bumpmap,
|
|
UniformsLib.normalmap,
|
|
UniformsLib.displacementmap,
|
|
UniformsLib.fog,
|
|
UniformsLib.lights,
|
|
{
|
|
emissive: { value: /* @__PURE__ */ new Color(0) },
|
|
specular: { value: /* @__PURE__ */ new Color(1118481) },
|
|
shininess: { value: 30 }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.meshphong_vert,
|
|
fragmentShader: ShaderChunk.meshphong_frag
|
|
},
|
|
standard: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.envmap,
|
|
UniformsLib.aomap,
|
|
UniformsLib.lightmap,
|
|
UniformsLib.emissivemap,
|
|
UniformsLib.bumpmap,
|
|
UniformsLib.normalmap,
|
|
UniformsLib.displacementmap,
|
|
UniformsLib.roughnessmap,
|
|
UniformsLib.metalnessmap,
|
|
UniformsLib.fog,
|
|
UniformsLib.lights,
|
|
{
|
|
emissive: { value: /* @__PURE__ */ new Color(0) },
|
|
roughness: { value: 1 },
|
|
metalness: { value: 0 },
|
|
envMapIntensity: { value: 1 }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.meshphysical_vert,
|
|
fragmentShader: ShaderChunk.meshphysical_frag
|
|
},
|
|
toon: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.aomap,
|
|
UniformsLib.lightmap,
|
|
UniformsLib.emissivemap,
|
|
UniformsLib.bumpmap,
|
|
UniformsLib.normalmap,
|
|
UniformsLib.displacementmap,
|
|
UniformsLib.gradientmap,
|
|
UniformsLib.fog,
|
|
UniformsLib.lights,
|
|
{
|
|
emissive: { value: /* @__PURE__ */ new Color(0) }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.meshtoon_vert,
|
|
fragmentShader: ShaderChunk.meshtoon_frag
|
|
},
|
|
matcap: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.bumpmap,
|
|
UniformsLib.normalmap,
|
|
UniformsLib.displacementmap,
|
|
UniformsLib.fog,
|
|
{
|
|
matcap: { value: null }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.meshmatcap_vert,
|
|
fragmentShader: ShaderChunk.meshmatcap_frag
|
|
},
|
|
points: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.points,
|
|
UniformsLib.fog
|
|
]),
|
|
vertexShader: ShaderChunk.points_vert,
|
|
fragmentShader: ShaderChunk.points_frag
|
|
},
|
|
dashed: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.fog,
|
|
{
|
|
scale: { value: 1 },
|
|
dashSize: { value: 1 },
|
|
totalSize: { value: 2 }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.linedashed_vert,
|
|
fragmentShader: ShaderChunk.linedashed_frag
|
|
},
|
|
depth: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.displacementmap
|
|
]),
|
|
vertexShader: ShaderChunk.depth_vert,
|
|
fragmentShader: ShaderChunk.depth_frag
|
|
},
|
|
normal: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.bumpmap,
|
|
UniformsLib.normalmap,
|
|
UniformsLib.displacementmap,
|
|
{
|
|
opacity: { value: 1 }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.meshnormal_vert,
|
|
fragmentShader: ShaderChunk.meshnormal_frag
|
|
},
|
|
sprite: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.sprite,
|
|
UniformsLib.fog
|
|
]),
|
|
vertexShader: ShaderChunk.sprite_vert,
|
|
fragmentShader: ShaderChunk.sprite_frag
|
|
},
|
|
background: {
|
|
uniforms: {
|
|
uvTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
t2D: { value: null },
|
|
backgroundIntensity: { value: 1 }
|
|
},
|
|
vertexShader: ShaderChunk.background_vert,
|
|
fragmentShader: ShaderChunk.background_frag
|
|
},
|
|
backgroundCube: {
|
|
uniforms: {
|
|
envMap: { value: null },
|
|
flipEnvMap: { value: -1 },
|
|
backgroundBlurriness: { value: 0 },
|
|
backgroundIntensity: { value: 1 },
|
|
backgroundRotation: { value: /* @__PURE__ */ new Matrix3 }
|
|
},
|
|
vertexShader: ShaderChunk.backgroundCube_vert,
|
|
fragmentShader: ShaderChunk.backgroundCube_frag
|
|
},
|
|
cube: {
|
|
uniforms: {
|
|
tCube: { value: null },
|
|
tFlip: { value: -1 },
|
|
opacity: { value: 1 }
|
|
},
|
|
vertexShader: ShaderChunk.cube_vert,
|
|
fragmentShader: ShaderChunk.cube_frag
|
|
},
|
|
equirect: {
|
|
uniforms: {
|
|
tEquirect: { value: null }
|
|
},
|
|
vertexShader: ShaderChunk.equirect_vert,
|
|
fragmentShader: ShaderChunk.equirect_frag
|
|
},
|
|
distanceRGBA: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.common,
|
|
UniformsLib.displacementmap,
|
|
{
|
|
referencePosition: { value: /* @__PURE__ */ new Vector3 },
|
|
nearDistance: { value: 1 },
|
|
farDistance: { value: 1000 }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.distanceRGBA_vert,
|
|
fragmentShader: ShaderChunk.distanceRGBA_frag
|
|
},
|
|
shadow: {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
UniformsLib.lights,
|
|
UniformsLib.fog,
|
|
{
|
|
color: { value: /* @__PURE__ */ new Color(0) },
|
|
opacity: { value: 1 }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.shadow_vert,
|
|
fragmentShader: ShaderChunk.shadow_frag
|
|
}
|
|
};
|
|
ShaderLib.physical = {
|
|
uniforms: /* @__PURE__ */ mergeUniforms([
|
|
ShaderLib.standard.uniforms,
|
|
{
|
|
clearcoat: { value: 0 },
|
|
clearcoatMap: { value: null },
|
|
clearcoatMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
clearcoatNormalMap: { value: null },
|
|
clearcoatNormalMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
clearcoatNormalScale: { value: /* @__PURE__ */ new Vector2(1, 1) },
|
|
clearcoatRoughness: { value: 0 },
|
|
clearcoatRoughnessMap: { value: null },
|
|
clearcoatRoughnessMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
dispersion: { value: 0 },
|
|
iridescence: { value: 0 },
|
|
iridescenceMap: { value: null },
|
|
iridescenceMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
iridescenceIOR: { value: 1.3 },
|
|
iridescenceThicknessMinimum: { value: 100 },
|
|
iridescenceThicknessMaximum: { value: 400 },
|
|
iridescenceThicknessMap: { value: null },
|
|
iridescenceThicknessMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
sheen: { value: 0 },
|
|
sheenColor: { value: /* @__PURE__ */ new Color(0) },
|
|
sheenColorMap: { value: null },
|
|
sheenColorMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
sheenRoughness: { value: 1 },
|
|
sheenRoughnessMap: { value: null },
|
|
sheenRoughnessMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
transmission: { value: 0 },
|
|
transmissionMap: { value: null },
|
|
transmissionMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
transmissionSamplerSize: { value: /* @__PURE__ */ new Vector2 },
|
|
transmissionSamplerMap: { value: null },
|
|
thickness: { value: 0 },
|
|
thicknessMap: { value: null },
|
|
thicknessMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
attenuationDistance: { value: 0 },
|
|
attenuationColor: { value: /* @__PURE__ */ new Color(0) },
|
|
specularColor: { value: /* @__PURE__ */ new Color(1, 1, 1) },
|
|
specularColorMap: { value: null },
|
|
specularColorMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
specularIntensity: { value: 1 },
|
|
specularIntensityMap: { value: null },
|
|
specularIntensityMapTransform: { value: /* @__PURE__ */ new Matrix3 },
|
|
anisotropyVector: { value: /* @__PURE__ */ new Vector2 },
|
|
anisotropyMap: { value: null },
|
|
anisotropyMapTransform: { value: /* @__PURE__ */ new Matrix3 }
|
|
}
|
|
]),
|
|
vertexShader: ShaderChunk.meshphysical_vert,
|
|
fragmentShader: ShaderChunk.meshphysical_frag
|
|
};
|
|
_rgb = { r: 0, b: 0, g: 0 };
|
|
_e1$1 = /* @__PURE__ */ new Euler;
|
|
_m1$12 = /* @__PURE__ */ new Matrix4;
|
|
EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
|
|
_flatCamera = /* @__PURE__ */ new OrthographicCamera;
|
|
_clearColor = /* @__PURE__ */ new Color;
|
|
PHI = (1 + Math.sqrt(5)) / 2;
|
|
INV_PHI = 1 / PHI;
|
|
_axisDirections = [
|
|
/* @__PURE__ */ new Vector3(-PHI, INV_PHI, 0),
|
|
/* @__PURE__ */ new Vector3(PHI, INV_PHI, 0),
|
|
/* @__PURE__ */ new Vector3(-INV_PHI, 0, PHI),
|
|
/* @__PURE__ */ new Vector3(INV_PHI, 0, PHI),
|
|
/* @__PURE__ */ new Vector3(0, PHI, -INV_PHI),
|
|
/* @__PURE__ */ new Vector3(0, PHI, INV_PHI),
|
|
/* @__PURE__ */ new Vector3(-1, 1, -1),
|
|
/* @__PURE__ */ new Vector3(1, 1, -1),
|
|
/* @__PURE__ */ new Vector3(-1, 1, 1),
|
|
/* @__PURE__ */ new Vector3(1, 1, 1)
|
|
];
|
|
emptyTexture = /* @__PURE__ */ new Texture;
|
|
emptyShadowTexture = /* @__PURE__ */ new DepthTexture(1, 1);
|
|
emptyArrayTexture = /* @__PURE__ */ new DataArrayTexture;
|
|
empty3dTexture = /* @__PURE__ */ new Data3DTexture;
|
|
emptyCubeTexture = /* @__PURE__ */ new CubeTexture;
|
|
arrayCacheF32 = [];
|
|
arrayCacheI32 = [];
|
|
mat4array = new Float32Array(16);
|
|
mat3array = new Float32Array(9);
|
|
mat2array = new Float32Array(4);
|
|
RePathPart = /(\w+)(\])?(\[|\.)?/g;
|
|
_m0 = /* @__PURE__ */ new Matrix3;
|
|
_v02 = /* @__PURE__ */ new Vector3;
|
|
includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
|
|
shaderChunkMap = new Map;
|
|
unrollLoopPattern = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;
|
|
reversedFuncs = {
|
|
[NeverDepth]: AlwaysDepth,
|
|
[LessDepth]: GreaterDepth,
|
|
[EqualDepth]: NotEqualDepth,
|
|
[LessEqualDepth]: GreaterEqualDepth,
|
|
[AlwaysDepth]: NeverDepth,
|
|
[GreaterDepth]: LessDepth,
|
|
[NotEqualDepth]: EqualDepth,
|
|
[GreaterEqualDepth]: LessEqualDepth
|
|
};
|
|
WebGLMultiviewRenderTarget = class WebGLMultiviewRenderTarget extends WebGLRenderTarget {
|
|
constructor(width, height, numViews, options = {}) {
|
|
super(width, height, options);
|
|
this.depthBuffer = false;
|
|
this.stencilBuffer = false;
|
|
this.numViews = numViews;
|
|
}
|
|
copy(source) {
|
|
super.copy(source);
|
|
this.numViews = source.numViews;
|
|
return this;
|
|
}
|
|
};
|
|
WebGLMultiviewRenderTarget.prototype.isWebGLMultiviewRenderTarget = true;
|
|
WebXRManager = class WebXRManager extends EventDispatcher {
|
|
constructor(renderer, gl, extensions, useMultiview) {
|
|
super();
|
|
const scope = this;
|
|
let session = null;
|
|
let framebufferScaleFactor = 1;
|
|
var poseTarget = null;
|
|
let referenceSpace = null;
|
|
let referenceSpaceType = "local-floor";
|
|
let foveation = 1;
|
|
let customReferenceSpace = null;
|
|
let pose = null;
|
|
var layers = [];
|
|
let glBinding = null;
|
|
let glProjLayer = null;
|
|
let glBaseLayer = null;
|
|
let xrFrame = null;
|
|
const depthSensing = new WebXRDepthSensing;
|
|
const attributes = gl.getContextAttributes();
|
|
let initialRenderTarget = null;
|
|
let newRenderTarget = null;
|
|
const controllers = [];
|
|
const controllerInputSources = [];
|
|
const currentSize = new Vector2;
|
|
let currentPixelRatio = null;
|
|
const cameraL = new PerspectiveCamera;
|
|
cameraL.viewport = new Vector4;
|
|
const cameraR = new PerspectiveCamera;
|
|
cameraR.viewport = new Vector4;
|
|
const cameras = [cameraL, cameraR];
|
|
const cameraXR = new ArrayCamera;
|
|
let _currentDepthNear = null;
|
|
let _currentDepthFar = null;
|
|
this.cameraAutoUpdate = true;
|
|
this.layersEnabled = false;
|
|
this.enabled = false;
|
|
this.isPresenting = false;
|
|
this.isMultiview = false;
|
|
this.getCameraPose = function() {
|
|
return pose;
|
|
};
|
|
this.getController = function(index) {
|
|
let controller = controllers[index];
|
|
if (controller === undefined) {
|
|
controller = new WebXRController;
|
|
controllers[index] = controller;
|
|
}
|
|
return controller.getTargetRaySpace();
|
|
};
|
|
this.getControllerGrip = function(index) {
|
|
let controller = controllers[index];
|
|
if (controller === undefined) {
|
|
controller = new WebXRController;
|
|
controllers[index] = controller;
|
|
}
|
|
return controller.getGripSpace();
|
|
};
|
|
this.getHand = function(index) {
|
|
let controller = controllers[index];
|
|
if (controller === undefined) {
|
|
controller = new WebXRController;
|
|
controllers[index] = controller;
|
|
}
|
|
return controller.getHandSpace();
|
|
};
|
|
function onSessionEvent(event) {
|
|
const controllerIndex = controllerInputSources.indexOf(event.inputSource);
|
|
if (controllerIndex === -1) {
|
|
return;
|
|
}
|
|
const controller = controllers[controllerIndex];
|
|
if (controller !== undefined) {
|
|
controller.update(event.inputSource, event.frame, customReferenceSpace || referenceSpace);
|
|
controller.dispatchEvent({ type: event.type, data: event.inputSource });
|
|
}
|
|
}
|
|
function onSessionEnd() {
|
|
session.removeEventListener("select", onSessionEvent);
|
|
session.removeEventListener("selectstart", onSessionEvent);
|
|
session.removeEventListener("selectend", onSessionEvent);
|
|
session.removeEventListener("squeeze", onSessionEvent);
|
|
session.removeEventListener("squeezestart", onSessionEvent);
|
|
session.removeEventListener("squeezeend", onSessionEvent);
|
|
session.removeEventListener("end", onSessionEnd);
|
|
session.removeEventListener("inputsourceschange", onInputSourcesChange);
|
|
for (let i = 0;i < controllers.length; i++) {
|
|
const inputSource = controllerInputSources[i];
|
|
if (inputSource === null)
|
|
continue;
|
|
controllerInputSources[i] = null;
|
|
controllers[i].disconnect(inputSource);
|
|
}
|
|
_currentDepthNear = null;
|
|
_currentDepthFar = null;
|
|
depthSensing.reset();
|
|
scope.isPresenting = false;
|
|
renderer.setRenderTarget(initialRenderTarget);
|
|
glBaseLayer = null;
|
|
glProjLayer = null;
|
|
glBinding = null;
|
|
session = null;
|
|
newRenderTarget = null;
|
|
animation.stop();
|
|
renderer.setPixelRatio(currentPixelRatio);
|
|
renderer.setSize(currentSize.width, currentSize.height, false);
|
|
scope.dispatchEvent({ type: "sessionend" });
|
|
}
|
|
this.setFramebufferScaleFactor = function(value) {
|
|
framebufferScaleFactor = value;
|
|
if (scope.isPresenting === true) {
|
|
console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.");
|
|
}
|
|
};
|
|
this.setReferenceSpaceType = function(value) {
|
|
referenceSpaceType = value;
|
|
if (scope.isPresenting === true) {
|
|
console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.");
|
|
}
|
|
};
|
|
this.getReferenceSpace = function() {
|
|
return customReferenceSpace || referenceSpace;
|
|
};
|
|
this.setReferenceSpace = function(space) {
|
|
customReferenceSpace = space;
|
|
};
|
|
this.getBaseLayer = function() {
|
|
return glProjLayer !== null ? glProjLayer : glBaseLayer;
|
|
};
|
|
this.getBinding = function() {
|
|
return glBinding;
|
|
};
|
|
this.getRenderTarget = function() {
|
|
return newRenderTarget;
|
|
};
|
|
this.getFrame = function() {
|
|
return xrFrame;
|
|
};
|
|
this.getSession = function() {
|
|
return session;
|
|
};
|
|
this.setSession = async function(value) {
|
|
session = value;
|
|
if (session !== null) {
|
|
initialRenderTarget = renderer.getRenderTarget();
|
|
session.addEventListener("select", onSessionEvent);
|
|
session.addEventListener("selectstart", onSessionEvent);
|
|
session.addEventListener("selectend", onSessionEvent);
|
|
session.addEventListener("squeeze", onSessionEvent);
|
|
session.addEventListener("squeezestart", onSessionEvent);
|
|
session.addEventListener("squeezeend", onSessionEvent);
|
|
session.addEventListener("end", onSessionEnd);
|
|
session.addEventListener("inputsourceschange", onInputSourcesChange);
|
|
if (attributes.xrCompatible !== true) {
|
|
await gl.makeXRCompatible();
|
|
}
|
|
currentPixelRatio = renderer.getPixelRatio();
|
|
renderer.getSize(currentSize);
|
|
const useLayers = typeof XRWebGLBinding !== "undefined" && "createProjectionLayer" in XRWebGLBinding.prototype;
|
|
if (!useLayers) {
|
|
const layerInit = {
|
|
antialias: attributes.antialias,
|
|
alpha: true,
|
|
depth: attributes.depth,
|
|
stencil: attributes.stencil,
|
|
framebufferScaleFactor
|
|
};
|
|
glBaseLayer = new XRWebGLLayer(session, gl, layerInit);
|
|
session.updateRenderState({ baseLayer: glBaseLayer });
|
|
renderer.setPixelRatio(1);
|
|
renderer.setSize(glBaseLayer.framebufferWidth, glBaseLayer.framebufferHeight, false);
|
|
newRenderTarget = new WebGLRenderTarget(glBaseLayer.framebufferWidth, glBaseLayer.framebufferHeight, {
|
|
format: RGBAFormat,
|
|
type: UnsignedByteType,
|
|
colorSpace: renderer.outputColorSpace,
|
|
stencilBuffer: attributes.stencil
|
|
});
|
|
} else {
|
|
let depthFormat = null;
|
|
let depthType = null;
|
|
let glDepthFormat = null;
|
|
if (attributes.depth) {
|
|
glDepthFormat = attributes.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24;
|
|
depthFormat = attributes.stencil ? DepthStencilFormat : DepthFormat;
|
|
depthType = attributes.stencil ? UnsignedInt248Type : UnsignedIntType;
|
|
}
|
|
scope.isMultiview = useMultiview && extensions.has("OCULUS_multiview");
|
|
const projectionlayerInit = {
|
|
colorFormat: gl.RGBA8,
|
|
depthFormat: glDepthFormat,
|
|
scaleFactor: framebufferScaleFactor
|
|
};
|
|
if (scope.isMultiview) {
|
|
projectionlayerInit.textureType = "texture-array";
|
|
}
|
|
glBinding = new XRWebGLBinding(session, gl);
|
|
glProjLayer = glBinding.createProjectionLayer(projectionlayerInit);
|
|
session.updateRenderState({ layers: [glProjLayer] });
|
|
renderer.setPixelRatio(1);
|
|
renderer.setSize(glProjLayer.textureWidth, glProjLayer.textureHeight, false);
|
|
const renderTargetOptions = {
|
|
format: RGBAFormat,
|
|
type: UnsignedByteType,
|
|
depthTexture: new DepthTexture(glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat),
|
|
stencilBuffer: attributes.stencil,
|
|
colorSpace: renderer.outputColorSpace,
|
|
samples: attributes.antialias ? 4 : 0,
|
|
resolveDepthBuffer: glProjLayer.ignoreDepthValues === false
|
|
};
|
|
if (scope.isMultiview) {
|
|
const extension = extensions.get("OCULUS_multiview");
|
|
this.maxNumViews = gl.getParameter(extension.MAX_VIEWS_OVR);
|
|
newRenderTarget = new WebGLMultiviewRenderTarget(glProjLayer.textureWidth, glProjLayer.textureHeight, 2, renderTargetOptions);
|
|
} else {
|
|
newRenderTarget = new WebGLRenderTarget(glProjLayer.textureWidth, glProjLayer.textureHeight, renderTargetOptions);
|
|
}
|
|
}
|
|
newRenderTarget.isXRRenderTarget = true;
|
|
this.setFoveation(foveation);
|
|
customReferenceSpace = null;
|
|
referenceSpace = await session.requestReferenceSpace(referenceSpaceType);
|
|
animation.setContext(session);
|
|
animation.start();
|
|
scope.isPresenting = true;
|
|
scope.dispatchEvent({ type: "sessionstart" });
|
|
}
|
|
};
|
|
this.getEnvironmentBlendMode = function() {
|
|
if (session !== null) {
|
|
return session.environmentBlendMode;
|
|
}
|
|
};
|
|
this.addLayer = function(layer) {
|
|
if (!window.XRWebGLBinding || !this.layersEnabled || !session) {
|
|
return;
|
|
}
|
|
layers.push(layer);
|
|
this.updateLayers();
|
|
};
|
|
this.removeLayer = function(layer) {
|
|
layers.splice(layers.indexOf(layer), 1);
|
|
if (!window.XRWebGLBinding || !this.layersEnabled || !session) {
|
|
return;
|
|
}
|
|
this.updateLayers();
|
|
};
|
|
this.updateLayers = function() {
|
|
var layersCopy = layers.map(function(x) {
|
|
return x;
|
|
});
|
|
layersCopy.unshift(session.renderState.layers[0]);
|
|
session.updateRenderState({ layers: layersCopy });
|
|
};
|
|
this.getDepthTexture = function() {
|
|
return depthSensing.getDepthTexture();
|
|
};
|
|
function onInputSourcesChange(event) {
|
|
for (let i = 0;i < event.removed.length; i++) {
|
|
const inputSource = event.removed[i];
|
|
const index = controllerInputSources.indexOf(inputSource);
|
|
if (index >= 0) {
|
|
controllerInputSources[index] = null;
|
|
controllers[index].disconnect(inputSource);
|
|
}
|
|
}
|
|
for (let i = 0;i < event.added.length; i++) {
|
|
const inputSource = event.added[i];
|
|
let controllerIndex = controllerInputSources.indexOf(inputSource);
|
|
if (controllerIndex === -1) {
|
|
for (let i2 = 0;i2 < controllers.length; i2++) {
|
|
if (i2 >= controllerInputSources.length) {
|
|
controllerInputSources.push(inputSource);
|
|
controllerIndex = i2;
|
|
break;
|
|
} else if (controllerInputSources[i2] === null) {
|
|
controllerInputSources[i2] = inputSource;
|
|
controllerIndex = i2;
|
|
break;
|
|
}
|
|
}
|
|
if (controllerIndex === -1)
|
|
break;
|
|
}
|
|
const controller = controllers[controllerIndex];
|
|
if (controller) {
|
|
controller.connect(inputSource);
|
|
}
|
|
}
|
|
}
|
|
const cameraLPos = new Vector3;
|
|
const cameraRPos = new Vector3;
|
|
function setProjectionFromUnion(camera, cameraL2, cameraR2) {
|
|
cameraLPos.setFromMatrixPosition(cameraL2.matrixWorld);
|
|
cameraRPos.setFromMatrixPosition(cameraR2.matrixWorld);
|
|
const ipd = cameraLPos.distanceTo(cameraRPos);
|
|
const projL = cameraL2.projectionMatrix.elements;
|
|
const projR = cameraR2.projectionMatrix.elements;
|
|
const near = projL[14] / (projL[10] - 1);
|
|
const far = projL[14] / (projL[10] + 1);
|
|
const topFov = (projL[9] + 1) / projL[5];
|
|
const bottomFov = (projL[9] - 1) / projL[5];
|
|
const leftFov = (projL[8] - 1) / projL[0];
|
|
const rightFov = (projR[8] + 1) / projR[0];
|
|
const left = near * leftFov;
|
|
const right = near * rightFov;
|
|
const zOffset = ipd / (-leftFov + rightFov);
|
|
const xOffset = zOffset * -leftFov;
|
|
cameraL2.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
|
|
camera.translateX(xOffset);
|
|
camera.translateZ(zOffset);
|
|
camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
|
|
camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
|
|
if (projL[10] === -1) {
|
|
camera.projectionMatrix.copy(cameraL2.projectionMatrix);
|
|
camera.projectionMatrixInverse.copy(cameraL2.projectionMatrixInverse);
|
|
} else {
|
|
const near2 = near + zOffset;
|
|
const far2 = far + zOffset;
|
|
const left2 = left - xOffset;
|
|
const right2 = right + (ipd - xOffset);
|
|
const top2 = topFov * far / far2 * near2;
|
|
const bottom2 = bottomFov * far / far2 * near2;
|
|
camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
|
|
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
}
|
|
}
|
|
function updateCamera(camera, parent) {
|
|
if (parent === null) {
|
|
camera.matrixWorld.copy(camera.matrix);
|
|
} else {
|
|
camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
|
|
}
|
|
camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
|
|
}
|
|
this.setPoseTarget = function(object) {
|
|
if (object !== undefined)
|
|
poseTarget = object;
|
|
};
|
|
this.updateCamera = function(camera) {
|
|
if (session === null)
|
|
return;
|
|
let depthNear = camera.near;
|
|
let depthFar = camera.far;
|
|
if (depthSensing.texture !== null) {
|
|
if (depthSensing.depthNear > 0)
|
|
depthNear = depthSensing.depthNear;
|
|
if (depthSensing.depthFar > 0)
|
|
depthFar = depthSensing.depthFar;
|
|
}
|
|
cameraXR.near = cameraR.near = cameraL.near = depthNear;
|
|
cameraXR.far = cameraR.far = cameraL.far = depthFar;
|
|
if (_currentDepthNear !== cameraXR.near || _currentDepthFar !== cameraXR.far) {
|
|
session.updateRenderState({
|
|
depthNear: cameraXR.near,
|
|
depthFar: cameraXR.far
|
|
});
|
|
_currentDepthNear = cameraXR.near;
|
|
_currentDepthFar = cameraXR.far;
|
|
}
|
|
cameraL.layers.mask = camera.layers.mask | 2;
|
|
cameraR.layers.mask = camera.layers.mask | 4;
|
|
cameraXR.layers.mask = cameraL.layers.mask | cameraR.layers.mask;
|
|
const cameras2 = cameraXR.cameras;
|
|
var object = poseTarget || camera;
|
|
const parent = object.parent;
|
|
updateCamera(cameraXR, parent);
|
|
for (let i = 0;i < cameras2.length; i++) {
|
|
updateCamera(cameras2[i], parent);
|
|
}
|
|
if (cameras2.length === 2) {
|
|
setProjectionFromUnion(cameraXR, cameraL, cameraR);
|
|
} else {
|
|
cameraXR.projectionMatrix.copy(cameraL.projectionMatrix);
|
|
}
|
|
updateUserCamera(camera, cameraXR, object);
|
|
};
|
|
function updateUserCamera(camera, cameraXR2, object) {
|
|
cameraXR2.matrixWorld.decompose(cameraXR2.position, cameraXR2.quaternion, cameraXR2.scale);
|
|
if (object.parent === null) {
|
|
object.matrix.copy(cameraXR2.matrixWorld);
|
|
} else {
|
|
object.matrix.copy(object.parent.matrixWorld);
|
|
object.matrix.invert();
|
|
object.matrix.multiply(cameraXR2.matrixWorld);
|
|
}
|
|
object.matrix.decompose(object.position, object.quaternion, object.scale);
|
|
object.updateMatrixWorld(true);
|
|
camera.projectionMatrix.copy(cameraXR2.projectionMatrix);
|
|
camera.projectionMatrixInverse.copy(cameraXR2.projectionMatrixInverse);
|
|
if (camera.isPerspectiveCamera) {
|
|
camera.fov = RAD2DEG * 2 * Math.atan(1 / camera.projectionMatrix.elements[5]);
|
|
camera.zoom = 1;
|
|
}
|
|
}
|
|
this.getCamera = function() {
|
|
return cameraXR;
|
|
};
|
|
this.getFoveation = function() {
|
|
if (glProjLayer === null && glBaseLayer === null) {
|
|
return;
|
|
}
|
|
return foveation;
|
|
};
|
|
this.setFoveation = function(value) {
|
|
foveation = value;
|
|
if (glProjLayer !== null) {
|
|
glProjLayer.fixedFoveation = value;
|
|
}
|
|
if (glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined) {
|
|
glBaseLayer.fixedFoveation = value;
|
|
}
|
|
};
|
|
this.hasDepthSensing = function() {
|
|
return depthSensing.texture !== null;
|
|
};
|
|
this.getDepthSensingMesh = function() {
|
|
return depthSensing.getMesh(cameraXR);
|
|
};
|
|
let onAnimationFrameCallback = null;
|
|
function onAnimationFrame(time, frame) {
|
|
pose = frame.getViewerPose(customReferenceSpace || referenceSpace);
|
|
xrFrame = frame;
|
|
if (pose !== null) {
|
|
const views = pose.views;
|
|
if (glBaseLayer !== null) {
|
|
renderer.setRenderTargetFramebuffer(newRenderTarget, glBaseLayer.framebuffer);
|
|
renderer.setRenderTarget(newRenderTarget);
|
|
}
|
|
let cameraXRNeedsUpdate = false;
|
|
if (views.length !== cameraXR.cameras.length) {
|
|
cameraXR.cameras.length = 0;
|
|
cameraXRNeedsUpdate = true;
|
|
}
|
|
for (let i = 0;i < views.length; i++) {
|
|
const view = views[i];
|
|
let viewport = null;
|
|
if (glBaseLayer !== null) {
|
|
viewport = glBaseLayer.getViewport(view);
|
|
} else {
|
|
const glSubImage = glBinding.getViewSubImage(glProjLayer, view);
|
|
viewport = glSubImage.viewport;
|
|
if (i === 0) {
|
|
renderer.setRenderTargetTextures(newRenderTarget, glSubImage.colorTexture, glProjLayer.ignoreDepthValues ? undefined : glSubImage.depthStencilTexture);
|
|
renderer.setRenderTarget(newRenderTarget);
|
|
}
|
|
}
|
|
let camera = cameras[i];
|
|
if (camera === undefined) {
|
|
camera = new PerspectiveCamera;
|
|
camera.layers.enable(i);
|
|
camera.viewport = new Vector4;
|
|
cameras[i] = camera;
|
|
}
|
|
camera.matrix.fromArray(view.transform.matrix);
|
|
camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
|
|
camera.projectionMatrix.fromArray(view.projectionMatrix);
|
|
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
|
|
if (i === 0) {
|
|
cameraXR.matrix.copy(camera.matrix);
|
|
cameraXR.matrix.decompose(cameraXR.position, cameraXR.quaternion, cameraXR.scale);
|
|
}
|
|
if (cameraXRNeedsUpdate === true) {
|
|
cameraXR.cameras.push(camera);
|
|
}
|
|
}
|
|
const enabledFeatures = session.enabledFeatures;
|
|
const gpuDepthSensingEnabled = enabledFeatures && enabledFeatures.includes("depth-sensing") && session.depthUsage == "gpu-optimized";
|
|
if (gpuDepthSensingEnabled && glBinding) {
|
|
const depthData = glBinding.getDepthInformation(views[0]);
|
|
if (depthData && depthData.isValid && depthData.texture) {
|
|
depthSensing.init(renderer, depthData, session.renderState);
|
|
}
|
|
}
|
|
}
|
|
for (let i = 0;i < controllers.length; i++) {
|
|
const inputSource = controllerInputSources[i];
|
|
const controller = controllers[i];
|
|
if (inputSource !== null && controller !== undefined) {
|
|
controller.update(inputSource, frame, customReferenceSpace || referenceSpace);
|
|
}
|
|
}
|
|
if (onAnimationFrameCallback)
|
|
onAnimationFrameCallback(time, frame);
|
|
if (frame.detectedPlanes) {
|
|
scope.dispatchEvent({ type: "planesdetected", data: frame });
|
|
}
|
|
xrFrame = null;
|
|
}
|
|
const animation = new WebGLAnimation;
|
|
animation.setAnimationLoop(onAnimationFrame);
|
|
this.setAnimationLoop = function(callback) {
|
|
onAnimationFrameCallback = callback;
|
|
};
|
|
this.dispose = function() {};
|
|
}
|
|
};
|
|
_e1 = /* @__PURE__ */ new Euler;
|
|
_m12 = /* @__PURE__ */ new Matrix4;
|
|
});
|
|
|
|
// node_modules/aframe/dist/aframe-master.module.min.js
|
|
var exports_aframe_master_module_min = {};
|
|
__export(exports_aframe_master_module_min, {
|
|
default: () => Vc
|
|
});
|
|
function i(e) {
|
|
var r = n[e];
|
|
if (r !== undefined)
|
|
return r.exports;
|
|
var o = n[e] = { id: e, exports: {} };
|
|
return t[e](o, o.exports, i), o.exports;
|
|
}
|
|
function b(e, t2, n2) {
|
|
return Math.min(Math.max(e, t2), n2);
|
|
}
|
|
function y(e, t2) {
|
|
return e.indexOf(t2) > -1;
|
|
}
|
|
function I(e, t2) {
|
|
return e.apply(null, t2);
|
|
}
|
|
function S(e) {
|
|
var t2 = M.exec(e);
|
|
return t2 ? t2[1].split(",").map(function(e2) {
|
|
return parseFloat(e2);
|
|
}) : [];
|
|
}
|
|
function D(e, t2) {
|
|
var n2 = S(e), i2 = b(L.und(n2[0]) ? 1 : n2[0], 0.1, 100), r2 = b(L.und(n2[1]) ? 100 : n2[1], 0.1, 100), o2 = b(L.und(n2[2]) ? 10 : n2[2], 0.1, 100), s2 = b(L.und(n2[3]) ? 0 : n2[3], 0.1, 100), a2 = Math.sqrt(r2 / i2), A2 = o2 / (2 * Math.sqrt(r2 * i2)), l2 = A2 < 1 ? a2 * Math.sqrt(1 - A2 * A2) : 0, c2 = A2 < 1 ? (A2 * a2 - s2) / l2 : -s2 + a2;
|
|
function h2(e2) {
|
|
var n3 = t2 ? t2 * e2 / 1000 : e2;
|
|
return n3 = A2 < 1 ? Math.exp(-n3 * A2 * a2) * (1 * Math.cos(l2 * n3) + c2 * Math.sin(l2 * n3)) : (1 + c2 * n3) * Math.exp(-n3 * a2), e2 === 0 || e2 === 1 ? e2 : 1 - n3;
|
|
}
|
|
return t2 ? h2 : function() {
|
|
var t3 = B.springs[e];
|
|
if (t3)
|
|
return t3;
|
|
for (var n3 = 1 / 6, i3 = 0, r3 = 0;; )
|
|
if (h2(i3 += n3) === 1) {
|
|
if (++r3 >= 16)
|
|
break;
|
|
} else
|
|
r3 = 0;
|
|
var o3 = i3 * n3 * 1000;
|
|
return B.springs[e] = o3, o3;
|
|
};
|
|
}
|
|
function k(e, t2) {
|
|
e === undefined && (e = 1), t2 === undefined && (t2 = 0.5);
|
|
var n2 = b(e, 1, 10), i2 = b(t2, 0.1, 2);
|
|
return function(e2) {
|
|
return e2 === 0 || e2 === 1 ? e2 : -n2 * Math.pow(2, 10 * (e2 - 1)) * Math.sin((e2 - 1 - i2 / (2 * Math.PI) * Math.asin(1 / n2)) * (2 * Math.PI) / i2);
|
|
};
|
|
}
|
|
function T(e) {
|
|
return e === undefined && (e = 10), function(t2) {
|
|
return Math.round(t2 * e) * (1 / e);
|
|
};
|
|
}
|
|
function U(e, t2) {
|
|
if (L.fnc(e))
|
|
return e;
|
|
var n2 = e.split("(")[0], i2 = F[n2], r2 = S(e);
|
|
switch (n2) {
|
|
case "spring":
|
|
return D(e, t2);
|
|
case "cubicBezier":
|
|
return I(R, r2);
|
|
case "steps":
|
|
return I(T, r2);
|
|
default:
|
|
return L.fnc(i2) ? I(i2, r2) : I(R, i2);
|
|
}
|
|
}
|
|
function O(e) {
|
|
try {
|
|
return document.querySelectorAll(e);
|
|
} catch (e2) {
|
|
return;
|
|
}
|
|
}
|
|
function G(e, t2) {
|
|
for (var n2 = P, i2 = e.length, r2 = arguments.length >= 2 ? arguments[1] : undefined, o2 = 0;o2 < i2; o2++)
|
|
if (o2 in e) {
|
|
var s2 = e[o2];
|
|
t2.call(r2, s2, o2, e) && n2.push(s2);
|
|
}
|
|
return (P = e).length = 0, n2;
|
|
}
|
|
function N(e, t2) {
|
|
t2 || (t2 = []);
|
|
for (var n2 = 0, i2 = e.length;n2 < i2; n2++) {
|
|
var r2 = e[n2];
|
|
Array.isArray(r2) ? N(r2, t2) : t2.push(r2);
|
|
}
|
|
return t2;
|
|
}
|
|
function j(e) {
|
|
return L.arr(e) ? e : (L.str(e) && (e = O(e) || e), e instanceof NodeList || e instanceof HTMLCollection ? [].slice.call(e) : [e]);
|
|
}
|
|
function _(e, t2) {
|
|
return e.some(function(e2) {
|
|
return e2 === t2;
|
|
});
|
|
}
|
|
function H(e) {
|
|
var t2 = {};
|
|
for (var n2 in e)
|
|
t2[n2] = e[n2];
|
|
return t2;
|
|
}
|
|
function q(e, t2) {
|
|
var n2 = H(e);
|
|
for (var i2 in e)
|
|
n2[i2] = t2.hasOwnProperty(i2) ? t2[i2] : e[i2];
|
|
return n2;
|
|
}
|
|
function V(e, t2) {
|
|
var n2 = H(e);
|
|
for (var i2 in t2)
|
|
n2[i2] = L.und(e[i2]) ? t2[i2] : e[i2];
|
|
return n2;
|
|
}
|
|
function Z(e) {
|
|
var t2 = X.exec(e);
|
|
if (t2)
|
|
return t2[2];
|
|
}
|
|
function $(e, t2) {
|
|
return L.fnc(e) ? e(t2.target, t2.id, t2.total) : e;
|
|
}
|
|
function ee(e, t2) {
|
|
return e.getAttribute(t2);
|
|
}
|
|
function te(e, t2, n2) {
|
|
if (_([n2, "deg", "rad", "turn"], Z(t2)))
|
|
return t2;
|
|
var i2 = B.CSS[t2 + n2];
|
|
if (!L.und(i2))
|
|
return i2;
|
|
var r2 = document.createElement(e.tagName), o2 = e.parentNode && e.parentNode !== document ? e.parentNode : document.body;
|
|
o2.appendChild(r2), r2.style.position = "absolute", r2.style.width = 100 + n2;
|
|
var s2 = 100 / r2.offsetWidth;
|
|
o2.removeChild(r2);
|
|
var a2 = s2 * parseFloat(t2);
|
|
return B.CSS[t2 + n2] = a2, a2;
|
|
}
|
|
function ne(e, t2, n2) {
|
|
if (t2 in e.style) {
|
|
var i2 = t2.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), r2 = e.style[t2] || getComputedStyle(e).getPropertyValue(i2) || "0";
|
|
return n2 ? te(e, r2, n2) : r2;
|
|
}
|
|
}
|
|
function ie(e, t2) {
|
|
return L.dom(e) && !L.inp(e) && (ee(e, t2) || L.svg(e) && e[t2]) ? "attribute" : L.dom(e) && _(v, t2) ? "transform" : L.dom(e) && t2 !== "transform" && ne(e, t2) ? "css" : e[t2] != null ? "object" : undefined;
|
|
}
|
|
function oe(e) {
|
|
if (L.dom(e)) {
|
|
for (var t2, n2 = e.style.transform || "", i2 = new Map;t2 = re.exec(n2); )
|
|
i2.set(t2[1], t2[2]);
|
|
return i2;
|
|
}
|
|
}
|
|
function se(e, t2, n2, i2) {
|
|
switch (ie(e, t2)) {
|
|
case "transform":
|
|
return function(e2, t3, n3, i3) {
|
|
var r2 = y(t3, "scale") ? 1 : 0 + function(e3) {
|
|
return y(e3, "translate") || e3 === "perspective" ? "px" : y(e3, "rotate") || y(e3, "skew") ? "deg" : undefined;
|
|
}(t3), o2 = oe(e2).get(t3) || r2;
|
|
return n3 && (n3.transforms.list.set(t3, o2), n3.transforms.last = t3), i3 ? te(e2, o2, i3) : o2;
|
|
}(e, t2, i2, n2);
|
|
case "css":
|
|
return ne(e, t2, n2);
|
|
case "attribute":
|
|
return ee(e, t2);
|
|
default:
|
|
return e[t2] || 0;
|
|
}
|
|
}
|
|
function Ae(e, t2) {
|
|
var n2 = ae.exec(e);
|
|
if (!n2)
|
|
return e;
|
|
var i2 = Z(e) || 0, r2 = parseFloat(t2), o2 = parseFloat(e.replace(n2[0], ""));
|
|
switch (n2[0][0]) {
|
|
case "+":
|
|
return r2 + o2 + i2;
|
|
case "-":
|
|
return r2 - o2 + i2;
|
|
case "*":
|
|
return r2 * o2 + i2;
|
|
}
|
|
}
|
|
function ce(e, t2) {
|
|
if (L.col(e))
|
|
return function(e2) {
|
|
return L.rgb(e2) ? (t3 = e2, (n3 = z.exec(t3)) ? "rgba(" + n3[1] + ",1)" : t3) : L.hex(e2) ? function(e3) {
|
|
var t4 = e3.replace(Y, function(e4, t5, n5, i3) {
|
|
return t5 + t5 + n5 + n5 + i3 + i3;
|
|
}), n4 = K.exec(t4);
|
|
return "rgba(" + parseInt(n4[1], 16) + "," + parseInt(n4[2], 16) + "," + parseInt(n4[3], 16) + ",1)";
|
|
}(e2) : L.hsl(e2) ? function(e3) {
|
|
var t4, n4, i3, r2 = W.exec(e3) || J.exec(e3), o2 = parseInt(r2[1], 10) / 360, s2 = parseInt(r2[2], 10) / 100, a2 = parseInt(r2[3], 10) / 100, A2 = r2[4] || 1;
|
|
function l2(e4, t5, n5) {
|
|
return n5 < 0 && (n5 += 1), n5 > 1 && (n5 -= 1), n5 < 1 / 6 ? e4 + 6 * (t5 - e4) * n5 : n5 < 0.5 ? t5 : n5 < 2 / 3 ? e4 + (t5 - e4) * (2 / 3 - n5) * 6 : e4;
|
|
}
|
|
if (s2 == 0)
|
|
t4 = n4 = i3 = a2;
|
|
else {
|
|
var c2 = a2 < 0.5 ? a2 * (1 + s2) : a2 + s2 - a2 * s2, h2 = 2 * a2 - c2;
|
|
t4 = l2(h2, c2, o2 + 1 / 3), n4 = l2(h2, c2, o2), i3 = l2(h2, c2, o2 - 1 / 3);
|
|
}
|
|
return "rgba(" + 255 * t4 + "," + 255 * n4 + "," + 255 * i3 + "," + A2 + ")";
|
|
}(e2) : undefined;
|
|
var t3, n3;
|
|
}(e);
|
|
var n2 = Z(e), i2 = n2 ? e.substr(0, e.length - n2.length) : e;
|
|
return t2 && !le.test(e) ? i2 + t2 : i2;
|
|
}
|
|
function he(e, t2) {
|
|
return Math.sqrt(Math.pow(t2.x - e.x, 2) + Math.pow(t2.y - e.y, 2));
|
|
}
|
|
function de(e) {
|
|
for (var t2, n2 = e.points, i2 = 0, r2 = 0;r2 < n2.numberOfItems; r2++) {
|
|
var o2 = n2.getItem(r2);
|
|
r2 > 0 && (i2 += he(t2, o2)), t2 = o2;
|
|
}
|
|
return i2;
|
|
}
|
|
function ue(e) {
|
|
if (e.getTotalLength)
|
|
return e.getTotalLength();
|
|
switch (e.tagName.toLowerCase()) {
|
|
case "circle":
|
|
return function(e2) {
|
|
return 2 * Math.PI * ee(e2, "r");
|
|
}(e);
|
|
case "rect":
|
|
return function(e2) {
|
|
return 2 * ee(e2, "width") + 2 * ee(e2, "height");
|
|
}(e);
|
|
case "line":
|
|
return function(e2) {
|
|
return he({ x: ee(e2, "x1"), y: ee(e2, "y1") }, { x: ee(e2, "x2"), y: ee(e2, "y2") });
|
|
}(e);
|
|
case "polyline":
|
|
return de(e);
|
|
case "polygon":
|
|
return function(e2) {
|
|
var t2 = e2.points;
|
|
return de(e2) + he(t2.getItem(t2.numberOfItems - 1), t2.getItem(0));
|
|
}(e);
|
|
}
|
|
}
|
|
function ge(e, t2) {
|
|
var n2 = t2 || {}, i2 = n2.el || function(e2) {
|
|
for (var t3 = e2.parentNode;L.svg(t3) && (t3 = t3.parentNode, L.svg(t3.parentNode)); )
|
|
;
|
|
return t3;
|
|
}(e), r2 = i2.getBoundingClientRect(), o2 = ee(i2, "viewBox"), s2 = r2.width, a2 = r2.height, A2 = n2.viewBox || (o2 ? o2.split(" ") : [0, 0, s2, a2]);
|
|
return { el: i2, viewBox: A2, x: A2[0] / 1, y: A2[1] / 1, w: s2 / A2[2], h: a2 / A2[3] };
|
|
}
|
|
function pe(e, t2) {
|
|
function n2(n3) {
|
|
n3 === undefined && (n3 = 0);
|
|
var i3 = t2 + n3 >= 1 ? t2 + n3 : 0;
|
|
return e.el.getPointAtLength(i3);
|
|
}
|
|
var i2 = ge(e.el, e.svg), r2 = n2(), o2 = n2(-1), s2 = n2(1);
|
|
switch (e.property) {
|
|
case "x":
|
|
return (r2.x - i2.x) * i2.w;
|
|
case "y":
|
|
return (r2.y - i2.y) * i2.h;
|
|
case "angle":
|
|
return 180 * Math.atan2(s2.y - o2.y, s2.x - o2.x) / Math.PI;
|
|
}
|
|
}
|
|
function me(e, t2) {
|
|
var n2 = ce(L.pth(e) ? e.totalLength : e, t2) + "";
|
|
return { original: n2, numbers: n2.match(fe) ? n2.match(fe).map(Number) : [0], strings: L.str(e) || t2 ? n2.split(fe) : [] };
|
|
}
|
|
function Ee(e) {
|
|
return G(e ? N(L.arr(e) ? e.map(j) : j(e)) : [], function(e2, t2, n2) {
|
|
return n2.indexOf(e2) === t2;
|
|
});
|
|
}
|
|
function Ce(e) {
|
|
var t2 = Ee(e);
|
|
return t2.map(function(e2, n2) {
|
|
return { target: e2, id: n2, total: t2.length, transforms: { list: oe(e2) } };
|
|
});
|
|
}
|
|
function Be(e, t2) {
|
|
var n2 = H(t2);
|
|
if (ve.test(n2.easing) && (n2.duration = D(n2.easing)), L.arr(e)) {
|
|
var i2 = e.length;
|
|
i2 !== 2 || L.obj(e[0]) ? L.fnc(t2.duration) || (n2.duration = t2.duration / i2) : e = { value: e };
|
|
}
|
|
var r2 = L.arr(e) ? e : [e];
|
|
return r2.map(function(e2, n3) {
|
|
var i3 = L.obj(e2) && !L.pth(e2) ? e2 : { value: e2 };
|
|
return L.und(i3.delay) && (i3.delay = n3 ? 0 : t2.delay), L.und(i3.endDelay) && (i3.endDelay = n3 === r2.length - 1 ? t2.endDelay : 0), i3;
|
|
}).map(function(e2) {
|
|
return V(e2, n2);
|
|
});
|
|
}
|
|
function ye(e, t2) {
|
|
for (var n2 = Ce(e), i2 = 0, r2 = n2.length;i2 < r2; i2++) {
|
|
var o2 = n2[i2];
|
|
for (var s2 in t2) {
|
|
var a2 = $(t2[s2], o2), A2 = o2.target, l2 = Z(a2), c2 = se(A2, s2, l2, o2), h2 = Ae(ce(a2, l2 || Z(c2)), c2), d2 = ie(A2, s2);
|
|
be[d2](A2, s2, h2, o2.transforms, true);
|
|
}
|
|
}
|
|
}
|
|
function Ie(e, t2) {
|
|
return G(N(e.map(function(e2) {
|
|
return t2.map(function(t3) {
|
|
return function(e3, t4) {
|
|
var n2 = ie(e3.target, t4.name);
|
|
if (n2) {
|
|
var i2 = function(e4, t5) {
|
|
var n3;
|
|
return e4.tweens.map(function(i3) {
|
|
var r3 = function(e5, t6) {
|
|
var n4 = {};
|
|
for (var i4 in e5) {
|
|
var r4 = $(e5[i4], t6);
|
|
L.arr(r4) && (r4 = r4.map(function(e6) {
|
|
return $(e6, t6);
|
|
})).length === 1 && (r4 = r4[0]), n4[i4] = r4;
|
|
}
|
|
return n4.duration = parseFloat(n4.duration), n4.delay = parseFloat(n4.delay), n4;
|
|
}(i3, t5), o2 = r3.value, s2 = L.arr(o2) ? o2[1] : o2, a2 = Z(s2), A2 = se(t5.target, e4.name, a2, t5), l2 = n3 ? n3.to.original : A2, c2 = L.arr(o2) ? o2[0] : l2, h2 = Z(c2) || Z(A2), d2 = a2 || h2;
|
|
return L.und(s2) && (s2 = l2), r3.from = me(c2, d2), r3.to = me(Ae(s2, c2), d2), r3.start = n3 ? n3.end : 0, r3.end = r3.start + r3.delay + r3.duration + r3.endDelay, r3.easing = U(r3.easing, r3.duration), r3.isPath = L.pth(o2), r3.isColor = L.col(r3.from.original), r3.isColor && (r3.round = 1), n3 = r3, r3;
|
|
});
|
|
}(t4, e3), r2 = i2[i2.length - 1];
|
|
return { type: n2, property: t4.name, animatable: e3, tweens: i2, duration: r2.end, delay: i2[0].delay, endDelay: r2.endDelay };
|
|
}
|
|
}(e2, t3);
|
|
});
|
|
})), function(e2) {
|
|
return !L.und(e2);
|
|
});
|
|
}
|
|
function we(e, t2) {
|
|
var n2 = e.length, i2 = function(e2) {
|
|
return e2.timelineOffset ? e2.timelineOffset : 0;
|
|
}, r2 = {};
|
|
return r2.duration = n2 ? Math.max.apply(Math, e.map(function(e2) {
|
|
return i2(e2) + e2.duration;
|
|
})) : t2.duration, r2.delay = n2 ? Math.min.apply(Math, e.map(function(e2) {
|
|
return i2(e2) + e2.delay;
|
|
})) : t2.delay, r2.endDelay = n2 ? r2.duration - Math.max.apply(Math, e.map(function(e2) {
|
|
return i2(e2) + e2.duration - e2.endDelay;
|
|
})) : t2.endDelay, r2;
|
|
}
|
|
function De(e) {
|
|
e === undefined && (e = {});
|
|
var t2, n2 = 0, i2 = 0, r2 = 0, o2 = 0, s2 = null;
|
|
function a2() {
|
|
return window.Promise && new Promise(function(e2) {
|
|
return s2 = e2;
|
|
});
|
|
}
|
|
var A2 = a2(), l2 = function(e2) {
|
|
var t3 = q(E, e2), n3 = q(C, e2), i3 = function(e3, t4) {
|
|
var n4 = [], i4 = t4.keyframes;
|
|
for (var r4 in i4 && (t4 = V(function(e4) {
|
|
for (var t5 = G(N(e4.map(function(e5) {
|
|
return Object.keys(e5);
|
|
})), function(e5) {
|
|
return L.key(e5);
|
|
}).reduce(function(e5, t6) {
|
|
return e5.indexOf(t6) < 0 && e5.push(t6), e5;
|
|
}, []), n5 = {}, i5 = function(i6) {
|
|
var r6 = t5[i6];
|
|
n5[r6] = e4.map(function(e5) {
|
|
var t6 = {};
|
|
for (var n6 in e5)
|
|
L.key(n6) ? n6 == r6 && (t6.value = e5[n6]) : t6[n6] = e5[n6];
|
|
return t6;
|
|
});
|
|
}, r5 = 0;r5 < t5.length; r5++)
|
|
i5(r5);
|
|
return n5;
|
|
}(i4), t4)), t4)
|
|
L.key(r4) && n4.push({ name: r4, tweens: Be(t4[r4], e3) });
|
|
return n4;
|
|
}(n3, e2), r3 = Ce(e2.targets), o3 = Ie(r3, i3), s3 = we(o3, n3), a3 = Qe;
|
|
return Qe++, V(t3, { id: a3, children: [], animatables: r3, animations: o3, duration: s3.duration, delay: s3.delay, endDelay: s3.endDelay });
|
|
}(e);
|
|
function c2() {
|
|
l2.reversed = !l2.reversed;
|
|
for (var e2 = 0, n3 = t2.length;e2 < n3; e2++)
|
|
t2[e2].reversed = l2.reversed;
|
|
}
|
|
function h2(e2) {
|
|
return l2.reversed ? l2.duration - e2 : e2;
|
|
}
|
|
function d2() {
|
|
n2 = 0, i2 = h2(l2.currentTime) * (1 / De.speed);
|
|
}
|
|
function u2(e2, t3) {
|
|
t3 && t3.seek(e2 - t3.timelineOffset);
|
|
}
|
|
function g2(e2) {
|
|
for (var t3 = 0, n3 = l2.animations, i3 = n3.length;t3 < i3; ) {
|
|
var r3 = n3[t3], o3 = r3.animatable, s3 = r3.tweens, a3 = s3.length - 1, A3 = s3[a3];
|
|
a3 && (A3 = G(s3, function(t4) {
|
|
return e2 < t4.end;
|
|
})[0] || A3);
|
|
for (var c3 = b(e2 - A3.start - A3.delay, 0, A3.duration) / A3.duration, h3 = isNaN(c3) ? 1 : A3.easing(c3), d3 = A3.to.strings, u3 = A3.round, g3 = [], p3 = A3.to.numbers.length, f3 = undefined, m2 = 0;m2 < p3; m2++) {
|
|
var E2 = undefined, C2 = A3.to.numbers[m2], v2 = A3.from.numbers[m2] || 0;
|
|
E2 = A3.isPath ? pe(A3.value, h3 * C2) : v2 + h3 * (C2 - v2), u3 && (A3.isColor && m2 > 2 || (E2 = Math.round(E2 * u3) / u3)), g3.push(E2);
|
|
}
|
|
var B2 = d3.length;
|
|
if (B2) {
|
|
f3 = d3[0];
|
|
for (var y2 = 0;y2 < B2; y2++) {
|
|
d3[y2];
|
|
var I2 = d3[y2 + 1], w2 = g3[y2];
|
|
isNaN(w2) || (f3 += I2 ? w2 + I2 : w2 + " ");
|
|
}
|
|
} else
|
|
f3 = g3[0];
|
|
be[r3.type](o3.target, r3.property, f3, o3.transforms), r3.currentValue = f3, t3++;
|
|
}
|
|
}
|
|
function p2(e2) {
|
|
l2[e2] && !l2.passThrough && l2[e2](l2);
|
|
}
|
|
function f2(e2) {
|
|
var { duration: d3, delay: f3 } = l2, m2 = d3 - l2.endDelay, E2 = h2(e2);
|
|
l2.progress = b(E2 / d3 * 100, 0, 100), l2.reversePlayback = E2 < l2.currentTime, t2 && function(e3) {
|
|
if (l2.reversePlayback)
|
|
for (var n3 = o2;n3--; )
|
|
u2(e3, t2[n3]);
|
|
else
|
|
for (var i3 = 0;i3 < o2; i3++)
|
|
u2(e3, t2[i3]);
|
|
}(E2), !l2.began && l2.currentTime > 0 && (l2.began = true, p2("begin"), p2("loopBegin")), E2 <= f3 && l2.currentTime !== 0 && g2(0), (E2 >= m2 && l2.currentTime !== d3 || !d3) && g2(d3), E2 > f3 && E2 < m2 ? (l2.changeBegan || (l2.changeBegan = true, l2.changeCompleted = false, p2("changeBegin")), p2("change"), g2(E2)) : l2.changeBegan && (l2.changeCompleted = true, l2.changeBegan = false, p2("changeComplete")), l2.currentTime = b(E2, 0, d3), l2.began && p2("update"), e2 >= d3 && (i2 = 0, l2.remaining && l2.remaining !== true && l2.remaining--, l2.remaining ? (n2 = r2, p2("loopComplete"), p2("loopBegin"), l2.direction === "alternate" && c2()) : (l2.paused = true, l2.completed || (l2.completed = true, p2("loopComplete"), p2("complete"), ("Promise" in window) && (s2(), A2 = a2()))));
|
|
}
|
|
return l2.reset = function() {
|
|
var e2 = l2.direction;
|
|
l2.passThrough = false, l2.currentTime = 0, l2.progress = 0, l2.paused = true, l2.began = false, l2.changeBegan = false, l2.completed = false, l2.changeCompleted = false, l2.reversePlayback = false, l2.reversed = e2 === "reverse", l2.remaining = l2.loop, t2 = l2.children;
|
|
for (var n3 = o2 = t2.length;n3--; )
|
|
l2.children[n3].reset();
|
|
(l2.reversed && l2.loop !== true || e2 === "alternate" && l2.loop === 1) && l2.remaining++, g2(0);
|
|
}, l2.set = function(e2, t3) {
|
|
return ye(e2, t3), l2;
|
|
}, l2.tick = function(e2) {
|
|
r2 = e2, n2 || (n2 = r2), f2((r2 + (i2 - n2)) * De.speed);
|
|
}, l2.seek = function(e2) {
|
|
f2(h2(e2));
|
|
}, l2.pause = function() {
|
|
l2.paused = true, d2();
|
|
}, l2.play = function() {
|
|
l2.paused && (l2.paused = false, Le.push(l2), d2(), xe || Se());
|
|
}, l2.reverse = function() {
|
|
c2(), d2();
|
|
}, l2.restart = function() {
|
|
l2.reset(), l2.play();
|
|
}, l2.finished = A2, l2.reset(), l2.autoplay && l2.play(), l2;
|
|
}
|
|
function ke(e, t2) {
|
|
for (var n2 = t2.length;n2--; )
|
|
_(e, t2[n2].animatable.target) && t2.splice(n2, 1);
|
|
}
|
|
function Oe() {
|
|
let e, t2;
|
|
function n2(e2, t3, n3, i2, r2, o2) {
|
|
const s2 = o2.num_components(), a2 = n3.num_points() * s2, A2 = a2 * r2.BYTES_PER_ELEMENT, l2 = function(e3, t4) {
|
|
switch (t4) {
|
|
case Float32Array:
|
|
return e3.DT_FLOAT32;
|
|
case Int8Array:
|
|
return e3.DT_INT8;
|
|
case Int16Array:
|
|
return e3.DT_INT16;
|
|
case Int32Array:
|
|
return e3.DT_INT32;
|
|
case Uint8Array:
|
|
return e3.DT_UINT8;
|
|
case Uint16Array:
|
|
return e3.DT_UINT16;
|
|
case Uint32Array:
|
|
return e3.DT_UINT32;
|
|
}
|
|
}(e2, r2), c2 = e2._malloc(A2);
|
|
t3.GetAttributeDataArrayForAllPoints(n3, o2, l2, A2, c2);
|
|
const h2 = new r2(e2.HEAPF32.buffer, c2, a2).slice();
|
|
return e2._free(c2), { name: i2, array: h2, itemSize: s2 };
|
|
}
|
|
onmessage = function(i2) {
|
|
const r2 = i2.data;
|
|
switch (r2.type) {
|
|
case "init":
|
|
e = r2.decoderConfig, t2 = new Promise(function(t3) {
|
|
e.onModuleLoaded = function(e2) {
|
|
t3({ draco: e2 });
|
|
}, DracoDecoderModule(e);
|
|
});
|
|
break;
|
|
case "decode":
|
|
const { buffer: i3, taskConfig: o2 } = r2;
|
|
t2.then((e2) => {
|
|
const t3 = e2.draco, s2 = new t3.Decoder;
|
|
try {
|
|
const e3 = function(e4, t4, i4, r3) {
|
|
const { attributeIDs: o3, attributeTypes: s3 } = r3;
|
|
let a3, A2;
|
|
const l2 = t4.GetEncodedGeometryType(i4);
|
|
if (l2 === e4.TRIANGULAR_MESH)
|
|
a3 = new e4.Mesh, A2 = t4.DecodeArrayToMesh(i4, i4.byteLength, a3);
|
|
else {
|
|
if (l2 !== e4.POINT_CLOUD)
|
|
throw new Error("THREE.DRACOLoader: Unexpected geometry type.");
|
|
a3 = new e4.PointCloud, A2 = t4.DecodeArrayToPointCloud(i4, i4.byteLength, a3);
|
|
}
|
|
if (!A2.ok() || a3.ptr === 0)
|
|
throw new Error("THREE.DRACOLoader: Decoding failed: " + A2.error_msg());
|
|
const c2 = { index: null, attributes: [] };
|
|
for (const i5 in o3) {
|
|
const A3 = self[s3[i5]];
|
|
let l3, h2;
|
|
if (r3.useUniqueIDs)
|
|
h2 = o3[i5], l3 = t4.GetAttributeByUniqueId(a3, h2);
|
|
else {
|
|
if (h2 = t4.GetAttributeId(a3, e4[o3[i5]]), h2 === -1)
|
|
continue;
|
|
l3 = t4.GetAttribute(a3, h2);
|
|
}
|
|
const d2 = n2(e4, t4, a3, i5, A3, l3);
|
|
i5 === "color" && (d2.vertexColorSpace = r3.vertexColorSpace), c2.attributes.push(d2);
|
|
}
|
|
return l2 === e4.TRIANGULAR_MESH && (c2.index = function(e5, t5, n3) {
|
|
const i5 = 3 * n3.num_faces(), r4 = 4 * i5, o4 = e5._malloc(r4);
|
|
t5.GetTrianglesUInt32Array(n3, r4, o4);
|
|
const s4 = new Uint32Array(e5.HEAPF32.buffer, o4, i5).slice();
|
|
return e5._free(o4), { array: s4, itemSize: 1 };
|
|
}(e4, t4, a3)), e4.destroy(a3), c2;
|
|
}(t3, s2, new Int8Array(i3), o2), a2 = e3.attributes.map((e4) => e4.array.buffer);
|
|
e3.index && a2.push(e3.index.array.buffer), self.postMessage({ type: "decode", id: r2.id, geometry: e3 }, a2);
|
|
} catch (e3) {
|
|
console.error(e3), self.postMessage({ type: "error", id: r2.id, error: e3.message });
|
|
} finally {
|
|
t3.destroy(s2);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}
|
|
function Pe(e, t2, n2 = true) {
|
|
if (!t2 || !t2.isReady)
|
|
throw new Error("BufferGeometryUtils: Initialized MikkTSpace library required.");
|
|
if (!e.hasAttribute("position") || !e.hasAttribute("normal") || !e.hasAttribute("uv"))
|
|
throw new Error('BufferGeometryUtils: Tangents require "position", "normal", and "uv" attributes.');
|
|
function i2(e2) {
|
|
if (e2.normalized || e2.isInterleavedBufferAttribute) {
|
|
const t3 = new Float32Array(e2.count * e2.itemSize);
|
|
for (let n3 = 0, i3 = 0;n3 < e2.count; n3++)
|
|
t3[i3++] = e2.getX(n3), t3[i3++] = e2.getY(n3), e2.itemSize > 2 && (t3[i3++] = e2.getZ(n3));
|
|
return t3;
|
|
}
|
|
return e2.array instanceof Float32Array ? e2.array : new Float32Array(e2.array);
|
|
}
|
|
const r2 = e.index ? e.toNonIndexed() : e, o2 = t2.generateTangents(i2(r2.attributes.position), i2(r2.attributes.normal), i2(r2.attributes.uv));
|
|
if (n2)
|
|
for (let e2 = 3;e2 < o2.length; e2 += 4)
|
|
o2[e2] *= -1;
|
|
return r2.setAttribute("tangent", new Re.BufferAttribute(o2, 4)), e !== r2 && e.copy(r2), e;
|
|
}
|
|
function Ge(e, t2 = false) {
|
|
const n2 = e[0].index !== null, i2 = new Set(Object.keys(e[0].attributes)), r2 = new Set(Object.keys(e[0].morphAttributes)), o2 = {}, s2 = {}, a2 = e[0].morphTargetsRelative, A2 = new Re.BufferGeometry;
|
|
let l2 = 0;
|
|
for (let c2 = 0;c2 < e.length; ++c2) {
|
|
const h2 = e[c2];
|
|
let d2 = 0;
|
|
if (n2 !== (h2.index !== null))
|
|
return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + c2 + ". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."), null;
|
|
for (const e2 in h2.attributes) {
|
|
if (!i2.has(e2))
|
|
return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + c2 + '. All geometries must have compatible attributes; make sure "' + e2 + '" attribute exists among all geometries, or in none of them.'), null;
|
|
o2[e2] === undefined && (o2[e2] = []), o2[e2].push(h2.attributes[e2]), d2++;
|
|
}
|
|
if (d2 !== i2.size)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + c2 + ". Make sure all geometries have the same number of attributes."), null;
|
|
if (a2 !== h2.morphTargetsRelative)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + c2 + ". .morphTargetsRelative must be consistent throughout all geometries."), null;
|
|
for (const e2 in h2.morphAttributes) {
|
|
if (!r2.has(e2))
|
|
return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + c2 + ". .morphAttributes must be consistent throughout all geometries."), null;
|
|
s2[e2] === undefined && (s2[e2] = []), s2[e2].push(h2.morphAttributes[e2]);
|
|
}
|
|
if (t2) {
|
|
let e2;
|
|
if (n2)
|
|
e2 = h2.index.count;
|
|
else {
|
|
if (h2.attributes.position === undefined)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + c2 + ". The geometry must have either an index or a position attribute"), null;
|
|
e2 = h2.attributes.position.count;
|
|
}
|
|
A2.addGroup(l2, e2, c2), l2 += e2;
|
|
}
|
|
}
|
|
if (n2) {
|
|
let t3 = 0;
|
|
const n3 = [];
|
|
for (let i3 = 0;i3 < e.length; ++i3) {
|
|
const r3 = e[i3].index;
|
|
for (let e2 = 0;e2 < r3.count; ++e2)
|
|
n3.push(r3.getX(e2) + t3);
|
|
t3 += e[i3].attributes.position.count;
|
|
}
|
|
A2.setIndex(n3);
|
|
}
|
|
for (const e2 in o2) {
|
|
const t3 = Ne(o2[e2]);
|
|
if (!t3)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the " + e2 + " attribute."), null;
|
|
A2.setAttribute(e2, t3);
|
|
}
|
|
for (const e2 in s2) {
|
|
const t3 = s2[e2][0].length;
|
|
if (t3 === 0)
|
|
break;
|
|
A2.morphAttributes = A2.morphAttributes || {}, A2.morphAttributes[e2] = [];
|
|
for (let n3 = 0;n3 < t3; ++n3) {
|
|
const t4 = [];
|
|
for (let i4 = 0;i4 < s2[e2].length; ++i4)
|
|
t4.push(s2[e2][i4][n3]);
|
|
const i3 = Ne(t4);
|
|
if (!i3)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the " + e2 + " morphAttribute."), null;
|
|
A2.morphAttributes[e2].push(i3);
|
|
}
|
|
}
|
|
return A2;
|
|
}
|
|
function Ne(e) {
|
|
let t2, n2, i2, r2 = -1, o2 = 0;
|
|
for (let s3 = 0;s3 < e.length; ++s3) {
|
|
const a3 = e[s3];
|
|
if (t2 === undefined && (t2 = a3.array.constructor), t2 !== a3.array.constructor)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."), null;
|
|
if (n2 === undefined && (n2 = a3.itemSize), n2 !== a3.itemSize)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."), null;
|
|
if (i2 === undefined && (i2 = a3.normalized), i2 !== a3.normalized)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."), null;
|
|
if (r2 === -1 && (r2 = a3.gpuType), r2 !== a3.gpuType)
|
|
return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."), null;
|
|
o2 += a3.count * n2;
|
|
}
|
|
const s2 = new t2(o2), a2 = new Re.BufferAttribute(s2, n2, i2);
|
|
let A2 = 0;
|
|
for (let t3 = 0;t3 < e.length; ++t3) {
|
|
const i3 = e[t3];
|
|
if (i3.isInterleavedBufferAttribute) {
|
|
const e2 = A2 / n2;
|
|
for (let t4 = 0, r3 = i3.count;t4 < r3; t4++)
|
|
for (let r4 = 0;r4 < n2; r4++) {
|
|
const n3 = i3.getComponent(t4, r4);
|
|
a2.setComponent(t4 + e2, r4, n3);
|
|
}
|
|
} else
|
|
s2.set(i3.array, A2);
|
|
A2 += i3.count * n2;
|
|
}
|
|
return r2 !== undefined && (a2.gpuType = r2), a2;
|
|
}
|
|
function je(e) {
|
|
return e.isInstancedInterleavedBufferAttribute || e.isInterleavedBufferAttribute ? He(e) : e.isInstancedBufferAttribute ? new Re.InstancedBufferAttribute().copy(e) : new Re.BufferAttribute().copy(e);
|
|
}
|
|
function _e(e) {
|
|
let t2, n2 = 0, i2 = 0;
|
|
for (let r3 = 0, o3 = e.length;r3 < o3; ++r3) {
|
|
const o4 = e[r3];
|
|
if (t2 === undefined && (t2 = o4.array.constructor), t2 !== o4.array.constructor)
|
|
return console.error("AttributeBuffers of different types cannot be interleaved"), null;
|
|
n2 += o4.array.length, i2 += o4.itemSize;
|
|
}
|
|
const r2 = new Re.InterleavedBuffer(new t2(n2), i2);
|
|
let o2 = 0;
|
|
const s2 = [], a2 = ["getX", "getY", "getZ", "getW"], A2 = ["setX", "setY", "setZ", "setW"];
|
|
for (let t3 = 0, n3 = e.length;t3 < n3; t3++) {
|
|
const n4 = e[t3], i3 = n4.itemSize, l2 = n4.count, c2 = new Re.InterleavedBufferAttribute(r2, i3, o2, n4.normalized);
|
|
s2.push(c2), o2 += i3;
|
|
for (let e2 = 0;e2 < l2; e2++)
|
|
for (let t4 = 0;t4 < i3; t4++)
|
|
c2[A2[t4]](e2, n4[a2[t4]](e2));
|
|
}
|
|
return s2;
|
|
}
|
|
function He(e) {
|
|
const t2 = e.data.array.constructor, n2 = e.count, i2 = e.itemSize, r2 = e.normalized, o2 = new t2(n2 * i2);
|
|
let s2;
|
|
s2 = e.isInstancedInterleavedBufferAttribute ? new Re.InstancedBufferAttribute(o2, i2, r2, e.meshPerAttribute) : new Re.BufferAttribute(o2, i2, r2);
|
|
for (let t3 = 0;t3 < n2; t3++)
|
|
s2.setX(t3, e.getX(t3)), i2 >= 2 && s2.setY(t3, e.getY(t3)), i2 >= 3 && s2.setZ(t3, e.getZ(t3)), i2 >= 4 && s2.setW(t3, e.getW(t3));
|
|
return s2;
|
|
}
|
|
function qe(e) {
|
|
const { attributes: t2, morphTargets: n2 } = e, i2 = new Map;
|
|
for (const e2 in t2) {
|
|
const n3 = t2[e2];
|
|
n3.isInterleavedBufferAttribute && (i2.has(n3) || i2.set(n3, He(n3)), t2[e2] = i2.get(n3));
|
|
}
|
|
for (const e2 in n2) {
|
|
const t3 = n2[e2];
|
|
t3.isInterleavedBufferAttribute && (i2.has(t3) || i2.set(t3, He(t3)), n2[e2] = i2.get(t3));
|
|
}
|
|
}
|
|
function Ve(e) {
|
|
let t2 = 0;
|
|
for (const n3 in e.attributes) {
|
|
const i2 = e.getAttribute(n3);
|
|
t2 += i2.count * i2.itemSize * i2.array.BYTES_PER_ELEMENT;
|
|
}
|
|
const n2 = e.getIndex();
|
|
return t2 += n2 ? n2.count * n2.itemSize * n2.array.BYTES_PER_ELEMENT : 0, t2;
|
|
}
|
|
function ze(e, t2 = 0.0001) {
|
|
t2 = Math.max(t2, Number.EPSILON);
|
|
const n2 = {}, i2 = e.getIndex(), r2 = e.getAttribute("position"), o2 = i2 ? i2.count : r2.count;
|
|
let s2 = 0;
|
|
const a2 = Object.keys(e.attributes), A2 = {}, l2 = {}, c2 = [], h2 = ["getX", "getY", "getZ", "getW"], d2 = ["setX", "setY", "setZ", "setW"];
|
|
for (let t3 = 0, n3 = a2.length;t3 < n3; t3++) {
|
|
const n4 = a2[t3], i3 = e.attributes[n4];
|
|
A2[n4] = new i3.constructor(new i3.array.constructor(i3.count * i3.itemSize), i3.itemSize, i3.normalized);
|
|
const r3 = e.morphAttributes[n4];
|
|
r3 && (l2[n4] || (l2[n4] = []), r3.forEach((e2, t4) => {
|
|
const i4 = new e2.array.constructor(e2.count * e2.itemSize);
|
|
l2[n4][t4] = new e2.constructor(i4, e2.itemSize, e2.normalized);
|
|
}));
|
|
}
|
|
const u2 = 0.5 * t2, g2 = Math.log10(1 / t2), p2 = Math.pow(10, g2), f2 = u2 * p2;
|
|
for (let t3 = 0;t3 < o2; t3++) {
|
|
const r3 = i2 ? i2.getX(t3) : t3;
|
|
let o3 = "";
|
|
for (let t4 = 0, n3 = a2.length;t4 < n3; t4++) {
|
|
const n4 = a2[t4], i3 = e.getAttribute(n4), s3 = i3.itemSize;
|
|
for (let e2 = 0;e2 < s3; e2++)
|
|
o3 += ~~(i3[h2[e2]](r3) * p2 + f2) + ",";
|
|
}
|
|
if (o3 in n2)
|
|
c2.push(n2[o3]);
|
|
else {
|
|
for (let t4 = 0, n3 = a2.length;t4 < n3; t4++) {
|
|
const n4 = a2[t4], i3 = e.getAttribute(n4), o4 = e.morphAttributes[n4], c3 = i3.itemSize, u3 = A2[n4], g3 = l2[n4];
|
|
for (let e2 = 0;e2 < c3; e2++) {
|
|
const t5 = h2[e2], n5 = d2[e2];
|
|
if (u3[n5](s2, i3[t5](r3)), o4)
|
|
for (let e3 = 0, i4 = o4.length;e3 < i4; e3++)
|
|
g3[e3][n5](s2, o4[e3][t5](r3));
|
|
}
|
|
}
|
|
n2[o3] = s2, c2.push(s2), s2++;
|
|
}
|
|
}
|
|
const m2 = e.clone();
|
|
for (const t3 in e.attributes) {
|
|
const e2 = A2[t3];
|
|
if (m2.setAttribute(t3, new e2.constructor(e2.array.slice(0, s2 * e2.itemSize), e2.itemSize, e2.normalized)), t3 in l2)
|
|
for (let e3 = 0;e3 < l2[t3].length; e3++) {
|
|
const n3 = l2[t3][e3];
|
|
m2.morphAttributes[t3][e3] = new n3.constructor(n3.array.slice(0, s2 * n3.itemSize), n3.itemSize, n3.normalized);
|
|
}
|
|
}
|
|
return m2.setIndex(c2), m2;
|
|
}
|
|
function Ye(e, t2) {
|
|
if (t2 === Re.TrianglesDrawMode)
|
|
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), e;
|
|
if (t2 === Re.TriangleFanDrawMode || t2 === Re.TriangleStripDrawMode) {
|
|
let n2 = e.getIndex();
|
|
if (n2 === null) {
|
|
const t3 = [], i3 = e.getAttribute("position");
|
|
if (i3 === undefined)
|
|
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), e;
|
|
for (let e2 = 0;e2 < i3.count; e2++)
|
|
t3.push(e2);
|
|
e.setIndex(t3), n2 = e.getIndex();
|
|
}
|
|
const i2 = n2.count - 2, r2 = [];
|
|
if (t2 === Re.TriangleFanDrawMode)
|
|
for (let e2 = 1;e2 <= i2; e2++)
|
|
r2.push(n2.getX(0)), r2.push(n2.getX(e2)), r2.push(n2.getX(e2 + 1));
|
|
else
|
|
for (let e2 = 0;e2 < i2; e2++)
|
|
e2 % 2 == 0 ? (r2.push(n2.getX(e2)), r2.push(n2.getX(e2 + 1)), r2.push(n2.getX(e2 + 2))) : (r2.push(n2.getX(e2 + 2)), r2.push(n2.getX(e2 + 1)), r2.push(n2.getX(e2)));
|
|
r2.length / 3 !== i2 && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
|
|
const o2 = e.clone();
|
|
return o2.setIndex(r2), o2.clearGroups(), o2;
|
|
}
|
|
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", t2), e;
|
|
}
|
|
function Ke(e) {
|
|
const t2 = new Re.Vector3, n2 = new Re.Vector3, i2 = new Re.Vector3, r2 = new Re.Vector3, o2 = new Re.Vector3, s2 = new Re.Vector3, a2 = new Re.Vector3, A2 = new Re.Vector3, l2 = new Re.Vector3;
|
|
function c2(e2, c3, h3, d3, u3, g3, p3, f3) {
|
|
t2.fromBufferAttribute(c3, u3), n2.fromBufferAttribute(c3, g3), i2.fromBufferAttribute(c3, p3);
|
|
const m3 = e2.morphTargetInfluences;
|
|
if (h3 && m3) {
|
|
a2.set(0, 0, 0), A2.set(0, 0, 0), l2.set(0, 0, 0);
|
|
for (let e3 = 0, c4 = h3.length;e3 < c4; e3++) {
|
|
const c5 = m3[e3], f4 = h3[e3];
|
|
c5 !== 0 && (r2.fromBufferAttribute(f4, u3), o2.fromBufferAttribute(f4, g3), s2.fromBufferAttribute(f4, p3), d3 ? (a2.addScaledVector(r2, c5), A2.addScaledVector(o2, c5), l2.addScaledVector(s2, c5)) : (a2.addScaledVector(r2.sub(t2), c5), A2.addScaledVector(o2.sub(n2), c5), l2.addScaledVector(s2.sub(i2), c5)));
|
|
}
|
|
t2.add(a2), n2.add(A2), i2.add(l2);
|
|
}
|
|
e2.isSkinnedMesh && (e2.applyBoneTransform(u3, t2), e2.applyBoneTransform(g3, n2), e2.applyBoneTransform(p3, i2)), f3[3 * u3 + 0] = t2.x, f3[3 * u3 + 1] = t2.y, f3[3 * u3 + 2] = t2.z, f3[3 * g3 + 0] = n2.x, f3[3 * g3 + 1] = n2.y, f3[3 * g3 + 2] = n2.z, f3[3 * p3 + 0] = i2.x, f3[3 * p3 + 1] = i2.y, f3[3 * p3 + 2] = i2.z;
|
|
}
|
|
const { geometry: h2, material: d2 } = e;
|
|
let u2, g2, p2;
|
|
const f2 = h2.index, m2 = h2.attributes.position, E2 = h2.morphAttributes.position, C2 = h2.morphTargetsRelative, v2 = h2.attributes.normal, B2 = h2.morphAttributes.position, b2 = h2.groups, y2 = h2.drawRange;
|
|
let I2, w2, x2, Q2, L2, M2, S2;
|
|
const D2 = new Float32Array(m2.count * m2.itemSize), k2 = new Float32Array(v2.count * v2.itemSize);
|
|
if (f2 !== null)
|
|
if (Array.isArray(d2))
|
|
for (I2 = 0, x2 = b2.length;I2 < x2; I2++)
|
|
for (L2 = b2[I2], M2 = Math.max(L2.start, y2.start), S2 = Math.min(L2.start + L2.count, y2.start + y2.count), w2 = M2, Q2 = S2;w2 < Q2; w2 += 3)
|
|
u2 = f2.getX(w2), g2 = f2.getX(w2 + 1), p2 = f2.getX(w2 + 2), c2(e, m2, E2, C2, u2, g2, p2, D2), c2(e, v2, B2, C2, u2, g2, p2, k2);
|
|
else
|
|
for (M2 = Math.max(0, y2.start), S2 = Math.min(f2.count, y2.start + y2.count), I2 = M2, x2 = S2;I2 < x2; I2 += 3)
|
|
u2 = f2.getX(I2), g2 = f2.getX(I2 + 1), p2 = f2.getX(I2 + 2), c2(e, m2, E2, C2, u2, g2, p2, D2), c2(e, v2, B2, C2, u2, g2, p2, k2);
|
|
else if (Array.isArray(d2))
|
|
for (I2 = 0, x2 = b2.length;I2 < x2; I2++)
|
|
for (L2 = b2[I2], M2 = Math.max(L2.start, y2.start), S2 = Math.min(L2.start + L2.count, y2.start + y2.count), w2 = M2, Q2 = S2;w2 < Q2; w2 += 3)
|
|
u2 = w2, g2 = w2 + 1, p2 = w2 + 2, c2(e, m2, E2, C2, u2, g2, p2, D2), c2(e, v2, B2, C2, u2, g2, p2, k2);
|
|
else
|
|
for (M2 = Math.max(0, y2.start), S2 = Math.min(m2.count, y2.start + y2.count), I2 = M2, x2 = S2;I2 < x2; I2 += 3)
|
|
u2 = I2, g2 = I2 + 1, p2 = I2 + 2, c2(e, m2, E2, C2, u2, g2, p2, D2), c2(e, v2, B2, C2, u2, g2, p2, k2);
|
|
return { positionAttribute: m2, normalAttribute: v2, morphedPositionAttribute: new Re.Float32BufferAttribute(D2, 3), morphedNormalAttribute: new Re.Float32BufferAttribute(k2, 3) };
|
|
}
|
|
function We(e) {
|
|
if (e.groups.length === 0)
|
|
return console.warn("THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge."), e;
|
|
let t2 = e.groups;
|
|
if (t2 = t2.sort((e2, t3) => e2.materialIndex !== t3.materialIndex ? e2.materialIndex - t3.materialIndex : e2.start - t3.start), e.getIndex() === null) {
|
|
const t3 = e.getAttribute("position"), n3 = [];
|
|
for (let e2 = 0;e2 < t3.count; e2 += 3)
|
|
n3.push(e2, e2 + 1, e2 + 2);
|
|
e.setIndex(n3);
|
|
}
|
|
const n2 = e.getIndex(), i2 = [];
|
|
for (let e2 = 0;e2 < t2.length; e2++) {
|
|
const r3 = t2[e2], o3 = r3.start, s2 = o3 + r3.count;
|
|
for (let e3 = o3;e3 < s2; e3++)
|
|
i2.push(n2.getX(e3));
|
|
}
|
|
e.dispose(), e.setIndex(i2);
|
|
let r2 = 0;
|
|
for (let e2 = 0;e2 < t2.length; e2++) {
|
|
const n3 = t2[e2];
|
|
n3.start = r2, r2 += n3.count;
|
|
}
|
|
let o2 = t2[0];
|
|
e.groups = [o2];
|
|
for (let n3 = 1;n3 < t2.length; n3++) {
|
|
const i3 = t2[n3];
|
|
o2.materialIndex === i3.materialIndex ? o2.count += i3.count : (o2 = i3, e.groups.push(o2));
|
|
}
|
|
return e;
|
|
}
|
|
function Je(e, t2 = Math.PI / 3) {
|
|
const n2 = Math.cos(t2), i2 = 100 * (1 + 0.0000000001), r2 = [new Re.Vector3, new Re.Vector3, new Re.Vector3], o2 = new Re.Vector3, s2 = new Re.Vector3, a2 = new Re.Vector3, A2 = new Re.Vector3;
|
|
function l2(e2) {
|
|
return `${~~(e2.x * i2)},${~~(e2.y * i2)},${~~(e2.z * i2)}`;
|
|
}
|
|
const c2 = e.index ? e.toNonIndexed() : e, h2 = c2.attributes.position, d2 = {};
|
|
for (let e2 = 0, t3 = h2.count / 3;e2 < t3; e2++) {
|
|
const t4 = 3 * e2, n3 = r2[0].fromBufferAttribute(h2, t4 + 0), i3 = r2[1].fromBufferAttribute(h2, t4 + 1), a3 = r2[2].fromBufferAttribute(h2, t4 + 2);
|
|
o2.subVectors(a3, i3), s2.subVectors(n3, i3);
|
|
const A3 = new Re.Vector3().crossVectors(o2, s2).normalize();
|
|
for (let e3 = 0;e3 < 3; e3++) {
|
|
const t5 = l2(r2[e3]);
|
|
t5 in d2 || (d2[t5] = []), d2[t5].push(A3);
|
|
}
|
|
}
|
|
const u2 = new Float32Array(3 * h2.count), g2 = new Re.BufferAttribute(u2, 3, false);
|
|
for (let e2 = 0, t3 = h2.count / 3;e2 < t3; e2++) {
|
|
const t4 = 3 * e2, i3 = r2[0].fromBufferAttribute(h2, t4 + 0), c3 = r2[1].fromBufferAttribute(h2, t4 + 1), u3 = r2[2].fromBufferAttribute(h2, t4 + 2);
|
|
o2.subVectors(u3, c3), s2.subVectors(i3, c3), a2.crossVectors(o2, s2).normalize();
|
|
for (let e3 = 0;e3 < 3; e3++) {
|
|
const i4 = d2[l2(r2[e3])];
|
|
A2.set(0, 0, 0);
|
|
for (let e4 = 0, t5 = i4.length;e4 < t5; e4++) {
|
|
const t6 = i4[e4];
|
|
a2.dot(t6) > n2 && A2.add(t6);
|
|
}
|
|
A2.normalize(), g2.setXYZ(t4 + e3, A2.x, A2.y, A2.z);
|
|
}
|
|
}
|
|
return c2.setAttribute("normal", g2), c2;
|
|
}
|
|
function Ze() {
|
|
let e = {};
|
|
return { get: function(t2) {
|
|
return e[t2];
|
|
}, add: function(t2, n2) {
|
|
e[t2] = n2;
|
|
}, remove: function(t2) {
|
|
delete e[t2];
|
|
}, removeAll: function() {
|
|
e = {};
|
|
} };
|
|
}
|
|
|
|
class et {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
|
|
}
|
|
_markDefs() {
|
|
const e = this.parser, t2 = this.parser.json.nodes || [];
|
|
for (let n2 = 0, i2 = t2.length;n2 < i2; n2++) {
|
|
const i3 = t2[n2];
|
|
i3.extensions && i3.extensions[this.name] && i3.extensions[this.name].light !== undefined && e._addNodeRef(this.cache, i3.extensions[this.name].light);
|
|
}
|
|
}
|
|
_loadLight(e) {
|
|
const t2 = this.parser, n2 = "light:" + e;
|
|
let i2 = t2.cache.get(n2);
|
|
if (i2)
|
|
return i2;
|
|
const r2 = t2.json, o2 = ((r2.extensions && r2.extensions[this.name] || {}).lights || [])[e];
|
|
let s2;
|
|
const a2 = new Re.Color(16777215);
|
|
o2.color !== undefined && a2.setRGB(o2.color[0], o2.color[1], o2.color[2], Re.LinearSRGBColorSpace);
|
|
const A2 = o2.range !== undefined ? o2.range : 0;
|
|
switch (o2.type) {
|
|
case "directional":
|
|
s2 = new Re.DirectionalLight(a2), s2.target.position.set(0, 0, -1), s2.add(s2.target);
|
|
break;
|
|
case "point":
|
|
s2 = new Re.PointLight(a2), s2.distance = A2;
|
|
break;
|
|
case "spot":
|
|
s2 = new Re.SpotLight(a2), s2.distance = A2, o2.spot = o2.spot || {}, o2.spot.innerConeAngle = o2.spot.innerConeAngle !== undefined ? o2.spot.innerConeAngle : 0, o2.spot.outerConeAngle = o2.spot.outerConeAngle !== undefined ? o2.spot.outerConeAngle : Math.PI / 4, s2.angle = o2.spot.outerConeAngle, s2.penumbra = 1 - o2.spot.innerConeAngle / o2.spot.outerConeAngle, s2.target.position.set(0, 0, -1), s2.add(s2.target);
|
|
break;
|
|
default:
|
|
throw new Error("THREE.GLTFLoader: Unexpected light type: " + o2.type);
|
|
}
|
|
return s2.position.set(0, 0, 0), Ut(s2, o2), o2.intensity !== undefined && (s2.intensity = o2.intensity), s2.name = t2.createUniqueName(o2.name || "light_" + e), i2 = Promise.resolve(s2), t2.cache.add(n2, i2), i2;
|
|
}
|
|
getDependency(e, t2) {
|
|
if (e === "light")
|
|
return this._loadLight(t2);
|
|
}
|
|
createNodeAttachment(e) {
|
|
const t2 = this, n2 = this.parser, i2 = n2.json.nodes[e], r2 = (i2.extensions && i2.extensions[this.name] || {}).light;
|
|
return r2 === undefined ? null : this._loadLight(r2).then(function(e2) {
|
|
return n2._getNodeRef(t2.cache, r2, e2);
|
|
});
|
|
}
|
|
}
|
|
|
|
class tt {
|
|
constructor() {
|
|
this.name = $e.KHR_MATERIALS_UNLIT;
|
|
}
|
|
getMaterialType() {
|
|
return Re.MeshBasicMaterial;
|
|
}
|
|
extendParams(e, t2, n2) {
|
|
const i2 = [];
|
|
e.color = new Re.Color(1, 1, 1), e.opacity = 1;
|
|
const r2 = t2.pbrMetallicRoughness;
|
|
if (r2) {
|
|
if (Array.isArray(r2.baseColorFactor)) {
|
|
const t3 = r2.baseColorFactor;
|
|
e.color.setRGB(t3[0], t3[1], t3[2], Re.LinearSRGBColorSpace), e.opacity = t3[3];
|
|
}
|
|
r2.baseColorTexture !== undefined && i2.push(n2.assignTexture(e, "map", r2.baseColorTexture, Re.SRGBColorSpace));
|
|
}
|
|
return Promise.all(i2);
|
|
}
|
|
}
|
|
|
|
class nt {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_EMISSIVE_STRENGTH;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser.json.materials[e];
|
|
if (!n2.extensions || !n2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const i2 = n2.extensions[this.name].emissiveStrength;
|
|
return i2 !== undefined && (t2.emissiveIntensity = i2), Promise.resolve();
|
|
}
|
|
}
|
|
|
|
class it {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_CLEARCOAT;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser, i2 = n2.json.materials[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const r2 = [], o2 = i2.extensions[this.name];
|
|
if (o2.clearcoatFactor !== undefined && (t2.clearcoat = o2.clearcoatFactor), o2.clearcoatTexture !== undefined && r2.push(n2.assignTexture(t2, "clearcoatMap", o2.clearcoatTexture)), o2.clearcoatRoughnessFactor !== undefined && (t2.clearcoatRoughness = o2.clearcoatRoughnessFactor), o2.clearcoatRoughnessTexture !== undefined && r2.push(n2.assignTexture(t2, "clearcoatRoughnessMap", o2.clearcoatRoughnessTexture)), o2.clearcoatNormalTexture !== undefined && (r2.push(n2.assignTexture(t2, "clearcoatNormalMap", o2.clearcoatNormalTexture)), o2.clearcoatNormalTexture.scale !== undefined)) {
|
|
const e2 = o2.clearcoatNormalTexture.scale;
|
|
t2.clearcoatNormalScale = new Re.Vector2(e2, e2);
|
|
}
|
|
return Promise.all(r2);
|
|
}
|
|
}
|
|
|
|
class rt {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_DISPERSION;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser.json.materials[e];
|
|
if (!n2.extensions || !n2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const i2 = n2.extensions[this.name];
|
|
return t2.dispersion = i2.dispersion !== undefined ? i2.dispersion : 0, Promise.resolve();
|
|
}
|
|
}
|
|
|
|
class ot {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_IRIDESCENCE;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser, i2 = n2.json.materials[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const r2 = [], o2 = i2.extensions[this.name];
|
|
return o2.iridescenceFactor !== undefined && (t2.iridescence = o2.iridescenceFactor), o2.iridescenceTexture !== undefined && r2.push(n2.assignTexture(t2, "iridescenceMap", o2.iridescenceTexture)), o2.iridescenceIor !== undefined && (t2.iridescenceIOR = o2.iridescenceIor), t2.iridescenceThicknessRange === undefined && (t2.iridescenceThicknessRange = [100, 400]), o2.iridescenceThicknessMinimum !== undefined && (t2.iridescenceThicknessRange[0] = o2.iridescenceThicknessMinimum), o2.iridescenceThicknessMaximum !== undefined && (t2.iridescenceThicknessRange[1] = o2.iridescenceThicknessMaximum), o2.iridescenceThicknessTexture !== undefined && r2.push(n2.assignTexture(t2, "iridescenceThicknessMap", o2.iridescenceThicknessTexture)), Promise.all(r2);
|
|
}
|
|
}
|
|
|
|
class st {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_SHEEN;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser, i2 = n2.json.materials[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const r2 = [];
|
|
t2.sheenColor = new Re.Color(0, 0, 0), t2.sheenRoughness = 0, t2.sheen = 1;
|
|
const o2 = i2.extensions[this.name];
|
|
if (o2.sheenColorFactor !== undefined) {
|
|
const e2 = o2.sheenColorFactor;
|
|
t2.sheenColor.setRGB(e2[0], e2[1], e2[2], Re.LinearSRGBColorSpace);
|
|
}
|
|
return o2.sheenRoughnessFactor !== undefined && (t2.sheenRoughness = o2.sheenRoughnessFactor), o2.sheenColorTexture !== undefined && r2.push(n2.assignTexture(t2, "sheenColorMap", o2.sheenColorTexture, Re.SRGBColorSpace)), o2.sheenRoughnessTexture !== undefined && r2.push(n2.assignTexture(t2, "sheenRoughnessMap", o2.sheenRoughnessTexture)), Promise.all(r2);
|
|
}
|
|
}
|
|
|
|
class at {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_TRANSMISSION;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser, i2 = n2.json.materials[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const r2 = [], o2 = i2.extensions[this.name];
|
|
return o2.transmissionFactor !== undefined && (t2.transmission = o2.transmissionFactor), o2.transmissionTexture !== undefined && r2.push(n2.assignTexture(t2, "transmissionMap", o2.transmissionTexture)), Promise.all(r2);
|
|
}
|
|
}
|
|
|
|
class At {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_VOLUME;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser, i2 = n2.json.materials[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const r2 = [], o2 = i2.extensions[this.name];
|
|
t2.thickness = o2.thicknessFactor !== undefined ? o2.thicknessFactor : 0, o2.thicknessTexture !== undefined && r2.push(n2.assignTexture(t2, "thicknessMap", o2.thicknessTexture)), t2.attenuationDistance = o2.attenuationDistance || 1 / 0;
|
|
const s2 = o2.attenuationColor || [1, 1, 1];
|
|
return t2.attenuationColor = new Re.Color().setRGB(s2[0], s2[1], s2[2], Re.LinearSRGBColorSpace), Promise.all(r2);
|
|
}
|
|
}
|
|
|
|
class lt {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_IOR;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser.json.materials[e];
|
|
if (!n2.extensions || !n2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const i2 = n2.extensions[this.name];
|
|
return t2.ior = i2.ior !== undefined ? i2.ior : 1.5, Promise.resolve();
|
|
}
|
|
}
|
|
|
|
class ct {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_SPECULAR;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser, i2 = n2.json.materials[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const r2 = [], o2 = i2.extensions[this.name];
|
|
t2.specularIntensity = o2.specularFactor !== undefined ? o2.specularFactor : 1, o2.specularTexture !== undefined && r2.push(n2.assignTexture(t2, "specularIntensityMap", o2.specularTexture));
|
|
const s2 = o2.specularColorFactor || [1, 1, 1];
|
|
return t2.specularColor = new Re.Color().setRGB(s2[0], s2[1], s2[2], Re.LinearSRGBColorSpace), o2.specularColorTexture !== undefined && r2.push(n2.assignTexture(t2, "specularColorMap", o2.specularColorTexture, Re.SRGBColorSpace)), Promise.all(r2);
|
|
}
|
|
}
|
|
|
|
class ht {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.EXT_MATERIALS_BUMP;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser, i2 = n2.json.materials[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const r2 = [], o2 = i2.extensions[this.name];
|
|
return t2.bumpScale = o2.bumpFactor !== undefined ? o2.bumpFactor : 1, o2.bumpTexture !== undefined && r2.push(n2.assignTexture(t2, "bumpMap", o2.bumpTexture)), Promise.all(r2);
|
|
}
|
|
}
|
|
|
|
class dt {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_MATERIALS_ANISOTROPY;
|
|
}
|
|
getMaterialType(e) {
|
|
const t2 = this.parser.json.materials[e];
|
|
return t2.extensions && t2.extensions[this.name] ? Re.MeshPhysicalMaterial : null;
|
|
}
|
|
extendMaterialParams(e, t2) {
|
|
const n2 = this.parser, i2 = n2.json.materials[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return Promise.resolve();
|
|
const r2 = [], o2 = i2.extensions[this.name];
|
|
return o2.anisotropyStrength !== undefined && (t2.anisotropy = o2.anisotropyStrength), o2.anisotropyRotation !== undefined && (t2.anisotropyRotation = o2.anisotropyRotation), o2.anisotropyTexture !== undefined && r2.push(n2.assignTexture(t2, "anisotropyMap", o2.anisotropyTexture)), Promise.all(r2);
|
|
}
|
|
}
|
|
|
|
class ut {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.KHR_TEXTURE_BASISU;
|
|
}
|
|
loadTexture(e) {
|
|
const t2 = this.parser, n2 = t2.json, i2 = n2.textures[e];
|
|
if (!i2.extensions || !i2.extensions[this.name])
|
|
return null;
|
|
const r2 = i2.extensions[this.name], o2 = t2.options.ktx2Loader;
|
|
if (!o2) {
|
|
if (n2.extensionsRequired && n2.extensionsRequired.indexOf(this.name) >= 0)
|
|
throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
|
|
return null;
|
|
}
|
|
return t2.loadTextureImage(e, r2.source, o2);
|
|
}
|
|
}
|
|
|
|
class gt {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.EXT_TEXTURE_WEBP, this.isSupported = null;
|
|
}
|
|
loadTexture(e) {
|
|
const t2 = this.name, n2 = this.parser, i2 = n2.json, r2 = i2.textures[e];
|
|
if (!r2.extensions || !r2.extensions[t2])
|
|
return null;
|
|
const o2 = r2.extensions[t2], s2 = i2.images[o2.source];
|
|
let a2 = n2.textureLoader;
|
|
if (s2.uri) {
|
|
const e2 = n2.options.manager.getHandler(s2.uri);
|
|
e2 !== null && (a2 = e2);
|
|
}
|
|
return this.detectSupport().then(function(r3) {
|
|
if (r3)
|
|
return n2.loadTextureImage(e, o2.source, a2);
|
|
if (i2.extensionsRequired && i2.extensionsRequired.indexOf(t2) >= 0)
|
|
throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
|
|
return n2.loadTexture(e);
|
|
});
|
|
}
|
|
detectSupport() {
|
|
return this.isSupported || (this.isSupported = new Promise(function(e) {
|
|
const t2 = new Image;
|
|
t2.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", t2.onload = t2.onerror = function() {
|
|
e(t2.height === 1);
|
|
};
|
|
})), this.isSupported;
|
|
}
|
|
}
|
|
|
|
class pt {
|
|
constructor(e) {
|
|
this.parser = e, this.name = $e.EXT_TEXTURE_AVIF, this.isSupported = null;
|
|
}
|
|
loadTexture(e) {
|
|
const t2 = this.name, n2 = this.parser, i2 = n2.json, r2 = i2.textures[e];
|
|
if (!r2.extensions || !r2.extensions[t2])
|
|
return null;
|
|
const o2 = r2.extensions[t2], s2 = i2.images[o2.source];
|
|
let a2 = n2.textureLoader;
|
|
if (s2.uri) {
|
|
const e2 = n2.options.manager.getHandler(s2.uri);
|
|
e2 !== null && (a2 = e2);
|
|
}
|
|
return this.detectSupport().then(function(r3) {
|
|
if (r3)
|
|
return n2.loadTextureImage(e, o2.source, a2);
|
|
if (i2.extensionsRequired && i2.extensionsRequired.indexOf(t2) >= 0)
|
|
throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");
|
|
return n2.loadTexture(e);
|
|
});
|
|
}
|
|
detectSupport() {
|
|
return this.isSupported || (this.isSupported = new Promise(function(e) {
|
|
const t2 = new Image;
|
|
t2.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=", t2.onload = t2.onerror = function() {
|
|
e(t2.height === 1);
|
|
};
|
|
})), this.isSupported;
|
|
}
|
|
}
|
|
|
|
class ft {
|
|
constructor(e) {
|
|
this.name = $e.EXT_MESHOPT_COMPRESSION, this.parser = e;
|
|
}
|
|
loadBufferView(e) {
|
|
const t2 = this.parser.json, n2 = t2.bufferViews[e];
|
|
if (n2.extensions && n2.extensions[this.name]) {
|
|
const e2 = n2.extensions[this.name], i2 = this.parser.getDependency("buffer", e2.buffer), r2 = this.parser.options.meshoptDecoder;
|
|
if (!r2 || !r2.supported) {
|
|
if (t2.extensionsRequired && t2.extensionsRequired.indexOf(this.name) >= 0)
|
|
throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
|
|
return null;
|
|
}
|
|
return i2.then(function(t3) {
|
|
const n3 = e2.byteOffset || 0, i3 = e2.byteLength || 0, o2 = e2.count, s2 = e2.byteStride, a2 = new Uint8Array(t3, n3, i3);
|
|
return r2.decodeGltfBufferAsync ? r2.decodeGltfBufferAsync(o2, s2, a2, e2.mode, e2.filter).then(function(e3) {
|
|
return e3.buffer;
|
|
}) : r2.ready.then(function() {
|
|
const t4 = new ArrayBuffer(o2 * s2);
|
|
return r2.decodeGltfBuffer(new Uint8Array(t4), o2, s2, a2, e2.mode, e2.filter), t4;
|
|
});
|
|
});
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
class mt {
|
|
constructor(e) {
|
|
this.name = $e.EXT_MESH_GPU_INSTANCING, this.parser = e;
|
|
}
|
|
createNodeMesh(e) {
|
|
const t2 = this.parser.json, n2 = t2.nodes[e];
|
|
if (!n2.extensions || !n2.extensions[this.name] || n2.mesh === undefined)
|
|
return null;
|
|
const i2 = t2.meshes[n2.mesh];
|
|
for (const e2 of i2.primitives)
|
|
if (e2.mode !== xt.TRIANGLES && e2.mode !== xt.TRIANGLE_STRIP && e2.mode !== xt.TRIANGLE_FAN && e2.mode !== undefined)
|
|
return null;
|
|
const r2 = n2.extensions[this.name].attributes, o2 = [], s2 = {};
|
|
for (const e2 in r2)
|
|
o2.push(this.parser.getDependency("accessor", r2[e2]).then((t3) => (s2[e2] = t3, s2[e2])));
|
|
return o2.length < 1 ? null : (o2.push(this.parser.createNodeMesh(e)), Promise.all(o2).then((e2) => {
|
|
const t3 = e2.pop(), n3 = t3.isGroup ? t3.children : [t3], i3 = e2[0].count, r3 = [];
|
|
for (const e3 of n3) {
|
|
const t4 = new Re.Matrix4, n4 = new Re.Vector3, o3 = new Re.Quaternion, a2 = new Re.Vector3(1, 1, 1), A2 = new Re.InstancedMesh(e3.geometry, e3.material, i3);
|
|
for (let e4 = 0;e4 < i3; e4++)
|
|
s2.TRANSLATION && n4.fromBufferAttribute(s2.TRANSLATION, e4), s2.ROTATION && o3.fromBufferAttribute(s2.ROTATION, e4), s2.SCALE && a2.fromBufferAttribute(s2.SCALE, e4), A2.setMatrixAt(e4, t4.compose(n4, o3, a2));
|
|
for (const t5 in s2)
|
|
if (t5 === "_COLOR_0") {
|
|
const e4 = s2[t5];
|
|
A2.instanceColor = new Re.InstancedBufferAttribute(e4.array, e4.itemSize, e4.normalized);
|
|
} else
|
|
t5 !== "TRANSLATION" && t5 !== "ROTATION" && t5 !== "SCALE" && e3.geometry.setAttribute(t5, s2[t5]);
|
|
Re.Object3D.prototype.copy.call(A2, e3), this.parser.assignFinalMaterial(A2), r3.push(A2);
|
|
}
|
|
return t3.isGroup ? (t3.clear(), t3.add(...r3), t3) : r3[0];
|
|
}));
|
|
}
|
|
}
|
|
|
|
class Ct {
|
|
constructor(e) {
|
|
this.name = $e.KHR_BINARY_GLTF, this.content = null, this.body = null;
|
|
const t2 = new DataView(e, 0, 12), n2 = new TextDecoder;
|
|
if (this.header = { magic: n2.decode(new Uint8Array(e.slice(0, 4))), version: t2.getUint32(4, true), length: t2.getUint32(8, true) }, this.header.magic !== Et)
|
|
throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
|
|
if (this.header.version < 2)
|
|
throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
|
|
const i2 = this.header.length - 12, r2 = new DataView(e, 12);
|
|
let o2 = 0;
|
|
for (;o2 < i2; ) {
|
|
const t3 = r2.getUint32(o2, true);
|
|
o2 += 4;
|
|
const i3 = r2.getUint32(o2, true);
|
|
if (o2 += 4, i3 === 1313821514) {
|
|
const i4 = new Uint8Array(e, 12 + o2, t3);
|
|
this.content = n2.decode(i4);
|
|
} else if (i3 === 5130562) {
|
|
const n3 = 12 + o2;
|
|
this.body = e.slice(n3, n3 + t3);
|
|
}
|
|
o2 += t3;
|
|
}
|
|
if (this.content === null)
|
|
throw new Error("THREE.GLTFLoader: JSON content not found.");
|
|
}
|
|
}
|
|
|
|
class vt {
|
|
constructor(e, t2) {
|
|
if (!t2)
|
|
throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
|
|
this.name = $e.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t2, this.dracoLoader.preload();
|
|
}
|
|
decodePrimitive(e, t2) {
|
|
const n2 = this.json, i2 = this.dracoLoader, r2 = e.extensions[this.name].bufferView, o2 = e.extensions[this.name].attributes, s2 = {}, a2 = {}, A2 = {};
|
|
for (const e2 in o2) {
|
|
const t3 = Dt[e2] || e2.toLowerCase();
|
|
s2[t3] = o2[e2];
|
|
}
|
|
for (const t3 in e.attributes) {
|
|
const i3 = Dt[t3] || t3.toLowerCase();
|
|
if (o2[t3] !== undefined) {
|
|
const r3 = n2.accessors[e.attributes[t3]], o3 = Qt[r3.componentType];
|
|
A2[i3] = o3.name, a2[i3] = r3.normalized === true;
|
|
}
|
|
}
|
|
return t2.getDependency("bufferView", r2).then(function(e2) {
|
|
return new Promise(function(t3, n3) {
|
|
i2.decodeDracoFile(e2, function(e3) {
|
|
for (const t4 in e3.attributes) {
|
|
const n4 = e3.attributes[t4], i3 = a2[t4];
|
|
i3 !== undefined && (n4.normalized = i3);
|
|
}
|
|
t3(e3);
|
|
}, s2, A2, Re.LinearSRGBColorSpace, n3);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
class Bt {
|
|
constructor() {
|
|
this.name = $e.KHR_TEXTURE_TRANSFORM;
|
|
}
|
|
extendTexture(e, t2) {
|
|
return t2.texCoord !== undefined && t2.texCoord !== e.channel || t2.offset !== undefined || t2.rotation !== undefined || t2.scale !== undefined ? (e = e.clone(), t2.texCoord !== undefined && (e.channel = t2.texCoord), t2.offset !== undefined && e.offset.fromArray(t2.offset), t2.rotation !== undefined && (e.rotation = t2.rotation), t2.scale !== undefined && e.repeat.fromArray(t2.scale), e.needsUpdate = true, e) : e;
|
|
}
|
|
}
|
|
|
|
class bt {
|
|
constructor() {
|
|
this.name = $e.KHR_MESH_QUANTIZATION;
|
|
}
|
|
}
|
|
function Rt(e) {
|
|
return e.DefaultMaterial === undefined && (e.DefaultMaterial = new Re.MeshStandardMaterial({ color: 16777215, emissive: 0, metalness: 1, roughness: 1, transparent: false, depthTest: true, side: Re.FrontSide })), e.DefaultMaterial;
|
|
}
|
|
function Ft(e, t2, n2) {
|
|
for (const i2 in n2.extensions)
|
|
e[i2] === undefined && (t2.userData.gltfExtensions = t2.userData.gltfExtensions || {}, t2.userData.gltfExtensions[i2] = n2.extensions[i2]);
|
|
}
|
|
function Ut(e, t2) {
|
|
t2.extras !== undefined && (typeof t2.extras == "object" ? Object.assign(e.userData, t2.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + t2.extras));
|
|
}
|
|
function Ot(e, t2) {
|
|
if (e.updateMorphTargets(), t2.weights !== undefined)
|
|
for (let n2 = 0, i2 = t2.weights.length;n2 < i2; n2++)
|
|
e.morphTargetInfluences[n2] = t2.weights[n2];
|
|
if (t2.extras && Array.isArray(t2.extras.targetNames)) {
|
|
const n2 = t2.extras.targetNames;
|
|
if (e.morphTargetInfluences.length === n2.length) {
|
|
e.morphTargetDictionary = {};
|
|
for (let t3 = 0, i2 = n2.length;t3 < i2; t3++)
|
|
e.morphTargetDictionary[n2[t3]] = t3;
|
|
} else
|
|
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
|
|
}
|
|
}
|
|
function Pt(e) {
|
|
let t2;
|
|
const n2 = e.extensions && e.extensions[$e.KHR_DRACO_MESH_COMPRESSION];
|
|
if (t2 = n2 ? "draco:" + n2.bufferView + ":" + n2.indices + ":" + Gt(n2.attributes) : e.indices + ":" + Gt(e.attributes) + ":" + e.mode, e.targets !== undefined)
|
|
for (let n3 = 0, i2 = e.targets.length;n3 < i2; n3++)
|
|
t2 += ":" + Gt(e.targets[n3]);
|
|
return t2;
|
|
}
|
|
function Gt(e) {
|
|
let t2 = "";
|
|
const n2 = Object.keys(e).sort();
|
|
for (let i2 = 0, r2 = n2.length;i2 < r2; i2++)
|
|
t2 += n2[i2] + ":" + e[n2[i2]] + ";";
|
|
return t2;
|
|
}
|
|
function Nt(e) {
|
|
switch (e) {
|
|
case Int8Array:
|
|
return 1 / 127;
|
|
case Uint8Array:
|
|
return 1 / 255;
|
|
case Int16Array:
|
|
return 1 / 32767;
|
|
case Uint16Array:
|
|
return 1 / 65535;
|
|
default:
|
|
throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
|
|
}
|
|
}
|
|
|
|
class _t {
|
|
constructor(e = {}, t2 = {}) {
|
|
this.json = e, this.extensions = {}, this.plugins = {}, this.options = t2, this.cache = new Ze, this.associations = new Map, this.primitiveCache = {}, this.nodeCache = {}, this.meshCache = { refs: {}, uses: {} }, this.cameraCache = { refs: {}, uses: {} }, this.lightCache = { refs: {}, uses: {} }, this.sourceCache = {}, this.textureCache = {}, this.nodeNamesUsed = {};
|
|
let n2 = false, i2 = -1, r2 = false, o2 = -1;
|
|
if (typeof navigator != "undefined") {
|
|
const e2 = navigator.userAgent;
|
|
n2 = /^((?!chrome|android).)*safari/i.test(e2) === true;
|
|
const t3 = e2.match(/Version\/(\d+)/);
|
|
i2 = n2 && t3 ? parseInt(t3[1], 10) : -1, r2 = e2.indexOf("Firefox") > -1, o2 = r2 ? e2.match(/Firefox\/([0-9]+)\./)[1] : -1;
|
|
}
|
|
typeof createImageBitmap == "undefined" || n2 && i2 < 17 || r2 && o2 < 98 ? this.textureLoader = new Re.TextureLoader(this.options.manager) : this.textureLoader = new Re.ImageBitmapLoader(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new Re.FileLoader(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(true);
|
|
}
|
|
setExtensions(e) {
|
|
this.extensions = e;
|
|
}
|
|
setPlugins(e) {
|
|
this.plugins = e;
|
|
}
|
|
parse(e, t2) {
|
|
const n2 = this, i2 = this.json, r2 = this.extensions;
|
|
this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(e2) {
|
|
return e2._markDefs && e2._markDefs();
|
|
}), Promise.all(this._invokeAll(function(e2) {
|
|
return e2.beforeRoot && e2.beforeRoot();
|
|
})).then(function() {
|
|
return Promise.all([n2.getDependencies("scene"), n2.getDependencies("animation"), n2.getDependencies("camera")]);
|
|
}).then(function(t3) {
|
|
const o2 = { scene: t3[0][i2.scene || 0], scenes: t3[0], animations: t3[1], cameras: t3[2], asset: i2.asset, parser: n2, userData: {} };
|
|
return Ft(r2, o2, i2), Ut(o2, i2), Promise.all(n2._invokeAll(function(e2) {
|
|
return e2.afterRoot && e2.afterRoot(o2);
|
|
})).then(function() {
|
|
for (const e2 of o2.scenes)
|
|
e2.updateMatrixWorld();
|
|
e(o2);
|
|
});
|
|
}).catch(t2);
|
|
}
|
|
_markDefs() {
|
|
const e = this.json.nodes || [], t2 = this.json.skins || [], n2 = this.json.meshes || [];
|
|
for (let n3 = 0, i2 = t2.length;n3 < i2; n3++) {
|
|
const i3 = t2[n3].joints;
|
|
for (let t3 = 0, n4 = i3.length;t3 < n4; t3++)
|
|
e[i3[t3]].isBone = true;
|
|
}
|
|
for (let t3 = 0, i2 = e.length;t3 < i2; t3++) {
|
|
const i3 = e[t3];
|
|
i3.mesh !== undefined && (this._addNodeRef(this.meshCache, i3.mesh), i3.skin !== undefined && (n2[i3.mesh].isSkinnedMesh = true)), i3.camera !== undefined && this._addNodeRef(this.cameraCache, i3.camera);
|
|
}
|
|
}
|
|
_addNodeRef(e, t2) {
|
|
t2 !== undefined && (e.refs[t2] === undefined && (e.refs[t2] = e.uses[t2] = 0), e.refs[t2]++);
|
|
}
|
|
_getNodeRef(e, t2, n2) {
|
|
if (e.refs[t2] <= 1)
|
|
return n2;
|
|
const i2 = n2.clone(), r2 = (e2, t3) => {
|
|
const n3 = this.associations.get(e2);
|
|
n3 != null && this.associations.set(t3, n3);
|
|
for (const [n4, i3] of e2.children.entries())
|
|
r2(i3, t3.children[n4]);
|
|
};
|
|
return r2(n2, i2), i2.name += "_instance_" + e.uses[t2]++, i2;
|
|
}
|
|
_invokeOne(e) {
|
|
const t2 = Object.values(this.plugins);
|
|
t2.push(this);
|
|
for (let n2 = 0;n2 < t2.length; n2++) {
|
|
const i2 = e(t2[n2]);
|
|
if (i2)
|
|
return i2;
|
|
}
|
|
return null;
|
|
}
|
|
_invokeAll(e) {
|
|
const t2 = Object.values(this.plugins);
|
|
t2.unshift(this);
|
|
const n2 = [];
|
|
for (let i2 = 0;i2 < t2.length; i2++) {
|
|
const r2 = e(t2[i2]);
|
|
r2 && n2.push(r2);
|
|
}
|
|
return n2;
|
|
}
|
|
getDependency(e, t2) {
|
|
const n2 = e + ":" + t2;
|
|
let i2 = this.cache.get(n2);
|
|
if (!i2) {
|
|
switch (e) {
|
|
case "scene":
|
|
i2 = this.loadScene(t2);
|
|
break;
|
|
case "node":
|
|
i2 = this._invokeOne(function(e2) {
|
|
return e2.loadNode && e2.loadNode(t2);
|
|
});
|
|
break;
|
|
case "mesh":
|
|
i2 = this._invokeOne(function(e2) {
|
|
return e2.loadMesh && e2.loadMesh(t2);
|
|
});
|
|
break;
|
|
case "accessor":
|
|
i2 = this.loadAccessor(t2);
|
|
break;
|
|
case "bufferView":
|
|
i2 = this._invokeOne(function(e2) {
|
|
return e2.loadBufferView && e2.loadBufferView(t2);
|
|
});
|
|
break;
|
|
case "buffer":
|
|
i2 = this.loadBuffer(t2);
|
|
break;
|
|
case "material":
|
|
i2 = this._invokeOne(function(e2) {
|
|
return e2.loadMaterial && e2.loadMaterial(t2);
|
|
});
|
|
break;
|
|
case "texture":
|
|
i2 = this._invokeOne(function(e2) {
|
|
return e2.loadTexture && e2.loadTexture(t2);
|
|
});
|
|
break;
|
|
case "skin":
|
|
i2 = this.loadSkin(t2);
|
|
break;
|
|
case "animation":
|
|
i2 = this._invokeOne(function(e2) {
|
|
return e2.loadAnimation && e2.loadAnimation(t2);
|
|
});
|
|
break;
|
|
case "camera":
|
|
i2 = this.loadCamera(t2);
|
|
break;
|
|
default:
|
|
if (i2 = this._invokeOne(function(n3) {
|
|
return n3 != this && n3.getDependency && n3.getDependency(e, t2);
|
|
}), !i2)
|
|
throw new Error("Unknown type: " + e);
|
|
}
|
|
this.cache.add(n2, i2);
|
|
}
|
|
return i2;
|
|
}
|
|
getDependencies(e) {
|
|
let t2 = this.cache.get(e);
|
|
if (!t2) {
|
|
const n2 = this, i2 = this.json[e + (e === "mesh" ? "es" : "s")] || [];
|
|
t2 = Promise.all(i2.map(function(t3, i3) {
|
|
return n2.getDependency(e, i3);
|
|
})), this.cache.add(e, t2);
|
|
}
|
|
return t2;
|
|
}
|
|
loadBuffer(e) {
|
|
const t2 = this.json.buffers[e], n2 = this.fileLoader;
|
|
if (t2.type && t2.type !== "arraybuffer")
|
|
throw new Error("THREE.GLTFLoader: " + t2.type + " buffer type is not supported.");
|
|
if (t2.uri === undefined && e === 0)
|
|
return Promise.resolve(this.extensions[$e.KHR_BINARY_GLTF].body);
|
|
const i2 = this.options;
|
|
return new Promise(function(e2, r2) {
|
|
n2.load(Re.LoaderUtils.resolveURL(t2.uri, i2.path), e2, undefined, function() {
|
|
r2(new Error('THREE.GLTFLoader: Failed to load buffer "' + t2.uri + '".'));
|
|
});
|
|
});
|
|
}
|
|
loadBufferView(e) {
|
|
const t2 = this.json.bufferViews[e];
|
|
return this.getDependency("buffer", t2.buffer).then(function(e2) {
|
|
const n2 = t2.byteLength || 0, i2 = t2.byteOffset || 0;
|
|
return e2.slice(i2, i2 + n2);
|
|
});
|
|
}
|
|
loadAccessor(e) {
|
|
const t2 = this, n2 = this.json, i2 = this.json.accessors[e];
|
|
if (i2.bufferView === undefined && i2.sparse === undefined) {
|
|
const e2 = St[i2.type], t3 = Qt[i2.componentType], n3 = i2.normalized === true, r3 = new t3(i2.count * e2);
|
|
return Promise.resolve(new Re.BufferAttribute(r3, e2, n3));
|
|
}
|
|
const r2 = [];
|
|
return i2.bufferView !== undefined ? r2.push(this.getDependency("bufferView", i2.bufferView)) : r2.push(null), i2.sparse !== undefined && (r2.push(this.getDependency("bufferView", i2.sparse.indices.bufferView)), r2.push(this.getDependency("bufferView", i2.sparse.values.bufferView))), Promise.all(r2).then(function(e2) {
|
|
const r3 = e2[0], o2 = St[i2.type], s2 = Qt[i2.componentType], a2 = s2.BYTES_PER_ELEMENT, A2 = a2 * o2, l2 = i2.byteOffset || 0, c2 = i2.bufferView !== undefined ? n2.bufferViews[i2.bufferView].byteStride : undefined, h2 = i2.normalized === true;
|
|
let d2, u2;
|
|
if (c2 && c2 !== A2) {
|
|
const e3 = Math.floor(l2 / c2), n3 = "InterleavedBuffer:" + i2.bufferView + ":" + i2.componentType + ":" + e3 + ":" + i2.count;
|
|
let A3 = t2.cache.get(n3);
|
|
A3 || (d2 = new s2(r3, e3 * c2, i2.count * c2 / a2), A3 = new Re.InterleavedBuffer(d2, c2 / a2), t2.cache.add(n3, A3)), u2 = new Re.InterleavedBufferAttribute(A3, o2, l2 % c2 / a2, h2);
|
|
} else
|
|
d2 = r3 === null ? new s2(i2.count * o2) : new s2(r3, l2, i2.count * o2), u2 = new Re.BufferAttribute(d2, o2, h2);
|
|
if (i2.sparse !== undefined) {
|
|
const t3 = St.SCALAR, n3 = Qt[i2.sparse.indices.componentType], a3 = i2.sparse.indices.byteOffset || 0, A3 = i2.sparse.values.byteOffset || 0, l3 = new n3(e2[1], a3, i2.sparse.count * t3), c3 = new s2(e2[2], A3, i2.sparse.count * o2);
|
|
r3 !== null && (u2 = new Re.BufferAttribute(u2.array.slice(), u2.itemSize, u2.normalized)), u2.normalized = false;
|
|
for (let e3 = 0, t4 = l3.length;e3 < t4; e3++) {
|
|
const t5 = l3[e3];
|
|
if (u2.setX(t5, c3[e3 * o2]), o2 >= 2 && u2.setY(t5, c3[e3 * o2 + 1]), o2 >= 3 && u2.setZ(t5, c3[e3 * o2 + 2]), o2 >= 4 && u2.setW(t5, c3[e3 * o2 + 3]), o2 >= 5)
|
|
throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
|
|
}
|
|
u2.normalized = h2;
|
|
}
|
|
return u2;
|
|
});
|
|
}
|
|
loadTexture(e) {
|
|
const t2 = this.json, n2 = this.options, i2 = t2.textures[e].source, r2 = t2.images[i2];
|
|
let o2 = this.textureLoader;
|
|
if (r2.uri) {
|
|
const e2 = n2.manager.getHandler(r2.uri);
|
|
e2 !== null && (o2 = e2);
|
|
}
|
|
return this.loadTextureImage(e, i2, o2);
|
|
}
|
|
loadTextureImage(e, t2, n2) {
|
|
const i2 = this, r2 = this.json, o2 = r2.textures[e], s2 = r2.images[t2], a2 = (s2.uri || s2.bufferView) + ":" + o2.sampler;
|
|
if (this.textureCache[a2])
|
|
return this.textureCache[a2];
|
|
const A2 = this.loadImageSource(t2, n2).then(function(t3) {
|
|
t3.flipY = false, t3.name = o2.name || s2.name || "", t3.name === "" && typeof s2.uri == "string" && s2.uri.startsWith("data:image/") === false && (t3.name = s2.uri);
|
|
const n3 = (r2.samplers || {})[o2.sampler] || {};
|
|
return t3.magFilter = Lt[n3.magFilter] || Re.LinearFilter, t3.minFilter = Lt[n3.minFilter] || Re.LinearMipmapLinearFilter, t3.wrapS = Mt[n3.wrapS] || Re.RepeatWrapping, t3.wrapT = Mt[n3.wrapT] || Re.RepeatWrapping, t3.generateMipmaps = !t3.isCompressedTexture && t3.minFilter !== Re.NearestFilter && t3.minFilter !== Re.LinearFilter, i2.associations.set(t3, { textures: e }), t3;
|
|
}).catch(function() {
|
|
return null;
|
|
});
|
|
return this.textureCache[a2] = A2, A2;
|
|
}
|
|
loadImageSource(e, t2) {
|
|
const n2 = this.json, i2 = this.options;
|
|
if (this.sourceCache[e] !== undefined)
|
|
return this.sourceCache[e].then((e2) => e2.clone());
|
|
const r2 = n2.images[e], o2 = self.URL || self.webkitURL;
|
|
let s2 = r2.uri || "", a2 = false;
|
|
if (r2.bufferView !== undefined)
|
|
s2 = this.getDependency("bufferView", r2.bufferView).then(function(e2) {
|
|
a2 = true;
|
|
const t3 = new Blob([e2], { type: r2.mimeType });
|
|
return s2 = o2.createObjectURL(t3), s2;
|
|
});
|
|
else if (r2.uri === undefined)
|
|
throw new Error("THREE.GLTFLoader: Image " + e + " is missing URI and bufferView");
|
|
const A2 = Promise.resolve(s2).then(function(e2) {
|
|
return new Promise(function(n3, r3) {
|
|
let o3 = n3;
|
|
t2.isImageBitmapLoader === true && (o3 = function(e3) {
|
|
const t3 = new Re.Texture(e3);
|
|
t3.needsUpdate = true, n3(t3);
|
|
}), t2.load(Re.LoaderUtils.resolveURL(e2, i2.path), o3, undefined, r3);
|
|
});
|
|
}).then(function(e2) {
|
|
var t3;
|
|
return a2 === true && o2.revokeObjectURL(s2), Ut(e2, r2), e2.userData.mimeType = r2.mimeType || ((t3 = r2.uri).search(/\.jpe?g($|\?)/i) > 0 || t3.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : t3.search(/\.webp($|\?)/i) > 0 || t3.search(/^data\:image\/webp/) === 0 ? "image/webp" : t3.search(/\.ktx2($|\?)/i) > 0 || t3.search(/^data\:image\/ktx2/) === 0 ? "image/ktx2" : "image/png"), e2;
|
|
}).catch(function(e2) {
|
|
throw console.error("THREE.GLTFLoader: Couldn't load texture", s2), e2;
|
|
});
|
|
return this.sourceCache[e] = A2, A2;
|
|
}
|
|
assignTexture(e, t2, n2, i2) {
|
|
const r2 = this;
|
|
return this.getDependency("texture", n2.index).then(function(o2) {
|
|
if (!o2)
|
|
return null;
|
|
if (n2.texCoord !== undefined && n2.texCoord > 0 && ((o2 = o2.clone()).channel = n2.texCoord), r2.extensions[$e.KHR_TEXTURE_TRANSFORM]) {
|
|
const e2 = n2.extensions !== undefined ? n2.extensions[$e.KHR_TEXTURE_TRANSFORM] : undefined;
|
|
if (e2) {
|
|
const t3 = r2.associations.get(o2);
|
|
o2 = r2.extensions[$e.KHR_TEXTURE_TRANSFORM].extendTexture(o2, e2), r2.associations.set(o2, t3);
|
|
}
|
|
}
|
|
return i2 !== undefined && (o2.colorSpace = i2), e[t2] = o2, o2;
|
|
});
|
|
}
|
|
assignFinalMaterial(e) {
|
|
const t2 = e.geometry;
|
|
let n2 = e.material;
|
|
const i2 = t2.attributes.tangent === undefined, r2 = t2.attributes.color !== undefined, o2 = t2.attributes.normal === undefined;
|
|
if (e.isPoints) {
|
|
const e2 = "PointsMaterial:" + n2.uuid;
|
|
let t3 = this.cache.get(e2);
|
|
t3 || (t3 = new Re.PointsMaterial, Re.Material.prototype.copy.call(t3, n2), t3.color.copy(n2.color), t3.map = n2.map, t3.sizeAttenuation = false, this.cache.add(e2, t3)), n2 = t3;
|
|
} else if (e.isLine) {
|
|
const e2 = "LineBasicMaterial:" + n2.uuid;
|
|
let t3 = this.cache.get(e2);
|
|
t3 || (t3 = new Re.LineBasicMaterial, Re.Material.prototype.copy.call(t3, n2), t3.color.copy(n2.color), t3.map = n2.map, this.cache.add(e2, t3)), n2 = t3;
|
|
}
|
|
if (i2 || r2 || o2) {
|
|
let e2 = "ClonedMaterial:" + n2.uuid + ":";
|
|
i2 && (e2 += "derivative-tangents:"), r2 && (e2 += "vertex-colors:"), o2 && (e2 += "flat-shading:");
|
|
let t3 = this.cache.get(e2);
|
|
t3 || (t3 = n2.clone(), r2 && (t3.vertexColors = true), o2 && (t3.flatShading = true), i2 && (t3.normalScale && (t3.normalScale.y *= -1), t3.clearcoatNormalScale && (t3.clearcoatNormalScale.y *= -1)), this.cache.add(e2, t3), this.associations.set(t3, this.associations.get(n2))), n2 = t3;
|
|
}
|
|
e.material = n2;
|
|
}
|
|
getMaterialType() {
|
|
return Re.MeshStandardMaterial;
|
|
}
|
|
loadMaterial(e) {
|
|
const t2 = this, n2 = this.json, i2 = this.extensions, r2 = n2.materials[e];
|
|
let o2;
|
|
const s2 = {}, a2 = [];
|
|
if ((r2.extensions || {})[$e.KHR_MATERIALS_UNLIT]) {
|
|
const e2 = i2[$e.KHR_MATERIALS_UNLIT];
|
|
o2 = e2.getMaterialType(), a2.push(e2.extendParams(s2, r2, t2));
|
|
} else {
|
|
const n3 = r2.pbrMetallicRoughness || {};
|
|
if (s2.color = new Re.Color(1, 1, 1), s2.opacity = 1, Array.isArray(n3.baseColorFactor)) {
|
|
const e2 = n3.baseColorFactor;
|
|
s2.color.setRGB(e2[0], e2[1], e2[2], Re.LinearSRGBColorSpace), s2.opacity = e2[3];
|
|
}
|
|
n3.baseColorTexture !== undefined && a2.push(t2.assignTexture(s2, "map", n3.baseColorTexture, Re.SRGBColorSpace)), s2.metalness = n3.metallicFactor !== undefined ? n3.metallicFactor : 1, s2.roughness = n3.roughnessFactor !== undefined ? n3.roughnessFactor : 1, n3.metallicRoughnessTexture !== undefined && (a2.push(t2.assignTexture(s2, "metalnessMap", n3.metallicRoughnessTexture)), a2.push(t2.assignTexture(s2, "roughnessMap", n3.metallicRoughnessTexture))), o2 = this._invokeOne(function(t3) {
|
|
return t3.getMaterialType && t3.getMaterialType(e);
|
|
}), a2.push(Promise.all(this._invokeAll(function(t3) {
|
|
return t3.extendMaterialParams && t3.extendMaterialParams(e, s2);
|
|
})));
|
|
}
|
|
r2.doubleSided === true && (s2.side = Re.DoubleSide);
|
|
const A2 = r2.alphaMode || "OPAQUE";
|
|
if (A2 === "BLEND" ? (s2.transparent = true, s2.depthWrite = false) : (s2.transparent = false, A2 === "MASK" && (s2.alphaTest = r2.alphaCutoff !== undefined ? r2.alphaCutoff : 0.5)), r2.normalTexture !== undefined && o2 !== Re.MeshBasicMaterial && (a2.push(t2.assignTexture(s2, "normalMap", r2.normalTexture)), s2.normalScale = new Re.Vector2(1, 1), r2.normalTexture.scale !== undefined)) {
|
|
const e2 = r2.normalTexture.scale;
|
|
s2.normalScale.set(e2, e2);
|
|
}
|
|
if (r2.occlusionTexture !== undefined && o2 !== Re.MeshBasicMaterial && (a2.push(t2.assignTexture(s2, "aoMap", r2.occlusionTexture)), r2.occlusionTexture.strength !== undefined && (s2.aoMapIntensity = r2.occlusionTexture.strength)), r2.emissiveFactor !== undefined && o2 !== Re.MeshBasicMaterial) {
|
|
const e2 = r2.emissiveFactor;
|
|
s2.emissive = new Re.Color().setRGB(e2[0], e2[1], e2[2], Re.LinearSRGBColorSpace);
|
|
}
|
|
return r2.emissiveTexture !== undefined && o2 !== Re.MeshBasicMaterial && a2.push(t2.assignTexture(s2, "emissiveMap", r2.emissiveTexture, Re.SRGBColorSpace)), Promise.all(a2).then(function() {
|
|
const n3 = new o2(s2);
|
|
return r2.name && (n3.name = r2.name), Ut(n3, r2), t2.associations.set(n3, { materials: e }), r2.extensions && Ft(i2, n3, r2), n3;
|
|
});
|
|
}
|
|
createUniqueName(e) {
|
|
const t2 = Re.PropertyBinding.sanitizeNodeName(e || "");
|
|
return t2 in this.nodeNamesUsed ? t2 + "_" + ++this.nodeNamesUsed[t2] : (this.nodeNamesUsed[t2] = 0, t2);
|
|
}
|
|
loadGeometries(e) {
|
|
const t2 = this, n2 = this.extensions, i2 = this.primitiveCache;
|
|
function r2(e2) {
|
|
return n2[$e.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e2, t2).then(function(n3) {
|
|
return Ht(n3, e2, t2);
|
|
});
|
|
}
|
|
const o2 = [];
|
|
for (let n3 = 0, s2 = e.length;n3 < s2; n3++) {
|
|
const s3 = e[n3], a2 = Pt(s3), A2 = i2[a2];
|
|
if (A2)
|
|
o2.push(A2.promise);
|
|
else {
|
|
let e2;
|
|
e2 = s3.extensions && s3.extensions[$e.KHR_DRACO_MESH_COMPRESSION] ? r2(s3) : Ht(new Re.BufferGeometry, s3, t2), i2[a2] = { primitive: s3, promise: e2 }, o2.push(e2);
|
|
}
|
|
}
|
|
return Promise.all(o2);
|
|
}
|
|
loadMesh(e) {
|
|
const t2 = this, n2 = this.json, i2 = this.extensions, r2 = n2.meshes[e], o2 = r2.primitives, s2 = [];
|
|
for (let e2 = 0, t3 = o2.length;e2 < t3; e2++) {
|
|
const t4 = o2[e2].material === undefined ? Rt(this.cache) : this.getDependency("material", o2[e2].material);
|
|
s2.push(t4);
|
|
}
|
|
return s2.push(t2.loadGeometries(o2)), Promise.all(s2).then(function(n3) {
|
|
const s3 = n3.slice(0, n3.length - 1), a2 = n3[n3.length - 1], A2 = [];
|
|
for (let n4 = 0, l3 = a2.length;n4 < l3; n4++) {
|
|
const l4 = a2[n4], c2 = o2[n4];
|
|
let h2;
|
|
const d2 = s3[n4];
|
|
if (c2.mode === xt.TRIANGLES || c2.mode === xt.TRIANGLE_STRIP || c2.mode === xt.TRIANGLE_FAN || c2.mode === undefined)
|
|
h2 = r2.isSkinnedMesh === true ? new Re.SkinnedMesh(l4, d2) : new Re.Mesh(l4, d2), h2.isSkinnedMesh === true && h2.normalizeSkinWeights(), c2.mode === xt.TRIANGLE_STRIP ? h2.geometry = Ye(h2.geometry, Re.TriangleStripDrawMode) : c2.mode === xt.TRIANGLE_FAN && (h2.geometry = Ye(h2.geometry, Re.TriangleFanDrawMode));
|
|
else if (c2.mode === xt.LINES)
|
|
h2 = new Re.LineSegments(l4, d2);
|
|
else if (c2.mode === xt.LINE_STRIP)
|
|
h2 = new Re.Line(l4, d2);
|
|
else if (c2.mode === xt.LINE_LOOP)
|
|
h2 = new Re.LineLoop(l4, d2);
|
|
else {
|
|
if (c2.mode !== xt.POINTS)
|
|
throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + c2.mode);
|
|
h2 = new Re.Points(l4, d2);
|
|
}
|
|
Object.keys(h2.geometry.morphAttributes).length > 0 && Ot(h2, r2), h2.name = t2.createUniqueName(r2.name || "mesh_" + e), Ut(h2, r2), c2.extensions && Ft(i2, h2, c2), t2.assignFinalMaterial(h2), A2.push(h2);
|
|
}
|
|
for (let n4 = 0, i3 = A2.length;n4 < i3; n4++)
|
|
t2.associations.set(A2[n4], { meshes: e, primitives: n4 });
|
|
if (A2.length === 1)
|
|
return r2.extensions && Ft(i2, A2[0], r2), A2[0];
|
|
const l2 = new Re.Group;
|
|
r2.extensions && Ft(i2, l2, r2), t2.associations.set(l2, { meshes: e });
|
|
for (let e2 = 0, t3 = A2.length;e2 < t3; e2++)
|
|
l2.add(A2[e2]);
|
|
return l2;
|
|
});
|
|
}
|
|
loadCamera(e) {
|
|
let t2;
|
|
const n2 = this.json.cameras[e], i2 = n2[n2.type];
|
|
if (i2)
|
|
return n2.type === "perspective" ? t2 = new Re.PerspectiveCamera(Re.MathUtils.radToDeg(i2.yfov), i2.aspectRatio || 1, i2.znear || 1, i2.zfar || 2000000) : n2.type === "orthographic" && (t2 = new Re.OrthographicCamera(-i2.xmag, i2.xmag, i2.ymag, -i2.ymag, i2.znear, i2.zfar)), n2.name && (t2.name = this.createUniqueName(n2.name)), Ut(t2, n2), Promise.resolve(t2);
|
|
console.warn("THREE.GLTFLoader: Missing camera parameters.");
|
|
}
|
|
loadSkin(e) {
|
|
const t2 = this.json.skins[e], n2 = [];
|
|
for (let e2 = 0, i2 = t2.joints.length;e2 < i2; e2++)
|
|
n2.push(this._loadNodeShallow(t2.joints[e2]));
|
|
return t2.inverseBindMatrices !== undefined ? n2.push(this.getDependency("accessor", t2.inverseBindMatrices)) : n2.push(null), Promise.all(n2).then(function(e2) {
|
|
const n3 = e2.pop(), i2 = e2, r2 = [], o2 = [];
|
|
for (let e3 = 0, s2 = i2.length;e3 < s2; e3++) {
|
|
const s3 = i2[e3];
|
|
if (s3) {
|
|
r2.push(s3);
|
|
const t3 = new Re.Matrix4;
|
|
n3 !== null && t3.fromArray(n3.array, 16 * e3), o2.push(t3);
|
|
} else
|
|
console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', t2.joints[e3]);
|
|
}
|
|
return new Re.Skeleton(r2, o2);
|
|
});
|
|
}
|
|
loadAnimation(e) {
|
|
const t2 = this.json, n2 = this, i2 = t2.animations[e], r2 = i2.name ? i2.name : "animation_" + e, o2 = [], s2 = [], a2 = [], A2 = [], l2 = [];
|
|
for (let e2 = 0, t3 = i2.channels.length;e2 < t3; e2++) {
|
|
const t4 = i2.channels[e2], n3 = i2.samplers[t4.sampler], r3 = t4.target, c2 = r3.node, h2 = i2.parameters !== undefined ? i2.parameters[n3.input] : n3.input, d2 = i2.parameters !== undefined ? i2.parameters[n3.output] : n3.output;
|
|
r3.node !== undefined && (o2.push(this.getDependency("node", c2)), s2.push(this.getDependency("accessor", h2)), a2.push(this.getDependency("accessor", d2)), A2.push(n3), l2.push(r3));
|
|
}
|
|
return Promise.all([Promise.all(o2), Promise.all(s2), Promise.all(a2), Promise.all(A2), Promise.all(l2)]).then(function(e2) {
|
|
const t3 = e2[0], i3 = e2[1], o3 = e2[2], s3 = e2[3], a3 = e2[4], A3 = [];
|
|
for (let e3 = 0, r3 = t3.length;e3 < r3; e3++) {
|
|
const r4 = t3[e3], l3 = i3[e3], c2 = o3[e3], h2 = s3[e3], d2 = a3[e3];
|
|
if (r4 === undefined)
|
|
continue;
|
|
r4.updateMatrix && r4.updateMatrix();
|
|
const u2 = n2._createAnimationTracks(r4, l3, c2, h2, d2);
|
|
if (u2)
|
|
for (let e4 = 0;e4 < u2.length; e4++)
|
|
A3.push(u2[e4]);
|
|
}
|
|
return new Re.AnimationClip(r2, undefined, A3);
|
|
});
|
|
}
|
|
createNodeMesh(e) {
|
|
const t2 = this.json, n2 = this, i2 = t2.nodes[e];
|
|
return i2.mesh === undefined ? null : n2.getDependency("mesh", i2.mesh).then(function(e2) {
|
|
const t3 = n2._getNodeRef(n2.meshCache, i2.mesh, e2);
|
|
return i2.weights !== undefined && t3.traverse(function(e3) {
|
|
if (e3.isMesh)
|
|
for (let t4 = 0, n3 = i2.weights.length;t4 < n3; t4++)
|
|
e3.morphTargetInfluences[t4] = i2.weights[t4];
|
|
}), t3;
|
|
});
|
|
}
|
|
loadNode(e) {
|
|
const t2 = this, n2 = this.json.nodes[e], i2 = t2._loadNodeShallow(e), r2 = [], o2 = n2.children || [];
|
|
for (let e2 = 0, n3 = o2.length;e2 < n3; e2++)
|
|
r2.push(t2.getDependency("node", o2[e2]));
|
|
const s2 = n2.skin === undefined ? Promise.resolve(null) : t2.getDependency("skin", n2.skin);
|
|
return Promise.all([i2, Promise.all(r2), s2]).then(function(e2) {
|
|
const t3 = e2[0], n3 = e2[1], i3 = e2[2];
|
|
i3 !== null && t3.traverse(function(e3) {
|
|
e3.isSkinnedMesh && e3.bind(i3, jt);
|
|
});
|
|
for (let e3 = 0, i4 = n3.length;e3 < i4; e3++)
|
|
t3.add(n3[e3]);
|
|
return t3;
|
|
});
|
|
}
|
|
_loadNodeShallow(e) {
|
|
const t2 = this.json, n2 = this.extensions, i2 = this;
|
|
if (this.nodeCache[e] !== undefined)
|
|
return this.nodeCache[e];
|
|
const r2 = t2.nodes[e], o2 = r2.name ? i2.createUniqueName(r2.name) : "", s2 = [], a2 = i2._invokeOne(function(t3) {
|
|
return t3.createNodeMesh && t3.createNodeMesh(e);
|
|
});
|
|
return a2 && s2.push(a2), r2.camera !== undefined && s2.push(i2.getDependency("camera", r2.camera).then(function(e2) {
|
|
return i2._getNodeRef(i2.cameraCache, r2.camera, e2);
|
|
})), i2._invokeAll(function(t3) {
|
|
return t3.createNodeAttachment && t3.createNodeAttachment(e);
|
|
}).forEach(function(e2) {
|
|
s2.push(e2);
|
|
}), this.nodeCache[e] = Promise.all(s2).then(function(t3) {
|
|
let s3;
|
|
if (s3 = r2.isBone === true ? new Re.Bone : t3.length > 1 ? new Re.Group : t3.length === 1 ? t3[0] : new Re.Object3D, s3 !== t3[0])
|
|
for (let e2 = 0, n3 = t3.length;e2 < n3; e2++)
|
|
s3.add(t3[e2]);
|
|
if (r2.name && (s3.userData.name = r2.name, s3.name = o2), Ut(s3, r2), r2.extensions && Ft(n2, s3, r2), r2.matrix !== undefined) {
|
|
const e2 = new Re.Matrix4;
|
|
e2.fromArray(r2.matrix), s3.applyMatrix4(e2);
|
|
} else
|
|
r2.translation !== undefined && s3.position.fromArray(r2.translation), r2.rotation !== undefined && s3.quaternion.fromArray(r2.rotation), r2.scale !== undefined && s3.scale.fromArray(r2.scale);
|
|
return i2.associations.has(s3) || i2.associations.set(s3, {}), i2.associations.get(s3).nodes = e, s3;
|
|
}), this.nodeCache[e];
|
|
}
|
|
loadScene(e) {
|
|
const t2 = this.extensions, n2 = this.json.scenes[e], i2 = this, r2 = new Re.Group;
|
|
n2.name && (r2.name = i2.createUniqueName(n2.name)), Ut(r2, n2), n2.extensions && Ft(t2, r2, n2);
|
|
const o2 = n2.nodes || [], s2 = [];
|
|
for (let e2 = 0, t3 = o2.length;e2 < t3; e2++)
|
|
s2.push(i2.getDependency("node", o2[e2]));
|
|
return Promise.all(s2).then(function(e2) {
|
|
for (let t3 = 0, n3 = e2.length;t3 < n3; t3++)
|
|
r2.add(e2[t3]);
|
|
return i2.associations = ((e3) => {
|
|
const t3 = new Map;
|
|
for (const [e4, n3] of i2.associations)
|
|
(e4 instanceof Re.Material || e4 instanceof Re.Texture) && t3.set(e4, n3);
|
|
return e3.traverse((e4) => {
|
|
const n3 = i2.associations.get(e4);
|
|
n3 != null && t3.set(e4, n3);
|
|
}), t3;
|
|
})(r2), r2;
|
|
});
|
|
}
|
|
_createAnimationTracks(e, t2, n2, i2, r2) {
|
|
const o2 = [], s2 = e.name ? e.name : e.uuid, a2 = [];
|
|
let A2;
|
|
switch (kt[r2.path] === kt.weights ? e.traverse(function(e2) {
|
|
e2.morphTargetInfluences && a2.push(e2.name ? e2.name : e2.uuid);
|
|
}) : a2.push(s2), kt[r2.path]) {
|
|
case kt.weights:
|
|
A2 = Re.NumberKeyframeTrack;
|
|
break;
|
|
case kt.rotation:
|
|
A2 = Re.QuaternionKeyframeTrack;
|
|
break;
|
|
case kt.position:
|
|
case kt.scale:
|
|
A2 = Re.VectorKeyframeTrack;
|
|
break;
|
|
default:
|
|
A2 = n2.itemSize === 1 ? Re.NumberKeyframeTrack : Re.VectorKeyframeTrack;
|
|
}
|
|
const l2 = i2.interpolation !== undefined ? Tt[i2.interpolation] : Re.InterpolateLinear, c2 = this._getArrayFromAccessor(n2);
|
|
for (let e2 = 0, n3 = a2.length;e2 < n3; e2++) {
|
|
const n4 = new A2(a2[e2] + "." + kt[r2.path], t2.array, c2, l2);
|
|
i2.interpolation === "CUBICSPLINE" && this._createCubicSplineTrackInterpolant(n4), o2.push(n4);
|
|
}
|
|
return o2;
|
|
}
|
|
_getArrayFromAccessor(e) {
|
|
let t2 = e.array;
|
|
if (e.normalized) {
|
|
const e2 = Nt(t2.constructor), n2 = new Float32Array(t2.length);
|
|
for (let i2 = 0, r2 = t2.length;i2 < r2; i2++)
|
|
n2[i2] = t2[i2] * e2;
|
|
t2 = n2;
|
|
}
|
|
return t2;
|
|
}
|
|
_createCubicSplineTrackInterpolant(e) {
|
|
e.createInterpolant = function(e2) {
|
|
return new (this instanceof Re.QuaternionKeyframeTrack ? wt : yt)(this.times, this.values, this.getValueSize() / 3, e2);
|
|
}, e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
|
|
}
|
|
}
|
|
function Ht(e, t2, n2) {
|
|
const i2 = t2.attributes, r2 = [];
|
|
function o2(t3, i3) {
|
|
return n2.getDependency("accessor", t3).then(function(t4) {
|
|
e.setAttribute(i3, t4);
|
|
});
|
|
}
|
|
for (const t3 in i2) {
|
|
const n3 = Dt[t3] || t3.toLowerCase();
|
|
n3 in e.attributes || r2.push(o2(i2[t3], n3));
|
|
}
|
|
if (t2.indices !== undefined && !e.index) {
|
|
const i3 = n2.getDependency("accessor", t2.indices).then(function(t3) {
|
|
e.setIndex(t3);
|
|
});
|
|
r2.push(i3);
|
|
}
|
|
return Re.ColorManagement.workingColorSpace !== Re.LinearSRGBColorSpace && "COLOR_0" in i2 && console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Re.ColorManagement.workingColorSpace}" not supported.`), Ut(e, t2), function(e2, t3, n3) {
|
|
const i3 = t3.attributes, r3 = new Re.Box3;
|
|
if (i3.POSITION === undefined)
|
|
return;
|
|
{
|
|
const e3 = n3.json.accessors[i3.POSITION], t4 = e3.min, o4 = e3.max;
|
|
if (t4 === undefined || o4 === undefined)
|
|
return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
if (r3.set(new Re.Vector3(t4[0], t4[1], t4[2]), new Re.Vector3(o4[0], o4[1], o4[2])), e3.normalized) {
|
|
const t5 = Nt(Qt[e3.componentType]);
|
|
r3.min.multiplyScalar(t5), r3.max.multiplyScalar(t5);
|
|
}
|
|
}
|
|
const o3 = t3.targets;
|
|
if (o3 !== undefined) {
|
|
const e3 = new Re.Vector3, t4 = new Re.Vector3;
|
|
for (let i4 = 0, r4 = o3.length;i4 < r4; i4++) {
|
|
const r5 = o3[i4];
|
|
if (r5.POSITION !== undefined) {
|
|
const i5 = n3.json.accessors[r5.POSITION], o4 = i5.min, s3 = i5.max;
|
|
if (o4 !== undefined && s3 !== undefined) {
|
|
if (t4.setX(Math.max(Math.abs(o4[0]), Math.abs(s3[0]))), t4.setY(Math.max(Math.abs(o4[1]), Math.abs(s3[1]))), t4.setZ(Math.max(Math.abs(o4[2]), Math.abs(s3[2]))), i5.normalized) {
|
|
const e4 = Nt(Qt[i5.componentType]);
|
|
t4.multiplyScalar(e4);
|
|
}
|
|
e3.max(t4);
|
|
} else
|
|
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
}
|
|
}
|
|
r3.expandByVector(e3);
|
|
}
|
|
e2.boundingBox = r3;
|
|
const s2 = new Re.Sphere;
|
|
r3.getCenter(s2.center), s2.radius = r3.min.distanceTo(r3.max) / 2, e2.boundingSphere = s2;
|
|
}(e, t2, n2), Promise.all(r2).then(function() {
|
|
return t2.targets !== undefined ? function(e2, t3, n3) {
|
|
let i3 = false, r3 = false, o3 = false;
|
|
for (let e3 = 0, n4 = t3.length;e3 < n4; e3++) {
|
|
const n5 = t3[e3];
|
|
if (n5.POSITION !== undefined && (i3 = true), n5.NORMAL !== undefined && (r3 = true), n5.COLOR_0 !== undefined && (o3 = true), i3 && r3 && o3)
|
|
break;
|
|
}
|
|
if (!i3 && !r3 && !o3)
|
|
return Promise.resolve(e2);
|
|
const s2 = [], a2 = [], A2 = [];
|
|
for (let l2 = 0, c2 = t3.length;l2 < c2; l2++) {
|
|
const c3 = t3[l2];
|
|
if (i3) {
|
|
const t4 = c3.POSITION !== undefined ? n3.getDependency("accessor", c3.POSITION) : e2.attributes.position;
|
|
s2.push(t4);
|
|
}
|
|
if (r3) {
|
|
const t4 = c3.NORMAL !== undefined ? n3.getDependency("accessor", c3.NORMAL) : e2.attributes.normal;
|
|
a2.push(t4);
|
|
}
|
|
if (o3) {
|
|
const t4 = c3.COLOR_0 !== undefined ? n3.getDependency("accessor", c3.COLOR_0) : e2.attributes.color;
|
|
A2.push(t4);
|
|
}
|
|
}
|
|
return Promise.all([Promise.all(s2), Promise.all(a2), Promise.all(A2)]).then(function(t4) {
|
|
const n4 = t4[0], s3 = t4[1], a3 = t4[2];
|
|
return i3 && (e2.morphAttributes.position = n4), r3 && (e2.morphAttributes.normal = s3), o3 && (e2.morphAttributes.color = a3), e2.morphTargetsRelative = true, e2;
|
|
});
|
|
}(e, t2.targets, n2) : e;
|
|
});
|
|
}
|
|
|
|
class qt {
|
|
constructor(e = 4) {
|
|
this.pool = e, this.queue = [], this.workers = [], this.workersResolve = [], this.workerStatus = 0;
|
|
}
|
|
_initWorker(e) {
|
|
if (!this.workers[e]) {
|
|
const t2 = this.workerCreator();
|
|
t2.addEventListener("message", this._onMessage.bind(this, e)), this.workers[e] = t2;
|
|
}
|
|
}
|
|
_getIdleWorker() {
|
|
for (let e = 0;e < this.pool; e++)
|
|
if (!(this.workerStatus & 1 << e))
|
|
return e;
|
|
return -1;
|
|
}
|
|
_onMessage(e, t2) {
|
|
const n2 = this.workersResolve[e];
|
|
if (n2 && n2(t2), this.queue.length) {
|
|
const { resolve: t3, msg: n3, transfer: i2 } = this.queue.shift();
|
|
this.workersResolve[e] = t3, this.workers[e].postMessage(n3, i2);
|
|
} else
|
|
this.workerStatus ^= 1 << e;
|
|
}
|
|
setWorkerCreator(e) {
|
|
this.workerCreator = e;
|
|
}
|
|
setWorkerLimit(e) {
|
|
this.pool = e;
|
|
}
|
|
postMessage(e, t2) {
|
|
return new Promise((n2) => {
|
|
const i2 = this._getIdleWorker();
|
|
i2 !== -1 ? (this._initWorker(i2), this.workerStatus |= 1 << i2, this.workersResolve[i2] = n2, this.workers[i2].postMessage(e, t2)) : this.queue.push({ resolve: n2, msg: e, transfer: t2 });
|
|
});
|
|
}
|
|
dispose() {
|
|
this.workers.forEach((e) => e.terminate()), this.workersResolve.length = 0, this.workers.length = 0, this.queue.length = 0, this.workerStatus = 0;
|
|
}
|
|
}
|
|
|
|
class an {
|
|
constructor() {
|
|
this.vkFormat = 0, this.typeSize = 1, this.pixelWidth = 0, this.pixelHeight = 0, this.pixelDepth = 0, this.layerCount = 0, this.faceCount = 1, this.supercompressionScheme = 0, this.levels = [], this.dataFormatDescriptor = [{ vendorId: 0, descriptorType: 0, descriptorBlockSize: 0, versionNumber: 2, colorModel: 0, colorPrimaries: 1, transferFunction: 2, flags: 0, texelBlockDimension: [0, 0, 0, 0], bytesPlane: [0, 0, 0, 0, 0, 0, 0, 0], samples: [] }], this.keyValue = {}, this.globalData = null;
|
|
}
|
|
}
|
|
|
|
class An {
|
|
constructor(e, t2, n2, i2) {
|
|
this._dataView = undefined, this._littleEndian = undefined, this._offset = undefined, this._dataView = new DataView(e.buffer, e.byteOffset + t2, n2), this._littleEndian = i2, this._offset = 0;
|
|
}
|
|
_nextUint8() {
|
|
const e = this._dataView.getUint8(this._offset);
|
|
return this._offset += 1, e;
|
|
}
|
|
_nextUint16() {
|
|
const e = this._dataView.getUint16(this._offset, this._littleEndian);
|
|
return this._offset += 2, e;
|
|
}
|
|
_nextUint32() {
|
|
const e = this._dataView.getUint32(this._offset, this._littleEndian);
|
|
return this._offset += 4, e;
|
|
}
|
|
_nextUint64() {
|
|
const e = this._dataView.getUint32(this._offset, this._littleEndian) + 2 ** 32 * this._dataView.getUint32(this._offset + 4, this._littleEndian);
|
|
return this._offset += 8, e;
|
|
}
|
|
_nextInt32() {
|
|
const e = this._dataView.getInt32(this._offset, this._littleEndian);
|
|
return this._offset += 4, e;
|
|
}
|
|
_nextUint8Array(e) {
|
|
const t2 = new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + this._offset, e);
|
|
return this._offset += e, t2;
|
|
}
|
|
_skip(e) {
|
|
return this._offset += e, this;
|
|
}
|
|
_scan(e, t2) {
|
|
t2 === undefined && (t2 = 0);
|
|
const n2 = this._offset;
|
|
let i2 = 0;
|
|
for (;this._dataView.getUint8(this._offset) !== t2 && i2 < e; )
|
|
i2++, this._offset++;
|
|
return i2 < e && this._offset++, new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + n2, i2);
|
|
}
|
|
}
|
|
function cn(e) {
|
|
return new TextDecoder().decode(e);
|
|
}
|
|
|
|
class fn {
|
|
init() {
|
|
return dn || (dn = typeof fetch != "undefined" ? fetch("data:application/wasm;base64," + mn).then((e) => e.arrayBuffer()).then((e) => WebAssembly.instantiate(e, pn)).then(this._init) : WebAssembly.instantiate(hn.from(mn, "base64"), pn).then(this._init), dn);
|
|
}
|
|
_init(e) {
|
|
un = e.instance, pn.env.emscripten_notify_memory_growth(0);
|
|
}
|
|
decode(e, t2 = 0) {
|
|
if (!un)
|
|
throw new Error("ZSTDDecoder: Await .init() before decoding.");
|
|
const n2 = e.byteLength, i2 = un.exports.malloc(n2);
|
|
gn.set(e, i2), t2 = t2 || Number(un.exports.ZSTD_findDecompressedSize(i2, n2));
|
|
const r2 = un.exports.malloc(t2), o2 = un.exports.ZSTD_decompress(r2, t2, i2, n2), s2 = gn.slice(r2, r2 + o2);
|
|
return un.exports.free(i2), un.exports.free(r2), s2;
|
|
}
|
|
}
|
|
function wn(e) {
|
|
const t2 = e.dataFormatDescriptor[0];
|
|
return t2.colorPrimaries === 1 ? t2.transferFunction === 2 ? Re.SRGBColorSpace : Re.LinearSRGBColorSpace : t2.colorPrimaries === 10 ? t2.transferFunction === 2 ? "display-p3" : "display-p3-linear" : (t2.colorPrimaries === 0 || console.warn(`THREE.KTX2Loader: Unsupported color primaries, "${t2.colorPrimaries}"`), Re.NoColorSpace);
|
|
}
|
|
|
|
class _n {
|
|
constructor(e = new Re.Vector3, t2 = new Re.Vector3, n2 = new Re.Matrix3) {
|
|
this.center = e, this.halfSize = t2, this.rotation = n2;
|
|
}
|
|
set(e, t2, n2) {
|
|
return this.center = e, this.halfSize = t2, this.rotation = n2, this;
|
|
}
|
|
copy(e) {
|
|
return this.center.copy(e.center), this.halfSize.copy(e.halfSize), this.rotation.copy(e.rotation), this;
|
|
}
|
|
clone() {
|
|
return new this.constructor().copy(this);
|
|
}
|
|
getSize(e) {
|
|
return e.copy(this.halfSize).multiplyScalar(2);
|
|
}
|
|
clampPoint(e, t2) {
|
|
const n2 = this.halfSize;
|
|
Rn.subVectors(e, this.center), this.rotation.extractBasis(Dn, kn, Tn), t2.copy(this.center);
|
|
const i2 = Re.MathUtils.clamp(Rn.dot(Dn), -n2.x, n2.x);
|
|
t2.add(Dn.multiplyScalar(i2));
|
|
const r2 = Re.MathUtils.clamp(Rn.dot(kn), -n2.y, n2.y);
|
|
t2.add(kn.multiplyScalar(r2));
|
|
const o2 = Re.MathUtils.clamp(Rn.dot(Tn), -n2.z, n2.z);
|
|
return t2.add(Tn.multiplyScalar(o2)), t2;
|
|
}
|
|
containsPoint(e) {
|
|
return Rn.subVectors(e, this.center), this.rotation.extractBasis(Dn, kn, Tn), Math.abs(Rn.dot(Dn)) <= this.halfSize.x && Math.abs(Rn.dot(kn)) <= this.halfSize.y && Math.abs(Rn.dot(Tn)) <= this.halfSize.z;
|
|
}
|
|
intersectsBox3(e) {
|
|
return this.intersectsOBB(Hn.fromBox3(e));
|
|
}
|
|
intersectsSphere(e) {
|
|
return this.clampPoint(e.center, Un), Un.distanceToSquared(e.center) <= e.radius * e.radius;
|
|
}
|
|
intersectsOBB(e, t2 = Number.EPSILON) {
|
|
xn.c = this.center, xn.e[0] = this.halfSize.x, xn.e[1] = this.halfSize.y, xn.e[2] = this.halfSize.z, this.rotation.extractBasis(xn.u[0], xn.u[1], xn.u[2]), Qn.c = e.center, Qn.e[0] = e.halfSize.x, Qn.e[1] = e.halfSize.y, Qn.e[2] = e.halfSize.z, e.rotation.extractBasis(Qn.u[0], Qn.u[1], Qn.u[2]);
|
|
for (let e2 = 0;e2 < 3; e2++)
|
|
for (let t3 = 0;t3 < 3; t3++)
|
|
Ln[e2][t3] = xn.u[e2].dot(Qn.u[t3]);
|
|
Rn.subVectors(Qn.c, xn.c), Sn[0] = Rn.dot(xn.u[0]), Sn[1] = Rn.dot(xn.u[1]), Sn[2] = Rn.dot(xn.u[2]);
|
|
for (let e2 = 0;e2 < 3; e2++)
|
|
for (let n3 = 0;n3 < 3; n3++)
|
|
Mn[e2][n3] = Math.abs(Ln[e2][n3]) + t2;
|
|
let n2, i2;
|
|
for (let e2 = 0;e2 < 3; e2++)
|
|
if (n2 = xn.e[e2], i2 = Qn.e[0] * Mn[e2][0] + Qn.e[1] * Mn[e2][1] + Qn.e[2] * Mn[e2][2], Math.abs(Sn[e2]) > n2 + i2)
|
|
return false;
|
|
for (let e2 = 0;e2 < 3; e2++)
|
|
if (n2 = xn.e[0] * Mn[0][e2] + xn.e[1] * Mn[1][e2] + xn.e[2] * Mn[2][e2], i2 = Qn.e[e2], Math.abs(Sn[0] * Ln[0][e2] + Sn[1] * Ln[1][e2] + Sn[2] * Ln[2][e2]) > n2 + i2)
|
|
return false;
|
|
return n2 = xn.e[1] * Mn[2][0] + xn.e[2] * Mn[1][0], i2 = Qn.e[1] * Mn[0][2] + Qn.e[2] * Mn[0][1], !(Math.abs(Sn[2] * Ln[1][0] - Sn[1] * Ln[2][0]) > n2 + i2 || (n2 = xn.e[1] * Mn[2][1] + xn.e[2] * Mn[1][1], i2 = Qn.e[0] * Mn[0][2] + Qn.e[2] * Mn[0][0], Math.abs(Sn[2] * Ln[1][1] - Sn[1] * Ln[2][1]) > n2 + i2 || (n2 = xn.e[1] * Mn[2][2] + xn.e[2] * Mn[1][2], i2 = Qn.e[0] * Mn[0][1] + Qn.e[1] * Mn[0][0], Math.abs(Sn[2] * Ln[1][2] - Sn[1] * Ln[2][2]) > n2 + i2 || (n2 = xn.e[0] * Mn[2][0] + xn.e[2] * Mn[0][0], i2 = Qn.e[1] * Mn[1][2] + Qn.e[2] * Mn[1][1], Math.abs(Sn[0] * Ln[2][0] - Sn[2] * Ln[0][0]) > n2 + i2 || (n2 = xn.e[0] * Mn[2][1] + xn.e[2] * Mn[0][1], i2 = Qn.e[0] * Mn[1][2] + Qn.e[2] * Mn[1][0], Math.abs(Sn[0] * Ln[2][1] - Sn[2] * Ln[0][1]) > n2 + i2 || (n2 = xn.e[0] * Mn[2][2] + xn.e[2] * Mn[0][2], i2 = Qn.e[0] * Mn[1][1] + Qn.e[1] * Mn[1][0], Math.abs(Sn[0] * Ln[2][2] - Sn[2] * Ln[0][2]) > n2 + i2 || (n2 = xn.e[0] * Mn[1][0] + xn.e[1] * Mn[0][0], i2 = Qn.e[1] * Mn[2][2] + Qn.e[2] * Mn[2][1], Math.abs(Sn[1] * Ln[0][0] - Sn[0] * Ln[1][0]) > n2 + i2 || (n2 = xn.e[0] * Mn[1][1] + xn.e[1] * Mn[0][1], i2 = Qn.e[0] * Mn[2][2] + Qn.e[2] * Mn[2][0], Math.abs(Sn[1] * Ln[0][1] - Sn[0] * Ln[1][1]) > n2 + i2 || (n2 = xn.e[0] * Mn[1][2] + xn.e[1] * Mn[0][2], i2 = Qn.e[0] * Mn[2][1] + Qn.e[1] * Mn[2][0], Math.abs(Sn[1] * Ln[0][2] - Sn[0] * Ln[1][2]) > n2 + i2)))))))));
|
|
}
|
|
intersectsPlane(e) {
|
|
this.rotation.extractBasis(Dn, kn, Tn);
|
|
const t2 = this.halfSize.x * Math.abs(e.normal.dot(Dn)) + this.halfSize.y * Math.abs(e.normal.dot(kn)) + this.halfSize.z * Math.abs(e.normal.dot(Tn)), n2 = e.normal.dot(this.center) - e.constant;
|
|
return Math.abs(n2) <= t2;
|
|
}
|
|
intersectRay(e, t2) {
|
|
return this.getSize(Fn), Pn.setFromCenterAndSize(Rn.set(0, 0, 0), Fn), Gn.setFromMatrix3(this.rotation), Gn.setPosition(this.center), Nn.copy(Gn).invert(), jn.copy(e).applyMatrix4(Nn), jn.intersectBox(Pn, t2) ? t2.applyMatrix4(Gn) : null;
|
|
}
|
|
intersectsRay(e) {
|
|
return this.intersectRay(e, Rn) !== null;
|
|
}
|
|
fromBox3(e) {
|
|
return e.getCenter(this.center), e.getSize(this.halfSize).multiplyScalar(0.5), this.rotation.identity(), this;
|
|
}
|
|
equals(e) {
|
|
return e.center.equals(this.center) && e.halfSize.equals(this.halfSize) && e.rotation.equals(this.rotation);
|
|
}
|
|
applyMatrix4(e) {
|
|
const t2 = e.elements;
|
|
let n2 = Rn.set(t2[0], t2[1], t2[2]).length();
|
|
const i2 = Rn.set(t2[4], t2[5], t2[6]).length(), r2 = Rn.set(t2[8], t2[9], t2[10]).length();
|
|
e.determinant() < 0 && (n2 = -n2), On.setFromMatrix4(e);
|
|
const o2 = 1 / n2, s2 = 1 / i2, a2 = 1 / r2;
|
|
return On.elements[0] *= o2, On.elements[1] *= o2, On.elements[2] *= o2, On.elements[3] *= s2, On.elements[4] *= s2, On.elements[5] *= s2, On.elements[6] *= a2, On.elements[7] *= a2, On.elements[8] *= a2, this.rotation.multiply(On), this.halfSize.x *= n2, this.halfSize.y *= i2, this.halfSize.z *= r2, Rn.setFromMatrixPosition(e), this.center.add(Rn), this;
|
|
}
|
|
}
|
|
function ti() {
|
|
const e = { objects: [], object: {}, vertices: [], normals: [], colors: [], uvs: [], materials: {}, materialLibraries: [], startObject: function(e2, t2) {
|
|
if (this.object && this.object.fromDeclaration === false)
|
|
return this.object.name = e2, void (this.object.fromDeclaration = t2 !== false);
|
|
const n2 = this.object && typeof this.object.currentMaterial == "function" ? this.object.currentMaterial() : undefined;
|
|
if (this.object && typeof this.object._finalize == "function" && this.object._finalize(true), this.object = { name: e2 || "", fromDeclaration: t2 !== false, geometry: { vertices: [], normals: [], colors: [], uvs: [], hasUVIndices: false }, materials: [], smooth: true, startMaterial: function(e3, t3) {
|
|
const n3 = this._finalize(false);
|
|
n3 && (n3.inherited || n3.groupCount <= 0) && this.materials.splice(n3.index, 1);
|
|
const i2 = { index: this.materials.length, name: e3 || "", mtllib: Array.isArray(t3) && t3.length > 0 ? t3[t3.length - 1] : "", smooth: n3 !== undefined ? n3.smooth : this.smooth, groupStart: n3 !== undefined ? n3.groupEnd : 0, groupEnd: -1, groupCount: -1, inherited: false, clone: function(e4) {
|
|
const t4 = { index: typeof e4 == "number" ? e4 : this.index, name: this.name, mtllib: this.mtllib, smooth: this.smooth, groupStart: 0, groupEnd: -1, groupCount: -1, inherited: false };
|
|
return t4.clone = this.clone.bind(t4), t4;
|
|
} };
|
|
return this.materials.push(i2), i2;
|
|
}, currentMaterial: function() {
|
|
if (this.materials.length > 0)
|
|
return this.materials[this.materials.length - 1];
|
|
}, _finalize: function(e3) {
|
|
const t3 = this.currentMaterial();
|
|
if (t3 && t3.groupEnd === -1 && (t3.groupEnd = this.geometry.vertices.length / 3, t3.groupCount = t3.groupEnd - t3.groupStart, t3.inherited = false), e3 && this.materials.length > 1)
|
|
for (let e4 = this.materials.length - 1;e4 >= 0; e4--)
|
|
this.materials[e4].groupCount <= 0 && this.materials.splice(e4, 1);
|
|
return e3 && this.materials.length === 0 && this.materials.push({ name: "", smooth: this.smooth }), t3;
|
|
} }, n2 && n2.name && typeof n2.clone == "function") {
|
|
const e3 = n2.clone(0);
|
|
e3.inherited = true, this.object.materials.push(e3);
|
|
}
|
|
this.objects.push(this.object);
|
|
}, finalize: function() {
|
|
this.object && typeof this.object._finalize == "function" && this.object._finalize(true);
|
|
}, parseVertexIndex: function(e2, t2) {
|
|
const n2 = parseInt(e2, 10);
|
|
return 3 * (n2 >= 0 ? n2 - 1 : n2 + t2 / 3);
|
|
}, parseNormalIndex: function(e2, t2) {
|
|
const n2 = parseInt(e2, 10);
|
|
return 3 * (n2 >= 0 ? n2 - 1 : n2 + t2 / 3);
|
|
}, parseUVIndex: function(e2, t2) {
|
|
const n2 = parseInt(e2, 10);
|
|
return 2 * (n2 >= 0 ? n2 - 1 : n2 + t2 / 2);
|
|
}, addVertex: function(e2, t2, n2) {
|
|
const i2 = this.vertices, r2 = this.object.geometry.vertices;
|
|
r2.push(i2[e2 + 0], i2[e2 + 1], i2[e2 + 2]), r2.push(i2[t2 + 0], i2[t2 + 1], i2[t2 + 2]), r2.push(i2[n2 + 0], i2[n2 + 1], i2[n2 + 2]);
|
|
}, addVertexPoint: function(e2) {
|
|
const t2 = this.vertices;
|
|
this.object.geometry.vertices.push(t2[e2 + 0], t2[e2 + 1], t2[e2 + 2]);
|
|
}, addVertexLine: function(e2) {
|
|
const t2 = this.vertices;
|
|
this.object.geometry.vertices.push(t2[e2 + 0], t2[e2 + 1], t2[e2 + 2]);
|
|
}, addNormal: function(e2, t2, n2) {
|
|
const i2 = this.normals, r2 = this.object.geometry.normals;
|
|
r2.push(i2[e2 + 0], i2[e2 + 1], i2[e2 + 2]), r2.push(i2[t2 + 0], i2[t2 + 1], i2[t2 + 2]), r2.push(i2[n2 + 0], i2[n2 + 1], i2[n2 + 2]);
|
|
}, addFaceNormal: function(e2, t2, n2) {
|
|
const i2 = this.vertices, r2 = this.object.geometry.normals;
|
|
Wn.fromArray(i2, e2), Jn.fromArray(i2, t2), Xn.fromArray(i2, n2), $n.subVectors(Xn, Jn), Zn.subVectors(Wn, Jn), $n.cross(Zn), $n.normalize(), r2.push($n.x, $n.y, $n.z), r2.push($n.x, $n.y, $n.z), r2.push($n.x, $n.y, $n.z);
|
|
}, addColor: function(e2, t2, n2) {
|
|
const i2 = this.colors, r2 = this.object.geometry.colors;
|
|
i2[e2] !== undefined && r2.push(i2[e2 + 0], i2[e2 + 1], i2[e2 + 2]), i2[t2] !== undefined && r2.push(i2[t2 + 0], i2[t2 + 1], i2[t2 + 2]), i2[n2] !== undefined && r2.push(i2[n2 + 0], i2[n2 + 1], i2[n2 + 2]);
|
|
}, addUV: function(e2, t2, n2) {
|
|
const i2 = this.uvs, r2 = this.object.geometry.uvs;
|
|
r2.push(i2[e2 + 0], i2[e2 + 1]), r2.push(i2[t2 + 0], i2[t2 + 1]), r2.push(i2[n2 + 0], i2[n2 + 1]);
|
|
}, addDefaultUV: function() {
|
|
const e2 = this.object.geometry.uvs;
|
|
e2.push(0, 0), e2.push(0, 0), e2.push(0, 0);
|
|
}, addUVLine: function(e2) {
|
|
const t2 = this.uvs;
|
|
this.object.geometry.uvs.push(t2[e2 + 0], t2[e2 + 1]);
|
|
}, addFace: function(e2, t2, n2, i2, r2, o2, s2, a2, A2) {
|
|
const l2 = this.vertices.length;
|
|
let c2 = this.parseVertexIndex(e2, l2), h2 = this.parseVertexIndex(t2, l2), d2 = this.parseVertexIndex(n2, l2);
|
|
if (this.addVertex(c2, h2, d2), this.addColor(c2, h2, d2), s2 !== undefined && s2 !== "") {
|
|
const e3 = this.normals.length;
|
|
c2 = this.parseNormalIndex(s2, e3), h2 = this.parseNormalIndex(a2, e3), d2 = this.parseNormalIndex(A2, e3), this.addNormal(c2, h2, d2);
|
|
} else
|
|
this.addFaceNormal(c2, h2, d2);
|
|
if (i2 !== undefined && i2 !== "") {
|
|
const e3 = this.uvs.length;
|
|
c2 = this.parseUVIndex(i2, e3), h2 = this.parseUVIndex(r2, e3), d2 = this.parseUVIndex(o2, e3), this.addUV(c2, h2, d2), this.object.geometry.hasUVIndices = true;
|
|
} else
|
|
this.addDefaultUV();
|
|
}, addPointGeometry: function(e2) {
|
|
this.object.geometry.type = "Points";
|
|
const t2 = this.vertices.length;
|
|
for (let n2 = 0, i2 = e2.length;n2 < i2; n2++) {
|
|
const i3 = this.parseVertexIndex(e2[n2], t2);
|
|
this.addVertexPoint(i3), this.addColor(i3);
|
|
}
|
|
}, addLineGeometry: function(e2, t2) {
|
|
this.object.geometry.type = "Line";
|
|
const n2 = this.vertices.length, i2 = this.uvs.length;
|
|
for (let t3 = 0, i3 = e2.length;t3 < i3; t3++)
|
|
this.addVertexLine(this.parseVertexIndex(e2[t3], n2));
|
|
for (let e3 = 0, n3 = t2.length;e3 < n3; e3++)
|
|
this.addUVLine(this.parseUVIndex(t2[e3], i2));
|
|
} };
|
|
return e.startObject("", false), e;
|
|
}
|
|
|
|
class ri {
|
|
constructor(e = "", t2 = {}) {
|
|
this.baseUrl = e, this.options = t2, this.materialsInfo = {}, this.materials = {}, this.materialsArray = [], this.nameLookup = {}, this.crossOrigin = "anonymous", this.side = this.options.side !== undefined ? this.options.side : Re.FrontSide, this.wrap = this.options.wrap !== undefined ? this.options.wrap : Re.RepeatWrapping;
|
|
}
|
|
setCrossOrigin(e) {
|
|
return this.crossOrigin = e, this;
|
|
}
|
|
setManager(e) {
|
|
this.manager = e;
|
|
}
|
|
setMaterials(e) {
|
|
this.materialsInfo = this.convert(e), this.materials = {}, this.materialsArray = [], this.nameLookup = {};
|
|
}
|
|
convert(e) {
|
|
if (!this.options)
|
|
return e;
|
|
const t2 = {};
|
|
for (const n2 in e) {
|
|
const i2 = e[n2], r2 = {};
|
|
t2[n2] = r2;
|
|
for (const e2 in i2) {
|
|
let t3 = true, n3 = i2[e2];
|
|
const o2 = e2.toLowerCase();
|
|
switch (o2) {
|
|
case "kd":
|
|
case "ka":
|
|
case "ks":
|
|
this.options && this.options.normalizeRGB && (n3 = [n3[0] / 255, n3[1] / 255, n3[2] / 255]), this.options && this.options.ignoreZeroRGBs && n3[0] === 0 && n3[1] === 0 && n3[2] === 0 && (t3 = false);
|
|
}
|
|
t3 && (r2[o2] = n3);
|
|
}
|
|
}
|
|
return t2;
|
|
}
|
|
preload() {
|
|
for (const e in this.materialsInfo)
|
|
this.create(e);
|
|
}
|
|
getIndex(e) {
|
|
return this.nameLookup[e];
|
|
}
|
|
getAsArray() {
|
|
let e = 0;
|
|
for (const t2 in this.materialsInfo)
|
|
this.materialsArray[e] = this.create(t2), this.nameLookup[t2] = e, e++;
|
|
return this.materialsArray;
|
|
}
|
|
create(e) {
|
|
return this.materials[e] === undefined && this.createMaterial_(e), this.materials[e];
|
|
}
|
|
createMaterial_(e) {
|
|
const t2 = this, n2 = this.materialsInfo[e], i2 = { name: e, side: this.side };
|
|
function r2(e2, n3) {
|
|
if (i2[e2])
|
|
return;
|
|
const r3 = t2.getTextureParams(n3, i2), o2 = t2.loadTexture((s2 = t2.baseUrl, typeof (a2 = r3.url) != "string" || a2 === "" ? "" : /^https?:\/\//i.test(a2) ? a2 : s2 + a2));
|
|
var s2, a2;
|
|
o2.repeat.copy(r3.scale), o2.offset.copy(r3.offset), o2.wrapS = t2.wrap, o2.wrapT = t2.wrap, e2 !== "map" && e2 !== "emissiveMap" || (o2.colorSpace = Re.SRGBColorSpace), i2[e2] = o2;
|
|
}
|
|
for (const e2 in n2) {
|
|
const t3 = n2[e2];
|
|
let o2;
|
|
if (t3 !== "")
|
|
switch (e2.toLowerCase()) {
|
|
case "kd":
|
|
i2.color = Re.ColorManagement.toWorkingColorSpace(new Re.Color().fromArray(t3), Re.SRGBColorSpace);
|
|
break;
|
|
case "ks":
|
|
i2.specular = Re.ColorManagement.toWorkingColorSpace(new Re.Color().fromArray(t3), Re.SRGBColorSpace);
|
|
break;
|
|
case "ke":
|
|
i2.emissive = Re.ColorManagement.toWorkingColorSpace(new Re.Color().fromArray(t3), Re.SRGBColorSpace);
|
|
break;
|
|
case "map_kd":
|
|
r2("map", t3);
|
|
break;
|
|
case "map_ks":
|
|
r2("specularMap", t3);
|
|
break;
|
|
case "map_ke":
|
|
r2("emissiveMap", t3);
|
|
break;
|
|
case "norm":
|
|
r2("normalMap", t3);
|
|
break;
|
|
case "map_bump":
|
|
case "bump":
|
|
r2("bumpMap", t3);
|
|
break;
|
|
case "map_d":
|
|
r2("alphaMap", t3), i2.transparent = true;
|
|
break;
|
|
case "ns":
|
|
i2.shininess = parseFloat(t3);
|
|
break;
|
|
case "d":
|
|
o2 = parseFloat(t3), o2 < 1 && (i2.opacity = o2, i2.transparent = true);
|
|
break;
|
|
case "tr":
|
|
o2 = parseFloat(t3), this.options && this.options.invertTrProperty && (o2 = 1 - o2), o2 > 0 && (i2.opacity = 1 - o2, i2.transparent = true);
|
|
}
|
|
}
|
|
return this.materials[e] = new Re.MeshPhongMaterial(i2), this.materials[e];
|
|
}
|
|
getTextureParams(e, t2) {
|
|
const n2 = { scale: new Re.Vector2(1, 1), offset: new Re.Vector2(0, 0) }, i2 = e.split(/\s+/);
|
|
let r2;
|
|
return r2 = i2.indexOf("-bm"), r2 >= 0 && (t2.bumpScale = parseFloat(i2[r2 + 1]), i2.splice(r2, 2)), r2 = i2.indexOf("-s"), r2 >= 0 && (n2.scale.set(parseFloat(i2[r2 + 1]), parseFloat(i2[r2 + 2])), i2.splice(r2, 4)), r2 = i2.indexOf("-o"), r2 >= 0 && (n2.offset.set(parseFloat(i2[r2 + 1]), parseFloat(i2[r2 + 2])), i2.splice(r2, 4)), n2.url = i2.join(" ").trim(), n2;
|
|
}
|
|
loadTexture(e, t2, n2, i2, r2) {
|
|
const o2 = this.manager !== undefined ? this.manager : Re.DefaultLoadingManager;
|
|
let s2 = o2.getHandler(e);
|
|
s2 === null && (s2 = new Re.TextureLoader(o2)), s2.setCrossOrigin && s2.setCrossOrigin(this.crossOrigin);
|
|
const a2 = s2.load(e, n2, i2, r2);
|
|
return t2 !== undefined && (a2.mapping = t2), a2;
|
|
}
|
|
}
|
|
|
|
class oi {
|
|
static fromCubeTexture(e) {
|
|
let t2 = 0;
|
|
const n2 = new Re.Vector3, i2 = new Re.Vector3, r2 = new Re.Color, o2 = [0, 0, 0, 0, 0, 0, 0, 0, 0], s2 = new Re.SphericalHarmonics3, a2 = s2.coefficients;
|
|
for (let s3 = 0;s3 < 6; s3++) {
|
|
const A3 = e.image[s3], l2 = A3.width, c2 = A3.height, h2 = document.createElement("canvas");
|
|
h2.width = l2, h2.height = c2;
|
|
const d2 = h2.getContext("2d");
|
|
d2.drawImage(A3, 0, 0, l2, c2);
|
|
const u2 = d2.getImageData(0, 0, l2, c2), g2 = u2.data, p2 = u2.width, f2 = 2 / p2;
|
|
for (let A4 = 0, l3 = g2.length;A4 < l3; A4 += 4) {
|
|
r2.setRGB(g2[A4] / 255, g2[A4 + 1] / 255, g2[A4 + 2] / 255), si(r2, e.colorSpace);
|
|
const l4 = A4 / 4, c3 = (l4 % p2 + 0.5) * f2 - 1, h3 = 1 - (Math.floor(l4 / p2) + 0.5) * f2;
|
|
switch (s3) {
|
|
case 0:
|
|
n2.set(-1, h3, -c3);
|
|
break;
|
|
case 1:
|
|
n2.set(1, h3, c3);
|
|
break;
|
|
case 2:
|
|
n2.set(-c3, 1, -h3);
|
|
break;
|
|
case 3:
|
|
n2.set(-c3, -1, h3);
|
|
break;
|
|
case 4:
|
|
n2.set(-c3, h3, 1);
|
|
break;
|
|
case 5:
|
|
n2.set(c3, h3, -1);
|
|
}
|
|
const d3 = n2.lengthSq(), u3 = 4 / (Math.sqrt(d3) * d3);
|
|
t2 += u3, i2.copy(n2).normalize(), Re.SphericalHarmonics3.getBasisAt(i2, o2);
|
|
for (let e2 = 0;e2 < 9; e2++)
|
|
a2[e2].x += o2[e2] * r2.r * u3, a2[e2].y += o2[e2] * r2.g * u3, a2[e2].z += o2[e2] * r2.b * u3;
|
|
}
|
|
}
|
|
const A2 = 4 * Math.PI / t2;
|
|
for (let e2 = 0;e2 < 9; e2++)
|
|
a2[e2].x *= A2, a2[e2].y *= A2, a2[e2].z *= A2;
|
|
return new Re.LightProbe(s2);
|
|
}
|
|
static async fromCubeRenderTarget(e, t2) {
|
|
const n2 = e.coordinateSystem === Re.WebGLCoordinateSystem ? -1 : 1;
|
|
let i2 = 0;
|
|
const r2 = new Re.Vector3, o2 = new Re.Vector3, s2 = new Re.Color, a2 = [0, 0, 0, 0, 0, 0, 0, 0, 0], A2 = new Re.SphericalHarmonics3, l2 = A2.coefficients, c2 = t2.texture.type, h2 = t2.width;
|
|
let d2;
|
|
e.isWebGLRenderer && (d2 = c2 === Re.HalfFloatType ? new Uint16Array(h2 * h2 * 4) : new Uint8Array(h2 * h2 * 4));
|
|
for (let A3 = 0;A3 < 6; A3++) {
|
|
e.isWebGLRenderer ? await e.readRenderTargetPixelsAsync(t2, 0, 0, h2, h2, d2, A3) : d2 = await e.readRenderTargetPixelsAsync(t2, 0, 0, h2, h2, 0, A3);
|
|
const u3 = 2 / h2;
|
|
for (let e2 = 0, g2 = d2.length;e2 < g2; e2 += 4) {
|
|
let g3, p2, f2;
|
|
c2 === Re.HalfFloatType ? (g3 = Re.DataUtils.fromHalfFloat(d2[e2]), p2 = Re.DataUtils.fromHalfFloat(d2[e2 + 1]), f2 = Re.DataUtils.fromHalfFloat(d2[e2 + 2])) : (g3 = d2[e2] / 255, p2 = d2[e2 + 1] / 255, f2 = d2[e2 + 2] / 255), s2.setRGB(g3, p2, f2), si(s2, t2.texture.colorSpace);
|
|
const m2 = e2 / 4, E2 = (1 - (m2 % h2 + 0.5) * u3) * n2, C2 = 1 - (Math.floor(m2 / h2) + 0.5) * u3;
|
|
switch (A3) {
|
|
case 0:
|
|
r2.set(-1 * n2, C2, E2 * n2);
|
|
break;
|
|
case 1:
|
|
r2.set(1 * n2, C2, -E2 * n2);
|
|
break;
|
|
case 2:
|
|
r2.set(E2, 1, -C2);
|
|
break;
|
|
case 3:
|
|
r2.set(E2, -1, C2);
|
|
break;
|
|
case 4:
|
|
r2.set(E2, C2, 1);
|
|
break;
|
|
case 5:
|
|
r2.set(-E2, C2, -1);
|
|
}
|
|
const v2 = r2.lengthSq(), B2 = 4 / (Math.sqrt(v2) * v2);
|
|
i2 += B2, o2.copy(r2).normalize(), Re.SphericalHarmonics3.getBasisAt(o2, a2);
|
|
for (let e3 = 0;e3 < 9; e3++)
|
|
l2[e3].x += a2[e3] * s2.r * B2, l2[e3].y += a2[e3] * s2.g * B2, l2[e3].z += a2[e3] * s2.b * B2;
|
|
}
|
|
}
|
|
const u2 = 4 * Math.PI / i2;
|
|
for (let e2 = 0;e2 < 9; e2++)
|
|
l2[e2].x *= u2, l2[e2].y *= u2, l2[e2].z *= u2;
|
|
return new Re.LightProbe(A2);
|
|
}
|
|
}
|
|
function si(e, t2) {
|
|
switch (t2) {
|
|
case Re.SRGBColorSpace:
|
|
e.convertSRGBToLinear();
|
|
break;
|
|
case Re.LinearSRGBColorSpace:
|
|
case Re.NoColorSpace:
|
|
break;
|
|
default:
|
|
console.warn("WARNING: LightProbeGenerator convertColorToLinear() encountered an unsupported color space.");
|
|
}
|
|
return e;
|
|
}
|
|
function wi() {
|
|
return vi || Bi;
|
|
}
|
|
function xi() {
|
|
return Bi;
|
|
}
|
|
function Qi() {
|
|
return vi;
|
|
}
|
|
function Di(e) {
|
|
var t2 = e || window.navigator.userAgent;
|
|
return /Nexus (7|9)|xoom|sch-i800|playbook|tablet|kindle/i.test(t2) || ki();
|
|
}
|
|
function ki(e, t2, n2) {
|
|
var i2 = e || window.navigator.userAgent, r2 = t2 || window.navigator.platform, o2 = n2 || window.navigator.maxTouchPoints || 0;
|
|
return (r2 === "iPad" || r2 === "MacIntel") && o2 > 0 && /Macintosh|Intel|iPad|ipad/i.test(i2) && !window.MSStream;
|
|
}
|
|
function Ti() {
|
|
var e = navigator.userAgent.includes("Macintosh"), t2 = navigator.maxTouchPoints === 5;
|
|
return e && t2 && bi;
|
|
}
|
|
function Ri() {
|
|
return /iPad|iPhone|iPod/.test(window.navigator.platform);
|
|
}
|
|
function Fi() {
|
|
return !Si() && !Pi() && window.orientation !== undefined;
|
|
}
|
|
function Ui() {
|
|
return /(OculusBrowser)/i.test(window.navigator.userAgent);
|
|
}
|
|
function Oi() {
|
|
return /(Mobile VR)/i.test(window.navigator.userAgent);
|
|
}
|
|
function Pi() {
|
|
return Ui() || Oi() || Ti();
|
|
}
|
|
function Gi() {
|
|
return /R7 Build/.test(window.navigator.userAgent);
|
|
}
|
|
function Ni() {
|
|
var e = window.orientation;
|
|
return Gi() && (e += 90), e === 90 || e === -90;
|
|
}
|
|
function qi() {
|
|
return {};
|
|
}
|
|
function Vi(e) {
|
|
var t2 = [], n2 = null;
|
|
function i2(i3) {
|
|
var r2, o2;
|
|
if ((i3 = i3 === undefined ? t2.length : i3) > 0 && n2 == null && (n2 = 0), i3 > 0)
|
|
for (r2 = t2.length, t2.length += Number(i3), o2 = r2;o2 < t2.length; o2++)
|
|
t2[o2] = e();
|
|
return t2.length;
|
|
}
|
|
return e = e || qi, { grow: i2, pool: t2, recycle: function(e2) {
|
|
e2 instanceof Object && (n2 !== null && n2 !== -1 ? t2[--n2] = e2 : t2[t2.length] = e2);
|
|
}, size: function() {
|
|
return t2.length;
|
|
}, use: function() {
|
|
var e2;
|
|
return n2 !== null && n2 !== t2.length || i2(t2.length || 5), e2 = t2[n2], t2[n2++] = Hi, zi(e2), e2;
|
|
} };
|
|
}
|
|
function zi(e) {
|
|
var t2;
|
|
if (e && e.constructor === Object)
|
|
for (t2 in e)
|
|
e[t2] = undefined;
|
|
}
|
|
function Yi(e, t2) {
|
|
var n2;
|
|
if (e && e.constructor === Object)
|
|
for (n2 in e)
|
|
n2 in t2 || delete e[n2];
|
|
}
|
|
function Zi(e, t2, n2) {
|
|
var i2, r2, o2, s2, a2, A2, l2, c2, h2 = n2 && typeof n2 == "object" ? n2 : {};
|
|
if (e && e instanceof Object)
|
|
return a2 = e.x === undefined ? t2 && t2.x : e.x, A2 = e.y === undefined ? t2 && t2.y : e.y, l2 = e.z === undefined ? t2 && t2.z : e.z, c2 = e.w === undefined ? t2 && t2.w : e.w, a2 != null && (h2.x = ir(a2)), A2 != null && (h2.y = ir(A2)), l2 != null && (h2.z = ir(l2)), c2 != null && (h2.w = ir(c2)), h2;
|
|
if (e == null)
|
|
return typeof t2 == "object" ? Object.assign(h2, t2) : t2;
|
|
for (i2 = e.trim().split(Xi), s2 = 0;s2 < Wi.length; s2++)
|
|
if (o2 = Wi[s2], i2[s2])
|
|
h2[o2] = parseFloat(i2[s2], 10);
|
|
else {
|
|
if ((r2 = t2 && t2[o2]) === undefined)
|
|
continue;
|
|
h2[o2] = ir(r2);
|
|
}
|
|
return h2;
|
|
}
|
|
function $i(e) {
|
|
var t2;
|
|
return typeof e != "object" ? e : (t2 = e.x + " " + e.y, e.z != null && (t2 += " " + e.z), e.w != null && (t2 += " " + e.w), t2);
|
|
}
|
|
function er(e, t2) {
|
|
return typeof e != "object" || typeof t2 != "object" ? e === t2 : e.x === t2.x && e.y === t2.y && e.z === t2.z && e.w === t2.w;
|
|
}
|
|
function tr(e) {
|
|
return Ji.test(e);
|
|
}
|
|
function nr(e) {
|
|
return Ki("`AFRAME.utils.isCoordinate` has been renamed to `AFRAME.utils.isCoordinates`"), tr(e);
|
|
}
|
|
function ir(e) {
|
|
return e != null && e.constructor === String ? parseFloat(e, 10) : e;
|
|
}
|
|
function rr(e) {
|
|
return new Re.Vector3(e.x, e.y, e.z);
|
|
}
|
|
function sr(e, t2) {
|
|
var n2 = or(e, t2 = t2 || ".");
|
|
return n2.length === 1 ? n2[0] : n2;
|
|
}
|
|
function ar(e, t2, n2) {
|
|
var i2;
|
|
return n2 = n2 || ".", t2.indexOf(n2) !== -1 ? (i2 = sr(t2, n2)).constructor === String ? e.getAttribute(i2) : e.getAttribute(i2[0])[i2[1]] : e.getAttribute(t2);
|
|
}
|
|
function Ar(e, t2, n2, i2) {
|
|
var r2;
|
|
i2 = i2 || ".", t2.indexOf(i2) === -1 ? e.setAttribute(t2, n2) : (r2 = sr(t2, i2)).constructor === String ? e.setAttribute(r2, n2) : e.setAttribute(r2[0], r2[1], n2);
|
|
}
|
|
function lr(e) {
|
|
var t2 = e.style.width, n2 = e.style.height;
|
|
e.style.width = parseInt(t2, 10) + 1 + "px", e.style.height = parseInt(n2, 10) + 1 + "px", setTimeout(function() {
|
|
e.style.width = t2, e.style.height = n2;
|
|
}, 200);
|
|
}
|
|
function hr(e, t2, n2) {
|
|
(function(e2, t3) {
|
|
var n3;
|
|
e2.tagName ? t3(e2.tagName === "IMG") : ((n3 = new XMLHttpRequest).open("HEAD", e2), n3.addEventListener("load", function(i2) {
|
|
var r2;
|
|
n3.status >= 200 && n3.status < 300 ? (r2 = n3.getResponseHeader("Content-Type")) == null ? pr(e2, t3) : r2.startsWith("image") ? t3(true) : t3(false) : pr(e2, t3), n3.abort();
|
|
}), n3.send());
|
|
})(e, function(i2) {
|
|
i2 ? t2(e) : n2(e);
|
|
});
|
|
}
|
|
function dr(e, t2, n2) {
|
|
var i2, r2, o2, s2 = "", a2 = [];
|
|
if (typeof e == "string") {
|
|
let A2 = function(e2) {
|
|
a2.push(e2), a2.length === 6 && t2(a2);
|
|
};
|
|
for (r2 = 0;r2 < 5; r2++)
|
|
s2 += "(url\\((?:[^\\)]+)\\),\\s*)";
|
|
if (s2 += "(url\\((?:[^\\)]+)\\)\\s*)", o2 = e.match(new RegExp(s2))) {
|
|
for (r2 = 1;r2 < 7; r2++)
|
|
hr(gr(o2[r2]), A2);
|
|
return;
|
|
}
|
|
if (!e.startsWith("#"))
|
|
return void hr(gr(e) || e, n2);
|
|
}
|
|
if (i2 = e.tagName ? e : function(e2) {
|
|
try {
|
|
var t3 = document.querySelector(e2);
|
|
return t3 || cr('No element was found matching the selector: "%s"', e2), t3;
|
|
} catch (t4) {
|
|
return void cr('"%s" is not a valid selector', e2);
|
|
}
|
|
}(e))
|
|
return i2.tagName === "A-CUBEMAP" && i2.srcs ? t2(i2.srcs) : i2.tagName === "IMG" ? n2(i2) : void cr('Selector "%s" does not point to <a-cubemap> or <img>', e);
|
|
}
|
|
function ur(e, t2) {
|
|
return dr(e, t2, function() {
|
|
cr("Expected cubemap but got image");
|
|
});
|
|
}
|
|
function gr(e) {
|
|
var t2 = e.match(/url\((.+)\)/);
|
|
if (t2)
|
|
return t2[1];
|
|
}
|
|
function pr(e, t2) {
|
|
var n2 = new Image;
|
|
n2.addEventListener("load", function() {
|
|
t2(true);
|
|
}), n2.addEventListener("error", function() {
|
|
t2(false);
|
|
}), n2.src = e;
|
|
}
|
|
function Er(e, t2) {
|
|
var n2 = t2.offset || { x: 0, y: 0 }, i2 = t2.repeat || { x: 1, y: 1 }, r2 = t2.npot || false, o2 = t2.anisotropy || Re.Texture.DEFAULT_ANISOTROPY, s2 = e.wrapS, a2 = e.wrapT, A2 = e.magFilter, l2 = e.minFilter;
|
|
r2 && (s2 = Re.ClampToEdgeWrapping, a2 = Re.ClampToEdgeWrapping, A2 = Re.LinearFilter, l2 = Re.LinearFilter), i2.x === 1 && i2.y === 1 || (s2 = Re.RepeatWrapping, a2 = Re.RepeatWrapping), e.offset.set(n2.x, n2.y), e.repeat.set(i2.x, i2.y), e.wrapS === s2 && e.wrapT === a2 && e.magFilter === A2 && e.minFilter === l2 && e.anisotropy === o2 || (e.wrapS = s2, e.wrapT = a2, e.magFilter = A2, e.minFilter = l2, e.anisotropy = o2, e.needsUpdate = true);
|
|
}
|
|
function Cr(e, t2, n2, i2) {
|
|
var { el: r2, material: o2 } = n2, s2 = r2.sceneEl.systems.renderer, a2 = i2[t2];
|
|
if (n2.materialSrcs || (n2.materialSrcs = {}), !a2)
|
|
return delete n2.materialSrcs[e], void A2(null);
|
|
function A2(t3) {
|
|
o2[e] !== t3 && (o2[e] && o2[e].dispose(), o2[e] = t3, o2.needsUpdate = true, Ir(r2, t3));
|
|
}
|
|
a2 === n2.materialSrcs[e] && o2[e] ? Er(o2[e], i2) : (n2.materialSrcs[e] = a2, a2 instanceof Re.Texture ? A2(a2) : r2.sceneEl.systems.material.loadTextureSource(a2, function(t3) {
|
|
if (n2.materialSrcs[e] === a2) {
|
|
var r3 = o2[e];
|
|
!r3 || t3 !== null && wr(r3, t3) || (r3 = null), !r3 && t3 && (r3 = xr(t3)), r3 && (r3.source !== t3 && (r3.source = t3, r3.needsUpdate = true), mr.has(e) && s2.applyColorCorrection(r3), Er(r3, i2)), A2(r3);
|
|
}
|
|
}));
|
|
}
|
|
function vr(e, t2) {
|
|
return Cr("map", "src", e, t2);
|
|
}
|
|
function Br(e, t2, n2) {
|
|
var i2 = e;
|
|
e === "ambientOcclusion" && (i2 = "ao");
|
|
var r2 = {};
|
|
return r2.src = n2[e + "Map"], r2.offset = n2[e + "TextureOffset"], r2.repeat = n2[e + "TextureRepeat"], r2.wrap = n2[e + "TextureWrap"], Cr(i2 + "Map", "src", t2, r2);
|
|
}
|
|
function yr(e, t2) {
|
|
var { material: n2, el: i2 } = e, r2 = "envMap", o2 = t2.envMap, s2 = t2.sphericalEnvMap, a2 = t2.refract;
|
|
if (s2 && (o2 = s2, fr("`sphericalEnvMap` property is deprecated, using spherical map as equirectangular map instead. Use `envMap` property with a CubeMap or Equirectangular image instead.")), e.materialSrcs || (e.materialSrcs = {}), !o2)
|
|
return delete e.materialSrcs[r2], n2.envMap = null, void (n2.needsUpdate = true);
|
|
function A2(t3) {
|
|
e.materialSrcs[r2] === o2 && (n2.envMap = t3, n2.needsUpdate = true, Ir(i2, t3));
|
|
}
|
|
e.materialSrcs[r2] = o2, br[o2] ? br[o2].then(A2) : br[o2] = new Promise(function(e2) {
|
|
dr(o2, function(t3) {
|
|
i2.sceneEl.systems.material.loadCubeMapTexture(t3, function(t4) {
|
|
t4.mapping = a2 ? Re.CubeRefractionMapping : Re.CubeReflectionMapping, A2(t4), e2(t4);
|
|
});
|
|
}, function(t3) {
|
|
i2.sceneEl.systems.material.loadTexture(t3, { src: t3 }, function(t4) {
|
|
t4.mapping = a2 ? Re.EquirectangularRefractionMapping : Re.EquirectangularReflectionMapping, A2(t4), e2(t4);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
function Ir(e, t2) {
|
|
function n2() {
|
|
e.emit("materialvideoloadeddata", { src: t2.image, texture: t2 });
|
|
}
|
|
function i2() {
|
|
e.emit("materialvideoended", { src: t2.image, texture: t2 });
|
|
}
|
|
t2 && (e.emit("materialtextureloaded", { src: t2.image, texture: t2 }), t2.image && t2.image.tagName === "VIDEO" && (t2.image.addEventListener("loadeddata", n2), t2.image.addEventListener("ended", i2), t2.addEventListener("dispose", function() {
|
|
t2.image.removeEventListener("loadeddata", n2), t2.image.removeEventListener("ended", i2);
|
|
})));
|
|
}
|
|
function wr(e, t2) {
|
|
return e.source === t2 && (t2.data instanceof HTMLCanvasElement ? e.isCanvasTexture : t2.data instanceof HTMLVideoElement ? e.isVideoTexture : e.isTexture && !e.isCanvasTexture && !e.isVideoTexture);
|
|
}
|
|
function xr(e) {
|
|
var t2;
|
|
return (t2 = e.data instanceof HTMLCanvasElement ? new Re.CanvasTexture : e.data instanceof HTMLVideoElement ? new Re.VideoTexture(e.data) : new Re.Texture).source = e, t2.needsUpdate = true, t2;
|
|
}
|
|
function Lr(e, t2) {
|
|
var n2;
|
|
return typeof e != "string" ? e : (n2 = function(e2, t3) {
|
|
var n3, i2, r2, o2, s2, a2;
|
|
for (t3 = t3 || {}, n3 = Tr(e2), i2 = 0;i2 < n3.length; i2++)
|
|
(r2 = n3[i2]) && (o2 = r2.indexOf(":"), s2 = r2.substr(0, o2).trim(), a2 = r2.substr(o2 + 1).trim(), t3[Sr(s2)] = a2);
|
|
return t3;
|
|
}(e, t2), n2[""] ? e : n2);
|
|
}
|
|
function Mr(e) {
|
|
return typeof e == "string" ? e : function(e2) {
|
|
var t2, n2 = 0, i2 = 0, r2 = "";
|
|
for (t2 in e2)
|
|
n2++;
|
|
for (t2 in e2)
|
|
r2 += t2 + ": " + e2[t2], i2 < n2 - 1 && (r2 += "; "), i2++;
|
|
return r2;
|
|
}(e);
|
|
}
|
|
function Sr(e) {
|
|
return e.replace(Qr, Rr);
|
|
}
|
|
function Rr(e) {
|
|
return e[1].toUpperCase();
|
|
}
|
|
function Ur(e, t2, n2) {
|
|
var i2, r2, o2 = e.el;
|
|
if ((r2 = !!(i2 = Or(e, t2, n2))) === e.controllerPresent)
|
|
return r2;
|
|
e.controllerPresent = r2, r2 ? (e.addEventListeners(), e.injectTrackedControls(i2), o2.emit("controllerconnected", { name: e.name, component: e })) : (e.removeEventListeners(), o2.emit("controllerdisconnected", { name: e.name, component: e }));
|
|
}
|
|
function Or(e, t2, n2) {
|
|
var i2, r2 = e.el.sceneEl, o2 = r2 && r2.systems["tracked-controls"];
|
|
return !!o2 && !(!(i2 = o2.controllers) || !i2.length) && Pr(i2, t2, n2.hand, n2.index, n2.iterateControllerProfiles, n2.handTracking);
|
|
}
|
|
function Pr(e, t2, n2, i2, r2, o2) {
|
|
var s2, a2, A2, l2, c2 = false;
|
|
for (s2 = 0;s2 < e.length; s2++) {
|
|
if (l2 = (A2 = e[s2]).profiles, o2)
|
|
c2 = A2.hand;
|
|
else if (r2)
|
|
for (a2 = 0;a2 < l2.length && !(c2 = l2[a2].startsWith(t2)); a2++)
|
|
;
|
|
else
|
|
c2 = l2.length > 0 && l2[0].startsWith(t2);
|
|
if (c2) {
|
|
if (A2.handedness === "right" || A2.handedness === "left") {
|
|
if (A2.handedness === n2)
|
|
return e[s2];
|
|
} else if (s2 === i2)
|
|
return e[s2];
|
|
}
|
|
}
|
|
}
|
|
function Gr(e, t2, n2) {
|
|
var i2, r2, o2, s2, a2;
|
|
for (r2 in t2) {
|
|
for (i2 = t2[r2], o2 = false, a2 = 0;a2 < i2.length; a2++)
|
|
n2.detail.changed[i2[a2]] && (o2 = true);
|
|
if (o2) {
|
|
for (s2 = {}, a2 = 0;a2 < i2.length; a2++)
|
|
s2[Fr[a2]] = n2.detail.axis[i2[a2]];
|
|
e.el.emit(r2 + "moved", s2);
|
|
}
|
|
}
|
|
}
|
|
function Nr(e, t2, n2, i2) {
|
|
var r2 = (i2 ? n2.mapping[i2] : n2.mapping).buttons[e];
|
|
n2.el.emit(r2 + t2), n2.updateModel && n2.updateModel(r2, t2);
|
|
}
|
|
function _r(e) {
|
|
return e.bind.apply(e, Array.prototype.slice.call(arguments, 1));
|
|
}
|
|
function Hr() {
|
|
return jr("`utils.checkHeadsetConnected` has moved to `utils.device.checkHeadsetConnected`"), wi();
|
|
}
|
|
function qr() {
|
|
return jr("`utils.isIOS` has moved to `utils.device.isIOS`"), Ri();
|
|
}
|
|
function Vr() {
|
|
return jr("`utils.isMobile has moved to `utils.device.isMobile`"), Si(arguments);
|
|
}
|
|
function zr(e, t2, n2) {
|
|
var i2;
|
|
return n2 && (e = e.bind(n2)), function() {
|
|
var n3 = Date.now();
|
|
(i2 === undefined || (i2 === undefined ? t2 : n3 - i2) >= t2) && (i2 = n3, e.apply(null, arguments));
|
|
};
|
|
}
|
|
function Yr(e, t2, n2) {
|
|
var i2, r2, o2;
|
|
n2 && (e = e.bind(n2));
|
|
var s2 = function() {
|
|
i2 = Date.now(), e.apply(this, o2), r2 = undefined;
|
|
};
|
|
return function() {
|
|
var n3 = Date.now(), a2 = i2 === undefined ? t2 : n3 - i2;
|
|
a2 >= t2 ? (clearTimeout(r2), r2 = undefined, i2 = n3, e.apply(null, arguments)) : (r2 = r2 || setTimeout(s2, t2 - a2), o2 = arguments);
|
|
};
|
|
}
|
|
function Kr(e, t2, n2) {
|
|
var i2;
|
|
return n2 && (e = e.bind(n2)), function(n3, r2) {
|
|
var o2 = i2 === undefined ? r2 : n3 - i2;
|
|
(i2 === undefined || o2 >= t2) && (i2 = n3, e(n3, o2));
|
|
};
|
|
}
|
|
function Wr(e, t2, n2) {
|
|
var i2;
|
|
return function() {
|
|
var r2 = this, o2 = arguments, s2 = n2 && !i2;
|
|
clearTimeout(i2), i2 = setTimeout(function() {
|
|
i2 = null, n2 || e.apply(r2, o2);
|
|
}, t2), s2 && e.apply(r2, o2);
|
|
};
|
|
}
|
|
function Zr(e) {
|
|
return JSON.parse(JSON.stringify(e));
|
|
}
|
|
function io(e) {
|
|
return !e.metaKey && document.activeElement === document.body;
|
|
}
|
|
function ro(e, t2) {
|
|
t2 === undefined && (t2 = " ");
|
|
var n2 = new RegExp(t2, "g");
|
|
return (e = (e || "").replace(n2, t2)).split(t2);
|
|
}
|
|
function oo(e, t2) {
|
|
t2 = t2 || {};
|
|
var n2 = {};
|
|
return Object.keys(t2).forEach(function(t3) {
|
|
e.hasAttribute(t3) && (n2[t3] = e.getAttribute(t3));
|
|
}), n2;
|
|
}
|
|
function so(e) {
|
|
e = e.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
|
var t2 = new RegExp("[\\?&]" + e + "=([^&#]*)").exec(location.search);
|
|
return t2 === null ? "" : decodeURIComponent(t2[1].replace(/\+/g, " "));
|
|
}
|
|
function ao() {
|
|
return window.top !== window.self;
|
|
}
|
|
function Ao(e) {
|
|
for (var t2 = [], n2 = e.getElementsByTagName("*"), i2 = 0, r2 = n2.length;i2 < r2; i2++)
|
|
n2[i2].isScene && t2.push(n2[i2]);
|
|
return t2;
|
|
}
|
|
function uo(e) {
|
|
return { tagName: "meta", attributes: e, exists: function() {
|
|
return document.querySelector('meta[name="' + e.name + '"]');
|
|
} };
|
|
}
|
|
function Bo(e) {
|
|
var t2 = go.hasAttribute("embedded"), n2 = fo(go.canvas, t2, go.maxCanvasSize, go.is("vr-mode"));
|
|
e.aspect = n2.width / n2.height, e.updateProjectionMatrix(), go.renderer.setSize(n2.width, n2.height, false);
|
|
}
|
|
function Qo(e, t2, n2, i2, r2, o2) {
|
|
if (e in Io)
|
|
throw new Error("Property type " + e + " is already registered.");
|
|
Io[e] = { default: t2, parse: n2 || Do, stringify: i2 || ko, equals: r2 || To, isCacheable: o2 !== false };
|
|
}
|
|
function Lo(e, t2) {
|
|
if (!Array.isArray(e) || !Array.isArray(t2))
|
|
return e === t2;
|
|
if (e.length !== t2.length)
|
|
return false;
|
|
for (var n2 = 0;n2 < e.length; n2++)
|
|
if (e[n2] !== t2[n2])
|
|
return false;
|
|
return true;
|
|
}
|
|
function Mo(e) {
|
|
var t2, n2;
|
|
return typeof e != "string" ? e : (n2 = e.match(xo)) ? n2[1] : e.charAt(0) === "#" ? (t2 = document.getElementById(e.substring(1))) ? t2.tagName === "CANVAS" || t2.tagName === "VIDEO" || t2.tagName === "IMG" ? t2 : t2.getAttribute("src") : void yo('"' + e + '" asset not found.') : e;
|
|
}
|
|
function So(e) {
|
|
return e.getAttribute ? e.getAttribute("id") ? "#" + e.getAttribute("id") : e.getAttribute("src") : ko(e);
|
|
}
|
|
function Do(e) {
|
|
return e;
|
|
}
|
|
function ko(e) {
|
|
return e === null ? "null" : e.toString();
|
|
}
|
|
function To(e, t2) {
|
|
return e === t2;
|
|
}
|
|
function Ro(e) {
|
|
return parseInt(e, 10);
|
|
}
|
|
function Fo(e, t2, n2) {
|
|
return Zi(e, t2, n2);
|
|
}
|
|
function Uo(e, t2) {
|
|
if (e === null)
|
|
return true;
|
|
if (typeof e != "object")
|
|
return false;
|
|
if (Object.keys(e).length !== t2)
|
|
return false;
|
|
var { x: n2, y: i2, z: r2, w: o2 } = e;
|
|
return !(typeof n2 != "number" || typeof i2 != "number" || t2 > 2 && typeof r2 != "number" || t2 > 3 && typeof o2 != "number");
|
|
}
|
|
function No(e) {
|
|
return "type" in e ? typeof e.type == "string" : ("default" in e);
|
|
}
|
|
function jo(e, t2) {
|
|
var n2;
|
|
if (No(e))
|
|
return _o(e, t2);
|
|
for (n2 in e)
|
|
e[n2] = _o(e[n2], t2);
|
|
return e;
|
|
}
|
|
function _o(e, t2) {
|
|
var n2, i2, r2 = e.default, o2 = e.type;
|
|
return e.type ? e.type === "bool" ? o2 = "boolean" : e.type === "float" && (o2 = "number") : o2 = r2 === undefined || typeof r2 != "boolean" && typeof r2 != "number" ? Array.isArray(r2) ? "array" : "string" : typeof r2, (i2 = Po[o2]) || Go("Unknown property type for component `" + t2 + "`: " + o2), n2 = !!e.parse, e.parse = e.parse || i2.parse, e.stringify = e.stringify || i2.stringify, e.equals = e.equals || i2.equals, e.isCacheable = e.isCacheable === true || i2.isCacheable, e.type = o2, "default" in e ? n2 || Oo(o2, r2) || Go("Default value `" + r2 + "` does not match type `" + o2 + "` in component `" + t2 + "`") : e.default = i2.default, e;
|
|
}
|
|
function Vo(e, t2, n2) {
|
|
return e != null && e !== "" || (e = t2.default, Array.isArray(e) && (e = e.slice())), t2.parse(e, t2.default, n2);
|
|
}
|
|
function zo(e, t2) {
|
|
var n2, i2, r2, o2, s2 = {};
|
|
for (n2 in e)
|
|
i2 = t2[n2], typeof (o2 = r2 = e[n2]) == "object" && (o2 = Yo(r2, i2), i2 || Go("Unknown component property: " + n2)), o2 !== undefined && (s2[n2] = o2);
|
|
return s2;
|
|
}
|
|
function Yo(e, t2) {
|
|
return typeof e != "object" ? e : t2 && e !== null ? t2.stringify(e) : JSON.stringify(e);
|
|
}
|
|
function cs(e, t2) {
|
|
var n2, i2, r2, o2, s2, a2 = {};
|
|
if (document.currentScript && document.currentScript !== ns && bo.forEach(function(t3) {
|
|
t3.hasLoaded || document.currentScript.compareDocumentPosition(t3) !== Node.DOCUMENT_POSITION_FOLLOWING && (ts("The component `" + e + "` was registered in a <script> tag after the scene. Component <script> tags in an HTML file should be declared *before* the scene such that the component is available to entities during scene initialization."), window.debug && (ls[e] = true));
|
|
}), is.test(e) === true && ts("The component name `" + e + "` contains uppercase characters, but HTML will ignore the capitalization of attribute names. Change the name to be lowercase: `" + e.toLowerCase() + "`"), e.indexOf("__") !== -1)
|
|
throw new Error("The component name `" + e + "` is not allowed. The sequence __ (double underscore) is reserved to specify an id for multiple components of the same type");
|
|
if (Object.keys(t2).forEach(function(e2) {
|
|
a2[e2] = { value: t2[e2], writable: true };
|
|
}), Ko[e])
|
|
throw new Error("The component `" + e + "` has been already registered. Check that you are not loading two versions of the same component or two different components of the same name.");
|
|
((n2 = function(e2, t3, n3) {
|
|
As.call(this, e2, t3, n3);
|
|
}).prototype = Object.create(As.prototype, a2)).name = e, n2.prototype.isPositionRotationScale = e === "position" || e === "rotation" || e === "scale", n2.prototype.constructor = n2, n2.prototype.system = m && fs[e], n2.prototype.play = (o2 = n2.prototype.play, function() {
|
|
var e2 = this.el.sceneEl, t3 = this.el.isPlaying && !this.isPlaying;
|
|
this.initialized && t3 && (o2.call(this), this.isPlaying = true, this.eventsAttach(), hs(this) && e2.addBehavior(this));
|
|
}), n2.prototype.pause = (s2 = n2.prototype.pause, function() {
|
|
var e2 = this.el.sceneEl;
|
|
this.isPlaying && (s2.call(this), this.isPlaying = false, this.eventsDetach(), hs(this) && e2.removeBehavior(this));
|
|
}), i2 = Jr(Jo(n2.prototype.schema, n2.prototype.name)), n2.prototype.isSingleProperty = r2 = Xo(n2.prototype.schema), n2.prototype.isObjectBased = !r2 || r2 && (ds(i2.default) || ds(Wo(undefined, i2))), rs[e] = Vi(), Ko[e] = { Component: n2, dependencies: n2.prototype.dependencies, before: n2.prototype.before, after: n2.prototype.after, isSingleProperty: n2.prototype.isSingleProperty, isObjectBased: n2.prototype.isObjectBased, multiple: n2.prototype.multiple, sceneOnly: n2.prototype.sceneOnly, name: e, schema: i2, stringify: n2.prototype.stringify };
|
|
for (var A2 = 0;A2 < bo.length; A2++)
|
|
bo[A2].emit("componentregistered", { name: e }, false);
|
|
return n2;
|
|
}
|
|
function hs(e) {
|
|
return e.tick || e.tock;
|
|
}
|
|
function ds(e) {
|
|
return e && e.constructor === Object && !(e instanceof window.HTMLElement);
|
|
}
|
|
function gs() {
|
|
us || (us = true, setTimeout(function() {
|
|
document.dispatchEvent(new CustomEvent("aframeready"));
|
|
}));
|
|
}
|
|
function Es(e, t2) {
|
|
var n2, i2, r2 = {}, o2 = Ao(document);
|
|
if (Object.keys(t2).forEach(function(e2) {
|
|
r2[e2] = { value: t2[e2], writable: true };
|
|
}), fs[e])
|
|
throw new Error("The system `" + e + "` has been already registered. Check that you are not loading two versions of the same system or two different systems of the same name.");
|
|
if (i2 = function(e2) {
|
|
ms.call(this, e2);
|
|
}, (i2.prototype = Object.create(ms.prototype, r2)).name = e, i2.prototype.constructor = i2, i2.prototype.schema = Jr(jo(i2.prototype.schema)), fs[e] = i2, us)
|
|
for (n2 = 0;n2 < o2.length; n2++)
|
|
o2[n2].initSystem(e);
|
|
}
|
|
function Bs(e) {
|
|
return e.tagName.toLowerCase() in vs || e.isANode;
|
|
}
|
|
function Ms(e, t2) {
|
|
return !(!e.components[t2] || !e.components[t2].attrValue) || function(e2, t3) {
|
|
var n2, i2 = false;
|
|
for (n2 = 0;n2 < t3.length && !(i2 = t3[n2].hasAttribute(e2)); ++n2)
|
|
;
|
|
return i2;
|
|
}(t2, e.mixinEls);
|
|
}
|
|
function Ss(e) {
|
|
return e.indexOf(ws) !== -1 && (e = or(e, ws)[0]), !!Ko[e];
|
|
}
|
|
function Ds(e) {
|
|
if (e.data && e.data.type === "vr")
|
|
switch (e.data.data) {
|
|
case "enter":
|
|
this.enterVR();
|
|
break;
|
|
case "exit":
|
|
this.exitVR();
|
|
}
|
|
}
|
|
function Os(e, t2) {
|
|
var n2, i2, r2 = {}, o2 = t2 || [];
|
|
for (i2 in o2.length = 0, e) {
|
|
var s2 = e[i2];
|
|
if (s2 !== undefined) {
|
|
var a2 = s2.before ? s2.before.slice(0) : [], A2 = s2.after ? s2.after.slice(0) : [];
|
|
r2[i2] = { before: a2, after: A2, visited: false, done: false };
|
|
}
|
|
}
|
|
for (i2 in r2)
|
|
for (n2 = 0;n2 < r2[i2].before.length; n2++) {
|
|
var l2 = r2[i2].before[n2];
|
|
l2 in r2 ? r2[l2].after.push(i2) : ks("Invalid ordering constraint, no component named `" + l2 + "` referenced by `" + i2 + "`");
|
|
}
|
|
function c2(e2) {
|
|
if (e2 in r2 && !r2[e2].done)
|
|
if (r2[e2].visited)
|
|
ks("Cycle detected, ignoring one or more before/after constraints. The resulting order might be incorrect");
|
|
else {
|
|
r2[e2].visited = true;
|
|
for (var t3 = 0;t3 < r2[e2].after.length; t3++) {
|
|
var n3 = r2[e2].after[t3];
|
|
n3 in r2 || ks("Invalid before/after constraint, no component named `" + n3 + "` referenced in `" + e2 + "`"), c2(n3);
|
|
}
|
|
r2[e2].done = true, o2.push(e2);
|
|
}
|
|
}
|
|
for (i2 in r2)
|
|
r2[i2].done || c2(i2);
|
|
return o2;
|
|
}
|
|
function Ps(e, t2) {
|
|
var n2, i2 = window.devicePixelRatio;
|
|
return !t2 || t2.width === -1 && t2.height === -1 || e.width * i2 < t2.width && e.height * i2 < t2.height || (n2 = e.width / e.height, e.width * i2 > t2.width && t2.width !== -1 && (e.width = Math.round(t2.width / i2), e.height = Math.round(t2.width / n2 / i2)), e.height * i2 > t2.height && t2.height !== -1 && (e.height = Math.round(t2.height / i2), e.width = Math.round(t2.height * n2 / i2))), e;
|
|
}
|
|
function Gs(e, t2, n2, i2) {
|
|
return e.parentElement ? t2 ? Ps({ height: e.parentElement.offsetHeight, width: e.parentElement.offsetWidth }, n2) : function(e2, t3) {
|
|
var n3;
|
|
return n3 = { height: document.body.offsetHeight, width: document.body.offsetWidth }, t3 ? n3 : Ps(n3, e2);
|
|
}(n2, i2) : { height: 0, width: 0 };
|
|
}
|
|
function qs(e, t2) {
|
|
var n2, i2 = {};
|
|
if (Object.keys(t2).forEach(function(e2) {
|
|
i2[e2] = { value: t2[e2], writable: true };
|
|
}), js[e])
|
|
throw new Error("The geometry `" + e + "` has been already registered");
|
|
return ((n2 = function() {
|
|
Hs.call(this);
|
|
}).prototype = Object.create(Hs.prototype, i2)).name = e, n2.prototype.constructor = n2, js[e] = { Geometry: n2, schema: Ns(n2.prototype.schema) }, _s.push(e), n2;
|
|
}
|
|
function Xs(e, t2) {
|
|
if (e = e.toLowerCase(), !vs[e]) {
|
|
vs[e] = true, Ys("Registering <%s>", e), t2.defaultAttributes && Ks("The 'defaultAttributes' object is deprecated. Use 'defaultComponents' instead.");
|
|
var n2 = t2.mappings || {}, i2 = class extends Ls {
|
|
constructor() {
|
|
super(), this.defaultComponentsFromPrimitive = t2.defaultComponents || t2.defaultAttributes || {}, this.deprecated = t2.deprecated || null, this.deprecatedMappings = t2.deprecatedMappings || {}, this.mappings = n2, t2.deprecated && console.warn(t2.deprecated), this.resolveMappingCollisions();
|
|
}
|
|
resolveMappingCollisions() {
|
|
var e2 = this.mappings, t3 = this;
|
|
Object.keys(e2).forEach(function(n3) {
|
|
var i3;
|
|
n3 !== n3.toLowerCase() && Ks("Mapping keys should be specified in lower case. The mapping key " + n3 + " may not be recognized"), Ko[n3] && (i3 = e2[n3].replace(".", "-"), e2[i3] = e2[n3], delete e2[n3], console.warn("The primitive " + t3.tagName.toLowerCase() + " has a mapping collision. The attribute " + n3 + " has the same name as a registered component and has been renamed to " + i3));
|
|
});
|
|
}
|
|
getExtraComponents() {
|
|
var e2, t3, n3, i3, r2, o2 = this;
|
|
for (t3 = Zr(this.defaultComponentsFromPrimitive), (r2 = this.getAttribute("mixin")) && (r2 = or(r2.trim(), /\s+/)).forEach(function(e3) {
|
|
var n4, r3, l2 = document.getElementById(e3);
|
|
if (l2) {
|
|
var { rawAttributeCache: c2, componentCache: h2 } = l2;
|
|
for (var d2 in c2) {
|
|
if (i3 = o2.mappings[d2])
|
|
return void Zs(i3, c2[d2], t3);
|
|
d2 in h2 && (t3[d2] = (n4 = t3[d2], r3 = h2[d2], s2(n4) ? a2(r3) : s2(r3) ? a2(n4) : A2(n4) && A2(r3) ? Xr(n4, r3) : a2(r3)));
|
|
}
|
|
}
|
|
}), n3 = 0;n3 < this.attributes.length; n3++)
|
|
e2 = this.attributes[n3], (i3 = this.mappings[e2.name]) && Zs(i3, e2.value, t3);
|
|
return t3;
|
|
function s2(e3) {
|
|
return e3 === undefined;
|
|
}
|
|
function a2(e3) {
|
|
return A2(e3) ? Xr({}, e3) : e3;
|
|
}
|
|
function A2(e3) {
|
|
return e3 !== null && e3.constructor === Object;
|
|
}
|
|
}
|
|
attributeChangedCallback(e2, t3, n3) {
|
|
var i3 = this.mappings[e2];
|
|
e2 in this.deprecatedMappings && console.warn(this.deprecatedMappings[e2]), e2 && i3 ? zs(this, i3, n3) : super.attributeChangedCallback(e2, t3, n3);
|
|
}
|
|
};
|
|
return customElements.define(e, i2), i2.mappings = n2, Js[e] = i2, i2;
|
|
}
|
|
Ws("Trying to register primitive " + e + " that has been already previously registered");
|
|
}
|
|
function Zs(e, t2, n2) {
|
|
var i2 = sr(e);
|
|
i2.constructor === Array ? (n2[i2[0]] = n2[i2[0]] || {}, n2[i2[0]][i2[1]] = t2.trim()) : n2[i2] = t2.trim();
|
|
}
|
|
function ia(e, t2) {
|
|
var n2, i2 = {};
|
|
if (Object.keys(t2).forEach(function(e2) {
|
|
i2[e2] = { value: t2[e2], writable: true };
|
|
}), $s[e])
|
|
throw new Error("The shader " + e + " has already been registered");
|
|
return ((n2 = function() {
|
|
na.call(this);
|
|
}).prototype = Object.create(na.prototype, i2)).name = e, n2.prototype.constructor = n2, $s[e] = { Shader: n2, schema: jo(n2.prototype.schema) }, ea.push(e), n2;
|
|
}
|
|
function sa(e) {
|
|
if (e.hasAttribute("autoplay") || e.getAttribute("preload") === "auto")
|
|
return new Promise(function(t2, n2) {
|
|
if (e.readyState === 4)
|
|
return t2();
|
|
if (e.error)
|
|
return n2();
|
|
function i2() {
|
|
for (var n3 = 0, i3 = 0;i3 < e.buffered.length; i3++)
|
|
n3 += e.buffered.end(i3) - e.buffered.start(i3);
|
|
n3 >= e.duration && (e.tagName === "VIDEO" && Re.Cache.add(e.getAttribute("src"), e), t2());
|
|
}
|
|
e.addEventListener("loadeddata", i2, false), e.addEventListener("progress", i2, false), e.addEventListener("error", n2, false);
|
|
});
|
|
}
|
|
function aa(e) {
|
|
var t2 = function(e2) {
|
|
var t3, n2, i2;
|
|
if (e2.hasAttribute("crossorigin"))
|
|
return e2;
|
|
if ((t3 = e2.getAttribute("src")) !== null) {
|
|
if (t3.indexOf("://") === -1)
|
|
return e2;
|
|
if ((i2 = (n2 = t3).indexOf("://") > -1 ? n2.split("/")[2] : n2.split("/")[0]).substring(0, i2.indexOf(":")) === window.location.host)
|
|
return e2;
|
|
}
|
|
return oa('Cross-origin element (e.g., <img>) was requested without `crossorigin` set. A-Frame will re-request the asset with `crossorigin` attribute set. Please set `crossorigin` on the element (e.g., <img crossorigin="anonymous">)', t3), e2.crossOrigin = "anonymous", e2.cloneNode(true);
|
|
}(e);
|
|
return t2.tagName && t2.tagName.toLowerCase() === "video" && (t2.setAttribute("playsinline", ""), t2.setAttribute("webkit-playsinline", "")), t2 !== e && (e.parentNode.appendChild(t2), e.parentNode.removeChild(e)), t2;
|
|
}
|
|
function Ca(e) {
|
|
e.x = Re.MathUtils.degToRad(e.x), e.y = Re.MathUtils.degToRad(e.y), e.z = Re.MathUtils.degToRad(e.z);
|
|
}
|
|
function va(e, t2, n2) {
|
|
var i2;
|
|
for (i2 = 0;i2 < t2.length; i2++)
|
|
e.addEventListener(t2[i2], n2);
|
|
}
|
|
function Ba(e, t2, n2) {
|
|
var i2;
|
|
for (i2 = 0;i2 < t2.length; i2++)
|
|
e.removeEventListener(t2[i2], n2);
|
|
}
|
|
function ba(e, t2) {
|
|
var n2, i2, r2;
|
|
for (i2 = Ia(t2), r2 = e, n2 = 0;n2 < i2.length; n2++)
|
|
r2 = r2[i2[n2]];
|
|
if (r2 === undefined)
|
|
throw console.log(e), new Error("[animation] property (" + t2 + ") could not be found");
|
|
return r2;
|
|
}
|
|
function ya(e, t2, n2, i2) {
|
|
var r2, o2, s2, a2;
|
|
for (t2.startsWith("object3D.rotation") && (n2 = Re.MathUtils.degToRad(n2)), o2 = Ia(t2), a2 = e, r2 = 0;r2 < o2.length - 1; r2++)
|
|
a2 = a2[o2[r2]];
|
|
s2 = o2[o2.length - 1], i2 !== fa ? a2[s2] = n2 : ("r" in a2[s2]) ? (a2[s2].r = n2.r, a2[s2].g = n2.g, a2[s2].b = n2.b) : (a2[s2].x = n2.r, a2[s2].y = n2.g, a2[s2].z = n2.b);
|
|
}
|
|
function Ia(e) {
|
|
return e in pa || (pa[e] = e.split(".")), pa[e];
|
|
}
|
|
function wa(e) {
|
|
return e.isRawProperty || e.property.startsWith(Ea) || e.property.startsWith("object3D");
|
|
}
|
|
function Xa(e, t2) {
|
|
var n2;
|
|
if (e)
|
|
return (n2 = Ja[e]) === "grip" ? n2 + (t2 ? "close" : "open") : n2 === "point" ? n2 + (t2 ? "up" : "down") : n2 === "pointing" || n2 === "pistol" ? n2 + (t2 ? "start" : "end") : undefined;
|
|
}
|
|
function iA(e, t2, n2) {
|
|
return (t2.dot(e) - t2.dot(n2)) / t2.length();
|
|
}
|
|
function EA(e, t2) {
|
|
return !(!e || !t2) && e.x === t2.x && e.y === t2.y && e.z === t2.z;
|
|
}
|
|
function wA(e, t2) {
|
|
e.dispose(), t2.unregisterMaterial(e), Object.keys(e).filter(function(t3) {
|
|
return e[t3] && e[t3].isTexture;
|
|
}).forEach(function(t3) {
|
|
e[t3].dispose();
|
|
});
|
|
}
|
|
function PA(e) {
|
|
e.traverse(function(t2) {
|
|
var n2;
|
|
t2.type === "Mesh" && (n2 = t2.material.clone(), e.originalColor = t2.material.color, t2.material.dispose(), t2.material = n2);
|
|
});
|
|
}
|
|
function WA(e, t2) {
|
|
var n2;
|
|
for (e.length = t2.length, n2 = 0;n2 < t2.length; n2++)
|
|
e[n2] = t2[n2];
|
|
}
|
|
function fl(e, t2, n2) {
|
|
return e || (0.5 + t2) * n2;
|
|
}
|
|
function _l(e, t2) {
|
|
this.renderer = e, this.xrHitTestSource = null, e.xr.addEventListener("sessionend", function() {
|
|
this.xrHitTestSource = null;
|
|
}.bind(this)), e.xr.addEventListener("sessionstart", function() {
|
|
this.sessionStart(t2);
|
|
}.bind(this)), this.renderer.xr.isPresenting && this.sessionStart(t2);
|
|
}
|
|
function Hl(e) {
|
|
console.warn(e.message), console.warn('Cannot requestHitTestSource Are you missing: webxr="optionalFeatures: hit-test;" from <a-scene>?');
|
|
}
|
|
function zl(e, t2) {
|
|
var n2, i2, r2, o2;
|
|
return (n2 = document.createElement("div")).classList.add("a-modal"), n2.setAttribute(hi, ""), (i2 = document.createElement("div")).className = "a-dialog", i2.setAttribute(hi, ""), n2.appendChild(i2), (r2 = document.createElement("div")).classList.add("a-dialog-text-container"), i2.appendChild(r2), (o2 = document.createElement("div")).classList.add("a-dialog-text"), o2.innerHTML = e, r2.appendChild(o2), i2.appendChild(t2), n2;
|
|
}
|
|
function ic(e) {
|
|
e.addEventListener("touchstart", function() {
|
|
e.classList.remove("resethover");
|
|
}, { passive: true }), e.addEventListener("touchend", function() {
|
|
e.classList.add("resethover");
|
|
}, { passive: true });
|
|
}
|
|
function pc(e, t2) {
|
|
return t2.color.set(e.color), t2.fog = e.fog, t2.wireframe = e.wireframe, t2.toneMapped = e.toneMapped, t2.wireframeLinewidth = e.wireframeLinewidth, t2;
|
|
}
|
|
function fc(e, t2) {
|
|
return t2.color.set(e.color), t2.emissive.set(e.emissive), t2.emissiveIntensity = e.emissiveIntensity, t2.fog = e.fog, t2.metalness = e.metalness, t2.roughness = e.roughness, t2.wireframe = e.wireframe, t2.wireframeLinewidth = e.wireframeLinewidth, e.normalMap && (t2.normalScale = e.normalScale), e.ambientOcclusionMap && (t2.aoMapIntensity = e.ambientOcclusionMapIntensity), e.displacementMap && (t2.displacementScale = e.displacementScale, t2.displacementBias = e.displacementBias), t2;
|
|
}
|
|
function mc(e, t2) {
|
|
switch (t2.color.set(e.color), t2.specular.set(e.specular), t2.emissive.set(e.emissive), t2.emissiveIntensity = e.emissiveIntensity, t2.fog = e.fog, t2.transparent = e.transparent, t2.wireframe = e.wireframe, t2.wireframeLinewidth = e.wireframeLinewidth, t2.shininess = e.shininess, t2.flatShading = e.flatShading, t2.wireframe = e.wireframe, t2.wireframeLinewidth = e.wireframeLinewidth, t2.reflectivity = e.reflectivity, t2.refractionRatio = e.refractionRatio, e.combine) {
|
|
case "mix":
|
|
t2.combine = Re.MixOperation;
|
|
break;
|
|
case "multiply":
|
|
t2.combine = Re.MultiplyOperation;
|
|
break;
|
|
case "add":
|
|
t2.combine = Re.AddOperation;
|
|
}
|
|
return e.normalMap && (t2.normalScale = e.normalScale), e.ambientOcclusionMap && (t2.aoMapIntensity = e.ambientOcclusionMapIntensity), e.bumpMap && (t2.bumpScale = e.bumpMapScale), e.displacementMap && (t2.displacementScale = e.displacementScale, t2.displacementBias = e.displacementBias), t2;
|
|
}
|
|
function Cc(e) {
|
|
var t2 = e.primitive, n2 = js[t2] && js[t2].Geometry, i2 = new n2;
|
|
if (!n2)
|
|
throw new Error("Unknown geometry `" + t2 + "`");
|
|
return i2.init(e), i2.geometry;
|
|
}
|
|
function xc(e, t2) {
|
|
return e.groupOrder !== t2.groupOrder ? e.groupOrder - t2.groupOrder : e.renderOrder !== t2.renderOrder ? e.renderOrder - t2.renderOrder : e.z - t2.z;
|
|
}
|
|
function Qc(e, t2) {
|
|
return e.groupOrder !== t2.groupOrder ? e.groupOrder - t2.groupOrder : e.renderOrder - t2.renderOrder;
|
|
}
|
|
function Lc(e, t2) {
|
|
return e.groupOrder !== t2.groupOrder ? e.groupOrder - t2.groupOrder : e.renderOrder !== t2.renderOrder ? e.renderOrder - t2.renderOrder : t2.z - e.z;
|
|
}
|
|
function kc(e) {
|
|
var t2 = e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
e === "fog" && (t2 = "material-fog"), e === "visible" && (t2 = "material-visible"), Dc[t2] = "material." + e;
|
|
}
|
|
function Tc() {
|
|
return { defaultComponents: { material: {} }, mappings: Jr({}, Dc) };
|
|
}
|
|
function Pc(e) {
|
|
return e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
}
|
|
var t, n, r, o, s, a, A, l, c, h, d, u, g, p, f, m, E, C, v, B, w, x, Q, L, M, R, F, P, z, Y, K, W, J, X, re, ae, le, fe, ve, be, xe, Qe = 0, Le, Me, Se, Te, Re, Fe, Ue, Xe, $e, Et = "glTF", yt, It, wt, xt, Qt, Lt, Mt, St, Dt, kt, Tt, jt, Vt = 9, zt = 15, Yt = 16, Kt = 22, Wt = 37, Jt = 43, Xt = 76, Zt = 83, $t = 97, en = 100, tn = 103, nn = 109, rn = 165, on = 166, sn = 1000066000, ln, hn, dn, un, gn, pn, mn = "AGFzbQEAAAABpQEVYAF/AX9gAn9/AGADf39/AX9gBX9/f39/AX9gAX8AYAJ/fwF/YAR/f39/AX9gA39/fwBgBn9/f39/fwF/YAd/f39/f39/AX9gAn9/AX5gAn5+AX5gAABgBX9/f39/AGAGf39/f39/AGAIf39/f39/f38AYAl/f39/f39/f38AYAABf2AIf39/f39/f38Bf2ANf39/f39/f39/f39/fwF/YAF/AX4CJwEDZW52H2Vtc2NyaXB0ZW5fbm90aWZ5X21lbW9yeV9ncm93dGgABANpaAEFAAAFAgEFCwACAQABAgIFBQcAAwABDgsBAQcAEhMHAAUBDAQEAAANBwQCAgYCBAgDAwMDBgEACQkHBgICAAYGAgQUBwYGAwIGAAMCAQgBBwUGCgoEEQAEBAEIAwgDBQgDEA8IAAcABAUBcAECAgUEAQCAAgYJAX8BQaCgwAILB2AHBm1lbW9yeQIABm1hbGxvYwAoBGZyZWUAJgxaU1REX2lzRXJyb3IAaBlaU1REX2ZpbmREZWNvbXByZXNzZWRTaXplAFQPWlNURF9kZWNvbXByZXNzAEoGX3N0YXJ0ACQJBwEAQQELASQKussBaA8AIAAgACgCBCABajYCBAsZACAAKAIAIAAoAgRBH3F0QQAgAWtBH3F2CwgAIABBiH9LC34BBH9BAyEBIAAoAgQiA0EgTQRAIAAoAggiASAAKAIQTwRAIAAQDQ8LIAAoAgwiAiABRgRAQQFBAiADQSBJGw8LIAAgASABIAJrIANBA3YiBCABIARrIAJJIgEbIgJrIgQ2AgggACADIAJBA3RrNgIEIAAgBCgAADYCAAsgAQsUAQF/IAAgARACIQIgACABEAEgAgv3AQECfyACRQRAIABCADcCACAAQQA2AhAgAEIANwIIQbh/DwsgACABNgIMIAAgAUEEajYCECACQQRPBEAgACABIAJqIgFBfGoiAzYCCCAAIAMoAAA2AgAgAUF/ai0AACIBBEAgAEEIIAEQFGs2AgQgAg8LIABBADYCBEF/DwsgACABNgIIIAAgAS0AACIDNgIAIAJBfmoiBEEBTQRAIARBAWtFBEAgACABLQACQRB0IANyIgM2AgALIAAgAS0AAUEIdCADajYCAAsgASACakF/ai0AACIBRQRAIABBADYCBEFsDwsgAEEoIAEQFCACQQN0ams2AgQgAgsWACAAIAEpAAA3AAAgACABKQAINwAICy8BAX8gAUECdEGgHWooAgAgACgCAEEgIAEgACgCBGprQR9xdnEhAiAAIAEQASACCyEAIAFCz9bTvtLHq9lCfiAAfEIfiUKHla+vmLbem55/fgsdAQF/IAAoAgggACgCDEYEfyAAKAIEQSBGBUEACwuCBAEDfyACQYDAAE8EQCAAIAEgAhBnIAAPCyAAIAJqIQMCQCAAIAFzQQNxRQRAAkAgAkEBSARAIAAhAgwBCyAAQQNxRQRAIAAhAgwBCyAAIQIDQCACIAEtAAA6AAAgAUEBaiEBIAJBAWoiAiADTw0BIAJBA3ENAAsLAkAgA0F8cSIEQcAASQ0AIAIgBEFAaiIFSw0AA0AgAiABKAIANgIAIAIgASgCBDYCBCACIAEoAgg2AgggAiABKAIMNgIMIAIgASgCEDYCECACIAEoAhQ2AhQgAiABKAIYNgIYIAIgASgCHDYCHCACIAEoAiA2AiAgAiABKAIkNgIkIAIgASgCKDYCKCACIAEoAiw2AiwgAiABKAIwNgIwIAIgASgCNDYCNCACIAEoAjg2AjggAiABKAI8NgI8IAFBQGshASACQUBrIgIgBU0NAAsLIAIgBE8NAQNAIAIgASgCADYCACABQQRqIQEgAkEEaiICIARJDQALDAELIANBBEkEQCAAIQIMAQsgA0F8aiIEIABJBEAgACECDAELIAAhAgNAIAIgAS0AADoAACACIAEtAAE6AAEgAiABLQACOgACIAIgAS0AAzoAAyABQQRqIQEgAkEEaiICIARNDQALCyACIANJBEADQCACIAEtAAA6AAAgAUEBaiEBIAJBAWoiAiADRw0ACwsgAAsMACAAIAEpAAA3AAALQQECfyAAKAIIIgEgACgCEEkEQEEDDwsgACAAKAIEIgJBB3E2AgQgACABIAJBA3ZrIgE2AgggACABKAAANgIAQQALDAAgACABKAIANgAAC/cCAQJ/AkAgACABRg0AAkAgASACaiAASwRAIAAgAmoiBCABSw0BCyAAIAEgAhALDwsgACABc0EDcSEDAkACQCAAIAFJBEAgAwRAIAAhAwwDCyAAQQNxRQRAIAAhAwwCCyAAIQMDQCACRQ0EIAMgAS0AADoAACABQQFqIQEgAkF/aiECIANBAWoiA0EDcQ0ACwwBCwJAIAMNACAEQQNxBEADQCACRQ0FIAAgAkF/aiICaiIDIAEgAmotAAA6AAAgA0EDcQ0ACwsgAkEDTQ0AA0AgACACQXxqIgJqIAEgAmooAgA2AgAgAkEDSw0ACwsgAkUNAgNAIAAgAkF/aiICaiABIAJqLQAAOgAAIAINAAsMAgsgAkEDTQ0AIAIhBANAIAMgASgCADYCACABQQRqIQEgA0EEaiEDIARBfGoiBEEDSw0ACyACQQNxIQILIAJFDQADQCADIAEtAAA6AAAgA0EBaiEDIAFBAWohASACQX9qIgINAAsLIAAL8wICAn8BfgJAIAJFDQAgACACaiIDQX9qIAE6AAAgACABOgAAIAJBA0kNACADQX5qIAE6AAAgACABOgABIANBfWogAToAACAAIAE6AAIgAkEHSQ0AIANBfGogAToAACAAIAE6AAMgAkEJSQ0AIABBACAAa0EDcSIEaiIDIAFB/wFxQYGChAhsIgE2AgAgAyACIARrQXxxIgRqIgJBfGogATYCACAEQQlJDQAgAyABNgIIIAMgATYCBCACQXhqIAE2AgAgAkF0aiABNgIAIARBGUkNACADIAE2AhggAyABNgIUIAMgATYCECADIAE2AgwgAkFwaiABNgIAIAJBbGogATYCACACQWhqIAE2AgAgAkFkaiABNgIAIAQgA0EEcUEYciIEayICQSBJDQAgAa0iBUIghiAFhCEFIAMgBGohAQNAIAEgBTcDGCABIAU3AxAgASAFNwMIIAEgBTcDACABQSBqIQEgAkFgaiICQR9LDQALCyAACy8BAn8gACgCBCAAKAIAQQJ0aiICLQACIQMgACACLwEAIAEgAi0AAxAIajYCACADCy8BAn8gACgCBCAAKAIAQQJ0aiICLQACIQMgACACLwEAIAEgAi0AAxAFajYCACADCx8AIAAgASACKAIEEAg2AgAgARAEGiAAIAJBCGo2AgQLCAAgAGdBH3MLugUBDX8jAEEQayIKJAACfyAEQQNNBEAgCkEANgIMIApBDGogAyAEEAsaIAAgASACIApBDGpBBBAVIgBBbCAAEAMbIAAgACAESxsMAQsgAEEAIAEoAgBBAXRBAmoQECENQVQgAygAACIGQQ9xIgBBCksNABogAiAAQQVqNgIAIAMgBGoiAkF8aiEMIAJBeWohDiACQXtqIRAgAEEGaiELQQQhBSAGQQR2IQRBICAAdCIAQQFyIQkgASgCACEPQQAhAiADIQYCQANAIAlBAkggAiAPS3JFBEAgAiEHAkAgCARAA0AgBEH//wNxQf//A0YEQCAHQRhqIQcgBiAQSQR/IAZBAmoiBigAACAFdgUgBUEQaiEFIARBEHYLIQQMAQsLA0AgBEEDcSIIQQNGBEAgBUECaiEFIARBAnYhBCAHQQNqIQcMAQsLIAcgCGoiByAPSw0EIAVBAmohBQNAIAIgB0kEQCANIAJBAXRqQQA7AQAgAkEBaiECDAELCyAGIA5LQQAgBiAFQQN1aiIHIAxLG0UEQCAHKAAAIAVBB3EiBXYhBAwCCyAEQQJ2IQQLIAYhBwsCfyALQX9qIAQgAEF/anEiBiAAQQF0QX9qIgggCWsiEUkNABogBCAIcSIEQQAgESAEIABIG2shBiALCyEIIA0gAkEBdGogBkF/aiIEOwEAIAlBASAGayAEIAZBAUgbayEJA0AgCSAASARAIABBAXUhACALQX9qIQsMAQsLAn8gByAOS0EAIAcgBSAIaiIFQQN1aiIGIAxLG0UEQCAFQQdxDAELIAUgDCIGIAdrQQN0awshBSACQQFqIQIgBEUhCCAGKAAAIAVBH3F2IQQMAQsLQWwgCUEBRyAFQSBKcg0BGiABIAJBf2o2AgAgBiAFQQdqQQN1aiADawwBC0FQCyEAIApBEGokACAACwkAQQFBBSAAGwsMACAAIAEoAAA2AAALqgMBCn8jAEHwAGsiCiQAIAJBAWohDiAAQQhqIQtBgIAEIAVBf2p0QRB1IQxBACECQQEhBkEBIAV0IglBf2oiDyEIA0AgAiAORkUEQAJAIAEgAkEBdCINai8BACIHQf//A0YEQCALIAhBA3RqIAI2AgQgCEF/aiEIQQEhBwwBCyAGQQAgDCAHQRB0QRB1ShshBgsgCiANaiAHOwEAIAJBAWohAgwBCwsgACAFNgIEIAAgBjYCACAJQQN2IAlBAXZqQQNqIQxBACEAQQAhBkEAIQIDQCAGIA5GBEADQAJAIAAgCUYNACAKIAsgAEEDdGoiASgCBCIGQQF0aiICIAIvAQAiAkEBajsBACABIAUgAhAUayIIOgADIAEgAiAIQf8BcXQgCWs7AQAgASAEIAZBAnQiAmooAgA6AAIgASACIANqKAIANgIEIABBAWohAAwBCwsFIAEgBkEBdGouAQAhDUEAIQcDQCAHIA1ORQRAIAsgAkEDdGogBjYCBANAIAIgDGogD3EiAiAISw0ACyAHQQFqIQcMAQsLIAZBAWohBgwBCwsgCkHwAGokAAsjAEIAIAEQCSAAhUKHla+vmLbem55/fkLj3MqV/M7y9YV/fAsQACAAQn43AwggACABNgIACyQBAX8gAARAIAEoAgQiAgRAIAEoAgggACACEQEADwsgABAmCwsfACAAIAEgAi8BABAINgIAIAEQBBogACACQQRqNgIEC0oBAX9BoCAoAgAiASAAaiIAQX9MBEBBiCBBMDYCAEF/DwsCQCAAPwBBEHRNDQAgABBmDQBBiCBBMDYCAEF/DwtBoCAgADYCACABC9cBAQh/Qbp/IQoCQCACKAIEIgggAigCACIJaiIOIAEgAGtLDQBBbCEKIAkgBCADKAIAIgtrSw0AIAAgCWoiBCACKAIIIgxrIQ0gACABQWBqIg8gCyAJQQAQKSADIAkgC2o2AgACQAJAIAwgBCAFa00EQCANIQUMAQsgDCAEIAZrSw0CIAcgDSAFayIAaiIBIAhqIAdNBEAgBCABIAgQDxoMAgsgBCABQQAgAGsQDyEBIAIgACAIaiIINgIEIAEgAGshBAsgBCAPIAUgCEEBECkLIA4hCgsgCgubAgEBfyMAQYABayINJAAgDSADNgJ8AkAgAkEDSwRAQX8hCQwBCwJAAkACQAJAIAJBAWsOAwADAgELIAZFBEBBuH8hCQwEC0FsIQkgBS0AACICIANLDQMgACAHIAJBAnQiAmooAgAgAiAIaigCABA7IAEgADYCAEEBIQkMAwsgASAJNgIAQQAhCQwCCyAKRQRAQWwhCQwCC0EAIQkgC0UgDEEZSHINAUEIIAR0QQhqIQBBACECA0AgAiAATw0CIAJBQGshAgwAAAsAC0FsIQkgDSANQfwAaiANQfgAaiAFIAYQFSICEAMNACANKAJ4IgMgBEsNACAAIA0gDSgCfCAHIAggAxAYIAEgADYCACACIQkLIA1BgAFqJAAgCQsLACAAIAEgAhALGgsQACAALwAAIAAtAAJBEHRyCy8AAn9BuH8gAUEISQ0AGkFyIAAoAAQiAEF3Sw0AGkG4fyAAQQhqIgAgACABSxsLCwkAIAAgATsAAAsDAAELigYBBX8gACAAKAIAIgVBfnE2AgBBACAAIAVBAXZqQYQgKAIAIgQgAEYbIQECQAJAIAAoAgQiAkUNACACKAIAIgNBAXENACACQQhqIgUgA0EBdkF4aiIDQQggA0EISxtnQR9zQQJ0QYAfaiIDKAIARgRAIAMgAigCDDYCAAsgAigCCCIDBEAgAyACKAIMNgIECyACKAIMIgMEQCADIAIoAgg2AgALIAIgAigCACAAKAIAQX5xajYCAEGEICEAAkACQCABRQ0AIAEgAjYCBCABKAIAIgNBAXENASADQQF2QXhqIgNBCCADQQhLG2dBH3NBAnRBgB9qIgMoAgAgAUEIakYEQCADIAEoAgw2AgALIAEoAggiAwRAIAMgASgCDDYCBAsgASgCDCIDBEAgAyABKAIINgIAQYQgKAIAIQQLIAIgAigCACABKAIAQX5xajYCACABIARGDQAgASABKAIAQQF2akEEaiEACyAAIAI2AgALIAIoAgBBAXZBeGoiAEEIIABBCEsbZ0Efc0ECdEGAH2oiASgCACEAIAEgBTYCACACIAA2AgwgAkEANgIIIABFDQEgACAFNgIADwsCQCABRQ0AIAEoAgAiAkEBcQ0AIAJBAXZBeGoiAkEIIAJBCEsbZ0Efc0ECdEGAH2oiAigCACABQQhqRgRAIAIgASgCDDYCAAsgASgCCCICBEAgAiABKAIMNgIECyABKAIMIgIEQCACIAEoAgg2AgBBhCAoAgAhBAsgACAAKAIAIAEoAgBBfnFqIgI2AgACQCABIARHBEAgASABKAIAQQF2aiAANgIEIAAoAgAhAgwBC0GEICAANgIACyACQQF2QXhqIgFBCCABQQhLG2dBH3NBAnRBgB9qIgIoAgAhASACIABBCGoiAjYCACAAIAE2AgwgAEEANgIIIAFFDQEgASACNgIADwsgBUEBdkF4aiIBQQggAUEISxtnQR9zQQJ0QYAfaiICKAIAIQEgAiAAQQhqIgI2AgAgACABNgIMIABBADYCCCABRQ0AIAEgAjYCAAsLDgAgAARAIABBeGoQJQsLgAIBA38CQCAAQQ9qQXhxQYQgKAIAKAIAQQF2ayICEB1Bf0YNAAJAQYQgKAIAIgAoAgAiAUEBcQ0AIAFBAXZBeGoiAUEIIAFBCEsbZ0Efc0ECdEGAH2oiASgCACAAQQhqRgRAIAEgACgCDDYCAAsgACgCCCIBBEAgASAAKAIMNgIECyAAKAIMIgFFDQAgASAAKAIINgIAC0EBIQEgACAAKAIAIAJBAXRqIgI2AgAgAkEBcQ0AIAJBAXZBeGoiAkEIIAJBCEsbZ0Efc0ECdEGAH2oiAygCACECIAMgAEEIaiIDNgIAIAAgAjYCDCAAQQA2AgggAkUNACACIAM2AgALIAELtwIBA38CQAJAIABBASAAGyICEDgiAA0AAkACQEGEICgCACIARQ0AIAAoAgAiA0EBcQ0AIAAgA0EBcjYCACADQQF2QXhqIgFBCCABQQhLG2dBH3NBAnRBgB9qIgEoAgAgAEEIakYEQCABIAAoAgw2AgALIAAoAggiAQRAIAEgACgCDDYCBAsgACgCDCIBBEAgASAAKAIINgIACyACECchAkEAIQFBhCAoAgAhACACDQEgACAAKAIAQX5xNgIAQQAPCyACQQ9qQXhxIgMQHSICQX9GDQIgAkEHakF4cSIAIAJHBEAgACACaxAdQX9GDQMLAkBBhCAoAgAiAUUEQEGAICAANgIADAELIAAgATYCBAtBhCAgADYCACAAIANBAXRBAXI2AgAMAQsgAEUNAQsgAEEIaiEBCyABC7kDAQJ/IAAgA2ohBQJAIANBB0wEQANAIAAgBU8NAiAAIAItAAA6AAAgAEEBaiEAIAJBAWohAgwAAAsACyAEQQFGBEACQCAAIAJrIgZBB00EQCAAIAItAAA6AAAgACACLQABOgABIAAgAi0AAjoAAiAAIAItAAM6AAMgAEEEaiACIAZBAnQiBkHAHmooAgBqIgIQFyACIAZB4B5qKAIAayECDAELIAAgAhAMCyACQQhqIQIgAEEIaiEACwJAAkACQAJAIAUgAU0EQCAAIANqIQEgBEEBRyAAIAJrQQ9Kcg0BA0AgACACEAwgAkEIaiECIABBCGoiACABSQ0ACwwFCyAAIAFLBEAgACEBDAQLIARBAUcgACACa0EPSnINASAAIQMgAiEEA0AgAyAEEAwgBEEIaiEEIANBCGoiAyABSQ0ACwwCCwNAIAAgAhAHIAJBEGohAiAAQRBqIgAgAUkNAAsMAwsgACEDIAIhBANAIAMgBBAHIARBEGohBCADQRBqIgMgAUkNAAsLIAIgASAAa2ohAgsDQCABIAVPDQEgASACLQAAOgAAIAFBAWohASACQQFqIQIMAAALAAsLQQECfyAAIAAoArjgASIDNgLE4AEgACgCvOABIQQgACABNgK84AEgACABIAJqNgK44AEgACABIAQgA2tqNgLA4AELpgEBAX8gACAAKALs4QEQFjYCyOABIABCADcD+OABIABCADcDuOABIABBwOABakIANwMAIABBqNAAaiIBQYyAgOAANgIAIABBADYCmOIBIABCADcDiOEBIABCAzcDgOEBIABBrNABakHgEikCADcCACAAQbTQAWpB6BIoAgA2AgAgACABNgIMIAAgAEGYIGo2AgggACAAQaAwajYCBCAAIABBEGo2AgALYQEBf0G4fyEDAkAgAUEDSQ0AIAIgABAhIgFBA3YiADYCCCACIAFBAXE2AgQgAiABQQF2QQNxIgM2AgACQCADQX9qIgFBAksNAAJAIAFBAWsOAgEAAgtBbA8LIAAhAwsgAwsMACAAIAEgAkEAEC4LiAQCA38CfiADEBYhBCAAQQBBKBAQIQAgBCACSwRAIAQPCyABRQRAQX8PCwJAAkAgA0EBRg0AIAEoAAAiBkGo6r5pRg0AQXYhAyAGQXBxQdDUtMIBRw0BQQghAyACQQhJDQEgAEEAQSgQECEAIAEoAAQhASAAQQE2AhQgACABrTcDAEEADwsgASACIAMQLyIDIAJLDQAgACADNgIYQXIhAyABIARqIgVBf2otAAAiAkEIcQ0AIAJBIHEiBkUEQEFwIQMgBS0AACIFQacBSw0BIAVBB3GtQgEgBUEDdkEKaq2GIgdCA4h+IAd8IQggBEEBaiEECyACQQZ2IQMgAkECdiEFAkAgAkEDcUF/aiICQQJLBEBBACECDAELAkACQAJAIAJBAWsOAgECAAsgASAEai0AACECIARBAWohBAwCCyABIARqLwAAIQIgBEECaiEEDAELIAEgBGooAAAhAiAEQQRqIQQLIAVBAXEhBQJ+AkACQAJAIANBf2oiA0ECTQRAIANBAWsOAgIDAQtCfyAGRQ0DGiABIARqMQAADAMLIAEgBGovAACtQoACfAwCCyABIARqKAAArQwBCyABIARqKQAACyEHIAAgBTYCICAAIAI2AhwgACAHNwMAQQAhAyAAQQA2AhQgACAHIAggBhsiBzcDCCAAIAdCgIAIIAdCgIAIVBs+AhALIAMLWwEBf0G4fyEDIAIQFiICIAFNBH8gACACakF/ai0AACIAQQNxQQJ0QaAeaigCACACaiAAQQZ2IgFBAnRBsB5qKAIAaiAAQSBxIgBFaiABRSAAQQV2cWoFQbh/CwsdACAAKAKQ4gEQWiAAQQA2AqDiASAAQgA3A5DiAQu1AwEFfyMAQZACayIKJABBuH8hBgJAIAVFDQAgBCwAACIIQf8BcSEHAkAgCEF/TARAIAdBgn9qQQF2IgggBU8NAkFsIQYgB0GBf2oiBUGAAk8NAiAEQQFqIQdBACEGA0AgBiAFTwRAIAUhBiAIIQcMAwUgACAGaiAHIAZBAXZqIgQtAABBBHY6AAAgACAGQQFyaiAELQAAQQ9xOgAAIAZBAmohBgwBCwAACwALIAcgBU8NASAAIARBAWogByAKEFMiBhADDQELIAYhBEEAIQYgAUEAQTQQECEJQQAhBQNAIAQgBkcEQCAAIAZqIggtAAAiAUELSwRAQWwhBgwDBSAJIAFBAnRqIgEgASgCAEEBajYCACAGQQFqIQZBASAILQAAdEEBdSAFaiEFDAILAAsLQWwhBiAFRQ0AIAUQFEEBaiIBQQxLDQAgAyABNgIAQQFBASABdCAFayIDEBQiAXQgA0cNACAAIARqIAFBAWoiADoAACAJIABBAnRqIgAgACgCAEEBajYCACAJKAIEIgBBAkkgAEEBcXINACACIARBAWo2AgAgB0EBaiEGCyAKQZACaiQAIAYLxhEBDH8jAEHwAGsiBSQAQWwhCwJAIANBCkkNACACLwAAIQogAi8AAiEJIAIvAAQhByAFQQhqIAQQDgJAIAMgByAJIApqakEGaiIMSQ0AIAUtAAohCCAFQdgAaiACQQZqIgIgChAGIgsQAw0BIAVBQGsgAiAKaiICIAkQBiILEAMNASAFQShqIAIgCWoiAiAHEAYiCxADDQEgBUEQaiACIAdqIAMgDGsQBiILEAMNASAAIAFqIg9BfWohECAEQQRqIQZBASELIAAgAUEDakECdiIDaiIMIANqIgIgA2oiDiEDIAIhBCAMIQcDQCALIAMgEElxBEAgACAGIAVB2ABqIAgQAkECdGoiCS8BADsAACAFQdgAaiAJLQACEAEgCS0AAyELIAcgBiAFQUBrIAgQAkECdGoiCS8BADsAACAFQUBrIAktAAIQASAJLQADIQogBCAGIAVBKGogCBACQQJ0aiIJLwEAOwAAIAVBKGogCS0AAhABIAktAAMhCSADIAYgBUEQaiAIEAJBAnRqIg0vAQA7AAAgBUEQaiANLQACEAEgDS0AAyENIAAgC2oiCyAGIAVB2ABqIAgQAkECdGoiAC8BADsAACAFQdgAaiAALQACEAEgAC0AAyEAIAcgCmoiCiAGIAVBQGsgCBACQQJ0aiIHLwEAOwAAIAVBQGsgBy0AAhABIActAAMhByAEIAlqIgkgBiAFQShqIAgQAkECdGoiBC8BADsAACAFQShqIAQtAAIQASAELQADIQQgAyANaiIDIAYgBUEQaiAIEAJBAnRqIg0vAQA7AAAgBUEQaiANLQACEAEgACALaiEAIAcgCmohByAEIAlqIQQgAyANLQADaiEDIAVB2ABqEA0gBUFAaxANciAFQShqEA1yIAVBEGoQDXJFIQsMAQsLIAQgDksgByACS3INAEFsIQsgACAMSw0BIAxBfWohCQNAQQAgACAJSSAFQdgAahAEGwRAIAAgBiAFQdgAaiAIEAJBAnRqIgovAQA7AAAgBUHYAGogCi0AAhABIAAgCi0AA2oiACAGIAVB2ABqIAgQAkECdGoiCi8BADsAACAFQdgAaiAKLQACEAEgACAKLQADaiEADAEFIAxBfmohCgNAIAVB2ABqEAQgACAKS3JFBEAgACAGIAVB2ABqIAgQAkECdGoiCS8BADsAACAFQdgAaiAJLQACEAEgACAJLQADaiEADAELCwNAIAAgCk0EQCAAIAYgBUHYAGogCBACQQJ0aiIJLwEAOwAAIAVB2ABqIAktAAIQASAAIAktAANqIQAMAQsLAkAgACAMTw0AIAAgBiAFQdgAaiAIEAIiAEECdGoiDC0AADoAACAMLQADQQFGBEAgBUHYAGogDC0AAhABDAELIAUoAlxBH0sNACAFQdgAaiAGIABBAnRqLQACEAEgBSgCXEEhSQ0AIAVBIDYCXAsgAkF9aiEMA0BBACAHIAxJIAVBQGsQBBsEQCAHIAYgBUFAayAIEAJBAnRqIgAvAQA7AAAgBUFAayAALQACEAEgByAALQADaiIAIAYgBUFAayAIEAJBAnRqIgcvAQA7AAAgBUFAayAHLQACEAEgACAHLQADaiEHDAEFIAJBfmohDANAIAVBQGsQBCAHIAxLckUEQCAHIAYgBUFAayAIEAJBAnRqIgAvAQA7AAAgBUFAayAALQACEAEgByAALQADaiEHDAELCwNAIAcgDE0EQCAHIAYgBUFAayAIEAJBAnRqIgAvAQA7AAAgBUFAayAALQACEAEgByAALQADaiEHDAELCwJAIAcgAk8NACAHIAYgBUFAayAIEAIiAEECdGoiAi0AADoAACACLQADQQFGBEAgBUFAayACLQACEAEMAQsgBSgCREEfSw0AIAVBQGsgBiAAQQJ0ai0AAhABIAUoAkRBIUkNACAFQSA2AkQLIA5BfWohAgNAQQAgBCACSSAFQShqEAQbBEAgBCAGIAVBKGogCBACQQJ0aiIALwEAOwAAIAVBKGogAC0AAhABIAQgAC0AA2oiACAGIAVBKGogCBACQQJ0aiIELwEAOwAAIAVBKGogBC0AAhABIAAgBC0AA2ohBAwBBSAOQX5qIQIDQCAFQShqEAQgBCACS3JFBEAgBCAGIAVBKGogCBACQQJ0aiIALwEAOwAAIAVBKGogAC0AAhABIAQgAC0AA2ohBAwBCwsDQCAEIAJNBEAgBCAGIAVBKGogCBACQQJ0aiIALwEAOwAAIAVBKGogAC0AAhABIAQgAC0AA2ohBAwBCwsCQCAEIA5PDQAgBCAGIAVBKGogCBACIgBBAnRqIgItAAA6AAAgAi0AA0EBRgRAIAVBKGogAi0AAhABDAELIAUoAixBH0sNACAFQShqIAYgAEECdGotAAIQASAFKAIsQSFJDQAgBUEgNgIsCwNAQQAgAyAQSSAFQRBqEAQbBEAgAyAGIAVBEGogCBACQQJ0aiIALwEAOwAAIAVBEGogAC0AAhABIAMgAC0AA2oiACAGIAVBEGogCBACQQJ0aiICLwEAOwAAIAVBEGogAi0AAhABIAAgAi0AA2ohAwwBBSAPQX5qIQIDQCAFQRBqEAQgAyACS3JFBEAgAyAGIAVBEGogCBACQQJ0aiIALwEAOwAAIAVBEGogAC0AAhABIAMgAC0AA2ohAwwBCwsDQCADIAJNBEAgAyAGIAVBEGogCBACQQJ0aiIALwEAOwAAIAVBEGogAC0AAhABIAMgAC0AA2ohAwwBCwsCQCADIA9PDQAgAyAGIAVBEGogCBACIgBBAnRqIgItAAA6AAAgAi0AA0EBRgRAIAVBEGogAi0AAhABDAELIAUoAhRBH0sNACAFQRBqIAYgAEECdGotAAIQASAFKAIUQSFJDQAgBUEgNgIUCyABQWwgBUHYAGoQCiAFQUBrEApxIAVBKGoQCnEgBUEQahAKcRshCwwJCwAACwALAAALAAsAAAsACwAACwALQWwhCwsgBUHwAGokACALC7UEAQ5/IwBBEGsiBiQAIAZBBGogABAOQVQhBQJAIARB3AtJDQAgBi0ABCEHIANB8ARqQQBB7AAQECEIIAdBDEsNACADQdwJaiIJIAggBkEIaiAGQQxqIAEgAhAxIhAQA0UEQCAGKAIMIgQgB0sNASADQdwFaiEPIANBpAVqIREgAEEEaiESIANBqAVqIQEgBCEFA0AgBSICQX9qIQUgCCACQQJ0aigCAEUNAAsgAkEBaiEOQQEhBQNAIAUgDk9FBEAgCCAFQQJ0IgtqKAIAIQwgASALaiAKNgIAIAVBAWohBSAKIAxqIQoMAQsLIAEgCjYCAEEAIQUgBigCCCELA0AgBSALRkUEQCABIAUgCWotAAAiDEECdGoiDSANKAIAIg1BAWo2AgAgDyANQQF0aiINIAw6AAEgDSAFOgAAIAVBAWohBQwBCwtBACEBIANBADYCqAUgBEF/cyAHaiEJQQEhBQNAIAUgDk9FBEAgCCAFQQJ0IgtqKAIAIQwgAyALaiABNgIAIAwgBSAJanQgAWohASAFQQFqIQUMAQsLIAcgBEEBaiIBIAJrIgRrQQFqIQgDQEEBIQUgBCAIT0UEQANAIAUgDk9FBEAgBUECdCIJIAMgBEE0bGpqIAMgCWooAgAgBHY2AgAgBUEBaiEFDAELCyAEQQFqIQQMAQsLIBIgByAPIAogESADIAIgARBkIAZBAToABSAGIAc6AAYgACAGKAIENgIACyAQIQULIAZBEGokACAFC8ENAQt/IwBB8ABrIgUkAEFsIQkCQCADQQpJDQAgAi8AACEKIAIvAAIhDCACLwAEIQYgBUEIaiAEEA4CQCADIAYgCiAMampBBmoiDUkNACAFLQAKIQcgBUHYAGogAkEGaiICIAoQBiIJEAMNASAFQUBrIAIgCmoiAiAMEAYiCRADDQEgBUEoaiACIAxqIgIgBhAGIgkQAw0BIAVBEGogAiAGaiADIA1rEAYiCRADDQEgACABaiIOQX1qIQ8gBEEEaiEGQQEhCSAAIAFBA2pBAnYiAmoiCiACaiIMIAJqIg0hAyAMIQQgCiECA0AgCSADIA9JcQRAIAYgBUHYAGogBxACQQF0aiIILQAAIQsgBUHYAGogCC0AARABIAAgCzoAACAGIAVBQGsgBxACQQF0aiIILQAAIQsgBUFAayAILQABEAEgAiALOgAAIAYgBUEoaiAHEAJBAXRqIggtAAAhCyAFQShqIAgtAAEQASAEIAs6AAAgBiAFQRBqIAcQAkEBdGoiCC0AACELIAVBEGogCC0AARABIAMgCzoAACAGIAVB2ABqIAcQAkEBdGoiCC0AACELIAVB2ABqIAgtAAEQASAAIAs6AAEgBiAFQUBrIAcQAkEBdGoiCC0AACELIAVBQGsgCC0AARABIAIgCzoAASAGIAVBKGogBxACQQF0aiIILQAAIQsgBUEoaiAILQABEAEgBCALOgABIAYgBUEQaiAHEAJBAXRqIggtAAAhCyAFQRBqIAgtAAEQASADIAs6AAEgA0ECaiEDIARBAmohBCACQQJqIQIgAEECaiEAIAkgBUHYAGoQDUVxIAVBQGsQDUVxIAVBKGoQDUVxIAVBEGoQDUVxIQkMAQsLIAQgDUsgAiAMS3INAEFsIQkgACAKSw0BIApBfWohCQNAIAVB2ABqEAQgACAJT3JFBEAgBiAFQdgAaiAHEAJBAXRqIggtAAAhCyAFQdgAaiAILQABEAEgACALOgAAIAYgBUHYAGogBxACQQF0aiIILQAAIQsgBUHYAGogCC0AARABIAAgCzoAASAAQQJqIQAMAQsLA0AgBUHYAGoQBCAAIApPckUEQCAGIAVB2ABqIAcQAkEBdGoiCS0AACEIIAVB2ABqIAktAAEQASAAIAg6AAAgAEEBaiEADAELCwNAIAAgCkkEQCAGIAVB2ABqIAcQAkEBdGoiCS0AACEIIAVB2ABqIAktAAEQASAAIAg6AAAgAEEBaiEADAELCyAMQX1qIQADQCAFQUBrEAQgAiAAT3JFBEAgBiAFQUBrIAcQAkEBdGoiCi0AACEJIAVBQGsgCi0AARABIAIgCToAACAGIAVBQGsgBxACQQF0aiIKLQAAIQkgBUFAayAKLQABEAEgAiAJOgABIAJBAmohAgwBCwsDQCAFQUBrEAQgAiAMT3JFBEAgBiAFQUBrIAcQAkEBdGoiAC0AACEKIAVBQGsgAC0AARABIAIgCjoAACACQQFqIQIMAQsLA0AgAiAMSQRAIAYgBUFAayAHEAJBAXRqIgAtAAAhCiAFQUBrIAAtAAEQASACIAo6AAAgAkEBaiECDAELCyANQX1qIQADQCAFQShqEAQgBCAAT3JFBEAgBiAFQShqIAcQAkEBdGoiAi0AACEKIAVBKGogAi0AARABIAQgCjoAACAGIAVBKGogBxACQQF0aiICLQAAIQogBUEoaiACLQABEAEgBCAKOgABIARBAmohBAwBCwsDQCAFQShqEAQgBCANT3JFBEAgBiAFQShqIAcQAkEBdGoiAC0AACECIAVBKGogAC0AARABIAQgAjoAACAEQQFqIQQMAQsLA0AgBCANSQRAIAYgBUEoaiAHEAJBAXRqIgAtAAAhAiAFQShqIAAtAAEQASAEIAI6AAAgBEEBaiEEDAELCwNAIAVBEGoQBCADIA9PckUEQCAGIAVBEGogBxACQQF0aiIALQAAIQIgBUEQaiAALQABEAEgAyACOgAAIAYgBUEQaiAHEAJBAXRqIgAtAAAhAiAFQRBqIAAtAAEQASADIAI6AAEgA0ECaiEDDAELCwNAIAVBEGoQBCADIA5PckUEQCAGIAVBEGogBxACQQF0aiIALQAAIQIgBUEQaiAALQABEAEgAyACOgAAIANBAWohAwwBCwsDQCADIA5JBEAgBiAFQRBqIAcQAkEBdGoiAC0AACECIAVBEGogAC0AARABIAMgAjoAACADQQFqIQMMAQsLIAFBbCAFQdgAahAKIAVBQGsQCnEgBUEoahAKcSAFQRBqEApxGyEJDAELQWwhCQsgBUHwAGokACAJC8oCAQR/IwBBIGsiBSQAIAUgBBAOIAUtAAIhByAFQQhqIAIgAxAGIgIQA0UEQCAEQQRqIQIgACABaiIDQX1qIQQDQCAFQQhqEAQgACAET3JFBEAgAiAFQQhqIAcQAkEBdGoiBi0AACEIIAVBCGogBi0AARABIAAgCDoAACACIAVBCGogBxACQQF0aiIGLQAAIQggBUEIaiAGLQABEAEgACAIOgABIABBAmohAAwBCwsDQCAFQQhqEAQgACADT3JFBEAgAiAFQQhqIAcQAkEBdGoiBC0AACEGIAVBCGogBC0AARABIAAgBjoAACAAQQFqIQAMAQsLA0AgACADT0UEQCACIAVBCGogBxACQQF0aiIELQAAIQYgBUEIaiAELQABEAEgACAGOgAAIABBAWohAAwBCwsgAUFsIAVBCGoQChshAgsgBUEgaiQAIAILtgMBCX8jAEEQayIGJAAgBkEANgIMIAZBADYCCEFUIQQCQAJAIANBQGsiDCADIAZBCGogBkEMaiABIAIQMSICEAMNACAGQQRqIAAQDiAGKAIMIgcgBi0ABEEBaksNASAAQQRqIQogBkEAOgAFIAYgBzoABiAAIAYoAgQ2AgAgB0EBaiEJQQEhBANAIAQgCUkEQCADIARBAnRqIgEoAgAhACABIAU2AgAgACAEQX9qdCAFaiEFIARBAWohBAwBCwsgB0EBaiEHQQAhBSAGKAIIIQkDQCAFIAlGDQEgAyAFIAxqLQAAIgRBAnRqIgBBASAEdEEBdSILIAAoAgAiAWoiADYCACAHIARrIQhBACEEAkAgC0EDTQRAA0AgBCALRg0CIAogASAEakEBdGoiACAIOgABIAAgBToAACAEQQFqIQQMAAALAAsDQCABIABPDQEgCiABQQF0aiIEIAg6AAEgBCAFOgAAIAQgCDoAAyAEIAU6AAIgBCAIOgAFIAQgBToABCAEIAg6AAcgBCAFOgAGIAFBBGohAQwAAAsACyAFQQFqIQUMAAALAAsgAiEECyAGQRBqJAAgBAutAQECfwJAQYQgKAIAIABHIAAoAgBBAXYiAyABa0F4aiICQXhxQQhHcgR/IAIFIAMQJ0UNASACQQhqC0EQSQ0AIAAgACgCACICQQFxIAAgAWpBD2pBeHEiASAAa0EBdHI2AgAgASAANgIEIAEgASgCAEEBcSAAIAJBAXZqIAFrIgJBAXRyNgIAQYQgIAEgAkH/////B3FqQQRqQYQgKAIAIABGGyABNgIAIAEQJQsLygIBBX8CQAJAAkAgAEEIIABBCEsbZ0EfcyAAaUEBR2oiAUEESSAAIAF2cg0AIAFBAnRB/B5qKAIAIgJFDQADQCACQXhqIgMoAgBBAXZBeGoiBSAATwRAIAIgBUEIIAVBCEsbZ0Efc0ECdEGAH2oiASgCAEYEQCABIAIoAgQ2AgALDAMLIARBHksNASAEQQFqIQQgAigCBCICDQALC0EAIQMgAUEgTw0BA0AgAUECdEGAH2ooAgAiAkUEQCABQR5LIQIgAUEBaiEBIAJFDQEMAwsLIAIgAkF4aiIDKAIAQQF2QXhqIgFBCCABQQhLG2dBH3NBAnRBgB9qIgEoAgBGBEAgASACKAIENgIACwsgAigCACIBBEAgASACKAIENgIECyACKAIEIgEEQCABIAIoAgA2AgALIAMgAygCAEEBcjYCACADIAAQNwsgAwvhCwINfwV+IwBB8ABrIgckACAHIAAoAvDhASIINgJcIAEgAmohDSAIIAAoAoDiAWohDwJAAkAgBUUEQCABIQQMAQsgACgCxOABIRAgACgCwOABIREgACgCvOABIQ4gAEEBNgKM4QFBACEIA0AgCEEDRwRAIAcgCEECdCICaiAAIAJqQazQAWooAgA2AkQgCEEBaiEIDAELC0FsIQwgB0EYaiADIAQQBhADDQEgB0EsaiAHQRhqIAAoAgAQEyAHQTRqIAdBGGogACgCCBATIAdBPGogB0EYaiAAKAIEEBMgDUFgaiESIAEhBEEAIQwDQCAHKAIwIAcoAixBA3RqKQIAIhRCEIinQf8BcSEIIAcoAkAgBygCPEEDdGopAgAiFUIQiKdB/wFxIQsgBygCOCAHKAI0QQN0aikCACIWQiCIpyEJIBVCIIghFyAUQiCIpyECAkAgFkIQiKdB/wFxIgNBAk8EQAJAIAZFIANBGUlyRQRAIAkgB0EYaiADQSAgBygCHGsiCiAKIANLGyIKEAUgAyAKayIDdGohCSAHQRhqEAQaIANFDQEgB0EYaiADEAUgCWohCQwBCyAHQRhqIAMQBSAJaiEJIAdBGGoQBBoLIAcpAkQhGCAHIAk2AkQgByAYNwNIDAELAkAgA0UEQCACBEAgBygCRCEJDAMLIAcoAkghCQwBCwJAAkAgB0EYakEBEAUgCSACRWpqIgNBA0YEQCAHKAJEQX9qIgMgA0VqIQkMAQsgA0ECdCAHaigCRCIJIAlFaiEJIANBAUYNAQsgByAHKAJINgJMCwsgByAHKAJENgJIIAcgCTYCRAsgF6chAyALBEAgB0EYaiALEAUgA2ohAwsgCCALakEUTwRAIAdBGGoQBBoLIAgEQCAHQRhqIAgQBSACaiECCyAHQRhqEAQaIAcgB0EYaiAUQhiIp0H/AXEQCCAUp0H//wNxajYCLCAHIAdBGGogFUIYiKdB/wFxEAggFadB//8DcWo2AjwgB0EYahAEGiAHIAdBGGogFkIYiKdB/wFxEAggFqdB//8DcWo2AjQgByACNgJgIAcoAlwhCiAHIAk2AmggByADNgJkAkACQAJAIAQgAiADaiILaiASSw0AIAIgCmoiEyAPSw0AIA0gBGsgC0Egak8NAQsgByAHKQNoNwMQIAcgBykDYDcDCCAEIA0gB0EIaiAHQdwAaiAPIA4gESAQEB4hCwwBCyACIARqIQggBCAKEAcgAkERTwRAIARBEGohAgNAIAIgCkEQaiIKEAcgAkEQaiICIAhJDQALCyAIIAlrIQIgByATNgJcIAkgCCAOa0sEQCAJIAggEWtLBEBBbCELDAILIBAgAiAOayICaiIKIANqIBBNBEAgCCAKIAMQDxoMAgsgCCAKQQAgAmsQDyEIIAcgAiADaiIDNgJkIAggAmshCCAOIQILIAlBEE8EQCADIAhqIQMDQCAIIAIQByACQRBqIQIgCEEQaiIIIANJDQALDAELAkAgCUEHTQRAIAggAi0AADoAACAIIAItAAE6AAEgCCACLQACOgACIAggAi0AAzoAAyAIQQRqIAIgCUECdCIDQcAeaigCAGoiAhAXIAIgA0HgHmooAgBrIQIgBygCZCEDDAELIAggAhAMCyADQQlJDQAgAyAIaiEDIAhBCGoiCCACQQhqIgJrQQ9MBEADQCAIIAIQDCACQQhqIQIgCEEIaiIIIANJDQAMAgALAAsDQCAIIAIQByACQRBqIQIgCEEQaiIIIANJDQALCyAHQRhqEAQaIAsgDCALEAMiAhshDCAEIAQgC2ogAhshBCAFQX9qIgUNAAsgDBADDQFBbCEMIAdBGGoQBEECSQ0BQQAhCANAIAhBA0cEQCAAIAhBAnQiAmpBrNABaiACIAdqKAJENgIAIAhBAWohCAwBCwsgBygCXCEIC0G6fyEMIA8gCGsiACANIARrSw0AIAQEfyAEIAggABALIABqBUEACyABayEMCyAHQfAAaiQAIAwLkRcCFn8FfiMAQdABayIHJAAgByAAKALw4QEiCDYCvAEgASACaiESIAggACgCgOIBaiETAkACQCAFRQRAIAEhAwwBCyAAKALE4AEhESAAKALA4AEhFSAAKAK84AEhDyAAQQE2AozhAUEAIQgDQCAIQQNHBEAgByAIQQJ0IgJqIAAgAmpBrNABaigCADYCVCAIQQFqIQgMAQsLIAcgETYCZCAHIA82AmAgByABIA9rNgJoQWwhECAHQShqIAMgBBAGEAMNASAFQQQgBUEESBshFyAHQTxqIAdBKGogACgCABATIAdBxABqIAdBKGogACgCCBATIAdBzABqIAdBKGogACgCBBATQQAhBCAHQeAAaiEMIAdB5ABqIQoDQCAHQShqEARBAksgBCAXTnJFBEAgBygCQCAHKAI8QQN0aikCACIdQhCIp0H/AXEhCyAHKAJQIAcoAkxBA3RqKQIAIh5CEIinQf8BcSEJIAcoAkggBygCREEDdGopAgAiH0IgiKchCCAeQiCIISAgHUIgiKchAgJAIB9CEIinQf8BcSIDQQJPBEACQCAGRSADQRlJckUEQCAIIAdBKGogA0EgIAcoAixrIg0gDSADSxsiDRAFIAMgDWsiA3RqIQggB0EoahAEGiADRQ0BIAdBKGogAxAFIAhqIQgMAQsgB0EoaiADEAUgCGohCCAHQShqEAQaCyAHKQJUISEgByAINgJUIAcgITcDWAwBCwJAIANFBEAgAgRAIAcoAlQhCAwDCyAHKAJYIQgMAQsCQAJAIAdBKGpBARAFIAggAkVqaiIDQQNGBEAgBygCVEF/aiIDIANFaiEIDAELIANBAnQgB2ooAlQiCCAIRWohCCADQQFGDQELIAcgBygCWDYCXAsLIAcgBygCVDYCWCAHIAg2AlQLICCnIQMgCQRAIAdBKGogCRAFIANqIQMLIAkgC2pBFE8EQCAHQShqEAQaCyALBEAgB0EoaiALEAUgAmohAgsgB0EoahAEGiAHIAcoAmggAmoiCSADajYCaCAKIAwgCCAJSxsoAgAhDSAHIAdBKGogHUIYiKdB/wFxEAggHadB//8DcWo2AjwgByAHQShqIB5CGIinQf8BcRAIIB6nQf//A3FqNgJMIAdBKGoQBBogB0EoaiAfQhiIp0H/AXEQCCEOIAdB8ABqIARBBHRqIgsgCSANaiAIazYCDCALIAg2AgggCyADNgIEIAsgAjYCACAHIA4gH6dB//8DcWo2AkQgBEEBaiEEDAELCyAEIBdIDQEgEkFgaiEYIAdB4ABqIRogB0HkAGohGyABIQMDQCAHQShqEARBAksgBCAFTnJFBEAgBygCQCAHKAI8QQN0aikCACIdQhCIp0H/AXEhCyAHKAJQIAcoAkxBA3RqKQIAIh5CEIinQf8BcSEIIAcoAkggBygCREEDdGopAgAiH0IgiKchCSAeQiCIISAgHUIgiKchDAJAIB9CEIinQf8BcSICQQJPBEACQCAGRSACQRlJckUEQCAJIAdBKGogAkEgIAcoAixrIgogCiACSxsiChAFIAIgCmsiAnRqIQkgB0EoahAEGiACRQ0BIAdBKGogAhAFIAlqIQkMAQsgB0EoaiACEAUgCWohCSAHQShqEAQaCyAHKQJUISEgByAJNgJUIAcgITcDWAwBCwJAIAJFBEAgDARAIAcoAlQhCQwDCyAHKAJYIQkMAQsCQAJAIAdBKGpBARAFIAkgDEVqaiICQQNGBEAgBygCVEF/aiICIAJFaiEJDAELIAJBAnQgB2ooAlQiCSAJRWohCSACQQFGDQELIAcgBygCWDYCXAsLIAcgBygCVDYCWCAHIAk2AlQLICCnIRQgCARAIAdBKGogCBAFIBRqIRQLIAggC2pBFE8EQCAHQShqEAQaCyALBEAgB0EoaiALEAUgDGohDAsgB0EoahAEGiAHIAcoAmggDGoiGSAUajYCaCAbIBogCSAZSxsoAgAhHCAHIAdBKGogHUIYiKdB/wFxEAggHadB//8DcWo2AjwgByAHQShqIB5CGIinQf8BcRAIIB6nQf//A3FqNgJMIAdBKGoQBBogByAHQShqIB9CGIinQf8BcRAIIB+nQf//A3FqNgJEIAcgB0HwAGogBEEDcUEEdGoiDSkDCCIdNwPIASAHIA0pAwAiHjcDwAECQAJAAkAgBygCvAEiDiAepyICaiIWIBNLDQAgAyAHKALEASIKIAJqIgtqIBhLDQAgEiADayALQSBqTw0BCyAHIAcpA8gBNwMQIAcgBykDwAE3AwggAyASIAdBCGogB0G8AWogEyAPIBUgERAeIQsMAQsgAiADaiEIIAMgDhAHIAJBEU8EQCADQRBqIQIDQCACIA5BEGoiDhAHIAJBEGoiAiAISQ0ACwsgCCAdpyIOayECIAcgFjYCvAEgDiAIIA9rSwRAIA4gCCAVa0sEQEFsIQsMAgsgESACIA9rIgJqIhYgCmogEU0EQCAIIBYgChAPGgwCCyAIIBZBACACaxAPIQggByACIApqIgo2AsQBIAggAmshCCAPIQILIA5BEE8EQCAIIApqIQoDQCAIIAIQByACQRBqIQIgCEEQaiIIIApJDQALDAELAkAgDkEHTQRAIAggAi0AADoAACAIIAItAAE6AAEgCCACLQACOgACIAggAi0AAzoAAyAIQQRqIAIgDkECdCIKQcAeaigCAGoiAhAXIAIgCkHgHmooAgBrIQIgBygCxAEhCgwBCyAIIAIQDAsgCkEJSQ0AIAggCmohCiAIQQhqIgggAkEIaiICa0EPTARAA0AgCCACEAwgAkEIaiECIAhBCGoiCCAKSQ0ADAIACwALA0AgCCACEAcgAkEQaiECIAhBEGoiCCAKSQ0ACwsgCxADBEAgCyEQDAQFIA0gDDYCACANIBkgHGogCWs2AgwgDSAJNgIIIA0gFDYCBCAEQQFqIQQgAyALaiEDDAILAAsLIAQgBUgNASAEIBdrIQtBACEEA0AgCyAFSARAIAcgB0HwAGogC0EDcUEEdGoiAikDCCIdNwPIASAHIAIpAwAiHjcDwAECQAJAAkAgBygCvAEiDCAepyICaiIKIBNLDQAgAyAHKALEASIJIAJqIhBqIBhLDQAgEiADayAQQSBqTw0BCyAHIAcpA8gBNwMgIAcgBykDwAE3AxggAyASIAdBGGogB0G8AWogEyAPIBUgERAeIRAMAQsgAiADaiEIIAMgDBAHIAJBEU8EQCADQRBqIQIDQCACIAxBEGoiDBAHIAJBEGoiAiAISQ0ACwsgCCAdpyIGayECIAcgCjYCvAEgBiAIIA9rSwRAIAYgCCAVa0sEQEFsIRAMAgsgESACIA9rIgJqIgwgCWogEU0EQCAIIAwgCRAPGgwCCyAIIAxBACACaxAPIQggByACIAlqIgk2AsQBIAggAmshCCAPIQILIAZBEE8EQCAIIAlqIQYDQCAIIAIQByACQRBqIQIgCEEQaiIIIAZJDQALDAELAkAgBkEHTQRAIAggAi0AADoAACAIIAItAAE6AAEgCCACLQACOgACIAggAi0AAzoAAyAIQQRqIAIgBkECdCIGQcAeaigCAGoiAhAXIAIgBkHgHmooAgBrIQIgBygCxAEhCQwBCyAIIAIQDAsgCUEJSQ0AIAggCWohBiAIQQhqIgggAkEIaiICa0EPTARAA0AgCCACEAwgAkEIaiECIAhBCGoiCCAGSQ0ADAIACwALA0AgCCACEAcgAkEQaiECIAhBEGoiCCAGSQ0ACwsgEBADDQMgC0EBaiELIAMgEGohAwwBCwsDQCAEQQNHBEAgACAEQQJ0IgJqQazQAWogAiAHaigCVDYCACAEQQFqIQQMAQsLIAcoArwBIQgLQbp/IRAgEyAIayIAIBIgA2tLDQAgAwR/IAMgCCAAEAsgAGoFQQALIAFrIRALIAdB0AFqJAAgEAslACAAQgA3AgAgAEEAOwEIIABBADoACyAAIAE2AgwgACACOgAKC7QFAQN/IwBBMGsiBCQAIABB/wFqIgVBfWohBgJAIAMvAQIEQCAEQRhqIAEgAhAGIgIQAw0BIARBEGogBEEYaiADEBwgBEEIaiAEQRhqIAMQHCAAIQMDQAJAIARBGGoQBCADIAZPckUEQCADIARBEGogBEEYahASOgAAIAMgBEEIaiAEQRhqEBI6AAEgBEEYahAERQ0BIANBAmohAwsgBUF+aiEFAn8DQEG6fyECIAMiASAFSw0FIAEgBEEQaiAEQRhqEBI6AAAgAUEBaiEDIARBGGoQBEEDRgRAQQIhAiAEQQhqDAILIAMgBUsNBSABIARBCGogBEEYahASOgABIAFBAmohA0EDIQIgBEEYahAEQQNHDQALIARBEGoLIQUgAyAFIARBGGoQEjoAACABIAJqIABrIQIMAwsgAyAEQRBqIARBGGoQEjoAAiADIARBCGogBEEYahASOgADIANBBGohAwwAAAsACyAEQRhqIAEgAhAGIgIQAw0AIARBEGogBEEYaiADEBwgBEEIaiAEQRhqIAMQHCAAIQMDQAJAIARBGGoQBCADIAZPckUEQCADIARBEGogBEEYahAROgAAIAMgBEEIaiAEQRhqEBE6AAEgBEEYahAERQ0BIANBAmohAwsgBUF+aiEFAn8DQEG6fyECIAMiASAFSw0EIAEgBEEQaiAEQRhqEBE6AAAgAUEBaiEDIARBGGoQBEEDRgRAQQIhAiAEQQhqDAILIAMgBUsNBCABIARBCGogBEEYahAROgABIAFBAmohA0EDIQIgBEEYahAEQQNHDQALIARBEGoLIQUgAyAFIARBGGoQEToAACABIAJqIABrIQIMAgsgAyAEQRBqIARBGGoQEToAAiADIARBCGogBEEYahAROgADIANBBGohAwwAAAsACyAEQTBqJAAgAgtpAQF/An8CQAJAIAJBB00NACABKAAAQbfIwuF+Rw0AIAAgASgABDYCmOIBQWIgAEEQaiABIAIQPiIDEAMNAhogAEKBgICAEDcDiOEBIAAgASADaiACIANrECoMAQsgACABIAIQKgtBAAsLrQMBBn8jAEGAAWsiAyQAQWIhCAJAIAJBCUkNACAAQZjQAGogAUEIaiIEIAJBeGogAEGY0AAQMyIFEAMiBg0AIANBHzYCfCADIANB/ABqIANB+ABqIAQgBCAFaiAGGyIEIAEgAmoiAiAEaxAVIgUQAw0AIAMoAnwiBkEfSw0AIAMoAngiB0EJTw0AIABBiCBqIAMgBkGAC0GADCAHEBggA0E0NgJ8IAMgA0H8AGogA0H4AGogBCAFaiIEIAIgBGsQFSIFEAMNACADKAJ8IgZBNEsNACADKAJ4IgdBCk8NACAAQZAwaiADIAZBgA1B4A4gBxAYIANBIzYCfCADIANB/ABqIANB+ABqIAQgBWoiBCACIARrEBUiBRADDQAgAygCfCIGQSNLDQAgAygCeCIHQQpPDQAgACADIAZBwBBB0BEgBxAYIAQgBWoiBEEMaiIFIAJLDQAgAiAFayEFQQAhAgNAIAJBA0cEQCAEKAAAIgZBf2ogBU8NAiAAIAJBAnRqQZzQAWogBjYCACACQQFqIQIgBEEEaiEEDAELCyAEIAFrIQgLIANBgAFqJAAgCAtGAQN/IABBCGohAyAAKAIEIQJBACEAA0AgACACdkUEQCABIAMgAEEDdGotAAJBFktqIQEgAEEBaiEADAELCyABQQggAmt0C4YDAQV/Qbh/IQcCQCADRQ0AIAItAAAiBEUEQCABQQA2AgBBAUG4fyADQQFGGw8LAn8gAkEBaiIFIARBGHRBGHUiBkF/Sg0AGiAGQX9GBEAgA0EDSA0CIAUvAABBgP4BaiEEIAJBA2oMAQsgA0ECSA0BIAItAAEgBEEIdHJBgIB+aiEEIAJBAmoLIQUgASAENgIAIAVBAWoiASACIANqIgNLDQBBbCEHIABBEGogACAFLQAAIgVBBnZBI0EJIAEgAyABa0HAEEHQEUHwEiAAKAKM4QEgACgCnOIBIAQQHyIGEAMiCA0AIABBmCBqIABBCGogBUEEdkEDcUEfQQggASABIAZqIAgbIgEgAyABa0GAC0GADEGAFyAAKAKM4QEgACgCnOIBIAQQHyIGEAMiCA0AIABBoDBqIABBBGogBUECdkEDcUE0QQkgASABIAZqIAgbIgEgAyABa0GADUHgDkGQGSAAKAKM4QEgACgCnOIBIAQQHyIAEAMNACAAIAFqIAJrIQcLIAcLrQMBCn8jAEGABGsiCCQAAn9BUiACQf8BSw0AGkFUIANBDEsNABogAkEBaiELIABBBGohCUGAgAQgA0F/anRBEHUhCkEAIQJBASEEQQEgA3QiB0F/aiIMIQUDQCACIAtGRQRAAkAgASACQQF0Ig1qLwEAIgZB//8DRgRAIAkgBUECdGogAjoAAiAFQX9qIQVBASEGDAELIARBACAKIAZBEHRBEHVKGyEECyAIIA1qIAY7AQAgAkEBaiECDAELCyAAIAQ7AQIgACADOwEAIAdBA3YgB0EBdmpBA2ohBkEAIQRBACECA0AgBCALRkUEQCABIARBAXRqLgEAIQpBACEAA0AgACAKTkUEQCAJIAJBAnRqIAQ6AAIDQCACIAZqIAxxIgIgBUsNAAsgAEEBaiEADAELCyAEQQFqIQQMAQsLQX8gAg0AGkEAIQIDfyACIAdGBH9BAAUgCCAJIAJBAnRqIgAtAAJBAXRqIgEgAS8BACIBQQFqOwEAIAAgAyABEBRrIgU6AAMgACABIAVB/wFxdCAHazsBACACQQFqIQIMAQsLCyEFIAhBgARqJAAgBQvjBgEIf0FsIQcCQCACQQNJDQACQAJAAkACQCABLQAAIgNBA3EiCUEBaw4DAwEAAgsgACgCiOEBDQBBYg8LIAJBBUkNAkEDIQYgASgAACEFAn8CQAJAIANBAnZBA3EiCEF+aiIEQQFNBEAgBEEBaw0BDAILIAVBDnZB/wdxIQQgBUEEdkH/B3EhAyAIRQwCCyAFQRJ2IQRBBCEGIAVBBHZB//8AcSEDQQAMAQsgBUEEdkH//w9xIgNBgIAISw0DIAEtAARBCnQgBUEWdnIhBEEFIQZBAAshBSAEIAZqIgogAksNAgJAIANBgQZJDQAgACgCnOIBRQ0AQQAhAgNAIAJBg4ABSw0BIAJBQGshAgwAAAsACwJ/IAlBA0YEQCABIAZqIQEgAEHw4gFqIQIgACgCDCEGIAUEQCACIAMgASAEIAYQXwwCCyACIAMgASAEIAYQXQwBCyAAQbjQAWohAiABIAZqIQEgAEHw4gFqIQYgAEGo0ABqIQggBQRAIAggBiADIAEgBCACEF4MAQsgCCAGIAMgASAEIAIQXAsQAw0CIAAgAzYCgOIBIABBATYCiOEBIAAgAEHw4gFqNgLw4QEgCUECRgRAIAAgAEGo0ABqNgIMCyAAIANqIgBBiOMBakIANwAAIABBgOMBakIANwAAIABB+OIBakIANwAAIABB8OIBakIANwAAIAoPCwJ/AkACQAJAIANBAnZBA3FBf2oiBEECSw0AIARBAWsOAgACAQtBASEEIANBA3YMAgtBAiEEIAEvAABBBHYMAQtBAyEEIAEQIUEEdgsiAyAEaiIFQSBqIAJLBEAgBSACSw0CIABB8OIBaiABIARqIAMQCyEBIAAgAzYCgOIBIAAgATYC8OEBIAEgA2oiAEIANwAYIABCADcAECAAQgA3AAggAEIANwAAIAUPCyAAIAM2AoDiASAAIAEgBGo2AvDhASAFDwsCfwJAAkACQCADQQJ2QQNxQX9qIgRBAksNACAEQQFrDgIAAgELQQEhByADQQN2DAILQQIhByABLwAAQQR2DAELIAJBBEkgARAhIgJBj4CAAUtyDQFBAyEHIAJBBHYLIQIgAEHw4gFqIAEgB2otAAAgAkEgahAQIQEgACACNgKA4gEgACABNgLw4QEgB0EBaiEHCyAHC0sAIABC+erQ0OfJoeThADcDICAAQgA3AxggAELP1tO+0ser2UI3AxAgAELW64Lu6v2J9eAANwMIIABCADcDACAAQShqQQBBKBAQGgviAgICfwV+IABBKGoiASAAKAJIaiECAn4gACkDACIDQiBaBEAgACkDECIEQgeJIAApAwgiBUIBiXwgACkDGCIGQgyJfCAAKQMgIgdCEol8IAUQGSAEEBkgBhAZIAcQGQwBCyAAKQMYQsXP2bLx5brqJ3wLIAN8IQMDQCABQQhqIgAgAk0EQEIAIAEpAAAQCSADhUIbiUKHla+vmLbem55/fkLj3MqV/M7y9YV/fCEDIAAhAQwBCwsCQCABQQRqIgAgAksEQCABIQAMAQsgASgAAK1Ch5Wvr5i23puef34gA4VCF4lCz9bTvtLHq9lCfkL5893xmfaZqxZ8IQMLA0AgACACSQRAIAAxAABCxc/ZsvHluuonfiADhUILiUKHla+vmLbem55/fiEDIABBAWohAAwBCwsgA0IhiCADhULP1tO+0ser2UJ+IgNCHYggA4VC+fPd8Zn2masWfiIDQiCIIAOFC+8CAgJ/BH4gACAAKQMAIAKtfDcDAAJAAkAgACgCSCIDIAJqIgRBH00EQCABRQ0BIAAgA2pBKGogASACECAgACgCSCACaiEEDAELIAEgAmohAgJ/IAMEQCAAQShqIgQgA2ogAUEgIANrECAgACAAKQMIIAQpAAAQCTcDCCAAIAApAxAgACkAMBAJNwMQIAAgACkDGCAAKQA4EAk3AxggACAAKQMgIABBQGspAAAQCTcDICAAKAJIIQMgAEEANgJIIAEgA2tBIGohAQsgAUEgaiACTQsEQCACQWBqIQMgACkDICEFIAApAxghBiAAKQMQIQcgACkDCCEIA0AgCCABKQAAEAkhCCAHIAEpAAgQCSEHIAYgASkAEBAJIQYgBSABKQAYEAkhBSABQSBqIgEgA00NAAsgACAFNwMgIAAgBjcDGCAAIAc3AxAgACAINwMICyABIAJPDQEgAEEoaiABIAIgAWsiBBAgCyAAIAQ2AkgLCy8BAX8gAEUEQEG2f0EAIAMbDwtBun8hBCADIAFNBH8gACACIAMQEBogAwVBun8LCy8BAX8gAEUEQEG2f0EAIAMbDwtBun8hBCADIAFNBH8gACACIAMQCxogAwVBun8LC6gCAQZ/IwBBEGsiByQAIABB2OABaikDAEKAgIAQViEIQbh/IQUCQCAEQf//B0sNACAAIAMgBBBCIgUQAyIGDQAgACgCnOIBIQkgACAHQQxqIAMgAyAFaiAGGyIKIARBACAFIAYbayIGEEAiAxADBEAgAyEFDAELIAcoAgwhBCABRQRAQbp/IQUgBEEASg0BCyAGIANrIQUgAyAKaiEDAkAgCQRAIABBADYCnOIBDAELAkACQAJAIARBBUgNACAAQdjgAWopAwBCgICACFgNAAwBCyAAQQA2ApziAQwBCyAAKAIIED8hBiAAQQA2ApziASAGQRRPDQELIAAgASACIAMgBSAEIAgQOSEFDAELIAAgASACIAMgBSAEIAgQOiEFCyAHQRBqJAAgBQtnACAAQdDgAWogASACIAAoAuzhARAuIgEQAwRAIAEPC0G4fyECAkAgAQ0AIABB7OABaigCACIBBEBBYCECIAAoApjiASABRw0BC0EAIQIgAEHw4AFqKAIARQ0AIABBkOEBahBDCyACCycBAX8QVyIERQRAQUAPCyAEIAAgASACIAMgBBBLEE8hACAEEFYgAAs/AQF/AkACQAJAIAAoAqDiAUEBaiIBQQJLDQAgAUEBaw4CAAECCyAAEDBBAA8LIABBADYCoOIBCyAAKAKU4gELvAMCB38BfiMAQRBrIgkkAEG4fyEGAkAgBCgCACIIQQVBCSAAKALs4QEiBRtJDQAgAygCACIHQQFBBSAFGyAFEC8iBRADBEAgBSEGDAELIAggBUEDakkNACAAIAcgBRBJIgYQAw0AIAEgAmohCiAAQZDhAWohCyAIIAVrIQIgBSAHaiEHIAEhBQNAIAcgAiAJECwiBhADDQEgAkF9aiICIAZJBEBBuH8hBgwCCyAJKAIAIghBAksEQEFsIQYMAgsgB0EDaiEHAn8CQAJAAkAgCEEBaw4CAgABCyAAIAUgCiAFayAHIAYQSAwCCyAFIAogBWsgByAGEEcMAQsgBSAKIAVrIActAAAgCSgCCBBGCyIIEAMEQCAIIQYMAgsgACgC8OABBEAgCyAFIAgQRQsgAiAGayECIAYgB2ohByAFIAhqIQUgCSgCBEUNAAsgACkD0OABIgxCf1IEQEFsIQYgDCAFIAFrrFINAQsgACgC8OABBEBBaiEGIAJBBEkNASALEEQhDCAHKAAAIAynRw0BIAdBBGohByACQXxqIQILIAMgBzYCACAEIAI2AgAgBSABayEGCyAJQRBqJAAgBgsuACAAECsCf0EAQQAQAw0AGiABRSACRXJFBEBBYiAAIAEgAhA9EAMNARoLQQALCzcAIAEEQCAAIAAoAsTgASABKAIEIAEoAghqRzYCnOIBCyAAECtBABADIAFFckUEQCAAIAEQWwsL0QIBB38jAEEQayIGJAAgBiAENgIIIAYgAzYCDCAFBEAgBSgCBCEKIAUoAgghCQsgASEIAkACQANAIAAoAuzhARAWIQsCQANAIAQgC0kNASADKAAAQXBxQdDUtMIBRgRAIAMgBBAiIgcQAw0EIAQgB2shBCADIAdqIQMMAQsLIAYgAzYCDCAGIAQ2AggCQCAFBEAgACAFEE5BACEHQQAQA0UNAQwFCyAAIAogCRBNIgcQAw0ECyAAIAgQUCAMQQFHQQAgACAIIAIgBkEMaiAGQQhqEEwiByIDa0EAIAMQAxtBCkdyRQRAQbh/IQcMBAsgBxADDQMgAiAHayECIAcgCGohCEEBIQwgBigCDCEDIAYoAgghBAwBCwsgBiADNgIMIAYgBDYCCEG4fyEHIAQNASAIIAFrIQcMAQsgBiADNgIMIAYgBDYCCAsgBkEQaiQAIAcLRgECfyABIAAoArjgASICRwRAIAAgAjYCxOABIAAgATYCuOABIAAoArzgASEDIAAgATYCvOABIAAgASADIAJrajYCwOABCwutAgIEfwF+IwBBQGoiBCQAAkACQCACQQhJDQAgASgAAEFwcUHQ1LTCAUcNACABIAIQIiEBIABCADcDCCAAQQA2AgQgACABNgIADAELIARBGGogASACEC0iAxADBEAgACADEBoMAQsgAwRAIABBuH8QGgwBCyACIAQoAjAiA2shAiABIANqIQMDQAJAIAAgAyACIARBCGoQLCIFEAMEfyAFBSACIAVBA2oiBU8NAUG4fwsQGgwCCyAGQQFqIQYgAiAFayECIAMgBWohAyAEKAIMRQ0ACyAEKAI4BEAgAkEDTQRAIABBuH8QGgwCCyADQQRqIQMLIAQoAighAiAEKQMYIQcgAEEANgIEIAAgAyABazYCACAAIAIgBmytIAcgB0J/URs3AwgLIARBQGskAAslAQF/IwBBEGsiAiQAIAIgACABEFEgAigCACEAIAJBEGokACAAC30BBH8jAEGQBGsiBCQAIARB/wE2AggCQCAEQRBqIARBCGogBEEMaiABIAIQFSIGEAMEQCAGIQUMAQtBVCEFIAQoAgwiB0EGSw0AIAMgBEEQaiAEKAIIIAcQQSIFEAMNACAAIAEgBmogAiAGayADEDwhBQsgBEGQBGokACAFC4cBAgJ/An5BABAWIQMCQANAIAEgA08EQAJAIAAoAABBcHFB0NS0wgFGBEAgACABECIiAhADRQ0BQn4PCyAAIAEQVSIEQn1WDQMgBCAFfCIFIARUIQJCfiEEIAINAyAAIAEQUiICEAMNAwsgASACayEBIAAgAmohAAwBCwtCfiAFIAEbIQQLIAQLPwIBfwF+IwBBMGsiAiQAAn5CfiACQQhqIAAgARAtDQAaQgAgAigCHEEBRg0AGiACKQMICyEDIAJBMGokACADC40BAQJ/IwBBMGsiASQAAkAgAEUNACAAKAKI4gENACABIABB/OEBaigCADYCKCABIAApAvThATcDICAAEDAgACgCqOIBIQIgASABKAIoNgIYIAEgASkDIDcDECACIAFBEGoQGyAAQQA2AqjiASABIAEoAig2AgggASABKQMgNwMAIAAgARAbCyABQTBqJAALKgECfyMAQRBrIgAkACAAQQA2AgggAEIANwMAIAAQWCEBIABBEGokACABC4cBAQN/IwBBEGsiAiQAAkAgACgCAEUgACgCBEVzDQAgAiAAKAIINgIIIAIgACkCADcDAAJ/IAIoAgAiAQRAIAIoAghBqOMJIAERBQAMAQtBqOMJECgLIgFFDQAgASAAKQIANwL04QEgAUH84QFqIAAoAgg2AgAgARBZIAEhAwsgAkEQaiQAIAMLywEBAn8jAEEgayIBJAAgAEGBgIDAADYCtOIBIABBADYCiOIBIABBADYC7OEBIABCADcDkOIBIABBADYCpOMJIABBADYC3OIBIABCADcCzOIBIABBADYCvOIBIABBADYCxOABIABCADcCnOIBIABBpOIBakIANwIAIABBrOIBakEANgIAIAFCADcCECABQgA3AhggASABKQMYNwMIIAEgASkDEDcDACABKAIIQQh2QQFxIQIgAEEANgLg4gEgACACNgKM4gEgAUEgaiQAC3YBA38jAEEwayIBJAAgAARAIAEgAEHE0AFqIgIoAgA2AiggASAAKQK80AE3AyAgACgCACEDIAEgAigCADYCGCABIAApArzQATcDECADIAFBEGoQGyABIAEoAig2AgggASABKQMgNwMAIAAgARAbCyABQTBqJAALzAEBAX8gACABKAK00AE2ApjiASAAIAEoAgQiAjYCwOABIAAgAjYCvOABIAAgAiABKAIIaiICNgK44AEgACACNgLE4AEgASgCuNABBEAgAEKBgICAEDcDiOEBIAAgAUGk0ABqNgIMIAAgAUGUIGo2AgggACABQZwwajYCBCAAIAFBDGo2AgAgAEGs0AFqIAFBqNABaigCADYCACAAQbDQAWogAUGs0AFqKAIANgIAIABBtNABaiABQbDQAWooAgA2AgAPCyAAQgA3A4jhAQs7ACACRQRAQbp/DwsgBEUEQEFsDwsgAiAEEGAEQCAAIAEgAiADIAQgBRBhDwsgACABIAIgAyAEIAUQZQtGAQF/IwBBEGsiBSQAIAVBCGogBBAOAn8gBS0ACQRAIAAgASACIAMgBBAyDAELIAAgASACIAMgBBA0CyEAIAVBEGokACAACzQAIAAgAyAEIAUQNiIFEAMEQCAFDwsgBSAESQR/IAEgAiADIAVqIAQgBWsgABA1BUG4fwsLRgEBfyMAQRBrIgUkACAFQQhqIAQQDgJ/IAUtAAkEQCAAIAEgAiADIAQQYgwBCyAAIAEgAiADIAQQNQshACAFQRBqJAAgAAtZAQF/QQ8hAiABIABJBEAgAUEEdCAAbiECCyAAQQh2IgEgAkEYbCIAQYwIaigCAGwgAEGICGooAgBqIgJBA3YgAmogAEGACGooAgAgAEGECGooAgAgAWxqSQs3ACAAIAMgBCAFQYAQEDMiBRADBEAgBQ8LIAUgBEkEfyABIAIgAyAFaiAEIAVrIAAQMgVBuH8LC78DAQN/IwBBIGsiBSQAIAVBCGogAiADEAYiAhADRQRAIAAgAWoiB0F9aiEGIAUgBBAOIARBBGohAiAFLQACIQMDQEEAIAAgBkkgBUEIahAEGwRAIAAgAiAFQQhqIAMQAkECdGoiBC8BADsAACAFQQhqIAQtAAIQASAAIAQtAANqIgQgAiAFQQhqIAMQAkECdGoiAC8BADsAACAFQQhqIAAtAAIQASAEIAAtAANqIQAMAQUgB0F+aiEEA0AgBUEIahAEIAAgBEtyRQRAIAAgAiAFQQhqIAMQAkECdGoiBi8BADsAACAFQQhqIAYtAAIQASAAIAYtAANqIQAMAQsLA0AgACAES0UEQCAAIAIgBUEIaiADEAJBAnRqIgYvAQA7AAAgBUEIaiAGLQACEAEgACAGLQADaiEADAELCwJAIAAgB08NACAAIAIgBUEIaiADEAIiA0ECdGoiAC0AADoAACAALQADQQFGBEAgBUEIaiAALQACEAEMAQsgBSgCDEEfSw0AIAVBCGogAiADQQJ0ai0AAhABIAUoAgxBIUkNACAFQSA2AgwLIAFBbCAFQQhqEAobIQILCwsgBUEgaiQAIAILkgIBBH8jAEFAaiIJJAAgCSADQTQQCyEDAkAgBEECSA0AIAMgBEECdGooAgAhCSADQTxqIAgQIyADQQE6AD8gAyACOgA+QQAhBCADKAI8IQoDQCAEIAlGDQEgACAEQQJ0aiAKNgEAIARBAWohBAwAAAsAC0EAIQkDQCAGIAlGRQRAIAMgBSAJQQF0aiIKLQABIgtBAnRqIgwoAgAhBCADQTxqIAotAABBCHQgCGpB//8DcRAjIANBAjoAPyADIAcgC2siCiACajoAPiAEQQEgASAKa3RqIQogAygCPCELA0AgACAEQQJ0aiALNgEAIARBAWoiBCAKSQ0ACyAMIAo2AgAgCUEBaiEJDAELCyADQUBrJAALowIBCX8jAEHQAGsiCSQAIAlBEGogBUE0EAsaIAcgBmshDyAHIAFrIRADQAJAIAMgCkcEQEEBIAEgByACIApBAXRqIgYtAAEiDGsiCGsiC3QhDSAGLQAAIQ4gCUEQaiAMQQJ0aiIMKAIAIQYgCyAPTwRAIAAgBkECdGogCyAIIAUgCEE0bGogCCAQaiIIQQEgCEEBShsiCCACIAQgCEECdGooAgAiCEEBdGogAyAIayAHIA4QYyAGIA1qIQgMAgsgCUEMaiAOECMgCUEBOgAPIAkgCDoADiAGIA1qIQggCSgCDCELA0AgBiAITw0CIAAgBkECdGogCzYBACAGQQFqIQYMAAALAAsgCUHQAGokAA8LIAwgCDYCACAKQQFqIQoMAAALAAs0ACAAIAMgBCAFEDYiBRADBEAgBQ8LIAUgBEkEfyABIAIgAyAFaiAEIAVrIAAQNAVBuH8LCyMAIAA/AEEQdGtB//8DakEQdkAAQX9GBEBBAA8LQQAQAEEBCzsBAX8gAgRAA0AgACABIAJBgCAgAkGAIEkbIgMQCyEAIAFBgCBqIQEgAEGAIGohACACIANrIgINAAsLCwYAIAAQAwsLqBUJAEGICAsNAQAAAAEAAAACAAAAAgBBoAgLswYBAAAAAQAAAAIAAAACAAAAJgAAAIIAAAAhBQAASgAAAGcIAAAmAAAAwAEAAIAAAABJBQAASgAAAL4IAAApAAAALAIAAIAAAABJBQAASgAAAL4IAAAvAAAAygIAAIAAAACKBQAASgAAAIQJAAA1AAAAcwMAAIAAAACdBQAASgAAAKAJAAA9AAAAgQMAAIAAAADrBQAASwAAAD4KAABEAAAAngMAAIAAAABNBgAASwAAAKoKAABLAAAAswMAAIAAAADBBgAATQAAAB8NAABNAAAAUwQAAIAAAAAjCAAAUQAAAKYPAABUAAAAmQQAAIAAAABLCQAAVwAAALESAABYAAAA2gQAAIAAAABvCQAAXQAAACMUAABUAAAARQUAAIAAAABUCgAAagAAAIwUAABqAAAArwUAAIAAAAB2CQAAfAAAAE4QAAB8AAAA0gIAAIAAAABjBwAAkQAAAJAHAACSAAAAAAAAAAEAAAABAAAABQAAAA0AAAAdAAAAPQAAAH0AAAD9AAAA/QEAAP0DAAD9BwAA/Q8AAP0fAAD9PwAA/X8AAP3/AAD9/wEA/f8DAP3/BwD9/w8A/f8fAP3/PwD9/38A/f//AP3//wH9//8D/f//B/3//w/9//8f/f//P/3//38AAAAAAQAAAAIAAAADAAAABAAAAAUAAAAGAAAABwAAAAgAAAAJAAAACgAAAAsAAAAMAAAADQAAAA4AAAAPAAAAEAAAABEAAAASAAAAEwAAABQAAAAVAAAAFgAAABcAAAAYAAAAGQAAABoAAAAbAAAAHAAAAB0AAAAeAAAAHwAAAAMAAAAEAAAABQAAAAYAAAAHAAAACAAAAAkAAAAKAAAACwAAAAwAAAANAAAADgAAAA8AAAAQAAAAEQAAABIAAAATAAAAFAAAABUAAAAWAAAAFwAAABgAAAAZAAAAGgAAABsAAAAcAAAAHQAAAB4AAAAfAAAAIAAAACEAAAAiAAAAIwAAACUAAAAnAAAAKQAAACsAAAAvAAAAMwAAADsAAABDAAAAUwAAAGMAAACDAAAAAwEAAAMCAAADBAAAAwgAAAMQAAADIAAAA0AAAAOAAAADAAEAQeAPC1EBAAAAAQAAAAEAAAABAAAAAgAAAAIAAAADAAAAAwAAAAQAAAAEAAAABQAAAAcAAAAIAAAACQAAAAoAAAALAAAADAAAAA0AAAAOAAAADwAAABAAQcQQC4sBAQAAAAIAAAADAAAABAAAAAUAAAAGAAAABwAAAAgAAAAJAAAACgAAAAsAAAAMAAAADQAAAA4AAAAPAAAAEAAAABIAAAAUAAAAFgAAABgAAAAcAAAAIAAAACgAAAAwAAAAQAAAAIAAAAAAAQAAAAIAAAAEAAAACAAAABAAAAAgAAAAQAAAAIAAAAAAAQBBkBIL5gQBAAAAAQAAAAEAAAABAAAAAgAAAAIAAAADAAAAAwAAAAQAAAAGAAAABwAAAAgAAAAJAAAACgAAAAsAAAAMAAAADQAAAA4AAAAPAAAAEAAAAAEAAAAEAAAACAAAAAAAAAABAAEBBgAAAAAAAAQAAAAAEAAABAAAAAAgAAAFAQAAAAAAAAUDAAAAAAAABQQAAAAAAAAFBgAAAAAAAAUHAAAAAAAABQkAAAAAAAAFCgAAAAAAAAUMAAAAAAAABg4AAAAAAAEFEAAAAAAAAQUUAAAAAAABBRYAAAAAAAIFHAAAAAAAAwUgAAAAAAAEBTAAAAAgAAYFQAAAAAAABwWAAAAAAAAIBgABAAAAAAoGAAQAAAAADAYAEAAAIAAABAAAAAAAAAAEAQAAAAAAAAUCAAAAIAAABQQAAAAAAAAFBQAAACAAAAUHAAAAAAAABQgAAAAgAAAFCgAAAAAAAAULAAAAAAAABg0AAAAgAAEFEAAAAAAAAQUSAAAAIAABBRYAAAAAAAIFGAAAACAAAwUgAAAAAAADBSgAAAAAAAYEQAAAABAABgRAAAAAIAAHBYAAAAAAAAkGAAIAAAAACwYACAAAMAAABAAAAAAQAAAEAQAAACAAAAUCAAAAIAAABQMAAAAgAAAFBQAAACAAAAUGAAAAIAAABQgAAAAgAAAFCQAAACAAAAULAAAAIAAABQwAAAAAAAAGDwAAACAAAQUSAAAAIAABBRQAAAAgAAIFGAAAACAAAgUcAAAAIAADBSgAAAAgAAQFMAAAAAAAEAYAAAEAAAAPBgCAAAAAAA4GAEAAAAAADQYAIABBgBcLhwIBAAEBBQAAAAAAAAUAAAAAAAAGBD0AAAAAAAkF/QEAAAAADwX9fwAAAAAVBf3/HwAAAAMFBQAAAAAABwR9AAAAAAAMBf0PAAAAABIF/f8DAAAAFwX9/38AAAAFBR0AAAAAAAgE/QAAAAAADgX9PwAAAAAUBf3/DwAAAAIFAQAAABAABwR9AAAAAAALBf0HAAAAABEF/f8BAAAAFgX9/z8AAAAEBQ0AAAAQAAgE/QAAAAAADQX9HwAAAAATBf3/BwAAAAEFAQAAABAABgQ9AAAAAAAKBf0DAAAAABAF/f8AAAAAHAX9//8PAAAbBf3//wcAABoF/f//AwAAGQX9//8BAAAYBf3//wBBkBkLhgQBAAEBBgAAAAAAAAYDAAAAAAAABAQAAAAgAAAFBQAAAAAAAAUGAAAAAAAABQgAAAAAAAAFCQAAAAAAAAULAAAAAAAABg0AAAAAAAAGEAAAAAAAAAYTAAAAAAAABhYAAAAAAAAGGQAAAAAAAAYcAAAAAAAABh8AAAAAAAAGIgAAAAAAAQYlAAAAAAABBikAAAAAAAIGLwAAAAAAAwY7AAAAAAAEBlMAAAAAAAcGgwAAAAAACQYDAgAAEAAABAQAAAAAAAAEBQAAACAAAAUGAAAAAAAABQcAAAAgAAAFCQAAAAAAAAUKAAAAAAAABgwAAAAAAAAGDwAAAAAAAAYSAAAAAAAABhUAAAAAAAAGGAAAAAAAAAYbAAAAAAAABh4AAAAAAAAGIQAAAAAAAQYjAAAAAAABBicAAAAAAAIGKwAAAAAAAwYzAAAAAAAEBkMAAAAAAAUGYwAAAAAACAYDAQAAIAAABAQAAAAwAAAEBAAAABAAAAQFAAAAIAAABQcAAAAgAAAFCAAAACAAAAUKAAAAIAAABQsAAAAAAAAGDgAAAAAAAAYRAAAAAAAABhQAAAAAAAAGFwAAAAAAAAYaAAAAAAAABh0AAAAAAAAGIAAAAAAAEAYDAAEAAAAPBgOAAAAAAA4GA0AAAAAADQYDIAAAAAAMBgMQAAAAAAsGAwgAAAAACgYDBABBpB0L2QEBAAAAAwAAAAcAAAAPAAAAHwAAAD8AAAB/AAAA/wAAAP8BAAD/AwAA/wcAAP8PAAD/HwAA/z8AAP9/AAD//wAA//8BAP//AwD//wcA//8PAP//HwD//z8A//9/AP///wD///8B////A////wf///8P////H////z////9/AAAAAAEAAAACAAAABAAAAAAAAAACAAAABAAAAAgAAAAAAAAAAQAAAAIAAAABAAAABAAAAAQAAAAEAAAABAAAAAgAAAAIAAAACAAAAAcAAAAIAAAACQAAAAoAAAALAEGgIAsDwBBQ", En, Cn, vn = 0, Bn, bn, yn, In, xn, Qn, Ln, Mn, Sn, Dn, kn, Tn, Rn, Fn, Un, On, Pn, Gn, Nn, jn, Hn, qn, Vn, zn, Yn, Kn, Wn, Jn, Xn, Zn, $n, ei, ni, ii, ai = function(e) {
|
|
var t2 = this;
|
|
this.object = e, this.object.rotation.reorder("YXZ"), this.enabled = true, this.deviceOrientation = {}, this.screenOrientation = 0, this.alphaOffset = 0;
|
|
var n2, i2, r2, o2, s2 = function(e2) {
|
|
t2.deviceOrientation = e2;
|
|
}, a2 = function() {
|
|
t2.screenOrientation = window.orientation || 0;
|
|
}, A2 = (n2 = new THREE.Vector3(0, 0, 1), i2 = new THREE.Euler, r2 = new THREE.Quaternion, o2 = new THREE.Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5)), function(e2, t3, s3, a3, A3) {
|
|
i2.set(s3, t3, -a3, "YXZ"), e2.setFromEuler(i2), e2.multiply(o2), e2.multiply(r2.setFromAxisAngle(n2, -A3));
|
|
});
|
|
this.connect = function() {
|
|
a2(), window.addEventListener("orientationchange", a2, false), window.addEventListener("deviceorientation", s2, false), t2.enabled = true;
|
|
}, this.disconnect = function() {
|
|
window.removeEventListener("orientationchange", a2, false), window.removeEventListener("deviceorientation", s2, false), t2.enabled = false;
|
|
}, this.update = function() {
|
|
if (t2.enabled !== false) {
|
|
var e2 = t2.deviceOrientation;
|
|
if (e2) {
|
|
var n3 = e2.alpha ? THREE.MathUtils.degToRad(e2.alpha) + t2.alphaOffset : 0, i3 = e2.beta ? THREE.MathUtils.degToRad(e2.beta) : 0, r3 = e2.gamma ? THREE.MathUtils.degToRad(e2.gamma) : 0, o3 = t2.screenOrientation ? THREE.MathUtils.degToRad(t2.screenOrientation) : 0;
|
|
A2(t2.object.quaternion, n3, i3, r3, o3);
|
|
}
|
|
}
|
|
}, this.dispose = function() {
|
|
t2.disconnect();
|
|
}, this.connect();
|
|
}, Ai, li, ci, hi = "aframe-injected", di, ui, gi, pi, fi, mi, Ei, Ci, vi = false, Bi = false, bi, yi, Ii, Li, Mi, Si, ji, _i, Hi, Ki, Wi, Ji, Xi, or, cr, fr, mr, br, Qr, Dr, kr, Tr, Fr, jr, Jr, Xr, $r, eo, to, no, lo, co, ho, go, po, fo, mo, Eo, Co, vo = "loading-screen", bo, yo, Io, wo, xo, Oo = function(e, t2) {
|
|
return (e !== "audio" || typeof t2 == "string") && !(e === "array" && !Array.isArray(t2)) && (e !== "asset" || typeof t2 == "string") && (e !== "boolean" || typeof t2 == "boolean") && (e !== "color" || typeof t2 == "string") && (e !== "int" || typeof t2 == "number") && (e !== "number" || typeof t2 == "number") && (e !== "map" || typeof t2 == "string") && (e !== "model" || typeof t2 == "string") && (e !== "selector" || typeof t2 == "string" || t2 === null) && (e !== "selectorAll" || typeof t2 == "string" || t2 === null) && (e !== "src" || typeof t2 == "string") && (e !== "string" || typeof t2 == "string") && (e !== "time" || typeof t2 == "number") && (e === "vec2" ? Uo(t2, 2) : e === "vec3" ? Uo(t2, 3) : e !== "vec4" || Uo(t2, 4));
|
|
}, Po, Go, Ho, qo, Ko, Wo, Jo, Xo, Zo, $o, es, ts, ns, is, rs, os, ss, as, As = function(e, t2, n2) {
|
|
var i2 = this;
|
|
if (this.sceneOnly && !e.isScene)
|
|
throw new Error("Component `" + this.name + "` can only be applied to <a-scene>");
|
|
if (n2 && !this.multiple)
|
|
throw new Error("Trying to initialize multiple components of type `" + this.name + "`. There can only be one component of this type per entity.");
|
|
this.el = e, this.id = n2, this.attrName = this.name + (n2 ? "__" + n2 : ""), this.evtDetail = { id: this.id, name: this.name }, this.initialized = false, this.el.components[this.attrName] = this, this.objectPool = rs[this.name];
|
|
var r2 = this.events;
|
|
this.events = {}, function(e2, t3) {
|
|
var n3;
|
|
for (n3 in t3)
|
|
e2.events[n3] = t3[n3].bind(e2);
|
|
}(this, r2), this.attrValue = undefined, this.isObjectBased ? (this.data = this.objectPool.use(), Yi(this.data, this.schema), this.oldData = this.objectPool.use(), Yi(this.oldData, this.schema), this.attrValueProxy = new Proxy(this, as)) : (this.data = undefined, this.oldData = undefined, this.attrValueProxy = undefined), this.deferUnknownPropertyWarnings = !!this.updateSchema, this.throttledEmitComponentChanged = Yr(function() {
|
|
e.emit("componentchanged", i2.evtDetail, false);
|
|
}, 200), this.updateProperties(t2, true);
|
|
}, ls, us = false, ps, fs, ms = function(e) {
|
|
var t2 = f && Ko[this.name];
|
|
this.el = e, this.sceneEl = e, t2 && (t2.Component.prototype.system = this), this.buildData(), this.init(), this.update({});
|
|
}, Cs, vs, bs, ys, Is, ws = "__", xs, Qs, Ls, ks, Ts, Rs, Fs, Us, Ns, js, _s, Hs = function() {}, Vs, zs, Ys, Ks, Ws, Js, $s, ea, ta, na = function() {}, ra, oa, Aa, la, ca = "1.7.0", ha, da, ua, ga, pa, fa = "color", ma = "rotation", Ea = "components", xa, Qa, La, Ma, Sa, Da = "click", ka = "mouseup", Ta = "cursor-fusing", Ra = "cursor-hovering", Fa = "cursor-hovered", Ua, Oa, Pa = "a-mouse-cursor-hover", Ga, Na, ja, _a, Ha, qa, Va, za, Ya = "Point", Ka = "Fist", Wa = "Thumb Up", Ja, Za = "hp-mixed-reality", $a, eA, tA, nA, rA, oA, sA, aA, AA, lA, cA, hA, dA, uA, gA, pA, fA, mA, CA = "logitech-mx-ink", vA, BA, bA, yA, IA, xA, QA, LA, MA, SA, DA = "oculus-touch", kA, TA, RA, FA = "oculus-touch", UA, OA, GA, NA, jA = "oculus-go", _A, HA, qA, VA, zA, YA = "raycaster-intersected-cleared", KA = "raycaster-intersection-cleared", JA, XA, ZA, $A, el, tl, nl, il, rl, ol, sl, al, Al, ll, cl, hl = "roboto", dl, ul, gl, pl, ml, El, Cl, vl, Bl = "valve", bl, yl, Il, wl, xl = "htc-vive", Ql, Ll = "htc-vive-focus", Ml, Sl, Dl = 0.00001, kl, Tl, Rl, Fl, Ul, Ol, Pl, Gl, Nl = "windows-mixed-reality", jl, ql = "a-dialog-buttons-container", Vl = "a-dialog-button", Yl, Kl, Wl, Jl, Xl, Zl, $l, ec = "a-hidden", tc, nc = "a-hidden", rc, oc, sc, ac, Ac, lc, cc, hc, dc, uc, gc, Ec = "data-aframe-default-camera", vc = "data-aframe-default-light", Bc, bc, yc, Ic, wc, Mc, Sc, Dc, Rc, Fc, Uc, Oc, Gc, Nc, jc, _c, Hc, qc, Vc;
|
|
var init_aframe_master_module_min = __esm(() => {
|
|
init_three_module();
|
|
t = { 8167: (e) => {
|
|
var t2 = Object.prototype.toString;
|
|
e.exports = function(e2) {
|
|
return e2.BYTES_PER_ELEMENT && t2.call(e2.buffer) === "[object ArrayBuffer]" || Array.isArray(e2);
|
|
};
|
|
}, 5734: (e) => {
|
|
e.exports = function(e2, t2) {
|
|
return typeof e2 == "number" ? e2 : typeof t2 == "number" ? t2 : 0;
|
|
};
|
|
}, 7961: (e, t2) => {
|
|
t2.byteLength = function(e2) {
|
|
var t3 = a(e2), n2 = t3[0], i2 = t3[1];
|
|
return 3 * (n2 + i2) / 4 - i2;
|
|
}, t2.toByteArray = function(e2) {
|
|
var t3, n2, o2 = a(e2), s2 = o2[0], A2 = o2[1], l = new r(function(e3, t4, n3) {
|
|
return 3 * (t4 + n3) / 4 - n3;
|
|
}(0, s2, A2)), c = 0, h = A2 > 0 ? s2 - 4 : s2;
|
|
for (n2 = 0;n2 < h; n2 += 4)
|
|
t3 = i[e2.charCodeAt(n2)] << 18 | i[e2.charCodeAt(n2 + 1)] << 12 | i[e2.charCodeAt(n2 + 2)] << 6 | i[e2.charCodeAt(n2 + 3)], l[c++] = t3 >> 16 & 255, l[c++] = t3 >> 8 & 255, l[c++] = 255 & t3;
|
|
return A2 === 2 && (t3 = i[e2.charCodeAt(n2)] << 2 | i[e2.charCodeAt(n2 + 1)] >> 4, l[c++] = 255 & t3), A2 === 1 && (t3 = i[e2.charCodeAt(n2)] << 10 | i[e2.charCodeAt(n2 + 1)] << 4 | i[e2.charCodeAt(n2 + 2)] >> 2, l[c++] = t3 >> 8 & 255, l[c++] = 255 & t3), l;
|
|
}, t2.fromByteArray = function(e2) {
|
|
for (var t3, i2 = e2.length, r2 = i2 % 3, o2 = [], s2 = 16383, a2 = 0, l = i2 - r2;a2 < l; a2 += s2)
|
|
o2.push(A(e2, a2, a2 + s2 > l ? l : a2 + s2));
|
|
return r2 === 1 ? (t3 = e2[i2 - 1], o2.push(n[t3 >> 2] + n[t3 << 4 & 63] + "==")) : r2 === 2 && (t3 = (e2[i2 - 2] << 8) + e2[i2 - 1], o2.push(n[t3 >> 10] + n[t3 >> 4 & 63] + n[t3 << 2 & 63] + "=")), o2.join("");
|
|
};
|
|
for (var n = [], i = [], r = typeof Uint8Array != "undefined" ? Uint8Array : Array, o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", s = 0;s < 64; ++s)
|
|
n[s] = o[s], i[o.charCodeAt(s)] = s;
|
|
function a(e2) {
|
|
var t3 = e2.length;
|
|
if (t3 % 4 > 0)
|
|
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
var n2 = e2.indexOf("=");
|
|
return n2 === -1 && (n2 = t3), [n2, n2 === t3 ? 0 : 4 - n2 % 4];
|
|
}
|
|
function A(e2, t3, i2) {
|
|
for (var r2, o2, s2 = [], a2 = t3;a2 < i2; a2 += 3)
|
|
r2 = (e2[a2] << 16 & 16711680) + (e2[a2 + 1] << 8 & 65280) + (255 & e2[a2 + 2]), s2.push(n[(o2 = r2) >> 18 & 63] + n[o2 >> 12 & 63] + n[o2 >> 6 & 63] + n[63 & o2]);
|
|
return s2.join("");
|
|
}
|
|
i[45] = 62, i[95] = 63;
|
|
}, 911: (e, t2, n) => {
|
|
var i = n(9922).hp;
|
|
e.exports = function(e2, t3) {
|
|
if (i.isBuffer(e2) && i.isBuffer(t3)) {
|
|
if (typeof e2.equals == "function")
|
|
return e2.equals(t3);
|
|
if (e2.length !== t3.length)
|
|
return false;
|
|
for (var n2 = 0;n2 < e2.length; n2++)
|
|
if (e2[n2] !== t3[n2])
|
|
return false;
|
|
return true;
|
|
}
|
|
};
|
|
}, 9922: (e, t2, n) => {
|
|
const i = n(7961), r = n(1024), o = typeof Symbol == "function" && typeof Symbol.for == "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
|
|
t2.hp = A, t2.IS = 50;
|
|
const s = 2147483647;
|
|
function a(e2) {
|
|
if (e2 > s)
|
|
throw new RangeError('The value "' + e2 + '" is invalid for option "size"');
|
|
const t3 = new Uint8Array(e2);
|
|
return Object.setPrototypeOf(t3, A.prototype), t3;
|
|
}
|
|
function A(e2, t3, n2) {
|
|
if (typeof e2 == "number") {
|
|
if (typeof t3 == "string")
|
|
throw new TypeError('The "string" argument must be of type string. Received type number');
|
|
return h(e2);
|
|
}
|
|
return l(e2, t3, n2);
|
|
}
|
|
function l(e2, t3, n2) {
|
|
if (typeof e2 == "string")
|
|
return function(e3, t4) {
|
|
if (typeof t4 == "string" && t4 !== "" || (t4 = "utf8"), !A.isEncoding(t4))
|
|
throw new TypeError("Unknown encoding: " + t4);
|
|
const n3 = 0 | p(e3, t4);
|
|
let i3 = a(n3);
|
|
const r3 = i3.write(e3, t4);
|
|
return r3 !== n3 && (i3 = i3.slice(0, r3)), i3;
|
|
}(e2, t3);
|
|
if (ArrayBuffer.isView(e2))
|
|
return function(e3) {
|
|
if (W(e3, Uint8Array)) {
|
|
const t4 = new Uint8Array(e3);
|
|
return u(t4.buffer, t4.byteOffset, t4.byteLength);
|
|
}
|
|
return d(e3);
|
|
}(e2);
|
|
if (e2 == null)
|
|
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof e2);
|
|
if (W(e2, ArrayBuffer) || e2 && W(e2.buffer, ArrayBuffer))
|
|
return u(e2, t3, n2);
|
|
if (typeof SharedArrayBuffer != "undefined" && (W(e2, SharedArrayBuffer) || e2 && W(e2.buffer, SharedArrayBuffer)))
|
|
return u(e2, t3, n2);
|
|
if (typeof e2 == "number")
|
|
throw new TypeError('The "value" argument must not be of type number. Received type number');
|
|
const i2 = e2.valueOf && e2.valueOf();
|
|
if (i2 != null && i2 !== e2)
|
|
return A.from(i2, t3, n2);
|
|
const r2 = function(e3) {
|
|
if (A.isBuffer(e3)) {
|
|
const t4 = 0 | g(e3.length), n3 = a(t4);
|
|
return n3.length === 0 || e3.copy(n3, 0, 0, t4), n3;
|
|
}
|
|
return e3.length !== undefined ? typeof e3.length != "number" || J(e3.length) ? a(0) : d(e3) : e3.type === "Buffer" && Array.isArray(e3.data) ? d(e3.data) : undefined;
|
|
}(e2);
|
|
if (r2)
|
|
return r2;
|
|
if (typeof Symbol != "undefined" && Symbol.toPrimitive != null && typeof e2[Symbol.toPrimitive] == "function")
|
|
return A.from(e2[Symbol.toPrimitive]("string"), t3, n2);
|
|
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof e2);
|
|
}
|
|
function c(e2) {
|
|
if (typeof e2 != "number")
|
|
throw new TypeError('"size" argument must be of type number');
|
|
if (e2 < 0)
|
|
throw new RangeError('The value "' + e2 + '" is invalid for option "size"');
|
|
}
|
|
function h(e2) {
|
|
return c(e2), a(e2 < 0 ? 0 : 0 | g(e2));
|
|
}
|
|
function d(e2) {
|
|
const t3 = e2.length < 0 ? 0 : 0 | g(e2.length), n2 = a(t3);
|
|
for (let i2 = 0;i2 < t3; i2 += 1)
|
|
n2[i2] = 255 & e2[i2];
|
|
return n2;
|
|
}
|
|
function u(e2, t3, n2) {
|
|
if (t3 < 0 || e2.byteLength < t3)
|
|
throw new RangeError('"offset" is outside of buffer bounds');
|
|
if (e2.byteLength < t3 + (n2 || 0))
|
|
throw new RangeError('"length" is outside of buffer bounds');
|
|
let i2;
|
|
return i2 = t3 === undefined && n2 === undefined ? new Uint8Array(e2) : n2 === undefined ? new Uint8Array(e2, t3) : new Uint8Array(e2, t3, n2), Object.setPrototypeOf(i2, A.prototype), i2;
|
|
}
|
|
function g(e2) {
|
|
if (e2 >= s)
|
|
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + s.toString(16) + " bytes");
|
|
return 0 | e2;
|
|
}
|
|
function p(e2, t3) {
|
|
if (A.isBuffer(e2))
|
|
return e2.length;
|
|
if (ArrayBuffer.isView(e2) || W(e2, ArrayBuffer))
|
|
return e2.byteLength;
|
|
if (typeof e2 != "string")
|
|
throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof e2);
|
|
const n2 = e2.length, i2 = arguments.length > 2 && arguments[2] === true;
|
|
if (!i2 && n2 === 0)
|
|
return 0;
|
|
let r2 = false;
|
|
for (;; )
|
|
switch (t3) {
|
|
case "ascii":
|
|
case "latin1":
|
|
case "binary":
|
|
return n2;
|
|
case "utf8":
|
|
case "utf-8":
|
|
return z(e2).length;
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
return 2 * n2;
|
|
case "hex":
|
|
return n2 >>> 1;
|
|
case "base64":
|
|
return Y(e2).length;
|
|
default:
|
|
if (r2)
|
|
return i2 ? -1 : z(e2).length;
|
|
t3 = ("" + t3).toLowerCase(), r2 = true;
|
|
}
|
|
}
|
|
function f(e2, t3, n2) {
|
|
let i2 = false;
|
|
if ((t3 === undefined || t3 < 0) && (t3 = 0), t3 > this.length)
|
|
return "";
|
|
if ((n2 === undefined || n2 > this.length) && (n2 = this.length), n2 <= 0)
|
|
return "";
|
|
if ((n2 >>>= 0) <= (t3 >>>= 0))
|
|
return "";
|
|
for (e2 || (e2 = "utf8");; )
|
|
switch (e2) {
|
|
case "hex":
|
|
return S(this, t3, n2);
|
|
case "utf8":
|
|
case "utf-8":
|
|
return x(this, t3, n2);
|
|
case "ascii":
|
|
return L(this, t3, n2);
|
|
case "latin1":
|
|
case "binary":
|
|
return M(this, t3, n2);
|
|
case "base64":
|
|
return w(this, t3, n2);
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
return D(this, t3, n2);
|
|
default:
|
|
if (i2)
|
|
throw new TypeError("Unknown encoding: " + e2);
|
|
e2 = (e2 + "").toLowerCase(), i2 = true;
|
|
}
|
|
}
|
|
function m(e2, t3, n2) {
|
|
const i2 = e2[t3];
|
|
e2[t3] = e2[n2], e2[n2] = i2;
|
|
}
|
|
function E(e2, t3, n2, i2, r2) {
|
|
if (e2.length === 0)
|
|
return -1;
|
|
if (typeof n2 == "string" ? (i2 = n2, n2 = 0) : n2 > 2147483647 ? n2 = 2147483647 : n2 < -2147483648 && (n2 = -2147483648), J(n2 = +n2) && (n2 = r2 ? 0 : e2.length - 1), n2 < 0 && (n2 = e2.length + n2), n2 >= e2.length) {
|
|
if (r2)
|
|
return -1;
|
|
n2 = e2.length - 1;
|
|
} else if (n2 < 0) {
|
|
if (!r2)
|
|
return -1;
|
|
n2 = 0;
|
|
}
|
|
if (typeof t3 == "string" && (t3 = A.from(t3, i2)), A.isBuffer(t3))
|
|
return t3.length === 0 ? -1 : C(e2, t3, n2, i2, r2);
|
|
if (typeof t3 == "number")
|
|
return t3 &= 255, typeof Uint8Array.prototype.indexOf == "function" ? r2 ? Uint8Array.prototype.indexOf.call(e2, t3, n2) : Uint8Array.prototype.lastIndexOf.call(e2, t3, n2) : C(e2, [t3], n2, i2, r2);
|
|
throw new TypeError("val must be string, number or Buffer");
|
|
}
|
|
function C(e2, t3, n2, i2, r2) {
|
|
let o2, s2 = 1, a2 = e2.length, A2 = t3.length;
|
|
if (i2 !== undefined && ((i2 = String(i2).toLowerCase()) === "ucs2" || i2 === "ucs-2" || i2 === "utf16le" || i2 === "utf-16le")) {
|
|
if (e2.length < 2 || t3.length < 2)
|
|
return -1;
|
|
s2 = 2, a2 /= 2, A2 /= 2, n2 /= 2;
|
|
}
|
|
function l2(e3, t4) {
|
|
return s2 === 1 ? e3[t4] : e3.readUInt16BE(t4 * s2);
|
|
}
|
|
if (r2) {
|
|
let i3 = -1;
|
|
for (o2 = n2;o2 < a2; o2++)
|
|
if (l2(e2, o2) === l2(t3, i3 === -1 ? 0 : o2 - i3)) {
|
|
if (i3 === -1 && (i3 = o2), o2 - i3 + 1 === A2)
|
|
return i3 * s2;
|
|
} else
|
|
i3 !== -1 && (o2 -= o2 - i3), i3 = -1;
|
|
} else
|
|
for (n2 + A2 > a2 && (n2 = a2 - A2), o2 = n2;o2 >= 0; o2--) {
|
|
let n3 = true;
|
|
for (let i3 = 0;i3 < A2; i3++)
|
|
if (l2(e2, o2 + i3) !== l2(t3, i3)) {
|
|
n3 = false;
|
|
break;
|
|
}
|
|
if (n3)
|
|
return o2;
|
|
}
|
|
return -1;
|
|
}
|
|
function v(e2, t3, n2, i2) {
|
|
n2 = Number(n2) || 0;
|
|
const r2 = e2.length - n2;
|
|
i2 ? (i2 = Number(i2)) > r2 && (i2 = r2) : i2 = r2;
|
|
const o2 = t3.length;
|
|
let s2;
|
|
for (i2 > o2 / 2 && (i2 = o2 / 2), s2 = 0;s2 < i2; ++s2) {
|
|
const i3 = parseInt(t3.substr(2 * s2, 2), 16);
|
|
if (J(i3))
|
|
return s2;
|
|
e2[n2 + s2] = i3;
|
|
}
|
|
return s2;
|
|
}
|
|
function B(e2, t3, n2, i2) {
|
|
return K(z(t3, e2.length - n2), e2, n2, i2);
|
|
}
|
|
function b(e2, t3, n2, i2) {
|
|
return K(function(e3) {
|
|
const t4 = [];
|
|
for (let n3 = 0;n3 < e3.length; ++n3)
|
|
t4.push(255 & e3.charCodeAt(n3));
|
|
return t4;
|
|
}(t3), e2, n2, i2);
|
|
}
|
|
function y(e2, t3, n2, i2) {
|
|
return K(Y(t3), e2, n2, i2);
|
|
}
|
|
function I(e2, t3, n2, i2) {
|
|
return K(function(e3, t4) {
|
|
let n3, i3, r2;
|
|
const o2 = [];
|
|
for (let s2 = 0;s2 < e3.length && !((t4 -= 2) < 0); ++s2)
|
|
n3 = e3.charCodeAt(s2), i3 = n3 >> 8, r2 = n3 % 256, o2.push(r2), o2.push(i3);
|
|
return o2;
|
|
}(t3, e2.length - n2), e2, n2, i2);
|
|
}
|
|
function w(e2, t3, n2) {
|
|
return t3 === 0 && n2 === e2.length ? i.fromByteArray(e2) : i.fromByteArray(e2.slice(t3, n2));
|
|
}
|
|
function x(e2, t3, n2) {
|
|
n2 = Math.min(e2.length, n2);
|
|
const i2 = [];
|
|
let r2 = t3;
|
|
for (;r2 < n2; ) {
|
|
const t4 = e2[r2];
|
|
let o2 = null, s2 = t4 > 239 ? 4 : t4 > 223 ? 3 : t4 > 191 ? 2 : 1;
|
|
if (r2 + s2 <= n2) {
|
|
let n3, i3, a2, A2;
|
|
switch (s2) {
|
|
case 1:
|
|
t4 < 128 && (o2 = t4);
|
|
break;
|
|
case 2:
|
|
n3 = e2[r2 + 1], (192 & n3) == 128 && (A2 = (31 & t4) << 6 | 63 & n3, A2 > 127 && (o2 = A2));
|
|
break;
|
|
case 3:
|
|
n3 = e2[r2 + 1], i3 = e2[r2 + 2], (192 & n3) == 128 && (192 & i3) == 128 && (A2 = (15 & t4) << 12 | (63 & n3) << 6 | 63 & i3, A2 > 2047 && (A2 < 55296 || A2 > 57343) && (o2 = A2));
|
|
break;
|
|
case 4:
|
|
n3 = e2[r2 + 1], i3 = e2[r2 + 2], a2 = e2[r2 + 3], (192 & n3) == 128 && (192 & i3) == 128 && (192 & a2) == 128 && (A2 = (15 & t4) << 18 | (63 & n3) << 12 | (63 & i3) << 6 | 63 & a2, A2 > 65535 && A2 < 1114112 && (o2 = A2));
|
|
}
|
|
}
|
|
o2 === null ? (o2 = 65533, s2 = 1) : o2 > 65535 && (o2 -= 65536, i2.push(o2 >>> 10 & 1023 | 55296), o2 = 56320 | 1023 & o2), i2.push(o2), r2 += s2;
|
|
}
|
|
return function(e3) {
|
|
const t4 = e3.length;
|
|
if (t4 <= Q)
|
|
return String.fromCharCode.apply(String, e3);
|
|
let n3 = "", i3 = 0;
|
|
for (;i3 < t4; )
|
|
n3 += String.fromCharCode.apply(String, e3.slice(i3, i3 += Q));
|
|
return n3;
|
|
}(i2);
|
|
}
|
|
A.TYPED_ARRAY_SUPPORT = function() {
|
|
try {
|
|
const e2 = new Uint8Array(1), t3 = { foo: function() {
|
|
return 42;
|
|
} };
|
|
return Object.setPrototypeOf(t3, Uint8Array.prototype), Object.setPrototypeOf(e2, t3), e2.foo() === 42;
|
|
} catch (e2) {
|
|
return false;
|
|
}
|
|
}(), A.TYPED_ARRAY_SUPPORT || typeof console == "undefined" || typeof console.error != "function" || console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."), Object.defineProperty(A.prototype, "parent", { enumerable: true, get: function() {
|
|
if (A.isBuffer(this))
|
|
return this.buffer;
|
|
} }), Object.defineProperty(A.prototype, "offset", { enumerable: true, get: function() {
|
|
if (A.isBuffer(this))
|
|
return this.byteOffset;
|
|
} }), A.poolSize = 8192, A.from = function(e2, t3, n2) {
|
|
return l(e2, t3, n2);
|
|
}, Object.setPrototypeOf(A.prototype, Uint8Array.prototype), Object.setPrototypeOf(A, Uint8Array), A.alloc = function(e2, t3, n2) {
|
|
return function(e3, t4, n3) {
|
|
return c(e3), e3 <= 0 ? a(e3) : t4 !== undefined ? typeof n3 == "string" ? a(e3).fill(t4, n3) : a(e3).fill(t4) : a(e3);
|
|
}(e2, t3, n2);
|
|
}, A.allocUnsafe = function(e2) {
|
|
return h(e2);
|
|
}, A.allocUnsafeSlow = function(e2) {
|
|
return h(e2);
|
|
}, A.isBuffer = function(e2) {
|
|
return e2 != null && e2._isBuffer === true && e2 !== A.prototype;
|
|
}, A.compare = function(e2, t3) {
|
|
if (W(e2, Uint8Array) && (e2 = A.from(e2, e2.offset, e2.byteLength)), W(t3, Uint8Array) && (t3 = A.from(t3, t3.offset, t3.byteLength)), !A.isBuffer(e2) || !A.isBuffer(t3))
|
|
throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
|
|
if (e2 === t3)
|
|
return 0;
|
|
let n2 = e2.length, i2 = t3.length;
|
|
for (let r2 = 0, o2 = Math.min(n2, i2);r2 < o2; ++r2)
|
|
if (e2[r2] !== t3[r2]) {
|
|
n2 = e2[r2], i2 = t3[r2];
|
|
break;
|
|
}
|
|
return n2 < i2 ? -1 : i2 < n2 ? 1 : 0;
|
|
}, A.isEncoding = function(e2) {
|
|
switch (String(e2).toLowerCase()) {
|
|
case "hex":
|
|
case "utf8":
|
|
case "utf-8":
|
|
case "ascii":
|
|
case "latin1":
|
|
case "binary":
|
|
case "base64":
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}, A.concat = function(e2, t3) {
|
|
if (!Array.isArray(e2))
|
|
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
if (e2.length === 0)
|
|
return A.alloc(0);
|
|
let n2;
|
|
if (t3 === undefined)
|
|
for (t3 = 0, n2 = 0;n2 < e2.length; ++n2)
|
|
t3 += e2[n2].length;
|
|
const i2 = A.allocUnsafe(t3);
|
|
let r2 = 0;
|
|
for (n2 = 0;n2 < e2.length; ++n2) {
|
|
let t4 = e2[n2];
|
|
if (W(t4, Uint8Array))
|
|
r2 + t4.length > i2.length ? (A.isBuffer(t4) || (t4 = A.from(t4)), t4.copy(i2, r2)) : Uint8Array.prototype.set.call(i2, t4, r2);
|
|
else {
|
|
if (!A.isBuffer(t4))
|
|
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
t4.copy(i2, r2);
|
|
}
|
|
r2 += t4.length;
|
|
}
|
|
return i2;
|
|
}, A.byteLength = p, A.prototype._isBuffer = true, A.prototype.swap16 = function() {
|
|
const e2 = this.length;
|
|
if (e2 % 2 != 0)
|
|
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
for (let t3 = 0;t3 < e2; t3 += 2)
|
|
m(this, t3, t3 + 1);
|
|
return this;
|
|
}, A.prototype.swap32 = function() {
|
|
const e2 = this.length;
|
|
if (e2 % 4 != 0)
|
|
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
for (let t3 = 0;t3 < e2; t3 += 4)
|
|
m(this, t3, t3 + 3), m(this, t3 + 1, t3 + 2);
|
|
return this;
|
|
}, A.prototype.swap64 = function() {
|
|
const e2 = this.length;
|
|
if (e2 % 8 != 0)
|
|
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
for (let t3 = 0;t3 < e2; t3 += 8)
|
|
m(this, t3, t3 + 7), m(this, t3 + 1, t3 + 6), m(this, t3 + 2, t3 + 5), m(this, t3 + 3, t3 + 4);
|
|
return this;
|
|
}, A.prototype.toString = function() {
|
|
const e2 = this.length;
|
|
return e2 === 0 ? "" : arguments.length === 0 ? x(this, 0, e2) : f.apply(this, arguments);
|
|
}, A.prototype.toLocaleString = A.prototype.toString, A.prototype.equals = function(e2) {
|
|
if (!A.isBuffer(e2))
|
|
throw new TypeError("Argument must be a Buffer");
|
|
return this === e2 || A.compare(this, e2) === 0;
|
|
}, A.prototype.inspect = function() {
|
|
let e2 = "";
|
|
const n2 = t2.IS;
|
|
return e2 = this.toString("hex", 0, n2).replace(/(.{2})/g, "$1 ").trim(), this.length > n2 && (e2 += " ... "), "<Buffer " + e2 + ">";
|
|
}, o && (A.prototype[o] = A.prototype.inspect), A.prototype.compare = function(e2, t3, n2, i2, r2) {
|
|
if (W(e2, Uint8Array) && (e2 = A.from(e2, e2.offset, e2.byteLength)), !A.isBuffer(e2))
|
|
throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof e2);
|
|
if (t3 === undefined && (t3 = 0), n2 === undefined && (n2 = e2 ? e2.length : 0), i2 === undefined && (i2 = 0), r2 === undefined && (r2 = this.length), t3 < 0 || n2 > e2.length || i2 < 0 || r2 > this.length)
|
|
throw new RangeError("out of range index");
|
|
if (i2 >= r2 && t3 >= n2)
|
|
return 0;
|
|
if (i2 >= r2)
|
|
return -1;
|
|
if (t3 >= n2)
|
|
return 1;
|
|
if (this === e2)
|
|
return 0;
|
|
let o2 = (r2 >>>= 0) - (i2 >>>= 0), s2 = (n2 >>>= 0) - (t3 >>>= 0);
|
|
const a2 = Math.min(o2, s2), l2 = this.slice(i2, r2), c2 = e2.slice(t3, n2);
|
|
for (let e3 = 0;e3 < a2; ++e3)
|
|
if (l2[e3] !== c2[e3]) {
|
|
o2 = l2[e3], s2 = c2[e3];
|
|
break;
|
|
}
|
|
return o2 < s2 ? -1 : s2 < o2 ? 1 : 0;
|
|
}, A.prototype.includes = function(e2, t3, n2) {
|
|
return this.indexOf(e2, t3, n2) !== -1;
|
|
}, A.prototype.indexOf = function(e2, t3, n2) {
|
|
return E(this, e2, t3, n2, true);
|
|
}, A.prototype.lastIndexOf = function(e2, t3, n2) {
|
|
return E(this, e2, t3, n2, false);
|
|
}, A.prototype.write = function(e2, t3, n2, i2) {
|
|
if (t3 === undefined)
|
|
i2 = "utf8", n2 = this.length, t3 = 0;
|
|
else if (n2 === undefined && typeof t3 == "string")
|
|
i2 = t3, n2 = this.length, t3 = 0;
|
|
else {
|
|
if (!isFinite(t3))
|
|
throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
|
|
t3 >>>= 0, isFinite(n2) ? (n2 >>>= 0, i2 === undefined && (i2 = "utf8")) : (i2 = n2, n2 = undefined);
|
|
}
|
|
const r2 = this.length - t3;
|
|
if ((n2 === undefined || n2 > r2) && (n2 = r2), e2.length > 0 && (n2 < 0 || t3 < 0) || t3 > this.length)
|
|
throw new RangeError("Attempt to write outside buffer bounds");
|
|
i2 || (i2 = "utf8");
|
|
let o2 = false;
|
|
for (;; )
|
|
switch (i2) {
|
|
case "hex":
|
|
return v(this, e2, t3, n2);
|
|
case "utf8":
|
|
case "utf-8":
|
|
return B(this, e2, t3, n2);
|
|
case "ascii":
|
|
case "latin1":
|
|
case "binary":
|
|
return b(this, e2, t3, n2);
|
|
case "base64":
|
|
return y(this, e2, t3, n2);
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
return I(this, e2, t3, n2);
|
|
default:
|
|
if (o2)
|
|
throw new TypeError("Unknown encoding: " + i2);
|
|
i2 = ("" + i2).toLowerCase(), o2 = true;
|
|
}
|
|
}, A.prototype.toJSON = function() {
|
|
return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) };
|
|
};
|
|
const Q = 4096;
|
|
function L(e2, t3, n2) {
|
|
let i2 = "";
|
|
n2 = Math.min(e2.length, n2);
|
|
for (let r2 = t3;r2 < n2; ++r2)
|
|
i2 += String.fromCharCode(127 & e2[r2]);
|
|
return i2;
|
|
}
|
|
function M(e2, t3, n2) {
|
|
let i2 = "";
|
|
n2 = Math.min(e2.length, n2);
|
|
for (let r2 = t3;r2 < n2; ++r2)
|
|
i2 += String.fromCharCode(e2[r2]);
|
|
return i2;
|
|
}
|
|
function S(e2, t3, n2) {
|
|
const i2 = e2.length;
|
|
(!t3 || t3 < 0) && (t3 = 0), (!n2 || n2 < 0 || n2 > i2) && (n2 = i2);
|
|
let r2 = "";
|
|
for (let i3 = t3;i3 < n2; ++i3)
|
|
r2 += X[e2[i3]];
|
|
return r2;
|
|
}
|
|
function D(e2, t3, n2) {
|
|
const i2 = e2.slice(t3, n2);
|
|
let r2 = "";
|
|
for (let e3 = 0;e3 < i2.length - 1; e3 += 2)
|
|
r2 += String.fromCharCode(i2[e3] + 256 * i2[e3 + 1]);
|
|
return r2;
|
|
}
|
|
function k(e2, t3, n2) {
|
|
if (e2 % 1 != 0 || e2 < 0)
|
|
throw new RangeError("offset is not uint");
|
|
if (e2 + t3 > n2)
|
|
throw new RangeError("Trying to access beyond buffer length");
|
|
}
|
|
function T(e2, t3, n2, i2, r2, o2) {
|
|
if (!A.isBuffer(e2))
|
|
throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
if (t3 > r2 || t3 < o2)
|
|
throw new RangeError('"value" argument is out of bounds');
|
|
if (n2 + i2 > e2.length)
|
|
throw new RangeError("Index out of range");
|
|
}
|
|
function R(e2, t3, n2, i2, r2) {
|
|
_(t3, i2, r2, e2, n2, 7);
|
|
let o2 = Number(t3 & BigInt(4294967295));
|
|
e2[n2++] = o2, o2 >>= 8, e2[n2++] = o2, o2 >>= 8, e2[n2++] = o2, o2 >>= 8, e2[n2++] = o2;
|
|
let s2 = Number(t3 >> BigInt(32) & BigInt(4294967295));
|
|
return e2[n2++] = s2, s2 >>= 8, e2[n2++] = s2, s2 >>= 8, e2[n2++] = s2, s2 >>= 8, e2[n2++] = s2, n2;
|
|
}
|
|
function F(e2, t3, n2, i2, r2) {
|
|
_(t3, i2, r2, e2, n2, 7);
|
|
let o2 = Number(t3 & BigInt(4294967295));
|
|
e2[n2 + 7] = o2, o2 >>= 8, e2[n2 + 6] = o2, o2 >>= 8, e2[n2 + 5] = o2, o2 >>= 8, e2[n2 + 4] = o2;
|
|
let s2 = Number(t3 >> BigInt(32) & BigInt(4294967295));
|
|
return e2[n2 + 3] = s2, s2 >>= 8, e2[n2 + 2] = s2, s2 >>= 8, e2[n2 + 1] = s2, s2 >>= 8, e2[n2] = s2, n2 + 8;
|
|
}
|
|
function U(e2, t3, n2, i2, r2, o2) {
|
|
if (n2 + i2 > e2.length)
|
|
throw new RangeError("Index out of range");
|
|
if (n2 < 0)
|
|
throw new RangeError("Index out of range");
|
|
}
|
|
function O(e2, t3, n2, i2, o2) {
|
|
return t3 = +t3, n2 >>>= 0, o2 || U(e2, 0, n2, 4), r.write(e2, t3, n2, i2, 23, 4), n2 + 4;
|
|
}
|
|
function P(e2, t3, n2, i2, o2) {
|
|
return t3 = +t3, n2 >>>= 0, o2 || U(e2, 0, n2, 8), r.write(e2, t3, n2, i2, 52, 8), n2 + 8;
|
|
}
|
|
A.prototype.slice = function(e2, t3) {
|
|
const n2 = this.length;
|
|
(e2 = ~~e2) < 0 ? (e2 += n2) < 0 && (e2 = 0) : e2 > n2 && (e2 = n2), (t3 = t3 === undefined ? n2 : ~~t3) < 0 ? (t3 += n2) < 0 && (t3 = 0) : t3 > n2 && (t3 = n2), t3 < e2 && (t3 = e2);
|
|
const i2 = this.subarray(e2, t3);
|
|
return Object.setPrototypeOf(i2, A.prototype), i2;
|
|
}, A.prototype.readUintLE = A.prototype.readUIntLE = function(e2, t3, n2) {
|
|
e2 >>>= 0, t3 >>>= 0, n2 || k(e2, t3, this.length);
|
|
let i2 = this[e2], r2 = 1, o2 = 0;
|
|
for (;++o2 < t3 && (r2 *= 256); )
|
|
i2 += this[e2 + o2] * r2;
|
|
return i2;
|
|
}, A.prototype.readUintBE = A.prototype.readUIntBE = function(e2, t3, n2) {
|
|
e2 >>>= 0, t3 >>>= 0, n2 || k(e2, t3, this.length);
|
|
let i2 = this[e2 + --t3], r2 = 1;
|
|
for (;t3 > 0 && (r2 *= 256); )
|
|
i2 += this[e2 + --t3] * r2;
|
|
return i2;
|
|
}, A.prototype.readUint8 = A.prototype.readUInt8 = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 1, this.length), this[e2];
|
|
}, A.prototype.readUint16LE = A.prototype.readUInt16LE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 2, this.length), this[e2] | this[e2 + 1] << 8;
|
|
}, A.prototype.readUint16BE = A.prototype.readUInt16BE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 2, this.length), this[e2] << 8 | this[e2 + 1];
|
|
}, A.prototype.readUint32LE = A.prototype.readUInt32LE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 4, this.length), (this[e2] | this[e2 + 1] << 8 | this[e2 + 2] << 16) + 16777216 * this[e2 + 3];
|
|
}, A.prototype.readUint32BE = A.prototype.readUInt32BE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 4, this.length), 16777216 * this[e2] + (this[e2 + 1] << 16 | this[e2 + 2] << 8 | this[e2 + 3]);
|
|
}, A.prototype.readBigUInt64LE = Z(function(e2) {
|
|
H(e2 >>>= 0, "offset");
|
|
const t3 = this[e2], n2 = this[e2 + 7];
|
|
t3 !== undefined && n2 !== undefined || q(e2, this.length - 8);
|
|
const i2 = t3 + 256 * this[++e2] + 65536 * this[++e2] + this[++e2] * 2 ** 24, r2 = this[++e2] + 256 * this[++e2] + 65536 * this[++e2] + n2 * 2 ** 24;
|
|
return BigInt(i2) + (BigInt(r2) << BigInt(32));
|
|
}), A.prototype.readBigUInt64BE = Z(function(e2) {
|
|
H(e2 >>>= 0, "offset");
|
|
const t3 = this[e2], n2 = this[e2 + 7];
|
|
t3 !== undefined && n2 !== undefined || q(e2, this.length - 8);
|
|
const i2 = t3 * 2 ** 24 + 65536 * this[++e2] + 256 * this[++e2] + this[++e2], r2 = this[++e2] * 2 ** 24 + 65536 * this[++e2] + 256 * this[++e2] + n2;
|
|
return (BigInt(i2) << BigInt(32)) + BigInt(r2);
|
|
}), A.prototype.readIntLE = function(e2, t3, n2) {
|
|
e2 >>>= 0, t3 >>>= 0, n2 || k(e2, t3, this.length);
|
|
let i2 = this[e2], r2 = 1, o2 = 0;
|
|
for (;++o2 < t3 && (r2 *= 256); )
|
|
i2 += this[e2 + o2] * r2;
|
|
return r2 *= 128, i2 >= r2 && (i2 -= Math.pow(2, 8 * t3)), i2;
|
|
}, A.prototype.readIntBE = function(e2, t3, n2) {
|
|
e2 >>>= 0, t3 >>>= 0, n2 || k(e2, t3, this.length);
|
|
let i2 = t3, r2 = 1, o2 = this[e2 + --i2];
|
|
for (;i2 > 0 && (r2 *= 256); )
|
|
o2 += this[e2 + --i2] * r2;
|
|
return r2 *= 128, o2 >= r2 && (o2 -= Math.pow(2, 8 * t3)), o2;
|
|
}, A.prototype.readInt8 = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 1, this.length), 128 & this[e2] ? -1 * (255 - this[e2] + 1) : this[e2];
|
|
}, A.prototype.readInt16LE = function(e2, t3) {
|
|
e2 >>>= 0, t3 || k(e2, 2, this.length);
|
|
const n2 = this[e2] | this[e2 + 1] << 8;
|
|
return 32768 & n2 ? 4294901760 | n2 : n2;
|
|
}, A.prototype.readInt16BE = function(e2, t3) {
|
|
e2 >>>= 0, t3 || k(e2, 2, this.length);
|
|
const n2 = this[e2 + 1] | this[e2] << 8;
|
|
return 32768 & n2 ? 4294901760 | n2 : n2;
|
|
}, A.prototype.readInt32LE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 4, this.length), this[e2] | this[e2 + 1] << 8 | this[e2 + 2] << 16 | this[e2 + 3] << 24;
|
|
}, A.prototype.readInt32BE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 4, this.length), this[e2] << 24 | this[e2 + 1] << 16 | this[e2 + 2] << 8 | this[e2 + 3];
|
|
}, A.prototype.readBigInt64LE = Z(function(e2) {
|
|
H(e2 >>>= 0, "offset");
|
|
const t3 = this[e2], n2 = this[e2 + 7];
|
|
t3 !== undefined && n2 !== undefined || q(e2, this.length - 8);
|
|
const i2 = this[e2 + 4] + 256 * this[e2 + 5] + 65536 * this[e2 + 6] + (n2 << 24);
|
|
return (BigInt(i2) << BigInt(32)) + BigInt(t3 + 256 * this[++e2] + 65536 * this[++e2] + this[++e2] * 2 ** 24);
|
|
}), A.prototype.readBigInt64BE = Z(function(e2) {
|
|
H(e2 >>>= 0, "offset");
|
|
const t3 = this[e2], n2 = this[e2 + 7];
|
|
t3 !== undefined && n2 !== undefined || q(e2, this.length - 8);
|
|
const i2 = (t3 << 24) + 65536 * this[++e2] + 256 * this[++e2] + this[++e2];
|
|
return (BigInt(i2) << BigInt(32)) + BigInt(this[++e2] * 2 ** 24 + 65536 * this[++e2] + 256 * this[++e2] + n2);
|
|
}), A.prototype.readFloatLE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 4, this.length), r.read(this, e2, true, 23, 4);
|
|
}, A.prototype.readFloatBE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 4, this.length), r.read(this, e2, false, 23, 4);
|
|
}, A.prototype.readDoubleLE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 8, this.length), r.read(this, e2, true, 52, 8);
|
|
}, A.prototype.readDoubleBE = function(e2, t3) {
|
|
return e2 >>>= 0, t3 || k(e2, 8, this.length), r.read(this, e2, false, 52, 8);
|
|
}, A.prototype.writeUintLE = A.prototype.writeUIntLE = function(e2, t3, n2, i2) {
|
|
e2 = +e2, t3 >>>= 0, n2 >>>= 0, i2 || T(this, e2, t3, n2, Math.pow(2, 8 * n2) - 1, 0);
|
|
let r2 = 1, o2 = 0;
|
|
for (this[t3] = 255 & e2;++o2 < n2 && (r2 *= 256); )
|
|
this[t3 + o2] = e2 / r2 & 255;
|
|
return t3 + n2;
|
|
}, A.prototype.writeUintBE = A.prototype.writeUIntBE = function(e2, t3, n2, i2) {
|
|
e2 = +e2, t3 >>>= 0, n2 >>>= 0, i2 || T(this, e2, t3, n2, Math.pow(2, 8 * n2) - 1, 0);
|
|
let r2 = n2 - 1, o2 = 1;
|
|
for (this[t3 + r2] = 255 & e2;--r2 >= 0 && (o2 *= 256); )
|
|
this[t3 + r2] = e2 / o2 & 255;
|
|
return t3 + n2;
|
|
}, A.prototype.writeUint8 = A.prototype.writeUInt8 = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 1, 255, 0), this[t3] = 255 & e2, t3 + 1;
|
|
}, A.prototype.writeUint16LE = A.prototype.writeUInt16LE = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 2, 65535, 0), this[t3] = 255 & e2, this[t3 + 1] = e2 >>> 8, t3 + 2;
|
|
}, A.prototype.writeUint16BE = A.prototype.writeUInt16BE = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 2, 65535, 0), this[t3] = e2 >>> 8, this[t3 + 1] = 255 & e2, t3 + 2;
|
|
}, A.prototype.writeUint32LE = A.prototype.writeUInt32LE = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 4, 4294967295, 0), this[t3 + 3] = e2 >>> 24, this[t3 + 2] = e2 >>> 16, this[t3 + 1] = e2 >>> 8, this[t3] = 255 & e2, t3 + 4;
|
|
}, A.prototype.writeUint32BE = A.prototype.writeUInt32BE = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 4, 4294967295, 0), this[t3] = e2 >>> 24, this[t3 + 1] = e2 >>> 16, this[t3 + 2] = e2 >>> 8, this[t3 + 3] = 255 & e2, t3 + 4;
|
|
}, A.prototype.writeBigUInt64LE = Z(function(e2, t3 = 0) {
|
|
return R(this, e2, t3, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
}), A.prototype.writeBigUInt64BE = Z(function(e2, t3 = 0) {
|
|
return F(this, e2, t3, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
}), A.prototype.writeIntLE = function(e2, t3, n2, i2) {
|
|
if (e2 = +e2, t3 >>>= 0, !i2) {
|
|
const i3 = Math.pow(2, 8 * n2 - 1);
|
|
T(this, e2, t3, n2, i3 - 1, -i3);
|
|
}
|
|
let r2 = 0, o2 = 1, s2 = 0;
|
|
for (this[t3] = 255 & e2;++r2 < n2 && (o2 *= 256); )
|
|
e2 < 0 && s2 === 0 && this[t3 + r2 - 1] !== 0 && (s2 = 1), this[t3 + r2] = (e2 / o2 | 0) - s2 & 255;
|
|
return t3 + n2;
|
|
}, A.prototype.writeIntBE = function(e2, t3, n2, i2) {
|
|
if (e2 = +e2, t3 >>>= 0, !i2) {
|
|
const i3 = Math.pow(2, 8 * n2 - 1);
|
|
T(this, e2, t3, n2, i3 - 1, -i3);
|
|
}
|
|
let r2 = n2 - 1, o2 = 1, s2 = 0;
|
|
for (this[t3 + r2] = 255 & e2;--r2 >= 0 && (o2 *= 256); )
|
|
e2 < 0 && s2 === 0 && this[t3 + r2 + 1] !== 0 && (s2 = 1), this[t3 + r2] = (e2 / o2 | 0) - s2 & 255;
|
|
return t3 + n2;
|
|
}, A.prototype.writeInt8 = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 1, 127, -128), e2 < 0 && (e2 = 255 + e2 + 1), this[t3] = 255 & e2, t3 + 1;
|
|
}, A.prototype.writeInt16LE = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 2, 32767, -32768), this[t3] = 255 & e2, this[t3 + 1] = e2 >>> 8, t3 + 2;
|
|
}, A.prototype.writeInt16BE = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 2, 32767, -32768), this[t3] = e2 >>> 8, this[t3 + 1] = 255 & e2, t3 + 2;
|
|
}, A.prototype.writeInt32LE = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 4, 2147483647, -2147483648), this[t3] = 255 & e2, this[t3 + 1] = e2 >>> 8, this[t3 + 2] = e2 >>> 16, this[t3 + 3] = e2 >>> 24, t3 + 4;
|
|
}, A.prototype.writeInt32BE = function(e2, t3, n2) {
|
|
return e2 = +e2, t3 >>>= 0, n2 || T(this, e2, t3, 4, 2147483647, -2147483648), e2 < 0 && (e2 = 4294967295 + e2 + 1), this[t3] = e2 >>> 24, this[t3 + 1] = e2 >>> 16, this[t3 + 2] = e2 >>> 8, this[t3 + 3] = 255 & e2, t3 + 4;
|
|
}, A.prototype.writeBigInt64LE = Z(function(e2, t3 = 0) {
|
|
return R(this, e2, t3, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
}), A.prototype.writeBigInt64BE = Z(function(e2, t3 = 0) {
|
|
return F(this, e2, t3, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
}), A.prototype.writeFloatLE = function(e2, t3, n2) {
|
|
return O(this, e2, t3, true, n2);
|
|
}, A.prototype.writeFloatBE = function(e2, t3, n2) {
|
|
return O(this, e2, t3, false, n2);
|
|
}, A.prototype.writeDoubleLE = function(e2, t3, n2) {
|
|
return P(this, e2, t3, true, n2);
|
|
}, A.prototype.writeDoubleBE = function(e2, t3, n2) {
|
|
return P(this, e2, t3, false, n2);
|
|
}, A.prototype.copy = function(e2, t3, n2, i2) {
|
|
if (!A.isBuffer(e2))
|
|
throw new TypeError("argument should be a Buffer");
|
|
if (n2 || (n2 = 0), i2 || i2 === 0 || (i2 = this.length), t3 >= e2.length && (t3 = e2.length), t3 || (t3 = 0), i2 > 0 && i2 < n2 && (i2 = n2), i2 === n2)
|
|
return 0;
|
|
if (e2.length === 0 || this.length === 0)
|
|
return 0;
|
|
if (t3 < 0)
|
|
throw new RangeError("targetStart out of bounds");
|
|
if (n2 < 0 || n2 >= this.length)
|
|
throw new RangeError("Index out of range");
|
|
if (i2 < 0)
|
|
throw new RangeError("sourceEnd out of bounds");
|
|
i2 > this.length && (i2 = this.length), e2.length - t3 < i2 - n2 && (i2 = e2.length - t3 + n2);
|
|
const r2 = i2 - n2;
|
|
return this === e2 && typeof Uint8Array.prototype.copyWithin == "function" ? this.copyWithin(t3, n2, i2) : Uint8Array.prototype.set.call(e2, this.subarray(n2, i2), t3), r2;
|
|
}, A.prototype.fill = function(e2, t3, n2, i2) {
|
|
if (typeof e2 == "string") {
|
|
if (typeof t3 == "string" ? (i2 = t3, t3 = 0, n2 = this.length) : typeof n2 == "string" && (i2 = n2, n2 = this.length), i2 !== undefined && typeof i2 != "string")
|
|
throw new TypeError("encoding must be a string");
|
|
if (typeof i2 == "string" && !A.isEncoding(i2))
|
|
throw new TypeError("Unknown encoding: " + i2);
|
|
if (e2.length === 1) {
|
|
const t4 = e2.charCodeAt(0);
|
|
(i2 === "utf8" && t4 < 128 || i2 === "latin1") && (e2 = t4);
|
|
}
|
|
} else
|
|
typeof e2 == "number" ? e2 &= 255 : typeof e2 == "boolean" && (e2 = Number(e2));
|
|
if (t3 < 0 || this.length < t3 || this.length < n2)
|
|
throw new RangeError("Out of range index");
|
|
if (n2 <= t3)
|
|
return this;
|
|
let r2;
|
|
if (t3 >>>= 0, n2 = n2 === undefined ? this.length : n2 >>> 0, e2 || (e2 = 0), typeof e2 == "number")
|
|
for (r2 = t3;r2 < n2; ++r2)
|
|
this[r2] = e2;
|
|
else {
|
|
const o2 = A.isBuffer(e2) ? e2 : A.from(e2, i2), s2 = o2.length;
|
|
if (s2 === 0)
|
|
throw new TypeError('The value "' + e2 + '" is invalid for argument "value"');
|
|
for (r2 = 0;r2 < n2 - t3; ++r2)
|
|
this[r2 + t3] = o2[r2 % s2];
|
|
}
|
|
return this;
|
|
};
|
|
const G = {};
|
|
function N(e2, t3, n2) {
|
|
G[e2] = class extends n2 {
|
|
constructor() {
|
|
super(), Object.defineProperty(this, "message", { value: t3.apply(this, arguments), writable: true, configurable: true }), this.name = `${this.name} [${e2}]`, this.stack, delete this.name;
|
|
}
|
|
get code() {
|
|
return e2;
|
|
}
|
|
set code(e3) {
|
|
Object.defineProperty(this, "code", { configurable: true, enumerable: true, value: e3, writable: true });
|
|
}
|
|
toString() {
|
|
return `${this.name} [${e2}]: ${this.message}`;
|
|
}
|
|
};
|
|
}
|
|
function j(e2) {
|
|
let t3 = "", n2 = e2.length;
|
|
const i2 = e2[0] === "-" ? 1 : 0;
|
|
for (;n2 >= i2 + 4; n2 -= 3)
|
|
t3 = `_${e2.slice(n2 - 3, n2)}${t3}`;
|
|
return `${e2.slice(0, n2)}${t3}`;
|
|
}
|
|
function _(e2, t3, n2, i2, r2, o2) {
|
|
if (e2 > n2 || e2 < t3) {
|
|
const i3 = typeof t3 == "bigint" ? "n" : "";
|
|
let r3;
|
|
throw r3 = o2 > 3 ? t3 === 0 || t3 === BigInt(0) ? `>= 0${i3} and < 2${i3} ** ${8 * (o2 + 1)}${i3}` : `>= -(2${i3} ** ${8 * (o2 + 1) - 1}${i3}) and < 2 ** ${8 * (o2 + 1) - 1}${i3}` : `>= ${t3}${i3} and <= ${n2}${i3}`, new G.ERR_OUT_OF_RANGE("value", r3, e2);
|
|
}
|
|
(function(e3, t4, n3) {
|
|
H(t4, "offset"), e3[t4] !== undefined && e3[t4 + n3] !== undefined || q(t4, e3.length - (n3 + 1));
|
|
})(i2, r2, o2);
|
|
}
|
|
function H(e2, t3) {
|
|
if (typeof e2 != "number")
|
|
throw new G.ERR_INVALID_ARG_TYPE(t3, "number", e2);
|
|
}
|
|
function q(e2, t3, n2) {
|
|
if (Math.floor(e2) !== e2)
|
|
throw H(e2, n2), new G.ERR_OUT_OF_RANGE(n2 || "offset", "an integer", e2);
|
|
if (t3 < 0)
|
|
throw new G.ERR_BUFFER_OUT_OF_BOUNDS;
|
|
throw new G.ERR_OUT_OF_RANGE(n2 || "offset", `>= ${n2 ? 1 : 0} and <= ${t3}`, e2);
|
|
}
|
|
N("ERR_BUFFER_OUT_OF_BOUNDS", function(e2) {
|
|
return e2 ? `${e2} is outside of buffer bounds` : "Attempt to access memory outside buffer bounds";
|
|
}, RangeError), N("ERR_INVALID_ARG_TYPE", function(e2, t3) {
|
|
return `The "${e2}" argument must be of type number. Received type ${typeof t3}`;
|
|
}, TypeError), N("ERR_OUT_OF_RANGE", function(e2, t3, n2) {
|
|
let i2 = `The value of "${e2}" is out of range.`, r2 = n2;
|
|
return Number.isInteger(n2) && Math.abs(n2) > 2 ** 32 ? r2 = j(String(n2)) : typeof n2 == "bigint" && (r2 = String(n2), (n2 > BigInt(2) ** BigInt(32) || n2 < -(BigInt(2) ** BigInt(32))) && (r2 = j(r2)), r2 += "n"), i2 += ` It must be ${t3}. Received ${r2}`, i2;
|
|
}, RangeError);
|
|
const V = /[^+/0-9A-Za-z-_]/g;
|
|
function z(e2, t3) {
|
|
let n2;
|
|
t3 = t3 || 1 / 0;
|
|
const i2 = e2.length;
|
|
let r2 = null;
|
|
const o2 = [];
|
|
for (let s2 = 0;s2 < i2; ++s2) {
|
|
if (n2 = e2.charCodeAt(s2), n2 > 55295 && n2 < 57344) {
|
|
if (!r2) {
|
|
if (n2 > 56319) {
|
|
(t3 -= 3) > -1 && o2.push(239, 191, 189);
|
|
continue;
|
|
}
|
|
if (s2 + 1 === i2) {
|
|
(t3 -= 3) > -1 && o2.push(239, 191, 189);
|
|
continue;
|
|
}
|
|
r2 = n2;
|
|
continue;
|
|
}
|
|
if (n2 < 56320) {
|
|
(t3 -= 3) > -1 && o2.push(239, 191, 189), r2 = n2;
|
|
continue;
|
|
}
|
|
n2 = 65536 + (r2 - 55296 << 10 | n2 - 56320);
|
|
} else
|
|
r2 && (t3 -= 3) > -1 && o2.push(239, 191, 189);
|
|
if (r2 = null, n2 < 128) {
|
|
if ((t3 -= 1) < 0)
|
|
break;
|
|
o2.push(n2);
|
|
} else if (n2 < 2048) {
|
|
if ((t3 -= 2) < 0)
|
|
break;
|
|
o2.push(n2 >> 6 | 192, 63 & n2 | 128);
|
|
} else if (n2 < 65536) {
|
|
if ((t3 -= 3) < 0)
|
|
break;
|
|
o2.push(n2 >> 12 | 224, n2 >> 6 & 63 | 128, 63 & n2 | 128);
|
|
} else {
|
|
if (!(n2 < 1114112))
|
|
throw new Error("Invalid code point");
|
|
if ((t3 -= 4) < 0)
|
|
break;
|
|
o2.push(n2 >> 18 | 240, n2 >> 12 & 63 | 128, n2 >> 6 & 63 | 128, 63 & n2 | 128);
|
|
}
|
|
}
|
|
return o2;
|
|
}
|
|
function Y(e2) {
|
|
return i.toByteArray(function(e3) {
|
|
if ((e3 = (e3 = e3.split("=")[0]).trim().replace(V, "")).length < 2)
|
|
return "";
|
|
for (;e3.length % 4 != 0; )
|
|
e3 += "=";
|
|
return e3;
|
|
}(e2));
|
|
}
|
|
function K(e2, t3, n2, i2) {
|
|
let r2;
|
|
for (r2 = 0;r2 < i2 && !(r2 + n2 >= t3.length || r2 >= e2.length); ++r2)
|
|
t3[r2 + n2] = e2[r2];
|
|
return r2;
|
|
}
|
|
function W(e2, t3) {
|
|
return e2 instanceof t3 || e2 != null && e2.constructor != null && e2.constructor.name != null && e2.constructor.name === t3.name;
|
|
}
|
|
function J(e2) {
|
|
return e2 != e2;
|
|
}
|
|
const X = function() {
|
|
const e2 = "0123456789abcdef", t3 = new Array(256);
|
|
for (let n2 = 0;n2 < 16; ++n2) {
|
|
const i2 = 16 * n2;
|
|
for (let r2 = 0;r2 < 16; ++r2)
|
|
t3[i2 + r2] = e2[n2] + e2[r2];
|
|
}
|
|
return t3;
|
|
}();
|
|
function Z(e2) {
|
|
return typeof BigInt == "undefined" ? $ : e2;
|
|
}
|
|
function $() {
|
|
throw new Error("BigInt not supported");
|
|
}
|
|
}, 9089: (e) => {
|
|
e.exports = function(e2) {
|
|
var t2 = [];
|
|
return t2.toString = function() {
|
|
return this.map(function(t3) {
|
|
var n = "", i = t3[5] !== undefined;
|
|
return t3[4] && (n += "@supports (".concat(t3[4], ") {")), t3[2] && (n += "@media ".concat(t3[2], " {")), i && (n += "@layer".concat(t3[5].length > 0 ? " ".concat(t3[5]) : "", " {")), n += e2(t3), i && (n += "}"), t3[2] && (n += "}"), t3[4] && (n += "}"), n;
|
|
}).join("");
|
|
}, t2.i = function(e3, n, i, r, o) {
|
|
typeof e3 == "string" && (e3 = [[null, e3, undefined]]);
|
|
var s = {};
|
|
if (i)
|
|
for (var a = 0;a < this.length; a++) {
|
|
var A = this[a][0];
|
|
A != null && (s[A] = true);
|
|
}
|
|
for (var l = 0;l < e3.length; l++) {
|
|
var c = [].concat(e3[l]);
|
|
i && s[c[0]] || (o !== undefined && (c[5] === undefined || (c[1] = "@layer".concat(c[5].length > 0 ? " ".concat(c[5]) : "", " {").concat(c[1], "}")), c[5] = o), n && (c[2] ? (c[1] = "@media ".concat(c[2], " {").concat(c[1], "}"), c[2] = n) : c[2] = n), r && (c[4] ? (c[1] = "@supports (".concat(c[4], ") {").concat(c[1], "}"), c[4] = r) : c[4] = "".concat(r)), t2.push(c));
|
|
}
|
|
}, t2;
|
|
};
|
|
}, 6492: (e) => {
|
|
e.exports = function(e2, t2) {
|
|
return t2 || (t2 = {}), e2 ? (e2 = String(e2.__esModule ? e2.default : e2), /^['"].*['"]$/.test(e2) && (e2 = e2.slice(1, -1)), t2.hash && (e2 += t2.hash), /["'() \t\n]|(%20)/.test(e2) || t2.needQuotes ? '"'.concat(e2.replace(/"/g, "\\\"").replace(/\n/g, "\\n"), '"') : e2) : e2;
|
|
};
|
|
}, 963: (e) => {
|
|
e.exports = function(e2) {
|
|
var t2 = e2[1], n = e2[3];
|
|
if (!n)
|
|
return t2;
|
|
if (typeof btoa == "function") {
|
|
var i = btoa(unescape(encodeURIComponent(JSON.stringify(n)))), r = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(i), o = "/*# ".concat(r, " */");
|
|
return [t2].concat([o]).join(`
|
|
`);
|
|
}
|
|
return [t2].join(`
|
|
`);
|
|
};
|
|
}, 8878: (e, t2, n) => {
|
|
t2.formatArgs = function(t3) {
|
|
if (t3[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + t3[0] + (this.useColors ? "%c " : " ") + "+" + e.exports.humanize(this.diff), !this.useColors)
|
|
return;
|
|
const n2 = "color: " + this.color;
|
|
t3.splice(1, 0, n2, "color: inherit");
|
|
let i2 = 0, r = 0;
|
|
t3[0].replace(/%[a-zA-Z%]/g, (e2) => {
|
|
e2 !== "%%" && (i2++, e2 === "%c" && (r = i2));
|
|
}), t3.splice(r, 0, n2);
|
|
}, t2.save = function(e2) {
|
|
try {
|
|
e2 ? t2.storage.setItem("debug", e2) : t2.storage.removeItem("debug");
|
|
} catch (e3) {}
|
|
}, t2.load = function() {
|
|
let e2;
|
|
try {
|
|
e2 = t2.storage.getItem("debug");
|
|
} catch (e3) {}
|
|
return !e2 && typeof process != "undefined" && "env" in process && (e2 = process.env.DEBUG), e2;
|
|
}, t2.useColors = function() {
|
|
if (typeof window != "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs))
|
|
return true;
|
|
if (typeof navigator != "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))
|
|
return false;
|
|
let e2;
|
|
return typeof document != "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window != "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator != "undefined" && navigator.userAgent && (e2 = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(e2[1], 10) >= 31 || typeof navigator != "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
}, t2.storage = function() {
|
|
try {
|
|
return localStorage;
|
|
} catch (e2) {}
|
|
}(), t2.destroy = (() => {
|
|
let e2 = false;
|
|
return () => {
|
|
e2 || (e2 = true, console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."));
|
|
};
|
|
})(), t2.colors = ["#0000CC", "#0000FF", "#0033CC", "#0033FF", "#0066CC", "#0066FF", "#0099CC", "#0099FF", "#00CC00", "#00CC33", "#00CC66", "#00CC99", "#00CCCC", "#00CCFF", "#3300CC", "#3300FF", "#3333CC", "#3333FF", "#3366CC", "#3366FF", "#3399CC", "#3399FF", "#33CC00", "#33CC33", "#33CC66", "#33CC99", "#33CCCC", "#33CCFF", "#6600CC", "#6600FF", "#6633CC", "#6633FF", "#66CC00", "#66CC33", "#9900CC", "#9900FF", "#9933CC", "#9933FF", "#99CC00", "#99CC33", "#CC0000", "#CC0033", "#CC0066", "#CC0099", "#CC00CC", "#CC00FF", "#CC3300", "#CC3333", "#CC3366", "#CC3399", "#CC33CC", "#CC33FF", "#CC6600", "#CC6633", "#CC9900", "#CC9933", "#CCCC00", "#CCCC33", "#FF0000", "#FF0033", "#FF0066", "#FF0099", "#FF00CC", "#FF00FF", "#FF3300", "#FF3333", "#FF3366", "#FF3399", "#FF33CC", "#FF33FF", "#FF6600", "#FF6633", "#FF9900", "#FF9933", "#FFCC00", "#FFCC33"], t2.log = console.debug || console.log || (() => {}), e.exports = n(8945)(t2);
|
|
const { formatters: i } = e.exports;
|
|
i.j = function(e2) {
|
|
try {
|
|
return JSON.stringify(e2);
|
|
} catch (e3) {
|
|
return "[UnexpectedJSONParseError]: " + e3.message;
|
|
}
|
|
};
|
|
}, 8945: (e, t2, n) => {
|
|
e.exports = function(e2) {
|
|
function t3(e3) {
|
|
let n2, r2, o, s = null;
|
|
function a(...e4) {
|
|
if (!a.enabled)
|
|
return;
|
|
const i2 = a, r3 = Number(new Date), o2 = r3 - (n2 || r3);
|
|
i2.diff = o2, i2.prev = n2, i2.curr = r3, n2 = r3, e4[0] = t3.coerce(e4[0]), typeof e4[0] != "string" && e4.unshift("%O");
|
|
let s2 = 0;
|
|
e4[0] = e4[0].replace(/%([a-zA-Z%])/g, (n3, r4) => {
|
|
if (n3 === "%%")
|
|
return "%";
|
|
s2++;
|
|
const o3 = t3.formatters[r4];
|
|
if (typeof o3 == "function") {
|
|
const t4 = e4[s2];
|
|
n3 = o3.call(i2, t4), e4.splice(s2, 1), s2--;
|
|
}
|
|
return n3;
|
|
}), t3.formatArgs.call(i2, e4), (i2.log || t3.log).apply(i2, e4);
|
|
}
|
|
return a.namespace = e3, a.useColors = t3.useColors(), a.color = t3.selectColor(e3), a.extend = i, a.destroy = t3.destroy, Object.defineProperty(a, "enabled", { enumerable: true, configurable: false, get: () => s !== null ? s : (r2 !== t3.namespaces && (r2 = t3.namespaces, o = t3.enabled(e3)), o), set: (e4) => {
|
|
s = e4;
|
|
} }), typeof t3.init == "function" && t3.init(a), a;
|
|
}
|
|
function i(e3, n2) {
|
|
const i2 = t3(this.namespace + (n2 === undefined ? ":" : n2) + e3);
|
|
return i2.log = this.log, i2;
|
|
}
|
|
function r(e3, t4) {
|
|
let n2 = 0, i2 = 0, r2 = -1, o = 0;
|
|
for (;n2 < e3.length; )
|
|
if (i2 < t4.length && (t4[i2] === e3[n2] || t4[i2] === "*"))
|
|
t4[i2] === "*" ? (r2 = i2, o = n2, i2++) : (n2++, i2++);
|
|
else {
|
|
if (r2 === -1)
|
|
return false;
|
|
i2 = r2 + 1, o++, n2 = o;
|
|
}
|
|
for (;i2 < t4.length && t4[i2] === "*"; )
|
|
i2++;
|
|
return i2 === t4.length;
|
|
}
|
|
return t3.debug = t3, t3.default = t3, t3.coerce = function(e3) {
|
|
return e3 instanceof Error ? e3.stack || e3.message : e3;
|
|
}, t3.disable = function() {
|
|
const e3 = [...t3.names, ...t3.skips.map((e4) => "-" + e4)].join(",");
|
|
return t3.enable(""), e3;
|
|
}, t3.enable = function(e3) {
|
|
t3.save(e3), t3.namespaces = e3, t3.names = [], t3.skips = [];
|
|
const n2 = (typeof e3 == "string" ? e3 : "").trim().replace(" ", ",").split(",").filter(Boolean);
|
|
for (const e4 of n2)
|
|
e4[0] === "-" ? t3.skips.push(e4.slice(1)) : t3.names.push(e4);
|
|
}, t3.enabled = function(e3) {
|
|
for (const n2 of t3.skips)
|
|
if (r(e3, n2))
|
|
return false;
|
|
for (const n2 of t3.names)
|
|
if (r(e3, n2))
|
|
return true;
|
|
return false;
|
|
}, t3.humanize = n(9192), t3.destroy = function() {
|
|
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
}, Object.keys(e2).forEach((n2) => {
|
|
t3[n2] = e2[n2];
|
|
}), t3.names = [], t3.skips = [], t3.formatters = {}, t3.selectColor = function(e3) {
|
|
let n2 = 0;
|
|
for (let t4 = 0;t4 < e3.length; t4++)
|
|
n2 = (n2 << 5) - n2 + e3.charCodeAt(t4), n2 |= 0;
|
|
return t3.colors[Math.abs(n2) % t3.colors.length];
|
|
}, t3.enable(t3.load()), t3;
|
|
};
|
|
}, 1124: (e, t2, n) => {
|
|
var i = n(6240), r = Object.prototype.hasOwnProperty, o = Object.prototype.propertyIsEnumerable;
|
|
function s(e2, t3, n2) {
|
|
var o2 = t3[n2];
|
|
if (o2 != null) {
|
|
if (r.call(e2, n2) && (e2[n2] === undefined || e2[n2] === null))
|
|
throw new TypeError("Cannot convert undefined or null to object (" + n2 + ")");
|
|
r.call(e2, n2) && i(o2) ? e2[n2] = a(Object(e2[n2]), t3[n2]) : e2[n2] = o2;
|
|
}
|
|
}
|
|
function a(e2, t3) {
|
|
if (e2 === t3)
|
|
return e2;
|
|
for (var n2 in t3 = Object(t3))
|
|
r.call(t3, n2) && s(e2, t3, n2);
|
|
if (Object.getOwnPropertySymbols)
|
|
for (var i2 = Object.getOwnPropertySymbols(t3), a2 = 0;a2 < i2.length; a2++)
|
|
o.call(t3, i2[a2]) && s(e2, t3, i2[a2]);
|
|
return e2;
|
|
}
|
|
e.exports = function(e2) {
|
|
e2 = function(e3) {
|
|
if (e3 == null)
|
|
throw new TypeError("Sources cannot be null or undefined");
|
|
return Object(e3);
|
|
}(e2);
|
|
for (var t3 = 1;t3 < arguments.length; t3++)
|
|
a(e2, arguments[t3]);
|
|
return e2;
|
|
};
|
|
}, 8480: (e) => {
|
|
e.exports = function(e2) {
|
|
switch (e2) {
|
|
case "int8":
|
|
return Int8Array;
|
|
case "int16":
|
|
return Int16Array;
|
|
case "int32":
|
|
return Int32Array;
|
|
case "uint8":
|
|
return Uint8Array;
|
|
case "uint16":
|
|
return Uint16Array;
|
|
case "uint32":
|
|
return Uint32Array;
|
|
case "float32":
|
|
return Float32Array;
|
|
case "float64":
|
|
return Float64Array;
|
|
case "array":
|
|
return Array;
|
|
case "uint8_clamped":
|
|
return Uint8ClampedArray;
|
|
}
|
|
};
|
|
}, 919: (e, t2, n) => {
|
|
var i;
|
|
i = typeof window != "undefined" ? window : n.g !== undefined ? n.g : typeof self != "undefined" ? self : {}, e.exports = i;
|
|
}, 1024: (e, t2) => {
|
|
t2.read = function(e2, t3, n, i, r) {
|
|
var o, s, a = 8 * r - i - 1, A = (1 << a) - 1, l = A >> 1, c = -7, h = n ? r - 1 : 0, d = n ? -1 : 1, u = e2[t3 + h];
|
|
for (h += d, o = u & (1 << -c) - 1, u >>= -c, c += a;c > 0; o = 256 * o + e2[t3 + h], h += d, c -= 8)
|
|
;
|
|
for (s = o & (1 << -c) - 1, o >>= -c, c += i;c > 0; s = 256 * s + e2[t3 + h], h += d, c -= 8)
|
|
;
|
|
if (o === 0)
|
|
o = 1 - l;
|
|
else {
|
|
if (o === A)
|
|
return s ? NaN : 1 / 0 * (u ? -1 : 1);
|
|
s += Math.pow(2, i), o -= l;
|
|
}
|
|
return (u ? -1 : 1) * s * Math.pow(2, o - i);
|
|
}, t2.write = function(e2, t3, n, i, r, o) {
|
|
var s, a, A, l = 8 * o - r - 1, c = (1 << l) - 1, h = c >> 1, d = r === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, u = i ? 0 : o - 1, g = i ? 1 : -1, p = t3 < 0 || t3 === 0 && 1 / t3 < 0 ? 1 : 0;
|
|
for (t3 = Math.abs(t3), isNaN(t3) || t3 === 1 / 0 ? (a = isNaN(t3) ? 1 : 0, s = c) : (s = Math.floor(Math.log(t3) / Math.LN2), t3 * (A = Math.pow(2, -s)) < 1 && (s--, A *= 2), (t3 += s + h >= 1 ? d / A : d * Math.pow(2, 1 - h)) * A >= 2 && (s++, A /= 2), s + h >= c ? (a = 0, s = c) : s + h >= 1 ? (a = (t3 * A - 1) * Math.pow(2, r), s += h) : (a = t3 * Math.pow(2, h - 1) * Math.pow(2, r), s = 0));r >= 8; e2[n + u] = 255 & a, u += g, a /= 256, r -= 8)
|
|
;
|
|
for (s = s << r | a, l += r;l > 0; e2[n + u] = 255 & s, u += g, s /= 256, l -= 8)
|
|
;
|
|
e2[n + u - g] |= 128 * p;
|
|
};
|
|
}, 2225: (e) => {
|
|
function t2(e2) {
|
|
return !!e2.constructor && typeof e2.constructor.isBuffer == "function" && e2.constructor.isBuffer(e2);
|
|
}
|
|
e.exports = function(e2) {
|
|
return e2 != null && (t2(e2) || function(e3) {
|
|
return typeof e3.readFloatLE == "function" && typeof e3.slice == "function" && t2(e3.slice(0, 0));
|
|
}(e2) || !!e2._isBuffer);
|
|
};
|
|
}, 8847: (e) => {
|
|
e.exports = function(e2) {
|
|
if (!e2)
|
|
return false;
|
|
var n = t2.call(e2);
|
|
return n === "[object Function]" || typeof e2 == "function" && n !== "[object RegExp]" || typeof window != "undefined" && (e2 === window.setTimeout || e2 === window.alert || e2 === window.confirm || e2 === window.prompt);
|
|
};
|
|
var t2 = Object.prototype.toString;
|
|
}, 6240: (e) => {
|
|
e.exports = function(e2) {
|
|
var t2 = typeof e2;
|
|
return e2 !== null && (t2 === "object" || t2 === "function");
|
|
};
|
|
}, 5651: (e, t2, n) => {
|
|
var i = n(5406), r = n(4597), o = n(5734), s = ["x", "e", "a", "o", "n", "s", "r", "c", "u", "m", "v", "w", "z"], a = ["m", "w"], A = ["H", "I", "N", "E", "F", "K", "L", "T", "U", "V", "W", "X", "Y", "Z"], l = 9, c = 32;
|
|
function h(e2) {
|
|
this.glyphs = [], this._measure = this.computeMetrics.bind(this), this.update(e2);
|
|
}
|
|
function d(e2) {
|
|
return new Function(["return function " + e2 + "() {", " return this._" + e2, "}"].join(`
|
|
`))();
|
|
}
|
|
function u(e2, t3) {
|
|
if (!e2.chars || e2.chars.length === 0)
|
|
return null;
|
|
var n2 = p(e2.chars, t3);
|
|
return n2 >= 0 ? e2.chars[n2] : null;
|
|
}
|
|
function g(e2, t3, n2) {
|
|
if (!e2.kernings || e2.kernings.length === 0)
|
|
return 0;
|
|
for (var i2 = e2.kernings, r2 = 0;r2 < i2.length; r2++) {
|
|
var o2 = i2[r2];
|
|
if (o2.first === t3 && o2.second === n2)
|
|
return o2.amount;
|
|
}
|
|
return 0;
|
|
}
|
|
function p(e2, t3, n2) {
|
|
for (var i2 = n2 = n2 || 0;i2 < e2.length; i2++)
|
|
if (e2[i2].id === t3)
|
|
return i2;
|
|
return -1;
|
|
}
|
|
e.exports = function(e2) {
|
|
return new h(e2);
|
|
}, h.prototype.update = function(e2) {
|
|
if (e2 = r({ measure: this._measure }, e2), this._opt = e2, this._opt.tabSize = o(this._opt.tabSize, 4), !e2.font)
|
|
throw new Error("must provide a valid bitmap font");
|
|
var t3 = this.glyphs, n2 = e2.text || "", a2 = e2.font;
|
|
this._setupSpaceGlyphs(a2);
|
|
var l2 = i.lines(n2, e2), c2 = e2.width || 0;
|
|
t3.length = 0;
|
|
var h2 = l2.reduce(function(e3, t4) {
|
|
return Math.max(e3, t4.width, c2);
|
|
}, 0), d2 = 0, u2 = 0, f = o(e2.lineHeight, a2.common.lineHeight), m = a2.common.base, E = f - m, C = e2.letterSpacing || 0, v = f * l2.length - E, B = function(e3) {
|
|
return e3 === "center" ? 1 : e3 === "right" ? 2 : 0;
|
|
}(this._opt.align);
|
|
u2 -= v, this._width = h2, this._height = v, this._descender = f - m, this._baseline = m, this._xHeight = function(e3) {
|
|
for (var t4 = 0;t4 < s.length; t4++) {
|
|
var n3 = s[t4].charCodeAt(0), i2 = p(e3.chars, n3);
|
|
if (i2 >= 0)
|
|
return e3.chars[i2].height;
|
|
}
|
|
return 0;
|
|
}(a2), this._capHeight = function(e3) {
|
|
for (var t4 = 0;t4 < A.length; t4++) {
|
|
var n3 = A[t4].charCodeAt(0), i2 = p(e3.chars, n3);
|
|
if (i2 >= 0)
|
|
return e3.chars[i2].height;
|
|
}
|
|
return 0;
|
|
}(a2), this._lineHeight = f, this._ascender = f - E - this._xHeight;
|
|
var b = this;
|
|
l2.forEach(function(e3, i2) {
|
|
for (var r2, o2 = e3.start, s2 = e3.end, A2 = e3.width, l3 = o2;l3 < s2; l3++) {
|
|
var c3 = n2.charCodeAt(l3), p2 = b.getGlyph(a2, c3);
|
|
if (p2) {
|
|
r2 && (d2 += g(a2, r2.id, p2.id));
|
|
var m2 = d2;
|
|
B === 1 ? m2 += (h2 - A2) / 2 : B === 2 && (m2 += h2 - A2), t3.push({ position: [m2, u2], data: p2, index: l3, line: i2 }), d2 += p2.xadvance + C, r2 = p2;
|
|
}
|
|
}
|
|
u2 += f, d2 = 0;
|
|
}), this._linesTotal = l2.length;
|
|
}, h.prototype._setupSpaceGlyphs = function(e2) {
|
|
if (this._fallbackSpaceGlyph = null, this._fallbackTabGlyph = null, e2.chars && e2.chars.length !== 0) {
|
|
var t3 = u(e2, c) || function(e3) {
|
|
for (var t4 = 0;t4 < a.length; t4++) {
|
|
var n3 = a[t4].charCodeAt(0), i2 = p(e3.chars, n3);
|
|
if (i2 >= 0)
|
|
return e3.chars[i2];
|
|
}
|
|
return 0;
|
|
}(e2) || e2.chars[0], n2 = this._opt.tabSize * t3.xadvance;
|
|
this._fallbackSpaceGlyph = t3, this._fallbackTabGlyph = r(t3, { x: 0, y: 0, xadvance: n2, id: l, xoffset: 0, yoffset: 0, width: 0, height: 0 });
|
|
}
|
|
}, h.prototype.getGlyph = function(e2, t3) {
|
|
return u(e2, t3) || (t3 === l ? this._fallbackTabGlyph : t3 === c ? this._fallbackSpaceGlyph : null);
|
|
}, h.prototype.computeMetrics = function(e2, t3, n2, i2) {
|
|
var r2, o2 = this._opt.letterSpacing || 0, s2 = this._opt.font, a2 = 0, A2 = 0, l2 = 0;
|
|
if (!s2.chars || s2.chars.length === 0)
|
|
return { start: t3, end: t3, width: 0 };
|
|
n2 = Math.min(e2.length, n2);
|
|
for (var c2 = t3;c2 < n2; c2++) {
|
|
var h2, d2 = e2.charCodeAt(c2);
|
|
if (h2 = this.getGlyph(s2, d2)) {
|
|
h2.xoffset;
|
|
var u2 = (a2 += r2 ? g(s2, r2.id, h2.id) : 0) + h2.xadvance + o2, p2 = a2 + h2.width;
|
|
if (p2 >= i2 || u2 >= i2)
|
|
break;
|
|
a2 = u2, A2 = p2, r2 = h2;
|
|
}
|
|
l2++;
|
|
}
|
|
return r2 && (A2 += r2.xoffset), { start: t3, end: t3 + l2, width: A2 };
|
|
}, ["width", "height", "descender", "ascender", "xHeight", "baseline", "capHeight", "lineHeight"].forEach(function(e2) {
|
|
Object.defineProperty(h.prototype, e2, { get: d(e2), configurable: true });
|
|
});
|
|
}, 5751: (e, t2, n) => {
|
|
var i = n(9922).hp, r = n(3558), o = function() {}, s = n(1476), a = n(7034), A = n(7480), l = n(573), c = n(4597), h = self.XMLHttpRequest && "withCredentials" in new XMLHttpRequest;
|
|
e.exports = function(e2, t3) {
|
|
t3 = typeof t3 == "function" ? t3 : o, typeof e2 == "string" ? e2 = { uri: e2 } : e2 || (e2 = {}), e2.binary && (e2 = function(e3) {
|
|
if (h)
|
|
return c(e3, { responseType: "arraybuffer" });
|
|
if (self.XMLHttpRequest === undefined)
|
|
throw new Error("your browser does not support XHR loading");
|
|
var t4 = new self.XMLHttpRequest;
|
|
return t4.overrideMimeType("text/plain; charset=x-user-defined"), c({ xhr: t4 }, e3);
|
|
}(e2)), r(e2, function(n2, r2, c2) {
|
|
if (n2)
|
|
return t3(n2);
|
|
if (!/^2/.test(r2.statusCode))
|
|
return t3(new Error("http status code: " + r2.statusCode));
|
|
if (!c2)
|
|
return t3(new Error("no body result"));
|
|
var h2, d, u = false;
|
|
if (h2 = c2, Object.prototype.toString.call(h2) === "[object ArrayBuffer]") {
|
|
var g = new Uint8Array(c2);
|
|
c2 = i.from(g, "binary");
|
|
}
|
|
l(c2) && (u = true, typeof c2 == "string" && (c2 = i.from(c2, "binary"))), u || (i.isBuffer(c2) && (c2 = c2.toString(e2.encoding)), c2 = c2.trim());
|
|
try {
|
|
var p = r2.headers["content-type"];
|
|
d = u ? A(c2) : /json/.test(p) || c2.charAt(0) === "{" ? JSON.parse(c2) : /xml/.test(p) || c2.charAt(0) === "<" ? a(c2) : s(c2);
|
|
} catch (e3) {
|
|
t3(new Error("error parsing font " + e3.message)), t3 = o;
|
|
}
|
|
t3(null, d);
|
|
});
|
|
};
|
|
}, 573: (e, t2, n) => {
|
|
var i = n(9922).hp, r = n(911), o = i.from([66, 77, 70, 3]);
|
|
e.exports = function(e2) {
|
|
return typeof e2 == "string" ? e2.substring(0, 3) === "BMF" : e2.length > 4 && r(e2.slice(0, 4), o);
|
|
};
|
|
}, 9192: (e) => {
|
|
var t2 = 1000, n = 60 * t2, i = 60 * n, r = 24 * i, o = 7 * r;
|
|
function s(e2, t3, n2, i2) {
|
|
var r2 = t3 >= 1.5 * n2;
|
|
return Math.round(e2 / n2) + " " + i2 + (r2 ? "s" : "");
|
|
}
|
|
e.exports = function(e2, a) {
|
|
a = a || {};
|
|
var A, l, c = typeof e2;
|
|
if (c === "string" && e2.length > 0)
|
|
return function(e3) {
|
|
if (!((e3 = String(e3)).length > 100)) {
|
|
var s2 = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e3);
|
|
if (s2) {
|
|
var a2 = parseFloat(s2[1]);
|
|
switch ((s2[2] || "ms").toLowerCase()) {
|
|
case "years":
|
|
case "year":
|
|
case "yrs":
|
|
case "yr":
|
|
case "y":
|
|
return 31557600000 * a2;
|
|
case "weeks":
|
|
case "week":
|
|
case "w":
|
|
return a2 * o;
|
|
case "days":
|
|
case "day":
|
|
case "d":
|
|
return a2 * r;
|
|
case "hours":
|
|
case "hour":
|
|
case "hrs":
|
|
case "hr":
|
|
case "h":
|
|
return a2 * i;
|
|
case "minutes":
|
|
case "minute":
|
|
case "mins":
|
|
case "min":
|
|
case "m":
|
|
return a2 * n;
|
|
case "seconds":
|
|
case "second":
|
|
case "secs":
|
|
case "sec":
|
|
case "s":
|
|
return a2 * t2;
|
|
case "milliseconds":
|
|
case "millisecond":
|
|
case "msecs":
|
|
case "msec":
|
|
case "ms":
|
|
return a2;
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}(e2);
|
|
if (c === "number" && isFinite(e2))
|
|
return a.long ? (A = e2, (l = Math.abs(A)) >= r ? s(A, l, r, "day") : l >= i ? s(A, l, i, "hour") : l >= n ? s(A, l, n, "minute") : l >= t2 ? s(A, l, t2, "second") : A + " ms") : function(e3) {
|
|
var o2 = Math.abs(e3);
|
|
return o2 >= r ? Math.round(e3 / r) + "d" : o2 >= i ? Math.round(e3 / i) + "h" : o2 >= n ? Math.round(e3 / n) + "m" : o2 >= t2 ? Math.round(e3 / t2) + "s" : e3 + "ms";
|
|
}(e2);
|
|
throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(e2));
|
|
};
|
|
}, 1476: (e) => {
|
|
function t2(e2, t3) {
|
|
if (!(e2 = e2.replace(/\t+/g, " ").trim()))
|
|
return null;
|
|
var i = e2.indexOf(" ");
|
|
if (i === -1)
|
|
throw new Error("no named row at line " + t3);
|
|
var r = e2.substring(0, i);
|
|
e2 = (e2 = (e2 = (e2 = e2.substring(i + 1)).replace(/letter=[\'\"]\S+[\'\"]/gi, "")).split("=")).map(function(e3) {
|
|
return e3.trim().match(/(".*?"|[^"\s]+)+(?=\s*|\s*$)/g);
|
|
});
|
|
for (var o = [], s = 0;s < e2.length; s++) {
|
|
var a = e2[s];
|
|
s === 0 ? o.push({ key: a[0], data: "" }) : s === e2.length - 1 ? o[o.length - 1].data = n(a[0]) : (o[o.length - 1].data = n(a[0]), o.push({ key: a[1], data: "" }));
|
|
}
|
|
var A = { key: r, data: {} };
|
|
return o.forEach(function(e3) {
|
|
A.data[e3.key] = e3.data;
|
|
}), A;
|
|
}
|
|
function n(e2) {
|
|
return e2 && e2.length !== 0 ? e2.indexOf('"') === 0 || e2.indexOf("'") === 0 ? e2.substring(1, e2.length - 1) : e2.indexOf(",") !== -1 ? function(e3) {
|
|
return e3.split(",").map(function(e4) {
|
|
return parseInt(e4, 10);
|
|
});
|
|
}(e2) : parseInt(e2, 10) : "";
|
|
}
|
|
e.exports = function(e2) {
|
|
if (!e2)
|
|
throw new Error("no data provided");
|
|
var n2 = { pages: [], chars: [], kernings: [] }, i = (e2 = e2.toString().trim()).split(/\r\n?|\n/g);
|
|
if (i.length === 0)
|
|
throw new Error("no data in BMFont file");
|
|
for (var r = 0;r < i.length; r++) {
|
|
var o = t2(i[r], r);
|
|
if (o)
|
|
if (o.key === "page") {
|
|
if (typeof o.data.id != "number")
|
|
throw new Error("malformed file at line " + r + " -- needs page id=N");
|
|
if (typeof o.data.file != "string")
|
|
throw new Error("malformed file at line " + r + ' -- needs page file="path"');
|
|
n2.pages[o.data.id] = o.data.file;
|
|
} else
|
|
o.key === "chars" || o.key === "kernings" || (o.key === "char" ? n2.chars.push(o.data) : o.key === "kerning" ? n2.kernings.push(o.data) : n2[o.key] = o.data);
|
|
}
|
|
return n2;
|
|
};
|
|
}, 7480: (e) => {
|
|
var t2 = [66, 77, 70];
|
|
function n(e2, t3, n2) {
|
|
if (n2 > t3.length - 1)
|
|
return 0;
|
|
var r = t3.readUInt8(n2++), o = t3.readInt32LE(n2);
|
|
switch (n2 += 4, r) {
|
|
case 1:
|
|
e2.info = function(e3, t4) {
|
|
var n3 = {};
|
|
n3.size = e3.readInt16LE(t4);
|
|
var r2 = e3.readUInt8(t4 + 2);
|
|
return n3.smooth = r2 >> 7 & 1, n3.unicode = r2 >> 6 & 1, n3.italic = r2 >> 5 & 1, n3.bold = r2 >> 4 & 1, r2 >> 3 & 1 && (n3.fixedHeight = 1), n3.charset = e3.readUInt8(t4 + 3) || "", n3.stretchH = e3.readUInt16LE(t4 + 4), n3.aa = e3.readUInt8(t4 + 6), n3.padding = [e3.readInt8(t4 + 7), e3.readInt8(t4 + 8), e3.readInt8(t4 + 9), e3.readInt8(t4 + 10)], n3.spacing = [e3.readInt8(t4 + 11), e3.readInt8(t4 + 12)], n3.outline = e3.readUInt8(t4 + 13), n3.face = function(e4, t5) {
|
|
return i(e4, t5).toString("utf8");
|
|
}(e3, t4 + 14), n3;
|
|
}(t3, n2);
|
|
break;
|
|
case 2:
|
|
e2.common = function(e3, t4) {
|
|
var n3 = {};
|
|
return n3.lineHeight = e3.readUInt16LE(t4), n3.base = e3.readUInt16LE(t4 + 2), n3.scaleW = e3.readUInt16LE(t4 + 4), n3.scaleH = e3.readUInt16LE(t4 + 6), n3.pages = e3.readUInt16LE(t4 + 8), e3.readUInt8(t4 + 10), n3.packed = 0, n3.alphaChnl = e3.readUInt8(t4 + 11), n3.redChnl = e3.readUInt8(t4 + 12), n3.greenChnl = e3.readUInt8(t4 + 13), n3.blueChnl = e3.readUInt8(t4 + 14), n3;
|
|
}(t3, n2);
|
|
break;
|
|
case 3:
|
|
e2.pages = function(e3, t4, n3) {
|
|
for (var r2 = [], o2 = i(e3, t4), s = o2.length + 1, a = n3 / s, A = 0;A < a; A++)
|
|
r2[A] = e3.slice(t4, t4 + o2.length).toString("utf8"), t4 += s;
|
|
return r2;
|
|
}(t3, n2, o);
|
|
break;
|
|
case 4:
|
|
e2.chars = function(e3, t4, n3) {
|
|
for (var i2 = [], r2 = n3 / 20, o2 = 0;o2 < r2; o2++) {
|
|
var s = {}, a = 20 * o2;
|
|
s.id = e3.readUInt32LE(t4 + 0 + a), s.x = e3.readUInt16LE(t4 + 4 + a), s.y = e3.readUInt16LE(t4 + 6 + a), s.width = e3.readUInt16LE(t4 + 8 + a), s.height = e3.readUInt16LE(t4 + 10 + a), s.xoffset = e3.readInt16LE(t4 + 12 + a), s.yoffset = e3.readInt16LE(t4 + 14 + a), s.xadvance = e3.readInt16LE(t4 + 16 + a), s.page = e3.readUInt8(t4 + 18 + a), s.chnl = e3.readUInt8(t4 + 19 + a), i2[o2] = s;
|
|
}
|
|
return i2;
|
|
}(t3, n2, o);
|
|
break;
|
|
case 5:
|
|
e2.kernings = function(e3, t4, n3) {
|
|
for (var i2 = [], r2 = n3 / 10, o2 = 0;o2 < r2; o2++) {
|
|
var s = {}, a = 10 * o2;
|
|
s.first = e3.readUInt32LE(t4 + 0 + a), s.second = e3.readUInt32LE(t4 + 4 + a), s.amount = e3.readInt16LE(t4 + 8 + a), i2[o2] = s;
|
|
}
|
|
return i2;
|
|
}(t3, n2, o);
|
|
}
|
|
return 5 + o;
|
|
}
|
|
function i(e2, t3) {
|
|
for (var n2 = t3;n2 < e2.length && e2[n2] !== 0; n2++)
|
|
;
|
|
return e2.slice(t3, n2);
|
|
}
|
|
e.exports = function(e2) {
|
|
if (e2.length < 6)
|
|
throw new Error("invalid buffer length for BMFont");
|
|
var i2 = t2.every(function(t3, n2) {
|
|
return e2.readUInt8(n2) === t3;
|
|
});
|
|
if (!i2)
|
|
throw new Error("BMFont missing BMF byte header");
|
|
var r = 3;
|
|
if (e2.readUInt8(r++) > 3)
|
|
throw new Error("Only supports BMFont Binary v3 (BMFont App v1.10)");
|
|
for (var o = { kernings: [], chars: [] }, s = 0;s < 5; s++)
|
|
r += n(o, e2, r);
|
|
return o;
|
|
};
|
|
}, 7034: (e, t2, n) => {
|
|
var i = n(7829), r = n(1896), o = { scaleh: "scaleH", scalew: "scaleW", stretchh: "stretchH", lineheight: "lineHeight", alphachnl: "alphaChnl", redchnl: "redChnl", greenchnl: "greenChnl", bluechnl: "blueChnl" };
|
|
function s(e2) {
|
|
var t3 = function(e3) {
|
|
for (var t4 = [], n2 = 0;n2 < e3.attributes.length; n2++)
|
|
t4.push(e3.attributes[n2]);
|
|
return t4;
|
|
}(e2);
|
|
return t3.reduce(function(e3, t4) {
|
|
var n2;
|
|
return e3[n2 = t4.nodeName, o[n2.toLowerCase()] || n2] = t4.nodeValue, e3;
|
|
}, {});
|
|
}
|
|
e.exports = function(e2) {
|
|
e2 = e2.toString();
|
|
var t3 = r(e2), n2 = { pages: [], chars: [], kernings: [] };
|
|
["info", "common"].forEach(function(e3) {
|
|
var r2 = t3.getElementsByTagName(e3)[0];
|
|
r2 && (n2[e3] = i(s(r2)));
|
|
});
|
|
var o2 = t3.getElementsByTagName("pages")[0];
|
|
if (!o2)
|
|
throw new Error("malformed file -- no <pages> element");
|
|
for (var a = o2.getElementsByTagName("page"), A = 0;A < a.length; A++) {
|
|
var l = a[A], c = parseInt(l.getAttribute("id"), 10), h = l.getAttribute("file");
|
|
if (isNaN(c))
|
|
throw new Error('malformed file -- page "id" attribute is NaN');
|
|
if (!h)
|
|
throw new Error('malformed file -- needs page "file" attribute');
|
|
n2.pages[parseInt(c, 10)] = h;
|
|
}
|
|
return ["chars", "kernings"].forEach(function(e3) {
|
|
var r2 = t3.getElementsByTagName(e3)[0];
|
|
if (r2)
|
|
for (var o3 = e3.substring(0, e3.length - 1), a2 = r2.getElementsByTagName(o3), A2 = 0;A2 < a2.length; A2++) {
|
|
var l2 = a2[A2];
|
|
n2[e3].push(i(s(l2)));
|
|
}
|
|
}), n2;
|
|
};
|
|
}, 7829: (e) => {
|
|
var t2 = "chasrset";
|
|
e.exports = function(e2) {
|
|
for (var n in e2 = Object.assign({}, e2), t2 in e2 && (e2.charset = e2[t2], delete e2[t2]), e2)
|
|
n !== "face" && n !== "charset" && (e2[n] = n === "padding" || n === "spacing" ? e2[n].split(",").map(function(e3) {
|
|
return parseInt(e3, 10);
|
|
}) : parseInt(e2[n], 10));
|
|
return e2;
|
|
};
|
|
}, 3216: (e) => {
|
|
var t2 = function(e2) {
|
|
return e2.replace(/^\s+|\s+$/g, "");
|
|
};
|
|
e.exports = function(e2) {
|
|
if (!e2)
|
|
return {};
|
|
for (var n, i = {}, r = t2(e2).split(`
|
|
`), o = 0;o < r.length; o++) {
|
|
var s = r[o], a = s.indexOf(":"), A = t2(s.slice(0, a)).toLowerCase(), l = t2(s.slice(a + 1));
|
|
i[A] === undefined ? i[A] = l : (n = i[A], Object.prototype.toString.call(n) === "[object Array]" ? i[A].push(l) : i[A] = [i[A], l]);
|
|
}
|
|
return i;
|
|
};
|
|
}, 9035: (e, t2, n) => {
|
|
var i = n(8480), r = n(8167), o = n(2225), s = [0, 2, 3], a = [2, 1, 3];
|
|
e.exports = function(e2, t3) {
|
|
e2 && (r(e2) || o(e2)) || (t3 = e2 || {}, e2 = null);
|
|
for (var n2 = typeof (t3 = typeof t3 == "number" ? { count: t3 } : t3 || {}).type == "string" ? t3.type : "uint16", A = typeof t3.count == "number" ? t3.count : 1, l = t3.start || 0, c = t3.clockwise !== false ? s : a, h = c[0], d = c[1], u = c[2], g = 6 * A, p = e2 || new (i(n2))(g), f = 0, m = 0;f < g; f += 6, m += 4) {
|
|
var E = f + l;
|
|
p[E + 0] = m + 0, p[E + 1] = m + 1, p[E + 2] = m + 2, p[E + 3] = m + h, p[E + 4] = m + d, p[E + 5] = m + u;
|
|
}
|
|
return p;
|
|
};
|
|
}, 4433: (e, t2, n) => {
|
|
var i = n(5651), r = n(9035), o = n(7106), s = n(1684);
|
|
e.exports = function(e2) {
|
|
return new a(e2);
|
|
};
|
|
|
|
class a extends THREE.BufferGeometry {
|
|
constructor(e2) {
|
|
super(), typeof e2 == "string" && (e2 = { text: e2 }), this._opt = Object.assign({}, e2), e2 && this.update(e2);
|
|
}
|
|
update(e2) {
|
|
if (typeof e2 == "string" && (e2 = { text: e2 }), !(e2 = Object.assign({}, this._opt, e2)).font)
|
|
throw new TypeError("must specify a { font } in options");
|
|
this.layout = i(e2);
|
|
var t3 = e2.flipY !== false, n2 = e2.font, s2 = n2.common.scaleW, a2 = n2.common.scaleH, A = this.layout.glyphs.filter(function(e3) {
|
|
var t4 = e3.data;
|
|
return t4.width * t4.height > 0;
|
|
});
|
|
this.visibleGlyphs = A;
|
|
var l = o.positions(A), c = o.uvs(A, s2, a2, t3), h = r([], { clockwise: true, type: "uint16", count: A.length });
|
|
if (this.setIndex(h), this.setAttribute("position", new THREE.BufferAttribute(l, 2)), this.setAttribute("uv", new THREE.BufferAttribute(c, 2)), !e2.multipage && "page" in this.attributes)
|
|
this.removeAttribute("page");
|
|
else if (e2.multipage) {
|
|
var d = o.pages(A);
|
|
this.setAttribute("page", new THREE.BufferAttribute(d, 1));
|
|
}
|
|
this.boundingBox !== null && this.computeBoundingBox(), this.boundingSphere !== null && this.computeBoundingSphere();
|
|
}
|
|
computeBoundingSphere() {
|
|
this.boundingSphere === null && (this.boundingSphere = new THREE.Sphere);
|
|
var e2 = this.attributes.position.array, t3 = this.attributes.position.itemSize;
|
|
if (!e2 || !t3 || e2.length < 2)
|
|
return this.boundingSphere.radius = 0, void this.boundingSphere.center.set(0, 0, 0);
|
|
s.computeSphere(e2, this.boundingSphere), isNaN(this.boundingSphere.radius) && console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.');
|
|
}
|
|
computeBoundingBox() {
|
|
this.boundingBox === null && (this.boundingBox = new THREE.Box3);
|
|
var e2 = this.boundingBox, t3 = this.attributes.position.array, n2 = this.attributes.position.itemSize;
|
|
!t3 || !n2 || t3.length < 2 ? e2.makeEmpty() : s.computeBox(t3, e2);
|
|
}
|
|
}
|
|
}, 1684: (e) => {
|
|
var t2 = { min: [0, 0], max: [0, 0] };
|
|
function n(e2) {
|
|
var n2 = e2.length / 2;
|
|
t2.min[0] = e2[0], t2.min[1] = e2[1], t2.max[0] = e2[0], t2.max[1] = e2[1];
|
|
for (var i = 0;i < n2; i++) {
|
|
var r = e2[2 * i + 0], o = e2[2 * i + 1];
|
|
t2.min[0] = Math.min(r, t2.min[0]), t2.min[1] = Math.min(o, t2.min[1]), t2.max[0] = Math.max(r, t2.max[0]), t2.max[1] = Math.max(o, t2.max[1]);
|
|
}
|
|
}
|
|
e.exports.computeBox = function(e2, i) {
|
|
n(e2), i.min.set(t2.min[0], t2.min[1], 0), i.max.set(t2.max[0], t2.max[1], 0);
|
|
}, e.exports.computeSphere = function(e2, i) {
|
|
n(e2);
|
|
var r = t2.min[0], o = t2.min[1], s = t2.max[0] - r, a = t2.max[1] - o, A = Math.sqrt(s * s + a * a);
|
|
i.center.set(r + s / 2, o + a / 2, 0), i.radius = A / 2;
|
|
};
|
|
}, 7106: (e) => {
|
|
e.exports.pages = function(e2) {
|
|
var t2 = new Float32Array(4 * e2.length * 1), n = 0;
|
|
return e2.forEach(function(e3) {
|
|
var i = e3.data.page || 0;
|
|
t2[n++] = i, t2[n++] = i, t2[n++] = i, t2[n++] = i;
|
|
}), t2;
|
|
}, e.exports.uvs = function(e2, t2, n, i) {
|
|
var r = new Float32Array(4 * e2.length * 2), o = 0;
|
|
return e2.forEach(function(e3) {
|
|
var s = e3.data, a = s.x + s.width, A = s.y + s.height, l = s.x / t2, c = s.y / n, h = a / t2, d = A / n;
|
|
i && (c = (n - s.y) / n, d = (n - A) / n), r[o++] = l, r[o++] = c, r[o++] = l, r[o++] = d, r[o++] = h, r[o++] = d, r[o++] = h, r[o++] = c;
|
|
}), r;
|
|
}, e.exports.positions = function(e2) {
|
|
var t2 = new Float32Array(4 * e2.length * 2), n = 0;
|
|
return e2.forEach(function(e3) {
|
|
var i = e3.data, r = e3.position[0] + i.xoffset, o = e3.position[1] + i.yoffset, s = i.width, a = i.height;
|
|
t2[n++] = r, t2[n++] = o, t2[n++] = r, t2[n++] = o + a, t2[n++] = r + s, t2[n++] = o + a, t2[n++] = r + s, t2[n++] = o;
|
|
}), t2;
|
|
};
|
|
}, 5406: (e) => {
|
|
var t2 = /\n/, n = /\s/;
|
|
function i(e2, t3, n2, i2) {
|
|
var r2 = e2.indexOf(t3, n2);
|
|
return r2 === -1 || r2 > i2 ? i2 : r2;
|
|
}
|
|
function r(e2) {
|
|
return n.test(e2);
|
|
}
|
|
function o(e2, t3, n2, i2) {
|
|
return { start: t3, end: t3 + Math.min(i2, n2 - t3) };
|
|
}
|
|
e.exports = function(t3, n2) {
|
|
return e.exports.lines(t3, n2).map(function(e2) {
|
|
return t3.substring(e2.start, e2.end);
|
|
}).join(`
|
|
`);
|
|
}, e.exports.lines = function(e2, n2) {
|
|
if ((n2 = n2 || {}).width === 0 && n2.mode !== "nowrap")
|
|
return [];
|
|
e2 = e2 || "";
|
|
var s = typeof n2.width == "number" ? n2.width : Number.MAX_VALUE, a = Math.max(0, n2.start || 0), A = typeof n2.end == "number" ? n2.end : e2.length, l = n2.mode, c = n2.measure || o;
|
|
return l === "pre" ? function(e3, n3, i2, r2, o2) {
|
|
for (var s2 = [], a2 = i2, A2 = i2;A2 < r2 && A2 < n3.length; A2++) {
|
|
var l2 = n3.charAt(A2), c2 = t2.test(l2);
|
|
if (c2 || A2 === r2 - 1) {
|
|
var h = e3(n3, a2, c2 ? A2 : A2 + 1, o2);
|
|
s2.push(h), a2 = A2 + 1;
|
|
}
|
|
}
|
|
return s2;
|
|
}(c, e2, a, A, s) : function(e3, t3, n3, o2, s2, a2) {
|
|
var A2 = [], l2 = s2;
|
|
for (a2 === "nowrap" && (l2 = Number.MAX_VALUE);n3 < o2 && n3 < t3.length; ) {
|
|
for (var c2 = i(t3, `
|
|
`, n3, o2);n3 < c2 && r(t3.charAt(n3)); )
|
|
n3++;
|
|
var h = e3(t3, n3, c2, l2), d = n3 + (h.end - h.start), u = d + 1;
|
|
if (d < c2) {
|
|
for (;d > n3 && !r(t3.charAt(d)); )
|
|
d--;
|
|
if (d === n3)
|
|
u > n3 + 1 && u--, d = u;
|
|
else
|
|
for (u = d;d > n3 && r(t3.charAt(d - 1)); )
|
|
d--;
|
|
}
|
|
if (d >= n3) {
|
|
var g = e3(t3, n3, d, l2);
|
|
A2.push(g);
|
|
}
|
|
n3 = u;
|
|
}
|
|
return A2;
|
|
}(c, e2, a, A, s, l);
|
|
};
|
|
}, 3558: (e, t2, n) => {
|
|
var i = n(919), r = n(8847), o = n(3216), s = n(4597);
|
|
function a(e2, t3, n2) {
|
|
var i2 = e2;
|
|
return r(t3) ? (n2 = t3, typeof e2 == "string" && (i2 = { uri: e2 })) : i2 = s(t3, { uri: e2 }), i2.callback = n2, i2;
|
|
}
|
|
function A(e2, t3, n2) {
|
|
return l(t3 = a(e2, t3, n2));
|
|
}
|
|
function l(e2) {
|
|
if (e2.callback === undefined)
|
|
throw new Error("callback argument missing");
|
|
var t3 = false, n2 = function(n3, i3, r3) {
|
|
t3 || (t3 = true, e2.callback(n3, i3, r3));
|
|
};
|
|
function i2() {
|
|
var e3 = undefined;
|
|
if (e3 = c.response ? c.response : c.responseText || function(e4) {
|
|
try {
|
|
if (e4.responseType === "document")
|
|
return e4.responseXML;
|
|
var t4 = e4.responseXML && e4.responseXML.documentElement.nodeName === "parsererror";
|
|
if (e4.responseType === "" && !t4)
|
|
return e4.responseXML;
|
|
} catch (e5) {}
|
|
return null;
|
|
}(c), m)
|
|
try {
|
|
e3 = JSON.parse(e3);
|
|
} catch (e4) {}
|
|
return e3;
|
|
}
|
|
function r2(e3) {
|
|
return clearTimeout(h), e3 instanceof Error || (e3 = new Error("" + (e3 || "Unknown XMLHttpRequest Error"))), e3.statusCode = 0, n2(e3, E);
|
|
}
|
|
function s2() {
|
|
if (!l2) {
|
|
var t4;
|
|
clearTimeout(h), t4 = e2.useXDR && c.status === undefined ? 200 : c.status === 1223 ? 204 : c.status;
|
|
var r3 = E, s3 = null;
|
|
return t4 !== 0 ? (r3 = { body: i2(), statusCode: t4, method: u, headers: {}, url: d, rawRequest: c }, c.getAllResponseHeaders && (r3.headers = o(c.getAllResponseHeaders()))) : s3 = new Error("Internal XMLHttpRequest Error"), n2(s3, r3, r3.body);
|
|
}
|
|
}
|
|
var a2, l2, c = e2.xhr || null;
|
|
c || (c = e2.cors || e2.useXDR ? new A.XDomainRequest : new A.XMLHttpRequest);
|
|
var h, d = c.url = e2.uri || e2.url, u = c.method = e2.method || "GET", g = e2.body || e2.data, p = c.headers = e2.headers || {}, f = !!e2.sync, m = false, E = { body: undefined, headers: {}, statusCode: 0, method: u, url: d, rawRequest: c };
|
|
if ("json" in e2 && e2.json !== false && (m = true, p.accept || p.Accept || (p.Accept = "application/json"), u !== "GET" && u !== "HEAD" && (p["content-type"] || p["Content-Type"] || (p["Content-Type"] = "application/json"), g = JSON.stringify(e2.json === true ? g : e2.json))), c.onreadystatechange = function() {
|
|
c.readyState === 4 && setTimeout(s2, 0);
|
|
}, c.onload = s2, c.onerror = r2, c.onprogress = function() {}, c.onabort = function() {
|
|
l2 = true;
|
|
}, c.ontimeout = r2, c.open(u, d, !f, e2.username, e2.password), f || (c.withCredentials = !!e2.withCredentials), !f && e2.timeout > 0 && (h = setTimeout(function() {
|
|
if (!l2) {
|
|
l2 = true, c.abort("timeout");
|
|
var e3 = new Error("XMLHttpRequest timeout");
|
|
e3.code = "ETIMEDOUT", r2(e3);
|
|
}
|
|
}, e2.timeout)), c.setRequestHeader)
|
|
for (a2 in p)
|
|
p.hasOwnProperty(a2) && c.setRequestHeader(a2, p[a2]);
|
|
else if (e2.headers && !function(e3) {
|
|
for (var t4 in e3)
|
|
if (e3.hasOwnProperty(t4))
|
|
return false;
|
|
return true;
|
|
}(e2.headers))
|
|
throw new Error("Headers cannot be set on an XDomainRequest object");
|
|
return "responseType" in e2 && (c.responseType = e2.responseType), "beforeSend" in e2 && typeof e2.beforeSend == "function" && e2.beforeSend(c), c.send(g || null), c;
|
|
}
|
|
e.exports = A, e.exports.default = A, A.XMLHttpRequest = i.XMLHttpRequest || function() {}, A.XDomainRequest = "withCredentials" in new A.XMLHttpRequest ? A.XMLHttpRequest : i.XDomainRequest, function(e2, t3) {
|
|
for (var n2 = 0;n2 < e2.length; n2++)
|
|
t3(e2[n2]);
|
|
}(["get", "put", "post", "patch", "head", "delete"], function(e2) {
|
|
A[e2 === "delete" ? "del" : e2] = function(t3, n2, i2) {
|
|
return (n2 = a(t3, n2, i2)).method = e2.toUpperCase(), l(n2);
|
|
};
|
|
});
|
|
}, 1896: (e) => {
|
|
e.exports = self.DOMParser !== undefined ? function(e2) {
|
|
return new self.DOMParser().parseFromString(e2, "application/xml");
|
|
} : self.ActiveXObject !== undefined && new self.ActiveXObject("Microsoft.XMLDOM") ? function(e2) {
|
|
var t2 = new self.ActiveXObject("Microsoft.XMLDOM");
|
|
return t2.async = "false", t2.loadXML(e2), t2;
|
|
} : function(e2) {
|
|
var t2 = document.createElement("div");
|
|
return t2.innerHTML = e2, t2;
|
|
};
|
|
}, 4597: (e) => {
|
|
e.exports = function() {
|
|
for (var e2 = {}, n = 0;n < arguments.length; n++) {
|
|
var i = arguments[n];
|
|
for (var r in i)
|
|
t2.call(i, r) && (e2[r] = i[r]);
|
|
}
|
|
return e2;
|
|
};
|
|
var t2 = Object.prototype.hasOwnProperty;
|
|
}, 8132: () => {
|
|
window.aframeStats = function(e) {
|
|
var t2 = null, n = e;
|
|
return { update: function() {
|
|
var e2;
|
|
t2("te").set((e2 = n.querySelectorAll("*"), Array.prototype.slice.call(e2).filter(function(e3) {
|
|
return e3.isEntity;
|
|
}), e2.length)), window.performance.getEntriesByName && t2("lt").set(window.performance.getEntriesByName("render-started")[0].startTime.toFixed(0));
|
|
}, start: function() {}, end: function() {}, attach: function(e2) {
|
|
t2 = e2;
|
|
}, values: { te: { caption: "Entities" }, lt: { caption: "Load Time" } }, groups: [{ caption: "A-Frame", values: ["te", "lt"] }], fractions: [] };
|
|
};
|
|
}, 3729: (e) => {
|
|
window.glStats = function() {
|
|
var e2 = null, t2 = 0, n = 0, i = 0, r = 0, o = 0, s = 0, a = 0;
|
|
function A(e3, t3) {
|
|
return function() {
|
|
t3.apply(this, arguments), e3.apply(this, arguments);
|
|
};
|
|
}
|
|
return WebGLRenderingContext.prototype.drawArrays = A(WebGLRenderingContext.prototype.drawArrays, function() {
|
|
t2++, arguments[0] == this.POINTS ? s += arguments[2] : o += arguments[2];
|
|
}), WebGLRenderingContext.prototype.drawElements = A(WebGLRenderingContext.prototype.drawElements, function() {
|
|
n++, r += arguments[1] / 3, o += arguments[1];
|
|
}), WebGLRenderingContext.prototype.useProgram = A(WebGLRenderingContext.prototype.useProgram, function() {
|
|
i++;
|
|
}), WebGLRenderingContext.prototype.bindTexture = A(WebGLRenderingContext.prototype.bindTexture, function() {
|
|
a++;
|
|
}), { update: function() {
|
|
e2("allcalls").set(t2 + n), e2("drawElements").set(n), e2("drawArrays").set(t2), e2("bindTexture").set(a), e2("useProgram").set(i), e2("glfaces").set(r), e2("glvertices").set(o), e2("glpoints").set(s);
|
|
}, start: function() {
|
|
t2 = 0, n = 0, i = 0, r = 0, o = 0, s = 0, a = 0;
|
|
}, end: function() {}, attach: function(t3) {
|
|
e2 = t3;
|
|
}, values: { allcalls: { over: 3000, caption: "Calls (hook)" }, drawelements: { caption: "drawElements (hook)" }, drawarrays: { caption: "drawArrays (hook)" } }, groups: [{ caption: "WebGL", values: ["allcalls", "drawelements", "drawarrays", "useprogram", "bindtexture", "glfaces", "glvertices", "glpoints"] }], fractions: [{ base: "allcalls", steps: ["drawelements", "drawarrays"] }] };
|
|
}, window.threeStats = function(e2) {
|
|
var t2 = null;
|
|
return { update: function() {
|
|
t2("renderer.info.memory.geometries").set(e2.info.memory.geometries), t2("renderer.info.programs").set(e2.info.programs?.length ?? NaN), t2("renderer.info.memory.textures").set(e2.info.memory.textures), t2("renderer.info.render.calls").set(e2.info.render.calls), t2("renderer.info.render.triangles").set(e2.info.render.triangles), t2("renderer.info.render.points").set(e2.info.render.points);
|
|
}, start: function() {}, end: function() {}, attach: function(e3) {
|
|
t2 = e3;
|
|
}, values: { "renderer.info.memory.geometries": { caption: "Geometries" }, "renderer.info.memory.textures": { caption: "Textures" }, "renderer.info.programs": { caption: "Programs" }, "renderer.info.render.calls": { caption: "Calls" }, "renderer.info.render.triangles": { caption: "Triangles", over: 1000 }, "renderer.info.render.points": { caption: "Points" } }, groups: [{ caption: "Three.js - Memory", values: ["renderer.info.memory.geometries", "renderer.info.programs", "renderer.info.memory.textures"] }, { caption: "Three.js - Render", values: ["renderer.info.render.calls", "renderer.info.render.triangles", "renderer.info.render.points"] }], fractions: [] };
|
|
}, window.BrowserStats = function() {
|
|
var e2 = null, t2 = 0, n = 0;
|
|
window.performance && !performance.memory && (performance.memory = { usedJSHeapSize: 0, totalJSHeapSize: 0 }), performance.memory.totalJSHeapSize === 0 && console.warn("totalJSHeapSize === 0... performance.memory is only available in Chrome .");
|
|
var i = Math.log(1024);
|
|
function r(e3) {
|
|
var t3 = Math.floor(Math.log(e3) / i);
|
|
return Math.round(100 * e3 / Math.pow(1024, t3)) / 100;
|
|
}
|
|
return { update: function() {
|
|
t2 = r(performance.memory.usedJSHeapSize), n = r(performance.memory.totalJSHeapSize), e2("memory").set(t2), e2("total").set(n);
|
|
}, start: function() {
|
|
t2 = 0;
|
|
}, end: function() {}, attach: function(t3) {
|
|
e2 = t3;
|
|
}, values: { memory: { caption: "Used Memory", average: true, avgMs: 1000, over: 22 }, total: { caption: "Total Memory" } }, groups: [{ caption: "Browser", values: ["memory", "total"] }], fractions: [{ base: "total", steps: ["memory"] }] };
|
|
}, e.exports = { glStats: window.glStats, threeStats: window.threeStats, BrowserStats: window.BrowserStats };
|
|
}, 282: (e) => {
|
|
(function() {
|
|
"performance" in window == 0 && (window.performance = {});
|
|
var e2 = window.performance;
|
|
if ("now" in e2 == 0) {
|
|
var t2 = Date.now();
|
|
e2.timing && e2.timing.navigationStart && (t2 = e2.timing.navigationStart), e2.now = function() {
|
|
return Date.now() - t2;
|
|
};
|
|
}
|
|
e2.mark || (e2.mark = function() {}), e2.measure || (e2.measure = function() {});
|
|
})(), window.rStats = function(e2) {
|
|
function t2(e3, t3) {
|
|
for (var n2 = Object.keys(e3), i2 = 0, r2 = n2.length;i2 < r2; i2++)
|
|
t3(n2[i2]);
|
|
}
|
|
var n = e2 || {}, i = n.colours || ["#850700", "#c74900", "#fcb300", "#284280", "#4c7c0c"], r = (n.CSSPath ? n.CSSPath : "") + "rStats.css";
|
|
(n.css || ["https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700,300", r]).forEach(function(e3) {
|
|
var t3, n2;
|
|
t3 = e3, (n2 = document.createElement("link")).href = t3, n2.rel = "stylesheet", n2.type = "text/css", document.getElementsByTagName("head")[0].appendChild(n2);
|
|
}), n.values || (n.values = {});
|
|
var o, s, a = 10, A = {};
|
|
function l(e3, t3, n2) {
|
|
var i2 = n2 || {}, r2 = document.createElement("canvas"), o2 = r2.getContext("2d"), s2 = 0, A2 = 0, l2 = i2.color ? i2.color : "#666666", c2 = document.createElement("canvas"), h2 = c2.getContext("2d");
|
|
c2.width = 1, c2.height = 20, h2.fillStyle = "#444444", h2.fillRect(0, 0, 1, 20), h2.fillStyle = l2, h2.fillRect(0, a, 1, a), h2.fillStyle = "#ffffff", h2.globalAlpha = 0.5, h2.fillRect(0, a, 1, 1), h2.globalAlpha = 1;
|
|
var d2 = document.createElement("canvas"), u2 = d2.getContext("2d");
|
|
return d2.width = 1, d2.height = 20, u2.fillStyle = "#444444", u2.fillRect(0, 0, 1, 20), u2.fillStyle = "#b70000", u2.fillRect(0, a, 1, a), u2.globalAlpha = 0.5, u2.fillStyle = "#ffffff", u2.fillRect(0, a, 1, 1), u2.globalAlpha = 1, r2.width = 200, r2.height = a, r2.style.width = r2.width + "px", r2.style.height = r2.height + "px", r2.className = "rs-canvas", e3.appendChild(r2), o2.fillStyle = "#444444", o2.fillRect(0, 0, r2.width, r2.height), { draw: function(e4, t4) {
|
|
(A2 += 0.1 * (e4 - A2)) > (s2 *= 0.99) && (s2 = A2), o2.drawImage(r2, 1, 0, r2.width - 1, r2.height, 0, 0, r2.width - 1, r2.height), t4 ? o2.drawImage(d2, r2.width - 1, r2.height - A2 * r2.height / s2 - a) : o2.drawImage(c2, r2.width - 1, r2.height - A2 * r2.height / s2 - a);
|
|
} };
|
|
}
|
|
function c(e3, n2) {
|
|
var r2 = document.createElement("canvas"), o2 = r2.getContext("2d");
|
|
return r2.width = 200, r2.height = a * n2, r2.style.width = r2.width + "px", r2.style.height = r2.height + "px", r2.className = "rs-canvas", e3.appendChild(r2), o2.fillStyle = "#444444", o2.fillRect(0, 0, r2.width, r2.height), { draw: function(e4) {
|
|
o2.drawImage(r2, 1, 0, r2.width - 1, r2.height, 0, 0, r2.width - 1, r2.height);
|
|
var n3 = 0;
|
|
t2(e4, function(t3) {
|
|
var s2 = e4[t3] * r2.height;
|
|
o2.fillStyle = i[t3], o2.fillRect(r2.width - 1, n3, 1, s2), n3 += s2;
|
|
});
|
|
} };
|
|
}
|
|
function h(e3, t3) {
|
|
var i2, r2 = e3, o2 = 0, a2 = 0, A2 = 0, c2 = 0, h2 = performance.now(), d2 = 0, u2 = document.createElement("div"), g = document.createElement("span"), p = document.createElement("div"), f = document.createTextNode(""), m = n ? n.values[r2.toLowerCase()] : null, E = new l(u2, r2, m), C = false;
|
|
function v(e4) {
|
|
if (m && m.average) {
|
|
c2 += e4, d2++;
|
|
var t4 = performance.now();
|
|
t4 - h2 >= (m.avgMs || 1000) && (A2 = c2 / d2, c2 = 0, h2 = t4, d2 = 0);
|
|
}
|
|
}
|
|
function B() {
|
|
i2 = performance.now(), n.userTimingAPI && performance.mark(r2 + "-start"), C = true;
|
|
}
|
|
function b() {
|
|
o2 = performance.now() - i2, n.userTimingAPI && (performance.mark(r2 + "-end"), C && performance.measure(r2, r2 + "-start", r2 + "-end")), v(o2);
|
|
}
|
|
return g.className = "rs-counter-id", g.textContent = m && m.caption ? m.caption : r2, p.className = "rs-counter-value", p.appendChild(f), u2.appendChild(g), u2.appendChild(p), t3 ? t3.div.appendChild(u2) : s.appendChild(u2), i2 = performance.now(), { set: function(e4) {
|
|
v(o2 = e4);
|
|
}, start: B, tick: function() {
|
|
b(), B();
|
|
}, end: b, frame: function() {
|
|
var e4 = performance.now(), t4 = e4 - i2;
|
|
a2++, t4 > 1000 && (o2 = m && m.interpolate === false ? a2 : 1000 * a2 / t4, a2 = 0, i2 = e4, v(o2));
|
|
}, value: function() {
|
|
return o2;
|
|
}, draw: function() {
|
|
var e4 = m && m.average ? A2 : o2;
|
|
f.nodeValue = Math.round(100 * e4) / 100;
|
|
var t4 = m && (m.below && o2 < m.below || m.over && o2 > m.over);
|
|
E.draw(o2, t4), u2.className = t4 ? "rs-counter-base alarm" : "rs-counter-base";
|
|
} };
|
|
}
|
|
function d(e3) {
|
|
var i2 = e3.toLowerCase();
|
|
if (i2 === undefined && (i2 = "default"), A[i2])
|
|
return A[i2];
|
|
var r2 = null;
|
|
n && n.groups && t2(n.groups, function(e4) {
|
|
var t3 = n.groups[parseInt(e4, 10)];
|
|
r2 || t3.values.indexOf(i2.toLowerCase()) === -1 || (r2 = t3);
|
|
});
|
|
var o2 = new h(i2, r2);
|
|
return A[i2] = o2, o2;
|
|
}
|
|
function u() {
|
|
t2(n.plugins, function(e3) {
|
|
n.plugins[e3].update();
|
|
}), t2(A, function(e3) {
|
|
A[e3].draw();
|
|
}), n && n.fractions && t2(n.fractions, function(e3) {
|
|
var i2 = n.fractions[parseInt(e3, 10)], r2 = [], o2 = A[i2.base.toLowerCase()];
|
|
o2 && (o2 = o2.value(), t2(n.fractions[e3].steps, function(t3) {
|
|
var i3 = n.fractions[e3].steps[parseInt(t3, 10)].toLowerCase(), s2 = A[i3];
|
|
s2 && r2.push(s2.value() / o2);
|
|
})), i2.graph.draw(r2);
|
|
});
|
|
}
|
|
return function() {
|
|
if (n.plugins) {
|
|
n.values || (n.values = {}), n.groups || (n.groups = []), n.fractions || (n.fractions = []);
|
|
for (var e3 = 0;e3 < n.plugins.length; e3++)
|
|
n.plugins[e3].attach(d), t2(n.plugins[e3].values, function(t3) {
|
|
n.values[t3] = n.plugins[e3].values[t3];
|
|
}), n.groups = n.groups.concat(n.plugins[e3].groups), n.fractions = n.fractions.concat(n.plugins[e3].fractions);
|
|
} else
|
|
n.plugins = {};
|
|
(o = document.createElement("div")).className = "rs-base", (s = document.createElement("div")).className = "rs-container", s.style.height = "auto", o.appendChild(s), document.body.appendChild(o), n && (n.groups && t2(n.groups, function(e4) {
|
|
var t3 = n.groups[parseInt(e4, 10)], i2 = document.createElement("div");
|
|
i2.className = "rs-group", t3.div = i2;
|
|
var r2 = document.createElement("h1");
|
|
r2.textContent = t3.caption, r2.addEventListener("click", function(e5) {
|
|
this.classList.toggle("hidden"), e5.preventDefault();
|
|
}.bind(i2)), s.appendChild(r2), s.appendChild(i2);
|
|
}), n.fractions && t2(n.fractions, function(e4) {
|
|
var r2 = n.fractions[parseInt(e4, 10)], o2 = document.createElement("div");
|
|
o2.className = "rs-fraction";
|
|
var A2 = document.createElement("div");
|
|
A2.className = "rs-legend";
|
|
var l2 = 0;
|
|
t2(n.fractions[e4].steps, function(t3) {
|
|
var r3 = document.createElement("p");
|
|
r3.textContent = n.fractions[e4].steps[t3], r3.style.color = i[l2], A2.appendChild(r3), l2++;
|
|
}), o2.appendChild(A2), o2.style.height = l2 * a + "px", r2.div = o2;
|
|
var h2 = new c(o2, l2);
|
|
r2.graph = h2, s.appendChild(o2);
|
|
}));
|
|
}(), function(e3) {
|
|
return e3 ? d(e3) : { element: o, update: u };
|
|
};
|
|
}, e.exports = window.rStats;
|
|
}, 2535: (e) => {
|
|
var t2 = { base64: function(e2, t3) {
|
|
return "data:" + e2 + ";base64," + t3;
|
|
}, isMobile: function() {
|
|
var e2, t3 = false;
|
|
return e2 = navigator.userAgent || navigator.vendor || window.opera, (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e2) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e2.substr(0, 4))) && (t3 = true), t3;
|
|
}, isIOS: function() {
|
|
return /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
|
|
}, isIFrame: function() {
|
|
try {
|
|
return window.self !== window.top;
|
|
} catch (e2) {
|
|
return true;
|
|
}
|
|
}, appendQueryParameter: function(e2, t3, n) {
|
|
var i = e2.indexOf("?") < 0 ? "?" : "&";
|
|
return e2 + (i + t3 + "=") + n;
|
|
}, getQueryParameter: function(e2) {
|
|
e2 = e2.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
|
var t3 = new RegExp("[\\?&]" + e2 + "=([^&#]*)").exec(location.search);
|
|
return t3 === null ? "" : decodeURIComponent(t3[1].replace(/\+/g, " "));
|
|
}, isLandscapeMode: function() {
|
|
return window.orientation == 90 || window.orientation == -90;
|
|
} };
|
|
e.exports = t2;
|
|
}, 5928: (e, t2, n) => {
|
|
var i, r = n(2535);
|
|
e.exports = (i = navigator.userAgent || navigator.vendor || window.opera).match(/iPhone/i) || i.match(/iPod/i) ? function() {
|
|
var e2 = null;
|
|
this.request = function() {
|
|
e2 || (e2 = setInterval(function() {
|
|
window.location.href = "/", setTimeout(window.stop, 0);
|
|
}, 15000));
|
|
}, this.release = function() {
|
|
e2 && (clearInterval(e2), e2 = null);
|
|
};
|
|
} : function() {
|
|
var e2 = document.createElement("video");
|
|
e2.addEventListener("ended", function() {
|
|
e2.play();
|
|
}), this.request = function() {
|
|
e2.paused && (e2.src = r.base64("video/webm", "GkXfowEAAAAAAAAfQoaBAUL3gQFC8oEEQvOBCEKChHdlYm1Ch4ECQoWBAhhTgGcBAAAAAAAH4xFNm3RALE27i1OrhBVJqWZTrIHfTbuMU6uEFlSua1OsggEwTbuMU6uEHFO7a1OsggfG7AEAAAAAAACkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmAQAAAAAAAEUq17GDD0JATYCNTGF2ZjU2LjQwLjEwMVdBjUxhdmY1Ni40MC4xMDFzpJAGSJTMbsLpDt/ySkipgX1fRImIQO1MAAAAAAAWVK5rAQAAAAAAADuuAQAAAAAAADLXgQFzxYEBnIEAIrWcg3VuZIaFVl9WUDmDgQEj44OEO5rKAOABAAAAAAAABrCBsLqBkB9DtnUBAAAAAAAAo+eBAKOmgQAAgKJJg0IAAV4BHsAHBIODCoAACmH2MAAAZxgz4dPSTFi5JACjloED6ACmAECSnABMQAADYAAAWi0quoCjloEH0ACmAECSnABNwAADYAAAWi0quoCjloELuACmAECSnABNgAADYAAAWi0quoCjloEPoACmAECSnABNYAADYAAAWi0quoCjloETiACmAECSnABNIAADYAAAWi0quoAfQ7Z1AQAAAAAAAJTnghdwo5aBAAAApgBAkpwATOAAA2AAAFotKrqAo5aBA+gApgBAkpwATMAAA2AAAFotKrqAo5aBB9AApgBAkpwATIAAA2AAAFotKrqAo5aBC7gApgBAkpwATEAAA2AAAFotKrqAo5aBD6AApgDAkpwAQ2AAA2AAAFotKrqAo5aBE4gApgBAkpwATCAAA2AAAFotKrqAH0O2dQEAAAAAAACU54Iu4KOWgQAAAKYAQJKcAEvAAANgAABaLSq6gKOWgQPoAKYAQJKcAEtgAANgAABaLSq6gKOWgQfQAKYAQJKcAEsAAANgAABaLSq6gKOWgQu4AKYAQJKcAEqAAANgAABaLSq6gKOWgQ+gAKYAQJKcAEogAANgAABaLSq6gKOWgROIAKYAQJKcAEnAAANgAABaLSq6gB9DtnUBAAAAAAAAlOeCRlCjloEAAACmAECSnABJgAADYAAAWi0quoCjloED6ACmAECSnABJIAADYAAAWi0quoCjloEH0ACmAMCSnABDYAADYAAAWi0quoCjloELuACmAECSnABI4AADYAAAWi0quoCjloEPoACmAECSnABIoAADYAAAWi0quoCjloETiACmAECSnABIYAADYAAAWi0quoAfQ7Z1AQAAAAAAAJTngl3Ao5aBAAAApgBAkpwASCAAA2AAAFotKrqAo5aBA+gApgBAkpwASAAAA2AAAFotKrqAo5aBB9AApgBAkpwAR8AAA2AAAFotKrqAo5aBC7gApgBAkpwAR4AAA2AAAFotKrqAo5aBD6AApgBAkpwAR2AAA2AAAFotKrqAo5aBE4gApgBAkpwARyAAA2AAAFotKrqAH0O2dQEAAAAAAACU54J1MKOWgQAAAKYAwJKcAENgAANgAABaLSq6gKOWgQPoAKYAQJKcAEbgAANgAABaLSq6gKOWgQfQAKYAQJKcAEagAANgAABaLSq6gKOWgQu4AKYAQJKcAEaAAANgAABaLSq6gKOWgQ+gAKYAQJKcAEZAAANgAABaLSq6gKOWgROIAKYAQJKcAEYAAANgAABaLSq6gB9DtnUBAAAAAAAAlOeCjKCjloEAAACmAECSnABF4AADYAAAWi0quoCjloED6ACmAECSnABFwAADYAAAWi0quoCjloEH0ACmAECSnABFoAADYAAAWi0quoCjloELuACmAECSnABFgAADYAAAWi0quoCjloEPoACmAMCSnABDYAADYAAAWi0quoCjloETiACmAECSnABFYAADYAAAWi0quoAfQ7Z1AQAAAAAAAJTngqQQo5aBAAAApgBAkpwARUAAA2AAAFotKrqAo5aBA+gApgBAkpwARSAAA2AAAFotKrqAo5aBB9AApgBAkpwARQAAA2AAAFotKrqAo5aBC7gApgBAkpwARQAAA2AAAFotKrqAo5aBD6AApgBAkpwAROAAA2AAAFotKrqAo5aBE4gApgBAkpwARMAAA2AAAFotKrqAH0O2dQEAAAAAAACU54K7gKOWgQAAAKYAQJKcAESgAANgAABaLSq6gKOWgQPoAKYAQJKcAESAAANgAABaLSq6gKOWgQfQAKYAwJKcAENgAANgAABaLSq6gKOWgQu4AKYAQJKcAERgAANgAABaLSq6gKOWgQ+gAKYAQJKcAERAAANgAABaLSq6gKOWgROIAKYAQJKcAEQgAANgAABaLSq6gB9DtnUBAAAAAAAAlOeC0vCjloEAAACmAECSnABEIAADYAAAWi0quoCjloED6ACmAECSnABEAAADYAAAWi0quoCjloEH0ACmAECSnABD4AADYAAAWi0quoCjloELuACmAECSnABDwAADYAAAWi0quoCjloEPoACmAECSnABDoAADYAAAWi0quoCjloETiACmAECSnABDgAADYAAAWi0quoAcU7trAQAAAAAAABG7j7OBALeK94EB8YIBd/CBAw=="), e2.play());
|
|
}, this.release = function() {
|
|
e2.pause(), e2.src = "";
|
|
};
|
|
};
|
|
}, 8217: (e, t2, n) => {
|
|
n.d(t2, { A: () => v });
|
|
var i = n(963), r = n.n(i), o = n(9089), s = n.n(o), a = n(6492), A = n.n(a), l = new URL(n(9169), n.b), c = new URL(n(6085), n.b), h = new URL(n(3931), n.b), d = new URL(n(7889), n.b), u = new URL(n(6517), n.b), g = s()(r()), p = A()(l), f = A()(c), m = A()(h), E = A()(d), C = A()(u);
|
|
g.push([e.id, `/* .a-fullscreen means not embedded. */
|
|
html.a-fullscreen {
|
|
bottom: 0;
|
|
left: 0;
|
|
position: fixed;
|
|
right: 0;
|
|
top: 0;
|
|
}
|
|
|
|
html.a-fullscreen body {
|
|
height: 100%;
|
|
margin: 0;
|
|
overflow: hidden;
|
|
padding: 0;
|
|
width: 100%;
|
|
}
|
|
|
|
/* Class is removed when doing <a-scene embedded>. */
|
|
html.a-fullscreen .a-canvas {
|
|
width: 100% !important;
|
|
height: 100% !important;
|
|
top: 0 !important;
|
|
left: 0 !important;
|
|
right: 0 !important;
|
|
bottom: 0 !important;
|
|
position: fixed !important;
|
|
}
|
|
|
|
html:not(.a-fullscreen) .a-enter-vr,
|
|
html:not(.a-fullscreen) .a-enter-ar {
|
|
right: 5px;
|
|
bottom: 5px;
|
|
}
|
|
|
|
html:not(.a-fullscreen) .a-enter-ar {
|
|
right: 60px;
|
|
}
|
|
|
|
/* In chrome mobile the user agent stylesheet set it to white */
|
|
:-webkit-full-screen {
|
|
background-color: transparent;
|
|
}
|
|
|
|
.a-hidden {
|
|
display: none !important;
|
|
}
|
|
|
|
.a-canvas {
|
|
height: 100%;
|
|
left: 0;
|
|
position: absolute;
|
|
top: 0;
|
|
width: 100%;
|
|
}
|
|
|
|
.a-canvas.a-grab-cursor:hover {
|
|
cursor: grab;
|
|
cursor: -moz-grab;
|
|
cursor: -webkit-grab;
|
|
}
|
|
|
|
canvas.a-canvas.a-mouse-cursor-hover:hover {
|
|
cursor: pointer;
|
|
}
|
|
|
|
.a-inspector-loader {
|
|
background-color: #ed3160;
|
|
position: fixed;
|
|
left: 3px;
|
|
top: 3px;
|
|
padding: 6px 10px;
|
|
color: #fff;
|
|
text-decoration: none;
|
|
font-size: 12px;
|
|
font-family: Roboto,sans-serif;
|
|
text-align: center;
|
|
z-index: 99999;
|
|
width: 204px;
|
|
}
|
|
|
|
/* Inspector loader animation */
|
|
@keyframes dots-1 { from { opacity: 0; } 25% { opacity: 1; } }
|
|
@keyframes dots-2 { from { opacity: 0; } 50% { opacity: 1; } }
|
|
@keyframes dots-3 { from { opacity: 0; } 75% { opacity: 1; } }
|
|
@-webkit-keyframes dots-1 { from { opacity: 0; } 25% { opacity: 1; } }
|
|
@-webkit-keyframes dots-2 { from { opacity: 0; } 50% { opacity: 1; } }
|
|
@-webkit-keyframes dots-3 { from { opacity: 0; } 75% { opacity: 1; } }
|
|
|
|
.a-inspector-loader .dots span {
|
|
animation: dots-1 2s infinite steps(1);
|
|
-webkit-animation: dots-1 2s infinite steps(1);
|
|
}
|
|
|
|
.a-inspector-loader .dots span:first-child + span {
|
|
animation-name: dots-2;
|
|
-webkit-animation-name: dots-2;
|
|
}
|
|
|
|
.a-inspector-loader .dots span:first-child + span + span {
|
|
animation-name: dots-3;
|
|
-webkit-animation-name: dots-3;
|
|
}
|
|
|
|
a-scene {
|
|
display: block;
|
|
position: relative;
|
|
height: 100%;
|
|
width: 100%;
|
|
}
|
|
|
|
a-assets,
|
|
a-scene video,
|
|
a-scene img,
|
|
a-scene audio {
|
|
display: none;
|
|
}
|
|
|
|
.a-enter-vr-modal,
|
|
.a-orientation-modal {
|
|
font-family: Consolas, Andale Mono, Courier New, monospace;
|
|
}
|
|
|
|
.a-enter-vr-modal a {
|
|
border-bottom: 1px solid #fff;
|
|
padding: 2px 0;
|
|
text-decoration: none;
|
|
transition: .1s color ease-in;
|
|
}
|
|
|
|
.a-enter-vr-modal a:hover {
|
|
background-color: #fff;
|
|
color: #111;
|
|
padding: 2px 4px;
|
|
position: relative;
|
|
left: -4px;
|
|
}
|
|
|
|
.a-enter-vr,
|
|
.a-enter-ar {
|
|
font-family: sans-serif, monospace;
|
|
font-size: 13px;
|
|
width: 100%;
|
|
font-weight: 200;
|
|
line-height: 16px;
|
|
position: absolute;
|
|
right: 20px;
|
|
bottom: 20px;
|
|
}
|
|
|
|
.a-enter-ar.xr {
|
|
right: 90px;
|
|
}
|
|
|
|
.a-enter-vr-button,
|
|
.a-enter-vr-modal,
|
|
.a-enter-vr-modal a {
|
|
color: #fff;
|
|
user-select: none;
|
|
outline: none;
|
|
}
|
|
|
|
.a-enter-vr-button {
|
|
background: rgba(0, 0, 0, 0.35) url(${p}) 50% 50% no-repeat;
|
|
}
|
|
|
|
.a-enter-ar-button {
|
|
background: rgba(0, 0, 0, 0.20) url(${f}) 50% 50% no-repeat;
|
|
}
|
|
|
|
.a-enter-vr.fullscreen .a-enter-vr-button {
|
|
background-image: url(${m});
|
|
}
|
|
|
|
.a-enter-vr-button,
|
|
.a-enter-ar-button {
|
|
background-size: 90% 90%;
|
|
border: 0;
|
|
bottom: 0;
|
|
cursor: pointer;
|
|
min-width: 58px;
|
|
min-height: 34px;
|
|
/* 1.74418604651 */
|
|
/*
|
|
In order to keep the aspect ratio when resizing
|
|
padding-top percentages are relative to the containing block's width.
|
|
http://stackoverflow.com/questions/12121090/responsively-change-div-size-keeping-aspect-ratio
|
|
*/
|
|
padding-right: 0;
|
|
padding-top: 0;
|
|
position: absolute;
|
|
right: 0;
|
|
transition: background-color .05s ease;
|
|
-webkit-transition: background-color .05s ease;
|
|
z-index: 9999;
|
|
border-radius: 8px;
|
|
touch-action: manipulation; /* Prevent iOS double tap zoom on the button */
|
|
}
|
|
|
|
.a-enter-ar-button {
|
|
background-size: 100% 90%;
|
|
border-radius: 7px;
|
|
}
|
|
|
|
.a-enter-ar-button:active,
|
|
.a-enter-ar-button:hover,
|
|
.a-enter-vr-button:active,
|
|
.a-enter-vr-button:hover {
|
|
background-color: #ef2d5e;
|
|
}
|
|
|
|
.a-enter-vr-button.resethover {
|
|
background-color: rgba(0, 0, 0, 0.35);
|
|
}
|
|
|
|
.a-enter-vr-modal {
|
|
background-color: #666;
|
|
border-radius: 0;
|
|
display: none;
|
|
min-height: 32px;
|
|
margin-right: 70px;
|
|
padding: 9px;
|
|
width: 280px;
|
|
right: 2%;
|
|
position: absolute;
|
|
}
|
|
|
|
.a-enter-vr-modal:after {
|
|
border-bottom: 10px solid transparent;
|
|
border-left: 10px solid #666;
|
|
border-top: 10px solid transparent;
|
|
display: inline-block;
|
|
content: '';
|
|
position: absolute;
|
|
right: -5px;
|
|
top: 5px;
|
|
width: 0;
|
|
height: 0;
|
|
}
|
|
|
|
.a-enter-vr-modal p,
|
|
.a-enter-vr-modal a {
|
|
display: inline;
|
|
}
|
|
|
|
.a-enter-vr-modal p {
|
|
margin: 0;
|
|
}
|
|
|
|
.a-enter-vr-modal p:after {
|
|
content: ' ';
|
|
}
|
|
|
|
.a-orientation-modal {
|
|
background: rgba(244, 244, 244, 1) url(${E}) center no-repeat;
|
|
background-size: 50% 50%;
|
|
bottom: 0;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
left: 0;
|
|
line-height: 20px;
|
|
right: 0;
|
|
position: fixed;
|
|
top: 0;
|
|
z-index: 9999999;
|
|
}
|
|
|
|
.a-orientation-modal:after {
|
|
color: #666;
|
|
content: "Insert phone into Cardboard holder.";
|
|
display: block;
|
|
position: absolute;
|
|
text-align: center;
|
|
top: 70%;
|
|
transform: translateY(-70%);
|
|
width: 100%;
|
|
}
|
|
|
|
.a-orientation-modal button {
|
|
background: url(${C}) no-repeat;
|
|
border: none;
|
|
height: 50px;
|
|
text-indent: -9999px;
|
|
width: 50px;
|
|
}
|
|
|
|
.a-loader-title {
|
|
background-color: rgba(0, 0, 0, 0.6);
|
|
font-family: sans-serif, monospace;
|
|
text-align: center;
|
|
font-size: 20px;
|
|
height: 50px;
|
|
font-weight: 300;
|
|
line-height: 50px;
|
|
position: absolute;
|
|
right: 0px;
|
|
left: 0px;
|
|
top: 0px;
|
|
color: white;
|
|
}
|
|
|
|
.a-modal {
|
|
position: absolute;
|
|
background: rgba(0, 0, 0, 0.60);
|
|
background-size: 50% 50%;
|
|
bottom: 0;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
left: 0;
|
|
line-height: 20px;
|
|
right: 0;
|
|
position: fixed;
|
|
top: 0;
|
|
z-index: 9999999;
|
|
}
|
|
|
|
.a-dialog {
|
|
position: relative;
|
|
left: 50%;
|
|
top: 50%;
|
|
transform: translate(-50%, -50%);
|
|
z-index: 199995;
|
|
width: 300px;
|
|
height: 200px;
|
|
background-size: contain;
|
|
background-color: white;
|
|
font-family: sans-serif, monospace;
|
|
font-size: 20px;
|
|
border-radius: 3px;
|
|
padding: 6px;
|
|
}
|
|
|
|
.a-dialog-text-container {
|
|
width: 100%;
|
|
height: 70%;
|
|
align-self: flex-start;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-content: center;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.a-dialog-text {
|
|
display: inline-block;
|
|
font-weight: normal;
|
|
font-size: 14pt;
|
|
margin: 8px;
|
|
}
|
|
|
|
.a-dialog-buttons-container {
|
|
display: inline-flex;
|
|
align-self: flex-end;
|
|
width: 100%;
|
|
height: 30%;
|
|
}
|
|
|
|
.a-dialog-button {
|
|
cursor: pointer;
|
|
align-self: center;
|
|
opacity: 0.9;
|
|
height: 80%;
|
|
width: 50%;
|
|
font-size: 12pt;
|
|
margin: 4px;
|
|
border-radius: 2px;
|
|
text-align:center;
|
|
border: none;
|
|
display: inline-block;
|
|
-webkit-transition: all 0.25s ease-in-out;
|
|
transition: all 0.25s ease-in-out;
|
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.10), 0 1px 2px rgba(0, 0, 0, 0.20);
|
|
user-select: none;
|
|
}
|
|
|
|
.a-dialog-permission-button:hover {
|
|
box-shadow: 0 7px 14px rgba(0,0,0,0.20), 0 2px 2px rgba(0,0,0,0.20);
|
|
}
|
|
|
|
.a-dialog-allow-button {
|
|
background-color: #00ceff;
|
|
}
|
|
|
|
.a-dialog-deny-button {
|
|
background-color: #ff005b;
|
|
}
|
|
|
|
.a-dialog-ok-button {
|
|
background-color: #00ceff;
|
|
width: 100%;
|
|
}
|
|
|
|
.a-dom-overlay:not(.a-no-style) {
|
|
overflow: hidden;
|
|
position: absolute;
|
|
pointer-events: none;
|
|
box-sizing: border-box;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
top: 0;
|
|
padding: 1em;
|
|
}
|
|
|
|
.a-dom-overlay:not(.a-no-style)>* {
|
|
pointer-events: auto;
|
|
}
|
|
`, "", { version: 3, sources: ["webpack://./src/style/aframe.css"], names: [], mappings: "AAAA,sCAAsC;AACtC;EACE,SAAS;EACT,OAAO;EACP,eAAe;EACf,QAAQ;EACR,MAAM;AACR;;AAEA;EACE,YAAY;EACZ,SAAS;EACT,gBAAgB;EAChB,UAAU;EACV,WAAW;AACb;;AAEA,oDAAoD;AACpD;EACE,sBAAsB;EACtB,uBAAuB;EACvB,iBAAiB;EACjB,kBAAkB;EAClB,mBAAmB;EACnB,oBAAoB;EACpB,0BAA0B;AAC5B;;AAEA;;EAEE,UAAU;EACV,WAAW;AACb;;AAEA;EACE,WAAW;AACb;;AAEA,gEAAgE;AAChE;EACE,6BAA6B;AAC/B;;AAEA;EACE,wBAAwB;AAC1B;;AAEA;EACE,YAAY;EACZ,OAAO;EACP,kBAAkB;EAClB,MAAM;EACN,WAAW;AACb;;AAEA;EACE,YAAY;EACZ,iBAAiB;EACjB,oBAAoB;AACtB;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,yBAAyB;EACzB,eAAe;EACf,SAAS;EACT,QAAQ;EACR,iBAAiB;EACjB,WAAW;EACX,qBAAqB;EACrB,eAAe;EACf,8BAA8B;EAC9B,kBAAkB;EAClB,cAAc;EACd,YAAY;AACd;;AAEA,+BAA+B;AAC/B,oBAAoB,OAAO,UAAU,EAAE,EAAE,MAAM,UAAU,EAAE,EAAE;AAC7D,oBAAoB,OAAO,UAAU,EAAE,EAAE,MAAM,UAAU,EAAE,EAAE;AAC7D,oBAAoB,OAAO,UAAU,EAAE,EAAE,MAAM,UAAU,EAAE,EAAE;AAC7D,4BAA4B,OAAO,UAAU,EAAE,EAAE,MAAM,UAAU,EAAE,EAAE;AACrE,4BAA4B,OAAO,UAAU,EAAE,EAAE,MAAM,UAAU,EAAE,EAAE;AACrE,4BAA4B,OAAO,UAAU,EAAE,EAAE,MAAM,UAAU,EAAE,EAAE;;AAErE;EACE,sCAAsC;EACtC,8CAA8C;AAChD;;AAEA;EACE,sBAAsB;EACtB,8BAA8B;AAChC;;AAEA;EACE,sBAAsB;EACtB,8BAA8B;AAChC;;AAEA;EACE,cAAc;EACd,kBAAkB;EAClB,YAAY;EACZ,WAAW;AACb;;AAEA;;;;EAIE,aAAa;AACf;;AAEA;;EAEE,0DAA0D;AAC5D;;AAEA;EACE,6BAA6B;EAC7B,cAAc;EACd,qBAAqB;EACrB,6BAA6B;AAC/B;;AAEA;EACE,sBAAsB;EACtB,WAAW;EACX,gBAAgB;EAChB,kBAAkB;EAClB,UAAU;AACZ;;AAEA;;EAEE,kCAAkC;EAClC,eAAe;EACf,WAAW;EACX,gBAAgB;EAChB,iBAAiB;EACjB,kBAAkB;EAClB,WAAW;EACX,YAAY;AACd;;AAEA;EACE,WAAW;AACb;;AAEA;;;EAGE,WAAW;EACX,iBAAiB;EACjB,aAAa;AACf;;AAEA;EACE,yFAA4qB;AAC9qB;;AAEA;EACE,yFAAkzB;AACpzB;;AAEA;EACE,yDAA2qK;AAC7qK;;AAEA;;EAEE,wBAAwB;EACxB,SAAS;EACT,SAAS;EACT,eAAe;EACf,eAAe;EACf,gBAAgB;EAChB,kBAAkB;EAClB;;;;GAIC;EACD,gBAAgB;EAChB,cAAc;EACd,kBAAkB;EAClB,QAAQ;EACR,sCAAsC;EACtC,8CAA8C;EAC9C,aAAa;EACb,kBAAkB;EAClB,0BAA0B,EAAE,8CAA8C;AAC5E;;AAEA;EACE,yBAAyB;EACzB,kBAAkB;AACpB;;AAEA;;;;EAIE,yBAAyB;AAC3B;;AAEA;EACE,qCAAqC;AACvC;;AAEA;EACE,sBAAsB;EACtB,gBAAgB;EAChB,aAAa;EACb,gBAAgB;EAChB,kBAAkB;EAClB,YAAY;EACZ,YAAY;EACZ,SAAS;EACT,kBAAkB;AACpB;;AAEA;EACE,qCAAqC;EACrC,4BAA4B;EAC5B,kCAAkC;EAClC,qBAAqB;EACrB,WAAW;EACX,kBAAkB;EAClB,WAAW;EACX,QAAQ;EACR,QAAQ;EACR,SAAS;AACX;;AAEA;;EAEE,eAAe;AACjB;;AAEA;EACE,SAAS;AACX;;AAEA;EACE,YAAY;AACd;;AAEA;EACE,2FAAivF;EACjvF,wBAAwB;EACxB,SAAS;EACT,eAAe;EACf,gBAAgB;EAChB,OAAO;EACP,iBAAiB;EACjB,QAAQ;EACR,eAAe;EACf,MAAM;EACN,gBAAgB;AAClB;;AAEA;EACE,WAAW;EACX,8CAA8C;EAC9C,cAAc;EACd,kBAAkB;EAClB,kBAAkB;EAClB,QAAQ;EACR,2BAA2B;EAC3B,WAAW;AACb;;AAEA;EACE,6DAA25B;EAC35B,YAAY;EACZ,YAAY;EACZ,oBAAoB;EACpB,WAAW;AACb;;AAEA;EACE,oCAAoC;EACpC,kCAAkC;EAClC,kBAAkB;EAClB,eAAe;EACf,YAAY;EACZ,gBAAgB;EAChB,iBAAiB;EACjB,kBAAkB;EAClB,UAAU;EACV,SAAS;EACT,QAAQ;EACR,YAAY;AACd;;AAEA;EACE,kBAAkB;EAClB,+BAA+B;EAC/B,wBAAwB;EACxB,SAAS;EACT,eAAe;EACf,gBAAgB;EAChB,OAAO;EACP,iBAAiB;EACjB,QAAQ;EACR,eAAe;EACf,MAAM;EACN,gBAAgB;AAClB;;AAEA;EACE,kBAAkB;EAClB,SAAS;EACT,QAAQ;EACR,gCAAgC;EAChC,eAAe;EACf,YAAY;EACZ,aAAa;EACb,wBAAwB;EACxB,uBAAuB;EACvB,kCAAkC;EAClC,eAAe;EACf,kBAAkB;EAClB,YAAY;AACd;;AAEA;EACE,WAAW;EACX,WAAW;EACX,sBAAsB;EACtB,aAAa;EACb,uBAAuB;EACvB,qBAAqB;EACrB,sBAAsB;AACxB;;AAEA;EACE,qBAAqB;EACrB,mBAAmB;EACnB,eAAe;EACf,WAAW;AACb;;AAEA;EACE,oBAAoB;EACpB,oBAAoB;EACpB,WAAW;EACX,WAAW;AACb;;AAEA;EACE,eAAe;EACf,kBAAkB;EAClB,YAAY;EACZ,WAAW;EACX,UAAU;EACV,eAAe;EACf,WAAW;EACX,kBAAkB;EAClB,iBAAiB;EACjB,YAAY;EACZ,qBAAqB;EACrB,yCAAyC;EACzC,iCAAiC;EACjC,wEAAwE;EACxE,iBAAiB;AACnB;;AAEA;EACE,mEAAmE;AACrE;;AAEA;EACE,yBAAyB;AAC3B;;AAEA;EACE,yBAAyB;AAC3B;;AAEA;EACE,yBAAyB;EACzB,WAAW;AACb;;AAEA;EACE,gBAAgB;EAChB,kBAAkB;EAClB,oBAAoB;EACpB,sBAAsB;EACtB,SAAS;EACT,OAAO;EACP,QAAQ;EACR,MAAM;EACN,YAAY;AACd;;AAEA;EACE,oBAAoB;AACtB", sourcesContent: [`/* .a-fullscreen means not embedded. */
|
|
html.a-fullscreen {
|
|
bottom: 0;
|
|
left: 0;
|
|
position: fixed;
|
|
right: 0;
|
|
top: 0;
|
|
}
|
|
|
|
html.a-fullscreen body {
|
|
height: 100%;
|
|
margin: 0;
|
|
overflow: hidden;
|
|
padding: 0;
|
|
width: 100%;
|
|
}
|
|
|
|
/* Class is removed when doing <a-scene embedded>. */
|
|
html.a-fullscreen .a-canvas {
|
|
width: 100% !important;
|
|
height: 100% !important;
|
|
top: 0 !important;
|
|
left: 0 !important;
|
|
right: 0 !important;
|
|
bottom: 0 !important;
|
|
position: fixed !important;
|
|
}
|
|
|
|
html:not(.a-fullscreen) .a-enter-vr,
|
|
html:not(.a-fullscreen) .a-enter-ar {
|
|
right: 5px;
|
|
bottom: 5px;
|
|
}
|
|
|
|
html:not(.a-fullscreen) .a-enter-ar {
|
|
right: 60px;
|
|
}
|
|
|
|
/* In chrome mobile the user agent stylesheet set it to white */
|
|
:-webkit-full-screen {
|
|
background-color: transparent;
|
|
}
|
|
|
|
.a-hidden {
|
|
display: none !important;
|
|
}
|
|
|
|
.a-canvas {
|
|
height: 100%;
|
|
left: 0;
|
|
position: absolute;
|
|
top: 0;
|
|
width: 100%;
|
|
}
|
|
|
|
.a-canvas.a-grab-cursor:hover {
|
|
cursor: grab;
|
|
cursor: -moz-grab;
|
|
cursor: -webkit-grab;
|
|
}
|
|
|
|
canvas.a-canvas.a-mouse-cursor-hover:hover {
|
|
cursor: pointer;
|
|
}
|
|
|
|
.a-inspector-loader {
|
|
background-color: #ed3160;
|
|
position: fixed;
|
|
left: 3px;
|
|
top: 3px;
|
|
padding: 6px 10px;
|
|
color: #fff;
|
|
text-decoration: none;
|
|
font-size: 12px;
|
|
font-family: Roboto,sans-serif;
|
|
text-align: center;
|
|
z-index: 99999;
|
|
width: 204px;
|
|
}
|
|
|
|
/* Inspector loader animation */
|
|
@keyframes dots-1 { from { opacity: 0; } 25% { opacity: 1; } }
|
|
@keyframes dots-2 { from { opacity: 0; } 50% { opacity: 1; } }
|
|
@keyframes dots-3 { from { opacity: 0; } 75% { opacity: 1; } }
|
|
@-webkit-keyframes dots-1 { from { opacity: 0; } 25% { opacity: 1; } }
|
|
@-webkit-keyframes dots-2 { from { opacity: 0; } 50% { opacity: 1; } }
|
|
@-webkit-keyframes dots-3 { from { opacity: 0; } 75% { opacity: 1; } }
|
|
|
|
.a-inspector-loader .dots span {
|
|
animation: dots-1 2s infinite steps(1);
|
|
-webkit-animation: dots-1 2s infinite steps(1);
|
|
}
|
|
|
|
.a-inspector-loader .dots span:first-child + span {
|
|
animation-name: dots-2;
|
|
-webkit-animation-name: dots-2;
|
|
}
|
|
|
|
.a-inspector-loader .dots span:first-child + span + span {
|
|
animation-name: dots-3;
|
|
-webkit-animation-name: dots-3;
|
|
}
|
|
|
|
a-scene {
|
|
display: block;
|
|
position: relative;
|
|
height: 100%;
|
|
width: 100%;
|
|
}
|
|
|
|
a-assets,
|
|
a-scene video,
|
|
a-scene img,
|
|
a-scene audio {
|
|
display: none;
|
|
}
|
|
|
|
.a-enter-vr-modal,
|
|
.a-orientation-modal {
|
|
font-family: Consolas, Andale Mono, Courier New, monospace;
|
|
}
|
|
|
|
.a-enter-vr-modal a {
|
|
border-bottom: 1px solid #fff;
|
|
padding: 2px 0;
|
|
text-decoration: none;
|
|
transition: .1s color ease-in;
|
|
}
|
|
|
|
.a-enter-vr-modal a:hover {
|
|
background-color: #fff;
|
|
color: #111;
|
|
padding: 2px 4px;
|
|
position: relative;
|
|
left: -4px;
|
|
}
|
|
|
|
.a-enter-vr,
|
|
.a-enter-ar {
|
|
font-family: sans-serif, monospace;
|
|
font-size: 13px;
|
|
width: 100%;
|
|
font-weight: 200;
|
|
line-height: 16px;
|
|
position: absolute;
|
|
right: 20px;
|
|
bottom: 20px;
|
|
}
|
|
|
|
.a-enter-ar.xr {
|
|
right: 90px;
|
|
}
|
|
|
|
.a-enter-vr-button,
|
|
.a-enter-vr-modal,
|
|
.a-enter-vr-modal a {
|
|
color: #fff;
|
|
user-select: none;
|
|
outline: none;
|
|
}
|
|
|
|
.a-enter-vr-button {
|
|
background: rgba(0, 0, 0, 0.35) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='108' height='62' viewBox='0 0 108 62'%3E%3Ctitle%3Eaframe-vrmode-noborder-reduced-tracking%3C/title%3E%3Cpath d='M68.81,21.56H64.23v8.27h4.58a4.13,4.13,0,0,0,3.1-1.09,4.2,4.2,0,0,0,1-3,4.24,4.24,0,0,0-1-3A4.05,4.05,0,0,0,68.81,21.56Z' fill='%23fff'/%3E%3Cpath d='M96,0H12A12,12,0,0,0,0,12V50A12,12,0,0,0,12,62H96a12,12,0,0,0,12-12V12A12,12,0,0,0,96,0ZM41.9,46H34L24,16h8l6,21.84,6-21.84H52Zm39.29,0H73.44L68.15,35.39H64.23V46H57V16H68.81q5.32,0,8.34,2.37a8,8,0,0,1,3,6.69,9.68,9.68,0,0,1-1.27,5.18,8.9,8.9,0,0,1-4,3.34l6.26,12.11Z' fill='%23fff'/%3E%3C/svg%3E") 50% 50% no-repeat;
|
|
}
|
|
|
|
.a-enter-ar-button {
|
|
background: rgba(0, 0, 0, 0.20) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='108' height='62' viewBox='0 0 108 62'%3E%3Ctitle%3Eaframe-armode-noborder-reduced-tracking%3C/title%3E%3Cpath d='M96,0H12A12,12,0,0,0,0,12V50A12,12,0,0,0,12,62H96a12,12,0,0,0,12-12V12A12,12,0,0,0,96,0Zm8,50a8,8,0,0,1-8,8H12a8,8,0,0,1-8-8V12a8,8,0,0,1,8-8H96a8,8,0,0,1,8,8Z' fill='%23fff'/%3E%3Cpath d='M43.35,39.82H32.51L30.45,46H23.88L35,16h5.73L52,46H45.43Zm-9.17-5h7.5L37.91,23.58Z' fill='%23fff'/%3E%3Cpath d='M68.11,35H63.18V46H57V16H68.15q5.31,0,8.2,2.37a8.18,8.18,0,0,1,2.88,6.7,9.22,9.22,0,0,1-1.33,5.12,9.09,9.09,0,0,1-4,3.26l6.49,12.26V46H73.73Zm-4.93-5h5a5.09,5.09,0,0,0,3.6-1.18,4.21,4.21,0,0,0,1.28-3.27,4.56,4.56,0,0,0-1.2-3.34A5,5,0,0,0,68.15,21h-5Z' fill='%23fff'/%3E%3C/svg%3E") 50% 50% no-repeat;
|
|
}
|
|
|
|
.a-enter-vr.fullscreen .a-enter-vr-button {
|
|
background-image: url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8' standalone='no'%3F%3E%3Csvg width='108' height='62' viewBox='0 0 108 62' version='1.1' id='svg320' sodipodi:docname='fullscreen-aframe.svg' xml:space='preserve' inkscape:version='1.2.1 (9c6d41e 2022-07-14)' xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape' xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23' xmlns:cc='http://creativecommons.org/ns%23' xmlns:dc='http://purl.org/dc/elements/1.1/'%3E%3Cdefs id='defs324' /%3E%3Csodipodi:namedview id='namedview322' pagecolor='%23ffffff' bordercolor='%23000000' borderopacity='0.25' inkscape:showpageshadow='2' inkscape:pageopacity='0.0' inkscape:pagecheckerboard='0' inkscape:deskcolor='%23d1d1d1' showgrid='false' inkscape:zoom='3.8064516' inkscape:cx='91.423729' inkscape:cy='-1.4449153' inkscape:window-width='1440' inkscape:window-height='847' inkscape:window-x='32' inkscape:window-y='25' inkscape:window-maximized='0' inkscape:current-layer='svg320' /%3E%3Ctitle id='title312'%3Eaframe-armode-noborder-reduced-tracking%3C/title%3E%3Cpath d='M96 0H12A12 12 0 0 0 0 12V50A12 12 0 0 0 12 62H96a12 12 0 0 0 12-12V12A12 12 0 0 0 96 0Zm8 50a8 8 0 0 1-8 8H12a8 8 0 0 1-8-8V12a8 8 0 0 1 8-8H96a8 8 0 0 1 8 8Z' fill='%23fff' id='path314' style='fill:%23ffffff' /%3E%3Cg id='g356' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g358' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g360' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g362' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g364' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g366' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g368' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g370' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g372' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g374' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g376' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g378' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g380' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g382' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cg id='g384' transform='translate(-206.61017 -232.61864)'%3E%3C/g%3E%3Cmetadata id='metadata561'%3E%3Crdf:RDF%3E%3Ccc:Work rdf:about=''%3E%3Cdc:title%3Eaframe-armode-noborder-reduced-tracking%3C/dc:title%3E%3C/cc:Work%3E%3C/rdf:RDF%3E%3C/metadata%3E%3Cpath d='m 98.168511 40.083649 c 0 -1.303681 -0.998788 -2.358041 -2.239389 -2.358041 -1.230088 0.0031 -2.240892 1.05436 -2.240892 2.358041 v 4.881296 l -9.041661 -9.041662 c -0.874129 -0.875631 -2.288954 -0.875631 -3.16308 0 -0.874129 0.874126 -0.874129 2.293459 0 3.167585 l 8.995101 8.992101 h -4.858767 c -1.323206 0.0031 -2.389583 1.004796 -2.389583 2.239386 0 1.237598 1.066377 2.237888 2.389583 2.237888 h 10.154599 c 1.323206 0 2.388082 -0.998789 2.392587 -2.237888 -0.0044 -0.03305 -0.009 -0.05858 -0.0134 -0.09161 0.0046 -0.04207 0.0134 -0.08712 0.0134 -0.13066 V 40.085172 h -1.52e-4' id='path596' style='fill:%23ffffff%3Bstroke-width:1.50194' /%3E%3Cpath d='m 23.091002 35.921781 -9.026643 9.041662 v -4.881296 c 0 -1.303681 -1.009302 -2.355037 -2.242393 -2.358041 -1.237598 0 -2.237888 1.05436 -2.237888 2.358041 l -0.0031 10.016421 c 0 0.04356 0.01211 0.08862 0.0015 0.130659 -0.0031 0.03153 -0.009 0.05709 -0.01211 0.09161 0.0031 1.239099 1.069379 2.237888 2.391085 2.237888 h 10.156101 c 1.320202 0 2.388079 -1.000291 2.388079 -2.237888 0 -1.234591 -1.067877 -2.236383 -2.388079 -2.239387 h -4.858767 l 8.995101 -8.9921 c 0.871126 -0.874127 0.871126 -2.293459 0 -3.167586 -0.875628 -0.877132 -2.291957 -0.877132 -3.169087 -1.52e-4' id='path598' style='fill:%23ffffff%3Bstroke-width:1.50194' /%3E%3Cpath d='m 84.649572 25.978033 9.041662 -9.041664 v 4.881298 c 0 1.299176 1.010806 2.350532 2.240891 2.355037 1.240601 0 2.23939 -1.055861 2.23939 -2.355037 V 11.798242 c 0 -0.04356 -0.009 -0.08862 -0.0134 -0.127671 0.0044 -0.03153 0.009 -0.06157 0.0134 -0.09313 -0.0044 -1.240598 -1.069379 -2.2393873 -2.391085 -2.2393873 h -10.1546 c -1.323205 0 -2.38958 0.9987893 -2.38958 2.2393873 0 1.233091 1.066375 2.237887 2.38958 2.240891 h 4.858768 l -8.995102 8.9921 c -0.874129 0.872625 -0.874129 2.288954 0 3.161578 0.874127 0.880137 2.288951 0.880137 3.16308 1.5e-4' id='path600' style='fill:%23ffffff%3Bstroke-width:1.50194' /%3E%3Cpath d='m 17.264988 13.822853 h 4.857265 c 1.320202 -0.0031 2.388079 -1.0078 2.388079 -2.240889 0 -1.240601 -1.067877 -2.2393893 -2.388079 -2.2393893 H 11.967654 c -1.321707 0 -2.388082 0.9987883 -2.391085 2.2393893 0.0031 0.03153 0.009 0.06157 0.01211 0.09313 -0.0031 0.03905 -0.0015 0.08262 -0.0015 0.127671 l 0.0031 10.020926 c 0 1.299176 1.00029 2.355038 2.237887 2.355038 1.233092 -0.0044 2.242393 -1.055862 2.242393 -2.355038 v -4.881295 l 9.026644 9.041661 c 0.877132 0.878635 2.293459 0.878635 3.169087 0 0.871125 -0.872624 0.871125 -2.288953 0 -3.161577 l -8.995282 -8.993616' id='path602' style='fill:%23ffffff%3Bstroke-width:1.50194' /%3E%3C/svg%3E");
|
|
}
|
|
|
|
.a-enter-vr-button,
|
|
.a-enter-ar-button {
|
|
background-size: 90% 90%;
|
|
border: 0;
|
|
bottom: 0;
|
|
cursor: pointer;
|
|
min-width: 58px;
|
|
min-height: 34px;
|
|
/* 1.74418604651 */
|
|
/*
|
|
In order to keep the aspect ratio when resizing
|
|
padding-top percentages are relative to the containing block's width.
|
|
http://stackoverflow.com/questions/12121090/responsively-change-div-size-keeping-aspect-ratio
|
|
*/
|
|
padding-right: 0;
|
|
padding-top: 0;
|
|
position: absolute;
|
|
right: 0;
|
|
transition: background-color .05s ease;
|
|
-webkit-transition: background-color .05s ease;
|
|
z-index: 9999;
|
|
border-radius: 8px;
|
|
touch-action: manipulation; /* Prevent iOS double tap zoom on the button */
|
|
}
|
|
|
|
.a-enter-ar-button {
|
|
background-size: 100% 90%;
|
|
border-radius: 7px;
|
|
}
|
|
|
|
.a-enter-ar-button:active,
|
|
.a-enter-ar-button:hover,
|
|
.a-enter-vr-button:active,
|
|
.a-enter-vr-button:hover {
|
|
background-color: #ef2d5e;
|
|
}
|
|
|
|
.a-enter-vr-button.resethover {
|
|
background-color: rgba(0, 0, 0, 0.35);
|
|
}
|
|
|
|
.a-enter-vr-modal {
|
|
background-color: #666;
|
|
border-radius: 0;
|
|
display: none;
|
|
min-height: 32px;
|
|
margin-right: 70px;
|
|
padding: 9px;
|
|
width: 280px;
|
|
right: 2%;
|
|
position: absolute;
|
|
}
|
|
|
|
.a-enter-vr-modal:after {
|
|
border-bottom: 10px solid transparent;
|
|
border-left: 10px solid #666;
|
|
border-top: 10px solid transparent;
|
|
display: inline-block;
|
|
content: '';
|
|
position: absolute;
|
|
right: -5px;
|
|
top: 5px;
|
|
width: 0;
|
|
height: 0;
|
|
}
|
|
|
|
.a-enter-vr-modal p,
|
|
.a-enter-vr-modal a {
|
|
display: inline;
|
|
}
|
|
|
|
.a-enter-vr-modal p {
|
|
margin: 0;
|
|
}
|
|
|
|
.a-enter-vr-modal p:after {
|
|
content: ' ';
|
|
}
|
|
|
|
.a-orientation-modal {
|
|
background: rgba(244, 244, 244, 1) url(data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20xmlns%3Axlink%3D%22http%3A//www.w3.org/1999/xlink%22%20version%3D%221.1%22%20x%3D%220px%22%20y%3D%220px%22%20viewBox%3D%220%200%2090%2090%22%20enable-background%3D%22new%200%200%2090%2090%22%20xml%3Aspace%3D%22preserve%22%3E%3Cpolygon%20points%3D%220%2C0%200%2C0%200%2C0%20%22%3E%3C/polygon%3E%3Cg%3E%3Cpath%20d%3D%22M71.545%2C48.145h-31.98V20.743c0-2.627-2.138-4.765-4.765-4.765H18.456c-2.628%2C0-4.767%2C2.138-4.767%2C4.765v42.789%20%20%20c0%2C2.628%2C2.138%2C4.766%2C4.767%2C4.766h5.535v0.959c0%2C2.628%2C2.138%2C4.765%2C4.766%2C4.765h42.788c2.628%2C0%2C4.766-2.137%2C4.766-4.765V52.914%20%20%20C76.311%2C50.284%2C74.173%2C48.145%2C71.545%2C48.145z%20M18.455%2C16.935h16.344c2.1%2C0%2C3.808%2C1.708%2C3.808%2C3.808v27.401H37.25V22.636%20%20%20c0-0.264-0.215-0.478-0.479-0.478H16.482c-0.264%2C0-0.479%2C0.214-0.479%2C0.478v36.585c0%2C0.264%2C0.215%2C0.478%2C0.479%2C0.478h7.507v7.644%20%20%20h-5.534c-2.101%2C0-3.81-1.709-3.81-3.81V20.743C14.645%2C18.643%2C16.354%2C16.935%2C18.455%2C16.935z%20M16.96%2C23.116h19.331v25.031h-7.535%20%20%20c-2.628%2C0-4.766%2C2.139-4.766%2C4.768v5.828h-7.03V23.116z%20M71.545%2C73.064H28.757c-2.101%2C0-3.81-1.708-3.81-3.808V52.914%20%20%20c0-2.102%2C1.709-3.812%2C3.81-3.812h42.788c2.1%2C0%2C3.809%2C1.71%2C3.809%2C3.812v16.343C75.354%2C71.356%2C73.645%2C73.064%2C71.545%2C73.064z%22%3E%3C/path%3E%3Cpath%20d%3D%22M28.919%2C58.424c-1.466%2C0-2.659%2C1.193-2.659%2C2.66c0%2C1.466%2C1.193%2C2.658%2C2.659%2C2.658c1.468%2C0%2C2.662-1.192%2C2.662-2.658%20%20%20C31.581%2C59.617%2C30.387%2C58.424%2C28.919%2C58.424z%20M28.919%2C62.786c-0.939%2C0-1.703-0.764-1.703-1.702c0-0.939%2C0.764-1.704%2C1.703-1.704%20%20%20c0.94%2C0%2C1.705%2C0.765%2C1.705%2C1.704C30.623%2C62.022%2C29.858%2C62.786%2C28.919%2C62.786z%22%3E%3C/path%3E%3Cpath%20d%3D%22M69.654%2C50.461H33.069c-0.264%2C0-0.479%2C0.215-0.479%2C0.479v20.288c0%2C0.264%2C0.215%2C0.478%2C0.479%2C0.478h36.585%20%20%20c0.263%2C0%2C0.477-0.214%2C0.477-0.478V50.939C70.131%2C50.676%2C69.917%2C50.461%2C69.654%2C50.461z%20M69.174%2C51.417V70.75H33.548V51.417H69.174z%22%3E%3C/path%3E%3Cpath%20d%3D%22M45.201%2C30.296c6.651%2C0%2C12.233%2C5.351%2C12.551%2C11.977l-3.033-2.638c-0.193-0.165-0.507-0.142-0.675%2C0.048%20%20%20c-0.174%2C0.198-0.153%2C0.501%2C0.045%2C0.676l3.883%2C3.375c0.09%2C0.075%2C0.198%2C0.115%2C0.312%2C0.115c0.141%2C0%2C0.273-0.061%2C0.362-0.166%20%20%20l3.371-3.877c0.173-0.2%2C0.151-0.502-0.047-0.675c-0.194-0.166-0.508-0.144-0.676%2C0.048l-2.592%2C2.979%20%20%20c-0.18-3.417-1.629-6.605-4.099-9.001c-2.538-2.461-5.877-3.817-9.404-3.817c-0.264%2C0-0.479%2C0.215-0.479%2C0.479%20%20%20C44.72%2C30.083%2C44.936%2C30.296%2C45.201%2C30.296z%22%3E%3C/path%3E%3C/g%3E%3C/svg%3E) center no-repeat;
|
|
background-size: 50% 50%;
|
|
bottom: 0;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
left: 0;
|
|
line-height: 20px;
|
|
right: 0;
|
|
position: fixed;
|
|
top: 0;
|
|
z-index: 9999999;
|
|
}
|
|
|
|
.a-orientation-modal:after {
|
|
color: #666;
|
|
content: "Insert phone into Cardboard holder.";
|
|
display: block;
|
|
position: absolute;
|
|
text-align: center;
|
|
top: 70%;
|
|
transform: translateY(-70%);
|
|
width: 100%;
|
|
}
|
|
|
|
.a-orientation-modal button {
|
|
background: url(data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20xmlns%3Axlink%3D%22http%3A//www.w3.org/1999/xlink%22%20version%3D%221.1%22%20x%3D%220px%22%20y%3D%220px%22%20viewBox%3D%220%200%20100%20100%22%20enable-background%3D%22new%200%200%20100%20100%22%20xml%3Aspace%3D%22preserve%22%3E%3Cpath%20fill%3D%22%23000000%22%20d%3D%22M55.209%2C50l17.803-17.803c1.416-1.416%2C1.416-3.713%2C0-5.129c-1.416-1.417-3.713-1.417-5.129%2C0L50.08%2C44.872%20%20L32.278%2C27.069c-1.416-1.417-3.714-1.417-5.129%2C0c-1.417%2C1.416-1.417%2C3.713%2C0%2C5.129L44.951%2C50L27.149%2C67.803%20%20c-1.417%2C1.416-1.417%2C3.713%2C0%2C5.129c0.708%2C0.708%2C1.636%2C1.062%2C2.564%2C1.062c0.928%2C0%2C1.856-0.354%2C2.564-1.062L50.08%2C55.13l17.803%2C17.802%20%20c0.708%2C0.708%2C1.637%2C1.062%2C2.564%2C1.062s1.856-0.354%2C2.564-1.062c1.416-1.416%2C1.416-3.713%2C0-5.129L55.209%2C50z%22%3E%3C/path%3E%3C/svg%3E) no-repeat;
|
|
border: none;
|
|
height: 50px;
|
|
text-indent: -9999px;
|
|
width: 50px;
|
|
}
|
|
|
|
.a-loader-title {
|
|
background-color: rgba(0, 0, 0, 0.6);
|
|
font-family: sans-serif, monospace;
|
|
text-align: center;
|
|
font-size: 20px;
|
|
height: 50px;
|
|
font-weight: 300;
|
|
line-height: 50px;
|
|
position: absolute;
|
|
right: 0px;
|
|
left: 0px;
|
|
top: 0px;
|
|
color: white;
|
|
}
|
|
|
|
.a-modal {
|
|
position: absolute;
|
|
background: rgba(0, 0, 0, 0.60);
|
|
background-size: 50% 50%;
|
|
bottom: 0;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
left: 0;
|
|
line-height: 20px;
|
|
right: 0;
|
|
position: fixed;
|
|
top: 0;
|
|
z-index: 9999999;
|
|
}
|
|
|
|
.a-dialog {
|
|
position: relative;
|
|
left: 50%;
|
|
top: 50%;
|
|
transform: translate(-50%, -50%);
|
|
z-index: 199995;
|
|
width: 300px;
|
|
height: 200px;
|
|
background-size: contain;
|
|
background-color: white;
|
|
font-family: sans-serif, monospace;
|
|
font-size: 20px;
|
|
border-radius: 3px;
|
|
padding: 6px;
|
|
}
|
|
|
|
.a-dialog-text-container {
|
|
width: 100%;
|
|
height: 70%;
|
|
align-self: flex-start;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-content: center;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.a-dialog-text {
|
|
display: inline-block;
|
|
font-weight: normal;
|
|
font-size: 14pt;
|
|
margin: 8px;
|
|
}
|
|
|
|
.a-dialog-buttons-container {
|
|
display: inline-flex;
|
|
align-self: flex-end;
|
|
width: 100%;
|
|
height: 30%;
|
|
}
|
|
|
|
.a-dialog-button {
|
|
cursor: pointer;
|
|
align-self: center;
|
|
opacity: 0.9;
|
|
height: 80%;
|
|
width: 50%;
|
|
font-size: 12pt;
|
|
margin: 4px;
|
|
border-radius: 2px;
|
|
text-align:center;
|
|
border: none;
|
|
display: inline-block;
|
|
-webkit-transition: all 0.25s ease-in-out;
|
|
transition: all 0.25s ease-in-out;
|
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.10), 0 1px 2px rgba(0, 0, 0, 0.20);
|
|
user-select: none;
|
|
}
|
|
|
|
.a-dialog-permission-button:hover {
|
|
box-shadow: 0 7px 14px rgba(0,0,0,0.20), 0 2px 2px rgba(0,0,0,0.20);
|
|
}
|
|
|
|
.a-dialog-allow-button {
|
|
background-color: #00ceff;
|
|
}
|
|
|
|
.a-dialog-deny-button {
|
|
background-color: #ff005b;
|
|
}
|
|
|
|
.a-dialog-ok-button {
|
|
background-color: #00ceff;
|
|
width: 100%;
|
|
}
|
|
|
|
.a-dom-overlay:not(.a-no-style) {
|
|
overflow: hidden;
|
|
position: absolute;
|
|
pointer-events: none;
|
|
box-sizing: border-box;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
top: 0;
|
|
padding: 1em;
|
|
}
|
|
|
|
.a-dom-overlay:not(.a-no-style)>* {
|
|
pointer-events: auto;
|
|
}
|
|
`], sourceRoot: "" }]);
|
|
const v = g;
|
|
}, 2470: (e, t2, n) => {
|
|
n.d(t2, { A: () => a });
|
|
var i = n(963), r = n.n(i), o = n(9089), s = n.n(o)()(r());
|
|
s.push([e.id, `.rs-base {
|
|
background-color: #333;
|
|
color: #fafafa;
|
|
border-radius: 0;
|
|
font: 10px monospace;
|
|
left: 5px;
|
|
line-height: 1em;
|
|
opacity: 0.85;
|
|
overflow: hidden;
|
|
padding: 10px;
|
|
position: fixed;
|
|
top: 5px;
|
|
width: 300px;
|
|
z-index: 10000;
|
|
}
|
|
|
|
.rs-base div.hidden {
|
|
display: none;
|
|
}
|
|
|
|
.rs-base h1 {
|
|
color: #fff;
|
|
cursor: pointer;
|
|
font-size: 1.4em;
|
|
font-weight: 300;
|
|
margin: 0 0 5px;
|
|
padding: 0;
|
|
}
|
|
|
|
.rs-group {
|
|
display: -webkit-box;
|
|
display: -webkit-flex;
|
|
display: flex;
|
|
-webkit-flex-direction: column-reverse;
|
|
flex-direction: column-reverse;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.rs-group:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.rs-counter-base {
|
|
align-items: center;
|
|
display: -webkit-box;
|
|
display: -webkit-flex;
|
|
display: flex;
|
|
height: 10px;
|
|
-webkit-justify-content: space-between;
|
|
justify-content: space-between;
|
|
margin: 2px 0;
|
|
}
|
|
|
|
.rs-counter-base.alarm {
|
|
color: #b70000;
|
|
text-shadow: 0 0 0 #b70000,
|
|
0 0 1px #fff,
|
|
0 0 1px #fff,
|
|
0 0 2px #fff,
|
|
0 0 2px #fff,
|
|
0 0 3px #fff,
|
|
0 0 3px #fff,
|
|
0 0 4px #fff,
|
|
0 0 4px #fff;
|
|
}
|
|
|
|
.rs-counter-id {
|
|
font-weight: 300;
|
|
-webkit-box-ordinal-group: 0;
|
|
-webkit-order: 0;
|
|
order: 0;
|
|
width: 54px;
|
|
}
|
|
|
|
.rs-counter-value {
|
|
font-weight: 300;
|
|
-webkit-box-ordinal-group: 1;
|
|
-webkit-order: 1;
|
|
order: 1;
|
|
text-align: right;
|
|
width: 35px;
|
|
}
|
|
|
|
.rs-canvas {
|
|
-webkit-box-ordinal-group: 2;
|
|
-webkit-order: 2;
|
|
order: 2;
|
|
}
|
|
|
|
@media (min-width: 480px) {
|
|
.rs-base {
|
|
left: 20px;
|
|
top: 20px;
|
|
}
|
|
}
|
|
`, "", { version: 3, sources: ["webpack://./src/style/rStats.css"], names: [], mappings: "AAAA;EACE,sBAAsB;EACtB,cAAc;EACd,gBAAgB;EAChB,oBAAoB;EACpB,SAAS;EACT,gBAAgB;EAChB,aAAa;EACb,gBAAgB;EAChB,aAAa;EACb,eAAe;EACf,QAAQ;EACR,YAAY;EACZ,cAAc;AAChB;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,WAAW;EACX,eAAe;EACf,gBAAgB;EAChB,gBAAgB;EAChB,eAAe;EACf,UAAU;AACZ;;AAEA;EACE,oBAAoB;EACpB,qBAAqB;EACrB,aAAa;EACb,sCAAsC;EACtC,8BAA8B;EAC9B,kBAAkB;AACpB;;AAEA;EACE,gBAAgB;AAClB;;AAEA;EACE,mBAAmB;EACnB,oBAAoB;EACpB,qBAAqB;EACrB,aAAa;EACb,YAAY;EACZ,sCAAsC;EACtC,8BAA8B;EAC9B,aAAa;AACf;;AAEA;EACE,cAAc;EACd;;;;;;;;2BAQyB;AAC3B;;AAEA;EACE,gBAAgB;EAChB,4BAA4B;EAC5B,gBAAgB;EAChB,QAAQ;EACR,WAAW;AACb;;AAEA;EACE,gBAAgB;EAChB,4BAA4B;EAC5B,gBAAgB;EAChB,QAAQ;EACR,iBAAiB;EACjB,WAAW;AACb;;AAEA;EACE,4BAA4B;EAC5B,gBAAgB;EAChB,QAAQ;AACV;;AAEA;EACE;IACE,UAAU;IACV,SAAS;EACX;AACF", sourcesContent: [`.rs-base {
|
|
background-color: #333;
|
|
color: #fafafa;
|
|
border-radius: 0;
|
|
font: 10px monospace;
|
|
left: 5px;
|
|
line-height: 1em;
|
|
opacity: 0.85;
|
|
overflow: hidden;
|
|
padding: 10px;
|
|
position: fixed;
|
|
top: 5px;
|
|
width: 300px;
|
|
z-index: 10000;
|
|
}
|
|
|
|
.rs-base div.hidden {
|
|
display: none;
|
|
}
|
|
|
|
.rs-base h1 {
|
|
color: #fff;
|
|
cursor: pointer;
|
|
font-size: 1.4em;
|
|
font-weight: 300;
|
|
margin: 0 0 5px;
|
|
padding: 0;
|
|
}
|
|
|
|
.rs-group {
|
|
display: -webkit-box;
|
|
display: -webkit-flex;
|
|
display: flex;
|
|
-webkit-flex-direction: column-reverse;
|
|
flex-direction: column-reverse;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.rs-group:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.rs-counter-base {
|
|
align-items: center;
|
|
display: -webkit-box;
|
|
display: -webkit-flex;
|
|
display: flex;
|
|
height: 10px;
|
|
-webkit-justify-content: space-between;
|
|
justify-content: space-between;
|
|
margin: 2px 0;
|
|
}
|
|
|
|
.rs-counter-base.alarm {
|
|
color: #b70000;
|
|
text-shadow: 0 0 0 #b70000,
|
|
0 0 1px #fff,
|
|
0 0 1px #fff,
|
|
0 0 2px #fff,
|
|
0 0 2px #fff,
|
|
0 0 3px #fff,
|
|
0 0 3px #fff,
|
|
0 0 4px #fff,
|
|
0 0 4px #fff;
|
|
}
|
|
|
|
.rs-counter-id {
|
|
font-weight: 300;
|
|
-webkit-box-ordinal-group: 0;
|
|
-webkit-order: 0;
|
|
order: 0;
|
|
width: 54px;
|
|
}
|
|
|
|
.rs-counter-value {
|
|
font-weight: 300;
|
|
-webkit-box-ordinal-group: 1;
|
|
-webkit-order: 1;
|
|
order: 1;
|
|
text-align: right;
|
|
width: 35px;
|
|
}
|
|
|
|
.rs-canvas {
|
|
-webkit-box-ordinal-group: 2;
|
|
-webkit-order: 2;
|
|
order: 2;
|
|
}
|
|
|
|
@media (min-width: 480px) {
|
|
.rs-base {
|
|
left: 20px;
|
|
top: 20px;
|
|
}
|
|
}
|
|
`], sourceRoot: "" }]);
|
|
const a = s;
|
|
}, 7180: (e, t2, n) => {
|
|
n.r(t2), n.d(t2, { default: () => m });
|
|
var i = n(5072), r = n.n(i), o = n(7825), s = n.n(o), a = n(7659), A = n.n(a), l = n(5056), c = n.n(l), h = n(540), d = n.n(h), u = n(1113), g = n.n(u), p = n(8217), f = {};
|
|
f.styleTagTransform = g(), f.setAttributes = c(), f.insert = A().bind(null, "head"), f.domAPI = s(), f.insertStyleElement = d(), r()(p.A, f);
|
|
const m = p.A && p.A.locals ? p.A.locals : undefined;
|
|
}, 9379: (e, t2, n) => {
|
|
n.r(t2), n.d(t2, { default: () => m });
|
|
var i = n(5072), r = n.n(i), o = n(7825), s = n.n(o), a = n(7659), A = n.n(a), l = n(5056), c = n.n(l), h = n(540), d = n.n(h), u = n(1113), g = n.n(u), p = n(2470), f = {};
|
|
f.styleTagTransform = g(), f.setAttributes = c(), f.insert = A().bind(null, "head"), f.domAPI = s(), f.insertStyleElement = d(), r()(p.A, f);
|
|
const m = p.A && p.A.locals ? p.A.locals : undefined;
|
|
}, 5072: (e) => {
|
|
var t2 = [];
|
|
function n(e2) {
|
|
for (var n2 = -1, i2 = 0;i2 < t2.length; i2++)
|
|
if (t2[i2].identifier === e2) {
|
|
n2 = i2;
|
|
break;
|
|
}
|
|
return n2;
|
|
}
|
|
function i(e2, i2) {
|
|
for (var o = {}, s = [], a = 0;a < e2.length; a++) {
|
|
var A = e2[a], l = i2.base ? A[0] + i2.base : A[0], c = o[l] || 0, h = "".concat(l, " ").concat(c);
|
|
o[l] = c + 1;
|
|
var d = n(h), u = { css: A[1], media: A[2], sourceMap: A[3], supports: A[4], layer: A[5] };
|
|
if (d !== -1)
|
|
t2[d].references++, t2[d].updater(u);
|
|
else {
|
|
var g = r(u, i2);
|
|
i2.byIndex = a, t2.splice(a, 0, { identifier: h, updater: g, references: 1 });
|
|
}
|
|
s.push(h);
|
|
}
|
|
return s;
|
|
}
|
|
function r(e2, t3) {
|
|
var n2 = t3.domAPI(t3);
|
|
return n2.update(e2), function(t4) {
|
|
if (t4) {
|
|
if (t4.css === e2.css && t4.media === e2.media && t4.sourceMap === e2.sourceMap && t4.supports === e2.supports && t4.layer === e2.layer)
|
|
return;
|
|
n2.update(e2 = t4);
|
|
} else
|
|
n2.remove();
|
|
};
|
|
}
|
|
e.exports = function(e2, r2) {
|
|
var o = i(e2 = e2 || [], r2 = r2 || {});
|
|
return function(e3) {
|
|
e3 = e3 || [];
|
|
for (var s = 0;s < o.length; s++) {
|
|
var a = n(o[s]);
|
|
t2[a].references--;
|
|
}
|
|
for (var A = i(e3, r2), l = 0;l < o.length; l++) {
|
|
var c = n(o[l]);
|
|
t2[c].references === 0 && (t2[c].updater(), t2.splice(c, 1));
|
|
}
|
|
o = A;
|
|
};
|
|
};
|
|
}, 7659: (e) => {
|
|
var t2 = {};
|
|
e.exports = function(e2, n) {
|
|
var i = function(e3) {
|
|
if (t2[e3] === undefined) {
|
|
var n2 = document.querySelector(e3);
|
|
if (window.HTMLIFrameElement && n2 instanceof window.HTMLIFrameElement)
|
|
try {
|
|
n2 = n2.contentDocument.head;
|
|
} catch (e4) {
|
|
n2 = null;
|
|
}
|
|
t2[e3] = n2;
|
|
}
|
|
return t2[e3];
|
|
}(e2);
|
|
if (!i)
|
|
throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
|
|
i.appendChild(n);
|
|
};
|
|
}, 540: (e) => {
|
|
e.exports = function(e2) {
|
|
var t2 = document.createElement("style");
|
|
return e2.setAttributes(t2, e2.attributes), e2.insert(t2, e2.options), t2;
|
|
};
|
|
}, 5056: (e, t2, n) => {
|
|
e.exports = function(e2) {
|
|
var t3 = n.nc;
|
|
t3 && e2.setAttribute("nonce", t3);
|
|
};
|
|
}, 7825: (e) => {
|
|
e.exports = function(e2) {
|
|
if (typeof document == "undefined")
|
|
return { update: function() {}, remove: function() {} };
|
|
var t2 = e2.insertStyleElement(e2);
|
|
return { update: function(n) {
|
|
(function(e3, t3, n2) {
|
|
var i = "";
|
|
n2.supports && (i += "@supports (".concat(n2.supports, ") {")), n2.media && (i += "@media ".concat(n2.media, " {"));
|
|
var r = n2.layer !== undefined;
|
|
r && (i += "@layer".concat(n2.layer.length > 0 ? " ".concat(n2.layer) : "", " {")), i += n2.css, r && (i += "}"), n2.media && (i += "}"), n2.supports && (i += "}");
|
|
var o = n2.sourceMap;
|
|
o && typeof btoa != "undefined" && (i += `
|
|
/*# sourceMappingURL=data:application/json;base64,`.concat(btoa(unescape(encodeURIComponent(JSON.stringify(o)))), " */")), t3.styleTagTransform(i, e3, t3.options);
|
|
})(t2, e2, n);
|
|
}, remove: function() {
|
|
(function(e3) {
|
|
if (e3.parentNode === null)
|
|
return false;
|
|
e3.parentNode.removeChild(e3);
|
|
})(t2);
|
|
} };
|
|
};
|
|
}, 1113: (e) => {
|
|
e.exports = function(e2, t2) {
|
|
if (t2.styleSheet)
|
|
t2.styleSheet.cssText = e2;
|
|
else {
|
|
for (;t2.firstChild; )
|
|
t2.removeChild(t2.firstChild);
|
|
t2.appendChild(document.createTextNode(e2));
|
|
}
|
|
};
|
|
}, 3931: (e) => {
|
|
e.exports = "data:image/svg+xml,%3C%3Fxml version=%271.0%27 encoding=%27UTF-8%27 standalone=%27no%27%3F%3E%3Csvg width=%27108%27 height=%2762%27 viewBox=%270 0 108 62%27 version=%271.1%27 id=%27svg320%27 sodipodi:docname=%27fullscreen-aframe.svg%27 xml:space=%27preserve%27 inkscape:version=%271.2.1 %289c6d41e 2022-07-14%29%27 xmlns:inkscape=%27http://www.inkscape.org/namespaces/inkscape%27 xmlns:sodipodi=%27http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd%27 xmlns=%27http://www.w3.org/2000/svg%27 xmlns:svg=%27http://www.w3.org/2000/svg%27 xmlns:rdf=%27http://www.w3.org/1999/02/22-rdf-syntax-ns%23%27 xmlns:cc=%27http://creativecommons.org/ns%23%27 xmlns:dc=%27http://purl.org/dc/elements/1.1/%27%3E%3Cdefs id=%27defs324%27 /%3E%3Csodipodi:namedview id=%27namedview322%27 pagecolor=%27%23ffffff%27 bordercolor=%27%23000000%27 borderopacity=%270.25%27 inkscape:showpageshadow=%272%27 inkscape:pageopacity=%270.0%27 inkscape:pagecheckerboard=%270%27 inkscape:deskcolor=%27%23d1d1d1%27 showgrid=%27false%27 inkscape:zoom=%273.8064516%27 inkscape:cx=%2791.423729%27 inkscape:cy=%27-1.4449153%27 inkscape:window-width=%271440%27 inkscape:window-height=%27847%27 inkscape:window-x=%2732%27 inkscape:window-y=%2725%27 inkscape:window-maximized=%270%27 inkscape:current-layer=%27svg320%27 /%3E%3Ctitle id=%27title312%27%3Eaframe-armode-noborder-reduced-tracking%3C/title%3E%3Cpath d=%27M96 0H12A12 12 0 0 0 0 12V50A12 12 0 0 0 12 62H96a12 12 0 0 0 12-12V12A12 12 0 0 0 96 0Zm8 50a8 8 0 0 1-8 8H12a8 8 0 0 1-8-8V12a8 8 0 0 1 8-8H96a8 8 0 0 1 8 8Z%27 fill=%27%23fff%27 id=%27path314%27 style=%27fill:%23ffffff%27 /%3E%3Cg id=%27g356%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g358%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g360%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g362%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g364%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g366%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g368%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g370%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g372%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g374%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g376%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g378%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g380%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g382%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cg id=%27g384%27 transform=%27translate%28-206.61017 -232.61864%29%27%3E%3C/g%3E%3Cmetadata id=%27metadata561%27%3E%3Crdf:RDF%3E%3Ccc:Work rdf:about=%27%27%3E%3Cdc:title%3Eaframe-armode-noborder-reduced-tracking%3C/dc:title%3E%3C/cc:Work%3E%3C/rdf:RDF%3E%3C/metadata%3E%3Cpath d=%27m 98.168511 40.083649 c 0 -1.303681 -0.998788 -2.358041 -2.239389 -2.358041 -1.230088 0.0031 -2.240892 1.05436 -2.240892 2.358041 v 4.881296 l -9.041661 -9.041662 c -0.874129 -0.875631 -2.288954 -0.875631 -3.16308 0 -0.874129 0.874126 -0.874129 2.293459 0 3.167585 l 8.995101 8.992101 h -4.858767 c -1.323206 0.0031 -2.389583 1.004796 -2.389583 2.239386 0 1.237598 1.066377 2.237888 2.389583 2.237888 h 10.154599 c 1.323206 0 2.388082 -0.998789 2.392587 -2.237888 -0.0044 -0.03305 -0.009 -0.05858 -0.0134 -0.09161 0.0046 -0.04207 0.0134 -0.08712 0.0134 -0.13066 V 40.085172 h -1.52e-4%27 id=%27path596%27 style=%27fill:%23ffffff%3Bstroke-width:1.50194%27 /%3E%3Cpath d=%27m 23.091002 35.921781 -9.026643 9.041662 v -4.881296 c 0 -1.303681 -1.009302 -2.355037 -2.242393 -2.358041 -1.237598 0 -2.237888 1.05436 -2.237888 2.358041 l -0.0031 10.016421 c 0 0.04356 0.01211 0.08862 0.0015 0.130659 -0.0031 0.03153 -0.009 0.05709 -0.01211 0.09161 0.0031 1.239099 1.069379 2.237888 2.391085 2.237888 h 10.156101 c 1.320202 0 2.388079 -1.000291 2.388079 -2.237888 0 -1.234591 -1.067877 -2.236383 -2.388079 -2.239387 h -4.858767 l 8.995101 -8.9921 c 0.871126 -0.874127 0.871126 -2.293459 0 -3.167586 -0.875628 -0.877132 -2.291957 -0.877132 -3.169087 -1.52e-4%27 id=%27path598%27 style=%27fill:%23ffffff%3Bstroke-width:1.50194%27 /%3E%3Cpath d=%27m 84.649572 25.978033 9.041662 -9.041664 v 4.881298 c 0 1.299176 1.010806 2.350532 2.240891 2.355037 1.240601 0 2.23939 -1.055861 2.23939 -2.355037 V 11.798242 c 0 -0.04356 -0.009 -0.08862 -0.0134 -0.127671 0.0044 -0.03153 0.009 -0.06157 0.0134 -0.09313 -0.0044 -1.240598 -1.069379 -2.2393873 -2.391085 -2.2393873 h -10.1546 c -1.323205 0 -2.38958 0.9987893 -2.38958 2.2393873 0 1.233091 1.066375 2.237887 2.38958 2.240891 h 4.858768 l -8.995102 8.9921 c -0.874129 0.872625 -0.874129 2.288954 0 3.161578 0.874127 0.880137 2.288951 0.880137 3.16308 1.5e-4%27 id=%27path600%27 style=%27fill:%23ffffff%3Bstroke-width:1.50194%27 /%3E%3Cpath d=%27m 17.264988 13.822853 h 4.857265 c 1.320202 -0.0031 2.388079 -1.0078 2.388079 -2.240889 0 -1.240601 -1.067877 -2.2393893 -2.388079 -2.2393893 H 11.967654 c -1.321707 0 -2.388082 0.9987883 -2.391085 2.2393893 0.0031 0.03153 0.009 0.06157 0.01211 0.09313 -0.0031 0.03905 -0.0015 0.08262 -0.0015 0.127671 l 0.0031 10.020926 c 0 1.299176 1.00029 2.355038 2.237887 2.355038 1.233092 -0.0044 2.242393 -1.055862 2.242393 -2.355038 v -4.881295 l 9.026644 9.041661 c 0.877132 0.878635 2.293459 0.878635 3.169087 0 0.871125 -0.872624 0.871125 -2.288953 0 -3.161577 l -8.995282 -8.993616%27 id=%27path602%27 style=%27fill:%23ffffff%3Bstroke-width:1.50194%27 /%3E%3C/svg%3E";
|
|
}, 6085: (e) => {
|
|
e.exports = "data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27108%27 height=%2762%27 viewBox=%270 0 108 62%27%3E%3Ctitle%3Eaframe-armode-noborder-reduced-tracking%3C/title%3E%3Cpath d=%27M96,0H12A12,12,0,0,0,0,12V50A12,12,0,0,0,12,62H96a12,12,0,0,0,12-12V12A12,12,0,0,0,96,0Zm8,50a8,8,0,0,1-8,8H12a8,8,0,0,1-8-8V12a8,8,0,0,1,8-8H96a8,8,0,0,1,8,8Z%27 fill=%27%23fff%27/%3E%3Cpath d=%27M43.35,39.82H32.51L30.45,46H23.88L35,16h5.73L52,46H45.43Zm-9.17-5h7.5L37.91,23.58Z%27 fill=%27%23fff%27/%3E%3Cpath d=%27M68.11,35H63.18V46H57V16H68.15q5.31,0,8.2,2.37a8.18,8.18,0,0,1,2.88,6.7,9.22,9.22,0,0,1-1.33,5.12,9.09,9.09,0,0,1-4,3.26l6.49,12.26V46H73.73Zm-4.93-5h5a5.09,5.09,0,0,0,3.6-1.18,4.21,4.21,0,0,0,1.28-3.27,4.56,4.56,0,0,0-1.2-3.34A5,5,0,0,0,68.15,21h-5Z%27 fill=%27%23fff%27/%3E%3C/svg%3E";
|
|
}, 9169: (e) => {
|
|
e.exports = "data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27108%27 height=%2762%27 viewBox=%270 0 108 62%27%3E%3Ctitle%3Eaframe-vrmode-noborder-reduced-tracking%3C/title%3E%3Cpath d=%27M68.81,21.56H64.23v8.27h4.58a4.13,4.13,0,0,0,3.1-1.09,4.2,4.2,0,0,0,1-3,4.24,4.24,0,0,0-1-3A4.05,4.05,0,0,0,68.81,21.56Z%27 fill=%27%23fff%27/%3E%3Cpath d=%27M96,0H12A12,12,0,0,0,0,12V50A12,12,0,0,0,12,62H96a12,12,0,0,0,12-12V12A12,12,0,0,0,96,0ZM41.9,46H34L24,16h8l6,21.84,6-21.84H52Zm39.29,0H73.44L68.15,35.39H64.23V46H57V16H68.81q5.32,0,8.34,2.37a8,8,0,0,1,3,6.69,9.68,9.68,0,0,1-1.27,5.18,8.9,8.9,0,0,1-4,3.34l6.26,12.11Z%27 fill=%27%23fff%27/%3E%3C/svg%3E";
|
|
}, 6517: (e) => {
|
|
e.exports = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20xmlns%3Axlink%3D%22http%3A//www.w3.org/1999/xlink%22%20version%3D%221.1%22%20x%3D%220px%22%20y%3D%220px%22%20viewBox%3D%220%200%20100%20100%22%20enable-background%3D%22new%200%200%20100%20100%22%20xml%3Aspace%3D%22preserve%22%3E%3Cpath%20fill%3D%22%23000000%22%20d%3D%22M55.209%2C50l17.803-17.803c1.416-1.416%2C1.416-3.713%2C0-5.129c-1.416-1.417-3.713-1.417-5.129%2C0L50.08%2C44.872%20%20L32.278%2C27.069c-1.416-1.417-3.714-1.417-5.129%2C0c-1.417%2C1.416-1.417%2C3.713%2C0%2C5.129L44.951%2C50L27.149%2C67.803%20%20c-1.417%2C1.416-1.417%2C3.713%2C0%2C5.129c0.708%2C0.708%2C1.636%2C1.062%2C2.564%2C1.062c0.928%2C0%2C1.856-0.354%2C2.564-1.062L50.08%2C55.13l17.803%2C17.802%20%20c0.708%2C0.708%2C1.637%2C1.062%2C2.564%2C1.062s1.856-0.354%2C2.564-1.062c1.416-1.416%2C1.416-3.713%2C0-5.129L55.209%2C50z%22%3E%3C/path%3E%3C/svg%3E";
|
|
}, 7889: (e) => {
|
|
e.exports = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20xmlns%3Axlink%3D%22http%3A//www.w3.org/1999/xlink%22%20version%3D%221.1%22%20x%3D%220px%22%20y%3D%220px%22%20viewBox%3D%220%200%2090%2090%22%20enable-background%3D%22new%200%200%2090%2090%22%20xml%3Aspace%3D%22preserve%22%3E%3Cpolygon%20points%3D%220%2C0%200%2C0%200%2C0%20%22%3E%3C/polygon%3E%3Cg%3E%3Cpath%20d%3D%22M71.545%2C48.145h-31.98V20.743c0-2.627-2.138-4.765-4.765-4.765H18.456c-2.628%2C0-4.767%2C2.138-4.767%2C4.765v42.789%20%20%20c0%2C2.628%2C2.138%2C4.766%2C4.767%2C4.766h5.535v0.959c0%2C2.628%2C2.138%2C4.765%2C4.766%2C4.765h42.788c2.628%2C0%2C4.766-2.137%2C4.766-4.765V52.914%20%20%20C76.311%2C50.284%2C74.173%2C48.145%2C71.545%2C48.145z%20M18.455%2C16.935h16.344c2.1%2C0%2C3.808%2C1.708%2C3.808%2C3.808v27.401H37.25V22.636%20%20%20c0-0.264-0.215-0.478-0.479-0.478H16.482c-0.264%2C0-0.479%2C0.214-0.479%2C0.478v36.585c0%2C0.264%2C0.215%2C0.478%2C0.479%2C0.478h7.507v7.644%20%20%20h-5.534c-2.101%2C0-3.81-1.709-3.81-3.81V20.743C14.645%2C18.643%2C16.354%2C16.935%2C18.455%2C16.935z%20M16.96%2C23.116h19.331v25.031h-7.535%20%20%20c-2.628%2C0-4.766%2C2.139-4.766%2C4.768v5.828h-7.03V23.116z%20M71.545%2C73.064H28.757c-2.101%2C0-3.81-1.708-3.81-3.808V52.914%20%20%20c0-2.102%2C1.709-3.812%2C3.81-3.812h42.788c2.1%2C0%2C3.809%2C1.71%2C3.809%2C3.812v16.343C75.354%2C71.356%2C73.645%2C73.064%2C71.545%2C73.064z%22%3E%3C/path%3E%3Cpath%20d%3D%22M28.919%2C58.424c-1.466%2C0-2.659%2C1.193-2.659%2C2.66c0%2C1.466%2C1.193%2C2.658%2C2.659%2C2.658c1.468%2C0%2C2.662-1.192%2C2.662-2.658%20%20%20C31.581%2C59.617%2C30.387%2C58.424%2C28.919%2C58.424z%20M28.919%2C62.786c-0.939%2C0-1.703-0.764-1.703-1.702c0-0.939%2C0.764-1.704%2C1.703-1.704%20%20%20c0.94%2C0%2C1.705%2C0.765%2C1.705%2C1.704C30.623%2C62.022%2C29.858%2C62.786%2C28.919%2C62.786z%22%3E%3C/path%3E%3Cpath%20d%3D%22M69.654%2C50.461H33.069c-0.264%2C0-0.479%2C0.215-0.479%2C0.479v20.288c0%2C0.264%2C0.215%2C0.478%2C0.479%2C0.478h36.585%20%20%20c0.263%2C0%2C0.477-0.214%2C0.477-0.478V50.939C70.131%2C50.676%2C69.917%2C50.461%2C69.654%2C50.461z%20M69.174%2C51.417V70.75H33.548V51.417H69.174z%22%3E%3C/path%3E%3Cpath%20d%3D%22M45.201%2C30.296c6.651%2C0%2C12.233%2C5.351%2C12.551%2C11.977l-3.033-2.638c-0.193-0.165-0.507-0.142-0.675%2C0.048%20%20%20c-0.174%2C0.198-0.153%2C0.501%2C0.045%2C0.676l3.883%2C3.375c0.09%2C0.075%2C0.198%2C0.115%2C0.312%2C0.115c0.141%2C0%2C0.273-0.061%2C0.362-0.166%20%20%20l3.371-3.877c0.173-0.2%2C0.151-0.502-0.047-0.675c-0.194-0.166-0.508-0.144-0.676%2C0.048l-2.592%2C2.979%20%20%20c-0.18-3.417-1.629-6.605-4.099-9.001c-2.538-2.461-5.877-3.817-9.404-3.817c-0.264%2C0-0.479%2C0.215-0.479%2C0.479%20%20%20C44.72%2C30.083%2C44.936%2C30.296%2C45.201%2C30.296z%22%3E%3C/path%3E%3C/g%3E%3C/svg%3E";
|
|
} };
|
|
n = {};
|
|
i.m = t, i.n = (e) => {
|
|
var t2 = e && e.__esModule ? () => e.default : () => e;
|
|
return i.d(t2, { a: t2 }), t2;
|
|
}, i.d = (e, t2) => {
|
|
for (var n2 in t2)
|
|
i.o(t2, n2) && !i.o(e, n2) && Object.defineProperty(e, n2, { enumerable: true, get: t2[n2] });
|
|
}, i.g = function() {
|
|
if (typeof globalThis == "object")
|
|
return globalThis;
|
|
try {
|
|
return this || new Function("return this")();
|
|
} catch (e) {
|
|
if (typeof window == "object")
|
|
return window;
|
|
}
|
|
}(), i.o = (e, t2) => Object.prototype.hasOwnProperty.call(e, t2), i.r = (e) => {
|
|
typeof Symbol != "undefined" && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: true });
|
|
}, i.b = document.baseURI || self.location.href, i.nc = undefined;
|
|
r = {};
|
|
i.d(r, { A: () => qc });
|
|
o = {};
|
|
i.r(o), i.d(o, { computeMikkTSpaceTangents: () => Pe, computeMorphedAttributes: () => Ke, deepCloneAttribute: () => je, deinterleaveAttribute: () => He, deinterleaveGeometry: () => qe, estimateBytesUsed: () => Ve, interleaveAttributes: () => _e, mergeAttributes: () => Ne, mergeGeometries: () => Ge, mergeGroups: () => We, mergeVertices: () => ze, toCreasedNormals: () => Je, toTrianglesDrawMode: () => Ye });
|
|
s = {};
|
|
i.r(s), i.d(s, { checkARSupport: () => xi, checkHeadsetConnected: () => wi, checkVRSupport: () => Qi, isAppleVisionPro: () => Ti, isBrowserEnvironment: () => ji, isFirefoxReality: () => Oi, isIOS: () => Ri, isIpad: () => ki, isLandscape: () => Ni, isMobile: () => Si, isMobileDeviceRequestingDesktopSite: () => Fi, isMobileVR: () => Pi, isNodeEnvironment: () => _i, isOculusBrowser: () => Ui, isR7: () => Gi, isTablet: () => Di, isWebXRAvailable: () => bi });
|
|
a = {};
|
|
i.r(a), i.d(a, { clearObject: () => zi, createPool: () => Vi, removeUnusedKeys: () => Yi });
|
|
A = {};
|
|
i.r(A), i.d(A, { equals: () => er, isCoordinate: () => nr, isCoordinates: () => tr, parse: () => Zi, regex: () => Ji, stringify: () => $i, toVector3: () => rr });
|
|
l = {};
|
|
i.r(l), i.d(l, { getComponentProperty: () => ar, getComponentPropertyPath: () => sr, setComponentProperty: () => Ar });
|
|
c = {};
|
|
i.r(c), i.d(c, { parseUrl: () => gr, validateCubemapSrc: () => ur, validateEnvMapSrc: () => dr, validateSrc: () => hr });
|
|
h = {};
|
|
i.r(h), i.d(h, { createCompatibleTexture: () => xr, handleTextureEvents: () => Ir, isCompatibleTexture: () => wr, setTextureProperties: () => Er, updateDistortionMap: () => Br, updateEnvMap: () => yr, updateMap: () => vr, updateMapMaterialFromData: () => Cr });
|
|
d = {};
|
|
i.r(d), i.d(d, { parse: () => Lr, stringify: () => Mr, toCamelCase: () => Sr });
|
|
u = {};
|
|
i.r(u), i.d(u, { checkControllerPresentAndSetup: () => Ur, emitIfAxesChanged: () => Gr, findMatchingControllerWebXR: () => Pr, isControllerPresentWebXR: () => Or, onButtonEvent: () => Nr });
|
|
g = {};
|
|
i.r(g), i.d(g, { bind: () => _r, checkHeadsetConnected: () => Hr, clone: () => Zr, coordinates: () => A, debounce: () => Wr, debug: () => fi, deepEqual: () => to, device: () => s, diff: () => no, entity: () => l, extend: () => Jr, extendDeep: () => Xr, findAllScenes: () => Ao, forceCanvasResizeSafariMobile: () => lr, getElData: () => oo, getUrlParameter: () => so, isIOS: () => qr, isIframed: () => ao, isMobile: () => Vr, material: () => h, objectPool: () => a, shouldCaptureKeyEvent: () => io, split: () => or, splitString: () => ro, srcLoader: () => c, styleParser: () => d, throttle: () => zr, throttleLeadingAndTrailing: () => Yr, throttleTick: () => Kr, trackedControls: () => u });
|
|
p = {};
|
|
i.r(p), i.d(p, { isSingleProperty: () => No, parseProperties: () => qo, parseProperty: () => Vo, process: () => jo, processPropertyDefinition: () => _o, stringifyProperties: () => zo, stringifyProperty: () => Yo });
|
|
f = {};
|
|
i.r(f), i.d(f, { Component: () => As, components: () => Ko, registerComponent: () => cs, registrationOrderWarnings: () => ls });
|
|
m = {};
|
|
i.r(m), i.d(m, { System: () => ms, registerSystem: () => Es, systems: () => fs });
|
|
E = { update: null, begin: null, loopBegin: null, changeBegin: null, change: null, changeComplete: null, loopComplete: null, complete: null, loop: 1, direction: "normal", autoplay: true, timelineOffset: 0 };
|
|
C = { duration: 1000, delay: 0, endDelay: 0, easing: "easeOutElastic(1, .5)", round: 0 };
|
|
v = ["translateX", "translateY", "translateZ", "rotate", "rotateX", "rotateY", "rotateZ", "scale", "scaleX", "scaleY", "scaleZ", "skew", "skewX", "skewY", "perspective"];
|
|
B = { CSS: {}, springs: {} };
|
|
w = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i;
|
|
x = /^rgb/;
|
|
Q = /^hsl/;
|
|
L = { arr: function(e) {
|
|
return Array.isArray(e);
|
|
}, obj: function(e) {
|
|
return y(Object.prototype.toString.call(e), "Object");
|
|
}, pth: function(e) {
|
|
return L.obj(e) && e.hasOwnProperty("totalLength");
|
|
}, svg: function(e) {
|
|
return e instanceof SVGElement;
|
|
}, inp: function(e) {
|
|
return e instanceof HTMLInputElement;
|
|
}, dom: function(e) {
|
|
return e.nodeType || L.svg(e);
|
|
}, str: function(e) {
|
|
return typeof e == "string";
|
|
}, fnc: function(e) {
|
|
return typeof e == "function";
|
|
}, und: function(e) {
|
|
return e === undefined;
|
|
}, hex: function(e) {
|
|
return w.test(e);
|
|
}, rgb: function(e) {
|
|
return x.test(e);
|
|
}, hsl: function(e) {
|
|
return Q.test(e);
|
|
}, col: function(e) {
|
|
return L.hex(e) || L.rgb(e) || L.hsl(e);
|
|
}, key: function(e) {
|
|
return !E.hasOwnProperty(e) && !C.hasOwnProperty(e) && e !== "targets" && e !== "keyframes";
|
|
} };
|
|
M = /\(([^)]+)\)/;
|
|
R = function() {
|
|
var e = 0.1;
|
|
function t2(e2, t3) {
|
|
return 1 - 3 * t3 + 3 * e2;
|
|
}
|
|
function n2(e2, t3) {
|
|
return 3 * t3 - 6 * e2;
|
|
}
|
|
function i2(e2) {
|
|
return 3 * e2;
|
|
}
|
|
function r2(e2, r3, o3) {
|
|
return ((t2(r3, o3) * e2 + n2(r3, o3)) * e2 + i2(r3)) * e2;
|
|
}
|
|
function o2(e2, r3, o3) {
|
|
return 3 * t2(r3, o3) * e2 * e2 + 2 * n2(r3, o3) * e2 + i2(r3);
|
|
}
|
|
return function(t3, n3, i3, s2) {
|
|
if (0 <= t3 && t3 <= 1 && 0 <= i3 && i3 <= 1) {
|
|
var a2 = new Float32Array(11);
|
|
if (t3 !== n3 || i3 !== s2)
|
|
for (var A2 = 0;A2 < 11; ++A2)
|
|
a2[A2] = r2(A2 * e, t3, i3);
|
|
return function(A3) {
|
|
return t3 === n3 && i3 === s2 || A3 === 0 || A3 === 1 ? A3 : r2(function(n4) {
|
|
for (var s3 = 0, A4 = 1;A4 !== 10 && a2[A4] <= n4; ++A4)
|
|
s3 += e;
|
|
--A4;
|
|
var l2 = s3 + (n4 - a2[A4]) / (a2[A4 + 1] - a2[A4]) * e, c2 = o2(l2, t3, i3);
|
|
return c2 >= 0.001 ? function(e2, t4, n5, i4) {
|
|
for (var s4 = 0;s4 < 4; ++s4) {
|
|
var a3 = o2(t4, n5, i4);
|
|
if (a3 === 0)
|
|
return t4;
|
|
t4 -= (r2(t4, n5, i4) - e2) / a3;
|
|
}
|
|
return t4;
|
|
}(n4, l2, t3, i3) : c2 === 0 ? l2 : function(e2, t4, n5, i4, o3) {
|
|
var s4, a3, A5 = 0;
|
|
do {
|
|
(s4 = r2(a3 = t4 + (n5 - t4) / 2, i4, o3) - e2) > 0 ? n5 = a3 : t4 = a3;
|
|
} while (Math.abs(s4) > 0.0000001 && ++A5 < 10);
|
|
return a3;
|
|
}(n4, s3, s3 + e, t3, i3);
|
|
}(A3), n3, s2);
|
|
};
|
|
}
|
|
};
|
|
}();
|
|
F = function() {
|
|
var e = ["Quad", "Cubic", "Quart", "Quint", "Sine", "Expo", "Circ", "Back", "Elastic"], t2 = { In: [[0.55, 0.085, 0.68, 0.53], [0.55, 0.055, 0.675, 0.19], [0.895, 0.03, 0.685, 0.22], [0.755, 0.05, 0.855, 0.06], [0.47, 0, 0.745, 0.715], [0.95, 0.05, 0.795, 0.035], [0.6, 0.04, 0.98, 0.335], [0.6, -0.28, 0.735, 0.045], k], Out: [[0.25, 0.46, 0.45, 0.94], [0.215, 0.61, 0.355, 1], [0.165, 0.84, 0.44, 1], [0.23, 1, 0.32, 1], [0.39, 0.575, 0.565, 1], [0.19, 1, 0.22, 1], [0.075, 0.82, 0.165, 1], [0.175, 0.885, 0.32, 1.275], function(e2, t3) {
|
|
return function(n3) {
|
|
return 1 - k(e2, t3)(1 - n3);
|
|
};
|
|
}], InOut: [[0.455, 0.03, 0.515, 0.955], [0.645, 0.045, 0.355, 1], [0.77, 0, 0.175, 1], [0.86, 0, 0.07, 1], [0.445, 0.05, 0.55, 0.95], [1, 0, 0, 1], [0.785, 0.135, 0.15, 0.86], [0.68, -0.55, 0.265, 1.55], function(e2, t3) {
|
|
return function(n3) {
|
|
return n3 < 0.5 ? k(e2, t3)(2 * n3) / 2 : 1 - k(e2, t3)(-2 * n3 + 2) / 2;
|
|
};
|
|
}] }, n2 = { linear: [0.25, 0.25, 0.75, 0.75] };
|
|
for (var i2 in t2)
|
|
for (var r2 = 0, o2 = t2[i2].length;r2 < o2; r2++)
|
|
n2["ease" + i2 + e[r2]] = t2[i2][r2];
|
|
return n2;
|
|
}();
|
|
P = [];
|
|
z = /rgb\((\d+,\s*[\d]+,\s*[\d]+)\)/g;
|
|
Y = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
K = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
|
|
W = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g;
|
|
J = /hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g;
|
|
X = /([\+\-]?[0-9#\.]+)(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/;
|
|
re = /(\w+)\(([^)]*)\)/g;
|
|
ae = /^(\*=|\+=|-=)/;
|
|
le = /\s/g;
|
|
fe = /-?\d*\.?\d+/g;
|
|
ve = /^spring/;
|
|
be = { css: function(e, t2, n2) {
|
|
return e.style[t2] = n2;
|
|
}, attribute: function(e, t2, n2) {
|
|
return e.setAttribute(t2, n2);
|
|
}, object: function(e, t2, n2) {
|
|
return e[t2] = n2;
|
|
}, transform: function(e, t2, n2, i2, r2) {
|
|
if (i2.list.set(t2, n2), t2 === i2.last || r2) {
|
|
var o2 = "";
|
|
i2.list.forEach(function(e2, t3) {
|
|
o2 += t3 + "(" + e2 + ") ";
|
|
}), e.style.transform = o2;
|
|
}
|
|
} };
|
|
Le = [];
|
|
Me = [];
|
|
Se = function() {
|
|
function e() {
|
|
xe = requestAnimationFrame(t2);
|
|
}
|
|
function t2(t3) {
|
|
var n2 = Le.length;
|
|
if (n2) {
|
|
for (var i2 = 0;i2 < n2; ) {
|
|
var r2 = Le[i2];
|
|
if (r2.paused) {
|
|
var o2 = Le.indexOf(r2);
|
|
o2 > -1 && (Le.splice(o2, 1), n2 = Le.length);
|
|
} else
|
|
r2.tick(t3);
|
|
i2++;
|
|
}
|
|
e();
|
|
} else
|
|
xe = cancelAnimationFrame(xe);
|
|
}
|
|
return e;
|
|
}();
|
|
document.addEventListener("visibilitychange", function() {
|
|
if (document.hidden) {
|
|
for (var e = 0, t2 = Le.length;e < t2; e++)
|
|
activeInstance[e].pause();
|
|
Me = Le.slice(0), Le = [];
|
|
} else
|
|
for (var n2 = 0, i2 = Me.length;n2 < i2; n2++)
|
|
Me[n2].play();
|
|
}), De.version = "3.0.0", De.speed = 1, De.running = Le, De.remove = function(e) {
|
|
for (var t2 = Ee(e), n2 = Le.length;n2--; ) {
|
|
var i2 = Le[n2], r2 = i2.animations, o2 = i2.children;
|
|
ke(t2, r2);
|
|
for (var s2 = o2.length;s2--; ) {
|
|
var a2 = o2[s2], A2 = a2.animations;
|
|
ke(t2, A2), A2.length || a2.children.length || o2.splice(s2, 1);
|
|
}
|
|
r2.length || o2.length || i2.pause();
|
|
}
|
|
}, De.get = se, De.set = ye, De.convertPx = te, De.path = function(e, t2) {
|
|
var n2 = L.str(e) ? O(e)[0] : e, i2 = t2 || 100;
|
|
return function(e2) {
|
|
return { property: e2, el: n2, svg: ge(n2), totalLength: ue(n2) * (i2 / 100) };
|
|
};
|
|
}, De.setDashoffset = function(e) {
|
|
var t2 = ue(e);
|
|
return e.setAttribute("stroke-dasharray", t2), t2;
|
|
}, De.stagger = function(e, t2) {
|
|
t2 === undefined && (t2 = {});
|
|
var n2 = t2.direction || "normal", i2 = t2.easing ? U(t2.easing) : null, r2 = t2.grid, o2 = t2.axis, s2 = t2.from || 0, a2 = s2 === "first", A2 = s2 === "center", l2 = s2 === "last", c2 = L.arr(e), h2 = c2 ? parseFloat(e[0]) : parseFloat(e), d2 = c2 ? parseFloat(e[1]) : 0, u2 = Z(c2 ? e[1] : e) || 0, g2 = t2.start || 0 + (c2 ? h2 : 0), p2 = [], f2 = 0;
|
|
return function(e2, t3, m2) {
|
|
if (a2 && (s2 = 0), A2 && (s2 = (m2 - 1) / 2), l2 && (s2 = m2 - 1), !p2.length) {
|
|
for (var E2 = 0;E2 < m2; E2++) {
|
|
if (r2) {
|
|
var C2 = A2 ? (r2[0] - 1) / 2 : s2 % r2[0], v2 = A2 ? (r2[1] - 1) / 2 : Math.floor(s2 / r2[0]), B2 = C2 - E2 % r2[0], b2 = v2 - Math.floor(E2 / r2[0]), y2 = Math.sqrt(B2 * B2 + b2 * b2);
|
|
o2 === "x" && (y2 = -B2), o2 === "y" && (y2 = -b2), p2.push(y2);
|
|
} else
|
|
p2.push(Math.abs(s2 - E2));
|
|
f2 = Math.max.apply(Math, p2);
|
|
}
|
|
i2 && (p2 = p2.map(function(e3) {
|
|
return i2(e3 / f2) * f2;
|
|
})), n2 === "reverse" && (p2 = p2.map(function(e3) {
|
|
return o2 ? e3 < 0 ? -1 * e3 : -e3 : Math.abs(f2 - e3);
|
|
}));
|
|
}
|
|
return g2 + (c2 ? (d2 - h2) / f2 : h2) * (Math.round(100 * p2[t3]) / 100) + u2;
|
|
};
|
|
}, De.timeline = function(e) {
|
|
e === undefined && (e = {});
|
|
var t2 = De(e);
|
|
return t2.duration = 0, t2.add = function(n2, i2) {
|
|
var r2 = Le.indexOf(t2), o2 = t2.children;
|
|
function s2(e2) {
|
|
e2.passThrough = true;
|
|
}
|
|
r2 > -1 && Le.splice(r2, 1);
|
|
for (var a2 = 0;a2 < o2.length; a2++)
|
|
s2(o2[a2]);
|
|
var A2 = V(n2, q(C, e));
|
|
A2.targets = A2.targets || e.targets;
|
|
var l2 = t2.duration;
|
|
A2.autoplay = false, A2.direction = t2.direction, A2.timelineOffset = L.und(i2) ? l2 : Ae(i2, l2), s2(t2), t2.seek(A2.timelineOffset);
|
|
var c2 = De(A2);
|
|
s2(c2), o2.push(c2);
|
|
var h2 = we(o2, e);
|
|
return t2.delay = h2.delay, t2.endDelay = h2.endDelay, t2.duration = h2.duration, t2.seek(0), t2.reset(), t2.autoplay && t2.play(), t2;
|
|
}, t2;
|
|
}, De.easing = U, De.penner = F, De.random = function(e, t2) {
|
|
return Math.floor(Math.random() * (t2 - e + 1)) + e;
|
|
};
|
|
Te = De;
|
|
Re = exports_three_module;
|
|
Fe = new WeakMap;
|
|
Ue = class Ue extends Re.Loader {
|
|
constructor(e) {
|
|
super(e), this.decoderPath = "", this.decoderConfig = {}, this.decoderBinary = null, this.decoderPending = null, this.workerLimit = 4, this.workerPool = [], this.workerNextTaskID = 1, this.workerSourceURL = "", this.defaultAttributeIDs = { position: "POSITION", normal: "NORMAL", color: "COLOR", uv: "TEX_COORD" }, this.defaultAttributeTypes = { position: "Float32Array", normal: "Float32Array", color: "Float32Array", uv: "Float32Array" };
|
|
}
|
|
setDecoderPath(e) {
|
|
return this.decoderPath = e, this;
|
|
}
|
|
setDecoderConfig(e) {
|
|
return this.decoderConfig = e, this;
|
|
}
|
|
setWorkerLimit(e) {
|
|
return this.workerLimit = e, this;
|
|
}
|
|
load(e, t2, n2, i2) {
|
|
const r2 = new Re.FileLoader(this.manager);
|
|
r2.setPath(this.path), r2.setResponseType("arraybuffer"), r2.setRequestHeader(this.requestHeader), r2.setWithCredentials(this.withCredentials), r2.load(e, (e2) => {
|
|
this.parse(e2, t2, i2);
|
|
}, n2, i2);
|
|
}
|
|
parse(e, t2, n2 = () => {}) {
|
|
this.decodeDracoFile(e, t2, null, null, Re.SRGBColorSpace, n2).catch(n2);
|
|
}
|
|
decodeDracoFile(e, t2, n2, i2, r2 = Re.LinearSRGBColorSpace, o2 = () => {}) {
|
|
const s2 = { attributeIDs: n2 || this.defaultAttributeIDs, attributeTypes: i2 || this.defaultAttributeTypes, useUniqueIDs: !!n2, vertexColorSpace: r2 };
|
|
return this.decodeGeometry(e, s2).then(t2).catch(o2);
|
|
}
|
|
decodeGeometry(e, t2) {
|
|
const n2 = JSON.stringify(t2);
|
|
if (Fe.has(e)) {
|
|
const t3 = Fe.get(e);
|
|
if (t3.key === n2)
|
|
return t3.promise;
|
|
if (e.byteLength === 0)
|
|
throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.");
|
|
}
|
|
let i2;
|
|
const r2 = this.workerNextTaskID++, o2 = e.byteLength, s2 = this._getWorker(r2, o2).then((n3) => (i2 = n3, new Promise((n4, o3) => {
|
|
i2._callbacks[r2] = { resolve: n4, reject: o3 }, i2.postMessage({ type: "decode", id: r2, taskConfig: t2, buffer: e }, [e]);
|
|
}))).then((e2) => this._createGeometry(e2.geometry));
|
|
return s2.catch(() => true).then(() => {
|
|
i2 && r2 && this._releaseTask(i2, r2);
|
|
}), Fe.set(e, { key: n2, promise: s2 }), s2;
|
|
}
|
|
_createGeometry(e) {
|
|
const t2 = new Re.BufferGeometry;
|
|
e.index && t2.setIndex(new Re.BufferAttribute(e.index.array, 1));
|
|
for (let n2 = 0;n2 < e.attributes.length; n2++) {
|
|
const i2 = e.attributes[n2], r2 = i2.name, o2 = i2.array, s2 = i2.itemSize, a2 = new Re.BufferAttribute(o2, s2);
|
|
r2 === "color" && (this._assignVertexColorSpace(a2, i2.vertexColorSpace), a2.normalized = o2 instanceof Float32Array == 0), t2.setAttribute(r2, a2);
|
|
}
|
|
return t2;
|
|
}
|
|
_assignVertexColorSpace(e, t2) {
|
|
if (t2 !== Re.SRGBColorSpace)
|
|
return;
|
|
const n2 = new Re.Color;
|
|
for (let t3 = 0, i2 = e.count;t3 < i2; t3++)
|
|
n2.fromBufferAttribute(e, t3), Re.ColorManagement.toWorkingColorSpace(n2, Re.SRGBColorSpace), e.setXYZ(t3, n2.r, n2.g, n2.b);
|
|
}
|
|
_loadLibrary(e, t2) {
|
|
const n2 = new Re.FileLoader(this.manager);
|
|
return n2.setPath(this.decoderPath), n2.setResponseType(t2), n2.setWithCredentials(this.withCredentials), new Promise((t3, i2) => {
|
|
n2.load(e, t3, undefined, i2);
|
|
});
|
|
}
|
|
preload() {
|
|
return this._initDecoder(), this;
|
|
}
|
|
_initDecoder() {
|
|
if (this.decoderPending)
|
|
return this.decoderPending;
|
|
const e = typeof WebAssembly != "object" || this.decoderConfig.type === "js", t2 = [];
|
|
return e ? t2.push(this._loadLibrary("draco_decoder.js", "text")) : (t2.push(this._loadLibrary("draco_wasm_wrapper.js", "text")), t2.push(this._loadLibrary("draco_decoder.wasm", "arraybuffer"))), this.decoderPending = Promise.all(t2).then((t3) => {
|
|
const n2 = t3[0];
|
|
e || (this.decoderConfig.wasmBinary = t3[1]);
|
|
const i2 = Oe.toString(), r2 = ["/* draco decoder */", n2, "", "/* worker */", i2.substring(i2.indexOf("{") + 1, i2.lastIndexOf("}"))].join(`
|
|
`);
|
|
this.workerSourceURL = URL.createObjectURL(new Blob([r2]));
|
|
}), this.decoderPending;
|
|
}
|
|
_getWorker(e, t2) {
|
|
return this._initDecoder().then(() => {
|
|
if (this.workerPool.length < this.workerLimit) {
|
|
const e2 = new Worker(this.workerSourceURL);
|
|
e2._callbacks = {}, e2._taskCosts = {}, e2._taskLoad = 0, e2.postMessage({ type: "init", decoderConfig: this.decoderConfig }), e2.onmessage = function(t3) {
|
|
const n3 = t3.data;
|
|
switch (n3.type) {
|
|
case "decode":
|
|
e2._callbacks[n3.id].resolve(n3);
|
|
break;
|
|
case "error":
|
|
e2._callbacks[n3.id].reject(n3);
|
|
break;
|
|
default:
|
|
console.error('THREE.DRACOLoader: Unexpected message, "' + n3.type + '"');
|
|
}
|
|
}, this.workerPool.push(e2);
|
|
} else
|
|
this.workerPool.sort(function(e2, t3) {
|
|
return e2._taskLoad > t3._taskLoad ? -1 : 1;
|
|
});
|
|
const n2 = this.workerPool[this.workerPool.length - 1];
|
|
return n2._taskCosts[e] = t2, n2._taskLoad += t2, n2;
|
|
});
|
|
}
|
|
_releaseTask(e, t2) {
|
|
e._taskLoad -= e._taskCosts[t2], delete e._callbacks[t2], delete e._taskCosts[t2];
|
|
}
|
|
debug() {
|
|
console.log("Task load: ", this.workerPool.map((e) => e._taskLoad));
|
|
}
|
|
dispose() {
|
|
for (let e = 0;e < this.workerPool.length; ++e)
|
|
this.workerPool[e].terminate();
|
|
return this.workerPool.length = 0, this.workerSourceURL !== "" && URL.revokeObjectURL(this.workerSourceURL), this;
|
|
}
|
|
};
|
|
Xe = class Xe extends Re.Loader {
|
|
constructor(e) {
|
|
super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(e2) {
|
|
return new it(e2);
|
|
}), this.register(function(e2) {
|
|
return new rt(e2);
|
|
}), this.register(function(e2) {
|
|
return new ut(e2);
|
|
}), this.register(function(e2) {
|
|
return new gt(e2);
|
|
}), this.register(function(e2) {
|
|
return new pt(e2);
|
|
}), this.register(function(e2) {
|
|
return new st(e2);
|
|
}), this.register(function(e2) {
|
|
return new at(e2);
|
|
}), this.register(function(e2) {
|
|
return new At(e2);
|
|
}), this.register(function(e2) {
|
|
return new lt(e2);
|
|
}), this.register(function(e2) {
|
|
return new nt(e2);
|
|
}), this.register(function(e2) {
|
|
return new ct(e2);
|
|
}), this.register(function(e2) {
|
|
return new ot(e2);
|
|
}), this.register(function(e2) {
|
|
return new dt(e2);
|
|
}), this.register(function(e2) {
|
|
return new ht(e2);
|
|
}), this.register(function(e2) {
|
|
return new et(e2);
|
|
}), this.register(function(e2) {
|
|
return new ft(e2);
|
|
}), this.register(function(e2) {
|
|
return new mt(e2);
|
|
});
|
|
}
|
|
load(e, t2, n2, i2) {
|
|
const r2 = this;
|
|
let o2;
|
|
if (this.resourcePath !== "")
|
|
o2 = this.resourcePath;
|
|
else if (this.path !== "") {
|
|
const t3 = Re.LoaderUtils.extractUrlBase(e);
|
|
o2 = Re.LoaderUtils.resolveURL(t3, this.path);
|
|
} else
|
|
o2 = Re.LoaderUtils.extractUrlBase(e);
|
|
this.manager.itemStart(e);
|
|
const s2 = function(t3) {
|
|
i2 ? i2(t3) : console.error(t3), r2.manager.itemError(e), r2.manager.itemEnd(e);
|
|
}, a2 = new Re.FileLoader(this.manager);
|
|
a2.setPath(this.path), a2.setResponseType("arraybuffer"), a2.setRequestHeader(this.requestHeader), a2.setWithCredentials(this.withCredentials), a2.load(e, function(n3) {
|
|
try {
|
|
r2.parse(n3, o2, function(n4) {
|
|
t2(n4), r2.manager.itemEnd(e);
|
|
}, s2);
|
|
} catch (e2) {
|
|
s2(e2);
|
|
}
|
|
}, n2, s2);
|
|
}
|
|
setDRACOLoader(e) {
|
|
return this.dracoLoader = e, this;
|
|
}
|
|
setKTX2Loader(e) {
|
|
return this.ktx2Loader = e, this;
|
|
}
|
|
setMeshoptDecoder(e) {
|
|
return this.meshoptDecoder = e, this;
|
|
}
|
|
register(e) {
|
|
return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this;
|
|
}
|
|
unregister(e) {
|
|
return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this;
|
|
}
|
|
parse(e, t2, n2, i2) {
|
|
let r2;
|
|
const o2 = {}, s2 = {}, a2 = new TextDecoder;
|
|
if (typeof e == "string")
|
|
r2 = JSON.parse(e);
|
|
else if (e instanceof ArrayBuffer)
|
|
if (a2.decode(new Uint8Array(e, 0, 4)) === Et) {
|
|
try {
|
|
o2[$e.KHR_BINARY_GLTF] = new Ct(e);
|
|
} catch (e2) {
|
|
return void (i2 && i2(e2));
|
|
}
|
|
r2 = JSON.parse(o2[$e.KHR_BINARY_GLTF].content);
|
|
} else
|
|
r2 = JSON.parse(a2.decode(e));
|
|
else
|
|
r2 = e;
|
|
if (r2.asset === undefined || r2.asset.version[0] < 2)
|
|
return void (i2 && i2(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));
|
|
const A2 = new _t(r2, { path: t2 || this.resourcePath || "", crossOrigin: this.crossOrigin, requestHeader: this.requestHeader, manager: this.manager, ktx2Loader: this.ktx2Loader, meshoptDecoder: this.meshoptDecoder });
|
|
A2.fileLoader.setRequestHeader(this.requestHeader);
|
|
for (let e2 = 0;e2 < this.pluginCallbacks.length; e2++) {
|
|
const t3 = this.pluginCallbacks[e2](A2);
|
|
t3.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), s2[t3.name] = t3, o2[t3.name] = true;
|
|
}
|
|
if (r2.extensionsUsed)
|
|
for (let e2 = 0;e2 < r2.extensionsUsed.length; ++e2) {
|
|
const t3 = r2.extensionsUsed[e2], n3 = r2.extensionsRequired || [];
|
|
switch (t3) {
|
|
case $e.KHR_MATERIALS_UNLIT:
|
|
o2[t3] = new tt;
|
|
break;
|
|
case $e.KHR_DRACO_MESH_COMPRESSION:
|
|
o2[t3] = new vt(r2, this.dracoLoader);
|
|
break;
|
|
case $e.KHR_TEXTURE_TRANSFORM:
|
|
o2[t3] = new Bt;
|
|
break;
|
|
case $e.KHR_MESH_QUANTIZATION:
|
|
o2[t3] = new bt;
|
|
break;
|
|
default:
|
|
n3.indexOf(t3) >= 0 && s2[t3] === undefined && console.warn('THREE.GLTFLoader: Unknown extension "' + t3 + '".');
|
|
}
|
|
}
|
|
A2.setExtensions(o2), A2.setPlugins(s2), A2.parse(n2, i2);
|
|
}
|
|
parseAsync(e, t2) {
|
|
const n2 = this;
|
|
return new Promise(function(i2, r2) {
|
|
n2.parse(e, t2, i2, r2);
|
|
});
|
|
}
|
|
};
|
|
$e = { KHR_BINARY_GLTF: "KHR_binary_glTF", KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression", KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual", KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat", KHR_MATERIALS_DISPERSION: "KHR_materials_dispersion", KHR_MATERIALS_IOR: "KHR_materials_ior", KHR_MATERIALS_SHEEN: "KHR_materials_sheen", KHR_MATERIALS_SPECULAR: "KHR_materials_specular", KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission", KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence", KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy", KHR_MATERIALS_UNLIT: "KHR_materials_unlit", KHR_MATERIALS_VOLUME: "KHR_materials_volume", KHR_TEXTURE_BASISU: "KHR_texture_basisu", KHR_TEXTURE_TRANSFORM: "KHR_texture_transform", KHR_MESH_QUANTIZATION: "KHR_mesh_quantization", KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength", EXT_MATERIALS_BUMP: "EXT_materials_bump", EXT_TEXTURE_WEBP: "EXT_texture_webp", EXT_TEXTURE_AVIF: "EXT_texture_avif", EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression", EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing" };
|
|
yt = class yt extends Re.Interpolant {
|
|
constructor(e, t2, n2, i2) {
|
|
super(e, t2, n2, i2);
|
|
}
|
|
copySampleValue_(e) {
|
|
const t2 = this.resultBuffer, n2 = this.sampleValues, i2 = this.valueSize, r2 = e * i2 * 3 + i2;
|
|
for (let e2 = 0;e2 !== i2; e2++)
|
|
t2[e2] = n2[r2 + e2];
|
|
return t2;
|
|
}
|
|
interpolate_(e, t2, n2, i2) {
|
|
const r2 = this.resultBuffer, o2 = this.sampleValues, s2 = this.valueSize, a2 = 2 * s2, A2 = 3 * s2, l2 = i2 - t2, c2 = (n2 - t2) / l2, h2 = c2 * c2, d2 = h2 * c2, u2 = e * A2, g2 = u2 - A2, p2 = -2 * d2 + 3 * h2, f2 = d2 - h2, m2 = 1 - p2, E2 = f2 - h2 + c2;
|
|
for (let e2 = 0;e2 !== s2; e2++) {
|
|
const t3 = o2[g2 + e2 + s2], n3 = o2[g2 + e2 + a2] * l2, i3 = o2[u2 + e2 + s2], A3 = o2[u2 + e2] * l2;
|
|
r2[e2] = m2 * t3 + E2 * n3 + p2 * i3 + f2 * A3;
|
|
}
|
|
return r2;
|
|
}
|
|
};
|
|
It = new Re.Quaternion;
|
|
wt = class wt extends yt {
|
|
interpolate_(e, t2, n2, i2) {
|
|
const r2 = super.interpolate_(e, t2, n2, i2);
|
|
return It.fromArray(r2).normalize().toArray(r2), r2;
|
|
}
|
|
};
|
|
xt = { FLOAT: 5126, FLOAT_MAT3: 35675, FLOAT_MAT4: 35676, FLOAT_VEC2: 35664, FLOAT_VEC3: 35665, FLOAT_VEC4: 35666, LINEAR: 9729, REPEAT: 10497, SAMPLER_2D: 35678, POINTS: 0, LINES: 1, LINE_LOOP: 2, LINE_STRIP: 3, TRIANGLES: 4, TRIANGLE_STRIP: 5, TRIANGLE_FAN: 6, UNSIGNED_BYTE: 5121, UNSIGNED_SHORT: 5123 };
|
|
Qt = { 5120: Int8Array, 5121: Uint8Array, 5122: Int16Array, 5123: Uint16Array, 5125: Uint32Array, 5126: Float32Array };
|
|
Lt = { 9728: Re.NearestFilter, 9729: Re.LinearFilter, 9984: Re.NearestMipmapNearestFilter, 9985: Re.LinearMipmapNearestFilter, 9986: Re.NearestMipmapLinearFilter, 9987: Re.LinearMipmapLinearFilter };
|
|
Mt = { 33071: Re.ClampToEdgeWrapping, 33648: Re.MirroredRepeatWrapping, 10497: Re.RepeatWrapping };
|
|
St = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 };
|
|
Dt = { POSITION: "position", NORMAL: "normal", TANGENT: "tangent", TEXCOORD_0: "uv", TEXCOORD_1: "uv1", TEXCOORD_2: "uv2", TEXCOORD_3: "uv3", COLOR_0: "color", WEIGHTS_0: "skinWeight", JOINTS_0: "skinIndex" };
|
|
kt = { scale: "scale", translation: "position", rotation: "quaternion", weights: "morphTargetInfluences" };
|
|
Tt = { CUBICSPLINE: undefined, LINEAR: Re.InterpolateLinear, STEP: Re.InterpolateDiscrete };
|
|
jt = new Re.Matrix4;
|
|
new Uint8Array([0]);
|
|
ln = [171, 75, 84, 88, 32, 50, 48, 187, 13, 10, 26, 10];
|
|
hn = i(9922).hp;
|
|
pn = { env: { emscripten_notify_memory_growth: function(e) {
|
|
gn = new Uint8Array(un.exports.memory.buffer);
|
|
} } };
|
|
En = (Re.SRGBTransfer, Re.LinearTransfer, Re.LinearTransfer, new WeakMap);
|
|
Bn = class Bn extends Re.Loader {
|
|
constructor(e) {
|
|
super(e), this.transcoderPath = "", this.transcoderBinary = null, this.transcoderPending = null, this.workerPool = new qt, this.workerSourceURL = "", this.workerConfig = null, typeof MSC_TRANSCODER != "undefined" && console.warn('THREE.KTX2Loader: Please update to latest "basis_transcoder". "msc_basis_transcoder" is no longer supported in three.js r125+.');
|
|
}
|
|
setTranscoderPath(e) {
|
|
return this.transcoderPath = e, this;
|
|
}
|
|
setWorkerLimit(e) {
|
|
return this.workerPool.setWorkerLimit(e), this;
|
|
}
|
|
async detectSupportAsync(e) {
|
|
return this.workerConfig = { astcSupported: await e.hasFeatureAsync("texture-compression-astc"), astcHDRSupported: false, etc1Supported: await e.hasFeatureAsync("texture-compression-etc1"), etc2Supported: await e.hasFeatureAsync("texture-compression-etc2"), dxtSupported: await e.hasFeatureAsync("texture-compression-bc"), bptcSupported: await e.hasFeatureAsync("texture-compression-bptc"), pvrtcSupported: await e.hasFeatureAsync("texture-compression-pvrtc") }, this;
|
|
}
|
|
detectSupport(e) {
|
|
return e.isWebGPURenderer === true ? this.workerConfig = { astcSupported: e.hasFeature("texture-compression-astc"), astcHDRSupported: false, etc1Supported: e.hasFeature("texture-compression-etc1"), etc2Supported: e.hasFeature("texture-compression-etc2"), dxtSupported: e.hasFeature("texture-compression-bc"), bptcSupported: e.hasFeature("texture-compression-bptc"), pvrtcSupported: e.hasFeature("texture-compression-pvrtc") } : this.workerConfig = { astcSupported: e.extensions.has("WEBGL_compressed_texture_astc"), astcHDRSupported: e.extensions.has("WEBGL_compressed_texture_astc") && e.extensions.get("WEBGL_compressed_texture_astc").getSupportedProfiles().includes("hdr"), etc1Supported: e.extensions.has("WEBGL_compressed_texture_etc1"), etc2Supported: e.extensions.has("WEBGL_compressed_texture_etc"), dxtSupported: e.extensions.has("WEBGL_compressed_texture_s3tc"), bptcSupported: e.extensions.has("EXT_texture_compression_bptc"), pvrtcSupported: e.extensions.has("WEBGL_compressed_texture_pvrtc") || e.extensions.has("WEBKIT_WEBGL_compressed_texture_pvrtc") }, this;
|
|
}
|
|
init() {
|
|
if (!this.transcoderPending) {
|
|
const e = new Re.FileLoader(this.manager);
|
|
e.setPath(this.transcoderPath), e.setWithCredentials(this.withCredentials);
|
|
const t2 = e.loadAsync("basis_transcoder.js"), n2 = new Re.FileLoader(this.manager);
|
|
n2.setPath(this.transcoderPath), n2.setResponseType("arraybuffer"), n2.setWithCredentials(this.withCredentials);
|
|
const i2 = n2.loadAsync("basis_transcoder.wasm");
|
|
this.transcoderPending = Promise.all([t2, i2]).then(([e2, t3]) => {
|
|
const n3 = Bn.BasisWorker.toString(), i3 = ["/* constants */", "let _EngineFormat = " + JSON.stringify(Bn.EngineFormat), "let _EngineType = " + JSON.stringify(Bn.EngineType), "let _TranscoderFormat = " + JSON.stringify(Bn.TranscoderFormat), "let _BasisFormat = " + JSON.stringify(Bn.BasisFormat), "/* basis_transcoder.js */", e2, "/* worker */", n3.substring(n3.indexOf("{") + 1, n3.lastIndexOf("}"))].join(`
|
|
`);
|
|
this.workerSourceURL = URL.createObjectURL(new Blob([i3])), this.transcoderBinary = t3, this.workerPool.setWorkerCreator(() => {
|
|
const e3 = new Worker(this.workerSourceURL), t4 = this.transcoderBinary.slice(0);
|
|
return e3.postMessage({ type: "init", config: this.workerConfig, transcoderBinary: t4 }, [t4]), e3;
|
|
});
|
|
}), vn > 0 && console.warn("THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues. Use a single KTX2Loader instance, or call .dispose() on old instances."), vn++;
|
|
}
|
|
return this.transcoderPending;
|
|
}
|
|
load(e, t2, n2, i2) {
|
|
if (this.workerConfig === null)
|
|
throw new Error("THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.");
|
|
const r2 = new Re.FileLoader(this.manager);
|
|
r2.setResponseType("arraybuffer"), r2.setWithCredentials(this.withCredentials), r2.load(e, (e2) => {
|
|
this.parse(e2, t2, i2);
|
|
}, n2, i2);
|
|
}
|
|
parse(e, t2, n2) {
|
|
if (this.workerConfig === null)
|
|
throw new Error("THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.");
|
|
if (En.has(e))
|
|
return En.get(e).promise.then(t2).catch(n2);
|
|
this._createTexture(e).then((e2) => t2 ? t2(e2) : null).catch(n2);
|
|
}
|
|
_createTextureFrom(e, t2) {
|
|
const { type: n2, error: i2, data: { faces: r2, width: o2, height: s2, format: a2, type: A2, dfdFlags: l2 } } = e;
|
|
if (n2 === "error")
|
|
return Promise.reject(i2);
|
|
let c2;
|
|
if (t2.faceCount === 6)
|
|
c2 = new Re.CompressedCubeTexture(r2, a2, A2);
|
|
else {
|
|
const e2 = r2[0].mipmaps;
|
|
c2 = t2.layerCount > 1 ? new Re.CompressedArrayTexture(e2, o2, s2, t2.layerCount, a2, A2) : new Re.CompressedTexture(e2, o2, s2, a2, A2);
|
|
}
|
|
return c2.minFilter = r2[0].mipmaps.length === 1 ? Re.LinearFilter : Re.LinearMipmapLinearFilter, c2.magFilter = Re.LinearFilter, c2.generateMipmaps = false, c2.needsUpdate = true, c2.colorSpace = wn(t2), c2.premultiplyAlpha = !!(1 & l2), c2;
|
|
}
|
|
async _createTexture(e, t2 = {}) {
|
|
const n2 = function(e2) {
|
|
const t3 = new Uint8Array(e2.buffer, e2.byteOffset, ln.length);
|
|
if (t3[0] !== ln[0] || t3[1] !== ln[1] || t3[2] !== ln[2] || t3[3] !== ln[3] || t3[4] !== ln[4] || t3[5] !== ln[5] || t3[6] !== ln[6] || t3[7] !== ln[7] || t3[8] !== ln[8] || t3[9] !== ln[9] || t3[10] !== ln[10] || t3[11] !== ln[11])
|
|
throw new Error("Missing KTX 2.0 identifier.");
|
|
const n3 = new an, i3 = 17 * Uint32Array.BYTES_PER_ELEMENT, r3 = new An(e2, ln.length, i3, true);
|
|
n3.vkFormat = r3._nextUint32(), n3.typeSize = r3._nextUint32(), n3.pixelWidth = r3._nextUint32(), n3.pixelHeight = r3._nextUint32(), n3.pixelDepth = r3._nextUint32(), n3.layerCount = r3._nextUint32(), n3.faceCount = r3._nextUint32();
|
|
const o3 = r3._nextUint32();
|
|
n3.supercompressionScheme = r3._nextUint32();
|
|
const s2 = r3._nextUint32(), a2 = r3._nextUint32(), A2 = r3._nextUint32(), l2 = r3._nextUint32(), c2 = r3._nextUint64(), h2 = r3._nextUint64(), d2 = new An(e2, ln.length + i3, 3 * o3 * 8, true);
|
|
for (let t4 = 0;t4 < o3; t4++)
|
|
n3.levels.push({ levelData: new Uint8Array(e2.buffer, e2.byteOffset + d2._nextUint64(), d2._nextUint64()), uncompressedByteLength: d2._nextUint64() });
|
|
const u2 = new An(e2, s2, a2, true), g2 = { vendorId: u2._skip(4)._nextUint16(), descriptorType: u2._nextUint16(), versionNumber: u2._nextUint16(), descriptorBlockSize: u2._nextUint16(), colorModel: u2._nextUint8(), colorPrimaries: u2._nextUint8(), transferFunction: u2._nextUint8(), flags: u2._nextUint8(), texelBlockDimension: [u2._nextUint8(), u2._nextUint8(), u2._nextUint8(), u2._nextUint8()], bytesPlane: [u2._nextUint8(), u2._nextUint8(), u2._nextUint8(), u2._nextUint8(), u2._nextUint8(), u2._nextUint8(), u2._nextUint8(), u2._nextUint8()], samples: [] }, p2 = (g2.descriptorBlockSize / 4 - 6) / 4;
|
|
for (let e3 = 0;e3 < p2; e3++) {
|
|
const t4 = { bitOffset: u2._nextUint16(), bitLength: u2._nextUint8(), channelType: u2._nextUint8(), samplePosition: [u2._nextUint8(), u2._nextUint8(), u2._nextUint8(), u2._nextUint8()], sampleLower: -1 / 0, sampleUpper: 1 / 0 };
|
|
64 & t4.channelType ? (t4.sampleLower = u2._nextInt32(), t4.sampleUpper = u2._nextInt32()) : (t4.sampleLower = u2._nextUint32(), t4.sampleUpper = u2._nextUint32()), g2.samples[e3] = t4;
|
|
}
|
|
n3.dataFormatDescriptor.length = 0, n3.dataFormatDescriptor.push(g2);
|
|
const f2 = new An(e2, A2, l2, true);
|
|
for (;f2._offset < l2; ) {
|
|
const e3 = f2._nextUint32(), t4 = f2._scan(e3), i4 = cn(t4);
|
|
if (n3.keyValue[i4] = f2._nextUint8Array(e3 - t4.byteLength - 1), i4.match(/^ktx/i)) {
|
|
const e4 = cn(n3.keyValue[i4]);
|
|
n3.keyValue[i4] = e4.substring(0, e4.lastIndexOf("\x00"));
|
|
}
|
|
f2._skip(e3 % 4 ? 4 - e3 % 4 : 0);
|
|
}
|
|
if (h2 <= 0)
|
|
return n3;
|
|
const m2 = new An(e2, c2, h2, true), E2 = m2._nextUint16(), C2 = m2._nextUint16(), v2 = m2._nextUint32(), B2 = m2._nextUint32(), b2 = m2._nextUint32(), y2 = m2._nextUint32(), I2 = [];
|
|
for (let e3 = 0;e3 < o3; e3++)
|
|
I2.push({ imageFlags: m2._nextUint32(), rgbSliceByteOffset: m2._nextUint32(), rgbSliceByteLength: m2._nextUint32(), alphaSliceByteOffset: m2._nextUint32(), alphaSliceByteLength: m2._nextUint32() });
|
|
const w2 = c2 + m2._offset, x2 = w2 + v2, Q2 = x2 + B2, L2 = Q2 + b2, M2 = new Uint8Array(e2.buffer, e2.byteOffset + w2, v2), S2 = new Uint8Array(e2.buffer, e2.byteOffset + x2, B2), D2 = new Uint8Array(e2.buffer, e2.byteOffset + Q2, b2), k2 = new Uint8Array(e2.buffer, e2.byteOffset + L2, y2);
|
|
return n3.globalData = { endpointCount: E2, selectorCount: C2, imageDescs: I2, endpointsData: M2, selectorsData: S2, tablesData: D2, extendedData: k2 }, n3;
|
|
}(new Uint8Array(e)), i2 = n2.vkFormat === sn && n2.dataFormatDescriptor[0].colorModel === 167;
|
|
if (n2.vkFormat !== 0 && (!i2 || this.workerConfig.astcHDRSupported))
|
|
return async function(e2) {
|
|
const { vkFormat: t3 } = e2;
|
|
if (yn[t3] === undefined)
|
|
throw new Error("THREE.KTX2Loader: Unsupported vkFormat.");
|
|
let n3;
|
|
e2.supercompressionScheme === 2 && (Cn || (Cn = new Promise(async (e3) => {
|
|
const t4 = new fn;
|
|
await t4.init(), e3(t4);
|
|
})), n3 = await Cn);
|
|
const i3 = [];
|
|
for (let r4 = 0;r4 < e2.levels.length; r4++) {
|
|
const o3 = Math.max(1, e2.pixelWidth >> r4), s2 = Math.max(1, e2.pixelHeight >> r4), a2 = e2.pixelDepth ? Math.max(1, e2.pixelDepth >> r4) : 0, A2 = e2.levels[r4];
|
|
let l2, c2;
|
|
if (e2.supercompressionScheme === 0)
|
|
l2 = A2.levelData;
|
|
else {
|
|
if (e2.supercompressionScheme !== 2)
|
|
throw new Error("THREE.KTX2Loader: Unsupported supercompressionScheme.");
|
|
l2 = n3.decode(A2.levelData, A2.uncompressedByteLength);
|
|
}
|
|
c2 = In[t3] === Re.FloatType ? new Float32Array(l2.buffer, l2.byteOffset, l2.byteLength / Float32Array.BYTES_PER_ELEMENT) : In[t3] === Re.HalfFloatType ? new Uint16Array(l2.buffer, l2.byteOffset, l2.byteLength / Uint16Array.BYTES_PER_ELEMENT) : l2, i3.push({ data: c2, width: o3, height: s2, depth: a2 });
|
|
}
|
|
let r3;
|
|
if (bn.has(yn[t3]))
|
|
r3 = e2.pixelDepth === 0 ? new Re.DataTexture(i3[0].data, e2.pixelWidth, e2.pixelHeight) : new Re.Data3DTexture(i3[0].data, e2.pixelWidth, e2.pixelHeight, e2.pixelDepth);
|
|
else {
|
|
if (e2.pixelDepth > 0)
|
|
throw new Error("THREE.KTX2Loader: Unsupported pixelDepth.");
|
|
r3 = new Re.CompressedTexture(i3, e2.pixelWidth, e2.pixelHeight), r3.minFilter = i3.length === 1 ? Re.LinearFilter : Re.LinearMipmapLinearFilter, r3.magFilter = Re.LinearFilter;
|
|
}
|
|
return r3.mipmaps = i3, r3.type = In[t3], r3.format = yn[t3], r3.colorSpace = wn(e2), r3.needsUpdate = true, Promise.resolve(r3);
|
|
}(n2);
|
|
const r2 = t2, o2 = this.init().then(() => this.workerPool.postMessage({ type: "transcode", buffer: e, taskConfig: r2 }, [e])).then((e2) => this._createTextureFrom(e2.data, n2));
|
|
return En.set(e, { promise: o2 }), o2;
|
|
}
|
|
dispose() {
|
|
return this.workerPool.dispose(), this.workerSourceURL && URL.revokeObjectURL(this.workerSourceURL), vn--, this;
|
|
}
|
|
};
|
|
Bn.BasisFormat = { ETC1S: 0, UASTC: 1, UASTC_HDR: 2 }, Bn.TranscoderFormat = { ETC1: 0, ETC2: 1, BC1: 2, BC3: 3, BC4: 4, BC5: 5, BC7_M6_OPAQUE_ONLY: 6, BC7_M5: 7, PVRTC1_4_RGB: 8, PVRTC1_4_RGBA: 9, ASTC_4x4: 10, ATC_RGB: 11, ATC_RGBA_INTERPOLATED_ALPHA: 12, RGBA32: 13, RGB565: 14, BGR565: 15, RGBA4444: 16, BC6H: 22, RGB_HALF: 24, RGBA_HALF: 25 }, Bn.EngineFormat = { RGBAFormat: Re.RGBAFormat, RGBA_ASTC_4x4_Format: Re.RGBA_ASTC_4x4_Format, RGB_BPTC_UNSIGNED_Format: Re.RGB_BPTC_UNSIGNED_Format, RGBA_BPTC_Format: Re.RGBA_BPTC_Format, RGBA_ETC2_EAC_Format: Re.RGBA_ETC2_EAC_Format, RGBA_PVRTC_4BPPV1_Format: Re.RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format: Re.RGBA_S3TC_DXT5_Format, RGB_ETC1_Format: Re.RGB_ETC1_Format, RGB_ETC2_Format: Re.RGB_ETC2_Format, RGB_PVRTC_4BPPV1_Format: Re.RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format: Re.RGBA_S3TC_DXT1_Format }, Bn.EngineType = { UnsignedByteType: Re.UnsignedByteType, HalfFloatType: Re.HalfFloatType, FloatType: Re.FloatType }, Bn.BasisWorker = function() {
|
|
let e, t2, n2;
|
|
const i2 = _EngineFormat, r2 = _EngineType, o2 = _TranscoderFormat, s2 = _BasisFormat;
|
|
self.addEventListener("message", function(i3) {
|
|
const o3 = i3.data;
|
|
switch (o3.type) {
|
|
case "init":
|
|
e = o3.config, a3 = o3.transcoderBinary, t2 = new Promise((e2) => {
|
|
n2 = { wasmBinary: a3, onRuntimeInitialized: e2 }, BASIS(n2);
|
|
}).then(() => {
|
|
n2.initializeBasis(), n2.KTX2File === undefined && console.warn("THREE.KTX2Loader: Please update Basis Universal transcoder.");
|
|
});
|
|
break;
|
|
case "transcode":
|
|
t2.then(() => {
|
|
try {
|
|
const { faces: t3, buffers: i4, width: a4, height: h2, hasAlpha: d2, format: u2, type: g2, dfdFlags: p2 } = function(t4) {
|
|
const i5 = new n2.KTX2File(new Uint8Array(t4));
|
|
function o4() {
|
|
i5.close(), i5.delete();
|
|
}
|
|
if (!i5.isValid())
|
|
throw o4(), new Error("THREE.KTX2Loader:\tInvalid or unsupported .ktx2 file");
|
|
let a5;
|
|
if (i5.isUASTC())
|
|
a5 = s2.UASTC;
|
|
else if (i5.isETC1S())
|
|
a5 = s2.ETC1S;
|
|
else {
|
|
if (!i5.isHDR())
|
|
throw new Error("THREE.KTX2Loader: Unknown Basis encoding");
|
|
a5 = s2.UASTC_HDR;
|
|
}
|
|
const h3 = i5.getWidth(), d3 = i5.getHeight(), u3 = i5.getLayers() || 1, g3 = i5.getLevels(), p3 = i5.getFaces(), f2 = i5.getHasAlpha(), m2 = i5.getDFDFlags(), { transcoderFormat: E2, engineFormat: C2, engineType: v2 } = function(t5, n3, i6, r3) {
|
|
const o5 = A2[t5];
|
|
for (let s3 = 0;s3 < o5.length; s3++) {
|
|
const a6 = o5[s3];
|
|
if ((!a6.if || e[a6.if]) && (a6.basisFormat.includes(t5) && !(r3 && a6.transcoderFormat.length < 2) && (!a6.needsPowerOfTwo || l2(n3) && l2(i6))))
|
|
return { transcoderFormat: a6.transcoderFormat[r3 ? 1 : 0], engineFormat: a6.engineFormat[r3 ? 1 : 0], engineType: a6.engineType[0] };
|
|
}
|
|
throw new Error("THREE.KTX2Loader: Failed to identify transcoding target.");
|
|
}(a5, h3, d3, f2);
|
|
if (!h3 || !d3 || !g3)
|
|
throw o4(), new Error("THREE.KTX2Loader:\tInvalid texture");
|
|
if (!i5.startTranscoding())
|
|
throw o4(), new Error("THREE.KTX2Loader: .startTranscoding failed");
|
|
const B2 = [], b2 = [];
|
|
for (let e2 = 0;e2 < p3; e2++) {
|
|
const t5 = [];
|
|
for (let n3 = 0;n3 < g3; n3++) {
|
|
const s3 = [];
|
|
let a6, A3;
|
|
for (let t6 = 0;t6 < u3; t6++) {
|
|
const l4 = i5.getImageLevelInfo(n3, t6, e2);
|
|
e2 !== 0 || n3 !== 0 || t6 !== 0 || l4.origWidth % 4 == 0 && l4.origHeight % 4 == 0 || console.warn("THREE.KTX2Loader: ETC1S and UASTC textures should use multiple-of-four dimensions."), g3 > 1 ? (a6 = l4.origWidth, A3 = l4.origHeight) : (a6 = l4.width, A3 = l4.height);
|
|
let c3 = new Uint8Array(i5.getImageTranscodedSizeInBytes(n3, t6, 0, E2));
|
|
const h4 = i5.transcodeImage(c3, n3, t6, e2, E2, 0, -1, -1);
|
|
if (v2 === r2.HalfFloatType && (c3 = new Uint16Array(c3.buffer, c3.byteOffset, c3.byteLength / Uint16Array.BYTES_PER_ELEMENT)), !h4)
|
|
throw o4(), new Error("THREE.KTX2Loader: .transcodeImage failed.");
|
|
s3.push(c3);
|
|
}
|
|
const l3 = c2(s3);
|
|
t5.push({ data: l3, width: a6, height: A3 }), b2.push(l3.buffer);
|
|
}
|
|
B2.push({ mipmaps: t5, width: h3, height: d3, format: C2, type: v2 });
|
|
}
|
|
return o4(), { faces: B2, buffers: b2, width: h3, height: d3, hasAlpha: f2, dfdFlags: m2, format: C2, type: v2 };
|
|
}(o3.buffer);
|
|
self.postMessage({ type: "transcode", id: o3.id, data: { faces: t3, width: a4, height: h2, hasAlpha: d2, format: u2, type: g2, dfdFlags: p2 } }, i4);
|
|
} catch (e2) {
|
|
console.error(e2), self.postMessage({ type: "error", id: o3.id, error: e2.message });
|
|
}
|
|
});
|
|
}
|
|
var a3;
|
|
});
|
|
const a2 = [{ if: "astcSupported", basisFormat: [s2.UASTC], transcoderFormat: [o2.ASTC_4x4, o2.ASTC_4x4], engineFormat: [i2.RGBA_ASTC_4x4_Format, i2.RGBA_ASTC_4x4_Format], engineType: [r2.UnsignedByteType], priorityETC1S: 1 / 0, priorityUASTC: 1, needsPowerOfTwo: false }, { if: "bptcSupported", basisFormat: [s2.ETC1S, s2.UASTC], transcoderFormat: [o2.BC7_M5, o2.BC7_M5], engineFormat: [i2.RGBA_BPTC_Format, i2.RGBA_BPTC_Format], engineType: [r2.UnsignedByteType], priorityETC1S: 3, priorityUASTC: 2, needsPowerOfTwo: false }, { if: "dxtSupported", basisFormat: [s2.ETC1S, s2.UASTC], transcoderFormat: [o2.BC1, o2.BC3], engineFormat: [i2.RGBA_S3TC_DXT1_Format, i2.RGBA_S3TC_DXT5_Format], engineType: [r2.UnsignedByteType], priorityETC1S: 4, priorityUASTC: 5, needsPowerOfTwo: false }, { if: "etc2Supported", basisFormat: [s2.ETC1S, s2.UASTC], transcoderFormat: [o2.ETC1, o2.ETC2], engineFormat: [i2.RGB_ETC2_Format, i2.RGBA_ETC2_EAC_Format], engineType: [r2.UnsignedByteType], priorityETC1S: 1, priorityUASTC: 3, needsPowerOfTwo: false }, { if: "etc1Supported", basisFormat: [s2.ETC1S, s2.UASTC], transcoderFormat: [o2.ETC1], engineFormat: [i2.RGB_ETC1_Format], engineType: [r2.UnsignedByteType], priorityETC1S: 2, priorityUASTC: 4, needsPowerOfTwo: false }, { if: "pvrtcSupported", basisFormat: [s2.ETC1S, s2.UASTC], transcoderFormat: [o2.PVRTC1_4_RGB, o2.PVRTC1_4_RGBA], engineFormat: [i2.RGB_PVRTC_4BPPV1_Format, i2.RGBA_PVRTC_4BPPV1_Format], engineType: [r2.UnsignedByteType], priorityETC1S: 5, priorityUASTC: 6, needsPowerOfTwo: true }, { if: "bptcSupported", basisFormat: [s2.UASTC_HDR], transcoderFormat: [o2.BC6H], engineFormat: [i2.RGB_BPTC_UNSIGNED_Format], engineType: [r2.HalfFloatType], priorityHDR: 1, needsPowerOfTwo: false }, { basisFormat: [s2.ETC1S, s2.UASTC], transcoderFormat: [o2.RGBA32, o2.RGBA32], engineFormat: [i2.RGBAFormat, i2.RGBAFormat], engineType: [r2.UnsignedByteType, r2.UnsignedByteType], priorityETC1S: 100, priorityUASTC: 100, needsPowerOfTwo: false }, { basisFormat: [s2.UASTC_HDR], transcoderFormat: [o2.RGBA_HALF], engineFormat: [i2.RGBAFormat], engineType: [r2.HalfFloatType], priorityHDR: 100, needsPowerOfTwo: false }], A2 = { [s2.ETC1S]: a2.filter((e2) => e2.basisFormat.includes(s2.ETC1S)).sort((e2, t3) => e2.priorityUASTC - t3.priorityUASTC), [s2.UASTC]: a2.filter((e2) => e2.basisFormat.includes(s2.UASTC)).sort((e2, t3) => e2.priorityUASTC - t3.priorityUASTC), [s2.UASTC_HDR]: a2.filter((e2) => e2.basisFormat.includes(s2.UASTC_HDR)).sort((e2, t3) => e2.priorityHDR - t3.priorityHDR) };
|
|
function l2(e2) {
|
|
return e2 <= 2 || !(e2 & e2 - 1) && e2 !== 0;
|
|
}
|
|
function c2(e2) {
|
|
if (e2.length === 1)
|
|
return e2[0];
|
|
let t3 = 0;
|
|
for (let n4 = 0;n4 < e2.length; n4++)
|
|
t3 += e2[n4].byteLength;
|
|
const n3 = new Uint8Array(t3);
|
|
let i3 = 0;
|
|
for (let t4 = 0;t4 < e2.length; t4++) {
|
|
const r3 = e2[t4];
|
|
n3.set(r3, i3), i3 += r3.byteLength;
|
|
}
|
|
return n3;
|
|
}
|
|
};
|
|
bn = new Set([Re.RGBAFormat, Re.RGFormat, Re.RedFormat]);
|
|
yn = { [nn]: Re.RGBAFormat, [$t]: Re.RGBAFormat, [Wt]: Re.RGBAFormat, [Jt]: Re.RGBAFormat, [tn]: Re.RGFormat, [Zt]: Re.RGFormat, [Yt]: Re.RGFormat, [Kt]: Re.RGFormat, [en]: Re.RedFormat, [Xt]: Re.RedFormat, [zt]: Re.RedFormat, [Vt]: Re.RedFormat, [sn]: Re.RGBA_ASTC_4x4_Format, [on]: Re.RGBA_ASTC_6x6_Format, [rn]: Re.RGBA_ASTC_6x6_Format };
|
|
In = { [nn]: Re.FloatType, [$t]: Re.HalfFloatType, [Wt]: Re.UnsignedByteType, [Jt]: Re.UnsignedByteType, [tn]: Re.FloatType, [Zt]: Re.HalfFloatType, [Yt]: Re.UnsignedByteType, [Kt]: Re.UnsignedByteType, [en]: Re.FloatType, [Xt]: Re.HalfFloatType, [zt]: Re.UnsignedByteType, [Vt]: Re.UnsignedByteType, [sn]: Re.HalfFloatType, [on]: Re.UnsignedByteType, [rn]: Re.UnsignedByteType };
|
|
xn = { c: null, u: [new Re.Vector3, new Re.Vector3, new Re.Vector3], e: [] };
|
|
Qn = { c: null, u: [new Re.Vector3, new Re.Vector3, new Re.Vector3], e: [] };
|
|
Ln = [[], [], []];
|
|
Mn = [[], [], []];
|
|
Sn = [];
|
|
Dn = new Re.Vector3;
|
|
kn = new Re.Vector3;
|
|
Tn = new Re.Vector3;
|
|
Rn = new Re.Vector3;
|
|
Fn = new Re.Vector3;
|
|
Un = new Re.Vector3;
|
|
On = new Re.Matrix3;
|
|
Pn = new Re.Box3;
|
|
Gn = new Re.Matrix4;
|
|
Nn = new Re.Matrix4;
|
|
jn = new Re.Ray;
|
|
Hn = new _n;
|
|
qn = /^[og]\s*(.+)?/;
|
|
Vn = /^mtllib /;
|
|
zn = /^usemtl /;
|
|
Yn = /^usemap /;
|
|
Kn = /\s+/;
|
|
Wn = new Re.Vector3;
|
|
Jn = new Re.Vector3;
|
|
Xn = new Re.Vector3;
|
|
Zn = new Re.Vector3;
|
|
$n = new Re.Vector3;
|
|
ei = new Re.Color;
|
|
ni = class ni extends Re.Loader {
|
|
constructor(e) {
|
|
super(e), this.materials = null;
|
|
}
|
|
load(e, t2, n2, i2) {
|
|
const r2 = this, o2 = new Re.FileLoader(this.manager);
|
|
o2.setPath(this.path), o2.setRequestHeader(this.requestHeader), o2.setWithCredentials(this.withCredentials), o2.load(e, function(n3) {
|
|
try {
|
|
t2(r2.parse(n3));
|
|
} catch (t3) {
|
|
i2 ? i2(t3) : console.error(t3), r2.manager.itemError(e);
|
|
}
|
|
}, n2, i2);
|
|
}
|
|
setMaterials(e) {
|
|
return this.materials = e, this;
|
|
}
|
|
parse(e) {
|
|
const t2 = new ti;
|
|
e.indexOf(`\r
|
|
`) !== -1 && (e = e.replace(/\r\n/g, `
|
|
`)), e.indexOf("\\\n") !== -1 && (e = e.replace(/\\\n/g, ""));
|
|
const n2 = e.split(`
|
|
`);
|
|
let i2 = [];
|
|
for (let e2 = 0, r3 = n2.length;e2 < r3; e2++) {
|
|
const r4 = n2[e2].trimStart();
|
|
if (r4.length === 0)
|
|
continue;
|
|
const o2 = r4.charAt(0);
|
|
if (o2 !== "#")
|
|
if (o2 === "v") {
|
|
const e3 = r4.split(Kn);
|
|
switch (e3[0]) {
|
|
case "v":
|
|
t2.vertices.push(parseFloat(e3[1]), parseFloat(e3[2]), parseFloat(e3[3])), e3.length >= 7 ? (ei.setRGB(parseFloat(e3[4]), parseFloat(e3[5]), parseFloat(e3[6]), Re.SRGBColorSpace), t2.colors.push(ei.r, ei.g, ei.b)) : t2.colors.push(undefined, undefined, undefined);
|
|
break;
|
|
case "vn":
|
|
t2.normals.push(parseFloat(e3[1]), parseFloat(e3[2]), parseFloat(e3[3]));
|
|
break;
|
|
case "vt":
|
|
t2.uvs.push(parseFloat(e3[1]), parseFloat(e3[2]));
|
|
}
|
|
} else if (o2 === "f") {
|
|
const e3 = r4.slice(1).trim().split(Kn), n3 = [];
|
|
for (let t3 = 0, i4 = e3.length;t3 < i4; t3++) {
|
|
const i5 = e3[t3];
|
|
if (i5.length > 0) {
|
|
const e4 = i5.split("/");
|
|
n3.push(e4);
|
|
}
|
|
}
|
|
const i3 = n3[0];
|
|
for (let e4 = 1, r5 = n3.length - 1;e4 < r5; e4++) {
|
|
const r6 = n3[e4], o3 = n3[e4 + 1];
|
|
t2.addFace(i3[0], r6[0], o3[0], i3[1], r6[1], o3[1], i3[2], r6[2], o3[2]);
|
|
}
|
|
} else if (o2 === "l") {
|
|
const e3 = r4.substring(1).trim().split(" ");
|
|
let n3 = [];
|
|
const i3 = [];
|
|
if (r4.indexOf("/") === -1)
|
|
n3 = e3;
|
|
else
|
|
for (let t3 = 0, r5 = e3.length;t3 < r5; t3++) {
|
|
const r6 = e3[t3].split("/");
|
|
r6[0] !== "" && n3.push(r6[0]), r6[1] !== "" && i3.push(r6[1]);
|
|
}
|
|
t2.addLineGeometry(n3, i3);
|
|
} else if (o2 === "p") {
|
|
const e3 = r4.slice(1).trim().split(" ");
|
|
t2.addPointGeometry(e3);
|
|
} else if ((i2 = qn.exec(r4)) !== null) {
|
|
const e3 = (" " + i2[0].slice(1).trim()).slice(1);
|
|
t2.startObject(e3);
|
|
} else if (zn.test(r4))
|
|
t2.object.startMaterial(r4.substring(7).trim(), t2.materialLibraries);
|
|
else if (Vn.test(r4))
|
|
t2.materialLibraries.push(r4.substring(7).trim());
|
|
else if (Yn.test(r4))
|
|
console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');
|
|
else if (o2 === "s") {
|
|
if (i2 = r4.split(" "), i2.length > 1) {
|
|
const e4 = i2[1].trim().toLowerCase();
|
|
t2.object.smooth = e4 !== "0" && e4 !== "off";
|
|
} else
|
|
t2.object.smooth = true;
|
|
const e3 = t2.object.currentMaterial();
|
|
e3 && (e3.smooth = t2.object.smooth);
|
|
} else {
|
|
if (r4 === "\x00")
|
|
continue;
|
|
console.warn('THREE.OBJLoader: Unexpected line: "' + r4 + '"');
|
|
}
|
|
}
|
|
t2.finalize();
|
|
const r2 = new Re.Group;
|
|
if (r2.materialLibraries = [].concat(t2.materialLibraries), !(t2.objects.length === 1 && t2.objects[0].geometry.vertices.length === 0) == true)
|
|
for (let e2 = 0, n3 = t2.objects.length;e2 < n3; e2++) {
|
|
const n4 = t2.objects[e2], i3 = n4.geometry, o2 = n4.materials, s2 = i3.type === "Line", a2 = i3.type === "Points";
|
|
let A2 = false;
|
|
if (i3.vertices.length === 0)
|
|
continue;
|
|
const l2 = new Re.BufferGeometry;
|
|
l2.setAttribute("position", new Re.Float32BufferAttribute(i3.vertices, 3)), i3.normals.length > 0 && l2.setAttribute("normal", new Re.Float32BufferAttribute(i3.normals, 3)), i3.colors.length > 0 && (A2 = true, l2.setAttribute("color", new Re.Float32BufferAttribute(i3.colors, 3))), i3.hasUVIndices === true && l2.setAttribute("uv", new Re.Float32BufferAttribute(i3.uvs, 2));
|
|
const c2 = [];
|
|
for (let e3 = 0, n5 = o2.length;e3 < n5; e3++) {
|
|
const n6 = o2[e3], i4 = n6.name + "_" + n6.smooth + "_" + A2;
|
|
let r3 = t2.materials[i4];
|
|
if (this.materials !== null)
|
|
if (r3 = this.materials.create(n6.name), !s2 || !r3 || r3 instanceof Re.LineBasicMaterial) {
|
|
if (a2 && r3 && !(r3 instanceof Re.PointsMaterial)) {
|
|
const e4 = new Re.PointsMaterial({ size: 10, sizeAttenuation: false });
|
|
Re.Material.prototype.copy.call(e4, r3), e4.color.copy(r3.color), e4.map = r3.map, r3 = e4;
|
|
}
|
|
} else {
|
|
const e4 = new Re.LineBasicMaterial;
|
|
Re.Material.prototype.copy.call(e4, r3), e4.color.copy(r3.color), r3 = e4;
|
|
}
|
|
r3 === undefined && (r3 = s2 ? new Re.LineBasicMaterial : a2 ? new Re.PointsMaterial({ size: 1, sizeAttenuation: false }) : new Re.MeshPhongMaterial, r3.name = n6.name, r3.flatShading = !n6.smooth, r3.vertexColors = A2, t2.materials[i4] = r3), c2.push(r3);
|
|
}
|
|
let h2;
|
|
if (c2.length > 1) {
|
|
for (let e3 = 0, t3 = o2.length;e3 < t3; e3++) {
|
|
const t4 = o2[e3];
|
|
l2.addGroup(t4.groupStart, t4.groupCount, e3);
|
|
}
|
|
h2 = s2 ? new Re.LineSegments(l2, c2) : a2 ? new Re.Points(l2, c2) : new Re.Mesh(l2, c2);
|
|
} else
|
|
h2 = s2 ? new Re.LineSegments(l2, c2[0]) : a2 ? new Re.Points(l2, c2[0]) : new Re.Mesh(l2, c2[0]);
|
|
h2.name = n4.name, r2.add(h2);
|
|
}
|
|
else if (t2.vertices.length > 0) {
|
|
const e2 = new Re.PointsMaterial({ size: 1, sizeAttenuation: false }), n3 = new Re.BufferGeometry;
|
|
n3.setAttribute("position", new Re.Float32BufferAttribute(t2.vertices, 3)), t2.colors.length > 0 && t2.colors[0] !== undefined && (n3.setAttribute("color", new Re.Float32BufferAttribute(t2.colors, 3)), e2.vertexColors = true);
|
|
const i3 = new Re.Points(n3, e2);
|
|
r2.add(i3);
|
|
}
|
|
return r2;
|
|
}
|
|
};
|
|
ii = class ii extends Re.Loader {
|
|
constructor(e) {
|
|
super(e);
|
|
}
|
|
load(e, t2, n2, i2) {
|
|
const r2 = this, o2 = this.path === "" ? Re.LoaderUtils.extractUrlBase(e) : this.path, s2 = new Re.FileLoader(this.manager);
|
|
s2.setPath(this.path), s2.setRequestHeader(this.requestHeader), s2.setWithCredentials(this.withCredentials), s2.load(e, function(n3) {
|
|
try {
|
|
t2(r2.parse(n3, o2));
|
|
} catch (t3) {
|
|
i2 ? i2(t3) : console.error(t3), r2.manager.itemError(e);
|
|
}
|
|
}, n2, i2);
|
|
}
|
|
setMaterialOptions(e) {
|
|
return this.materialOptions = e, this;
|
|
}
|
|
parse(e, t2) {
|
|
const n2 = e.split(`
|
|
`);
|
|
let i2 = {};
|
|
const r2 = /\s+/, o2 = {};
|
|
for (let e2 = 0;e2 < n2.length; e2++) {
|
|
let t3 = n2[e2];
|
|
if (t3 = t3.trim(), t3.length === 0 || t3.charAt(0) === "#")
|
|
continue;
|
|
const s3 = t3.indexOf(" ");
|
|
let a2 = s3 >= 0 ? t3.substring(0, s3) : t3;
|
|
a2 = a2.toLowerCase();
|
|
let A2 = s3 >= 0 ? t3.substring(s3 + 1) : "";
|
|
if (A2 = A2.trim(), a2 === "newmtl")
|
|
i2 = { name: A2 }, o2[A2] = i2;
|
|
else if (a2 === "ka" || a2 === "kd" || a2 === "ks" || a2 === "ke") {
|
|
const e3 = A2.split(r2, 3);
|
|
i2[a2] = [parseFloat(e3[0]), parseFloat(e3[1]), parseFloat(e3[2])];
|
|
} else
|
|
i2[a2] = A2;
|
|
}
|
|
const s2 = new ri(this.resourcePath || t2, this.materialOptions);
|
|
return s2.setCrossOrigin(this.crossOrigin), s2.setManager(this.manager), s2.setMaterials(o2), s2;
|
|
}
|
|
};
|
|
Ai = globalThis.THREE = { ...Re };
|
|
Ai.DRACOLoader = Ue, Ai.GLTFLoader = Xe, Ai.KTX2Loader = Bn, Ai.OBJLoader = ni, Ai.MTLLoader = ii, Ai.OBB = _n, Ai.BufferGeometryUtils = o, Ai.LightProbeGenerator = oi, Ai.DeviceOrientationControls = ai, Ai.Cache.enabled = true;
|
|
li = Ai;
|
|
ci = window.AFRAME_CDN_ROOT || "https://cdn.aframe.io/";
|
|
di = i(8878);
|
|
ui = i.n(di);
|
|
gi = { colors: { debug: "gray", error: "red", info: "gray", warn: "orange" } };
|
|
ui().formatArgs = function(e) {
|
|
if (e[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + e[0] + (this.useColors ? "%c " : " "), this.useColors) {
|
|
var t2;
|
|
this.color = (t2 = function(e2) {
|
|
var t3 = e2.split(":");
|
|
return t3[t3.length - 1];
|
|
}(this.namespace), gi.colors && gi.colors[t2] || null);
|
|
var n2 = "color: " + this.color;
|
|
e.splice(1, 0, n2, "color: inherit");
|
|
var i2 = 0, r2 = 0;
|
|
e[0].replace(/%[a-zA-Z%]/g, function(e2) {
|
|
e2 !== "%%" && (i2++, e2 === "%c" && (r2 = i2));
|
|
}), e.splice(r2, 0, n2);
|
|
}
|
|
};
|
|
pi = function() {
|
|
try {
|
|
return window.localStorage;
|
|
} catch (e) {}
|
|
}();
|
|
pi && (parseInt(pi.logs, 10) || pi.logs === "true") ? ui().enable("*") : ui().enable("*:error,*:info,*:warn");
|
|
fi = ui();
|
|
mi = i(1124);
|
|
Ei = i.n(mi);
|
|
Ci = fi("device:error");
|
|
bi = navigator.xr !== undefined;
|
|
if (bi) {
|
|
yi = function() {
|
|
var e = document.querySelector("a-scene");
|
|
e ? e.hasLoaded ? e.components["xr-mode-ui"].updateEnterInterfaces() : e.addEventListener("loaded", yi) : window.addEventListener("DOMContentLoaded", yi);
|
|
}, Ii = function(e) {
|
|
Ci("WebXR session support error: " + e.message);
|
|
};
|
|
navigator.xr.isSessionSupported ? (navigator.xr.isSessionSupported("immersive-vr").then(function(e) {
|
|
vi = e, yi();
|
|
}).catch(Ii), navigator.xr.isSessionSupported("immersive-ar").then(function(e) {
|
|
Bi = e, yi();
|
|
}).catch(function() {})) : navigator.xr.supportsSession ? (navigator.xr.supportsSession("immersive-vr").then(function() {
|
|
vi = true, yi();
|
|
}).catch(Ii), navigator.xr.supportsSession("immersive-ar").then(function() {
|
|
Bi = true, yi();
|
|
}).catch(function() {})) : Ci("WebXR has neither isSessionSupported or supportsSession?!");
|
|
}
|
|
Si = (Li = false, Mi = window.navigator.userAgent || window.navigator.vendor || window.opera, (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(Mi) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(Mi.substr(0, 4))) && (Li = true), (Ri() || Di() || Gi()) && (Li = true), Pi() && (Li = false), function() {
|
|
return Li;
|
|
});
|
|
ji = typeof process == "undefined" || true;
|
|
_i = !ji;
|
|
Hi = Object.freeze(Object.create(null));
|
|
Ki = fi("utils:coordinates:warn");
|
|
Wi = ["x", "y", "z", "w"];
|
|
Ji = /^\s*((-?\d*\.{0,1}\d+(e-?\d+)?)\s+){2,3}(-?\d*\.{0,1}\d+(e-?\d+)?)\s*$/;
|
|
Xi = /\s+/g;
|
|
or = function() {
|
|
var e = {};
|
|
return function(t2, n2) {
|
|
return n2 in e || (e[n2] = {}), t2 in e[n2] || (e[n2][t2] = t2.split(n2)), e[n2][t2];
|
|
};
|
|
}();
|
|
cr = fi("utils:src-loader:warn");
|
|
fr = fi("utils:material:warn");
|
|
mr = new Set(["emissiveMap", "envMap", "map", "specularMap"]);
|
|
br = {};
|
|
Qr = /-([a-z])/g;
|
|
Tr = (Dr = [], kr = /url\([^)]+$/, function(e) {
|
|
var t2, n2 = "", i2 = 0;
|
|
for (Dr.length = 0;i2 < e.length; )
|
|
(t2 = e.indexOf(";", i2)) === -1 && (t2 = e.length), n2 += e.substring(i2, t2), kr.test(n2) ? (n2 += ";", i2 = t2 + 1) : (Dr.push(n2.trim()), n2 = "", i2 = t2 + 1);
|
|
return Dr;
|
|
});
|
|
Fr = ["x", "y", "z", "w"];
|
|
jr = fi("utils:warn");
|
|
Jr = Object.assign;
|
|
Xr = Ei();
|
|
to = ($r = Vi(function() {
|
|
return [];
|
|
}), function(e, t2) {
|
|
var n2, i2, r2, o2, s2, a2;
|
|
if (e === undefined || t2 === undefined || e === null || t2 === null || !(e && t2 && e.constructor === Object && t2.constructor === Object || e.constructor === Array && t2.constructor === Array))
|
|
return e === t2;
|
|
for (n2 in i2 = $r.use(), r2 = $r.use(), i2.length = 0, r2.length = 0, e)
|
|
i2.push(n2);
|
|
for (n2 in t2)
|
|
r2.push(n2);
|
|
if (i2.length !== r2.length)
|
|
return $r.recycle(i2), $r.recycle(r2), false;
|
|
for (o2 = 0;o2 < i2.length; ++o2)
|
|
if (s2 = e[i2[o2]], a2 = t2[i2[o2]], typeof s2 == "object" || typeof a2 == "object" || Array.isArray(s2) && Array.isArray(a2)) {
|
|
if (s2 === a2)
|
|
continue;
|
|
if (!to(s2, a2))
|
|
return $r.recycle(i2), $r.recycle(r2), false;
|
|
} else if (s2 !== a2)
|
|
return $r.recycle(i2), $r.recycle(r2), false;
|
|
return $r.recycle(i2), $r.recycle(r2), true;
|
|
});
|
|
no = (eo = [], function(e, t2, n2) {
|
|
var i2, r2, o2, s2, a2, A2, l2;
|
|
for (a2 in s2 = n2 || {}, eo.length = 0, e)
|
|
eo.push(a2);
|
|
if (!t2)
|
|
return s2;
|
|
for (o2 in t2)
|
|
eo.indexOf(o2) === -1 && eo.push(o2);
|
|
for (A2 = 0;A2 < eo.length; A2++)
|
|
i2 = e[a2 = eo[A2]], r2 = t2[a2], ((l2 = i2 && r2 && i2.constructor === Object && r2.constructor === Object) && !to(i2, r2) || !l2 && i2 !== r2) && (s2[a2] = r2);
|
|
return s2;
|
|
});
|
|
co = [uo({ name: "viewport", content: "width=device-width,initial-scale=1,maximum-scale=1,shrink-to-fit=no,user-scalable=no,minimal-ui,viewport-fit=cover" }), uo({ name: "mobile-web-app-capable", content: "yes" }), uo({ name: "theme-color", content: "black" })];
|
|
ho = [uo({ name: "apple-mobile-web-app-capable", content: "yes" }), uo({ name: "apple-mobile-web-app-status-bar-style", content: "black" }), (lo = { rel: "apple-touch-icon", href: "https://aframe.io/images/aframe-logo-152.png" }, { tagName: "link", attributes: lo, exists: function() {
|
|
return document.querySelector('link[rel="' + lo.rel + '"]');
|
|
} })];
|
|
mo = i(5928);
|
|
Eo = i.n(mo);
|
|
Co = d;
|
|
bo = [];
|
|
yo = ui()("core:propertyTypes:warn");
|
|
Io = {};
|
|
wo = /[,> .[\]:]/;
|
|
xo = /url\((.+)\)/;
|
|
Qo("audio", "", Mo, So), Qo("array", [], function(e) {
|
|
return Array.isArray(e) ? e : e && typeof e == "string" ? e.split(",").map(function(e2) {
|
|
return e2.trim();
|
|
}) : [];
|
|
}, function(e) {
|
|
return e.join(", ");
|
|
}, Lo), Qo("asset", "", Mo, So), Qo("boolean", false, function(e) {
|
|
return e !== "false" && e !== false;
|
|
}), Qo("color", "#FFF"), Qo("int", 0, Ro), Qo("number", 0, function(e) {
|
|
return parseFloat(e, 10);
|
|
}), Qo("map", "", Mo, So), Qo("model", "", Mo, So), Qo("selector", null, function(e) {
|
|
return e ? typeof e != "string" ? e : e[0] !== "#" || wo.test(e) ? document.querySelector(e) : document.getElementById(e.substring(1)) : null;
|
|
}, function(e) {
|
|
return e.getAttribute ? "#" + e.getAttribute("id") : ko(e);
|
|
}, To, false), Qo("selectorAll", null, function(e) {
|
|
return e ? typeof e != "string" ? e : Array.prototype.slice.call(document.querySelectorAll(e), 0) : null;
|
|
}, function(e) {
|
|
return e instanceof Array ? e.map(function(e2) {
|
|
return "#" + e2.getAttribute("id");
|
|
}).join(", ") : ko(e);
|
|
}, Lo, false), Qo("src", "", function(e) {
|
|
return yo("`src` property type is deprecated. Use `asset` instead."), Mo(e);
|
|
}, So), Qo("string", ""), Qo("time", 0, Ro), Qo("vec2", { x: 0, y: 0 }, Fo, $i, er), Qo("vec3", { x: 0, y: 0, z: 0 }, Fo, $i, er), Qo("vec4", { x: 0, y: 0, z: 0, w: 1 }, Fo, $i, er);
|
|
Po = Io;
|
|
Go = fi("core:schema:warn");
|
|
qo = (Ho = [], function(e, t2, n2, i2, r2) {
|
|
var o2, s2, a2, A2;
|
|
for (s2 in Ho.length = 0, n2 ? e : t2)
|
|
n2 && e[s2] === undefined || Ho.push(s2);
|
|
if (e === null || typeof e != "object")
|
|
return e;
|
|
for (s2 in e)
|
|
e[s2] === undefined || t2[s2] || r2 || Go("Unknown property `" + s2 + "` for component/system `" + i2 + "`.");
|
|
for (o2 = 0;o2 < Ho.length; o2++) {
|
|
if (a2 = t2[s2 = Ho[o2]], A2 = e[s2], !t2[s2])
|
|
return;
|
|
e[s2] = Vo(A2, a2);
|
|
}
|
|
return e;
|
|
});
|
|
Ko = {};
|
|
Wo = Vo;
|
|
Jo = jo;
|
|
Xo = No;
|
|
Zo = zo;
|
|
$o = Yo;
|
|
es = d;
|
|
ts = fi("core:component:warn");
|
|
ns = document.currentScript;
|
|
is = new RegExp("[A-Z]+");
|
|
rs = {};
|
|
os = Object.freeze({});
|
|
ss = [];
|
|
as = { get: function(e, t2) {
|
|
return e.getComputedPropertyValue(t2);
|
|
}, set: function(e, t2, n2) {
|
|
return t2 in e.schema ? e.recomputeProperty(t2, n2) : n2 !== undefined && e.handleUnknownProperty(t2, n2), true;
|
|
} };
|
|
As.prototype = { schema: {}, init: function() {}, events: {}, update: function(e) {}, updateSchema: undefined, tick: undefined, tock: undefined, play: function() {}, pause: function() {}, remove: function() {}, stringify: function(e) {
|
|
var t2 = this.schema;
|
|
return typeof e == "string" ? e : this.isSingleProperty ? $o(e, t2) : (e = Zo(e, t2), es.stringify(e));
|
|
}, flushToDOM: function(e) {
|
|
var t2 = e ? this.data : this.attrValue;
|
|
t2 != null && window.HTMLElement.prototype.setAttribute.call(this.el, this.attrName, this.stringify(t2));
|
|
}, updateProperties: function(e, t2) {
|
|
var n2 = this.el;
|
|
this.updateData(e, t2), (n2.hasLoaded || n2.isLoading) && (this.initialized ? this.callUpdateHandler() : this.initComponent());
|
|
}, initComponent: function() {
|
|
var e, t2 = this.el;
|
|
t2.initializingComponents[this.name] || (t2.initializingComponents[this.name] = true, this.init(), this.initialized = true, delete t2.initializingComponents[this.name], e = this.isObjectBased ? os : undefined, this.dataChanged = false, this.storeOldData(), this.update(e), t2.isPlaying && this.play(), t2.emit("componentinitialized", this.evtDetail, false));
|
|
}, updateData: function(e, t2) {
|
|
this.isSingleProperty ? this.recomputeProperty(undefined, e) : (t2 ? (zi(this.attrValue), this.recomputeData(e), this.schemaChangeRequired = !!this.updateSchema) : typeof e == "string" ? es.parse(e, this.attrValueProxy) : Jr(this.attrValueProxy, e), this.updateSchemaIfNeeded(e));
|
|
}, updateSchemaIfNeeded: function(e) {
|
|
if (this.schemaChangeRequired && this.updateSchema)
|
|
for (var t2 in ss.length = 0, this.updateSchema(this.data), Yi(this.data, this.schema), this.recomputeData(e), this.schemaChangeRequired = false, this.attrValue)
|
|
this.attrValue[t2] !== undefined && ss.indexOf(t2) === -1 && ((t2 in this.schema) || ts("Unknown property `" + t2 + "` for component `" + this.name + "`."));
|
|
for (var n2 = 0;n2 < ss.length; n2++)
|
|
ts("Unknown property `" + ss[n2] + "` for component `" + this.name + "`.");
|
|
ss.length = 0;
|
|
}, callUpdateHandler: function() {
|
|
if (this.isPositionRotationScale || this.dataChanged) {
|
|
this.dataChanged = false;
|
|
var e = this.oldData;
|
|
this.oldDataInUse = true, this.update(e), e !== this.oldData && this.objectPool.recycle(e), this.oldDataInUse = false, this.storeOldData(), this.throttledEmitComponentChanged();
|
|
}
|
|
}, handleMixinUpdate: function() {
|
|
this.recomputeData(), this.updateSchemaIfNeeded(), this.callUpdateHandler();
|
|
}, resetProperty: function(e) {
|
|
(this.isSingleProperty || (e in this.schema)) && (e ? this.attrValue[e] = undefined : (this.isObjectBased && this.objectPool.recycle(this.attrValue), this.attrValue = undefined), this.recomputeProperty(e, undefined), this.updateSchemaIfNeeded(), this.callUpdateHandler());
|
|
}, extendSchema: function(e) {
|
|
var t2;
|
|
t2 = Jr({}, Ko[this.name].schema), Jr(t2, e), this.schema = Jo(t2), this.el.emit("schemachanged", this.evtDetail);
|
|
}, getComputedPropertyValue: function(e) {
|
|
var t2 = this.el.mixinEls, n2 = this.attrValue && e ? this.attrValue[e] : this.attrValue;
|
|
if (n2 !== undefined)
|
|
return n2;
|
|
for (var i2 = t2.length - 1;i2 >= 0; i2--) {
|
|
var r2 = t2[i2].getAttribute(this.attrName);
|
|
if (r2 !== null && (!e || (e in r2)))
|
|
return e ? r2[e] : r2;
|
|
}
|
|
return e ? this.schema[e].default : this.schema.default;
|
|
}, recomputeProperty: function(e, t2) {
|
|
var n2 = e ? this.schema[e] : this.schema;
|
|
if (t2 != null) {
|
|
this.attrValue === undefined && this.isObjectBased && (this.attrValue = this.objectPool.use());
|
|
var i2 = e ? this.attrValue[e] : this.attrValue;
|
|
typeof (i2 = n2.isCacheable ? Wo(t2, n2, i2) : t2) == "string" && (i2 = t2 === "" ? undefined : t2), e ? this.attrValue[e] = i2 : this.attrValue = i2;
|
|
}
|
|
this.oldDataInUse && (this.oldData = this.objectPool.use(), Yi(this.oldData, this.schema), this.storeOldData(), this.oldDataInUse = false);
|
|
var r2 = e ? this.oldData[e] : this.oldData, o2 = e ? this.data[e] : this.data, s2 = Wo(this.getComputedPropertyValue(e), n2, o2);
|
|
return n2.type !== "array" || e || (s2 = Zr(s2)), n2.equals(s2, r2) || (this.dataChanged = true, n2.schemaChange && (this.schemaChangeRequired = true)), e ? this.data[e] = s2 : this.data = s2, s2;
|
|
}, handleUnknownProperty: function(e, t2) {
|
|
this.attrValue === undefined && (this.attrValue = this.objectPool.use()), this.attrValue[e] = t2, this.deferUnknownPropertyWarnings ? ss.push(e) : this.silenceUnknownPropertyWarnings || ts("Unknown property `" + e + "` for component `" + this.name + "`.");
|
|
}, storeOldData: function() {
|
|
var e;
|
|
if (this.isObjectBased)
|
|
if (this.isSingleProperty)
|
|
this.oldData = Wo(this.data, this.schema, this.oldData);
|
|
else
|
|
for (e in this.schema)
|
|
this.data[e] !== undefined && (this.data[e] && typeof this.data[e] == "object" ? this.oldData[e] = Wo(this.data[e], this.schema[e], this.oldData[e]) : this.oldData[e] = this.data[e]);
|
|
else
|
|
this.oldData = this.data;
|
|
}, recomputeData: function(e) {
|
|
var t2;
|
|
if (this.isSingleProperty)
|
|
this.recomputeProperty(undefined, e);
|
|
else {
|
|
for (t2 in this.schema)
|
|
this.attrValueProxy[t2] = undefined;
|
|
e && typeof e == "object" ? Jr(this.attrValueProxy, e) : typeof e == "string" && es.parse(e, this.attrValueProxy);
|
|
}
|
|
}, eventsAttach: function() {
|
|
var e;
|
|
for (e in this.eventsDetach(), this.events)
|
|
this.el.addEventListener(e, this.events[e]);
|
|
}, eventsDetach: function() {
|
|
var e;
|
|
for (e in this.events)
|
|
this.el.removeEventListener(e, this.events[e]);
|
|
}, destroy: function() {
|
|
this.objectPool.recycle(this.attrValue), this.objectPool.recycle(this.data), this.objectPool.recycle(this.oldData), this.attrValue = this.data = this.oldData = this.attrValueProxy = undefined;
|
|
} };
|
|
ls = {};
|
|
ps = d;
|
|
fs = {};
|
|
ms.prototype = { schema: {}, init: function() {}, update: function(e) {}, updateProperties: function(e) {
|
|
var t2 = this.data;
|
|
Object.keys(this.schema).length !== 0 && (this.buildData(e), this.update(t2));
|
|
}, buildData: function(e) {
|
|
var t2 = this.schema;
|
|
Object.keys(t2).length !== 0 && (e = e || window.HTMLElement.prototype.getAttribute.call(this.sceneEl, this.name), No(t2) ? this.data = Vo(e, t2) : this.data = qo(ps.parse(e) || {}, t2, false, this.name));
|
|
}, tick: undefined, tock: undefined, play: function() {}, pause: function() {} };
|
|
Cs = fi("core:a-node:warn");
|
|
vs = { "a-scene": true, "a-assets": true, "a-assets-items": true, "a-cubemap": true, "a-mixin": true, "a-node": true, "a-entity": true };
|
|
bs = class bs extends HTMLElement {
|
|
constructor() {
|
|
super(), this.computedMixinStr = "", this.hasLoaded = false, this.isANode = true, this.mixinEls = [];
|
|
}
|
|
connectedCallback() {
|
|
us ? this.doConnectedCallback() : document.addEventListener("aframeready", this.connectedCallback.bind(this));
|
|
}
|
|
doConnectedCallback() {
|
|
var e;
|
|
this.sceneEl = this.closestScene(), this.sceneEl || Cs("You are attempting to attach <" + this.tagName + "> outside of an A-Frame scene. Append this element to `<a-scene>` instead."), this.hasLoaded = false, this.emit("nodeready", undefined, false), this.isMixin || (e = this.getAttribute("mixin")) && this.updateMixins(e);
|
|
}
|
|
attributeChangedCallback(e, t2, n2) {
|
|
n2 !== this.computedMixinStr && (e !== "mixin" || this.isMixin || this.updateMixins(n2, t2));
|
|
}
|
|
closestScene() {
|
|
for (var e = this;e && !e.isScene; )
|
|
e = e.parentElement;
|
|
return e;
|
|
}
|
|
closest(e) {
|
|
for (var t2 = this.matches || this.mozMatchesSelector || this.msMatchesSelector || this.oMatchesSelector || this.webkitMatchesSelector, n2 = this;n2 && !t2.call(n2, e); )
|
|
n2 = n2.parentElement;
|
|
return n2;
|
|
}
|
|
disconnectedCallback() {
|
|
this.hasLoaded = false;
|
|
}
|
|
load(e, t2) {
|
|
var n2, i2 = this;
|
|
this.hasLoaded || (t2 = t2 || Bs, n2 = this.getChildren().filter(t2).map(function(e2) {
|
|
return new Promise(function(t3, n3) {
|
|
if (e2.hasLoaded)
|
|
return t3();
|
|
e2.addEventListener("loaded", t3), e2.addEventListener("error", n3);
|
|
});
|
|
}), Promise.allSettled(n2).then(function(t3) {
|
|
t3.forEach(function(e2) {
|
|
e2.status === "rejected" && Cs("Rendering scene with errors on node: ", e2.reason.target);
|
|
}), i2.isLoading = true, i2.setupMutationObserver(), e && e(), i2.isLoading = false, i2.hasLoaded = true, i2.emit("loaded-private", undefined, false), i2.emit("loaded", undefined, false);
|
|
}));
|
|
}
|
|
setupMutationObserver() {
|
|
var e = this;
|
|
new MutationObserver(function(t2) {
|
|
var n2;
|
|
for (n2 = 0;n2 < t2.length; n2++)
|
|
if (t2[n2].type === "attributes") {
|
|
var i2 = t2[n2].attributeName, r2 = window.HTMLElement.prototype.getAttribute.call(e, i2), o2 = t2[n2].oldValue;
|
|
e.attributeChangedCallback(i2, o2, r2);
|
|
}
|
|
}).observe(this, { attributes: true, attributeOldValue: true });
|
|
}
|
|
getChildren() {
|
|
return Array.prototype.slice.call(this.children, 0);
|
|
}
|
|
updateMixins(e, t2) {
|
|
var n2, i2, r2, o2 = bs.newMixinIdArray, s2 = bs.oldMixinIdArray, a2 = bs.mixinIds;
|
|
for (o2.length = 0, s2.length = 0, i2 = e ? or(e.trim(), /\s+/) : o2, r2 = t2 ? or(t2.trim(), /\s+/) : s2, a2.newMixinIds = i2, a2.oldMixinIds = r2, n2 = 0;n2 < r2.length; n2++)
|
|
i2.indexOf(r2[n2]) === -1 && this.unregisterMixin(r2[n2]);
|
|
for (this.computedMixinStr = "", this.mixinEls.length = 0, n2 = 0;n2 < i2.length; n2++)
|
|
this.registerMixin(i2[n2]);
|
|
return this.computedMixinStr && (this.computedMixinStr = this.computedMixinStr.trim(), window.HTMLElement.prototype.setAttribute.call(this, "mixin", this.computedMixinStr)), i2.length === 0 && window.HTMLElement.prototype.removeAttribute.call(this, "mixin"), a2;
|
|
}
|
|
registerMixin(e) {
|
|
var t2, n2, i2, r2 = document.getElementById(e);
|
|
if (r2) {
|
|
if (i2 = r2.getAttribute("mixin"))
|
|
for (t2 = or(i2.trim(), /\s+/), n2 = 0;n2 < t2.length; n2++)
|
|
this.registerMixin(t2[n2]);
|
|
this.computedMixinStr = this.computedMixinStr + " " + r2.id, this.mixinEls.push(r2);
|
|
} else
|
|
Cs("No mixin was found with id `%s`", e);
|
|
}
|
|
setAttribute(e, t2) {
|
|
e === "mixin" && this.updateMixins(t2), window.HTMLElement.prototype.setAttribute.call(this, e, t2);
|
|
}
|
|
unregisterMixin(e) {
|
|
var t2, n2 = this.mixinEls;
|
|
for (t2 = 0;t2 < n2.length; ++t2)
|
|
if (e === n2[t2].id) {
|
|
n2.splice(t2, 1);
|
|
break;
|
|
}
|
|
}
|
|
emit(e, t2, n2, i2) {
|
|
var r2 = bs.evtData;
|
|
n2 === undefined && (n2 = true), r2.bubbles = !!n2, r2.detail = t2, i2 && (r2 = Jr({}, i2, r2)), this.dispatchEvent(new CustomEvent(e, r2));
|
|
}
|
|
};
|
|
bs.evtData = {}, bs.newMixinIdArray = [], bs.oldMixinIdArray = [], bs.mixinIds = {}, customElements.define("a-node", bs);
|
|
ys = fi("core:a-entity:debug");
|
|
Is = fi("core:a-entity:warn");
|
|
xs = ["position", "rotation", "scale", "visible"];
|
|
Qs = { once: true };
|
|
Ls = class Ls extends bs {
|
|
constructor() {
|
|
super(), this.components = {}, this.initializingComponents = {}, this.componentsToUpdate = {}, this.isEntity = true, this.isPlaying = false, this.object3D = new Re.Group, this.object3D.rotation.order = "YXZ", this.object3D.el = this, this.object3DMap = {}, this.parentEl = null, this.rotationObj = {}, this.states = [];
|
|
}
|
|
attributeChangedCallback(e, t2, n2) {
|
|
var i2 = this.components[e];
|
|
super.attributeChangedCallback(), i2 && i2.justInitialized && n2 === "" ? delete i2.justInitialized : (i2 || n2 !== null) && this.setEntityAttribute(e, t2, n2);
|
|
}
|
|
doConnectedCallback() {
|
|
var e, t2, n2 = this;
|
|
super.doConnectedCallback(), t2 = this.sceneEl, this.addToParent(), this.isScene || (t2 ? !(e = t2.querySelector("a-assets")) || e.hasLoaded ? this.load() : e.addEventListener("loaded", function() {
|
|
n2.load();
|
|
}) : this.load());
|
|
}
|
|
disconnectedCallback() {
|
|
var e;
|
|
if (this.parentEl) {
|
|
for (e in this.components)
|
|
this.removeComponent(e, false);
|
|
this.isScene || (this.removeFromParent(), super.disconnectedCallback(), this.object3D.el = null);
|
|
}
|
|
}
|
|
getObject3D(e) {
|
|
return this.object3DMap[e];
|
|
}
|
|
setObject3D(e, t2) {
|
|
var n2, i2 = this;
|
|
if (!(t2 instanceof Re.Object3D))
|
|
throw new Error("`Entity.setObject3D` was called with an object that was not an instance of THREE.Object3D.");
|
|
(n2 = this.getObject3D(e)) && this.object3D.remove(n2), t2.el = this, t2.children.length && t2.traverse(function(e2) {
|
|
e2.el = i2;
|
|
}), this.object3D.add(t2), this.object3DMap[e] = t2, this.emit("object3dset", { object: t2, type: e });
|
|
}
|
|
removeObject3D(e) {
|
|
var t2 = this.getObject3D(e);
|
|
t2 ? (this.object3D.remove(t2), delete this.object3DMap[e], this.emit("object3dremove", { type: e })) : Is("Tried to remove `Object3D` of type:", e, "which was not defined.");
|
|
}
|
|
getOrCreateObject3D(e, t2) {
|
|
var n2 = this.getObject3D(e);
|
|
return !n2 && t2 && (n2 = new t2, this.setObject3D(e, n2)), Is("`getOrCreateObject3D` has been deprecated. Use `setObject3D()` and `object3dset` event instead."), n2;
|
|
}
|
|
add(e) {
|
|
if (!e.object3D)
|
|
throw new Error("Trying to add an element that doesn't have an `object3D`");
|
|
this.object3D.add(e.object3D), this.emit("child-attached", { el: e });
|
|
}
|
|
addToParent() {
|
|
var e = this.parentEl = this.parentNode;
|
|
e && e.add && !this.attachedToParent && (e.add(this), this.attachedToParent = true);
|
|
}
|
|
removeFromParent() {
|
|
var e = this.parentEl;
|
|
this.parentEl.remove(this), this.attachedToParent = false, this.parentEl = null, e.emit("child-detached", { el: this });
|
|
}
|
|
load() {
|
|
var e = this;
|
|
!this.hasLoaded && this.parentEl && super.load.call(this, function() {
|
|
e.parentEl && (e.updateComponents(), (e.isScene || e.parentEl.isPlaying) && e.play());
|
|
});
|
|
}
|
|
remove(e) {
|
|
e ? this.object3D.remove(e.object3D) : this.parentNode.removeChild(this);
|
|
}
|
|
getChildEntities() {
|
|
for (var e = this.children, t2 = [], n2 = 0;n2 < e.length; n2++) {
|
|
var i2 = e[n2];
|
|
i2 instanceof Ls && t2.push(i2);
|
|
}
|
|
return t2;
|
|
}
|
|
initComponent(e, t2, n2) {
|
|
var i2, r2, o2, s2;
|
|
s2 = (o2 = or(e, ws))[0], r2 = o2.length > 2 ? o2.slice(1).join("__") : o2[1], Ko[s2] && (Ms(this, e) || t2 !== undefined || n2) && ((e in this.components) || (this.initComponentDependencies(s2), i2 = new Ko[s2].Component(this, t2, r2), this.isPlaying && i2.play(), this.hasAttribute(e) || (i2.justInitialized = true, window.HTMLElement.prototype.setAttribute.call(this, e, "")), ys("Component initialized: %s", e)));
|
|
}
|
|
initComponentDependencies(e) {
|
|
var t2, n2;
|
|
if (Ko[e] && (t2 = Ko[e].dependencies))
|
|
for (n2 = 0;n2 < t2.length; n2++)
|
|
this.initComponent(t2[n2], window.HTMLElement.prototype.getAttribute.call(this, t2[n2]) || undefined, true);
|
|
}
|
|
removeComponent(e, t2) {
|
|
var n2;
|
|
(n2 = this.components[e]) && (n2.initialized ? (n2.pause(), n2.remove(), t2 && (n2.destroy(), delete this.components[e], this.hasAttribute(e) && window.HTMLElement.prototype.removeAttribute.call(this, e)), this.emit("componentremoved", n2.evtDetail, false)) : this.addEventListener("componentinitialized", function n(i2) {
|
|
i2.detail.name === e && (this.removeComponent(e, t2), this.removeEventListener("componentinitialized", n));
|
|
}));
|
|
}
|
|
updateComponents() {
|
|
var e, t2, n2, i2, r2, o2, s2 = this.componentsToUpdate;
|
|
if (this.hasLoaded || this.isLoading) {
|
|
for (n2 = 0;n2 < this.mixinEls.length; n2++)
|
|
for (i2 in this.mixinEls[n2].componentCache)
|
|
Ss(i2) && (s2[i2] = true);
|
|
if (this.getExtraComponents)
|
|
for (i2 in t2 = this.getExtraComponents())
|
|
Ss(i2) && (s2[i2] = true);
|
|
for (n2 = 0;n2 < this.attributes.length; ++n2)
|
|
i2 = this.attributes[n2].name, xs.indexOf(i2) === -1 && Ss(i2) && (s2[i2] = true);
|
|
for (n2 = 0;n2 < xs.length; n2++)
|
|
i2 = xs[n2], this.hasAttribute(i2) && this.updateComponent(i2, this.getDOMAttribute(i2));
|
|
for (i2 in s2)
|
|
r2 = this.getDOMAttribute(i2), e = (o2 = t2 && t2[i2]) ? o2.constructor === Object ? Jr(o2, Lr(r2 || {})) : r2 || o2 : r2, this.updateComponent(i2, e), delete s2[i2];
|
|
}
|
|
}
|
|
updateComponent(e, t2, n2) {
|
|
var i2 = this.components[e];
|
|
if (i2)
|
|
return t2 !== null || Ms(this, e) ? void i2.updateProperties(t2, n2) : void this.removeComponent(e, true);
|
|
this.initComponent(e, t2, false);
|
|
}
|
|
removeAttribute(e, t2) {
|
|
var n2 = this.components[e];
|
|
n2 && t2 === undefined && this.removeComponent(e, true), n2 && t2 !== undefined ? n2.resetProperty(t2) : (e === "mixin" && this.mixinUpdate(""), window.HTMLElement.prototype.removeAttribute.call(this, e));
|
|
}
|
|
play() {
|
|
var e, t2, n2;
|
|
if (!this.isPlaying && (this.hasLoaded || this.isLoading)) {
|
|
for (n2 in this.isPlaying = true, this.components)
|
|
this.components[n2].play();
|
|
for (e = this.getChildEntities(), t2 = 0;t2 < e.length; t2++)
|
|
e[t2].play();
|
|
this.emit("play");
|
|
}
|
|
}
|
|
pause() {
|
|
var e, t2, n2;
|
|
if (this.isPlaying) {
|
|
for (n2 in this.isPlaying = false, this.components)
|
|
this.components[n2].pause();
|
|
for (e = this.getChildEntities(), t2 = 0;t2 < e.length; t2++)
|
|
e[t2].pause();
|
|
this.emit("pause");
|
|
}
|
|
}
|
|
setEntityAttribute(e, t2, n2) {
|
|
if (Ko[e] || this.components[e])
|
|
this.updateComponent(e, n2);
|
|
else if (e === "mixin") {
|
|
if (n2 === this.computedMixinStr)
|
|
return;
|
|
this.mixinUpdate(n2, t2);
|
|
}
|
|
}
|
|
mixinUpdate(e, t2, n2) {
|
|
var i2, r2, o2, s2, a2 = Ls.componentsUpdated, A2 = this;
|
|
if (n2 || (t2 = t2 || this.getAttribute("mixin")), this.hasLoaded) {
|
|
for (o2 = this.updateMixins(e, t2), a2.length = 0, s2 = 0;s2 < this.mixinEls.length; s2++)
|
|
for (i2 in this.mixinEls[s2].componentCache)
|
|
a2.indexOf(i2) === -1 && (this.components[i2] ? this.components[i2].handleMixinUpdate() : this.initComponent(i2, null), a2.push(i2));
|
|
for (s2 = 0;s2 < o2.oldMixinIds.length; s2++)
|
|
if (r2 = document.getElementById(o2.oldMixinIds[s2]))
|
|
for (i2 in r2.componentCache)
|
|
a2.indexOf(i2) === -1 && this.components[i2] && (this.getDOMAttribute(i2) ? this.components[i2].handleMixinUpdate() : this.removeComponent(i2, true));
|
|
} else
|
|
this.addEventListener("loaded-private", function() {
|
|
A2.mixinUpdate(e, t2, true);
|
|
}, Qs);
|
|
}
|
|
setAttribute(e, t2, n2) {
|
|
var i2, r2, o2, s2, a2, A2 = Ls.singlePropUpdate;
|
|
if (o2 = (s2 = e.indexOf(ws)) > 0 ? e.substring(0, s2) : e, !Ko[o2])
|
|
return e === "mixin" && this.mixinUpdate(t2), void super.setAttribute.call(this, e, t2);
|
|
if (!this.components[e] && this.hasAttribute(e) && this.updateComponent(e, window.HTMLElement.prototype.getAttribute.call(this, e)), n2 !== undefined && typeof t2 == "string" && t2.length > 0 && typeof Lr(t2) == "string") {
|
|
for (a2 in A2)
|
|
delete A2[a2];
|
|
(i2 = A2)[t2] = n2, r2 = false;
|
|
} else
|
|
i2 = t2, r2 = n2 === true;
|
|
this.updateComponent(e, i2, r2), this.sceneEl && this.sceneEl.getAttribute("debug") && this.components[e].flushToDOM();
|
|
}
|
|
flushToDOM(e) {
|
|
var t2, n2, i2, r2 = this.components, o2 = this.children;
|
|
for (i2 in r2)
|
|
r2[i2].flushToDOM();
|
|
if (e)
|
|
for (n2 = 0;n2 < o2.length; ++n2)
|
|
(t2 = o2[n2]).flushToDOM && t2.flushToDOM(e);
|
|
}
|
|
getAttribute(e) {
|
|
var t2, n2, i2, r2;
|
|
return e === "position" ? this.object3D.position : e === "rotation" ? (n2 = Re.MathUtils.radToDeg, i2 = this.object3D.rotation, (r2 = this.rotationObj).x = n2(i2.x), r2.y = n2(i2.y), r2.z = n2(i2.z), r2) : e === "scale" ? this.object3D.scale : e === "visible" ? this.object3D.visible : (t2 = this.components[e]) ? t2.data : window.HTMLElement.prototype.getAttribute.call(this, e);
|
|
}
|
|
getDOMAttribute(e) {
|
|
var t2 = this.components[e];
|
|
return t2 ? t2.attrValue : window.HTMLElement.prototype.getAttribute.call(this, e);
|
|
}
|
|
addState(e) {
|
|
this.is(e) || (this.states.push(e), this.emit("stateadded", e));
|
|
}
|
|
removeState(e) {
|
|
var t2 = this.states.indexOf(e);
|
|
t2 !== -1 && (this.states.splice(t2, 1), this.emit("stateremoved", e));
|
|
}
|
|
is(e) {
|
|
return this.states.indexOf(e) !== -1;
|
|
}
|
|
inspect() {
|
|
this.sceneEl.components.inspector.openInspector(this);
|
|
}
|
|
destroy() {
|
|
var e;
|
|
if (this.parentNode)
|
|
Is("Entity can only be destroyed if detached from scenegraph.");
|
|
else
|
|
for (e in this.components)
|
|
this.components[e].destroy();
|
|
}
|
|
};
|
|
Ls.componentsUpdated = [], Ls.singlePropUpdate = {}, customElements.define("a-entity", Ls), Ri() && window.addEventListener("orientationchange", function() {
|
|
document.documentElement.style.height = "initial", setTimeout(function() {
|
|
document.documentElement.style.height = "100%", setTimeout(function() {
|
|
window.scrollTo(0, 1);
|
|
}, 500);
|
|
}, 500);
|
|
});
|
|
ks = fi("core:a-scene:warn");
|
|
Ts = Ri();
|
|
Rs = Si();
|
|
Fs = bi;
|
|
Us = class Us extends Ls {
|
|
constructor() {
|
|
var e;
|
|
super(), (e = this).clock = new Re.Clock, e.isIOS = Ts, e.isMobile = Rs, e.hasWebXR = Fs, e.isAR = false, e.isScene = true, e.object3D = new Re.Scene, e.resize = e.resize.bind(e), e.render = e.render.bind(e), e.systems = {}, e.systemNames = [], e.time = e.delta = 0, e.usedOfferSession = false, e.componentOrder = [], e.behaviors = {}, e.hasLoaded = false, e.isPlaying = false, e.originalHTML = e.innerHTML;
|
|
}
|
|
addFullScreenStyles() {
|
|
document.documentElement.classList.add("a-fullscreen");
|
|
}
|
|
removeFullScreenStyles() {
|
|
document.documentElement.classList.remove("a-fullscreen");
|
|
}
|
|
doConnectedCallback() {
|
|
var e = this, t2 = this.hasAttribute("embedded");
|
|
this.setAttribute("inspector", ""), this.setAttribute("keyboard-shortcuts", ""), this.setAttribute("screenshot", ""), this.setAttribute("xr-mode-ui", ""), this.setAttribute("device-orientation-permission-ui", ""), super.doConnectedCallback(), function(e2) {
|
|
var t3;
|
|
function n2() {
|
|
document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || e2.exitVR(), document.activeElement.blur(), document.body.focus();
|
|
}
|
|
(t3 = document.createElement("canvas")).classList.add("a-canvas"), t3.dataset.aframeCanvas = true, e2.appendChild(t3), document.addEventListener("fullscreenchange", n2), document.addEventListener("mozfullscreenchange", n2), document.addEventListener("webkitfullscreenchange", n2), document.addEventListener("MSFullscreenChange", n2), t3.addEventListener("touchmove", function(e3) {
|
|
e3.preventDefault();
|
|
}, { passive: false }), e2.canvas = t3, e2.emit("render-target-loaded", { target: t3 }), setTimeout(e2.resize.bind(e2), 0);
|
|
}(this), this.setupRenderer(), function(e2, t3) {
|
|
fo = t3;
|
|
var n2, i2, r2, o2, s2, a2, A2, l2, c2, h2, d2 = (go = e2).hasAttribute(vo) ? Co.parse(go.getAttribute(vo)) : undefined, u2 = d2 && d2.dotsColor || "white", g2 = d2 && d2.backgroundColor || "#24CAFF";
|
|
(d2 === undefined || d2.enabled === "true" || d2.enabled === undefined) && (n2 = new Re.Scene, i2 = new Re.SphereGeometry(0.2, 36, 18, 0, 2 * Math.PI, 0, Math.PI), r2 = new Re.MeshBasicMaterial({ color: u2 }), o2 = new Re.Mesh(i2, r2), s2 = o2.clone(), a2 = o2.clone(), A2 = new Re.PerspectiveCamera(80, window.innerWidth / window.innerHeight, 0.0005, 1e4), l2 = new Re.Clock, c2 = 0, h2 = function() {
|
|
go.renderer.render(n2, A2), c2 = l2.getElapsedTime() % 4, o2.visible = c2 >= 1, s2.visible = c2 >= 2, a2.visible = c2 >= 3;
|
|
}, n2.background = new Re.Color(g2), n2.add(A2), o2.position.set(-1, 0, -15), s2.position.set(0, 0, -15), a2.position.set(1, 0, -15), A2.add(o2), A2.add(s2), A2.add(a2), (po = document.createElement("div")).className = "a-loader-title", po.innerHTML = document.title, po.style.display = "none", po.setAttribute(hi, ""), go.appendChild(po), setTimeout(function() {
|
|
go.hasLoaded || (Bo(A2), po.style.display = "block", window.addEventListener("resize", function() {
|
|
Bo(A2);
|
|
}), go.renderer.setAnimationLoop(h2));
|
|
}, 200));
|
|
}(this, Gs), this.resize(), t2 || this.addFullScreenStyles(), ao() && window.addEventListener("message", Ds.bind(this)), function(e2) {
|
|
var t3, n2 = document.head, i2 = n2.querySelector("script"), r2 = [];
|
|
return co.forEach(o2), e2.isIOS && ho.forEach(o2), r2;
|
|
function o2(e3) {
|
|
e3 && !e3.exists() && (t3 = function(e4) {
|
|
if (e4 && e4.tagName) {
|
|
var t4 = document.createElement(e4.tagName);
|
|
return t4.setAttribute(hi, ""), Jr(t4, e4.attributes);
|
|
}
|
|
}(e3), t3 && (i2 ? i2.parentNode.insertBefore(t3, i2) : n2.appendChild(t3), r2.push(t3)));
|
|
}
|
|
}(this), function(e2) {
|
|
if (e2.isMobile) {
|
|
var t3 = e2.wakelock = new (Eo());
|
|
e2.addEventListener("enter-vr", function() {
|
|
t3.request();
|
|
}), e2.addEventListener("exit-vr", function() {
|
|
t3.release();
|
|
});
|
|
}
|
|
}(this), this.enterVRBound = function() {
|
|
e.enterVR();
|
|
}, this.exitVRBound = function() {
|
|
e.exitVR();
|
|
}, window.addEventListener("sessionend", this.resize), this.addEventListener("cameraready", function() {
|
|
e.attachedCallbackPostCamera();
|
|
}), this.initSystems(), this.componentOrder = Os(Ko, this.componentOrder), this.addEventListener("componentregistered", function() {
|
|
e.componentOrder = Os(Ko, e.componentOrder);
|
|
}), this.hasWebXR && navigator.xr && navigator.xr.addEventListener && navigator.xr.addEventListener("sessiongranted", function() {
|
|
e.enterVR();
|
|
});
|
|
}
|
|
attachedCallbackPostCamera() {
|
|
var e = this;
|
|
window.addEventListener("load", undefined), window.addEventListener("resize", function() {
|
|
e.isIOS ? setTimeout(e.resize, 100) : e.resize();
|
|
}), this.play(), bo.push(this);
|
|
}
|
|
initSystems() {
|
|
var e;
|
|
for (e in this.initSystem("camera"), fs)
|
|
e !== "camera" && this.initSystem(e);
|
|
}
|
|
initSystem(e) {
|
|
this.systems[e] || (this.systems[e] = new fs[e](this), this.systemNames.push(e));
|
|
}
|
|
disconnectedCallback() {
|
|
var e = bo.indexOf(this);
|
|
super.disconnectedCallback(), bo.splice(e, 1), window.removeEventListener("sessionend", this.resize), this.removeFullScreenStyles(), this.renderer.dispose();
|
|
}
|
|
addBehavior(e) {
|
|
var t2, n2, i2 = this.behaviors[e.name];
|
|
for (n2 in i2 || (i2 = this.behaviors[e.name] = { tick: { inUse: false, array: [], markedForRemoval: [] }, tock: { inUse: false, array: [], markedForRemoval: [] } }), i2)
|
|
if (e[n2]) {
|
|
if ((t2 = i2[n2]).inUse) {
|
|
var r2 = t2.markedForRemoval.indexOf(e);
|
|
r2 !== -1 && t2.markedForRemoval.splice(r2, 1);
|
|
}
|
|
t2.array.indexOf(e) === -1 && t2.array.push(e);
|
|
}
|
|
}
|
|
getPointerLockElement() {
|
|
return document.pointerLockElement;
|
|
}
|
|
checkHeadsetConnected() {
|
|
return wi();
|
|
}
|
|
enterAR() {
|
|
var e;
|
|
if (!this.hasWebXR)
|
|
throw e = "Failed to enter AR mode, WebXR not supported.", new Error(e);
|
|
if (!xi())
|
|
throw e = "Failed to enter AR, WebXR immersive-ar mode not supported in your browser or device.", new Error(e);
|
|
return this.enterVR(true);
|
|
}
|
|
enterVR(e, t2) {
|
|
var n2, i2 = this, r2 = i2.renderer.xr;
|
|
if (t2 && (!navigator.xr || !navigator.xr.offerSession))
|
|
return Promise.resolve("OfferSession is not supported.");
|
|
if (i2.usedOfferSession && t2)
|
|
return Promise.resolve("OfferSession was already called.");
|
|
if (this.is("vr-mode"))
|
|
return Promise.resolve("Already in VR.");
|
|
if (this.checkHeadsetConnected() || this.isMobile) {
|
|
var o2 = i2.getAttribute("renderer");
|
|
if (r2.enabled = true, this.hasWebXR) {
|
|
this.xrSession && this.xrSession.removeEventListener("end", this.exitVRBound);
|
|
var s2 = this.sceneEl.systems.webxr.sessionReferenceSpaceType;
|
|
r2.setReferenceSpaceType(s2);
|
|
var a2 = e ? "immersive-ar" : "immersive-vr";
|
|
return n2 = this.sceneEl.systems.webxr.sessionConfiguration, new Promise(function(e2, s3) {
|
|
var l2 = t2 ? navigator.xr.offerSession.bind(navigator.xr) : navigator.xr.requestSession.bind(navigator.xr);
|
|
i2.usedOfferSession |= t2, l2(a2, n2).then(function(s4) {
|
|
t2 && (i2.usedOfferSession = false), r2.layersEnabled = n2.requiredFeatures.indexOf("layers") !== -1, r2.setSession(s4).then(function() {
|
|
r2.setFoveation(o2.foveationLevel), i2.xrSession = s4, i2.systems.renderer.setWebXRFrameRate(s4), s4.addEventListener("end", i2.exitVRBound), A2(e2);
|
|
});
|
|
}, function(e3) {
|
|
s3(new Error("Failed to enter " + (a2 === "immersive-ar" ? "AR" : "VR") + " mode (`requestSession`)", { cause: e3 }));
|
|
});
|
|
});
|
|
}
|
|
throw new Error("Failed to enter " + (e ? "AR" : "VR") + " no WebXR");
|
|
}
|
|
return A2(), Promise.resolve();
|
|
function A2(t3) {
|
|
var n3;
|
|
e ? i2.addState("ar-mode") : i2.addState("vr-mode"), i2.emit("enter-vr", { target: i2 }), !i2.hasWebXR && i2.isMobile && screen.orientation && screen.orientation.lock && screen.orientation.lock("landscape"), i2.addFullScreenStyles(), i2.isMobile || i2.checkHeadsetConnected() || ((n3 = i2.canvas).requestFullscreen || n3.webkitRequestFullscreen || n3.mozRequestFullScreen || n3.msRequestFullscreen).apply(n3, [{ navigationUI: "hide" }]), i2.resize(), t3 && t3();
|
|
}
|
|
}
|
|
exitVR() {
|
|
var e = this, t2 = this.renderer.xr;
|
|
if (!this.is("vr-mode") && !this.is("ar-mode"))
|
|
return Promise.resolve("Not in immersive mode.");
|
|
if (this.checkHeadsetConnected() || this.isMobile) {
|
|
if (t2.enabled = false, !this.hasWebXR)
|
|
throw Error("Failed to exit VR - no WebXR");
|
|
this.xrSession.removeEventListener("end", this.exitVRBound), this.xrSession.end().then(function() {}, function() {}), this.xrSession = undefined;
|
|
} else
|
|
(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement) && (document.exitFullscreen ? document.exitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitExitFullscreen && document.webkitExitFullscreen());
|
|
return e.removeState("vr-mode"), e.removeState("ar-mode"), e.isMobile && screen.orientation && screen.orientation.unlock && screen.orientation.unlock(), e.hasAttribute("embedded") && e.removeFullScreenStyles(), e.resize(), e.isIOS && lr(e.canvas), e.renderer.setPixelRatio(window.devicePixelRatio), e.emit("exit-vr", { target: e }), Promise.resolve();
|
|
}
|
|
getAttribute(e) {
|
|
var t2 = this.systems[e];
|
|
return t2 ? t2.data : Ls.prototype.getAttribute.call(this, e);
|
|
}
|
|
getDOMAttribute(e) {
|
|
var t2 = this.systems[e];
|
|
return t2 ? t2.data : Ls.prototype.getDOMAttribute.call(this, e);
|
|
}
|
|
setAttribute(e, t2, n2) {
|
|
if (fs[e]) {
|
|
bs.prototype.setAttribute.call(this, e, t2);
|
|
var i2 = this.systems[e];
|
|
i2 && i2.updateProperties(t2);
|
|
} else
|
|
Ls.prototype.setAttribute.call(this, e, t2, n2);
|
|
}
|
|
removeBehavior(e) {
|
|
var t2, n2, i2, r2 = this.behaviors[e.name];
|
|
for (n2 in r2)
|
|
e[n2] && (i2 = (t2 = r2[n2]).array.indexOf(e)) !== -1 && (t2.inUse ? t2.markedForRemoval.indexOf(e) === -1 && t2.markedForRemoval.push(e) : (t2.array[i2] = t2.array[t2.array.length - 1], t2.array.pop()));
|
|
}
|
|
resize() {
|
|
var e, t2, n2 = this.camera, i2 = this.canvas, r2 = this.renderer.xr.isPresenting;
|
|
e = this.renderer.xr.enabled && r2, !n2 || !i2 || this.is("vr-mode") && (this.isMobile || e) || (t2 = Gs(i2, this.getAttribute("embedded") && !this.is("vr-mode"), this.maxCanvasSize, this.is("vr-mode")), n2.aspect = t2.width / t2.height, n2.updateProjectionMatrix(), this.renderer.setSize(t2.width, t2.height, false), this.emit("rendererresize", null, false));
|
|
}
|
|
setupRenderer() {
|
|
var e, t2, n2, i2 = this;
|
|
n2 = { alpha: true, antialias: !Rs, canvas: this.canvas, logarithmicDepthBuffer: false, powerPreference: "high-performance" }, this.maxCanvasSize = { height: -1, width: -1 }, this.hasAttribute("renderer") && ((t2 = Lr(this.getAttribute("renderer"))).precision && (n2.precision = t2.precision + "p"), t2.antialias && t2.antialias !== "auto" && (n2.antialias = t2.antialias === "true"), t2.logarithmicDepthBuffer && t2.logarithmicDepthBuffer !== "auto" && (n2.logarithmicDepthBuffer = t2.logarithmicDepthBuffer === "true"), t2.alpha && (n2.alpha = t2.alpha === "true"), t2.stencil && (n2.stencil = t2.stencil === "true"), t2.multiviewStereo && (n2.multiviewStereo = t2.multiviewStereo === "true"), this.maxCanvasSize = { width: t2.maxCanvasWidth ? parseInt(t2.maxCanvasWidth) : this.maxCanvasSize.width, height: t2.maxCanvasHeight ? parseInt(t2.maxCanvasHeight) : this.maxCanvasSize.height });
|
|
var r2 = ["WebGLRenderer", "WebGPURenderer"].find(function(e2) {
|
|
return Re[e2];
|
|
});
|
|
(e = this.renderer = new Re[r2](n2)).xr.setPoseTarget || (e.xr.setPoseTarget = function() {}), e.setPixelRatio(window.devicePixelRatio), this.camera && e.xr.setPoseTarget(this.camera.el.object3D), this.addEventListener("camera-set-active", function() {
|
|
e.xr.setPoseTarget(i2.camera.el.object3D);
|
|
});
|
|
}
|
|
play() {
|
|
var e = this, t2 = this;
|
|
this.renderStarted ? Ls.prototype.play.call(this) : (this.addEventListener("loaded", function() {
|
|
var e2 = this.renderer;
|
|
Ls.prototype.play.call(this), t2.renderStarted || (t2.resize(), t2.renderer && (window.performance && window.performance.mark("render-started"), window.removeEventListener("resize", Bo), po && (po.style.display = "none"), e2.setAnimationLoop(this.render), t2.renderStarted = true, t2.emit("renderstart")));
|
|
}), setTimeout(function() {
|
|
Ls.prototype.load.call(e);
|
|
}));
|
|
}
|
|
updateComponent(e) {
|
|
e in fs || Ls.prototype.updateComponent.apply(this, arguments);
|
|
}
|
|
tick(e, t2) {
|
|
var n2, i2 = this.systems;
|
|
for (this.callComponentBehaviors("tick", e, t2), n2 = 0;n2 < this.systemNames.length; n2++)
|
|
i2[this.systemNames[n2]].tick && i2[this.systemNames[n2]].tick(e, t2);
|
|
}
|
|
tock(e, t2, n2) {
|
|
var i2, r2 = this.systems;
|
|
for (this.callComponentBehaviors("tock", e, t2), i2 = 0;i2 < this.systemNames.length; i2++)
|
|
r2[this.systemNames[i2]].tock && r2[this.systemNames[i2]].tock(e, t2, n2);
|
|
}
|
|
render(e, t2) {
|
|
var n2 = this.renderer;
|
|
this.frame = t2, this.delta = 1000 * this.clock.getDelta(), this.time = 1000 * this.clock.elapsedTime, this.isPlaying && this.tick(this.time, this.delta);
|
|
var i2 = null;
|
|
if (this.is("ar-mode") && (i2 = this.object3D.background, this.object3D.background = null), n2.render(this.object3D, this.camera), i2 && (this.object3D.background = i2), this.isPlaying) {
|
|
var r2 = n2.xr.isPresenting ? n2.xr.getCamera() : this.camera;
|
|
this.tock(this.time, this.delta, r2);
|
|
}
|
|
}
|
|
callComponentBehaviors(e, t2, n2) {
|
|
for (var i2, r2 = 0;r2 < this.componentOrder.length; r2++) {
|
|
var o2 = this.behaviors[this.componentOrder[r2]];
|
|
if (o2) {
|
|
var s2 = o2[e];
|
|
for (s2.inUse = true, i2 = 0;i2 < s2.array.length; i2++)
|
|
s2.array[i2].isPlaying && s2.array[i2][e](t2, n2);
|
|
for (s2.inUse = false, i2 = 0;i2 < s2.markedForRemoval.length; i2++)
|
|
this.removeBehavior(s2.markedForRemoval[i2]);
|
|
s2.markedForRemoval.length = 0;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
customElements.define("a-scene", Us);
|
|
Ns = jo;
|
|
js = {};
|
|
_s = [];
|
|
Hs.prototype = { schema: {}, init: function(e) {
|
|
return this.geometry = new Re.BufferGeometry, this.geometry;
|
|
}, update: function(e) {} };
|
|
Vs = fi;
|
|
zs = Ar;
|
|
Ys = Vs("extras:primitives:debug");
|
|
Ks = Vs("extras:primitives:warn");
|
|
Ws = Vs("extras:primitives:error");
|
|
Js = {};
|
|
$s = {};
|
|
ea = [];
|
|
ta = { array: "v3", color: "v3", int: "i", number: "f", map: "t", time: "f", vec2: "v2", vec3: "v3", vec4: "v4" };
|
|
na.prototype = { schema: {}, vertexShader: "void main() {gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);}", fragmentShader: "void main() {gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);}", init: function(e) {
|
|
return this.uniforms = this.initUniforms(), this.material = new (this.raw ? Re.RawShaderMaterial : Re.ShaderMaterial)({ uniforms: this.uniforms, glslVersion: this.raw || this.glsl3 ? Re.GLSL3 : null, vertexShader: this.vertexShader, fragmentShader: this.fragmentShader }), this.material;
|
|
}, initUniforms: function() {
|
|
var e, t2, n2 = this.schema, i2 = {};
|
|
for (e in n2)
|
|
n2[e].is === "uniform" && (t2 = ta[n2[e].type], i2[e] = { type: t2, value: undefined });
|
|
return i2;
|
|
}, update: function(e) {
|
|
var t2, n2, i2 = this.schema, r2 = this.uniforms;
|
|
for (t2 in e)
|
|
if (i2[t2] && i2[t2].is === "uniform")
|
|
if (i2[t2].type !== "map")
|
|
r2[t2].value = this.parseValue(i2[t2].type, e[t2]), r2[t2].needsUpdate = true;
|
|
else {
|
|
if (!r2[t2] || r2[t2].value === e[t2])
|
|
continue;
|
|
n2 = "_texture_" + t2, this.setMapOnTextureLoad(r2, t2, n2), Cr(n2, t2, this, e);
|
|
}
|
|
}, parseValue: function(e, t2) {
|
|
var n2;
|
|
switch (e) {
|
|
case "vec2":
|
|
return new Re.Vector2(t2.x, t2.y);
|
|
case "vec3":
|
|
return new Re.Vector3(t2.x, t2.y, t2.z);
|
|
case "vec4":
|
|
return new Re.Vector4(t2.x, t2.y, t2.z, t2.w);
|
|
case "color":
|
|
return n2 = new Re.Color(t2), new Re.Vector3(n2.r, n2.g, n2.b);
|
|
default:
|
|
return t2;
|
|
}
|
|
}, setMapOnTextureLoad: function(e, t2, n2) {
|
|
var i2 = this;
|
|
this.el.addEventListener("materialtextureloaded", function() {
|
|
e[t2].value = i2.material[n2], e[t2].needsUpdate = true;
|
|
});
|
|
} };
|
|
ra = new Re.FileLoader;
|
|
oa = fi("core:a-assets:warn");
|
|
customElements.define("a-assets", class extends bs {
|
|
constructor() {
|
|
super(), this.isAssets = true, this.fileLoader = ra, this.timeout = null;
|
|
}
|
|
doConnectedCallback() {
|
|
var e, t2, n2, i2, r2, o2, s2 = this, a2 = [];
|
|
if (super.doConnectedCallback(), !this.parentNode.isScene)
|
|
throw new Error("<a-assets> must be a child of a <a-scene>.");
|
|
for (r2 = this.querySelectorAll("img"), e = 0;e < r2.length; e++)
|
|
i2 = aa(r2[e]), a2.push(new Promise(function(t3, n3) {
|
|
Re.Cache.add(r2[e].getAttribute("src"), i2), i2.complete ? t3() : (i2.onload = t3, i2.onerror = n3);
|
|
}));
|
|
for (n2 = this.querySelectorAll("audio, video"), e = 0;e < n2.length; e++)
|
|
(t2 = aa(n2[e])).src || t2.srcObject || oa("Audio/video asset has neither `src` nor `srcObject` attributes."), a2.push(sa(t2));
|
|
this.getChildren().forEach(function(e2) {
|
|
e2.isAssetItem && e2.hasAttribute("src") && a2.push(new Promise(function(t3, n3) {
|
|
if (e2.hasLoaded)
|
|
return t3();
|
|
e2.addEventListener("loaded", t3), e2.addEventListener("error", n3);
|
|
}));
|
|
}), Promise.allSettled(a2).then(function() {
|
|
s2.timeout !== null && s2.load();
|
|
}), o2 = parseInt(this.getAttribute("timeout"), 10) || 3000, this.timeout = setTimeout(function() {
|
|
s2.hasLoaded || (oa("Asset loading timed out in", o2, "ms"), s2.timeout = null, s2.emit("timeout"), s2.load());
|
|
}, o2);
|
|
}
|
|
disconnectedCallback() {
|
|
super.disconnectedCallback(), this.timeout && clearTimeout(this.timeout);
|
|
}
|
|
load() {
|
|
super.load.call(this, null, function() {
|
|
return false;
|
|
});
|
|
}
|
|
}), customElements.define("a-asset-item", class extends bs {
|
|
constructor() {
|
|
super(), this.data = null, this.isAssetItem = true;
|
|
}
|
|
connectedCallback() {
|
|
var e = this, t2 = this.getAttribute("src");
|
|
ra.setResponseType(this.getAttribute("response-type") || function(e2) {
|
|
var t3 = function(e3) {
|
|
var t4 = document.createElement("a");
|
|
t4.href = e3;
|
|
var n3 = t4.search.replace(/^\?/, ""), i2 = e3.replace(n3, "").replace("?", "");
|
|
return i2.substring(i2.lastIndexOf("/") + 1);
|
|
}(e2), n2 = t3.lastIndexOf(".");
|
|
return n2 >= 0 && t3.slice(n2, e2.search(/\?|#|$/)) === ".glb" ? "arraybuffer" : "text";
|
|
}(t2)), ra.load(t2, function(t3) {
|
|
e.data = t3, bs.prototype.load.call(e);
|
|
}, function(t3) {
|
|
e.emit("progress", { loadedBytes: t3.loaded, totalBytes: t3.total, xhr: t3 });
|
|
}, function(t3) {
|
|
e.emit("error", { xhr: t3 }, false);
|
|
});
|
|
}
|
|
});
|
|
Aa = fi("core:cubemap:warn");
|
|
la = class la extends HTMLElement {
|
|
constructor(e) {
|
|
return super(e);
|
|
}
|
|
onReadyStateChange() {
|
|
document.readyState === "complete" && this.doConnectedCallback();
|
|
}
|
|
connectedCallback() {
|
|
document.readyState === "complete" ? la.prototype.doConnectedCallback.call(this) : document.addEventListener("readystatechange", this.onReadyStateChange.bind(this));
|
|
}
|
|
doConnectedCallback() {
|
|
this.srcs = this.validate();
|
|
}
|
|
validate() {
|
|
var e, t2 = this.querySelectorAll("[src]"), n2 = [];
|
|
if (t2.length === 6) {
|
|
for (e = 0;e < t2.length; e++)
|
|
t2[e].tagName === "IMG" ? n2.push(t2[e]) : n2.push(t2[e].getAttribute("src"));
|
|
return n2;
|
|
}
|
|
Aa("<a-cubemap> did not contain exactly six elements each with a `src` attribute.");
|
|
}
|
|
};
|
|
customElements.define("a-cubemap", la), customElements.define("a-mixin", class extends bs {
|
|
constructor() {
|
|
super(), this.componentCache = {}, this.rawAttributeCache = {}, this.isMixin = true;
|
|
}
|
|
doConnectedCallback() {
|
|
super.doConnectedCallback(), this.sceneEl = this.closestScene(), this.id = this.getAttribute("id"), this.cacheAttributes(), this.updateEntities(), this.load();
|
|
}
|
|
attributeChangedCallback(e, t2, n2) {
|
|
super.attributeChangedCallback(), this.cacheAttribute(e, n2), this.updateEntities();
|
|
}
|
|
setAttribute(e, t2) {
|
|
window.HTMLElement.prototype.setAttribute.call(this, e, t2), this.cacheAttribute(e, t2);
|
|
}
|
|
cacheAttribute(e, t2) {
|
|
var n2, i2;
|
|
i2 = or(e, "__")[0], n2 = Ko[i2], t2 === undefined && (t2 = window.HTMLElement.prototype.getAttribute.call(this, e)), this.rawAttributeCache[e] = t2, n2 && (this.componentCache[e] = this.parseComponentAttrValue(n2, t2));
|
|
}
|
|
parseComponentAttrValue(e, t2) {
|
|
var n2;
|
|
return typeof t2 != "string" ? t2 : (e.isSingleProperty ? typeof (n2 = e.schema.parse(t2)) == "string" && (n2 = t2) : n2 = Lr(t2), n2);
|
|
}
|
|
getAttribute(e) {
|
|
return this.componentCache[e] || window.HTMLElement.prototype.getAttribute.call(this, e);
|
|
}
|
|
cacheAttributes() {
|
|
var e, t2, n2 = this.attributes;
|
|
for (t2 = 0;t2 < n2.length; t2++)
|
|
e = n2[t2].name, this.cacheAttribute(e);
|
|
}
|
|
updateEntities() {
|
|
var e, t2, n2;
|
|
if (this.sceneEl)
|
|
for (t2 = this.sceneEl.querySelectorAll("[mixin~=" + this.id + "]"), n2 = 0;n2 < t2.length; n2++)
|
|
(e = t2[n2]).hasLoaded && !e.isMixin && e.mixinUpdate(this.id);
|
|
}
|
|
});
|
|
ha = new Re.Color;
|
|
da = new Re.Color;
|
|
ua = ar;
|
|
ga = Ar;
|
|
pa = {};
|
|
cs("animation", { schema: { autoplay: { default: true }, delay: { default: 0 }, dir: { default: "" }, dur: { default: 1000 }, easing: { default: "easeInQuad" }, elasticity: { default: 400 }, enabled: { default: true }, from: { default: "" }, loop: { default: 0, parse: function(e) {
|
|
return e === true || e === "true" || e !== false && e !== "false" && parseInt(e, 10);
|
|
} }, property: { default: "" }, startEvents: { type: "array" }, pauseEvents: { type: "array" }, resumeEvents: { type: "array" }, round: { default: false }, to: { default: "" }, type: { default: "" }, isRawProperty: { default: false } }, multiple: true, init: function() {
|
|
var e = this;
|
|
this.eventDetail = { name: this.attrName }, this.time = 0, this.animation = null, this.animationIsPlaying = false, this.onStartEvent = this.onStartEvent.bind(this), this.beginAnimation = this.beginAnimation.bind(this), this.pauseAnimation = this.pauseAnimation.bind(this), this.resumeAnimation = this.resumeAnimation.bind(this), this.fromColor = {}, this.toColor = {}, this.targets = {}, this.targetsArray = [], this.updateConfigForDefault = this.updateConfigForDefault.bind(this), this.updateConfigForRawColor = this.updateConfigForRawColor.bind(this), this.config = { complete: function() {
|
|
e.animationIsPlaying = false, e.el.emit("animationcomplete", e.eventDetail, false), e.id && e.el.emit("animationcomplete__" + e.id, e.eventDetail, false);
|
|
} };
|
|
}, update: function(e) {
|
|
var t2 = this.config, n2 = this.data;
|
|
this.animationIsPlaying = false, this.data.enabled && n2.property && (t2.autoplay = false, t2.direction = n2.dir, t2.duration = n2.dur, t2.easing = n2.easing, t2.elasticity = n2.elasticity, t2.loop = n2.loop, t2.round = n2.round, this.createAndStartAnimation());
|
|
}, tick: function(e, t2) {
|
|
this.animationIsPlaying && (this.time += t2, this.animation.tick(this.time));
|
|
}, remove: function() {
|
|
this.pauseAnimation(), this.removeEventListeners();
|
|
}, pause: function() {
|
|
this.paused = true, this.pausedWasPlaying = this.animationIsPlaying, this.pauseAnimation(), this.removeEventListeners();
|
|
}, play: function() {
|
|
this.paused && (this.paused = false, this.addEventListeners(), this.pausedWasPlaying && (this.resumeAnimation(), this.pausedWasPlaying = false));
|
|
}, createAndStartAnimation: function() {
|
|
var e = this.data;
|
|
this.updateConfig(), this.animationIsPlaying = false, this.animation = Te(this.config), this.animation.began = true, this.removeEventListeners(), this.addEventListeners(), !e.autoplay || e.startEvents && e.startEvents.length || (e.delay ? setTimeout(this.beginAnimation, e.delay) : this.beginAnimation());
|
|
}, beginAnimation: function() {
|
|
this.updateConfig(), this.animation.began = true, this.time = 0, this.animationIsPlaying = true, this.stopRelatedAnimations(), this.el.emit("animationbegin", this.eventDetail, false);
|
|
}, pauseAnimation: function() {
|
|
this.animationIsPlaying = false;
|
|
}, resumeAnimation: function() {
|
|
this.animationIsPlaying = true;
|
|
}, onStartEvent: function() {
|
|
this.data.enabled && (this.updateConfig(), this.animation && this.animation.pause(), this.animation = Te(this.config), this.data.delay ? setTimeout(this.beginAnimation, this.data.delay) : this.beginAnimation());
|
|
}, updateConfigForRawColor: function() {
|
|
var e, t2, n2, i2 = this.config, r2 = this.data, o2 = this.el;
|
|
if (!this.waitComponentInitRawProperty(this.updateConfigForRawColor)) {
|
|
for (t2 in e = r2.from === "" ? ba(o2, r2.property) : r2.from, n2 = r2.to, this.setColorConfig(e, n2), e = this.fromColor, n2 = this.toColor, this.targetsArray.length = 0, this.targetsArray.push(e), i2.targets = this.targetsArray, n2)
|
|
i2[t2] = n2[t2];
|
|
var s2;
|
|
i2.update = (s2 = {}, function(e2) {
|
|
var t3;
|
|
(t3 = e2.animatables[0].target).r === s2.r && t3.g === s2.g && t3.b === s2.b || ya(o2, r2.property, t3, r2.type);
|
|
});
|
|
}
|
|
}, updateConfigForDefault: function() {
|
|
var e, t2, n2, i2, r2 = this.config, o2 = this.data, s2 = this.el;
|
|
this.waitComponentInitRawProperty(this.updateConfigForDefault) || (e = o2.from === "" ? wa(o2) ? ba(s2, o2.property) : ua(s2, o2.property) : o2.from, n2 = o2.to, isNaN(e || n2) ? (e = e ? e.toString() : e, n2 = n2 ? n2.toString() : n2) : (e = parseFloat(e), n2 = parseFloat(n2)), (t2 = o2.to === "true" || o2.to === "false" || o2.to === true || o2.to === false) && (e = o2.from === "true" || o2.from === true ? 1 : 0, n2 = o2.to === "true" || o2.to === true ? 1 : 0), this.targets.aframeProperty = e, r2.targets = this.targets, r2.aframeProperty = n2, r2.update = function(e2) {
|
|
var n3;
|
|
(n3 = e2.animatables[0].target.aframeProperty) !== i2 && (i2 = n3, t2 && (n3 = n3 >= 1), wa(o2) ? ya(s2, o2.property, n3, o2.type) : ga(s2, o2.property, n3));
|
|
});
|
|
}, updateConfigForVector: function() {
|
|
var e, t2, n2, i2, r2 = this.config, o2 = this.data, s2 = this.el, a2 = Ia(o2.property), A2 = a2[0] === "object3D" ? a2[1] : a2[0];
|
|
for (e in t2 = o2.from !== "" ? Zi(o2.from) : ua(s2, A2), n2 = Zi(o2.to), A2 === ma && (Ca(t2), Ca(n2)), this.targetsArray.length = 0, this.targetsArray.push(t2), r2.targets = this.targetsArray, n2)
|
|
r2[e] = n2[e];
|
|
r2.update = A2 !== "position" && A2 !== ma && A2 !== "scale" ? function() {
|
|
var e2 = {};
|
|
return function(t3) {
|
|
var n3 = t3.animatables[0].target;
|
|
n3.x === e2.x && n3.y === e2.y && n3.z === e2.z || (e2.x = n3.x, e2.y = n3.y, e2.z = n3.z, ga(s2, o2.property, n3));
|
|
};
|
|
}() : (i2 = {}, function(e2) {
|
|
var t3 = e2.animatables[0].target;
|
|
t3.x === i2.x && t3.y === i2.y && t3.z === i2.z || (i2.x = t3.x, i2.y = t3.y, i2.z = t3.z, s2.object3D[A2].set(t3.x, t3.y, t3.z));
|
|
});
|
|
}, updateConfig: function() {
|
|
var e;
|
|
e = function(e2, t2) {
|
|
var n2, i2, r2, o2;
|
|
return (r2 = t2.split("."))[0] !== "object3D" || r2[2] || r2[1] !== "position" && r2[1] !== "rotation" && r2[1] !== "scale" ? (i2 = r2[0], o2 = r2[1], (n2 = e2.components[i2] || Ko[i2]) ? o2 && !n2.schema[o2] ? null : o2 ? n2.schema[o2].type : n2.schema.type : null) : "vec3";
|
|
}(this.el, this.data.property), wa(this.data) && this.data.type === fa ? this.updateConfigForRawColor() : e === "vec2" || e === "vec3" || e === "vec4" ? this.updateConfigForVector() : this.updateConfigForDefault();
|
|
}, waitComponentInitRawProperty: function(e) {
|
|
var t2, n2 = this.data, i2 = this.el, r2 = this;
|
|
return n2.from === "" && !!n2.property.startsWith(Ea) && (t2 = Ia(n2.property)[1], !i2.components[t2] && (i2.addEventListener("componentinitialized", function n(o2) {
|
|
o2.detail.name === t2 && (e(), r2.animation = Te(r2.config), i2.removeEventListener("componentinitialized", n));
|
|
}), true));
|
|
}, stopRelatedAnimations: function() {
|
|
var e, t2;
|
|
for (t2 in this.el.components)
|
|
e = this.el.components[t2], t2 !== this.attrName && e.name === "animation" && e.animationIsPlaying && e.data.property === this.data.property && (e.animationIsPlaying = false);
|
|
}, addEventListeners: function() {
|
|
var e = this.data, t2 = this.el;
|
|
va(t2, e.startEvents, this.onStartEvent), va(t2, e.pauseEvents, this.pauseAnimation), va(t2, e.resumeEvents, this.resumeAnimation);
|
|
}, removeEventListeners: function() {
|
|
var e = this.data, t2 = this.el;
|
|
Ba(t2, e.startEvents, this.onStartEvent), Ba(t2, e.pauseEvents, this.pauseAnimation), Ba(t2, e.resumeEvents, this.resumeAnimation);
|
|
}, setColorConfig: function(e, t2) {
|
|
ha.set(e), da.set(t2), e = this.fromColor, t2 = this.toColor, e.r = ha.r, e.g = ha.g, e.b = ha.b, t2.r = da.r, t2.g = da.g, t2.b = da.b;
|
|
} });
|
|
xa = fi("components:anchored:warn");
|
|
cs("anchored", { schema: { persistent: { default: false } }, init: function() {
|
|
var e = this.el.sceneEl.getAttribute("webxr"), t2 = e.optionalFeatures;
|
|
t2.indexOf("anchors") === -1 && (t2.push("anchors"), this.el.sceneEl.setAttribute("webxr", e)), this.auxQuaternion = new Re.Quaternion, this.onEnterVR = this.onEnterVR.bind(this), this.el.sceneEl.addEventListener("enter-vr", this.onEnterVR);
|
|
}, onEnterVR: function() {
|
|
this.anchor = undefined, this.requestPersistentAnchorPending = this.data.persistent, this.requestAnchorPending = !this.data.persistent;
|
|
}, tick: function() {
|
|
var e, t2, n2, i2 = this.el.sceneEl, r2 = i2.renderer.xr, o2 = this.el.object3D;
|
|
(i2.is("ar-mode") || i2.is("vr-mode")) && (!this.anchor && this.requestPersistentAnchorPending && this.restorePersistentAnchor(), !this.anchor && this.requestAnchorPending && this.createAnchor(), this.anchor && (e = i2.frame, t2 = r2.getReferenceSpace(), n2 = e.getPose(this.anchor.anchorSpace, t2), o2.position.copy(n2.transform.position), o2.quaternion.copy(n2.transform.orientation)));
|
|
}, createAnchor: async function(e, t2) {
|
|
var n2, i2, r2, o2, s2 = this.el.sceneEl, a2 = s2.renderer.xr, A2 = this.el.object3D;
|
|
e = e || A2.position, t2 = t2 || this.auxQuaternion.setFromEuler(A2.rotation), function(e2) {
|
|
var t3 = e2.renderer.xr.getSession();
|
|
return t3 && t3.restorePersistentAnchor;
|
|
}(s2) ? (this.anchor && this.deleteAnchor(), n2 = s2.frame, i2 = a2.getReferenceSpace(), r2 = new XRRigidTransform({ x: e.x, y: e.y, z: e.z }, { x: t2.x, y: t2.y, z: t2.z, w: t2.w }), this.requestAnchorPending = false, o2 = await n2.createAnchor(r2, i2), this.data.persistent && (this.el.id ? (this.persistentHandle = await o2.requestPersistentHandle(), localStorage.setItem(this.el.id, this.persistentHandle)) : xa("The anchor won't be persisted because the entity has no assigned id.")), s2.object3D.attach(this.el.object3D), this.anchor = o2) : xa("This browser doesn't support the WebXR anchors module");
|
|
}, restorePersistentAnchor: async function() {
|
|
var e, t2 = this.el.sceneEl.renderer.xr.getSession(), n2 = t2.persistentAnchors;
|
|
if (this.requestPersistentAnchorPending = false, !this.el.id)
|
|
return xa("The entity associated to the persistent anchor cannot be retrieved because it doesn't have an assigned id."), void (this.requestAnchorPending = true);
|
|
if (n2) {
|
|
e = localStorage.getItem(this.el.id);
|
|
for (var i2 = 0;i2 < n2.length; ++i2)
|
|
if (e === n2[i2]) {
|
|
this.anchor = await t2.restorePersistentAnchor(n2[i2]), this.anchor && (this.persistentHandle = n2[i2]);
|
|
break;
|
|
}
|
|
this.anchor || (this.requestAnchorPending = true);
|
|
} else
|
|
this.requestPersistentAnchorPending = true;
|
|
}, deleteAnchor: function() {
|
|
var e, t2 = this.anchor;
|
|
t2 && (e = this.el.sceneEl.renderer.xr.getSession(), t2.delete(), this.el.sceneEl.object3D.add(this.el.object3D), this.persistentHandle && e.deletePersistentAnchor(this.persistentHandle), this.anchor = undefined);
|
|
} }), cs("camera", { schema: { active: { default: true }, far: { default: 1e4 }, fov: { default: 80, min: 0 }, near: { default: 0.005, min: 0 }, spectator: { default: false }, zoom: { default: 1, min: 0 } }, init: function() {
|
|
var e, t2 = this.el;
|
|
e = this.camera = new Re.PerspectiveCamera, t2.setObject3D("camera", e);
|
|
}, update: function(e) {
|
|
var t2 = this.data, n2 = this.camera;
|
|
n2.aspect = t2.aspect || window.innerWidth / window.innerHeight, n2.far = t2.far, n2.fov = t2.fov, n2.near = t2.near, n2.zoom = t2.zoom, n2.updateProjectionMatrix(), this.updateActiveCamera(e), this.updateSpectatorCamera(e);
|
|
}, updateActiveCamera: function(e) {
|
|
var t2 = this.data, n2 = this.el, i2 = this.system;
|
|
e && e.active === t2.active || t2.spectator || (t2.active && i2.activeCameraEl !== n2 ? i2.setActiveCamera(n2) : t2.active || i2.activeCameraEl !== n2 || i2.disableActiveCamera());
|
|
}, updateSpectatorCamera: function(e) {
|
|
var t2 = this.data, n2 = this.el, i2 = this.system;
|
|
e && e.spectator === t2.spectator || (t2.spectator && i2.spectatorCameraEl !== n2 ? i2.setSpectatorCamera(n2) : t2.spectator || i2.spectatorCameraEl !== n2 || i2.disableSpectatorCamera());
|
|
}, remove: function() {
|
|
this.el.removeObject3D("camera");
|
|
} });
|
|
Ua = { DOWN: ["mousedown", "touchstart"], UP: ["mouseup", "touchend"] };
|
|
Oa = { DOWN: ["selectstart"], UP: ["selectend"] };
|
|
Ga = (cs("cursor", { dependencies: ["raycaster"], schema: { downEvents: { default: [] }, fuse: { default: Si() }, fuseTimeout: { default: 1500, min: 0 }, mouseCursorStylesEnabled: { default: true }, upEvents: { default: [] }, rayOrigin: { default: "entity", oneOf: ["mouse", "entity", "xrselect"] } }, after: ["tracked-controls"], multiple: true, init: function() {
|
|
var e = this;
|
|
this.fuseTimeout = undefined, this.cursorDownEl = null, this.intersectedEl = null, this.canvasBounds = document.body.getBoundingClientRect(), this.isCursorDown = false, this.activeXRInput = null, this.updateCanvasBounds = Wr(function() {
|
|
e.canvasBounds = e.el.sceneEl.canvas.getBoundingClientRect();
|
|
}, 500), this.eventDetail = {}, this.intersectedEventDetail = { cursorEl: this.el }, this.onCursorDown = this.onCursorDown.bind(this), this.onCursorUp = this.onCursorUp.bind(this), this.onIntersection = this.onIntersection.bind(this), this.onIntersectionCleared = this.onIntersectionCleared.bind(this), this.onMouseMove = this.onMouseMove.bind(this), this.onEnterVR = this.onEnterVR.bind(this);
|
|
}, update: function(e) {
|
|
var t2 = this.data.rayOrigin;
|
|
t2 !== e.rayOrigin && (t2 === "entity" && this.resetRaycaster(), this.updateMouseEventListeners(), t2 !== "xrselect" && t2 !== "entity" || this.addWebXREventListeners(), e.rayOrigin !== "xrselect" && e.rayOrigin !== "entity" || this.removeWebXREventListeners());
|
|
}, tick: function() {
|
|
var e = this.el.sceneEl.frame, t2 = this.activeXRInput;
|
|
this.data.rayOrigin === "xrselect" && e && t2 && this.onMouseMove({ frame: e, inputSource: t2, type: "fakeselectevent" });
|
|
}, play: function() {
|
|
this.addEventListeners();
|
|
}, pause: function() {
|
|
this.removeEventListeners();
|
|
}, remove: function() {
|
|
var e = this.el;
|
|
e.removeState(Ra), e.removeState(Ta), clearTimeout(this.fuseTimeout), this.intersectedEl && this.intersectedEl.removeState(Fa), this.removeEventListeners();
|
|
}, addEventListeners: function() {
|
|
var e, t2 = this.data, n2 = this.el, i2 = this;
|
|
function r2() {
|
|
e = n2.sceneEl.canvas, t2.downEvents.length || t2.upEvents.length || (Ua.DOWN.forEach(function(t3) {
|
|
e.addEventListener(t3, i2.onCursorDown, { passive: false });
|
|
}), Ua.UP.forEach(function(t3) {
|
|
e.addEventListener(t3, i2.onCursorUp, { passive: false });
|
|
}));
|
|
}
|
|
(e = n2.sceneEl.canvas) ? r2() : n2.sceneEl.addEventListener("render-target-loaded", r2), t2.downEvents.forEach(function(e2) {
|
|
n2.addEventListener(e2, i2.onCursorDown);
|
|
}), t2.upEvents.forEach(function(e2) {
|
|
n2.addEventListener(e2, i2.onCursorUp);
|
|
}), n2.addEventListener("raycaster-intersection", this.onIntersection), n2.addEventListener("raycaster-closest-entity-changed", this.onIntersection), n2.addEventListener("raycaster-intersection-cleared", this.onIntersectionCleared), n2.sceneEl.addEventListener("rendererresize", this.updateCanvasBounds), n2.sceneEl.addEventListener("enter-vr", this.onEnterVR), window.addEventListener("resize", this.updateCanvasBounds), window.addEventListener("scroll", this.updateCanvasBounds), this.updateMouseEventListeners();
|
|
}, removeEventListeners: function() {
|
|
var e, t2 = this.data, n2 = this.el, i2 = this;
|
|
!(e = n2.sceneEl.canvas) || t2.downEvents.length || t2.upEvents.length || (Ua.DOWN.forEach(function(t3) {
|
|
e.removeEventListener(t3, i2.onCursorDown);
|
|
}), Ua.UP.forEach(function(t3) {
|
|
e.removeEventListener(t3, i2.onCursorUp);
|
|
})), t2.downEvents.forEach(function(e2) {
|
|
n2.removeEventListener(e2, i2.onCursorDown);
|
|
}), t2.upEvents.forEach(function(e2) {
|
|
n2.removeEventListener(e2, i2.onCursorUp);
|
|
}), n2.removeEventListener("raycaster-intersection", this.onIntersection), n2.removeEventListener("raycaster-closest-entity-changed", this.onIntersection), n2.removeEventListener("raycaster-intersection-cleared", this.onIntersectionCleared), e.removeEventListener("mousemove", this.onMouseMove), e.removeEventListener("touchstart", this.onMouseMove), e.removeEventListener("touchmove", this.onMouseMove), n2.sceneEl.removeEventListener("rendererresize", this.updateCanvasBounds), n2.sceneEl.removeEventListener("enter-vr", this.onEnterVR), window.removeEventListener("resize", this.updateCanvasBounds), window.removeEventListener("scroll", this.updateCanvasBounds), this.removeWebXREventListeners();
|
|
}, updateMouseEventListeners: function() {
|
|
var e, t2 = this.el;
|
|
(e = t2.sceneEl.canvas).removeEventListener("mousemove", this.onMouseMove), e.removeEventListener("touchmove", this.onMouseMove), t2.setAttribute("raycaster", "useWorldCoordinates", false), this.data.rayOrigin === "mouse" && (e.addEventListener("mousemove", this.onMouseMove), e.addEventListener("touchmove", this.onMouseMove, { passive: false }), t2.setAttribute("raycaster", "useWorldCoordinates", true), this.updateCanvasBounds());
|
|
}, resetRaycaster: function() {
|
|
this.el.setAttribute("raycaster", { direction: new Re.Vector3().set(0, 0, -1), origin: new Re.Vector3 });
|
|
}, addWebXREventListeners: function() {
|
|
var e = this, t2 = this.el.sceneEl.xrSession;
|
|
t2 && (Oa.DOWN.forEach(function(n2) {
|
|
t2.addEventListener(n2, e.onCursorDown);
|
|
}), Oa.UP.forEach(function(n2) {
|
|
t2.addEventListener(n2, e.onCursorUp);
|
|
}));
|
|
}, removeWebXREventListeners: function() {
|
|
var e = this, t2 = this.el.sceneEl.xrSession;
|
|
t2 && (Oa.DOWN.forEach(function(n2) {
|
|
t2.removeEventListener(n2, e.onCursorDown);
|
|
}), Oa.UP.forEach(function(n2) {
|
|
t2.removeEventListener(n2, e.onCursorUp);
|
|
}));
|
|
}, onMouseMove: (Qa = new Re.Vector3, La = new Re.Vector2, Ma = new Re.Vector3, Sa = { origin: Ma, direction: Qa }, function(e) {
|
|
var t2, n2, i2, r2, o2, s2, a2, A2, l2, c2 = this.canvasBounds, h2 = this.el.sceneEl.camera;
|
|
h2.parent.updateMatrixWorld(), n2 = (i2 = e.type === "touchmove" || e.type === "touchstart" ? e.touches.item(0) : e).clientX - c2.left, r2 = i2.clientY - c2.top, La.x = n2 / c2.width * 2 - 1, La.y = -r2 / c2.height * 2 + 1, this.data.rayOrigin !== "xrselect" || e.type !== "selectstart" && e.type !== "fakeselectevent" ? e.type === "fakeselectout" ? (Qa.set(0, 1, 0), Ma.set(0, 9999, 0)) : h2 && h2.isPerspectiveCamera ? (Ma.setFromMatrixPosition(h2.matrixWorld), Qa.set(La.x, La.y, 0.5).unproject(h2).sub(Ma).normalize()) : h2 && h2.isOrthographicCamera ? (Ma.set(La.x, La.y, (h2.near + h2.far) / (h2.near - h2.far)).unproject(h2), Qa.set(0, 0, -1).transformDirection(h2.matrixWorld)) : console.error("AFRAME.Raycaster: Unsupported camera type: " + h2.type) : (o2 = e.frame, s2 = e.inputSource, a2 = this.el.sceneEl.renderer.xr.getReferenceSpace(), (A2 = o2.getPose(s2.targetRaySpace, a2)) && (l2 = A2.transform, Qa.set(0, 0, -1), Qa.applyQuaternion(l2.orientation), Ma.copy(l2.position), (t2 = h2.el.object3D.parent).localToWorld(Ma), Qa.transformDirection(t2.matrixWorld))), this.el.setAttribute("raycaster", Sa), e.type === "touchmove" && e.preventDefault();
|
|
}), onCursorDown: function(e) {
|
|
this.isCursorDown = true, this.data.rayOrigin === "mouse" && e.type === "touchstart" && (this.onMouseMove(e), this.el.components.raycaster.checkIntersections(), e.preventDefault()), this.data.rayOrigin === "xrselect" && e.type === "selectstart" && (this.activeXRInput = e.inputSource, this.onMouseMove(e), this.el.components.raycaster.checkIntersections(), this.el.components.raycaster.intersectedEls.length && this.el.sceneEl.components["ar-hit-test"] !== undefined && this.el.sceneEl.getAttribute("ar-hit-test").enabled && (this.el.sceneEl.setAttribute("ar-hit-test", "enabled", false), this.reenableARHitTest = true)), this.twoWayEmit("mousedown", e), this.cursorDownEl = this.intersectedEl;
|
|
}, onCursorUp: function(e) {
|
|
if (this.isCursorDown && (this.data.rayOrigin !== "xrselect" || this.activeXRInput === e.inputSource)) {
|
|
this.isCursorDown = false;
|
|
var t2 = this.data;
|
|
this.twoWayEmit(ka, e), this.reenableARHitTest === true && (this.el.sceneEl.setAttribute("ar-hit-test", "enabled", true), this.reenableARHitTest = undefined), this.cursorDownEl && this.cursorDownEl !== this.intersectedEl && (this.intersectedEventDetail.intersection = null, this.cursorDownEl.emit(ka, this.intersectedEventDetail)), t2.fuse && t2.rayOrigin !== "mouse" && t2.rayOrigin !== "xrselect" || !this.intersectedEl || this.cursorDownEl !== this.intersectedEl || this.twoWayEmit(Da, e), t2.rayOrigin === "xrselect" && this.onMouseMove({ type: "fakeselectout" }), this.activeXRInput = null, this.cursorDownEl = null, e.type === "touchend" && e.preventDefault();
|
|
}
|
|
}, onIntersection: function(e) {
|
|
var t2, n2, i2, r2, o2 = this.el;
|
|
n2 = e.detail.els[0] === o2 ? 1 : 0, r2 = e.detail.intersections[n2], (i2 = e.detail.els[n2]) && this.intersectedEl !== i2 && (this.intersectedEl && (t2 = this.el.components.raycaster.getIntersection(this.intersectedEl)) && t2.distance <= r2.distance || (this.clearCurrentIntersection(true), this.setIntersection(i2, r2)));
|
|
}, onIntersectionCleared: function(e) {
|
|
e.detail.clearedEls.indexOf(this.intersectedEl) !== -1 && this.clearCurrentIntersection();
|
|
}, onEnterVR: function() {
|
|
var e = this.data.rayOrigin;
|
|
this.clearCurrentIntersection(true), e !== "xrselect" && e !== "entity" || this.addWebXREventListeners();
|
|
}, setIntersection: function(e, t2) {
|
|
var n2 = this.el, i2 = this.data, r2 = this;
|
|
this.intersectedEl !== e && (this.intersectedEl = e, n2.addState(Ra), e.addState(Fa), this.twoWayEmit("mouseenter"), this.data.mouseCursorStylesEnabled && this.data.rayOrigin === "mouse" && this.el.sceneEl.canvas.classList.add(Pa), i2.fuseTimeout !== 0 && i2.fuse && i2.rayOrigin !== "xrselect" && i2.rayOrigin !== "mouse" && (n2.addState(Ta), this.twoWayEmit("fusing"), this.fuseTimeout = setTimeout(function() {
|
|
n2.removeState(Ta), r2.twoWayEmit(Da);
|
|
}, i2.fuseTimeout)));
|
|
}, clearCurrentIntersection: function(e) {
|
|
var t2, n2, i2 = this.el;
|
|
this.intersectedEl && (this.intersectedEl.removeState(Fa), i2.removeState(Ra), i2.removeState(Ta), this.twoWayEmit("mouseleave"), this.data.mouseCursorStylesEnabled && this.data.rayOrigin === "mouse" && this.el.sceneEl.canvas.classList.remove(Pa), this.intersectedEl = null, clearTimeout(this.fuseTimeout), e !== true && (n2 = this.el.components.raycaster.intersections).length !== 0 && (t2 = n2[n2[0].object.el === i2 ? 1 : 0]) && this.setIntersection(t2.object.el, t2));
|
|
}, twoWayEmit: function(e, t2) {
|
|
var n2, i2 = this.el, r2 = this.intersectedEl;
|
|
function o2(e2, n3) {
|
|
t2 instanceof MouseEvent ? e2.mouseEvent = t2 : typeof TouchEvent != "undefined" && t2 instanceof TouchEvent && (e2.touchEvent = t2);
|
|
}
|
|
n2 = this.el.components.raycaster.getIntersection(r2), this.eventDetail.intersectedEl = r2, this.eventDetail.intersection = n2, o2(this.eventDetail), i2.emit(e, this.eventDetail), r2 && (this.intersectedEventDetail.intersection = n2, o2(this.intersectedEventDetail), r2.emit(e, this.intersectedEventDetail));
|
|
} }), new Re.BufferGeometry);
|
|
Na = (cs("geometry", { schema: { buffer: { default: true }, primitive: { default: "box", oneOf: _s, schemaChange: true }, skipCache: { default: false } }, init: function() {
|
|
this.geometry = null;
|
|
}, update: function(e) {
|
|
var t2, n2 = this.data, i2 = this.el, r2 = this.system;
|
|
this.geometry && (r2.unuseGeometry(e), this.geometry = null), this.geometry = r2.getOrCreateGeometry(n2), (t2 = i2.getObject3D("mesh")) ? t2.geometry = this.geometry : ((t2 = new Re.Mesh).geometry = this.geometry, this.el.getAttribute("material") || (t2.material = new Re.MeshStandardMaterial({ color: 16777215 * Math.random(), metalness: 0, roughness: 0.5 })), i2.setObject3D("mesh", t2));
|
|
}, remove: function() {
|
|
this.system.unuseGeometry(this.data), this.el.getObject3D("mesh").geometry = Ga, this.geometry = null;
|
|
}, updateSchema: function(e) {
|
|
var t2 = this.oldData && this.oldData.primitive, n2 = e.primitive, i2 = js[n2] && js[n2].schema;
|
|
if (!i2)
|
|
throw new Error("Unknown geometry schema `" + n2 + "`");
|
|
t2 && t2 === n2 || this.extendSchema(i2);
|
|
} }), "generic");
|
|
ja = (cs("generic-tracked-controller-controls", { schema: { hand: { default: "" }, defaultModel: { default: true }, defaultModelColor: { default: "gray" }, disabled: { default: false } }, after: ["tracked-controls"], mapping: { axes: { touchpad: [0, 1], thumbstick: [2, 3] }, buttons: ["trigger", "squeeze", "touchpad", "thumbstick"] }, bindMethods: function() {
|
|
this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, init: function() {
|
|
var e = this;
|
|
this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e);
|
|
}, this.controllerPresent = false, this.wasControllerConnected = false, this.bindMethods(), this.el.addEventListener("controllerconnected", function(t2) {
|
|
t2.detail.name !== e.name && (e.wasControllerConnected = true, e.removeEventListeners(), e.removeControllersUpdateListener());
|
|
});
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.data, t2 = e.hand ? e.hand : undefined;
|
|
Ur(this, Na, { hand: t2, iterateControllerProfiles: true });
|
|
}, play: function() {
|
|
this.wasControllerConnected || (this.checkIfControllerPresent(), this.addControllersUpdateListener());
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data;
|
|
this.el.components["tracked-controls"] ? this.removeEventListeners() : (e.setAttribute("tracked-controls", { hand: t2.hand, idPrefix: Na, iterateControllerProfiles: true }), this.data.defaultModel && this.initDefaultModel());
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.wasControllerConnected && this.checkIfControllerPresent();
|
|
}, onButtonChanged: function(e) {
|
|
var t2 = this.mapping.buttons[e.detail.id];
|
|
t2 && this.el.emit(t2 + "changed", e.detail.state);
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping.axes, e);
|
|
}, initDefaultModel: function() {
|
|
var e = this.modelEl = document.createElement("a-entity");
|
|
e.setAttribute("geometry", { primitive: "sphere", radius: 0.03 }), e.setAttribute("material", { color: this.data.color }), this.el.appendChild(e), this.el.emit("controllermodelready", { name: "generic-tracked-controller-controls", model: this.modelEl, rayOrigin: { origin: { x: 0, y: 0, z: -0.01 }, direction: { x: 0, y: 0, z: -1 } } });
|
|
} }), fi("components:gltf-model:warn"));
|
|
cs("gltf-model", { schema: { type: "model" }, init: function() {
|
|
var e = this, t2 = this.system.getDRACOLoader(), n2 = this.system.getMeshoptDecoder(), i2 = this.system.getKTX2Loader();
|
|
this.model = null, this.loader = new Xe, t2 && this.loader.setDRACOLoader(t2), this.ready = n2 ? n2.then(function(t3) {
|
|
e.loader.setMeshoptDecoder(t3);
|
|
}) : Promise.resolve(), i2 && this.loader.setKTX2Loader(i2);
|
|
}, update: function() {
|
|
var e = this, t2 = this.el, n2 = this.data;
|
|
n2 && (this.remove(), this.ready.then(function() {
|
|
e.loader.load(n2, function(n3) {
|
|
e.model = n3.scene || n3.scenes[0], e.model.animations = n3.animations, t2.setObject3D("mesh", e.model), t2.emit("model-loaded", { format: "gltf", model: e.model });
|
|
}, undefined, function(e2) {
|
|
var i2 = e2 && e2.message ? e2.message : "Failed to load glTF model";
|
|
ja(i2), t2.emit("model-error", { format: "gltf", src: n2 });
|
|
});
|
|
}));
|
|
}, remove: function() {
|
|
this.model && this.el.removeObject3D("mesh");
|
|
} }), cs("grabbable", { init: function() {
|
|
this.el.setAttribute("obb-collider", "centerModel: true");
|
|
} });
|
|
Ha = ci + "controllers/oculus-hands/v4/left.glb";
|
|
qa = ci + "controllers/oculus-hands/v4/right.glb";
|
|
Va = ["wrist", "thumb-metacarpal", "thumb-phalanx-proximal", "thumb-phalanx-distal", "thumb-tip", "index-finger-metacarpal", "index-finger-phalanx-proximal", "index-finger-phalanx-intermediate", "index-finger-phalanx-distal", "index-finger-tip", "middle-finger-metacarpal", "middle-finger-phalanx-proximal", "middle-finger-phalanx-intermediate", "middle-finger-phalanx-distal", "middle-finger-tip", "ring-finger-metacarpal", "ring-finger-phalanx-proximal", "ring-finger-phalanx-intermediate", "ring-finger-phalanx-distal", "ring-finger-tip", "pinky-finger-metacarpal", "pinky-finger-phalanx-proximal", "pinky-finger-phalanx-intermediate", "pinky-finger-phalanx-distal", "pinky-finger-tip"];
|
|
cs("hand-tracking-controls", { schema: { hand: { default: "right", oneOf: ["left", "right"] }, modelStyle: { default: "mesh", oneOf: ["dots", "mesh"] }, modelColor: { default: "white" }, modelOpacity: { default: 1 } }, after: ["tracked-controls"], bindMethods: function() {
|
|
this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this);
|
|
}, addEventListeners: function() {
|
|
this.el.addEventListener("model-loaded", this.onModelLoaded);
|
|
for (var e = 0;e < this.jointEls.length; ++e)
|
|
this.jointEls[e].object3D.visible = true;
|
|
}, removeEventListeners: function() {
|
|
this.el.removeEventListener("model-loaded", this.onModelLoaded);
|
|
for (var e = 0;e < this.jointEls.length; ++e)
|
|
this.jointEls[e].object3D.visible = false;
|
|
}, init: function() {
|
|
var e = this.el.sceneEl, t2 = e.getAttribute("webxr"), n2 = t2.optionalFeatures;
|
|
n2.indexOf("hand-tracking") === -1 && (n2.push("hand-tracking"), e.setAttribute("webxr", t2)), this.wristObject3D = new Re.Object3D, this.el.sceneEl.object3D.add(this.wristObject3D), this.onModelLoaded = this.onModelLoaded.bind(this), this.onChildAttached = this.onChildAttached.bind(this), this.jointEls = [], this.controllerPresent = false, this.isPinched = false, this.pinchEventDetail = { position: new Re.Vector3, wristRotation: new Re.Quaternion }, this.indexTipPosition = new Re.Vector3, this.hasPoses = false, this.jointPoses = new Float32Array(16 * Va.length), this.jointRadii = new Float32Array(Va.length), this.bindMethods(), this.updateReferenceSpace = this.updateReferenceSpace.bind(this), this.el.sceneEl.addEventListener("enter-vr", this.updateReferenceSpace), this.el.sceneEl.addEventListener("exit-vr", this.updateReferenceSpace), this.el.addEventListener("child-attached", this.onChildAttached), this.wristObject3D.visible = false;
|
|
}, onChildAttached: function(e) {
|
|
this.addChildEntity(e.detail.el);
|
|
}, update: function() {
|
|
this.updateModelMaterial();
|
|
}, updateModelMaterial: function() {
|
|
var e = this.jointEls, t2 = this.skinnedMesh, n2 = !(this.data.modelOpacity === 1);
|
|
t2 && (this.skinnedMesh.material.color.set(this.data.modelColor), this.skinnedMesh.material.transparent = n2, this.skinnedMesh.material.opacity = this.data.modelOpacity);
|
|
for (var i2 = 0;i2 < e.length; i2++)
|
|
e[i2].setAttribute("material", { color: this.data.modelColor, transparent: n2, opacity: this.data.modelOpacity });
|
|
}, updateReferenceSpace: function() {
|
|
var e = this, t2 = this.el.sceneEl.xrSession;
|
|
if (this.referenceSpace = undefined, t2) {
|
|
var n2 = e.el.sceneEl.systems.webxr.sessionReferenceSpaceType;
|
|
t2.requestReferenceSpace(n2).then(function(t3) {
|
|
e.referenceSpace = t3;
|
|
}).catch(function(t3) {
|
|
throw e.el.sceneEl.systems.webxr.warnIfFeatureNotRequested(n2, "tracked-controls-webxr uses reference space " + n2), t3;
|
|
});
|
|
}
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.data;
|
|
Ur(this, "", { hand: e.hand ? e.hand : undefined, iterateControllerProfiles: true, handTracking: true });
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, tick: function() {
|
|
var e = this.el.sceneEl, t2 = this.el.components["tracked-controls"] && this.el.components["tracked-controls"].controller, n2 = e.frame, i2 = this.el.components["tracked-controls"], r2 = this.referenceSpace;
|
|
t2 && n2 && r2 && i2 && (this.hasPoses = false, t2.hand && (this.el.object3D.position.set(0, 0, 0), this.el.object3D.rotation.set(0, 0, 0), this.hasPoses = n2.fillPoses(t2.hand.values(), r2, this.jointPoses) && n2.fillJointRadii(t2.hand.values(), this.jointRadii), this.updateHandModel(), this.detectGesture(), this.updateWristObject()));
|
|
}, updateWristObject: (_a = new Re.Matrix4, function() {
|
|
var e = this.wristObject3D;
|
|
e && this.hasPoses && (_a.fromArray(this.jointPoses, 0), e.position.setFromMatrixPosition(_a), e.quaternion.setFromRotationMatrix(_a));
|
|
}), updateHandModel: function() {
|
|
this.wristObject3D.visible = true, this.el.object3D.visible = true, this.data.modelStyle === "dots" && this.updateHandDotsModel(), this.data.modelStyle === "mesh" && this.updateHandMeshModel();
|
|
}, getBone: function(e) {
|
|
for (var t2 = this.bones, n2 = 0;n2 < t2.length; n2++)
|
|
if (t2[n2].name === e)
|
|
return t2[n2];
|
|
return null;
|
|
}, updateHandMeshModel: function() {
|
|
var e = new Re.Matrix4;
|
|
return function() {
|
|
var t2 = 0, n2 = this.jointPoses, i2 = this.el.components["tracked-controls"] && this.el.components["tracked-controls"].controller;
|
|
if (i2 && this.mesh && (this.mesh.visible = false, this.hasPoses))
|
|
for (var r2 of i2.hand.values()) {
|
|
var o2 = this.getBone(r2.jointName);
|
|
o2 != null && (this.mesh.visible = true, e.fromArray(n2, 16 * t2), o2.position.setFromMatrixPosition(e), o2.quaternion.setFromRotationMatrix(e)), t2++;
|
|
}
|
|
};
|
|
}(), updateHandDotsModel: function() {
|
|
for (var e, t2, n2 = this.jointPoses, i2 = this.jointRadii, r2 = this.el.components["tracked-controls"] && this.el.components["tracked-controls"].controller, o2 = 0;o2 < r2.hand.size; o2++)
|
|
t2 = (e = this.jointEls[o2]).object3D, e.object3D.visible = this.hasPoses, this.hasPoses && (t2.matrix.fromArray(n2, 16 * o2), t2.matrix.decompose(t2.position, t2.rotation, t2.scale), e.setAttribute("scale", { x: i2[o2], y: i2[o2], z: i2[o2] }));
|
|
}, detectGesture: function() {
|
|
this.detectPinch();
|
|
}, detectPinch: function() {
|
|
var e = new Re.Vector3, t2 = new Re.Matrix4;
|
|
return function() {
|
|
var n2 = this.indexTipPosition, i2 = this.pinchEventDetail;
|
|
if (this.hasPoses) {
|
|
e.setFromMatrixPosition(t2.fromArray(this.jointPoses, 64)), n2.setFromMatrixPosition(t2.fromArray(this.jointPoses, 144)), i2.wristRotation.setFromRotationMatrix(t2.fromArray(this.jointPoses, 0));
|
|
var r2 = n2.distanceTo(e);
|
|
r2 < 0.015 && this.isPinched === false && (this.isPinched = true, i2.position.copy(n2).add(e).multiplyScalar(0.5), this.el.emit("pinchstarted", i2)), r2 > 0.02 && this.isPinched === true && (this.isPinched = false, i2.position.copy(n2).add(e).multiplyScalar(0.5), this.el.emit("pinchended", i2)), this.isPinched && (i2.position.copy(n2).add(e).multiplyScalar(0.5), this.el.emit("pinchmoved", i2));
|
|
}
|
|
};
|
|
}(), pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data;
|
|
e.setAttribute("tracked-controls", { id: "", hand: t2.hand, iterateControllerProfiles: true, handTrackingEnabled: true }), this.mesh ? this.mesh !== e.getObject3D("mesh") && e.setObject3D("mesh", this.mesh) : this.initDefaultModel();
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
var e, t2 = this.el;
|
|
this.checkIfControllerPresent(), e = t2.components["tracked-controls"] && t2.components["tracked-controls"].controller, this.mesh && e && e.hand && e.hand instanceof XRHand && t2.setObject3D("mesh", this.mesh);
|
|
}, initDefaultModel: function() {
|
|
var e = this.data;
|
|
e.modelStyle === "dots" && this.initDotsModel(), e.modelStyle === "mesh" && this.initMeshHandModel(), this.el.object3D.visible = true, this.wristObject3D.visible = true;
|
|
}, initDotsModel: function() {
|
|
if (this.jointEls.length === 0) {
|
|
for (var e = 0;e < Va.length; ++e) {
|
|
var t2 = this.jointEl = document.createElement("a-entity");
|
|
t2.setAttribute("geometry", { primitive: "sphere", radius: 1 }), t2.object3D.visible = false, this.el.appendChild(t2), this.jointEls.push(t2);
|
|
}
|
|
this.updateModelMaterial();
|
|
}
|
|
}, initMeshHandModel: function() {
|
|
var e = this.data.hand === "left" ? Ha : qa;
|
|
this.el.setAttribute("gltf-model", e);
|
|
}, onModelLoaded: function() {
|
|
var e = this.mesh = this.el.getObject3D("mesh").children[0], t2 = this.skinnedMesh = e.getObjectByProperty("type", "SkinnedMesh");
|
|
this.skinnedMesh && (this.bones = t2.skeleton.bones, this.el.removeObject3D("mesh"), e.position.set(0, 0, 0), e.rotation.set(0, 0, 0), t2.frustumCulled = false, t2.material = new Re.MeshStandardMaterial, this.updateModelMaterial(), this.setupChildrenEntities(), this.el.setObject3D("mesh", e), this.el.emit("controllermodelready", { name: "hand-tracking-controls", model: this.data.model, rayOrigin: new Re.Vector3(0, 0, 0) }));
|
|
}, setupChildrenEntities: function() {
|
|
for (var e = this.el.children, t2 = 0;t2 < e.length; ++t2)
|
|
e[t2] instanceof Ls && this.addChildEntity(e[t2]);
|
|
}, addChildEntity: function(e) {
|
|
e instanceof Ls && this.wristObject3D.add(e.object3D);
|
|
} }), cs("hand-tracking-grab-controls", { schema: { hand: { default: "right", oneOf: ["left", "right"] }, color: { type: "color", default: "white" }, hoverColor: { type: "color", default: "#538df1" }, hoverEnabled: { default: false } }, init: function() {
|
|
var e, t2 = this.el, n2 = this.data;
|
|
e = n2.hand === "right" ? "components.hand-tracking-controls.bones.3" : "components.hand-tracking-controls.bones.21", t2.setAttribute("hand-tracking-controls", { hand: n2.hand }), t2.setAttribute("obb-collider", { trackedObject3D: e, size: 0.04 }), this.auxMatrix = new Re.Matrix4, this.onCollisionStarted = this.onCollisionStarted.bind(this), this.el.addEventListener("obbcollisionstarted", this.onCollisionStarted), this.onCollisionEnded = this.onCollisionEnded.bind(this), this.el.addEventListener("obbcollisionended", this.onCollisionEnded), this.onPinchStarted = this.onPinchStarted.bind(this), this.el.addEventListener("pinchstarted", this.onPinchStarted), this.onPinchEnded = this.onPinchEnded.bind(this), this.el.addEventListener("pinchended", this.onPinchEnded);
|
|
}, transferEntityOwnership: function() {
|
|
for (var e, t2 = this.el.sceneEl.querySelectorAll("[hand-tracking-grab-controls]"), n2 = 0;n2 < t2.length; ++n2)
|
|
(e = t2[n2].components["hand-tracking-grab-controls"]) !== this && this.grabbedEl && this.grabbedEl === e.grabbedEl && e.releaseGrabbedEntity();
|
|
return false;
|
|
}, onCollisionStarted: function(e) {
|
|
var t2 = e.detail.withEl;
|
|
this.collidedEl || t2.getAttribute("grabbable") && (this.collidedEl = t2, this.grabbingObject3D = e.detail.trackedObject3D, this.data.hoverEnabled && this.el.setAttribute("hand-tracking-controls", "modelColor", this.data.hoverColor));
|
|
}, onCollisionEnded: function() {
|
|
this.collidedEl = undefined, this.grabbedEl || (this.grabbingObject3D = undefined, this.data.hoverEnabled && this.el.setAttribute("hand-tracking-controls", "modelColor", this.data.color));
|
|
}, onPinchStarted: function(e) {
|
|
this.collidedEl && (this.grabbedEl = this.collidedEl, this.transferEntityOwnership(), this.grab());
|
|
}, onPinchEnded: function() {
|
|
this.releaseGrabbedEntity();
|
|
}, releaseGrabbedEntity: function() {
|
|
var e = this.grabbedEl;
|
|
if (e) {
|
|
var t2 = e.object3D, n2 = t2.parent, i2 = this.originalParent;
|
|
t2.applyMatrix4(n2.matrixWorld), t2.applyMatrix4(this.auxMatrix.copy(i2.matrixWorld).invert()), n2.remove(t2), i2.add(t2), this.el.emit("grabended", { grabbedEl: e }), this.grabbedEl = undefined, this.originalParent = undefined;
|
|
}
|
|
}, grab: function() {
|
|
var e = this.grabbedEl, t2 = e.object3D, n2 = t2.parent;
|
|
this.originalParent = n2;
|
|
var i2 = this.el.components["hand-tracking-controls"].wristObject3D;
|
|
t2.applyMatrix4(n2.matrixWorld), t2.applyMatrix4(this.auxMatrix.copy(i2.matrixWorld).invert()), n2.remove(t2), i2.add(t2), this.el.emit("grabstarted", { grabbedEl: e });
|
|
} });
|
|
za = { toonLeft: ci + "controllers/hands/leftHand.glb", toonRight: ci + "controllers/hands/rightHand.glb", lowPolyLeft: ci + "controllers/hands/leftHandLow.glb", lowPolyRight: ci + "controllers/hands/rightHandLow.glb", highPolyLeft: ci + "controllers/hands/leftHandHigh.glb", highPolyRight: ci + "controllers/hands/rightHandHigh.glb" };
|
|
Ja = {};
|
|
Ja[Ka] = "grip", Ja[Wa] = "pistol", Ja[Ya] = "pointing", cs("hand-controls", { schema: { color: { default: "white", type: "color" }, hand: { default: "left" }, handModelStyle: { default: "lowPoly", oneOf: ["lowPoly", "highPoly", "toon"] } }, after: ["tracked-controls"], init: function() {
|
|
var e = this, t2 = this.el;
|
|
this.pressedButtons = {}, this.touchedButtons = {}, this.loader = new Xe, this.loader.setCrossOrigin("anonymous"), this.onGripDown = function() {
|
|
e.handleButton("grip", "down");
|
|
}, this.onGripUp = function() {
|
|
e.handleButton("grip", "up");
|
|
}, this.onTrackpadDown = function() {
|
|
e.handleButton("trackpad", "down");
|
|
}, this.onTrackpadUp = function() {
|
|
e.handleButton("trackpad", "up");
|
|
}, this.onTrackpadTouchStart = function() {
|
|
e.handleButton("trackpad", "touchstart");
|
|
}, this.onTrackpadTouchEnd = function() {
|
|
e.handleButton("trackpad", "touchend");
|
|
}, this.onTriggerDown = function() {
|
|
e.handleButton("trigger", "down");
|
|
}, this.onTriggerUp = function() {
|
|
e.handleButton("trigger", "up");
|
|
}, this.onTriggerTouchStart = function() {
|
|
e.handleButton("trigger", "touchstart");
|
|
}, this.onTriggerTouchEnd = function() {
|
|
e.handleButton("trigger", "touchend");
|
|
}, this.onGripTouchStart = function() {
|
|
e.handleButton("grip", "touchstart");
|
|
}, this.onGripTouchEnd = function() {
|
|
e.handleButton("grip", "touchend");
|
|
}, this.onThumbstickDown = function() {
|
|
e.handleButton("thumbstick", "down");
|
|
}, this.onThumbstickUp = function() {
|
|
e.handleButton("thumbstick", "up");
|
|
}, this.onAorXTouchStart = function() {
|
|
e.handleButton("AorX", "touchstart");
|
|
}, this.onAorXTouchEnd = function() {
|
|
e.handleButton("AorX", "touchend");
|
|
}, this.onBorYTouchStart = function() {
|
|
e.handleButton("BorY", "touchstart");
|
|
}, this.onBorYTouchEnd = function() {
|
|
e.handleButton("BorY", "touchend");
|
|
}, this.onSurfaceTouchStart = function() {
|
|
e.handleButton("surface", "touchstart");
|
|
}, this.onSurfaceTouchEnd = function() {
|
|
e.handleButton("surface", "touchend");
|
|
}, this.onControllerConnected = this.onControllerConnected.bind(this), this.onControllerDisconnected = this.onControllerDisconnected.bind(this), t2.addEventListener("controllerconnected", this.onControllerConnected), t2.addEventListener("controllerdisconnected", this.onControllerDisconnected), t2.object3D.visible = false;
|
|
}, play: function() {
|
|
this.addEventListeners();
|
|
}, pause: function() {
|
|
this.removeEventListeners();
|
|
}, tick: function(e, t2) {
|
|
var n2 = this.el.getObject3D("mesh");
|
|
n2 && n2.mixer && n2.mixer.update(t2 / 1000);
|
|
}, onControllerConnected: function(e) {
|
|
var t2 = this.el, n2 = this.data.hand, i2 = this.el.getObject3D("mesh");
|
|
t2.object3D.visible = true;
|
|
var r2 = n2 === "left" ? Math.PI / 2 : -Math.PI / 2, o2 = t2.sceneEl.hasWebXR ? -Math.PI / 2 : 0;
|
|
e.detail.name === "pico-controls" && (o2 += Math.PI / 4), i2.position.set(0, 0, 0), i2.rotation.set(o2, 0, r2);
|
|
}, onControllerDisconnected: function() {
|
|
this.el.object3D.visible = false;
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("gripdown", this.onGripDown), e.addEventListener("gripup", this.onGripUp), e.addEventListener("trackpaddown", this.onTrackpadDown), e.addEventListener("trackpadup", this.onTrackpadUp), e.addEventListener("trackpadtouchstart", this.onTrackpadTouchStart), e.addEventListener("trackpadtouchend", this.onTrackpadTouchEnd), e.addEventListener("triggerdown", this.onTriggerDown), e.addEventListener("triggerup", this.onTriggerUp), e.addEventListener("triggertouchstart", this.onTriggerTouchStart), e.addEventListener("triggertouchend", this.onTriggerTouchEnd), e.addEventListener("griptouchstart", this.onGripTouchStart), e.addEventListener("griptouchend", this.onGripTouchEnd), e.addEventListener("thumbstickdown", this.onThumbstickDown), e.addEventListener("thumbstickup", this.onThumbstickUp), e.addEventListener("abuttontouchstart", this.onAorXTouchStart), e.addEventListener("abuttontouchend", this.onAorXTouchEnd), e.addEventListener("bbuttontouchstart", this.onBorYTouchStart), e.addEventListener("bbuttontouchend", this.onBorYTouchEnd), e.addEventListener("xbuttontouchstart", this.onAorXTouchStart), e.addEventListener("xbuttontouchend", this.onAorXTouchEnd), e.addEventListener("ybuttontouchstart", this.onBorYTouchStart), e.addEventListener("ybuttontouchend", this.onBorYTouchEnd), e.addEventListener("surfacetouchstart", this.onSurfaceTouchStart), e.addEventListener("surfacetouchend", this.onSurfaceTouchEnd);
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("gripdown", this.onGripDown), e.removeEventListener("gripup", this.onGripUp), e.removeEventListener("trackpaddown", this.onTrackpadDown), e.removeEventListener("trackpadup", this.onTrackpadUp), e.removeEventListener("trackpadtouchstart", this.onTrackpadTouchStart), e.removeEventListener("trackpadtouchend", this.onTrackpadTouchEnd), e.removeEventListener("triggerdown", this.onTriggerDown), e.removeEventListener("triggerup", this.onTriggerUp), e.removeEventListener("triggertouchstart", this.onTriggerTouchStart), e.removeEventListener("triggertouchend", this.onTriggerTouchEnd), e.removeEventListener("griptouchstart", this.onGripTouchStart), e.removeEventListener("griptouchend", this.onGripTouchEnd), e.removeEventListener("thumbstickdown", this.onThumbstickDown), e.removeEventListener("thumbstickup", this.onThumbstickUp), e.removeEventListener("abuttontouchstart", this.onAorXTouchStart), e.removeEventListener("abuttontouchend", this.onAorXTouchEnd), e.removeEventListener("bbuttontouchstart", this.onBorYTouchStart), e.removeEventListener("bbuttontouchend", this.onBorYTouchEnd), e.removeEventListener("xbuttontouchstart", this.onAorXTouchStart), e.removeEventListener("xbuttontouchend", this.onAorXTouchEnd), e.removeEventListener("ybuttontouchstart", this.onBorYTouchStart), e.removeEventListener("ybuttontouchend", this.onBorYTouchEnd), e.removeEventListener("surfacetouchstart", this.onSurfaceTouchStart), e.removeEventListener("surfacetouchend", this.onSurfaceTouchEnd);
|
|
}, update: function(e) {
|
|
var t2, n2 = this.el, i2 = this.data.hand, r2 = this.data.handModelStyle, o2 = this.data.color, s2 = this;
|
|
if (t2 = { hand: i2, model: false }, i2 !== e) {
|
|
var a2 = za[r2 + i2.charAt(0).toUpperCase() + i2.slice(1)];
|
|
this.loader.load(a2, function(e2) {
|
|
var i3 = e2.scene.children[0];
|
|
i3.mixer = new Re.AnimationMixer(i3), s2.clips = e2.animations, n2.setObject3D("mesh", i3), i3.traverse(function(e3) {
|
|
e3.isMesh && (e3.material.color = new Re.Color(o2));
|
|
}), n2.setAttribute("magicleap-controls", t2), n2.setAttribute("vive-controls", t2), n2.setAttribute("meta-touch-controls", t2), n2.setAttribute("pico-controls", t2), n2.setAttribute("windows-motion-controls", t2), n2.setAttribute("hp-mixed-reality-controls", t2);
|
|
});
|
|
}
|
|
}, remove: function() {
|
|
this.el.removeObject3D("mesh");
|
|
}, handleButton: function(e, t2) {
|
|
var n2, i2 = t2 === "down", r2 = t2 === "touchstart";
|
|
if (t2.indexOf("touch") === 0) {
|
|
if (r2 === this.touchedButtons[e])
|
|
return;
|
|
this.touchedButtons[e] = r2;
|
|
} else {
|
|
if (i2 === this.pressedButtons[e])
|
|
return;
|
|
this.pressedButtons[e] = i2;
|
|
}
|
|
n2 = this.gesture, this.gesture = this.determineGesture(), this.gesture !== n2 && (this.animateGesture(this.gesture, n2), this.emitGestureEvents(this.gesture, n2));
|
|
}, determineGesture: function() {
|
|
var e, t2, n2, i2 = this.pressedButtons.grip, r2 = this.pressedButtons.surface || this.touchedButtons.surface, o2 = this.pressedButtons.trackpad || this.touchedButtons.trackpad, s2 = this.pressedButtons.trigger || this.touchedButtons.trigger, a2 = this.touchedButtons.AorX || this.touchedButtons.BorY;
|
|
return t2 = this.el.components["tracked-controls"], (n2 = t2 && t2.controller) && (n2.id && n2.id.indexOf("OpenVR ") === 0 || n2.profiles && n2.profiles[0] && n2.profiles[0] === "htc-vive") ? i2 || s2 ? e = Ka : o2 && (e = Ya) : i2 ? e = r2 || a2 || o2 ? s2 ? Ka : Ya : s2 ? Wa : "Point + Thumb" : s2 && (e = "Hold"), e;
|
|
}, getClip: function(e) {
|
|
var t2, n2;
|
|
for (n2 = 0;n2 < this.clips.length; n2++)
|
|
if ((t2 = this.clips[n2]).name === e)
|
|
return t2;
|
|
}, animateGesture: function(e, t2) {
|
|
e ? this.playAnimation(e || "Open", t2, false) : this.playAnimation(t2, t2, true);
|
|
}, emitGestureEvents: function(e, t2) {
|
|
var n2, i2 = this.el;
|
|
t2 !== e && ((n2 = Xa(t2, false)) && i2.emit(n2), (n2 = Xa(e, true)) && i2.emit(n2));
|
|
}, playAnimation: function(e, t2, n2) {
|
|
var i2, r2, o2 = this.el.getObject3D("mesh");
|
|
if (o2) {
|
|
if (i2 = this.getClip(e), r2 = o2.mixer.clipAction(i2), n2)
|
|
return r2.paused = false, void (r2.timeScale = -1);
|
|
if (r2.clampWhenFinished = true, r2.loop = Re.LoopOnce, r2.repetitions = 0, r2.timeScale = 1, r2.time = 0, r2.weight = 1, !t2)
|
|
return o2.mixer.stopAllAction(), void r2.play();
|
|
i2 = this.getClip(t2), r2.reset(), r2.play(), o2.mixer.clipAction(i2).crossFadeTo(r2, 0.15, true);
|
|
}
|
|
} }), cs("hide-on-enter-ar", { init: function() {
|
|
var e = this;
|
|
this.el.sceneEl.addEventListener("enter-vr", function() {
|
|
e.el.sceneEl.is("ar-mode") && (e.el.object3D.visible = false);
|
|
}), this.el.sceneEl.addEventListener("exit-vr", function() {
|
|
e.el.object3D.visible = true;
|
|
});
|
|
} }), cs("hide-on-enter-vr", { init: function() {
|
|
var e = this;
|
|
this.el.sceneEl.addEventListener("enter-vr", function() {
|
|
e.el.sceneEl.is("vr-mode") && (e.el.object3D.visible = false);
|
|
}), this.el.sceneEl.addEventListener("exit-vr", function() {
|
|
e.el.object3D.visible = true;
|
|
});
|
|
} });
|
|
$a = ci + "controllers/hp/mixed-reality/";
|
|
eA = { x: 0, y: 0, z: 0.06 };
|
|
tA = { _x: Math.PI / 4, _y: 0, _z: 0, _order: "XYZ" };
|
|
nA = (cs("hp-mixed-reality-controls", { schema: { hand: { default: "none" }, model: { default: true } }, mapping: { left: { axes: { touchpad: [2, 3] }, buttons: ["trigger", "grip", "none", "thumbstick", "xbutton", "ybutton"] }, right: { axes: { touchpad: [2, 3] }, buttons: ["trigger", "grip", "none", "thumbstick", "abutton", "bbutton"] } }, init: function() {
|
|
var e = this;
|
|
this.controllerPresent = false, this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e, e.data.hand);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e, e.data.hand);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e, e.data.hand);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e, e.data.hand);
|
|
}, this.previousButtonValues = {}, this.bindMethods();
|
|
}, update: function() {
|
|
var e = this.data;
|
|
this.controllerIndex = e.hand === "right" ? 0 : e.hand === "left" ? 1 : 2;
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, bindMethods: function() {
|
|
this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("axismove", this.onAxisMoved), e.addEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("axismove", this.onAxisMoved), e.removeEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.data;
|
|
Ur(this, Za, { index: this.controllerIndex, hand: e.hand });
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data;
|
|
e.setAttribute("tracked-controls", { idPrefix: Za, hand: t2.hand, controller: this.controllerIndex }), this.data.model && this.el.setAttribute("gltf-model", $a + this.data.hand + ".glb");
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onButtonChanged: function(e) {
|
|
var t2, n2 = this.mapping[this.data.hand].buttons[e.detail.id];
|
|
n2 && (n2 === "trigger" && (t2 = e.detail.state.value, console.log("analog value of trigger press: " + t2)), this.el.emit(n2 + "changed", e.detail.state));
|
|
}, onModelLoaded: function(e) {
|
|
var t2 = e.detail.model;
|
|
this.data.model && (t2.position.copy(eA), t2.rotation.copy(tA), this.el.emit("controllermodelready", { name: "hp-mixed-reality-controls", model: this.data.model, rayOrigin: new Re.Vector3(0, 0, 0) }));
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping.axes, e);
|
|
} }), fi("components:layer:warn"));
|
|
cs("layer", { schema: { type: { default: "quad", oneOf: ["quad", "monocubemap", "stereocubemap"] }, src: { type: "map" }, rotateCubemap: { default: false }, width: { default: 0 }, height: { default: 0 } }, init: function() {
|
|
var e = this.el.sceneEl.renderer.getContext();
|
|
this.quaternion = new Re.Quaternion, this.position = new Re.Vector3, this.bindMethods(), this.needsRedraw = false, this.frameBuffer = e.createFramebuffer();
|
|
var t2 = this.el.sceneEl.getAttribute("webxr"), n2 = t2.requiredFeatures;
|
|
n2.indexOf("layers") === -1 && (n2.push("layers"), this.el.sceneEl.setAttribute("webxr", t2)), this.el.sceneEl.addEventListener("enter-vr", this.onEnterVR), this.el.sceneEl.addEventListener("exit-vr", this.onExitVR);
|
|
}, bindMethods: function() {
|
|
this.onRequestedReferenceSpace = this.onRequestedReferenceSpace.bind(this), this.onEnterVR = this.onEnterVR.bind(this), this.onExitVR = this.onExitVR.bind(this);
|
|
}, update: function(e) {
|
|
this.data.src !== e.src && this.updateSrc();
|
|
}, updateSrc: function() {
|
|
var e = this.data.type;
|
|
this.texture = undefined, e !== "quad" ? e !== "monocubemap" && e !== "stereocubemap" || this.loadCubeMapImages() : this.loadQuadImage();
|
|
}, loadCubeMapImages: function() {
|
|
var e, t2 = this.xrGLFactory, n2 = this.el.sceneEl.frame, i2 = this.data.src, r2 = this.data.type;
|
|
this.visibilityChanged = false, this.layer && (r2 !== "monocubemap" && r2 !== "stereocubemap" || (i2.complete ? this.pendingCubeMapUpdate = false : this.pendingCubeMapUpdate = true, this.loadingScreen ? this.loadingScreen = false : this.loadingScreen = true, r2 === "monocubemap" ? (e = t2.getSubImage(this.layer, n2), this.loadCubeMapImage(e.colorTexture, i2, 0)) : (e = t2.getSubImage(this.layer, n2, "left"), this.loadCubeMapImage(e.colorTexture, i2, 0), e = t2.getSubImage(this.layer, n2, "right"), this.loadCubeMapImage(e.colorTexture, i2, 6))));
|
|
}, loadQuadImage: function() {
|
|
var e = this.data.src, t2 = this;
|
|
this.el.sceneEl.systems.material.loadTexture(e, { src: e }, function(n2) {
|
|
t2.el.sceneEl.renderer.initTexture(n2), t2.texture = n2, e.tagName === "VIDEO" && setTimeout(function() {
|
|
t2.textureIsVideo = true;
|
|
}, 1000), t2.layer && (t2.layer.height = t2.data.height / 2 || t2.texture.image.height / 1000, t2.layer.width = t2.data.width / 2 || t2.texture.image.width / 1000, t2.needsRedraw = true), t2.updateQuadPanel();
|
|
});
|
|
}, preGenerateCubeMapTextures: function(e, t2) {
|
|
this.data.type === "monocubemap" ? this.generateCubeMapTextures(e, 0, t2) : (this.generateCubeMapTextures(e, 0, t2), this.generateCubeMapTextures(e, 6, t2));
|
|
}, generateCubeMapTextures: function(e, t2, n2) {
|
|
for (var i2, r2, o2 = this.data, s2 = this.cubeFaceSize, a2 = Math.min(e.width, e.height), A2 = [], l2 = 0;l2 < 6; l2++) {
|
|
var c2 = document.createElement("CANVAS");
|
|
c2.width = c2.height = s2;
|
|
var h2 = c2.getContext("2d");
|
|
o2.rotateCubemap && (l2 !== 2 && l2 !== 3 || (h2.save(), h2.translate(s2, s2), h2.rotate(Math.PI))), h2.drawImage(e, (l2 + t2) * a2, 0, a2, a2, 0, 0, s2, s2), h2.restore(), n2 && n2(), A2.push(c2);
|
|
}
|
|
return o2.rotateCubemap && (i2 = A2[0], r2 = A2[1], A2[0] = r2, A2[1] = i2, i2 = A2[4], r2 = A2[5], A2[4] = r2, A2[5] = i2), n2 && n2(), A2;
|
|
}, loadCubeMapImage: function(e, t2, n2) {
|
|
var i2, r2 = this.el.sceneEl.renderer.getContext();
|
|
r2.pixelStorei(r2.UNPACK_FLIP_Y_WEBGL, false), r2.bindTexture(r2.TEXTURE_CUBE_MAP, e), i2 = !t2.complete || this.loadingScreen ? this.loadingScreenImages : this.generateCubeMapTextures(t2, n2);
|
|
var o2 = 0;
|
|
i2.forEach(function(e2, t3) {
|
|
r2.texSubImage2D(r2.TEXTURE_CUBE_MAP_POSITIVE_X + t3, 0, 0, 0, r2.RGBA, r2.UNSIGNED_BYTE, e2), o2 = r2.getError();
|
|
}), o2 !== 0 && console.log("renderingError, WebGL Error Code: " + o2), r2.bindTexture(r2.TEXTURE_CUBE_MAP, null);
|
|
}, tick: function() {
|
|
this.el.sceneEl.xrSession && this.referenceSpace && (this.layer || !this.el.sceneEl.is("vr-mode") && !this.el.sceneEl.is("ar-mode") || this.initLayer(), this.updateTransform(), this.data.src.complete && (this.pendingCubeMapUpdate || this.loadingScreen || this.visibilityChanged) && this.loadCubeMapImages(), (this.needsRedraw || this.layer.needsRedraw || this.textureIsVideo) && (this.data.type === "quad" && this.draw(), this.needsRedraw = false));
|
|
}, initLayer: function() {
|
|
var e = this, t2 = this.data.type;
|
|
this.el.sceneEl.xrSession.onvisibilitychange = function(t3) {
|
|
e.visibilityChanged = t3.session.visibilityState !== "hidden";
|
|
}, t2 !== "quad" ? t2 !== "monocubemap" && t2 !== "stereocubemap" || this.initCubeMapLayer() : this.initQuadLayer();
|
|
}, initQuadLayer: function() {
|
|
var e = this.el.sceneEl, t2 = e.renderer.getContext(), n2 = this.xrGLFactory = new XRWebGLBinding(e.xrSession, t2);
|
|
this.texture && (this.layer = n2.createQuadLayer({ space: this.referenceSpace, viewPixelHeight: 2048, viewPixelWidth: 2048, height: this.data.height / 2 || this.texture.image.height / 1000, width: this.data.width / 2 || this.texture.image.width / 1000 }), this.initLoadingScreenImages(), e.renderer.xr.addLayer(this.layer));
|
|
}, initCubeMapLayer: function() {
|
|
var e = this.data.src, t2 = this.el.sceneEl, n2 = t2.renderer.getContext(), i2 = n2.getParameter(n2.MAX_CUBE_MAP_TEXTURE_SIZE), r2 = this.cubeFaceSize = Math.min(i2, Math.min(e.width, e.height)), o2 = this.xrGLFactory = new XRWebGLBinding(t2.xrSession, n2);
|
|
this.layer = o2.createCubeLayer({ space: this.referenceSpace, viewPixelWidth: r2, viewPixelHeight: r2, layout: this.data.type === "monocubemap" ? "mono" : "stereo", isStatic: false }), this.initLoadingScreenImages(), this.loadCubeMapImages(), t2.renderer.xr.addLayer(this.layer);
|
|
}, initLoadingScreenImages: function() {
|
|
for (var e = this.cubeFaceSize, t2 = this.loadingScreenImages = [], n2 = 0;n2 < 6; n2++) {
|
|
var i2 = document.createElement("CANVAS");
|
|
i2.width = i2.height = e;
|
|
var r2 = i2.getContext("2d");
|
|
i2.width = i2.height = e, r2.fillStyle = "black", r2.fillRect(0, 0, e, e), n2 !== 2 && n2 !== 3 && (r2.translate(e, 0), r2.scale(-1, 1), r2.fillStyle = "white", r2.font = "30px Arial", r2.fillText("Loading", e / 2, e / 2)), t2.push(i2);
|
|
}
|
|
}, destroyLayer: function() {
|
|
this.layer && (this.el.sceneEl.renderer.xr.removeLayer(this.layer), this.layer.destroy(), this.layer = undefined);
|
|
}, toggleCompositorLayer: function() {
|
|
this.enableCompositorLayer(!this.layerEnabled);
|
|
}, enableCompositorLayer: function(e) {
|
|
this.layerEnabled = e, this.quadPanelEl.object3D.visible = !this.layerEnabled;
|
|
}, updateQuadPanel: function() {
|
|
var e = this.quadPanelEl;
|
|
this.quadPanelEl || (e = this.quadPanelEl = document.createElement("a-entity"), this.el.appendChild(e)), e.setAttribute("material", { shader: "flat", src: this.data.src, transparent: true }), e.setAttribute("geometry", { primitive: "plane", height: this.data.height || this.texture.image.height / 1000, width: this.data.width || this.texture.image.height / 1000 });
|
|
}, draw: function() {
|
|
var e = this.el.sceneEl, t2 = this.el.sceneEl.renderer.getContext(), n2 = this.xrGLFactory.getSubImage(this.layer, e.frame), i2 = e.renderer.properties.get(this.texture).__webglTexture, r2 = t2.getParameter(t2.FRAMEBUFFER_BINDING);
|
|
t2.viewport(n2.viewport.x, n2.viewport.y, n2.viewport.width, n2.viewport.height), t2.bindFramebuffer(t2.FRAMEBUFFER, this.frameBuffer), t2.framebufferTexture2D(t2.FRAMEBUFFER, t2.COLOR_ATTACHMENT0, t2.TEXTURE_2D, n2.colorTexture, 0), function(e2, t3, n3, i3) {
|
|
var r3 = e2.createFramebuffer(), o2 = n3.viewport.x, s2 = n3.viewport.y, a2 = n3.viewport.x + n3.viewport.width, A2 = n3.viewport.y + n3.viewport.height;
|
|
i3.tagName === "VIDEO" && (e2.bindTexture(e2.TEXTURE_2D, t3), e2.texSubImage2D(e2.TEXTURE_2D, 0, 0, 0, i3.width, i3.height, e2.RGB, e2.UNSIGNED_BYTE, i3)), e2.bindFramebuffer(e2.READ_FRAMEBUFFER, r3), e2.framebufferTexture2D(e2.READ_FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, t3, 0), e2.readBuffer(e2.COLOR_ATTACHMENT0), e2.blitFramebuffer(0, 0, i3.width, i3.height, o2, s2, a2, A2, e2.COLOR_BUFFER_BIT, e2.NEAREST), e2.bindFramebuffer(e2.READ_FRAMEBUFFER, null), e2.deleteFramebuffer(r3);
|
|
}(t2, i2, n2, this.data.src), t2.bindFramebuffer(t2.FRAMEBUFFER, r2);
|
|
}, updateTransform: function() {
|
|
var e = this.el, t2 = this.position, n2 = this.quaternion;
|
|
e.object3D.updateMatrixWorld(), t2.setFromMatrixPosition(e.object3D.matrixWorld), n2.setFromRotationMatrix(e.object3D.matrixWorld), this.layerEnabled || t2.set(0, 0, 1e8), this.layer.transform = new XRRigidTransform(t2, n2);
|
|
}, onEnterVR: function() {
|
|
var e = this.el.sceneEl, t2 = e.xrSession;
|
|
e.hasWebXR && XRWebGLBinding && t2 ? (t2.requestReferenceSpace("local-floor").then(this.onRequestedReferenceSpace), this.layerEnabled = true, this.quadPanelEl && (this.quadPanelEl.object3D.visible = false), this.data.src.play && this.data.src.play()) : nA("The layer component requires WebXR and the layers API enabled");
|
|
}, onExitVR: function() {
|
|
this.quadPanelEl && (this.quadPanelEl.object3D.visible = true), this.destroyLayer();
|
|
}, onRequestedReferenceSpace: function(e) {
|
|
this.referenceSpace = e;
|
|
} }), cs("laser-controls", { schema: { hand: { default: "right" }, model: { default: true }, defaultModelColor: { type: "color", default: "grey" } }, init: function() {
|
|
var e = this.config, t2 = this.data, n2 = this.el, i2 = this, r2 = { hand: t2.hand, model: t2.model };
|
|
function o2(t3) {
|
|
var r3 = e[t3.detail.name];
|
|
if (r3) {
|
|
var o3 = Jr({ showLine: true }, r3.raycaster || {});
|
|
t3.detail.rayOrigin && (o3.origin = t3.detail.rayOrigin.origin, o3.direction = t3.detail.rayOrigin.direction, o3.showLine = true), t3.detail.rayOrigin || !i2.modelReady ? n2.setAttribute("raycaster", o3) : n2.setAttribute("raycaster", "showLine", true), n2.setAttribute("cursor", Jr({ fuse: false }, r3.cursor));
|
|
}
|
|
}
|
|
n2.setAttribute("hp-mixed-reality-controls", r2), n2.setAttribute("magicleap-controls", r2), n2.setAttribute("oculus-go-controls", r2), n2.setAttribute("meta-touch-controls", r2), n2.setAttribute("pico-controls", r2), n2.setAttribute("valve-index-controls", r2), n2.setAttribute("vive-controls", r2), n2.setAttribute("vive-focus-controls", r2), n2.setAttribute("windows-motion-controls", r2), n2.setAttribute("generic-tracked-controller-controls", { hand: r2.hand }), n2.addEventListener("controllerconnected", o2), n2.addEventListener("controllerdisconnected", function(t3) {
|
|
e[t3.detail.name] && n2.setAttribute("raycaster", "showLine", false);
|
|
}), n2.addEventListener("controllermodelready", function(e2) {
|
|
o2(e2), i2.modelReady = true;
|
|
});
|
|
}, config: { "generic-tracked-controller-controls": { cursor: { downEvents: ["triggerdown"], upEvents: ["triggerup"] } }, "hp-mixed-reality-controls": { cursor: { downEvents: ["triggerdown"], upEvents: ["triggerup"] }, raycaster: { origin: { x: 0, y: 0, z: 0 } } }, "magicleap-controls": { cursor: { downEvents: ["trackpaddown", "triggerdown"], upEvents: ["trackpadup", "triggerup"] } }, "oculus-go-controls": { cursor: { downEvents: ["triggerdown"], upEvents: ["triggerup"] }, raycaster: { origin: { x: 0, y: 0.0005, z: 0 } } }, "meta-touch-controls": { cursor: { downEvents: ["triggerdown"], upEvents: ["triggerup"] }, raycaster: { origin: { x: 0, y: 0, z: 0 } } }, "pico-controls": { cursor: { downEvents: ["triggerdown"], upEvents: ["triggerup"] } }, "valve-index-controls": { cursor: { downEvents: ["triggerdown"], upEvents: ["triggerup"] } }, "vive-controls": { cursor: { downEvents: ["triggerdown"], upEvents: ["triggerup"] } }, "vive-focus-controls": { cursor: { downEvents: ["trackpaddown", "triggerdown"], upEvents: ["trackpadup", "triggerup"] } }, "windows-motion-controls": { cursor: { downEvents: ["triggerdown"], upEvents: ["triggerup"] }, raycaster: { showLine: false } } } });
|
|
gA = Re.MathUtils.degToRad;
|
|
pA = fi("components:light:warn");
|
|
fA = new Re.CubeTextureLoader;
|
|
mA = {};
|
|
cs("light", { schema: { angle: { default: 60, if: { type: ["spot"] } }, color: { type: "color", if: { type: ["ambient", "directional", "hemisphere", "point", "spot"] } }, envMap: { default: "", if: { type: ["probe"] } }, groundColor: { type: "color", if: { type: ["hemisphere"] } }, decay: { default: 1, if: { type: ["point", "spot"] } }, distance: { default: 0, min: 0, if: { type: ["point", "spot"] } }, intensity: { default: 3.14, min: 0, if: { type: ["ambient", "directional", "hemisphere", "point", "spot", "probe"] } }, penumbra: { default: 0, min: 0, max: 1, if: { type: ["spot"] } }, type: { default: "directional", oneOf: ["ambient", "directional", "hemisphere", "point", "spot", "probe"], schemaChange: true }, target: { type: "selector", if: { type: ["spot", "directional"] } }, castShadow: { default: false, if: { type: ["point", "spot", "directional"] } }, shadowBias: { default: 0, if: { castShadow: true } }, shadowCameraFar: { default: 500, if: { castShadow: true } }, shadowCameraFov: { default: 90, if: { castShadow: true } }, shadowCameraNear: { default: 0.5, if: { castShadow: true } }, shadowCameraTop: { default: 5, if: { castShadow: true } }, shadowCameraRight: { default: 5, if: { castShadow: true } }, shadowCameraBottom: { default: -5, if: { castShadow: true } }, shadowCameraLeft: { default: -5, if: { castShadow: true } }, shadowCameraVisible: { default: false, if: { castShadow: true } }, shadowCameraAutomatic: { default: "", if: { type: ["directional"] } }, shadowMapHeight: { default: 512, if: { castShadow: true } }, shadowMapWidth: { default: 512, if: { castShadow: true } }, shadowRadius: { default: 1, if: { castShadow: true } } }, init: function() {
|
|
var e = this.el;
|
|
this.light = null, this.defaultTarget = null, this.system.registerLight(e);
|
|
}, update: function(e) {
|
|
var t2 = this.data, n2 = no(t2, e), i2 = this.light, r2 = this;
|
|
if (!i2 || "type" in n2)
|
|
this.setLight(this.data), this.updateShadow();
|
|
else {
|
|
var o2 = false;
|
|
Object.keys(n2).forEach(function(e2) {
|
|
var n3 = t2[e2];
|
|
switch (e2) {
|
|
case "color":
|
|
i2.color.set(n3);
|
|
break;
|
|
case "groundColor":
|
|
i2.groundColor.set(n3);
|
|
break;
|
|
case "angle":
|
|
i2.angle = gA(n3);
|
|
break;
|
|
case "target":
|
|
n3 === null ? t2.type !== "spot" && t2.type !== "directional" || (i2.target = r2.defaultTarget) : n3.hasLoaded ? r2.onSetTarget(n3, i2) : n3.addEventListener("loaded", r2.onSetTarget.bind(r2, n3, i2));
|
|
break;
|
|
case "envMap":
|
|
r2.updateProbeMap(t2, i2);
|
|
break;
|
|
case "castShadow":
|
|
case "shadowBias":
|
|
case "shadowCameraFar":
|
|
case "shadowCameraFov":
|
|
case "shadowCameraNear":
|
|
case "shadowCameraTop":
|
|
case "shadowCameraRight":
|
|
case "shadowCameraBottom":
|
|
case "shadowCameraLeft":
|
|
case "shadowCameraVisible":
|
|
case "shadowMapHeight":
|
|
case "shadowMapWidth":
|
|
case "shadowRadius":
|
|
o2 || (r2.updateShadow(), o2 = true);
|
|
break;
|
|
case "shadowCameraAutomatic":
|
|
t2.shadowCameraAutomatic ? r2.shadowCameraAutomaticEls = Array.from(document.querySelectorAll(t2.shadowCameraAutomatic)) : r2.shadowCameraAutomaticEls = [];
|
|
break;
|
|
default:
|
|
i2[e2] = n3;
|
|
}
|
|
});
|
|
}
|
|
}, tick: (rA = new Re.Box3, oA = new Re.Vector3, sA = new Re.Vector3, aA = new Re.Matrix4, AA = new Re.Sphere, lA = new Re.Vector3, function() {
|
|
if (this.data.type === "directional" && this.light.shadow && this.light.shadow.camera instanceof Re.OrthographicCamera && this.shadowCameraAutomaticEls.length) {
|
|
var e = this.light.shadow.camera;
|
|
e.getWorldDirection(oA), e.getWorldPosition(sA), aA.copy(e.matrixWorld), aA.invert(), e.near = 1, e.left = 1e5, e.right = -1e5, e.top = -1e5, e.bottom = 1e5, this.shadowCameraAutomaticEls.forEach(function(t2) {
|
|
rA.setFromObject(t2.object3D), rA.getBoundingSphere(AA);
|
|
var n2, i2, r2, o2, s2, a2 = iA(sA, oA, AA.center), A2 = (n2 = sA, i2 = oA, r2 = AA.center, o2 = lA, s2 = iA(n2, i2, r2), o2.copy(i2), o2.multiplyScalar(s2), o2.add(r2), o2).applyMatrix4(aA);
|
|
e.near = Math.min(-a2 - AA.radius - 1, e.near), e.left = Math.min(-AA.radius + A2.x, e.left), e.right = Math.max(AA.radius + A2.x, e.right), e.top = Math.max(AA.radius + A2.y, e.top), e.bottom = Math.min(-AA.radius + A2.y, e.bottom);
|
|
}), e.updateProjectionMatrix();
|
|
}
|
|
}), setLight: function(e) {
|
|
var t2 = this.el, n2 = this.getLight(e);
|
|
n2 && (this.light && t2.removeObject3D("light"), this.light = n2, this.light.el = t2, t2.setObject3D("light", this.light), e.type !== "spot" && e.type !== "directional" && e.type !== "hemisphere" || t2.getObject3D("light").translateY(-1), e.type === "spot" && (t2.setObject3D("light-target", this.defaultTarget), t2.getObject3D("light-target").position.set(0, 0, -1)), e.shadowCameraAutomatic ? this.shadowCameraAutomaticEls = Array.from(document.querySelectorAll(e.shadowCameraAutomatic)) : this.shadowCameraAutomaticEls = []);
|
|
}, updateShadow: function() {
|
|
var e = this.el, t2 = this.data, n2 = this.light;
|
|
n2.castShadow = t2.castShadow;
|
|
var i2 = e.getObject3D("cameraHelper");
|
|
if (t2.shadowCameraVisible && !i2 ? (i2 = new Re.CameraHelper(n2.shadow.camera), e.setObject3D("cameraHelper", i2)) : !t2.shadowCameraVisible && i2 && e.removeObject3D("cameraHelper"), !t2.castShadow)
|
|
return n2;
|
|
n2.shadow.bias = t2.shadowBias, n2.shadow.radius = t2.shadowRadius, n2.shadow.mapSize.height = t2.shadowMapHeight, n2.shadow.mapSize.width = t2.shadowMapWidth, n2.shadow.camera.near = t2.shadowCameraNear, n2.shadow.camera.far = t2.shadowCameraFar, n2.shadow.camera instanceof Re.OrthographicCamera ? (n2.shadow.camera.top = t2.shadowCameraTop, n2.shadow.camera.right = t2.shadowCameraRight, n2.shadow.camera.bottom = t2.shadowCameraBottom, n2.shadow.camera.left = t2.shadowCameraLeft) : n2.shadow.camera.fov = t2.shadowCameraFov, n2.shadow.camera.updateProjectionMatrix(), i2 && i2.update();
|
|
}, getLight: function(e) {
|
|
var t2 = e.angle, n2 = new Re.Color(e.color);
|
|
n2 = n2.getHex();
|
|
var { decay: i2, distance: r2 } = e, o2 = new Re.Color(e.groundColor);
|
|
o2 = o2.getHex();
|
|
var { intensity: s2, type: a2, target: A2 } = e, l2 = null;
|
|
switch (a2.toLowerCase()) {
|
|
case "ambient":
|
|
return new Re.AmbientLight(n2, s2);
|
|
case "directional":
|
|
return l2 = new Re.DirectionalLight(n2, s2), this.defaultTarget = l2.target, A2 && (A2.hasLoaded ? this.onSetTarget(A2, l2) : A2.addEventListener("loaded", this.onSetTarget.bind(this, A2, l2))), l2;
|
|
case "hemisphere":
|
|
return new Re.HemisphereLight(n2, o2, s2);
|
|
case "point":
|
|
return new Re.PointLight(n2, s2, r2, i2);
|
|
case "spot":
|
|
return l2 = new Re.SpotLight(n2, s2, r2, gA(t2), e.penumbra, i2), this.defaultTarget = l2.target, A2 && (A2.hasLoaded ? this.onSetTarget(A2, l2) : A2.addEventListener("loaded", this.onSetTarget.bind(this, A2, l2))), l2;
|
|
case "probe":
|
|
return l2 = new Re.LightProbe, this.updateProbeMap(e, l2), l2;
|
|
default:
|
|
pA("%s is not a valid light type. Choose from ambient, directional, hemisphere, point, spot.", a2);
|
|
}
|
|
}, updateProbeMap: function(e, t2) {
|
|
e.envMap ? (mA[e.envMap] === undefined && (mA[e.envMap] = new window.Promise(function(t3) {
|
|
ur(e.envMap, function(n2) {
|
|
fA.load(n2, function(n3) {
|
|
var i2 = oi.fromCubeTexture(n3);
|
|
mA[e.envMap] = i2, t3(i2);
|
|
});
|
|
});
|
|
})), mA[e.envMap] instanceof window.Promise ? mA[e.envMap].then(function(e2) {
|
|
t2.copy(e2);
|
|
}) : mA[e.envMap] instanceof Re.LightProbe && t2.copy(mA[e.envMap])) : t2.copy(new Re.LightProbe);
|
|
}, onSetTarget: function(e, t2) {
|
|
t2.target = e.object3D;
|
|
}, remove: function() {
|
|
var e = this.el;
|
|
e.removeObject3D("light"), e.getObject3D("cameraHelper") && e.removeObject3D("cameraHelper");
|
|
} }), cs("line", { schema: { start: { type: "vec3", default: { x: 0, y: 0, z: 0 } }, end: { type: "vec3", default: { x: 0, y: 0, z: 0 } }, color: { type: "color", default: "#74BEC1" }, opacity: { type: "number", default: 1 }, visible: { default: true } }, multiple: true, init: function() {
|
|
var e, t2, n2 = this.data;
|
|
t2 = this.material = new Re.LineBasicMaterial({ color: n2.color, opacity: n2.opacity, transparent: n2.opacity < 1, visible: n2.visible }), (e = this.geometry = new Re.BufferGeometry).setAttribute("position", new Re.BufferAttribute(new Float32Array(6), 3)), this.line = new Re.Line(e, t2), this.el.setObject3D(this.attrName, this.line);
|
|
}, update: function(e) {
|
|
var t2 = this.data, n2 = this.geometry, i2 = false, r2 = this.material, o2 = n2.attributes.position.array;
|
|
EA(t2.start, e.start) || (o2[0] = t2.start.x, o2[1] = t2.start.y, o2[2] = t2.start.z, i2 = true), EA(t2.end, e.end) || (o2[3] = t2.end.x, o2[4] = t2.end.y, o2[5] = t2.end.z, i2 = true), i2 && (n2.attributes.position.needsUpdate = true, n2.computeBoundingSphere()), r2.color.setStyle(t2.color), r2.opacity = t2.opacity, r2.transparent = t2.opacity < 1, r2.visible = t2.visible;
|
|
}, remove: function() {
|
|
this.el.removeObject3D(this.attrName, this.line);
|
|
} }), cs("link", { schema: { backgroundColor: { default: "red", type: "color" }, borderColor: { default: "white", type: "color" }, highlighted: { default: false }, highlightedColor: { default: "#24CAFF", type: "color" }, href: { default: "" }, image: { type: "asset" }, on: { default: "click" }, peekMode: { default: false }, title: { default: "" }, titleColor: { default: "white", type: "color" }, visualAspectEnabled: { default: false } }, init: function() {
|
|
this.navigate = this.navigate.bind(this), this.previousQuaternion = undefined, this.quaternionClone = new Re.Quaternion, this.hiddenEls = [];
|
|
}, update: function(e) {
|
|
var t2, n2, i2 = this.data, r2 = this.el;
|
|
if (i2.visualAspectEnabled) {
|
|
var o2 = this.el.getAttribute("scale");
|
|
this.previewDistance = 15 * (o2.x + o2.y) / 2, this.initVisualAspect(), t2 = i2.highlighted ? i2.highlightedColor : i2.backgroundColor, n2 = i2.highlighted ? i2.highlightedColor : i2.borderColor, r2.setAttribute("material", "backgroundColor", t2), r2.setAttribute("material", "strokeColor", n2), i2.on !== e.on && this.updateEventListener(), e.peekMode !== undefined && i2.peekMode !== e.peekMode && this.updatePeekMode(), i2.image && e.image !== i2.image && r2.setAttribute("material", "pano", typeof i2.image == "string" ? i2.image : i2.image.src);
|
|
}
|
|
}, updatePeekMode: function() {
|
|
var e = this.el, t2 = this.sphereEl;
|
|
this.data.peekMode ? (this.hideAll(), e.getObject3D("mesh").visible = false, t2.setAttribute("visible", true)) : (this.showAll(), e.getObject3D("mesh").visible = true, t2.setAttribute("visible", false));
|
|
}, play: function() {
|
|
this.updateEventListener();
|
|
}, pause: function() {
|
|
this.removeEventListener();
|
|
}, updateEventListener: function() {
|
|
var e = this.el;
|
|
e.isPlaying && (this.removeEventListener(), e.addEventListener(this.data.on, this.navigate));
|
|
}, removeEventListener: function() {
|
|
var e = this.data.on;
|
|
e && this.el.removeEventListener(e, this.navigate);
|
|
}, initVisualAspect: function() {
|
|
var e, t2, n2, i2 = this.el;
|
|
this.data.visualAspectEnabled && !this.visualAspectInitialized && (n2 = this.textEl = this.textEl || document.createElement("a-entity"), t2 = this.sphereEl = this.sphereEl || document.createElement("a-entity"), e = this.semiSphereEl = this.semiSphereEl || document.createElement("a-entity"), i2.setAttribute("geometry", { primitive: "circle", radius: 1, segments: 64 }), i2.setAttribute("material", { shader: "portal", pano: this.data.image, side: "double", previewDistance: this.previewDistance }), n2.setAttribute("text", { color: this.data.titleColor, align: "center", font: "kelsonsans", value: this.data.title || this.data.href, width: 4 }), n2.setAttribute("position", "0 1.5 0"), i2.appendChild(n2), e.setAttribute("geometry", { primitive: "sphere", radius: 1, phiStart: 0, segmentsWidth: 64, segmentsHeight: 64, phiLength: 180, thetaStart: 0, thetaLength: 360 }), e.setAttribute("material", { shader: "portal", borderEnabled: 0, pano: this.data.image, side: "back", previewDistance: this.previewDistance }), e.setAttribute("rotation", "0 180 0"), e.setAttribute("position", "0 0 0"), e.setAttribute("visible", false), i2.appendChild(e), t2.setAttribute("geometry", { primitive: "sphere", radius: 10, segmentsWidth: 64, segmentsHeight: 64 }), t2.setAttribute("material", { shader: "portal", borderEnabled: 0, pano: this.data.image, side: "back", previewDistance: this.previewDistance }), t2.setAttribute("visible", false), i2.appendChild(t2), this.visualAspectInitialized = true);
|
|
}, navigate: function() {
|
|
window.location = this.data.href;
|
|
}, tick: function() {
|
|
var e = new Re.Vector3, t2 = new Re.Vector3, n2 = new Re.Quaternion, i2 = new Re.Vector3;
|
|
return function() {
|
|
var r2, o2, s2 = this.el, a2 = s2.object3D, A2 = s2.sceneEl.camera, l2 = this.textEl;
|
|
if (this.data.visualAspectEnabled)
|
|
if (a2.updateMatrixWorld(), A2.parent.updateMatrixWorld(), A2.updateMatrixWorld(), a2.matrix.decompose(t2, n2, i2), t2.setFromMatrixPosition(a2.matrixWorld), e.setFromMatrixPosition(A2.matrixWorld), (o2 = t2.distanceTo(e)) > 1.33333 * this.previewDistance)
|
|
this.previousQuaternion || (this.quaternionClone.copy(n2), this.previousQuaternion = this.quaternionClone), a2.lookAt(e);
|
|
else {
|
|
if (r2 = this.calculateCameraPortalOrientation(), o2 < 0.5) {
|
|
if (this.semiSphereEl.getAttribute("visible") === true)
|
|
return;
|
|
l2.setAttribute("text", "width", 1.5), r2 <= 0 ? (l2.setAttribute("position", "0 0 0.75"), l2.setAttribute("rotation", "0 180 0"), this.semiSphereEl.setAttribute("rotation", "0 0 0")) : (l2.setAttribute("position", "0 0 -0.75"), l2.setAttribute("rotation", "0 0 0"), this.semiSphereEl.setAttribute("rotation", "0 180 0")), s2.getObject3D("mesh").visible = false, this.semiSphereEl.setAttribute("visible", true), this.peekCameraPortalOrientation = r2;
|
|
} else
|
|
r2 <= 0 ? l2.setAttribute("rotation", "0 180 0") : l2.setAttribute("rotation", "0 0 0"), l2.setAttribute("text", "width", 5), l2.setAttribute("position", "0 1.5 0"), s2.getObject3D("mesh").visible = true, this.semiSphereEl.setAttribute("visible", false), this.peekCameraPortalOrientation = undefined;
|
|
this.previousQuaternion && (a2.quaternion.copy(this.previousQuaternion), this.previousQuaternion = undefined);
|
|
}
|
|
};
|
|
}(), hideAll: function() {
|
|
var e = this.el, t2 = this.hiddenEls, n2 = this;
|
|
t2.length > 0 || e.sceneEl.object3D.traverse(function(i2) {
|
|
i2 && i2.el && i2.el.hasAttribute("link-controls") || i2.el && i2 !== e.sceneEl.object3D && i2.el !== e && i2.el !== n2.sphereEl && i2.el !== e.sceneEl.cameraEl && i2.el.getAttribute("visible") !== false && i2.el !== n2.textEl && i2.el !== n2.semiSphereEl && (i2.el.setAttribute("visible", false), t2.push(i2.el));
|
|
});
|
|
}, showAll: function() {
|
|
this.hiddenEls.forEach(function(e) {
|
|
e.setAttribute("visible", true);
|
|
}), this.hiddenEls = [];
|
|
}, calculateCameraPortalOrientation: (cA = new Re.Matrix4, hA = new Re.Vector3, dA = new Re.Vector3(0, 0, 1), uA = new Re.Vector3(0, 0, 0), function() {
|
|
var e = this.el, t2 = e.sceneEl.camera;
|
|
return hA.set(0, 0, 0), dA.set(0, 0, 1), uA.set(0, 0, 0), e.object3D.matrixWorld.extractRotation(cA), dA.applyMatrix4(cA), e.object3D.updateMatrixWorld(), e.object3D.localToWorld(uA), t2.parent.parent.updateMatrixWorld(), t2.parent.updateMatrixWorld(), t2.updateMatrixWorld(), t2.localToWorld(hA), hA.sub(uA).normalize(), dA.normalize(), Math.sign(dA.dot(hA));
|
|
}), remove: function() {
|
|
this.removeEventListener();
|
|
} }), ia("portal", { schema: { borderEnabled: { default: 1, type: "int", is: "uniform" }, backgroundColor: { default: "red", type: "color", is: "uniform" }, pano: { type: "map", is: "uniform" }, strokeColor: { default: "white", type: "color", is: "uniform" }, previewDistance: { default: 15, type: "float", is: "uniform" } }, vertexShader: ["vec3 portalPosition;", "varying vec3 vWorldPosition;", "varying float vDistanceToCenter;", "varying float vDistance;", "void main() {", "vDistanceToCenter = clamp(length(position - vec3(0.0, 0.0, 0.0)), 0.0, 1.0);", "portalPosition = (modelMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz;", "vDistance = length(portalPosition - cameraPosition);", "vWorldPosition = (modelMatrix * vec4(position, 1.0)).xyz;", "gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);", "}"].join(`
|
|
`), fragmentShader: ["#define RECIPROCAL_PI2 0.15915494", "uniform sampler2D pano;", "uniform vec3 strokeColor;", "uniform vec3 backgroundColor;", "uniform float borderEnabled;", "uniform float previewDistance;", "varying float vDistanceToCenter;", "varying float vDistance;", "varying vec3 vWorldPosition;", "void main() {", "vec3 direction = normalize(vWorldPosition - cameraPosition);", "vec2 sampleUV;", "float borderThickness = clamp(exp(-vDistance / 50.0), 0.6, 0.95);", "sampleUV.y = clamp(direction.y * 0.5 + 0.5, 0.0, 1.0);", "sampleUV.x = atan(direction.z, -direction.x) * -RECIPROCAL_PI2 + 0.5;", "if (vDistanceToCenter > borderThickness && borderEnabled == 1.0) {", "gl_FragColor = vec4(strokeColor, 1.0);", "} else {", "gl_FragColor = mix(texture2D(pano, sampleUV), vec4(backgroundColor, 1.0), clamp(pow((vDistance / previewDistance), 2.0), 0.0, 1.0));", "}", "}"].join(`
|
|
`) });
|
|
vA = ci + "controllers/logitech/";
|
|
BA = (cs("logitech-mx-ink-controls", { schema: { hand: { default: "left" }, model: { default: true }, orientationOffset: { type: "vec3" } }, mapping: { left: { buttons: ["front", "back", "none", "none", "none", "tip"] }, right: { buttons: ["front", "back", "none", "none", "none", "tip"] } }, init: function() {
|
|
var e = this;
|
|
this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e, e.data.hand);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e, e.data.hand);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e, e.data.hand);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e, e.data.hand);
|
|
}, this.bindMethods();
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, bindMethods: function() {
|
|
this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("axismove", this.onAxisMoved), e.addEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("axismove", this.onAxisMoved), e.removeEventListener("model-loaded", this.onModelLoaded), e.sceneEl.removeEventListener("enter-vr", this.onEnterVR), e.sceneEl.removeEventListener("exit-vr", this.onExitVR), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.controllerObject3D;
|
|
e && (e.visible = false), Ur(this, CA, { hand: this.data.hand, iterateControllerProfiles: true });
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data, n2 = CA;
|
|
e.setAttribute("tracked-controls", { id: n2, hand: t2.hand, handTrackingEnabled: false, iterateControllerProfiles: true, orientationOffset: t2.orientationOffset }), this.loadModel();
|
|
}, loadModel: function() {
|
|
var e = this.controllerObject3D;
|
|
if (this.data.model)
|
|
return e ? (e.visible = this.el.sceneEl.is("vr-mode"), void this.el.setObject3D("mesh", e)) : void this.el.setAttribute("gltf-model", vA + "logitech-mx-ink.glb");
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onButtonChanged: function(e) {
|
|
var t2, n2 = this.mapping[this.data.hand].buttons[e.detail.id];
|
|
n2 && (n2 === "trigger" && (t2 = e.detail.state.value, console.log("analog value of trigger press: " + t2)), this.el.emit(n2 + "changed", e.detail.state));
|
|
}, onModelLoaded: function(e) {
|
|
e.target === this.el && this.data.model && (this.el.emit("controllermodelready", { name: "logitech-mx-ink-controls", model: this.data.model, rayOrigin: new Re.Vector3(0, 0, 0) }), this.controllerObject3D = this.el.getObject3D("mesh"), this.controllerObject3D.visible = this.el.sceneEl.is("vr-mode"));
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping.axes, e);
|
|
} }), Math.PI / 2);
|
|
bA = (cs("look-controls", { dependencies: ["position", "rotation"], schema: { enabled: { default: true }, magicWindowTrackingEnabled: { default: true }, pointerLockEnabled: { default: false }, reverseMouseDrag: { default: false }, reverseTouchDrag: { default: false }, touchEnabled: { default: true }, mouseEnabled: { default: true } }, init: function() {
|
|
this.deltaYaw = 0, this.previousHMDPosition = new Re.Vector3, this.hmdQuaternion = new Re.Quaternion, this.magicWindowAbsoluteEuler = new Re.Euler, this.magicWindowDeltaEuler = new Re.Euler, this.position = new Re.Vector3, this.magicWindowObject = new Re.Object3D, this.rotation = {}, this.deltaRotation = {}, this.savedPose = null, this.pointerLocked = false, this.setupMouseControls(), this.bindMethods(), this.previousMouseEvent = {}, this.setupMagicWindowControls(), this.savedPose = { position: new Re.Vector3, rotation: new Re.Euler }, (this.el.sceneEl.is("vr-mode") || this.el.sceneEl.is("ar-mode")) && this.onEnterVR();
|
|
}, setupMagicWindowControls: function() {
|
|
var e, t2 = this.data;
|
|
(Si() || Fi()) && (e = this.magicWindowControls = new ai(this.magicWindowObject), typeof DeviceOrientationEvent != "undefined" && DeviceOrientationEvent.requestPermission && (e.enabled = false, this.el.sceneEl.components["device-orientation-permission-ui"].permissionGranted ? e.enabled = t2.magicWindowTrackingEnabled : this.el.sceneEl.addEventListener("deviceorientationpermissiongranted", function() {
|
|
e.enabled = t2.magicWindowTrackingEnabled;
|
|
})));
|
|
}, update: function(e) {
|
|
var t2 = this.data;
|
|
t2.enabled !== e.enabled && this.updateGrabCursor(t2.enabled), e && !t2.magicWindowTrackingEnabled && e.magicWindowTrackingEnabled && (this.magicWindowAbsoluteEuler.set(0, 0, 0), this.magicWindowDeltaEuler.set(0, 0, 0)), this.magicWindowControls && (this.magicWindowControls.enabled = t2.magicWindowTrackingEnabled), e && !t2.pointerLockEnabled !== e.pointerLockEnabled && (this.removeEventListeners(), this.addEventListeners(), this.pointerLocked && this.exitPointerLock());
|
|
}, tick: function(e) {
|
|
this.data.enabled && this.updateOrientation();
|
|
}, play: function() {
|
|
this.addEventListeners();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.pointerLocked && this.exitPointerLock();
|
|
}, remove: function() {
|
|
this.removeEventListeners(), this.pointerLocked && this.exitPointerLock();
|
|
}, bindMethods: function() {
|
|
this.onMouseDown = this.onMouseDown.bind(this), this.onMouseMove = this.onMouseMove.bind(this), this.onMouseUp = this.onMouseUp.bind(this), this.onTouchStart = this.onTouchStart.bind(this), this.onTouchMove = this.onTouchMove.bind(this), this.onTouchEnd = this.onTouchEnd.bind(this), this.onEnterVR = this.onEnterVR.bind(this), this.onExitVR = this.onExitVR.bind(this), this.onPointerLockChange = this.onPointerLockChange.bind(this), this.onPointerLockError = this.onPointerLockError.bind(this);
|
|
}, setupMouseControls: function() {
|
|
this.mouseDown = false, this.pitchObject = new Re.Object3D, this.yawObject = new Re.Object3D, this.yawObject.position.y = 10, this.yawObject.add(this.pitchObject);
|
|
}, addEventListeners: function() {
|
|
var e = this.el.sceneEl, t2 = e.canvas;
|
|
t2 ? (t2.addEventListener("mousedown", this.onMouseDown, false), window.addEventListener("mousemove", this.onMouseMove, false), window.addEventListener("mouseup", this.onMouseUp, false), t2.addEventListener("touchstart", this.onTouchStart, { passive: true }), window.addEventListener("touchmove", this.onTouchMove, { passive: true }), window.addEventListener("touchend", this.onTouchEnd, { passive: true }), e.addEventListener("enter-vr", this.onEnterVR), e.addEventListener("exit-vr", this.onExitVR), this.data.pointerLockEnabled && (document.addEventListener("pointerlockchange", this.onPointerLockChange, false), document.addEventListener("mozpointerlockchange", this.onPointerLockChange, false), document.addEventListener("pointerlockerror", this.onPointerLockError, false))) : e.addEventListener("render-target-loaded", this.addEventListeners.bind(this));
|
|
}, removeEventListeners: function() {
|
|
var e = this.el.sceneEl, t2 = e && e.canvas;
|
|
t2 && (t2.removeEventListener("mousedown", this.onMouseDown), window.removeEventListener("mousemove", this.onMouseMove), window.removeEventListener("mouseup", this.onMouseUp), t2.removeEventListener("touchstart", this.onTouchStart), window.removeEventListener("touchmove", this.onTouchMove), window.removeEventListener("touchend", this.onTouchEnd), e.removeEventListener("enter-vr", this.onEnterVR), e.removeEventListener("exit-vr", this.onExitVR), document.removeEventListener("pointerlockchange", this.onPointerLockChange, false), document.removeEventListener("mozpointerlockchange", this.onPointerLockChange, false), document.removeEventListener("pointerlockerror", this.onPointerLockError, false));
|
|
}, updateOrientation: function() {
|
|
var e = this.el.object3D, t2 = this.pitchObject, n2 = this.yawObject, i2 = this.el.sceneEl;
|
|
(i2.is("vr-mode") || i2.is("ar-mode")) && i2.checkHeadsetConnected() || (this.updateMagicWindowOrientation(), e.rotation.x = this.magicWindowDeltaEuler.x + t2.rotation.x, e.rotation.y = this.magicWindowDeltaEuler.y + n2.rotation.y, e.rotation.z = this.magicWindowDeltaEuler.z);
|
|
}, updateMagicWindowOrientation: function() {
|
|
var e = this.magicWindowAbsoluteEuler, t2 = this.magicWindowDeltaEuler;
|
|
this.magicWindowControls && this.magicWindowControls.enabled && (this.magicWindowControls.update(), e.setFromQuaternion(this.magicWindowObject.quaternion, "YXZ"), this.previousMagicWindowYaw || e.y === 0 || (this.previousMagicWindowYaw = e.y), this.previousMagicWindowYaw && (t2.x = e.x, t2.y += e.y - this.previousMagicWindowYaw, t2.z = e.z, this.previousMagicWindowYaw = e.y));
|
|
}, onMouseMove: function(e) {
|
|
var t2, n2, i2, r2 = this.pitchObject, o2 = this.previousMouseEvent, s2 = this.yawObject;
|
|
this.data.enabled && (this.mouseDown || this.pointerLocked) && (this.pointerLocked ? (n2 = e.movementX || e.mozMovementX || 0, i2 = e.movementY || e.mozMovementY || 0) : (n2 = e.screenX - o2.screenX, i2 = e.screenY - o2.screenY), this.previousMouseEvent.screenX = e.screenX, this.previousMouseEvent.screenY = e.screenY, t2 = this.data.reverseMouseDrag ? 1 : -1, s2.rotation.y += 0.002 * n2 * t2, r2.rotation.x += 0.002 * i2 * t2, r2.rotation.x = Math.max(-BA, Math.min(BA, r2.rotation.x)));
|
|
}, onMouseDown: function(e) {
|
|
var t2 = this.el.sceneEl;
|
|
if (this.data.enabled && this.data.mouseEnabled && (!t2.is("vr-mode") && !t2.is("ar-mode") || !t2.checkHeadsetConnected()) && e.button === 0) {
|
|
var n2 = t2 && t2.canvas;
|
|
this.mouseDown = true, this.previousMouseEvent.screenX = e.screenX, this.previousMouseEvent.screenY = e.screenY, this.showGrabbingCursor(), this.data.pointerLockEnabled && !this.pointerLocked && (n2.requestPointerLock ? n2.requestPointerLock() : n2.mozRequestPointerLock && n2.mozRequestPointerLock());
|
|
}
|
|
}, showGrabbingCursor: function() {
|
|
this.el.sceneEl.canvas.style.cursor = "grabbing";
|
|
}, hideGrabbingCursor: function() {
|
|
this.el.sceneEl.canvas.style.cursor = "";
|
|
}, onMouseUp: function() {
|
|
this.mouseDown = false, this.hideGrabbingCursor();
|
|
}, onTouchStart: function(e) {
|
|
e.touches.length !== 1 || !this.data.touchEnabled || this.el.sceneEl.is("vr-mode") || this.el.sceneEl.is("ar-mode") || (this.touchStart = { x: e.touches[0].pageX, y: e.touches[0].pageY }, this.touchStarted = true);
|
|
}, onTouchMove: function(e) {
|
|
var t2, n2, i2 = this.el.sceneEl.canvas, r2 = this.yawObject;
|
|
this.touchStarted && this.data.touchEnabled && (n2 = 2 * Math.PI * (e.touches[0].pageX - this.touchStart.x) / i2.clientWidth, t2 = this.data.reverseTouchDrag ? 1 : -1, r2.rotation.y -= 0.5 * n2 * t2, this.touchStart = { x: e.touches[0].pageX, y: e.touches[0].pageY });
|
|
}, onTouchEnd: function() {
|
|
this.touchStarted = false;
|
|
}, onEnterVR: function() {
|
|
var e = this.el.sceneEl;
|
|
e.checkHeadsetConnected() && (this.saveCameraPose(), this.el.object3D.position.set(0, 0, 0), this.el.object3D.rotation.set(0, 0, 0), e.hasWebXR && (this.el.object3D.matrixAutoUpdate = false, this.el.object3D.updateMatrix()));
|
|
}, onExitVR: function() {
|
|
this.el.sceneEl.checkHeadsetConnected() && (this.restoreCameraPose(), this.previousHMDPosition.set(0, 0, 0), this.el.object3D.matrixAutoUpdate = true);
|
|
}, onPointerLockChange: function() {
|
|
this.pointerLocked = !(!document.pointerLockElement && !document.mozPointerLockElement);
|
|
}, onPointerLockError: function() {
|
|
this.pointerLocked = false;
|
|
}, exitPointerLock: function() {
|
|
document.exitPointerLock(), this.pointerLocked = false;
|
|
}, updateGrabCursor: function(e) {
|
|
var t2 = this.el.sceneEl;
|
|
function n2() {
|
|
t2.canvas.classList.add("a-grab-cursor");
|
|
}
|
|
function i2() {
|
|
t2.canvas.classList.remove("a-grab-cursor");
|
|
}
|
|
t2.canvas ? e ? n2() : i2() : e ? t2.addEventListener("render-target-loaded", n2) : t2.addEventListener("render-target-loaded", i2);
|
|
}, saveCameraPose: function() {
|
|
var e = this.el;
|
|
this.savedPose.position.copy(e.object3D.position), this.savedPose.rotation.copy(e.object3D.rotation), this.hasSavedPose = true;
|
|
}, restoreCameraPose: function() {
|
|
var e = this.el, t2 = this.savedPose;
|
|
this.hasSavedPose && (e.object3D.position.copy(t2.position), e.object3D.rotation.copy(t2.rotation), this.hasSavedPose = false);
|
|
} }), "magicleap-one");
|
|
yA = ci + "controllers/magicleap/magicleap-one-controller.glb";
|
|
IA = (cs("magicleap-controls", { schema: { hand: { default: "none" }, model: { default: true } }, mapping: { axes: { touchpad: [0, 1] }, buttons: ["trigger", "grip", "touchpad", "menu"] }, init: function() {
|
|
var e = this;
|
|
this.controllerPresent = false, this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e);
|
|
}, this.previousButtonValues = {}, this.bindMethods();
|
|
}, update: function() {
|
|
var e = this.data;
|
|
this.controllerIndex = e.hand === "right" ? 0 : e.hand === "left" ? 1 : 2;
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, bindMethods: function() {
|
|
this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("axismove", this.onAxisMoved), e.addEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("axismove", this.onAxisMoved), e.removeEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.data;
|
|
Ur(this, bA, { index: this.controllerIndex, hand: e.hand });
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data;
|
|
e.setAttribute("tracked-controls", { idPrefix: bA, hand: t2.hand, controller: this.controllerIndex }), this.data.model && this.el.setAttribute("gltf-model", yA);
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onButtonChanged: function(e) {
|
|
var t2, n2 = this.mapping.buttons[e.detail.id];
|
|
n2 && (n2 === "trigger" && (t2 = e.detail.state.value, console.log("analog value of trigger press: " + t2)), this.el.emit(n2 + "changed", e.detail.state));
|
|
}, onModelLoaded: function(e) {
|
|
e.detail.model.scale.set(0.01, 0.01, 0.01);
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping.axes, e);
|
|
}, updateModel: function(e, t2) {}, setButtonColor: function(e, t2) {} }), fi("components:material:error"));
|
|
cs("material", { schema: { alphaTest: { default: 0, min: 0, max: 1 }, depthTest: { default: true }, depthWrite: { default: true }, flatShading: { default: false }, npot: { default: false }, offset: { type: "vec2", default: { x: 0, y: 0 } }, opacity: { default: 1, min: 0, max: 1 }, repeat: { type: "vec2", default: { x: 1, y: 1 } }, shader: { default: "standard", oneOf: ea, schemaChange: true }, side: { default: "front", oneOf: ["front", "back", "double"] }, transparent: { default: false }, vertexColorsEnabled: { default: false }, visible: { default: true }, blending: { default: "normal", oneOf: ["none", "normal", "additive", "subtractive", "multiply"] }, dithering: { default: true }, anisotropy: { default: 0, min: 0 } }, init: function() {
|
|
this.material = null;
|
|
}, update: function(e) {
|
|
var t2 = this.data;
|
|
this.shader && t2.shader === e.shader || this.updateShader(t2.shader), this.shader.update(this.data), this.updateMaterial(e);
|
|
}, updateSchema: function(e) {
|
|
var t2, n2, i2, r2;
|
|
n2 = e && e.shader, t2 = this.oldData && this.oldData.shader, (i2 = $s[r2 = n2 || t2] && $s[r2].schema) || IA("Unknown shader schema " + r2), t2 && n2 === t2 || (this.extendSchema(i2), this.updateBehavior());
|
|
}, updateBehavior: function() {
|
|
var e, t2, n2 = this.el.sceneEl, i2 = this.schema, r2 = this;
|
|
function o2(e2, n3) {
|
|
var i3;
|
|
for (i3 in t2)
|
|
t2[i3] = e2;
|
|
r2.shader.update(t2);
|
|
}
|
|
for (e in this.tick = undefined, t2 = {}, i2)
|
|
i2[e].type === "time" && (this.tick = o2, t2[e] = true);
|
|
n2 && (this.tick ? n2.addBehavior(this) : n2.removeBehavior(this));
|
|
}, updateShader: function(e) {
|
|
var t2, n2 = this.data, i2 = $s[e] && $s[e].Shader;
|
|
if (!i2)
|
|
throw new Error("Unknown shader " + e);
|
|
(t2 = this.shader = new i2).el = this.el, t2.init(n2), this.setMaterial(t2.material), this.updateSchema(n2);
|
|
}, updateMaterial: function(e) {
|
|
var t2, n2 = this.data, i2 = this.material;
|
|
for (t2 in i2.alphaTest = n2.alphaTest, i2.depthTest = n2.depthTest !== false, i2.depthWrite = n2.depthWrite !== false, i2.opacity = n2.opacity, i2.flatShading = n2.flatShading, i2.side = function(e2) {
|
|
switch (e2) {
|
|
case "back":
|
|
return Re.BackSide;
|
|
case "double":
|
|
return Re.DoubleSide;
|
|
default:
|
|
return Re.FrontSide;
|
|
}
|
|
}(n2.side), i2.transparent = n2.transparent !== false || n2.opacity < 1, i2.vertexColors = n2.vertexColorsEnabled, i2.visible = n2.visible, i2.blending = function(e2) {
|
|
switch (e2) {
|
|
case "none":
|
|
return Re.NoBlending;
|
|
case "additive":
|
|
return Re.AdditiveBlending;
|
|
case "subtractive":
|
|
return Re.SubtractiveBlending;
|
|
case "multiply":
|
|
return Re.MultiplyBlending;
|
|
default:
|
|
return Re.NormalBlending;
|
|
}
|
|
}(n2.blending), i2.dithering = n2.dithering, e)
|
|
break;
|
|
!t2 || e.alphaTest === n2.alphaTest && e.side === n2.side && e.vertexColorsEnabled === n2.vertexColorsEnabled || (i2.needsUpdate = true);
|
|
}, remove: function() {
|
|
var e = new Re.MeshBasicMaterial, t2 = this.material, n2 = this.el.getObject3D("mesh");
|
|
n2 && (n2.material = e), wA(t2, this.system);
|
|
}, setMaterial: function(e) {
|
|
var t2, n2 = this.el, i2 = this.system;
|
|
this.material && wA(this.material, i2), this.material = e, i2.registerMaterial(e), (t2 = n2.getObject3D("mesh")) ? t2.material = e : n2.addEventListener("object3dset", function t(i3) {
|
|
i3.detail.type === "mesh" && i3.target === n2 && (n2.getObject3D("mesh").material = e, n2.removeEventListener("object3dset", t));
|
|
});
|
|
} });
|
|
kA = ci + "controllers/oculus/oculus-touch-controller-";
|
|
TA = ci + "controllers/meta/";
|
|
RA = { left: { modelUrl: kA + "left.gltf", rayOrigin: { origin: { x: 0.002, y: -0.005, z: -0.03 }, direction: { x: 0, y: -0.8, z: -1 } }, modelPivotOffset: new Re.Vector3(-0.005, 0.036, -0.037), modelPivotRotation: new Re.Euler(Math.PI / 4.5, 0, 0) }, right: { modelUrl: kA + "right.gltf", rayOrigin: { origin: { x: -0.002, y: -0.005, z: -0.03 }, direction: { x: 0, y: -0.8, z: -1 } }, modelPivotOffset: new Re.Vector3(0.005, 0.036, -0.037), modelPivotRotation: new Re.Euler(Math.PI / 4.5, 0, 0) } };
|
|
UA = { "oculus-touch": RA, "oculus-touch-v2": { left: { modelUrl: kA + "gen2-left.gltf", rayOrigin: { origin: { x: -0.006, y: -0.03, z: -0.04 }, direction: { x: 0, y: -0.9, z: -1 } }, modelPivotOffset: new Re.Vector3(0, -0.007, -0.021), modelPivotRotation: new Re.Euler(-Math.PI / 4, 0, 0) }, right: { modelUrl: kA + "gen2-right.gltf", rayOrigin: { origin: { x: 0.006, y: -0.03, z: -0.04 }, direction: { x: 0, y: -0.9, z: -1 } }, modelPivotOffset: new Re.Vector3(0, -0.007, -0.021), modelPivotRotation: new Re.Euler(-Math.PI / 4, 0, 0) } }, "oculus-touch-v3": { left: { modelUrl: kA + "v3-left.glb", rayOrigin: { origin: { x: 0.0065, y: -0.0186, z: -0.05 }, direction: { x: 0.12394785839500175, y: -0.5944043672340157, z: -0.7945567170519814 } }, modelPivotOffset: new Re.Vector3(0, 0, 0), modelPivotRotation: new Re.Euler(0, 0, 0) }, right: { modelUrl: kA + "v3-right.glb", rayOrigin: { origin: { x: -0.0065, y: -0.0186, z: -0.05 }, direction: { x: -0.12394785839500175, y: -0.5944043672340157, z: -0.7945567170519814 } }, modelPivotOffset: new Re.Vector3(0, 0, 0), modelPivotRotation: new Re.Euler(0, 0, 0) } }, "meta-quest-touch-pro": { left: { modelUrl: TA + "quest-touch-pro-left.glb", rayOrigin: { origin: { x: 0.0065, y: -0.0186, z: -0.05 }, direction: { x: 0.12394785839500175, y: -0.5944043672340157, z: -0.7945567170519814 } }, modelPivotOffset: new Re.Vector3(0, 0, 0), modelPivotRotation: new Re.Euler(0, 0, 0) }, right: { modelUrl: TA + "quest-touch-pro-right.glb", rayOrigin: { origin: { x: -0.0065, y: -0.0186, z: -0.05 }, direction: { x: -0.12394785839500175, y: -0.5944043672340157, z: -0.7945567170519814 } }, modelPivotOffset: new Re.Vector3(0, 0, 0), modelPivotRotation: new Re.Euler(0, 0, 0) } }, "meta-quest-touch-plus": { left: { modelUrl: TA + "quest-touch-plus-left.glb", rayOrigin: { origin: { x: 0.0065, y: -0.0186, z: -0.05 }, direction: { x: 0.12394785839500175, y: -0.5944043672340157, z: -0.7945567170519814 } }, modelPivotOffset: new Re.Vector3(0, 0, 0), modelPivotRotation: new Re.Euler(0, 0, 0) }, right: { modelUrl: TA + "quest-touch-plus-right.glb", rayOrigin: { origin: { x: -0.0065, y: -0.0186, z: -0.05 }, direction: { x: -0.12394785839500175, y: -0.5944043672340157, z: -0.7945567170519814 } }, modelPivotOffset: new Re.Vector3(0, 0, 0), modelPivotRotation: new Re.Euler(0, 0, 0) } } };
|
|
OA = { schema: { hand: { default: "left" }, buttonColor: { type: "color", default: "#999" }, buttonTouchColor: { type: "color", default: "#8AB" }, buttonHighlightColor: { type: "color", default: "#2DF" }, model: { default: true }, controllerType: { default: "auto", oneOf: ["auto", "oculus-touch", "oculus-touch-v2", "oculus-touch-v3"] } }, after: ["tracked-controls"], mapping: { left: { axes: { thumbstick: [2, 3] }, buttons: ["trigger", "grip", "none", "thumbstick", "xbutton", "ybutton", "surface"] }, right: { axes: { thumbstick: [2, 3] }, buttons: ["trigger", "grip", "none", "thumbstick", "abutton", "bbutton", "surface"] } }, bindMethods: function() {
|
|
this.onButtonChanged = this.onButtonChanged.bind(this), this.onThumbstickMoved = this.onThumbstickMoved.bind(this), this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, init: function() {
|
|
var e = this;
|
|
this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e, e.data.hand);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e, e.data.hand);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e, e.data.hand);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e, e.data.hand);
|
|
}, this.controllerPresent = false, this.previousButtonValues = {}, this.bindMethods(), this.triggerEuler = new Re.Euler;
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("axismove", this.onAxisMoved), e.addEventListener("model-loaded", this.onModelLoaded), e.addEventListener("thumbstickmoved", this.onThumbstickMoved), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("axismove", this.onAxisMoved), e.removeEventListener("model-loaded", this.onModelLoaded), e.removeEventListener("thumbstickmoved", this.onThumbstickMoved), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.controllerObject3D;
|
|
e && (e.visible = false), Ur(this, DA, { hand: this.data.hand, iterateControllerProfiles: true });
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, loadModel: function(e) {
|
|
var t2, n2 = this.data;
|
|
if (n2.model) {
|
|
if (this.controllerObject3D)
|
|
return this.controllerObject3D.visible = true, void this.el.setObject3D("mesh", this.controllerObject3D);
|
|
if (this.displayModel = UA[n2.controllerType] || UA[FA], n2.controllerType === "auto") {
|
|
t2 = FA;
|
|
for (var i2 = Object.keys(UA), r2 = 0;r2 < e.profiles.length; r2++)
|
|
if (i2.indexOf(e.profiles[r2]) !== -1) {
|
|
t2 = e.profiles[r2];
|
|
break;
|
|
}
|
|
this.displayModel = UA[t2];
|
|
}
|
|
var o2 = this.displayModel[n2.hand].modelUrl;
|
|
this.isTouchV3orPROorPlus = this.displayModel === UA["oculus-touch-v3"] || this.displayModel === UA["meta-quest-touch-pro"] || this.displayModel === UA["meta-quest-touch-plus"], this.el.setAttribute("gltf-model", o2);
|
|
}
|
|
}, injectTrackedControls: function(e) {
|
|
var t2 = this.data, n2 = DA;
|
|
this.el.setAttribute("tracked-controls", { id: n2, hand: t2.hand, handTrackingEnabled: false, iterateControllerProfiles: true }), this.loadModel(e);
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onButtonChanged: function(e) {
|
|
var t2 = this.mapping[this.data.hand].buttons[e.detail.id];
|
|
if (t2) {
|
|
if (this.isTouchV3orPROorPlus)
|
|
this.onButtonChangedV3orPROorPlus(e);
|
|
else {
|
|
var n2, i2 = this.buttonMeshes;
|
|
t2 !== "trigger" && t2 !== "grip" || (n2 = e.detail.state.value), i2 && (t2 === "trigger" && i2.trigger && (i2.trigger.rotation.x = this.originalXRotationTrigger - n2 * (Math.PI / 26)), t2 === "grip" && i2.grip && (n2 *= this.data.hand === "left" ? -1 : 1, i2.grip.position.x = this.originalXPositionGrip + 0.004 * n2));
|
|
}
|
|
this.el.emit(t2 + "changed", e.detail.state);
|
|
}
|
|
}, onButtonChangedV3orPROorPlus: function(e) {
|
|
var t2, n2 = this.mapping[this.data.hand].buttons[e.detail.id], i2 = this.buttonObjects;
|
|
i2 && i2[n2] && (t2 = e.detail.state.value, i2[n2].quaternion.slerpQuaternions(this.buttonRanges[n2].min.quaternion, this.buttonRanges[n2].max.quaternion, t2), i2[n2].position.lerpVectors(this.buttonRanges[n2].min.position, this.buttonRanges[n2].max.position, t2));
|
|
}, onModelLoaded: function(e) {
|
|
if (e.target === this.el && this.data.model) {
|
|
if (this.isTouchV3orPROorPlus)
|
|
this.onTouchV3orPROorPlusModelLoaded(e);
|
|
else {
|
|
var t2, n2 = this.controllerObject3D = e.detail.model;
|
|
(t2 = this.buttonMeshes = {}).grip = n2.getObjectByName("buttonHand"), this.originalXPositionGrip = t2.grip && t2.grip.position.x, t2.trigger = n2.getObjectByName("buttonTrigger"), this.originalXRotationTrigger = t2.trigger && t2.trigger.rotation.x, t2.thumbstick = n2.getObjectByName("stick"), t2.xbutton = n2.getObjectByName("buttonX"), t2.abutton = n2.getObjectByName("buttonA"), t2.ybutton = n2.getObjectByName("buttonY"), t2.bbutton = n2.getObjectByName("buttonB");
|
|
}
|
|
for (var i2 in this.buttonMeshes)
|
|
this.buttonMeshes[i2] && PA(this.buttonMeshes[i2]);
|
|
this.applyOffset(e.detail.model), this.el.emit("controllermodelready", { name: "meta-touch-controls", model: this.data.model, rayOrigin: this.displayModel[this.data.hand].rayOrigin });
|
|
}
|
|
}, applyOffset: function(e) {
|
|
e.position.copy(this.displayModel[this.data.hand].modelPivotOffset), e.rotation.copy(this.displayModel[this.data.hand].modelPivotRotation);
|
|
}, onTouchV3orPROorPlusModelLoaded: function(e) {
|
|
var t2 = this.controllerObject3D = e.detail.model, n2 = this.buttonObjects = {}, i2 = this.buttonMeshes = {}, r2 = this.buttonRanges = {};
|
|
i2.grip = t2.getObjectByName("squeeze"), n2.grip = t2.getObjectByName("xr_standard_squeeze_pressed_value"), r2.grip = { min: t2.getObjectByName("xr_standard_squeeze_pressed_min"), max: t2.getObjectByName("xr_standard_squeeze_pressed_max") }, n2.grip.minX = n2.grip.position.x, i2.thumbstick = t2.getObjectByName("thumbstick"), n2.thumbstick = t2.getObjectByName("xr_standard_thumbstick_pressed_value"), r2.thumbstick = { min: t2.getObjectByName("xr_standard_thumbstick_pressed_min"), max: t2.getObjectByName("xr_standard_thumbstick_pressed_max") }, n2.thumbstickXAxis = t2.getObjectByName("xr_standard_thumbstick_xaxis_pressed_value"), r2.thumbstickXAxis = { min: t2.getObjectByName("xr_standard_thumbstick_xaxis_pressed_min"), max: t2.getObjectByName("xr_standard_thumbstick_xaxis_pressed_max") }, n2.thumbstickYAxis = t2.getObjectByName("xr_standard_thumbstick_yaxis_pressed_value"), r2.thumbstickYAxis = { min: t2.getObjectByName("xr_standard_thumbstick_yaxis_pressed_min"), max: t2.getObjectByName("xr_standard_thumbstick_yaxis_pressed_max") }, i2.trigger = t2.getObjectByName("trigger"), n2.trigger = t2.getObjectByName("xr_standard_trigger_pressed_value"), r2.trigger = { min: t2.getObjectByName("xr_standard_trigger_pressed_min"), max: t2.getObjectByName("xr_standard_trigger_pressed_max") }, r2.trigger.diff = { x: Math.abs(r2.trigger.max.rotation.x) - Math.abs(r2.trigger.min.rotation.x), y: Math.abs(r2.trigger.max.rotation.y) - Math.abs(r2.trigger.min.rotation.y), z: Math.abs(r2.trigger.max.rotation.z) - Math.abs(r2.trigger.min.rotation.z) };
|
|
var o2 = this.data.hand === "left" ? "x" : "a", s2 = this.data.hand === "left" ? "y" : "b", a2 = o2 + "button", A2 = s2 + "button";
|
|
i2[a2] = t2.getObjectByName(o2 + "_button"), n2[a2] = t2.getObjectByName(o2 + "_button_pressed_value"), r2[a2] = { min: t2.getObjectByName(o2 + "_button_pressed_min"), max: t2.getObjectByName(o2 + "_button_pressed_max") }, i2[A2] = t2.getObjectByName(s2 + "_button"), n2[A2] = t2.getObjectByName(s2 + "_button_pressed_value"), r2[A2] = { min: t2.getObjectByName(s2 + "_button_pressed_min"), max: t2.getObjectByName(s2 + "_button_pressed_max") };
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping[this.data.hand].axes, e);
|
|
}, onThumbstickMoved: function(e) {
|
|
if (this.buttonMeshes && this.buttonMeshes.thumbstick)
|
|
if (this.isTouchV3orPROorPlus)
|
|
this.updateThumbstickTouchV3orPROorPlus(e);
|
|
else
|
|
for (var t2 in e.detail)
|
|
this.buttonObjects.thumbstick.rotation[this.axisMap[t2]] = this.buttonRanges.thumbstick.originalRotation[this.axisMap[t2]] - Math.PI / 8 * e.detail[t2] * (t2 === "y" || this.data.hand === "right" ? -1 : 1);
|
|
}, axisMap: { y: "x", x: "z" }, updateThumbstickTouchV3orPROorPlus: function(e) {
|
|
var t2 = (e.detail.x + 1) / 2;
|
|
this.buttonObjects.thumbstickXAxis.quaternion.slerpQuaternions(this.buttonRanges.thumbstickXAxis.min.quaternion, this.buttonRanges.thumbstickXAxis.max.quaternion, t2);
|
|
var n2 = (e.detail.y + 1) / 2;
|
|
this.buttonObjects.thumbstickYAxis.quaternion.slerpQuaternions(this.buttonRanges.thumbstickYAxis.min.quaternion, this.buttonRanges.thumbstickYAxis.max.quaternion, n2);
|
|
}, updateModel: function(e, t2) {
|
|
this.data.model && this.updateButtonModel(e, t2);
|
|
}, updateButtonModel: function(e, t2) {
|
|
var n2, i2 = this.buttonMeshes;
|
|
i2 && i2[e] && (n2 = t2 === "up" || t2 === "touchend" ? i2[e].originalColor || this.data.buttonColor : t2 === "touchstart" ? this.data.buttonTouchColor : this.data.buttonHighlightColor, i2[e].material.color.set(n2));
|
|
} };
|
|
cs("oculus-touch-controls", OA), cs("meta-touch-controls", OA), cs("obb-collider", { schema: { size: { default: 0 }, trackedObject3D: { default: "" }, minimumColliderDimension: { default: 0.02 }, centerModel: { default: false } }, init: function() {
|
|
this.previousScale = new Re.Vector3().copy(this.el.object3D.scale), this.auxEuler = new Re.Euler, this.boundingBox = new Re.Box3, this.boundingBoxSize = new Re.Vector3, this.updateCollider = this.updateCollider.bind(this), this.onModelLoaded = this.onModelLoaded.bind(this), this.updateBoundingBox = this.updateBoundingBox.bind(this), this.el.addEventListener("model-loaded", this.onModelLoaded), this.updateCollider(), this.system.addCollider(this.el);
|
|
}, remove: function() {
|
|
this.system.removeCollider(this.el);
|
|
}, update: function() {
|
|
this.data.trackedObject3D && (this.trackedObject3DPath = this.data.trackedObject3D.split("."));
|
|
}, onModelLoaded: function() {
|
|
this.data.centerModel && this.centerModel(), this.updateCollider();
|
|
}, centerModel: function() {
|
|
var e, t2 = this.el, n2 = t2.components["gltf-model"] && t2.components["gltf-model"].model;
|
|
n2 && (this.el.removeObject3D("mesh"), e = new Re.Box3().setFromObject(n2).getCenter(new Re.Vector3), n2.position.x += n2.position.x - e.x, n2.position.y += n2.position.y - e.y, n2.position.z += n2.position.z - e.z, this.el.setObject3D("mesh", n2));
|
|
}, updateCollider: function() {
|
|
var e = this.el, t2 = this.boundingBoxSize, n2 = this.aabb = this.aabb || new _n;
|
|
this.obb = this.obb || new _n, e.hasLoaded ? (this.updateBoundingBox(), n2.halfSize.copy(t2).multiplyScalar(0.5), this.el.sceneEl.systems["obb-collider"].data.showColliders && this.showCollider()) : e.addEventListener("loaded", this.updateCollider);
|
|
}, showCollider: function() {
|
|
this.updateColliderMesh(), this.renderColliderMesh.visible = true;
|
|
}, updateColliderMesh: function() {
|
|
var e = this.renderColliderMesh, t2 = this.boundingBoxSize;
|
|
e ? (e.geometry.dispose(), e.geometry = new Re.BoxGeometry(t2.x, t2.y, t2.z)) : this.initColliderMesh();
|
|
}, hideCollider: function() {
|
|
this.renderColliderMesh && (this.renderColliderMesh.visible = false);
|
|
}, initColliderMesh: function() {
|
|
var e, t2, n2;
|
|
e = this.boundingBoxSize, t2 = this.renderColliderGeometry = new Re.BoxGeometry(e.x, e.y, e.z), (n2 = this.renderColliderMesh = new Re.Mesh(t2, new Re.MeshLambertMaterial({ color: 65280, side: Re.DoubleSide }))).matrixAutoUpdate = false, n2.matrixWorldAutoUpdate = false, n2.updateMatrixWorld = function() {}, this.el.sceneEl.object3D.add(n2);
|
|
}, updateBoundingBox: (xA = new Re.Vector3, QA = new Re.Vector3, LA = new Re.Quaternion, MA = new Re.Quaternion, SA = new Re.Matrix4, function() {
|
|
var e = this.auxEuler, t2 = this.boundingBox, n2 = this.data.size, i2 = this.trackedObject3D || this.el.object3D, r2 = this.boundingBoxSize, o2 = this.data.minimumColliderDimension;
|
|
if (n2)
|
|
return this.boundingBoxSize.x = n2, this.boundingBoxSize.y = n2, void (this.boundingBoxSize.z = n2);
|
|
e.copy(i2.rotation), i2.rotation.set(0, 0, 0), i2.parent.matrixWorld.decompose(xA, LA, QA), SA.compose(xA, MA, QA), i2.parent.matrixWorld.copy(SA), t2.setFromObject(i2, true), t2.getSize(r2), r2.x = r2.x < o2 ? o2 : r2.x, r2.y = r2.y < o2 ? o2 : r2.y, r2.z = r2.z < o2 ? o2 : r2.z, i2.parent.matrixWorld.compose(xA, LA, QA), this.el.object3D.rotation.copy(e);
|
|
}), checkTrackedObject: function() {
|
|
var e, t2 = this.trackedObject3DPath;
|
|
if (t2 && t2.length && !this.trackedObject3D) {
|
|
e = this.el;
|
|
for (var n2 = 0;n2 < t2.length && (e = e[t2[n2]]); n2++)
|
|
;
|
|
e && (this.trackedObject3D = e, this.updateCollider());
|
|
}
|
|
return this.trackedObject3D;
|
|
}, tick: function() {
|
|
var e = new Re.Vector3, t2 = new Re.Vector3, n2 = new Re.Quaternion, i2 = new Re.Matrix4;
|
|
return function() {
|
|
var r2 = this.obb, o2 = this.renderColliderMesh, s2 = this.checkTrackedObject() || this.el.object3D;
|
|
s2 && (s2.updateMatrix(), s2.updateMatrixWorld(true), s2.matrixWorld.decompose(e, n2, t2), (Math.abs(t2.x - this.previousScale.x) > 0.0001 || Math.abs(t2.y - this.previousScale.y) > 0.0001 || Math.abs(t2.z - this.previousScale.z) > 0.0001) && this.updateCollider(), this.previousScale.copy(t2), t2.set(1, 1, 1), i2.compose(e, n2, t2), o2 && o2.matrixWorld.copy(i2), r2.copy(this.aabb), r2.applyMatrix4(i2));
|
|
};
|
|
}() });
|
|
GA = fi("components:obj-model:warn");
|
|
NA = (cs("obj-model", { schema: { mtl: { type: "model" }, obj: { type: "model" } }, init: function() {
|
|
var e = this;
|
|
this.model = null, this.objLoader = new ni, this.mtlLoader = new ii(this.objLoader.manager), this.mtlLoader.crossOrigin = "", this.el.addEventListener("componentinitialized", function(t2) {
|
|
e.model && t2.detail.name === "material" && e.applyMaterial();
|
|
});
|
|
}, update: function() {
|
|
var e = this.data;
|
|
e.obj && (this.resetMesh(), this.loadObj(e.obj, e.mtl));
|
|
}, remove: function() {
|
|
this.resetMesh();
|
|
}, resetMesh: function() {
|
|
this.model && this.el.removeObject3D("mesh");
|
|
}, loadObj: function(e, t2) {
|
|
var n2 = this, i2 = this.el, r2 = this.mtlLoader, o2 = this.objLoader, s2 = this.el.sceneEl.systems.renderer, a2 = t2.substr(0, t2.lastIndexOf("/") + 1);
|
|
if (t2)
|
|
return i2.hasAttribute("material") && GA("Material component properties are ignored when a .MTL is provided"), r2.setResourcePath(a2), void r2.load(t2, function(t3) {
|
|
t3.preload(), o2.setMaterials(t3), o2.load(e, function(e2) {
|
|
n2.model = e2, n2.model.traverse(function(e3) {
|
|
if (e3.isMesh) {
|
|
var t4 = e3.material;
|
|
t4.map && s2.applyColorCorrection(t4.map), t4.emissiveMap && s2.applyColorCorrection(t4.emissiveMap);
|
|
}
|
|
}), i2.setObject3D("mesh", e2), i2.emit("model-loaded", { format: "obj", model: e2 });
|
|
});
|
|
});
|
|
o2.load(e, function(e2) {
|
|
n2.model = e2, n2.applyMaterial(), i2.setObject3D("mesh", e2), i2.emit("model-loaded", { format: "obj", model: e2 });
|
|
});
|
|
}, applyMaterial: function() {
|
|
var e = this.el.components.material;
|
|
e && this.model.traverse(function(t2) {
|
|
t2 instanceof Re.Mesh && (t2.material = e.material);
|
|
});
|
|
} }), ci + "controllers/oculus/go/oculus-go-controller.gltf");
|
|
_A = (cs("oculus-go-controls", { schema: { hand: { default: "" }, buttonColor: { type: "color", default: "#FFFFFF" }, buttonTouchedColor: { type: "color", default: "#BBBBBB" }, buttonHighlightColor: { type: "color", default: "#7A7A7A" }, model: { default: true } }, mapping: { axes: { touchpad: [0, 1] }, buttons: ["trigger", "none", "touchpad"] }, bindMethods: function() {
|
|
this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, init: function() {
|
|
var e = this;
|
|
this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e);
|
|
}, this.controllerPresent = false, this.bindMethods();
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("model-loaded", this.onModelLoaded), e.addEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("model-loaded", this.onModelLoaded), e.removeEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
Ur(this, jA, this.data.hand ? { hand: this.data.hand } : {});
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data;
|
|
e.setAttribute("tracked-controls", { hand: t2.hand, idPrefix: jA }), this.data.model && this.el.setAttribute("gltf-model", NA);
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onModelLoaded: function(e) {
|
|
var t2, n2 = e.detail.model;
|
|
e.target === this.el && this.data.model && ((t2 = this.buttonMeshes = {}).trigger = n2.getObjectByName("oculus_go_button_trigger"), t2.trackpad = n2.getObjectByName("oculus_go_touchpad"), t2.touchpad = n2.getObjectByName("oculus_go_touchpad"));
|
|
}, onButtonChanged: function(e) {
|
|
var t2 = this.mapping.buttons[e.detail.id];
|
|
t2 && this.el.emit(t2 + "changed", e.detail.state);
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping.axes, e);
|
|
}, updateModel: function(e, t2) {
|
|
this.data.model && this.updateButtonModel(e, t2);
|
|
}, updateButtonModel: function(e, t2) {
|
|
var n2 = this.buttonMeshes;
|
|
if (n2 && n2[e]) {
|
|
var i2;
|
|
switch (t2) {
|
|
case "down":
|
|
i2 = this.data.buttonHighlightColor;
|
|
break;
|
|
case "touchstart":
|
|
i2 = this.data.buttonTouchedColor;
|
|
break;
|
|
default:
|
|
i2 = this.data.buttonColor;
|
|
}
|
|
n2[e].material.color.set(i2);
|
|
}
|
|
} }), "pico-4");
|
|
HA = ci + "controllers/pico/pico4/";
|
|
qA = (cs("pico-controls", { schema: { hand: { default: "none" }, model: { default: true } }, mapping: { left: { axes: { thumbstick: [2, 3] }, buttons: ["trigger", "grip", "none", "thumbstick", "xbutton", "ybutton"] }, right: { axes: { thumbstick: [2, 3] }, buttons: ["trigger", "grip", "none", "thumbstick", "abutton", "bbutton"] } }, init: function() {
|
|
var e = this;
|
|
this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e, e.data.hand);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e, e.data.hand);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e, e.data.hand);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e, e.data.hand);
|
|
}, this.bindMethods();
|
|
}, update: function() {
|
|
var e = this.data;
|
|
this.controllerIndex = e.hand === "right" ? 0 : e.hand === "left" ? 1 : 2;
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, bindMethods: function() {
|
|
this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("axismove", this.onAxisMoved), e.addEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("axismove", this.onAxisMoved), e.removeEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.data;
|
|
Ur(this, _A, { index: this.controllerIndex, hand: e.hand });
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data;
|
|
e.setAttribute("tracked-controls", { idPrefix: _A, hand: t2.hand, controller: this.controllerIndex }), this.data.model && this.el.setAttribute("gltf-model", HA + this.data.hand + ".glb");
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onButtonChanged: function(e) {
|
|
var t2, n2 = this.mapping[this.data.hand].buttons[e.detail.id];
|
|
n2 && (n2 === "trigger" && (t2 = e.detail.state.value, console.log("analog value of trigger press: " + t2)), this.el.emit(n2 + "changed", e.detail.state));
|
|
}, onModelLoaded: function(e) {
|
|
e.target === this.el && this.data.model && this.el.emit("controllermodelready", { name: "pico-controls", model: this.data.model, rayOrigin: new Re.Vector3(0, 0, 0) });
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping[this.data.hand].axes, e);
|
|
} }), cs("position", { schema: { type: "vec3" }, update: function() {
|
|
var e = this.el.object3D, t2 = this.data;
|
|
e.position.set(t2.x, t2.y, t2.z);
|
|
}, remove: function() {
|
|
this.el.object3D.position.set(0, 0, 0);
|
|
} }), fi("components:raycaster:warn"));
|
|
VA = /^[\w\s-.,[\]#]*$/;
|
|
zA = { childList: true, attributes: true, subtree: true };
|
|
cs("raycaster", { schema: { autoRefresh: { default: true }, direction: { type: "vec3", default: { x: 0, y: 0, z: -1 } }, enabled: { default: true }, far: { default: 1000 }, interval: { default: 0 }, near: { default: 0 }, objects: { default: "" }, origin: { type: "vec3" }, showLine: { default: false }, lineColor: { default: "white" }, lineOpacity: { default: 1 }, useWorldCoordinates: { default: false } }, multiple: true, init: function() {
|
|
this.clearedIntersectedEls = [], this.unitLineEndVec3 = new Re.Vector3, this.intersectedEls = [], this.intersections = [], this.newIntersectedEls = [], this.newIntersections = [], this.objects = [], this.prevCheckTime = undefined, this.prevIntersectedEls = [], this.rawIntersections = [], this.raycaster = new Re.Raycaster, this.updateOriginDirection(), this.setDirty = this.setDirty.bind(this), this.updateLine = this.updateLine.bind(this), this.observer = new MutationObserver(this.setDirty), this.dirty = true, this.lineEndVec3 = new Re.Vector3, this.otherLineEndVec3 = new Re.Vector3, this.lineData = { end: this.lineEndVec3 }, this.getIntersection = this.getIntersection.bind(this), this.intersectedDetail = { el: this.el, getIntersection: this.getIntersection }, this.intersectedClearedDetail = { el: this.el }, this.intersectionClearedDetail = { clearedEls: this.clearedIntersectedEls }, this.intersectionDetail = {};
|
|
}, update: function(e) {
|
|
var t2 = this.data, n2 = this.el, i2 = this.raycaster;
|
|
i2.far = t2.far, i2.near = t2.near, !t2.showLine || t2.far === e.far && t2.origin === e.origin && t2.direction === e.direction && e.showLine || (this.unitLineEndVec3.copy(t2.direction).normalize(), this.drawLine()), !t2.showLine && e.showLine && n2.removeAttribute("line"), t2.objects === e.objects || VA.test(t2.objects) || qA('[raycaster] Selector "' + t2.objects + '" may not update automatically with DOM changes.'), t2.objects || qA('[raycaster] For performance, please define raycaster.objects when using raycaster or cursor components to whitelist which entities to intersect with. e.g., raycaster="objects: [data-raycastable]".'), t2.autoRefresh !== e.autoRefresh && n2.isPlaying && (t2.autoRefresh ? this.addEventListeners() : this.removeEventListeners()), e.enabled && !t2.enabled && this.clearAllIntersections(), t2.objects !== e.objects && this.setDirty();
|
|
}, play: function() {
|
|
this.addEventListeners();
|
|
}, pause: function() {
|
|
this.removeEventListeners();
|
|
}, remove: function() {
|
|
this.data.showLine && this.el.removeAttribute("line"), this.clearAllIntersections();
|
|
}, addEventListeners: function() {
|
|
this.data.autoRefresh && (this.observer.observe(this.el.sceneEl, zA), this.el.sceneEl.addEventListener("object3dset", this.setDirty), this.el.sceneEl.addEventListener("object3dremove", this.setDirty));
|
|
}, removeEventListeners: function() {
|
|
this.observer.disconnect(), this.el.sceneEl.removeEventListener("object3dset", this.setDirty), this.el.sceneEl.removeEventListener("object3dremove", this.setDirty);
|
|
}, setDirty: function() {
|
|
this.dirty = true;
|
|
}, refreshObjects: function() {
|
|
var e, t2 = this.data;
|
|
e = t2.objects ? this.el.sceneEl.querySelectorAll(t2.objects) : this.el.sceneEl.querySelectorAll("*"), this.objects = this.flattenObject3DMaps(e), this.dirty = false;
|
|
}, tock: function(e) {
|
|
var t2 = this.data, n2 = this.prevCheckTime;
|
|
t2.enabled && (n2 && e - n2 < t2.interval || (this.prevCheckTime = e, this.checkIntersections()));
|
|
}, checkIntersections: function() {
|
|
var e, t2, n2 = this.clearedIntersectedEls, i2 = this.el, r2 = this.data, o2 = this.intersectedEls, s2 = this.intersections, a2 = this.newIntersectedEls, A2 = this.newIntersections, l2 = this.prevIntersectedEls, c2 = this.rawIntersections;
|
|
for (this.dirty && this.refreshObjects(), WA(this.prevIntersectedEls, this.intersectedEls), this.updateOriginDirection(), c2.length = 0, this.raycaster.intersectObjects(this.objects, true, c2), s2.length = 0, o2.length = 0, e = 0;e < c2.length; e++)
|
|
t2 = c2[e], r2.showLine && t2.object === i2.getObject3D("line") || t2.object.el && (s2.push(t2), o2.push(t2.object.el));
|
|
for (A2.length = 0, a2.length = 0, e = 0;e < s2.length; e++)
|
|
l2.indexOf(s2[e].object.el) === -1 && (A2.push(s2[e]), a2.push(s2[e].object.el));
|
|
for (n2.length = 0, e = 0;e < l2.length; e++)
|
|
o2.indexOf(l2[e]) === -1 && (l2[e].emit(YA, this.intersectedClearedDetail), n2.push(l2[e]));
|
|
for (n2.length && i2.emit(KA, this.intersectionClearedDetail), e = 0;e < a2.length; e++)
|
|
a2[e].emit("raycaster-intersected", this.intersectedDetail);
|
|
A2.length && (this.intersectionDetail.els = a2, this.intersectionDetail.intersections = A2, i2.emit("raycaster-intersection", this.intersectionDetail)), (l2.length === 0 && s2.length > 0 || l2.length > 0 && s2.length === 0 || l2.length && s2.length && l2[0] !== s2[0].object.el) && (this.intersectionDetail.els = this.intersectedEls, this.intersectionDetail.intersections = s2, i2.emit("raycaster-closest-entity-changed", this.intersectionDetail)), r2.showLine && setTimeout(this.updateLine);
|
|
}, updateLine: function() {
|
|
var e, t2 = this.el, n2 = this.intersections;
|
|
n2.length && (e = n2[0].object.el === t2 && n2[1] ? n2[1].distance : n2[0].distance), this.drawLine(e);
|
|
}, getIntersection: function(e) {
|
|
var t2, n2;
|
|
for (t2 = 0;t2 < this.intersections.length; t2++)
|
|
if ((n2 = this.intersections[t2]).object.el === e)
|
|
return n2;
|
|
return null;
|
|
}, updateOriginDirection: function() {
|
|
var e = new Re.Vector3, t2 = new Re.Vector3;
|
|
return function() {
|
|
var n2 = this.el, i2 = this.data;
|
|
i2.useWorldCoordinates ? this.raycaster.set(i2.origin, i2.direction) : (n2.object3D.updateMatrixWorld(), t2.setFromMatrixPosition(n2.object3D.matrixWorld), i2.origin.x === 0 && i2.origin.y === 0 && i2.origin.z === 0 || (t2 = n2.object3D.localToWorld(t2.copy(i2.origin))), e.copy(i2.direction).transformDirection(n2.object3D.matrixWorld).normalize(), this.raycaster.set(t2, e));
|
|
};
|
|
}(), drawLine: function(e) {
|
|
var t2, n2 = this.data, i2 = this.el;
|
|
t2 = this.lineData.end === this.lineEndVec3 ? this.otherLineEndVec3 : this.lineEndVec3, e === undefined && (e = n2.far === 1 / 0 ? 1000 : n2.far), this.lineData.start = n2.origin, this.lineData.end = t2.copy(this.unitLineEndVec3).multiplyScalar(e).add(n2.origin), this.lineData.color = n2.lineColor, this.lineData.opacity = n2.lineOpacity, i2.setAttribute("line", this.lineData);
|
|
}, flattenObject3DMaps: function(e) {
|
|
var t2, n2, i2 = this.objects, r2 = this.el.sceneEl.object3D;
|
|
function o2(e2) {
|
|
return e2.parent ? o2(e2.parent) : e2 === r2;
|
|
}
|
|
for (i2.length = 0, n2 = 0;n2 < e.length; n2++) {
|
|
var s2 = e[n2];
|
|
if (s2.isEntity && s2.object3D && o2(s2.object3D))
|
|
for (t2 in s2.object3DMap)
|
|
i2.push(s2.getObject3D(t2));
|
|
}
|
|
return i2;
|
|
}, clearAllIntersections: function() {
|
|
var e;
|
|
for (e = 0;e < this.intersectedEls.length; e++)
|
|
this.intersectedEls[e].emit(YA, this.intersectedClearedDetail);
|
|
WA(this.clearedIntersectedEls, this.intersectedEls), this.intersectedEls.length = 0, this.intersections.length = 0, this.el.emit(KA, this.intersectionClearedDetail);
|
|
} });
|
|
el = Re.MathUtils.degToRad;
|
|
tl = (cs("rotation", { schema: { type: "vec3" }, update: function() {
|
|
var e = this.data;
|
|
this.el.object3D.rotation.set(el(e.x), el(e.y), el(e.z), "YXZ");
|
|
}, remove: function() {
|
|
this.el.object3D.rotation.set(0, 0, 0);
|
|
} }), cs("scale", { schema: { type: "vec3", default: { x: 1, y: 1, z: 1 } }, update: function() {
|
|
var e = this.data;
|
|
this.el.object3D.scale.set(e.x, e.y, e.z);
|
|
}, remove: function() {
|
|
this.el.object3D.scale.set(1, 1, 1);
|
|
} }), cs("shadow", { schema: { cast: { default: true }, receive: { default: true } }, init: function() {
|
|
this.onMeshChanged = this.update.bind(this), this.el.addEventListener("object3dset", this.onMeshChanged), this.system.setShadowMapEnabled(true);
|
|
}, update: function() {
|
|
var e = this.data;
|
|
this.updateDescendants(e.cast, e.receive);
|
|
}, remove: function() {
|
|
this.el.removeEventListener("object3dset", this.onMeshChanged), this.updateDescendants(false, false);
|
|
}, updateDescendants: function(e, t2) {
|
|
var n2 = this.el.sceneEl;
|
|
this.el.object3D.traverse(function(i2) {
|
|
if (i2 instanceof Re.Mesh && (i2.castShadow = e, i2.receiveShadow = t2, n2.hasLoaded && i2.material))
|
|
for (var r2 = Array.isArray(i2.material) ? i2.material : [i2.material], o2 = 0;o2 < r2.length; o2++)
|
|
r2[o2].needsUpdate = true;
|
|
});
|
|
} }), fi("components:sound:warn"));
|
|
nl = (cs("sound", { schema: { autoplay: { default: false }, distanceModel: { default: "inverse", oneOf: ["linear", "inverse", "exponential"] }, loop: { default: false }, loopStart: { default: 0 }, loopEnd: { default: 0 }, maxDistance: { default: 1e4 }, on: { default: "" }, poolSize: { default: 1 }, positional: { default: true }, refDistance: { default: 1 }, rolloffFactor: { default: 1 }, src: { type: "audio" }, volume: { default: 1 } }, multiple: true, init: function() {
|
|
var e = this;
|
|
this.listener = null, this.audioLoader = new Re.AudioLoader, this.pool = new Re.Group, this.loaded = false, this.mustPlay = false, this.playSoundBound = function() {
|
|
e.playSound();
|
|
};
|
|
}, update: function(e) {
|
|
var t2, n2, i2 = this.data, r2 = i2.src !== e.src;
|
|
if (r2) {
|
|
if (!i2.src)
|
|
return;
|
|
this.setupSound();
|
|
}
|
|
for (t2 = 0;t2 < this.pool.children.length; t2++)
|
|
n2 = this.pool.children[t2], i2.positional && (n2.setDistanceModel(i2.distanceModel), n2.setMaxDistance(i2.maxDistance), n2.setRefDistance(i2.refDistance), n2.setRolloffFactor(i2.rolloffFactor)), n2.setLoop(i2.loop), n2.setLoopStart(i2.loopStart), i2.loopStart !== 0 && i2.loopEnd === 0 ? n2.setLoopEnd(n2.buffer.duration) : n2.setLoopEnd(i2.loopEnd), n2.setVolume(i2.volume), n2.isPaused = false;
|
|
if (i2.on !== e.on && this.updateEventListener(e.on), r2) {
|
|
var o2 = this;
|
|
this.loaded = false, this.audioLoader.load(i2.src, function(e2) {
|
|
for (t2 = 0;t2 < o2.pool.children.length; t2++)
|
|
(n2 = o2.pool.children[t2]).setBuffer(e2);
|
|
o2.loaded = true, Re.Cache.remove(i2.src), (o2.data.autoplay || o2.mustPlay) && o2.playSound(o2.processSound), o2.el.emit("sound-loaded", o2.evtDetail, false);
|
|
});
|
|
}
|
|
}, pause: function() {
|
|
this.stopSound(), this.removeEventListener();
|
|
}, play: function() {
|
|
this.data.autoplay && this.playSound(), this.updateEventListener();
|
|
}, remove: function() {
|
|
var e;
|
|
this.removeEventListener(), this.el.getObject3D(this.attrName) && this.el.removeObject3D(this.attrName);
|
|
try {
|
|
for (e = 0;e < this.pool.children.length; e++)
|
|
this.pool.children[e].disconnect();
|
|
} catch (e2) {
|
|
tl("Audio source not properly disconnected");
|
|
}
|
|
}, updateEventListener: function(e) {
|
|
var t2 = this.el;
|
|
e && t2.removeEventListener(e, this.playSoundBound), t2.addEventListener(this.data.on, this.playSoundBound);
|
|
}, removeEventListener: function() {
|
|
this.el.removeEventListener(this.data.on, this.playSoundBound);
|
|
}, setupSound: function() {
|
|
var e, t2, n2 = this.el, i2 = n2.sceneEl, r2 = this;
|
|
this.pool.children.length > 0 && (this.stopSound(), n2.removeObject3D("sound"));
|
|
var o2 = this.listener = i2.audioListener || new Re.AudioListener;
|
|
for (i2.audioListener = o2, i2.camera && i2.camera.add(o2), i2.addEventListener("camera-set-active", function(e2) {
|
|
e2.detail.cameraEl.getObject3D("camera").add(o2);
|
|
}), this.pool = new Re.Group, e = 0;e < this.data.poolSize; e++)
|
|
t2 = this.data.positional ? new Re.PositionalAudio(o2) : new Re.Audio(o2), this.pool.add(t2);
|
|
for (n2.setObject3D(this.attrName, this.pool), e = 0;e < this.pool.children.length; e++)
|
|
(t2 = this.pool.children[e]).onEnded = function() {
|
|
this.isPlaying = false, r2.el.emit("sound-ended", r2.evtDetail, false);
|
|
};
|
|
}, pauseSound: function() {
|
|
var e, t2;
|
|
for (this.isPlaying = false, e = 0;e < this.pool.children.length; e++)
|
|
(t2 = this.pool.children[e]).source && t2.source.buffer && t2.isPlaying && !t2.isPaused && (t2.isPaused = true, t2.pause());
|
|
}, playSound: function(e) {
|
|
var t2, n2, i2;
|
|
if (!this.loaded)
|
|
return tl("Sound not loaded yet. It will be played once it finished loading"), this.mustPlay = true, void (this.processSound = e);
|
|
for (t2 = false, this.isPlaying = true, n2 = 0;n2 < this.pool.children.length; n2++)
|
|
(i2 = this.pool.children[n2]).isPlaying || !i2.buffer || t2 || (e && e(i2), i2.play(), i2.isPaused = false, t2 = true);
|
|
t2 ? (this.mustPlay = false, this.processSound = undefined) : tl("All the sounds are playing. If you need to play more sounds simultaneously consider increasing the size of pool with the `poolSize` attribute.", this.el);
|
|
}, stopSound: function() {
|
|
var e, t2;
|
|
for (this.isPlaying = false, e = 0;e < this.pool.children.length; e++) {
|
|
if (!(t2 = this.pool.children[e]).source || !t2.source.buffer)
|
|
return;
|
|
t2.stop();
|
|
}
|
|
} }), i(4433));
|
|
il = i.n(nl);
|
|
rl = i(5751);
|
|
ol = i.n(rl);
|
|
sl = fi("components:text:error");
|
|
al = fi("components:text:warn");
|
|
Al = ci + "fonts/";
|
|
ll = { aileronsemibold: Al + "Aileron-Semibold.fnt", dejavu: Al + "DejaVu-sdf.fnt", exo2bold: Al + "Exo2Bold.fnt", exo2semibold: Al + "Exo2SemiBold.fnt", kelsonsans: Al + "KelsonSans.fnt", monoid: Al + "Monoid.fnt", mozillavr: Al + "mozillavr.fnt", roboto: Al + "Roboto-msdf.json", sourcecodepro: Al + "SourceCodePro.fnt" };
|
|
cl = ["roboto"];
|
|
dl = new function() {
|
|
var e = this.cache = {};
|
|
this.get = function(t2, n2) {
|
|
return t2 in e || (e[t2] = n2()), e[t2];
|
|
};
|
|
};
|
|
ul = {};
|
|
gl = {};
|
|
pl = /^\w+:/;
|
|
cs("text", { multiple: true, schema: { align: { type: "string", default: "left", oneOf: ["left", "right", "center"] }, alphaTest: { default: 0.5 }, anchor: { default: "center", oneOf: ["left", "right", "center", "align"] }, baseline: { default: "center", oneOf: ["top", "center", "bottom"] }, color: { type: "color", default: "#FFF" }, font: { type: "string", default: hl }, fontImage: { type: "string" }, height: { type: "number" }, letterSpacing: { type: "number", default: 0 }, lineHeight: { type: "number" }, negate: { type: "boolean", default: true }, opacity: { type: "number", default: 1 }, shader: { default: "sdf", oneOf: $s }, side: { default: "front", oneOf: ["front", "back", "double"] }, tabSize: { default: 4 }, transparent: { default: true }, value: { type: "string" }, whiteSpace: { default: "normal", oneOf: ["normal", "pre", "nowrap"] }, width: { type: "number" }, wrapCount: { type: "number", default: 40 }, wrapPixels: { type: "number" }, xOffset: { type: "number", default: 0 }, yOffset: { type: "number", default: 0 }, zOffset: { type: "number", default: 0.001 } }, init: function() {
|
|
this.shaderData = {}, this.geometry = il()(), this.createOrUpdateMaterial(), this.explicitGeoDimensionsChecked = false;
|
|
}, update: function(e) {
|
|
var t2 = this.data, n2 = this.currentFont;
|
|
gl[t2.font] ? this.texture = gl[t2.font] : (this.texture = gl[t2.font] = new Re.Texture, this.texture.anisotropy = 16), this.createOrUpdateMaterial(), e.font === t2.font ? n2 && (this.updateGeometry(this.geometry, n2), this.updateLayout()) : this.updateFont();
|
|
}, remove: function() {
|
|
this.geometry.dispose(), this.geometry = null, this.el.removeObject3D(this.attrName), this.material.dispose(), this.material = null, this.texture.dispose(), this.texture = null, this.shaderObject && delete this.shaderObject;
|
|
}, createOrUpdateMaterial: function() {
|
|
var e, t2, n2, i2 = this.data, r2 = this.material, o2 = this.shaderData;
|
|
if (n2 = i2.shader, cl.indexOf(i2.font) !== -1 || i2.font.indexOf("-msdf.") >= 0 ? n2 = "msdf" : (i2.font in ll) && cl.indexOf(i2.font) === -1 && (n2 = "sdf"), e = (this.shaderObject && this.shaderObject.name) !== n2, o2.alphaTest = i2.alphaTest, o2.color = i2.color, o2.map = this.texture, o2.opacity = i2.opacity, o2.side = function(e2) {
|
|
switch (e2) {
|
|
case "back":
|
|
return Re.FrontSide;
|
|
case "double":
|
|
return Re.DoubleSide;
|
|
default:
|
|
return Re.BackSide;
|
|
}
|
|
}(i2.side), o2.transparent = i2.transparent, o2.negate = i2.negate, !e)
|
|
return this.shaderObject.update(o2), r2.transparent = o2.transparent, void (r2.side = o2.side);
|
|
t2 = function(e2, t3, n3) {
|
|
var i3, r3;
|
|
return (r3 = new $s[t3].Shader).el = e2, r3.init(n3), r3.update(n3), (i3 = r3.material).transparent = n3.transparent, { material: i3, shader: r3 };
|
|
}(this.el, n2, o2), this.material = t2.material, this.shaderObject = t2.shader, this.material.side = o2.side, this.mesh && (this.mesh.material = this.material);
|
|
}, updateFont: function() {
|
|
var e, t2 = this.data, n2 = this.el, i2 = this.geometry, r2 = this;
|
|
t2.font || al("No font specified. Using the default font."), this.mesh && (this.mesh.visible = false), e = this.lookupFont(t2.font || hl) || t2.font, dl.get(e, function() {
|
|
return function(e2, t3) {
|
|
return new Promise(function(n3, i3) {
|
|
ol()(e2, function(r3, o2) {
|
|
if (r3)
|
|
return sl("Error loading font", e2), void i3(r3);
|
|
e2.indexOf("/Roboto-msdf.json") >= 0 && (t3 = 30), t3 && o2.chars.forEach(function(e3) {
|
|
e3.yoffset += t3;
|
|
}), n3(o2);
|
|
});
|
|
});
|
|
}(e, t2.yOffset);
|
|
}).then(function(o2) {
|
|
var s2;
|
|
if (o2.pages.length !== 1)
|
|
throw new Error("Currently only single-page bitmap fonts are supported.");
|
|
ul[e] || (o2.widthFactor = ul[o2] = function(e2) {
|
|
var t3 = 0, n3 = 0, i3 = 0;
|
|
return e2.chars.forEach(function(e3) {
|
|
t3 += e3.xadvance, e3.id >= 48 && e3.id <= 57 && (i3++, n3 += e3.xadvance);
|
|
}), i3 ? n3 / i3 : t3 / e2.chars.length;
|
|
}(o2)), r2.currentFont = o2, s2 = r2.getFontImageSrc(), dl.get(s2, function() {
|
|
return function(e2) {
|
|
return new Promise(function(t3, n3) {
|
|
new Re.ImageLoader().load(e2, function(e3) {
|
|
t3(e3);
|
|
}, undefined, function() {
|
|
sl("Error loading font image", e2), n3(null);
|
|
});
|
|
});
|
|
}(s2);
|
|
}).then(function(e2) {
|
|
var s3 = r2.texture;
|
|
s3 && (s3.image = e2, s3.needsUpdate = true, gl[t2.font] = s3, r2.texture = s3, r2.initMesh(), r2.currentFont = o2, r2.updateGeometry(i2, o2), r2.updateLayout(), r2.mesh.visible = true, n2.emit("textfontset", { font: t2.font, fontObj: o2 }));
|
|
}).catch(function(e2) {
|
|
sl(e2.message), sl(e2.stack);
|
|
});
|
|
}).catch(function(e2) {
|
|
sl(e2.message), sl(e2.stack);
|
|
});
|
|
}, initMesh: function() {
|
|
this.mesh || (this.mesh = new Re.Mesh(this.geometry, this.material), this.el.setObject3D(this.attrName, this.mesh));
|
|
}, getFontImageSrc: function() {
|
|
if (this.data.fontImage)
|
|
return this.data.fontImage;
|
|
var e = this.lookupFont(this.data.font || hl) || this.data.font, t2 = this.currentFont.pages[0];
|
|
return t2.match(pl) && t2.indexOf("http") !== 0 ? e.replace(/(\.fnt)|(\.json)/, ".png") : Re.LoaderUtils.extractUrlBase(e) + t2;
|
|
}, updateLayout: function() {
|
|
var e, t2, n2, i2, r2, o2, s2, a2, A2, l2 = this.el, c2 = this.data, h2 = this.geometry, d2 = this.mesh;
|
|
if (d2 && h2.layout) {
|
|
if (n2 = l2.getAttribute("geometry"), i2 = (o2 = (s2 = c2.width || n2 && n2.width || 1) / fl(c2.wrapPixels, c2.wrapCount, this.currentFont.widthFactor)) * ((r2 = h2.layout).height + r2.descender), n2 && n2.primitive === "plane" && (this.explicitGeoDimensionsChecked || (this.explicitGeoDimensionsChecked = true, this.hasExplicitGeoWidth = !!n2.width, this.hasExplicitGeoHeight = !!n2.height), this.hasExplicitGeoWidth || l2.setAttribute("geometry", "width", s2), this.hasExplicitGeoHeight || l2.setAttribute("geometry", "height", i2)), (e = c2.anchor === "align" ? c2.align : c2.anchor) === "left")
|
|
a2 = 0;
|
|
else if (e === "right")
|
|
a2 = -1 * r2.width;
|
|
else {
|
|
if (e !== "center")
|
|
throw new TypeError("Invalid text.anchor property value", e);
|
|
a2 = -1 * r2.width / 2;
|
|
}
|
|
if ((t2 = c2.baseline) === "bottom")
|
|
A2 = 0;
|
|
else if (t2 === "top")
|
|
A2 = -1 * r2.height + r2.ascender;
|
|
else {
|
|
if (t2 !== "center")
|
|
throw new TypeError("Invalid text.baseline property value", t2);
|
|
A2 = -1 * r2.height / 2;
|
|
}
|
|
d2.position.x = a2 * o2 + c2.xOffset, d2.position.y = A2 * o2, d2.position.z = c2.zOffset, d2.scale.set(o2, -1 * o2, o2);
|
|
}
|
|
}, lookupFont: function(e) {
|
|
return ll[e];
|
|
}, updateGeometry: (JA = {}, XA = {}, ZA = /\\n/g, $A = /\\t/g, function(e, t2) {
|
|
var n2 = this.data;
|
|
XA.font = t2, XA.lineHeight = n2.lineHeight && isFinite(n2.lineHeight) ? n2.lineHeight : t2.common.lineHeight, XA.text = n2.value.toString().replace(ZA, `
|
|
`).replace($A, "\t"), XA.width = fl(n2.wrapPixels, n2.wrapCount, t2.widthFactor), e.update(Jr(JA, n2, XA));
|
|
}) });
|
|
Cl = (cs("tracked-controls", { schema: { id: { type: "string", default: "" }, controller: { default: -1 }, autoHide: { default: true }, hand: { type: "string", default: "" }, handTrackingEnabled: { default: false }, iterateControllerProfiles: { default: false } }, init: function() {
|
|
this.buttonEventDetails = {}, this.buttonStates = this.el.components["tracked-controls"].buttonStates = {}, this.axis = this.el.components["tracked-controls"].axis = [0, 0, 0], this.changedAxes = [], this.axisMoveEventDetail = { axis: this.axis, changed: this.changedAxes }, this.updateController = this.updateController.bind(this);
|
|
}, update: function() {
|
|
this.updateController();
|
|
}, play: function() {
|
|
var e = this.el.sceneEl;
|
|
this.updateController(), e.addEventListener("controllersupdated", this.updateController);
|
|
}, pause: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.updateController);
|
|
}, isControllerPresent: function(e) {
|
|
return !(!this.controller || this.controller.gamepad || e.inputSource.handedness !== "none" && e.inputSource.handedness !== this.data.hand);
|
|
}, updateController: function() {
|
|
this.controller = Pr(this.system.controllers, this.data.id, this.data.hand, this.data.controller, this.data.iterateControllerProfiles, this.data.handTrackingEnabled), this.el.components["tracked-controls"].controller = this.controller;
|
|
}, tick: function() {
|
|
var e = this.el.sceneEl, t2 = this.controller, n2 = e.frame;
|
|
this.data.autoHide && (this.el.object3D.visible = !!t2), t2 && e.frame && this.system.referenceSpace && (t2.hand || (this.pose = n2.getPose(t2.gripSpace, this.system.referenceSpace), this.updatePose(), this.updateButtons()));
|
|
}, updatePose: function() {
|
|
var e = this.el.object3D, t2 = this.pose;
|
|
t2 && (e.matrix.elements = t2.transform.matrix, e.matrix.decompose(e.position, e.rotation, e.scale));
|
|
}, updateButtons: function() {
|
|
var e, t2, n2, i2 = this.controller;
|
|
if (i2 && i2.gamepad) {
|
|
for (n2 = i2.gamepad, t2 = 0;t2 < n2.buttons.length; ++t2)
|
|
this.buttonStates[t2] || (this.buttonStates[t2] = { pressed: false, touched: false, value: 0 }), this.buttonEventDetails[t2] || (this.buttonEventDetails[t2] = { id: t2, state: this.buttonStates[t2] }), e = n2.buttons[t2], this.handleButton(t2, e);
|
|
this.handleAxes();
|
|
}
|
|
}, handleButton: function(e, t2) {
|
|
return !!(this.handlePress(e, t2) | this.handleTouch(e, t2) | this.handleValue(e, t2)) && (this.el.emit("buttonchanged", this.buttonEventDetails[e], false), true);
|
|
}, handleAxes: function() {
|
|
var e, t2 = false, n2 = this.controller.gamepad.axes, i2 = this.axis, r2 = this.changedAxes;
|
|
for (this.changedAxes.splice(0, this.changedAxes.length), e = 0;e < n2.length; ++e)
|
|
r2.push(i2[e] !== n2[e]), r2[e] && (t2 = true);
|
|
if (!t2)
|
|
return false;
|
|
for (this.axis.splice(0, this.axis.length), e = 0;e < n2.length; e++)
|
|
this.axis.push(n2[e]);
|
|
return this.el.emit("axismove", this.axisMoveEventDetail, false), true;
|
|
}, handlePress: function(e, t2) {
|
|
var n2, i2 = this.buttonStates[e];
|
|
return t2.pressed !== i2.pressed && (n2 = t2.pressed ? "buttondown" : "buttonup", this.el.emit(n2, this.buttonEventDetails[e], false), i2.pressed = t2.pressed, true);
|
|
}, handleTouch: function(e, t2) {
|
|
var n2, i2 = this.buttonStates[e];
|
|
return t2.touched !== i2.touched && (n2 = t2.touched ? "touchstart" : "touchend", this.el.emit(n2, this.buttonEventDetails[e], false), i2.touched = t2.touched, true);
|
|
}, handleValue: function(e, t2) {
|
|
var n2 = this.buttonStates[e];
|
|
return t2.value !== n2.value && (n2.value = t2.value, true);
|
|
} }), cs("visible", { schema: { default: true }, update: function() {
|
|
this.el.object3D.visible = this.data;
|
|
} }), ci + "controllers/valve/index/valve-index-");
|
|
vl = { left: Cl + "left.glb", right: Cl + "right.glb" };
|
|
bl = { left: { x: 0, y: -0.05, z: 0.06 }, right: { x: 0, y: -0.05, z: 0.06 } };
|
|
yl = { left: { _x: Math.PI / 3, _y: 0, _z: 0, _order: "XYZ" }, right: { _x: Math.PI / 3, _y: 0, _z: 0, _order: "XYZ" } };
|
|
Il = (cs("valve-index-controls", { schema: { hand: { default: "left" }, buttonColor: { type: "color", default: "#FAFAFA" }, buttonHighlightColor: { type: "color", default: "#22D1EE" }, model: { default: true } }, after: ["tracked-controls"], mapping: { axes: { trackpad: [0, 1], thumbstick: [2, 3] }, buttons: ["trigger", "grip", "trackpad", "thumbstick", "abutton"] }, init: function() {
|
|
var e = this;
|
|
this.controllerPresent = false, this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e);
|
|
}, this.previousButtonValues = {}, this.bindMethods();
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, bindMethods: function() {
|
|
this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("model-loaded", this.onModelLoaded), e.addEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("model-loaded", this.onModelLoaded), e.removeEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.data, t2 = e.hand === "right" ? 0 : e.hand === "left" ? 1 : 2;
|
|
Ur(this, Bl, { index: t2, iterateControllerProfiles: true, hand: e.hand });
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data;
|
|
e.setAttribute("tracked-controls", { idPrefix: Bl, controller: t2.hand === "right" ? 1 : t2.hand === "left" ? 0 : 2, hand: t2.hand }), this.loadModel();
|
|
}, loadModel: function() {
|
|
var e = this.data;
|
|
e.model && this.el.setAttribute("gltf-model", "" + vl[e.hand]);
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onButtonChanged: function(e) {
|
|
var t2, n2 = this.mapping.buttons[e.detail.id], i2 = this.buttonMeshes;
|
|
n2 && (n2 === "trigger" && (t2 = e.detail.state.value, i2 && i2.trigger && (i2.trigger.rotation.x = this.triggerOriginalRotationX - t2 * (Math.PI / 40))), this.el.emit(n2 + "changed", e.detail.state));
|
|
}, onModelLoaded: function(e) {
|
|
var t2, n2 = e.detail.model, i2 = this;
|
|
e.target === this.el && this.data.model && ((t2 = this.buttonMeshes = {}).grip = { left: n2.getObjectByName("leftgrip"), right: n2.getObjectByName("rightgrip") }, t2.menu = n2.getObjectByName("menubutton"), t2.system = n2.getObjectByName("systembutton"), t2.trackpad = n2.getObjectByName("touchpad"), t2.trigger = n2.getObjectByName("trigger"), this.triggerOriginalRotationX = t2.trigger.rotation.x, Object.keys(t2).forEach(function(e2) {
|
|
i2.setButtonColor(e2, i2.data.buttonColor);
|
|
}), n2.position.copy(yl[this.data.hand]), n2.rotation.copy(bl[this.data.hand]), this.el.emit("controllermodelready", { name: "valve-index-controls", model: this.data.model, rayOrigin: new Re.Vector3(0, 0, 0) }));
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping.axes, e);
|
|
}, updateModel: function(e, t2) {
|
|
var n2;
|
|
this.data.model && (t2.indexOf("touch") !== -1 || (n2 = t2 === "up" ? this.data.buttonColor : this.data.buttonHighlightColor, this.setButtonColor(e, n2)));
|
|
}, setButtonColor: function(e, t2) {} }), ci + "controllers/vive/vr_controller_vive.obj");
|
|
wl = ci + "controllers/vive/vr_controller_vive.mtl";
|
|
Ql = (cs("vive-controls", { schema: { hand: { default: "left" }, buttonColor: { type: "color", default: "#FAFAFA" }, buttonHighlightColor: { type: "color", default: "#22D1EE" }, model: { default: true } }, after: ["tracked-controls"], mapping: { axes: { touchpad: [0, 1] }, buttons: ["trigger", "grip", "touchpad", "none"] }, init: function() {
|
|
var e = this;
|
|
this.controllerPresent = false, this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e);
|
|
}, this.previousButtonValues = {}, this.bindMethods();
|
|
}, update: function() {
|
|
var e = this.data;
|
|
this.controllerIndex = e.hand === "right" ? 0 : e.hand === "left" ? 1 : 2;
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, bindMethods: function() {
|
|
this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("model-loaded", this.onModelLoaded), e.addEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("model-loaded", this.onModelLoaded), e.removeEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
var e = this.data;
|
|
Ur(this, xl, { index: this.controllerIndex, hand: e.hand });
|
|
}, injectTrackedControls: function() {
|
|
var e = this.el, t2 = this.data;
|
|
e.setAttribute("tracked-controls", { idPrefix: xl, hand: t2.hand, controller: this.controllerIndex }), this.data.model && this.el.setAttribute("obj-model", { obj: Il, mtl: wl });
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onButtonChanged: function(e) {
|
|
var t2, n2 = this.mapping.buttons[e.detail.id], i2 = this.buttonMeshes;
|
|
n2 && (n2 === "trigger" && (t2 = e.detail.state.value, i2 && i2.trigger && (i2.trigger.rotation.x = -t2 * (Math.PI / 12))), this.el.emit(n2 + "changed", e.detail.state));
|
|
}, onModelLoaded: function(e) {
|
|
var t2, n2 = e.detail.model, i2 = this;
|
|
e.target === this.el && this.data.model && ((t2 = this.buttonMeshes = {}).grip = { left: n2.getObjectByName("leftgrip"), right: n2.getObjectByName("rightgrip") }, t2.menu = n2.getObjectByName("menubutton"), t2.system = n2.getObjectByName("systembutton"), t2.trackpad = n2.getObjectByName("touchpad"), t2.touchpad = n2.getObjectByName("touchpad"), t2.trigger = n2.getObjectByName("trigger"), Object.keys(t2).forEach(function(e2) {
|
|
i2.setButtonColor(e2, i2.data.buttonColor);
|
|
}), n2.position.set(0, -0.015, 0.04));
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping.axes, e);
|
|
}, updateModel: function(e, t2) {
|
|
var n2;
|
|
this.data.model && (t2.indexOf("touch") !== -1 || (n2 = t2 === "up" ? this.data.buttonColor : this.data.buttonHighlightColor, this.setButtonColor(e, n2)));
|
|
}, setButtonColor: function(e, t2) {
|
|
var n2 = this.buttonMeshes;
|
|
if (n2)
|
|
return e === "grip" ? (n2.grip.left.material.color.set(t2), void n2.grip.right.material.color.set(t2)) : void n2[e].material.color.set(t2);
|
|
} }), ci + "controllers/vive/focus-controller/focus-controller.gltf");
|
|
Ml = (cs("vive-focus-controls", { schema: { hand: { default: "" }, buttonTouchedColor: { type: "color", default: "#BBBBBB" }, buttonHighlightColor: { type: "color", default: "#7A7A7A" }, model: { default: true } }, after: ["tracked-controls"], mapping: { axes: { touchpad: [0, 1] }, buttons: ["trigger", "none", "touchpad", "none", "menu"] }, bindMethods: function() {
|
|
this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.removeControllersUpdateListener = this.removeControllersUpdateListener.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, init: function() {
|
|
var e = this;
|
|
this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t2) {
|
|
Nr(t2.detail.id, "down", e);
|
|
}, this.onButtonUp = function(t2) {
|
|
Nr(t2.detail.id, "up", e);
|
|
}, this.onButtonTouchStart = function(t2) {
|
|
Nr(t2.detail.id, "touchstart", e);
|
|
}, this.onButtonTouchEnd = function(t2) {
|
|
Nr(t2.detail.id, "touchend", e);
|
|
}, this.controllerPresent = false, this.bindMethods();
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("model-loaded", this.onModelLoaded), e.addEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = true, this.addControllersUpdateListener();
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("model-loaded", this.onModelLoaded), e.removeEventListener("axismove", this.onAxisMoved), this.controllerEventsActive = false, this.removeControllersUpdateListener();
|
|
}, checkIfControllerPresent: function() {
|
|
Ur(this, Ll, this.data.hand ? { hand: this.data.hand } : {});
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, injectTrackedControls: function() {
|
|
this.el.setAttribute("tracked-controls", { idPrefix: Ll }), this.data.model && this.el.setAttribute("gltf-model", Ql);
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onModelLoaded: function(e) {
|
|
var t2, n2 = e.detail.model;
|
|
e.target === this.el && this.data.model && ((t2 = this.buttonMeshes = {}).trigger = n2.getObjectByName("BumperKey"), t2.triggerPressed = n2.getObjectByName("BumperKey_Press"), t2.triggerPressed && (t2.triggerPressed.visible = false), t2.touchpad = n2.getObjectByName("TouchPad"), t2.touchpadPressed = n2.getObjectByName("TouchPad_Press"), t2.trackpad = n2.getObjectByName("TouchPad"), t2.trackpadPressed = n2.getObjectByName("TouchPad_Press"), t2.trackpadPressed && (t2.trackpadPressed.visible = false));
|
|
}, onButtonChanged: function(e) {
|
|
var t2 = this.mapping.buttons[e.detail.id];
|
|
t2 && this.el.emit(t2 + "changed", e.detail.state);
|
|
}, onAxisMoved: function(e) {
|
|
Gr(this, this.mapping.axes, e);
|
|
}, updateModel: function(e, t2) {
|
|
this.data.model && this.updateButtonModel(e, t2);
|
|
}, updateButtonModel: function(e, t2) {
|
|
var n2 = this.buttonMeshes, i2 = e + "Pressed";
|
|
if (n2 && n2[e] && n2[i2]) {
|
|
var r2;
|
|
switch (t2) {
|
|
case "down":
|
|
r2 = this.data.buttonHighlightColor;
|
|
break;
|
|
case "touchstart":
|
|
r2 = this.data.buttonTouchedColor;
|
|
}
|
|
r2 && n2[i2].material.color.set(r2), n2[i2].visible = !!r2, n2[e].visible = !r2;
|
|
}
|
|
} }), { 38: "ArrowUp", 37: "ArrowLeft", 40: "ArrowDown", 39: "ArrowRight", 87: "KeyW", 65: "KeyA", 83: "KeyS", 68: "KeyD" });
|
|
Sl = io;
|
|
kl = ["KeyW", "KeyA", "KeyS", "KeyD", "ArrowUp", "ArrowLeft", "ArrowRight", "ArrowDown"];
|
|
cs("wasd-controls", { schema: { acceleration: { default: 65 }, adAxis: { default: "x", oneOf: ["x", "y", "z"] }, adEnabled: { default: true }, adInverted: { default: false }, enabled: { default: true }, fly: { default: false }, wsAxis: { default: "z", oneOf: ["x", "y", "z"] }, wsEnabled: { default: true }, wsInverted: { default: false } }, after: ["look-controls"], init: function() {
|
|
this.keys = {}, this.easing = 1.1, this.velocity = new Re.Vector3, this.onBlur = this.onBlur.bind(this), this.onContextMenu = this.onContextMenu.bind(this), this.onFocus = this.onFocus.bind(this), this.onKeyDown = this.onKeyDown.bind(this), this.onKeyUp = this.onKeyUp.bind(this), this.onVisibilityChange = this.onVisibilityChange.bind(this), this.attachVisibilityEventListeners();
|
|
}, tick: function(e, t2) {
|
|
var n2 = this.data, i2 = this.el, r2 = this.velocity;
|
|
(r2[n2.adAxis] || r2[n2.wsAxis] || !function(e2) {
|
|
var t3;
|
|
for (t3 in e2)
|
|
return false;
|
|
return true;
|
|
}(this.keys)) && (t2 /= 1000, this.updateVelocity(t2), (r2[n2.adAxis] || r2[n2.wsAxis]) && i2.object3D.position.add(this.getMovementVector(t2)));
|
|
}, update: function(e) {
|
|
e.adAxis !== this.data.adAxis && (this.velocity[e.adAxis] = 0), e.wsAxis !== this.data.wsAxis && (this.velocity[e.wsAxis] = 0);
|
|
}, remove: function() {
|
|
this.removeKeyEventListeners(), this.removeVisibilityEventListeners();
|
|
}, play: function() {
|
|
this.attachKeyEventListeners();
|
|
}, pause: function() {
|
|
this.keys = {}, this.removeKeyEventListeners();
|
|
}, updateVelocity: function(e) {
|
|
var t2, n2, i2, r2, o2, s2 = this.data, a2 = this.keys, A2 = this.velocity;
|
|
if (n2 = s2.adAxis, r2 = s2.wsAxis, e > 0.2)
|
|
return A2[n2] = 0, void (A2[r2] = 0);
|
|
var l2 = Math.pow(1 / this.easing, 60 * e);
|
|
A2[n2] !== 0 && (A2[n2] = A2[n2] * l2), A2[r2] !== 0 && (A2[r2] = A2[r2] * l2), Math.abs(A2[n2]) < Dl && (A2[n2] = 0), Math.abs(A2[r2]) < Dl && (A2[r2] = 0), s2.enabled && (t2 = s2.acceleration, s2.adEnabled && (i2 = s2.adInverted ? -1 : 1, (a2.KeyA || a2.ArrowLeft) && (A2[n2] -= i2 * t2 * e), (a2.KeyD || a2.ArrowRight) && (A2[n2] += i2 * t2 * e)), s2.wsEnabled && (o2 = s2.wsInverted ? -1 : 1, (a2.KeyW || a2.ArrowUp) && (A2[r2] -= o2 * t2 * e), (a2.KeyS || a2.ArrowDown) && (A2[r2] += o2 * t2 * e)));
|
|
}, getMovementVector: (ml = new Re.Vector3(0, 0, 0), El = new Re.Euler(0, 0, 0, "YXZ"), function(e) {
|
|
var t2, n2 = this.el.getAttribute("rotation"), i2 = this.velocity;
|
|
return ml.copy(i2), ml.multiplyScalar(e), n2 ? (t2 = this.data.fly ? n2.x : 0, El.set(Re.MathUtils.degToRad(t2), Re.MathUtils.degToRad(n2.y), 0), ml.applyEuler(El), ml) : ml;
|
|
}), attachVisibilityEventListeners: function() {
|
|
window.oncontextmenu = this.onContextMenu, window.addEventListener("blur", this.onBlur), window.addEventListener("focus", this.onFocus), document.addEventListener("visibilitychange", this.onVisibilityChange);
|
|
}, removeVisibilityEventListeners: function() {
|
|
window.removeEventListener("blur", this.onBlur), window.removeEventListener("focus", this.onFocus), document.removeEventListener("visibilitychange", this.onVisibilityChange);
|
|
}, attachKeyEventListeners: function() {
|
|
window.addEventListener("keydown", this.onKeyDown), window.addEventListener("keyup", this.onKeyUp);
|
|
}, removeKeyEventListeners: function() {
|
|
window.removeEventListener("keydown", this.onKeyDown), window.removeEventListener("keyup", this.onKeyUp);
|
|
}, onContextMenu: function() {
|
|
for (var e = Object.keys(this.keys), t2 = 0;t2 < e.length; t2++)
|
|
delete this.keys[e[t2]];
|
|
}, onBlur: function() {
|
|
this.pause();
|
|
}, onFocus: function() {
|
|
this.play();
|
|
}, onVisibilityChange: function() {
|
|
document.hidden ? this.onBlur() : this.onFocus();
|
|
}, onKeyDown: function(e) {
|
|
var t2;
|
|
Sl(e) && (t2 = e.code || Ml[e.keyCode], kl.indexOf(t2) !== -1 && (this.keys[t2] = true));
|
|
}, onKeyUp: function(e) {
|
|
var t2;
|
|
t2 = e.code || Ml[e.keyCode], delete this.keys[t2];
|
|
} });
|
|
Ul = fi("components:windows-motion-controls:debug");
|
|
Ol = fi("components:windows-motion-controls:warn");
|
|
Pl = ci + "controllers/microsoft/";
|
|
Gl = { left: "left.glb", right: "right.glb", default: "universal.glb" };
|
|
jl = (cs("windows-motion-controls", { schema: { hand: { default: "right" }, pair: { default: 0 }, model: { default: true } }, after: ["tracked-controls"], mapping: { axes: { touchpad: [0, 1], thumbstick: [2, 3] }, buttons: ["trigger", "squeeze", "touchpad", "thumbstick", "menu"], axisMeshNames: ["TOUCHPAD_TOUCH_X", "TOUCHPAD_TOUCH_X", "THUMBSTICK_X", "THUMBSTICK_Y"], buttonMeshNames: { trigger: "SELECT", menu: "MENU", squeeze: "GRASP", thumbstick: "THUMBSTICK_PRESS", touchpad: "TOUCHPAD_PRESS" }, pointingPoseMeshName: "POINTING_POSE" }, bindMethods: function() {
|
|
this.onModelError = this.onModelError.bind(this), this.onModelLoaded = this.onModelLoaded.bind(this), this.onControllersUpdate = this.onControllersUpdate.bind(this), this.checkIfControllerPresent = this.checkIfControllerPresent.bind(this), this.onAxisMoved = this.onAxisMoved.bind(this);
|
|
}, init: function() {
|
|
var e = this, t2 = this.el;
|
|
this.onButtonChanged = this.onButtonChanged.bind(this), this.onButtonDown = function(t3) {
|
|
Nr(t3.detail.id, "down", e);
|
|
}, this.onButtonUp = function(t3) {
|
|
Nr(t3.detail.id, "up", e);
|
|
}, this.onButtonTouchStart = function(t3) {
|
|
Nr(t3.detail.id, "touchstart", e);
|
|
}, this.onButtonTouchEnd = function(t3) {
|
|
Nr(t3.detail.id, "touchend", e);
|
|
}, this.onControllerConnected = function() {
|
|
e.setModelVisibility(true);
|
|
}, this.onControllerDisconnected = function() {
|
|
e.setModelVisibility(false);
|
|
}, this.controllerPresent = false, this.previousButtonValues = {}, this.bindMethods(), this.loadedMeshInfo = { buttonMeshes: null, axisMeshes: null }, this.rayOrigin = { origin: new Re.Vector3, direction: new Re.Vector3(0, 0, -1), createdFromMesh: false }, t2.addEventListener("controllerconnected", this.onControllerConnected), t2.addEventListener("controllerdisconnected", this.onControllerDisconnected);
|
|
}, addEventListeners: function() {
|
|
var e = this.el;
|
|
e.addEventListener("buttonchanged", this.onButtonChanged), e.addEventListener("buttondown", this.onButtonDown), e.addEventListener("buttonup", this.onButtonUp), e.addEventListener("touchstart", this.onButtonTouchStart), e.addEventListener("touchend", this.onButtonTouchEnd), e.addEventListener("axismove", this.onAxisMoved), e.addEventListener("model-error", this.onModelError), e.addEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = true;
|
|
}, removeEventListeners: function() {
|
|
var e = this.el;
|
|
e.removeEventListener("buttonchanged", this.onButtonChanged), e.removeEventListener("buttondown", this.onButtonDown), e.removeEventListener("buttonup", this.onButtonUp), e.removeEventListener("touchstart", this.onButtonTouchStart), e.removeEventListener("touchend", this.onButtonTouchEnd), e.removeEventListener("axismove", this.onAxisMoved), e.removeEventListener("model-error", this.onModelError), e.removeEventListener("model-loaded", this.onModelLoaded), this.controllerEventsActive = false;
|
|
}, checkIfControllerPresent: function() {
|
|
Ur(this, Nl, { hand: this.data.hand, index: this.data.pair, iterateControllerProfiles: true });
|
|
}, play: function() {
|
|
this.checkIfControllerPresent(), this.addControllersUpdateListener();
|
|
}, pause: function() {
|
|
this.removeEventListeners(), this.removeControllersUpdateListener();
|
|
}, updateControllerModel: function() {
|
|
if (this.data.model && !this.rayOrigin.createdFromMesh) {
|
|
var e = this.createControllerModelUrl();
|
|
this.loadModel(e);
|
|
} else
|
|
this.modelReady();
|
|
}, createControllerModelUrl: function(e) {
|
|
var t2 = this.data.hand;
|
|
return Pl + "default/" + (Gl[t2] || Gl.default);
|
|
}, injectTrackedControls: function() {
|
|
var e = this.data;
|
|
this.el.setAttribute("tracked-controls", { idPrefix: Nl, controller: e.pair, hand: e.hand }), this.updateControllerModel();
|
|
}, addControllersUpdateListener: function() {
|
|
this.el.sceneEl.addEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, removeControllersUpdateListener: function() {
|
|
this.el.sceneEl.removeEventListener("controllersupdated", this.onControllersUpdate, false);
|
|
}, onControllersUpdate: function() {
|
|
this.checkIfControllerPresent();
|
|
}, onModelError: function(e) {
|
|
var t2 = this.createControllerModelUrl(true);
|
|
e.detail.src !== t2 ? (Ol("Failed to load controller model for device, attempting to load default."), this.loadModel(t2)) : Ol("Failed to load default controller model.");
|
|
}, loadModel: function(e) {
|
|
this.el.setAttribute("gltf-model", "url(" + e + ")");
|
|
}, onModelLoaded: function(e) {
|
|
var t2, n2, i2, r2, o2 = this.controllerModel = e.detail.model, s2 = this.loadedMeshInfo;
|
|
if (e.target === this.el) {
|
|
if (Ul("Processing model"), s2.buttonMeshes = {}, s2.axisMeshes = {}, o2) {
|
|
for (t2 = 0;t2 < this.mapping.buttons.length; t2++)
|
|
(n2 = this.mapping.buttonMeshNames[this.mapping.buttons[t2]]) ? (i2 = o2.getObjectByName(n2)) ? (r2 = { index: t2, value: a2(i2, "VALUE"), pressed: a2(i2, "PRESSED"), unpressed: a2(i2, "UNPRESSED") }).value && r2.pressed && r2.unpressed ? s2.buttonMeshes[this.mapping.buttons[t2]] = r2 : Ol("Missing button submesh under mesh with name: " + n2 + "(VALUE: " + !!r2.value + ", PRESSED: " + !!r2.pressed + ", UNPRESSED:" + !!r2.unpressed + ")") : Ol("Missing button mesh with name: " + n2) : Ul("Skipping unknown button at index: " + t2 + " with mapped name: " + this.mapping.buttons[t2]);
|
|
for (t2 = 0;t2 < this.mapping.axisMeshNames.length; t2++)
|
|
(n2 = this.mapping.axisMeshNames[t2]) ? (i2 = o2.getObjectByName(n2)) ? (r2 = { index: t2, value: a2(i2, "VALUE"), min: a2(i2, "MIN"), max: a2(i2, "MAX") }).value && r2.min && r2.max ? s2.axisMeshes[t2] = r2 : Ol("Missing axis submesh under mesh with name: " + n2 + "(VALUE: " + !!r2.value + ", MIN: " + !!r2.min + ", MAX:" + !!r2.max + ")") : Ol("Missing axis mesh with name: " + n2) : Ul("Skipping unknown axis at index: " + t2);
|
|
this.calculateRayOriginFromMesh(o2), this.setModelVisibility();
|
|
}
|
|
Ul("Model load complete.");
|
|
}
|
|
function a2(e2, t3) {
|
|
for (var n3 = 0, i3 = e2.children.length;n3 < i3; n3++) {
|
|
var r3 = e2.children[n3];
|
|
if (r3 && r3.name === t3)
|
|
return r3;
|
|
}
|
|
}
|
|
}, calculateRayOriginFromMesh: function() {
|
|
var e = new Re.Quaternion;
|
|
return function(t2) {
|
|
var n2;
|
|
if (this.rayOrigin.origin.set(0, 0, 0), this.rayOrigin.direction.set(0, 0, -1), this.rayOrigin.createdFromMesh = true, n2 = t2.getObjectByName(this.mapping.pointingPoseMeshName)) {
|
|
var i2 = t2.parent;
|
|
i2 && (t2.parent = null, t2.updateMatrixWorld(true), t2.parent = i2), n2.getWorldPosition(this.rayOrigin.origin), n2.getWorldQuaternion(e), this.rayOrigin.direction.applyQuaternion(e), i2 && t2.updateMatrixWorld(true);
|
|
} else
|
|
Ul("Mesh does not contain pointing origin data, defaulting to none.");
|
|
this.modelReady();
|
|
};
|
|
}(), lerpAxisTransform: function() {
|
|
var e = new Re.Quaternion;
|
|
return function(t2, n2) {
|
|
var i2 = this.loadedMeshInfo.axisMeshes[t2];
|
|
if (i2) {
|
|
var { min: r2, max: o2, value: s2 } = i2, a2 = 0.5 * n2 + 0.5;
|
|
s2.setRotationFromQuaternion(e.copy(r2.quaternion).slerp(o2.quaternion, a2)), s2.position.lerpVectors(r2.position, o2.position, a2);
|
|
}
|
|
};
|
|
}(), lerpButtonTransform: function() {
|
|
var e = new Re.Quaternion;
|
|
return function(t2, n2) {
|
|
var i2 = this.loadedMeshInfo.buttonMeshes[t2];
|
|
if (i2) {
|
|
var { unpressed: r2, pressed: o2, value: s2 } = i2;
|
|
s2.setRotationFromQuaternion(e.copy(r2.quaternion).slerp(o2.quaternion, n2)), s2.position.lerpVectors(r2.position, o2.position, n2);
|
|
}
|
|
};
|
|
}(), modelReady: function() {
|
|
this.el.emit("controllermodelready", { name: "windows-motion-controls", model: this.data.model, rayOrigin: this.rayOrigin });
|
|
}, onButtonChanged: function(e) {
|
|
var t2 = this.mapping.buttons[e.detail.id];
|
|
t2 && (this.loadedMeshInfo && this.loadedMeshInfo.buttonMeshes && this.lerpButtonTransform(t2, e.detail.state.value), this.el.emit(t2 + "changed", e.detail.state));
|
|
}, onAxisMoved: function(e) {
|
|
var t2 = this.mapping.axisMeshNames.length;
|
|
if (this.loadedMeshInfo && this.loadedMeshInfo.axisMeshes)
|
|
for (var n2 = 0;n2 < t2; n2++)
|
|
this.lerpAxisTransform(n2, e.detail.axis[n2] || 0);
|
|
Gr(this, this.mapping.axes, e);
|
|
}, setModelVisibility: function(e) {
|
|
var t2 = this.el.getObject3D("mesh");
|
|
this.controllerPresent && (e = e !== undefined ? e : this.modelVisible, this.modelVisible = e, t2 && (t2.visible = e));
|
|
} }), Tl = new Re.Quaternion, Rl = new Re.Vector3, function(e, t2, n2) {
|
|
t2.position.copy(e.transform.position), t2.quaternion.copy(e.transform.orientation), Rl.copy(n2), Tl.copy(e.transform.orientation), Rl.applyQuaternion(Tl), t2.position.sub(Rl);
|
|
});
|
|
jl.tempFakePose = { transform: { orientation: new Re.Quaternion, position: new Re.Vector3 } }, _l.prototype.previousFrameAnchors = new Set, _l.prototype.anchorToObject3D = new Map, _l.prototype.sessionStart = function(e) {
|
|
this.session = this.renderer.xr.getSession(), "requestHitTestSource" in this.session ? e.space ? this.session.requestHitTestSource(e).then(function(e2) {
|
|
this.xrHitTestSource = e2;
|
|
}.bind(this)).catch(Hl) : e.profile && this.session.requestHitTestSourceForTransientInput(e).then(function(e2) {
|
|
this.xrHitTestSource = e2, this.transient = true;
|
|
}.bind(this)).catch(Hl) : Hl({ message: "No requestHitTestSource on the session." });
|
|
}, _l.prototype.anchorFromLastHitTestResult = function(e, t2) {
|
|
var n2 = this.lastHitTest;
|
|
if (n2) {
|
|
var i2 = { object3D: e, offset: t2 };
|
|
Array.from(this.anchorToObject3D.entries()).forEach(function(t3) {
|
|
var n3 = t3[1].object3D, i3 = t3[0];
|
|
n3 === e && (this.anchorToObject3D.delete(i3), i3.delete());
|
|
}.bind(this)), n2.createAnchor && n2.createAnchor().then(function(e2) {
|
|
this.anchorToObject3D.set(e2, i2);
|
|
}.bind(this)).catch(function(e2) {
|
|
console.warn(e2.message), console.warn('Cannot create anchor, are you missing: webxr="optionalFeatures: anchors;" from <a-scene>?');
|
|
});
|
|
}
|
|
}, _l.prototype.doHit = function(e) {
|
|
if (this.renderer.xr.isPresenting) {
|
|
var t2, n2, i2 = this.renderer.xr.getReferenceSpace(), r2 = e.getViewerPose(i2);
|
|
return this.xrHitTestSource && r2 ? this.transient ? (t2 = e.getHitTestResultsForTransientInput(this.xrHitTestSource)).length > 0 && (n2 = t2[0].results).length > 0 && (this.lastHitTest = n2[0], n2[0].getPose(i2)) : (t2 = e.getHitTestResults(this.xrHitTestSource)).length > 0 && (this.lastHitTest = t2[0], t2[0].getPose(i2)) : undefined;
|
|
}
|
|
}, _l.updateAnchorPoses = function(e, t2) {
|
|
var n2 = e.trackedAnchors || _l.prototype.previousFrameAnchors;
|
|
_l.prototype.previousFrameAnchors.forEach(function(e2) {
|
|
n2.has(e2) || _l.prototype.anchorToObject3D.delete(e2);
|
|
}), n2.forEach(function(n3) {
|
|
var i2, r2, o2, s2;
|
|
try {
|
|
if (i2 = e.getPose(n3.anchorSpace, t2)) {
|
|
if (!(r2 = _l.prototype.anchorToObject3D.get(n3)))
|
|
return;
|
|
o2 = r2.offset, s2 = r2.object3D, jl(i2, s2, o2);
|
|
}
|
|
} catch (e2) {
|
|
console.error("while updating anchor poses:", e2);
|
|
}
|
|
}), _l.prototype.previousFrameAnchors = n2;
|
|
}, cs("ar-hit-test", { schema: { target: { type: "selector" }, enabled: { default: true }, src: { default: "data:image/webp;base64,UklGRkQHAABXRUJQVlA4WAoAAAAQAAAA/wEA/wEAQUxQSL0DAAARDzD/ERGCjrY9sYYFfgo6aa1kJ7K0w9Lo3AadLSVeFxevQwj5kuM8RfR/Atw/C0+ozB/oUBrloFZs6ElSW88j1KA4yExNWQaqRZquIDF0JYmlq0hAuUDTFu66tng3teW7pa3cQf1V1edvur54M/Slm6Wv3Gx9zw0MXlQLntcsBN6wkHjTQuYtC4W3LTw8mGRVG57TbAROtxHfZNhInGkjc5aNwtk2Hg6Mvki14k+NkZzCwQgCxalcAv3kddRTPI1DcUrXId1FLf1uHpzaQz4tquhZVLlKesbVpqKeTj0n0F5PpXDlFN9UqmhalL/ImuZFo6KmToWLoKlddMprqlS8cKovBvHo2kTiFV2LN4msaxKZl3QNiair8xYRdDWivIvXVXmbcMqJ51UebZuFXxZt6xd4laxtciqRtA3Cv0nU1t+kEUFbI8JvCa+tvkm3FDlO/W+OR99+kWEp/YYo+tYfTVnf/K8cE/F///3vv//993eeL+a+uvjawLcX3xjYvJotBFY3kVjTRGFtE+BU2AiMbiQyhpHMWEYeBozAH5qNBYRDB5KBCaTDBKKBAZTDBoKBDjwHAN5ABeCJBsAZcAAC0YHHxAYSMYBiYgGZWEA2MYFCbCCZGAAIANFEB+AnYgMQTDQAYSJ2AN5EBZAm4gDgTDgAeSIu4DGygTIRN1CMLOCZiACykQlg4jsAycgA8AO+BxCNdJyDkcbwRirDGXGnx8w+FDPrkM3MQ9JQZMYhiiwV/RDMtIM3U1/DmXHUo+IR2kSR2ToWkQ1NIn2qf2J8LCqJKiDUiSADHY3whirhdHgZ94HKaR97PhE+twEUJUFoAcgyTct8hfSxSkShASDKdMJ/ritKHwgyQ0sD4D/miCxU5SbhOOUDTnZpccCjYP/i0bZ/8bAgtVGEoGapWIQXyzKVKLwgNJFk2rtMIgoNRJlOZF7SNSSyUEeQmbxBFKEmtYjEe8S8zOZ1AkJVCmS88FJOtF40Ksg4oUaFiygk3C8qlTVNyl8UTevCUdAE2t14PfVqU1FPp57TopKeQZWromddTQp6QOfTOEQt/ZDuipZ11w/wOiqO8dRORcc6BQEkDQMClaHcn5wV9yLbxsNZNgpn2sicYSNxuo34Js1G4FQbnuNsOPa28PCWhcKbFjJvWEi8ZiHwqgXPcxbc5db33Cx95WboSzddX7yp+vyN0+eul7ZyN7Xlu64t3jVt4c5pc4JLV5EYupJE0xUknC4nOjVlmaYpyLit53HCQ0+ScnqceNcS5dzUkd0/CwMAVlA4IGADAAAQXwCdASoAAgACP8ne6Wy/tjCpqJ/IA/A5CWlu4XYBG/Pz8AfwD8APz//f3v8E1fuHZnxKYACtfuHZnxKYACrYTb5mOslhxu843ecbvON3nG7zjd3a0VCn7G1MABVxwH/Xd25gAK1+4dmfEpe2+PHhQaj75++riG6FuYACtfuHZnxKYACRrK3q9xO8Ss3uWKnMhs/rDF1hi6wxdYYusMXWGI5QRcCFDZog5OgqNlse1NDuz/UoFa/cOzPiUwAEsAOK4/nu5eZHK2tlXxJfNYlMABWv3Dsz4bvNJ5YA/LtxJ38SmAArX7h2Z8Sk5vdZUYv7mZPiUwAFa/cOzPh21s5OgZxf1mfEpemRyFr/rM+JS9noA/LtxJ38SmAAlUJIotzAASn6TjdhK+D3Dsz4dyvB7h2Z8O2tnJ0DOL+sz4lL2nKLT4lL/+iSLOocxq639w7M34MNZdm55uJ8v8ra2cpVZnxKTq2F3PN/cNksAfl24k7+JTAASqrD37h2Z7b1W+VtbOUqsz4lJ1bC7nm/uGyWAPy7cSd/EpgAJVVh79w7M9t6rfK2tnKVWZ8Sk6thdzzf3DZLAH5duJO/iUwAEqqw9+4dme29VvlbWzlKrM+JSdWwu55v7hslgD8u3EnfxKYACVVYe/cOzPbeq3ytrZylVme0kYJ8557FLerqFrzIbPrrf3DZLAH5duJO/iUvaVMS9BoaF4p7pSDFTP1XMyfElelrM0DOL+sz4eBJ13nV1OppBGPuKb4YzXQgq9uH19uS/0+JS9t9fr6ZUlQBelDG6GMgq97otb5QMPJwtKyBTbFp8Sl7b6/X0ykkawEOsgdiE6Fi0vb/Eve6xkwsmug0Z4nGNHQO8839bpTsjpz7SWIJxKagvd1QWMa6FYT1KEw3j4XDT6vJ9Xk+nyfT5Pq8n1eEmk5dinMM/9Fcfz4Z3Dsz3KD2dw7LxBRxKrqUUGQPH/7zxr1KIfNpLEJ0MZB2ITM/0Z2EFoh12NlXnEcpYcbvON3nG7zjd5xu84vfcNIAAP7+y8ceyzbVxkakPYY4lcr72fqOnDwipv+yxC71wAADBrjKnAAAAAAAAAAAAAAw7oNGHttqWONcoFN/2WIDc2pa6WVFtFYROlsaMaTXdcOjXHz93+YxAglKa4AAAAA=", type: "map" }, type: { default: "footprint", oneOf: ["footprint", "map"] }, footprintDepth: { default: 0.1 }, mapSize: { type: "vec2", default: { x: 0.5, y: 0.5 } } }, sceneOnly: true, init: function() {
|
|
this.hitTest = null, this.imageDataArray = new Uint8ClampedArray(1048576), this.imageData = new ImageData(this.imageDataArray, 512, 512), this.textureCache = new Map, this.orthoCam = new Re.OrthographicCamera, this.orthoCam.layers.set(21), this.textureTarget = new Re.WebGLRenderTarget(512, 512, {}), this.basicMaterial = new Re.MeshBasicMaterial({ color: 0, side: Re.DoubleSide }), this.canvas = document.createElement("canvas"), this.context = this.canvas.getContext("2d"), this.context.imageSmoothingEnabled = false, this.canvas.width = 512, this.canvas.height = 512, this.canvasTexture = new Re.CanvasTexture(this.canvas, { alpha: true }), this.canvasTexture.flipY = false;
|
|
var e = this.el.getAttribute("webxr"), t2 = e.optionalFeatures;
|
|
t2.includes("hit-test") && t2.includes("anchors") || (t2.push("hit-test"), t2.push("anchors"), this.el.setAttribute("webxr", e)), this.el.sceneEl.renderer.xr.addEventListener("sessionend", function() {
|
|
this.hitTest = null;
|
|
}.bind(this)), this.el.sceneEl.addEventListener("enter-vr", function() {
|
|
if (this.el.is("ar-mode")) {
|
|
var e2 = this.el.sceneEl.renderer, t3 = this.session = e2.xr.getSession();
|
|
this.hasPosedOnce = false, this.bboxMesh.visible = false, Fl || (Fl = new Map), t3.requestReferenceSpace("viewer").then(function(t4) {
|
|
this.viewerHitTest = this.hitTest = new _l(e2, { space: t4 }), this.el.emit("ar-hit-test-start");
|
|
}.bind(this));
|
|
var n2 = this;
|
|
this.el.sceneEl.addEventListener("controllersupdated", function() {
|
|
var t4 = this.xrSession && this.xrSession.inputSources;
|
|
if (t4) {
|
|
for (var i3 = 0;i3 < t4.length; ++i3)
|
|
if (t4[i3].targetRayMode === "tracked-pointer") {
|
|
n2.hitTest = new _l(e2, { space: t4[i3].targetRaySpace }), Fl.set(t4[i3], n2.hitTest), n2.viewerHitTest && typeof n2.viewerHitTest.cancel == "function" && (n2.viewerHitTest.cancel(), n2.viewerHitTest = null);
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
var i2 = "generic-touchscreen", r2 = new _l(e2, { profile: i2 });
|
|
t3.addEventListener("selectstart", function(t4) {
|
|
if (this.data.enabled === true) {
|
|
var n3 = t4.inputSource;
|
|
this.bboxMesh.visible = true, this.hasPosedOnce === true && (this.el.emit("ar-hit-test-select-start", { inputSource: n3, position: this.bboxMesh.position, orientation: this.bboxMesh.quaternion }), n3.profiles[0] === i2 ? this.hitTest = r2 : (this.hitTest = Fl.get(n3) || new _l(e2, { space: n3.targetRaySpace }), Fl.set(n3, this.hitTest)));
|
|
}
|
|
}.bind(this)), t3.addEventListener("selectend", function(e3) {
|
|
if (this.hitTest && this.data.enabled === true) {
|
|
var t4, n3 = e3.inputSource;
|
|
this.hasPosedOnce === true && (this.bboxMesh.visible = false, this.data.target && (t4 = this.data.target.object3D) && (jl.tempFakePose.transform.position.copy(this.bboxMesh.position), jl.tempFakePose.transform.orientation.copy(this.bboxMesh.quaternion), jl(jl.tempFakePose, t4, this.bboxOffset), t4.visible = true, this.hitTest.anchorFromLastHitTestResult(t4, this.bboxOffset)), this.el.emit("ar-hit-test-select", { inputSource: n3, position: this.bboxMesh.position, orientation: this.bboxMesh.quaternion }), this.hitTest = null);
|
|
} else
|
|
this.hitTest = null;
|
|
}.bind(this));
|
|
}
|
|
}.bind(this)), this.bboxOffset = new Re.Vector3, this.update = this.update.bind(this), this.makeBBox();
|
|
}, update: function() {
|
|
this.data.enabled === false && (this.hitTest = null, this.bboxMesh.visible = false), this.data.target && (this.data.target.object3D ? (this.data.target.addEventListener("model-loaded", this.update), this.data.target.object3D.layers.enable(21), this.data.target.object3D.traverse(function(e) {
|
|
e.layers.enable(21);
|
|
})) : this.data.target.addEventListener("loaded", this.update, { once: true })), this.bboxNeedsUpdate = true;
|
|
}, makeBBox: function() {
|
|
var e = new Re.PlaneGeometry(1, 1), t2 = new Re.MeshBasicMaterial({ transparent: true, color: 16777215 });
|
|
e.rotateX(-Math.PI / 2), e.rotateY(-Math.PI / 2), this.bbox = new Re.Box3, this.bboxMesh = new Re.Mesh(e, t2), this.el.setObject3D("ar-hit-test", this.bboxMesh), this.bboxMesh.visible = false;
|
|
}, updateFootprint: function() {
|
|
var e, t2, n2, i2 = this.el.sceneEl.renderer, r2 = i2.xr.enabled;
|
|
this.bboxMesh.material.map = this.canvasTexture, this.bboxMesh.material.needsUpdate = true, this.orthoCam.rotation.set(-Math.PI / 2, 0, -Math.PI / 2), this.orthoCam.position.copy(this.bboxMesh.position), this.orthoCam.position.y -= this.bboxMesh.scale.y / 2, this.orthoCam.near = 0.1, this.orthoCam.far = this.orthoCam.near + this.data.footprintDepth * this.bboxMesh.scale.y, this.orthoCam.position.y += this.orthoCam.far, this.orthoCam.right = this.bboxMesh.scale.z / 2, this.orthoCam.left = -this.bboxMesh.scale.z / 2, this.orthoCam.top = this.bboxMesh.scale.x / 2, this.orthoCam.bottom = -this.bboxMesh.scale.x / 2, this.orthoCam.updateProjectionMatrix(), t2 = i2.getRenderTarget(), i2.setRenderTarget(this.textureTarget), i2.xr.enabled = false, n2 = this.el.object3D.background, this.el.object3D.overrideMaterial = this.basicMaterial, this.el.object3D.background = null, i2.render(this.el.object3D, this.orthoCam), this.el.object3D.background = n2, this.el.object3D.overrideMaterial = null, i2.xr.enabled = r2, i2.setRenderTarget(t2), i2.readRenderTargetPixels(this.textureTarget, 0, 0, 512, 512, this.imageDataArray), this.context.putImageData(this.imageData, 0, 0), this.context.shadowColor = "white", this.context.shadowBlur = 10, this.context.drawImage(this.canvas, 0, 0), e = this.context.getImageData(0, 0, 512, 512);
|
|
for (var o2 = 0;o2 < 262144; o2++)
|
|
e.data[4 * o2 + 3] !== 0 && e.data[4 * o2 + 3] !== 255 && (e.data[4 * o2 + 3] = 128);
|
|
this.context.putImageData(e, 0, 0), this.canvasTexture.needsUpdate = true;
|
|
}, tick: function() {
|
|
var e, t2, n2 = this.el.sceneEl.frame, i2 = this.el.sceneEl.renderer;
|
|
(n2 && _l.updateAnchorPoses(n2, i2.xr.getReferenceSpace()), this.bboxNeedsUpdate) && (this.bboxNeedsUpdate = false, this.data.target && this.data.type !== "map" || (this.textureCache.has(this.data.src) ? t2 = this.textureCache.get(this.data.src) : (t2 = new Re.TextureLoader().load(this.data.src), this.textureCache.set(this.data.src, t2)), this.bboxMesh.material.map = t2, this.bboxMesh.material.needsUpdate = true), this.data.target && this.data.target.object3D ? (this.bbox.setFromObject(this.data.target.object3D), this.bbox.getCenter(this.bboxMesh.position), this.bbox.getSize(this.bboxMesh.scale), this.data.type === "footprint" && (this.bboxMesh.scale.x *= 1.04, this.bboxMesh.scale.z *= 1.04, this.updateFootprint()), this.bboxMesh.position.y -= this.bboxMesh.scale.y / 2, this.bboxOffset.copy(this.bboxMesh.position), this.bboxOffset.sub(this.data.target.object3D.position)) : this.bboxMesh.scale.set(this.data.mapSize.x, 1, this.data.mapSize.y));
|
|
this.hitTest && (e = this.hitTest.doHit(n2)) && (this.hasPosedOnce !== true && (this.hasPosedOnce = true, this.el.emit("ar-hit-test-achieved")), this.bboxMesh.visible = true, this.bboxMesh.position.copy(e.transform.position), this.bboxMesh.quaternion.copy(e.transform.orientation));
|
|
} }), cs("background", { schema: { color: { type: "color", default: "black" }, transparent: { default: false } }, sceneOnly: true, update: function() {
|
|
var e = this.data, t2 = this.el.object3D;
|
|
e.transparent ? t2.background = null : t2.background = new Re.Color(e.color);
|
|
}, remove: function() {
|
|
this.el.object3D.background = null;
|
|
} }), cs("debug", { schema: { default: true }, sceneOnly: true });
|
|
cs("device-orientation-permission-ui", { schema: { enabled: { default: true }, deviceMotionMessage: { default: "This immersive website requires access to your device motion sensors." }, httpsMessage: { default: "Access this site over HTTPS to enter VR mode and grant access to the device sensors." }, denyButtonText: { default: "Deny" }, allowButtonText: { default: "Allow" }, cancelButtonText: { default: "Cancel" } }, sceneOnly: true, init: function() {
|
|
var e = this;
|
|
this.data.enabled && (window.isSecureContext || this.showHTTPAlert(), typeof DeviceOrientationEvent != "undefined" && DeviceOrientationEvent.requestPermission ? (this.onDeviceMotionDialogAllowClicked = this.onDeviceMotionDialogAllowClicked.bind(this), this.onDeviceMotionDialogDenyClicked = this.onDeviceMotionDialogDenyClicked.bind(this), DeviceOrientationEvent.requestPermission().then(function() {
|
|
e.el.emit("deviceorientationpermissiongranted"), e.permissionGranted = true;
|
|
}).catch(function() {
|
|
var t2, n2, i2, r2, o2, s2, a2, A2;
|
|
e.devicePermissionDialogEl = (t2 = e.data.denyButtonText, n2 = e.data.allowButtonText, i2 = e.data.deviceMotionMessage, r2 = e.onDeviceMotionDialogAllowClicked, o2 = e.onDeviceMotionDialogDenyClicked, (s2 = document.createElement("div")).classList.add(ql), (a2 = document.createElement("button")).classList.add(Vl, "a-dialog-deny-button"), a2.setAttribute(hi, ""), a2.innerHTML = t2, s2.appendChild(a2), (A2 = document.createElement("button")).classList.add(Vl, "a-dialog-allow-button"), A2.setAttribute(hi, ""), A2.innerHTML = n2, s2.appendChild(A2), A2.addEventListener("click", function(e2) {
|
|
e2.stopPropagation(), r2();
|
|
}), a2.addEventListener("click", function(e2) {
|
|
e2.stopPropagation(), o2();
|
|
}), zl(i2, s2)), e.el.appendChild(e.devicePermissionDialogEl);
|
|
})) : this.permissionGranted = true);
|
|
}, remove: function() {
|
|
this.devicePermissionDialogEl && this.el.removeChild(this.devicePermissionDialogEl);
|
|
}, onDeviceMotionDialogDenyClicked: function() {
|
|
this.remove();
|
|
}, showHTTPAlert: function() {
|
|
var e, t2, n2, i2, r2, o2 = this, s2 = (e = o2.data.cancelButtonText, t2 = o2.data.httpsMessage, n2 = function() {
|
|
o2.el.removeChild(s2);
|
|
}, (i2 = document.createElement("div")).classList.add(ql), (r2 = document.createElement("button")).classList.add(Vl, "a-dialog-ok-button"), r2.setAttribute(hi, ""), r2.innerHTML = e, i2.appendChild(r2), r2.addEventListener("click", function(e2) {
|
|
e2.stopPropagation(), n2();
|
|
}), zl(t2, i2));
|
|
this.el.appendChild(s2);
|
|
}, onDeviceMotionDialogAllowClicked: function() {
|
|
var e = this;
|
|
this.el.emit("deviceorientationpermissionrequested"), DeviceOrientationEvent.requestPermission().then(function(t2) {
|
|
t2 === "granted" ? (e.el.emit("deviceorientationpermissiongranted"), e.permissionGranted = true) : e.el.emit("deviceorientationpermissionrejected"), e.remove();
|
|
}).catch(console.error);
|
|
} }), cs("embedded", { dependencies: ["xr-mode-ui"], schema: { default: true }, sceneOnly: true, update: function() {
|
|
var e = this.el, t2 = e.querySelector(".a-enter-vr");
|
|
this.data === true ? (t2 && t2.classList.add("embedded"), e.removeFullScreenStyles()) : (t2 && t2.classList.remove("embedded"), e.addFullScreenStyles());
|
|
} });
|
|
Yl = "https://unpkg.com/aframe-inspector@" + function() {
|
|
var e = ca.split(".");
|
|
return e[2] = "x", e.join(".");
|
|
}() + "/dist/aframe-inspector.min.js";
|
|
cs("inspector", { schema: { url: { default: Yl } }, sceneOnly: true, init: function() {
|
|
this.firstPlay = true, this.onKeydown = this.onKeydown.bind(this), this.onMessage = this.onMessage.bind(this), this.initOverlay(), window.addEventListener("keydown", this.onKeydown), window.addEventListener("message", this.onMessage);
|
|
}, play: function() {
|
|
var e;
|
|
this.firstPlay && (e = so("inspector")) !== "false" && e && (this.openInspector(), this.firstPlay = false);
|
|
}, initOverlay: function() {
|
|
this.loadingMessageEl = document.createElement("div"), this.loadingMessageEl.classList.add("a-inspector-loader"), this.loadingMessageEl.innerHTML = 'Loading Inspector<span class="dots"><span>.</span><span>.</span><span>.</span></span>';
|
|
}, remove: function() {
|
|
this.removeEventListeners();
|
|
}, onKeydown: function(e) {
|
|
e.keyCode === 73 && (e.ctrlKey && e.altKey || e.getModifierState("AltGraph")) && this.openInspector();
|
|
}, showLoader: function() {
|
|
document.body.appendChild(this.loadingMessageEl);
|
|
}, hideLoader: function() {
|
|
document.body.removeChild(this.loadingMessageEl);
|
|
}, onMessage: function(e) {
|
|
e.data === "INJECT_AFRAME_INSPECTOR" && this.openInspector();
|
|
}, openInspector: function(e) {
|
|
var t2, n2 = this;
|
|
AFRAME.INSPECTOR || AFRAME.inspectorInjected ? AFRAME.INSPECTOR.open(e) : (this.showLoader(), (t2 = document.createElement("script")).src = this.data.url, t2.setAttribute("data-name", "aframe-inspector"), t2.setAttribute(hi, ""), t2.onload = function() {
|
|
AFRAME.INSPECTOR.open(e), n2.hideLoader(), n2.removeEventListeners();
|
|
}, t2.onerror = function() {
|
|
n2.loadingMessageEl.innerHTML = "Error loading Inspector";
|
|
}, document.head.appendChild(t2), AFRAME.inspectorInjected = true);
|
|
}, removeEventListeners: function() {
|
|
window.removeEventListener("keydown", this.onKeydown), window.removeEventListener("message", this.onMessage);
|
|
} }), cs("fog", { schema: { color: { type: "color", default: "#000" }, density: { default: 0.00025 }, far: { default: 1000, min: 0 }, near: { default: 1, min: 0 }, type: { default: "linear", oneOf: ["linear", "exponential"] } }, sceneOnly: true, update: function() {
|
|
var e = this.data, t2 = this.el, n2 = this.el.object3D.fog;
|
|
n2 && e.type === n2.name ? Object.keys(this.schema).forEach(function(t3) {
|
|
var i2 = e[t3];
|
|
t3 === "color" && (i2 = new Re.Color(i2)), n2[t3] = i2;
|
|
}) : t2.object3D.fog = function(e2) {
|
|
var t3;
|
|
return (t3 = e2.type === "exponential" ? new Re.FogExp2(e2.color, e2.density) : new Re.Fog(e2.color, e2.near, e2.far)).name = e2.type, t3;
|
|
}(e);
|
|
}, remove: function() {
|
|
var e = this.el;
|
|
this.el.object3D.fog && (e.object3D.fog = null);
|
|
} }), cs("keyboard-shortcuts", { schema: { enterVR: { default: true }, exitVR: { default: true } }, sceneOnly: true, init: function() {
|
|
this.onKeyup = this.onKeyup.bind(this);
|
|
}, play: function() {
|
|
window.addEventListener("keyup", this.onKeyup, false);
|
|
}, pause: function() {
|
|
window.removeEventListener("keyup", this.onKeyup);
|
|
}, onKeyup: function(e) {
|
|
var t2 = this.el;
|
|
io(e) && (this.data.enterVR && e.keyCode === 70 && t2.enterVR(), this.data.exitVR && e.keyCode === 27 && t2.exitVR());
|
|
} });
|
|
Kl = fi("components:pool:warn");
|
|
cs("pool", { schema: { container: { default: "" }, mixin: { default: "" }, size: { default: 0 }, dynamic: { default: false } }, sceneOnly: true, multiple: true, initPool: function() {
|
|
var e;
|
|
for (this.availableEls = [], this.usedEls = [], this.data.mixin || Kl("No mixin provided for pool component."), this.data.container && (this.container = document.querySelector(this.data.container), this.container || Kl("Container " + this.data.container + " not found.")), this.container = this.container || this.el, e = 0;e < this.data.size; ++e)
|
|
this.createEntity();
|
|
}, update: function(e) {
|
|
var t2 = this.data;
|
|
e.mixin === t2.mixin && e.size === t2.size || this.initPool();
|
|
}, createEntity: function() {
|
|
var e;
|
|
(e = document.createElement("a-entity")).play = this.wrapPlay(e.play), e.setAttribute("mixin", this.data.mixin), e.object3D.visible = false, e.pause(), this.container.appendChild(e), this.availableEls.push(e);
|
|
var t2 = this.usedEls;
|
|
e.addEventListener("loaded", function() {
|
|
t2.indexOf(e) === -1 && (e.object3DParent = e.object3D.parent, e.object3D.parent.remove(e.object3D));
|
|
});
|
|
}, wrapPlay: function(e) {
|
|
var t2 = this.usedEls;
|
|
return function() {
|
|
t2.indexOf(this) !== -1 && e.call(this);
|
|
};
|
|
}, requestEntity: function() {
|
|
var e;
|
|
if (this.availableEls.length === 0) {
|
|
if (this.data.dynamic === false)
|
|
return void Kl("Requested entity from empty pool: " + this.attrName);
|
|
Kl("Requested entity from empty pool. This pool is dynamic and will resize automatically. You might want to increase its initial size: " + this.attrName), this.createEntity();
|
|
}
|
|
return e = this.availableEls.shift(), this.usedEls.push(e), e.object3DParent && (e.object3DParent.add(e.object3D), this.updateRaycasters()), e.object3D.visible = true, e;
|
|
}, returnEntity: function(e) {
|
|
var t2 = this.usedEls.indexOf(e);
|
|
if (t2 !== -1)
|
|
return this.usedEls.splice(t2, 1), this.availableEls.push(e), e.object3DParent = e.object3D.parent, e.object3D.parent.remove(e.object3D), this.updateRaycasters(), e.object3D.visible = false, e.pause(), e;
|
|
Kl("The returned entity was not previously pooled from " + this.attrName);
|
|
}, updateRaycasters: function() {
|
|
document.querySelectorAll("[raycaster]").forEach(function(e) {
|
|
e.components.raycaster.setDirty();
|
|
});
|
|
} }), cs("real-world-meshing", { schema: { filterLabels: { type: "array" }, meshesEnabled: { default: true }, meshMixin: { default: true }, planesEnabled: { default: true }, planeMixin: { default: "" } }, sceneOnly: true, init: function() {
|
|
var e = this.el.getAttribute("webxr"), t2 = e.requiredFeatures;
|
|
t2.indexOf("mesh-detection") === -1 && (t2.push("mesh-detection"), this.el.setAttribute("webxr", e)), t2.indexOf("plane-detection") === -1 && (t2.push("plane-detection"), this.el.setAttribute("webxr", e)), this.meshEntities = [], this.initWorldMeshEntity = this.initWorldMeshEntity.bind(this);
|
|
}, tick: function() {
|
|
this.el.is("ar-mode") && (this.detectMeshes(), this.updateMeshes());
|
|
}, detectMeshes: function() {
|
|
var e, t2, n2, i2 = this.data, r2 = this.el, o2 = this.meshEntities, s2 = false, a2 = [], A2 = this.data.filterLabels;
|
|
e = (n2 = r2.frame).detectedMeshes, t2 = n2.detectedPlanes;
|
|
for (var l2 = 0;l2 < o2.length; l2++)
|
|
o2[l2].present = false;
|
|
if (i2.meshesEnabled) {
|
|
for (var c2 of e.values())
|
|
if (!A2.length || A2.indexOf(c2.semanticLabel) !== -1) {
|
|
for (l2 = 0;l2 < o2.length; l2++)
|
|
if (c2 === o2[l2].mesh) {
|
|
s2 = true, o2[l2].present = true, o2[l2].lastChangedTime < c2.lastChangedTime && this.updateMeshGeometry(o2[l2].el, c2), o2[l2].lastChangedTime = c2.lastChangedTime;
|
|
break;
|
|
}
|
|
s2 || a2.push(c2), s2 = false;
|
|
}
|
|
}
|
|
if (i2.planesEnabled) {
|
|
for (c2 of t2.values())
|
|
if (!A2.length || A2.indexOf(c2.semanticLabel) !== -1) {
|
|
for (l2 = 0;l2 < o2.length; l2++)
|
|
if (c2 === o2[l2].mesh) {
|
|
s2 = true, o2[l2].present = true, o2[l2].lastChangedTime < c2.lastChangedTime && this.updateMeshGeometry(o2[l2].el, c2), o2[l2].lastChangedTime = c2.lastChangedTime;
|
|
break;
|
|
}
|
|
s2 || a2.push(c2), s2 = false;
|
|
}
|
|
}
|
|
this.deleteMeshes(), this.createNewMeshes(a2);
|
|
}, updateMeshes: function() {
|
|
var e = new Re.Matrix4;
|
|
return function() {
|
|
for (var t2, n2, i2, r2 = this.el, o2 = r2.frame, s2 = this.meshEntities, a2 = r2.renderer.xr.getReferenceSpace(), A2 = 0;A2 < s2.length; A2++)
|
|
i2 = s2[A2].mesh.meshSpace || s2[A2].mesh.planeSpace, t2 = o2.getPose(i2, a2), (n2 = s2[A2].el).hasLoaded && (e.fromArray(t2.transform.matrix), e.decompose(n2.object3D.position, n2.object3D.quaternion, n2.object3D.scale));
|
|
};
|
|
}(), deleteMeshes: function() {
|
|
for (var e = this.meshEntities, t2 = [], n2 = 0;n2 < e.length; n2++)
|
|
e[n2].present ? t2.push(e[n2]) : this.el.removeChild(e[n2]);
|
|
this.meshEntities = t2;
|
|
}, createNewMeshes: function(e) {
|
|
for (var t2, n2 = 0;n2 < e.length; n2++)
|
|
t2 = document.createElement("a-entity"), this.meshEntities.push({ mesh: e[n2], el: t2 }), t2.addEventListener("loaded", this.initWorldMeshEntity), this.el.appendChild(t2);
|
|
}, initMeshGeometry: function(e) {
|
|
var t2, n2, i2;
|
|
if (e instanceof XRPlane) {
|
|
n2 = new Re.Shape, i2 = e.polygon;
|
|
for (var r2 = 0;r2 < i2.length; ++r2)
|
|
r2 === 0 ? n2.moveTo(i2[r2].x, i2[r2].z) : n2.lineTo(i2[r2].x, i2[r2].z);
|
|
return (t2 = new Re.ShapeGeometry(n2)).rotateX(Math.PI / 2), t2;
|
|
}
|
|
return (t2 = new Re.BufferGeometry).setAttribute("position", new Re.BufferAttribute(e.vertices, 3)), t2.setIndex(new Re.BufferAttribute(e.indices, 1)), t2;
|
|
}, initWorldMeshEntity: function(e) {
|
|
for (var t2, n2, i2, r2 = e.target, o2 = this.meshEntities, s2 = 0;s2 < o2.length; s2++)
|
|
if (o2[s2].el === r2) {
|
|
i2 = o2[s2];
|
|
break;
|
|
}
|
|
t2 = this.initMeshGeometry(i2.mesh), n2 = new Re.Mesh(t2, new Re.MeshBasicMaterial({ color: 16777215 * Math.random(), side: Re.DoubleSide })), r2.setObject3D("mesh", n2), i2.mesh instanceof XRPlane && this.data.planeMixin ? r2.setAttribute("mixin", this.data.planeMixin) : this.data.meshMixin && r2.setAttribute("mixin", this.data.meshMixin), r2.setAttribute("data-world-mesh", i2.mesh.semanticLabel);
|
|
}, updateMeshGeometry: function(e, t2) {
|
|
var n2 = e.getObject3D("mesh");
|
|
n2.geometry.dispose(), n2.geometry = this.initMeshGeometry(t2);
|
|
} }), cs("reflection", { schema: { directionalLight: { type: "selector" } }, sceneOnly: true, init: function() {
|
|
var e = this;
|
|
this.cubeRenderTarget = new Re.WebGLCubeRenderTarget(16), this.cubeCamera = new Re.CubeCamera(0.1, 1000, this.cubeRenderTarget), this.lightingEstimationTexture = new Re.WebGLCubeRenderTarget(16).texture, this.needsVREnvironmentUpdate = true;
|
|
var t2 = this.el.getAttribute("webxr"), n2 = t2.optionalFeatures;
|
|
n2.includes("light-estimation") || (n2.push("light-estimation"), this.el.setAttribute("webxr", t2)), this.el.addEventListener("enter-vr", function() {
|
|
e.el.is("ar-mode") && e.el.renderer.xr.getSession().requestLightProbe && e.startLightProbe();
|
|
}), this.el.addEventListener("exit-vr", function() {
|
|
e.xrLightProbe && e.stopLightProbe();
|
|
}), this.el.object3D.environment = this.cubeRenderTarget.texture;
|
|
}, stopLightProbe: function() {
|
|
this.xrLightProbe = null, this.probeLight && (this.probeLight.components.light.light.intensity = 0), this.needsVREnvironmentUpdate = true, this.el.object3D.environment = this.cubeRenderTarget.texture;
|
|
}, startLightProbe: function() {
|
|
this.needsLightProbeUpdate = true;
|
|
}, setupLightProbe: function() {
|
|
var e = this.el.renderer, t2 = e.xr.getSession(), n2 = this, i2 = e.getContext();
|
|
if (!this.probeLight) {
|
|
var r2 = document.createElement("a-light");
|
|
r2.setAttribute("type", "probe"), r2.setAttribute("intensity", 0), this.el.appendChild(r2), this.probeLight = r2;
|
|
}
|
|
switch (t2.preferredReflectionFormat) {
|
|
case "srgba8":
|
|
i2.getExtension("EXT_sRGB");
|
|
break;
|
|
case "rgba16f":
|
|
i2.getExtension("OES_texture_half_float");
|
|
}
|
|
this.glBinding = new XRWebGLBinding(t2, i2), i2.getExtension("EXT_sRGB"), i2.getExtension("OES_texture_half_float"), t2.requestLightProbe().then(function(e2) {
|
|
n2.xrLightProbe = e2, e2.addEventListener("reflectionchange", n2.updateXRCubeMap.bind(n2));
|
|
}).catch(function(e2) {
|
|
console.warn("Lighting estimation not supported: " + e2.message), console.warn('Are you missing: webxr="optionalFeatures: light-estimation;" from <a-scene>?');
|
|
});
|
|
}, updateXRCubeMap: function() {
|
|
var e = this.el.renderer, t2 = this.glBinding.getReflectionCubeMap(this.xrLightProbe);
|
|
t2 && (e.properties.get(this.lightingEstimationTexture).__webglTexture = t2, this.lightingEstimationTexture.needsPMREMUpdate = true, this.el.object3D.environment = this.lightingEstimationTexture);
|
|
}, tick: function() {
|
|
var e = this.el.object3D, t2 = this.el.renderer, n2 = this.el.frame;
|
|
if (n2 && this.xrLightProbe) {
|
|
var i2 = n2.getLightEstimate(this.xrLightProbe);
|
|
i2 && function(e2, t3, n3, i3) {
|
|
var r2 = Math.max(e2.primaryLightIntensity.x, Math.max(e2.primaryLightIntensity.y, e2.primaryLightIntensity.z));
|
|
t3.sh.fromArray(e2.sphericalHarmonicsCoefficients), t3.intensity = 3.14, n3 && (n3.color.setRGB(e2.primaryLightIntensity.x / r2, e2.primaryLightIntensity.y / r2, e2.primaryLightIntensity.z / r2), n3.intensity = r2, i3.copy(e2.primaryLightDirection));
|
|
}(i2, this.probeLight.components.light.light, this.data.directionalLight && this.data.directionalLight.components.light.light, this.data.directionalLight && this.data.directionalLight.object3D.position);
|
|
}
|
|
this.needsVREnvironmentUpdate && (e.environment = null, this.needsVREnvironmentUpdate = false, this.cubeCamera.position.set(0, 1.6, 0), this.cubeCamera.update(t2, e), e.environment = this.cubeRenderTarget.texture), this.needsLightProbeUpdate && n2 && (this.setupLightProbe(), this.needsLightProbeUpdate = false);
|
|
}, remove: function() {
|
|
this.el.object3D.environment = null, this.probeLight && this.el.removeChild(this.probeLight);
|
|
} });
|
|
Wl = ["attribute vec3 position;", "attribute vec2 uv;", "uniform mat4 projectionMatrix;", "uniform mat4 modelViewMatrix;", "varying vec2 vUv;", "void main() {", " vUv = vec2( 1.- uv.x, uv.y );", " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", "}"].join(`
|
|
`);
|
|
Jl = ["precision mediump float;", "uniform samplerCube map;", "varying vec2 vUv;", "#define M_PI 3.141592653589793238462643383279", "void main() {", " vec2 uv = vUv;", " float longitude = uv.x * 2. * M_PI - M_PI + M_PI / 2.;", " float latitude = uv.y * M_PI;", " vec3 dir = vec3(", " - sin( longitude ) * sin( latitude ),", " cos( latitude ),", " - cos( longitude ) * sin( latitude )", " );", " normalize( dir );", " gl_FragColor = vec4( textureCube( map, dir ).rgb, 1.0 );", "}"].join(`
|
|
`);
|
|
Xl = (cs("screenshot", { schema: { width: { default: 4096 }, height: { default: 2048 }, camera: { type: "selector" } }, sceneOnly: true, setup: function() {
|
|
var e = this.el;
|
|
if (!this.canvas) {
|
|
var t2 = e.renderer.getContext();
|
|
t2 && (this.cubeMapSize = t2.getParameter(t2.MAX_CUBE_MAP_TEXTURE_SIZE), this.material = new Re.RawShaderMaterial({ uniforms: { map: { type: "t", value: null } }, vertexShader: Wl, fragmentShader: Jl, side: Re.DoubleSide }), this.quad = new Re.Mesh(new Re.PlaneGeometry(1, 1), this.material), this.quad.visible = false, this.camera = new Re.OrthographicCamera(-0.5, 0.5, 0.5, -0.5, -1e4, 1e4), this.canvas = document.createElement("canvas"), this.ctx = this.canvas.getContext("2d"), e.object3D.add(this.quad), this.onKeyDown = this.onKeyDown.bind(this));
|
|
}
|
|
}, getRenderTarget: function(e, t2) {
|
|
return new Re.WebGLRenderTarget(e, t2, { colorSpace: this.el.sceneEl.renderer.outputColorSpace, minFilter: Re.LinearFilter, magFilter: Re.LinearFilter, wrapS: Re.ClampToEdgeWrapping, wrapT: Re.ClampToEdgeWrapping, format: Re.RGBAFormat, type: Re.UnsignedByteType });
|
|
}, resize: function(e, t2) {
|
|
this.quad.scale.set(e, t2, 1), this.camera.left = -1 * e / 2, this.camera.right = e / 2, this.camera.top = t2 / 2, this.camera.bottom = -1 * t2 / 2, this.camera.updateProjectionMatrix(), this.canvas.width = e, this.canvas.height = t2;
|
|
}, play: function() {
|
|
window.addEventListener("keydown", this.onKeyDown);
|
|
}, onKeyDown: function(e) {
|
|
var t2 = e.keyCode === 83 && e.ctrlKey && e.altKey;
|
|
if (this.data && t2) {
|
|
var n2 = e.shiftKey ? "equirectangular" : "perspective";
|
|
this.capture(n2);
|
|
}
|
|
}, setCapture: function(e) {
|
|
var t2, n2, i2, r2, o2 = this.el;
|
|
return e === "perspective" ? (this.quad.visible = false, n2 = this.data.camera && this.data.camera.components.camera.camera || o2.camera, t2 = { width: this.data.width, height: this.data.height }) : (n2 = this.camera, r2 = new Re.WebGLCubeRenderTarget(Math.min(this.cubeMapSize, 2048), { format: Re.RGBFormat, generateMipmaps: true, minFilter: Re.LinearMipmapLinearFilter, colorSpace: Re.SRGBColorSpace }), i2 = new Re.CubeCamera(o2.camera.near, o2.camera.far, r2), o2.camera.getWorldPosition(i2.position), o2.camera.getWorldQuaternion(i2.quaternion), i2.update(o2.renderer, o2.object3D), this.quad.material.uniforms.map.value = i2.renderTarget.texture, t2 = { width: this.data.width, height: this.data.height }, this.quad.visible = true), { camera: n2, size: t2, projection: e };
|
|
}, capture: function(e) {
|
|
var t2, n2 = this.el.renderer.xr.enabled, i2 = this.el.renderer;
|
|
this.setup(), i2.xr.enabled = false, t2 = this.setCapture(e), this.renderCapture(t2.camera, t2.size, t2.projection), this.saveCapture(), i2.xr.enabled = n2;
|
|
}, getCanvas: function(e) {
|
|
var t2 = this.el.renderer.xr.enabled, n2 = this.el.renderer;
|
|
this.setup();
|
|
var i2 = this.setCapture(e);
|
|
return n2.xr.enabled = false, this.renderCapture(i2.camera, i2.size, i2.projection), n2.xr.enabled = t2, this.canvas;
|
|
}, renderCapture: function(e, t2, n2) {
|
|
var i2, r2, o2, s2 = this.el.renderer.autoClear, a2 = this.el, A2 = a2.renderer;
|
|
r2 = this.getRenderTarget(t2.width, t2.height), o2 = new Uint8Array(4 * t2.width * t2.height), this.resize(t2.width, t2.height), A2.autoClear = true, A2.clear(), A2.setRenderTarget(r2), A2.render(a2.object3D, e), A2.autoClear = s2, A2.readRenderTargetPixels(r2, 0, 0, t2.width, t2.height, o2), A2.setRenderTarget(null), n2 === "perspective" && (o2 = this.flipPixelsVertically(o2, t2.width, t2.height)), i2 = new ImageData(new Uint8ClampedArray(o2), t2.width, t2.height), this.quad.visible = false, this.ctx.putImageData(i2, 0, 0);
|
|
}, flipPixelsVertically: function(e, t2, n2) {
|
|
for (var i2 = e.slice(0), r2 = 0;r2 < t2; ++r2)
|
|
for (var o2 = 0;o2 < n2; ++o2)
|
|
i2[4 * r2 + o2 * t2 * 4] = e[4 * r2 + (n2 - o2) * t2 * 4], i2[4 * r2 + 1 + o2 * t2 * 4] = e[4 * r2 + 1 + (n2 - o2) * t2 * 4], i2[4 * r2 + 2 + o2 * t2 * 4] = e[4 * r2 + 2 + (n2 - o2) * t2 * 4], i2[4 * r2 + 3 + o2 * t2 * 4] = e[4 * r2 + 3 + (n2 - o2) * t2 * 4];
|
|
return i2;
|
|
}, saveCapture: function() {
|
|
this.canvas.toBlob(function(e) {
|
|
var t2 = "screenshot-" + document.title.toLowerCase() + "-" + Date.now() + ".png", n2 = document.createElement("a"), i2 = URL.createObjectURL(e);
|
|
n2.href = i2, n2.setAttribute("download", t2), n2.innerHTML = "downloading...", n2.style.display = "none", document.body.appendChild(n2), setTimeout(function() {
|
|
n2.click(), document.body.removeChild(n2);
|
|
}, 1);
|
|
}, "image/png");
|
|
} }), i(282));
|
|
Zl = i.n(Xl);
|
|
$l = (i(3729), i(8132), window.aframeStats);
|
|
tc = window.threeStats;
|
|
cs("stats", { schema: { default: true }, sceneOnly: true, init: function() {
|
|
var e = this.el;
|
|
so("stats") !== "false" && (this.stats = function(e2) {
|
|
var t2 = new tc(e2.renderer), n2 = new $l(e2), i2 = e2.isMobile ? [] : [t2, n2];
|
|
return new (Zl())({ css: [], values: { fps: { caption: "fps", below: 30 } }, groups: [{ caption: "Framerate", values: ["fps", "raf"] }], plugins: i2 });
|
|
}(e), this.statsEl = document.querySelector(".rs-base"), this.hideBound = this.hide.bind(this), this.showBound = this.show.bind(this), e.addEventListener("enter-vr", this.hideBound), e.addEventListener("exit-vr", this.showBound));
|
|
}, update: function() {
|
|
if (this.stats)
|
|
return this.data ? this.show() : this.hide();
|
|
}, remove: function() {
|
|
this.el.removeEventListener("enter-vr", this.hideBound), this.el.removeEventListener("exit-vr", this.showBound), this.statsEl && this.statsEl.parentNode.removeChild(this.statsEl);
|
|
}, tick: function() {
|
|
var e = this.stats;
|
|
e && (e("rAF").tick(), e("FPS").frame(), e().update());
|
|
}, hide: function() {
|
|
this.statsEl.classList.add(ec);
|
|
}, show: function() {
|
|
this.statsEl.classList.remove(ec);
|
|
} });
|
|
cs("xr-mode-ui", { dependencies: ["canvas"], schema: { enabled: { default: true }, enterVRButton: { default: "" }, enterVREnabled: { default: true }, enterARButton: { default: "" }, enterAREnabled: { default: true }, XRMode: { default: "vr", oneOf: ["vr", "ar", "xr"] } }, sceneOnly: true, init: function() {
|
|
var e = this, t2 = this.el;
|
|
so("ui") !== "false" && (this.insideLoader = false, this.enterVREl = null, this.enterAREl = null, this.orientationModalEl = null, this.bindMethods(), t2.addEventListener("enter-vr", this.updateEnterInterfaces), t2.addEventListener("exit-vr", this.updateEnterInterfaces), t2.addEventListener("update-vr-devices", this.updateEnterInterfaces), window.addEventListener("message", function(t3) {
|
|
t3.data.type === "loaderReady" && (e.insideLoader = true, e.remove());
|
|
}), window.addEventListener("orientationchange", this.toggleOrientationModalIfNeeded));
|
|
}, bindMethods: function() {
|
|
this.onEnterVRButtonClick = this.onEnterVRButtonClick.bind(this), this.onEnterARButtonClick = this.onEnterARButtonClick.bind(this), this.onModalClick = this.onModalClick.bind(this), this.toggleOrientationModalIfNeeded = this.toggleOrientationModalIfNeeded.bind(this), this.updateEnterInterfaces = this.updateEnterInterfaces.bind(this);
|
|
}, onModalClick: function() {
|
|
this.el.exitVR();
|
|
}, onEnterVRButtonClick: function() {
|
|
this.el.enterVR();
|
|
}, onEnterARButtonClick: function() {
|
|
this.el.enterAR();
|
|
}, update: function() {
|
|
var e, t2, n2, i2 = this.data, r2 = this.el;
|
|
if (!i2.enabled || this.insideLoader || so("ui") === "false")
|
|
return this.remove();
|
|
this.enterVREl || this.enterAREl || this.orientationModalEl || (this.enterVREl || !i2.enterVREnabled || i2.XRMode !== "xr" && i2.XRMode !== "vr" || (i2.enterVRButton ? (this.enterVREl = document.querySelector(i2.enterVRButton), this.enterVREl.addEventListener("click", this.onEnterVRButtonClick)) : (this.enterVREl = (e = this.onEnterVRButtonClick, (n2 = document.createElement("div")).classList.add("a-enter-vr"), n2.setAttribute(hi, ""), (t2 = document.createElement("button")).className = "a-enter-vr-button", t2.setAttribute("title", "Enter VR mode with a headset or fullscreen without"), t2.setAttribute(hi, ""), Si() && ic(t2), n2.appendChild(t2), t2.addEventListener("click", function(t3) {
|
|
e(), t3.stopPropagation();
|
|
}), n2), r2.appendChild(this.enterVREl))), this.enterAREl || !i2.enterAREnabled || i2.XRMode !== "xr" && i2.XRMode !== "ar" || (i2.enterARButton ? (this.enterAREl = document.querySelector(i2.enterARButton), this.enterAREl.addEventListener("click", this.onEnterARButtonClick)) : (this.enterAREl = function(e2, t3) {
|
|
var n3, i3;
|
|
return (i3 = document.createElement("div")).classList.add("a-enter-ar"), t3 && i3.classList.add("xr"), i3.setAttribute(hi, ""), (n3 = document.createElement("button")).className = "a-enter-ar-button", n3.setAttribute("title", "Enter AR mode with a headset or handheld device."), n3.setAttribute(hi, ""), Si() && ic(n3), i3.appendChild(n3), n3.addEventListener("click", function(t4) {
|
|
e2(), t4.stopPropagation();
|
|
}), i3;
|
|
}(this.onEnterARButtonClick, i2.XRMode === "xr"), r2.appendChild(this.enterAREl))), this.orientationModalEl = function(e2) {
|
|
var t3 = document.createElement("div");
|
|
t3.className = "a-orientation-modal", t3.classList.add(nc), t3.setAttribute(hi, "");
|
|
var n3 = document.createElement("button");
|
|
return n3.setAttribute(hi, ""), n3.innerHTML = "Exit VR", n3.addEventListener("click", e2), t3.appendChild(n3), t3;
|
|
}(this.onModalClick), r2.appendChild(this.orientationModalEl), this.updateEnterInterfaces());
|
|
}, remove: function() {
|
|
[this.enterVREl, this.enterAREl, this.orientationModalEl].forEach(function(e) {
|
|
e && e.parentNode && e.parentNode.removeChild(e);
|
|
}), this.enterVREl = undefined, this.enterAREl = undefined, this.orientationModalEl = undefined;
|
|
}, updateEnterInterfaces: function() {
|
|
this.toggleEnterVRButtonIfNeeded(), this.toggleEnterARButtonIfNeeded(), this.toggleOrientationModalIfNeeded();
|
|
}, toggleEnterVRButtonIfNeeded: function() {
|
|
var e = this.el;
|
|
this.enterVREl && (e.is("vr-mode") || (e.isMobile || Fi()) && !Qi() ? this.enterVREl.classList.add(nc) : (Qi() || this.enterVREl.classList.add("fullscreen"), this.enterVREl.classList.remove(nc), e.enterVR(false, true)));
|
|
}, toggleEnterARButtonIfNeeded: function() {
|
|
var e = this.el;
|
|
this.enterAREl && (e.is("vr-mode") || !xi() ? this.enterAREl.classList.add(nc) : (this.enterAREl.classList.remove(nc), e.enterVR(true, true)));
|
|
}, toggleOrientationModalIfNeeded: function() {
|
|
var e = this.el, t2 = this.orientationModalEl;
|
|
t2 && e.isMobile && (!Ni() && e.is("vr-mode") ? t2.classList.remove(nc) : t2.classList.add(nc));
|
|
} }), qs("box", { schema: { depth: { default: 1, min: 0 }, height: { default: 1, min: 0 }, width: { default: 1, min: 0 }, segmentsHeight: { default: 1, min: 1, max: 20, type: "int" }, segmentsWidth: { default: 1, min: 1, max: 20, type: "int" }, segmentsDepth: { default: 1, min: 1, max: 20, type: "int" } }, init: function(e) {
|
|
this.geometry = new Re.BoxGeometry(e.width, e.height, e.depth, e.segmentsWidth, e.segmentsHeight, e.segmentsDepth);
|
|
} });
|
|
rc = Re.MathUtils.degToRad;
|
|
qs("circle", { schema: { radius: { default: 1, min: 0 }, segments: { default: 32, min: 3, type: "int" }, thetaLength: { default: 360, min: 0 }, thetaStart: { default: 0 } }, init: function(e) {
|
|
this.geometry = new Re.CircleGeometry(e.radius, e.segments, rc(e.thetaStart), rc(e.thetaLength));
|
|
} });
|
|
oc = Re.MathUtils.degToRad;
|
|
qs("cone", { schema: { height: { default: 1, min: 0 }, openEnded: { default: false }, radiusBottom: { default: 1, min: 0 }, radiusTop: { default: 0.01, min: 0 }, segmentsHeight: { default: 18, min: 1, type: "int" }, segmentsRadial: { default: 36, min: 3, type: "int" }, thetaLength: { default: 360, min: 0 }, thetaStart: { default: 0 } }, init: function(e) {
|
|
this.geometry = new Re.CylinderGeometry(e.radiusTop, e.radiusBottom, e.height, e.segmentsRadial, e.segmentsHeight, e.openEnded, oc(e.thetaStart), oc(e.thetaLength));
|
|
} });
|
|
sc = Re.MathUtils.degToRad;
|
|
qs("cylinder", { schema: { height: { default: 1, min: 0 }, openEnded: { default: false }, radius: { default: 1, min: 0 }, segmentsHeight: { default: 18, min: 1, type: "int" }, segmentsRadial: { default: 36, min: 3, type: "int" }, thetaLength: { default: 360, min: 0 }, thetaStart: { default: 0 } }, init: function(e) {
|
|
this.geometry = new Re.CylinderGeometry(e.radius, e.radius, e.height, e.segmentsRadial, e.segmentsHeight, e.openEnded, sc(e.thetaStart), sc(e.thetaLength));
|
|
} }), qs("dodecahedron", { schema: { detail: { default: 0, min: 0, max: 5, type: "int" }, radius: { default: 1, min: 0 } }, init: function(e) {
|
|
this.geometry = new Re.DodecahedronGeometry(e.radius, e.detail);
|
|
} }), qs("icosahedron", { schema: { detail: { default: 0, min: 0, max: 5, type: "int" }, radius: { default: 1, min: 0 } }, init: function(e) {
|
|
this.geometry = new Re.IcosahedronGeometry(e.radius, e.detail);
|
|
} }), qs("octahedron", { schema: { detail: { default: 0, min: 0, max: 5, type: "int" }, radius: { default: 1, min: 0 } }, init: function(e) {
|
|
this.geometry = new Re.OctahedronGeometry(e.radius, e.detail);
|
|
} }), qs("plane", { schema: { height: { default: 1, min: 0 }, width: { default: 1, min: 0 }, segmentsHeight: { default: 1, min: 1, max: 20, type: "int" }, segmentsWidth: { default: 1, min: 1, max: 20, type: "int" } }, init: function(e) {
|
|
this.geometry = new Re.PlaneGeometry(e.width, e.height, e.segmentsWidth, e.segmentsHeight);
|
|
} });
|
|
ac = Re.MathUtils.degToRad;
|
|
qs("ring", { schema: { radiusInner: { default: 0.8, min: 0 }, radiusOuter: { default: 1.2, min: 0 }, segmentsPhi: { default: 10, min: 1, type: "int" }, segmentsTheta: { default: 32, min: 3, type: "int" }, thetaLength: { default: 360, min: 0 }, thetaStart: { default: 0 } }, init: function(e) {
|
|
this.geometry = new Re.RingGeometry(e.radiusInner, e.radiusOuter, e.segmentsTheta, e.segmentsPhi, ac(e.thetaStart), ac(e.thetaLength));
|
|
} });
|
|
Ac = Re.MathUtils.degToRad;
|
|
qs("sphere", { schema: { radius: { default: 1, min: 0 }, phiLength: { default: 360 }, phiStart: { default: 0, min: 0 }, thetaLength: { default: 180, min: 0 }, thetaStart: { default: 0 }, segmentsHeight: { default: 18, min: 2, type: "int" }, segmentsWidth: { default: 36, min: 3, type: "int" } }, init: function(e) {
|
|
this.geometry = new Re.SphereGeometry(e.radius, e.segmentsWidth, e.segmentsHeight, Ac(e.phiStart), Ac(e.phiLength), Ac(e.thetaStart), Ac(e.thetaLength));
|
|
} }), qs("tetrahedron", { schema: { detail: { default: 0, min: 0, max: 5, type: "int" }, radius: { default: 1, min: 0 } }, init: function(e) {
|
|
this.geometry = new Re.TetrahedronGeometry(e.radius, e.detail);
|
|
} });
|
|
lc = Re.MathUtils.degToRad;
|
|
qs("torus", { schema: { arc: { default: 360 }, radius: { default: 1, min: 0 }, radiusTubular: { default: 0.2, min: 0 }, segmentsRadial: { default: 36, min: 2, type: "int" }, segmentsTubular: { default: 32, min: 3, type: "int" } }, init: function(e) {
|
|
this.geometry = new Re.TorusGeometry(e.radius, 2 * e.radiusTubular, e.segmentsRadial, e.segmentsTubular, lc(e.arc));
|
|
} }), qs("torusKnot", { schema: { p: { default: 2, min: 1 }, q: { default: 3, min: 1 }, radius: { default: 1, min: 0 }, radiusTubular: { default: 0.2, min: 0 }, segmentsRadial: { default: 8, min: 3, type: "int" }, segmentsTubular: { default: 100, min: 3, type: "int" } }, init: function(e) {
|
|
this.geometry = new Re.TorusKnotGeometry(e.radius, 2 * e.radiusTubular, e.segmentsTubular, e.segmentsRadial, e.p, e.q);
|
|
} });
|
|
cc = new Re.Quaternion;
|
|
hc = new Re.Vector3(0, 0, 1);
|
|
dc = new Re.Vector2;
|
|
uc = new Re.Vector2;
|
|
gc = new Re.Vector2;
|
|
qs("triangle", { schema: { vertexA: { type: "vec3", default: { x: 0, y: 0.5, z: 0 } }, vertexB: { type: "vec3", default: { x: -0.5, y: -0.5, z: 0 } }, vertexC: { type: "vec3", default: { x: 0.5, y: -0.5, z: 0 } } }, init: function(e) {
|
|
var t2, n2, i2, r2, o2, s2, a2, A2, l2;
|
|
(i2 = new Re.Triangle).a.set(e.vertexA.x, e.vertexA.y, e.vertexA.z), i2.b.set(e.vertexB.x, e.vertexB.y, e.vertexB.z), i2.c.set(e.vertexC.x, e.vertexC.y, e.vertexC.z), n2 = i2.getNormal(new Re.Vector3), cc.setFromUnitVectors(n2, hc), r2 = i2.a.clone().applyQuaternion(cc), o2 = i2.b.clone().applyQuaternion(cc), s2 = i2.c.clone().applyQuaternion(cc), dc.set(Math.min(r2.x, o2.x, s2.x), Math.min(r2.y, o2.y, s2.y)), uc.set(Math.max(r2.x, o2.x, s2.x), Math.max(r2.y, o2.y, s2.y)), gc.set(0, 0).subVectors(uc, dc), r2 = new Re.Vector2().subVectors(r2, dc).divide(gc), o2 = new Re.Vector2().subVectors(o2, dc).divide(gc), s2 = new Re.Vector2().subVectors(s2, dc).divide(gc), t2 = this.geometry = new Re.BufferGeometry, a2 = [i2.a.x, i2.a.y, i2.a.z, i2.b.x, i2.b.y, i2.b.z, i2.c.x, i2.c.y, i2.c.z], A2 = [n2.x, n2.y, n2.z, n2.x, n2.y, n2.z, n2.x, n2.y, n2.z], l2 = [r2.x, r2.y, o2.x, o2.y, s2.x, s2.y], t2.setAttribute("position", new Re.Float32BufferAttribute(a2, 3)), t2.setAttribute("normal", new Re.Float32BufferAttribute(A2, 3)), t2.setAttribute("uv", new Re.Float32BufferAttribute(l2, 2));
|
|
} }), ia("flat", { schema: { color: { type: "color" }, fog: { default: true }, offset: { type: "vec2", default: { x: 0, y: 0 } }, repeat: { type: "vec2", default: { x: 1, y: 1 } }, src: { type: "map" }, wireframe: { default: false }, wireframeLinewidth: { default: 2 }, toneMapped: { default: true } }, init: function(e) {
|
|
this.materialData = { color: new Re.Color }, pc(e, this.materialData), this.material = new Re.MeshBasicMaterial(this.materialData);
|
|
}, update: function(e) {
|
|
this.updateMaterial(e), vr(this, e);
|
|
}, updateMaterial: function(e) {
|
|
var t2;
|
|
for (t2 in pc(e, this.materialData), this.materialData)
|
|
this.material[t2] = this.materialData[t2];
|
|
} }), ia("standard", { schema: { ambientOcclusionMap: { type: "map" }, ambientOcclusionMapIntensity: { default: 1 }, ambientOcclusionTextureOffset: { type: "vec2" }, ambientOcclusionTextureRepeat: { type: "vec2", default: { x: 1, y: 1 } }, color: { type: "color" }, displacementMap: { type: "map" }, displacementScale: { default: 1 }, displacementBias: { default: 0.5 }, displacementTextureOffset: { type: "vec2" }, displacementTextureRepeat: { type: "vec2", default: { x: 1, y: 1 } }, emissive: { type: "color", default: "#000" }, emissiveIntensity: { default: 1 }, envMap: { default: "" }, fog: { default: true }, metalness: { default: 0, min: 0, max: 1 }, metalnessMap: { type: "map" }, metalnessTextureOffset: { type: "vec2" }, metalnessTextureRepeat: { type: "vec2", default: { x: 1, y: 1 } }, normalMap: { type: "map" }, normalScale: { type: "vec2", default: { x: 1, y: 1 } }, normalTextureOffset: { type: "vec2" }, normalTextureRepeat: { type: "vec2", default: { x: 1, y: 1 } }, offset: { type: "vec2", default: { x: 0, y: 0 } }, repeat: { type: "vec2", default: { x: 1, y: 1 } }, roughness: { default: 0.5, min: 0, max: 1 }, roughnessMap: { type: "map" }, roughnessTextureOffset: { type: "vec2" }, roughnessTextureRepeat: { type: "vec2", default: { x: 1, y: 1 } }, sphericalEnvMap: { type: "map" }, src: { type: "map" }, wireframe: { default: false }, wireframeLinewidth: { default: 2 } }, init: function(e) {
|
|
this.materialData = { color: new Re.Color, emissive: new Re.Color }, fc(e, this.materialData), this.material = new Re.MeshStandardMaterial(this.materialData);
|
|
}, update: function(e) {
|
|
this.updateMaterial(e), vr(this, e), Br("normal", this, e), Br("displacement", this, e), Br("ambientOcclusion", this, e), Br("metalness", this, e), Br("roughness", this, e), yr(this, e);
|
|
}, updateMaterial: function(e) {
|
|
var t2, n2 = this.material;
|
|
for (t2 in fc(e, this.materialData), this.materialData)
|
|
n2[t2] = this.materialData[t2];
|
|
} }), ia("phong", { schema: { color: { type: "color" }, emissive: { type: "color", default: "black" }, emissiveIntensity: { default: 1 }, specular: { type: "color", default: "#111111" }, transparent: { default: false }, fog: { default: true }, offset: { type: "vec2", default: { x: 0, y: 0 } }, repeat: { type: "vec2", default: { x: 1, y: 1 } }, src: { type: "map" }, envMap: { default: "" }, sphericalEnvMap: { type: "map" }, shininess: { default: 30 }, flatShading: { default: false }, wireframe: { default: false }, wireframeLinewidth: { default: 2 }, combine: { oneOF: ["multiply", "mix", "add"], default: "mix" }, reflectivity: { default: 0.9 }, refractionRatio: { default: 0.98 }, refract: { default: false }, normalMap: { type: "map" }, normalScale: { type: "vec2", default: { x: 1, y: 1 } }, normalTextureOffset: { type: "vec2" }, normalTextureRepeat: { type: "vec2", default: { x: 1, y: 1 } }, ambientOcclusionMap: { type: "map" }, ambientOcclusionMapIntensity: { default: 1 }, displacementMap: { type: "map" }, displacementScale: { default: 1 }, displacementBias: { default: 0.5 }, displacementTextureOffset: { type: "vec2" }, displacementTextureRepeat: { type: "vec2", default: { x: 1, y: 1 } }, bumpMap: { type: "map" }, bumpMapScale: { default: 1 }, bumpTextureOffset: { type: "vec2" }, bumpTextureRepeat: { type: "vec2", default: { x: 1, y: 1 } } }, init: function(e) {
|
|
this.materialData = { color: new Re.Color, specular: new Re.Color, emissive: new Re.Color }, mc(e, this.materialData), this.material = new Re.MeshPhongMaterial(this.materialData);
|
|
var t2 = this.el.sceneEl;
|
|
Object.defineProperty(this.material, "envMap", { get: function() {
|
|
return this._envMap || t2.object3D.environment;
|
|
}, set: function(e2) {
|
|
this._envMap = e2;
|
|
} });
|
|
}, update: function(e) {
|
|
this.updateMaterial(e), vr(this, e), Br("normal", this, e), Br("displacement", this, e), Br("ambientOcclusion", this, e), Br("bump", this, e), yr(this, e);
|
|
}, updateMaterial: function(e) {
|
|
var t2;
|
|
for (t2 in mc(e, this.materialData), this.materialData)
|
|
this.material[t2] = this.materialData[t2];
|
|
} }), ia("sdf", { schema: { alphaTest: { type: "number", is: "uniform", default: 0.5 }, color: { type: "color", is: "uniform", default: "white" }, map: { type: "map", is: "uniform" }, opacity: { type: "number", is: "uniform", default: 1 } }, vertexShader: ["#include <common>", "#include <fog_pars_vertex>", "#include <logdepthbuf_pars_vertex>", "out vec2 vUV;", "void main(void) {", " vUV = uv;", " #include <begin_vertex>", " #include <project_vertex>", " #include <logdepthbuf_vertex>", " #include <fog_vertex>", "}"].join(`
|
|
`), fragmentShader: ["#include <common>", "#include <fog_pars_fragment>", "#include <logdepthbuf_pars_fragment>", "uniform float alphaTest;", "uniform float opacity;", "uniform sampler2D map;", "uniform vec3 color;", "in vec2 vUV;", "float contour(float width, float value) {", " return smoothstep(0.5 - value, 0.5 + value, width);", "}", "#define BIG_ENOUGH 0.001", "#define MODIFIED_ALPHATEST (0.02 * isBigEnough / BIG_ENOUGH)", "void main() {", " vec2 uv = vUV;", " vec4 texColor = texture(map, uv);", " float dist = texColor.a;", " float width = fwidth(dist);", " float alpha = contour(dist, width);", " float dscale = 0.353505;", " vec2 duv = dscale * (dFdx(uv) + dFdy(uv));", " float isBigEnough = max(abs(duv.x), abs(duv.y));", " if (isBigEnough > BIG_ENOUGH) {", " float ratio = BIG_ENOUGH / isBigEnough;", " alpha = ratio * alpha + (1.0 - ratio) * dist;", " }", " if (isBigEnough <= BIG_ENOUGH) {", " vec4 box = vec4 (uv - duv, uv + duv);", " alpha = (alpha + 0.5 * (", " contour(texture(map, box.xy).a, width)", " + contour(texture(map, box.zw).a, width)", " + contour(texture(map, box.xw).a, width)", " + contour(texture(map, box.zy).a, width)", " )) / 3.0;", " }", " if (alpha < alphaTest * MODIFIED_ALPHATEST) { discard; return; }", " gl_FragColor = vec4(color, opacity * alpha);", " #include <logdepthbuf_fragment>", " #include <tonemapping_fragment>", " #include <colorspace_fragment>", " #include <fog_fragment>", "}"].join(`
|
|
`), init: function() {
|
|
return this.uniforms = this.initUniforms(), Re.UniformsUtils && (this.uniforms = Re.UniformsUtils.merge([Re.UniformsLib.fog, this.uniforms])), this.material = new Re.ShaderMaterial({ uniforms: this.uniforms, vertexShader: this.vertexShader, fragmentShader: this.fragmentShader, fog: true }), this.material;
|
|
} }), ia("msdf", { schema: { alphaTest: { type: "number", is: "uniform", default: 0.5 }, color: { type: "color", is: "uniform", default: "white" }, map: { type: "map", is: "uniform" }, negate: { type: "boolean", is: "uniform", default: true }, opacity: { type: "number", is: "uniform", default: 1 } }, vertexShader: ["#include <common>", "#include <fog_pars_vertex>", "#include <logdepthbuf_pars_vertex>", "out vec2 vUV;", "void main(void) {", " vUV = uv;", " #include <begin_vertex>", " #include <project_vertex>", " #include <logdepthbuf_vertex>", " #include <fog_vertex>", "}"].join(`
|
|
`), fragmentShader: ["#include <common>", "#include <fog_pars_fragment>", "#include <logdepthbuf_pars_fragment>", "uniform bool negate;", "uniform float alphaTest;", "uniform float opacity;", "uniform sampler2D map;", "uniform vec3 color;", "in vec2 vUV;", "float median(float r, float g, float b) {", " return max(min(r, g), min(max(r, g), b));", "}", "#define BIG_ENOUGH 0.001", "#define MODIFIED_ALPHATEST (0.02 * isBigEnough / BIG_ENOUGH)", "void main() {", " vec3 sampleColor = texture(map, vUV).rgb;", " if (negate) { sampleColor = 1.0 - sampleColor; }", " float sigDist = median(sampleColor.r, sampleColor.g, sampleColor.b) - 0.5;", " float alpha = clamp(sigDist / fwidth(sigDist) + 0.5, 0.0, 1.0);", " float dscale = 0.353505;", " vec2 duv = dscale * (dFdx(vUV) + dFdy(vUV));", " float isBigEnough = max(abs(duv.x), abs(duv.y));", " // Do modified alpha test.", " if (isBigEnough > BIG_ENOUGH) {", " float ratio = BIG_ENOUGH / isBigEnough;", " alpha = ratio * alpha + (1.0 - ratio) * (sigDist + 0.5);", " }", " // Do modified alpha test.", " if (alpha < alphaTest * MODIFIED_ALPHATEST) { discard; return; }", " gl_FragColor = vec4(color.xyz, alpha * opacity);", " #include <logdepthbuf_fragment>", " #include <tonemapping_fragment>", " #include <colorspace_fragment>", " #include <fog_fragment>", "}"].join(`
|
|
`), init: function() {
|
|
return this.uniforms = this.initUniforms(), Re.UniformsUtils && (this.uniforms = Re.UniformsUtils.merge([Re.UniformsLib.fog, this.uniforms])), this.material = new Re.ShaderMaterial({ uniforms: this.uniforms, vertexShader: this.vertexShader, fragmentShader: this.fragmentShader, fog: true }), this.material;
|
|
} }), ia("shadow", { schema: { opacity: { default: 0.5 }, transparent: { default: true }, alphaToCoverage: { default: true } }, init: function(e) {
|
|
this.material = new Re.ShadowMaterial;
|
|
}, update: function(e) {
|
|
this.material.opacity = e.opacity, this.material.alphaToCoverage = e.alphaToCoverage, this.material.transparent = e.transparent;
|
|
} });
|
|
Es("camera", { init: function() {
|
|
this.activeCameraEl = null, this.render = this.render.bind(this), this.unwrapRender = this.unwrapRender.bind(this), this.wrapRender = this.wrapRender.bind(this), this.initialCameraFound = false, this.numUserCameras = 0, this.numUserCamerasChecked = 0, this.setupInitialCamera();
|
|
}, setupInitialCamera: function() {
|
|
var e, t2, n2 = this.sceneEl, i2 = this;
|
|
if (!n2.camera || n2.camera.el.getAttribute("camera").spectator)
|
|
if ((e = n2.querySelectorAll("a-camera, :not(a-mixin)[camera]")).length)
|
|
for (this.numUserCameras = e.length, t2 = 0;t2 < e.length; t2++)
|
|
e[t2].addEventListener("object3dset", function(e2) {
|
|
e2.detail.type === "camera" && i2.checkUserCamera(this);
|
|
}), e[t2].isANode ? e[t2].load() : e[t2].addEventListener("nodeready", function() {
|
|
this.load();
|
|
});
|
|
else
|
|
this.createDefaultCamera();
|
|
else
|
|
n2.emit("cameraready", { cameraEl: n2.camera.el });
|
|
}, checkUserCamera: function(e) {
|
|
var t2, n2 = this.el.sceneEl;
|
|
this.numUserCamerasChecked++, this.initialCameraFound || ((t2 = e.getAttribute("camera")).active && !t2.spectator ? (this.initialCameraFound = true, n2.camera = e.getObject3D("camera"), n2.emit("cameraready", { cameraEl: e })) : this.numUserCamerasChecked === this.numUserCameras && this.createDefaultCamera());
|
|
}, createDefaultCamera: function() {
|
|
var e, t2 = this.sceneEl;
|
|
(e = document.createElement("a-entity")).setAttribute("camera", { active: true }), e.setAttribute("position", { x: 0, y: 1.6, z: 0 }), e.setAttribute("wasd-controls", ""), e.setAttribute("look-controls", ""), e.setAttribute(hi, ""), e.addEventListener("object3dset", function(n2) {
|
|
n2.detail.type === "camera" && (t2.camera = n2.detail.object, t2.emit("cameraready", { cameraEl: e }));
|
|
}), t2.appendChild(e);
|
|
}, disableActiveCamera: function() {
|
|
var e;
|
|
(e = this.sceneEl.querySelectorAll(":not(a-mixin)[camera]"))[e.length - 1].setAttribute("camera", "active", true);
|
|
}, setActiveCamera: function(e) {
|
|
var t2, n2, i2, r2, o2 = this.activeCameraEl, s2 = this.sceneEl;
|
|
if ((r2 = e.getObject3D("camera")) && e !== this.activeCameraEl) {
|
|
var a2 = s2.querySelector("[" + Ec + "]");
|
|
for (e !== (a2 && a2.querySelector(":not(a-mixin)[camera]")) && function(e2) {
|
|
var t3;
|
|
e2.camera && (t3 = e2.querySelector("[" + Ec + "]")) && e2.removeChild(t3);
|
|
}(s2), this.activeCameraEl = e, this.activeCameraEl.play(), s2.camera = r2, o2 && o2.setAttribute("camera", "active", false), n2 = s2.querySelectorAll(":not(a-mixin)[camera]"), i2 = 0;i2 < n2.length; i2++)
|
|
(t2 = n2[i2]).isEntity && e !== t2 && (t2.setAttribute("camera", "active", false), t2.pause());
|
|
s2.emit("camera-set-active", { cameraEl: e });
|
|
}
|
|
}, setSpectatorCamera: function(e) {
|
|
var t2, n2 = this.spectatorCameraEl, i2 = this.sceneEl;
|
|
e.getObject3D("camera") && e !== this.spectatorCameraEl && (n2 && n2.setAttribute("camera", "spectator", false), t2 = this.spectatorCameraEl = e, i2.addEventListener("enter-vr", this.wrapRender), i2.addEventListener("exit-vr", this.unwrapRender), t2.setAttribute("camera", "active", false), t2.play(), i2.emit("camera-set-spectator", { cameraEl: e }));
|
|
}, disableSpectatorCamera: function() {
|
|
this.spectatorCameraEl = undefined;
|
|
}, wrapRender: function() {
|
|
this.spectatorCameraEl && !this.originalRender && (this.originalRender = this.sceneEl.renderer.render, this.sceneEl.renderer.render = this.render);
|
|
}, unwrapRender: function() {
|
|
this.originalRender && (this.sceneEl.renderer.render = this.originalRender, this.originalRender = undefined);
|
|
}, render: function(e, t2) {
|
|
var n2, i2, r2 = this.sceneEl;
|
|
n2 = r2.renderer.xr.enabled, this.originalRender.call(r2.renderer, e, t2), this.spectatorCameraEl && !r2.isMobile && n2 && (i2 = this.spectatorCameraEl.components.camera.camera, r2.renderer.xr.enabled = false, this.originalRender.call(r2.renderer, e, i2), r2.renderer.xr.enabled = n2);
|
|
} }), Es("geometry", { init: function() {
|
|
this.cache = {}, this.cacheCount = {};
|
|
}, clearCache: function() {
|
|
this.cache = {}, this.cacheCount = {};
|
|
}, getOrCreateGeometry: function(e) {
|
|
var t2, n2, i2 = this.cache;
|
|
return e.skipCache ? Cc(e) : (t2 = i2[n2 = this.hash(e)], function(e2, t3) {
|
|
e2[t3] = e2[t3] === undefined ? 1 : e2[t3] + 1;
|
|
}(this.cacheCount, n2), t2 || (t2 = Cc(e), i2[n2] = t2, t2));
|
|
}, unuseGeometry: function(e) {
|
|
var t2, n2 = this.cache, i2 = this.cacheCount;
|
|
e.skipCache || n2[t2 = this.hash(e)] && (function(e2, t3) {
|
|
e2[t3]--;
|
|
}(i2, t2), i2[t2] > 0 || (n2[t2].dispose(), delete n2[t2], delete i2[t2]));
|
|
}, hash: function(e) {
|
|
return JSON.stringify(e);
|
|
} }), Es("gltf-model", { schema: { dracoDecoderPath: { default: "https://www.gstatic.com/draco/versioned/decoders/1.5.7/" }, basisTranscoderPath: { default: "" }, meshoptDecoderPath: { default: "" } }, init: function() {
|
|
this.update();
|
|
}, update: function() {
|
|
var e = this.data.dracoDecoderPath, t2 = this.data.basisTranscoderPath, n2 = this.data.meshoptDecoderPath;
|
|
!this.dracoLoader && e && (this.dracoLoader = new Ue, this.dracoLoader.setDecoderPath(e)), !this.ktx2Loader && t2 && (this.ktx2Loader = new Bn, this.ktx2Loader.setTranscoderPath(t2).detectSupport(this.el.renderer)), !this.meshoptDecoder && n2 && (this.meshoptDecoder = function(e2) {
|
|
return new Promise(function(t3, n3) {
|
|
var i2 = document.createElement("script");
|
|
document.body.appendChild(i2), i2.onload = t3, i2.onerror = n3, i2.async = true, i2.src = e2;
|
|
});
|
|
}(n2).then(function() {
|
|
return window.MeshoptDecoder.ready;
|
|
}).then(function() {
|
|
return window.MeshoptDecoder;
|
|
}));
|
|
}, getDRACOLoader: function() {
|
|
return this.dracoLoader;
|
|
}, getKTX2Loader: function() {
|
|
return this.ktx2Loader;
|
|
}, getMeshoptDecoder: function() {
|
|
return this.meshoptDecoder;
|
|
} });
|
|
Bc = (Es("light", { schema: { defaultLightsEnabled: { default: true } }, init: function() {
|
|
this.defaultLights = false, this.userDefinedLights = false, this.sceneEl.addEventListener("loaded", this.setupDefaultLights.bind(this));
|
|
}, registerLight: function(e) {
|
|
e.hasAttribute(vc) || (this.removeDefaultLights(), this.userDefinedLights = true);
|
|
}, removeDefaultLights: function() {
|
|
var e, t2 = this.sceneEl;
|
|
if (this.defaultLights) {
|
|
e = document.querySelectorAll("[" + vc + "]");
|
|
for (var n2 = 0;n2 < e.length; n2++)
|
|
t2.removeChild(e[n2]);
|
|
this.defaultLights = false;
|
|
}
|
|
}, setupDefaultLights: function() {
|
|
var e, t2, n2 = this.sceneEl;
|
|
this.userDefinedLights || this.defaultLights || !this.data.defaultLightsEnabled || ((e = document.createElement("a-entity")).setAttribute("light", { color: "#BBB", type: "ambient" }), e.setAttribute(vc, ""), e.setAttribute(hi, ""), n2.appendChild(e), (t2 = document.createElement("a-entity")).setAttribute("light", { color: "#FFF", intensity: 1.884, castShadow: true }), t2.setAttribute("position", { x: -0.5, y: 1, z: 1 }), t2.setAttribute(vc, ""), t2.setAttribute(hi, ""), n2.appendChild(t2), this.defaultLights = true);
|
|
} }), fi);
|
|
bc = Bc("components:texture:error");
|
|
yc = Bc("components:texture:warn");
|
|
Ic = new Re.ImageLoader;
|
|
Es("material", { init: function() {
|
|
this.materials = {}, this.sourceCache = {};
|
|
}, clearTextureSourceCache: function() {
|
|
this.sourceCache = {};
|
|
}, loadTexture: function(e, t2, n2) {
|
|
this.loadTextureSource(e, function(e2) {
|
|
var i2 = xr(e2);
|
|
Er(i2, t2), n2(i2);
|
|
});
|
|
}, loadTextureSource: function(e, t2) {
|
|
var n2 = this, i2 = this.sourceCache, r2 = this.hash(e);
|
|
function o2(e2) {
|
|
i2[r2] = Promise.resolve(e2), i2[r2].then(t2);
|
|
}
|
|
i2[r2] ? i2[r2].then(t2) : e.tagName !== "CANVAS" ? o2(new Promise(function(t3, i3) {
|
|
hr(e, function(e2) {
|
|
n2.loadImage(e2, t3);
|
|
}, function(e2) {
|
|
n2.loadVideo(e2, t3);
|
|
});
|
|
})) : o2(new Re.Source(e));
|
|
}, loadCubeMapTexture: function(e, t2) {
|
|
var n2 = this, i2 = 0, r2 = new Re.CubeTexture;
|
|
function o2(o3) {
|
|
n2.loadTextureSource(e[o3], function(e2) {
|
|
r2.images[o3] = e2.data, ++i2 == 6 && (r2.needsUpdate = true, t2(r2));
|
|
});
|
|
}
|
|
if (r2.colorSpace = Re.SRGBColorSpace, e.length === 6)
|
|
for (var s2 = 0;s2 < e.length; s2++)
|
|
o2(s2);
|
|
else
|
|
yc("Cube map texture requires exactly 6 sources, got only %s sources", e.length);
|
|
}, loadImage: function(e, t2) {
|
|
t2(typeof e == "string" ? function(e2) {
|
|
return new Promise(function(t3, n2) {
|
|
Ic.load(e2, function(e3) {
|
|
t3(new Re.Source(e3));
|
|
}, function() {}, function(e3) {
|
|
bc("`$s` could not be fetched (Error code: %s; Response: %s)", e3.status, e3.statusText);
|
|
});
|
|
});
|
|
}(e) : new Re.Source(e));
|
|
}, loadVideo: function(e, t2) {
|
|
var n2;
|
|
typeof e != "string" && function(e2) {
|
|
e2.autoplay = e2.hasAttribute("autoplay") && e2.getAttribute("autoplay") !== "false", e2.controls = e2.hasAttribute("controls") && e2.getAttribute("controls") !== "false", e2.getAttribute("loop") === "false" && e2.removeAttribute("loop"), e2.getAttribute("preload") === "false" && (e2.preload = "none"), e2.crossOrigin = e2.crossOrigin || "anonymous", e2.setAttribute("playsinline", ""), e2.setAttribute("webkit-playsinline", "");
|
|
}(n2 = e), n2 = n2 || function(e2) {
|
|
var t3 = document.createElement("video");
|
|
return t3.setAttribute("playsinline", ""), t3.setAttribute("webkit-playsinline", ""), t3.autoplay = true, t3.loop = true, t3.crossOrigin = "anonymous", t3.addEventListener("error", function() {
|
|
yc("`%s` is not a valid video", e2);
|
|
}, true), t3.src = e2, t3;
|
|
}(e), t2(new Re.Source(n2));
|
|
}, hash: function(e) {
|
|
return e.tagName && (e.id || e.src) || e;
|
|
}, registerMaterial: function(e) {
|
|
this.materials[e.uuid] = e;
|
|
}, unregisterMaterial: function(e) {
|
|
delete this.materials[e.uuid];
|
|
} }), Es("obb-collider", { schema: { showColliders: { default: false } }, init: function() {
|
|
this.collisions = [], this.colliderEls = [];
|
|
}, addCollider: function(e) {
|
|
this.colliderEls.push(e), this.data.showColliders ? e.components["obb-collider"].showCollider() : e.components["obb-collider"].hideCollider(), this.tick = this.detectCollisions;
|
|
}, removeCollider: function(e) {
|
|
var t2 = this.colliderEls, n2 = t2.indexOf(e);
|
|
e.components["obb-collider"].hideCollider(), n2 > -1 && t2.splice(n2, 1), t2.length === 0 && (this.tick = undefined);
|
|
}, registerCollision: function(e, t2) {
|
|
var n2 = this.collisions, i2 = false, r2 = e.obb, o2 = t2.obb, s2 = e.renderColliderMesh, a2 = t2.renderColliderMesh;
|
|
s2 && s2.material.color.set(16711680), a2 && a2.material.color.set(16711680);
|
|
for (var A2 = 0;A2 < n2.length; A2++)
|
|
if (n2[A2].componentA.obb === r2 && n2[A2].componentB.obb === o2 || n2[A2].componentA.obb === o2 && n2[A2].componentB.obb === r2) {
|
|
i2 = true, n2[A2].detected = true;
|
|
break;
|
|
}
|
|
i2 || (n2.push({ componentA: e, componentB: t2, detected: true }), e.el.emit("obbcollisionstarted", { trackedObject3D: e.trackedObject3D, withEl: t2.el }), t2.el.emit("obbcollisionstarted", { trackedObject3D: t2.trackedObject3D, withEl: e.el }));
|
|
}, resetCollisions: function() {
|
|
for (var e = this.collisions, t2 = 0;t2 < e.length; t2++)
|
|
e[t2].detected = false;
|
|
}, clearCollisions: function() {
|
|
for (var e, t2, n2, i2, r2 = this.collisions, o2 = [], s2 = 0;s2 < r2.length; s2++)
|
|
r2[s2].detected ? o2.push(r2[s2]) : (e = r2[s2].componentA, t2 = r2[s2].componentB, n2 = e.renderColliderMesh, i2 = t2.renderColliderMesh, n2 && n2.material.color.set(65280), e.el.emit("obbcollisionended", { trackedObject3D: this.trackedObject3D, withEl: t2.el }), i2 && i2.material.color.set(65280), t2.el.emit("obbcollisionended", { trackedObject3D: this.trackedObject3D, withEl: e.el }));
|
|
this.collisions = o2;
|
|
}, detectCollisions: function() {
|
|
var e, t2, n2, i2, r2 = this.colliderEls;
|
|
if (!(r2.length < 2)) {
|
|
this.resetCollisions();
|
|
for (var o2 = 0;o2 < r2.length; o2++)
|
|
if (n2 = r2[o2].components["obb-collider"], (e = r2[o2].components["obb-collider"].obb).halfSize.x !== 0 && e.halfSize.y !== 0 && e.halfSize.z !== 0)
|
|
for (var s2 = o2 + 1;s2 < r2.length; s2++)
|
|
(t2 = (i2 = r2[s2].components["obb-collider"]).obb).halfSize.x !== 0 && t2.halfSize.y !== 0 && t2.halfSize.z !== 0 && e.intersectsOBB(t2) && this.registerCollision(n2, i2);
|
|
this.clearCollisions();
|
|
}
|
|
} });
|
|
wc = fi("components:renderer:warn");
|
|
Es("renderer", { schema: { antialias: { default: "auto", oneOf: ["true", "false", "auto"] }, highRefreshRate: { default: Ui() }, logarithmicDepthBuffer: { default: "auto", oneOf: ["true", "false", "auto"] }, maxCanvasWidth: { default: -1 }, maxCanvasHeight: { default: -1 }, multiviewStereo: { default: false }, exposure: { default: 1, if: { toneMapping: ["ACESFilmic", "linear", "reinhard", "cineon", "AgX", "neutral"] } }, toneMapping: { default: "no", oneOf: ["no", "ACESFilmic", "linear", "reinhard", "cineon", "AgX", "neutral"] }, precision: { default: "high", oneOf: ["high", "medium", "low"] }, anisotropy: { default: 1 }, sortTransparentObjects: { default: false }, colorManagement: { default: true }, alpha: { default: true }, stencil: { default: false }, foveationLevel: { default: 1 } }, init: function() {
|
|
var e = this.data, t2 = this.el, n2 = this.data.toneMapping.charAt(0).toUpperCase() + this.data.toneMapping.slice(1), i2 = t2.renderer;
|
|
i2.toneMapping = Re[n2 + "ToneMapping"], Re.Texture.DEFAULT_ANISOTROPY = e.anisotropy, Re.ColorManagement.enabled = e.colorManagement, i2.outputColorSpace = e.colorManagement ? Re.SRGBColorSpace : Re.LinearSRGBColorSpace, t2.hasAttribute("antialias") && wc('Component `antialias` is deprecated. Use `renderer="antialias: true"` instead.'), t2.hasAttribute("logarithmicDepthBuffer") && wc('Component `logarithmicDepthBuffer` is deprecated. Use `renderer="logarithmicDepthBuffer: true"` instead.'), i2.sortObjects = true, i2.setOpaqueSort(xc);
|
|
}, update: function() {
|
|
var e = this.data, t2 = this.el.renderer, n2 = this.data.toneMapping.charAt(0).toUpperCase() + this.data.toneMapping.slice(1);
|
|
t2.toneMapping = Re[n2 + "ToneMapping"], t2.toneMappingExposure = e.exposure, t2.xr.setFoveation(e.foveationLevel), e.sortObjects && wc('`sortObjects` property is deprecated. Use `renderer="sortTransparentObjects: true"` instead.'), e.sortTransparentObjects ? t2.setTransparentSort(Lc) : t2.setTransparentSort(Qc);
|
|
}, applyColorCorrection: function(e) {
|
|
this.data.colorManagement && e && e.isTexture && e.colorSpace !== Re.SRGBColorSpace && (e.colorSpace = Re.SRGBColorSpace, e.needsUpdate = true);
|
|
}, setWebXRFrameRate: function(e) {
|
|
var t2, n2 = this.data, i2 = e.supportedFrameRates;
|
|
i2 && e.updateTargetFrameRate && (t2 = i2.includes(90) ? n2.highRefreshRate ? 90 : 72 : n2.highRefreshRate ? 72 : 60, e.updateTargetFrameRate(t2).catch(function(e2) {
|
|
console.warn("failed to set target frame rate of " + t2 + ". Error info: " + e2);
|
|
}));
|
|
} });
|
|
Mc = { basic: Re.BasicShadowMap, pcf: Re.PCFShadowMap, pcfsoft: Re.PCFSoftShadowMap };
|
|
Es("shadow", { schema: { enabled: { default: true }, autoUpdate: { default: true }, type: { default: "pcf", oneOf: ["basic", "pcf", "pcfsoft"] } }, init: function() {
|
|
var e = this.sceneEl, t2 = this.data;
|
|
this.shadowMapEnabled = false, e.renderer.shadowMap.type = Mc[t2.type], e.renderer.shadowMap.autoUpdate = t2.autoUpdate;
|
|
}, update: function(e) {
|
|
e.enabled !== this.data.enabled && this.setShadowMapEnabled(this.shadowMapEnabled);
|
|
}, setShadowMapEnabled: function(e) {
|
|
var t2 = this.sceneEl, n2 = this.sceneEl.renderer;
|
|
this.shadowMapEnabled = e;
|
|
var i2 = this.data.enabled && this.shadowMapEnabled;
|
|
n2 && i2 !== n2.shadowMap.enabled && (n2.shadowMap.enabled = i2, function(e2) {
|
|
e2.hasLoaded && e2.object3D.traverse(function(e3) {
|
|
if (e3.material)
|
|
for (var t3 = Array.isArray(e3.material) ? e3.material : [e3.material], n3 = 0;n3 < t3.length; n3++)
|
|
t3[n3].needsUpdate = true;
|
|
});
|
|
}(t2));
|
|
} }), Es("tracked-controls", { init: function() {
|
|
this.controllers = [], this.onInputSourcesChange = this.onInputSourcesChange.bind(this), this.onEnterVR = this.onEnterVR.bind(this), this.el.addEventListener("enter-vr", this.onEnterVR), this.onExitVR = this.onExitVR.bind(this), this.el.addEventListener("exit-vr", this.onExitVR);
|
|
}, onEnterVR: function() {
|
|
this.el.xrSession && this.el.xrSession.addEventListener("inputsourceschange", this.onInputSourcesChange);
|
|
}, onExitVR: function() {
|
|
this.referenceSpace = undefined, this.controllers = [], this.el.emit("controllersupdated", undefined, false);
|
|
}, onInputSourcesChange: function() {
|
|
var e = this, t2 = this.el.xrSession, n2 = this.el.sceneEl.systems.webxr.sessionReferenceSpaceType;
|
|
t2.requestReferenceSpace(n2).then(function(t3) {
|
|
e.referenceSpace = t3;
|
|
}).catch(function(t3) {
|
|
throw e.el.sceneEl.systems.webxr.warnIfFeatureNotRequested(n2, 'tracked-controls uses reference space "' + n2 + '".'), t3;
|
|
}), this.controllers = t2.inputSources, this.el.emit("controllersupdated", undefined, false);
|
|
} });
|
|
Sc = fi("systems:webxr:warn");
|
|
Dc = (Es("webxr", { schema: { referenceSpaceType: { type: "string", default: "local-floor" }, requiredFeatures: { type: "array", default: ["local-floor"] }, optionalFeatures: { type: "array", default: ["bounded-floor"] }, overlayElement: { type: "selector" } }, update: function() {
|
|
var e = this.data;
|
|
this.sessionConfiguration = { requiredFeatures: e.requiredFeatures, optionalFeatures: e.optionalFeatures }, this.sessionReferenceSpaceType = e.referenceSpaceType, e.overlayElement && (e.overlayElement.classList.remove("a-dom-overlay"), e.optionalFeatures.includes("dom-overlay") || (e.optionalFeatures.push("dom-overlay"), this.el.setAttribute("webxr", e)), this.warnIfFeatureNotRequested("dom-overlay"), this.sessionConfiguration.domOverlay = { root: e.overlayElement }, e.overlayElement.classList.add("a-dom-overlay"));
|
|
}, wasFeatureRequested: function(e) {
|
|
return e === "viewer" || e === "local" || !(!this.sessionConfiguration.requiredFeatures.includes(e) && !this.sessionConfiguration.optionalFeatures.includes(e));
|
|
}, warnIfFeatureNotRequested: function(e, t2) {
|
|
this.wasFeatureRequested(e) || Sc((t2 ? t2 + " " : "") + 'Please add the feature "' + e + `" to a-scene's webxr system options in requiredFeatures/optionalFeatures.`);
|
|
} }), {});
|
|
Object.keys(Ko.material.schema).forEach(kc), Object.keys($s.standard.schema).forEach(kc);
|
|
Rc = new Re.Vector3;
|
|
Fc = new Re.Vector3;
|
|
cs("pivot", { dependencies: ["position"], schema: { type: "vec3" }, init: function() {
|
|
var e = this.data, t2 = this.el, n2 = t2.object3D.parent, i2 = t2.object3D, r2 = new Re.Group;
|
|
Rc.copy(i2.position), Fc.copy(i2.rotation), n2.remove(i2), r2.add(i2), n2.add(r2), t2.object3D = r2, i2.position.set(-1 * e.x, -1 * e.y, -1 * e.z), r2.position.set(e.x + Rc.x, e.y + Rc.y, e.z + Rc.z), r2.rotation.copy(i2.rotation), i2.rotation.set(0, 0, 0);
|
|
} }), Xs("a-camera", { defaultComponents: { camera: {}, "look-controls": {}, "wasd-controls": {}, position: { x: 0, y: 1.6, z: 0 } }, mappings: { active: "camera.active", far: "camera.far", fov: "camera.fov", "look-controls-enabled": "look-controls.enabled", near: "camera.near", "pointer-lock-enabled": "look-controls.pointerLockEnabled", "wasd-controls-enabled": "wasd-controls.enabled", "reverse-mouse-drag": "look-controls.reverseMouseDrag", zoom: "camera.zoom" } }), Xs("a-cursor", Xr({}, Tc(), { defaultComponents: { cursor: {}, geometry: { primitive: "ring", radiusOuter: 0.016, radiusInner: 0.01, segmentsTheta: 32 }, material: { color: "#000", shader: "flat", opacity: 0.8 }, position: { x: 0, y: 0, z: -1 } }, mappings: { far: "raycaster.far", fuse: "cursor.fuse", "fuse-timeout": "cursor.fuseTimeout", interval: "raycaster.interval", objects: "raycaster.objects" } })), Xs("a-curvedimage", Xr({}, Tc(), { defaultComponents: { geometry: { height: 1, primitive: "cylinder", radius: 2, segmentsRadial: 48, thetaLength: 270, openEnded: true, thetaStart: 0 }, material: { color: "#FFF", shader: "flat", side: "double", transparent: true, repeat: "-1 1" } }, mappings: { height: "geometry.height", "open-ended": "geometry.openEnded", radius: "geometry.radius", segments: "geometry.segmentsRadial", start: "geometry.thetaStart", "theta-length": "geometry.thetaLength", "theta-start": "geometry.thetaStart", width: "geometry.thetaLength" } })), Xs("a-gltf-model", { mappings: { src: "gltf-model" } }), Xs("a-image", Xr({}, Tc(), { defaultComponents: { geometry: { primitive: "plane" }, material: { color: "#FFF", shader: "flat", side: "double", transparent: true } }, mappings: { height: "geometry.height", width: "geometry.width" } })), Xs("a-light", { defaultComponents: { light: {} }, mappings: { angle: "light.angle", color: "light.color", "ground-color": "light.groundColor", decay: "light.decay", distance: "light.distance", intensity: "light.intensity", penumbra: "light.penumbra", type: "light.type", target: "light.target", envmap: "light.envMap", "shadow-camera-automatic": "light.shadowCameraAutomatic" } }), Xs("a-link", { defaultComponents: { link: { visualAspectEnabled: true } }, mappings: { href: "link.href", image: "link.image", title: "link.title" } }), Xs("a-obj-model", Xr({}, Tc(), { defaultComponents: { "obj-model": {} }, mappings: { src: "obj-model.obj", mtl: "obj-model.mtl" } }));
|
|
Uc = {};
|
|
Oc = Uc;
|
|
_s.forEach(function(e) {
|
|
var t2 = js[e], n2 = Pc(e), i2 = {};
|
|
Object.keys(t2.schema).forEach(function(e2) {
|
|
i2[Pc(e2)] = "geometry." + e2;
|
|
});
|
|
var r2 = "a-" + n2, o2 = Xs(r2, Xr({}, Tc(), { defaultComponents: { geometry: { primitive: e } }, mappings: i2 }));
|
|
Uc[r2] = o2;
|
|
}), Xs("a-sky", Xr({}, Tc(), { defaultComponents: { geometry: { primitive: "sphere", radius: 500, segmentsWidth: 64, segmentsHeight: 32 }, material: { color: "#FFF", side: "back", shader: "flat", npot: true }, scale: "-1 1 1" }, mappings: Xr({}, Oc["a-sphere"].mappings) })), Xs("a-sound", { defaultComponents: { sound: {} }, mappings: { src: "sound.src", on: "sound.on", autoplay: "sound.autoplay", loop: "sound.loop", volume: "sound.volume" } }), Gc = { text: { anchor: "align", width: 5 } }, Nc = Nc || {}, Object.keys(Gc).forEach(function(e) {
|
|
(function(e2, t2) {
|
|
var n2 = Ko[e2].schema;
|
|
Object.keys(n2).forEach(function(n3) {
|
|
var i2 = n3.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
t2[i2] !== undefined && (i2 = e2 + "-" + n3), t2[i2] = e2 + "." + n3;
|
|
});
|
|
})(e, Nc);
|
|
}), Xs("a-text", Xr({}, null, { defaultComponents: Gc, mappings: Nc })), Xs("a-video", Xr({}, Tc(), { defaultComponents: { geometry: { primitive: "plane" }, material: { color: "#FFF", shader: "flat", side: "double", transparent: true } }, mappings: { height: "geometry.height", width: "geometry.width" } })), Xs("a-videosphere", Xr({}, Tc(), { defaultComponents: { geometry: { primitive: "sphere", radius: 500, segmentsWidth: 64, segmentsHeight: 32 }, material: { color: "#FFF", shader: "flat", side: "back", npot: true }, scale: "-1 1 1" }, mappings: { radius: "geometry.radius", "segments-height": "geometry.segmentsHeight", "segments-width": "geometry.segmentsWidth" } }));
|
|
jc = fi;
|
|
_c = jc("A-Frame:error");
|
|
Hc = jc("A-Frame:warn");
|
|
window.document.currentScript && window.document.currentScript.parentNode !== window.document.head && !window.debug && Hc("Put the A-Frame <script> tag in the <head> of the HTML *before* the scene to ensure everything for A-Frame is properly registered before they are used from HTML."), window.cordova || window.location.protocol !== "file:" || _c("This HTML file is currently being served via the file:// protocol. Assets, textures, and models WILL NOT WORK due to cross-origin policy! Please use a local or hosted server: https://aframe.io/docs/1.4.0/introduction/installation.html#use-a-local-server."), ji && (window.logs = jc, i(7180), i(9379)), console.log("A-Frame Version: 1.7.0 (Date 2025-03-12, Commit #1b9650f1)"), console.log("THREE Version (https://github.com/supermedium/three.js):", li.REVISION), window.AFRAME_ASYNC || (document.readyState !== "complete" ? document.addEventListener("readystatechange", function e() {
|
|
document.readyState === "complete" && (document.removeEventListener("readystatechange", e), gs());
|
|
}) : gs());
|
|
qc = globalThis.AFRAME = { AComponent: As, AEntity: Ls, ANode: bs, ANIME: Te, AScene: Us, components: Ko, coreComponents: Object.keys(Ko), geometries: js, registerComponent: cs, registerGeometry: qs, registerPrimitive: Xs, registerShader: ia, registerSystem: Es, primitives: { getMeshMixin: Tc, primitives: Js }, scenes: bo, schema: p, shaders: $s, systems: fs, emitReady: gs, THREE: li, utils: g, version: ca };
|
|
Vc = r.A;
|
|
});
|
|
|
|
// lib/xrforge/util.js
|
|
async function inferSource(src) {
|
|
let response = await fetch(src, {
|
|
method: "HEAD"
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
let contentDisposition = response.headers.get("Content-Disposition");
|
|
let file = extractFilename(contentDisposition);
|
|
let srcParts = src.split("/");
|
|
srcParts.pop();
|
|
srcParts.push(file);
|
|
return srcParts.join("/");
|
|
}
|
|
function extractFilename(contentDispositionHeader) {
|
|
if (!contentDispositionHeader)
|
|
return "";
|
|
const utf8Match = contentDispositionHeader.match(/filename\*=(?:utf-8|UTF-8)''(.+?)(?:;|$)/i);
|
|
if (utf8Match && utf8Match[1]) {
|
|
return decodeURIComponent(utf8Match[1].trim());
|
|
}
|
|
const basicMatch = contentDispositionHeader.match(/filename="(.+?)"/i);
|
|
if (basicMatch && basicMatch[1]) {
|
|
return basicMatch[1].trim();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// lib/xrforge/index.js
|
|
var btn_play = document.querySelector("#btn_play");
|
|
btn_play.addEventListener("click", () => {
|
|
btn_play.style.display = "none";
|
|
Promise.resolve().then(() => init_aframe_master_module_min());
|
|
});
|
|
var src = document.location.search.substr(1);
|
|
var cover2 = src;
|
|
var img = /\.(png|jpg|webp)/;
|
|
if (src.match(img)) {
|
|
cover2 = await inferSource(src);
|
|
src = cover2.replace(img, ".glb");
|
|
}
|
|
console.dir({ cover: cover2, src });
|
|
document.querySelector("#scene").setAttribute("gltf-model", `url(${src})`);
|
|
document.body.style.background = `url(${cover2}) no-repeat center / cover`;
|