Beispiel #1
0
    def create_mesh(self):
        """ Create real mesh object from the geometry and material """
        max_faces = 65530//3
        #geometries = []
        start = 0

        while(True):
            _faces=[]
            _vertices = []
            if (len(self.stl_mesh.v0)-start) >= max_faces:
                print("Faces are more than max")
                length = max_faces
                #
                # mesh = STLMesh(self.stl_mesh.v0[start:start+length], self.stl_mesh.v1[start:start+length], self.stl_mesh.v2[start:start+length], self.stl_mesh.normals[start:start+length],
                # self.material)
                #
                # self.add(mesh)
                _vertices = np.concatenate((self.stl_mesh.v0[start:start+length],self.stl_mesh.v1[start:start+length],self.stl_mesh.v2[start:start+length]))
                for i in range(length):

                    f3 = Face3(i,i+length, i+ length*2)
                    f3.vertex_normals = [self.stl_mesh.normals[start+i],self.stl_mesh.normals[start+i],self.stl_mesh.normals[start+i]]
                    _faces.append(f3)



                geo = Geometry()
                geo.vertices = _vertices
                geo.faces = _faces
                mesh = Mesh(geo, self.material)
                self.add(mesh)
                start = start+length


            else:
                length = len(self.stl_mesh.v0)-start
                _vertices = np.concatenate((self.stl_mesh.v0[start:],self.stl_mesh.v1[start:],self.stl_mesh.v2[start:]))
                for i in range(length):
                    f3 = Face3(i,i+length, i+ length*2)
                    f3.vertex_normals = [self.stl_mesh.normals[i+start],self.stl_mesh.normals[i+start],self.stl_mesh.normals[i+start]]
                    _faces.append(f3)
                geo = Geometry()
                geo.vertices = _vertices
                geo.faces = _faces
                #geometries.append(geo)
                mesh = Mesh(geo, self.material)
                self.add(mesh)

                # length = max_faces
                #
                # mesh = STLMesh(self.stl_mesh.v0[start:], self.stl_mesh.v1[start:], self.stl_mesh.v2[start:], self.stl_mesh.normals[start:],
                # self.material)
                #
                # self.add(mesh)
                break

        return self
 def create_cube(self):
     cube_geo = BoxGeometry(1, 1, 1)
     #  BoxGeometry(random.randint(5, 15)/10, random.randint(5, 15)/10, random.randint(5, 15)/10)
     cube_mat = Material(
         color=(random.randint(0, 100) / 100, random.randint(0, 100) / 100, random.randint(0, 100) / 100))
     cube = Mesh(
         geometry=cube_geo,
         material=cube_mat
     )
     cube.pos.z = -5
     cube.rotation.x = random.randint(0, 360)
     self.scene.add(cube)
     Clock.schedule_interval(lambda *args: self.rotate_cube(cube), .01)
     # noinspection PyProtectedMember
     self.renderer._instructions.add(cube.as_instructions())
Beispiel #3
0
    def build(self):
        root = FloatLayout()

        self.renderer = Renderer(shader_file=shader_file)
        self.renderer.set_clear_color((.16, .30, .44, 1.))

        scene = Scene()
        # geometry = CylinderGeometry(0.5, 2)
        geometry = SphereGeometry(1)
        # geometry = BoxGeometry(1, 1, 1)
        material = Material(color=(0.3, 0., 0.3),
                            diffuse=(0.3, 0.3, 0.3),
                            specular=(0., 0., 0.))

        loader = STLLoader()
        obj = loader.load(stl_file, material)
        self.item = obj

        scene.add(self.item)

        self.cube = Mesh(geometry, material)
        self.item.pos.z = -1.5
        #self.cube.pos.z=-5
        camera = PerspectiveCamera(75, 0.3, 0.5, 1000)
        #camera = OrthographicCamera()

        #scene.add(self.cube)
        self.renderer.render(scene, camera)

        root.add_widget(self.renderer)
        Clock.schedule_interval(self._rotate_cube, 1 / 20)
        self.renderer.bind(size=self._adjust_aspect)

        return root
Beispiel #4
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer()
        scene = Scene()
        # load stl file
        mesh_a = mesh.Mesh.from_file('./meshes/base_link.STL')
        geo = STLGeometry(mesh_a)
        material = Material(color=(0., 0., 1.),
                            diffuse=(0., 0., 0.1),
                            specular=(.1, .1, .1))
        obj = Mesh(geo, material)

        # obj.position.z = 10
        self.my_obj = obj

        # load obj file
        # loader = OBJLoader()
        # obj = loader.load(obj_file)
        # self.monkey = obj.children[0]
        #
        scene.add(obj)
        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
Beispiel #5
0
    def build(self):
        layout = FloatLayout()

        # create renderer
        self.renderer = Renderer()

        # create scene
        scene = Scene()

        # create default cube for scene
        cube_geo = my.Msh('sphere.msh',name='zob')
        cube_mat = Material()
        self.cube = Mesh(geometry = cube_geo, material = cube_mat) # default pos == (0,0,0)
        self.cube.pos.z = 0

        # create camera for scene
        self.camera = PerspectiveCamera(
                fov = 75,    #distance from the screen
                aspect=0,    # "screen" ratio
                near=1,      # nearest rendered point
                far=100       # furthest rendered point
        )
        # start rendering the scene and camera
        scene.add(self.cube)
        self.renderer.render(scene,self.camera)

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

        layout.add_widget(self.renderer)
        Clock.schedule_interval(self.rotate_cube, .01)
        return layout
Beispiel #6
0
    def build(self):
        layout = FloatLayout()

        # Create renderer.
        self.renderer = Renderer()

        # Create scene.
        scene = Scene()

        # Create default cube for scene.
        cube_geo = BoxGeometry(1, 1, 1)
        cube_mat = Material()
        self.cube = Mesh(geometry=cube_geo, material=cube_mat)
        self.cube.pos.z = -5

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

        # Start rendering the scene and camera.
        scene.add(self.cube)
        self.renderer.render(scene, self.camera)

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

        layout.add_widget(self.renderer)
        Clock.schedule_interval(self.rotate_cube, 0.01)
        return layout
Beispiel #7
0
    def build(self):
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(45, 1, 0.1, 2500)
        self.renderer.set_clear_color((.2, .2, .2, 1.))

        self.camera = camera
        self.renderer.main_light.intensity = 5000
        root = ObjectTrackball(camera, 10)

        geometry = PrismGeometry(radius=1, height=1, segments=64)
        material = Material(color=(1., 1., 1.),
                            diffuse=(1., 1., 1.),
                            specular=(.35, .35, .35),
                            shininess=200,
                            transparency=0.8)
        obj = Mesh(geometry, material)
        scene.add(obj)

        # create a grid on the xz plane
        geometry = GridGeometry(size=(30, 30), spacing=1)
        material = Material(color=(1., 1., 1.),
                            diffuse=(1., 1., 1.),
                            specular=(.35, .35, .35),
                            transparency=.1)
        lines = Lines(geometry, material)
        lines.rotation.x = 90
        scene.add(lines)

        self.renderer.render(scene, camera)
        self.renderer.main_light.intensity = 500

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        return root
Beispiel #8
0
    def build(self):
        layout = FloatLayout()

        # create renderer
        self.renderer = Renderer()

        # create scene
        scene = Scene()

        # create default cube for scene
        for i in range(1, 6):
            for j in range(1, 6):
                cube_geo = BoxGeometry(*[1] * 3)
                cube_mat = Material(color=(randint(0, 10) * .1,
                                           randint(0, 10) * .1,
                                           randint(0, 10) * .1))
                cube = Mesh(geometry=cube_geo,
                            material=cube_mat)  # default pos == (0, 0, 0)
                cube.pos.y = -0.5
                cube.pos.z = -i
                cube.pos.x = j - 3
                self.cubes.append(cube)
                scene.add(cube)

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

        # start rendering the scene and camera
        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(self.renderer)
        #Clock.schedule_interval(self.move_cubes, 1/60)
        Window.bind(on_key_down=self.handle_keys)
        return layout
Beispiel #9
0
    def build(self):
        root = FloatLayout()

        self.renderer = Renderer()
        self.renderer.set_clear_color((.2, .2, .2, 1.))
        scene = Scene()
        geometry = BoxGeometry(1, 1, 1)
        material = Material(color=(0., 1., 0.),
                            diffuse=(0., 1., 0.),
                            specular=(.35, .35, .35))
        self.cube = Mesh(geometry, material)
        self.cube.pos.z = -3
        camera = PerspectiveCamera(75, 0.3, 1, 1000)

        scene.add(self.cube)
        self.renderer.render(scene, camera)

        root.add_widget(self.renderer)
        Clock.schedule_interval(self._rotate_cube, 1 / 20)
        self.renderer.bind(size=self._adjust_aspect)

        return root
Beispiel #10
0
    def build(self):
        self.renderer = Renderer()
        scene = Scene()
        camera = PerspectiveCamera(45, 1, 0.1, 2500)
        self.renderer.set_clear_color((.2, .2, .2, 1.))

        self.camera = camera
        root = ObjectTrackball(camera, 10)

        # add a cube to the environment as an example
        # NOTE: the grid will be rendered without transparency if it
        # is added before the box.
        # This may be because the shader is not called until a 'triangles' mesh is
        # rendered? Hence the Fragment Shader has not yet been called?
        geometry = BoxGeometry(1, 1, 1)
        material = Material(color=(1., 1., 1.),
                            diffuse=(1., 1., 1.),
                            specular=(.35, .35, .35))
        obj = Mesh(geometry, material)
        scene.add(obj)

        # create a grid on the xz plane
        geometry = GridGeometry(size=(30, 30), spacing=1)
        material = Material(color=(1., 1., 1.),
                            diffuse=(1., 1., 1.),
                            specular=(.35, .35, .35),
                            transparency=.1)
        lines = Lines(geometry, material)
        lines.rotation.x = 90
        scene.add(lines)

        self.renderer.render(scene, camera)
        self.renderer.main_light.intensity = 500

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        return root
Beispiel #11
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
Beispiel #12
0
    def construct_manipulator(self):
        material = Material(color=(0., 0., 1.),
                            diffuse=(1., 1., 0.),
                            specular=(.35, .35, .35))

        # axis a
        # one jaw
        axis_a_dimensions = JOINT_SIZE_A[0], JOINT_SIZE_A[2], JOINT_SIZE_A[1]
        axis_a_geometry = create_joint_rectangle(axis_a_dimensions[0],
                                                 axis_a_dimensions[1],
                                                 axis_a_dimensions[2])
        axis_a_left_mesh = Mesh(axis_a_geometry, material)
        axis_a_right_mesh = Mesh(axis_a_geometry, material)
        self.joints.append(axis_a_left_mesh)
        self.joints.append(axis_a_right_mesh)

        # axis b wrist
        axis_b_dimensions = get_joint_hypo_length(
            JOINT_OFFSET_A_1), JOINT_SIZE_B[1], JOINT_SIZE_B[2]
        axis_b_geometry = create_joint_rectangle(axis_b_dimensions[0],
                                                 axis_b_dimensions[1],
                                                 axis_b_dimensions[2])
        material = Material(color=(1., 0., 0.),
                            diffuse=(1., 0., 0.),
                            specular=(.35, .35, .35))
        axis_b_mesh = Mesh(axis_b_geometry, material)
        self.joints.append(axis_b_mesh)

        axis_b_mesh.add(axis_a_left_mesh)
        axis_a_left_mesh.pos.x = axis_b_dimensions[0]
        axis_a_left_mesh.pos.z = axis_b_dimensions[2] / 2

        axis_b_mesh.add(axis_a_right_mesh)
        axis_a_right_mesh.pos.x = axis_b_dimensions[0]
        axis_a_right_mesh.pos.z = -axis_b_dimensions[2] / 2

        # axis c bend
        axis_c_dimensions = get_joint_hypo_length(
            JOINT_OFFSET_B), JOINT_SIZE_C[1], JOINT_SIZE_C[2]
        axis_c_geometry = create_joint_rectangle(axis_c_dimensions[0],
                                                 axis_c_dimensions[1],
                                                 axis_c_dimensions[2])
        material = Material(color=(1., 1., 0.),
                            diffuse=(1., 1., 0.),
                            specular=(.35, .35, .35))
        axis_c_mesh = Mesh(axis_c_geometry, material)
        self.joints.append(axis_c_mesh)

        axis_c_mesh.add(axis_b_mesh)
        axis_b_mesh.pos.x = axis_c_dimensions[0]

        # axis d bend
        axis_d_dimensions = get_joint_hypo_length(
            JOINT_OFFSET_C), JOINT_SIZE_D[1], JOINT_SIZE_D[2]
        axis_d_geometry = create_joint_rectangle(axis_d_dimensions[0],
                                                 axis_d_dimensions[1],
                                                 axis_d_dimensions[2])
        material = Material(color=(1., 0., 1.),
                            diffuse=(1., 0., 1.),
                            specular=(.35, .35, .35))
        axis_d_mesh = Mesh(axis_d_geometry, material)
        self.joints.append(axis_d_mesh)

        axis_d_mesh.add(axis_c_mesh)
        axis_c_mesh.pos.x = axis_d_dimensions[0]

        # axis e mesh
        axis_e_dimensions = get_joint_hypo_length(
            JOINT_OFFSET_D), JOINT_SIZE_E[1], JOINT_SIZE_E[2]
        axis_e_geometry = create_joint_rectangle(axis_e_dimensions[0],
                                                 axis_e_dimensions[1],
                                                 axis_e_dimensions[2])
        material = Material(color=(0., 1., 0.),
                            diffuse=(0., 1., 0.),
                            specular=(.35, .35, .35))
        axis_e_mesh = Mesh(axis_e_geometry, material)
        self.joints.append(axis_e_mesh)

        axis_e_mesh.add(axis_d_mesh)
        axis_d_mesh.pos.x = axis_e_dimensions[0]

        # axis f
        axis_f_dimensions = get_joint_hypo_length(
            JOINT_OFFSET_E), JOINT_SIZE_F[1], JOINT_SIZE_F[2]
        axis_f_geometry = create_joint_rectangle(axis_f_dimensions[0],
                                                 axis_f_dimensions[1],
                                                 axis_f_dimensions[2])
        material = Material(color=(0., 1., 1.),
                            diffuse=(0., 1., 1.),
                            specular=(.35, .35, .35))
        axis_f_mesh = Mesh(axis_f_geometry, material)
        self.joints.append(axis_f_mesh)

        axis_f_mesh.add(axis_e_mesh)
        axis_e_mesh.pos.x = axis_f_dimensions[0]

        # axis_g
        axis_g_dimensions = get_joint_hypo_length(
            JOINT_OFFSET_F), JOINT_SIZE_G[1], JOINT_SIZE_G[2]
        axis_g_geometry = create_joint_rectangle(axis_g_dimensions[0],
                                                 axis_g_dimensions[1],
                                                 axis_g_dimensions[2])
        material = Material(color=(1., .4, .1),
                            diffuse=(1., .4, .1),
                            specular=(.35, .35, .35))
        axis_g_mesh = Mesh(axis_g_geometry, material)
        self.joints.append(axis_g_mesh)

        axis_g_mesh.add(axis_f_mesh)
        axis_f_mesh.pos.x = axis_g_dimensions[0]
        axis_f_mesh.rotation.z = -90

        # base
        base_dimensions = 0.05, axis_b_dimensions[1], axis_b_dimensions[2]
        base_geometry = create_joint_rectangle(base_dimensions[0],
                                               base_dimensions[1],
                                               base_dimensions[2])
        material = Material(color=(0., 1., 1.),
                            diffuse=(0., 1., 1.),
                            specular=(.35, .35, .35))
        base_mesh = Mesh(base_geometry, material)
        self.joints.append(base_mesh)

        base_mesh.add(axis_g_mesh)
        base_mesh.rotation.z = 90

        axis_g_mesh.pos.x = base_dimensions[0]
        axis_g_mesh.rotation.z = -90

        return base_mesh
Beispiel #13
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
Beispiel #14
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

        # black cube with red reflections
        # and half-transparent
        cube_geo = BoxGeometry(.3, .3, .3)
        cube_mat = Material(
            transparency=0.5,
            color=(0, 0, 0),  # base color
            specular=(10, 0, 0)  # mirror-like reflections
        )
        self.cubes.append(Mesh(
            geometry=cube_geo,
            material=cube_mat
        ))  # default pos == (0, 0, 0)
        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

        cube_geo = BoxGeometry(.3, .3, .3)
        cube_mat = Material(
            transparency=0.5,
            color=(0, 0, 0),  # base color
            specular=(10, 0, 0)
        )
        self.main_cube = Mesh(
            geometry=cube_geo,
            material=cube_mat
        )  # default pos == (0, 0, 0)
        self.main_cube.rotation.x = 45
        self.main_cube.rotation.y = 45
        self.main_cube.pos.z = -5
        scene.add(self.main_cube)

        plane_geo = BoxGeometry(5, 5, .1)
        plane_mat = Material(
            color=(1, 1, 1)  # base color
        )
        plane = Mesh(
            geometry=plane_geo,
            material=plane_mat
        )
        plane.pos.z = -10
        scene.add(plane)

        # 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(Widget())
        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
Beispiel #15
0
    def make_3d(self, clock=None):

        #self.root = FloatLayout()
        self.renderer = Renderer()
        self.renderer.set_clear_color((.2, .2, .2, 1.))

        self.scene = Scene()

        #geometry = BoxGeometry(0.5, 0.5, 0.5)
        geometry = SphereGeometry(0.1)
        material = Material(color=(0., 0., 1.),
                            diffuse=(1., 1., 0.),
                            specular=(.35, .35, .35))
        """
        a = 5
        liste = []
        i = 0
        for z in range(-5, -35, -1):
            for x in range(-5, 5):
                liste.append(Mesh(geometry, material))
                liste[-1].pos.x = x
                liste[-1].pos.y = -i
                liste[-1].pos.z = z
                print(x, -i, z)
                self.scene.add(liste[-1])
            i+=1
        """
        #!erster test für errecnete Daten
        liste = []
        for z in range(0, int(Global.config["maxy"])):
            #for z in range(0, 10):
            #i = 0
            test = calculationClass.find_mistakes_along_x_axis(z)
            #print(test)
            for x, y, rad in calculationClass.find_mistakes_along_x_axis(z):
                #for x, y in [[1, 2], [2, 0], [2.314, 5], [3, 0], [3.123, 4]]:
                #for x, y in [[1, 2], [2, 0], [3, 0]]:
                #for x in [8.06158101842821, 4.06158101842821, 0.09813725490196079]:
                #for x in test[:][0]:
                #for line in test[:10]:
                #x = line[0]
                x = float(x)
                y = float(y)
                #x = 8.06158101842821
                #new_list.append([x, y, z, rad])
                rad = 1
                #y = 0
                z += 5
                liste.append(Mesh(geometry, material))
                #liste[-1].pos.x = x - 8
                liste[-1].pos.x = -z
                liste[-1].pos.y = y
                liste[-1].pos.z = x
                #print(x, y, z)
                self.scene.add(liste[-1])
                #i += 1

        self.renderer.render(self.scene, self.camera)

        self.renderer.bind(size=self._adjust_aspect)

        self.layout.add_widget(self.renderer)

        print(liste[0])
        print(liste[0].pos)
        #self.look_at = liste[0].pos

        #self.look_at.x = liste[0][0]
        #self.look_at.y = liste[0][1]
        #self.look_at.z = liste[0][2]
        #self.camera.look_at(self.look_at)
        #test = (liste[0][0], liste[0][1], liste[0][2])
        #a = tuple(liste[0].pos)
        #print(a)
        #self.camera.look_at(a)
        #self.look_at.x = liste[0].pos.x
        #self.look_at.y = liste[0].pos.y
        #self.look_at.z = liste[0].pos.z
        self.look_at = Vector3(0, 0, -1)

        #self.camera.look_at(self.look_at)

        #self.add_widget(self.root)
        print("here")
Beispiel #16
0
    def convert_to_mesh(self, vertex_format=None):
        """Converts data gotten from the .obj definition
        file and create Kivy3 Mesh object which may be used
        for drawing object in the scene
        """

        geometry = Geometry()
        material = Material()
        mtl_dirname = os.path.abspath(os.path.dirname(self.loader.mtl_source))

        v_idx = 0
        # create geometry for mesh
        for f in self.faces:
            verts = f[0]
            norms = f[1]
            tcs = f[2]
            face3 = Face3(0, 0, 0)
            for i, e in enumerate(['a', 'b', 'c']):
                #get normal components
                n = (0.0, 0.0, 0.0)
                if norms[i] != -1:
                    n = self.loader.normals[norms[i] - 1]
                face3.vertex_normals.append(n)

                #get vertex components
                v = self.loader.vertices[verts[i] - 1]
                geometry.vertices.append(v)
                setattr(face3, e, v_idx)
                v_idx += 1

                #get texture coordinate components
                t = (0.0, 0.0)
                if tcs[i] != -1:
                    t = self.loader.texcoords[tcs[i] - 1]
                tc = Vector2(t[0], 1. - t[1])
                geometry.face_vertex_uvs[0].append(tc)

            geometry.faces.append(face3)

        # apply material for object
        if self.mtl_name in self.loader.mtl_contents:
            raw_material = self.loader.mtl_contents[self.mtl_name]
            for k, v in raw_material.iteritems():
                _k = self._mtl_map.get(k, None)
                if k in [
                        "map_Kd",
                ]:
                    map_path = os.path.join(mtl_dirname, v[0])
                    tex = Image(map_path).texture
                    material.map = tex
                    continue
                if _k:
                    if len(v) == 1:
                        v = float(v[0])
                        if k == 'Tr':
                            v = 1. - v
                        setattr(material, _k, v)
                    else:
                        v = map(lambda x: float(x), v)
                        setattr(material, _k, v)
        mesh = Mesh(geometry, material)
        return mesh
Beispiel #17
0
    def convert_to_mesh(
        self,
        vertex_format=None
    ):  # Ripped from kivy3/loaders/objloader.py and edited by GJ
        """Converts data gotten from the ._obj definition
        file and create Kivy3 Mesh object which may be used
        for drawing object in the scene
        """

        geometry = Geometry()
        material = Material()
        mtl_dirname = abspath(
            dirname(self.loader.mtl_source
                    ))  # We don't need this as we arnt loading any images
        # but just in case we keep it

        v_idx = 0
        # create geometry for mesh
        for f in self.faces:
            verts = f[0]
            norms = f[1]
            tcs = f[2]
            face3 = Face3(0, 0, 0)
            for i, e in enumerate(['a', 'b', 'c']):
                # get normal components
                n = (0.0, 0.0, 0.0)
                if norms[i] != -1:
                    n = self.loader.normals[norms[i] - 1]
                face3.vertex_normals.append(n)

                # get vertex components
                v = self.loader.vertices[verts[i] - 1]
                geometry.vertices.append(v)
                setattr(face3, e, v_idx)
                v_idx += 1

                # get texture coordinate components
                t = (0.0, 0.0)
                if tcs[i] != -1:
                    t = self.loader.texcoords[tcs[i] - 1]
                tc = Vector2(t[0], 1. - t[1])
                geometry.face_vertex_uvs[0].append(tc)

            geometry.faces.append(face3)

        # apply material for object
        if self.mtl_name in self.loader.mtl_contents:
            raw_material = self.loader.mtl_contents[self.mtl_name]
            # shader ignores values
            zeros = [
                '0', '0.0', '0.00', '0.000', '0.0000', '0.00000', '0.000000'
            ]
            for k, v in raw_material.items():
                _k = self._mtl_map.get(k, None)
                if k in [
                        "map_Kd",
                ]:
                    self.log_warning(
                        "the tag map_kd should not be used as a material, use map_id and give the texture"
                        " type (ini section and option)")
                    map_path = join(mtl_dirname, v[0])
                    if not exists(map_path):
                        msg = u'Texture not found <{}>'
                        self.log_warning(msg.format(map_path))
                        continue
                    tex = Image(map_path).texture
                    material.map = tex
                    continue
                if k in [
                        "map_id",
                ]:

                    tex = self.textures.get("Materials", str(v[0]))
                    material.map = tex

                if _k:
                    if len(v) == 1:
                        v[0] = '0.000001' if v[0] in zeros else v[0]
                        v = float(v[0])
                        if k == 'Tr':
                            v = 1. - v
                        setattr(material, _k, v)
                    else:
                        v = list(map(lambda x: float(x), v))
                        setattr(material, _k, v)

        if not material.map:
            self.log_warning(
                "No material given or used wrong name -", self.mtl_name,
                "(if nothing here then you "
                "provided no mtl file)")
            material.map = Image(objLoader_folder + '/empty.png').texture
            material.texture_ratio = 0.0
        mesh = Mesh(geometry, material)
        return mesh
Beispiel #18
0
    def build(self):
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(45, 1, 0.1, 2500)
        self.renderer.set_clear_color(clear_color)

        self.camera = camera

        root = ObjectTrackball(camera, 10, self.renderer)

        id_color = (0, 0, 0x7F)
        geometry = BoxGeometry(1, 1, 1)
        material = Material(color=(1., 1., 1.),
                            diffuse=(1., 1., 1.),
                            specular=(.35, .35, .35),
                            id_color=id_color,
                            shininess=1.)
        obj = Mesh(geometry, material)
        scene.add(obj)
        root.object_list.append({'id': id_color, 'obj': obj})

        id_color = (0, 0x7F, 0)
        geometry = BoxGeometry(1, 1, 1)
        material = Material(color=(0., 0., 1.),
                            diffuse=(0., 0., 1.),
                            specular=(.35, .35, .35),
                            id_color=id_color,
                            shininess=1.)
        obj = Mesh(geometry, material)
        obj.position.x = 2
        scene.add(obj)
        root.object_list.append({'id': id_color, 'obj': obj})

        # create a grid on the xz plane
        geometry = GridGeometry(size=(30, 30), spacing=1)
        material = Material(color=(1., 1., 1.),
                            diffuse=(1., 1., 1.),
                            specular=(.35, .35, .35),
                            transparency=.5)
        lines = Lines(geometry, material)
        lines.rotation.x = 90
        scene.add(lines)

        geometry = Geometry()
        geometry.vertices = [[0.0, 0.0, 0.0], [3.0, 0.0, 0.0]]
        geometry.lines = [Line2(a=0, b=1)]
        material = Material(color=(1., 0., 0.),
                            diffuse=(1., 0., 0.),
                            specular=(.35, .35, .35))
        lines = Lines(geometry, material)
        lines.position.y = -0.01
        scene.add(lines)

        geometry = Geometry()
        geometry.vertices = [[0.0, 0.0, 0.0], [0.0, 3.0, 0.0]]
        geometry.lines = [Line2(a=0, b=1)]
        material = Material(color=(0., 1., 0.),
                            diffuse=(0., 1., 0.),
                            specular=(1., 1.0, 1.0))
        lines = Lines(geometry, material)
        scene.add(lines)

        geometry = Geometry()
        geometry.vertices = [[0.0, 0.0, 0.0], [0.0, 0.0, 3.0]]
        geometry.lines = [Line2(a=0, b=1)]
        material = Material(color=(0., 0., 1.),
                            diffuse=(0., 0., 1.),
                            specular=(.35, .35, .35))
        lines = Lines(geometry, material)
        lines.position.y = -0.01
        scene.add(lines)

        self.renderer.render(scene, camera)
        self.renderer.main_light.intensity = 1000
        self.renderer.main_light.pos = (10, 10, -10)

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)

        return root
Beispiel #19
0
    def convert_to_mesh(self, vertex_format=None):
        """Converts data gotten from the .obj definition
        file and create Kivy3 Mesh object which may be used
        for drawing object in the scene
        """

        geometry = Geometry()
        material = Material()
        mtl_dirname = abspath(dirname(self.loader.mtl_source))

        v_idx = 0
        # create geometry for mesh
        for f in self.faces:
            verts = f[0]
            norms = f[1]
            tcs = f[2]
            face3 = Face3(0, 0, 0)
            for i, e in enumerate(['a', 'b', 'c']):
                # get normal components
                n = (0.0, 0.0, 0.0)
                if norms[i] != -1:
                    n = self.loader.normals[norms[i] - 1]
                face3.vertex_normals.append(n)

                # get vertex components
                v = self.loader.vertices[verts[i] - 1]
                geometry.vertices.append(v)
                setattr(face3, e, v_idx)
                v_idx += 1

                # get texture coordinate components
                t = (0.0, 0.0)
                if tcs[i] != -1:
                    t = self.loader.texcoords[tcs[i] - 1]
                tc = Vector2(t[0], 1. - t[1])
                geometry.face_vertex_uvs[0].append(tc)

            geometry.faces.append(face3)

        # apply material for object
        if self.mtl_name in self.loader.mtl_contents:
            raw_material = self.loader.mtl_contents[self.mtl_name]
            # shader ignores values
            zeros = ['0', '0.0', '0.00', '0.000', '0.0000',
                     '0.00000', '0.000000']
            for k, v in raw_material.items():
                _k = self._mtl_map.get(k, None)
                # TODO: also handle map_Ka and map_Ks
                if k in ["map_Kd", ]:
                    # TODO: map file path may contains spaces.
                    #      current implementation fails.
                    map_path = join(mtl_dirname, v[0])
                    if not exists(map_path):
                        msg = u'WaveObject: Texture not found <{}>'
                        Logger.warning(msg.format(map_path))
                        continue
                    tex = Image(map_path).texture
                    material.map = tex
                    continue
                if _k:
                    if len(v) == 1:
                        v[0] = '0.000001' if v[0] in zeros else v[0]
                        v = float(v[0])
                        if k == 'Tr':
                            v = 1. - v
                        setattr(material, _k, v)
                    else:
                        v = list(map(lambda x: float(x), v))
                        setattr(material, _k, v)

        if not material.map:
            material.map = Image(folder + '/empty.png').texture
            material.texture_ratio = 0.0
        mesh = Mesh(geometry, material)
        return mesh