3 Replies Latest reply: Nov 5, 2011 3:37 AM by bhavesh4u RSS

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

    YannickFR1 Community Member

      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.

        • 1. Re: How using loaded mesh to create a shape for a rigidbody ?
          bhavesh4u Community Member

          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.

          • 2. Re: How using loaded mesh to create a shape for a rigidbody ?
            bhavesh4u Community Member

            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?

            • 3. Re: How using loaded mesh to create a shape for a rigidbody ?
              bhavesh4u Community Member

              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 );

                        }

              }

               

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