@inweb/viewer-three 26.2.0 → 26.2.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 +4 -57
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -3
- package/dist/viewer-three.module.js +2 -21
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/components/LightComponent.d.ts +1 -0
- package/lib/Viewer/components/LightHelperComponent.d.ts +9 -0
- package/package.json +5 -5
- package/src/Viewer/components/AxesHelperComponent.ts +15 -12
- package/src/Viewer/components/ExtentsHelperComponent.ts +7 -7
- package/src/Viewer/components/LightComponent.ts +24 -5
- package/src/Viewer/components/LightHelperComponent.ts +69 -0
- package/src/Viewer/components/index.ts +6 -6
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IComponent } from "@inweb/viewer-core";
|
|
2
|
+
import type { Viewer } from "../Viewer";
|
|
3
|
+
export declare class LightHelperComponent implements IComponent {
|
|
4
|
+
private viewer;
|
|
5
|
+
private lightHelpers;
|
|
6
|
+
constructor(viewer: Viewer);
|
|
7
|
+
dispose(): void;
|
|
8
|
+
geometryEnd: () => void;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "26.2.
|
|
3
|
+
"version": "26.2.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.2.
|
|
32
|
-
"@inweb/eventemitter2": "~26.2.
|
|
33
|
-
"@inweb/markup": "~26.2.
|
|
34
|
-
"@inweb/viewer-core": "~26.2.
|
|
31
|
+
"@inweb/client": "~26.2.2",
|
|
32
|
+
"@inweb/eventemitter2": "~26.2.2",
|
|
33
|
+
"@inweb/markup": "~26.2.2",
|
|
34
|
+
"@inweb/viewer-core": "~26.2.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/three": "^0.173.0",
|
|
@@ -41,10 +41,10 @@ export class AxesHelperComponent implements IComponent {
|
|
|
41
41
|
|
|
42
42
|
dispose() {
|
|
43
43
|
this.axesHelper1.removeFromParent();
|
|
44
|
-
this.axesHelper1
|
|
44
|
+
this.axesHelper1.dispose();
|
|
45
45
|
|
|
46
46
|
this.axesHelper2.removeFromParent();
|
|
47
|
-
this.axesHelper2
|
|
47
|
+
this.axesHelper2.dispose();
|
|
48
48
|
|
|
49
49
|
this.viewer.removeEventListener("geometryend", this.geometryEnd);
|
|
50
50
|
this.viewer.removeEventListener("clear", this.geometryEnd);
|
|
@@ -52,19 +52,22 @@ export class AxesHelperComponent implements IComponent {
|
|
|
52
52
|
|
|
53
53
|
geometryEnd = () => {
|
|
54
54
|
this.axesHelper1.removeFromParent();
|
|
55
|
+
this.axesHelper1.dispose();
|
|
56
|
+
|
|
55
57
|
this.axesHelper2.removeFromParent();
|
|
58
|
+
this.axesHelper2.dispose();
|
|
59
|
+
|
|
60
|
+
if (this.viewer.extents.isEmpty()) return;
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const center = this.viewer.extents.getCenter(new Vector3());
|
|
62
|
+
const size = this.viewer.extents.getSize(new Vector3()).length();
|
|
63
|
+
const center = this.viewer.extents.getCenter(new Vector3());
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
this.axesHelper1 = new AxesHelper(size);
|
|
66
|
+
this.axesHelper1.position.copy(center);
|
|
67
|
+
this.viewer.helpers.add(this.axesHelper1);
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
+
this.axesHelper2 = new AxesHelper(size);
|
|
70
|
+
this.axesHelper2.position.set(0, 0, 0);
|
|
71
|
+
this.viewer.helpers.add(this.axesHelper2);
|
|
69
72
|
};
|
|
70
73
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Box3, Box3Helper
|
|
24
|
+
import { Box3, Box3Helper } from "three";
|
|
25
25
|
|
|
26
26
|
import { IComponent } from "@inweb/viewer-core";
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
@@ -31,7 +31,7 @@ export class ExtentsHelperComponent implements IComponent {
|
|
|
31
31
|
private boxHelper: Box3Helper;
|
|
32
32
|
|
|
33
33
|
constructor(viewer: Viewer) {
|
|
34
|
-
this.boxHelper = new Box3Helper(new Box3());
|
|
34
|
+
this.boxHelper = new Box3Helper(new Box3(), "#ff0000");
|
|
35
35
|
this.viewer = viewer;
|
|
36
36
|
this.viewer.on("geometryend", this.geometryEnd);
|
|
37
37
|
this.viewer.on("explode", this.geometryEnd);
|
|
@@ -40,7 +40,7 @@ export class ExtentsHelperComponent implements IComponent {
|
|
|
40
40
|
|
|
41
41
|
dispose() {
|
|
42
42
|
this.boxHelper.removeFromParent();
|
|
43
|
-
this.boxHelper
|
|
43
|
+
this.boxHelper.dispose();
|
|
44
44
|
|
|
45
45
|
this.viewer.off("geometryend", this.geometryEnd);
|
|
46
46
|
this.viewer.off("explode", this.geometryEnd);
|
|
@@ -50,9 +50,9 @@ export class ExtentsHelperComponent implements IComponent {
|
|
|
50
50
|
geometryEnd = () => {
|
|
51
51
|
this.boxHelper.removeFromParent();
|
|
52
52
|
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if (this.viewer.extents.isEmpty()) return;
|
|
54
|
+
|
|
55
|
+
this.boxHelper.box = this.viewer.extents.clone();
|
|
56
|
+
this.viewer.helpers.add(this.boxHelper);
|
|
57
57
|
};
|
|
58
58
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { AmbientLight, DirectionalLight } from "three";
|
|
24
|
+
import { AmbientLight, DirectionalLight, Sphere } from "three";
|
|
25
25
|
|
|
26
26
|
import { IComponent } from "@inweb/viewer-core";
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
@@ -35,18 +35,37 @@ export class LightComponent implements IComponent {
|
|
|
35
35
|
this.viewer = viewer;
|
|
36
36
|
|
|
37
37
|
this.ambientLight = new AmbientLight(0xffffff, 0);
|
|
38
|
-
this.viewer.
|
|
38
|
+
this.viewer.scene.add(this.ambientLight);
|
|
39
39
|
|
|
40
40
|
this.directionalLight = new DirectionalLight(0xffffff, 1);
|
|
41
41
|
this.directionalLight.position.set(0.5, 0, 0.866); // ~60º
|
|
42
|
-
this.viewer.
|
|
42
|
+
this.viewer.scene.add(this.directionalLight);
|
|
43
|
+
|
|
44
|
+
this.viewer.addEventListener("geometryend", this.geometryEnd);
|
|
45
|
+
this.viewer.addEventListener("clear", this.geometryEnd);
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
dispose(): void {
|
|
46
49
|
this.ambientLight.removeFromParent();
|
|
47
|
-
this.ambientLight
|
|
50
|
+
this.ambientLight.dispose();
|
|
48
51
|
|
|
49
52
|
this.directionalLight.removeFromParent();
|
|
50
|
-
this.directionalLight
|
|
53
|
+
this.directionalLight.dispose();
|
|
54
|
+
|
|
55
|
+
this.viewer.removeEventListener("geometryend", this.geometryEnd);
|
|
56
|
+
this.viewer.removeEventListener("clear", this.geometryEnd);
|
|
51
57
|
}
|
|
58
|
+
|
|
59
|
+
geometryEnd = () => {
|
|
60
|
+
this.ambientLight.removeFromParent();
|
|
61
|
+
this.directionalLight.removeFromParent();
|
|
62
|
+
|
|
63
|
+
if (this.viewer.extents.isEmpty()) return;
|
|
64
|
+
|
|
65
|
+
const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2;
|
|
66
|
+
this.directionalLight.position.set(0.5, 0, 0.866).multiplyScalar(extentsSize * 2);
|
|
67
|
+
|
|
68
|
+
this.viewer.scene.add(this.ambientLight);
|
|
69
|
+
this.viewer.scene.add(this.directionalLight);
|
|
70
|
+
};
|
|
52
71
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, 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-2024 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 { DirectionalLightHelper, Sphere } from "three";
|
|
25
|
+
|
|
26
|
+
import { IComponent } from "@inweb/viewer-core";
|
|
27
|
+
import type { Viewer } from "../Viewer";
|
|
28
|
+
|
|
29
|
+
export class LightHelperComponent implements IComponent {
|
|
30
|
+
private viewer: Viewer;
|
|
31
|
+
private lightHelpers: DirectionalLightHelper[];
|
|
32
|
+
|
|
33
|
+
constructor(viewer: Viewer) {
|
|
34
|
+
this.lightHelpers = [];
|
|
35
|
+
this.viewer = viewer;
|
|
36
|
+
this.viewer.addEventListener("geometryend", this.geometryEnd);
|
|
37
|
+
this.viewer.addEventListener("clear", this.geometryEnd);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
dispose() {
|
|
41
|
+
this.lightHelpers.forEach((helper) => {
|
|
42
|
+
helper.removeFromParent();
|
|
43
|
+
helper.dispose();
|
|
44
|
+
});
|
|
45
|
+
this.lightHelpers.length = 0;
|
|
46
|
+
|
|
47
|
+
this.viewer.removeEventListener("geometryend", this.geometryEnd);
|
|
48
|
+
this.viewer.removeEventListener("clear", this.geometryEnd);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
geometryEnd = () => {
|
|
52
|
+
this.lightHelpers.forEach((helper) => {
|
|
53
|
+
helper.removeFromParent();
|
|
54
|
+
helper.dispose();
|
|
55
|
+
});
|
|
56
|
+
this.lightHelpers.length = 0;
|
|
57
|
+
|
|
58
|
+
const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2;
|
|
59
|
+
const size = extentsSize / 10;
|
|
60
|
+
|
|
61
|
+
this.viewer.scene.traverse((object: any) => {
|
|
62
|
+
if (object.isDirectionalLight) {
|
|
63
|
+
const helper = new DirectionalLightHelper(object, size, "#aa0000");
|
|
64
|
+
this.lightHelpers.push(helper);
|
|
65
|
+
this.viewer.helpers.add(helper);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -28,11 +28,11 @@ import { BackgroundComponent } from "./BackgroundComponent";
|
|
|
28
28
|
import { CameraComponent } from "./CameraComponent";
|
|
29
29
|
import { ExtentsComponent } from "./ExtentsComponent";
|
|
30
30
|
// import { ExtentsHelperComponent } from "./ExtentsHelperComponent";
|
|
31
|
-
import { LightComponent } from "./LightComponent";
|
|
31
|
+
// import { LightComponent } from "./LightComponent";
|
|
32
|
+
// import { LightHelperComponent } from "./LightHelperComponent";
|
|
32
33
|
import { RenderLoopComponent } from "./RenderLoopComponent";
|
|
33
34
|
import { ResizeCanvasComponent } from "./ResizeCanvasComponent";
|
|
34
35
|
import { SelectionComponent } from "./SelectionComponent";
|
|
35
|
-
// import { ViewPositionComponent } from "./ViewPositionComponent";
|
|
36
36
|
import { WCSHelperComponent } from "./WCSHelperComponent";
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -78,14 +78,14 @@ export const components: IComponentsRegistry = componentsRegistry("threejs");
|
|
|
78
78
|
// build-in components
|
|
79
79
|
|
|
80
80
|
components.registerComponent("ExtentsComponent", (viewer) => new ExtentsComponent(viewer));
|
|
81
|
-
components.registerComponent("LightComponent", (viewer) => new LightComponent(viewer));
|
|
82
|
-
components.registerComponent("BackgroundComponent", (viewer) => new BackgroundComponent(viewer));
|
|
83
81
|
components.registerComponent("CameraComponent", (viewer) => new CameraComponent(viewer));
|
|
82
|
+
components.registerComponent("BackgroundComponent", (viewer) => new BackgroundComponent(viewer));
|
|
83
|
+
// components.registerComponent("LightComponent", (viewer) => new LightComponent(viewer));
|
|
84
84
|
components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
|
|
85
85
|
components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
|
|
86
86
|
components.registerComponent("SelectionComponent", (viewer) => new SelectionComponent(viewer));
|
|
87
|
-
components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));
|
|
88
87
|
|
|
88
|
+
components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));
|
|
89
89
|
// components.registerComponent("AxesHelperComponent", (viewer) => new AxesHelperComponent(viewer));
|
|
90
90
|
// components.registerComponent("ExtentsHelperComponent", (viewer) => new ExtentsHelperComponent(viewer));
|
|
91
|
-
// components.registerComponent("
|
|
91
|
+
// components.registerComponent("LightHelperComponent", (viewer) => new LightHelperComponent(viewer));
|