@inweb/viewer-three 27.1.1 → 27.1.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.
Files changed (51) hide show
  1. package/dist/extensions/components/AxesHelperComponent.js +12 -11
  2. package/dist/extensions/components/AxesHelperComponent.js.map +1 -1
  3. package/dist/extensions/components/AxesHelperComponent.min.js +1 -1
  4. package/dist/extensions/components/AxesHelperComponent.module.js +12 -11
  5. package/dist/extensions/components/AxesHelperComponent.module.js.map +1 -1
  6. package/dist/extensions/components/GridHelperComponent.js +4 -6
  7. package/dist/extensions/components/GridHelperComponent.js.map +1 -1
  8. package/dist/extensions/components/GridHelperComponent.min.js +1 -1
  9. package/dist/extensions/components/GridHelperComponent.module.js +4 -6
  10. package/dist/extensions/components/GridHelperComponent.module.js.map +1 -1
  11. package/dist/extensions/components/LightHelperComponent.js +5 -5
  12. package/dist/extensions/components/LightHelperComponent.js.map +1 -1
  13. package/dist/extensions/components/LightHelperComponent.min.js +1 -1
  14. package/dist/extensions/components/LightHelperComponent.module.js +6 -6
  15. package/dist/extensions/components/LightHelperComponent.module.js.map +1 -1
  16. package/dist/extensions/components/RoomEnvironmentComponent.js +1 -0
  17. package/dist/extensions/components/RoomEnvironmentComponent.js.map +1 -1
  18. package/dist/extensions/components/RoomEnvironmentComponent.min.js +1 -1
  19. package/dist/extensions/loaders/GLTFCloudLoader.js.map +1 -1
  20. package/dist/extensions/loaders/GLTFFileLoader.js.map +1 -1
  21. package/dist/extensions/loaders/IFCXLoader.js.map +1 -1
  22. package/dist/viewer-three.js +2630 -751
  23. package/dist/viewer-three.js.map +1 -1
  24. package/dist/viewer-three.min.js +4 -4
  25. package/dist/viewer-three.module.js +143 -89
  26. package/dist/viewer-three.module.js.map +1 -1
  27. package/extensions/components/AxesHelperComponent.ts +13 -12
  28. package/extensions/components/GridHelperComponent.ts +4 -6
  29. package/extensions/components/LightHelperComponent.ts +6 -6
  30. package/lib/Viewer/commands/SetDefaultViewPosition.d.ts +1 -1
  31. package/lib/Viewer/loaders/GLTFBinaryParser.d.ts +11 -0
  32. package/lib/Viewer/loaders/GLTFFileDynamicLoader.d.ts +0 -1
  33. package/lib/Viewer/loaders/JSONStreamParser.d.ts +5 -0
  34. package/package.json +11 -9
  35. package/src/Viewer/Viewer.ts +4 -7
  36. package/src/Viewer/commands/SetDefaultViewPosition.ts +3 -3
  37. package/src/Viewer/commands/ZoomTo.ts +6 -6
  38. package/src/Viewer/components/CameraComponent.ts +3 -3
  39. package/src/Viewer/components/LightComponent.ts +5 -8
  40. package/src/Viewer/components/SelectionComponent.ts +3 -1
  41. package/src/Viewer/draggers/CuttingPlaneDragger.ts +6 -6
  42. package/src/Viewer/draggers/FlyDragger.ts +1 -1
  43. package/src/Viewer/draggers/MeasureLineDragger.ts +10 -7
  44. package/src/Viewer/draggers/WalkDragger.ts +1 -1
  45. package/src/Viewer/loaders/DynamicGltfLoader/DynamicGltfLoader.js +63 -10
  46. package/src/Viewer/loaders/DynamicGltfLoader/GltfStructure.js +7 -1
  47. package/src/Viewer/loaders/{GLTFBinaryExtension.ts → GLTFBinaryParser.ts} +34 -29
  48. package/src/Viewer/loaders/GLTFCloudDynamicLoader.ts +10 -9
  49. package/src/Viewer/loaders/GLTFFileDynamicLoader.ts +9 -8
  50. package/src/Viewer/loaders/JSONStreamParser.ts +38 -0
  51. package/lib/Viewer/loaders/GLTFBinaryExtension.d.ts +0 -5
@@ -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: 0x004e4042 };
34
+ const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN: 0x004e4942 };
35
35
 
36
- export class GLTFBinaryExtension {
37
- public content: string;
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 headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
42
- const textDecoder = new TextDecoder();
48
+ const dataView = new DataView(data, 0);
43
49
 
44
- const magic = textDecoder.decode(new Uint8Array(data.slice(0, 4)));
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 = textDecoder.decode(data);
54
+ this.content = new Uint8Array(data);
48
55
  return;
49
56
  }
50
57
 
51
- const header = {
58
+ this.header = {
52
59
  magic,
53
- version: headerView.getUint32(4, true),
54
- length: headerView.getUint32(8, true),
60
+ version: dataView.getUint32(4, true),
61
+ length: dataView.getUint32(8, true),
55
62
  };
56
63
 
57
- if (header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
58
- throw new Error("Unsupported glTF-Binary header.");
64
+ if (this.header.length !== data.byteLength) {
65
+ throw new Error("GLTFBinaryParser: Invalid binary file header.");
59
66
  }
60
-
61
- if (header.version < 2.0) {
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
- const chunkContentsLength = header.length - BINARY_EXTENSION_HEADER_LENGTH;
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 (chunkIndex < chunkContentsLength) {
70
- const chunkLength = chunkView.getUint32(chunkIndex, true);
71
- chunkIndex += 4;
73
+ while (offset < this.header.length) {
74
+ const chunkLength = dataView.getUint32(offset, true);
75
+ offset += 4;
72
76
 
73
- const chunkType = chunkView.getUint32(chunkIndex, true);
74
- chunkIndex += 4;
77
+ const chunkType = dataView.getUint32(offset, true);
78
+ offset += 4;
75
79
 
76
80
  if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
77
- const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
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
- const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
81
- this.body = data.slice(byteOffset, byteOffset + chunkLength);
83
+ this.body = data.slice(offset, offset + chunkLength);
82
84
  }
83
85
 
84
- chunkIndex += chunkLength;
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 progress = (progress: number) => {
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
- const arrayBuffer = await model.downloadResource(
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
- const text = new TextDecoder().decode(arrayBuffer);
100
- const json = JSON.parse(text);
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) => {
@@ -29,14 +29,14 @@ import { DynamicModelImpl } from "./DynamicGltfLoader/DynamicModelImpl";
29
29
  import { DynamicGltfLoader } from "./DynamicGltfLoader/DynamicGltfLoader.js";
30
30
  import { GltfStructure } from "./DynamicGltfLoader/GltfStructure.js";
31
31
  import { GLTFLoadingManager, GLTFLoadParams } from "./GLTFLoadingManager";
32
- import { GLTFBinaryExtension } from "./GLTFBinaryExtension";
32
+ import { GLTFBinaryParser } from "./GLTFBinaryParser";
33
+ import { JSONStreamParser } from "./JSONStreamParser";
33
34
  import { RangesLoader } from "./RangesLoader";
34
35
 
35
36
  export class GLTFFileDynamicLoader extends Loader {
36
37
  public viewer: Viewer;
37
38
  private gltfLoader: DynamicGltfLoader;
38
39
  private manager: GLTFLoadingManager;
39
- private gltf: any;
40
40
  private glb: ArrayBuffer;
41
41
 
42
42
  constructor(viewer: Viewer) {
@@ -104,15 +104,16 @@ export class GLTFFileDynamicLoader extends Loader {
104
104
 
105
105
  const data = await loader.loadAsync(this.manager.fileURL, progress);
106
106
 
107
- const extension = new GLTFBinaryExtension(data as ArrayBuffer);
108
- this.gltf = JSON.parse(extension.content);
109
- this.glb = extension.body;
107
+ const binaryParser = new GLTFBinaryParser(data as ArrayBuffer);
108
+ const jsonParser = new JSONStreamParser(binaryParser.content);
110
109
 
111
- if (/\.glb$/i.test(this.manager.fileURL) && !this.glb) {
112
- throw new Error("GLTFFileDynamicLoader: Binary buffer chunk not found or type not supported.");
110
+ if (!jsonParser.json) {
111
+ throw new Error("GLTFFileDynamicLoader: JSON content not found or invalid.");
113
112
  }
114
113
 
115
- return this.gltf;
114
+ this.glb = binaryParser.body;
115
+
116
+ return jsonParser.json;
116
117
  },
117
118
 
118
119
  loadBinaryData: (ranges, uri = "") => {
@@ -0,0 +1,38 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2025, 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-2025 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 { JSONParser } from "@streamparser/json";
25
+
26
+ export class JSONStreamParser extends JSONParser {
27
+ public json: any;
28
+
29
+ constructor(data?: Uint8Array) {
30
+ super();
31
+
32
+ this.onValue = ({ value, stack }) => {
33
+ if (stack.length === 0) this.json = value;
34
+ };
35
+
36
+ if (data) this.write(data);
37
+ }
38
+ }
@@ -1,5 +0,0 @@
1
- export declare class GLTFBinaryExtension {
2
- content: string;
3
- body: ArrayBuffer;
4
- constructor(data: ArrayBuffer);
5
- }