Ejemplo n.º 1
0
 def __init__(self, dynamic=False):
     super(Object3D, self).__init__()
     self._sel_color = COLORS[self.sel_col]
     self._ovr_color = COLORS[self.ovr_col]
     self._std_color = COLORS[self.std_col]
     self.data = coin.SoCoordinate4()
     self.color = coin.SoMaterial()
     self.color.diffuseColor = self._std_color
     self.addChild(self.color)
     self.addChild(self.data)
     self.start_pos = None
     self.dynamic = dynamic
     self.on_drag = []
     self.on_drag_release = []
     self.on_drag_start = []
     self._delete = False
     self._tmp_points = None
     self.enabled = True
Ejemplo n.º 2
0
    def __init__(self, points, dynamic=False):
        super(Object3D, self).__init__()
        self.data = coin.SoCoordinate3()
        self.color = coin.SoMaterial()
        self.set_color()
        self += [self.color, self.data]
        self.start_pos = None
        self.dynamic = dynamic

        # callback function lists
        self.on_drag = []
        self.on_drag_release = []
        self.on_drag_start = []

        self._delete = False
        self._tmp_points = None
        self.enabled = True
        self.points = points
Ejemplo n.º 3
0
 def __init__(self,line=None,width=0.1,height=1,shaded=False):
     self.trans = coin.SoTransform()
     m = coin.SoMaterial()
     m.transparency.setValue(0.8)
     m.diffuseColor.setValue([0.4,0.4,0.6])
     w = coin.SoDrawStyle()
     w.style = coin.SoDrawStyle.LINES
     self.cube = coin.SoCube()
     self.cube.height.setValue(width)
     self.cube.depth.setValue(height)
     self.baseline = None
     if line:
         self.baseline = line
         self.update()
     if shaded:
         Tracker.__init__(self,children=[self.trans,m,self.cube],name="boxTracker")
     else:
         Tracker.__init__(self,children=[self.trans,w,self.cube],name="boxTracker")
Ejemplo n.º 4
0
def mat2mat(obj):
    '''
    Convert gegede material to SoMaterial.  They have nothing in common.

    ambientColor
    diffuseColor
    specularColor
    emissiveColor
    shininess
    transparency
    '''
    # fixme: add checking of hints
    out = coin.SoMaterial()
    out.diffuseColor = make_rand_vector()
    out.specularColor = make_rand_vector()
    out.ambientColor = make_rand_vector()
    out.transparency = 0.5
    return out
Ejemplo n.º 5
0
    def build_lines(self):
        np = self._number_of_points
        n = 1 + 2 * np

        self.line_mat1 = coin.SoMaterial()
        ol = list()  #[(0.2,0.2,0.2)] + [(0.6,0.6,0.6)] * 9
        bind1 = coin.SoMaterialBinding()
        bind1.value = coin.SoMaterialBinding.PER_PART
        l1 = coin.SoIndexedLineSet()
        l1.coordIndex.setValue(0)
        ind = list()
        for i in range(2 * self._number_of_points + 1):
            if not i == self._number_of_points:
                ind.append((i * n))
                ind.append(((i + 1) * n) - 1)
                ind.append(-1)
                if (i % 10) == 0:
                    ol.append((0.2, 0.2, 0.2))
                else:
                    ol.append((0.4, 0.4, 0.4))
            #print(ind)
        self.line_mat1.diffuseColor.setValues(0, len(ol), ol)
        l1.coordIndex.setValues(0, len(ind), ind)

        l2 = coin.SoIndexedLineSet()
        l2.coordIndex.setValue(0)
        ind2 = list()
        for i in range(2 * self._number_of_points + 1):
            if not i == self._number_of_points:
                ind2.append(i)
                ind2.append(i + (n - 1) * n)
                ind2.append(-1)
                #if (i % 10) == 0:
                #ol.append((0.2,0.2,0.2))
                #else:
                #ol.append((0.4,0.4,0.4))
            #print(ind)
        #self.line_mat1.diffuseColor.setValues(0, len(ol), ol )
        l2.coordIndex.setValues(0, len(ind2), ind2)

        self.sep2.addChild(bind1)
        self.sep2.addChild(self.line_mat1)
        self.sep2.addChild(l1)
        self.sep2.addChild(l2)
Ejemplo n.º 6
0
def viewer(scene=None,background=(1.0,1.0,1.0),lightdir=None):

    """viewer(scene=None,background=(1.0,1.0,1.0),lightdir=None): starts
    a standalone coin viewer with the contents of the given scene. You can
    give a background color, and optionally a light direction as a (x,y,z)
    tuple. In this case, a directional light will be added and shadows will
    be turned on. This might not work with some 3D drivers."""

    # Initialize Coin. This returns a main window to use
    from pivy import coin
    from pivy import sogui

    win = sogui.SoGui.init()
    if win is None:
        print("Unable to create a SoGui window")
        return

    win.setBackgroundColor(coin.SbColor(background[0],background[1],background[2]))

    if not scene:
        # build a quick default scene
        mat = coin.SoMaterial()
        mat.diffuseColor = (1.0, 0.0, 0.0)
        # Make a scene containing a red cone
        scene = coin.SoSeparator()
        scene.addChild(mat)
        scene.addChild(coin.SoCone())

    if lightdir:
        scene = embedLight(scene,lightdir)

    # ref the scene so it doesn't get garbage-collected
    scene.ref()

    # Create a viewer in which to see our scene graph
    viewer = sogui.SoGuiExaminerViewer(win)

    # Put our scene into viewer, change the title
    viewer.setSceneGraph(scene)
    viewer.setTitle("Coin viewer")
    viewer.show()

    sogui.SoGui.show(win) # Display main window
    sogui.SoGui.mainLoop()     # Main Coin event loop
Ejemplo n.º 7
0
 def attach(self, vobj):
     self.bubbles = None
     self.bubbletexts = []
     sep = coin.SoSeparator()
     self.mat = coin.SoMaterial()
     self.linestyle = coin.SoDrawStyle()
     self.linecoords = coin.SoCoordinate3()
     self.lineset = coin.SoType.fromName("SoBrepEdgeSet").createInstance()
     self.bubbleset = coin.SoSeparator()
     self.labelset = coin.SoSeparator()
     sep.addChild(self.mat)
     sep.addChild(self.linestyle)
     sep.addChild(self.linecoords)
     sep.addChild(self.lineset)
     sep.addChild(self.bubbleset)
     sep.addChild(self.labelset)
     vobj.addDisplayMode(sep, "Default")
     self.onChanged(vobj, "BubbleSize")
     self.onChanged(vobj, "ShowLabel")
Ejemplo n.º 8
0
    def attach(self,vobj):

        ArchComponent.ViewProviderComponent.attach(self,vobj)
        from pivy import coin
        self.color = coin.SoBaseColor()
        self.font = coin.SoFont()
        self.text1 = coin.SoAsciiText()
        self.text1.string = " "
        self.text1.justification = coin.SoAsciiText.LEFT
        self.text2 = coin.SoAsciiText()
        self.text2.string = " "
        self.text2.justification = coin.SoAsciiText.LEFT
        self.coords = coin.SoTransform()
        self.header = coin.SoTransform()
        self.label = coin.SoSwitch()
        sep = coin.SoSeparator()
        self.label.whichChild = 0
        sep.addChild(self.coords)
        sep.addChild(self.color)
        sep.addChild(self.font)
        sep.addChild(self.text2)
        sep.addChild(self.header)
        sep.addChild(self.text1)
        self.label.addChild(sep)
        vobj.Annotation.addChild(self.label)
        self.onChanged(vobj,"TextColor")
        self.onChanged(vobj,"FontSize")
        self.onChanged(vobj,"FirstLine")
        self.onChanged(vobj,"LineSpacing")
        self.onChanged(vobj,"FontName")
        self.Object = vobj.Object
        # footprint mode
        self.fmat = coin.SoMaterial()
        self.fcoords = coin.SoCoordinate3()
        self.fset = coin.SoIndexedFaceSet()
        fhints = coin.SoShapeHints()
        fhints.vertexOrdering = fhints.COUNTERCLOCKWISE
        sep = coin.SoSeparator()
        sep.addChild(self.fmat)
        sep.addChild(self.fcoords)
        sep.addChild(fhints)
        sep.addChild(self.fset)
        vobj.RootNode.addChild(sep)
Ejemplo n.º 9
0
def main():
    app = QtWidgets.QApplication(sys.argv)

    root = coin.SoSeparator()
    mat = coin.SoMaterial()
    mat.diffuseColor.setValue(coin.SbColor(0.8, 1, 0.8))
    mat.specularColor.setValue(coin.SbColor(1, 1, 1))
    mat.shininess.setValue(1.0)
    mat.transparency.setValue(0.9)
    root.addChild(mat)
    root.addChild(coin.SoSphere())
    root.addChild(coin.SoCube())

    viewer = quarter.QuarterWidget()
    viewer.setSceneGraph(root)

    viewer.setWindowTitle("minimal")
    viewer.show()
    sys.exit(app.exec_())
Ejemplo n.º 10
0
    def __init__(self, position=App.Vector(0, 0, 0), radius=1):
        self.trans = coin.SoTransform()
        self.trans.translation.setValue([position.x, position.y, position.z])
        self.line = coin.SoLineSet()
        self.line.numVertices.setValue(4)
        m = coin.SoMaterial()
        m.transparency.setValue(0.9)
        m.diffuseColor.setValue([0, 1, 0])
        self.coords = coin.SoCoordinate3()
        self.coords.point.set1Value(0, [0.0, 0.0, 0.0])
        self.coords.point.set1Value(1, [100.0, 0.0, 0.0])
        self.coords.point.set1Value(2, [200.0, 200.0, 0.0])
        self.coords.point.set1Value(3, [200.0, 400.0, 0.0])

        Tracker.__init__(self,
                         children=[m, self.trans, self.line, self.coords],
                         name="radiusTracker")

        self.on()
Ejemplo n.º 11
0
def simple_poly_mesh(verts, poly, color=None):
    color = color or COLORS["grey"]
    _vertices = [list(v) for v in verts]
    _polygons = []
    for pol in poly:
        _polygons += list(pol) + [-1]
    sep = coin.SoSeparator()
    vertex_property = coin.SoVertexProperty()
    face_set = coin.SoIndexedFaceSet()
    shape_hint = coin.SoShapeHints()
    shape_hint.vertexOrdering = coin.SoShapeHints.COUNTERCLOCKWISE
    shape_hint.creaseAngle = np.pi / 3
    face_mat = coin.SoMaterial()
    face_mat.diffuseColor = color
    vertex_property.vertex.setValues(0, len(_vertices), _vertices)
    face_set.coordIndex.setValues(0, len(_polygons), list(_polygons))
    vertex_property.materialBinding = coin.SoMaterialBinding.PER_VERTEX_INDEXED
    sep += [shape_hint, vertex_property, face_mat, face_set]
    return sep
Ejemplo n.º 12
0
 def __init__(self, dotted=False, scolor=None, swidth=None, face=False):
     self.origin = Vector(0, 0, 0)
     line = coin.SoLineSet()
     line.numVertices.setValue(5)
     self.coords = coin.SoCoordinate3()  # this is the coordinate
     self.coords.point.setValues(
         0, 50, [[0, 0, 0], [2, 0, 0], [2, 2, 0], [0, 2, 0], [0, 0, 0]])
     if face:
         m1 = coin.SoMaterial()
         m1.transparency.setValue(0.5)
         m1.diffuseColor.setValue([0.5, 0.5, 1.0])
         f = coin.SoIndexedFaceSet()
         f.coordIndex.setValues([0, 1, 2, 3])
         Tracker.__init__(self, dotted, scolor, swidth,
                          [self.coords, line, m1, f])
     else:
         Tracker.__init__(self, dotted, scolor, swidth, [self.coords, line])
     self.u = FreeCAD.DraftWorkingPlane.u
     self.v = FreeCAD.DraftWorkingPlane.v
Ejemplo n.º 13
0
def dim_dash(p1, p2, color, LineWidth):
    dash = coin.SoSeparator()
    pick_style = coin.SoPickStyle()
    pick_style.style.setValue(coin.SoPickStyle.UNPICKABLE) #This will disallow to be picked by mouse click
    v = coin.SoVertexProperty()
    v.vertex.set1Value(0, p1)
    v.vertex.set1Value(1, p2)
    line = coin.SoLineSet()
    line.vertexProperty = v
    style = coin.SoDrawStyle()
    style.lineWidth = LineWidth
    my_transparency = coin.SoMaterial()
    my_transparency.transparency.setValue(0.5)
    dash.addChild(pick_style)       #This will disallow to be picked by mouse click
    dash.addChild(style)
    dash.addChild(my_transparency)
    dash.addChild(color)
    dash.addChild(line)
    return dash
Ejemplo n.º 14
0
    def attach(self, vobj):
        '''
        Create Object visuals in 3D view.
        '''
        # GeoCoord Node.
        self.geo_coords = coin.SoGeoCoordinate()

        # Point group features.
        points = coin.SoPointSet()
        self.markers = coin.SoMarkerSet()
        self.color_mat = coin.SoMaterial()
        self.point_normal = coin.SoNormal()
        self.point_style = coin.SoDrawStyle()
        self.point_style.style = coin.SoDrawStyle.POINTS

        # Highlight for selection.
        highlight = coin.SoType.fromName('SoFCSelection').createInstance()
        #highlight.documentName.setValue(FreeCAD.ActiveDocument.Name)
        #highlight.objectName.setValue(vobj.Object.Name)
        #highlight.subElementName.setValue("Main")
        highlight.addChild(self.geo_coords)
        highlight.addChild(points)
        highlight.addChild(self.markers)

        # Point labels features.
        color =coin.SoBaseColor()
        self.point_labels = coin.SoSeparator()
        self.point_labels.addChild(color)

        # Point group root.
        point_root = coin.SoSeparator()
        point_root.addChild(self.point_labels)
        point_root.addChild(self.point_style)
        point_root.addChild(self.point_normal)
        point_root.addChild(self.color_mat)
        point_root.addChild(highlight)
        vobj.addDisplayMode(point_root,"Point")

        # Take features from properties.
        if vobj.Object.Points: self.onChanged(vobj,"Elevation")
        self.onChanged(vobj,"PointSize")
        self.onChanged(vobj,"PointColor")
Ejemplo n.º 15
0
    def createExtensionSoSwitch(self, ext):
        sep = coin.SoSeparator()
        pos = coin.SoTranslation()
        mat = coin.SoMaterial()
        crd = coin.SoCoordinate3()
        fce = coin.SoFaceSet()
        hnt = coin.SoShapeHints()

        if not ext is None:
            wire = ext.getWire()
            if wire:
                if isinstance(wire, (list, tuple)):
                    p0 = [p for p in wire[0].discretize(Deflection=0.02)]
                    p1 = [p for p in wire[1].discretize(Deflection=0.02)]
                    p2 = list(reversed(p1))
                    polygon = [(p.x, p.y, p.z) for p in (p0 + p2)]
                else:
                    poly = [p for p in wire.discretize(Deflection=0.02)][:-1]
                    polygon = [(p.x, p.y, p.z) for p in poly]
                crd.point.setValues(polygon)
            else:
                return None

            mat.diffuseColor = self.ColourDisabled
            mat.transparency = self.TransparencyDeselected

            hnt.faceType = coin.SoShapeHints.UNKNOWN_FACE_TYPE
            hnt.vertexOrdering = coin.SoShapeHints.CLOCKWISE

            sep.addChild(pos)
            sep.addChild(mat)
            sep.addChild(hnt)
            sep.addChild(crd)
            sep.addChild(fce)

        switch = coin.SoSwitch()
        switch.addChild(sep)
        switch.whichChild = coin.SO_SWITCH_NONE

        self.material = mat

        return switch
Ejemplo n.º 16
0
def main():
    app = QApplication(sys.argv)

    root = coin.SoSeparator()
    

    vert = coin.SoVertexShader()
    vert.sourceProgram = "vertex.glsl"
    
    frag = coin.SoFragmentShader()
    frag.sourceProgram = "frag.glsl"
    
    shaders = [vert,frag]
    pro = coin.SoShaderProgram()
    pro.shaderObject.setValues(0,len(shaders),shaders)
    
    
    mat = coin.SoMaterial()
    mat.diffuseColor.setValue(coin.SbColor(0.8, 0.8, 0.8))
    mat.specularColor.setValue(coin.SbColor(1, 1, 1))
    mat.shininess.setValue(1.0)
    mat.transparency.setValue(0.5)
    
    
    
    
    sphere = coin.SoSphere()
    sphere.radius = 1.2
    
    
    root.addChild(pro)
    root.addChild(sphere)
    root.addChild(mat)
    root.addChild(coin.SoCube())

    viewer = quarter.QuarterWidget()
    viewer.setSceneGraph(root)

    viewer.setWindowTitle("minimal")
    viewer.show()
    sys.exit(app.exec_())
Ejemplo n.º 17
0
    def attach(self, vobj):
        """Set up the scene sub-graph of the view provider."""
        # Main attributes of the Coin scenegraph
        self.mattext = coin.SoMaterial()
        self.trans = coin.SoTransform()
        self.font = coin.SoFont()
        self.text2d = coin.SoText2()  # Faces the camera always
        self.text3d = coin.SoAsciiText()  # Can be oriented in 3D space

        textdrawstyle = coin.SoDrawStyle()
        textdrawstyle.style = coin.SoDrawStyle.FILLED

        # The text string needs to be initialized to something,
        # otherwise it may crash
        self.text2d.string = self.text3d.string = "Label"
        self.text2d.justification = coin.SoText2.LEFT
        self.text3d.justification = coin.SoAsciiText.LEFT

        self.node2d = coin.SoGroup()
        self.node2d.addChild(self.trans)
        self.node2d.addChild(self.mattext)
        self.node2d.addChild(textdrawstyle)
        self.node2d.addChild(self.font)
        self.node2d.addChild(self.text2d)

        self.node3d = coin.SoGroup()
        self.node3d.addChild(self.trans)
        self.node3d.addChild(self.mattext)
        self.node3d.addChild(textdrawstyle)
        self.node3d.addChild(self.font)
        self.node3d.addChild(self.text3d)

        vobj.addDisplayMode(self.node2d, "2D text")
        vobj.addDisplayMode(self.node3d, "3D text")
        self.onChanged(vobj, "TextColor")
        self.onChanged(vobj, "FontSize")
        self.onChanged(vobj, "FontName")
        self.onChanged(vobj, "Justification")
        self.onChanged(vobj, "LineSpacing")
        self.onChanged(vobj, "ScaleMultiplier")
        self.Object = vobj.Object
Ejemplo n.º 18
0
 def __init__(self, points, dynamic=False):
     super(Object3D, self).__init__()
     self._sel_color = COLORS[self.sel_col]
     self._ovr_color = COLORS[self.ovr_col]
     self._std_color = COLORS[self.std_col]
     self.data = coin.SoCoordinate3()
     self.color = coin.SoMaterial()
     self.color.diffuseColor = self._std_color
     self.addChild(self.color)
     self.addChild(self.data)
     self.start_pos = None
     self.dynamic = dynamic
     self.on_drag = []
     self.on_drag_release = []
     self.on_drag_start = []
     self._delete = False
     self._tmp_points = None
     self.enabled = True
     if depth(points) != 2:
         raise AttributeError('depth of list should be 2')
     self.points = points
Ejemplo n.º 19
0
 def onChanged(self, vobj, prop):
     if prop == "ShowNodes":
         if hasattr(self, "nodes"):
             vobj.Annotation.removeChild(self.nodes)
             del self.nodes
         if vobj.ShowNodes:
             from pivy import coin
             self.nodes = coin.SoAnnotation()
             self.coords = coin.SoCoordinate3()
             self.mat = coin.SoMaterial()
             self.pointstyle = coin.SoDrawStyle()
             self.pointstyle.style = coin.SoDrawStyle.POINTS
             self.pointset = coin.SoType.fromName(
                 "SoBrepPointSet").createInstance()
             self.linestyle = coin.SoDrawStyle()
             self.linestyle.style = coin.SoDrawStyle.LINES
             self.lineset = coin.SoType.fromName(
                 "SoBrepEdgeSet").createInstance()
             self.nodes.addChild(self.coords)
             self.nodes.addChild(self.mat)
             self.nodes.addChild(self.pointstyle)
             self.nodes.addChild(self.pointset)
             self.nodes.addChild(self.linestyle)
             self.nodes.addChild(self.lineset)
             vobj.Annotation.addChild(self.nodes)
             self.updateData(vobj.Object, "Nodes")
             self.onChanged(vobj, "NodeColor")
             self.onChanged(vobj, "NodeLine")
             self.onChanged(vobj, "NodeSize")
     elif prop == "NodeColor":
         if hasattr(self, "mat"):
             l = vobj.NodeColor
             self.mat.diffuseColor.setValue([l[0], l[1], l[2]])
     elif prop == "NodeLine":
         if hasattr(self, "linestyle"):
             self.linestyle.lineWidth = vobj.NodeLine
     elif prop == "NodeSize":
         if hasattr(self, "pointstyle"):
             self.pointstyle.pointSize = vobj.NodeSize
     ArchComponent.ViewProviderComponent.onChanged(self, vobj, prop)
Ejemplo n.º 20
0
    def __init__(self, view):
        self.view = view

        self.pos = coin.SoTranslation()

        self.mat = coin.SoMaterial()
        self.mat.diffuseColor = coin.SbColor(
            MachinekitPreferences.hudFontColorUnhomed())
        self.mat.transparency = 0

        self.fnt = coin.SoFont()

        self.txt = coin.SoText2()
        self.txt.string = 'setValues'
        self.txt.justification = coin.SoText2.LEFT

        self.sep = coin.SoSeparator()

        self.sep.addChild(self.pos)
        self.sep.addChild(self.mat)
        self.sep.addChild(self.fnt)
        self.sep.addChild(self.txt)
Ejemplo n.º 21
0
def main():
    myWindow = SoGui.init(sys.argv[0])
    if myWindow == None: sys.exit(1)

    # add a new marker type:
    utils.addMarkerFromSvg("test.svg", "CUSTOM_MARKER",  50)

    root = coin.SoSeparator()
    color = coin.SoMaterial()
    color.diffuseColor = (1., 0., 0.)

    marker = coin.SoMarkerSet()
    marker.markerIndex = coin.SoMarkerSet.CUSTOM_MARKER
    data = coin.SoCoordinate3()
    data.point.setValue(0, 0, 0)
    data.point.setValues(0, 1, [[0., 0., 0.]])

    myCamera = coin.SoPerspectiveCamera()
    root.addChild(myCamera)
    root.addChild(coin.SoDirectionalLight())
    root.addChild(color)
    root.addChild(data)
    root.addChild(marker)
    root.addChild(data)
    root.addChild(marker)

    myRenderArea = SoGuiRenderArea(myWindow)

    myCamera.viewAll(root, myRenderArea.getViewportRegion())

    myRenderArea.setSceneGraph(root)
    myRenderArea.setTitle("Hello Cone")
    myRenderArea.show()

    SoGui.show(myWindow)
    SoGui.mainLoop()
Ejemplo n.º 22
0
    def setupCoin(self):
        from pivy import coin

        compasssep = coin.SoSeparator()

        self.transform = coin.SoTransform()

        darkNorthMaterial = coin.SoMaterial()
        darkNorthMaterial.diffuseColor.set1Value(0, 0.5, 0,
                                                 0)  # north dark color

        lightNorthMaterial = coin.SoMaterial()
        lightNorthMaterial.diffuseColor.set1Value(0, 0.9, 0,
                                                  0)  # north light color

        darkGreyMaterial = coin.SoMaterial()
        darkGreyMaterial.diffuseColor.set1Value(0, 0.9, 0.9, 0.9)  # dark color

        lightGreyMaterial = coin.SoMaterial()
        lightGreyMaterial.diffuseColor.set1Value(0, 0.5, 0.5,
                                                 0.5)  # light color

        coords = self.buildCoordinates()

        # coordIndex = [0, 1, 2, -1, 2, 3, 0, -1]

        lightColorFaceset = coin.SoIndexedFaceSet()
        lightColorCoordinateIndex = [4, 5, 6, -1, 8, 9, 10, -1, 12, 13, 14, -1]
        lightColorFaceset.coordIndex.setValues(0,
                                               len(lightColorCoordinateIndex),
                                               lightColorCoordinateIndex)

        darkColorFaceset = coin.SoIndexedFaceSet()
        darkColorCoordinateIndex = [6, 7, 4, -1, 10, 11, 8, -1, 14, 15, 12, -1]
        darkColorFaceset.coordIndex.setValues(0, len(darkColorCoordinateIndex),
                                              darkColorCoordinateIndex)

        lightNorthFaceset = coin.SoIndexedFaceSet()
        lightNorthCoordinateIndex = [2, 3, 0, -1]
        lightNorthFaceset.coordIndex.setValues(0,
                                               len(lightNorthCoordinateIndex),
                                               lightNorthCoordinateIndex)

        darkNorthFaceset = coin.SoIndexedFaceSet()
        darkNorthCoordinateIndex = [0, 1, 2, -1]
        darkNorthFaceset.coordIndex.setValues(0, len(darkNorthCoordinateIndex),
                                              darkNorthCoordinateIndex)

        self.compassswitch = coin.SoSwitch()
        self.compassswitch.whichChild = coin.SO_SWITCH_NONE
        self.compassswitch.addChild(compasssep)

        lightGreySeparator = coin.SoSeparator()
        lightGreySeparator.addChild(lightGreyMaterial)
        lightGreySeparator.addChild(lightColorFaceset)

        darkGreySeparator = coin.SoSeparator()
        darkGreySeparator.addChild(darkGreyMaterial)
        darkGreySeparator.addChild(darkColorFaceset)

        lightNorthSeparator = coin.SoSeparator()
        lightNorthSeparator.addChild(lightNorthMaterial)
        lightNorthSeparator.addChild(lightNorthFaceset)

        darkNorthSeparator = coin.SoSeparator()
        darkNorthSeparator.addChild(darkNorthMaterial)
        darkNorthSeparator.addChild(darkNorthFaceset)

        compasssep.addChild(coords)
        compasssep.addChild(self.transform)
        compasssep.addChild(lightGreySeparator)
        compasssep.addChild(darkGreySeparator)
        compasssep.addChild(lightNorthSeparator)
        compasssep.addChild(darkNorthSeparator)

        return self.compassswitch
Ejemplo n.º 23
0
du = du**2 + dv**2

colors = (du - min(du)) / (max(du) - min(du))
colors = np.array([colors,
                   np.zeros(len(colors)),
                   np.zeros(len(colors))]).T.tolist()
from pivy import coin
# # from pivy_primitives_new_new import Marker

result = coin.SoSeparator()

myBinding = coin.SoMaterialBinding()
myBinding.value = coin.SoMaterialBinding.PER_VERTEX_INDEXED
result.addChild(myBinding)

myMaterial = coin.SoMaterial()
myMaterial.diffuseColor.setValues(0, len(colors), colors)
result += myMaterial

# Define coordinates for vertices
myCoords = coin.SoCoordinate3()
myCoords.point.setValues(0, len(pos), pos.tolist())
result += myCoords

# Define the QuadMesh.
myQuadMesh = coin.SoQuadMesh()
myQuadMesh.verticesPerRow = u_dess
myQuadMesh.verticesPerColumn = v_dess

result += myQuadMesh
Ejemplo n.º 24
0
def draw_Text_Wheel(vec=App.Vector(0.0, 0.0, 0.0),
                    _color=FR_COLOR.FR_WHITE,
                    setupRotation=[0, 0, 0],
                    _rotation=[0.0, 0.0, 0.0, 0.0],
                    _Scale=[1, 1, 1],
                    LineWidth=1.0):
    try:
        TextScale = 0.04
        txtCol = coin.SoBaseColor()  # must be converted to SoBaseColor
        txtCol.rgb = _color
        txtXSo = coin.SoSeparator()  # must be converted to SoBaseColor
        txtXSo.Name = "90Degree"
        txtXTransform = coin.SoTransform()
        txtXTransform.translation.setValue(5.5, 0.0, 0.0)
        txtXTransform.rotation.setValue(coin.SbVec3f(6.0, 0.0, 0.0),
                                        math.radians(0.0))
        txtXTransform.scaleFactor.setValue(TextScale, TextScale, TextScale)
        textX = ["90.0°", ""]
        text3DX = coin.SoAsciiText()  # Draw text in the 3D world
        text3DX.string.setValues([l.encode("utf8") for l in textX if l])
        txtXSo.addChild(txtXTransform)
        txtXSo.addChild(txtCol)
        txtXSo.addChild(text3DX)

        txtXPSo = coin.SoSeparator()  # must be converted to SoBaseColor
        txtXPSo.Name = "270Degree"
        txtXPTransform = coin.SoTransform()
        txtXPTransform.translation.setValue(0.0, -5.5, 0.0)
        txtXPTransform.rotation.setValue(coin.SbVec3f(0.0, 0.0, 0.0),
                                         math.radians(0.0))
        txtXPTransform.scaleFactor.setValue(TextScale, TextScale, TextScale)
        textXP = ["270.0°", ""]
        text3DXP = coin.SoAsciiText()  # Draw text in the 3D world
        text3DXP.string.setValues([l.encode("utf8") for l in textXP if l])
        txtXPSo.addChild(txtXPTransform)
        txtXPSo.addChild(txtCol)
        txtXPSo.addChild(text3DXP)

        txtYSo = coin.SoSeparator()  # must be converted to SoBaseColor
        txtYSo.Name = "0Degree"
        txtYTransform = coin.SoTransform()
        txtYTransform.translation.setValue(0.0, 5.5, 0.0)
        txtYTransform.rotation.setValue(coin.SbVec3f(0.0, 0.0, 0.0),
                                        math.radians(00.0))
        txtYTransform.scaleFactor.setValue(TextScale, TextScale, TextScale)
        textY = ["0.0°", ""]
        text3DY = coin.SoAsciiText()  # Draw text in the 3D world
        text3DY.string.setValues([l.encode("utf8") for l in textY if l])
        txtYSo.addChild(txtYTransform)
        txtYSo.addChild(txtCol)
        txtYSo.addChild(text3DY)

        txtYPSo = coin.SoSeparator()  # must be converted to SoBaseColor
        txtYPSo.Name = "180Degree"
        txtYPTransform = coin.SoTransform()
        txtYPTransform.translation.setValue(-6.0, 0.0, 0.0)
        txtYPTransform.rotation.setValue(coin.SbVec3f(0.0, 0.0, 0.0),
                                         math.radians(0.0))
        txtYPTransform.scaleFactor.setValue(TextScale, TextScale, TextScale)
        textYP = ["180.0°", ""]
        text3DYP = coin.SoAsciiText()  # Draw text in the 3D world
        text3DYP.string.setValues([l.encode("utf8") for l in textYP if l])
        txtYPSo.addChild(txtYPTransform)
        txtYPSo.addChild(txtCol)
        txtYPSo.addChild(text3DYP)

        groupT = coin.SoSeparator()
        groupT.Name = "GroupT"
        groupT.addChild(txtXSo)
        groupT.addChild(txtXPSo)
        groupT.addChild(txtYSo)
        groupT.addChild(txtYPSo)

        txtRoot = coin.SoSeparator()
        txtRoot.Name = "AllText-coordination"
        txtrootTrans = coin.SoTransform()
        txtrootTrans.rotation.setValue(coin.SbVec3f(1.0, 0.0, 0.0),
                                       math.radians(0))
        txtRoot.addChild(txtrootTrans)
        txtRoot.addChild(groupT)

        tRadiusX = coin.SbVec3f()
        tRadiusY = coin.SbVec3f()
        tRadiusZ = coin.SbVec3f()

        transfromX = coin.SoTransform()
        transfromY = coin.SoTransform()
        transfromZ = coin.SoTransform()

        tRadiusX.setValue(1, 0, 0)
        tRadiusY.setValue(0, 1, 0)
        tRadiusZ.setValue(0, 0, 1)
        transfromX.rotation.setValue(tRadiusX, math.radians(setupRotation[0]))
        transfromY.rotation.setValue(tRadiusY, math.radians(setupRotation[1]))
        transfromZ.rotation.setValue(tRadiusZ, math.radians(setupRotation[2]))

        SoSeparatorSetupX = coin.SoSeparator()
        SoSeparatorSetupX.Name = "SetupX"
        SoSeparatorSetupY = coin.SoSeparator()
        SoSeparatorSetupY.Name = "SetupY"
        SoSeparatorSetupZ = coin.SoSeparator()
        SoSeparatorSetupZ.Name = "SetupZ"

        SoSeparatorSetupX.addChild(transfromX)
        SoSeparatorSetupX.addChild(txtRoot)

        SoSeparatorSetupY.addChild(transfromY)
        SoSeparatorSetupY.addChild(SoSeparatorSetupX)

        SoSeparatorSetupZ.addChild(transfromZ)
        SoSeparatorSetupZ.addChild(SoSeparatorSetupY)
        tempR = coin.SbVec3f()
        tempR.setValue(_rotation[0], _rotation[1], _rotation[2])
        rootTransform = coin.SoTransform()
        rootTransform.rotation.setValue(tempR, math.radians(_rotation[3]))
        rootTransform.scaleFactor.setValue(_Scale)

        material = coin.SoMaterial()
        material.diffuseColor.setValue(_color)
        material.emissiveColor.setValue(_color)
        material.transparency.setValue(0.0)

        root = coin.SoSeparator()
        root.Name = "RootText"
        transla = coin.SoTranslation()
        transla.translation.setValue([vec.x, vec.y, vec.z])

        root.addChild(material)
        col1 = coin.SoBaseColor()  # must be converted to SoBaseColor
        col1.rgb = _color

        root.addChild(rootTransform)
        root.addChild(col1)
        root.addChild(transla)
        root.addChild(SoSeparatorSetupZ)
        return root

    except Exception as err:
        App.Console.PrintError("'Wheel' Failed. "
                               "{err}\n".format(err=str(err)))
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 25
0
def draw_AllParts(vec=App.Vector(0, 0, 0),
                  Ptype: str = "",
                  _color=FR_COLOR.FR_RED,
                  setupRotation=[0, 0, 0, 0],
                  _rotation=[0, 0, 0, 0],
                  _Scale=[1, 1, 1],
                  LineWidth=1):

    style = coin.SoDrawStyle()
    style.lineWidth = LineWidth

    objectToDraw = coin.SoSeparator()
    theObject = coin.SoCylinder()
    transtheObject = coin.SoTransform()  # theObject cylinder

    tempC = coin.SbVec3f()
    if Ptype == "Center":
        objectToDraw.Name = "Center"
        tempC.setValue(1, 0, 0)
        transtheObject.rotation.setValue(tempC, math.radians(90))
        theObject.radius = 4.5
        theObject.height = 0.65
        col1 = coin.SoBaseColor()  # must be converted to SoBaseColor
        col1.rgb = FR_COLOR.FR_GLASS
    elif Ptype == "Xaxis":
        objectToDraw.Name = "Xaxis"
        tempC.setValue(0, 0, 1)
        transtheObject.rotation.setValue(tempC, math.radians(90))
        theObject.radius = 0.25
        theObject.height = 20
        col1 = coin.SoBaseColor()  # must be converted to SoBaseColor
        col1.rgb = FR_COLOR.FR_RED
    elif Ptype == "Yaxis":
        objectToDraw.Name = "Yaxis"
        tempC.setValue(0, 0, 1)
        transtheObject.rotation.setValue(tempC, math.radians(0))
        theObject.radius = 0.25
        theObject.height = 20
        col1 = coin.SoBaseColor()  # must be converted to SoBaseColor
        col1.rgb = FR_COLOR.FR_GREENYELLOW
    elif Ptype == "45axis":
        objectToDraw.Name = "45axis"
        tempC.setValue(0, 0, 1)
        transtheObject.rotation.setValue(tempC, math.radians(45))
        theObject.radius = 0.25
        theObject.height = 14
        col1 = coin.SoBaseColor()  # must be converted to SoBaseColor
        col1.rgb = FR_COLOR.FR_BLUEVIOLET
    elif Ptype == "135axis":
        objectToDraw.Name = "135Axis"
        tempC.setValue(0, 0, 1)
        transtheObject.rotation.setValue(tempC, math.radians(135))
        theObject.radius = 0.25
        theObject.height = 14
        col1 = coin.SoBaseColor()  # must be converted to SoBaseColor
        col1.rgb = FR_COLOR.FR_ORANGE

    objectToDraw.addChild(col1)
    objectToDraw.addChild(transtheObject)
    objectToDraw.addChild(theObject)

    tRadiusX = coin.SbVec3f()
    tRadiusY = coin.SbVec3f()
    tRadiusZ = coin.SbVec3f()

    tRadiusX.setValue(1, 0, 0)
    tRadiusY.setValue(0, 1, 0)
    tRadiusZ.setValue(0, 0, 1)

    tempTransform_x = coin.SoTransform()
    tempTransform_y = coin.SoTransform()
    tempTransform_z = coin.SoTransform()

    tempTransform_x.rotation.setValue(tRadiusX, math.radians(setupRotation[0]))
    tempTransform_y.rotation.setValue(tRadiusY, math.radians(setupRotation[1]))
    tempTransform_z.rotation.setValue(tRadiusZ, math.radians(setupRotation[2]))

    SoSeparatorSetupX = coin.SoSeparator()
    SoSeparatorSetupY = coin.SoSeparator()
    SoSeparatorSetupZ = coin.SoSeparator()

    SoSeparatorSetupX.addChild(tempTransform_x)
    SoSeparatorSetupX.addChild(objectToDraw)

    SoSeparatorSetupY.addChild(tempTransform_y)
    SoSeparatorSetupY.addChild(SoSeparatorSetupX)

    SoSeparatorSetupZ.addChild(tempTransform_z)
    SoSeparatorSetupZ.addChild(SoSeparatorSetupY)

    tempR = coin.SbVec3f()
    tempR.setValue(_rotation[0], _rotation[1], _rotation[2])

    rootTransform = coin.SoTransform()
    rootTransform.rotation.setValue(tempR, math.radians(_rotation[3]))
    rootTransform.scaleFactor.setValue(_Scale)
    root = coin.SoSeparator()
    root.Name = "RootAxisDrawing"
    transla = coin.SoTranslation()
    transla.translation.setValue([vec.x, vec.y, vec.z])

    material = coin.SoMaterial()
    if (Ptype == "Center"):
        material.transparency.setValue(0.80)
    else:
        material.transparency.setValue(0.0)
    material.diffuseColor.setValue(_color)
    material.emissiveColor.setValue(_color)

    root.addChild(transla)
    root.addChild(rootTransform)
    #root.addChild(material)
    root.addChild(SoSeparatorSetupZ)
    return root
Ejemplo n.º 26
0
    def attach(self, vobj):
        """Respond to created/restored object event (callback).

        Args:
            vobj -- Related ViewProviderDocumentObject
        """
        # pylint: disable=attribute-defined-outside-init
        self.fpo = vobj.Object

        # Here we create a coin representation
        self.coin = SimpleNamespace()
        scene = Gui.ActiveDocument.ActiveView.getSceneGraph()

        size = 5
        height = 10

        self.coin.geometry = coin.SoSwitch()
        self.coin.node = coin.SoSeparator()
        self.coin.transform = coin.SoTransform()
        self.coin.node.addChild(self.coin.transform)
        self.coin.material = coin.SoMaterial()
        self.coin.node.addChild(self.coin.material)
        self.coin.drawstyle = coin.SoDrawStyle()
        self.coin.drawstyle.style = coin.SoDrawStyle.LINES
        self.coin.drawstyle.lineWidth = 1
        self.coin.drawstyle.linePattern = 0xaaaa
        self.coin.node.addChild(self.coin.drawstyle)
        self.coin.coords = coin.SoCoordinate3()
        self.coin.coords.point.setValues(
            0,
            15,
            [
                (-size * 2, +size, 0),  # Front rectangle
                (+size * 2, +size, 0),  # Front rectangle
                (+size * 2, -size, 0),  # Front rectangle
                (-size * 2, -size, 0),  # Front rectangle
                (-size * 2, +size, 0),  # Front rectangle
                (-size * 2, +size, 0),  # Left triangle
                (0, 0, height * 2),  # Left triangle
                (-size * 2, -size, 0),  # Left triangle
                (+size * 2, +size, 0),  # Right triangle
                (0, 0, height * 2),  # Right triangle
                (+size * 2, -size, 0),  # Right triangle
                (-size * 1.8, 1.2 * +size, 0),  # Up triangle (arrow)
                (0, 1.4 * +size, 0),  # Up triangle (arrow)
                (+size * 1.8, 1.2 * +size, 0),  # Up triangle (arrow)
                (-size * 1.8, 1.2 * +size, 0)
            ]  # Up triangle (arrow)
        )
        self.coin.node.addChild(self.coin.coords)
        self.coin.lineset = coin.SoLineSet()
        self.coin.lineset.numVertices.setValues(0, 4, [5, 3, 3, 4])
        self.coin.node.addChild(self.coin.lineset)

        self.coin.geometry.addChild(self.coin.node)
        self.coin.geometry.whichChild.setValue(coin.SO_SWITCH_ALL)
        scene.addChild(self.coin.geometry)  # Insert back
        vobj.addDisplayMode(self.coin.geometry, "Shaded")

        # Update coin elements with actual object properties
        self._update_placement(self.fpo)
Ejemplo n.º 27
0
    def rays(self, escaping_len=.2, max_rays=None, resolution=None):
        """
		Method to draw the rays to a Coin3D scenegraph. Needs to be called after a raytrace has been peroformed.
		"""

        tree = self.sim.tree
        no = coin.SoSeparator()

        # loop through the reflection sequences?
        co = []  # regular lines
        pos = []  # 2D level text position
        text = []  # 2D level text
        hist = {}  # ray histories, for highlighted rays

        lentree = tree.num_bunds()

        for level in xrange(lentree):

            start_rays = tree[level]
            if max_rays == None:
                selector = None
            elif level == 0:
                ordered_parents = tree.ordered_parents()
                selector = N.arange(max_rays)
            else:
                selector = N.nonzero(N.in1d(start_rays.get_parents(),
                                            selector))[0]

            sv = start_rays.get_vertices(selector)
            sd = start_rays.get_directions(selector)
            se = start_rays.get_energy(selector)
            rays = len(se)

            if level == tree.num_bunds() - 1:
                parents = []
            else:
                end_rays = tree[level + 1]
                ev = end_rays.get_vertices()
                parents = end_rays.get_parents()

            # loop through individual rays in this bundle
            for ray in xrange(rays):
                if se[ray] <= self.sim.minener:
                    # ignore rays with starting energy smaller than energy cutoff
                    continue

                if ray in parents:
                    # Has a hit on another surface
                    first_childs = N.nonzero(ray == parents)[0]
                    c1 = sv[:, ray]
                    for cs in first_childs:
                        c2 = ev[:, cs]
                        co += [(c1[0], c1[1], c1[2]), (c2[0], c2[1], c2[2])]

                else:
                    l = escaping_len
                    #if level == 0:
                    #	l = 0.1
                    # Escaping ray.
                    c1 = sv[:, ray]
                    c2 = sv[:, ray] + sd[:, ray] * l
                    co += [(c1[0], c1[1], c1[2]), (c2[0], c2[1], c2[2])]

            color = (1, 1 - float(level) / lentree, 0.5)

            no1 = coin.SoSeparator()

            ma1 = coin.SoMaterial()
            ma1.diffuseColor = color
            no1.addChild(ma1)

            ds = coin.SoDrawStyle()
            ds.style = ds.LINES
            ds.lineWidth = 2
            no1.addChild(ds)

            coor = coin.SoCoordinate3()
            coor.point.setValues(0, len(co), co)
            no1.addChild(coor)

            ls = coin.SoLineSet()
            ind = [2] * (len(co) / 2)
            ls.numVertices.setValues(0, len(ind), ind)
            no1.addChild(ls)

            no.addChild(no1)

        self.r.addChild(no)
Ejemplo n.º 28
0
    def __init__(self):
        # self.space = 1
        self.space = Draft.getParam("gridSpacing")
        # self.mainlines = 10
        self.mainlines = Draft.getParam("gridEvery")
        self.numlines = 100
        col = [0.2, 0.2, 0.3]

        pick = coin.SoPickStyle()
        pick.style.setValue(coin.SoPickStyle.UNPICKABLE)

        self.trans = coin.SoTransform()
        self.trans.translation.setValue([0, 0, 0])

        bound = (self.numlines / 2) * self.space
        pts = []
        mpts = []
        apts = []
        for i in range(self.numlines + 1):
            curr = -bound + i * self.space
            z = 0
            if i / float(self.mainlines) == i / self.mainlines:
                if round(curr, 4) == 0:
                    apts.extend([[-bound, curr, z], [bound, curr, z]])
                    apts.extend([[curr, -bound, z], [curr, bound, z]])
                else:
                    mpts.extend([[-bound, curr, z], [bound, curr, z]])
                    mpts.extend([[curr, -bound, z], [curr, bound, z]])
            else:
                pts.extend([[-bound, curr, z], [bound, curr, z]])
                pts.extend([[curr, -bound, z], [curr, bound, z]])
        idx = []
        midx = []
        aidx = []
        for p in range(0, len(pts), 2):
            idx.append(2)
        for mp in range(0, len(mpts), 2):
            midx.append(2)
        for ap in range(0, len(apts), 2):
            aidx.append(2)

        mat1 = coin.SoMaterial()
        mat1.transparency.setValue(0.7)
        mat1.diffuseColor.setValue(col)
        self.coords1 = coin.SoCoordinate3()
        self.coords1.point.setValues(pts)
        lines1 = coin.SoLineSet()
        lines1.numVertices.setValues(idx)
        mat2 = coin.SoMaterial()
        mat2.transparency.setValue(0.3)
        mat2.diffuseColor.setValue(col)
        self.coords2 = coin.SoCoordinate3()
        self.coords2.point.setValues(mpts)
        lines2 = coin.SoLineSet()
        lines2.numVertices.setValues(midx)
        mat3 = coin.SoMaterial()
        mat3.transparency.setValue(0)
        mat3.diffuseColor.setValue(col)
        self.coords3 = coin.SoCoordinate3()
        self.coords3.point.setValues(apts)
        lines3 = coin.SoLineSet()
        lines3.numVertices.setValues(aidx)
        s = coin.SoSeparator()
        s.addChild(pick)
        s.addChild(self.trans)
        s.addChild(mat1)
        s.addChild(self.coords1)
        s.addChild(lines1)
        s.addChild(mat2)
        s.addChild(self.coords2)
        s.addChild(lines2)
        s.addChild(mat3)
        s.addChild(self.coords3)
        s.addChild(lines3)
        Tracker.__init__(self, children=[s])
        self.update()
Ejemplo n.º 29
0
    def createExtensionSoSwitch(self, ext):
        if not ext:
            return None

        sep = coin.SoSeparator()
        pos = coin.SoTranslation()
        mat = coin.SoMaterial()
        crd = coin.SoCoordinate3()
        fce = coin.SoFaceSet()
        hnt = coin.SoShapeHints()
        numVert = list()  # track number of vertices in each polygon face

        try:
            wire = ext.getWire()
        except FreeCAD.Base.FreeCADError:
            wire = None

        if not wire:
            return None

        if isinstance(wire, (list, tuple)):
            p0 = [p for p in wire[0].discretize(Deflection=0.02)]
            p1 = [p for p in wire[1].discretize(Deflection=0.02)]
            p2 = list(reversed(p1))
            polygon = [(p.x, p.y, p.z) for p in (p0 + p2)]
        else:
            if ext.extFaces:
                # Create polygon for each extension face in compound extensions
                allPolys = list()
                extFaces = ext.getExtensionFaces(wire)
                for f in extFaces:
                    pCnt = 0
                    wCnt = 0
                    for w in f.Wires:
                        if wCnt == 0:
                            poly = [p for p in w.discretize(Deflection=0.01)]
                        else:
                            poly = [p for p in w.discretize(Deflection=0.01)
                                    ][:-1]
                        pCnt += len(poly)
                        allPolys.extend(poly)
                    numVert.append(pCnt)
                polygon = [(p.x, p.y, p.z) for p in allPolys]
            else:
                # poly = [p for p in wire.discretize(Deflection=0.02)][:-1]
                poly = [p for p in wire.discretize(Deflection=0.02)]
                polygon = [(p.x, p.y, p.z) for p in poly]
        crd.point.setValues(polygon)

        mat.diffuseColor = self.ColourDisabled
        mat.transparency = self.TransparencyDeselected

        hnt.faceType = coin.SoShapeHints.UNKNOWN_FACE_TYPE
        hnt.vertexOrdering = coin.SoShapeHints.CLOCKWISE

        if numVert:
            # Transfer vertex counts for polygon faces
            fce.numVertices.setValues(tuple(numVert))

        sep.addChild(pos)
        sep.addChild(mat)
        sep.addChild(hnt)
        sep.addChild(crd)
        sep.addChild(fce)

        # Finalize SoSwitch
        switch = coin.SoSwitch()
        switch.addChild(sep)
        switch.whichChild = coin.SO_SWITCH_NONE

        self.material = mat

        return switch
Ejemplo n.º 30
0
    def attach(self, vobj):
        '''
        Create Object visuals in 3D view.
        '''
        # GeoCoords Node.
        self.geo_coords = coin.SoGeoCoordinate()

        # Surface features.
        self.triangles = coin.SoIndexedFaceSet()
        shape_hints = coin.SoShapeHints()
        shape_hints.vertex_ordering = coin.SoShapeHints.COUNTERCLOCKWISE
        self.mat_color = coin.SoMaterial()
        mat_binding = coin.SoMaterialBinding()
        mat_binding.value = coin.SoMaterialBinding.OVERALL
        edge_color = coin.SoBaseColor()
        edge_color.rgb = (0.5, 0.5, 0.5)
        offset = coin.SoPolygonOffset()

        # Line style.
        line_style = coin.SoDrawStyle()
        line_style.style = coin.SoDrawStyle.LINES
        line_style.lineWidth = 2

        # Contour features.
        cont_color = coin.SoBaseColor()
        cont_color.rgb = (1, 1, 0)
        self.cont_coords = coin.SoGeoCoordinate()
        self.cont_lines = coin.SoLineSet()

        # Contour root.
        contours = coin.SoSeparator()
        contours.addChild(cont_color)
        contours.addChild(line_style)
        contours.addChild(self.cont_coords)
        contours.addChild(self.cont_lines)

        # Face root.
        faces = coin.SoSeparator()
        faces.addChild(shape_hints)
        faces.addChild(self.mat_color)
        faces.addChild(mat_binding)
        faces.addChild(self.geo_coords)
        faces.addChild(self.triangles)

        # Highlight for selection.
        highlight = coin.SoType.fromName('SoFCSelection').createInstance()
        #highlight.documentName.setValue(FreeCAD.ActiveDocument.Name)
        #highlight.objectName.setValue(vobj.Object.Name)
        #highlight.subElementName.setValue("Main")
        highlight.addChild(edge_color)
        highlight.addChild(line_style)
        highlight.addChild(self.geo_coords)
        highlight.addChild(self.triangles)

        # Surface root.
        surface_root = coin.SoSeparator()
        surface_root.addChild(contours)
        surface_root.addChild(offset)
        surface_root.addChild(faces)
        surface_root.addChild(offset)
        surface_root.addChild(highlight)
        vobj.addDisplayMode(surface_root,"Surface")

        # Take features from properties.
        self.onChanged(vobj,"TriangleColor")