@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
|
@@ -3672,7 +3672,6 @@ class GltfStructure {
|
|
|
3672
3672
|
constructor(id, loadController) {
|
|
3673
3673
|
this.id = `${id}`;
|
|
3674
3674
|
this.json = null;
|
|
3675
|
-
this.baseUrl = "";
|
|
3676
3675
|
this.loadController = loadController;
|
|
3677
3676
|
this.loader = null;
|
|
3678
3677
|
this.batchDelay = 10;
|
|
@@ -3691,13 +3690,11 @@ class GltfStructure {
|
|
|
3691
3690
|
}
|
|
3692
3691
|
async initialize(loader) {
|
|
3693
3692
|
this.json = await this.loadController.loadJson();
|
|
3694
|
-
this.baseUrl = await this.loadController.baseUrl();
|
|
3695
3693
|
this.loader = loader;
|
|
3696
3694
|
this.uri = this.json.buffers[0].uri || "";
|
|
3697
3695
|
}
|
|
3698
3696
|
clear() {
|
|
3699
3697
|
this.json = null;
|
|
3700
|
-
this.baseUrl = "";
|
|
3701
3698
|
this.loadController = null;
|
|
3702
3699
|
this.pendingRequests = [];
|
|
3703
3700
|
if (this.batchTimeout) {
|
|
@@ -3978,12 +3975,8 @@ class GltfStructure {
|
|
|
3978
3975
|
const loadTexture = async (imageIndex) => {
|
|
3979
3976
|
const image = this.json.images[imageIndex];
|
|
3980
3977
|
if (image.uri) {
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
} else {
|
|
3984
|
-
const fullUrl = this.baseUrl + image.uri;
|
|
3985
|
-
return await this.textureLoader.loadAsync(fullUrl);
|
|
3986
|
-
}
|
|
3978
|
+
const fullUrl = await this.loadController.resolveURL(image.uri);
|
|
3979
|
+
return this.textureLoader.loadAsync(fullUrl);
|
|
3987
3980
|
} else if (image.bufferView !== undefined) {
|
|
3988
3981
|
const bufferView = this.json.bufferViews[image.bufferView];
|
|
3989
3982
|
const array = await this.getBufferView(bufferView.byteOffset || 0, bufferView.byteLength, 5121);
|
|
@@ -6154,7 +6147,10 @@ class GLTFFileDynamicLoader extends Loader {
|
|
|
6154
6147
|
const data = await loader.loadAsync(this.manager.fileURL, progress);
|
|
6155
6148
|
const extension = new GLTFBinaryExtension(data);
|
|
6156
6149
|
this.gltf = JSON.parse(extension.content);
|
|
6157
|
-
this.
|
|
6150
|
+
this.glb = extension.body;
|
|
6151
|
+
if (/\.glb$/i.test(this.manager.fileURL) && !this.glb) {
|
|
6152
|
+
throw new Error("GLTFFileDynamicLoader: Binary buffer chunk not found or type not supported.");
|
|
6153
|
+
}
|
|
6158
6154
|
return this.gltf;
|
|
6159
6155
|
},
|
|
6160
6156
|
loadBinaryData: (ranges, uri = "") => {
|
|
@@ -6162,15 +6158,16 @@ class GLTFFileDynamicLoader extends Loader {
|
|
|
6162
6158
|
loader.setRequestHeader(params.requestHeader || {});
|
|
6163
6159
|
loader.setWithCredentials(params.withCredentials || false);
|
|
6164
6160
|
loader.setAbortSignal(this.gltfLoader.abortController.signal);
|
|
6165
|
-
if (this.
|
|
6166
|
-
return loader.extractRanges(this.
|
|
6161
|
+
if (this.glb)
|
|
6162
|
+
return loader.extractRanges(this.glb, ranges);
|
|
6167
6163
|
const path = this.manager.path || this.manager.resourcePath;
|
|
6168
6164
|
const url = LoaderUtils.resolveURL(uri, path);
|
|
6169
6165
|
return loader.load(this.manager.resolveURL(url), ranges);
|
|
6170
6166
|
},
|
|
6171
|
-
|
|
6167
|
+
resolveURL: (uri) => {
|
|
6172
6168
|
const path = this.manager.path || this.manager.resourcePath;
|
|
6173
|
-
|
|
6169
|
+
const url = LoaderUtils.resolveURL(uri, path);
|
|
6170
|
+
return Promise.resolve(this.manager.resolveURL(url));
|
|
6174
6171
|
},
|
|
6175
6172
|
};
|
|
6176
6173
|
const structure = new GltfStructure(modelImpl.id, loadController);
|
|
@@ -6241,7 +6238,11 @@ class GLTFCloudDynamicLoader extends Loader {
|
|
|
6241
6238
|
}));
|
|
6242
6239
|
return model.downloadResourceRange(model.geometry[0], undefined, ranges, undefined, this.gltfLoader.getAbortController().signal);
|
|
6243
6240
|
},
|
|
6244
|
-
|
|
6241
|
+
resolveURL: (uri) => {
|
|
6242
|
+
const path = `${model.httpClient.serverUrl}${model.path}/`;
|
|
6243
|
+
const url = LoaderUtils.resolveURL(uri, path);
|
|
6244
|
+
return Promise.resolve(url);
|
|
6245
|
+
},
|
|
6245
6246
|
};
|
|
6246
6247
|
const structure = new GltfStructure(modelImpl.id, loadController);
|
|
6247
6248
|
await this.gltfLoader.loadStructure(structure);
|
|
@@ -6965,9 +6966,27 @@ class Viewer extends EventEmitter2 {
|
|
|
6965
6966
|
const rect = this.canvas.getBoundingClientRect();
|
|
6966
6967
|
const x = position.x / (rect.width / 2) - 1;
|
|
6967
6968
|
const y = -position.y / (rect.height / 2) + 1;
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6969
|
+
if (this.camera["isPerspectiveCamera"]) {
|
|
6970
|
+
const raycaster = new Raycaster();
|
|
6971
|
+
const mouse = new Vector2(x, y);
|
|
6972
|
+
raycaster.setFromCamera(mouse, this.camera);
|
|
6973
|
+
const cameraDirection = new Vector3();
|
|
6974
|
+
this.camera.getWorldDirection(cameraDirection);
|
|
6975
|
+
const targetPlane = new Plane().setFromNormalAndCoplanarPoint(cameraDirection, this.target);
|
|
6976
|
+
const intersectionPoint = new Vector3();
|
|
6977
|
+
raycaster.ray.intersectPlane(targetPlane, intersectionPoint);
|
|
6978
|
+
if (!intersectionPoint) {
|
|
6979
|
+
const point = new Vector3(x, y, -1);
|
|
6980
|
+
point.unproject(this.camera);
|
|
6981
|
+
return { x: point.x, y: point.y, z: point.z };
|
|
6982
|
+
}
|
|
6983
|
+
return { x: intersectionPoint.x, y: intersectionPoint.y, z: intersectionPoint.z };
|
|
6984
|
+
}
|
|
6985
|
+
else {
|
|
6986
|
+
const point = new Vector3(x, y, -1);
|
|
6987
|
+
point.unproject(this.camera);
|
|
6988
|
+
return { x: point.x, y: point.y, z: point.z };
|
|
6989
|
+
}
|
|
6971
6990
|
}
|
|
6972
6991
|
worldToScreen(position) {
|
|
6973
6992
|
if (!this.renderer)
|