babylon.cannonJSPlugin.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. module BABYLON {
  2. declare var require;
  3. declare var CANNON;
  4. export class CannonJSPlugin implements IPhysicsEnginePlugin {
  5. public world: any; //this.BJSCANNON.World
  6. public name: string = "CannonJSPlugin";
  7. private _physicsMaterials = [];
  8. private _fixedTimeStep: number = 1 / 60;
  9. //See https://github.com/schteppe/CANNON.js/blob/gh-pages/demos/collisionFilter.html
  10. private _currentCollisionGroup = 2;
  11. public BJSCANNON = typeof CANNON !== 'undefined' ? CANNON : (typeof require !== 'undefined' ? require('cannon') : undefined);
  12. public constructor(private _useDeltaForWorldStep: boolean = true, iterations: number = 10) {
  13. if (!this.isSupported()) {
  14. Tools.Error("CannonJS is not available. Please make sure you included the js file.");
  15. return;
  16. }
  17. this.world = new this.BJSCANNON.World();
  18. this.world.broadphase = new this.BJSCANNON.NaiveBroadphase();
  19. this.world.solver.iterations = iterations;
  20. }
  21. public setGravity(gravity: Vector3): void {
  22. this.world.gravity.copy(gravity);
  23. }
  24. public setTimeStep(timeStep: number) {
  25. this._fixedTimeStep = timeStep;
  26. }
  27. public getTimeStep(): number {
  28. return this._fixedTimeStep;
  29. }
  30. public executeStep(delta: number, impostors: Array<PhysicsImpostor>): void {
  31. // Delta is in seconds, should be provided in milliseconds
  32. this.world.step(this._fixedTimeStep, this._useDeltaForWorldStep ? delta * 1000 : 0, 3);
  33. }
  34. public applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
  35. var worldPoint = new this.BJSCANNON.Vec3(contactPoint.x, contactPoint.y, contactPoint.z);
  36. var impulse = new this.BJSCANNON.Vec3(force.x, force.y, force.z);
  37. impostor.physicsBody.applyImpulse(impulse, worldPoint);
  38. }
  39. public applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
  40. var worldPoint = new this.BJSCANNON.Vec3(contactPoint.x, contactPoint.y, contactPoint.z);
  41. var impulse = new this.BJSCANNON.Vec3(force.x, force.y, force.z);
  42. impostor.physicsBody.applyForce(impulse, worldPoint);
  43. }
  44. public generatePhysicsBody(impostor: PhysicsImpostor) {
  45. //parent-child relationship. Does this impostor has a parent impostor?
  46. if (impostor.parent) {
  47. if (impostor.physicsBody) {
  48. this.removePhysicsBody(impostor);
  49. //TODO is that needed?
  50. impostor.forceUpdate();
  51. }
  52. return;
  53. }
  54. //should a new body be created for this impostor?
  55. if (impostor.isBodyInitRequired()) {
  56. var shape = this._createShape(impostor);
  57. //unregister events, if body is being changed
  58. var oldBody = impostor.physicsBody;
  59. if (oldBody) {
  60. this.removePhysicsBody(impostor);
  61. }
  62. //create the body and material
  63. var material = this._addMaterial("mat-" + impostor.uniqueId, impostor.getParam("friction"), impostor.getParam("restitution"));
  64. var bodyCreationObject = {
  65. mass: impostor.getParam("mass"),
  66. material: material
  67. };
  68. // A simple extend, in case native options were used.
  69. var nativeOptions = impostor.getParam("nativeOptions");
  70. for (var key in nativeOptions) {
  71. if (nativeOptions.hasOwnProperty(key)) {
  72. bodyCreationObject[key] = nativeOptions[key];
  73. }
  74. }
  75. impostor.physicsBody = new this.BJSCANNON.Body(bodyCreationObject);
  76. impostor.physicsBody.addEventListener("collide", impostor.onCollide);
  77. this.world.addEventListener("preStep", impostor.beforeStep);
  78. this.world.addEventListener("postStep", impostor.afterStep);
  79. impostor.physicsBody.addShape(shape);
  80. this.world.add(impostor.physicsBody);
  81. //try to keep the body moving in the right direction by taking old properties.
  82. //Should be tested!
  83. if (oldBody) {
  84. ['force', 'torque', 'velocity', 'angularVelocity'].forEach(function (param) {
  85. impostor.physicsBody[param].copy(oldBody[param]);
  86. });
  87. }
  88. this._processChildMeshes(impostor);
  89. }
  90. //now update the body's transformation
  91. this._updatePhysicsBodyTransformation(impostor);
  92. }
  93. private _processChildMeshes(mainImpostor: PhysicsImpostor) {
  94. var meshChildren = mainImpostor.object.getChildMeshes ? mainImpostor.object.getChildMeshes(true) : [];
  95. let currentRotation: Quaternion = mainImpostor.object.rotationQuaternion;
  96. if (meshChildren.length) {
  97. var processMesh = (localPosition: Vector3, mesh: AbstractMesh) => {
  98. var childImpostor = mesh.getPhysicsImpostor();
  99. if (childImpostor) {
  100. var parent = childImpostor.parent;
  101. if (parent !== mainImpostor) {
  102. var pPosition = mesh.getAbsolutePosition().subtract(mainImpostor.object.getAbsolutePosition());
  103. let localRotation = mesh.rotationQuaternion.multiply(Quaternion.Inverse(currentRotation));
  104. if (childImpostor.physicsBody) {
  105. this.removePhysicsBody(childImpostor);
  106. childImpostor.physicsBody = null;
  107. }
  108. childImpostor.parent = mainImpostor;
  109. childImpostor.resetUpdateFlags();
  110. mainImpostor.physicsBody.addShape(this._createShape(childImpostor), new this.BJSCANNON.Vec3(pPosition.x, pPosition.y, pPosition.z), new this.BJSCANNON.Quaternion(localRotation.x, localRotation.y, localRotation.z, localRotation.w));
  111. //Add the mass of the children.
  112. mainImpostor.physicsBody.mass += childImpostor.getParam("mass");
  113. }
  114. }
  115. currentRotation.multiplyInPlace(mesh.rotationQuaternion);
  116. mesh.getChildMeshes(true).forEach(processMesh.bind(this, mesh.getAbsolutePosition()));
  117. }
  118. meshChildren.forEach(processMesh.bind(this, mainImpostor.object.getAbsolutePosition()));
  119. }
  120. }
  121. public removePhysicsBody(impostor: PhysicsImpostor) {
  122. impostor.physicsBody.removeEventListener("collide", impostor.onCollide);
  123. this.world.removeEventListener("preStep", impostor.beforeStep);
  124. this.world.removeEventListener("postStep", impostor.afterStep);
  125. this.world.remove(impostor.physicsBody);
  126. }
  127. public generateJoint(impostorJoint: PhysicsImpostorJoint) {
  128. var mainBody = impostorJoint.mainImpostor.physicsBody;
  129. var connectedBody = impostorJoint.connectedImpostor.physicsBody;
  130. if (!mainBody || !connectedBody) {
  131. return;
  132. }
  133. var constraint;
  134. var jointData = impostorJoint.joint.jointData;
  135. //TODO - https://github.com/schteppe/this.BJSCANNON.js/blob/gh-pages/demos/collisionFilter.html
  136. var constraintData = {
  137. pivotA: jointData.mainPivot ? new this.BJSCANNON.Vec3().copy(jointData.mainPivot) : null,
  138. pivotB: jointData.connectedPivot ? new this.BJSCANNON.Vec3().copy(jointData.connectedPivot) : null,
  139. axisA: jointData.mainAxis ? new this.BJSCANNON.Vec3().copy(jointData.mainAxis) : null,
  140. axisB: jointData.connectedAxis ? new this.BJSCANNON.Vec3().copy(jointData.connectedAxis) : null,
  141. maxForce: jointData.nativeParams.maxForce,
  142. collideConnected: !!jointData.collision
  143. };
  144. switch (impostorJoint.joint.type) {
  145. case PhysicsJoint.HingeJoint:
  146. case PhysicsJoint.Hinge2Joint:
  147. constraint = new this.BJSCANNON.HingeConstraint(mainBody, connectedBody, constraintData);
  148. break;
  149. case PhysicsJoint.DistanceJoint:
  150. constraint = new this.BJSCANNON.DistanceConstraint(mainBody, connectedBody, (<DistanceJointData>jointData).maxDistance || 2)
  151. break;
  152. case PhysicsJoint.SpringJoint:
  153. var springData = <SpringJointData>jointData;
  154. constraint = new this.BJSCANNON.Spring(mainBody, connectedBody, {
  155. restLength: springData.length,
  156. stiffness: springData.stiffness,
  157. damping: springData.damping,
  158. localAnchorA: constraintData.pivotA,
  159. localAnchorB: constraintData.pivotB
  160. });
  161. break;
  162. case PhysicsJoint.LockJoint:
  163. constraint = new this.BJSCANNON.LockConstraint(mainBody, connectedBody, constraintData);
  164. break;
  165. case PhysicsJoint.PointToPointJoint:
  166. case PhysicsJoint.BallAndSocketJoint:
  167. default:
  168. constraint = new this.BJSCANNON.PointToPointConstraint(mainBody, constraintData.pivotA, connectedBody, constraintData.pivotA, constraintData.maxForce);
  169. break;
  170. }
  171. //set the collideConnected flag after the creation, since DistanceJoint ignores it.
  172. constraint.collideConnected = !!jointData.collision
  173. impostorJoint.joint.physicsJoint = constraint;
  174. //don't add spring as constraint, as it is not one.
  175. if (impostorJoint.joint.type !== PhysicsJoint.SpringJoint) {
  176. this.world.addConstraint(constraint);
  177. } else {
  178. impostorJoint.mainImpostor.registerAfterPhysicsStep(function () {
  179. constraint.applyForce();
  180. });
  181. }
  182. }
  183. public removeJoint(impostorJoint: PhysicsImpostorJoint) {
  184. this.world.removeConstraint(impostorJoint.joint.physicsJoint);
  185. }
  186. private _addMaterial(name: string, friction: number, restitution: number) {
  187. var index;
  188. var mat;
  189. for (index = 0; index < this._physicsMaterials.length; index++) {
  190. mat = this._physicsMaterials[index];
  191. if (mat.friction === friction && mat.restitution === restitution) {
  192. return mat;
  193. }
  194. }
  195. var currentMat = new this.BJSCANNON.Material(name);
  196. currentMat.friction = friction;
  197. currentMat.restitution = restitution;
  198. this._physicsMaterials.push(currentMat);
  199. return currentMat;
  200. }
  201. private _checkWithEpsilon(value: number): number {
  202. return value < PhysicsEngine.Epsilon ? PhysicsEngine.Epsilon : value;
  203. }
  204. private _createShape(impostor: PhysicsImpostor) {
  205. var object = impostor.object;
  206. var returnValue;
  207. var extendSize = impostor.getObjectExtendSize();
  208. switch (impostor.type) {
  209. case PhysicsImpostor.SphereImpostor:
  210. var radiusX = extendSize.x;
  211. var radiusY = extendSize.y;
  212. var radiusZ = extendSize.z;
  213. returnValue = new this.BJSCANNON.Sphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2);
  214. break;
  215. //TMP also for cylinder - TODO Cannon supports cylinder natively.
  216. case PhysicsImpostor.CylinderImpostor:
  217. returnValue = new this.BJSCANNON.Cylinder(this._checkWithEpsilon(extendSize.x) / 2, this._checkWithEpsilon(extendSize.x) / 2, this._checkWithEpsilon(extendSize.y), 16);
  218. break;
  219. case PhysicsImpostor.BoxImpostor:
  220. var box = extendSize.scale(0.5);
  221. returnValue = new this.BJSCANNON.Box(new this.BJSCANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
  222. break;
  223. case PhysicsImpostor.PlaneImpostor:
  224. Tools.Warn("Attention, PlaneImposter might not behave as you expect. Consider using BoxImposter instead");
  225. returnValue = new this.BJSCANNON.Plane();
  226. break;
  227. case PhysicsImpostor.MeshImpostor:
  228. var rawVerts = object.getVerticesData ? object.getVerticesData(VertexBuffer.PositionKind) : [];
  229. var rawFaces = object.getIndices ? object.getIndices() : [];
  230. Tools.Warn("MeshImpostor only collides against spheres.");
  231. returnValue = new this.BJSCANNON.Trimesh(<number[]>rawVerts, <number[]>rawFaces);
  232. break;
  233. case PhysicsImpostor.HeightmapImpostor:
  234. returnValue = this._createHeightmap(object);
  235. break;
  236. case PhysicsImpostor.ParticleImpostor:
  237. returnValue = new this.BJSCANNON.Particle();
  238. break;
  239. }
  240. return returnValue;
  241. }
  242. private _createHeightmap(object: IPhysicsEnabledObject, pointDepth?: number) {
  243. var pos = object.getVerticesData(VertexBuffer.PositionKind);
  244. var matrix = [];
  245. //For now pointDepth will not be used and will be automatically calculated.
  246. //Future reference - try and find the best place to add a reference to the pointDepth variable.
  247. var arraySize = pointDepth || ~~(Math.sqrt(pos.length / 3) - 1);
  248. var dim = Math.min(object.getBoundingInfo().boundingBox.extendSizeWorld.x, object.getBoundingInfo().boundingBox.extendSizeWorld.z);
  249. var elementSize = dim * 2 / arraySize;
  250. var minY = object.getBoundingInfo().boundingBox.extendSizeWorld.y;
  251. for (var i = 0; i < pos.length; i = i + 3) {
  252. var x = Math.round((pos[i + 0]) / elementSize + arraySize / 2);
  253. var z = Math.round(((pos[i + 2]) / elementSize - arraySize / 2) * -1);
  254. var y = pos[i + 1] + minY;
  255. if (!matrix[x]) {
  256. matrix[x] = [];
  257. }
  258. if (!matrix[x][z]) {
  259. matrix[x][z] = y;
  260. }
  261. matrix[x][z] = Math.max(y, matrix[x][z]);
  262. }
  263. for (var x = 0; x <= arraySize; ++x) {
  264. if (!matrix[x]) {
  265. var loc = 1;
  266. while (!matrix[(x + loc) % arraySize]) {
  267. loc++;
  268. }
  269. matrix[x] = matrix[(x + loc) % arraySize].slice();
  270. //console.log("missing x", x);
  271. }
  272. for (var z = 0; z <= arraySize; ++z) {
  273. if (!matrix[x][z]) {
  274. var loc = 1;
  275. var newValue;
  276. while (newValue === undefined) {
  277. newValue = matrix[x][(z + loc++) % arraySize];
  278. }
  279. matrix[x][z] = newValue;
  280. }
  281. }
  282. }
  283. var shape = new this.BJSCANNON.Heightfield(matrix, {
  284. elementSize: elementSize
  285. });
  286. //For future reference, needed for body transformation
  287. shape.minY = minY;
  288. return shape;
  289. }
  290. private _minus90X = new Quaternion(-0.7071067811865475, 0, 0, 0.7071067811865475);
  291. private _plus90X = new Quaternion(0.7071067811865475, 0, 0, 0.7071067811865475);
  292. private _tmpPosition: Vector3 = Vector3.Zero();
  293. private _tmpQuaternion: Quaternion = new Quaternion();
  294. private _tmpDeltaPosition: Vector3 = Vector3.Zero();
  295. private _tmpDeltaRotation: Quaternion = new Quaternion();
  296. private _tmpUnityRotation: Quaternion = new Quaternion();
  297. private _updatePhysicsBodyTransformation(impostor: PhysicsImpostor) {
  298. var object = impostor.object;
  299. //make sure it is updated...
  300. object.computeWorldMatrix && object.computeWorldMatrix(true);
  301. // The delta between the mesh position and the mesh bounding box center
  302. var center = impostor.getObjectCenter();
  303. this._tmpDeltaPosition.copyFrom(object.position.subtract(center));
  304. this._tmpPosition.copyFrom(center);
  305. var quaternion = object.rotationQuaternion;
  306. //is shape is a plane or a heightmap, it must be rotated 90 degs in the X axis.
  307. if (impostor.type === PhysicsImpostor.PlaneImpostor || impostor.type === PhysicsImpostor.HeightmapImpostor || impostor.type === PhysicsImpostor.CylinderImpostor) {
  308. //-90 DEG in X, precalculated
  309. quaternion = quaternion.multiply(this._minus90X);
  310. //Invert! (Precalculated, 90 deg in X)
  311. //No need to clone. this will never change.
  312. impostor.setDeltaRotation(this._plus90X);
  313. }
  314. //If it is a heightfield, if should be centered.
  315. if (impostor.type === PhysicsImpostor.HeightmapImpostor) {
  316. var mesh = <AbstractMesh>(<any>object);
  317. //calculate the correct body position:
  318. var rotationQuaternion = mesh.rotationQuaternion;
  319. mesh.rotationQuaternion = this._tmpUnityRotation;
  320. mesh.computeWorldMatrix(true);
  321. //get original center with no rotation
  322. var c = center.clone();
  323. var oldPivot = mesh.getPivotMatrix() || Matrix.Translation(0, 0, 0);
  324. //rotation is back
  325. mesh.rotationQuaternion = rotationQuaternion;
  326. //calculate the new center using a pivot (since this.BJSCANNON.js doesn't center height maps)
  327. var p = Matrix.Translation(mesh.getBoundingInfo().boundingBox.extendSizeWorld.x, 0, -mesh.getBoundingInfo().boundingBox.extendSizeWorld.z);
  328. mesh.setPivotMatrix(p);
  329. mesh.computeWorldMatrix(true);
  330. //calculate the translation
  331. var translation = mesh.getBoundingInfo().boundingBox.centerWorld.subtract(center).subtract(mesh.position).negate();
  332. this._tmpPosition.copyFromFloats(translation.x, translation.y - mesh.getBoundingInfo().boundingBox.extendSizeWorld.y, translation.z);
  333. //add it inverted to the delta
  334. this._tmpDeltaPosition.copyFrom(mesh.getBoundingInfo().boundingBox.centerWorld.subtract(c));
  335. this._tmpDeltaPosition.y += mesh.getBoundingInfo().boundingBox.extendSizeWorld.y;
  336. mesh.setPivotMatrix(oldPivot);
  337. mesh.computeWorldMatrix(true);
  338. } else if (impostor.type === PhysicsImpostor.MeshImpostor) {
  339. this._tmpDeltaPosition.copyFromFloats(0, 0, 0);
  340. this._tmpPosition.copyFrom(object.position);
  341. }
  342. impostor.setDeltaPosition(this._tmpDeltaPosition);
  343. //Now update the impostor object
  344. impostor.physicsBody.position.copy(this._tmpPosition);
  345. impostor.physicsBody.quaternion.copy(quaternion);
  346. }
  347. public setTransformationFromPhysicsBody(impostor: PhysicsImpostor) {
  348. impostor.object.position.copyFrom(impostor.physicsBody.position);
  349. impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
  350. }
  351. public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
  352. impostor.physicsBody.position.copy(newPosition);
  353. impostor.physicsBody.quaternion.copy(newRotation);
  354. }
  355. public isSupported(): boolean {
  356. return this.BJSCANNON !== undefined;
  357. }
  358. public setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
  359. impostor.physicsBody.velocity.copy(velocity);
  360. }
  361. public setAngularVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
  362. impostor.physicsBody.angularVelocity.copy(velocity);
  363. }
  364. public getLinearVelocity(impostor: PhysicsImpostor): Vector3 {
  365. var v = impostor.physicsBody.velocity;
  366. if (!v) return null;
  367. return new Vector3(v.x, v.y, v.z)
  368. }
  369. public getAngularVelocity(impostor: PhysicsImpostor): Vector3 {
  370. var v = impostor.physicsBody.angularVelocity;
  371. if (!v) return null;
  372. return new Vector3(v.x, v.y, v.z)
  373. }
  374. public setBodyMass(impostor: PhysicsImpostor, mass: number) {
  375. impostor.physicsBody.mass = mass;
  376. impostor.physicsBody.updateMassProperties();
  377. }
  378. public getBodyMass(impostor: PhysicsImpostor): number {
  379. return impostor.physicsBody.mass;
  380. }
  381. public getBodyFriction(impostor: PhysicsImpostor): number {
  382. return impostor.physicsBody.material.friction;
  383. }
  384. public setBodyFriction(impostor: PhysicsImpostor, friction: number) {
  385. impostor.physicsBody.material.friction = friction;
  386. }
  387. public getBodyRestitution(impostor: PhysicsImpostor): number {
  388. return impostor.physicsBody.material.restitution;
  389. }
  390. public setBodyRestitution(impostor: PhysicsImpostor, restitution: number) {
  391. impostor.physicsBody.material.restitution = restitution;
  392. }
  393. public sleepBody(impostor: PhysicsImpostor) {
  394. impostor.physicsBody.sleep();
  395. }
  396. public wakeUpBody(impostor: PhysicsImpostor) {
  397. impostor.physicsBody.wakeUp();
  398. }
  399. public updateDistanceJoint(joint: PhysicsJoint, maxDistance: number, minDistance?: number) {
  400. joint.physicsJoint.distance = maxDistance;
  401. }
  402. private enableMotor(joint: IMotorEnabledJoint, motorIndex?: number) {
  403. if (!motorIndex) {
  404. joint.physicsJoint.enableMotor();
  405. }
  406. }
  407. private disableMotor(joint: IMotorEnabledJoint, motorIndex?: number) {
  408. if (!motorIndex) {
  409. joint.physicsJoint.disableMotor();
  410. }
  411. }
  412. public setMotor(joint: IMotorEnabledJoint, speed?: number, maxForce?: number, motorIndex?: number) {
  413. if (!motorIndex) {
  414. joint.physicsJoint.enableMotor();
  415. joint.physicsJoint.setMotorSpeed(speed);
  416. if (maxForce) {
  417. this.setLimit(joint, maxForce);
  418. }
  419. }
  420. }
  421. public setLimit(joint: IMotorEnabledJoint, upperLimit: number, lowerLimit?: number) {
  422. joint.physicsJoint.motorEquation.maxForce = upperLimit;
  423. joint.physicsJoint.motorEquation.minForce = lowerLimit === void 0 ? -upperLimit : lowerLimit;
  424. }
  425. public syncMeshWithImpostor(mesh: AbstractMesh, impostor: PhysicsImpostor) {
  426. var body = impostor.physicsBody;
  427. mesh.position.x = body.position.x;
  428. mesh.position.y = body.position.y;
  429. mesh.position.z = body.position.z;
  430. mesh.rotationQuaternion.x = body.quaternion.x;
  431. mesh.rotationQuaternion.y = body.quaternion.y;
  432. mesh.rotationQuaternion.z = body.quaternion.z;
  433. mesh.rotationQuaternion.w = body.quaternion.w;
  434. }
  435. public getRadius(impostor: PhysicsImpostor): number {
  436. var shape = impostor.physicsBody.shapes[0];
  437. return shape.boundingSphereRadius;
  438. }
  439. public getBoxSizeToRef(impostor: PhysicsImpostor, result: Vector3): void {
  440. var shape = impostor.physicsBody.shapes[0];
  441. result.x = shape.halfExtents.x * 2;
  442. result.y = shape.halfExtents.y * 2;
  443. result.z = shape.halfExtents.z * 2;
  444. }
  445. public dispose() {
  446. }
  447. }
  448. }