XSIPLUGINCALLBACK XSI::CStatus VMFImportProperty_Define( const CRef & in_Ctx ) { Application app ; CustomProperty prop = Context(in_Ctx).GetSource() ; Parameter param ; // Default capabilities for most of these parameters int caps = siPersistable ; CValue dft ; // Used for arguments we don't want to set prop.AddParameter( L"Filename",CValue::siString, caps, L"Filename", L"", dft, param ) ; prop.AddParameter( L"TexturePath",CValue::siString, caps, L"Texture path", L"", dft, param ) ; dft = true; prop.AddParameter( L"UseMaterials",CValue::siBool, caps, L"Import Materials", L"", dft, param ) ; return CStatus::OK; }
Parameter Get3DCoatParam( const CString& in_strName ) { CustomProperty pset = Get3DCoatProp(); if (!pset.IsValid()) return CRef(); Parameter param = pset.GetParameters().GetItem(in_strName); return param; }
//***************************************************************************** CustomProperty Get3DCoatProp() { //Application app; Model root = app.GetActiveSceneRoot(); CustomProperty prop = root.GetProperties().GetItem(L"AppLink_3DCoat"); if (!prop.IsValid()) { prop = root.AddProperty( L"AppLink_3DCoat" ); } return prop; }
// Callback for the siOnActivateEvent event. SICALLBACK siOnActivateEvent_OnEvent( CRef& in_ctxt ) { Context ctxt( in_ctxt ); //Application().LogMessage(L"siOnActivateEvent_OnEvent called",siVerboseMsg); //Application().LogMessage(L"State: " + CString(ctxt.GetAttribute(L"State")),siVerboseMsg); bool bState = ctxt.GetAttribute(L"State"); if(bState) { CustomProperty prop = app.GetActiveSceneRoot().GetProperties().GetItem(L"AppLink_3DCoat"); if (prop.IsValid()) { if(prop.GetParameter("bEvent").GetValue()) { CString s_CoatLocation = prop.GetParameter(L"coatLocation").GetValue(); CString exportPath = CUtils::BuildPath(s_CoatLocation, L"export.txt"); CString objPath; std::ifstream fileref(exportPath.GetAsciiString()); bool bfile = false; if(fileref.good()) { std::string row; std::getline(fileref, row); objPath = row.c_str(); bfile = true; } fileref.close(); if(bfile) { UIToolkit uitool = Application().GetUIToolkit(); LONG out; uitool.MsgBox(L"Import file?", siMsgOkCancel|siMsgInformation|MB_APPLMODAL, L"", (LONG) out); if(out == siMsgOk) { app.LogMessage(L"Start Import!"); CValueArray args(2); args[0] = objPath; args[1] = prop.GetParameterValue( L"bReplace" ); CValue noret; app.ExecuteCommand( L"Coat3DImport", args, noret ) ; } } } } } // Return value is ignored as this event can not be aborted. return CStatus::OK; }
void FindFolder3DCoatV(CustomProperty& prop, TCHAR* path) { CString exePath = CUtils::BuildPath(path, L"3D-Coat-V3"); if(FileOrDirectoryExists(exePath.GetAsciiString(), true)) { prop.GetParameter(L"exeLocation").PutValue(exePath + CUtils::Slash()); } else { exePath = CUtils::BuildPath(path, L"3D-Coat-V4"); if(FileOrDirectoryExists(exePath.GetAsciiString(), true)) { prop.GetParameter(L"exeLocation").PutValue(exePath + CUtils::Slash()); } else { prop.GetParameter(L"exeLocation").PutValue(L""); } } }
// Property Define ============================================ XSIPLUGINCALLBACK CStatus sn_squashstretch_prop_Define( CRef& in_ctxt ) { Context ctxt( in_ctxt ); CustomProperty oCustomProperty; Parameter oParam; oCustomProperty = ctxt.GetSource(); oCustomProperty.AddParameter(L"blend",CValue::siDouble,siPersistable | siAnimatable,L"",L"",1,0,1,0,1,oParam); oCustomProperty.AddParameter(L"sq_min",CValue::siDouble,siPersistable | siAnimatable,L"",L"",0,-100000,100000,0,1,oParam); oCustomProperty.AddParameter(L"sq_max",CValue::siDouble,siPersistable | siAnimatable,L"",L"",5,-100000,100000,0,1,oParam); oCustomProperty.AddParameter(L"sq_y",CValue::siDouble,siPersistable | siAnimatable,L"",L"",1,-100000,100000,0,1,oParam); oCustomProperty.AddParameter(L"sq_z",CValue::siDouble,siPersistable | siAnimatable,L"",L"",1,-100000,100000,0,1,oParam); oCustomProperty.AddParameter(L"st_min",CValue::siDouble,siPersistable | siAnimatable,L"",L"",5,-100000,100000,0,1,oParam); oCustomProperty.AddParameter(L"st_max",CValue::siDouble,siPersistable | siAnimatable,L"",L"",10,-100000,100000,0,1,oParam); oCustomProperty.AddParameter(L"st_y",CValue::siDouble,siPersistable | siAnimatable,L"",L"",.5,-100000,100000,1,5,oParam); oCustomProperty.AddParameter(L"st_z",CValue::siDouble,siPersistable | siAnimatable,L"",L"",.5,-100000,100000,1,5,oParam); oCustomProperty.AddParameter(L"sq_y_profile",CValue::siDouble,siPersistable | siAnimatable,L"",L"",1,-100000,100000,1,5,oParam); oCustomProperty.AddParameter(L"sq_z_profile",CValue::siDouble,siPersistable | siAnimatable,L"",L"",1,-100000,100000,1,5,oParam); oCustomProperty.AddParameter(L"st_y_profile",CValue::siDouble,siPersistable | siAnimatable,L"",L"",1,-100000,100000,1,5,oParam); oCustomProperty.AddParameter(L"st_z_profile",CValue::siDouble,siPersistable | siAnimatable,L"",L"",1,-100000,100000,1,5,oParam); return CStatus::OK; }
SICALLBACK AppLink_3DCoat_Define( CRef& in_ctxt ) { Context ctxt( in_ctxt ); CustomProperty pset; Parameter param; pset = ctxt.GetSource(); CValue dft ; pset.AddParameter(L"Logo", CValue::siString, NULL, L"", L"", dft, param); pset.AddParameter(L"tempLocation", CValue::siString, siPersistable, L"Temp Path", L"", dft, param); pset.AddParameter(L"coatLocation", CValue::siString, siPersistable, L"Exchange Path", L"", dft, param); pset.AddParameter(L"exeLocation", CValue::siString, siPersistable, L"3D-Coat.exe", L"", dft, param); pset.AddParameter(L"typePaint", CValue::siUInt1, NULL, L"Painting type", L"", (LONG)0, (LONG)0, (LONG)9, dft, dft, param); pset.AddParameter(L"bExpNorm", CValue::siBool, NULL, L"Normals", L"", true, param); pset.AddParameter(L"bExpMat", CValue::siBool, NULL, L"Material", L"", true, param); pset.AddParameter(L"bExpUV", CValue::siBool, NULL, L"Current UV Set", L"", true, param); pset.AddParameter(L"bExpSkipImp", CValue::siBool, NULL, L"Skip Import Dialog", L"", false, param); pset.AddParameter(L"bExpSkipExp", CValue::siBool, NULL, L"Skip Export Dialog", L"", false, param); //pset.AddParameter(L"bCopyTexE", CValue::siBool, NULL, L"Copy textures", L"", false, param); pset.AddParameter(L"bStart", CValue::siBool, NULL, L"Start 3D-Coat", L"", true, param); //pset.AddParameter(L"bCopyTexI", CValue::siBool, NULL, L"Copy textures", L"", false, param); pset.AddParameter(L"bReplace", CValue::siBool, NULL, L"Replace Objects", L"", true, param); pset.AddParameter(L"bEvent", CValue::siBool, NULL, L"Prompt", L"", false, param); pset.AddParameter(L"bImpNorm", CValue::siBool, NULL, L"Normals", L"", true, param); pset.AddParameter(L"bImpMat", CValue::siBool, NULL, L"Material", L"", true, param); //pset.AddParameter(L"bImpNewMat", CValue::siBool, NULL, L"New material", L"", false, param); pset.AddParameter(L"swMap", CValue::siUInt1, NULL, L"Map type", L"", (LONG)0, (LONG)0, (LONG)1, dft, dft, param); pset.AddParameter(L"bImpUV", CValue::siBool, NULL, L"UV Set", L"", true, param); return CStatus::OK; }
SICALLBACK AppLink_3DCoat_PPGEvent( const CRef& in_ctxt ) { //Application app; PPGEventContext ctxt( in_ctxt ) ; CustomProperty prop = ctxt.GetSource(); PPGEventContext::PPGEvent eventID = ctxt.GetEventID() ; //CString s_ExeLocation = prop.GetParameter(L"coatExe").GetValue(); if ( eventID == PPGEventContext::siOnInit ) { CString s_ExportLocation = prop.GetParameter(L"tempLocation").GetValue(); CString s_CoatLocation = prop.GetParameter(L"coatLocation").GetValue(); Plugin pl(app.GetPlugins().GetItem(L"AppLink_3DCoat_Plugin")); pluginPath = CUtils::BuildPath(app.GetInstallationPath(pl.GetOrigin()), L"AppLink_3DCoat", L"Application", L"Plugins"); if(prop.GetParameter(L"tempLocation").GetValue() == L"") { Project prj = app.GetActiveProject(); Scene scn = prj.GetActiveScene(); CString tempPath = CUtils::BuildPath(app.GetInstallationPath(siProjectPath), L"3DCoat", scn.GetName(), scn.GetName() + L".obj"); prop.GetParameter(L"tempLocation").PutValue(tempPath); prop.GetParameter(L"tempLocation").PutCapabilityFlag(siReadOnly, true); } if(prop.GetParameter(L"coatLocation").GetValue() == L"") { TCHAR Path[MAX_PATH]; if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, Path))) { CString exchPath = CUtils::BuildPath(Path, L"3D-CoatV3", L"Exchange"); prop.GetParameter(L"coatLocation").PutValue(exchPath); } } //prop.GetParameter(L"bImpNorm").PutCapabilityFlag(siNotInspectable, true); //prop.GetParameter(L"bImpNewMat").PutCapabilityFlag(siReadOnly, true); ctxt.PutAttribute(L"Refresh",true); } else if ( eventID == PPGEventContext::siButtonClicked ) { CValue buttonPressed = ctxt.GetAttribute( L"Button" ); CString tempLocation = prop.GetParameter(L"tempLocation").GetValue(); CString coatLocation = prop.GetParameter(L"coatLocation").GetValue(); if( buttonPressed.GetAsText() == L"Coat3DExport" ) { CustomProperty in_pset = ctxt.GetSource(); if(CUtils::EnsureFolderExists(tempLocation, true)) { CValueArray args(6); args[0] = tempLocation; args[1] = coatLocation; args[2] = in_pset.GetParameterValue( L"typePaint" ); //args[3] = in_pset.GetParameterValue( L"bCopyTexE" ); args[3] = in_pset.GetParameterValue( L"bExpMat" ); args[4] = in_pset.GetParameterValue( L"bExpUV" ); args[5] = in_pset.GetParameterValue( L"bExpNorm" ); CValue retVal; app.ExecuteCommand( L"Coat3DExport", args, retVal ); CString exeLocation = prop.GetParameter(L"exeLocation").GetValue(); bool bStart = prop.GetParameter(L"bStart").GetValue(); if(exeLocation != L"" && bStart) { if(!Find3DCoat()) { if((int)::ShellExecute(NULL, TEXT("open"), exeLocation.GetAsciiString(), NULL, NULL, SW_SHOWNORMAL) <= 32) { app.LogMessage(L"3D-Coat.exe not found!", siWarningMsg); } } else { app.LogMessage(L"3D-Coat.exe is run!", siWarningMsg); } } } else { app.LogMessage(L"Note temp path exists!", siErrorMsg); } } else if( buttonPressed.GetAsText() == L"Coat3DImport" ) { CustomProperty in_pset = ctxt.GetSource(); CString exportPath = CUtils::BuildPath(coatLocation, L"export.txt"); CString objPath; std::ifstream mfrExportTxt; mfrExportTxt.open (exportPath.GetAsciiString());//c:\Documents and Settings\user\My Documents\3D-CoatV3\Exchange\export.txt //app.LogMessage(L"Export.txt is it! :" + strOut); if(mfrExportTxt.good()) { std::string row; std::getline(mfrExportTxt, row); objPath = row.c_str(); //app.LogMessage(L"first row: " + CString(row.c_str())); } else { UIToolkit uitool = app.GetUIToolkit(); LONG out; uitool.MsgBox(L"import file not found!", siMsgOkOnly|siMsgExclamation, L"", (LONG) out); if(out == siMsgOk) { return CStatus::False; } } mfrExportTxt.close(); app.LogMessage(coatLocation); app.LogMessage(exportPath); if(objPath != L"") { CValueArray args(2); args[0] = objPath; args[1] = in_pset.GetParameterValue( L"bReplace" ); CValue noret; app.ExecuteCommand( L"Coat3DImport", args, noret ); } } } else if ( eventID == PPGEventContext::siParameterChange ) { Parameter changed = ctxt.GetSource(); CustomProperty prop = changed.GetParent(); CString paramName = changed.GetScriptName(); if ( paramName == L"bImpMat" ) { CValue bFlag = prop.GetParameter(L"bImpMat").GetValue(); //prop.GetParameter(L"swMap").PutCapabilityFlag(siNotInspectable, !bFlag); prop.GetParameter(L"swMap").PutCapabilityFlag(siReadOnly, !bFlag); } ctxt.PutAttribute(L"Refresh",true); } return CStatus::OK ; }
/** Event handler for when the options dialog is interacted with */ CStatus OgreMeshExportOptions_PPGEvent( const CRef& io_Ctx ) { // This callback is called when events happen in the user interface // This is where you implement the "logic" code. Application app ; static bool hasSkel = false; PPGEventContext ctx( io_Ctx ) ; PPGEventContext::PPGEvent eventID = ctx.GetEventID() ; CustomProperty prop = ctx.GetSource() ; Parameter objectNameParam = prop.GetParameters().GetItem( L"objectName" ) ; // On open dialog if ( eventID == PPGEventContext::siOnInit ) { CString theObjectName; // Pre-populate object with currently selected item(s) Selection sel(app.GetSelection()); if (sel.GetCount() > 0) { CString val; for (int i = 0; i < sel.GetCount(); ++i) { CString thisName = SIObject(sel[i]).GetName(); val += thisName; theObjectName += thisName; if (i < sel.GetCount() - 1) { val += L", "; theObjectName += L"_"; } } prop.PutParameterValue(L"objectName", val); } else { // no selection, assume entire scene prop.PutParameterValue(L"objectName", CString(L"[Entire Scene]")); } // Make the selection read-only objectNameParam.PutCapabilityFlag( siReadOnly, true ); // Default mesh name if (prop.GetParameterValue(L"targetMeshFileName") == L"") { // default name prop.PutParameterValue(L"targetMeshFileName", theObjectName + L".mesh"); } // Default material name if (prop.GetParameterValue(L"targetMaterialFileName") == L"") { // default name prop.PutParameterValue(L"targetMaterialFileName", theObjectName + L".material"); } // default the frame rate to that selected in animation panel prop.PutParameterValue(L"fps", CTime().GetFrameRate()); // enable / disable the skeleton export based on envelopes if (!hasSkeleton(sel, true)) { prop.PutParameterValue(L"exportSkeleton", false); Parameter param = prop.GetParameters().GetItem(L"exportSkeleton"); param.PutCapabilityFlag(siReadOnly, true); param = prop.GetParameters().GetItem(L"targetSkeletonFileName"); param.PutCapabilityFlag(siReadOnly, true); hasSkel = false; } else { prop.PutParameterValue(L"exportSkeleton", true); Parameter param = prop.GetParameters().GetItem(L"exportSkeleton"); param.PutCapabilityFlag(siReadOnly, false); param = prop.GetParameters().GetItem(L"targetSkeletonFileName"); param.PutCapabilityFlag(siReadOnly, false); if (prop.GetParameterValue(L"targetSkeletonFileName") == L"") { // default name prop.PutParameterValue(L"targetSkeletonFileName", theObjectName + L".skeleton"); } hasSkel = true; } // value of param is a griddata object // initialise it with all detected animations if it's empty Parameter param = prop.GetParameters().GetItem(L"animationList"); GridData gd(param.GetValue()); if (gd.GetRowCount() == 0 || gd.GetCell(0,0) == L"No data has been set") { populateAnimationsList(gd); } } // On clicking a button else if ( eventID == PPGEventContext::siButtonClicked ) { CValue buttonPressed = ctx.GetAttribute( L"Button" ); // Clicked the refresh animation button if ( buttonPressed.GetAsText() == L"refreshAnimation" ) { LONG btn; CStatus ret = app.GetUIToolkit().MsgBox( L"Are you sure you want to lose the current contents " L"of the animations list and to refresh it from mixers?", siMsgYesNo, L"Confirm", btn); if (btn == 6) { Parameter param = prop.GetParameters().GetItem(L"animationList"); GridData gd(param.GetValue()); populateAnimationsList(gd); } } else if( buttonPressed.GetAsText() == L"addAnimation" ) { Parameter param = prop.GetParameters().GetItem(L"animationList"); GridData gd(param.GetValue()); gd.PutRowCount(gd.GetRowCount() + 1); // default export to true and sample rate gd.PutCell(ANIMATION_LIST_EXPORT_COL, gd.GetRowCount()-1, true); gd.PutCell(ANIMATION_LIST_IKFREQ_COL, gd.GetRowCount()-1, (LONG)5); } else if( buttonPressed.GetAsText() == L"removeAnimation" ) { Parameter param = prop.GetParameters().GetItem(L"animationList"); GridData gd(param.GetValue()); GridWidget gw = gd.GetGridWidget(); // cell-level selection, so have to search for selection in every cell long selRow = -1; for (long row = 0; row < gd.GetRowCount() && selRow == -1; ++row) { for (long col = 0; col < gd.GetColumnCount() && selRow == -1; ++col) { if (gw.IsCellSelected(col, row)) { selRow = row; } } } if (selRow != -1) { LONG btn; CStatus ret = app.GetUIToolkit().MsgBox( L"Are you sure you want to remove this animation entry?", siMsgYesNo, L"Confirm", btn); if (btn == 6) { // Move all the contents up one for (long row = selRow; row < gd.GetRowCount(); ++row) { for (long col = 0; col < gd.GetColumnCount(); ++col) { gd.PutCell(col, row, gd.GetCell(col, row+1)); } } // remove last row gd.PutRowCount(gd.GetRowCount() - 1); } } } } // Changed a parameter else if ( eventID == PPGEventContext::siParameterChange ) { Parameter changed = ctx.GetSource() ; CustomProperty prop = changed.GetParent() ; CString paramName = changed.GetScriptName() ; // Check paramName against parameter names, perform custom onChanged event if (paramName == L"targetMeshFileName") { // Default skeleton & material name Ogre::String meshName = XSItoOgre(XSI::CString(changed.GetValue())); if (hasSkel) { Ogre::String skelName = meshName; if (Ogre::StringUtil::endsWith(skelName, ".mesh")) { skelName = skelName.substr(0, skelName.size() - 5) + ".skeleton"; } CString xsiSkelName = OgretoXSI(skelName); prop.PutParameterValue(L"targetSkeletonFileName", xsiSkelName); } // default material script name Ogre::String matName = meshName; if (Ogre::StringUtil::endsWith(matName, ".mesh")) { matName = matName.substr(0, matName.size() - 5) + ".material"; } CString xsiMatName = OgretoXSI(matName); prop.PutParameterValue(L"targetMaterialFileName", xsiMatName); } } return CStatus::OK; }
/** Defines the persistable parameters on the options dialog */ CStatus OgreMeshExportOptions_Define( const CRef & in_Ctx ) { // Here is where we add all the parameters to the // Custom Property. This will be called each time // an new instance of the Custom Property is called. // It is not called when an persisted Custom Property is loaded. Application app ; CustomProperty prop = Context(in_Ctx).GetSource(); Parameter param ; // Default capabilities for most of these parameters int caps = siPersistable ; CValue nullValue; // Used for arguments we don't want to set prop.AddParameter( L"version",CValue::siString, caps, L"Version", L"", nullValue, param) ; prop.AddParameter( L"objectName",CValue::siString, caps, L"Object Name", L"", nullValue, param) ; prop.AddParameter( L"objects",CValue::siRefArray, caps, L"Collection of selected objects", L"", nullValue, param) ; prop.AddParameter( L"targetMeshFileName",CValue::siString, caps, L"Mesh Filename", L"", nullValue, param) ; prop.AddParameter( L"mergeSubmeshes",CValue::siBool, caps, L"Merge objects with same material?", L"If false, a separate named SubMesh will be created for every PolygonMesh " L"preserving your model divisions. If true, the exporter will merge all " L"PolygonMesh objects with the same material, which is more efficient, but " L"does not preserve your modelling divisions.", CValue(true), param) ; prop.AddParameter( L"exportChildren",CValue::siBool, caps, L"Export Children", L"If true, children of all selected objects will be exported.", CValue(true), param) ; prop.AddParameter( L"calculateEdgeLists",CValue::siBool, caps, L"Calculate Edge Lists (stencil shadows)", L"", CValue(true), param) ; prop.AddParameter( L"calculateTangents",CValue::siBool, caps, L"Calculate Tangents (normal mapping)", L"", CValue(false), param) ; prop.AddParameter( L"tangentSemantic",CValue::siString, caps, L"Tangent Semantic", L"", L"t", param) ; prop.AddParameter( L"tangentsSplitMirrored",CValue::siBool, caps, L"Split tangents at UV mirror", L"", CValue(false), param) ; prop.AddParameter( L"tangentsSplitRotated",CValue::siBool, caps, L"Split tangents at UV rotation", L"", CValue(false), param) ; prop.AddParameter( L"tangentsUseParity",CValue::siBool, caps, L"4D Tangents", L"", CValue(false), param) ; prop.AddParameter( L"numLodLevels",CValue::siInt2, caps, L"Levels of Detail", L"", (LONG)0, param) ; prop.AddParameter( L"lodDistanceIncrement",CValue::siFloat, caps, L"Distance Increment", L"", (LONG)2000, //default (LONG)1, // hard min (LONG)1000000, // hard max (LONG)50, // suggested min (LONG)10000, // suggested max param) ; prop.AddParameter( L"lodQuota",CValue::siString, caps, L"Reduction Style", L"", L"p", param) ; prop.AddParameter( L"lodReduction",CValue::siFloat, caps, L"Reduction Value", L"", CValue(50.0f), param) ; prop.AddParameter( L"exportSkeleton",CValue::siBool, caps, L"Export Skeleton", L"", CValue(true), param) ; prop.AddParameter( L"exportVertexAnimation",CValue::siBool, caps, L"Export Vertex Animation", L"", CValue(true), param) ; prop.AddParameter( L"targetSkeletonFileName",CValue::siString, caps, L"Skeleton Filename", L"", nullValue, param) ; prop.AddParameter( L"fps",CValue::siInt2, caps, L"Frames per second", L"", (LONG)24, param) ; prop.AddGridParameter(L"animationList"); prop.AddParameter( L"exportMaterials", CValue::siBool, caps, L"Export Materials", L"", CValue(true), param); prop.AddParameter( L"copyTextures", CValue::siBool, caps, L"Copy Textures To Folder", L"", CValue(true), param); prop.AddParameter( L"targetMaterialFileName",CValue::siString, caps, L"Material Filename", L"", nullValue, param) ; prop.AddParameter( L"materialPrefix",CValue::siString, caps, L"Material Prefix", L"", nullValue, param) ; return CStatus::OK; }