How can I make the same function work for different arrays? -
what want execute function when want push positions of vertices of 3d geometry array. want use same code on again when want push positions array. possible use function when want push in array? can me please?
this code:
function sphereposition() { sphere.position.x + sphere.geometry.vertices[i].clone().x * 1; sphere.position.y + sphere.geometry.vertices[i].clone().y * 1; sphere.position.z +sphere.geometry.vertices[i].clone().z * 1; } ( var = 0; < particles; i++ ) { positions.push( sphereposition(); ); }
this not three.js question more of programming question how organize data
?
you have several options (not exhaustive list).
- add position cone2. data
world space position + vertices position
- use 2 arrays. 1
object world space position
, 1vertices position
- premultiply vertices object matrix , store result.
using option 1:
function getobjectdata (object) { var world_position = object.position; var vertices_position = object.geometry.vertices; ( var = 0; < particles; i++ ) { positions.push( world_position.x + vertices_position[i].x, world_position.y + vertices_position[i].y, world_position.z + vertices_position[i].z, ); } }
Comments
Post a Comment