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/Light/TranslationLightManager.h"
00027
00028 namespace LampForMaya{
00029
00030
00031
00032 TranslationLightManager::TranslationLightManager() :
00033 database_(256, 0.75f), array_(256){
00034 }
00035
00036
00037 TranslationLightManager::~TranslationLightManager(){
00038 Assert(database_.getCount() == 0);
00039 Assert(array_.getCount() == 0);
00040 if(getCount() != 0){ clear(); }
00041 }
00042
00043
00044 bool TranslationLightManager::collectLights(){
00045 MStatus result;
00046 MItDag dagIterator(MItDag::kBreadthFirst, MFn::kLight, &result);
00047 MayaStatusCheck(result);
00048 MDagPath dagPath;
00049 for( ; !dagIterator.isDone(); dagIterator.next()){
00050 result = dagIterator.getPath(dagPath);
00051 MayaStatusCheck(result);
00052 MFnDagNode dagNode(dagPath, &result);
00053 MayaStatusCheck(result);
00054
00055 MString dagName = dagNode.name(&result);
00056 MayaStatusCheck(result);
00057
00058 if(!dagPath.hasFn(MFn::kLight)){ continue; }
00059
00060 if(dagNode.isIntermediateObject()){ continue; }
00061
00062 if(!analysisLight(dagPath)){ return false; }
00063 }
00064 return true;
00065 }
00066
00067
00068 bool TranslationLightManager::analysisLight(const MDagPath& dagPath){
00069 MStatus result;
00070 MFnDagNode lightNode(dagPath, &result);
00071 MayaStatusCheck(result);
00072 if( (!dagPath.hasFn(MFn::kAmbientLight)) &&
00073 (!dagPath.hasFn(MFn::kDirectionalLight)) &&
00074 (!dagPath.hasFn(MFn::kPointLight)) ){ return true; }
00075
00076 MObject lightObject = dagPath.node(&result);
00077 MayaStatusCheck(result);
00078
00079 String lightName = lightNode.name(&result).asChar();
00080 MayaStatusCheck(result);
00081 TranslationLight* exist = database_.get(lightName);
00082 if(exist != NULL){
00083
00084 if(exist->getObject() != lightObject){
00085 MayaErrorOut(String("TranslationLightManager::analysisModel() "
00086 "名前が重複しています ") + lightName);
00087 return false;
00088 }
00089 return true;
00090 }
00091
00092 TranslationLight* light = NULL;
00093 if(dagPath.hasFn(MFn::kAmbientLight)){
00094 light = new TranslationAmbientLight(dagPath, lightName);
00095 }else if(dagPath.hasFn(MFn::kDirectionalLight)){
00096 light = new TranslationDirectionalLight(dagPath, lightName);
00097 }else if(dagPath.hasFn(MFn::kPointLight)){
00098 light = new TranslationPointLight(dagPath, lightName);
00099 }
00100 if(!light->analyze()){
00101 delete light;
00102 return false;
00103 }
00104 database_.put(lightName, light);
00105 array_.add(light);
00106 return true;
00107 }
00108
00109
00110 bool TranslationLightManager::convertToLamp(Scene* scene) const{
00111 for(int i = 0; i < getCount(); i++){
00112 if(!get(i)->convertToLamp(scene)){ return false; }
00113 }
00114 return true;
00115 }
00116
00117
00118 int TranslationLightManager::clear(){
00119 int result = getCount();
00120
00121 for(int i = 0; i < result; i++){ delete array_.get(i); }
00122 array_.clear();
00123 database_.clear();
00124 return result;
00125 }
00126
00127 }
00128