Skip navigation
Currently Being Moderated

How using loaded mesh to create a shape for a rigidbody ?

Oct 16, 2011 10:03 AM

I want to load a mesh, and use its shape in order to create a rigidbody. Is there a solution to pass a vertex array for example to create a shape. If so, what class I need to use ? (com.adobe.pellet.collision.shape.bt... )

I can use a primitive shape for my rigidBody, but I want my object stands on its own faces.

 
Replies
  • Currently Being Moderated
    Nov 3, 2011 3:14 AM   in reply to YannickFR1

    Even, I am looking a way to treat the loaded model (.obj) as rigidbody.

     

    Basically, I am loading "PalmTrees.obj" and I've rolling ball. I want my ball to interact with these PlamTrees - ball should not cross over the tree.

     

    Please help.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 4, 2011 1:38 AM   in reply to bhavesh4u

    I got the reference of SceneNode and now using createRigidBody, I want to convert it to rigidbody - so that I can apply mass.


    But, I am not able to grip the third parameter which says -

    public function createRigidBody( obj:SceneNode, mass:Number, shape:btCollisionShape ):btRigidBody

     

     

    // I've reached till here...

    var tree:SceneNode = new SceneNode( "PalmTrees" );

    var rigidTree:PelletRigidBody = mPellet.createRigidBody(tree, 0, WHAT_GOES_HERE??);

     

    Any idea?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 5, 2011 3:37 AM   in reply to YannickFR1

    Finally, its done !!!

     

    Here is the code to extract the mesh data from loaded model and apply rigidBody to it.

     

    I used "TestPhysicsStaticMesh.as" class from Proscenium Samples folder to get this done.

     

    //=======================================

     

    _modelLoader = new OBJLoader( "../res/content/PalmTrees/PalmTrees.obj" );

    _modelLoader.addEventListener( Event.COMPLETE, loadComplete);

     

     

    protected function loadComplete( event:Event ):void

    {

              var tree:SceneNode = new SceneNode( "PalmTrees" );

              var manifest:ModelManifest = _modelLoader.model.addTo( tree );

              var scale:Number = 2;

              for each (var boatMesh:SceneMesh in manifest.meshes)

              {

                        var indices:Vector.<uint> = new Vector.<uint>;

                        var vertices:Vector.<Number> = new Vector.<Number>;

                        var indexVertexArray:btTriangleIndexVertexArray;

                        var shape:btBvhTriangleMeshShape;

                        var boatCollision:SceneNode;

                        var rbody:btRigidBody;

     

                        boatMesh.getIndexVertexArrayCopyForAllElements( indices, vertices );

                        indexVertexArray = new btTriangleIndexVertexArray( indices.length/3, indices, vertices.length/3, vertices );

                        shape = new btBvhTriangleMeshShape(indexVertexArray,false);

                        boatCollision = new SceneNode;

                        boatMesh.addChild( boatCollision );

                        rbody = mPellet.createRigidBody(boatCollision, 0, shape);

                        shape.setLocalScaling(scale,scale,scale);

                        rbody.worldTransform.origin.setValue(10,0,-20);

                        boatCollision.physicsObject.collisionFlags |= btCollisionObject.CF_STATIC_OBJECT;

     

     

                        boatMesh.appendScale(scale,scale,scale);

                        boatMesh.appendTranslation(10,0,-20);

                        scene.addChild( boatMesh );

              }

    }

     

    //=======================================

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points