three-stdlib 2.8.3 → 2.8.7
Sign up to get free protection for your applications and to get access to all the features.
- package/controls/PointerLockControls.cjs.js +1 -1
- package/controls/PointerLockControls.d.ts +3 -3
- package/controls/PointerLockControls.js +12 -10
- package/index.cjs.js +1 -1
- package/index.d.ts +9 -4
- package/index.js +9 -4
- package/libs/MotionControllers.cjs.js +1 -0
- package/libs/MotionControllers.js +403 -0
- package/loaders/GLTFLoader.cjs.js +1 -1
- package/loaders/GLTFLoader.js +0 -1
- package/modifiers/CurveModifier.cjs.js +1 -1
- package/modifiers/CurveModifier.js +1 -1
- package/package.json +2 -3
- package/webxr/OculusHandModel.cjs.js +1 -0
- package/webxr/OculusHandModel.d.ts +19 -0
- package/webxr/OculusHandModel.js +72 -0
- package/webxr/OculusHandPointerModel.cjs.js +1 -0
- package/webxr/OculusHandPointerModel.d.ts +63 -0
- package/webxr/OculusHandPointerModel.js +248 -0
- package/webxr/Text2D.cjs.js +1 -0
- package/webxr/Text2D.d.ts +3 -0
- package/webxr/Text2D.js +32 -0
- package/webxr/VRButton.cjs.js +1 -1
- package/webxr/VRButton.js +17 -1
- package/webxr/XRControllerModelFactory.cjs.js +1 -1
- package/webxr/XRControllerModelFactory.js +65 -66
- package/webxr/XREstimatedLight.cjs.js +1 -1
- package/webxr/XREstimatedLight.js +1 -0
- package/webxr/XRHandMeshModel.cjs.js +1 -0
- package/webxr/XRHandMeshModel.d.ts +11 -0
- package/webxr/XRHandMeshModel.js +55 -0
- package/webxr/XRHandModelFactory.cjs.js +1 -1
- package/webxr/XRHandModelFactory.js +47 -50
- package/webxr/XRHandPrimitiveModel.cjs.js +1 -1
- package/webxr/XRHandPrimitiveModel.js +31 -41
- package/webxr/XRHandOculusMeshModel.cjs.js +0 -1
- package/webxr/XRHandOculusMeshModel.js +0 -89
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new i(e)})),this.register((function(e){return new p(e)})),this.register((function(e){return new d(e)})),this.register((function(e){return new a(e)})),this.register((function(e){return new l(e)})),this.register((function(e){return new c(e)})),this.register((function(e){return new u(e)})),this.register((function(e){return new h(e)})),this.register((function(e){return new r(e)})),this.register((function(e){return new m(e)}))}load(t,s,n,r){const o=this;let i;i=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:e.LoaderUtils.extractUrlBase(t),this.manager.itemStart(t);const a=function(e){r?r(e):console.error(e),o.manager.itemError(t),o.manager.itemEnd(t)},l=new e.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(t,(function(e){try{o.parse(e,i,(function(e){s(e),o.manager.itemEnd(t)}),a)}catch(e){a(e)}}),n,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(t,s,r,i){let a;const l={},c={};if("string"==typeof t)a=t;else{if(e.LoaderUtils.decodeText(new Uint8Array(t,0,4))===f){try{l[n.KHR_BINARY_GLTF]=new x(t)}catch(e){return void(i&&i(e))}a=l[n.KHR_BINARY_GLTF].content}else a=e.LoaderUtils.decodeText(new Uint8Array(t))}const u=JSON.parse(a);if(void 0===u.asset||u.asset.version[0]<2)return void(i&&i(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const h=new Y(u,{path:s||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});h.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](h);c[t.name]=t,l[t.name]=!0}if(u.extensionsUsed)for(let e=0;e<u.extensionsUsed.length;++e){const t=u.extensionsUsed[e],s=u.extensionsRequired||[];switch(t){case n.KHR_MATERIALS_UNLIT:l[t]=new o;break;case n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:l[t]=new S;break;case n.KHR_DRACO_MESH_COMPRESSION:l[t]=new M(u,this.dracoLoader);break;case n.KHR_TEXTURE_TRANSFORM:l[t]=new R;break;case n.KHR_MESH_QUANTIZATION:l[t]=new _;break;default:s.indexOf(t)>=0&&void 0===c[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}h.setExtensions(l),h.setPlugins(c),h.parse(r,i)}parseAsync(e,t){const s=this;return new Promise((function(n,r){s.parse(e,t,n,r)}))}}function s(){let e={};return{get:function(t){return e[t]},add:function(t,s){e[t]=s},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const n={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_IOR:"KHR_materials_ior",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",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",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression"};class r{constructor(e){this.parser=e,this.name=n.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 n=t[s];n.extensions&&n.extensions[this.name]&&void 0!==n.extensions[this.name].light&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(t){const s=this.parser,n="light:"+t;let r=s.cache.get(n);if(r)return r;const o=s.json,i=((o.extensions&&o.extensions[this.name]||{}).lights||[])[t];let a;const l=new e.Color(16777215);void 0!==i.color&&l.fromArray(i.color);const c=void 0!==i.range?i.range:0;switch(i.type){case"directional":a=new e.DirectionalLight(l),a.target.position.set(0,0,-1),a.add(a.target);break;case"point":a=new e.PointLight(l),a.distance=c;break;case"spot":a=new e.SpotLight(l),a.distance=c,i.spot=i.spot||{},i.spot.innerConeAngle=void 0!==i.spot.innerConeAngle?i.spot.innerConeAngle:0,i.spot.outerConeAngle=void 0!==i.spot.outerConeAngle?i.spot.outerConeAngle:Math.PI/4,a.angle=i.spot.outerConeAngle,a.penumbra=1-i.spot.innerConeAngle/i.spot.outerConeAngle,a.target.position.set(0,0,-1),a.add(a.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+i.type)}return a.position.set(0,0,0),a.decay=2,void 0!==i.intensity&&(a.intensity=i.intensity),a.name=s.createUniqueName(i.name||"light_"+t),r=Promise.resolve(a),s.cache.add(n,r),r}createNodeAttachment(e){const t=this,s=this.parser,n=s.json.nodes[e],r=(n.extensions&&n.extensions[this.name]||{}).light;return void 0===r?null:this._loadLight(r).then((function(e){return s._getNodeRef(t.cache,r,e)}))}}class o{constructor(){this.name=n.KHR_MATERIALS_UNLIT}getMaterialType(){return e.MeshBasicMaterial}extendParams(t,s,n){const r=[];t.color=new e.Color(1,1,1),t.opacity=1;const o=s.pbrMetallicRoughness;if(o){if(Array.isArray(o.baseColorFactor)){const e=o.baseColorFactor;t.color.fromArray(e),t.opacity=e[3]}void 0!==o.baseColorTexture&&r.push(n.assignTexture(t,"map",o.baseColorTexture))}return Promise.all(r)}}class i{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];if(void 0!==i.clearcoatFactor&&(s.clearcoat=i.clearcoatFactor),void 0!==i.clearcoatTexture&&o.push(n.assignTexture(s,"clearcoatMap",i.clearcoatTexture)),void 0!==i.clearcoatRoughnessFactor&&(s.clearcoatRoughness=i.clearcoatRoughnessFactor),void 0!==i.clearcoatRoughnessTexture&&o.push(n.assignTexture(s,"clearcoatRoughnessMap",i.clearcoatRoughnessTexture)),void 0!==i.clearcoatNormalTexture&&(o.push(n.assignTexture(s,"clearcoatNormalMap",i.clearcoatNormalTexture)),void 0!==i.clearcoatNormalTexture.scale)){const t=i.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new e.Vector2(t,t)}return Promise.all(o)}}class a{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SHEEN}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[];s.sheenColor=new e.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const i=r.extensions[this.name];return void 0!==i.sheenColorFactor&&s.sheenColor.fromArray(i.sheenColorFactor),void 0!==i.sheenRoughnessFactor&&(s.sheenRoughness=i.sheenRoughnessFactor),void 0!==i.sheenColorTexture&&o.push(n.assignTexture(s,"sheenColorMap",i.sheenColorTexture)),void 0!==i.sheenRoughnessTexture&&o.push(n.assignTexture(s,"sheenRoughnessMap",i.sheenRoughnessTexture)),Promise.all(o)}}class l{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&r.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(r)}}class c{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_VOLUME}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];s.thickness=void 0!==i.thicknessFactor?i.thicknessFactor:0,void 0!==i.thicknessTexture&&o.push(n.assignTexture(s,"thicknessMap",i.thicknessTexture)),s.attenuationDistance=i.attenuationDistance||0;const a=i.attenuationColor||[1,1,1];return s.attenuationColor=new e.Color(a[0],a[1],a[2]),Promise.all(o)}}class u{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_IOR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name];return t.ior=void 0!==n.ior?n.ior:1.5,Promise.resolve()}}class h{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SPECULAR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];s.specularIntensity=void 0!==i.specularFactor?i.specularFactor:1,void 0!==i.specularTexture&&o.push(n.assignTexture(s,"specularIntensityMap",i.specularTexture));const a=i.specularColorFactor||[1,1,1];return s.specularColor=new e.Color(a[0],a[1],a[2]),void 0!==i.specularColorTexture&&o.push(n.assignTexture(s,"specularColorMap",i.specularColorTexture).then((function(t){t.encoding=e.sRGBEncoding}))),Promise.all(o)}}class p{constructor(e){this.parser=e,this.name=n.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 r=n.extensions[this.name],o=s.images[r.source],i=t.options.ktx2Loader;if(!i){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,o,i)}}class d{constructor(e){this.parser=e,this.name=n.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,r=n.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],i=n.images[o.source];let a=s.textureLoader;if(i.uri){const e=s.options.manager.getHandler(i.uri);null!==e&&(a=e)}return this.detectSupport().then((function(r){if(r)return s.loadTextureImage(e,i,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(1===t.height)}}))),this.isSupported}}class m{constructor(e){this.name=n.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 e=s.extensions[this.name],n=this.parser.getDependency("buffer",e.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.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 Promise.all([n,r.ready]).then((function(t){const s=e.byteOffset||0,n=e.byteLength||0,o=e.count,i=e.byteStride,a=new ArrayBuffer(o*i),l=new Uint8Array(t[0],s,n);return r.decodeGltfBuffer(new Uint8Array(a),o,i,l,e.mode,e.filter),a}))}return null}}const f="glTF",g=1313821514,T=5130562;class x{constructor(t){this.name=n.KHR_BINARY_GLTF,this.content=null,this.body=null;const s=new DataView(t,0,12);if(this.header={magic:e.LoaderUtils.decodeText(new Uint8Array(t.slice(0,4))),version:s.getUint32(4,!0),length:s.getUint32(8,!0)},this.header.magic!==f)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-12,o=new DataView(t,12);let i=0;for(;i<r;){const s=o.getUint32(i,!0);i+=4;const n=o.getUint32(i,!0);if(i+=4,n===g){const n=new Uint8Array(t,12+i,s);this.content=e.LoaderUtils.decodeText(n)}else if(n===T){const e=12+i;this.body=t.slice(e,e+s)}i+=s}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class M{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=n.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,i={},a={},l={};for(const e in o){const t=k[e]||e.toLowerCase();i[t]=o[e]}for(const t in e.attributes){const n=k[t]||t.toLowerCase();if(void 0!==o[t]){const r=s.accessors[e.attributes[t]],o=N[r.componentType];l[n]=o,a[n]=!0===r.normalized}}return t.getDependency("bufferView",r).then((function(e){return new Promise((function(t){n.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],n=a[t];void 0!==n&&(s.normalized=n)}t(e)}),i,l)}))}))}}class R{constructor(){this.name=n.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),void 0===t.offset&&void 0===t.rotation&&void 0===t.scale||(e=e.clone(),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class v extends e.MeshStandardMaterial{constructor(t){super(),this.isGLTFSpecularGlossinessMaterial=!0;const s=["#ifdef USE_SPECULARMAP","\tuniform sampler2D specularMap;","#endif"].join("\n"),n=["#ifdef USE_GLOSSINESSMAP","\tuniform sampler2D glossinessMap;","#endif"].join("\n"),r=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP","\tvec4 texelSpecular = texture2D( specularMap, vUv );","\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture","\tspecularFactor *= texelSpecular.rgb;","#endif"].join("\n"),o=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP","\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );","\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture","\tglossinessFactor *= texelGlossiness.a;","#endif"].join("\n"),i=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.specularColor = specularFactor;"].join("\n"),a={specular:{value:(new e.Color).setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=a,this.onBeforeCompile=function(e){for(const t in a)e.uniforms[t]=a[t];e.fragmentShader=e.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",s).replace("#include <metalnessmap_pars_fragment>",n).replace("#include <roughnessmap_fragment>",r).replace("#include <metalnessmap_fragment>",o).replace("#include <lights_physical_fragment>",i)},Object.defineProperties(this,{specular:{get:function(){return a.specular.value},set:function(e){a.specular.value=e}},specularMap:{get:function(){return a.specularMap.value},set:function(e){a.specularMap.value=e,e?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return a.glossiness.value},set:function(e){a.glossiness.value=e}},glossinessMap:{get:function(){return a.glossinessMap.value},set:function(e){a.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(t)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class S{constructor(){this.name=n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity","refractionRatio"]}getMaterialType(){return v}extendParams(t,s,n){const r=s.extensions[this.name];t.color=new e.Color(1,1,1),t.opacity=1;const o=[];if(Array.isArray(r.diffuseFactor)){const e=r.diffuseFactor;t.color.fromArray(e),t.opacity=e[3]}if(void 0!==r.diffuseTexture&&o.push(n.assignTexture(t,"map",r.diffuseTexture)),t.emissive=new e.Color(0,0,0),t.glossiness=void 0!==r.glossinessFactor?r.glossinessFactor:1,t.specular=new e.Color(1,1,1),Array.isArray(r.specularFactor)&&t.specular.fromArray(r.specularFactor),void 0!==r.specularGlossinessTexture){const e=r.specularGlossinessTexture;o.push(n.assignTexture(t,"glossinessMap",e)),o.push(n.assignTexture(t,"specularMap",e))}return Promise.all(o)}createMaterial(t){const s=new v(t);return s.fog=!0,s.color=t.color,s.map=void 0===t.map?null:t.map,s.lightMap=null,s.lightMapIntensity=1,s.aoMap=void 0===t.aoMap?null:t.aoMap,s.aoMapIntensity=1,s.emissive=t.emissive,s.emissiveIntensity=1,s.emissiveMap=void 0===t.emissiveMap?null:t.emissiveMap,s.bumpMap=void 0===t.bumpMap?null:t.bumpMap,s.bumpScale=1,s.normalMap=void 0===t.normalMap?null:t.normalMap,s.normalMapType=e.TangentSpaceNormalMap,t.normalScale&&(s.normalScale=t.normalScale),s.displacementMap=null,s.displacementScale=1,s.displacementBias=0,s.specularMap=void 0===t.specularMap?null:t.specularMap,s.specular=t.specular,s.glossinessMap=void 0===t.glossinessMap?null:t.glossinessMap,s.glossiness=t.glossiness,s.alphaMap=null,s.envMap=void 0===t.envMap?null:t.envMap,s.envMapIntensity=1,s.refractionRatio=.98,s}}class _{constructor(){this.name=n.KHR_MESH_QUANTIZATION}}class y extends e.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=e*n*3+n;for(let e=0;e!==n;e++)t[e]=s[r+e];return t}}y.prototype.beforeStart_=y.prototype.copySampleValue_,y.prototype.afterEnd_=y.prototype.copySampleValue_,y.prototype.interpolate_=function(e,t,s,n){const r=this.resultBuffer,o=this.sampleValues,i=this.valueSize,a=2*i,l=3*i,c=n-t,u=(s-t)/c,h=u*u,p=h*u,d=e*l,m=d-l,f=-2*p+3*h,g=p-h,T=1-f,x=g-h+u;for(let e=0;e!==i;e++){const t=o[m+e+i],s=o[m+e+a]*c,n=o[d+e+i],l=o[d+e]*c;r[e]=T*t+x*s+f*n+g*l}return r};const A=new e.Quaternion;class E extends y{interpolate_(e,t,s,n){const r=super.interpolate_(e,t,s,n);return A.fromArray(r).normalize().toArray(r),r}}const L=0,w=1,b=2,P=3,I=4,C=5,O=6,N={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},F={9728:e.NearestFilter,9729:e.LinearFilter,9984:e.NearestMipmapNearestFilter,9985:e.LinearMipmapNearestFilter,9986:e.NearestMipmapLinearFilter,9987:e.LinearMipmapLinearFilter},H={33071:e.ClampToEdgeWrapping,33648:e.MirroredRepeatWrapping,10497:e.RepeatWrapping},U={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},k={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},D={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},G={CUBICSPLINE:void 0,LINEAR:e.InterpolateLinear,STEP:e.InterpolateDiscrete},B="OPAQUE",K="MASK",j="BLEND";function V(e,t,s){for(const n in s.extensions)void 0===e[n]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[n]=s.extensions[n])}function X(e,t){void 0!==t.extras&&("object"==typeof t.extras?Object.assign(e.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function q(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,n=t.weights.length;s<n;s++)e.morphTargetInfluences[s]=t.weights[s];if(t.extras&&Array.isArray(t.extras.targetNames)){const s=t.extras.targetNames;if(e.morphTargetInfluences.length===s.length){e.morphTargetDictionary={};for(let t=0,n=s.length;t<n;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function z(e){const t=e.extensions&&e.extensions[n.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+W(t.attributes):e.indices+":"+W(e.attributes)+":"+e.mode,s}function W(e){let t="";const s=Object.keys(e).sort();for(let n=0,r=s.length;n<r;n++)t+=s[n]+":"+e[s[n]]+";";return t}function Q(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 Y{constructor(t={},n={}){this.json=t,this.extensions={},this.plugins={},this.options=n,this.cache=new s,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.textureCache={},this.nodeNamesUsed={},"undefined"!=typeof createImageBitmap&&!1===/Firefox|^((?!chrome|android).)*safari/i.test(navigator.userAgent)?this.textureLoader=new e.ImageBitmapLoader(this.options.manager):this.textureLoader=new e.TextureLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new e.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,n=this.json,r=this.extensions;this.cache.removeAll(),this._invokeAll((function(e){return e._markDefs&&e._markDefs()})),Promise.all(this._invokeAll((function(e){return e.beforeRoot&&e.beforeRoot()}))).then((function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])})).then((function(t){const o={scene:t[0][n.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:n.asset,parser:s,userData:{}};V(r,o,n),X(o,n),Promise.all(s._invokeAll((function(e){return e.afterRoot&&e.afterRoot(o)}))).then((function(){e(o)}))})).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s].joints;for(let t=0,s=n.length;t<s;t++)e[n[t]].isBone=!0}for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0!==n.mesh&&(this._addNodeRef(this.meshCache,n.mesh),void 0!==n.skin&&(s[n.mesh].isSkinnedMesh=!0)),void 0!==n.camera&&this._addNodeRef(this.cameraCache,n.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const n=s.clone(),r=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,n]of e.children.entries())r(n,t.children[s])};return r(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 r=e(t[n]);r&&s.push(r)}return s}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.loadNode(t);break;case"mesh":n=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":n=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":n=this.loadSkin(t);break;case"animation":n=this.loadAnimation(t);break;case"camera":n=this.loadCamera(t);break;default:throw new Error("Unknown type: "+e)}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(n.map((function(t,n){return s.getDependency(e,n)}))),this.cache.add(e,t)}return t}loadBuffer(t){const s=this.json.buffers[t],r=this.fileLoader;if(s.type&&"arraybuffer"!==s.type)throw new Error("THREE.GLTFLoader: "+s.type+" buffer type is not supported.");if(void 0===s.uri&&0===t)return Promise.resolve(this.extensions[n.KHR_BINARY_GLTF].body);const o=this.options;return new Promise((function(t,n){r.load(e.LoaderUtils.resolveURL(s.uri,o.path),t,void 0,(function(){n(new Error('THREE.GLTFLoader: Failed to load buffer "'+s.uri+'".'))}))}))}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then((function(e){const s=t.byteLength||0,n=t.byteOffset||0;return e.slice(n,n+s)}))}loadAccessor(t){const s=this,n=this.json,r=this.json.accessors[t];if(void 0===r.bufferView&&void 0===r.sparse)return Promise.resolve(null);const o=[];return void 0!==r.bufferView?o.push(this.getDependency("bufferView",r.bufferView)):o.push(null),void 0!==r.sparse&&(o.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),o.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(o).then((function(t){const o=t[0],i=U[r.type],a=N[r.componentType],l=a.BYTES_PER_ELEMENT,c=l*i,u=r.byteOffset||0,h=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,p=!0===r.normalized;let d,m;if(h&&h!==c){const t=Math.floor(u/h),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+t+":"+r.count;let c=s.cache.get(n);c||(d=new a(o,t*h,r.count*h/l),c=new e.InterleavedBuffer(d,h/l),s.cache.add(n,c)),m=new e.InterleavedBufferAttribute(c,i,u%h/l,p)}else d=null===o?new a(r.count*i):new a(o,u,r.count*i),m=new e.BufferAttribute(d,i,p);if(void 0!==r.sparse){const s=U.SCALAR,n=N[r.sparse.indices.componentType],l=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,u=new n(t[1],l,r.sparse.count*s),h=new a(t[2],c,r.sparse.count*i);null!==o&&(m=new e.BufferAttribute(m.array.slice(),m.itemSize,m.normalized));for(let e=0,t=u.length;e<t;e++){const t=u[e];if(m.setX(t,h[e*i]),i>=2&&m.setY(t,h[e*i+1]),i>=3&&m.setZ(t,h[e*i+2]),i>=4&&m.setW(t,h[e*i+3]),i>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return m}))}loadTexture(e){const t=this.json,s=this.options,n=t.textures[e],r=t.images[n.source];let o=this.textureLoader;if(r.uri){const e=s.manager.getHandler(r.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(t,s,n){const r=this,o=this.json,i=this.options,a=o.textures[t],l=(s.uri||s.bufferView)+":"+a.sampler;if(this.textureCache[l])return this.textureCache[l];const c=self.URL||self.webkitURL;let u=s.uri||"",h=!1;if(void 0!==s.bufferView)u=r.getDependency("bufferView",s.bufferView).then((function(e){h=!0;const t=new Blob([e],{type:s.mimeType});return u=c.createObjectURL(t),u}));else if(void 0===s.uri)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");const p=Promise.resolve(u).then((function(t){return new Promise((function(s,r){let o=s;!0===n.isImageBitmapLoader&&(o=function(t){const n=new e.Texture(t);n.needsUpdate=!0,s(n)}),n.load(e.LoaderUtils.resolveURL(t,i.path),o,void 0,r)}))})).then((function(s){!0===h&&c.revokeObjectURL(u),s.flipY=!1,a.name&&(s.name=a.name);const n=(o.samplers||{})[a.sampler]||{};return s.magFilter=F[n.magFilter]||e.LinearFilter,s.minFilter=F[n.minFilter]||e.LinearMipmapLinearFilter,s.wrapS=H[n.wrapS]||e.RepeatWrapping,s.wrapT=H[n.wrapT]||e.RepeatWrapping,r.associations.set(s,{textures:t}),s})).catch((function(){return console.error("THREE.GLTFLoader: Couldn't load texture",u),null}));return this.textureCache[l]=p,p}assignTexture(e,t,s){const r=this;return this.getDependency("texture",s.index).then((function(o){if(void 0===s.texCoord||0==s.texCoord||"aoMap"===t&&1==s.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+s.texCoord+" for texture "+t+" not yet supported."),r.extensions[n.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[n.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=r.associations.get(o);o=r.extensions[n.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),r.associations.set(o,t)}}return e[t]=o,o}))}assignFinalMaterial(t){const s=t.geometry;let n=t.material;const r=void 0===s.attributes.tangent,o=void 0!==s.attributes.color,i=void 0===s.attributes.normal;if(t.isPoints){const t="PointsMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.PointsMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),s.map=n.map,s.sizeAttenuation=!1,this.cache.add(t,s)),n=s}else if(t.isLine){const t="LineBasicMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.LineBasicMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),this.cache.add(t,s)),n=s}if(r||o||i){let e="ClonedMaterial:"+n.uuid+":";n.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),r&&(e+="derivative-tangents:"),o&&(e+="vertex-colors:"),i&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),o&&(t.vertexColors=!0),i&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}n.aoMap&&void 0===s.attributes.uv2&&void 0!==s.attributes.uv&&s.setAttribute("uv2",s.attributes.uv),t.material=n}getMaterialType(){return e.MeshStandardMaterial}loadMaterial(t){const s=this,r=this.json,o=this.extensions,i=r.materials[t];let a;const l={},c=i.extensions||{},u=[];if(c[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];a=e.getMaterialType(),u.push(e.extendParams(l,i,s))}else if(c[n.KHR_MATERIALS_UNLIT]){const e=o[n.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),u.push(e.extendParams(l,i,s))}else{const n=i.pbrMetallicRoughness||{};if(l.color=new e.Color(1,1,1),l.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;l.color.fromArray(e),l.opacity=e[3]}void 0!==n.baseColorTexture&&u.push(s.assignTexture(l,"map",n.baseColorTexture)),l.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,l.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(u.push(s.assignTexture(l,"metalnessMap",n.metallicRoughnessTexture)),u.push(s.assignTexture(l,"roughnessMap",n.metallicRoughnessTexture))),a=this._invokeOne((function(e){return e.getMaterialType&&e.getMaterialType(t)})),u.push(Promise.all(this._invokeAll((function(e){return e.extendMaterialParams&&e.extendMaterialParams(t,l)}))))}!0===i.doubleSided&&(l.side=e.DoubleSide);const h=i.alphaMode||B;if(h===j?(l.transparent=!0,l.depthWrite=!1):(l.transparent=!1,l.alphaWrite=!1,h===K&&(l.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&a!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"normalMap",i.normalTexture)),l.normalScale=new e.Vector2(1,1),void 0!==i.normalTexture.scale)){const e=i.normalTexture.scale;l.normalScale.set(e,e)}return void 0!==i.occlusionTexture&&a!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(l.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&a!==e.MeshBasicMaterial&&(l.emissive=(new e.Color).fromArray(i.emissiveFactor)),void 0!==i.emissiveTexture&&a!==e.MeshBasicMaterial&&u.push(s.assignTexture(l,"emissiveMap",i.emissiveTexture)),Promise.all(u).then((function(){let r;return r=a===v?o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(l):new a(l),i.name&&(r.name=i.name),r.map&&(r.map.encoding=e.sRGBEncoding),r.emissiveMap&&(r.emissiveMap.encoding=e.sRGBEncoding),X(r,i),s.associations.set(r,{materials:t}),i.extensions&&V(o,r,i),r}))}createUniqueName(t){const s=e.PropertyBinding.sanitizeNodeName(t||"");let n=s;for(let e=1;this.nodeNamesUsed[n];++e)n=s+"_"+e;return this.nodeNamesUsed[n]=!0,n}loadGeometries(t){const s=this,r=this.extensions,o=this.primitiveCache;function i(e){return r[n.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return Z(t,e,s)}))}const a=[];for(let r=0,l=t.length;r<l;r++){const l=t[r],c=z(l),u=o[c];if(u)a.push(u.promise);else{let t;t=l.extensions&&l.extensions[n.KHR_DRACO_MESH_COMPRESSION]?i(l):Z(new e.BufferGeometry,l,s),o[c]={primitive:l,promise:t},a.push(t)}}return Promise.all(a)}loadMesh(t){const s=this,n=this.json,r=this.extensions,o=n.meshes[t],i=o.primitives,a=[];for(let t=0,s=i.length;t<s;t++){const s=void 0===i[t].material?(void 0===(l=this.cache).DefaultMaterial&&(l.DefaultMaterial=new e.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:e.FrontSide})),l.DefaultMaterial):this.getDependency("material",i[t].material);a.push(s)}var l;return a.push(s.loadGeometries(i)),Promise.all(a).then((function(n){const a=n.slice(0,n.length-1),l=n[n.length-1],c=[];for(let n=0,u=l.length;n<u;n++){const u=l[n],h=i[n];let p;const d=a[n];if(h.mode===I||h.mode===C||h.mode===O||void 0===h.mode)p=!0===o.isSkinnedMesh?new e.SkinnedMesh(u,d):new e.Mesh(u,d),!0!==p.isSkinnedMesh||p.geometry.attributes.skinWeight.normalized||p.normalizeSkinWeights(),h.mode===C?p.geometry=$(p.geometry,e.TriangleStripDrawMode):h.mode===O&&(p.geometry=$(p.geometry,e.TriangleFanDrawMode));else if(h.mode===w)p=new e.LineSegments(u,d);else if(h.mode===P)p=new e.Line(u,d);else if(h.mode===b)p=new e.LineLoop(u,d);else{if(h.mode!==L)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+h.mode);p=new e.Points(u,d)}Object.keys(p.geometry.morphAttributes).length>0&&q(p,o),p.name=s.createUniqueName(o.name||"mesh_"+t),X(p,o),h.extensions&&V(r,p,h),s.assignFinalMaterial(p),c.push(p)}for(let e=0,n=c.length;e<n;e++)s.associations.set(c[e],{meshes:t,primitives:e});if(1===c.length)return c[0];const u=new e.Group;s.associations.set(u,{meshes:t});for(let e=0,t=c.length;e<t;e++)u.add(c[e]);return u}))}loadCamera(t){let s;const n=this.json.cameras[t],r=n[n.type];if(r)return"perspective"===n.type?s=new e.PerspectiveCamera(e.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(s=new e.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(s.name=this.createUniqueName(n.name)),X(s,n),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s={joints:t.joints};return void 0===t.inverseBindMatrices?Promise.resolve(s):this.getDependency("accessor",t.inverseBindMatrices).then((function(e){return s.inverseBindMatrices=e,s}))}loadAnimation(t){const s=this.json.animations[t],n=[],r=[],o=[],i=[],a=[];for(let e=0,t=s.channels.length;e<t;e++){const t=s.channels[e],l=s.samplers[t.sampler],c=t.target,u=void 0!==c.node?c.node:c.id,h=void 0!==s.parameters?s.parameters[l.input]:l.input,p=void 0!==s.parameters?s.parameters[l.output]:l.output;n.push(this.getDependency("node",u)),r.push(this.getDependency("accessor",h)),o.push(this.getDependency("accessor",p)),i.push(l),a.push(c)}return Promise.all([Promise.all(n),Promise.all(r),Promise.all(o),Promise.all(i),Promise.all(a)]).then((function(n){const r=n[0],o=n[1],i=n[2],a=n[3],l=n[4],c=[];for(let t=0,s=r.length;t<s;t++){const s=r[t],n=o[t],u=i[t],h=a[t],p=l[t];if(void 0===s)continue;let d;switch(s.updateMatrix(),s.matrixAutoUpdate=!0,D[p.path]){case D.weights:d=e.NumberKeyframeTrack;break;case D.rotation:d=e.QuaternionKeyframeTrack;break;case D.position:case D.scale:default:d=e.VectorKeyframeTrack}const m=s.name?s.name:s.uuid,f=void 0!==h.interpolation?G[h.interpolation]:e.InterpolateLinear,g=[];D[p.path]===D.weights?s.traverse((function(e){e.morphTargetInfluences&&g.push(e.name?e.name:e.uuid)})):g.push(m);let T=u.array;if(u.normalized){const e=Q(T.constructor),t=new Float32Array(T.length);for(let s=0,n=T.length;s<n;s++)t[s]=T[s]*e;T=t}for(let t=0,s=g.length;t<s;t++){const s=new d(g[t]+"."+D[p.path],n.array,T,f);"CUBICSPLINE"===h.interpolation&&(s.createInterpolant=function(t){return new(this instanceof e.QuaternionKeyframeTrack?E:y)(this.times,this.values,this.getValueSize()/3,t)},s.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),c.push(s)}}const u=s.name?s.name:"animation_"+t;return new e.AnimationClip(u,void 0,c)}))}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return void 0===n.mesh?null:s.getDependency("mesh",n.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,n.mesh,e);return void 0!==n.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=n.weights.length;t<s;t++)e.morphTargetInfluences[t]=n.weights[t]})),t}))}loadNode(t){const s=this.json,n=this.extensions,r=this,o=s.nodes[t],i=o.name?r.createUniqueName(o.name):"";return function(){const e=[],s=r._invokeOne((function(e){return e.createNodeMesh&&e.createNodeMesh(t)}));return s&&e.push(s),void 0!==o.camera&&e.push(r.getDependency("camera",o.camera).then((function(e){return r._getNodeRef(r.cameraCache,o.camera,e)}))),r._invokeAll((function(e){return e.createNodeAttachment&&e.createNodeAttachment(t)})).forEach((function(t){e.push(t)})),Promise.all(e)}().then((function(s){let a;if(a=!0===o.isBone?new e.Bone:s.length>1?new e.Group:1===s.length?s[0]:new e.Object3D,a!==s[0])for(let e=0,t=s.length;e<t;e++)a.add(s[e]);if(o.name&&(a.userData.name=o.name,a.name=i),X(a,o),o.extensions&&V(n,a,o),void 0!==o.matrix){const t=new e.Matrix4;t.fromArray(o.matrix),a.applyMatrix4(t)}else void 0!==o.translation&&a.position.fromArray(o.translation),void 0!==o.rotation&&a.quaternion.fromArray(o.rotation),void 0!==o.scale&&a.scale.fromArray(o.scale);return r.associations.has(a)||r.associations.set(a,{}),r.associations.get(a).nodes=t,a}))}loadScene(t){const s=this.json,n=this.extensions,r=this.json.scenes[t],o=this,i=new e.Group;r.name&&(i.name=o.createUniqueName(r.name)),X(i,r),r.extensions&&V(n,i,r);const a=r.nodes||[],l=[];for(let e=0,t=a.length;e<t;e++)l.push(J(a[e],i,s,o));return Promise.all(l).then((function(){return o.associations=(t=>{const s=new Map;for(const[t,n]of o.associations)(t instanceof e.Material||t instanceof e.Texture)&&s.set(t,n);return t.traverse((e=>{const t=o.associations.get(e);null!=t&&s.set(e,t)})),s})(i),i}))}}function J(t,s,n,r){const o=n.nodes[t];return r.getDependency("node",t).then((function(t){if(void 0===o.skin)return t;let s;return r.getDependency("skin",o.skin).then((function(e){s=e;const t=[];for(let e=0,n=s.joints.length;e<n;e++)t.push(r.getDependency("node",s.joints[e]));return Promise.all(t)})).then((function(n){return t.traverse((function(t){if(!t.isMesh)return;const r=[],o=[];for(let t=0,i=n.length;t<i;t++){const i=n[t];if(i){r.push(i);const n=new e.Matrix4;void 0!==s.inverseBindMatrices&&n.fromArray(s.inverseBindMatrices.array,16*t),o.push(n)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[t])}t.bind(new e.Skeleton(r,o),t.matrixWorld)})),t}))})).then((function(e){s.add(e);const t=[];if(o.children){const s=o.children;for(let o=0,i=s.length;o<i;o++){const i=s[o];t.push(J(i,e,n,r))}}return Promise.all(t)}))}function Z(t,s,n){const r=s.attributes,o=[];function i(e,s){return n.getDependency("accessor",e).then((function(e){t.setAttribute(s,e)}))}for(const e in r){const s=k[e]||e.toLowerCase();s in t.attributes||o.push(i(r[e],s))}if(void 0!==s.indices&&!t.index){const e=n.getDependency("accessor",s.indices).then((function(e){t.setIndex(e)}));o.push(e)}return X(t,s),function(t,s,n){const r=s.attributes,o=new e.Box3;if(void 0===r.POSITION)return;{const t=n.json.accessors[r.POSITION],s=t.min,i=t.max;if(void 0===s||void 0===i)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(o.set(new e.Vector3(s[0],s[1],s[2]),new e.Vector3(i[0],i[1],i[2])),t.normalized){const e=Q(N[t.componentType]);o.min.multiplyScalar(e),o.max.multiplyScalar(e)}}const i=s.targets;if(void 0!==i){const t=new e.Vector3,s=new e.Vector3;for(let e=0,r=i.length;e<r;e++){const r=i[e];if(void 0!==r.POSITION){const e=n.json.accessors[r.POSITION],o=e.min,i=e.max;if(void 0!==o&&void 0!==i){if(s.setX(Math.max(Math.abs(o[0]),Math.abs(i[0]))),s.setY(Math.max(Math.abs(o[1]),Math.abs(i[1]))),s.setZ(Math.max(Math.abs(o[2]),Math.abs(i[2]))),e.normalized){const t=Q(N[e.componentType]);s.multiplyScalar(t)}t.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}o.expandByVector(t)}t.boundingBox=o;const a=new e.Sphere;o.getCenter(a.center),a.radius=o.min.distanceTo(o.max)/2,t.boundingSphere=a}(t,s,n),Promise.all(o).then((function(){return void 0!==s.targets?function(e,t,s){let n=!1,r=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(n=!0),void 0!==s.NORMAL&&(r=!0),n&&r)break}if(!n&&!r)return Promise.resolve(e);const o=[],i=[];for(let a=0,l=t.length;a<l;a++){const l=t[a];if(n){const t=void 0!==l.POSITION?s.getDependency("accessor",l.POSITION):e.attributes.position;o.push(t)}if(r){const t=void 0!==l.NORMAL?s.getDependency("accessor",l.NORMAL):e.attributes.normal;i.push(t)}}return Promise.all([Promise.all(o),Promise.all(i)]).then((function(t){const s=t[0],o=t[1];return n&&(e.morphAttributes.position=s),r&&(e.morphAttributes.normal=o),e.morphTargetsRelative=!0,e}))}(t,s.targets,n):t}))}function $(t,s){let n=t.getIndex();if(null===n){const e=[],s=t.getAttribute("position");if(void 0===s)return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t;for(let t=0;t<s.count;t++)e.push(t);t.setIndex(e),n=t.getIndex()}const r=n.count-2,o=[];if(s===e.TriangleFanDrawMode)for(let e=1;e<=r;e++)o.push(n.getX(0)),o.push(n.getX(e)),o.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(o.push(n.getX(e)),o.push(n.getX(e+1)),o.push(n.getX(e+2))):(o.push(n.getX(e+2)),o.push(n.getX(e+1)),o.push(n.getX(e)));o.length/3!==r&&console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=t.clone();return i.setIndex(o),i}exports.GLTFLoader=t;
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new i(e)})),this.register((function(e){return new p(e)})),this.register((function(e){return new d(e)})),this.register((function(e){return new a(e)})),this.register((function(e){return new l(e)})),this.register((function(e){return new c(e)})),this.register((function(e){return new u(e)})),this.register((function(e){return new h(e)})),this.register((function(e){return new r(e)})),this.register((function(e){return new m(e)}))}load(t,s,n,r){const o=this;let i;i=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:e.LoaderUtils.extractUrlBase(t),this.manager.itemStart(t);const a=function(e){r?r(e):console.error(e),o.manager.itemError(t),o.manager.itemEnd(t)},l=new e.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(t,(function(e){try{o.parse(e,i,(function(e){s(e),o.manager.itemEnd(t)}),a)}catch(e){a(e)}}),n,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(t,s,r,i){let a;const l={},c={};if("string"==typeof t)a=t;else{if(e.LoaderUtils.decodeText(new Uint8Array(t,0,4))===f){try{l[n.KHR_BINARY_GLTF]=new x(t)}catch(e){return void(i&&i(e))}a=l[n.KHR_BINARY_GLTF].content}else a=e.LoaderUtils.decodeText(new Uint8Array(t))}const u=JSON.parse(a);if(void 0===u.asset||u.asset.version[0]<2)return void(i&&i(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const h=new Y(u,{path:s||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});h.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](h);c[t.name]=t,l[t.name]=!0}if(u.extensionsUsed)for(let e=0;e<u.extensionsUsed.length;++e){const t=u.extensionsUsed[e],s=u.extensionsRequired||[];switch(t){case n.KHR_MATERIALS_UNLIT:l[t]=new o;break;case n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:l[t]=new S;break;case n.KHR_DRACO_MESH_COMPRESSION:l[t]=new M(u,this.dracoLoader);break;case n.KHR_TEXTURE_TRANSFORM:l[t]=new R;break;case n.KHR_MESH_QUANTIZATION:l[t]=new _;break;default:s.indexOf(t)>=0&&void 0===c[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}h.setExtensions(l),h.setPlugins(c),h.parse(r,i)}parseAsync(e,t){const s=this;return new Promise((function(n,r){s.parse(e,t,n,r)}))}}function s(){let e={};return{get:function(t){return e[t]},add:function(t,s){e[t]=s},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const n={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_IOR:"KHR_materials_ior",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",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",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression"};class r{constructor(e){this.parser=e,this.name=n.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 n=t[s];n.extensions&&n.extensions[this.name]&&void 0!==n.extensions[this.name].light&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(t){const s=this.parser,n="light:"+t;let r=s.cache.get(n);if(r)return r;const o=s.json,i=((o.extensions&&o.extensions[this.name]||{}).lights||[])[t];let a;const l=new e.Color(16777215);void 0!==i.color&&l.fromArray(i.color);const c=void 0!==i.range?i.range:0;switch(i.type){case"directional":a=new e.DirectionalLight(l),a.target.position.set(0,0,-1),a.add(a.target);break;case"point":a=new e.PointLight(l),a.distance=c;break;case"spot":a=new e.SpotLight(l),a.distance=c,i.spot=i.spot||{},i.spot.innerConeAngle=void 0!==i.spot.innerConeAngle?i.spot.innerConeAngle:0,i.spot.outerConeAngle=void 0!==i.spot.outerConeAngle?i.spot.outerConeAngle:Math.PI/4,a.angle=i.spot.outerConeAngle,a.penumbra=1-i.spot.innerConeAngle/i.spot.outerConeAngle,a.target.position.set(0,0,-1),a.add(a.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+i.type)}return a.position.set(0,0,0),a.decay=2,void 0!==i.intensity&&(a.intensity=i.intensity),a.name=s.createUniqueName(i.name||"light_"+t),r=Promise.resolve(a),s.cache.add(n,r),r}createNodeAttachment(e){const t=this,s=this.parser,n=s.json.nodes[e],r=(n.extensions&&n.extensions[this.name]||{}).light;return void 0===r?null:this._loadLight(r).then((function(e){return s._getNodeRef(t.cache,r,e)}))}}class o{constructor(){this.name=n.KHR_MATERIALS_UNLIT}getMaterialType(){return e.MeshBasicMaterial}extendParams(t,s,n){const r=[];t.color=new e.Color(1,1,1),t.opacity=1;const o=s.pbrMetallicRoughness;if(o){if(Array.isArray(o.baseColorFactor)){const e=o.baseColorFactor;t.color.fromArray(e),t.opacity=e[3]}void 0!==o.baseColorTexture&&r.push(n.assignTexture(t,"map",o.baseColorTexture))}return Promise.all(r)}}class i{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];if(void 0!==i.clearcoatFactor&&(s.clearcoat=i.clearcoatFactor),void 0!==i.clearcoatTexture&&o.push(n.assignTexture(s,"clearcoatMap",i.clearcoatTexture)),void 0!==i.clearcoatRoughnessFactor&&(s.clearcoatRoughness=i.clearcoatRoughnessFactor),void 0!==i.clearcoatRoughnessTexture&&o.push(n.assignTexture(s,"clearcoatRoughnessMap",i.clearcoatRoughnessTexture)),void 0!==i.clearcoatNormalTexture&&(o.push(n.assignTexture(s,"clearcoatNormalMap",i.clearcoatNormalTexture)),void 0!==i.clearcoatNormalTexture.scale)){const t=i.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new e.Vector2(t,t)}return Promise.all(o)}}class a{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SHEEN}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[];s.sheenColor=new e.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const i=r.extensions[this.name];return void 0!==i.sheenColorFactor&&s.sheenColor.fromArray(i.sheenColorFactor),void 0!==i.sheenRoughnessFactor&&(s.sheenRoughness=i.sheenRoughnessFactor),void 0!==i.sheenColorTexture&&o.push(n.assignTexture(s,"sheenColorMap",i.sheenColorTexture)),void 0!==i.sheenRoughnessTexture&&o.push(n.assignTexture(s,"sheenRoughnessMap",i.sheenRoughnessTexture)),Promise.all(o)}}class l{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&r.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(r)}}class c{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_VOLUME}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];s.thickness=void 0!==i.thicknessFactor?i.thicknessFactor:0,void 0!==i.thicknessTexture&&o.push(n.assignTexture(s,"thicknessMap",i.thicknessTexture)),s.attenuationDistance=i.attenuationDistance||0;const a=i.attenuationColor||[1,1,1];return s.attenuationColor=new e.Color(a[0],a[1],a[2]),Promise.all(o)}}class u{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_IOR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name];return t.ior=void 0!==n.ior?n.ior:1.5,Promise.resolve()}}class h{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SPECULAR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];s.specularIntensity=void 0!==i.specularFactor?i.specularFactor:1,void 0!==i.specularTexture&&o.push(n.assignTexture(s,"specularIntensityMap",i.specularTexture));const a=i.specularColorFactor||[1,1,1];return s.specularColor=new e.Color(a[0],a[1],a[2]),void 0!==i.specularColorTexture&&o.push(n.assignTexture(s,"specularColorMap",i.specularColorTexture).then((function(t){t.encoding=e.sRGBEncoding}))),Promise.all(o)}}class p{constructor(e){this.parser=e,this.name=n.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 r=n.extensions[this.name],o=s.images[r.source],i=t.options.ktx2Loader;if(!i){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,o,i)}}class d{constructor(e){this.parser=e,this.name=n.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,r=n.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],i=n.images[o.source];let a=s.textureLoader;if(i.uri){const e=s.options.manager.getHandler(i.uri);null!==e&&(a=e)}return this.detectSupport().then((function(r){if(r)return s.loadTextureImage(e,i,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(1===t.height)}}))),this.isSupported}}class m{constructor(e){this.name=n.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 e=s.extensions[this.name],n=this.parser.getDependency("buffer",e.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.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 Promise.all([n,r.ready]).then((function(t){const s=e.byteOffset||0,n=e.byteLength||0,o=e.count,i=e.byteStride,a=new ArrayBuffer(o*i),l=new Uint8Array(t[0],s,n);return r.decodeGltfBuffer(new Uint8Array(a),o,i,l,e.mode,e.filter),a}))}return null}}const f="glTF",g=1313821514,T=5130562;class x{constructor(t){this.name=n.KHR_BINARY_GLTF,this.content=null,this.body=null;const s=new DataView(t,0,12);if(this.header={magic:e.LoaderUtils.decodeText(new Uint8Array(t.slice(0,4))),version:s.getUint32(4,!0),length:s.getUint32(8,!0)},this.header.magic!==f)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-12,o=new DataView(t,12);let i=0;for(;i<r;){const s=o.getUint32(i,!0);i+=4;const n=o.getUint32(i,!0);if(i+=4,n===g){const n=new Uint8Array(t,12+i,s);this.content=e.LoaderUtils.decodeText(n)}else if(n===T){const e=12+i;this.body=t.slice(e,e+s)}i+=s}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class M{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=n.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,i={},a={},l={};for(const e in o){const t=k[e]||e.toLowerCase();i[t]=o[e]}for(const t in e.attributes){const n=k[t]||t.toLowerCase();if(void 0!==o[t]){const r=s.accessors[e.attributes[t]],o=N[r.componentType];l[n]=o,a[n]=!0===r.normalized}}return t.getDependency("bufferView",r).then((function(e){return new Promise((function(t){n.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],n=a[t];void 0!==n&&(s.normalized=n)}t(e)}),i,l)}))}))}}class R{constructor(){this.name=n.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),void 0===t.offset&&void 0===t.rotation&&void 0===t.scale||(e=e.clone(),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class v extends e.MeshStandardMaterial{constructor(t){super(),this.isGLTFSpecularGlossinessMaterial=!0;const s=["#ifdef USE_SPECULARMAP","\tuniform sampler2D specularMap;","#endif"].join("\n"),n=["#ifdef USE_GLOSSINESSMAP","\tuniform sampler2D glossinessMap;","#endif"].join("\n"),r=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP","\tvec4 texelSpecular = texture2D( specularMap, vUv );","\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture","\tspecularFactor *= texelSpecular.rgb;","#endif"].join("\n"),o=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP","\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );","\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture","\tglossinessFactor *= texelGlossiness.a;","#endif"].join("\n"),i=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.specularColor = specularFactor;"].join("\n"),a={specular:{value:(new e.Color).setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=a,this.onBeforeCompile=function(e){for(const t in a)e.uniforms[t]=a[t];e.fragmentShader=e.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",s).replace("#include <metalnessmap_pars_fragment>",n).replace("#include <roughnessmap_fragment>",r).replace("#include <metalnessmap_fragment>",o).replace("#include <lights_physical_fragment>",i)},Object.defineProperties(this,{specular:{get:function(){return a.specular.value},set:function(e){a.specular.value=e}},specularMap:{get:function(){return a.specularMap.value},set:function(e){a.specularMap.value=e,e?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return a.glossiness.value},set:function(e){a.glossiness.value=e}},glossinessMap:{get:function(){return a.glossinessMap.value},set:function(e){a.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(t)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class S{constructor(){this.name=n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity","refractionRatio"]}getMaterialType(){return v}extendParams(t,s,n){const r=s.extensions[this.name];t.color=new e.Color(1,1,1),t.opacity=1;const o=[];if(Array.isArray(r.diffuseFactor)){const e=r.diffuseFactor;t.color.fromArray(e),t.opacity=e[3]}if(void 0!==r.diffuseTexture&&o.push(n.assignTexture(t,"map",r.diffuseTexture)),t.emissive=new e.Color(0,0,0),t.glossiness=void 0!==r.glossinessFactor?r.glossinessFactor:1,t.specular=new e.Color(1,1,1),Array.isArray(r.specularFactor)&&t.specular.fromArray(r.specularFactor),void 0!==r.specularGlossinessTexture){const e=r.specularGlossinessTexture;o.push(n.assignTexture(t,"glossinessMap",e)),o.push(n.assignTexture(t,"specularMap",e))}return Promise.all(o)}createMaterial(t){const s=new v(t);return s.fog=!0,s.color=t.color,s.map=void 0===t.map?null:t.map,s.lightMap=null,s.lightMapIntensity=1,s.aoMap=void 0===t.aoMap?null:t.aoMap,s.aoMapIntensity=1,s.emissive=t.emissive,s.emissiveIntensity=1,s.emissiveMap=void 0===t.emissiveMap?null:t.emissiveMap,s.bumpMap=void 0===t.bumpMap?null:t.bumpMap,s.bumpScale=1,s.normalMap=void 0===t.normalMap?null:t.normalMap,s.normalMapType=e.TangentSpaceNormalMap,t.normalScale&&(s.normalScale=t.normalScale),s.displacementMap=null,s.displacementScale=1,s.displacementBias=0,s.specularMap=void 0===t.specularMap?null:t.specularMap,s.specular=t.specular,s.glossinessMap=void 0===t.glossinessMap?null:t.glossinessMap,s.glossiness=t.glossiness,s.alphaMap=null,s.envMap=void 0===t.envMap?null:t.envMap,s.envMapIntensity=1,s.refractionRatio=.98,s}}class _{constructor(){this.name=n.KHR_MESH_QUANTIZATION}}class y extends e.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=e*n*3+n;for(let e=0;e!==n;e++)t[e]=s[r+e];return t}}y.prototype.beforeStart_=y.prototype.copySampleValue_,y.prototype.afterEnd_=y.prototype.copySampleValue_,y.prototype.interpolate_=function(e,t,s,n){const r=this.resultBuffer,o=this.sampleValues,i=this.valueSize,a=2*i,l=3*i,c=n-t,u=(s-t)/c,h=u*u,p=h*u,d=e*l,m=d-l,f=-2*p+3*h,g=p-h,T=1-f,x=g-h+u;for(let e=0;e!==i;e++){const t=o[m+e+i],s=o[m+e+a]*c,n=o[d+e+i],l=o[d+e]*c;r[e]=T*t+x*s+f*n+g*l}return r};const A=new e.Quaternion;class E extends y{interpolate_(e,t,s,n){const r=super.interpolate_(e,t,s,n);return A.fromArray(r).normalize().toArray(r),r}}const L=0,w=1,b=2,P=3,I=4,C=5,O=6,N={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},F={9728:e.NearestFilter,9729:e.LinearFilter,9984:e.NearestMipmapNearestFilter,9985:e.LinearMipmapNearestFilter,9986:e.NearestMipmapLinearFilter,9987:e.LinearMipmapLinearFilter},H={33071:e.ClampToEdgeWrapping,33648:e.MirroredRepeatWrapping,10497:e.RepeatWrapping},U={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},k={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},D={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},G={CUBICSPLINE:void 0,LINEAR:e.InterpolateLinear,STEP:e.InterpolateDiscrete},B="OPAQUE",K="MASK",j="BLEND";function V(e,t,s){for(const n in s.extensions)void 0===e[n]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[n]=s.extensions[n])}function X(e,t){void 0!==t.extras&&("object"==typeof t.extras?Object.assign(e.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function q(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,n=t.weights.length;s<n;s++)e.morphTargetInfluences[s]=t.weights[s];if(t.extras&&Array.isArray(t.extras.targetNames)){const s=t.extras.targetNames;if(e.morphTargetInfluences.length===s.length){e.morphTargetDictionary={};for(let t=0,n=s.length;t<n;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function z(e){const t=e.extensions&&e.extensions[n.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+W(t.attributes):e.indices+":"+W(e.attributes)+":"+e.mode,s}function W(e){let t="";const s=Object.keys(e).sort();for(let n=0,r=s.length;n<r;n++)t+=s[n]+":"+e[s[n]]+";";return t}function Q(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 Y{constructor(t={},n={}){this.json=t,this.extensions={},this.plugins={},this.options=n,this.cache=new s,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.textureCache={},this.nodeNamesUsed={},"undefined"!=typeof createImageBitmap&&!1===/Firefox|^((?!chrome|android).)*safari/i.test(navigator.userAgent)?this.textureLoader=new e.ImageBitmapLoader(this.options.manager):this.textureLoader=new e.TextureLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new e.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,n=this.json,r=this.extensions;this.cache.removeAll(),this._invokeAll((function(e){return e._markDefs&&e._markDefs()})),Promise.all(this._invokeAll((function(e){return e.beforeRoot&&e.beforeRoot()}))).then((function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])})).then((function(t){const o={scene:t[0][n.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:n.asset,parser:s,userData:{}};V(r,o,n),X(o,n),Promise.all(s._invokeAll((function(e){return e.afterRoot&&e.afterRoot(o)}))).then((function(){e(o)}))})).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s].joints;for(let t=0,s=n.length;t<s;t++)e[n[t]].isBone=!0}for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0!==n.mesh&&(this._addNodeRef(this.meshCache,n.mesh),void 0!==n.skin&&(s[n.mesh].isSkinnedMesh=!0)),void 0!==n.camera&&this._addNodeRef(this.cameraCache,n.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const n=s.clone(),r=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,n]of e.children.entries())r(n,t.children[s])};return r(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 r=e(t[n]);r&&s.push(r)}return s}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.loadNode(t);break;case"mesh":n=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":n=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":n=this.loadSkin(t);break;case"animation":n=this.loadAnimation(t);break;case"camera":n=this.loadCamera(t);break;default:throw new Error("Unknown type: "+e)}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(n.map((function(t,n){return s.getDependency(e,n)}))),this.cache.add(e,t)}return t}loadBuffer(t){const s=this.json.buffers[t],r=this.fileLoader;if(s.type&&"arraybuffer"!==s.type)throw new Error("THREE.GLTFLoader: "+s.type+" buffer type is not supported.");if(void 0===s.uri&&0===t)return Promise.resolve(this.extensions[n.KHR_BINARY_GLTF].body);const o=this.options;return new Promise((function(t,n){r.load(e.LoaderUtils.resolveURL(s.uri,o.path),t,void 0,(function(){n(new Error('THREE.GLTFLoader: Failed to load buffer "'+s.uri+'".'))}))}))}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then((function(e){const s=t.byteLength||0,n=t.byteOffset||0;return e.slice(n,n+s)}))}loadAccessor(t){const s=this,n=this.json,r=this.json.accessors[t];if(void 0===r.bufferView&&void 0===r.sparse)return Promise.resolve(null);const o=[];return void 0!==r.bufferView?o.push(this.getDependency("bufferView",r.bufferView)):o.push(null),void 0!==r.sparse&&(o.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),o.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(o).then((function(t){const o=t[0],i=U[r.type],a=N[r.componentType],l=a.BYTES_PER_ELEMENT,c=l*i,u=r.byteOffset||0,h=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,p=!0===r.normalized;let d,m;if(h&&h!==c){const t=Math.floor(u/h),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+t+":"+r.count;let c=s.cache.get(n);c||(d=new a(o,t*h,r.count*h/l),c=new e.InterleavedBuffer(d,h/l),s.cache.add(n,c)),m=new e.InterleavedBufferAttribute(c,i,u%h/l,p)}else d=null===o?new a(r.count*i):new a(o,u,r.count*i),m=new e.BufferAttribute(d,i,p);if(void 0!==r.sparse){const s=U.SCALAR,n=N[r.sparse.indices.componentType],l=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,u=new n(t[1],l,r.sparse.count*s),h=new a(t[2],c,r.sparse.count*i);null!==o&&(m=new e.BufferAttribute(m.array.slice(),m.itemSize,m.normalized));for(let e=0,t=u.length;e<t;e++){const t=u[e];if(m.setX(t,h[e*i]),i>=2&&m.setY(t,h[e*i+1]),i>=3&&m.setZ(t,h[e*i+2]),i>=4&&m.setW(t,h[e*i+3]),i>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return m}))}loadTexture(e){const t=this.json,s=this.options,n=t.textures[e],r=t.images[n.source];let o=this.textureLoader;if(r.uri){const e=s.manager.getHandler(r.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(t,s,n){const r=this,o=this.json,i=this.options,a=o.textures[t],l=(s.uri||s.bufferView)+":"+a.sampler;if(this.textureCache[l])return this.textureCache[l];const c=self.URL||self.webkitURL;let u=s.uri||"",h=!1;if(void 0!==s.bufferView)u=r.getDependency("bufferView",s.bufferView).then((function(e){h=!0;const t=new Blob([e],{type:s.mimeType});return u=c.createObjectURL(t),u}));else if(void 0===s.uri)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");const p=Promise.resolve(u).then((function(t){return new Promise((function(s,r){let o=s;!0===n.isImageBitmapLoader&&(o=function(t){const n=new e.Texture(t);n.needsUpdate=!0,s(n)}),n.load(e.LoaderUtils.resolveURL(t,i.path),o,void 0,r)}))})).then((function(s){!0===h&&c.revokeObjectURL(u),s.flipY=!1,a.name&&(s.name=a.name);const n=(o.samplers||{})[a.sampler]||{};return s.magFilter=F[n.magFilter]||e.LinearFilter,s.minFilter=F[n.minFilter]||e.LinearMipmapLinearFilter,s.wrapS=H[n.wrapS]||e.RepeatWrapping,s.wrapT=H[n.wrapT]||e.RepeatWrapping,r.associations.set(s,{textures:t}),s})).catch((function(){return console.error("THREE.GLTFLoader: Couldn't load texture",u),null}));return this.textureCache[l]=p,p}assignTexture(e,t,s){const r=this;return this.getDependency("texture",s.index).then((function(o){if(void 0===s.texCoord||0==s.texCoord||"aoMap"===t&&1==s.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+s.texCoord+" for texture "+t+" not yet supported."),r.extensions[n.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[n.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=r.associations.get(o);o=r.extensions[n.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),r.associations.set(o,t)}}return e[t]=o,o}))}assignFinalMaterial(t){const s=t.geometry;let n=t.material;const r=void 0===s.attributes.tangent,o=void 0!==s.attributes.color,i=void 0===s.attributes.normal;if(t.isPoints){const t="PointsMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.PointsMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),s.map=n.map,s.sizeAttenuation=!1,this.cache.add(t,s)),n=s}else if(t.isLine){const t="LineBasicMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.LineBasicMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),this.cache.add(t,s)),n=s}if(r||o||i){let e="ClonedMaterial:"+n.uuid+":";n.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),r&&(e+="derivative-tangents:"),o&&(e+="vertex-colors:"),i&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),o&&(t.vertexColors=!0),i&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}n.aoMap&&void 0===s.attributes.uv2&&void 0!==s.attributes.uv&&s.setAttribute("uv2",s.attributes.uv),t.material=n}getMaterialType(){return e.MeshStandardMaterial}loadMaterial(t){const s=this,r=this.json,o=this.extensions,i=r.materials[t];let a;const l={},c=i.extensions||{},u=[];if(c[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];a=e.getMaterialType(),u.push(e.extendParams(l,i,s))}else if(c[n.KHR_MATERIALS_UNLIT]){const e=o[n.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),u.push(e.extendParams(l,i,s))}else{const n=i.pbrMetallicRoughness||{};if(l.color=new e.Color(1,1,1),l.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;l.color.fromArray(e),l.opacity=e[3]}void 0!==n.baseColorTexture&&u.push(s.assignTexture(l,"map",n.baseColorTexture)),l.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,l.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(u.push(s.assignTexture(l,"metalnessMap",n.metallicRoughnessTexture)),u.push(s.assignTexture(l,"roughnessMap",n.metallicRoughnessTexture))),a=this._invokeOne((function(e){return e.getMaterialType&&e.getMaterialType(t)})),u.push(Promise.all(this._invokeAll((function(e){return e.extendMaterialParams&&e.extendMaterialParams(t,l)}))))}!0===i.doubleSided&&(l.side=e.DoubleSide);const h=i.alphaMode||B;if(h===j?(l.transparent=!0,l.depthWrite=!1):(l.transparent=!1,h===K&&(l.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&a!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"normalMap",i.normalTexture)),l.normalScale=new e.Vector2(1,1),void 0!==i.normalTexture.scale)){const e=i.normalTexture.scale;l.normalScale.set(e,e)}return void 0!==i.occlusionTexture&&a!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(l.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&a!==e.MeshBasicMaterial&&(l.emissive=(new e.Color).fromArray(i.emissiveFactor)),void 0!==i.emissiveTexture&&a!==e.MeshBasicMaterial&&u.push(s.assignTexture(l,"emissiveMap",i.emissiveTexture)),Promise.all(u).then((function(){let r;return r=a===v?o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(l):new a(l),i.name&&(r.name=i.name),r.map&&(r.map.encoding=e.sRGBEncoding),r.emissiveMap&&(r.emissiveMap.encoding=e.sRGBEncoding),X(r,i),s.associations.set(r,{materials:t}),i.extensions&&V(o,r,i),r}))}createUniqueName(t){const s=e.PropertyBinding.sanitizeNodeName(t||"");let n=s;for(let e=1;this.nodeNamesUsed[n];++e)n=s+"_"+e;return this.nodeNamesUsed[n]=!0,n}loadGeometries(t){const s=this,r=this.extensions,o=this.primitiveCache;function i(e){return r[n.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return Z(t,e,s)}))}const a=[];for(let r=0,l=t.length;r<l;r++){const l=t[r],c=z(l),u=o[c];if(u)a.push(u.promise);else{let t;t=l.extensions&&l.extensions[n.KHR_DRACO_MESH_COMPRESSION]?i(l):Z(new e.BufferGeometry,l,s),o[c]={primitive:l,promise:t},a.push(t)}}return Promise.all(a)}loadMesh(t){const s=this,n=this.json,r=this.extensions,o=n.meshes[t],i=o.primitives,a=[];for(let t=0,s=i.length;t<s;t++){const s=void 0===i[t].material?(void 0===(l=this.cache).DefaultMaterial&&(l.DefaultMaterial=new e.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:e.FrontSide})),l.DefaultMaterial):this.getDependency("material",i[t].material);a.push(s)}var l;return a.push(s.loadGeometries(i)),Promise.all(a).then((function(n){const a=n.slice(0,n.length-1),l=n[n.length-1],c=[];for(let n=0,u=l.length;n<u;n++){const u=l[n],h=i[n];let p;const d=a[n];if(h.mode===I||h.mode===C||h.mode===O||void 0===h.mode)p=!0===o.isSkinnedMesh?new e.SkinnedMesh(u,d):new e.Mesh(u,d),!0!==p.isSkinnedMesh||p.geometry.attributes.skinWeight.normalized||p.normalizeSkinWeights(),h.mode===C?p.geometry=$(p.geometry,e.TriangleStripDrawMode):h.mode===O&&(p.geometry=$(p.geometry,e.TriangleFanDrawMode));else if(h.mode===w)p=new e.LineSegments(u,d);else if(h.mode===P)p=new e.Line(u,d);else if(h.mode===b)p=new e.LineLoop(u,d);else{if(h.mode!==L)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+h.mode);p=new e.Points(u,d)}Object.keys(p.geometry.morphAttributes).length>0&&q(p,o),p.name=s.createUniqueName(o.name||"mesh_"+t),X(p,o),h.extensions&&V(r,p,h),s.assignFinalMaterial(p),c.push(p)}for(let e=0,n=c.length;e<n;e++)s.associations.set(c[e],{meshes:t,primitives:e});if(1===c.length)return c[0];const u=new e.Group;s.associations.set(u,{meshes:t});for(let e=0,t=c.length;e<t;e++)u.add(c[e]);return u}))}loadCamera(t){let s;const n=this.json.cameras[t],r=n[n.type];if(r)return"perspective"===n.type?s=new e.PerspectiveCamera(e.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(s=new e.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(s.name=this.createUniqueName(n.name)),X(s,n),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s={joints:t.joints};return void 0===t.inverseBindMatrices?Promise.resolve(s):this.getDependency("accessor",t.inverseBindMatrices).then((function(e){return s.inverseBindMatrices=e,s}))}loadAnimation(t){const s=this.json.animations[t],n=[],r=[],o=[],i=[],a=[];for(let e=0,t=s.channels.length;e<t;e++){const t=s.channels[e],l=s.samplers[t.sampler],c=t.target,u=void 0!==c.node?c.node:c.id,h=void 0!==s.parameters?s.parameters[l.input]:l.input,p=void 0!==s.parameters?s.parameters[l.output]:l.output;n.push(this.getDependency("node",u)),r.push(this.getDependency("accessor",h)),o.push(this.getDependency("accessor",p)),i.push(l),a.push(c)}return Promise.all([Promise.all(n),Promise.all(r),Promise.all(o),Promise.all(i),Promise.all(a)]).then((function(n){const r=n[0],o=n[1],i=n[2],a=n[3],l=n[4],c=[];for(let t=0,s=r.length;t<s;t++){const s=r[t],n=o[t],u=i[t],h=a[t],p=l[t];if(void 0===s)continue;let d;switch(s.updateMatrix(),s.matrixAutoUpdate=!0,D[p.path]){case D.weights:d=e.NumberKeyframeTrack;break;case D.rotation:d=e.QuaternionKeyframeTrack;break;case D.position:case D.scale:default:d=e.VectorKeyframeTrack}const m=s.name?s.name:s.uuid,f=void 0!==h.interpolation?G[h.interpolation]:e.InterpolateLinear,g=[];D[p.path]===D.weights?s.traverse((function(e){e.morphTargetInfluences&&g.push(e.name?e.name:e.uuid)})):g.push(m);let T=u.array;if(u.normalized){const e=Q(T.constructor),t=new Float32Array(T.length);for(let s=0,n=T.length;s<n;s++)t[s]=T[s]*e;T=t}for(let t=0,s=g.length;t<s;t++){const s=new d(g[t]+"."+D[p.path],n.array,T,f);"CUBICSPLINE"===h.interpolation&&(s.createInterpolant=function(t){return new(this instanceof e.QuaternionKeyframeTrack?E:y)(this.times,this.values,this.getValueSize()/3,t)},s.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),c.push(s)}}const u=s.name?s.name:"animation_"+t;return new e.AnimationClip(u,void 0,c)}))}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return void 0===n.mesh?null:s.getDependency("mesh",n.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,n.mesh,e);return void 0!==n.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=n.weights.length;t<s;t++)e.morphTargetInfluences[t]=n.weights[t]})),t}))}loadNode(t){const s=this.json,n=this.extensions,r=this,o=s.nodes[t],i=o.name?r.createUniqueName(o.name):"";return function(){const e=[],s=r._invokeOne((function(e){return e.createNodeMesh&&e.createNodeMesh(t)}));return s&&e.push(s),void 0!==o.camera&&e.push(r.getDependency("camera",o.camera).then((function(e){return r._getNodeRef(r.cameraCache,o.camera,e)}))),r._invokeAll((function(e){return e.createNodeAttachment&&e.createNodeAttachment(t)})).forEach((function(t){e.push(t)})),Promise.all(e)}().then((function(s){let a;if(a=!0===o.isBone?new e.Bone:s.length>1?new e.Group:1===s.length?s[0]:new e.Object3D,a!==s[0])for(let e=0,t=s.length;e<t;e++)a.add(s[e]);if(o.name&&(a.userData.name=o.name,a.name=i),X(a,o),o.extensions&&V(n,a,o),void 0!==o.matrix){const t=new e.Matrix4;t.fromArray(o.matrix),a.applyMatrix4(t)}else void 0!==o.translation&&a.position.fromArray(o.translation),void 0!==o.rotation&&a.quaternion.fromArray(o.rotation),void 0!==o.scale&&a.scale.fromArray(o.scale);return r.associations.has(a)||r.associations.set(a,{}),r.associations.get(a).nodes=t,a}))}loadScene(t){const s=this.json,n=this.extensions,r=this.json.scenes[t],o=this,i=new e.Group;r.name&&(i.name=o.createUniqueName(r.name)),X(i,r),r.extensions&&V(n,i,r);const a=r.nodes||[],l=[];for(let e=0,t=a.length;e<t;e++)l.push(J(a[e],i,s,o));return Promise.all(l).then((function(){return o.associations=(t=>{const s=new Map;for(const[t,n]of o.associations)(t instanceof e.Material||t instanceof e.Texture)&&s.set(t,n);return t.traverse((e=>{const t=o.associations.get(e);null!=t&&s.set(e,t)})),s})(i),i}))}}function J(t,s,n,r){const o=n.nodes[t];return r.getDependency("node",t).then((function(t){if(void 0===o.skin)return t;let s;return r.getDependency("skin",o.skin).then((function(e){s=e;const t=[];for(let e=0,n=s.joints.length;e<n;e++)t.push(r.getDependency("node",s.joints[e]));return Promise.all(t)})).then((function(n){return t.traverse((function(t){if(!t.isMesh)return;const r=[],o=[];for(let t=0,i=n.length;t<i;t++){const i=n[t];if(i){r.push(i);const n=new e.Matrix4;void 0!==s.inverseBindMatrices&&n.fromArray(s.inverseBindMatrices.array,16*t),o.push(n)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[t])}t.bind(new e.Skeleton(r,o),t.matrixWorld)})),t}))})).then((function(e){s.add(e);const t=[];if(o.children){const s=o.children;for(let o=0,i=s.length;o<i;o++){const i=s[o];t.push(J(i,e,n,r))}}return Promise.all(t)}))}function Z(t,s,n){const r=s.attributes,o=[];function i(e,s){return n.getDependency("accessor",e).then((function(e){t.setAttribute(s,e)}))}for(const e in r){const s=k[e]||e.toLowerCase();s in t.attributes||o.push(i(r[e],s))}if(void 0!==s.indices&&!t.index){const e=n.getDependency("accessor",s.indices).then((function(e){t.setIndex(e)}));o.push(e)}return X(t,s),function(t,s,n){const r=s.attributes,o=new e.Box3;if(void 0===r.POSITION)return;{const t=n.json.accessors[r.POSITION],s=t.min,i=t.max;if(void 0===s||void 0===i)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(o.set(new e.Vector3(s[0],s[1],s[2]),new e.Vector3(i[0],i[1],i[2])),t.normalized){const e=Q(N[t.componentType]);o.min.multiplyScalar(e),o.max.multiplyScalar(e)}}const i=s.targets;if(void 0!==i){const t=new e.Vector3,s=new e.Vector3;for(let e=0,r=i.length;e<r;e++){const r=i[e];if(void 0!==r.POSITION){const e=n.json.accessors[r.POSITION],o=e.min,i=e.max;if(void 0!==o&&void 0!==i){if(s.setX(Math.max(Math.abs(o[0]),Math.abs(i[0]))),s.setY(Math.max(Math.abs(o[1]),Math.abs(i[1]))),s.setZ(Math.max(Math.abs(o[2]),Math.abs(i[2]))),e.normalized){const t=Q(N[e.componentType]);s.multiplyScalar(t)}t.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}o.expandByVector(t)}t.boundingBox=o;const a=new e.Sphere;o.getCenter(a.center),a.radius=o.min.distanceTo(o.max)/2,t.boundingSphere=a}(t,s,n),Promise.all(o).then((function(){return void 0!==s.targets?function(e,t,s){let n=!1,r=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(n=!0),void 0!==s.NORMAL&&(r=!0),n&&r)break}if(!n&&!r)return Promise.resolve(e);const o=[],i=[];for(let a=0,l=t.length;a<l;a++){const l=t[a];if(n){const t=void 0!==l.POSITION?s.getDependency("accessor",l.POSITION):e.attributes.position;o.push(t)}if(r){const t=void 0!==l.NORMAL?s.getDependency("accessor",l.NORMAL):e.attributes.normal;i.push(t)}}return Promise.all([Promise.all(o),Promise.all(i)]).then((function(t){const s=t[0],o=t[1];return n&&(e.morphAttributes.position=s),r&&(e.morphAttributes.normal=o),e.morphTargetsRelative=!0,e}))}(t,s.targets,n):t}))}function $(t,s){let n=t.getIndex();if(null===n){const e=[],s=t.getAttribute("position");if(void 0===s)return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t;for(let t=0;t<s.count;t++)e.push(t);t.setIndex(e),n=t.getIndex()}const r=n.count-2,o=[];if(s===e.TriangleFanDrawMode)for(let e=1;e<=r;e++)o.push(n.getX(0)),o.push(n.getX(e)),o.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(o.push(n.getX(e)),o.push(n.getX(e+1)),o.push(n.getX(e+2))):(o.push(n.getX(e+2)),o.push(n.getX(e+1)),o.push(n.getX(e)));o.length/3!==r&&console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=t.clone();return i.setIndex(o),i}exports.GLTFLoader=t;
|
package/loaders/GLTFLoader.js
CHANGED
@@ -2239,7 +2239,6 @@ class GLTFParser {
|
|
2239
2239
|
materialParams.depthWrite = false;
|
2240
2240
|
} else {
|
2241
2241
|
materialParams.transparent = false;
|
2242
|
-
materialParams.alphaWrite = false;
|
2243
2242
|
|
2244
2243
|
if (alphaMode === ALPHA_MODES.MASK) {
|
2245
2244
|
materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e);const s=(e=1)=>{const n=new Float32Array(4096*e*
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e);const s=(e=1)=>{const n=new Float32Array(4096*e*4),r=new t.DataTexture(n,1024,4*e,t.RGBAFormat,t.FloatType);return r.wrapS=t.RepeatWrapping,r.wrapT=t.RepeatWrapping,r.magFilter=t.NearestFilter,r.needsUpdate=!0,r},i=(e,t,n=0)=>{const r=Math.floor(1024);t.arcLengthDivisions=r/2,t.updateArcLengths();const s=t.getSpacedPoints(r),i=t.computeFrenetFrames(r,!0);for(let t=0;t<r;t++){const r=Math.floor(t/1024),o=t%1024;let f=s[t];a(e,o,f.x,f.y,f.z,0+r+4*n),f=i.tangents[t],a(e,o,f.x,f.y,f.z,1+r+4*n),f=i.normals[t],a(e,o,f.x,f.y,f.z,2+r+4*n),f=i.binormals[t],a(e,o,f.x,f.y,f.z,3+r+4*n)}e.needsUpdate=!0},a=(e,t,n,r,s,i)=>{const a=e.image,{data:o}=a,f=4096*i;o[4*t+f+0]=n,o[4*t+f+1]=r,o[4*t+f+2]=s,o[4*t+f+3]=1};function o(e){return{spineTexture:{value:e},pathOffset:{type:"f",value:0},pathSegment:{type:"f",value:1},spineOffset:{type:"f",value:161},spineLength:{type:"f",value:400},flow:{type:"i",value:1}}}function f(e,t,n=1){e.__ok||(e.__ok=!0,e.onBeforeCompile=e=>{if(e.__modified)return;e.__modified=!0,Object.assign(e.uniforms,t);const r=`\n\t\tuniform sampler2D spineTexture;\n\t\tuniform float pathOffset;\n\t\tuniform float pathSegment;\n\t\tuniform float spineOffset;\n\t\tuniform float spineLength;\n\t\tuniform int flow;\n\n\t\tfloat textureLayers = ${4*n}.;\n\t\tfloat textureStacks = 1.;\n\n\t\t${e.vertexShader}\n\t\t`.replace("#include <beginnormal_vertex>","").replace("#include <defaultnormal_vertex>","").replace("#include <begin_vertex>","").replace(/void\s*main\s*\(\)\s*\{/,"\n void main() {\n #include <beginnormal_vertex>\n\n vec4 worldPos = modelMatrix * vec4(position, 1.);\n\n bool bend = flow > 0;\n float xWeight = bend ? 0. : 1.;\n\n #ifdef USE_INSTANCING\n float pathOffsetFromInstanceMatrix = instanceMatrix[3][2];\n float spineLengthFromInstanceMatrix = instanceMatrix[3][0];\n float spinePortion = bend ? (worldPos.x + spineOffset) / spineLengthFromInstanceMatrix : 0.;\n float mt = (spinePortion * pathSegment + pathOffset + pathOffsetFromInstanceMatrix)*textureStacks;\n #else\n float spinePortion = bend ? (worldPos.x + spineOffset) / spineLength : 0.;\n float mt = (spinePortion * pathSegment + pathOffset)*textureStacks;\n #endif\n\n mt = mod(mt, textureStacks);\n float rowOffset = floor(mt);\n\n #ifdef USE_INSTANCING\n rowOffset += instanceMatrix[3][1] * 4.;\n #endif\n\n vec3 spinePos = texture2D(spineTexture, vec2(mt, (0. + rowOffset + 0.5) / textureLayers)).xyz;\n vec3 a = texture2D(spineTexture, vec2(mt, (1. + rowOffset + 0.5) / textureLayers)).xyz;\n vec3 b = texture2D(spineTexture, vec2(mt, (2. + rowOffset + 0.5) / textureLayers)).xyz;\n vec3 c = texture2D(spineTexture, vec2(mt, (3. + rowOffset + 0.5) / textureLayers)).xyz;\n mat3 basis = mat3(a, b, c);\n\n vec3 transformed = basis\n * vec3(worldPos.x * xWeight, worldPos.y * 1., worldPos.z * 1.)\n + spinePos;\n\n vec3 transformedNormal = normalMatrix * (basis * objectNormal);\n\t\t\t").replace("#include <project_vertex>","vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n\t\t\t\tgl_Position = projectionMatrix * mvPosition;");e.vertexShader=r})}class l{constructor(e,n=1){r.default(this,"curveArray",void 0),r.default(this,"curveLengthArray",void 0),r.default(this,"object3D",void 0),r.default(this,"splineTexure",void 0),r.default(this,"uniforms",void 0);const i=e.clone(),a=s(n),l=o(a);i.traverse((e=>{(e instanceof t.Mesh||e instanceof t.InstancedMesh)&&(e.material=e.material.clone(),f(e.material,l,n))})),this.curveArray=new Array(n),this.curveLengthArray=new Array(n),this.object3D=i,this.splineTexure=a,this.uniforms=l}updateCurve(e,t){if(e>=this.curveArray.length)throw Error("Index out of range for Flow");const n=t.getLength();this.uniforms.spineLength.value=n,this.curveLengthArray[e]=n,this.curveArray[e]=t,i(this.splineTexure,t,e)}moveAlongCurve(e){this.uniforms.pathOffset.value+=e}}const u=new t.Matrix4;exports.Flow=l,exports.InstancedFlow=class extends l{constructor(e,n,s,i){const a=new t.InstancedMesh(s,i,e);a.instanceMatrix.setUsage(t.DynamicDrawUsage),super(a,n),r.default(this,"offsets",void 0),r.default(this,"whichCurve",void 0),this.offsets=new Array(e).fill(0),this.whichCurve=new Array(e).fill(0)}writeChanges(e){u.makeTranslation(this.curveLengthArray[this.whichCurve[e]],this.whichCurve[e],this.offsets[e]),this.object3D.setMatrixAt(e,u),this.object3D.instanceMatrix.needsUpdate=!0}moveIndividualAlongCurve(e,t){this.offsets[e]+=t,this.writeChanges(e)}setCurve(e,t){if(isNaN(t))throw Error("curve index being set is Not a Number (NaN)");this.whichCurve[e]=t,this.writeChanges(e)}},exports.getUniforms=o,exports.initSplineTexture=s,exports.modifyShader=f,exports.updateSplineTexture=i;
|
@@ -2,7 +2,7 @@ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
2
|
import { DataTexture, RGBAFormat, FloatType, RepeatWrapping, NearestFilter, Mesh, InstancedMesh, Matrix4, DynamicDrawUsage } from 'three';
|
3
3
|
|
4
4
|
// Original src: https://github.com/zz85/threejs-path-flow
|
5
|
-
const CHANNELS =
|
5
|
+
const CHANNELS = 4;
|
6
6
|
const TEXTURE_WIDTH = 1024;
|
7
7
|
const TEXTURE_HEIGHT = 4;
|
8
8
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "three-stdlib",
|
3
|
-
"version": "2.8.
|
3
|
+
"version": "2.8.7",
|
4
4
|
"private": false,
|
5
5
|
"description": "stand-alone library of threejs examples",
|
6
6
|
"main": "index.cjs.js",
|
@@ -22,7 +22,6 @@
|
|
22
22
|
"dependencies": {
|
23
23
|
"@babel/runtime": "^7.16.7",
|
24
24
|
"@webgpu/glslang": "^0.0.15",
|
25
|
-
"@webxr-input-profiles/motion-controllers": "^1.0.0",
|
26
25
|
"chevrotain": "^9.0.2",
|
27
26
|
"draco3d": "^1.4.1",
|
28
27
|
"fflate": "^0.6.9",
|
@@ -33,6 +32,6 @@
|
|
33
32
|
"zstddec": "^0.0.2"
|
34
33
|
},
|
35
34
|
"peerDependencies": {
|
36
|
-
"three": ">=0.
|
35
|
+
"three": ">=0.137.0"
|
37
36
|
}
|
38
37
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./XRHandMeshModel.cjs.js");require("../loaders/GLTFLoader.cjs.js");class o extends e.Object3D{constructor(e){super(),this.controller=e,this.motionController=null,this.envMap=null,this.mesh=null,e.addEventListener("connected",(o=>{const n=o.data;n.hand&&!this.motionController&&(this.xrInputSource=n,this.motionController=new t.XRHandMeshModel(this,e,this.path,n.handedness))})),e.addEventListener("disconnected",(()=>{this.clear(),this.motionController=null}))}updateMatrixWorld(e){super.updateMatrixWorld(e),this.motionController&&this.motionController.updateMesh()}getPointerPosition(){const e=this.controller.joints["index-finger-tip"];return e?e.position:null}intersectBoxObject(t){const o=this.getPointerPosition();if(o){const n=new e.Sphere(o,.01),r=(new e.Box3).setFromObject(t);return n.intersectsBox(r)}return!1}checkButton(e){this.intersectBoxObject(e)?e.onPress():e.onClear(),e.isPressed()&&e.whilePressed()}}exports.OculusHandModel=o;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Object3D, Sphere, Box3, Mesh, Texture, Vector3 } from 'three';
|
2
|
+
|
3
|
+
export class OculusHandModel extends Object3D {
|
4
|
+
controller: Object3D;
|
5
|
+
motionController: Object3D | null;
|
6
|
+
envMap: Texture | null;
|
7
|
+
|
8
|
+
mesh: Mesh | null;
|
9
|
+
|
10
|
+
constructor(controller: Object3D);
|
11
|
+
|
12
|
+
updateMatrixWorld(force?: boolean): void;
|
13
|
+
|
14
|
+
getPointerPosition(): Vector3 | null;
|
15
|
+
|
16
|
+
intersectBoxObject(boxObject: Object3D): boolean;
|
17
|
+
|
18
|
+
checkButton(button: Object3D): void;
|
19
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { Object3D, Sphere, Box3 } from 'three';
|
2
|
+
import { XRHandMeshModel } from './XRHandMeshModel.js';
|
3
|
+
|
4
|
+
const TOUCH_RADIUS = 0.01;
|
5
|
+
const POINTING_JOINT = 'index-finger-tip';
|
6
|
+
|
7
|
+
class OculusHandModel extends Object3D {
|
8
|
+
constructor(controller) {
|
9
|
+
super();
|
10
|
+
this.controller = controller;
|
11
|
+
this.motionController = null;
|
12
|
+
this.envMap = null;
|
13
|
+
this.mesh = null;
|
14
|
+
controller.addEventListener('connected', event => {
|
15
|
+
const xrInputSource = event.data;
|
16
|
+
|
17
|
+
if (xrInputSource.hand && !this.motionController) {
|
18
|
+
this.xrInputSource = xrInputSource;
|
19
|
+
this.motionController = new XRHandMeshModel(this, controller, this.path, xrInputSource.handedness);
|
20
|
+
}
|
21
|
+
});
|
22
|
+
controller.addEventListener('disconnected', () => {
|
23
|
+
this.clear();
|
24
|
+
this.motionController = null;
|
25
|
+
});
|
26
|
+
}
|
27
|
+
|
28
|
+
updateMatrixWorld(force) {
|
29
|
+
super.updateMatrixWorld(force);
|
30
|
+
|
31
|
+
if (this.motionController) {
|
32
|
+
this.motionController.updateMesh();
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
getPointerPosition() {
|
37
|
+
const indexFingerTip = this.controller.joints[POINTING_JOINT];
|
38
|
+
|
39
|
+
if (indexFingerTip) {
|
40
|
+
return indexFingerTip.position;
|
41
|
+
} else {
|
42
|
+
return null;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
intersectBoxObject(boxObject) {
|
47
|
+
const pointerPosition = this.getPointerPosition();
|
48
|
+
|
49
|
+
if (pointerPosition) {
|
50
|
+
const indexSphere = new Sphere(pointerPosition, TOUCH_RADIUS);
|
51
|
+
const box = new Box3().setFromObject(boxObject);
|
52
|
+
return indexSphere.intersectsBox(box);
|
53
|
+
} else {
|
54
|
+
return false;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
checkButton(button) {
|
59
|
+
if (this.intersectBoxObject(button)) {
|
60
|
+
button.onPress();
|
61
|
+
} else {
|
62
|
+
button.onClear();
|
63
|
+
}
|
64
|
+
|
65
|
+
if (button.isPressed()) {
|
66
|
+
button.whilePressed();
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
}
|
71
|
+
|
72
|
+
export { OculusHandModel };
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";function t(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("three"));const i=new e.Vector3(0,1,0),s=new e.Vector3(0,0,1);class r extends e.Object3D{constructor(t,e){super(),this.hand=t,this.controller=e,this.motionController=null,this.envMap=null,this.mesh=null,this.pointerGeometry=null,this.pointerMesh=null,this.pointerObject=null,this.pinched=!1,this.attached=!1,this.cursorObject=null,this.raycaster=null,t.addEventListener("connected",(t=>{const e=t.data;e.hand&&(this.visible=!0,this.xrInputSource=e,this.createPointer())}))}_drawVerticesRing(t,e,i){const r=e.clone();for(var o=0;o<16;o++){r.applyAxisAngle(s,2*Math.PI/16);const e=16*i+o;t[3*e]=r.x,t[3*e+1]=r.y,t[3*e+2]=r.z}}_updatePointerVertices(t){const s=this.pointerGeometry.attributes.position.array,r=new e.Vector3(.002,0,-1*(.035-t));this._drawVerticesRing(s,r,0);const o=new e.Vector3(Math.sin(110*Math.PI/180)*t,Math.cos(110*Math.PI/180)*t,0);for(var n=0;n<12;n++)this._drawVerticesRing(s,o,n+1),o.applyAxisAngle(i,110*Math.PI/180/-24);const a=new e.Vector3(0,0,-1*(.035-t));s[624]=a.x,s[625]=a.y,s[626]=a.z;const c=new e.Vector3(0,0,t);s[627]=c.x,s[628]=c.y,s[629]=c.z,this.pointerGeometry.setAttribute("position",new e.Float32BufferAttribute(s,3))}createPointer(){var t,i;const s=new Array(630).fill(0),r=[];for(this.pointerGeometry=new e.BufferGeometry,this.pointerGeometry.setAttribute("position",new e.Float32BufferAttribute(s,3)),this._updatePointerVertices(.01),t=0;t<12;t++){for(i=0;i<15;i++)r.push(16*t+i,16*t+i+1,16*(t+1)+i),r.push(16*t+i+1,16*(t+1)+i+1,16*(t+1)+i);r.push(16*(t+1)-1,16*t,16*(t+2)-1),r.push(16*t,16*(t+1),16*(t+2)-1)}for(t=0;t<15;t++)r.push(208,t+1,t),r.push(209,t+192,t+192+1);r.push(208,0,15),r.push(209,207,192);const o=new e.MeshBasicMaterial;o.transparent=!0,o.opacity=.4,this.pointerGeometry.setIndex(r),this.pointerMesh=new e.Mesh(this.pointerGeometry,o),this.pointerMesh.position.set(0,0,-.01),this.pointerObject=new e.Object3D,this.pointerObject.add(this.pointerMesh),this.raycaster=new e.Raycaster;const n=new e.SphereGeometry(.02,10,10),a=new e.MeshBasicMaterial;a.transparent=!0,a.opacity=.4,this.cursorObject=new e.Mesh(n,a),this.pointerObject.add(this.cursorObject),this.add(this.pointerObject)}_updateRaycaster(){if(this.raycaster){const t=this.pointerObject.matrixWorld,i=new e.Matrix4;i.identity().extractRotation(t),this.raycaster.ray.origin.setFromMatrixPosition(t),this.raycaster.ray.direction.set(0,0,-1).applyMatrix4(i)}}_updatePointer(){this.pointerObject.visible=this.controller.visible;const t=this.hand.joints["index-finger-tip"],e=this.hand.joints["thumb-tip"],i=t.position.distanceTo(e.position),s=t.position.clone().add(e.position).multiplyScalar(.5);this.pointerObject.position.copy(s),this.pointerObject.quaternion.copy(this.controller.quaternion),this.pinched=i<=.02;const r=(i-.01)/.04,o=(i-.01)/.01;if(r>1)this._updatePointerVertices(.01),this.pointerMesh.position.set(0,0,-.01),this.pointerMesh.material.opacity=.4;else if(r>0){const t=.007*r+.003;this._updatePointerVertices(t),o<1?(this.pointerMesh.position.set(0,0,-1*t-.02*(1-o)),this.pointerMesh.material.opacity=.4+.6*(1-o)):(this.pointerMesh.position.set(0,0,-1*t),this.pointerMesh.material.opacity=.4)}else this._updatePointerVertices(.003),this.pointerMesh.position.set(0,0,-.023),this.pointerMesh.material.opacity=1;this.cursorObject.material.opacity=this.pointerMesh.material.opacity}updateMatrixWorld(t){super.updateMatrixWorld(t),this.pointerGeometry&&(this._updatePointer(),this._updateRaycaster())}isPinched(){return this.pinched}setAttached(t){this.attached=t}isAttached(){return this.attached}intersectObject(t,e=!0){if(this.raycaster)return this.raycaster.intersectObject(t,e)}intersectObjects(t,e=!0){if(this.raycaster)return this.raycaster.intersectObjects(t,e)}checkIntersections(t,i=!1){if(this.raycaster&&!this.attached){const s=this.raycaster.intersectObjects(t,i),r=new e.Vector3(0,0,-1);if(s.length>0){const t=s[0].distance;this.cursorObject.position.copy(r.multiplyScalar(t))}else this.cursorObject.position.copy(r.multiplyScalar(1.5))}}setCursor(t){const i=new e.Vector3(0,0,-1);this.raycaster&&!this.attached&&this.cursorObject.position.copy(i.multiplyScalar(t))}}exports.OculusHandPointerModel=r;
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import {
|
2
|
+
BufferGeometry,
|
3
|
+
Intersection,
|
4
|
+
Mesh,
|
5
|
+
MeshBasicMaterial,
|
6
|
+
Object3D,
|
7
|
+
Raycaster,
|
8
|
+
SphereBufferGeometry,
|
9
|
+
Texture,
|
10
|
+
Vector3,
|
11
|
+
} from 'three';
|
12
|
+
|
13
|
+
export class OculusHandPointerModel extends Object3D {
|
14
|
+
hand: Object3D;
|
15
|
+
controller: Object3D;
|
16
|
+
motionController: Object3D | null;
|
17
|
+
|
18
|
+
envMap: Texture | null;
|
19
|
+
|
20
|
+
mesh: Mesh | null;
|
21
|
+
|
22
|
+
pointerGeometry: BufferGeometry | null;
|
23
|
+
pointerMesh: Mesh<BufferGeometry, MeshBasicMaterial> | null;
|
24
|
+
pointerObject: Object3D | null;
|
25
|
+
|
26
|
+
pinched: boolean;
|
27
|
+
attached: boolean;
|
28
|
+
|
29
|
+
cursorObject: Mesh<SphereBufferGeometry, MeshBasicMaterial> | null;
|
30
|
+
|
31
|
+
raycaster: Raycaster;
|
32
|
+
|
33
|
+
visible: boolean;
|
34
|
+
xrInputSource: unknown;
|
35
|
+
|
36
|
+
constructor(hand: Object3D, controller: Object3D);
|
37
|
+
|
38
|
+
private _drawVerticesRing(vertices: number[], baseVector: Vector3, ringIndex: number): void;
|
39
|
+
|
40
|
+
private _updatePointerVertices(rearRadius: number): void;
|
41
|
+
|
42
|
+
public createPointer(): void;
|
43
|
+
|
44
|
+
private _updateRaycaster(): void;
|
45
|
+
|
46
|
+
private _updatePointer(): void;
|
47
|
+
|
48
|
+
public updateMatrixWorld(force?: boolean): void;
|
49
|
+
|
50
|
+
public isPinched(): boolean;
|
51
|
+
|
52
|
+
public setAttached(attached: boolean): void;
|
53
|
+
|
54
|
+
public isAttached(): boolean;
|
55
|
+
|
56
|
+
public intersectObject(object: Object3D, recursive?: boolean): Intersection[] | void;
|
57
|
+
|
58
|
+
public intersectObjects(objects: Object3D[], recursive?: boolean): Intersection[] | void;
|
59
|
+
|
60
|
+
public checkIntersections(objects: Object3D[], recursive?: boolean): void;
|
61
|
+
|
62
|
+
public setCursor(distance: number): void;
|
63
|
+
}
|