@babylonjs/serializers 7.34.3 → 7.35.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/objSerializer.js.map +1 -1
- package/USDZ/usdzExporter.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/glTFAnimation.js.map +1 -1
- package/glTF/2.0/glTFData.js.map +1 -1
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/glTF/2.0/glTFSerializer.js.map +1 -1
- package/glTF/2.0/glTFUtilities.js.map +1 -1
- package/legacy/legacy-glTF2Serializer.js.map +1 -1
- package/legacy/legacy-objSerializer.js.map +1 -1
- package/legacy/legacy-stlSerializer.js.map +1 -1
- package/legacy/legacy-usdzSerializer.js.map +1 -1
- package/package.json +3 -3
- package/stl/stlSerializer.js.map +1 -1
package/stl/stlSerializer.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stlSerializer.js","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E,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;oBACjF,IAAI,IAAI,iBAAiB,CAAC;oBAC1B,IAAI,IAAI,gBAAgB,CAAC;iBAC5B;aACJ;YACD,IAAI,CAAC,MAAM,IAAI,sBAAsB,EAAE;gBACnC,IAAI,IAAI,WAAW,GAAG,IAAI,GAAG,MAAM,CAAC;aACvC;SACJ;QAED,IAAI,CAAC,MAAM,IAAI,CAAC,sBAAsB,EAAE;YACpC,IAAI,IAAI,kBAAkB,CAAC;SAC9B;QAED,IAAI,QAAQ,EAAE;YACV,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YACtC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAAC;YACpE,CAAC,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC1C,CAAC,CAAC,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;YAC/B,CAAC,CAAC,KAAK,EAAE,CAAC;SACb;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import { Mesh } from \"core/Meshes/mesh\";\r\nimport { InstancedMesh } from \"core/Meshes/instancedMesh\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * Class for generating STL data from a Babylon scene.\r\n */\r\nexport class STLExport {\r\n /**\r\n * Exports the geometry of a Mesh array in .STL file format (ASCII)\r\n * @param meshes list defines the mesh to serialize\r\n * @param download triggers the automatic download of the file.\r\n * @param fileName changes the downloads fileName.\r\n * @param binary changes the STL to a binary type.\r\n * @param isLittleEndian toggle for binary type exporter.\r\n * @param doNotBakeTransform toggle if meshes transforms should be baked or not.\r\n * @param supportInstancedMeshes toggle to export instanced Meshes. Enabling support for instanced meshes will override doNoBakeTransform as true\r\n * @param exportIndividualMeshes toggle to export each mesh as an independent mesh. By default, all the meshes are combined into one mesh. This property has no effect when exporting in binary format\r\n * @returns the STL as UTF8 string\r\n */\r\n public static CreateSTL(\r\n meshes: (Mesh | InstancedMesh)[],\r\n download: boolean = true,\r\n fileName: string = \"stlmesh\",\r\n binary: boolean = false,\r\n isLittleEndian: boolean = true,\r\n doNotBakeTransform: boolean = false,\r\n supportInstancedMeshes: boolean = false,\r\n exportIndividualMeshes: boolean = false\r\n ): any {\r\n //Binary support adapted from https://gist.github.com/paulkaplan/6d5f0ab2c7e8fdc68a61\r\n\r\n const getFaceData = function (indices: any, vertices: any, i: number) {\r\n const id = [indices[i] * 3, indices[i + 1] * 3, indices[i + 2] * 3];\r\n const v = [\r\n new Vector3(vertices[id[0]], vertices[id[0] + 2], vertices[id[0] + 1]),\r\n new Vector3(vertices[id[1]], vertices[id[1] + 2], vertices[id[1] + 1]),\r\n new Vector3(vertices[id[2]], vertices[id[2] + 2], vertices[id[2] + 1]),\r\n ];\r\n const p1p2 = v[0].subtract(v[1]);\r\n const p3p2 = v[2].subtract(v[1]);\r\n const n = Vector3.Cross(p3p2, p1p2).normalize();\r\n\r\n return { v, n };\r\n };\r\n\r\n const writeVector = function (dataview: any, offset: number, vector: Vector3, isLittleEndian: boolean) {\r\n offset = writeFloat(dataview, offset, vector.x, isLittleEndian);\r\n offset = writeFloat(dataview, offset, vector.y, isLittleEndian);\r\n return writeFloat(dataview, offset, vector.z, isLittleEndian);\r\n };\r\n\r\n const writeFloat = function (dataview: any, offset: number, value: number, isLittleEndian: boolean) {\r\n dataview.setFloat32(offset, value, isLittleEndian);\r\n return offset + 4;\r\n };\r\n\r\n const getVerticesData = function (mesh: InstancedMesh | Mesh) {\r\n if (supportInstancedMeshes) {\r\n let sourceMesh = mesh;\r\n if (mesh instanceof InstancedMesh) {\r\n sourceMesh = mesh.sourceMesh;\r\n }\r\n const data = sourceMesh.getVerticesData(VertexBuffer.PositionKind, true, true);\r\n if (!data) return [];\r\n const temp = Vector3.Zero();\r\n let index;\r\n for (index = 0; index < data.length; index += 3) {\r\n Vector3.TransformCoordinatesFromFloatsToRef(data[index], data[index + 1], data[index + 2], mesh.computeWorldMatrix(true), temp).toArray(data, index);\r\n }\r\n return data;\r\n } else {\r\n return mesh.getVerticesData(VertexBuffer.PositionKind) || [];\r\n }\r\n };\r\n\r\n if (supportInstancedMeshes) {\r\n doNotBakeTransform = true;\r\n }\r\n\r\n let data: DataView | string = \"\";\r\n\r\n let faceCount = 0;\r\n let offset = 0;\r\n\r\n if (binary) {\r\n for (let i = 0; i < meshes.length; i++) {\r\n const mesh = meshes[i];\r\n const indices = mesh.getIndices();\r\n faceCount += indices ? indices.length / 3 : 0;\r\n }\r\n\r\n const bufferSize = 84 + 50 * faceCount;\r\n const buffer = new ArrayBuffer(bufferSize);\r\n data = new DataView(buffer);\r\n\r\n offset += 80;\r\n data.setUint32(offset, faceCount, isLittleEndian);\r\n offset += 4;\r\n } else {\r\n if (!exportIndividualMeshes) {\r\n data = \"solid stlmesh\\r\\n\";\r\n }\r\n }\r\n\r\n for (let i = 0; i < meshes.length; i++) {\r\n const mesh = meshes[i];\r\n if (!binary && exportIndividualMeshes) {\r\n data += \"solid \" + mesh.name + \"\\r\\n\";\r\n }\r\n if (!doNotBakeTransform && mesh instanceof Mesh) {\r\n mesh.bakeCurrentTransformIntoVertices();\r\n }\r\n const vertices = getVerticesData(mesh);\r\n const indices = mesh.getIndices() || [];\r\n\r\n for (let i = 0; i < indices.length; i += 3) {\r\n const fd = getFaceData(indices, vertices, i);\r\n\r\n if (binary) {\r\n offset = writeVector(data, offset, fd.n, isLittleEndian);\r\n offset = writeVector(data, offset, fd.v[0], isLittleEndian);\r\n offset = writeVector(data, offset, fd.v[1], isLittleEndian);\r\n offset = writeVector(data, offset, fd.v[2], isLittleEndian);\r\n offset += 2;\r\n } else {\r\n data += \"\\tfacet normal \" + fd.n.x + \" \" + fd.n.y + \" \" + fd.n.z + \"\\r\\n\";\r\n data += \"\\t\\touter loop\\r\\n\";\r\n data += \"\\t\\t\\tvertex \" + fd.v[0].x + \" \" + fd.v[0].y + \" \" + fd.v[0].z + \"\\r\\n\";\r\n data += \"\\t\\t\\tvertex \" + fd.v[1].x + \" \" + fd.v[1].y + \" \" + fd.v[1].z + \"\\r\\n\";\r\n data += \"\\t\\t\\tvertex \" + fd.v[2].x + \" \" + fd.v[2].y + \" \" + fd.v[2].z + \"\\r\\n\";\r\n data += \"\\t\\tendloop\\r\\n\";\r\n data += \"\\tendfacet\\r\\n\";\r\n }\r\n }\r\n if (!binary && exportIndividualMeshes) {\r\n data += \"endsolid \" + name + \"\\r\\n\";\r\n }\r\n }\r\n\r\n if (!binary && !exportIndividualMeshes) {\r\n data += \"endsolid stlmesh\";\r\n }\r\n\r\n if (download) {\r\n const a = document.createElement(\"a\");\r\n const blob = new Blob([data], { type: \"application/octet-stream\" });\r\n a.href = window.URL.createObjectURL(blob);\r\n a.download = fileName + \".stl\";\r\n a.click();\r\n }\r\n\r\n return data;\r\n }\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"stlSerializer.js","sourceRoot":"","sources":["../../../../dev/serializers/src/stl/stlSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,uCAAyB;AACxC,OAAO,EAAE,aAAa,EAAE,gDAAkC;AAC1D,OAAO,EAAE,YAAY,EAAE,0CAA4B;AACnD,OAAO,EAAE,OAAO,EAAE,6CAA+B;AAEjD;;GAEG;AACH,MAAM,OAAO,SAAS;IAClB;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,SAAS,CACnB,MAAgC,EAChC,WAAoB,IAAI,EACxB,WAAmB,SAAS,EAC5B,SAAkB,KAAK,EACvB,iBAA0B,IAAI,EAC9B,qBAA8B,KAAK,EACnC,yBAAkC,KAAK,EACvC,yBAAkC,KAAK;QAEvC,qFAAqF;QAErF,MAAM,WAAW,GAAG,UAAU,OAAY,EAAE,QAAa,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,IAAI,kBAAkB,CAAC;QAC/B,CAAC;QAED,IAAI,QAAQ,EAAE,CAAC;YACX,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YACtC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAAC;YACpE,CAAC,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC1C,CAAC,CAAC,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;YAC/B,CAAC,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import { Mesh } from \"core/Meshes/mesh\";\r\nimport { InstancedMesh } from \"core/Meshes/instancedMesh\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * Class for generating STL data from a Babylon scene.\r\n */\r\nexport class STLExport {\r\n /**\r\n * Exports the geometry of a Mesh array in .STL file format (ASCII)\r\n * @param meshes list defines the mesh to serialize\r\n * @param download triggers the automatic download of the file.\r\n * @param fileName changes the downloads fileName.\r\n * @param binary changes the STL to a binary type.\r\n * @param isLittleEndian toggle for binary type exporter.\r\n * @param doNotBakeTransform toggle if meshes transforms should be baked or not.\r\n * @param supportInstancedMeshes toggle to export instanced Meshes. Enabling support for instanced meshes will override doNoBakeTransform as true\r\n * @param exportIndividualMeshes toggle to export each mesh as an independent mesh. By default, all the meshes are combined into one mesh. This property has no effect when exporting in binary format\r\n * @returns the STL as UTF8 string\r\n */\r\n public static CreateSTL(\r\n meshes: (Mesh | InstancedMesh)[],\r\n download: boolean = true,\r\n fileName: string = \"stlmesh\",\r\n binary: boolean = false,\r\n isLittleEndian: boolean = true,\r\n doNotBakeTransform: boolean = false,\r\n supportInstancedMeshes: boolean = false,\r\n exportIndividualMeshes: boolean = false\r\n ): any {\r\n //Binary support adapted from https://gist.github.com/paulkaplan/6d5f0ab2c7e8fdc68a61\r\n\r\n const getFaceData = function (indices: any, vertices: any, i: number) {\r\n const id = [indices[i] * 3, indices[i + 1] * 3, indices[i + 2] * 3];\r\n const v = [\r\n new Vector3(vertices[id[0]], vertices[id[0] + 2], vertices[id[0] + 1]),\r\n new Vector3(vertices[id[1]], vertices[id[1] + 2], vertices[id[1] + 1]),\r\n new Vector3(vertices[id[2]], vertices[id[2] + 2], vertices[id[2] + 1]),\r\n ];\r\n const p1p2 = v[0].subtract(v[1]);\r\n const p3p2 = v[2].subtract(v[1]);\r\n const n = Vector3.Cross(p3p2, p1p2).normalize();\r\n\r\n return { v, n };\r\n };\r\n\r\n const writeVector = function (dataview: any, offset: number, vector: Vector3, isLittleEndian: boolean) {\r\n offset = writeFloat(dataview, offset, vector.x, isLittleEndian);\r\n offset = writeFloat(dataview, offset, vector.y, isLittleEndian);\r\n return writeFloat(dataview, offset, vector.z, isLittleEndian);\r\n };\r\n\r\n const writeFloat = function (dataview: any, offset: number, value: number, isLittleEndian: boolean) {\r\n dataview.setFloat32(offset, value, isLittleEndian);\r\n return offset + 4;\r\n };\r\n\r\n const getVerticesData = function (mesh: InstancedMesh | Mesh) {\r\n if (supportInstancedMeshes) {\r\n let sourceMesh = mesh;\r\n if (mesh instanceof InstancedMesh) {\r\n sourceMesh = mesh.sourceMesh;\r\n }\r\n const data = sourceMesh.getVerticesData(VertexBuffer.PositionKind, true, true);\r\n if (!data) return [];\r\n const temp = Vector3.Zero();\r\n let index;\r\n for (index = 0; index < data.length; index += 3) {\r\n Vector3.TransformCoordinatesFromFloatsToRef(data[index], data[index + 1], data[index + 2], mesh.computeWorldMatrix(true), temp).toArray(data, index);\r\n }\r\n return data;\r\n } else {\r\n return mesh.getVerticesData(VertexBuffer.PositionKind) || [];\r\n }\r\n };\r\n\r\n if (supportInstancedMeshes) {\r\n doNotBakeTransform = true;\r\n }\r\n\r\n let data: DataView | string = \"\";\r\n\r\n let faceCount = 0;\r\n let offset = 0;\r\n\r\n if (binary) {\r\n for (let i = 0; i < meshes.length; i++) {\r\n const mesh = meshes[i];\r\n const indices = mesh.getIndices();\r\n faceCount += indices ? indices.length / 3 : 0;\r\n }\r\n\r\n const bufferSize = 84 + 50 * faceCount;\r\n const buffer = new ArrayBuffer(bufferSize);\r\n data = new DataView(buffer);\r\n\r\n offset += 80;\r\n data.setUint32(offset, faceCount, isLittleEndian);\r\n offset += 4;\r\n } else {\r\n if (!exportIndividualMeshes) {\r\n data = \"solid stlmesh\\r\\n\";\r\n }\r\n }\r\n\r\n for (let i = 0; i < meshes.length; i++) {\r\n const mesh = meshes[i];\r\n if (!binary && exportIndividualMeshes) {\r\n data += \"solid \" + mesh.name + \"\\r\\n\";\r\n }\r\n if (!doNotBakeTransform && mesh instanceof Mesh) {\r\n mesh.bakeCurrentTransformIntoVertices();\r\n }\r\n const vertices = getVerticesData(mesh);\r\n const indices = mesh.getIndices() || [];\r\n\r\n for (let i = 0; i < indices.length; i += 3) {\r\n const fd = getFaceData(indices, vertices, i);\r\n\r\n if (binary) {\r\n offset = writeVector(data, offset, fd.n, isLittleEndian);\r\n offset = writeVector(data, offset, fd.v[0], isLittleEndian);\r\n offset = writeVector(data, offset, fd.v[1], isLittleEndian);\r\n offset = writeVector(data, offset, fd.v[2], isLittleEndian);\r\n offset += 2;\r\n } else {\r\n data += \"\\tfacet normal \" + fd.n.x + \" \" + fd.n.y + \" \" + fd.n.z + \"\\r\\n\";\r\n data += \"\\t\\touter loop\\r\\n\";\r\n data += \"\\t\\t\\tvertex \" + fd.v[0].x + \" \" + fd.v[0].y + \" \" + fd.v[0].z + \"\\r\\n\";\r\n data += \"\\t\\t\\tvertex \" + fd.v[1].x + \" \" + fd.v[1].y + \" \" + fd.v[1].z + \"\\r\\n\";\r\n data += \"\\t\\t\\tvertex \" + fd.v[2].x + \" \" + fd.v[2].y + \" \" + fd.v[2].z + \"\\r\\n\";\r\n data += \"\\t\\tendloop\\r\\n\";\r\n data += \"\\tendfacet\\r\\n\";\r\n }\r\n }\r\n if (!binary && exportIndividualMeshes) {\r\n data += \"endsolid \" + name + \"\\r\\n\";\r\n }\r\n }\r\n\r\n if (!binary && !exportIndividualMeshes) {\r\n data += \"endsolid stlmesh\";\r\n }\r\n\r\n if (download) {\r\n const a = document.createElement(\"a\");\r\n const blob = new Blob([data], { type: \"application/octet-stream\" });\r\n a.href = window.URL.createObjectURL(blob);\r\n a.download = fileName + \".stl\";\r\n a.click();\r\n }\r\n\r\n return data;\r\n }\r\n}\r\n"]}
|