Esempio n. 1
0
    def __init__(self, cname, category, filename=''):
        """ ComponentCreator constructor

        This class allow to create Python component for MORSE. It consists of an
        Empty object, to which you can then add meshs of your choice. It adds
        automaticaly the logic (Always sensor link to a Python controller). And
        set the default physics_type to 'NO_COLLISION'.

        :param cname: (string) component name (Empty object in Blender scene)
        :param category: (string) in ['actuators', 'sensors', 'robots']
        :param filename: (string, optional) used for the datastream configuration
            name of the Blender file in MORSE_COMPONENTS/category/filename.blend
            see morse.builder.data.MORSE_DATASTREAM_DICT (default: None)
        :return: a new AbstractComponent instance.
        """
        AbstractComponent.__init__(self, filename=filename, category=category)
        bpymorse.deselect_all()
        bpymorse.add_morse_empty()
        obj = bpymorse.get_first_selected_object()
        if cname:
            obj.name = cname
            self.basename = cname
        # no collision by default for components
        obj.game.physics_type = 'NO_COLLISION'
        self.set_blender_object(obj)
        # Add MORSE logic
        self.morseable()
Esempio n. 2
0
    def __init__(self, 
                 name, 
                 category, 
                 action = APPEND_EMPTY, 
                 blendfile = "", 
                 blendobject = None,
                 make_morseable = True):
        """ ComponentCreator constructor

        This class allow to create simulation components from MORSE builder
        scripts. It initially consists in an Empty object, to which you can
        then add meshs of your choice. It adds automaticaly the logic (Always
        sensor link to a Python controller). And set the default physics_type
        to 'NO_COLLISION'.

        :param name: (string) component name (used as Blender object name)
        :param category: (string) one of ['actuators', 'sensors', 'robots']
        :param action: indicate what to do with the `blendfile` and
        `blendobject` parameters. Must be one of [APPEND_EMPTY, USE_BLEND,
        LINK_EXISTING_OBJECT]. 
            - If APPEND_EMPTY (default), a new Blender `Empty` is created and
            `blendfile` and `blendobject` are ignored.
            - If USE_BLEND, `blendfile` is treated as the path to a Blender file,
            and if `blendobject` is also specified, the given object is
            selected (otherwise, the last object selected in the Blender file
            is returned).
            - If LINK_EXISTING_OBJECT, `blendfile` is ignored and `blendobject`
            is treated as the name of a Blender object which is already present
            in the scene.
        :param blendfile: (string, default:"") path to a Blender file (.blend)
        containing meshes for the component. Must be in MORSE_RESOURCE_PATH.
        :param blendobject: (string, default:None) Name of the Blender object
        to use (cf above for details).
        :param make_morseable: (boolean) Add Morse logic. Make it false
            if you add some blend file which already contains the
            necessary logic (default: True).
        """
        AbstractComponent.__init__(self, filename=blendfile, category=category)
        bpymorse.deselect_all()
        if action == ComponentCreator.APPEND_EMPTY:
            bpymorse.add_morse_empty()
        elif action == ComponentCreator.USE_BLEND:
            self.append_meshes()
            if blendobject:
                bpymorse.select_only(bpymorse.get_object(blendobject))
        elif action == ComponentCreator.LINK_EXISTING_OBJECT:
            bpymorse.select_only(bpymorse.get_object(blendobject))

        obj = bpymorse.get_first_selected_object()
        if name:
            obj.name = name
            self.basename = name
        # no collision by default for components
        obj.game.physics_type = 'NO_COLLISION'
        self.set_blender_object(obj)
        # Add MORSE logic
        if make_morseable:
            self.morseable()

        self.properties(Component_Tag = True, classpath = self.__class__._classpath)
Esempio n. 3
0
    def __init__(self, cname, category, filename=''):
        """ ComponentCreator constructor

        This class allow to create Python component for MORSE. It consists of an
        Empty object, to which you can then add meshs of your choice. It adds
        automaticaly the logic (Always sensor link to a Python controller). And
        set the default physics_type to 'NO_COLLISION'.

        :param cname: (string) component name (Empty object in Blender scene)
        :param category: (string) in ['actuators', 'sensors', 'robots']
        :param filename: (string, optional) used for the datastream configuration
            name of the Blender file in MORSE_COMPONENTS/category/filename.blend
            see morse.builder.data.MORSE_DATASTREAM_DICT (default: None)
        :return: a new AbstractComponent instance.
        """
        AbstractComponent.__init__(self, filename=filename, category=category)
        bpymorse.deselect_all()
        bpymorse.add_morse_empty()
        obj = bpymorse.get_first_selected_object()
        if cname:
            obj.name = cname
            self.basename = cname
        # no collision by default for components
        obj.game.physics_type = 'NO_COLLISION'
        self.set_blender_object(obj)
        # Add MORSE logic
        self.morseable()
Esempio n. 4
0
 def __init__(self, name):
     AbstractComponent.__init__(self)
     bpymorse.deselect_all()
     self.mesh_primitive_add()
     obj = bpymorse.get_first_selected_object()
     obj.name = name
     # no collision by default for components
     obj.game.physics_type = 'NO_COLLISION'
     self.set_blender_object(obj)
Esempio n. 5
0
 def __init__(self, name):
     AbstractComponent.__init__(self)
     bpymorse.deselect_all()
     self.mesh_primitive_add()
     obj = bpymorse.get_first_selected_object()
     obj.name = name
     # no collision by default for components
     obj.game.physics_type = 'NO_COLLISION'
     self.set_blender_object(obj)
Esempio n. 6
0
 def __init__(self, name):
     AbstractComponent.__init__(self)
     bpymorse.deselect_all()
     self.mesh_primitive_add()
     obj = bpymorse.get_first_selected_object()
     obj.name = name
     obj.empty_draw_type = 'ARROWS'
     obj.empty_draw_size = 0.1
     self.set_blender_object(obj)
Esempio n. 7
0
 def __init__(self, name):
     AbstractComponent.__init__(self)
     bpymorse.deselect_all()
     self.mesh_primitive_add()
     obj = bpymorse.get_first_selected_object()
     obj.name = name
     obj.empty_draw_type = 'ARROWS'
     obj.empty_draw_size = 0.1
     self.set_blender_object(obj)
Esempio n. 8
0
 def __init__(self, name):
     AbstractComponent.__init__(self)
     bpymorse.deselect_all()
     bpymorse.add_camera()
     obj = bpymorse.get_first_selected_object()
     obj.name = name
     # no collision by default for components
     obj.game.physics_type = 'NO_COLLISION'
     self.set_blender_object(obj)
     # Camera look in +Z
     self.rotate(y=math.pi)
Esempio n. 9
0
 def __init__(self, name):
     AbstractComponent.__init__(self)
     bpymorse.deselect_all()
     bpymorse.add_camera()
     obj = bpymorse.get_first_selected_object()
     obj.name = name
     # no collision by default for components
     obj.game.physics_type = 'NO_COLLISION'
     self.set_blender_object(obj)
     # Camera look in +Z
     self.rotate(y=math.pi, z=math.pi)
Esempio n. 10
0
 def __init__(self, name, lamp_type='SPOT'):
     AbstractComponent.__init__(self)
     bpymorse.deselect_all()
     bpymorse.add_lamp(type=lamp_type)
     obj = bpymorse.get_first_selected_object()
     obj.name = name
     # no collision by default for components
     obj.game.physics_type = 'NO_COLLISION'
     self.set_blender_object(obj)
     # Emit in +X
     self.rotate(y=-math.pi/2)
     if lamp_type is 'SPOT':
         spot = bpymorse.get_last_lamp()
         spot.spot_size = math.pi / 2
         spot.distance = 10
Esempio n. 11
0
 def __init__(self, name, lamp_type='SPOT'):
     AbstractComponent.__init__(self)
     bpymorse.deselect_all()
     bpymorse.add_lamp(type=lamp_type)
     obj = bpymorse.get_first_selected_object()
     obj.name = name
     # no collision by default for components
     obj.game.physics_type = 'NO_COLLISION'
     self.set_blender_object(obj)
     # Emit in +X
     self.rotate(y=-math.pi / 2)
     if lamp_type is 'SPOT':
         spot = bpymorse.get_last_lamp()
         spot.spot_size = math.pi / 2
         spot.distance = 10
Esempio n. 12
0
    def append_collada(self, component=None):
        """ Append Collada objects to this component

        Overloads :py:meth:`morse.builder.abstractcomponent.AbstractComponent.append_collada`

        :param component: component in which the objects are located
        :return: list of the imported Blender objects
        """
        imported_objects = AbstractComponent.append_collada(self, component)
        self.parent_root(imported_objects)

        return imported_objects
Esempio n. 13
0
    def append_collada(self, component=None):
        """ Append Collada objects to this component

        Overloads :py:meth:`morse.builder.abstractcomponent.AbstractComponent.append_collada`

        :param component: component in which the objects are located
        :return: list of the imported Blender objects
        """
        imported_objects = AbstractComponent.append_collada(self, component)
        self.parent_root(imported_objects)

        return imported_objects
Esempio n. 14
0
    def append_meshes(self, objects=None, component=None, prefix=None):
        """ Append the objects to this component

        Overloads :py:meth:`morse.builder.abstractcomponent.AbstractComponent.append_meshes`

        :param objects: list of the objects names to append
        :param component: component in which the objects are located
        :return: list of the imported Blender objects
        """
        imported_objects = AbstractComponent.append_meshes(self, objects, component, prefix)
        self.parent_root(imported_objects)

        return imported_objects
Esempio n. 15
0
    def append_collada(self, component=None):
        """ Append Collada objects to this component

        The objects are located in:
        MORSE_COMPONENTS/`self._category`/`component`.dae

        :param component: component in which the objects are located
        :return: list of the imported Blender objects
        """
        imported_objects = AbstractComponent.append_collada(self, component)
        self.parent_root(imported_objects)

        return imported_objects
Esempio n. 16
0
    def append_meshes(self, objects=None, component=None, prefix=None):
        """ Append the objects to this component

        Overloads :py:meth:`morse.builder.abstractcomponent.AbstractComponent.append_meshes`

        :param objects: list of the objects names to append
        :param component: component in which the objects are located
        :return: list of the imported Blender objects
        """
        imported_objects = AbstractComponent.append_meshes(
            self, objects, component, prefix)
        self.parent_root(imported_objects)

        return imported_objects
Esempio n. 17
0
    def append_meshes(self, objects=None, component=None, prefix=None):
        """ Append the objects to this component

        The `objects` are located in:
        MORSE_COMPONENTS/`self._category`/`component`.blend/Object/

        :param objects: list of the objects names to append
        :param component: component in which the objects are located
        :return: list of the imported Blender objects
        """
        imported_objects = AbstractComponent.append_meshes(self, objects, \
                                                           component, prefix)
        self.parent_root(imported_objects)

        return imported_objects
Esempio n. 18
0
    def __init__(self,
                 name,
                 category,
                 action=APPEND_EMPTY,
                 blendfile="",
                 blendobject=None,
                 make_morseable=True):
        """ ComponentCreator constructor

        This class allow to create simulation components from MORSE builder
        scripts. It initially consists in an Empty object, to which you can
        then add meshs of your choice. It adds automaticaly the logic (Always
        sensor link to a Python controller). And set the default physics_type
        to 'NO_COLLISION'.

        :param name: (string) component name (used as Blender object name)
        :param category: (string) one of ['actuators', 'sensors', 'robots']
        :param action: indicate what to do with the `blendfile` and
        `blendobject` parameters. Must be one of [APPEND_EMPTY, USE_BLEND,
        LINK_EXISTING_OBJECT]. 
            - If APPEND_EMPTY (default), a new Blender `Empty` is created and
            `blendfile` and `blendobject` are ignored.
            - If USE_BLEND, `blendfile` is treated as the path to a Blender file,
            and if `blendobject` is also specified, the given object is
            selected (otherwise, the last object selected in the Blender file
            is returned).
            - If LINK_EXISTING_OBJECT, `blendfile` is ignored and `blendobject`
            is treated as the name of a Blender object which is already present
            in the scene.
        :param blendfile: (string, default:"") path to a Blender file (.blend)
        containing meshes for the component. Must be in MORSE_RESOURCE_PATH.
        :param blendobject: (string, default:None) Name of the Blender object
        to use (cf above for details).
        :param make_morseable: (boolean) Add Morse logic. Make it false
            if you add some blend file which already contains the
            necessary logic (default: True).
        """
        AbstractComponent.__init__(self, filename=blendfile, category=category)
        bpymorse.deselect_all()
        if action == ComponentCreator.APPEND_EMPTY:
            bpymorse.add_morse_empty()
        elif action == ComponentCreator.USE_BLEND:
            self.append_meshes()
            if blendobject:
                bpymorse.select_only(bpymorse.get_object(blendobject))
        elif action == ComponentCreator.LINK_EXISTING_OBJECT:
            bpymorse.select_only(bpymorse.get_object(blendobject))

        obj = bpymorse.get_first_selected_object()
        if name:
            obj.name = name
            self.basename = name
        # no collision by default for components
        obj.game.physics_type = 'NO_COLLISION'
        self.set_blender_object(obj)
        # Add MORSE logic
        if make_morseable:
            self.morseable()

        self.properties(Component_Tag=True,
                        classpath=self.__class__._classpath)