Wrapper for the OCCT material classes XCAFDoc_Material and XCAFDoc_VisMaterial. XCAFDoc_Material is focused on physical material properties and XCAFDoc_VisMaterial is for visual properties to be used when rendering.
| 59 | |
| 60 | |
| 61 | class Material(object): |
| 62 | """ |
| 63 | Wrapper for the OCCT material classes XCAFDoc_Material and XCAFDoc_VisMaterial. |
| 64 | XCAFDoc_Material is focused on physical material properties and |
| 65 | XCAFDoc_VisMaterial is for visual properties to be used when rendering. |
| 66 | """ |
| 67 | |
| 68 | wrapped: XCAFDoc_Material |
| 69 | wrapped_vis: XCAFDoc_VisMaterial |
| 70 | |
| 71 | def __init__(self, name: str | None = None, **kwargs): |
| 72 | """ |
| 73 | Can be passed an arbitrary string name for the material along with keyword |
| 74 | arguments defining some other characteristics of the material. If nothing is |
| 75 | passed, arbitrary defaults are used. |
| 76 | """ |
| 77 | |
| 78 | # Create the default material object and prepare to set a few defaults |
| 79 | self.wrapped = XCAFDoc_Material() |
| 80 | |
| 81 | # Default values in case the user did not set any others |
| 82 | aName = "Default" |
| 83 | aDescription = "" |
| 84 | aDensity = 7.85 |
| 85 | aDensityName = "Mass density" |
| 86 | aDensityTypeName = "g/cm^3" |
| 87 | |
| 88 | # See if there are any non-defaults to be set |
| 89 | if name: |
| 90 | aName = name |
| 91 | if "description" in kwargs.keys(): |
| 92 | aDescription = kwargs["description"] |
| 93 | if "density" in kwargs.keys(): |
| 94 | aDensity = kwargs["density"] |
| 95 | if "densityUnit" in kwargs.keys(): |
| 96 | aDensityTypeName = kwargs["densityUnit"] |
| 97 | |
| 98 | # Set the properties on the material object |
| 99 | self.wrapped.Set( |
| 100 | TCollection_HAsciiString(aName), |
| 101 | TCollection_HAsciiString(aDescription), |
| 102 | aDensity, |
| 103 | TCollection_HAsciiString(aDensityName), |
| 104 | TCollection_HAsciiString(aDensityTypeName), |
| 105 | ) |
| 106 | |
| 107 | # Create the default visual material object and allow it to be used just with |
| 108 | # the OCC layer, for now. When this material class is expanded to include visual |
| 109 | # attributes, the OCC docs say that XCAFDoc_VisMaterialTool should be used to |
| 110 | # manage those attributes on the XCAFDoc_VisMaterial class. |
| 111 | self.wrapped_vis = XCAFDoc_VisMaterial() |
| 112 | |
| 113 | @property |
| 114 | def name(self) -> str: |
| 115 | """ |
| 116 | Get the string name of the material. |
| 117 | """ |
| 118 | return self.wrapped.GetName().ToCString() |
no outgoing calls