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