[Fixed]Custom mesh disappearing from certain angles

Hi All,



I’ve got a custom mesh created as per the tutorial (although somewhat more complex.



The mesh is animated and moves around - after each move I call update bound



[java]

if (modified != UpdateResult.NONE || tpf == 0) {

mesh.setBuffer(Type.Position, 3, pointsBuffer);

mesh.updateBound();

}

if (modified == UpdateResult.BOTH || tpf == 0)

mesh.setBuffer(Type.Color, 4, colorsBuffer);

[/java]



Everything looks fine at first but if I move the camera so it is no longer viewing the area where I first created the mesh (the geometry localTranslation does not move but the points within it do) then the mesh disappears from screen.



I’m working on the theory that it’s being culled, which means the bounds aren’t up to date - but I thought that’s what updateBound was supposed to fix?



Any suggestions?



Thanks,

Z

I guess the bounds are not updated. Try doing that (on the geometry maybe?) after setting the mesh buffer.

I call updateBound on the mesh. Do I need to do it on the geometry too/as well/instead?



Shouldn’t the call propagate upwards if it needs to?

I’ve noted something similar to a mesh I’ve done. Afaik it wasn’t doing this before, but it’s possible I’ve overlooked that.



The mesh itself doesn’t move, but it’s parent node is rotated. Because of that I’m wondering if there’s something that has changed that could be doing that.



I do update its bound after the mesh’s creation.

@normen said:
I guess the bounds are not updated. Try doing that (on the geometry maybe?) after setting the mesh buffer.


I just checked and Geometry has no updateBounds() method, there is one on the mesh but I'm already calling it. Maybe it's broken?

updateWorldBounds

Doesn’t exist (according to ctrl space anyway). Only one is updateModelBound and updateGeometricState and both have a warning attached saying updating is not needed.

it’s protected

1 Like

Shouldn’t mesh.updateBound cause geometry.updateWorldBound to happen automatically?



If not then shouldn’t updateWorldBound be public and mentioned in the tutorial on custom meshes?

Don’t call mesh.updateBound() call geom.updateModelBound()

it updates the mesh bounds then set the flag to refresh the bound on the geometry

the world bounds will be updated in the next update loop, updateWorldBound is not supposed to be called directly by users…

4 Likes
@nehon said:
Don't call mesh.updateBound() call geom.updateModelBound()
it updates the mesh bounds then set the flag to refresh the bound on the geometry
the world bounds will be updated in the next update loop, updateWorldBound is not supposed to be called directly by users..


Ok, I can confirm that this fixes the problem. There is a warning on updateModelBounds saying I should never need to call it though... ?
@zarch said:
There is a warning on updateModelBounds saying I should never need to call it though... ?

mhh? where?
i only see this
[java]
/**
* Updates the bounding volume of the mesh. Should be called when the
* mesh has been modified.
*/
public void updateModelBound()
[/java]

Yeah this should be right normally, that comment is a bit too general and should probably be more specific about custom meshes.

Added:



If modifying a mesh dynamically in a way which would change the model's bounds then you need to call updateModelBound() on the Geometry object containing the mesh after calling updateBounds() on the mesh object. There is a warning on updateModelBounds about not usually needing to use it but that can be ignored in this special case.


to the wiki page. https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes
4 Likes

Thanks for updating the wiki

I’ll try that.



Thanks.

It seems the error was mine as I wasn’t calling updateBound() in my “updatePosition(…)” method.