Load entity from file

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
giulioz
Posts: 5
Joined: Sun Sep 04, 2011 5:34 pm

Load entity from file

Post by giulioz »

Hi!

I need to create a physic entity loading a 3d model for shape and mass and other variable from file.
It's possible to do that?

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

Re: Load entity from file

Post by Norbo »

Yes, but I've avoided adding in direct serialization for entity types. I would recommend saving and loading the information you know you will need to reconstruct the scene externally.
giulioz
Posts: 5
Joined: Sun Sep 04, 2011 5:34 pm

Re: Load entity from file

Post by giulioz »

i didn't understand a thing: how i can apply to a 3d model physics?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Load entity from file

Post by Norbo »

If you're just looking to create a physical representation of a loaded 3d model, then you have a few choices.

1) Load the model for graphics only. Create an approximation out of simple primitives for the collision geometry that the physics engine will handle. You can use a CompoundBody containing BoxShapes and SphereShapes, for example. Transform the graphics using the entity's position and orientation.

2) Create convex hulls from the graphics model, or a simplified version of it. A single convex hull could be the collision shape for a whole model if the model is convex enough. If not, a CompoundBody of multiple ConvexHullShapes would be necessary. Note that keeping the geometry simple is important for performance.

3) You can technically create a MobileMesh from a model, but a MobileMesh that handles every triangle individually is going to be a lot slower in collisions than an approximation like #1.

To get an idea of how to construct entities in different ways, I would recommend checking out the BEPUphysicsDemos source in the main BEPUphysics download, in particular the EntityConstructionDemo.
giulioz
Posts: 5
Joined: Sun Sep 04, 2011 5:34 pm

Re: Load entity from file

Post by giulioz »

an example?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Load entity from file

Post by Norbo »

The EntityConstructionDemo in the BEPUphysicsDemos source (which comes in the main source download over at http://bepuphysics.codeplex.com/SourceC ... changesets) shows a bunch of examples of how to construct entities, including compound entities.

The important parts are setting up a compound's children and then making sure you position the graphic correctly relative to the physical representation. The compound constructors can output a position in various ways that tells you the local offset to apply to the graphic to align it with the physics.
Post Reply