Explorar o código

Physics dependency

sebavan %!s(int64=6) %!d(string=hai) anos
pai
achega
e227ceb6b1

+ 1 - 7
Tools/Config/tempCircularValidation/core.json

@@ -29,12 +29,6 @@
     "../../src/Particles/subEmitter.ts": [
         "../../src/Particles/particleSystem.ts"
     ],
-    "../../src/Physics/Plugins/cannonJSPlugin.ts": [
-        "../../src/Physics/physicsEngine.ts"
-    ],
-    "../../src/Physics/physicsEngine.ts": [
-        "../../src/Physics/Plugins/cannonJSPlugin.ts"
-    ],
     "../../src/Rendering/depthRenderer.ts": [
         "../../src/Rendering/depthRendererSceneComponent.ts"
     ],
@@ -47,5 +41,5 @@
     "../../src/Rendering/geometryBufferRendererSceneComponent.ts": [
         "../../src/Rendering/geometryBufferRenderer.ts"
     ],
-    "errorCount": 16
+    "errorCount": 14
 }

+ 2 - 0
src/Physics/Plugins/cannonJSPlugin.ts

@@ -657,3 +657,5 @@ import { PhysicsEngine } from "../../Physics/physicsEngine";
             };
         }
     }
+
+    PhysicsEngine.DefaultPluginFactory = () => { return new CannonJSPlugin(); };

+ 9 - 3
src/Physics/physicsEngine.ts

@@ -4,8 +4,6 @@ import { IPhysicsEngine, PhysicsImpostorJoint, IPhysicsEnginePlugin } from "./IP
 import { PhysicsImpostor, IPhysicsEnabledObject } from "./physicsImpostor";
 import { PhysicsJoint } from "./physicsJoint";
 
-import { CannonJSPlugin } from "../Physics/Plugins/cannonJSPlugin";
-
     /**
      * Class used to control physics engine
      * @see http://doc.babylonjs.com/how_to/using_the_physics_engine
@@ -25,11 +23,19 @@ import { CannonJSPlugin } from "../Physics/Plugins/cannonJSPlugin";
         public gravity: Vector3;
 
         /**
+         * Factory used to create the default physics plugin.
+         * @returns The default physics plugin
+         */
+        public static DefaultPluginFactory(): IPhysicsEnginePlugin {
+            throw "Import CannonJSPlugin or Fill DefaultPluginFactory static property on PhysicsEngine before relying on default physics plugin.";
+        }
+
+        /**
          * Creates a new Physics Engine
          * @param gravity defines the gravity vector used by the simulation
          * @param _physicsPlugin defines the plugin to use (CannonJS by default)
          */
-        constructor(gravity: Nullable<Vector3>, private _physicsPlugin: IPhysicsEnginePlugin = new CannonJSPlugin()) {
+        constructor(gravity: Nullable<Vector3>, private _physicsPlugin: IPhysicsEnginePlugin = PhysicsEngine.DefaultPluginFactory()) {
             if (!this._physicsPlugin.isSupported()) {
                 throw new Error("Physics Engine " + this._physicsPlugin.name + " cannot be found. "
                     + "Please make sure it is included.");

+ 1 - 1
src/scene.ts

@@ -152,7 +152,7 @@ import { EngineStore } from "./Engines/engineStore";
          * @returns The default material
          */
         public static DefaultMaterialFactory(scene: Scene): Material {
-            throw "Import StandardMaterial or Fill DefaultMaterialFactory static property on scene before using relying on default material creation.";
+            throw "Import StandardMaterial or Fill DefaultMaterialFactory static property on scene before relying on default material creation.";
         }
 
         // Members