changing scale of mesh at runtime

May 14, 2011 at 8:14 PM

Hey everyone,

I noticed something today that I think *might* be a bug.   In my game, at runtime, I can add a new mesh into the world. This is working great. Now in my game the user can ‘select’ meshes by clicking on them. I use the Geometry.Intersects method to detect if a specific mesh has been clicked. This is also working great. The trouble comes in when I try to dynamically resize the mesh at run time. (Say I make it bigger) Now I do this by adjusting the property on the mesh called World. If I scale up a mesh in this way the Geometry.Intersects method no longer detects a mesh intersection.

What I believe to be the trouble is the bounding sphere of the mesh. This is not calculated when the mesh intersection test is done, but pre-calculated some other time. When I change the world matrix on a specific mesh, this bounding sphere stays the same. Since I’m increasing the size of the object, I would expect the bounding sphere to grow.

Now the weird thing about this is that I can turn on bounding spheres (as a test) to view them as I move around my world. It would appear that the bounding sphere IS being calculated correctly for the drawing. Just not when intersection tests are done.

Does Balder support directly setting the world matrix on a mesh? If so, shouldn’t the bounding sphere either be adjusted, or recalculated for an intersection test?

Thanks for any advice anyone can offer.

 

May 14, 2011 at 9:01 PM

Here is a quick demo that shows the trouble.  I've build this with the latest source, but you'll need to fix the reff. for this to work on your machine. (I didn't include the Balder files)

NOTES:
Notice you can make the box larger and smaller by clicking on the two buttons at the top.
When you click the box (BEFORE you resize, Balder reports the distance to the object)
When the object is made SMALLER this continues to work. (size <= 1)
When the object is made LARGER you can no longer click it.  (size > 1)

http://zerfservices.com/TestMeshScale/BalderTestMeshScale.zip

Coordinator
May 20, 2011 at 9:35 PM

The handling of bounding spheres are lacking the transformation of what is known internally as the ActualWorld, so scaling things won't matter for the bounding sphere - I'm afraid. 

May 20, 2011 at 9:39 PM

Thanks for the reply!

Does this mean that the interection methods will not work for any mesh with a world transformation on it (if it's scaled up)?  Is this a bug, or expected?  I'm still new to 3d so I'm not sure how it's suppose to work.  Do you have any advice on how to scale up a mesh but keep the intersection methods working?

Thanks for your help!

Coordinator
May 20, 2011 at 9:41 PM

This is a bug - and I'm afraid there is not much to do about it, except fixing the bug..  

May 20, 2011 at 10:00 PM

Thanks Adept,

I didn’t mean any offense by my above statement. I was just making sure I understood that this was a bug and not expected behavior. I’m not sure I can fix this myself but I’ll be happy to give it a try! If I’m able to get anything I’ll be sure to post it.  Thanks for all your hard work.  I know it must get a bit overwhelming at times.

Coordinator
May 20, 2011 at 10:19 PM

No offense taken. :)    Just short on time these days, so short answers..   

I love getting reports and feedback - its just been stressful with a lot of different stuff lately. But the calendar is clearing up, and a brighter Balder future ahead.. :)  

 

Basically, if I'm not mistaken - the bounding spheres is a bit of hack today. They are structs if I'm not mistaken, and they are therefor calculated on the fly when needed, both for interaction and rendering. And I believe they are using the wrong matrix when calculated. Could be as simple as switching to using the ActualWorld matrix property on the node itself.  Not 100% sure though.    If you figure it out, I'd love a patch file from you - or a pull request if you have a fork.