示例#1
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))
示例#2
0
    def build(self):
        root = BaseBox()

        self.renderer = Renderer(shader_file=shader_file)
        self.renderer.set_clear_color((.2, .2, .2, 1.))
        self.scene = Scene()

        self.manipulator = self.construct_manipulator()

        camera = PerspectiveCamera(75, 0.01, 0.01, 1500)
        trackball = ObjectTrackball(camera, 2)

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

        self.renderer.main_light.intensity = 3000

        trackball.add_widget(self.renderer)
        root.add_widget(trackball)

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

        root.joints = self.joints
        root.renderer = self.renderer
        return root
示例#3
0
文件: monkey.py 项目: KeyWeeUsr/kivy3
class MainApp(App):

    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

    def _update_obj(self, dt):
        obj = self.monkey
        if obj.pos.z > -30:
            obj.pos.z -= 0.5

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect
示例#4
0
文件: main.py 项目: KeyWeeUsr/kivy3
class MainApp(App):

    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        loader = OBJMTLLoader()
        obj = loader.load(obj_file, mtl_file)

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

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

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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect

    def _rotate_obj(self, dt):
        self.orion.rot.x += 2
示例#5
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
示例#6
0
文件: example3.py 项目: sulik011/pong
class MainApp(App):

    def build(self):
        root = FloatLayout()
        self.renderer = Renderer()
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        # load obj file
        loader = OBJMTLLoader()
        obj_path = os.path.join(os.path.dirname(__file__), "./testnurbs.obj")
        obj = loader.load(obj_path, "./testnurbs.mtl")

        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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        with self.canvas.before:
            # sfondo
            Color(0, 0, 0)
            self.background = Rectangle()
            # colore del modello
            Color(.9, .9, 1)

        # renderer
        self.renderer = Renderer(shader_file="glContext\\simple.glsl")

        # scene
        self.scene = Scene()

        # objects
        self.objects = Objects_list()
        self.object_father = self.objects.get()

        # adding objects to scene
        self.scene.add(self.object_father)

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

        # rendering
        self.renderer.render(self.scene, self.camera)
        self.renderer.bind(size=self._adjust_aspect)
        self.add_widget(self.renderer)
示例#8
0
    def __init__(self, root, **kwargs):
        super().__init__(root)
        self.path = 'forge/embyr/'
        self.glSetup()
        self.camera = PerspectiveCamera(30, 1, 10, 1000)
        #self.transform = Transform()
        self.transform = Transform(pos=[8, 20, 8], lookvec=[40, 10, 40])

        pos = kwargs.pop('pos', None)
        size = kwargs.pop('size', None)
        #pos_hint = {'right':ww, 'bottom':hh}
        self.renderer = Renderer(shader_file=self.path + shaderf)
        #self.renderer.pos_hint = pos_hint

        self.scene = Scene()
        #self.renderer.size_hint = (0.5, 0.5)
        self.transform.size = (0, 0)
        self.transform.size_hint = (0, 0)

        self.renderer.render(self.scene, self.camera)
        self.renderer.bind(size=self._adjust_aspect)
        self.renderer.size_hint = size
        self.renderer.pos = pos

        #self.renderer.pos = (256, 256)

        self.root.add_widget(self.renderer)
        self.root.add_widget(self.transform)
示例#9
0
class MainApp(App):
    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

    def _update_obj(self, dt):
        obj = self.monkey
        if obj.pos.z > -30:
            obj.pos.z -= 0.5

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect
示例#10
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
示例#11
0
class MainApp(App):

    def build(self):
        self.renderer = Renderer()
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 100, 2500)
        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)
        self.renderer.main_light.intensity = 500

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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect
示例#12
0
文件: main.py 项目: ElHacker/PTAM
    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
示例#13
0
文件: my3D.py 项目: guifon1000/my3D
    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
示例#14
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
示例#15
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
示例#16
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
示例#17
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
示例#18
0
class MainApp(App):
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        loader = OBJMTLLoader()
        obj = loader.load(obj_file, mtl_file)

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

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

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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect

    def _rotate_obj(self, dt):
        self.orion.rot.x += 2
示例#19
0
文件: main.py 项目: simudream/kivy3
class MainApp(App):

    def build(self):
        self.look_at = Vector3(0, 0, -1)
        root = FloatLayout()
        self.renderer = Renderer(shader_file="../textures/simple.glsl")
        scene = Scene()
        self.camera = PerspectiveCamera(75, 1, 1, 1000)
        self.camera.pos.z = 5
        loader = OBJMTLLoader()
        obj = loader.load("../textures/orion.obj", "../textures/orion.mtl")
        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)

        scene.add(*obj.children)

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

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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect

    def _keyboard_closed(self):
        self._keyboard.unbind(on_key_down=self._on_keyboard_down)
        self._keyboard = None

    def _on_keyboard_down(self,  keyboard, keycode, text, modifiers):
        if  keycode[1] == 'w':
            self.camera.pos.z -= 0.2
        elif keycode[1] == 's':
            self.camera.pos.z += 0.2
        elif keycode[1] == 'a':
            self.camera.pos.x -= 0.2
        elif keycode[1] == 'd':
            self.camera.pos.x += 0.2

        elif keycode[1] == 'up':
            self.look_at.y += 0.2
        elif keycode[1] == 'down':
            self.look_at.y -= 0.2
        elif keycode[1] == 'right':
            self.look_at.x += 0.2
        elif keycode[1] == 'left':
            self.look_at.x -= 0.2

        self.camera.look_at(self.look_at)

    def _rotate_obj(self, dt):
        self.orion.rot.x += 2
        self.orion.rot.z += 2
示例#20
0
文件: main.py 项目: nskrypnik/kivy3
class MainApp(App):

    def build(self):
        self.look_at = Vector3(0, 0, -1)
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        self.camera = PerspectiveCamera(75, 1, 1, 1000)
        self.camera.pos.z = 5
        loader = OBJMTLLoader()
        obj = loader.load(obj_file, mtl_file)
        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)

        scene.add(*obj.children)

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

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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect

    def _keyboard_closed(self):
        self._keyboard.unbind(on_key_down=self._on_keyboard_down)
        self._keyboard = None

    def _on_keyboard_down(self,  keyboard, keycode, text, modifiers):
        if  keycode[1] == 'w':
            self.camera.pos.z -= 0.2
        elif keycode[1] == 's':
            self.camera.pos.z += 0.2
        elif keycode[1] == 'a':
            self.camera.pos.y -= 0.2
        elif keycode[1] == 'd':
            self.camera.pos.y += 0.2

        elif keycode[1] == 'up':
            self.look_at.y += 0.2
        elif keycode[1] == 'down':
            self.look_at.y -= 0.2
        elif keycode[1] == 'right':
            self.look_at.x += 0.2
        elif keycode[1] == 'left':
            self.look_at.x -= 0.2

        self.camera.look_at(self.look_at)

    def _rotate_obj(self, dt):
        self.orion.rot.x += 2
        self.orion.rot.z += 2
示例#21
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))
示例#22
0
    def load_level(self, level):
        self.level = level
        self.inputVector = Vector3([0, 0, 0])

        # (re)create renderer
        if self.renderer:
            self.remove_widget(self.renderer)
        self.renderer = Renderer(size_hint=(5, 5), shader_file="flat.glsl")
        self.add_widget(self.renderer, index=1)
        self.renderer.set_clear_color((0, 0, 0, 1))  # rgba

        # e.g. when added to parent
        self.renderer.bind(size=self._adjust_aspect)

        self.renderer.render(level.scene, level.camera)
        self.resizeRenderer()
示例#23
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer()
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        # load obj file
        loader = OBJLoader()
        obj_path = os.path.join(os.path.dirname(__file__), "./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
示例#24
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
示例#25
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
示例#26
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
示例#27
0
class My3D(App):
    def _adjust_aspect(self, *args):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect

    def rotate_cube(self, *dt):
        self.cube.rotation.y += 1

    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)  # default pos == (0, 0, 0)
        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 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.rotate_cube, .01)
        return layout
示例#28
0
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        loader = OBJMTLLoader()
        obj = loader.load(obj_file, mtl_file)

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

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

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        Clock.schedule_interval(self._rotate_obj, 1 / 20)
        return root
示例#29
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
示例#30
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
示例#31
0
class MainApp(App):
    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

    def _update_obj(self, dt):
        obj = self.my_obj
        if obj.pos.z > -2:
            obj.pos.z -= 0.5
        else:
            obj.rotation.y += 1
            obj.rotation.x += 0.5

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect
示例#32
0
    def build(self):
        camera = PerspectiveCamera(30, 1, 1, 1000)
        self.renderer = Renderer()
        self.scene = Scene()
        root = FloatLayout()

        obj = self.loader.load('tex/nn.obj', 'tex/nn.mtl')
        self.scene.add(obj)
        obj.pos.y = 1
        self.makeMap()

        self.renderer.render(self.scene, camera)
        self.renderer.camera.look_at(0, 0, 0)
        root.add_widget(self.renderer)
        root.add_widget(self.pan)
        root.add_widget(self.rotate)
        root.add_widget(self.zoom)
        self.renderer.bind(size=self._adjust_aspect)
        self.loop(self.update)
        return root
示例#33
0
    def build(self):
        self.look_at = Vector3(0, 0, -1)
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        self.camera = PerspectiveCamera(75, 1, 1, 1000)
        self.camera.pos.z = 5
        loader = OBJMTLLoader()
        obj = loader.load(obj_file, mtl_file)
        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)

        scene.add(*obj.children)

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

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        Clock.schedule_interval(self._rotate_obj, 1 / 20)
        return root
示例#34
0
class SceneApp(App):

    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., 0., 1.), diffuse=(1., 1., 0.),
                            specular=(.35, .35, .35))
        self.cube = Mesh(geometry, material)
        self.cube.pos.z = -5
        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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect

    def _rotate_cube(self, dt):
        self.cube.rotation.x += 1
        self.cube.rotation.y += 1
        self.cube.rotation.z += 1
示例#35
0
class SceneApp(App):
    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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect

    def _rotate_cube(self, dt):
        self.cube.rotation.x += 1
        self.cube.rotation.y += 1
        self.cube.rotation.z += 1
示例#36
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
示例#37
0
class MainApp(App):

    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

    def _adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect
示例#38
0
文件: monkey.py 项目: KeyWeeUsr/kivy3
    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
示例#39
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
示例#40
0
	def build(self):
		box= BoxLayout(orientation='vertical')
		layout = GridLayout(cols=5)
		layout.add_widget(Button(text='rotx',on_press=self.stop_rotx))
		layout.add_widget(Button(text='roty',on_press=self.stop_roty))
		layout.add_widget(Button(text='up',on_press=self.up))
		layout.add_widget(Button(text='down',on_press=self.dn))
		layout.add_widget(Button(text='xpos',on_press=self.xp))
		layout.add_widget(Button(text='xneg',on_press=self.xm))
		layout.add_widget(PongGame(text='keyboard'))
		box.add_widget(layout)
		root = FloatLayout()
		box.add_widget(root)
		self.renderer = Renderer(shader_file="simple.glsl")
		print "self.renderr"
		dir(self.renderer)
		
		# hintergrund 
		self.renderer. set_clear_color((0.9,1,1, 1));
		
		scene = Scene()
		camera = PerspectiveCamera(45, 1, 1, 1000)
		camera.position=(0,0,90)
		self.camera=camera
		#loader = OBJMTLLoader()
		#obj = loader.load("my_colors.obj", "my_colors.mtl")

		loader = OBJLoader()
		#obj = loader.load("my_colors.obj")
		#obj = loader.load("Cube.obj")
		#obj = loader.load("Fusion003.obj")
		obj = loader.load(file)

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

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

		root.add_widget(self.renderer)
		self.renderer.bind(size=self._adjust_aspect)
		Clock.schedule_interval(self._rotate_obj, 1 / 20)
		return box
示例#41
0
文件: example3.py 项目: 3demax/kivy3
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer()
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        # load obj file
        loader = OBJMTLLoader()
        obj_path = os.path.join(os.path.dirname(kivy3.__file__), "tests/testnurbs.obj")
        obj = loader.load(obj_path, "testnurbs.mtl")

        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
示例#42
0
文件: main.py 项目: KeyWeeUsr/kivy3
    def build(self):
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        loader = OBJMTLLoader()
        obj = loader.load(obj_file, mtl_file)

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

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

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        Clock.schedule_interval(self._rotate_obj, 1 / 20)
        return root
示例#43
0
文件: kpilotgui.py 项目: aaaler/k9
    def gsensor_init(self):
        pilot.send ("GSENSOR ON")
        self.renderer = Renderer(shader_file="3d/simple.glsl")
        scene = Scene()
        # load obj file
        loader = OBJLoader()
        obj = loader.load("3d/k9.obj")
        self.k9obj = obj.children[0]

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

        self.renderer.size_hint = (None,None)
        self.renderer.pos_hint = {'right' : .99, 'y': 0.4}
        self.renderer.render(scene, camera)
        self.renderer.size = (300,300)

        self.add_widget(self.renderer)
        Clock.schedule_interval(self.gsensor_3d_update, 1. / 20)
        self.renderer.bind(size=self.gsensor_3d_adjust_aspect)
示例#44
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., 0., 1.), diffuse=(1., 1., 0.),
                            specular=(.35, .35, .35))
        self.cube = Mesh(geometry, material)
        self.cube.pos.z = -5
        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
示例#45
0
文件: main.py 项目: nskrypnik/kivy3
    def build(self):
        self.look_at = Vector3(0, 0, -1)
        root = FloatLayout()
        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        self.camera = PerspectiveCamera(75, 1, 1, 1000)
        self.camera.pos.z = 5
        loader = OBJMTLLoader()
        obj = loader.load(obj_file, mtl_file)
        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)

        scene.add(*obj.children)

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

        root.add_widget(self.renderer)
        self.renderer.bind(size=self._adjust_aspect)
        Clock.schedule_interval(self._rotate_obj, 1 / 20)
        return root
示例#46
0
文件: kpilotgui.py 项目: aaaler/k9
class RootLayout(FloatLayout):
    mainview_log = ObjectProperty()
    speed = ObjectProperty()
    rot_speed = ObjectProperty()
    statslabel = ObjectProperty()
    label1 = ObjectProperty()
    fpvideo = ObjectProperty()
    bVid = ObjectProperty()
    log = ObjectProperty()
    console_input  = ObjectProperty()
    logstream = io.StringIO()
    console_log  = ObjectProperty()
    joy1 = ObjectProperty()
    bHWJ = ObjectProperty()
    
    
#    def on_logstream(self, *args):
#        self.mainview_log.text = self.logstream.getvalue()
    def __init__(self, *args, **kwargs):
        super(RootLayout, self).__init__(**kwargs)
    
    def delayed_init (self):
        pygame.joystick.init()
        if pygame.joystick.get_count() > 0:
            self.bHWJ.disabled = False        
            self.log.info (u"Hardware joysticks available: {}".format(pygame.joystick.get_count()) )

    def gsensor_init(self):
        pilot.send ("GSENSOR ON")
        self.renderer = Renderer(shader_file="3d/simple.glsl")
        scene = Scene()
        # load obj file
        loader = OBJLoader()
        obj = loader.load("3d/k9.obj")
        self.k9obj = obj.children[0]

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

        self.renderer.size_hint = (None,None)
        self.renderer.pos_hint = {'right' : .99, 'y': 0.4}
        self.renderer.render(scene, camera)
        self.renderer.size = (300,300)

        self.add_widget(self.renderer)
        Clock.schedule_interval(self.gsensor_3d_update, 1. / 20)
        self.renderer.bind(size=self.gsensor_3d_adjust_aspect)

    def gsensor_3d_adjust_aspect(self, inst, val):
        rsize = self.renderer.size
        aspect = rsize[0] / float(rsize[1])
        self.renderer.camera.aspect = aspect

    def gsensor_3d_update(self,dt):
        obj = self.k9obj
        if obj.pos.z > -30:
            obj.pos.z -= 0.5
#        obj.rotation.y += 0.5


    def gsensor_stop(self):
        pilot.send ("GSENSOR OFF")
        self.remove_widget(self.renderer)
        self.renderer = None
        pass


    def hwjoystick_init (self):
        if pygame.joystick.get_count() > 0:
            hwjoystick = pygame.joystick.Joystick(0)
            pygame.event.pump()
            hwjoystick.init()
            pygame.event.pump()
            joyname=hwjoystick.get_name()  
            self.log.info (u"Hardware joystick enabled: {}.".format(joyname))
            self.joy1.hwjoystick_init(hwjoystick)
        else:
            self.hwjoystick = False


    def ConsoleCmd (self, data):
        data = unicode (data,'utf-8');
        if data == "" : return False
        self.log.debug (u"Console input {}".format(data))
        request = data.split(' ');
        cmd = request.pop(0).lower() 
        cmd = cmd.strip("\n")
        if (data[0:1] == '-'):
            pilot.send ("SAY "+pickle.dumps(data[1:]))
            self.log.info (u"Pronouncing {}".format(data[1:])) 
        elif cmd == 'q' or cmd == 'quit':
            App.get_running_app().stop()
        elif cmd == 'send':
            pkt = ' '.join(request)
            pilot.send (pkt)
            self.log.info (u"Sent: {}".format(pkt))
        elif cmd == '?' or cmd == 'eval':
            cmd = " ".join(request)
            try:
                output = eval("pprint.pformat({})".format(cmd))
                self.log.info (u"{} = {}".format(cmd, output))
            except Exception, e:
                self.log.error(u"eval \"{}\" raised {} Exception: {}".format(cmd,type(e).__name__ ,e))
        elif cmd == '!' or cmd == 'exec':
            cmd = " ".join(request)
            try:
                exec(cmd)
                self.log.info (u"Executed: {}".format(cmd))
            except Exception, e:
                self.log.error(u"exec \"{}\" raised {} Exception: {}".format(cmd,type(e).__name__ ,e))
示例#47
0
class ImuView(BoxLayout):
    ACCELX_SCALING = 5.0
    ACCELY_SCALING = 1.0
    ACCELZ_SCALING = 2.0
    GYRO_SCALING = 1.0
    ZOOM_SCALING = 0.2
    TOUCHWHEEL_ZOOM_MULTIPLIER = 1
    ROTATION_SCALING = 0.2
    DRAG_CUSTOMIZE_THRESHOLD = 10

    position_x = NumericProperty(0)
    position_y = NumericProperty(-0.30)
    position_z = NumericProperty(-5.0)
    rotation_x = NumericProperty(-5)
    rotation_y = NumericProperty(180)
    rotation_z = NumericProperty(0)

    accel_x = NumericProperty(0)
    accel_y = NumericProperty(0)
    accel_z = NumericProperty(0)

    accel = ReferenceListProperty(accel_x, accel_y, accel_z)
    imu_obj = ObjectProperty()

    gyro_yaw = NumericProperty(0)
    gyro_pitch = NumericProperty(0)
    gyro_roll = NumericProperty(0)
    gyro = ReferenceListProperty(gyro_yaw, gyro_pitch, gyro_roll)
    model_path = StringProperty()

    def __init__(self, **kwargs):
        super(ImuView, self).__init__(**kwargs)
        self._touches = []
        self.imu_obj = None
        self.size_scaling = 1
        self.init_view()
        self.register_event_type('on_customize')
        self._total_drag_distance = 0
        self._last_button = None

    def on_customize(self):
        pass

    def init_view(self):
        Window.bind(on_motion=self.on_motion)

    def cleanup_view(self):
        Window.unbind(on_motion=self.on_motion)

    def on_model_path(self, instance, value):
        self._setup_object()

    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))


    def _adjust_aspect(self, instance, value):
        rsize = self.renderer.size
        width = max(1, rsize[0])
        height = max(1, rsize[1])
        if height == 0:
            return
        self.renderer.camera.aspect = width / float(height)
        self.size_scaling = 1 / float(dp(1))  # width /  (width * height) / (Window.size[0] * Window.size[1])

    @property
    def _zoom_scaling(self):
        return self.size_scaling * ImuView.ZOOM_SCALING

    def define_rotate_angle(self, touch):
        x_angle = (touch.dx / self.width) * 360
        y_angle = -1 * (touch.dy / self.height) * 360
        return x_angle, y_angle

    def on_touch_down(self, touch):
        super(ImuView, self).on_touch_down(touch)
        if self._last_button == 'left' or self._last_button == None:
            self._total_drag_distance = 0

        x, y = touch.x, touch.y
        if self.collide_point(x, y):
            touch.grab(self)
            self._touches.append(touch)
            return True
        return False

    def on_touch_up(self, touch):
        super(ImuView, self).on_touch_up(touch)
        x, y = touch.x, touch.y

        # remove it from our saved touches
        if touch in self._touches:  # and touch.grab_state:
            touch.ungrab(self)
            self._touches.remove(touch)

        # stop propagating if its within our bounds
        if self.collide_point(x, y):
            if self._total_drag_distance < ImuView.DRAG_CUSTOMIZE_THRESHOLD:
                self.dispatch('on_customize')
                self._total_drag_distance = ImuView.DRAG_CUSTOMIZE_THRESHOLD

            return True

        return False

    def on_touch_move(self, touch):
        Logger.debug("dx: %s, dy: %s. Widget: (%s, %s)" % (touch.dx, touch.dy, self.width, self.height))
        self._total_drag_distance += abs(touch.dx) + abs(touch.dy)

        if touch in self._touches and touch.grab_current == self:
            if len(self._touches) == 1:
                # here do just rotation
                ax, ay = self.define_rotate_angle(touch)

                self.rotation_x -= (ay * ImuView.ROTATION_SCALING)
                self.rotation_y += (ax * ImuView.ROTATION_SCALING)

                # ax, ay = math.radians(ax), math.radians(ay)

            elif len(self._touches) == 2:  # scaling here
                # use two touches to determine do we need scal
                touch1, touch2 = self._touches
                old_pos1 = (touch1.x - touch1.dx, touch1.y - touch1.dy)
                old_pos2 = (touch2.x - touch2.dx, touch2.y - touch2.dy)

                old_dx = old_pos1[0] - old_pos2[0]
                old_dy = old_pos1[1] - old_pos2[1]

                old_distance = (old_dx * old_dx + old_dy * old_dy)

                new_dx = touch1.x - touch2.x
                new_dy = touch1.y - touch2.y

                new_distance = (new_dx * new_dx + new_dy * new_dy)

                if new_distance > old_distance:
                    scale = 1 * self._zoom_scaling
                elif new_distance == old_distance:
                    scale = 0
                else:
                    scale = -1 * self._zoom_scaling

                if scale:
                    self.position_z += scale

    def on_motion(self, instance, event, motion_event):

        if motion_event.x > 0 and motion_event.y > 0 and self.collide_point(motion_event.x, motion_event.y):
            try:
                button = motion_event.button
                self._last_button = button
                SCALE_FACTOR = 0.1
                z_distance = self._zoom_scaling * ImuView.TOUCHWHEEL_ZOOM_MULTIPLIER
                if button == 'scrollup':
                    self.position_z += z_distance
                    self._total_drag_distance += 100
                else:
                    if button == 'scrolldown':
                        self.position_z -= z_distance
            except:
                pass  # no scrollwheel support


    def on_position_x(self, instance, value):
        try:
            self.imu_obj.pos.x = value
        except AttributeError:
            pass

    def on_position_y(self, instance, value):
        try:
            self.imu_obj.pos.y = value
        except AttributeError:
            pass

    def on_position_z(self, instance, value):
        try:
            self.imu_obj.pos.z = value
        except AttributeError:
            pass

    def on_rotation_x(self, instance, value):
        try:
            self.imu_obj.rotation.x = value
        except AttributeError:
            pass

    def on_rotation_y(self, instance, value):
        try:
            self.imu_obj.rotation.y = value
        except AttributeError:
            pass

    def on_rotation_z(self, instance, value):
        try:
            self.imu_obj.rotation.z = value
        except AttributeError:
            pass

    def on_accel_x(self, instance, value):
        try:
            self.imu_obj.pos.z = self.position_z - (value * ImuView.ACCELX_SCALING)
        except AttributeError:
            pass

    def on_accel_y(self, instance, value):
        try:
            self.imu_obj.pos.x = self.position_x + (value * ImuView.ACCELY_SCALING)
        except AttributeError:
            pass

    def on_accel_z(self, instance, value):
        try:
            # subtract 1.0 to compensate for gravity
            self.imu_obj.pos.y = self.position_y - ((value - 1.0) * ImuView.ACCELZ_SCALING)
        except AttributeError:
            pass

    def on_gyro_yaw(self, instance, value):
        try:
            self.imu_obj.rotation.y = self.rotation_y - (value * ImuView.GYRO_SCALING)
        except AttributeError:
            pass

    def on_gyro_pitch(self, instance, value):
        try:
            self.imu_obj.rotation.x = self.rotation_x - (value * ImuView.GYRO_SCALING)
        except AttributeError:
            pass

    def on_gyro_roll(self, instance, value):
        try:
            self.imu_obj.rotation.z = self.rotation_z + (value * ImuView.GYRO_SCALING)
        except AttributeError:
            pass
示例#48
0
class MainApp(App):

	
	rotx=Property(True)
	roty=Property(True)
	
	def stop_rotx(self,a):
		self.rotx= not self.rotx

	def stop_roty(self,a):
		self.roty= not self.roty
		
	def up(self,a):
		v=self.camera.position
		nv=(v[0],v[1],v[2]+10)
		print nv
		self.camera.position=nv

	def dn(self,a):
		v=self.camera.position
		nv=(v[0],v[1],v[2]-10)
		print nv
		self.camera.position=nv


	def xp(self,a):
		for obj in self.scene.children:
			print obj
			obj.pos.x += 30.
	def xm(self,a):
		for obj in self.scene.children:
			obj.pos.x -= 30.


	def build(self):
		box= BoxLayout(orientation='vertical')
		layout = GridLayout(cols=5)
		layout.add_widget(Button(text='rotx',on_press=self.stop_rotx))
		layout.add_widget(Button(text='roty',on_press=self.stop_roty))
		layout.add_widget(Button(text='up',on_press=self.up))
		layout.add_widget(Button(text='down',on_press=self.dn))
		layout.add_widget(Button(text='xpos',on_press=self.xp))
		layout.add_widget(Button(text='xneg',on_press=self.xm))
		layout.add_widget(PongGame(text='keyboard'))
		box.add_widget(layout)
		root = FloatLayout()
		box.add_widget(root)
		self.renderer = Renderer(shader_file="simple.glsl")
		print "self.renderr"
		dir(self.renderer)
		
		# hintergrund 
		self.renderer. set_clear_color((0.9,1,1, 1));
		
		scene = Scene()
		camera = PerspectiveCamera(45, 1, 1, 1000)
		camera.position=(0,0,90)
		self.camera=camera
		#loader = OBJMTLLoader()
		#obj = loader.load("my_colors.obj", "my_colors.mtl")

		loader = OBJLoader()
		#obj = loader.load("my_colors.obj")
		#obj = loader.load("Cube.obj")
		#obj = loader.load("Fusion003.obj")
		obj = loader.load(file)

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

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

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

	def _adjust_aspect(self, inst, val):
		rsize = self.renderer.size
		aspect = rsize[0] / float(rsize[1])
		self.renderer.camera.aspect = aspect

	def _rotate_obj(self, dt):
		if self.rotx:
			self.orion.rot.x += 0.2
		if self.roty:
			self.orion.rot.y += 0.4