summit/frontend/node_modules/three-stdlib/exporters/OBJExporter.cjs.map

1 line
11 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"OBJExporter.cjs","sources":["../../src/exporters/OBJExporter.ts"],"sourcesContent":["import { BufferAttribute, Color, Line, Matrix3, Mesh, Object3D, Points, Vector2, Vector3 } from 'three'\n\nclass OBJExporter {\n private output\n\n private indexVertex\n private indexVertexUvs\n private indexNormals\n\n private vertex\n private color\n private normal\n private uv\n\n private face: string[]\n\n constructor() {\n this.output = ''\n\n this.indexVertex = 0\n this.indexVertexUvs = 0\n this.indexNormals = 0\n\n this.vertex = new Vector3()\n this.color = new Color()\n this.normal = new Vector3()\n this.uv = new Vector2()\n\n this.face = []\n }\n\n public parse(object: Object3D): string {\n object.traverse((child) => {\n if (child instanceof Mesh && child.isMesh) {\n this.parseMesh(child)\n }\n\n if (child instanceof Line && child.isLine) {\n this.parseLine(child)\n }\n\n if (child instanceof Points && child.isPoints) {\n this.parsePoints(child)\n }\n })\n\n return this.output\n }\n\n private parseMesh(mesh: Mesh): void {\n let nbVertex = 0\n let nbNormals = 0\n let nbVertexUvs = 0\n\n const geometry = mesh.geometry\n\n const normalMatrixWorld = new Matrix3()\n\n if (!geometry.isBufferGeometry) {\n throw new Error('THREE.OBJExporter: Geometry is not of type THREE.BufferGeometry.')\n }\n\n // shortcuts\n const vertices = geometry.getAttribute('position')\n const normals = geometry.getAttribute('normal')\n const uvs = geometry.getAttribute('uv')\n const indices = geometry.getIndex()\n\n // name of the mesh object\n this.output += `o ${mesh.name}\\n`\n\n // name of the mesh material\n if (mesh.material && !Array.isArray(mesh.material) && mesh.material.name) {\n this.output += `usemtl ${mesh.material.name}\\n`\n }\n\n // vertices\n\n if (vertices !== undefined) {\n for (let i = 0, l = vertices.count; i < l; i++, nbVertex++) {\n this.vertex.x = vertices.getX(i)\n this.vertex.y = vertices.getY(i)\n this.vertex.z = vertices.getZ(i)\n\n // transform the vertex to world space\n this.vertex.applyMatrix4(mesh.matrixWorld)\n\n // transform the vertex to export format\n this.output += `v ${this.vertex.x} ${this.vertex.y} ${this.vertex.z}\\n`\n }\n }\n\n // uvs\n\n if (uvs !== undefined) {\n for (let i = 0, l = uvs.count; i < l; i++, nbVertexUvs++) {\n this.uv.x = uvs.getX(i)\n this.uv.y = uvs.getY(i)\n\n // transform the uv to export format\n this.output += `vt ${this.uv.x} ${this.uv.y}\\n`\n }\n }\n\n // normals\n\n if (normals !== undefined) {\n normalMatrixWorld.getNormalMatrix(mesh.matrixWorld)\n\n for (let i = 0, l = normals.count; i < l; i++, nbNormals++) {\n this.normal.x = normals.getX(i)\n this.normal.y = normals.getY(i)\n this.normal.z = normals.getZ(i)\n\n // transform the normal to world space\n this.normal.applyMatrix3(normalMatrixWorld).normalize()\n\n // transform the normal to export format\n this.output += `vn ${this.normal.x} ${this.normal.y} ${this.normal.z}\\n`\n }\n }\n\n // faces\n\n if (indices !== null) {\n for (let i = 0, l = indices.count; i < l; i += 3) {\n for (let m = 0; m < 3; m++) {\n const j = indices.getX(i + m) + 1\n\n this.face[m] =\n this.indexVertex +\n j +\n (normals || uvs\n ? `/${uvs ? this.indexVertexUvs + j : ''}${normals ? `/${this.indexNormals + j}` : ''}`\n : '')\n }\n\n // transform the face to export format\n this.output += `f ${this.face.join(' ')}\\n`\n }\n } else {\n for (let i = 0, l = vertices.count; i < l; i += 3) {\n for (let m = 0; m < 3; m++) {\n const j = i + m + 1\n\n this.face[m] =\n this.indexVertex +\n j +\n (normals || uvs\n