MeshExploder causes submeshes to rotate

Hello.
I have a parent/child mesh structure. The parent rotates around the Y axis and the submeshes rotates fine with it. If I add an MeshExploder to the mix, the submeshes “inherits” the rotation and starts rotate around their own Y-axes. Sample here: https://playground.babylonjs.com/#Q78ZB6#1
Is this by design or a bug?
All the best,
—bjorn

Pinging @danjpar who created the MeshExploder !

@bjornbacklund
The children rotate because their parent rotates. I’ll dig around to see if there is a way to ignore the inherited animations.

A quick workaround is to create an empty mesh and set that as the parent for the smaller cubes.
https://playground.babylonjs.com/#Q78ZB6#2

1 Like

Thanks but that does not solve the problem. The small cubes should still circle around the center cube while “exploding in/out”.

Sorry

https://playground.babylonjs.com/#Q78ZB6#3
After messing around in the code, I realize the smaller cubes should be following the large cube like the sphere is.

@Deltakosh
Here is the code that is setting the positions of the exploding meshes. I imagine an easy fix would be to have a boolean flag on the explode function to update the origin vectors with the centermesh/parent transformations.

public explode(direction: number = 1.0): void {
    for (var index = 0; index < this._meshes.length; index++) {
        if (this._meshes[index] && this._meshesOrigins[index] && this._toCenterVectors[index]) {
            this._toCenterVectors[index].scaleToRef(direction, this._scaledDirection);
            this._meshesOrigins[index].addToRef(this._scaledDirection, this._newPosition);
            this._meshes[index].setAbsolutePosition(this._newPosition);
        }
    }
    this._centerMesh.setAbsolutePosition(this._centerPosition);
}

Any recommendations for easiest way to update those vectors?

BTW, any plans to make the MeshExploder an Animatable ?
—bjorn
#bjornsplayground

My guts tell me that if we want to support parent hierarchy we should simply call .position instead of setAbsolutePosition

Thoughts?

I’ll keep messing around with the code. Right off the bat, changing to this._meshes[index].position = this._newPosition; allows for the parent transformations, however, only one of the smaller cubes are present (or all of the smaller cubes in one position).

I think the latter. Can you somehow recreates your tests in the PG?

https://brave-gates-959b79.netlify.app/

I’ll rewrite the code as a function in the playground

1 Like

Any progress on this?
Would love to see a fix, here is a sample using the exploder (would be awesome to be able to rotate the cube)… https://youtu.be/tPfEhi6SOIY
#bjornsplayground