|
30 | 30 | from OCP.Message import Message_ProgressRange
|
31 | 31 | from OCP.Interface import Interface_Static
|
32 | 32 |
|
33 |
| -from ..assembly import AssemblyProtocol, color_to_occt, toCAF, toVTK, toFusedCAF |
| 33 | +from ..assembly import ( |
| 34 | + AssemblyProtocol, |
| 35 | + color_to_occt, |
| 36 | + toCAF, |
| 37 | + toVTK, |
| 38 | + toFusedCAF, |
| 39 | + material_to_occt, |
| 40 | +) |
34 | 41 | from ..geom import Location
|
35 | 42 | from ..shapes import Shape, Compound
|
36 | 43 |
|
@@ -139,6 +146,8 @@ def exportStepMeta(
|
139 | 146 | shape_tool = XCAFDoc_DocumentTool.ShapeTool_s(doc.Main())
|
140 | 147 | color_tool = XCAFDoc_DocumentTool.ColorTool_s(doc.Main())
|
141 | 148 | layer_tool = XCAFDoc_DocumentTool.LayerTool_s(doc.Main())
|
| 149 | + material_tool = XCAFDoc_DocumentTool.MaterialTool_s(doc.Main()) |
| 150 | + vis_material_tool = XCAFDoc_DocumentTool.VisMaterialTool_s(doc.Main()) |
142 | 151 |
|
143 | 152 | def _process_child(child: AssemblyProtocol, assy_label: TDF_Label):
|
144 | 153 | """
|
@@ -166,16 +175,46 @@ def _process_child(child: AssemblyProtocol, assy_label: TDF_Label):
|
166 | 175 | child.name,
|
167 | 176 | child.loc,
|
168 | 177 | child.color,
|
| 178 | + child.material, |
169 | 179 | )
|
170 | 180 |
|
171 | 181 | if child_items:
|
172 |
| - shape, name, loc, color = child_items |
| 182 | + shape, name, loc, color, material = child_items |
173 | 183 |
|
174 | 184 | # Handle shape name, color and location
|
175 | 185 | part_label = shape_tool.AddShape(shape.wrapped, False)
|
176 | 186 | TDataStd_Name.Set_s(part_label, TCollection_ExtendedString(name))
|
177 |
| - if color: |
| 187 | + |
| 188 | + # Handle color and material |
| 189 | + if material: |
| 190 | + # Set color from material if available |
| 191 | + if material.color: |
| 192 | + color_tool.SetColor( |
| 193 | + part_label, color_to_occt(material.color), XCAFDoc_ColorGen |
| 194 | + ) |
| 195 | + |
| 196 | + # Convert material to OCCT format and add to document |
| 197 | + mat, vis_mat = material_to_occt(material) |
| 198 | + |
| 199 | + # Create material label |
| 200 | + mat_lab = material_tool.AddMaterial( |
| 201 | + mat.GetName(), |
| 202 | + mat.GetDescription(), |
| 203 | + mat.GetDensity(), |
| 204 | + mat.GetDensName(), |
| 205 | + mat.GetDensValType(), |
| 206 | + ) |
| 207 | + material_tool.SetMaterial(part_label, mat_lab) |
| 208 | + |
| 209 | + # Add visualization material to the document |
| 210 | + vis_mat_lab = vis_material_tool.AddMaterial( |
| 211 | + vis_mat, TCollection_AsciiString(material.name) |
| 212 | + ) |
| 213 | + vis_material_tool.SetShapeMaterial(part_label, vis_mat_lab) |
| 214 | + elif color: |
| 215 | + # If no material but color exists, set the color directly |
178 | 216 | color_tool.SetColor(part_label, color_to_occt(color), XCAFDoc_ColorGen)
|
| 217 | + |
179 | 218 | shape_tool.AddComponent(assy_label, part_label, loc.wrapped)
|
180 | 219 |
|
181 | 220 | # If this assembly has shape metadata, add it to the shape
|
|
0 commit comments