fix: reimplement SealCube as fwdRef
This commit is contained in:
+6
-3
@@ -560,10 +560,12 @@ function Terrain({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SealCube() {
|
const SealCube = forwardRef<Mesh>((props, ref) => {
|
||||||
const texture = useLoader(TextureLoader, '/img/niko.jpg');
|
const texture = useLoader(TextureLoader, '/img/niko.jpg');
|
||||||
const meshRef = useRef<Mesh>(null);
|
const meshRef = useRef<Mesh>(null);
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => meshRef.current!, []);
|
||||||
|
|
||||||
useFrame((state, delta) => {
|
useFrame((state, delta) => {
|
||||||
if (meshRef.current) {
|
if (meshRef.current) {
|
||||||
meshRef.current.rotation.x += delta * 0.5;
|
meshRef.current.rotation.x += delta * 0.5;
|
||||||
@@ -572,12 +574,13 @@ function SealCube() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<mesh position={[0, 5, 0]} ref={meshRef} castShadow receiveShadow>
|
<mesh ref={meshRef} position={[0, 5, 0]} castShadow receiveShadow>
|
||||||
<boxGeometry args={[0.85, 0.85, 0.85]} />
|
<boxGeometry args={[0.85, 0.85, 0.85]} />
|
||||||
<meshBasicMaterial map={texture} />
|
<meshBasicMaterial map={texture} />
|
||||||
</mesh>
|
</mesh>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
SealCube.displayName = "SealCube"
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
// const { chunks, chunkSize, chunkRes, terrainScale, hillScale, hillHeight, detailScale, detailHeight, wireframe, grassCount, grassSize, grassLOD } = useControls(
|
// const { chunks, chunkSize, chunkRes, terrainScale, hillScale, hillHeight, detailScale, detailHeight, wireframe, grassCount, grassSize, grassLOD } = useControls(
|
||||||
|
|||||||
Reference in New Issue
Block a user