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