-
I want object pooling. I want hide or replace one box in instanced mehes. Please tip or example code. Ref is : |
Beta Was this translation helpful? Give feedback.
Answered by
codynova
May 11, 2020
Replies: 1 comment 1 reply
-
You can use the index of the instanced body to refer to it in the API: const NUMBER_OF_BOXES = 10
const BODY_INDEX = 4
const [ref, api] = useBox(() => ({
mass: 1,
args: [0.05, 0.05, 0.05],
position: [Math.random() - 0.5, Math.random() * 2, Math.random() - 0.5],
}))
useFrame(() => api.at(BODY_INDEX).position.set(1, 1, 1))
return (
<instancedMesh ref={ref} args={[null, null, NUMBER_OF_BOXES]}> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
codynova
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the index of the instanced body to refer to it in the API: