@woosh/meep-engine 2.120.0 → 2.120.2

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 (148) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/core/binary/FLOAT32_MAX.d.ts +2 -0
  4. package/src/core/binary/FLOAT32_MAX.d.ts.map +1 -0
  5. package/src/core/binary/FLOAT32_MAX.js +1 -0
  6. package/src/core/collection/RingBuffer.d.ts +2 -3
  7. package/src/core/collection/RingBuffer.d.ts.map +1 -1
  8. package/src/core/collection/RingBuffer.js +9 -4
  9. package/src/core/color/Color.d.ts.map +1 -1
  10. package/src/core/color/Color.js +15 -1
  11. package/src/core/geom/2d/circle/Circle.d.ts +7 -5
  12. package/src/core/geom/2d/circle/Circle.d.ts.map +1 -1
  13. package/src/core/geom/2d/circle/Circle.js +7 -5
  14. package/src/core/geom/2d/circle/circle_area.d.ts +7 -0
  15. package/src/core/geom/2d/circle/circle_area.d.ts.map +1 -0
  16. package/src/core/geom/2d/circle/circle_area.js +8 -0
  17. package/src/core/geom/Quaternion.d.ts.map +1 -1
  18. package/src/core/geom/Quaternion.js +57 -23
  19. package/src/core/geom/Vector4.d.ts.map +1 -1
  20. package/src/core/geom/Vector4.js +32 -0
  21. package/src/core/geom/mat2/M2_IDENTITY.d.ts +6 -0
  22. package/src/core/geom/mat2/M2_IDENTITY.d.ts.map +1 -0
  23. package/src/core/geom/mat2/M2_IDENTITY.js +8 -0
  24. package/src/core/geom/mat2/m2_is_diagonal.d.ts +8 -0
  25. package/src/core/geom/mat2/m2_is_diagonal.d.ts.map +1 -0
  26. package/src/core/geom/mat2/m2_is_diagonal.js +9 -0
  27. package/src/core/geom/mat2/m2_is_orthogonal.d.ts +8 -0
  28. package/src/core/geom/mat2/m2_is_orthogonal.d.ts.map +1 -0
  29. package/src/core/geom/mat2/m2_is_orthogonal.js +23 -0
  30. package/src/core/geom/mat2/m2_transpose.d.ts +9 -0
  31. package/src/core/geom/mat2/m2_transpose.d.ts.map +1 -0
  32. package/src/core/geom/mat2/m2_transpose.js +17 -0
  33. package/src/core/graph/graph_compute_adjacency_matrix.d.ts +7 -5
  34. package/src/core/graph/graph_compute_adjacency_matrix.d.ts.map +1 -1
  35. package/src/core/graph/graph_compute_adjacency_matrix.js +11 -5
  36. package/src/core/graph/graph_compute_distance_matrix.d.ts.map +1 -1
  37. package/src/core/graph/graph_compute_distance_matrix.js +30 -56
  38. package/src/core/graph/graph_compute_laplacian_matrix.d.ts +6 -6
  39. package/src/core/graph/graph_compute_laplacian_matrix.js +6 -6
  40. package/src/core/json/abstractJSONDeserializer.d.ts.map +1 -1
  41. package/src/core/json/abstractJSONDeserializer.js +7 -1
  42. package/src/core/math/bell_membership_function.d.ts.map +1 -1
  43. package/src/core/math/bell_membership_function.js +6 -1
  44. package/src/core/math/linalg/m2/m2_polar_decomp.d.ts +19 -0
  45. package/src/core/math/linalg/m2/m2_polar_decomp.d.ts.map +1 -0
  46. package/src/core/math/linalg/m2/m2_polar_decomp.js +27 -0
  47. package/src/core/math/linalg/m2/m2_polar_decomp_noS.d.ts +15 -0
  48. package/src/core/math/linalg/m2/m2_polar_decomp_noS.d.ts.map +1 -0
  49. package/src/core/math/linalg/m2/m2_polar_decomp_noS.js +32 -0
  50. package/src/core/math/linalg/m2/m2_svd.d.ts +19 -0
  51. package/src/core/math/linalg/m2/m2_svd.d.ts.map +1 -0
  52. package/src/core/math/linalg/m2/m2_svd.js +96 -0
  53. package/src/core/math/linalg/solve_linear_system_GEPP_2x2.d.ts +1 -1
  54. package/src/core/math/linalg/solve_linear_system_GEPP_2x2.js +1 -1
  55. package/src/core/model/node-graph/node/NodeDescription.d.ts.map +1 -1
  56. package/src/core/model/node-graph/node/NodeDescription.js +14 -0
  57. package/src/core/model/node-graph/type/DataType.d.ts.map +1 -1
  58. package/src/core/model/node-graph/type/DataType.js +4 -0
  59. package/src/core/process/WatchDog.d.ts +41 -12
  60. package/src/core/process/WatchDog.d.ts.map +1 -1
  61. package/src/core/process/WatchDog.js +47 -16
  62. package/src/engine/development/performance/RingBufferMetric.d.ts +1 -1
  63. package/src/engine/development/performance/RingBufferMetric.d.ts.map +1 -1
  64. package/src/engine/ecs/Entity.js +2 -2
  65. package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
  66. package/src/engine/ecs/EntityComponentDataset.js +31 -13
  67. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  68. package/src/engine/ecs/EntityManager.js +10 -1
  69. package/src/engine/ecs/EntityObserver.d.ts.map +1 -1
  70. package/src/engine/ecs/EntityObserver.js +2 -10
  71. package/src/engine/ecs/EntityReference.d.ts +10 -2
  72. package/src/engine/ecs/EntityReference.d.ts.map +1 -1
  73. package/src/engine/ecs/EntityReference.js +24 -6
  74. package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
  75. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSerializationAdapter.js +3 -3
  76. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSerializationUpgrader_0_1.d.ts +4 -0
  77. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSerializationUpgrader_0_1.d.ts.map +1 -0
  78. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSerializationUpgrader_0_1.js +24 -0
  79. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts.map +1 -1
  80. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +3 -9
  81. package/src/engine/ecs/terrain/overlay/TerrainOverlay.d.ts.map +1 -1
  82. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +14 -8
  83. package/src/engine/ecs/transform/Transform.d.ts +5 -1
  84. package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
  85. package/src/engine/ecs/transform/Transform.js +5 -1
  86. package/src/engine/graphics/texture/sampler/Sampler2D.d.ts +349 -50
  87. package/src/engine/intelligence/behavior/ecs/DieBehavior.d.ts +3 -0
  88. package/src/engine/intelligence/behavior/ecs/DieBehavior.d.ts.map +1 -1
  89. package/src/engine/intelligence/behavior/ecs/DieBehavior.js +4 -0
  90. package/src/engine/intelligence/behavior/ecs/KillBehavior.d.ts +17 -0
  91. package/src/engine/intelligence/behavior/ecs/KillBehavior.d.ts.map +1 -0
  92. package/src/engine/intelligence/behavior/ecs/KillBehavior.js +47 -0
  93. package/src/engine/intelligence/blackboard/BlackboardStack.d.ts +1 -1
  94. package/src/engine/intelligence/blackboard/BlackboardStack.js +1 -1
  95. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationAdapter.d.ts.map +1 -1
  96. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationAdapter.js +3 -1
  97. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_2_3.d.ts.map +1 -1
  98. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_2_3.js +3 -7
  99. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_3_4.d.ts +5 -0
  100. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_3_4.d.ts.map +1 -0
  101. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_3_4.js +19 -0
  102. package/src/engine/physics/mls-mpm/MLS_MPM.d.ts +1 -1
  103. package/src/engine/physics/mls-mpm/MLS_MPM.d.ts.map +1 -1
  104. package/src/engine/physics/mls-mpm/MLS_MPM.js +9 -114
  105. package/src/engine/physics/mls-mpm/README.md +5 -0
  106. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts +7 -6
  107. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts.map +1 -1
  108. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +51 -43
  109. package/editor/actions/concrete/ModifyPatchSampler2DAction.d.ts +0 -48
  110. package/editor/actions/concrete/ModifyPatchTextureArray2DAction.d.ts.map +0 -1
  111. package/editor/actions/concrete/PaintTerrainOverlayAction.d.ts.map +0 -1
  112. package/editor/actions/concrete/PatchTerrainHeightAction.d.ts.map +0 -1
  113. package/editor/actions/concrete/SelectionAddAction.d.ts.map +0 -1
  114. package/editor/actions/concrete/SelectionClearAction.d.ts.map +0 -1
  115. package/editor/actions/concrete/SelectionRemoveAction.d.ts.map +0 -1
  116. package/editor/actions/concrete/TransformModifyAction.d.ts.map +0 -1
  117. package/editor/actions/concrete/WriteGridValueAction.d.ts.map +0 -1
  118. package/src/engine/ecs/read_entity_reference.d.ts +0 -9
  119. package/src/engine/ecs/read_entity_reference.d.ts.map +0 -1
  120. package/src/engine/ecs/read_entity_reference.js +0 -15
  121. package/src/engine/physics/ammo/Body.js +0 -103
  122. package/src/engine/physics/ammo/PhysicsWorker.d.ts +0 -72
  123. package/src/engine/physics/ammo/PhysicsWorker.d.ts.map +0 -1
  124. package/src/engine/physics/ammo/PhysicsWorker.js +0 -437
  125. package/src/engine/physics/ammo/World.d.ts +0 -68
  126. package/src/engine/physics/ammo/World.d.ts.map +0 -1
  127. package/src/engine/physics/ammo/World.js +0 -336
  128. package/src/engine/physics/ammo/shapes/BoxShape.d.ts +0 -10
  129. package/src/engine/physics/ammo/shapes/BoxShape.d.ts.map +0 -1
  130. package/src/engine/physics/ammo/shapes/BoxShape.js +0 -11
  131. package/src/engine/physics/ammo/shapes/CapsuleShape.d.ts +0 -9
  132. package/src/engine/physics/ammo/shapes/CapsuleShape.d.ts.map +0 -1
  133. package/src/engine/physics/ammo/shapes/CapsuleShape.js +0 -10
  134. package/src/engine/physics/ammo/shapes/MeshShape.d.ts +0 -8
  135. package/src/engine/physics/ammo/shapes/MeshShape.d.ts.map +0 -1
  136. package/src/engine/physics/ammo/shapes/MeshShape.js +0 -9
  137. package/src/engine/physics/ammo/shapes/PlaneShape.d.ts +0 -11
  138. package/src/engine/physics/ammo/shapes/PlaneShape.d.ts.map +0 -1
  139. package/src/engine/physics/ammo/shapes/PlaneShape.js +0 -14
  140. package/src/engine/physics/ammo/shapes/Shape.d.ts +0 -7
  141. package/src/engine/physics/ammo/shapes/Shape.d.ts.map +0 -1
  142. package/src/engine/physics/ammo/shapes/Shape.js +0 -9
  143. package/src/engine/physics/ammo/shapes/SphereShape.d.ts +0 -8
  144. package/src/engine/physics/ammo/shapes/SphereShape.d.ts.map +0 -1
  145. package/src/engine/physics/ammo/shapes/SphereShape.js +0 -9
  146. package/src/engine/physics/cannon/CannonJSPhysicsSystem.d.ts +0 -15
  147. package/src/engine/physics/cannon/CannonJSPhysicsSystem.d.ts.map +0 -1
  148. package/src/engine/physics/cannon/CannonJSPhysicsSystem.js +0 -196
@@ -1,103 +0,0 @@
1
- import Quaternion from '../../../core/geom/Quaternion.js';
2
- import Vector3 from "../../../core/geom/Vector3.js";
3
-
4
- /**
5
- *
6
- * @param {Object} options
7
- * @constructor
8
- */
9
- const Body = function (options) {
10
- if (!options) {
11
- options = {};
12
- }
13
-
14
- this.id = -1;
15
-
16
- this.shape = options.shape || null;
17
- this.position = new Vector3();
18
- this.rotation = new Quaternion();
19
- this.linearVelocity = new Vector3();
20
- if (options.position !== void 0) {
21
- this.position.copy(options.position);
22
- }
23
- if (options.rotation !== void 0) {
24
- this.rotation.copy(options.rotation);
25
- }
26
- if (options.linearVelocity !== void 0) {
27
- this.linearVelocity.copy(options.linearVelocity);
28
- }
29
- this.angularFactor = options.angularFactor || new Vector3(1, 1, 1);
30
- this.mass = options.mass || 0;
31
- this.friction = options.friction || 0;
32
- this.disableGravity = options.disableGravity || false;
33
- this.disableCollisionResponse = options.disableCollisionResponse || false;
34
- //
35
- const self = this;
36
- this.changedAttributes = [];
37
- [
38
- "position",
39
- "rotation",
40
- "linearVelocity"
41
- ].forEach(function (prop) {
42
-
43
- this[prop].onChange.add(function () {
44
- self.changedAttributes.push(prop);
45
- });
46
- }, this);
47
-
48
- //callbacks
49
- this.__callbacksChange = [];
50
- this.__callbacksCollision = [];
51
- //central impulse
52
- this.__centralImpulse = null;
53
- //Collision contacts
54
- this.__contacts = [];
55
- };
56
- Body.prototype.getContacts = function () {
57
- return this.__contacts;
58
- };
59
- Body.prototype.onChange = function (f) {
60
- this.__callbacksChange.push(f);
61
- };
62
- Body.prototype.update = function (newPosition, newRotation, newLinearVelocity) {
63
- let hasChanged = false;
64
- const position = this.position;
65
- if (position.x !== newPosition.x || position.y !== newPosition.y || position.z !== newPosition.z) {
66
- position.set(newPosition.x, newPosition.y, newPosition.z);
67
- hasChanged = true;
68
- }
69
- const rotation = this.rotation;
70
- if (rotation.x !== newRotation.x || rotation.y !== newRotation.y || rotation.z !== newRotation.z || rotation.w !== newRotation.w) {
71
- rotation.set(newRotation.x, newRotation.y, newRotation.z, newRotation.w);
72
- hasChanged = true;
73
- }
74
- const linearVelocity = this.linearVelocity;
75
- if (linearVelocity.x !== newLinearVelocity.x || linearVelocity.y !== newLinearVelocity.y || linearVelocity.z !== newLinearVelocity.z) {
76
- linearVelocity.copy(newLinearVelocity);
77
- }
78
- if (hasChanged) {
79
- //execute callbacks
80
- this.__callbacksChange.forEach(function (callback) {
81
- callback();
82
- });
83
- }
84
- };
85
- Body.prototype.applyCentralImpulse = function (force) {
86
-
87
- if (this.__centralImpulse) {
88
- this.__centralImpulse.add(force);
89
- } else {
90
- //impulse not defined
91
- this.__centralImpulse = new Vector3(force.x, force.y, force.z);
92
- }
93
- };
94
- Body.prototype.onCollision = function (f) {
95
- this.__callbacksCollision.push(f);
96
- };
97
- Body.prototype.collide = function (otherBody) {
98
- this.__callbacksCollision.forEach(function (callback) {
99
- callback(otherBody);
100
- });
101
- };
102
- export default Body;
103
-
@@ -1,72 +0,0 @@
1
- declare function registerCollision(body1: any, body2: any, contactPoint: any): void;
2
- declare function getElementByTowersId(id: any, collection: any): any;
3
- declare function getShapeById(id: any): any;
4
- declare function getBodyById(id: any): any;
5
- declare function btVector3ToJSON(vector: any): {
6
- x: any;
7
- y: any;
8
- z: any;
9
- };
10
- declare function write_btVector3(ptr: any, value: any): void;
11
- declare function write_btVector4(ptr: any, value: any): void;
12
- declare function btQuaternionToJSON(q: any): {
13
- x: any;
14
- y: any;
15
- z: any;
16
- w: any;
17
- };
18
- declare function make_btVector3(json: any): any;
19
- declare function make_btQuaternion(json: any): any;
20
- declare function threeGeometryTobtTriangleMesh(geometry: any): any;
21
- /**
22
- * This will be called every simulation tick, including sub-steps. Collision detection is done inside this function
23
- * @param world
24
- * @param timeStep
25
- */
26
- declare function simulationTickCallback(world: any, timeStep: any): void;
27
- declare function sendCollisions(): void;
28
- declare namespace Module {
29
- let TOTAL_MEMORY: number;
30
- let ALLOW_MEMORY_GROWTH: number;
31
- }
32
- declare namespace btRigidBodyFlags {
33
- let BT_DISABLE_WORLD_GRAVITY: number;
34
- let BT_ENABLE_GYROPSCOPIC_FORCE: number;
35
- }
36
- declare namespace CollisionFlags {
37
- let CF_STATIC_OBJECT: number;
38
- let CF_KINEMATIC_OBJECT: number;
39
- let CF_NO_CONTACT_RESPONSE: number;
40
- let CF_CUSTOM_MATERIAL_CALLBACK: number;
41
- let CF_CHARACTER_OBJECT: number;
42
- let CF_DISABLE_VISUALIZE_OBJECT: number;
43
- let CF_DISABLE_SPU_COLLISION_PROCESSING: number;
44
- }
45
- declare const broadphase: any;
46
- declare const collisionConfiguration: any;
47
- declare const dispatcher: any;
48
- declare const solver: any;
49
- declare const dynamicsWorld: any;
50
- declare const globalGravity: any;
51
- declare const simulationTickCallbackPointer: any;
52
- declare const bodies: any[];
53
- declare const shapes: any[];
54
- declare const transform: any;
55
- /**
56
- * @type {Array<Array>}
57
- */
58
- declare const collisions: Array<any[]>;
59
- declare let simulationStepInProgress: boolean;
60
- declare namespace api {
61
- function addShape(options: any): void;
62
- function addBody(options: any): void;
63
- function removeBody(options: any): void;
64
- function writeBodyAttributes(options: any): void;
65
- function rayTest(options: any): void;
66
- function rayCast(options: any): void;
67
- function simulate(delta: any): void;
68
- function applyCentralImpulse(data: any): void;
69
- }
70
- declare const raytest_from: any;
71
- declare const raytest_to: any;
72
- //# sourceMappingURL=PhysicsWorker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PhysicsWorker.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/ammo/PhysicsWorker.js"],"names":[],"mappings":"AAsDA,oFAoBC;AAED,qEASC;AAED,4CAGC;AAED,2CAGC;AAED;;;;EAOC;AAED,6DAIC;AAED,6DAKC;AAED;;;;;EAQC;AAED,gDAGC;AAED,mDAGC;AAED,mEAeC;AAED;;;;GAIG;AACH,yEAyBC;AA0KD,wCAaC;;;;;;;;;;;;;;;;;;AAxVD,8BAA+C;AAG/C,0CAA0E;AAC1E,8BAA0E;AAG1E,0BAA8D;AAG9D,iCAA+G;AAC/G,iCAAoD;AAIpD,iDAAuF;AAKvF,4BAAkB;AAClB,4BAAkB;AAClB,6BAAyC;AACzC;;GAEG;AACH,0BAFU,KAAK,OAAO,CAEA;AACtB,8CAAqC;;IAyIrC,sCA6BC;IACD,qCAgDC;IACD,wCAMC;IACD,iDAqCC;IAID,qCAgBC;IACD,qCAqBC;IAiBD,oCA2CC;IACD,8CAUC;;AA/GK,gCAA0C;AAC5C,8BAAwC"}
@@ -1,437 +0,0 @@
1
-
2
- let Module = {
3
- TOTAL_MEMORY: 20 * 1024 * 1024,
4
- ALLOW_MEMORY_GROWTH: 1
5
- };
6
- /**
7
- * Bullet enumerations
8
- */
9
- const btRigidBodyFlags = {
10
- BT_DISABLE_WORLD_GRAVITY: 1,
11
- BT_ENABLE_GYROPSCOPIC_FORCE: 2
12
- };
13
- const CollisionFlags = {
14
- CF_STATIC_OBJECT: 1,
15
- CF_KINEMATIC_OBJECT: 2,
16
- CF_NO_CONTACT_RESPONSE: 4,
17
- CF_CUSTOM_MATERIAL_CALLBACK: 8,
18
- CF_CHARACTER_OBJECT: 16,
19
- CF_DISABLE_VISUALIZE_OBJECT: 32,
20
- CF_DISABLE_SPU_COLLISION_PROCESSING: 64
21
- };
22
- importScripts('../../../lib/ammo.src');
23
-
24
- // Bullet-interfacing code
25
- // Build the broadphase
26
- const broadphase = new Ammo.btDbvtBroadphase();
27
-
28
- // Set up the collision configuration and dispatcher
29
- const collisionConfiguration = new Ammo.btDefaultCollisionConfiguration();
30
- const dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration);
31
-
32
- // The actual physics solver
33
- const solver = new Ammo.btSequentialImpulseConstraintSolver();
34
-
35
- // The world.
36
- const dynamicsWorld = new Ammo.btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
37
- const globalGravity = new Ammo.btVector3(0, -10, 0);
38
- dynamicsWorld.setGravity(globalGravity);
39
- //add tick callback
40
- Ammo.Runtime = Runtime || Ammo.Runtime;
41
- const simulationTickCallbackPointer = Ammo.Runtime.addFunction(simulationTickCallback);
42
- dynamicsWorld.setInternalTickCallback(simulationTickCallbackPointer);
43
- //Runtime.removeFunction(pointer);
44
-
45
-
46
- const bodies = [];
47
- const shapes = [];
48
- const transform = new Ammo.btTransform();
49
- /**
50
- * @type {Array<Array>}
51
- */
52
- const collisions = [];
53
- let simulationStepInProgress = false;
54
-
55
- function registerCollision(body1, body2, contactPoint) {
56
-
57
- const id1 = body1.__towers_id;
58
- const id2 = body2.__towers_id;
59
- let collision1 = collisions[id1];
60
- let collision2 = collisions[id2];
61
- if (!collision1) {
62
- collision1 = collisions[id1] = [];
63
- }
64
- if (!collision2) {
65
- collision2 = collisions[id2] = [];
66
- }
67
- let contact = collision1[id2];
68
- if (contact == null) {
69
- collision1[id2] = contactPoint;
70
- }
71
- contact = collision2[id1];
72
- if (contact == null) {
73
- collision2[id1] = contactPoint;
74
- }
75
- }
76
-
77
- function getElementByTowersId(id, collection) {
78
-
79
- for (let i = 0; i < collection.length; i++) {
80
- const element = collection[i];
81
- if (element.__towers_id == id) {
82
- return element;
83
- }
84
- }
85
- return null;
86
- }
87
-
88
- function getShapeById(id) {
89
-
90
- return getElementByTowersId(id, shapes);
91
- }
92
-
93
- function getBodyById(id) {
94
-
95
- return getElementByTowersId(id, bodies);
96
- }
97
-
98
- function btVector3ToJSON(vector) {
99
-
100
- return {
101
- x: vector.x(),
102
- y: vector.y(),
103
- z: vector.z()
104
- };
105
- }
106
-
107
- function write_btVector3(ptr, value) {
108
- ptr.setX(value.x);
109
- ptr.setY(value.y);
110
- ptr.setZ(value.z);
111
- }
112
-
113
- function write_btVector4(ptr, value) {
114
- ptr.setX(value.x);
115
- ptr.setY(value.y);
116
- ptr.setZ(value.z);
117
- ptr.setW(value.w);
118
- }
119
-
120
- function btQuaternionToJSON(q) {
121
-
122
- return {
123
- x: q.x(),
124
- y: q.y(),
125
- z: q.z(),
126
- w: q.w()
127
- };
128
- }
129
-
130
- function make_btVector3(json) {
131
-
132
- return new Ammo.btVector3(json.x, json.y, json.z);
133
- }
134
-
135
- function make_btQuaternion(json) {
136
-
137
- return new Ammo.btQuaternion(json.x, json.y, json.z, json.w);
138
- }
139
-
140
- function threeGeometryTobtTriangleMesh(geometry) {
141
-
142
- const threeFaces = geometry.faces;
143
- const triMesh = new Ammo.btTriangleMesh();
144
- const vertices = geometry.vertices.map(function (v) {
145
- return new Ammo.btVector3(v.x, v.y, v.z);
146
- });
147
-
148
- threeFaces.forEach(function (face) {
149
- const a = vertices[face.a];
150
- const b = vertices[face.b];
151
- const c = vertices[face.c];
152
- triMesh.addTriangle(a, b, c);
153
- });
154
- return triMesh;
155
- }
156
-
157
- /**
158
- * This will be called every simulation tick, including sub-steps. Collision detection is done inside this function
159
- * @param world
160
- * @param timeStep
161
- */
162
- function simulationTickCallback(world, timeStep) {
163
-
164
- //collision information extraction
165
- const numManifolds = dispatcher.getNumManifolds();
166
- for (let i = 0; i < numManifolds; i++) {
167
- const contactManifold = dispatcher.getManifoldByIndexInternal(i);
168
- const body0 = contactManifold.getBody0();
169
- const body1 = contactManifold.getBody1();
170
- const numContacts = contactManifold.getNumContacts();
171
- for (let j = 0; j < numContacts; j++) {
172
- const pt = contactManifold.getContactPoint(j);
173
- //intersection
174
- const ptA = pt.getPositionWorldOnA();
175
- let ptB = pt.getPositionWorldOnB();
176
- // console.log("hit!");
177
- //wrap pointers
178
- const b0 = Ammo.wrapPointer(body0, Ammo.btRigidBody);
179
- const b1 = Ammo.wrapPointer(body1, Ammo.btRigidBody);
180
- registerCollision(b0, b1, btVector3ToJSON(ptA));
181
- // postMessage({method: "collision", a: b0.__towers_id, b: b1.__towers_id});
182
- }
183
- }
184
- //send out collisions
185
-
186
- // console.log("world: "+world+", timeStep: "+timeStep);
187
- }
188
-
189
- const api = {};
190
- api.addShape = function (options) {
191
-
192
- let shape = null;
193
- switch (options.type) {
194
- case "sphere":
195
- shape = new Ammo.btSphereShape(options.radius);
196
- break;
197
- case "mesh":
198
- const triMesh = threeGeometryTobtTriangleMesh(options.mesh);
199
- shape = new Ammo.btBvhTriangleMeshShape(triMesh, true);
200
- break;
201
- case "plane":
202
- shape = new Ammo.btStaticPlaneShape(new Ammo.btVector3(options.x, options.y, options.z), options.w);
203
- break;
204
- case "box":
205
- shape = new Ammo.btBoxShape(new Ammo.btVector3(options.x, options.y, options.z));
206
- break;
207
- case "capsule":
208
- shape = new Ammo.btCapsuleShape(options.raidus, options.height);
209
- break;
210
- default :
211
- //unsupported type
212
- break;
213
- }
214
- if (shape != null) {
215
- shape.__towers_id = options.id;
216
- shapes.push(shape);
217
- // console.log("shape " + options.id + " added", options);
218
- }
219
- };
220
- api.addBody = function (options) {
221
-
222
- //defaults
223
- const position = options.position || { x: 0, y: 0, z: 0 };
224
- const rotation = options.rotation || { x: 0, y: 0, z: 0, w: 1 };
225
- const mass = options.mass || 0;
226
- const shapeId = options.shape;
227
- //prepare shape
228
- const shape = getShapeById(shapeId);
229
- const inertia = new Ammo.btVector3(0, 0, 0);
230
- if (mass != 0) {
231
- //dynamic
232
- shape.calculateLocalInertia(mass, inertia);
233
- }
234
- //prepare transform
235
- const btPosition = make_btVector3(position);
236
- const btQuaternion = new Ammo.btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
237
- const transform = new Ammo.btTransform(btQuaternion, btPosition);
238
- //motion state
239
- const motionState = new Ammo.btDefaultMotionState(transform);
240
- const constructionInfo = new Ammo.btRigidBodyConstructionInfo(mass, motionState, shape, inertia);
241
- //create the body
242
- const body = new Ammo.btRigidBody(constructionInfo);
243
- if (options.friction && options.friction != 0) {
244
- body.setFriction(options.friction);
245
- }
246
- //linear velocity
247
- const linearVelocity = options.linearVelocity;
248
- if (linearVelocity) {
249
- body.setLinearVelocity(make_btVector3(linearVelocity));
250
- }
251
- //angular factor, affecting impulses and forces
252
- const angularFactor = options.angularFactor;
253
- if (angularFactor && (angularFactor.x != 1 || angularFactor.y != 1 || angularFactor.z != 1)) {
254
- body.setAngularFactor(make_btVector3(angularFactor));
255
- }
256
- //custom gravity
257
- const gravity = options.gravity;
258
- if (gravity) {
259
- body.setFlags(btRigidBodyFlags.BT_DISABLE_WORLD_GRAVITY);
260
- }
261
- const disableCollisionResponse = options.disableCollisionResponse;
262
- if (disableCollisionResponse) {
263
- body.setCollisionFlags(body.getCollisionFlags() | CollisionFlags.CF_NO_CONTACT_RESPONSE);
264
- }
265
- dynamicsWorld.addRigidBody(body);
266
- body.__towers_id = options.id;
267
- bodies.push(body);
268
- };
269
- api.removeBody = function (options) {
270
-
271
- const body = getBodyById(options.id);
272
- dynamicsWorld.removeRigidBody(body);
273
- Ammo.destroy(body); //clean up
274
- bodies.splice(bodies.indexOf(body), 1); //remove from array
275
- };
276
- api.writeBodyAttributes = function (options) {
277
-
278
- for (let i = 0; i < options.length; i++) {
279
- const obj = options[i];
280
- const body = getBodyById(obj.id);
281
- const attributes = obj.attributes;
282
- let t, v3, v4;
283
- for (let prop in attributes) {
284
- if (!attributes.hasOwnProperty(prop)) {
285
- continue;
286
- }
287
- const value = attributes[prop];
288
- switch (prop) {
289
- case "linearVelocity":
290
- // body.setLinearVelocity(make_btVector3(value));
291
- v3 = body.getLinearVelocity();
292
- write_btVector3(v3, value);
293
- break;
294
- case "position":
295
- t = body.getWorldTransform();
296
- v3 = t.getOrigin();
297
- write_btVector3(v3, value);
298
- // t.setOrigin(make_btVector3(value));
299
- break;
300
- case "rotation":
301
- t = body.getWorldTransform();
302
- v4 = t.getRotation();
303
- write_btVector4(v4, value);
304
- // t.setRotation(make_btQuaternion(value));
305
- break;
306
- default :
307
- console.warn("unknown body property " + prop);
308
- }
309
- //
310
- }
311
- body.activate(); //wake up the body
312
- }
313
- };
314
-
315
- const raytest_from = new Ammo.btVector3(0, 0, 0),
316
- raytest_to = new Ammo.btVector3(0, 0, 0);
317
- api.rayTest = function (options) {
318
- const from = options.from;
319
- const to = options.to;
320
- write_btVector3(raytest_from, from);
321
- write_btVector3(raytest_to, to);
322
- const cb = new Ammo.ClosestRayResultCallback(raytest_from, raytest_to);
323
- dynamicsWorld.rayTest(raytest_from, raytest_to, cb);
324
- if (cb.hasHit()) {
325
- const hitPointWorld = cb.get_m_hitPointWorld();
326
- let hitNormalWorld = cb.get_m_hitNormalWorld();
327
- // Do some clever stuff here
328
- postMessage({ method: "rayHit", point: btVector3ToJSON(hitPointWorld) });
329
- } else {
330
- postMessage({ method: "rayMiss" });
331
- }
332
- Ammo.destroy(cb);
333
- };
334
- api.rayCast = function (options) {
335
- const from = options.from;
336
- const to = options.to;
337
- write_btVector3(raytest_from, from);
338
- write_btVector3(raytest_to, to);
339
- const cb = new Ammo.btCollisionWorld.AllHitsRayResultCallback(raytest_from, raytest_to);
340
- const points = [];
341
- if (cb.hasHit()) {
342
- const hitPointWorld = cb.get_m_hitPointWorld();
343
- // var hitNormalWorld = cb.get_m_hitNormalWorld();
344
- // Do some clever stuff here
345
- const length = hitPointWorld.size();
346
- for (let i = 0; i < length; i++) {
347
- const at = hitPointWorld.at(i);
348
- points.push(btVector3ToJSON(at));
349
- }
350
- } else {
351
- }
352
-
353
- destroy(cb);
354
- postMessage({ method: "rayCast", points: points });
355
- };
356
-
357
- function sendCollisions() {
358
- const count = collisions.reduce(function (prev, val) {
359
- return prev + val.length;
360
- }, 0);
361
- const i = count * 2;
362
- const data = new Int32Array(i);
363
- collisions.forEach(function (val, id1) {
364
- val.forEach(function (v, id2) {
365
- data[--i] = id1;
366
- data[--i] = id2;
367
- });
368
- });
369
- postMessage({ method: "collisions", pairs: data }, [data.buffer]);
370
- }
371
-
372
- api.simulate = function (delta) {
373
-
374
- const substeps = 2;
375
- //reset collision matrix
376
- collisions = [];
377
- //tell simulation world to perform step
378
- dynamicsWorld.stepSimulation(delta, substeps);
379
- const ids = new Int32Array(bodies.length);
380
- const states = new Float32Array(bodies.length * 10);
381
- bodies.forEach(function (body, index) {
382
- body.getMotionState().getWorldTransform(transform);
383
- const origin = transform.getOrigin();
384
- const rotation = transform.getRotation();
385
- const id = body.__towers_id;
386
- const linearVelocity = body.getLinearVelocity();
387
- ids[index] = id;
388
- const j = (index * 10);
389
- //position
390
- states[j] = origin.x();
391
- states[j + 1] = origin.y();
392
- states[j + 2] = origin.z();
393
- //rotation
394
- states[j + 3] = rotation.x();
395
- states[j + 4] = rotation.y();
396
- states[j + 5] = rotation.z();
397
- states[j + 6] = rotation.w();
398
- //velocity
399
- states[j + 7] = linearVelocity.x();
400
- states[j + 8] = linearVelocity.y();
401
- states[j + 9] = linearVelocity.z();
402
- // the reason for mapping is the fact that JS will use map internally for our contacts array, but when passing
403
- // out - it will end up as a large sparse array, and that would take a lot of memory
404
- // var bodyCollisions = collisions[body.__towers_id];
405
- // if (bodyCollisions) {
406
- // var contacts = info.collisions = [];
407
- // bodyCollisions.forEach(function (val, key) {
408
- // contacts.push({t: key, p: val});
409
- // });
410
- // }
411
- // message.push(info);
412
- });
413
- postMessage({ method: "updateState", ids: ids, states: states }, [ids.buffer, states.buffer]);
414
- sendCollisions();
415
- };
416
- api.applyCentralImpulse = function (data) {
417
-
418
- for (let i = 0; i < data.length; i++) {
419
- const pair = data[i];
420
- const id = pair.id;
421
- const value = pair.value;
422
- const body = getBodyById(id);
423
- body.applyCentralImpulse(make_btVector3(value));
424
- body.activate();
425
- }
426
- };
427
- onmessage = function (event) {
428
- const data = event.data;
429
- const method = api[data.method];
430
- if (method) {
431
- method(data.options);
432
- } else {
433
- console.error(data.method, "is not a supported method");
434
- }
435
- };
436
-
437
- postMessage({ method: "workerReady", options: null });
@@ -1,68 +0,0 @@
1
- export default World;
2
- declare class World {
3
- constructor(readyCallback: any);
4
- worker: Worker;
5
- shapeIdPool: IdPool;
6
- bodyIdPool: IdPool;
7
- /**
8
- *
9
- * @type {Shape[]}
10
- */
11
- shapes: Shape[];
12
- bodies: Body[];
13
- __updateCallbacks: any[];
14
- __raytestCallbacks: any[];
15
- __raycastCallbacks: any[];
16
- __stepDoneCallbacks: any[];
17
- /**
18
- *
19
- * @param {number} id
20
- * @returns {Body}
21
- */
22
- getBodyById(id: number): Body;
23
- /**
24
- *
25
- * @param {Array} update
26
- */
27
- updateBodies(update: any[]): void;
28
- /**
29
- *
30
- * @param {Shape} shape
31
- */
32
- addShape(shape: Shape): void;
33
- /**
34
- *
35
- * @param {Body} body
36
- */
37
- addBody(body: Body): void;
38
- /**
39
- *
40
- * @param {Body} body
41
- */
42
- removeBody(body: Body): void;
43
- sendImpulses(): void;
44
- writeChangedAttributes(): void;
45
- /**
46
- *
47
- * @param {Vector3} from
48
- * @param {Vector3} to
49
- * @param {function<Vector3>} callback
50
- */
51
- rayTest(from: Vector3, to: Vector3, callback: any): void;
52
- /**
53
- *
54
- * @param {Vector3} from
55
- * @param {Vector3} to
56
- * @param {function} callback
57
- */
58
- rayCast(from: Vector3, to: Vector3, callback: Function): void;
59
- /**
60
- *
61
- * @param {number} delta
62
- * @param {function} callback
63
- */
64
- simulate(delta: number, callback: Function): void;
65
- }
66
- import IdPool from '../../../core/IdPool.js';
67
- import Vector3 from "../../../core/geom/Vector3.js";
68
- //# sourceMappingURL=World.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"World.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/ammo/World.js"],"names":[],"mappings":";AAYA;IACI,gCA8FC;IA7FG,eAA8D;IAC9D,oBAA+B;IAC/B,mBAA8B;IAE9B;;;OAGG;IACH,QAFU,KAAK,EAAE,CAED;IAMD,QAFL,IAAI,EAAE,CAEe;IAC/B,yBAA2B;IACF,0BAA4B;IAC5B,0BAA4B;IAC3B,2BAA6B;IA6E3D;;;;OAIG;IACH,gBAHW,MAAM,GACJ,IAAI,CAKhB;IAED;;;OAGG;IACH,kCAoCC;IAED;;;OAGG;IACH,gBAFW,KAAK,QAQf;IAED;;;OAGG;IACH,cAFW,IAAI,QAgCd;IAED;;;OAGG;IACH,iBAFW,IAAI,QAad;IAED,qBAyBC;IAED,+BA8BC;IAED;;;;;OAKG;IACH,cAJW,OAAO,MACP,OAAO,uBAWjB;IAED;;;;;OAKG;IACH,cAJW,OAAO,MACP,OAAO,4BAWjB;IAED;;;;OAIG;IACH,gBAHW,MAAM,4BAYhB;CACJ;mBA3UkB,yBAAyB;oBADxB,+BAA+B"}