Skip to content

Commit

Permalink
fix: GizmoViewcube
Browse files Browse the repository at this point in the history
  • Loading branch information
seasick committed Jan 6, 2024
1 parent bc270e9 commit 96b5f34
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/components/threeJs/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@react-three/drei';
import { Canvas } from '@react-three/fiber';
import React from 'react';
import * as THREE from 'three';

import { Environment } from './Environment';
import Model from './Model';
Expand Down Expand Up @@ -80,6 +81,14 @@ export default function ThreeJsCanvas({
}
};

const tweenCamera = (position: THREE.Vector3) => {
const point = new THREE.Spherical().setFromVector3(
new THREE.Vector3(position.x, position.y, position.z)
);
cameraControlRef.current!.rotateTo(point.theta, point.phi, true);
cameraControlRef.current!.fitToSphere(geometry, true);
};

return (
<Canvas
id="editor-canvas"
Expand Down Expand Up @@ -110,7 +119,21 @@ export default function ThreeJsCanvas({
onPointerMove={handlePointerMove}
/>
<GizmoHelper alignment="bottom-right" margin={[80, 80]}>
<GizmoViewcube />
<GizmoViewcube
onClick={(e) => {
e.stopPropagation();
if (
e.eventObject.position.x === 0 &&
e.eventObject.position.y === 0 &&
e.eventObject.position.z === 0

This comment has been minimized.

Copy link
@vinkovsky

vinkovsky Apr 20, 2024

Hi! You can simplify this:

if (eventObject.position.length() === 0)

) {
tweenCamera(e.face!.normal);
} else {
tweenCamera(e.eventObject.position);
}
return null;
}}
/>
</GizmoHelper>
</Canvas>
);
Expand Down

0 comments on commit 96b5f34

Please sign in to comment.