1 |
- var BABYLON;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r){var s=r.replace(/\.[^\/.]+$/,"");return new e._GLTF2Exporter(t)._generateGLTF(s)},t.GLB=function(t,r){var s=r.replace(/\.[^\/.]+$/,"");return new e._GLTF2Exporter(t)._generateGLB(s)},t})();e.GLTF2Export=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function t(e){this.asset={generator:"BabylonJS",version:"2.0"},this.babylonScene=e,this.bufferViews=new Array,this.accessors=new Array,this.meshes=new Array,this.scenes=new Array,this.nodes=new Array;var t=0;t=this.createScene(this.babylonScene,t),this.totalByteLength=t}return t.prototype.createBufferView=function(e,t,r){var s={buffer:e,byteLength:r};return t>0&&(s.byteOffset=t),s},t.prototype.createAccessor=function(e,t,r,s,i,n,a){var o={name:t,bufferView:e,componentType:s,count:i,type:r};return n&&(o.min=n),a&&(o.max=a),o},t.prototype.calculateMinMax=function(e,t,r,s,i){var n=[1/0,1/0,1/0],a=[-(1/0),-(1/0),-(1/0)],o=t+r;if(r>0)for(var f=t;f<o;++f)for(var c=i*f,u=0;u<i;++u)e[c]<n[u]&&(n[u]=e[c]),e[c]>a[u]&&(a[u]=e[c]),++c;return{min:n,max:a}},t.prototype.writeAttributeData=function(t,r,s,i,n,a,o){var f=n,c=r.verticesStart+r.verticesCount,u=0;switch(t){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var h=r.verticesStart;h<c;++h){var l=h*i;a.setFloat32(f,s[l],!0),f+=4,a.setFloat32(f,s[l+1],!0),f+=4,o?a.setFloat32(f,s[l+2],!0):a.setFloat32(f,-s[l+2],!0),f+=4}u=12*r.verticesCount;break;case e.VertexBuffer.TangentKind:for(var h=r.indexStart;h<c;++h){var l=h*i;a.setFloat32(f,s[l],!0),f+=4,a.setFloat32(f,s[l+1],!0),f+=4,o?a.setFloat32(f,s[l+2],!0):a.setFloat32(f,-s[l+2],!0),f+=4,a.setFloat32(f,s[l+3],!0),f+=4}u=16*r.verticesCount;break;case e.VertexBuffer.ColorKind:for(var h=r.verticesStart;h<c;++h){var l=h*i;a.setFloat32(f,s[l],!0),f+=4,a.setFloat32(f,s[l+1],!0),f+=4,a.setFloat32(f,s[l+2],!0),f+=4,a.setFloat32(f,s[l+3],!0),f+=4}u=16*r.verticesCount;break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=r.verticesStart;h<c;++h){var l=h*i;a.setFloat32(f,s[l],!0),f+=4,a.setFloat32(f,s[l+1],!0),f+=4}u=8*r.verticesCount;break;default:throw new Error("Unsupported vertex buffer type: "+t)}return u},t.prototype.generateJSON=function(e,t,r){var s={byteLength:this.totalByteLength},i={buffers:[s],asset:this.asset,meshes:this.meshes,scenes:this.scenes,nodes:this.nodes,bufferViews:this.bufferViews,accessors:this.accessors};return this.scenes.length>0&&(i.scene=0),e||(s.uri=t+".bin"),r?JSON.stringify(i,null,2):JSON.stringify(i)},t.prototype._generateGLTF=function(t){var r=this.generateJSON(!1,t,!0),s=this.generateBinary(),i=new Blob([s],{type:"application/octet-stream"}),n=t+".gltf",a=t+".bin",o=new e._GLTFData;return o._glTFFiles[n]=r,o._glTFFiles[a]=i,o},t.prototype.generateBinary=function(){var e=0,t=new ArrayBuffer(this.totalByteLength),r=new DataView(t);return e=this.createScene(this.babylonScene,e,r),t},t.prototype._generateGLB=function(t){var r=this.generateJSON(!0),s=this.generateBinary(),i=t+".glb",n=r.length,a=n%4,o=s.byteLength%4,f=0===a?a:4-a,c=0===o?o:4-o,u=28+n+f+s.byteLength+c,h=new ArrayBuffer(12),l=new DataView(h);l.setUint32(0,1179937895,!0),l.setUint32(4,2,!0),l.setUint32(8,u,!0);var v=new ArrayBuffer(8+n+f),g=new DataView(v);g.setUint32(0,n+f,!0),g.setUint32(4,1313821514,!0);for(var p=new Uint8Array(v,8),V=0;V<n;++V)p[V]=r.charCodeAt(V);for(var B=new Uint8Array(v,8+n),V=0;V<f;++V)B[V]=32;var w=new ArrayBuffer(8),d=new DataView(w);d.setUint32(0,s.byteLength,!0),d.setUint32(4,5130562,!0);for(var b=new ArrayBuffer(c),y=new Uint8Array(b),V=0;V<c;++V)y[V]=0;var x=new Blob([h,v,w,s,b],{type:"application/octet-stream"}),A=new e._GLTFData;return A._glTFFiles[i]=x,A},t.prototype.setNodeTransformation=function(t,r,s){0===r.position.x&&0===r.position.y&&0===r.position.z||(t.translation=s?r.position.asArray():[r.position.x,r.position.y,-r.position.z]),1===r.scaling.x&&1===r.scaling.y&&1===r.scaling.z||(t.scale=s?r.scaling.asArray():[r.scaling.x,r.scaling.y,-r.scaling.z]);var i=e.Quaternion.RotationYawPitchRoll(r.rotation.y,r.rotation.x,r.rotation.z);r.rotationQuaternion&&(i=i.multiply(r.rotationQuaternion)),0===i.x&&0===i.y&&0===i.z&&1===i.w||(t.rotation=s?i.asArray():[-i.x,-i.y,i.z,i.w])},t.prototype.setPrimitiveAttributes=function(t,r,s,i,n){for(var a=0;a<r.subMeshes.length;++a){var o=null,f=r.subMeshes[a],c={attributes:{}};if(r instanceof e.Mesh?o=r:r instanceof e.InstancedMesh&&(o=r.sourceMesh),o.isVerticesDataPresent(e.VertexBuffer.PositionKind)){var u=o.getVertexBuffer(e.VertexBuffer.PositionKind),h=u.getOffset(),l=u.getData(),v=u.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.PositionKind,f,l,v,s,n,i);else{var g=12*f.verticesCount,p=this.createBufferView(0,s,g);s+=g,this.bufferViews.push(p);var V=this.calculateMinMax(l,f.verticesStart,f.verticesCount,h,v),B=this.createAccessor(this.bufferViews.length-1,"Position","VEC3",5126,f.verticesCount,V.min,V.max);this.accessors.push(B),c.attributes.POSITION=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.NormalKind)){var w=o.getVertexBuffer(e.VertexBuffer.NormalKind),d=w.getData(),b=w.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.NormalKind,f,d,b,s,n,i);else{var g=12*f.verticesCount,p=this.createBufferView(0,s,g);s+=g,this.bufferViews.push(p);var B=this.createAccessor(this.bufferViews.length-1,"Normal","VEC3",5126,f.verticesCount);this.accessors.push(B),c.attributes.NORMAL=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.TangentKind)){var y=o.getVertexBuffer(e.VertexBuffer.TangentKind),x=y.getData(),A=y.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.TangentKind,f,x,A,s,n,i);else{var g=16*f.verticesCount,p=this.createBufferView(0,s,g);s+=g,this.bufferViews.push(p);var B=this.createAccessor(this.bufferViews.length-1,"Tangent","VEC4",5126,f.verticesCount);this.accessors.push(B),c.attributes.TANGENT=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.ColorKind)){var m=o.getVertexBuffer(e.VertexBuffer.ColorKind),C=m.getData(),F=m.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.ColorKind,f,C,F,s,n,i);else{var g=16*f.verticesCount,p=this.createBufferView(0,s,g);s+=g,this.bufferViews.push(p);var B=this.createAccessor(this.bufferViews.length-1,"Color","VEC4",5126,f.verticesCount);this.accessors.push(B),c.attributes.COLOR_0=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.UVKind)){var L=o.getVertexBuffer(e.VertexBuffer.UVKind),S=L.getData(),T=L.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.UVKind,f,S,T,s,n,i);else{var g=8*f.verticesCount,p=this.createBufferView(0,s,g);s+=g,this.bufferViews.push(p);var B=this.createAccessor(this.bufferViews.length-1,"Texture Coords","VEC2",5126,f.verticesCount);this.accessors.push(B),c.attributes.TEXCOORD_0=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)){var D=o.getVertexBuffer(e.VertexBuffer.UV2Kind),O=D.getData(),N=D.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.UV2Kind,f,O,N,s,n,i);else{var g=8*f.verticesCount,p=this.createBufferView(0,s,g);s+=g,this.bufferViews.push(p);var B=this.createAccessor(this.bufferViews.length-1,"Texture Coords","VEC2",5126,f.verticesCount);this.accessors.push(B),c.attributes.TEXCOORD_1=this.accessors.length-1}}if(o.getTotalIndices()>0)if(n){for(var K=o.getIndices(),U=f.indexStart,_=f.indexCount+U,E=s,P=U;P<_;P+=3)n.setUint32(E,K[P],!0),E+=4,n.setUint32(E,K[P+1],!0),E+=4,n.setUint32(E,K[P+2],!0),E+=4;var g=4*f.indexCount;s+=g}else{var G=f.indexCount,g=4*G,p=this.createBufferView(0,s,g);s+=g,this.bufferViews.push(p);var B=this.createAccessor(this.bufferViews.length-1,"Indices","SCALAR",5125,G);this.accessors.push(B),c.indices=this.accessors.length-1}o.material,t.primitives.push(c)}return s},t.prototype.createScene=function(e,t,r){if(e.meshes.length>0){for(var s=e.meshes,i={nodes:new Array},n=0;n<s.length;++n){var a={mesh:-1},o=s[n],f=o.getScene().useRightHandedSystem;this.setNodeTransformation(a,o,f);var c={primitives:new Array};c.primitives=[],t=this.setPrimitiveAttributes(c,o,t,f,r),this.meshes.push(c),a.mesh=this.meshes.length-1,o.name&&(a.name=o.name),this.nodes.push(a),i.nodes.push(this.nodes.length-1)}this.scenes.push(i)}return t},t})();e._GLTF2Exporter=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function e(){this._glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return e.indexOf(t,e.length-t.length)!==-1}for(var t in this._glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var s=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"}),r.href=window.URL.createObjectURL(new Blob([s],i)),r.click()}},e})();e._GLTFData=t})(BABYLON||(BABYLON={}));
|