@inweb/viewer-three 26.12.2 → 26.12.4

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.
@@ -6,7 +6,7 @@ export declare class GLTFFileDynamicLoader extends Loader {
6
6
  private gltfLoader;
7
7
  private manager;
8
8
  private gltf;
9
- private bin;
9
+ private glb;
10
10
  constructor(viewer: Viewer);
11
11
  dispose(): void;
12
12
  isSupport(file: any, format?: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-three",
3
- "version": "26.12.2",
3
+ "version": "26.12.4",
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.2",
39
- "@inweb/eventemitter2": "~26.12.2",
40
- "@inweb/markup": "~26.12.2",
41
- "@inweb/viewer-core": "~26.12.2"
38
+ "@inweb/client": "~26.12.4",
39
+ "@inweb/eventemitter2": "~26.12.4",
40
+ "@inweb/markup": "~26.12.4",
41
+ "@inweb/viewer-core": "~26.12.4"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/three": "^0.180.0",
@@ -311,7 +311,7 @@ export class DynamicGltfLoader {
311
311
  const uniqueTextureIds = new Set();
312
312
  if (Array.isArray(this.structures)) {
313
313
  for (const structure of this.structures) {
314
- console.log(structure.materialCache.values());
314
+ // console.log(structure.materialCache.values());
315
315
  try {
316
316
  for (const entry of structure.materialCache.values()) {
317
317
  if (entry?.mesh?.uuid) uniqueMaterialIds.add(entry.mesh.uuid);
@@ -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
- if (image.uri.startsWith("data:")) {
401
- return await this.textureLoader.loadAsync(image.uri);
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
- baseUrl: () => Promise.resolve(`${model.httpClient.serverUrl}${model.path}/`),
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 bin: ArrayBuffer;
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.bin = extension.body;
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.bin) return loader.extractRanges(this.bin, ranges);
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
- baseUrl: () => {
132
+ resolveURL: (uri) => {
129
133
  const path = this.manager.path || this.manager.resourcePath;
130
- return Promise.resolve(path);
134
+ const url = LoaderUtils.resolveURL(uri, path);
135
+ return Promise.resolve(this.manager.resolveURL(url));
131
136
  },
132
137
  };
133
138