[SOLVED] Some basics questions


Recommended Posts

Hello everyone !


I have some basic questions for you if you could help me :)


- I'm loading meshes on the fly by script using this code :

Object obj = new ObjectMesh(filePath)) ;
if (obj != NULL)
engine.editor.addNode(obj) ;
obj.setName(name) ;
obj.setMaterial(material, "*") ;
obj.setProperty(property) ;


Actually, it is really simple. This code works well (meshes are correctly loaded and displayed) but if i call with correct arguments :

engine.world.getIntersection(p0, p1, ~0, ret) ;

I can't have any intersection at all.


If I call :

engine.editor.getIntersection(p0, p1, ret) ;

it works but it's not really what I want and I get a node instead of an Object ...


Also, if I put the mesh loading in the .world file, everything works well.


So, what is the good way of loading node on the fly please ?



- On the first call to getIntersection, Unigine freezes for 3/4 seconds (I really have complex 3D objects) and I see the memory usage that grows in the profiler the next frame.

I assume that Unigine builds some tree to optimize intersection detection but the freeze is really annoying at runtime.


Is it possible to better understand what is going on and maybe optimize it in init / loading process ?



Thank you for your time !

Link to post

If I remember correctly, you should call engine.world.updateSpatial() after engine.editor.addNode(obj) ;

Link to post

Thanks for your suggestion Steve, but unfortunately calling the updateSpatial method don't resolve my issue :(

Link to post

You're right and I'm already using it (but it was truncated for the example code above :().


Anyway, the problem is still present with it.

Link to post



Make sure you have 'intersection' flag enabled on your property which is assigned on mesh surfaces, also you need at least one surface with 'intersection' flag enabled.

Link to post



Yes intersection flag is enabled on both surfaces and node (only have one surface at the moment);

Link to post

this should be the general rule for concrete problems like this, otherwise most of the time it's just blind guessing

Link to post

I was building the test world when I found out what was wrong !


When loading on the fly my meshes, I was calling :

   	obj.setProperty("surface_base") ;


But it Is not the good method to set a property of a surface and thus allowing it to be intersected.

Here is the good one :


   	obj.setProperty("surface_base", "*") ;



However, my other problem is still present : on first mouse over, Unigine freezes for some time and then run perfectly smoothly. What I would want is to perform the "freeze calculations" during the init method but not at render.


Please find enclosed the test directory including the world file, its cpp code and the content that lead to this behavior.



Thanks you !


Link to post

Thank you :D


Do you think its a bug ?


If you want, I think I could give you some more complex meshes objects if it could help ;)

Link to post

Oh, this mesh is complex enough :)


Actually it's very complex to be efficiently handled in real time. On the first calculation of intersection, a binary spatial tree is created for mesh surfaces and then polygons. You've got around 500k triangles (!) - no wonder it takes some time to create BSP. What you can do about it is:

  • Calculate first intersection in the init(). BSP will be created at once, and on first calculation in update(), there will be no stall.

int init()
return 1 ;

  • Optimize your art. There are parts where your mesh is definitely too dense and decreasing the number even won't compromise the visual quality.
  • If it's essential that you use such high-poly meshes, you can simply add a hidden surface, very rough and plain, purely for calculating intersection. Then you'll simply need to disable intersections with the main mesh surface. Adding a dummy collision/intersection geometry really helps when it comes to intersecting with complex models.

Link to post



Thanks for theses explanations !


I totally agreed that these models are way too complex and really really dense for no reason. I tested them because some times clients have very very poor DMU that we have to work with ... (I have one with 1000K triangles ... makes other people crazy).


Will definitely look into hidden surface for fastest meshes collision :)



Thanks !

Link to post