@babylonjs/core 6.6.0 → 6.7.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.
@@ -19,13 +19,6 @@ class MeshAccumulator {
19
19
  constructor(mesh, collectIndices, scene) {
20
20
  this._vertices = []; /// Vertices in body space
21
21
  this._indices = [];
22
- const worldFromRoot = mesh.computeWorldMatrix(true);
23
- const rootScale = new Vector3();
24
- const rootOrientation = new Quaternion();
25
- const rootTranslation = new Vector3();
26
- worldFromRoot.decompose(rootScale, rootOrientation, rootTranslation);
27
- this._bodyFromWorld = Matrix.Compose(Vector3.One(), mesh.rotationQuaternion ? mesh.rotationQuaternion : Quaternion.Identity(), mesh.position);
28
- this._bodyFromWorld = this._bodyFromWorld.invert();
29
22
  this._isRightHanded = scene.useRightHandedSystem;
30
23
  this._collectIndices = collectIndices;
31
24
  }
@@ -44,8 +37,10 @@ class MeshAccumulator {
44
37
  */
45
38
  addMesh(mesh, includeChildren) {
46
39
  const indexOffset = this._vertices.length;
47
- const worldFromShape = mesh.computeWorldMatrix(true);
48
- const shapeFromBody = worldFromShape.multiply(this._bodyFromWorld);
40
+ // Force absoluteScaling to be computed
41
+ mesh.computeWorldMatrix(true);
42
+ const shapeFromBody = TmpVectors.Matrix[0];
43
+ Matrix.ScalingToRef(mesh.absoluteScaling.x, mesh.absoluteScaling.y, mesh.absoluteScaling.z, shapeFromBody);
49
44
  const vertexData = mesh.getVerticesData(VertexBuffer.PositionKind) || [];
50
45
  const numVerts = vertexData.length / 3;
51
46
  for (let v = 0; v < numVerts; v++) {
@@ -422,6 +417,7 @@ export class HavokPlugin {
422
417
  * physical behavior of the body.
423
418
  */
424
419
  syncTransform(body, transformNode) {
420
+ var _a;
425
421
  if (body._pluginDataInstances.length) {
426
422
  // instances
427
423
  const m = transformNode;
@@ -453,23 +449,28 @@ export class HavokPlugin {
453
449
  quat.set(bodyOrientation[0], bodyOrientation[1], bodyOrientation[2], bodyOrientation[3]);
454
450
  const parent = transformNode.parent;
455
451
  // transform position/orientation in parent space
456
- if (parent && parent.absoluteRotationQuaternion) {
457
- TmpVectors.Vector3[2].set(bodyTranslation[0], bodyTranslation[1], bodyTranslation[2]);
458
- parent.absoluteRotationQuaternion.conjugateToRef(TmpVectors.Quaternion[1]);
459
- quat.multiplyInPlace(TmpVectors.Quaternion[1]);
460
- TmpVectors.Vector3[2].subtractToRef(parent.absolutePosition, TmpVectors.Vector3[0]);
461
- const localPosition = TmpVectors.Vector3[1];
462
- TmpVectors.Vector3[0].rotateByQuaternionToRef(TmpVectors.Quaternion[1], localPosition);
463
- transformNode.position.set(localPosition.x, localPosition.y, localPosition.z); // use set so position._isDirty is true
452
+ if (parent && !parent.getWorldMatrix().isIdentity()) {
453
+ parent.computeWorldMatrix(true);
454
+ quat.normalize();
455
+ const finalTransform = TmpVectors.Matrix[0];
456
+ const finalTranslation = TmpVectors.Vector3[0];
457
+ finalTranslation.copyFromFloats(bodyTranslation[0], bodyTranslation[1], bodyTranslation[2]);
458
+ Matrix.ComposeToRef(transformNode.absoluteScaling, quat, finalTranslation, finalTransform);
459
+ const parentInverseTransform = TmpVectors.Matrix[1];
460
+ parent.getWorldMatrix().invertToRef(parentInverseTransform);
461
+ const localTransform = TmpVectors.Matrix[2];
462
+ finalTransform.multiplyToRef(parentInverseTransform, localTransform);
463
+ localTransform.decomposeToTransformNode(transformNode);
464
+ (_a = transformNode.rotationQuaternion) === null || _a === void 0 ? void 0 : _a.normalize();
464
465
  }
465
466
  else {
466
467
  transformNode.position.set(bodyTranslation[0], bodyTranslation[1], bodyTranslation[2]);
467
- }
468
- if (transformNode.rotationQuaternion) {
469
- transformNode.rotationQuaternion.copyFrom(quat);
470
- }
471
- else {
472
- quat.toEulerAnglesToRef(transformNode.rotation);
468
+ if (transformNode.rotationQuaternion) {
469
+ transformNode.rotationQuaternion.copyFrom(quat);
470
+ }
471
+ else {
472
+ quat.toEulerAnglesToRef(transformNode.rotation);
473
+ }
473
474
  }
474
475
  }
475
476
  catch (e) {
@@ -1032,7 +1033,7 @@ export class HavokPlugin {
1032
1033
  */
1033
1034
  _getTransformInfos(node) {
1034
1035
  if (node.parent) {
1035
- node.computeWorldMatrix();
1036
+ node.computeWorldMatrix(true);
1036
1037
  return [this._bVecToV3(node.absolutePosition), this._bQuatToV4(node.absoluteRotationQuaternion)];
1037
1038
  }
1038
1039
  let orientation = TmpVectors.Quaternion[0];