在react js gltf模型中显示白屏,无法使用react-三/纤维和drei和三个js正确加载
我使用@react- Three / Fiber,@react- Three / drei,Three js和gltfjsx制作了一个3D渲染网站。我想渲染一个 gltf 文件,我已经成功地做到了这一点,但有一个问题,那就是每当开发服务器启动时,屏幕就会闪烁并变成空白。虽然如果我使用 drei 提供的网格(如立方体和球体),屏幕不会变成空白,但一旦我想使用自定义 gltf 模型,屏幕就会变成空白,下面是我的 jsx 组件和 app.js 文件
MODEL COMPONENT
/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
*/
import React, { useRef } from 'react'
import { useGLTF } from '@react-three/drei'
export default function Model({ ...props }) {
const group = useRef()
const { nodes, materials } = useGLTF('/linear_irl.gltf')
return (
<group ref={group} {...props} dispose={null} scale={10}>
<mesh geometry={nodes.sphere.geometry} material={nodes.sphere.material} />
<mesh geometry={nodes.sphere_1.geometry} material={nodes.sphere_1.material} />
<mesh geometry={nodes.sphere_2.geometry} material={nodes.sphere_2.material} />
</group>
)
}
useGLTF.preload('/linear_irl.gltf')
App.js
<Canvas className="Canvas">
<ambientLight intensity={0.5}/>
<directionalLight position={[-2,5,2]}/>
<Suspense fallback={null}></Suspense>
<OrbitControls/>
<Linear_irl/>
</Canvas>
链接到下面的 gltf 文件 GLTF 文件 Google 云端硬盘链接
I used @react-three/fiber , @react-three/drei, three js and gltfjsx to make a 3d rendering website. I want to render a gltf file and I successfully could do it already but with a problem which is whenever the dev server starts the screen flickers and goes blank. Although if i use meshes provided by drei like cube and sphere the screen won't go blank but as soon as i want to use custom gltf model, the screen goes blank down below is my jsx component and app.js file
MODEL COMPONENT
/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
*/
import React, { useRef } from 'react'
import { useGLTF } from '@react-three/drei'
export default function Model({ ...props }) {
const group = useRef()
const { nodes, materials } = useGLTF('/linear_irl.gltf')
return (
<group ref={group} {...props} dispose={null} scale={10}>
<mesh geometry={nodes.sphere.geometry} material={nodes.sphere.material} />
<mesh geometry={nodes.sphere_1.geometry} material={nodes.sphere_1.material} />
<mesh geometry={nodes.sphere_2.geometry} material={nodes.sphere_2.material} />
</group>
)
}
useGLTF.preload('/linear_irl.gltf')
App.js
<Canvas className="Canvas">
<ambientLight intensity={0.5}/>
<directionalLight position={[-2,5,2]}/>
<Suspense fallback={null}></Suspense>
<OrbitControls/>
<Linear_irl/>
</Canvas>
Link to the gltf file down below
GLTF File Google Drive Link
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试过这个方法吗?用 Canvas 下方的 Suspense 包裹整个场景。
Tried this way? wrap the whole scene with Suspense right below Canvas.