clonephysijs

BUG? Physijs Clone does not retain Phsyijs properties (collide-ability)


In Physijs, I created a "bumper" cylinder mesh for a sphere to ricochet off of. I then cloned the mesh, positioned the clones (and for this example, the original mesh) and added them to a "ground" box, like this:

    // CREATE AND CLONE A BUMPER
bumper = new Physijs.CylinderMesh
(
    new THREE.CylinderGeometry( 5, 5, 7, 20, 80, false ),
    ground_material,
    0 // mass 
);

var Bumper01 = bumper.clone();
var Bumper02 = bumper.clone();

// POSITION THE CLONES AND THE ORIGINAL BUMPER 
Bumper01.position.set( -2, 4, -50 );
Bumper02.position.set( 2, 4, -10 );
bumper.position.set( 0, 4, 30 );

// ADD THE CLONES AND THE ORIGINAL BUMPER TO THE GROUND CUBE
groundCube.add( bumper, Bumper01, Bumper02 );

scene.add( groundCube );

Only the original bumper functions, the sphere passes through the clones.

Working example HERE

Am I doing something wrong? Is "clone" not intended to work this way in Physijs?

Have I discovered a bug?

For now, I will just create new Phsyijs meshes for each bumper I require...

-Marqso


Solution

  • I think I know what you are talking about.

    The internal clone() function creates a new THREE.Mesh, not a Physijs one. To solve the problem, simply create a cloning function that encases the THREE.Mesh into a Physijs.CylinderMesh:

    function cloneBumper(){
        var obj = new Physijs.CylinderMesh(bumper.clone().geometry, bumper.material, bumper.mass);
        return obj;
    }
    

    Done! Your bumper should now be cloned properly!