@inweb/viewer-three 27.1.1 → 27.1.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/extensions/components/AxesHelperComponent.js +12 -11
- package/dist/extensions/components/AxesHelperComponent.js.map +1 -1
- package/dist/extensions/components/AxesHelperComponent.min.js +1 -1
- package/dist/extensions/components/AxesHelperComponent.module.js +12 -11
- package/dist/extensions/components/AxesHelperComponent.module.js.map +1 -1
- package/dist/extensions/components/GridHelperComponent.js +4 -6
- package/dist/extensions/components/GridHelperComponent.js.map +1 -1
- package/dist/extensions/components/GridHelperComponent.min.js +1 -1
- package/dist/extensions/components/GridHelperComponent.module.js +4 -6
- package/dist/extensions/components/GridHelperComponent.module.js.map +1 -1
- package/dist/extensions/components/LightHelperComponent.js +5 -5
- package/dist/extensions/components/LightHelperComponent.js.map +1 -1
- package/dist/extensions/components/LightHelperComponent.min.js +1 -1
- package/dist/extensions/components/LightHelperComponent.module.js +6 -6
- package/dist/extensions/components/LightHelperComponent.module.js.map +1 -1
- package/dist/viewer-three.js +1344 -78
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +4 -4
- package/dist/viewer-three.module.js +98 -79
- package/dist/viewer-three.module.js.map +1 -1
- package/extensions/components/AxesHelperComponent.ts +13 -12
- package/extensions/components/GridHelperComponent.ts +4 -6
- package/extensions/components/LightHelperComponent.ts +6 -6
- package/lib/Viewer/commands/SetDefaultViewPosition.d.ts +1 -1
- package/lib/Viewer/loaders/GLTFBinaryParser.d.ts +11 -0
- package/lib/Viewer/loaders/GLTFFileDynamicLoader.d.ts +0 -1
- package/lib/Viewer/loaders/JSONStreamParser.d.ts +5 -0
- package/package.json +7 -5
- package/src/Viewer/Viewer.ts +4 -7
- package/src/Viewer/commands/SetDefaultViewPosition.ts +3 -3
- package/src/Viewer/commands/ZoomTo.ts +6 -6
- package/src/Viewer/components/CameraComponent.ts +3 -3
- package/src/Viewer/components/LightComponent.ts +5 -8
- package/src/Viewer/components/SelectionComponent.ts +3 -1
- package/src/Viewer/draggers/CuttingPlaneDragger.ts +6 -6
- package/src/Viewer/draggers/FlyDragger.ts +1 -1
- package/src/Viewer/draggers/MeasureLineDragger.ts +10 -7
- package/src/Viewer/draggers/WalkDragger.ts +1 -1
- package/src/Viewer/loaders/DynamicGltfLoader/GltfStructure.js +7 -1
- package/src/Viewer/loaders/{GLTFBinaryExtension.ts → GLTFBinaryParser.ts} +34 -29
- package/src/Viewer/loaders/GLTFCloudDynamicLoader.ts +10 -9
- package/src/Viewer/loaders/GLTFFileDynamicLoader.ts +9 -8
- package/src/Viewer/loaders/JSONStreamParser.ts +38 -0
- package/lib/Viewer/loaders/GLTFBinaryExtension.d.ts +0 -5
|
@@ -35,7 +35,7 @@ class AxesHelperComponent implements IComponent {
|
|
|
35
35
|
this.axesHelper2 = new AxesHelper(1);
|
|
36
36
|
this.modelHelpers = [];
|
|
37
37
|
|
|
38
|
-
this.axesHelper1.setColors("#ccc", "#ccc", "#ccc");
|
|
38
|
+
// this.axesHelper1.setColors("#ccc", "#ccc", "#ccc");
|
|
39
39
|
|
|
40
40
|
this.viewer = viewer;
|
|
41
41
|
this.viewer.addEventListener("initialize", this.syncHelper);
|
|
@@ -70,27 +70,28 @@ class AxesHelperComponent implements IComponent {
|
|
|
70
70
|
this.axesHelper1.removeFromParent();
|
|
71
71
|
this.axesHelper2.removeFromParent();
|
|
72
72
|
|
|
73
|
-
const
|
|
74
|
-
const
|
|
73
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
74
|
+
const extentsCenter = this.viewer.extents.getCenter(new Vector3());
|
|
75
75
|
|
|
76
76
|
this.axesHelper1.position.set(0, 0, 0);
|
|
77
|
-
this.axesHelper1.scale.setScalar(
|
|
77
|
+
this.axesHelper1.scale.setScalar(extentsSize * 1.5);
|
|
78
|
+
this.viewer.helpers.add(this.axesHelper1);
|
|
78
79
|
|
|
79
|
-
this.
|
|
80
|
-
this.axesHelper2.scale.setScalar(size);
|
|
80
|
+
if (this.viewer.models.length < 1) return;
|
|
81
81
|
|
|
82
|
-
this.
|
|
82
|
+
this.axesHelper2.position.copy(extentsCenter);
|
|
83
|
+
this.axesHelper2.scale.setScalar(extentsSize);
|
|
83
84
|
this.viewer.helpers.add(this.axesHelper2);
|
|
84
85
|
|
|
85
86
|
if (this.viewer.models.length < 2) return;
|
|
86
87
|
|
|
87
88
|
this.viewer.models.forEach((model) => {
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const
|
|
89
|
+
const modelExtents = model.getExtents(new Box3());
|
|
90
|
+
const modelSize = modelExtents.getSize(new Vector3()).length() || 1;
|
|
91
|
+
const modelCenter = modelExtents.getCenter(new Vector3());
|
|
91
92
|
|
|
92
|
-
const helper = new AxesHelper(
|
|
93
|
-
helper.position.copy(
|
|
93
|
+
const helper = new AxesHelper(modelSize);
|
|
94
|
+
helper.position.copy(modelCenter);
|
|
94
95
|
|
|
95
96
|
this.modelHelpers.push(helper);
|
|
96
97
|
this.viewer.helpers.add(helper);
|
|
@@ -48,16 +48,14 @@ class GridHelperComponent implements IComponent {
|
|
|
48
48
|
syncHelper = () => {
|
|
49
49
|
this.gridHelper.removeFromParent();
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const size = this.viewer.extents.getSize(new Vector3()).multiply(this.viewer.camera.up).length();
|
|
54
|
-
const center = this.viewer.extents.getCenter(new Vector3());
|
|
51
|
+
const extentsSizeUp = this.viewer.extents.getSize(new Vector3()).multiply(this.viewer.camera.up).length() || 1;
|
|
52
|
+
const extentsCenter = this.viewer.extents.getCenter(new Vector3());
|
|
55
53
|
|
|
56
54
|
const upY = new Vector3(0, 1, 0);
|
|
57
55
|
const up = new Vector3().copy(this.viewer.camera.up);
|
|
58
56
|
|
|
59
|
-
this.gridHelper.scale.setScalar(
|
|
60
|
-
this.gridHelper.position.copy(
|
|
57
|
+
this.gridHelper.scale.setScalar(extentsSizeUp);
|
|
58
|
+
this.gridHelper.position.copy(extentsCenter);
|
|
61
59
|
this.gridHelper.quaternion.setFromUnitVectors(upY, up);
|
|
62
60
|
|
|
63
61
|
this.viewer.helpers.add(this.gridHelper);
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { DirectionalLightHelper, HemisphereLightHelper, PointLightHelper,
|
|
24
|
+
import { DirectionalLightHelper, HemisphereLightHelper, PointLightHelper, Vector3 } from "three";
|
|
25
25
|
import { IComponent, components, Viewer } from "@inweb/viewer-three";
|
|
26
26
|
|
|
27
27
|
class LightHelperComponent implements IComponent {
|
|
@@ -53,15 +53,15 @@ class LightHelperComponent implements IComponent {
|
|
|
53
53
|
});
|
|
54
54
|
this.lightHelpers.length = 0;
|
|
55
55
|
|
|
56
|
-
const extentsSize = this.viewer.extents.
|
|
57
|
-
const
|
|
56
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
57
|
+
const helperSize = extentsSize / 20;
|
|
58
58
|
|
|
59
59
|
this.viewer.scene.traverse((object: any) => {
|
|
60
60
|
let helper: DirectionalLightHelper | HemisphereLightHelper | PointLightHelper;
|
|
61
61
|
|
|
62
|
-
if (object.isDirectionalLight) helper = new DirectionalLightHelper(object,
|
|
63
|
-
else if (object.isHemisphereLight) helper = new HemisphereLightHelper(object,
|
|
64
|
-
else if (object.isPointLight) helper = new PointLightHelper(object,
|
|
62
|
+
if (object.isDirectionalLight) helper = new DirectionalLightHelper(object, helperSize, "#aa0000");
|
|
63
|
+
else if (object.isHemisphereLight) helper = new HemisphereLightHelper(object, helperSize, "#ff9800");
|
|
64
|
+
else if (object.isPointLight) helper = new PointLightHelper(object, helperSize, "#ff9800");
|
|
65
65
|
|
|
66
66
|
if (helper) {
|
|
67
67
|
this.lightHelpers.push(helper);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "27.1.
|
|
3
|
+
"version": "27.1.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",
|
|
@@ -35,17 +35,19 @@
|
|
|
35
35
|
"docs": "typedoc"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@inweb/client": "~27.1.
|
|
39
|
-
"@inweb/eventemitter2": "~27.1.
|
|
40
|
-
"@inweb/markup": "~27.1.
|
|
41
|
-
"@inweb/viewer-core": "~27.1.
|
|
38
|
+
"@inweb/client": "~27.1.2",
|
|
39
|
+
"@inweb/eventemitter2": "~27.1.2",
|
|
40
|
+
"@inweb/markup": "~27.1.2",
|
|
41
|
+
"@inweb/viewer-core": "~27.1.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
+
"@streamparser/json": "^0.0.22",
|
|
44
45
|
"@types/three": "^0.180.0",
|
|
45
46
|
"potree-core": "^2.0.11",
|
|
46
47
|
"three": "^0.180.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
50
|
+
"@streamparser/json": "^0.0.22",
|
|
49
51
|
"@types/three": "^0.180.0",
|
|
50
52
|
"three": "^0.180.0"
|
|
51
53
|
}
|
package/src/Viewer/Viewer.ts
CHANGED
|
@@ -31,7 +31,6 @@ import {
|
|
|
31
31
|
Plane,
|
|
32
32
|
Raycaster,
|
|
33
33
|
Scene,
|
|
34
|
-
Sphere,
|
|
35
34
|
Vector2,
|
|
36
35
|
Vector3,
|
|
37
36
|
WebGLRenderer,
|
|
@@ -458,15 +457,14 @@ export class Viewer
|
|
|
458
457
|
if (model && typeof model.database === "string") {
|
|
459
458
|
file = model.file;
|
|
460
459
|
}
|
|
461
|
-
if (!model) throw new Error(`Format not supported`);
|
|
462
460
|
|
|
463
461
|
let format = params.format;
|
|
464
|
-
if (!format && typeof file["type"] === "string") format = file["type"].split(".").pop();
|
|
462
|
+
if (!format && file && typeof file["type"] === "string") format = file["type"].split(".").pop();
|
|
465
463
|
if (!format && typeof file === "string") format = file.split(".").pop();
|
|
466
464
|
if (!format && file instanceof globalThis.File) format = file.name.split(".").pop();
|
|
467
465
|
|
|
468
466
|
const loader: ILoader = loaders.createLoader(this, model, format);
|
|
469
|
-
if (!loader) throw new Error(`Format not supported`);
|
|
467
|
+
if (!loader) throw new Error(`Format not supported (${format})`);
|
|
470
468
|
this.loaders.push(loader);
|
|
471
469
|
|
|
472
470
|
this.emitEvent({ type: "geometrystart", file, model });
|
|
@@ -534,7 +532,6 @@ export class Viewer
|
|
|
534
532
|
this.helpers.clear();
|
|
535
533
|
|
|
536
534
|
this.extents.makeEmpty();
|
|
537
|
-
this.target.set(0, 0, 0);
|
|
538
535
|
|
|
539
536
|
this.syncOptions();
|
|
540
537
|
this.syncOverlay();
|
|
@@ -675,7 +672,7 @@ export class Viewer
|
|
|
675
672
|
|
|
676
673
|
const setOrthogonalCamera = (orthogonal_camera: IOrthogonalCamera) => {
|
|
677
674
|
if (orthogonal_camera) {
|
|
678
|
-
const extentsSize = this.extents.
|
|
675
|
+
const extentsSize = this.extents.getSize(new Vector3()).length() || 1;
|
|
679
676
|
const rendererSize = this.renderer.getSize(new Vector2());
|
|
680
677
|
const aspectRatio = rendererSize.x / rendererSize.y;
|
|
681
678
|
|
|
@@ -706,7 +703,7 @@ export class Viewer
|
|
|
706
703
|
|
|
707
704
|
const setPerspectiveCamera = (perspective_camera: IPerspectiveCamera) => {
|
|
708
705
|
if (perspective_camera) {
|
|
709
|
-
const extentsSize = this.extents.
|
|
706
|
+
const extentsSize = this.extents.getSize(new Vector3()).length() || 1;
|
|
710
707
|
const rendererSize = this.renderer.getSize(new Vector2());
|
|
711
708
|
const aspectRatio = rendererSize.x / rendererSize.y;
|
|
712
709
|
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Quaternion,
|
|
24
|
+
import { Quaternion, Vector3 } from "three";
|
|
25
25
|
import type { Viewer } from "../Viewer";
|
|
26
26
|
import { zoomTo } from "./ZoomTo";
|
|
27
27
|
|
|
@@ -38,9 +38,9 @@ export const defaultViewPositions = {
|
|
|
38
38
|
nw: new Vector3(1, 1, 1).normalize(),
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export function setDefaultViewPosition(viewer: Viewer, position
|
|
41
|
+
export function setDefaultViewPosition(viewer: Viewer, position = "sw"): void {
|
|
42
42
|
const extentsCenter = viewer.extents.getCenter(new Vector3());
|
|
43
|
-
const extentsSize = viewer.extents.
|
|
43
|
+
const extentsSize = viewer.extents.getSize(new Vector3()).length() || 1;
|
|
44
44
|
|
|
45
45
|
const upY = new Vector3(0, 1, 0);
|
|
46
46
|
const offsetY = defaultViewPositions[position] || defaultViewPositions["sw"];
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Box3, MathUtils,
|
|
24
|
+
import { Box3, MathUtils, Vector2, Vector3 } from "three";
|
|
25
25
|
import type { Viewer } from "../Viewer";
|
|
26
26
|
|
|
27
27
|
export function zoomTo(viewer: Viewer, box: Box3): void {
|
|
28
28
|
if (box.isEmpty()) return;
|
|
29
29
|
|
|
30
30
|
const boxCenter = box.getCenter(new Vector3());
|
|
31
|
-
const boxSize = box.
|
|
31
|
+
const boxSize = box.getSize(new Vector3()).length() || 1;
|
|
32
32
|
|
|
33
33
|
const rendererSize = viewer.renderer.getSize(new Vector2());
|
|
34
34
|
const aspectRatio = rendererSize.x / rendererSize.y;
|
|
@@ -38,14 +38,14 @@ export function zoomTo(viewer: Viewer, box: Box3): void {
|
|
|
38
38
|
if (camera.isPerspectiveCamera) {
|
|
39
39
|
const offset = new Vector3(0, 0, 1)
|
|
40
40
|
.applyQuaternion(camera.quaternion)
|
|
41
|
-
.multiplyScalar(boxSize / Math.tan(MathUtils.degToRad(camera.fov * 0.5)));
|
|
41
|
+
.multiplyScalar(boxSize / (2 * Math.tan(MathUtils.degToRad(camera.fov * 0.5))));
|
|
42
42
|
|
|
43
43
|
camera.position.copy(offset).add(boxCenter);
|
|
44
44
|
camera.updateMatrixWorld();
|
|
45
45
|
}
|
|
46
46
|
if (camera.isOrthographicCamera) {
|
|
47
|
-
camera.top = boxSize;
|
|
48
|
-
camera.bottom = -boxSize;
|
|
47
|
+
camera.top = boxSize / 2;
|
|
48
|
+
camera.bottom = -boxSize / 2;
|
|
49
49
|
camera.left = camera.bottom * aspectRatio;
|
|
50
50
|
camera.right = camera.top * aspectRatio;
|
|
51
51
|
camera.zoom = 1;
|
|
@@ -53,7 +53,7 @@ export function zoomTo(viewer: Viewer, box: Box3): void {
|
|
|
53
53
|
|
|
54
54
|
const offset = new Vector3(0, 0, 1)
|
|
55
55
|
.applyQuaternion(camera.quaternion)
|
|
56
|
-
.multiplyScalar(viewer.extents.
|
|
56
|
+
.multiplyScalar(viewer.extents.getSize(new Vector3()).length() || 1);
|
|
57
57
|
|
|
58
58
|
camera.position.copy(offset).add(boxCenter);
|
|
59
59
|
camera.updateMatrixWorld();
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { MathUtils, OrthographicCamera, PerspectiveCamera,
|
|
24
|
+
import { MathUtils, OrthographicCamera, PerspectiveCamera, Vector2, Vector3 } from "three";
|
|
25
25
|
|
|
26
26
|
import { CameraMode, IComponent } from "@inweb/viewer-core";
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
@@ -47,7 +47,7 @@ export class CameraComponent implements IComponent {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
switchCamera(camera: any) {
|
|
50
|
-
const extentsSize = this.viewer.extents.
|
|
50
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
51
51
|
const rendererSize = this.viewer.renderer.getSize(new Vector2());
|
|
52
52
|
const aspectRatio = rendererSize.x / rendererSize.y;
|
|
53
53
|
|
|
@@ -95,7 +95,7 @@ export class CameraComponent implements IComponent {
|
|
|
95
95
|
if (currentCamera.isPerspectiveCamera) {
|
|
96
96
|
const fov = currentCamera.fov;
|
|
97
97
|
const distance = currentCamera.position.distanceTo(target);
|
|
98
|
-
const fieldHeight = 2 * Math.tan(MathUtils.degToRad(fov
|
|
98
|
+
const fieldHeight = 2 * Math.tan(MathUtils.degToRad(fov * 0.5)) * distance;
|
|
99
99
|
|
|
100
100
|
camera = new OrthographicCamera();
|
|
101
101
|
camera.top = fieldHeight / 2;
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { AmbientLight, DirectionalLight, HemisphereLight, Quaternion,
|
|
24
|
+
import { AmbientLight, DirectionalLight, HemisphereLight, Quaternion, Vector3 } from "three";
|
|
25
25
|
|
|
26
26
|
import { IComponent } from "@inweb/viewer-core";
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
@@ -71,7 +71,7 @@ export class LightComponent implements IComponent {
|
|
|
71
71
|
if (this.viewer.extents.isEmpty()) return;
|
|
72
72
|
|
|
73
73
|
const extentsCenter = this.viewer.extents.getCenter(new Vector3());
|
|
74
|
-
const extentsSize = this.viewer.extents.
|
|
74
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
75
75
|
|
|
76
76
|
const upY = new Vector3(0, 1, 0);
|
|
77
77
|
const frontY = new Vector3(0, 0, -1);
|
|
@@ -83,19 +83,16 @@ export class LightComponent implements IComponent {
|
|
|
83
83
|
this.directionalLight.position
|
|
84
84
|
.copy(up)
|
|
85
85
|
.applyAxisAngle(front, (-Math.PI * 30) / 180)
|
|
86
|
-
.multiplyScalar(extentsSize
|
|
86
|
+
.multiplyScalar(extentsSize)
|
|
87
87
|
.add(extentsCenter);
|
|
88
88
|
this.directionalLight.target.position.copy(extentsCenter);
|
|
89
89
|
|
|
90
|
-
this.frontLight.position
|
|
91
|
-
.copy(front)
|
|
92
|
-
.multiplyScalar(extentsSize * 2)
|
|
93
|
-
.add(extentsCenter);
|
|
90
|
+
this.frontLight.position.copy(front).multiplyScalar(extentsSize).add(extentsCenter);
|
|
94
91
|
this.frontLight.target.position.copy(extentsCenter);
|
|
95
92
|
|
|
96
93
|
this.hemisphereLight.position
|
|
97
94
|
.copy(front)
|
|
98
|
-
.multiplyScalar(extentsSize *
|
|
95
|
+
.multiplyScalar(extentsSize * 1.5)
|
|
99
96
|
.add(extentsCenter);
|
|
100
97
|
|
|
101
98
|
this.viewer.scene.add(this.ambientLight);
|
|
@@ -63,8 +63,10 @@ export class SelectionComponent implements IComponent {
|
|
|
63
63
|
const upPosition = this.getMousePosition(event, new Vector2());
|
|
64
64
|
if (upPosition.distanceTo(this.downPosition) !== 0) return;
|
|
65
65
|
|
|
66
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
67
|
+
|
|
66
68
|
const snapper = new Snapper(this.viewer.camera, this.viewer.renderer, this.viewer.canvas);
|
|
67
|
-
snapper.threshold =
|
|
69
|
+
snapper.threshold = extentsSize / 10000;
|
|
68
70
|
|
|
69
71
|
let intersections = [];
|
|
70
72
|
this.viewer.models.forEach((model) => {
|
|
@@ -37,20 +37,20 @@ export class CuttingPlaneDragger extends OrbitDragger {
|
|
|
37
37
|
constructor(viewer: Viewer, normal: Vector3, color: number) {
|
|
38
38
|
super(viewer);
|
|
39
39
|
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const constant = -
|
|
40
|
+
const extentsSize = viewer.extents.getSize(new Vector3()).length() || 1;
|
|
41
|
+
const extentsCenter = viewer.extents.getCenter(new Vector3());
|
|
42
|
+
const constant = -extentsCenter.dot(normal);
|
|
43
43
|
|
|
44
44
|
this.plane = new Plane(normal, constant);
|
|
45
45
|
|
|
46
46
|
if (!viewer.renderer.clippingPlanes) viewer.renderer.clippingPlanes = [];
|
|
47
47
|
viewer.renderer.clippingPlanes.push(this.plane);
|
|
48
48
|
|
|
49
|
-
this.planeHelper = new PlaneHelper(this.plane,
|
|
49
|
+
this.planeHelper = new PlaneHelper(this.plane, extentsSize, color, extentsCenter);
|
|
50
50
|
this.viewer.helpers.add(this.planeHelper);
|
|
51
51
|
|
|
52
52
|
this.planeCenter = new Object3D();
|
|
53
|
-
this.planeCenter.position.copy(
|
|
53
|
+
this.planeCenter.position.copy(extentsCenter);
|
|
54
54
|
this.viewer.helpers.add(this.planeCenter);
|
|
55
55
|
|
|
56
56
|
this.transform = new TransformControls(viewer.camera, viewer.canvas);
|
|
@@ -104,7 +104,7 @@ export class CuttingPlaneDragger extends OrbitDragger {
|
|
|
104
104
|
};
|
|
105
105
|
|
|
106
106
|
updatePlaneSize = () => {
|
|
107
|
-
this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length();
|
|
107
|
+
this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
108
108
|
this.viewer.update();
|
|
109
109
|
};
|
|
110
110
|
|
|
@@ -66,7 +66,7 @@ export class FlyDragger implements IDragger {
|
|
|
66
66
|
|
|
67
67
|
updateControls = () => {
|
|
68
68
|
const size = this.viewer.extents.getSize(new Vector3());
|
|
69
|
-
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
|
|
69
|
+
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2 || 1;
|
|
70
70
|
this.joyStickControls.movementSpeed = this.controls.movementSpeed;
|
|
71
71
|
this.joyStickControls.multiplier = this.controls.multiplier;
|
|
72
72
|
};
|
|
@@ -49,8 +49,10 @@ export class MeasureLineDragger extends OrbitDragger {
|
|
|
49
49
|
this.line = new MeasureLine(this.overlay, this.scale, this.units, this.precision);
|
|
50
50
|
this.overlay.addLine(this.line);
|
|
51
51
|
|
|
52
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
53
|
+
|
|
52
54
|
this.snapper = new Snapper(viewer.camera, viewer.renderer, viewer.canvas);
|
|
53
|
-
this.snapper.threshold =
|
|
55
|
+
this.snapper.threshold = extentsSize / 10000;
|
|
54
56
|
|
|
55
57
|
this.objects = [];
|
|
56
58
|
this.updateObjects();
|
|
@@ -170,7 +172,10 @@ export class MeasureLineDragger extends OrbitDragger {
|
|
|
170
172
|
const units = this.viewer.options.rulerUnit ?? "Default";
|
|
171
173
|
const precision = this.viewer.options.rulerPrecision ?? "Default";
|
|
172
174
|
|
|
173
|
-
if (
|
|
175
|
+
if (!model) {
|
|
176
|
+
this.scale = 1;
|
|
177
|
+
this.units = "";
|
|
178
|
+
} else if (units === "Default") {
|
|
174
179
|
this.scale = model.getUnitScale();
|
|
175
180
|
this.units = model.getUnitString();
|
|
176
181
|
} else {
|
|
@@ -178,11 +183,9 @@ export class MeasureLineDragger extends OrbitDragger {
|
|
|
178
183
|
this.units = units;
|
|
179
184
|
}
|
|
180
185
|
|
|
181
|
-
if (precision
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
this.precision = precision;
|
|
185
|
-
}
|
|
186
|
+
if (!model) this.precision = 2;
|
|
187
|
+
else if (precision === "Default") this.precision = model.getPrecision();
|
|
188
|
+
else this.precision = precision;
|
|
186
189
|
|
|
187
190
|
this.overlay.updateLineUnits(this.scale, this.units, this.precision);
|
|
188
191
|
};
|
|
@@ -74,7 +74,7 @@ export class WalkDragger implements IDragger {
|
|
|
74
74
|
|
|
75
75
|
updateControls = () => {
|
|
76
76
|
const size = this.viewer.extents.getSize(new Vector3());
|
|
77
|
-
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
|
|
77
|
+
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2 || 1;
|
|
78
78
|
this.joyStickControls.movementSpeed = this.controls.movementSpeed;
|
|
79
79
|
this.joyStickControls.multiplier = this.controls.multiplier;
|
|
80
80
|
};
|
|
@@ -64,7 +64,13 @@ export class GltfStructure {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
async initialize(loader) {
|
|
67
|
-
|
|
67
|
+
const json = await this.loadController.loadJson();
|
|
68
|
+
|
|
69
|
+
if (json.asset === undefined || json.asset.version[0] < 2) {
|
|
70
|
+
throw new Error("GltfStructure: Unsupported asset. glTF versions >=2.0 are supported.");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.json = json;
|
|
68
74
|
this.loader = loader;
|
|
69
75
|
this.uri = this.json.buffers[0].uri || "";
|
|
70
76
|
}
|
|
@@ -31,61 +31,66 @@
|
|
|
31
31
|
|
|
32
32
|
const BINARY_EXTENSION_HEADER_MAGIC = "glTF";
|
|
33
33
|
const BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
34
|
-
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN:
|
|
34
|
+
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN: 0x004e4942 };
|
|
35
35
|
|
|
36
|
-
export
|
|
37
|
-
|
|
36
|
+
export interface GLTFBinaryHeader {
|
|
37
|
+
magic: string;
|
|
38
|
+
version: number;
|
|
39
|
+
length: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class GLTFBinaryParser {
|
|
43
|
+
public header: GLTFBinaryHeader;
|
|
44
|
+
public content: Uint8Array;
|
|
38
45
|
public body: ArrayBuffer;
|
|
39
46
|
|
|
40
47
|
constructor(data: ArrayBuffer) {
|
|
41
|
-
const
|
|
42
|
-
const textDecoder = new TextDecoder();
|
|
48
|
+
const dataView = new DataView(data, 0);
|
|
43
49
|
|
|
44
|
-
const
|
|
50
|
+
const textDecoder = new TextDecoder();
|
|
51
|
+
const magic = textDecoder.decode(new Uint8Array(data, 0, Math.min(4, data.byteLength)));
|
|
45
52
|
|
|
46
53
|
if (magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
|
47
|
-
this.content =
|
|
54
|
+
this.content = new Uint8Array(data);
|
|
48
55
|
return;
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
|
|
58
|
+
this.header = {
|
|
52
59
|
magic,
|
|
53
|
-
version:
|
|
54
|
-
length:
|
|
60
|
+
version: dataView.getUint32(4, true),
|
|
61
|
+
length: dataView.getUint32(8, true),
|
|
55
62
|
};
|
|
56
63
|
|
|
57
|
-
if (header.
|
|
58
|
-
throw new Error("
|
|
64
|
+
if (this.header.length !== data.byteLength) {
|
|
65
|
+
throw new Error("GLTFBinaryParser: Invalid binary file header.");
|
|
59
66
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error("Legacy binary file detected.");
|
|
67
|
+
if (this.header.version < 2.0) {
|
|
68
|
+
throw new Error("GLTFBinaryParser: Legacy binary file detected.");
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
|
|
67
|
-
let chunkIndex = 0;
|
|
71
|
+
let offset = BINARY_EXTENSION_HEADER_LENGTH;
|
|
68
72
|
|
|
69
|
-
while (
|
|
70
|
-
const chunkLength =
|
|
71
|
-
|
|
73
|
+
while (offset < this.header.length) {
|
|
74
|
+
const chunkLength = dataView.getUint32(offset, true);
|
|
75
|
+
offset += 4;
|
|
72
76
|
|
|
73
|
-
const chunkType =
|
|
74
|
-
|
|
77
|
+
const chunkType = dataView.getUint32(offset, true);
|
|
78
|
+
offset += 4;
|
|
75
79
|
|
|
76
80
|
if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
|
|
77
|
-
|
|
78
|
-
this.content = textDecoder.decode(contentArray);
|
|
81
|
+
this.content = new Uint8Array(data, offset, chunkLength);
|
|
79
82
|
} else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
|
|
80
|
-
|
|
81
|
-
this.body = data.slice(byteOffset, byteOffset + chunkLength);
|
|
83
|
+
this.body = data.slice(offset, offset + chunkLength);
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
offset += chunkLength;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
if (typeof this.content === "undefined") {
|
|
88
|
-
throw new Error("JSON content not found.");
|
|
90
|
+
throw new Error("GLTFBinaryParser: JSON content not found.");
|
|
91
|
+
}
|
|
92
|
+
if (typeof this.body === "undefined") {
|
|
93
|
+
throw new Error("GLTFBinaryParser: Binary buffer chunk not found or type not supported.");
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
}
|
|
@@ -28,6 +28,7 @@ import { Viewer } from "../Viewer";
|
|
|
28
28
|
import { DynamicModelImpl } from "./DynamicGltfLoader/DynamicModelImpl";
|
|
29
29
|
import { DynamicGltfLoader } from "./DynamicGltfLoader/DynamicGltfLoader.js";
|
|
30
30
|
import { GltfStructure } from "./DynamicGltfLoader/GltfStructure.js";
|
|
31
|
+
import { JSONStreamParser } from "./JSONStreamParser";
|
|
31
32
|
|
|
32
33
|
export class GLTFCloudDynamicLoader extends Loader {
|
|
33
34
|
public viewer: Viewer;
|
|
@@ -86,20 +87,20 @@ export class GLTFCloudDynamicLoader extends Loader {
|
|
|
86
87
|
|
|
87
88
|
const loadController = {
|
|
88
89
|
loadJson: async () => {
|
|
89
|
-
const
|
|
90
|
+
const jsonParser = new JSONStreamParser();
|
|
91
|
+
|
|
92
|
+
const progress = (progress: number, chunk: Uint8Array) => {
|
|
93
|
+
jsonParser.write(chunk);
|
|
90
94
|
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
|
|
91
95
|
};
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
model.database,
|
|
95
|
-
progress,
|
|
96
|
-
this.gltfLoader.getAbortController().signal
|
|
97
|
-
);
|
|
97
|
+
await model.downloadResource(model.database, progress, this.gltfLoader.getAbortController().signal);
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
if (!jsonParser.json) {
|
|
100
|
+
throw new Error("GLTFCloudDynamicLoader: JSON content not found or invalid.");
|
|
101
|
+
}
|
|
101
102
|
|
|
102
|
-
return json;
|
|
103
|
+
return jsonParser.json;
|
|
103
104
|
},
|
|
104
105
|
|
|
105
106
|
loadBinaryData: (requests) => {
|