@babylonjs/loaders 6.7.0 → 6.8.1
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/solidParser.js +11 -11
- package/OBJ/solidParser.js.map +1 -1
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.d.ts +3 -2
- package/glTF/1.0/glTFLoaderUtils.js +1 -0
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +5 -1
- package/glTF/glTFFileLoader.js +31 -5
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.d.ts +1 -1
- package/glTF/glTFValidation.js +3 -2
- package/glTF/glTFValidation.js.map +1 -1
- package/package.json +3 -5
package/STL/stlFileLoader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stlFileLoader.js","sourceRoot":"","sources":["../../../../lts/loaders/generated/STL/stlFileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAEnD,OAAO,EAAE,IAAI,EAAE,uCAAyB;AAExC,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,cAAc,EAAE,0CAA4B;AAGrD;;;GAGG;AACH,MAAM,OAAO,aAAa;IAA1B;QACI,gBAAgB;QACT,iBAAY,GAAG,yCAAyC,CAAC;QAEhE,gBAAgB;QACT,kBAAa,GAAG,0BAA0B,CAAC;QAClD,gBAAgB;QACT,kBAAa,GAAG,mJAAmJ,CAAC;QAC3K,gBAAgB;QACT,kBAAa,GAAG,mJAAmJ,CAAC;QAE3K;;WAEG;QACI,SAAI,GAAG,KAAK,CAAC;QAEpB;;;;WAIG;QACI,eAAU,GAAiC;YAC9C,MAAM,E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;oBACH,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAEvF,2DAA2D;oBAC3D,4BAA4B;oBAC5B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;iBACjD;aACJ;YACD,IAAI,aAAa,CAAC,6BAA6B,EAAE;gBAC7C,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;gBAC/D,YAAY,IAAI,CAAC,CAAC;aACrB;iBAAM;gBACH,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;aAChE;YACD,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,CAAC,CAAC;SACpC;QAED,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;;AA/OD;;;;GAIG;AACW,2CAA6B,GAAG,KAAK,CAAC;AA6OxD,IAAI,WAAW,EAAE;IACb,WAAW,CAAC,cAAc,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;CACnD","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n/**\r\n * STL file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class STLFileLoader implements ISceneLoaderPlugin {\r\n /** @internal */\r\n public solidPattern = /solid (\\S*)([\\S\\s]*?)endsolid[ ]*(\\S*)/g;\r\n\r\n /** @internal */\r\n public facetsPattern = /facet([\\s\\S]*?)endfacet/g;\r\n /** @internal */\r\n public normalPattern = /normal[\\s]+([-+]?[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;\r\n /** @internal */\r\n public vertexPattern = /vertex[\\s]+([-+]?[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public name = \"stl\";\r\n\r\n /**\r\n * Defines the extensions the stl loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n * we'll convert to string if it looks like it's an ASCII .stl\r\n */\r\n public extensions: ISceneLoaderPluginExtensions = {\r\n \".stl\": { isBinary: true },\r\n };\r\n\r\n /**\r\n * Defines if Y and Z axes are swapped or not when loading an STL file.\r\n * The default is false to maintain backward compatibility. When set to\r\n * true, coordinates from the STL file are used without change.\r\n */\r\n public static DO_NOT_ALTER_FILE_COORDINATES = false;\r\n\r\n /**\r\n * Import meshes into a scene.\r\n * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param scene The scene to import into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param meshes The meshes array to import into\r\n * @returns True if successful or false otherwise\r\n */\r\n public importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>): boolean {\r\n let matches;\r\n\r\n if (typeof data !== \"string\") {\r\n if (this._isBinary(data)) {\r\n // binary .stl\r\n const babylonMesh = new Mesh(\"stlmesh\", scene);\r\n this._parseBinary(babylonMesh, data);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n return true;\r\n }\r\n\r\n // ASCII .stl\r\n\r\n // convert to string\r\n const array_buffer = new Uint8Array(data);\r\n let str = \"\";\r\n for (let i = 0; i < data.byteLength; i++) {\r\n str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian\r\n }\r\n data = str;\r\n }\r\n\r\n //if arrived here, data is a string, containing the STLA data.\r\n\r\n while ((matches = this.solidPattern.exec(data))) {\r\n let meshName = matches[1];\r\n const meshNameFromEnd = matches[3];\r\n if (meshNameFromEnd && meshName != meshNameFromEnd) {\r\n Tools.Error(\"Error in STL, solid name != endsolid name\");\r\n return false;\r\n }\r\n\r\n // check meshesNames\r\n if (meshesNames && meshName) {\r\n if (meshesNames instanceof Array) {\r\n if (!meshesNames.indexOf(meshName)) {\r\n continue;\r\n }\r\n } else {\r\n if (meshName !== meshesNames) {\r\n continue;\r\n }\r\n }\r\n }\r\n\r\n // stl mesh name can be empty as well\r\n meshName = meshName || \"stlmesh\";\r\n\r\n const babylonMesh = new Mesh(meshName, scene);\r\n this._parseASCII(babylonMesh, matches[2]);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Load into a scene.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns true if successful or false otherwise\r\n */\r\n public load(scene: Scene, data: any, rootUrl: string): boolean {\r\n const result = this.importMesh(null, scene, data, rootUrl, null);\r\n return result;\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n public loadAssetContainer(scene: Scene, data: string, rootUrl: string): AssetContainer {\r\n const container = new AssetContainer(scene);\r\n scene._blockEntityCollection = true;\r\n this.importMesh(null, scene, data, rootUrl, container.meshes);\r\n scene._blockEntityCollection = false;\r\n return container;\r\n }\r\n\r\n private _isBinary(data: any) {\r\n // check if file size is correct for binary stl\r\n const reader = new DataView(data);\r\n\r\n // A Binary STL header is 80 bytes, if the data size is not great than\r\n // that then it's not a binary STL.\r\n if (reader.byteLength <= 80) {\r\n return false;\r\n }\r\n\r\n const faceSize = (32 / 8) * 3 + (32 / 8) * 3 * 3 + 16 / 8;\r\n const nFaces = reader.getUint32(80, true);\r\n\r\n if (80 + 32 / 8 + nFaces * faceSize === reader.byteLength) {\r\n return true;\r\n }\r\n\r\n // US-ASCII begin with 's', 'o', 'l', 'i', 'd'\r\n const ascii = [115, 111, 108, 105, 100];\r\n for (let off = 0; off < 5; off++) {\r\n if (reader.getUint8(off) !== ascii[off]) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _parseBinary(mesh: Mesh, data: ArrayBuffer) {\r\n const reader = new DataView(data);\r\n const faces = reader.getUint32(80, true);\r\n\r\n const dataOffset = 84;\r\n const faceLength = 12 * 4 + 2;\r\n\r\n let offset = 0;\r\n\r\n const positions = new Float32Array(faces * 3 * 3);\r\n const normals = new Float32Array(faces * 3 * 3);\r\n const indices = new Uint32Array(faces * 3);\r\n let indicesCount = 0;\r\n\r\n for (let face = 0; face < faces; face++) {\r\n const start = dataOffset + face * faceLength;\r\n const normalX = reader.getFloat32(start, true);\r\n const normalY = reader.getFloat32(start + 4, true);\r\n const normalZ = reader.getFloat32(start + 8, true);\r\n\r\n for (let i = 1; i <= 3; i++) {\r\n const vertexstart = start + i * 12;\r\n\r\n // ordering is intentional to match ascii import\r\n positions[offset] = reader.getFloat32(vertexstart, true);\r\n normals[offset] = normalX;\r\n\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 2] = normalY;\r\n normals[offset + 1] = normalZ;\r\n } else {\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 1] = normalY;\r\n normals[offset + 2] = normalZ;\r\n }\r\n\r\n offset += 3;\r\n }\r\n\r\n if (STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n indices[indicesCount] = indicesCount;\r\n indices[indicesCount + 1] = indicesCount + 2;\r\n indices[indicesCount + 2] = indicesCount + 1;\r\n indicesCount += 3;\r\n } else {\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n }\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n\r\n private _parseASCII(mesh: Mesh, solidData: string) {\r\n const positions = [];\r\n const normals = [];\r\n const indices = [];\r\n let indicesCount = 0;\r\n\r\n //load facets, ignoring loop as the standard doesn't define it can contain more than vertices\r\n let matches;\r\n while ((matches = this.facetsPattern.exec(solidData))) {\r\n const facet = matches[1];\r\n //one normal per face\r\n const normalMatches = this.normalPattern.exec(facet);\r\n this.normalPattern.lastIndex = 0;\r\n if (!normalMatches) {\r\n continue;\r\n }\r\n const normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];\r\n\r\n let vertexMatch;\r\n while ((vertexMatch = this.vertexPattern.exec(facet))) {\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));\r\n normals.push(normal[0], normal[1], normal[2]);\r\n } else {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[3]), Number(vertexMatch[5]));\r\n\r\n // Flipping the second and third component because inverted\r\n // when normal was declared.\r\n normals.push(normal[0], normal[2], normal[1]);\r\n }\r\n }\r\n if (STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n indices.push(indicesCount, indicesCount + 2, indicesCount + 1);\r\n indicesCount += 3;\r\n } else {\r\n indices.push(indicesCount++, indicesCount++, indicesCount++);\r\n }\r\n this.vertexPattern.lastIndex = 0;\r\n }\r\n\r\n this.facetsPattern.lastIndex = 0;\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n SceneLoader.RegisterPlugin(new STLFileLoader());\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"stlFileLoader.js","sourceRoot":"","sources":["../../../../lts/loaders/generated/STL/stlFileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAEnD,OAAO,EAAE,IAAI,EAAE,uCAAyB;AAExC,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,cAAc,EAAE,0CAA4B;AAGrD;;;GAGG;AACH,MAAM,OAAO,aAAa;IAA1B;QACI,gBAAgB;QACT,iBAAY,GAAG,yCAAyC,CAAC;QAEhE,gBAAgB;QACT,kBAAa,GAAG,0BAA0B,CAAC;QAClD,gBAAgB;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S;AA6OxD,IAAI,WAAW,EAAE;IACb,WAAW,CAAC,cAAc,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;CACnD","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n/**\r\n * STL file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class STLFileLoader implements ISceneLoaderPlugin {\r\n /** @internal */\r\n public solidPattern = /solid (\\S*)([\\S\\s]*?)endsolid[ ]*(\\S*)/g;\r\n\r\n /** @internal */\r\n public facetsPattern = /facet([\\s\\S]*?)endfacet/g;\r\n /** @internal */\r\n public normalPattern = /normal[\\s]+([-+]?[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;\r\n /** @internal */\r\n public vertexPattern = /vertex[\\s]+([-+]?[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public name = \"stl\";\r\n\r\n /**\r\n * Defines the extensions the stl loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n * we'll convert to string if it looks like it's an ASCII .stl\r\n */\r\n public extensions: ISceneLoaderPluginExtensions = {\r\n \".stl\": { isBinary: true },\r\n };\r\n\r\n /**\r\n * Defines if Y and Z axes are swapped or not when loading an STL file.\r\n * The default is false to maintain backward compatibility. When set to\r\n * true, coordinates from the STL file are used without change.\r\n */\r\n public static DO_NOT_ALTER_FILE_COORDINATES = false;\r\n\r\n /**\r\n * Import meshes into a scene.\r\n * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param scene The scene to import into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param meshes The meshes array to import into\r\n * @returns True if successful or false otherwise\r\n */\r\n public importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>): boolean {\r\n let matches;\r\n\r\n if (typeof data !== \"string\") {\r\n if (this._isBinary(data)) {\r\n // binary .stl\r\n const babylonMesh = new Mesh(\"stlmesh\", scene);\r\n this._parseBinary(babylonMesh, data);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n return true;\r\n }\r\n\r\n // ASCII .stl\r\n\r\n // convert to string\r\n const array_buffer = new Uint8Array(data);\r\n let str = \"\";\r\n for (let i = 0; i < data.byteLength; i++) {\r\n str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian\r\n }\r\n data = str;\r\n }\r\n\r\n //if arrived here, data is a string, containing the STLA data.\r\n\r\n while ((matches = this.solidPattern.exec(data))) {\r\n let meshName = matches[1];\r\n const meshNameFromEnd = matches[3];\r\n if (meshNameFromEnd && meshName != meshNameFromEnd) {\r\n Tools.Error(\"Error in STL, solid name != endsolid name\");\r\n return false;\r\n }\r\n\r\n // check meshesNames\r\n if (meshesNames && meshName) {\r\n if (meshesNames instanceof Array) {\r\n if (!meshesNames.indexOf(meshName)) {\r\n continue;\r\n }\r\n } else {\r\n if (meshName !== meshesNames) {\r\n continue;\r\n }\r\n }\r\n }\r\n\r\n // stl mesh name can be empty as well\r\n meshName = meshName || \"stlmesh\";\r\n\r\n const babylonMesh = new Mesh(meshName, scene);\r\n this._parseASCII(babylonMesh, matches[2]);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Load into a scene.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns true if successful or false otherwise\r\n */\r\n public load(scene: Scene, data: any, rootUrl: string): boolean {\r\n const result = this.importMesh(null, scene, data, rootUrl, null);\r\n return result;\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n public loadAssetContainer(scene: Scene, data: string, rootUrl: string): AssetContainer {\r\n const container = new AssetContainer(scene);\r\n scene._blockEntityCollection = true;\r\n this.importMesh(null, scene, data, rootUrl, container.meshes);\r\n scene._blockEntityCollection = false;\r\n return container;\r\n }\r\n\r\n private _isBinary(data: any) {\r\n // check if file size is correct for binary stl\r\n const reader = new DataView(data);\r\n\r\n // A Binary STL header is 80 bytes, if the data size is not great than\r\n // that then it's not a binary STL.\r\n if (reader.byteLength <= 80) {\r\n return false;\r\n }\r\n\r\n const faceSize = (32 / 8) * 3 + (32 / 8) * 3 * 3 + 16 / 8;\r\n const nFaces = reader.getUint32(80, true);\r\n\r\n if (80 + 32 / 8 + nFaces * faceSize === reader.byteLength) {\r\n return true;\r\n }\r\n\r\n // US-ASCII begin with 's', 'o', 'l', 'i', 'd'\r\n const ascii = [115, 111, 108, 105, 100];\r\n for (let off = 0; off < 5; off++) {\r\n if (reader.getUint8(off) !== ascii[off]) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _parseBinary(mesh: Mesh, data: ArrayBuffer) {\r\n const reader = new DataView(data);\r\n const faces = reader.getUint32(80, true);\r\n\r\n const dataOffset = 84;\r\n const faceLength = 12 * 4 + 2;\r\n\r\n let offset = 0;\r\n\r\n const positions = new Float32Array(faces * 3 * 3);\r\n const normals = new Float32Array(faces * 3 * 3);\r\n const indices = new Uint32Array(faces * 3);\r\n let indicesCount = 0;\r\n\r\n for (let face = 0; face < faces; face++) {\r\n const start = dataOffset + face * faceLength;\r\n const normalX = reader.getFloat32(start, true);\r\n const normalY = reader.getFloat32(start + 4, true);\r\n const normalZ = reader.getFloat32(start + 8, true);\r\n\r\n for (let i = 1; i <= 3; i++) {\r\n const vertexstart = start + i * 12;\r\n\r\n // ordering is intentional to match ascii import\r\n positions[offset] = reader.getFloat32(vertexstart, true);\r\n normals[offset] = normalX;\r\n\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 2] = normalY;\r\n normals[offset + 1] = normalZ;\r\n } else {\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 1] = normalY;\r\n normals[offset + 2] = normalZ;\r\n }\r\n\r\n offset += 3;\r\n }\r\n\r\n if (STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n indices[indicesCount] = indicesCount;\r\n indices[indicesCount + 1] = indicesCount + 2;\r\n indices[indicesCount + 2] = indicesCount + 1;\r\n indicesCount += 3;\r\n } else {\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n }\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n\r\n private _parseASCII(mesh: Mesh, solidData: string) {\r\n const positions = [];\r\n const normals = [];\r\n const indices = [];\r\n let indicesCount = 0;\r\n\r\n //load facets, ignoring loop as the standard doesn't define it can contain more than vertices\r\n let matches;\r\n while ((matches = this.facetsPattern.exec(solidData))) {\r\n const facet = matches[1];\r\n //one normal per face\r\n const normalMatches = this.normalPattern.exec(facet);\r\n this.normalPattern.lastIndex = 0;\r\n if (!normalMatches) {\r\n continue;\r\n }\r\n const normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];\r\n\r\n let vertexMatch;\r\n while ((vertexMatch = this.vertexPattern.exec(facet))) {\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));\r\n normals.push(normal[0], normal[1], normal[2]);\r\n } else {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[3]), Number(vertexMatch[5]));\r\n\r\n // Flipping the second and third component because inverted\r\n // when normal was declared.\r\n normals.push(normal[0], normal[2], normal[1]);\r\n }\r\n }\r\n if (STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n indices.push(indicesCount, indicesCount + 2, indicesCount + 1);\r\n indicesCount += 3;\r\n } else {\r\n indices.push(indicesCount++, indicesCount++, indicesCount++);\r\n }\r\n this.vertexPattern.lastIndex = 0;\r\n }\r\n\r\n this.facetsPattern.lastIndex = 0;\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n SceneLoader.RegisterPlugin(new STLFileLoader());\r\n}\r\n"]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { IGLTFTechniqueParameter, IGLTFAccessor, IGLTFRuntime, IGLTFBufferView } from "./glTFLoaderInterfaces";
|
2
|
-
import {
|
2
|
+
import { EComponentType } from "./glTFLoaderInterfaces";
|
3
3
|
import { Effect } from "@babylonjs/core/Materials/effect.js";
|
4
4
|
import { ShaderMaterial } from "@babylonjs/core/Materials/shaderMaterial.js";
|
5
5
|
import type { Node } from "@babylonjs/core/node.js";
|
@@ -40,8 +40,9 @@ export declare class GLTFUtils {
|
|
40
40
|
/**
|
41
41
|
* Returns the texture filter mode giving a mode value
|
42
42
|
* @param mode the filter mode value
|
43
|
+
* @returns the filter mode (TODO - needs to be a type?)
|
43
44
|
*/
|
44
|
-
static GetTextureFilterMode(mode: number):
|
45
|
+
static GetTextureFilterMode(mode: number): number;
|
45
46
|
static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
|
46
47
|
/**
|
47
48
|
* Returns a buffer from its accessor
|
@@ -140,6 +140,7 @@ export class GLTFUtils {
|
|
140
140
|
/**
|
141
141
|
* Returns the texture filter mode giving a mode value
|
142
142
|
* @param mode the filter mode value
|
143
|
+
* @returns the filter mode (TODO - needs to be a type?)
|
143
144
|
*/
|
144
145
|
static GetTextureFilterMode(mode) {
|
145
146
|
switch (mode) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"glTFLoaderUtils.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/glTF/1.0/glTFLoaderUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG9G,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAC3E,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,cAAc,EAAE,oDAAsC;AAC/D,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAI1D;;;;GAIG;AACH,MAAM,OAAO,SAAS;IAClB;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAC,KAAY,EAAE,MAAY,EAAE,SAAkC,EAAE,WAAmB,EAAE,cAAuC;QAChJ,IAAI,GAAG,GA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,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,MAAM,CAAC,YAAY,CAAC,gCAAgC,CAAC,GAAG;gBACpD,wBAAwB;gBACxB,EAAE;gBACF,0BAA0B;gBAC1B,EAAE;gBACF,iBAAiB;gBACjB,GAAG;gBACH,gCAAgC;gBAChC,GAAG;aACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,MAAM,UAAU,GAAG;gBACf,MAAM,EAAE,qBAAqB;gBAC7B,QAAQ,EAAE,qBAAqB;aAClC,CAAC;YAEF,MAAM,OAAO,GAAG;gBACZ,UAAU,EAAE,CAAC,UAAU,CAAC;gBACxB,QAAQ,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC;gBACnD,QAAQ,EAAE,IAAI,KAAK,EAAU;gBAC7B,iBAAiB,EAAE,KAAK;aAC3B,CAAC;YAEF,SAAS,CAAC,gBAAgB,GAAG,IAAI,cAAc,CAAC,qBAAqB,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;YACnG,SAAS,CAAC,gBAAgB,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;SACtF;QAED,OAAO,SAAS,CAAC,gBAAgB,CAAC;IACtC,CAAC;;AAED,4BAA4B;AACb,0BAAgB,GAA6B,IAAI,CAAC","sourcesContent":["import type { IGLTFTechniqueParameter, IGLTFAccessor, IGLTFRuntime, IGLTFBufferView } from \"./glTFLoaderInterfaces\";\r\nimport { EParameterType, ETextureWrapMode, ETextureFilterType, EComponentType } from \"./glTFLoaderInterfaces\";\r\n\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector2, Vector3, Vector4, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport { ShaderMaterial } from \"core/Materials/shaderMaterial\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Node } from \"core/node\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n/**\r\n * Utils functions for GLTF\r\n * @internal\r\n * @deprecated\r\n */\r\nexport class GLTFUtils {\r\n /**\r\n * Sets the given \"parameter\" matrix\r\n * @param scene the Scene object\r\n * @param source the source node where to pick the matrix\r\n * @param parameter the GLTF technique parameter\r\n * @param uniformName the name of the shader's uniform\r\n * @param shaderMaterial the shader material\r\n */\r\n public static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void {\r\n let mat: Nullable<Matrix> = null;\r\n\r\n if (parameter.semantic === \"MODEL\") {\r\n mat = source.getWorldMatrix();\r\n } else if (parameter.semantic === \"PROJECTION\") {\r\n mat = scene.getProjectionMatrix();\r\n } else if (parameter.semantic === \"VIEW\") {\r\n mat = scene.getViewMatrix();\r\n } else if (parameter.semantic === \"MODELVIEWINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());\r\n } else if (parameter.semantic === \"MODELVIEW\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix());\r\n } else if (parameter.semantic === \"MODELVIEWPROJECTION\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());\r\n } else if (parameter.semantic === \"MODELINVERSE\") {\r\n mat = source.getWorldMatrix().invert();\r\n } else if (parameter.semantic === \"VIEWINVERSE\") {\r\n mat = scene.getViewMatrix().invert();\r\n } else if (parameter.semantic === \"PROJECTIONINVERSE\") {\r\n mat = scene.getProjectionMatrix().invert();\r\n } else if (parameter.semantic === \"MODELVIEWINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();\r\n } else if (parameter.semantic === \"MODELVIEWPROJECTIONINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();\r\n } else if (parameter.semantic === \"MODELINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().invert());\r\n }\r\n\r\n if (mat) {\r\n switch (parameter.type) {\r\n case EParameterType.FLOAT_MAT2:\r\n shaderMaterial.setMatrix2x2(uniformName, Matrix.GetAsMatrix2x2(mat));\r\n break;\r\n case EParameterType.FLOAT_MAT3:\r\n shaderMaterial.setMatrix3x3(uniformName, Matrix.GetAsMatrix3x3(mat));\r\n break;\r\n case EParameterType.FLOAT_MAT4:\r\n shaderMaterial.setMatrix(uniformName, mat);\r\n break;\r\n default:\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets the given \"parameter\" matrix\r\n * @param shaderMaterial the shader material\r\n * @param uniform the name of the shader's uniform\r\n * @param value the value of the uniform\r\n * @param type the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)\r\n */\r\n public static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean {\r\n switch (type) {\r\n case EParameterType.FLOAT:\r\n shaderMaterial.setFloat(uniform, value);\r\n return true;\r\n case EParameterType.FLOAT_VEC2:\r\n shaderMaterial.setVector2(uniform, Vector2.FromArray(value));\r\n return true;\r\n case EParameterType.FLOAT_VEC3:\r\n shaderMaterial.setVector3(uniform, Vector3.FromArray(value));\r\n return true;\r\n case EParameterType.FLOAT_VEC4:\r\n shaderMaterial.setVector4(uniform, Vector4.FromArray(value));\r\n return true;\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the wrap mode of the texture\r\n * @param mode the mode value\r\n */\r\n public static GetWrapMode(mode: number): number {\r\n switch (mode) {\r\n case ETextureWrapMode.CLAMP_TO_EDGE:\r\n return Texture.CLAMP_ADDRESSMODE;\r\n case ETextureWrapMode.MIRRORED_REPEAT:\r\n return Texture.MIRROR_ADDRESSMODE;\r\n case ETextureWrapMode.REPEAT:\r\n return Texture.WRAP_ADDRESSMODE;\r\n default:\r\n return Texture.WRAP_ADDRESSMODE;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the byte stride giving an accessor\r\n * @param accessor the GLTF accessor objet\r\n */\r\n public static GetByteStrideFromType(accessor: IGLTFAccessor): number {\r\n // Needs this function since \"byteStride\" isn't requiered in glTF format\r\n const type = accessor.type;\r\n\r\n switch (type) {\r\n case \"VEC2\":\r\n return 2;\r\n case \"VEC3\":\r\n return 3;\r\n case \"VEC4\":\r\n return 4;\r\n case \"MAT2\":\r\n return 4;\r\n case \"MAT3\":\r\n return 9;\r\n case \"MAT4\":\r\n return 16;\r\n default:\r\n return 1;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the texture filter mode giving a mode value\r\n * @param mode the filter mode value\r\n */\r\n public static GetTextureFilterMode(mode: number): ETextureFilterType {\r\n switch (mode) {\r\n case ETextureFilterType.LINEAR:\r\n case ETextureFilterType.LINEAR_MIPMAP_NEAREST:\r\n case ETextureFilterType.LINEAR_MIPMAP_LINEAR:\r\n return Texture.TRILINEAR_SAMPLINGMODE;\r\n case ETextureFilterType.NEAREST:\r\n case ETextureFilterType.NEAREST_MIPMAP_NEAREST:\r\n return Texture.NEAREST_SAMPLINGMODE;\r\n default:\r\n return Texture.BILINEAR_SAMPLINGMODE;\r\n }\r\n }\r\n\r\n public static GetBufferFromBufferView(\r\n gltfRuntime: IGLTFRuntime,\r\n bufferView: IGLTFBufferView,\r\n byteOffset: number,\r\n byteLength: number,\r\n componentType: EComponentType\r\n ): ArrayBufferView {\r\n byteOffset = bufferView.byteOffset + byteOffset;\r\n\r\n const loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];\r\n if (byteOffset + byteLength > loadedBufferView.byteLength) {\r\n throw new Error(\"Buffer access is out of range\");\r\n }\r\n\r\n const buffer = loadedBufferView.buffer;\r\n byteOffset += loadedBufferView.byteOffset;\r\n\r\n switch (componentType) {\r\n case EComponentType.BYTE:\r\n return new Int8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_BYTE:\r\n return new Uint8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.SHORT:\r\n return new Int16Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_SHORT:\r\n return new Uint16Array(buffer, byteOffset, byteLength);\r\n default:\r\n return new Float32Array(buffer, byteOffset, byteLength);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a buffer from its accessor\r\n * @param gltfRuntime the GLTF runtime\r\n * @param accessor the GLTF accessor\r\n */\r\n public static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any {\r\n const bufferView: IGLTFBufferView = gltfRuntime.bufferViews[accessor.bufferView];\r\n const byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);\r\n return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);\r\n }\r\n\r\n /**\r\n * Decodes a buffer view into a string\r\n * @param view the buffer view\r\n */\r\n public static DecodeBufferToText(view: ArrayBufferView): string {\r\n let result = \"\";\r\n const length = view.byteLength;\r\n\r\n for (let i = 0; i < length; ++i) {\r\n result += String.fromCharCode((<any>view)[i]);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns the default material of gltf. Related to\r\n * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material\r\n * @param scene the Babylon.js scene\r\n */\r\n public static GetDefaultMaterial(scene: Scene): ShaderMaterial {\r\n if (!GLTFUtils._DefaultMaterial) {\r\n Effect.ShadersStore[\"GLTFDefaultMaterialVertexShader\"] = [\r\n \"precision highp float;\",\r\n \"\",\r\n \"uniform mat4 worldView;\",\r\n \"uniform mat4 projection;\",\r\n \"\",\r\n \"attribute vec3 position;\",\r\n \"\",\r\n \"void main(void)\",\r\n \"{\",\r\n \" gl_Position = projection * worldView * vec4(position, 1.0);\",\r\n \"}\",\r\n ].join(\"\\n\");\r\n\r\n Effect.ShadersStore[\"GLTFDefaultMaterialPixelShader\"] = [\r\n \"precision highp float;\",\r\n \"\",\r\n \"uniform vec4 u_emission;\",\r\n \"\",\r\n \"void main(void)\",\r\n \"{\",\r\n \" gl_FragColor = u_emission;\",\r\n \"}\",\r\n ].join(\"\\n\");\r\n\r\n const shaderPath = {\r\n vertex: \"GLTFDefaultMaterial\",\r\n fragment: \"GLTFDefaultMaterial\",\r\n };\r\n\r\n const options = {\r\n attributes: [\"position\"],\r\n uniforms: [\"worldView\", \"projection\", \"u_emission\"],\r\n samplers: new Array<string>(),\r\n needAlphaBlending: false,\r\n };\r\n\r\n GLTFUtils._DefaultMaterial = new ShaderMaterial(\"GLTFDefaultMaterial\", scene, shaderPath, options);\r\n GLTFUtils._DefaultMaterial.setColor4(\"u_emission\", new Color4(0.5, 0.5, 0.5, 1.0));\r\n }\r\n\r\n return GLTFUtils._DefaultMaterial;\r\n }\r\n\r\n // The GLTF default material\r\n private static _DefaultMaterial: Nullable<ShaderMaterial> = null;\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"glTFLoaderUtils.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/glTF/1.0/glTFLoaderUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG9G,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAC3E,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,cAAc,EAAE,oDAAsC;AAC/D,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAI1D;;;;GAIG;AACH,MAAM,OAAO,SAAS;IAClB;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAC,KAAY,EAAE,MAAY,EAAE,SAAkC,EAAE,WAAmB,EAAE,cAAuC;QAChJ,IAAI,GAAG,GAAqB,IAAI,CAAC;QAEjC,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,EAAE;YAChC,GAAG,GA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,GAAG;gBACpD,wBAAwB;gBACxB,EAAE;gBACF,0BAA0B;gBAC1B,EAAE;gBACF,iBAAiB;gBACjB,GAAG;gBACH,gCAAgC;gBAChC,GAAG;aACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,MAAM,UAAU,GAAG;gBACf,MAAM,EAAE,qBAAqB;gBAC7B,QAAQ,EAAE,qBAAqB;aAClC,CAAC;YAEF,MAAM,OAAO,GAAG;gBACZ,UAAU,EAAE,CAAC,UAAU,CAAC;gBACxB,QAAQ,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC;gBACnD,QAAQ,EAAE,IAAI,KAAK,EAAU;gBAC7B,iBAAiB,EAAE,KAAK;aAC3B,CAAC;YAEF,SAAS,CAAC,gBAAgB,GAAG,IAAI,cAAc,CAAC,qBAAqB,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;YACnG,SAAS,CAAC,gBAAgB,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;SACtF;QAED,OAAO,SAAS,CAAC,gBAAgB,CAAC;IACtC,CAAC;;AAED,4BAA4B;AACb,0BAAgB,GAA6B,IAAI,CAAC","sourcesContent":["import type { IGLTFTechniqueParameter, IGLTFAccessor, IGLTFRuntime, IGLTFBufferView } from \"./glTFLoaderInterfaces\";\r\nimport { EParameterType, ETextureWrapMode, ETextureFilterType, EComponentType } from \"./glTFLoaderInterfaces\";\r\n\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector2, Vector3, Vector4, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport { ShaderMaterial } from \"core/Materials/shaderMaterial\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Node } from \"core/node\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n/**\r\n * Utils functions for GLTF\r\n * @internal\r\n * @deprecated\r\n */\r\nexport class GLTFUtils {\r\n /**\r\n * Sets the given \"parameter\" matrix\r\n * @param scene the Scene object\r\n * @param source the source node where to pick the matrix\r\n * @param parameter the GLTF technique parameter\r\n * @param uniformName the name of the shader's uniform\r\n * @param shaderMaterial the shader material\r\n */\r\n public static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void {\r\n let mat: Nullable<Matrix> = null;\r\n\r\n if (parameter.semantic === \"MODEL\") {\r\n mat = source.getWorldMatrix();\r\n } else if (parameter.semantic === \"PROJECTION\") {\r\n mat = scene.getProjectionMatrix();\r\n } else if (parameter.semantic === \"VIEW\") {\r\n mat = scene.getViewMatrix();\r\n } else if (parameter.semantic === \"MODELVIEWINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());\r\n } else if (parameter.semantic === \"MODELVIEW\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix());\r\n } else if (parameter.semantic === \"MODELVIEWPROJECTION\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());\r\n } else if (parameter.semantic === \"MODELINVERSE\") {\r\n mat = source.getWorldMatrix().invert();\r\n } else if (parameter.semantic === \"VIEWINVERSE\") {\r\n mat = scene.getViewMatrix().invert();\r\n } else if (parameter.semantic === \"PROJECTIONINVERSE\") {\r\n mat = scene.getProjectionMatrix().invert();\r\n } else if (parameter.semantic === \"MODELVIEWINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();\r\n } else if (parameter.semantic === \"MODELVIEWPROJECTIONINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();\r\n } else if (parameter.semantic === \"MODELINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().invert());\r\n }\r\n\r\n if (mat) {\r\n switch (parameter.type) {\r\n case EParameterType.FLOAT_MAT2:\r\n shaderMaterial.setMatrix2x2(uniformName, Matrix.GetAsMatrix2x2(mat));\r\n break;\r\n case EParameterType.FLOAT_MAT3:\r\n shaderMaterial.setMatrix3x3(uniformName, Matrix.GetAsMatrix3x3(mat));\r\n break;\r\n case EParameterType.FLOAT_MAT4:\r\n shaderMaterial.setMatrix(uniformName, mat);\r\n break;\r\n default:\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets the given \"parameter\" matrix\r\n * @param shaderMaterial the shader material\r\n * @param uniform the name of the shader's uniform\r\n * @param value the value of the uniform\r\n * @param type the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)\r\n */\r\n public static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean {\r\n switch (type) {\r\n case EParameterType.FLOAT:\r\n shaderMaterial.setFloat(uniform, value);\r\n return true;\r\n case EParameterType.FLOAT_VEC2:\r\n shaderMaterial.setVector2(uniform, Vector2.FromArray(value));\r\n return true;\r\n case EParameterType.FLOAT_VEC3:\r\n shaderMaterial.setVector3(uniform, Vector3.FromArray(value));\r\n return true;\r\n case EParameterType.FLOAT_VEC4:\r\n shaderMaterial.setVector4(uniform, Vector4.FromArray(value));\r\n return true;\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the wrap mode of the texture\r\n * @param mode the mode value\r\n */\r\n public static GetWrapMode(mode: number): number {\r\n switch (mode) {\r\n case ETextureWrapMode.CLAMP_TO_EDGE:\r\n return Texture.CLAMP_ADDRESSMODE;\r\n case ETextureWrapMode.MIRRORED_REPEAT:\r\n return Texture.MIRROR_ADDRESSMODE;\r\n case ETextureWrapMode.REPEAT:\r\n return Texture.WRAP_ADDRESSMODE;\r\n default:\r\n return Texture.WRAP_ADDRESSMODE;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the byte stride giving an accessor\r\n * @param accessor the GLTF accessor objet\r\n */\r\n public static GetByteStrideFromType(accessor: IGLTFAccessor): number {\r\n // Needs this function since \"byteStride\" isn't requiered in glTF format\r\n const type = accessor.type;\r\n\r\n switch (type) {\r\n case \"VEC2\":\r\n return 2;\r\n case \"VEC3\":\r\n return 3;\r\n case \"VEC4\":\r\n return 4;\r\n case \"MAT2\":\r\n return 4;\r\n case \"MAT3\":\r\n return 9;\r\n case \"MAT4\":\r\n return 16;\r\n default:\r\n return 1;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the texture filter mode giving a mode value\r\n * @param mode the filter mode value\r\n * @returns the filter mode (TODO - needs to be a type?)\r\n */\r\n public static GetTextureFilterMode(mode: number): number {\r\n switch (mode) {\r\n case ETextureFilterType.LINEAR:\r\n case ETextureFilterType.LINEAR_MIPMAP_NEAREST:\r\n case ETextureFilterType.LINEAR_MIPMAP_LINEAR:\r\n return Texture.TRILINEAR_SAMPLINGMODE;\r\n case ETextureFilterType.NEAREST:\r\n case ETextureFilterType.NEAREST_MIPMAP_NEAREST:\r\n return Texture.NEAREST_SAMPLINGMODE;\r\n default:\r\n return Texture.BILINEAR_SAMPLINGMODE;\r\n }\r\n }\r\n\r\n public static GetBufferFromBufferView(\r\n gltfRuntime: IGLTFRuntime,\r\n bufferView: IGLTFBufferView,\r\n byteOffset: number,\r\n byteLength: number,\r\n componentType: EComponentType\r\n ): ArrayBufferView {\r\n byteOffset = bufferView.byteOffset + byteOffset;\r\n\r\n const loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];\r\n if (byteOffset + byteLength > loadedBufferView.byteLength) {\r\n throw new Error(\"Buffer access is out of range\");\r\n }\r\n\r\n const buffer = loadedBufferView.buffer;\r\n byteOffset += loadedBufferView.byteOffset;\r\n\r\n switch (componentType) {\r\n case EComponentType.BYTE:\r\n return new Int8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_BYTE:\r\n return new Uint8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.SHORT:\r\n return new Int16Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_SHORT:\r\n return new Uint16Array(buffer, byteOffset, byteLength);\r\n default:\r\n return new Float32Array(buffer, byteOffset, byteLength);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a buffer from its accessor\r\n * @param gltfRuntime the GLTF runtime\r\n * @param accessor the GLTF accessor\r\n */\r\n public static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any {\r\n const bufferView: IGLTFBufferView = gltfRuntime.bufferViews[accessor.bufferView];\r\n const byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);\r\n return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);\r\n }\r\n\r\n /**\r\n * Decodes a buffer view into a string\r\n * @param view the buffer view\r\n */\r\n public static DecodeBufferToText(view: ArrayBufferView): string {\r\n let result = \"\";\r\n const length = view.byteLength;\r\n\r\n for (let i = 0; i < length; ++i) {\r\n result += String.fromCharCode((<any>view)[i]);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns the default material of gltf. Related to\r\n * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material\r\n * @param scene the Babylon.js scene\r\n */\r\n public static GetDefaultMaterial(scene: Scene): ShaderMaterial {\r\n if (!GLTFUtils._DefaultMaterial) {\r\n Effect.ShadersStore[\"GLTFDefaultMaterialVertexShader\"] = [\r\n \"precision highp float;\",\r\n \"\",\r\n \"uniform mat4 worldView;\",\r\n \"uniform mat4 projection;\",\r\n \"\",\r\n \"attribute vec3 position;\",\r\n \"\",\r\n \"void main(void)\",\r\n \"{\",\r\n \" gl_Position = projection * worldView * vec4(position, 1.0);\",\r\n \"}\",\r\n ].join(\"\\n\");\r\n\r\n Effect.ShadersStore[\"GLTFDefaultMaterialPixelShader\"] = [\r\n \"precision highp float;\",\r\n \"\",\r\n \"uniform vec4 u_emission;\",\r\n \"\",\r\n \"void main(void)\",\r\n \"{\",\r\n \" gl_FragColor = u_emission;\",\r\n \"}\",\r\n ].join(\"\\n\");\r\n\r\n const shaderPath = {\r\n vertex: \"GLTFDefaultMaterial\",\r\n fragment: \"GLTFDefaultMaterial\",\r\n };\r\n\r\n const options = {\r\n attributes: [\"position\"],\r\n uniforms: [\"worldView\", \"projection\", \"u_emission\"],\r\n samplers: new Array<string>(),\r\n needAlphaBlending: false,\r\n };\r\n\r\n GLTFUtils._DefaultMaterial = new ShaderMaterial(\"GLTFDefaultMaterial\", scene, shaderPath, options);\r\n GLTFUtils._DefaultMaterial.setColor4(\"u_emission\", new Color4(0.5, 0.5, 0.5, 1.0));\r\n }\r\n\r\n return GLTFUtils._DefaultMaterial;\r\n }\r\n\r\n // The GLTF default material\r\n private static _DefaultMaterial: Nullable<ShaderMaterial> = null;\r\n}\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_ior.js","sourceRoot":"","sources":["../../../../../../lts/loaders/generated/glTF/2.0/Extensions/KHR_materials_ior.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,iBAAiB;IAuB1B;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,kB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,iBAAiB,GAAG,UAAU,CAAC,GAAG,CAAC;SACtD;aAAM;YACH,eAAe,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,YAAY,CAAC;SACtE;QAED,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;;AA3DD;;GAEG;AACqB,8BAAY,GAAG,GAAG,AAAN,CAAO;AA2D/C,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\n\r\nimport type { IMaterial } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsIor } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_materials_ior\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_ior/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_ior implements IGLTFLoaderExtension {\r\n /**\r\n * Default ior Value from the spec.\r\n */\r\n private static readonly _DEFAULT_IOR = 1.5;\r\n\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 180;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsIor>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadIorPropertiesAsync(extensionContext, extension, babylonMaterial));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadIorPropertiesAsync(context: string, properties: IKHRMaterialsIor, babylonMaterial: Material): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n if (properties.ior !== undefined) {\r\n babylonMaterial.indexOfRefraction = properties.ior;\r\n } else {\r\n babylonMaterial.indexOfRefraction = KHR_materials_ior._DEFAULT_IOR;\r\n }\r\n\r\n return Promise.resolve();\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_ior(loader));\r\n"]}
|