def __init__(self):
        configuration = self.Configuration()
        configuration.title = "Magnum Python Primitives + SceneGraph Example"
        Application.__init__(self, configuration)

        gl.Renderer.enable(gl.Renderer.Feature.DEPTH_TEST)
        gl.Renderer.enable(gl.Renderer.Feature.FACE_CULLING)

        # Scene and drawables
        self._scene = Scene3D()
        self._drawables = scenegraph.DrawableGroup3D()

        # Camera setup
        camera_object = Object3D(parent=self._scene)
        camera_object.translate(Vector3.z_axis(10.0))
        self._camera = scenegraph.Camera3D(camera_object)
        self._camera.projection_matrix = Matrix4.perspective_projection(
            fov=Deg(35.0), aspect_ratio=1.33333, near=0.01, far=100.0)

        # Cube object and drawable
        self._cube = Object3D(parent=self._scene)
        self._cube.rotate_y(Deg(40.0))
        self._cube.rotate_x(Deg(30.0))
        self._cube_drawable = CubeDrawable(
            self._cube, self._drawables,
            meshtools.compile(primitives.cube_solid()), shaders.PhongGL(),
            Color3.from_hsv(Deg(35.0), 1.0, 1.0))

        self._previous_mouse_position = Vector2i()
Пример #2
0
    def __init__(self):
        configuration = self.Configuration()
        configuration.title = "Magnum Python Textured Triangle Example"
        Application.__init__(self, configuration)

        buffer = gl.Buffer()
        buffer.set_data(array.array('f', [
            -0.5, -0.5, 0.0, 0.0,
             0.5, -0.5, 1.0, 0.0,
             0.0,  0.5, 0.5, 1.0
        ]))

        self._mesh = gl.Mesh()
        self._mesh.count = 3
        self._mesh.add_vertex_buffer(buffer, 0, 4*4,
            TexturedTriangleShader.POSITION)
        self._mesh.add_vertex_buffer(buffer, 2*4, 4*4,
            TexturedTriangleShader.TEXTURE_COORDINATES)

        importer = trade.ImporterManager().load_and_instantiate('TgaImporter')
        importer.open_file(os.path.join(os.path.dirname(__file__),
                                        '../textured-triangle/stone.tga'))
        image = importer.image2d(0)

        self._texture = gl.Texture2D()
        self._texture.wrapping = gl.SamplerWrapping.CLAMP_TO_EDGE
        self._texture.minification_filter = gl.SamplerFilter.LINEAR
        self._texture.magnification_filter = gl.SamplerFilter.LINEAR
        self._texture.set_storage(1, gl.TextureFormat.RGB8, image.size)
        self._texture.set_sub_image(0, Vector2i(), image)

        # or self._shader = shaders.Flat2D(shaders.Flat2D.Flags.TEXTURED)
        self._shader = TexturedTriangleShader()
Пример #3
0
    def __init__(self):
        configuration = self.Configuration()
        configuration.title = "Magnum Python Viewer Example"
        Application.__init__(self, configuration)

        gl.Renderer.enable(gl.Renderer.Feature.DEPTH_TEST)
        gl.Renderer.enable(gl.Renderer.Feature.FACE_CULLING)

        # Scene and drawables
        self._scene = Scene3D()
        self._drawables = scenegraph.DrawableGroup3D()

        # Every scene needs a camera
        camera_object = Object3D(parent=self._scene)
        camera_object.translate(Vector3.z_axis(5.0))
        self._camera = scenegraph.Camera3D(camera_object)
        self._camera.aspect_ratio_policy = scenegraph.AspectRatioPolicy.EXTEND
        self._camera.projection_matrix = Matrix4.perspective_projection(
            fov=Deg(35.0), aspect_ratio=1.0, near=0.01, far=100.0)
        self._camera.viewport = self.framebuffer_size

        # Base object, parent of all (for easy manipulation)
        self._manipulator = Object3D(parent=self._scene)

        # Setup renderer and shader defaults
        gl.Renderer.enable(gl.Renderer.Feature.DEPTH_TEST)
        gl.Renderer.enable(gl.Renderer.Feature.FACE_CULLING)
        colored_shader = shaders.Phong()
        colored_shader.ambient_color = Color3(0.06667)
        colored_shader.shininess = 80.0

        # Import Suzanne head and eyes (yes, sorry, it's all hardcoded here)
        importer = trade.ImporterManager().load_and_instantiate(
            'TinyGltfImporter')
        importer.open_file(
            os.path.join(os.path.dirname(__file__), '../viewer/scene.glb'))
        suzanne_object = Object3D(parent=self._manipulator)
        suzanne_mesh = meshtools.compile(
            importer.mesh(importer.mesh_for_name('Suzanne')))
        suzanne_eyes_mesh = meshtools.compile(
            importer.mesh(importer.mesh_for_name('Eyes')))
        self._suzanne = ColoredDrawable(suzanne_object, self._drawables,
                                        suzanne_mesh, colored_shader,
                                        Color3(0.15, 0.49, 1.0))
        self._suzanne_eyes = ColoredDrawable(suzanne_object, self._drawables,
                                             suzanne_eyes_mesh, colored_shader,
                                             Color3(0.95))

        self._previous_mouse_position = Vector2i()
Пример #4
0
    def __init__(self):
        configuration = self.Configuration()
        configuration.title = "Magnum Python Primitives Example"
        Application.__init__(self, configuration)

        gl.Renderer.enable(gl.Renderer.Feature.DEPTH_TEST)
        gl.Renderer.enable(gl.Renderer.Feature.FACE_CULLING)

        self._mesh = meshtools.compile(primitives.cube_solid())
        self._shader = shaders.PhongGL()

        self._transformation = (
            Matrix4.rotation_x(Deg(30.0)) @ Matrix4.rotation_y(Deg(40.0)))
        self._projection = (Matrix4.perspective_projection(
            fov=Deg(35.0), aspect_ratio=1.33333, near=0.01, far=100.0)
                            @ Matrix4.translation(Vector3.z_axis(-10.0)))
        self._color = Color3.from_hsv(Deg(35.0), 1.0, 1.0)
        self._previous_mouse_position = Vector2i()
Пример #5
0
    def __init__(self):
        configuration = self.Configuration()
        configuration.title = "Magnum Python Triangle Example"
        Application.__init__(self, configuration)

        buffer = gl.Buffer()
        buffer.set_data(
            array.array('f', [
                -0.5, -0.5, 1.0, 0.0, 0.0, 0.5, -0.5, 0.0, 1.0, 0.0, 0.0, 0.5,
                0.0, 0.0, 1.0
            ]))

        self._mesh = gl.Mesh()
        self._mesh.count = 3
        self._mesh.add_vertex_buffer(buffer, 0, 5 * 4,
                                     shaders.VertexColor2D.POSITION)
        self._mesh.add_vertex_buffer(buffer, 2 * 4, 5 * 4,
                                     shaders.VertexColor2D.COLOR3)

        self._shader = shaders.VertexColor2D()