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 "Translator/Camera/TranslationCamera.h"
00027 #include "Translator/Camera/TranslationCameraManager.h"
00028 #include "Translator/Model/TranslationModelManager.h"
00029 #include "Translator/Animation/TranslationAnimationUtility.h"
00030 #include "Graphics/Scene/Scene.h"
00031 #include "Graphics/Camera/CameraManager.h"
00032 #include "Graphics/Model/ModelManager.h"
00033 #include "Animation/VectorInterpolator/VectorArrayInterpolator.h"
00034 #include "Animation/RotationInterpolator/EulerArrayInterpolator.h"
00035 #include "Animation/System/AnimationManager.h"
00036 #include "Animation/System/AnimationSet.h"
00037 #include "Animation/Camera/CameraAnimation.h"
00038
00039 namespace LampForMaya{
00040
00041
00042
00043 TranslationCamera::TranslationCamera(
00044 const MDagPath& initializePath, const String& initializeName) :
00045 dagPath_(initializePath), name_(initializeName),
00046 rotationAnimation_(NULL), translationAnimation_(NULL),
00047 hasAnimation_(false){
00048 MStatus result;
00049
00050 object_ = dagPath_.node(&result);
00051 MayaStatusCheck(result);
00052 }
00053
00054
00055 TranslationCamera::~TranslationCamera(){
00056 SafeDelete(translationAnimation_);
00057 SafeDelete(rotationAnimation_);
00058 }
00059
00060
00061 bool TranslationCamera::analyze(){
00062 MStatus result;
00063 String errorString;
00064 MFnDagNode dagNode(dagPath_, &result);
00065 MayaStatusCheck(result);
00066
00067
00068 MFnTransform transform(dagPath_.transform(), &result);
00069 MayaStatusCheck(result);
00070
00071
00072 MPoint scalePivotTrans =
00073 transform.scalePivotTranslation(MSpace::kTransform, &result);
00074 MayaStatusCheck(result);
00075 if(!zeroCheck(scalePivotTrans)){
00076 errorString.format("TranslationCamera::analyze() "
00077 "scalePivotTranslationが0でない ( %8f, %8f, %8f ) %s",
00078 scalePivotTrans.x, scalePivotTrans.y, scalePivotTrans.z,
00079 name_.getBytes());
00080 MayaErrorOut(errorString);
00081 return false;
00082 }
00083
00084
00085 MPoint rotationPivotTrans =
00086 transform.rotatePivotTranslation(MSpace::kTransform, &result);
00087 MayaStatusCheck(result);
00088 if(!zeroCheck(rotationPivotTrans)){
00089 errorString.format("TranslationCamera::analyze() "
00090 "rotationPivotTransが0でない ( %8f, %8f, %8f ) %s",
00091 rotationPivotTrans.x, rotationPivotTrans.y,
00092 rotationPivotTrans.z, name_.getBytes());
00093 MayaErrorOut(errorString);
00094 return false;
00095 }
00096
00097
00098 double shearArray[3];
00099 result = transform.getShear(shearArray);
00100 MPoint shear(shearArray);
00101 if(!zeroCheck(shear)){
00102 errorString.format("TranslationCamera::analyze() "
00103 "shearが0でない ( %8f, %8f, %8f ) %s",
00104 shear.x, shear.y, shear.z, name_.getBytes());
00105 MayaErrorOut(errorString);
00106 return false;
00107 }
00108
00109
00110 MPoint scalePivot = transform.scalePivot(MSpace::kTransform, &result);
00111 MayaStatusCheck(result);
00112 if(!zeroCheck(scalePivot)){
00113 errorString.format("TranslationCamera::analyze() "
00114 "scalePivotが0でない ( %8f, %8f, %8f ) %s",
00115 scalePivot.x, scalePivot.y, scalePivot.z,
00116 name_.getBytes());
00117 MayaErrorOut(errorString);
00118 return false;
00119 }
00120
00121
00122 MPoint rotationPivot = transform.rotatePivot(MSpace::kTransform, &result);
00123 MayaStatusCheck(result);
00124 if(!zeroCheck(rotationPivot)){
00125 errorString.format("TranslationCamera::analyze() "
00126 "rotationPivotTransが0でない ( %8f, %8f, %8f ) %s",
00127 rotationPivot.x, rotationPivot.y,
00128 rotationPivot.z, name_.getBytes());
00129 MayaErrorOut(errorString);
00130 return false;
00131 }
00132
00133
00134 double scale[3];
00135 result = transform.getScale(scale);
00136 MayaStatusCheck(result);
00137 if((scale[0] != 1.0) || (scale[1] != 1.0) || (scale[2] != 1.0)){
00138 errorString.format("TranslationCamera::analyze() "
00139 "scaleが1でない ( %8f, %8f, %8f ) %s",
00140 (float)scale[0], (float)scale[1], (float)scale[2],
00141 name_.getBytes());
00142 MayaErrorOut(errorString);
00143 return false;
00144 }
00145
00146
00147 MEulerRotation rotation;
00148 result = transform.getRotation(rotation);
00149 MayaStatusCheck(result);
00150 if(rotation.order != MEulerRotation::kXYZ){
00151 errorString.format("TranslationCamera::analyze() "
00152 "回転順序はXYZしかサポートしていません %s", name_.getBytes());
00153 MayaErrorOut(errorString);
00154 return false;
00155 }
00156 rotation_.set((float)rotation.x, (float)rotation.y, (float)rotation.z);
00157
00158
00159 MVector translation = transform.translation(MSpace::kTransform, &result);
00160 MayaStatusCheck(result);
00161 translation_.set(
00162 (float)translation.x, (float)translation.y, (float)translation.z);
00163
00164
00165
00166
00167
00168
00169
00170 return true;
00171 }
00172
00173
00174 bool TranslationCamera::zeroCheck(const MPoint& point){
00175 if( (Math::abs((float)point.x) > Math::epsilon) ||
00176 (Math::abs((float)point.y) > Math::epsilon) ||
00177 (Math::abs((float)point.z) > Math::epsilon)){
00178 return false;
00179 }
00180 return true;
00181 }
00182
00183
00184 bool TranslationCamera::analyzeAnimation(){
00185 hasAnimation_ = false;
00186
00187 if(!sequence_.analyze(object_)){ return true; }
00188 int startTime = sequence_.getStartTime(0);
00189 int endTime = sequence_.getEndTime(sequence_.getSequenceCount() - 1);
00190
00191
00192
00193 rotationAnimation_ =
00194 TranslationAnimationUtility::analyzeRotationAnimation(
00195 dagPath_.transform(), "rotate", rotation_, startTime, endTime);
00196 if(rotationAnimation_ != NULL){ hasAnimation_ = true; }
00197
00198 translationAnimation_ =
00199 TranslationAnimationUtility::analyzeVectorAnimation(
00200 dagPath_.transform(), "translate", translation_, startTime, endTime);
00201 if(translationAnimation_ != NULL){ hasAnimation_ = true; }
00202
00203
00204
00205 return true;
00206 }
00207
00208
00209 bool TranslationCamera::convertToLamp(Scene* scene){
00210 CameraManager* cameraManager = scene->getCameraManager();
00211 camera_ = cameraManager->createCamera(name_);
00212 camera_->setTransformation(rotation_, translation_);
00213 return true;
00214 }
00215
00216
00217 bool TranslationCamera::convertAnimation(
00218 AnimationManager* animationManager, AnimationSet* animationSet){
00219 if(!hasAnimation_){ return true; }
00220 if(!sequence_.hasSequence()){ return true; }
00221 CameraAnimation* animation = animationManager->createCamera(name_);
00222 if(animation->getName() != name_){
00223 MayaErrorOut(String("TranslationCamera::convertAnimation() ") +
00224 name_ + "の名前が重複しています ");
00225 return false;
00226 }
00227 CameraAnimationData* data =
00228 animationManager->createCameraData(name_);
00229 if(data->getName() != name_){
00230 MayaErrorOut(String("TranslationCamera::convertAnimation() ") +
00231 name_ + "の名前が重複しています ");
00232 return false;
00233 }
00234
00235 animation->setTargetName(name_);
00236 animation->setCameraAnimationData(data);
00237 animationSet->addAnimation(animation);
00238
00239 int sequenceCount = sequence_.getSequenceCount();
00240 data->setSequenceCount(sequenceCount);
00241 for(int i = 0; i < sequenceCount; i++){
00242 int startTime = sequence_.getStartTime(i);
00243 int endTime = sequence_.getEndTime(i);
00244 int size = endTime - startTime + 1;
00245
00246 EulerArrayInterpolator* rotation = NULL;
00247 if(rotationAnimation_ != NULL){
00248 rotation = new EulerArrayInterpolator();
00249 rotation->setSize(size);
00250 for(int j = 0; j < size; j++){
00251 rotation->setValue(j,
00252 rotationAnimation_->getValue(startTime + j));
00253 }
00254 }
00255
00256 VectorArrayInterpolator* translation = NULL;
00257 if(translationAnimation_ != NULL){
00258 translation = new VectorArrayInterpolator();
00259 translation->setSize(size);
00260 for(int j = 0; j < size; j++){
00261 translation->setValue(j,
00262 translationAnimation_->getValue(startTime + j));
00263 }
00264 }
00265
00266 if(rotation != NULL){ data->setRotation(i, rotation); }
00267 if(translation != NULL){
00268 data->setTranslation(i, translation);
00269 }
00270 data->setLooped(i, sequence_.isLooped(i));
00271 }
00272 return true;
00273 }
00274
00275 }
00276