Exemple #1
0
    def Activated(self):
        from pivy import sogui
        from pivy import coin

        global myRenderArea
        if myRenderArea == None:
            root = coin.SoSeparator()
            myCamera = coin.SoPerspectiveCamera()
            myMaterial = coin.SoMaterial()
            root.addChild(myCamera)
            root.addChild(coin.SoDirectionalLight())
            #myMaterial.diffuseColor = (1.0, 0.0, 0.0)   # Red
            root.addChild(myMaterial)
            root.addChild(coin.SoCone())

            # Create a renderArea in which to see our scene graph.
            # The render area will appear within the main window.
            myRenderArea = sogui.SoGuiRenderArea(FreeCADGui.getMainWindow())

            # Make myCamera see everything.
            myCamera.viewAll(root, myRenderArea.getViewportRegion())

            # Put our scene in myRenderArea, change the title
            myRenderArea.setSceneGraph(root)
            myRenderArea.setTitle("Hello Cone")
        myRenderArea.show()
Exemple #2
0
    def setSceneGraph(self, node):
        if node and self.scene == node:
            return

        camera = None
        superscene = None
        viewall = False

        if node:
            self.scene = node
            self.scene.ref()

            superscene = coin.SoSeparator()
            superscene.addChild(coin.SoDepthBuffer())
            superscene.addChild(self.headlight)

            camera = self.searchForCamera(node)
            if not camera:
                camera = coin.SoPerspectiveCamera()
                superscene.addChild(camera)
                viewall = True

            superscene.addChild(node)

        self.soeventmanager.setSceneGraph(superscene)
        self.sorendermanager.setSceneGraph(superscene)
        self.soeventmanager.setCamera(camera)
        self.sorendermanager.setCamera(camera)

        if viewall:
            self.viewAll()

        if superscene:
            superscene.touch()
Exemple #3
0
def render(outputfile,scene=None,camera=None,zoom=False,width=400,height=300,background=(1.0,1.0,1.0)):

    """render(outputfile,scene=None,camera=None,zoom=False,width=400,height=300,background=(1.0,1.0,1.0)):
    Renders a PNG image of given width and height and background color from the given coin scene, using
    the given coin camera (ortho or perspective). If zoom is True the camera will be resized to fit all
    objects. The outputfile must be a file path to save a png image."""

    # On Linux, the X server must have indirect rendering enabled in order to be able to do offline
    # PNG rendering. Unfortunately, this is turned off by default on most recent distros. The easiest
    # way I found is to edit (or create if inexistant) /etc/X11/xorg.conf and add this:
    #
    # Section "ServerFlags"
    #    Option "AllowIndirectGLX" "on"
    #    Option "IndirectGLX" "on"
    # EndSection
    #
    # But there are other ways, google of GLX indirect rendering

    if isinstance(camera,str):
        camera = getCoinCamera(camera)

    print("Starting offline renderer")
    # build an offline scene root separator
    root = coin.SoSeparator()
    # add one light (mandatory)
    light = coin.SoDirectionalLight()
    root.addChild(light)
    if not camera:
        # create a default camera if none was given
        camera = coin.SoPerspectiveCamera()
        cameraRotation = coin.SbRotation.identity()
        cameraRotation *= coin.SbRotation(coin.SbVec3f(1,0,0),-0.4)
        cameraRotation *= coin.SbRotation(coin.SbVec3f(0,1,0), 0.4)
        camera.orientation = cameraRotation
        # make sure all objects get in the view later
        zoom = True
    root.addChild(camera)
    if scene:
        root.addChild(scene)
    else:
        # no scene was given, add a simple cube
        cube = coin.SoCube()
        root.addChild(cube)
    vpRegion = coin.SbViewportRegion(width,height)
    if zoom:
        camera.viewAll(root,vpRegion)
    print("Creating viewport")
    offscreenRenderer = coin.SoOffscreenRenderer(vpRegion)
    offscreenRenderer.setBackgroundColor(coin.SbColor(background[0],background[1],background[2]))
    print("Ready to render")
    # ref ensures that the node will not be garbage-collected during rendering
    root.ref()
    ok = offscreenRenderer.render(root)
    root.unref()
    if ok:
        offscreenRenderer.writeToFile(outputfile,"PNG")
        print("Rendering",outputfile,"done")
    else:
        print("Error rendering image")
Exemple #4
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()
Exemple #5
0
from __future__ import print_function
import sys
from pivy import coin
from pivy.gui import soqt
# import shiboken if you want to use the widget within qt

myWindow = soqt.SoQt.init(sys.argv[0])
print(myWindow)
scene = coin.SoSeparator()
cam = coin.SoPerspectiveCamera()
cam.position = (0, 0, 4)
light = coin.SoLightModel()
light.model = coin.SoLightModel.BASE_COLOR
scene += light, cam, coin.SoCone()
viewer = soqt.SoQtRenderArea(myWindow)
viewer.setSceneGraph(scene)
viewer.setTitle("Examiner Viewer")
viewer.show()
soqt.SoQt.show(myWindow)
soqt.SoQt.mainLoop()