Page 1 of 1

Load entity from file

Posted: Sun Sep 04, 2011 5:41 pm
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

Re: Load entity from file

Posted: Sun Sep 04, 2011 5:47 pm
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.

Re: Load entity from file

Posted: Sun Sep 04, 2011 6:01 pm
by giulioz
i didn't understand a thing: how i can apply to a 3d model physics?

Re: Load entity from file

Posted: Sun Sep 04, 2011 6:29 pm
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.

Re: Load entity from file

Posted: Mon Sep 05, 2011 1:31 pm
by giulioz
an example?

Re: Load entity from file

Posted: Mon Sep 05, 2011 5:30 pm
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.