[Bugs] Morphable Entities
Posted: 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.
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:
New Code:
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.
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.
}
Old Code:
Code: Select all
public void Remove(object objectToRemove)
{
Remove(displayObjects[objectToRemove]);
}
Code: Select all
public void Remove(object objectToRemove)
{
Remove(displayObjects[objectToRemove]);
displayObjects.Remove(objectToRemove);
}