From 5094996a02267e855eb9581ecbe1aa97eb1f6e27 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Date: Fri, 12 Mar 2021 16:17:31 +1100 Subject: [PATCH] Match camera fov between cameras, add axes related to #235 --- web/src/components/IdeViewer/IdeViewer.js | 30 +++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/web/src/components/IdeViewer/IdeViewer.js b/web/src/components/IdeViewer/IdeViewer.js index 739eb22..e324c19 100644 --- a/web/src/components/IdeViewer/IdeViewer.js +++ b/web/src/components/IdeViewer/IdeViewer.js @@ -10,11 +10,14 @@ function Controls({ onCameraChange }) { const { scene, camera, gl } = useThree() useEffect(() => { // init camera position - camera.position.x = 12 + camera.position.x = 16 camera.position.y = 12 - // Euler rotation can be problematic since order matters - // We want it to rotate around the z or vertical axis first then the x axis - // in Three Y is the vertical axis (Z for openscad) + console.log(camera) + camera.fov = 22.5 // matches default openscad fov + + // Order matters with Euler rotations + // We want it to rotate around the z or vertical axis first then the x axis to match openscad + // in Three.js Y is the vertical axis (Z for openscad) camera.rotation._order = 'YXZ' if (controls.current) { @@ -29,7 +32,7 @@ function Controls({ onCameraChange }) { } const getPositions = () => { const { x: scadX, y: scadZ, z: negScadY } = target.object.position - const scale = 10 // I'm not sure why this is exactly 10 + const scale = 10 const scadY = -negScadY return [scadX * scale, scadY * scale, scadZ * scale] } @@ -65,7 +68,7 @@ function Box(props) { return ( - + ) @@ -85,14 +88,6 @@ const IdeViewer = () => { currentCode = state.code return (
-
- Rotating the Three.js Cube should than update the openscad camera to - view the CAD object from the same angle. But having trouble translating - between the two coordinate systems. OpenScad's camera only changes X and - Z angles and Y is always 0. Where as rotation values from Three seem to - change all x, y and z. I probably need to learn a bit more about 3d - math. -
{image && (
{ /> - - - - + + +