babylonjs-loaders 9.22.2 → 9.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).BABYLON=t.BABYLON||{},t.BABYLON)}(this,function(t,s){"use strict";class e{constructor(){this.materials=[]}parseMTL(t,i,o,r){if(i instanceof ArrayBuffer)return;const n=i.split("\n"),a=/\s+/;let l,h=null;for(let i=0;i<n.length;i++){const _=n[i].trim();if(0===_.length||"#"===_.charAt(0))continue;const p=_.indexOf(" ");let d=p>=0?_.substring(0,p):_;d=d.toLowerCase();const m=p>=0?_.substring(p+1).trim():"";if("newmtl"===d)h&&this.materials.push(h),t._blockEntityCollection=!!r,h=new s.StandardMaterial(m,t),h._parentContainer=r,t._blockEntityCollection=!1;else if("kd"===d&&h)l=m.split(a,3).map(parseFloat),h.diffuseColor=s.Color3.FromArray(l);else if("ka"===d&&h)l=m.split(a,3).map(parseFloat),h.ambientColor=s.Color3.FromArray(l);else if("ks"===d&&h)l=m.split(a,3).map(parseFloat),h.specularColor=s.Color3.FromArray(l);else if("ke"===d&&h)l=m.split(a,3).map(parseFloat),h.emissiveColor=s.Color3.FromArray(l);else if("ns"===d&&h)h.specularPower=parseFloat(m);else if("d"===d&&h)h.alpha=parseFloat(m);else if("map_ka"===d&&h)h.ambientTexture=e._GetTexture(o,m,t);else if("map_kd"===d&&h)h.diffuseTexture=e._GetTexture(o,m,t);else if("map_ks"===d&&h)h.specularTexture=e._GetTexture(o,m,t);else if("map_ns"===d);else if("map_bump"===d&&h){const s=m.split(a),i=s.indexOf("-bm");let r=null;i>=0&&(r=s[i+1],s.splice(i,2)),h.bumpTexture=e._GetTexture(o,s.join(" "),t),h.bumpTexture&&null!==r&&(h.bumpTexture.level=parseFloat(r))}else"map_d"===d&&h&&(h.opacityTexture=e._GetTexture(o,m,t))}h&&this.materials.push(h)}static _GetTexture(t,i,o){if(!i)return null;let r=t;if("file:"===t){let t=i.lastIndexOf("\\");-1===t&&(t=i.lastIndexOf("/")),r+=t>-1?i.substring(t+1):i}else r+=i;return new s.Texture(r,o,!1,e.INVERT_TEXTURE_Y)}}e.INVERT_TEXTURE_Y=!0;class i{constructor(t,e,i){this._positions=[],this._normals=[],this._uvs=[],this._colors=[],this._extColors=[],this._meshesFromObj=[],this._indicesForBabylon=[],this._wrappedPositionForBabylon=[],this._wrappedUvsForBabylon=[],this._wrappedColorsForBabylon=[],this._wrappedNormalsForBabylon=[],this._tuplePosNorm=[],this._curPositionInIndices=0,this._hasMeshes=!1,this._unwrappedPositionsForBabylon=[],this._unwrappedColorsForBabylon=[],this._unwrappedNormalsForBabylon=[],this._unwrappedUVForBabylon=[],this._triangles=[],this._materialNameFromObj="",this._objMeshName="",this._increment=1,this._isFirstMaterial=!0,this._grayColor=new s.Color4(.5,.5,.5,1),this._hasLineData=!1,this._materialToUse=t,this._babylonMeshesArray=e,this._loadingOptions=i}_isInArray(t,s){t[s[0]]||(t[s[0]]={normals:[],idx:[]});const e=t[s[0]].normals.indexOf(s[1]);return-1===e?-1:t[s[0]].idx[e]}_isInArrayUV(t,s){t[s[0]]||(t[s[0]]={normals:[],idx:[],uv:[]});const e=t[s[0]].normals.indexOf(s[1]);return 1!=e&&s[2]===t[s[0]].uv[e]?t[s[0]].idx[e]:-1}_setData(t){var s,e;let i;null!==(s=t.indiceUvsFromObj)&&void 0!==s||(t.indiceUvsFromObj=-1),null!==(e=t.indiceNormalFromObj)&&void 0!==e||(t.indiceNormalFromObj=-1),i=this._loadingOptions.optimizeWithUV?this._isInArrayUV(this._tuplePosNorm,[t.indicePositionFromObj,t.indiceNormalFromObj,t.indiceUvsFromObj]):this._isInArray(this._tuplePosNorm,[t.indicePositionFromObj,t.indiceNormalFromObj]),-1===i?(this._indicesForBabylon.push(this._wrappedPositionForBabylon.length),this._wrappedPositionForBabylon.push(t.positionVectorFromOBJ),void 0!==t.textureVectorFromOBJ&&this._wrappedUvsForBabylon.push(t.textureVectorFromOBJ),void 0!==t.normalsVectorFromOBJ&&this._wrappedNormalsForBabylon.push(t.normalsVectorFromOBJ),void 0!==t.positionColorsFromOBJ&&this._wrappedColorsForBabylon.push(t.positionColorsFromOBJ),this._tuplePosNorm[t.indicePositionFromObj].normals.push(t.indiceNormalFromObj),this._tuplePosNorm[t.indicePositionFromObj].idx.push(this._curPositionInIndices++),this._loadingOptions.optimizeWithUV&&this._tuplePosNorm[t.indicePositionFromObj].uv.push(t.indiceUvsFromObj)):this._indicesForBabylon.push(i)}_unwrapData(){try{for(let t=0;t<this._wrappedPositionForBabylon.length;t++)this._unwrappedPositionsForBabylon.push(this._wrappedPositionForBabylon[t].x*this._handednessSign,this._wrappedPositionForBabylon[t].y,this._wrappedPositionForBabylon[t].z),this._wrappedNormalsForBabylon.length&&this._unwrappedNormalsForBabylon.push(this._wrappedNormalsForBabylon[t].x*this._handednessSign,this._wrappedNormalsForBabylon[t].y,this._wrappedNormalsForBabylon[t].z),this._wrappedUvsForBabylon.length&&this._unwrappedUVForBabylon.push(this._wrappedUvsForBabylon[t].x,this._wrappedUvsForBabylon[t].y),this._wrappedColorsForBabylon.length&&this._unwrappedColorsForBabylon.push(this._wrappedColorsForBabylon[t].r,this._wrappedColorsForBabylon[t].g,this._wrappedColorsForBabylon[t].b,this._wrappedColorsForBabylon[t].a);this._wrappedPositionForBabylon.length=0,this._wrappedNormalsForBabylon.length=0,this._wrappedUvsForBabylon.length=0,this._wrappedColorsForBabylon.length=0,this._tuplePosNorm.length=0,this._curPositionInIndices=0}catch(t){throw new Error("Unable to unwrap data while parsing OBJ data.",{cause:t})}}_getTriangles(t,s){for(let e=s;e<t.length-1;e++)this._pushTriangle(t,e)}_getColor(t){var s;return this._loadingOptions.importVertexColors?null!==(s=this._extColors[t])&&void 0!==s?s:this._colors[t]:void 0}_setDataForCurrentFaceWithPattern1(t,s){this._getTriangles(t,s);for(let t=0;t<this._triangles.length;t++){const s=parseInt(this._triangles[t])-1;this._setData({indicePositionFromObj:s,positionVectorFromOBJ:this._positions[s],positionColorsFromOBJ:this._getColor(s)})}this._triangles.length=0}_setDataForCurrentFaceWithPattern2(t,s){this._getTriangles(t,s);for(let t=0;t<this._triangles.length;t++){const s=this._triangles[t].split("/"),e=parseInt(s[0])-1,i=parseInt(s[1])-1;this._setData({indicePositionFromObj:e,indiceUvsFromObj:i,positionVectorFromOBJ:this._positions[e],textureVectorFromOBJ:this._uvs[i],positionColorsFromOBJ:this._getColor(e)})}this._triangles.length=0}_setDataForCurrentFaceWithPattern3(t,s){this._getTriangles(t,s);for(let t=0;t<this._triangles.length;t++){const s=this._triangles[t].split("/"),e=parseInt(s[0])-1,i=parseInt(s[1])-1,o=parseInt(s[2])-1;this._setData({indicePositionFromObj:e,indiceUvsFromObj:i,indiceNormalFromObj:o,positionVectorFromOBJ:this._positions[e],textureVectorFromOBJ:this._uvs[i],normalsVectorFromOBJ:this._normals[o]})}this._triangles.length=0}_setDataForCurrentFaceWithPattern4(t,s){this._getTriangles(t,s);for(let t=0;t<this._triangles.length;t++){const s=this._triangles[t].split("//"),e=parseInt(s[0])-1,i=parseInt(s[1])-1;this._setData({indicePositionFromObj:e,indiceNormalFromObj:i,positionVectorFromOBJ:this._positions[e],normalsVectorFromOBJ:this._normals[i],positionColorsFromOBJ:this._getColor(e)})}this._triangles.length=0}_setDataForCurrentFaceWithPattern5(t,s){this._getTriangles(t,s);for(let t=0;t<this._triangles.length;t++){const s=this._triangles[t].split("/"),e=this._positions.length+parseInt(s[0]),i=this._uvs.length+parseInt(s[1]),o=this._normals.length+parseInt(s[2]);this._setData({indicePositionFromObj:e,indiceUvsFromObj:i,indiceNormalFromObj:o,positionVectorFromOBJ:this._positions[e],textureVectorFromOBJ:this._uvs[i],normalsVectorFromOBJ:this._normals[o],positionColorsFromOBJ:this._getColor(e)})}this._triangles.length=0}_addPreviousObjMesh(){this._meshesFromObj.length>0&&(this._handledMesh=this._meshesFromObj[this._meshesFromObj.length-1],this._unwrapData(),this._loadingOptions.useLegacyBehavior&&this._indicesForBabylon.reverse(),this._handledMesh.indices=this._indicesForBabylon.slice(),this._handledMesh.positions=this._unwrappedPositionsForBabylon.slice(),this._unwrappedNormalsForBabylon.length&&(this._handledMesh.normals=this._unwrappedNormalsForBabylon.slice()),this._unwrappedUVForBabylon.length&&(this._handledMesh.uvs=this._unwrappedUVForBabylon.slice()),this._unwrappedColorsForBabylon.length&&(this._handledMesh.colors=this._unwrappedColorsForBabylon.slice()),this._handledMesh.hasLines=this._hasLineData,this._indicesForBabylon.length=0,this._unwrappedPositionsForBabylon.length=0,this._unwrappedColorsForBabylon.length=0,this._unwrappedNormalsForBabylon.length=0,this._unwrappedUVForBabylon.length=0,this._hasLineData=!1)}_optimizeNormals(t){const e=t.getVerticesData(s.VertexBuffer.PositionKind),i=t.getVerticesData(s.VertexBuffer.NormalKind),o={};if(!e||!i)return;for(let t=0;t<e.length/3;t++){const s=e[3*t+0]+"_"+e[3*t+1]+"_"+e[3*t+2];let i=o[s];i||(i=[],o[s]=i),i.push(t)}const r=new s.Vector3;for(const t in o){const s=o[t];if(s.length<2)continue;const e=s[0];for(let t=1;t<s.length;++t){const o=s[t];i[3*e+0]+=i[3*o+0],i[3*e+1]+=i[3*o+1],i[3*e+2]+=i[3*o+2]}r.copyFromFloats(i[3*e+0],i[3*e+1],i[3*e+2]),r.normalize();for(let t=0;t<s.length;++t){const e=s[t];i[3*e+0]=r.x,i[3*e+1]=r.y,i[3*e+2]=r.z}}t.setVerticesData(s.VertexBuffer.NormalKind,i)}static _IsLineElement(t){return t.startsWith("l")}static _IsObjectElement(t){return t.startsWith("o")}static _IsGroupElement(t){return t.startsWith("g")}static _GetZbrushMRGB(t,e){if(!t.startsWith("mrgb"))return null;if(t=t.replace("mrgb","").trim(),e)return[];const i=t.match(/[a-z0-9]/g);if(!i||i.length%8!=0)return[];const o=[];for(let t=0;t<i.length/8;t++){const e=i[8*t+2]+i[8*t+3],r=i[8*t+4]+i[8*t+5],n=i[8*t+6]+i[8*t+7];o.push(new s.Color4(parseInt(e,16)/255,parseInt(r,16)/255,parseInt(n,16)/255,1))}return o}parse(t,e,o,r,n){var a,l,h,_,p;e=(e=e.replace(/#MRGB/g,"mrgb")).replace(/#.*$/gm,"").trim(),this._loadingOptions.useLegacyBehavior?(this._pushTriangle=(t,s)=>this._triangles.push(t[0],t[s],t[s+1]),this._handednessSign=1):o.useRightHandedSystem?(this._pushTriangle=(t,s)=>this._triangles.push(t[0],t[s+1],t[s]),this._handednessSign=1):(this._pushTriangle=(t,s)=>this._triangles.push(t[0],t[s],t[s+1]),this._handednessSign=-1);const d=e.split("\n"),m=[];let c=[];m.push(c);for(let t=0;t<d.length;t++){const s=d[t].trim().replace(/\s\s/g," ");if(0!==s.length&&"#"!==s.charAt(0))if((i._IsGroupElement(s)||i._IsObjectElement(s))&&(c=[],m.push(c)),i._IsLineElement(s)){const t=s.split(" ");for(let s=1;s<t.length-1;s++)c.push(`l ${t[s]} ${t[s+1]}`)}else c.push(s)}const u=m.flat();for(let t=0;t<u.length;t++){const e=u[t].trim().replace(/\s\s/g," ");let o;if(0!==e.length&&"#"!==e.charAt(0))if(i.VertexPattern.test(e)){if(o=e.match(/[^ ]+/g),this._positions.push(new s.Vector3(parseFloat(o[1]),parseFloat(o[2]),parseFloat(o[3]))),this._loadingOptions.importVertexColors)if(o.length>=7){const t=parseFloat(o[4]),e=parseFloat(o[5]),i=parseFloat(o[6]);this._colors.push(new s.Color4(t>1?t/255:t,e>1?e/255:e,i>1?i/255:i,7===o.length||void 0===o[7]?1:parseFloat(o[7])))}else this._colors.push(this._grayColor)}else if(null!==(o=i.NormalPattern.exec(e)))this._normals.push(new s.Vector3(parseFloat(o[1]),parseFloat(o[2]),parseFloat(o[3])));else if(null!==(o=i.UVPattern.exec(e)))this._uvs.push(new s.Vector2(parseFloat(o[1])*this._loadingOptions.UVScaling.x,parseFloat(o[2])*this._loadingOptions.UVScaling.y));else if(null!==(o=i.FacePattern3.exec(e)))this._setDataForCurrentFaceWithPattern3(o[1].trim().split(" "),1);else if(null!==(o=i.FacePattern4.exec(e)))this._setDataForCurrentFaceWithPattern4(o[1].trim().split(" "),1);else if(null!==(o=i.FacePattern5.exec(e)))this._setDataForCurrentFaceWithPattern5(o[1].trim().split(" "),1);else if(null!==(o=i.FacePattern2.exec(e)))this._setDataForCurrentFaceWithPattern2(o[1].trim().split(" "),1);else if(null!==(o=i.FacePattern1.exec(e)))this._setDataForCurrentFaceWithPattern1(o[1].trim().split(" "),1);else if(null!==(o=i.LinePattern1.exec(e)))this._setDataForCurrentFaceWithPattern1(o[1].trim().split(" "),0),this._hasLineData=!0;else if(null!==(o=i.LinePattern2.exec(e)))this._setDataForCurrentFaceWithPattern2(o[1].trim().split(" "),0),this._hasLineData=!0;else if(o=i._GetZbrushMRGB(e,!this._loadingOptions.importVertexColors))for(const t of o)this._extColors.push(t);else if(null!==(o=i.LinePattern3.exec(e)))this._setDataForCurrentFaceWithPattern3(o[1].trim().split(" "),0),this._hasLineData=!0;else if(i.GroupDescriptor.test(e)||i.ObjectDescriptor.test(e)){const t={name:e.substring(2).trim(),indices:null,positions:null,normals:null,uvs:null,colors:null,materialName:this._materialNameFromObj,isObject:i.ObjectDescriptor.test(e)};this._addPreviousObjMesh(),this._meshesFromObj.push(t),this._hasMeshes=!0,this._isFirstMaterial=!0,this._increment=1}else if(i.UseMtlDescriptor.test(e)){if(this._materialNameFromObj=e.substring(7).trim(),!this._isFirstMaterial||!this._hasMeshes){this._addPreviousObjMesh();const t={name:(this._objMeshName||"mesh")+"_mm"+this._increment.toString(),indices:null,positions:null,normals:null,uvs:null,colors:null,materialName:this._materialNameFromObj,isObject:!1};this._increment++,this._meshesFromObj.push(t),this._hasMeshes=!0}this._hasMeshes&&this._isFirstMaterial&&(this._meshesFromObj[this._meshesFromObj.length-1].materialName=this._materialNameFromObj,this._isFirstMaterial=!1)}else i.MtlLibGroupDescriptor.test(e)?n(e.substring(7).trim()):i.SmoothDescriptor.test(e)||s.Logger.Log("Unhandled expression at line : "+e)}if(this._hasMeshes&&(this._handledMesh=this._meshesFromObj[this._meshesFromObj.length-1],this._loadingOptions.useLegacyBehavior&&this._indicesForBabylon.reverse(),this._unwrapData(),this._handledMesh.indices=this._indicesForBabylon,this._handledMesh.positions=this._unwrappedPositionsForBabylon,this._unwrappedNormalsForBabylon.length&&(this._handledMesh.normals=this._unwrappedNormalsForBabylon),this._unwrappedUVForBabylon.length&&(this._handledMesh.uvs=this._unwrappedUVForBabylon),this._unwrappedColorsForBabylon.length&&(this._handledMesh.colors=this._unwrappedColorsForBabylon),this._handledMesh.hasLines=this._hasLineData),!this._hasMeshes){let t=null;if(this._indicesForBabylon.length)this._loadingOptions.useLegacyBehavior&&this._indicesForBabylon.reverse(),this._unwrapData();else{for(const t of this._positions)this._unwrappedPositionsForBabylon.push(t.x,t.y,t.z);if(this._normals.length)for(const t of this._normals)this._unwrappedNormalsForBabylon.push(t.x,t.y,t.z);if(this._uvs.length)for(const t of this._uvs)this._unwrappedUVForBabylon.push(t.x,t.y);if(this._extColors.length)for(const t of this._extColors)this._unwrappedColorsForBabylon.push(t.r,t.g,t.b,t.a);else if(this._colors.length)for(const t of this._colors)this._unwrappedColorsForBabylon.push(t.r,t.g,t.b,t.a);this._materialNameFromObj||(t=new s.StandardMaterial(s.Geometry.RandomId(),o),t.pointsCloud=!0,this._materialNameFromObj=t.name,this._normals.length||(t.disableLighting=!0,t.emissiveColor=s.Color3.White()))}this._meshesFromObj.push({name:s.Geometry.RandomId(),indices:this._indicesForBabylon,positions:this._unwrappedPositionsForBabylon,colors:this._unwrappedColorsForBabylon,normals:this._unwrappedNormalsForBabylon,uvs:this._unwrappedUVForBabylon,materialName:this._materialNameFromObj,directMaterial:t,isObject:!0,hasLines:this._hasLineData})}for(let e=0;e<this._meshesFromObj.length;e++){if(t&&this._meshesFromObj[e].name)if(t instanceof Array){if(-1===t.indexOf(this._meshesFromObj[e].name))continue}else if(this._meshesFromObj[e].name!==t)continue;this._handledMesh=this._meshesFromObj[e],o._blockEntityCollection=!!r;const i=new s.Mesh(this._meshesFromObj[e].name,o);if(i._parentContainer=r,o._blockEntityCollection=!1,this._handledMesh._babylonMesh=i,!this._handledMesh.isObject)for(let t=e-1;t>=0;--t)if(this._meshesFromObj[t].isObject&&this._meshesFromObj[t]._babylonMesh){i.parent=this._meshesFromObj[t]._babylonMesh;break}if(this._materialToUse.push(this._meshesFromObj[e].materialName),this._handledMesh.hasLines&&(null!==(a=i._internalMetadata)&&void 0!==a||(i._internalMetadata={}),i._internalMetadata._isLine=!0),0===(null===(l=this._handledMesh.positions)||void 0===l?void 0:l.length)){this._babylonMeshesArray.push(i);continue}const n=new s.VertexData;if(n.indices=this._handledMesh.indices,n.positions=this._handledMesh.positions,this._loadingOptions.computeNormals||!(null===(h=this._handledMesh.normals)||void 0===h?void 0:h.length)){const t=new Array;s.VertexData.ComputeNormals(this._handledMesh.positions,this._handledMesh.indices,t),n.normals=t}else n.normals=this._handledMesh.normals;(null===(_=this._handledMesh.uvs)||void 0===_?void 0:_.length)&&(n.uvs=this._handledMesh.uvs),(null===(p=this._handledMesh.colors)||void 0===p?void 0:p.length)&&(n.colors=this._handledMesh.colors),n.applyToMesh(i),this._loadingOptions.invertY&&(i.scaling.y*=-1),this._loadingOptions.optimizeNormals&&this._optimizeNormals(i),this._babylonMeshesArray.push(i),this._handledMesh.directMaterial&&(i.material=this._handledMesh.directMaterial)}}}i.ObjectDescriptor=/^o/,i.GroupDescriptor=/^g/,i.MtlLibGroupDescriptor=/^mtllib /,i.UseMtlDescriptor=/^usemtl /,i.SmoothDescriptor=/^s /,i.VertexPattern=/^v(\s+[\d|.|+|\-|e|E]+){3,7}/,i.NormalPattern=/^vn(\s+[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)/,i.UVPattern=/^vt(\s+[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)/,i.FacePattern1=/^f\s+(([\d]{1,}[\s]?){3,})+/,i.FacePattern2=/^f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,i.FacePattern3=/^f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,i.FacePattern4=/^f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/,i.FacePattern5=/^f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/,i.LinePattern1=/^l\s+(([\d]{1,}[\s]?){2,})+/,i.LinePattern2=/^l\s+((([\d]{1,}\/[\d]{1,}[\s]?){2,})+)/,i.LinePattern3=/^l\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){2,})+)/;class o{static get INVERT_TEXTURE_Y(){return e.INVERT_TEXTURE_Y}static set INVERT_TEXTURE_Y(t){e.INVERT_TEXTURE_Y=t}constructor(t){this.name="obj",this.extensions=".obj",this._assetContainer=null,this._loadingOptions=Object.assign(Object.assign({},o._DefaultLoadingOptions),null!=t?t:{})}static get _DefaultLoadingOptions(){return{computeNormals:o.COMPUTE_NORMALS,optimizeNormals:o.OPTIMIZE_NORMALS,importVertexColors:o.IMPORT_VERTEX_COLORS,invertY:o.INVERT_Y,invertTextureY:o.INVERT_TEXTURE_Y,UVScaling:o.UV_SCALING,materialLoadingFailsSilently:o.MATERIAL_LOADING_FAILS_SILENTLY,optimizeWithUV:o.OPTIMIZE_WITH_UV,skipMaterials:o.SKIP_MATERIALS,useLegacyBehavior:o.USE_LEGACY_BEHAVIOR}}_loadMTL(t,e,i,o){const r=e+t;s.Tools.LoadFile(r,i,void 0,void 0,!1,(t,s)=>{o(r,s)})}createPlugin(t){return new o(t.obj)}canDirectLoad(){return!1}importMeshAsync(t,s,e,i){return this._parseSolidAsync(t,s,e,i).then(t=>({meshes:t,particleSystems:[],skeletons:[],animationGroups:[],transformNodes:[],geometries:[],lights:[],spriteManagers:[]}))}loadAsync(t,s,e){return this.importMeshAsync(null,t,s,e).then(()=>{})}loadAssetContainerAsync(t,e,i){const o=new s.AssetContainer(t);return this._assetContainer=o,this.importMeshAsync(null,t,e,i).then(t=>(t.meshes.forEach(t=>o.meshes.push(t)),t.meshes.forEach(t=>{const s=t.material;s&&-1==o.materials.indexOf(s)&&(o.materials.push(s),s.getActiveTextures().forEach(t=>{-1==o.textures.indexOf(t)&&o.textures.push(t)}))}),this._assetContainer=null,o)).catch(t=>{throw this._assetContainer=null,t})}_parseSolidAsync(t,o,r,n){let a="";const l=new e,h=[],_=[];r=r.replace(/#.*$/gm,"").trim(),new i(h,_,this._loadingOptions).parse(t,r,o,this._assetContainer,t=>{a=t});const p=[];return""===a||this._loadingOptions.skipMaterials||p.push(new Promise((t,e)=>{this._loadMTL(a,n,i=>{try{l.parseMTL(o,i,n,this._assetContainer);for(let t=0;t<l.materials.length;t++){let s=0;const e=[];let i;for(;(i=h.indexOf(l.materials[t].name,s))>-1;)e.push(i),s=i+1;if(-1===i&&0===e.length)l.materials[t].dispose();else for(let s=0;s<e.length;s++){const i=_[e[s]],o=l.materials[t];i.material=o,i.getTotalIndices()||(o.pointsCloud=!0)}}t()}catch(i){s.Tools.Warn(`Error processing MTL file: '${a}'`),this._loadingOptions.materialLoadingFailsSilently?t():e(i)}},(i,o)=>{s.Tools.Warn(`Error downloading MTL file: '${a}'`),this._loadingOptions.materialLoadingFailsSilently?t():e(o)})})),Promise.all(p).then(()=>{const t=t=>{var s,e;return Boolean(null!==(e=null===(s=t._internalMetadata)||void 0===s?void 0:s._isLine)&&void 0!==e&&e)};return _.forEach(e=>{var i,r;if(t(e)){let n=null!==(i=e.material)&&void 0!==i?i:new s.StandardMaterial(e.name+"_line",o);n.getBindedMeshes().filter(s=>!t(s)).length>0&&(n=null!==(r=n.clone(n.name+"_line"))&&void 0!==r?r:n),n.wireframe=!0,e.material=n,e._internalMetadata&&(e._internalMetadata._isLine=void 0)}}),_})}}o.OPTIMIZE_WITH_UV=!0,o.INVERT_Y=!1,o.IMPORT_VERTEX_COLORS=!1,o.COMPUTE_NORMALS=!1,o.OPTIMIZE_NORMALS=!1,o.UV_SCALING=new s.Vector2(1,1),o.SKIP_MATERIALS=!1,o.MATERIAL_LOADING_FAILS_SILENTLY=!0,o.USE_LEGACY_BEHAVIOR=!1;let r=!1;function n(){r||(r=!0,s.RegisterSceneLoaderPlugin(new o))}n();var a={__proto__:null,MTLFileLoader:e,OBJFileLoader:o,RegisterOBJFileLoader:n,SolidParser:i};const l="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==l)for(const t in a)l.BABYLON[t]||(l.BABYLON[t]=a[t]);t.MTLFileLoader=e,t.OBJFileLoader=o,t.RegisterOBJFileLoader=n,t.SolidParser=i});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";class s{constructor(){this.materials=[]}parseMTL(e,i,o,r){if(i instanceof ArrayBuffer)return;const n=i.split("\n"),a=/\s+/;let l,h=null;for(let i=0;i<n.length;i++){const _=n[i].trim();if(0===_.length||"#"===_.charAt(0))continue;const p=_.indexOf(" ");let d=p>=0?_.substring(0,p):_;d=d.toLowerCase();const m=p>=0?_.substring(p+1).trim():"";if("newmtl"===d)h&&this.materials.push(h),e._blockEntityCollection=!!r,h=new t.StandardMaterial(m,e),h._parentContainer=r,e._blockEntityCollection=!1;else if("kd"===d&&h)l=m.split(a,3).map(parseFloat),h.diffuseColor=t.Color3.FromArray(l);else if("ka"===d&&h)l=m.split(a,3).map(parseFloat),h.ambientColor=t.Color3.FromArray(l);else if("ks"===d&&h)l=m.split(a,3).map(parseFloat),h.specularColor=t.Color3.FromArray(l);else if("ke"===d&&h)l=m.split(a,3).map(parseFloat),h.emissiveColor=t.Color3.FromArray(l);else if("ns"===d&&h)h.specularPower=parseFloat(m);else if("d"===d&&h)h.alpha=parseFloat(m);else if("map_ka"===d&&h)h.ambientTexture=s._GetTexture(o,m,e);else if("map_kd"===d&&h)h.diffuseTexture=s._GetTexture(o,m,e);else if("map_ks"===d&&h)h.specularTexture=s._GetTexture(o,m,e);else if("map_ns"===d);else if("map_bump"===d&&h){const t=m.split(a),i=t.indexOf("-bm");let r=null;i>=0&&(r=t[i+1],t.splice(i,2)),h.bumpTexture=s._GetTexture(o,t.join(" "),e),h.bumpTexture&&null!==r&&(h.bumpTexture.level=parseFloat(r))}else"map_d"===d&&h&&(h.opacityTexture=s._GetTexture(o,m,e))}h&&this.materials.push(h)}static _GetTexture(e,i,o){if(!i)return null;let r=e;if("file:"===e){let e=i.lastIndexOf("\\");-1===e&&(e=i.lastIndexOf("/")),r+=e>-1?i.substring(e+1):i}else r+=i;return new t.Texture(r,o,!1,s.INVERT_TEXTURE_Y)}}s.INVERT_TEXTURE_Y=!0;class i{constructor(e,s,i){this._positions=[],this._normals=[],this._uvs=[],this._colors=[],this._extColors=[],this._meshesFromObj=[],this._indicesForBabylon=[],this._wrappedPositionForBabylon=[],this._wrappedUvsForBabylon=[],this._wrappedColorsForBabylon=[],this._wrappedNormalsForBabylon=[],this._tuplePosNorm=[],this._curPositionInIndices=0,this._hasMeshes=!1,this._unwrappedPositionsForBabylon=[],this._unwrappedColorsForBabylon=[],this._unwrappedNormalsForBabylon=[],this._unwrappedUVForBabylon=[],this._triangles=[],this._materialNameFromObj="",this._objMeshName="",this._increment=1,this._isFirstMaterial=!0,this._grayColor=new t.Color4(.5,.5,.5,1),this._hasLineData=!1,this._materialToUse=e,this._babylonMeshesArray=s,this._loadingOptions=i}_isInArray(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[]});const s=e[t[0]].normals.indexOf(t[1]);return-1===s?-1:e[t[0]].idx[s]}_isInArrayUV(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[],uv:[]});const s=e[t[0]].normals.indexOf(t[1]);return 1!=s&&t[2]===e[t[0]].uv[s]?e[t[0]].idx[s]:-1}_setData(e){var t,s;let i;null!==(t=e.indiceUvsFromObj)&&void 0!==t||(e.indiceUvsFromObj=-1),null!==(s=e.indiceNormalFromObj)&&void 0!==s||(e.indiceNormalFromObj=-1),i=this._loadingOptions.optimizeWithUV?this._isInArrayUV(this._tuplePosNorm,[e.indicePositionFromObj,e.indiceNormalFromObj,e.indiceUvsFromObj]):this._isInArray(this._tuplePosNorm,[e.indicePositionFromObj,e.indiceNormalFromObj]),-1===i?(this._indicesForBabylon.push(this._wrappedPositionForBabylon.length),this._wrappedPositionForBabylon.push(e.positionVectorFromOBJ),void 0!==e.textureVectorFromOBJ&&this._wrappedUvsForBabylon.push(e.textureVectorFromOBJ),void 0!==e.normalsVectorFromOBJ&&this._wrappedNormalsForBabylon.push(e.normalsVectorFromOBJ),void 0!==e.positionColorsFromOBJ&&this._wrappedColorsForBabylon.push(e.positionColorsFromOBJ),this._tuplePosNorm[e.indicePositionFromObj].normals.push(e.indiceNormalFromObj),this._tuplePosNorm[e.indicePositionFromObj].idx.push(this._curPositionInIndices++),this._loadingOptions.optimizeWithUV&&this._tuplePosNorm[e.indicePositionFromObj].uv.push(e.indiceUvsFromObj)):this._indicesForBabylon.push(i)}_unwrapData(){try{for(let e=0;e<this._wrappedPositionForBabylon.length;e++)this._unwrappedPositionsForBabylon.push(this._wrappedPositionForBabylon[e].x*this._handednessSign,this._wrappedPositionForBabylon[e].y,this._wrappedPositionForBabylon[e].z),this._wrappedNormalsForBabylon.length&&this._unwrappedNormalsForBabylon.push(this._wrappedNormalsForBabylon[e].x*this._handednessSign,this._wrappedNormalsForBabylon[e].y,this._wrappedNormalsForBabylon[e].z),this._wrappedUvsForBabylon.length&&this._unwrappedUVForBabylon.push(this._wrappedUvsForBabylon[e].x,this._wrappedUvsForBabylon[e].y),this._wrappedColorsForBabylon.length&&this._unwrappedColorsForBabylon.push(this._wrappedColorsForBabylon[e].r,this._wrappedColorsForBabylon[e].g,this._wrappedColorsForBabylon[e].b,this._wrappedColorsForBabylon[e].a);this._wrappedPositionForBabylon.length=0,this._wrappedNormalsForBabylon.length=0,this._wrappedUvsForBabylon.length=0,this._wrappedColorsForBabylon.length=0,this._tuplePosNorm.length=0,this._curPositionInIndices=0}catch(e){throw new Error("Unable to unwrap data while parsing OBJ data.",{cause:e})}}_getTriangles(e,t){for(let s=t;s<e.length-1;s++)this._pushTriangle(e,s)}_getColor(e){var t;return this._loadingOptions.importVertexColors?null!==(t=this._extColors[e])&&void 0!==t?t:this._colors[e]:void 0}_setDataForCurrentFaceWithPattern1(e,t){this._getTriangles(e,t);for(let e=0;e<this._triangles.length;e++){const t=parseInt(this._triangles[e])-1;this._setData({indicePositionFromObj:t,positionVectorFromOBJ:this._positions[t],positionColorsFromOBJ:this._getColor(t)})}this._triangles.length=0}_setDataForCurrentFaceWithPattern2(e,t){this._getTriangles(e,t);for(let e=0;e<this._triangles.length;e++){const t=this._triangles[e].split("/"),s=parseInt(t[0])-1,i=parseInt(t[1])-1;this._setData({indicePositionFromObj:s,indiceUvsFromObj:i,positionVectorFromOBJ:this._positions[s],textureVectorFromOBJ:this._uvs[i],positionColorsFromOBJ:this._getColor(s)})}this._triangles.length=0}_setDataForCurrentFaceWithPattern3(e,t){this._getTriangles(e,t);for(let e=0;e<this._triangles.length;e++){const t=this._triangles[e].split("/"),s=parseInt(t[0])-1,i=parseInt(t[1])-1,o=parseInt(t[2])-1;this._setData({indicePositionFromObj:s,indiceUvsFromObj:i,indiceNormalFromObj:o,positionVectorFromOBJ:this._positions[s],textureVectorFromOBJ:this._uvs[i],normalsVectorFromOBJ:this._normals[o]})}this._triangles.length=0}_setDataForCurrentFaceWithPattern4(e,t){this._getTriangles(e,t);for(let e=0;e<this._triangles.length;e++){const t=this._triangles[e].split("//"),s=parseInt(t[0])-1,i=parseInt(t[1])-1;this._setData({indicePositionFromObj:s,indiceNormalFromObj:i,positionVectorFromOBJ:this._positions[s],normalsVectorFromOBJ:this._normals[i],positionColorsFromOBJ:this._getColor(s)})}this._triangles.length=0}_setDataForCurrentFaceWithPattern5(e,t){this._getTriangles(e,t);for(let e=0;e<this._triangles.length;e++){const t=this._triangles[e].split("/"),s=this._positions.length+parseInt(t[0]),i=this._uvs.length+parseInt(t[1]),o=this._normals.length+parseInt(t[2]);this._setData({indicePositionFromObj:s,indiceUvsFromObj:i,indiceNormalFromObj:o,positionVectorFromOBJ:this._positions[s],textureVectorFromOBJ:this._uvs[i],normalsVectorFromOBJ:this._normals[o],positionColorsFromOBJ:this._getColor(s)})}this._triangles.length=0}_addPreviousObjMesh(){this._meshesFromObj.length>0&&(this._handledMesh=this._meshesFromObj[this._meshesFromObj.length-1],this._unwrapData(),this._loadingOptions.useLegacyBehavior&&this._indicesForBabylon.reverse(),this._handledMesh.indices=this._indicesForBabylon.slice(),this._handledMesh.positions=this._unwrappedPositionsForBabylon.slice(),this._unwrappedNormalsForBabylon.length&&(this._handledMesh.normals=this._unwrappedNormalsForBabylon.slice()),this._unwrappedUVForBabylon.length&&(this._handledMesh.uvs=this._unwrappedUVForBabylon.slice()),this._unwrappedColorsForBabylon.length&&(this._handledMesh.colors=this._unwrappedColorsForBabylon.slice()),this._handledMesh.hasLines=this._hasLineData,this._indicesForBabylon.length=0,this._unwrappedPositionsForBabylon.length=0,this._unwrappedColorsForBabylon.length=0,this._unwrappedNormalsForBabylon.length=0,this._unwrappedUVForBabylon.length=0,this._hasLineData=!1)}_optimizeNormals(e){const s=e.getVerticesData(t.VertexBuffer.PositionKind),i=e.getVerticesData(t.VertexBuffer.NormalKind),o={};if(!s||!i)return;for(let e=0;e<s.length/3;e++){const t=s[3*e+0]+"_"+s[3*e+1]+"_"+s[3*e+2];let i=o[t];i||(i=[],o[t]=i),i.push(e)}const r=new t.Vector3;for(const e in o){const t=o[e];if(t.length<2)continue;const s=t[0];for(let e=1;e<t.length;++e){const o=t[e];i[3*s+0]+=i[3*o+0],i[3*s+1]+=i[3*o+1],i[3*s+2]+=i[3*o+2]}r.copyFromFloats(i[3*s+0],i[3*s+1],i[3*s+2]),r.normalize();for(let e=0;e<t.length;++e){const s=t[e];i[3*s+0]=r.x,i[3*s+1]=r.y,i[3*s+2]=r.z}}e.setVerticesData(t.VertexBuffer.NormalKind,i)}static _IsLineElement(e){return e.startsWith("l")}static _IsObjectElement(e){return e.startsWith("o")}static _IsGroupElement(e){return e.startsWith("g")}static _GetZbrushMRGB(e,s){if(!e.startsWith("mrgb"))return null;if(e=e.replace("mrgb","").trim(),s)return[];const i=e.match(/[a-z0-9]/g);if(!i||i.length%8!=0)return[];const o=[];for(let e=0;e<i.length/8;e++){const s=i[8*e+2]+i[8*e+3],r=i[8*e+4]+i[8*e+5],n=i[8*e+6]+i[8*e+7];o.push(new t.Color4(parseInt(s,16)/255,parseInt(r,16)/255,parseInt(n,16)/255,1))}return o}parse(e,s,o,r,n){var a,l,h,_,p;s=(s=s.replace(/#MRGB/g,"mrgb")).replace(/#.*$/gm,"").trim(),this._loadingOptions.useLegacyBehavior?(this._pushTriangle=(e,t)=>this._triangles.push(e[0],e[t],e[t+1]),this._handednessSign=1):o.useRightHandedSystem?(this._pushTriangle=(e,t)=>this._triangles.push(e[0],e[t+1],e[t]),this._handednessSign=1):(this._pushTriangle=(e,t)=>this._triangles.push(e[0],e[t],e[t+1]),this._handednessSign=-1);const d=s.split("\n"),m=[];let c=[];m.push(c);for(let e=0;e<d.length;e++){const t=d[e].trim().replace(/\s\s/g," ");if(0!==t.length&&"#"!==t.charAt(0))if((i._IsGroupElement(t)||i._IsObjectElement(t))&&(c=[],m.push(c)),i._IsLineElement(t)){const e=t.split(" ");for(let t=1;t<e.length-1;t++)c.push(`l ${e[t]} ${e[t+1]}`)}else c.push(t)}const u=m.flat();for(let e=0;e<u.length;e++){const s=u[e].trim().replace(/\s\s/g," ");let o;if(0!==s.length&&"#"!==s.charAt(0))if(i.VertexPattern.test(s)){if(o=s.match(/[^ ]+/g),this._positions.push(new t.Vector3(parseFloat(o[1]),parseFloat(o[2]),parseFloat(o[3]))),this._loadingOptions.importVertexColors)if(o.length>=7){const e=parseFloat(o[4]),s=parseFloat(o[5]),i=parseFloat(o[6]);this._colors.push(new t.Color4(e>1?e/255:e,s>1?s/255:s,i>1?i/255:i,7===o.length||void 0===o[7]?1:parseFloat(o[7])))}else this._colors.push(this._grayColor)}else if(null!==(o=i.NormalPattern.exec(s)))this._normals.push(new t.Vector3(parseFloat(o[1]),parseFloat(o[2]),parseFloat(o[3])));else if(null!==(o=i.UVPattern.exec(s)))this._uvs.push(new t.Vector2(parseFloat(o[1])*this._loadingOptions.UVScaling.x,parseFloat(o[2])*this._loadingOptions.UVScaling.y));else if(null!==(o=i.FacePattern3.exec(s)))this._setDataForCurrentFaceWithPattern3(o[1].trim().split(" "),1);else if(null!==(o=i.FacePattern4.exec(s)))this._setDataForCurrentFaceWithPattern4(o[1].trim().split(" "),1);else if(null!==(o=i.FacePattern5.exec(s)))this._setDataForCurrentFaceWithPattern5(o[1].trim().split(" "),1);else if(null!==(o=i.FacePattern2.exec(s)))this._setDataForCurrentFaceWithPattern2(o[1].trim().split(" "),1);else if(null!==(o=i.FacePattern1.exec(s)))this._setDataForCurrentFaceWithPattern1(o[1].trim().split(" "),1);else if(null!==(o=i.LinePattern1.exec(s)))this._setDataForCurrentFaceWithPattern1(o[1].trim().split(" "),0),this._hasLineData=!0;else if(null!==(o=i.LinePattern2.exec(s)))this._setDataForCurrentFaceWithPattern2(o[1].trim().split(" "),0),this._hasLineData=!0;else if(o=i._GetZbrushMRGB(s,!this._loadingOptions.importVertexColors))for(const e of o)this._extColors.push(e);else if(null!==(o=i.LinePattern3.exec(s)))this._setDataForCurrentFaceWithPattern3(o[1].trim().split(" "),0),this._hasLineData=!0;else if(i.GroupDescriptor.test(s)||i.ObjectDescriptor.test(s)){const e={name:s.substring(2).trim(),indices:null,positions:null,normals:null,uvs:null,colors:null,materialName:this._materialNameFromObj,isObject:i.ObjectDescriptor.test(s)};this._addPreviousObjMesh(),this._meshesFromObj.push(e),this._hasMeshes=!0,this._isFirstMaterial=!0,this._increment=1}else if(i.UseMtlDescriptor.test(s)){if(this._materialNameFromObj=s.substring(7).trim(),!this._isFirstMaterial||!this._hasMeshes){this._addPreviousObjMesh();const e={name:(this._objMeshName||"mesh")+"_mm"+this._increment.toString(),indices:null,positions:null,normals:null,uvs:null,colors:null,materialName:this._materialNameFromObj,isObject:!1};this._increment++,this._meshesFromObj.push(e),this._hasMeshes=!0}this._hasMeshes&&this._isFirstMaterial&&(this._meshesFromObj[this._meshesFromObj.length-1].materialName=this._materialNameFromObj,this._isFirstMaterial=!1)}else i.MtlLibGroupDescriptor.test(s)?n(s.substring(7).trim()):i.SmoothDescriptor.test(s)||t.Logger.Log("Unhandled expression at line : "+s)}if(this._hasMeshes&&(this._handledMesh=this._meshesFromObj[this._meshesFromObj.length-1],this._loadingOptions.useLegacyBehavior&&this._indicesForBabylon.reverse(),this._unwrapData(),this._handledMesh.indices=this._indicesForBabylon,this._handledMesh.positions=this._unwrappedPositionsForBabylon,this._unwrappedNormalsForBabylon.length&&(this._handledMesh.normals=this._unwrappedNormalsForBabylon),this._unwrappedUVForBabylon.length&&(this._handledMesh.uvs=this._unwrappedUVForBabylon),this._unwrappedColorsForBabylon.length&&(this._handledMesh.colors=this._unwrappedColorsForBabylon),this._handledMesh.hasLines=this._hasLineData),!this._hasMeshes){let e=null;if(this._indicesForBabylon.length)this._loadingOptions.useLegacyBehavior&&this._indicesForBabylon.reverse(),this._unwrapData();else{for(const e of this._positions)this._unwrappedPositionsForBabylon.push(e.x,e.y,e.z);if(this._normals.length)for(const e of this._normals)this._unwrappedNormalsForBabylon.push(e.x,e.y,e.z);if(this._uvs.length)for(const e of this._uvs)this._unwrappedUVForBabylon.push(e.x,e.y);if(this._extColors.length)for(const e of this._extColors)this._unwrappedColorsForBabylon.push(e.r,e.g,e.b,e.a);else if(this._colors.length)for(const e of this._colors)this._unwrappedColorsForBabylon.push(e.r,e.g,e.b,e.a);this._materialNameFromObj||(e=new t.StandardMaterial(t.Geometry.RandomId(),o),e.pointsCloud=!0,this._materialNameFromObj=e.name,this._normals.length||(e.disableLighting=!0,e.emissiveColor=t.Color3.White()))}this._meshesFromObj.push({name:t.Geometry.RandomId(),indices:this._indicesForBabylon,positions:this._unwrappedPositionsForBabylon,colors:this._unwrappedColorsForBabylon,normals:this._unwrappedNormalsForBabylon,uvs:this._unwrappedUVForBabylon,materialName:this._materialNameFromObj,directMaterial:e,isObject:!0,hasLines:this._hasLineData})}for(let s=0;s<this._meshesFromObj.length;s++){if(e&&this._meshesFromObj[s].name)if(e instanceof Array){if(-1===e.indexOf(this._meshesFromObj[s].name))continue}else if(this._meshesFromObj[s].name!==e)continue;this._handledMesh=this._meshesFromObj[s],o._blockEntityCollection=!!r;const i=new t.Mesh(this._meshesFromObj[s].name,o);if(i._parentContainer=r,o._blockEntityCollection=!1,this._handledMesh._babylonMesh=i,!this._handledMesh.isObject)for(let e=s-1;e>=0;--e)if(this._meshesFromObj[e].isObject&&this._meshesFromObj[e]._babylonMesh){i.parent=this._meshesFromObj[e]._babylonMesh;break}if(this._materialToUse.push(this._meshesFromObj[s].materialName),this._handledMesh.hasLines&&(null!==(a=i._internalMetadata)&&void 0!==a||(i._internalMetadata={}),i._internalMetadata._isLine=!0),0===(null===(l=this._handledMesh.positions)||void 0===l?void 0:l.length)){this._babylonMeshesArray.push(i);continue}const n=new t.VertexData;if(n.indices=this._handledMesh.indices,n.positions=this._handledMesh.positions,this._loadingOptions.computeNormals||!(null===(h=this._handledMesh.normals)||void 0===h?void 0:h.length)){const e=new Array;t.VertexData.ComputeNormals(this._handledMesh.positions,this._handledMesh.indices,e),n.normals=e}else n.normals=this._handledMesh.normals;(null===(_=this._handledMesh.uvs)||void 0===_?void 0:_.length)&&(n.uvs=this._handledMesh.uvs),(null===(p=this._handledMesh.colors)||void 0===p?void 0:p.length)&&(n.colors=this._handledMesh.colors),n.applyToMesh(i),this._loadingOptions.invertY&&(i.scaling.y*=-1),this._loadingOptions.optimizeNormals&&this._optimizeNormals(i),this._babylonMeshesArray.push(i),this._handledMesh.directMaterial&&(i.material=this._handledMesh.directMaterial)}}}i.ObjectDescriptor=/^o/,i.GroupDescriptor=/^g/,i.MtlLibGroupDescriptor=/^mtllib /,i.UseMtlDescriptor=/^usemtl /,i.SmoothDescriptor=/^s /,i.VertexPattern=/^v(\s+[\d|.|+|\-|e|E]+){3,7}/,i.NormalPattern=/^vn(\s+[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)/,i.UVPattern=/^vt(\s+[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)/,i.FacePattern1=/^f\s+(([\d]{1,}[\s]?){3,})+/,i.FacePattern2=/^f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,i.FacePattern3=/^f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,i.FacePattern4=/^f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/,i.FacePattern5=/^f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/,i.LinePattern1=/^l\s+(([\d]{1,}[\s]?){2,})+/,i.LinePattern2=/^l\s+((([\d]{1,}\/[\d]{1,}[\s]?){2,})+)/,i.LinePattern3=/^l\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){2,})+)/;const o={".obj":{isBinary:!0}};class r{static get INVERT_TEXTURE_Y(){return s.INVERT_TEXTURE_Y}static set INVERT_TEXTURE_Y(e){s.INVERT_TEXTURE_Y=e}constructor(e){this.name="obj",this.extensions=o,this._assetContainer=null,this._loadingOptions=Object.assign(Object.assign({},r._DefaultLoadingOptions),null!=e?e:{})}static get _DefaultLoadingOptions(){return{encoding:r.ENCODING,computeNormals:r.COMPUTE_NORMALS,optimizeNormals:r.OPTIMIZE_NORMALS,importVertexColors:r.IMPORT_VERTEX_COLORS,invertY:r.INVERT_Y,invertTextureY:r.INVERT_TEXTURE_Y,UVScaling:r.UV_SCALING,materialLoadingFailsSilently:r.MATERIAL_LOADING_FAILS_SILENTLY,optimizeWithUV:r.OPTIMIZE_WITH_UV,skipMaterials:r.SKIP_MATERIALS,useLegacyBehavior:r.USE_LEGACY_BEHAVIOR}}_loadMTL(e,s,i,o){const r=s+e;t.Tools.LoadFile(r,i,void 0,void 0,!0,(e,t)=>{o(r,t)})}_decode(e){var t;if("string"==typeof e)return e;const s=new Uint8Array(e),i=null!==(t=this._loadingOptions.encoding)&&void 0!==t?t:"auto";if("auto"!==i)return new TextDecoder(i).decode(s);if(255===s[0]&&254===s[1])return new TextDecoder("utf-16le").decode(s);if(254===s[0]&&255===s[1])return new TextDecoder("utf-16be").decode(s);try{return new TextDecoder("utf-8",{fatal:!0}).decode(s)}catch(e){return new TextDecoder("gb18030").decode(s)}}createPlugin(e){return new r(e.obj)}canDirectLoad(){return!1}importMeshAsync(e,t,s,i){return this._parseSolidAsync(e,t,s,i).then(e=>({meshes:e,particleSystems:[],skeletons:[],animationGroups:[],transformNodes:[],geometries:[],lights:[],spriteManagers:[]}))}loadAsync(e,t,s){return this.importMeshAsync(null,e,t,s).then(()=>{})}loadAssetContainerAsync(e,s,i){const o=new t.AssetContainer(e);return this._assetContainer=o,this.importMeshAsync(null,e,s,i).then(e=>(e.meshes.forEach(e=>o.meshes.push(e)),e.meshes.forEach(e=>{const t=e.material;t&&-1==o.materials.indexOf(t)&&(o.materials.push(t),t.getActiveTextures().forEach(e=>{-1==o.textures.indexOf(e)&&o.textures.push(e)}))}),this._assetContainer=null,o)).catch(e=>{throw this._assetContainer=null,e})}_parseSolidAsync(e,o,r,n){let a="";const l=new s,h=[],_=[];r=(r=this._decode(r)).replace(/#.*$/gm,"").trim(),new i(h,_,this._loadingOptions).parse(e,r,o,this._assetContainer,e=>{a=e});const p=[];return""===a||this._loadingOptions.skipMaterials||p.push(new Promise((e,s)=>{this._loadMTL(a,n,i=>{try{l.parseMTL(o,this._decode(i),n,this._assetContainer);for(let e=0;e<l.materials.length;e++){let t=0;const s=[];let i;for(;(i=h.indexOf(l.materials[e].name,t))>-1;)s.push(i),t=i+1;if(-1===i&&0===s.length)l.materials[e].dispose();else for(let t=0;t<s.length;t++){const i=_[s[t]],o=l.materials[e];i.material=o,i.getTotalIndices()||(o.pointsCloud=!0)}}e()}catch(i){t.Tools.Warn(`Error processing MTL file: '${a}'`),this._loadingOptions.materialLoadingFailsSilently?e():s(i)}},(i,o)=>{t.Tools.Warn(`Error downloading MTL file: '${a}'`),this._loadingOptions.materialLoadingFailsSilently?e():s(o)})})),Promise.all(p).then(()=>{const e=e=>{var t,s;return Boolean(null!==(s=null===(t=e._internalMetadata)||void 0===t?void 0:t._isLine)&&void 0!==s&&s)};return _.forEach(s=>{var i,r;if(e(s)){let n=null!==(i=s.material)&&void 0!==i?i:new t.StandardMaterial(s.name+"_line",o);n.getBindedMeshes().filter(t=>!e(t)).length>0&&(n=null!==(r=n.clone(n.name+"_line"))&&void 0!==r?r:n),n.wireframe=!0,s.material=n,s._internalMetadata&&(s._internalMetadata._isLine=void 0)}}),_})}}r.ENCODING="auto",r.OPTIMIZE_WITH_UV=!0,r.INVERT_Y=!1,r.IMPORT_VERTEX_COLORS=!1,r.COMPUTE_NORMALS=!1,r.OPTIMIZE_NORMALS=!1,r.UV_SCALING=new t.Vector2(1,1),r.SKIP_MATERIALS=!1,r.MATERIAL_LOADING_FAILS_SILENTLY=!0,r.USE_LEGACY_BEHAVIOR=!1;let n=!1;function a(){n||(n=!0,t.RegisterSceneLoaderPlugin(new r))}a();var l={__proto__:null,MTLFileLoader:s,OBJFileLoader:r,RegisterOBJFileLoader:a,SolidParser:i};const h="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==h)for(const e in l)h.BABYLON[e]||(h.BABYLON[e]=l[e]);e.MTLFileLoader=s,e.OBJFileLoader=r,e.RegisterOBJFileLoader=a,e.SolidParser=i});
2
2
  //# sourceMappingURL=babylon.objFileLoader.min.js.map