如何在网页中呈现搅拌机模型?搅拌机、模型、网页、如何在

2023-09-03 11:01:10 作者:我很拽你怎样

我已经研究了在我的Web应用程序中渲染我的搅拌机模型的多个选项,现在我正在将我的模型导出为.gltf格式,下面是我的代码

App.js

import React, { Suspense } from 'react';
import './App.css';
import Model from './Model'
function App() {
  return (
    <div className="App">
      <Suspense fallback={null}>
        <Model />
      </Suspense>
    </div>
  );
}

export default App;
建筑工程搅拌机模型设计

Model.js

import React from 'react'
import { useLoader } from 'react-three-fiber'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
import Scene from './scene.gltf'
function Model(props) {
  const { nodes, materials } = useLoader(GLTFLoader, Scene)
  return (
    <div>

    </div>
  )
}

export default Model

问题

GLTF加载器引发错误

我想要的

我希望将我的模型在Reaction应用程序的搅拌器中显示为 尽我所能 旋转控制很棒..

抛出错误

RangeError: Invalid typed array length: 1299
    at new Float32Array (<anonymous>)
    at GLTFLoader.js:1965
    at async Promise.all (:3000/index 0)
    at async Promise.all (:3000/index 0)
    at async Promise.all (:3000/index 4)
    at async Promise.all (:3000/index 0)
    at async Promise.all (:3000/index 2)
    at async Promise.all (:3000/index 0)
    at async Promise.all

推荐答案

它不是这样工作的。R3f是一种Reaction渲染器。REACTION-DOM渲染div和跨度,r3f渲染网格和材质。您可以很好地混合这两个呈现器,但不能将div转储到r3f,或将网格转储到反应域。

https://codesandbox.io/s/r3f-contact-shadow-c75jh