Skip to content

Commit

Permalink
fix(core): updates base coordination matrix from FragmentsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
HoyosJuan committed Jul 17, 2024
1 parent 529e5e1 commit 6fe6a82
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions packages/core/src/fragments/FragmentsManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class FragmentsManager extends Component implements Disposable {
readonly groups = new Map<string, FragmentsGroup>();

baseCoordinationModel = "";
baseCoordinationMatrix = new THREE.Matrix4();

/** {@link Component.enabled} */
enabled = true;
Expand Down Expand Up @@ -209,9 +210,7 @@ export class FragmentsManager extends Component implements Disposable {
* All other models are then transformed to match the base model's coordinate system.
*
* @param models - The models to apply coordinate transformation to.
* If not provided, all groups are used.
*
* @returns {void}
* If not provided, all models are used.
*/
coordinate(models = Array.from(this.groups.values())) {
const isFirstModel = this.baseCoordinationModel.length === 0;
Expand All @@ -221,29 +220,23 @@ export class FragmentsManager extends Component implements Disposable {
return;
}
this.baseCoordinationModel = first.uuid;
this.baseCoordinationMatrix = first.coordinationMatrix.clone();
}

if (!models.length) {
return;
}

const baseModel = this.groups.get(this.baseCoordinationModel);

if (!baseModel) {
console.log("No base model found for coordination!");
return;
}

for (const model of models) {
if (model === baseModel) {
if (model.coordinationMatrix.equals(this.baseCoordinationMatrix)) {
continue;
}
model.position.set(0, 0, 0);
model.rotation.set(0, 0, 0);
model.scale.set(1, 1, 1);
model.updateMatrix();
model.applyMatrix4(model.coordinationMatrix.clone().invert());
model.applyMatrix4(baseModel.coordinationMatrix);
model.applyMatrix4(this.baseCoordinationMatrix);
}
}
}

0 comments on commit 6fe6a82

Please sign in to comment.