简体   繁体   English

如何渲染相同 3D Model 的多个 3D;

[英]How To Render Multiple 3D of Same 3D Model;

I have a 3D model from Mixamo and used npx gltfjsx to make it into a component.我有一个来自 Mixamo 的 3D model 并使用 npx gltfjsx 将其制成组件。 Now I would like to render this model multiple times, but when I try to do so, I only get one model on Canvas.现在我想多次渲染这个 model,但是当我尝试这样做时,我只在 Canvas 上得到一个 model。

Is there a way to do this?有没有办法做到这一点? Here is my file:这是我的文件:

  const { actions } = useAnimations(animations, heroRef);

  return (
    <>
      <group ref={heroRef} dispose={null}>
        <group rotation={[Math.PI / 2, 0, 0]} scale={0.01}>
          <primitive object={nodes.mixamorig1Hips} />
          <skinnedMesh
            geometry={nodes.Ch36.geometry}
            material={materials.Ch36_Body}
            skeleton={nodes.Ch36.skeleton}
          />
        </group>

        {/* <gridHelper args={[25, 25]}/> */}
      </group>
    </>
  );
}

useGLTF.preload("/Mannequin.glb"); ```

Any help/advice is appreciated.

The model needs to be cloned, like this:需要克隆 model,如下所示:

const scene = React.useMemo(() => {
  return model.scene.clone();
}, [model]);

The above clones the scene , but you can do the same to nodes , materials , etc. inside the object returned from useGLTF以上克隆了scene ,但是您可以对从 useGLTF 返回的useGLTF中的nodesmaterials等执行相同操作。

Here's an example:这是一个例子:

https://codesandbox.io/s/heuristic-clarke-g58yp?file=/src/App.js https://codesandbox.io/s/heuristic-clarke-g58yp?file=/src/App.js

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

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