00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "System/stdafx.h"
00026 #include "Utility/MayaAttributeUtility.h"
00027
00028 namespace LampForMaya{
00029
00030
00031
00032 MObject MayaAttributeUtility::getAttribute(
00033 const MObject& node, const String& attributeName){
00034 MStatus result;
00035 MFnDependencyNode dependencyNode(node, &result);
00036 MayaStatusCheck(result);
00037 MString attrName(attributeName.getBytes());
00038 MObject attribute = dependencyNode.attribute(attrName, &result);
00039 MayaStatusCheck(result);
00040 return attribute;
00041 }
00042
00043
00044 MPlug MayaAttributeUtility::getPlug(
00045 const MObject& node, const String& plugName){
00046 MStatus result;
00047 MFnDependencyNode dependencyNode(node, &result);
00048 MayaStatusCheck(result);
00049 MPlug plug = dependencyNode.findPlug(plugName.getBytes(), &result);
00050 MayaStatusCheck(result);
00051 return plug;
00052 }
00053
00054
00055 bool MayaAttributeUtility::getBool(
00056 const MObject& node, const MObject& attribute){
00057 bool value;
00058 MPlug plug(node, attribute);
00059 MayaStatusCheck(plug.getValue(value));
00060 return value;
00061 }
00062
00063
00064 bool MayaAttributeUtility::getBool(
00065 const MObject& node, const String& attributeName){
00066 return getBool(node, getAttribute(node, attributeName));
00067 }
00068
00069
00070 int MayaAttributeUtility::getInt(
00071 const MObject& node, const MObject& attribute){
00072 int value;
00073 MPlug plug(node, attribute);
00074 MayaStatusCheck(plug.getValue(value));
00075 return value;
00076 }
00077
00078
00079 int MayaAttributeUtility::getInt(
00080 const MObject& node, const String& attributeName){
00081 return getInt(node, getAttribute(node, attributeName));
00082 }
00083
00084
00085 float MayaAttributeUtility::getFloat(
00086 const MObject& node, const MObject& attribute){
00087 float value;
00088 MPlug plug(node, attribute);
00089 MayaStatusCheck(plug.getValue(value));
00090 return value;
00091 }
00092
00093
00094 float MayaAttributeUtility::getFloat(
00095 const MObject& node, const String& attributeName){
00096 return getFloat(node, getAttribute(node, attributeName));
00097 }
00098
00099
00100 String MayaAttributeUtility::getString(
00101 const MObject& node, const MObject& attribute){
00102 MString value;
00103 MPlug plug(node, attribute);
00104 MayaStatusCheck(plug.getValue(value));
00105 return String(value.asChar());
00106 }
00107
00108
00109 String MayaAttributeUtility::getString(
00110 const MObject& node, const String& attributeName){
00111 return getString(node, getAttribute(node, attributeName));
00112 }
00113
00114
00115 Color3f MayaAttributeUtility::getColor3f(
00116 const MObject& node, const MObject& attribute){
00117 MStatus result;
00118 MPlug plug(node, attribute);
00119 MObject plugData;
00120 MayaStatusCheck(plug.getValue(plugData));
00121 MFnNumericData data(plugData, &result);
00122 MayaStatusCheck(result);
00123 Color3f value;
00124 MayaStatusCheck(data.getData(value.r, value.g, value.b));
00125 return value;
00126 }
00127
00128
00129 Color3f MayaAttributeUtility::getColor3f(
00130 const MObject& node, const String& attributeName){
00131 return getColor3f(node, getAttribute(node, attributeName));
00132 }
00133
00134
00135 Vector3 MayaAttributeUtility::getVector(
00136 const MObject& node, const MObject& attribute){
00137 MStatus result;
00138 MPlug plug(node, attribute);
00139 MObject plugData;
00140 MayaStatusCheck(plug.getValue(plugData));
00141 MFnNumericData data(plugData, &result);
00142 MayaStatusCheck(result);
00143 Vector3 value;
00144 MayaStatusCheck(data.getData(value.x, value.y, value.z));
00145 return value;
00146 }
00147
00148
00149 Vector3 MayaAttributeUtility::getVector(
00150 const MObject& node, const String& attributeName){
00151 return getVector(node, getAttribute(node, attributeName));
00152 }
00153
00154
00155 Matrix44 MayaAttributeUtility::getMatrix(
00156 const MObject& node, const MObject& attribute){
00157 MStatus result;
00158 MPlug plug(node, attribute);
00159 MObject plugData;
00160 MayaStatusCheck(plug.getValue(plugData));
00161 MFnMatrixData data(plugData, &result);
00162 MayaStatusCheck(result);
00163 const MMatrix& matrix = data.matrix(&result);
00164 MayaStatusCheck(result);
00165 Matrix44 value;
00166
00167 for(int i = 0; i < 4; i++){
00168 for(int j = 0; j < 4; j++){ value.m[i][j] = (float)matrix[j][i]; }
00169 }
00170 return value;
00171 }
00172
00173
00174 Matrix44 MayaAttributeUtility::getMatrix(
00175 const MObject& node, const String& attributeName){
00176 return getMatrix(node, getAttribute(node, attributeName));
00177 }
00178
00179 }
00180