Jump to content

Is there a way to visualize the physics impostor ?


altreality
 Share

Recommended Posts

I do not see any way to draw the box impostor around my mesh(if I am using a box impostor for it) 

 

It helps find out the reason for unexpected collisions some times.

 

Would it make sense to automatically create a physics mesh when  setPhysicsState()is called ?  Maybe maintain a reference to this mesh in a member of AbstractMesh like _physicsMesh ?

      

 AbstractMesh.prototype.setPhysicsState = function (impostor, options) {            var physicsEngine = this.getScene().getPhysicsEngine();            if (!physicsEngine) {                return;            }            if (impostor.impostor) {                               options = impostor;                impostor = impostor.impostor;            }            impostor = impostor || BABYLON.PhysicsEngine.NoImpostor;            if (impostor === BABYLON.PhysicsEngine.NoImpostor) {                physicsEngine._unregisterMesh(this);                return;            }            options.mass = options.mass || 0;            options.friction = options.friction || 0.2;            options.restitution = options.restitution || 0.9;            this._physicImpostor = impostor;            this._physicsMass = options.mass;            this._physicsFriction = options.friction;            this._physicRestitution = options.restitution;            this._physicsMesh = createDownSampledPhysicsMesh(); <----------------------------------------------            return physicsEngine._registerMesh(this, impostor, options);        };

This _physicsMesh member too is then updated by the physics plugin inside :

CannonJSPlugin.prototype.runOneStep = function (delta) {            this._world.step(delta);            for (var index = 0; index < this._registeredMeshes.length; index++) {                var registeredMesh = this._registeredMeshes[index];                if (registeredMesh.isChild) {                    continue;                }                // Body position                var bodyX = registeredMesh.body.position.x, bodyY = registeredMesh.body.position.y, bodyZ = registeredMesh.body.position.z;                // _physicsMesh should not use delta, its a faithful copy of the body's position inside the physics engine                registeredMesh.mesh._physicsMesh.position.x = bodyX ;                registeredMesh.mesh._physicsMesh.position.y = bodyZ ;   // flip Y & Z to account for handedness, apparently this is enough                registeredMesh.mesh._physicsMesh.position.z = bodyY ;                var deltaPos = registeredMesh.delta;                if (deltaPos) {                    registeredMesh.mesh.position.x = bodyX + deltaPos.x;                    registeredMesh.mesh.position.y = bodyZ + deltaPos.y;                    registeredMesh.mesh.position.z = bodyY + deltaPos.z;                                    } else {                    registeredMesh.mesh.position.x = bodyX;                    registeredMesh.mesh.position.y = bodyZ;                    registeredMesh.mesh.position.z = bodyY;                }                if (!registeredMesh.mesh.rotationQuaternion) {                    registeredMesh.mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);                }                registeredMesh.mesh.rotationQuaternion.x = registeredMesh.body.quaternion.x;                registeredMesh.mesh.rotationQuaternion.y = registeredMesh.body.quaternion.z;                registeredMesh.mesh.rotationQuaternion.z = registeredMesh.body.quaternion.y;                registeredMesh.mesh.rotationQuaternion.w = -registeredMesh.body.quaternion.w;            }        };

_physicsMesh can be created only when the user requests physics draw.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...