I am creating an ARCore Android app that involves rendering up to thousands of cubes, of course using a Node and ModelRenderable object for each. Understandably, I'm unable to do that without running into memory issues, so I'm looking for ways to optimize. Ideas I've had so far are:
- Removing all of the cubes that had no empty space around them since they would be invisible.
- Investigating into some sort of culling (which I don't know much about) to not render the sides of the cubes that are invisible. I don't know if ARCore will already do this.
- Hiding all of the cubes that are hidden behind other cubes. I don't yet understand the math behind this.
- Grouping cubes of the same type into larger cubes. In one example, there might be 16x16x16 rendered on the screen. Each cube is an individual unit with its own type. So in relation to my grouping idea, I would take all the cubes that have the same type would be replaced with one larger cube or cuboid.
I've tried removing all of the cubes that have no empty space around them, as those will not be visible. Long term, however, this will be insufficient.
I don't have a lot of code to show that's related as this question is more looking for ideas to write code, but basically I'll be having a very large number of:
// Where position is a Vector3 and material is a Material object. ModelRenderable cube = ShapeFactory.makeCube(new Vector3(CUBE_WIDTH, CUBE_WIDTH, CUBE_WIDTH), position, material); Node node = new Node(); node.setRenderable(cube);
I'm not creating a new material every time, I generate those at startup.
I understand there are lots of questions already answered about this kind of optimization, but I haven't been able to find much about the implementation of things such as culling and hiding blocked cubes in the context of ARCore. Would I be better off using Unity?
If anyone has advice or ideas, I'd love to hear them.