Menu

TriMesh physics

2006-09-29
2013-04-25
  • Felipe M. G. Ceotto

    Dear all,

    I've been trying to use the Brume's capacity to use ODE for TriMesh collision, with the BrumeCollisionTriMesh, but I can't get past its initialization. I always get a NullReferenceException. The line is: BrumeCollisionTriMesh physCastle = new BrumeCollisionTriMesh(this.CollisionWorld.CollisionSpace, castle.Mesh);

    Is there any initialization to the physics that I'm missing (I'm only setting the gravity before this)?

    My final goal is: I have a castle mesh (.X) and a character animated mesh (also .X), and I've loaded them into my scene. I want to make the character walk around the castle, using collision detection so that the character don't walk through walls. To do this, I'm trying to set the castle as a TriMesh and my character could be just a BouncingBox.

    Any help?

    Thanks!

     
    • Felipe M. G. Ceotto

      I've also just figured out something...
      If I have the following lines in my project:

      this.PhysicsWorld.SetGravity(0, -10, 0);
      this.PhysicsWorld.GeneratePhysicsBody(castle);
      this.CollisionWorld.GenerateCollisionShape(castle);

      Well, my castle should fall, shouldn't it? But it doesn't... I'm wondering if the Brume engine does what I'm looking for. By the way, the castle object is a BrumeLightedObject with a mesh that was set from a BrumeXMesh.

       
    • Bart

      Bart - 2006-10-01

      As far as I can see by looking at Brume source, I see that GeneratePhysicsBody only works for primitives like spheres and cubes. But there is a second method that takes an additional argument. Maybe you could try:
      this.PhysicsWorld.GeneratePhysicsBody(castle, BrumePhysicsParams.BODY_FROM_BOUNDING_BOX);

      This will take the mesh's bounding box (or sphere) and use that for the physics (I guess it will not look very accurate) but it will prevent other bodys from passing through your castle (or if they have enough force, your castle will start to move :-))

      Regards
      Bart

       
    • Felipe M. G. Ceotto

      Dear Bart,

      Thanks for your reply, but doing that won't do what I need. That will prevent my character from entering the castle, and will make the castle a box. What I want is to let the character in, but not through the walls, which is much more complex (that's why the TriMesh).

      Thanks for trying, anyway. If anybody else knows how to do this, please, I still couldn't do it.

       
    • Bart

      Bart - 2006-10-02

      As far as I can see, what you want is currently not supported by Brume. Or you must make your castle out of multiple primitives (box, spheres). Maybe you can access the ODE API directly (e.g. add a reference directly to ODE.DLL and see what it offers) Documentation can be found at http://www.ode.org/\)

      Good luck
      Bart

       
    • Felipe M. G. Ceotto

      Yeah, I am looking through ODE.NET already, but it would be really nice if it was possible to do it directly with Brume. I agree with you that it might not be currently supported, but if it's not, why is the BrumeCollisionTriMesh class available?

      So, I'm still keeping my hopes up. :)

       
    • Chris

      Chris - 2006-10-02

      Hi Guys !

      This class is available but it's 'work in progress'. I tried to use the ODE TriMesh structures but it doesn't seem to work.
      Notice that I tried just once...so there is huge place for further investigation ;o)
      I will take a look at this one tomorrow.

      Now for the collision & physics API :
        ceottaki : for your castle you will need the call to the GenerateCollisionShape(castle) in order to create the collision structure.
      This call doesn't crash on my system...but it has no effect (?). I mean that if I add a falling ball above my terrain it falls through it.

      The GeneratePhysicsBody is needed too. In this case, Bart is right : all you have to do is to assign a primitive shape (a cube ?) and put it into the physics engine (remember that it is just an abstract object that simulates your castle's behaviour...only collisions need a triMesh. FOr complex behaviours you have to add multiple objects with joints).
      One solution is to use the bounding box or bounding sphere like this :

      castle.AddBoundingSphere(new BrumeBoundingSphere(new BrumeVector(0,0,0), 20.0f));

      this.CollisionWorld.GenerateCollisionShape(castle, BrumeCollisionParams.SHAPE_FROM_MESH);
      castle.Mesh.InitEvent += new BrumeMeshSimpleDelegate(OnTriMeshInit);

      public void OnTriMeshInit(BrumeMesh mesh)
      {              this.PhysicsWorld.GeneratePhysicsBody(castle, BrumePhysicsParams.BODY_FROM_BOUNDING_SPHERE);
      }

      Notice that a delegate is needed. It's de to Brume's initialisation order : the ODE tri mesh is initialised after GameInit. Damn ! there is a lot of work to simplify this...

      But for the Castle you don't need physics so one way should be to set the mass to a huge value.....but wait ! I remember Bart's post about that and it's a bad practice ;o)
      So i will investigate this one too !

       
    • Felipe M. G. Ceotto

      Ok, Chris. Thanks for the extensive reply.
      I'll be waiting on the news about that work in progress then!

      Thanks again!

       

Log in to post a comment.

MongoDB Logo MongoDB