UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

2 lines (1 loc) 28.4 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("../../../build/three.module.js");const t={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class s{constructor(){this.pluginCallbacks=[],this.register((function(e){return new F(e)})),this.register((function(e){return new E(e)})),this.register((function(e){return new B(e)})),this.register((function(e){return new j(e)})),this.register((function(e){return new P(e)})),this.register((function(e){return new V(e)})),this.register((function(e){return new O(e)})),this.register((function(e){return new D(e)})),this.register((function(e){return new H(e)})),this.register((function(e){return new K(e)}))}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,n){const r=new _,i=[];for(let a=0,o=this.pluginCallbacks.length;a<o;a++)i.push(this.pluginCallbacks[a](r));r.setPlugins(i),r.write(e,t,n).catch(s)}parseAsync(e,t){const s=this;return new Promise((function(n,r){s.parse(e,n,r,t)}))}}const n=0,r=1,i=2,a=3,o=4,c=5120,l=5121,u=5122,h=5123,p=5124,m=5125,f=5126,g=34962,d=34963,x=9728,y=9729,b=9984,M=9985,T=9986,w=9987,A=33071,I=33648,v=10497,R={};R[e.NearestFilter]=x,R[e.NearestMipmapNearestFilter]=b,R[e.NearestMipmapLinearFilter]=T,R[e.LinearFilter]=y,R[e.LinearMipmapNearestFilter]=M,R[e.LinearMipmapLinearFilter]=w,R[e.ClampToEdgeWrapping]=A,R[e.RepeatWrapping]=v,R[e.MirroredRepeatWrapping]=I;const S={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},k=new e.Color;function U(e,t){return e.length===t.length&&e.every((function(e,s){return e===t[s]}))}function z(e){return 4*Math.ceil(e/4)}function N(e,t=0){const s=z(e.byteLength);if(s!==e.byteLength){const n=new Uint8Array(s);if(n.set(new Uint8Array(e)),0!==t)for(let r=e.byteLength;r<s;r++)n[r]=t;return n.buffer}return e}function C(){return"undefined"==typeof document&&"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(1,1):document.createElement("canvas")}function L(e,t){if(void 0!==e.toBlob)return new Promise((s=>e.toBlob(s,t)));let s;return"image/jpeg"===t?s=.92:"image/webp"===t&&(s=.8),e.convertToBlob({type:t,quality:s})}class _{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter"}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map}}setPlugins(e){this.plugins=e}async write(e,t,s={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},s),this.options.animations.length>0&&(this.options.trs=!0),this.processInput(e),await Promise.all(this.pending);const n=this,r=n.buffers,i=n.json;s=n.options;const a=n.extensionsUsed,o=n.extensionsRequired,c=new Blob(r,{type:"application/octet-stream"}),l=Object.keys(a),u=Object.keys(o);if(l.length>0&&(i.extensionsUsed=l),u.length>0&&(i.extensionsRequired=u),i.buffers&&i.buffers.length>0&&(i.buffers[0].byteLength=c.size),!0===s.binary){const e=new FileReader;e.readAsArrayBuffer(c),e.onloadend=function(){const s=N(e.result),n=new DataView(new ArrayBuffer(8));n.setUint32(0,s.byteLength,!0),n.setUint32(4,5130562,!0);const r=N((a=JSON.stringify(i),(new TextEncoder).encode(a).buffer),32);var a;const o=new DataView(new ArrayBuffer(8));o.setUint32(0,r.byteLength,!0),o.setUint32(4,1313821514,!0);const c=new ArrayBuffer(12),l=new DataView(c);l.setUint32(0,1179937895,!0),l.setUint32(4,2,!0);const u=12+o.byteLength+r.byteLength+n.byteLength+s.byteLength;l.setUint32(8,u,!0);const h=new Blob([c,o,r,n,s],{type:"application/octet-stream"}),p=new FileReader;p.readAsArrayBuffer(h),p.onloadend=function(){t(p.result)}}}else if(i.buffers&&i.buffers.length>0){const e=new FileReader;e.readAsDataURL(c),e.onloadend=function(){const s=e.result;i.buffers[0].uri=s,t(i)}}else t(i)}serializeUserData(e,t){if(0===Object.keys(e.userData).length)return;const s=this.options,n=this.extensionsUsed;try{const r=JSON.parse(JSON.stringify(e.userData));if(s.includeCustomExtensions&&r.gltfExtensions){void 0===t.extensions&&(t.extensions={});for(const e in r.gltfExtensions)t.extensions[e]=r.gltfExtensions[e],n[e]=!0;delete r.gltfExtensions}Object.keys(r).length>0&&(t.extras=r)}catch(r){}}getUID(e,t=!1){if(!1===this.uids.has(e)){const t=new Map;t.set(!0,this.uid++),t.set(!1,this.uid++),this.uids.set(e,t)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(t){if(this.cache.attributesNormalized.has(t))return!1;const s=new e.Vector3;for(let e=0,n=t.count;e<n;e++)if(Math.abs(s.fromBufferAttribute(t,e).length()-1)>5e-4)return!1;return!0}createNormalizedNormalAttribute(t){const s=this.cache;if(s.attributesNormalized.has(t))return s.attributesNormalized.get(t);const n=t.clone(),r=new e.Vector3;for(let e=0,i=n.count;e<i;e++)r.fromBufferAttribute(n,e),0===r.x&&0===r.y&&0===r.z?r.setX(1):r.normalize(),n.setXYZ(e,r.x,r.y,r.z);return s.attributesNormalized.set(t,n),n}applyTextureTransform(e,t){let s=!1;const n={};0===t.offset.x&&0===t.offset.y||(n.offset=t.offset.toArray(),s=!0),0!==t.rotation&&(n.rotation=t.rotation,s=!0),1===t.repeat.x&&1===t.repeat.y||(n.scale=t.repeat.toArray(),s=!0),s&&(e.extensions=e.extensions||{},e.extensions.KHR_texture_transform=n,this.extensionsUsed.KHR_texture_transform=!0)}buildMetalRoughTexture(t,s){if(t===s)return t;function n(t){return t.encoding===e.sRGBEncoding?function(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}:function(e){return e}}const r=t?t.image:null,i=s?s.image:null,a=Math.max(r?r.width:0,i?i.width:0),o=Math.max(r?r.height:0,i?i.height:0),c=C();c.width=a,c.height=o;const l=c.getContext("2d");l.fillStyle="#00ffff",l.fillRect(0,0,a,o);const u=l.getImageData(0,0,a,o);if(r){l.drawImage(r,0,0,a,o);const e=n(t),s=l.getImageData(0,0,a,o).data;for(let t=2;t<s.length;t+=4)u.data[t]=256*e(s[t]/256)}if(i){l.drawImage(i,0,0,a,o);const e=n(s),t=l.getImageData(0,0,a,o).data;for(let s=1;s<t.length;s+=4)u.data[s]=256*e(t[s]/256)}l.putImageData(u,0,0);const h=(t||s).clone();return h.source=new e.Source(c),h.encoding=e.LinearEncoding,h}processBuffer(e){const t=this.json,s=this.buffers;return t.buffers||(t.buffers=[{byteLength:0}]),s.push(e),0}processBufferView(t,s,n,r,i){const a=this.json;let o;switch(a.bufferViews||(a.bufferViews=[]),s){case c:case l:o=1;break;case u:case h:o=2;break;default:o=4}const d=z(r*t.itemSize*o),x=new DataView(new ArrayBuffer(d));let y=0;for(let g=n;g<n+r;g++)for(let n=0;n<t.itemSize;n++){let r;t.itemSize>4?r=t.array[g*t.itemSize+n]:(0===n?r=t.getX(g):1===n?r=t.getY(g):2===n?r=t.getZ(g):3===n&&(r=t.getW(g)),!0===t.normalized&&(r=e.MathUtils.normalize(r,t.array))),s===f?x.setFloat32(y,r,!0):s===p?x.setInt32(y,r,!0):s===m?x.setUint32(y,r,!0):s===u?x.setInt16(y,r,!0):s===h?x.setUint16(y,r,!0):s===c?x.setInt8(y,r):s===l&&x.setUint8(y,r),y+=o}const b={buffer:this.processBuffer(x.buffer),byteOffset:this.byteOffset,byteLength:d};void 0!==i&&(b.target=i),i===g&&(b.byteStride=t.itemSize*o),this.byteOffset+=d,a.bufferViews.push(b);return{id:a.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){const t=this,s=t.json;return s.bufferViews||(s.bufferViews=[]),new Promise((function(n){const r=new FileReader;r.readAsArrayBuffer(e),r.onloadend=function(){const e=N(r.result),i={buffer:t.processBuffer(e),byteOffset:t.byteOffset,byteLength:e.byteLength};t.byteOffset+=e.byteLength,n(s.bufferViews.push(i)-1)}}))}processAccessor(t,s,n,r){const i=this.json;let a;if(t.array.constructor===Float32Array)a=f;else if(t.array.constructor===Int32Array)a=p;else if(t.array.constructor===Uint32Array)a=m;else if(t.array.constructor===Int16Array)a=u;else if(t.array.constructor===Uint16Array)a=h;else if(t.array.constructor===Int8Array)a=c;else{if(t.array.constructor!==Uint8Array)throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type.");a=l}if(void 0===n&&(n=0),void 0===r&&(r=t.count),0===r)return null;const o=function(t,s,n){const r={min:new Array(t.itemSize).fill(Number.POSITIVE_INFINITY),max:new Array(t.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let i=s;i<s+n;i++)for(let s=0;s<t.itemSize;s++){let n;t.itemSize>4?n=t.array[i*t.itemSize+s]:(0===s?n=t.getX(i):1===s?n=t.getY(i):2===s?n=t.getZ(i):3===s&&(n=t.getW(i)),!0===t.normalized&&(n=e.MathUtils.normalize(n,t.array))),r.min[s]=Math.min(r.min[s],n),r.max[s]=Math.max(r.max[s],n)}return r}(t,n,r);let x;void 0!==s&&(x=t===s.index?d:g);const y=this.processBufferView(t,a,n,r,x),b={bufferView:y.id,byteOffset:y.byteOffset,componentType:a,count:r,max:o.max,min:o.min,type:{1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"}[t.itemSize]};return!0===t.normalized&&(b.normalized=!0),i.accessors||(i.accessors=[]),i.accessors.push(b)-1}processImage(t,s,n,r="image/png"){if(null!==t){const s=this,i=s.cache,a=s.json,o=s.options,c=s.pending;i.images.has(t)||i.images.set(t,{});const l=i.images.get(t),u=r+":flipY/"+n.toString();if(void 0!==l[u])return l[u];a.images||(a.images=[]);const h={mimeType:r},p=C();p.width=Math.min(t.width,o.maxTextureSize),p.height=Math.min(t.height,o.maxTextureSize);const m=p.getContext("2d");if(!0===n&&(m.translate(0,p.height),m.scale(1,-1)),void 0!==t.data){e.RGBAFormat,t.width>o.maxTextureSize||(t.height,o.maxTextureSize);const s=new Uint8ClampedArray(t.height*t.width*4);for(let e=0;e<s.length;e+=4)s[e+0]=t.data[e+0],s[e+1]=t.data[e+1],s[e+2]=t.data[e+2],s[e+3]=t.data[e+3];m.putImageData(new ImageData(s,t.width,t.height),0,0)}else m.drawImage(t,0,0,p.width,p.height);!0===o.binary?c.push(L(p,r).then((e=>s.processBufferViewImage(e))).then((e=>{h.bufferView=e}))):void 0!==p.toDataURL?h.uri=p.toDataURL(r):c.push(L(p,r).then((e=>(new FileReader).readAsDataURL(e))).then((e=>{h.uri=e})));const f=a.images.push(h)-1;return l[u]=f,f}throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){const t=this.json;t.samplers||(t.samplers=[]);const s={magFilter:R[e.magFilter],minFilter:R[e.minFilter],wrapS:R[e.wrapS],wrapT:R[e.wrapT]};return t.samplers.push(s)-1}processTexture(e){const t=this.cache,s=this.json;if(t.textures.has(e))return t.textures.get(e);s.textures||(s.textures=[]);let n=e.userData.mimeType;"image/webp"===n&&(n="image/png");const r={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,n)};e.name&&(r.name=e.name),this._invokeAll((function(t){t.writeTexture&&t.writeTexture(e,r)}));const i=s.textures.push(r)-1;return t.textures.set(e,i),i}processMaterial(t){const s=this.cache,n=this.json;if(s.materials.has(t))return s.materials.get(t);if(t.isShaderMaterial)return null;n.materials||(n.materials=[]);const r={pbrMetallicRoughness:{}};!0!==t.isMeshStandardMaterial&&t.isMeshBasicMaterial;const i=t.color.toArray().concat([t.opacity]);if(U(i,[1,1,1,1])||(r.pbrMetallicRoughness.baseColorFactor=i),t.isMeshStandardMaterial?(r.pbrMetallicRoughness.metallicFactor=t.metalness,r.pbrMetallicRoughness.roughnessFactor=t.roughness):(r.pbrMetallicRoughness.metallicFactor=.5,r.pbrMetallicRoughness.roughnessFactor=.5),t.metalnessMap||t.roughnessMap){const e=this.buildMetalRoughTexture(t.metalnessMap,t.roughnessMap),s={index:this.processTexture(e)};this.applyTextureTransform(s,e),r.pbrMetallicRoughness.metallicRoughnessTexture=s}if(t.map){const e={index:this.processTexture(t.map)};this.applyTextureTransform(e,t.map),r.pbrMetallicRoughness.baseColorTexture=e}if(t.emissive){const e=t.emissive;if(Math.max(e.r,e.g,e.b)>0&&(r.emissiveFactor=t.emissive.toArray()),t.emissiveMap){const e={index:this.processTexture(t.emissiveMap)};this.applyTextureTransform(e,t.emissiveMap),r.emissiveTexture=e}}if(t.normalMap){const e={index:this.processTexture(t.normalMap)};t.normalScale&&1!==t.normalScale.x&&(e.scale=t.normalScale.x),this.applyTextureTransform(e,t.normalMap),r.normalTexture=e}if(t.aoMap){const e={index:this.processTexture(t.aoMap),texCoord:1};1!==t.aoMapIntensity&&(e.strength=t.aoMapIntensity),this.applyTextureTransform(e,t.aoMap),r.occlusionTexture=e}t.transparent?r.alphaMode="BLEND":t.alphaTest>0&&(r.alphaMode="MASK",r.alphaCutoff=t.alphaTest),t.side===e.DoubleSide&&(r.doubleSided=!0),""!==t.name&&(r.name=t.name),this.serializeUserData(t,r),this._invokeAll((function(e){e.writeMaterial&&e.writeMaterial(t,r)}));const a=n.materials.push(r)-1;return s.materials.set(t,a),a}processMesh(t){const s=this.cache,c=this.json,l=[t.geometry.uuid];if(Array.isArray(t.material))for(let e=0,n=t.material.length;e<n;e++)l.push(t.material[e].uuid);else l.push(t.material.uuid);const u=l.join(":");if(s.meshes.has(u))return s.meshes.get(u);const h=t.geometry;let p;p=t.isLineSegments?r:t.isLineLoop?i:t.isLine?a:t.isPoints?n:t.material.wireframe?r:o;const m={},f={},g=[],d=[],x={uv:"TEXCOORD_0",uv2:"TEXCOORD_1",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},y=h.getAttribute("normal");void 0===y||this.isNormalizedNormalAttribute(y)||h.setAttribute("normal",this.createNormalizedNormalAttribute(y));let b=null;for(let n in h.attributes){if("morph"===n.slice(0,5))continue;const t=h.attributes[n];n=x[n]||n.toUpperCase();if(/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(n)||(n="_"+n),s.attributes.has(this.getUID(t))){f[n]=s.attributes.get(this.getUID(t));continue}b=null;const r=t.array;"JOINTS_0"!==n||r instanceof Uint16Array||r instanceof Uint8Array||(b=new e.BufferAttribute(new Uint16Array(r),t.itemSize,t.normalized));const i=this.processAccessor(b||t,h);null!==i&&(n.startsWith("_")||this.detectMeshQuantization(n,t),f[n]=i,s.attributes.set(this.getUID(t),i))}if(void 0!==y&&h.setAttribute("normal",y),0===Object.keys(f).length)return null;if(void 0!==t.morphTargetInfluences&&t.morphTargetInfluences.length>0){const e=[],n=[],r={};if(void 0!==t.morphTargetDictionary)for(const s in t.morphTargetDictionary)r[t.morphTargetDictionary[s]]=s;for(let i=0;i<t.morphTargetInfluences.length;++i){const a={};let o=!1;for(const e in h.morphAttributes){if("position"!==e&&"normal"!==e){o||(o=!0);continue}const t=h.morphAttributes[e][i],n=e.toUpperCase(),r=h.attributes[e];if(s.attributes.has(this.getUID(t,!0))){a[n]=s.attributes.get(this.getUID(t,!0));continue}const c=t.clone();if(!h.morphTargetsRelative)for(let e=0,s=t.count;e<s;e++)for(let n=0;n<t.itemSize;n++)0===n&&c.setX(e,t.getX(e)-r.getX(e)),1===n&&c.setY(e,t.getY(e)-r.getY(e)),2===n&&c.setZ(e,t.getZ(e)-r.getZ(e)),3===n&&c.setW(e,t.getW(e)-r.getW(e));a[n]=this.processAccessor(c,h),s.attributes.set(this.getUID(r,!0),a[n])}d.push(a),e.push(t.morphTargetInfluences[i]),void 0!==t.morphTargetDictionary&&n.push(r[i])}m.weights=e,n.length>0&&(m.extras={},m.extras.targetNames=n)}const M=Array.isArray(t.material);if(M&&0===h.groups.length)return null;const T=M?t.material:[t.material],w=M?h.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let e=0,n=w.length;e<n;e++){const t={mode:p,attributes:f};if(this.serializeUserData(h,t),d.length>0&&(t.targets=d),null!==h.index){let n=this.getUID(h.index);void 0===w[e].start&&void 0===w[e].count||(n+=":"+w[e].start+":"+w[e].count),s.attributes.has(n)?t.indices=s.attributes.get(n):(t.indices=this.processAccessor(h.index,h,w[e].start,w[e].count),s.attributes.set(n,t.indices)),null===t.indices&&delete t.indices}const n=this.processMaterial(T[w[e].materialIndex]);null!==n&&(t.material=n),g.push(t)}m.primitives=g,c.meshes||(c.meshes=[]),this._invokeAll((function(e){e.writeMesh&&e.writeMesh(t,m)}));const A=c.meshes.push(m)-1;return s.meshes.set(u,A),A}detectMeshQuantization(e,s){if(this.extensionsUsed.KHR_mesh_quantization)return;let n;switch(s.array.constructor){case Int8Array:n="byte";break;case Uint8Array:n="unsigned byte";break;case Int16Array:n="short";break;case Uint16Array:n="unsigned short";break;default:return}s.normalized&&(n+=" normalized");const r=e.split("_",1)[0];t[r]&&t[r].includes(n)&&(this.extensionsUsed.KHR_mesh_quantization=!0,this.extensionsRequired.KHR_mesh_quantization=!0)}processCamera(t){const s=this.json;s.cameras||(s.cameras=[]);const n=t.isOrthographicCamera,r={type:n?"orthographic":"perspective"};return n?r.orthographic={xmag:2*t.right,ymag:2*t.top,zfar:t.far<=0?.001:t.far,znear:t.near<0?0:t.near}:r.perspective={aspectRatio:t.aspect,yfov:e.MathUtils.degToRad(t.fov),zfar:t.far<=0?.001:t.far,znear:t.near<0?0:t.near},""!==t.name&&(r.name=t.type),s.cameras.push(r)-1}processAnimation(t,n){const r=this.json,i=this.nodeMap;r.animations||(r.animations=[]);const a=(t=s.Utils.mergeMorphTargetTracks(t.clone(),n)).tracks,o=[],c=[];for(let s=0;s<a.length;++s){const t=a[s],r=e.PropertyBinding.parseTrackName(t.name);let l=e.PropertyBinding.findNode(n,r.nodeName);const u=S[r.propertyName];if("bones"===r.objectName&&(l=!0===l.isSkinnedMesh?l.skeleton.getBoneByName(r.objectIndex):void 0),!l||!u)return null;const h=1;let p,m=t.values.length/t.times.length;u===S.morphTargetInfluences&&(m/=l.morphTargetInfluences.length),!0===t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline?(p="CUBICSPLINE",m/=3):p=t.getInterpolation()===e.InterpolateDiscrete?"STEP":"LINEAR",c.push({input:this.processAccessor(new e.BufferAttribute(t.times,h)),output:this.processAccessor(new e.BufferAttribute(t.values,m)),interpolation:p}),o.push({sampler:c.length-1,target:{node:i.get(l),path:u}})}return r.animations.push({name:t.name||"clip_"+r.animations.length,samplers:c,channels:o}),r.animations.length-1}processSkin(t){const s=this.json,n=this.nodeMap,r=s.nodes[n.get(t)],i=t.skeleton;if(void 0===i)return null;const a=t.skeleton.bones[0];if(void 0===a)return null;const o=[],c=new Float32Array(16*i.bones.length),l=new e.Matrix4;for(let e=0;e<i.bones.length;++e)o.push(n.get(i.bones[e])),l.copy(i.boneInverses[e]),l.multiply(t.bindMatrix).toArray(c,16*e);void 0===s.skins&&(s.skins=[]),s.skins.push({inverseBindMatrices:this.processAccessor(new e.BufferAttribute(c,16)),joints:o,skeleton:n.get(a)});return r.skin=s.skins.length-1}processNode(e){const t=this.json,s=this.options,n=this.nodeMap;t.nodes||(t.nodes=[]);const r={};if(s.trs){const t=e.quaternion.toArray(),s=e.position.toArray(),n=e.scale.toArray();U(t,[0,0,0,1])||(r.rotation=t),U(s,[0,0,0])||(r.translation=s),U(n,[1,1,1])||(r.scale=n)}else e.matrixAutoUpdate&&e.updateMatrix(),!1===U(e.matrix.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])&&(r.matrix=e.matrix.elements);if(""!==e.name&&(r.name=String(e.name)),this.serializeUserData(e,r),e.isMesh||e.isLine||e.isPoints){const t=this.processMesh(e);null!==t&&(r.mesh=t)}else e.isCamera&&(r.camera=this.processCamera(e));if(e.isSkinnedMesh&&this.skins.push(e),e.children.length>0){const t=[];for(let n=0,r=e.children.length;n<r;n++){const r=e.children[n];if(r.visible||!1===s.onlyVisible){const e=this.processNode(r);null!==e&&t.push(e)}}t.length>0&&(r.children=t)}this._invokeAll((function(t){t.writeNode&&t.writeNode(e,r)}));const i=t.nodes.push(r)-1;return n.set(e,i),i}processScene(e){const t=this.json,s=this.options;t.scenes||(t.scenes=[],t.scene=0);const n={};""!==e.name&&(n.name=e.name),t.scenes.push(n);const r=[];for(let i=0,a=e.children.length;i<a;i++){const t=e.children[i];if(t.visible||!1===s.onlyVisible){const e=this.processNode(t);null!==e&&r.push(e)}}r.length>0&&(n.nodes=r),this.serializeUserData(e,n)}processObjects(t){const s=new e.Scene;s.name="AuxScene";for(let e=0;e<t.length;e++)s.children.push(t[e]);this.processScene(s)}processInput(t){const s=this.options;t=t instanceof Array?t:[t],this._invokeAll((function(e){e.beforeParse&&e.beforeParse(t)}));const n=[];for(let r=0;r<t.length;r++)t[r]instanceof e.Scene?this.processScene(t[r]):n.push(t[r]);n.length>0&&this.processObjects(n);for(let e=0;e<this.skins.length;++e)this.processSkin(this.skins[e]);for(let e=0;e<s.animations.length;++e)this.processAnimation(s.animations[e],t[0]);this._invokeAll((function(e){e.afterParse&&e.afterParse(t)}))}_invokeAll(e){for(let t=0,s=this.plugins.length;t<s;t++)e(this.plugins[t])}}class F{constructor(e){this.writer=e,this.name="KHR_lights_punctual"}writeNode(e,t){if(!e.isLight)return;if(!e.isDirectionalLight&&!e.isPointLight&&!e.isSpotLight)return;const s=this.writer,n=s.json,r=s.extensionsUsed,i={};e.name&&(i.name=e.name),i.color=e.color.toArray(),i.intensity=e.intensity,e.isDirectionalLight?i.type="directional":e.isPointLight?(i.type="point",e.distance>0&&(i.range=e.distance)):e.isSpotLight&&(i.type="spot",e.distance>0&&(i.range=e.distance),i.spot={},i.spot.innerConeAngle=(e.penumbra-1)*e.angle*-1,i.spot.outerConeAngle=e.angle),void 0!==e.decay&&e.decay,e.target&&(e.target.parent!==e||0!==e.target.position.x||0!==e.target.position.y||e.target.position.z),r[this.name]||(n.extensions=n.extensions||{},n.extensions[this.name]={lights:[]},r[this.name]=!0);const a=n.extensions[this.name].lights;a.push(i),t.extensions=t.extensions||{},t.extensions[this.name]={light:a.length-1}}}class E{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}writeMaterial(e,t){if(!e.isMeshBasicMaterial)return;const s=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},s[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}}class O{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.clearcoat)return;const s=this.writer,n=s.extensionsUsed,r={};if(r.clearcoatFactor=e.clearcoat,e.clearcoatMap){const t={index:s.processTexture(e.clearcoatMap)};s.applyTextureTransform(t,e.clearcoatMap),r.clearcoatTexture=t}if(r.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){const t={index:s.processTexture(e.clearcoatRoughnessMap)};s.applyTextureTransform(t,e.clearcoatRoughnessMap),r.clearcoatRoughnessTexture=t}if(e.clearcoatNormalMap){const t={index:s.processTexture(e.clearcoatNormalMap)};s.applyTextureTransform(t,e.clearcoatNormalMap),r.clearcoatNormalTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}}class D{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.iridescence)return;const s=this.writer,n=s.extensionsUsed,r={};if(r.iridescenceFactor=e.iridescence,e.iridescenceMap){const t={index:s.processTexture(e.iridescenceMap)};s.applyTextureTransform(t,e.iridescenceMap),r.iridescenceTexture=t}if(r.iridescenceIor=e.iridescenceIOR,r.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],r.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){const t={index:s.processTexture(e.iridescenceThicknessMap)};s.applyTextureTransform(t,e.iridescenceThicknessMap),r.iridescenceThicknessTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}}class B{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)return;const s=this.writer,n=s.extensionsUsed,r={};if(r.transmissionFactor=e.transmission,e.transmissionMap){const t={index:s.processTexture(e.transmissionMap)};s.applyTextureTransform(t,e.transmissionMap),r.transmissionTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}}class j{constructor(e){this.writer=e,this.name="KHR_materials_volume"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)return;const s=this.writer,n=s.extensionsUsed,r={};if(r.thicknessFactor=e.thickness,e.thicknessMap){const t={index:s.processTexture(e.thicknessMap)};s.applyTextureTransform(t,e.thicknessMap),r.thicknessTexture=t}r.attenuationDistance=e.attenuationDistance,r.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}}class P{constructor(e){this.writer=e,this.name="KHR_materials_ior"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1.5===e.ior)return;const s=this.writer.extensionsUsed,n={};n.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=n,s[this.name]=!0}}class V{constructor(e){this.writer=e,this.name="KHR_materials_specular"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1===e.specularIntensity&&e.specularColor.equals(k)&&!e.specularIntensityMap&&!e.specularColorTexture)return;const s=this.writer,n=s.extensionsUsed,r={};if(e.specularIntensityMap){const t={index:s.processTexture(e.specularIntensityMap)};s.applyTextureTransform(t,e.specularIntensityMap),r.specularTexture=t}if(e.specularColorMap){const t={index:s.processTexture(e.specularColorMap)};s.applyTextureTransform(t,e.specularColorMap),r.specularColorTexture=t}r.specularFactor=e.specularIntensity,r.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}}class H{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.sheen)return;const s=this.writer,n=s.extensionsUsed,r={};if(e.sheenRoughnessMap){const t={index:s.processTexture(e.sheenRoughnessMap)};s.applyTextureTransform(t,e.sheenRoughnessMap),r.sheenRoughnessTexture=t}if(e.sheenColorMap){const t={index:s.processTexture(e.sheenColorMap)};s.applyTextureTransform(t,e.sheenColorMap),r.sheenColorTexture=t}r.sheenRoughnessFactor=e.sheenRoughness,r.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}}class K{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}writeMaterial(e,t){if(!e.isMeshStandardMaterial||1===e.emissiveIntensity)return;const s=this.writer.extensionsUsed,n={};n.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=n,s[this.name]=!0}}s.Utils={insertKeyframe:function(e,t){const s=.001,n=e.getValueSize(),r=new e.TimeBufferType(e.times.length+1),i=new e.ValueBufferType(e.values.length+n),a=e.createInterpolant(new e.ValueBufferType(n));let o;if(0===e.times.length){r[0]=t;for(let e=0;e<n;e++)i[e]=0;o=0}else if(t<e.times[0]){if(Math.abs(e.times[0]-t)<s)return 0;r[0]=t,r.set(e.times,1),i.set(a.evaluate(t),0),i.set(e.values,n),o=0}else if(t>e.times[e.times.length-1]){if(Math.abs(e.times[e.times.length-1]-t)<s)return e.times.length-1;r[r.length-1]=t,r.set(e.times,0),i.set(e.values,0),i.set(a.evaluate(t),e.values.length),o=r.length-1}else for(let c=0;c<e.times.length;c++){if(Math.abs(e.times[c]-t)<s)return c;if(e.times[c]<t&&e.times[c+1]>t){r.set(e.times.slice(0,c+1),0),r[c+1]=t,r.set(e.times.slice(c+1),c+2),i.set(e.values.slice(0,(c+1)*n),0),i.set(a.evaluate(t),(c+1)*n),i.set(e.values.slice((c+1)*n),(c+2)*n),o=c+1;break}}return e.times=r,e.values=i,o},mergeMorphTargetTracks:function(t,s){const n=[],r={},i=t.tracks;for(let a=0;a<i.length;++a){let t=i[a];const o=e.PropertyBinding.parseTrackName(t.name),c=e.PropertyBinding.findNode(s,o.nodeName);if("morphTargetInfluences"!==o.propertyName||void 0===o.propertyIndex){n.push(t);continue}if(t.createInterpolant!==t.InterpolantFactoryMethodDiscrete&&t.createInterpolant!==t.InterpolantFactoryMethodLinear){if(t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");t=t.clone(),t.setInterpolation(e.InterpolateLinear)}const l=c.morphTargetInfluences.length,u=c.morphTargetDictionary[o.propertyIndex];if(void 0===u)throw new Error("THREE.GLTFExporter: Morph target name not found: "+o.propertyIndex);let h;if(void 0===r[c.uuid]){h=t.clone();const e=new h.ValueBufferType(l*h.times.length);for(let t=0;t<h.times.length;t++)e[t*l+u]=h.values[t];h.name=(o.nodeName||"")+".morphTargetInfluences",h.values=e,r[c.uuid]=h,n.push(h);continue}const p=t.createInterpolant(new t.ValueBufferType(1));h=r[c.uuid];for(let e=0;e<h.times.length;e++)h.values[e*l+u]=p.evaluate(h.times[e]);for(let e=0;e<t.times.length;e++){const s=this.insertKeyframe(h,t.times[e]);h.values[s*l+u]=t.values[e]}}return t.tracks=n,t}},exports.GLTFExporter=s;