@babylonjs/core 6.11.2 → 6.12.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 (45) hide show
  1. package/Cameras/freeCamera.js +14 -10
  2. package/Cameras/freeCamera.js.map +1 -1
  3. package/Cameras/targetCamera.d.ts +5 -0
  4. package/Cameras/targetCamera.js +47 -12
  5. package/Cameras/targetCamera.js.map +1 -1
  6. package/Debug/skeletonViewer.js +2 -2
  7. package/Debug/skeletonViewer.js.map +1 -1
  8. package/DeviceInput/eventFactory.js +7 -0
  9. package/DeviceInput/eventFactory.js.map +1 -1
  10. package/Engines/Processors/shaderCodeCursor.js +32 -8
  11. package/Engines/Processors/shaderCodeCursor.js.map +1 -1
  12. package/Engines/thinEngine.js +2 -2
  13. package/Engines/thinEngine.js.map +1 -1
  14. package/Inputs/scene.inputManager.js +4 -0
  15. package/Inputs/scene.inputManager.js.map +1 -1
  16. package/Layers/effectLayer.d.ts +4 -0
  17. package/Layers/effectLayer.js +2 -2
  18. package/Layers/effectLayer.js.map +1 -1
  19. package/Layers/glowLayer.d.ts +4 -0
  20. package/Layers/glowLayer.js +2 -1
  21. package/Layers/glowLayer.js.map +1 -1
  22. package/Materials/greasedLinePluginMaterial.js +10 -9
  23. package/Materials/greasedLinePluginMaterial.js.map +1 -1
  24. package/Meshes/mesh.d.ts +4 -0
  25. package/Meshes/mesh.js +10 -0
  26. package/Meshes/mesh.js.map +1 -1
  27. package/Meshes/trailMesh.js +10 -2
  28. package/Meshes/trailMesh.js.map +1 -1
  29. package/Misc/sceneSerializer.js +68 -49
  30. package/Misc/sceneSerializer.js.map +1 -1
  31. package/Particles/gpuParticleSystem.d.ts +8 -1
  32. package/Particles/gpuParticleSystem.js +16 -4
  33. package/Particles/gpuParticleSystem.js.map +1 -1
  34. package/Physics/v2/Plugins/havokPlugin.d.ts +5 -3
  35. package/Physics/v2/Plugins/havokPlugin.js +53 -24
  36. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  37. package/XR/features/WebXRControllerMovement.d.ts +2 -1
  38. package/XR/features/WebXRControllerMovement.js +10 -10
  39. package/XR/features/WebXRControllerMovement.js.map +1 -1
  40. package/XR/webXRCamera.js +5 -0
  41. package/XR/webXRCamera.js.map +1 -1
  42. package/package.json +1 -1
  43. package/scene.d.ts +6 -0
  44. package/scene.js +13 -0
  45. package/scene.js.map +1 -1
@@ -423,7 +423,9 @@ export declare class HavokPlugin implements IPhysicsEnginePluginV2 {
423
423
  * Adds a child shape to the given shape.
424
424
  * @param shape - The parent shape.
425
425
  * @param newChild - The child shape to add.
426
- * @param childTransform - The transform of the child shape relative to the parent shape.
426
+ * @param translation - The relative translation of the child from the parent shape
427
+ * @param rotation - The relative rotation of the child from the parent shape
428
+ * @param scale - The relative scale scale of the child from the parent shaep
427
429
  *
428
430
  */
429
431
  addChild(shape: PhysicsShape, newChild: PhysicsShape, translation?: Vector3, rotation?: Quaternion, scale?: Vector3): void;
@@ -445,14 +447,14 @@ export declare class HavokPlugin implements IPhysicsEnginePluginV2 {
445
447
  /**
446
448
  * Calculates the bounding box of a given physics shape.
447
449
  *
448
- * @param shape - The physics shape to calculate the bounding box for.
450
+ * @param _shape - The physics shape to calculate the bounding box for.
449
451
  * @returns The calculated bounding box.
450
452
  *
451
453
  * This method is useful for physics engines as it allows to calculate the
452
454
  * boundaries of a given shape. Knowing the boundaries of a shape is important
453
455
  * for collision detection and other physics calculations.
454
456
  */
455
- getBoundingBox(shape: PhysicsShape): BoundingBox;
457
+ getBoundingBox(_shape: PhysicsShape): BoundingBox;
456
458
  /**
457
459
  * Gets the geometry of a physics body.
458
460
  *
@@ -4,6 +4,7 @@ import { Logger } from "../../../Misc/logger.js";
4
4
  import { PhysicsMaterialCombineMode } from "../physicsMaterial.js";
5
5
  import { PhysicsShape } from "../physicsShape.js";
6
6
  import { Mesh } from "../../../Meshes/mesh.js";
7
+ import { InstancedMesh } from "../../../Meshes/instancedMesh.js";
7
8
  import { VertexBuffer } from "../../../Buffers/buffer.js";
8
9
  import { ArrayTools } from "../../../Misc/arrayTools.js";
9
10
  import { Observable } from "../../../Misc/observable.js";
@@ -35,17 +36,50 @@ class MeshAccumulator {
35
36
  * have a physics impostor. This is useful for creating a physics engine
36
37
  * that accurately reflects the mesh and its children.
37
38
  */
38
- addMesh(mesh, includeChildren) {
39
- const indexOffset = this._vertices.length;
40
- // Force absoluteScaling to be computed
39
+ addNodeMeshes(mesh, includeChildren) {
40
+ // Force absoluteScaling to be computed; we're going to use that to bake
41
+ // the scale of any parent nodes into this shape, as physics engines
42
+ // usually use rigid transforms, so can't handle arbitrary scale.
41
43
  mesh.computeWorldMatrix(true);
42
- const shapeFromBody = TmpVectors.Matrix[0];
43
- Matrix.ScalingToRef(mesh.absoluteScaling.x, mesh.absoluteScaling.y, mesh.absoluteScaling.z, shapeFromBody);
44
+ const rootScaled = TmpVectors.Matrix[0];
45
+ Matrix.ScalingToRef(mesh.absoluteScaling.x, mesh.absoluteScaling.y, mesh.absoluteScaling.z, rootScaled);
46
+ if (mesh instanceof Mesh) {
47
+ this._addMesh(mesh, rootScaled);
48
+ }
49
+ else if (mesh instanceof InstancedMesh) {
50
+ this._addMesh(mesh.sourceMesh, rootScaled);
51
+ }
52
+ if (includeChildren) {
53
+ const worldToRoot = TmpVectors.Matrix[1];
54
+ mesh.computeWorldMatrix().invertToRef(worldToRoot);
55
+ const worldToRootScaled = TmpVectors.Matrix[2];
56
+ worldToRoot.multiplyToRef(rootScaled, worldToRootScaled);
57
+ const children = mesh.getChildMeshes(false);
58
+ // Ignore any children which have a physics body.
59
+ // Other plugin implementations do not have this check, which appears to be
60
+ // a bug, as otherwise, the mesh will have a duplicate collider
61
+ children
62
+ .filter((m) => !m.physicsBody)
63
+ .forEach((m) => {
64
+ const childToWorld = m.computeWorldMatrix();
65
+ const childToRootScaled = TmpVectors.Matrix[3];
66
+ childToWorld.multiplyToRef(worldToRootScaled, childToRootScaled);
67
+ if (m instanceof Mesh) {
68
+ this._addMesh(m, childToRootScaled);
69
+ }
70
+ else if (m instanceof InstancedMesh) {
71
+ this._addMesh(m.sourceMesh, childToRootScaled);
72
+ }
73
+ });
74
+ }
75
+ }
76
+ _addMesh(mesh, meshToRoot) {
44
77
  const vertexData = mesh.getVerticesData(VertexBuffer.PositionKind) || [];
45
78
  const numVerts = vertexData.length / 3;
79
+ const indexOffset = this._vertices.length;
46
80
  for (let v = 0; v < numVerts; v++) {
47
81
  const pos = new Vector3(vertexData[v * 3 + 0], vertexData[v * 3 + 1], vertexData[v * 3 + 2]);
48
- this._vertices.push(Vector3.TransformCoordinates(pos, shapeFromBody));
82
+ this._vertices.push(Vector3.TransformCoordinates(pos, meshToRoot));
49
83
  }
50
84
  if (this._collectIndices) {
51
85
  const meshIndices = mesh.getIndices();
@@ -65,13 +99,6 @@ class MeshAccumulator {
65
99
  }
66
100
  }
67
101
  }
68
- if (includeChildren) {
69
- const children = mesh.getChildMeshes(false);
70
- // Ignore any children which have a physics body.
71
- // Other plugin implementations do not have this check, which appears to be
72
- // a bug, as otherwise, the mesh will have a duplicate collider
73
- children.filter((m) => !m.physicsBody).forEach((m) => this.addMesh(m, includeChildren));
74
- }
75
102
  }
76
103
  /**
77
104
  * Allocate and populate the vertex positions inside the physics plugin.
@@ -92,10 +119,10 @@ class MeshAccumulator {
92
119
  ret[i * 3 + 1] = this._vertices[i].y;
93
120
  ret[i * 3 + 2] = this._vertices[i].z;
94
121
  }
95
- return ret;
122
+ return { offset: bufferBegin, numObjects: nFloats };
96
123
  }
97
124
  freeBuffer(plugin, arr) {
98
- plugin._free(arr.byteOffset);
125
+ plugin._free(arr.offset);
99
126
  }
100
127
  /**
101
128
  * Allocate and populate the triangle indices inside the physics plugin
@@ -112,7 +139,7 @@ class MeshAccumulator {
112
139
  for (let i = 0; i < this._indices.length; i++) {
113
140
  ret[i] = this._indices[i];
114
141
  }
115
- return ret;
142
+ return { offset: bufferBegin, numObjects: this._indices.length };
116
143
  }
117
144
  }
118
145
  class BodyPluginData {
@@ -950,16 +977,16 @@ export class HavokPlugin {
950
977
  const includeChildMeshes = !!options.includeChildMeshes;
951
978
  const needIndices = type != PhysicsShapeType.CONVEX_HULL;
952
979
  const accum = new MeshAccumulator(mesh, needIndices, mesh === null || mesh === void 0 ? void 0 : mesh.getScene());
953
- accum.addMesh(mesh, includeChildMeshes);
980
+ accum.addNodeMeshes(mesh, includeChildMeshes);
954
981
  const positions = accum.getVertices(this._hknp);
955
- const numVec3s = positions.length / 3;
982
+ const numVec3s = positions.numObjects / 3;
956
983
  if (type == PhysicsShapeType.CONVEX_HULL) {
957
- shape._pluginData = this._hknp.HP_Shape_CreateConvexHull(positions.byteOffset, numVec3s)[1];
984
+ shape._pluginData = this._hknp.HP_Shape_CreateConvexHull(positions.offset, numVec3s)[1];
958
985
  }
959
986
  else {
960
987
  const triangles = accum.getTriangles(this._hknp);
961
- const numTriangles = triangles.length / 3;
962
- shape._pluginData = this._hknp.HP_Shape_CreateMesh(positions.byteOffset, numVec3s, triangles.byteOffset, numTriangles)[1];
988
+ const numTriangles = triangles.numObjects / 3;
989
+ shape._pluginData = this._hknp.HP_Shape_CreateMesh(positions.offset, numVec3s, triangles.offset, numTriangles)[1];
963
990
  accum.freeBuffer(this._hknp, triangles);
964
991
  }
965
992
  accum.freeBuffer(this._hknp, positions);
@@ -1051,7 +1078,9 @@ export class HavokPlugin {
1051
1078
  * Adds a child shape to the given shape.
1052
1079
  * @param shape - The parent shape.
1053
1080
  * @param newChild - The child shape to add.
1054
- * @param childTransform - The transform of the child shape relative to the parent shape.
1081
+ * @param translation - The relative translation of the child from the parent shape
1082
+ * @param rotation - The relative rotation of the child from the parent shape
1083
+ * @param scale - The relative scale scale of the child from the parent shaep
1055
1084
  *
1056
1085
  */
1057
1086
  addChild(shape, newChild, translation, rotation, scale) {
@@ -1084,14 +1113,14 @@ export class HavokPlugin {
1084
1113
  /**
1085
1114
  * Calculates the bounding box of a given physics shape.
1086
1115
  *
1087
- * @param shape - The physics shape to calculate the bounding box for.
1116
+ * @param _shape - The physics shape to calculate the bounding box for.
1088
1117
  * @returns The calculated bounding box.
1089
1118
  *
1090
1119
  * This method is useful for physics engines as it allows to calculate the
1091
1120
  * boundaries of a given shape. Knowing the boundaries of a shape is important
1092
1121
  * for collision detection and other physics calculations.
1093
1122
  */
1094
- getBoundingBox(shape) {
1123
+ getBoundingBox(_shape) {
1095
1124
  return {};
1096
1125
  }
1097
1126
  /**