Changing Entity prefabs at runtime

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
indiefreaks
Posts: 8
Joined: Fri Aug 19, 2011 10:30 pm

Changing Entity prefabs at runtime

Post by indiefreaks »

Hi,

I'm currently working on a BEPUPhysics Manager for my framework (the Indiefreaks Game Framework http://igf.codeplex.com) for the SunBurn engine to replace the built in Collision system.

My goal is to provide a simple to use API that wraps most of the BEPUPhysics required processes so that SunBurn & IGF developers can easily plug Physics to their game entities.

I won't go into the details of the SunBurn scene graph but the idea is to plug BEPUPhysics entities inside this scene graph.

I'm therefore thinking on creating a dedicated component per prefab and per static & mobile meshes treatment so that developers just plug these components to their game entities depending on the game entity type (a box, a sphere, etc...).

But it seems that all the Prefabs require you to create them with their scale pushed to the Shape constructor and I would like to avoid doing so and instead automatically set them based on the game entity itself.

Since most of the game entities used in a SunBurn game will be models, should I use TriangleMesh.GetVerticesAndIndicesFromModel() to then compute the different sizes to apply to the Entity prefab?
Can I apply this information with an instance of an Entity or do I have to create the Entity with its constructor?

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

Re: Changing Entity prefabs at runtime

Post by Norbo »

Can I apply this information with an instance of an Entity or do I have to create the Entity with its constructor?
On some shapes, including the Box and Sphere, the shape can be modified after the fact by setting the relevant properties like Length or Radius. This also triggers an inertia tensor recomputation, so the new entity should behave as expected. Setting them up front in the constructor saves time and is the way to go if possible, though.

The EntityConstructionDemo in the BEPUphysicsDemos project (http://bepuphysics.codeplex.com/SourceC ... ionDemo.cs) shows a bunch of ways to handle the configuration of entities which may be helpful. In particular, an entity's Shape and Collidable can be created independently of the entity itself.

Also, while there is no universal "Scale" property common to all shapes, convex shapes which are otherwise difficult to re-scale (perhaps a MinkowskiSumShape or WrappedShape) can be put inside a TransformableShape which can apply arbitrary linear transformations to convex shapes. It does cost a bit more, though, and prevents special case collision detection systems like box-box from being used.
Since most of the game entities used in a SunBurn game will be models, should I use TriangleMesh.GetVerticesAndIndicesFromModel() to then compute the different sizes to apply to the Entity prefab?
I assume you mean compute a BoundingBox or BoundingSphere and use the sizes to inform the creation of a Box or Sphere. That is certainly doable, though it would likely be a rough approximation of a mesh that a human designer could improve upon. More complicated OBB-fitting algorithms would probably not be worth implementing.

Also, avoiding MobileMeshes in favor of simpler convex shapes or CompoundShapes of multiple convex shapes is a very good idea. Approximations using convexes or compound convexes will be a lot faster.
indiefreaks
Posts: 8
Joined: Fri Aug 19, 2011 10:30 pm

Re: Changing Entity prefabs at runtime

Post by indiefreaks »

Thank you Norbo for these precious information. They'll help me define the best design for my framework. You cleared most of my points and I'll keep you posted on my progress ;)

Thank you also for providing us with this great physics engine. Kick a** :p
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Changing Entity prefabs at runtime

Post by Norbo »

Thank you also for providing us with this great physics engine. Kick a** :p
No problem 8)
Post Reply