Procházet zdrojové kódy

Adding cylinder impostors

Raanan Weber před 9 roky
rodič
revize
3906749366

+ 11 - 9
src/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -245,10 +245,9 @@
             mesh.computeWorldMatrix(true);
             mesh.computeWorldMatrix(true);
 
 
             var returnValue;
             var returnValue;
-
+            var bbox = mesh.getBoundingInfo().boundingBox;
             switch (impostor.type) {
             switch (impostor.type) {
                 case PhysicsEngine.SphereImpostor:
                 case PhysicsEngine.SphereImpostor:
-                    var bbox = mesh.getBoundingInfo().boundingBox;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
@@ -257,26 +256,29 @@
 
 
                     break;
                     break;
                 //TMP also for cylinder - TODO Cannon supports cylinder natively.
                 //TMP also for cylinder - TODO Cannon supports cylinder natively.
-                case PhysicsEngine.CylinderImpostor:
-                    Tools.Warn("CylinderImposter not yet implemented, using BoxImposter instead");
-                case PhysicsEngine.BoxImpostor:
-                    bbox = mesh.getBoundingInfo().boundingBox;
+                case PhysicsImpostor.CylinderImpostor:
+                    var min = bbox.minimumWorld;
+                    var max = bbox.maximumWorld;
+                    var box = max.subtract(min);
+                    returnValue = new CANNON.Cylinder(new CANNON.Vec3(this._checkWithEpsilon(box.x) / 2, this._checkWithEpsilon(box.x) / 2, this._checkWithEpsilon(box.y), 16));
+                    break;
+                case PhysicsImpostor.BoxImpostor:
                     var min = bbox.minimumWorld;
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
                     var max = bbox.maximumWorld;
                     var box = max.subtract(min).scale(0.5);
                     var box = max.subtract(min).scale(0.5);
                     returnValue = new CANNON.Box(new CANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
                     returnValue = new CANNON.Box(new CANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
                     break;
                     break;
-                case PhysicsEngine.PlaneImpostor:
+                case PhysicsImpostor.PlaneImpostor:
                     Tools.Warn("Attention, PlaneImposter might not behave as you expect. Consider using BoxImposter instead");
                     Tools.Warn("Attention, PlaneImposter might not behave as you expect. Consider using BoxImposter instead");
                     returnValue = new CANNON.Plane();
                     returnValue = new CANNON.Plane();
                     break;
                     break;
-                case PhysicsEngine.MeshImpostor:
+                case PhysicsImpostor.MeshImpostor:
                     var rawVerts = mesh.getVerticesData(VertexBuffer.PositionKind);
                     var rawVerts = mesh.getVerticesData(VertexBuffer.PositionKind);
                     var rawFaces = mesh.getIndices();
                     var rawFaces = mesh.getIndices();
                     Tools.Warn("MeshImpostor only collides against spheres.");
                     Tools.Warn("MeshImpostor only collides against spheres.");
                     returnValue = new CANNON.Trimesh(rawVerts, rawFaces);
                     returnValue = new CANNON.Trimesh(rawVerts, rawFaces);
                     break;
                     break;
-                case PhysicsEngine.HeightmapImpostor:
+                case PhysicsImpostor.HeightmapImpostor:
                     returnValue = this._createHeightmap(mesh);
                     returnValue = this._createHeightmap(mesh);
                     break;
                     break;
 
 

+ 13 - 2
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -170,9 +170,20 @@ module BABYLON {
                             bodyConfig.size.push(size);
                             bodyConfig.size.push(size);
                             break;
                             break;
 
 
-                        case PhysicsEngine.PlaneImpostor:
-                        //TODO Oimo now supports cylinder!
                         case PhysicsEngine.CylinderImpostor:
                         case PhysicsEngine.CylinderImpostor:
+                            var min = bbox.minimumWorld;
+                            var max = bbox.maximumWorld;
+                            var box = max.subtract(min);
+                            var sizeX = checkWithEpsilon(box.x) / 2;
+                            var sizeY = checkWithEpsilon(box.y);
+                            bodyConfig.type.push('cylinder');
+                            bodyConfig.size.push(sizeX);
+                            bodyConfig.size.push(sizeY);
+                            //due to the way oimo works with compounds, add one more value.
+                            bodyConfig.size.push(sizeY);
+                            break;
+
+                        case PhysicsEngine.PlaneImpostor:
                         case PhysicsEngine.BoxImpostor:
                         case PhysicsEngine.BoxImpostor:
                         default:
                         default: