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 * 変換アニメーションユーティリティ実装 00022 * @author Junpee 00023 */ 00024 00025 #include "System/stdafx.h" 00026 #include "Translator/Animation/TranslationAnimationUtility.h" 00027 #include "Animation/VectorInterpolator/VectorArrayInterpolator.h" 00028 #include "Animation/RotationInterpolator/EulerArrayInterpolator.h" 00029 00030 namespace LampForMaya{ 00031 00032 //------------------------------------------------------------------------------ 00033 // ベクトルアニメーションの分析 00034 VectorArrayInterpolator* TranslationAnimationUtility::analyzeVectorAnimation( 00035 const MObject& object, const MString& attributeName, 00036 const Vector3& defaultValue, int startTime, int endTime){ 00037 MStatus result; 00038 MFnDependencyNode dependencyNode(object, &result); 00039 MayaStatusCheck(result); 00040 // アニメーションしているかどうか調査 00041 MPlug xPlug = dependencyNode.findPlug(attributeName + "X", &result); 00042 MayaStatusCheck(result); 00043 // bool xAnimated = isAnimated(xPlug, startTime, endTime); 00044 MPlug yPlug = dependencyNode.findPlug(attributeName + "Y", &result); 00045 MayaStatusCheck(result); 00046 // bool yAnimated = isAnimated(yPlug, startTime, endTime); 00047 MPlug zPlug = dependencyNode.findPlug(attributeName + "Z", &result); 00048 MayaStatusCheck(result); 00049 // bool zAnimated = isAnimated(zPlug, startTime, endTime); 00050 // if((!xAnimated) && (!yAnimated) && (!zAnimated)){ return NULL; } 00051 // アニメーションデータの読み出し 00052 VectorArrayInterpolator* interpolator = 00053 new VectorArrayInterpolator(); 00054 int size = endTime - startTime + 1; 00055 interpolator->setSize(endTime - startTime + 1); 00056 for(int i = 0; i < size; i++){ 00057 Vector3 value(defaultValue); 00058 MDGContext context(MTime((double)(startTime + i))); 00059 // if(xAnimated){ xPlug.getValue(value.x, context); } 00060 // if(yAnimated){ yPlug.getValue(value.y, context); } 00061 // if(zAnimated){ zPlug.getValue(value.z, context); } 00062 xPlug.getValue(value.x, context); 00063 yPlug.getValue(value.y, context); 00064 zPlug.getValue(value.z, context); 00065 interpolator->setValue(startTime + i, value); 00066 } 00067 return interpolator; 00068 } 00069 //------------------------------------------------------------------------------ 00070 // 回転アニメーションの分析 00071 EulerArrayInterpolator* 00072 TranslationAnimationUtility::analyzeRotationAnimation( 00073 const MObject& object, const MString& attributeName, 00074 const Vector3& defaultValue, int startTime, int endTime){ 00075 MStatus result; 00076 MFnDependencyNode dependencyNode(object, &result); 00077 MayaStatusCheck(result); 00078 // アニメーションしているかどうか調査 00079 MPlug xPlug = dependencyNode.findPlug(attributeName + "X", &result); 00080 MayaStatusCheck(result); 00081 // bool xAnimated = isAnimated(xPlug, startTime, endTime); 00082 MPlug yPlug = dependencyNode.findPlug(attributeName + "Y", &result); 00083 MayaStatusCheck(result); 00084 // bool yAnimated = isAnimated(yPlug, startTime, endTime); 00085 MPlug zPlug = dependencyNode.findPlug(attributeName + "Z", &result); 00086 MayaStatusCheck(result); 00087 // bool zAnimated = isAnimated(zPlug, startTime, endTime); 00088 // if((!xAnimated) && (!yAnimated) && (!zAnimated)){ return NULL; } 00089 // アニメーションデータの読み出し 00090 EulerArrayInterpolator* interpolator = 00091 new EulerArrayInterpolator(); 00092 int size = endTime - startTime + 1; 00093 interpolator->setSize(endTime - startTime + 1); 00094 for(int i = 0; i < size; i++){ 00095 Vector3 value(defaultValue); 00096 MDGContext context(MTime((double)(startTime + i))); 00097 // if(xAnimated){ xPlug.getValue(value.x, context); } 00098 // if(yAnimated){ yPlug.getValue(value.y, context); } 00099 // if(zAnimated){ zPlug.getValue(value.z, context); } 00100 xPlug.getValue(value.x, context); 00101 yPlug.getValue(value.y, context); 00102 zPlug.getValue(value.z, context); 00103 interpolator->setValue(startTime + i, value); 00104 } 00105 return interpolator; 00106 } 00107 //------------------------------------------------------------------------------ 00108 // アニメーションしているか 00109 /* 00110 bool TranslationAnimationUtility::isAnimated( 00111 const MPlug& plug, int startTime, int endTime){ 00112 MStatus result; 00113 bool animated = MAnimUtil::isAnimated(plug, true, &result); 00114 MayaStatusCheck(result); 00115 // アニメーションフラグが立っていればtrue 00116 if(animated){ return true; } 00117 // アニメーションフラグが立っていなくても値に変化があればtrue 00118 int size = endTime - startTime + 1; 00119 float startValue; 00120 MDGContext startContext(MTime((double)(startTime))); 00121 plug.getValue(startValue, startContext); 00122 for(int i = 0; i < size; i++){ 00123 MDGContext context(MTime((double)(startTime + i))); 00124 float value; 00125 plug.getValue(value, context); 00126 if(Math::abs(startValue - value) > Math::epsilon){ return true; } 00127 } 00128 return false; 00129 } 00130 */ 00131 //------------------------------------------------------------------------------ 00132 } // End of namespace LampForMaya 00133 //------------------------------------------------------------------------------