attach highlight to all entities, not the ultimate owning asset entity

This commit is contained in:
Nick Fisher
2025-07-03 11:51:42 +08:00
parent 23e34e6da4
commit 8e88252337

View File

@@ -76,8 +76,6 @@ class FFIView extends View<Pointer<TView>> {
OverlayManager_setRenderTarget( OverlayManager_setRenderTarget(
overlayManager!, overlayRenderTarget!.getNativeHandle()); overlayManager!, overlayRenderTarget!.getNativeHandle());
await oldRenderTarget!.destroy(); await oldRenderTarget!.destroy();
print("Resized render target to ${width}x${height}");
print(StackTrace.current);
}); });
} }
} }
@@ -280,7 +278,7 @@ class FFIView extends View<Pointer<TView>> {
RenderTarget? overlayRenderTarget; RenderTarget? overlayRenderTarget;
Material? highlightMaterial; Material? highlightMaterial;
final _highlighted = <ThermionAsset, MaterialInstance>{}; final _highlighted = <ThermionEntity, MaterialInstance>{};
/// ///
/// ///
@@ -293,8 +291,6 @@ class FFIView extends View<Pointer<TView>> {
int? entity, int? entity,
double scale = 1.05, double scale = 1.05,
int primitiveIndex = 0}) async { int primitiveIndex = 0}) async {
entity ??= asset.entity;
if (overlayScene == null) { if (overlayScene == null) {
overlayScene = await FilamentApp.instance!.createScene(); overlayScene = await FilamentApp.instance!.createScene();
final vp = await getViewport(); final vp = await getViewport();
@@ -309,19 +305,36 @@ class FFIView extends View<Pointer<TView>> {
RenderTicker_setOverlayManager(app.renderTicker, overlayManager!); RenderTicker_setOverlayManager(app.renderTicker, overlayManager!);
final highlightMaterialPtr = await withPointerCallback<TMaterial>( final highlightMaterialPtr = await withPointerCallback<TMaterial>(
(cb) => Material_createOutlineMaterialRenderThread(app.engine, cb)); (cb) => Material_createOutlineMaterialRenderThread(app.engine, cb));
highlightMaterial = FFIMaterial(highlightMaterialPtr, app); highlightMaterial =
FFIMaterial(highlightMaterialPtr, app);
} }
var highlightMaterialInstance = await highlightMaterial!.createInstance(); MaterialInstance? highlightMaterialInstance;
await highlightMaterialInstance.setParameterFloat("scale", scale);
await highlightMaterialInstance.setDepthCullingEnabled(true); entity ??= asset.entity;
await highlightMaterialInstance.setDepthWriteEnabled(true); final entities = [entity, ...await asset.getChildEntities()];
OverlayManager_addComponent( for (final entity in entities) {
overlayManager!, entity, highlightMaterialInstance.getNativeHandle()); if (!await FilamentApp.instance!.isRenderable(entity)) {
continue;
}
if (_highlighted.containsKey(entity)) {
_highlighted[entity]!.setParameterFloat4("color", r, g, b, 1.0);
} else {
if (highlightMaterialInstance == null) {
highlightMaterialInstance = await highlightMaterial!.createInstance();
await highlightMaterialInstance!.setParameterFloat("scale", scale);
await highlightMaterialInstance!
.setParameterFloat4("color", r, g, b, 1.0);
_highlighted[asset] = highlightMaterialInstance; await highlightMaterialInstance!.setDepthCullingEnabled(true);
await highlightMaterialInstance!.setDepthWriteEnabled(true);
}
OverlayManager_addComponent(overlayManager!, entity,
highlightMaterialInstance.getNativeHandle());
_highlighted[entity] = highlightMaterialInstance!;
}
}
_logger.info("Added stencil highlight for asset (entity ${asset.entity})"); _logger.info("Added stencil highlight for asset (entity ${asset.entity})");
} }
@@ -331,22 +344,29 @@ class FFIView extends View<Pointer<TView>> {
/// ///
@override @override
Future removeStencilHighlight(ThermionAsset asset) async { Future removeStencilHighlight(ThermionAsset asset) async {
if (!_highlighted.containsKey(asset)) { if (overlayManager == null) {
_logger
.warning("No stencil highlight for asset (entity ${asset.entity})");
return; return;
} }
final materialInstance = _highlighted[asset]!; final entities = [asset.entity, ...await asset.getChildEntities()];
_highlighted.remove(asset);
_logger
.info("Removing stencil highlight for asset (entity ${asset.entity})");
OverlayManager_removeComponent(overlayManager!, asset.entity); for (final entity in entities) {
OverlayManager_removeComponent(overlayManager!, entity);
}
await materialInstance.destroy(); final destroyed = <MaterialInstance>{};
for (final entity in entities) {
final materialInstance = _highlighted[entity];
if (!await FilamentApp.instance!.isRenderable(entity) ||
materialInstance == null) {
continue;
}
_logger _highlighted.remove(entity);
.info("Removed stencil highlight for asset (entity ${asset.entity})"); if (!destroyed.contains(materialInstance)) {
await materialInstance.destroy();
destroyed.add(materialInstance);
}
}
} }
void setName(String name) { void setName(String name) {