I've got a line "walking around my scene" (some kind of a 3D snake) randomly and the next thing I wish to achieve is set a box around its head.
The line bufferGeometry
is set by
var positions1 = new Float32Array( MAX_POINTS * 3 ); // 3 vertices per point
var positions2 = new Float32Array( MAX_POINTS * 3 ); // 3 vertices per point
buffGeometry1.addAttribute( 'position', new THREE.BufferAttribute( positions1, 3 ) );
buffGeometry2.addAttribute( 'position', new THREE.BufferAttribute( positions2, 3 ) );
I chose to set a cube (boxGeometry
object) around it, and I used the following code lines to try and achieve that:
var positioning = buffGeometry1.getAttribute('position');
cube.position.x = positioning[0];//(line1.geometry.attributes.position.array[drawCount]);
cube.position.y = positioning[1];//(line1.geometry.attributes.position.array[drawCount + 1]);
cube.position.z = positioning[2];
As I debug, I see that my positioning
array is undefined. so I guess something there went wrong.
Thanks.
Try:
console.log(buffGeometry1.getAttribute('position'))
My THREE.BufferGeometry shows me that verticles are stored in positioning.array so you should acces them by:
positioning.array[0]
positioning.array[1]
positioning.array[2]