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).

  1. add position cone2. data world space position + vertices position
  2. use 2 arrays. 1 object world space position , 1 vertices position
  3. 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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -