@inweb/viewer-three 26.9.1 → 26.9.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/plugins/components/AxesHelperComponent.js +8 -6
- package/dist/plugins/components/AxesHelperComponent.js.map +1 -1
- package/dist/plugins/components/AxesHelperComponent.min.js +1 -1
- package/dist/plugins/components/AxesHelperComponent.module.js +8 -6
- package/dist/plugins/components/AxesHelperComponent.module.js.map +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.js.map +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.min.js +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.module.js +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.module.js.map +1 -1
- package/dist/plugins/components/LightHelperComponent.js.map +1 -1
- package/dist/plugins/components/LightHelperComponent.min.js +1 -1
- package/dist/plugins/components/LightHelperComponent.module.js +7 -7
- package/dist/plugins/components/LightHelperComponent.module.js.map +1 -1
- package/dist/plugins/components/RoomEnvironmentComponent.js.map +1 -1
- package/dist/plugins/components/RoomEnvironmentComponent.min.js +1 -1
- package/dist/plugins/components/RoomEnvironmentComponent.module.js +1 -1
- package/dist/plugins/components/RoomEnvironmentComponent.module.js.map +1 -1
- package/dist/plugins/components/StatsPanelComponent.js.map +1 -1
- package/dist/plugins/components/StatsPanelComponent.min.js +1 -1
- package/dist/plugins/components/StatsPanelComponent.module.js +1 -1
- package/dist/plugins/components/StatsPanelComponent.module.js.map +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.js.map +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.min.js +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.module.js +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.module.js.map +1 -1
- package/dist/plugins/loaders/IFCXLoader.js +4 -4
- package/dist/plugins/loaders/IFCXLoader.js.map +1 -1
- package/dist/plugins/loaders/IFCXLoader.min.js +1 -1
- package/dist/plugins/loaders/IFCXLoader.module.js +92 -92
- package/dist/plugins/loaders/IFCXLoader.module.js.map +1 -1
- package/dist/plugins/loaders/PotreeLoader.js +160 -0
- package/dist/plugins/loaders/PotreeLoader.js.map +1 -0
- package/dist/plugins/loaders/PotreeLoader.min.js +1 -0
- package/dist/plugins/loaders/PotreeLoader.module.js +68 -0
- package/dist/plugins/loaders/PotreeLoader.module.js.map +1 -0
- package/dist/viewer-three.js +1180 -795
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -3
- package/dist/viewer-three.module.js +608 -301
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +3 -2
- package/lib/Viewer/controls/FlyControls.d.ts +34 -0
- package/lib/Viewer/controls/WalkControls.d.ts +19 -3
- package/lib/Viewer/draggers/FlyDragger.d.ts +14 -0
- package/package.json +6 -5
- package/plugins/components/AxesHelperComponent.ts +10 -6
- package/plugins/loaders/{IFCXCloudLoader.ts → IFCX/IFCXCloudLoader.ts} +1 -1
- package/plugins/loaders/{IFCXFileLoader.ts → IFCX/IFCXFileLoader.ts} +1 -1
- package/plugins/loaders/Potree/PotreeFileLoader.ts +106 -0
- package/plugins/loaders/Potree/PotreeModelImpl.ts +36 -0
- package/plugins/loaders/Potree/index.ts +28 -0
- package/src/Viewer/Viewer.ts +34 -10
- package/src/Viewer/components/ExtentsComponent.ts +1 -1
- package/src/Viewer/components/ResizeCanvasComponent.ts +1 -18
- package/src/Viewer/controls/FlyControls.ts +205 -0
- package/src/Viewer/controls/WalkControls.ts +129 -20
- package/src/Viewer/draggers/FlyDragger.ts +73 -0
- package/src/Viewer/draggers/OrbitDragger.ts +9 -0
- package/src/Viewer/draggers/WalkDragger.ts +11 -2
- package/src/Viewer/draggers/index.ts +2 -0
- package/src/Viewer/helpers/WCSHelper.ts +3 -3
- /package/plugins/loaders/{IFCXLoader.ts → IFCX/index.ts} +0 -0
|
@@ -2,7 +2,7 @@ import { draggersRegistry, commandsRegistry, componentsRegistry, Loader, loaders
|
|
|
2
2
|
|
|
3
3
|
export * from "@inweb/viewer-core";
|
|
4
4
|
|
|
5
|
-
import { Line, Vector3, BufferGeometry, Float32BufferAttribute, LineBasicMaterial, Mesh, MeshBasicMaterial, DoubleSide, EventDispatcher, MOUSE, TOUCH, Spherical, Quaternion, Vector2, Plane, Object3D, Matrix4, Vector4, Raycaster, Controls, Clock,
|
|
5
|
+
import { Line, Vector3, BufferGeometry, Float32BufferAttribute, LineBasicMaterial, Mesh, MeshBasicMaterial, DoubleSide, EventDispatcher, MOUSE, TOUCH, Spherical, Quaternion, Vector2, Plane, Object3D, Matrix4, Vector4, Raycaster, Controls, Clock, MathUtils, Sphere, Box3, Color, AmbientLight, DirectionalLight, HemisphereLight, MeshPhongMaterial, WebGLRenderTarget, UnsignedByteType, RGBAFormat, EdgesGeometry, OrthographicCamera, CylinderGeometry, Sprite, CanvasTexture, SRGBColorSpace, SpriteMaterial, LoadingManager, LoaderUtils, TextureLoader, BufferAttribute, PointsMaterial, Points, TriangleStripDrawMode, TriangleFanDrawMode, LineSegments, LineLoop, Group, NormalBlending, PerspectiveCamera, UniformsUtils, ShaderMaterial, AdditiveBlending, HalfFloatType, Scene, WebGLRenderer, LinearSRGBColorSpace } from "three";
|
|
6
6
|
|
|
7
7
|
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
8
8
|
|
|
@@ -785,6 +785,13 @@ class OrbitDragger {
|
|
|
785
785
|
this.viewer.target.copy(this.orbit.target);
|
|
786
786
|
this.viewer.update();
|
|
787
787
|
switch (this.orbit.state) {
|
|
788
|
+
case STATE.ROTATE:
|
|
789
|
+
case STATE.TOUCH_ROTATE:
|
|
790
|
+
this.viewer.emitEvent({
|
|
791
|
+
type: "orbit"
|
|
792
|
+
});
|
|
793
|
+
break;
|
|
794
|
+
|
|
788
795
|
case STATE.PAN:
|
|
789
796
|
case STATE.TOUCH_PAN:
|
|
790
797
|
this.viewer.emitEvent({
|
|
@@ -805,6 +812,9 @@ class OrbitDragger {
|
|
|
805
812
|
});
|
|
806
813
|
break;
|
|
807
814
|
}
|
|
815
|
+
this.viewer.emitEvent({
|
|
816
|
+
type: "changecamera"
|
|
817
|
+
});
|
|
808
818
|
this.changed = true;
|
|
809
819
|
};
|
|
810
820
|
this.stopContextMenu = event => {
|
|
@@ -1039,7 +1049,7 @@ class MeasureSnapper {
|
|
|
1039
1049
|
}
|
|
1040
1050
|
update(scene) {
|
|
1041
1051
|
this.objects = [];
|
|
1042
|
-
scene.traverseVisible(
|
|
1052
|
+
scene.traverseVisible(child => this.objects.push(child));
|
|
1043
1053
|
}
|
|
1044
1054
|
}
|
|
1045
1055
|
|
|
@@ -1072,21 +1082,21 @@ class MeasureOverlay {
|
|
|
1072
1082
|
this.container = undefined;
|
|
1073
1083
|
}
|
|
1074
1084
|
clear() {
|
|
1075
|
-
this.lines.forEach(
|
|
1085
|
+
this.lines.forEach(line => line.dispose());
|
|
1076
1086
|
this.lines = [];
|
|
1077
1087
|
}
|
|
1078
1088
|
render() {
|
|
1079
1089
|
this.projector.updateProjectionMatrix();
|
|
1080
|
-
this.lines.forEach(
|
|
1090
|
+
this.lines.forEach(line => line.render());
|
|
1081
1091
|
}
|
|
1082
1092
|
update() {
|
|
1083
|
-
this.lines.forEach(
|
|
1093
|
+
this.lines.forEach(line => line.update());
|
|
1084
1094
|
}
|
|
1085
1095
|
addLine(line) {
|
|
1086
1096
|
this.lines.push(line);
|
|
1087
1097
|
}
|
|
1088
1098
|
removeLine(line) {
|
|
1089
|
-
this.lines = this.lines.filter(
|
|
1099
|
+
this.lines = this.lines.filter(x => x !== line);
|
|
1090
1100
|
}
|
|
1091
1101
|
}
|
|
1092
1102
|
|
|
@@ -1294,6 +1304,282 @@ class PanDragger extends OrbitDragger {
|
|
|
1294
1304
|
}
|
|
1295
1305
|
|
|
1296
1306
|
class WalkControls extends Controls {
|
|
1307
|
+
constructor(camera, canvas, groundObjects, viewer) {
|
|
1308
|
+
super(camera, canvas);
|
|
1309
|
+
this.EYE_HEIGHT = 1.7;
|
|
1310
|
+
this.FAILING_DISTANCE = 2;
|
|
1311
|
+
this.GROUND_FOLLOWING_SPEED = .05;
|
|
1312
|
+
this.LOOK_SPEED = .1;
|
|
1313
|
+
this.WALK_SPEED_DELIMITER = 4;
|
|
1314
|
+
this.WHEEL_SPEED_DELIMITER = 15e3;
|
|
1315
|
+
this.movementSpeed = .1;
|
|
1316
|
+
this.multiplier = 3;
|
|
1317
|
+
this.moveWheel = 0;
|
|
1318
|
+
this.mouseDragOn = false;
|
|
1319
|
+
this.onPointerDown = event => {
|
|
1320
|
+
if (event.button !== 0) return;
|
|
1321
|
+
this.domElement.setPointerCapture(event.pointerId);
|
|
1322
|
+
this.downPosition.set(event.clientX, event.clientY);
|
|
1323
|
+
this.quaternion.copy(this.object.quaternion);
|
|
1324
|
+
this.mouseDragOn = true;
|
|
1325
|
+
};
|
|
1326
|
+
this.onPointerMove = event => {
|
|
1327
|
+
if (!this.mouseDragOn) return;
|
|
1328
|
+
const movePosition = new Vector2(event.clientX, event.clientY);
|
|
1329
|
+
if (this.downPosition.distanceTo(movePosition) === 0) return;
|
|
1330
|
+
this.rotateDelta.copy(this.downPosition).sub(movePosition);
|
|
1331
|
+
this.rotateCamera(this.rotateDelta);
|
|
1332
|
+
this.dispatchEvent({
|
|
1333
|
+
type: "change"
|
|
1334
|
+
});
|
|
1335
|
+
};
|
|
1336
|
+
this.onPointerUp = event => {
|
|
1337
|
+
this.domElement.releasePointerCapture(event.pointerId);
|
|
1338
|
+
this.mouseDragOn = false;
|
|
1339
|
+
};
|
|
1340
|
+
this.onPointerCancel = event => {
|
|
1341
|
+
this.domElement.dispatchEvent(new PointerEvent("pointerup", event));
|
|
1342
|
+
};
|
|
1343
|
+
this.onWheel = event => {
|
|
1344
|
+
this.moveWheel = event.deltaY;
|
|
1345
|
+
this.update();
|
|
1346
|
+
};
|
|
1347
|
+
this.onKeyDown = event => {
|
|
1348
|
+
switch (event.code) {
|
|
1349
|
+
case "NumpadSubtract":
|
|
1350
|
+
case "Minus":
|
|
1351
|
+
if (this.multiplier > 1) {
|
|
1352
|
+
this.multiplier = this.multiplier - 1;
|
|
1353
|
+
this.dispatchEvent({
|
|
1354
|
+
type: "walkspeedchange",
|
|
1355
|
+
data: this.multiplier
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
break;
|
|
1359
|
+
|
|
1360
|
+
case "NumpadAdd":
|
|
1361
|
+
case "Equal":
|
|
1362
|
+
if (this.multiplier < 10) {
|
|
1363
|
+
this.multiplier = this.multiplier + 1;
|
|
1364
|
+
this.dispatchEvent({
|
|
1365
|
+
type: "walkspeedchange",
|
|
1366
|
+
data: this.multiplier
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
break;
|
|
1370
|
+
|
|
1371
|
+
case "ArrowLeft":
|
|
1372
|
+
case "ArrowRight":
|
|
1373
|
+
case "ArrowUp":
|
|
1374
|
+
case "ArrowDown":
|
|
1375
|
+
case "KeyW":
|
|
1376
|
+
case "KeyS":
|
|
1377
|
+
case "KeyA":
|
|
1378
|
+
case "KeyD":
|
|
1379
|
+
case "KeyQ":
|
|
1380
|
+
case "KeyE":
|
|
1381
|
+
this.moveKeys.add(event.code);
|
|
1382
|
+
this.update();
|
|
1383
|
+
break;
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
this.onKeyUp = event => {
|
|
1387
|
+
if (this.moveKeys.delete(event.code)) this.update();
|
|
1388
|
+
};
|
|
1389
|
+
this.initHighlighter = () => {
|
|
1390
|
+
this.highlighter = this.viewer.getComponent("HighlighterComponent");
|
|
1391
|
+
};
|
|
1392
|
+
this.camera = camera;
|
|
1393
|
+
this.viewer = viewer;
|
|
1394
|
+
this.groundObjects = groundObjects;
|
|
1395
|
+
this.raycaster = new Raycaster;
|
|
1396
|
+
this.raycaster.near = 0;
|
|
1397
|
+
this.raycaster.far = this.EYE_HEIGHT + this.FAILING_DISTANCE;
|
|
1398
|
+
this.moveKeys = new Set;
|
|
1399
|
+
this.moveClock = new Clock;
|
|
1400
|
+
this.quaternion = camera.quaternion.clone();
|
|
1401
|
+
this.downPosition = new Vector2(0, 0);
|
|
1402
|
+
this.rotateDelta = new Vector2(0, 0);
|
|
1403
|
+
this.domElement.addEventListener("pointerdown", this.onPointerDown);
|
|
1404
|
+
this.domElement.addEventListener("pointermove", this.onPointerMove);
|
|
1405
|
+
this.domElement.addEventListener("pointerup", this.onPointerUp);
|
|
1406
|
+
this.domElement.addEventListener("pointercancel", this.onPointerCancel);
|
|
1407
|
+
this.domElement.addEventListener("wheel", this.onWheel);
|
|
1408
|
+
window.addEventListener("keydown", this.onKeyDown);
|
|
1409
|
+
window.addEventListener("keyup", this.onKeyUp);
|
|
1410
|
+
}
|
|
1411
|
+
dispose() {
|
|
1412
|
+
this.domElement.removeEventListener("pointerdown", this.onPointerDown);
|
|
1413
|
+
this.domElement.removeEventListener("pointermove", this.onPointerMove);
|
|
1414
|
+
this.domElement.removeEventListener("pointerup", this.onPointerUp);
|
|
1415
|
+
this.domElement.removeEventListener("pointercancel", this.onPointerCancel);
|
|
1416
|
+
this.domElement.removeEventListener("wheel", this.onWheel);
|
|
1417
|
+
window.removeEventListener("keydown", this.onKeyDown);
|
|
1418
|
+
window.removeEventListener("keyup", this.onKeyUp);
|
|
1419
|
+
super.dispose();
|
|
1420
|
+
}
|
|
1421
|
+
updateGroundFollowing() {
|
|
1422
|
+
this.raycaster.set(this.object.position, new Vector3(0, -1, 0));
|
|
1423
|
+
this.raycaster.params = this.raycaster.params = {
|
|
1424
|
+
Mesh: {},
|
|
1425
|
+
Line: {
|
|
1426
|
+
threshold: 0
|
|
1427
|
+
},
|
|
1428
|
+
Line2: {
|
|
1429
|
+
threshold: 0
|
|
1430
|
+
},
|
|
1431
|
+
LOD: {
|
|
1432
|
+
threshold: 0
|
|
1433
|
+
},
|
|
1434
|
+
Points: {
|
|
1435
|
+
threshold: 0
|
|
1436
|
+
},
|
|
1437
|
+
Sprite: {
|
|
1438
|
+
threshold: 0
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
let intersects = this.raycaster.intersectObjects(this.groundObjects, false);
|
|
1442
|
+
if (intersects.length > 0) {
|
|
1443
|
+
const groundY = intersects[0].point.y;
|
|
1444
|
+
const targetY = groundY + this.EYE_HEIGHT;
|
|
1445
|
+
this.object.position.y = MathUtils.lerp(this.object.position.y, targetY, this.GROUND_FOLLOWING_SPEED);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
select(objects, model) {
|
|
1449
|
+
if (!model) {
|
|
1450
|
+
this.viewer.models.forEach(model => this.select(objects, model));
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
if (!Array.isArray(objects)) objects = [ objects ];
|
|
1454
|
+
if (!objects.length) return;
|
|
1455
|
+
model.showOriginalObjects(objects);
|
|
1456
|
+
this.highlighter.highlight(objects);
|
|
1457
|
+
objects.forEach(object => this.viewer.selected.push(object));
|
|
1458
|
+
objects.forEach(object => object.isSelected = true);
|
|
1459
|
+
}
|
|
1460
|
+
update() {
|
|
1461
|
+
let moved = false;
|
|
1462
|
+
let upgradeGroundFollowing = false;
|
|
1463
|
+
const forward = new Vector3;
|
|
1464
|
+
const sideways = new Vector3;
|
|
1465
|
+
if (this.moveKeys.size > 0) {
|
|
1466
|
+
upgradeGroundFollowing = true;
|
|
1467
|
+
const timeDelta = this.moveClock.getDelta();
|
|
1468
|
+
const moveDelta = timeDelta * this.multiplier * this.movementSpeed / this.WALK_SPEED_DELIMITER;
|
|
1469
|
+
this.object.getWorldDirection(forward);
|
|
1470
|
+
forward.y = 0;
|
|
1471
|
+
forward.normalize();
|
|
1472
|
+
sideways.setFromMatrixColumn(this.object.matrix, 0);
|
|
1473
|
+
sideways.y = 0;
|
|
1474
|
+
sideways.normalize();
|
|
1475
|
+
if (this.moveKeys.has("KeyW")) {
|
|
1476
|
+
this.object.position.addScaledVector(forward, moveDelta);
|
|
1477
|
+
}
|
|
1478
|
+
if (this.moveKeys.has("KeyS")) {
|
|
1479
|
+
this.object.position.addScaledVector(forward, -moveDelta);
|
|
1480
|
+
}
|
|
1481
|
+
if (this.moveKeys.has("KeyA")) {
|
|
1482
|
+
this.object.position.addScaledVector(sideways, -moveDelta);
|
|
1483
|
+
}
|
|
1484
|
+
if (this.moveKeys.has("KeyD")) {
|
|
1485
|
+
this.object.position.addScaledVector(sideways, moveDelta);
|
|
1486
|
+
}
|
|
1487
|
+
if (this.moveKeys.has("KeyQ")) {
|
|
1488
|
+
this.object.translateY(moveDelta);
|
|
1489
|
+
upgradeGroundFollowing = false;
|
|
1490
|
+
}
|
|
1491
|
+
if (this.moveKeys.has("KeyE")) {
|
|
1492
|
+
this.object.translateY(-moveDelta);
|
|
1493
|
+
upgradeGroundFollowing = false;
|
|
1494
|
+
}
|
|
1495
|
+
const lookDelta = this.LOOK_SPEED + (this.multiplier - 1);
|
|
1496
|
+
if (this.moveKeys.has("ArrowUp")) this.rotateCamera(this.rotateDelta.add(new Vector2(0, -lookDelta / 2)));
|
|
1497
|
+
if (this.moveKeys.has("ArrowDown")) this.rotateCamera(this.rotateDelta.add(new Vector2(0, lookDelta / 2)));
|
|
1498
|
+
if (this.moveKeys.has("ArrowLeft")) this.rotateCamera(this.rotateDelta.add(new Vector2(lookDelta, 0)));
|
|
1499
|
+
if (this.moveKeys.has("ArrowRight")) this.rotateCamera(this.rotateDelta.add(new Vector2(-lookDelta, 0)));
|
|
1500
|
+
this.moveWheel = 0;
|
|
1501
|
+
moved = true;
|
|
1502
|
+
}
|
|
1503
|
+
if (this.moveWheel !== 0) {
|
|
1504
|
+
const moveDelta = this.moveWheel * this.multiplier * this.movementSpeed / this.WHEEL_SPEED_DELIMITER;
|
|
1505
|
+
this.object.getWorldDirection(forward);
|
|
1506
|
+
forward.y = 0;
|
|
1507
|
+
forward.normalize();
|
|
1508
|
+
this.object.position.addScaledVector(forward, -moveDelta);
|
|
1509
|
+
this.moveWheel += -1 * Math.sign(this.moveWheel);
|
|
1510
|
+
moved = true;
|
|
1511
|
+
}
|
|
1512
|
+
if (upgradeGroundFollowing) this.updateGroundFollowing();
|
|
1513
|
+
if (moved) {
|
|
1514
|
+
this.dispatchEvent({
|
|
1515
|
+
type: "change"
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
if (this.moveKeys.size === 0 && this.moveWheel === 0) {
|
|
1519
|
+
this.moveClock.stop();
|
|
1520
|
+
this.moveClock.autoStart = true;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
rotateCamera(delta) {
|
|
1524
|
+
const rotateX = Math.PI * delta.x / this.domElement.clientWidth;
|
|
1525
|
+
const rotateY = Math.PI * delta.y / this.domElement.clientHeight;
|
|
1526
|
+
const xRotation = new Quaternion;
|
|
1527
|
+
xRotation.setFromAxisAngle(this.object.up, rotateX);
|
|
1528
|
+
const yRotation = new Quaternion;
|
|
1529
|
+
yRotation.setFromAxisAngle(new Vector3(1, 0, 0), rotateY);
|
|
1530
|
+
const quaternion = this.quaternion.clone();
|
|
1531
|
+
quaternion.premultiply(xRotation).multiply(yRotation).normalize();
|
|
1532
|
+
this.object.setRotationFromQuaternion(quaternion);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
class WalkDragger {
|
|
1537
|
+
constructor(viewer) {
|
|
1538
|
+
this.updateControls = () => {
|
|
1539
|
+
const size = this.viewer.extents.getSize(new Vector3);
|
|
1540
|
+
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
|
|
1541
|
+
};
|
|
1542
|
+
this.controlsChange = () => {
|
|
1543
|
+
this.viewer.update();
|
|
1544
|
+
this.viewer.emitEvent({
|
|
1545
|
+
type: "changecamera"
|
|
1546
|
+
});
|
|
1547
|
+
};
|
|
1548
|
+
this.walkspeedChange = event => {
|
|
1549
|
+
this.viewer.emitEvent(event);
|
|
1550
|
+
};
|
|
1551
|
+
this.viewerRender = () => {
|
|
1552
|
+
this.controls.update();
|
|
1553
|
+
};
|
|
1554
|
+
this.viewerZoom = () => {
|
|
1555
|
+
this.controls.rotateDelta.set(0, 0);
|
|
1556
|
+
};
|
|
1557
|
+
const meshOnlyGround = [];
|
|
1558
|
+
viewer.models[0].getObjects().forEach(obj => {
|
|
1559
|
+
obj.traverse(child => {
|
|
1560
|
+
if (child instanceof Mesh) {
|
|
1561
|
+
meshOnlyGround.push(child);
|
|
1562
|
+
}
|
|
1563
|
+
});
|
|
1564
|
+
});
|
|
1565
|
+
this.controls = new WalkControls(viewer.camera, viewer.canvas, meshOnlyGround, viewer);
|
|
1566
|
+
this.controls.addEventListener("change", this.controlsChange);
|
|
1567
|
+
this.controls.addEventListener("walkspeedchange", this.walkspeedChange);
|
|
1568
|
+
this.viewer = viewer;
|
|
1569
|
+
this.viewer.on("render", this.viewerRender);
|
|
1570
|
+
this.viewer.on("zoom", this.viewerZoom);
|
|
1571
|
+
this.updateControls();
|
|
1572
|
+
}
|
|
1573
|
+
dispose() {
|
|
1574
|
+
this.viewer.off("render", this.viewerRender);
|
|
1575
|
+
this.viewer.off("zoom", this.viewerZoom);
|
|
1576
|
+
this.controls.removeEventListener("walkspeedchange", this.walkspeedChange);
|
|
1577
|
+
this.controls.removeEventListener("change", this.controlsChange);
|
|
1578
|
+
this.controls.dispose();
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
class FlyControls extends Controls {
|
|
1297
1583
|
constructor(camera, canvas) {
|
|
1298
1584
|
super(camera, canvas);
|
|
1299
1585
|
this.movementSpeed = .2;
|
|
@@ -1336,7 +1622,7 @@ class WalkControls extends Controls {
|
|
|
1336
1622
|
if (this.multiplier > 1) {
|
|
1337
1623
|
this.multiplier = this.multiplier - 1;
|
|
1338
1624
|
this.dispatchEvent({
|
|
1339
|
-
type: "
|
|
1625
|
+
type: "flyspeedchange",
|
|
1340
1626
|
data: this.multiplier
|
|
1341
1627
|
});
|
|
1342
1628
|
}
|
|
@@ -1347,7 +1633,7 @@ class WalkControls extends Controls {
|
|
|
1347
1633
|
if (this.multiplier < 10) {
|
|
1348
1634
|
this.multiplier = this.multiplier + 1;
|
|
1349
1635
|
this.dispatchEvent({
|
|
1350
|
-
type: "
|
|
1636
|
+
type: "flyspeedchange",
|
|
1351
1637
|
data: this.multiplier
|
|
1352
1638
|
});
|
|
1353
1639
|
}
|
|
@@ -1440,7 +1726,7 @@ class WalkControls extends Controls {
|
|
|
1440
1726
|
}
|
|
1441
1727
|
}
|
|
1442
1728
|
|
|
1443
|
-
class
|
|
1729
|
+
class FlyDragger {
|
|
1444
1730
|
constructor(viewer) {
|
|
1445
1731
|
this.updateControls = () => {
|
|
1446
1732
|
const size = this.viewer.extents.getSize(new Vector3);
|
|
@@ -1448,8 +1734,11 @@ class WalkDragger {
|
|
|
1448
1734
|
};
|
|
1449
1735
|
this.controlsChange = () => {
|
|
1450
1736
|
this.viewer.update();
|
|
1737
|
+
this.viewer.emitEvent({
|
|
1738
|
+
type: "changecamera"
|
|
1739
|
+
});
|
|
1451
1740
|
};
|
|
1452
|
-
this.
|
|
1741
|
+
this.flyspeedChange = event => {
|
|
1453
1742
|
this.viewer.emitEvent(event);
|
|
1454
1743
|
};
|
|
1455
1744
|
this.viewerRender = () => {
|
|
@@ -1458,9 +1747,9 @@ class WalkDragger {
|
|
|
1458
1747
|
this.viewerZoom = () => {
|
|
1459
1748
|
this.controls.rotateDelta.set(0, 0);
|
|
1460
1749
|
};
|
|
1461
|
-
this.controls = new
|
|
1750
|
+
this.controls = new FlyControls(viewer.camera, viewer.canvas);
|
|
1462
1751
|
this.controls.addEventListener("change", this.controlsChange);
|
|
1463
|
-
this.controls.addEventListener("
|
|
1752
|
+
this.controls.addEventListener("flyspeedchange", this.flyspeedChange);
|
|
1464
1753
|
this.viewer = viewer;
|
|
1465
1754
|
this.viewer.on("render", this.viewerRender);
|
|
1466
1755
|
this.viewer.on("zoom", this.viewerZoom);
|
|
@@ -1469,7 +1758,7 @@ class WalkDragger {
|
|
|
1469
1758
|
dispose() {
|
|
1470
1759
|
this.viewer.off("render", this.viewerRender);
|
|
1471
1760
|
this.viewer.off("zoom", this.viewerZoom);
|
|
1472
|
-
this.controls.removeEventListener("
|
|
1761
|
+
this.controls.removeEventListener("flyspeedchange", this.flyspeedChange);
|
|
1473
1762
|
this.controls.removeEventListener("change", this.controlsChange);
|
|
1474
1763
|
this.controls.dispose();
|
|
1475
1764
|
}
|
|
@@ -1488,21 +1777,23 @@ class ZoomDragger extends OrbitDragger {
|
|
|
1488
1777
|
|
|
1489
1778
|
const draggers = draggersRegistry("threejs");
|
|
1490
1779
|
|
|
1491
|
-
draggers.registerDragger("Pan",
|
|
1780
|
+
draggers.registerDragger("Pan", viewer => new PanDragger(viewer));
|
|
1492
1781
|
|
|
1493
|
-
draggers.registerDragger("Orbit",
|
|
1782
|
+
draggers.registerDragger("Orbit", viewer => new OrbitDragger(viewer));
|
|
1494
1783
|
|
|
1495
|
-
draggers.registerDragger("Zoom",
|
|
1784
|
+
draggers.registerDragger("Zoom", viewer => new ZoomDragger(viewer));
|
|
1496
1785
|
|
|
1497
|
-
draggers.registerDragger("MeasureLine",
|
|
1786
|
+
draggers.registerDragger("MeasureLine", viewer => new MeasureLineDragger(viewer));
|
|
1498
1787
|
|
|
1499
|
-
draggers.registerDragger("CuttingPlaneXAxis",
|
|
1788
|
+
draggers.registerDragger("CuttingPlaneXAxis", viewer => new CuttingPlaneXAxisDragger(viewer));
|
|
1500
1789
|
|
|
1501
|
-
draggers.registerDragger("CuttingPlaneYAxis",
|
|
1790
|
+
draggers.registerDragger("CuttingPlaneYAxis", viewer => new CuttingPlaneYAxisDragger(viewer));
|
|
1502
1791
|
|
|
1503
|
-
draggers.registerDragger("CuttingPlaneZAxis",
|
|
1792
|
+
draggers.registerDragger("CuttingPlaneZAxis", viewer => new CuttingPlaneZAxisDragger(viewer));
|
|
1504
1793
|
|
|
1505
|
-
draggers.registerDragger("Walk",
|
|
1794
|
+
draggers.registerDragger("Walk", viewer => new WalkDragger(viewer));
|
|
1795
|
+
|
|
1796
|
+
draggers.registerDragger("Fly", viewer => new FlyDragger(viewer));
|
|
1506
1797
|
|
|
1507
1798
|
function applyModelTransform(viewer, model) {
|
|
1508
1799
|
console.warn("applyModelTransform not implemented");
|
|
@@ -1533,7 +1824,7 @@ function createPreview(viewer, type = "image/jpeg", encoderOptions = .25) {
|
|
|
1533
1824
|
}
|
|
1534
1825
|
|
|
1535
1826
|
function explode(viewer, index = 0) {
|
|
1536
|
-
viewer.models.forEach(
|
|
1827
|
+
viewer.models.forEach(model => model.explode(index));
|
|
1537
1828
|
viewer.update();
|
|
1538
1829
|
viewer.emitEvent({
|
|
1539
1830
|
type: "explode",
|
|
@@ -1614,17 +1905,17 @@ function getDefaultViewPositions() {
|
|
|
1614
1905
|
}
|
|
1615
1906
|
|
|
1616
1907
|
function getModels(viewer) {
|
|
1617
|
-
return viewer.models.map(
|
|
1908
|
+
return viewer.models.map(model => model.handle);
|
|
1618
1909
|
}
|
|
1619
1910
|
|
|
1620
1911
|
function getSelected(viewer) {
|
|
1621
1912
|
const handles = [];
|
|
1622
|
-
viewer.models.forEach(
|
|
1913
|
+
viewer.models.forEach(model => handles.push(...model.getHandlesByObjects(viewer.selected)));
|
|
1623
1914
|
return handles;
|
|
1624
1915
|
}
|
|
1625
1916
|
|
|
1626
1917
|
function hideSelected(viewer) {
|
|
1627
|
-
viewer.models.forEach(
|
|
1918
|
+
viewer.models.forEach(model => model.hideObjects(viewer.selected));
|
|
1628
1919
|
const selection = viewer.getComponent("SelectionComponent");
|
|
1629
1920
|
selection.clearSelection();
|
|
1630
1921
|
viewer.update();
|
|
@@ -1639,7 +1930,7 @@ function hideSelected(viewer) {
|
|
|
1639
1930
|
}
|
|
1640
1931
|
|
|
1641
1932
|
function isolateSelected(viewer) {
|
|
1642
|
-
viewer.models.forEach(
|
|
1933
|
+
viewer.models.forEach(model => model.isolateObjects(viewer.selected));
|
|
1643
1934
|
viewer.update();
|
|
1644
1935
|
viewer.emitEvent({
|
|
1645
1936
|
type: "isolate"
|
|
@@ -1670,7 +1961,7 @@ function resetView(viewer) {
|
|
|
1670
1961
|
function selectModel(viewer, handle) {
|
|
1671
1962
|
const selection = viewer.getComponent("SelectionComponent");
|
|
1672
1963
|
selection.clearSelection();
|
|
1673
|
-
viewer.models.filter(
|
|
1964
|
+
viewer.models.filter(model => model.handle === handle).forEach(model => selection.select(model.getObjects(), model));
|
|
1674
1965
|
viewer.update();
|
|
1675
1966
|
viewer.emit({
|
|
1676
1967
|
type: "select",
|
|
@@ -1689,11 +1980,11 @@ function setMarkupColor(viewer, r = 255, g = 0, b = 0) {
|
|
|
1689
1980
|
function setSelected(viewer, handles = []) {
|
|
1690
1981
|
const selection = viewer.getComponent("SelectionComponent");
|
|
1691
1982
|
selection.clearSelection();
|
|
1692
|
-
viewer.models.forEach(
|
|
1983
|
+
viewer.models.forEach(model => {
|
|
1693
1984
|
const objects = model.getObjectsByHandles(handles);
|
|
1694
1985
|
model.showObjects(objects);
|
|
1695
1986
|
selection.select(objects, model);
|
|
1696
|
-
})
|
|
1987
|
+
});
|
|
1697
1988
|
viewer.update();
|
|
1698
1989
|
viewer.emitEvent({
|
|
1699
1990
|
type: "show"
|
|
@@ -1706,7 +1997,7 @@ function setSelected(viewer, handles = []) {
|
|
|
1706
1997
|
}
|
|
1707
1998
|
|
|
1708
1999
|
function showAll(viewer) {
|
|
1709
|
-
viewer.models.forEach(
|
|
2000
|
+
viewer.models.forEach(model => model.showAllObjects());
|
|
1710
2001
|
viewer.update();
|
|
1711
2002
|
viewer.emitEvent({
|
|
1712
2003
|
type: "showall"
|
|
@@ -1720,17 +2011,17 @@ function zoomToExtents(viewer) {
|
|
|
1720
2011
|
function zoomToObjects(viewer, handles = []) {
|
|
1721
2012
|
const handleSet = new Set(handles);
|
|
1722
2013
|
const objects = [];
|
|
1723
|
-
viewer.scene.traverseVisible(
|
|
2014
|
+
viewer.scene.traverseVisible(child => {
|
|
1724
2015
|
var _a;
|
|
1725
|
-
if (handleSet.has((_a = child.userData) === null || _a ===
|
|
1726
|
-
})
|
|
1727
|
-
const extents = objects.reduce((
|
|
2016
|
+
if (handleSet.has((_a = child.userData) === null || _a === void 0 ? void 0 : _a.handle)) objects.push(child);
|
|
2017
|
+
});
|
|
2018
|
+
const extents = objects.reduce((result, object) => result.expandByObject(object), new Box3);
|
|
1728
2019
|
if (extents.isEmpty()) extents.copy(viewer.extents);
|
|
1729
2020
|
zoomTo(viewer, extents);
|
|
1730
2021
|
}
|
|
1731
2022
|
|
|
1732
2023
|
function zoomToSelected(viewer) {
|
|
1733
|
-
const extents = viewer.selected.reduce((
|
|
2024
|
+
const extents = viewer.selected.reduce((result, object) => result.expandByObject(object), new Box3);
|
|
1734
2025
|
if (extents.isEmpty()) extents.copy(viewer.extents);
|
|
1735
2026
|
zoomTo(viewer, extents);
|
|
1736
2027
|
}
|
|
@@ -1783,25 +2074,25 @@ commands.registerCommand("zoomToObjects", zoomToObjects);
|
|
|
1783
2074
|
|
|
1784
2075
|
commands.registerCommand("zoomToSelected", zoomToSelected);
|
|
1785
2076
|
|
|
1786
|
-
commands.registerCommand("top",
|
|
2077
|
+
commands.registerCommand("top", viewer => setDefaultViewPosition(viewer, "top"));
|
|
1787
2078
|
|
|
1788
|
-
commands.registerCommand("bottom",
|
|
2079
|
+
commands.registerCommand("bottom", viewer => setDefaultViewPosition(viewer, "bottom"));
|
|
1789
2080
|
|
|
1790
|
-
commands.registerCommand("left",
|
|
2081
|
+
commands.registerCommand("left", viewer => setDefaultViewPosition(viewer, "left"));
|
|
1791
2082
|
|
|
1792
|
-
commands.registerCommand("right",
|
|
2083
|
+
commands.registerCommand("right", viewer => setDefaultViewPosition(viewer, "right"));
|
|
1793
2084
|
|
|
1794
|
-
commands.registerCommand("front",
|
|
2085
|
+
commands.registerCommand("front", viewer => setDefaultViewPosition(viewer, "front"));
|
|
1795
2086
|
|
|
1796
|
-
commands.registerCommand("back",
|
|
2087
|
+
commands.registerCommand("back", viewer => setDefaultViewPosition(viewer, "back"));
|
|
1797
2088
|
|
|
1798
|
-
commands.registerCommand("sw",
|
|
2089
|
+
commands.registerCommand("sw", viewer => setDefaultViewPosition(viewer, "sw"));
|
|
1799
2090
|
|
|
1800
|
-
commands.registerCommand("se",
|
|
2091
|
+
commands.registerCommand("se", viewer => setDefaultViewPosition(viewer, "se"));
|
|
1801
2092
|
|
|
1802
|
-
commands.registerCommand("ne",
|
|
2093
|
+
commands.registerCommand("ne", viewer => setDefaultViewPosition(viewer, "ne"));
|
|
1803
2094
|
|
|
1804
|
-
commands.registerCommand("nw",
|
|
2095
|
+
commands.registerCommand("nw", viewer => setDefaultViewPosition(viewer, "nw"));
|
|
1805
2096
|
|
|
1806
2097
|
commands.registerCommandAlias("clearMarkup", "clearOverlay");
|
|
1807
2098
|
|
|
@@ -1854,9 +2145,9 @@ class CameraComponent {
|
|
|
1854
2145
|
const rendererSize = this.viewer.renderer.getSize(new Vector2);
|
|
1855
2146
|
const aspect = rendererSize.x / rendererSize.y;
|
|
1856
2147
|
let camera;
|
|
1857
|
-
this.viewer.scene.traverse(
|
|
2148
|
+
this.viewer.scene.traverse(object => {
|
|
1858
2149
|
if (object.isCamera) if (!camera) camera = object; else if (object.isPerspectiveCamera && camera.isOrthographicCamera) camera = object;
|
|
1859
|
-
})
|
|
2150
|
+
});
|
|
1860
2151
|
if (camera) {
|
|
1861
2152
|
camera.isDefaultCamera = true;
|
|
1862
2153
|
camera.scale.set(1, 1, 1);
|
|
@@ -1896,9 +2187,9 @@ class ExtentsComponent {
|
|
|
1896
2187
|
constructor(viewer) {
|
|
1897
2188
|
this.syncExtents = () => {
|
|
1898
2189
|
const extents = new Box3;
|
|
1899
|
-
this.viewer.models.forEach(
|
|
2190
|
+
this.viewer.models.forEach(model => model.getExtents(extents));
|
|
1900
2191
|
this.viewer.extents.copy(extents);
|
|
1901
|
-
extents.getCenter(this.viewer.target);
|
|
2192
|
+
this.viewer.extents.getCenter(this.viewer.target);
|
|
1902
2193
|
};
|
|
1903
2194
|
this.viewer = viewer;
|
|
1904
2195
|
this.viewer.addEventListener("databasechunk", this.syncExtents);
|
|
@@ -1990,25 +2281,7 @@ class ResizeCanvasComponent {
|
|
|
1990
2281
|
this.resizeViewer = entries => {
|
|
1991
2282
|
const {width: width, height: height} = entries[0].contentRect;
|
|
1992
2283
|
if (!width || !height) return;
|
|
1993
|
-
|
|
1994
|
-
const aspect = width / height;
|
|
1995
|
-
if (camera.isPerspectiveCamera) {
|
|
1996
|
-
camera.aspect = aspect;
|
|
1997
|
-
camera.updateProjectionMatrix();
|
|
1998
|
-
}
|
|
1999
|
-
if (camera.isOrthographicCamera) {
|
|
2000
|
-
camera.left = camera.bottom * aspect;
|
|
2001
|
-
camera.right = camera.top * aspect;
|
|
2002
|
-
camera.updateProjectionMatrix();
|
|
2003
|
-
}
|
|
2004
|
-
this.viewer.renderer.setSize(width, height, true);
|
|
2005
|
-
this.viewer.composer.setSize(width, height);
|
|
2006
|
-
this.viewer.update(true);
|
|
2007
|
-
this.viewer.emitEvent({
|
|
2008
|
-
type: "resize",
|
|
2009
|
-
width: width,
|
|
2010
|
-
height: height
|
|
2011
|
-
});
|
|
2284
|
+
this.viewer.setSize(width, height);
|
|
2012
2285
|
};
|
|
2013
2286
|
this.viewer = viewer;
|
|
2014
2287
|
this.resizeObserver = new ResizeObserver(this.resizeViewer);
|
|
@@ -2124,7 +2397,7 @@ class HighlighterComponent {
|
|
|
2124
2397
|
const {edgesVisibility: edgesVisibility} = this.viewer.options;
|
|
2125
2398
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2126
2399
|
if (!objects.length) return;
|
|
2127
|
-
objects.filter(
|
|
2400
|
+
objects.filter(object => !object.userData.isEdge).forEach(object => {
|
|
2128
2401
|
if (object.isHighlighted) return;
|
|
2129
2402
|
if (object.isLine || object.isLineSegments) {
|
|
2130
2403
|
const positions = object.geometry.attributes.position.array;
|
|
@@ -2154,19 +2427,19 @@ class HighlighterComponent {
|
|
|
2154
2427
|
object.material = this.facesMaterial;
|
|
2155
2428
|
object.isHighlighted = true;
|
|
2156
2429
|
}
|
|
2157
|
-
})
|
|
2430
|
+
});
|
|
2158
2431
|
}
|
|
2159
2432
|
unhighlight(objects) {
|
|
2160
2433
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2161
2434
|
if (!objects.length) return;
|
|
2162
|
-
objects.forEach(
|
|
2435
|
+
objects.forEach(object => {
|
|
2163
2436
|
if (!object.isHighlighted) return;
|
|
2164
2437
|
object.isHighlighted = false;
|
|
2165
2438
|
object.material = object.userData.originalMaterial;
|
|
2166
2439
|
object.userData.highlightWireframe.removeFromParent();
|
|
2167
2440
|
delete object.userData.originalMaterial;
|
|
2168
2441
|
delete object.userData.highlightWireframe;
|
|
2169
|
-
})
|
|
2442
|
+
});
|
|
2170
2443
|
}
|
|
2171
2444
|
syncHighlightColors() {
|
|
2172
2445
|
const {facesColor: facesColor, facesTransparancy: facesTransparancy, facesOverlap: facesOverlap} = this.viewer.options;
|
|
@@ -2182,16 +2455,16 @@ class HighlighterComponent {
|
|
|
2182
2455
|
this.lineGlowMaterial.color.setRGB(edgesColor.r / 255, edgesColor.g / 255, edgesColor.b / 255);
|
|
2183
2456
|
this.lineGlowMaterial.depthTest = !edgesOverlap;
|
|
2184
2457
|
this.lineGlowMaterial.depthWrite = !edgesOverlap;
|
|
2185
|
-
this.viewer.selected.forEach(
|
|
2458
|
+
this.viewer.selected.forEach(selected => {
|
|
2186
2459
|
const wireframe = selected.userData.highlightWireframe;
|
|
2187
2460
|
if (wireframe) wireframe.visible = edgesVisibility;
|
|
2188
|
-
})
|
|
2461
|
+
});
|
|
2189
2462
|
}
|
|
2190
2463
|
viewerResize(event) {
|
|
2191
2464
|
var _a, _b, _c;
|
|
2192
|
-
(_a = this.renderTarget) === null || _a ===
|
|
2193
|
-
(_b = this.edgesMaterial) === null || _b ===
|
|
2194
|
-
(_c = this.lineGlowMaterial) === null || _c ===
|
|
2465
|
+
(_a = this.renderTarget) === null || _a === void 0 ? void 0 : _a.setSize(event.width, event.height);
|
|
2466
|
+
(_b = this.edgesMaterial) === null || _b === void 0 ? void 0 : _b.resolution.set(event.width, event.height);
|
|
2467
|
+
(_c = this.lineGlowMaterial) === null || _c === void 0 ? void 0 : _c.resolution.set(event.width, event.height);
|
|
2195
2468
|
}
|
|
2196
2469
|
}
|
|
2197
2470
|
|
|
@@ -2206,15 +2479,15 @@ class SelectionComponent {
|
|
|
2206
2479
|
const upPosition = this.getMousePosition(event, new Vector2);
|
|
2207
2480
|
if (upPosition.distanceTo(this.downPosition) !== 0) return;
|
|
2208
2481
|
let intersections = [];
|
|
2209
|
-
this.viewer.models.forEach(
|
|
2482
|
+
this.viewer.models.forEach(model => {
|
|
2210
2483
|
const objects = model.getVisibleObjects();
|
|
2211
2484
|
const intersects = this.getPointerIntersects(upPosition, objects);
|
|
2212
2485
|
if (intersects.length > 0) intersections.push({
|
|
2213
2486
|
...intersects[0],
|
|
2214
2487
|
model: model
|
|
2215
2488
|
});
|
|
2216
|
-
})
|
|
2217
|
-
intersections = intersections.sort((
|
|
2489
|
+
});
|
|
2490
|
+
intersections = intersections.sort((a, b) => a.distance - b.distance);
|
|
2218
2491
|
if (!event.shiftKey) this.clearSelection();
|
|
2219
2492
|
if (intersections.length > 0) {
|
|
2220
2493
|
const model = intersections[0].model;
|
|
@@ -2277,27 +2550,27 @@ class SelectionComponent {
|
|
|
2277
2550
|
}
|
|
2278
2551
|
select(objects, model) {
|
|
2279
2552
|
if (!model) {
|
|
2280
|
-
this.viewer.models.forEach(
|
|
2553
|
+
this.viewer.models.forEach(model => this.select(objects, model));
|
|
2281
2554
|
return;
|
|
2282
2555
|
}
|
|
2283
2556
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2284
2557
|
if (!objects.length) return;
|
|
2285
2558
|
model.showOriginalObjects(objects);
|
|
2286
2559
|
this.highlighter.highlight(objects);
|
|
2287
|
-
objects.forEach(
|
|
2288
|
-
objects.forEach(
|
|
2560
|
+
objects.forEach(object => this.viewer.selected.push(object));
|
|
2561
|
+
objects.forEach(object => object.isSelected = true);
|
|
2289
2562
|
}
|
|
2290
2563
|
deselect(objects, model) {
|
|
2291
2564
|
if (!model) {
|
|
2292
|
-
this.viewer.models.forEach(
|
|
2565
|
+
this.viewer.models.forEach(model => this.select(objects, model));
|
|
2293
2566
|
return;
|
|
2294
2567
|
}
|
|
2295
2568
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2296
2569
|
if (!objects.length) return;
|
|
2297
2570
|
this.highlighter.unhighlight(objects);
|
|
2298
2571
|
model.hideOriginalObjects(objects);
|
|
2299
|
-
this.viewer.selected = this.viewer.selected.filter(
|
|
2300
|
-
objects.forEach(
|
|
2572
|
+
this.viewer.selected = this.viewer.selected.filter(x => !objects.includes(x));
|
|
2573
|
+
objects.forEach(object => object.isSelected = false);
|
|
2301
2574
|
}
|
|
2302
2575
|
toggleSelection(objects, model) {
|
|
2303
2576
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
@@ -2307,8 +2580,8 @@ class SelectionComponent {
|
|
|
2307
2580
|
clearSelection() {
|
|
2308
2581
|
if (!this.viewer.selected.length) return;
|
|
2309
2582
|
this.highlighter.unhighlight(this.viewer.selected);
|
|
2310
|
-
this.viewer.models.forEach(
|
|
2311
|
-
this.viewer.selected.forEach(
|
|
2583
|
+
this.viewer.models.forEach(model => model.hideOriginalObjects(this.viewer.selected));
|
|
2584
|
+
this.viewer.selected.forEach(object => object.isSelected = false);
|
|
2312
2585
|
this.viewer.selected.length = 0;
|
|
2313
2586
|
}
|
|
2314
2587
|
}
|
|
@@ -2322,15 +2595,15 @@ class WCSHelper extends Object3D {
|
|
|
2322
2595
|
this.orthoCamera.position.set(0, 0, 2);
|
|
2323
2596
|
const matRed = new MeshBasicMaterial({
|
|
2324
2597
|
toneMapped: false,
|
|
2325
|
-
color: "#
|
|
2598
|
+
color: "#dd0000"
|
|
2326
2599
|
});
|
|
2327
2600
|
const matGreen = new MeshBasicMaterial({
|
|
2328
2601
|
toneMapped: false,
|
|
2329
|
-
color: "#
|
|
2602
|
+
color: "#00dd00"
|
|
2330
2603
|
});
|
|
2331
2604
|
const matBlue = new MeshBasicMaterial({
|
|
2332
2605
|
toneMapped: false,
|
|
2333
|
-
color: "#
|
|
2606
|
+
color: "#0000dd"
|
|
2334
2607
|
});
|
|
2335
2608
|
const spriteRed = this.getSpriteMaterial(matRed.color, "X");
|
|
2336
2609
|
const spriteGreen = this.getSpriteMaterial(matGreen.color, "Y");
|
|
@@ -2344,8 +2617,8 @@ class WCSHelper extends Object3D {
|
|
|
2344
2617
|
Y: [ [ new Mesh(arrowGeometry, matGreen), [ 0, .5, 0 ], null ], [ new Mesh(lineGeometry, matGreen), null, null ], [ new Sprite(spriteGreen), [ 0, 1.55, 0 ] ] ],
|
|
2345
2618
|
Z: [ [ new Mesh(arrowGeometry, matBlue), [ 0, 0, .5 ], [ Math.PI / 2, 0, 0 ] ], [ new Mesh(lineGeometry, matBlue), null, [ Math.PI / 2, 0, 0 ] ], [ new Sprite(spriteBlue), [ 0, 0, 1.55 ] ] ]
|
|
2346
2619
|
};
|
|
2347
|
-
Object.keys(axesMap).forEach(
|
|
2348
|
-
axesMap[key].forEach(
|
|
2620
|
+
Object.keys(axesMap).forEach(key => {
|
|
2621
|
+
axesMap[key].forEach(objects => {
|
|
2349
2622
|
const object = objects[0];
|
|
2350
2623
|
const position = objects[1];
|
|
2351
2624
|
const rotation = objects[2];
|
|
@@ -2354,14 +2627,14 @@ class WCSHelper extends Object3D {
|
|
|
2354
2627
|
if (rotation) object.rotation.set(rotation[0], rotation[1], rotation[2]);
|
|
2355
2628
|
object.updateMatrixWorld();
|
|
2356
2629
|
this.add(object);
|
|
2357
|
-
})
|
|
2358
|
-
})
|
|
2630
|
+
});
|
|
2631
|
+
});
|
|
2359
2632
|
}
|
|
2360
2633
|
dispose() {
|
|
2361
|
-
this.traverse(
|
|
2634
|
+
this.traverse(object => {
|
|
2362
2635
|
if (object.geometry) object.geometry.dispose();
|
|
2363
2636
|
if (object.material) object.material.dispose();
|
|
2364
|
-
})
|
|
2637
|
+
});
|
|
2365
2638
|
}
|
|
2366
2639
|
getSpriteMaterial(color, text) {
|
|
2367
2640
|
const canvas = document.createElement("canvas");
|
|
@@ -2423,23 +2696,23 @@ class WCSHelperComponent {
|
|
|
2423
2696
|
|
|
2424
2697
|
const components = componentsRegistry("threejs");
|
|
2425
2698
|
|
|
2426
|
-
components.registerComponent("ExtentsComponent",
|
|
2699
|
+
components.registerComponent("ExtentsComponent", viewer => new ExtentsComponent(viewer));
|
|
2427
2700
|
|
|
2428
|
-
components.registerComponent("CameraComponent",
|
|
2701
|
+
components.registerComponent("CameraComponent", viewer => new CameraComponent(viewer));
|
|
2429
2702
|
|
|
2430
|
-
components.registerComponent("BackgroundComponent",
|
|
2703
|
+
components.registerComponent("BackgroundComponent", viewer => new BackgroundComponent(viewer));
|
|
2431
2704
|
|
|
2432
|
-
components.registerComponent("LightComponent",
|
|
2705
|
+
components.registerComponent("LightComponent", viewer => new LightComponent(viewer));
|
|
2433
2706
|
|
|
2434
|
-
components.registerComponent("ResizeCanvasComponent",
|
|
2707
|
+
components.registerComponent("ResizeCanvasComponent", viewer => new ResizeCanvasComponent(viewer));
|
|
2435
2708
|
|
|
2436
|
-
components.registerComponent("RenderLoopComponent",
|
|
2709
|
+
components.registerComponent("RenderLoopComponent", viewer => new RenderLoopComponent(viewer));
|
|
2437
2710
|
|
|
2438
|
-
components.registerComponent("HighlighterComponent",
|
|
2711
|
+
components.registerComponent("HighlighterComponent", viewer => new HighlighterComponent(viewer));
|
|
2439
2712
|
|
|
2440
|
-
components.registerComponent("SelectionComponent",
|
|
2713
|
+
components.registerComponent("SelectionComponent", viewer => new SelectionComponent(viewer));
|
|
2441
2714
|
|
|
2442
|
-
components.registerComponent("WCSHelperComponent",
|
|
2715
|
+
components.registerComponent("WCSHelperComponent", viewer => new WCSHelperComponent(viewer));
|
|
2443
2716
|
|
|
2444
2717
|
class GLTFLoadingManager extends LoadingManager {
|
|
2445
2718
|
constructor(file, params = {}) {
|
|
@@ -2454,19 +2727,19 @@ class GLTFLoadingManager extends LoadingManager {
|
|
|
2454
2727
|
this.fileURL = file;
|
|
2455
2728
|
this.resourcePath = LoaderUtils.extractUrlBase(file);
|
|
2456
2729
|
} else {
|
|
2457
|
-
externalFiles.forEach((
|
|
2730
|
+
externalFiles.forEach((value, key) => this.fileURL = value === file ? key : this.fileURL);
|
|
2458
2731
|
externalFiles.set(this.fileURL, file);
|
|
2459
2732
|
}
|
|
2460
|
-
externalFiles.forEach((
|
|
2733
|
+
externalFiles.forEach((value, key) => {
|
|
2461
2734
|
let dataURL;
|
|
2462
2735
|
if (typeof value === "string") dataURL = value; else dataURL = URL.createObjectURL(new Blob([ value ]));
|
|
2463
2736
|
this.dataURLs.set(key, dataURL);
|
|
2464
|
-
})
|
|
2465
|
-
this.setURLModifier(
|
|
2737
|
+
});
|
|
2738
|
+
this.setURLModifier(url => {
|
|
2466
2739
|
const key = decodeURI(url).replace(this.path, "").replace(this.resourcePath, "").replace(/^(\.?\/)/, "");
|
|
2467
2740
|
const dataURL = this.dataURLs.get(key);
|
|
2468
|
-
return dataURL !== null && dataURL !==
|
|
2469
|
-
})
|
|
2741
|
+
return dataURL !== null && dataURL !== void 0 ? dataURL : url;
|
|
2742
|
+
});
|
|
2470
2743
|
}
|
|
2471
2744
|
dispose() {
|
|
2472
2745
|
this.dataURLs.forEach(URL.revokeObjectURL);
|
|
@@ -2484,7 +2757,7 @@ class ModelImpl {
|
|
|
2484
2757
|
}
|
|
2485
2758
|
function disposeMaterials(material) {
|
|
2486
2759
|
const materials = Array.isArray(material) ? material : [ material ];
|
|
2487
|
-
materials.forEach(
|
|
2760
|
+
materials.forEach(material => disposeMaterial(material));
|
|
2488
2761
|
}
|
|
2489
2762
|
function disposeObject(object) {
|
|
2490
2763
|
if (object.geometry) object.geometry.dispose();
|
|
@@ -2494,17 +2767,17 @@ class ModelImpl {
|
|
|
2494
2767
|
this.scene.clear();
|
|
2495
2768
|
}
|
|
2496
2769
|
getExtents(target) {
|
|
2497
|
-
this.scene.traverseVisible(
|
|
2770
|
+
this.scene.traverseVisible(object => !object.children.length && target.expandByObject(object));
|
|
2498
2771
|
return target;
|
|
2499
2772
|
}
|
|
2500
2773
|
getObjects() {
|
|
2501
2774
|
const objects = [];
|
|
2502
|
-
this.scene.traverse(
|
|
2775
|
+
this.scene.traverse(object => objects.push(object));
|
|
2503
2776
|
return objects;
|
|
2504
2777
|
}
|
|
2505
2778
|
getVisibleObjects() {
|
|
2506
2779
|
const objects = [];
|
|
2507
|
-
this.scene.traverseVisible(
|
|
2780
|
+
this.scene.traverseVisible(object => objects.push(object));
|
|
2508
2781
|
return objects;
|
|
2509
2782
|
}
|
|
2510
2783
|
hasObject(object) {
|
|
@@ -2516,23 +2789,23 @@ class ModelImpl {
|
|
|
2516
2789
|
}
|
|
2517
2790
|
getOwnObjects(objects) {
|
|
2518
2791
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2519
|
-
return objects.filter(
|
|
2792
|
+
return objects.filter(object => this.hasObject(object));
|
|
2520
2793
|
}
|
|
2521
2794
|
getObjectsByHandles(handles) {
|
|
2522
2795
|
const handleSet = new Set(handles);
|
|
2523
2796
|
const objects = [];
|
|
2524
|
-
this.scene.traverse(
|
|
2797
|
+
this.scene.traverse(object => handleSet.has(object.userData.handle) && objects.push(object));
|
|
2525
2798
|
return objects;
|
|
2526
2799
|
}
|
|
2527
2800
|
getHandlesByObjects(objects) {
|
|
2528
2801
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2529
2802
|
const handlesSet = new Set;
|
|
2530
|
-
this.getOwnObjects(objects).forEach(
|
|
2803
|
+
this.getOwnObjects(objects).forEach(object => handlesSet.add(object.userData.handle));
|
|
2531
2804
|
return Array.from(handlesSet);
|
|
2532
2805
|
}
|
|
2533
2806
|
hideObjects(objects) {
|
|
2534
2807
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2535
|
-
this.getOwnObjects(objects).forEach(
|
|
2808
|
+
this.getOwnObjects(objects).forEach(object => object.visible = false);
|
|
2536
2809
|
return this;
|
|
2537
2810
|
}
|
|
2538
2811
|
hideAllObjects() {
|
|
@@ -2541,20 +2814,20 @@ class ModelImpl {
|
|
|
2541
2814
|
isolateObjects(objects) {
|
|
2542
2815
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2543
2816
|
const visibleSet = new Set(objects);
|
|
2544
|
-
this.getOwnObjects(objects).forEach(
|
|
2545
|
-
this.scene.traverse(
|
|
2817
|
+
this.getOwnObjects(objects).forEach(object => object.traverseAncestors(parent => visibleSet.add(parent)));
|
|
2818
|
+
this.scene.traverse(object => object.visible = visibleSet.has(object));
|
|
2546
2819
|
return this;
|
|
2547
2820
|
}
|
|
2548
2821
|
showObjects(objects) {
|
|
2549
2822
|
if (!Array.isArray(objects)) objects = [ objects ];
|
|
2550
|
-
this.getOwnObjects(objects).forEach(
|
|
2823
|
+
this.getOwnObjects(objects).forEach(object => {
|
|
2551
2824
|
object.visible = true;
|
|
2552
|
-
object.traverseAncestors(
|
|
2553
|
-
})
|
|
2825
|
+
object.traverseAncestors(parent => parent.visible = true);
|
|
2826
|
+
});
|
|
2554
2827
|
return this;
|
|
2555
2828
|
}
|
|
2556
2829
|
showAllObjects() {
|
|
2557
|
-
this.scene.traverse(
|
|
2830
|
+
this.scene.traverse(object => object.visible = true);
|
|
2558
2831
|
return this;
|
|
2559
2832
|
}
|
|
2560
2833
|
showOriginalObjects(objects) {
|
|
@@ -2566,10 +2839,10 @@ class ModelImpl {
|
|
|
2566
2839
|
explode(scale = 0, coeff = 4) {
|
|
2567
2840
|
function calcExplodeDepth(object, depth) {
|
|
2568
2841
|
let res = depth;
|
|
2569
|
-
object.children.forEach(
|
|
2842
|
+
object.children.forEach(x => {
|
|
2570
2843
|
const objectDepth = calcExplodeDepth(x, depth + 1);
|
|
2571
2844
|
if (res < objectDepth) res = objectDepth;
|
|
2572
|
-
})
|
|
2845
|
+
});
|
|
2573
2846
|
object.userData.originalPosition = object.position.clone();
|
|
2574
2847
|
object.userData.originalCenter = (new Box3).setFromObject(object).getCenter(new Vector3);
|
|
2575
2848
|
object.userData.isExplodeLocked = depth > 2 && object.children.length === 0;
|
|
@@ -2591,7 +2864,7 @@ class ModelImpl {
|
|
|
2591
2864
|
const objectOffset = objectCenter.clone().sub(parentCenter).multiplyScalar(objectScale);
|
|
2592
2865
|
object.position.add(objectOffset);
|
|
2593
2866
|
}
|
|
2594
|
-
object.children.forEach(
|
|
2867
|
+
object.children.forEach(x => explodeObject(x, depth + 1));
|
|
2595
2868
|
}
|
|
2596
2869
|
explodeObject(this.scene, 0);
|
|
2597
2870
|
this.scene.updateMatrixWorld();
|
|
@@ -2647,9 +2920,9 @@ class DynamicModelImpl extends ModelImpl {
|
|
|
2647
2920
|
}
|
|
2648
2921
|
getObjects() {
|
|
2649
2922
|
const objects = [];
|
|
2650
|
-
this.gltfLoader.originalObjects.forEach(
|
|
2923
|
+
this.gltfLoader.originalObjects.forEach(object => {
|
|
2651
2924
|
objects.push(object);
|
|
2652
|
-
})
|
|
2925
|
+
});
|
|
2653
2926
|
return objects;
|
|
2654
2927
|
}
|
|
2655
2928
|
getVisibleObjects() {
|
|
@@ -2661,16 +2934,16 @@ class DynamicModelImpl extends ModelImpl {
|
|
|
2661
2934
|
getObjectsByHandles(handles) {
|
|
2662
2935
|
const handlesSet = new Set(handles);
|
|
2663
2936
|
const objects = [];
|
|
2664
|
-
handlesSet.forEach(
|
|
2937
|
+
handlesSet.forEach(handle => {
|
|
2665
2938
|
const handle2 = `${this.modelId}_${handle}`;
|
|
2666
2939
|
const handles = this.gltfLoader.handleToObjects.get(handle2) || [];
|
|
2667
2940
|
objects.push(...Array.from(handles));
|
|
2668
|
-
})
|
|
2941
|
+
});
|
|
2669
2942
|
return objects;
|
|
2670
2943
|
}
|
|
2671
2944
|
getHandlesByObjects(objects) {
|
|
2672
2945
|
const handles = super.getHandlesByObjects(objects);
|
|
2673
|
-
return handles.map(
|
|
2946
|
+
return handles.map(x => x.split("_").pop());
|
|
2674
2947
|
}
|
|
2675
2948
|
hideObjects(objects) {
|
|
2676
2949
|
const handles = super.getHandlesByObjects(objects);
|
|
@@ -2711,13 +2984,24 @@ const GL_COMPONENT_TYPES = {
|
|
|
2711
2984
|
};
|
|
2712
2985
|
|
|
2713
2986
|
const GL_CONSTANTS = {
|
|
2987
|
+
FLOAT: 5126,
|
|
2988
|
+
FLOAT_MAT3: 35675,
|
|
2989
|
+
FLOAT_MAT4: 35676,
|
|
2990
|
+
FLOAT_VEC2: 35664,
|
|
2991
|
+
FLOAT_VEC3: 35665,
|
|
2992
|
+
FLOAT_VEC4: 35666,
|
|
2993
|
+
LINEAR: 9729,
|
|
2994
|
+
REPEAT: 10497,
|
|
2995
|
+
SAMPLER_2D: 35678,
|
|
2714
2996
|
POINTS: 0,
|
|
2715
2997
|
LINES: 1,
|
|
2716
2998
|
LINE_LOOP: 2,
|
|
2717
2999
|
LINE_STRIP: 3,
|
|
2718
3000
|
TRIANGLES: 4,
|
|
2719
3001
|
TRIANGLE_STRIP: 5,
|
|
2720
|
-
TRIANGLE_FAN: 6
|
|
3002
|
+
TRIANGLE_FAN: 6,
|
|
3003
|
+
UNSIGNED_BYTE: 5121,
|
|
3004
|
+
UNSIGNED_SHORT: 5123
|
|
2721
3005
|
};
|
|
2722
3006
|
|
|
2723
3007
|
const MAX_GAP = 128 * 1024;
|
|
@@ -2765,19 +3049,19 @@ class GltfStructure {
|
|
|
2765
3049
|
return this.json;
|
|
2766
3050
|
}
|
|
2767
3051
|
scheduleRequest(request) {
|
|
2768
|
-
return new Promise((
|
|
3052
|
+
return new Promise((resolve, reject) => {
|
|
2769
3053
|
this.pendingRequests.push({
|
|
2770
3054
|
...request,
|
|
2771
3055
|
_resolve: resolve,
|
|
2772
3056
|
_reject: reject
|
|
2773
3057
|
});
|
|
2774
|
-
})
|
|
3058
|
+
});
|
|
2775
3059
|
}
|
|
2776
3060
|
async flushBufferRequests() {
|
|
2777
3061
|
if (!this.pendingRequests || this.pendingRequests.length === 0) return;
|
|
2778
3062
|
const requests = [ ...this.pendingRequests ];
|
|
2779
3063
|
this.pendingRequests = [];
|
|
2780
|
-
requests.sort((
|
|
3064
|
+
requests.sort((a, b) => a.offset - b.offset);
|
|
2781
3065
|
const mergedRanges = [];
|
|
2782
3066
|
let current = {
|
|
2783
3067
|
start: requests[0].offset,
|
|
@@ -2837,7 +3121,7 @@ class GltfStructure {
|
|
|
2837
3121
|
});
|
|
2838
3122
|
}
|
|
2839
3123
|
}
|
|
2840
|
-
const promises = finalRanges.map(
|
|
3124
|
+
const promises = finalRanges.map(async (range, index) => {
|
|
2841
3125
|
await this.loader.waitForChunkSlot();
|
|
2842
3126
|
try {
|
|
2843
3127
|
const length = range.end - range.start;
|
|
@@ -2865,7 +3149,7 @@ class GltfStructure {
|
|
|
2865
3149
|
} finally {
|
|
2866
3150
|
this.loader.releaseChunkSlot();
|
|
2867
3151
|
}
|
|
2868
|
-
})
|
|
3152
|
+
});
|
|
2869
3153
|
await Promise.all(promises);
|
|
2870
3154
|
this.pendingRequests = [];
|
|
2871
3155
|
}
|
|
@@ -3022,7 +3306,7 @@ class GltfStructure {
|
|
|
3022
3306
|
};
|
|
3023
3307
|
const texturePromises = [];
|
|
3024
3308
|
for (let i = 0; i < this.json.textures.length; i++) {
|
|
3025
|
-
texturePromises.push(loadTexture(this.json.textures[i].source).then(
|
|
3309
|
+
texturePromises.push(loadTexture(this.json.textures[i].source).then(texture => this.textureCache.set(i, texture)));
|
|
3026
3310
|
}
|
|
3027
3311
|
await Promise.all(texturePromises);
|
|
3028
3312
|
}
|
|
@@ -3101,9 +3385,9 @@ class GltfStructure {
|
|
|
3101
3385
|
return null;
|
|
3102
3386
|
}
|
|
3103
3387
|
disposeMaterials() {
|
|
3104
|
-
this.textureCache.forEach(
|
|
3388
|
+
this.textureCache.forEach(texture => texture.dispose());
|
|
3105
3389
|
this.textureCache.clear();
|
|
3106
|
-
this.materials.forEach(
|
|
3390
|
+
this.materials.forEach(material => {
|
|
3107
3391
|
if (material.map) material.map.dispose();
|
|
3108
3392
|
if (material.lightMap) material.lightMap.dispose();
|
|
3109
3393
|
if (material.bumpMap) material.bumpMap.dispose();
|
|
@@ -3115,9 +3399,9 @@ class GltfStructure {
|
|
|
3115
3399
|
if (material.roughnessMap) material.roughnessMap.dispose();
|
|
3116
3400
|
if (material.emissiveMap) material.emissiveMap.dispose();
|
|
3117
3401
|
material.dispose();
|
|
3118
|
-
})
|
|
3402
|
+
});
|
|
3119
3403
|
this.materials.clear();
|
|
3120
|
-
this.materialCache.forEach(
|
|
3404
|
+
this.materialCache.forEach(materialCache => {
|
|
3121
3405
|
if (materialCache.mesh) {
|
|
3122
3406
|
if (materialCache.mesh.map) materialCache.mesh.map.dispose();
|
|
3123
3407
|
if (materialCache.mesh.lightMap) materialCache.mesh.lightMap.dispose();
|
|
@@ -3139,7 +3423,7 @@ class GltfStructure {
|
|
|
3139
3423
|
if (materialCache.lines.map) materialCache.lines.map.dispose();
|
|
3140
3424
|
materialCache.lines.dispose();
|
|
3141
3425
|
}
|
|
3142
|
-
})
|
|
3426
|
+
});
|
|
3143
3427
|
this.materialCache.clear();
|
|
3144
3428
|
}
|
|
3145
3429
|
estimateNodeSize(meshIndex) {
|
|
@@ -3264,29 +3548,29 @@ class DynamicGltfLoader {
|
|
|
3264
3548
|
setMemoryLimit(bytesLimit) {}
|
|
3265
3549
|
estimateGeometrySize(nodeGroup) {
|
|
3266
3550
|
let totalSize = 0;
|
|
3267
|
-
nodeGroup.traverse(
|
|
3551
|
+
nodeGroup.traverse(child => {
|
|
3268
3552
|
if (child.geometry) {
|
|
3269
3553
|
if (this.abortController.signal.aborted) {
|
|
3270
3554
|
throw new DOMException("Loading aborted", "AbortError");
|
|
3271
3555
|
}
|
|
3272
3556
|
const geometry = child.geometry;
|
|
3273
3557
|
if (geometry.attributes) {
|
|
3274
|
-
Object.values(geometry.attributes).forEach(
|
|
3558
|
+
Object.values(geometry.attributes).forEach(attribute => {
|
|
3275
3559
|
if (attribute && attribute.array) {
|
|
3276
3560
|
totalSize += attribute.array.byteLength;
|
|
3277
3561
|
}
|
|
3278
|
-
})
|
|
3562
|
+
});
|
|
3279
3563
|
}
|
|
3280
3564
|
if (geometry.index && geometry.index.array) {
|
|
3281
3565
|
totalSize += geometry.index.array.byteLength;
|
|
3282
3566
|
}
|
|
3283
3567
|
}
|
|
3284
|
-
})
|
|
3568
|
+
});
|
|
3285
3569
|
return totalSize;
|
|
3286
3570
|
}
|
|
3287
3571
|
recalculateScene() {
|
|
3288
3572
|
const geometries = [];
|
|
3289
|
-
this.scene.traverse(
|
|
3573
|
+
this.scene.traverse(object => {
|
|
3290
3574
|
if (this.abortController.signal.aborted) {
|
|
3291
3575
|
throw new DOMException("Loading aborted", "AbortError");
|
|
3292
3576
|
}
|
|
@@ -3299,11 +3583,11 @@ class DynamicGltfLoader {
|
|
|
3299
3583
|
distance: object.position.distanceTo(this.camera.position)
|
|
3300
3584
|
});
|
|
3301
3585
|
}
|
|
3302
|
-
})
|
|
3586
|
+
});
|
|
3303
3587
|
if (this.abortController.signal.aborted) {
|
|
3304
3588
|
throw new DOMException("Loading aborted", "AbortError");
|
|
3305
3589
|
}
|
|
3306
|
-
geometries.sort((
|
|
3590
|
+
geometries.sort((a, b) => b.distance - a.distance);
|
|
3307
3591
|
let currentMemoryUsage = 0;
|
|
3308
3592
|
for (const geo of geometries) {
|
|
3309
3593
|
currentMemoryUsage += geo.size;
|
|
@@ -3415,9 +3699,9 @@ class DynamicGltfLoader {
|
|
|
3415
3699
|
node.loading = false;
|
|
3416
3700
|
return;
|
|
3417
3701
|
}
|
|
3418
|
-
bufferRequests.sort((
|
|
3702
|
+
bufferRequests.sort((a, b) => a.offset - b.offset);
|
|
3419
3703
|
const minOffset = bufferRequests[0].offset;
|
|
3420
|
-
const maxOffset = Math.max(...bufferRequests.map(
|
|
3704
|
+
const maxOffset = Math.max(...bufferRequests.map(r => r.offset + r.length));
|
|
3421
3705
|
const totalLength = maxOffset - minOffset;
|
|
3422
3706
|
const {buffer: buffer, relOffset: baseRelOffset} = await node.structure.scheduleRequest({
|
|
3423
3707
|
offset: minOffset,
|
|
@@ -3433,25 +3717,25 @@ class DynamicGltfLoader {
|
|
|
3433
3717
|
const geometry = new BufferGeometry;
|
|
3434
3718
|
const reqs = primitiveReqMap.get(primIdx);
|
|
3435
3719
|
if (primitive.attributes.POSITION !== undefined) {
|
|
3436
|
-
const req = reqs.find(
|
|
3720
|
+
const req = reqs.find(r => r.type === "position" && r.accessorIndex === primitive.attributes.POSITION);
|
|
3437
3721
|
const accessor = node.structure.json.accessors[primitive.attributes.POSITION];
|
|
3438
3722
|
const components = node.structure.getNumComponents(accessor.type);
|
|
3439
3723
|
geometry.setAttribute("position", new BufferAttribute(req.data, components));
|
|
3440
3724
|
}
|
|
3441
3725
|
if (primitive.attributes.NORMAL !== undefined) {
|
|
3442
|
-
const req = reqs.find(
|
|
3726
|
+
const req = reqs.find(r => r.type === "normal" && r.accessorIndex === primitive.attributes.NORMAL);
|
|
3443
3727
|
const accessor = node.structure.json.accessors[primitive.attributes.NORMAL];
|
|
3444
3728
|
const components = node.structure.getNumComponents(accessor.type);
|
|
3445
3729
|
geometry.setAttribute("normal", new BufferAttribute(req.data, components));
|
|
3446
3730
|
}
|
|
3447
3731
|
if (primitive.attributes.TEXCOORD_0 !== undefined) {
|
|
3448
|
-
const req = reqs.find(
|
|
3732
|
+
const req = reqs.find(r => r.type === "uv" && r.accessorIndex === primitive.attributes.TEXCOORD_0);
|
|
3449
3733
|
const accessor = node.structure.json.accessors[primitive.attributes.TEXCOORD_0];
|
|
3450
3734
|
const components = node.structure.getNumComponents(accessor.type);
|
|
3451
3735
|
geometry.setAttribute("uv", new BufferAttribute(req.data, components));
|
|
3452
3736
|
}
|
|
3453
3737
|
if (primitive.indices !== undefined) {
|
|
3454
|
-
const req = reqs.find(
|
|
3738
|
+
const req = reqs.find(r => r.type === "index" && r.accessorIndex === primitive.indices);
|
|
3455
3739
|
geometry.setIndex(new BufferAttribute(req.data, 1));
|
|
3456
3740
|
}
|
|
3457
3741
|
let material;
|
|
@@ -3550,14 +3834,14 @@ class DynamicGltfLoader {
|
|
|
3550
3834
|
} else {
|
|
3551
3835
|
this.scene.remove(node.object);
|
|
3552
3836
|
}
|
|
3553
|
-
node.object.traverse(
|
|
3837
|
+
node.object.traverse(child => {
|
|
3554
3838
|
if (child.geometry) {
|
|
3555
3839
|
const geometrySize = this.geometryCache.get(child.geometry.uuid) || 0;
|
|
3556
3840
|
this.currentMemoryUsage -= geometrySize;
|
|
3557
3841
|
this.geometryCache.delete(child.geometry.uuid);
|
|
3558
3842
|
child.geometry.dispose();
|
|
3559
3843
|
}
|
|
3560
|
-
})
|
|
3844
|
+
});
|
|
3561
3845
|
node.object = null;
|
|
3562
3846
|
node.loaded = false;
|
|
3563
3847
|
this.updateMemoryIndicator();
|
|
@@ -3566,7 +3850,7 @@ class DynamicGltfLoader {
|
|
|
3566
3850
|
}
|
|
3567
3851
|
checkDistances() {
|
|
3568
3852
|
const cameraPosition = this.camera.position;
|
|
3569
|
-
this.nodes.forEach((
|
|
3853
|
+
this.nodes.forEach((node, nodeId) => {
|
|
3570
3854
|
const distance = cameraPosition.distanceTo(node.position);
|
|
3571
3855
|
if (node.loaded) {
|
|
3572
3856
|
if (distance > this.unloadDistance) {
|
|
@@ -3577,7 +3861,7 @@ class DynamicGltfLoader {
|
|
|
3577
3861
|
this.loadNode(nodeId);
|
|
3578
3862
|
}
|
|
3579
3863
|
}
|
|
3580
|
-
})
|
|
3864
|
+
});
|
|
3581
3865
|
}
|
|
3582
3866
|
async loadStructure(structures) {
|
|
3583
3867
|
this.clear();
|
|
@@ -3620,7 +3904,7 @@ class DynamicGltfLoader {
|
|
|
3620
3904
|
}
|
|
3621
3905
|
}
|
|
3622
3906
|
const ignoreEdges = estimatedSize * 2 > this.memoryLimit;
|
|
3623
|
-
this.nodesToLoad.sort((
|
|
3907
|
+
this.nodesToLoad.sort((a, b) => {
|
|
3624
3908
|
const nodeA = this.nodes.get(a);
|
|
3625
3909
|
const nodeB = this.nodes.get(b);
|
|
3626
3910
|
if (!nodeA?.geometryExtents || !nodeB?.geometryExtents) {
|
|
@@ -3631,16 +3915,16 @@ class DynamicGltfLoader {
|
|
|
3631
3915
|
const volumeA = sizeA.x * sizeA.y * sizeA.z;
|
|
3632
3916
|
const volumeB = sizeB.x * sizeB.y * sizeB.z;
|
|
3633
3917
|
return volumeB - volumeA;
|
|
3634
|
-
})
|
|
3918
|
+
});
|
|
3635
3919
|
if (!ignoreEdges && this.visibleEdges) {
|
|
3636
3920
|
this.nodesToLoad.push(...this.edgeNodes);
|
|
3637
3921
|
}
|
|
3638
3922
|
this.dispatchEvent("databasechunk", {
|
|
3639
3923
|
totalNodes: this.nodesToLoad.length,
|
|
3640
|
-
structures: this.structures.map(
|
|
3924
|
+
structures: this.structures.map(s => ({
|
|
3641
3925
|
id: s.id,
|
|
3642
|
-
nodeCount: this.nodesToLoad.filter(
|
|
3643
|
-
}))
|
|
3926
|
+
nodeCount: this.nodesToLoad.filter(nodeId => nodeId.startsWith(s.id)).length
|
|
3927
|
+
}))
|
|
3644
3928
|
});
|
|
3645
3929
|
}
|
|
3646
3930
|
async processNodeHierarchy(structure, nodeId, parentGroup) {
|
|
@@ -3760,9 +4044,9 @@ class DynamicGltfLoader {
|
|
|
3760
4044
|
this.dispatchEvent("update");
|
|
3761
4045
|
this.lastUpdateTime = currentTime;
|
|
3762
4046
|
}
|
|
3763
|
-
await new Promise(
|
|
4047
|
+
await new Promise(resolve => {
|
|
3764
4048
|
setTimeout(resolve, 0);
|
|
3765
|
-
})
|
|
4049
|
+
});
|
|
3766
4050
|
}
|
|
3767
4051
|
};
|
|
3768
4052
|
try {
|
|
@@ -3807,12 +4091,12 @@ class DynamicGltfLoader {
|
|
|
3807
4091
|
console.timeEnd("optimize scene");
|
|
3808
4092
|
}
|
|
3809
4093
|
cleanupPartialLoad() {
|
|
3810
|
-
this.nodesToLoad.forEach(
|
|
4094
|
+
this.nodesToLoad.forEach(nodeId => {
|
|
3811
4095
|
const node = this.nodes.get(nodeId);
|
|
3812
4096
|
if (node && node.loading) {
|
|
3813
4097
|
this.unloadNode(nodeId);
|
|
3814
4098
|
}
|
|
3815
|
-
})
|
|
4099
|
+
});
|
|
3816
4100
|
}
|
|
3817
4101
|
createDefaultMaterial(primitiveMode = undefined) {
|
|
3818
4102
|
if (primitiveMode === GL_CONSTANTS.POINTS) {
|
|
@@ -3896,7 +4180,7 @@ class DynamicGltfLoader {
|
|
|
3896
4180
|
this.nodesToLoad = [];
|
|
3897
4181
|
}
|
|
3898
4182
|
removeOptimization() {
|
|
3899
|
-
this.originalObjects.forEach(
|
|
4183
|
+
this.originalObjects.forEach(obj => obj.visible = true);
|
|
3900
4184
|
const disposeMerged = obj => {
|
|
3901
4185
|
if (obj.parent) {
|
|
3902
4186
|
obj.parent.remove(obj);
|
|
@@ -3924,13 +4208,13 @@ class DynamicGltfLoader {
|
|
|
3924
4208
|
}
|
|
3925
4209
|
clear() {
|
|
3926
4210
|
this.chunkQueue = [];
|
|
3927
|
-
this.structures.forEach(
|
|
4211
|
+
this.structures.forEach(structure => {
|
|
3928
4212
|
if (structure) {
|
|
3929
4213
|
structure.clear();
|
|
3930
4214
|
}
|
|
3931
|
-
})
|
|
4215
|
+
});
|
|
3932
4216
|
this.structures = [];
|
|
3933
|
-
this.nodes.forEach(
|
|
4217
|
+
this.nodes.forEach(node => {
|
|
3934
4218
|
if (node.object) {
|
|
3935
4219
|
if (node.object.parent) {
|
|
3936
4220
|
node.object.parent.remove(node.object);
|
|
@@ -3940,72 +4224,72 @@ class DynamicGltfLoader {
|
|
|
3940
4224
|
}
|
|
3941
4225
|
if (node.object.material) {
|
|
3942
4226
|
if (Array.isArray(node.object.material)) {
|
|
3943
|
-
node.object.material.forEach(
|
|
4227
|
+
node.object.material.forEach(material => material.dispose());
|
|
3944
4228
|
} else {
|
|
3945
4229
|
node.object.material.dispose();
|
|
3946
4230
|
}
|
|
3947
4231
|
}
|
|
3948
4232
|
}
|
|
3949
|
-
})
|
|
4233
|
+
});
|
|
3950
4234
|
this.nodes.clear();
|
|
3951
|
-
this.loadedMeshes.forEach(
|
|
4235
|
+
this.loadedMeshes.forEach(mesh => {
|
|
3952
4236
|
if (mesh.geometry) mesh.geometry.dispose();
|
|
3953
4237
|
if (mesh.material) {
|
|
3954
4238
|
if (Array.isArray(mesh.material)) {
|
|
3955
|
-
mesh.material.forEach(
|
|
4239
|
+
mesh.material.forEach(material => material.dispose());
|
|
3956
4240
|
} else {
|
|
3957
4241
|
mesh.material.dispose();
|
|
3958
4242
|
}
|
|
3959
4243
|
}
|
|
3960
|
-
})
|
|
4244
|
+
});
|
|
3961
4245
|
this.loadedMeshes.clear();
|
|
3962
|
-
this.structureRoots.forEach(
|
|
4246
|
+
this.structureRoots.forEach(rootGroup => {
|
|
3963
4247
|
if (rootGroup) {
|
|
3964
|
-
rootGroup.traverse(
|
|
4248
|
+
rootGroup.traverse(child => {
|
|
3965
4249
|
if (child.geometry) child.geometry.dispose();
|
|
3966
4250
|
if (child.material) {
|
|
3967
4251
|
if (Array.isArray(child.material)) {
|
|
3968
|
-
child.material.forEach(
|
|
4252
|
+
child.material.forEach(material => material.dispose());
|
|
3969
4253
|
} else {
|
|
3970
4254
|
child.material.dispose();
|
|
3971
4255
|
}
|
|
3972
4256
|
}
|
|
3973
|
-
})
|
|
4257
|
+
});
|
|
3974
4258
|
if (rootGroup.parent) {
|
|
3975
4259
|
rootGroup.parent.remove(rootGroup);
|
|
3976
4260
|
}
|
|
3977
4261
|
}
|
|
3978
|
-
})
|
|
4262
|
+
});
|
|
3979
4263
|
this.structureRoots.clear();
|
|
3980
|
-
this.mergedMesh.forEach(
|
|
4264
|
+
this.mergedMesh.forEach(mesh => {
|
|
3981
4265
|
if (mesh.geometry) mesh.geometry.dispose();
|
|
3982
4266
|
if (mesh.material) {
|
|
3983
4267
|
if (Array.isArray(mesh.material)) {
|
|
3984
|
-
mesh.material.forEach(
|
|
4268
|
+
mesh.material.forEach(material => material.dispose());
|
|
3985
4269
|
} else {
|
|
3986
4270
|
mesh.material.dispose();
|
|
3987
4271
|
}
|
|
3988
4272
|
}
|
|
3989
4273
|
if (mesh.parent) mesh.parent.remove(mesh);
|
|
3990
|
-
})
|
|
4274
|
+
});
|
|
3991
4275
|
this.mergedMesh.clear();
|
|
3992
|
-
this.mergedLines.forEach(
|
|
4276
|
+
this.mergedLines.forEach(line => {
|
|
3993
4277
|
if (line.geometry) line.geometry.dispose();
|
|
3994
4278
|
if (line.material) line.material.dispose();
|
|
3995
4279
|
if (line.parent) line.parent.remove(line);
|
|
3996
|
-
})
|
|
4280
|
+
});
|
|
3997
4281
|
this.mergedLines.clear();
|
|
3998
|
-
this.mergedLineSegments.forEach(
|
|
4282
|
+
this.mergedLineSegments.forEach(lineSegment => {
|
|
3999
4283
|
if (lineSegment.geometry) lineSegment.geometry.dispose();
|
|
4000
4284
|
if (lineSegment.material) lineSegment.material.dispose();
|
|
4001
4285
|
if (lineSegment.parent) lineSegment.parent.remove(lineSegment);
|
|
4002
|
-
})
|
|
4286
|
+
});
|
|
4003
4287
|
this.mergedLineSegments.clear();
|
|
4004
|
-
this.mergedPoints.forEach(
|
|
4288
|
+
this.mergedPoints.forEach(points => {
|
|
4005
4289
|
if (points.geometry) points.geometry.dispose();
|
|
4006
4290
|
if (points.material) points.material.dispose();
|
|
4007
4291
|
if (points.parent) points.parent.remove(points);
|
|
4008
|
-
})
|
|
4292
|
+
});
|
|
4009
4293
|
this.mergedPoints.clear();
|
|
4010
4294
|
this.geometryCache.clear();
|
|
4011
4295
|
this.materialCache.clear();
|
|
@@ -4047,12 +4331,12 @@ class DynamicGltfLoader {
|
|
|
4047
4331
|
}
|
|
4048
4332
|
removeEventListener(event, handler) {
|
|
4049
4333
|
if (this.eventHandlers[event]) {
|
|
4050
|
-
this.eventHandlers[event] = this.eventHandlers[event].filter(
|
|
4334
|
+
this.eventHandlers[event] = this.eventHandlers[event].filter(h => h !== handler);
|
|
4051
4335
|
}
|
|
4052
4336
|
}
|
|
4053
4337
|
dispatchEvent(event, data) {
|
|
4054
4338
|
if (this.eventHandlers[event]) {
|
|
4055
|
-
this.eventHandlers[event].forEach(
|
|
4339
|
+
this.eventHandlers[event].forEach(handler => handler(data));
|
|
4056
4340
|
}
|
|
4057
4341
|
}
|
|
4058
4342
|
registerObjectWithHandle(object, handle) {
|
|
@@ -4071,9 +4355,9 @@ class DynamicGltfLoader {
|
|
|
4071
4355
|
getHandlesByObjects(objects) {
|
|
4072
4356
|
if (!objects.length) return [];
|
|
4073
4357
|
const handles = new Set;
|
|
4074
|
-
objects.forEach(
|
|
4358
|
+
objects.forEach(obj => {
|
|
4075
4359
|
if (this.originalObjects.has(obj)) handles.add(obj.userData.handle);
|
|
4076
|
-
})
|
|
4360
|
+
});
|
|
4077
4361
|
return Array.from(handles);
|
|
4078
4362
|
}
|
|
4079
4363
|
getMaterialId(material, index) {
|
|
@@ -4129,7 +4413,7 @@ class DynamicGltfLoader {
|
|
|
4129
4413
|
this.originalObjects.clear();
|
|
4130
4414
|
this.originalObjectsToSelection.clear();
|
|
4131
4415
|
const structureGroups = new Map;
|
|
4132
|
-
this.scene.traverse(
|
|
4416
|
+
this.scene.traverse(object => {
|
|
4133
4417
|
if (object.userData.structureId) {
|
|
4134
4418
|
const structureId = object.userData.structureId;
|
|
4135
4419
|
if (!structureGroups.has(structureId)) {
|
|
@@ -4156,7 +4440,7 @@ class DynamicGltfLoader {
|
|
|
4156
4440
|
this.addToMaterialGroup(object, group.mapPoints, group.points);
|
|
4157
4441
|
}
|
|
4158
4442
|
}
|
|
4159
|
-
})
|
|
4443
|
+
});
|
|
4160
4444
|
for (const group of structureGroups.values()) {
|
|
4161
4445
|
group.mapMeshes.clear();
|
|
4162
4446
|
group.mapLines.clear();
|
|
@@ -4167,12 +4451,12 @@ class DynamicGltfLoader {
|
|
|
4167
4451
|
this.mergeLineSegmentGroups(group.lineSegments, group.rootGroup);
|
|
4168
4452
|
this.mergePointsGroups(group.points, group.rootGroup);
|
|
4169
4453
|
}
|
|
4170
|
-
this.originalObjects.forEach(
|
|
4454
|
+
this.originalObjects.forEach(obj => {
|
|
4171
4455
|
obj.visible = false;
|
|
4172
4456
|
if (!(obj instanceof Points) && !obj.userData.isEdge) {
|
|
4173
4457
|
this.originalObjectsToSelection.add(obj);
|
|
4174
4458
|
}
|
|
4175
|
-
})
|
|
4459
|
+
});
|
|
4176
4460
|
this.dispatchEvent("update");
|
|
4177
4461
|
}
|
|
4178
4462
|
mergeMeshGroups(materialGroups, rootGroup) {
|
|
@@ -4200,11 +4484,11 @@ class DynamicGltfLoader {
|
|
|
4200
4484
|
this.mergedMesh.add(mergedMesh);
|
|
4201
4485
|
this.optimizedOriginalMap.set(mergedMesh, optimizedObjects);
|
|
4202
4486
|
mergedObjects.push(mergedMesh);
|
|
4203
|
-
geometries.forEach(
|
|
4487
|
+
geometries.forEach(geometry => {
|
|
4204
4488
|
geometry.dispose();
|
|
4205
|
-
})
|
|
4489
|
+
});
|
|
4206
4490
|
}
|
|
4207
|
-
handles.forEach(
|
|
4491
|
+
handles.forEach(handle => {
|
|
4208
4492
|
if (this.handleToOptimizedObjects.has(handle)) {
|
|
4209
4493
|
const existingObjects = this.handleToOptimizedObjects.get(handle);
|
|
4210
4494
|
existingObjects.push(...mergedObjects);
|
|
@@ -4212,12 +4496,12 @@ class DynamicGltfLoader {
|
|
|
4212
4496
|
} else {
|
|
4213
4497
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
4214
4498
|
}
|
|
4215
|
-
})
|
|
4499
|
+
});
|
|
4216
4500
|
} catch (error) {
|
|
4217
4501
|
console.error("Failed to merge meshes for material:", error);
|
|
4218
|
-
group.objects.forEach(
|
|
4502
|
+
group.objects.forEach(mesh => {
|
|
4219
4503
|
mesh.visible = true;
|
|
4220
|
-
})
|
|
4504
|
+
});
|
|
4221
4505
|
}
|
|
4222
4506
|
}
|
|
4223
4507
|
}
|
|
@@ -4226,15 +4510,15 @@ class DynamicGltfLoader {
|
|
|
4226
4510
|
if (group.objects.length === 0) continue;
|
|
4227
4511
|
const handles = new Set;
|
|
4228
4512
|
let totalVertices = 0;
|
|
4229
|
-
group.objects.map(
|
|
4513
|
+
group.objects.map(line => {
|
|
4230
4514
|
handles.add(line.userData.handle);
|
|
4231
4515
|
totalVertices += line.geometry.attributes.position.count;
|
|
4232
|
-
})
|
|
4516
|
+
});
|
|
4233
4517
|
const positions = new Float32Array(totalVertices * 3);
|
|
4234
4518
|
let posOffset = 0;
|
|
4235
4519
|
const indices = [];
|
|
4236
4520
|
let vertexOffset = 0;
|
|
4237
|
-
group.objects.forEach(
|
|
4521
|
+
group.objects.forEach(line => {
|
|
4238
4522
|
const geometry = line.geometry;
|
|
4239
4523
|
const positionAttr = geometry.attributes.position;
|
|
4240
4524
|
const vertexCount = positionAttr.count;
|
|
@@ -4252,7 +4536,7 @@ class DynamicGltfLoader {
|
|
|
4252
4536
|
indices.push(vertexOffset + i, vertexOffset + i + 1);
|
|
4253
4537
|
}
|
|
4254
4538
|
vertexOffset += vertexCount;
|
|
4255
|
-
})
|
|
4539
|
+
});
|
|
4256
4540
|
const geometry = new BufferGeometry;
|
|
4257
4541
|
geometry.setAttribute("position", new BufferAttribute(positions, 3));
|
|
4258
4542
|
geometry.setIndex(indices);
|
|
@@ -4266,7 +4550,7 @@ class DynamicGltfLoader {
|
|
|
4266
4550
|
rootGroup.add(mergedLine);
|
|
4267
4551
|
this.mergedLines.add(mergedLine);
|
|
4268
4552
|
this.optimizedOriginalMap.set(mergedLine, group.objects);
|
|
4269
|
-
handles.forEach(
|
|
4553
|
+
handles.forEach(handle => {
|
|
4270
4554
|
if (this.handleToOptimizedObjects.has(handle)) {
|
|
4271
4555
|
const existingObjects = this.handleToOptimizedObjects.get(handle);
|
|
4272
4556
|
existingObjects.push(...mergedObjects);
|
|
@@ -4274,7 +4558,7 @@ class DynamicGltfLoader {
|
|
|
4274
4558
|
} else {
|
|
4275
4559
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
4276
4560
|
}
|
|
4277
|
-
})
|
|
4561
|
+
});
|
|
4278
4562
|
}
|
|
4279
4563
|
}
|
|
4280
4564
|
mergeLineSegmentGroups(materialGroups, rootGroup) {
|
|
@@ -4302,11 +4586,11 @@ class DynamicGltfLoader {
|
|
|
4302
4586
|
this.mergedLineSegments.add(mergedLine);
|
|
4303
4587
|
this.optimizedOriginalMap.set(mergedLine, optimizedObjects);
|
|
4304
4588
|
mergedObjects.push(mergedLine);
|
|
4305
|
-
geometries.forEach(
|
|
4589
|
+
geometries.forEach(geometry => {
|
|
4306
4590
|
geometry.dispose();
|
|
4307
|
-
})
|
|
4591
|
+
});
|
|
4308
4592
|
}
|
|
4309
|
-
handles.forEach(
|
|
4593
|
+
handles.forEach(handle => {
|
|
4310
4594
|
if (this.handleToOptimizedObjects.has(handle)) {
|
|
4311
4595
|
const existingObjects = this.handleToOptimizedObjects.get(handle);
|
|
4312
4596
|
existingObjects.push(...mergedObjects);
|
|
@@ -4314,12 +4598,12 @@ class DynamicGltfLoader {
|
|
|
4314
4598
|
} else {
|
|
4315
4599
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
4316
4600
|
}
|
|
4317
|
-
})
|
|
4601
|
+
});
|
|
4318
4602
|
} catch (error) {
|
|
4319
4603
|
console.warn("Failed to merge line segments for material:", error);
|
|
4320
|
-
group.objects.forEach(
|
|
4604
|
+
group.objects.forEach(line => {
|
|
4321
4605
|
line.visible = true;
|
|
4322
|
-
})
|
|
4606
|
+
});
|
|
4323
4607
|
}
|
|
4324
4608
|
}
|
|
4325
4609
|
}
|
|
@@ -4348,11 +4632,11 @@ class DynamicGltfLoader {
|
|
|
4348
4632
|
this.mergedPoints.add(mergedPoints);
|
|
4349
4633
|
this.optimizedOriginalMap.set(mergedPoints, optimizedObjects);
|
|
4350
4634
|
mergedObjects.push(mergedPoints);
|
|
4351
|
-
geometries.forEach(
|
|
4635
|
+
geometries.forEach(geometry => {
|
|
4352
4636
|
geometry.dispose();
|
|
4353
|
-
})
|
|
4637
|
+
});
|
|
4354
4638
|
}
|
|
4355
|
-
handles.forEach(
|
|
4639
|
+
handles.forEach(handle => {
|
|
4356
4640
|
if (this.handleToOptimizedObjects.has(handle)) {
|
|
4357
4641
|
const existingObjects = this.handleToOptimizedObjects.get(handle);
|
|
4358
4642
|
existingObjects.push(...mergedObjects);
|
|
@@ -4360,22 +4644,22 @@ class DynamicGltfLoader {
|
|
|
4360
4644
|
} else {
|
|
4361
4645
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
4362
4646
|
}
|
|
4363
|
-
})
|
|
4647
|
+
});
|
|
4364
4648
|
} catch (error) {
|
|
4365
4649
|
console.warn("Failed to merge points for material:", error);
|
|
4366
|
-
group.objects.forEach(
|
|
4650
|
+
group.objects.forEach(points => {
|
|
4367
4651
|
points.visible = true;
|
|
4368
|
-
})
|
|
4652
|
+
});
|
|
4369
4653
|
}
|
|
4370
4654
|
}
|
|
4371
4655
|
}
|
|
4372
4656
|
mergeInSingleSegment(structureId, rootGroup) {
|
|
4373
|
-
const lineSegmentsArray = [ ...this.mergedLineSegments, ...this.mergedLines ].filter(
|
|
4657
|
+
const lineSegmentsArray = [ ...this.mergedLineSegments, ...this.mergedLines ].filter(obj => obj.userData.structureId === structureId);
|
|
4374
4658
|
if (lineSegmentsArray.length === 0) return;
|
|
4375
4659
|
try {
|
|
4376
4660
|
const geometriesWithIndex = [];
|
|
4377
|
-
const hasNormals = lineSegmentsArray.some(
|
|
4378
|
-
lineSegmentsArray.forEach(
|
|
4661
|
+
const hasNormals = lineSegmentsArray.some(segment => segment.geometry.attributes.normal !== undefined);
|
|
4662
|
+
lineSegmentsArray.forEach(segment => {
|
|
4379
4663
|
const clonedGeometry = segment.geometry.clone();
|
|
4380
4664
|
segment.updateWorldMatrix(true, false);
|
|
4381
4665
|
clonedGeometry.applyMatrix4(segment.matrixWorld);
|
|
@@ -4401,7 +4685,7 @@ class DynamicGltfLoader {
|
|
|
4401
4685
|
clonedGeometry.setIndex(indices);
|
|
4402
4686
|
}
|
|
4403
4687
|
geometriesWithIndex.push(clonedGeometry);
|
|
4404
|
-
})
|
|
4688
|
+
});
|
|
4405
4689
|
const finalGeometry = mergeGeometries(geometriesWithIndex, false);
|
|
4406
4690
|
const material = new LineBasicMaterial({
|
|
4407
4691
|
vertexColors: true
|
|
@@ -4413,33 +4697,33 @@ class DynamicGltfLoader {
|
|
|
4413
4697
|
mergedLine.userData.structureId = structureId;
|
|
4414
4698
|
rootGroup.add(mergedLine);
|
|
4415
4699
|
this.mergedLineSegments.add(mergedLine);
|
|
4416
|
-
lineSegmentsArray.forEach(
|
|
4700
|
+
lineSegmentsArray.forEach(obj => {
|
|
4417
4701
|
if (obj.parent) {
|
|
4418
4702
|
obj.parent.remove(obj);
|
|
4419
4703
|
}
|
|
4420
4704
|
obj.geometry.dispose();
|
|
4421
|
-
})
|
|
4705
|
+
});
|
|
4422
4706
|
} catch (error) {
|
|
4423
4707
|
console.error("Failed to merge geometries:", error);
|
|
4424
|
-
lineSegmentsArray.forEach(
|
|
4708
|
+
lineSegmentsArray.forEach(obj => {
|
|
4425
4709
|
obj.visible = true;
|
|
4426
4710
|
rootGroup.add(obj);
|
|
4427
|
-
})
|
|
4711
|
+
});
|
|
4428
4712
|
}
|
|
4429
4713
|
}
|
|
4430
4714
|
showOriginalObjects(objects) {
|
|
4431
|
-
objects.forEach(
|
|
4715
|
+
objects.forEach(obj => {
|
|
4432
4716
|
if (this.originalObjects.has(obj)) {
|
|
4433
4717
|
obj.visible = true;
|
|
4434
4718
|
}
|
|
4435
|
-
})
|
|
4719
|
+
});
|
|
4436
4720
|
}
|
|
4437
4721
|
hideOriginalObjects(objects) {
|
|
4438
|
-
objects.forEach(
|
|
4722
|
+
objects.forEach(obj => {
|
|
4439
4723
|
if (this.originalObjects.has(obj)) {
|
|
4440
4724
|
obj.visible = false;
|
|
4441
4725
|
}
|
|
4442
|
-
})
|
|
4726
|
+
});
|
|
4443
4727
|
}
|
|
4444
4728
|
createVAO(geometry) {
|
|
4445
4729
|
if (!this.useVAO) {
|
|
@@ -4494,15 +4778,15 @@ class DynamicGltfLoader {
|
|
|
4494
4778
|
this.syncHiddenObjects();
|
|
4495
4779
|
}
|
|
4496
4780
|
hideObjects(handles) {
|
|
4497
|
-
handles.forEach(
|
|
4781
|
+
handles.forEach(handle => {
|
|
4498
4782
|
this.hiddenHandles.add(handle);
|
|
4499
|
-
})
|
|
4783
|
+
});
|
|
4500
4784
|
this.syncHiddenObjects();
|
|
4501
4785
|
}
|
|
4502
4786
|
showObjects(handles) {
|
|
4503
|
-
handles.forEach(
|
|
4787
|
+
handles.forEach(handle => {
|
|
4504
4788
|
this.hiddenHandles.delete(handle);
|
|
4505
|
-
})
|
|
4789
|
+
});
|
|
4506
4790
|
this.syncHiddenObjects();
|
|
4507
4791
|
}
|
|
4508
4792
|
syncHiddenObjects() {
|
|
@@ -4523,47 +4807,47 @@ class DynamicGltfLoader {
|
|
|
4523
4807
|
if (this.hiddenHandles.size === 0) {
|
|
4524
4808
|
return;
|
|
4525
4809
|
}
|
|
4526
|
-
this.hiddenHandles.forEach(
|
|
4810
|
+
this.hiddenHandles.forEach(handle => {
|
|
4527
4811
|
const objects = this.handleToOptimizedObjects.get(handle);
|
|
4528
4812
|
if (objects) {
|
|
4529
|
-
objects.forEach(
|
|
4813
|
+
objects.forEach(x => this.oldOptimizeObjects.add(x));
|
|
4530
4814
|
}
|
|
4531
|
-
})
|
|
4532
|
-
this.oldOptimizeObjects.forEach(
|
|
4815
|
+
});
|
|
4816
|
+
this.oldOptimizeObjects.forEach(optimizedObject => {
|
|
4533
4817
|
optimizedObject.visible = false;
|
|
4534
4818
|
const originObjects = this.optimizedOriginalMap.get(optimizedObject);
|
|
4535
4819
|
const updateListToOptimize = [];
|
|
4536
|
-
originObjects.forEach(
|
|
4820
|
+
originObjects.forEach(obj => {
|
|
4537
4821
|
if (!this.hiddenHandles.has(obj.userData.handle)) {
|
|
4538
4822
|
updateListToOptimize.push(obj);
|
|
4539
4823
|
}
|
|
4540
|
-
})
|
|
4824
|
+
});
|
|
4541
4825
|
const firstObject = updateListToOptimize[0];
|
|
4542
4826
|
if (firstObject instanceof Mesh || firstObject instanceof LineSegments) {
|
|
4543
|
-
const geometries = updateListToOptimize.map(
|
|
4827
|
+
const geometries = updateListToOptimize.map(obj => {
|
|
4544
4828
|
const geometry = obj.geometry.clone();
|
|
4545
4829
|
obj.updateWorldMatrix(true, false);
|
|
4546
4830
|
geometry.applyMatrix4(obj.matrixWorld);
|
|
4547
4831
|
return geometry;
|
|
4548
|
-
})
|
|
4832
|
+
});
|
|
4549
4833
|
const newMergedGeometry = mergeGeometries(geometries);
|
|
4550
4834
|
const mergedObject = firstObject instanceof Mesh ? new Mesh(newMergedGeometry, optimizedObject.material) : new LineSegments(newMergedGeometry, optimizedObject.material);
|
|
4551
4835
|
mergedObject.visible = true;
|
|
4552
4836
|
optimizedObject.parent.add(mergedObject);
|
|
4553
4837
|
this.newOptimizedObjects.add(mergedObject);
|
|
4554
|
-
geometries.forEach(
|
|
4838
|
+
geometries.forEach(geometry => {
|
|
4555
4839
|
geometry.dispose();
|
|
4556
|
-
})
|
|
4840
|
+
});
|
|
4557
4841
|
} else if (firstObject instanceof Line) {
|
|
4558
4842
|
let totalVertices = 0;
|
|
4559
|
-
updateListToOptimize.map(
|
|
4843
|
+
updateListToOptimize.map(line => {
|
|
4560
4844
|
totalVertices += line.geometry.attributes.position.count;
|
|
4561
|
-
})
|
|
4845
|
+
});
|
|
4562
4846
|
const positions = new Float32Array(totalVertices * 3);
|
|
4563
4847
|
let posOffset = 0;
|
|
4564
4848
|
const indices = [];
|
|
4565
4849
|
let vertexOffset = 0;
|
|
4566
|
-
updateListToOptimize.forEach(
|
|
4850
|
+
updateListToOptimize.forEach(line => {
|
|
4567
4851
|
const geometry = line.geometry;
|
|
4568
4852
|
const positionAttr = geometry.attributes.position;
|
|
4569
4853
|
const vertexCount = positionAttr.count;
|
|
@@ -4581,7 +4865,7 @@ class DynamicGltfLoader {
|
|
|
4581
4865
|
indices.push(vertexOffset + i, vertexOffset + i + 1);
|
|
4582
4866
|
}
|
|
4583
4867
|
vertexOffset += vertexCount;
|
|
4584
|
-
})
|
|
4868
|
+
});
|
|
4585
4869
|
const geometry = new BufferGeometry;
|
|
4586
4870
|
geometry.setAttribute("position", new BufferAttribute(positions, 3));
|
|
4587
4871
|
geometry.setIndex(indices);
|
|
@@ -4592,7 +4876,7 @@ class DynamicGltfLoader {
|
|
|
4592
4876
|
optimizedObject.parent.add(mergedLine);
|
|
4593
4877
|
this.newOptimizedObjects.add(mergedLine);
|
|
4594
4878
|
}
|
|
4595
|
-
})
|
|
4879
|
+
});
|
|
4596
4880
|
}
|
|
4597
4881
|
getStructureGeometryExtent(structureId) {
|
|
4598
4882
|
const extent = new Box3;
|
|
@@ -4623,9 +4907,9 @@ class DynamicGltfLoader {
|
|
|
4623
4907
|
this.activeChunkLoads++;
|
|
4624
4908
|
return Promise.resolve();
|
|
4625
4909
|
}
|
|
4626
|
-
return new Promise(
|
|
4910
|
+
return new Promise(resolve => {
|
|
4627
4911
|
this.chunkQueue.push(resolve);
|
|
4628
|
-
})
|
|
4912
|
+
});
|
|
4629
4913
|
}
|
|
4630
4914
|
releaseChunkSlot() {
|
|
4631
4915
|
this.activeChunkLoads--;
|
|
@@ -4653,7 +4937,7 @@ class GLTFCloudDynamicLoader {
|
|
|
4653
4937
|
this.gltfLoader = new DynamicGltfLoader(this.viewer.camera, scene, this.viewer.renderer);
|
|
4654
4938
|
this.gltfLoader.memoryLimit = this.viewer.options.memoryLimit;
|
|
4655
4939
|
this.gltfLoader.setVisibleEdges(this.viewer.options.edgeModel);
|
|
4656
|
-
this.gltfLoader.addEventListener("databasechunk",
|
|
4940
|
+
this.gltfLoader.addEventListener("databasechunk", data => {
|
|
4657
4941
|
const modelImpl = new DynamicModelImpl(scene);
|
|
4658
4942
|
modelImpl.loader = this;
|
|
4659
4943
|
modelImpl.viewer = this.viewer;
|
|
@@ -4670,8 +4954,8 @@ class GLTFCloudDynamicLoader {
|
|
|
4670
4954
|
file: model.file,
|
|
4671
4955
|
model: model
|
|
4672
4956
|
});
|
|
4673
|
-
})
|
|
4674
|
-
this.gltfLoader.addEventListener("geometryprogress",
|
|
4957
|
+
});
|
|
4958
|
+
this.gltfLoader.addEventListener("geometryprogress", data => {
|
|
4675
4959
|
const progress = data.loaded / data.total;
|
|
4676
4960
|
this.viewer.emitEvent({
|
|
4677
4961
|
type: "geometryprogress",
|
|
@@ -4679,18 +4963,18 @@ class GLTFCloudDynamicLoader {
|
|
|
4679
4963
|
file: model.file,
|
|
4680
4964
|
model: model
|
|
4681
4965
|
});
|
|
4682
|
-
})
|
|
4683
|
-
this.gltfLoader.addEventListener("geometryerror",
|
|
4966
|
+
});
|
|
4967
|
+
this.gltfLoader.addEventListener("geometryerror", data => {
|
|
4684
4968
|
this.viewer.emitEvent({
|
|
4685
4969
|
type: "geometryerror",
|
|
4686
4970
|
data: data,
|
|
4687
4971
|
file: model.file,
|
|
4688
4972
|
model: model
|
|
4689
4973
|
});
|
|
4690
|
-
})
|
|
4691
|
-
this.gltfLoader.addEventListener("update",
|
|
4974
|
+
});
|
|
4975
|
+
this.gltfLoader.addEventListener("update", data => {
|
|
4692
4976
|
this.viewer.update();
|
|
4693
|
-
})
|
|
4977
|
+
});
|
|
4694
4978
|
const loadController = {
|
|
4695
4979
|
loadJson: async () => {
|
|
4696
4980
|
const progress = progress => {
|
|
@@ -4706,11 +4990,11 @@ class GLTFCloudDynamicLoader {
|
|
|
4706
4990
|
return json;
|
|
4707
4991
|
},
|
|
4708
4992
|
loadBinaryData: requests => {
|
|
4709
|
-
const ranges = requests.map(
|
|
4993
|
+
const ranges = requests.map(request => ({
|
|
4710
4994
|
begin: request.offset,
|
|
4711
4995
|
end: request.offset + request.length - 1,
|
|
4712
4996
|
requestId: this.requestId++
|
|
4713
|
-
}))
|
|
4997
|
+
}));
|
|
4714
4998
|
return model.downloadResourceRange(model.geometry[0], undefined, ranges, undefined, this.gltfLoader.getAbortController().signal);
|
|
4715
4999
|
},
|
|
4716
5000
|
baseUrl: () => Promise.resolve(`${model.httpClient.serverUrl}${model.path}/`)
|
|
@@ -4727,9 +5011,9 @@ class GLTFCloudDynamicLoader {
|
|
|
4727
5011
|
|
|
4728
5012
|
const loaders = loadersRegistry("threejs");
|
|
4729
5013
|
|
|
4730
|
-
loaders.registerLoader("gltf-file",
|
|
5014
|
+
loaders.registerLoader("gltf-file", viewer => new GLTFFileLoader(viewer));
|
|
4731
5015
|
|
|
4732
|
-
loaders.registerLoader("gltf-cloud",
|
|
5016
|
+
loaders.registerLoader("gltf-cloud", viewer => new GLTFCloudDynamicLoader(viewer));
|
|
4733
5017
|
|
|
4734
5018
|
class SSAARenderPass extends Pass {
|
|
4735
5019
|
constructor(scenes, camera, clearColor = 0, clearAlpha = 0) {
|
|
@@ -4807,7 +5091,7 @@ class SSAARenderPass extends Pass {
|
|
|
4807
5091
|
renderer.setClearColor(this.clearColor, this.clearAlpha);
|
|
4808
5092
|
renderer.setRenderTarget(this._sampleRenderTarget);
|
|
4809
5093
|
renderer.clear();
|
|
4810
|
-
this.scenes.forEach(
|
|
5094
|
+
this.scenes.forEach(scene => renderer.render(scene, this.camera));
|
|
4811
5095
|
renderer.setRenderTarget(this.renderToScreen ? null : writeBuffer);
|
|
4812
5096
|
if (i === 0) {
|
|
4813
5097
|
renderer.setClearColor(0, 0);
|
|
@@ -4859,7 +5143,7 @@ class Viewer extends EventEmitter2 {
|
|
|
4859
5143
|
this.target = new Vector3;
|
|
4860
5144
|
this._activeDragger = null;
|
|
4861
5145
|
this._components = [];
|
|
4862
|
-
this.
|
|
5146
|
+
this._renderTime = 0;
|
|
4863
5147
|
this.render = this.render.bind(this);
|
|
4864
5148
|
this.update = this.update.bind(this);
|
|
4865
5149
|
this._markup = new Markup;
|
|
@@ -4877,7 +5161,7 @@ class Viewer extends EventEmitter2 {
|
|
|
4877
5161
|
return this._markup;
|
|
4878
5162
|
}
|
|
4879
5163
|
initialize(canvas, onProgress) {
|
|
4880
|
-
this.addEventListener("optionschange",
|
|
5164
|
+
this.addEventListener("optionschange", event => this.syncOptions(event.data));
|
|
4881
5165
|
this.scene = new Scene;
|
|
4882
5166
|
this.helpers = new Helpers;
|
|
4883
5167
|
this.target = new Vector3(0, 0, 0);
|
|
@@ -4917,16 +5201,17 @@ class Viewer extends EventEmitter2 {
|
|
|
4917
5201
|
this.composer.addPass(this.fxaaPass);
|
|
4918
5202
|
this.composer.addPass(this.ssaaRenderPass);
|
|
4919
5203
|
this.composer.addPass(this.outputPass);
|
|
5204
|
+
this.composer.setSize(width, height);
|
|
4920
5205
|
this.canvas = canvas;
|
|
4921
|
-
this.canvasEvents.forEach(
|
|
5206
|
+
this.canvasEvents.forEach(x => canvas.addEventListener(x, this.canvaseventlistener));
|
|
4922
5207
|
this._markup.initialize(this.canvas, this.canvasEvents, this, this);
|
|
4923
5208
|
for (const name of components.getComponents().keys()) {
|
|
4924
5209
|
this._components.push(components.createComponent(name, this));
|
|
4925
5210
|
}
|
|
4926
5211
|
this.syncOptions();
|
|
4927
5212
|
this.syncOverlay();
|
|
4928
|
-
this.
|
|
4929
|
-
this.render(this.
|
|
5213
|
+
this._renderTime = performance.now();
|
|
5214
|
+
this.render(this._renderTime);
|
|
4930
5215
|
if (typeof onProgress === "function") onProgress(new ProgressEvent("progress", {
|
|
4931
5216
|
lengthComputable: true,
|
|
4932
5217
|
loaded: 1,
|
|
@@ -4951,11 +5236,11 @@ class Viewer extends EventEmitter2 {
|
|
|
4951
5236
|
});
|
|
4952
5237
|
this.removeAllListeners();
|
|
4953
5238
|
this.setActiveDragger();
|
|
4954
|
-
this._components.forEach(
|
|
5239
|
+
this._components.forEach(component => component.dispose());
|
|
4955
5240
|
this._components = [];
|
|
4956
5241
|
this._markup.dispose();
|
|
4957
5242
|
if (this.canvas) {
|
|
4958
|
-
this.canvasEvents.forEach(
|
|
5243
|
+
this.canvasEvents.forEach(x => this.canvas.removeEventListener(x, this.canvaseventlistener));
|
|
4959
5244
|
this.canvas = undefined;
|
|
4960
5245
|
}
|
|
4961
5246
|
if (this.composer) this.composer.dispose();
|
|
@@ -4982,8 +5267,30 @@ class Viewer extends EventEmitter2 {
|
|
|
4982
5267
|
isInitialized() {
|
|
4983
5268
|
return !!this.renderer;
|
|
4984
5269
|
}
|
|
5270
|
+
setSize(width, height, updateStyle = true) {
|
|
5271
|
+
if (!this.renderer) return;
|
|
5272
|
+
const camera = this.camera;
|
|
5273
|
+
const aspect = width / height;
|
|
5274
|
+
if (camera.isPerspectiveCamera) {
|
|
5275
|
+
camera.aspect = aspect;
|
|
5276
|
+
camera.updateProjectionMatrix();
|
|
5277
|
+
}
|
|
5278
|
+
if (camera.isOrthographicCamera) {
|
|
5279
|
+
camera.left = camera.bottom * aspect;
|
|
5280
|
+
camera.right = camera.top * aspect;
|
|
5281
|
+
camera.updateProjectionMatrix();
|
|
5282
|
+
}
|
|
5283
|
+
this.renderer.setSize(width, height, updateStyle);
|
|
5284
|
+
this.composer.setSize(width, height);
|
|
5285
|
+
this.update(true);
|
|
5286
|
+
this.emitEvent({
|
|
5287
|
+
type: "resize",
|
|
5288
|
+
width: width,
|
|
5289
|
+
height: height
|
|
5290
|
+
});
|
|
5291
|
+
}
|
|
4985
5292
|
update(force = false) {
|
|
4986
|
-
this.
|
|
5293
|
+
this._renderNeeded = true;
|
|
4987
5294
|
if (force) this.render();
|
|
4988
5295
|
this.emitEvent({
|
|
4989
5296
|
type: "update",
|
|
@@ -4993,18 +5300,18 @@ class Viewer extends EventEmitter2 {
|
|
|
4993
5300
|
render(time, force = false) {
|
|
4994
5301
|
var _a, _b;
|
|
4995
5302
|
if (!this.renderer) return;
|
|
4996
|
-
if (!
|
|
5303
|
+
if (!this._renderNeeded && !force) return;
|
|
4997
5304
|
if (!time) time = performance.now();
|
|
4998
|
-
const deltaTime = (time - this.
|
|
4999
|
-
this.
|
|
5000
|
-
this.
|
|
5305
|
+
const deltaTime = (time - this._renderTime) / 1e3;
|
|
5306
|
+
this._renderTime = time;
|
|
5307
|
+
this._renderNeeded = false;
|
|
5001
5308
|
if (this.options.antialiasing === true || this.options.antialiasing === "msaa") {
|
|
5002
5309
|
this.renderer.render(this.scene, this.camera);
|
|
5003
5310
|
this.renderer.render(this.helpers, this.camera);
|
|
5004
5311
|
} else {
|
|
5005
5312
|
this.composer.render(deltaTime);
|
|
5006
5313
|
}
|
|
5007
|
-
(_b = (_a = this._activeDragger) === null || _a ===
|
|
5314
|
+
(_b = (_a = this._activeDragger) === null || _a === void 0 ? void 0 : _a.updatePreview) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
5008
5315
|
this.emitEvent({
|
|
5009
5316
|
type: "render",
|
|
5010
5317
|
time: time,
|
|
@@ -5027,7 +5334,7 @@ class Viewer extends EventEmitter2 {
|
|
|
5027
5334
|
let model = file;
|
|
5028
5335
|
if (model && typeof model.getModels === "function") {
|
|
5029
5336
|
const models = await model.getModels();
|
|
5030
|
-
model = models.find(
|
|
5337
|
+
model = models.find(model => model.default) || models[0] || file;
|
|
5031
5338
|
}
|
|
5032
5339
|
if (!model) throw new Error(`Format not supported`);
|
|
5033
5340
|
let format = params.format;
|
|
@@ -5079,7 +5386,7 @@ class Viewer extends EventEmitter2 {
|
|
|
5079
5386
|
});
|
|
5080
5387
|
}
|
|
5081
5388
|
cancel() {
|
|
5082
|
-
this.loaders.forEach(
|
|
5389
|
+
this.loaders.forEach(loader => loader.cancel());
|
|
5083
5390
|
this.emitEvent({
|
|
5084
5391
|
type: "cancel"
|
|
5085
5392
|
});
|
|
@@ -5091,9 +5398,9 @@ class Viewer extends EventEmitter2 {
|
|
|
5091
5398
|
this.clearSlices();
|
|
5092
5399
|
this.clearOverlay();
|
|
5093
5400
|
this.clearSelected();
|
|
5094
|
-
this.loaders.forEach(
|
|
5401
|
+
this.loaders.forEach(loader => loader.dispose());
|
|
5095
5402
|
this.loaders = [];
|
|
5096
|
-
this.models.forEach(
|
|
5403
|
+
this.models.forEach(model => model.dispose());
|
|
5097
5404
|
this.models = [];
|
|
5098
5405
|
this.scene.clear();
|
|
5099
5406
|
this.helpers.clear();
|
|
@@ -5169,7 +5476,7 @@ class Viewer extends EventEmitter2 {
|
|
|
5169
5476
|
newDragger = draggers.createDragger(name, this);
|
|
5170
5477
|
if (newDragger) {
|
|
5171
5478
|
this._activeDragger = newDragger;
|
|
5172
|
-
(_b = (_a = this._activeDragger).initialize) === null || _b ===
|
|
5479
|
+
(_b = (_a = this._activeDragger).initialize) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
5173
5480
|
}
|
|
5174
5481
|
}
|
|
5175
5482
|
const canvas = this.canvas;
|
|
@@ -5193,7 +5500,7 @@ class Viewer extends EventEmitter2 {
|
|
|
5193
5500
|
}
|
|
5194
5501
|
}
|
|
5195
5502
|
getComponent(name) {
|
|
5196
|
-
return this._components.find(
|
|
5503
|
+
return this._components.find(component => component.name === name);
|
|
5197
5504
|
}
|
|
5198
5505
|
is3D() {
|
|
5199
5506
|
return true;
|
|
@@ -5290,16 +5597,16 @@ class Viewer extends EventEmitter2 {
|
|
|
5290
5597
|
}
|
|
5291
5598
|
};
|
|
5292
5599
|
const setClippingPlanes = clipping_planes => {
|
|
5293
|
-
clipping_planes === null || clipping_planes ===
|
|
5600
|
+
clipping_planes === null || clipping_planes === void 0 ? void 0 : clipping_planes.forEach(clipping_plane => {
|
|
5294
5601
|
const plane = new Plane;
|
|
5295
5602
|
plane.setFromNormalAndCoplanarPoint(getVector3FromPoint3d(clipping_plane.direction), getVector3FromPoint3d(clipping_plane.location));
|
|
5296
5603
|
this.renderer.clippingPlanes.push(plane);
|
|
5297
|
-
})
|
|
5604
|
+
});
|
|
5298
5605
|
};
|
|
5299
5606
|
const setSelection = selection => {
|
|
5300
|
-
if (selection) this.setSelected(selection.map(
|
|
5607
|
+
if (selection) this.setSelected(selection.map(component => component.handle));
|
|
5301
5608
|
};
|
|
5302
|
-
const draggerName = (_a = this._activeDragger) === null || _a ===
|
|
5609
|
+
const draggerName = (_a = this._activeDragger) === null || _a === void 0 ? void 0 : _a.name;
|
|
5303
5610
|
this.setActiveDragger();
|
|
5304
5611
|
this.clearSlices();
|
|
5305
5612
|
this.clearOverlay();
|
|
@@ -5311,7 +5618,7 @@ class Viewer extends EventEmitter2 {
|
|
|
5311
5618
|
setClippingPlanes(viewpoint.clipping_planes);
|
|
5312
5619
|
setSelection(viewpoint.selection);
|
|
5313
5620
|
this._markup.setViewpoint(viewpoint);
|
|
5314
|
-
this.target = getVector3FromPoint3d((_c = (_b = viewpoint.custom_fields) === null || _b ===
|
|
5621
|
+
this.target = getVector3FromPoint3d((_c = (_b = viewpoint.custom_fields) === null || _b === void 0 ? void 0 : _b.camera_target) !== null && _c !== void 0 ? _c : this.target);
|
|
5315
5622
|
this.setActiveDragger(draggerName);
|
|
5316
5623
|
this.emitEvent({
|
|
5317
5624
|
type: "drawviewpoint",
|
|
@@ -5346,18 +5653,18 @@ class Viewer extends EventEmitter2 {
|
|
|
5346
5653
|
};
|
|
5347
5654
|
const getClippingPlanes = () => {
|
|
5348
5655
|
const clipping_planes = [];
|
|
5349
|
-
this.renderer.clippingPlanes.forEach(
|
|
5656
|
+
this.renderer.clippingPlanes.forEach(plane => {
|
|
5350
5657
|
const clipping_plane = {
|
|
5351
5658
|
location: getPoint3dFromVector3(plane.coplanarPoint(new Vector3)),
|
|
5352
5659
|
direction: getPoint3dFromVector3(plane.normal)
|
|
5353
5660
|
};
|
|
5354
5661
|
clipping_planes.push(clipping_plane);
|
|
5355
|
-
})
|
|
5662
|
+
});
|
|
5356
5663
|
return clipping_planes;
|
|
5357
5664
|
};
|
|
5358
|
-
const getSelection = () => this.getSelected().map(
|
|
5665
|
+
const getSelection = () => this.getSelected().map(handle => ({
|
|
5359
5666
|
handle: handle
|
|
5360
|
-
}))
|
|
5667
|
+
}));
|
|
5361
5668
|
const viewpoint = {
|
|
5362
5669
|
custom_fields: {}
|
|
5363
5670
|
};
|