Skip to content

Commit bcaeb33

Browse files
committed
fix(reconciler,components): do not set highlight layer as a mesh parent
Setting the highlight layer as a mesh parent breaks the Babylon.js ActionManager lifecycle on the mesh. Use a custom property instead.
1 parent 162a67d commit bcaeb33

File tree

6 files changed

+1751
-1312
lines changed

6 files changed

+1751
-1312
lines changed

package-lock.json

Lines changed: 1454 additions & 1286 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/library/src/_generated/babylon.core.constructors.ts

Lines changed: 57 additions & 21 deletions
Large diffs are not rendered by default.

packages/library/src/_generated/babylon.core.declarations.ts

Lines changed: 231 additions & 1 deletion
Large diffs are not rendered by default.

packages/library/src/components/hosts/MeshHost.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class MeshHost {
7272
if (isInstanceOf(parentInstance, 'HighlightLayer')) {
7373
const { highlightLayer } = child;
7474
if (highlightLayer) {
75+
child.highlightLayerParent = parentInstance as BabylonEntity<HighlightLayer>;
7576
const { color, glowEmissiveOnly } = highlightLayer;
7677
(parentInstance as HighlightLayer).addMesh(child, color, glowEmissiveOnly);
7778
}
@@ -85,14 +86,14 @@ export class MeshHost {
8586
}
8687

8788
static commitUpdate(instance: AugmentedMesh, updatePayload: UpdatePayload): void {
88-
const parent = instance.parent;
89+
const parent = instance.highlightLayerParent as BabylonEntity<HighlightLayer>;
8990
if (parent && isInstanceOf(parent, 'HighlightLayer')) {
9091
const highlightLayer = updatePayload.highlightLayer as MeshProps['highlightLayer'];
9192
if (highlightLayer) {
9293
const { color, glowEmissiveOnly } = highlightLayer;
93-
(parent as unknown as HighlightLayer).addMesh(instance, color, glowEmissiveOnly);
94+
parent.addMesh(instance, color, glowEmissiveOnly);
9495
} else {
95-
(parent as unknown as HighlightLayer).removeMesh(instance);
96+
parent.removeMesh(instance);
9697
}
9798
}
9899
}

packages/library/src/reconciler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function isParentNeeded(child: BabylonEntity) {
2525
if (isInstanceOf(child, 'BaseTexture')) {
2626
return false;
2727
}
28+
if (isInstanceOf(child, 'HighlightLayer')) {
29+
return false;
30+
}
2831
return true;
2932
}
3033

packages/library/src/types/props.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ActionEvent, HighlightLayer, Node, Observable, Scene, StandardMaterial } from '@babylonjs/core';
2-
import type { Either } from './types';
2+
import type { Either, BabylonEntity } from './types';
33
import type { AdvancedDynamicTexture, Grid, Vector2WithInfo } from '@babylonjs/gui';
44
import { ActionManager } from '@babylonjs/core/Actions/actionManager.js';
55

@@ -149,6 +149,7 @@ export type MeshProps = Either<Clonable, Instanceable> &
149149
color: Parameters<HighlightLayer['addMesh']>[1];
150150
glowEmissiveOnly?: Parameters<HighlightLayer['addMesh']>[2];
151151
};
152+
highlightLayerParent?: BabylonEntity<HighlightLayer>;
152153
// add here other mesh props (e.g. "onDrag")
153154
};
154155

0 commit comments

Comments
 (0)