a07f63fbc1e56c94948f0eaab3e30a14ee304c4db55b670040343b09bc8e0ac0.json 14 KB

1
  1. {"ast":null,"code":"import { Logger } from \"../Misc/logger.js\";\nimport { Observable } from \"../Misc/observable.js\";\nimport { SceneComponentConstants } from \"../sceneComponent.js\";\nimport { Scene } from \"../scene.js\";\nimport { PhysicsEngine as PhysicsEngineV1 } from \"./v1/physicsEngine.js\";\nimport { PhysicsEngine as PhysicsEngineV2 } from \"./v2/physicsEngine.js\";\n/**\n * Gets the current physics engine\n * @returns a IPhysicsEngine or null if none attached\n */\nScene.prototype.getPhysicsEngine = function () {\n return this._physicsEngine;\n};\n/**\n * Enables physics to the current scene\n * @param gravity defines the scene's gravity for the physics engine\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\n * @returns a boolean indicating if the physics engine was initialized\n */\nScene.prototype.enablePhysics = function (gravity = null, plugin) {\n if (this._physicsEngine) {\n return true;\n }\n // Register the component to the scene\n let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE);\n if (!component) {\n component = new PhysicsEngineSceneComponent(this);\n this._addComponent(component);\n }\n try {\n if (!plugin || (plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 1) {\n this._physicsEngine = new PhysicsEngineV1(gravity, plugin);\n } else if ((plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 2) {\n this._physicsEngine = new PhysicsEngineV2(gravity, plugin);\n } else {\n throw new Error(\"Unsupported Physics plugin version.\");\n }\n this._physicsTimeAccumulator = 0;\n return true;\n } catch (e) {\n Logger.Error(e.message);\n return false;\n }\n};\n/**\n * Disables and disposes the physics engine associated with the scene\n */\nScene.prototype.disablePhysicsEngine = function () {\n if (!this._physicsEngine) {\n return;\n }\n this._physicsEngine.dispose();\n this._physicsEngine = null;\n};\n/**\n * Gets a boolean indicating if there is an active physics engine\n * @returns a boolean indicating if there is an active physics engine\n */\nScene.prototype.isPhysicsEnabled = function () {\n return this._physicsEngine !== undefined;\n};\n/**\n * Deletes a physics compound impostor\n * @param compound defines the compound to delete\n */\nScene.prototype.deleteCompoundImpostor = function (compound) {\n const mesh = compound.parts[0].mesh;\n if (mesh.physicsImpostor) {\n mesh.physicsImpostor.dispose( /*true*/);\n mesh.physicsImpostor = null;\n }\n};\n/**\n * @internal\n */\nScene.prototype._advancePhysicsEngineStep = function (step) {\n if (this._physicsEngine) {\n const subTime = this._physicsEngine.getSubTimeStep();\n if (subTime > 0) {\n this._physicsTimeAccumulator += step;\n while (this._physicsTimeAccumulator > subTime) {\n this.onBeforePhysicsObservable.notifyObservers(this);\n this._physicsEngine._step(subTime / 1000);\n this.onAfterPhysicsObservable.notifyObservers(this);\n this._physicsTimeAccumulator -= subTime;\n }\n } else {\n this.onBeforePhysicsObservable.notifyObservers(this);\n this._physicsEngine._step(step / 1000);\n this.onAfterPhysicsObservable.notifyObservers(this);\n }\n }\n};\n/**\n * Defines the physics engine scene component responsible to manage a physics engine\n */\nexport class PhysicsEngineSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_PHYSICSENGINE;\n this.scene = scene;\n this.scene.onBeforePhysicsObservable = new Observable();\n this.scene.onAfterPhysicsObservable = new Observable();\n // Replace the function used to get the deterministic frame time\n this.scene.getDeterministicFrameTime = () => {\n if (this.scene._physicsEngine) {\n return this.scene._physicsEngine.getTimeStep() * 1000;\n }\n return 1000.0 / 60.0;\n };\n }\n /**\n * Registers the component in a given scene\n */\n register() {}\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Nothing to do for this component\n }\n /**\n * Disposes the component and the associated resources\n */\n dispose() {\n this.scene.onBeforePhysicsObservable.clear();\n this.scene.onAfterPhysicsObservable.clear();\n if (this.scene._physicsEngine) {\n this.scene.disablePhysicsEngine();\n }\n }\n}","map":{"version":3,"names":["Logger","Observable","SceneComponentConstants","Scene","PhysicsEngine","PhysicsEngineV1","PhysicsEngineV2","prototype","getPhysicsEngine","_physicsEngine","enablePhysics","gravity","plugin","component","_getComponent","NAME_PHYSICSENGINE","PhysicsEngineSceneComponent","_addComponent","getPluginVersion","Error","_physicsTimeAccumulator","e","message","disablePhysicsEngine","dispose","isPhysicsEnabled","undefined","deleteCompoundImpostor","compound","mesh","parts","physicsImpostor","_advancePhysicsEngineStep","step","subTime","getSubTimeStep","onBeforePhysicsObservable","notifyObservers","_step","onAfterPhysicsObservable","constructor","scene","name","getDeterministicFrameTime","getTimeStep","register","rebuild","clear"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Physics/joinedPhysicsEngineComponent.js"],"sourcesContent":["import { Logger } from \"../Misc/logger.js\";\nimport { Observable } from \"../Misc/observable.js\";\nimport { SceneComponentConstants } from \"../sceneComponent.js\";\nimport { Scene } from \"../scene.js\";\nimport { PhysicsEngine as PhysicsEngineV1 } from \"./v1/physicsEngine.js\";\nimport { PhysicsEngine as PhysicsEngineV2 } from \"./v2/physicsEngine.js\";\n/**\n * Gets the current physics engine\n * @returns a IPhysicsEngine or null if none attached\n */\nScene.prototype.getPhysicsEngine = function () {\n return this._physicsEngine;\n};\n/**\n * Enables physics to the current scene\n * @param gravity defines the scene's gravity for the physics engine\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\n * @returns a boolean indicating if the physics engine was initialized\n */\nScene.prototype.enablePhysics = function (gravity = null, plugin) {\n if (this._physicsEngine) {\n return true;\n }\n // Register the component to the scene\n let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE);\n if (!component) {\n component = new PhysicsEngineSceneComponent(this);\n this._addComponent(component);\n }\n try {\n if (!plugin || plugin?.getPluginVersion() === 1) {\n this._physicsEngine = new PhysicsEngineV1(gravity, plugin);\n }\n else if (plugin?.getPluginVersion() === 2) {\n this._physicsEngine = new PhysicsEngineV2(gravity, plugin);\n }\n else {\n throw new Error(\"Unsupported Physics plugin version.\");\n }\n this._physicsTimeAccumulator = 0;\n return true;\n }\n catch (e) {\n Logger.Error(e.message);\n return false;\n }\n};\n/**\n * Disables and disposes the physics engine associated with the scene\n */\nScene.prototype.disablePhysicsEngine = function () {\n if (!this._physicsEngine) {\n return;\n }\n this._physicsEngine.dispose();\n this._physicsEngine = null;\n};\n/**\n * Gets a boolean indicating if there is an active physics engine\n * @returns a boolean indicating if there is an active physics engine\n */\nScene.prototype.isPhysicsEnabled = function () {\n return this._physicsEngine !== undefined;\n};\n/**\n * Deletes a physics compound impostor\n * @param compound defines the compound to delete\n */\nScene.prototype.deleteCompoundImpostor = function (compound) {\n const mesh = compound.parts[0].mesh;\n if (mesh.physicsImpostor) {\n mesh.physicsImpostor.dispose( /*true*/);\n mesh.physicsImpostor = null;\n }\n};\n/**\n * @internal\n */\nScene.prototype._advancePhysicsEngineStep = function (step) {\n if (this._physicsEngine) {\n const subTime = this._physicsEngine.getSubTimeStep();\n if (subTime > 0) {\n this._physicsTimeAccumulator += step;\n while (this._physicsTimeAccumulator > subTime) {\n this.onBeforePhysicsObservable.notifyObservers(this);\n this._physicsEngine._step(subTime / 1000);\n this.onAfterPhysicsObservable.notifyObservers(this);\n this._physicsTimeAccumulator -= subTime;\n }\n }\n else {\n this.onBeforePhysicsObservable.notifyObservers(this);\n this._physicsEngine._step(step / 1000);\n this.onAfterPhysicsObservable.notifyObservers(this);\n }\n }\n};\n/**\n * Defines the physics engine scene component responsible to manage a physics engine\n */\nexport class PhysicsEngineSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_PHYSICSENGINE;\n this.scene = scene;\n this.scene.onBeforePhysicsObservable = new Observable();\n this.scene.onAfterPhysicsObservable = new Observable();\n // Replace the function used to get the deterministic frame time\n this.scene.getDeterministicFrameTime = () => {\n if (this.scene._physicsEngine) {\n return this.scene._physicsEngine.getTimeStep() * 1000;\n }\n return 1000.0 / 60.0;\n };\n }\n /**\n * Registers the component in a given scene\n */\n register() { }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Nothing to do for this component\n }\n /**\n * Disposes the component and the associated resources\n */\n dispose() {\n this.scene.onBeforePhysicsObservable.clear();\n this.scene.onAfterPhysicsObservable.clear();\n if (this.scene._physicsEngine) {\n this.scene.disablePhysicsEngine();\n }\n }\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,UAAU,QAAQ,uBAAuB;AAClD,SAASC,uBAAuB,QAAQ,sBAAsB;AAC9D,SAASC,KAAK,QAAQ,aAAa;AACnC,SAASC,aAAa,IAAIC,eAAe,QAAQ,uBAAuB;AACxE,SAASD,aAAa,IAAIE,eAAe,QAAQ,uBAAuB;AACxE;AACA;AACA;AACA;AACAH,KAAK,CAACI,SAAS,CAACC,gBAAgB,GAAG,YAAY;EAC3C,OAAO,IAAI,CAACC,cAAc;AAC9B,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACAN,KAAK,CAACI,SAAS,CAACG,aAAa,GAAG,UAAUC,OAAO,GAAG,IAAI,EAAEC,MAAM,EAAE;EAC9D,IAAI,IAAI,CAACH,cAAc,EAAE;IACrB,OAAO,IAAI;EACf;EACA;EACA,IAAII,SAAS,GAAG,IAAI,CAACC,aAAa,CAACZ,uBAAuB,CAACa,kBAAkB,CAAC;EAC9E,IAAI,CAACF,SAAS,EAAE;IACZA,SAAS,GAAG,IAAIG,2BAA2B,CAAC,IAAI,CAAC;IACjD,IAAI,CAACC,aAAa,CAACJ,SAAS,CAAC;EACjC;EACA,IAAI;IACA,IAAI,CAACD,MAAM,IAAI,CAAAA,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEM,gBAAgB,CAAC,CAAC,MAAK,CAAC,EAAE;MAC7C,IAAI,CAACT,cAAc,GAAG,IAAIJ,eAAe,CAACM,OAAO,EAAEC,MAAM,CAAC;IAC9D,CAAC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;AACA;EACIC,QAAQA,CAAA,EAAG,CAAE;EACb;AACJ;AACA;AACA;EACIC,OAAOA,CAAA,EAAG;IACN;EAAA;EAEJ;AACJ;AACA;EACItB,OAAOA,CAAA,EAAG;IACN,IAAI,CAACiB,KAAK,CAACL,yBAAyB,CAACW,KAAK,CAAC,CAAC;IAC5C,IAAI,CAACN,KAAK,CAACF,wBAAwB,CAACQ,KAAK,CAAC,CAAC;IAC3C,IAAI,IAAI,CAACN,KAAK,CAAChC,cAAc,EAAE;MAC3B,IAAI,CAACgC,KAAK,CAAClB,oBAAoB,CAAC,CAAC;IACrC;EACJ;AACJ","ignoreList":[]},"metadata":{},"sourceType":"module","externalDependencies":[]}