Thousands of Cubes

Software: Away3D 4.x

shoey, Newbie
Posted: 26 March 2014 12:07 AM   Total Posts: 5

Hello Community!

I am trying to reproduce this example that was made in Flare3D using the Away3D engine, which renders over 50,000 cubes using what they call a CubeMesh:
http://wiki.flare3d.com/index.php?title=Test18_-_CubeMesh

I tried to do this by creating the same amount of CubeGeometry Meshes in a ObjectContainer3D, however at around 5,000 cubes I get a ‘Error #3691: Resource limit for this resource type exceeded.’

I’m not sure if there is an equivalent to Flare3D’s CubeMesh in Away3D, or if this is possible in Away3D. Any kind of advice is greatly appreciated!

Thanks!

   

shoey, Newbie
Posted: 26 March 2014 10:38 PM   Total Posts: 5   [ # 1 ]

I overlooked the example code, I see now that the CubeMesh is a custom class that extends Flare3D’s Mesh3D class. I’m not at all familiar with Flare3D so I didn’t have any luck trying to convert the custom class for away3D.

I was able to get past my previous error by creating clones of a single CubeGeometry Mesh, although I now have performance issues with around 10,000 cubes.

Can anyone please suggest a way to increase performance when trying to render over 10,000 cubes? I’ve read that merging all your objects into a mesh helps a lot but won’t this mean I’m forced to make all my cubes the same color?

Thanks!

   

shoey, Newbie
Posted: 27 March 2014 08:33 AM   Total Posts: 5   [ # 2 ]

I was able to recreate the example by merging all the cubes into a single mesh, runs smooth.

   

Avatar
theMightyAtom, Sr. Member
Posted: 27 March 2014 09:39 AM   Total Posts: 669   [ # 3 ]

Hi Shoey,

If you make all the cubes share the same geometry, that should be even better!

Something like…

var cubeGeom:CubeGeometry = new CubeGeometry();
var 
cubeMat:ColorMaterial = new ColorMaterial();
  
private function 
createCubes():void {
 
var i:uint
 var 
m:Mesh;
    
 for (
010000i++) {
  m 
= new Mesh(cubeGeomcubeMat);
  
View3D.scene.addChild(m);
  
}

The point is that in the drawing cycle the GPU can use the exact same geometry, which *should* give even better performance (or at least use less memory) than merging.

Good Luck!

   

OEGInc, Newbie
Posted: 27 March 2014 05:47 PM   Total Posts: 27   [ # 4 ]
shoey - 27 March 2014 08:33 AM

I was able to recreate the example by merging all the cubes into a single mesh, runs smooth.

How did you manage to do that?  I was attempting to do something similar, but I had the same performance issues…

 

   

shoey, Newbie
Posted: 28 March 2014 12:33 AM   Total Posts: 5   [ # 5 ]
OEGInc - 27 March 2014 05:47 PM
shoey - 27 March 2014 08:33 AM

I was able to recreate the example by merging all the cubes into a single mesh, runs smooth.

How did you manage to do that?  I was attempting to do something similar, but I had the same performance issues…

This is how I did it.. Create 50,000 cubes using the same CubeGeometry and add them to a container, then merge the containers into a mesh:

var cubeGeom:CubeGeometry = new CubeGeometry(5,5,5);

var black_material:ColorMaterial = new ColorMaterial(0x111111, 1);
var white_material:ColorMaterial = new ColorMaterial(0xEEEEEE, 1);

var black_cubes:ObjectContainer3D = new ObjectContainer3D();
var white_cubes:ObjectContainer3D = new ObjectContainer3D();

for(var i:int = 0; i < 50000; i++)
{
var cube:Mesh = new Mesh(cubeGeom);
   
var x:Number = Math.random() * 1000 - 500;
var y:Number = Math.random() * 1000 - 500;
var z:Number = Math.random() * 1000 - 500;
cube.x = x;
cube.y = y;
cube.z = z;

var color:Number = Math.random();
if (color < .5) {
  cube.material = black_material;
  black_cubes.addChild(cube);
} else {
  cube.material = white_material;
  white_cubes.addChild(cube);
}
}

var merger:Merge = new Merge(true); //true value keeps applied material
var merged_mesh:Mesh = new Mesh(null);

merger.applyToContainer(merged_mesh, black_cubes);
merger.applyToContainer(merged_mesh, white_cubes);

scene.addChild(merged_mesh);

   

shoey, Newbie
Posted: 28 March 2014 12:43 AM   Total Posts: 5   [ # 6 ]
theMightyAtom - 27 March 2014 09:39 AM

Hi Shoey,

If you make all the cubes share the same geometry, that should be even better!

Something like…

var cubeGeom:CubeGeometry = new CubeGeometry();
var 
cubeMat:ColorMaterial = new ColorMaterial();
  
private function 
createCubes():void {
 
var i:uint
 var 
m:Mesh;
    
 for (
010000i++) {
  m 
= new Mesh(cubeGeomcubeMat);
  
View3D.scene.addChild(m);
  
}

The point is that in the drawing cycle the GPU can use the exact same geometry, which *should* give even better performance (or at least use less memory) than merging.

Good Luck!

Thanks I updated my code to do this, The performance is equal but this makes more sense anyways.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X