def loadTargetFromMesh(context): ob = context.object if not utils.isBaseOrTarget(ob): raise NameError("Active object %s is not a base object" % ob.name) scn = context.scene trg = None for ob1 in scn.objects: if ob1.select and ob1.type == 'MESH' and ob1 != ob: trg = ob1 break if not trg: raise NameError("Two meshes must be selected") bpy.ops.object.mode_set(mode='OBJECT') scn.objects.active = trg bpy.ops.object.transform_apply(location=False, rotation=True, scale=True) scn.objects.active = ob name = trg.name skey = ob.shape_key_add(name=name, from_mix=False) ob.active_shape_key_index = utils.shapeKeyLen(ob) - 1 skey.name = name nVerts = len(ob.data.vertices) for v in trg.data.vertices[0:nVerts]: skey.data[v.index].co = v.co skey.slider_min = -1.0 skey.slider_max = 1.0 skey.value = 1.0 ob.show_only_shape_key = False ob.use_shape_key_edit_mode = True ob["NTargets"] += 1 ob["FilePath"] = 0 ob.SelectedOnly = False scn.objects.unlink(trg) return
def checkValid(ob): nShapes = utils.shapeKeyLen(ob) if nShapes != ob["NTargets"] + 1: print("Consistency problem:\n %d shapes, %d targets" % (nShapes, ob["NTargets"])) return False return True
def newTarget(context): ob = context.object bpy.ops.object.mode_set(mode='OBJECT') skey = ob.shape_key_add(name="Target", from_mix=False) ob.active_shape_key_index = utils.shapeKeyLen(ob) - 1 skey.slider_min = -1.0 skey.slider_max = 1.0 skey.value = 1.0 ob.show_only_shape_key = False ob.use_shape_key_edit_mode = True ob["NTargets"] += 1 ob["FilePath"] = 0 ob.SelectedOnly = False return
def checkValid(ob): nShapes = utils.shapeKeyLen(ob) if nShapes != ob["NTargets"]+1: print("Consistency problem:\n %d shapes, %d targets" % (nShapes, ob["NTargets"])) return False return True