support bd cad objects with color tagged

This commit is contained in:
Chaser Huang
2024-10-07 21:21:51 -04:00
committed by Yeicor
parent e73f745800
commit 712e0a06e6
3 changed files with 29 additions and 9 deletions

View File

@@ -10,12 +10,23 @@ from OCP.TopExp import TopExp
from OCP.TopLoc import TopLoc_Location
from OCP.TopTools import TopTools_IndexedMapOfShape
from OCP.TopoDS import TopoDS_Shape
from build123d import Compound, Shape
from build123d import Compound, Shape, Color
from yacv_server.gltf import GLTFMgr
CADCoreLike = Union[TopoDS_Shape, TopLoc_Location] # Faces, Edges, Vertices and Locations for now
CADLike = Union[CADCoreLike, any] # build123d and cadquery types
ColorTuple = Tuple[float, float, float, float]
def get_color(obj: CADLike) -> Optional[ColorTuple]:
"""Get color from a CAD Object"""
if 'color' in dir(obj):
if isinstance(obj.color, tuple):
return obj.color
if isinstance(obj.color, Color):
return obj.color.to_tuple()
return None
def get_shape(obj: CADLike, error: bool = True) -> Optional[CADCoreLike]: