CustomMesh disappearing

Hey there again. After solving my last problem i tumbled upon this one… I cant find any solution. I was working on that one for several days and found out most things myself but i have no clue why this happens…

I have a mazegenerator which creates me a 2D Array of ones and zeros representing empty and filled cells. Works fine.

I have a class MazeToMesh which generates two custom meshs out of this data:

One is the ground. Works fine.

One is the maze itself. Works fine.

Adding the individual meshes seperate results in fine display. Bt if i add both things like below whatever mesh added to the rootnode first just disappears. I dont have any clue why…

Any ideas? Below my code … As i said: The meshs themselfes are fine, they work individually but together they cripple. oO


MazeGenerator M = new MazeGenerator(25,25,1,1);

MazeToMesh M2M=new MazeToMesh(M.getGrid());

Geometry ground = new Geometry("Ground", M2M.getGround());

Material gmat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");

gmat.setFloat("Shininess", 0.3f);

gmat.setBoolean("UseMaterialColors", true);

gmat.setColor("Diffuse", ColorRGBA.Gray);

gmat.setColor("Ambient", ColorRGBA.DarkGray);

gmat.setColor("Specular", ColorRGBA.Red);

gmat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/tile.jpg"));



Geometry geom = new Geometry("TheMaze", M2M.getMesh());

Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");

mat.setFloat("Shininess", 0.2f);

mat.setBoolean("UseMaterialColors", true);

mat.setColor("Diffuse", ColorRGBA.Gray);

mat.setColor("Ambient", ColorRGBA.Gray);

mat.setColor("Specular", ColorRGBA.Gray);

mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/wall.jpg"));




I searched a bit more and found out, that the other object is rendered, when ever the first object ISNT rendered. So it can always only ONE object be rendered per time… Why is that? oô

This last part… how did you determine this? When is one of the objects not rendered?

The code looks fine at quick glance. I’m wondering if the custom meshes have had their updateBound() called. Maybe it’s a culling issue?

Either way, if you replace your custom mesh with a Box in the above code and you still get the “only one object at a time” problem then you at least will know it’s not your meshes. And if you don’t have the problem anymore then you will know that it definitely is.

1 Like

I just checked my meshes from different angles.

Whenever my ground was off-screen i could suddenly see my mazemesh. I further checked that…

In my mazetomesh class i call updateBound on the meshes after i set the Buffers. I believe thats how it was described in the tutorial about custom meshes.

I just added a box to the scene.

Its getting wierder and wierder… Now i can see everything as long as the box is in my view. When it goes off screen only the ground is rendered again. Im so confused by this problem… So puzzled. I cant sleep because i try to solve it.

Maybe i screwed something with the bounding of my mazemesh… But why is it rendered then, when i can see the box and isnt, when the box is off screen?

It still sounds like a bounding problem… if the box is at 0,0,0 then when you are looking at it then you are also looking directly at the root node. You could confirm that by putting some other boxes in the scene not at the origin.

…but if you are calling updateBound() after setting up your custom mesh then I don’t know why there would be a problem. Otherwise, we don’t have enough information to help. Normally this sort of thing “just works”.

The box is not at 0,0,0 its at 0,10,0.

What information would help you? I can upload screenshots from different cases, my sourcecode (per pastebin or rapidshar, since meshcreation is a long process), different debugmethods as long as you tell me, how i can debug the bounding volumes for example.

I used the intersect method of the boundin volumes btw. Even when world and model bound dont itnersect the error is there. As far as I know jME uses this information for culling…

So something is wrong somewhere…

I guess its a culling problem, but hell… i just dont get it, really.

I’m curious what getGround() and getMesh() is doing… and if there is anything else about your scene setup other than what you’ve shown.

getGround and getMesh just return the generated Meshes. Those are setup in the constructor of Maze2Mesh. Its plainly return Maze; or return Ground; Whereas Maze and Ground are Mesh’s.

My actual setting is tiny:

I attach the ground, the maze, a box and an AmbientLight.

Then i set the camera to (0,10,0) (i moved the box to (0,5,0) now) and let it look to the origin with lookAt. Further i set the movement speed. Thats all. SimpleUpdate() and SimpleRender() arent used at all atm.

Thats why it is so puzzling. Its the first time i encounter this kind of problem. I was pretty fine with jMEs way of handling the scenegraph till here…

Its just for testing causes atm, thats why i have everything in the simpleInitApp() method and i dont ignore walls not seen while generation (what i will later on since it can save loads of faces).

Any suggestions how i can debug this sort of problem? As i said: Its the first time i encounter that kind of problem.

getGround and getMesh just return the generated Meshes. Those are setup in the constructor of Maze2Mesh. Its plainly return Maze; or return Ground; Whereas Maze and Ground are Mesh’s.

That's the code I'm interested in seeing. Here's why:

1) There is nothing wrong that I can see with the code you've posted.

2) Adding regular meshes to the scene seems to work fine.

3) Your custom meshes do not work fine.

All evidence points to something wrong with your meshes. That may not be true but given just the code we've seen and the problem as described, that's the only direction we can look.

This presumes that nothing else other than what you've shown has been added to rootNode, ie: only mesh and ground are in root node other than the test boxes that you've added.

I understand that quite well. Its my first try with custommeshs so i dont know if what i’ve done is right. I cant believe that something is wrong though, since the mehses work fine as long as the other mesh is not added.

One thing to mention is, that im working with the newest nightly btw.

Well then: Here is my MazeToMesh class. Its quite ugly atm and needs some optimization but thats planned. :stuck_out_tongue:

If you need anything else just let me know. The int[][] is filled with 0 and 1. 0 representing a way, 1 a wall.

Here two screnshots:

It should be clear which is which. :smiley:

I don’t know why this would be the problem but on quick read I noticed:

maze.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(I));

But if you are building triangles then the 1 should be a 3.

Isnt that the Position-Buffer where a 3 should be? The indexes are saying which Position shall get used? I will try it out with that change, though.

Edit: Does not change anything.

The index buffer is saying how many positions per primitive. If you are making triangles then there are 3 verts per primitive.

1 Like

I did some more debugging.

It seems like the worldbound is not intersecting, but the modelbound is. The mehses are clearly not intersecting. Could it be the modelbounds arent updated properly?

Is the model or the world bound important?

PS: Thanks for the hint with the 3verts per primitive. You never stop learning. :slight_smile:

I don’t know… normally this stuff just works without issue.

Did fixing the index element count change anything? That might have been screwing with the bounds calculations.

I made the proposed change but it dosnt change anything.

I will do a quick cullcheck now…


public void simpleRender(RenderManager rm) {

System.out.print((maze!=null && maze.checkCulling(cam))?“Culling maze!n”:"");


Spits out “Culling maze!” even though the object is not rendered. Thats means, it is in the camera frustum and the engine knows it. So why is it culled anyway?

Without some deep tracing and/or a lot more time than I have at the moment, I’m not sure what else to say.

Adding custom meshes to a scene is usually not so hard. I do it all the time and have never run into this issue. So something weird is going on. If you can reduce it to a minimal test case and post it then maybe others can play too and may see something I didn’t.

Haha…what the hell.

When i set the material to unshaded it works. It works totally fine then! The maze is rendered all the time its in camerafrustum.

So its a material issue? Or a light issue?

This case rly puzzles me.

pastebins not working right now so I can’t look.

If you are using Lighting.j3md then you will need a light in your scene and your mesh will need normals. Without one or the other, strange things may happen.

I have a ambientlight added to the scene.

I thought the normals are automaticly computed and thats why the order of vertex adding is important. Do i have to fill the normal-buffer myself? If so: Why isnt the ground bugged then?