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