Skip to content

Commit 8ec856b

Browse files
Refactor render interface after MC meeting
1 parent e3ea1d8 commit 8ec856b

File tree

5 files changed

+45
-39
lines changed

5 files changed

+45
-39
lines changed

flow360/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
RenderCameraConfig,
138138
RenderEnvironmentConfig,
139139
RenderLightingConfig,
140-
RenderMaterialConfig,
141140
SkyboxBackground,
142141
SkyboxTexture,
143142
SolidBackground,

flow360/component/simulation/outputs/output_render_types.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,7 @@ def rainbow(cls, field, min=0, max=1, alpha=1):
244244

245245

246246
AllMaterialTypes = Union[PBRMaterial, FieldMaterial]
247-
248-
249-
class RenderMaterialConfig(Flow360BaseModel):
250-
materials: List[AllMaterialTypes] = pd.Field([])
251-
mappings: Dict[str, int] = pd.Field({})
252-
247+
253248

254249
class Transform(Flow360BaseModel):
255250
translation: LengthType.Point = pd.Field(default=[0, 0, 0])

flow360/component/simulation/outputs/outputs.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
# pylint: disable=too-many-lines
9-
from typing import Annotated, List, Literal, Optional, Union, get_args
9+
from typing import Annotated, Dict, List, Literal, Optional, Union, get_args
1010

1111
import pydantic as pd
1212

@@ -33,10 +33,10 @@
3333
get_field_values,
3434
)
3535
from flow360.component.simulation.outputs.output_render_types import (
36+
AllMaterialTypes,
3637
RenderCameraConfig,
3738
RenderEnvironmentConfig,
3839
RenderLightingConfig,
39-
RenderMaterialConfig,
4040
Transform,
4141
)
4242
from flow360.component.simulation.primitives import (
@@ -702,20 +702,22 @@ class RenderOutput(_AnimationSettings):
702702
"""
703703

704704
name: Optional[str] = pd.Field("Render output", description="Name of the `IsosurfaceOutput`.")
705-
entities: Optional[EntityList[Surface, Slice]] = pd.Field(
706-
None, description="List of of :class:`~flow360.Surface` or `~flow360.Slice` entities."
705+
surfaces: Optional[EntityList[Surface]] = pd.Field(
706+
None, description="List of of :class:`~flow360.Surface` entities."
707+
)
708+
slices: Optional[EntityList[Slice]] = pd.Field(
709+
None, description="List of of :class:`~flow360.Slice` entities."
707710
)
708711
isosurfaces: Optional[UniqueItemList[Isosurface]] = pd.Field(
709712
None, description="List of :class:`~flow360.Isosurface` entities."
710713
)
711714
output_fields: UniqueItemList[Union[CommonFieldNames, str]] = pd.Field(
712-
description="List of output variables. Including "
713-
":ref:`universal output variables<UniversalVariablesV2>` and :class:`UserDefinedField`."
715+
[], description="List of output variables."
714716
)
715717
camera: RenderCameraConfig = pd.Field(description="Camera settings", default_factory=RenderCameraConfig.orthographic)
716718
lighting: RenderLightingConfig = pd.Field(description="Lighting settings", default_factory=RenderLightingConfig.default)
717719
environment: RenderEnvironmentConfig = pd.Field(description="Environment settings", default_factory=RenderEnvironmentConfig.simple)
718-
materials: RenderMaterialConfig = pd.Field(description="Material settings")
720+
materials: Dict[str, AllMaterialTypes] = pd.Field(description="Material settings per entity")
719721
transform: Optional[Transform] = pd.Field(None, description="Optional model transform to apply to all entities")
720722
output_type: Literal["RenderOutput"] = pd.Field("RenderOutput", frozen=True)
721723

flow360/component/simulation/translator/solver_translator.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
)
9898
from flow360.component.simulation.simulation_params import SimulationParams
9999
from flow360.component.simulation.time_stepping.time_stepping import Steady, Unsteady
100+
from flow360.component.simulation.outputs.output_render_types import FieldMaterial
100101
from flow360.component.simulation.translator.user_expression_utils import (
101102
udf_prepending_code,
102103
)
@@ -594,29 +595,31 @@ def translate_render_output(
594595
environment = render.environment.model_dump(
595596
exclude_none=True, exclude_unset=True, by_alias=True
596597
)
597-
materials = render.materials.model_dump(
598-
exclude_none=True, exclude_unset=True, by_alias=True
599-
)
598+
599+
materials = {}
600+
601+
for name, material in render.materials.items():
602+
material = material.model_dump(exclude_none=True, exclude_unset=True, by_alias=True)
603+
materials[name] = material
604+
605+
if "outputField" in material and material["outputField"] not in render.output_fields:
606+
print(f"Adding material field: {material['outputField']}")
607+
render.output_fields.append(material["outputField"])
608+
609+
print(f"Render output fields are: {render.output_fields}")
610+
611+
print(f"Materials are: {materials}")
600612

601613
translated_output = {
602614
"animationFrequency": render.frequency,
603615
"animationFrequencyOffset": render.frequency_offset,
604-
"isoSurfaces": translate_setting_and_apply_to_all_entities(
605-
[render],
606-
RenderOutput,
607-
translation_func=translate_output_fields,
608-
to_list=False,
609-
entity_injection_func=isosurface_injection_function,
610-
entity_type_to_include=Isosurface,
611-
entity_list_attribute_name="isosurfaces",
612-
entity_injection_input_params=input_params,
613-
),
614616
"surfaces": translate_setting_and_apply_to_all_entities(
615617
[render],
616618
RenderOutput,
617619
translation_func=translate_output_fields,
618620
to_list=False,
619621
entity_type_to_include=Surface,
622+
entity_list_attribute_name="surfaces"
620623
),
621624
"slices": translate_setting_and_apply_to_all_entities(
622625
[render],
@@ -625,6 +628,17 @@ def translate_render_output(
625628
to_list=False,
626629
entity_injection_func=slice_injection_function,
627630
entity_type_to_include=Slice,
631+
entity_list_attribute_name="slices"
632+
),
633+
"isoSurfaces": translate_setting_and_apply_to_all_entities(
634+
[render],
635+
RenderOutput,
636+
translation_func=translate_output_fields,
637+
to_list=False,
638+
entity_injection_func=isosurface_injection_function,
639+
entity_type_to_include=Isosurface,
640+
entity_list_attribute_name="isosurfaces",
641+
entity_injection_input_params=input_params,
628642
),
629643
"camera": remove_units_in_dict(camera),
630644
"lighting": remove_units_in_dict(lighting),

tests/simulation/translator/test_solver_translator.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
RenderCameraConfig,
7373
RenderEnvironmentConfig,
7474
RenderLightingConfig,
75-
RenderMaterialConfig,
7675
SkyboxBackground,
7776
SkyboxTexture,
7877
StaticCamera,
@@ -276,17 +275,14 @@ def get_om6Wing_tutorial_param():
276275
environment=RenderEnvironmentConfig(
277276
background=SkyboxBackground(texture=SkyboxTexture.SKY)
278277
),
279-
materials=RenderMaterialConfig(
280-
materials=[
281-
PBRMaterial(
282-
color=(245, 245, 246),
283-
alpha=1.0,
284-
roughness=0.3,
285-
f0=(0.56, 0.56, 0.56),
286-
)
287-
],
288-
mappings={"iso": 0},
289-
),
278+
materials={
279+
"iso": PBRMaterial(
280+
color=(245, 245, 246),
281+
alpha=1.0,
282+
roughness=0.3,
283+
f0=(0.56, 0.56, 0.56),
284+
)
285+
}
290286
),
291287
],
292288
)

0 commit comments

Comments
 (0)