@inweb/viewer-visualize 26.9.4 → 26.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/viewer-visualize.js +227 -5
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +227 -5
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Draggers/OdaFlyDragger.d.ts +31 -0
- package/lib/Viewer/Draggers/OdaWalkDragger.d.ts +2 -0
- package/package.json +5 -5
- package/src/Viewer/Draggers/OdaFlyDragger.ts +292 -0
- package/src/Viewer/Draggers/OdaWalkDragger.ts +27 -2
- package/src/Viewer/Draggers/index.ts +2 -0
package/dist/viewer-visualize.js
CHANGED
|
@@ -1258,9 +1258,9 @@
|
|
|
1258
1258
|
}
|
|
1259
1259
|
}
|
|
1260
1260
|
|
|
1261
|
-
const FocalLengthConst = 42.0;
|
|
1262
|
-
const calcFocalLength = (lensLength, fieldWidth, fieldHeight) => {
|
|
1263
|
-
return (lensLength / FocalLengthConst) * Math.sqrt(fieldWidth * fieldWidth + fieldHeight * fieldHeight);
|
|
1261
|
+
const FocalLengthConst$1 = 42.0;
|
|
1262
|
+
const calcFocalLength$1 = (lensLength, fieldWidth, fieldHeight) => {
|
|
1263
|
+
return (lensLength / FocalLengthConst$1) * Math.sqrt(fieldWidth * fieldWidth + fieldHeight * fieldHeight);
|
|
1264
1264
|
};
|
|
1265
1265
|
class OdaWalkDragger extends OdBaseDragger {
|
|
1266
1266
|
constructor(subject) {
|
|
@@ -1371,10 +1371,10 @@
|
|
|
1371
1371
|
for (const keyCode of this.keyPressMap) {
|
|
1372
1372
|
switch (keyCode) {
|
|
1373
1373
|
case "KeyW":
|
|
1374
|
-
this.
|
|
1374
|
+
this.moveForward(currentDelta);
|
|
1375
1375
|
break;
|
|
1376
1376
|
case "KeyS":
|
|
1377
|
-
this.
|
|
1377
|
+
this.moveBackward(currentDelta);
|
|
1378
1378
|
break;
|
|
1379
1379
|
case "KeyA":
|
|
1380
1380
|
this.cameraWalker.moveLeft(currentDelta);
|
|
@@ -1411,6 +1411,27 @@
|
|
|
1411
1411
|
this.subject.emitEvent({ type: "changecamera" });
|
|
1412
1412
|
}
|
|
1413
1413
|
}
|
|
1414
|
+
moveForward(currentDelta) {
|
|
1415
|
+
const { Vector3d } = this.m_module;
|
|
1416
|
+
const camera = this.cameraWalker.camera().openObjectAsCamera();
|
|
1417
|
+
const target = Vector3d.createFromArray(camera.target());
|
|
1418
|
+
const dir = Vector3d.createFromArray(camera.direction());
|
|
1419
|
+
const up = Vector3d.createFromArray(camera.upVector());
|
|
1420
|
+
const pos = Vector3d.createFromArray(camera.position());
|
|
1421
|
+
let move = Vector3d.createFromArray([dir.x, dir.y, 0]);
|
|
1422
|
+
if (Math.abs(dir.x) > 0.001 && Math.abs(dir.y) > 0.001) {
|
|
1423
|
+
move.setToProduct(move.normalize(), currentDelta);
|
|
1424
|
+
}
|
|
1425
|
+
else {
|
|
1426
|
+
move = Vector3d.createFromArray([0, currentDelta, 0]);
|
|
1427
|
+
}
|
|
1428
|
+
let newPos = pos.add(move);
|
|
1429
|
+
let newTarget = target.add(move);
|
|
1430
|
+
camera.setupCamera(newPos.toArray(), newTarget.toArray(), up.toArray());
|
|
1431
|
+
}
|
|
1432
|
+
moveBackward(currentDelta) {
|
|
1433
|
+
this.moveForward(-currentDelta);
|
|
1434
|
+
}
|
|
1414
1435
|
turnLeft(angle) {
|
|
1415
1436
|
const pCamera = this.cameraWalker.camera().openObjectAsCamera();
|
|
1416
1437
|
const dir = this.toVector(pCamera.direction());
|
|
@@ -1424,6 +1445,206 @@
|
|
|
1424
1445
|
pCamera.setupCameraByDirection(pos, dir.toArray(), up.toArray());
|
|
1425
1446
|
pCamera.delete();
|
|
1426
1447
|
}
|
|
1448
|
+
setupCamera(view) {
|
|
1449
|
+
const pCamera = this.cameraId.openObjectAsCamera();
|
|
1450
|
+
const target = view.viewTarget;
|
|
1451
|
+
pCamera.setDisplayGlyph(false);
|
|
1452
|
+
pCamera.setDisplayTarget(false);
|
|
1453
|
+
pCamera.setAutoAdjust(true);
|
|
1454
|
+
pCamera.setupCamera(view.viewPosition, target, view.upVector);
|
|
1455
|
+
pCamera.setNearClip(false, 1.0);
|
|
1456
|
+
pCamera.setFarClip(false, 0);
|
|
1457
|
+
pCamera.setViewParameters(view.viewFieldWidth, view.viewFieldHeight, true);
|
|
1458
|
+
const focalL = calcFocalLength$1(view.lensLength, view.viewFieldWidth, view.viewFieldHeight);
|
|
1459
|
+
const pTarget = this.toPoint(view.viewTarget);
|
|
1460
|
+
const viewDir = this.toPoint(view.viewPosition);
|
|
1461
|
+
const viewDirSub = viewDir.sub(pTarget);
|
|
1462
|
+
const viewDirVec = viewDirSub.asVector();
|
|
1463
|
+
const viewDirVecNormal = viewDirVec.normalize();
|
|
1464
|
+
const geViewDir = this.toGeVector(viewDirVecNormal);
|
|
1465
|
+
const newGeViewDir = [geViewDir[0] * focalL, geViewDir[1] * focalL, geViewDir[2] * focalL];
|
|
1466
|
+
const pTarget2 = this.toPoint(view.viewTarget);
|
|
1467
|
+
const newGeViewDirPt = this.toPoint(newGeViewDir);
|
|
1468
|
+
const newPos = pTarget2.add(newGeViewDirPt);
|
|
1469
|
+
pCamera.setupCamera(this.toGePoint(newPos), view.viewTarget, view.upVector);
|
|
1470
|
+
this.deleteAll([pTarget, viewDir, viewDirSub, viewDirVec, viewDirVecNormal, pTarget2, newGeViewDirPt, newPos]);
|
|
1471
|
+
pCamera.assignView(view);
|
|
1472
|
+
pCamera.delete();
|
|
1473
|
+
}
|
|
1474
|
+
getMaxDimension(view) {
|
|
1475
|
+
const [xmax, ymax, zmax] = view.sceneExtents.max();
|
|
1476
|
+
const [xmin, ymin, zmin] = view.sceneExtents.min();
|
|
1477
|
+
const volume = [xmax - xmin, ymax - ymin, zmax - zmin];
|
|
1478
|
+
return Math.max(...volume);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
const FocalLengthConst = 42.0;
|
|
1483
|
+
const calcFocalLength = (lensLength, fieldWidth, fieldHeight) => {
|
|
1484
|
+
return (lensLength / FocalLengthConst) * Math.sqrt(fieldWidth * fieldWidth + fieldHeight * fieldHeight);
|
|
1485
|
+
};
|
|
1486
|
+
class OdaFlyDragger extends OdBaseDragger {
|
|
1487
|
+
constructor(subject) {
|
|
1488
|
+
super(subject);
|
|
1489
|
+
this.viewer = undefined;
|
|
1490
|
+
this.multiplier = 5;
|
|
1491
|
+
this.speed = 1;
|
|
1492
|
+
this.keyPressMap = new Set();
|
|
1493
|
+
this.keydown = this.keydown.bind(this);
|
|
1494
|
+
this.keyup = this.keyup.bind(this);
|
|
1495
|
+
this.lastFrameTS = 0;
|
|
1496
|
+
this.animationId = undefined;
|
|
1497
|
+
this.processMovement = this.processMovement.bind(this);
|
|
1498
|
+
this.deltaAngle = Math.PI / 3600;
|
|
1499
|
+
this.autoSelect = true;
|
|
1500
|
+
}
|
|
1501
|
+
initialize() {
|
|
1502
|
+
super.initialize();
|
|
1503
|
+
this.viewer = this.getViewer();
|
|
1504
|
+
window.addEventListener("keydown", this.keydown, false);
|
|
1505
|
+
window.addEventListener("keyup", this.keyup, false);
|
|
1506
|
+
this.oldWCSEnableValue = this.viewer.getEnableWCS();
|
|
1507
|
+
this.viewer.setEnableWCS(false);
|
|
1508
|
+
const view = this.viewer.activeView;
|
|
1509
|
+
const maxDimension = this.getMaxDimension(view);
|
|
1510
|
+
this.speed = maxDimension / 30000;
|
|
1511
|
+
this.subject.emitEvent({ type: "flystart" });
|
|
1512
|
+
this.viewParams = this.getViewParams();
|
|
1513
|
+
this.setViewParams(this.viewParams);
|
|
1514
|
+
const model = this.viewer.getActiveModel();
|
|
1515
|
+
this.cameraId = model.appendCamera("Camera0");
|
|
1516
|
+
this.setupCamera(view);
|
|
1517
|
+
model.delete();
|
|
1518
|
+
this.cameraFlyer = new this.m_module.OdTvCameraWalker();
|
|
1519
|
+
this.cameraFlyer.setCamera(this.cameraId);
|
|
1520
|
+
this.subject.update();
|
|
1521
|
+
this.enableZoomWheelPreviousValue = this.subject.options.enableZoomWheel;
|
|
1522
|
+
this.subject.options.enableZoomWheel = false;
|
|
1523
|
+
}
|
|
1524
|
+
dispose() {
|
|
1525
|
+
var _a;
|
|
1526
|
+
this.oldWCSEnableValue =
|
|
1527
|
+
this.oldWCSEnableValue !== undefined ? this.oldWCSEnableValue : this.subject.options.showWCS;
|
|
1528
|
+
this.viewer.setEnableWCS(this.oldWCSEnableValue);
|
|
1529
|
+
super.dispose();
|
|
1530
|
+
this.keyPressMap.clear();
|
|
1531
|
+
window.removeEventListener("keydown", this.keydown);
|
|
1532
|
+
window.removeEventListener("keyup", this.keyup);
|
|
1533
|
+
if (this.animationId) {
|
|
1534
|
+
window.cancelAnimationFrame(this.animationId);
|
|
1535
|
+
this.animationId = undefined;
|
|
1536
|
+
}
|
|
1537
|
+
if (this.cameraId) {
|
|
1538
|
+
const model = this.viewer.getActiveModel();
|
|
1539
|
+
model.removeEntity(this.cameraId);
|
|
1540
|
+
model.delete();
|
|
1541
|
+
(_a = this.cameraFlyer) === null || _a === void 0 ? void 0 : _a.delete();
|
|
1542
|
+
}
|
|
1543
|
+
if (this.viewParams) {
|
|
1544
|
+
this.setViewParams(this.viewParams);
|
|
1545
|
+
const avp = this.viewer.activeView;
|
|
1546
|
+
avp.delete();
|
|
1547
|
+
}
|
|
1548
|
+
this.subject.update(true);
|
|
1549
|
+
this.subject.options.enableZoomWheel = this.enableZoomWheelPreviousValue;
|
|
1550
|
+
}
|
|
1551
|
+
keydown(ev) {
|
|
1552
|
+
switch (ev.code) {
|
|
1553
|
+
case "NumpadSubtract":
|
|
1554
|
+
case "Minus":
|
|
1555
|
+
if (this.multiplier > 1) {
|
|
1556
|
+
this.multiplier = this.multiplier - 1;
|
|
1557
|
+
this.subject.emitEvent({ type: "flyspeedchange", data: this.multiplier });
|
|
1558
|
+
}
|
|
1559
|
+
break;
|
|
1560
|
+
case "NumpadAdd":
|
|
1561
|
+
case "Equal":
|
|
1562
|
+
if (this.multiplier < 10) {
|
|
1563
|
+
this.multiplier = this.multiplier + 1;
|
|
1564
|
+
this.subject.emitEvent({ type: "flyspeedchange", data: this.multiplier });
|
|
1565
|
+
}
|
|
1566
|
+
break;
|
|
1567
|
+
case "KeyW":
|
|
1568
|
+
case "KeyA":
|
|
1569
|
+
case "KeyS":
|
|
1570
|
+
case "KeyD":
|
|
1571
|
+
case "KeyQ":
|
|
1572
|
+
case "KeyE":
|
|
1573
|
+
this.keyPressMap.add(ev.code);
|
|
1574
|
+
if (!this.animationId)
|
|
1575
|
+
this.processMovement(0);
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
keyup(ev) {
|
|
1580
|
+
this.keyPressMap.delete(ev.code);
|
|
1581
|
+
if (this.keyPressMap.size < 1 && this.animationId) {
|
|
1582
|
+
window.cancelAnimationFrame(this.animationId);
|
|
1583
|
+
this.animationId = undefined;
|
|
1584
|
+
this.lastFrameTS = 0;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
processMovement(timestamp) {
|
|
1588
|
+
this.animationId = requestAnimationFrame(this.processMovement);
|
|
1589
|
+
if (this.lastFrameTS !== 0) {
|
|
1590
|
+
const deltaTS = timestamp - this.lastFrameTS;
|
|
1591
|
+
const currentDelta = this.multiplier * deltaTS * this.speed;
|
|
1592
|
+
for (const keyCode of this.keyPressMap) {
|
|
1593
|
+
switch (keyCode) {
|
|
1594
|
+
case "KeyW":
|
|
1595
|
+
this.cameraFlyer.moveForward(currentDelta);
|
|
1596
|
+
break;
|
|
1597
|
+
case "KeyS":
|
|
1598
|
+
this.cameraFlyer.moveBackward(currentDelta);
|
|
1599
|
+
break;
|
|
1600
|
+
case "KeyA":
|
|
1601
|
+
this.cameraFlyer.moveLeft(currentDelta);
|
|
1602
|
+
break;
|
|
1603
|
+
case "KeyD":
|
|
1604
|
+
this.cameraFlyer.moveRight(currentDelta);
|
|
1605
|
+
break;
|
|
1606
|
+
case "KeyQ":
|
|
1607
|
+
this.cameraFlyer.moveUp(currentDelta);
|
|
1608
|
+
break;
|
|
1609
|
+
case "KeyE":
|
|
1610
|
+
this.cameraFlyer.moveDown(currentDelta);
|
|
1611
|
+
break;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
this.subject.update();
|
|
1615
|
+
this.subject.emitEvent({ type: "changecamera" });
|
|
1616
|
+
}
|
|
1617
|
+
this.lastFrameTS = timestamp;
|
|
1618
|
+
}
|
|
1619
|
+
start(x, y) {
|
|
1620
|
+
this.dragPosition = { x, y };
|
|
1621
|
+
}
|
|
1622
|
+
drag(x, y) {
|
|
1623
|
+
if (this.cameraId && this.isDragging) {
|
|
1624
|
+
const dltX = x - this.dragPosition.x;
|
|
1625
|
+
const dltY = y - this.dragPosition.y;
|
|
1626
|
+
this.dragPosition = { x, y };
|
|
1627
|
+
if (dltX !== 0.0)
|
|
1628
|
+
this.turnLeft(-dltX * this.deltaAngle);
|
|
1629
|
+
if (dltY !== 0.0)
|
|
1630
|
+
this.cameraFlyer.turnDown(dltY * this.deltaAngle);
|
|
1631
|
+
this.subject.update();
|
|
1632
|
+
this.subject.emitEvent({ type: "changecamera" });
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
turnLeft(angle) {
|
|
1636
|
+
const pCamera = this.cameraFlyer.camera().openObjectAsCamera();
|
|
1637
|
+
const dir = this.toVector(pCamera.direction());
|
|
1638
|
+
const up = this.toVector(pCamera.upVector());
|
|
1639
|
+
const pos = pCamera.position();
|
|
1640
|
+
const rotMatrix = this.createMatrix3d();
|
|
1641
|
+
const zAxisVector = [0, 0, 1];
|
|
1642
|
+
rotMatrix.setToRotation(angle, zAxisVector, pos);
|
|
1643
|
+
dir.transformBy(rotMatrix);
|
|
1644
|
+
up.transformBy(rotMatrix);
|
|
1645
|
+
pCamera.setupCameraByDirection(pos, dir.toArray(), up.toArray());
|
|
1646
|
+
pCamera.delete();
|
|
1647
|
+
}
|
|
1427
1648
|
setupCamera(view) {
|
|
1428
1649
|
const pCamera = this.cameraId.openObjectAsCamera();
|
|
1429
1650
|
const target = view.viewTarget;
|
|
@@ -2248,6 +2469,7 @@
|
|
|
2248
2469
|
draggers.registerDragger("CuttingPlaneYAxis", (viewer) => new OdCuttingPlaneYAxisDragger(viewer));
|
|
2249
2470
|
draggers.registerDragger("CuttingPlaneZAxis", (viewer) => new OdCuttingPlaneZAxisDragger(viewer));
|
|
2250
2471
|
draggers.registerDragger("Walk", (viewer) => new OdaWalkDragger(viewer));
|
|
2472
|
+
draggers.registerDragger("Fly", (viewer) => new OdaFlyDragger(viewer));
|
|
2251
2473
|
|
|
2252
2474
|
const composeMatrixFromTransform = (transform, modelCenter, visLib) => {
|
|
2253
2475
|
const { translate, scale, rotation } = transform;
|