【发布时间】:2021-12-08 01:04:06
【问题描述】:
我正在使用 react-three-fiber,我想建一所房子。所以我使用 GLTF 模型来显示门。
渲染一扇门很好,但是当我从同一个 GLTF 文件渲染两扇门时,只会渲染第二扇门。看起来第二扇门取代了第一扇门,而不是一扇新门。
如何实现拥有多个门,我已经搜索过,但似乎没有人问这个问题???
我的代码:
Door.tsx
import React from 'react';
import { useLoader } from "@react-three/fiber";
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
interface DoorProps {
rotation: any;
}
function Door(props: DoorProps) {
const gltf = useLoader(GLTFLoader, '/simple_door.gltf');
return (
<>
<primitive
object={gltf.scene}
position={[25, 1, -17]}
scale={0.05}
rotation={props.rotation}
/>
</>
);
}
export default Door;
Room.tsx
function Room() {
return (
<Canvas
shadows
dpr={[1, 2]}
frameloop="demand"
style={{ height: 800 }}
camera={{ fov: 75, near: 0.1, far: 1000, position: [0, 10, 20] }}
>
<OrbitControls addEventListener={undefined} hasEventListener={undefined} removeEventListener={undefined} dispatchEvent={undefined} />
<ambientLight intensity={0.8} />
<color attach="background" args={['#d0d0d0']} />
<fog attach="fog" args={['#d0d0d0', 100, 600]} />
<Suspense fallback={null}>
<Environment preset="city" />
<Door />
<Plane
width={50}
height={10}
depth={1}
position={[0, 0, -20]}
/>
<Door
rotation={[0, 90*Math.PI/180, 0]}
/>
<Plane
width={50}
height={1}
depth={50}
position={[0, -4.5, 5]}
/>
</Suspense>
</Canvas>
);
};
export default Room;
【问题讨论】:
标签: reactjs three.js gltf react-three-fiber