@selvajs/visualization 1.8.0-beta.5 → 1.8.0-beta.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/render.cjs +42 -0
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +16 -1
- package/dist/render.d.ts +16 -1
- package/dist/render.js +42 -0
- package/dist/render.js.map +1 -1
- package/package.json +1 -1
package/dist/render.cjs
CHANGED
|
@@ -854,6 +854,40 @@ function createCameraController(deps) {
|
|
|
854
854
|
const setView = (preset, animate = true) => {
|
|
855
855
|
setViewDirection(VIEW_DIRECTIONS[preset], animate);
|
|
856
856
|
};
|
|
857
|
+
const getCameraView = () => {
|
|
858
|
+
const target = controls.target;
|
|
859
|
+
const offset = active().position.clone().sub(target);
|
|
860
|
+
if (offset.lengthSq() < 1e-12) offset.copy(VIEW_DIRECTIONS.iso);
|
|
861
|
+
if (projection === "orthographic") offset.divideScalar(ortho.zoom);
|
|
862
|
+
return {
|
|
863
|
+
direction: rounded(offset.clone().normalize()),
|
|
864
|
+
position: rounded(target.clone().add(offset)),
|
|
865
|
+
target: rounded(target)
|
|
866
|
+
};
|
|
867
|
+
};
|
|
868
|
+
const setCameraView = (view, animate = false) => {
|
|
869
|
+
const position = toVector(view.position);
|
|
870
|
+
const target = toVector(view.target);
|
|
871
|
+
if (position && target && position.distanceToSquared(target) > 1e-12) {
|
|
872
|
+
cancelTween();
|
|
873
|
+
const cam = active();
|
|
874
|
+
if (projection === "orthographic") ortho.zoom = 1;
|
|
875
|
+
if (animate) {
|
|
876
|
+
activeTween = animateMove(cam, controls, position, target, () => {
|
|
877
|
+
if (projection === "orthographic") syncOrthoFrustum();
|
|
878
|
+
});
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
cam.position.copy(position);
|
|
882
|
+
controls.target.copy(target);
|
|
883
|
+
if (projection === "orthographic") syncOrthoFrustum();
|
|
884
|
+
controls.update();
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
const direction = toVector(view.direction);
|
|
888
|
+
if (direction && direction.lengthSq() > 1e-12) setViewDirection(direction.normalize(), animate);
|
|
889
|
+
else setView("iso", animate);
|
|
890
|
+
};
|
|
857
891
|
const setRotateEnabled = (enabled) => {
|
|
858
892
|
controls.enableRotate = enabled;
|
|
859
893
|
};
|
|
@@ -871,6 +905,8 @@ function createCameraController(deps) {
|
|
|
871
905
|
},
|
|
872
906
|
setView,
|
|
873
907
|
setViewDirection,
|
|
908
|
+
getCameraView,
|
|
909
|
+
setCameraView,
|
|
874
910
|
frameBounds,
|
|
875
911
|
setRotateEnabled,
|
|
876
912
|
isRotateEnabled: () => controls.enableRotate,
|
|
@@ -878,6 +914,12 @@ function createCameraController(deps) {
|
|
|
878
914
|
dispose: cancelTween
|
|
879
915
|
};
|
|
880
916
|
}
|
|
917
|
+
const rounded = (v) => [
|
|
918
|
+
v.x,
|
|
919
|
+
v.y,
|
|
920
|
+
v.z
|
|
921
|
+
].map((n) => Math.round(n * 1e6) / 1e6);
|
|
922
|
+
const toVector = (values) => values?.length === 3 && values.every(Number.isFinite) ? new three.Vector3(values[0], values[1], values[2]) : void 0;
|
|
881
923
|
/**
|
|
882
924
|
* Nudges a top/bottom view direction a ~0.5° tilt off the up axis; other presets pass through
|
|
883
925
|
* unchanged. Looking exactly down `up` is an OrbitControls singularity: camera direction coincides
|