@shapediver/viewer.data-engine.geometry-engine 3.9.0 → 3.9.1
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/README.md +1 -1
- package/dist/GeometryEngine.d.ts +2 -2
- package/dist/GeometryEngine.d.ts.map +1 -1
- package/dist/GeometryEngine.js +47 -30
- package/dist/GeometryEngine.js.map +1 -1
- package/dist/gltfv1/GLTFLoader.d.ts +2 -2
- package/dist/gltfv1/GLTFLoader.d.ts.map +1 -1
- package/dist/gltfv1/GLTFLoader.js +143 -75
- package/dist/gltfv1/GLTFLoader.js.map +1 -1
- package/dist/gltfv1/SDGTFLoader.d.ts +1 -1
- package/dist/gltfv1/SDGTFLoader.d.ts.map +1 -1
- package/dist/gltfv1/SDGTFLoader.js +95 -74
- package/dist/gltfv1/SDGTFLoader.js.map +1 -1
- package/dist/gltfv2/GLTFLoader.d.ts +6 -6
- package/dist/gltfv2/GLTFLoader.d.ts.map +1 -1
- package/dist/gltfv2/GLTFLoader.js +200 -112
- package/dist/gltfv2/GLTFLoader.js.map +1 -1
- package/dist/gltfv2/draco/draco_decoder.d.ts.map +1 -1
- package/dist/gltfv2/draco/draco_decoder.js +101696 -49810
- package/dist/gltfv2/draco/draco_decoder.js.map +1 -1
- package/dist/gltfv2/loaders/AccessorLoader.d.ts +3 -3
- package/dist/gltfv2/loaders/AccessorLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/AccessorLoader.js +21 -13
- package/dist/gltfv2/loaders/AccessorLoader.js.map +1 -1
- package/dist/gltfv2/loaders/BufferLoader.d.ts +1 -1
- package/dist/gltfv2/loaders/BufferLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/BufferLoader.js +10 -8
- package/dist/gltfv2/loaders/BufferLoader.js.map +1 -1
- package/dist/gltfv2/loaders/BufferViewLoader.d.ts +2 -2
- package/dist/gltfv2/loaders/BufferViewLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/BufferViewLoader.js +5 -5
- package/dist/gltfv2/loaders/BufferViewLoader.js.map +1 -1
- package/dist/gltfv2/loaders/GeometryLoader.d.ts +7 -7
- package/dist/gltfv2/loaders/GeometryLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/GeometryLoader.js +39 -28
- package/dist/gltfv2/loaders/GeometryLoader.js.map +1 -1
- package/dist/gltfv2/loaders/MaterialLoader.d.ts +3 -3
- package/dist/gltfv2/loaders/MaterialLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/MaterialLoader.js +301 -108
- package/dist/gltfv2/loaders/MaterialLoader.js.map +1 -1
- package/dist/gltfv2/loaders/TextureLoader.d.ts +2 -2
- package/dist/gltfv2/loaders/TextureLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/TextureLoader.js +23 -15
- package/dist/gltfv2/loaders/TextureLoader.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +57 -57
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLTFLoader.d.ts","sourceRoot":"","sources":["../../src/gltfv2/GLTFLoader.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"GLTFLoader.d.ts","sourceRoot":"","sources":["../../src/gltfv2/GLTFLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,6CAA6C,CAAC;AAWrE,OAAO,EAAC,SAAS,EAAW,MAAM,qCAAqC,CAAC;AA8BxE,oBAAY,eAAe;IAC1B,eAAe,oBAAoB;IACnC,0BAA0B,+BAA+B;IACzD,mBAAmB,wBAAwB;IAC3C,uBAAuB,4BAA4B;IACnD,iBAAiB,sBAAsB;IACvC,mCAAmC,wCAAwC;IAC3E,mBAAmB,wBAAwB;IAC3C,sBAAsB,2BAA2B;IACjD,0BAA0B,+BAA+B;IACzD,mBAAmB,wBAAwB;IAC3C,sBAAsB,2BAA2B;IACjD,oBAAoB,yBAAyB;IAC7C,qBAAqB,0BAA0B;IAC/C,qBAAqB,0BAA0B;IAC/C,2BAA2B,gCAAgC;IAC3D,uBAAuB,4BAA4B;CACnD;AAKD,qBAAa,UAAU;IAGtB,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAM;IACrD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqC;IAClE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAiBpC;IACF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAiC;IACvE,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAO;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyC;IAExE,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,MAAM,CAEP;IACP,OAAO,CAAC,uBAAuB,CAAK;IACpC,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,cAAc,CAAiB;IAM1B,IAAI,CAChB,OAAO,EAAE,QAAQ,EACjB,UAAU,CAAC,EAAE,WAAW,EACxB,UAAU,CAAC,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;KACtB,EACD,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC;IA6JR,WAAW,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IA8FtE;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAiDrB,OAAO,CAAC,UAAU;IAmClB,OAAO,CAAC,UAAU;YAsFJ,QAAQ;YAkPR,SAAS;IAkBvB,OAAO,CAAC,QAAQ;IA2BhB,OAAO,CAAC,4BAA4B;CA4EpC"}
|
|
@@ -10,18 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.GLTFLoader = exports.GLTF_EXTENSIONS = void 0;
|
|
13
|
+
const viewer_rendering_engine_camera_engine_1 = require("@shapediver/viewer.rendering-engine.camera-engine");
|
|
14
|
+
const viewer_rendering_engine_light_engine_1 = require("@shapediver/viewer.rendering-engine.light-engine");
|
|
13
15
|
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
14
16
|
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
15
|
-
const gl_matrix_1 = require("gl-matrix");
|
|
16
17
|
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
17
|
-
const
|
|
18
|
-
const
|
|
18
|
+
const gl_matrix_1 = require("gl-matrix");
|
|
19
|
+
const AccessorLoader_1 = require("./loaders/AccessorLoader");
|
|
19
20
|
const BufferLoader_1 = require("./loaders/BufferLoader");
|
|
20
21
|
const BufferViewLoader_1 = require("./loaders/BufferViewLoader");
|
|
21
|
-
const AccessorLoader_1 = require("./loaders/AccessorLoader");
|
|
22
|
-
const TextureLoader_1 = require("./loaders/TextureLoader");
|
|
23
|
-
const MaterialLoader_1 = require("./loaders/MaterialLoader");
|
|
24
22
|
const GeometryLoader_1 = require("./loaders/GeometryLoader");
|
|
23
|
+
const MaterialLoader_1 = require("./loaders/MaterialLoader");
|
|
24
|
+
const TextureLoader_1 = require("./loaders/TextureLoader");
|
|
25
25
|
var GLTF_EXTENSIONS;
|
|
26
26
|
(function (GLTF_EXTENSIONS) {
|
|
27
27
|
GLTF_EXTENSIONS["KHR_BINARY_GLTF"] = "KHR_binary_glTF";
|
|
@@ -42,7 +42,7 @@ var GLTF_EXTENSIONS;
|
|
|
42
42
|
GLTF_EXTENSIONS["EXT_MESH_GPU_INSTANCING"] = "EXT_mesh_gpu_instancing";
|
|
43
43
|
})(GLTF_EXTENSIONS = exports.GLTF_EXTENSIONS || (exports.GLTF_EXTENSIONS = {}));
|
|
44
44
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
45
|
-
const DRACO = require(
|
|
45
|
+
const DRACO = require("./draco/draco_decoder.js");
|
|
46
46
|
class GLTFLoader {
|
|
47
47
|
constructor() {
|
|
48
48
|
// #region Properties (22)
|
|
@@ -54,7 +54,7 @@ class GLTFLoader {
|
|
|
54
54
|
this._performanceEvaluator = viewer_shared_services_1.PerformanceEvaluator.instance;
|
|
55
55
|
this._progressUpdateLimit = 500;
|
|
56
56
|
this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
|
|
57
|
-
this._eventId =
|
|
57
|
+
this._eventId = "";
|
|
58
58
|
this._nodes = {};
|
|
59
59
|
this._numberOfConvertedNodes = 0;
|
|
60
60
|
this._numberOfNodes = 0;
|
|
@@ -67,14 +67,21 @@ class GLTFLoader {
|
|
|
67
67
|
var _a, _b;
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
69
|
this._eventId = taskEventId || this._uuidGenerator.create();
|
|
70
|
-
const eventStart = {
|
|
70
|
+
const eventStart = {
|
|
71
|
+
type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING,
|
|
72
|
+
id: this._eventId,
|
|
73
|
+
progress: 0,
|
|
74
|
+
status: "Starting glTF 2.0 loading.",
|
|
75
|
+
};
|
|
71
76
|
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
|
|
72
77
|
this._numberOfConvertedNodes = 0;
|
|
73
78
|
this._numberOfNodes = content.nodes ? content.nodes.length : 0;
|
|
74
79
|
this._progressTimer = performance.now();
|
|
75
80
|
this._baseUri = baseUri;
|
|
76
81
|
if (gltfBinary && gltfHeader)
|
|
77
|
-
this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH +
|
|
82
|
+
this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH +
|
|
83
|
+
gltfHeader.contentLength +
|
|
84
|
+
8, gltfHeader.length);
|
|
78
85
|
this._content = content;
|
|
79
86
|
this.validateVersionAndExtensions();
|
|
80
87
|
const dracoModule = yield new DRACO();
|
|
@@ -89,17 +96,25 @@ class GLTFLoader {
|
|
|
89
96
|
this._materialLoader = new MaterialLoader_1.MaterialLoader(this._content, this._textureLoader);
|
|
90
97
|
yield this._materialLoader.load();
|
|
91
98
|
this._geometryLoader = new GeometryLoader_1.GeometryLoader(this._content, this._accessorLoader, this._bufferViewLoader, this._materialLoader, dracoModule);
|
|
92
|
-
const eventProgressInit = {
|
|
99
|
+
const eventProgressInit = {
|
|
100
|
+
type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING,
|
|
101
|
+
id: this._eventId,
|
|
102
|
+
progress: 0.1,
|
|
103
|
+
status: "Initial logic of glTF loading.",
|
|
104
|
+
};
|
|
93
105
|
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventProgressInit);
|
|
94
106
|
const node = yield this.loadScene();
|
|
95
|
-
if (this._content.extensions &&
|
|
96
|
-
|
|
107
|
+
if (this._content.extensions &&
|
|
108
|
+
this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS]) {
|
|
109
|
+
const variants = this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS]
|
|
110
|
+
.variants;
|
|
97
111
|
for (let i = 0; i < variants.length; i++)
|
|
98
112
|
this._geometryLoader.materialVariantsData.variants.push(variants[i].name);
|
|
99
113
|
this._geometryLoader.materialVariantsData.variantIndex = 0;
|
|
100
114
|
node.data.push(this._geometryLoader.materialVariantsData);
|
|
101
115
|
}
|
|
102
|
-
if (this._content.skins !== undefined &&
|
|
116
|
+
if (this._content.skins !== undefined &&
|
|
117
|
+
this._content.nodes !== undefined) {
|
|
103
118
|
for (let i = 0; i < ((_a = this._content.nodes) === null || _a === void 0 ? void 0 : _a.length); i++) {
|
|
104
119
|
if (this._content.nodes[i].skin !== undefined) {
|
|
105
120
|
const skinDef = this.loadSkin(this._content.nodes[i].skin);
|
|
@@ -125,25 +140,34 @@ class GLTFLoader {
|
|
|
125
140
|
if (this._content.animations)
|
|
126
141
|
for (let i = 0; i < ((_b = this._content.animations) === null || _b === void 0 ? void 0 : _b.length); i++)
|
|
127
142
|
node.data.push(this.loadAnimation(i));
|
|
128
|
-
const eventEnd = {
|
|
143
|
+
const eventEnd = {
|
|
144
|
+
type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING,
|
|
145
|
+
id: this._eventId,
|
|
146
|
+
progress: 1,
|
|
147
|
+
status: "GlTF loading complete.",
|
|
148
|
+
};
|
|
129
149
|
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
130
150
|
return node;
|
|
131
151
|
});
|
|
132
152
|
}
|
|
133
153
|
loadWithUrl(url) {
|
|
134
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
this._performanceEvaluator.startSection(
|
|
136
|
-
this._performanceEvaluator.startSection(
|
|
137
|
-
const axiosResponse = yield this._httpClient.get(url, {
|
|
138
|
-
responseType:
|
|
139
|
-
});
|
|
140
|
-
this._performanceEvaluator.endSection(
|
|
155
|
+
this._performanceEvaluator.startSection("gltfProcessing." + url);
|
|
156
|
+
this._performanceEvaluator.startSection("loadGltf." + url);
|
|
157
|
+
const axiosResponse = (yield this._httpClient.get(url, {
|
|
158
|
+
responseType: "arraybuffer",
|
|
159
|
+
}));
|
|
160
|
+
this._performanceEvaluator.endSection("loadGltf." + url);
|
|
141
161
|
let gltfContent, gltfBinary, gltfBaseUrl, gltfHeader;
|
|
142
162
|
const magic = new TextDecoder().decode(new Uint8Array(axiosResponse.data, 0, 4));
|
|
143
|
-
const isBinary = magic ===
|
|
144
|
-
(axiosResponse.headers[
|
|
145
|
-
axiosResponse.headers[
|
|
146
|
-
|
|
163
|
+
const isBinary = magic === "glTF" ||
|
|
164
|
+
(axiosResponse.headers["content-type"] &&
|
|
165
|
+
(axiosResponse.headers["content-type"] ===
|
|
166
|
+
"model/gltf-binary" ||
|
|
167
|
+
axiosResponse.headers["content-type"] ===
|
|
168
|
+
"application/octet-stream" ||
|
|
169
|
+
axiosResponse.headers["content-type"] ===
|
|
170
|
+
"model/gltf.binary"));
|
|
147
171
|
if (isBinary) {
|
|
148
172
|
gltfBinary = axiosResponse.data;
|
|
149
173
|
// create header data
|
|
@@ -153,27 +177,32 @@ class GLTFLoader {
|
|
|
153
177
|
version: headerDataView.getUint32(4, true),
|
|
154
178
|
length: headerDataView.getUint32(8, true),
|
|
155
179
|
contentLength: headerDataView.getUint32(12, true),
|
|
156
|
-
contentFormat: headerDataView.getUint32(16, true)
|
|
180
|
+
contentFormat: headerDataView.getUint32(16, true),
|
|
157
181
|
};
|
|
158
|
-
if (gltfHeader.magic !=
|
|
159
|
-
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError(
|
|
182
|
+
if (gltfHeader.magic != "glTF")
|
|
183
|
+
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError("GLTFLoader.load: Invalid data: sdgTF magic wrong.");
|
|
160
184
|
// create content
|
|
161
185
|
const contentDataView = new DataView(gltfBinary, this.BINARY_EXTENSION_HEADER_LENGTH, gltfHeader.contentLength);
|
|
162
186
|
const contentDecoded = new TextDecoder().decode(contentDataView);
|
|
163
187
|
gltfContent = JSON.parse(contentDecoded);
|
|
164
188
|
// create body
|
|
165
|
-
this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH +
|
|
189
|
+
this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH +
|
|
190
|
+
gltfHeader.contentLength +
|
|
191
|
+
8, gltfHeader.length);
|
|
166
192
|
}
|
|
167
193
|
else {
|
|
168
194
|
gltfContent = JSON.parse(new TextDecoder().decode(axiosResponse.data));
|
|
169
195
|
const removeLastDirectoryPartOf = (the_url) => {
|
|
170
|
-
const dir_char = the_url.includes(
|
|
196
|
+
const dir_char = the_url.includes("/") ? "/" : "\\";
|
|
171
197
|
const the_arr = the_url.split(dir_char);
|
|
172
198
|
the_arr.pop();
|
|
173
199
|
return the_arr.join(dir_char);
|
|
174
200
|
};
|
|
175
201
|
gltfBaseUrl = removeLastDirectoryPartOf(url);
|
|
176
|
-
if (!gltfBaseUrl &&
|
|
202
|
+
if (!gltfBaseUrl &&
|
|
203
|
+
window &&
|
|
204
|
+
window.location &&
|
|
205
|
+
window.location.href)
|
|
177
206
|
gltfBaseUrl = removeLastDirectoryPartOf(window.location.href);
|
|
178
207
|
}
|
|
179
208
|
return yield this.load(gltfContent, gltfBinary, gltfHeader, gltfBaseUrl);
|
|
@@ -182,15 +211,15 @@ class GLTFLoader {
|
|
|
182
211
|
// #endregion Public Methods (2)
|
|
183
212
|
// #region Private Methods (7)
|
|
184
213
|
/**
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
214
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
|
|
215
|
+
* @param {number} animationIndex
|
|
216
|
+
* @return {Promise<AnimationClip>}
|
|
217
|
+
*/
|
|
189
218
|
loadAnimation(animationId) {
|
|
190
219
|
if (!this._content.animations)
|
|
191
|
-
throw new Error(
|
|
220
|
+
throw new Error("Animations not available.");
|
|
192
221
|
if (!this._content.animations[animationId])
|
|
193
|
-
throw new Error(
|
|
222
|
+
throw new Error("Animations not available.");
|
|
194
223
|
const animationDef = this._content.animations[animationId];
|
|
195
224
|
const animationTracks = [];
|
|
196
225
|
let min = Infinity, max = -Infinity;
|
|
@@ -201,36 +230,36 @@ class GLTFLoader {
|
|
|
201
230
|
const path = target.path;
|
|
202
231
|
const node = this._nodes[target.node];
|
|
203
232
|
if (node === undefined)
|
|
204
|
-
throw new Error(
|
|
233
|
+
throw new Error("Animation node not available.");
|
|
205
234
|
const input = this._accessorLoader.getAccessor(sampler.input);
|
|
206
235
|
min = Math.min(min, input.min[0]);
|
|
207
236
|
max = Math.max(max, input.max[0]);
|
|
208
237
|
const output = this._accessorLoader.getAccessor(sampler.output);
|
|
209
238
|
let interpolation = sampler.interpolation;
|
|
210
|
-
if (interpolation ===
|
|
211
|
-
this._logger.warn(
|
|
212
|
-
interpolation =
|
|
239
|
+
if (interpolation === "CUBICSPLINE") {
|
|
240
|
+
this._logger.warn("Animation with CUBICSPLINE interpolation is currently not supported. Assigning linear interpolation instead.");
|
|
241
|
+
interpolation = "linear";
|
|
213
242
|
}
|
|
214
243
|
animationTracks.push({
|
|
215
244
|
node,
|
|
216
245
|
times: input.array,
|
|
217
246
|
values: output.array,
|
|
218
247
|
path: path,
|
|
219
|
-
interpolation: interpolation === null || interpolation === void 0 ? void 0 : interpolation.toLowerCase()
|
|
248
|
+
interpolation: interpolation === null || interpolation === void 0 ? void 0 : interpolation.toLowerCase(),
|
|
220
249
|
});
|
|
221
250
|
}
|
|
222
|
-
return new viewer_shared_types_1.AnimationData(animationDef.name ||
|
|
251
|
+
return new viewer_shared_types_1.AnimationData(animationDef.name || "gltf_animation_" + animationId, animationTracks, min, max - min);
|
|
223
252
|
}
|
|
224
253
|
loadCamera(cameraId) {
|
|
225
254
|
if (!this._content.cameras)
|
|
226
|
-
throw new Error(
|
|
255
|
+
throw new Error("Cameras not available.");
|
|
227
256
|
if (!this._content.cameras[cameraId])
|
|
228
|
-
throw new Error(
|
|
257
|
+
throw new Error("Cameras not available.");
|
|
229
258
|
const cameraDef = this._content.cameras[cameraId];
|
|
230
|
-
const cameraNode = new viewer_shared_node_tree_1.TreeNode(cameraDef.name ||
|
|
259
|
+
const cameraNode = new viewer_shared_node_tree_1.TreeNode(cameraDef.name || "camera_" + cameraId);
|
|
231
260
|
cameraNode.originalName = cameraDef.name;
|
|
232
261
|
let cameraData;
|
|
233
|
-
if (cameraDef.type ===
|
|
262
|
+
if (cameraDef.type === "perspective") {
|
|
234
263
|
const perspectiveCameraDef = cameraDef.perspective;
|
|
235
264
|
cameraData = new viewer_rendering_engine_camera_engine_1.PerspectiveCamera(cameraNode.id);
|
|
236
265
|
cameraNode.data.push(cameraData);
|
|
@@ -255,26 +284,35 @@ class GLTFLoader {
|
|
|
255
284
|
return cameraNode;
|
|
256
285
|
}
|
|
257
286
|
loadLights(lightId) {
|
|
258
|
-
if (!this._content.extensions ||
|
|
287
|
+
if (!this._content.extensions ||
|
|
288
|
+
!this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL] ||
|
|
289
|
+
!this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL]
|
|
290
|
+
.lights)
|
|
259
291
|
throw new Error(`Extension ${GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL} not available.`);
|
|
260
|
-
if (!this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL]
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const
|
|
292
|
+
if (!this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL]
|
|
293
|
+
.lights[lightId])
|
|
294
|
+
throw new Error("Light not available.");
|
|
295
|
+
const lightDef = this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL]
|
|
296
|
+
.lights[lightId];
|
|
297
|
+
const lightNode = new viewer_shared_node_tree_1.TreeNode(lightDef.name || "light_" + lightId);
|
|
264
298
|
lightNode.originalName = lightDef.name;
|
|
265
|
-
let color =
|
|
299
|
+
let color = "#ffffffff";
|
|
266
300
|
if (lightDef.color !== undefined)
|
|
267
|
-
color = [
|
|
301
|
+
color = [
|
|
302
|
+
lightDef.color[0] * 255,
|
|
303
|
+
lightDef.color[1] * 255,
|
|
304
|
+
lightDef.color[2] * 255,
|
|
305
|
+
];
|
|
268
306
|
const range = lightDef.range !== undefined ? lightDef.range : 0;
|
|
269
307
|
let lightData;
|
|
270
|
-
if (lightDef.type ===
|
|
308
|
+
if (lightDef.type === "directional") {
|
|
271
309
|
lightData = new viewer_rendering_engine_light_engine_1.DirectionalLight({ color });
|
|
272
310
|
lightNode.data.push(lightData);
|
|
273
311
|
const directionalLightData = lightData;
|
|
274
312
|
if (lightDef.intensity !== undefined)
|
|
275
313
|
directionalLightData.intensity = lightDef.intensity;
|
|
276
314
|
}
|
|
277
|
-
else if (lightDef.type ===
|
|
315
|
+
else if (lightDef.type === "point") {
|
|
278
316
|
lightData = new viewer_rendering_engine_light_engine_1.PointLight({ color });
|
|
279
317
|
lightNode.data.push(lightData);
|
|
280
318
|
const pointLightData = lightData;
|
|
@@ -284,16 +322,24 @@ class GLTFLoader {
|
|
|
284
322
|
lightData.intensity = lightDef.intensity;
|
|
285
323
|
pointLightData.position = [0, 0, 0];
|
|
286
324
|
}
|
|
287
|
-
else if (lightDef.type ===
|
|
325
|
+
else if (lightDef.type === "spot") {
|
|
288
326
|
lightData = new viewer_rendering_engine_light_engine_1.SpotLight({ color });
|
|
289
327
|
lightNode.data.push(lightData);
|
|
290
328
|
lightDef.spot = lightDef.spot || {};
|
|
291
|
-
lightDef.spot.innerConeAngle =
|
|
292
|
-
|
|
329
|
+
lightDef.spot.innerConeAngle =
|
|
330
|
+
lightDef.spot.innerConeAngle !== undefined
|
|
331
|
+
? lightDef.spot.innerConeAngle
|
|
332
|
+
: 0;
|
|
333
|
+
lightDef.spot.outerConeAngle =
|
|
334
|
+
lightDef.spot.outerConeAngle !== undefined
|
|
335
|
+
? lightDef.spot.outerConeAngle
|
|
336
|
+
: Math.PI / 4.0;
|
|
293
337
|
const spotLightData = lightData;
|
|
294
338
|
spotLightData.distance = range;
|
|
295
339
|
spotLightData.angle = lightDef.spot.outerConeAngle;
|
|
296
|
-
spotLightData.penumbra =
|
|
340
|
+
spotLightData.penumbra =
|
|
341
|
+
1.0 -
|
|
342
|
+
lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
|
|
297
343
|
spotLightData.decay = 2;
|
|
298
344
|
if (lightDef.intensity !== undefined)
|
|
299
345
|
lightData.intensity = lightDef.intensity;
|
|
@@ -301,7 +347,7 @@ class GLTFLoader {
|
|
|
301
347
|
spotLightData.target = [0, 0, -1];
|
|
302
348
|
}
|
|
303
349
|
else {
|
|
304
|
-
throw new Error(
|
|
350
|
+
throw new Error("Unexpected light type: " + lightDef.type);
|
|
305
351
|
}
|
|
306
352
|
lightData.useNodeData = true;
|
|
307
353
|
return lightNode;
|
|
@@ -309,56 +355,66 @@ class GLTFLoader {
|
|
|
309
355
|
loadNode(nodeId) {
|
|
310
356
|
return __awaiter(this, void 0, void 0, function* () {
|
|
311
357
|
if (!this._content.nodes)
|
|
312
|
-
throw new Error(
|
|
358
|
+
throw new Error("Nodes not available.");
|
|
313
359
|
if (!this._content.nodes[nodeId])
|
|
314
|
-
throw new Error(
|
|
360
|
+
throw new Error("Node not available.");
|
|
315
361
|
const node = this._content.nodes[nodeId];
|
|
316
|
-
const nodeDef = new viewer_shared_node_tree_1.TreeNode(node.name ||
|
|
362
|
+
const nodeDef = new viewer_shared_node_tree_1.TreeNode(node.name || "node_" + nodeId);
|
|
317
363
|
nodeDef.originalName = node.name;
|
|
318
364
|
this._nodes[nodeId] = nodeDef;
|
|
319
365
|
if (node.matrix) {
|
|
320
366
|
nodeDef.addTransformation({
|
|
321
|
-
id:
|
|
322
|
-
matrix: gl_matrix_1.mat4.fromValues(node.matrix[0], node.matrix[1], node.matrix[2], node.matrix[3], node.matrix[4], node.matrix[5], node.matrix[6], node.matrix[7], node.matrix[8], node.matrix[9], node.matrix[10], node.matrix[11], node.matrix[12], node.matrix[13], node.matrix[14], node.matrix[15])
|
|
367
|
+
id: "gltf_matrix",
|
|
368
|
+
matrix: gl_matrix_1.mat4.fromValues(node.matrix[0], node.matrix[1], node.matrix[2], node.matrix[3], node.matrix[4], node.matrix[5], node.matrix[6], node.matrix[7], node.matrix[8], node.matrix[9], node.matrix[10], node.matrix[11], node.matrix[12], node.matrix[13], node.matrix[14], node.matrix[15]),
|
|
323
369
|
});
|
|
324
370
|
nodeDef.addTransformation({
|
|
325
|
-
id:
|
|
326
|
-
matrix: gl_matrix_1.mat4.create()
|
|
371
|
+
id: "gltf_matrix_translation",
|
|
372
|
+
matrix: gl_matrix_1.mat4.create(),
|
|
327
373
|
});
|
|
328
374
|
nodeDef.addTransformation({
|
|
329
|
-
id:
|
|
330
|
-
matrix: gl_matrix_1.mat4.create()
|
|
375
|
+
id: "gltf_matrix_rotation",
|
|
376
|
+
matrix: gl_matrix_1.mat4.create(),
|
|
331
377
|
});
|
|
332
378
|
nodeDef.addTransformation({
|
|
333
|
-
id:
|
|
334
|
-
matrix: gl_matrix_1.mat4.create()
|
|
379
|
+
id: "gltf_matrix_scale",
|
|
380
|
+
matrix: gl_matrix_1.mat4.create(),
|
|
335
381
|
});
|
|
336
382
|
}
|
|
337
383
|
else if (node.translation || node.scale || node.rotation) {
|
|
338
|
-
const matT = node.translation
|
|
339
|
-
|
|
340
|
-
|
|
384
|
+
const matT = node.translation
|
|
385
|
+
? gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(node.translation[0], node.translation[1], node.translation[2]))
|
|
386
|
+
: gl_matrix_1.mat4.create();
|
|
387
|
+
const matS = node.scale
|
|
388
|
+
? gl_matrix_1.mat4.fromScaling(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(node.scale[0], node.scale[1], node.scale[2]))
|
|
389
|
+
: gl_matrix_1.mat4.create();
|
|
390
|
+
const matR = node.rotation
|
|
391
|
+
? gl_matrix_1.mat4.fromQuat(gl_matrix_1.mat4.create(), gl_matrix_1.vec4.fromValues(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]))
|
|
392
|
+
: gl_matrix_1.mat4.create();
|
|
341
393
|
nodeDef.addTransformation({
|
|
342
|
-
id:
|
|
343
|
-
matrix: matT
|
|
394
|
+
id: "gltf_matrix_translation",
|
|
395
|
+
matrix: matT,
|
|
344
396
|
});
|
|
345
397
|
nodeDef.addTransformation({
|
|
346
|
-
id:
|
|
347
|
-
matrix: matR
|
|
398
|
+
id: "gltf_matrix_rotation",
|
|
399
|
+
matrix: matR,
|
|
348
400
|
});
|
|
349
401
|
nodeDef.addTransformation({
|
|
350
|
-
id:
|
|
351
|
-
matrix: matS
|
|
402
|
+
id: "gltf_matrix_scale",
|
|
403
|
+
matrix: matS,
|
|
352
404
|
});
|
|
353
405
|
}
|
|
354
406
|
const instanceTransformations = [];
|
|
355
|
-
if (node.extensions &&
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
|
|
407
|
+
if (node.extensions &&
|
|
408
|
+
node.extensions[GLTF_EXTENSIONS.EXT_MESH_GPU_INSTANCING]) {
|
|
409
|
+
const ext = node.extensions[GLTF_EXTENSIONS.EXT_MESH_GPU_INSTANCING]
|
|
410
|
+
.attributes;
|
|
411
|
+
if (ext["TRANSLATION"] && ext["ROTATION"] && ext["SCALE"]) {
|
|
412
|
+
const translationAttribute = this._accessorLoader.getAccessor(ext["TRANSLATION"]);
|
|
413
|
+
const rotationAttribute = this._accessorLoader.getAccessor(ext["ROTATION"]);
|
|
414
|
+
const scaleAttribute = this._accessorLoader.getAccessor(ext["SCALE"]);
|
|
415
|
+
if (translationAttribute &&
|
|
416
|
+
rotationAttribute &&
|
|
417
|
+
scaleAttribute) {
|
|
362
418
|
const translationMatrices = [];
|
|
363
419
|
for (let i = 0; i < translationAttribute.array.length; i += 3)
|
|
364
420
|
translationMatrices.push(gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(translationAttribute.array[i], translationAttribute.array[i + 1], translationAttribute.array[i + 2])));
|
|
@@ -368,7 +424,9 @@ class GLTFLoader {
|
|
|
368
424
|
const scaleMatrices = [];
|
|
369
425
|
for (let i = 0; i < scaleAttribute.array.length; i += 3)
|
|
370
426
|
scaleMatrices.push(gl_matrix_1.mat4.fromScaling(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(scaleAttribute.array[i], scaleAttribute.array[i + 1], scaleAttribute.array[i + 2])));
|
|
371
|
-
if (translationMatrices.length ===
|
|
427
|
+
if (translationMatrices.length ===
|
|
428
|
+
rotationMatrices.length &&
|
|
429
|
+
translationMatrices.length === scaleMatrices.length) {
|
|
372
430
|
for (let i = 0; i < translationMatrices.length; i++) {
|
|
373
431
|
const transformationMatrix = gl_matrix_1.mat4.create();
|
|
374
432
|
gl_matrix_1.mat4.multiply(transformationMatrix, translationMatrices[i], rotationMatrices[i]);
|
|
@@ -383,7 +441,8 @@ class GLTFLoader {
|
|
|
383
441
|
nodeDef.addChild(this._geometryLoader.loadMesh(node.mesh, node.weights, instanceTransformations));
|
|
384
442
|
if (node.camera !== undefined)
|
|
385
443
|
nodeDef.addChild(this.loadCamera(node.camera));
|
|
386
|
-
if (node.extensions &&
|
|
444
|
+
if (node.extensions &&
|
|
445
|
+
node.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL])
|
|
387
446
|
nodeDef.addChild(this.loadLights(node.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].light));
|
|
388
447
|
if (node.children) {
|
|
389
448
|
for (let i = 0, len = node.children.length; i < len; i++) {
|
|
@@ -396,11 +455,18 @@ class GLTFLoader {
|
|
|
396
455
|
nodeDef.data.push(customData);
|
|
397
456
|
}
|
|
398
457
|
this._numberOfConvertedNodes++;
|
|
399
|
-
if (performance.now() - this._progressTimer >
|
|
458
|
+
if (performance.now() - this._progressTimer >
|
|
459
|
+
this._progressUpdateLimit) {
|
|
400
460
|
this._progressTimer = performance.now();
|
|
401
|
-
const eventProgress = {
|
|
461
|
+
const eventProgress = {
|
|
462
|
+
type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING,
|
|
463
|
+
id: this._eventId,
|
|
464
|
+
progress: this._numberOfConvertedNodes / this._numberOfNodes / 2 +
|
|
465
|
+
0.1,
|
|
466
|
+
status: `GlTF conversion progress: ${this._numberOfConvertedNodes}/${this._numberOfNodes} nodes.`,
|
|
467
|
+
};
|
|
402
468
|
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventProgress);
|
|
403
|
-
yield new Promise(resolve => setTimeout(resolve, 0));
|
|
469
|
+
yield new Promise((resolve) => setTimeout(resolve, 0));
|
|
404
470
|
}
|
|
405
471
|
return nodeDef;
|
|
406
472
|
});
|
|
@@ -408,16 +474,16 @@ class GLTFLoader {
|
|
|
408
474
|
loadScene() {
|
|
409
475
|
return __awaiter(this, void 0, void 0, function* () {
|
|
410
476
|
if (!this._content.scenes)
|
|
411
|
-
throw new Error(
|
|
477
|
+
throw new Error("Scenes not available.");
|
|
412
478
|
const sceneId = this._content.scene || 0;
|
|
413
479
|
if (!this._content.scenes[sceneId])
|
|
414
|
-
throw new Error(
|
|
480
|
+
throw new Error("Scene not available.");
|
|
415
481
|
const scene = this._content.scenes[sceneId];
|
|
416
|
-
const sceneDef = new viewer_shared_node_tree_1.TreeNode(scene.name ||
|
|
482
|
+
const sceneDef = new viewer_shared_node_tree_1.TreeNode(scene.name || "scene_" + sceneId + "");
|
|
417
483
|
sceneDef.originalName = scene.name;
|
|
418
484
|
sceneDef.addTransformation({
|
|
419
485
|
id: this._uuidGenerator.create(),
|
|
420
|
-
matrix: this._globalTransformation
|
|
486
|
+
matrix: this._globalTransformation,
|
|
421
487
|
});
|
|
422
488
|
if (scene.nodes)
|
|
423
489
|
for (let i = 0, len = scene.nodes.length; i < len; i++)
|
|
@@ -427,13 +493,13 @@ class GLTFLoader {
|
|
|
427
493
|
}
|
|
428
494
|
loadSkin(skinId) {
|
|
429
495
|
if (!this._content.skins)
|
|
430
|
-
throw new Error(
|
|
496
|
+
throw new Error("Skins not available.");
|
|
431
497
|
if (!this._content.skins[skinId])
|
|
432
|
-
throw new Error(
|
|
498
|
+
throw new Error("Skin not available.");
|
|
433
499
|
const skinDef = this._content.skins[skinId];
|
|
434
500
|
const skinEntry = {
|
|
435
501
|
joints: skinDef.joints,
|
|
436
|
-
inverseBindMatrices: null
|
|
502
|
+
inverseBindMatrices: null,
|
|
437
503
|
};
|
|
438
504
|
if (skinDef.inverseBindMatrices === undefined) {
|
|
439
505
|
return skinEntry;
|
|
@@ -443,13 +509,15 @@ class GLTFLoader {
|
|
|
443
509
|
}
|
|
444
510
|
validateVersionAndExtensions() {
|
|
445
511
|
if (!this._content.asset)
|
|
446
|
-
throw new Error(
|
|
512
|
+
throw new Error("Asset not available.");
|
|
447
513
|
const asset = this._content.asset;
|
|
448
514
|
if (!asset.version)
|
|
449
|
-
throw new Error(
|
|
450
|
-
const version = asset.minVersion
|
|
451
|
-
|
|
452
|
-
|
|
515
|
+
throw new Error("Asset does not have a version.");
|
|
516
|
+
const version = asset.minVersion
|
|
517
|
+
? asset.minVersion
|
|
518
|
+
: asset.version;
|
|
519
|
+
if (!version.startsWith("2"))
|
|
520
|
+
throw new Error("Version of the glTF not supported.");
|
|
453
521
|
if (this._content.extensionsUsed) {
|
|
454
522
|
const notSupported = [];
|
|
455
523
|
for (let i = 0; i < this._content.extensionsUsed.length; i++) {
|
|
@@ -457,12 +525,22 @@ class GLTFLoader {
|
|
|
457
525
|
notSupported.push(this._content.extensionsUsed[i]);
|
|
458
526
|
}
|
|
459
527
|
if (notSupported.length > 0) {
|
|
460
|
-
let message =
|
|
528
|
+
let message = "Extension" + (notSupported.length === 1 ? " " : "s ");
|
|
461
529
|
notSupported.forEach((element, index) => {
|
|
462
|
-
message +=
|
|
530
|
+
message +=
|
|
531
|
+
'"' +
|
|
532
|
+
element +
|
|
533
|
+
'"' +
|
|
534
|
+
(index === notSupported.length - 1
|
|
535
|
+
? ""
|
|
536
|
+
: index === notSupported.length - 2
|
|
537
|
+
? " and "
|
|
538
|
+
: ", ");
|
|
463
539
|
});
|
|
464
|
-
message +=
|
|
465
|
-
|
|
540
|
+
message +=
|
|
541
|
+
(notSupported.length === 1 ? " is" : " are") +
|
|
542
|
+
" not supported, but used. Loading glTF regardless.";
|
|
543
|
+
this._logger.info("GLTFLoader.validateVersionAndExtensions: " + message);
|
|
466
544
|
}
|
|
467
545
|
}
|
|
468
546
|
if (this._content.extensionsRequired) {
|
|
@@ -472,11 +550,21 @@ class GLTFLoader {
|
|
|
472
550
|
notSupported.push(this._content.extensionsRequired[i]);
|
|
473
551
|
}
|
|
474
552
|
if (notSupported.length > 0) {
|
|
475
|
-
let message =
|
|
553
|
+
let message = "Extension" + (notSupported.length === 1 ? " " : "s ");
|
|
476
554
|
notSupported.forEach((element, index) => {
|
|
477
|
-
message +=
|
|
555
|
+
message +=
|
|
556
|
+
'"' +
|
|
557
|
+
element +
|
|
558
|
+
'"' +
|
|
559
|
+
(index === notSupported.length - 1
|
|
560
|
+
? ""
|
|
561
|
+
: index === notSupported.length - 2
|
|
562
|
+
? " and "
|
|
563
|
+
: ", ");
|
|
478
564
|
});
|
|
479
|
-
message +=
|
|
565
|
+
message +=
|
|
566
|
+
(notSupported.length === 1 ? " is" : " are") +
|
|
567
|
+
" not supported, but required. Aborting glTF loading.";
|
|
480
568
|
throw new Error(message);
|
|
481
569
|
}
|
|
482
570
|
}
|