简体   繁体   English

在 react js gltf model 中显示白屏,没有正确加载 react-three/fibre 和 drei 和 three.js

[英]White screen showing in react js gltf model, not loading properly with react-three/fibre and drei and three js

I used @react-three/fiber, @react-three/drei, three.js and gltfjsx to make a 3d rendering website.我用@react-three/fiber、@react-three/drei、three.js和gltfjsx做了一个3d的渲染网站。 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.我想渲染一个 gltf 文件,我已经成功地完成了,但是有一个问题,那就是每当开发服务器启动时屏幕闪烁并变为空白。 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虽然如果我使用 drei 提供的网格,如立方体和球体,屏幕不会 go 空白,但一旦我想使用自定义 gltf model,屏幕就会变成空白,下面是我的 jsx 组件和 app.js 文件

MODEL COMPONENT MODEL 组件

/*
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应用程序.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链接到下面的gltf 文件 GLTF 文件 Google 云端硬盘链接

Tried this way?试过这样吗? wrap the whole scene with Suspense right below Canvas.在 Canvas 下方用 Suspense 包裹整个场景。

<Canvas className="Canvas">
  <Suspense fallback={null}>
    <ambientLight intensity={0.5}/>
    <directionalLight position={[-2,5,2]}/>
    <OrbitControls/>
    <Linear_irl/>
  </Suspense>
</Canvas>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM