In my program, it will update camera position to a 3D object in a model. Then I want it can move the camera around the 3D object.
It now can update camera position, but camera can’t move around a object.
This is my code. How can I fix it?
function Button(props) {
const vec = new THREE.Vector3(0, 3, 5);
const { x, y, z } = props.position;
const { camera, gl } = useThree()
if (x && y && z) {
vec.set(x, y, z);
}
useFrame((state) => {
const step = 0.1;
camera.position.lerp(vec, step)
camera.lookAt(0, 0, 0)
camera.updateProjectionMatrix()
});
return null;
}
const ModelCanvas = (props) => {
return (
<div className="center">
<Canvas
shadowMap
style={{ background: "#ffffff" }}
// camera={{ position: [0, 3, 10], fov: 100 }}
camera={{ position: [2, 0, 5], fov: 100 }}
gl={{ antialias: false, logarithmicDepthBuffer: true }}
id="my-canvas"
>
<ambientLight intensity={0.5} />
<pointLight position={[0, 60, -100]} intensity={20} />
<pointLight position={[-50, 0, -50]} intensity={2} />
<spotLight
castShadow
intensity={8}
angle={Math.PI / 10}
position={[10, 10, 10]}
shadow-mapSize-width={2048}
shadow-mapSize-height={2048}
/>
<Suspense fallback={null}>
<Model url={"/compressed.glb"} />
</Suspense>
<Button position={props.value} />
<PointerLockControls />
</Canvas>
</div>
);
};