def deriveMotor(obj, jointdict=None): """Derives motor information from an object. Args: obj(bpy_types.Object): Blender object to derive the motor from jointdict(dict, optional): phobos representation of the respective joint (Default value = None) Returns: : dict -- phobos representation of a motor """ import phobos.model.models as models import phobos.model.controllers as controllermodel props = models.initObjectProperties(obj, phobostype='motor') # return None if no motor is attached (there will always be at least a name in the props) if len(props) < 2: return None # make sure the parent is a joint if not obj.parent or obj.parent.phobostype != 'link' or 'joint/type' not in obj.parent: log( "Can not derive motor from {}. Insufficient requirements from parent object!" .format(obj.name), 'ERROR', ) return None props['joint'] = nUtils.getObjectName(obj.parent, phobostype='joint') # try to derive the motor controller controllerobjs = [ control for control in obj.children if control.phobostype == 'controller' ] if controllerobjs: controller = controllermodel.deriveController(controllerobjs[0]) else: controller = None # assign the derived controller if controller: props['controller'] = controller['name'] else: del props['controller'] return props
def deriveMotor(obj, jointdict=None): """Derives motor information from an object. Args: obj(bpy_types.Object): Blender object to derive the motor from jointdict(dict, optional): phobos representation of the respective joint (Default value = None) Returns: : dict -- phobos representation of a motor """ import phobos.model.models as models import phobos.model.controllers as controllermodel props = models.initObjectProperties(obj, phobostype='motor') # return None if no motor is attached (there will always be at least a name in the props) if len(props) < 2: return None # make sure the parent is a joint if not obj.parent or obj.parent.phobostype != 'link' or 'joint/type' not in obj.parent: log( "Can not derive motor from {}. Insufficient requirements from parent object!".format( obj.name ), 'ERROR', ) return None props['joint'] = nUtils.getObjectName(obj.parent, phobostype='joint') # try to derive the motor controller controllerobjs = [control for control in obj.children if control.phobostype == 'controller'] if controllerobjs: controller = controllermodel.deriveController(controllerobjs[0]) else: controller = None # assign the derived controller if controller: props['controller'] = controller['name'] else: del props['controller'] return props
def deriveDictEntry(obj, names=False, objectlist=[], logging=True, adjust=True): """Derives a phobos dictionary entry from the provided object. Args: obj(bpy_types.Object): The object to derive the dict entry (phobos data structure) from. names(bool, optional): use object names as dict entries instead of object links. (Default value = False) logging(bool, optional): whether to log messages or not (Default value = True) objectlist: (Default value = []) adjust: (Default value = True) Returns: : dict -- phobos representation of the object """ props = {} try: if obj.phobostype == 'inertial': props = deriveInertial(obj, adjust=adjust, logging=logging) elif obj.phobostype == 'visual': props = deriveVisual(obj) elif obj.phobostype == 'collision': props = deriveCollision(obj) elif obj.phobostype == 'approxsphere': props = deriveApproxsphere(obj) elif obj.phobostype == 'sensor': props = sensormodel.deriveSensor(obj, names=names, objectlist=objectlist, logging=logging) elif obj.phobostype == 'controller': props = controllermodel.deriveController(obj) elif obj.phobostype == 'light': props = deriveLight(obj) elif obj.phobostype == 'motor': props = motormodel.deriveMotor(obj) elif obj.phobostype == 'annotation': props = deriveAnnotation(obj) except KeyError: log("A KeyError occurred due to missing data in object" + obj.name, "DEBUG") return None, None return props
def deriveMotor(obj, jointdict=None): """Derives motor information from an object. Args: obj(bpy_types.Object): Blender object to derive the motor from jointdict(dict, optional): phobos representation of the respective joint (Default value = None) Returns: : dict -- phobos representation of a motor """ import phobos.model.models as models import phobos.model.controllers as controllermodel props = models.initObjectProperties(obj, phobostype='motor') # return None if no motor is attached (there will always be at least a name in the props) if len(props) < 2: return None # make sure the parent is a joint if not obj.parent or obj.parent.phobostype != 'link' or 'joint/type' not in obj.parent: log( "Can not derive motor from {}. Insufficient requirements from parent object!" .format(obj.name), 'ERROR', ) return None props['joint'] = nUtils.getObjectName(obj.parent, phobostype='joint') # todo: transfer joint limits to motor properties # check for a mimic motor for k in (obj.parent).keys(): # Check for mimic motor if "mimic" in k: # Find the name mimic_driver = sUtils.getObjectByName( (obj.parent)['joint/mimic_joint'], phobostypes=['link']) c_motor = sUtils.getImmediateChildren(mimic_driver, phobostypes=['motor']) props['mimic_motor'] = nUtils.getObjectName(c_motor[0], phobostype='motor') props['mimic_multiplier'] = (obj.parent)['joint/mimic_multiplier'] props['mimic_offset'] = (obj.parent)['joint/mimic_offset'] break # try to derive the motor controller controllerobjs = [ control for control in obj.children if control.phobostype == 'controller' ] if controllerobjs: controller = controllermodel.deriveController(controllerobjs[0]) else: controller = None # assign the derived controller if controller: props['controller'] = controller['name'] else: del props['controller'] return props