@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
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
|
|
24
24
|
import { draggersRegistry, commandsRegistry, Options, componentsRegistry, Info, Loader, loadersRegistry, CANVAS_EVENTS } from '@inweb/viewer-core';
|
|
25
25
|
export * from '@inweb/viewer-core';
|
|
26
|
-
import { Line, Vector3, BufferGeometry, Float32BufferAttribute, LineBasicMaterial, Mesh, MeshBasicMaterial, DoubleSide, EventDispatcher, MOUSE, TOUCH, Spherical, Quaternion, Vector2, Plane, Object3D, Line3, Raycaster, MathUtils, EdgesGeometry, Matrix4, Vector4, Controls, Clock,
|
|
26
|
+
import { Line, Vector3, BufferGeometry, Float32BufferAttribute, LineBasicMaterial, Mesh, MeshBasicMaterial, DoubleSide, EventDispatcher, MOUSE, TOUCH, Spherical, Quaternion, Vector2, Plane, Object3D, Line3, Raycaster, MathUtils, EdgesGeometry, Matrix4, Vector4, Controls, Clock, Box3, Color, PerspectiveCamera, OrthographicCamera, AmbientLight, DirectionalLight, HemisphereLight, REVISION, MeshPhongMaterial, WebGLRenderTarget, UnsignedByteType, RGBAFormat, CylinderGeometry, Sprite, CanvasTexture, SRGBColorSpace, SpriteMaterial, TextureLoader, BufferAttribute, PointsMaterial, Points, TriangleStripDrawMode, TriangleFanDrawMode, LineSegments, LineLoop, Group, NormalBlending, LoadingManager, LoaderUtils, FileLoader, UniformsUtils, ShaderMaterial, AdditiveBlending, HalfFloatType, Scene, WebGLRenderer, LinearSRGBColorSpace } from 'three';
|
|
27
27
|
import { TransformControls } from 'three/examples/jsm/controls/TransformControls.js';
|
|
28
28
|
import { LineSegmentsGeometry } from 'three/examples/jsm/lines/LineSegmentsGeometry.js';
|
|
29
29
|
import { Wireframe } from 'three/examples/jsm/lines/Wireframe.js';
|
|
30
30
|
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial.js';
|
|
31
31
|
import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
32
|
+
import { JSONParser } from '@streamparser/json';
|
|
32
33
|
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
|
|
33
34
|
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
|
|
34
35
|
import { FXAAPass } from 'three/examples/jsm/postprocessing/FXAAPass.js';
|
|
@@ -841,7 +842,7 @@ class CuttingPlaneDragger extends OrbitDragger {
|
|
|
841
842
|
this.orbit.enabled = !event.value;
|
|
842
843
|
};
|
|
843
844
|
this.updatePlaneSize = () => {
|
|
844
|
-
this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length();
|
|
845
|
+
this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
845
846
|
this.viewer.update();
|
|
846
847
|
};
|
|
847
848
|
this.updateTransformCamera = () => {
|
|
@@ -852,17 +853,17 @@ class CuttingPlaneDragger extends OrbitDragger {
|
|
|
852
853
|
this.plane.negate();
|
|
853
854
|
this.viewer.update();
|
|
854
855
|
};
|
|
855
|
-
const
|
|
856
|
-
const
|
|
857
|
-
const constant = -
|
|
856
|
+
const extentsSize = viewer.extents.getSize(new Vector3()).length() || 1;
|
|
857
|
+
const extentsCenter = viewer.extents.getCenter(new Vector3());
|
|
858
|
+
const constant = -extentsCenter.dot(normal);
|
|
858
859
|
this.plane = new Plane(normal, constant);
|
|
859
860
|
if (!viewer.renderer.clippingPlanes)
|
|
860
861
|
viewer.renderer.clippingPlanes = [];
|
|
861
862
|
viewer.renderer.clippingPlanes.push(this.plane);
|
|
862
|
-
this.planeHelper = new PlaneHelper(this.plane,
|
|
863
|
+
this.planeHelper = new PlaneHelper(this.plane, extentsSize, color, extentsCenter);
|
|
863
864
|
this.viewer.helpers.add(this.planeHelper);
|
|
864
865
|
this.planeCenter = new Object3D();
|
|
865
|
-
this.planeCenter.position.copy(
|
|
866
|
+
this.planeCenter.position.copy(extentsCenter);
|
|
866
867
|
this.viewer.helpers.add(this.planeCenter);
|
|
867
868
|
this.transform = new TransformControls(viewer.camera, viewer.canvas);
|
|
868
869
|
this.transform.showX = !!normal.x;
|
|
@@ -1173,7 +1174,11 @@ class MeasureLineDragger extends OrbitDragger {
|
|
|
1173
1174
|
const model = this.viewer.models[0];
|
|
1174
1175
|
const units = (_a = this.viewer.options.rulerUnit) !== null && _a !== void 0 ? _a : "Default";
|
|
1175
1176
|
const precision = (_b = this.viewer.options.rulerPrecision) !== null && _b !== void 0 ? _b : "Default";
|
|
1176
|
-
if (
|
|
1177
|
+
if (!model) {
|
|
1178
|
+
this.scale = 1;
|
|
1179
|
+
this.units = "";
|
|
1180
|
+
}
|
|
1181
|
+
else if (units === "Default") {
|
|
1177
1182
|
this.scale = model.getUnitScale();
|
|
1178
1183
|
this.units = model.getUnitString();
|
|
1179
1184
|
}
|
|
@@ -1181,20 +1186,21 @@ class MeasureLineDragger extends OrbitDragger {
|
|
|
1181
1186
|
this.scale = convertUnits(model.getUnits(), units, 1);
|
|
1182
1187
|
this.units = units;
|
|
1183
1188
|
}
|
|
1184
|
-
if (
|
|
1189
|
+
if (!model)
|
|
1190
|
+
this.precision = 2;
|
|
1191
|
+
else if (precision === "Default")
|
|
1185
1192
|
this.precision = model.getPrecision();
|
|
1186
|
-
|
|
1187
|
-
else {
|
|
1193
|
+
else
|
|
1188
1194
|
this.precision = precision;
|
|
1189
|
-
}
|
|
1190
1195
|
this.overlay.updateLineUnits(this.scale, this.units, this.precision);
|
|
1191
1196
|
};
|
|
1192
1197
|
this.overlay = new MeasureOverlay(viewer.camera, viewer.canvas);
|
|
1193
1198
|
this.overlay.attach();
|
|
1194
1199
|
this.line = new MeasureLine(this.overlay, this.scale, this.units, this.precision);
|
|
1195
1200
|
this.overlay.addLine(this.line);
|
|
1201
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
1196
1202
|
this.snapper = new Snapper(viewer.camera, viewer.renderer, viewer.canvas);
|
|
1197
|
-
this.snapper.threshold =
|
|
1203
|
+
this.snapper.threshold = extentsSize / 10000;
|
|
1198
1204
|
this.objects = [];
|
|
1199
1205
|
this.updateObjects();
|
|
1200
1206
|
this.updateUnits();
|
|
@@ -1893,7 +1899,7 @@ class WalkDragger {
|
|
|
1893
1899
|
constructor(viewer) {
|
|
1894
1900
|
this.updateControls = () => {
|
|
1895
1901
|
const size = this.viewer.extents.getSize(new Vector3());
|
|
1896
|
-
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
|
|
1902
|
+
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2 || 1;
|
|
1897
1903
|
this.joyStickControls.movementSpeed = this.controls.movementSpeed;
|
|
1898
1904
|
this.joyStickControls.multiplier = this.controls.multiplier;
|
|
1899
1905
|
};
|
|
@@ -2099,7 +2105,7 @@ class FlyDragger {
|
|
|
2099
2105
|
constructor(viewer) {
|
|
2100
2106
|
this.updateControls = () => {
|
|
2101
2107
|
const size = this.viewer.extents.getSize(new Vector3());
|
|
2102
|
-
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
|
|
2108
|
+
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2 || 1;
|
|
2103
2109
|
this.joyStickControls.movementSpeed = this.controls.movementSpeed;
|
|
2104
2110
|
this.joyStickControls.multiplier = this.controls.multiplier;
|
|
2105
2111
|
};
|
|
@@ -2204,27 +2210,27 @@ function zoomTo(viewer, box) {
|
|
|
2204
2210
|
if (box.isEmpty())
|
|
2205
2211
|
return;
|
|
2206
2212
|
const boxCenter = box.getCenter(new Vector3());
|
|
2207
|
-
const boxSize = box.
|
|
2213
|
+
const boxSize = box.getSize(new Vector3()).length() || 1;
|
|
2208
2214
|
const rendererSize = viewer.renderer.getSize(new Vector2());
|
|
2209
2215
|
const aspectRatio = rendererSize.x / rendererSize.y;
|
|
2210
2216
|
const camera = viewer.camera;
|
|
2211
2217
|
if (camera.isPerspectiveCamera) {
|
|
2212
2218
|
const offset = new Vector3(0, 0, 1)
|
|
2213
2219
|
.applyQuaternion(camera.quaternion)
|
|
2214
|
-
.multiplyScalar(boxSize / Math.tan(MathUtils.degToRad(camera.fov * 0.5)));
|
|
2220
|
+
.multiplyScalar(boxSize / (2 * Math.tan(MathUtils.degToRad(camera.fov * 0.5))));
|
|
2215
2221
|
camera.position.copy(offset).add(boxCenter);
|
|
2216
2222
|
camera.updateMatrixWorld();
|
|
2217
2223
|
}
|
|
2218
2224
|
if (camera.isOrthographicCamera) {
|
|
2219
|
-
camera.top = boxSize;
|
|
2220
|
-
camera.bottom = -boxSize;
|
|
2225
|
+
camera.top = boxSize / 2;
|
|
2226
|
+
camera.bottom = -boxSize / 2;
|
|
2221
2227
|
camera.left = camera.bottom * aspectRatio;
|
|
2222
2228
|
camera.right = camera.top * aspectRatio;
|
|
2223
2229
|
camera.zoom = 1;
|
|
2224
2230
|
camera.updateProjectionMatrix();
|
|
2225
2231
|
const offset = new Vector3(0, 0, 1)
|
|
2226
2232
|
.applyQuaternion(camera.quaternion)
|
|
2227
|
-
.multiplyScalar(viewer.extents.
|
|
2233
|
+
.multiplyScalar(viewer.extents.getSize(new Vector3()).length() || 1);
|
|
2228
2234
|
camera.position.copy(offset).add(boxCenter);
|
|
2229
2235
|
camera.updateMatrixWorld();
|
|
2230
2236
|
}
|
|
@@ -2245,9 +2251,9 @@ const defaultViewPositions = {
|
|
|
2245
2251
|
ne: new Vector3(-1, 1, 1).normalize(),
|
|
2246
2252
|
nw: new Vector3(1, 1, 1).normalize(),
|
|
2247
2253
|
};
|
|
2248
|
-
function setDefaultViewPosition(viewer, position) {
|
|
2254
|
+
function setDefaultViewPosition(viewer, position = "sw") {
|
|
2249
2255
|
const extentsCenter = viewer.extents.getCenter(new Vector3());
|
|
2250
|
-
const extentsSize = viewer.extents.
|
|
2256
|
+
const extentsSize = viewer.extents.getSize(new Vector3()).length() || 1;
|
|
2251
2257
|
const upY = new Vector3(0, 1, 0);
|
|
2252
2258
|
const offsetY = defaultViewPositions[position] || defaultViewPositions["sw"];
|
|
2253
2259
|
const up = new Vector3().copy(viewer.camera.up);
|
|
@@ -2504,7 +2510,7 @@ class CameraComponent {
|
|
|
2504
2510
|
return camera.isOrthographicCamera ? "orthographic" : "perspective";
|
|
2505
2511
|
}
|
|
2506
2512
|
switchCamera(camera) {
|
|
2507
|
-
const extentsSize = this.viewer.extents.
|
|
2513
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
2508
2514
|
const rendererSize = this.viewer.renderer.getSize(new Vector2());
|
|
2509
2515
|
const aspectRatio = rendererSize.x / rendererSize.y;
|
|
2510
2516
|
if (camera.isPerspectiveCamera) {
|
|
@@ -2544,7 +2550,7 @@ class CameraComponent {
|
|
|
2544
2550
|
if (currentCamera.isPerspectiveCamera) {
|
|
2545
2551
|
const fov = currentCamera.fov;
|
|
2546
2552
|
const distance = currentCamera.position.distanceTo(target);
|
|
2547
|
-
const fieldHeight = 2 * Math.tan(MathUtils.degToRad(fov
|
|
2553
|
+
const fieldHeight = 2 * Math.tan(MathUtils.degToRad(fov * 0.5)) * distance;
|
|
2548
2554
|
camera = new OrthographicCamera();
|
|
2549
2555
|
camera.top = fieldHeight / 2;
|
|
2550
2556
|
camera.bottom = -fieldHeight / 2;
|
|
@@ -2602,7 +2608,7 @@ class LightComponent {
|
|
|
2602
2608
|
if (this.viewer.extents.isEmpty())
|
|
2603
2609
|
return;
|
|
2604
2610
|
const extentsCenter = this.viewer.extents.getCenter(new Vector3());
|
|
2605
|
-
const extentsSize = this.viewer.extents.
|
|
2611
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
2606
2612
|
const upY = new Vector3(0, 1, 0);
|
|
2607
2613
|
const frontY = new Vector3(0, 0, -1);
|
|
2608
2614
|
const up = new Vector3().copy(this.viewer.camera.up);
|
|
@@ -2611,17 +2617,14 @@ class LightComponent {
|
|
|
2611
2617
|
this.directionalLight.position
|
|
2612
2618
|
.copy(up)
|
|
2613
2619
|
.applyAxisAngle(front, (-Math.PI * 30) / 180)
|
|
2614
|
-
.multiplyScalar(extentsSize
|
|
2620
|
+
.multiplyScalar(extentsSize)
|
|
2615
2621
|
.add(extentsCenter);
|
|
2616
2622
|
this.directionalLight.target.position.copy(extentsCenter);
|
|
2617
|
-
this.frontLight.position
|
|
2618
|
-
.copy(front)
|
|
2619
|
-
.multiplyScalar(extentsSize * 2)
|
|
2620
|
-
.add(extentsCenter);
|
|
2623
|
+
this.frontLight.position.copy(front).multiplyScalar(extentsSize).add(extentsCenter);
|
|
2621
2624
|
this.frontLight.target.position.copy(extentsCenter);
|
|
2622
2625
|
this.hemisphereLight.position
|
|
2623
2626
|
.copy(front)
|
|
2624
|
-
.multiplyScalar(extentsSize *
|
|
2627
|
+
.multiplyScalar(extentsSize * 1.5)
|
|
2625
2628
|
.add(extentsCenter);
|
|
2626
2629
|
this.viewer.scene.add(this.ambientLight);
|
|
2627
2630
|
this.viewer.scene.add(this.directionalLight);
|
|
@@ -3027,8 +3030,9 @@ class SelectionComponent {
|
|
|
3027
3030
|
const upPosition = this.getMousePosition(event, new Vector2());
|
|
3028
3031
|
if (upPosition.distanceTo(this.downPosition) !== 0)
|
|
3029
3032
|
return;
|
|
3033
|
+
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
3030
3034
|
const snapper = new Snapper(this.viewer.camera, this.viewer.renderer, this.viewer.canvas);
|
|
3031
|
-
snapper.threshold =
|
|
3035
|
+
snapper.threshold = extentsSize / 10000;
|
|
3032
3036
|
let intersections = [];
|
|
3033
3037
|
this.viewer.models.forEach((model) => {
|
|
3034
3038
|
const objects = model.getVisibleObjects();
|
|
@@ -3797,7 +3801,11 @@ class GltfStructure {
|
|
|
3797
3801
|
this.criticalError = null;
|
|
3798
3802
|
}
|
|
3799
3803
|
async initialize(loader) {
|
|
3800
|
-
|
|
3804
|
+
const json = await this.loadController.loadJson();
|
|
3805
|
+
if (json.asset === undefined || json.asset.version[0] < 2) {
|
|
3806
|
+
throw new Error("GltfStructure: Unsupported asset. glTF versions >=2.0 are supported.");
|
|
3807
|
+
}
|
|
3808
|
+
this.json = json;
|
|
3801
3809
|
this.loader = loader;
|
|
3802
3810
|
this.uri = this.json.buffers[0].uri || "";
|
|
3803
3811
|
}
|
|
@@ -6293,48 +6301,59 @@ class GLTFLoadingManager extends LoadingManager {
|
|
|
6293
6301
|
|
|
6294
6302
|
const BINARY_EXTENSION_HEADER_MAGIC = "glTF";
|
|
6295
6303
|
const BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
6296
|
-
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN:
|
|
6297
|
-
class
|
|
6304
|
+
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN: 0x004e4942 };
|
|
6305
|
+
class GLTFBinaryParser {
|
|
6298
6306
|
constructor(data) {
|
|
6299
|
-
const
|
|
6307
|
+
const dataView = new DataView(data, 0);
|
|
6300
6308
|
const textDecoder = new TextDecoder();
|
|
6301
|
-
const magic = textDecoder.decode(new Uint8Array(data.
|
|
6309
|
+
const magic = textDecoder.decode(new Uint8Array(data, 0, Math.min(4, data.byteLength)));
|
|
6302
6310
|
if (magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
|
6303
|
-
this.content =
|
|
6311
|
+
this.content = new Uint8Array(data);
|
|
6304
6312
|
return;
|
|
6305
6313
|
}
|
|
6306
|
-
|
|
6314
|
+
this.header = {
|
|
6307
6315
|
magic,
|
|
6308
|
-
version:
|
|
6309
|
-
length:
|
|
6316
|
+
version: dataView.getUint32(4, true),
|
|
6317
|
+
length: dataView.getUint32(8, true),
|
|
6310
6318
|
};
|
|
6311
|
-
if (header.
|
|
6312
|
-
throw new Error("
|
|
6313
|
-
}
|
|
6314
|
-
if (header.version < 2.0) {
|
|
6315
|
-
throw new Error("Legacy binary file detected.");
|
|
6316
|
-
}
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
const
|
|
6322
|
-
|
|
6323
|
-
const chunkType = chunkView.getUint32(chunkIndex, true);
|
|
6324
|
-
chunkIndex += 4;
|
|
6319
|
+
if (this.header.length !== data.byteLength) {
|
|
6320
|
+
throw new Error("GLTFBinaryParser: Invalid binary file header.");
|
|
6321
|
+
}
|
|
6322
|
+
if (this.header.version < 2.0) {
|
|
6323
|
+
throw new Error("GLTFBinaryParser: Legacy binary file detected.");
|
|
6324
|
+
}
|
|
6325
|
+
let offset = BINARY_EXTENSION_HEADER_LENGTH;
|
|
6326
|
+
while (offset < this.header.length) {
|
|
6327
|
+
const chunkLength = dataView.getUint32(offset, true);
|
|
6328
|
+
offset += 4;
|
|
6329
|
+
const chunkType = dataView.getUint32(offset, true);
|
|
6330
|
+
offset += 4;
|
|
6325
6331
|
if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
|
|
6326
|
-
|
|
6327
|
-
this.content = textDecoder.decode(contentArray);
|
|
6332
|
+
this.content = new Uint8Array(data, offset, chunkLength);
|
|
6328
6333
|
}
|
|
6329
6334
|
else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
|
|
6330
|
-
|
|
6331
|
-
this.body = data.slice(byteOffset, byteOffset + chunkLength);
|
|
6335
|
+
this.body = data.slice(offset, offset + chunkLength);
|
|
6332
6336
|
}
|
|
6333
|
-
|
|
6337
|
+
offset += chunkLength;
|
|
6334
6338
|
}
|
|
6335
6339
|
if (typeof this.content === "undefined") {
|
|
6336
|
-
throw new Error("JSON content not found.");
|
|
6340
|
+
throw new Error("GLTFBinaryParser: JSON content not found.");
|
|
6337
6341
|
}
|
|
6342
|
+
if (typeof this.body === "undefined") {
|
|
6343
|
+
throw new Error("GLTFBinaryParser: Binary buffer chunk not found or type not supported.");
|
|
6344
|
+
}
|
|
6345
|
+
}
|
|
6346
|
+
}
|
|
6347
|
+
|
|
6348
|
+
class JSONStreamParser extends JSONParser {
|
|
6349
|
+
constructor(data) {
|
|
6350
|
+
super();
|
|
6351
|
+
this.onValue = ({ value, stack }) => {
|
|
6352
|
+
if (stack.length === 0)
|
|
6353
|
+
this.json = value;
|
|
6354
|
+
};
|
|
6355
|
+
if (data)
|
|
6356
|
+
this.write(data);
|
|
6338
6357
|
}
|
|
6339
6358
|
}
|
|
6340
6359
|
|
|
@@ -6443,13 +6462,13 @@ class GLTFFileDynamicLoader extends Loader {
|
|
|
6443
6462
|
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
|
|
6444
6463
|
};
|
|
6445
6464
|
const data = await loader.loadAsync(this.manager.fileURL, progress);
|
|
6446
|
-
const
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
throw new Error("GLTFFileDynamicLoader: Binary buffer chunk not found or type not supported.");
|
|
6465
|
+
const binaryParser = new GLTFBinaryParser(data);
|
|
6466
|
+
const jsonParser = new JSONStreamParser(binaryParser.content);
|
|
6467
|
+
if (!jsonParser.json) {
|
|
6468
|
+
throw new Error("GLTFFileDynamicLoader: JSON content not found or invalid.");
|
|
6451
6469
|
}
|
|
6452
|
-
|
|
6470
|
+
this.glb = binaryParser.body;
|
|
6471
|
+
return jsonParser.json;
|
|
6453
6472
|
},
|
|
6454
6473
|
loadBinaryData: (ranges, uri = "") => {
|
|
6455
6474
|
const loader = new RangesLoader();
|
|
@@ -6520,13 +6539,16 @@ class GLTFCloudDynamicLoader extends Loader {
|
|
|
6520
6539
|
});
|
|
6521
6540
|
const loadController = {
|
|
6522
6541
|
loadJson: async () => {
|
|
6523
|
-
const
|
|
6542
|
+
const jsonParser = new JSONStreamParser();
|
|
6543
|
+
const progress = (progress, chunk) => {
|
|
6544
|
+
jsonParser.write(chunk);
|
|
6524
6545
|
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
|
|
6525
6546
|
};
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6547
|
+
await model.downloadResource(model.database, progress, this.gltfLoader.getAbortController().signal);
|
|
6548
|
+
if (!jsonParser.json) {
|
|
6549
|
+
throw new Error("GLTFCloudDynamicLoader: JSON content not found or invalid.");
|
|
6550
|
+
}
|
|
6551
|
+
return jsonParser.json;
|
|
6530
6552
|
},
|
|
6531
6553
|
loadBinaryData: (requests) => {
|
|
6532
6554
|
const ranges = requests.map((request) => ({
|
|
@@ -6963,10 +6985,8 @@ class Viewer extends EventEmitter2 {
|
|
|
6963
6985
|
if (model && typeof model.database === "string") {
|
|
6964
6986
|
file = model.file;
|
|
6965
6987
|
}
|
|
6966
|
-
if (!model)
|
|
6967
|
-
throw new Error(`Format not supported`);
|
|
6968
6988
|
let format = params.format;
|
|
6969
|
-
if (!format && typeof file["type"] === "string")
|
|
6989
|
+
if (!format && file && typeof file["type"] === "string")
|
|
6970
6990
|
format = file["type"].split(".").pop();
|
|
6971
6991
|
if (!format && typeof file === "string")
|
|
6972
6992
|
format = file.split(".").pop();
|
|
@@ -6974,7 +6994,7 @@ class Viewer extends EventEmitter2 {
|
|
|
6974
6994
|
format = file.name.split(".").pop();
|
|
6975
6995
|
const loader = loaders.createLoader(this, model, format);
|
|
6976
6996
|
if (!loader)
|
|
6977
|
-
throw new Error(`Format not supported`);
|
|
6997
|
+
throw new Error(`Format not supported (${format})`);
|
|
6978
6998
|
this.loaders.push(loader);
|
|
6979
6999
|
this.emitEvent({ type: "geometrystart", file, model });
|
|
6980
7000
|
try {
|
|
@@ -7016,7 +7036,6 @@ class Viewer extends EventEmitter2 {
|
|
|
7016
7036
|
this.scene.clear();
|
|
7017
7037
|
this.helpers.clear();
|
|
7018
7038
|
this.extents.makeEmpty();
|
|
7019
|
-
this.target.set(0, 0, 0);
|
|
7020
7039
|
this.syncOptions();
|
|
7021
7040
|
this.syncOverlay();
|
|
7022
7041
|
this.emitEvent({ type: "clear" });
|
|
@@ -7132,7 +7151,7 @@ class Viewer extends EventEmitter2 {
|
|
|
7132
7151
|
const getVector3FromPoint3d = ({ x, y, z }) => new Vector3(x, y, z);
|
|
7133
7152
|
const setOrthogonalCamera = (orthogonal_camera) => {
|
|
7134
7153
|
if (orthogonal_camera) {
|
|
7135
|
-
const extentsSize = this.extents.
|
|
7154
|
+
const extentsSize = this.extents.getSize(new Vector3()).length() || 1;
|
|
7136
7155
|
const rendererSize = this.renderer.getSize(new Vector2());
|
|
7137
7156
|
const aspectRatio = rendererSize.x / rendererSize.y;
|
|
7138
7157
|
const camera = new OrthographicCamera();
|
|
@@ -7158,7 +7177,7 @@ class Viewer extends EventEmitter2 {
|
|
|
7158
7177
|
};
|
|
7159
7178
|
const setPerspectiveCamera = (perspective_camera) => {
|
|
7160
7179
|
if (perspective_camera) {
|
|
7161
|
-
const extentsSize = this.extents.
|
|
7180
|
+
const extentsSize = this.extents.getSize(new Vector3()).length() || 1;
|
|
7162
7181
|
const rendererSize = this.renderer.getSize(new Vector2());
|
|
7163
7182
|
const aspectRatio = rendererSize.x / rendererSize.y;
|
|
7164
7183
|
const camera = new PerspectiveCamera();
|