import { useState, useMemo, useRef, useEffect } from 'react';
|
import { useFrame } from '@react-three/fiber';
|
import { useFBX, useAnimations } from '@react-three/drei';
|
import * as THREE from 'three';
|
|
const setShadow = (obj) => {
|
obj.castShadow = true;
|
obj.receiveShadow = true;
|
|
if (obj.children) {
|
obj.children.forEach((child) => {
|
setShadow(child);
|
});
|
}
|
};
|
|
const setColor = (obj) => {
|
if (obj.material) {
|
obj.material.color.set(0x4680BF);
|
}
|
if (obj.children) {
|
obj.children.forEach((child) => {
|
setColor(child);
|
});
|
}
|
};
|
|
const Box = (props) => {
|
const { position = [0, 300, 0] } = props;
|
|
const boxModel = useMemo(() => {
|
const fbx = useFBX('/models/box/box.fbx');
|
if (!fbx.castShadow) {
|
setShadow(fbx);
|
}
|
return fbx.clone();
|
}, [])
|
|
useEffect(() => {
|
|
}, []);
|
|
return (
|
<>
|
<group rotation={[0, 0, 0]} scale={0.5} position={position}>
|
<primitive object={boxModel} castShadow />
|
</group>
|
</>
|
)
|
}
|
|
export default Box;
|