Page 1 of 1
A House / Building source code ?
Posted: Thu May 16, 2013 12:49 pm
by kavatortank
I have a question,
Have you got a source code for a house or a building ?
Re: A House / Building source code ?
Posted: Thu May 16, 2013 7:34 pm
by Norbo
The StaticMeshDemo would be the most relevant example. Structures are not usually built out of a bunch of separate entities like boxes and spheres; instead, they are constructed from loaded meshes.
If you do want to use a bunch of primitives to make a structure rather than a mesh, the StaticGroupDemo would be useful. The StaticGroup allows the combination of thousands of static collidables- boxes, meshes, and everything else- into one efficient representation.
Re: A House / Building source code ?
Posted: Thu May 16, 2013 8:16 pm
by kavatortank
Okay,
And bepuphysics engine can do breakable sets like house, buildings, etc ... ? Because staticMesh is static ^^ and can't be breakable, no ?
Re: A House / Building source code ?
Posted: Thu May 16, 2013 8:23 pm
by Norbo
Destructibility is often accomplished by swapping from the static representation to a 'destroyed' version with optional dynamic debris. This gives you maximum performance when everything is static, while still letting you blow stuff up.
There's nothing built in to help manage this, but it's pretty easy to do. For example, just add/remove objects as needed when the associated gameplay object goes below a certain "HP" value.
More advanced forms of destructibility, like stress-based fracture, are also possible, but are quite a bit harder to implement than the swapping approach. I have an implementation of dynamic compound fracturing used in a little prototype spaceship game which uses such a system quite effectively; that's where the CompoundHelper splitting stuff came from. I've been intending to polish this implementation up and release it as part of BEPUphysics but I haven't yet gotten around to it- but it is definitely possible!
Re: A House / Building source code ?
Posted: Thu May 16, 2013 8:33 pm
by kavatortank
Norbo wrote: I've been intending to polish this implementation up and release it as part of BEPUphysics but I haven't yet gotten around to it- but it is definitely possible!
You don't have a little source code for me ?

Re: A House / Building source code ?
Posted: Thu May 16, 2013 8:38 pm
by Norbo
The fracture system really isn't fit for public consumption; releasing such features prematurely tends to cause more work for me than actually getting them to a usable state first
Also, the swap-based destructibility is actually a better fit for many games anyway. It's simpler, easier, faster, and more controllable.
Re: A House / Building source code ?
Posted: Thu May 16, 2013 8:43 pm
by kavatortank
Norbo wrote:Destructibility is often accomplished by swapping from the static representation to a 'destroyed' version with optional dynamic debris. This gives you maximum performance when everything is static, while still letting you blow stuff up.
But it does not support the point of impact. Imagine, a tank shoots a building and the replacement model has a destruction which is not located at the site of impact, the report will be poor, right? There is no better solution?
Re: A House / Building source code ?
Posted: Thu May 16, 2013 8:57 pm
by Norbo
That is easy enough to handle by swapping out the affected section of the mesh, rather than the entire mesh. You can make the destructibility as detailed as you desire.
There's no way around designing the destructible pieces with the desired level of detail, unless you want to go for pure procedural object fracture- that is, taking a single volume and making it many without designing the result at content creation time. This is doable, but is much harder than even the dynamic compound fracturing I referred to previously. In addition, the results are somewhat difficult to control- you'd probably end up designing 'destructible pieces' just to help guide the procedural fracturing process.
Another difficulty step above that would be to just run full FEA, with volumetric elements constructed procedurally from source content according to some material properties. Then, you could add a bunch of fancy tricks that would end up making it look something like DMM by Pixelux. Of course, to get there, you'd spend about as much time working on it as Pixelux did.

Re: A House / Building source code ?
Posted: Thu May 16, 2013 9:07 pm
by kavatortank
Hum... I'm waiting for you source code men.
Are you sure that you don't have any sample using bepuphysics ?
Re: A House / Building source code ?
Posted: Thu May 16, 2013 9:16 pm
by Norbo
Hum... I'm waiting for you source code men.
I would not recommend waiting on me to release that dynamic compound splitting thing. The first version of it was made back in mid 2011
Are you sure that you don't have any sample using bepuphysics ?
I do not have a sample available showing swap-based destructibility, but it is very simple. All that has to be done is: 1) remove the 'healthy' version, 2) add the 'destroyed' version, 3) toss any extra debris in there that you want.
You can choose however much detail you want. For example, you might have a car just be one whole destructible object which has one healthy and one destroyed version. But for a house, you might decide to make each wall have its own healthy and destroyed state, so that you can blow them up independently based on where an impact occurs. Or perhaps each wall has ten separate chunks, so that you can destroy individual pieces of each wall.
Re: A House / Building source code ?
Posted: Thu May 16, 2013 9:49 pm
by kavatortank
I didn't understand how you know where a object collide in a other object, can you help me ?
Re: A House / Building source code ?
Posted: Thu May 16, 2013 9:57 pm
by Norbo
You could use either use
collision events or check a collidable's contacts.
For the latter option: every collidable knows the list of collision pairs in which it is involved. These are stored in the Pairs list. For example, to get the pairs an entity is involved with, you check the entity.CollisionInformation.Pairs list, because the CollisionInformation property returns the collidable associated with the entity. Another example: a StaticMesh is a collidable itself, so you can just check StaticMesh.Pairs.
Each one of those pair objects has a Contacts collection. If there exist any contacts in that collection with a nonnegative penetration depth, then the pair of objects is touching. (Note that you cannot merely check the Contacts.Count to know if two objects are touching in general: contacts may have negative penetration depth, representing a speculative contact. Speculative contacts are used for stability and continuous collision detection purposes, but do not represent a current collision.)
For an example, check out the CharacterController's QueryManager; it performs this kind of scan to look for supports.
Either way you do it, the contact data tells you the collision position and other information.