@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
1,215 lines (1,205 loc) • 495 kB
JavaScript
import { Mesh as q, SphereGeometry as pi, Vector3 as P, MeshBasicMaterial as St, Node as Ea, PerspectiveCamera as bs, NodeFrame as Ca, NodeBuilder as Ba, GLSLNodeParser as wa, ShaderLib as Qt, UniformsUtils as fi, UniformsLib as Pn, normalView as ya, defaultShaderStages as Wn, ShaderChunk as Qa, Material as nn, TrianglesDrawMode as xa, TriangleFanDrawMode as Vs, TriangleStripDrawMode as No, Matrix4 as ue, Loader as Nt, LoaderUtils as sn, FileLoader as It, MeshPhysicalMaterial as Rt, Vector2 as Le, Color as Se, LinearSRGBColorSpace as Xe, SRGBColorSpace as ge, SpotLight as Uo, PointLight as Xs, DirectionalLight as Go, InstancedMesh as Sa, Quaternion as Te, InstancedBufferAttribute as Ta, Object3D as Tt, TextureLoader as mi, ImageBitmapLoader as va, BufferAttribute as st, InterleavedBuffer as Ra, LinearMipmapLinearFilter as zn, NearestMipmapLinearFilter as Po, LinearMipmapNearestFilter as Oo, NearestMipmapNearestFilter as Ii, LinearFilter as rt, NearestFilter as us, RepeatWrapping as an, MirroredRepeatWrapping as Ho, ClampToEdgeWrapping as gs, PointsMaterial as Fn, LineBasicMaterial as Lt, MeshStandardMaterial as bi, DoubleSide as Ei, PropertyBinding as Et, BufferGeometry as gt, SkinnedMesh as Ci, LineSegments as ds, Line as ft, LineLoop as _a, Points as as, Group as on, MathUtils as Qe, OrthographicCamera as jo, Skeleton as qo, AnimationClip as Bi, Bone as Zs, InterpolateDiscrete as wi, InterpolateLinear as Kn, InterleavedBufferAttribute as tn, Texture as $s, VectorKeyframeTrack as ps, NumberKeyframeTrack as fs, QuaternionKeyframeTrack as ms, ColorManagement as We, FrontSide as zo, Interpolant as Da, Box3 as Es, Sphere as yi, RGBA_S3TC_DXT1_Format as ei, RGB_PVRTC_4BPPV1_Format as Ma, RGB_ETC2_Format as Ko, RGB_ETC1_Format as Fa, RGBA_S3TC_DXT5_Format as ti, RGBA_PVRTC_4BPPV1_Format as ka, RGBA_ETC2_EAC_Format as Yo, RGBA_BPTC_Format as ni, RGB_BPTC_UNSIGNED_Format as La, RGBA_ASTC_4x4_Format as As, RGBAFormat as Kt, FloatType as bt, HalfFloatType as Ve, UnsignedByteType as pt, CompressedCubeTexture as Na, CompressedArrayTexture as Ua, CompressedTexture as On, NoColorSpace as Is, RGBA_S3TC_DXT3_Format as Ui, RGB_S3TC_DXT1_Format as Gi, RGBA_ASTC_6x6_Format as Pi, RGBFormat as si, RedFormat as pn, RGFormat as kn, UnsignedInt101111Type as Jo, UnsignedInt5999Type as Wo, DataTexture as Ga, Data3DTexture as Pa, ExtrudeGeometry as Oa, ShapePath as Ha, Raycaster as Qi, CylinderGeometry as Ke, BoxGeometry as je, Float32BufferAttribute as Fe, OctahedronGeometry as Vn, TorusGeometry as Bn, Euler as zt, Controls as Vo, PlaneGeometry as xi, DataTextureLoader as Xo, DataUtils as fn, Vector4 as Ut, Curve as ja, MeshPhongMaterial as Hn, MeshLambertMaterial as qa, EquirectangularReflectionMapping as za, AmbientLight as Ka, Uint16BufferAttribute as Ya, Matrix3 as Zo, ShapeUtils as Ja, DefaultLoadingManager as Wa, Ray as Va, Plane as Xa, MOUSE as In, TOUCH as mn, Spherical as Oi, ShaderMaterial as $o, Uniform$1 as Za, Scene as ii, WebGLRenderer as $a, CanvasTexture as er, REVISION as eA, Source as tA, InstancedBufferGeometry as nA, InstancedInterleavedBuffer as oi, WireframeGeometry as sA, Line3 as iA, ColorKeyframeTrack as oA } from "./three-BRSLmpyi.js";
class Bh extends q {
constructor(e, t, s, n = 128) {
if (t <= 0 || s <= 0 || n <= 0)
throw new Error("GroundedSkybox height, radius, and resolution must be positive.");
const i = new pi(s, 2 * n, n);
i.scale(1, 1, -1);
const o = i.getAttribute("position"), r = new P();
for (let a = 0; a < o.count; ++a)
if (r.fromBufferAttribute(o, a), r.y < 0) {
const c = -t * 3 / 2, l = r.y < c ? -t / r.y : 1 - r.y * r.y / (3 * c * c);
r.multiplyScalar(l), r.toArray(o.array, 3 * a);
}
o.needsUpdate = !0, super(i, new St({ map: e, depthWrite: !1 }));
}
}
class Be extends Ea {
constructor(e) {
super(e.nodeType), this.node = null, this.source = null, this.target = null, this.inclusionType = "replace", Object.assign(this, e);
}
generate(e) {
return this.node.build(e, this.getNodeType(e));
}
}
const nt = new Ca();
nt.camera = new bs();
const Hi = {
LineBasicNodeMaterial: Qt.basic,
MeshBasicNodeMaterial: Qt.basic,
PointsNodeMaterial: Qt.points,
MeshStandardNodeMaterial: Qt.standard,
MeshPhysicalNodeMaterial: Qt.physical,
MeshPhongNodeMaterial: Qt.phong
}, rA = {
atan2: "atan"
}, aA = {
low: "lowp",
medium: "mediump",
high: "highp"
};
function Ot(A) {
return `#include <${A}>`;
}
function wn(A) {
return `${A}Shader`;
}
class AA extends Ba {
constructor(e, t, s, n = null) {
super(e, t, new wa(), null, n), this.shader = s, this.slots = { vertex: [], fragment: [] }, this._parseShaderLib(), this._parseInclude("fragment", "lights_physical_fragment", "clearcoat_normal_fragment_begin", "transmission_fragment"), this._parseObject(), this._sortSlotsToFlow(), this.useComparisonMethod = !0;
}
getMethod(e) {
return rA[e] || e;
}
addSlot(e, t) {
this.slots[e].push(t);
}
_parseShaderLib() {
const e = this.material;
let t = e.type;
if (e.isMeshPhysicalNodeMaterial ? t = "MeshPhysicalNodeMaterial" : e.isMeshStandardNodeMaterial ? t = "MeshStandardNodeMaterial" : e.isMeshPhongNodeMaterial ? t = "MeshPhongNodeMaterial" : e.isMeshBasicNodeMaterial ? t = "MeshBasicNodeMaterial" : e.isPointsNodeMaterial ? t = "PointsNodeMaterial" : e.isLineBasicNodeMaterial && (t = "LineBasicNodeMaterial"), Hi[t] !== void 0) {
const s = Hi[t], n = this.shader;
n.vertexShader = s.vertexShader, n.fragmentShader = s.fragmentShader, n.uniforms = fi.merge([s.uniforms, Pn.lights]);
}
}
_parseObject() {
const { material: e, renderer: t } = this;
this.addSlot("fragment", new Be({
node: ya,
nodeType: "vec3",
source: "void main() {",
target: "vec3 TransformedNormalView = %RESULT%;",
inclusionType: "append"
})), t.toneMappingNode && t.toneMappingNode.isNode === !0 && this.addSlot("fragment", new Be({
node: e.colorNode,
nodeType: "vec4",
source: Ot("tonemapping_fragment"),
target: ""
})), e.colorNode && e.colorNode.isNode && this.addSlot("fragment", new Be({
node: e.colorNode,
nodeType: "vec4",
source: "vec4 diffuseColor = vec4( diffuse, opacity );",
target: "vec4 diffuseColor = %RESULT%; diffuseColor.a *= opacity;"
})), e.opacityNode && e.opacityNode.isNode && this.addSlot("fragment", new Be({
node: e.opacityNode,
nodeType: "float",
source: Ot("alphatest_fragment"),
target: "diffuseColor.a = %RESULT%;",
inclusionType: "append"
})), e.normalNode && e.normalNode.isNode && this.addSlot("fragment", new Be({
node: e.normalNode,
nodeType: "vec3",
source: Ot("normal_fragment_begin"),
target: "normal = %RESULT%;",
inclusionType: "append"
})), e.emissiveNode && e.emissiveNode.isNode && this.addSlot("fragment", new Be({
node: e.emissiveNode,
nodeType: "vec3",
source: Ot("emissivemap_fragment"),
target: "totalEmissiveRadiance = %RESULT%;",
inclusionType: "append"
})), e.isMeshStandardNodeMaterial && (e.metalnessNode && e.metalnessNode.isNode && this.addSlot("fragment", new Be({
node: e.metalnessNode,
nodeType: "float",
source: Ot("metalnessmap_fragment"),
target: "metalnessFactor = %RESULT%;",
inclusionType: "append"
})), e.roughnessNode && e.roughnessNode.isNode && this.addSlot("fragment", new Be({
node: e.roughnessNode,
nodeType: "float",
source: Ot("roughnessmap_fragment"),
target: "roughnessFactor = %RESULT%;",
inclusionType: "append"
})), e.isMeshPhysicalNodeMaterial && (e.clearcoatNode && e.clearcoatNode.isNode ? (this.addSlot("fragment", new Be({
node: e.clearcoatNode,
nodeType: "float",
source: "material.clearcoat = clearcoat;",
target: "material.clearcoat = %RESULT%;"
})), e.clearcoatRoughnessNode && e.clearcoatRoughnessNode.isNode && this.addSlot("fragment", new Be({
node: e.clearcoatRoughnessNode,
nodeType: "float",
source: "material.clearcoatRoughness = clearcoatRoughness;",
target: "material.clearcoatRoughness = %RESULT%;"
})), e.clearcoatNormalNode && e.clearcoatNormalNode.isNode && this.addSlot("fragment", new Be({
node: e.clearcoatNormalNode,
nodeType: "vec3",
source: "vec3 clearcoatNormal = nonPerturbedNormal;",
target: "vec3 clearcoatNormal = %RESULT%;"
})), e.defines.USE_CLEARCOAT = "") : delete e.defines.USE_CLEARCOAT, e.sheenNode && e.sheenNode.isNode ? (this.addSlot("fragment", new Be({
node: e.sheenNode,
nodeType: "vec3",
source: "material.sheenColor = sheenColor;",
target: "material.sheenColor = %RESULT%;"
})), e.sheenRoughnessNode && e.sheenRoughnessNode.isNode && this.addSlot("fragment", new Be({
node: e.sheenRoughnessNode,
nodeType: "float",
source: "material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );",
target: "material.sheenRoughness = clamp( %RESULT%, 0.07, 1.0 );"
})), e.defines.USE_SHEEN = "") : delete e.defines.USE_SHEEN, e.iridescenceNode && e.iridescenceNode.isNode ? (this.addSlot("fragment", new Be({
node: e.iridescenceNode,
nodeType: "float",
source: "material.iridescence = iridescence;",
target: "material.iridescence = %RESULT%;"
})), e.iridescenceIORNode && e.iridescenceIORNode.isNode && this.addSlot("fragment", new Be({
node: e.iridescenceIORNode,
nodeType: "float",
source: "material.iridescenceIOR = iridescenceIOR;",
target: "material.iridescenceIOR = %RESULT%;"
})), e.iridescenceThicknessNode && e.iridescenceThicknessNode.isNode && this.addSlot("fragment", new Be({
node: e.iridescenceThicknessNode,
nodeType: "float",
source: "material.iridescenceThickness = iridescenceThicknessMaximum;",
target: "material.iridescenceThickness = %RESULT%;"
})), e.defines.USE_IRIDESCENCE = "") : delete e.defines.USE_IRIDESCENCE, e.iorNode && e.iorNode.isNode && this.addSlot("fragment", new Be({
node: e.iorNode,
nodeType: "float",
source: "material.ior = ior;",
target: "material.ior = %RESULT%;"
})), e.specularColorNode && e.specularColorNode.isNode && this.addSlot("fragment", new Be({
node: e.specularColorNode,
nodeType: "vec3",
source: "vec3 specularColorFactor = specularColor;",
target: "vec3 specularColorFactor = %RESULT%;"
})), e.specularIntensityNode && e.specularIntensityNode.isNode && this.addSlot("fragment", new Be({
node: e.specularIntensityNode,
nodeType: "float",
source: "float specularIntensityFactor = specularIntensity;",
target: "float specularIntensityFactor = %RESULT%;"
})), e.transmissionNode && e.transmissionNode.isNode ? (this.addSlot("fragment", new Be({
node: e.transmissionNode,
nodeType: "float",
source: "material.transmission = transmission;",
target: "material.transmission = %RESULT%;"
})), e.thicknessNode && e.thicknessNode.isNode && this.addSlot("fragment", new Be({
node: e.thicknessNode,
nodeType: "float",
source: "material.thickness = thickness;",
target: "material.thickness = %RESULT%;"
})), e.attenuationDistanceNode && e.attenuationDistanceNode.isNode && this.addSlot("fragment", new Be({
node: e.attenuationDistanceNode,
nodeType: "float",
source: "material.attenuationDistance = attenuationDistance;",
target: "material.attenuationDistance = %RESULT%;"
})), e.attenuationColorNode && e.attenuationColorNode.isNode && this.addSlot("fragment", new Be({
node: e.attenuationColorNode,
nodeType: "vec3",
source: "material.attenuationColor = attenuationColor;",
target: "material.attenuationColor = %RESULT%;"
})), e.transmission = 1, e.defines.USE_TRANSMISSION = "") : (e.transmission = 0, delete e.defines.USE_TRANSMISSION))), e.positionNode && e.positionNode.isNode && this.addSlot("vertex", new Be({
node: e.positionNode,
nodeType: "vec3",
source: Ot("begin_vertex"),
target: "transformed = %RESULT%;",
inclusionType: "append"
})), e.sizeNode && e.sizeNode.isNode && this.addSlot("vertex", new Be({
node: e.sizeNode,
nodeType: "float",
source: "gl_PointSize = size;",
target: "gl_PointSize = %RESULT%;"
}));
}
generateTexture(e, t, s) {
return e.isTextureCube ? `textureCube( ${t}, ${s} )` : `texture2D( ${t}, ${s} )`;
}
generateTextureLevel(e, t, s, n) {
return `textureLod( ${t}, ${s}, ${n} )`;
}
buildFunctionCode(e) {
const t = e.layout, s = this.flowShaderNode(e), n = [];
for (const o of t.inputs)
n.push(this.getType(o.type) + " " + o.name);
return `${this.getType(t.type)} ${t.name}( ${n.join(", ")} ) {
${s.vars}
${s.code}
return ${s.result};
}`;
}
getUniforms(e) {
const t = this.uniforms[e];
let s = "";
for (const n of t) {
if (/^(modelViewMatrix|projectionMatrix)$/.test(n.name))
continue;
let i = null;
n.type === "texture" ? i = `sampler2D ${n.name}; ` : n.type === "cubeTexture" ? i = `samplerCube ${n.name}; ` : i = `${this.getVectorType(n.type)} ${n.name}; `;
const o = n.node.precision;
o !== null ? i = "uniform " + aA[o] + " " + i : i = "uniform " + i, s += i;
}
return s;
}
getAttributes(e) {
let t = "";
if (e === "vertex") {
const s = this.attributes;
for (const n of s)
/^(position|normal|uv[1-3]?)$/.test(n.name) || (t += `attribute ${n.type} ${n.name}; `);
}
return t;
}
getVaryings(e) {
let t = "";
const s = this.varyings;
if (e === "vertex")
for (const n of s)
t += `${n.needsInterpolation ? "varying" : "/*varying*/"} ${n.type} ${n.name}; `;
else if (e === "fragment")
for (const n of s)
n.needsInterpolation && (t += `varying ${n.type} ${n.name}; `);
return t;
}
addCode(e, t, s, n = this) {
const i = wn(e);
let o = n[i];
const r = o.indexOf(t);
if (r !== -1) {
const a = o.substring(0, r + t.length), c = o.substring(r + t.length);
o = `${a}
${s}
${c}`;
}
n[i] = o;
}
replaceCode(e, t, s, n = this) {
const i = wn(e);
n[i] = n[i].replaceAll(t, s);
}
getVertexIndex() {
return "gl_VertexID";
}
getFrontFacing() {
return "gl_FrontFacing";
}
getFragCoord() {
return "gl_FragCoord";
}
isFlipY() {
return !0;
}
buildCode() {
const e = {};
for (const t of Wn) {
const s = this.getUniforms(t), n = this.getAttributes(t), i = this.getVaryings(t), o = this.getVars(t), r = this.getCodes(t);
e[t] = `${this.getSignature()}
// <node_builder>
// uniforms
${s}
// attributes
${n}
// varyings
${i}
// vars
${o}
// codes
${r}
// </node_builder>
${this.shader[wn(t)]}
`;
}
this.vertexShader = e.vertex, this.fragmentShader = e.fragment;
}
build() {
return super.build(!1), this._addSnippets(), this._addUniforms(), this._updateUniforms(), this.shader.vertexShader = this.vertexShader, this.shader.fragmentShader = this.fragmentShader, this;
}
_parseInclude(e, ...t) {
for (const s of t) {
const n = Ot(s), i = Qa[s], o = wn(e);
this.shader[o] = this.shader[o].replaceAll(n, i);
}
}
_sortSlotsToFlow() {
for (const e of Wn) {
const t = this.shader[wn(e)], s = this.slots[e].sort((n, i) => t.indexOf(n.source) > t.indexOf(i.source) ? 1 : -1);
for (const n of s)
this.addFlow(e, n);
}
}
_addSnippets() {
for (const e of Wn) {
for (const t of this.slots[e]) {
const s = this.getFlowData(
t
/*, shaderStage*/
), n = t.inclusionType, i = t.source, o = s.code + `
` + t.target.replace("%RESULT%", s.result);
n === "append" ? this.addCode(e, i, o) : n === "replace" ? this.replaceCode(e, i, o) : console.warn(`Inclusion type "${n}" not compatible.`);
}
this.addCode(
e,
"main() {",
`
` + this.flowCode[e]
);
}
}
_addUniforms() {
for (const e of Wn)
for (const t of this.uniforms[e])
this.shader.uniforms[t.name] = t;
}
_updateUniforms() {
nt.object = this.object, nt.renderer = this.renderer, nt.material = this.material, nt.scene = this.scene;
for (const e of this.updateNodes)
nt.updateNode(e);
}
}
const tr = /* @__PURE__ */ new WeakMap();
nn.prototype.onBuild = function(A, e, t) {
const s = this;
if (s.isNodeMaterial === !0) {
let n;
try {
n = new AA(A, t, e, s).build(), tr.set(s, n);
} catch (i) {
console.error("Material.prototype.onBuild: ", i);
}
}
};
nn.prototype.onBeforeRender = function(A, e, t, s, n) {
const i = tr.get(this);
if (i !== void 0) {
nt.material = this, nt.camera = t, nt.object = n, nt.renderer = A, nt.scene = e, nt.geometry = s;
const o = i.updateNodes;
if (o.length > 0) {
A.state.useProgram(null);
for (const r of o)
nt.updateNode(r);
}
}
};
var cs = function() {
var A = 0, e = document.createElement("div");
e.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", e.addEventListener("click", function(l) {
l.preventDefault(), s(++A % e.children.length);
}, !1);
function t(l) {
return e.appendChild(l.dom), l;
}
function s(l) {
for (var h = 0; h < e.children.length; h++)
e.children[h].style.display = h === l ? "block" : "none";
A = l;
}
var n = (performance || Date).now(), i = n, o = 0, r = t(new cs.Panel("FPS", "#0ff", "#002")), a = t(new cs.Panel("MS", "#0f0", "#020"));
if (self.performance && self.performance.memory)
var c = t(new cs.Panel("MB", "#f08", "#201"));
return s(0), {
REVISION: 16,
dom: e,
addPanel: t,
showPanel: s,
begin: function() {
n = (performance || Date).now();
},
end: function() {
o++;
var l = (performance || Date).now();
if (a.update(l - n, 200), l >= i + 1e3 && (r.update(o * 1e3 / (l - i), 100), i = l, o = 0, c)) {
var h = performance.memory;
c.update(h.usedJSHeapSize / 1048576, h.jsHeapSizeLimit / 1048576);
}
return l;
},
update: function() {
n = this.end();
},
// Backwards Compatibility
domElement: e,
setMode: s
};
};
cs.Panel = function(A, e, t) {
var s = 1 / 0, n = 0, i = Math.round, o = i(window.devicePixelRatio || 1), r = 80 * o, a = 48 * o, c = 3 * o, l = 2 * o, h = 3 * o, u = 15 * o, d = 74 * o, p = 30 * o, m = document.createElement("canvas");
m.width = r, m.height = a, m.style.cssText = "width:80px;height:48px";
var I = m.getContext("2d");
return I.font = "bold " + 9 * o + "px Helvetica,Arial,sans-serif", I.textBaseline = "top", I.fillStyle = t, I.fillRect(0, 0, r, a), I.fillStyle = e, I.fillText(A, c, l), I.fillRect(h, u, d, p), I.fillStyle = t, I.globalAlpha = 0.9, I.fillRect(h, u, d, p), {
dom: m,
update: function(E, w) {
s = Math.min(s, E), n = Math.max(n, E), I.fillStyle = t, I.globalAlpha = 1, I.fillRect(0, 0, r, u), I.fillStyle = e, I.fillText(i(E) + " " + A + " (" + i(s) + "-" + i(n) + ")", c, l), I.drawImage(m, h + o, u, d - o, p, h, u, d - o, p), I.fillRect(h + d - o, u, o, p), I.fillStyle = t, I.globalAlpha = 0.9, I.fillRect(h + d - o, u, o, i((1 - E / w) * p));
}
};
};
function wh(A, e = 1e-4) {
e = Math.max(e, Number.EPSILON);
const t = {}, s = A.getIndex(), n = A.getAttribute("position"), i = s ? s.count : n.count;
let o = 0;
const r = Object.keys(A.attributes), a = {}, c = {}, l = [], h = ["getX", "getY", "getZ", "getW"], u = ["setX", "setY", "setZ", "setW"];
for (let w = 0, b = r.length; w < b; w++) {
const B = r[w], y = A.attributes[B];
a[B] = new y.constructor(
new y.array.constructor(y.count * y.itemSize),
y.itemSize,
y.normalized
);
const R = A.morphAttributes[B];
R && (c[B] || (c[B] = []), R.forEach((_, x) => {
const T = new _.array.constructor(_.count * _.itemSize);
c[B][x] = new _.constructor(T, _.itemSize, _.normalized);
}));
}
const d = e * 0.5, p = Math.log10(1 / e), m = Math.pow(10, p), I = d * m;
for (let w = 0; w < i; w++) {
const b = s ? s.getX(w) : w;
let B = "";
for (let y = 0, R = r.length; y < R; y++) {
const _ = r[y], x = A.getAttribute(_), T = x.itemSize;
for (let L = 0; L < T; L++)
B += `${~~(x[h[L]](b) * m + I)},`;
}
if (B in t)
l.push(t[B]);
else {
for (let y = 0, R = r.length; y < R; y++) {
const _ = r[y], x = A.getAttribute(_), T = A.morphAttributes[_], L = x.itemSize, N = a[_], H = c[_];
for (let Z = 0; Z < L; Z++) {
const U = h[Z], Y = u[Z];
if (N[Y](o, x[U](b)), T)
for (let O = 0, $ = T.length; O < $; O++)
H[O][Y](o, T[O][U](b));
}
}
t[B] = o, l.push(o), o++;
}
}
const E = A.clone();
for (const w in A.attributes) {
const b = a[w];
if (E.setAttribute(w, new b.constructor(
b.array.slice(0, o * b.itemSize),
b.itemSize,
b.normalized
)), w in c)
for (let B = 0; B < c[w].length; B++) {
const y = c[w][B];
E.morphAttributes[w][B] = new y.constructor(
y.array.slice(0, o * y.itemSize),
y.itemSize,
y.normalized
);
}
}
return E.setIndex(l), E;
}
function ji(A, e) {
if (e === xa)
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), A;
if (e === Vs || e === No) {
let t = A.getIndex();
if (t === null) {
const o = [], r = A.getAttribute("position");
if (r !== void 0) {
for (let a = 0; a < r.count; a++)
o.push(a);
A.setIndex(o), t = A.getIndex();
} else
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), A;
}
const s = t.count - 2, n = [];
if (e === Vs)
for (let o = 1; o <= s; o++)
n.push(t.getX(0)), n.push(t.getX(o)), n.push(t.getX(o + 1));
else
for (let o = 0; o < s; o++)
o % 2 === 0 ? (n.push(t.getX(o)), n.push(t.getX(o + 1)), n.push(t.getX(o + 2))) : (n.push(t.getX(o + 2)), n.push(t.getX(o + 1)), n.push(t.getX(o)));
n.length / 3 !== s && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
const i = A.clone();
return i.setIndex(n), i.clearGroups(), i;
} else
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", e), A;
}
class nr extends Nt {
constructor(e) {
super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) {
return new gA(t);
}), this.register(function(t) {
return new dA(t);
}), this.register(function(t) {
return new wA(t);
}), this.register(function(t) {
return new yA(t);
}), this.register(function(t) {
return new QA(t);
}), this.register(function(t) {
return new fA(t);
}), this.register(function(t) {
return new mA(t);
}), this.register(function(t) {
return new IA(t);
}), this.register(function(t) {
return new bA(t);
}), this.register(function(t) {
return new uA(t);
}), this.register(function(t) {
return new EA(t);
}), this.register(function(t) {
return new pA(t);
}), this.register(function(t) {
return new BA(t);
}), this.register(function(t) {
return new CA(t);
}), this.register(function(t) {
return new lA(t);
}), this.register(function(t) {
return new xA(t);
}), this.register(function(t) {
return new SA(t);
});
}
load(e, t, s, n) {
const i = this;
let o;
if (this.resourcePath !== "")
o = this.resourcePath;
else if (this.path !== "") {
const c = sn.extractUrlBase(e);
o = sn.resolveURL(c, this.path);
} else
o = sn.extractUrlBase(e);
this.manager.itemStart(e);
const r = function(c) {
n ? n(c) : console.error(c), i.manager.itemError(e), i.manager.itemEnd(e);
}, a = new It(this.manager);
a.setPath(this.path), a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setWithCredentials(this.withCredentials), a.load(e, function(c) {
try {
i.parse(c, o, function(l) {
t(l), i.manager.itemEnd(e);
}, r);
} catch (l) {
r(l);
}
}, s, r);
}
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, t, s, n) {
let i, o;
const r = {}, a = {}, c = new TextDecoder();
if (typeof e == "string")
try {
i = JSON.parse(e);
} catch (h) {
o = e, n && n(h);
return;
}
else if (e instanceof ArrayBuffer)
if (c.decode(new Uint8Array(e, 0, 4)) === sr) {
try {
r[ae.KHR_BINARY_GLTF] = new TA(e);
} catch (u) {
n && n(u);
return;
}
try {
i = JSON.parse(r[ae.KHR_BINARY_GLTF].content);
} catch (u) {
o = r[ae.KHR_BINARY_GLTF].content, n && n(u);
return;
}
} else
try {
i = JSON.parse(c.decode(e));
} catch (u) {
o = c.decode(e), n && n(u);
return;
}
else
i = e;
if (i.asset === void 0 || i.asset.version[0] < 2) {
n && n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
return;
}
this.json = i, this.jsonErrorData = o;
const l = new OA(i, {
path: t || this.resourcePath || "",
crossOrigin: this.crossOrigin,
requestHeader: this.requestHeader,
manager: this.manager,
ktx2Loader: this.ktx2Loader,
meshoptDecoder: this.meshoptDecoder
});
l.fileLoader.setRequestHeader(this.requestHeader);
for (let h = 0; h < this.pluginCallbacks.length; h++) {
const u = this.pluginCallbacks[h](l);
u.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[u.name] = u, r[u.name] = !0;
}
if (i.extensionsUsed)
for (let h = 0; h < i.extensionsUsed.length; ++h) {
const u = i.extensionsUsed[h], d = i.extensionsRequired || [];
switch (u) {
case ae.KHR_MATERIALS_UNLIT:
r[u] = new hA();
break;
case ae.KHR_DRACO_MESH_COMPRESSION:
r[u] = new vA(i, this.dracoLoader);
break;
case ae.KHR_TEXTURE_TRANSFORM:
r[u] = new RA();
break;
case ae.KHR_MESH_QUANTIZATION:
r[u] = new _A();
break;
default:
d.indexOf(u) >= 0 && a[u] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + u + '".');
}
}
l.setExtensions(r), l.setPlugins(a), l.parse(s, n);
}
parseAsync(e, t) {
const s = this;
return new Promise(function(n, i) {
s.parse(e, t, n, i);
});
}
}
function cA() {
let A = {};
return {
get: function(e) {
return A[e];
},
add: function(e, t) {
A[e] = t;
},
remove: function(e) {
delete A[e];
},
removeAll: function() {
A = {};
}
};
}
const ae = {
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"
};
class lA {
constructor(e) {
this.parser = e, this.name = ae.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
}
_markDefs() {
const e = this.parser, t = this.parser.json.nodes || [];
for (let s = 0, n = t.length; s < n; s++) {
const i = t[s];
i.extensions && i.extensions[this.name] && i.extensions[this.name].light !== void 0 && e._addNodeRef(this.cache, i.extensions[this.name].light);
}
}
_loadLight(e) {
const t = this.parser, s = "light:" + e;
let n = t.cache.get(s);
if (n) return n;
const i = t.json, a = ((i.extensions && i.extensions[this.name] || {}).lights || [])[e];
let c;
const l = new Se(16777215);
a.color !== void 0 && l.setRGB(a.color[0], a.color[1], a.color[2], Xe);
const h = a.range !== void 0 ? a.range : 0;
switch (a.type) {
case "directional":
c = new Go(l), c.target.position.set(0, 0, -1), c.add(c.target);
break;
case "point":
c = new Xs(l), c.distance = h;
break;
case "spot":
c = new Uo(l), c.distance = h, a.spot = a.spot || {}, a.spot.innerConeAngle = a.spot.innerConeAngle !== void 0 ? a.spot.innerConeAngle : 0, a.spot.outerConeAngle = a.spot.outerConeAngle !== void 0 ? a.spot.outerConeAngle : Math.PI / 4, c.angle = a.spot.outerConeAngle, c.penumbra = 1 - a.spot.innerConeAngle / a.spot.outerConeAngle, c.target.position.set(0, 0, -1), c.add(c.target);
break;
default:
throw new Error("THREE.GLTFLoader: Unexpected light type: " + a.type);
}
return c.position.set(0, 0, 0), c.decay = 2, kt(c, a), a.intensity !== void 0 && (c.intensity = a.intensity), c.name = t.createUniqueName(a.name || "light_" + e), n = Promise.resolve(c), t.cache.add(s, n), n;
}
getDependency(e, t) {
if (e === "light")
return this._loadLight(t);
}
createNodeAttachment(e) {
const t = this, s = this.parser, i = s.json.nodes[e], r = (i.extensions && i.extensions[this.name] || {}).light;
return r === void 0 ? null : this._loadLight(r).then(function(a) {
return s._getNodeRef(t.cache, r, a);
});
}
}
let hA = class {
constructor() {
this.name = ae.KHR_MATERIALS_UNLIT;
}
getMaterialType() {
return St;
}
extendParams(e, t, s) {
const n = [];
e.color = new Se(1, 1, 1), e.opacity = 1;
const i = t.pbrMetallicRoughness;
if (i) {
if (Array.isArray(i.baseColorFactor)) {
const o = i.baseColorFactor;
e.color.setRGB(o[0], o[1], o[2], Xe), e.opacity = o[3];
}
i.baseColorTexture !== void 0 && n.push(s.assignTexture(e, "map", i.baseColorTexture, ge));
}
return Promise.all(n);
}
}, uA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_EMISSIVE_STRENGTH;
}
extendMaterialParams(e, t) {
const n = this.parser.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = n.extensions[this.name].emissiveStrength;
return i !== void 0 && (t.emissiveIntensity = i), Promise.resolve();
}
}, gA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_CLEARCOAT;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
if (o.clearcoatFactor !== void 0 && (t.clearcoat = o.clearcoatFactor), o.clearcoatTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatMap", o.clearcoatTexture)), o.clearcoatRoughnessFactor !== void 0 && (t.clearcoatRoughness = o.clearcoatRoughnessFactor), o.clearcoatRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatRoughnessMap", o.clearcoatRoughnessTexture)), o.clearcoatNormalTexture !== void 0 && (i.push(s.assignTexture(t, "clearcoatNormalMap", o.clearcoatNormalTexture)), o.clearcoatNormalTexture.scale !== void 0)) {
const r = o.clearcoatNormalTexture.scale;
t.clearcoatNormalScale = new Le(r, r);
}
return Promise.all(i);
}
}, dA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_DISPERSION;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const n = this.parser.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = n.extensions[this.name];
return t.dispersion = i.dispersion !== void 0 ? i.dispersion : 0, Promise.resolve();
}
}, pA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_IRIDESCENCE;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
return o.iridescenceFactor !== void 0 && (t.iridescence = o.iridescenceFactor), o.iridescenceTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceMap", o.iridescenceTexture)), o.iridescenceIor !== void 0 && (t.iridescenceIOR = o.iridescenceIor), t.iridescenceThicknessRange === void 0 && (t.iridescenceThicknessRange = [100, 400]), o.iridescenceThicknessMinimum !== void 0 && (t.iridescenceThicknessRange[0] = o.iridescenceThicknessMinimum), o.iridescenceThicknessMaximum !== void 0 && (t.iridescenceThicknessRange[1] = o.iridescenceThicknessMaximum), o.iridescenceThicknessTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceThicknessMap", o.iridescenceThicknessTexture)), Promise.all(i);
}
}, fA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_SHEEN;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [];
t.sheenColor = new Se(0, 0, 0), t.sheenRoughness = 0, t.sheen = 1;
const o = n.extensions[this.name];
if (o.sheenColorFactor !== void 0) {
const r = o.sheenColorFactor;
t.sheenColor.setRGB(r[0], r[1], r[2], Xe);
}
return o.sheenRoughnessFactor !== void 0 && (t.sheenRoughness = o.sheenRoughnessFactor), o.sheenColorTexture !== void 0 && i.push(s.assignTexture(t, "sheenColorMap", o.sheenColorTexture, ge)), o.sheenRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "sheenRoughnessMap", o.sheenRoughnessTexture)), Promise.all(i);
}
}, mA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_TRANSMISSION;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
return o.transmissionFactor !== void 0 && (t.transmission = o.transmissionFactor), o.transmissionTexture !== void 0 && i.push(s.assignTexture(t, "transmissionMap", o.transmissionTexture)), Promise.all(i);
}
}, IA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_VOLUME;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
t.thickness = o.thicknessFactor !== void 0 ? o.thicknessFactor : 0, o.thicknessTexture !== void 0 && i.push(s.assignTexture(t, "thicknessMap", o.thicknessTexture)), t.attenuationDistance = o.attenuationDistance || 1 / 0;
const r = o.attenuationColor || [1, 1, 1];
return t.attenuationColor = new Se().setRGB(r[0], r[1], r[2], Xe), Promise.all(i);
}
}, bA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_IOR;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const n = this.parser.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = n.extensions[this.name];
return t.ior = i.ior !== void 0 ? i.ior : 1.5, Promise.resolve();
}
}, EA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_SPECULAR;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
t.specularIntensity = o.specularFactor !== void 0 ? o.specularFactor : 1, o.specularTexture !== void 0 && i.push(s.assignTexture(t, "specularIntensityMap", o.specularTexture));
const r = o.specularColorFactor || [1, 1, 1];
return t.specularColor = new Se().setRGB(r[0], r[1], r[2], Xe), o.specularColorTexture !== void 0 && i.push(s.assignTexture(t, "specularColorMap", o.specularColorTexture, ge)), Promise.all(i);
}
}, CA = class {
constructor(e) {
this.parser = e, this.name = ae.EXT_MATERIALS_BUMP;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
return t.bumpScale = o.bumpFactor !== void 0 ? o.bumpFactor : 1, o.bumpTexture !== void 0 && i.push(s.assignTexture(t, "bumpMap", o.bumpTexture)), Promise.all(i);
}
}, BA = class {
constructor(e) {
this.parser = e, this.name = ae.KHR_MATERIALS_ANISOTROPY;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : Rt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
return o.anisotropyStrength !== void 0 && (t.anisotropy = o.anisotropyStrength), o.anisotropyRotation !== void 0 && (t.anisotropyRotation = o.anisotropyRotation), o.anisotropyTexture !== void 0 && i.push(s.assignTexture(t, "anisotropyMap", o.anisotropyTexture)), Promise.all(i);
}
};
class wA {
constructor(e) {
this.parser = e, this.name = ae.KHR_TEXTURE_BASISU;
}
loadTexture(e) {
const t = this.parser, s = t.json, n = s.textures[e];
if (!n.extensions || !n.extensions[this.name])
return null;
const i = n.extensions[this.name], o = t.options.ktx2Loader;
if (!o) {
if (s.extensionsRequired && s.extensionsRequired.indexOf(this.name) >= 0)
throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
return null;
}
return t.loadTextureImage(e, i.source, o);
}
}
class yA {
constructor(e) {
this.parser = e, this.name = ae.EXT_TEXTURE_WEBP, this.isSupported = null;
}
loadTexture(e) {
const t = this.name, s = this.parser, n = s.json, i = n.textures[e];
if (!i.extensions || !i.extensions[t])
return null;
const o = i.extensions[t], r = n.images[o.source];
let a = s.textureLoader;
if (r.uri) {
const c = s.options.manager.getHandler(r.uri);
c !== null && (a = c);
}
return this.detectSupport().then(function(c) {
if (c) return s.loadTextureImage(e, o.source, a);
if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0)
throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
return s.loadTexture(e);
});
}
detectSupport() {
return this.isSupported || (this.isSupported = new Promise(function(e) {
const t = new Image();
t.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", t.onload = t.onerror = function() {
e(t.height === 1);
};
})), this.isSupported;
}
}
class QA {
constructor(e) {
this.parser = e, this.name = ae.EXT_TEXTURE_AVIF, this.isSupported = null;
}
loadTexture(e) {
const t = this.name, s = this.parser, n = s.json, i = n.textures[e];
if (!i.extensions || !i.extensions[t])
return null;
const o = i.extensions[t], r = n.images[o.source];
let a = s.textureLoader;
if (r.uri) {
const c = s.options.manager.getHandler(r.uri);
c !== null && (a = c);
}
return this.detectSupport().then(function(c) {
if (c) return s.loadTextureImage(e, o.source, a);
if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0)
throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");
return s.loadTexture(e);
});
}
detectSupport() {
return this.isSupported || (this.isSupported = new Promise(function(e) {
const t = new Image();
t.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=", t.onload = t.onerror = function() {
e(t.height === 1);
};
})), this.isSupported;
}
}
class xA {
constructor(e) {
this.name = ae.EXT_MESHOPT_COMPRESSION, this.parser = e;
}
loadBufferView(e) {
const t = this.parser.json, s = t.bufferViews[e];
if (s.extensions && s.extensions[this.name]) {
const n = s.extensions[this.name], i = this.parser.getDependency("buffer", n.buffer), o = this.parser.options.meshoptDecoder;
if (!o || !o.supported) {
if (t.extensionsRequired && t.extensionsRequired.indexOf(this.name) >= 0)
throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
return null;
}
return i.then(function(r) {
const a = n.byteOffset || 0, c = n.byteLength || 0, l = n.count, h = n.byteStride, u = new Uint8Array(r, a, c);
return o.decodeGltfBufferAsync ? o.decodeGltfBufferAsync(l, h, u, n.mode, n.filter).then(function(d) {
return d.buffer;
}) : o.ready.then(function() {
const d = new ArrayBuffer(l * h);
return o.decodeGltfBuffer(new Uint8Array(d), l, h, u, n.mode, n.filter), d;
});
});
} else
return null;
}
}
let SA = class {
constructor(e) {
this.name = ae.EXT_MESH_GPU_INSTANCING, this.parser = e;
}
createNodeMesh(e) {
const t = this.parser.json, s = t.nodes[e];
if (!s.extensions || !s.extensions[this.name] || s.mesh === void 0)
return null;
const n = t.meshes[s.mesh];
for (const c of n.primitives)
if (c.mode !== ut.TRIANGLES && c.mode !== ut.TRIANGLE_STRIP && c.mode !== ut.TRIANGLE_FAN && c.mode !== void 0)
return null;
const o = s.extensions[this.name].attributes, r = [], a = {};
for (const c in o)
r.push(this.parser.getDependency("accessor", o[c]).then((l) => (a[c] = l, a[c])));
return r.length < 1 ? null : (r.push(this.parser.createNodeMesh(e)), Promise.all(r).then((c) => {
const l = c.pop(), h = l.isGroup ? l.children : [l], u = c[0].count, d = [];
for (const p of h) {
const m = new ue(), I = new P(), E = new Te(), w = new P(1, 1, 1), b = new Sa(p.geometry, p.material, u);
for (let B = 0; B < u; B++)
a.TRANSLATION && I.fromBufferAttribute(a.TRANSLATION, B), a.ROTATION && E.fromBufferAttribute(a.ROTATION, B), a.SCALE && w.fromBufferAttribute(a.SCALE, B), b.setMatrixAt(B, m.compose(I, E, w));
for (const B in a)
if (B === "_COLOR_0") {
const y = a[B];
b.instanceColor = new Ta(y.array, y.itemSize, y.normalized);
} else B !== "TRANSLATION" && B !== "ROTATION" && B !== "SCALE" && p.geometry.setAttribute(B, a[B]);
Tt.prototype.copy.call(b, p), this.parser.assignFinalMaterial(b), d.push(b);
}
return l.isGroup ? (l.clear(), l.add(...d), l) : d[0];
}));
}
};
const sr = "glTF", yn = 12, qi = { JSON: 1313821514, BIN: 5130562 };
class TA {
constructor(e) {
this.name = ae.KHR_BINARY_GLTF, this.content = null, this.body = null;
const t = new DataView(e, 0, yn), s = new TextDecoder();
if (this.header = {
magic: s.decode(new Uint8Array(e.slice(0, 4))),
version: t.getUint32(4, !0),
length: t.getUint32(8, !0)
}, this.header.magic !== sr)
throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
if (this.header.version < 2)
throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
const n = this.header.length - yn, i = new DataView(e, yn);
let o = 0;
for (; o < n; ) {
const r = i.getUint32(o, !0);
o += 4;
const a = i.getUint32(o, !0);
if (o += 4, a === qi.JSON) {
const c = new Uint8Array(e, yn + o, r);
this.content = s.decode(c);
} else if (a === qi.BIN) {
const c = yn + o;
this.body = e.slice(c, c + r);
}
o += r;
}
if (this.content === null)
throw new Error("THREE.GLTFLoader: JSON content not found.");
}
}
class vA {
constructor(e, t) {
if (!t)
throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
this.name = ae.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t, this.dracoLoader.preload();
}
decodePrimitive(e, t) {
const s = this.json, n = this.dracoLoader, i = e.extensions[this.name].bufferView, o = e.extensions[this.name].attributes, r = {}, a = {}, c = {};
for (const l in o) {
const h = ri[l] || l.toLowerCase();
r[h] = o[l];
}
for (const l in e.attributes) {
const h = ri[l] || l.toLowerCase();
if (o[l] !== void 0) {
const u = s.accessors[e.attributes[l]], d = bn[u.componentType];
c[h] = d.name, a[h] = u.normalized === !0;
}
}
return t.getDependency("bufferView", i).then(function(l) {
return new Promise(function(h, u) {
n.decodeDracoFile(l, function(d) {
for (const p in d.attributes) {
const m = d.attributes[p], I = a[p];
I !== void 0 && (m.normalized = I);
}
h(d);
}, r, c, Xe, u);
});
});
}
}
class RA {
constructor() {
this.name = ae.KHR_TEXTURE_TRANSFORM;
}
extendTexture(e, t) {
return (t.texCoord === void 0 || t.texCoord === e.channel) && t.offset === void 0 && t.rotation === void 0 && t.scale === void 0 || (e = e.clone(), t.texCoord !== void 0 && (e.channel = t.texCoord), t.offset !== void 0 && e.offset.fromArray(t.offset), t.rotation !== void 0 && (e.rotation = t.rotation), t.scale !== void 0 && e.repeat.fromArray(t.scale), e.needsUpdate = !0), e;
}
}
class _A {
constructor() {
this.name = ae.KHR_MESH_QUANTIZATION;
}
}
class ir extends Da {
constructor(e, t, s, n) {
super(e, t, s, n);
}
copySampleValue_(e) {
const t = this.resultBuffer, s = this.sampleValues, n = this.valueSize, i = e * n * 3 + n;
for (let o = 0; o !== n; o++)
t[o] = s[i + o];
return t;
}
interpolate_(e, t, s, n) {
const i = this.resultBuffer, o = this.sampleValues, r = this.valueSize, a = r * 2, c = r * 3, l = n - t, h = (s - t) / l, u = h * h, d = u * h, p = e * c, m = p - c, I = -2 * d + 3 * u, E = d - u, w = 1 - I, b = E - u + h;
for (let B = 0; B !== r; B++) {
const y = o[m + B + r], R = o[m + B + a] * l, _ = o[p + B + r], x = o[p + B] * l;
i[B] = w * y + b * R + I * _ + E * x;
}
return i;
}
}
const DA = new Te();
class MA extends ir {
interpolate_(e, t, s, n) {
const i = super.interpolate_(e, t, s, n);
return DA.fromArray(i).normalize().toArray(i), i;
}
}
const ut = {
POINTS: 0,
LINES: 1,
LINE_LOOP: 2,
LINE_STRIP: 3,
TRIANGLES: 4,
TRIANGLE_STRIP: 5,
TRIANGLE_FAN: 6
}, bn = {
5120: Int8Array,
5121: Uint8Array,
5122: Int16Array,
5123: Uint16Array,
5125: Uint32Array,
5126: Float32Array
}, zi = {
9728: us,
9729: rt,
9984