<Canvas id=‘Canvas-Image’ dpr={[1,2]} shadows camera={{ fov : 45 }} style={{position: ‘absolute’, backgroundColor: ‘#F2F1F6’}}>
{/* Camera */}
<PerspectiveCamera makeDefault position={frontBack ? [0, 0, -3.75] : [0, 0, 3.75]} />
{/* Tshirtdesign */}
<TshirtModel />
<directionalLight args={["#ffffff", 1]} position={[0, 2, 0]} />
<OrbitControls />
{/* Ambient light */}
<ambientLight />
</Suspense>
</Canvas>
Need more details to help you. I assume you are trying to move the camera to the axis?¿
Use useFrame
hook or useEffect
depend on how you setup your scene, then inside listen to the changes. I usually use like this
const [isTakingScreenshot, setIsTakingScreenshot= useState(false)
// your other code
useFrame(()=>{
if(isTakingScreenhot){
const positions =[
// define camera positions of all sides as vector3, {x:0,y:0,z:0}
]
const delayBetweenScreenshots = 500;
const captureScreenshot = async (position, index) => {
controlsRef.current.object.position.set(position.x, position.y, position.z);
controlsRef.current?.update();
await new Promise((resolve) => setTimeout(resolve, delayBetweenScreenshots));
const canvas = canvasRenderedRef.current;
const screenshotDataUrl = canvas.toDataURL('image/png');
const a = document.createElement('a');
a.href = screenshotDataUrl;
a.download = `${index}.jpg`;
a.click();
};
const captureScreenshotsSequentially = async () => {
for (let i = 0; i < positions.length; i++) {
await captureScreenshot(positions[i], i);
}
};
captureScreenshotsSequentially().then(async () => {
await new Promise((resolve) => setTimeout(resolve, delayBetweenScreenshots));
controlsRef.current.object.position.set(positions[0].x, positions[0].y, positions[0].z);
controlsRef.current?.update();
setIsTakingScreenshot(false)
})
}
})