MStatus preview(const MArgList& args,bool useVertexColor) { //单实例先清除 if(MaterialSet::getSingletonPtr()) MaterialSet::getSingletonPtr()->clear(); char tempPath[MAX_PATH]; GetTempPath(MAX_PATH, tempPath); std::string tempFileName(tempPath); ExportOptions::instance().m_outFilePath = tempFileName.c_str(); tempFileName += "\\"; tempFileName += _T("maya.mz"); ExportOptions::instance().m_outFile = tempFileName.c_str(); ExportOptions::instance().clipList.clear(); MTime kTimeMin = MAnimControl::animationStartTime(); //整个场景的起始帧 MTime kTimeMax = MAnimControl::animationEndTime(); //整个场景的结束帧 clipInfo clip; clip.name = "Animation"; clip.startFrame = (int)kTimeMin.value(); clip.endFrame = (int)kTimeMax.value(); clip.stepFrame = 1; ExportOptions::instance().clipList.push_back(clip); ExportOptions::instance().exportAnims = true; ExportOptions::instance().exportVertexColour = useVertexColor; /*BindPoseTool bindPoseTool; bindPoseTool.GoIntoBindPose();*/ MWriter writer; writer.read(); MStatus status = writer.write(); #ifdef RELEASEDEBUG #define DLL_NAME "MayaPreview_rd.exe" #elif _DEBUG #define DLL_NAME "MayaPreview_d.exe" #else #define DLL_NAME "MayaPreview.exe" #endif if(status == MS::kSuccess) { HWND hWnd = FindWindowEx(0,0,0,"MayaPreview"); //if(hWnd) //{ // SendMessage(hWnd,WM_CLOSE,0,0); // hWnd = 0; //} if(!hWnd) { static const std::string tMaxProgramName("Maya.exe"); char path[257]; GetModuleFileName(GetModuleHandle(tMaxProgramName.c_str()),path,256); std::string parentPath(path); parentPath.erase(parentPath.size() - tMaxProgramName.size(), tMaxProgramName.size()); std::string previewProgramPath(parentPath + "preview\\" + DLL_NAME); if(!ShellExecute(0,"open",previewProgramPath.c_str(),"","",SW_SHOW)) { MessageBox(0,previewProgramPath.c_str(),"Can't Find MayaPreview Program",0); return MS::kFailure; } hWnd = FindWindowEx(0,0,0,"MayaPreview"); DWORD tick = GetTickCount(); while(!hWnd) { DWORD tickNow = GetTickCount(); if(tickNow - tick > 3000)break; Sleep(1); hWnd = FindWindowEx(0,0,0,"MayaPreview"); } } if(hWnd) { SendMessage(hWnd,WM_USER + 128,0,0); SetActiveWindow(hWnd); SetForegroundWindow(hWnd); BringWindowToTop(hWnd); } } /*bindPoseTool .UndoGoIntoBindPose();*/ return MS::kSuccess; }
bool Effect::loadFromFile( const std::string& filename ) { // Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the // shader debugger. Debugging vertex shaders requires either REF or software vertex // processing, and debugging pixel shaders requires REF. The // D3DXSHADER_FORCE_*_SOFTWARE_NOOPT flag improves the debug experience in the // shader debugger. It enables source level debugging, prevents instruction // reordering, prevents dead code elimination, and forces the compiler to compile // against the next higher available software target, which ensures that the // unoptimized shaders do not exceed the shader model limitations. Setting these // flags will cause slower rendering since the shaders will be unoptimized and // forced into software. See the DirectX documentation for more information about // using the shader debugger. DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE; #if defined( DEBUG ) || defined( _DEBUG ) // Set the D3DXSHADER_DEBUG flag to embed debug information in the shaders. // Setting this flag improves the shader debugging experience, but still allows // the shaders to be optimized and to run exactly the way they will run in // the release configuration of this program. dwShaderFlags |= D3DXSHADER_DEBUG; #endif #ifdef DEBUG_VS dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT; #endif #ifdef DEBUG_PS dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT; #endif // Preshaders are parts of the shader that the effect system pulls out of the // shader and runs on the host CPU. They should be used if you are GPU limited. // The D3DXSHADER_NO_PRESHADER flag disables preshaders. //if( !g_bEnablePreshader ) // dwShaderFlags |= D3DXSHADER_NO_PRESHADER; // Create an effect from an ASCII or binary effect description // std::string data = filename; HRESULT hr; if (FAILED(hr = D3DXCreateEffectFromFile(Paras::getInstancePtr()->_device, data.c_str(), NULL, NULL, dwShaderFlags, NULL, &_effect, NULL))) { data.clear(); Buddha::FileSystem::getInstancePtr()->getDataDirectory(data); data += filename; if (FAILED(hr = D3DXCreateEffectFromFile(Paras::getInstancePtr()->_device, data.c_str(), NULL, NULL, dwShaderFlags, NULL, &_effect, NULL))) { data.clear(); // char path[257]; static const std::string tMaxProgramName("MaxPreview.exe"); GetModuleFileName(GetModuleHandle(tMaxProgramName.c_str()), path, 256); std::string parentPath(path); parentPath.erase(parentPath.size() - tMaxProgramName.size(), tMaxProgramName.size()); std::string previewProgramPath(parentPath); // data = previewProgramPath + filename; if (FAILED(hr = D3DXCreateEffectFromFile(Paras::getInstancePtr()->_device, data.c_str(), NULL, NULL, dwShaderFlags, NULL, &_effect, NULL))) { std::ostringstream buf; buf<<"D3DXCreateTextureFromFile "<<filename<<" Error Code : "<<(hr); Error(buf.str()); return false; } } } return true; }