@inweb/viewer-three 26.4.1 → 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 +61151 -44369
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +2 -7
- package/dist/viewer-three.module.js +209 -92
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +51 -68
- package/lib/Viewer/commands/index.d.ts +1 -1
- package/lib/Viewer/components/{ExtentsHelperComponent.d.ts → RoomEnvironmentComponent.d.ts} +2 -4
- 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/commands/index.ts +1 -1
- package/src/Viewer/components/BackgroundComponent.ts +1 -9
- package/src/Viewer/components/CameraComponent.ts +5 -1
- package/src/Viewer/components/ExtentsComponent.ts +1 -2
- package/src/Viewer/components/LightComponent.ts +6 -4
- package/src/Viewer/components/RoomEnvironmentComponent.ts +47 -0
- package/src/Viewer/components/index.ts +4 -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/LightHelperComponent.d.ts +0 -9
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { draggersRegistry, commandsRegistry, componentsRegistry, Options, CANVAS_EVENTS } from "@inweb/viewer-core";
|
|
1
|
+
import { draggersRegistry, commandsRegistry, componentsRegistry, Loader, loadersRegistry, Options, CANVAS_EVENTS } from "@inweb/viewer-core";
|
|
2
2
|
|
|
3
3
|
export * from "@inweb/viewer-core";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export * from "@inweb/markup";
|
|
8
|
-
|
|
9
|
-
import { Line, Vector3, BufferGeometry, Float32BufferAttribute, LineBasicMaterial, Mesh, MeshBasicMaterial, DoubleSide, EventDispatcher, MOUSE, TOUCH, Spherical, Quaternion, Vector2, Plane, Object3D, Matrix4, Vector4, Raycaster, Controls, Clock, Box3, Sphere, MathUtils, Color, PMREMGenerator, OrthographicCamera, CylinderGeometry, Sprite, CanvasTexture, SRGBColorSpace, SpriteMaterial, LoadingManager, LoaderUtils, Scene, PerspectiveCamera, WebGLRenderer, LinearToneMapping } from "three";
|
|
5
|
+
import { Line, Vector3, BufferGeometry, Float32BufferAttribute, LineBasicMaterial, Mesh, MeshBasicMaterial, DoubleSide, EventDispatcher, MOUSE, TOUCH, Spherical, Quaternion, Vector2, Plane, Object3D, Matrix4, Vector4, Raycaster, Controls, Clock, Box3, Sphere, MathUtils, Color, PMREMGenerator, AmbientLight, DirectionalLight, OrthographicCamera, CylinderGeometry, Sprite, CanvasTexture, SRGBColorSpace, SpriteMaterial, LoadingManager, LoaderUtils, Scene, PerspectiveCamera, WebGLRenderer, LinearToneMapping } from "three";
|
|
10
6
|
|
|
11
7
|
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
12
8
|
|
|
@@ -16,6 +12,10 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
|
16
12
|
|
|
17
13
|
import { EventEmitter2 } from "@inweb/eventemitter2";
|
|
18
14
|
|
|
15
|
+
import { Markup } from "@inweb/markup";
|
|
16
|
+
|
|
17
|
+
export * from "@inweb/markup";
|
|
18
|
+
|
|
19
19
|
class PlaneHelper extends Line {
|
|
20
20
|
constructor(plane, size = 1, color = 16776960, offset = new Vector3) {
|
|
21
21
|
const positions = [ 1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0, 1, 1, 0 ];
|
|
@@ -1519,7 +1519,7 @@ function calcExplodeDepth(object, depth) {
|
|
|
1519
1519
|
return res;
|
|
1520
1520
|
}
|
|
1521
1521
|
|
|
1522
|
-
function
|
|
1522
|
+
function explodeModel(scene, scale = 0, coeff = 4) {
|
|
1523
1523
|
scale /= 100;
|
|
1524
1524
|
if (!scene.explodeDepth) scene.explodeDepth = calcExplodeDepth(scene, 1);
|
|
1525
1525
|
const maxDepth = scene.explodeDepth;
|
|
@@ -1542,7 +1542,7 @@ function explodeScene(scene, scale = 0, coeff = 4) {
|
|
|
1542
1542
|
}
|
|
1543
1543
|
|
|
1544
1544
|
function explode(viewer, index = 0) {
|
|
1545
|
-
viewer.models.forEach((model =>
|
|
1545
|
+
viewer.models.forEach((model => explodeModel(model, index)));
|
|
1546
1546
|
viewer.scene.updateMatrixWorld();
|
|
1547
1547
|
viewer.update();
|
|
1548
1548
|
viewer.emitEvent({
|
|
@@ -1947,24 +1947,33 @@ class BackgroundComponent {
|
|
|
1947
1947
|
};
|
|
1948
1948
|
this.viewer = viewer;
|
|
1949
1949
|
this.backgroundColor = new Color(16777215);
|
|
1950
|
-
const environment = new RoomEnvironment;
|
|
1951
|
-
const pmremGenerator = new PMREMGenerator(this.viewer.renderer);
|
|
1952
1950
|
this.viewer.renderer.setClearColor(this.backgroundColor);
|
|
1953
1951
|
this.viewer.scene.background = this.backgroundColor;
|
|
1954
|
-
this.viewer.scene.environment = pmremGenerator.fromScene(environment).texture;
|
|
1955
1952
|
this.viewer.addEventListener("optionschange", this.syncOptions);
|
|
1956
|
-
environment.dispose();
|
|
1957
1953
|
}
|
|
1958
1954
|
dispose() {
|
|
1959
1955
|
this.viewer.removeEventListener("optionschange", this.syncOptions);
|
|
1960
|
-
this.viewer.scene.environment = undefined;
|
|
1961
1956
|
this.viewer.scene.background = undefined;
|
|
1962
1957
|
}
|
|
1963
1958
|
}
|
|
1964
1959
|
|
|
1960
|
+
class RoomEnvironmentComponent {
|
|
1961
|
+
constructor(viewer) {
|
|
1962
|
+
this.viewer = viewer;
|
|
1963
|
+
const environment = new RoomEnvironment;
|
|
1964
|
+
const pmremGenerator = new PMREMGenerator(this.viewer.renderer);
|
|
1965
|
+
this.viewer.scene.environment = pmremGenerator.fromScene(environment).texture;
|
|
1966
|
+
environment.dispose();
|
|
1967
|
+
}
|
|
1968
|
+
dispose() {
|
|
1969
|
+
this.viewer.scene.environment = undefined;
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1965
1973
|
class CameraComponent {
|
|
1966
1974
|
constructor(viewer) {
|
|
1967
1975
|
this.geometryEnd = () => {
|
|
1976
|
+
const extentsCenter = this.viewer.extents.getCenter(new Vector3);
|
|
1968
1977
|
const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere).radius * 2;
|
|
1969
1978
|
const rendererSize = this.viewer.renderer.getSize(new Vector2);
|
|
1970
1979
|
const aspect = rendererSize.x / rendererSize.y;
|
|
@@ -1991,6 +2000,7 @@ class CameraComponent {
|
|
|
1991
2000
|
camera.far = extentsSize * 100;
|
|
1992
2001
|
camera.updateProjectionMatrix();
|
|
1993
2002
|
}
|
|
2003
|
+
this.viewer.target.copy(extentsCenter);
|
|
1994
2004
|
if (!sceneCamera) {
|
|
1995
2005
|
this.viewer.executeCommand("setDefaultViewPosition");
|
|
1996
2006
|
}
|
|
@@ -2009,7 +2019,6 @@ class ExtentsComponent {
|
|
|
2009
2019
|
const extents = new Box3;
|
|
2010
2020
|
this.viewer.scene.traverseVisible((object => !object.children.length && extents.expandByObject(object)));
|
|
2011
2021
|
this.viewer.extents.copy(extents);
|
|
2012
|
-
this.viewer.target.copy(extents.getCenter(new Vector3));
|
|
2013
2022
|
};
|
|
2014
2023
|
this.viewer = viewer;
|
|
2015
2024
|
this.viewer.addEventListener("databasechunk", this.syncExtents);
|
|
@@ -2029,6 +2038,38 @@ class ExtentsComponent {
|
|
|
2029
2038
|
}
|
|
2030
2039
|
}
|
|
2031
2040
|
|
|
2041
|
+
class LightComponent {
|
|
2042
|
+
constructor(viewer) {
|
|
2043
|
+
this.geometryEnd = () => {
|
|
2044
|
+
this.ambientLight.removeFromParent();
|
|
2045
|
+
this.directionalLight.removeFromParent();
|
|
2046
|
+
if (this.viewer.extents.isEmpty()) return;
|
|
2047
|
+
const extentsCenter = this.viewer.extents.getCenter(new Vector3);
|
|
2048
|
+
const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere).radius * 2;
|
|
2049
|
+
this.directionalLight.position.set(.5, 0, .866).multiplyScalar(extentsSize).add(extentsCenter);
|
|
2050
|
+
this.directionalLight.target.position.copy(extentsCenter);
|
|
2051
|
+
this.viewer.scene.add(this.ambientLight);
|
|
2052
|
+
this.viewer.scene.add(this.directionalLight);
|
|
2053
|
+
};
|
|
2054
|
+
this.viewer = viewer;
|
|
2055
|
+
this.ambientLight = new AmbientLight(16777215, 0);
|
|
2056
|
+
this.viewer.scene.add(this.ambientLight);
|
|
2057
|
+
this.directionalLight = new DirectionalLight(16777215, 1);
|
|
2058
|
+
this.directionalLight.position.set(.5, 0, .866);
|
|
2059
|
+
this.viewer.scene.add(this.directionalLight);
|
|
2060
|
+
this.viewer.addEventListener("databasechunk", this.geometryEnd);
|
|
2061
|
+
this.viewer.addEventListener("clear", this.geometryEnd);
|
|
2062
|
+
}
|
|
2063
|
+
dispose() {
|
|
2064
|
+
this.ambientLight.removeFromParent();
|
|
2065
|
+
this.ambientLight.dispose();
|
|
2066
|
+
this.directionalLight.removeFromParent();
|
|
2067
|
+
this.directionalLight.dispose();
|
|
2068
|
+
this.viewer.removeEventListener("databasechunk", this.geometryEnd);
|
|
2069
|
+
this.viewer.removeEventListener("clear", this.geometryEnd);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2032
2073
|
class RenderLoopComponent {
|
|
2033
2074
|
constructor(viewer) {
|
|
2034
2075
|
this.animate = (time = 0) => {
|
|
@@ -2189,6 +2230,10 @@ components.registerComponent("CameraComponent", (viewer => new CameraComponent(v
|
|
|
2189
2230
|
|
|
2190
2231
|
components.registerComponent("BackgroundComponent", (viewer => new BackgroundComponent(viewer)));
|
|
2191
2232
|
|
|
2233
|
+
components.registerComponent("RoomEnvironmentComponent", (viewer => new RoomEnvironmentComponent(viewer)));
|
|
2234
|
+
|
|
2235
|
+
components.registerComponent("LightComponent", (viewer => new LightComponent(viewer)));
|
|
2236
|
+
|
|
2192
2237
|
components.registerComponent("ResizeCanvasComponent", (viewer => new ResizeCanvasComponent(viewer)));
|
|
2193
2238
|
|
|
2194
2239
|
components.registerComponent("RenderLoopComponent", (viewer => new RenderLoopComponent(viewer)));
|
|
@@ -2198,21 +2243,22 @@ components.registerComponent("SelectionComponent", (viewer => new SelectionCompo
|
|
|
2198
2243
|
components.registerComponent("WCSHelperComponent", (viewer => new WCSHelperComponent(viewer)));
|
|
2199
2244
|
|
|
2200
2245
|
class GLTFLoadingManager extends LoadingManager {
|
|
2201
|
-
constructor(file,
|
|
2246
|
+
constructor(file, params = {}) {
|
|
2202
2247
|
super();
|
|
2203
2248
|
this.path = "";
|
|
2204
2249
|
this.resourcePath = "";
|
|
2205
2250
|
this.fileURL = "";
|
|
2206
2251
|
this.dataURLs = new Map;
|
|
2207
2252
|
this.path = params.path || "";
|
|
2253
|
+
const externalFiles = params.externalFiles || new Map;
|
|
2208
2254
|
if (typeof file === "string") {
|
|
2209
2255
|
this.fileURL = file;
|
|
2210
2256
|
this.resourcePath = LoaderUtils.extractUrlBase(file);
|
|
2211
2257
|
} else {
|
|
2212
|
-
|
|
2213
|
-
|
|
2258
|
+
externalFiles.forEach(((value, key) => this.fileURL = value === file ? key : this.fileURL));
|
|
2259
|
+
externalFiles.set(this.fileURL, file);
|
|
2214
2260
|
}
|
|
2215
|
-
|
|
2261
|
+
externalFiles.forEach(((value, key) => {
|
|
2216
2262
|
let dataURL;
|
|
2217
2263
|
if (typeof value === "string") dataURL = value; else dataURL = URL.createObjectURL(new Blob([ value ]));
|
|
2218
2264
|
this.dataURLs.set(key, dataURL);
|
|
@@ -2228,6 +2274,91 @@ class GLTFLoadingManager extends LoadingManager {
|
|
|
2228
2274
|
}
|
|
2229
2275
|
}
|
|
2230
2276
|
|
|
2277
|
+
class GLTFModelLoader extends Loader {
|
|
2278
|
+
constructor(viewer) {
|
|
2279
|
+
super();
|
|
2280
|
+
this.viewer = viewer;
|
|
2281
|
+
}
|
|
2282
|
+
isSupport(model) {
|
|
2283
|
+
return typeof model === "object" && typeof model.database === "string" && typeof model.downloadResource === "function" && /.gltf$/i.test(model.database);
|
|
2284
|
+
}
|
|
2285
|
+
async load(model) {
|
|
2286
|
+
const url = `${model.httpClient.serverUrl}${model.path}/${model.database}`;
|
|
2287
|
+
const manager = new GLTFLoadingManager(url);
|
|
2288
|
+
const loader = new GLTFLoader(manager);
|
|
2289
|
+
loader.setRequestHeader(model.httpClient.headers);
|
|
2290
|
+
const progress = event => {
|
|
2291
|
+
const {lengthComputable: lengthComputable, loaded: loaded, total: total} = event;
|
|
2292
|
+
const progress = lengthComputable ? loaded / total : 1;
|
|
2293
|
+
this.viewer.emitEvent({
|
|
2294
|
+
type: "geometryprogress",
|
|
2295
|
+
data: progress,
|
|
2296
|
+
file: model.file,
|
|
2297
|
+
model: model
|
|
2298
|
+
});
|
|
2299
|
+
};
|
|
2300
|
+
const gltf = await loader.loadAsync(url, progress);
|
|
2301
|
+
if (!this.viewer.scene) return this;
|
|
2302
|
+
this.viewer.scene.add(gltf.scene);
|
|
2303
|
+
this.viewer.models.push(gltf.scene);
|
|
2304
|
+
this.viewer.syncOptions();
|
|
2305
|
+
this.viewer.syncOverlay();
|
|
2306
|
+
this.viewer.update();
|
|
2307
|
+
this.viewer.emitEvent({
|
|
2308
|
+
type: "databasechunk",
|
|
2309
|
+
data: gltf.scene,
|
|
2310
|
+
file: model.file,
|
|
2311
|
+
model: model
|
|
2312
|
+
});
|
|
2313
|
+
return this;
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
class GLTFFileLoader extends Loader {
|
|
2318
|
+
constructor(viewer) {
|
|
2319
|
+
super();
|
|
2320
|
+
this.viewer = viewer;
|
|
2321
|
+
}
|
|
2322
|
+
isSupport(file, format) {
|
|
2323
|
+
return (typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) && /(gltf|glb)$/i.test(format);
|
|
2324
|
+
}
|
|
2325
|
+
async load(buffer, format, params) {
|
|
2326
|
+
const manager = new GLTFLoadingManager(buffer, params);
|
|
2327
|
+
const loader = new GLTFLoader(manager);
|
|
2328
|
+
loader.setPath(manager.path);
|
|
2329
|
+
loader.setCrossOrigin(params.crossOrigin || loader.crossOrigin);
|
|
2330
|
+
loader.setWithCredentials(params.withCredentials || loader.withCredentials);
|
|
2331
|
+
const progress = event => {
|
|
2332
|
+
const {lengthComputable: lengthComputable, loaded: loaded, total: total} = event;
|
|
2333
|
+
const progress = lengthComputable ? loaded / total : 1;
|
|
2334
|
+
this.viewer.emitEvent({
|
|
2335
|
+
type: "geometryprogress",
|
|
2336
|
+
data: progress,
|
|
2337
|
+
file: buffer
|
|
2338
|
+
});
|
|
2339
|
+
};
|
|
2340
|
+
const gltf = await loader.loadAsync(manager.fileURL, progress);
|
|
2341
|
+
if (!this.viewer.scene) return this;
|
|
2342
|
+
this.viewer.scene.add(gltf.scene);
|
|
2343
|
+
this.viewer.models.push(gltf.scene);
|
|
2344
|
+
this.viewer.syncOptions();
|
|
2345
|
+
this.viewer.syncOverlay();
|
|
2346
|
+
this.viewer.update();
|
|
2347
|
+
this.viewer.emitEvent({
|
|
2348
|
+
type: "databasechunk",
|
|
2349
|
+
data: gltf.scene,
|
|
2350
|
+
file: buffer
|
|
2351
|
+
});
|
|
2352
|
+
return this;
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
const loaders = loadersRegistry("threejs");
|
|
2357
|
+
|
|
2358
|
+
loaders.registerLoader("gltf", (viewer => new GLTFModelLoader(viewer)));
|
|
2359
|
+
|
|
2360
|
+
loaders.registerLoader("gltf-file", (viewer => new GLTFFileLoader(viewer)));
|
|
2361
|
+
|
|
2231
2362
|
class Viewer extends EventEmitter2 {
|
|
2232
2363
|
constructor(client) {
|
|
2233
2364
|
super();
|
|
@@ -2236,6 +2367,7 @@ class Viewer extends EventEmitter2 {
|
|
|
2236
2367
|
this.canvasEvents = CANVAS_EVENTS;
|
|
2237
2368
|
this.canvaseventlistener = event => this.emit(event);
|
|
2238
2369
|
this.models = [];
|
|
2370
|
+
this.loaders = [];
|
|
2239
2371
|
this.selected = [];
|
|
2240
2372
|
this.extents = new Box3;
|
|
2241
2373
|
this.target = new Vector3;
|
|
@@ -2361,97 +2493,80 @@ class Viewer extends EventEmitter2 {
|
|
|
2361
2493
|
loadReferences(model) {
|
|
2362
2494
|
return Promise.resolve(this);
|
|
2363
2495
|
}
|
|
2364
|
-
async open(file) {
|
|
2496
|
+
async open(file, params = {}) {
|
|
2365
2497
|
if (!this.renderer) return this;
|
|
2366
|
-
|
|
2367
|
-
|
|
2498
|
+
if (params.mode !== "a" && params.mode !== "append") {
|
|
2499
|
+
this.cancel();
|
|
2500
|
+
this.clear();
|
|
2501
|
+
}
|
|
2368
2502
|
this.emitEvent({
|
|
2369
2503
|
type: "open",
|
|
2370
|
-
file: file
|
|
2371
|
-
model: file
|
|
2504
|
+
file: file
|
|
2372
2505
|
});
|
|
2373
|
-
let model =
|
|
2374
|
-
if (
|
|
2375
|
-
const models = await
|
|
2376
|
-
model = models.find((model => model.default)) || models[0];
|
|
2506
|
+
let model = file;
|
|
2507
|
+
if (model && typeof model.getModels === "function") {
|
|
2508
|
+
const models = await model.getModels();
|
|
2509
|
+
model = models.find((model => model.default)) || models[0] || file;
|
|
2377
2510
|
}
|
|
2378
|
-
if (!model) throw new Error(
|
|
2379
|
-
|
|
2380
|
-
if (
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
await this.loadGltfFile(url, undefined, params);
|
|
2387
|
-
return this;
|
|
2388
|
-
}
|
|
2389
|
-
cancel() {
|
|
2511
|
+
if (!model) throw new Error(`Format not supported`);
|
|
2512
|
+
let format = params.format;
|
|
2513
|
+
if (!format && typeof model.type === "string") format = model.type.split(".").pop();
|
|
2514
|
+
if (!format && typeof file === "string") format = file.split(".").pop();
|
|
2515
|
+
if (!format && file instanceof globalThis.File) format = file.name.split(".").pop();
|
|
2516
|
+
const loader = loaders.createLoader(this, model, format);
|
|
2517
|
+
if (!loader) throw new Error(`Format not supported`);
|
|
2518
|
+
this.loaders.push(loader);
|
|
2390
2519
|
this.emitEvent({
|
|
2391
|
-
type: "
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
}
|
|
2395
|
-
openGltfFile(file, externalData = new Map, params = {}) {
|
|
2396
|
-
if (!this.renderer) return Promise.resolve(this);
|
|
2397
|
-
this.cancel();
|
|
2398
|
-
this.clear();
|
|
2399
|
-
this.emitEvent({
|
|
2400
|
-
type: "open"
|
|
2520
|
+
type: "geometrystart",
|
|
2521
|
+
file: file,
|
|
2522
|
+
model: model
|
|
2401
2523
|
});
|
|
2402
|
-
return this.loadGltfFile(file, externalData, params);
|
|
2403
|
-
}
|
|
2404
|
-
async loadGltfFile(file, externalData = new Map, params = {}) {
|
|
2405
|
-
const manager = new GLTFLoadingManager(file, externalData, params);
|
|
2406
2524
|
try {
|
|
2407
|
-
this.
|
|
2408
|
-
|
|
2409
|
-
});
|
|
2410
|
-
const loader = new GLTFLoader(manager);
|
|
2411
|
-
loader.setPath(manager.path);
|
|
2412
|
-
loader.setRequestHeader(params.requestHeader);
|
|
2413
|
-
loader.setCrossOrigin(params.crossOrigin || loader.crossOrigin);
|
|
2414
|
-
loader.setWithCredentials(params.withCredentials || loader.withCredentials);
|
|
2415
|
-
const gltf = await loader.loadAsync(manager.fileURL, (event => {
|
|
2416
|
-
const {lengthComputable: lengthComputable, loaded: loaded, total: total} = event;
|
|
2417
|
-
const progress = lengthComputable ? loaded / total : 1;
|
|
2418
|
-
this.emitEvent({
|
|
2419
|
-
type: "geometryprogress",
|
|
2420
|
-
data: progress
|
|
2421
|
-
});
|
|
2422
|
-
}));
|
|
2423
|
-
if (!this.scene) return this;
|
|
2424
|
-
if (!gltf.scene) throw new Error("No glTF scene found");
|
|
2425
|
-
this.models.push(gltf);
|
|
2426
|
-
this.scene.add(gltf.scene);
|
|
2427
|
-
this.syncOptions();
|
|
2428
|
-
this.syncOverlay();
|
|
2429
|
-
this.update();
|
|
2430
|
-
this.emitEvent({
|
|
2431
|
-
type: "databasechunk"
|
|
2432
|
-
});
|
|
2433
|
-
this.emitEvent({
|
|
2434
|
-
type: "geometryend",
|
|
2435
|
-
data: gltf.scene
|
|
2436
|
-
});
|
|
2525
|
+
await this.loadReferences(model);
|
|
2526
|
+
await loader.load(model, format, params);
|
|
2437
2527
|
} catch (error) {
|
|
2438
2528
|
this.emitEvent({
|
|
2439
2529
|
type: "geometryerror",
|
|
2440
|
-
data: error
|
|
2530
|
+
data: error,
|
|
2531
|
+
file: file,
|
|
2532
|
+
model: model
|
|
2441
2533
|
});
|
|
2442
2534
|
throw error;
|
|
2443
|
-
} finally {
|
|
2444
|
-
manager.dispose();
|
|
2445
2535
|
}
|
|
2536
|
+
this.emitEvent({
|
|
2537
|
+
type: "geometryend",
|
|
2538
|
+
file: file,
|
|
2539
|
+
model: model
|
|
2540
|
+
});
|
|
2541
|
+
return this;
|
|
2542
|
+
}
|
|
2543
|
+
openGltfFile(file, externalFiles, params = {}) {
|
|
2544
|
+
return this.open(file, {
|
|
2545
|
+
...params,
|
|
2546
|
+
format: "gltf",
|
|
2547
|
+
externalFiles: externalFiles
|
|
2548
|
+
});
|
|
2549
|
+
}
|
|
2550
|
+
loadGltfFile(file, externalFiles, params = {}) {
|
|
2551
|
+
return this.open(file, {
|
|
2552
|
+
...params,
|
|
2553
|
+
format: "gltf",
|
|
2554
|
+
externalFiles: externalFiles,
|
|
2555
|
+
mode: "append"
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
cancel() {
|
|
2559
|
+
this.loaders.forEach((loader => loader.cancel()));
|
|
2560
|
+
this.emitEvent({
|
|
2561
|
+
type: "cancel"
|
|
2562
|
+
});
|
|
2446
2563
|
return this;
|
|
2447
2564
|
}
|
|
2448
2565
|
clear() {
|
|
2449
2566
|
if (!this.renderer) return this;
|
|
2450
2567
|
function disposeMaterial(material) {
|
|
2451
2568
|
const materials = Array.isArray(material) ? material : [ material ];
|
|
2452
|
-
materials.forEach((material =>
|
|
2453
|
-
material.dispose();
|
|
2454
|
-
}));
|
|
2569
|
+
materials.forEach((material => material.dispose()));
|
|
2455
2570
|
}
|
|
2456
2571
|
function disposeObject(object) {
|
|
2457
2572
|
if (object.geometry) object.geometry.dispose();
|
|
@@ -2463,10 +2578,12 @@ class Viewer extends EventEmitter2 {
|
|
|
2463
2578
|
this.clearSelected();
|
|
2464
2579
|
this.helpers.traverse(disposeObject);
|
|
2465
2580
|
this.helpers.clear();
|
|
2466
|
-
this.models.forEach((
|
|
2467
|
-
this.models.forEach((
|
|
2581
|
+
this.models.forEach((model => model.traverse(disposeObject)));
|
|
2582
|
+
this.models.forEach((model => model.removeFromParent()));
|
|
2468
2583
|
this.models = [];
|
|
2469
2584
|
this.scene.clear();
|
|
2585
|
+
this.loaders.forEach((loader => loader.dispose()));
|
|
2586
|
+
this.loaders = [];
|
|
2470
2587
|
this.syncOptions();
|
|
2471
2588
|
this.syncOverlay();
|
|
2472
2589
|
this.update(true);
|
|
@@ -2729,5 +2846,5 @@ class Viewer extends EventEmitter2 {
|
|
|
2729
2846
|
}
|
|
2730
2847
|
}
|
|
2731
2848
|
|
|
2732
|
-
export { Viewer, commands, components, draggers };
|
|
2849
|
+
export { GLTFLoadingManager, Viewer, commands, components, draggers, loaders };
|
|
2733
2850
|
//# sourceMappingURL=viewer-three.module.js.map
|