Spacing out a mesh with thousands of cubes

Software: Away3D 4.x

sllik, Newbie
Posted: 19 November 2012 09:44 PM   Total Posts: 7

Hey I have a Mesh that consists of about 8000 evenly spaced out bars across the x-axis. I generated this Mesh by creating 8000 Meshes from a CubeGeometry and then merging them into a single Mesh. The reason I merge them into a single Mesh is to improve performance when resizing all the bars at once.

Now my question is, is it possible to somehow increase/reduce the space between the bars without losing performance. Basically I want to achieve this without going through the process of creating the bars from scratch.

I am using a OrthographicLens lense so you can think of it in 2D space.

   

Babylon, Jr. Member
Posted: 20 November 2012 04:12 AM   Total Posts: 39   [ # 1 ]

Greetings,
OK. so you merge two things together like

merge.apply(FinalMeshtempMesh); 

cool. Well now you want to keep track of the vertices that represent tempMesh inside your FinalMesh. You do this by accessing the subgeometries of FinalMesh. But how do you know which tempMesh is the mesh your talking about? Well for me I created an object that contains this information.

private var cubeDatas:Object { startIndex0endIndex0geometrys0geometrys20visiblefalse};

mergeNum FinalMesh.geometry.subGeometries[(FinalMesh.geometry.subGeometries.length-1)].vertexData.length/3;
   
merge.apply(FinalMeshtempMesh);
   
   
mergeNum2 FinalMesh.geometry.subGeometries[(FinalMesh.geometry.subGeometries.length-1)].vertexData.length/3;
   
   
cubeDatas[nameAsNumber]={startIndexmergeNumendIndexmergeNum2geometrys: (FinalMesh.geometry.subGeometries.length-1), geometrys2tempGeomvisibletrue }

So I have two numbers, the before and after size of my FinalMesh subgeometries. this way I know where in the FinalMesh my tempMesh was.

So now I create a function that goes through the subgeometries, and at the location of tempMesh I edit it’s x y and z

private function setMeshPartPosition(mesh:MeshmeshPartID:int):void{
 
 
var geometry:Geometry mesh.geometry;
 var 
geometries:Vector.<SubGeometry> = geometry.subGeometries;
 var 
numSubGeoms:int geometries.length;
 var 
vertices:Vector.<Number>;
 var 
verticesLengthuint;
 var 
juint;
 var 
subGeom:SubGeometry;
 
 
 
subGeom SubGeometry(geometries[1]);
 
vertices subGeom.vertexData;
 
 for (var 
i:int=cubeDatas[meshPartID].startIndex;i<cubeDatas[meshPartID].endIndex;i++){
  
  
var position:Vector3D=new Vector3D();
  
//calculate the position of the point here
  
FinalMesh.geometry.subGeometries[1].vertexData[i*3] 999//x
  
  
FinalMesh.geometry.subGeometries[1].vertexData[(i*3)+1] += 1//y
  
FinalMesh.geometry.subGeometries[1].vertexData[(i*3)+2] += 1//z
  
 
}
 
//update the vertexBuffer of the finalmesh subgeometrie[0]
 
FinalMesh.geometry.subGeometries[1].updateVertexData(vertices);
 
//subGeom.updateVertexData(vertices);

Please view this thread:
http://away3d.com/forum/viewthread/3180/
For a better understanding perhaps of what you want to do.

 

 

   

sllik, Newbie
Posted: 20 November 2012 04:57 PM   Total Posts: 7   [ # 2 ]

Thanks for the reply, this is exactly what I needed!

 

   

sllik, Newbie
Posted: 21 November 2012 04:55 AM   Total Posts: 7   [ # 3 ]

Hm repositioning 8000 bars would mean running a loop of 0 to 192000 (24 x-coordinates for each cube) which will definitely effect the FPS. I need to reposition them in a very specific way, I need to increase/decrease the space between them across the x-axis. I’m wondering if there is another way to achieve this without having such a big loop.

 

   

Babylon, Jr. Member
Posted: 21 November 2012 07:12 AM   Total Posts: 39   [ # 4 ]

resize and reposition or what?

 

   

sllik, Newbie
Posted: 21 November 2012 07:44 AM   Total Posts: 7   [ # 5 ]

No I don’t want to resize them I just want increase the space between them.

So I start off with the attached image. What I need to do is to increase the space between the bars. In the attached image there are 4px between each bar I want to increase that to 8px for example.

Using your method I would need to loop through all the bars and adjust the verticies for each bar to reposition them to allow for more space between the bars which results in a loop of 0 to 192000 (if I have 8000 bars with 24 verticies each).

I’m wondering if there is another method to achieve this without having to do this loop. I was thinking of maybe somehow using a custom lens… not sure how though or if it’s even possible.

 

   

sllik, Newbie
Posted: 21 November 2012 04:51 PM   Total Posts: 7   [ # 6 ]

Hmm is it possible to create a transformation matrix for the subgeometry that could use the index of vertexData as a variable, so that the verticies repositioned disproportionally

 

   

Babylon, Jr. Member
Posted: 22 November 2012 12:34 AM   Total Posts: 39   [ # 7 ]

EDIT::::::___
Whoops, you want to move them all at once, so this bottom post probably means nothing to you
____:::::::::::

When you cycle through the subgeometry of the FinalMesh that contains your many meshes, you don’t need to cycle through every set of vertices for every cube..

for (var i:int=cubeDatas[meshPartID].startIndex;i<cubeDatas[meshPartID].endIndex;i++)

My data object cubeDatas[] is what contains the information for each cube in my giant mesh, meshPartID is th index that represents my one cube, of many.
.start and .end represent the beginning number if the finalMesh subgeometries, before and after the merge

mergeNum FinalMesh.geometry.subGeometries[(FinalMesh.geometry.subGeometries.length-1)].vertexData.length/3;
   
merge.apply(FinalMeshtempMesh);
   
   
mergeNum2 FinalMesh.geometry.subGeometries[(FinalMesh.geometry.subGeometries.length-1)].vertexData.length/3;
   
   
cubeDatas[nameAsNumber]={startIndexmergeNumendIndexmergeNum2geometrys: (FinalMesh.geometry.subGeometries.length-1), geometrys2tempGeomvisibletrue }

As you see i have mergeNum and mergeNum2, that i store into start and end of my cubeDatas[] object. I figure out the cubes name through nameAsNumber.

Since I know my cubes will never have the same X Y Z coordinates, i figure out they’re name doing this:

nameAsNumber = (1000 tempMesh.x) + (1000000 tempMesh.y) + (1000000000 tempMesh.z

For lack of a better idea.

That is why you are only cycling through 1 cube x 24 vertices every time

 

   

sllik, Newbie
Posted: 22 November 2012 12:44 AM   Total Posts: 7   [ # 8 ]

yeah I need a way to move them all at once :/

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X