# Optimizing large number of ModelRenderable cubes with ARCore?

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:

1. Removing all of the cubes that had no empty space around them since they would be invisible.
2. 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.
3. Hiding all of the cubes that are hidden behind other cubes. I don't yet understand the math behind this.
4. 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.

• You say you're aware of the "lots of questions already answered about this kind of optimization" — how have you tried applying these existing answers to your case so far? I assume based on these answers you've chosen one specific optimization approach that seems promising to try first? What specific steps have you taken to understand and implement that approach, and what one step are you currently stuck on? – DMGregory Jul 5 at 13:39
• @DMGregory I am stuck on finding details on things such as in-code control over culling in the ARCore platform. I have taken the steps of trying to remove the cubes that won't be visible because they're completely surrounded, which helps, but it won't be entirely sufficient long-term. I have done some searching on culling in ARCore and it seems to be something that the documentation only describes as controllable in the Material JSON files, which I am not using. I am also unsure of the implementation of determining which cubes the camera cannot see in this context. – David Reidsma Jul 5 at 14:17
• Great, then instead of listing everything you can think of in your question, edit it to ask about the one specific issue that's blocking you currently. You can always post a second question for the next issue you're stuck on, if the answers you get on the first issue don't take you the whole way. A narrow focus helps you get answers faster, and they'll tend to be more useful to you, rather than repeating generalities you've already gleaned from past answers. – DMGregory Jul 5 at 14:21
• By the way, the culling parameter in the material files you describe sounds like it's backface culling (removing faces that face away from the camera). This is not the same as occlusion culling or hidden surface removal, which sounds like the problem you're trying to solve. – DMGregory Jul 5 at 14:22
• I'm voting to close because as written, the question solicits a very broad general discussion about block world optimizations without identifying a specific problem to solve and then asks "should I use ARCore or Unity?" – Pikalek Jul 5 at 15:54