jeromeetienne / tquery

extension system for three.js
http://jeromeetienne.github.io/tquery/
MIT License
651 stars 120 forks source link

Problems with Physics plugin #237

Closed d4n5h closed 11 years ago

d4n5h commented 11 years ago

Objects are randomly generated, but no physics... As you can see here: http://jeromeetienne.github.com/tquery/plugins/physics/examples/index.html (I'm on Firefox)...

jeromeetienne commented 11 years ago

It wprks well here

mariolg commented 11 years ago

Firefox 22, firebug 1.11.4 & 1.12.1beta, non of them works. Elements start to accumulate in the initial point and do not fall down.In chrome is working perfectly.

mariolg commented 11 years ago

Hello again.

Finally I detected the problem in those firefox releases. It had to do with the postmessage content.

Firefox versions seem to not clone well the data inside the arguments. I move all the messages in the worker to JSON as this:

transferableMessage( { datos: worldreport });
transferableMessage( { datos: collisionreport });

For the OBJECTREADY to homogeneize I added to MESSAGE_TYPES another two key including the one for debug (this should be added to physi.js & physijs_worker.js):

MESSAGE_TYPES = {
    WORLDREPORT: 0,
    COLLISIONREPORT: 1,
            OBJECTREADY: 2,
            DEBUG: 3
},

So that the invocation trasformed into:

comando = new Float32Array(2);
comando[0] = MESSAGE_TYPES.OBJECTREADY;
comando[1] = body.id;

/* transferableMessage({ cmd: 'objectReady', params: body.id });*/ transferableMessage( { datos: comando} );

Note: comando shoud be globally declared withint the worker as collisionreport or worldreport.

Then I changed the event handler:

Physijs.xScene.prototype._onMessage = function( event ) {
    //console.assert( this instanceof Physijs.Scene )
    var _temp;
    switch ( event.data.datos[0] ) {
        case MESSAGE_TYPES.WORLDREPORT:
            this._updateScene( event.data.datos );
            break;
        case MESSAGE_TYPES.COLLISIONREPORT:
            this._updateCollisions( event.data.datos );
            break;
        case MESSAGE_TYPES.OBJECTREADY:
            _temp = event.data.datos[1];
            if ( this._objects[ _temp ].readyCallback ) {
                this._objects[ _temp ].readyCallback( this._objects[ _temp ] );
            }
            break;
        case MESSAGE_TYPES.DEBUG:
            console.log('Debug received from worker');
            break;
    }
};

Now it's working properly in my Firefox versions.

Regards

BTW: so a nice package tQuery!!!!