Replies: 1 comment 3 replies
-
Your code is a bit messy. Not sure to understand what are you trying to do. The proper way to update a mesh geometry could be: From a given mesh: const MyCustomMesh = () => {
const mesh = useRef(null)
// --snip--
return (
<mesh ref={mesh}>
<planeBufferGeometry args={[10, 10, 50, 10]} />
<meshStandardMaterial color="#00ffff"/>
</mesh>
)
} Update the buffer geometry via const updateBufferGeometry = () => {
const { geometry } = mesh.current
const { position } = geometry.attributes
for (const index of enumerate(position.count)) {
position.array[index * 3 + 2] = amplitude * (Math.random() - 0.5)
}
position.needsUpdate = true
geometry.computeVertexNormals()
} Where enumerate is a little generator helper: function* enumerate(count) {
let i = 0
while (i < count) yield i++
} That could be replaced by a "old fashion for loop": for (let index = 0; index < position.count; index++) { /* --snip-- */ } |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to create a plane and set the x,y,z locations for the plane individually. So, in three.js it would be something like this ...
var plane = new THREE.PlaneGeometry(planeSize, planeSize, planeDefinition, planeDefinition);
var plane = new THREE.Mesh(plane, new THREE.MeshBasicMaterial({
color: meshColor,
wireframe: true
}));
for (var i = 0; i < plane.vertices.length; i++) {
plane.vertices[i].z += Math.random() * vertexHeight - vertexHeight;
plane.vertices[i]._myZ = plane.vertices[i].z
}
I don't need to update these vertices locations, so I don't need to use a hook of any kind. Is there a parameter to feed vertices locations directly into the react component? Is there a better way to do this? Thanks
Beta Was this translation helpful? Give feedback.
All reactions