MCPcopy
hub / github.com/CadQuery/cadquery / toJSON

Function toJSON

cadquery/occ_impl/assembly.py:718–751  ·  view source on GitHub ↗

Export an object to a structure suitable for converting to VTK.js JSON.

(
    assy: AssemblyProtocol,
    color: Tuple[float, float, float, float] = (1.0, 1.0, 1.0, 1.0),
    edgecolor: Tuple[float, float, float, float] = (0.0, 0.0, 0.0, 1.0),
    tolerance: float = 1e-3,
)

Source from the content-addressed store, hash-verified

716
717
718def toJSON(
719 assy: AssemblyProtocol,
720 color: Tuple[float, float, float, float] = (1.0, 1.0, 1.0, 1.0),
721 edgecolor: Tuple[float, float, float, float] = (0.0, 0.0, 0.0, 1.0),
722 tolerance: float = 1e-3,
723) -> List[Dict[str, Any]]:
724 """
725 Export an object to a structure suitable for converting to VTK.js JSON.
726 """
727
728 rv = []
729
730 for shape, _, loc, col_ in assy:
731
732 val_faces: Any = {}
733 val_edges: Any = {}
734
735 data_edges, data_faces = toString(shape, tolerance)
736 trans, rot = loc.toTuple()
737
738 val_edges["shape"] = data_edges
739 val_edges["color"] = edgecolor
740 val_edges["position"] = trans
741 val_edges["orientation"] = tuple(radians(r) for r in rot)
742
743 val_faces["shape"] = data_faces
744 val_faces["color"] = col_.toTuple() if col_ else color
745 val_faces["position"] = trans
746 val_faces["orientation"] = tuple(radians(r) for r in rot)
747
748 rv.append(val_edges)
749 rv.append(val_faces)
750
751 return rv
752
753
754def toFusedCAF(

Callers 3

runMethod · 0.90
test_toJSONFunction · 0.90
displayFunction · 0.85

Calls 3

toStringFunction · 0.85
appendMethod · 0.80
toTupleMethod · 0.45

Tested by 1

test_toJSONFunction · 0.72