Skip to content
Merged
Show file tree
Hide file tree
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
46 changes: 18 additions & 28 deletions flow360/component/simulation/outputs/render_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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),
)


Expand Down Expand Up @@ -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,
Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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)
)


Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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,
Expand All @@ -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.

Expand All @@ -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,
Expand All @@ -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.

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/simulation/translator/ref/Flow360_om6wing_render.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
{
"isoSurfaces": {},
"material": {
"alpha": 1.0,
"opacity": 1.0,
"color": [
255,
255,
Expand All @@ -132,7 +132,7 @@
}
},
"material": {
"alpha": 1.0,
"opacity": 1.0,
"colormap": [
[
0,
Expand Down
4 changes: 2 additions & 2 deletions tests/simulation/translator/test_solver_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand All @@ -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
),
),
],
Expand Down
Loading