@inweb/viewer-three 26.12.0 → 26.12.3
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 +156 -78
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +2 -2
- package/dist/viewer-three.module.js +37 -18
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/loaders/GLTFFileDynamicLoader.d.ts +1 -1
- package/package.json +5 -5
- package/src/Viewer/Viewer.ts +34 -5
- package/src/Viewer/loaders/DynamicGltfLoader/GltfStructure.js +2 -9
- package/src/Viewer/loaders/GLTFCloudDynamicLoader.ts +6 -2
- package/src/Viewer/loaders/GLTFFileDynamicLoader.ts +10 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "26.12.
|
|
3
|
+
"version": "26.12.3",
|
|
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,10 +35,10 @@
|
|
|
35
35
|
"docs": "typedoc"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@inweb/client": "~26.12.
|
|
39
|
-
"@inweb/eventemitter2": "~26.12.
|
|
40
|
-
"@inweb/markup": "~26.12.
|
|
41
|
-
"@inweb/viewer-core": "~26.12.
|
|
38
|
+
"@inweb/client": "~26.12.3",
|
|
39
|
+
"@inweb/eventemitter2": "~26.12.3",
|
|
40
|
+
"@inweb/markup": "~26.12.3",
|
|
41
|
+
"@inweb/viewer-core": "~26.12.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/three": "^0.180.0",
|
package/src/Viewer/Viewer.ts
CHANGED
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
import {
|
|
25
25
|
Box3,
|
|
26
26
|
LinearSRGBColorSpace,
|
|
27
|
-
// LinearToneMapping,
|
|
28
27
|
Object3D,
|
|
29
28
|
OrthographicCamera,
|
|
30
29
|
PerspectiveCamera,
|
|
31
30
|
Plane,
|
|
31
|
+
Raycaster,
|
|
32
32
|
Scene,
|
|
33
33
|
Sphere,
|
|
34
34
|
Vector2,
|
|
@@ -832,7 +832,11 @@ export class Viewer
|
|
|
832
832
|
}
|
|
833
833
|
|
|
834
834
|
// IWorldTransform
|
|
835
|
-
|
|
835
|
+
// ===================== AI-CODE-START ======================
|
|
836
|
+
// Source: Claude Sonnet 4.5
|
|
837
|
+
// Date: 2025-11-25
|
|
838
|
+
// Reviewer: vitaly.ivanov@opendesign.com
|
|
839
|
+
// Issue: CLOUD-5990
|
|
836
840
|
screenToWorld(position: { x: number; y: number }): { x: number; y: number; z: number } {
|
|
837
841
|
if (!this.renderer) return { x: position.x, y: position.y, z: 0 };
|
|
838
842
|
|
|
@@ -840,11 +844,36 @@ export class Viewer
|
|
|
840
844
|
const x = position.x / (rect.width / 2) - 1;
|
|
841
845
|
const y = -position.y / (rect.height / 2) + 1;
|
|
842
846
|
|
|
843
|
-
|
|
844
|
-
|
|
847
|
+
if (this.camera["isPerspectiveCamera"]) {
|
|
848
|
+
// Create a raycaster from the screen position
|
|
849
|
+
const raycaster = new Raycaster();
|
|
850
|
+
const mouse = new Vector2(x, y);
|
|
851
|
+
raycaster.setFromCamera(mouse, this.camera);
|
|
852
|
+
|
|
853
|
+
// Create a plane perpendicular to the camera direction at the target point
|
|
854
|
+
const cameraDirection = new Vector3();
|
|
855
|
+
this.camera.getWorldDirection(cameraDirection);
|
|
856
|
+
const targetPlane = new Plane().setFromNormalAndCoplanarPoint(cameraDirection, this.target);
|
|
857
|
+
|
|
858
|
+
// Intersect the ray with the target plane
|
|
859
|
+
const intersectionPoint = new Vector3();
|
|
860
|
+
raycaster.ray.intersectPlane(targetPlane, intersectionPoint);
|
|
861
|
+
|
|
862
|
+
// If intersection fails (ray parallel to plane), fallback to near plane unprojection
|
|
863
|
+
if (!intersectionPoint) {
|
|
864
|
+
const point = new Vector3(x, y, -1);
|
|
865
|
+
point.unproject(this.camera);
|
|
866
|
+
return { x: point.x, y: point.y, z: point.z };
|
|
867
|
+
}
|
|
868
|
+
return { x: intersectionPoint.x, y: intersectionPoint.y, z: intersectionPoint.z };
|
|
869
|
+
} else {
|
|
870
|
+
const point = new Vector3(x, y, -1);
|
|
871
|
+
point.unproject(this.camera);
|
|
845
872
|
|
|
846
|
-
|
|
873
|
+
return { x: point.x, y: point.y, z: point.z };
|
|
874
|
+
}
|
|
847
875
|
}
|
|
876
|
+
// ===================== AI-CODE-END ======================
|
|
848
877
|
|
|
849
878
|
worldToScreen(position: { x: number; y: number; z: number }): { x: number; y: number } {
|
|
850
879
|
if (!this.renderer) return { x: position.x, y: position.y };
|
|
@@ -46,7 +46,6 @@ export class GltfStructure {
|
|
|
46
46
|
constructor(id, loadController) {
|
|
47
47
|
this.id = `${id}`;
|
|
48
48
|
this.json = null;
|
|
49
|
-
this.baseUrl = "";
|
|
50
49
|
this.loadController = loadController;
|
|
51
50
|
this.loader = null;
|
|
52
51
|
this.batchDelay = 10;
|
|
@@ -66,14 +65,12 @@ export class GltfStructure {
|
|
|
66
65
|
|
|
67
66
|
async initialize(loader) {
|
|
68
67
|
this.json = await this.loadController.loadJson();
|
|
69
|
-
this.baseUrl = await this.loadController.baseUrl();
|
|
70
68
|
this.loader = loader;
|
|
71
69
|
this.uri = this.json.buffers[0].uri || "";
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
clear() {
|
|
75
73
|
this.json = null;
|
|
76
|
-
this.baseUrl = "";
|
|
77
74
|
this.loadController = null;
|
|
78
75
|
this.pendingRequests = [];
|
|
79
76
|
if (this.batchTimeout) {
|
|
@@ -397,12 +394,8 @@ export class GltfStructure {
|
|
|
397
394
|
const image = this.json.images[imageIndex];
|
|
398
395
|
|
|
399
396
|
if (image.uri) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
} else {
|
|
403
|
-
const fullUrl = this.baseUrl + image.uri;
|
|
404
|
-
return await this.textureLoader.loadAsync(fullUrl);
|
|
405
|
-
}
|
|
397
|
+
const fullUrl = await this.loadController.resolveURL(image.uri);
|
|
398
|
+
return this.textureLoader.loadAsync(fullUrl);
|
|
406
399
|
} else if (image.bufferView !== undefined) {
|
|
407
400
|
const bufferView = this.json.bufferViews[image.bufferView];
|
|
408
401
|
const array = await this.getBufferView(bufferView.byteOffset || 0, bufferView.byteLength, 5121);
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Group } from "three";
|
|
24
|
+
import { Group, LoaderUtils } from "three";
|
|
25
25
|
import { Loader, LoadParams } from "@inweb/viewer-core";
|
|
26
26
|
|
|
27
27
|
import { Viewer } from "../Viewer";
|
|
@@ -118,7 +118,11 @@ export class GLTFCloudDynamicLoader extends Loader {
|
|
|
118
118
|
);
|
|
119
119
|
},
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
resolveURL: (uri) => {
|
|
122
|
+
const path = `${model.httpClient.serverUrl}${model.path}/`;
|
|
123
|
+
const url = LoaderUtils.resolveURL(uri, path);
|
|
124
|
+
return Promise.resolve(url);
|
|
125
|
+
},
|
|
122
126
|
};
|
|
123
127
|
|
|
124
128
|
const structure = new GltfStructure(modelImpl.id, loadController);
|
|
@@ -37,7 +37,7 @@ export class GLTFFileDynamicLoader extends Loader {
|
|
|
37
37
|
private gltfLoader: DynamicGltfLoader;
|
|
38
38
|
private manager: GLTFLoadingManager;
|
|
39
39
|
private gltf: any;
|
|
40
|
-
private
|
|
40
|
+
private glb: ArrayBuffer;
|
|
41
41
|
|
|
42
42
|
constructor(viewer: Viewer) {
|
|
43
43
|
super();
|
|
@@ -106,7 +106,11 @@ export class GLTFFileDynamicLoader extends Loader {
|
|
|
106
106
|
|
|
107
107
|
const extension = new GLTFBinaryExtension(data as ArrayBuffer);
|
|
108
108
|
this.gltf = JSON.parse(extension.content);
|
|
109
|
-
this.
|
|
109
|
+
this.glb = extension.body;
|
|
110
|
+
|
|
111
|
+
if (/\.glb$/i.test(this.manager.fileURL) && !this.glb) {
|
|
112
|
+
throw new Error("GLTFFileDynamicLoader: Binary buffer chunk not found or type not supported.");
|
|
113
|
+
}
|
|
110
114
|
|
|
111
115
|
return this.gltf;
|
|
112
116
|
},
|
|
@@ -117,7 +121,7 @@ export class GLTFFileDynamicLoader extends Loader {
|
|
|
117
121
|
loader.setWithCredentials(params.withCredentials || false);
|
|
118
122
|
loader.setAbortSignal(this.gltfLoader.abortController.signal);
|
|
119
123
|
|
|
120
|
-
if (this.
|
|
124
|
+
if (this.glb) return loader.extractRanges(this.glb, ranges);
|
|
121
125
|
|
|
122
126
|
const path = this.manager.path || this.manager.resourcePath;
|
|
123
127
|
const url = LoaderUtils.resolveURL(uri, path);
|
|
@@ -125,9 +129,10 @@ export class GLTFFileDynamicLoader extends Loader {
|
|
|
125
129
|
return loader.load(this.manager.resolveURL(url), ranges);
|
|
126
130
|
},
|
|
127
131
|
|
|
128
|
-
|
|
132
|
+
resolveURL: (uri) => {
|
|
129
133
|
const path = this.manager.path || this.manager.resourcePath;
|
|
130
|
-
|
|
134
|
+
const url = LoaderUtils.resolveURL(uri, path);
|
|
135
|
+
return Promise.resolve(this.manager.resolveURL(url));
|
|
131
136
|
},
|
|
132
137
|
};
|
|
133
138
|
|