@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.
- package/Audio/sound.d.ts +5 -0
- package/Audio/sound.js +7 -0
- package/Audio/sound.js.map +1 -1
- package/Debug/physicsViewer.d.ts +4 -3
- package/Debug/physicsViewer.js +2 -2
- package/Debug/physicsViewer.js.map +1 -1
- package/Engines/Extensions/engine.renderTarget.js +15 -15
- package/Engines/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/Extensions/engine.renderTargetCube.d.ts +1 -1
- package/Engines/Extensions/engine.renderTargetCube.js.map +1 -1
- package/Engines/Extensions/engine.views.d.ts +4 -0
- package/Engines/Extensions/engine.views.js +61 -42
- package/Engines/Extensions/engine.views.js.map +1 -1
- package/Engines/Native/nativeHardwareTexture.d.ts +14 -0
- package/Engines/Native/nativeHardwareTexture.js +24 -0
- package/Engines/Native/nativeHardwareTexture.js.map +1 -0
- package/Engines/Native/nativeInterfaces.d.ts +22 -15
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Native/nativePipelineContext.d.ts +252 -0
- package/Engines/Native/nativePipelineContext.js +502 -0
- package/Engines/Native/nativePipelineContext.js.map +1 -0
- package/Engines/Native/nativeRenderTargetWrapper.d.ts +16 -0
- package/Engines/Native/nativeRenderTargetWrapper.js +33 -0
- package/Engines/Native/nativeRenderTargetWrapper.js.map +1 -0
- package/Engines/WebGPU/Extensions/engine.renderTarget.js +3 -3
- package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.renderTargetCube.js.map +1 -1
- package/Engines/engine.d.ts +1 -0
- package/Engines/engine.js +24 -18
- package/Engines/engine.js.map +1 -1
- package/Engines/nativeEngine.d.ts +18 -17
- package/Engines/nativeEngine.js +100 -598
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/nullEngine.d.ts +1 -1
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/thinEngine.d.ts +1 -1
- package/Engines/thinEngine.js +41 -38
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js.map +1 -1
- package/Gizmos/planeRotationGizmo.js +3 -1
- package/Gizmos/planeRotationGizmo.js.map +1 -1
- package/Inputs/scene.inputManager.js +4 -4
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Loading/Plugins/babylonFileLoader.js +3 -3
- package/Loading/Plugins/babylonFileLoader.js.map +1 -1
- package/Materials/Node/Blocks/Dual/textureBlock.js +1 -1
- package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +19 -1
- package/Materials/Node/nodeMaterial.js +30 -0
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Node/nodeMaterialBuildStateSharedData.d.ts +2 -8
- package/Materials/Node/nodeMaterialBuildStateSharedData.js.map +1 -1
- package/Materials/Textures/baseTexture.d.ts +2 -1
- package/Materials/Textures/baseTexture.js +3 -2
- package/Materials/Textures/baseTexture.js.map +1 -1
- package/Materials/Textures/internalTexture.d.ts +2 -0
- package/Materials/Textures/internalTexture.js +4 -0
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Materials/Textures/mirrorTexture.js +0 -2
- package/Materials/Textures/mirrorTexture.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.d.ts +53 -3
- package/Materials/Textures/renderTargetTexture.js +25 -25
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/Textures/texture.d.ts +2 -0
- package/Materials/Textures/texture.js +35 -7
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/Textures/textureCreationOptions.d.ts +4 -1
- package/Materials/Textures/textureCreationOptions.js.map +1 -1
- package/Materials/material.js +1 -1
- package/Materials/material.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +4 -4
- package/Meshes/abstractMesh.js +4 -4
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/mesh.d.ts +2 -2
- package/Meshes/mesh.js +1 -1
- package/Meshes/mesh.js.map +1 -1
- package/Misc/copyTextureToTexture.d.ts +9 -2
- package/Misc/copyTextureToTexture.js +23 -1
- package/Misc/copyTextureToTexture.js.map +1 -1
- package/Particles/IParticleSystem.d.ts +15 -1
- package/Particles/IParticleSystem.js.map +1 -1
- package/Particles/gpuParticleSystem.d.ts +24 -2
- package/Particles/gpuParticleSystem.js +98 -43
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particleSystem.d.ts +6 -1
- package/Particles/particleSystem.js +7 -2
- package/Particles/particleSystem.js.map +1 -1
- package/Physics/IPhysicsEngine.d.ts +8 -108
- package/Physics/IPhysicsEngine.js.map +1 -1
- package/Physics/Plugins/ammoJSPlugin.d.ts +1 -389
- package/Physics/Plugins/ammoJSPlugin.js +2 -1414
- package/Physics/Plugins/ammoJSPlugin.js.map +1 -1
- package/Physics/Plugins/cannonJSPlugin.d.ts +1 -75
- package/Physics/Plugins/cannonJSPlugin.js +2 -664
- package/Physics/Plugins/cannonJSPlugin.js.map +1 -1
- package/Physics/Plugins/oimoJSPlugin.d.ts +1 -59
- package/Physics/Plugins/oimoJSPlugin.js +2 -432
- package/Physics/Plugins/oimoJSPlugin.js.map +1 -1
- package/Physics/index.d.ts +3 -6
- package/Physics/index.js +3 -6
- package/Physics/index.js.map +1 -1
- package/Physics/physicsEngine.d.ts +1 -135
- package/Physics/physicsEngine.js +2 -221
- package/Physics/physicsEngine.js.map +1 -1
- package/Physics/physicsEngineComponent.d.ts +7 -42
- package/Physics/physicsEngineComponent.js +11 -71
- package/Physics/physicsEngineComponent.js.map +1 -1
- package/Physics/physicsHelper.d.ts +1 -411
- package/Physics/physicsHelper.js +2 -708
- package/Physics/physicsHelper.js.map +1 -1
- package/Physics/physicsImpostor.d.ts +1 -640
- package/Physics/physicsImpostor.js +2 -1004
- package/Physics/physicsImpostor.js.map +1 -1
- package/Physics/physicsJoint.d.ts +1 -275
- package/Physics/physicsJoint.js +2 -222
- package/Physics/physicsJoint.js.map +1 -1
- package/Physics/v1/IPhysicsEnginePlugin.d.ts +73 -0
- package/Physics/v1/IPhysicsEnginePlugin.js +2 -0
- package/Physics/v1/IPhysicsEnginePlugin.js.map +1 -0
- package/Physics/v1/Plugins/ammoJSPlugin.d.ts +401 -0
- package/Physics/v1/Plugins/ammoJSPlugin.js +1431 -0
- package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -0
- package/Physics/v1/Plugins/cannonJSPlugin.d.ts +87 -0
- package/Physics/v1/Plugins/cannonJSPlugin.js +683 -0
- package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -0
- package/Physics/{Plugins → v1/Plugins}/index.d.ts +0 -0
- package/Physics/{Plugins → v1/Plugins}/index.js +0 -0
- package/Physics/v1/Plugins/index.js.map +1 -0
- package/Physics/v1/Plugins/oimoJSPlugin.d.ts +71 -0
- package/Physics/v1/Plugins/oimoJSPlugin.js +450 -0
- package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -0
- package/Physics/v1/index.d.ts +7 -0
- package/Physics/v1/index.js +9 -0
- package/Physics/v1/index.js.map +1 -0
- package/Physics/v1/physicsEngine.d.ts +147 -0
- package/Physics/v1/physicsEngine.js +237 -0
- package/Physics/v1/physicsEngine.js.map +1 -0
- package/Physics/v1/physicsEngineComponent.d.ts +45 -0
- package/Physics/v1/physicsEngineComponent.js +70 -0
- package/Physics/v1/physicsEngineComponent.js.map +1 -0
- package/Physics/v1/physicsHelper.d.ts +411 -0
- package/Physics/v1/physicsHelper.js +709 -0
- package/Physics/v1/physicsHelper.js.map +1 -0
- package/Physics/v1/physicsImpostor.d.ts +636 -0
- package/Physics/v1/physicsImpostor.js +1001 -0
- package/Physics/v1/physicsImpostor.js.map +1 -0
- package/Physics/v1/physicsJoint.d.ts +275 -0
- package/Physics/v1/physicsJoint.js +223 -0
- package/Physics/v1/physicsJoint.js.map +1 -0
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +170 -0
- package/Physics/v2/IPhysicsEnginePlugin.js +47 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -0
- package/Physics/v2/Plugins/index.d.ts +0 -0
- package/Physics/v2/Plugins/index.js +2 -0
- package/Physics/v2/Plugins/index.js.map +1 -0
- package/Physics/v2/index.d.ts +6 -0
- package/Physics/v2/index.js +8 -0
- package/Physics/v2/index.js.map +1 -0
- package/Physics/v2/physicsAggregate.d.ts +114 -0
- package/Physics/v2/physicsAggregate.js +46 -0
- package/Physics/v2/physicsAggregate.js.map +1 -0
- package/Physics/v2/physicsBody.d.ts +109 -0
- package/Physics/v2/physicsBody.js +158 -0
- package/Physics/v2/physicsBody.js.map +1 -0
- package/Physics/v2/physicsConstraint.d.ts +184 -0
- package/Physics/v2/physicsConstraint.js +257 -0
- package/Physics/v2/physicsConstraint.js.map +1 -0
- package/Physics/v2/physicsEngine.d.ts +103 -0
- package/Physics/v2/physicsEngine.js +146 -0
- package/Physics/v2/physicsEngine.js.map +1 -0
- package/Physics/v2/physicsEngineComponent.d.ts +31 -0
- package/Physics/v2/physicsEngineComponent.js +50 -0
- package/Physics/v2/physicsEngineComponent.js.map +1 -0
- package/Physics/v2/physicsMaterial.d.ts +45 -0
- package/Physics/v2/physicsMaterial.js +67 -0
- package/Physics/v2/physicsMaterial.js.map +1 -0
- package/Physics/v2/physicsShape.d.ts +182 -0
- package/Physics/v2/physicsShape.js +229 -0
- package/Physics/v2/physicsShape.js.map +1 -0
- package/PostProcesses/postProcess.d.ts +3 -1
- package/PostProcesses/postProcess.js +4 -1
- package/PostProcesses/postProcess.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderer.d.ts +153 -0
- package/Rendering/fluidRenderer/fluidRenderer.js +410 -0
- package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -0
- package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.d.ts +13 -0
- package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js +31 -0
- package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js.map +1 -0
- package/Rendering/fluidRenderer/fluidRenderingObject.d.ts +81 -0
- package/Rendering/fluidRenderer/fluidRenderingObject.js +180 -0
- package/Rendering/fluidRenderer/fluidRenderingObject.js.map +1 -0
- package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.d.ts +63 -0
- package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js +130 -0
- package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js.map +1 -0
- package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.d.ts +64 -0
- package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js +104 -0
- package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js.map +1 -0
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.d.ts +234 -0
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +690 -0
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -0
- package/Rendering/fluidRenderer/fluidRenderingTextures.d.ts +56 -0
- package/Rendering/fluidRenderer/fluidRenderingTextures.js +261 -0
- package/Rendering/fluidRenderer/fluidRenderingTextures.js.map +1 -0
- package/Rendering/fluidRenderer/index.d.ts +5 -0
- package/Rendering/fluidRenderer/index.js +6 -0
- package/Rendering/fluidRenderer/index.js.map +1 -0
- package/Rendering/index.d.ts +1 -0
- package/Rendering/index.js +2 -0
- package/Rendering/index.js.map +1 -1
- package/Shaders/copyTextureToTexture.fragment.js +4 -1
- package/Shaders/copyTextureToTexture.fragment.js.map +1 -1
- package/Shaders/fluidRenderingBilateralBlur.fragment.d.ts +5 -0
- package/Shaders/fluidRenderingBilateralBlur.fragment.js +9 -0
- package/Shaders/fluidRenderingBilateralBlur.fragment.js.map +1 -0
- package/Shaders/fluidRenderingParticleDepth.fragment.d.ts +5 -0
- package/Shaders/fluidRenderingParticleDepth.fragment.js +17 -0
- package/Shaders/fluidRenderingParticleDepth.fragment.js.map +1 -0
- package/Shaders/fluidRenderingParticleDepth.vertex.d.ts +5 -0
- package/Shaders/fluidRenderingParticleDepth.vertex.js +13 -0
- package/Shaders/fluidRenderingParticleDepth.vertex.js.map +1 -0
- package/Shaders/fluidRenderingParticleDiffuse.fragment.d.ts +5 -0
- package/Shaders/fluidRenderingParticleDiffuse.fragment.js +9 -0
- package/Shaders/fluidRenderingParticleDiffuse.fragment.js.map +1 -0
- package/Shaders/fluidRenderingParticleDiffuse.vertex.d.ts +5 -0
- package/Shaders/fluidRenderingParticleDiffuse.vertex.js +4 -0
- package/Shaders/fluidRenderingParticleDiffuse.vertex.js.map +1 -0
- package/Shaders/fluidRenderingParticleThickness.fragment.d.ts +5 -0
- package/Shaders/fluidRenderingParticleThickness.fragment.js +9 -0
- package/Shaders/fluidRenderingParticleThickness.fragment.js.map +1 -0
- package/Shaders/fluidRenderingParticleThickness.vertex.d.ts +5 -0
- package/Shaders/fluidRenderingParticleThickness.vertex.js +9 -0
- package/Shaders/fluidRenderingParticleThickness.vertex.js.map +1 -0
- package/Shaders/fluidRenderingRender.fragment.d.ts +5 -0
- package/Shaders/fluidRenderingRender.fragment.js +46 -0
- package/Shaders/fluidRenderingRender.fragment.js.map +1 -0
- package/Shaders/fluidRenderingStandardBlur.fragment.d.ts +5 -0
- package/Shaders/fluidRenderingStandardBlur.fragment.js +9 -0
- package/Shaders/fluidRenderingStandardBlur.fragment.js.map +1 -0
- package/XR/features/WebXRControllerPhysics.d.ts +1 -1
- package/XR/features/WebXRControllerPhysics.js +1 -1
- package/XR/features/WebXRControllerPhysics.js.map +1 -1
- package/XR/features/WebXRHandTracking.js +1 -1
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +6 -1
- package/scene.js.map +1 -1
- package/sceneComponent.d.ts +3 -0
- package/sceneComponent.js +3 -0
- package/sceneComponent.js.map +1 -1
- package/Physics/Plugins/index.js.map +0 -1
|
@@ -1,665 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { VertexBuffer } from "../../Buffers/buffer.js";
|
|
4
|
-
import { PhysicsImpostor } from "../../Physics/physicsImpostor.js";
|
|
5
|
-
import { PhysicsJoint } from "../../Physics/physicsJoint.js";
|
|
6
|
-
import { PhysicsEngine } from "../../Physics/physicsEngine.js";
|
|
7
|
-
import { PhysicsRaycastResult } from "../physicsRaycastResult.js";
|
|
8
|
-
/** @internal */
|
|
9
|
-
export class CannonJSPlugin {
|
|
10
|
-
constructor(_useDeltaForWorldStep = true, iterations = 10, cannonInjection = CANNON) {
|
|
11
|
-
this._useDeltaForWorldStep = _useDeltaForWorldStep;
|
|
12
|
-
this.name = "CannonJSPlugin";
|
|
13
|
-
this._physicsMaterials = new Array();
|
|
14
|
-
this._fixedTimeStep = 1 / 60;
|
|
15
|
-
this._physicsBodiesToRemoveAfterStep = new Array();
|
|
16
|
-
this._firstFrame = true;
|
|
17
|
-
this._tmpQuaternion = new Quaternion();
|
|
18
|
-
this._minus90X = new Quaternion(-0.7071067811865475, 0, 0, 0.7071067811865475);
|
|
19
|
-
this._plus90X = new Quaternion(0.7071067811865475, 0, 0, 0.7071067811865475);
|
|
20
|
-
this._tmpPosition = Vector3.Zero();
|
|
21
|
-
this._tmpDeltaPosition = Vector3.Zero();
|
|
22
|
-
this._tmpUnityRotation = new Quaternion();
|
|
23
|
-
this.BJSCANNON = cannonInjection;
|
|
24
|
-
if (!this.isSupported()) {
|
|
25
|
-
Logger.Error("CannonJS is not available. Please make sure you included the js file.");
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
this._extendNamespace();
|
|
29
|
-
this.world = new this.BJSCANNON.World();
|
|
30
|
-
this.world.broadphase = new this.BJSCANNON.NaiveBroadphase();
|
|
31
|
-
this.world.solver.iterations = iterations;
|
|
32
|
-
this._cannonRaycastResult = new this.BJSCANNON.RaycastResult();
|
|
33
|
-
this._raycastResult = new PhysicsRaycastResult();
|
|
34
|
-
}
|
|
35
|
-
setGravity(gravity) {
|
|
36
|
-
const vec = gravity;
|
|
37
|
-
this.world.gravity.set(vec.x, vec.y, vec.z);
|
|
38
|
-
}
|
|
39
|
-
setTimeStep(timeStep) {
|
|
40
|
-
this._fixedTimeStep = timeStep;
|
|
41
|
-
}
|
|
42
|
-
getTimeStep() {
|
|
43
|
-
return this._fixedTimeStep;
|
|
44
|
-
}
|
|
45
|
-
executeStep(delta, impostors) {
|
|
46
|
-
// due to cannon's architecture, the first frame's before-step is skipped.
|
|
47
|
-
if (this._firstFrame) {
|
|
48
|
-
this._firstFrame = false;
|
|
49
|
-
for (const impostor of impostors) {
|
|
50
|
-
if (!(impostor.type == PhysicsImpostor.HeightmapImpostor || impostor.type === PhysicsImpostor.PlaneImpostor)) {
|
|
51
|
-
impostor.beforeStep();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
this.world.step(this._useDeltaForWorldStep ? delta : this._fixedTimeStep);
|
|
56
|
-
this._removeMarkedPhysicsBodiesFromWorld();
|
|
57
|
-
}
|
|
58
|
-
_removeMarkedPhysicsBodiesFromWorld() {
|
|
59
|
-
if (this._physicsBodiesToRemoveAfterStep.length > 0) {
|
|
60
|
-
this._physicsBodiesToRemoveAfterStep.forEach((physicsBody) => {
|
|
61
|
-
if (typeof this.world.removeBody === "function") {
|
|
62
|
-
this.world.removeBody(physicsBody);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
this.world.remove(physicsBody);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
this._physicsBodiesToRemoveAfterStep.length = 0;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
applyImpulse(impostor, force, contactPoint) {
|
|
72
|
-
const worldPoint = new this.BJSCANNON.Vec3(contactPoint.x, contactPoint.y, contactPoint.z);
|
|
73
|
-
const impulse = new this.BJSCANNON.Vec3(force.x, force.y, force.z);
|
|
74
|
-
impostor.physicsBody.applyImpulse(impulse, worldPoint);
|
|
75
|
-
}
|
|
76
|
-
applyForce(impostor, force, contactPoint) {
|
|
77
|
-
const worldPoint = new this.BJSCANNON.Vec3(contactPoint.x, contactPoint.y, contactPoint.z);
|
|
78
|
-
const impulse = new this.BJSCANNON.Vec3(force.x, force.y, force.z);
|
|
79
|
-
impostor.physicsBody.applyForce(impulse, worldPoint);
|
|
80
|
-
}
|
|
81
|
-
generatePhysicsBody(impostor) {
|
|
82
|
-
// When calling forceUpdate generatePhysicsBody is called again, ensure that the updated body does not instantly collide with removed body
|
|
83
|
-
this._removeMarkedPhysicsBodiesFromWorld();
|
|
84
|
-
//parent-child relationship. Does this impostor have a parent impostor?
|
|
85
|
-
if (impostor.parent) {
|
|
86
|
-
if (impostor.physicsBody) {
|
|
87
|
-
this.removePhysicsBody(impostor);
|
|
88
|
-
//TODO is that needed?
|
|
89
|
-
impostor.forceUpdate();
|
|
90
|
-
}
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
//should a new body be created for this impostor?
|
|
94
|
-
if (impostor.isBodyInitRequired()) {
|
|
95
|
-
const shape = this._createShape(impostor);
|
|
96
|
-
if (!shape) {
|
|
97
|
-
Logger.Warn("It was not possible to create a physics body for this object.");
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
//unregister events if body is being changed
|
|
101
|
-
const oldBody = impostor.physicsBody;
|
|
102
|
-
if (oldBody) {
|
|
103
|
-
this.removePhysicsBody(impostor);
|
|
104
|
-
}
|
|
105
|
-
//create the body and material
|
|
106
|
-
const material = this._addMaterial("mat-" + impostor.uniqueId, impostor.getParam("friction"), impostor.getParam("restitution"));
|
|
107
|
-
const bodyCreationObject = {
|
|
108
|
-
mass: impostor.getParam("mass"),
|
|
109
|
-
material: material,
|
|
110
|
-
};
|
|
111
|
-
// A simple extend, in case native options were used.
|
|
112
|
-
const nativeOptions = impostor.getParam("nativeOptions");
|
|
113
|
-
for (const key in nativeOptions) {
|
|
114
|
-
if (Object.prototype.hasOwnProperty.call(nativeOptions, key)) {
|
|
115
|
-
bodyCreationObject[key] = nativeOptions[key];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
impostor.physicsBody = new this.BJSCANNON.Body(bodyCreationObject);
|
|
119
|
-
impostor.physicsBody.addEventListener("collide", impostor.onCollide);
|
|
120
|
-
this.world.addEventListener("preStep", impostor.beforeStep);
|
|
121
|
-
this.world.addEventListener("postStep", impostor.afterStep);
|
|
122
|
-
impostor.physicsBody.addShape(shape);
|
|
123
|
-
if (typeof this.world.addBody === "function") {
|
|
124
|
-
this.world.addBody(impostor.physicsBody);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
this.world.add(impostor.physicsBody);
|
|
128
|
-
}
|
|
129
|
-
//try to keep the body moving in the right direction by taking old properties.
|
|
130
|
-
//Should be tested!
|
|
131
|
-
if (oldBody) {
|
|
132
|
-
["force", "torque", "velocity", "angularVelocity"].forEach(function (param) {
|
|
133
|
-
const vec = oldBody[param];
|
|
134
|
-
impostor.physicsBody[param].set(vec.x, vec.y, vec.z);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
this._processChildMeshes(impostor);
|
|
138
|
-
}
|
|
139
|
-
//now update the body's transformation
|
|
140
|
-
this._updatePhysicsBodyTransformation(impostor);
|
|
141
|
-
}
|
|
142
|
-
_processChildMeshes(mainImpostor) {
|
|
143
|
-
const meshChildren = mainImpostor.object.getChildMeshes ? mainImpostor.object.getChildMeshes(true) : [];
|
|
144
|
-
const mainRotation = mainImpostor.object.rotationQuaternion;
|
|
145
|
-
if (mainRotation) {
|
|
146
|
-
mainRotation.conjugateToRef(this._tmpQuaternion);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
this._tmpQuaternion.set(0, 0, 0, 1);
|
|
150
|
-
}
|
|
151
|
-
if (meshChildren.length) {
|
|
152
|
-
const processMesh = (mesh) => {
|
|
153
|
-
if (!mesh.rotationQuaternion) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const childImpostor = mesh.getPhysicsImpostor();
|
|
157
|
-
if (childImpostor) {
|
|
158
|
-
const parent = childImpostor.parent;
|
|
159
|
-
if (parent !== mainImpostor && mesh.parent) {
|
|
160
|
-
const pPosition = mesh.getAbsolutePosition().subtract(mesh.parent.getAbsolutePosition());
|
|
161
|
-
const q = mesh.rotationQuaternion.multiply(this._tmpQuaternion);
|
|
162
|
-
if (childImpostor.physicsBody) {
|
|
163
|
-
this.removePhysicsBody(childImpostor);
|
|
164
|
-
childImpostor.physicsBody = null;
|
|
165
|
-
}
|
|
166
|
-
childImpostor.parent = mainImpostor;
|
|
167
|
-
childImpostor.resetUpdateFlags();
|
|
168
|
-
mainImpostor.physicsBody.addShape(this._createShape(childImpostor), new this.BJSCANNON.Vec3(pPosition.x, pPosition.y, pPosition.z), new this.BJSCANNON.Quaternion(q.x, q.y, q.z, q.w));
|
|
169
|
-
//Add the mass of the children.
|
|
170
|
-
mainImpostor.physicsBody.mass += childImpostor.getParam("mass");
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
mesh.getChildMeshes(true)
|
|
174
|
-
.filter((m) => !!m.physicsImpostor)
|
|
175
|
-
.forEach(processMesh);
|
|
176
|
-
};
|
|
177
|
-
meshChildren.filter((m) => !!m.physicsImpostor).forEach(processMesh);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
removePhysicsBody(impostor) {
|
|
181
|
-
impostor.physicsBody.removeEventListener("collide", impostor.onCollide);
|
|
182
|
-
this.world.removeEventListener("preStep", impostor.beforeStep);
|
|
183
|
-
this.world.removeEventListener("postStep", impostor.afterStep);
|
|
184
|
-
// Only remove the physics body after the physics step to avoid disrupting cannon's internal state
|
|
185
|
-
if (this._physicsBodiesToRemoveAfterStep.indexOf(impostor.physicsBody) === -1) {
|
|
186
|
-
this._physicsBodiesToRemoveAfterStep.push(impostor.physicsBody);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
generateJoint(impostorJoint) {
|
|
190
|
-
const mainBody = impostorJoint.mainImpostor.physicsBody;
|
|
191
|
-
const connectedBody = impostorJoint.connectedImpostor.physicsBody;
|
|
192
|
-
if (!mainBody || !connectedBody) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
let constraint;
|
|
196
|
-
const jointData = impostorJoint.joint.jointData;
|
|
197
|
-
//TODO - https://github.com/schteppe/this.BJSCANNON.js/blob/gh-pages/demos/collisionFilter.html
|
|
198
|
-
const constraintData = {
|
|
199
|
-
pivotA: jointData.mainPivot ? new this.BJSCANNON.Vec3().set(jointData.mainPivot.x, jointData.mainPivot.y, jointData.mainPivot.z) : null,
|
|
200
|
-
pivotB: jointData.connectedPivot ? new this.BJSCANNON.Vec3().set(jointData.connectedPivot.x, jointData.connectedPivot.y, jointData.connectedPivot.z) : null,
|
|
201
|
-
axisA: jointData.mainAxis ? new this.BJSCANNON.Vec3().set(jointData.mainAxis.x, jointData.mainAxis.y, jointData.mainAxis.z) : null,
|
|
202
|
-
axisB: jointData.connectedAxis ? new this.BJSCANNON.Vec3().set(jointData.connectedAxis.x, jointData.connectedAxis.y, jointData.connectedAxis.z) : null,
|
|
203
|
-
maxForce: jointData.nativeParams.maxForce,
|
|
204
|
-
collideConnected: !!jointData.collision,
|
|
205
|
-
};
|
|
206
|
-
switch (impostorJoint.joint.type) {
|
|
207
|
-
case PhysicsJoint.HingeJoint:
|
|
208
|
-
case PhysicsJoint.Hinge2Joint:
|
|
209
|
-
constraint = new this.BJSCANNON.HingeConstraint(mainBody, connectedBody, constraintData);
|
|
210
|
-
break;
|
|
211
|
-
case PhysicsJoint.DistanceJoint:
|
|
212
|
-
constraint = new this.BJSCANNON.DistanceConstraint(mainBody, connectedBody, jointData.maxDistance || 2);
|
|
213
|
-
break;
|
|
214
|
-
case PhysicsJoint.SpringJoint: {
|
|
215
|
-
const springData = jointData;
|
|
216
|
-
constraint = new this.BJSCANNON.Spring(mainBody, connectedBody, {
|
|
217
|
-
restLength: springData.length,
|
|
218
|
-
stiffness: springData.stiffness,
|
|
219
|
-
damping: springData.damping,
|
|
220
|
-
localAnchorA: constraintData.pivotA,
|
|
221
|
-
localAnchorB: constraintData.pivotB,
|
|
222
|
-
});
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
case PhysicsJoint.LockJoint:
|
|
226
|
-
constraint = new this.BJSCANNON.LockConstraint(mainBody, connectedBody, constraintData);
|
|
227
|
-
break;
|
|
228
|
-
case PhysicsJoint.PointToPointJoint:
|
|
229
|
-
case PhysicsJoint.BallAndSocketJoint:
|
|
230
|
-
default:
|
|
231
|
-
constraint = new this.BJSCANNON.PointToPointConstraint(mainBody, constraintData.pivotA, connectedBody, constraintData.pivotB, constraintData.maxForce);
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
//set the collideConnected flag after the creation, since DistanceJoint ignores it.
|
|
235
|
-
constraint.collideConnected = !!jointData.collision;
|
|
236
|
-
impostorJoint.joint.physicsJoint = constraint;
|
|
237
|
-
//don't add spring as constraint, as it is not one.
|
|
238
|
-
if (impostorJoint.joint.type !== PhysicsJoint.SpringJoint) {
|
|
239
|
-
this.world.addConstraint(constraint);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
impostorJoint.joint.jointData.forceApplicationCallback =
|
|
243
|
-
impostorJoint.joint.jointData.forceApplicationCallback ||
|
|
244
|
-
function () {
|
|
245
|
-
constraint.applyForce();
|
|
246
|
-
};
|
|
247
|
-
impostorJoint.mainImpostor.registerAfterPhysicsStep(impostorJoint.joint.jointData.forceApplicationCallback);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
removeJoint(impostorJoint) {
|
|
251
|
-
if (impostorJoint.joint.type !== PhysicsJoint.SpringJoint) {
|
|
252
|
-
this.world.removeConstraint(impostorJoint.joint.physicsJoint);
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
impostorJoint.mainImpostor.unregisterAfterPhysicsStep(impostorJoint.joint.jointData.forceApplicationCallback);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
_addMaterial(name, friction, restitution) {
|
|
259
|
-
let index;
|
|
260
|
-
let mat;
|
|
261
|
-
for (index = 0; index < this._physicsMaterials.length; index++) {
|
|
262
|
-
mat = this._physicsMaterials[index];
|
|
263
|
-
if (mat.friction === friction && mat.restitution === restitution) {
|
|
264
|
-
return mat;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const currentMat = new this.BJSCANNON.Material(name);
|
|
268
|
-
currentMat.friction = friction;
|
|
269
|
-
currentMat.restitution = restitution;
|
|
270
|
-
this._physicsMaterials.push(currentMat);
|
|
271
|
-
return currentMat;
|
|
272
|
-
}
|
|
273
|
-
_checkWithEpsilon(value) {
|
|
274
|
-
return value < PhysicsEngine.Epsilon ? PhysicsEngine.Epsilon : value;
|
|
275
|
-
}
|
|
276
|
-
_createShape(impostor) {
|
|
277
|
-
const object = impostor.object;
|
|
278
|
-
let returnValue;
|
|
279
|
-
const impostorExtents = impostor.getObjectExtents();
|
|
280
|
-
switch (impostor.type) {
|
|
281
|
-
case PhysicsImpostor.SphereImpostor: {
|
|
282
|
-
const radiusX = impostorExtents.x;
|
|
283
|
-
const radiusY = impostorExtents.y;
|
|
284
|
-
const radiusZ = impostorExtents.z;
|
|
285
|
-
returnValue = new this.BJSCANNON.Sphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2);
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
//TMP also for cylinder - TODO Cannon supports cylinder natively.
|
|
289
|
-
case PhysicsImpostor.CylinderImpostor: {
|
|
290
|
-
let nativeParams = impostor.getParam("nativeOptions");
|
|
291
|
-
if (!nativeParams) {
|
|
292
|
-
nativeParams = {};
|
|
293
|
-
}
|
|
294
|
-
const radiusTop = nativeParams.radiusTop !== undefined ? nativeParams.radiusTop : this._checkWithEpsilon(impostorExtents.x) / 2;
|
|
295
|
-
const radiusBottom = nativeParams.radiusBottom !== undefined ? nativeParams.radiusBottom : this._checkWithEpsilon(impostorExtents.x) / 2;
|
|
296
|
-
const height = nativeParams.height !== undefined ? nativeParams.height : this._checkWithEpsilon(impostorExtents.y);
|
|
297
|
-
const numSegments = nativeParams.numSegments !== undefined ? nativeParams.numSegments : 16;
|
|
298
|
-
returnValue = new this.BJSCANNON.Cylinder(radiusTop, radiusBottom, height, numSegments);
|
|
299
|
-
// Rotate 90 degrees as this shape is horizontal in cannon
|
|
300
|
-
const quat = new this.BJSCANNON.Quaternion();
|
|
301
|
-
quat.setFromAxisAngle(new this.BJSCANNON.Vec3(1, 0, 0), -Math.PI / 2);
|
|
302
|
-
const translation = new this.BJSCANNON.Vec3(0, 0, 0);
|
|
303
|
-
returnValue.transformAllPoints(translation, quat);
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
case PhysicsImpostor.BoxImpostor: {
|
|
307
|
-
const box = impostorExtents.scale(0.5);
|
|
308
|
-
returnValue = new this.BJSCANNON.Box(new this.BJSCANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
case PhysicsImpostor.PlaneImpostor:
|
|
312
|
-
Logger.Warn("Attention, PlaneImposter might not behave as you expect. Consider using BoxImposter instead");
|
|
313
|
-
returnValue = new this.BJSCANNON.Plane();
|
|
314
|
-
break;
|
|
315
|
-
case PhysicsImpostor.MeshImpostor: {
|
|
316
|
-
// should transform the vertex data to world coordinates!!
|
|
317
|
-
const rawVerts = object.getVerticesData ? object.getVerticesData(VertexBuffer.PositionKind) : [];
|
|
318
|
-
const rawFaces = object.getIndices ? object.getIndices() : [];
|
|
319
|
-
if (!rawVerts) {
|
|
320
|
-
Logger.Warn("Tried to create a MeshImpostor for an object without vertices. This will fail.");
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
// get only scale! so the object could transform correctly.
|
|
324
|
-
const oldPosition = object.position.clone();
|
|
325
|
-
const oldRotation = object.rotation && object.rotation.clone();
|
|
326
|
-
const oldQuaternion = object.rotationQuaternion && object.rotationQuaternion.clone();
|
|
327
|
-
object.position.copyFromFloats(0, 0, 0);
|
|
328
|
-
object.rotation && object.rotation.copyFromFloats(0, 0, 0);
|
|
329
|
-
object.rotationQuaternion && object.rotationQuaternion.copyFrom(impostor.getParentsRotation());
|
|
330
|
-
object.rotationQuaternion && object.parent && object.rotationQuaternion.conjugateInPlace();
|
|
331
|
-
const transform = object.computeWorldMatrix(true);
|
|
332
|
-
// convert rawVerts to object space
|
|
333
|
-
const transformedVertices = new Array();
|
|
334
|
-
let index;
|
|
335
|
-
for (index = 0; index < rawVerts.length; index += 3) {
|
|
336
|
-
Vector3.TransformCoordinates(Vector3.FromArray(rawVerts, index), transform).toArray(transformedVertices, index);
|
|
337
|
-
}
|
|
338
|
-
Logger.Warn("MeshImpostor only collides against spheres.");
|
|
339
|
-
returnValue = new this.BJSCANNON.Trimesh(transformedVertices, rawFaces);
|
|
340
|
-
//now set back the transformation!
|
|
341
|
-
object.position.copyFrom(oldPosition);
|
|
342
|
-
oldRotation && object.rotation && object.rotation.copyFrom(oldRotation);
|
|
343
|
-
oldQuaternion && object.rotationQuaternion && object.rotationQuaternion.copyFrom(oldQuaternion);
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
case PhysicsImpostor.HeightmapImpostor: {
|
|
347
|
-
const oldPosition2 = object.position.clone();
|
|
348
|
-
const oldRotation2 = object.rotation && object.rotation.clone();
|
|
349
|
-
const oldQuaternion2 = object.rotationQuaternion && object.rotationQuaternion.clone();
|
|
350
|
-
object.position.copyFromFloats(0, 0, 0);
|
|
351
|
-
object.rotation && object.rotation.copyFromFloats(0, 0, 0);
|
|
352
|
-
object.rotationQuaternion && object.rotationQuaternion.copyFrom(impostor.getParentsRotation());
|
|
353
|
-
object.rotationQuaternion && object.parent && object.rotationQuaternion.conjugateInPlace();
|
|
354
|
-
object.rotationQuaternion && object.rotationQuaternion.multiplyInPlace(this._minus90X);
|
|
355
|
-
returnValue = this._createHeightmap(object);
|
|
356
|
-
object.position.copyFrom(oldPosition2);
|
|
357
|
-
oldRotation2 && object.rotation && object.rotation.copyFrom(oldRotation2);
|
|
358
|
-
oldQuaternion2 && object.rotationQuaternion && object.rotationQuaternion.copyFrom(oldQuaternion2);
|
|
359
|
-
object.computeWorldMatrix(true);
|
|
360
|
-
break;
|
|
361
|
-
}
|
|
362
|
-
case PhysicsImpostor.ParticleImpostor:
|
|
363
|
-
returnValue = new this.BJSCANNON.Particle();
|
|
364
|
-
break;
|
|
365
|
-
case PhysicsImpostor.NoImpostor:
|
|
366
|
-
returnValue = new this.BJSCANNON.Box(new this.BJSCANNON.Vec3(0, 0, 0));
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
return returnValue;
|
|
370
|
-
}
|
|
371
|
-
_createHeightmap(object, pointDepth) {
|
|
372
|
-
let pos = object.getVerticesData(VertexBuffer.PositionKind);
|
|
373
|
-
const transform = object.computeWorldMatrix(true);
|
|
374
|
-
// convert rawVerts to object space
|
|
375
|
-
const transformedVertices = new Array();
|
|
376
|
-
let index;
|
|
377
|
-
for (index = 0; index < pos.length; index += 3) {
|
|
378
|
-
Vector3.TransformCoordinates(Vector3.FromArray(pos, index), transform).toArray(transformedVertices, index);
|
|
379
|
-
}
|
|
380
|
-
pos = transformedVertices;
|
|
381
|
-
const matrix = new Array();
|
|
382
|
-
//For now pointDepth will not be used and will be automatically calculated.
|
|
383
|
-
//Future reference - try and find the best place to add a reference to the pointDepth variable.
|
|
384
|
-
const arraySize = pointDepth || ~~(Math.sqrt(pos.length / 3) - 1);
|
|
385
|
-
const boundingInfo = object.getBoundingInfo();
|
|
386
|
-
const dim = Math.min(boundingInfo.boundingBox.extendSizeWorld.x, boundingInfo.boundingBox.extendSizeWorld.y);
|
|
387
|
-
const minY = boundingInfo.boundingBox.extendSizeWorld.z;
|
|
388
|
-
const elementSize = (dim * 2) / arraySize;
|
|
389
|
-
for (let i = 0; i < pos.length; i = i + 3) {
|
|
390
|
-
const x = Math.round(pos[i + 0] / elementSize + arraySize / 2);
|
|
391
|
-
const z = Math.round((pos[i + 1] / elementSize - arraySize / 2) * -1);
|
|
392
|
-
const y = -pos[i + 2] + minY;
|
|
393
|
-
if (!matrix[x]) {
|
|
394
|
-
matrix[x] = [];
|
|
395
|
-
}
|
|
396
|
-
if (!matrix[x][z]) {
|
|
397
|
-
matrix[x][z] = y;
|
|
398
|
-
}
|
|
399
|
-
matrix[x][z] = Math.max(y, matrix[x][z]);
|
|
400
|
-
}
|
|
401
|
-
for (let x = 0; x <= arraySize; ++x) {
|
|
402
|
-
if (!matrix[x]) {
|
|
403
|
-
let loc = 1;
|
|
404
|
-
while (!matrix[(x + loc) % arraySize]) {
|
|
405
|
-
loc++;
|
|
406
|
-
}
|
|
407
|
-
matrix[x] = matrix[(x + loc) % arraySize].slice();
|
|
408
|
-
//console.log("missing x", x);
|
|
409
|
-
}
|
|
410
|
-
for (let z = 0; z <= arraySize; ++z) {
|
|
411
|
-
if (!matrix[x][z]) {
|
|
412
|
-
let loc = 1;
|
|
413
|
-
let newValue;
|
|
414
|
-
while (newValue === undefined) {
|
|
415
|
-
newValue = matrix[x][(z + loc++) % arraySize];
|
|
416
|
-
}
|
|
417
|
-
matrix[x][z] = newValue;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const shape = new this.BJSCANNON.Heightfield(matrix, {
|
|
422
|
-
elementSize: elementSize,
|
|
423
|
-
});
|
|
424
|
-
//For future reference, needed for body transformation
|
|
425
|
-
shape.minY = minY;
|
|
426
|
-
return shape;
|
|
427
|
-
}
|
|
428
|
-
_updatePhysicsBodyTransformation(impostor) {
|
|
429
|
-
const object = impostor.object;
|
|
430
|
-
//make sure it is updated...
|
|
431
|
-
object.computeWorldMatrix && object.computeWorldMatrix(true);
|
|
432
|
-
if (!object.getBoundingInfo()) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
const center = impostor.getObjectCenter();
|
|
436
|
-
//m.getAbsolutePosition().subtract(m.getBoundingInfo().boundingBox.centerWorld)
|
|
437
|
-
// The delta between the mesh position and the mesh bounding box center
|
|
438
|
-
this._tmpDeltaPosition.copyFrom(object.getAbsolutePivotPoint().subtract(center));
|
|
439
|
-
this._tmpDeltaPosition.divideInPlace(impostor.object.scaling);
|
|
440
|
-
this._tmpPosition.copyFrom(center);
|
|
441
|
-
let quaternion = object.rotationQuaternion;
|
|
442
|
-
if (!quaternion) {
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
//is shape is a plane or a heightmap, it must be rotated 90 degs in the X axis.
|
|
446
|
-
//ideally these would be rotated at time of creation like cylinder but they dont extend ConvexPolyhedron
|
|
447
|
-
if (impostor.type === PhysicsImpostor.PlaneImpostor || impostor.type === PhysicsImpostor.HeightmapImpostor) {
|
|
448
|
-
//-90 DEG in X, precalculated
|
|
449
|
-
quaternion = quaternion.multiply(this._minus90X);
|
|
450
|
-
//Invert! (Precalculated, 90 deg in X)
|
|
451
|
-
//No need to clone. this will never change.
|
|
452
|
-
impostor.setDeltaRotation(this._plus90X);
|
|
453
|
-
}
|
|
454
|
-
//If it is a heightfield, if should be centered.
|
|
455
|
-
if (impostor.type === PhysicsImpostor.HeightmapImpostor) {
|
|
456
|
-
const mesh = object;
|
|
457
|
-
let boundingInfo = mesh.getBoundingInfo();
|
|
458
|
-
//calculate the correct body position:
|
|
459
|
-
const rotationQuaternion = mesh.rotationQuaternion;
|
|
460
|
-
mesh.rotationQuaternion = this._tmpUnityRotation;
|
|
461
|
-
mesh.computeWorldMatrix(true);
|
|
462
|
-
//get original center with no rotation
|
|
463
|
-
const c = center.clone();
|
|
464
|
-
let oldPivot = mesh.getPivotMatrix();
|
|
465
|
-
if (oldPivot) {
|
|
466
|
-
// create a copy the pivot Matrix as it is modified in place
|
|
467
|
-
oldPivot = oldPivot.clone();
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
oldPivot = Matrix.Identity();
|
|
471
|
-
}
|
|
472
|
-
//calculate the new center using a pivot (since this.BJSCANNON.js doesn't center height maps)
|
|
473
|
-
const p = Matrix.Translation(boundingInfo.boundingBox.extendSizeWorld.x, 0, -boundingInfo.boundingBox.extendSizeWorld.z);
|
|
474
|
-
mesh.setPreTransformMatrix(p);
|
|
475
|
-
mesh.computeWorldMatrix(true);
|
|
476
|
-
// force bounding box recomputation
|
|
477
|
-
boundingInfo = mesh.getBoundingInfo();
|
|
478
|
-
//calculate the translation
|
|
479
|
-
const translation = boundingInfo.boundingBox.centerWorld.subtract(center).subtract(mesh.position).negate();
|
|
480
|
-
this._tmpPosition.copyFromFloats(translation.x, translation.y - boundingInfo.boundingBox.extendSizeWorld.y, translation.z);
|
|
481
|
-
//add it inverted to the delta
|
|
482
|
-
this._tmpDeltaPosition.copyFrom(boundingInfo.boundingBox.centerWorld.subtract(c));
|
|
483
|
-
this._tmpDeltaPosition.y += boundingInfo.boundingBox.extendSizeWorld.y;
|
|
484
|
-
//rotation is back
|
|
485
|
-
mesh.rotationQuaternion = rotationQuaternion;
|
|
486
|
-
mesh.setPreTransformMatrix(oldPivot);
|
|
487
|
-
mesh.computeWorldMatrix(true);
|
|
488
|
-
}
|
|
489
|
-
else if (impostor.type === PhysicsImpostor.MeshImpostor) {
|
|
490
|
-
this._tmpDeltaPosition.copyFromFloats(0, 0, 0);
|
|
491
|
-
}
|
|
492
|
-
impostor.setDeltaPosition(this._tmpDeltaPosition);
|
|
493
|
-
//Now update the impostor object
|
|
494
|
-
impostor.physicsBody.position.set(this._tmpPosition.x, this._tmpPosition.y, this._tmpPosition.z);
|
|
495
|
-
impostor.physicsBody.quaternion.set(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
|
|
496
|
-
}
|
|
497
|
-
setTransformationFromPhysicsBody(impostor) {
|
|
498
|
-
impostor.object.position.set(impostor.physicsBody.position.x, impostor.physicsBody.position.y, impostor.physicsBody.position.z);
|
|
499
|
-
if (impostor.object.rotationQuaternion) {
|
|
500
|
-
const q = impostor.physicsBody.quaternion;
|
|
501
|
-
impostor.object.rotationQuaternion.set(q.x, q.y, q.z, q.w);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
setPhysicsBodyTransformation(impostor, newPosition, newRotation) {
|
|
505
|
-
impostor.physicsBody.position.set(newPosition.x, newPosition.y, newPosition.z);
|
|
506
|
-
impostor.physicsBody.quaternion.set(newRotation.x, newRotation.y, newRotation.z, newRotation.w);
|
|
507
|
-
}
|
|
508
|
-
isSupported() {
|
|
509
|
-
return this.BJSCANNON !== undefined;
|
|
510
|
-
}
|
|
511
|
-
setLinearVelocity(impostor, velocity) {
|
|
512
|
-
impostor.physicsBody.velocity.set(velocity.x, velocity.y, velocity.z);
|
|
513
|
-
}
|
|
514
|
-
setAngularVelocity(impostor, velocity) {
|
|
515
|
-
impostor.physicsBody.angularVelocity.set(velocity.x, velocity.y, velocity.z);
|
|
516
|
-
}
|
|
517
|
-
getLinearVelocity(impostor) {
|
|
518
|
-
const v = impostor.physicsBody.velocity;
|
|
519
|
-
if (!v) {
|
|
520
|
-
return null;
|
|
521
|
-
}
|
|
522
|
-
return new Vector3(v.x, v.y, v.z);
|
|
523
|
-
}
|
|
524
|
-
getAngularVelocity(impostor) {
|
|
525
|
-
const v = impostor.physicsBody.angularVelocity;
|
|
526
|
-
if (!v) {
|
|
527
|
-
return null;
|
|
528
|
-
}
|
|
529
|
-
return new Vector3(v.x, v.y, v.z);
|
|
530
|
-
}
|
|
531
|
-
setBodyMass(impostor, mass) {
|
|
532
|
-
impostor.physicsBody.mass = mass;
|
|
533
|
-
impostor.physicsBody.updateMassProperties();
|
|
534
|
-
}
|
|
535
|
-
getBodyMass(impostor) {
|
|
536
|
-
return impostor.physicsBody.mass;
|
|
537
|
-
}
|
|
538
|
-
getBodyFriction(impostor) {
|
|
539
|
-
return impostor.physicsBody.material.friction;
|
|
540
|
-
}
|
|
541
|
-
setBodyFriction(impostor, friction) {
|
|
542
|
-
impostor.physicsBody.material.friction = friction;
|
|
543
|
-
}
|
|
544
|
-
getBodyRestitution(impostor) {
|
|
545
|
-
return impostor.physicsBody.material.restitution;
|
|
546
|
-
}
|
|
547
|
-
setBodyRestitution(impostor, restitution) {
|
|
548
|
-
impostor.physicsBody.material.restitution = restitution;
|
|
549
|
-
}
|
|
550
|
-
sleepBody(impostor) {
|
|
551
|
-
impostor.physicsBody.sleep();
|
|
552
|
-
}
|
|
553
|
-
wakeUpBody(impostor) {
|
|
554
|
-
impostor.physicsBody.wakeUp();
|
|
555
|
-
}
|
|
556
|
-
updateDistanceJoint(joint, maxDistance) {
|
|
557
|
-
joint.physicsJoint.distance = maxDistance;
|
|
558
|
-
}
|
|
559
|
-
setMotor(joint, speed, maxForce, motorIndex) {
|
|
560
|
-
if (!motorIndex) {
|
|
561
|
-
joint.physicsJoint.enableMotor();
|
|
562
|
-
joint.physicsJoint.setMotorSpeed(speed);
|
|
563
|
-
if (maxForce) {
|
|
564
|
-
this.setLimit(joint, maxForce);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
setLimit(joint, minForce, maxForce) {
|
|
569
|
-
joint.physicsJoint.motorEquation.maxForce = maxForce;
|
|
570
|
-
joint.physicsJoint.motorEquation.minForce = minForce === void 0 ? -minForce : minForce;
|
|
571
|
-
}
|
|
572
|
-
syncMeshWithImpostor(mesh, impostor) {
|
|
573
|
-
const body = impostor.physicsBody;
|
|
574
|
-
mesh.position.x = body.position.x;
|
|
575
|
-
mesh.position.y = body.position.y;
|
|
576
|
-
mesh.position.z = body.position.z;
|
|
577
|
-
if (mesh.rotationQuaternion) {
|
|
578
|
-
mesh.rotationQuaternion.x = body.quaternion.x;
|
|
579
|
-
mesh.rotationQuaternion.y = body.quaternion.y;
|
|
580
|
-
mesh.rotationQuaternion.z = body.quaternion.z;
|
|
581
|
-
mesh.rotationQuaternion.w = body.quaternion.w;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
getRadius(impostor) {
|
|
585
|
-
const shape = impostor.physicsBody.shapes[0];
|
|
586
|
-
return shape.boundingSphereRadius;
|
|
587
|
-
}
|
|
588
|
-
getBoxSizeToRef(impostor, result) {
|
|
589
|
-
const shape = impostor.physicsBody.shapes[0];
|
|
590
|
-
result.x = shape.halfExtents.x * 2;
|
|
591
|
-
result.y = shape.halfExtents.y * 2;
|
|
592
|
-
result.z = shape.halfExtents.z * 2;
|
|
593
|
-
}
|
|
594
|
-
dispose() { }
|
|
595
|
-
_extendNamespace() {
|
|
596
|
-
//this will force cannon to execute at least one step when using interpolation
|
|
597
|
-
const step_tmp1 = new this.BJSCANNON.Vec3();
|
|
598
|
-
const engine = this.BJSCANNON;
|
|
599
|
-
this.BJSCANNON.World.prototype.step = function (dt, timeSinceLastCalled, maxSubSteps) {
|
|
600
|
-
maxSubSteps = maxSubSteps || 10;
|
|
601
|
-
timeSinceLastCalled = timeSinceLastCalled || 0;
|
|
602
|
-
if (timeSinceLastCalled === 0) {
|
|
603
|
-
this.internalStep(dt);
|
|
604
|
-
this.time += dt;
|
|
605
|
-
}
|
|
606
|
-
else {
|
|
607
|
-
let internalSteps = Math.floor((this.time + timeSinceLastCalled) / dt) - Math.floor(this.time / dt);
|
|
608
|
-
internalSteps = Math.min(internalSteps, maxSubSteps) || 1;
|
|
609
|
-
const t0 = performance.now();
|
|
610
|
-
for (let i = 0; i !== internalSteps; i++) {
|
|
611
|
-
this.internalStep(dt);
|
|
612
|
-
if (performance.now() - t0 > dt * 1000) {
|
|
613
|
-
break;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
this.time += timeSinceLastCalled;
|
|
617
|
-
const h = this.time % dt;
|
|
618
|
-
const h_div_dt = h / dt;
|
|
619
|
-
const interpvelo = step_tmp1;
|
|
620
|
-
const bodies = this.bodies;
|
|
621
|
-
for (let j = 0; j !== bodies.length; j++) {
|
|
622
|
-
const b = bodies[j];
|
|
623
|
-
if (b.type !== engine.Body.STATIC && b.sleepState !== engine.Body.SLEEPING) {
|
|
624
|
-
b.position.vsub(b.previousPosition, interpvelo);
|
|
625
|
-
interpvelo.scale(h_div_dt, interpvelo);
|
|
626
|
-
b.position.vadd(interpvelo, b.interpolatedPosition);
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
b.interpolatedPosition.set(b.position.x, b.position.y, b.position.z);
|
|
630
|
-
b.interpolatedQuaternion.set(b.quaternion.x, b.quaternion.y, b.quaternion.z, b.quaternion.w);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Does a raycast in the physics world
|
|
638
|
-
* @param from when should the ray start?
|
|
639
|
-
* @param to when should the ray end?
|
|
640
|
-
* @returns PhysicsRaycastResult
|
|
641
|
-
*/
|
|
642
|
-
raycast(from, to) {
|
|
643
|
-
this._cannonRaycastResult.reset();
|
|
644
|
-
this.world.raycastClosest(from, to, {}, this._cannonRaycastResult);
|
|
645
|
-
this._raycastResult.reset(from, to);
|
|
646
|
-
if (this._cannonRaycastResult.hasHit) {
|
|
647
|
-
// TODO: do we also want to get the body it hit?
|
|
648
|
-
this._raycastResult.setHitData({
|
|
649
|
-
x: this._cannonRaycastResult.hitNormalWorld.x,
|
|
650
|
-
y: this._cannonRaycastResult.hitNormalWorld.y,
|
|
651
|
-
z: this._cannonRaycastResult.hitNormalWorld.z,
|
|
652
|
-
}, {
|
|
653
|
-
x: this._cannonRaycastResult.hitPointWorld.x,
|
|
654
|
-
y: this._cannonRaycastResult.hitPointWorld.y,
|
|
655
|
-
z: this._cannonRaycastResult.hitPointWorld.z,
|
|
656
|
-
});
|
|
657
|
-
this._raycastResult.setHitDistance(this._cannonRaycastResult.distance);
|
|
658
|
-
}
|
|
659
|
-
return this._raycastResult;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
PhysicsEngine.DefaultPluginFactory = () => {
|
|
663
|
-
return new CannonJSPlugin();
|
|
664
|
-
};
|
|
1
|
+
// ES 6 Compatibility
|
|
2
|
+
export * from "../v1/Plugins/cannonJSPlugin.js";
|
|
665
3
|
//# sourceMappingURL=cannonJSPlugin.js.map
|