aframe-extras.loaders.min.js 51 KB

1
  1. !function e(t,r,n){function a(o,s){if(!r[o]){if(!t[o]){var c="function"==typeof require&&require;if(!s&&c)return c(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[o]={exports:{}};t[o][0].call(l.exports,function(e){var r=t[o][1][e];return a(r||e)},l,l.exports,e,t,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o<n.length;o++)a(n[o]);return a}({1:[function(e,t,r){"use strict";e("./src/loaders")},{"./src/loaders":8}],2:[function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a="function"==typeof Symbol&&"symbol"===n(Symbol.iterator)?function(e){return void 0===e?"undefined":n(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":n(e)};THREE.LoaderUtils={extractUrlBase:THREE.Loader.prototype.extractUrlBase,decodeText:function(e){return(new TextDecoder).decode(e)}},t.exports=THREE.FBXLoader=function(){function e(e){this.manager=void 0!==e?e:THREE.DefaultLoadingManager}function t(e){this.textureLoader=e}function r(){}function n(){}function i(){}function o(){}function s(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=void 0===t||t}function c(){}function u(e){var 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 l(e){return e/46186158e3}function p(e,t,r,n){var a;switch(n.mappingType){case"ByPolygonVertex":a=e;break;case"ByPolygon":a=t;break;case"ByVertice":a=r;break;case"AllSame":a=n.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+n.mappingType)}"IndexToDirect"===n.referenceType&&(a=n.indices[a]);var i=a*n.dataSize,o=i+n.dataSize;return function(e,t,r,n){for(var a=r,i=0;a<n;a++,i++)e[i]=t[a];return e}(T,n.buffer,i,o)}function f(e){var t=new THREE.Matrix4;I.set(0,0,0),x.identity();var r=h(e.eulerOrder?e.eulerOrder:0);if(e.translation&&I.fromArray(e.translation),e.rotationOffset&&I.add(w.fromArray(e.rotationOffset)),e.rotation){(n=e.rotation.map(THREE.Math.degToRad)).push(r),x.makeRotationFromEuler(b.fromArray(n))}if(e.preRotation){(n=e.preRotation.map(THREE.Math.degToRad)).push(r),R.makeRotationFromEuler(b.fromArray(n)),x.premultiply(R)}if(e.postRotation){var n=e.postRotation.map(THREE.Math.degToRad);n.push(r),R.makeRotationFromEuler(b.fromArray(n)),R.getInverse(R),x.multiply(R)}return e.scale&&t.scale(w.fromArray(e.scale)),t.setPosition(I),t.multiply(x),t}function h(e){var t=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return 6===e?(console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),t[0]):t[e]}function d(e){return e.split(",").map(function(e){return parseFloat(e)})}function m(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=e.byteLength),THREE.LoaderUtils.decodeText(new Uint8Array(e,t,r))}function v(e,t,r){return e.slice(0,t).concat(r).concat(e.slice(t))}var g,E,y;e.prototype={constructor:e,crossOrigin:"anonymous",load:function(e,t,r,n){var a=this,i=THREE.LoaderUtils.extractUrlBase(e),o=new THREE.FileLoader(this.manager);o.setResponseType("arraybuffer"),o.load(e,function(r){try{var o=a.parse(r,i);t(o)}catch(t){setTimeout(function(){n&&n(t),a.manager.itemError(e)},0)}},r,n)},setCrossOrigin:function(e){return this.crossOrigin=e,this},parse:function(e,r){if(function(e){var t="Kaydara FBX Binary \0";return e.byteLength>=t.length&&t===m(e,0,t.length)}(e))g=(new o).parse(e);else{var n=m(e);if(!function(e){function t(t){var r=e[t-1];return e=e.slice(n+t),n++,r}for(var r=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"],n=0,a=0;a<r.length;++a)if(t(1)===r[a])return!1;return!0}(n))throw new Error("THREE.FBXLoader: Unknown format.");if(u(n)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+u(n));g=(new i).parse(n)}return new t(new THREE.TextureLoader(this.manager).setPath(r).setCrossOrigin(this.crossOrigin)).parse(g)}},t.prototype={constructor:t,parse:function(){E=this.parseConnections();var e=this.parseImages(),t=this.parseTextures(e),n=this.parseMaterials(t),a=this.parseDeformers(),i=(new r).parse(a);return this.parseScene(a,i,n),y},parseConnections:function(){var e=new Map;if("Connections"in g){g.Connections.connections.forEach(function(t){var r=t[0],n=t[1],a=t[2];e.has(r)||e.set(r,{parents:[],children:[]});var i={ID:n,relationship:a};e.get(r).parents.push(i),e.has(n)||e.set(n,{parents:[],children:[]});var o={ID:r,relationship:a};e.get(n).children.push(o)})}return e},parseImages:function(){var e={},t={};if("Video"in g.Objects){var r=g.Objects.Video;for(var n in r){var a=r[n];if(e[c=parseInt(n)]=a.RelativeFilename||a.Filename,"Content"in a){var i=a.Content instanceof ArrayBuffer&&a.Content.byteLength>0,o="string"==typeof a.Content&&""!==a.Content;if(i||o){var s=this.parseImage(r[n]);t[a.RelativeFilename||a.Filename]=s}}}}for(var c in e){var u=e[c];void 0!==t[u]?e[c]=t[u]:e[c]=e[c].split("\\").pop()}return e},parseImage:function(e){var t,r=e.Content,n=e.RelativeFilename||e.Filename,a=n.slice(n.lastIndexOf(".")+1).toLowerCase();switch(a){case"bmp":t="image/bmp";break;case"jpg":case"jpeg":t="image/jpeg";break;case"png":t="image/png";break;case"tif":t="image/tiff";break;case"tga":if("function"!=typeof THREE.TGALoader)return void console.warn("FBXLoader: THREE.TGALoader is required to load TGA textures");null===THREE.Loader.Handlers.get(".tga")&&THREE.Loader.Handlers.add(/\.tga$/i,new THREE.TGALoader),t="image/tga";break;default:return void console.warn('FBXLoader: Image type "'+a+'" is not supported.')}if("string"==typeof r)return"data:"+t+";base64,"+r;var i=new Uint8Array(r);return window.URL.createObjectURL(new Blob([i],{type:t}))},parseTextures:function(e){var t=new Map;if("Texture"in g.Objects){var r=g.Objects.Texture;for(var n in r){var a=this.parseTexture(r[n],e);t.set(parseInt(n),a)}}return t},parseTexture:function(e,t){var r=this.loadTexture(e,t);r.ID=e.id,r.name=e.attrName;var n=e.WrapModeU,a=e.WrapModeV,i=void 0!==n?n.value:0,o=void 0!==a?a.value:0;if(r.wrapS=0===i?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,r.wrapT=0===o?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,"Scaling"in e){var s=e.Scaling.value;r.repeat.x=s[0],r.repeat.y=s[1]}return r},loadTexture:function(e,t){var r,n=this.textureLoader.path,a=E.get(e.id).children;void 0!==a&&a.length>0&&void 0!==t[a[0].ID]&&(0!==(r=t[a[0].ID]).indexOf("blob:")&&0!==r.indexOf("data:")||this.textureLoader.setPath(void 0));var i,o=e.FileName.slice(-3).toLowerCase();if("tga"===o){var s=THREE.Loader.Handlers.get(".tga");null===s?(console.warn("FBXLoader: TGALoader not found, creating empty placeholder texture for",r),i=new THREE.Texture):i=s.load(r)}else"psd"===o?(console.warn("FBXLoader: PSD textures are not supported, creating empty placeholder texture for",r),i=new THREE.Texture):i=this.textureLoader.load(r);return this.textureLoader.setPath(n),i},parseMaterials:function(e){var t=new Map;if("Material"in g.Objects){var r=g.Objects.Material;for(var n in r){var a=this.parseMaterial(r[n],e);null!==a&&t.set(parseInt(n),a)}}return t},parseMaterial:function(e,t){var r=e.id,n=e.attrName,i=e.ShadingModel;if("object"===(void 0===i?"undefined":a(i))&&(i=i.value),!E.has(r))return null;var o,s=this.parseParameters(e,t,r);switch(i.toLowerCase()){case"phong":o=new THREE.MeshPhongMaterial;break;case"lambert":o=new THREE.MeshLambertMaterial;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',i),o=new THREE.MeshPhongMaterial({color:3342591})}return o.setValues(s),o.name=n,o},parseParameters:function(e,t,r){var n={};e.BumpFactor&&(n.bumpScale=e.BumpFactor.value),e.Diffuse?n.color=(new THREE.Color).fromArray(e.Diffuse.value):e.DiffuseColor&&"Color"===e.DiffuseColor.type&&(n.color=(new THREE.Color).fromArray(e.DiffuseColor.value)),e.DisplacementFactor&&(n.displacementScale=e.DisplacementFactor.value),e.Emissive?n.emissive=(new THREE.Color).fromArray(e.Emissive.value):e.EmissiveColor&&"Color"===e.EmissiveColor.type&&(n.emissive=(new THREE.Color).fromArray(e.EmissiveColor.value)),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):e.SpecularColor&&"Color"===e.SpecularColor.type&&(n.specular=(new THREE.Color).fromArray(e.SpecularColor.value));var a=this;return E.get(r).children.forEach(function(e){var r=e.relationship;switch(r){case"Bump":n.bumpMap=a.getTexture(t,e.ID);break;case"DiffuseColor":n.map=a.getTexture(t,e.ID);break;case"DisplacementColor":n.displacementMap=a.getTexture(t,e.ID);break;case"EmissiveColor":n.emissiveMap=a.getTexture(t,e.ID);break;case"NormalMap":n.normalMap=a.getTexture(t,e.ID);break;case"ReflectionColor":n.envMap=a.getTexture(t,e.ID),n.envMap.mapping=THREE.EquirectangularReflectionMapping;break;case"SpecularColor":n.specularMap=a.getTexture(t,e.ID);break;case"TransparentColor":n.alphaMap=a.getTexture(t,e.ID),n.transparent=!0;break;case"AmbientColor":case"ShininessExponent":case"SpecularFactor":case"VectorDisplacementColor":default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",r)}}),n},getTexture:function(e,t){return"LayeredTexture"in g.Objects&&t in g.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=E.get(t).children[0].ID),e.get(t)},parseDeformers:function(){var e={},t={};if("Deformer"in g.Objects){var r=g.Objects.Deformer;for(var n in r){var a=r[n],i=E.get(parseInt(n));if("Skin"===a.attrType){var o=this.parseSkeleton(i,r);o.ID=n,i.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),o.geometryID=i.parents[0].ID,e[n]=o}else if("BlendShape"===a.attrType){var s={id:n};s.rawTargets=this.parseMorphTargets(i,r),s.id=n,i.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[n]=s}}}return{skeletons:e,morphTargets:t}},parseSkeleton:function(e,t){var r=[];return e.children.forEach(function(e){var n=t[e.ID];if("Cluster"===n.attrType){var a={ID:e.ID,indices:[],weights:[],transform:(new THREE.Matrix4).fromArray(n.Transform.a),transformLink:(new THREE.Matrix4).fromArray(n.TransformLink.a),linkMode:n.Mode};"Indexes"in n&&(a.indices=n.Indexes.a,a.weights=n.Weights.a),r.push(a)}}),{rawBones:r,bones:[]}},parseMorphTargets:function(e,t){for(var r=[],n=0;n<e.children.length;n++){if(8===n){console.warn("FBXLoader: maximum of 8 morph targets supported. Ignoring additional targets.");break}var a=e.children[n],i=t[a.ID],o={name:i.attrName,initialWeight:i.DeformPercent,id:i.id,fullWeights:i.FullWeights.a};if("BlendShapeChannel"!==i.attrType)return;E.get(parseInt(a.ID)).children.forEach(function(e){void 0===e.relationship&&(o.geoID=e.ID)}),r.push(o)}return r},parseScene:function(e,t,r){y=new THREE.Group;var a=this.parseModels(e.skeletons,t,r),i=g.Objects.Model,o=this;a.forEach(function(e){var t=i[e.ID];o.setLookAtProperties(e,t);E.get(e.ID).parents.forEach(function(t){var r=a.get(t.ID);void 0!==r&&r.add(e)}),null===e.parent&&y.add(e)}),this.bindSkeleton(e.skeletons,t,a),this.createAmbientLight(),this.setupMorphMaterials();var s=(new n).parse();1===y.children.length&&y.children[0].isGroup&&(y.children[0].animations=s,y=y.children[0]),y.animations=s},parseModels:function(e,t,r){var n=new Map,a=g.Objects.Model;for(var i in a){var o=parseInt(i),s=a[i],c=E.get(o),u=this.buildSkeleton(c,e,o,s.attrName);if(!u){switch(s.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"Null":default:u=new THREE.Group}u.name=THREE.PropertyBinding.sanitizeNodeName(s.attrName),u.ID=o}this.setModelTransforms(u,s),n.set(o,u)}return n},buildSkeleton:function(e,t,r,n){var a=null;return e.parents.forEach(function(e){for(var i in t){var o=t[i];o.rawBones.forEach(function(t,i){if(t.ID===e.ID){var s=a;(a=new THREE.Bone).matrixWorld.copy(t.transformLink),a.name=THREE.PropertyBinding.sanitizeNodeName(n),a.ID=r,o.bones[i]=a,null!==s&&a.add(s)}})}}),a},createCamera:function(e){var t,r;if(e.children.forEach(function(e){var t=g.Objects.NodeAttribute[e.ID];void 0!==t&&(r=t)}),void 0===r)t=new THREE.Object3D;else{var n=0;void 0!==r.CameraProjectionType&&1===r.CameraProjectionType.value&&(n=1);var a=1;void 0!==r.NearPlane&&(a=r.NearPlane.value/1e3);var i=1e3;void 0!==r.FarPlane&&(i=r.FarPlane.value/1e3);var o=window.innerWidth,s=window.innerHeight;void 0!==r.AspectWidth&&void 0!==r.AspectHeight&&(o=r.AspectWidth.value,s=r.AspectHeight.value);var c=o/s,u=45;void 0!==r.FieldOfView&&(u=r.FieldOfView.value);var l=r.FocalLength?r.FocalLength.value:null;switch(n){case 0:t=new THREE.PerspectiveCamera(u,c,a,i),null!==l&&t.setFocalLength(l);break;case 1:t=new THREE.OrthographicCamera(-o/2,o/2,s/2,-s/2,a,i);break;default:console.warn("THREE.FBXLoader: Unknown camera type "+n+"."),t=new THREE.Object3D}}return t},createLight:function(e){var t,r;if(e.children.forEach(function(e){var t=g.Objects.NodeAttribute[e.ID];void 0!==t&&(r=t)}),void 0===r)t=new THREE.Object3D;else{var n;n=void 0===r.LightType?0:r.LightType.value;var a=16777215;void 0!==r.Color&&(a=(new THREE.Color).fromArray(r.Color.value));var i=void 0===r.Intensity?1:r.Intensity.value/100;void 0!==r.CastLightOnObject&&0===r.CastLightOnObject.value&&(i=0);var o=0;void 0!==r.FarAttenuationEnd&&(o=void 0!==r.EnableFarAttenuation&&0===r.EnableFarAttenuation.value?0:r.FarAttenuationEnd.value);switch(n){case 0:t=new THREE.PointLight(a,i,o,1);break;case 1:t=new THREE.DirectionalLight(a,i);break;case 2:var s=Math.PI/3;void 0!==r.InnerAngle&&(s=THREE.Math.degToRad(r.InnerAngle.value));var c=0;void 0!==r.OuterAngle&&(c=THREE.Math.degToRad(r.OuterAngle.value),c=Math.max(c,1)),t=new THREE.SpotLight(a,i,o,s,c,1);break;default:console.warn("THREE.FBXLoader: Unknown light type "+r.LightType.value+", defaulting to a THREE.PointLight."),t=new THREE.PointLight(a,i)}void 0!==r.CastShadows&&1===r.CastShadows.value&&(t.castShadow=!0)}return t},createMesh:function(e,t,r){var n,a=null,i=null,o=[];return e.children.forEach(function(e){t.has(e.ID)&&(a=t.get(e.ID)),r.has(e.ID)&&o.push(r.get(e.ID))}),o.length>1?i=o:o.length>0?i=o[0]:(i=new THREE.MeshPhongMaterial({color:13421772}),o.push(i)),"color"in a.attributes&&o.forEach(function(e){e.vertexColors=THREE.VertexColors}),a.FBX_Deformer?(o.forEach(function(e){e.skinning=!0}),n=new THREE.SkinnedMesh(a,i)):n=new THREE.Mesh(a,i),n},createCurve:function(e,t){var r=e.children.reduce(function(e,r){return t.has(r.ID)&&(e=t.get(r.ID)),e},null),n=new THREE.LineBasicMaterial({color:3342591,linewidth:1});return new THREE.Line(r,n)},setModelTransforms:function(e,t){var r={};"RotationOrder"in t&&(r.eulerOrder=parseInt(t.RotationOrder.value)),"Lcl_Translation"in t&&(r.translation=t.Lcl_Translation.value),"RotationOffset"in t&&(r.rotationOffset=t.RotationOffset.value),"Lcl_Rotation"in t&&(r.rotation=t.Lcl_Rotation.value),"PreRotation"in t&&(r.preRotation=t.PreRotation.value),"PostRotation"in t&&(r.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(r.scale=t.Lcl_Scaling.value);var n=f(r);e.applyMatrix(n)},setLookAtProperties:function(e,t){if("LookAtProperty"in t){E.get(e.ID).children.forEach(function(t){if("LookAtProperty"===t.relationship){var r=g.Objects.Model[t.ID];if("Lcl_Translation"in r){var n=r.Lcl_Translation.value;void 0!==e.target?(e.target.position.fromArray(n),y.add(e.target)):e.lookAt((new THREE.Vector3).fromArray(n))}}})}},bindSkeleton:function(e,t,r){var n=this.parsePoseNodes();for(var a in e){var i=e[a];E.get(parseInt(i.ID)).parents.forEach(function(e){if(t.has(e.ID)){var a=e.ID;E.get(a).parents.forEach(function(e){if(r.has(e.ID)){r.get(e.ID).bind(new THREE.Skeleton(i.bones),n[e.ID])}})}})}},parsePoseNodes:function(){var e={};if("Pose"in g.Objects){var t=g.Objects.Pose;for(var r in t)if("BindPose"===t[r].attrType){var 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},createAmbientLight:function(){if("GlobalSettings"in g&&"AmbientColor"in g.GlobalSettings){var e=g.GlobalSettings.AmbientColor.value,t=e[0],r=e[1],n=e[2];if(0!==t||0!==r||0!==n){var a=new THREE.Color(t,r,n);y.add(new THREE.AmbientLight(a,1))}}},setupMorphMaterials:function(){y.traverse(function(e){if(e.isMesh&&(e.geometry.morphAttributes.position||e.geometry.morphAttributes.normal)){var t=e.uuid,r=e.material.uuid,n=!1;y.traverse(function(e){e.isMesh&&e.material.uuid===r&&e.uuid!==t&&(n=!0)}),!0===n&&(e.material=e.material.clone()),e.material.morphTargets=!0}})}},r.prototype={constructor:r,parse:function(e){var t=new Map;if("Geometry"in g.Objects){var r=g.Objects.Geometry;for(var n in r){var a=E.get(parseInt(n)),i=this.parseGeometry(a,r[n],e);t.set(parseInt(n),i)}}return t},parseGeometry:function(e,t,r){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,r);case"NurbsCurve":return this.parseNurbsGeometry(t)}},parseMeshGeometry:function(e,t,r){var n=r.skeletons,a=r.morphTargets,i=e.parents.map(function(e){return g.Objects.Model[e.ID]});if(0!==i.length){var o=e.children.reduce(function(e,t){return void 0!==n[t.ID]&&(e=n[t.ID]),e},null),s=e.children.reduce(function(e,t){return void 0!==a[t.ID]&&(e=a[t.ID]),e},null),c=i[0],u={};"RotationOrder"in c&&(u.eulerOrder=c.RotationOrder.value),"GeometricTranslation"in c&&(u.translation=c.GeometricTranslation.value),"GeometricRotation"in c&&(u.rotation=c.GeometricRotation.value),"GeometricScaling"in c&&(u.scale=c.GeometricScaling.value);var l=f(u);return this.genGeometry(t,o,s,l)}},genGeometry:function(e,t,r,n){var a=new THREE.BufferGeometry;e.attrName&&(a.name=e.attrName);var i=this.parseGeoNode(e,t),o=this.genBuffers(i),s=new THREE.Float32BufferAttribute(o.vertex,3);if(n.applyToBufferAttribute(s),a.addAttribute("position",s),o.colors.length>0&&a.addAttribute("color",new THREE.Float32BufferAttribute(o.colors,3)),t&&(a.addAttribute("skinIndex",new THREE.Uint16BufferAttribute(o.weightsIndices,4)),a.addAttribute("skinWeight",new THREE.Float32BufferAttribute(o.vertexWeights,4)),a.FBX_Deformer=t),o.normal.length>0){var c=new THREE.Float32BufferAttribute(o.normal,3);(new THREE.Matrix3).getNormalMatrix(n).applyToBufferAttribute(c),a.addAttribute("normal",c)}if(o.uvs.forEach(function(e,t){var r="uv"+(t+1).toString();0===t&&(r="uv"),a.addAttribute(r,new THREE.Float32BufferAttribute(o.uvs[t],2))}),i.material&&"AllSame"!==i.material.mappingType){var u=o.materialIndex[0],l=0;if(o.materialIndex.forEach(function(e,t){e!==u&&(a.addGroup(l,t-l,u),u=e,l=t)}),a.groups.length>0){var p=a.groups[a.groups.length-1],f=p.start+p.count;f!==o.materialIndex.length&&a.addGroup(f,o.materialIndex.length-f,u)}0===a.groups.length&&a.addGroup(0,o.materialIndex.length,o.materialIndex[0])}return this.addMorphTargets(a,e,r,n),a},parseGeoNode:function(e,t){var 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=[];for(var n=0;e.LayerElementUV[n];)r.uv.push(this.parseUVs(e.LayerElementUV[n])),n++}return r.weightTable={},null!==t&&(r.skeleton=t,t.rawBones.forEach(function(e,t){e.indices.forEach(function(n,a){void 0===r.weightTable[n]&&(r.weightTable[n]=[]),r.weightTable[n].push({id:t,weight:e.weights[a]})})})),r},genBuffers:function(e){var t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]},r=0,n=0,a=!1,i=[],o=[],s=[],c=[],u=[],l=[],f=this;return e.vertexIndices.forEach(function(h,d){var m=!1;h<0&&(h^=-1,m=!0);var v=[],g=[];if(i.push(3*h,3*h+1,3*h+2),e.color){R=p(d,r,h,e.color);s.push(R[0],R[1],R[2])}if(e.skeleton){if(void 0!==e.weightTable[h]&&e.weightTable[h].forEach(function(e){g.push(e.weight),v.push(e.id)}),g.length>4){a||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),a=!0);var E=[0,0,0,0],y=[0,0,0,0];g.forEach(function(e,t){var r=e,n=v[t];y.forEach(function(e,t,a){if(r>e){a[t]=r,r=e;var i=E[t];E[t]=n,n=i}})}),v=E,g=y}for(;g.length<4;)g.push(0),v.push(0);for(var T=0;T<4;++T)u.push(g[T]),l.push(v[T])}if(e.normal){var R=p(d,r,h,e.normal);o.push(R[0],R[1],R[2])}if(e.material&&"AllSame"!==e.material.mappingType)var b=p(d,r,h,e.material)[0];e.uv&&e.uv.forEach(function(e,t){var n=p(d,r,h,e);void 0===c[t]&&(c[t]=[]),c[t].push(n[0]),c[t].push(n[1])}),n++,m&&(f.genFace(t,e,i,b,o,s,c,u,l,n),r++,n=0,i=[],o=[],s=[],c=[],u=[],l=[])}),t},genFace:function(e,t,r,n,a,i,o,s,c,u){for(var l=2;l<u;l++)e.vertex.push(t.vertexPositions[r[0]]),e.vertex.push(t.vertexPositions[r[1]]),e.vertex.push(t.vertexPositions[r[2]]),e.vertex.push(t.vertexPositions[r[3*(l-1)]]),e.vertex.push(t.vertexPositions[r[3*(l-1)+1]]),e.vertex.push(t.vertexPositions[r[3*(l-1)+2]]),e.vertex.push(t.vertexPositions[r[3*l]]),e.vertex.push(t.vertexPositions[r[3*l+1]]),e.vertex.push(t.vertexPositions[r[3*l+2]]),t.skeleton&&(e.vertexWeights.push(s[0]),e.vertexWeights.push(s[1]),e.vertexWeights.push(s[2]),e.vertexWeights.push(s[3]),e.vertexWeights.push(s[4*(l-1)]),e.vertexWeights.push(s[4*(l-1)+1]),e.vertexWeights.push(s[4*(l-1)+2]),e.vertexWeights.push(s[4*(l-1)+3]),e.vertexWeights.push(s[4*l]),e.vertexWeights.push(s[4*l+1]),e.vertexWeights.push(s[4*l+2]),e.vertexWeights.push(s[4*l+3]),e.weightsIndices.push(c[0]),e.weightsIndices.push(c[1]),e.weightsIndices.push(c[2]),e.weightsIndices.push(c[3]),e.weightsIndices.push(c[4*(l-1)]),e.weightsIndices.push(c[4*(l-1)+1]),e.weightsIndices.push(c[4*(l-1)+2]),e.weightsIndices.push(c[4*(l-1)+3]),e.weightsIndices.push(c[4*l]),e.weightsIndices.push(c[4*l+1]),e.weightsIndices.push(c[4*l+2]),e.weightsIndices.push(c[4*l+3])),t.color&&(e.colors.push(i[0]),e.colors.push(i[1]),e.colors.push(i[2]),e.colors.push(i[3*(l-1)]),e.colors.push(i[3*(l-1)+1]),e.colors.push(i[3*(l-1)+2]),e.colors.push(i[3*l]),e.colors.push(i[3*l+1]),e.colors.push(i[3*l+2])),t.material&&"AllSame"!==t.material.mappingType&&(e.materialIndex.push(n),e.materialIndex.push(n),e.materialIndex.push(n)),t.normal&&(e.normal.push(a[0]),e.normal.push(a[1]),e.normal.push(a[2]),e.normal.push(a[3*(l-1)]),e.normal.push(a[3*(l-1)+1]),e.normal.push(a[3*(l-1)+2]),e.normal.push(a[3*l]),e.normal.push(a[3*l+1]),e.normal.push(a[3*l+2])),t.uv&&t.uv.forEach(function(t,r){void 0===e.uvs[r]&&(e.uvs[r]=[]),e.uvs[r].push(o[r][0]),e.uvs[r].push(o[r][1]),e.uvs[r].push(o[r][2*(l-1)]),e.uvs[r].push(o[r][2*(l-1)+1]),e.uvs[r].push(o[r][2*l]),e.uvs[r].push(o[r][2*l+1])})},addMorphTargets:function(e,t,r,n){if(null!==r){e.morphAttributes.position=[],e.morphAttributes.normal=[];var a=this;r.rawTargets.forEach(function(r){var i=g.Objects.Geometry[r.geoID];void 0!==i&&a.genMorphGeometry(e,t,i,n)})}},genMorphGeometry:function(e,t,r,n){var a=new THREE.BufferGeometry;r.attrName&&(a.name=r.attrName);for(var i=void 0!==t.PolygonVertexIndex?t.PolygonVertexIndex.a:[],o=void 0!==t.Vertices?t.Vertices.a.slice():[],s=void 0!==r.Vertices?r.Vertices.a:[],c=void 0!==r.Indexes?r.Indexes.a:[],u=0;u<c.length;u++){var l=3*c[u];o[l]+=s[3*u],o[l+1]+=s[3*u+1],o[l+2]+=s[3*u+2]}var p={vertexIndices:i,vertexPositions:o},f=this.genBuffers(p),h=new THREE.Float32BufferAttribute(f.vertex,3);h.name=r.attrName,n.applyToBufferAttribute(h),e.morphAttributes.position.push(h)},parseNormals:function(e){var t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.Normals.a,a=[];return"IndexToDirect"===r&&("NormalIndex"in e?a=e.NormalIndex.a:"NormalsIndex"in e&&(a=e.NormalsIndex.a)),{dataSize:3,buffer:n,indices:a,mappingType:t,referenceType:r}},parseUVs:function(e){var t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.UV.a,a=[];return"IndexToDirect"===r&&(a=e.UVIndex.a),{dataSize:2,buffer:n,indices:a,mappingType:t,referenceType:r}},parseVertexColors:function(e){var t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.Colors.a,a=[];return"IndexToDirect"===r&&(a=e.ColorIndex.a),{dataSize:4,buffer:n,indices:a,mappingType:t,referenceType:r}},parseMaterialIndices:function(e){var t=e.MappingInformationType,r=e.ReferenceInformationType;if("NoMappingInformation"===t)return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:r};for(var n=e.Materials.a,a=[],i=0;i<n.length;++i)a.push(i);return{dataSize:1,buffer:n,indices:a,mappingType:t,referenceType:r}},parseNurbsGeometry:function(e){if(void 0===THREE.NURBSCurve)return console.error("THREE.FBXLoader: The loader relies on THREE.NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry."),new THREE.BufferGeometry;var 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;for(var r=t-1,n=e.KnotVector.a,a=[],i=e.Points.a,o=0,s=i.length;o<s;o+=4)a.push((new THREE.Vector4).fromArray(i,o));var c,u;if("Closed"===e.Form)a.push(a[0]);else if("Periodic"===e.Form){c=r,u=n.length-1-c;for(o=0;o<r;++o)a.push(a[o])}var l=new THREE.NURBSCurve(r,n,a,c,u).getPoints(7*a.length),p=new Float32Array(3*l.length);l.forEach(function(e,t){e.toArray(p,3*t)});var f=new THREE.BufferGeometry;return f.addAttribute("position",new THREE.BufferAttribute(p,3)),f}},n.prototype={constructor:n,parse:function(){var e=[],t=this.parseClips();if(void 0===t)return e;for(var r in t){var n=t[r],a=this.addClip(n);e.push(a)}return e},parseClips:function(){if(void 0!==g.Objects.AnimationCurve){var e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);var t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}},parseAnimationCurveNodes:function(){var e=g.Objects.AnimationCurveNode,t=new Map;for(var r in e){var n=e[r];if(null!==n.attrName.match(/S|R|T|DeformPercent/)){var a={id:n.id,attr:n.attrName,curves:{}};t.set(a.id,a)}}return t},parseAnimationCurves:function(e){var t=g.Objects.AnimationCurve;for(var r in t){var n={id:t[r].id,times:t[r].KeyTime.a.map(l),values:t[r].KeyValueFloat.a},a=E.get(n.id);if(void 0!==a){var i=a.parents[0].ID,o=a.parents[0].relationship;o.match(/X/)?e.get(i).curves.x=n:o.match(/Y/)?e.get(i).curves.y=n:o.match(/Z/)?e.get(i).curves.z=n:o.match(/d|DeformPercent/)&&e.has(i)&&(e.get(i).curves.morph=n)}}},parseAnimationLayers:function(e){var t=g.Objects.AnimationLayer,r=new Map;for(var n in t){var a=[],i=E.get(parseInt(n));if(void 0!==i){var o=this;i.children.forEach(function(t,r){if(e.has(t.ID)){var n=e.get(t.ID);if(void 0!==n.curves.x||void 0!==n.curves.y||void 0!==n.curves.z){if(void 0===a[r]){E.get(t.ID).parents.forEach(function(e){void 0!==e.relationship&&(p=e.ID)});var i=g.Objects.Model[p.toString()],s={modelName:THREE.PropertyBinding.sanitizeNodeName(i.attrName),initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1],transform:o.getModelAnimTransform(i)};"PreRotation"in i&&(s.preRotations=i.PreRotation.value),"PostRotation"in i&&(s.postRotations=i.PostRotation.value),a[r]=s}a[r][n.attr]=n}else if(void 0!==n.curves.morph){if(void 0===a[r]){var c;E.get(t.ID).parents.forEach(function(e){void 0!==e.relationship&&(c=e.ID)});var u=E.get(c).parents[0].ID,l=E.get(u).parents[0].ID,p=E.get(l).parents[0].ID,i=g.Objects.Model[p],s={modelName:THREE.PropertyBinding.sanitizeNodeName(i.attrName),morphName:g.Objects.Deformer[c].attrName};a[r]=s}a[r][n.attr]=n}}}),r.set(parseInt(n),a)}}return r},getModelAnimTransform:function(e){var t={};return"RotationOrder"in e&&(t.eulerOrder=parseInt(e.RotationOrder.value)),"Lcl_Translation"in e&&(t.translation=e.Lcl_Translation.value),"RotationOffset"in e&&(t.rotationOffset=e.RotationOffset.value),"Lcl_Rotation"in e&&(t.rotation=e.Lcl_Rotation.value),"PreRotation"in e&&(t.preRotation=e.PreRotation.value),"PostRotation"in e&&(t.postRotation=e.PostRotation.value),"Lcl_Scaling"in e&&(t.scale=e.Lcl_Scaling.value),f(t)},parseAnimStacks:function(e){var t=g.Objects.AnimationStack,r={};for(var n in t){var a=E.get(parseInt(n)).children;a.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");var i=e.get(a[0].ID);r[n]={name:t[n].attrName,layer:i}}return r},addClip:function(e){var t=[],r=this;return e.layer.forEach(function(e){t=t.concat(r.generateTracks(e))}),new THREE.AnimationClip(e.name,-1,t)},generateTracks:function(e){var t=[],r=new THREE.Vector3,n=new THREE.Quaternion,a=new THREE.Vector3;if(e.transform&&e.transform.decompose(r,n,a),r=r.toArray(),n=(new THREE.Euler).setFromQuaternion(n).toArray(),a=a.toArray(),void 0!==e.T&&Object.keys(e.T.curves).length>0){var i=this.generateVectorTrack(e.modelName,e.T.curves,r,"position");void 0!==i&&t.push(i)}if(void 0!==e.R&&Object.keys(e.R.curves).length>0){var o=this.generateRotationTrack(e.modelName,e.R.curves,n,e.preRotations,e.postRotations);void 0!==o&&t.push(o)}if(void 0!==e.S&&Object.keys(e.S.curves).length>0){var s=this.generateVectorTrack(e.modelName,e.S.curves,a,"scale");void 0!==s&&t.push(s)}if(void 0!==e.DeformPercent){var c=this.generateMorphTrack(e);void 0!==c&&t.push(c)}return t},generateVectorTrack:function(e,t,r,n){var a=this.getTimesForAllAxes(t),i=this.getKeyframeTrackValues(a,t,r);return new THREE.VectorKeyframeTrack(e+"."+n,a,i)},generateRotationTrack:function(e,t,r,n,a){void 0!==t.x&&(this.interpolateRotations(t.x),t.x.values=t.x.values.map(THREE.Math.degToRad)),void 0!==t.y&&(this.interpolateRotations(t.y),t.y.values=t.y.values.map(THREE.Math.degToRad)),void 0!==t.z&&(this.interpolateRotations(t.z),t.z.values=t.z.values.map(THREE.Math.degToRad));var i=this.getTimesForAllAxes(t),o=this.getKeyframeTrackValues(i,t,r);void 0!==n&&((n=n.map(THREE.Math.degToRad)).push("ZYX"),n=(new THREE.Euler).fromArray(n),n=(new THREE.Quaternion).setFromEuler(n)),void 0!==a&&((a=a.map(THREE.Math.degToRad)).push("ZYX"),a=(new THREE.Euler).fromArray(a),a=(new THREE.Quaternion).setFromEuler(a).inverse());for(var s=new THREE.Quaternion,c=new THREE.Euler,u=[],l=0;l<o.length;l+=3)c.set(o[l],o[l+1],o[l+2],"ZYX"),s.setFromEuler(c),void 0!==n&&s.premultiply(n),void 0!==a&&s.multiply(a),s.toArray(u,l/3*4);return new THREE.QuaternionKeyframeTrack(e+".quaternion",i,u)},generateMorphTrack:function(e){var t=e.DeformPercent.curves.morph,r=t.values.map(function(e){return e/100}),n=y.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new THREE.NumberKeyframeTrack(e.modelName+".morphTargetInfluences["+n+"]",t.times,r)},getTimesForAllAxes:function(e){var t=[];return 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}).filter(function(e,t,r){return r.indexOf(e)==t})},getKeyframeTrackValues:function(e,t,r){var n=r,a=[],i=-1,o=-1,s=-1;return e.forEach(function(e){if(t.x&&(i=t.x.times.indexOf(e)),t.y&&(o=t.y.times.indexOf(e)),t.z&&(s=t.z.times.indexOf(e)),-1!==i){var r=t.x.values[i];a.push(r),n[0]=r}else a.push(n[0]);if(-1!==o){var c=t.y.values[o];a.push(c),n[1]=c}else a.push(n[1]);if(-1!==s){var u=t.z.values[s];a.push(u),n[2]=u}else a.push(n[2])}),a},interpolateRotations:function(e){for(var t=1;t<e.values.length;t++){var r=e.values[t-1],n=e.values[t]-r,a=Math.abs(n);if(a>=180){for(var i=a/180,o=n/i,s=r+o,c=e.times[t-1],u=(e.times[t]-c)/i,l=c+u,p=[],f=[];l<e.times[t];)p.push(l),l+=u,f.push(s),s+=o;e.times=v(e.times,t,p),e.values=v(e.values,t,f)}}}},i.prototype={constructor:i,getPrevNode:function(){return this.nodeStack[this.currentIndent-2]},getCurrentNode:function(){return this.nodeStack[this.currentIndent-1]},getCurrentProp:function(){return this.currentProp},pushStack:function(e){this.nodeStack.push(e),this.currentIndent+=1},popStack:function(){this.nodeStack.pop(),this.currentIndent-=1},setCurrentProp:function(e,t){this.currentProp=e,this.currentPropName=t},parse:function(e){this.currentIndent=0,console.log("FBXTree: ",c),this.allNodes=new c,this.nodeStack=[],this.currentProp=[],this.currentPropName="";var t=this,r=e.split(/[\r\n]+/);return r.forEach(function(e,n){var a=e.match(/^[\s\t]*;/),i=e.match(/^[\s\t]*$/);if(!a&&!i){var o=e.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),s=e.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),c=e.match("^\\t{"+(t.currentIndent-1)+"}}");o?t.parseNodeBegin(e,o):s?t.parseNodeProperty(e,s,r[++n]):c?t.popStack():e.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(e)}}),this.allNodes},parseNodeBegin:function(e,t){var r=t[1].trim().replace(/^"/,"").replace(/"$/,""),n=t[2].split(",").map(function(e){return e.trim().replace(/^"/,"").replace(/"$/,"")}),a={name:r},i=this.parseNodeAttr(n),o=this.getCurrentNode();0===this.currentIndent?this.allNodes.add(r,a):r in o?("PoseNode"===r?o.PoseNode.push(a):void 0!==o[r].id&&(o[r]={},o[r][o[r].id]=o[r]),""!==i.id&&(o[r][i.id]=a)):"number"==typeof i.id?(o[r]={},o[r][i.id]=a):"Properties70"!==r&&(o[r]="PoseNode"===r?[a]:a),"number"==typeof i.id&&(a.id=i.id),""!==i.name&&(a.attrName=i.name),""!==i.type&&(a.attrType=i.type),this.pushStack(a)},parseNodeAttr:function(e){var t=e[0];""!==e[0]&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));var r="",n="";return e.length>1&&(r=e[1].replace(/^(\w+)::/,""),n=e[2]),{id:t,name:r,type:n}},parseNodeProperty:function(e,t,r){var n=t[1].replace(/^"/,"").replace(/"$/,"").trim(),a=t[2].replace(/^"/,"").replace(/"$/,"").trim();"Content"===n&&","===a&&(a=r.replace(/"/g,"").replace(/,$/,"").trim());var i=this.getCurrentNode();if("Properties70"!==i.name){if("C"===n){var o=a.split(",").slice(1),s=parseInt(o[0]),c=parseInt(o[1]),u=a.split(",").slice(3);n="connections",function(e,t){for(var r=0,n=e.length,a=t.length;r<a;r++,n++)e[n]=t[r]}(a=[s,c],u=u.map(function(e){return e.trim().replace(/^"/,"")})),void 0===i[n]&&(i[n]=[])}"Node"===n&&(i.id=a),n in i&&Array.isArray(i[n])?i[n].push(a):"a"!==n?i[n]=a:i.a=a,this.setCurrentProp(i,n),"a"===n&&","!==a.slice(-1)&&(i.a=d(a))}else this.parseNodeSpecialProperty(e,n,a)},parseNodePropertyContinued:function(e){var t=this.getCurrentNode();t.a+=e,","!==e.slice(-1)&&(t.a=d(t.a))},parseNodeSpecialProperty:function(e,t,r){var n=r.split('",').map(function(e){return e.trim().replace(/^\"/,"").replace(/\s/,"_")}),a=n[0],i=n[1],o=n[2],s=n[3],c=n[4];switch(i){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":c=parseFloat(c);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":c=d(c)}this.getPrevNode()[a]={type:i,type2:o,flag:s,value:c},this.setCurrentProp(this.getPrevNode(),a)}},o.prototype={constructor:o,parse:function(e){var t=new s(e);t.skip(23);var r=t.getUint32();console.log("THREE.FBXLoader: FBX binary version: "+r);for(var n=new c;!this.endOfContent(t);){var a=this.parseNode(t,r);null!==a&&n.add(a.name,a)}return n},endOfContent:function(e){return e.size()%16==0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()},parseNode:function(e,t){var r={},n=t>=7500?e.getUint64():e.getUint32(),a=t>=7500?e.getUint64():e.getUint32(),i=(t>=7500?e.getUint64():e.getUint32(),e.getUint8()),o=e.getString(i);if(0===n)return null;for(var s=[],c=0;c<a;c++)s.push(this.parseProperty(e));var u=s.length>0?s[0]:"",l=s.length>1?s[1]:"",p=s.length>2?s[2]:"";for(r.singleProperty=1===a&&e.getOffset()===n;n>e.getOffset();){var f=this.parseNode(e,t);null!==f&&this.parseSubNode(o,r,f)}return r.propertyList=s,"number"==typeof u&&(r.id=u),""!==l&&(r.attrName=l),""!==p&&(r.attrType=p),""!==o&&(r.name=o),r},parseSubNode:function(e,t,r){if(!0===r.singleProperty){var n=r.propertyList[0];Array.isArray(n)?(t[r.name]=r,r.a=n):t[r.name]=n}else if("Connections"===e&&"C"===r.name){var a=[];r.propertyList.forEach(function(e,t){0!==t&&a.push(e)}),void 0===t.connections&&(t.connections=[]),t.connections.push(a)}else if("Properties70"===r.name){Object.keys(r).forEach(function(e){t[e]=r[e]})}else if("Properties70"===e&&"P"===r.name){var i,o=r.propertyList[0],s=r.propertyList[1],c=r.propertyList[2],u=r.propertyList[3];0===o.indexOf("Lcl ")&&(o=o.replace("Lcl ","Lcl_")),0===s.indexOf("Lcl ")&&(s=s.replace("Lcl ","Lcl_")),i="Color"===s||"ColorRGB"===s||"Vector"===s||"Vector3D"===s||0===s.indexOf("Lcl_")?[r.propertyList[4],r.propertyList[5],r.propertyList[6]]:r.propertyList[4],t[o]={type:s,type2:c,flag:u,value:i}}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:function(e){var t=e.getString(1);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":r=e.getUint32();return e.getArrayBuffer(r);case"S":var r=e.getUint32();return e.getString(r);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":var n=e.getUint32(),a=e.getUint32(),i=e.getUint32();if(0===a)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)}"undefined"==typeof Zlib&&console.error("THREE.FBXLoader: External library Inflate.min.js required, obtain or import from https://github.com/imaya/zlib.js");var o=new s(new Zlib.Inflate(new Uint8Array(e.getArrayBuffer(i))).decompress().buffer);switch(t){case"b":case"c":return o.getBooleanArray(n);case"d":return o.getFloat64Array(n);case"f":return o.getFloat32Array(n);case"i":return o.getInt32Array(n);case"l":return o.getInt64Array(n)}default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}},s.prototype={constructor:s,getOffset:function(){return this.offset},size:function(){return this.dv.buffer.byteLength},skip:function(e){this.offset+=e},getBoolean:function(){return 1==(1&this.getUint8())},getBooleanArray:function(e){for(var t=[],r=0;r<e;r++)t.push(this.getBoolean());return t},getUint8:function(){var e=this.dv.getUint8(this.offset);return this.offset+=1,e},getInt16:function(){var e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e},getInt32:function(){var e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e},getInt32Array:function(e){for(var t=[],r=0;r<e;r++)t.push(this.getInt32());return t},getUint32:function(){var e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e},getInt64:function(){var e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),2147483648&t?(t=4294967295&~t,4294967295===(e=4294967295&~e)&&(t=t+1&4294967295),e=e+1&4294967295,-(4294967296*t+e)):4294967296*t+e},getInt64Array:function(e){for(var t=[],r=0;r<e;r++)t.push(this.getInt64());return t},getUint64:function(){var e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),4294967296*t+e},getFloat32:function(){var e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e},getFloat32Array:function(e){for(var t=[],r=0;r<e;r++)t.push(this.getFloat32());return t},getFloat64:function(){var e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e},getFloat64Array:function(e){for(var t=[],r=0;r<e;r++)t.push(this.getFloat64());return t},getArrayBuffer:function(e){var t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t},getString:function(e){for(var t=[],r=0;r<e;r++)t[r]=this.getUint8();var n=t.indexOf(0);return n>=0&&(t=t.slice(0,n)),THREE.LoaderUtils.decodeText(new Uint8Array(t))}},c.prototype={constructor:c,add:function(e,t){this[e]=t}};var T=[],R=new THREE.Matrix4,b=new THREE.Euler,w=new THREE.Vector3,I=new THREE.Vector3,x=new THREE.Matrix4;return e}()},{}],3:[function(e,t,r){"use strict";t.exports=THREE.PLYLoader=function(e){this.manager=void 0!==e?e:THREE.DefaultLoadingManager,this.propertyNameMapping={}},THREE.PLYLoader.prototype={constructor:THREE.PLYLoader,load:function(e,t,r,n){var a=this,i=new THREE.XHRLoader(this.manager);i.setResponseType("arraybuffer"),i.load(e,function(e){t(a.parse(e))},r,n)},setPropertyNameMapping:function(e){this.propertyNameMapping=e},bin2str:function(e){for(var t=new Uint8Array(e),r="",n=0;n<e.byteLength;n++)r+=String.fromCharCode(t[n]);return r},isASCII:function(e){return"ascii"===this.parseHeader(this.bin2str(e)).format},parse:function(e){return e instanceof ArrayBuffer?this.isASCII(e)?this.parseASCII(this.bin2str(e)):this.parseBinary(e):this.parseASCII(e)},parseHeader:function(e){function t(e,t){var r={type:e[0]};return"list"===r.type?(r.name=e[3],r.countType=e[1],r.itemType=e[2]):r.name=e[1],r.name in t&&(r.name=t[r.name]),r}var r="",n=0,a=/ply([\s\S]*)end_header\s/.exec(e);null!==a&&(r=a[1],n=a[0].length);for(var i,o,s={comments:[],elements:[],headerLength:n},c=r.split("\n"),u=void 0,l=0;l<c.length;l++){var p=c[l];if(""!==(p=p.trim()))switch(o=p.split(/\s+/),i=o.shift(),p=o.join(" "),i){case"format":s.format=o[0],s.version=o[1];break;case"comment":s.comments.push(p);break;case"element":void 0!==u&&s.elements.push(u),(u=Object()).name=o[0],u.count=parseInt(o[1]),u.properties=[];break;case"property":u.properties.push(t(o,this.propertyNameMapping));break;default:console.log("unhandled",i,o)}}return void 0!==u&&s.elements.push(u),s},parseASCIINumber:function(e,t){switch(t){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(e);case"float":case"double":case"float32":case"float64":return parseFloat(e)}},parseASCIIElement:function(e,t){for(var r=t.split(/\s+/),n=Object(),a=0;a<e.length;a++)if("list"===e[a].type){for(var i=[],o=this.parseASCIINumber(r.shift(),e[a].countType),s=0;s<o;s++)i.push(this.parseASCIINumber(r.shift(),e[a].itemType));n[e[a].name]=i}else n[e[a].name]=this.parseASCIINumber(r.shift(),e[a].type);return n},parseASCII:function(e){var t,r=new THREE.Geometry,n=this.parseHeader(e),a="";null!==(t=/end_header\s([\s\S]*)$/.exec(e))&&(a=t[1]);var i=a.split("\n"),o=0,s=0;r.useColor=!1;for(var c=0;c<i.length;c++){var u=i[c];if(""!==(u=u.trim())){s>=n.elements[o].count&&(o++,s=0);var l=this.parseASCIIElement(n.elements[o].properties,u);this.handleElement(r,n.elements[o].name,l),s++}}return this.postProcess(r)},postProcess:function(e){if(e.useColor){for(var t=0;t<e.faces.length;t++)e.faces[t].vertexColors=[e.colors[e.faces[t].a],e.colors[e.faces[t].b],e.colors[e.faces[t].c]];e.elementsNeedUpdate=!0}return e.computeBoundingSphere(),e},handleElement:function(e,t,r){if("vertex"===t){if(e.vertices.push(new THREE.Vector3(r.x,r.y,r.z)),"red"in r&&"green"in r&&"blue"in r){e.useColor=!0;var n=new THREE.Color;n.setRGB(r.red/255,r.green/255,r.blue/255),e.colors.push(n)}}else if("face"===t){var a=r.vertex_indices||r.vertex_index;3===a.length?e.faces.push(new THREE.Face3(a[0],a[1],a[2])):4===a.length&&e.faces.push(new THREE.Face3(a[0],a[1],a[3]),new THREE.Face3(a[1],a[2],a[3]))}},binaryRead:function(e,t,r,n){switch(r){case"int8":case"char":return[e.getInt8(t),1];case"uint8":case"uchar":return[e.getUint8(t),1];case"int16":case"short":return[e.getInt16(t,n),2];case"uint16":case"ushort":return[e.getUint16(t,n),2];case"int32":case"int":return[e.getInt32(t,n),4];case"uint32":case"uint":return[e.getUint32(t,n),4];case"float32":case"float":return[e.getFloat32(t,n),4];case"float64":case"double":return[e.getFloat64(t,n),8]}},binaryReadElement:function(e,t,r,n){for(var a,i=Object(),o=0,s=0;s<r.length;s++)if("list"===r[s].type){var c=[],u=(a=this.binaryRead(e,t+o,r[s].countType,n))[0];o+=a[1];for(var l=0;l<u;l++)a=this.binaryRead(e,t+o,r[s].itemType,n),c.push(a[0]),o+=a[1];i[r[s].name]=c}else a=this.binaryRead(e,t+o,r[s].type,n),i[r[s].name]=a[0],o+=a[1];return[i,o]},parseBinary:function(e){for(var t,r=new THREE.Geometry,n=this.parseHeader(this.bin2str(e)),a="binary_little_endian"===n.format,i=new DataView(e,n.headerLength),o=0,s=0;s<n.elements.length;s++)for(var c=0;c<n.elements[s].count;c++){o+=(t=this.binaryReadElement(i,o,n.elements[s].properties,a))[1];var u=t[0];this.handleElement(r,n.elements[s].name,u)}return this.postProcess(r)}}},{}],4:[function(e,t,r){"use strict";function n(e){var t=document.getElementById(e),r=t.parentNode;try{r&&r.removeChild(t)}catch(e){}}function a(e,t,r){return new r(function(r,a){var i=t.timeout||5e3,o="script_"+Date.now()+"_"+Math.ceil(1e5*Math.random()),s=function(e,t){var r=document.createElement("script");return r.type="text/javascript",r.async=!0,r.id=t,r.src=e,r}(e,o),c=setTimeout(function(){a(new Error("Script request to "+e+" timed out")),n(o)},i),u=function(e){clearTimeout(e)};s.addEventListener("load",function(e){r({ok:!0}),u(c),n(o)}),s.addEventListener("error",function(t){a(new Error("Script request to "+e+" failed "+t)),u(c),n(o)}),function(e){var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}(s)})}t.exports=function(e){return e=e||{},function(t,r){return r=r||{},a(t,r,e.Promise||Promise)}}},{}],5:[function(e,t,r){"use strict";function n(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")}var a={once:THREE.LoopOnce,repeat:THREE.LoopRepeat,pingpong:THREE.LoopPingPong};t.exports=AFRAME.registerComponent("animation-mixer",{schema:{clip:{default:"*"},duration:{default:0},clampWhenFinished:{default:!1,type:"boolean"},crossFadeDuration:{default:0},loop:{default:"repeat",oneOf:Object.keys(a)},repetitions:{default:1/0,min:0},timeScale:{default:1}},init:function(){var e=this;this.model=null,this.mixer=null,this.activeActions=[];var t=this.el.getObject3D("mesh");t?this.load(t):this.el.addEventListener("model-loaded",function(t){e.load(t.detail.model)})},load:function(e){var t=this.el;this.model=e,this.mixer=new THREE.AnimationMixer(e),this.mixer.addEventListener("loop",function(e){t.emit("animation-loop",{action:e.action,loopDelta:e.loopDelta})}),this.mixer.addEventListener("finished",function(e){t.emit("animation-finished",{action:e.action,direction:e.direction})}),this.data.clip&&this.update({})},remove:function(){this.mixer&&this.mixer.stopAllAction()},update:function(e){if(e){var t=this.data,r=AFRAME.utils.diff(t,e);if("clip"in r)return this.stopAction(),void(t.clip&&this.playAction());this.activeActions.forEach(function(e){"duration"in r&&t.duration&&e.setDuration(t.duration),"clampWhenFinished"in r&&(e.clampWhenFinished=t.clampWhenFinished),("loop"in r||"repetitions"in r)&&e.setLoop(a[t.loop],t.repetitions),"timeScale"in r&&e.setEffectiveTimeScale(t.timeScale)})}},stopAction:function(){for(var e=this.data,t=0;t<this.activeActions.length;t++)e.crossFadeDuration?this.activeActions[t].fadeOut(e.crossFadeDuration):this.activeActions[t].stop();this.activeActions.length=0},playAction:function(){if(this.mixer){var e=this.model,t=this.data,r=e.animations||(e.geometry||{}).animations||[];if(r.length)for(var i,o=function(e){return new RegExp("^"+e.split(/\*+/).map(n).join(".*")+"$")}(t.clip),s=0;i=r[s];s++)if(i.name.match(o)){var c=this.mixer.clipAction(i,e);c.enabled=!0,c.clampWhenFinished=t.clampWhenFinished,t.duration&&c.setDuration(t.duration),c.setLoop(a[t.loop],t.repetitions).setEffectiveTimeScale(t.timeScale).fadeIn(t.crossFadeDuration).play(),this.activeActions.push(c)}}},tick:function(e,t){this.mixer&&!isNaN(t)&&this.mixer.update(t/1e3)}})},{}],6:[function(e,t,r){"use strict";THREE.FBXLoader=e("../../lib/FBXLoader"),t.exports=AFRAME.registerComponent("fbx-model",{schema:{src:{type:"asset"},crossorigin:{default:""}},init:function(){this.model=null},update:function(){var e=this.data;if(e.src){this.remove();var t=new THREE.FBXLoader;e.crossorigin&&t.setCrossOrigin(e.crossorigin),t.load(e.src,this.load.bind(this))}},load:function(e){this.model=e,this.el.setObject3D("mesh",e),this.el.emit("model-loaded",{format:"fbx",model:e})},remove:function(){this.model&&this.el.removeObject3D("mesh")}})},{"../../lib/FBXLoader":2}],7:[function(e,t,r){"use strict";var n=e("../../lib/fetch-script")(),a=function(){var e=void 0;return function(){return e=e||n("https://rawgit.com/mrdoob/three.js/r86/examples/js/loaders/GLTFLoader.js")}}();t.exports=AFRAME.registerComponent("gltf-model-legacy",{schema:{type:"model"},init:function(){var e=this;this.model=null,this.loader=null,this.loaderPromise=a().then(function(){e.loader=new THREE.GLTFLoader,e.loader.setCrossOrigin("Anonymous")})},update:function(){var e=this,t=this,r=this.el,n=this.data;n&&(this.remove(),this.loaderPromise.then(function(){e.loader.load(n,function(e){t.model=e.scene,t.model.animations=e.animations,r.setObject3D("mesh",t.model),r.emit("model-loaded",{format:"gltf",model:t.model})})}))},remove:function(){this.model&&this.el.removeObject3D("mesh")}})},{"../../lib/fetch-script":4}],8:[function(e,t,r){"use strict";e("./animation-mixer"),e("./fbx-model"),e("./gltf-model-legacy"),e("./json-model"),e("./object-model"),e("./ply-model")},{"./animation-mixer":5,"./fbx-model":6,"./gltf-model-legacy":7,"./json-model":9,"./object-model":10,"./ply-model":11}],9:[function(e,t,r){"use strict";t.exports=AFRAME.registerComponent("json-model",{schema:{src:{type:"asset"},crossorigin:{default:""}},init:function(){this.model=null},update:function(){var e=this,t=void 0,r=this.data;r.src&&(this.remove(),t=new THREE.JSONLoader,r.crossorigin&&(t.crossOrigin=r.crossorigin),t.load(r.src,function(t,r){r.forEach(function(e){e.vertexColors=(t.faces[0]||{}).color?THREE.FaceColors:THREE.NoColors,e.skinning=!!(t.bones||[]).length,e.morphTargets=!!(t.morphTargets||[]).length,e.morphNormals=!!(t.morphNormals||[]).length});var n=(t.bones||[]).length?new THREE.SkinnedMesh(t,new THREE.MultiMaterial(r)):new THREE.Mesh(t,new THREE.MultiMaterial(r));e.load(n)}))},load:function(e){this.model=e,this.el.setObject3D("mesh",e),this.el.emit("model-loaded",{format:"json",model:e})},remove:function(){this.model&&this.el.removeObject3D("mesh")}})},{}],10:[function(e,t,r){"use strict";t.exports=AFRAME.registerComponent("object-model",{schema:{src:{type:"asset"},crossorigin:{default:""}},init:function(){this.model=null},update:function(){var e=this,t=void 0,r=this.data;r.src&&(this.remove(),t=new THREE.ObjectLoader,r.crossorigin&&t.setCrossOrigin(r.crossorigin),t.load(r.src,function(t){t.traverse(function(e){e instanceof THREE.SkinnedMesh&&e.material&&(e.material.skinning=!!(e.geometry&&e.geometry.bones||[]).length)}),e.load(t)}))},load:function(e){this.model=e,this.el.setObject3D("mesh",e),this.el.emit("model-loaded",{format:"json",model:e})},remove:function(){this.model&&this.el.removeObject3D("mesh")}})},{}],11:[function(e,t,r){"use strict";THREE.PLYLoader=e("../../lib/PLYLoader"),t.exports.System=AFRAME.registerSystem("ply-model",{init:function(){this.cache={}},getOrLoadGeometry:function(e,t){var r=this.cache,n=r[e];return!t&&n?n:(r[e]=new Promise(function(t){(new THREE.PLYLoader).load(e,function(e){t(e)})}),r[e])}}),t.exports.Component=AFRAME.registerComponent("ply-model",{schema:{skipCache:{type:"boolean",default:!1},src:{type:"asset"}},init:function(){this.model=null},update:function(){var e=this.data,t=this.el;e.src?this.system.getOrLoadGeometry(e.src,e.skipCache).then(function(e){var r=function(e){return new THREE.Mesh(e,new THREE.MeshPhongMaterial({color:16777215,shading:THREE.FlatShading,vertexColors:THREE.VertexColors,shininess:0}))}(e);t.setObject3D("mesh",r),t.emit("model-loaded",{format:"ply",model:r})}):console.warn("[%s] `src` property is required.",this.name)},remove:function(){this.model&&this.el.removeObject3D("mesh")}})},{"../../lib/PLYLoader":3}]},{},[1]);