babylonjs-serializers
Advanced tools
Comparing version 3.2.0-rc.4 to 3.2.0
@@ -1,2 +0,2 @@ | ||
!(function(e,t){var r=[],a=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(a=a||require("babylonjs"),module.exports=t(a)):"function"==typeof define&&define.amd?(r.push("babylonjs"),define("babylonjs-serializers",r,t)):"object"==typeof exports?(a=a||require("babylonjs"),exports["babylonjs-serializers"]=t(a)):e.BABYLON=t(a)})(this,(function(e){e=e||this.BABYLON;var e;this&&this.__decorate,this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}})();!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,a,i){var n=[],o=1;r&&(a||(a="mat"),n.push("mtllib "+a+".mtl"));for(var s=0;s<t.length;s++){n.push("g object"+s),n.push("o object_"+s);var l=null;if(i){var u=e.Matrix.Translation(t[s].position.x,t[s].position.y,t[s].position.z);l=e.Matrix.Translation(-t[s].position.x,-t[s].position.y,-t[s].position.z),t[s].bakeTransformIntoVertices(u)}if(r){var c=t[s].material;c&&n.push("usemtl "+c.id)}var h=t[s].geometry;if(h){var f=h.getVerticesData("position"),p=h.getVerticesData("normal"),m=h.getVerticesData("uv"),d=h.getIndices(),g=0;if(f&&p&&m&&d){for(var T=0;T<f.length;T+=3)n.push("v "+f[T]+" "+f[T+1]+" "+f[T+2]),g++;for(T=0;T<p.length;T+=3)n.push("vn "+p[T]+" "+p[T+1]+" "+p[T+2]);for(T=0;T<m.length;T+=2)n.push("vt "+m[T]+" "+m[T+1]);for(T=0;T<d.length;T+=3)n.push("f "+(d[T+2]+o)+"/"+(d[T+2]+o)+"/"+(d[T+2]+o)+" "+(d[T+1]+o)+"/"+(d[T+1]+o)+"/"+(d[T+1]+o)+" "+(d[T]+o)+"/"+(d[T]+o)+"/"+(d[T]+o));i&&l&&t[s].bakeTransformIntoVertices(l),o+=g}}}return n.join("\n")},t.MTL=function(e){var t=[],r=e.material;t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4));return r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},t})();e.OBJExport=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,""),n=new e.GLTF2._Exporter(t,a);return t.isReady?n._generateGLTF(i):(e.Tools.Error("glTF Serializer: Scene is not ready!"),null)},t.GLB=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,""),n=new e.GLTF2._Exporter(t,a);return t.isReady?n._generateGLB(i):(e.Tools.Error("glTF Serializer: Scene is not ready!"),null)},t})();e.GLTF2Export=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function r(e,t){this.asset={generator:"BabylonJS",version:"2.0"},this.babylonScene=e,this.bufferViews=[],this.accessors=[],this.meshes=[],this.scenes=[],this.nodes=[],this.images=[],this.materials=[],this.textures=[],this.animations=[],this.imageData={},this.convertToRightHandedSystem=!this.babylonScene.useRightHandedSystem;var r=t||{};this.shouldExportMesh=r.shouldExportMesh?r.shouldExportMesh:function(e){return!0},this.animationSampleRate=r.animationSampleRate?r.animationSampleRate:1/60}return r.prototype.writeAttributeData=function(r,a,i){for(var n,o,s=e.VertexBuffer.DeduceStride(r),l=0,u=a.length/s;l<u;++l){if(o=l*s,r===e.VertexBuffer.PositionKind||r===e.VertexBuffer.NormalKind){var c=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedVector3FromRef(c),n=c.asArray()}else if(r===e.VertexBuffer.TangentKind||r===e.VertexBuffer.ColorKind){var c=e.Vector4.FromArray(a,o);this.convertToRightHandedSystem&&r!==e.VertexBuffer.ColorKind&&t._GLTFUtilities.GetRightHandedVector4FromRef(c),n=c.asArray()}else r===e.VertexBuffer.UVKind||r===e.VertexBuffer.UV2Kind?(this.convertToRightHandedSystem,n=[a[o],a[o+1]]):(e.Tools.Warn("Unsupported Vertex Buffer Type: "+r),n=[]);n.forEach((function(e){i.setFloat32(e)}))}return 4*a.length},r.prototype.generateJSON=function(e,r,a){var i,n,o,s={byteLength:this.totalByteLength},l=this.totalByteLength,u={asset:this.asset};if(s.byteLength&&(u.buffers=[s]),this.nodes&&this.nodes.length&&(u.nodes=this.nodes),this.meshes&&this.meshes.length&&(u.meshes=this.meshes),this.scenes&&this.scenes.length&&(u.scenes=this.scenes,u.scene=0),this.bufferViews&&this.bufferViews.length&&(u.bufferViews=this.bufferViews),this.accessors&&this.accessors.length&&(u.accessors=this.accessors),this.animations&&this.animations.length&&(u.animations=this.animations),this.materials&&this.materials.length&&(u.materials=this.materials),this.textures&&this.textures.length&&(u.textures=this.textures),this.images&&this.images.length)if(e){u.images=[];var c=this;this.images.forEach((function(e){e.uri&&(n=c.imageData[e.uri],i=e.uri.split(".")[0]+" image",o=t._GLTFUtilities.CreateBufferView(0,l,n.data.length,void 0,i),l+=n.data.buffer.byteLength,c.bufferViews.push(o),e.bufferView=c.bufferViews.length-1,e.name=i,e.mimeType=n.mimeType,e.uri=void 0,u.images||(u.images=[]),u.images.push(e))})),s.byteLength=l}else u.images=this.images;return e||(s.uri=r+".bin"),a?JSON.stringify(u,null,2):JSON.stringify(u)},r.prototype._generateGLTF=function(t){var r=this.generateBinary(),a=this.generateJSON(!1,t,!0),i=new Blob([r],{type:"application/octet-stream"}),n=t+".gltf",o=t+".bin",s=new e.GLTFData;if(s.glTFFiles[n]=a,s.glTFFiles[o]=i,this.imageData)for(var l in this.imageData)s.glTFFiles[l]=new Blob([this.imageData[l].data],{type:this.imageData[l].mimeType});return s},r.prototype.generateBinary=function(){var e=new a(4);return this.createScene(this.babylonScene,e),e.getArrayBuffer()},r.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},r.prototype._generateGLB=function(t){var r=this.generateBinary(),a=this.generateJSON(!0),i=t+".glb",n=a.length,o=0;for(var s in this.imageData)o+=this.imageData[s].data.byteLength;var l=this._getPadding(n),u=this._getPadding(r.byteLength),c=this._getPadding(o),h=28+n+l+r.byteLength+u+o+c,f=new ArrayBuffer(12),p=new DataView(f);p.setUint32(0,1179937895,!0),p.setUint32(4,2,!0),p.setUint32(8,h,!0);var m=new ArrayBuffer(8+n+l),d=new DataView(m);d.setUint32(0,n+l,!0),d.setUint32(4,1313821514,!0);for(var g=new Uint8Array(m,8),T=0;T<n;++T)g[T]=a.charCodeAt(T);for(var y=new Uint8Array(m,8+n),T=0;T<l;++T)y[T]=32;var x=new ArrayBuffer(8),v=new DataView(x);v.setUint32(0,r.byteLength+o+c,!0),v.setUint32(4,5130562,!0);for(var b=new ArrayBuffer(u),_=new Uint8Array(b),T=0;T<u;++T)_[T]=0;for(var C=new ArrayBuffer(c),A=new Uint8Array(C),T=0;T<c;++T)A[T]=0;var B=[f,m,x,r];for(var s in this.imageData)B.push(this.imageData[s].data.buffer);B.push(b),B.push(C);var F=new Blob(B,{type:"application/octet-stream"}),M=new e.GLTFData;return M.glTFFiles[i]=F,M},r.prototype.setNodeTransformation=function(r,a){a.position.equalsToFloats(0,0,0)||(r.translation=this.convertToRightHandedSystem?t._GLTFUtilities.GetRightHandedVector3(a.position).asArray():a.position.asArray()),a.scaling.equalsToFloats(1,1,1)||(r.scale=a.scaling.asArray());var i=e.Quaternion.RotationYawPitchRoll(a.rotation.y,a.rotation.x,a.rotation.z);a.rotationQuaternion&&(i=i.multiply(a.rotationQuaternion)),0===i.x&&0===i.y&&0===i.z&&1===i.w||(this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedQuaternionFromRef(i),r.rotation=i.normalize().asArray())},r.prototype.createBufferViewKind=function(r,a,i,n){var o,s,l,u=null;a instanceof e.Mesh?u=a:a instanceof e.InstancedMesh&&(u=a.sourceMesh),u&&(s=u.getVerticesData(r))&&(o=4*s.length,l=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),o,n,r+" - "+u.name),this.bufferViews.push(l),this.writeAttributeData(r,s,i))},r.prototype.setPrimitiveAttributes=function(r,a,i){var n,o,s,l,u,c,h,f,p,m,d,g,T,y,x=null,v=null,b=null;a instanceof e.Mesh?x=a:a instanceof e.InstancedMesh&&(x=a.sourceMesh);var _=[{kind:e.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:e.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(x){for(var C=0,A=_;C<A.length;C++){var B=A[C];n=B.kind,x.isVerticesDataPresent(n)&&(this.createBufferViewKind(n,a,i,B.byteStride),B.bufferViewIndex=this.bufferViews.length-1)}if(x.getTotalIndices()&&(o=x.getIndices())){s=4*o.length,l=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),s,void 0,"Indices - "+x.name),this.bufferViews.push(l),b=this.bufferViews.length-1;for(var F=0,M=o.length;F<M;++F)i.setUInt32(o[F])}if(a.subMeshes){u=!1;for(var E=0,R=a.subMeshes;E<R.length;E++){var S=R[E];c={attributes:{}};for(var L=0,w=_;L<w.length;L++){var B=w[L];if(n=B.kind,(h=x.getVerticesData(n))&&(f=e.VertexBuffer.DeduceStride(n),void 0!=(y=B.bufferViewIndex)))switch(p={min:null,max:null},n==e.VertexBuffer.PositionKind&&(p=t._GLTFUtilities.CalculateMinMaxPositions(h,0,h.length/f,this.convertToRightHandedSystem)),T=t._GLTFUtilities.CreateAccessor(y,n+" - "+a.name,B.accessorType,5126,h.length/f,0,p.min,p.max),this.accessors.push(T),n){case e.VertexBuffer.PositionKind:c.attributes.POSITION=this.accessors.length-1;break;case e.VertexBuffer.NormalKind:c.attributes.NORMAL=this.accessors.length-1;break;case e.VertexBuffer.ColorKind:c.attributes.COLOR_0=this.accessors.length-1;break;case e.VertexBuffer.TangentKind:c.attributes.TANGENT=this.accessors.length-1;break;case e.VertexBuffer.UVKind:c.attributes.TEXCOORD_0=this.accessors.length-1,u=!0;break;case e.VertexBuffer.UV2Kind:c.attributes.TEXCOORD_1=this.accessors.length-1,u=!0;break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+n)}}b&&(T=t._GLTFUtilities.CreateAccessor(b,"indices - "+a.name,"SCALAR",5125,S.indexCount,4*S.indexStart,null,null),this.accessors.push(T),c.indices=this.accessors.length-1),x.material&&(v=null,x.material instanceof e.StandardMaterial||x.material instanceof e.PBRMetallicRoughnessMaterial||x.material instanceof e.PBRMaterial?v=a.getScene().materials.indexOf(x.material):x.material instanceof e.MultiMaterial?(d=x.material,(g=d.subMaterials[S.materialIndex])&&(v=a.getScene().materials.indexOf(g))):e.Tools.Warn("Material type "+x.material.getClassName()+" for material "+x.material.name+" is not yet implemented in glTF serializer."),null!=v&&Object.keys(c.attributes).length>0&&(u?(t._GLTFMaterial._HasTexturesPresent(this.materials[v])||(delete c.attributes.TEXCOORD_0,delete c.attributes.TEXCOORD_1),c.material=v):t._GLTFMaterial._HasTexturesPresent(this.materials[v])&&(m=t._GLTFMaterial._StripTexturesFromMaterial(this.materials[v]),this.materials.push(m),c.material=this.materials.length-1))),r.primitives.push(c)}}}},r.prototype.createScene=function(r,a){if(r.meshes.length){var i,n,o,s=r.meshes,l={nodes:[]};t._GLTFMaterial._ConvertMaterialsToGLTF(r.materials,"image/png",this.images,this.textures,this.materials,this.imageData,!0),this.nodeMap=this.createNodeMapAndAnimations(r,a),this.totalByteLength=a.getByteOffset();var u=this;s.forEach((function(t){if(i=u.nodeMap[t.uniqueId],n=u.nodes[i],t.parent||(u.shouldExportMesh(t)?l.nodes.push(i):e.Tools.Log("Omitting "+t.name+" from scene.")),o=t.getDescendants(!0),!n.children&&o&&o.length){n.children=[];for(var r=0,a=o;r<a.length;r++){var s=a[r];n.children.push(u.nodeMap[s.uniqueId])}}})),this.scenes.push(l)}},r.prototype.createNodeMapAndAnimations=function(e,r){var a,i,n={},o={name:"runtime animations",channels:[],samplers:[]},s=[],l=this;return e.meshes.forEach((function(u){i=l.createNode(u,r),l.nodes.push(i),a=l.nodes.length-1,n[u.uniqueId]=a,!e.animationGroups.length&&u.animations.length&&t._GLTFAnimation._CreateNodeAnimationFromMeshAnimations(u,o,s,n,l.nodes,r,l.bufferViews,l.accessors,l.convertToRightHandedSystem,l.animationSampleRate)})),o.channels.length&&o.samplers.length&&this.animations.push(o),s.forEach((function(e){e.channels.length&&e.samplers.length&&l.animations.push(e)})),e.animationGroups.length&&t._GLTFAnimation._CreateNodeAnimationFromAnimationGroups(e,l.animations,n,this.nodes,r,this.bufferViews,this.accessors,this.convertToRightHandedSystem,l.animationSampleRate),n},r.prototype.createNode=function(e,t){var r={},a={primitives:[]};return e.name&&(r.name=e.name),this.setNodeTransformation(r,e),this.setPrimitiveAttributes(a,e,t),a.primitives.length&&(this.meshes.push(a),r.mesh=this.meshes.length-1),r},r})();t._Exporter=r;var a=(function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype.resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),a=new Uint8Array(t),i=0,n=a.byteLength;i<n;++i)a[i]=r[i];this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer)},e.prototype.getArrayBuffer=function(){return this.resizeBuffer(this.getByteOffset()),this._arrayBuffer},e.prototype.getByteOffset=function(){return this._byteOffset},e.prototype.setUInt8=function(e){this._byteOffset+1>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset++,e)},e.prototype.setFloat32=function(e){this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.setUInt32=function(e){this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e})();t._BinaryWriter=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){var t=(function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-1!==e.indexOf(t,e.length-t.length)}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var a=this.glTFFiles[t],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([a],i)),r.click()}},e})();e.GLTFData=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function t(){}return t.FuzzyEquals=function(t,r,a){return e.Scalar.WithinEpsilon(t.r,r.r,a)&&e.Scalar.WithinEpsilon(t.g,r.g,a)&&e.Scalar.WithinEpsilon(t.b,r.b,a)},t._ConvertMaterialsToGLTF=function(r,a,i,n,o,s,l){for(var u=0;u<r.length;++u){var c=r[u];c instanceof e.StandardMaterial?t._ConvertStandardMaterial(c,a,i,n,o,s,l):c instanceof e.PBRMetallicRoughnessMaterial?t._ConvertPBRMetallicRoughnessMaterial(c,a,i,n,o,s,l):c instanceof e.PBRMaterial?t._ConvertPBRMaterial(c,a,i,n,o,s,l):e.Tools.Error("Unsupported material type: "+c.name)}},t._StripTexturesFromMaterial=function(e){var t={};if(e){t.name=e.name,t.doubleSided=e.doubleSided,t.alphaMode=e.alphaMode,t.alphaCutoff=e.alphaCutoff,t.emissiveFactor=e.emissiveFactor;var r=e.pbrMetallicRoughness;r&&(t.pbrMetallicRoughness={},t.pbrMetallicRoughness.baseColorFactor=r.baseColorFactor,t.pbrMetallicRoughness.metallicFactor=r.metallicFactor,t.pbrMetallicRoughness.roughnessFactor=r.roughnessFactor)}return t},t._HasTexturesPresent=function(e){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},t._ConvertToGLTFPBRMetallicRoughness=function(t){function r(e,t,r,a,i){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*a+e*e*e*i}var a=new e.Vector2(0,1),i=new e.Vector2(0,.1),n=new e.Vector2(0,.1),o=new e.Vector2(1300,.1),s=t.diffuseColor.toLinearSpace().scale(.5),l=t.alpha,u=e.Scalar.Clamp(t.specularPower,0,this._maxSpecularPower),c=(function(e){return r(Math.pow(e/o.x,.333333),a.y,i.y,n.y,o.y)})(u);return{baseColorFactor:[s.r,s.g,s.b,l],metallicFactor:0,roughnessFactor:c}},t._SolveMetallic=function(r,a,i){if(a<t._dielectricSpecular.r)return t._dielectricSpecular,0;var n=t._dielectricSpecular.r,o=r*i/(1-t._dielectricSpecular.r)+a-2*t._dielectricSpecular.r,s=t._dielectricSpecular.r-a,l=o*o-4*n*s;return e.Scalar.Clamp((-o+Math.sqrt(l))/(2*n),0,1)},t._GetAlphaMode=function(t){if(t instanceof e.StandardMaterial){var r=t;return 1!=r.alpha||null!=r.diffuseTexture&&r.diffuseTexture.hasAlpha||null!=r.opacityTexture?"BLEND":"OPAQUE"}if(t instanceof e.PBRMetallicRoughnessMaterial){var a=t;switch(a.transparencyMode){case e.PBRMaterial.PBRMATERIAL_OPAQUE:return"OPAQUE";case e.PBRMaterial.PBRMATERIAL_ALPHABLEND:return"BLEND";case e.PBRMaterial.PBRMATERIAL_ALPHATEST:return"MASK";case e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND:return e.Tools.Warn(t.name+": GLTF Exporter | Alpha test and blend mode not supported in glTF. Alpha blend used instead."),"BLEND";default:return e.Tools.Error("Unsupported alpha mode "+a.transparencyMode),null}}else{if(!(t instanceof e.PBRMaterial))return e.Tools.Error("Unsupported Babylon material type"),null;var i=t;switch(i.transparencyMode){case e.PBRMaterial.PBRMATERIAL_OPAQUE:return"OPAQUE";case e.PBRMaterial.PBRMATERIAL_ALPHABLEND:return"BLEND";case e.PBRMaterial.PBRMATERIAL_ALPHATEST:return"MASK";case e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND:return e.Tools.Warn(t.name+": GLTF Exporter | Alpha test and blend mode not supported in glTF. Alpha blend used instead."),"BLEND";default:return e.Tools.Error("Unsupported alpha mode "+i.transparencyMode),null}}},t._ConvertStandardMaterial=function(r,a,i,n,o,s,l){var u=t._ConvertToGLTFPBRMetallicRoughness(r),c={name:r.name};if(null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),c.doubleSided=!0),l){if(r.diffuseTexture){var h=t._ExportTexture(r.diffuseTexture,a,i,n,s);null!=h&&(u.baseColorTexture=h)}if(r.bumpTexture){var h=t._ExportTexture(r.bumpTexture,a,i,n,s);h&&(c.normalTexture=h)}if(r.emissiveTexture){var f=t._ExportTexture(r.emissiveTexture,a,i,n,s);f&&(c.emissiveTexture=f),c.emissiveFactor=[1,1,1]}if(r.ambientTexture){var h=t._ExportTexture(r.ambientTexture,a,i,n,s);if(h){var p={index:h.index};c.occlusionTexture=p,p.strength=1}}}(r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?c.alphaMode="BLEND":e.Tools.Warn(r.name+": glTF 2.0 does not support alpha mode: "+r.alphaMode.toString())),r.emissiveColor&&!this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(c.emissiveFactor=r.emissiveColor.asArray()),c.pbrMetallicRoughness=u,o.push(c)},t._ConvertPBRMetallicRoughnessMaterial=function(r,a,i,n,o,s,l){var u={};r.baseColor&&(u.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,r.alpha]),null!=r.metallic&&1!==r.metallic&&(u.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(u.roughnessFactor=r.roughness);var c={name:r.name};if(r.doubleSided&&(c.doubleSided=r.doubleSided),l){if(null!=r.baseTexture){var h=t._ExportTexture(r.baseTexture,a,i,n,s);null!=h&&(u.baseColorTexture=h)}if(r.normalTexture){var h=t._ExportTexture(r.normalTexture,a,i,n,s);h&&(c.normalTexture=h)}if(r.occlusionTexture){var h=t._ExportTexture(r.occlusionTexture,a,i,n,s);h&&(c.occlusionTexture=h,null!=r.occlusionStrength&&(c.occlusionTexture.strength=r.occlusionStrength))}if(r.emissiveTexture){var h=t._ExportTexture(r.emissiveTexture,a,i,n,s);null!=h&&(c.emissiveTexture=h)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(c.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var f=t._GetAlphaMode(r);f&&"OPAQUE"!==f&&(c.alphaMode=f,"BLEND"===f&&(c.alphaCutoff=r.alphaCutOff))}c.pbrMetallicRoughness=u,o.push(c)},t._CreateBase64FromCanvas=function(e,t,r,a){var i=document.createElement("canvas");i.id="WriteCanvas";var n=i.getContext("2d");i.width=t,i.height=r;var o=n.createImageData(t,r);return o.data.set(e),n.putImageData(o,0,0),i.toDataURL(a)},t._CreateWhiteTexture=function(t,r,a){for(var i=new Uint8Array(t*r*4),n=0;n<i.length;++n)i[n]=255;return e.RawTexture.CreateRGBATexture(i,t,r,a)},t._ResizeTexturesToSameDimensions=function(t,r,a){var i,n,o=t?t.getSize():{width:0,height:0},s=r?r.getSize():{width:0,height:0};return o.width<s.width?(i=t?e.TextureTools.CreateResizedCopy(t,s.width,s.height,!0):this._CreateWhiteTexture(s.width,s.height,a),n=r):o.width>s.width?(n=r?e.TextureTools.CreateResizedCopy(r,o.width,o.height,!0):this._CreateWhiteTexture(o.width,o.height,a),i=t):(i=t,n=r),{texture1:i,texture2:n}},t._ConvertSpecularGlossinessTexturesToMetallicRoughness=function(t,r,a,i){if(!t&&!r)return null;var n=t?t.getScene():r.getScene();if(!n)return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!"),null;var o,s,l=this._ResizeTexturesToSameDimensions(t,r,n),u=l.texture1.getSize(),c=u.width,h=u.height,f=l.texture1.readPixels();if(!(f instanceof Uint8Array))return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture1.name),null;if(o=l.texture1.readPixels(),!((f=l.texture2.readPixels())instanceof Uint8Array))return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture2.name),null;s=l.texture2.readPixels();for(var p=s.byteLength,m=new Uint8Array(p),d=new Uint8Array(p),g=e.Color3.Black(),T=0,y=0,x=0;x<h;++x)for(var v=0;v<c;++v){var b=4*(c*x+v),_=e.Color3.FromInts(o[b],o[b+1],o[b+2]).toLinearSpace().multiply(a.diffuseColor),C=e.Color3.FromInts(s[b],s[b+1],s[b+2]).toLinearSpace().multiply(a.specularColor),A=s[b+3]/255*a.glossiness,B={diffuseColor:_,specularColor:C,glossiness:A},F=this._ConvertSpecularGlossinessToMetallicRoughness(B);g.r=Math.max(g.r,F.baseColor.r),g.g=Math.max(g.g,F.baseColor.g),g.b=Math.max(g.b,F.baseColor.b),T=Math.max(T,F.metallic),y=Math.max(y,F.roughness),d[b]=255*F.baseColor.r,d[b+1]=255*F.baseColor.g,d[b+2]=255*F.baseColor.b,d[b+3]=l.texture1.hasAlpha?o[b+3]:255,m[b]=0,m[b+1]=255*F.roughness,m[b+2]=255*F.metallic,m[b+3]=255}for(var M={baseColor:g,metallic:T,roughness:y},E=!1,R=!1,x=0;x<h;++x)for(var v=0;v<c;++v){var S=4*(c*x+v);d[S]/=M.baseColor.r>this._epsilon?M.baseColor.r:1,d[S+1]/=M.baseColor.g>this._epsilon?M.baseColor.g:1,d[S+2]/=M.baseColor.b>this._epsilon?M.baseColor.b:1;var L=e.Color3.FromInts(d[S],d[S+1],d[S+2]),w=L.toGammaSpace();d[S]=255*w.r,d[S+1]=255*w.g,d[S+2]=255*w.b,this.FuzzyEquals(w,e.Color3.White(),this._epsilon)||(R=!0),m[S+1]/=M.roughness>this._epsilon?M.roughness:1,m[S+2]/=M.metallic>this._epsilon?M.metallic:1;var P=e.Color3.FromInts(255,m[S+1],m[S+2]);this.FuzzyEquals(P,e.Color3.White(),this._epsilon)||(E=!0)}if(E){var V=this._CreateBase64FromCanvas(m,c,h,i);M.metallicRoughnessTextureBase64=V}if(R){var G=this._CreateBase64FromCanvas(d,c,h,i);M.baseColorTextureBase64=G}return M},t._ConvertSpecularGlossinessToMetallicRoughness=function(r){var a=t._GetPerceivedBrightness(r.diffuseColor),i=t._GetPerceivedBrightness(r.specularColor),n=1-t._GetMaxComponent(r.specularColor),o=t._SolveMetallic(a,i,n),s=r.diffuseColor.scale(n/(1-this._dielectricSpecular.r)/Math.max(1-o,this._epsilon)),l=r.specularColor.subtract(this._dielectricSpecular.scale(1-o)).scale(1/Math.max(o,this._epsilon)),u=e.Color3.Lerp(s,l,o*o);return u=u.clampToRef(0,1,u),{baseColor:u,metallic:o,roughness:1-r.glossiness}},t._GetPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},t._GetMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},t._ConvertMetalRoughFactorsToMetallicRoughness=function(e,r,a,i,n,o,s){var l={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};if(s){if(e.albedoTexture){var u=t._ExportTexture(e.albedoTexture,r,a,i,o);u&&(n.baseColorTexture=u)}if(e.metallicTexture){var u=t._ExportTexture(e.metallicTexture,r,a,i,o);null!=u&&(n.metallicRoughnessTexture=u)}}return l},t._ConvertSpecGlossFactorsToMetallicRoughness=function(r,a,i,n,o,s,l){var u={diffuseColor:r.albedoColor||e.Color3.White(),specularColor:r.reflectivityColor||e.Color3.White(),glossiness:r.microSurface||1};if(r.reflectivityTexture&&!r.useMicroSurfaceFromReflectivityMapAlpha)return e.Tools.Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported"),null;var c=this._ConvertSpecularGlossinessTexturesToMetallicRoughness(r.albedoTexture,r.reflectivityTexture,u,a);if(c){if(l){if(c.baseColorTextureBase64){var h=t._GetTextureInfoFromBase64(c.baseColorTextureBase64,"bjsBaseColorTexture_"+n.length+".png",a,i,n,s);null!=h&&(o.baseColorTexture=h)}if(c.metallicRoughnessTextureBase64){var f=t._GetTextureInfoFromBase64(c.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+n.length+".png",a,i,n,s);null!=f&&(o.metallicRoughnessTexture=f)}}}else c=this._ConvertSpecularGlossinessToMetallicRoughness(u);return c},t._ConvertPBRMaterial=function(r,a,i,n,o,s,l){var u,c={},h={name:r.name};if(u=r.isMetallicWorkflow()?this._ConvertMetalRoughFactorsToMetallicRoughness(r,a,i,n,c,s,l):this._ConvertSpecGlossFactorsToMetallicRoughness(r,a,i,n,c,s,l)){if(this.FuzzyEquals(u.baseColor,e.Color3.White(),this._epsilon)&&r.alpha>=this._epsilon||(c.baseColorFactor=[u.baseColor.r,u.baseColor.g,u.baseColor.b,r.alpha]),null!=u.metallic&&1!==u.metallic&&(c.metallicFactor=u.metallic),null!=u.roughness&&1!==u.roughness&&(c.roughnessFactor=u.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),h.doubleSided=!0),l){if(r.bumpTexture){var f=t._ExportTexture(r.bumpTexture,a,i,n,s);f&&(h.normalTexture=f)}if(r.ambientTexture){var f=t._ExportTexture(r.ambientTexture,a,i,n,s);if(f){var p={index:f.index};h.occlusionTexture=p,r.ambientTextureStrength&&(p.strength=r.ambientTextureStrength)}}if(r.emissiveTexture){var f=t._ExportTexture(r.emissiveTexture,a,i,n,s);null!=f&&(h.emissiveTexture=f)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)||(h.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var m=t._GetAlphaMode(r);m&&"OPAQUE"!==m&&(h.alphaMode=m,"BLEND"===m&&(h.alphaCutoff=r.alphaCutOff))}h.pbrMetallicRoughness=c,o.push(h)}},t.GetPixelsFromTexture=function(t){return t.textureType,e.Engine.TEXTURETYPE_UNSIGNED_INT,t.readPixels()},t._ExportTexture=function(r,a,i,n,o){var s="texture_"+(n.length-1).toString(),l=r.getInternalTexture();null!=l&&(s=l.url||s),s=e.Tools.GetFilename(s);var u=s.split(".")[0],c="";if("image/jpeg"===a)c=".jpg";else{if("image/png"!==a)return e.Tools.Error("Unsupported mime type "+a),null;c=".png"}s=u+c;var h=t.GetPixelsFromTexture(r),f=r.getSize(),p=this._CreateBase64FromCanvas(h,f.width,f.height,a);return this._GetTextureInfoFromBase64(p,s,a,i,n,o)},t._GetTextureInfoFromBase64=function(e,t,r,a,i,n){for(var o=null,s={source:a.length},l=atob(e.split(",")[1]),u=new ArrayBuffer(l.length),c=new Uint8Array(u),h=0,f=l.length;h<f;++h)c[h]=l.charCodeAt(h);var p={data:c,mimeType:r};if(n[t]=p,"image/jpeg"===r||"image/png"===r){for(var m={uri:t},d=-1,h=0;h<a.length;++h)if(a[h].uri===t){d=h;break}-1===d?(a.push(m),s.source=a.length-1,i.push({source:a.length-1}),o={index:a.length-1}):(s.source=d,o={index:d})}return o},t._dielectricSpecular=new e.Color3(.04,.04,.04),t._maxSpecularPower=1024,t._epsilon=1e-6,t})();t._GLTFMaterial=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){!(function(t){var r;!(function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"})(r||(r={}));var a=(function(){function a(){}return a._CreateNodeAnimation=function(t,r,i,n,o,s){var l=[],u=[],c=r.getKeys(),h=a.calculateMinMaxKeyFrames(c),f=a._DeduceInterpolation(c,i,o),p=h.max-h.min,m=f.interpolationType,d=f.shouldBakeAnimation;if(d?a._CreateBakedAnimation(t,r,i,h.min,h.max,r.framePerSecond,s,l,u,h,n,o):"LINEAR"===m||"STEP"===m?a._CreateLinearOrStepAnimation(t,r,i,p,l,u,n,o):"CUBICSPLINE"===m?a._CreateCubicSplineAnimation(t,r,i,p,l,u,n,o):a._CreateBakedAnimation(t,r,i,h.min,h.max,r.framePerSecond,s,l,u,h,n,o),l.length&&u.length){return{inputs:l,outputs:u,samplerInterpolation:m,inputsMin:d?h.min:e.Tools.FloatRound(h.min/r.framePerSecond),inputsMax:d?h.max:e.Tools.FloatRound(h.max/r.framePerSecond)}}return null},a._DeduceAnimationInfo=function(t){var r=null,a="VEC3",i=!1,n=t.targetProperty.split(".");switch(n[0]){case"scaling":r="scale";break;case"position":r="translation";break;case"rotation":a="VEC4",r="rotation";break;case"rotationQuaternion":a="VEC4",i=!0,r="rotation";break;default:e.Tools.Error("Unsupported animatable property "+n[0])}return r?{animationChannelTargetPath:r,dataAccessorType:a,useQuaternion:i}:(e.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},a._CreateNodeAnimationFromMeshAnimations=function(e,t,r,i,n,o,s,l,u,c){var h;e.animations&&e.animations.forEach((function(n){var f=a._DeduceAnimationInfo(n);f&&(h={name:n.name,samplers:[],channels:[]},a.AddAnimation(""+n.name,n.hasRunningRuntimeAnimations?t:h,e,n,f.dataAccessorType,f.animationChannelTargetPath,i,o,s,l,u,f.useQuaternion,c),h.samplers.length&&h.channels.length&&r.push(h))}))},a._CreateNodeAnimationFromAnimationGroups=function(t,r,i,n,o,s,l,u,c){var h;if(t.animationGroups){t.animationGroups.forEach((function(t){h={name:t.name,channels:[],samplers:[]},t.targetedAnimations.forEach((function(t){var r=t.target,n=t.animation;if(r instanceof e.Mesh){var f=a._DeduceAnimationInfo(t.animation);if(f){var p=r;a.AddAnimation(""+n.name,h,p,n,f.dataAccessorType,f.animationChannelTargetPath,i,o,s,l,u,f.useQuaternion,c)}}})),h.channels.length&&h.samplers.length&&r.push(h)}))}},a.AddAnimation=function(e,r,i,n,o,s,l,u,c,h,f,p,m){var d,g,T,y,x,v,b,_=a._CreateNodeAnimation(i,n,s,f,p,m);if(_){var C=l[i.uniqueId],A=4*_.inputs.length;d=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),A,void 0,e+" keyframe data view"),c.push(d),_.inputs.forEach((function(e){u.setFloat32(e)})),g=t._GLTFUtilities.CreateAccessor(c.length-1,e+" keyframes","SCALAR",5126,_.inputs.length,null,[_.inputsMin],[_.inputsMax]),h.push(g),T=h.length-1,x=_.outputs.length,A="VEC3"===o?12*_.outputs.length:16*_.outputs.length,d=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),A,void 0,e+" data view"),c.push(d),_.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),g=t._GLTFUtilities.CreateAccessor(c.length-1,e+" data",o,5126,x,null,null,null),h.push(g),y=h.length-1,v={interpolation:_.samplerInterpolation,input:T,output:y},r.samplers.push(v),b={sampler:r.samplers.length-1,target:{node:C,path:s}},r.channels.push(b)}},a._CreateBakedAnimation=function(t,r,i,n,o,s,l,u,c,h,f,p){var m,d,g=e.Quaternion.Identity(),T=null,y=null,x=null,v=null,b=null,_=null;h.min=e.Tools.FloatRound(n/s);for(var C=r.getKeys(),A=0,B=C.length;A<B;++A){if(_=null,x=C[A],A+1<B)if(v=C[A+1],x.value.equals(v.value)){if(0!==A)continue;_=x.frame}else _=v.frame;else{if(b=C[A-1],x.value.equals(b.value))continue;_=o}if(_)for(var F=x.frame;F<=_;F+=l)(d=e.Tools.FloatRound(F/s))!==T&&(T=d,y=d,m=r._interpolate(F,0,void 0,r.loopMode),a._SetInterpolatedValue(t,m,d,r,i,g,u,c,f,p))}y&&(h.max=y)},a._ConvertFactorToVector3OrQuaternion=function(t,r,i,n,o,s,l){var u,c,h=null,f=a._GetBasePositionRotationOrScale(r,o,s,l);if(n===e.Animation.ANIMATIONTYPE_FLOAT)switch(u=i.targetProperty.split("."),c=u?u[1]:"",h=l?e.Quaternion.FromArray(f).normalize():e.Vector3.FromArray(f),c){case"x":case"y":h[c]=s&&l?-t:t;break;case"z":h[c]=s&&!l&&"scale"!==o?-t:t;break;case"w":h.w=t;break;default: | ||
e.Tools.Error('glTFAnimation: Unsupported component type "'+c+'" for scale animation!')}return h},a._SetInterpolatedValue=function(t,r,a,i,n,o,s,l,u,c){var h,f=i.dataType;s.push(a),"number"==typeof r&&(r=this._ConvertFactorToVector3OrQuaternion(r,t,i,f,n,u,c)),r&&("rotation"===n?(c?o=r:(h=r,e.Quaternion.RotationYawPitchRollToRef(h.y,h.x,h.z,o)),u&&(o.x*=-1,o.y*=-1,l.push(o.asArray()))):(h=r,u&&"scale"!==n&&(h.z*=-1),l.push(h.asArray())))},a._CreateLinearOrStepAnimation=function(e,t,r,i,n,o,s,l){t.getKeys().forEach((function(i){n.push(i.frame/t.framePerSecond),a._AddKeyframeValue(i,t,o,r,e,s,l)}))},a._CreateCubicSplineAnimation=function(e,t,i,n,o,s,l,u){t.getKeys().forEach((function(c){o.push(c.frame/t.framePerSecond),a.AddSplineTangent(r.INTANGENT,s,i,"CUBICSPLINE",c,n,u,l),a._AddKeyframeValue(c,t,s,i,e,l,u),a.AddSplineTangent(r.OUTTANGENT,s,i,"CUBICSPLINE",c,n,u,l)}))},a._GetBasePositionRotationOrScale=function(t,r,a,i){var n;return"rotation"===r?i?t.rotationQuaternion?(n=t.rotationQuaternion.asArray(),a&&(n[0]*=-1,n[1]*=-1)):n=e.Quaternion.Identity().asArray():(n=t.rotation.asArray(),n[2]*=-1):"translation"===r?(n=t.position.asArray(),a&&(n[2]*=-1)):n=t.scaling.asArray(),n},a._AddKeyframeValue=function(t,r,a,i,n,o,s){var l,u,c=r.dataType;c===e.Animation.ANIMATIONTYPE_VECTOR3?(l=t.value.asArray(),o&&"scale"!==i&&(l[2]*=-1),"rotation"===i?a.push(e.Vector3.FromArray(l).toQuaternion().asArray()):a.push(l)):c===e.Animation.ANIMATIONTYPE_FLOAT?(u=this._ConvertFactorToVector3OrQuaternion(t.value,n,r,c,i,o,s))&&("rotation"===i?s?a.push(u.normalize().asArray()):a.push(u.toQuaternion().normalize().asArray()):a.push(u.asArray())):c===e.Animation.ANIMATIONTYPE_QUATERNION?(l=t.value.normalize().asArray(),o&&(l[0]*=-1,l[1]*=-1),a.push(l)):e.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},a._DeduceInterpolation=function(t,r,a){var i,n,o=!1;if("rotation"===r&&!a)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,l=t.length;s<l;++s)if(n=t[s],n.inTangent||n.outTangent)if(i){if("CUBICSPLINE"!==i){i="LINEAR",o=!0;break}}else i="CUBICSPLINE";else if(i){if("CUBICSPLINE"===i||n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP&&"STEP"!==i){i="LINEAR",o=!0;break}}else i=n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return i||(i="LINEAR"),{interpolationType:i,shouldBakeAnimation:o}},a.AddSplineTangent=function(e,t,a,i,n,o,s,l){var u,c=e===r.INTANGENT?n.inTangent:n.outTangent;"CUBICSPLINE"===i&&("rotation"===a?c?(u=s?c.scale(o).asArray():c.scale(o).toQuaternion().asArray(),l&&(u[0]*=-1,u[1]*=-1)):u=[0,0,0,0]:c?(u=c.scale(o).asArray(),l&&(u[2]*=-1)):u=[0,0,0],t.push(u))},a.calculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},a})();t._GLTFAnimation=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;return (function(e){!(function(t){var r=(function(){function t(){}return t.CreateBufferView=function(e,t,r,a,i){var n={buffer:e,byteLength:r};return t&&(n.byteOffset=t),i&&(n.name=i),a&&(n.byteStride=a),n},t.CreateAccessor=function(e,t,r,a,i,n,o,s){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return o&&(l.min=o),s&&(l.max=s),n&&(l.byteOffset=n),l},t.CalculateMinMaxPositions=function(r,a,i,n){var o,s,l,u=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(i)for(var h=a,f=a+i;h<f;++h){o=3*h,s=e.Vector3.FromArray(r,o),n&&t.GetRightHandedVector3FromRef(s),l=s.asArray();for(var p=0;p<3;++p){var m=l[p];m<u[p]&&(u[p]=m),m>c[p]&&(c[p]=m),++o}}return{min:u,max:c}},t.GetRightHandedVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t.GetRightHandedVector3FromRef=function(e){e.z*=-1},t.GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},t.GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},t})();t._GLTFUtilities=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={})),e})); | ||
!(function(e,t){var r=[],a=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(a=a||require("babylonjs"),module.exports=t(a)):"function"==typeof define&&define.amd?(r.push("babylonjs"),define("babylonjs-serializers",r,t)):"object"==typeof exports?(a=a||require("babylonjs"),exports["babylonjs-serializers"]=t(a)):e.BABYLON=t(a)})(this,(function(e){e=e||this.BABYLON;var e;this&&this.__decorate,this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}})();!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,a,i){var n=[],o=1;r&&(a||(a="mat"),n.push("mtllib "+a+".mtl"));for(var s=0;s<t.length;s++){n.push("g object"+s),n.push("o object_"+s);var l=null;if(i){var u=e.Matrix.Translation(t[s].position.x,t[s].position.y,t[s].position.z);l=e.Matrix.Translation(-t[s].position.x,-t[s].position.y,-t[s].position.z),t[s].bakeTransformIntoVertices(u)}if(r){var f=t[s].material;f&&n.push("usemtl "+f.id)}var c=t[s].geometry;if(c){var h=c.getVerticesData("position"),d=c.getVerticesData("normal"),m=c.getVerticesData("uv"),p=c.getIndices(),g=0;if(h&&d&&m&&p){for(var T=0;T<h.length;T+=3)n.push("v "+h[T]+" "+h[T+1]+" "+h[T+2]),g++;for(T=0;T<d.length;T+=3)n.push("vn "+d[T]+" "+d[T+1]+" "+d[T+2]);for(T=0;T<m.length;T+=2)n.push("vt "+m[T]+" "+m[T+1]);for(T=0;T<p.length;T+=3)n.push("f "+(p[T+2]+o)+"/"+(p[T+2]+o)+"/"+(p[T+2]+o)+" "+(p[T+1]+o)+"/"+(p[T+1]+o)+"/"+(p[T+1]+o)+" "+(p[T]+o)+"/"+(p[T]+o)+"/"+(p[T]+o));i&&l&&t[s].bakeTransformIntoVertices(l),o+=g}}}return n.join("\n")},t.MTL=function(e){var t=[],r=e.material;t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4));return r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},t})();e.OBJExport=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLTF(i)},t.GLTFAsync=function(e,r,a){return Promise.resolve(e.whenReadyAsync()).then((function(){return t.GLTF(e,r,a)}))},t.GLB=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLB(i)},t.GLBAsync=function(e,r,a){return Promise.resolve(e.whenReadyAsync()).then((function(){return t.GLB(e,r,a)}))},t})();e.GLTF2Export=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function r(e,t){this.asset={generator:"BabylonJS",version:"2.0"},this.babylonScene=e,this.bufferViews=[],this.accessors=[],this.meshes=[],this.scenes=[],this.nodes=[],this.images=[],this.materials=[],this.textures=[],this.samplers=[],this.animations=[],this.imageData={},this.convertToRightHandedSystem=!this.babylonScene.useRightHandedSystem;var r=t||{};this.shouldExportTransformNode=r.shouldExportTransformNode?r.shouldExportTransformNode:function(e){return!0},this.animationSampleRate=r.animationSampleRate?r.animationSampleRate:1/60}return r.prototype.reorderIndicesBasedOnPrimitiveMode=function(t,r,a,i,n){switch(r){case e.Material.TriangleFillMode:i||(i=0);for(var o=t.indexStart,s=t.indexStart+t.indexCount;o<s;o+=3){var l=i+4*o,u=n.getUInt32(l+4),f=n.getUInt32(l+8);n.setUInt32(f,l+4),n.setUInt32(u,l+8)}break;case e.Material.TriangleFanDrawMode:for(var o=t.indexStart+t.indexCount-1,c=t.indexStart;o>=c;--o)n.setUInt32(a[o],i),i+=4;break;case e.Material.TriangleStripDrawMode:t.indexCount>=3&&(n.setUInt32(a[t.indexStart+2],i+4),n.setUInt32(a[t.indexStart+1],i+8))}},r.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(t,r,a,i,n,o,s){if(this.convertToRightHandedSystem&&a===e.Material.ClockWiseSideOrientation)switch(r){case e.Material.TriangleFillMode:this.reorderTriangleFillMode(t,r,a,i,n,o,s);break;case e.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(t,r,a,i,n,o,s);break;case e.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(t,r,a,i,n,o,s)}},r.prototype.reorderTriangleFillMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type);if(t.verticesCount%3!=0)e.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var f=[],c=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)c=h*u,f.push(e.Vector3.FromArray(n,c)),f.push(e.Vector3.FromArray(n,c+2*u)),f.push(e.Vector3.FromArray(n,c+u));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)c=h*u,f.push(e.Vector4.FromArray(n,c)),f.push(e.Vector4.FromArray(n,c+2*u)),f.push(e.Vector4.FromArray(n,c+u));break;case e.VertexBuffer.ColorKind:for(var d=l.getSize(),h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=d)c=h*u,4===d?(f.push(e.Vector4.FromArray(n,c)),f.push(e.Vector4.FromArray(n,c+2*u)),f.push(e.Vector4.FromArray(n,c+u))):(f.push(e.Vector3.FromArray(n,c)),f.push(e.Vector3.FromArray(n,c+2*u)),f.push(e.Vector3.FromArray(n,c+u)));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)c=h*u,f.push(e.Vector2.FromArray(n,c)),f.push(e.Vector2.FromArray(n,c+2*u)),f.push(e.Vector2.FromArray(n,c+u));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(f,o,i,n,s)}}else e.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+i+" not present!")},r.prototype.reorderTriangleStripDrawMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),f=[],c=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:c=t.verticesStart,f.push(e.Vector3.FromArray(n,c+2*u)),f.push(e.Vector3.FromArray(n,c+u));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector4.FromArray(n,c));break;case e.VertexBuffer.ColorKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,4===l.getSize()?f.push(e.Vector4.FromArray(n,c)):f.push(e.Vector3.FromArray(n,c));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector2.FromArray(n,c));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(f,o+12,i,n,s)}else e.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+i+" not present!")},r.prototype.reorderTriangleFanMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),f=[],c=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector3.FromArray(n,c));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector4.FromArray(n,c));break;case e.VertexBuffer.ColorKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector4.FromArray(n,c)),4===l.getSize()?f.push(e.Vector4.FromArray(n,c)):f.push(e.Vector3.FromArray(n,c));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector2.FromArray(n,c));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(f,o,i,n,s)}else e.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+i+" not present!")},r.prototype.writeVertexAttributeData=function(r,a,i,n,o){for(var s=0,l=r;s<l.length;s++){var u=l[s];!this.convertToRightHandedSystem||i===e.VertexBuffer.ColorKind||u instanceof e.Vector2||(u instanceof e.Vector3?i===e.VertexBuffer.PositionKind?t._GLTFUtilities.GetRightHandedPositionVector3FromRef(u):t._GLTFUtilities.GetRightHandedNormalVector3FromRef(u):t._GLTFUtilities.GetRightHandedVector4FromRef(u));for(var f=0,c=u.asArray();f<c.length;f++){var h=c[f];o.setFloat32(h,a),a+=4}}},r.prototype.writeAttributeData=function(r,a,i,n){var o,s=i/4,l=[];switch(r){case e.VertexBuffer.PositionKind:for(var u=0,f=a.length/s;u<f;++u){o=u*s;var c=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedPositionVector3FromRef(c),l.push(c.asArray())}break;case e.VertexBuffer.NormalKind:for(var u=0,h=a.length/s;u<h;++u){o=u*s;var c=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedNormalVector3FromRef(c),l.push(c.asArray())}break;case e.VertexBuffer.TangentKind:for(var u=0,d=a.length/s;u<d;++u){o=u*s;var c=e.Vector4.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedVector4FromRef(c),l.push(c.asArray())}break;case e.VertexBuffer.ColorKind:for(var u=0,m=a.length/s;u<m;++u){o=u*s;var c=3===s?e.Vector3.FromArray(a,o):e.Vector4.FromArray(a,o);l.push(c.asArray())}break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var u=0,p=a.length/s;u<p;++u)o=u*s,l.push((this.convertToRightHandedSystem,[a[o],a[o+1]]));break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+r),l=[]}for(var g=0,T=l;g<T.length;g++)for(var y=T[g],v=0,x=y;v<x.length;v++){var b=x[v];n.setFloat32(b)}},r.prototype.generateJSON=function(e,r,a){var i,n,o,s=this,l={byteLength:this.totalByteLength},u=this.totalByteLength,f={asset:this.asset};return l.byteLength&&(f.buffers=[l]),this.nodes&&this.nodes.length&&(f.nodes=this.nodes),this.meshes&&this.meshes.length&&(f.meshes=this.meshes),this.scenes&&this.scenes.length&&(f.scenes=this.scenes,f.scene=0),this.bufferViews&&this.bufferViews.length&&(f.bufferViews=this.bufferViews),this.accessors&&this.accessors.length&&(f.accessors=this.accessors),this.animations&&this.animations.length&&(f.animations=this.animations),this.materials&&this.materials.length&&(f.materials=this.materials),this.textures&&this.textures.length&&(f.textures=this.textures),this.samplers&&this.samplers.length&&(f.samplers=this.samplers),this.images&&this.images.length&&(e?(f.images=[],this.images.forEach((function(e){e.uri&&(n=s.imageData[e.uri],i=e.uri.split(".")[0]+" image",o=t._GLTFUtilities.CreateBufferView(0,u,n.data.length,void 0,i),u+=n.data.buffer.byteLength,s.bufferViews.push(o),e.bufferView=s.bufferViews.length-1,e.name=i,e.mimeType=n.mimeType,e.uri=void 0,f.images||(f.images=[]),f.images.push(e))})),l.byteLength=u):f.images=this.images),e||(l.uri=r+".bin"),a?JSON.stringify(f,null,2):JSON.stringify(f)},r.prototype._generateGLTF=function(t){var r=this.generateBinary(),a=this.generateJSON(!1,t,!0),i=new Blob([r],{type:"application/octet-stream"}),n=t+".gltf",o=t+".bin",s=new e.GLTFData;if(s.glTFFiles[n]=a,s.glTFFiles[o]=i,this.imageData)for(var l in this.imageData)s.glTFFiles[l]=new Blob([this.imageData[l].data],{type:this.imageData[l].mimeType});return s},r.prototype.generateBinary=function(){var e=new a(4);return this.createScene(this.babylonScene,e),e.getArrayBuffer()},r.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},r.prototype._generateGLB=function(t){var r=this.generateBinary(),a=this.generateJSON(!0),i=t+".glb",n=a.length,o=0;for(var s in this.imageData)o+=this.imageData[s].data.byteLength;var l=this._getPadding(n),u=this._getPadding(r.byteLength),f=this._getPadding(o),c=28+n+l+r.byteLength+u+o+f,h=new ArrayBuffer(12),d=new DataView(h);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,c,!0);var m=new ArrayBuffer(8+n+l),p=new DataView(m);p.setUint32(0,n+l,!0),p.setUint32(4,1313821514,!0);for(var g=new Uint8Array(m,8),T=0;T<n;++T)g[T]=a.charCodeAt(T);for(var y=new Uint8Array(m,8+n),T=0;T<l;++T)y[T]=32;var v=new ArrayBuffer(8),x=new DataView(v);x.setUint32(0,r.byteLength+o+f,!0),x.setUint32(4,5130562,!0);for(var b=new ArrayBuffer(u),F=new Uint8Array(b),T=0;T<u;++T)F[T]=0;for(var A=new ArrayBuffer(f),_=new Uint8Array(A),T=0;T<f;++T)_[T]=0;var R=[h,m,v,r];for(var s in this.imageData)R.push(this.imageData[s].data.buffer);R.push(b),R.push(A);var C=new Blob(R,{type:"application/octet-stream"}),M=new e.GLTFData;return M.glTFFiles[i]=C,M},r.prototype.setNodeTransformation=function(r,a){a.position.equalsToFloats(0,0,0)||(r.translation=this.convertToRightHandedSystem?t._GLTFUtilities.GetRightHandedPositionVector3(a.position).asArray():a.position.asArray()),a.scaling.equalsToFloats(1,1,1)||(r.scale=a.scaling.asArray());var i=e.Quaternion.RotationYawPitchRoll(a.rotation.y,a.rotation.x,a.rotation.z);a.rotationQuaternion&&i.multiplyInPlace(a.rotationQuaternion),0===i.x&&0===i.y&&0===i.z&&1===i.w||(this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedQuaternionFromRef(i),r.rotation=i.normalize().asArray())},r.prototype.getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},r.prototype.createBufferViewKind=function(r,a,i,n){var o=a instanceof e.Mesh?a:a instanceof e.InstancedMesh?a.sourceMesh:null;if(o){var s=o.getVerticesData(r);if(s){var l=4*s.length,u=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),l,n,r+" - "+o.name);this.bufferViews.push(u),this.writeAttributeData(r,s,n,i)}}},r.prototype.getMeshPrimitiveMode=function(t){return t.material?t.material.fillMode:e.Material.TriangleFanDrawMode},r.prototype.setPrimitiveMode=function(t,r){switch(r){case e.Material.TriangleFillMode:break;case e.Material.TriangleStripDrawMode:t.mode=5;break;case e.Material.TriangleFanDrawMode:t.mode=6;break;case e.Material.PointListDrawMode:t.mode=0;case e.Material.PointFillMode:t.mode=0;break;case e.Material.LineLoopDrawMode:t.mode=2;break;case e.Material.LineListDrawMode:t.mode=1;break;case e.Material.LineStripDrawMode:t.mode=3}},r.prototype.setAttributeKind=function(t,r){switch(r){case e.VertexBuffer.PositionKind:t.attributes.POSITION=this.accessors.length-1;break;case e.VertexBuffer.NormalKind:t.attributes.NORMAL=this.accessors.length-1;break;case e.VertexBuffer.ColorKind:t.attributes.COLOR_0=this.accessors.length-1;break;case e.VertexBuffer.TangentKind:t.attributes.TANGENT=this.accessors.length-1;break;case e.VertexBuffer.UVKind:t.attributes.TEXCOORD_0=this.accessors.length-1;break;case e.VertexBuffer.UV2Kind:t.attributes.TEXCOORD_1=this.accessors.length-1;break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+r)}},r.prototype.setPrimitiveAttributes=function(r,a,i){var n,o,s,l=null;a instanceof e.Mesh?l=a:a instanceof e.InstancedMesh&&(l=a.sourceMesh);var u=[{kind:e.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:e.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(l){for(var f=null,c=this.getMeshPrimitiveMode(l),h={},d=0,m=u;d<m.length;d++){var p=m[d],g=p.kind;if(l.isVerticesDataPresent(g)){var T=this.getVertexBufferFromMesh(g,l);p.byteStride=T?4*T.getSize():4*e.VertexBuffer.DeduceStride(g),12===p.byteStride&&(p.accessorType="VEC3"),this.createBufferViewKind(g,a,i,p.byteStride),p.bufferViewIndex=this.bufferViews.length-1,h[g]=p.bufferViewIndex}}if(l.getTotalIndices()){var y=l.getIndices();if(y){var v=4*y.length;n=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),v,void 0,"Indices - "+l.name),this.bufferViews.push(n),f=this.bufferViews.length-1;for(var x=0,b=y.length;x<b;++x)i.setUInt32(y[x])}}if(l.subMeshes){o=!1;for(var F=0,A=l.subMeshes;F<A.length;F++){for(var _=A[F],R={attributes:{}},C=0,M=u;C<M.length;C++){var p=M[C],g=p.kind,S=l.getVerticesData(g);if(S){var T=this.getVertexBufferFromMesh(g,l);if(T){var V=T.getSize(),B=p.bufferViewIndex;if(void 0!=B){s={min:null,max:null},g==e.VertexBuffer.PositionKind&&(s=t._GLTFUtilities.CalculateMinMaxPositions(S,0,S.length/V,this.convertToRightHandedSystem));var E=t._GLTFUtilities.CreateAccessor(B,g+" - "+a.name,p.accessorType,5126,S.length/V,0,s.min,s.max);this.accessors.push(E),this.setAttributeKind(R,g),null==R.attributes.TEXCOORD_0&&null==R.attributes.TEXCOORD_1||(o=!0)}}}}if(f){var E=t._GLTFUtilities.CreateAccessor(f,"indices - "+a.name,"SCALAR",5125,_.indexCount,4*_.indexStart,null,null);this.accessors.push(E),R.indices=this.accessors.length-1}if(l.material){var w=null;if(l.material instanceof e.StandardMaterial||l.material instanceof e.PBRMetallicRoughnessMaterial||l.material instanceof e.PBRMaterial)w=a.getScene().materials.indexOf(l.material);else if(l.material instanceof e.MultiMaterial){var L=l.material,G=L.subMaterials[_.materialIndex];G&&(w=a.getScene().materials.indexOf(G))}else e.Tools.Warn("Material type "+l.material.getClassName()+" for material "+l.material.name+" is not yet implemented in glTF serializer.");if(null!=w&&Object.keys(R.attributes).length>0){var P=this.babylonScene.materials[w].sideOrientation;if(this.setPrimitiveMode(R,c),this.convertToRightHandedSystem&&P===e.Material.ClockWiseSideOrientation){var N=null!=f?this.bufferViews[f].byteOffset:null;null==N&&(N=0);var I=null;if(null!=f&&(I=l.getIndices()),I)this.reorderIndicesBasedOnPrimitiveMode(_,c,I,N,i);else for(var U=0,O=u;U<O.length;U++){var p=O[U],S=l.getVerticesData(p.kind);if(S){var k=this.bufferViews[h[p.kind]].byteOffset;k||(k=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(_,c,P,p.kind,S,k,i)}}}if(o)t._GLTFMaterial._HasTexturesPresent(this.materials[w])||(delete R.attributes.TEXCOORD_0,delete R.attributes.TEXCOORD_1),R.material=w;else if(t._GLTFMaterial._HasTexturesPresent(this.materials[w])){var D=t._GLTFMaterial._StripTexturesFromMaterial(this.materials[w]);this.materials.push(D),R.material=this.materials.length-1}else R.material=w}}else{var P=this.babylonScene.defaultMaterial.sideOrientation,N=null!=f?this.bufferViews[f].byteOffset:null;null==N&&(N=0);var I=null;if(null!=f&&(I=l.getIndices()),I)P===e.Material.ClockWiseSideOrientation&&this.reorderIndicesBasedOnPrimitiveMode(_,c,I,N,i);else for(var K=0,z=u;K<z.length;K++){var p=z[K],S=l.getVerticesData(p.kind);if(S){var H=this.bufferViews[h[p.kind]].byteOffset;H||(H=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(_,c,P,p.kind,S,H,i)}}}r.primitives.push(R)}}}},r.prototype.createScene=function(r,a){if(this.setNodeTransformation.length){var i={nodes:[]},n=void 0,o=void 0,s=void 0,l=r.transformNodes.concat(r.meshes);t._GLTFMaterial._ConvertMaterialsToGLTF(r.materials,"image/png",this.images,this.textures,this.samplers,this.materials,this.imageData,!0),this.nodeMap=this.createNodeMapAndAnimations(r,l,this.shouldExportTransformNode,a),this.totalByteLength=a.getByteOffset();for(var u=0,f=l;u<f.length;u++){var c=f[u];if(null!=(n=this.nodeMap[c.uniqueId])&&(o=this.nodes[n],c.parent||(this.shouldExportTransformNode(c)?(this.convertToRightHandedSystem&&(o.translation&&(o.translation[2]*=-1,o.translation[0]*=-1),o.rotation=o.rotation?e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(o.rotation)).asArray():e.Quaternion.FromArray([0,1,0,0]).asArray()),i.nodes.push(n)):e.Tools.Log("Omitting "+c.name+" from scene.")),s=c.getDescendants(!0),!o.children&&s&&s.length)){o.children=[];for(var h=0,d=s;h<d.length;h++){var m=d[h];null!=this.nodeMap[m.uniqueId]&&o.children.push(this.nodeMap[m.uniqueId])}}}i.nodes.length&&this.scenes.push(i)}},r.prototype.createNodeMapAndAnimations=function(e,r,a,i){for(var n,o,s=this,l={},u={name:"runtime animations",channels:[],samplers:[]},f=[],c=0,h=r;c<h.length;c++){var d=h[c];a(d)?(o=this.createNode(d,i),this.nodes.push(o),n=this.nodes.length-1,l[d.uniqueId]=n,!e.animationGroups.length&&d.animations.length&&t._GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations(d,u,f,l,this.nodes,i,this.bufferViews,this.accessors,this.convertToRightHandedSystem,this.animationSampleRate)):d.name}return u.channels.length&&u.samplers.length&&this.animations.push(u),f.forEach((function(e){e.channels.length&&e.samplers.length&&s.animations.push(e)})),e.animationGroups.length&&t._GLTFAnimation._CreateNodeAnimationFromAnimationGroups(e,this.animations,l,this.nodes,i,this.bufferViews,this.accessors,this.convertToRightHandedSystem,this.animationSampleRate),l},r.prototype.createNode=function(e,t){var r={},a={primitives:[]};return e.name&&(r.name=e.name),this.setNodeTransformation(r,e),this.setPrimitiveAttributes(a,e,t),a.primitives.length&&(this.meshes.push(a),r.mesh=this.meshes.length-1),r},r})();t._Exporter=r;var a=(function(){function t(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return t.prototype.resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),a=new Uint8Array(t),i=0,n=a.byteLength;i<n;++i)a[i]=r[i];this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer)},t.prototype.getArrayBuffer=function(){return this.resizeBuffer(this.getByteOffset()),this._arrayBuffer},t.prototype.getByteOffset=function(){return this._byteOffset},t.prototype.setUInt8=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint8(r,t):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset++,t))},t.prototype.getUInt32=function(t){if(t<this._byteOffset)return this._dataView.getUint32(t,!0);throw e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},t.prototype.getVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0))},t.prototype.setVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0))},t.prototype.getVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0),t.w=this._dataView.getFloat32(r+12,!0))},t.prototype.setVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0),this._dataView.setFloat32(r+12,t.w,!0))},t.prototype.setFloat32=function(t,r){isNaN(t)&&e.Tools.Error("Invalid data being written!"),null!=r&&(r<this._byteOffset?this._dataView.setFloat32(r,t,!0):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!")),this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,t,!0),this._byteOffset+=4},t.prototype.setUInt32=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint32(r,t,!0):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,t,!0),this._byteOffset+=4)},t})();t._BinaryWriter=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){var t=(function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-1!==e.indexOf(t,e.length-t.length)}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var a=this.glTFFiles[t],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([a],i)),r.click()}},e})();e.GLTFData=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function t(){}return t.FuzzyEquals=function(t,r,a){return e.Scalar.WithinEpsilon(t.r,r.r,a)&&e.Scalar.WithinEpsilon(t.g,r.g,a)&&e.Scalar.WithinEpsilon(t.b,r.b,a)},t._ConvertMaterialsToGLTF=function(r,a,i,n,o,s,l,u){for(var f=0,c=r;f<c.length;f++){var h=c[f];h instanceof e.StandardMaterial?t._ConvertStandardMaterial(h,a,i,n,o,s,l,u):h instanceof e.PBRMetallicRoughnessMaterial?t._ConvertPBRMetallicRoughnessMaterial(h,a,i,n,o,s,l,u):h instanceof e.PBRMaterial?t._ConvertPBRMaterial(h,a,i,n,o,s,l,u):e.Tools.Error("Unsupported material type: "+h.name)}},t._StripTexturesFromMaterial=function(e){var t={};if(e){t.name=e.name,t.doubleSided=e.doubleSided,t.alphaMode=e.alphaMode,t.alphaCutoff=e.alphaCutoff,t.emissiveFactor=e.emissiveFactor;var r=e.pbrMetallicRoughness;r&&(t.pbrMetallicRoughness={},t.pbrMetallicRoughness.baseColorFactor=r.baseColorFactor,t.pbrMetallicRoughness.metallicFactor=r.metallicFactor,t.pbrMetallicRoughness.roughnessFactor=r.roughnessFactor)}return t},t._HasTexturesPresent=function(e){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},t._ConvertToGLTFPBRMetallicRoughness=function(t){function r(e,t,r,a,i){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*a+e*e*e*i}var a=new e.Vector2(0,1),i=new e.Vector2(0,.1),n=new e.Vector2(0,.1),o=new e.Vector2(1300,.1),s=t.diffuseColor.toLinearSpace().scale(.5),l=t.alpha,u=e.Scalar.Clamp(t.specularPower,0,this._maxSpecularPower),f=(function(e){return r(Math.pow(e/o.x,.333333),a.y,i.y,n.y,o.y)})(u);return{baseColorFactor:[s.r,s.g,s.b,l],metallicFactor:0,roughnessFactor:f}},t._SolveMetallic=function(r,a,i){if(a<t._dielectricSpecular.r)return t._dielectricSpecular,0;var n=t._dielectricSpecular.r,o=r*i/(1-t._dielectricSpecular.r)+a-2*t._dielectricSpecular.r,s=t._dielectricSpecular.r-a,l=o*o-4*n*s;return e.Scalar.Clamp((-o+Math.sqrt(l))/(2*n),0,1)},t._GetAlphaMode=function(t){if(t instanceof e.StandardMaterial){var r=t;return 1!=r.alpha||null!=r.diffuseTexture&&r.diffuseTexture.hasAlpha||null!=r.opacityTexture?"BLEND":"OPAQUE"}if(t instanceof e.PBRMetallicRoughnessMaterial){var a=t;switch(a.transparencyMode){case e.PBRMaterial.PBRMATERIAL_OPAQUE:return"OPAQUE";case e.PBRMaterial.PBRMATERIAL_ALPHABLEND:return"BLEND";case e.PBRMaterial.PBRMATERIAL_ALPHATEST:return"MASK";case e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND:return e.Tools.Warn(t.name+": GLTF Exporter | Alpha test and blend mode not supported in glTF. Alpha blend used instead."),"BLEND";default:return e.Tools.Error("Unsupported alpha mode "+a.transparencyMode),null}}else{if(!(t instanceof e.PBRMaterial))return e.Tools.Error("Unsupported Babylon material type"),null;var i=t;switch(i.transparencyMode){case e.PBRMaterial.PBRMATERIAL_OPAQUE:return"OPAQUE";case e.PBRMaterial.PBRMATERIAL_ALPHABLEND:return"BLEND";case e.PBRMaterial.PBRMATERIAL_ALPHATEST:return"MASK";case e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND:return e.Tools.Warn(t.name+": GLTF Exporter | Alpha test and blend mode not supported in glTF. Alpha blend used instead."),"BLEND";default:return e.Tools.Error("Unsupported alpha mode "+i.transparencyMode),null}}},t._ConvertStandardMaterial=function(r,a,i,n,o,s,l,u){var f=t._ConvertToGLTFPBRMetallicRoughness(r),c={name:r.name};if(null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),c.doubleSided=!0),u){if(r.diffuseTexture){var h=t._ExportTexture(r.diffuseTexture,a,i,n,o,l);null!=h&&(f.baseColorTexture=h)}if(r.bumpTexture){var h=t._ExportTexture(r.bumpTexture,a,i,n,o,l);h&&(c.normalTexture=h,1!==r.bumpTexture.level&&(c.normalTexture.scale=r.bumpTexture.level))}if(r.emissiveTexture){var d=t._ExportTexture(r.emissiveTexture,a,i,n,o,l);d&&(c.emissiveTexture=d),c.emissiveFactor=[1,1,1]}if(r.ambientTexture){var h=t._ExportTexture(r.ambientTexture,a,i,n,o,l);if(h){var m={index:h.index};c.occlusionTexture=m,m.strength=1}}}(r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?c.alphaMode="BLEND":e.Tools.Warn(r.name+": glTF 2.0 does not support alpha mode: "+r.alphaMode.toString())),r.emissiveColor&&!this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(c.emissiveFactor=r.emissiveColor.asArray()),c.pbrMetallicRoughness=f,s.push(c)},t._ConvertPBRMetallicRoughnessMaterial=function(r,a,i,n,o,s,l,u){var f={};r.baseColor&&(f.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,r.alpha]),null!=r.metallic&&1!==r.metallic&&(f.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(f.roughnessFactor=r.roughness);var c={name:r.name};if(r.doubleSided&&(c.doubleSided=r.doubleSided),u){if(null!=r.baseTexture){var h=t._ExportTexture(r.baseTexture,a,i,n,o,l);null!=h&&(f.baseColorTexture=h)}if(r.normalTexture){var h=t._ExportTexture(r.normalTexture,a,i,n,o,l);h&&(c.normalTexture=h,1!==r.normalTexture.level&&(c.normalTexture.scale=r.normalTexture.level))}if(r.occlusionTexture){var h=t._ExportTexture(r.occlusionTexture,a,i,n,o,l);h&&(c.occlusionTexture=h,null!=r.occlusionStrength&&(c.occlusionTexture.strength=r.occlusionStrength))}if(r.emissiveTexture){var h=t._ExportTexture(r.emissiveTexture,a,i,n,o,l);null!=h&&(c.emissiveTexture=h)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(c.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var d=t._GetAlphaMode(r);d&&"OPAQUE"!==d&&(c.alphaMode=d,"MASK"===d&&(c.alphaCutoff=r.alphaCutOff))}c.pbrMetallicRoughness=f,s.push(c)},t._CreateBase64FromCanvas=function(e,t,r,a){var i=document.createElement("canvas");i.width=t,i.height=r,i.id="WriteCanvas";var n=i.getContext("2d"),o=n.createImageData(t,r);return o.data.set(e),n.putImageData(o,0,0),i.toDataURL(a)},t._CreateWhiteTexture=function(t,r,a){for(var i=new Uint8Array(t*r*4),n=0;n<i.length;n+=4)i[n]=i[n+1]=i[n+2]=i[n+3]=255;return e.RawTexture.CreateRGBATexture(i,t,r,a)},t._ResizeTexturesToSameDimensions=function(t,r,a){var i,n,o=t?t.getSize():{width:0,height:0},s=r?r.getSize():{width:0,height:0};return o.width<s.width?(i=t?e.TextureTools.CreateResizedCopy(t,s.width,s.height,!0):this._CreateWhiteTexture(s.width,s.height,a),n=r):o.width>s.width?(n=r?e.TextureTools.CreateResizedCopy(r,o.width,o.height,!0):this._CreateWhiteTexture(o.width,o.height,a),i=t):(i=t,n=r),{texture1:i,texture2:n}},t._ConvertSpecularGlossinessTexturesToMetallicRoughness=function(t,r,a,i){if(!t&&!r)return null;var n=t?t.getScene():r.getScene();if(!n)return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!"),null;var o,s,l=this._ResizeTexturesToSameDimensions(t,r,n),u=l.texture1.getSize(),f=u.width,c=u.height,h=l.texture1.readPixels() | ||
;if(!(h instanceof Uint8Array))return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture1.name),null;if(o=l.texture1.readPixels(),!((h=l.texture2.readPixels())instanceof Uint8Array))return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture2.name),null;s=l.texture2.readPixels();for(var d=s.byteLength,m=new Uint8Array(d),p=new Uint8Array(d),g=e.Color3.Black(),T=0,y=0,v=0;v<c;++v)for(var x=0;x<f;++x){var b=4*(f*v+x),F=e.Color3.FromInts(o[b],o[b+1],o[b+2]).toLinearSpace().multiply(a.diffuseColor),A=e.Color3.FromInts(s[b],s[b+1],s[b+2]).toLinearSpace().multiply(a.specularColor),_=s[b+3]/255*a.glossiness,R={diffuseColor:F,specularColor:A,glossiness:_},C=this._ConvertSpecularGlossinessToMetallicRoughness(R);g.r=Math.max(g.r,C.baseColor.r),g.g=Math.max(g.g,C.baseColor.g),g.b=Math.max(g.b,C.baseColor.b),T=Math.max(T,C.metallic),y=Math.max(y,C.roughness),p[b]=255*C.baseColor.r,p[b+1]=255*C.baseColor.g,p[b+2]=255*C.baseColor.b,p[b+3]=l.texture1.hasAlpha?o[b+3]:255,m[b]=0,m[b+1]=255*C.roughness,m[b+2]=255*C.metallic,m[b+3]=255}for(var M={baseColor:g,metallic:T,roughness:y},S=!1,V=!1,v=0;v<c;++v)for(var x=0;x<f;++x){var B=4*(f*v+x);p[B]/=M.baseColor.r>this._epsilon?M.baseColor.r:1,p[B+1]/=M.baseColor.g>this._epsilon?M.baseColor.g:1,p[B+2]/=M.baseColor.b>this._epsilon?M.baseColor.b:1;var E=e.Color3.FromInts(p[B],p[B+1],p[B+2]),w=E.toGammaSpace();p[B]=255*w.r,p[B+1]=255*w.g,p[B+2]=255*w.b,this.FuzzyEquals(w,e.Color3.White(),this._epsilon)||(V=!0),m[B+1]/=M.roughness>this._epsilon?M.roughness:1,m[B+2]/=M.metallic>this._epsilon?M.metallic:1;var L=e.Color3.FromInts(255,m[B+1],m[B+2]);this.FuzzyEquals(L,e.Color3.White(),this._epsilon)||(S=!0)}if(S){var G=this._CreateBase64FromCanvas(m,f,c,i);M.metallicRoughnessTextureBase64=G}if(V){var P=this._CreateBase64FromCanvas(p,f,c,i);M.baseColorTextureBase64=P}return M},t._ConvertSpecularGlossinessToMetallicRoughness=function(r){var a=t._GetPerceivedBrightness(r.diffuseColor),i=t._GetPerceivedBrightness(r.specularColor),n=1-t._GetMaxComponent(r.specularColor),o=t._SolveMetallic(a,i,n),s=r.diffuseColor.scale(n/(1-this._dielectricSpecular.r)/Math.max(1-o,this._epsilon)),l=r.specularColor.subtract(this._dielectricSpecular.scale(1-o)).scale(1/Math.max(o,this._epsilon)),u=e.Color3.Lerp(s,l,o*o);return u=u.clampToRef(0,1,u),{baseColor:u,metallic:o,roughness:1-r.glossiness}},t._GetPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},t._GetMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},t._ConvertMetalRoughFactorsToMetallicRoughness=function(e,r,a,i,n,o,s,l){var u={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};if(l){if(e.albedoTexture){var f=t._ExportTexture(e.albedoTexture,r,a,i,n,s);f&&(o.baseColorTexture=f)}if(e.metallicTexture){var f=t._ExportTexture(e.metallicTexture,r,a,i,n,s);null!=f&&(o.metallicRoughnessTexture=f)}}return u},t._GetGLTFTextureSampler=function(r){var a=t._GetGLTFTextureWrapModesSampler(r),i=r instanceof e.Texture?r.samplingMode:null;if(null!=i)switch(i){case e.Texture.LINEAR_LINEAR:a.magFilter=9729,a.minFilter=9729;break;case e.Texture.LINEAR_NEAREST:a.magFilter=9729,a.minFilter=9728;break;case e.Texture.NEAREST_LINEAR:a.magFilter=9728,a.minFilter=9729;break;case e.Texture.NEAREST_LINEAR_MIPLINEAR:a.magFilter=9728,a.minFilter=9987;break;case e.Texture.NEAREST_NEAREST:a.magFilter=9728,a.minFilter=9728;break;case e.Texture.NEAREST_LINEAR_MIPNEAREST:a.magFilter=9728,a.minFilter=9985;break;case e.Texture.LINEAR_NEAREST_MIPNEAREST:a.magFilter=9729,a.minFilter=9984;break;case e.Texture.LINEAR_NEAREST_MIPLINEAR:a.magFilter=9729,a.minFilter=9986;break;case e.Texture.NEAREST_NEAREST_MIPLINEAR:a.magFilter=9728,a.minFilter=9986;break;case e.Texture.LINEAR_LINEAR_MIPLINEAR:a.magFilter=9729,a.minFilter=9987;break;case e.Texture.LINEAR_LINEAR_MIPNEAREST:a.magFilter=9729,a.minFilter=9985;break;case e.Texture.NEAREST_NEAREST_MIPNEAREST:a.magFilter=9728,a.minFilter=9984}return a},t._GetGLTFTextureWrapMode=function(t){switch(t){case e.Texture.WRAP_ADDRESSMODE:return 10497;case e.Texture.CLAMP_ADDRESSMODE:return 33071;case e.Texture.MIRROR_ADDRESSMODE:return 33648;default:return e.Tools.Error("Unsupported Texture Wrap Mode "+t+"!"),10497}},t._GetGLTFTextureWrapModesSampler=function(r){var a=t._GetGLTFTextureWrapMode(r instanceof e.Texture?r.wrapU:e.Texture.WRAP_ADDRESSMODE),i=t._GetGLTFTextureWrapMode(r instanceof e.Texture?r.wrapV:e.Texture.WRAP_ADDRESSMODE);return 10497===a&&10497===i?{}:{wrapS:a,wrapT:i}},t._ConvertSpecGlossFactorsToMetallicRoughness=function(r,a,i,n,o,s,l,u){var f={diffuseColor:r.albedoColor||e.Color3.White(),specularColor:r.reflectivityColor||e.Color3.White(),glossiness:r.microSurface||1},c=null,h=this._GetGLTFTextureSampler(r.albedoTexture);if(null!=h.magFilter&&null!=h.minFilter&&null!=h.wrapS&&null!=h.wrapT&&(o.push(h),c=o.length-1),r.reflectivityTexture&&!r.useMicroSurfaceFromReflectivityMapAlpha)return e.Tools.Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported"),null;var d=this._ConvertSpecularGlossinessTexturesToMetallicRoughness(r.albedoTexture,r.reflectivityTexture,f,a);if(d){if(u){if(d.baseColorTextureBase64){var m=t._GetTextureInfoFromBase64(d.baseColorTextureBase64,"bjsBaseColorTexture_"+n.length+".png",a,i,n,r.albedoTexture.coordinatesIndex,c,l);null!=m&&(s.baseColorTexture=m)}if(d.metallicRoughnessTextureBase64){var p=t._GetTextureInfoFromBase64(d.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+n.length+".png",a,i,n,r.reflectivityTexture.coordinatesIndex,c,l);null!=p&&(s.metallicRoughnessTexture=p)}}}else d=this._ConvertSpecularGlossinessToMetallicRoughness(f);return d},t._ConvertPBRMaterial=function(r,a,i,n,o,s,l,u){var f,c={},h={name:r.name};if(f=r.isMetallicWorkflow()?this._ConvertMetalRoughFactorsToMetallicRoughness(r,a,i,n,o,c,l,u):this._ConvertSpecGlossFactorsToMetallicRoughness(r,a,i,n,o,c,l,u)){if(this.FuzzyEquals(f.baseColor,e.Color3.White(),this._epsilon)&&r.alpha>=this._epsilon||(c.baseColorFactor=[f.baseColor.r,f.baseColor.g,f.baseColor.b,r.alpha]),null!=f.metallic&&1!==f.metallic&&(c.metallicFactor=f.metallic),null!=f.roughness&&1!==f.roughness&&(c.roughnessFactor=f.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),h.doubleSided=!0),u){if(r.bumpTexture){var d=t._ExportTexture(r.bumpTexture,a,i,n,o,l);d&&(h.normalTexture=d,1!==r.bumpTexture.level&&(h.normalTexture.scale=r.bumpTexture.level))}if(r.ambientTexture){var d=t._ExportTexture(r.ambientTexture,a,i,n,o,l);if(d){var m={index:d.index};h.occlusionTexture=m,r.ambientTextureStrength&&(m.strength=r.ambientTextureStrength)}}if(r.emissiveTexture){var d=t._ExportTexture(r.emissiveTexture,a,i,n,o,l);null!=d&&(h.emissiveTexture=d)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)||(h.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var p=t._GetAlphaMode(r);p&&"OPAQUE"!==p&&(h.alphaMode=p,"MASK"===p&&(h.alphaCutoff=r.alphaCutOff))}h.pbrMetallicRoughness=c,s.push(h)}},t.GetPixelsFromTexture=function(t){return t.textureType,e.Engine.TEXTURETYPE_UNSIGNED_INT,t.readPixels()},t._ExportTexture=function(r,a,i,n,o,s){for(var l=t._GetGLTFTextureSampler(r),u=null,f=null,c=0;c<o.length;++c){var h=o[c];if(h.minFilter===l.minFilter&&h.magFilter===l.magFilter&&h.wrapS===l.wrapS&&h.wrapT===l.wrapT){f=c;break}}null==f?(o.push(l),u=o.length-1):u=f;var d="texture_"+(n.length-1).toString(),m=r.getInternalTexture();null!=m&&(d=m.url||d),d=e.Tools.GetFilename(d);var p=d.split(".")[0],g="";if("image/jpeg"===a)g=".jpg";else{if("image/png"!==a)return e.Tools.Error("Unsupported mime type "+a),null;g=".png"}d=p+g;var T=t.GetPixelsFromTexture(r),y=r.getSize(),v=this._CreateBase64FromCanvas(T,y.width,y.height,a);return this._GetTextureInfoFromBase64(v,d,a,i,n,r.coordinatesIndex,u,s)},t._GetTextureInfoFromBase64=function(e,t,r,a,i,n,o,s){var l=null,u={source:a.length,name:t};null!=o&&(u.sampler=o);for(var f=atob(e.split(",")[1]),c=new ArrayBuffer(f.length),h=new Uint8Array(c),d=0,m=f.length;d<m;++d)h[d]=f.charCodeAt(d);var p={data:h,mimeType:r};if(s[t]=p,"image/jpeg"===r||"image/png"===r){for(var g={uri:t},T=null,d=0;d<a.length;++d)if(a[d].uri===t){T=d;break}null==T?(a.push(g),u.source=a.length-1):u.source=T,i.push(u),l={index:i.length-1},n&&(l.texCoord=n)}return l},t._dielectricSpecular=new e.Color3(.04,.04,.04),t._maxSpecularPower=1024,t._epsilon=1e-6,t})();t._GLTFMaterial=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){!(function(t){var r;!(function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"})(r||(r={}));var a=(function(){function a(){}return a._CreateNodeAnimation=function(t,r,i,n,o,s){var l=[],u=[],f=r.getKeys(),c=a.calculateMinMaxKeyFrames(f),h=a._DeduceInterpolation(f,i,o),d=c.max-c.min,m=h.interpolationType,p=h.shouldBakeAnimation;if(p?a._CreateBakedAnimation(t,r,i,c.min,c.max,r.framePerSecond,s,l,u,c,n,o):"LINEAR"===m||"STEP"===m?a._CreateLinearOrStepAnimation(t,r,i,d,l,u,n,o):"CUBICSPLINE"===m?a._CreateCubicSplineAnimation(t,r,i,d,l,u,n,o):a._CreateBakedAnimation(t,r,i,c.min,c.max,r.framePerSecond,s,l,u,c,n,o),l.length&&u.length){return{inputs:l,outputs:u,samplerInterpolation:m,inputsMin:p?c.min:e.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:p?c.max:e.Tools.FloatRound(c.max/r.framePerSecond)}}return null},a._DeduceAnimationInfo=function(t){var r=null,a="VEC3",i=!1,n=t.targetProperty.split(".");switch(n[0]){case"scaling":r="scale";break;case"position":r="translation";break;case"rotation":a="VEC4",r="rotation";break;case"rotationQuaternion":a="VEC4",i=!0,r="rotation";break;default:e.Tools.Error("Unsupported animatable property "+n[0])}return r?{animationChannelTargetPath:r,dataAccessorType:a,useQuaternion:i}:(e.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},a._CreateNodeAnimationFromTransformNodeAnimations=function(e,t,r,i,n,o,s,l,u,f){var c;if(e.animations)for(var h=0,d=e.animations;h<d.length;h++){var m=d[h],p=a._DeduceAnimationInfo(m);p&&(c={name:m.name,samplers:[],channels:[]},a.AddAnimation(""+m.name,m.hasRunningRuntimeAnimations?t:c,e,m,p.dataAccessorType,p.animationChannelTargetPath,i,o,s,l,u,p.useQuaternion,f),c.samplers.length&&c.channels.length&&r.push(c))}},a._CreateNodeAnimationFromAnimationGroups=function(t,r,i,n,o,s,l,u,f){var c;if(t.animationGroups)for(var h=t.animationGroups,d=0,m=h;d<m.length;d++){var p=m[d];c={name:p.name,channels:[],samplers:[]};for(var g=0,T=p.targetedAnimations;g<T.length;g++){var y=T[g],v=y.target,x=y.animation;if(v instanceof e.Mesh||1===v.length&&v[0]instanceof e.Mesh){var b=a._DeduceAnimationInfo(y.animation);if(b){var F=v instanceof e.Mesh?v:v[0];a.AddAnimation(""+x.name,c,F,x,b.dataAccessorType,b.animationChannelTargetPath,i,o,s,l,u,b.useQuaternion,f)}}}c.channels.length&&c.samplers.length&&r.push(c)}},a.AddAnimation=function(e,r,i,n,o,s,l,u,f,c,h,d,m){var p,g,T,y,v,x,b,F=a._CreateNodeAnimation(i,n,s,h,d,m);if(F){var A=l[i.uniqueId],_=4*F.inputs.length;p=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),_,void 0,e+" keyframe data view"),f.push(p),F.inputs.forEach((function(e){u.setFloat32(e)})),g=t._GLTFUtilities.CreateAccessor(f.length-1,e+" keyframes","SCALAR",5126,F.inputs.length,null,[F.inputsMin],[F.inputsMax]),c.push(g),T=c.length-1,v=F.outputs.length,_="VEC3"===o?12*F.outputs.length:16*F.outputs.length,p=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),_,void 0,e+" data view"),f.push(p),F.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),g=t._GLTFUtilities.CreateAccessor(f.length-1,e+" data",o,5126,v,null,null,null),c.push(g),y=c.length-1,x={interpolation:F.samplerInterpolation,input:T,output:y},r.samplers.push(x),b={sampler:r.samplers.length-1,target:{node:A,path:s}},r.channels.push(b)}},a._CreateBakedAnimation=function(t,r,i,n,o,s,l,u,f,c,h,d){var m,p,g=e.Quaternion.Identity(),T=null,y=null,v=null,x=null,b=null,F=null;c.min=e.Tools.FloatRound(n/s);for(var A=r.getKeys(),_=0,R=A.length;_<R;++_){if(F=null,v=A[_],_+1<R)if(x=A[_+1],v.value.equals(x.value)){if(0!==_)continue;F=v.frame}else F=x.frame;else{if(b=A[_-1],v.value.equals(b.value))continue;F=o}if(F)for(var C=v.frame;C<=F;C+=l)(p=e.Tools.FloatRound(C/s))!==T&&(T=p,y=p,m=r._interpolate(C,0,void 0,r.loopMode),a._SetInterpolatedValue(t,m,p,r,i,g,u,f,h,d))}y&&(c.max=y)},a._ConvertFactorToVector3OrQuaternion=function(t,r,i,n,o,s,l){var u,f,c=null,h=a._GetBasePositionRotationOrScale(r,o,s,l);if(n===e.Animation.ANIMATIONTYPE_FLOAT)switch(u=i.targetProperty.split("."),f=u?u[1]:"",c=l?e.Quaternion.FromArray(h).normalize():e.Vector3.FromArray(h),f){case"x":case"y":c[f]=s&&l&&"scale"!==o?-t:t;break;case"z":c[f]=s&&!l&&"scale"!==o?-t:t;break;case"w":c.w=t;break;default:e.Tools.Error('glTFAnimation: Unsupported component type "'+f+'" for scale animation!')}return c},a._SetInterpolatedValue=function(r,a,i,n,o,s,l,u,f,c){var h,d=n.dataType;l.push(i),"number"==typeof a&&(a=this._ConvertFactorToVector3OrQuaternion(a,r,n,d,o,f,c)),a&&("rotation"===o?(c?s=a:(h=a,e.Quaternion.RotationYawPitchRollToRef(h.y,h.x,h.z,s)),f&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(s),r.parent||(s=e.Quaternion.FromArray([0,1,0,0]).multiply(s))),u.push(s.asArray())):(h=a,f&&"scale"!==o&&(t._GLTFUtilities.GetRightHandedPositionVector3FromRef(h),r.parent||(h.x*=-1,h.z*=-1)),u.push(h.asArray())))},a._CreateLinearOrStepAnimation=function(e,t,r,i,n,o,s,l){for(var u=0,f=t.getKeys();u<f.length;u++){var c=f[u];n.push(c.frame/t.framePerSecond),a._AddKeyframeValue(c,t,o,r,e,s,l)}},a._CreateCubicSplineAnimation=function(e,t,i,n,o,s,l,u){t.getKeys().forEach((function(f){o.push(f.frame/t.framePerSecond),a.AddSplineTangent(e,r.INTANGENT,s,i,"CUBICSPLINE",f,n,u,l),a._AddKeyframeValue(f,t,s,i,e,l,u),a.AddSplineTangent(e,r.OUTTANGENT,s,i,"CUBICSPLINE",f,n,u,l)}))},a._GetBasePositionRotationOrScale=function(r,a,i,n){var o;return"rotation"===a?n?r.rotationQuaternion?(o=r.rotationQuaternion.asArray(),i&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(o),r.parent||(o=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(o)).asArray()))):o=e.Quaternion.Identity().asArray():(o=r.rotation.asArray(),t._GLTFUtilities.GetRightHandedNormalArray3FromRef(o)):"translation"===a?(o=r.position.asArray(),i&&t._GLTFUtilities.GetRightHandedPositionArray3FromRef(o)):o=r.scaling.asArray(),o},a._AddKeyframeValue=function(r,a,i,n,o,s,l){var u,f,c=a.dataType;if(c===e.Animation.ANIMATIONTYPE_VECTOR3){if(u=r.value.asArray(),"rotation"===n){var h=e.Vector3.FromArray(u),d=e.Quaternion.RotationYawPitchRoll(h.y,h.x,h.z);s&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(d),o.parent||(d=e.Quaternion.FromArray([0,1,0,0]).multiply(d))),u=d.asArray()}else"translation"===n&&s&&(t._GLTFUtilities.GetRightHandedNormalArray3FromRef(u),o.parent||(u[0]*=-1,u[2]*=-1));i.push(u)}else if(c===e.Animation.ANIMATIONTYPE_FLOAT){if(f=this._ConvertFactorToVector3OrQuaternion(r.value,o,a,c,n,s,l)){if("rotation"===n){var m=l?f:e.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z).normalize();s&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(m),o.parent||(m=e.Quaternion.FromArray([0,1,0,0]).multiply(m))),i.push(m.asArray())}else"translation"===n&&s&&(t._GLTFUtilities.GetRightHandedNormalVector3FromRef(f),o.parent||(f.x*=-1,f.z*=-1));i.push(f.asArray())}}else c===e.Animation.ANIMATIONTYPE_QUATERNION?(u=r.value.normalize().asArray(),s&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(u),o.parent||(u=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(u)).asArray())),i.push(u)):e.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},a._DeduceInterpolation=function(t,r,a){var i,n,o=!1;if("rotation"===r&&!a)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,l=t.length;s<l;++s)if(n=t[s],n.inTangent||n.outTangent)if(i){if("CUBICSPLINE"!==i){i="LINEAR",o=!0;break}}else i="CUBICSPLINE";else if(i){if("CUBICSPLINE"===i||n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP&&"STEP"!==i){i="LINEAR",o=!0;break}}else i=n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return i||(i="LINEAR"),{interpolationType:i,shouldBakeAnimation:o}},a.AddSplineTangent=function(a,i,n,o,s,l,u,f,c){var h,d=i===r.INTANGENT?l.inTangent:l.outTangent;if("CUBICSPLINE"===s){if("rotation"===o)if(d){if(f)h=d.scale(u).asArray();else{var m=d.scale(u);h=e.Quaternion.RotationYawPitchRoll(m.y,m.x,m.z).asArray()}c&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(h),a.parent||(h=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(h)).asArray()))}else h=[0,0,0,0];else d?(h=d.scale(u).asArray(),c&&"translation"===o&&(t._GLTFUtilities.GetRightHandedPositionArray3FromRef(h),a.parent||(h[0]*=-1,h[2]*=-1))):h=[0,0,0];n.push(h)}},a.calculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},a})();t._GLTFAnimation=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;return (function(e){!(function(t){var r=(function(){function t(){}return t.CreateBufferView=function(e,t,r,a,i){var n={buffer:e,byteLength:r};return t&&(n.byteOffset=t),i&&(n.name=i),a&&(n.byteStride=a),n},t.CreateAccessor=function(e,t,r,a,i,n,o,s){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=n&&(l.byteOffset=n),l},t.CalculateMinMaxPositions=function(r,a,i,n){var o,s,l,u=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0];if(i)for(var c=a,h=a+i;c<h;++c){o=3*c,s=e.Vector3.FromArray(r,o),n&&t.GetRightHandedPositionVector3FromRef(s),l=s.asArray();for(var d=0;d<3;++d){var m=l[d];m<u[d]&&(u[d]=m),m>f[d]&&(f[d]=m),++o}}return{min:u,max:f}},t.GetRightHandedPositionVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t.GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},t.GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},t.GetRightHandedNormalVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t.GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},t.GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},t.GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},t.GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},t.GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},t.GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},t})();t._GLTFUtilities=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={})),e})); |
@@ -21,9 +21,9 @@ /// <reference types="babylonjs"/> | ||
*/ | ||
interface IExporterOptions { | ||
interface IExportOptions { | ||
/** | ||
* Function which indicates whether a babylon mesh should be exported or not | ||
* @param mesh source Babylon mesh. It is used to check whether it should be exported to glTF or not | ||
* @param transformNode source Babylon transform node. It is used to check whether it should be exported to glTF or not | ||
* @returns boolean, which indicates whether the mesh should be exported (true) or not (false) | ||
*/ | ||
shouldExportMesh?(mesh: AbstractMesh): boolean; | ||
shouldExportTransformNode?(transformNode: TransformNode): boolean; | ||
/** | ||
@@ -39,3 +39,3 @@ * The sample rate to bake animation curves | ||
/** | ||
* Exports the geometry of the scene to .gltf file format | ||
* Exports the geometry of the scene to .gltf file format synchronously | ||
* @param scene Babylon scene with scene hierarchy information | ||
@@ -47,6 +47,15 @@ * @param filePrefix File prefix to use when generating the glTF file | ||
*/ | ||
static GLTF(scene: Scene, filePrefix: string, options?: IExporterOptions): Nullable<GLTFData>; | ||
private static GLTF(scene, filePrefix, options?); | ||
/** | ||
* Exports the geometry of the scene to .glb file format | ||
* Exports the geometry of the scene to .gltf file format asynchronously | ||
* @param scene Babylon scene with scene hierarchy information | ||
* @param filePrefix File prefix to use when generating the glTF file | ||
* @param options Exporter options | ||
* @returns Returns an object with a .gltf file and associates texture names | ||
* as keys and their data and paths as values | ||
*/ | ||
static GLTFAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>; | ||
/** | ||
* Exports the geometry of the scene to .glb file format synchronously | ||
* @param scene Babylon scene with scene hierarchy information | ||
* @param filePrefix File prefix to use when generating glb file | ||
@@ -56,3 +65,11 @@ * @param options Exporter options | ||
*/ | ||
static GLB(scene: Scene, filePrefix: string, options?: IExporterOptions): Nullable<GLTFData>; | ||
private static GLB(scene, filePrefix, options?); | ||
/** | ||
* Exports the geometry of the scene to .glb file format asychronously | ||
* @param scene Babylon scene with scene hierarchy information | ||
* @param filePrefix File prefix to use when generating glb file | ||
* @param options Exporter options | ||
* @returns Returns an object with a .glb filename as key and data as value | ||
*/ | ||
static GLBAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>; | ||
} | ||
@@ -109,2 +126,6 @@ } | ||
/** | ||
* Stores all the texture samplers | ||
*/ | ||
private samplers; | ||
/** | ||
* Stores all the generated animation samplers, which is referenced by glTF animations | ||
@@ -141,3 +162,3 @@ */ | ||
private animationSampleRate; | ||
private shouldExportMesh; | ||
private shouldExportTransformNode; | ||
/** | ||
@@ -148,4 +169,62 @@ * Creates a glTF Exporter instance, which can accept optional exporter options | ||
*/ | ||
constructor(babylonScene: Scene, options?: IExporterOptions); | ||
constructor(babylonScene: Scene, options?: IExportOptions); | ||
private reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter); | ||
/** | ||
* Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is | ||
* clock-wise during export to glTF | ||
* @param submesh BabylonJS submesh | ||
* @param primitiveMode Primitive mode of the mesh | ||
* @param sideOrientation the winding order of the submesh | ||
* @param vertexBufferKind The type of vertex attribute | ||
* @param meshAttributeArray The vertex attribute data | ||
* @param byteOffset The offset to the binary data | ||
* @param binaryWriter The binary data for the glTF file | ||
*/ | ||
private reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter); | ||
/** | ||
* Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is | ||
* clock-wise during export to glTF | ||
* @param submesh BabylonJS submesh | ||
* @param primitiveMode Primitive mode of the mesh | ||
* @param sideOrientation the winding order of the submesh | ||
* @param vertexBufferKind The type of vertex attribute | ||
* @param meshAttributeArray The vertex attribute data | ||
* @param byteOffset The offset to the binary data | ||
* @param binaryWriter The binary data for the glTF file | ||
*/ | ||
private reorderTriangleFillMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter); | ||
/** | ||
* Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is | ||
* clock-wise during export to glTF | ||
* @param submesh BabylonJS submesh | ||
* @param primitiveMode Primitive mode of the mesh | ||
* @param sideOrientation the winding order of the submesh | ||
* @param vertexBufferKind The type of vertex attribute | ||
* @param meshAttributeArray The vertex attribute data | ||
* @param byteOffset The offset to the binary data | ||
* @param binaryWriter The binary data for the glTF file | ||
*/ | ||
private reorderTriangleStripDrawMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter); | ||
/** | ||
* Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is | ||
* clock-wise during export to glTF | ||
* @param submesh BabylonJS submesh | ||
* @param primitiveMode Primitive mode of the mesh | ||
* @param sideOrientation the winding order of the submesh | ||
* @param vertexBufferKind The type of vertex attribute | ||
* @param meshAttributeArray The vertex attribute data | ||
* @param byteOffset The offset to the binary data | ||
* @param binaryWriter The binary data for the glTF file | ||
*/ | ||
private reorderTriangleFanMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter); | ||
/** | ||
* Writes the vertex attribute data to binary | ||
* @param vertices The vertices to write to the binary writer | ||
* @param byteOffset The offset into the binary writer to overwrite binary data | ||
* @param vertexAttributeKind The vertex attribute type | ||
* @param meshAttributeArray The vertex attribute data | ||
* @param binaryWriter The writer containing the binary data | ||
*/ | ||
private writeVertexAttributeData(vertices, byteOffset, vertexAttributeKind, meshAttributeArray, binaryWriter); | ||
/** | ||
* Writes mesh attribute data to a data buffer | ||
@@ -156,5 +235,5 @@ * Returns the bytelength of the data | ||
* @param binaryWriter The buffer to write the binary data to | ||
* @returns Byte length of the attribute data | ||
* @param indices Used to specify the order of the vertex data | ||
*/ | ||
private writeAttributeData(vertexBufferKind, meshAttributeArray, binaryWriter); | ||
private writeAttributeData(vertexBufferKind, meshAttributeArray, byteStride, binaryWriter); | ||
/** | ||
@@ -195,19 +274,38 @@ * Generates glTF json data | ||
* @param node glTF Node for storing the transformation data | ||
* @param babylonMesh Babylon mesh used as the source for the transformation data | ||
* @param babylonTransformNode Babylon mesh used as the source for the transformation data | ||
*/ | ||
private setNodeTransformation(node, babylonMesh); | ||
private setNodeTransformation(node, babylonTransformNode); | ||
private getVertexBufferFromMesh(attributeKind, bufferMesh); | ||
/** | ||
* Creates a bufferview based on the vertices type for the Babylon mesh | ||
* @param kind Indicates the type of vertices data | ||
* @param babylonMesh The Babylon mesh to get the vertices data from | ||
* @param babylonTransformNode The Babylon mesh to get the vertices data from | ||
* @param binaryWriter The buffer to write the bufferview data to | ||
*/ | ||
private createBufferViewKind(kind, babylonMesh, binaryWriter, byteStride); | ||
private createBufferViewKind(kind, babylonTransformNode, binaryWriter, byteStride); | ||
/** | ||
* The primitive mode of the Babylon mesh | ||
* @param babylonMesh The BabylonJS mesh | ||
*/ | ||
private getMeshPrimitiveMode(babylonMesh); | ||
/** | ||
* Sets the primitive mode of the glTF mesh primitive | ||
* @param meshPrimitive glTF mesh primitive | ||
* @param primitiveMode The primitive mode | ||
*/ | ||
private setPrimitiveMode(meshPrimitive, primitiveMode); | ||
/** | ||
* Sets the vertex attribute accessor based of the glTF mesh primitive | ||
* @param meshPrimitive glTF mesh primitive | ||
* @param attributeKind vertex attribute | ||
* @returns boolean specifying if uv coordinates are present | ||
*/ | ||
private setAttributeKind(meshPrimitive, attributeKind); | ||
/** | ||
* Sets data for the primitive attributes of each submesh | ||
* @param mesh glTF Mesh object to store the primitive attribute information | ||
* @param babylonMesh Babylon mesh to get the primitive attribute data from | ||
* @param babylonTransformNode Babylon mesh to get the primitive attribute data from | ||
* @param binaryWriter Buffer to write the attribute data to | ||
*/ | ||
private setPrimitiveAttributes(mesh, babylonMesh, binaryWriter); | ||
private setPrimitiveAttributes(mesh, babylonTransformNode, binaryWriter); | ||
/** | ||
@@ -218,3 +316,2 @@ * Creates a glTF scene based on the array of meshes | ||
* @param binaryWriter Buffer to write binary data to | ||
* @returns bytelength + byteoffset | ||
*/ | ||
@@ -224,7 +321,7 @@ private createScene(babylonScene, binaryWriter); | ||
* Creates a mapping of Node unique id to node index and handles animations | ||
* @param scene Babylon Scene | ||
* @param babylonScene Babylon Scene | ||
* @param binaryWriter Buffer to write binary data to | ||
* @returns Node mapping of unique id to index | ||
*/ | ||
private createNodeMapAndAnimations(scene, binaryWriter); | ||
private createNodeMapAndAnimations(babylonScene, nodes, shouldExportTransformNode, binaryWriter); | ||
/** | ||
@@ -236,3 +333,3 @@ * Creates a glTF node from a Babylon mesh | ||
*/ | ||
private createNode(babylonMesh, binaryWriter); | ||
private createNode(babylonTransformNode, binaryWriter); | ||
} | ||
@@ -280,14 +377,26 @@ /** | ||
* @param entry | ||
* @param byteOffset If defined, specifies where to set the value as an offset. | ||
*/ | ||
setUInt8(entry: number): void; | ||
setUInt8(entry: number, byteOffset?: number): void; | ||
/** | ||
* Gets an UInt32 in the array buffer | ||
* @param entry | ||
* @param byteOffset If defined, specifies where to set the value as an offset. | ||
*/ | ||
getUInt32(byteOffset: number): number; | ||
getVector3Float32FromRef(vector3: Vector3, byteOffset: number): void; | ||
setVector3Float32FromRef(vector3: Vector3, byteOffset: number): void; | ||
getVector4Float32FromRef(vector4: Vector4, byteOffset: number): void; | ||
setVector4Float32FromRef(vector4: Vector4, byteOffset: number): void; | ||
/** | ||
* Stores a Float32 in the array buffer | ||
* @param entry | ||
*/ | ||
setFloat32(entry: number): void; | ||
setFloat32(entry: number, byteOffset?: number): void; | ||
/** | ||
* Stores an UInt32 in the array buffer | ||
* @param entry | ||
* @param byteOffset If defined, specifies where to set the value as an offset. | ||
*/ | ||
setUInt32(entry: number): void; | ||
setUInt32(entry: number, byteOffset?: number): void; | ||
} | ||
@@ -324,3 +433,2 @@ } | ||
* @hidden | ||
*/ | ||
@@ -357,3 +465,3 @@ class _GLTFMaterial { | ||
*/ | ||
static _ConvertMaterialsToGLTF(babylonMaterials: Material[], mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
static _ConvertMaterialsToGLTF(babylonMaterials: Material[], mimeType: ImageMimeType, images: IImage[], textures: ITexture[], samplers: ISampler[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
@@ -406,3 +514,3 @@ data: Uint8Array; | ||
*/ | ||
static _ConvertStandardMaterial(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
static _ConvertStandardMaterial(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], samplers: ISampler[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
@@ -423,3 +531,3 @@ data: Uint8Array; | ||
*/ | ||
static _ConvertPBRMetallicRoughnessMaterial(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
static _ConvertPBRMetallicRoughnessMaterial(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], samplers: ISampler[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
@@ -495,3 +603,6 @@ data: Uint8Array; | ||
*/ | ||
private static _ConvertMetalRoughFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, glTFPbrMetallicRoughness, imageData, hasTextureCoords); | ||
private static _ConvertMetalRoughFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, samplers, glTFPbrMetallicRoughness, imageData, hasTextureCoords); | ||
private static _GetGLTFTextureSampler(texture); | ||
private static _GetGLTFTextureWrapMode(wrapMode); | ||
private static _GetGLTFTextureWrapModesSampler(texture); | ||
/** | ||
@@ -508,3 +619,3 @@ * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors | ||
*/ | ||
private static _ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, glTFPbrMetallicRoughness, imageData, hasTextureCoords); | ||
private static _ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, samplers, glTFPbrMetallicRoughness, imageData, hasTextureCoords); | ||
/** | ||
@@ -520,3 +631,3 @@ * Converts a Babylon PBR Metallic Roughness Material to a glTF Material | ||
*/ | ||
static _ConvertPBRMaterial(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
static _ConvertPBRMaterial(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], samplers: ISampler[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
@@ -537,3 +648,3 @@ data: Uint8Array; | ||
*/ | ||
private static _ExportTexture(babylonTexture, mimeType, images, textures, imageData); | ||
private static _ExportTexture(babylonTexture, mimeType, images, textures, samplers, imageData); | ||
/** | ||
@@ -549,3 +660,3 @@ * Builds a texture from base64 string | ||
*/ | ||
private static _GetTextureInfoFromBase64(base64Texture, textureName, mimeType, images, textures, imageData); | ||
private static _GetTextureInfoFromBase64(base64Texture, textureName, mimeType, images, textures, texCoordIndex, samplerIndex, imageData); | ||
} | ||
@@ -605,5 +716,6 @@ } | ||
/** | ||
* @ignore | ||
* | ||
* Creates glTF channel animation from BabylonJS animation. | ||
* @param babylonMesh - BabylonJS mesh. | ||
* @param babylonTransformNode - BabylonJS mesh. | ||
* @param animation - animation. | ||
@@ -615,7 +727,8 @@ * @param animationChannelTargetPath - The target animation channel. | ||
*/ | ||
static _CreateNodeAnimation(babylonMesh: BABYLON.Mesh, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData>; | ||
static _CreateNodeAnimation(babylonTransformNode: TransformNode, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData>; | ||
private static _DeduceAnimationInfo(animation); | ||
/** | ||
* | ||
* @param babylonMesh | ||
* @ignore | ||
* Create node animations from the transform node animations | ||
* @param babylonTransformNode | ||
* @param runtimeGLTFAnimation | ||
@@ -630,7 +743,8 @@ * @param idleGLTFAnimations | ||
*/ | ||
static _CreateNodeAnimationFromMeshAnimations(babylonMesh: Mesh, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: { | ||
static _CreateNodeAnimationFromTransformNodeAnimations(babylonTransformNode: TransformNode, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: { | ||
[key: number]: number; | ||
}, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void; | ||
/** | ||
* | ||
* @ignore | ||
* Create node animations from the animation groups | ||
* @param babylonScene | ||
@@ -648,6 +762,6 @@ * @param glTFAnimations | ||
}, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void; | ||
private static AddAnimation(name, glTFAnimation, babylonMesh, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, useQuaternion, animationSampleRate); | ||
private static AddAnimation(name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, useQuaternion, animationSampleRate); | ||
/** | ||
* Create a baked animation | ||
* @param babylonMesh BabylonJS mesh | ||
* @param babylonTransformNode BabylonJS mesh | ||
* @param animation BabylonJS animation corresponding to the BabylonJS mesh | ||
@@ -663,8 +777,8 @@ * @param animationChannelTargetPath animation target channel | ||
*/ | ||
private static _CreateBakedAnimation(babylonMesh, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, convertToRightHandedSystem, useQuaternion); | ||
private static _ConvertFactorToVector3OrQuaternion(factor, babylonMesh, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion); | ||
private static _SetInterpolatedValue(babylonMesh, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion); | ||
private static _CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, convertToRightHandedSystem, useQuaternion); | ||
private static _ConvertFactorToVector3OrQuaternion(factor, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion); | ||
private static _SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion); | ||
/** | ||
* Creates linear animation from the animation key frames | ||
* @param babylonMesh BabylonJS mesh | ||
* @param babylonTransformNode BabylonJS mesh | ||
* @param animation BabylonJS animation | ||
@@ -678,6 +792,6 @@ * @param animationChannelTargetPath The target animation channel | ||
*/ | ||
private static _CreateLinearOrStepAnimation(babylonMesh, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion); | ||
private static _CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion); | ||
/** | ||
* Creates cubic spline animation from the animation key frames | ||
* @param babylonMesh BabylonJS mesh | ||
* @param babylonTransformNode BabylonJS mesh | ||
* @param animation BabylonJS animation | ||
@@ -691,4 +805,4 @@ * @param animationChannelTargetPath The target animation channel | ||
*/ | ||
private static _CreateCubicSplineAnimation(babylonMesh, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion); | ||
private static _GetBasePositionRotationOrScale(babylonMesh, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion); | ||
private static _CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion); | ||
private static _GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion); | ||
/** | ||
@@ -704,3 +818,9 @@ * Adds a key frame value | ||
*/ | ||
private static _AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonMesh, convertToRightHandedSystem, useQuaternion); | ||
private static _AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion); | ||
/** | ||
* Determine the interpolation based on the key frames | ||
* @param keyFrames | ||
* @param animationChannelTargetPath | ||
* @param useQuaternion | ||
*/ | ||
private static _DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion); | ||
@@ -719,3 +839,3 @@ /** | ||
*/ | ||
private static AddSplineTangent(tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem); | ||
private static AddSplineTangent(babylonTransformNode, tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem); | ||
/** | ||
@@ -775,3 +895,3 @@ * Get the minimum and maximum key frames' frame values | ||
*/ | ||
static GetRightHandedVector3(vector: Vector3): Vector3; | ||
static GetRightHandedPositionVector3(vector: Vector3): Vector3; | ||
/** | ||
@@ -781,4 +901,25 @@ * Converts a Vector3 to right-handed | ||
*/ | ||
static GetRightHandedVector3FromRef(vector: Vector3): void; | ||
static GetRightHandedPositionVector3FromRef(vector: Vector3): void; | ||
/** | ||
* Converts a three element number array to right-handed | ||
* @param vector number array to convert to right-handed | ||
*/ | ||
static GetRightHandedPositionArray3FromRef(vector: number[]): void; | ||
/** | ||
* Converts a new right-handed Vector3 | ||
* @param vector vector3 array | ||
* @returns right-handed Vector3 | ||
*/ | ||
static GetRightHandedNormalVector3(vector: Vector3): Vector3; | ||
/** | ||
* Converts a Vector3 to right-handed | ||
* @param vector Vector3 to convert to right-handed | ||
*/ | ||
static GetRightHandedNormalVector3FromRef(vector: Vector3): void; | ||
/** | ||
* Converts a three element number array to right-handed | ||
* @param vector number array to convert to right-handed | ||
*/ | ||
static GetRightHandedNormalArray3FromRef(vector: number[]): void; | ||
/** | ||
* Converts a Vector4 to right-handed | ||
@@ -789,2 +930,7 @@ * @param vector Vector4 to convert to right-handed | ||
/** | ||
* Converts a Vector4 to right-handed | ||
* @param vector Vector4 to convert to right-handed | ||
*/ | ||
static GetRightHandedArray4FromRef(vector: number[]): void; | ||
/** | ||
* Converts a Quaternion to right-handed | ||
@@ -794,3 +940,8 @@ * @param quaternion Source quaternion to convert to right-handed | ||
static GetRightHandedQuaternionFromRef(quaternion: Quaternion): void; | ||
/** | ||
* Converts a Quaternion to right-handed | ||
* @param quaternion Source quaternion to convert to right-handed | ||
*/ | ||
static GetRightHandedQuaternionArrayFromRef(quaternion: number[]): void; | ||
} | ||
} |
@@ -7,3 +7,3 @@ { | ||
"description": "The Babylon.js serializers library is an extension you can use to serialize Babylon scenes.", | ||
"version": "3.2.0-rc.4", | ||
"version": "3.2.0", | ||
"repository": { | ||
@@ -31,3 +31,3 @@ "type": "git", | ||
"dependencies": { | ||
"babylonjs-gltf2interface": "3.2.0-rc.4" | ||
"babylonjs-gltf2interface": "3.2.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
288324
4331
2
+ Addedbabylonjs-gltf2interface@3.2.0(transitive)
- Removedbabylonjs-gltf2interface@3.2.0-rc.4(transitive)