@babylonjs/core 5.46.0 → 5.47.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Actions/actionManager.js +6 -1
- package/Actions/actionManager.js.map +1 -1
- package/Debug/physicsViewer.js +3 -3
- package/Debug/physicsViewer.js.map +1 -1
- package/DeviceInput/eventFactory.d.ts +1 -1
- package/DeviceInput/eventFactory.js +4 -4
- package/DeviceInput/eventFactory.js.map +1 -1
- package/DeviceInput/webDeviceInputSystem.js +2 -2
- package/DeviceInput/webDeviceInputSystem.js.map +1 -1
- package/Engines/Extensions/engine.alpha.js +7 -0
- package/Engines/Extensions/engine.alpha.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.alpha.js +8 -0
- package/Engines/WebGPU/Extensions/engine.alpha.js.map +1 -1
- package/Engines/engine.d.ts +1 -3
- package/Engines/engine.js +27 -33
- package/Engines/engine.js.map +1 -1
- package/Engines/thinEngine.d.ts +44 -30
- package/Engines/thinEngine.js +42 -57
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.d.ts +10 -56
- package/Engines/webgpuEngine.js +15 -31
- package/Engines/webgpuEngine.js.map +1 -1
- package/Events/pointerEvents.js +1 -1
- package/Events/pointerEvents.js.map +1 -1
- package/Inputs/scene.inputManager.d.ts +4 -3
- package/Inputs/scene.inputManager.js +12 -11
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +1 -3
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/videoTexture.js +1 -1
- package/Materials/Textures/videoTexture.js.map +1 -1
- package/Maths/math.vector.d.ts +21 -0
- package/Maths/math.vector.js +27 -0
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/mesh.js +1 -1
- package/Meshes/mesh.js.map +1 -1
- package/Particles/particleSystemComponent.js +5 -0
- package/Particles/particleSystemComponent.js.map +1 -1
- package/Physics/index.d.ts +1 -0
- package/Physics/index.js +1 -0
- package/Physics/index.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +12 -14
- package/Physics/v2/IPhysicsEnginePlugin.js +6 -5
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +14 -5
- package/Physics/v2/physicsBody.js +19 -7
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsConstraint.d.ts +139 -66
- package/Physics/v2/physicsConstraint.js +146 -79
- package/Physics/v2/physicsConstraint.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js +9 -1
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingObject.js +3 -0
- package/Rendering/fluidRenderer/fluidRenderingObject.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +3 -0
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +129 -124
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockClearcoat.js +1 -3
- package/Shaders/ShadersInclude/pbrBlockClearcoat.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js +1 -1
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js.map +1 -1
- package/Shaders/fluidRenderingParticleDepth.fragment.js +5 -1
- package/Shaders/fluidRenderingParticleDepth.fragment.js.map +1 -1
- package/Shaders/fluidRenderingRender.fragment.js +7 -2
- package/Shaders/fluidRenderingRender.fragment.js.map +1 -1
- package/Shaders/geometry.fragment.d.ts +2 -0
- package/Shaders/geometry.fragment.js +5 -1
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/geometry.vertex.d.ts +2 -0
- package/Shaders/geometry.vertex.js +8 -4
- package/Shaders/geometry.vertex.js.map +1 -1
- package/package.json +1 -1
|
@@ -44,6 +44,11 @@ Engine.prototype.createEffectForParticles = function (fragmentName, uniformsName
|
|
|
44
44
|
if (defines.indexOf(" BILLBOARD") === -1) {
|
|
45
45
|
defines += "\n#define BILLBOARD\n";
|
|
46
46
|
}
|
|
47
|
+
if (particleSystem === null || particleSystem === void 0 ? void 0 : particleSystem.isAnimationSheetEnabled) {
|
|
48
|
+
if (defines.indexOf(" ANIMATESHEET") === -1) {
|
|
49
|
+
defines += "\n#define ANIMATESHEET\n";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
47
52
|
if (samplers.indexOf("diffuseSampler") === -1) {
|
|
48
53
|
samplers.push("diffuseSampler");
|
|
49
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"particleSystemComponent.js","sourceRoot":"","sources":["../../../../lts/core/generated/Particles/particleSystemComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,6BAA6B,CAAC;AAGrC,yCAAyC;AACzC,aAAa,CAAC,SAAS,CAAC,uBAAuB,CAAC,mBAAmB,EAAE,CAAC,UAAe,EAAE,KAAY,EAAE,SAAyB,EAAE,OAAe,EAAE,EAAE;IAC/I,MAAM,gBAAgB,GAAG,aAAa,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;IAExG,IAAI,CAAC,gBAAgB,EAAE;QACnB,OAAO;KACV;IAED,oBAAoB;IACpB,IAAI,UAAU,CAAC,eAAe,KAAK,SAAS,IAAI,UAAU,CAAC,eAAe,KAAK,IAAI,EAAE;QACjF,KAAK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C1C,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEvB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACzE,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAQ,cAAc,CAAC,OAAO,CAAC;QAE5C,IAAI,OAAO,CAAC,QAAQ,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE;YACzD,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SAChC;KACJ;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { Mesh } from \"../Meshes/mesh\";\r\nimport type { IParticleSystem } from \"./IParticleSystem\";\r\nimport { GPUParticleSystem } from \"./gpuParticleSystem\";\r\nimport { AbstractScene } from \"../abstractScene\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport { ParticleSystem } from \"./particleSystem\";\r\nimport type { Scene } from \"../scene\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport type { AssetContainer } from \"../assetContainer\";\r\n\r\nimport \"../Shaders/particles.vertex\";\r\nimport type { EffectFallbacks } from \"../Materials/effectFallbacks\";\r\n\r\n// Adds the parsers to the scene parsers.\r\nAbstractScene.AddParser(SceneComponentConstants.NAME_PARTICLESYSTEM, (parsedData: any, scene: Scene, container: AssetContainer, rootUrl: string) => {\r\n const individualParser = AbstractScene.GetIndividualParser(SceneComponentConstants.NAME_PARTICLESYSTEM);\r\n\r\n if (!individualParser) {\r\n return;\r\n }\r\n\r\n // Particles Systems\r\n if (parsedData.particleSystems !== undefined && parsedData.particleSystems !== null) {\r\n for (let index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {\r\n const parsedParticleSystem = parsedData.particleSystems[index];\r\n container.particleSystems.push(individualParser(parsedParticleSystem, scene, rootUrl));\r\n }\r\n }\r\n});\r\n\r\nAbstractScene.AddIndividualParser(SceneComponentConstants.NAME_PARTICLESYSTEM, (parsedParticleSystem: any, scene: Scene, rootUrl: string) => {\r\n if (parsedParticleSystem.activeParticleCount) {\r\n const ps = GPUParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);\r\n return ps;\r\n } else {\r\n const ps = ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);\r\n return ps;\r\n }\r\n});\r\n\r\ndeclare module \"../Engines/engine\" {\r\n export interface Engine {\r\n /**\r\n * Create an effect to use with particle systems.\r\n * Please note that some parameters like animation sheets or not being billboard are not supported in this configuration, except if you pass\r\n * the particle system for which you want to create a custom effect in the last parameter\r\n * @param fragmentName defines the base name of the effect (The name of file without .fragment.fx)\r\n * @param uniformsNames defines a list of attribute names\r\n * @param samplers defines an array of string used to represent textures\r\n * @param defines defines the string containing the defines to use to compile the shaders\r\n * @param fallbacks defines the list of potential fallbacks to use if shader compilation fails\r\n * @param onCompiled defines a function to call when the effect creation is successful\r\n * @param onError defines a function to call when the effect creation has failed\r\n * @param particleSystem the particle system you want to create the effect for\r\n * @returns the new Effect\r\n */\r\n createEffectForParticles(\r\n fragmentName: string,\r\n uniformsNames: string[],\r\n samplers: string[],\r\n defines: string,\r\n fallbacks?: EffectFallbacks,\r\n onCompiled?: (effect: Effect) => void,\r\n onError?: (effect: Effect, errors: string) => void,\r\n particleSystem?: IParticleSystem\r\n ): Effect;\r\n }\r\n}\r\n\r\nEngine.prototype.createEffectForParticles = function (\r\n fragmentName: string,\r\n uniformsNames: string[] = [],\r\n samplers: string[] = [],\r\n defines = \"\",\r\n fallbacks?: EffectFallbacks,\r\n onCompiled?: (effect: Effect) => void,\r\n onError?: (effect: Effect, errors: string) => void,\r\n particleSystem?: IParticleSystem\r\n): Effect {\r\n let attributesNamesOrOptions: Array<string> = [];\r\n let effectCreationOption: Array<string> = [];\r\n const allSamplers: Array<string> = [];\r\n\r\n if (particleSystem) {\r\n particleSystem.fillUniformsAttributesAndSamplerNames(effectCreationOption, attributesNamesOrOptions, allSamplers);\r\n } else {\r\n attributesNamesOrOptions = ParticleSystem._GetAttributeNamesOrOptions();\r\n effectCreationOption = ParticleSystem._GetEffectCreationOptions();\r\n }\r\n\r\n if (defines.indexOf(\" BILLBOARD\") === -1) {\r\n defines += \"\\n#define BILLBOARD\\n\";\r\n }\r\n\r\n if (samplers.indexOf(\"diffuseSampler\") === -1) {\r\n samplers.push(\"diffuseSampler\");\r\n }\r\n\r\n return this.createEffect(\r\n {\r\n vertex: particleSystem?.vertexShaderName ?? \"particles\",\r\n fragmentElement: fragmentName,\r\n },\r\n attributesNamesOrOptions,\r\n effectCreationOption.concat(uniformsNames),\r\n allSamplers.concat(samplers),\r\n defines,\r\n fallbacks,\r\n onCompiled,\r\n onError\r\n );\r\n};\r\n\r\ndeclare module \"../Meshes/mesh\" {\r\n export interface Mesh {\r\n /**\r\n * Returns an array populated with IParticleSystem objects whose the mesh is the emitter\r\n * @returns an array of IParticleSystem\r\n */\r\n getEmittedParticleSystems(): IParticleSystem[];\r\n\r\n /**\r\n * Returns an array populated with IParticleSystem objects whose the mesh or its children are the emitter\r\n * @returns an array of IParticleSystem\r\n */\r\n getHierarchyEmittedParticleSystems(): IParticleSystem[];\r\n }\r\n}\r\n\r\nMesh.prototype.getEmittedParticleSystems = function (): IParticleSystem[] {\r\n const results = new Array<IParticleSystem>();\r\n for (let index = 0; index < this.getScene().particleSystems.length; index++) {\r\n const particleSystem = this.getScene().particleSystems[index];\r\n if (particleSystem.emitter === this) {\r\n results.push(particleSystem);\r\n }\r\n }\r\n return results;\r\n};\r\n\r\nMesh.prototype.getHierarchyEmittedParticleSystems = function (): IParticleSystem[] {\r\n const results = new Array<IParticleSystem>();\r\n const descendants = this.getDescendants();\r\n descendants.push(this);\r\n\r\n for (let index = 0; index < this.getScene().particleSystems.length; index++) {\r\n const particleSystem = this.getScene().particleSystems[index];\r\n const emitter: any = particleSystem.emitter;\r\n\r\n if (emitter.position && descendants.indexOf(emitter) !== -1) {\r\n results.push(particleSystem);\r\n }\r\n }\r\n\r\n return results;\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"particleSystemComponent.js","sourceRoot":"","sources":["../../../../lts/core/generated/Particles/particleSystemComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,6BAA6B,CAAC;AAGrC,yCAAyC;AACzC,aAAa,CAAC,SAAS,CAAC,uBAAuB,CAAC,mBAAmB,EAAE,CAAC,UAAe,EAAE,KAAY,EAAE,SAAyB,EAAE,OAAe,EAAE,EAAE;IAC/I,MAAM,gBAAgB,GAAG,aAAa,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;IAExG,IAAI,CAAC,gBAAgB,EAAE;QACnB,OAAO;KACV;IAED,oBAAoB;IACpB,IAAI,UAAU,CAAC,eAAe,KAAK,SAAS,IAAI,UAAU,CAAC,eAAe,KAAK,IAAI,EAAE;QACjF,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE;YACnF,MAAM,oBAAoB,GAAG,UAAU,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YAC/D,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,gBAAgB,CAAC,oBAAoB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G,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACzE,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAQ,cAAc,CAAC,OAAO,CAAC;QAE5C,IAAI,OAAO,CAAC,QAAQ,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE;YACzD,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SAChC;KACJ;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { Mesh } from \"../Meshes/mesh\";\r\nimport type { IParticleSystem } from \"./IParticleSystem\";\r\nimport { GPUParticleSystem } from \"./gpuParticleSystem\";\r\nimport { AbstractScene } from \"../abstractScene\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport { ParticleSystem } from \"./particleSystem\";\r\nimport type { Scene } from \"../scene\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport type { AssetContainer } from \"../assetContainer\";\r\n\r\nimport \"../Shaders/particles.vertex\";\r\nimport type { EffectFallbacks } from \"../Materials/effectFallbacks\";\r\n\r\n// Adds the parsers to the scene parsers.\r\nAbstractScene.AddParser(SceneComponentConstants.NAME_PARTICLESYSTEM, (parsedData: any, scene: Scene, container: AssetContainer, rootUrl: string) => {\r\n const individualParser = AbstractScene.GetIndividualParser(SceneComponentConstants.NAME_PARTICLESYSTEM);\r\n\r\n if (!individualParser) {\r\n return;\r\n }\r\n\r\n // Particles Systems\r\n if (parsedData.particleSystems !== undefined && parsedData.particleSystems !== null) {\r\n for (let index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {\r\n const parsedParticleSystem = parsedData.particleSystems[index];\r\n container.particleSystems.push(individualParser(parsedParticleSystem, scene, rootUrl));\r\n }\r\n }\r\n});\r\n\r\nAbstractScene.AddIndividualParser(SceneComponentConstants.NAME_PARTICLESYSTEM, (parsedParticleSystem: any, scene: Scene, rootUrl: string) => {\r\n if (parsedParticleSystem.activeParticleCount) {\r\n const ps = GPUParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);\r\n return ps;\r\n } else {\r\n const ps = ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);\r\n return ps;\r\n }\r\n});\r\n\r\ndeclare module \"../Engines/engine\" {\r\n export interface Engine {\r\n /**\r\n * Create an effect to use with particle systems.\r\n * Please note that some parameters like animation sheets or not being billboard are not supported in this configuration, except if you pass\r\n * the particle system for which you want to create a custom effect in the last parameter\r\n * @param fragmentName defines the base name of the effect (The name of file without .fragment.fx)\r\n * @param uniformsNames defines a list of attribute names\r\n * @param samplers defines an array of string used to represent textures\r\n * @param defines defines the string containing the defines to use to compile the shaders\r\n * @param fallbacks defines the list of potential fallbacks to use if shader compilation fails\r\n * @param onCompiled defines a function to call when the effect creation is successful\r\n * @param onError defines a function to call when the effect creation has failed\r\n * @param particleSystem the particle system you want to create the effect for\r\n * @returns the new Effect\r\n */\r\n createEffectForParticles(\r\n fragmentName: string,\r\n uniformsNames: string[],\r\n samplers: string[],\r\n defines: string,\r\n fallbacks?: EffectFallbacks,\r\n onCompiled?: (effect: Effect) => void,\r\n onError?: (effect: Effect, errors: string) => void,\r\n particleSystem?: IParticleSystem\r\n ): Effect;\r\n }\r\n}\r\n\r\nEngine.prototype.createEffectForParticles = function (\r\n fragmentName: string,\r\n uniformsNames: string[] = [],\r\n samplers: string[] = [],\r\n defines = \"\",\r\n fallbacks?: EffectFallbacks,\r\n onCompiled?: (effect: Effect) => void,\r\n onError?: (effect: Effect, errors: string) => void,\r\n particleSystem?: IParticleSystem\r\n): Effect {\r\n let attributesNamesOrOptions: Array<string> = [];\r\n let effectCreationOption: Array<string> = [];\r\n const allSamplers: Array<string> = [];\r\n\r\n if (particleSystem) {\r\n particleSystem.fillUniformsAttributesAndSamplerNames(effectCreationOption, attributesNamesOrOptions, allSamplers);\r\n } else {\r\n attributesNamesOrOptions = ParticleSystem._GetAttributeNamesOrOptions();\r\n effectCreationOption = ParticleSystem._GetEffectCreationOptions();\r\n }\r\n\r\n if (defines.indexOf(\" BILLBOARD\") === -1) {\r\n defines += \"\\n#define BILLBOARD\\n\";\r\n }\r\n\r\n if (particleSystem?.isAnimationSheetEnabled) {\r\n if (defines.indexOf(\" ANIMATESHEET\") === -1) {\r\n defines += \"\\n#define ANIMATESHEET\\n\";\r\n }\r\n }\r\n\r\n if (samplers.indexOf(\"diffuseSampler\") === -1) {\r\n samplers.push(\"diffuseSampler\");\r\n }\r\n\r\n return this.createEffect(\r\n {\r\n vertex: particleSystem?.vertexShaderName ?? \"particles\",\r\n fragmentElement: fragmentName,\r\n },\r\n attributesNamesOrOptions,\r\n effectCreationOption.concat(uniformsNames),\r\n allSamplers.concat(samplers),\r\n defines,\r\n fallbacks,\r\n onCompiled,\r\n onError\r\n );\r\n};\r\n\r\ndeclare module \"../Meshes/mesh\" {\r\n export interface Mesh {\r\n /**\r\n * Returns an array populated with IParticleSystem objects whose the mesh is the emitter\r\n * @returns an array of IParticleSystem\r\n */\r\n getEmittedParticleSystems(): IParticleSystem[];\r\n\r\n /**\r\n * Returns an array populated with IParticleSystem objects whose the mesh or its children are the emitter\r\n * @returns an array of IParticleSystem\r\n */\r\n getHierarchyEmittedParticleSystems(): IParticleSystem[];\r\n }\r\n}\r\n\r\nMesh.prototype.getEmittedParticleSystems = function (): IParticleSystem[] {\r\n const results = new Array<IParticleSystem>();\r\n for (let index = 0; index < this.getScene().particleSystems.length; index++) {\r\n const particleSystem = this.getScene().particleSystems[index];\r\n if (particleSystem.emitter === this) {\r\n results.push(particleSystem);\r\n }\r\n }\r\n return results;\r\n};\r\n\r\nMesh.prototype.getHierarchyEmittedParticleSystems = function (): IParticleSystem[] {\r\n const results = new Array<IParticleSystem>();\r\n const descendants = this.getDescendants();\r\n descendants.push(this);\r\n\r\n for (let index = 0; index < this.getScene().particleSystems.length; index++) {\r\n const particleSystem = this.getScene().particleSystems[index];\r\n const emitter: any = particleSystem.emitter;\r\n\r\n if (emitter.position && descendants.indexOf(emitter) !== -1) {\r\n results.push(particleSystem);\r\n }\r\n }\r\n\r\n return results;\r\n};\r\n"]}
|
package/Physics/index.d.ts
CHANGED
package/Physics/index.js
CHANGED
package/Physics/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lts/core/generated/Physics/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nexport * from \"./v1/index\";\r\nexport * from \"./v2/index\";\r\nexport * from \"./physicsEngineComponent\";\r\nexport * from \"./v1/physicsEngineComponent\";\r\nexport * from \"./physicsHelper\";\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lts/core/generated/Physics/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nexport * from \"./v1/index\";\r\nexport * from \"./v2/index\";\r\nexport * from \"./physicsEngineComponent\";\r\nexport * from \"./v1/physicsEngineComponent\";\r\nexport * from \"./physicsHelper\";\r\nexport * from \"./physicsRaycastResult\";\r\n"]}
|
|
@@ -27,11 +27,12 @@ export declare enum ConstraintAxis {
|
|
|
27
27
|
}
|
|
28
28
|
/** @internal */
|
|
29
29
|
export declare enum ConstraintType {
|
|
30
|
-
BALL_AND_SOCKET =
|
|
31
|
-
DISTANCE =
|
|
32
|
-
HINGE =
|
|
33
|
-
SLIDER =
|
|
34
|
-
LOCK =
|
|
30
|
+
BALL_AND_SOCKET = 1,
|
|
31
|
+
DISTANCE = 2,
|
|
32
|
+
HINGE = 3,
|
|
33
|
+
SLIDER = 4,
|
|
34
|
+
LOCK = 5,
|
|
35
|
+
PRISMATIC = 6
|
|
35
36
|
}
|
|
36
37
|
/** @internal */
|
|
37
38
|
export declare enum ShapeType {
|
|
@@ -67,6 +68,8 @@ export interface PhysicsConstraintParameters {
|
|
|
67
68
|
pivotB?: Vector3;
|
|
68
69
|
axisA?: Vector3;
|
|
69
70
|
axisB?: Vector3;
|
|
71
|
+
maxDistance?: number;
|
|
72
|
+
collision?: boolean;
|
|
70
73
|
}
|
|
71
74
|
/**
|
|
72
75
|
*
|
|
@@ -126,14 +129,15 @@ export interface IPhysicsEnginePluginV2 {
|
|
|
126
129
|
getAngularDamping(body: PhysicsBody): number;
|
|
127
130
|
setLinearVelocity(body: PhysicsBody, linVel: Vector3): void;
|
|
128
131
|
getLinearVelocityToRef(body: PhysicsBody, linVel: Vector3): void;
|
|
129
|
-
applyImpulse(body: PhysicsBody,
|
|
130
|
-
applyForce(body: PhysicsBody,
|
|
132
|
+
applyImpulse(body: PhysicsBody, impulse: Vector3, location: Vector3): void;
|
|
133
|
+
applyForce(body: PhysicsBody, force: Vector3, location: Vector3): void;
|
|
131
134
|
setAngularVelocity(body: PhysicsBody, angVel: Vector3): void;
|
|
132
135
|
getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3): void;
|
|
133
136
|
getBodyGeometry(body: PhysicsBody): {};
|
|
134
137
|
disposeBody(body: PhysicsBody): void;
|
|
135
138
|
registerOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
|
|
136
139
|
unregisterOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
|
|
140
|
+
addConstraint(body: PhysicsBody, childBody: PhysicsBody, constraint: PhysicsConstraint): void;
|
|
137
141
|
initShape(shape: PhysicsShape, type: ShapeType, options: PhysicsShapeParameters): void;
|
|
138
142
|
setFilterLayer(shape: PhysicsShape, layer: number): void;
|
|
139
143
|
getFilterLayer(shape: PhysicsShape): number;
|
|
@@ -152,13 +156,7 @@ export interface IPhysicsEnginePluginV2 {
|
|
|
152
156
|
setRestitution(material: PhysicsMaterial, restitution: number): void;
|
|
153
157
|
getRestitution(material: PhysicsMaterial): number;
|
|
154
158
|
disposeMaterial(material: PhysicsMaterial): void;
|
|
155
|
-
initConstraint(constraint: PhysicsConstraint,
|
|
156
|
-
setParentBody(constraint: PhysicsConstraint, body: PhysicsBody): void;
|
|
157
|
-
getParentBody(constraint: PhysicsConstraint): PhysicsBody;
|
|
158
|
-
setChildBody(constraint: PhysicsConstraint, body: PhysicsBody): void;
|
|
159
|
-
getChildBody(constraint: PhysicsConstraint): PhysicsBody;
|
|
160
|
-
setAnchorInParent(constraint: PhysicsConstraint, pivot: Vector3, axisX: Vector3, axisY: Vector3): void;
|
|
161
|
-
setAnchorInChild(constraint: PhysicsConstraint, pivot: Vector3, axisX: Vector3, axisY: Vector3): void;
|
|
159
|
+
initConstraint(constraint: PhysicsConstraint, body: PhysicsBody, childBody: PhysicsBody): void;
|
|
162
160
|
setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;
|
|
163
161
|
getEnabled(constraint: PhysicsConstraint): boolean;
|
|
164
162
|
setCollisionsEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;
|
|
@@ -20,11 +20,12 @@ export var ConstraintAxis;
|
|
|
20
20
|
/** @internal */
|
|
21
21
|
export var ConstraintType;
|
|
22
22
|
(function (ConstraintType) {
|
|
23
|
-
ConstraintType[ConstraintType["BALL_AND_SOCKET"] =
|
|
24
|
-
ConstraintType[ConstraintType["DISTANCE"] =
|
|
25
|
-
ConstraintType[ConstraintType["HINGE"] =
|
|
26
|
-
ConstraintType[ConstraintType["SLIDER"] =
|
|
27
|
-
ConstraintType[ConstraintType["LOCK"] =
|
|
23
|
+
ConstraintType[ConstraintType["BALL_AND_SOCKET"] = 1] = "BALL_AND_SOCKET";
|
|
24
|
+
ConstraintType[ConstraintType["DISTANCE"] = 2] = "DISTANCE";
|
|
25
|
+
ConstraintType[ConstraintType["HINGE"] = 3] = "HINGE";
|
|
26
|
+
ConstraintType[ConstraintType["SLIDER"] = 4] = "SLIDER";
|
|
27
|
+
ConstraintType[ConstraintType["LOCK"] = 5] = "LOCK";
|
|
28
|
+
ConstraintType[ConstraintType["PRISMATIC"] = 6] = "PRISMATIC";
|
|
28
29
|
})(ConstraintType || (ConstraintType = {}));
|
|
29
30
|
/** @internal */
|
|
30
31
|
export var ShapeType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IPhysicsEnginePlugin.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/IPhysicsEnginePlugin.ts"],"names":[],"mappings":"AAWA,gBAAgB;AAChB,MAAM,CAAN,IAAY,uBAKX;AALD,WAAY,uBAAuB;IAC/B,qEAAI,CAAA;IACJ,2EAAO,CAAA;IACP,yEAAM,CAAA;IACN,qEAAI,CAAA;AACR,CAAC,EALW,uBAAuB,KAAvB,uBAAuB,QAKlC;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAQX;AARD,WAAY,cAAc;IACtB,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,yEAAe,CAAA;AACnB,CAAC,EARW,cAAc,KAAd,cAAc,QAQzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"IPhysicsEnginePlugin.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/IPhysicsEnginePlugin.ts"],"names":[],"mappings":"AAWA,gBAAgB;AAChB,MAAM,CAAN,IAAY,uBAKX;AALD,WAAY,uBAAuB;IAC/B,qEAAI,CAAA;IACJ,2EAAO,CAAA;IACP,yEAAM,CAAA;IACN,qEAAI,CAAA;AACR,CAAC,EALW,uBAAuB,KAAvB,uBAAuB,QAKlC;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAQX;AARD,WAAY,cAAc;IACtB,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,yEAAe,CAAA;AACnB,CAAC,EARW,cAAc,KAAd,cAAc,QAQzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAOX;AAPD,WAAY,cAAc;IACtB,yEAAmB,CAAA;IACnB,2DAAY,CAAA;IACZ,qDAAS,CAAA;IACT,uDAAU,CAAA;IACV,mDAAQ,CAAA;IACR,6DAAa,CAAA;AACjB,CAAC,EAPW,cAAc,KAAd,cAAc,QAOzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,SASX;AATD,WAAY,SAAS;IACjB,6CAAM,CAAA;IACN,+CAAO,CAAA;IACP,iDAAQ,CAAA;IACR,uCAAG,CAAA;IACH,uDAAW,CAAA;IACX,mDAAS,CAAA;IACT,yCAAI,CAAA;IACJ,uDAAW,CAAA;AACf,CAAC,EATW,SAAS,KAAT,SAAS,QASpB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC3B,6DAAI,CAAA;IACJ,qEAAQ,CAAA;IACR,qEAAQ,CAAA;AACZ,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B","sourcesContent":["import type { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { PhysicsRaycastResult } from \"../physicsRaycastResult\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\n/** @internal */\r\nexport enum ConstraintAxisLimitMode {\r\n FREE,\r\n LIMITED,\r\n LOCKED,\r\n NONE,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintAxis {\r\n LINEAR_X,\r\n LINEAR_Y,\r\n LINEAR_Z,\r\n ANGULAR_X,\r\n ANGULAR_Y,\r\n ANGULAR_Z,\r\n LINEAR_DISTANCE,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintType {\r\n BALL_AND_SOCKET = 1,\r\n DISTANCE = 2,\r\n HINGE = 3,\r\n SLIDER = 4,\r\n LOCK = 5,\r\n PRISMATIC = 6,\r\n}\r\n\r\n/** @internal */\r\nexport enum ShapeType {\r\n SPHERE,\r\n CAPSULE,\r\n CYLINDER,\r\n BOX,\r\n CONVEX_HULL,\r\n CONTAINER,\r\n MESH,\r\n HEIGHTFIELD,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintMotorType {\r\n NONE,\r\n VELOCITY,\r\n POSITION,\r\n}\r\n\r\n/** @internal */\r\nexport interface PhysicsShapeParameters {\r\n center?: Vector3;\r\n radius?: number;\r\n pointA?: Vector3;\r\n pointB?: Vector3;\r\n rotation?: Quaternion;\r\n extents?: Vector3;\r\n mesh?: Mesh;\r\n includeChildMeshes?: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport interface PhysicsConstraintParameters {\r\n pivotA?: Vector3;\r\n pivotB?: Vector3;\r\n axisA?: Vector3;\r\n axisB?: Vector3;\r\n maxDistance?: number;\r\n collision?: boolean;\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport interface MassProperties {\r\n /**\r\n *\r\n */\r\n centerOfMass: Vector3;\r\n /**\r\n *\r\n */\r\n mass: number;\r\n /**\r\n *\r\n */\r\n inertia: Vector3;\r\n /**\r\n *\r\n */\r\n inertiaOrientation: Quaternion;\r\n}\r\n\r\n/** @internal */\r\nexport interface IPhysicsEnginePluginV2 {\r\n /**\r\n *\r\n */\r\n world: any;\r\n /**\r\n *\r\n */\r\n name: string;\r\n setGravity(gravity: Vector3): void;\r\n setTimeStep(timeStep: number): void;\r\n getTimeStep(): number;\r\n executeStep(delta: number, bodies: Array<PhysicsBody>): void; //not forgetting pre and post events\r\n getPluginVersion(): number;\r\n registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n\r\n // body\r\n initBody(body: PhysicsBody, position: Vector3, orientation: Quaternion): void;\r\n initBodyInstances(body: PhysicsBody, mesh: Mesh): void;\r\n removeBody(body: PhysicsBody): void;\r\n sync(body: PhysicsBody): void;\r\n syncTransform(body: PhysicsBody, transformNode: TransformNode): void;\r\n setShape(body: PhysicsBody, shape: PhysicsShape): void;\r\n getShape(body: PhysicsBody): PhysicsShape;\r\n setFilterGroup(body: PhysicsBody, group: number): void;\r\n getFilterGroup(body: PhysicsBody): number;\r\n setEventMask(body: PhysicsBody, eventMask: number): void;\r\n getEventMask(body: PhysicsBody): number;\r\n setMassProperties(body: PhysicsBody, massProps: MassProperties): void;\r\n getMassProperties(body: PhysicsBody): MassProperties;\r\n setLinearDamping(body: PhysicsBody, damping: number): void;\r\n getLinearDamping(body: PhysicsBody): number;\r\n setAngularDamping(body: PhysicsBody, damping: number): void;\r\n getAngularDamping(body: PhysicsBody): number;\r\n setLinearVelocity(body: PhysicsBody, linVel: Vector3): void;\r\n getLinearVelocityToRef(body: PhysicsBody, linVel: Vector3): void;\r\n applyImpulse(body: PhysicsBody, impulse: Vector3, location: Vector3): void;\r\n applyForce(body: PhysicsBody, force: Vector3, location: Vector3): void;\r\n setAngularVelocity(body: PhysicsBody, angVel: Vector3): void;\r\n getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3): void;\r\n getBodyGeometry(body: PhysicsBody): {};\r\n disposeBody(body: PhysicsBody): void;\r\n registerOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n unregisterOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n addConstraint(body: PhysicsBody, childBody: PhysicsBody, constraint: PhysicsConstraint): void;\r\n\r\n // shape\r\n initShape(shape: PhysicsShape, type: ShapeType, options: PhysicsShapeParameters): void;\r\n setFilterLayer(shape: PhysicsShape, layer: number): void;\r\n getFilterLayer(shape: PhysicsShape): number;\r\n setMaterial(shape: PhysicsShape, material: PhysicsMaterial): void;\r\n getMaterial(shape: PhysicsShape): PhysicsMaterial;\r\n setDensity(shape: PhysicsShape, density: number): void;\r\n getDensity(shape: PhysicsShape): number;\r\n addChild(shape: PhysicsShape, newChild: PhysicsShape, childTransform: TransformNode): void;\r\n removeChild(shape: PhysicsShape, childIndex: number): void;\r\n getNumChildren(shape: PhysicsShape): number;\r\n getBoundingBox(shape: PhysicsShape): BoundingBox;\r\n disposeShape(shape: PhysicsShape): void;\r\n\r\n // material\r\n initMaterial(material: PhysicsMaterial): void;\r\n setFriction(material: PhysicsMaterial, friction: number): void;\r\n getFriction(material: PhysicsMaterial): number;\r\n setRestitution(material: PhysicsMaterial, restitution: number): void;\r\n getRestitution(material: PhysicsMaterial): number;\r\n disposeMaterial(material: PhysicsMaterial): void;\r\n\r\n // constraint\r\n initConstraint(constraint: PhysicsConstraint, body: PhysicsBody, childBody: PhysicsBody): void;\r\n setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;\r\n getEnabled(constraint: PhysicsConstraint): boolean;\r\n setCollisionsEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;\r\n getCollisionsEnabled(constraint: PhysicsConstraint): boolean;\r\n setAxisFriction(constraint: PhysicsConstraint, axis: ConstraintAxis, friction: number): void;\r\n getAxisFriction(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMode(constraint: PhysicsConstraint, axis: ConstraintAxis, limitMode: ConstraintAxisLimitMode): void;\r\n getAxisMode(constraint: PhysicsConstraint, axis: ConstraintAxis): ConstraintAxisLimitMode;\r\n setAxisMinLimit(constraint: PhysicsConstraint, axis: ConstraintAxis, minLimit: number): void;\r\n getAxisMinLimit(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMaxLimit(constraint: PhysicsConstraint, axis: ConstraintAxis, limit: number): void;\r\n getAxisMaxLimit(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMotorType(constraint: PhysicsConstraint, axis: ConstraintAxis, motorType: ConstraintMotorType): void;\r\n getAxisMotorType(constraint: PhysicsConstraint, axis: ConstraintAxis): ConstraintMotorType;\r\n setAxisMotorTarget(constraint: PhysicsConstraint, axis: ConstraintAxis, target: number): void;\r\n getAxisMotorTarget(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMotorMaxForce(constraint: PhysicsConstraint, axis: ConstraintAxis, maxForce: number): void;\r\n getAxisMotorMaxForce(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n disposeConstraint(constraint: PhysicsConstraint): void;\r\n\r\n // raycast\r\n raycast(from: Vector3, to: Vector3, result: PhysicsRaycastResult): void;\r\n\r\n dispose(): void;\r\n}\r\n"]}
|
|
@@ -4,6 +4,7 @@ import { Vector3 } from "../../Maths/math.vector";
|
|
|
4
4
|
import type { Scene } from "../../scene";
|
|
5
5
|
import type { TransformNode } from "../../Meshes";
|
|
6
6
|
import type { Nullable } from "../../types.js";
|
|
7
|
+
import type { PhysicsConstraint } from "./physicsConstraint";
|
|
7
8
|
/**
|
|
8
9
|
* PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows
|
|
9
10
|
* the user to set the mass and velocity of the body, which can then be used to calculate the
|
|
@@ -200,23 +201,23 @@ export declare class PhysicsBody {
|
|
|
200
201
|
/**
|
|
201
202
|
* Applies an impulse to the physics object.
|
|
202
203
|
*
|
|
203
|
-
* @param location The location of the impulse.
|
|
204
204
|
* @param impulse The impulse vector.
|
|
205
|
+
* @param location The location of the impulse.
|
|
205
206
|
*
|
|
206
207
|
* This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,
|
|
207
208
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
208
209
|
*/
|
|
209
|
-
applyImpulse(
|
|
210
|
+
applyImpulse(impulse: Vector3, location: Vector3): void;
|
|
210
211
|
/**
|
|
211
212
|
* Applies a force to the physics object.
|
|
212
213
|
*
|
|
213
|
-
* @param location The location of the force.
|
|
214
214
|
* @param force The force vector.
|
|
215
|
+
* @param location The location of the force.
|
|
215
216
|
*
|
|
216
217
|
* This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,
|
|
217
218
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
218
219
|
*/
|
|
219
|
-
applyForce(
|
|
220
|
+
applyForce(force: Vector3, location: Vector3): void;
|
|
220
221
|
/**
|
|
221
222
|
* Retrieves the geometry of the body from the physics plugin.
|
|
222
223
|
*
|
|
@@ -241,9 +242,17 @@ export declare class PhysicsBody {
|
|
|
241
242
|
*/
|
|
242
243
|
getObjectExtents(): Vector3;
|
|
243
244
|
/**
|
|
244
|
-
*
|
|
245
|
+
* @returns geometric center of the associated mesh
|
|
245
246
|
*/
|
|
246
247
|
getObjectCenter(): Vector3;
|
|
248
|
+
/**
|
|
249
|
+
* Adds a constraint to the physics engine.
|
|
250
|
+
*
|
|
251
|
+
* @param childBody - The body to which the constraint will be applied.
|
|
252
|
+
* @param constraint - The constraint to be applied.
|
|
253
|
+
*
|
|
254
|
+
*/
|
|
255
|
+
addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void;
|
|
247
256
|
/**
|
|
248
257
|
* Disposes the body from the physics engine.
|
|
249
258
|
*
|
|
@@ -245,26 +245,26 @@ export class PhysicsBody {
|
|
|
245
245
|
/**
|
|
246
246
|
* Applies an impulse to the physics object.
|
|
247
247
|
*
|
|
248
|
-
* @param location The location of the impulse.
|
|
249
248
|
* @param impulse The impulse vector.
|
|
249
|
+
* @param location The location of the impulse.
|
|
250
250
|
*
|
|
251
251
|
* This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,
|
|
252
252
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
253
253
|
*/
|
|
254
|
-
applyImpulse(
|
|
255
|
-
this._physicsPlugin.applyImpulse(this,
|
|
254
|
+
applyImpulse(impulse, location) {
|
|
255
|
+
this._physicsPlugin.applyImpulse(this, impulse, location);
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
258
|
* Applies a force to the physics object.
|
|
259
259
|
*
|
|
260
|
-
* @param location The location of the force.
|
|
261
260
|
* @param force The force vector.
|
|
261
|
+
* @param location The location of the force.
|
|
262
262
|
*
|
|
263
263
|
* This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,
|
|
264
264
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
265
265
|
*/
|
|
266
|
-
applyForce(
|
|
267
|
-
this._physicsPlugin.applyForce(this,
|
|
266
|
+
applyForce(force, location) {
|
|
267
|
+
this._physicsPlugin.applyForce(this, force, location);
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
270
270
|
* Retrieves the geometry of the body from the physics plugin.
|
|
@@ -323,12 +323,22 @@ export class PhysicsBody {
|
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
/**
|
|
326
|
-
*
|
|
326
|
+
* @returns geometric center of the associated mesh
|
|
327
327
|
*/
|
|
328
328
|
getObjectCenter() {
|
|
329
329
|
// TODO
|
|
330
330
|
return new Vector3(0, 0, 0);
|
|
331
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Adds a constraint to the physics engine.
|
|
334
|
+
*
|
|
335
|
+
* @param childBody - The body to which the constraint will be applied.
|
|
336
|
+
* @param constraint - The constraint to be applied.
|
|
337
|
+
*
|
|
338
|
+
*/
|
|
339
|
+
addConstraint(childBody, constraint) {
|
|
340
|
+
this._physicsPlugin.addConstraint(this, childBody, constraint);
|
|
341
|
+
}
|
|
332
342
|
/**
|
|
333
343
|
* Disposes the body from the physics engine.
|
|
334
344
|
*
|
|
@@ -338,6 +348,8 @@ export class PhysicsBody {
|
|
|
338
348
|
this._physicsEngine.removeBody(this);
|
|
339
349
|
this._physicsPlugin.removeBody(this);
|
|
340
350
|
this._physicsPlugin.disposeBody(this);
|
|
351
|
+
this._pluginData = null;
|
|
352
|
+
this._pluginDataInstances.length = 0;
|
|
341
353
|
}
|
|
342
354
|
}
|
|
343
355
|
PhysicsBody._DEFAULT_OBJECT_SIZE = new Vector3(1, 1, 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM9D;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA8BpB;;;;;;;;OAQG;IACH,YAAY,aAA4B,EAAE,KAAY;QAtCtD;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAa7C;;;WAGG;QACH,mBAAc,GAAY,IAAI,CAAC;QAe3B,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QACD,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAmB,CAAC;QAChE,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QACD,IAAI,CAAC,cAAc,GAAG,a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IACL,CAAC;IAED;;OAEG;IACI,eAAe;QAClB,OAAO;QACP,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;;AA1Vc,gCAAoB,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,gCAAoB,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC","sourcesContent":["import type { IPhysicsEnginePluginV2, MassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode, AbstractMesh } from \"../../Meshes\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\n/**\r\n * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows\r\n * the user to set the mass and velocity of the body, which can then be used to calculate the\r\n * motion of the body in the physics engine.\r\n */\r\nexport class PhysicsBody {\r\n /**\r\n * V2 Physics plugin private data for single Transform\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * V2 Physics plugin private data for instances\r\n */\r\n public _pluginDataInstances: Array<any> = [];\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n /**\r\n * The engine used to create and manage this Physics Body\r\n */\r\n private _physicsEngine: PhysicsEngine;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n disablePreStep: boolean = true;\r\n\r\n private static _DEFAULT_OBJECT_SIZE: Vector3 = new Vector3(1, 1, 1);\r\n private static _IDENTITY_QUATERNION = Quaternion.Identity();\r\n\r\n /**\r\n * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, m);\r\n } else {\r\n // single instance\r\n this._physicsPlugin.initBody(this, transformNode.position, transformNode.rotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public setShape(shape: PhysicsShape): void {\r\n this._physicsPlugin.setShape(this, shape);\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public getShape(): PhysicsShape | undefined {\r\n return this._physicsPlugin.getShape(this);\r\n }\r\n\r\n /**\r\n * Sets the filter group of the physics body.\r\n * @param group - The filter group of the physics body.\r\n *\r\n * This method is useful for setting the filter group of the physics body.\r\n * The filter group is used to determine which bodies should collide with each other.\r\n * This allows for more control over the physics engine and can be used to create more realistic simulations.\r\n */\r\n public setFilterGroup(group: number): void {\r\n this._physicsPlugin.setFilterGroup(this, group);\r\n }\r\n\r\n /**\r\n * Gets the filter group of the physics engine.\r\n *\r\n * @returns The filter group of the physics engine.\r\n *\r\n * This method is useful for getting the filter group of the physics engine,\r\n * which is used to determine which objects will interact with each other.\r\n * This is important for creating realistic physics simulations.\r\n */\r\n public getFilterGroup(): number {\r\n return this._physicsPlugin.getFilterGroup(this);\r\n }\r\n\r\n /**\r\n * Sets the event mask for the physics engine.\r\n *\r\n * @param eventMask - A bitmask that determines which events will be sent to the physics engine.\r\n *\r\n * This method is useful for setting the event mask for the physics engine, which determines which events\r\n * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.\r\n */\r\n public setEventMask(eventMask: number): void {\r\n this._physicsPlugin.setEventMask(this, eventMask);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n *\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(): number {\r\n return this._physicsPlugin.getEventMask(this);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: MassProperties): void {\r\n this._physicsPlugin.setMassProperties(this, massProps);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n *\r\n * @returns The mass properties of the object, or `undefined` if the physics\r\n * plugin does not support mass properties.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(): MassProperties | undefined {\r\n return this._physicsPlugin.getMassProperties(this);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number): void {\r\n this._physicsPlugin.setLinearDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(): number {\r\n return this._physicsPlugin.getLinearDamping(this);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number): void {\r\n this._physicsPlugin.setAngularDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(): number {\r\n return this._physicsPlugin.getAngularDamping(this);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.*/\r\n public getLinearVelocityToRef(linVel: Vector3): void {\r\n return this._physicsPlugin.getLinearVelocityToRef(this, linVel);\r\n }\r\n\r\n /**\r\n * Sets the angular velocity of the physics object.\r\n * @param angVel - The angular velocity to set.\r\n *\r\n * This method is useful for setting the angular velocity of a physics object, which is necessary for\r\n * simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,\r\n * which is important for simulating realistic motion.\r\n */\r\n public setAngularVelocity(angVel: Vector3): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3): void {\r\n return this._physicsPlugin.getAngularVelocityToRef(this, angVel);\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param location The location of the impulse.\r\n * @param impulse The impulse vector.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(location: Vector3, impulse: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, location, impulse);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param location The location of the force.\r\n * @param force The force vector.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(location: Vector3, force: Vector3): void {\r\n this._physicsPlugin.applyForce(this, location, force);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): {} {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Register a collision callback that is called when the body collides\r\n * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world\r\n * and do the filtering on the user side.\r\n */\r\n public registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.registerOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Unregister a collision callback that is called when the body collides\r\n */\r\n public unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.unregisterOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Gets the object extents\r\n * @returns the object extents\r\n */\r\n public getObjectExtents(): Vector3 {\r\n const tmAbstractMesh = this.transformNode as AbstractMesh;\r\n if (tmAbstractMesh.getBoundingInfo) {\r\n const q = this.transformNode.rotationQuaternion;\r\n const scaling = this.transformNode.scaling.clone();\r\n //reset rotation\r\n this.transformNode.rotationQuaternion = PhysicsBody._IDENTITY_QUATERNION;\r\n //calculate the world matrix with no rotation\r\n const worldMatrix = this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n if (worldMatrix) {\r\n worldMatrix.decompose(scaling, undefined, undefined);\r\n }\r\n const boundingInfo = tmAbstractMesh.getBoundingInfo();\r\n // get the global scaling of the object\r\n const size = boundingInfo.boundingBox.extendSize.scale(2).multiplyInPlace(scaling);\r\n size.x = Math.abs(size.x);\r\n size.y = Math.abs(size.y);\r\n size.z = Math.abs(size.z);\r\n //bring back the rotation\r\n this.transformNode.rotationQuaternion = q;\r\n //calculate the world matrix with the new rotation\r\n this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n return size;\r\n } else {\r\n return PhysicsBody._DEFAULT_OBJECT_SIZE;\r\n }\r\n }\r\n\r\n /**\r\n * return geometric center of the associated mesh\r\n */\r\n public getObjectCenter(): Vector3 {\r\n // TODO\r\n return new Vector3(0, 0, 0);\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM9D;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA8BpB;;;;;;;;OAQG;IACH,YAAY,aAA4B,EAAE,KAAY;QAtCtD;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAa7C;;;WAGG;QACH,mBAA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CAAC,aAAa,CAAC,kBAAkB,GAAG,CAAC,CAAC;YAC1C,kDAAkD;YAClD,IAAI,CAAC,aAAa,CAAC,kBAAkB,IAAI,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACrF,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,WAAW,CAAC,oBAAoB,CAAC;SAC3C;IACL,CAAC;IAED;;OAEG;IACI,eAAe;QAClB,OAAO;QACP,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACI,aAAa,CAAC,SAAsB,EAAE,UAA6B;QACtE,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IACnE,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IACzC,CAAC;;AAvWc,gCAAoB,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,gCAAoB,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC","sourcesContent":["import type { IPhysicsEnginePluginV2, MassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode, AbstractMesh } from \"../../Meshes\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\n/**\r\n * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows\r\n * the user to set the mass and velocity of the body, which can then be used to calculate the\r\n * motion of the body in the physics engine.\r\n */\r\nexport class PhysicsBody {\r\n /**\r\n * V2 Physics plugin private data for single Transform\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * V2 Physics plugin private data for instances\r\n */\r\n public _pluginDataInstances: Array<any> = [];\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n /**\r\n * The engine used to create and manage this Physics Body\r\n */\r\n private _physicsEngine: PhysicsEngine;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n disablePreStep: boolean = true;\r\n\r\n private static _DEFAULT_OBJECT_SIZE: Vector3 = new Vector3(1, 1, 1);\r\n private static _IDENTITY_QUATERNION = Quaternion.Identity();\r\n\r\n /**\r\n * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, m);\r\n } else {\r\n // single instance\r\n this._physicsPlugin.initBody(this, transformNode.position, transformNode.rotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public setShape(shape: PhysicsShape): void {\r\n this._physicsPlugin.setShape(this, shape);\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public getShape(): PhysicsShape | undefined {\r\n return this._physicsPlugin.getShape(this);\r\n }\r\n\r\n /**\r\n * Sets the filter group of the physics body.\r\n * @param group - The filter group of the physics body.\r\n *\r\n * This method is useful for setting the filter group of the physics body.\r\n * The filter group is used to determine which bodies should collide with each other.\r\n * This allows for more control over the physics engine and can be used to create more realistic simulations.\r\n */\r\n public setFilterGroup(group: number): void {\r\n this._physicsPlugin.setFilterGroup(this, group);\r\n }\r\n\r\n /**\r\n * Gets the filter group of the physics engine.\r\n *\r\n * @returns The filter group of the physics engine.\r\n *\r\n * This method is useful for getting the filter group of the physics engine,\r\n * which is used to determine which objects will interact with each other.\r\n * This is important for creating realistic physics simulations.\r\n */\r\n public getFilterGroup(): number {\r\n return this._physicsPlugin.getFilterGroup(this);\r\n }\r\n\r\n /**\r\n * Sets the event mask for the physics engine.\r\n *\r\n * @param eventMask - A bitmask that determines which events will be sent to the physics engine.\r\n *\r\n * This method is useful for setting the event mask for the physics engine, which determines which events\r\n * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.\r\n */\r\n public setEventMask(eventMask: number): void {\r\n this._physicsPlugin.setEventMask(this, eventMask);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n *\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(): number {\r\n return this._physicsPlugin.getEventMask(this);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: MassProperties): void {\r\n this._physicsPlugin.setMassProperties(this, massProps);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n *\r\n * @returns The mass properties of the object, or `undefined` if the physics\r\n * plugin does not support mass properties.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(): MassProperties | undefined {\r\n return this._physicsPlugin.getMassProperties(this);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number): void {\r\n this._physicsPlugin.setLinearDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(): number {\r\n return this._physicsPlugin.getLinearDamping(this);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number): void {\r\n this._physicsPlugin.setAngularDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(): number {\r\n return this._physicsPlugin.getAngularDamping(this);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.*/\r\n public getLinearVelocityToRef(linVel: Vector3): void {\r\n return this._physicsPlugin.getLinearVelocityToRef(this, linVel);\r\n }\r\n\r\n /**\r\n * Sets the angular velocity of the physics object.\r\n * @param angVel - The angular velocity to set.\r\n *\r\n * This method is useful for setting the angular velocity of a physics object, which is necessary for\r\n * simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,\r\n * which is important for simulating realistic motion.\r\n */\r\n public setAngularVelocity(angVel: Vector3): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3): void {\r\n return this._physicsPlugin.getAngularVelocityToRef(this, angVel);\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyForce(this, force, location);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): {} {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Register a collision callback that is called when the body collides\r\n * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world\r\n * and do the filtering on the user side.\r\n */\r\n public registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.registerOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Unregister a collision callback that is called when the body collides\r\n */\r\n public unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.unregisterOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Gets the object extents\r\n * @returns the object extents\r\n */\r\n public getObjectExtents(): Vector3 {\r\n const tmAbstractMesh = this.transformNode as AbstractMesh;\r\n if (tmAbstractMesh.getBoundingInfo) {\r\n const q = this.transformNode.rotationQuaternion;\r\n const scaling = this.transformNode.scaling.clone();\r\n //reset rotation\r\n this.transformNode.rotationQuaternion = PhysicsBody._IDENTITY_QUATERNION;\r\n //calculate the world matrix with no rotation\r\n const worldMatrix = this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n if (worldMatrix) {\r\n worldMatrix.decompose(scaling, undefined, undefined);\r\n }\r\n const boundingInfo = tmAbstractMesh.getBoundingInfo();\r\n // get the global scaling of the object\r\n const size = boundingInfo.boundingBox.extendSize.scale(2).multiplyInPlace(scaling);\r\n size.x = Math.abs(size.x);\r\n size.y = Math.abs(size.y);\r\n size.z = Math.abs(size.z);\r\n //bring back the rotation\r\n this.transformNode.rotationQuaternion = q;\r\n //calculate the world matrix with the new rotation\r\n this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n return size;\r\n } else {\r\n return PhysicsBody._DEFAULT_OBJECT_SIZE;\r\n }\r\n }\r\n\r\n /**\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenter(): Vector3 {\r\n // TODO\r\n return new Vector3(0, 0, 0);\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint);\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n }\r\n}\r\n"]}
|