@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
|
@@ -772,9 +772,9 @@ class MeasureLineDragger extends OdBaseDragger {
|
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
774
|
|
|
775
|
-
const FocalLengthConst = 42.0;
|
|
776
|
-
const calcFocalLength = (lensLength, fieldWidth, fieldHeight) => {
|
|
777
|
-
return (lensLength / FocalLengthConst) * Math.sqrt(fieldWidth * fieldWidth + fieldHeight * fieldHeight);
|
|
775
|
+
const FocalLengthConst$1 = 42.0;
|
|
776
|
+
const calcFocalLength$1 = (lensLength, fieldWidth, fieldHeight) => {
|
|
777
|
+
return (lensLength / FocalLengthConst$1) * Math.sqrt(fieldWidth * fieldWidth + fieldHeight * fieldHeight);
|
|
778
778
|
};
|
|
779
779
|
class OdaWalkDragger extends OdBaseDragger {
|
|
780
780
|
constructor(subject) {
|
|
@@ -885,10 +885,10 @@ class OdaWalkDragger extends OdBaseDragger {
|
|
|
885
885
|
for (const keyCode of this.keyPressMap) {
|
|
886
886
|
switch (keyCode) {
|
|
887
887
|
case "KeyW":
|
|
888
|
-
this.
|
|
888
|
+
this.moveForward(currentDelta);
|
|
889
889
|
break;
|
|
890
890
|
case "KeyS":
|
|
891
|
-
this.
|
|
891
|
+
this.moveBackward(currentDelta);
|
|
892
892
|
break;
|
|
893
893
|
case "KeyA":
|
|
894
894
|
this.cameraWalker.moveLeft(currentDelta);
|
|
@@ -925,6 +925,27 @@ class OdaWalkDragger extends OdBaseDragger {
|
|
|
925
925
|
this.subject.emitEvent({ type: "changecamera" });
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
|
+
moveForward(currentDelta) {
|
|
929
|
+
const { Vector3d } = this.m_module;
|
|
930
|
+
const camera = this.cameraWalker.camera().openObjectAsCamera();
|
|
931
|
+
const target = Vector3d.createFromArray(camera.target());
|
|
932
|
+
const dir = Vector3d.createFromArray(camera.direction());
|
|
933
|
+
const up = Vector3d.createFromArray(camera.upVector());
|
|
934
|
+
const pos = Vector3d.createFromArray(camera.position());
|
|
935
|
+
let move = Vector3d.createFromArray([dir.x, dir.y, 0]);
|
|
936
|
+
if (Math.abs(dir.x) > 0.001 && Math.abs(dir.y) > 0.001) {
|
|
937
|
+
move.setToProduct(move.normalize(), currentDelta);
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
move = Vector3d.createFromArray([0, currentDelta, 0]);
|
|
941
|
+
}
|
|
942
|
+
let newPos = pos.add(move);
|
|
943
|
+
let newTarget = target.add(move);
|
|
944
|
+
camera.setupCamera(newPos.toArray(), newTarget.toArray(), up.toArray());
|
|
945
|
+
}
|
|
946
|
+
moveBackward(currentDelta) {
|
|
947
|
+
this.moveForward(-currentDelta);
|
|
948
|
+
}
|
|
928
949
|
turnLeft(angle) {
|
|
929
950
|
const pCamera = this.cameraWalker.camera().openObjectAsCamera();
|
|
930
951
|
const dir = this.toVector(pCamera.direction());
|
|
@@ -938,6 +959,206 @@ class OdaWalkDragger extends OdBaseDragger {
|
|
|
938
959
|
pCamera.setupCameraByDirection(pos, dir.toArray(), up.toArray());
|
|
939
960
|
pCamera.delete();
|
|
940
961
|
}
|
|
962
|
+
setupCamera(view) {
|
|
963
|
+
const pCamera = this.cameraId.openObjectAsCamera();
|
|
964
|
+
const target = view.viewTarget;
|
|
965
|
+
pCamera.setDisplayGlyph(false);
|
|
966
|
+
pCamera.setDisplayTarget(false);
|
|
967
|
+
pCamera.setAutoAdjust(true);
|
|
968
|
+
pCamera.setupCamera(view.viewPosition, target, view.upVector);
|
|
969
|
+
pCamera.setNearClip(false, 1.0);
|
|
970
|
+
pCamera.setFarClip(false, 0);
|
|
971
|
+
pCamera.setViewParameters(view.viewFieldWidth, view.viewFieldHeight, true);
|
|
972
|
+
const focalL = calcFocalLength$1(view.lensLength, view.viewFieldWidth, view.viewFieldHeight);
|
|
973
|
+
const pTarget = this.toPoint(view.viewTarget);
|
|
974
|
+
const viewDir = this.toPoint(view.viewPosition);
|
|
975
|
+
const viewDirSub = viewDir.sub(pTarget);
|
|
976
|
+
const viewDirVec = viewDirSub.asVector();
|
|
977
|
+
const viewDirVecNormal = viewDirVec.normalize();
|
|
978
|
+
const geViewDir = this.toGeVector(viewDirVecNormal);
|
|
979
|
+
const newGeViewDir = [geViewDir[0] * focalL, geViewDir[1] * focalL, geViewDir[2] * focalL];
|
|
980
|
+
const pTarget2 = this.toPoint(view.viewTarget);
|
|
981
|
+
const newGeViewDirPt = this.toPoint(newGeViewDir);
|
|
982
|
+
const newPos = pTarget2.add(newGeViewDirPt);
|
|
983
|
+
pCamera.setupCamera(this.toGePoint(newPos), view.viewTarget, view.upVector);
|
|
984
|
+
this.deleteAll([pTarget, viewDir, viewDirSub, viewDirVec, viewDirVecNormal, pTarget2, newGeViewDirPt, newPos]);
|
|
985
|
+
pCamera.assignView(view);
|
|
986
|
+
pCamera.delete();
|
|
987
|
+
}
|
|
988
|
+
getMaxDimension(view) {
|
|
989
|
+
const [xmax, ymax, zmax] = view.sceneExtents.max();
|
|
990
|
+
const [xmin, ymin, zmin] = view.sceneExtents.min();
|
|
991
|
+
const volume = [xmax - xmin, ymax - ymin, zmax - zmin];
|
|
992
|
+
return Math.max(...volume);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
const FocalLengthConst = 42.0;
|
|
997
|
+
const calcFocalLength = (lensLength, fieldWidth, fieldHeight) => {
|
|
998
|
+
return (lensLength / FocalLengthConst) * Math.sqrt(fieldWidth * fieldWidth + fieldHeight * fieldHeight);
|
|
999
|
+
};
|
|
1000
|
+
class OdaFlyDragger extends OdBaseDragger {
|
|
1001
|
+
constructor(subject) {
|
|
1002
|
+
super(subject);
|
|
1003
|
+
this.viewer = undefined;
|
|
1004
|
+
this.multiplier = 5;
|
|
1005
|
+
this.speed = 1;
|
|
1006
|
+
this.keyPressMap = new Set();
|
|
1007
|
+
this.keydown = this.keydown.bind(this);
|
|
1008
|
+
this.keyup = this.keyup.bind(this);
|
|
1009
|
+
this.lastFrameTS = 0;
|
|
1010
|
+
this.animationId = undefined;
|
|
1011
|
+
this.processMovement = this.processMovement.bind(this);
|
|
1012
|
+
this.deltaAngle = Math.PI / 3600;
|
|
1013
|
+
this.autoSelect = true;
|
|
1014
|
+
}
|
|
1015
|
+
initialize() {
|
|
1016
|
+
super.initialize();
|
|
1017
|
+
this.viewer = this.getViewer();
|
|
1018
|
+
window.addEventListener("keydown", this.keydown, false);
|
|
1019
|
+
window.addEventListener("keyup", this.keyup, false);
|
|
1020
|
+
this.oldWCSEnableValue = this.viewer.getEnableWCS();
|
|
1021
|
+
this.viewer.setEnableWCS(false);
|
|
1022
|
+
const view = this.viewer.activeView;
|
|
1023
|
+
const maxDimension = this.getMaxDimension(view);
|
|
1024
|
+
this.speed = maxDimension / 30000;
|
|
1025
|
+
this.subject.emitEvent({ type: "flystart" });
|
|
1026
|
+
this.viewParams = this.getViewParams();
|
|
1027
|
+
this.setViewParams(this.viewParams);
|
|
1028
|
+
const model = this.viewer.getActiveModel();
|
|
1029
|
+
this.cameraId = model.appendCamera("Camera0");
|
|
1030
|
+
this.setupCamera(view);
|
|
1031
|
+
model.delete();
|
|
1032
|
+
this.cameraFlyer = new this.m_module.OdTvCameraWalker();
|
|
1033
|
+
this.cameraFlyer.setCamera(this.cameraId);
|
|
1034
|
+
this.subject.update();
|
|
1035
|
+
this.enableZoomWheelPreviousValue = this.subject.options.enableZoomWheel;
|
|
1036
|
+
this.subject.options.enableZoomWheel = false;
|
|
1037
|
+
}
|
|
1038
|
+
dispose() {
|
|
1039
|
+
var _a;
|
|
1040
|
+
this.oldWCSEnableValue =
|
|
1041
|
+
this.oldWCSEnableValue !== undefined ? this.oldWCSEnableValue : this.subject.options.showWCS;
|
|
1042
|
+
this.viewer.setEnableWCS(this.oldWCSEnableValue);
|
|
1043
|
+
super.dispose();
|
|
1044
|
+
this.keyPressMap.clear();
|
|
1045
|
+
window.removeEventListener("keydown", this.keydown);
|
|
1046
|
+
window.removeEventListener("keyup", this.keyup);
|
|
1047
|
+
if (this.animationId) {
|
|
1048
|
+
window.cancelAnimationFrame(this.animationId);
|
|
1049
|
+
this.animationId = undefined;
|
|
1050
|
+
}
|
|
1051
|
+
if (this.cameraId) {
|
|
1052
|
+
const model = this.viewer.getActiveModel();
|
|
1053
|
+
model.removeEntity(this.cameraId);
|
|
1054
|
+
model.delete();
|
|
1055
|
+
(_a = this.cameraFlyer) === null || _a === void 0 ? void 0 : _a.delete();
|
|
1056
|
+
}
|
|
1057
|
+
if (this.viewParams) {
|
|
1058
|
+
this.setViewParams(this.viewParams);
|
|
1059
|
+
const avp = this.viewer.activeView;
|
|
1060
|
+
avp.delete();
|
|
1061
|
+
}
|
|
1062
|
+
this.subject.update(true);
|
|
1063
|
+
this.subject.options.enableZoomWheel = this.enableZoomWheelPreviousValue;
|
|
1064
|
+
}
|
|
1065
|
+
keydown(ev) {
|
|
1066
|
+
switch (ev.code) {
|
|
1067
|
+
case "NumpadSubtract":
|
|
1068
|
+
case "Minus":
|
|
1069
|
+
if (this.multiplier > 1) {
|
|
1070
|
+
this.multiplier = this.multiplier - 1;
|
|
1071
|
+
this.subject.emitEvent({ type: "flyspeedchange", data: this.multiplier });
|
|
1072
|
+
}
|
|
1073
|
+
break;
|
|
1074
|
+
case "NumpadAdd":
|
|
1075
|
+
case "Equal":
|
|
1076
|
+
if (this.multiplier < 10) {
|
|
1077
|
+
this.multiplier = this.multiplier + 1;
|
|
1078
|
+
this.subject.emitEvent({ type: "flyspeedchange", data: this.multiplier });
|
|
1079
|
+
}
|
|
1080
|
+
break;
|
|
1081
|
+
case "KeyW":
|
|
1082
|
+
case "KeyA":
|
|
1083
|
+
case "KeyS":
|
|
1084
|
+
case "KeyD":
|
|
1085
|
+
case "KeyQ":
|
|
1086
|
+
case "KeyE":
|
|
1087
|
+
this.keyPressMap.add(ev.code);
|
|
1088
|
+
if (!this.animationId)
|
|
1089
|
+
this.processMovement(0);
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
keyup(ev) {
|
|
1094
|
+
this.keyPressMap.delete(ev.code);
|
|
1095
|
+
if (this.keyPressMap.size < 1 && this.animationId) {
|
|
1096
|
+
window.cancelAnimationFrame(this.animationId);
|
|
1097
|
+
this.animationId = undefined;
|
|
1098
|
+
this.lastFrameTS = 0;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
processMovement(timestamp) {
|
|
1102
|
+
this.animationId = requestAnimationFrame(this.processMovement);
|
|
1103
|
+
if (this.lastFrameTS !== 0) {
|
|
1104
|
+
const deltaTS = timestamp - this.lastFrameTS;
|
|
1105
|
+
const currentDelta = this.multiplier * deltaTS * this.speed;
|
|
1106
|
+
for (const keyCode of this.keyPressMap) {
|
|
1107
|
+
switch (keyCode) {
|
|
1108
|
+
case "KeyW":
|
|
1109
|
+
this.cameraFlyer.moveForward(currentDelta);
|
|
1110
|
+
break;
|
|
1111
|
+
case "KeyS":
|
|
1112
|
+
this.cameraFlyer.moveBackward(currentDelta);
|
|
1113
|
+
break;
|
|
1114
|
+
case "KeyA":
|
|
1115
|
+
this.cameraFlyer.moveLeft(currentDelta);
|
|
1116
|
+
break;
|
|
1117
|
+
case "KeyD":
|
|
1118
|
+
this.cameraFlyer.moveRight(currentDelta);
|
|
1119
|
+
break;
|
|
1120
|
+
case "KeyQ":
|
|
1121
|
+
this.cameraFlyer.moveUp(currentDelta);
|
|
1122
|
+
break;
|
|
1123
|
+
case "KeyE":
|
|
1124
|
+
this.cameraFlyer.moveDown(currentDelta);
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
this.subject.update();
|
|
1129
|
+
this.subject.emitEvent({ type: "changecamera" });
|
|
1130
|
+
}
|
|
1131
|
+
this.lastFrameTS = timestamp;
|
|
1132
|
+
}
|
|
1133
|
+
start(x, y) {
|
|
1134
|
+
this.dragPosition = { x, y };
|
|
1135
|
+
}
|
|
1136
|
+
drag(x, y) {
|
|
1137
|
+
if (this.cameraId && this.isDragging) {
|
|
1138
|
+
const dltX = x - this.dragPosition.x;
|
|
1139
|
+
const dltY = y - this.dragPosition.y;
|
|
1140
|
+
this.dragPosition = { x, y };
|
|
1141
|
+
if (dltX !== 0.0)
|
|
1142
|
+
this.turnLeft(-dltX * this.deltaAngle);
|
|
1143
|
+
if (dltY !== 0.0)
|
|
1144
|
+
this.cameraFlyer.turnDown(dltY * this.deltaAngle);
|
|
1145
|
+
this.subject.update();
|
|
1146
|
+
this.subject.emitEvent({ type: "changecamera" });
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
turnLeft(angle) {
|
|
1150
|
+
const pCamera = this.cameraFlyer.camera().openObjectAsCamera();
|
|
1151
|
+
const dir = this.toVector(pCamera.direction());
|
|
1152
|
+
const up = this.toVector(pCamera.upVector());
|
|
1153
|
+
const pos = pCamera.position();
|
|
1154
|
+
const rotMatrix = this.createMatrix3d();
|
|
1155
|
+
const zAxisVector = [0, 0, 1];
|
|
1156
|
+
rotMatrix.setToRotation(angle, zAxisVector, pos);
|
|
1157
|
+
dir.transformBy(rotMatrix);
|
|
1158
|
+
up.transformBy(rotMatrix);
|
|
1159
|
+
pCamera.setupCameraByDirection(pos, dir.toArray(), up.toArray());
|
|
1160
|
+
pCamera.delete();
|
|
1161
|
+
}
|
|
941
1162
|
setupCamera(view) {
|
|
942
1163
|
const pCamera = this.cameraId.openObjectAsCamera();
|
|
943
1164
|
const target = view.viewTarget;
|
|
@@ -1762,6 +1983,7 @@ draggers.registerDragger("CuttingPlaneXAxis", (viewer) => new OdCuttingPlaneXAxi
|
|
|
1762
1983
|
draggers.registerDragger("CuttingPlaneYAxis", (viewer) => new OdCuttingPlaneYAxisDragger(viewer));
|
|
1763
1984
|
draggers.registerDragger("CuttingPlaneZAxis", (viewer) => new OdCuttingPlaneZAxisDragger(viewer));
|
|
1764
1985
|
draggers.registerDragger("Walk", (viewer) => new OdaWalkDragger(viewer));
|
|
1986
|
+
draggers.registerDragger("Fly", (viewer) => new OdaFlyDragger(viewer));
|
|
1765
1987
|
|
|
1766
1988
|
const composeMatrixFromTransform = (transform, modelCenter, visLib) => {
|
|
1767
1989
|
const { translate, scale, rotation } = transform;
|