altreality Posted December 25, 2014 Share Posted December 25, 2014 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. Quote Link to comment Share on other sites More sharing options...
davrous Posted December 25, 2014 Share Posted December 25, 2014 Hello, We don't have an embedded way to do it in our engine. Still, it m's very easy to do it by code like I've explained in this article: http://blogs.msdn.com/b/davrous/archive/2014/11/18/understanding-collisions-amp-physics-by-building-a-cool-webgl-babylon-js-demo-with-oimo-js.aspxBye,David Quote Link to comment Share on other sites More sharing options...
altreality Posted December 25, 2014 Author Share Posted December 25, 2014 Thanks David. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 27, 2014 Share Posted December 27, 2014 What about displaying bounding boxes? mesh.showBoundingBox = true Quote Link to comment Share on other sites More sharing options...
altreality Posted December 28, 2014 Author Share Posted December 28, 2014 Yeah that would work too Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.