@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.
- package/dist/bundle/index.js +33146 -1
- package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
- package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
- package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
- package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
- package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
- package/dist/cjs/src/analysis/analysis.js +560 -1
- package/dist/cjs/src/analysis/testing.js +958 -1
- package/dist/cjs/src/core/centralPlant.js +1149 -1
- package/dist/cjs/src/core/debugLogger.js +175 -1
- package/dist/cjs/src/core/mathUtils.js +574 -1
- package/dist/cjs/src/core/nameUtils.js +93 -1
- package/dist/cjs/src/data/export.js +716 -1
- package/dist/cjs/src/data/import.js +380 -1
- package/dist/cjs/src/data/numerics.js +522 -1
- package/dist/cjs/src/helpers/sceneHelper.js +572 -1
- package/dist/cjs/src/index.js +69 -1
- package/dist/cjs/src/managers/components/animationManager.js +123 -1
- package/dist/cjs/src/managers/components/componentManager.js +332 -1
- package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
- package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
- package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
- package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
- package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
- package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
- package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
- package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
- package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
- package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
- package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
- package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
- package/dist/cjs/src/managers/system/disposalManager.js +444 -1
- package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
- package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
- package/dist/cjs/src/rendering/modelPreloader.js +369 -1
- package/dist/cjs/src/rendering/rendering2D.js +631 -1
- package/dist/cjs/src/rendering/rendering3D.js +685 -1
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
- package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
- package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
- package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
- package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
- package/dist/esm/src/analysis/analysis.js +536 -1
- package/dist/esm/src/analysis/testing.js +954 -1
- package/dist/esm/src/core/centralPlant.js +1144 -1
- package/dist/esm/src/core/debugLogger.js +167 -1
- package/dist/esm/src/core/mathUtils.js +570 -1
- package/dist/esm/src/core/nameUtils.js +87 -1
- package/dist/esm/src/data/export.js +712 -1
- package/dist/esm/src/data/import.js +356 -1
- package/dist/esm/src/data/numerics.js +518 -1
- package/dist/esm/src/helpers/sceneHelper.js +547 -1
- package/dist/esm/src/index.js +35 -1
- package/dist/esm/src/managers/components/animationManager.js +119 -1
- package/dist/esm/src/managers/components/componentManager.js +328 -1
- package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
- package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
- package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
- package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
- package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
- package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
- package/dist/esm/src/managers/environment/environmentManager.js +690 -1
- package/dist/esm/src/managers/environment/textureConfig.js +202 -1
- package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
- package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
- package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
- package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
- package/dist/esm/src/managers/system/disposalManager.js +440 -1
- package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
- package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
- package/dist/esm/src/rendering/modelPreloader.js +364 -1
- package/dist/esm/src/rendering/rendering2D.js +627 -1
- package/dist/esm/src/rendering/rendering3D.js +661 -1
- package/package.json +1 -1
|
@@ -1 +1,538 @@
|
|
|
1
|
-
import
|
|
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 };
|