Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12101 #13098

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/dev/core/src/Meshes/transformNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,14 @@ export class TransformNode extends Node {
* The node will remain exactly where it is and its position / rotation will be updated accordingly.
* Note that if the mesh has a pivot matrix / point defined it will be applied after the parent was updated.
* In that case the node will not remain in the same space as it is, as the pivot will be applied.
* To avoid this, you can set updatePivot to true and the pivot will be updated to identity
* @see https://doc.babylonjs.com/how_to/parenting
* @param node the node ot set as the parent
* @param preserveScalingSign if true, keep scaling sign of child. Otherwise, scaling sign might change.
* @param updatePivot if true, update the pivot matrix to keep the node in the same space as before
* @returns this TransformNode.
*/
public setParent(node: Nullable<Node>, preserveScalingSign: boolean = false): TransformNode {
public setParent(node: Nullable<Node>, preserveScalingSign: boolean = false, updatePivot = false): TransformNode {
if (!node && !this.parent) {
return this;
}
Expand Down Expand Up @@ -797,6 +799,11 @@ export class TransformNode extends Node {
this.position.copyFrom(position);

this.parent = node;

if (updatePivot) {
this.setPivotMatrix(Matrix.Identity());
}

return this;
}

Expand Down