@inweb/viewer-three 26.4.1 → 26.4.2
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/viewer-three.js +55 -28
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -3
- package/dist/viewer-three.module.js +17 -6
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/commands/index.d.ts +1 -1
- package/lib/Viewer/components/RoomEnvironmentComponent.d.ts +7 -0
- package/package.json +5 -5
- 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 +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "26.4.
|
|
3
|
+
"version": "26.4.2",
|
|
4
4
|
"description": "JavaScript library for rendering CAD and BIM files in a browser using Three.js",
|
|
5
5
|
"homepage": "https://cloud.opendesign.com/docs/index.html",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"docs": "typedoc"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@inweb/client": "~26.4.
|
|
32
|
-
"@inweb/eventemitter2": "~26.4.
|
|
33
|
-
"@inweb/markup": "~26.4.
|
|
34
|
-
"@inweb/viewer-core": "~26.4.
|
|
31
|
+
"@inweb/client": "~26.4.2",
|
|
32
|
+
"@inweb/eventemitter2": "~26.4.2",
|
|
33
|
+
"@inweb/markup": "~26.4.2",
|
|
34
|
+
"@inweb/viewer-core": "~26.4.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/three": "^0.173.0",
|
|
@@ -47,7 +47,7 @@ import { zoomToObjects } from "./ZoomToObjects";
|
|
|
47
47
|
import { zoomToSelected } from "./ZoomToSelected";
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Viewer commands registry. Use this registry to register custom commands.
|
|
51
51
|
*
|
|
52
52
|
* To implement custom command:
|
|
53
53
|
*
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Color
|
|
25
|
-
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
|
|
24
|
+
import { Color } from "three";
|
|
26
25
|
|
|
27
26
|
import { IComponent } from "@inweb/viewer-core";
|
|
28
27
|
import type { Viewer } from "../Viewer";
|
|
@@ -36,20 +35,13 @@ export class BackgroundComponent implements IComponent {
|
|
|
36
35
|
|
|
37
36
|
this.backgroundColor = new Color(0xffffff);
|
|
38
37
|
|
|
39
|
-
const environment = new RoomEnvironment();
|
|
40
|
-
const pmremGenerator = new PMREMGenerator(this.viewer.renderer);
|
|
41
|
-
|
|
42
38
|
this.viewer.renderer.setClearColor(this.backgroundColor);
|
|
43
39
|
this.viewer.scene.background = this.backgroundColor;
|
|
44
|
-
this.viewer.scene.environment = pmremGenerator.fromScene(environment).texture;
|
|
45
40
|
this.viewer.addEventListener("optionschange", this.syncOptions);
|
|
46
|
-
|
|
47
|
-
environment.dispose();
|
|
48
41
|
}
|
|
49
42
|
|
|
50
43
|
dispose() {
|
|
51
44
|
this.viewer.removeEventListener("optionschange", this.syncOptions);
|
|
52
|
-
this.viewer.scene.environment = undefined;
|
|
53
45
|
this.viewer.scene.background = undefined;
|
|
54
46
|
}
|
|
55
47
|
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Sphere, Vector2 } from "three";
|
|
24
|
+
import { Sphere, Vector2, Vector3 } from "three";
|
|
25
25
|
|
|
26
26
|
import { IComponent } from "@inweb/viewer-core";
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
@@ -39,10 +39,12 @@ export class CameraComponent implements IComponent {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
geometryEnd = () => {
|
|
42
|
+
const extentsCenter = this.viewer.extents.getCenter(new Vector3());
|
|
42
43
|
const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2;
|
|
43
44
|
const rendererSize = this.viewer.renderer.getSize(new Vector2());
|
|
44
45
|
const aspect = rendererSize.x / rendererSize.y;
|
|
45
46
|
|
|
47
|
+
// TODO: do not change the camera and target after opening the second model in "append" mode
|
|
46
48
|
let sceneCamera: any;
|
|
47
49
|
this.viewer.scene.traverse((object: any) => {
|
|
48
50
|
if (object.isCamera)
|
|
@@ -71,6 +73,8 @@ export class CameraComponent implements IComponent {
|
|
|
71
73
|
camera.updateProjectionMatrix();
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
this.viewer.target.copy(extentsCenter);
|
|
77
|
+
|
|
74
78
|
if (!sceneCamera) {
|
|
75
79
|
this.viewer.executeCommand("setDefaultViewPosition");
|
|
76
80
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Box3
|
|
24
|
+
import { Box3 } from "three";
|
|
25
25
|
|
|
26
26
|
import { IComponent } from "@inweb/viewer-core";
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
@@ -53,6 +53,5 @@ export class ExtentsComponent implements IComponent {
|
|
|
53
53
|
this.viewer.scene.traverseVisible((object) => !object.children.length && extents.expandByObject(object));
|
|
54
54
|
|
|
55
55
|
this.viewer.extents.copy(extents);
|
|
56
|
-
this.viewer.target.copy(extents.getCenter(new Vector3()));
|
|
57
56
|
};
|
|
58
57
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { AmbientLight, DirectionalLight, Sphere } from "three";
|
|
24
|
+
import { AmbientLight, DirectionalLight, Sphere, Vector3 } from "three";
|
|
25
25
|
|
|
26
26
|
import { IComponent } from "@inweb/viewer-core";
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
@@ -41,7 +41,7 @@ export class LightComponent implements IComponent {
|
|
|
41
41
|
this.directionalLight.position.set(0.5, 0, 0.866); // ~60º
|
|
42
42
|
this.viewer.scene.add(this.directionalLight);
|
|
43
43
|
|
|
44
|
-
this.viewer.addEventListener("
|
|
44
|
+
this.viewer.addEventListener("databasechunk", this.geometryEnd);
|
|
45
45
|
this.viewer.addEventListener("clear", this.geometryEnd);
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -52,7 +52,7 @@ export class LightComponent implements IComponent {
|
|
|
52
52
|
this.directionalLight.removeFromParent();
|
|
53
53
|
this.directionalLight.dispose();
|
|
54
54
|
|
|
55
|
-
this.viewer.removeEventListener("
|
|
55
|
+
this.viewer.removeEventListener("databasechunk", this.geometryEnd);
|
|
56
56
|
this.viewer.removeEventListener("clear", this.geometryEnd);
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -62,8 +62,10 @@ export class LightComponent implements IComponent {
|
|
|
62
62
|
|
|
63
63
|
if (this.viewer.extents.isEmpty()) return;
|
|
64
64
|
|
|
65
|
+
const extentsCenter = this.viewer.extents.getCenter(new Vector3());
|
|
65
66
|
const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2;
|
|
66
|
-
this.directionalLight.position.set(0.5, 0, 0.866).multiplyScalar(extentsSize
|
|
67
|
+
this.directionalLight.position.set(0.5, 0, 0.866).multiplyScalar(extentsSize).add(extentsCenter);
|
|
68
|
+
this.directionalLight.target.position.copy(extentsCenter);
|
|
67
69
|
|
|
68
70
|
this.viewer.scene.add(this.ambientLight);
|
|
69
71
|
this.viewer.scene.add(this.directionalLight);
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { PMREMGenerator } from "three";
|
|
25
|
+
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
|
|
26
|
+
|
|
27
|
+
import { IComponent } from "@inweb/viewer-core";
|
|
28
|
+
import type { Viewer } from "../Viewer";
|
|
29
|
+
|
|
30
|
+
export class RoomEnvironmentComponent implements IComponent {
|
|
31
|
+
protected viewer: Viewer;
|
|
32
|
+
|
|
33
|
+
constructor(viewer: Viewer) {
|
|
34
|
+
this.viewer = viewer;
|
|
35
|
+
|
|
36
|
+
const environment = new RoomEnvironment();
|
|
37
|
+
const pmremGenerator = new PMREMGenerator(this.viewer.renderer);
|
|
38
|
+
|
|
39
|
+
this.viewer.scene.environment = pmremGenerator.fromScene(environment).texture;
|
|
40
|
+
|
|
41
|
+
environment.dispose();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dispose() {
|
|
45
|
+
this.viewer.scene.environment = undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -25,6 +25,7 @@ import { IComponentsRegistry, componentsRegistry } from "@inweb/viewer-core";
|
|
|
25
25
|
|
|
26
26
|
// import { AxesHelperComponent } from "./AxesHelperComponent";
|
|
27
27
|
import { BackgroundComponent } from "./BackgroundComponent";
|
|
28
|
+
import { RoomEnvironmentComponent } from "./RoomEnvironmentComponent";
|
|
28
29
|
import { CameraComponent } from "./CameraComponent";
|
|
29
30
|
import { ExtentsComponent } from "./ExtentsComponent";
|
|
30
31
|
// import { ExtentsHelperComponent } from "./ExtentsHelperComponent";
|
|
@@ -80,6 +81,7 @@ export const components: IComponentsRegistry = componentsRegistry("threejs");
|
|
|
80
81
|
components.registerComponent("ExtentsComponent", (viewer) => new ExtentsComponent(viewer));
|
|
81
82
|
components.registerComponent("CameraComponent", (viewer) => new CameraComponent(viewer));
|
|
82
83
|
components.registerComponent("BackgroundComponent", (viewer) => new BackgroundComponent(viewer));
|
|
84
|
+
components.registerComponent("RoomEnvironmentComponent", (viewer) => new RoomEnvironmentComponent(viewer));
|
|
83
85
|
// components.registerComponent("LightComponent", (viewer) => new LightComponent(viewer));
|
|
84
86
|
components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
|
|
85
87
|
components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
|