About Store Forum Documentation Contact
Donations:
197$/mo



Post Reply 
Dynamically Constructing the Destructible Object
Author Message
ronghester Offline
Bronze Supporter

Post: #1
Dynamically Constructing the Destructible Object
I could not find any relevant topic regarding this. so creating a new topic..

How to dynamically construct a destructible object using the code? for example I can create a game items dynamically like

Game::ObjParamsPtr obj=Game::Objs.ptrRequire("Obj/Item/Weapon/Blunt/Club/0.obj");
Game::Item * tem = (Game::Item*)Game::World.objCreateNear(*obj, Matrix(obj->scale(), Vec(0, 1, 0)));


In the same way how can i create a destructible objects using the *.destruct file.

One other thing, is it possible to construct a destructible object using a ragdoll of a character?
08-07-2013 08:38 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #2
RE: Dynamically Constructing the Destructible Object
I didn't try make any destructable object by myself yet, but maybe I can help you.

Quote:How to dynamically construct a destructible object using the code?
I think you can use DestructMesh :

Code:
DestructMesh& create(Mesh &mesh, Int cuts, MaterialPtr material, Flt tex_scale=1, Int phys_vtx_limit=-1, Bool cut_affects_biggest_part=true); // create destructible object from 'mesh', use 'cuts' number of plane cuts to split the mesh, use 'material' for creating the solid inside part with 'tex_scale' texture scaling, 'phys_vtx_limit'=limit for number of vertexes in each physical body part (used only when >0), 'cut_affects_biggest_part'=if apply cutting to the biggest part only or the whole mesh

Next you could for example create own class inherit from Game::Destructable and link destruct data in constructor

Code:
MyDestructClass : GameDestructable

MyDestructClass::MyDestructClass() {
   mode         =STATIC;
   piece_index  =-1;
   scale        = 0;
   destruct_mesh= PointerToMyDestructMesh;
}

Quote:In the same way how can i create a destructible objects using the *.destruct file.

add "destruct" Params to Object in Editor with path to destruct file, and use Destructable class to handle it;

Quote:One other thing, is it possible to construct a destructible object using a ragdoll of a character?
As I remember DestructMesh will create destructable parts randomly.

But I belive this is possible, but it will cost you a lot of code to write. (It's not supported by Esenthel Engine, you have to made DestructMesh by yourself, cuts mesh manualy)

Also in "Game Object Classes Source Code" you will find source code for Game::Destructable.
(This post was last modified: 08-07-2013 10:20 AM by Pherael.)
08-07-2013 10:20 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #3
RE: Dynamically Constructing the Destructible Object
Just buy the Game Objects source code. It's all there.

Edit: Oh nevermind, it doesn't seem to be available anymore.
(This post was last modified: 08-07-2013 04:36 PM by aceio76.)
08-07-2013 04:34 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #4
RE: Dynamically Constructing the Destructible Object
I believe Game Object Source is available under the 2.0 license, separate download from the EE editor but in the same window as Esenthel2.0 engine is.
08-07-2013 05:23 PM
Find all posts by this user Quote this message in a reply
TheElk Offline
Member

Post: #5
RE: Dynamically Constructing the Destructible Object
yes you are correct Zervox

and thank you did't see that.

TheElk
08-07-2013 08:34 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ronghester Offline
Bronze Supporter

Post: #6
RE: Dynamically Constructing the Destructible Object
Thanks all, I just realize the source code can be downloaded from there.
@pherael thank that helped me a lot.
08-07-2013 10:23 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #7
RE: Dynamically Constructing the Destructible Object
Ok sorry if it's a stupid request, but I just can't get it to work;
Can someone please post some actual code that would create a destructible object? I either manage to get a crash when the object is created, or it is created but it it not displayed. And it's not the object to blame, if I declare it as static for example it works.
This is my code, in the create function:

mode=BREAKABLE;
piece_index=-1;
super.create(obj);
// destruct_mesh.create(*mesh, 5, T.material, 1, 8, true);

Like this, it creates the object but I can't see it. If I uncomment the last row, it crashes at run-time. I'd really appreciate some working code, I'm sure I can figure what I'm doing wrong if I can see something done right.
10-04-2013 10:07 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #8
RE: Dynamically Constructing the Destructible Object
Is this your own class inherit from Destructable? You should show some more code.

You can try something like this (not tested, only idea in my head)
Code:
mode       =DEFAULT_MODE;
   piece_index=-1;
   scale      =obj.scale   ();
   mesh       =obj.mesh    ();
   material   =obj.material();
   phys       =obj.phys    ();
   destruct_mesh.create(*mesh, 5, T.material, 1, 8, true); //<- destruct mesh shoul be create before before super.create if you inherit from Game.Destructable
   super.create(obj);

But this make you copy scale, mesh, material and phys twice;

So you should make you own function something like this (code from "Game Object Classes Source Code")

Code:
void create(ObjParams &obj)
{
   mode       =DEFAULT_MODE;
   piece_index=-1;
   scale      =obj.scale   ();
   mesh       =obj.mesh    ();
   material   =obj.material();
   phys       =obj.phys    ();

   Matrix matrix=obj.matrixFinal().normalize();

/*CREATE DESTRUCT_MESH HERE #################################################
destruct_mesh.create(*mesh, 5, T.material, 1, 8, true);
*/

   if(mode==BREAKABLE) // create as BREAKABLE
   {
      if(destruct_mesh)
      {
         // create actors
         FREP(destruct_mesh->parts())actors.New().create(destruct_mesh->part(i).phys, 1, scale)
                                                 .matrix(matrix)
                                                 .obj   (this);
         // put actors to sleep
         REPAO(actors).vel(Vec(0)).angVel(Vec(0)).sleep(true);
      }
   }else
   if(mode==STATIC) // create as STATIC
   {
      if(phys)actors.New().create(*phys, 0, scale) // create main actor
                          .matrix(matrix)
                          .obj   (this);
   }else
   {
      Exit("Unrecognized Destructible Mode");
   }
}

Didn't test it, sorry if it will not work.
(This post was last modified: 10-04-2013 10:49 AM by Pherael.)
10-04-2013 10:45 AM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #9
RE: Dynamically Constructing the Destructible Object
No, neither method seems to work. Creating the destruct_mesh crashes it, no matter where i put it; I even tried with a manually created mesh in game init. It sucks that I don't know this, but I managed without destruct for now. I found an alternative to what I needed.
10-04-2013 05:58 PM
Find all posts by this user Quote this message in a reply
Post Reply