@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,223 lines • 467 kB
JavaScript
import { Mesh as q, SphereGeometry as ai, Vector3 as P, MeshBasicMaterial as wt, TrianglesDrawMode as ca, TriangleFanDrawMode as Ns, TriangleStripDrawMode as wo, Loader as Mt, LoaderUtils as Xt, FileLoader as ft, MeshPhysicalMaterial as xt, Vector2 as ke, Color as xe, LinearSRGBColorSpace as We, SRGBColorSpace as ge, SpotLight as yo, PointLight as Ps, DirectionalLight as Qo, Matrix4 as ue, InstancedMesh as la, Quaternion as Se, InstancedBufferAttribute as ha, Object3D as yt, TextureLoader as Ai, ImageBitmapLoader as ua, BufferAttribute as tt, InterleavedBuffer as ga, LinearMipmapLinearFilter as Un, NearestMipmapLinearFilter as xo, LinearMipmapNearestFilter as So, NearestMipmapNearestFilter as ci, LinearFilter as it, NearestFilter as is, RepeatWrapping as en, MirroredRepeatWrapping as To, ClampToEdgeWrapping as os, PointsMaterial as Sn, Material as Mn, LineBasicMaterial as _t, MeshStandardMaterial as li, DoubleSide as hi, PropertyBinding as Ft, BufferGeometry as lt, SkinnedMesh as vo, LineSegments as rs, Line as gt, LineLoop as pa, Points as Zn, Group as Zt, PerspectiveCamera as As, MathUtils as ye, OrthographicCamera as Do, Skeleton as Ro, AnimationClip as _o, Bone as Os, InterpolateDiscrete as Mo, InterpolateLinear as ui, InterleavedBufferAttribute as Wt, Texture as Hs, VectorKeyframeTrack as js, NumberKeyframeTrack as qs, QuaternionKeyframeTrack as zs, ColorManagement as Je, FrontSide as Fo, Interpolant as fa, Box3 as cs, Sphere as gi, CompressedCubeTexture as da, CompressedArrayTexture as Ia, CompressedTexture as Fn, NoColorSpace as as, RGBA_BPTC_Format as Ys, RGBA_S3TC_DXT5_Format as Ks, RGBA_S3TC_DXT3_Format as Si, RGB_S3TC_DXT1_Format as Ti, RGBA_S3TC_DXT1_Format as Js, RGBA_ASTC_6x6_Format as vi, RGBA_ASTC_4x4_Format as $n, RGBA_ETC2_EAC_Format as ko, RGB_ETC2_Format as Lo, RGBFormat as Vs, RedFormat as cn, RGFormat as Tn, RGBAFormat as Ht, UnsignedByteType as ut, HalfFloatType as Ve, UnsignedInt101111Type as Go, UnsignedInt5999Type as Uo, FloatType as dt, DataTexture as ma, Data3DTexture as Ea, RGB_PVRTC_4BPPV1_Format as ba, RGB_ETC1_Format as Ca, RGBA_PVRTC_4BPPV1_Format as Ba, RGB_BPTC_UNSIGNED_Format as wa, NodeFrame as ya, ShaderLib as Ct, ExtrudeGeometry as Qa, ShapePath as xa, DataTextureLoader as No, DataUtils as ln, CylinderGeometry as ze, BoxGeometry as He, Float32BufferAttribute as Me, OctahedronGeometry as On, TorusGeometry as dn, Euler as Ot, Controls as Po, Raycaster as pi, PlaneGeometry as fi, MOUSE as un, TOUCH as hn, Spherical as Di, Ray as Sa, Plane as Ta, ShaderMaterial as Oo, Uniform$1 as va, Scene as Ws, WebGLRenderer as Da, CanvasTexture as Ho, REVISION as Ra, Source as _a, InstancedBufferGeometry as Ma, InstancedInterleavedBuffer as Xs, WireframeGeometry as Fa, UniformsUtils as jo, UniformsLib as es, Vector4 as kt, Line3 as ka, Matrix3 as qo, Curve as La, MeshPhongMaterial as kn, MeshLambertMaterial as Ga, EquirectangularReflectionMapping as Ua, AmbientLight as Na, Uint16BufferAttribute as Pa, ShapeUtils as Oa, DefaultLoadingManager as Ha } from "./three.js";
class $l 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 ai(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 wt({ map: e, depthWrite: !1 }));
}
}
function eh(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"], g = ["setX", "setY", "setZ", "setW"];
for (let w = 0, b = r.length; w < b; w++) {
const B = r[w], Q = A.attributes[B];
a[B] = new Q.constructor(
new Q.array.constructor(Q.count * Q.itemSize),
Q.itemSize,
Q.normalized
);
const D = A.morphAttributes[B];
D && (c[B] || (c[B] = []), D.forEach((R, x) => {
const T = new R.array.constructor(R.count * R.itemSize);
c[B][x] = new R.constructor(T, R.itemSize, R.normalized);
}));
}
const p = e * 0.5, d = Math.log10(1 / e), I = Math.pow(10, d), m = p * I;
for (let w = 0; w < i; w++) {
const b = s ? s.getX(w) : w;
let B = "";
for (let Q = 0, D = r.length; Q < D; Q++) {
const R = r[Q], x = A.getAttribute(R), T = x.itemSize;
for (let U = 0; U < T; U++)
B += `${~~(x[h[U]](b) * I + m)},`;
}
if (B in t)
l.push(t[B]);
else {
for (let Q = 0, D = r.length; Q < D; Q++) {
const R = r[Q], x = A.getAttribute(R), T = A.morphAttributes[R], U = x.itemSize, L = a[R], H = c[R];
for (let Z = 0; Z < U; Z++) {
const G = h[Z], K = g[Z];
if (L[K](o, x[G](b)), T)
for (let O = 0, $ = T.length; O < $; O++)
H[O][K](o, T[O][G](b));
}
}
t[B] = o, l.push(o), o++;
}
}
const C = A.clone();
for (const w in A.attributes) {
const b = a[w];
if (C.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 Q = c[w][B];
C.morphAttributes[w][B] = new Q.constructor(
Q.array.slice(0, o * Q.itemSize),
Q.itemSize,
Q.normalized
);
}
}
return C.setIndex(l), C;
}
function Ri(A, e) {
if (e === ca)
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), A;
if (e === Ns || e === wo) {
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 === Ns)
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 zo extends Mt {
constructor(e) {
super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) {
return new Ka(t);
}), this.register(function(t) {
return new Ja(t);
}), this.register(function(t) {
return new sA(t);
}), this.register(function(t) {
return new iA(t);
}), this.register(function(t) {
return new oA(t);
}), this.register(function(t) {
return new Wa(t);
}), this.register(function(t) {
return new Xa(t);
}), this.register(function(t) {
return new Za(t);
}), this.register(function(t) {
return new $a(t);
}), this.register(function(t) {
return new Ya(t);
}), this.register(function(t) {
return new eA(t);
}), this.register(function(t) {
return new Va(t);
}), this.register(function(t) {
return new nA(t);
}), this.register(function(t) {
return new tA(t);
}), this.register(function(t) {
return new qa(t);
}), this.register(function(t) {
return new rA(t);
}), this.register(function(t) {
return new aA(t);
});
}
load(e, t, s, n) {
const i = this;
let o;
if (this.resourcePath !== "")
o = this.resourcePath;
else if (this.path !== "") {
const c = Xt.extractUrlBase(e);
o = Xt.resolveURL(c, this.path);
} else
o = Xt.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 ft(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)) === Yo) {
try {
r[ae.KHR_BINARY_GLTF] = new AA(e);
} catch (g) {
n && n(g);
return;
}
try {
i = JSON.parse(r[ae.KHR_BINARY_GLTF].content);
} catch (g) {
o = r[ae.KHR_BINARY_GLTF].content, n && n(g);
return;
}
} else
try {
i = JSON.parse(c.decode(e));
} catch (g) {
o = c.decode(e), n && n(g);
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 CA(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 g = this.pluginCallbacks[h](l);
g.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[g.name] = g, r[g.name] = !0;
}
if (i.extensionsUsed)
for (let h = 0; h < i.extensionsUsed.length; ++h) {
const g = i.extensionsUsed[h], p = i.extensionsRequired || [];
switch (g) {
case ae.KHR_MATERIALS_UNLIT:
r[g] = new za();
break;
case ae.KHR_DRACO_MESH_COMPRESSION:
r[g] = new cA(i, this.dracoLoader);
break;
case ae.KHR_TEXTURE_TRANSFORM:
r[g] = new lA();
break;
case ae.KHR_MESH_QUANTIZATION:
r[g] = new hA();
break;
default:
p.indexOf(g) >= 0 && a[g] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + g + '".');
}
}
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 ja() {
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 qa {
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 xe(16777215);
a.color !== void 0 && l.setRGB(a.color[0], a.color[1], a.color[2], We);
const h = a.range !== void 0 ? a.range : 0;
switch (a.type) {
case "directional":
c = new Qo(l), c.target.position.set(0, 0, -1), c.add(c.target);
break;
case "point":
c = new Ps(l), c.distance = h;
break;
case "spot":
c = new yo(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, Rt(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 za = class {
constructor() {
this.name = ae.KHR_MATERIALS_UNLIT;
}
getMaterialType() {
return wt;
}
extendParams(e, t, s) {
const n = [];
e.color = new xe(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], We), e.opacity = o[3];
}
i.baseColorTexture !== void 0 && n.push(s.assignTexture(e, "map", i.baseColorTexture, ge));
}
return Promise.all(n);
}
}, Ya = 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();
}
}, Ka = 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 : xt;
}
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 ke(r, r);
}
return Promise.all(i);
}
}, Ja = 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 : xt;
}
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();
}
}, Va = 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 : xt;
}
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);
}
}, Wa = 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 : xt;
}
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 xe(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], We);
}
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);
}
}, Xa = 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 : xt;
}
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);
}
}, Za = 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 : xt;
}
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 xe().setRGB(r[0], r[1], r[2], We), Promise.all(i);
}
}, $a = 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 : xt;
}
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 : xt;
}
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 xe().setRGB(r[0], r[1], r[2], We), o.specularColorTexture !== void 0 && i.push(s.assignTexture(t, "specularColorMap", o.specularColorTexture, ge)), Promise.all(i);
}
}, tA = 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 : xt;
}
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);
}
}, nA = 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 : xt;
}
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 sA {
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 iA {
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 oA {
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 rA {
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, g = new Uint8Array(r, a, c);
return o.decodeGltfBufferAsync ? o.decodeGltfBufferAsync(l, h, g, n.mode, n.filter).then(function(p) {
return p.buffer;
}) : o.ready.then(function() {
const p = new ArrayBuffer(l * h);
return o.decodeGltfBuffer(new Uint8Array(p), l, h, g, n.mode, n.filter), p;
});
});
} else
return null;
}
}
let aA = 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 !== ct.TRIANGLES && c.mode !== ct.TRIANGLE_STRIP && c.mode !== ct.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], g = c[0].count, p = [];
for (const d of h) {
const I = new ue(), m = new P(), C = new Se(), w = new P(1, 1, 1), b = new la(d.geometry, d.material, g);
for (let B = 0; B < g; B++)
a.TRANSLATION && m.fromBufferAttribute(a.TRANSLATION, B), a.ROTATION && C.fromBufferAttribute(a.ROTATION, B), a.SCALE && w.fromBufferAttribute(a.SCALE, B), b.setMatrixAt(B, I.compose(m, C, w));
for (const B in a)
if (B === "_COLOR_0") {
const Q = a[B];
b.instanceColor = new ha(Q.array, Q.itemSize, Q.normalized);
} else B !== "TRANSLATION" && B !== "ROTATION" && B !== "SCALE" && d.geometry.setAttribute(B, a[B]);
yt.prototype.copy.call(b, d), this.parser.assignFinalMaterial(b), p.push(b);
}
return l.isGroup ? (l.clear(), l.add(...p), l) : p[0];
}));
}
};
const Yo = "glTF", In = 12, _i = { JSON: 1313821514, BIN: 5130562 };
class AA {
constructor(e) {
this.name = ae.KHR_BINARY_GLTF, this.content = null, this.body = null;
const t = new DataView(e, 0, In), 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 !== Yo)
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 - In, i = new DataView(e, In);
let o = 0;
for (; o < n; ) {
const r = i.getUint32(o, !0);
o += 4;
const a = i.getUint32(o, !0);
if (o += 4, a === _i.JSON) {
const c = new Uint8Array(e, In + o, r);
this.content = s.decode(c);
} else if (a === _i.BIN) {
const c = In + o;
this.body = e.slice(c, c + r);
}
o += r;
}
if (this.content === null)
throw new Error("THREE.GLTFLoader: JSON content not found.");
}
}
class cA {
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 = Zs[l] || l.toLowerCase();
r[h] = o[l];
}
for (const l in e.attributes) {
const h = Zs[l] || l.toLowerCase();
if (o[l] !== void 0) {
const g = s.accessors[e.attributes[l]], p = gn[g.componentType];
c[h] = p.name, a[h] = g.normalized === !0;
}
}
return t.getDependency("bufferView", i).then(function(l) {
return new Promise(function(h, g) {
n.decodeDracoFile(l, function(p) {
for (const d in p.attributes) {
const I = p.attributes[d], m = a[d];
m !== void 0 && (I.normalized = m);
}
h(p);
}, r, c, We, g);
});
});
}
}
class lA {
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 hA {
constructor() {
this.name = ae.KHR_MESH_QUANTIZATION;
}
}
class Ko extends fa {
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, g = h * h, p = g * h, d = e * c, I = d - c, m = -2 * p + 3 * g, C = p - g, w = 1 - m, b = C - g + h;
for (let B = 0; B !== r; B++) {
const Q = o[I + B + r], D = o[I + B + a] * l, R = o[d + B + r], x = o[d + B] * l;
i[B] = w * Q + b * D + m * R + C * x;
}
return i;
}
}
const uA = new Se();
class gA extends Ko {
interpolate_(e, t, s, n) {
const i = super.interpolate_(e, t, s, n);
return uA.fromArray(i).normalize().toArray(i), i;
}
}
const ct = {
POINTS: 0,
LINES: 1,
LINE_LOOP: 2,
LINE_STRIP: 3,
TRIANGLES: 4,
TRIANGLE_STRIP: 5,
TRIANGLE_FAN: 6
}, gn = {
5120: Int8Array,
5121: Uint8Array,
5122: Int16Array,
5123: Uint16Array,
5125: Uint32Array,
5126: Float32Array
}, Mi = {
9728: is,
9729: it,
9984: ci,
9985: So,
9986: xo,
9987: Un
}, Fi = {
33071: os,
33648: To,
10497: en
}, ps = {
SCALAR: 1,
VEC2: 2,
VEC3: 3,
VEC4: 4,
MAT2: 4,
MAT3: 9,
MAT4: 16
}, Zs = {
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"
}, Ut = {
scale: "scale",
translation: "position",
rotation: "quaternion",
weights: "morphTargetInfluences"
}, pA = {
CUBICSPLINE: void 0,
// We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
// keyframe track will be initialized with a default interpolation type, then modified.
LINEAR: ui,
STEP: Mo
}, fs = {
OPAQUE: "OPAQUE",
MASK: "MASK",
BLEND: "BLEND"
};
function fA(A) {
return A.DefaultMaterial === void 0 && (A.DefaultMaterial = new li({
color: 16777215,
emissive: 0,
metalness: 1,
roughness: 1,
transparent: !1,
depthTest: !0,
side: Fo
})), A.DefaultMaterial;
}
function Yt(A, e, t) {
for (const s in t.extensions)
A[s] === void 0 && (e.userData.gltfExtensions = e.userData.gltfExtensions || {}, e.userData.gltfExtensions[s] = t.extensions[s]);
}
function Rt(A, e) {
e.extras !== void 0 && (typeof e.extras == "object" ? Object.assign(A.userData, e.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + e.extras));
}
function dA(A, e, t) {
let s = !1, n = !1, i = !1;
for (let c = 0, l = e.length; c < l; c++) {
const h = e[c];
if (h.POSITION !== void 0 && (s = !0), h.NORMAL !== void 0 && (n = !0), h.COLOR_0 !== void 0 && (i = !0), s && n && i) break;
}
if (!s && !n && !i) return Promise.resolve(A);
const o = [], r = [], a = [];
for (let c = 0, l = e.length; c < l; c++) {
const h = e[c];
if (s) {
const g = h.POSITION !== void 0 ? t.getDependency("accessor", h.POSITION) : A.attributes.position;
o.push(g);
}
if (n) {
const g = h.NORMAL !== void 0 ? t.getDependency("accessor", h.NORMAL) : A.attributes.normal;
r.push(g);
}
if (i) {
const g = h.COLOR_0 !== void 0 ? t.getDependency("accessor", h.COLOR_0) : A.attributes.color;
a.push(g);
}
}
return Promise.all([
Promise.all(o),
Promise.all(r),
Promise.all(a)
]).then(function(c) {
const l = c[0], h = c[1], g = c[2];
return s && (A.morphAttributes.position = l), n && (A.morphAttributes.normal = h), i && (A.morphAttributes.color = g), A.morphTargetsRelative = !0, A;
});
}
function IA(A, e) {
if (A.updateMorphTargets(), e.weights !== void 0)
for (let t = 0, s = e.weights.length; t < s; t++)
A.morphTargetInfluences[t] = e.weights[t];
if (e.extras && Array.isArray(e.extras.targetNames)) {
const t = e.extras.targetNames;
if (A.morphTargetInfluences.length === t.length) {
A.morphTargetDictionary = {};
for (let s = 0, n = t.length; s < n; s++)
A.morphTargetDictionary[t[s]] = s;
} else
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
}
}
function mA(A) {
let e;
const t = A.extensions && A.extensions[ae.KHR_DRACO_MESH_COMPRESSION];
if (t ? e = "draco:" + t.bufferView + ":" + t.indices + ":" + ds(t.attributes) : e = A.indices + ":" + ds(A.attributes) + ":" + A.mode, A.targets !== void 0)
for (let s = 0, n = A.targets.length; s < n; s++)
e += ":" + ds(A.targets[s]);
return e;
}
function ds(A) {
let e = "";
const t = Object.keys(A).sort();
for (let s = 0, n = t.length; s < n; s++)
e += t[s] + ":" + A[t[s]] + ";";
return e;
}
function $s(A) {
switch (A) {
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.");
}
}
function EA(A) {
return A.search(/\.jpe?g($|\?)/i) > 0 || A.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : A.search(/\.webp($|\?)/i) > 0 || A.search(/^data\:image\/webp/) === 0 ? "image/webp" : "image/png";
}
const bA = new ue();
class CA {
constructor(e = {}, t = {}) {
this.json = e, this.extensions = {}, this.plugins = {}, this.options = t, this.cache = new ja(), this.associations = /* @__PURE__ */ 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 s = !1, n = -1, i = !1, o = -1;
if (typeof navigator < "u") {
const r = navigator.userAgent;
s = /^((?!chrome|android).)*safari/i.test(r) === !0;
const a = r.match(/Version\/(\d+)/);
n = s && a ? parseInt(a[1], 10) : -1, i = r.indexOf("Firefox") > -1, o = i ? r.match(/Firefox\/([0-9]+)\./)[1] : -1;
}
typeof createImageBitmap > "u" || s && n < 17 || i && o < 98 ? this.textureLoader = new Ai(this.options.manager) : this.textureLoader = new ua(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new ft(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0);
}
setExtensions(e) {
this.extensions = e;
}
setPlugins(e) {
this.plugins = e;
}
parse(e, t) {
const s = this, n = this.json, i = this.extensions;
this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(o) {
return o._markDefs && o._markDefs();
}), Promise.all(this._invokeAll(function(o) {
return o.beforeRoot && o.beforeRoot();
})).then(function() {
return Promise.all([
s.getDependencies("scene"),
s.getDependencies("animation"),
s.getDependencies("camera")
]);
}).then(function(o) {
const r = {
scene: o[0][n.scene || 0],
scenes: o[0],
animations: o[1],
cameras: o[2],
asset: n.asset,
parser: s,
userData: {}
};
return Yt(i, r, n), Rt(r, n), Promise.all(s._invokeAll(function(a) {
return a.afterRoot && a.afterRoot(r);
})).then(function() {
for (const a of r.scenes)
a.updateMatrixWorld();
e(r);
});
}).catch(t);
}
/**
* Marks the special nodes/meshes in json for efficient parse.
*/
_markDefs() {
const e = this.json.nodes || [], t = this.json.skins || [], s = this.json.meshes || [];
for (let n = 0, i = t.length; n < i; n++) {
const o = t[n].joints;
for (let r = 0, a = o.length; r < a; r++)
e[o[r]].isBone = !0;
}
for (let n = 0, i = e.length; n < i; n++) {
const o = e[n];
o.mesh !== void 0 && (this._addNodeRef(this.meshCache, o.mesh), o.skin !== void 0 && (s[o.mesh].isSkinnedMesh = !0)), o.camera !== void 0 && this._addNodeRef(this.cameraCache, o.camera);
}
}
/**
* Counts references to shared node / Object3D resources. These resources
* can be reused, or "instantiated", at multiple nodes in the scene
* hierarchy. Mesh, Camera, and Light instances are instantiated and must
* be marked. Non-scenegraph resources (like Materials, Geometries, and
* Textures) can be reused directly and are not marked here.
*
* Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
*/
_addNodeRef(e, t) {
t !== void 0 && (e.refs[t] === void 0 && (e.refs[t] = e.uses[t] = 0), e.refs[t]++);
}
/** Returns a reference to a shared resource, cloning it if necessary. */
_getNodeRef(e, t, s) {
if (e.refs[t] <= 1) return s;
const n = s.clone(), i = (o, r) => {
const a = this.associations.get(o);
a != null && this.associations.set(r, a);
for (const [c, l] of o.children.entries())
i(l, r.children[c]);
};
return i(s, n), n.name += "_instance_" + e.uses[t]++, n;
}
_invokeOne(e) {
const t = Object.values(this.plugins);
t.push(this);
for (let s = 0; s < t.length; s++) {
const n = e(t[s]);
if (n) return n;
}
return null;
}
_invokeAll(e) {
const t = Object.values(this.plugins);
t.unshift(this);
const s = [];
for (let n = 0; n < t.length; n++) {
const i = e(t[n]);
i && s.push(i);
}
return s;
}
/**
* Requests the specified dependency asynchronously, with caching.
* @param {string} type
* @param {number} index
* @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
*/
getDependency(e, t) {
const s = e + ":" + t;
let n = this.cache.get(s);
if (!n) {
switch (e) {
case "scene":
n = this.loadScene(t);
break;
case "node":
n = this._invokeOne(function(i) {
return i.loadNode && i.loadNode(t);
});
break;
case "mesh":
n = this._invokeOne(function(i) {
return i.loadMesh && i.loadMesh(t);
});
break;
case "accessor":
n = this.loadAccessor(t);
break;
case "bufferView":
n = this._invokeOne(function(i) {
return i.loadBufferView && i.loadBufferView(t);
});
break;
case "buffer":
n = this.loadBuffer(t);
break;
case "material":
n = this._invokeOne(function(i) {
return i.loadMaterial && i.loadMaterial(t);
});
break;
case "texture":
n = this._invokeOne(function(i) {
return i.loadTexture && i.loadTexture(t);
});
break;
case "skin":
n = this.loadSkin(t);
break;
case "animation":
n = this._invokeOne(function(i) {
return i.loadAnimation && i.loadAnimation(t);
});
break;
case "camera":
n = this.loadCamera(t);
break;
default:
if (n = this._invokeOne(function(i) {
return i != this && i.getDependency && i.getDependency(e, t);
}), !n)
throw new Error("Unknown type: " + e);
break;
}
this.cache.add(s, n);
}
return n;
}
/**
* Requests all dependencies of the specified type asynchronously, with caching.
* @param {string} type
* @return {Promise<Array<Object>>}
*/
getDependencies(e) {
let t = this.cache.get(e);
if (!t) {
const s = this, n = this.json[e + (e === "mesh" ? "es" : "s")] || [];
t = Promise.all(n.map(function(i, o) {
return s.getDependency(e, o);
})), this.cache.add(e, t);
}
return t;
}
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
* @param {number} bufferIndex
* @return {Promise<ArrayBuffer>}
*/
loadBuffer(e) {
const t = this.json.buffers[e], s = this.fileLoader;
if (t.type && t.type !== "arraybuffer")
throw new Error("THREE.GLTFLoader: " + t.type + " buffer type is not supported.");
if (t.uri === void 0 && e === 0)
return Promise.resolve(this.extensions[ae.KHR_BINARY_GLTF].body);
const n = this.options;
return new Promise(function(i, o) {
s.load(Xt.resolveURL(t.uri, n.path), i, void 0, function() {
o(new Error('THREE.GLTFLoader: Failed to load buffer "' + t.uri + '".'));
});
});
}
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
* @param {number} bufferViewIndex
* @return {Promise<ArrayBuffer>}
*/
loadBufferView(e) {
const t = this.json.bufferViews[e];
return this.getDependency("buffer", t.buffer).then(function(s) {
const n = t.byteLength || 0, i = t.byteOffset || 0;
return s.slice(i, i + n);
});
}
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
* @param {number} accessorIndex
* @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
*/
loadAccessor(e) {
const t = this, s = this.json, n = this.json.accessors[e];
if (n.bufferView === void 0 && n.sparse === void 0) {
const o = ps[n.type], r = gn[n.componentType], a = n.normalized === !0, c = new r(n.count * o);
return Promise.resolve(new tt(c, o, a));
}
const i = [];
return n.bufferView !== void 0 ? i.push(this.getDependency("bufferView", n.bufferView)) : i.push(null), n.sparse !== void 0 && (i.push(this.getDependency("bufferView", n.sparse.indices.bufferView)), i.push(this.getDependency("bufferView", n.sparse.values.bufferView))), Promise.all(i).then(function(o) {
const r = o[0], a = ps[n.type], c = gn[n.componentType], l = c.BYTES_PER_ELEMENT, h = l * a, g = n.byteOffset || 0, p = n.bufferView !== void 0 ? s.bufferViews[n.bufferView].byteStride : void 0, d = n.normalized === !0;
let I, m;
if (p && p !== h) {
const C = Math.floor(g / p), w = "InterleavedBuffer:" + n.bufferView + ":" + n.componentType + ":" + C + ":" + n.count;
let b = t.cache.get(w);
b || (I = new c(r, C * p, n.count * p / l), b = new ga(I, p / l), t.cache.add(w, b)), m = new Wt(b, a, g % p / l, d);
} else
r === null ? I = new c(n.count * a) : I = new c(r, g, n.count * a), m = new tt(I, a, d);
if (n.sparse !== void 0) {
const C = ps.SCALAR, w = gn[n.sparse.indices.componentType], b = n.sparse.indices.byteOffset || 0, B = n.sparse.values.byteOffset || 0, Q = new w(o[1], b, n.sparse.count * C), D = new c(o[2], B, n.sparse.count * a);
r !== null && (m = new tt(m.array.slice(), m.itemSize, m.normalized)), m.normalized = !1;
for (let R = 0, x = Q.length; R < x; R++) {
const T = Q[R];
if (m.setX(T, D[R * a]), a >= 2 && m.setY(T, D[R * a + 1]), a >= 3 && m.setZ(T, D[R * a + 2]), a >= 4 && m.setW(T, D[R * a + 3]), a >= 5) throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
}
m.normalized = d;
}
return m;
});
}
/**
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
* @param {number} textureIndex
* @return {Promise<THREE.Texture|null>}
*/
loadTexture(e) {
const t = this.json, s = this.options, i = t.textures[e].source, o = t.images[i];
let r = this.textureLoader;
if (o.uri) {
const a = s.manager.getHandler(o.uri);
a !== null && (r = a);
}
return this.loadTextureImage(e, i, r);
}
loadTextureImage(e, t, s) {
const n = this, i = this.json, o = i.textures[e], r = i.images[t], a = (r.uri || r.bufferView) + ":" + o.sampler;
if (this.textureCache[a])
return this.textureCache[a];
const c = this.loadImageSource(t, s).then(function(l) {
l.flipY = !1, l.name = o.name || r.name || "", l.name === "" && typeof r.uri == "string" && r.uri.startsWith("data:image/") === !1 && (l.name = r.uri);
const g = (i.samplers || {})[o.sampler] || {};
return l.magFilter = Mi[g.magFilter] || it, l.minFilter = Mi[g.minFilter] || Un, l.wrapS = Fi[g.wrapS] || en, l.wrapT = Fi[g.wrapT] || en, l.anisotropy = 4, n.associations.set(l, { textures: e }), l;
}).catch(function() {
return null;
});
return this.textureCache[a] = c, c;
}
loadImageSource(e, t) {
const s = this, n = this.json, i = this.options;
if (this.sourceCache[e] !== void 0)
return this.sourceCache[e].then((h) => h.clone());
const o = n.images[e], r = self.URL || s