def append_collada(self, component=None): """ Append Collada objects to the scene :param component: component in which the objects are located :return: list of the imported Blender objects """ if not component: component = self._blender_filename if component.endswith('.dae'): filepath = os.path.abspath(component) # external blend file else: filepath = os.path.join(MORSE_COMPONENTS, self._category, component + '.dae') if not os.path.exists(filepath): logger.error("Collada file %s for external asset import can" \ "not be found.\nEither provide an absolute path, or" \ "a path relative to MORSE assets directory (typically"\ "$PREFIX/share/morse/data)" % filepath) return # Save a list of objects names before importing Collada objects_names = [obj.name for obj in bpymorse.get_objects()] # Import Collada from filepath bpymorse.collada_import(filepath=filepath) # Get a list of the imported objects imported_objects = [obj for obj in bpymorse.get_objects() \ if obj.name not in objects_names] return imported_objects
def append_collada(self, component=None): """ Append Collada objects to the scene :param component: component in which the objects are located :return: list of the imported Blender objects """ if not component: component = self._blender_filename if component.endswith(".dae"): filepath = os.path.abspath(component) # external blend file else: filepath = os.path.join(MORSE_COMPONENTS, self._category, component + ".dae") if not os.path.exists(filepath): logger.error( "Collada file %s for external asset import can" "not be found.\nEither provide an absolute path, or" "a path relative to MORSE assets directory (typically" "$PREFIX/share/morse/data)" % (filepath) ) return # Save a list of objects names before importing Collada objects_names = [obj.name for obj in bpymorse.get_objects()] # Import Collada from filepath bpymorse.collada_import(filepath=filepath) # Get a list of the imported objects imported_objects = [obj for obj in bpymorse.get_objects() if obj.name not in objects_names] return imported_objects
def _generate_robot_properties(self): robots = {} for obj in bpymorse.get_objects(): p = obj.game.properties if 'Robot_Tag' in p and 'jsbsim_model' in p: loc = obj.location rot = obj.rotation_euler model = p['jsbsim_model'].value geoc = self.coord_conv.ecef_to_geocentric( self.coord_conv.ltp_to_ecef( self.coord_conv.blender_to_ltp(numpy.matrix(loc)))) geoc[0, 0] = degrees(geoc[0, 0]) geoc[0, 1] = degrees(geoc[0, 1]) geoc[0, 2] -= self.coord_conv.A # XXX check angles orientation robots[obj.name] = { 'longitude': geoc[0, 0], 'latitude': geoc[0, 1], 'altitude': geoc[0, 2], 'yaw': rot.z, 'pitch': rot.y, 'roll': rot.x, 'model': model } self.properties['robots'] = robots
def find_family(self): objs = bpymorse.get_objects() # Initialise family to parent family =[self.name] while True: more = 0 for f in family: remaining = [o for o in objs if o.name not in family] for r in remaining: # Check forward constraints for c in objs[f].constraints: if 'target' in dir(c): if c.target.name == r.name: family.append(r.name) more += 1 # Check backward constraints for c in r.constraints: if 'target' in dir(c): if c.target.name == f: family.append(r.name) more += 1 if not more: break return set(family)
def translate_compound(self, x=0.0, y=0.0, z=0.0): objs = bpymorse.get_objects() family = find_family(self) # print("found %d objects constrained by %s:" % (len(family)-1, self.name)) # print([f for f in family if f != self.name]) for f in family: oldl = objs[f].location objs[f].location = (oldl.x+x,oldl.y+y,oldl.z+z)
def rotate_compound(self, x=0.0, y=0.0, z=0.0): objs = bpymorse.get_objects() family = find_family(self) # Parent origin origin = self.location # Rotation matrix rot = Euler([x,y,z]).to_matrix() for f in family: oldl = objs[f].location oldr = objs[f].rotation_euler # Rotate each object around the parent origin objs[f].rotation_euler = (oldr.x+x,oldr.y+y,oldr.z+z) objs[f].location = rot * (oldl - origin) + origin