def execute(self, context): modelsPosesColl = bUtils.getPhobosPreferences().models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose if bpy.data.images[activeModelPoseIndex].name in modelsPosesColl.keys( ): activeModelPose = modelsPosesColl[ bpy.data.images[activeModelPoseIndex].name] if activeModelPose.type != "robot_name": # show on view_3d root = None if context.scene.objects.active != None: root = sUtils.getRoot(context.scene.objects.active) if not bpy.context.scene.preview_visible and \ (bpy.data.images[activeModelPoseIndex].type == 'IMAGE') and \ (root is None or not sUtils.isRoot(root) or not (modelsPosesColl[bpy.data.images[activeModelPoseIndex].name] != root["modelname"]) or len(bpy.context.selected_objects) == 0): bpy.ops.view3d.draw_preview_operator() bpy.context.scene.preview_visible = True else: activeModelPose.hide = not activeModelPose.hide if activeModelPose.hide: activeModelPose.icon = "RIGHTARROW" else: activeModelPose.icon = "DOWNARROW_HLT" for modelPose in modelsPosesColl: if (modelPose.type != "robot_name") and ( modelPose.parent == activeModelPose.name): modelPose.hide = activeModelPose.hide return {'FINISHED'}
def poll(self, context): """ Args: context: Returns: """ result = False modelsPosesColl = bUtils.getPhobosPreferences().models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose root = None # TODO delete me? # print("modelfile: ("+modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].model_file+")") if context.scene.objects.active != None: root = sUtils.getRoot(context.scene.objects.active) try: if ( not root or not sUtils.isRoot(root) or bpy.data.images[activeModelPoseIndex].name in modelsPosesColl.keys() and modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].model_file != '' and len(bpy.context.selected_objects) == 0 or modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].robot_name != root["model/name"] ): result = True except KeyError: result = False return result
def poll(self, context): """ Args: context: Returns: """ result = False modelsPosesColl = bUtils.getPhobosPreferences().models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose root = None # TODO delete me? # print("modelfile: ("+modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].model_file+")") if context.view_layer.objects.active != None: root = sUtils.getRoot(context.view_layer.objects.active) try: if (not root or not sUtils.isRoot(root) or bpy.data.images[activeModelPoseIndex].name in modelsPosesColl.keys() and modelsPosesColl[bpy.data.images[activeModelPoseIndex]. name].model_file != '' and len(bpy.context.selected_objects) == 0 or modelsPosesColl[bpy.data.images[activeModelPoseIndex]. name].robot_name != root["model/name"]): result = True except KeyError: result = False return result
def poll(self, context): modelsPosesColl = bUtils.getPhobosPreferences().models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose return (context.selected_objects and context.active_object and sUtils.isRoot(context.active_object) and bpy.data.images[activeModelPoseIndex].name in modelsPosesColl.keys() and modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].robot_name == context.active_object['modelname'] and modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].type == 'robot_pose')
def poll(self, context): modelsPosesColl = bpy.context.user_preferences.addons[ "phobos"].preferences.models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose root = sUtils.isRoot(context.scene.objects.active) return root and bpy.data.images[ activeModelPoseIndex].name in modelsPosesColl.keys()
def poll(self, context): """ Args: context: Returns: """ return (bpy.context.selected_objects and context.active_object and sUtils.isRoot(context.active_object))
def poll(self, context): result = False modelsPosesColl = bUtils.getPhobosPreferences().models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose root = sUtils.isRoot(context.scene.objects.active) if root and \ (bpy.data.images[activeModelPoseIndex].name in modelsPosesColl.keys()) and \ (modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].robot_name == root["modelname"]) and \ (modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].type == 'robot_pose'): result = True return result
def poll(self, context): """ Args: context: Returns: """ return ( bpy.context.selected_objects and context.active_object and sUtils.isRoot(context.active_object) )
def execute(self, context): """ Args: context: Returns: """ modelsPosesColl = bUtils.getPhobosPreferences().models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose if bpy.data.images[activeModelPoseIndex].name in modelsPosesColl.keys(): activeModelPose = modelsPosesColl[bpy.data.images[activeModelPoseIndex].name] if activeModelPose.type != "robot_name": # show on view_3d root = None if context.scene.objects.active != None: root = sUtils.getRoot(context.scene.objects.active) if ( not bpy.context.scene.preview_visible and (bpy.data.images[activeModelPoseIndex].type == 'IMAGE') and ( root is None or not sUtils.isRoot(root) or not ( modelsPosesColl[bpy.data.images[activeModelPoseIndex].name] != root["model/name"] ) or len(bpy.context.selected_objects) == 0 ) ): bpy.ops.view3d.draw_preview_operator() bpy.context.scene.preview_visible = True else: activeModelPose.hide = not activeModelPose.hide if activeModelPose.hide: activeModelPose.icon = "RIGHTARROW" else: activeModelPose.icon = "DOWNARROW_HLT" for modelPose in modelsPosesColl: if (modelPose.type != "robot_name") and ( modelPose.parent == activeModelPose.name ): modelPose.hide = activeModelPose.hide return {'FINISHED'}
def poll(self, context): """ Args: context: Returns: """ modelsPosesColl = bUtils.getPhobosPreferences().models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose return ( context.selected_objects and context.active_object and sUtils.isRoot(context.active_object) and bpy.data.images[activeModelPoseIndex].name in modelsPosesColl.keys() and modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].robot_name == context.active_object['model/name'] and modelsPosesColl[bpy.data.images[activeModelPoseIndex].name].type == 'robot_pose' )
def poll(self, context): return bpy.context.selected_objects and context.active_object and sUtils.isRoot( context.active_object)
def deriveModelDictionaryFromSubmodel(modelname): model = { 'links': {}, 'joints': {}, 'sensors': {}, 'motors': {}, 'controllers': {}, 'materials': {}, 'meshes': {}, 'lights': {}, 'groups': {}, 'chains': {} } # collect general model properties model['date'] = datetime.now().strftime("%Y%m%d_%H:%M") model['name'] = modelname # collect all submodels submodels = [a for a in bpy.data.objects if a.phobostype == 'submodel'] # namespace links, joints, motors etc for each submodel for subm in submodels: print('-----------------------', subm.name, subm['submodelname'], '\n') rootlink = [ r for r in bpy.data.objects if sUtils.isRoot(r) and r['modelname'] == subm['submodelname'] ][0] adict = buildModelDictionary(rootlink) for l in adict['links']: model['links'][namespaced(l, subm.name)] = namespaceLink( adict['links'][l], subm.name) for j in adict['joints']: model['joints'][namespaced(j, subm.name)] = namespaceJoint( adict['joints'][j], subm.name) for m in adict['motors']: model['motors'][namespaced(m, subm.name)] = namespaceMotor( adict['motors'][m], subm.name) for mat in adict['materials']: if mat not in model['materials']: model['materials'][mat] = adict['materials'][mat] for mesh in adict['meshes']: model['meshes'][namespaced(mesh, subm.name)] = adict['meshes'][mesh] print('\n\n') for subm in submodels: rootlink = [ r for r in bpy.data.objects if sUtils.isRoot(r) and r['modelname'] == subm['submodelname'] ][0] if subm.parent: # get interfaces and parents parentsubmodelname = subm.parent.parent.parent['submodelname'] parentinterfacename = subm.parent.parent['interface/name'] parentsubmodel = [ r for r in bpy.data.objects if sUtils.isRoot(r) and r['modelname'] == parentsubmodelname ][0] parentinterface = [ i for i in sUtils.getChildren(parentsubmodel, ('interface', )) if i['interface/name'] == parentinterfacename ][0] parentlinkname = parentinterface.parent.name # derive link pose for root link matrix = eUtils.getCombinedTransform(subm, subm.parent.parent.parent) pose = { 'rawmatrix': matrix, 'matrix': [list(vector) for vector in list(matrix)], 'translation': list(matrix.to_translation()), 'rotation_euler': list(matrix.to_euler()), 'rotation_quaternion': list(matrix.to_quaternion()) } model['links'][namespaced(rootlink.name, subm.name)]['pose'] = pose # derive additional joint model['joints'][a.name] = deriveJoint(rootlink) #print(yaml.dump(model['joints'][a.name])) model['joints'][a.name]['name'] = namespaced(rootlink.name, a.name) model['joints'][a.name]['parent'] = namespaced( parentlinkname, a.parent.parent.parent.name) model['joints'][a.name]['child'] = namespaced( rootlink.name, a.name) #print(yaml.dump(model['joints'][a.name])) #print('######################') #for j in model['joints']: # print(model['joints'][j]['name'], model['joints'][j]['child'], model['joints'][j]['child']) #print('######################') return model
# delete objects designated for deletion sUtils.selectObjects(objects_to_be_deleted) bpy.ops.object.delete(use_global=True) # remove motor limits custom properties for obj in objectlist: if 'motor/limit' in obj: del obj['motor/limit'] elif 'motor/limits' in obj: del obj['motor/limits'] # move modelname to model/name and reassign root for obj in objectlist: if 'modelname' in obj: obj['model/name'] = obj['modelname'] del obj['modelname'] if 'version' in obj: obj['model/version'] = obj['version'] del obj['version'] if sUtils.isRoot(obj): bpy.context.view_layer.objects.active = obj bpy.ops.phobos.set_model_root() # update joint shapes for whole model joints = [obj for obj in objectlist if 'joint/type' in obj] for joint in joints: resource_obj = ioUtils.getResource(['joint', joint['joint/type']]) joint.pose.bones[0].custom_shape = resource_obj
def deriveModelDictionaryFromAssemblies(modelname): model = { 'links': {}, 'joints': {}, 'sensors': {}, 'motors': {}, 'controllers': {}, 'materials': {}, 'meshes': {}, 'lights': {}, 'groups': {}, 'chains': {} } model['date'] = datetime.now().strftime("%Y%m%d_%H:%M") model['name'] = modelname assemblies = [a for a in bpy.data.objects if a.phobostype == 'assembly'] for a in assemblies: print('-----------------------', a.name, a['assemblyname'], '\n') rootlink = [ r for r in bpy.data.objects if sUtils.isRoot(r) and r['modelname'] == a['assemblyname'] ][0] adict = buildModelDictionary(rootlink) for l in adict['links']: model['links'][namespaced(l, a.name)] = namespaceLink( adict['links'][l], a.name) for j in adict['joints']: model['joints'][namespaced(j, a.name)] = namespaceJoint( adict['joints'][j], a.name) for m in adict['motors']: model['motors'][namespaced(m, a.name)] = namespaceMotor( adict['motors'][m], a.name) for mat in adict['materials']: if mat not in model['materials']: model['materials'][mat] = adict['materials'][mat] for mesh in adict['meshes']: model['meshes'][namespaced(mesh, a.name)] = adict['meshes'][mesh] print('\n\n') for a in assemblies: rootlink = [ r for r in bpy.data.objects if sUtils.isRoot(r) and r['modelname'] == a['assemblyname'] ][0] if a.parent: #print('combining...:', a.name) #print([l for l in model['links']]) parentassemblyname = a.parent.parent.parent['assemblyname'] #print(parentassemblyname) parentinterfacename = a.parent.parent['interface/name'] #print(parentinterfacename) parentassembly = [ r for r in bpy.data.objects if sUtils.isRoot(r) and r['modelname'] == parentassemblyname ][0] #print(parentassembly) parentinterface = [ i for i in sUtils.getChildren(parentassembly, ('interface', )) if i['interface/name'] == parentinterfacename ][0] #print(parentinterface) parentlinkname = parentinterface.parent.name #print(parentlinkname) # derive link pose for root link matrix = eUtils.getCombinedTransform(a, a.parent.parent.parent) pose = { 'rawmatrix': matrix, 'matrix': [list(vector) for vector in list(matrix)], 'translation': list(matrix.to_translation()), 'rotation_euler': list(matrix.to_euler()), 'rotation_quaternion': list(matrix.to_quaternion()) } model['links'][namespaced(rootlink.name, a.name)]['pose'] = pose # derive additional joint model['joints'][a.name] = deriveJoint(rootlink) #print(yaml.dump(model['joints'][a.name])) model['joints'][a.name]['name'] = namespaced(rootlink.name, a.name) model['joints'][a.name]['parent'] = namespaced( parentlinkname, a.parent.parent.parent.name) model['joints'][a.name]['child'] = namespaced( rootlink.name, a.name) #print(yaml.dump(model['joints'][a.name])) #print('######################') #for j in model['joints']: # print(model['joints'][j]['name'], model['joints'][j]['child'], model['joints'][j]['child']) #print('######################') return model
# delete objects designated for deletion sUtils.selectObjects(objects_to_be_deleted) bpy.ops.object.delete(use_global=True) # remove motor limits custom properties for obj in objectlist: if 'motor/limit' in obj: del obj['motor/limit'] elif 'motor/limits' in obj: del obj['motor/limits'] # move modelname to model/name and reassign root for obj in objectlist: if 'modelname' in obj: obj['model/name'] = obj['modelname'] del obj['modelname'] if 'version' in obj: obj['model/version'] = obj['version'] del obj['version'] if sUtils.isRoot(obj): bpy.context.scene.objects.active = obj bpy.ops.phobos.set_model_root() # update joint shapes for whole model joints = [obj for obj in objectlist if 'joint/type' in obj] for joint in joints: resource_obj = ioUtils.getResource(['joint', joint['joint/type']]) joint.pose.bones[0].custom_shape = resource_obj