Beispiel #1
0
 def __init__(self):
     '''Future methods
     - Add light
     - Add mesh
     - Add ros-camera (How to handle rigid-body offsets?)
     '''
     self.entities = []
     self.my_lights = []
     self.shader_manager = ShaderManager()
Beispiel #2
0
 def __init__(self):
     '''Future methods
     - Add light
     - Add mesh
     - Add ros-camera (How to handle rigid-body offsets?)
     '''
     self.entities = []
     self.my_lights = []
     self.shader_manager = ShaderManager()
Beispiel #3
0
class World(object):
    def __init__(self):
        '''Future methods
        - Add light
        - Add mesh
        - Add ros-camera (How to handle rigid-body offsets?)
        '''
        self.entities = []
        self.my_lights = []
        self.shader_manager = ShaderManager()

    def add_sphere(self, position, radius, color, **kwargs):
        '''Add a sphere entity to the scene'''
        kwargs["shader_manager"] = self.shader_manager
        sphere = Sphere(position, radius, color, **kwargs)
        self.entities.append(sphere)
        return sphere

    def add_box(self, position, width, height, depth, color):
        '''Add a box entity to the scene'''
        box = Box(position,
                  width,
                  height,
                  depth,
                  color,
                  shader_manager=self.shader_manager)
        self.entities.append(box)
        return box

    def add_plane(self,
                  position,
                  width,
                  height,
                  color=(0, 0, 255),
                  orientation=None):
        plane = Plane(position,
                      width,
                      height,
                      color,
                      orientation,
                      shader_manager=self.shader_manager)
        self.entities.append(plane)
        return plane

    def add_mesh(self, mesh, *args, **kwargs):
        kwargs["shader_manager"] = self.shader_manager
        mesh = Mesh(mesh, *args, **kwargs)
        self.entities.append(mesh)
        return mesh

    def add_entity(self, Entity_Type, *args, **kwargs):
        kwargs["shader_manager"] = self.shader_manager
        entity = Entity_Type(*args, **kwargs)
        self.entities.append(entity)
        return entity

    def add_camera(self, position, orientation, topic, projection=None):
        '''Add a ros-camera to view the scene
            TODO: Only draw when the frame is going to be needed
        '''
        raise (NotImplementedError('add_camera not implemented!'))
        # camera = Camera((640, 640), position, orientation, topic, projection=projection)
        # self.views.append(camera)
        # return camera

    def add_sonar(self, position, orientation, projection=None, maxdepth=100):
        '''Add a ros-sonar to view the scene'''
        raise (NotImplementedError('add_sonar not implemented!'))

    def add_point_light(self, position, intensity):
        '''Add a point-light to illuminate the scene
            Shading implemented:
                - Diffuse (Lambert)
                - Blinn-Phong
                - Multiple lights
            TODO:
                - Shadows
            '''
        self.shader_manager.get_lighting_manager().add_item(
            position, intensity)

    def set_view(self, view):
        for entity in self.entities:
            entity.set_view(view)

    def draw(self, cur_view):
        '''Todo:
            Swappable shaders'''
        # Draw the objects to the screen
        for entity in self.entities[::-1]:
            entity.set_view(cur_view)
            entity.draw()
Beispiel #4
0
class World(object):

    def __init__(self):
        '''Future methods
        - Add light
        - Add mesh
        - Add ros-camera (How to handle rigid-body offsets?)
        '''
        self.entities = []
        self.my_lights = []
        self.shader_manager = ShaderManager()

    def add_sphere(self, position, radius, color, **kwargs):
        '''Add a sphere entity to the scene'''
        kwargs["shader_manager"] = self.shader_manager
        sphere = Sphere(position, radius, color, **kwargs)
        self.entities.append(sphere)
        return sphere

    def add_box(self, position, width, height, depth, color):
        '''Add a box entity to the scene'''
        box = Box(position, width, height, depth, color, shader_manager=self.shader_manager)
        self.entities.append(box)
        return box

    def add_plane(self, position, width, height, color=(0, 0, 255), orientation=None):
        plane = Plane(position, width, height, color, orientation, shader_manager=self.shader_manager)
        self.entities.append(plane)
        return plane

    def add_mesh(self, mesh, *args, **kwargs):
        kwargs["shader_manager"] = self.shader_manager
        mesh = Mesh(mesh, *args, **kwargs)
        self.entities.append(mesh)
        return mesh

    def add_entity(self, Entity_Type, *args, **kwargs):
        kwargs["shader_manager"] = self.shader_manager
        entity = Entity_Type(*args, **kwargs)
        self.entities.append(entity)
        return entity

    def add_camera(self, position, orientation, topic, projection=None):
        '''Add a ros-camera to view the scene
            TODO: Only draw when the frame is going to be needed
        '''
        raise NotImplementedError
        # camera = Camera((640, 640), position, orientation, topic, projection=projection)
        # self.views.append(camera)
        # return camera

    def add_sonar(self, position, orientation, projection=None, maxdepth=100):
        '''Add a ros-sonar to view the scene'''
        raise NotImplementedError

    def add_point_light(self, position, intensity):
        '''Add a point-light to illuminate the scene
            Shading implemented:
                - Diffuse (Lambert)
                - Blinn-Phong
                - Multiple lights
            TODO:
                - Shadows
            '''
        self.shader_manager.get_lighting_manager().add_item(position, intensity)

    def set_view(self, view):
        for entity in self.entities:
            entity.set_view(view)

    def draw(self, cur_view):
        '''Todo:
            Swappable shaders'''
        # Draw the objects to the screen
        for entity in self.entities[::-1]:
            entity.set_view(cur_view)
            entity.draw()