@2112-lab/central-plant 0.1.4 → 0.1.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.
Files changed (88) hide show
  1. package/dist/bundle/index.js +33146 -1
  2. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
  3. package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
  4. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
  5. package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
  6. package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
  7. package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
  8. package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
  9. package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
  10. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
  11. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
  12. package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
  13. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
  14. package/dist/cjs/src/analysis/analysis.js +560 -1
  15. package/dist/cjs/src/analysis/testing.js +958 -1
  16. package/dist/cjs/src/core/centralPlant.js +1149 -1
  17. package/dist/cjs/src/core/debugLogger.js +175 -1
  18. package/dist/cjs/src/core/mathUtils.js +574 -1
  19. package/dist/cjs/src/core/nameUtils.js +93 -1
  20. package/dist/cjs/src/data/export.js +716 -1
  21. package/dist/cjs/src/data/import.js +380 -1
  22. package/dist/cjs/src/data/numerics.js +522 -1
  23. package/dist/cjs/src/helpers/sceneHelper.js +572 -1
  24. package/dist/cjs/src/index.js +69 -1
  25. package/dist/cjs/src/managers/components/animationManager.js +123 -1
  26. package/dist/cjs/src/managers/components/componentManager.js +332 -1
  27. package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
  28. package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
  29. package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
  30. package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
  31. package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
  32. package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
  33. package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
  34. package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
  35. package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
  36. package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
  37. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
  38. package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
  39. package/dist/cjs/src/managers/system/disposalManager.js +444 -1
  40. package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
  41. package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
  42. package/dist/cjs/src/rendering/modelPreloader.js +369 -1
  43. package/dist/cjs/src/rendering/rendering2D.js +631 -1
  44. package/dist/cjs/src/rendering/rendering3D.js +685 -1
  45. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
  46. package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
  47. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
  48. package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
  49. package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
  50. package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
  51. package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
  52. package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
  53. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
  54. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
  55. package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
  56. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
  57. package/dist/esm/src/analysis/analysis.js +536 -1
  58. package/dist/esm/src/analysis/testing.js +954 -1
  59. package/dist/esm/src/core/centralPlant.js +1144 -1
  60. package/dist/esm/src/core/debugLogger.js +167 -1
  61. package/dist/esm/src/core/mathUtils.js +570 -1
  62. package/dist/esm/src/core/nameUtils.js +87 -1
  63. package/dist/esm/src/data/export.js +712 -1
  64. package/dist/esm/src/data/import.js +356 -1
  65. package/dist/esm/src/data/numerics.js +518 -1
  66. package/dist/esm/src/helpers/sceneHelper.js +547 -1
  67. package/dist/esm/src/index.js +35 -1
  68. package/dist/esm/src/managers/components/animationManager.js +119 -1
  69. package/dist/esm/src/managers/components/componentManager.js +328 -1
  70. package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
  71. package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
  72. package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
  73. package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
  74. package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
  75. package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
  76. package/dist/esm/src/managers/environment/environmentManager.js +690 -1
  77. package/dist/esm/src/managers/environment/textureConfig.js +202 -1
  78. package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
  79. package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
  80. package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
  81. package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
  82. package/dist/esm/src/managers/system/disposalManager.js +440 -1
  83. package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
  84. package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
  85. package/dist/esm/src/rendering/modelPreloader.js +364 -1
  86. package/dist/esm/src/rendering/rendering2D.js +627 -1
  87. package/dist/esm/src/rendering/rendering3D.js +661 -1
  88. package/package.json +1 -1
@@ -1 +1,538 @@
1
- import{Color as n,Vector3 as t,Matrix3 as e,ColorManagement as o,SRGBColorSpace as r}from"three";class l{parse(l,i,a={}){function f(n){l.traverse(function(t){if(!0===t.isMesh||t.isPoints){const e=t,o=e.geometry;!0===o.hasAttribute("position")&&n(e,o)}})}const p=(a=Object.assign({binary:!1,excludeAttributes:[],littleEndian:!1},a)).excludeAttributes;let u=!0,c=!1,s=!1,y=!1,d=0,h=0;l.traverse(function(n){if(!0===n.isMesh){const t=n.geometry,e=t.getAttribute("position"),o=t.getAttribute("normal"),r=t.getAttribute("uv"),l=t.getAttribute("color"),i=t.getIndex();if(void 0===e)return;d+=e.count,h+=i?i.count/3:e.count/3,void 0!==o&&(c=!0),void 0!==r&&(y=!0),void 0!==l&&(s=!0)}else if(n.isPoints){const t=n.geometry,e=t.getAttribute("position"),o=t.getAttribute("normal"),r=t.getAttribute("color");d+=e.count,void 0!==o&&(c=!0),void 0!==r&&(s=!0),u=!1}});const $=new n;if(u=u&&-1===p.indexOf("index"),c=c&&-1===p.indexOf("normal"),s=s&&-1===p.indexOf("color"),y=y&&-1===p.indexOf("uv"),u&&h!==Math.floor(h))return null;let m=`ply\nformat ${a.binary?a.littleEndian?"binary_little_endian":"binary_big_endian":"ascii"} 1.0\nelement vertex ${d}\nproperty float x\nproperty float y\nproperty float z\n`;!0===c&&(m+="property float nx\nproperty float ny\nproperty float nz\n"),!0===y&&(m+="property float s\nproperty float t\n"),!0===s&&(m+="property uchar red\nproperty uchar green\nproperty uchar blue\n"),!0===u&&(m+=`element face ${h}\nproperty list uchar int vertex_index\n`),m+="end_header\n";const v=new t,x=new e;let w=null;if(!0===a.binary){const n=(new TextEncoder).encode(m),t=d*(12+(c?12:0)+(s?3:0)+(y?8:0)),e=u?13*h:0,l=new DataView(new ArrayBuffer(n.length+t+e));new Uint8Array(l.buffer).set(n,0);let i=n.length,p=n.length+t,b=0;f(function(n,t){const e=t.getAttribute("position"),f=t.getAttribute("normal"),d=t.getAttribute("uv"),h=t.getAttribute("color"),m=t.getIndex();x.getNormalMatrix(n.matrixWorld);for(let t=0,p=e.count;t<p;t++)v.fromBufferAttribute(e,t),v.applyMatrix4(n.matrixWorld),l.setFloat32(i,v.x,a.littleEndian),i+=4,l.setFloat32(i,v.y,a.littleEndian),i+=4,l.setFloat32(i,v.z,a.littleEndian),i+=4,!0===c&&(null!=f?(v.fromBufferAttribute(f,t),v.applyMatrix3(x).normalize(),l.setFloat32(i,v.x,a.littleEndian),i+=4,l.setFloat32(i,v.y,a.littleEndian),i+=4,l.setFloat32(i,v.z,a.littleEndian),i+=4):(l.setFloat32(i,0,a.littleEndian),i+=4,l.setFloat32(i,0,a.littleEndian),i+=4,l.setFloat32(i,0,a.littleEndian),i+=4)),!0===y&&(null!=d?(l.setFloat32(i,d.getX(t),a.littleEndian),i+=4,l.setFloat32(i,d.getY(t),a.littleEndian),i+=4):(l.setFloat32(i,0,a.littleEndian),i+=4,l.setFloat32(i,0,a.littleEndian),i+=4)),!0===s&&(null!=h?($.fromBufferAttribute(h,t),o.workingToColorSpace($,r),l.setUint8(i,Math.floor(255*$.r)),i+=1,l.setUint8(i,Math.floor(255*$.g)),i+=1,l.setUint8(i,Math.floor(255*$.b)),i+=1):(l.setUint8(i,255),i+=1,l.setUint8(i,255),i+=1,l.setUint8(i,255),i+=1));if(!0===u)if(null!==m)for(let n=0,t=m.count;n<t;n+=3)l.setUint8(p,3),p+=1,l.setUint32(p,m.getX(n+0)+b,a.littleEndian),p+=4,l.setUint32(p,m.getX(n+1)+b,a.littleEndian),p+=4,l.setUint32(p,m.getX(n+2)+b,a.littleEndian),p+=4;else for(let n=0,t=e.count;n<t;n+=3)l.setUint8(p,3),p+=1,l.setUint32(p,b+n,a.littleEndian),p+=4,l.setUint32(p,b+n+1,a.littleEndian),p+=4,l.setUint32(p,b+n+2,a.littleEndian),p+=4;b+=e.count}),w=l.buffer}else{let n=0,t="",e="";f(function(l,i){const a=i.getAttribute("position"),f=i.getAttribute("normal"),p=i.getAttribute("uv"),d=i.getAttribute("color"),m=i.getIndex();x.getNormalMatrix(l.matrixWorld);for(let n=0,e=a.count;n<e;n++){v.fromBufferAttribute(a,n),v.applyMatrix4(l.matrixWorld);let e=v.x+" "+v.y+" "+v.z;!0===c&&(null!=f?(v.fromBufferAttribute(f,n),v.applyMatrix3(x).normalize(),e+=" "+v.x+" "+v.y+" "+v.z):e+=" 0 0 0"),!0===y&&(e+=null!=p?" "+p.getX(n)+" "+p.getY(n):" 0 0"),!0===s&&(null!=d?($.fromBufferAttribute(d,n),o.workingToColorSpace($,r),e+=" "+Math.floor(255*$.r)+" "+Math.floor(255*$.g)+" "+Math.floor(255*$.b)):e+=" 255 255 255"),t+=e+"\n"}if(!0===u){if(null!==m)for(let t=0,o=m.count;t<o;t+=3)e+=`3 ${m.getX(t+0)+n}`,e+=` ${m.getX(t+1)+n}`,e+=` ${m.getX(t+2)+n}\n`;else for(let t=0,o=a.count;t<o;t+=3)e+=`3 ${n+t} ${n+t+1} ${n+t+2}\n`;h+=m?m.count/3:a.count/3}n+=a.count}),w=`${m}${t}${u?`${e}\n`:"\n"}`}return"function"==typeof i&&requestAnimationFrame(()=>i(w)),w}}export{l as PLYExporter};
1
+ import { Color, Vector3, Matrix3, ColorManagement, SRGBColorSpace } from 'three';
2
+
3
+ /**
4
+ * An exporter for PLY.
5
+ *
6
+ * PLY (Polygon or Stanford Triangle Format) is a file format for efficient delivery and
7
+ * loading of simple, static 3D content in a dense format. Both binary and ascii formats are
8
+ * supported. PLY can store vertex positions, colors, normals and uv coordinates. No textures
9
+ * or texture references are saved.
10
+ *
11
+ * ```js
12
+ * const exporter = new PLYExporter();
13
+ * const data = exporter.parse( scene, options );
14
+ * ```
15
+ *
16
+ * @three_import import { PLYExporter } from 'three/addons/exporters/PLYExporter.js';
17
+ */
18
+ class PLYExporter {
19
+
20
+ /**
21
+ * Parses the given 3D object and generates the PLY output.
22
+ *
23
+ * If the 3D object is composed of multiple children and geometry, they are merged into a single mesh in the file.
24
+ *
25
+ * @param {Object3D} object - The 3D object to export.
26
+ * @param {PLYExporter~OnDone} onDone - A callback function that is executed when the export has finished.
27
+ * @param {PLYExporter~Options} options - The export options.
28
+ * @return {?string|ArrayBuffer} The exported PLY.
29
+ */
30
+ parse( object, onDone, options = {} ) {
31
+
32
+ // reference https://github.com/gkjohnson/ply-exporter-js
33
+
34
+ // Iterate over the valid meshes in the object
35
+ function traverseMeshes( cb ) {
36
+
37
+ object.traverse( function ( child ) {
38
+
39
+ if ( child.isMesh === true || child.isPoints ) {
40
+
41
+ const mesh = child;
42
+ const geometry = mesh.geometry;
43
+
44
+ if ( geometry.hasAttribute( 'position' ) === true ) {
45
+
46
+ cb( mesh, geometry );
47
+
48
+ }
49
+
50
+ }
51
+
52
+ } );
53
+
54
+ }
55
+
56
+ // Default options
57
+ const defaultOptions = {
58
+ binary: false,
59
+ excludeAttributes: [], // normal, uv, color, index
60
+ littleEndian: false
61
+ };
62
+
63
+ options = Object.assign( defaultOptions, options );
64
+
65
+ const excludeAttributes = options.excludeAttributes;
66
+ let includeIndices = true;
67
+ let includeNormals = false;
68
+ let includeColors = false;
69
+ let includeUVs = false;
70
+
71
+ // count the vertices, check which properties are used,
72
+ // and cache the BufferGeometry
73
+ let vertexCount = 0;
74
+ let faceCount = 0;
75
+
76
+ object.traverse( function ( child ) {
77
+
78
+ if ( child.isMesh === true ) {
79
+
80
+ const mesh = child;
81
+ const geometry = mesh.geometry;
82
+
83
+ const vertices = geometry.getAttribute( 'position' );
84
+ const normals = geometry.getAttribute( 'normal' );
85
+ const uvs = geometry.getAttribute( 'uv' );
86
+ const colors = geometry.getAttribute( 'color' );
87
+ const indices = geometry.getIndex();
88
+
89
+ if ( vertices === undefined ) {
90
+
91
+ return;
92
+
93
+ }
94
+
95
+ vertexCount += vertices.count;
96
+ faceCount += indices ? indices.count / 3 : vertices.count / 3;
97
+
98
+ if ( normals !== undefined ) includeNormals = true;
99
+
100
+ if ( uvs !== undefined ) includeUVs = true;
101
+
102
+ if ( colors !== undefined ) includeColors = true;
103
+
104
+ } else if ( child.isPoints ) {
105
+
106
+ const mesh = child;
107
+ const geometry = mesh.geometry;
108
+
109
+ const vertices = geometry.getAttribute( 'position' );
110
+ const normals = geometry.getAttribute( 'normal' );
111
+ const colors = geometry.getAttribute( 'color' );
112
+
113
+ vertexCount += vertices.count;
114
+
115
+ if ( normals !== undefined ) includeNormals = true;
116
+
117
+ if ( colors !== undefined ) includeColors = true;
118
+
119
+ includeIndices = false;
120
+
121
+ }
122
+
123
+ } );
124
+
125
+ const tempColor = new Color();
126
+ includeIndices = includeIndices && excludeAttributes.indexOf( 'index' ) === - 1;
127
+ includeNormals = includeNormals && excludeAttributes.indexOf( 'normal' ) === - 1;
128
+ includeColors = includeColors && excludeAttributes.indexOf( 'color' ) === - 1;
129
+ includeUVs = includeUVs && excludeAttributes.indexOf( 'uv' ) === - 1;
130
+
131
+
132
+ if ( includeIndices && faceCount !== Math.floor( faceCount ) ) {
133
+
134
+ // point cloud meshes will not have an index array and may not have a
135
+ // number of vertices that is divisible by 3 (and therefore representable
136
+ // as triangles)
137
+ console.error(
138
+
139
+ 'PLYExporter: Failed to generate a valid PLY file with triangle indices because the ' +
140
+ 'number of indices is not divisible by 3.'
141
+
142
+ );
143
+
144
+ return null;
145
+
146
+ }
147
+
148
+ const indexByteCount = 4;
149
+
150
+ let header =
151
+ 'ply\n' +
152
+ `format ${ options.binary ? ( options.littleEndian ? 'binary_little_endian' : 'binary_big_endian' ) : 'ascii' } 1.0\n` +
153
+ `element vertex ${vertexCount}\n` +
154
+
155
+ // position
156
+ 'property float x\n' +
157
+ 'property float y\n' +
158
+ 'property float z\n';
159
+
160
+ if ( includeNormals === true ) {
161
+
162
+ // normal
163
+ header +=
164
+ 'property float nx\n' +
165
+ 'property float ny\n' +
166
+ 'property float nz\n';
167
+
168
+ }
169
+
170
+ if ( includeUVs === true ) {
171
+
172
+ // uvs
173
+ header +=
174
+ 'property float s\n' +
175
+ 'property float t\n';
176
+
177
+ }
178
+
179
+ if ( includeColors === true ) {
180
+
181
+ // colors
182
+ header +=
183
+ 'property uchar red\n' +
184
+ 'property uchar green\n' +
185
+ 'property uchar blue\n';
186
+
187
+ }
188
+
189
+ if ( includeIndices === true ) {
190
+
191
+ // faces
192
+ header +=
193
+ `element face ${faceCount}\n` +
194
+ 'property list uchar int vertex_index\n';
195
+
196
+ }
197
+
198
+ header += 'end_header\n';
199
+
200
+
201
+ // Generate attribute data
202
+ const vertex = new Vector3();
203
+ const normalMatrixWorld = new Matrix3();
204
+ let result = null;
205
+
206
+ if ( options.binary === true ) {
207
+
208
+ // Binary File Generation
209
+ const headerBin = new TextEncoder().encode( header );
210
+
211
+ // 3 position values at 4 bytes
212
+ // 3 normal values at 4 bytes
213
+ // 3 color channels with 1 byte
214
+ // 2 uv values at 4 bytes
215
+ const vertexListLength = vertexCount * ( 4 * 3 + ( includeNormals ? 4 * 3 : 0 ) + ( includeColors ? 3 : 0 ) + ( includeUVs ? 4 * 2 : 0 ) );
216
+
217
+ // 1 byte shape descriptor
218
+ // 3 vertex indices at ${indexByteCount} bytes
219
+ const faceListLength = includeIndices ? faceCount * ( indexByteCount * 3 + 1 ) : 0;
220
+ const output = new DataView( new ArrayBuffer( headerBin.length + vertexListLength + faceListLength ) );
221
+ new Uint8Array( output.buffer ).set( headerBin, 0 );
222
+
223
+
224
+ let vOffset = headerBin.length;
225
+ let fOffset = headerBin.length + vertexListLength;
226
+ let writtenVertices = 0;
227
+ traverseMeshes( function ( mesh, geometry ) {
228
+
229
+ const vertices = geometry.getAttribute( 'position' );
230
+ const normals = geometry.getAttribute( 'normal' );
231
+ const uvs = geometry.getAttribute( 'uv' );
232
+ const colors = geometry.getAttribute( 'color' );
233
+ const indices = geometry.getIndex();
234
+
235
+ normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
236
+
237
+ for ( let i = 0, l = vertices.count; i < l; i ++ ) {
238
+
239
+ vertex.fromBufferAttribute( vertices, i );
240
+
241
+ vertex.applyMatrix4( mesh.matrixWorld );
242
+
243
+
244
+ // Position information
245
+ output.setFloat32( vOffset, vertex.x, options.littleEndian );
246
+ vOffset += 4;
247
+
248
+ output.setFloat32( vOffset, vertex.y, options.littleEndian );
249
+ vOffset += 4;
250
+
251
+ output.setFloat32( vOffset, vertex.z, options.littleEndian );
252
+ vOffset += 4;
253
+
254
+ // Normal information
255
+ if ( includeNormals === true ) {
256
+
257
+ if ( normals != null ) {
258
+
259
+ vertex.fromBufferAttribute( normals, i );
260
+
261
+ vertex.applyMatrix3( normalMatrixWorld ).normalize();
262
+
263
+ output.setFloat32( vOffset, vertex.x, options.littleEndian );
264
+ vOffset += 4;
265
+
266
+ output.setFloat32( vOffset, vertex.y, options.littleEndian );
267
+ vOffset += 4;
268
+
269
+ output.setFloat32( vOffset, vertex.z, options.littleEndian );
270
+ vOffset += 4;
271
+
272
+ } else {
273
+
274
+ output.setFloat32( vOffset, 0, options.littleEndian );
275
+ vOffset += 4;
276
+
277
+ output.setFloat32( vOffset, 0, options.littleEndian );
278
+ vOffset += 4;
279
+
280
+ output.setFloat32( vOffset, 0, options.littleEndian );
281
+ vOffset += 4;
282
+
283
+ }
284
+
285
+ }
286
+
287
+ // UV information
288
+ if ( includeUVs === true ) {
289
+
290
+ if ( uvs != null ) {
291
+
292
+ output.setFloat32( vOffset, uvs.getX( i ), options.littleEndian );
293
+ vOffset += 4;
294
+
295
+ output.setFloat32( vOffset, uvs.getY( i ), options.littleEndian );
296
+ vOffset += 4;
297
+
298
+ } else {
299
+
300
+ output.setFloat32( vOffset, 0, options.littleEndian );
301
+ vOffset += 4;
302
+
303
+ output.setFloat32( vOffset, 0, options.littleEndian );
304
+ vOffset += 4;
305
+
306
+ }
307
+
308
+ }
309
+
310
+ // Color information
311
+ if ( includeColors === true ) {
312
+
313
+ if ( colors != null ) {
314
+
315
+ tempColor.fromBufferAttribute( colors, i );
316
+
317
+ ColorManagement.workingToColorSpace( tempColor, SRGBColorSpace );
318
+
319
+ output.setUint8( vOffset, Math.floor( tempColor.r * 255 ) );
320
+ vOffset += 1;
321
+
322
+ output.setUint8( vOffset, Math.floor( tempColor.g * 255 ) );
323
+ vOffset += 1;
324
+
325
+ output.setUint8( vOffset, Math.floor( tempColor.b * 255 ) );
326
+ vOffset += 1;
327
+
328
+ } else {
329
+
330
+ output.setUint8( vOffset, 255 );
331
+ vOffset += 1;
332
+
333
+ output.setUint8( vOffset, 255 );
334
+ vOffset += 1;
335
+
336
+ output.setUint8( vOffset, 255 );
337
+ vOffset += 1;
338
+
339
+ }
340
+
341
+ }
342
+
343
+ }
344
+
345
+ if ( includeIndices === true ) {
346
+
347
+ // Create the face list
348
+
349
+ if ( indices !== null ) {
350
+
351
+ for ( let i = 0, l = indices.count; i < l; i += 3 ) {
352
+
353
+ output.setUint8( fOffset, 3 );
354
+ fOffset += 1;
355
+
356
+ output.setUint32( fOffset, indices.getX( i + 0 ) + writtenVertices, options.littleEndian );
357
+ fOffset += indexByteCount;
358
+
359
+ output.setUint32( fOffset, indices.getX( i + 1 ) + writtenVertices, options.littleEndian );
360
+ fOffset += indexByteCount;
361
+
362
+ output.setUint32( fOffset, indices.getX( i + 2 ) + writtenVertices, options.littleEndian );
363
+ fOffset += indexByteCount;
364
+
365
+ }
366
+
367
+ } else {
368
+
369
+ for ( let i = 0, l = vertices.count; i < l; i += 3 ) {
370
+
371
+ output.setUint8( fOffset, 3 );
372
+ fOffset += 1;
373
+
374
+ output.setUint32( fOffset, writtenVertices + i, options.littleEndian );
375
+ fOffset += indexByteCount;
376
+
377
+ output.setUint32( fOffset, writtenVertices + i + 1, options.littleEndian );
378
+ fOffset += indexByteCount;
379
+
380
+ output.setUint32( fOffset, writtenVertices + i + 2, options.littleEndian );
381
+ fOffset += indexByteCount;
382
+
383
+ }
384
+
385
+ }
386
+
387
+ }
388
+
389
+
390
+ // Save the amount of verts we've already written so we can offset
391
+ // the face index on the next mesh
392
+ writtenVertices += vertices.count;
393
+
394
+ } );
395
+
396
+ result = output.buffer;
397
+
398
+ } else {
399
+
400
+ // Ascii File Generation
401
+ // count the number of vertices
402
+ let writtenVertices = 0;
403
+ let vertexList = '';
404
+ let faceList = '';
405
+
406
+ traverseMeshes( function ( mesh, geometry ) {
407
+
408
+ const vertices = geometry.getAttribute( 'position' );
409
+ const normals = geometry.getAttribute( 'normal' );
410
+ const uvs = geometry.getAttribute( 'uv' );
411
+ const colors = geometry.getAttribute( 'color' );
412
+ const indices = geometry.getIndex();
413
+
414
+ normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
415
+
416
+ // form each line
417
+ for ( let i = 0, l = vertices.count; i < l; i ++ ) {
418
+
419
+ vertex.fromBufferAttribute( vertices, i );
420
+
421
+ vertex.applyMatrix4( mesh.matrixWorld );
422
+
423
+
424
+ // Position information
425
+ let line =
426
+ vertex.x + ' ' +
427
+ vertex.y + ' ' +
428
+ vertex.z;
429
+
430
+ // Normal information
431
+ if ( includeNormals === true ) {
432
+
433
+ if ( normals != null ) {
434
+
435
+ vertex.fromBufferAttribute( normals, i );
436
+
437
+ vertex.applyMatrix3( normalMatrixWorld ).normalize();
438
+
439
+ line += ' ' +
440
+ vertex.x + ' ' +
441
+ vertex.y + ' ' +
442
+ vertex.z;
443
+
444
+ } else {
445
+
446
+ line += ' 0 0 0';
447
+
448
+ }
449
+
450
+ }
451
+
452
+ // UV information
453
+ if ( includeUVs === true ) {
454
+
455
+ if ( uvs != null ) {
456
+
457
+ line += ' ' +
458
+ uvs.getX( i ) + ' ' +
459
+ uvs.getY( i );
460
+
461
+ } else {
462
+
463
+ line += ' 0 0';
464
+
465
+ }
466
+
467
+ }
468
+
469
+ // Color information
470
+ if ( includeColors === true ) {
471
+
472
+ if ( colors != null ) {
473
+
474
+ tempColor.fromBufferAttribute( colors, i );
475
+
476
+ ColorManagement.workingToColorSpace( tempColor, SRGBColorSpace );
477
+
478
+ line += ' ' +
479
+ Math.floor( tempColor.r * 255 ) + ' ' +
480
+ Math.floor( tempColor.g * 255 ) + ' ' +
481
+ Math.floor( tempColor.b * 255 );
482
+
483
+ } else {
484
+
485
+ line += ' 255 255 255';
486
+
487
+ }
488
+
489
+ }
490
+
491
+ vertexList += line + '\n';
492
+
493
+ }
494
+
495
+ // Create the face list
496
+ if ( includeIndices === true ) {
497
+
498
+ if ( indices !== null ) {
499
+
500
+ for ( let i = 0, l = indices.count; i < l; i += 3 ) {
501
+
502
+ faceList += `3 ${ indices.getX( i + 0 ) + writtenVertices }`;
503
+ faceList += ` ${ indices.getX( i + 1 ) + writtenVertices }`;
504
+ faceList += ` ${ indices.getX( i + 2 ) + writtenVertices }\n`;
505
+
506
+ }
507
+
508
+ } else {
509
+
510
+ for ( let i = 0, l = vertices.count; i < l; i += 3 ) {
511
+
512
+ faceList += `3 ${ writtenVertices + i } ${ writtenVertices + i + 1 } ${ writtenVertices + i + 2 }\n`;
513
+
514
+ }
515
+
516
+ }
517
+
518
+ faceCount += indices ? indices.count / 3 : vertices.count / 3;
519
+
520
+ }
521
+
522
+ writtenVertices += vertices.count;
523
+
524
+ } );
525
+
526
+ result = `${ header }${vertexList}${ includeIndices ? `${faceList}\n` : '\n' }`;
527
+
528
+ }
529
+
530
+ if ( typeof onDone === 'function' ) requestAnimationFrame( () => onDone( result ) );
531
+
532
+ return result;
533
+
534
+ }
535
+
536
+ }
537
+
538
+ export { PLYExporter };