three-stdlib 2.28.5 → 2.28.6

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,145 +1,124 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => {
5
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
- return value;
7
- };
8
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
3
  const THREE = require("three");
10
4
  class STLExporter {
11
- constructor() {
12
- __publicField(this, "binary");
13
- __publicField(this, "output");
14
- __publicField(this, "offset");
15
- __publicField(this, "objects");
16
- __publicField(this, "triangles");
17
- __publicField(this, "vA");
18
- __publicField(this, "vB");
19
- __publicField(this, "vC");
20
- __publicField(this, "cb");
21
- __publicField(this, "ab");
22
- __publicField(this, "normal");
23
- this.binary = false;
24
- this.output = "";
25
- this.offset = 80;
26
- this.objects = [];
27
- this.triangles = 0;
28
- this.vA = new THREE.Vector3();
29
- this.vB = new THREE.Vector3();
30
- this.vC = new THREE.Vector3();
31
- this.cb = new THREE.Vector3();
32
- this.ab = new THREE.Vector3();
33
- this.normal = new THREE.Vector3();
34
- }
35
- parse(scene, options) {
36
- this.binary = options.binary !== void 0 ? options.binary : false;
37
- scene.traverse((object) => {
38
- if (object instanceof THREE.Mesh && object.isMesh) {
5
+ parse(scene, options = {}) {
6
+ options = Object.assign(
7
+ {
8
+ binary: false
9
+ },
10
+ options
11
+ );
12
+ const binary = options.binary;
13
+ const objects = [];
14
+ let triangles = 0;
15
+ scene.traverse(function(object) {
16
+ if (object.isMesh) {
39
17
  const geometry = object.geometry;
40
- if (!geometry.isBufferGeometry) {
41
- throw new Error("THREE.STLExporter: Geometry is not of type THREE.BufferGeometry.");
42
- }
43
18
  const index = geometry.index;
44
19
  const positionAttribute = geometry.getAttribute("position");
45
- this.triangles += index !== null ? index.count / 3 : positionAttribute.count / 3;
46
- this.objects.push({
20
+ triangles += index !== null ? index.count / 3 : positionAttribute.count / 3;
21
+ objects.push({
47
22
  object3d: object,
48
23
  geometry
49
24
  });
50
25
  }
51
26
  });
52
- if (this.binary) {
53
- const bufferLength = this.triangles * 2 + this.triangles * 3 * 4 * 4 + 80 + 4;
27
+ let output;
28
+ let offset = 80;
29
+ if (binary === true) {
30
+ const bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4;
54
31
  const arrayBuffer = new ArrayBuffer(bufferLength);
55
- this.output = new DataView(arrayBuffer);
56
- this.output.setUint32(this.offset, this.triangles, true);
57
- this.offset += 4;
32
+ output = new DataView(arrayBuffer);
33
+ output.setUint32(offset, triangles, true);
34
+ offset += 4;
58
35
  } else {
59
- this.output = "";
60
- this.output += "solid exported\n";
36
+ output = "";
37
+ output += "solid exported\n";
61
38
  }
62
- for (let i = 0, il = this.objects.length; i < il; i++) {
63
- const object = this.objects[i].object3d;
64
- const geometry = this.objects[i].geometry;
39
+ const vA = new THREE.Vector3();
40
+ const vB = new THREE.Vector3();
41
+ const vC = new THREE.Vector3();
42
+ const cb = new THREE.Vector3();
43
+ const ab = new THREE.Vector3();
44
+ const normal = new THREE.Vector3();
45
+ for (let i = 0, il = objects.length; i < il; i++) {
46
+ const object = objects[i].object3d;
47
+ const geometry = objects[i].geometry;
65
48
  const index = geometry.index;
66
49
  const positionAttribute = geometry.getAttribute("position");
67
- if (object instanceof THREE.SkinnedMesh) {
68
- if (index !== null) {
69
- for (let j = 0; j < index.count; j += 3) {
70
- const a = index.getX(j + 0);
71
- const b = index.getX(j + 1);
72
- const c = index.getX(j + 2);
73
- this.writeFace(a, b, c, positionAttribute, object);
74
- }
75
- } else {
76
- for (let j = 0; j < positionAttribute.count; j += 3) {
77
- const a = j + 0;
78
- const b = j + 1;
79
- const c = j + 2;
80
- this.writeFace(a, b, c, positionAttribute, object);
81
- }
50
+ if (index !== null) {
51
+ for (let j = 0; j < index.count; j += 3) {
52
+ const a = index.getX(j + 0);
53
+ const b = index.getX(j + 1);
54
+ const c = index.getX(j + 2);
55
+ writeFace(a, b, c, positionAttribute, object);
56
+ }
57
+ } else {
58
+ for (let j = 0; j < positionAttribute.count; j += 3) {
59
+ const a = j + 0;
60
+ const b = j + 1;
61
+ const c = j + 2;
62
+ writeFace(a, b, c, positionAttribute, object);
82
63
  }
83
64
  }
84
65
  }
85
- if (!this.binary) {
86
- this.output += "endsolid exported\n";
66
+ if (binary === false) {
67
+ output += "endsolid exported\n";
87
68
  }
88
- return this.output;
89
- }
90
- writeFace(a, b, c, positionAttribute, object) {
91
- this.vA.fromBufferAttribute(positionAttribute, a);
92
- this.vB.fromBufferAttribute(positionAttribute, b);
93
- this.vC.fromBufferAttribute(positionAttribute, c);
94
- if (object.isSkinnedMesh) {
95
- object.boneTransform(a, this.vA);
96
- object.boneTransform(b, this.vB);
97
- object.boneTransform(c, this.vC);
98
- }
99
- this.vA.applyMatrix4(object.matrixWorld);
100
- this.vB.applyMatrix4(object.matrixWorld);
101
- this.vC.applyMatrix4(object.matrixWorld);
102
- this.writeNormal(this.vA, this.vB, this.vC);
103
- this.writeVertex(this.vA);
104
- this.writeVertex(this.vB);
105
- this.writeVertex(this.vC);
106
- if (this.binary && this.output instanceof DataView) {
107
- this.output.setUint16(this.offset, 0, true);
108
- this.offset += 2;
109
- } else {
110
- this.output += " endloop\n";
111
- this.output += " endfacet\n";
69
+ return output;
70
+ function writeFace(a, b, c, positionAttribute, object) {
71
+ vA.fromBufferAttribute(positionAttribute, a);
72
+ vB.fromBufferAttribute(positionAttribute, b);
73
+ vC.fromBufferAttribute(positionAttribute, c);
74
+ if (object.isSkinnedMesh === true) {
75
+ object.applyBoneTransform(a, vA);
76
+ object.applyBoneTransform(b, vB);
77
+ object.applyBoneTransform(c, vC);
78
+ }
79
+ vA.applyMatrix4(object.matrixWorld);
80
+ vB.applyMatrix4(object.matrixWorld);
81
+ vC.applyMatrix4(object.matrixWorld);
82
+ writeNormal(vA, vB, vC);
83
+ writeVertex(vA);
84
+ writeVertex(vB);
85
+ writeVertex(vC);
86
+ if (binary === true) {
87
+ output.setUint16(offset, 0, true);
88
+ offset += 2;
89
+ } else {
90
+ output += " endloop\n";
91
+ output += " endfacet\n";
92
+ }
112
93
  }
113
- }
114
- writeNormal(vA, vB, vC) {
115
- this.cb.subVectors(vC, vB);
116
- this.ab.subVectors(vA, vB);
117
- this.cb.cross(this.ab).normalize();
118
- this.normal.copy(this.cb).normalize();
119
- if (this.binary && this.output instanceof DataView) {
120
- this.output.setFloat32(this.offset, this.normal.x, true);
121
- this.offset += 4;
122
- this.output.setFloat32(this.offset, this.normal.y, true);
123
- this.offset += 4;
124
- this.output.setFloat32(this.offset, this.normal.z, true);
125
- this.offset += 4;
126
- } else {
127
- this.output += ` facet normal ${this.normal.x} ${this.normal.y} ${this.normal.z}
128
- `;
129
- this.output += " outer loop\n";
94
+ function writeNormal(vA2, vB2, vC2) {
95
+ cb.subVectors(vC2, vB2);
96
+ ab.subVectors(vA2, vB2);
97
+ cb.cross(ab).normalize();
98
+ normal.copy(cb).normalize();
99
+ if (binary === true) {
100
+ output.setFloat32(offset, normal.x, true);
101
+ offset += 4;
102
+ output.setFloat32(offset, normal.y, true);
103
+ offset += 4;
104
+ output.setFloat32(offset, normal.z, true);
105
+ offset += 4;
106
+ } else {
107
+ output += " facet normal " + normal.x + " " + normal.y + " " + normal.z + "\n";
108
+ output += " outer loop\n";
109
+ }
130
110
  }
131
- }
132
- writeVertex(vertex) {
133
- if (this.binary && this.output instanceof DataView) {
134
- this.output.setFloat32(this.offset, vertex.x, true);
135
- this.offset += 4;
136
- this.output.setFloat32(this.offset, vertex.y, true);
137
- this.offset += 4;
138
- this.output.setFloat32(this.offset, vertex.z, true);
139
- this.offset += 4;
140
- } else {
141
- this.output += ` vertex vertex.x vertex.y vertex.z
142
- `;
111
+ function writeVertex(vertex) {
112
+ if (binary === true) {
113
+ output.setFloat32(offset, vertex.x, true);
114
+ offset += 4;
115
+ output.setFloat32(offset, vertex.y, true);
116
+ offset += 4;
117
+ output.setFloat32(offset, vertex.z, true);
118
+ offset += 4;
119
+ } else {
120
+ output += " vertex " + vertex.x + " " + vertex.y + " " + vertex.z + "\n";
121
+ }
143
122
  }
144
123
  }
145
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"STLExporter.cjs","sources":["../../src/exporters/STLExporter.ts"],"sourcesContent":["import { BufferAttribute, InterleavedBufferAttribute, Mesh, Object3D, PlaneGeometry, SkinnedMesh, Vector3 } from 'three'\n\n/**\n * Usage:\n * const exporter = new STLExporter();\n *\n * // second argument is a list of options\n * const data = exporter.parse( mesh, { binary: true } );\n *\n */\n\n// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f7ec78508c6797e42f87a4390735bc2c650a1bfd/types/three/examples/jsm/exporters/STLExporter.d.ts\nexport interface STLExporterOptions {\n binary?: boolean\n}\n\nclass STLExporter {\n private binary\n\n private output: string | DataView\n private offset\n\n private objects: { object3d: Object3D; geometry: PlaneGeometry }[]\n private triangles\n\n private vA\n private vB\n private vC\n private cb\n private ab\n private normal\n\n constructor() {\n this.binary = false\n\n this.output = ''\n this.offset = 80 // skip header\n\n this.objects = []\n this.triangles = 0\n\n this.vA = new Vector3()\n this.vB = new Vector3()\n this.vC = new Vector3()\n this.cb = new Vector3()\n this.ab = new Vector3()\n this.normal = new Vector3()\n }\n\n public parse(scene: Object3D, options: STLExporterOptions): string | DataView {\n this.binary = options.binary !== undefined ? options.binary : false\n\n //\n\n scene.traverse((object) => {\n if (object instanceof Mesh && object.isMesh) {\n const geometry = object.geometry\n\n if (!geometry.isBufferGeometry) {\n throw new Error('THREE.STLExporter: Geometry is not of type THREE.BufferGeometry.')\n }\n\n const index = geometry.index\n const positionAttribute = geometry.getAttribute('position')\n\n this.triangles += index !== null ? index.count / 3 : positionAttribute.count / 3\n\n this.objects.push({\n object3d: object,\n geometry: geometry,\n })\n }\n })\n\n if (this.binary) {\n const bufferLength = this.triangles * 2 + this.triangles * 3 * 4 * 4 + 80 + 4\n const arrayBuffer = new ArrayBuffer(bufferLength)\n this.output = new DataView(arrayBuffer)\n this.output.setUint32(this.offset, this.triangles, true)\n this.offset += 4\n } else {\n this.output = ''\n this.output += 'solid exported\\n'\n }\n\n for (let i = 0, il = this.objects.length; i < il; i++) {\n const object = this.objects[i].object3d\n const geometry = this.objects[i].geometry\n\n const index = geometry.index\n const positionAttribute = geometry.getAttribute('position')\n\n if (object instanceof SkinnedMesh) {\n if (index !== null) {\n // indexed geometry\n\n for (let j = 0; j < index.count; j += 3) {\n const a = index.getX(j + 0)\n const b = index.getX(j + 1)\n const c = index.getX(j + 2)\n\n this.writeFace(a, b, c, positionAttribute, object)\n }\n } else {\n // non-indexed geometry\n\n for (let j = 0; j < positionAttribute.count; j += 3) {\n const a = j + 0\n const b = j + 1\n const c = j + 2\n\n this.writeFace(a, b, c, positionAttribute, object)\n }\n }\n }\n }\n\n if (!this.binary) {\n this.output += 'endsolid exported\\n'\n }\n\n return this.output\n }\n\n private writeFace(\n a: number,\n b: number,\n c: number,\n positionAttribute: BufferAttribute | InterleavedBufferAttribute,\n object: SkinnedMesh,\n ): void {\n this.vA.fromBufferAttribute(positionAttribute, a)\n this.vB.fromBufferAttribute(positionAttribute, b)\n this.vC.fromBufferAttribute(positionAttribute, c)\n\n if (object.isSkinnedMesh) {\n object.boneTransform(a, this.vA)\n object.boneTransform(b, this.vB)\n object.boneTransform(c, this.vC)\n }\n\n this.vA.applyMatrix4(object.matrixWorld)\n this.vB.applyMatrix4(object.matrixWorld)\n this.vC.applyMatrix4(object.matrixWorld)\n\n this.writeNormal(this.vA, this.vB, this.vC)\n\n this.writeVertex(this.vA)\n this.writeVertex(this.vB)\n this.writeVertex(this.vC)\n\n if (this.binary && this.output instanceof DataView) {\n this.output.setUint16(this.offset, 0, true)\n this.offset += 2\n } else {\n this.output += '\\t\\tendloop\\n'\n this.output += '\\tendfacet\\n'\n }\n }\n\n private writeNormal(vA: Vector3, vB: Vector3, vC: Vector3): void {\n this.cb.subVectors(vC, vB)\n this.ab.subVectors(vA, vB)\n this.cb.cross(this.ab).normalize()\n\n this.normal.copy(this.cb).normalize()\n\n if (this.binary && this.output instanceof DataView) {\n this.output.setFloat32(this.offset, this.normal.x, true)\n this.offset += 4\n this.output.setFloat32(this.offset, this.normal.y, true)\n this.offset += 4\n this.output.setFloat32(this.offset, this.normal.z, true)\n this.offset += 4\n } else {\n this.output += `\\tfacet normal ${this.normal.x} ${this.normal.y} ${this.normal.z}\\n`\n this.output += '\\t\\touter loop\\n'\n }\n }\n\n private writeVertex(vertex: Vector3): void {\n if (this.binary && this.output instanceof DataView) {\n this.output.setFloat32(this.offset, vertex.x, true)\n this.offset += 4\n this.output.setFloat32(this.offset, vertex.y, true)\n this.offset += 4\n this.output.setFloat32(this.offset, vertex.z, true)\n this.offset += 4\n } else {\n this.output += `\\t\\t\\tvertex vertex.x vertex.y vertex.z\\n`\n }\n }\n}\n\nexport { STLExporter }\n"],"names":["Vector3","Mesh","SkinnedMesh"],"mappings":";;;;;;;;;AAgBA,MAAM,YAAY;AAAA,EAgBhB,cAAc;AAfN;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAGN,SAAK,SAAS;AAEd,SAAK,SAAS;AACd,SAAK,SAAS;AAEd,SAAK,UAAU;AACf,SAAK,YAAY;AAEZ,SAAA,KAAK,IAAIA,MAAAA;AACT,SAAA,KAAK,IAAIA,MAAAA;AACT,SAAA,KAAK,IAAIA,MAAAA;AACT,SAAA,KAAK,IAAIA,MAAAA;AACT,SAAA,KAAK,IAAIA,MAAAA;AACT,SAAA,SAAS,IAAIA,MAAAA;EACpB;AAAA,EAEO,MAAM,OAAiB,SAAgD;AAC5E,SAAK,SAAS,QAAQ,WAAW,SAAY,QAAQ,SAAS;AAIxD,UAAA,SAAS,CAAC,WAAW;AACrB,UAAA,kBAAkBC,MAAAA,QAAQ,OAAO,Q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AAE1B,QAAI,KAAK,UAAU,KAAK,kBAAkB,UAAU;AAClD,WAAK,OAAO,WAAW,KAAK,QAAQ,KAAK,OAAO,GAAG,IAAI;AACvD,WAAK,UAAU;AACf,WAAK,OAAO,WAAW,KAAK,QAAQ,KAAK,OAAO,GAAG,IAAI;AACvD,WAAK,UAAU;AACf,WAAK,OAAO,WAAW,KAAK,QAAQ,KAAK,OAAO,GAAG,IAAI;AACvD,WAAK,UAAU;AAAA,IAAA,OACV;AACA,WAAA,UAAU,iBAAkB,KAAK,OAAO,KAAK,KAAK,OAAO,KAAK,KAAK,OAAO;AAAA;AAC/E,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AAAA,EAEQ,YAAY,QAAuB;AACzC,QAAI,KAAK,UAAU,KAAK,kBAAkB,UAAU;AAClD,WAAK,OAAO,WAAW,KAAK,QAAQ,OAAO,GAAG,IAAI;AAClD,WAAK,UAAU;AACf,WAAK,OAAO,WAAW,KAAK,QAAQ,OAAO,GAAG,IAAI;AAClD,WAAK,UAAU;AACf,WAAK,OAAO,WAAW,KAAK,QAAQ,OAAO,GAAG,IAAI;AAClD,WAAK,UAAU;AAAA,IAAA,OACV;AACL,WAAK,UAAU;AAAA;AAAA,IACjB;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"STLExporter.cjs","sources":["../../src/exporters/STLExporter.js"],"sourcesContent":["import { Vector3 } from 'three'\n\n/**\n * Usage:\n * const exporter = new STLExporter();\n *\n * // second argument is a list of options\n * const data = exporter.parse( mesh, { binary: true } );\n *\n */\n\nclass STLExporter {\n parse(scene, options = {}) {\n options = Object.assign(\n {\n binary: false,\n },\n options,\n )\n\n const binary = options.binary\n\n //\n\n const objects = []\n let triangles = 0\n\n scene.traverse(function (object) {\n if (object.isMesh) {\n const geometry = object.geometry\n\n const index = geometry.index\n const positionAttribute = geometry.getAttribute('position')\n\n triangles += index !== null ? index.count / 3 : positionAttribute.count / 3\n\n objects.push({\n object3d: object,\n geometry: geometry,\n })\n }\n })\n\n let output\n let offset = 80 // skip header\n\n if (binary === true) {\n const bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4\n const arrayBuffer = new ArrayBuffer(bufferLength)\n output = new DataView(arrayBuffer)\n output.setUint32(offset, triangles, true)\n offset += 4\n } else {\n output = ''\n output += 'solid exported\\n'\n }\n\n const vA = new Vector3()\n const vB = new Vector3()\n const vC = new Vector3()\n const cb = new Vector3()\n const ab = new Vector3()\n const normal = new Vector3()\n\n for (let i = 0, il = objects.length; i < il; i++) {\n const object = objects[i].object3d\n const geometry = objects[i].geometry\n\n const index = geometry.index\n const positionAttribute = geometry.getAttribute('position')\n\n if (index !== null) {\n // indexed geometry\n\n for (let j = 0; j < index.count; j += 3) {\n const a = index.getX(j + 0)\n const b = index.getX(j + 1)\n const c = index.getX(j + 2)\n\n writeFace(a, b, c, positionAttribute, object)\n }\n } else {\n // non-indexed geometry\n\n for (let j = 0; j < positionAttribute.count; j += 3) {\n const a = j + 0\n const b = j + 1\n const c = j + 2\n\n writeFace(a, b, c, positionAttribute, object)\n }\n }\n }\n\n if (binary === false) {\n output += 'endsolid exported\\n'\n }\n\n return output\n\n function writeFace(a, b, c, positionAttribute, object) {\n vA.fromBufferAttribute(positionAttribute, a)\n vB.fromBufferAttribute(positionAttribute, b)\n vC.fromBufferAttribute(positionAttribute, c)\n\n if (object.isSkinnedMesh === true) {\n object.applyBoneTransform(a, vA)\n object.applyBoneTransform(b, vB)\n object.applyBoneTransform(c, vC)\n }\n\n vA.applyMatrix4(object.matrixWorld)\n vB.applyMatrix4(object.matrixWorld)\n vC.applyMatrix4(object.matrixWorld)\n\n writeNormal(vA, vB, vC)\n\n writeVertex(vA)\n writeVertex(vB)\n writeVertex(vC)\n\n if (binary === true) {\n output.setUint16(offset, 0, true)\n offset += 2\n } else {\n output += '\\t\\tendloop\\n'\n output += '\\tendfacet\\n'\n }\n }\n\n function writeNormal(vA, vB, vC) {\n cb.subVectors(vC, vB)\n ab.subVectors(vA, vB)\n cb.cross(ab).normalize()\n\n normal.copy(cb).normalize()\n\n if (binary === true) {\n output.setFloat32(offset, normal.x, true)\n offset += 4\n output.setFloat32(offset, normal.y, true)\n offset += 4\n output.setFloat32(offset, normal.z, true)\n offset += 4\n } else {\n output += '\\tfacet normal ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\\n'\n output += '\\t\\touter loop\\n'\n }\n }\n\n function writeVertex(vertex) {\n if (binary === true) {\n output.setFloat32(offset, vertex.x, true)\n offset += 4\n output.setFloat32(offset, vertex.y, true)\n offset += 4\n output.setFloat32(offset, vertex.z, true)\n offset += 4\n } else {\n output += '\\t\\t\\tvertex ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\\n'\n }\n }\n }\n}\n\nexport { STLExporter }\n"],"names":["Vector3","vA","vB","vC"],"mappings":";;;AAWA,MAAM,YAAY;AAAA,EAChB,MAAM,OAAO,UAAU,IAAI;AACzB,cAAU,OAAO;AAAA,MACf;AAAA,QACE,QAAQ;AAAA,MACT;AAAA,MACD;AAAA,IACD;AAED,UAAM,SAAS,QAAQ;AAIvB,UAAM,UAAU,CAAE;AAClB,QAAI,YAAY;AAEhB,UAAM,SAAS,SAAU,QAAQ;AAC/B,UAAI,OAAO,QAAQ;AACjB,cAAM,WAAW,OAAO;AAExB,cAAM,QAAQ,SAAS;AACvB,cAAM,oBAAoB,SAAS,aAAa,UAAU;AAE1D,qBAAa,UAAU,OAAO,MAAM,QAAQ,IAAI,kBAAkB,QAAQ;AAE1E,gBAAQ,KAAK;AAAA,UACX,UAAU;AAAA,UACV;AAAA,QACV,CAAS;AAAA,MACF;AAAA,IACP,CAAK;AAED,QAAI;AACJ,QAAI,SAAS;AAEb,QAAI,WAAW,MAAM;AACnB,YAAM,eAAe,YAAY,IAAI,YAAY,IAAI,IAAI,IAAI,KAAK;AAClE,YAAM,cAAc,IAAI,YAAY,YAAY;AAChD,eAAS,IAAI,SAAS,WAAW;AACjC,aAAO,UAAU,QAAQ,WAAW,IAAI;AACxC,g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}
@@ -1,31 +1,21 @@
1
- import { Object3D } from 'three';
2
- /**
3
- * Usage:
4
- * const exporter = new STLExporter();
5
- *
6
- * // second argument is a list of options
7
- * const data = exporter.parse( mesh, { binary: true } );
8
- *
9
- */
1
+ import { Object3D } from 'three'
2
+
3
+ export interface STLExporterOptionsBinary {
4
+ binary: true
5
+ }
6
+
7
+ export interface STLExporterOptionsString {
8
+ binary?: false
9
+ }
10
+
10
11
  export interface STLExporterOptions {
11
- binary?: boolean;
12
+ binary?: boolean
12
13
  }
13
- declare class STLExporter {
14
- private binary;
15
- private output;
16
- private offset;
17
- private objects;
18
- private triangles;
19
- private vA;
20
- private vB;
21
- private vC;
22
- private cb;
23
- private ab;
24
- private normal;
25
- constructor();
26
- parse(scene: Object3D, options: STLExporterOptions): string | DataView;
27
- private writeFace;
28
- private writeNormal;
29
- private writeVertex;
14
+
15
+ export class STLExporter {
16
+ constructor()
17
+
18
+ parse(scene: Object3D, options: STLExporterOptionsBinary): DataView
19
+ parse(scene: Object3D, options?: STLExporterOptionsString): string
20
+ parse(scene: Object3D, options?: STLExporterOptions): string | DataView
30
21
  }
31
- export { STLExporter };
@@ -1,143 +1,122 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- import { Vector3, Mesh, SkinnedMesh } from "three";
1
+ import { Vector3 } from "three";
8
2
  class STLExporter {
9
- constructor() {
10
- __publicField(this, "binary");
11
- __publicField(this, "output");
12
- __publicField(this, "offset");
13
- __publicField(this, "objects");
14
- __publicField(this, "triangles");
15
- __publicField(this, "vA");
16
- __publicField(this, "vB");
17
- __publicField(this, "vC");
18
- __publicField(this, "cb");
19
- __publicField(this, "ab");
20
- __publicField(this, "normal");
21
- this.binary = false;
22
- this.output = "";
23
- this.offset = 80;
24
- this.objects = [];
25
- this.triangles = 0;
26
- this.vA = new Vector3();
27
- this.vB = new Vector3();
28
- this.vC = new Vector3();
29
- this.cb = new Vector3();
30
- this.ab = new Vector3();
31
- this.normal = new Vector3();
32
- }
33
- parse(scene, options) {
34
- this.binary = options.binary !== void 0 ? options.binary : false;
35
- scene.traverse((object) => {
36
- if (object instanceof Mesh && object.isMesh) {
3
+ parse(scene, options = {}) {
4
+ options = Object.assign(
5
+ {
6
+ binary: false
7
+ },
8
+ options
9
+ );
10
+ const binary = options.binary;
11
+ const objects = [];
12
+ let triangles = 0;
13
+ scene.traverse(function(object) {
14
+ if (object.isMesh) {
37
15
  const geometry = object.geometry;
38
- if (!geometry.isBufferGeometry) {
39
- throw new Error("THREE.STLExporter: Geometry is not of type THREE.BufferGeometry.");
40
- }
41
16
  const index = geometry.index;
42
17
  const positionAttribute = geometry.getAttribute("position");
43
- this.triangles += index !== null ? index.count / 3 : positionAttribute.count / 3;
44
- this.objects.push({
18
+ triangles += index !== null ? index.count / 3 : positionAttribute.count / 3;
19
+ objects.push({
45
20
  object3d: object,
46
21
  geometry
47
22
  });
48
23
  }
49
24
  });
50
- if (this.binary) {
51
- const bufferLength = this.triangles * 2 + this.triangles * 3 * 4 * 4 + 80 + 4;
25
+ let output;
26
+ let offset = 80;
27
+ if (binary === true) {
28
+ const bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4;
52
29
  const arrayBuffer = new ArrayBuffer(bufferLength);
53
- this.output = new DataView(arrayBuffer);
54
- this.output.setUint32(this.offset, this.triangles, true);
55
- this.offset += 4;
30
+ output = new DataView(arrayBuffer);
31
+ output.setUint32(offset, triangles, true);
32
+ offset += 4;
56
33
  } else {
57
- this.output = "";
58
- this.output += "solid exported\n";
34
+ output = "";
35
+ output += "solid exported\n";
59
36
  }
60
- for (let i = 0, il = this.objects.length; i < il; i++) {
61
- const object = this.objects[i].object3d;
62
- const geometry = this.objects[i].geometry;
37
+ const vA = new Vector3();
38
+ const vB = new Vector3();
39
+ const vC = new Vector3();
40
+ const cb = new Vector3();
41
+ const ab = new Vector3();
42
+ const normal = new Vector3();
43
+ for (let i = 0, il = objects.length; i < il; i++) {
44
+ const object = objects[i].object3d;
45
+ const geometry = objects[i].geometry;
63
46
  const index = geometry.index;
64
47
  const positionAttribute = geometry.getAttribute("position");
65
- if (object instanceof SkinnedMesh) {
66
- if (index !== null) {
67
- for (let j = 0; j < index.count; j += 3) {
68
- const a = index.getX(j + 0);
69
- const b = index.getX(j + 1);
70
- const c = index.getX(j + 2);
71
- this.writeFace(a, b, c, positionAttribute, object);
72
- }
73
- } else {
74
- for (let j = 0; j < positionAttribute.count; j += 3) {
75
- const a = j + 0;
76
- const b = j + 1;
77
- const c = j + 2;
78
- this.writeFace(a, b, c, positionAttribute, object);
79
- }
48
+ if (index !== null) {
49
+ for (let j = 0; j < index.count; j += 3) {
50
+ const a = index.getX(j + 0);
51
+ const b = index.getX(j + 1);
52
+ const c = index.getX(j + 2);
53
+ writeFace(a, b, c, positionAttribute, object);
54
+ }
55
+ } else {
56
+ for (let j = 0; j < positionAttribute.count; j += 3) {
57
+ const a = j + 0;
58
+ const b = j + 1;
59
+ const c = j + 2;
60
+ writeFace(a, b, c, positionAttribute, object);
80
61
  }
81
62
  }
82
63
  }
83
- if (!this.binary) {
84
- this.output += "endsolid exported\n";
64
+ if (binary === false) {
65
+ output += "endsolid exported\n";
85
66
  }
86
- return this.output;
87
- }
88
- writeFace(a, b, c, positionAttribute, object) {
89
- this.vA.fromBufferAttribute(positionAttribute, a);
90
- this.vB.fromBufferAttribute(positionAttribute, b);
91
- this.vC.fromBufferAttribute(positionAttribute, c);
92
- if (object.isSkinnedMesh) {
93
- object.boneTransform(a, this.vA);
94
- object.boneTransform(b, this.vB);
95
- object.boneTransform(c, this.vC);
96
- }
97
- this.vA.applyMatrix4(object.matrixWorld);
98
- this.vB.applyMatrix4(object.matrixWorld);
99
- this.vC.applyMatrix4(object.matrixWorld);
100
- this.writeNormal(this.vA, this.vB, this.vC);
101
- this.writeVertex(this.vA);
102
- this.writeVertex(this.vB);
103
- this.writeVertex(this.vC);
104
- if (this.binary && this.output instanceof DataView) {
105
- this.output.setUint16(this.offset, 0, true);
106
- this.offset += 2;
107
- } else {
108
- this.output += " endloop\n";
109
- this.output += " endfacet\n";
67
+ return output;
68
+ function writeFace(a, b, c, positionAttribute, object) {
69
+ vA.fromBufferAttribute(positionAttribute, a);
70
+ vB.fromBufferAttribute(positionAttribute, b);
71
+ vC.fromBufferAttribute(positionAttribute, c);
72
+ if (object.isSkinnedMesh === true) {
73
+ object.applyBoneTransform(a, vA);
74
+ object.applyBoneTransform(b, vB);
75
+ object.applyBoneTransform(c, vC);
76
+ }
77
+ vA.applyMatrix4(object.matrixWorld);
78
+ vB.applyMatrix4(object.matrixWorld);
79
+ vC.applyMatrix4(object.matrixWorld);
80
+ writeNormal(vA, vB, vC);
81
+ writeVertex(vA);
82
+ writeVertex(vB);
83
+ writeVertex(vC);
84
+ if (binary === true) {
85
+ output.setUint16(offset, 0, true);
86
+ offset += 2;
87
+ } else {
88
+ output += " endloop\n";
89
+ output += " endfacet\n";
90
+ }
110
91
  }
111
- }
112
- writeNormal(vA, vB, vC) {
113
- this.cb.subVectors(vC, vB);
114
- this.ab.subVectors(vA, vB);
115
- this.cb.cross(this.ab).normalize();
116
- this.normal.copy(this.cb).normalize();
117
- if (this.binary && this.output instanceof DataView) {
118
- this.output.setFloat32(this.offset, this.normal.x, true);
119
- this.offset += 4;
120
- this.output.setFloat32(this.offset, this.normal.y, true);
121
- this.offset += 4;
122
- this.output.setFloat32(this.offset, this.normal.z, true);
123
- this.offset += 4;
124
- } else {
125
- this.output += ` facet normal ${this.normal.x} ${this.normal.y} ${this.normal.z}
126
- `;
127
- this.output += " outer loop\n";
92
+ function writeNormal(vA2, vB2, vC2) {
93
+ cb.subVectors(vC2, vB2);
94
+ ab.subVectors(vA2, vB2);
95
+ cb.cross(ab).normalize();
96
+ normal.copy(cb).normalize();
97
+ if (binary === true) {
98
+ output.setFloat32(offset, normal.x, true);
99
+ offset += 4;
100
+ output.setFloat32(offset, normal.y, true);
101
+ offset += 4;
102
+ output.setFloat32(offset, normal.z, true);
103
+ offset += 4;
104
+ } else {
105
+ output += " facet normal " + normal.x + " " + normal.y + " " + normal.z + "\n";
106
+ output += " outer loop\n";
107
+ }
128
108
  }
129
- }
130
- writeVertex(vertex) {
131
- if (this.binary && this.output instanceof DataView) {
132
- this.output.setFloat32(this.offset, vertex.x, true);
133
- this.offset += 4;
134
- this.output.setFloat32(this.offset, vertex.y, true);
135
- this.offset += 4;
136
- this.output.setFloat32(this.offset, vertex.z, true);
137
- this.offset += 4;
138
- } else {
139
- this.output += ` vertex vertex.x vertex.y vertex.z
140
- `;
109
+ function writeVertex(vertex) {
110
+ if (binary === true) {
111
+ output.setFloat32(offset, vertex.x, true);
112
+ offset += 4;
113
+ output.setFloat32(offset, vertex.y, true);
114
+ offset += 4;
115
+ output.setFloat32(offset, vertex.z, true);
116
+ offset += 4;
117
+ } else {
118
+ output += " vertex " + vertex.x + " " + vertex.y + " " + vertex.z + "\n";
119
+ }
141
120
  }
142
121
  }
143
122
  }
@@ -1 +1 @@
1
- {"version":3,"file":"STLExporter.js","sources":["../../src/exporters/STLExporter.ts"],"sourcesContent":["import { BufferAttribute, InterleavedBufferAttribute, Mesh, Object3D, PlaneGeometry, SkinnedMesh, Vector3 } from 'three'\n\n/**\n * Usage:\n * const exporter = new STLExporter();\n *\n * // second argument is a list of options\n * const data = exporter.parse( mesh, { binary: true } );\n *\n */\n\n// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f7ec78508c6797e42f87a4390735bc2c650a1bfd/types/three/examples/jsm/exporters/STLExporter.d.ts\nexport interface STLExporterOptions {\n binary?: boolean\n}\n\nclass STLExporter {\n private binary\n\n private output: string | DataView\n private offset\n\n private objects: { object3d: Object3D; geometry: PlaneGeometry }[]\n private triangles\n\n private vA\n private vB\n private vC\n private cb\n private ab\n private normal\n\n constructor() {\n this.binary = false\n\n this.output = ''\n this.offset = 80 // skip header\n\n this.objects = []\n this.triangles = 0\n\n this.vA = new Vector3()\n this.vB = new Vector3()\n this.vC = new Vector3()\n this.cb = new Vector3()\n this.ab = new Vector3()\n this.normal = new Vector3()\n }\n\n public parse(scene: Object3D, options: STLExporterOptions): string | DataView {\n this.binary = options.binary !== undefined ? options.binary : false\n\n //\n\n scene.traverse((object) => {\n if (object instanceof Mesh && object.isMesh) {\n const geometry = object.geometry\n\n if (!geometry.isBufferGeometry) {\n throw new Error('THREE.STLExporter: Geometry is not of type THREE.BufferGeometry.')\n }\n\n const index = geometry.index\n const positionAttribute = geometry.getAttribute('position')\n\n this.triangles += index !== null ? index.count / 3 : positionAttribute.count / 3\n\n this.objects.push({\n object3d: object,\n geometry: geometry,\n })\n }\n })\n\n if (this.binary) {\n const bufferLength = this.triangles * 2 + this.triangles * 3 * 4 * 4 + 80 + 4\n const arrayBuffer = new ArrayBuffer(bufferLength)\n this.output = new DataView(arrayBuffer)\n this.output.setUint32(this.offset, this.triangles, true)\n this.offset += 4\n } else {\n this.output = ''\n this.output += 'solid exported\\n'\n }\n\n for (let i = 0, il = this.objects.length; i < il; i++) {\n const object = this.objects[i].object3d\n const geometry = this.objects[i].geometry\n\n const index = geometry.index\n const positionAttribute = geometry.getAttribute('position')\n\n if (object instanceof SkinnedMesh) {\n if (index !== null) {\n // indexed geometry\n\n for (let j = 0; j < index.count; j += 3) {\n const a = index.getX(j + 0)\n const b = index.getX(j + 1)\n const c = index.getX(j + 2)\n\n this.writeFace(a, b, c, positionAttribute, object)\n }\n } else {\n // non-indexed geometry\n\n for (let j = 0; j < positionAttribute.count; j += 3) {\n const a = j + 0\n const b = j + 1\n const c = j + 2\n\n this.writeFace(a, b, c, positionAttribute, object)\n }\n }\n }\n }\n\n if (!this.binary) {\n this.output += 'endsolid exported\\n'\n }\n\n return this.output\n }\n\n private writeFace(\n a: number,\n b: number,\n c: number,\n positionAttribute: BufferAttribute | InterleavedBufferAttribute,\n object: SkinnedMesh,\n ): void {\n this.vA.fromBufferAttribute(positionAttribute, a)\n this.vB.fromBufferAttribute(positionAttribute, b)\n this.vC.fromBufferAttribute(positionAttribute, c)\n\n if (object.isSkinnedMesh) {\n object.boneTransform(a, this.vA)\n object.boneTransform(b, this.vB)\n object.boneTransform(c, this.vC)\n }\n\n this.vA.applyMatrix4(object.matrixWorld)\n this.vB.applyMatrix4(object.matrixWorld)\n this.vC.applyMatrix4(object.matrixWorld)\n\n this.writeNormal(this.vA, this.vB, this.vC)\n\n this.writeVertex(this.vA)\n this.writeVertex(this.vB)\n this.writeVertex(this.vC)\n\n if (this.binary && this.output instanceof DataView) {\n this.output.setUint16(this.offset, 0, true)\n this.offset += 2\n } else {\n this.output += '\\t\\tendloop\\n'\n this.output += '\\tendfacet\\n'\n }\n }\n\n private writeNormal(vA: Vector3, vB: Vector3, vC: Vector3): void {\n this.cb.subVectors(vC, vB)\n this.ab.subVectors(vA, vB)\n this.cb.cross(this.ab).normalize()\n\n this.normal.copy(this.cb).normalize()\n\n if (this.binary && this.output instanceof DataView) {\n this.output.setFloat32(this.offset, this.normal.x, true)\n this.offset += 4\n this.output.setFloat32(this.offset, this.normal.y, true)\n this.offset += 4\n this.output.setFloat32(this.offset, this.normal.z, true)\n this.offset += 4\n } else {\n this.output += `\\tfacet normal ${this.normal.x} ${this.normal.y} ${this.normal.z}\\n`\n this.output += '\\t\\touter loop\\n'\n }\n }\n\n private writeVertex(vertex: Vector3): void {\n if (this.binary && this.output instanceof DataView) {\n this.output.setFloat32(this.offset, vertex.x, true)\n this.offset += 4\n this.output.setFloat32(this.offset, vertex.y, true)\n this.offset += 4\n this.output.setFloat32(this.offset, vertex.z, true)\n this.offset += 4\n } else {\n this.output += `\\t\\t\\tvertex vertex.x vertex.y vertex.z\\n`\n }\n }\n}\n\nexport { STLExporter }\n"],"names":[],"mappings":";;;;;;;AAgBA,MAAM,YAAY;AAAA,EAgBhB,cAAc;AAfN;AAEA;AAC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src/exporters/STLExporter.js"],"sourcesContent":["import { Vector3 } from 'three'\n\n/**\n * Usage:\n * const exporter = new STLExporter();\n *\n * // second argument is a list of options\n * const data = exporter.parse( mesh, { binary: true } );\n *\n */\n\nclass STLExporter {\n parse(scene, options = {}) {\n options = Object.assign(\n {\n binary: false,\n },\n options,\n )\n\n const binary = options.binary\n\n //\n\n const objects = []\n let triangles = 0\n\n scene.traverse(function (object) {\n if (object.isMesh) {\n const geometry = object.geometry\n\n const index = geometry.index\n const positionAttribute = geometry.getAttribute('position')\n\n triangles += index !== null ? index.count / 3 : positionAttribute.count / 3\n\n objects.push({\n object3d: object,\n geometry: geometry,\n })\n }\n })\n\n let output\n let offset = 80 // skip header\n\n if (binary === true) {\n const bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4\n const arrayBuffer = new ArrayBuffer(bufferLength)\n output = new DataView(arrayBuffer)\n output.setUint32(offset, triangles, true)\n offset += 4\n } else {\n output = ''\n output += 'solid exported\\n'\n }\n\n const vA = new Vector3()\n const vB = new Vector3()\n const vC = new Vector3()\n const cb = new Vector3()\n const ab = new Vector3()\n const normal = new Vector3()\n\n for (let i = 0, il = objects.length; i < il; i++) {\n const object = objects[i].object3d\n const geometry = objects[i].geometry\n\n const index = geometry.index\n const positionAttribute = geometry.getAttribute('position')\n\n if (index !== null) {\n // indexed geometry\n\n for (let j = 0; j < index.count; j += 3) {\n const a = index.getX(j + 0)\n const b = index.getX(j + 1)\n const c = index.getX(j + 2)\n\n writeFace(a, b, c, positionAttribute, object)\n }\n } else {\n // non-indexed geometry\n\n for (let j = 0; j < positionAttribute.count; j += 3) {\n const a = j + 0\n const b = j + 1\n const c = j + 2\n\n writeFace(a, b, c, positionAttribute, object)\n }\n }\n }\n\n if (binary === false) {\n output += 'endsolid exported\\n'\n }\n\n return output\n\n function writeFace(a, b, c, positionAttribute, object) {\n vA.fromBufferAttribute(positionAttribute, a)\n vB.fromBufferAttribute(positionAttribute, b)\n vC.fromBufferAttribute(positionAttribute, c)\n\n if (object.isSkinnedMesh === true) {\n object.applyBoneTransform(a, vA)\n object.applyBoneTransform(b, vB)\n object.applyBoneTransform(c, vC)\n }\n\n vA.applyMatrix4(object.matrixWorld)\n vB.applyMatrix4(object.matrixWorld)\n vC.applyMatrix4(object.matrixWorld)\n\n writeNormal(vA, vB, vC)\n\n writeVertex(vA)\n writeVertex(vB)\n writeVertex(vC)\n\n if (binary === true) {\n output.setUint16(offset, 0, true)\n offset += 2\n } else {\n output += '\\t\\tendloop\\n'\n output += '\\tendfacet\\n'\n }\n }\n\n function writeNormal(vA, vB, vC) {\n cb.subVectors(vC, vB)\n ab.subVectors(vA, vB)\n cb.cross(ab).normalize()\n\n normal.copy(cb).normalize()\n\n if (binary === true) {\n output.setFloat32(offset, normal.x, true)\n offset += 4\n output.setFloat32(offset, normal.y, true)\n offset += 4\n output.setFloat32(offset, normal.z, true)\n offset += 4\n } else {\n output += '\\tfacet normal ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\\n'\n output += '\\t\\touter loop\\n'\n }\n }\n\n function writeVertex(vertex) {\n if (binary === true) {\n output.setFloat32(offset, vertex.x, true)\n offset += 4\n output.setFloat32(offset, vertex.y, true)\n offset += 4\n output.setFloat32(offset, vertex.z, true)\n offset += 4\n } else {\n output += '\\t\\t\\tvertex ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\\n'\n }\n }\n }\n}\n\nexport { STLExporter }\n"],"names":["vA","vB","vC"],"mappings":";AAWA,MAAM,YAAY;AAAA,EAChB,MAAM,OAAO,UAAU,IAAI;AACzB,cAAU,OAAO;AAAA,MACf;AAAA,QACE,QAAQ;AAAA,MACT;AAAA,MACD;AAAA,IACD;AAED,UAAM,SAAS,QAAQ;AAIvB,UAAM,UAAU,CAAE;AAClB,QAAI,YAAY;AAEhB,UAAM,SAAS,SAAU,QAAQ;AAC/B,UAAI,OAAO,QAAQ;AACjB,cAAM,WAAW,OAAO;AAExB,cAAM,QAAQ,SAAS;AACvB,cAAM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,MAAM,OAAO,IAAI;AAC3E,kBAAU;AAAA,MACX;AAAA,IACF;AAED,aAAS,YAAY,QAAQ;AAC3B,UAAI,WAAW,MAAM;AACnB,eAAO,WAAW,QAAQ,OAAO,GAAG,IAAI;AACxC,kBAAU;AACV,eAAO,WAAW,QAAQ,OAAO,GAAG,IAAI;AACxC,kBAAU;AACV,eAAO,WAAW,QAAQ,OAAO,GAAG,IAAI;AACxC,kBAAU;AAAA,MAClB,OAAa;AACL,kBAAU,eAAkB,OAAO,IAAI,MAAM,OAAO,IAAI,MAAM,OAAO,IAAI;AAAA,MAC1E;AAAA,IACF;AAAA,EACF;AACH;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-stdlib",
3
- "version": "2.28.5",
3
+ "version": "2.28.6",
4
4
  "description": "stand-alone library of threejs examples",
5
5
  "keywords": [
6
6
  "three",