[Bugs] Morphable Entities

Post and discuss features you'd like to see in the BEPUphysics library.
Post Reply
twig314159
Posts: 7
Joined: Thu Apr 28, 2011 5:31 am

[Bugs] Morphable Entities

Post by twig314159 » Thu May 05, 2011 7:57 am

I'm combining compound and morphable entities in order to have a compound object that can change it's collision information at run time. Everything working well except for the following bug I've come across.

Bug - Updating CollisionInformation on a MorphableEntity does not cause the ModelDrawer to update the mesh data for that entity

From debugging, the InstanceModelDrawer (and I presume others) only captures the collision information mesh when the entity is added to the drawer.

In order to get around that, I decided to remove my entity from the drawer and then immediately add it back. It turns out this doesn't work because of a bug. The following code from ModelDrawer.cs fails because the objectToDisplay is still in the displayObjects collection even after calling Remove.

Code: Select all

        public ModelDisplayObjectBase Add(object objectToDisplay)
        {
            ModelDisplayObjectBase displayObject = GetDisplayObject(objectToDisplay);
            if (displayObject != null)
            {
                Add(displayObject);
                displayObjects.Add(objectToDisplay, displayObject);
                return displayObject;
            }
            return null; //Couldn't add it.
        }
The fix I found that works for me is to also remove the objectToRemove from the displayObjects collection. It's added to the displayObjects collection in Add, but it's never removed during Remove.

Old Code:

Code: Select all

        public void Remove(object objectToRemove)
        {
            Remove(displayObjects[objectToRemove]);
        }
New Code:

Code: Select all

        public void Remove(object objectToRemove)
        {
            Remove(displayObjects[objectToRemove]);
            displayObjects.Remove(objectToRemove);
        }
After compiling and running with the new code, a quick Remove immediately followed by an Add forces the ModelDrawer to use the new CollisionInformation for the MorphableEntity and it is then rendered properly.

Norbo
Site Admin
Posts: 4558
Joined: Tue Jul 04, 2006 4:45 am

Re: [Bugs] Morphable Entities

Post by Norbo » Thu May 05, 2011 7:33 pm

Thanks for the report!
The problem with removing/adding as well as another crash associated with removing with the InstancedModelDrawer should be fixed in the development version:
http://bepuphysics.codeplex.com/SourceC ... evelopment
(More info about crash here: http://www.bepu-games.com/forums/viewto ... f=4&t=1168)

The lack of updating collision shapes on change isn't a bug, but rather something intentionally left out. It may be added later and it wouldn't be really difficult to do, but it's not really a high priority :)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest