I am building a game that incorporates a randomly generated tile-based maze. It does this by first generating a grid of characters using a dungeon generator algorithm, and then steps through each character in turn generating boxes or quads (walls or floors) for each cell in the grid depending on its value.
I’ve had the algorithm working before fine, even using the GeometryBatchFactory however this time I get a really weird effect. Since the last version I have rewritten most of the engine around it (it only displays the map so far), but the core class for generating the 3D map has remained much the same.
Without optimising the nodes it works fine, however after calling optimise I get the following:
It is meant to look like this (sorry about the poor paint job, it takes fiddling to generate the same map twice):
This is just a small section of the map and I am splitting the map into nodes that incorporate a 10x10 section of the grid before optimising each node. If I optimise the entire map as one node I lose the bottom 3/4 rows from the map in much the same way as these small sections.
The weird thing is the meshes are still there, they just lose the material and turn black.
[java]
Node currentNode = new Node();
int xCount = 0;
int yCount = 0;
for (int row = 0; row < cells.length; row++){
xCount++;
for (int col = 0; col < cells[row].length; col++){
I don’t think you need to re attach the nodes after optimizing, the optimize method re-attaches the newly created geomtetry by istelf, so you may be doubling up on your geom, which would explain your flickering.
I’m not going to lie, I only glanced over your code looking for quick wins, sorry
I see what your doing now, it looks kinda of awkward , are you sure it’s attaching 10x10 blocks ? … since your x count only increases at the end of each row, I think you may be adding at at least 9 full rows before optimizing.
I would recommend you try pulling out all the optimize code and putting it after you have generated all your geometry, I think it could be complicating the issue where it is, and how its done. This should also result in better code separation.
Oh yeah you have a good point there, rookie mistake. Don’t think this is the issue though as if I optimise it all as one node I get this at the bottom of the map:
[java]
for (int row = 0; row < cells.length; row++){
for (int col = 0; col < cells[row].length; col++){
… and confirm that causes it to break (make sure you do the optimizing that way, not your original way, simply so I can eliminate possible causes). It just feels like there is duplicate un-optimized geometry floating around there somewhere.
Are you using the Unshaded material with no lights ?
cells is an array of chars that represents the generated map. processCell() takes a char and, depending on the character, creates either a box (wall) or a quad (floor) for that cell on the map. It then positions it accordingly with setLocalTranslation() and returns it so it can be added to the mapNode.
Alot of those settings are just the result of me fiddling, but I know it worked when I tried it before so I am 90% certain it’s not a problem with that code.