def redoIt(self, *args): nMob = getNObjectMobFromMob(self._nObjectMobHandle.object()) if nMob.isNull(): m_cmds.error("Selection has no relationship with nObjects") return mfn_dep_nCloth = om2.MFnDependencyNode(nMob) plug = mfn_dep_nCloth.findPlug(self._plugName, False) dataHandle = plug.asMDataHandle() data = dataHandle.data() isDataNull = data.isNull() # NOTE(Fuzes): If the Data is Null we set it ourselves, else we work on the reference if isDataNull: newData = om2.MFnDoubleArrayData() mobData = newData.create(self._current_weights) dataHandle.setMObject(mobData) plug.setMDataHandle(dataHandle) self._needsUndo = True return else: doubleArrayData = om2.MFnDoubleArrayData(data) self._prev_weights = om2.MDoubleArray() for i, value in enumerate(self._current_weights): self._prev_weights.append(doubleArrayData[i]) doubleArrayData[i] = value self._needsUndo = True return
def init(): pass # (1) Get Maya data types and attributes kString = om.MFnData.kString kFloat = om.MFnNumericData.kFloat tAttr = om.MFnTypedAttribute() nAttr = om.MFnNumericAttribute() kDoubleArray = om.MFnNumericData.kDoubleArray # (2) Setup attributes csvToScalarArray.filePath = tAttr.create('filePath', 'fp', kString) tAttr.usedAsFilename = True csvToScalarArray.frame = nAttr.create('frame', 'fr', kFloat, 0.0) nAttr.hidden = False nAttr.keyable = True csvToScalarArray.result = tAttr.create('result', 'r', kDoubleArray, om.MFnDoubleArrayData().create()) tAttr.writable = False tAttr.storable = False tAttr.readable = True # (3) Add the attributes to the node csvToScalarArray.addAttribute(csvToScalarArray.filePath) csvToScalarArray.addAttribute(csvToScalarArray.frame) csvToScalarArray.addAttribute(csvToScalarArray.result) # (4) Set the attribute dependencies csvToScalarArray.attributeAffects(csvToScalarArray.filePath, csvToScalarArray.result) csvToScalarArray.attributeAffects(csvToScalarArray.frame, csvToScalarArray.result)
def compute(self, plug, data): # (1) Get handles from data stream fpHandle = data.inputValue(csvToScalarArray.filePath) filePath = fpHandle.asString() frHandle = data.inputValue(csvToScalarArray.frame) frame = int(np.float32(frHandle.asFloat())) result_handle = data.outputValue(csvToScalarArray.result) if filePath == "": return # (2) Get CSV data data_cache.getOrLoad(filePath) # (3) Load data based on frame frame = max(0, frame) frame = min(frame, data_cache.data.shape[0] - 1) frame_data = data_cache.data[frame, :] # (4) Output output_array = om.MFnDoubleArrayData(result_handle.data()) output_values = [] for component in frame_data: output_values.append(component) output_array.set(output_values) result_handle.setClean()
def clearWeights(attribute): """Clear the deformer weights of the given attribute by assigning an empty array. This is much faster than iterating through all weights indices individually and removing them. :param attribute: The full path of the weights attribute which should get cleared. :type attribute: str """ sel = om2.MSelectionList() sel.add(attribute) plug = sel.getPlug(0) emptyArray = om2.MDoubleArray() dataFn = om2.MFnDoubleArrayData() obj = dataFn.create(emptyArray) plug.setMObject(obj)
def getTypedValue(plug): """Returns the maya type from the given typedAttributePlug :param plug: MPLug :return: maya type """ tAttr = om2.MFnTypedAttribute(plug.attribute()) dataType = tAttr.attrType() if dataType == om2.MFnData.kInvalid: return None, None elif dataType == om2.MFnData.kString: return attrtypes.kMFnDataString, plug.asString() elif dataType == om2.MFnData.kNumeric: return getNumericValue(plug) elif dataType == om2.MFnData.kMatrix: return attrtypes.kMFnDataMatrix, om2.MFnMatrixData( plug.asMObject()).matrix() elif dataType == om2.MFnData.kFloatArray: return attrtypes.kMFnDataFloatArray, om2.MFnFloatArrayData( plug.asMObject()).array() elif dataType == om2.MFnData.kDoubleArray: return attrtypes.kMFnDataDoubleArray, om2.MFnDoubleArrayData( plug.asMObject()).array() elif dataType == om2.MFnData.kIntArray: return attrtypes.kMFnDataIntArray, om2.MFnIntArrayData( plug.asMObject()).array() elif dataType == om2.MFnData.kPointArray: return attrtypes.kMFnDataPointArray, om2.MFnPointArrayData( plug.asMObject()).array() elif dataType == om2.MFnData.kVectorArray: return attrtypes.kMFnDataVectorArray, om2.MFnVectorArrayData( plug.asMObject()).array() elif dataType == om2.MFnData.kStringArray: return attrtypes.kMFnDataStringArray, om2.MFnStringArrayData( plug.asMObject()).array() elif dataType == om2.MFnData.kMatrixArray: return attrtypes.kMFnDataMatrixArray, om2.MFnMatrixArrayData( plug.asMObject()).array() return None, None
def undoIt(self, *args): # NOTE(fuzes): If nothing is to be undone we simply return if not self._needsUndo: return nMob = getNObjectMobFromMob(self._nObjectMobHandle.object()) mfn_dep_nCloth = om2.MFnDependencyNode(nMob) plug = mfn_dep_nCloth.findPlug(self._plugName, False) dataHandle = plug.asMDataHandle() data = dataHandle.data() # NOTE(fuzes): If there where no previous weights set we simply initialize each vertex to a weight of 0.0 doubleArrayData = om2.MFnDoubleArrayData(data) if not self._prev_weights: for i in xrange(len(doubleArrayData)): doubleArrayData[i] = 0 else: for i, value in enumerate(self._prev_weights): doubleArrayData[i] = value
def doIt(self, *args): # NOTE(fuzes): Here we only gather the data for the command argDB = om2.MArgDatabase(self.syntax(), args[0]) if argDB.isFlagSet("-pn"): plugName = argDB.flagArgumentString("-pn", 0) if not plugName in _PER_VERTEX_ATTRIBUTE_NAMES: m_cmds.error("Invalid Plug Name") return else: m_cmds.error("plugName flag must be set") selList = argDB.getObjectList() mob = selList.getDependNode(0) nMob = getNObjectMobFromMob(mob) if nMob.isNull(): m_cmds.error("Selection has no relationship with nObjects") return mfn_dep_nCloth = om2.MFnDependencyNode(nMob) plug = mfn_dep_nCloth.findPlug(plugName, False) dataHandle = plug.asMDataHandle() data = dataHandle.data() isDataNull = data.isNull() result = om2.MDoubleArray() if isDataNull: self.clearResult() self.setResult(result) else: doubleArrayData = om2.MFnDoubleArrayData(data) result = doubleArrayData.array() self.clearResult() self.setResult(result)
def init_decode(): # (1) Setup attributes nAttr = om.MFnNumericAttribute() # Maya's Numeric Attribute class tAttr = om.MFnTypedAttribute() mAttr = om.MFnMatrixAttribute() uAttr = om.MFnUnitAttribute() kFloat = om.MFnNumericData.kFloat # Maya's float type k3Float = om.MFnNumericData.k3Float # Maya's float type kAngle = om.MFnUnitAttribute.kAngle kDoubleArray = om.MFnNumericData.kDoubleArray kBool = om.MFnNumericData.kBoolean # Setup attribute helper functions and classes def add_nAttr(params): setattr(ikrig_decode, params[0], nAttr.create(params[0], params[1], params[2])) nAttr.hidden = False nAttr.keyable = True return getattr(ikrig_decode, params[0]) def add_out_nAttr(params): setattr(ikrig_decode, params[0], nAttr.create(params[0], params[1], params[2])) mAttr.writable = False mAttr.storable = False mAttr.readable = True return getattr(ikrig_decode, params[0]) class out_euler_nAttr: i = 0 def create(self, params): rotX = uAttr.create("rotateX" + str(self.i), "rx" + str(self.i), kAngle) uAttr.writable = False uAttr.storable = False rotY = uAttr.create("rotateY" + str(self.i), "ry" + str(self.i), kAngle) uAttr.writable = False uAttr.storable = False rotZ = uAttr.create("rotateZ" + str(self.i), "rz" + str(self.i), kAngle) uAttr.writable = False uAttr.storable = False setattr(ikrig_decode, params[0], nAttr.create(params[0], params[1], rotX, rotY, rotZ)) nAttr.writable = False nAttr.storable = False nAttr.readable = True self.i += 1 return getattr(ikrig_decode, params[0]) euler_nAttr = out_euler_nAttr() # (2) Setup the input attributes in_attributes = [] ikrig_decode.encoded_pose = tAttr.create('encoded_pose', 'ep', kDoubleArray, om.MFnDoubleArrayData().create()) tAttr.connectable = True tAttr.hidden = False ikrig_decode.offset_mat = mAttr.create('offset_mat', 'om') mAttr.keyable = True mAttr.hidden = False in_attributes.append(ikrig_decode.encoded_pose) in_attributes.append(ikrig_decode.offset_mat) in_attributes.append(add_nAttr(('height_hips', 'hh', kFloat))) in_attributes.append(add_nAttr(('root_offset_neck', 'o0', k3Float))) in_attributes.append(add_nAttr(('root_offset_leg_L', 'o1', k3Float))) in_attributes.append(add_nAttr(('root_offset_leg_R', 'o2', k3Float))) in_attributes.append(add_nAttr(('root_offset_arm_L', 'o3', k3Float))) in_attributes.append(add_nAttr(('root_offset_arm_R', 'o4', k3Float))) in_attributes.append(add_nAttr(('length_spine', 'l0', kFloat))) in_attributes.append(add_nAttr(('length_neck', 'l1', kFloat))) in_attributes.append(add_nAttr(('length_leg_L', 'l2', kFloat))) in_attributes.append(add_nAttr(('length_leg_R', 'l3', kFloat))) in_attributes.append(add_nAttr(('length_arm_L', 'l4', kFloat))) in_attributes.append(add_nAttr(('length_arm_R', 'l5', kFloat))) ikrig_decode.normalized_global_xfo = nAttr.create('normalized_global_xfo', 'nx', kBool, 1) nAttr.hidden = False nAttr.keyable = True # (3) Setup the output attributes out_attributes = [] ikrig_decode.global_mat = mAttr.create('global_mat', 'gm') mAttr.writable = False mAttr.storable = False mAttr.connectable = True mAttr.readable = True out_attributes.append(ikrig_decode.global_mat) out_attributes.append(add_out_nAttr(('ik_Spine_root', 'ikp0', k3Float))) out_attributes.append(add_out_nAttr(('ik_Spine_dir', 'ikd0', k3Float))) out_attributes.append(add_out_nAttr(('ik_Spine_eff', 'ike0', k3Float))) out_attributes.append(euler_nAttr.create(('ik_Spine_eff_rot', 'ikr0'))) out_attributes.append(add_out_nAttr(('ik_Neck_root', 'ikp1', k3Float))) out_attributes.append(add_out_nAttr(('ik_Neck_dir', 'ikd1', k3Float))) out_attributes.append(add_out_nAttr(('ik_Neck_eff', 'ike1', k3Float))) out_attributes.append(euler_nAttr.create(('ik_Neck_eff_rot', 'ikr1'))) out_attributes.append(add_out_nAttr(('ik_Leg_root_L', 'ikp2', k3Float))) out_attributes.append(add_out_nAttr(('ik_Leg_dir_L', 'ikd2', k3Float))) out_attributes.append(add_out_nAttr(('ik_Leg_eff_L', 'ike2', k3Float))) out_attributes.append(euler_nAttr.create(('ik_Leg_eff_rot_L', 'ikr2'))) out_attributes.append(add_out_nAttr(('ik_Leg_root_R', 'ikp3', k3Float))) out_attributes.append(add_out_nAttr(('ik_Leg_dir_R', 'ikd3', k3Float))) out_attributes.append(add_out_nAttr(('ik_Leg_eff_R', 'ike3', k3Float))) out_attributes.append(euler_nAttr.create(('ik_Leg_eff_rot_R', 'ikr3'))) out_attributes.append(add_out_nAttr(('ik_Arm_root_L', 'ikp4', k3Float))) out_attributes.append(add_out_nAttr(('ik_Arm_dir_L', 'ikd4', k3Float))) out_attributes.append(add_out_nAttr(('ik_Arm_eff_L', 'ike4', k3Float))) out_attributes.append(euler_nAttr.create(('ik_Arm_eff_rot_L', 'ikr4'))) out_attributes.append(add_out_nAttr(('ik_Arm_root_R', 'ikp5', k3Float))) out_attributes.append(add_out_nAttr(('ik_Arm_dir_R', 'ikd5', k3Float))) out_attributes.append(add_out_nAttr(('ik_Arm_eff_R', 'ike5', k3Float))) out_attributes.append(euler_nAttr.create(('ik_Arm_eff_rot_R', 'ikr5'))) # (4) Add the attributes to the node for attribute in in_attributes: ikrig_decode.addAttribute(attribute) for attribute in out_attributes: ikrig_decode.addAttribute(attribute) ikrig_decode.addAttribute(ikrig_decode.normalized_global_xfo) # (5) Set the attribute dependencies for out_attribute in out_attributes: ikrig_decode.attributeAffects(ikrig_decode.normalized_global_xfo, out_attribute) for in_attribute in in_attributes: ikrig_decode.attributeAffects(in_attribute, out_attribute)
def init_encode(): # (1) Setup attributes nAttr = om.MFnNumericAttribute() mAttr = om.MFnMatrixAttribute() tAttr = om.MFnTypedAttribute() kDoubleArray = om.MFnNumericData.kDoubleArray kFloat = om.MFnNumericData.kFloat k3Float = om.MFnNumericData.k3Float kBool = om.MFnNumericData.kBoolean def add_nAttr(params): setattr(ikrig_encode, params[0], nAttr.create(params[0], params[1], params[2])) nAttr.hidden = False nAttr.keyable = True return getattr(ikrig_encode, params[0]) def add_mAttr(params): setattr(ikrig_encode, params[0], mAttr.create(params[0], params[1])) mAttr.writable = True mAttr.storable = True mAttr.connectable = True mAttr.hidden = False return getattr(ikrig_encode, params[0]) ikrig_encode.mirror = nAttr.create('mirror', 'mi', kBool, 0) nAttr.hidden = False nAttr.keyable = True ikrig_encode.normalize_global_xfo = nAttr.create('normalize_global_xfo', 'nx', kBool, 1) nAttr.hidden = False nAttr.keyable = True in_attributes = [] # Character size attr. in_attributes.append(add_nAttr(('height_hips', 'hh', kFloat))) in_attributes.append(add_nAttr(('root_offset_neck', 'o0', k3Float))) in_attributes.append(add_nAttr(('root_offset_leg_L', 'o1', k3Float))) in_attributes.append(add_nAttr(('root_offset_leg_R', 'o2', k3Float))) in_attributes.append(add_nAttr(('root_offset_arm_L', 'o3', k3Float))) in_attributes.append(add_nAttr(('root_offset_arm_R', 'o4', k3Float))) in_attributes.append(add_nAttr(('length_spine', 'l0', kFloat))) in_attributes.append(add_nAttr(('length_neck', 'l1', kFloat))) in_attributes.append(add_nAttr(('length_leg_L', 'l2', kFloat))) in_attributes.append(add_nAttr(('length_leg_R', 'l3', kFloat))) in_attributes.append(add_nAttr(('length_arm_L', 'l4', kFloat))) in_attributes.append(add_nAttr(('length_arm_R', 'l5', kFloat))) # Character positional attr. in_attributes.append(add_mAttr(('mat_hips_rest', 'hr'))) in_attributes.append(add_mAttr(('mat_hips', 'h'))) in_attributes.append(add_mAttr(('mat_spine', 's'))) in_attributes.append(add_mAttr(('mat_chest', 'c'))) in_attributes.append(add_mAttr(('mat_neck', 'n'))) in_attributes.append(add_mAttr(('mat_neck_mid', 'nm'))) in_attributes.append(add_mAttr(('mat_head', 'e'))) in_attributes.append(add_mAttr(('mat_leg_L', 'll'))) in_attributes.append(add_mAttr(('mat_shin_L', 'sl'))) in_attributes.append(add_mAttr(('mat_foot_L', 'fl'))) in_attributes.append(add_mAttr(('mat_leg_R', 'lr'))) in_attributes.append(add_mAttr(('mat_shin_R', 'sr'))) in_attributes.append(add_mAttr(('mat_foot_R', 'fr'))) in_attributes.append(add_mAttr(('mat_shoulder_L', 'ol'))) in_attributes.append(add_mAttr(('mat_elbow_L', 'el'))) in_attributes.append(add_mAttr(('mat_hand_L', 'al'))) in_attributes.append(add_mAttr(('mat_shoulder_R', 'or'))) in_attributes.append(add_mAttr(('mat_elbow_R', 'er'))) in_attributes.append(add_mAttr(('mat_hand_R', 'ar'))) #(2) Setup the output attributes ikrig_encode.result = tAttr.create('result', 'r', kDoubleArray, om.MFnDoubleArrayData().create()) tAttr.writable = False tAttr.storable = False tAttr.readable = True # (3) Add the attributes to the node for attribute in in_attributes: ikrig_encode.addAttribute(attribute) ikrig_encode.addAttribute(ikrig_encode.mirror) ikrig_encode.addAttribute(ikrig_encode.normalize_global_xfo) ikrig_encode.addAttribute(ikrig_encode.result) # (4) Set the attribute dependencies for attribute in in_attributes: ikrig_encode.attributeAffects(attribute, ikrig_encode.result) ikrig_encode.attributeAffects(ikrig_encode.mirror, ikrig_encode.result) ikrig_encode.attributeAffects(ikrig_encode.normalize_global_xfo, ikrig_encode.result)
def compute(self, plug, datablock): #(1) # (1) Get handles from MPxNode's data block encoded_pose_handle = datablock.inputValue(ikrig_decode.encoded_pose) encoded_pose_marray = om.MFnDoubleArrayData(encoded_pose_handle.data()) encoded_pose_array = encoded_pose_marray.array() offset_mat_Handle = datablock.inputValue(ikrig_decode.offset_mat) offset_mat = offset_mat_Handle.asMatrix() for attr in float_attrs: handle = datablock.inputValue(getattr(ikrig_decode, attr)) exec(attr + "= handle.asFloat()") for attr in vector_attrs: handle = datablock.inputValue(getattr(ikrig_decode, attr)) vec = handle.asFloatVector() exec(attr + "= om.MVector(vec.x, vec.y, vec.z)") for attr in out_float3_attrs: handle = datablock.outputValue(getattr(ikrig_decode, attr)) exec(attr + "_Handle = handle") global_mat_Handle = datablock.outputValue(ikrig_decode.global_mat) normalized_global_xfoHandle = datablock.inputValue( ikrig_decode.normalized_global_xfo) normalized_global_xfo = normalized_global_xfoHandle.asBool() if len(encoded_pose_array) != 86: print( 'Encoded pose with wrong length, expecting 86 dimensions got ' + str(len(encoded_pose_array))) return # Global character transform g_tr_x = encoded_pose_array[0] g_tr_y = 0 g_tr_z = encoded_pose_array[1] g_ori = om.MEulerRotation(0, encoded_pose_array[2], 0) g_mat = g_ori.asMatrix() if normalized_global_xfo: g_tr_x *= height_hips g_tr_z *= height_hips g_mat[12] = g_tr_x g_mat[13] = g_tr_y g_mat[14] = g_tr_z g_mat *= offset_mat global_mat_Handle.setMMatrix(g_mat) ik_spine_root, ik_spine_eff, ik_spine_upv, ik_spine_eff_rot = encoded2IK( encoded_pose_array[3:16], False, height_hips, length_spine) ik_spine_root.y += height_hips ik_neck_root, ik_neck_eff, ik_neck_upv, ik_neck_eff_rot = encoded2IK( encoded_pose_array[16:30], root_offset_neck, height_hips, length_neck) ik_leg_root_L, ik_leg_eff_L, ik_leg_upv_L, ik_leg_eff_rot_L = encoded2IK( encoded_pose_array[30:44], root_offset_leg_L, height_hips, length_leg_L) ik_leg_root_R, ik_leg_eff_R, ik_leg_upv_R, ik_leg_eff_rot_R = encoded2IK( encoded_pose_array[44:58], root_offset_leg_R, height_hips, length_leg_R) ik_arm_root_L, ik_arm_eff_L, ik_arm_upv_L, ik_arm_eff_rot_L = encoded2IK( encoded_pose_array[58:72], root_offset_arm_L, height_hips, length_arm_L) ik_arm_root_R, ik_arm_eff_R, ik_arm_upv_R, ik_arm_eff_rot_R = encoded2IK( encoded_pose_array[72:86], root_offset_arm_R, height_hips, length_arm_R) ik_neck_root = ik_neck_root * ik_spine_eff_rot.asMatrix() ik_arm_root_L = ik_arm_root_L * ik_spine_eff_rot.asMatrix() ik_arm_root_R = ik_arm_root_R * ik_spine_eff_rot.asMatrix() ik_Spine_root_Handle.set3Float(ik_spine_root[0], ik_spine_root[1], ik_spine_root[2]) ik_Spine_eff_Handle.set3Float(ik_spine_eff[0], ik_spine_eff[1], ik_spine_eff[2]) ik_Spine_dir_Handle.set3Float(ik_spine_upv[0], ik_spine_upv[1], ik_spine_upv[2]) ik_Spine_eff_rot_Handle.set3Double(ik_spine_eff_rot[0], ik_spine_eff_rot[1], ik_spine_eff_rot[2]) ik_Neck_root_Handle.set3Float(ik_neck_root[0], ik_neck_root[1], ik_neck_root[2]) ik_Neck_eff_Handle.set3Float(ik_neck_eff[0], ik_neck_eff[1], ik_neck_eff[2]) ik_Neck_dir_Handle.set3Float(ik_neck_upv[0], ik_neck_upv[1], ik_neck_upv[2]) ik_Neck_eff_rot_Handle.set3Double(ik_neck_eff_rot[0], ik_neck_eff_rot[1], ik_neck_eff_rot[2]) ik_Leg_root_L_Handle.set3Float(ik_leg_root_L[0], ik_leg_root_L[1], ik_leg_root_L[2]) ik_Leg_eff_L_Handle.set3Float(ik_leg_eff_L[0], ik_leg_eff_L[1], ik_leg_eff_L[2]) ik_Leg_dir_L_Handle.set3Float(ik_leg_upv_L[0], ik_leg_upv_L[1], ik_leg_upv_L[2]) ik_Leg_eff_rot_L_Handle.set3Double(ik_leg_eff_rot_L[0], ik_leg_eff_rot_L[1], ik_leg_eff_rot_L[2]) ik_Leg_root_R_Handle.set3Float(ik_leg_root_R[0], ik_leg_root_R[1], ik_leg_root_R[2]) ik_Leg_eff_R_Handle.set3Float(ik_leg_eff_R[0], ik_leg_eff_R[1], ik_leg_eff_R[2]) ik_Leg_dir_R_Handle.set3Float(ik_leg_upv_R[0], ik_leg_upv_R[1], ik_leg_upv_R[2]) ik_Leg_eff_rot_R_Handle.set3Double(ik_leg_eff_rot_R[0], ik_leg_eff_rot_R[1], ik_leg_eff_rot_R[2]) ik_Arm_root_L_Handle.set3Float(ik_arm_root_L[0], ik_arm_root_L[1], ik_arm_root_L[2]) ik_Arm_eff_L_Handle.set3Float(ik_arm_eff_L[0], ik_arm_eff_L[1], ik_arm_eff_L[2]) ik_Arm_dir_L_Handle.set3Float(ik_arm_upv_L[0], ik_arm_upv_L[1], ik_arm_upv_L[2]) ik_Arm_eff_rot_L_Handle.set3Double(ik_arm_eff_rot_L[0], ik_arm_eff_rot_L[1], ik_arm_eff_rot_L[2]) ik_Arm_root_R_Handle.set3Float(ik_arm_root_R[0], ik_arm_root_R[1], ik_arm_root_R[2]) ik_Arm_eff_R_Handle.set3Float(ik_arm_eff_R[0], ik_arm_eff_R[1], ik_arm_eff_R[2]) ik_Arm_dir_R_Handle.set3Float(ik_arm_upv_R[0], ik_arm_upv_R[1], ik_arm_upv_R[2]) ik_Arm_eff_rot_R_Handle.set3Double(ik_arm_eff_rot_R[0], ik_arm_eff_rot_R[1], ik_arm_eff_rot_R[2]) ik_Spine_root_Handle.setClean() ik_Spine_eff_Handle.setClean() ik_Spine_dir_Handle.setClean() ik_Spine_eff_rot_Handle.setClean() ik_Neck_root_Handle.setClean() ik_Neck_eff_Handle.setClean() ik_Neck_dir_Handle.setClean() ik_Neck_eff_rot_Handle.setClean() ik_Leg_root_L_Handle.setClean() ik_Leg_eff_L_Handle.setClean() ik_Leg_dir_L_Handle.setClean() ik_Leg_eff_rot_L_Handle.setClean() ik_Leg_root_R_Handle.setClean() ik_Leg_eff_R_Handle.setClean() ik_Leg_dir_R_Handle.setClean() ik_Leg_eff_rot_R_Handle.setClean() ik_Arm_root_L_Handle.setClean() ik_Arm_eff_L_Handle.setClean() ik_Arm_dir_L_Handle.setClean() ik_Arm_eff_rot_L_Handle.setClean() ik_Arm_root_R_Handle.setClean() ik_Arm_eff_R_Handle.setClean() ik_Arm_dir_R_Handle.setClean() ik_Arm_eff_rot_R_Handle.setClean()
def compute(self, plug, datablock): #(1) # (1) Get handles from MPxNode's data block for attr in float_attrs: handle = datablock.inputValue(getattr(ikrig_encode, attr)) exec(attr + "= handle.asFloat()") for attr in vector_attrs: handle = datablock.inputValue(getattr(ikrig_encode, attr)) vec = handle.asFloatVector() exec(attr + "= om.MVector(vec.x, vec.y, vec.z)") for attr in mat_attrs: handle = datablock.inputValue(getattr(ikrig_encode, attr)) exec(attr + "= handle.asMatrix()") mirrorHandle = datablock.inputValue(ikrig_encode.mirror) mirror = mirrorHandle.asBool() normalize_global_xfoHandle = datablock.inputValue( ikrig_encode.normalize_global_xfo) normalize_global_xfo = normalize_global_xfoHandle.asBool() # Global xfo with default hips height and 2d orientation # get xfo from rest pose mat_hips_delta = mat_hips_rest.inverse() * mat_hips # use xfo to transform direction vector direction = om.MVector([.0, .0, 1.]) * mat_hips_delta # constraint direction to xz plane direction.y = 0 # get all vectors zaxis = direction.normal() yaxis = om.MVector([.0, 1., .0]) xaxis = yaxis ^ zaxis.normal() # build global matrix g_tr_x = mat_hips[12] g_tr_y = height_hips g_tr_z = mat_hips[14] # scale to normalize for height zaxis *= height_hips yaxis *= height_hips xaxis *= height_hips g_mat = om.MMatrix([[xaxis[0], xaxis[1], xaxis[2], 0], [yaxis[0], yaxis[1], yaxis[2], 0], [zaxis[0], zaxis[1], zaxis[2], 0], [g_tr_x, g_tr_y, g_tr_z, 1]]) g_ori = om.MEulerRotation() g_ori = g_ori.setValue(g_mat.homogenize()) # chains ik_spine_root, ik_spine_eff, ik_spine_upv, ik_spine_eff_rot = FK2encoded( g_mat, False, mat_hips, mat_spine, mat_chest, length_spine) # lower body roots are offsets to hips lower_body_mat = om.MMatrix(g_mat) lower_body_mat[12] = mat_hips[12] lower_body_mat[13] = mat_hips[13] lower_body_mat[14] = mat_hips[14] ik_leg_root_L, ik_leg_eff_L, ik_leg_upv_L, ik_leg_eff_rot_L = FK2encoded( lower_body_mat, root_offset_leg_L, mat_leg_L, mat_shin_L, mat_foot_L, length_leg_L) ik_leg_root_R, ik_leg_eff_R, ik_leg_upv_R, ik_leg_eff_rot_R = FK2encoded( lower_body_mat, root_offset_leg_R, mat_leg_R, mat_shin_R, mat_foot_R, length_leg_R) # upper body roots are offsets to neck upper_body_mat = om.MMatrix(g_mat) upper_body_mat[12] = mat_chest[12] upper_body_mat[13] = mat_chest[13] upper_body_mat[14] = mat_chest[14] ik_arm_root_L, ik_arm_eff_L, ik_arm_upv_L, ik_arm_eff_rot_L = FK2encoded( upper_body_mat, root_offset_arm_L, mat_shoulder_L, mat_elbow_L, mat_hand_L, length_arm_L) ik_arm_root_R, ik_arm_eff_R, ik_arm_upv_R, ik_arm_eff_rot_R = FK2encoded( upper_body_mat, root_offset_arm_R, mat_shoulder_R, mat_elbow_R, mat_hand_R, length_arm_R) ik_neck_root, ik_neck_eff, ik_neck_upv, ik_neck_eff_rot = FK2encoded( upper_body_mat, root_offset_neck, mat_neck, mat_neck_mid, mat_head, length_neck) if normalize_global_xfo: g_tr_x /= height_hips g_tr_z /= height_hips if g_ori.y < 0: # avoid flips on y rotation g_ori.y += math.radians(360) global_components = (g_tr_x, g_tr_z, g_ori.y) pos_components = [ ik_spine_root, ik_spine_eff, ik_spine_upv, ik_neck_eff, ik_neck_upv, ik_leg_eff_L, ik_leg_upv_L, ik_leg_eff_R, ik_leg_upv_R, ik_arm_eff_L, ik_arm_upv_L, ik_arm_eff_R, ik_arm_upv_R ] rot_components = [ ik_spine_eff_rot, ik_neck_root, ik_neck_eff_rot, ik_leg_root_L, ik_leg_eff_rot_L, ik_leg_root_R, ik_leg_eff_rot_R, ik_arm_root_L, ik_arm_eff_rot_L, ik_arm_root_R, ik_arm_eff_rot_R ] if mirror: global_components = (-g_tr_x, g_tr_z, -g_ori.y) for component in pos_components: component[0] *= -1 for component in rot_components: component[0] *= -1 component[3] *= -1 out_components = [ global_components, pos_components[0], pos_components[1], pos_components[2], rot_components[0], rot_components[1], pos_components[3], pos_components[4], rot_components[2], rot_components[5], pos_components[7], pos_components[8], rot_components[6], rot_components[3], pos_components[5], pos_components[6], rot_components[4], rot_components[9], pos_components[11], pos_components[12], rot_components[10], rot_components[7], pos_components[9], pos_components[10], rot_components[8] ] else: out_components = [ global_components, pos_components[0], pos_components[1], pos_components[2], rot_components[0], rot_components[1], pos_components[3], pos_components[4], rot_components[2], rot_components[3], pos_components[5], pos_components[6], rot_components[4], rot_components[5], pos_components[7], pos_components[8], rot_components[6], rot_components[7], pos_components[9], pos_components[10], rot_components[8], rot_components[9], pos_components[11], pos_components[12], rot_components[10] ] result_handle = datablock.outputValue(ikrig_encode.result) output_array = om.MFnDoubleArrayData(result_handle.data()) output_values = [] for component in out_components: for i in range(len(component)): output_values.append(component[i]) output_array.set(output_values) result_handle.setClean()
def addAttribute(node, longName, shortName, attrType=attrtypes.kMFnNumericDouble, isArray=False, apply=True): """This function uses the api to create attributes on the given node, currently WIP but currently works for string,int, float, bool, message, matrix. if the attribute exists a ValueError will be raised. :param node: MObject :param longName: str, the long name for the attribute :param shortName: str, the shortName for the attribute :param attrType: attribute Type, attrtypes constants :param apply: if False the attribute will be immediately created on the node else just return the attribute instance :rtype: om.MObject """ if hasAttribute(node, longName): raise ValueError("Node -> '%s' already has attribute -> '%s'" % (nameFromMObject(node), longName)) aobj = None attr = None if attrType == attrtypes.kMFnNumericDouble: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kDouble) elif attrType == attrtypes.kMFnNumericFloat: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kFloat) elif attrType == attrtypes.kMFnNumericBoolean: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kBoolean) elif attrType == attrtypes.kMFnNumericInt: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kInt) elif attrType == attrtypes.kMFnNumericShort: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kShort) elif attrType == attrtypes.kMFnNumericLong: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kLong) elif attrType == attrtypes.kMFnNumericByte: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kByte) elif attrType == attrtypes.kMFnNumericChar: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kChar) elif attrType == attrtypes.kMFnNumericAddr: attr = om2.MFnNumericAttribute() aobj = attr.createAddr(longName, shortName) elif attrType == attrtypes.kMFnkEnumAttribute: attr = om2.MFnEnumAttribute() aobj = attr.create(longName, shortName) elif attrType == attrtypes.kMFnCompoundAttribute: attr = om2.MFnCompoundAttribute() aobj = attr.create(longName, shortName) elif attrType == attrtypes.kMFnMessageAttribute: attr = om2.MFnMessageAttribute() aobj = attr.create(longName, shortName) elif attrType == attrtypes.kMFnDataString: attr = om2.MFnTypedAttribute() stringData = om2.MFnStringData().create("") aobj = attr.create(longName, shortName, om2.MFnData.kString, stringData) elif attrType == attrtypes.kMFnUnitAttributeDistance: attr = om2.MFnUnitAttribute() aobj = attr.create(longName, shortName, om2.MDistance()) elif attrType == attrtypes.kMFnUnitAttributeAngle: attr = om2.MFnUnitAttribute() aobj = attr.create(longName, shortName, om2.MAngle()) elif attrType == attrtypes.kMFnUnitAttributeTime: attr = om2.MFnUnitAttribute() aobj = attr.create(longName, shortName, om2.MTime()) elif attrType == attrtypes.kMFnDataMatrix: attr = om2.MFnMatrixAttribute() aobj = attr.create(longName, shortName) elif attrType == attrtypes.kMFnDataFloatArray: attr = om2.MFnFloatArray() aobj = attr.create(longName, shortName) elif attrType == attrtypes.kMFnDataDoubleArray: data = om2.MFnDoubleArrayData().create(om2.MDoubleArray()) attr = om2.MFnTypedAttribute() aobj = attr.create(longName, shortName, om2.MFnData.kDoubleArray, data) elif attrType == attrtypes.kMFnDataIntArray: data = om2.MFnIntArrayData().create(om2.MIntArray()) attr = om2.MFnTypedAttribute() aobj = attr.create(longName, shortName, om2.MFnData.kIntArray, data) elif attrType == attrtypes.kMFnDataPointArray: data = om2.MFnPointArrayData().create(om2.MPointArray()) attr = om2.MFnTypedAttribute() aobj = attr.create(longName, shortName, om2.MFnData.kPointArray, data) elif attrType == attrtypes.kMFnDataVectorArray: data = om2.MFnVectorArrayData().create(om2.MVectorArray()) attr = om2.MFnTypedAttribute() aobj = attr.create(longName, shortName, om2.MFnData.kVectorArray, data) elif attrType == attrtypes.kMFnDataStringArray: data = om2.MFnStringArrayData().create(om2.MStringArray()) attr = om2.MFnTypedAttribute() aobj = attr.create(longName, shortName, om2.MFnData.kStringArray, data) elif attrType == attrtypes.kMFnDataMatrixArray: data = om2.MFnMatrixArrayData().create(om2.MMatrixArray()) attr = om2.MFnTypedAttribute() aobj = attr.create(longName, shortName, om2.MFnData.kMatrixArray, data) elif attrType == attrtypes.kMFnNumericInt64: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kInt64) elif attrType == attrtypes.kMFnNumericLast: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.kLast) elif attrType == attrtypes.kMFnNumeric2Double: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k2Double) elif attrType == attrtypes.kMFnNumeric2Float: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k2Float) elif attrType == attrtypes.kMFnNumeric2Int: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k2Int) elif attrType == attrtypes.kMFnNumeric2Long: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k2Long) elif attrType == attrtypes.kMFnNumeric2Short: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k2Short) elif attrType == attrtypes.kMFnNumeric3Double: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k3Double) elif attrType == attrtypes.kMFnNumeric3Float: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k3Float) elif attrType == attrtypes.kMFnNumeric3Int: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k3Int) elif attrType == attrtypes.kMFnNumeric3Long: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k3Long) elif attrType == attrtypes.kMFnNumeric3Short: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k3Short) elif attrType == attrtypes.kMFnNumeric4Double: attr = om2.MFnNumericAttribute() aobj = attr.create(longName, shortName, om2.MFnNumericData.k4Double) if aobj is not None and apply: attr.array = isArray mod = om2.MDGModifier() mod.addAttribute(node, aobj) mod.doIt() return attr
def compute(self, plug, datablock): #(1) # (1) Get handles from MPxNode's data block encoded_pose_handle = datablock.inputValue(ikrig_decode.encoded_pose) encoded_pose_marray = om.MFnDoubleArrayData(encoded_pose_handle.data()) encoded_pose_array = encoded_pose_marray.array() offset_mat_Handle = datablock.inputValue(ikrig_decode.offset_mat) offset_mat = offset_mat_Handle.asMatrix() for attr in float_attrs: handle = datablock.inputValue(getattr(ikrig_decode, attr)) exec(attr + "= handle.asFloat()") for attr in out_float3_attrs: handle = datablock.outputValue(getattr(ikrig_decode, attr)) exec(attr + "_Handle = handle") global_mat_Handle = datablock.outputValue(ikrig_decode.global_mat) if len(encoded_pose_array) != 81: return # Global character transform g_tr_x = encoded_pose_array[0] g_tr_y = 0 g_tr_z = encoded_pose_array[1] g_ori = om.MEulerRotation(0, encoded_pose_array[2], 0) g_mat = g_ori.asMatrix() g_mat[12] = g_tr_x * height_hips g_mat[13] = g_tr_y g_mat[14] = g_tr_z * height_hips g_mat *= offset_mat global_mat_Handle.setMMatrix(g_mat) ik_spine_root, ik_spine_eff, ik_spine_upv, ik_spine_eff_rot = encoded2IK( encoded_pose_array[3:16], height_hips, length_spine) ik_spine_root.y += height_hips ik_neck_root, ik_neck_eff, ik_neck_upv, ik_neck_eff_rot = encoded2IK( encoded_pose_array[16:29], height_hips, length_neck) ik_leg_root_L, ik_leg_eff_L, ik_leg_upv_L, ik_leg_eff_rot_L = encoded2IK( encoded_pose_array[29:42], height_hips, length_leg_L) ik_leg_root_R, ik_leg_eff_R, ik_leg_upv_R, ik_leg_eff_rot_R = encoded2IK( encoded_pose_array[42:55], height_hips, length_leg_R) ik_arm_root_L, ik_arm_eff_L, ik_arm_upv_L, ik_arm_eff_rot_L = encoded2IK( encoded_pose_array[55:68], height_hips, length_arm_L) ik_arm_root_R, ik_arm_eff_R, ik_arm_upv_R, ik_arm_eff_rot_R = encoded2IK( encoded_pose_array[68:81], height_hips, length_arm_R) ik_Spine_root_Handle.set3Float(ik_spine_root[0], ik_spine_root[1], ik_spine_root[2]) ik_Spine_eff_Handle.set3Float(ik_spine_eff[0], ik_spine_eff[1], ik_spine_eff[2]) ik_Spine_dir_Handle.set3Float(ik_spine_upv[0], ik_spine_upv[1], ik_spine_upv[2]) ik_Spine_eff_rot_Handle.set3Double(ik_spine_eff_rot[0], ik_spine_eff_rot[1], ik_spine_eff_rot[2]) ik_Neck_root_Handle.set3Float(ik_neck_root[0], ik_neck_root[1], ik_neck_root[2]) ik_Neck_eff_Handle.set3Float(ik_neck_eff[0], ik_neck_eff[1], ik_neck_eff[2]) ik_Neck_dir_Handle.set3Float(ik_neck_upv[0], ik_neck_upv[1], ik_neck_upv[2]) ik_Neck_eff_rot_Handle.set3Double(ik_neck_eff_rot[0], ik_neck_eff_rot[1], ik_neck_eff_rot[2]) ik_Leg_root_L_Handle.set3Float(ik_leg_root_L[0], ik_leg_root_L[1], ik_leg_root_L[2]) ik_Leg_eff_L_Handle.set3Float(ik_leg_eff_L[0], ik_leg_eff_L[1], ik_leg_eff_L[2]) ik_Leg_dir_L_Handle.set3Float(ik_leg_upv_L[0], ik_leg_upv_L[1], ik_leg_upv_L[2]) ik_Leg_eff_rot_L_Handle.set3Double(ik_leg_eff_rot_L[0], ik_leg_eff_rot_L[1], ik_leg_eff_rot_L[2]) ik_Leg_root_R_Handle.set3Float(ik_leg_root_R[0], ik_leg_root_R[1], ik_leg_root_R[2]) ik_Leg_eff_R_Handle.set3Float(ik_leg_eff_R[0], ik_leg_eff_R[1], ik_leg_eff_R[2]) ik_Leg_dir_R_Handle.set3Float(ik_leg_upv_R[0], ik_leg_upv_R[1], ik_leg_upv_R[2]) ik_Leg_eff_rot_R_Handle.set3Double(ik_leg_eff_rot_R[0], ik_leg_eff_rot_R[1], ik_leg_eff_rot_R[2]) ik_Arm_root_L_Handle.set3Float(ik_arm_root_L[0], ik_arm_root_L[1], ik_arm_root_L[2]) ik_Arm_eff_L_Handle.set3Float(ik_arm_eff_L[0], ik_arm_eff_L[1], ik_arm_eff_L[2]) ik_Arm_dir_L_Handle.set3Float(ik_arm_upv_L[0], ik_arm_upv_L[1], ik_arm_upv_L[2]) ik_Arm_eff_rot_L_Handle.set3Double(ik_arm_eff_rot_L[0], ik_arm_eff_rot_L[1], ik_arm_eff_rot_L[2]) ik_Arm_root_R_Handle.set3Float(ik_arm_root_R[0], ik_arm_root_R[1], ik_arm_root_R[2]) ik_Arm_eff_R_Handle.set3Float(ik_arm_eff_R[0], ik_arm_eff_R[1], ik_arm_eff_R[2]) ik_Arm_dir_R_Handle.set3Float(ik_arm_upv_R[0], ik_arm_upv_R[1], ik_arm_upv_R[2]) ik_Arm_eff_rot_R_Handle.set3Double(ik_arm_eff_rot_R[0], ik_arm_eff_rot_R[1], ik_arm_eff_rot_R[2])
def compute(self, plug, datablock): #(1) # (1) Get handles from MPxNode's data block for attr in float_attrs: handle = datablock.inputValue(getattr(ikrig_encode, attr)) exec(attr + "= handle.asFloat()") for attr in mat_attrs: handle = datablock.inputValue(getattr(ikrig_encode, attr)) exec(attr + "= handle.asMatrix()") # Global xfo with default hips height and 2d orientation # get xfo from rest pose mat_hips_delta = mat_hips_rest.inverse() * mat_hips # use xfo to transform direction vector direction = om.MVector([.0, .0, 1.]) * mat_hips_delta # constraint direction to xz plane direction.y = 0 # get all vectors zaxis = direction.normal() yaxis = om.MVector([.0, 1., .0]) xaxis = yaxis ^ zaxis.normal() # build global matrix g_tr_x = mat_hips[12] g_tr_y = height_hips g_tr_z = mat_hips[14] # scale to normalize for height zaxis *= height_hips yaxis *= height_hips xaxis *= height_hips g_mat = om.MMatrix([[xaxis[0], xaxis[1], xaxis[2], 0], [yaxis[0], yaxis[1], yaxis[2], 0], [zaxis[0], zaxis[1], zaxis[2], 0], [g_tr_x, g_tr_y, g_tr_z, 1]]) g_ori = om.MQuaternion() g_ori = g_ori.setValue(g_mat.homogenize()) # chains ik_spine_root, ik_spine_eff, ik_spine_upv, ik_spine_eff_rot = FK2encoded( g_mat, mat_hips, mat_spine, mat_neck, length_spine) # lower body roots are offsets to hips lower_body_mat = om.MMatrix(g_mat) lower_body_mat[12] = mat_hips[12] lower_body_mat[13] = mat_hips[13] lower_body_mat[14] = mat_hips[14] ik_leg_root_L, ik_leg_eff_L, ik_leg_upv_L, ik_leg_eff_rot_L = FK2encoded( lower_body_mat, mat_leg_L, mat_shin_L, mat_foot_L, length_leg_L) ik_leg_root_R, ik_leg_eff_R, ik_leg_upv_R, ik_leg_eff_rot_R = FK2encoded( lower_body_mat, mat_leg_R, mat_shin_R, mat_foot_R, length_leg_R) # upper body roots are offsets to neck upper_body_mat = om.MMatrix(g_mat) upper_body_mat[12] = mat_neck[12] upper_body_mat[13] = mat_neck[13] upper_body_mat[14] = mat_neck[14] ik_arm_root_L, ik_arm_eff_L, ik_arm_upv_L, ik_arm_eff_rot_L = FK2encoded( upper_body_mat, mat_shoulder_L, mat_elbow_L, mat_hand_L, length_arm_L) ik_arm_root_R, ik_arm_eff_R, ik_arm_upv_R, ik_arm_eff_rot_R = FK2encoded( upper_body_mat, mat_shoulder_R, mat_elbow_R, mat_hand_R, length_arm_R) ik_neck_root, ik_neck_eff, ik_neck_upv, ik_neck_eff_rot = FK2encoded( upper_body_mat, mat_neck, mat_neck_mid, mat_head, length_neck) out_components = [ (g_tr_x, g_tr_z), g_ori, ik_spine_root, ik_spine_eff, ik_spine_upv, ik_spine_eff_rot, ik_neck_root, ik_neck_eff, ik_neck_upv, ik_neck_eff_rot, ik_leg_root_L, ik_leg_eff_L, ik_leg_upv_L, ik_leg_eff_rot_L, ik_leg_root_R, ik_leg_eff_R, ik_leg_upv_R, ik_leg_eff_rot_R, ik_arm_root_L, ik_arm_eff_L, ik_arm_upv_L, ik_arm_eff_rot_L, ik_arm_root_R, ik_arm_eff_R, ik_arm_upv_R, ik_arm_eff_rot_R ] result_handle = datablock.outputValue(ikrig_encode.result) output_array = om.MFnDoubleArrayData(result_handle.data()) output_values = [] for component in out_components: for i in range(len(component)): output_values.append(component[i]) output_array.set(output_values) result_handle.setClean()
def compute(self, plug, datablock): #(1) # (1) Get handles from MPxNode's data block encoded_pose_handle = datablock.inputValue(ikrig_decode.encoded_pose) encoded_pose_marray = om.MFnDoubleArrayData(encoded_pose_handle.data()) encoded_pose_array = encoded_pose_marray.array() offset_mat_Handle = datablock.inputValue(ikrig_decode.offset_mat) offset_mat = offset_mat_Handle.asMatrix() for attr in float_attrs: handle = datablock.inputValue(getattr(ikrig_decode, attr)) exec(attr + "= handle.asFloat()") for attr in out_float3_attrs: handle = datablock.outputValue(getattr(ikrig_decode, attr)) exec(attr + "_Handle = handle") global_mat_Handle = datablock.outputValue(ikrig_decode.global_mat) # print(encoded_pose_array.array()) # Global character transform g_tr_x = encoded_pose_array[0] g_tr_y = 0 g_tr_z = encoded_pose_array[1] g_ori = om.MQuaternion(encoded_pose_array[2], encoded_pose_array[3], encoded_pose_array[4], encoded_pose_array[5]) g_mat = g_ori.asMatrix() g_mat[12] = g_tr_x g_mat[13] = g_tr_y g_mat[14] = g_tr_z g_mat *= offset_mat global_mat_Handle.setMMatrix(g_mat) ik_spine_root, ik_spine_eff, ik_spine_upv, ik_spine_eff_rot = encoded2IK( encoded_pose_array[6:19], height_hips, length_spine) ik_spine_root.y += height_hips ik_neck_root, ik_neck_eff, ik_neck_upv, ik_neck_eff_rot = encoded2IK( encoded_pose_array[19:32], height_hips, length_neck) ik_leg_root_L, ik_leg_eff_L, ik_leg_upv_L, ik_leg_eff_rot_L = encoded2IK( encoded_pose_array[32:45], height_hips, length_leg_L) ik_leg_root_R, ik_leg_eff_R, ik_leg_upv_R, ik_leg_eff_rot_R = encoded2IK( encoded_pose_array[45:58], height_hips, length_leg_R) ik_arm_root_L, ik_arm_eff_L, ik_arm_upv_L, ik_arm_eff_rot_L = encoded2IK( encoded_pose_array[58:71], height_hips, length_arm_L) ik_arm_root_R, ik_arm_eff_R, ik_arm_upv_R, ik_arm_eff_rot_R = encoded2IK( encoded_pose_array[71:84], height_hips, length_arm_R) ik_Spine_root_Handle.set3Float(ik_spine_root[0], ik_spine_root[1], ik_spine_root[2]) ik_Spine_eff_Handle.set3Float(ik_spine_eff[0], ik_spine_eff[1], ik_spine_eff[2]) ik_Spine_dir_Handle.set3Float(ik_spine_upv[0], ik_spine_upv[1], ik_spine_upv[2]) ik_Spine_eff_rot_Handle.set3Double(ik_spine_eff_rot[0], ik_spine_eff_rot[1], ik_spine_eff_rot[2]) ik_Neck_root_Handle.set3Float(ik_neck_root[0], ik_neck_root[1], ik_neck_root[2]) ik_Neck_eff_Handle.set3Float(ik_neck_eff[0], ik_neck_eff[1], ik_neck_eff[2]) ik_Neck_dir_Handle.set3Float(ik_neck_upv[0], ik_neck_upv[1], ik_neck_upv[2]) ik_Neck_eff_rot_Handle.set3Double(ik_neck_eff_rot[0], ik_neck_eff_rot[1], ik_neck_eff_rot[2]) ik_Leg_root_L_Handle.set3Float(ik_leg_root_L[0], ik_leg_root_L[1], ik_leg_root_L[2]) ik_Leg_eff_L_Handle.set3Float(ik_leg_eff_L[0], ik_leg_eff_L[1], ik_leg_eff_L[2]) ik_Leg_dir_L_Handle.set3Float(ik_leg_upv_L[0], ik_leg_upv_L[1], ik_leg_upv_L[2]) ik_Leg_eff_rot_L_Handle.set3Double(ik_leg_eff_rot_L[0], ik_leg_eff_rot_L[1], ik_leg_eff_rot_L[2]) ik_Leg_root_R_Handle.set3Float(ik_leg_root_R[0], ik_leg_root_R[1], ik_leg_root_R[2]) ik_Leg_eff_R_Handle.set3Float(ik_leg_eff_R[0], ik_leg_eff_R[1], ik_leg_eff_R[2]) ik_Leg_dir_R_Handle.set3Float(ik_leg_upv_R[0], ik_leg_upv_R[1], ik_leg_upv_R[2]) ik_Leg_eff_rot_R_Handle.set3Double(ik_leg_eff_rot_R[0], ik_leg_eff_rot_R[1], ik_leg_eff_rot_R[2]) ik_Arm_root_L_Handle.set3Float(ik_arm_root_L[0], ik_arm_root_L[1], ik_arm_root_L[2]) ik_Arm_eff_L_Handle.set3Float(ik_arm_eff_L[0], ik_arm_eff_L[1], ik_arm_eff_L[2]) ik_Arm_dir_L_Handle.set3Float(ik_arm_upv_L[0], ik_arm_upv_L[1], ik_arm_upv_L[2]) ik_Arm_eff_rot_L_Handle.set3Double(ik_arm_eff_rot_L[0], ik_arm_eff_rot_L[1], ik_arm_eff_rot_L[2]) ik_Arm_root_R_Handle.set3Float(ik_arm_root_R[0], ik_arm_root_R[1], ik_arm_root_R[2]) ik_Arm_eff_R_Handle.set3Float(ik_arm_eff_R[0], ik_arm_eff_R[1], ik_arm_eff_R[2]) ik_Arm_dir_R_Handle.set3Float(ik_arm_upv_R[0], ik_arm_upv_R[1], ik_arm_upv_R[2]) ik_Arm_eff_rot_R_Handle.set3Double(ik_arm_eff_rot_R[0], ik_arm_eff_rot_R[1], ik_arm_eff_rot_R[2])