Skip to content

Best practices for adding a lot of dynamic objects from gltfjsx to the Physics world #91

Answered by stockhuman
shampliu asked this question in General
Discussion options

You must be logged in to vote

Are these objects similar enough in size and shape to be used as instanced geometry as in the cube demo? That would be the most efficient.

Else, I've done this, which isn't great by any means, but ran alright. There might be a yet-more-efficient way of doing things.

function Model (props) {
  const gltf = useLoader(GLTFLoader, props.url)
  const [ref, api] = use<shape>(() => ({...}))
  return (<mesh .../>)
}
// and a setup that populates a physics world
const objects = [] // a list of urls, objects from a scene, what have you
<Physics>
  {objects.map((object) => (
    <Model {...object} />
  ))}
</Physics>

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@shampliu
Comment options

Answer selected by shampliu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants