当前位置: 首页>>代码示例>>Python>>正文


Python Scene.render方法代码示例

本文整理汇总了Python中scene.Scene.render方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.render方法的具体用法?Python Scene.render怎么用?Python Scene.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scene.Scene的用法示例。


在下文中一共展示了Scene.render方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import render [as 别名]
    def render(self):
        scene = Scene(self.width, self.height)

        start = time.time()

        for x, y, pixel in scene.render():
            self.surface.set_at((x, y), pixel)

        end = time.time()
        print('Rendered in {0}s'.format(end - start))
开发者ID:bakerj76,项目名称:march,代码行数:12,代码来源:march.py

示例2: test_empty_scene

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import render [as 别名]
 def test_empty_scene(self):
     s = Scene()
     img = s.render()
     h.assert_equal(img.getpixel((0, 0)), (0, 0, 0, 0))
开发者ID:nickstenning,项目名称:scene,代码行数:6,代码来源:test_scene.py

示例3: Viewer

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import render [as 别名]
class Viewer(object):
    def __init__(self):
        """ Initialize the viewer. """
        self.init_interface()
        self.init_opengl()
        self.init_scene()
        self.init_interaction()
        init_primitives()

    def init_interface(self):
        """ initialize the window and register the render function """
        glutInit()
        glutInitWindowSize(640, 480)
        glutCreateWindow("3D Modeller")
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
        glutDisplayFunc(self.render)

    def init_interaction(self):
        """ init user interaction and callbacks """
        self.interaction = Interaction()
        self.interaction.register_callback('pick', self.pick)
        self.interaction.register_callback('move', self.move)
        self.interaction.register_callback('place', self.place)
        self.interaction.register_callback('rotate_color', self.rotate_color)
        self.interaction.register_callback('scale', self.scale)

    def init_scene(self):
        """ initialize the scene object and initial scene """
        self.scene = Scene()
        self.initial_scene()

    def init_opengl(self):
        """ initialize the opengl settings to render the scene """
        self.inverseModelView = numpy.identity(4)
        self.modelView = numpy.identity(4)

        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)

        glEnable(GL_LIGHT0)
        glLightfv(GL_LIGHT0, GL_POSITION, GLfloat_4(0, 0, 1, 0))
        glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, GLfloat_3(0, 0, -1))

        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
        glEnable(GL_COLOR_MATERIAL)
        glClearColor(1.0, 1.0, 1.0, 0.0)

    def main_loop(self):
        glutMainLoop()

    def render(self):
        """ The render pass for the scene """
        self.init_view()

        # Enable lighting and color
        glEnable(GL_LIGHTING)

        glClearColor(0.4, 0.4, 0.4, 0.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Load the modelview matrix from the current state of the trackball
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        loc = self.interaction.translation
        glTranslated(-loc[0], -loc[1], -loc[2])
        glMultMatrixf(self.interaction.trackball.matrix)

        # store the inverse of the current modelview.
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))

        # render the scene. This will call the render function for each object in the scene
        self.scene.render()

        # draw the grid
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()

        # flush the buffers so that the scene can be drawn
        glFlush()

    def init_view(self):
        """ initialize the projection matrix """
        xSize, ySize = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)
        aspect_ratio = float(xSize) / float(ySize)

        # load the projection matrix. Always the same
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        glViewport(0, 0, xSize, ySize)
        gluPerspective(70, aspect_ratio, 0.1, 1000.0)
        glTranslated(0, 0, -15)

    def initial_scene(self):
#.........这里部分代码省略.........
开发者ID:343829084,项目名称:500lines,代码行数:103,代码来源:viewer.py

示例4: Vector

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import render [as 别名]
    blue = Vector(0, 0, 1)
    yellow = Vector(1, 1, 0)
    grey = Vector(.5, .5, .5)

    # Materials
    redSurface = Material(red)
    greenSurface = Material(green)
    blueSurface = Material(blue)
    greySurface = Material(grey)
    yellowSurface = Material(yellow)
    checkerboard = CheckerboardMaterial() 

    # Add objects to scene
    scene.addObject(Sphere(Point(2.5, 3, -10), RADIUS, redSurface))
    scene.addObject(Sphere(Point(-2.5, 3, -10), RADIUS, greenSurface))
    scene.addObject(Sphere(Point(0, 7, -10), RADIUS, blueSurface))
    scene.addObject(Plane(Point(0, 0, 0), Vector(0, 1, 0), checkerboard))# greySurface))
    scene.addObject(Triangle(Point(2.5, 3, -10), Point(-2.5, 3, -10), Point(0, 7, -10), yellowSurface))

    scene.addLight(Light(Point(30, 30, 10)))

    scene.setUpCamera(Point(0,2,10), Vector(0,1,0), Point(0,3,0), FIELDOFVIEW)

    # and render
    scene.render(image, level=recursionLevel)
    
    print 'Rendering Time: %d seconds' % (time.time() - beginTime)
    
    image.show()
    image.save('out_image.png', 'PNG')
开发者ID:eyesfocus,项目名称:mi-hsrm-cg,代码行数:32,代码来源:raytracer.py

示例5: Controller

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import render [as 别名]

#.........这里部分代码省略.........

    def slotColorChanged(self, color):
        shapes = self.selectedShapes()
        if shapes:
            for shape in shapes:
                shape.settings.setColor(color)
        else:
            self.scene.newShapeSettings.setColor(color)

    def slotThicknessChanged(self, thickness):
        shapes = self.selectedShapes()
        if shapes:
            for shape in shapes:
                shape.settings.setThickness(thickness)
        else:
            self.scene.newShapeSettings.setThickness(thickness)

    def show(self):
        self.window.show()


    def open(self):
        name = QFileDialog.getOpenFileName(self.window, self.tr("Open Image"))
        if name.isEmpty():
            return
        self.load(name)


    def grabScreenshot(self):
        pos = self.window.pos()
        self.window.hide()
        try:
            pix = grab.showDialog()
            if pix is not None:
                self.setPixmap(pix)
        finally:
            self.window.show()
            self.window.move(pos)
            KWindowSystem.forceActiveWindow(self.window.winId())


    def save(self):
        name = QFileDialog.getSaveFileName(self.window, self.tr("Save Image as"))
        if name.isEmpty():
            return

        image = self.imageFromScene()
        ok = image.save(name)
        if not ok:
            KMessageBox.error(self.window, self.tr("Failed to save image as %1").arg(name));


    def imageFromScene(self):
        # Hide elements we don't want to show
        selection = self.scene.selectedItems()
        self.scene.clearSelection()
        self.pixmapItem.setHandlesVisible(False)

        # Render
        rect = self.scene.itemsBoundingRect()
        image = QImage(int(rect.width()), int(rect.height()), QImage.Format_ARGB32)
        image.fill(Qt.transparent)
        painter = QPainter(image)
        painter.setRenderHint(QPainter.Antialiasing)
        self.scene.render(painter, QRectF(image.rect()), rect)
        painter.end()

        # Restore hidden elements
        for item in selection:
            item.setSelected(True)
        self.pixmapItem.setHandlesVisible(True)

        return image


    def load(self, fileName):
        self.setPixmap(QPixmap(fileName))


    def setPixmap(self, pix):
        self.pixmapItem.setPixmap(pix)
        self.scene.setSceneRect(QRectF(pix.rect()))


    def slotToolChanged(self, action):
        toolFromAction = {
            self.ui.actionBubble: AddBubbleTool,
            self.ui.actionLine: AddLineTool,
            }

        klass = toolFromAction.get(action)
        if klass:
            tool = klass(self.scene)
        else:
            tool = None
        self.scene.setTool(tool)

    def deleteItems(self):
        for shape in self.selectedShapes():
            self.scene.removeShape(shape)
开发者ID:agateau,项目名称:annot8,代码行数:104,代码来源:controller.py

示例6: Renderer

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import render [as 别名]
class Renderer(object):
    def __init__(self):
        self.scene = Scene()
        self.scene.add(Snowman())
        sn2 = Snowman()
        sn3 = Snowman()
        sn2.x = 3
        sn3.z = 2
        self.scene.add(sn2)
        self.scene.add(sn3)
        self.scene.camera.translate(0, -.5, -4)

    def setup(self):
        """Set up the OpenGL environment."""
        # Initialize the drawing environment (create main windows, etc)
        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
        glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT)
        glutCreateWindow(name)

        glShadeModel(GL_SMOOTH)

        glClearDepth(1.0)
        glDepthFunc(GL_LESS)                                # The Type Of Depth Test To Do
        glEnable(GL_DEPTH_TEST)                             # Enables Depth Testing
        glShadeModel(GL_SMOOTH)                             # Enables Smooth Color Shading

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()                                    # Reset The Projection Matrix

        # Calculate The Aspect Ratio Of The Window
        gluPerspective(45.0, float(WINDOW_WIDTH)/float(WINDOW_HEIGHT), 0.1, 100.0)

        glMatrixMode(GL_MODELVIEW)

        # Set up keyboard listeners.
        glutKeyboardFunc(self.on_key)

    def start(self):
        """Begin the render."""
        glutDisplayFunc(self.render)
        glutMainLoop()

    def render(self):
        """Render the scene."""
        self.scene.render()

    def on_key(self, key, x, y):
        """Handle a keypress."""
        print "Received", key
        if key == "a":
            self.scene.camera.translate(x=0.05)
        elif key == "d":
            self.scene.camera.translate(x=-0.05)
        elif key == "s":
            self.scene.camera.translate(y=0.05)
        elif key == "w":
            self.scene.camera.translate(y=-0.05)
        elif key == "e":
            self.scene.camera.translate(z=0.05)
        elif key == "q":
            self.scene.camera.translate(z=-0.05)
        elif key == "j":
            self.scene.camera.rotate(y=-5)
        elif key == "l":
            self.scene.camera.rotate(y=5)
        elif key == "k":
            self.scene.camera.rotate(x=5)
        elif key == "i":
            self.scene.camera.rotate(x=-5)
        elif key == "u":
            self.scene.camera.rotate(z=5)
        elif key == "o":
            self.scene.camera.rotate(z=-5)

        self.render()
开发者ID:nickpascucci,项目名称:AppDesign,代码行数:78,代码来源:driver.py

示例7: int

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import render [as 别名]
import time
import sys

if __name__=="__main__":
    #import rpdb2; rpdb2.start_embedded_debugger('1234')
    # do raycaster things
    objectlist = [objects.CollidableSphere(position=euclid.Point3(10.,-5.,5.), radius=3.,
                     color=(255, 215, 0), roughness=0.8),
                  objects.CollidableSphere(position=euclid.Point3(6.,0.,0.), radius=1.,
                     color=(0, 255, 0), roughness=0.99),
                  objects.CollidableSphere(position=euclid.Point3(20.,5.,0.), radius=11.,
                     color=(188, 188, 177), roughness=0.8),
                  objects.CollidablePlane(origin=euclid.Point3(10.,0.,-10.)
                    ,normal=euclid.Vector3(.5, 0.,-1.),
                    roughness=0.8)]
    lights = [objects.Light(position=euclid.Point3(0.,0.,0.)),
    objects.Light(position=euclid.Point3(10.,0.,5.)),
    objects.Light(position=euclid.Point3(-50.,0.,55.))]
    try:
        i,j = sys.argv[1].split(",")
        i,j = int(i), int(j)
    except:
        i,j = 256, 256
    camera = Camera(imageDim=(i,j),focallength=3., screenDim=(16,9))
    myScene = Scene(camera=camera, objects=objectlist, lights=lights)
    myScene.skycolor = (90, 90, 255)
    starttime = time.clock()
    myScene.render(depth=3)
    endtime = time.clock()
    print("Took %.2f seconds for rendering a %dx%d image." % (endtime - starttime,
        camera.imagew, camera.imageh))
开发者ID:Skyyrunner,项目名称:raycaster3,代码行数:33,代码来源:raycaster.py


注:本文中的scene.Scene.render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。