@babylonjs/core 5.35.0 → 5.36.0

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.
Files changed (250) hide show
  1. package/Audio/sound.d.ts +5 -0
  2. package/Audio/sound.js +7 -0
  3. package/Audio/sound.js.map +1 -1
  4. package/Debug/physicsViewer.d.ts +4 -3
  5. package/Debug/physicsViewer.js +2 -2
  6. package/Debug/physicsViewer.js.map +1 -1
  7. package/Engines/Extensions/engine.renderTarget.js +15 -15
  8. package/Engines/Extensions/engine.renderTarget.js.map +1 -1
  9. package/Engines/Extensions/engine.renderTargetCube.d.ts +1 -1
  10. package/Engines/Extensions/engine.renderTargetCube.js.map +1 -1
  11. package/Engines/Extensions/engine.views.d.ts +4 -0
  12. package/Engines/Extensions/engine.views.js +61 -42
  13. package/Engines/Extensions/engine.views.js.map +1 -1
  14. package/Engines/Native/nativeHardwareTexture.d.ts +14 -0
  15. package/Engines/Native/nativeHardwareTexture.js +24 -0
  16. package/Engines/Native/nativeHardwareTexture.js.map +1 -0
  17. package/Engines/Native/nativeInterfaces.d.ts +22 -15
  18. package/Engines/Native/nativeInterfaces.js.map +1 -1
  19. package/Engines/Native/nativePipelineContext.d.ts +252 -0
  20. package/Engines/Native/nativePipelineContext.js +502 -0
  21. package/Engines/Native/nativePipelineContext.js.map +1 -0
  22. package/Engines/Native/nativeRenderTargetWrapper.d.ts +16 -0
  23. package/Engines/Native/nativeRenderTargetWrapper.js +33 -0
  24. package/Engines/Native/nativeRenderTargetWrapper.js.map +1 -0
  25. package/Engines/WebGPU/Extensions/engine.renderTarget.js +3 -3
  26. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  27. package/Engines/WebGPU/Extensions/engine.renderTargetCube.js.map +1 -1
  28. package/Engines/engine.d.ts +1 -0
  29. package/Engines/engine.js +24 -18
  30. package/Engines/engine.js.map +1 -1
  31. package/Engines/nativeEngine.d.ts +18 -17
  32. package/Engines/nativeEngine.js +100 -598
  33. package/Engines/nativeEngine.js.map +1 -1
  34. package/Engines/nullEngine.d.ts +1 -1
  35. package/Engines/nullEngine.js.map +1 -1
  36. package/Engines/thinEngine.d.ts +1 -1
  37. package/Engines/thinEngine.js +41 -38
  38. package/Engines/thinEngine.js.map +1 -1
  39. package/Engines/webgpuEngine.js.map +1 -1
  40. package/Gizmos/planeRotationGizmo.js +3 -1
  41. package/Gizmos/planeRotationGizmo.js.map +1 -1
  42. package/Inputs/scene.inputManager.js +4 -4
  43. package/Inputs/scene.inputManager.js.map +1 -1
  44. package/Loading/Plugins/babylonFileLoader.js +3 -3
  45. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  46. package/Materials/Node/Blocks/Dual/textureBlock.js +1 -1
  47. package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
  48. package/Materials/Node/nodeMaterial.d.ts +19 -1
  49. package/Materials/Node/nodeMaterial.js +30 -0
  50. package/Materials/Node/nodeMaterial.js.map +1 -1
  51. package/Materials/Node/nodeMaterialBuildStateSharedData.d.ts +2 -8
  52. package/Materials/Node/nodeMaterialBuildStateSharedData.js.map +1 -1
  53. package/Materials/Textures/baseTexture.d.ts +2 -1
  54. package/Materials/Textures/baseTexture.js +3 -2
  55. package/Materials/Textures/baseTexture.js.map +1 -1
  56. package/Materials/Textures/internalTexture.d.ts +2 -0
  57. package/Materials/Textures/internalTexture.js +4 -0
  58. package/Materials/Textures/internalTexture.js.map +1 -1
  59. package/Materials/Textures/mirrorTexture.js +0 -2
  60. package/Materials/Textures/mirrorTexture.js.map +1 -1
  61. package/Materials/Textures/renderTargetTexture.d.ts +53 -3
  62. package/Materials/Textures/renderTargetTexture.js +25 -25
  63. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  64. package/Materials/Textures/texture.d.ts +2 -0
  65. package/Materials/Textures/texture.js +35 -7
  66. package/Materials/Textures/texture.js.map +1 -1
  67. package/Materials/Textures/textureCreationOptions.d.ts +4 -1
  68. package/Materials/Textures/textureCreationOptions.js.map +1 -1
  69. package/Materials/material.js +1 -1
  70. package/Materials/material.js.map +1 -1
  71. package/Meshes/abstractMesh.d.ts +4 -4
  72. package/Meshes/abstractMesh.js +4 -4
  73. package/Meshes/abstractMesh.js.map +1 -1
  74. package/Meshes/mesh.d.ts +2 -2
  75. package/Meshes/mesh.js +1 -1
  76. package/Meshes/mesh.js.map +1 -1
  77. package/Misc/copyTextureToTexture.d.ts +9 -2
  78. package/Misc/copyTextureToTexture.js +23 -1
  79. package/Misc/copyTextureToTexture.js.map +1 -1
  80. package/Particles/IParticleSystem.d.ts +15 -1
  81. package/Particles/IParticleSystem.js.map +1 -1
  82. package/Particles/gpuParticleSystem.d.ts +24 -2
  83. package/Particles/gpuParticleSystem.js +98 -43
  84. package/Particles/gpuParticleSystem.js.map +1 -1
  85. package/Particles/particleSystem.d.ts +6 -1
  86. package/Particles/particleSystem.js +7 -2
  87. package/Particles/particleSystem.js.map +1 -1
  88. package/Physics/IPhysicsEngine.d.ts +8 -108
  89. package/Physics/IPhysicsEngine.js.map +1 -1
  90. package/Physics/Plugins/ammoJSPlugin.d.ts +1 -389
  91. package/Physics/Plugins/ammoJSPlugin.js +2 -1414
  92. package/Physics/Plugins/ammoJSPlugin.js.map +1 -1
  93. package/Physics/Plugins/cannonJSPlugin.d.ts +1 -75
  94. package/Physics/Plugins/cannonJSPlugin.js +2 -664
  95. package/Physics/Plugins/cannonJSPlugin.js.map +1 -1
  96. package/Physics/Plugins/oimoJSPlugin.d.ts +1 -59
  97. package/Physics/Plugins/oimoJSPlugin.js +2 -432
  98. package/Physics/Plugins/oimoJSPlugin.js.map +1 -1
  99. package/Physics/index.d.ts +3 -6
  100. package/Physics/index.js +3 -6
  101. package/Physics/index.js.map +1 -1
  102. package/Physics/physicsEngine.d.ts +1 -135
  103. package/Physics/physicsEngine.js +2 -221
  104. package/Physics/physicsEngine.js.map +1 -1
  105. package/Physics/physicsEngineComponent.d.ts +7 -42
  106. package/Physics/physicsEngineComponent.js +11 -71
  107. package/Physics/physicsEngineComponent.js.map +1 -1
  108. package/Physics/physicsHelper.d.ts +1 -411
  109. package/Physics/physicsHelper.js +2 -708
  110. package/Physics/physicsHelper.js.map +1 -1
  111. package/Physics/physicsImpostor.d.ts +1 -640
  112. package/Physics/physicsImpostor.js +2 -1004
  113. package/Physics/physicsImpostor.js.map +1 -1
  114. package/Physics/physicsJoint.d.ts +1 -275
  115. package/Physics/physicsJoint.js +2 -222
  116. package/Physics/physicsJoint.js.map +1 -1
  117. package/Physics/v1/IPhysicsEnginePlugin.d.ts +73 -0
  118. package/Physics/v1/IPhysicsEnginePlugin.js +2 -0
  119. package/Physics/v1/IPhysicsEnginePlugin.js.map +1 -0
  120. package/Physics/v1/Plugins/ammoJSPlugin.d.ts +401 -0
  121. package/Physics/v1/Plugins/ammoJSPlugin.js +1431 -0
  122. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -0
  123. package/Physics/v1/Plugins/cannonJSPlugin.d.ts +87 -0
  124. package/Physics/v1/Plugins/cannonJSPlugin.js +683 -0
  125. package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -0
  126. package/Physics/{Plugins → v1/Plugins}/index.d.ts +0 -0
  127. package/Physics/{Plugins → v1/Plugins}/index.js +0 -0
  128. package/Physics/v1/Plugins/index.js.map +1 -0
  129. package/Physics/v1/Plugins/oimoJSPlugin.d.ts +71 -0
  130. package/Physics/v1/Plugins/oimoJSPlugin.js +450 -0
  131. package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -0
  132. package/Physics/v1/index.d.ts +7 -0
  133. package/Physics/v1/index.js +9 -0
  134. package/Physics/v1/index.js.map +1 -0
  135. package/Physics/v1/physicsEngine.d.ts +147 -0
  136. package/Physics/v1/physicsEngine.js +237 -0
  137. package/Physics/v1/physicsEngine.js.map +1 -0
  138. package/Physics/v1/physicsEngineComponent.d.ts +45 -0
  139. package/Physics/v1/physicsEngineComponent.js +70 -0
  140. package/Physics/v1/physicsEngineComponent.js.map +1 -0
  141. package/Physics/v1/physicsHelper.d.ts +411 -0
  142. package/Physics/v1/physicsHelper.js +709 -0
  143. package/Physics/v1/physicsHelper.js.map +1 -0
  144. package/Physics/v1/physicsImpostor.d.ts +636 -0
  145. package/Physics/v1/physicsImpostor.js +1001 -0
  146. package/Physics/v1/physicsImpostor.js.map +1 -0
  147. package/Physics/v1/physicsJoint.d.ts +275 -0
  148. package/Physics/v1/physicsJoint.js +223 -0
  149. package/Physics/v1/physicsJoint.js.map +1 -0
  150. package/Physics/v2/IPhysicsEnginePlugin.d.ts +170 -0
  151. package/Physics/v2/IPhysicsEnginePlugin.js +47 -0
  152. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -0
  153. package/Physics/v2/Plugins/index.d.ts +0 -0
  154. package/Physics/v2/Plugins/index.js +2 -0
  155. package/Physics/v2/Plugins/index.js.map +1 -0
  156. package/Physics/v2/index.d.ts +6 -0
  157. package/Physics/v2/index.js +8 -0
  158. package/Physics/v2/index.js.map +1 -0
  159. package/Physics/v2/physicsAggregate.d.ts +114 -0
  160. package/Physics/v2/physicsAggregate.js +46 -0
  161. package/Physics/v2/physicsAggregate.js.map +1 -0
  162. package/Physics/v2/physicsBody.d.ts +109 -0
  163. package/Physics/v2/physicsBody.js +158 -0
  164. package/Physics/v2/physicsBody.js.map +1 -0
  165. package/Physics/v2/physicsConstraint.d.ts +184 -0
  166. package/Physics/v2/physicsConstraint.js +257 -0
  167. package/Physics/v2/physicsConstraint.js.map +1 -0
  168. package/Physics/v2/physicsEngine.d.ts +103 -0
  169. package/Physics/v2/physicsEngine.js +146 -0
  170. package/Physics/v2/physicsEngine.js.map +1 -0
  171. package/Physics/v2/physicsEngineComponent.d.ts +31 -0
  172. package/Physics/v2/physicsEngineComponent.js +50 -0
  173. package/Physics/v2/physicsEngineComponent.js.map +1 -0
  174. package/Physics/v2/physicsMaterial.d.ts +45 -0
  175. package/Physics/v2/physicsMaterial.js +67 -0
  176. package/Physics/v2/physicsMaterial.js.map +1 -0
  177. package/Physics/v2/physicsShape.d.ts +182 -0
  178. package/Physics/v2/physicsShape.js +229 -0
  179. package/Physics/v2/physicsShape.js.map +1 -0
  180. package/PostProcesses/postProcess.d.ts +3 -1
  181. package/PostProcesses/postProcess.js +4 -1
  182. package/PostProcesses/postProcess.js.map +1 -1
  183. package/Rendering/fluidRenderer/fluidRenderer.d.ts +153 -0
  184. package/Rendering/fluidRenderer/fluidRenderer.js +410 -0
  185. package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -0
  186. package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.d.ts +13 -0
  187. package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js +31 -0
  188. package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js.map +1 -0
  189. package/Rendering/fluidRenderer/fluidRenderingObject.d.ts +81 -0
  190. package/Rendering/fluidRenderer/fluidRenderingObject.js +180 -0
  191. package/Rendering/fluidRenderer/fluidRenderingObject.js.map +1 -0
  192. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.d.ts +63 -0
  193. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js +130 -0
  194. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js.map +1 -0
  195. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.d.ts +64 -0
  196. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js +104 -0
  197. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js.map +1 -0
  198. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.d.ts +234 -0
  199. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +690 -0
  200. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -0
  201. package/Rendering/fluidRenderer/fluidRenderingTextures.d.ts +56 -0
  202. package/Rendering/fluidRenderer/fluidRenderingTextures.js +261 -0
  203. package/Rendering/fluidRenderer/fluidRenderingTextures.js.map +1 -0
  204. package/Rendering/fluidRenderer/index.d.ts +5 -0
  205. package/Rendering/fluidRenderer/index.js +6 -0
  206. package/Rendering/fluidRenderer/index.js.map +1 -0
  207. package/Rendering/index.d.ts +1 -0
  208. package/Rendering/index.js +2 -0
  209. package/Rendering/index.js.map +1 -1
  210. package/Shaders/copyTextureToTexture.fragment.js +4 -1
  211. package/Shaders/copyTextureToTexture.fragment.js.map +1 -1
  212. package/Shaders/fluidRenderingBilateralBlur.fragment.d.ts +5 -0
  213. package/Shaders/fluidRenderingBilateralBlur.fragment.js +9 -0
  214. package/Shaders/fluidRenderingBilateralBlur.fragment.js.map +1 -0
  215. package/Shaders/fluidRenderingParticleDepth.fragment.d.ts +5 -0
  216. package/Shaders/fluidRenderingParticleDepth.fragment.js +17 -0
  217. package/Shaders/fluidRenderingParticleDepth.fragment.js.map +1 -0
  218. package/Shaders/fluidRenderingParticleDepth.vertex.d.ts +5 -0
  219. package/Shaders/fluidRenderingParticleDepth.vertex.js +13 -0
  220. package/Shaders/fluidRenderingParticleDepth.vertex.js.map +1 -0
  221. package/Shaders/fluidRenderingParticleDiffuse.fragment.d.ts +5 -0
  222. package/Shaders/fluidRenderingParticleDiffuse.fragment.js +9 -0
  223. package/Shaders/fluidRenderingParticleDiffuse.fragment.js.map +1 -0
  224. package/Shaders/fluidRenderingParticleDiffuse.vertex.d.ts +5 -0
  225. package/Shaders/fluidRenderingParticleDiffuse.vertex.js +4 -0
  226. package/Shaders/fluidRenderingParticleDiffuse.vertex.js.map +1 -0
  227. package/Shaders/fluidRenderingParticleThickness.fragment.d.ts +5 -0
  228. package/Shaders/fluidRenderingParticleThickness.fragment.js +9 -0
  229. package/Shaders/fluidRenderingParticleThickness.fragment.js.map +1 -0
  230. package/Shaders/fluidRenderingParticleThickness.vertex.d.ts +5 -0
  231. package/Shaders/fluidRenderingParticleThickness.vertex.js +9 -0
  232. package/Shaders/fluidRenderingParticleThickness.vertex.js.map +1 -0
  233. package/Shaders/fluidRenderingRender.fragment.d.ts +5 -0
  234. package/Shaders/fluidRenderingRender.fragment.js +46 -0
  235. package/Shaders/fluidRenderingRender.fragment.js.map +1 -0
  236. package/Shaders/fluidRenderingStandardBlur.fragment.d.ts +5 -0
  237. package/Shaders/fluidRenderingStandardBlur.fragment.js +9 -0
  238. package/Shaders/fluidRenderingStandardBlur.fragment.js.map +1 -0
  239. package/XR/features/WebXRControllerPhysics.d.ts +1 -1
  240. package/XR/features/WebXRControllerPhysics.js +1 -1
  241. package/XR/features/WebXRControllerPhysics.js.map +1 -1
  242. package/XR/features/WebXRHandTracking.js +1 -1
  243. package/XR/features/WebXRHandTracking.js.map +1 -1
  244. package/package.json +1 -1
  245. package/scene.js +6 -1
  246. package/scene.js.map +1 -1
  247. package/sceneComponent.d.ts +3 -0
  248. package/sceneComponent.js +3 -0
  249. package/sceneComponent.js.map +1 -1
  250. package/Physics/Plugins/index.js.map +0 -1
@@ -0,0 +1,1001 @@
1
+ import { Logger } from "../../Misc/logger.js";
2
+ import { ArrayTools } from "../../Misc/arrayTools.js";
3
+ import { Vector3, Quaternion } from "../../Maths/math.vector.js";
4
+ import { AbstractMesh } from "../../Meshes/abstractMesh.js";
5
+ import { Mesh } from "../../Meshes/mesh.js";
6
+ import { PhysicsJoint } from "./physicsJoint.js";
7
+ import { Space } from "../../Maths/math.axis.js";
8
+ Mesh._PhysicsImpostorParser = function (scene, physicObject, jsonObject) {
9
+ return new PhysicsImpostor(physicObject, jsonObject.physicsImpostor, {
10
+ mass: jsonObject.physicsMass,
11
+ friction: jsonObject.physicsFriction,
12
+ restitution: jsonObject.physicsRestitution,
13
+ }, scene);
14
+ };
15
+ /**
16
+ * Represents a physics imposter
17
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
18
+ */
19
+ export class PhysicsImpostor {
20
+ /**
21
+ * Initializes the physics imposter
22
+ * @param object The physics-enabled object used as the physics imposter
23
+ * @param type The type of the physics imposter. Types are available as static members of this class.
24
+ * @param _options The options for the physics imposter
25
+ * @param _scene The Babylon scene
26
+ */
27
+ constructor(
28
+ /**
29
+ * The physics-enabled object used as the physics imposter
30
+ */
31
+ object,
32
+ /**
33
+ * The type of the physics imposter
34
+ */
35
+ type, _options = { mass: 0 }, _scene) {
36
+ this.object = object;
37
+ this.type = type;
38
+ this._options = _options;
39
+ this._scene = _scene;
40
+ /** @internal */
41
+ this._pluginData = {};
42
+ this._bodyUpdateRequired = false;
43
+ this._onBeforePhysicsStepCallbacks = new Array();
44
+ this._onAfterPhysicsStepCallbacks = new Array();
45
+ /** @internal */
46
+ this._onPhysicsCollideCallbacks = [];
47
+ this._deltaPosition = Vector3.Zero();
48
+ this._isDisposed = false;
49
+ /**
50
+ * @internal
51
+ */
52
+ this.soft = false;
53
+ /**
54
+ * @internal
55
+ */
56
+ this.segments = 0;
57
+ //temp variables for parent rotation calculations
58
+ //private _mats: Array<Matrix> = [new Matrix(), new Matrix()];
59
+ this._tmpQuat = new Quaternion();
60
+ this._tmpQuat2 = new Quaternion();
61
+ /**
62
+ * this function is executed by the physics engine.
63
+ */
64
+ this.beforeStep = () => {
65
+ if (!this._physicsEngine) {
66
+ return;
67
+ }
68
+ this.object.translate(this._deltaPosition, -1);
69
+ this._deltaRotationConjugated &&
70
+ this.object.rotationQuaternion &&
71
+ this.object.rotationQuaternion.multiplyToRef(this._deltaRotationConjugated, this.object.rotationQuaternion);
72
+ this.object.computeWorldMatrix(false);
73
+ if (this.object.parent && this.object.rotationQuaternion) {
74
+ this.getParentsRotation();
75
+ this._tmpQuat.multiplyToRef(this.object.rotationQuaternion, this._tmpQuat);
76
+ }
77
+ else {
78
+ this._tmpQuat.copyFrom(this.object.rotationQuaternion || new Quaternion());
79
+ }
80
+ if (!this._options.disableBidirectionalTransformation) {
81
+ this.object.rotationQuaternion &&
82
+ this._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(this, /*bInfo.boundingBox.centerWorld*/ this.object.getAbsolutePosition(), this._tmpQuat);
83
+ }
84
+ this._onBeforePhysicsStepCallbacks.forEach((func) => {
85
+ func(this);
86
+ });
87
+ };
88
+ /**
89
+ * this function is executed by the physics engine
90
+ */
91
+ this.afterStep = () => {
92
+ if (!this._physicsEngine) {
93
+ return;
94
+ }
95
+ this._onAfterPhysicsStepCallbacks.forEach((func) => {
96
+ func(this);
97
+ });
98
+ this._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(this);
99
+ // object has now its world rotation. needs to be converted to local.
100
+ if (this.object.parent && this.object.rotationQuaternion) {
101
+ this.getParentsRotation();
102
+ this._tmpQuat.conjugateInPlace();
103
+ this._tmpQuat.multiplyToRef(this.object.rotationQuaternion, this.object.rotationQuaternion);
104
+ }
105
+ // take the position set and make it the absolute position of this object.
106
+ this.object.setAbsolutePosition(this.object.position);
107
+ if (this._deltaRotation) {
108
+ this.object.rotationQuaternion && this.object.rotationQuaternion.multiplyToRef(this._deltaRotation, this.object.rotationQuaternion);
109
+ this._deltaPosition.applyRotationQuaternionToRef(this._deltaRotation, PhysicsImpostor._TmpVecs[0]);
110
+ this.object.translate(PhysicsImpostor._TmpVecs[0], 1);
111
+ }
112
+ else {
113
+ this.object.translate(this._deltaPosition, 1);
114
+ }
115
+ this.object.computeWorldMatrix(true);
116
+ };
117
+ /**
118
+ * Legacy collision detection event support
119
+ */
120
+ this.onCollideEvent = null;
121
+ /**
122
+ *
123
+ * @param e
124
+ * @returns
125
+ */
126
+ this.onCollide = (e) => {
127
+ if (!this._onPhysicsCollideCallbacks.length && !this.onCollideEvent) {
128
+ return;
129
+ }
130
+ if (!this._physicsEngine) {
131
+ return;
132
+ }
133
+ const otherImpostor = this._physicsEngine.getImpostorWithPhysicsBody(e.body);
134
+ if (otherImpostor) {
135
+ // Legacy collision detection event support
136
+ if (this.onCollideEvent) {
137
+ this.onCollideEvent(this, otherImpostor);
138
+ }
139
+ this._onPhysicsCollideCallbacks
140
+ .filter((obj) => {
141
+ return obj.otherImpostors.indexOf(otherImpostor) !== -1;
142
+ })
143
+ .forEach((obj) => {
144
+ obj.callback(this, otherImpostor, e.point, e.distance, e.impulse, e.normal);
145
+ });
146
+ }
147
+ };
148
+ //sanity check!
149
+ if (!this.object) {
150
+ Logger.Error("No object was provided. A physics object is obligatory");
151
+ return;
152
+ }
153
+ if (this.object.parent && _options.mass !== 0) {
154
+ Logger.Warn("A physics impostor has been created for an object which has a parent. Babylon physics currently works in local space so unexpected issues may occur.");
155
+ }
156
+ // Legacy support for old syntax.
157
+ if (!this._scene && object.getScene) {
158
+ this._scene = object.getScene();
159
+ }
160
+ if (!this._scene) {
161
+ return;
162
+ }
163
+ if (this.type > 100) {
164
+ this.soft = true;
165
+ }
166
+ this._physicsEngine = this._scene.getPhysicsEngine();
167
+ if (!this._physicsEngine) {
168
+ Logger.Error("Physics not enabled. Please use scene.enablePhysics(...) before creating impostors.");
169
+ }
170
+ else {
171
+ //set the object's quaternion, if not set
172
+ if (!this.object.rotationQuaternion) {
173
+ if (this.object.rotation) {
174
+ this.object.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.object.rotation.y, this.object.rotation.x, this.object.rotation.z);
175
+ }
176
+ else {
177
+ this.object.rotationQuaternion = new Quaternion();
178
+ }
179
+ }
180
+ //default options params
181
+ this._options.mass = _options.mass === void 0 ? 0 : _options.mass;
182
+ this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;
183
+ this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;
184
+ if (this.soft) {
185
+ //softbody mass must be above 0;
186
+ this._options.mass = this._options.mass > 0 ? this._options.mass : 1;
187
+ this._options.pressure = _options.pressure === void 0 ? 200 : _options.pressure;
188
+ this._options.stiffness = _options.stiffness === void 0 ? 1 : _options.stiffness;
189
+ this._options.velocityIterations = _options.velocityIterations === void 0 ? 20 : _options.velocityIterations;
190
+ this._options.positionIterations = _options.positionIterations === void 0 ? 20 : _options.positionIterations;
191
+ this._options.fixedPoints = _options.fixedPoints === void 0 ? 0 : _options.fixedPoints;
192
+ this._options.margin = _options.margin === void 0 ? 0 : _options.margin;
193
+ this._options.damping = _options.damping === void 0 ? 0 : _options.damping;
194
+ this._options.path = _options.path === void 0 ? null : _options.path;
195
+ this._options.shape = _options.shape === void 0 ? null : _options.shape;
196
+ }
197
+ this._joints = [];
198
+ //If the mesh has a parent, don't initialize the physicsBody. Instead wait for the parent to do that.
199
+ if (!this.object.parent || this._options.ignoreParent) {
200
+ this._init();
201
+ }
202
+ else if (this.object.parent.physicsImpostor) {
203
+ Logger.Warn("You must affect impostors to children before affecting impostor to parent.");
204
+ }
205
+ }
206
+ }
207
+ /**
208
+ * Specifies if the physics imposter is disposed
209
+ */
210
+ get isDisposed() {
211
+ return this._isDisposed;
212
+ }
213
+ /**
214
+ * Gets the mass of the physics imposter
215
+ */
216
+ get mass() {
217
+ return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyMass(this) : 0;
218
+ }
219
+ set mass(value) {
220
+ this.setMass(value);
221
+ }
222
+ /**
223
+ * Gets the coefficient of friction
224
+ */
225
+ get friction() {
226
+ return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyFriction(this) : 0;
227
+ }
228
+ /**
229
+ * Sets the coefficient of friction
230
+ */
231
+ set friction(value) {
232
+ if (!this._physicsEngine) {
233
+ return;
234
+ }
235
+ this._physicsEngine.getPhysicsPlugin().setBodyFriction(this, value);
236
+ }
237
+ /**
238
+ * Gets the coefficient of restitution
239
+ */
240
+ get restitution() {
241
+ return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyRestitution(this) : 0;
242
+ }
243
+ /**
244
+ * Sets the coefficient of restitution
245
+ */
246
+ set restitution(value) {
247
+ if (!this._physicsEngine) {
248
+ return;
249
+ }
250
+ this._physicsEngine.getPhysicsPlugin().setBodyRestitution(this, value);
251
+ }
252
+ /**
253
+ * Gets the pressure of a soft body; only supported by the AmmoJSPlugin
254
+ */
255
+ get pressure() {
256
+ if (!this._physicsEngine) {
257
+ return 0;
258
+ }
259
+ const plugin = this._physicsEngine.getPhysicsPlugin();
260
+ if (!plugin.setBodyPressure) {
261
+ return 0;
262
+ }
263
+ return plugin.getBodyPressure(this);
264
+ }
265
+ /**
266
+ * Sets the pressure of a soft body; only supported by the AmmoJSPlugin
267
+ */
268
+ set pressure(value) {
269
+ if (!this._physicsEngine) {
270
+ return;
271
+ }
272
+ const plugin = this._physicsEngine.getPhysicsPlugin();
273
+ if (!plugin.setBodyPressure) {
274
+ return;
275
+ }
276
+ plugin.setBodyPressure(this, value);
277
+ }
278
+ /**
279
+ * Gets the stiffness of a soft body; only supported by the AmmoJSPlugin
280
+ */
281
+ get stiffness() {
282
+ if (!this._physicsEngine) {
283
+ return 0;
284
+ }
285
+ const plugin = this._physicsEngine.getPhysicsPlugin();
286
+ if (!plugin.getBodyStiffness) {
287
+ return 0;
288
+ }
289
+ return plugin.getBodyStiffness(this);
290
+ }
291
+ /**
292
+ * Sets the stiffness of a soft body; only supported by the AmmoJSPlugin
293
+ */
294
+ set stiffness(value) {
295
+ if (!this._physicsEngine) {
296
+ return;
297
+ }
298
+ const plugin = this._physicsEngine.getPhysicsPlugin();
299
+ if (!plugin.setBodyStiffness) {
300
+ return;
301
+ }
302
+ plugin.setBodyStiffness(this, value);
303
+ }
304
+ /**
305
+ * Gets the velocityIterations of a soft body; only supported by the AmmoJSPlugin
306
+ */
307
+ get velocityIterations() {
308
+ if (!this._physicsEngine) {
309
+ return 0;
310
+ }
311
+ const plugin = this._physicsEngine.getPhysicsPlugin();
312
+ if (!plugin.getBodyVelocityIterations) {
313
+ return 0;
314
+ }
315
+ return plugin.getBodyVelocityIterations(this);
316
+ }
317
+ /**
318
+ * Sets the velocityIterations of a soft body; only supported by the AmmoJSPlugin
319
+ */
320
+ set velocityIterations(value) {
321
+ if (!this._physicsEngine) {
322
+ return;
323
+ }
324
+ const plugin = this._physicsEngine.getPhysicsPlugin();
325
+ if (!plugin.setBodyVelocityIterations) {
326
+ return;
327
+ }
328
+ plugin.setBodyVelocityIterations(this, value);
329
+ }
330
+ /**
331
+ * Gets the positionIterations of a soft body; only supported by the AmmoJSPlugin
332
+ */
333
+ get positionIterations() {
334
+ if (!this._physicsEngine) {
335
+ return 0;
336
+ }
337
+ const plugin = this._physicsEngine.getPhysicsPlugin();
338
+ if (!plugin.getBodyPositionIterations) {
339
+ return 0;
340
+ }
341
+ return plugin.getBodyPositionIterations(this);
342
+ }
343
+ /**
344
+ * Sets the positionIterations of a soft body; only supported by the AmmoJSPlugin
345
+ */
346
+ set positionIterations(value) {
347
+ if (!this._physicsEngine) {
348
+ return;
349
+ }
350
+ const plugin = this._physicsEngine.getPhysicsPlugin();
351
+ if (!plugin.setBodyPositionIterations) {
352
+ return;
353
+ }
354
+ plugin.setBodyPositionIterations(this, value);
355
+ }
356
+ /**
357
+ * This function will completely initialize this impostor.
358
+ * It will create a new body - but only if this mesh has no parent.
359
+ * If it has, this impostor will not be used other than to define the impostor
360
+ * of the child mesh.
361
+ * @internal
362
+ */
363
+ _init() {
364
+ if (!this._physicsEngine) {
365
+ return;
366
+ }
367
+ this._physicsEngine.removeImpostor(this);
368
+ this.physicsBody = null;
369
+ this._parent = this._parent || this._getPhysicsParent();
370
+ if (!this._isDisposed && (!this.parent || this._options.ignoreParent)) {
371
+ this._physicsEngine.addImpostor(this);
372
+ }
373
+ }
374
+ _getPhysicsParent() {
375
+ if (this.object.parent instanceof AbstractMesh) {
376
+ const parentMesh = this.object.parent;
377
+ return parentMesh.physicsImpostor;
378
+ }
379
+ return null;
380
+ }
381
+ /**
382
+ * Should a new body be generated.
383
+ * @returns boolean specifying if body initialization is required
384
+ */
385
+ isBodyInitRequired() {
386
+ return this._bodyUpdateRequired || (!this._physicsBody && (!this._parent || !!this._options.ignoreParent));
387
+ }
388
+ /**
389
+ * Sets the updated scaling
390
+ */
391
+ setScalingUpdated() {
392
+ this.forceUpdate();
393
+ }
394
+ /**
395
+ * Force a regeneration of this or the parent's impostor's body.
396
+ * Use with caution - This will remove all previously-instantiated joints.
397
+ */
398
+ forceUpdate() {
399
+ this._init();
400
+ if (this.parent && !this._options.ignoreParent) {
401
+ this.parent.forceUpdate();
402
+ }
403
+ }
404
+ /*public get mesh(): AbstractMesh {
405
+ return this._mesh;
406
+ }*/
407
+ /**
408
+ * Gets the body that holds this impostor. Either its own, or its parent.
409
+ */
410
+ get physicsBody() {
411
+ return this._parent && !this._options.ignoreParent ? this._parent.physicsBody : this._physicsBody;
412
+ }
413
+ /**
414
+ * Get the parent of the physics imposter
415
+ * @returns Physics imposter or null
416
+ */
417
+ get parent() {
418
+ return !this._options.ignoreParent && this._parent ? this._parent : null;
419
+ }
420
+ /**
421
+ * Sets the parent of the physics imposter
422
+ */
423
+ set parent(value) {
424
+ this._parent = value;
425
+ }
426
+ /**
427
+ * Set the physics body. Used mainly by the physics engine/plugin
428
+ */
429
+ set physicsBody(physicsBody) {
430
+ if (this._physicsBody && this._physicsEngine) {
431
+ this._physicsEngine.getPhysicsPlugin().removePhysicsBody(this);
432
+ }
433
+ this._physicsBody = physicsBody;
434
+ this.resetUpdateFlags();
435
+ }
436
+ /**
437
+ * Resets the update flags
438
+ */
439
+ resetUpdateFlags() {
440
+ this._bodyUpdateRequired = false;
441
+ }
442
+ /**
443
+ * Gets the object extents
444
+ * @returns the object extents
445
+ */
446
+ getObjectExtents() {
447
+ if (this.object.getBoundingInfo) {
448
+ const q = this.object.rotationQuaternion;
449
+ const scaling = this.object.scaling.clone();
450
+ //reset rotation
451
+ this.object.rotationQuaternion = PhysicsImpostor.IDENTITY_QUATERNION;
452
+ //calculate the world matrix with no rotation
453
+ const worldMatrix = this.object.computeWorldMatrix && this.object.computeWorldMatrix(true);
454
+ if (worldMatrix) {
455
+ worldMatrix.decompose(scaling, undefined, undefined);
456
+ }
457
+ const boundingInfo = this.object.getBoundingInfo();
458
+ // get the global scaling of the object
459
+ const size = boundingInfo.boundingBox.extendSize.scale(2).multiplyInPlace(scaling);
460
+ size.x = Math.abs(size.x);
461
+ size.y = Math.abs(size.y);
462
+ size.z = Math.abs(size.z);
463
+ //bring back the rotation
464
+ this.object.rotationQuaternion = q;
465
+ //calculate the world matrix with the new rotation
466
+ this.object.computeWorldMatrix && this.object.computeWorldMatrix(true);
467
+ return size;
468
+ }
469
+ else {
470
+ return PhysicsImpostor.DEFAULT_OBJECT_SIZE;
471
+ }
472
+ }
473
+ /**
474
+ * Gets the object center
475
+ * @returns The object center
476
+ */
477
+ getObjectCenter() {
478
+ if (this.object.getBoundingInfo) {
479
+ const boundingInfo = this.object.getBoundingInfo();
480
+ return boundingInfo.boundingBox.centerWorld;
481
+ }
482
+ else {
483
+ return this.object.position;
484
+ }
485
+ }
486
+ /**
487
+ * Get a specific parameter from the options parameters
488
+ * @param paramName The object parameter name
489
+ * @returns The object parameter
490
+ */
491
+ getParam(paramName) {
492
+ return this._options[paramName];
493
+ }
494
+ /**
495
+ * Sets a specific parameter in the options given to the physics plugin
496
+ * @param paramName The parameter name
497
+ * @param value The value of the parameter
498
+ */
499
+ setParam(paramName, value) {
500
+ this._options[paramName] = value;
501
+ this._bodyUpdateRequired = true;
502
+ }
503
+ /**
504
+ * Specifically change the body's mass. Won't recreate the physics body object
505
+ * @param mass The mass of the physics imposter
506
+ */
507
+ setMass(mass) {
508
+ if (this.getParam("mass") !== mass) {
509
+ this.setParam("mass", mass);
510
+ }
511
+ if (this._physicsEngine) {
512
+ this._physicsEngine.getPhysicsPlugin().setBodyMass(this, mass);
513
+ }
514
+ }
515
+ /**
516
+ * Gets the linear velocity
517
+ * @returns linear velocity or null
518
+ */
519
+ getLinearVelocity() {
520
+ return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this) : Vector3.Zero();
521
+ }
522
+ /**
523
+ * Sets the linear velocity
524
+ * @param velocity linear velocity or null
525
+ */
526
+ setLinearVelocity(velocity) {
527
+ if (this._physicsEngine) {
528
+ this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this, velocity);
529
+ }
530
+ }
531
+ /**
532
+ * Gets the angular velocity
533
+ * @returns angular velocity or null
534
+ */
535
+ getAngularVelocity() {
536
+ return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this) : Vector3.Zero();
537
+ }
538
+ /**
539
+ * Sets the angular velocity
540
+ * @param velocity The velocity or null
541
+ */
542
+ setAngularVelocity(velocity) {
543
+ if (this._physicsEngine) {
544
+ this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this, velocity);
545
+ }
546
+ }
547
+ /**
548
+ * Execute a function with the physics plugin native code
549
+ * Provide a function the will have two variables - the world object and the physics body object
550
+ * @param func The function to execute with the physics plugin native code
551
+ */
552
+ executeNativeFunction(func) {
553
+ if (this._physicsEngine) {
554
+ func(this._physicsEngine.getPhysicsPlugin().world, this.physicsBody);
555
+ }
556
+ }
557
+ /**
558
+ * Register a function that will be executed before the physics world is stepping forward
559
+ * @param func The function to execute before the physics world is stepped forward
560
+ */
561
+ registerBeforePhysicsStep(func) {
562
+ this._onBeforePhysicsStepCallbacks.push(func);
563
+ }
564
+ /**
565
+ * Unregister a function that will be executed before the physics world is stepping forward
566
+ * @param func The function to execute before the physics world is stepped forward
567
+ */
568
+ unregisterBeforePhysicsStep(func) {
569
+ const index = this._onBeforePhysicsStepCallbacks.indexOf(func);
570
+ if (index > -1) {
571
+ this._onBeforePhysicsStepCallbacks.splice(index, 1);
572
+ }
573
+ else {
574
+ Logger.Warn("Function to remove was not found");
575
+ }
576
+ }
577
+ /**
578
+ * Register a function that will be executed after the physics step
579
+ * @param func The function to execute after physics step
580
+ */
581
+ registerAfterPhysicsStep(func) {
582
+ this._onAfterPhysicsStepCallbacks.push(func);
583
+ }
584
+ /**
585
+ * Unregisters a function that will be executed after the physics step
586
+ * @param func The function to execute after physics step
587
+ */
588
+ unregisterAfterPhysicsStep(func) {
589
+ const index = this._onAfterPhysicsStepCallbacks.indexOf(func);
590
+ if (index > -1) {
591
+ this._onAfterPhysicsStepCallbacks.splice(index, 1);
592
+ }
593
+ else {
594
+ Logger.Warn("Function to remove was not found");
595
+ }
596
+ }
597
+ /**
598
+ * register a function that will be executed when this impostor collides against a different body
599
+ * @param collideAgainst Physics imposter, or array of physics imposters to collide against
600
+ * @param func Callback that is executed on collision
601
+ */
602
+ registerOnPhysicsCollide(collideAgainst, func) {
603
+ const collidedAgainstList = collideAgainst instanceof Array ? collideAgainst : [collideAgainst];
604
+ this._onPhysicsCollideCallbacks.push({ callback: func, otherImpostors: collidedAgainstList });
605
+ }
606
+ /**
607
+ * Unregisters the physics imposter's collision callback
608
+ * @param collideAgainst The physics object to collide against
609
+ * @param func Callback to execute on collision
610
+ */
611
+ unregisterOnPhysicsCollide(collideAgainst, func) {
612
+ const collidedAgainstList = collideAgainst instanceof Array ? collideAgainst : [collideAgainst];
613
+ let index = -1;
614
+ const found = this._onPhysicsCollideCallbacks.some((cbDef, idx) => {
615
+ if (cbDef.callback === func && cbDef.otherImpostors.length === collidedAgainstList.length) {
616
+ // chcek the arrays match
617
+ const sameList = cbDef.otherImpostors.every((impostor) => {
618
+ return collidedAgainstList.indexOf(impostor) > -1;
619
+ });
620
+ if (sameList) {
621
+ index = idx;
622
+ }
623
+ return sameList;
624
+ }
625
+ return false;
626
+ });
627
+ if (found) {
628
+ this._onPhysicsCollideCallbacks.splice(index, 1);
629
+ }
630
+ else {
631
+ Logger.Warn("Function to remove was not found");
632
+ }
633
+ }
634
+ /**
635
+ * Get the parent rotation
636
+ * @returns The parent rotation
637
+ */
638
+ getParentsRotation() {
639
+ let parent = this.object.parent;
640
+ this._tmpQuat.copyFromFloats(0, 0, 0, 1);
641
+ while (parent) {
642
+ if (parent.rotationQuaternion) {
643
+ this._tmpQuat2.copyFrom(parent.rotationQuaternion);
644
+ }
645
+ else {
646
+ Quaternion.RotationYawPitchRollToRef(parent.rotation.y, parent.rotation.x, parent.rotation.z, this._tmpQuat2);
647
+ }
648
+ this._tmpQuat.multiplyToRef(this._tmpQuat2, this._tmpQuat);
649
+ parent = parent.parent;
650
+ }
651
+ return this._tmpQuat;
652
+ }
653
+ /**
654
+ * Apply a force
655
+ * @param force The force to apply
656
+ * @param contactPoint The contact point for the force
657
+ * @returns The physics imposter
658
+ */
659
+ applyForce(force, contactPoint) {
660
+ if (this._physicsEngine) {
661
+ this._physicsEngine.getPhysicsPlugin().applyForce(this, force, contactPoint);
662
+ }
663
+ return this;
664
+ }
665
+ /**
666
+ * Apply an impulse
667
+ * @param force The impulse force
668
+ * @param contactPoint The contact point for the impulse force
669
+ * @returns The physics imposter
670
+ */
671
+ applyImpulse(force, contactPoint) {
672
+ if (this._physicsEngine) {
673
+ this._physicsEngine.getPhysicsPlugin().applyImpulse(this, force, contactPoint);
674
+ }
675
+ return this;
676
+ }
677
+ /**
678
+ * A help function to create a joint
679
+ * @param otherImpostor A physics imposter used to create a joint
680
+ * @param jointType The type of joint
681
+ * @param jointData The data for the joint
682
+ * @returns The physics imposter
683
+ */
684
+ createJoint(otherImpostor, jointType, jointData) {
685
+ const joint = new PhysicsJoint(jointType, jointData);
686
+ this.addJoint(otherImpostor, joint);
687
+ return this;
688
+ }
689
+ /**
690
+ * Add a joint to this impostor with a different impostor
691
+ * @param otherImpostor A physics imposter used to add a joint
692
+ * @param joint The joint to add
693
+ * @returns The physics imposter
694
+ */
695
+ addJoint(otherImpostor, joint) {
696
+ this._joints.push({
697
+ otherImpostor: otherImpostor,
698
+ joint: joint,
699
+ });
700
+ if (this._physicsEngine) {
701
+ this._physicsEngine.addJoint(this, otherImpostor, joint);
702
+ }
703
+ return this;
704
+ }
705
+ /**
706
+ * Add an anchor to a cloth impostor
707
+ * @param otherImpostor rigid impostor to anchor to
708
+ * @param width ratio across width from 0 to 1
709
+ * @param height ratio up height from 0 to 1
710
+ * @param influence the elasticity between cloth impostor and anchor from 0, very stretchy to 1, little stretch
711
+ * @param noCollisionBetweenLinkedBodies when true collisions between cloth impostor and anchor are ignored; default false
712
+ * @returns impostor the soft imposter
713
+ */
714
+ addAnchor(otherImpostor, width, height, influence, noCollisionBetweenLinkedBodies) {
715
+ if (!this._physicsEngine) {
716
+ return this;
717
+ }
718
+ const plugin = this._physicsEngine.getPhysicsPlugin();
719
+ if (!plugin.appendAnchor) {
720
+ return this;
721
+ }
722
+ if (this._physicsEngine) {
723
+ plugin.appendAnchor(this, otherImpostor, width, height, influence, noCollisionBetweenLinkedBodies);
724
+ }
725
+ return this;
726
+ }
727
+ /**
728
+ * Add a hook to a rope impostor
729
+ * @param otherImpostor rigid impostor to anchor to
730
+ * @param length ratio across rope from 0 to 1
731
+ * @param influence the elasticity between rope impostor and anchor from 0, very stretchy to 1, little stretch
732
+ * @param noCollisionBetweenLinkedBodies when true collisions between soft impostor and anchor are ignored; default false
733
+ * @returns impostor the rope imposter
734
+ */
735
+ addHook(otherImpostor, length, influence, noCollisionBetweenLinkedBodies) {
736
+ if (!this._physicsEngine) {
737
+ return this;
738
+ }
739
+ const plugin = this._physicsEngine.getPhysicsPlugin();
740
+ if (!plugin.appendAnchor) {
741
+ return this;
742
+ }
743
+ if (this._physicsEngine) {
744
+ plugin.appendHook(this, otherImpostor, length, influence, noCollisionBetweenLinkedBodies);
745
+ }
746
+ return this;
747
+ }
748
+ /**
749
+ * Will keep this body still, in a sleep mode.
750
+ * @returns the physics imposter
751
+ */
752
+ sleep() {
753
+ if (this._physicsEngine) {
754
+ this._physicsEngine.getPhysicsPlugin().sleepBody(this);
755
+ }
756
+ return this;
757
+ }
758
+ /**
759
+ * Wake the body up.
760
+ * @returns The physics imposter
761
+ */
762
+ wakeUp() {
763
+ if (this._physicsEngine) {
764
+ this._physicsEngine.getPhysicsPlugin().wakeUpBody(this);
765
+ }
766
+ return this;
767
+ }
768
+ /**
769
+ * Clones the physics imposter
770
+ * @param newObject The physics imposter clones to this physics-enabled object
771
+ * @returns A nullable physics imposter
772
+ */
773
+ clone(newObject) {
774
+ if (!newObject) {
775
+ return null;
776
+ }
777
+ return new PhysicsImpostor(newObject, this.type, this._options, this._scene);
778
+ }
779
+ /**
780
+ * Disposes the physics imposter
781
+ */
782
+ dispose( /*disposeChildren: boolean = true*/) {
783
+ //no dispose if no physics engine is available.
784
+ if (!this._physicsEngine) {
785
+ return;
786
+ }
787
+ this._joints.forEach((j) => {
788
+ if (this._physicsEngine) {
789
+ this._physicsEngine.removeJoint(this, j.otherImpostor, j.joint);
790
+ }
791
+ });
792
+ //dispose the physics body
793
+ this._physicsEngine.removeImpostor(this);
794
+ if (this.parent) {
795
+ this.parent.forceUpdate();
796
+ }
797
+ else {
798
+ /*this._object.getChildMeshes().forEach(function(mesh) {
799
+ if (mesh.physicsImpostor) {
800
+ if (disposeChildren) {
801
+ mesh.physicsImpostor.dispose();
802
+ mesh.physicsImpostor = null;
803
+ }
804
+ }
805
+ })*/
806
+ }
807
+ this._isDisposed = true;
808
+ }
809
+ /**
810
+ * Sets the delta position
811
+ * @param position The delta position amount
812
+ */
813
+ setDeltaPosition(position) {
814
+ this._deltaPosition.copyFrom(position);
815
+ }
816
+ /**
817
+ * Sets the delta rotation
818
+ * @param rotation The delta rotation amount
819
+ */
820
+ setDeltaRotation(rotation) {
821
+ if (!this._deltaRotation) {
822
+ this._deltaRotation = new Quaternion();
823
+ }
824
+ this._deltaRotation.copyFrom(rotation);
825
+ this._deltaRotationConjugated = this._deltaRotation.conjugate();
826
+ }
827
+ /**
828
+ * Gets the box size of the physics imposter and stores the result in the input parameter
829
+ * @param result Stores the box size
830
+ * @returns The physics imposter
831
+ */
832
+ getBoxSizeToRef(result) {
833
+ if (this._physicsEngine) {
834
+ this._physicsEngine.getPhysicsPlugin().getBoxSizeToRef(this, result);
835
+ }
836
+ return this;
837
+ }
838
+ /**
839
+ * Gets the radius of the physics imposter
840
+ * @returns Radius of the physics imposter
841
+ */
842
+ getRadius() {
843
+ return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getRadius(this) : 0;
844
+ }
845
+ /**
846
+ * Sync a bone with this impostor
847
+ * @param bone The bone to sync to the impostor.
848
+ * @param boneMesh The mesh that the bone is influencing.
849
+ * @param jointPivot The pivot of the joint / bone in local space.
850
+ * @param distToJoint Optional distance from the impostor to the joint.
851
+ * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.
852
+ */
853
+ syncBoneWithImpostor(bone, boneMesh, jointPivot, distToJoint, adjustRotation) {
854
+ const tempVec = PhysicsImpostor._TmpVecs[0];
855
+ const mesh = this.object;
856
+ if (mesh.rotationQuaternion) {
857
+ if (adjustRotation) {
858
+ const tempQuat = PhysicsImpostor._TmpQuat;
859
+ mesh.rotationQuaternion.multiplyToRef(adjustRotation, tempQuat);
860
+ bone.setRotationQuaternion(tempQuat, Space.WORLD, boneMesh);
861
+ }
862
+ else {
863
+ bone.setRotationQuaternion(mesh.rotationQuaternion, Space.WORLD, boneMesh);
864
+ }
865
+ }
866
+ tempVec.x = 0;
867
+ tempVec.y = 0;
868
+ tempVec.z = 0;
869
+ if (jointPivot) {
870
+ tempVec.x = jointPivot.x;
871
+ tempVec.y = jointPivot.y;
872
+ tempVec.z = jointPivot.z;
873
+ bone.getDirectionToRef(tempVec, boneMesh, tempVec);
874
+ if (distToJoint === undefined || distToJoint === null) {
875
+ distToJoint = jointPivot.length();
876
+ }
877
+ tempVec.x *= distToJoint;
878
+ tempVec.y *= distToJoint;
879
+ tempVec.z *= distToJoint;
880
+ }
881
+ if (bone.getParent()) {
882
+ tempVec.addInPlace(mesh.getAbsolutePosition());
883
+ bone.setAbsolutePosition(tempVec, boneMesh);
884
+ }
885
+ else {
886
+ boneMesh.setAbsolutePosition(mesh.getAbsolutePosition());
887
+ boneMesh.position.x -= tempVec.x;
888
+ boneMesh.position.y -= tempVec.y;
889
+ boneMesh.position.z -= tempVec.z;
890
+ }
891
+ }
892
+ /**
893
+ * Sync impostor to a bone
894
+ * @param bone The bone that the impostor will be synced to.
895
+ * @param boneMesh The mesh that the bone is influencing.
896
+ * @param jointPivot The pivot of the joint / bone in local space.
897
+ * @param distToJoint Optional distance from the impostor to the joint.
898
+ * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.
899
+ * @param boneAxis Optional vector3 axis the bone is aligned with
900
+ */
901
+ syncImpostorWithBone(bone, boneMesh, jointPivot, distToJoint, adjustRotation, boneAxis) {
902
+ const mesh = this.object;
903
+ if (mesh.rotationQuaternion) {
904
+ if (adjustRotation) {
905
+ const tempQuat = PhysicsImpostor._TmpQuat;
906
+ bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, tempQuat);
907
+ tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);
908
+ }
909
+ else {
910
+ bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, mesh.rotationQuaternion);
911
+ }
912
+ }
913
+ const pos = PhysicsImpostor._TmpVecs[0];
914
+ const boneDir = PhysicsImpostor._TmpVecs[1];
915
+ if (!boneAxis) {
916
+ boneAxis = PhysicsImpostor._TmpVecs[2];
917
+ boneAxis.x = 0;
918
+ boneAxis.y = 1;
919
+ boneAxis.z = 0;
920
+ }
921
+ bone.getDirectionToRef(boneAxis, boneMesh, boneDir);
922
+ bone.getAbsolutePositionToRef(boneMesh, pos);
923
+ if ((distToJoint === undefined || distToJoint === null) && jointPivot) {
924
+ distToJoint = jointPivot.length();
925
+ }
926
+ if (distToJoint !== undefined && distToJoint !== null) {
927
+ pos.x += boneDir.x * distToJoint;
928
+ pos.y += boneDir.y * distToJoint;
929
+ pos.z += boneDir.z * distToJoint;
930
+ }
931
+ mesh.setAbsolutePosition(pos);
932
+ }
933
+ }
934
+ /**
935
+ * The default object size of the imposter
936
+ */
937
+ PhysicsImpostor.DEFAULT_OBJECT_SIZE = new Vector3(1, 1, 1);
938
+ /**
939
+ * The identity quaternion of the imposter
940
+ */
941
+ PhysicsImpostor.IDENTITY_QUATERNION = Quaternion.Identity();
942
+ PhysicsImpostor._TmpVecs = ArrayTools.BuildArray(3, Vector3.Zero);
943
+ PhysicsImpostor._TmpQuat = Quaternion.Identity();
944
+ //Impostor types
945
+ /**
946
+ * No-Imposter type
947
+ */
948
+ PhysicsImpostor.NoImpostor = 0;
949
+ /**
950
+ * Sphere-Imposter type
951
+ */
952
+ PhysicsImpostor.SphereImpostor = 1;
953
+ /**
954
+ * Box-Imposter type
955
+ */
956
+ PhysicsImpostor.BoxImpostor = 2;
957
+ /**
958
+ * Plane-Imposter type
959
+ */
960
+ PhysicsImpostor.PlaneImpostor = 3;
961
+ /**
962
+ * Mesh-imposter type (Only available to objects with vertices data)
963
+ */
964
+ PhysicsImpostor.MeshImpostor = 4;
965
+ /**
966
+ * Capsule-Impostor type (Ammo.js plugin only)
967
+ */
968
+ PhysicsImpostor.CapsuleImpostor = 6;
969
+ /**
970
+ * Cylinder-Imposter type
971
+ */
972
+ PhysicsImpostor.CylinderImpostor = 7;
973
+ /**
974
+ * Particle-Imposter type
975
+ */
976
+ PhysicsImpostor.ParticleImpostor = 8;
977
+ /**
978
+ * Heightmap-Imposter type
979
+ */
980
+ PhysicsImpostor.HeightmapImpostor = 9;
981
+ /**
982
+ * ConvexHull-Impostor type (Ammo.js plugin only)
983
+ */
984
+ PhysicsImpostor.ConvexHullImpostor = 10;
985
+ /**
986
+ * Custom-Imposter type (Ammo.js plugin only)
987
+ */
988
+ PhysicsImpostor.CustomImpostor = 100;
989
+ /**
990
+ * Rope-Imposter type
991
+ */
992
+ PhysicsImpostor.RopeImpostor = 101;
993
+ /**
994
+ * Cloth-Imposter type
995
+ */
996
+ PhysicsImpostor.ClothImpostor = 102;
997
+ /**
998
+ * Softbody-Imposter type
999
+ */
1000
+ PhysicsImpostor.SoftbodyImpostor = 103;
1001
+ //# sourceMappingURL=physicsImpostor.js.map