@inweb/viewer-three 26.5.0 → 26.5.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/dist/plugins/components/AxesHelperComponent.js +65 -0
- package/dist/plugins/components/AxesHelperComponent.js.map +1 -0
- package/dist/plugins/components/AxesHelperComponent.min.js +1 -0
- package/dist/plugins/components/AxesHelperComponent.module.js +39 -0
- package/dist/plugins/components/AxesHelperComponent.module.js.map +1 -0
- package/dist/plugins/components/ExtentsHelperComponent.js +55 -0
- package/dist/plugins/components/ExtentsHelperComponent.js.map +1 -0
- package/dist/plugins/components/ExtentsHelperComponent.min.js +1 -0
- package/dist/plugins/components/ExtentsHelperComponent.module.js +29 -0
- package/dist/plugins/components/ExtentsHelperComponent.module.js.map +1 -0
- package/dist/plugins/components/LightHelperComponent.js +65 -0
- package/dist/plugins/components/LightHelperComponent.js.map +1 -0
- package/dist/plugins/components/LightHelperComponent.min.js +1 -0
- package/dist/plugins/components/LightHelperComponent.module.js +40 -0
- package/dist/plugins/components/LightHelperComponent.module.js.map +1 -0
- package/dist/plugins/loaders/IFCXLoader.js +887 -0
- package/dist/plugins/loaders/IFCXLoader.js.map +1 -0
- package/dist/plugins/loaders/IFCXLoader.min.js +1 -0
- package/dist/plugins/loaders/IFCXLoader.module.js +726 -0
- package/dist/plugins/loaders/IFCXLoader.module.js.map +1 -0
- package/dist/viewer-three.js +49075 -32407
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +2 -7
- package/dist/viewer-three.module.js +192 -86
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +51 -68
- package/lib/Viewer/loaders/GLTFFileLoader.d.ts +9 -0
- package/lib/Viewer/loaders/GLTFLoadingManager.d.ts +9 -3
- package/lib/Viewer/loaders/GLTFModelLoader.d.ts +8 -0
- package/lib/Viewer/loaders/index.d.ts +67 -0
- package/lib/index-umd.d.ts +1 -0
- package/lib/index.d.ts +6 -4
- package/package.json +10 -7
- package/{src/Viewer → plugins}/components/AxesHelperComponent.ts +4 -4
- package/{src/Viewer → plugins}/components/ExtentsHelperComponent.ts +4 -4
- package/{src/Viewer → plugins}/components/LightHelperComponent.ts +4 -4
- package/plugins/loaders/IFCX/IFCXLoader.ts +71 -0
- package/plugins/loaders/IFCX/render.js +701 -0
- package/plugins/loaders/IFCXFileLoader.ts +76 -0
- package/plugins/loaders/IFCXLoader.ts +30 -0
- package/plugins/loaders/IFCXModelLoader.ts +75 -0
- package/src/Viewer/Viewer.ts +101 -148
- package/src/Viewer/commands/Explode.ts +2 -2
- package/src/Viewer/components/index.ts +2 -8
- package/src/Viewer/loaders/GLTFFileLoader.ts +73 -0
- package/src/Viewer/loaders/GLTFLoadingManager.ts +16 -8
- package/src/Viewer/loaders/GLTFModelLoader.ts +74 -0
- package/src/Viewer/loaders/index.ts +99 -0
- package/src/index-umd.ts +30 -0
- package/src/index.ts +9 -5
- package/lib/Viewer/components/AxesHelperComponent.d.ts +0 -10
- package/lib/Viewer/components/ExtentsHelperComponent.d.ts +0 -9
- package/lib/Viewer/components/LightHelperComponent.d.ts +0 -9
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('@inweb/viewer-three'), require('three')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['@inweb/viewer-three', 'three'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ODA.Three, global.THREE));
|
|
5
|
+
})(this, (function (viewerThree, three) { 'use strict';
|
|
6
|
+
|
|
7
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
8
|
+
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
|
|
9
|
+
// All rights reserved.
|
|
10
|
+
//
|
|
11
|
+
// This software and its documentation and related materials are owned by
|
|
12
|
+
// the Alliance. The software may only be incorporated into application
|
|
13
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
14
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
15
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
16
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
17
|
+
// protected by copyright law and international treaty provisions. Application
|
|
18
|
+
// programs incorporating this software must include the following statement
|
|
19
|
+
// with their copyright notices:
|
|
20
|
+
//
|
|
21
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
22
|
+
// license agreement with Open Design Alliance.
|
|
23
|
+
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
|
|
24
|
+
// All rights reserved.
|
|
25
|
+
//
|
|
26
|
+
// By use of this software, its documentation or related materials, you
|
|
27
|
+
// acknowledge and accept the above terms.
|
|
28
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const THREE = {
|
|
32
|
+
Box3: three.Box3,
|
|
33
|
+
BufferAttribute: three.BufferAttribute,
|
|
34
|
+
BufferGeometry: three.BufferGeometry,
|
|
35
|
+
Color: three.Color,
|
|
36
|
+
Group: three.Group,
|
|
37
|
+
Line: three.Line,
|
|
38
|
+
LineBasicMaterial: three.LineBasicMaterial,
|
|
39
|
+
Matrix4: three.Matrix4,
|
|
40
|
+
Mesh: three.Mesh,
|
|
41
|
+
MeshBasicMaterial: three.MeshBasicMaterial,
|
|
42
|
+
PerspectiveCamera: three.PerspectiveCamera,
|
|
43
|
+
Scene: three.Scene,
|
|
44
|
+
Vector3: three.Vector3,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// composed-object.ts
|
|
48
|
+
function getChildByName(root, childName, skip = 0) {
|
|
49
|
+
let fragments = childName.replace(/^<\/|^\/|>$/g, "").split("/");
|
|
50
|
+
for (let i = 0; i < skip; ++i) {
|
|
51
|
+
fragments.shift();
|
|
52
|
+
}
|
|
53
|
+
let start = root;
|
|
54
|
+
while (fragments.length && start && start.children) {
|
|
55
|
+
// console.log(start, fragments[0]);
|
|
56
|
+
let f = fragments.shift();
|
|
57
|
+
start = start.children.find((i) => i.name.split("/").reverse()[0] === f);
|
|
58
|
+
}
|
|
59
|
+
if (fragments.length == 0) {
|
|
60
|
+
return start;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// compose-alpha.ts
|
|
65
|
+
function GetNode(node, path) {
|
|
66
|
+
if (path === "") return node;
|
|
67
|
+
let parts = path.split("/");
|
|
68
|
+
let child = node.children.get(parts[0]);
|
|
69
|
+
if (child) {
|
|
70
|
+
if (parts.length === 1) {
|
|
71
|
+
return child;
|
|
72
|
+
}
|
|
73
|
+
return GetNode(child, GetTail(path));
|
|
74
|
+
} else {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function GetHead(path) {
|
|
79
|
+
return path.split("/")[0];
|
|
80
|
+
}
|
|
81
|
+
function GetTail(path) {
|
|
82
|
+
let parts = path.split("/");
|
|
83
|
+
parts.shift();
|
|
84
|
+
return parts.join("/");
|
|
85
|
+
}
|
|
86
|
+
function MakeNode(node) {
|
|
87
|
+
return {
|
|
88
|
+
node,
|
|
89
|
+
children: /* @__PURE__ */ new Map(),
|
|
90
|
+
attributes: /* @__PURE__ */ new Map(),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function ConvertToCompositionNode(path, inputNodes) {
|
|
94
|
+
let compositionNode = {
|
|
95
|
+
path,
|
|
96
|
+
children: {},
|
|
97
|
+
inherits: {},
|
|
98
|
+
attributes: {},
|
|
99
|
+
};
|
|
100
|
+
inputNodes.forEach((node) => {
|
|
101
|
+
Object.keys(node.children).forEach((childName) => {
|
|
102
|
+
compositionNode.children[childName] = node.children[childName];
|
|
103
|
+
});
|
|
104
|
+
Object.keys(node.inherits).forEach((inheritName) => {
|
|
105
|
+
let ih = node.inherits[inheritName];
|
|
106
|
+
if (ih === null) {
|
|
107
|
+
delete compositionNode.inherits[inheritName];
|
|
108
|
+
} else {
|
|
109
|
+
compositionNode.inherits[inheritName] = ih;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Object.keys(node.attributes).forEach((attrName) => {
|
|
113
|
+
compositionNode.attributes[attrName] = node.attributes[attrName];
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return compositionNode;
|
|
117
|
+
}
|
|
118
|
+
function MMSet(map, key, value) {
|
|
119
|
+
if (map.has(key)) {
|
|
120
|
+
map.get(key)?.push(value);
|
|
121
|
+
} else {
|
|
122
|
+
map.set(key, [value]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function FindRootsOrCycles(nodes) {
|
|
126
|
+
let dependencies = /* @__PURE__ */ new Map();
|
|
127
|
+
let dependents = /* @__PURE__ */ new Map();
|
|
128
|
+
nodes.forEach((node, path) => {
|
|
129
|
+
Object.keys(node.inherits).forEach((inheritName) => {
|
|
130
|
+
MMSet(dependencies, path, node.inherits[inheritName]);
|
|
131
|
+
MMSet(dependents, node.inherits[inheritName], path);
|
|
132
|
+
});
|
|
133
|
+
Object.keys(node.children).forEach((childName) => {
|
|
134
|
+
MMSet(dependencies, path, node.children[childName]);
|
|
135
|
+
MMSet(dependents, node.children[childName], path);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
let paths = [...nodes.keys()];
|
|
139
|
+
let perm = {};
|
|
140
|
+
let temp = {};
|
|
141
|
+
function visit(path) {
|
|
142
|
+
if (perm[path]) return;
|
|
143
|
+
if (temp[path]) throw new Error(`CYCLE!`);
|
|
144
|
+
temp[path] = true;
|
|
145
|
+
let deps = dependencies.get(path);
|
|
146
|
+
if (deps) {
|
|
147
|
+
deps.forEach((dep) => visit(dep));
|
|
148
|
+
}
|
|
149
|
+
perm[path] = true;
|
|
150
|
+
}
|
|
151
|
+
let roots = /* @__PURE__ */ new Set();
|
|
152
|
+
try {
|
|
153
|
+
paths.forEach((path) => {
|
|
154
|
+
if (!dependents.has(path) && path.indexOf("/") === -1) {
|
|
155
|
+
roots.add(path);
|
|
156
|
+
}
|
|
157
|
+
visit(path);
|
|
158
|
+
});
|
|
159
|
+
} catch {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return roots;
|
|
163
|
+
}
|
|
164
|
+
function ConvertNodes(input) {
|
|
165
|
+
let compositionNodes = /* @__PURE__ */ new Map();
|
|
166
|
+
for (let [path, inputNodes] of input) {
|
|
167
|
+
compositionNodes.set(path, ConvertToCompositionNode(path, inputNodes));
|
|
168
|
+
}
|
|
169
|
+
return compositionNodes;
|
|
170
|
+
}
|
|
171
|
+
var CycleError = class extends Error {};
|
|
172
|
+
function ExpandFirstRootInInput(nodes) {
|
|
173
|
+
let roots = FindRootsOrCycles(nodes);
|
|
174
|
+
if (!roots) {
|
|
175
|
+
throw new CycleError();
|
|
176
|
+
}
|
|
177
|
+
return ExpandNewNode([...roots.values()][0], nodes);
|
|
178
|
+
}
|
|
179
|
+
function CreateArtificialRoot(nodes) {
|
|
180
|
+
let roots = FindRootsOrCycles(nodes);
|
|
181
|
+
if (!roots) {
|
|
182
|
+
throw new CycleError();
|
|
183
|
+
}
|
|
184
|
+
let pseudoRoot = {
|
|
185
|
+
node: "",
|
|
186
|
+
attributes: /* @__PURE__ */ new Map(),
|
|
187
|
+
children: /* @__PURE__ */ new Map(),
|
|
188
|
+
};
|
|
189
|
+
roots.forEach((root) => {
|
|
190
|
+
pseudoRoot.children.set(root, ExpandNewNode(root, nodes));
|
|
191
|
+
});
|
|
192
|
+
return pseudoRoot;
|
|
193
|
+
}
|
|
194
|
+
function ExpandNewNode(node, nodes) {
|
|
195
|
+
return ExpandNode(node, MakeNode(node), nodes);
|
|
196
|
+
}
|
|
197
|
+
function ExpandNode(path, node, nodes) {
|
|
198
|
+
let input = nodes.get(path);
|
|
199
|
+
if (input) {
|
|
200
|
+
AddDataFromInput(input, node, nodes);
|
|
201
|
+
}
|
|
202
|
+
node.children.forEach((child, name) => {
|
|
203
|
+
ExpandNode(`${path}/${name}`, child, nodes);
|
|
204
|
+
});
|
|
205
|
+
return node;
|
|
206
|
+
}
|
|
207
|
+
function AddDataFromInput(input, node, nodes) {
|
|
208
|
+
Object.values(input.inherits).forEach((inherit) => {
|
|
209
|
+
let classNode = ExpandNewNode(GetHead(inherit), nodes);
|
|
210
|
+
let subnode = GetNode(classNode, GetTail(inherit));
|
|
211
|
+
if (!subnode) throw new Error(`Unknown node ${inherit}`);
|
|
212
|
+
subnode.children.forEach((child, childName) => {
|
|
213
|
+
node.children.set(childName, child);
|
|
214
|
+
});
|
|
215
|
+
for (let [attrID, attr] of subnode.attributes) {
|
|
216
|
+
node.attributes.set(attrID, attr);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
Object.entries(input.children).forEach(([childName, child]) => {
|
|
220
|
+
if (child !== null) {
|
|
221
|
+
let classNode = ExpandNewNode(GetHead(child), nodes);
|
|
222
|
+
let subnode = GetNode(classNode, GetTail(child));
|
|
223
|
+
if (!subnode) throw new Error(`Unknown node ${child}`);
|
|
224
|
+
node.children.set(childName, subnode);
|
|
225
|
+
} else {
|
|
226
|
+
node.children.delete(childName);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
Object.entries(input.attributes).forEach(([attrID, attr]) => {
|
|
230
|
+
node.attributes.set(attrID, attr);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// workflow-alpha.ts
|
|
235
|
+
function MMSet2(map, key, value) {
|
|
236
|
+
if (map.has(key)) {
|
|
237
|
+
map.get(key)?.push(value);
|
|
238
|
+
} else {
|
|
239
|
+
map.set(key, [value]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function ToInputNodes(data) {
|
|
243
|
+
let inputNodes = /* @__PURE__ */ new Map();
|
|
244
|
+
data.forEach((ifcxNode) => {
|
|
245
|
+
let node = {
|
|
246
|
+
path: ifcxNode.identifier,
|
|
247
|
+
children: ifcxNode.children ? ifcxNode.children : {},
|
|
248
|
+
inherits: ifcxNode.inherits ? ifcxNode.inherits : {},
|
|
249
|
+
attributes: ifcxNode.attributes ? ifcxNode.attributes : {},
|
|
250
|
+
};
|
|
251
|
+
MMSet2(inputNodes, node.path, node);
|
|
252
|
+
});
|
|
253
|
+
return inputNodes;
|
|
254
|
+
}
|
|
255
|
+
var SchemaValidationError = class extends Error {};
|
|
256
|
+
function ValidateAttributeValue(desc, value, path, schemas) {
|
|
257
|
+
if (desc.inherits) {
|
|
258
|
+
desc.inherits.forEach((inheritedSchemaID) => {
|
|
259
|
+
let inheritedSchema = schemas[inheritedSchemaID];
|
|
260
|
+
if (!inheritedSchema) {
|
|
261
|
+
throw new SchemaValidationError(`Unknown inherited schema id "${desc.inherits}"`);
|
|
262
|
+
}
|
|
263
|
+
ValidateAttributeValue(inheritedSchema.value, value, path, schemas);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
if (desc.dataType === "Boolean") {
|
|
267
|
+
if (typeof value !== "boolean") {
|
|
268
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type boolean`);
|
|
269
|
+
}
|
|
270
|
+
} else if (desc.dataType === "String") {
|
|
271
|
+
if (typeof value !== "string") {
|
|
272
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type string`);
|
|
273
|
+
}
|
|
274
|
+
} else if (desc.dataType === "DateTime") {
|
|
275
|
+
if (typeof value !== "string") {
|
|
276
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type date`);
|
|
277
|
+
}
|
|
278
|
+
} else if (desc.dataType === "Enum") {
|
|
279
|
+
if (typeof value !== "string") {
|
|
280
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type string`);
|
|
281
|
+
}
|
|
282
|
+
let found = desc.enumRestrictions.options.filter((option) => option === value).length === 1;
|
|
283
|
+
if (!found) {
|
|
284
|
+
throw new SchemaValidationError(`Expected "${value}" to be one of [${desc.enumRestrictions.options.join(",")}]`);
|
|
285
|
+
}
|
|
286
|
+
} else if (desc.dataType === "Integer") {
|
|
287
|
+
if (typeof value !== "number") {
|
|
288
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type int`);
|
|
289
|
+
}
|
|
290
|
+
} else if (desc.dataType === "Real") {
|
|
291
|
+
if (typeof value !== "number") {
|
|
292
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type real`);
|
|
293
|
+
}
|
|
294
|
+
} else if (desc.dataType === "Relation") {
|
|
295
|
+
if (typeof value !== "string") {
|
|
296
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type string`);
|
|
297
|
+
}
|
|
298
|
+
} else if (desc.dataType === "Object") {
|
|
299
|
+
if (typeof value !== "object") {
|
|
300
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type object`);
|
|
301
|
+
}
|
|
302
|
+
if (desc.objectRestrictions) {
|
|
303
|
+
Object.keys(desc.objectRestrictions.values).forEach((key) => {
|
|
304
|
+
if (!Object.hasOwn(value, key)) {
|
|
305
|
+
throw new SchemaValidationError(`Expected "${value}" to have key ${key}`);
|
|
306
|
+
}
|
|
307
|
+
ValidateAttributeValue(desc.objectRestrictions.values[key], value[key], path + "." + key, schemas);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
} else if (desc.dataType === "Array") {
|
|
311
|
+
if (!Array.isArray(value)) {
|
|
312
|
+
throw new SchemaValidationError(`Expected "${value}" to be of type array`);
|
|
313
|
+
}
|
|
314
|
+
value.forEach((entry) => {
|
|
315
|
+
ValidateAttributeValue(desc.arrayRestrictions.value, entry, path + ".<array>.", schemas);
|
|
316
|
+
});
|
|
317
|
+
} else {
|
|
318
|
+
throw new SchemaValidationError(`Unexpected datatype ${desc.dataType}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function Validate(schemas, inputNodes) {
|
|
322
|
+
inputNodes.forEach((node) => {
|
|
323
|
+
Object.keys(node.attributes).forEach((schemaID) => {
|
|
324
|
+
if (!schemas[schemaID]) {
|
|
325
|
+
throw new SchemaValidationError(`Missing schema "${schemaID}" referenced by ["${node.path}"].attributes`);
|
|
326
|
+
}
|
|
327
|
+
let schema = schemas[schemaID];
|
|
328
|
+
let value = node.attributes[schemaID];
|
|
329
|
+
try {
|
|
330
|
+
ValidateAttributeValue(schema.value, value, "", schemas);
|
|
331
|
+
} catch (e) {
|
|
332
|
+
if (e instanceof SchemaValidationError) {
|
|
333
|
+
throw new SchemaValidationError(`Error validating ["${node.path}"].attributes["${schemaID}"]: ${e.message}`);
|
|
334
|
+
} else {
|
|
335
|
+
throw e;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function LoadIfcxFile(file, checkSchemas = true, createArtificialRoot = false) {
|
|
342
|
+
let inputNodes = ToInputNodes(file.data);
|
|
343
|
+
let compositionNodes = ConvertNodes(inputNodes);
|
|
344
|
+
try {
|
|
345
|
+
if (checkSchemas) {
|
|
346
|
+
Validate(file.schemas, compositionNodes);
|
|
347
|
+
}
|
|
348
|
+
} catch (e) {
|
|
349
|
+
throw e;
|
|
350
|
+
}
|
|
351
|
+
if (createArtificialRoot) {
|
|
352
|
+
return CreateArtificialRoot(compositionNodes);
|
|
353
|
+
} else {
|
|
354
|
+
return ExpandFirstRootInInput(compositionNodes);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function Federate(files) {
|
|
358
|
+
let result = {
|
|
359
|
+
header: files[0].header,
|
|
360
|
+
schemas: {},
|
|
361
|
+
data: [],
|
|
362
|
+
};
|
|
363
|
+
files.forEach((file) => {
|
|
364
|
+
Object.keys(file.schemas).forEach((schemaID) => (result.schemas[schemaID] = file.schemas[schemaID]));
|
|
365
|
+
});
|
|
366
|
+
files.forEach((file) => {
|
|
367
|
+
file.data.forEach((node) => result.data.push(node));
|
|
368
|
+
});
|
|
369
|
+
return Prune(result);
|
|
370
|
+
}
|
|
371
|
+
function Collapse(nodes, deleteEmpty = false) {
|
|
372
|
+
let result = {
|
|
373
|
+
path: nodes[0].path,
|
|
374
|
+
children: {},
|
|
375
|
+
inherits: {},
|
|
376
|
+
attributes: {},
|
|
377
|
+
};
|
|
378
|
+
nodes.forEach((node) => {
|
|
379
|
+
Object.keys(node.children).forEach((name) => {
|
|
380
|
+
result.children[name] = node.children[name];
|
|
381
|
+
});
|
|
382
|
+
Object.keys(node.inherits).forEach((name) => {
|
|
383
|
+
result.inherits[name] = node.inherits[name];
|
|
384
|
+
});
|
|
385
|
+
Object.keys(node.attributes).forEach((name) => {
|
|
386
|
+
result.attributes[name] = node.attributes[name];
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
if (deleteEmpty) {
|
|
390
|
+
let empty = true;
|
|
391
|
+
Object.keys(result.children).forEach((name) => {
|
|
392
|
+
if (result.children[name] !== null) empty = false;
|
|
393
|
+
});
|
|
394
|
+
Object.keys(result.inherits).forEach((name) => {
|
|
395
|
+
if (result.inherits[name] !== null) empty = false;
|
|
396
|
+
});
|
|
397
|
+
Object.keys(result.attributes).forEach((name) => {
|
|
398
|
+
if (result.attributes[name] !== null) empty = false;
|
|
399
|
+
});
|
|
400
|
+
if (empty) return null;
|
|
401
|
+
}
|
|
402
|
+
return result;
|
|
403
|
+
}
|
|
404
|
+
function Prune(file, deleteEmpty = false) {
|
|
405
|
+
let result = {
|
|
406
|
+
header: file.header,
|
|
407
|
+
schemas: file.schemas,
|
|
408
|
+
data: [],
|
|
409
|
+
};
|
|
410
|
+
let inputNodes = ToInputNodes(file.data);
|
|
411
|
+
inputNodes.forEach((nodes) => {
|
|
412
|
+
let collapsed = Collapse(nodes, deleteEmpty);
|
|
413
|
+
if (collapsed)
|
|
414
|
+
result.data.push({
|
|
415
|
+
identifier: collapsed.path,
|
|
416
|
+
children: collapsed.children,
|
|
417
|
+
inherits: collapsed.inherits,
|
|
418
|
+
attributes: collapsed.attributes,
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
return result;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// compose-flattened.ts
|
|
425
|
+
function TreeNodeToComposedObject(path, node, schemas) {
|
|
426
|
+
let co = {
|
|
427
|
+
name: path,
|
|
428
|
+
attributes: {},
|
|
429
|
+
children: [],
|
|
430
|
+
};
|
|
431
|
+
node.children.forEach((childNode, childName) => {
|
|
432
|
+
co.children?.push(TreeNodeToComposedObject(`${path}/${childName}`, childNode, schemas));
|
|
433
|
+
});
|
|
434
|
+
node.attributes.forEach((attr, attrName) => {
|
|
435
|
+
if (attr && typeof attr === "object" && !Array.isArray(attr)) {
|
|
436
|
+
Object.keys(attr).forEach((compname) => {
|
|
437
|
+
co.attributes[`${attrName}::${compname}`] = attr[compname];
|
|
438
|
+
});
|
|
439
|
+
} else {
|
|
440
|
+
let schema = schemas[attrName];
|
|
441
|
+
if (schema && schema.value.quantityKind) {
|
|
442
|
+
let postfix = "";
|
|
443
|
+
let quantityKind = schema.value.quantityKind;
|
|
444
|
+
if (quantityKind === "Length") {
|
|
445
|
+
postfix = "m";
|
|
446
|
+
} else if (quantityKind === "Volume") {
|
|
447
|
+
postfix = "m" + String.fromCodePoint(179);
|
|
448
|
+
}
|
|
449
|
+
co.attributes[attrName] = `${attr} ${postfix}`;
|
|
450
|
+
} else {
|
|
451
|
+
co.attributes[attrName] = attr;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
if (Object.keys(co.attributes).length === 0) delete co.attributes;
|
|
456
|
+
return co;
|
|
457
|
+
}
|
|
458
|
+
function compose3(files) {
|
|
459
|
+
let federated = Federate(files);
|
|
460
|
+
let tree = LoadIfcxFile(federated, true, true);
|
|
461
|
+
return TreeNodeToComposedObject("", tree, federated.schemas);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// render.ts
|
|
465
|
+
// var controls;
|
|
466
|
+
// var renderer;
|
|
467
|
+
var scene;
|
|
468
|
+
var camera;
|
|
469
|
+
var datas = [];
|
|
470
|
+
var autoCamera = true;
|
|
471
|
+
// var THREE = window["THREE"];
|
|
472
|
+
function init() {
|
|
473
|
+
scene = new THREE.Scene();
|
|
474
|
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);
|
|
475
|
+
camera.up.set(0, 0, 1);
|
|
476
|
+
camera.position.set(50, 50, 50);
|
|
477
|
+
camera.lookAt(0, 0, 0);
|
|
478
|
+
// const nd = document.querySelector(".viewport");
|
|
479
|
+
// renderer = new THREE.WebGLRenderer({
|
|
480
|
+
// alpha: true,
|
|
481
|
+
// logarithmicDepthBuffer: true
|
|
482
|
+
// });
|
|
483
|
+
// renderer.setSize(nd.offsetWidth, nd.offsetHeight);
|
|
484
|
+
// controls = new THREE.OrbitControls(camera, renderer.domElement);
|
|
485
|
+
// controls.enableDamping = true;
|
|
486
|
+
// controls.dampingFactor = 0.25;
|
|
487
|
+
// nd.appendChild(renderer.domElement);
|
|
488
|
+
scene.add(camera);
|
|
489
|
+
return scene;
|
|
490
|
+
}
|
|
491
|
+
function HasAttr(node, attrName) {
|
|
492
|
+
if (!node || !node.attributes) return false;
|
|
493
|
+
return !!node.attributes[attrName];
|
|
494
|
+
}
|
|
495
|
+
function FindChildWithAttr(node, attrName) {
|
|
496
|
+
if (!node || !node.children) return undefined;
|
|
497
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
498
|
+
if (HasAttr(node.children[i], attrName)) {
|
|
499
|
+
return node.children[i];
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return undefined;
|
|
503
|
+
}
|
|
504
|
+
function createMaterialFromParent(parent, root) {
|
|
505
|
+
let reference = parent.attributes["usd::usdshade::materialbindingapi::material::binding"];
|
|
506
|
+
let material = {
|
|
507
|
+
color: new THREE.Color(0.6, 0.6, 0.6),
|
|
508
|
+
transparent: false,
|
|
509
|
+
opacity: 1,
|
|
510
|
+
};
|
|
511
|
+
if (reference) {
|
|
512
|
+
const materialNode = getChildByName(root, reference.ref);
|
|
513
|
+
let shader = FindChildWithAttr(materialNode, "usd::materials::inputs::diffuseColor");
|
|
514
|
+
if (shader) {
|
|
515
|
+
let color = shader?.attributes["usd::materials::inputs::diffuseColor"];
|
|
516
|
+
material.color = new THREE.Color(...color);
|
|
517
|
+
if (shader?.attributes["usd::materials::inputs::opacity"]) {
|
|
518
|
+
material.transparent = true;
|
|
519
|
+
material.opacity = shader.attributes["usd::materials::inputs::opacity"];
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return material;
|
|
524
|
+
}
|
|
525
|
+
function createCurveFromJson(node, parent, root) {
|
|
526
|
+
let points = new Float32Array(node.attributes["usd::usdgeom::basiscurves::points"].flat());
|
|
527
|
+
const geometry = new THREE.BufferGeometry();
|
|
528
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(points, 3));
|
|
529
|
+
const material = createMaterialFromParent(parent, root);
|
|
530
|
+
let lineMaterial = new THREE.LineBasicMaterial({ ...material });
|
|
531
|
+
lineMaterial.color.multiplyScalar(0.8);
|
|
532
|
+
return new THREE.Line(geometry, lineMaterial);
|
|
533
|
+
}
|
|
534
|
+
function createMeshFromJson(node, parent, root) {
|
|
535
|
+
let points = new Float32Array(node.attributes["usd::usdgeom::mesh::points"].flat());
|
|
536
|
+
let indices = new Uint16Array(node.attributes["usd::usdgeom::mesh::faceVertexIndices"]);
|
|
537
|
+
const geometry = new THREE.BufferGeometry();
|
|
538
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(points, 3));
|
|
539
|
+
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
|
540
|
+
geometry.computeVertexNormals();
|
|
541
|
+
const material = createMaterialFromParent(parent, root);
|
|
542
|
+
let meshMaterial = new THREE.MeshBasicMaterial({ ...material });
|
|
543
|
+
return new THREE.Mesh(geometry, meshMaterial);
|
|
544
|
+
}
|
|
545
|
+
function traverseTree(node, parent, root, parentNode = undefined) {
|
|
546
|
+
let elem = new THREE.Group();
|
|
547
|
+
if (HasAttr(node, "usd::usdgeom::visibility::visibility")) {
|
|
548
|
+
if (node.attributes["usd::usdgeom::visibility::visibility"] === "invisible") {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
} else if (HasAttr(node, "usd::usdgeom::mesh::points")) {
|
|
552
|
+
elem = createMeshFromJson(node, parentNode, root);
|
|
553
|
+
} else if (HasAttr(node, "usd::usdgeom::basiscurves::points")) {
|
|
554
|
+
elem = createCurveFromJson(node, parentNode, root);
|
|
555
|
+
}
|
|
556
|
+
parent.add(elem);
|
|
557
|
+
if (node !== root) {
|
|
558
|
+
elem.matrixAutoUpdate = false;
|
|
559
|
+
let matrixNode =
|
|
560
|
+
node.attributes && node.attributes["usd::xformop::transform"]
|
|
561
|
+
? node.attributes["usd::xformop::transform"].flat()
|
|
562
|
+
: null;
|
|
563
|
+
if (matrixNode) {
|
|
564
|
+
let matrix = new THREE.Matrix4();
|
|
565
|
+
matrix.set(...matrixNode);
|
|
566
|
+
matrix.transpose();
|
|
567
|
+
elem.matrix = matrix;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
(node.children || []).forEach((child) => traverseTree(child, elem || parent, root, node));
|
|
571
|
+
}
|
|
572
|
+
// function encodeHtmlEntities(str) {
|
|
573
|
+
// const div = document.createElement("div");
|
|
574
|
+
// div.textContent = str;
|
|
575
|
+
// return div.innerHTML;
|
|
576
|
+
// }
|
|
577
|
+
// var icons = {
|
|
578
|
+
// "usd::usdgeom::mesh::points": "deployed_code",
|
|
579
|
+
// "usd::usdgeom::basiscurves::points": "line_curve",
|
|
580
|
+
// "usd::usdshade::material::outputs::surface.connect": "line_style"
|
|
581
|
+
// };
|
|
582
|
+
// function buildDomTree(prim, node) {
|
|
583
|
+
// const elem = document.createElement("div");
|
|
584
|
+
// let span;
|
|
585
|
+
// elem.appendChild(document.createTextNode(prim.name ? prim.name.split("/").reverse()[0] : "root"));
|
|
586
|
+
// elem.appendChild(span = document.createElement("span"));
|
|
587
|
+
// Object.entries(icons).forEach(([k, v]) => span.innerText += (prim.attributes || {})[k] ? v : " ");
|
|
588
|
+
// span.className = "material-symbols-outlined";
|
|
589
|
+
// elem.onclick = (evt) => {
|
|
590
|
+
// let rows = [["name", prim.name]].concat(Object.entries(prim.attributes)).map(([k, v]) => `<tr><td>${encodeHtmlEntities(k)}</td><td>${encodeHtmlEntities(typeof v === "object" ? JSON.stringify(v) : v)}</td>`).join("");
|
|
591
|
+
// document.querySelector(".attributes .table").innerHTML = `<table border="0">${rows}</table>`;
|
|
592
|
+
// evt.stopPropagation();
|
|
593
|
+
// };
|
|
594
|
+
// node.appendChild(elem);
|
|
595
|
+
// (prim.children || []).forEach((p) => buildDomTree(p, elem));
|
|
596
|
+
// }
|
|
597
|
+
function composeAndRender() {
|
|
598
|
+
if (scene) {
|
|
599
|
+
scene.children = [];
|
|
600
|
+
}
|
|
601
|
+
// document.querySelector(".tree").innerHTML = "";
|
|
602
|
+
if (datas.length === 0) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
let tree = null;
|
|
606
|
+
let dataArray = datas.map((arr) => arr[1]);
|
|
607
|
+
tree = compose3(dataArray);
|
|
608
|
+
if (!tree) {
|
|
609
|
+
console.error("No result from composition");
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
traverseTree(tree, scene || init(), tree);
|
|
613
|
+
if (autoCamera) {
|
|
614
|
+
const boundingBox = new THREE.Box3();
|
|
615
|
+
boundingBox.setFromObject(scene);
|
|
616
|
+
if (!boundingBox.isEmpty()) {
|
|
617
|
+
let avg = boundingBox.min.clone().add(boundingBox.max).multiplyScalar(0.5);
|
|
618
|
+
let ext = boundingBox.max.clone().sub(boundingBox.min).length();
|
|
619
|
+
camera.position.copy(avg.clone().add(new THREE.Vector3(1, 1, 1).normalize().multiplyScalar(ext)));
|
|
620
|
+
camera.far = ext * 3;
|
|
621
|
+
camera.updateProjectionMatrix();
|
|
622
|
+
// controls.target.copy(avg);
|
|
623
|
+
// controls.update();
|
|
624
|
+
autoCamera = false;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
// buildDomTree(tree, document.querySelector(".tree"));
|
|
628
|
+
// animate();
|
|
629
|
+
}
|
|
630
|
+
// function createLayerDom() {
|
|
631
|
+
// document.querySelector(".layers div").innerHTML = "";
|
|
632
|
+
// datas.forEach(([name, _], index) => {
|
|
633
|
+
// const elem = document.createElement("div");
|
|
634
|
+
// elem.appendChild(document.createTextNode(name));
|
|
635
|
+
// ["\u25B3", "\u25BD", "\xD7"].reverse().forEach((lbl, cmd) => {
|
|
636
|
+
// const btn = document.createElement("span");
|
|
637
|
+
// btn.onclick = (evt) => {
|
|
638
|
+
// evt.stopPropagation();
|
|
639
|
+
// if (cmd === 2) {
|
|
640
|
+
// if (index > 0) {
|
|
641
|
+
// [datas[index], datas[index - 1]] = [datas[index - 1], datas[index]];
|
|
642
|
+
// }
|
|
643
|
+
// } else if (cmd === 1) {
|
|
644
|
+
// if (index < datas.length - 1) {
|
|
645
|
+
// [datas[index], datas[index + 1]] = [datas[index + 1], datas[index]];
|
|
646
|
+
// }
|
|
647
|
+
// } else if (cmd === 0) {
|
|
648
|
+
// datas.splice(index, 1);
|
|
649
|
+
// }
|
|
650
|
+
// composeAndRender();
|
|
651
|
+
// createLayerDom();
|
|
652
|
+
// };
|
|
653
|
+
// btn.appendChild(document.createTextNode(lbl));
|
|
654
|
+
// elem.appendChild(btn);
|
|
655
|
+
// });
|
|
656
|
+
// document.querySelector(".layers div").appendChild(elem);
|
|
657
|
+
// });
|
|
658
|
+
// }
|
|
659
|
+
// function addModel(name, m) {
|
|
660
|
+
// datas.push([name, m]);
|
|
661
|
+
// createLayerDom();
|
|
662
|
+
// composeAndRender();
|
|
663
|
+
// }
|
|
664
|
+
// function animate() {
|
|
665
|
+
// requestAnimationFrame(animate);
|
|
666
|
+
// controls.update();
|
|
667
|
+
// renderer.render(scene, camera);
|
|
668
|
+
// }
|
|
669
|
+
// export {
|
|
670
|
+
// composeAndRender,
|
|
671
|
+
// addModel as default
|
|
672
|
+
// };
|
|
673
|
+
function parse(m, name) {
|
|
674
|
+
datas.push([name, m]);
|
|
675
|
+
composeAndRender();
|
|
676
|
+
return scene;
|
|
677
|
+
}
|
|
678
|
+
function clear() {
|
|
679
|
+
scene = undefined;
|
|
680
|
+
datas.length = 0;
|
|
681
|
+
autoCamera = true;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
685
|
+
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
|
|
686
|
+
// All rights reserved.
|
|
687
|
+
//
|
|
688
|
+
// This software and its documentation and related materials are owned by
|
|
689
|
+
// the Alliance. The software may only be incorporated into application
|
|
690
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
691
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
692
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
693
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
694
|
+
// protected by copyright law and international treaty provisions. Application
|
|
695
|
+
// programs incorporating this software must include the following statement
|
|
696
|
+
// with their copyright notices:
|
|
697
|
+
//
|
|
698
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
699
|
+
// license agreement with Open Design Alliance.
|
|
700
|
+
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
|
|
701
|
+
// All rights reserved.
|
|
702
|
+
//
|
|
703
|
+
// By use of this software, its documentation or related materials, you
|
|
704
|
+
// acknowledge and accept the above terms.
|
|
705
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
706
|
+
class IFCXModelLoader extends viewerThree.Loader {
|
|
707
|
+
constructor(viewer) {
|
|
708
|
+
super();
|
|
709
|
+
this.viewer = viewer;
|
|
710
|
+
}
|
|
711
|
+
isSupport(file) {
|
|
712
|
+
return (typeof file === "object" &&
|
|
713
|
+
typeof file.type === "string" &&
|
|
714
|
+
typeof file.download === "function" &&
|
|
715
|
+
/.ifcx$/i.test(file.type));
|
|
716
|
+
}
|
|
717
|
+
async load(model) {
|
|
718
|
+
const progress = (progress) => {
|
|
719
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model });
|
|
720
|
+
};
|
|
721
|
+
const arrayBuffer = await model.download(progress, this.abortController.signal);
|
|
722
|
+
if (!this.viewer.scene)
|
|
723
|
+
return this;
|
|
724
|
+
const textDecoder = new TextDecoder();
|
|
725
|
+
const json = JSON.parse(textDecoder.decode(arrayBuffer));
|
|
726
|
+
const scene = parse(json);
|
|
727
|
+
clear();
|
|
728
|
+
let handle = 0;
|
|
729
|
+
scene.traverse((object) => {
|
|
730
|
+
object.userData = { handle, ...object.userData };
|
|
731
|
+
handle++;
|
|
732
|
+
});
|
|
733
|
+
this.viewer.scene.add(scene);
|
|
734
|
+
this.viewer.models.push(scene);
|
|
735
|
+
this.viewer.syncOptions();
|
|
736
|
+
this.viewer.syncOverlay();
|
|
737
|
+
this.viewer.update();
|
|
738
|
+
this.viewer.emitEvent({ type: "databasechunk", data: scene, file: model });
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
744
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
745
|
+
// All rights reserved.
|
|
746
|
+
//
|
|
747
|
+
// This software and its documentation and related materials are owned by
|
|
748
|
+
// the Alliance. The software may only be incorporated into application
|
|
749
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
750
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
751
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
752
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
753
|
+
// protected by copyright law and international treaty provisions. Application
|
|
754
|
+
// programs incorporating this software must include the following statement
|
|
755
|
+
// with their copyright notices:
|
|
756
|
+
//
|
|
757
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
758
|
+
// license agreement with Open Design Alliance.
|
|
759
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
760
|
+
// All rights reserved.
|
|
761
|
+
//
|
|
762
|
+
// By use of this software, its documentation or related materials, you
|
|
763
|
+
// acknowledge and accept the above terms.
|
|
764
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
765
|
+
class IFCXLoader extends three.Loader {
|
|
766
|
+
load(url, onLoad, onProgress, onError) {
|
|
767
|
+
const manager = this.manager;
|
|
768
|
+
manager.itemStart(url);
|
|
769
|
+
const _onLoad = (scene) => {
|
|
770
|
+
onLoad(scene);
|
|
771
|
+
manager.itemEnd(url);
|
|
772
|
+
};
|
|
773
|
+
const _onError = (e) => {
|
|
774
|
+
if (onError)
|
|
775
|
+
onError(e);
|
|
776
|
+
else
|
|
777
|
+
console.error(e);
|
|
778
|
+
manager.itemError(url);
|
|
779
|
+
manager.itemEnd(url);
|
|
780
|
+
};
|
|
781
|
+
const loader = new three.FileLoader(this.manager);
|
|
782
|
+
loader.setPath(this.path);
|
|
783
|
+
loader.setResponseType("json");
|
|
784
|
+
loader.setRequestHeader(this.requestHeader);
|
|
785
|
+
loader.setWithCredentials(this.withCredentials);
|
|
786
|
+
loader.load(url, (json) => this.parse(json, _onLoad, _onError), onProgress, onError);
|
|
787
|
+
}
|
|
788
|
+
parse(json, onLoad, onError) {
|
|
789
|
+
try {
|
|
790
|
+
onLoad(parse(json));
|
|
791
|
+
}
|
|
792
|
+
catch (e) {
|
|
793
|
+
onError(e);
|
|
794
|
+
}
|
|
795
|
+
finally {
|
|
796
|
+
clear();
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
802
|
+
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
|
|
803
|
+
// All rights reserved.
|
|
804
|
+
//
|
|
805
|
+
// This software and its documentation and related materials are owned by
|
|
806
|
+
// the Alliance. The software may only be incorporated into application
|
|
807
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
808
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
809
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
810
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
811
|
+
// protected by copyright law and international treaty provisions. Application
|
|
812
|
+
// programs incorporating this software must include the following statement
|
|
813
|
+
// with their copyright notices:
|
|
814
|
+
//
|
|
815
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
816
|
+
// license agreement with Open Design Alliance.
|
|
817
|
+
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
|
|
818
|
+
// All rights reserved.
|
|
819
|
+
//
|
|
820
|
+
// By use of this software, its documentation or related materials, you
|
|
821
|
+
// acknowledge and accept the above terms.
|
|
822
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
823
|
+
class IFCXFileLoader extends viewerThree.Loader {
|
|
824
|
+
constructor(viewer) {
|
|
825
|
+
super();
|
|
826
|
+
this.viewer = viewer;
|
|
827
|
+
}
|
|
828
|
+
isSupport(file, format) {
|
|
829
|
+
return ((typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
|
|
830
|
+
/(ifcx)$/i.test(format));
|
|
831
|
+
}
|
|
832
|
+
async load(file, format, params) {
|
|
833
|
+
const manager = new viewerThree.GLTFLoadingManager(file, params);
|
|
834
|
+
const loader = new IFCXLoader(manager);
|
|
835
|
+
loader.setPath(manager.path);
|
|
836
|
+
loader.setCrossOrigin(params.crossOrigin || loader.crossOrigin);
|
|
837
|
+
loader.setWithCredentials(params.withCredentials || loader.withCredentials);
|
|
838
|
+
const progress = (event) => {
|
|
839
|
+
const { lengthComputable, loaded, total } = event;
|
|
840
|
+
const progress = lengthComputable ? loaded / total : 1;
|
|
841
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
|
|
842
|
+
};
|
|
843
|
+
const scene = await loader.loadAsync(manager.fileURL, progress);
|
|
844
|
+
if (!this.viewer.scene)
|
|
845
|
+
return this;
|
|
846
|
+
let handle = 0;
|
|
847
|
+
scene.traverse((object) => {
|
|
848
|
+
object.userData = { handle, ...object.userData };
|
|
849
|
+
handle++;
|
|
850
|
+
});
|
|
851
|
+
this.viewer.scene.add(scene);
|
|
852
|
+
this.viewer.models.push(scene);
|
|
853
|
+
this.viewer.syncOptions();
|
|
854
|
+
this.viewer.syncOverlay();
|
|
855
|
+
this.viewer.update();
|
|
856
|
+
this.viewer.emitEvent({ type: "databasechunk", data: scene, file });
|
|
857
|
+
return this;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
862
|
+
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
|
|
863
|
+
// All rights reserved.
|
|
864
|
+
//
|
|
865
|
+
// This software and its documentation and related materials are owned by
|
|
866
|
+
// the Alliance. The software may only be incorporated into application
|
|
867
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
868
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
869
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
870
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
871
|
+
// protected by copyright law and international treaty provisions. Application
|
|
872
|
+
// programs incorporating this software must include the following statement
|
|
873
|
+
// with their copyright notices:
|
|
874
|
+
//
|
|
875
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
876
|
+
// license agreement with Open Design Alliance.
|
|
877
|
+
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
|
|
878
|
+
// All rights reserved.
|
|
879
|
+
//
|
|
880
|
+
// By use of this software, its documentation or related materials, you
|
|
881
|
+
// acknowledge and accept the above terms.
|
|
882
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
883
|
+
viewerThree.loaders.registerLoader("ifcx", (viewer) => new IFCXModelLoader(viewer));
|
|
884
|
+
viewerThree.loaders.registerLoader("ifcx-file", (viewer) => new IFCXFileLoader(viewer));
|
|
885
|
+
|
|
886
|
+
}));
|
|
887
|
+
//# sourceMappingURL=IFCXLoader.js.map
|