1 line
10 KiB
Plaintext
1 line
10 KiB
Plaintext
|
|
{"version":3,"file":"DRACOExporter.cjs","sources":["../../src/exporters/DRACOExporter.js"],"sourcesContent":["import { BufferGeometry, Mesh, Points } from 'three'\n\n/**\n * Export draco compressed files from threejs geometry objects.\n *\n * Draco files are compressed and usually are smaller than conventional 3D file formats.\n *\n * The exporter receives a options object containing\n * - decodeSpeed, indicates how to tune the encoder regarding decode speed (0 gives better speed but worst quality)\n * - encodeSpeed, indicates how to tune the encoder parameters (0 gives better speed but worst quality)\n * - encoderMethod\n * - quantization, indicates the presision of each type of data stored in the draco file in the order (POSITION, NORMAL, COLOR, TEX_COORD, GENERIC)\n * - exportUvs\n * - exportNormals\n */\n\nconst DRACOExporter = /* @__PURE__ */ (() => {\n class DRACOExporter {\n // Encoder methods\n\n static MESH_EDGEBREAKER_ENCODING = 1\n static MESH_SEQUENTIAL_ENCODING = 0\n\n // Geometry type\n\n static POINT_CLOUD = 0\n static TRIANGULAR_MESH = 1\n\n // Attribute type\n static INVALID = -1\n static POSITION = 0\n static NORMAL = 1\n static COLOR = 2\n static TEX_COORD = 3\n static GENERIC = 4\n\n parse(\n object,\n options = {\n decodeSpeed: 5,\n encodeSpeed: 5,\n encoderMethod: DRACOExporter.MESH_EDGEBREAKER_ENCODING,\n quantization: [16, 8, 8, 8, 8],\n exportUvs: true,\n exportNormals: true,\n exportColor: false,\n },\n ) {\n if (object instanceof BufferGeometry && object.isBufferGeometry) {\n throw new Error('DRACOExporter: The first parameter of parse() is now an instance of Mesh or Points.')\n }\n\n if (DracoEncoderModule === undefined) {\n throw new Error('THREE.DRACOExporter: required the draco_encoder to work.')\n }\n\n const geometry = object.geometry\n\n const dracoEncoder = DracoEncoderModule()\n const encoder = new dracoEncoder.Encoder()\n let builder\n let dracoObject\n\n if (!geometry.isBufferGeometry) {\n throw new Error(\n 'THREE.DRACOExporter.parse(geometry, options): geometry is not a THREE.BufferGeometry instance.',\n )\n }\n\n if (object instanceof Mesh && object.isMesh) {\n builder = new dracoEncoder.MeshBuilder()\n dracoObject = new dracoEncoder.Mesh()\n\n const vertices = geometry.getAttribute('position')\n // @ts-ignore\n builder.AddFloatAttributeToMesh(\n dracoObject,\n dracoEncoder.POSITION,\n vertices.count,\n vertices.itemSize,\n vertices.array,\n )\n\n const faces = geometry.getIndex()\n\n if (faces !== null) {\n builder.AddFacesToMesh(dracoObject, faces.count / 3, faces.array)\n } else {\n const faces = new (vertices.count > 65535 ? Uint32Array : Uint16Array)(vertices.count)\n\n for (let i = 0; i < faces.length; i++) {\n faces[i] = i\n }\n\n builder.AddFacesToMesh(dracoObject, vertices.count, faces)\n }\n\n if (options.exportNormals) {\n const normals = geometry.getAttribute('normal')\n\n if (normals !== undefined) {\n // @ts-ignore\n builder.AddFloatAttributeToMesh(\n dracoObject,\n dracoEncoder.NORMAL,\n normals.count,\n normals.itemSize,\n normals.array,\n )\n }\n }\n\n if (options.exportUvs) {\n const uvs = geometry.getAttribute('uv')\n\n if (uvs !== undefined) {\n // @ts-ignore\n builder.AddFloatAttributeToMesh(dracoObject, dracoEncoder.TEX_COORD, uvs.count, uvs.itemSize, uvs.array)\n }\n }\n\n if (options.exportColor) {\n const colors = geometry.getAttribute('color')\n\n if (colors !== undefined) {\n // @ts-ignore\n builder.AddFloatAttributeToMesh(\n
|