From c524fb065852381988ae204912a98e476c6bf4df Mon Sep 17 00:00:00 2001 From: andrzej-krupka Date: Tue, 23 Dec 2025 22:57:55 +0000 Subject: [PATCH] Rename alpha to opacity, fix field material behavior for vector fields --- .../simulation/outputs/render_config.py | 46 ++++++++----------- .../ref/Flow360_om6wing_render.json | 4 +- .../translator/test_solver_translator.py | 4 +- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/flow360/component/simulation/outputs/render_config.py b/flow360/component/simulation/outputs/render_config.py index c25107466..069fd29ce 100644 --- a/flow360/component/simulation/outputs/render_config.py +++ b/flow360/component/simulation/outputs/render_config.py @@ -347,7 +347,7 @@ class Lighting(Flow360BaseModel): ) @classmethod - def default(cls): + def default(cls, direction=(-1.0, -1.0, -1.0)): """ Returns the default lighting configuration. @@ -357,9 +357,7 @@ def default(cls): """ return Lighting( ambient=AmbientLight(intensity=0.4, color=(255, 255, 255)), - directional=DirectionalLight( - intensity=1.0, color=(255, 255, 255), direction=(-1.0, -1.0, -1.0) - ), + directional=DirectionalLight(intensity=1.0, color=(255, 255, 255), direction=direction), ) @@ -482,7 +480,7 @@ class PBRMaterial(MaterialBase): color: Color = pd.Field( default=[255, 255, 255], description="Basic diffuse color of the material (base color)" ) - alpha: float = pd.Field( + opacity: float = pd.Field( default=1, ge=0, le=1, @@ -500,7 +498,7 @@ class PBRMaterial(MaterialBase): ) @classmethod - def metal(cls, shine=0.5, alpha=1.0): + def metal(cls, shine=0.5, opacity=1.0): """ Create a metallic PBR material. @@ -509,11 +507,11 @@ def metal(cls, shine=0.5, alpha=1.0): >>> PBRMaterial.metal(shine=0.8) """ return PBRMaterial( - color=(255, 255, 255), alpha=alpha, roughness=1 - shine, f0=(0.56, 0.56, 0.56) + color=(255, 255, 255), opacity=opacity, roughness=1 - shine, f0=(0.56, 0.56, 0.56) ) @classmethod - def plastic(cls, shine=0.5, alpha=1.0): + def plastic(cls, shine=0.5, opacity=1.0): """ Create a plastic PBR material. @@ -522,7 +520,7 @@ def plastic(cls, shine=0.5, alpha=1.0): >>> PBRMaterial.plastic(shine=0.2) """ return PBRMaterial( - color=(255, 255, 255), alpha=alpha, roughness=1 - shine, f0=(0.03, 0.03, 0.03) + color=(255, 255, 255), opacity=opacity, roughness=1 - shine, f0=(0.03, 0.03, 0.03) ) @@ -536,7 +534,7 @@ class FieldMaterial(MaterialBase): """ type_name: Literal["FieldMaterial"] = pd.Field("FieldMaterial", frozen=True) - alpha: float = pd.Field( + opacity: float = pd.Field( default=1, ge=0, le=1, @@ -565,14 +563,6 @@ def _preprocess_expression_and_solver_variable(cls, value): ) return solver_variable_to_user_variable(value) - @pd.field_validator("output_field", mode="after") - @classmethod - def check_expression_length(cls, v): - """Ensure the output field is a scalar.""" - if isinstance(v, UserVariable) and len(v) != 0: - raise ValueError(f"The output field ({v}) must be defined with a scalar variable.") - return v - @pd.field_validator("output_field", mode="after") @classmethod def check_runtime_expression(cls, v): @@ -648,7 +638,7 @@ def check_iso_value_for_string_field(cls, v, info: pd.ValidationInfo): return v @classmethod - def rainbow(cls, field, min_value, max_value, alpha=1): + def rainbow(cls, field, min_value, max_value, opacity=1): """ Create a rainbow-style colormap for scalar fields. @@ -669,11 +659,11 @@ def _rainbow_rgb(t): # Approximated from TS rainbowGradient sampling return FieldMaterial( - alpha=alpha, output_field=field, min=min_value, max=max_value, colormap=colormap + opacity=opacity, output_field=field, min=min_value, max=max_value, colormap=colormap ) @classmethod - def orizon(cls, field, min_value, max_value, alpha=1): + def orizon(cls, field, min_value, max_value, opacity=1): """ Create an Orizon-style (blue–orange) colormap. @@ -694,11 +684,11 @@ def _orizon_rgb(t): # Approximated from TS orizonGradient sampling return FieldMaterial( - alpha=alpha, output_field=field, min=min_value, max=max_value, colormap=colormap + opacity=opacity, output_field=field, min=min_value, max=max_value, colormap=colormap ) @classmethod - def viridis(cls, field, min_value, max_value, alpha=1): + def viridis(cls, field, min_value, max_value, opacity=1): """ Create a Viridis colormap. @@ -707,7 +697,7 @@ def viridis(cls, field, min_value, max_value, alpha=1): >>> FieldMaterial.viridis("vorticity") """ return FieldMaterial( - alpha=alpha, + opacity=opacity, output_field=field, min=min_value, max=max_value, @@ -722,7 +712,7 @@ def viridis(cls, field, min_value, max_value, alpha=1): ) @classmethod - def magma(cls, field, min_value, max_value, alpha=1): + def magma(cls, field, min_value, max_value, opacity=1): """ Create a Magma colormap. @@ -731,7 +721,7 @@ def magma(cls, field, min_value, max_value, alpha=1): >>> FieldMaterial.magma("density") """ return FieldMaterial( - alpha=alpha, + opacity=opacity, output_field=field, min=min_value, max=max_value, @@ -745,7 +735,7 @@ def magma(cls, field, min_value, max_value, alpha=1): ) @classmethod - def airflow(cls, field, min_value, max_value, alpha=1): + def airflow(cls, field, min_value, max_value, opacity=1): """ Create an Airflow-style visualization colormap. @@ -754,7 +744,7 @@ def airflow(cls, field, min_value, max_value, alpha=1): >>> FieldMaterial.airflow("pressure_coefficient") """ return FieldMaterial( - alpha=alpha, + opacity=opacity, output_field=field, min=min_value, max=max_value, diff --git a/tests/simulation/translator/ref/Flow360_om6wing_render.json b/tests/simulation/translator/ref/Flow360_om6wing_render.json index 152b80422..93e94a549 100644 --- a/tests/simulation/translator/ref/Flow360_om6wing_render.json +++ b/tests/simulation/translator/ref/Flow360_om6wing_render.json @@ -105,7 +105,7 @@ { "isoSurfaces": {}, "material": { - "alpha": 1.0, + "opacity": 1.0, "color": [ 255, 255, @@ -132,7 +132,7 @@ } }, "material": { - "alpha": 1.0, + "opacity": 1.0, "colormap": [ [ 0, diff --git a/tests/simulation/translator/test_solver_translator.py b/tests/simulation/translator/test_solver_translator.py index 9f5c27cec..e36a8b99d 100644 --- a/tests/simulation/translator/test_solver_translator.py +++ b/tests/simulation/translator/test_solver_translator.py @@ -1523,7 +1523,7 @@ def test_om6wing_render_output(get_om6Wing_tutorial_param): groups=[ RenderOutputGroup( surfaces=[Surface(name="1")], - material=PBRMaterial.metal(shine=0.7, alpha=1.0), + material=PBRMaterial.metal(shine=0.7, opacity=1.0), ), RenderOutputGroup( slices=[ @@ -1541,7 +1541,7 @@ def test_om6wing_render_output(get_om6Wing_tutorial_param): ) ], material=FieldMaterial.rainbow( - field=solution.Mach, min_value=0, max_value=0.1, alpha=1 + field=solution.Mach, min_value=0, max_value=0.1, opacity=1 ), ), ],