def __init__(self, filename="props/objects", prefix=None, keep_pose=False): """ Initialize a PassiveObject :param filename: The Blender file to load. Path can be absolute or if no extension relative to MORSE assets' installation path (typically, $PREFIX/share/morse/data) :param prefix: (optional) the prefix of the objects to load in the Blender file. If not set, all objects present in the file are loaded. If set, all objects **prefixed** by this name are imported. :param keep_pose: If set, the object pose (translation and rotation) in the Blender file is kept. Else, the object own center is placed at origin and all rotation are reset. :return: a new AbstractComponent instance. """ AbstractComponent.__init__(self, filename=filename) logger.info("Importing the following passive object(s): %s" % prefix) imported_objects = self.append_meshes(prefix=prefix) # Here we use the fact that after appending, Blender select the objects # and the root (parent) object first ( [0] ) self.set_blender_object(imported_objects[0]) if not keep_pose: self.location = (0.0, 0.0, 0.0) self.rotation_euler = (0.0, 0.0, 0.0)
def __init__(self, category='', filename='', blender_object_name=None, make_morseable=True): """ Initialize a MORSE component :param category: The category of the component (folder in MORSE_COMPONENTS) :param filename: The name of the component (file in MORSE_COMPONENTS/category/name.blend) If ends with '.blend', append the objects from the Blender file. :param blender_object_name: If set, use the given Blender object as 'root' for this component. Otherwise, select the first available Blender object (the top parent in case of a hierarchy of objects). :param make_morseable: If the component has no property for the simulation, append default Morse ones. See self.morseable() """ AbstractComponent.__init__(self, filename=filename, category=category) imported_objects = self.append_meshes() if blender_object_name is None: # Here we use the fact that after appending, Blender select the objects # and the root (parent) object first ( [0] ) self.set_blender_object(imported_objects[0]) else: self.set_blender_object([ o for o in imported_objects if o.name == blender_object_name ][0]) # If the object has no MORSE logic, add default one if make_morseable and category in ['sensors', 'actuators', 'robots'] \ and not self.is_morseable(): self.morseable()
def __init__(self, category='', filename='',blender_object_name=None, make_morseable=True): """ Initialize a MORSE component :param category: The category of the component (folder in MORSE_COMPONENTS) :param filename: The name of the component (file in MORSE_COMPONENTS/category/name.blend) If ends with '.blend', append the objects from the Blender file. :param blender_object_name: If set, use the given Blender object as 'root' for this component. Otherwise, select the first available Blender object (the top parent in case of a hierarchy of objects). :param make_morseable: If the component has no property for the simulation, append default Morse ones. See self.morseable() """ AbstractComponent.__init__(self, filename=filename, category=category) if blender_object_name is None: imported_objects = self.append_meshes() else: imported_objects = self.append_meshes(objects=[blender_object_name]) if not imported_objects: raise MorseBuilderNoComponentError("No object named <%s> in %s" % (blender_object_name, filename)) # Here we use the fact that after appending, Blender select the objects # and the root (parent) object first ( [0] ) self.set_blender_object(imported_objects[0]) # If the object has no MORSE logic, add default one if make_morseable and category in ['sensors', 'actuators', 'robots'] \ and not self.is_morseable(): self.morseable()
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)
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)
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)
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
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
def __init__(self, category="", filename="", make_morseable=True): """ Initialize a MORSE component :param category: The category of the component (folder in MORSE_COMPONENTS) :param filename: The name of the component (file in MORSE_COMPONENTS/category/name.blend) If ends with '.blend', append the objects from the Blender file. :param make_morseable: If the component has no property for the simulation, append default Morse ones. See self.morseable() """ AbstractComponent.__init__(self, filename=filename, category=category) imported_objects = self.append_meshes() # Here we use the fact that after appending, Blender select the objects # and the root (parent) object first ( [0] ) self.set_blender_object(imported_objects[0]) # If the object has no MORSE logic, add default one if make_morseable and category in ["sensors", "actuators", "robots"] and not self.is_morseable(): self.morseable()
def __init__(self, category='', filename='', make_morseable=True): """ Initialize a MORSE component :param category: The category of the component (folder in MORSE_COMPONENTS) :param filename: The name of the component (file in MORSE_COMPONENTS/category/name.blend) If ends with '.blend', append the objects from the Blender file. :param make_morseable: If the component has no property for the simulation, append default Morse ones. See self.morseable() """ AbstractComponent.__init__(self, filename=filename, category=category) imported_objects = self.append_meshes() # Here we use the fact that after appending, Blender select the objects # and the root (parent) object first ( [0] ) self.set_blender_object(imported_objects[0]) # If the object has no MORSE logic, add default one if make_morseable and category in ['sensors', 'actuators', 'robots'] \ and not self.is_morseable(): self.morseable()