freecadviewer module¶
This module contains functions that enable rendering FreeCAD Document objects inside an IPython environment, for example inside a Jupyter Notebook. The function needed to do this is render_document.
-
class
freecadviewer.RendererConfig¶ Bases:
objectProvides a safe configuration for the PyThreeJS renderer
-
selection_mode¶
-
show_config()¶
-
show_edges¶
-
show_faces¶
-
show_mesh¶
-
show_normals¶
-
view_height¶
-
view_width¶
-
-
freecadviewer.bfs_traversal(node: <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, coordinates: Optional[<sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>] = None, material: Optional[<sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>] = None, transform: Optional[<sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>] = None, index: int = 0, print_tree: bool = False, depth_counter: int = 0, object_index: int = 0) → List[Tuple[<sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, int, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>]]¶ Return list of all (SoIndexed(Line/Face)Set, SoCoordinate3, SoMaterial) tuples inside the scene graph.
The breadth first search always referes to the parent material and coordinates if there aren’t any on the same level.
-
freecadviewer.compute_normals(faces: List[Tuple[int, int, int]], vertices: List[Tuple[float, float, float]]) → numpy.array¶ Returns a list of normals for each vertex.
Input for N faces should be numpy array of shape (N, 3) and for M vertices shape (M, 3) respectively
-
freecadviewer.create_face_geom(coord_vals: List[Tuple[float, float, float]], face_indices: List[List[int]], face_color: Tuple[float, float, float], transparency: float, translation: Tuple[float, float, float] = None, quaternion: Tuple[float, float, float, float] = None) → List[Union[pythreejs.objects.Mesh_autogen.Mesh, pythreejs.objects.Line_autogen.Line, pythreejs.math.Sphere_autogen.Sphere]]¶ Returns a pythreejs Mesh object that consists of the faces given by face_indices and the coord_vals.
Additionally the attributes Mesh.default_material and Mesh.geometry.default_color will be set before returning the Mesh. Those attributes contain references to the default colors and materials that are set in this function to restore later changes.
-
freecadviewer.create_geometry(res_tuple: Tuple[<sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, int, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>], name: str = '', show_faces: bool = True, show_edges: bool = True) → List[Union[pythreejs.objects.Mesh_autogen.Mesh, pythreejs.objects.Line_autogen.Line, pythreejs.math.Sphere_autogen.Sphere]]¶ Returns PyThreeJS representations of the given Coin3D object tuples.
-
freecadviewer.create_line_geom(coord_vals: List[Tuple[float, float, float]], indices: List[List[int]], line_color: Tuple[float, float, float], translation: Tuple[float, float, float] = None, quaternion: Tuple[float, float, float, float] = None) → List[Union[pythreejs.objects.Mesh_autogen.Mesh, pythreejs.objects.Line_autogen.Line, pythreejs.math.Sphere_autogen.Sphere]]¶ Return a pythreejs Line object consisting of lines defined by the line_indices and the coord_vals.
Additionally the attributes Line.default_color and Line.edge_index will be set before returning the Line array. Those attributes contain references to the default colors, that are set in this function to restore later changes, and the FreeCAD edge index.
-
freecadviewer.document_to_scene_graph(doc) → Tuple[<sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, List[str]]¶ Convert a FreeCAD document to a Coin3D scene graph and retain a list of object names
-
freecadviewer.extract_values(res_tuple: Tuple[<sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, int, <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>]) → Tuple[List[Tuple[float, float, float]], List[List[int]], Tuple[float, float, float, float], Tuple[float, float, float], Tuple[float, float, float], int, bool]¶ Given the Coin3D scene graph object tuple the function will return the information (coordinates, indices etc.) in an more basic python type as in the typing specification.
-
freecadviewer.freecad_name_from_obj3d(obj3d: Union[pythreejs.objects.Mesh_autogen.Mesh, pythreejs.objects.Line_autogen.Line, pythreejs.math.Sphere_autogen.Sphere]) → str¶ Returns the objects name inside the FreeCAD document.
-
freecadviewer.generate_line_vertices(line_indices: List[int], coord_vals: List[Tuple[float, float, float]]) → List[Tuple[float, float, float]]¶ Replaces indices in list with the corresponding coordinate values
-
freecadviewer.generate_picker(geometries: List[Union[pythreejs.objects.Mesh_autogen.Mesh, pythreejs.objects.Line_autogen.Line, pythreejs.math.Sphere_autogen.Sphere]], part_indices: List[List[int]], mode: str = 'click') → Tuple[ipywidgets.widgets.widget_string.HTML, pythreejs.controls.Picker_autogen.Picker]¶ Returns a picker that will enable object and face selection as well as highlighting those selections
Picker mode can be mousemove or click or dblclick and is set via the mode parameter.
-
freecadviewer.get_document_renderer(doc, renderer_config: freecadviewer.RendererConfig = <freecadviewer.RendererConfig object>) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8d5d0>¶ Return a Renderer and HTML for rendering any FreeCAD document inside Jupyter Notebook
-
freecadviewer.get_line_geometries(geom: Union[pythreejs.objects.Mesh_autogen.Mesh, pythreejs.objects.Line_autogen.Line, pythreejs.math.Sphere_autogen.Sphere]) → pythreejs.objects.LineSegments_autogen.LineSegments¶ Return line segments that represent the edges of the given objects mesh.
-
freecadviewer.get_name(obj: Union[pythreejs.objects.Mesh_autogen.Mesh, pythreejs.objects.Line_autogen.Line, pythreejs.math.Sphere_autogen.Sphere, None]) → str¶ Returns object.name except if object is None. Then returns string “None”.
-
freecadviewer.get_objects_renderer(root_node: <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, names: List[str], renderer_config: freecadviewer.RendererConfig = <freecadviewer.RendererConfig object>) → Tuple[pythreejs.core.Renderer.Renderer, ipywidgets.widgets.widget_string.HTML]¶ Return a Renderer and HTML for rendering any coin root node of a scene graph containing LineSets or FaceSets inside Jupyter notebook.
-
freecadviewer.index_by_face_index(part_index: List[int], face_index: int) → Optional[int]¶ Returns the index of the Shape face for a given face index. If the face index is not in the part_index returns None.
-
freecadviewer.part_index_by_name(name: str, part_indices: List[List[int]]) → List[int]¶ Returns coin.IndexedFaceSet`s `partIndex attribute given the pythreejs Geometry name attribute containing the objects index in the Coin scene graph at the beginning of the name. >>part_index_by_name(“2 4”, [[1,1,1], [2,3,4], [222]]) [222]
-
freecadviewer.render_document(doc, renderer_config: freecadviewer.RendererConfig = <freecadviewer.RendererConfig object>) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8d5d0>¶ Return a DisplayHandle rendering any FreeCAD document inside Jupyter notebook.
-
freecadviewer.render_objects(root_node: <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>, names: List[str], renderer_config: freecadviewer.RendererConfig = <freecadviewer.RendererConfig object>) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8d5d0>¶ Return a DisplayHandle rendering any coin root node of a scene graph containing LineSets or FaceSets inside Jupyter notebook.
-
freecadviewer.reset_object_highlighting(obj: Union[pythreejs.objects.Mesh_autogen.Mesh, pythreejs.objects.Line_autogen.Line, pythreejs.math.Sphere_autogen.Sphere]) → None¶ After calling this function the object of type Line, Sphere or Mesh will be reset to it’s default colors.
-
freecadviewer.so_col_to_hex(so_color: tuple) → str¶ Translate Coin scene object color into html hex color strings. >>>so_col_tohex((1,0,0.5)) “#ff0008”
-
freecadviewer.transform_indices(so_node: <sphinx.ext.autodoc.importer._MockObject object at 0x7f927cc8a850>) → List[List[int]]¶ Returns list of lists that represent indices from pivy.coin scene objects ‘SoIndexedLineSet’ and ‘SoIndexedFaceSet’. When ever a -1 is encountered in so_node.coordIndex a separate new Line or Face is created
-
freecadviewer.vertices_col_highlight_face(shape_face_index: int, cols_default: numpy.array, part_index: List[int], face_indices: List[int]) → numpy.array¶ Returns vertex color array where the indexed face is highlighted.