feat(materials): Add setColor method with opacity preservation #137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new
setColormethod that allows applying color-only highlights while preserving original material properties such as opacity and transparency. The method provides a convenient way to change only the color of items without affecting other material properties.Key changes:
New
setColormethod - Added toFragmentsModel,VirtualFragmentsModel,HighlightManager, andHighlightHelper:preserveOriginalMaterialflag inMaterialDefinitionto indicate color-only operationsEnhanced
processHighlightinMaterialManager- Fixed to properly handle thepreserveOriginalMaterialflag:renderedFaceswhile maintaining other propertiesMaterial deduplication fix - Updated
VirtualMaterialControllerto prevent deduplication for materials withpreserveOriginalMaterialflag, as they need to preserve original properties that may differ even with the same colorType definition - Added
preserveOriginalMaterial?: booleantoMaterialDefinitiontypeUsage Example
The
setColormethod provides a simple API for applying color-only highlights while preserving material properties like opacity:Key benefit: Unlike using
highlight()with a full material definition,setColor()automatically preserves the original material's opacity and transparency. This is especially useful when working with transparent materials that should maintain their transparency when highlighted.Additional context
This feature is particularly useful for visualizations where you want to change the color of items (e.g., for highlighting or filtering) without losing transparency or other material properties. The
setColormethod provides a simpler API compared to usinghighlightwith a full material definition when only the color needs to change. Otherwise it is not possible to add color to an item that has different material opacities (e.g. a window with frame and glass) while those opacities should be obtained.Files changed:
fragments-model.ts- AddedsetColormethodhighlight-manager.ts- AddedsetColormethodhighlight-helper.ts- AddedsetColorimplementationvirtual-fragments-model.ts- AddedsetColormethodmaterial-manager.ts- EnhancedprocessHighlightto preserve original material propertiesvirtual-material-controller.ts- Prevented deduplication for materials withpreserveOriginalMaterialmodel-types.ts- AddedpreserveOriginalMaterialflag toMaterialDefinitionWhat is the purpose of this pull request?
Before submitting the PR, please make sure you do the following:
feat(examples): add hello-world example).fixes #123).