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