Je suis nouveau ici sur ce forum.
Je suis en train de suivre un tutoriel :https://www.youtube.com/watch?v=ZqEa8fTxypQ
et j'ai eu un problème avec mon composant CameraRig car ma page était blanche et j'ai donc fait ceci et ça marche :
code d'origine :
Code : Tout sélectionner
return <group ref={group}>{children}</group>
Code : Tout sélectionner
const {nœuds, matériaux } = useGLTF('/shirt_baked.glb');
Avez-vous une idée ? car je cherche depuis plusieurs jours sans succès.
Shirt.jsx
Code : Tout sélectionner
import React from 'react'
import { easing } from 'maath';
import { useSnapshot } from 'valtio';
import { useFrame } from '@react-three/fiber';
import { Decal, useGLTF, useTexture } from '@react-three/drei';
import state from '../store';
const Shirt = () => {
const snap = useSnapshot(state);
const { nodes, materials } = useGLTF('/shirt_baked.glb');
const logoTexture = useTexture(snap.logoDecal);
const fullTexture = useTexture(snap.fullDecal);
useFrame((state, delta) => easing.dampC(materials.lambert1.color, snap.color, 0.25, delta));
const stateString = JSON.stringify(snap);
return (
<group key={stateString}>
<mesh
castShadow
geometry={nodes.T_Shirt_male.geometry}
material={materials.lambert1}
material-roughness={1}
dispose={null}
>
{snap.isFullTexture && (
<Decal
position={[0, 0, 0]}
rotation={[0, 0, 0]}
scale={1}
map={fullTexture}
/>
)}
{snap.isLogoTexture && (
<Decal
position={[0, 0.04, 0.15]}
rotation={[0, 0, 0]}
scale={0.15}
map={logoTexture}
map-anisotropy={16}
depthTest={false}
depthWrite={true}
/>
)}
</mesh>
</group>
)
}
export default Shirt
Code : Tout sélectionner
import React, { useRef } from 'react';
import { useFrame } from '@react-three/fiber';
import { easing } from 'maath';
import { useSnapshot } from 'valtio';
import state from '../store';
const CameraRig = ({ children }) => {
const group = useRef();
const snap = useSnapshot(state);
useFrame((state, delta) => {
const isBreakpoint = window.innerWidth <= 1260;
const isMobile = window.innerWidth <= 600;
// set the initial position of the model
let targetPosition = [-0.4, 0, 2];
if (snap.intro) {
if (isBreakpoint) targetPosition = [0, 0, 2];
if (isMobile) targetPosition = [0, 0.2, 2.5];
} else {
if (isMobile) targetPosition = [0, 0, 2.5]
else targetPosition = [0, 0, 2];
}
// set model camera position
easing.damp3(state.camera.position, targetPosition, 0.25, delta)
// set the model rotation smoothly
easing.dampE(
group.current.rotation,
[state.pointer.y / 10, -state.pointer.x / 5, 0],
0.25,
delta
)
})
return <group ref={group}></group>
}
export default CameraRig
Code : Tout sélectionner
import { Canvas } from '@react-three/fiber';
import { Environment, Center } from '@react-three/drei';
import Shirt from './Shirt';
import Backdrop from './Backdrop';
import CameraRig from './CameraRig';
const CanvasModel = () => {
return (
<Canvas
shadows
camera={{ position: [0, 0, 0], fov: 25 }}
gl={{ preserveDrawingBuffer: true }}
className="w-full max-w-full h-full transition-all ease-in"
>
<ambientLight intensity={0.5} />
<Environment preset="city" />
<CameraRig>
<Backdrop />
<Center>
<Shirt />
</Center>
</CameraRig>
</Canvas>
)
}
export default CanvasModel