Closed ametis70 closed 3 years ago
I think you need to useTrimesh, but be aware that it will detect collisions only against spheres.
export const TheModel = ({ ...props }) => {
const { position, rotation } = props
const { nodes } = useLoader(GLTFLoader, "model.glb");
const vertices = geometry.attributes.position.array;
const indices = geometry.index.array
const [ref] = useTrimesh(() => ({
rotation,
position,
mass: 0,
args: [vertices, indices]
}))
return (
<mesh ref={ref} geometry={geometry} >
<meshStandardMaterial attach="material" color='#ff0000' />
</mesh>
)
}
Thanks! I ended up using trimesh in that way
[trimesh] will detect collisions only against spheres.
FYI I'm working on a way easily convert complex geometries into decomposed convex shapes in browser/Node.js, such that they can collide with other shapes, not just spheres: https://twitter.com/GlavinW/status/1518397865592303618?s=20&t=db0kTGnYxorVMd-_93CqjQ Works well with Cannon in my testing.
I think you need to useTrimesh, but be aware that it will detect collisions only against spheres.
export const TheModel = ({ ...props }) => { const { position, rotation } = props const { nodes } = useLoader(GLTFLoader, "model.glb"); const vertices = geometry.attributes.position.array; const indices = geometry.index.array const [ref] = useTrimesh(() => ({ rotation, position, mass: 0, args: [vertices, indices] })) return ( <mesh ref={ref} geometry={geometry} > <meshStandardMaterial attach="material" color='#ff0000' /> </mesh> ) }
I don't know what is 'geometry', where you import it to use?
I made a model that has a invisible geometry that should act like as a cage for the physics:
Is there a way to use the highlighted (orange) for this purpose? I'm trying to make something like a walking simulator, and the user shouldn't be able to cross that bound.
I was thinking of splitting it into smaller parts that are all convex, but that sounds pretty time consuming and I'm not even sure if it will work. Maybe I'm missing something and there is an easier way to achieve this?