I have the following code, I want to write it with array and itemSize arguments instead of args like the second code, but it does not give me the same results. I tried to add also the “count” argument to see if it made a difference ( count = {cellData.positions.length/3} ) but this still doesn’t give me the same answer.
you should get the same results. you can see an example w/o args here: Threejs journey - CodeSandbox but again, if you don’t, three internals have other stuff in it or they add something tomorrow and your code will fail. i would suggest using args bc why wouldn’t you want to use the constructor arguments that threejs prescribes?
btw in v8 the awkward object/array-attach stuff goes away, you just use attach for everything and dash notation
const mesh = new THREE.Mesh()
mesh.geometry = new THREE.BufferGeometry()
geometry.attributes.position = new THREE.BufferAttribute(positionArray, 3)
geometry.attributes.aScale = new THREE.BufferAttribute(scaleArray, 1)
Ok, thank you I kept the args.
trying to apply what you explained I also tried to modify the states via refs.
But with this code, the refs do change, but the rendering does not update. I don’t understand how this is possible. To be more precise the update works only if I remove the bufferAttribute attach=“index”…, but I need it in order to display the correct geometries.
there’s a great article in three docs about this, how to update things: three.js docs
generally you can’t replace buffers and attributes, you can mutate them, but you can’t exceed the length which is most likely where you get that error from. the article above covers buffergeometries and attributes as well. if you do exchange buffers entirely you need to call needsUpdate somewhere, the entire shader will re-compile - i would not recommend it.
generally react+three is just a way to express code, it won’t change how three works or the rules it adheres to. sticking more to the three docs when in doubt will always help.