胶州空管前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

1 lines
48 KiB

!function(){if(void 0===THREE.SkinnedMeshEx){const e=new THREE.Vector3,t=new THREE.Vector4,r=new THREE.Vector4,n=new THREE.Vector3,o=(new THREE.Box3,new THREE.Matrix4);class s extends THREE.SkinnedMesh{constructor(e,t){super(e,t),this.isSkinnedMeshEx=!0,this.bindMatrixInverseReal=new THREE.Matrix4}computeBoundingBox(){const e=this.geometry;return null===this.boundingBox&&(this.boundingBox=new Box3),e.computeBoundingBox()}getBindMatrixInverse(){return this.bindMatrixInverseReal}copy(e){return super.copy(e),this.isSkinnedMeshEx=e.isSkinnedMeshEx,this.bindMatrixInverseReal.copy(e.bindMatrixInverseReal),this}bind(e,t){this.skeleton&&(this.skeleton.associatedSkinnedMesh=null),super.bind(e,t),this.bindMatrixInverseReal.copy(this.bindMatrix).invert(),this.skeleton.associatedSkinnedMesh=this}updateMatrixWorld(e){THREE.Mesh.prototype.updateMatrixWorld.call(this,e),"attached"===this.bindMode?(this.bindMatrixInverseReal.copy(this.matrixWorld).invert(),this.bindMatrixInverse.identity()):"detached"===this.bindMode?(this.bindMatrixInverse.copy(this.bindMatrix).invert(),this.bindMatrixInverseReal.copy(this.bindMatrix).invert()):console.warn("THREE.SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}boneTransform(s,a){const i=this.skeleton,l=this.geometry;t.fromBufferAttribute(l.attributes.skinIndex,s),r.fromBufferAttribute(l.attributes.skinWeight,s),e.fromBufferAttribute(l.attributes.position,s).applyMatrix4(this.bindMatrix),a.set(0,0,0);for(let s=0;s<4;s++){const l=r.getComponent(s);if(0!==l){const r=t.getComponent(s);o.multiplyMatrices(i.bones[r].matrixWorld,i.boneInverses[r]),a.addScaledVector(n.copy(e).applyMatrix4(o),l)}}return a.applyMatrix4(this.bindMatrixInverseReal)}}THREE.SkinnedMeshEx=s}if(void 0===THREE.SkeletonEx){const e=new THREE.Matrix4,t=new THREE.Matrix4;class r extends THREE.Skeleton{constructor(e=[],t=[]){super(e,t),this.associatedSkinnedMesh=null}clone(){return new r(this.bones,this.boneInverses)}getBindMatrixInverse(){return this.associatedSkinnedMesh?this.associatedSkinnedMesh.getBindMatrixInverse():void 0}update(){const r=this.bones,n=this.boneInverses,o=this.boneMatrices,s=this.boneTexture,a=this.getBindMatrixInverse();for(let s=0,i=r.length;s<i;s++){const i=r[s]?r[s].matrixWorld:t;e.multiplyMatrices(i,n[s]),a&&e.premultiply(a),e.toArray(o,16*s)}null!==s&&(s.needsUpdate=!0)}}THREE.SkeletonEx=r}function e(e,t,r){const n=r.length-e-1;if(t>=r[n])return n-1;if(t<=r[e])return e;let o=e,s=n,a=Math.floor((o+s)/2);for(;t<r[a]||t>=r[a+1];)t<r[a]?s=a:o=a,a=Math.floor((o+s)/2);return a}function t(e,t,r,n){const o=[],s=[],a=[];o[0]=1;for(let i=1;i<=r;++i){s[i]=t-n[e+1-i],a[i]=n[e+i]-t;let r=0;for(let e=0;e<i;++e){const t=a[e+1],n=s[i-e],l=o[e]/(t+n);o[e]=r+t*l,r=n*l}o[i]=r}return o}function r(e,t){let r=1;for(let t=2;t<=e;++t)r*=t;let n=1;for(let e=2;e<=t;++e)n*=e;for(let r=2;r<=e-t;++r)n*=r;return r/n}function n(t,n,o,s,a){const i=function(t,r,n,o,s){const a=s<t?s:t,i=[],l=e(t,o,r),c=function(e,t,r,n,o){const s=[];for(let e=0;e<=r;++e)s[e]=0;const a=[];for(let e=0;e<=n;++e)a[e]=s.slice(0);const i=[];for(let e=0;e<=r;++e)i[e]=s.slice(0);i[0][0]=1;const l=s.slice(0),c=s.slice(0);for(let n=1;n<=r;++n){l[n]=t-o[e+1-n],c[n]=o[e+n]-t;let r=0;for(let e=0;e<n;++e){const t=c[e+1],o=l[n-e];i[n][e]=t+o;const s=i[e][n-1]/i[n][e];i[e][n]=r+t*s,r=o*s}i[n][n]=r}for(let e=0;e<=r;++e)a[0][e]=i[e][r];for(let e=0;e<=r;++e){let t=0,o=1;const l=[];for(let e=0;e<=r;++e)l[e]=s.slice(0);l[0][0]=1;for(let s=1;s<=n;++s){let n=0;const c=e-s,u=r-s;e>=s&&(l[o][0]=l[t][0]/i[u+1][c],n=l[o][0]*i[c][u]);const p=e-1<=u?s-1:r-e;for(let e=c>=-1?1:-c;e<=p;++e)l[o][e]=(l[t][e]-l[t][e-1])/i[u+1][c+e],n+=l[o][e]*i[c+e][u];e<=u&&(l[o][s]=-l[t][s-1]/i[u+1][e],n+=l[o][s]*i[e][u]),a[s][e]=n;const h=t;t=o,o=h}}let u=r;for(let e=1;e<=n;++e){for(let t=0;t<=r;++t)a[e][t]*=u;u*=r-e}return a}(l,o,t,a,r),u=[];for(let e=0;e<n.length;++e){const t=n[e].clone(),r=t.w;t.x*=r,t.y*=r,t.z*=r,u[e]=t}for(let e=0;e<=a;++e){const r=u[l-t].clone().multiplyScalar(c[e][0]);for(let n=1;n<=t;++n)r.add(u[l-t+n].clone().multiplyScalar(c[e][n]));i[e]=r}for(let e=a+1;e<=s+1;++e)i[e]=new THREE.Vector4(0,0,0);return i}(t,n,o,s,a);return function(e){const t=e.length,n=[],o=[];for(let r=0;r<t;++r){const t=e[r];n[r]=new THREE.Vector3(t.x,t.y,t.z),o[r]=t.w}const s=[];for(let e=0;e<t;++e){const t=n[e].clone();for(let n=1;n<=e;++n)t.sub(s[e-n].clone().multiplyScalar(r(e,n)*o[n]));s[e]=t.divideScalar(o[0])}return s}(i)}class o extends THREE.Curve{constructor(e,t,r,n,o){super(),this.degree=e,this.knots=t,this.controlPoints=[],this.startKnot=n||0,this.endKnot=o||this.knots.length-1;for(let e=0;e<r.length;++e){const t=r[e];this.controlPoints[e]=new THREE.Vector4(t.x,t.y,t.z,t.w)}}getPoint(r,n=new THREE.Vector3){const o=n,s=this.knots[this.startKnot]+r*(this.knots[this.endKnot]-this.knots[this.startKnot]),a=function(r,n,o,s){const a=e(r,s,n),i=t(a,s,r,n),l=new THREE.Vector4(0,0,0,0);for(let e=0;e<=r;++e){const t=o[a-r+e],n=i[e],s=t.w*n;l.x+=t.x*s,l.y+=t.y*s,l.z+=t.z*s,l.w+=t.w*n}return l}(this.degree,this.knots,this.controlPoints,s);return 1!==a.w&&a.divideScalar(a.w),o.set(a.x,a.y,a.z)}getTangent(e,t=new THREE.Vector3){const r=t,o=this.knots[0]+e*(this.knots[this.knots.length-1]-this.knots[0]),s=n(this.degree,this.knots,this.controlPoints,o,1);return r.copy(s[1]).normalize(),r}}let s,a,i;class l extends THREE.Loader{constructor(e){super(e)}load(e,t,r,n){const o=this,s=""===o.path?THREE.LoaderUtils.extractUrlBase(e):o.path,a=new THREE.FileLoader(this.manager);a.setPath(o.path),a.setResponseType("arraybuffer"),a.setRequestHeader(o.requestHeader),a.setWithCredentials(o.withCredentials),a.load(e,(function(r){try{o.parse(r,s,t)}catch(t){n?n(t):console.error(t),o.manager.itemError(e)}}),r,n)}parse(e,t,r){if(function(e){const t="Kaydara FBX Binary \0";return e.byteLength>=t.length&&t===I(e,0,t.length)}(e))s=(new d).parse(e);else{const t=I(e);if(!function(e){const t=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let r=0;function n(t){const n=e[t-1];return e=e.slice(r+t),r++,n}for(let e=0;e<t.length;++e){if(n(1)===t[e])return!1}return!0}(t))throw new Error("THREE.FBXLoader: Unknown format.");if(E(t)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+E(t));s=(new h).parse(t)}const n=new THREE.TextureLoader(this.manager).setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin);return new c(n,this.manager).parse(s,r)}}class c{constructor(e,t){this.textureLoader=e,this.manager=t,this.imageNum=0,this.loadTextureCount=0,this.onLoad=null}parse(e,t){a=this.parseConnections(),this.onLoad=t;const r=this.parseImages();0==this.imageNum?this.onLoadTexture():this.parseTextures(r)}onLoadTexture(){if(this.loadTextureCount++,this.loadTextureCount>=this.imageNum){const e=this.parseMaterials(this.textures),t=this.parseDeformers(),r=(new u).parse(t);this.parseScene(t,r,e),this.onLoad&&this.onLoad(i)}}parseConnections(){const e=new Map;if("Connections"in s){s.Connections.connections.forEach((function(t){const r=t[0],n=t[1],o=t[2];e.has(r)||e.set(r,{parents:[],children:[]});const s={ID:n,relationship:o};e.get(r).parents.push(s),e.has(n)||e.set(n,{parents:[],children:[]});const a={ID:r,relationship:o};e.get(n).children.push(a)}))}return e}parseImages(){const e={},t={};if(this.imageNum=0,"Video"in s.Objects){const r=s.Objects.Video;for(const n in r){const o=r[n];if(e[parseInt(n)]=o.RelativeFilename||o.Filename,"Content"in o){const e=o.Content instanceof ArrayBuffer&&o.Content.byteLength>0,s="string"==typeof o.Content&&""!==o.Content;if(e||s){const e=this.parseImage(r[n]);t[o.RelativeFilename||o.Filename]=e}}}}for(const r in e){const n=e[r];this.imageNum++,void 0!==t[n]?e[r]=t[n]:e[r]=e[r].split("\\").pop()}return e}parseImage(e){const t=e.Content,r=e.RelativeFilename||e.Filename,n=r.slice(r.lastIndexOf(".")+1).toLowerCase();let o;switch(n){case"bmp":o="image/bmp";break;case"jpg":case"jpeg":o="image/jpeg";break;case"png":o="image/png";break;case"tif":o="image/tiff";break;case"tga":null===this.manager.getHandler(".tga")&&console.warn("FBXLoader: TGA loader not found, skipping ",r),o="image/tga";break;default:return void console.warn('FBXLoader: Image type "'+n+'" is not supported.')}if("string"==typeof t)return"data:"+o+";base64,"+t;{const e=new Uint8Array(t);return window.URL.createObjectURL(new Blob([e],{type:o}))}}parseTextures(e){if(this.textures=new Map,"Texture"in s.Objects){const t=s.Objects.Texture;for(const r in t){const n=this.parseTexture(t[r],e);this.textures.set(parseInt(r),n)}}return this.textures}parseTexture(e,t){const r=this.loadTexture(e,t);if(!r)return r;r.ID=e.id,r.name=e.attrName;const n=e.WrapModeU,o=e.WrapModeV,s=void 0!==n?n.value:0,a=void 0!==o?o.value:0;if(r.wrapS=0===s?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,r.wrapT=0===a?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,"Scaling"in e){const t=e.Scaling.value;r.repeat.x=t[0],r.repeat.y=t[1]}if("Translation"in e){const t=e.Translation.value;r.offset.x=t[0],r.offset.y=t[1]}return r}loadTexture(e,t){let r;const n=this.textureLoader.path,o=a.get(e.id).children;let s;void 0!==o&&o.length>0&&void 0!==t[o[0].ID]&&(r=t[o[0].ID],0!==r.indexOf("blob:")&&0!==r.indexOf("data:")||this.textureLoader.setPath(void 0));const i=e.FileName.slice(-3).toLowerCase();if("tga"===i){const t=this.manager.getHandler(".tga");null===t?(console.warn("FBXLoader: TGA loader not found, creating placeholder texture for",e.RelativeFilename),s=new THREE.Texture,s=null,this.onLoadTexture()):(t.setPath(this.textureLoader.path),s=t.load(r,(()=>{this.onLoadTexture()}),void 0,(()=>{this.textures.set(e.id,null),this.onLoadTexture()})))}else if("dds"===i){const t=this.manager.getHandler(".dds");null===t?(console.warn("FBXLoader: DDS loader not found, creating placeholder texture for",e.RelativeFilename),s=new THREE.Texture,s=null,this.onLoadTexture()):(t.setPath(this.textureLoader.path),s=t.load(r,(()=>{this.onLoadTexture()}),void 0,(()=>{this.textures.set(e.id,null),this.onLoadTexture()})))}else"psd"===i?(console.warn("FBXLoader: PSD textures are not supported, creating placeholder texture for",e.RelativeFilename),s=new THREE.Texture,s=null,this.onLoadTexture()):s=this.textureLoader.load(r,(()=>{this.onLoadTexture()}),void 0,(()=>{this.textures.set(e.id,null),this.onLoadTexture()}));return this.textureLoader.setPath(n),s}parseMaterials(e){const t=new Map;if("Material"in s.Objects){const r=s.Objects.Material;for(const n in r){const o=this.parseMaterial(r[n],e);null!==o&&t.set(parseInt(n),o)}}return t}parseMaterial(e,t){const r=e.id,n=e.attrName;let o=e.ShadingModel;if("object"==typeof o&&(o=o.value),!a.has(r))return null;const s=this.parseParameters(e,t,r);let i;switch(o.toLowerCase()){case"phong":i=new THREE.MeshPhongMaterial;break;case"lambert":i=new THREE.MeshLambertMaterial;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to THREE.MeshPhongMaterial.',o),i=new THREE.MeshPhongMaterial}return i.setValues(s),i.name=n,i}parseParameters(e,t,r){const n={};e.BumpFactor&&(n.bumpScale=e.BumpFactor.value),e.Diffuse?n.color=(new THREE.Color).fromArray(e.Diffuse.value).convertSRGBToLinear():!e.DiffuseColor||"THREE.Color"!==e.DiffuseColor.type&&"ColorRGB"!==e.DiffuseColor.type||(n.color=(new THREE.Color).fromArray(e.DiffuseColor.value).convertSRGBToLinear()),e.DisplacementFactor&&(n.displacementScale=e.DisplacementFactor.value),e.Emissive?n.emissive=(new THREE.Color).fromArray(e.Emissive.value).convertSRGBToLinear():!e.EmissiveColor||"THREE.Color"!==e.EmissiveColor.type&&"ColorRGB"!==e.EmissiveColor.type||(n.emissive=(new THREE.Color).fromArray(e.EmissiveColor.value).convertSRGBToLinear()),e.EmissiveFactor&&(n.emissiveIntensity=parseFloat(e.EmissiveFactor.value)),e.Opacity&&(n.opacity=parseFloat(e.Opacity.value)),n.opacity<1&&(n.transparent=!0),e.ReflectionFactor&&(n.reflectivity=e.ReflectionFactor.value),e.Shininess&&(n.shininess=e.Shininess.value),e.Specular?n.specular=(new THREE.Color).fromArray(e.Specular.value).convertSRGBToLinear():e.SpecularColor&&"THREE.Color"===e.SpecularColor.type&&(n.specular=(new THREE.Color).fromArray(e.SpecularColor.value).convertSRGBToLinear());const o=this;return a.get(r).children.forEach((function(e){const r=e.relationship;switch(r){case"Bump":n.bumpMap=o.getTexture(t,e.ID);break;case"Maya|TEX_ao_map":n.aoMap=o.getTexture(t,e.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":n.map=o.getTexture(t,e.ID),n.map&&(n.map.colorSpace=THREE.SRGBColorSpace);break;case"DisplacementColor":n.displacementMap=o.getTexture(t,e.ID);break;case"EmissiveColor":n.emissiveMap=o.getTexture(t,e.ID),n.emissiveMap&&(n.emissiveMap.colorSpace=THREE.SRGBColorSpace);break;case"NormalMap":case"Maya|TEX_normal_map":n.normalMap=o.getTexture(t,e.ID);break;case"ReflectionColor":n.envMap=o.getTexture(t,e.ID),n.envMap&&(n.envMap.mapping=THREE.EquirectangularReflectionMapping,n.envMap.colorSpace=THREE.SRGBColorSpace);break;case"SpecularColor":n.specularMap=o.getTexture(t,e.ID),n.specularMap&&(n.specularMap.colorSpace=THREE.SRGBColorSpace);break;case"TransparentColor":case"TransparencyFactor":n.alphaMap=o.getTexture(t,e.ID),n.transparent=!0;break;default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",r)}})),n}getTexture(e,t){return"LayeredTexture"in s.Objects&&t in s.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=a.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in s.Objects){const r=s.Objects.Deformer;for(const n in r){const o=r[n],s=a.get(parseInt(n));if("Skin"===o.attrType){const t=this.parseSkeleton(s,r);t.ID=n,s.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),t.geometryID=s.parents[0].ID,e[n]=t}else if("BlendShape"===o.attrType){const e={id:n};e.rawTargets=this.parseMorphTargets(s,r),e.id=n,s.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[n]=e}}}return{skeletons:e,morphTargets:t}}parseSkeleton(e,t){const r=[];return e.children.forEach((function(e){const n=t[e.ID];if("Cluster"!==n.attrType)return;const o={ID:e.ID,indices:[],weights:[],transformLink:(new THREE.Matrix4).fromArray(n.TransformLink.a)};"Indexes"in n&&(o.indices=n.Indexes.a,o.weights=n.Weights.a),r.push(o)})),{rawBones:r,bones:[]}}parseMorphTargets(e,t){const r=[];for(let n=0;n<e.children.length;n++){const o=e.children[n],s=t[o.ID],i={name:s.attrName,initialWeight:s.DeformPercent,id:s.id,fullWeights:s.FullWeights.a};if("BlendShapeChannel"!==s.attrType)return;i.geoID=a.get(parseInt(o.ID)).children.filter((function(e){return void 0===e.relationship}))[0].ID,r.push(i)}return r}parseScene(e,t,r){i=new THREE.Group;const n=this.parseModels(e.skeletons,t,r),o=s.Objects.Model,l=this;n.forEach((function(e){const t=o[e.ID];l.setLookAtProperties(e,t);a.get(e.ID).parents.forEach((function(t){const r=n.get(t.ID);void 0!==r&&r.add(e)})),null===e.parent&&i.add(e)})),this.bindSkeleton(e.skeletons,t,n),this.addGlobalSceneSettings(),i.traverse((function(e){if(e.userData.transformData){e.parent&&(e.userData.transformData.parentMatrix=e.parent.matrix,e.userData.transformData.parentMatrixWorld=e.parent.matrixWorld);const t=x(e.userData.transformData);e.applyMatrix4(t),e.updateWorldMatrix()}}));const c=(new p).parse();1===i.children.length&&i.children[0].isGroup&&(i.children[0].animations=c,i=i.children[0]),i.animations=c}parseModels(e,t,r){const n=new Map,o=s.Objects.Model;for(const s in o){const i=parseInt(s),l=o[s],c=a.get(i);let u=this.buildSkeleton(c,e,i,l.attrName);if(!u){switch(l.attrType){case"Camera":u=this.createCamera(c);break;case"Light":u=this.createLight(c);break;case"Mesh":u=this.createMesh(c,t,r);break;case"NurbsCurve":u=this.createCurve(c,t);break;case"LimbNode":case"Root":u=new THREE.Bone;break;default:u=new THREE.Group}u.name=l.attrName?THREE.PropertyBinding.sanitizeNodeName(l.attrName):"",u.userData.originalName=l.attrName,u.ID=i}this.getTransformData(u,l),n.set(i,u)}return n}buildSkeleton(e,t,r,n){let o=null;return e.parents.forEach((function(e){for(const s in t){const a=t[s];a.rawBones.forEach((function(t,s){if(t.ID===e.ID){const e=o;o=new THREE.Bone,o.matrixWorld.copy(t.transformLink),o.name=n?THREE.PropertyBinding.sanitizeNodeName(n):"",o.userData.originalName=n,o.ID=r,a.bones[s]=o,null!==e&&o.add(e)}}))}})),o}createCamera(e){let t,r;if(e.children.forEach((function(e){const t=s.Objects.NodeAttribute[e.ID];void 0!==t&&(r=t)})),void 0===r)t=new THREE.Object3D;else{let e=0;void 0!==r.CameraProjectionType&&1===r.CameraProjectionType.value&&(e=1);let n=1;void 0!==r.NearPlane&&(n=r.NearPlane.value/1e3);let o=1e3;void 0!==r.FarPlane&&(o=r.FarPlane.value/1e3);let s=window.innerWidth,a=window.innerHeight;void 0!==r.AspectWidth&&void 0!==r.AspectHeight&&(s=r.AspectWidth.value,a=r.AspectHeight.value);const i=s/a;let l=45;void 0!==r.FieldOfView&&(l=r.FieldOfView.value);const c=r.FocalLength?r.FocalLength.value:null;switch(e){case 0:t=new THREE.PerspectiveCamera(l,i,n,o),null!==c&&t.setFocalLength(c);break;case 1:t=new THREE.OrthographicCamera(-s/2,s/2,a/2,-a/2,n,o);break;default:console.warn("THREE.FBXLoader: Unknown camera type "+e+"."),t=new THREE.Object3D}}return t}createLight(e){let t,r;if(e.children.forEach((function(e){const t=s.Objects.NodeAttribute[e.ID];void 0!==t&&(r=t)})),void 0===r)t=new THREE.Object3D;else{let e;e=void 0===r.LightType?0:r.LightType.value;let n=16777215;void 0!==r.THREE.Color&&(n=(new THREE.Color).fromArray(r.THREE.Color.value).convertSRGBToLinear());let o=void 0===r.Intensity?1:r.Intensity.value/100;void 0!==r.CastLightOnObject&&0===r.CastLightOnObject.value&&(o=0);let s=0;void 0!==r.FarAttenuationEnd&&(s=void 0!==r.EnableFarAttenuation&&0===r.EnableFarAttenuation.value?0:r.FarAttenuationEnd.value);const a=1;switch(e){case 0:t=new THREE.PointLight(n,o,s,a);break;case 1:t=new THREE.DirectionalLight(n,o);break;case 2:let e=Math.PI/3;void 0!==r.InnerAngle&&(e=THREE.MathUtils.degToRad(r.InnerAngle.value));let i=0;void 0!==r.OuterAngle&&(i=THREE.MathUtils.degToRad(r.OuterAngle.value),i=Math.max(i,1)),t=new THREE.SpotLight(n,o,s,e,i,a);break;default:console.warn("THREE.FBXLoader: Unknown light type "+r.LightType.value+", defaulting to a THREE.PointLight."),t=new THREE.PointLight(n,o)}void 0!==r.CastShadows&&1===r.CastShadows.value&&(t.castShadow=!0)}return t}createMesh(e,t,r){let n,o=null,s=null;const a=[];return e.children.forEach((function(e){t.has(e.ID)&&(o=t.get(e.ID)),r.has(e.ID)&&a.push(r.get(e.ID))})),a.length>1?s=a:a.length>0?s=a[0]:(s=new THREE.MeshPhongMaterial({name:THREE.Loader.DEFAULT_MATERIAL_NAME,color:13421772}),a.push(s)),"color"in o.attributes&&a.forEach((function(e){e.vertexColors=!0})),o.FBX_Deformer?(n=new THREE.SkinnedMeshEx(o,s),n.normalizeSkinWeights()):n=new THREE.Mesh(o,s),n}createCurve(e,t){const r=e.children.reduce((function(e,r){return t.has(r.ID)&&(e=t.get(r.ID)),e}),null),n=new THREE.LineBasicMaterial({name:THREE.Loader.DEFAULT_MATERIAL_NAME,color:3342591,linewidth:1});return new THREE.Line(r,n)}getTransformData(e,t){const r={};"InheritType"in t&&(r.inheritType=parseInt(t.InheritType.value)),r.eulerOrder="RotationOrder"in t?w(t.RotationOrder.value):"ZYX","Lcl_Translation"in t&&(r.translation=t.Lcl_Translation.value),"PreRotation"in t&&(r.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(r.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(r.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(r.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(r.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(r.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(r.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(r.rotationPivot=t.RotationPivot.value),e.userData.transformData=r}setLookAtProperties(e,t){if("LookAtProperty"in t){a.get(e.ID).children.forEach((function(t){if("LookAtProperty"===t.relationship){const r=s.Objects.Model[t.ID];if("Lcl_Translation"in r){const t=r.Lcl_Translation.value;void 0!==e.target?(e.target.position.fromArray(t),i.add(e.target)):e.lookAt((new THREE.Vector3).fromArray(t))}}}))}}bindSkeleton(e,t,r){const n=this.parsePoseNodes();for(const o in e){const s=e[o];a.get(parseInt(s.ID)).parents.forEach((function(e){if(t.has(e.ID)){const t=e.ID;a.get(t).parents.forEach((function(e){if(r.has(e.ID)){r.get(e.ID).bind(new THREE.SkeletonEx(s.bones),n[e.ID])}}))}}))}}parsePoseNodes(){const e={};if("Pose"in s.Objects){const t=s.Objects.Pose;for(const r in t)if("BindPose"===t[r].attrType&&t[r].NbPoseNodes>0){const n=t[r].PoseNode;Array.isArray(n)?n.forEach((function(t){e[t.Node]=(new THREE.Matrix4).fromArray(t.Matrix.a)})):e[n.Node]=(new THREE.Matrix4).fromArray(n.Matrix.a)}}return e}addGlobalSceneSettings(){if("GlobalSettings"in s){if("AmbientColor"in s.GlobalSettings){const e=s.GlobalSettings.AmbientColor.value,t=e[0],r=e[1],n=e[2];if(0!==t||0!==r||0!==n){const e=new THREE.Color(t,r,n).convertSRGBToLinear();i.add(new THREE.AmbientLight(e,1))}}"UnitScaleFactor"in s.GlobalSettings&&(i.userData.unitScaleFactor=s.GlobalSettings.UnitScaleFactor.value)}}}class u{constructor(){this.negativeMaterialIndices=!1}parse(e){const t=new Map;if("Geometry"in s.Objects){const r=s.Objects.Geometry;for(const n in r){const o=a.get(parseInt(n)),s=this.parseGeometry(o,r[n],e);t.set(parseInt(n),s)}}return!0===this.negativeMaterialIndices&&console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."),t}parseGeometry(e,t,r){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,r);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,r){const n=r.skeletons,o=[],a=e.parents.map((function(e){return s.Objects.Model[e.ID]}));if(0===a.length)return;const i=e.children.reduce((function(e,t){return void 0!==n[t.ID]&&(e=n[t.ID]),e}),null);e.children.forEach((function(e){void 0!==r.morphTargets[e.ID]&&o.push(r.morphTargets[e.ID])}));const l=a[0],c={};"RotationOrder"in l&&(c.eulerOrder=w(l.RotationOrder.value)),"InheritType"in l&&(c.inheritType=parseInt(l.InheritType.value)),"GeometricTranslation"in l&&(c.translation=l.GeometricTranslation.value),"GeometricRotation"in l&&(c.rotation=l.GeometricRotation.value),"GeometricScaling"in l&&(c.scale=l.GeometricScaling.value);const u=x(c);return this.genGeometry(t,i,o,u)}genGeometry(e,t,r,n){const o=new THREE.BufferGeometry;e.attrName&&(o.name=e.attrName);const s=this.parseGeoNode(e,t),a=this.genBuffers(s),i=new THREE.Float32BufferAttribute(a.vertex,3);if(i.applyMatrix4(n),o.setAttribute("position",i),a.colors.length>0&&o.setAttribute("color",new THREE.Float32BufferAttribute(a.colors,3)),t&&(o.setAttribute("skinIndex",new THREE.Uint16BufferAttribute(a.weightsIndices,4)),o.setAttribute("skinWeight",new THREE.Float32BufferAttribute(a.vertexWeights,4)),o.FBX_Deformer=t),a.normal.length>0){const e=(new THREE.Matrix3).getNormalMatrix(n),t=new THREE.Float32BufferAttribute(a.normal,3);t.applyNormalMatrix(e),o.setAttribute("normal",t)}if(a.uvs.forEach((function(e,t){const r=0===t?"uv":`uv${t}`;o.setAttribute(r,new THREE.Float32BufferAttribute(a.uvs[t],2))})),s.material&&"AllSame"!==s.material.mappingType){let e=a.materialIndex[0],t=0;if(a.materialIndex.forEach((function(r,n){r!==e&&(o.addGroup(t,n-t,e),e=r,t=n)})),o.groups.length>0){const t=o.groups[o.groups.length-1],r=t.start+t.count;r!==a.materialIndex.length&&o.addGroup(r,a.materialIndex.length-r,e)}0===o.groups.length&&o.addGroup(0,a.materialIndex.length,a.materialIndex[0])}return this.addMorphTargets(o,e,r,n),o}parseGeoNode(e,t){const r={};if(r.vertexPositions=void 0!==e.Vertices?e.Vertices.a:[],r.vertexIndices=void 0!==e.PolygonVertexIndex?e.PolygonVertexIndex.a:[],e.LayerElementColor&&(r.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(r.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(r.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){r.uv=[];let t=0;for(;e.LayerElementUV[t];)e.LayerElementUV[t].UV&&r.uv.push(this.parseUVs(e.LayerElementUV[t])),t++}return r.weightTable={},null!==t&&(r.skeleton=t,t.rawBones.forEach((function(e,t){e.indices.forEach((function(n,o){void 0===r.weightTable[n]&&(r.weightTable[n]=[]),r.weightTable[n].push({id:t,weight:e.weights[o]})}))}))),r}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let r=0,n=0,o=!1,s=[],a=[],i=[],l=[],c=[],u=[];const p=this;return e.vertexIndices.forEach((function(h,d){let f,m=!1;h<0&&(h^=-1,m=!0);let E=[],g=[];if(s.push(3*h,3*h+1,3*h+2),e.color){const t=v(d,r,h,e.color);i.push(t[0],t[1],t[2])}if(e.skeleton){if(void 0!==e.weightTable[h]&&e.weightTable[h].forEach((function(e){g.push(e.weight),E.push(e.id)})),g.length>4){o||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),o=!0);const e=[0,0,0,0],t=[0,0,0,0];g.forEach((function(r,n){let o=r,s=E[n];t.forEach((function(t,r,n){if(o>t){n[r]=o,o=t;const a=e[r];e[r]=s,s=a}}))})),E=e,g=t}for(;g.length<4;)g.push(0),E.push(0);for(let e=0;e<4;++e)c.push(g[e]),u.push(E[e])}if(e.normal){const t=v(d,r,h,e.normal);a.push(t[0],t[1],t[2])}e.material&&"AllSame"!==e.material.mappingType&&(f=v(d,r,h,e.material)[0],f<0&&(p.negativeMaterialIndices=!0,f=0)),e.uv&&e.uv.forEach((function(e,t){const n=v(d,r,h,e);void 0===l[t]&&(l[t]=[]),l[t].push(n[0]),l[t].push(n[1])})),n++,m&&(p.genFace(t,e,s,f,a,i,l,c,u,n),r++,n=0,s=[],a=[],i=[],l=[],c=[],u=[])})),t}getNormalNewell(e){const t=new THREE.Vector3(0,0,0);for(let r=0;r<e.length;r++){const n=e[r],o=e[(r+1)%e.length];t.x+=(n.y-o.y)*(n.z+o.z),t.y+=(n.z-o.z)*(n.x+o.x),t.z+=(n.x-o.x)*(n.y+o.y)}return t.normalize(),t}getNormalTangentAndBitangent(e){const t=this.getNormalNewell(e),r=(Math.abs(t.z)>.5?new THREE.Vector3(0,1,0):new THREE.Vector3(0,0,1)).cross(t).normalize(),n=t.clone().cross(r).normalize();return{normal:t,tangent:r,bitangent:n}}flattenVertex(e,t,r){return new THREE.Vector2(e.dot(t),e.dot(r))}genFace(e,t,r,n,o,s,a,i,l,c){let u;if(c>3){const e=[];for(let n=0;n<r.length;n+=3)e.push(new THREE.Vector3(t.vertexPositions[r[n]],t.vertexPositions[r[n+1]],t.vertexPositions[r[n+2]]));const{tangent:n,bitangent:o}=this.getNormalTangentAndBitangent(e),s=[];for(const t of e)s.push(this.flattenVertex(t,n,o));u=THREE.ShapeUtils.triangulateShape(s,[])}else u=[[0,1,2]];for(const[c,p,h]of u)e.vertex.push(t.vertexPositions[r[3*c]]),e.vertex.push(t.vertexPositions[r[3*c+1]]),e.vertex.push(t.vertexPositions[r[3*c+2]]),e.vertex.push(t.vertexPositions[r[3*p]]),e.vertex.push(t.vertexPositions[r[3*p+1]]),e.vertex.push(t.vertexPositions[r[3*p+2]]),e.vertex.push(t.vertexPositions[r[3*h]]),e.vertex.push(t.vertexPositions[r[3*h+1]]),e.vertex.push(t.vertexPositions[r[3*h+2]]),t.skeleton&&(e.vertexWeights.push(i[4*c]),e.vertexWeights.push(i[4*c+1]),e.vertexWeights.push(i[4*c+2]),e.vertexWeights.push(i[4*c+3]),e.vertexWeights.push(i[4*p]),e.vertexWeights.push(i[4*p+1]),e.vertexWeights.push(i[4*p+2]),e.vertexWeights.push(i[4*p+3]),e.vertexWeights.push(i[4*h]),e.vertexWeights.push(i[4*h+1]),e.vertexWeights.push(i[4*h+2]),e.vertexWeights.push(i[4*h+3]),e.weightsIndices.push(l[4*c]),e.weightsIndices.push(l[4*c+1]),e.weightsIndices.push(l[4*c+2]),e.weightsIndices.push(l[4*c+3]),e.weightsIndices.push(l[4*p]),e.weightsIndices.push(l[4*p+1]),e.weightsIndices.push(l[4*p+2]),e.weightsIndices.push(l[4*p+3]),e.weightsIndices.push(l[4*h]),e.weightsIndices.push(l[4*h+1]),e.weightsIndices.push(l[4*h+2]),e.weightsIndices.push(l[4*h+3])),t.color&&(e.colors.push(s[3*c]),e.colors.push(s[3*c+1]),e.colors.push(s[3*c+2]),e.colors.push(s[3*p]),e.colors.push(s[3*p+1]),e.colors.push(s[3*p+2]),e.colors.push(s[3*h]),e.colors.push(s[3*h+1]),e.colors.push(s[3*h+2])),t.material&&"AllSame"!==t.material.mappingType&&(e.materialIndex.push(n),e.materialIndex.push(n),e.materialIndex.push(n)),t.normal&&(e.normal.push(o[3*c]),e.normal.push(o[3*c+1]),e.normal.push(o[3*c+2]),e.normal.push(o[3*p]),e.normal.push(o[3*p+1]),e.normal.push(o[3*p+2]),e.normal.push(o[3*h]),e.normal.push(o[3*h+1]),e.normal.push(o[3*h+2])),t.uv&&t.uv.forEach((function(t,r){void 0===e.uvs[r]&&(e.uvs[r]=[]),e.uvs[r].push(a[r][2*c]),e.uvs[r].push(a[r][2*c+1]),e.uvs[r].push(a[r][2*p]),e.uvs[r].push(a[r][2*p+1]),e.uvs[r].push(a[r][2*h]),e.uvs[r].push(a[r][2*h+1])}))}addMorphTargets(e,t,r,n){if(0===r.length)return;e.morphTargetsRelative=!0,e.morphAttributes.position=[];const o=this;r.forEach((function(r){r.rawTargets.forEach((function(r){const a=s.Objects.Geometry[r.geoID];void 0!==a&&o.genMorphGeometry(e,t,a,n,r.name)}))}))}genMorphGeometry(e,t,r,n,o){const s=void 0!==t.PolygonVertexIndex?t.PolygonVertexIndex.a:[],a=void 0!==r.Vertices?r.Vertices.a:[],i=void 0!==r.Indexes?r.Indexes.a:[],l=3*e.attributes.position.count,c=new Float32Array(l);for(let e=0;e<i.length;e++){const t=3*i[e];c[t]=a[3*e],c[t+1]=a[3*e+1],c[t+2]=a[3*e+2]}const u={vertexIndices:s,vertexPositions:c},p=this.genBuffers(u),h=new THREE.Float32BufferAttribute(p.vertex,3);h.name=o||r.attrName,h.applyMatrix4(n),e.morphAttributes.position.push(h)}parseNormals(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.Normals.a;let o=[];return"IndexToDirect"===r&&("NormalIndex"in e?o=e.NormalIndex.a:"NormalsIndex"in e&&(o=e.NormalsIndex.a)),{dataSize:3,buffer:n,indices:o,mappingType:t,referenceType:r}}parseUVs(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.UV.a;let o=[];return"IndexToDirect"===r&&(o=e.UVIndex.a),{dataSize:2,buffer:n,indices:o,mappingType:t,referenceType:r}}parseVertexColors(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.Colors.a;let o=[];"IndexToDirect"===r&&(o=e.ColorIndex.a);for(let e=0,t=new THREE.Color;e<n.length;e+=4)t.fromArray(n,e).convertSRGBToLinear().toArray(n,e);return{dataSize:4,buffer:n,indices:o,mappingType:t,referenceType:r}}parseMaterialIndices(e){const t=e.MappingInformationType,r=e.ReferenceInformationType;if("NoMappingInformation"===t)return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:r};const n=e.Materials.a,o=[];for(let e=0;e<n.length;++e)o.push(e);return{dataSize:1,buffer:n,indices:o,mappingType:t,referenceType:r}}parseNurbsGeometry(e){const t=parseInt(e.Order);if(isNaN(t))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",e.Order,e.id),new THREE.BufferGeometry;const r=t-1,n=e.KnotVector.a,s=[],a=e.Points.a;for(let e=0,t=a.length;e<t;e+=4)s.push((new THREE.Vector4).fromArray(a,e));let i,l;if("Closed"===e.Form)s.push(s[0]);else if("Periodic"===e.Form){i=r,l=n.length-1-i;for(let e=0;e<r;++e)s.push(s[e])}const c=new o(r,n,s,i,l).getPoints(12*s.length);return(new THREE.BufferGeometry).setFromPoints(c)}}class p{parse(){const e=[],t=this.parseClips();if(void 0!==t)for(const r in t){const n=t[r],o=this.addClip(n);e.push(o)}return e}parseClips(){if(void 0===s.Objects.AnimationCurve)return;const e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);const t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}parseAnimationCurveNodes(){const e=s.Objects.AnimationCurveNode,t=new Map;for(const r in e){const n=e[r];if(null!==n.attrName.match(/S|R|T|DeformPercent/)){const e={id:n.id,attr:n.attrName,curves:{}};t.set(e.id,e)}}return t}parseAnimationCurves(e){const t=s.Objects.AnimationCurve;for(const r in t){const n={id:t[r].id,times:t[r].KeyTime.a.map(g),values:t[r].KeyValueFloat.a},o=a.get(n.id);if(void 0!==o){const t=o.parents[0].ID,r=o.parents[0].relationship;r.match(/X/)?e.get(t).curves.x=n:r.match(/Y/)?e.get(t).curves.y=n:r.match(/Z/)?e.get(t).curves.z=n:r.match(/DeformPercent/)&&e.has(t)&&(e.get(t).curves.morph=n)}}}parseAnimationLayers(e){const t=s.Objects.AnimationLayer,r=new Map;for(const n in t){const t=[],o=a.get(parseInt(n));if(void 0!==o){o.children.forEach((function(r,n){if(e.has(r.ID)){const o=e.get(r.ID);if(void 0!==o.curves.x||void 0!==o.curves.y||void 0!==o.curves.z){if(void 0===t[n]){const e=a.get(r.ID).parents.filter((function(e){return void 0!==e.relationship}))[0].ID;if(void 0!==e){const o=s.Objects.Model[e.toString()];if(void 0===o)return void console.warn("THREE.FBXLoader: Encountered a unused curve.",r);const a={modelName:o.attrName?THREE.PropertyBinding.sanitizeNodeName(o.attrName):"",ID:o.id,initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1]};i.traverse((function(e){e.ID===o.id&&(a.transform=e.matrix,e.userData.transformData&&(a.eulerOrder=e.userData.transformData.eulerOrder))})),a.transform||(a.transform=new THREE.Matrix4),"PreRotation"in o&&(a.preRotation=o.PreRotation.value),"PostRotation"in o&&(a.postRotation=o.PostRotation.value),t[n]=a}}t[n]&&(t[n][o.attr]=o)}else if(void 0!==o.curves.morph){if(void 0===t[n]){const e=a.get(r.ID).parents.filter((function(e){return void 0!==e.relationship}))[0].ID,o=a.get(e).parents[0].ID,i=a.get(o).parents[0].ID,l=a.get(i).parents[0].ID,c=s.Objects.Model[l],u={modelName:c.attrName?THREE.PropertyBinding.sanitizeNodeName(c.attrName):"",morphName:s.Objects.Deformer[e].attrName};t[n]=u}t[n][o.attr]=o}}})),r.set(parseInt(n),t)}}return r}parseAnimStacks(e){const t=s.Objects.AnimationStack,r={};for(const n in t){const o=a.get(parseInt(n)).children;o.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const s=e.get(o[0].ID);r[n]={name:t[n].attrName,layer:s}}return r}addClip(e){let t=[];const r=this;return e.layer.forEach((function(e){t=t.concat(r.generateTracks(e))})),new THREE.AnimationClip(e.name,-1,t)}generateTracks(e){const t=[];let r=new THREE.Vector3,n=new THREE.Quaternion,o=new THREE.Vector3;if(e.transform&&e.transform.decompose(r,new THREE.Quaternion,o),r=r.toArray(),n=(new THREE.Euler).setFromQuaternion(n,e.eulerOrder).toArray(),o=o.toArray(),void 0!==e.T&&Object.keys(e.T.curves).length>0){const n=this.generateVectorTrack(e.modelName,e.T.curves,r,"position");void 0!==n&&t.push(n)}if(void 0!==e.R&&Object.keys(e.R.curves).length>0){const r=this.generateRotationTrack(e.modelName,e.R.curves,n,e.preRotation,e.postRotation,e.eulerOrder);void 0!==r&&t.push(r)}if(void 0!==e.S&&Object.keys(e.S.curves).length>0){const r=this.generateVectorTrack(e.modelName,e.S.curves,o,"scale");void 0!==r&&t.push(r)}if(void 0!==e.DeformPercent){const r=this.generateMorphTrack(e);void 0!==r&&t.push(r)}return t}generateVectorTrack(e,t,r,n){const o=this.getTimesForAllAxes(t),s=this.getKeyframeTrackValues(o,t,r);return new THREE.VectorKeyframeTrack(e+"."+n,o,s)}generateRotationTrack(e,t,r,n,o,s){void 0!==t.x&&(this.interpolateRotations2(t.x),t.x.values=t.x.values.map(THREE.MathUtils.degToRad)),void 0!==t.y&&(this.interpolateRotations2(t.y),t.y.values=t.y.values.map(THREE.MathUtils.degToRad)),void 0!==t.z&&(this.interpolateRotations2(t.z),t.z.values=t.z.values.map(THREE.MathUtils.degToRad));const a=this.getTimesForAllAxes(t),i=this.getKeyframeTrackValues(a,t,r);void 0!==n&&((n=n.map(THREE.MathUtils.degToRad)).push(s),n=(new THREE.Euler).fromArray(n),n=(new THREE.Quaternion).setFromEuler(n)),void 0!==o&&((o=o.map(THREE.MathUtils.degToRad)).push(s),o=(new THREE.Euler).fromArray(o),o=(new THREE.Quaternion).setFromEuler(o).invert());const l=new THREE.Quaternion,c=new THREE.Euler,u=[];for(let e=0;e<i.length;e+=3)c.set(i[e],i[e+1],i[e+2],s),l.setFromEuler(c),void 0!==n&&l.premultiply(n),void 0!==o&&l.multiply(o),l.toArray(u,e/3*4);return new THREE.QuaternionKeyframeTrack(e+".quaternion",a,u)}generateMorphTrack(e){const t=e.DeformPercent.curves.morph,r=t.values.map((function(e){return e/100})),n=i.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new THREE.NumberKeyframeTrack(e.modelName+".morphTargetInfluences["+n+"]",t.times,r)}getTimesForAllAxes(e){let t=[];if(void 0!==e.x&&(t=t.concat(e.x.times)),void 0!==e.y&&(t=t.concat(e.y.times)),void 0!==e.z&&(t=t.concat(e.z.times)),t=t.sort((function(e,t){return e-t})),t.length>1){let e=1,r=t[0];for(let n=1;n<t.length;n++){const o=t[n];o!==r&&(t[e]=o,r=o,e++)}t=t.slice(0,e)}return t}getKeyframeTrackValues(e,t,r){const n=r,o=[];let s=-1,a=-1,i=-1;return e.forEach((function(e){if(t.x&&(s=t.x.times.indexOf(e)),t.y&&(a=t.y.times.indexOf(e)),t.z&&(i=t.z.times.indexOf(e)),-1!==s){const e=t.x.values[s];o.push(e),n[0]=e}else o.push(n[0]);if(-1!==a){const e=t.y.values[a];o.push(e),n[1]=e}else o.push(n[1]);if(-1!==i){const e=t.z.values[i];o.push(e),n[2]=e}else o.push(n[2])})),o}interpolateRotations(e,t,r,n){const o=[],s=[];o.push(e.times[0]),s.push(THREE.MathUtils.degToRad(e.values[0])),s.push(THREE.MathUtils.degToRad(t.values[0])),s.push(THREE.MathUtils.degToRad(r.values[0]));for(let a=1;a<e.values.length;a++){const i=[e.values[a-1],t.values[a-1],r.values[a-1]];if(isNaN(i[0])||isNaN(i[1])||isNaN(i[2]))continue;const l=i.map(THREE.MathUtils.degToRad),c=[e.values[a],t.values[a],r.values[a]];if(isNaN(c[0])||isNaN(c[1])||isNaN(c[2]))continue;const u=c.map(THREE.MathUtils.degToRad),p=[c[0]-i[0],c[1]-i[1],c[2]-i[2]],h=[Math.abs(p[0]),Math.abs(p[1]),Math.abs(p[2])];if(h[0]>=180||h[1]>=180||h[2]>=180){const t=Math.max(...h)/180,r=new THREE.Euler(...l,n),i=new THREE.Euler(...u,n),c=(new THREE.Quaternion).setFromEuler(r),p=(new THREE.Quaternion).setFromEuler(i);c.dot(p)&&p.set(-p.x,-p.y,-p.z,-p.w);const d=e.times[a-1],f=e.times[a]-d,m=new THREE.Quaternion,E=new THREE.Euler;for(let e=0;e<1;e+=1/t)m.copy(c.clone().slerp(p.clone(),e)),o.push(d+e*f),E.setFromQuaternion(m,n),s.push(E.x),s.push(E.y),s.push(E.z)}else o.push(e.times[a]),s.push(THREE.MathUtils.degToRad(e.values[a])),s.push(THREE.MathUtils.degToRad(t.values[a])),s.push(THREE.MathUtils.degToRad(r.values[a]))}return[o,s]}interpolateRotations2(e){for(let t=1;t<e.values.length;t++){const r=e.values[t-1],n=e.values[t]-r,o=Math.abs(n);if(o>=180){const s=o/180,a=n/s;let i=r+a;const l=e.times[t-1],c=(e.times[t]-l)/s;let u=l+c;const p=[],h=[];for(;u<e.times[t];)p.push(u),u+=c,h.push(i),i+=a;e.times=H(e.times,t,p),e.values=H(e.values,t,h)}}}}class h{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new m,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,r=e.split(/[\r\n]+/);return r.forEach((function(e,n){const o=e.match(/^[\s\t]*;/),s=e.match(/^[\s\t]*$/);if(o||s)return;const a=e.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),i=e.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),l=e.match("^\\t{"+(t.currentIndent-1)+"}}");a?t.parseNodeBegin(e,a):i?t.parseNodeProperty(e,i,r[++n]):l?t.popStack():e.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(e)})),this.allNodes}parseNodeBegin(e,t){const r=t[1].trim().replace(/^"/,"").replace(/"$/,""),n=t[2].split(",").map((function(e){return e.trim().replace(/^"/,"").replace(/"$/,"")})),o={name:r},s=this.parseNodeAttr(n),a=this.getCurrentNode();0===this.currentIndent?this.allNodes.add(r,o):r in a?("PoseNode"===r?a.PoseNode.push(o):void 0!==a[r].id&&(a[r]={},a[r][a[r].id]=a[r]),""!==s.id&&(a[r][s.id]=o)):"number"==typeof s.id?(a[r]={},a[r][s.id]=o):"Properties70"!==r&&(a[r]="PoseNode"===r?[o]:o),"number"==typeof s.id&&(o.id=s.id),""!==s.name&&(o.attrName=s.name),""!==s.type&&(o.attrType=s.type),this.pushStack(o)}parseNodeAttr(e){let t=e[0];""!==e[0]&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let r="",n="";return e.length>1&&(r=e[1].replace(/^(\w+)::/,""),n=e[2]),{id:t,name:r,type:n}}parseNodeProperty(e,t,r){let n=t[1].replace(/^"/,"").replace(/"$/,"").trim(),o=t[2].replace(/^"/,"").replace(/"$/,"").trim();"Content"===n&&","===o&&(o=r.replace(/"/g,"").replace(/,$/,"").trim());const s=this.getCurrentNode();if("Properties70"!==s.name){if("C"===n){const e=o.split(",").slice(1),t=parseInt(e[0]),r=parseInt(e[1]);let a=o.split(",").slice(3);a=a.map((function(e){return e.trim().replace(/^"/,"")})),n="connections",o=[t,r],function(e,t){for(let r=0,n=e.length,o=t.length;r<o;r++,n++)e[n]=t[r]}(o,a),void 0===s[n]&&(s[n]=[])}"Node"===n&&(s.id=o),n in s&&Array.isArray(s[n])?s[n].push(o):"a"!==n?s[n]=o:s.a=o,this.setCurrentProp(s,n),"a"===n&&","!==o.slice(-1)&&(s.a=b(o))}else this.parseNodeSpecialProperty(e,n,o)}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,","!==e.slice(-1)&&(t.a=b(t.a))}parseNodeSpecialProperty(e,t,r){const n=r.split('",').map((function(e){return e.trim().replace(/^\"/,"").replace(/\s/,"_")})),o=n[0],s=n[1],a=n[2],i=n[3];let l=n[4];switch(s){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":l=parseFloat(l);break;case"THREE.Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":l=b(l)}this.getPrevNode()[o]={type:s,type2:a,flag:i,value:l},this.setCurrentProp(this.getPrevNode(),o)}}class d{parse(e){const t=new f(e);t.skip(23);const r=t.getUint32();if(r<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+r);const n=new m;for(;!this.endOfContent(t);){const e=this.parseNode(t,r);null!==e&&n.add(e.name,e)}return n}endOfContent(e){return e.size()%16==0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const r={},n=t>=7500?e.getUint64():e.getUint32(),o=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const s=e.getUint8(),a=e.getString(s);if(0===n)return null;const i=[];for(let t=0;t<o;t++)i.push(this.parseProperty(e));const l=i.length>0?i[0]:"",c=i.length>1?i[1]:"",u=i.length>2?i[2]:"";for(r.singleProperty=1===o&&e.getOffset()===n;n>e.getOffset();){const n=this.parseNode(e,t);null!==n&&this.parseSubNode(a,r,n)}return r.propertyList=i,"number"==typeof l&&(r.id=l),""!==c&&(r.attrName=c),""!==u&&(r.attrType=u),""!==a&&(r.name=a),r}parseSubNode(e,t,r){if(!0===r.singleProperty){const e=r.propertyList[0];Array.isArray(e)?(t[r.name]=r,r.a=e):t[r.name]=e}else if("Connections"===e&&"C"===r.name){const e=[];r.propertyList.forEach((function(t,r){0!==r&&e.push(t)})),void 0===t.connections&&(t.connections=[]),t.connections.push(e)}else if("Properties70"===r.name){Object.keys(r).forEach((function(e){t[e]=r[e]}))}else if("Properties70"===e&&"P"===r.name){let e=r.propertyList[0],n=r.propertyList[1];const o=r.propertyList[2],s=r.propertyList[3];let a;0===e.indexOf("Lcl ")&&(e=e.replace("Lcl ","Lcl_")),0===n.indexOf("Lcl ")&&(n=n.replace("Lcl ","Lcl_")),a="THREE.Color"===n||"ColorRGB"===n||"Vector"===n||"Vector3D"===n||0===n.indexOf("Lcl_")?[r.propertyList[4],r.propertyList[5],r.propertyList[6]]:r.propertyList[4],t[e]={type:n,type2:o,flag:s,value:a}}else void 0===t[r.name]?"number"==typeof r.id?(t[r.name]={},t[r.name][r.id]=r):t[r.name]=r:"PoseNode"===r.name?(Array.isArray(t[r.name])||(t[r.name]=[t[r.name]]),t[r.name].push(r)):void 0===t[r.name][r.id]&&(t[r.name][r.id]=r)}parseProperty(e){const t=e.getString(1);let r;switch(t){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return r=e.getUint32(),e.getArrayBuffer(r);case"S":return r=e.getUint32(),e.getString(r);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const n=e.getUint32(),o=e.getUint32(),s=e.getUint32();if(0===o)switch(t){case"b":case"c":return e.getBooleanArray(n);case"d":return e.getFloat64Array(n);case"f":return e.getFloat32Array(n);case"i":return e.getInt32Array(n);case"l":return e.getInt64Array(n)}const a=fflate.unzlibSync(new Uint8Array(e.getArrayBuffer(s))),i=new f(a.buffer);switch(t){case"b":case"c":return i.getBooleanArray(n);case"d":return i.getFloat64Array(n);case"f":return i.getFloat32Array(n);case"i":return i.getInt32Array(n);case"l":return i.getInt64Array(n)}break;default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}}class f{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=void 0===t||t,this._textDecoder=new TextDecoder}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return 1==(1&this.getUint8())}getBooleanArray(e){const t=[];for(let r=0;r<e;r++)t.push(this.getBoolean());return t}getUint8(){const e=this.dv.getUint8(this.offset);return this.offset+=1,e}getInt16(){const e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}getInt32(){const e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}getInt32Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getInt32());return t}getUint32(){const e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}getInt64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),2147483648&t?(t=4294967295&~t,e=4294967295&~e,4294967295===e&&(t=t+1&4294967295),e=e+1&4294967295,-(4294967296*t+e)):4294967296*t+e}getInt64Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getInt64());return t}getUint64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),4294967296*t+e}getFloat32(){const e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}getFloat32Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getFloat32());return t}getFloat64(){const e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}getFloat64Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getFloat64());return t}getArrayBuffer(e){const t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}getString(e){const t=this.offset;let r=new Uint8Array(this.dv.buffer,t,e);this.skip(e);const n=r.indexOf(0);return n>=0&&(r=new Uint8Array(this.dv.buffer,t,n)),this._textDecoder.decode(r)}}class m{add(e,t){this[e]=t}}function E(e){const t=e.match(/FBXVersion: (\d+)/);if(t){return parseInt(t[1])}throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function g(e){return e/46186158e3}const T=[];function v(e,t,r,n){let o;switch(n.mappingType){case"ByPolygonVertex":o=e;break;case"ByPolygon":o=t;break;case"ByVertice":o=r;break;case"AllSame":o=n.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+n.mappingType)}"IndexToDirect"===n.referenceType&&(o=n.indices[o]);const s=o*n.dataSize,a=s+n.dataSize;return function(e,t,r,n){for(let o=r,s=0;o<n;o++,s++)e[s]=t[o];return e}(T,n.buffer,s,a)}const y=new THREE.Euler,R=new THREE.Vector3;function x(e){const t=new THREE.Matrix4,r=new THREE.Matrix4,n=new THREE.Matrix4,o=new THREE.Matrix4,s=new THREE.Matrix4,a=new THREE.Matrix4,i=new THREE.Matrix4,l=new THREE.Matrix4,c=new THREE.Matrix4,u=new THREE.Matrix4,p=new THREE.Matrix4,h=new THREE.Matrix4,d=e.inheritType?e.inheritType:0;if(e.translation&&t.setPosition(R.fromArray(e.translation)),e.preRotation){const t=e.preRotation.map(THREE.MathUtils.degToRad);t.push(e.eulerOrder||THREE.Euler.DEFAULT_ORDER),r.makeRotationFromEuler(y.fromArray(t))}if(e.rotation){const t=e.rotation.map(THREE.MathUtils.degToRad);t.push(e.eulerOrder||THREE.Euler.DEFAULT_ORDER),n.makeRotationFromEuler(y.fromArray(t))}if(e.postRotation){const t=e.postRotation.map(THREE.MathUtils.degToRad);t.push(e.eulerOrder||THREE.Euler.DEFAULT_ORDER),o.makeRotationFromEuler(y.fromArray(t)),o.invert()}e.scale&&s.scale(R.fromArray(e.scale)),e.scalingOffset&&i.setPosition(R.fromArray(e.scalingOffset)),e.scalingPivot&&a.setPosition(R.fromArray(e.scalingPivot)),e.rotationOffset&&l.setPosition(R.fromArray(e.rotationOffset)),e.rotationPivot&&c.setPosition(R.fromArray(e.rotationPivot)),e.parentMatrixWorld&&(p.copy(e.parentMatrix),u.copy(e.parentMatrixWorld));const f=r.clone().multiply(n).multiply(o),m=new THREE.Matrix4;m.extractRotation(u);const E=new THREE.Matrix4;E.copyPosition(u);const g=E.clone().invert().multiply(u),T=m.clone().invert().multiply(g),v=s,x=new THREE.Matrix4;if(0===d)x.copy(m).multiply(f).multiply(T).multiply(v);else if(1===d)x.copy(m).multiply(T).multiply(f).multiply(v);else{const e=(new THREE.Matrix4).scale((new THREE.Vector3).setFromMatrixScale(p)).clone().invert(),t=T.clone().multiply(e);x.copy(m).multiply(f).multiply(t).multiply(v)}const w=c.clone().invert(),b=a.clone().invert();let I=t.clone().multiply(l).multiply(c).multiply(r).multiply(n).multiply(o).multiply(w).multiply(i).multiply(a).multiply(s).multiply(b);const H=(new THREE.Matrix4).copyPosition(I),M=u.clone().multiply(H);return h.copyPosition(M),I=h.clone().multiply(x),I.premultiply(u.invert()),I}function w(e){const t=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return 6===(e=e||0)?(console.warn("THREE.FBXLoader: unsupported THREE.Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),t[0]):t[e]}function b(e){return e.split(",").map((function(e){return parseFloat(e)}))}function I(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=e.byteLength),(new TextDecoder).decode(new Uint8Array(e,t,r))}function H(e,t,r){return e.slice(0,t).concat(r).concat(e.slice(t))}THREE.FBXLoader=l}();