@inweb/viewer-three 26.6.5 → 26.6.7
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 +5 -5
- package/dist/plugins/components/AxesHelperComponent.js.map +1 -1
- package/dist/plugins/components/AxesHelperComponent.min.js +1 -1
- package/dist/plugins/components/AxesHelperComponent.module.js +5 -5
- package/dist/plugins/components/AxesHelperComponent.module.js.map +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.js +15 -7
- package/dist/plugins/components/ExtentsHelperComponent.js.map +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.min.js +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.module.js +15 -7
- package/dist/plugins/components/ExtentsHelperComponent.module.js.map +1 -1
- package/dist/plugins/components/LightHelperComponent.js +5 -5
- package/dist/plugins/components/LightHelperComponent.js.map +1 -1
- package/dist/plugins/components/LightHelperComponent.min.js +1 -1
- package/dist/plugins/components/LightHelperComponent.module.js +5 -5
- package/dist/plugins/components/LightHelperComponent.module.js.map +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.js +4840 -0
- package/dist/plugins/loaders/GLTFCloudLoader.js.map +1 -0
- package/dist/plugins/loaders/GLTFCloudLoader.min.js +1 -0
- package/dist/plugins/loaders/GLTFCloudLoader.module.js +49 -0
- package/dist/plugins/loaders/GLTFCloudLoader.module.js.map +1 -0
- package/dist/plugins/loaders/IFCXLoader.js +12 -6
- package/dist/plugins/loaders/IFCXLoader.js.map +1 -1
- package/dist/plugins/loaders/IFCXLoader.min.js +1 -1
- package/dist/plugins/loaders/IFCXLoader.module.js +13 -7
- package/dist/plugins/loaders/IFCXLoader.module.js.map +1 -1
- package/dist/viewer-three.js +3131 -459
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +2 -2
- package/dist/viewer-three.module.js +2326 -264
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +6 -5
- package/lib/Viewer/components/HighlighterComponent.d.ts +4 -3
- package/lib/Viewer/components/SelectionComponent.d.ts +8 -5
- package/lib/Viewer/draggers/CuttingPlaneDragger.d.ts +1 -1
- package/lib/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.d.ts +20 -0
- package/lib/Viewer/loaders/GLTFCloudDynamicLoader.d.ts +15 -0
- package/lib/Viewer/model/IModelImpl.d.ts +27 -0
- package/lib/Viewer/model/ModelImpl.d.ts +30 -0
- package/lib/Viewer/model/index.d.ts +2 -0
- package/lib/index.d.ts +1 -0
- package/package.json +11 -7
- package/plugins/components/AxesHelperComponent.ts +5 -5
- package/plugins/components/ExtentsHelperComponent.ts +15 -7
- package/plugins/components/LightHelperComponent.ts +5 -5
- package/{src/Viewer/loaders/GLTFCloudModelLoader.ts → plugins/loaders/GLTFCloudLoader.ts} +15 -12
- package/plugins/loaders/{IFCXCloudFileLoader.ts → IFCXCloudLoader.ts} +8 -4
- package/plugins/loaders/IFCXFileLoader.ts +7 -3
- package/plugins/loaders/IFCXLoader.ts +2 -2
- package/src/Viewer/Viewer.ts +32 -36
- package/src/Viewer/commands/ClearSelected.ts +2 -3
- package/src/Viewer/commands/Explode.ts +1 -47
- package/src/Viewer/commands/GetModels.ts +1 -1
- package/src/Viewer/commands/GetSelected.ts +3 -1
- package/src/Viewer/commands/HideSelected.ts +3 -4
- package/src/Viewer/commands/IsolateSelected.ts +1 -7
- package/src/Viewer/commands/SelectModel.ts +9 -1
- package/src/Viewer/commands/SetSelected.ts +8 -10
- package/src/Viewer/commands/ShowAll.ts +1 -1
- package/src/Viewer/components/BackgroundComponent.ts +1 -0
- package/src/Viewer/components/ExtentsComponent.ts +5 -3
- package/src/Viewer/components/HighlighterComponent.ts +79 -48
- package/src/Viewer/components/SelectionComponent.ts +67 -21
- package/src/Viewer/draggers/CuttingPlaneDragger.ts +7 -3
- package/src/Viewer/draggers/MeasureLineDragger.ts +2 -0
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicGltfLoader.js +1628 -0
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.ts +102 -0
- package/src/Viewer/loaders/DynamicGltfLoader/GltfStructure.js +450 -0
- package/src/Viewer/loaders/GLTFCloudDynamicLoader.ts +145 -0
- package/src/Viewer/loaders/GLTFFileLoader.ts +7 -2
- package/src/Viewer/loaders/index.ts +2 -2
- package/src/Viewer/model/IModelImpl.ts +67 -0
- package/src/Viewer/model/ModelImpl.ts +215 -0
- package/src/Viewer/model/index.ts +25 -0
- package/src/index.ts +1 -0
- package/lib/Viewer/loaders/GLTFCloudModelLoader.d.ts +0 -8
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { Box3, Object3D } from "three";
|
|
25
|
+
|
|
26
|
+
import { ModelImpl } from "../../model";
|
|
27
|
+
import { DynamicGltfLoader } from "./DynamicGltfLoader.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Dynamic model implementation.
|
|
31
|
+
*/
|
|
32
|
+
export class DynamicModelImpl extends ModelImpl {
|
|
33
|
+
public gltfLoader: DynamicGltfLoader;
|
|
34
|
+
|
|
35
|
+
override getExtents(target: Box3): Box3 {
|
|
36
|
+
return target.union(this.gltfLoader.getTotalGeometryExtent());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override getObjects(): Object3D[] {
|
|
40
|
+
const objects = [];
|
|
41
|
+
this.gltfLoader.originalObjects.forEach((object: Object3D) => {
|
|
42
|
+
objects.push(object);
|
|
43
|
+
});
|
|
44
|
+
return objects;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override getVisibleObjects(): Object3D[] {
|
|
48
|
+
return this.gltfLoader.getOriginalObjectForSelect();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override hasObject(object: any): boolean {
|
|
52
|
+
return this.gltfLoader.originalObjects.has(object);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override getObjectsByHandles(handles: string | string[]): Object3D[] {
|
|
56
|
+
const handlesSet = new Set(handles);
|
|
57
|
+
const objects = [];
|
|
58
|
+
handlesSet.forEach((handle) => {
|
|
59
|
+
const handles = this.gltfLoader.handleToObjects.get(handle) || [];
|
|
60
|
+
objects.push(...Array.from(handles));
|
|
61
|
+
});
|
|
62
|
+
return objects;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override hideObjects(objects: Object3D | Object3D[]): this {
|
|
66
|
+
this.getOwnObjects(objects)
|
|
67
|
+
.map((object) => object.userData.handle)
|
|
68
|
+
.forEach((handle) => this.gltfLoader.hiddenHandles.add(handle));
|
|
69
|
+
this.gltfLoader.syncHiddenObjects();
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
override isolateObjects(objects: Object3D | Object3D[]): this {
|
|
74
|
+
const handles = this.getHandlesByObjects(objects);
|
|
75
|
+
this.gltfLoader.isolateObjects(new Set(handles));
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override showObjects(objects: Object3D | Object3D[]): this {
|
|
80
|
+
this.getOwnObjects(objects)
|
|
81
|
+
.map((object) => object.userData.handle)
|
|
82
|
+
.forEach((handle) => this.gltfLoader.hiddenHandles.delete(handle));
|
|
83
|
+
this.gltfLoader.syncHiddenObjects();
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
override showAllObjects(): this {
|
|
88
|
+
this.gltfLoader.hiddenHandles.clear();
|
|
89
|
+
this.gltfLoader.syncHiddenObjects();
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
override showOriginalObjects(objects: Object3D | Object3D[]): this {
|
|
94
|
+
this.getOwnObjects(objects).forEach((object) => (object.visible = true));
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
override hideOriginalObjects(objects: Object3D | Object3D[]): this {
|
|
99
|
+
this.getOwnObjects(objects).forEach((object) => (object.visible = false));
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { TextureLoader, BufferAttribute, MeshStandardMaterial, DoubleSide, FrontSide } from "three";
|
|
2
|
+
|
|
3
|
+
export const GL_COMPONENT_TYPES = {
|
|
4
|
+
5120: Int8Array,
|
|
5
|
+
5121: Uint8Array,
|
|
6
|
+
5122: Int16Array,
|
|
7
|
+
5123: Uint16Array,
|
|
8
|
+
5125: Uint32Array,
|
|
9
|
+
5126: Float32Array,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const GL_CONSTANTS = {
|
|
13
|
+
FLOAT: 5126,
|
|
14
|
+
//FLOAT_MAT2: 35674,
|
|
15
|
+
FLOAT_MAT3: 35675,
|
|
16
|
+
FLOAT_MAT4: 35676,
|
|
17
|
+
FLOAT_VEC2: 35664,
|
|
18
|
+
FLOAT_VEC3: 35665,
|
|
19
|
+
FLOAT_VEC4: 35666,
|
|
20
|
+
LINEAR: 9729,
|
|
21
|
+
REPEAT: 10497,
|
|
22
|
+
SAMPLER_2D: 35678,
|
|
23
|
+
POINTS: 0,
|
|
24
|
+
LINES: 1,
|
|
25
|
+
LINE_LOOP: 2,
|
|
26
|
+
LINE_STRIP: 3,
|
|
27
|
+
TRIANGLES: 4,
|
|
28
|
+
TRIANGLE_STRIP: 5,
|
|
29
|
+
TRIANGLE_FAN: 6,
|
|
30
|
+
UNSIGNED_BYTE: 5121,
|
|
31
|
+
UNSIGNED_SHORT: 5123,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export class GltfStructure {
|
|
35
|
+
constructor(id) {
|
|
36
|
+
this.id = `${id}`;
|
|
37
|
+
this.json = null;
|
|
38
|
+
this.baseUrl = "";
|
|
39
|
+
|
|
40
|
+
// Binary manager properties
|
|
41
|
+
this.loadController = null;
|
|
42
|
+
// Request batching parameters
|
|
43
|
+
this.batchDelay = 10;
|
|
44
|
+
this.maxBatchSize = 5 * 1024 * 1024;
|
|
45
|
+
this.maxRangesPerRequest = 512;
|
|
46
|
+
|
|
47
|
+
// Request queue
|
|
48
|
+
this.pendingRequests = [];
|
|
49
|
+
this.batchTimeout = null;
|
|
50
|
+
|
|
51
|
+
// Material and texture properties
|
|
52
|
+
this.textureLoader = new TextureLoader();
|
|
53
|
+
this.materials = new Map();
|
|
54
|
+
this.textureCache = new Map();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async initialize(loadController) {
|
|
58
|
+
this.json = await loadController.loadJson();
|
|
59
|
+
this.baseUrl = await loadController.baseUrl();
|
|
60
|
+
this.loadController = loadController;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
clear() {
|
|
64
|
+
this.json = null;
|
|
65
|
+
this.baseUrl = "";
|
|
66
|
+
this.loadController = null;
|
|
67
|
+
this.pendingRequests = [];
|
|
68
|
+
if (this.batchTimeout) {
|
|
69
|
+
clearTimeout(this.batchTimeout);
|
|
70
|
+
this.batchTimeout = null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Clear materials and textures
|
|
74
|
+
this.disposeMaterials();
|
|
75
|
+
this.textureCache.clear();
|
|
76
|
+
this.materials.clear();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getJson() {
|
|
80
|
+
return this.json;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Schedule a request for processing
|
|
84
|
+
scheduleRequest(request) {
|
|
85
|
+
this.pendingRequests.push(request);
|
|
86
|
+
|
|
87
|
+
// Clear existing timeout
|
|
88
|
+
if (this.batchTimeout) {
|
|
89
|
+
clearTimeout(this.batchTimeout);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Set new timeout for batch processing
|
|
93
|
+
this.batchTimeout = setTimeout(() => this.processBatch(), this.batchDelay);
|
|
94
|
+
|
|
95
|
+
// Return a promise that will resolve when the data is available
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
request.resolve = resolve;
|
|
98
|
+
request.reject = reject;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async processBatch() {
|
|
103
|
+
if (this.pendingRequests.length === 0) return;
|
|
104
|
+
|
|
105
|
+
// Take current batch of requests and clear timeout
|
|
106
|
+
const currentBatch = [...this.pendingRequests];
|
|
107
|
+
this.pendingRequests = [];
|
|
108
|
+
|
|
109
|
+
if (this.batchTimeout) {
|
|
110
|
+
clearTimeout(this.batchTimeout);
|
|
111
|
+
this.batchTimeout = null;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
// Split requests into smaller groups
|
|
115
|
+
for (let i = 0; i < currentBatch.length; i += this.maxRangesPerRequest) {
|
|
116
|
+
const batchRequests = currentBatch.slice(i, i + this.maxRangesPerRequest);
|
|
117
|
+
const buffer = await this.loadController.loadBinaryData(batchRequests);
|
|
118
|
+
|
|
119
|
+
let currentOffset = 0;
|
|
120
|
+
batchRequests.forEach((request) => {
|
|
121
|
+
const view = this.createTypedArray(buffer, currentOffset, request.length, request.componentType);
|
|
122
|
+
request.resolve(view);
|
|
123
|
+
currentOffset += request.length;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error("Error processing batch:", error);
|
|
128
|
+
currentBatch.forEach((request) => request.reject(error));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (this.pendingRequests.length > 0) {
|
|
132
|
+
this.batchTimeout = setTimeout(() => this.processBatch(), this.batchDelay);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
getBufferView(byteOffset, byteLength, componentType) {
|
|
137
|
+
return this.scheduleRequest({
|
|
138
|
+
offset: byteOffset,
|
|
139
|
+
length: byteLength,
|
|
140
|
+
componentType,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
createTypedArray(buffer, offset, length, componentType) {
|
|
145
|
+
try {
|
|
146
|
+
// Validate parameters
|
|
147
|
+
if (!buffer || !(buffer instanceof ArrayBuffer)) {
|
|
148
|
+
throw new Error("Invalid buffer");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Calculate element size for given type
|
|
152
|
+
let elementSize;
|
|
153
|
+
switch (componentType) {
|
|
154
|
+
case 5120:
|
|
155
|
+
case 5121:
|
|
156
|
+
elementSize = 1;
|
|
157
|
+
break; // BYTE, UNSIGNED_BYTE
|
|
158
|
+
case 5122:
|
|
159
|
+
case 5123:
|
|
160
|
+
elementSize = 2;
|
|
161
|
+
break; // SHORT, UNSIGNED_SHORT
|
|
162
|
+
case 5125:
|
|
163
|
+
case 5126:
|
|
164
|
+
elementSize = 4;
|
|
165
|
+
break; // UNSIGNED_INT, FLOAT
|
|
166
|
+
default:
|
|
167
|
+
throw new Error(`Unsupported component type: ${componentType}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Check if requested length is correct
|
|
171
|
+
const numElements = length / elementSize;
|
|
172
|
+
if (!Number.isInteger(numElements)) {
|
|
173
|
+
throw new Error(`Invalid length ${length} for component type ${componentType}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Check if buffer is large enough
|
|
177
|
+
if (length > buffer.byteLength) {
|
|
178
|
+
throw new Error(`Buffer too small: need ${length} bytes, but buffer is ${buffer.byteLength} bytes`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Create appropriate typed array
|
|
182
|
+
const ArrayType = GL_COMPONENT_TYPES[componentType];
|
|
183
|
+
return new ArrayType(buffer, offset, numElements);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
if (error.name !== "AbortError") {
|
|
186
|
+
console.error("Error creating typed array:", {
|
|
187
|
+
bufferSize: buffer?.byteLength,
|
|
188
|
+
offset,
|
|
189
|
+
length,
|
|
190
|
+
componentType,
|
|
191
|
+
error,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async createBufferAttribute(accessorIndex) {
|
|
199
|
+
if (!this.json) {
|
|
200
|
+
throw new Error("No GLTF structure loaded");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const gltf = this.json;
|
|
204
|
+
const accessor = gltf.accessors[accessorIndex];
|
|
205
|
+
const bufferView = gltf.bufferViews[accessor.bufferView];
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
const byteOffset = (bufferView.byteOffset || 0) + (accessor.byteOffset || 0);
|
|
209
|
+
const components = this.getNumComponents(accessor.type);
|
|
210
|
+
const count = accessor.count;
|
|
211
|
+
const byteLength = count * components * this.getComponentSize(accessor.componentType);
|
|
212
|
+
|
|
213
|
+
const array = await this.getBufferView(byteOffset, byteLength, accessor.componentType);
|
|
214
|
+
|
|
215
|
+
const attribute = new BufferAttribute(array, components);
|
|
216
|
+
|
|
217
|
+
if (accessor.min !== undefined) attribute.min = accessor.min;
|
|
218
|
+
if (accessor.max !== undefined) attribute.max = accessor.max;
|
|
219
|
+
|
|
220
|
+
return attribute;
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (error.name !== "AbortError") {
|
|
223
|
+
console.error("Error creating buffer attribute:", {
|
|
224
|
+
error,
|
|
225
|
+
accessor,
|
|
226
|
+
bufferView,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
getComponentSize(componentType) {
|
|
235
|
+
switch (componentType) {
|
|
236
|
+
case 5120: // BYTE
|
|
237
|
+
case 5121: // UNSIGNED_BYTE
|
|
238
|
+
return 1;
|
|
239
|
+
case 5122: // SHORT
|
|
240
|
+
case 5123: // UNSIGNED_SHORT
|
|
241
|
+
return 2;
|
|
242
|
+
case 5125: // UNSIGNED_INT
|
|
243
|
+
case 5126: // FLOAT
|
|
244
|
+
return 4;
|
|
245
|
+
default:
|
|
246
|
+
throw new Error(`Unknown component type: ${componentType}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
getNumComponents(type) {
|
|
251
|
+
switch (type) {
|
|
252
|
+
case "SCALAR":
|
|
253
|
+
return 1;
|
|
254
|
+
case "VEC2":
|
|
255
|
+
return 2;
|
|
256
|
+
case "VEC3":
|
|
257
|
+
return 3;
|
|
258
|
+
case "VEC4":
|
|
259
|
+
return 4;
|
|
260
|
+
case "MAT2":
|
|
261
|
+
return 4;
|
|
262
|
+
case "MAT3":
|
|
263
|
+
return 9;
|
|
264
|
+
case "MAT4":
|
|
265
|
+
return 16;
|
|
266
|
+
default:
|
|
267
|
+
throw new Error(`Unknown type: ${type}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async loadTextures() {
|
|
272
|
+
if (!this.json.textures) return;
|
|
273
|
+
|
|
274
|
+
const loadTexture = async (imageIndex) => {
|
|
275
|
+
const image = this.json.images[imageIndex];
|
|
276
|
+
|
|
277
|
+
if (image.uri) {
|
|
278
|
+
// Handle base64 or URL
|
|
279
|
+
if (image.uri.startsWith("data:")) {
|
|
280
|
+
return await this.textureLoader.loadAsync(image.uri);
|
|
281
|
+
} else {
|
|
282
|
+
const fullUrl = this.baseUrl + image.uri;
|
|
283
|
+
return await this.textureLoader.loadAsync(fullUrl);
|
|
284
|
+
}
|
|
285
|
+
} else if (image.bufferView !== undefined) {
|
|
286
|
+
// Handle embedded binary data
|
|
287
|
+
const bufferView = this.json.bufferViews[image.bufferView];
|
|
288
|
+
const array = await this.getBufferView(
|
|
289
|
+
bufferView.byteOffset || 0,
|
|
290
|
+
bufferView.byteLength,
|
|
291
|
+
5121 // UNSIGNED_BYTE
|
|
292
|
+
);
|
|
293
|
+
const blob = new Blob([array], { type: image.mimeType });
|
|
294
|
+
const url = URL.createObjectURL(blob);
|
|
295
|
+
const texture = await this.textureLoader.loadAsync(url);
|
|
296
|
+
URL.revokeObjectURL(url);
|
|
297
|
+
texture.flipY = false; // GLTF standard
|
|
298
|
+
return texture;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// Load all textures
|
|
303
|
+
const texturePromises = [];
|
|
304
|
+
for (let i = 0; i < this.json.textures.length; i++) {
|
|
305
|
+
texturePromises.push(
|
|
306
|
+
loadTexture(this.json.textures[i].source).then((texture) => this.textureCache.set(i, texture))
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
await Promise.all(texturePromises);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
loadMaterials() {
|
|
313
|
+
if (!this.json.materials) return this.materials;
|
|
314
|
+
|
|
315
|
+
for (let i = 0; i < this.json.materials.length; i++) {
|
|
316
|
+
const materialDef = this.json.materials[i];
|
|
317
|
+
const material = this.createMaterial(materialDef);
|
|
318
|
+
this.materials.set(i, material);
|
|
319
|
+
}
|
|
320
|
+
return this.materials;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
createMaterial(materialDef) {
|
|
324
|
+
const material = new MeshStandardMaterial();
|
|
325
|
+
|
|
326
|
+
// Base color
|
|
327
|
+
if (materialDef.pbrMetallicRoughness) {
|
|
328
|
+
const pbr = materialDef.pbrMetallicRoughness;
|
|
329
|
+
|
|
330
|
+
if (pbr.baseColorFactor) {
|
|
331
|
+
material.color.fromArray(pbr.baseColorFactor);
|
|
332
|
+
material.opacity = pbr.baseColorFactor[3];
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (pbr.baseColorTexture) {
|
|
336
|
+
material.map = this.textureCache.get(pbr.baseColorTexture.index);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Metallic and roughness
|
|
340
|
+
if (pbr.metallicFactor !== undefined) {
|
|
341
|
+
material.metalness = pbr.metallicFactor;
|
|
342
|
+
}
|
|
343
|
+
if (pbr.roughnessFactor !== undefined) {
|
|
344
|
+
material.roughness = pbr.roughnessFactor;
|
|
345
|
+
}
|
|
346
|
+
if (pbr.metallicRoughnessTexture) {
|
|
347
|
+
material.metalnessMap = this.textureCache.get(pbr.metallicRoughnessTexture.index);
|
|
348
|
+
material.roughnessMap = material.metalnessMap;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Normal map
|
|
353
|
+
if (materialDef.normalTexture) {
|
|
354
|
+
material.normalMap = this.textureCache.get(materialDef.normalTexture.index);
|
|
355
|
+
if (materialDef.normalTexture.scale !== undefined) {
|
|
356
|
+
material.normalScale.set(materialDef.normalTexture.scale, materialDef.normalTexture.scale);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Emissive
|
|
361
|
+
if (materialDef.emissiveFactor) {
|
|
362
|
+
material.emissive.fromArray(materialDef.emissiveFactor);
|
|
363
|
+
}
|
|
364
|
+
if (materialDef.emissiveTexture) {
|
|
365
|
+
material.emissiveMap = this.textureCache.get(materialDef.emissiveTexture.index);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Occlusion
|
|
369
|
+
if (materialDef.occlusionTexture) {
|
|
370
|
+
material.aoMap = this.textureCache.get(materialDef.occlusionTexture.index);
|
|
371
|
+
if (materialDef.occlusionTexture.strength !== undefined) {
|
|
372
|
+
material.aoMapIntensity = materialDef.occlusionTexture.strength;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Alpha mode
|
|
377
|
+
if (materialDef.alphaMode === "BLEND") {
|
|
378
|
+
material.transparent = true;
|
|
379
|
+
} else if (materialDef.alphaMode === "MASK") {
|
|
380
|
+
material.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Double sided
|
|
384
|
+
material.side = materialDef.doubleSided ? DoubleSide : FrontSide;
|
|
385
|
+
|
|
386
|
+
material.name = materialDef.name;
|
|
387
|
+
|
|
388
|
+
return material;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
disposeMaterials() {
|
|
392
|
+
// Dispose all textures
|
|
393
|
+
this.textureCache.forEach((texture) => texture.dispose());
|
|
394
|
+
this.textureCache.clear();
|
|
395
|
+
|
|
396
|
+
// Dispose all materials
|
|
397
|
+
this.materials.forEach((material) => {
|
|
398
|
+
if (material.map) material.map.dispose();
|
|
399
|
+
if (material.lightMap) material.lightMap.dispose();
|
|
400
|
+
if (material.bumpMap) material.bumpMap.dispose();
|
|
401
|
+
if (material.normalMap) material.normalMap.dispose();
|
|
402
|
+
if (material.specularMap) material.specularMap.dispose();
|
|
403
|
+
if (material.envMap) material.envMap.dispose();
|
|
404
|
+
if (material.aoMap) material.aoMap.dispose();
|
|
405
|
+
if (material.metalnessMap) material.metalnessMap.dispose();
|
|
406
|
+
if (material.roughnessMap) material.roughnessMap.dispose();
|
|
407
|
+
if (material.emissiveMap) material.emissiveMap.dispose();
|
|
408
|
+
material.dispose();
|
|
409
|
+
});
|
|
410
|
+
this.materials.clear();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
estimateNodeSize(meshIndex) {
|
|
414
|
+
if (!this.json.meshes) return 0;
|
|
415
|
+
|
|
416
|
+
const meshDef = this.json.meshes[meshIndex];
|
|
417
|
+
if (!meshDef || !meshDef.primitives) return 0;
|
|
418
|
+
|
|
419
|
+
let totalSize = 0;
|
|
420
|
+
|
|
421
|
+
// Estimate size for each primitive
|
|
422
|
+
for (const primitive of meshDef.primitives) {
|
|
423
|
+
// Check for attributes
|
|
424
|
+
if (primitive.attributes) {
|
|
425
|
+
// Calculate attributes size
|
|
426
|
+
for (const [, accessorIndex] of Object.entries(primitive.attributes)) {
|
|
427
|
+
if (accessorIndex === undefined) continue;
|
|
428
|
+
|
|
429
|
+
const accessor = this.json.accessors[accessorIndex];
|
|
430
|
+
if (!accessor) continue;
|
|
431
|
+
|
|
432
|
+
const numComponents = this.getNumComponents(accessor.type);
|
|
433
|
+
const bytesPerComponent = this.getComponentSize(accessor.componentType);
|
|
434
|
+
totalSize += accessor.count * numComponents * bytesPerComponent;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// Calculate indices size if present
|
|
439
|
+
if (primitive.indices !== undefined) {
|
|
440
|
+
const accessor = this.json.accessors[primitive.indices];
|
|
441
|
+
if (accessor) {
|
|
442
|
+
const bytesPerComponent = this.getComponentSize(accessor.componentType);
|
|
443
|
+
totalSize += accessor.count * bytesPerComponent;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return totalSize;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { Group } from "three";
|
|
25
|
+
import { ILoader, LoadParams } from "@inweb/viewer-core";
|
|
26
|
+
|
|
27
|
+
import { Viewer } from "../Viewer";
|
|
28
|
+
import { DynamicModelImpl } from "./DynamicGltfLoader/DynamicModelImpl";
|
|
29
|
+
import { DynamicGltfLoader } from "./DynamicGltfLoader/DynamicGltfLoader.js";
|
|
30
|
+
import { GltfStructure } from "./DynamicGltfLoader/GltfStructure.js";
|
|
31
|
+
|
|
32
|
+
export class GLTFCloudDynamicLoader implements ILoader {
|
|
33
|
+
public viewer: Viewer;
|
|
34
|
+
public scene: Group;
|
|
35
|
+
public gltfLoader: DynamicGltfLoader;
|
|
36
|
+
public requestId = 0;
|
|
37
|
+
|
|
38
|
+
constructor(viewer: Viewer) {
|
|
39
|
+
this.viewer = viewer;
|
|
40
|
+
this.scene = new Group();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
dispose() {
|
|
44
|
+
if (this.gltfLoader) this.gltfLoader.clear();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
isSupport(file: any): boolean {
|
|
48
|
+
return (
|
|
49
|
+
typeof file === "object" &&
|
|
50
|
+
typeof file.database === "string" &&
|
|
51
|
+
typeof file.downloadResource === "function" &&
|
|
52
|
+
typeof file.downloadResourceRange === "function" &&
|
|
53
|
+
/.gltf$/i.test(file.database)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async load(model: any, format?: string, params?: LoadParams): Promise<this> {
|
|
58
|
+
this.gltfLoader = new DynamicGltfLoader(this.viewer.camera, this.viewer.scene, this.viewer.renderer);
|
|
59
|
+
this.gltfLoader.memoryLimit = this.viewer.options.memoryLimit;
|
|
60
|
+
|
|
61
|
+
this.gltfLoader.addEventListener("databasechunk", (data) => {
|
|
62
|
+
const modelImpl = new DynamicModelImpl(this.scene);
|
|
63
|
+
modelImpl.loader = this;
|
|
64
|
+
modelImpl.gltfLoader = this.gltfLoader;
|
|
65
|
+
modelImpl.viewer = this.viewer;
|
|
66
|
+
|
|
67
|
+
this.viewer.scene.add(this.scene);
|
|
68
|
+
this.viewer.models.push(modelImpl);
|
|
69
|
+
|
|
70
|
+
this.viewer.syncOptions();
|
|
71
|
+
this.viewer.syncOverlay();
|
|
72
|
+
this.viewer.update();
|
|
73
|
+
|
|
74
|
+
this.viewer.emitEvent({ type: "databasechunk", data, file: model.file, model });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
this.gltfLoader.addEventListener("geometryprogress", (data) => {
|
|
78
|
+
const progress = data.loaded / data.total;
|
|
79
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
this.gltfLoader.addEventListener("geometrymemory", (data) => {
|
|
83
|
+
this.viewer.emit({ type: "geometryprogress", data });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.gltfLoader.addEventListener("geometryerror", (data) => {
|
|
87
|
+
this.viewer.emitEvent({ type: "geometryerror", data, file: model.file, model });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
this.gltfLoader.addEventListener("update", (data) => {
|
|
91
|
+
this.viewer.update();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const loadController = {
|
|
95
|
+
loadJson: async () => {
|
|
96
|
+
const progress = (progress: number) => {
|
|
97
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model });
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const arrayBuffer = await model.downloadResource(
|
|
101
|
+
model.database,
|
|
102
|
+
progress,
|
|
103
|
+
this.gltfLoader.getAbortController().signal
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const text = new TextDecoder().decode(arrayBuffer);
|
|
107
|
+
const json = JSON.parse(text);
|
|
108
|
+
|
|
109
|
+
return json;
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
loadBinaryData: (requests) => {
|
|
113
|
+
const ranges = requests.map((request) => ({
|
|
114
|
+
begin: request.offset,
|
|
115
|
+
end: request.offset + request.length - 1,
|
|
116
|
+
requestId: this.requestId++,
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
return model.downloadResourceRange(
|
|
120
|
+
model.geometry[0],
|
|
121
|
+
undefined,
|
|
122
|
+
ranges,
|
|
123
|
+
undefined,
|
|
124
|
+
this.gltfLoader.getAbortController().signal
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
baseUrl: () => Promise.resolve(`${model.httpClient.serverUrl}${model.path}/`),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const structure = new GltfStructure(1);
|
|
132
|
+
await structure.initialize(loadController);
|
|
133
|
+
|
|
134
|
+
await this.gltfLoader.loadStructure(structure);
|
|
135
|
+
await this.gltfLoader.loadNodes();
|
|
136
|
+
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
cancel() {
|
|
141
|
+
if (this.gltfLoader) {
|
|
142
|
+
this.gltfLoader.abortLoading();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|