Example #1
0
 def __init__(self, **kwargs):
     self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
     self._keyboard.bind(on_key_down=self._on_keyboard_down)
     #        self.canvas = RenderContext(compute_normal_mat=True)
     # TODO - Pass the shader source as an argument to the constructor
     #        self.canvas.shader.source = resource_find('./utils/simple.glsl')
     # TODO - Pass the object file as an argument to the constructor
     self.scene = ObjFile(resource_find('./models/square.obj'))
     self.cam_pos = 100
     self.cam_rot = 0
     self.light_pos = [0., 0., 1., 1.]
     super(Renderer, self).__init__(**kwargs)
     with self.canvas:
         self.fbo = Fbo(size=(1920, 1080), clear_color=(1, 0, 0, 0))
         self.fbo.shader.source = resource_find('./utils/ggx.glsl')
     self.fbo['rdiff'] = self.fbo['rspec'] = self.fbo['lintensity'] = 1.0
     with self.fbo:
         self.cb = Callback(self.setup_gl_context)
         PushMatrix()
         self.setup_scene()
         PopMatrix()
         self.cb = Callback(self.reset_gl_context)
     self.fbo['diffuse'] = 2
     self.fbo['specular'] = 3
     self.fbo['nmap'] = 4
     self.fbo['roughness'] = 5
     self.fbo['model_mat'] = Matrix()
     self.fbo['test_mat'] = Matrix().look_at(0, 0, 100, 0, 0, 0, 0, 1, 0)
     Clock.schedule_interval(self.update_glsl, 1 / 60.)
Example #2
0
    def getObjects(self):
        tr = {}

        ff = open(self.files)
        fo = open(self.objNames)

        filesList = []
        objList = []

        while True:
            lf = str(ff.readline()[:-1])
            on = str(fo.readline()[:-1])
            if lf == "":
                break

            filesList.append('./3dModels/' + lf + '.obj')
            objList.append(on)

        scene = ObjFile(filesList)
        for i, o in enumerate(objList):
            #print(o)
            keys = list(scene.objects.keys())
            tr[o] = scene.objects[keys[i]]

        #print("loadet [%s] objects"%len(tr))
        #print(tr)

        return tr
Example #3
0
    def __init__(self, **kwargs):
        self.canvas = RenderContext(compute_normal_mat=True)
        self.canvas.shader.source = resource_find('simple.glsl')
        self.scene = ObjFile([
            #			resource_find("3d_roseta.obj"),
            #			resource_find("3d_phone_textured.obj")
            resource_find("./3dModels/3d_board.obj"),
            resource_find("./3dModels/boat.obj"),
            resource_find('./3dModels/3d_box.obj')
        ])

        self.useWavas = True

        if self.useWavas:
            self.waveSize = [7, 7, 2.5]
            self.wave = []
            for c in range(0, self.waveSize[0] * self.waveSize[1], 1):
                self.wave.append(self.scene.objects['Cube'])

        else:
            self.scene.objects['board0'] = self.scene.objects['board_Cube']
            self.scene.objects['board1'] = self.scene.objects['board_Cube']
            self.scene.objects['board2'] = self.scene.objects['board_Cube']

        self.o = self.scene.objects
        super(simRender, self).__init__(**kwargs)
        with self.canvas:
            self.cb = Callback(self.setup_gl_context)
            PushMatrix()
            self.setup_scene()
            PopMatrix()
            self.cb = Callback(self.reset_gl_context)
Example #4
0
 def render(self, obj_file):
     self.canvas.clear()
     self.scene = ObjFile(obj_file)
     with self.canvas:
         self.cb = Callback(lambda args: glEnable(GL_DEPTH_TEST))
         PushMatrix()
         self._setup_scene()
         PopMatrix()
         self.cb = Callback(lambda args: glDisable(GL_DEPTH_TEST))
     Clock.schedule_interval(self._update_glsl, 1 / 60.)
Example #5
0
 def __init__(self, **kwargs):
     self.canvas = RenderContext(compute_normal_mat=True)
     self.canvas.shader.source = resource_find('simple.glsl')
     self.scene = ObjFile(resource_find("monkey.obj"))
     super(Renderer, self).__init__(**kwargs)
     with self.canvas:
         self.cb = Callback(self.setup_gl_context)
         PushMatrix()
         self.setup_scene()
         PopMatrix()
         self.cb = Callback(self.reset_gl_context)
     Clock.schedule_interval(self.update_glsl, 1 / 60.)
Example #6
0
 def __init__(self, **kwargs):
     self.scene = ObjFile(resource_find('./models/square.obj'))
     super(MaskDisplay, self).__init__(**kwargs)
     with self.canvas:
         self.fbo = Fbo(size=self.size, clear_color=(1., 1., 1., 1.))
         self.fbo.shader.source = resource_find('./utils/mask.glsl')
     with self.fbo:
         self.cb = Callback(self.setup_gl_context)
         PushMatrix()
         self.setup_scene()
         PopMatrix()
         self.cb = Callback(self.reset_gl_context)
     self.fbo['tex1'] = 1
Example #7
0
 def __init__(self, grasp, **kwargs):
     self.grasp = grasp
     self.canvas = RenderContext(compute_normasl_mat=True)
     self.canvas.shader.source = resource_find('simple.glsl')
     self.scene = ObjFile(resource_find(self.grasp.obj_file))
     #self.scene = ObjFile(resource_find('Co_clean.obj'))
     super(Renderer, self).__init__(**kwargs)
     with self.canvas:
         self.cb = Callback(self.setup_gl_context)
         PushMatrix()
         self.setup_scene()
         PopMatrix()
         self.cb = Callback(self.reset_gl_context)
     Clock.schedule_once(self.rot_up)
     Clock.schedule_once(self.rot_left)
Example #8
0
    def __init__(self, **kwargs):
        self.canvas = RenderContext(compute_normal_mat=True)
        self.canvas.shader.source = resource_find('simple.glsl')
        ml = modelsLoader("boat2")
        self.o = ml.getObjects()
        scenRos = ObjFile(resource_find("./3dModels/3d_roseta.obj"))
        self.o['roseta'] = scenRos.objects[list(scenRos.objects.keys())[0]]
        print("roseta[%s]" % self.o['roseta'])

        super(Renderer, self).__init__(**kwargs)
        with self.canvas:
            self.cb = Callback(self.setup_gl_context)
            PushMatrix()
            self.setup_scene()
            PopMatrix()
            self.cb = Callback(self.reset_gl_context)
Example #9
0
 def get_scene(filename):
     path = '{}.obj'.format(filename)
     if os.path.exists(path):
         return ObjFile(path)
     else:
         print '{} does not exist'.format(path)
Example #10
0
def main():
    # light
    vcode = """
        #version 330

        layout (location = 0) in vec3 position;
        layout (location = 1) in vec3 color;
        layout (location = 2) in vec2 text;
        layout (location = 3) in vec3 offset;

        out vec3 ver_color;
        out vec2 ver_tex;

        uniform mat4 projection;
        uniform mat4 view;
        uniform mat4 model;

        void main()
        {{
            gl_Position = projection * view * model * vec4(position + offset, 1.0);
            ver_color = color;
            ver_tex = text;
        }}"""

    fcode = """
        #version 330
        in vec3 ver_color;
        in vec2 ver_tex;
        out vec4 color;
        uniform sampler2D tex;

        void main()
        {{
            color = vec4(ver_color, 1.0f);
            //color = texture(tex, ver_tex);
        }}"""

    scene = ObjFile("3Drendering\monkey.obj")
    m = list(scene.objects.values())[0]
    data = m.vertices
    vformat = list(zip(*m.vertex_format))[1]

    data_a = (
        -0.5,
        -0.5,
        0.5,
        0.0,
        0.0,
        1.0,
        0.0,
        0.0,  # A
        0.5,
        -0.5,
        0.5,
        0.0,
        1.0,
        0.0,
        1.0,
        0.0,  # B
        0.5,
        0.5,
        0.5,
        0.0,
        1.0,
        1.0,
        1.0,
        1.0,  # C
        -0.5,
        0.5,
        0.5,
        1.0,
        0.0,
        0.0,
        0.0,
        1.0,  # D
        -0.5,
        -0.5,
        -0.5,
        1.0,
        0.0,
        1.0,
        0.0,
        0.0,  # E
        0.5,
        -0.5,
        -0.5,
        1.0,
        1.0,
        0.0,
        1.0,
        0.0,  # F
        0.5,
        0.5,
        -0.5,
        1.0,
        1.0,
        1.0,
        1.0,
        1.0,  # G
        -0.5,
        0.5,
        -0.5,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0,  # H
    )
    data_i = (
        0,
        1,
        2,
        2,
        3,
        0,
        4,
        7,
        6,
        6,
        5,
        4,
        3,
        7,
        4,
        4,
        0,
        3,
        5,
        6,
        2,
        2,
        1,
        5,
        6,
        7,
        3,
        3,
        2,
        6,
        0,
        4,
        5,
        5,
        1,
        0,
    )

    vformat1 = [3, 3, 2]
    data1 = []
    size_point = sum(vformat1)
    for i in data_i:
        data1.extend(data_a[i * size_point:(i + 1) * size_point])

    tdata = []
    for x in range(-2, 2, 2):
        for y in range(-2, 2, 2):
            tdata.extend([x, y, 0])
    tformat = [3]
    tdivisor = [1]

    light = LightBasic()
    w, h = 800, 480
    event = WindowEvent(w, h)
    #event = None
    light.create_window(w, h, event)

    vex_data = (data1, vformat1, None)
    inst_data = (tdata, tformat, tdivisor)

    datas = {'vertex': vex_data, 'inst': inst_data}

    shader = light.create_shader_instances(datas, vcode, fcode, "wood.png",
                                           lightShader)
    if shader is None:
        print("create shader failed")
        return

    # light.set_shader('trans', 'view', light.box_view_transform, shader_box)
    # light.set_shader('trans', 'project', light.box_project_transform, shader_box)

    light.run()