@shapediver/viewer.data-engine.geometry-engine 2.9.10 → 2.10.0
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/GeometryEngine.js +13 -17
- package/dist/GeometryEngine.js.map +1 -1
- package/dist/gltfv1/GLTFLoader.js +41 -45
- package/dist/gltfv1/GLTFLoader.js.map +1 -1
- package/dist/gltfv1/SDGTFLoader.js +94 -98
- package/dist/gltfv1/SDGTFLoader.js.map +1 -1
- package/dist/gltfv2/GLTFLoader.js +56 -60
- package/dist/gltfv2/GLTFLoader.js.map +1 -1
- package/dist/gltfv2/loaders/AccessorLoader.js +11 -15
- package/dist/gltfv2/loaders/AccessorLoader.js.map +1 -1
- package/dist/gltfv2/loaders/BufferLoader.js +3 -7
- package/dist/gltfv2/loaders/BufferLoader.js.map +1 -1
- package/dist/gltfv2/loaders/BufferViewLoader.js +1 -5
- package/dist/gltfv2/loaders/BufferViewLoader.js.map +1 -1
- package/dist/gltfv2/loaders/GeometryLoader.js +15 -19
- package/dist/gltfv2/loaders/GeometryLoader.js.map +1 -1
- package/dist/gltfv2/loaders/MaterialLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/MaterialLoader.js +85 -56
- package/dist/gltfv2/loaders/MaterialLoader.js.map +1 -1
- package/dist/gltfv2/loaders/TextureLoader.js +4 -8
- package/dist/gltfv2/loaders/TextureLoader.js.map +1 -1
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/gltfv2/loaders/MaterialLoader.ts +39 -19
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,18 +7,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const gl_matrix_1 = require("gl-matrix");
|
|
18
|
-
class SDGTFLoader {
|
|
10
|
+
import { TreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
11
|
+
import { Logger, ShapeDiverViewerDataProcessingError } from '@shapediver/viewer.shared.services';
|
|
12
|
+
import { ACCESSORCOMPONENTTYPE_V1 as ACCESSOR_COMPONENTTYPE, ACCESSORTYPE_V1 as ACCESSORTYPE, } from '@shapediver/viewer.data-engine.shared-types';
|
|
13
|
+
import { AttributeData, GeometryData, PRIMITIVE_MODE, PrimitiveData, } from '@shapediver/viewer.shared.types';
|
|
14
|
+
import { mat4, vec3, vec4 } from 'gl-matrix';
|
|
15
|
+
export class SDGTFLoader {
|
|
19
16
|
constructor() {
|
|
20
17
|
// #region Properties (5)
|
|
21
18
|
this.BINARY_EXTENSION_HEADER_LENGTH = 20;
|
|
22
|
-
this._logger =
|
|
19
|
+
this._logger = Logger.instance;
|
|
23
20
|
// #endregion Private Methods (6)
|
|
24
21
|
}
|
|
25
22
|
// #endregion Properties (5)
|
|
@@ -36,7 +33,7 @@ class SDGTFLoader {
|
|
|
36
33
|
contentFormat: headerDataView.getUint32(17, true)
|
|
37
34
|
};
|
|
38
35
|
if (header.magic != 'sdgTF')
|
|
39
|
-
throw new
|
|
36
|
+
throw new ShapeDiverViewerDataProcessingError('SDGTFLoader.load: Invalid data: sdgTF magic wrong.');
|
|
40
37
|
// create content
|
|
41
38
|
const contentDataView = new DataView(binaryGeometry, gltfLength + this.BINARY_EXTENSION_HEADER_LENGTH + 1, header.contentLength);
|
|
42
39
|
const contentDecoded = new TextDecoder().decode(contentDataView);
|
|
@@ -44,7 +41,7 @@ class SDGTFLoader {
|
|
|
44
41
|
this._body = binaryGeometry.slice(gltfLength + this.BINARY_EXTENSION_HEADER_LENGTH + 1 + header.contentLength, gltfLength + header.length);
|
|
45
42
|
}
|
|
46
43
|
else {
|
|
47
|
-
return new
|
|
44
|
+
return new TreeNode();
|
|
48
45
|
}
|
|
49
46
|
return yield this.loadScene();
|
|
50
47
|
});
|
|
@@ -69,12 +66,12 @@ class SDGTFLoader {
|
|
|
69
66
|
throw new Error('Accessor not available.');
|
|
70
67
|
const accessor = this._content.accessors[accessorName];
|
|
71
68
|
const bufferView = this._body;
|
|
72
|
-
const itemSize =
|
|
73
|
-
const ArrayType =
|
|
69
|
+
const itemSize = ACCESSORTYPE[accessor.type];
|
|
70
|
+
const ArrayType = ACCESSOR_COMPONENTTYPE[accessor.componentType];
|
|
74
71
|
const elementBytes = ArrayType.BYTES_PER_ELEMENT;
|
|
75
72
|
const itemBytes = elementBytes * itemSize;
|
|
76
73
|
const byteOffset = accessor.byteOffset || 0;
|
|
77
|
-
return new
|
|
74
|
+
return new AttributeData(new ArrayType(bufferView, byteOffset, itemSize * accessor.count), itemSize, itemBytes, byteOffset, elementBytes, false, accessor.count);
|
|
78
75
|
});
|
|
79
76
|
}
|
|
80
77
|
loadArcs() {
|
|
@@ -82,22 +79,22 @@ class SDGTFLoader {
|
|
|
82
79
|
if (!this._content.arcs)
|
|
83
80
|
throw new Error('Arcs not available.');
|
|
84
81
|
const arc = this._content.arcs;
|
|
85
|
-
const arcNode = new
|
|
82
|
+
const arcNode = new TreeNode('arcs');
|
|
86
83
|
const data = yield this.loadAccessor(arc.attributes['ARCS']);
|
|
87
84
|
// data with an absolute classic array of Vec12s ...
|
|
88
85
|
// like you usually have it in any good program
|
|
89
86
|
// not 4 Vec3s, no, that would be to logic, but a Vec12 instead
|
|
90
87
|
const count = data.array.length / data.itemSize;
|
|
91
88
|
for (let i = 0; i < count; ++i) {
|
|
92
|
-
const singleArcNode = new
|
|
89
|
+
const singleArcNode = new TreeNode('arc_' + i);
|
|
93
90
|
const index = i * 12;
|
|
94
|
-
const arcCenter =
|
|
95
|
-
const arcXAxis =
|
|
96
|
-
const arcYAxis =
|
|
91
|
+
const arcCenter = vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
|
|
92
|
+
const arcXAxis = vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
|
|
93
|
+
const arcYAxis = vec3.fromValues(data.array[index + 6], data.array[index + 7], data.array[index + 8]);
|
|
97
94
|
const arcRadius = data.array[index + 9];
|
|
98
95
|
const arcMinAngle = data.array[index + 10];
|
|
99
96
|
const arcMaxAngle = data.array[index + 11];
|
|
100
|
-
const arcZAxis =
|
|
97
|
+
const arcZAxis = vec3.cross(vec3.create(), arcXAxis, arcYAxis);
|
|
101
98
|
if (arcRadius <= 0) {
|
|
102
99
|
this._logger.warn('SDGTFLoader.loadArcs: Arc radius is <= 0.');
|
|
103
100
|
continue;
|
|
@@ -123,14 +120,14 @@ class SDGTFLoader {
|
|
|
123
120
|
getPointOnArc(d / numberOfPoints);
|
|
124
121
|
const array = new Float32Array(points);
|
|
125
122
|
const attributes = {};
|
|
126
|
-
attributes['POSITION'] = new
|
|
127
|
-
const geometry = new
|
|
123
|
+
attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
|
|
124
|
+
const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
|
|
128
125
|
singleArcNode.data.push(geometry);
|
|
129
126
|
singleArcNode.addTransformation({
|
|
130
127
|
id: 'arc_' + i + '_translation',
|
|
131
|
-
matrix:
|
|
128
|
+
matrix: mat4.translate(mat4.create(), mat4.create(), vec3.fromValues(arcCenter[0], arcCenter[1], arcCenter[2]))
|
|
132
129
|
});
|
|
133
|
-
const arcRotationMatrix =
|
|
130
|
+
const arcRotationMatrix = mat4.transpose(mat4.create(), mat4.fromValues(arcXAxis[0], arcYAxis[0], arcZAxis[0], 0, arcXAxis[1], arcYAxis[1], arcZAxis[1], 0, arcXAxis[2], arcYAxis[2], arcZAxis[2], 0, 0, 0, 0, 1));
|
|
134
131
|
singleArcNode.addTransformation({
|
|
135
132
|
id: 'arc_' + i + '_rotation',
|
|
136
133
|
matrix: arcRotationMatrix
|
|
@@ -145,11 +142,11 @@ class SDGTFLoader {
|
|
|
145
142
|
if (!this._content.beziercurves[beziercurveName])
|
|
146
143
|
throw new Error('Beziercurve not available.');
|
|
147
144
|
const beziercurve = this._content.beziercurves[beziercurveName];
|
|
148
|
-
const beziercurveNode = new
|
|
145
|
+
const beziercurveNode = new TreeNode(beziercurveName);
|
|
149
146
|
const controlPointsData = yield this.loadAccessor(beziercurve.attributes['CONTROLPOINTS']); // vec3
|
|
150
147
|
const controlPoints = [];
|
|
151
148
|
for (let i = 0; i < controlPointsData.array.length; i += 3)
|
|
152
|
-
controlPoints.push(
|
|
149
|
+
controlPoints.push(vec4.fromValues(controlPointsData.array[i], controlPointsData.array[i + 1], controlPointsData.array[i + 2], 1));
|
|
153
150
|
const knotsData = yield this.loadAccessor(beziercurve.attributes['KNOTS']); // scalar
|
|
154
151
|
const knots = [knotsData.array[0]];
|
|
155
152
|
for (let i = 0; i < knotsData.array.length; i++)
|
|
@@ -199,12 +196,12 @@ class SDGTFLoader {
|
|
|
199
196
|
const calcBSplinePoint = (u) => {
|
|
200
197
|
const span = findSpan(u);
|
|
201
198
|
const N = calcBasisFunctions(span, u);
|
|
202
|
-
const C =
|
|
199
|
+
const C = vec4.create();
|
|
203
200
|
for (let j = 0; j <= degree; ++j) {
|
|
204
201
|
const point = controlPoints[span - degree + j];
|
|
205
202
|
const Nj = N[j];
|
|
206
203
|
const wNj = point[3] * Nj;
|
|
207
|
-
|
|
204
|
+
vec4.add(C, C, vec4.fromValues(point[0] * wNj, point[1] * wNj, point[2] * wNj, point[3] * Nj));
|
|
208
205
|
}
|
|
209
206
|
return C;
|
|
210
207
|
};
|
|
@@ -215,7 +212,7 @@ class SDGTFLoader {
|
|
|
215
212
|
let hpoint = calcBSplinePoint(u);
|
|
216
213
|
if (hpoint[3] !== 1.0) {
|
|
217
214
|
// project to 3D space: (wx, wy, wz, w) -> (x, y, z, 1)
|
|
218
|
-
hpoint =
|
|
215
|
+
hpoint = vec4.divide(vec4.create(), hpoint, vec4.fromValues(hpoint[3], hpoint[3], hpoint[3], hpoint[3]));
|
|
219
216
|
}
|
|
220
217
|
points.push(hpoint[0], hpoint[1], hpoint[2]);
|
|
221
218
|
};
|
|
@@ -223,14 +220,14 @@ class SDGTFLoader {
|
|
|
223
220
|
// We go through the control points, measure the distance
|
|
224
221
|
let distance = 0;
|
|
225
222
|
for (let i = 1; i < controlPoints.length; i++)
|
|
226
|
-
distance +=
|
|
223
|
+
distance += vec3.distance(vec3.fromValues(controlPoints[i - 1][0], controlPoints[i - 1][1], controlPoints[i - 1][2]), vec3.fromValues(controlPoints[i][0], controlPoints[i][1], controlPoints[i][2]));
|
|
227
224
|
const numberOfPoints = Math.min(100, Math.max(25, Math.floor(distance / 0.1)));
|
|
228
225
|
for (let d = 0; d <= numberOfPoints; d++)
|
|
229
226
|
getPointOnBezierCurve(d / numberOfPoints);
|
|
230
227
|
const array = new Float32Array(points);
|
|
231
228
|
const attributes = {};
|
|
232
|
-
attributes['POSITION'] = new
|
|
233
|
-
const geometry = new
|
|
229
|
+
attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
|
|
230
|
+
const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
|
|
234
231
|
beziercurveNode.data.push(geometry);
|
|
235
232
|
return beziercurveNode;
|
|
236
233
|
});
|
|
@@ -240,17 +237,17 @@ class SDGTFLoader {
|
|
|
240
237
|
if (!this._content.circles)
|
|
241
238
|
throw new Error('Circles not available.');
|
|
242
239
|
const circle = this._content.circles;
|
|
243
|
-
const circleNode = new
|
|
240
|
+
const circleNode = new TreeNode('circles');
|
|
244
241
|
const data = yield this.loadAccessor(circle.attributes['CIRCLES']);
|
|
245
242
|
const count = data.array.length / data.itemSize;
|
|
246
243
|
for (let i = 0; i < count; i++) {
|
|
247
|
-
const singleCircleNode = new
|
|
244
|
+
const singleCircleNode = new TreeNode('circle_' + i);
|
|
248
245
|
const index = i * 10;
|
|
249
|
-
const circleCenter =
|
|
250
|
-
const circleXAxis =
|
|
251
|
-
const circleYAxis =
|
|
246
|
+
const circleCenter = vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
|
|
247
|
+
const circleXAxis = vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
|
|
248
|
+
const circleYAxis = vec3.fromValues(data.array[index + 6], data.array[index + 7], data.array[index + 8]);
|
|
252
249
|
const circleRadius = data.array[index + 9];
|
|
253
|
-
const circleZAxis =
|
|
250
|
+
const circleZAxis = vec3.cross(vec3.create(), circleXAxis, circleYAxis);
|
|
254
251
|
if (circleRadius <= 0) {
|
|
255
252
|
this._logger.warn('SDGTFLoader.loadCircles: Circle radius is <= 0.');
|
|
256
253
|
continue;
|
|
@@ -276,14 +273,14 @@ class SDGTFLoader {
|
|
|
276
273
|
getPointOnArc(d / numberOfPoints);
|
|
277
274
|
const array = new Float32Array(points);
|
|
278
275
|
const attributes = {};
|
|
279
|
-
attributes['POSITION'] = new
|
|
280
|
-
const geometry = new
|
|
276
|
+
attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
|
|
277
|
+
const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
|
|
281
278
|
singleCircleNode.data.push(geometry);
|
|
282
279
|
singleCircleNode.addTransformation({
|
|
283
280
|
id: 'circle_' + i + '_translation',
|
|
284
|
-
matrix:
|
|
281
|
+
matrix: mat4.translate(mat4.create(), mat4.create(), vec3.fromValues(circleCenter[0], circleCenter[1], circleCenter[2]))
|
|
285
282
|
});
|
|
286
|
-
const circleRotationMatrix =
|
|
283
|
+
const circleRotationMatrix = mat4.transpose(mat4.create(), mat4.fromValues(circleXAxis[0], circleYAxis[0], circleZAxis[0], 0, circleXAxis[1], circleYAxis[1], circleZAxis[1], 0, circleXAxis[2], circleYAxis[2], circleZAxis[2], 0, 0, 0, 0, 1));
|
|
287
284
|
singleCircleNode.addTransformation({
|
|
288
285
|
id: 'circle_' + i + '_rotation',
|
|
289
286
|
matrix: circleRotationMatrix
|
|
@@ -298,29 +295,29 @@ class SDGTFLoader {
|
|
|
298
295
|
if (!this._content.cylinders)
|
|
299
296
|
throw new Error('Cylinders not available.');
|
|
300
297
|
const cylinder = this._content.cylinders;
|
|
301
|
-
const cylinderNode = new
|
|
298
|
+
const cylinderNode = new TreeNode('cylinders');
|
|
302
299
|
const data = yield this.loadAccessor(cylinder.attributes['CYLINDERS']);
|
|
303
300
|
const count = data.array.length / data.itemSize;
|
|
304
301
|
for (let i = 0; i < count; i++) {
|
|
305
|
-
const singleCylinderNode = new
|
|
302
|
+
const singleCylinderNode = new TreeNode('cylinder_' + i);
|
|
306
303
|
const index = i * 7;
|
|
307
|
-
const cylinderTop =
|
|
308
|
-
const cylinderBottom =
|
|
304
|
+
const cylinderTop = vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
|
|
305
|
+
const cylinderBottom = vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
|
|
309
306
|
const cylinderRadius = data.array[index + 6];
|
|
310
|
-
const cylinderAxis =
|
|
311
|
-
const dotX = Math.abs(
|
|
312
|
-
const dotY = Math.abs(
|
|
307
|
+
const cylinderAxis = vec3.sub(vec3.create(), cylinderTop, cylinderBottom);
|
|
308
|
+
const dotX = Math.abs(vec3.dot(cylinderAxis, vec3.fromValues(1, 0, 0)));
|
|
309
|
+
const dotY = Math.abs(vec3.dot(cylinderAxis, vec3.fromValues(0, 1, 0)));
|
|
313
310
|
let cylinderXAxis;
|
|
314
311
|
if (dotX < dotY) {
|
|
315
|
-
cylinderXAxis =
|
|
312
|
+
cylinderXAxis = vec3.cross(vec3.create(), cylinderAxis, vec3.fromValues(1, 0, 0));
|
|
316
313
|
}
|
|
317
314
|
else {
|
|
318
|
-
cylinderXAxis =
|
|
315
|
+
cylinderXAxis = vec3.cross(vec3.create(), cylinderAxis, vec3.fromValues(0, 1, 0));
|
|
319
316
|
}
|
|
320
|
-
const cylinderYAxis =
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
317
|
+
const cylinderYAxis = vec3.cross(vec3.create(), cylinderAxis, cylinderXAxis);
|
|
318
|
+
vec3.normalize(cylinderAxis, cylinderAxis);
|
|
319
|
+
vec3.normalize(cylinderXAxis, cylinderXAxis);
|
|
320
|
+
vec3.normalize(cylinderYAxis, cylinderYAxis);
|
|
324
321
|
if (cylinderRadius <= 0) {
|
|
325
322
|
this._logger.warn('SDGTFLoader.loadCylinders: Cylinder radius is <= 0.');
|
|
326
323
|
continue;
|
|
@@ -329,14 +326,14 @@ class SDGTFLoader {
|
|
|
329
326
|
const vertices = [];
|
|
330
327
|
const normals = [];
|
|
331
328
|
const uvs = [];
|
|
332
|
-
const height =
|
|
329
|
+
const height = vec3.distance(cylinderTop, cylinderBottom);
|
|
333
330
|
const halfHeight = height / 2;
|
|
334
331
|
const thetaStart = 0, thetaLength = Math.PI * 2;
|
|
335
332
|
let indexCounter = 0;
|
|
336
333
|
const indexArray = [];
|
|
337
334
|
const heightSegments = 1, radialSegments = 50;
|
|
338
|
-
const normal =
|
|
339
|
-
const vertex =
|
|
335
|
+
const normal = vec3.create();
|
|
336
|
+
const vertex = vec3.create();
|
|
340
337
|
let groupCount = 0;
|
|
341
338
|
// this will be used to calculate the normal
|
|
342
339
|
const slope = 0;
|
|
@@ -357,7 +354,7 @@ class SDGTFLoader {
|
|
|
357
354
|
vertex[2] = radius * cosTheta;
|
|
358
355
|
vertices.push(vertex[0], vertex[1], vertex[2]);
|
|
359
356
|
// normal
|
|
360
|
-
|
|
357
|
+
vec3.normalize(normal, vec3.fromValues(sinTheta, slope, cosTheta));
|
|
361
358
|
normals.push(normal[0], normal[1], normal[2]);
|
|
362
359
|
// uv
|
|
363
360
|
uvs.push(u, 1 - v);
|
|
@@ -383,27 +380,27 @@ class SDGTFLoader {
|
|
|
383
380
|
}
|
|
384
381
|
}
|
|
385
382
|
const attributes = {};
|
|
386
|
-
attributes['POSITION'] = new
|
|
387
|
-
attributes['NORMAL'] = new
|
|
388
|
-
attributes['TEXCOORD_0'] = new
|
|
389
|
-
const geometry = new
|
|
383
|
+
attributes['POSITION'] = new AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
|
|
384
|
+
attributes['NORMAL'] = new AttributeData(new Float32Array(normals), 3, 0, 0, 0, false, normals.length / 3);
|
|
385
|
+
attributes['TEXCOORD_0'] = new AttributeData(new Float32Array(uvs), 2, 0, 0, 0, false, uvs.length / 2);
|
|
386
|
+
const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
|
|
390
387
|
singleCylinderNode.data.push(geometry);
|
|
391
388
|
singleCylinderNode.addTransformation({
|
|
392
389
|
id: 'cylinder_' + i + '_translation',
|
|
393
|
-
matrix:
|
|
390
|
+
matrix: mat4.translate(mat4.create(), mat4.create(), cylinderBottom)
|
|
394
391
|
});
|
|
395
|
-
const cylinderRotationMatrix =
|
|
392
|
+
const cylinderRotationMatrix = mat4.transpose(mat4.create(), mat4.fromValues(cylinderXAxis[0], cylinderYAxis[0], cylinderAxis[0], 0, cylinderXAxis[1], cylinderYAxis[1], cylinderAxis[1], 0, cylinderXAxis[2], cylinderYAxis[2], cylinderAxis[2], 0, 0, 0, 0, 1));
|
|
396
393
|
singleCylinderNode.addTransformation({
|
|
397
394
|
id: 'cylinder_' + i + '_rotation',
|
|
398
395
|
matrix: cylinderRotationMatrix
|
|
399
396
|
});
|
|
400
397
|
singleCylinderNode.addTransformation({
|
|
401
398
|
id: 'cylinder_' + i + '_rotation2',
|
|
402
|
-
matrix:
|
|
399
|
+
matrix: mat4.rotateX(mat4.create(), mat4.create(), 0.5 * Math.PI)
|
|
403
400
|
});
|
|
404
401
|
singleCylinderNode.addTransformation({
|
|
405
402
|
id: 'cylinder_' + i + '_translation2',
|
|
406
|
-
matrix:
|
|
403
|
+
matrix: mat4.translate(mat4.create(), mat4.create(), vec3.fromValues(0, 0, 0.5 * vec3.distance(cylinderTop, cylinderBottom)))
|
|
407
404
|
});
|
|
408
405
|
cylinderNode.addChild(singleCylinderNode);
|
|
409
406
|
}
|
|
@@ -415,13 +412,13 @@ class SDGTFLoader {
|
|
|
415
412
|
if (!this._content.spheres)
|
|
416
413
|
throw new Error('Spheres not available.');
|
|
417
414
|
const sphere = this._content.spheres;
|
|
418
|
-
const sphereNode = new
|
|
415
|
+
const sphereNode = new TreeNode('spheres');
|
|
419
416
|
const data = yield this.loadAccessor(sphere.attributes['SPHERES']);
|
|
420
417
|
const count = data.array.length / data.itemSize;
|
|
421
418
|
for (let i = 0; i < count; i++) {
|
|
422
|
-
const singleSphereNode = new
|
|
419
|
+
const singleSphereNode = new TreeNode('sphere_' + i);
|
|
423
420
|
const index = i * 4;
|
|
424
|
-
const sphereTranslation =
|
|
421
|
+
const sphereTranslation = vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
|
|
425
422
|
const sphereRadius = data.array[index + 3];
|
|
426
423
|
if (sphereRadius <= 0) {
|
|
427
424
|
this._logger.warn('SDGTFLoader.loadSpheres: Sphere radius is <= 0.');
|
|
@@ -453,10 +450,10 @@ class SDGTFLoader {
|
|
|
453
450
|
for (let ix = 0; ix <= widthSegments; ix++) {
|
|
454
451
|
const u = ix / widthSegments;
|
|
455
452
|
// vertex
|
|
456
|
-
const vertex =
|
|
453
|
+
const vertex = vec3.fromValues(-sphereRadius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength), sphereRadius * Math.cos(thetaStart + v * thetaLength), sphereRadius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength));
|
|
457
454
|
vertices.push(vertex[0], vertex[1], vertex[2]);
|
|
458
455
|
// normal
|
|
459
|
-
const normal =
|
|
456
|
+
const normal = vec3.normalize(vec3.create(), vertex);
|
|
460
457
|
normals.push(normal[0], normal[1], normal[2]);
|
|
461
458
|
// uv
|
|
462
459
|
uvs.push(u + uOffset, 1 - v);
|
|
@@ -478,14 +475,14 @@ class SDGTFLoader {
|
|
|
478
475
|
}
|
|
479
476
|
}
|
|
480
477
|
const attributes = {};
|
|
481
|
-
attributes['POSITION'] = new
|
|
482
|
-
attributes['NORMAL'] = new
|
|
483
|
-
attributes['TEXCOORD_0'] = new
|
|
484
|
-
const geometry = new
|
|
478
|
+
attributes['POSITION'] = new AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
|
|
479
|
+
attributes['NORMAL'] = new AttributeData(new Float32Array(normals), 3, 0, 0, 0, false, normals.length / 3);
|
|
480
|
+
attributes['TEXCOORD_0'] = new AttributeData(new Float32Array(uvs), 2, 0, 0, 0, false, uvs.length / 2);
|
|
481
|
+
const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
|
|
485
482
|
singleSphereNode.data.push(geometry);
|
|
486
483
|
singleSphereNode.addTransformation({
|
|
487
484
|
id: 'sphere_' + i + '_translation',
|
|
488
|
-
matrix:
|
|
485
|
+
matrix: mat4.translate(mat4.create(), mat4.create(), sphereTranslation)
|
|
489
486
|
});
|
|
490
487
|
sphereNode.addChild(singleSphereNode);
|
|
491
488
|
}
|
|
@@ -497,11 +494,11 @@ class SDGTFLoader {
|
|
|
497
494
|
if (!this._content.points[pointName])
|
|
498
495
|
throw new Error('Point not available.');
|
|
499
496
|
const point = this._content.points[pointName];
|
|
500
|
-
const pointNode = new
|
|
497
|
+
const pointNode = new TreeNode(pointName);
|
|
501
498
|
const attributes = {};
|
|
502
499
|
const data = yield this.loadAccessor(point.attributes['POINTS']);
|
|
503
|
-
attributes['POSITION'] = new
|
|
504
|
-
const geometry = new
|
|
500
|
+
attributes['POSITION'] = new AttributeData(data.array, 3, data.itemBytes, data.byteOffset, data.elementBytes, data.normalized, data.count);
|
|
501
|
+
const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.POINTS);
|
|
505
502
|
pointNode.data.push(geometry);
|
|
506
503
|
return pointNode;
|
|
507
504
|
});
|
|
@@ -511,11 +508,11 @@ class SDGTFLoader {
|
|
|
511
508
|
if (!this._content.polylines[polylineName])
|
|
512
509
|
throw new Error('Polyline not available.');
|
|
513
510
|
const polyLine = this._content.polylines[polylineName];
|
|
514
|
-
const polyLineNode = new
|
|
511
|
+
const polyLineNode = new TreeNode(polylineName);
|
|
515
512
|
const attributes = {};
|
|
516
513
|
const data = yield this.loadAccessor(polyLine.attributes['VERTICES']);
|
|
517
|
-
attributes['POSITION'] = new
|
|
518
|
-
const geometry = new
|
|
514
|
+
attributes['POSITION'] = new AttributeData(data.array, 3, data.itemBytes, data.byteOffset, data.elementBytes, data.normalized, data.count);
|
|
515
|
+
const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
|
|
519
516
|
polyLineNode.data.push(geometry);
|
|
520
517
|
return polyLineNode;
|
|
521
518
|
});
|
|
@@ -525,7 +522,7 @@ class SDGTFLoader {
|
|
|
525
522
|
if (!this._content.surfacepatches[surfacepatchName])
|
|
526
523
|
throw new Error('Surfacepatch not available.');
|
|
527
524
|
const surfacepatch = this._content.surfacepatches[surfacepatchName];
|
|
528
|
-
const surfacepatchNode = new
|
|
525
|
+
const surfacepatchNode = new TreeNode(surfacepatchName);
|
|
529
526
|
const controlPointCountU = surfacepatch.controlPointCountU;
|
|
530
527
|
const controlPointCountV = surfacepatch.controlPointCountV;
|
|
531
528
|
const controlPointsData = yield this.loadAccessor(surfacepatch.attributes['CONTROLPOINTS']); // vec3
|
|
@@ -534,7 +531,7 @@ class SDGTFLoader {
|
|
|
534
531
|
for (let u = 0; u < controlPointCountU; u++) {
|
|
535
532
|
let innerArray = [];
|
|
536
533
|
for (let v = 0; v < controlPointCountV; v++) {
|
|
537
|
-
innerArray.push(
|
|
534
|
+
innerArray.push(vec4.fromValues(controlPointsData.array[pointCount * 3], controlPointsData.array[pointCount * 3 + 1], controlPointsData.array[pointCount * 3 + 2], 1));
|
|
538
535
|
pointCount++;
|
|
539
536
|
}
|
|
540
537
|
controlPoints.push(innerArray);
|
|
@@ -598,22 +595,22 @@ class SDGTFLoader {
|
|
|
598
595
|
const Nv = calcBasisFunctions(knotsV, degreeV, vspan, v);
|
|
599
596
|
const temp = [];
|
|
600
597
|
for (let l = 0; l <= degreeV; ++l) {
|
|
601
|
-
temp[l] =
|
|
598
|
+
temp[l] = vec4.create();
|
|
602
599
|
for (let k = 0; k <= degreeU; ++k) {
|
|
603
|
-
const point =
|
|
600
|
+
const point = vec4.clone(controlPoints[uspan - degreeU + k][vspan - degreeV + l]);
|
|
604
601
|
const w = point[3];
|
|
605
602
|
point[0] *= w;
|
|
606
603
|
point[1] *= w;
|
|
607
604
|
point[2] *= w;
|
|
608
|
-
|
|
605
|
+
vec4.add(temp[l], temp[l], vec4.multiply(vec4.create(), point, vec4.fromValues(Nu[k], Nu[k], Nu[k], Nu[k])));
|
|
609
606
|
}
|
|
610
607
|
}
|
|
611
|
-
const Sw =
|
|
608
|
+
const Sw = vec4.create();
|
|
612
609
|
for (let l = 0; l <= degreeV; ++l) {
|
|
613
|
-
|
|
610
|
+
vec4.add(Sw, Sw, vec4.multiply(vec4.create(), temp[l], vec4.fromValues(Nv[l], Nv[l], Nv[l], Nv[l])));
|
|
614
611
|
}
|
|
615
|
-
|
|
616
|
-
return
|
|
612
|
+
vec4.divide(Sw, Sw, vec4.fromValues(Sw[3], Sw[3], Sw[3], Sw[3]));
|
|
613
|
+
return vec3.fromValues(Sw[0], Sw[1], Sw[2]);
|
|
617
614
|
};
|
|
618
615
|
const getPointOnSurfacepatch = (t1, t2) => {
|
|
619
616
|
const u = knotsU[0] + t1 * (knotsU[knotsU.length - 1] - knotsU[0]); // linear mapping t1->u
|
|
@@ -643,18 +640,18 @@ class SDGTFLoader {
|
|
|
643
640
|
}
|
|
644
641
|
}
|
|
645
642
|
const attributes = {};
|
|
646
|
-
attributes['POSITION'] = new
|
|
643
|
+
attributes['POSITION'] = new AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
|
|
647
644
|
// to not compute normals ourselves, we just let three.js do it
|
|
648
645
|
// in our geometry loader, this array will cause the computation of vertex normals
|
|
649
|
-
attributes['NORMAL'] = new
|
|
650
|
-
const geometry = new
|
|
646
|
+
attributes['NORMAL'] = new AttributeData(new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 3, 0, 0, 0, false, vertices.length / 3);
|
|
647
|
+
const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
|
|
651
648
|
surfacepatchNode.data.push(geometry);
|
|
652
649
|
return surfacepatchNode;
|
|
653
650
|
});
|
|
654
651
|
}
|
|
655
652
|
loadScene() {
|
|
656
653
|
return __awaiter(this, void 0, void 0, function* () {
|
|
657
|
-
const sceneNode = new
|
|
654
|
+
const sceneNode = new TreeNode('sdgtf_content');
|
|
658
655
|
// arcs
|
|
659
656
|
if (this._content.arcs)
|
|
660
657
|
sceneNode.addChild(yield this.loadArcs());
|
|
@@ -691,5 +688,4 @@ class SDGTFLoader {
|
|
|
691
688
|
});
|
|
692
689
|
}
|
|
693
690
|
}
|
|
694
|
-
exports.SDGTFLoader = SDGTFLoader;
|
|
695
691
|
//# sourceMappingURL=SDGTFLoader.js.map
|