Esempio n. 1
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(90, 1, 1, 10000)

        # loader = OBJMTLLoader()
        # obj = loader.load(obj_file, mtl_file)

        loader = OBJLoader()
        obj = loader.load(obj_file)

        self.renderer.main_light.pos = 1, 20, 50
        self.renderer.main_light.intensity = 1000

        camera.pos = 0, 0, 50
        camera.look_at((0, 0, 0))

        scene.add(*obj.children)
        for obj in scene.children:
            obj.pos.z = -0.
            obj.scale = 0.1, 0.1, 0.1

        self.renderer.render(scene, camera)
        self.orion = scene.children

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        Clock.schedule_interval(self._rotate_obj, 1 / 20)
        # Clock.schedule_interval(self.print_color, 2)
        return root
Esempio n. 2
0
    def _setup_object(self):

        self.clear_widgets()
        if is_ios():  # TODO enable this when iOS bug is resolved
            return

        shader_file = resource_find(
            os.path.join('resource', 'models', 'shaders.glsl'))
        obj_path = resource_find(self.model_path)

        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        loader = OBJLoader()
        obj = loader.load(obj_path)

        scene.add(*obj.children)
        for obj in scene.children:
            obj.pos.x = self.position_x
            obj.pos.y = self.position_y
            obj.pos.z = self.position_z
            obj.rotation.x = self.rotation_x
            obj.rotation.y = self.rotation_y
            obj.rotation.z = self.rotation_z
            obj.material.specular = .85, .85, .85
            obj.material.color = 1.0, 1.0, 1.0
            obj.material.diffuse = 0.5, 0.5, 0.5
            obj.material.transparency = 1.0
            obj.material.intensity = 0.5
            self.imu_obj = obj
            # obj.material.shininess = 1.0

        self.renderer.render(scene, camera)
        self.renderer.bind(size=self._adjust_aspect)
        Clock.schedule_once(lambda dt: self.add_widget(self.renderer))
Esempio n. 3
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer()
        scene = Scene()
        camera = PerspectiveCamera(30, 1, 1, 1000)
        # load obj file
        loader = OBJLoader()
        obj_path = os.path.join(os.path.dirname(__file__),
                                "examples/testnurbs.obj")
        obj = loader.load(obj_path)

        scene.add(*obj.children)
        for obj in scene.children:
            obj.pos.z = -20
            obj.material.specular = .35, .35, .35

        # set colors to 3d objects
        scene.children[0].material.color = 0., .7, 0.  # green
        scene.children[1].material.color = .7, 0., 0.  # red
        scene.children[2].material.color = 0., 0., .7  # blue
        scene.children[3].material.color = .7, .7, 0.  # yellow

        scene.children[0].material.diffuse = 0., .7, 0.  # green
        scene.children[1].material.diffuse = .7, 0., 0.  # red
        scene.children[2].material.diffuse = 0., 0., .7  # blue
        scene.children[3].material.diffuse = .7, .7, 0.  # yellow

        self.renderer.render(scene, camera)
        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        return root
Esempio n. 4
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file='examples/simple.glsl')
        scene = Scene()
        camera = PerspectiveCamera(30, 1, 1, 1000)
        # load obj file
        loader = OBJLoader()
        obj_path = os.path.join(os.path.dirname(__file__), "cube.obj")
        obj = loader.load(obj_path)
        cube = obj.children[0]
        #scene.add(*obj.children)
        #for obj in scene.children:

        scene.add(cube)
        cube.pos.z = -20
        cube.rot.y = -45
        cube.rot.x = 45
        cube.material.specular = .35, .35, .35

        # set colors to 3d objects
        scene.children[0].material.color = 0., .7, 0.  # green
        scene.children[0].material.diffuse = 0., .7, 0.  # green

        self.renderer.render(scene, camera)
        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        return root
Esempio n. 5
0
    def __init__(self, source_file):
        self.obj = OBJLoader().load(f"glContext\\models\\{source_file}.obj")
        self.obj.name = source_file
        self._origin = [0, 0, 0]
        self._pos = [0, 0, 0]

        self._set_origin()
        self._set_pos()
Esempio n. 6
0
    def build(self):
        self.renderer = Renderer()
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        loader = OBJLoader()
        obj = loader.load(obj_file)
        self.obj3d = obj
        self.camera = camera
        root = ObjectTrackball(camera, 1500)

        scene.add(obj)

        self.renderer.render(scene, camera)

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        return root
Esempio n. 7
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        # load obj file
        loader = OBJLoader()
        obj = loader.load(obj_file)
        self.monkey = obj.children[0]

        scene.add(*obj.children)
        camera = PerspectiveCamera(15, 1, 1, 1000)

        self.renderer.render(scene, camera)
        root.add_widget(self.renderer)
        Clock.schedule_interval(self._update_obj, 1. / 20)
        self.renderer.bind(size=self._adjust_aspect)
        return root
Esempio n. 8
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        # load obj file
        loader = OBJLoader()
        obj = loader.load(obj_path)

        scene.add(*obj.children)
        for obj in scene.children:
            obj.pos.z = -20

        self.renderer.render(scene, camera)
        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        return root
Esempio n. 9
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file="simple.glsl")
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        # load obj file
        loader = OBJLoader()
        obj_path = os.path.join(os.path.dirname(kivy3.__file__),
                                "tests/testnurbs.obj")
        obj = loader.load(obj_path)

        scene.add(*obj.children)
        for obj in scene.children:
            obj.pos.z = -20

        self.renderer.render(scene, camera)
        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        return root
Esempio n. 10
0
    def build(self):
        layout = GridLayout(cols=3)

        # create renderer
        self.renderer = Renderer(size_hint=(5, 5))
        self.renderer.set_clear_color((0.1, 0.1, 0.1, 1))  # rgba

        # create scene
        scene = Scene()
        self.cubes = []

        # create cubes for scene
        #
        # default pure green cube
        cube_geo = BoxGeometry(.3, .3, .3)
        cube_mat = Material(color=(0, 0.5, 0)  # base color
                            )
        self.cubes.append(Mesh(geometry=cube_geo,
                               material=cube_mat))  # default pos == (0, 0, 0)
        self.cubes[0].pos.z = -5
        self.cubes[0].pos.x = 1
        self.cubes[0].pos.y = 0.8
        self.cubes[0].rotation.x = 45

        # black cube, red shadow, half-transparent
        cube_geo = BoxGeometry(.3, .3, .3)
        cube_mat = Material(
            transparency=0.5,
            color=(0, 0, 0),  # base color
            diffuse=(10, 0, 0),  # color of "shadows"
            specular=(0, 0, 0)  # mirror-like reflections
        )
        self.cubes.append(Mesh(geometry=cube_geo,
                               material=cube_mat))  # default pos == (0, 0, 0)
        self.cubes[1].pos.z = -5
        self.cubes[1].pos.x = -1
        self.cubes[1].pos.y = 0.8
        self.cubes[1].rotation.y = 45

        # default pure green cube with red reflections
        cube_geo = BoxGeometry(.3, .3, .3)
        cube_mat = Material(
            transparency=1,
            color=(0, 0.5, 0),  # base color
            diffuse=(0, 0, 0),  # color of "shadows"
            specular=(10, 0, 0)  # mirror-like reflections
        )
        self.cubes.append(Mesh(geometry=cube_geo,
                               material=cube_mat))  # default pos == (0, 0, 0)
        self.cubes[2].pos.z = -5
        self.cubes[2].pos.x = 1
        self.cubes[2].pos.y = -0.8
        self.cubes[2].rotation.z = 45

        # something.obj from Blender
        loader = OBJLoader()
        self.cubes.extend(
            loader.load(join(FOLDER, 'models', 'something.obj')).children)
        self.cubes[3].pos.z = -5
        self.cubes[3].pos.x = -1
        self.cubes[3].pos.y = -0.8
        self.cubes[3].rotation.x = 45
        self.cubes[3].material.color = (0.1, 0.4, 0.1)
        self.cubes[3].material.texture_ratio = 0.0

        # cube object from Blender
        loader = OBJLoader()
        self.main_cube = loader.load(join(FOLDER, 'models', 'cube.obj'))
        self.main_cube.rotation.x = 45
        self.main_cube.rotation.y = 45
        self.main_cube.pos.z = -5
        self.main_cube.scale = (0.5, 0.5, 0.5)
        scene.add(self.main_cube)

        planes = [((0, 0, -10), (0, 0, 0)), ((-10, 0, 0), (0, -90, 0)),
                  ((10, 0, 0), (0, 90, 0)),
                  ((0, 0, 10), (0, 180, 0))]  # position and rotation changes
        for plane in planes:
            geo = BoxGeometry(5, 5, .1)
            mat = Material(color=(1, 1, 1))
            mesh = Mesh(geometry=geo, material=mat)
            mesh.pos.x += plane[0][0]
            mesh.pos.y += plane[0][1]
            mesh.pos.z += plane[0][2]
            mesh.rot.x += plane[1][0]
            mesh.rot.y += plane[1][1]
            mesh.rot.z += plane[1][2]
            scene.add(mesh)

        # create camera for scene
        self.camera = PerspectiveCamera(
            fov=75,  # distance from the screen
            aspect=0,  # "screen" ratio
            near=.1,  # nearest rendered point
            far=1000  # farthest rendered point
        )

        # start rendering the scene and camera
        for cube in self.cubes:
            scene.add(cube)
        self.renderer.render(scene, self.camera)

        # set renderer ratio is its size changes
        # e.g. when added to parent
        self.renderer.bind(size=self._adjust_aspect)

        layout.add_widget(Factory.CamRot())
        layout.add_widget(Factory.LightPanel())
        layout.add_widget(Factory.CamStrafe())
        layout.add_widget(Widget())

        layout.add_widget(self.renderer)

        layout.add_widget(Label(text='+\n\nY\n\n-'))
        layout.add_widget(Factory.CamNav())
        layout.add_widget(Label(text='-      X      +'))
        layout.add_widget(Factory.ObjNav())

        Clock.schedule_interval(self.rotate_cube, .01)
        Clock.schedule_interval(self.scale_cube, 1)

        # keyboard listener
        Listener()
        return layout
Esempio n. 11
0
    def build(self):
        self.theflag = 0
        self.theflag0 = 0
        self.distan = 1000  # дистанция до начальной точки (0,0,-50) что бы ничего не было за экраном (надо будет выстваить на изменение)
        bl = BoxLayout(orientation='vertical',
                       size_hint=(.15, 1),
                       spacing=10,
                       padding=10)  # левая панель
        al = AnchorLayout(anchor_x='left',
                          anchor_y='center')  # основная система интерфейса
        layout = GridLayout(cols=2, spacing=3,
                            size_hint=(1, 1))  #сетка для кнопок поворота

        matrix = np.load('matrix0.npy', allow_pickle=True)
        counter = int(int(matrix.size) / 2)
        x = np.zeros(counter)
        y = np.zeros(counter)
        z = np.zeros(counter)
        soe = np.zeros((counter, counter))

        for i in range(2):
            if (i == 0):
                for j in range(counter):
                    for k in range(3):
                        a = matrix[i, j]
                        if (k == 0):
                            x[j] = a[k] * 10
                        elif (k == 1):
                            y[j] = a[k] * 10
                        else:
                            z[j] = a[k] * 10
            else:
                for j in range(counter):
                    a = matrix[i, j]
                    for k in range(counter):
                        soe[j][k] = a[k]
        print(x, y, z)
        print(soe)
        # кнопка загрузки координат
        loader = Button(text='Load', on_press=self.load)
        bl.add_widget(loader)

        #starter = Button(text='Построить', on_press = self.letstart)
        #bl.add_widget(starter)

        bl.add_widget(Widget())
        # create renderer
        self.renderer = Renderer()

        # create scene
        scene = Scene()

        #lines
        k0 = 0
        k1 = 0
        lines_list = []
        for i in soe:
            for j in i:
                if (j == 1):
                    line0_geo = BoxGeometry(
                        1,
                        int(((y[k0] - y[k1])**2 + (x[k0] - x[k1])**2 +
                             (z[k0] - z[k1])**2)**0.5), 1)
                    #print(int(((abs(x[k0]-x[k1]) + abs(y[k0]-y[k1])+ abs(z[k0]-z[k1]))**0.5)),'length')
                    #print(int(abs(y[k0]-y[k1]) + abs(x[k0]-x[k1])+ abs(z[k0]-z[k1])))
                    line0_mat = Material()
                    self.line0 = Mesh(
                        geometry=line0_geo,
                        material=line0_mat)  # default pos == (0, 0, 0)
                    self.line0.pos.x = int((x[k0] + x[k1]) / 2)
                    self.line0.pos.y = int((y[k0] + y[k1]) / 2)
                    self.line0.pos.z = int((z[k0] + z[k1]) / 2) - self.distan
                    if y[k0] - y[k1] == 0 and x[k0] - x[
                            k1] == 0 and z[k0] - z[k1] != 0:
                        self.line0.rotation.x = 90
                    elif y[k0] - y[k1] == 0 and x[k0] - x[k1] != 0 and z[
                            k0] - z[k1] == 0:
                        self.line0.rotation.z = 90
                    elif y[k0] - y[k1] != 0 and x[k0] - x[k1] == 0 and z[
                            k0] - z[k1] == 0:
                        ###
                        fff = 0
                    elif y[k0] - y[k1] != 0 and x[k0] - x[k1] != 0 and z[
                            k0] - z[k1] == 0:
                        self.line0.rotation.z = math.atan(
                            (x[k0] - x[k1]) / (y[k0] - y[k1])) / math.pi * 180
                    elif y[k0] - y[k1] != 0 and x[k0] - x[
                            k1] == 0 and z[k0] - z[k1] != 0:
                        #self.line0.rotation.x = math.atan((z[k0]-z[k1])/(y[k0]-y[k1]))/math.pi*180
                        self.line0.rotation.x = math.acos(
                            abs(y[k0] - y[k1]) /
                            ((x[k0] - x[k1])**2 + (y[k0] - y[k1])**2 +
                             (z[k0] - z[k1])**2)**0.5) / math.pi * 180
                        #print()
                    elif y[k0] - y[k1] == 0 and x[k0] - x[k1] != 0 and z[
                            k0] - z[k1] != 0:
                        self.line0.rotation.z = math.atan(
                            (x[k0] - x[k1]) /
                            (z[k0] - z[k1])) / math.pi * 180 * -1
                        self.line0.rotation.x = 90

                    ###
                    elif y[k0] - y[k1] != 0 and x[k0] - x[k1] != 0 and z[
                            k0] - z[k1] != 0:
                        if ((x[k0] < x[k1] and y[k0] < y[k1])
                                or (x[k0] > x[k1] and y[k0] > y[k1])):
                            #self.line0.rotation.z = math.atan((abs(z[k0]-z[k1]))/1.5/(abs(y[k0]-y[k1])))/math.pi*180
                            self.line0.rotation.z = math.acos(
                                abs(y[k0] - y[k1]) /
                                ((x[k0] - x[k1])**2 + (y[k0] - y[k1])**2 +
                                 (0)**2)**0.5) / math.pi * 180 * -1
                            #проблема
                        else:
                            self.line0.rotation.z = math.acos(
                                abs(y[k0] - y[k1]) /
                                ((x[k0] - x[k1])**2 + (y[k0] - y[k1])**2 +
                                 (0)**2)**0.5) / math.pi * 180
                        #self.line0.rotation.x = math.atan((1.25*abs(x[k0]-x[k1]))/(abs(y[k0]-y[k1])))/math.pi*180*-1
                        if ((z[k0] < z[k1] and y[k0] < y[k1])
                                or (z[k0] > z[k1] and y[k0] > y[k1])):
                            self.line0.rotation.x = math.acos(
                                abs(y[k0] - y[k1]) /
                                ((0)**2 + (y[k0] - y[k1])**2 +
                                 (z[k0] - z[k1])**2)**0.5) / math.pi * 180
                            #проблема
                        else:
                            self.line0.rotation.x = math.acos(
                                abs(y[k0] - y[k1]) /
                                ((0)**2 + (y[k0] - y[k1])**2 +
                                 (z[k0] - z[k1])**2)**0.5) / math.pi * 180 * -1

                        #self.line0.rotation.x = math.acos(abs(y[k0]-y[k1])/((0)**2+(y[k0]-y[k1])**2+(z[k0]-z[k1])**2)**0.5)/math.pi*180*-1#there
                        print(self.line0.rotation.z)
                        print(self.line0.rotation.x)
                    lines_list.append(self.line0)
                k1 += 1
            k0 += 1
            k1 = 0
        line0_geo = BoxGeometry(1, y[1] - y[0], 1)
        line0_mat = Material()
        self.line0 = Mesh(geometry=line0_geo,
                          material=line0_mat)  # default pos == (0, 0, 0)
        self.line0.pos.z = int(z[0]) - self.distan

        #self.line3.rotation.x = 90

        #points
        point_list = []
        sumx = 0
        sumy = 0
        sumz = 0
        sumcount = 0
        loader = OBJLoader()

        for i in range(counter):
            point_geom = SphereGeometry(1.1)
            point_mat = Material()
            self.point0 = Mesh(geometry=point_geom, material=point_mat)
            self.point0.pos.x = int(x[i])
            self.point0.pos.y = int(y[i])
            self.point0.pos.z = int(z[i]) - self.distan
            self.point0.scale = (1, 1, 1)
            point_list.append(self.point0)
            sumx += self.point0.pos.x
            sumy += self.point0.pos.y
            sumz += self.point0.pos.z
            sumcount += 1
            #scene.add(self.point0)

        point_geom = SphereGeometry()
        point_mat = Material()
        self.point1 = Mesh(geometry=point_geom, material=point_mat)
        self.point1.pos.x = sumx / sumcount
        self.point1.pos.y = sumy / sumcount
        self.point1.pos.z = sumz / sumcount
        self.point1.scale = (1, 1, 1)
        #scene.add(self.point1)
        self.camera = PerspectiveCamera(
            fov=100,  # размер окна т.е. чем больше фов тем больше масштаб
            aspect=0,  # "screen" ratio
            near=1,  # рендер от
            far=10000  # дистанция рендера
        )

        k0 = 0
        self.ll = []
        for i in soe:
            for j in i:
                if (j == 1):
                    self.ll.append(lines_list[k0])
                    scene.add(lines_list[k0])
                    k0 += 1

        for i in range(counter):
            scene.add(point_list[i])
            pass

        self.pp = point_list
        self.renderer.render(scene, self.camera)
        self.renderer.bind(size=self._adjust_aspect)
        al.add_widget(self.renderer)
        bl.add_widget(Factory.Fov())
        bl.add_widget(Factory.CamNav())
        al.add_widget(bl)
        return al