Example #1
0
 def setup_scene(self):
     Color(1, 1, 1, 1)
     PushMatrix()
     Translate(0, 0, -3)
     self.rot = Rotate(1, 0, 1, 0)
     m = list(self.scene.objects.values())[0]
     UpdateNormalMatrix()
     self.mesh = Mesh(
         vertices=m.vertices,
         indices=m.indices,
         fmt=m.vertex_format,
         mode='triangles',
     )
     PopMatrix()
Example #2
0
 def as_instructions(self):
     """ Get instructions set for renderer """
     if not self._instructions.children:
         self._instructions.add(self._push_matrix)
         self._instructions.add(self._translate)
         self._instructions.add(self.scale)
         for rot in self._rotors.values():
             self._instructions.add(rot)
         self._instructions.add(UpdateNormalMatrix())
         for instr in self.custom_instructions():
             self._instructions.add(instr)
         for child in self.get_children_instructions():
             self._instructions.add(child)
         self._instructions.add(self._pop_matrix)
     return self._instructions
Example #3
0
    def setup_scene(self):
        Color(1, 1, 1, 0)

        PushMatrix()
        self.cam_translate = Translate(self.cam_translation)
        # Rotate(0, 1, 0, 0)
        self.cam_rot_x = Rotate(self.cam_rotation[0], 1, 0, 0)
        self.cam_rot_y = Rotate(self.cam_rotation[1], 0, 1, 0)
        self.cam_rot_z = Rotate(self.cam_rotation[2], 0, 0, 1)
        self.scale = Scale(self.obj_scale)
        UpdateNormalMatrix()
        if self.display_all:
            for i in self._scene.objects:
                self.draw_object(i)
        else:
            self.draw_object(self.obj_id)
        PopMatrix()
Example #4
0
    def setup_scene(self):
        Color(.5, .5, .5, 0)

        PushMatrix()
        Translate(0, -3, -5)
        # This Kivy native Rotation is used just for
        # enabling rotation scene like trackball
        self.rotx = Rotate(0, 1, 0, 0)
        # here just rotate scene for best view
        self.roty = Rotate(180, 0, 1, 0)
        self.scale = Scale(1)

        UpdateNormalMatrix()

        self.draw_elements()

        PopMatrix()
Example #5
0
 def _setup_scene(self):
     for mi, m in enumerate(self.scene.objects.values()):
         Color(1, 1, 1, 1)
         PushMatrix()
         Translate(0, -0.3, -1.8)
         setattr(self, 'mesh%03d_rotx' % mi, Rotate(180, 1, 0, 0))
         setattr(self, 'mesh%03d_roty' % mi, Rotate(0, 0, 1, 0))
         setattr(self, 'mesh%03d_scale' % mi, Scale(1))
         UpdateNormalMatrix()
         mesh = Mesh(
             vertices=m.vertices,
             indices=m.indices,
             fmt=m.vertex_format,
             mode='triangles',
         )
         setattr(self, 'mesh%03d' % mi, mesh)
         PopMatrix()
Example #6
0
 def setup_scene(self):
     Color(1, 0, 1, 1)
     PushMatrix()
     self.translate = Translate(0, -3, -10)
     self.rotx = Rotate(0, 1, 0, 0)
     self.rot = Rotate(0.5, 0, 1, 0)
     self.scale = Scale(1.0)
     #m = random.sample(xrange(10), 10)#list(self.scene.objects.values())[0]
     #m = list(self.scene.objects.values())[0]
     self.mesh = self.generateMesh()  #Mesh(
     UpdateNormalMatrix()
     #self.mesh = Mesh(
     #    vertices=m.vertices,
     #    indices=m.indices,
     #    fmt=m.vertex_format,
     #    mode='triangles',
     #)
     PopMatrix()
Example #7
0
    def __init__(self, grid, **kwargs):
        self.canvas = RenderContext()
        self.canvas.shader.source = SIMPLE_SHADER
        self._atlas = Atlas(BG_ATLAS_ATLAS)
        self._tex = CoreImage(BG_ATLAS_IMAGE).texture

        super().__init__(size_hint=(1, 1), **kwargs)
        with self.canvas:
            PushMatrix()
            UpdateNormalMatrix()

            vertices = []
            indices = []
            rows = 40
            cols = 40
            blk_h = 1. / rows
            blk_w = 1. / cols
            n = 0
            tex_names = list(self._atlas.textures.keys())
            for i, j in product(range(cols), range(rows)):
                tex_name = tex_names[(i + j) % len(tex_names)]
                win_x1, win_y1 = blk_w * i - .5, blk_h * j - .5
                win_x2, win_y2 = blk_w * (i + 1) - .5, blk_h * (j + 1) - .5
                tex_pos = self._atlas[tex_name].uvpos
                tex_size = self._atlas[tex_name].uvsize
                tex_x1, tex_y1 = tex_pos
                tex_x2, tex_y2 = tex_pos[0] + tex_size[0], tex_pos[
                    1] + tex_size[1]
                vertices.extend([
                    win_x1, win_y1, 0, tex_x1, tex_y1, win_x2, win_y1, 0,
                    tex_x2, tex_y1, win_x1, win_y2, 0, tex_x1, tex_y2, win_x2,
                    win_y2, 0, tex_x2, tex_y2
                ])

                indices.extend([n, n + 1, n + 2, n + 2, n + 1, n + 3])
                n += 4

            fmt = [(b'v_pos', 3, 'float'), (b'v_uv', 2, 'float')]
            self.mesh = Mesh(texture=self._tex,
                             vertices=vertices,
                             indices=indices,
                             fmt=fmt,
                             mode="triangles")
            PopMatrix()
Example #8
0
    def populate_fbo(self, fbo):
        Logger.info("Setting up FBO")

        with self.canvas:
            fbo.shader.source = resource_find('simple.glsl')
            fbo['diffuse_light'] = (1.0, 1.0, 0.8)
            fbo['ambient_light'] = (0.8, 0.8, 0.8)

        with fbo:
            self.cb = Callback(self.setup_gl_context)
            PushMatrix()
            BindTexture(source='testure.jpg', index=1)
            UpdateNormalMatrix()
            Translate(0, 0, -3)
            self.rot = Rotate(1, 0, 1, 0)
            # self.show_axis()
            self.make_pretty_dots()
            PopMatrix()
            self.cb = Callback(self.reset_gl_context)
        fbo['texture1'] = 1
Example #9
0
    def setup_scene(self, rendered_obj, opts: dict = {}):
        self.curr_obj = rendered_obj
        self._recalc_normals = True
        self._update_glsl()
        with self.canvas:
            self.cb = Callback(self._setup_gl_context)
            PushMatrix()
            self.trans = Translate(0, 0, -3)
            self.rotx = Rotate(
                1, 1, 0, 0)  # so that the object does not break continuity
            self.scale = Scale(1, 1, 1)

            self.yaw = Rotate(0, 0, 0, 1)
            self.pitch = Rotate(0, -1, 0, 0)
            self.roll = Rotate(0, 0, 1, 0)
            self.quat = euler_to_quaternion([0, 0, 0])

            UpdateNormalMatrix()
            if rendered_obj in self._create_mesh_fn.keys():
                self._create_mesh_fn[rendered_obj](**opts)
            # self.trans.x += 1  # move everything to the right
            PopMatrix()
            self.cb = Callback(self._reset_gl_context)
Example #10
0
    def populate_fbo(self, fbo):
        with self.canvas:
            fbo.shader.source = resource_find('simple.glsl')
            fbo['diffuse_light'] = (1.0, 1.0, 0.8)
            fbo['ambient_light'] = (0.5, 0.5, 0.5)

        with fbo:
            self.cb = Callback(self.setup_gl_context)
            PushMatrix()
            if hasattr(self, 'model_texture'):
                BindTexture(texture=self.model_texture, index=1)
            Translate(0, 1, self.gl_depth + 1)
            self.rot = Rotate(0, 0, 1, 0)
            UpdateNormalMatrix()
            Color(1, 1, 1, 1)
            self.mesh = Mesh(
                    vertices=self.mesh_data.vertices,
                    indices=self.mesh_data.indices,
                    fmt=self.mesh_data.vertex_format,
                    mode=self.mesh_data.mode,
                )
            PopMatrix()
            self.cb = Callback(self.reset_gl_context)
        fbo['texture1'] = 1
Example #11
0
    def __init__(self, width, height, canvas, ac, eye_pos, eye_angle):
        super(DisplayController, self).__init__()
        self.width = width
        self.height = height
        self.canvas = canvas
        self.eye_pos = eye_pos
        self.eye_angle = eye_angle
        self.ac = ac

        self.canvas.shader.source = resource_find('data/simple.glsl')

        self.all_notes = []
        self.future_notes = {}
        self.past_notes = {}
        self.ticks = []

        # self.planes = range(0, 10 * config['PLANE_SPACING'], config['PLANE_SPACING'])
        self.planes = []
        self.lines = []

        self.past_displays = InstructionGroup()
        self.future_displays = InstructionGroup()
        self.plane_displays = InstructionGroup()
        self.line_displays = InstructionGroup()

        self.fixed_x = Translate(0, 0, 0)
        self.fixed_y = Translate(0, 0, 0)
        self.fixed_z = Translate(0, 0, 0)
        self.fixed_azi = Rotate(origin=(0, 0, 0), axis=(0, 1, 0))
        self.fixed_ele = Rotate(origin=(0, 0, 0), axis=(1, 0, 0))

        self.alpha_callback = Callback(self.alpha_sample_callback)
        self.disable_alpha_callback = Callback(
            self.disable_alpha_sample_callback)
        self.alpha_instruction = InstructionGroup()
        self.alpha_disable_instruction = InstructionGroup()
        self.alpha_sample_enable = False

        self.canvas.add(Callback(self.setup_gl_context))
        self.canvas.add(self.alpha_instruction)
        self.canvas.add(PushMatrix())
        self.canvas.add(UpdateNormalMatrix())

        self.canvas.add(PushMatrix())
        self.canvas.add(self.fixed_z)
        self.canvas.add(self.line_displays)
        self.canvas.add(PopMatrix())

        self.canvas.add(PushMatrix())
        self.canvas.add(self.past_displays)
        self.canvas.add(self.future_displays)
        self.canvas.add(PopMatrix())

        self.canvas.add(PushMatrix())
        # self.canvas.add(self.fixed_x)
        # self.canvas.add(self.fixed_y)
        self.canvas.add(self.plane_displays)
        self.canvas.add(PopMatrix())

        # self.canvas.add(PushMatrix())
        # self.canvas.add(self.fixed_x)
        # self.canvas.add(self.fixed_y)
        # self.canvas.add(self.fixed_z)
        # self.canvas.add(Plane(-config['SELF_PLANE_DISTANCE'], size=0.1, color=(0x20/255., 0xD8/255., 0xE9/255.), tr=0.2))
        # self.canvas.add(PopMatrix())

        self.canvas.add(PopMatrix())
        self.canvas.add(self.alpha_disable_instruction)
        self.canvas.add(Callback(self.reset_gl_context))

        self.draw_planes()