Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

# MayaAttributeUtility.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * Mayaアトリビュートユーティリティ実装
    00022  * @author Junpee
    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 } // End of namespace LampForMaya
    00180 //------------------------------------------------------------------------------