chandlerprall / Physijs

Physics plugin for Three.js
MIT License
2.75k stars 455 forks source link

constraint is undefined #238

Open RdlP opened 9 years ago

RdlP commented 9 years ago

Hello,

I am trying to add a Slider constraint to a mesh of my scene as following

scene = new Physijs.Scene;
    scene.addEventListener(
            'update',
            function() {
                scene.simulate();
                //physics_stats.update();
            }
        );

var geometry = new THREE.BoxGeometry(1,1,3);
    var texture = THREE.ImageUtils.loadTexture( "res/textures/wood1.jpg" );
    var material = new THREE.MeshLambertMaterial({color: 0xffffFF, map: texture, side: THREE.DoubleSide});
    material.wireframe = false;
    //var mesh = new THREE.Mesh(geometry, material);
    var mesh = new Physijs.BoxMesh(geometry, material);
    mesh.position.set(14,1,0);
    playerPale = mesh;
    scene.add(mesh);

    var constraint = new Physijs.SliderConstraint(
        mesh, // First object to be constrained
        new THREE.Vector3( 0, 10, 0 ), // point in the scene to apply the constraint
        new THREE.Vector3( 0, 0, 1 ) // Axis along which the hinge lies - in this case it is the X axis
    );
    scene.addConstraint( constraint );
    constraint.setLimits(
        new THREE.Vector3(14,1,-8), // lower limit of linear movement, expressed in world units
        new THREE.Vector3(14,1,8), // upper limit of linear movement, expressed in world units
        Math.PI, // lower limit of angular movement, expressed in radians
        -Math.PI // upper limit of angular movement, expressed in radians
    );

And I am getting the next errors in firefox:

TypeError: rotation.setEuler is not a function physijs_worker.js:752:0
TypeError: constraint is undefined physijs_worker.js:970:0

Any advice? Thanks

Edit:

I have tried an example that cames with Physi.js (constraints_car.html) and result is the same:

TypeError: rotation.setEulerZYX is not a function physijs_worker.js:844:0
TypeError: constraint is undefined physijs_worker.js:1087:0
TypeError: constraint is undefined physijs_worker.js:1101:0
TypeError: rotation.setEulerZYX is not a function physijs_worker.js:844:0
TypeError: constraint is undefined physijs_worker.js:1087:0
TypeError: constraint is undefined physijs_worker.js:1101:0
TypeError: rotation.setEulerZYX is not a function physijs_worker.js:844:0
TypeError: constraint is undefined physijs_worker.js:1087:0
TypeError: constraint is undefined physijs_worker.js:1101:0
TypeError: rotation.setEulerZYX is not a function physijs_worker.js:844:0
TypeError: constraint is undefined physijs_worker.js:1087:0
TypeError: constraint is undefined physijs_worker.js:1101:0
Galfour commented 9 years ago

I had the same problem with other type of constraints, with constraints between 2 objects.

RdlP commented 9 years ago

I think the project (physi.js) is outdated and doesn't work with the newers version of THREE.js

Galfour commented 9 years ago

If that's the problem, then the documentation is not up-to-date. And I don't know where I can find the changes

ghost commented 8 years ago

I think it's the current ammo.js version that makes that conflict. I'm using an older ammo.js which just works fine and I don't get that error anymore.