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

Image Element mask fix #7341

Merged
merged 3 commits into from
Feb 11, 2025
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
18 changes: 14 additions & 4 deletions src/framework/components/element/image-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class ImageRenderable {
this.model = null;
this.node = null;
this.mesh = null;
this.meshInstance?.destroy();
this.meshInstance = null;
this.unmaskMeshInstance?.destroy();
this.unmaskMeshInstance = null;
this._entity = null;
this._element = null;
}
Expand All @@ -92,6 +95,11 @@ class ImageRenderable {
setMask(mask) {
if (!this.meshInstance) return;

// remove model to remove mesh instance from layers
if (this._entity.enabled && this._element.enabled) {
this._element.removeModelFromLayers(this.model);
}

if (mask) {
this.unmaskMeshInstance = new MeshInstance(this.mesh, this.meshInstance.material, this.node);
this.unmaskMeshInstance.name = `Unmask: ${this._entity.name}`;
Expand All @@ -111,15 +119,17 @@ class ImageRenderable {
if (idx >= 0) {
this.model.meshInstances.splice(idx, 1);
}

this.unmaskMeshInstance = null;
}

// remove model then re-add to update to current mesh instances
// re-add to update to current mesh instances
if (this._entity.enabled && this._element.enabled) {
this._element.removeModelFromLayers(this.model);
this._element.addModelToLayers(this.model);
}

if (!mask) {
this.unmaskMeshInstance?.destroy();
this.unmaskMeshInstance = null;
}
}

setMaterial(material) {
Expand Down