<instancedMesh ref={ref} args={[null, null, blocks.length]}>
<boxBufferGeometry attach="geometry" args={[1, 1, 1]}>
</boxBufferGeometry>
<meshStandardMaterial attach="material" ref={material}>
</meshStandardMaterial>
</instancedMesh>
I want to set the color for the cube depending on its position, I figured out how to use boxBufferGeometry in instancedMesh, however I don’t understand how to do it with meshStandardMaterial and color
const ref = useRef<Mesh>()
const material = useRef<MeshStandardMaterial>()
useLayoutEffect(() => {
blocks.forEach((v, i) => {
tempObject.position.set(v.x, v.y, v.z)
tempObject.updateMatrix()
ref.current.setMatrixAt(i, tempObject.matrix)
ref.current.instanceMatrix.needsUpdate = true
})
}, [])