void VMFImport() { Application app; CStatus st; Property prop; prop = app.GetActiveSceneRoot().GetProperties().GetItem( L"VMFImportProperty" ); if (!prop.IsValid()) prop = app.GetActiveSceneRoot().AddProperty( L"VMFImportProperty" ) ; CValueArray args(5); args[0] = prop; args[1] = L""; args[2] = L"VMFImportProperty"; args[3] = (long)4; args[4] = true; CValue ret; st = app.ExecuteCommand(L"InspectObj",args,ret); if ( CStatus::OK == st ) { // // FileName // char l_szFilename[MAX_PATH]; memset ( l_szFilename,0,MAX_PATH ); Parameter parm = prop.GetParameters().GetItem(L"Filename" ); CString str = parm.GetValue(); const wchar_t * p = str.GetWideString(); wcstombs( l_szFilename, p, wcslen (p)); parm = prop.GetParameters().GetItem(L"TexturePath" ); str = parm.GetValue(); p = str.GetWideString(); wcstombs( ___gTexturePathOverride, p, wcslen (p)); // // Bools // parm = prop.GetParameters().GetItem(L"UseMaterials"); g_iImportMaterials = (bool) parm.GetValue(); if (l_szFilename && strlen( l_szFilename ) > 0) { CMapParser p; p.Read ( l_szFilename ); p.ConvertToSemanticLayer(); } else { XSILogMessage ( L"Error - Invalid file specified", XSI::siErrorMsg ); } } }
void populateAnimationsList(XSI::GridData gd) { // 5 columns gd.PutColumnCount(5); // Export column is a check box gd.PutColumnType(ANIMATION_LIST_EXPORT_COL, siColumnBool); // Labels gd.PutColumnLabel(ANIMATION_LIST_EXPORT_COL, L""); gd.PutColumnLabel(ANIMATION_LIST_NAME_COL, L"Name"); gd.PutColumnLabel(ANIMATION_LIST_START_COL, L"Start"); gd.PutColumnLabel(ANIMATION_LIST_END_COL, L"End"); gd.PutColumnLabel(ANIMATION_LIST_IKFREQ_COL, L"Sample Freq"); Application app; Model appRoot(app.GetActiveSceneRoot()); getAnimations(appRoot, animList); gd.PutRowCount(animList.size()); long row = 0; for (Ogre::AnimationList::iterator a = animList.begin(); a != animList.end(); ++a, ++row) { gd.PutCell(ANIMATION_LIST_NAME_COL, row, OgretoXSI(a->animationName)); // default to export gd.PutCell(ANIMATION_LIST_EXPORT_COL, row, true); gd.PutCell(ANIMATION_LIST_START_COL, row, CValue((LONG)a->startFrame)); gd.PutCell(ANIMATION_LIST_END_COL, row, CValue((LONG)a->endFrame)); gd.PutCell(ANIMATION_LIST_IKFREQ_COL, row, a->ikSampleInterval); } }
CString GetUserSelectedObject() { Application app; Model root(app.GetActiveSceneRoot()); CStringArray emptyArray; CRefArray cRefArray = root.FindChildren( L"", L"", emptyArray, true ); CStringArray nameArray(cRefArray.GetCount()); for ( long i=0; i < cRefArray.GetCount(); i++ ) { nameArray[i] = SIObject(cRefArray[i]).GetName(); } //todo qsort the nameArray // Using the COMAPIHandler for creating a "XSIDial.XSIDialog" CComAPIHandler xsidialog; xsidialog.CreateInstance( L"XSIDial.XSIDialog"); CValue index; CValueArray args(cRefArray.GetCount()); for (long y=0; y < cRefArray.GetCount(); y++) args[y]=nameArray[y]; xsidialog.Call(L"Combo",index,L"Select Item",args ); long ind = (LONG)index; return args[ind]; }
//***************************************************************************** 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; }
/** Callback event when clicking the export menu option. Adds an instance of the options dialog as a property, then uses the InspectObj XSI command to pop it up in a modal dialog. If it wasn't cancelled, performs an export. */ XSI::CStatus OnOgreMeshExportMenu( XSI::CRef& in_ref ) { Ogre::LogManager logMgr; logMgr.createLog("OgreXSIExporter.log", true); CString msg(L"OGRE Exporter Version "); msg += OGRE_XSI_EXPORTER_VERSION; LogOgreAndXSI(msg); Application app; CStatus st(CStatus::OK); Property prop = app.GetActiveSceneRoot().GetProperties().GetItem(exportPropertyDialogName); if (prop.IsValid()) { // Check version number CString currVersion(prop.GetParameterValue(L"version")); if (!currVersion.IsEqualNoCase(OGRE_XSI_EXPORTER_VERSION)) { DeleteObj(exportPropertyDialogName); prop.ResetObject(); } } if (!prop.IsValid()) { prop = app.GetActiveSceneRoot().AddProperty(exportPropertyDialogName); prop.PutParameterValue(L"version", CString(OGRE_XSI_EXPORTER_VERSION)); } try { // Popup Returns true if the command was cancelled otherwise it returns false. CStatus ret = Popup(exportPropertyDialogName,CValue(),L"OGRE Mesh / Skeleton Export",((LONG)siModal),true); if (ret == CStatus::OK) { Ogre::XsiMeshExporter meshExporter; Ogre::XsiSkeletonExporter skelExporter; // retrieve the parameters Parameter param = prop.GetParameters().GetItem(L"objectName"); CString objectName = param.GetValue(); param = prop.GetParameters().GetItem( L"targetMeshFileName" ); Ogre::String meshFileName = XSItoOgre(XSI::CString(param.GetValue())); if (meshFileName.empty()) { OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "You must supply a mesh file name", "OGRE Exporter"); } // fix any omission of '.mesh' if (!Ogre::StringUtil::endsWith(meshFileName, ".mesh")) { meshFileName += ".mesh"; } param = prop.GetParameters().GetItem( L"mergeSubmeshes" ); bool mergeSubmeshes = param.GetValue(); param = prop.GetParameters().GetItem( L"exportChildren" ); bool exportChildren = param.GetValue(); param = prop.GetParameters().GetItem( L"calculateEdgeLists" ); bool edgeLists = param.GetValue(); param = prop.GetParameters().GetItem( L"calculateTangents" ); bool tangents = param.GetValue(); param = prop.GetParameters().GetItem( L"tangentSemantic" ); CString tangentSemStr = param.GetValue(); Ogre::VertexElementSemantic tangentSemantic = (tangentSemStr == L"t")? Ogre::VES_TANGENT : Ogre::VES_TEXTURE_COORDINATES; param = prop.GetParameters().GetItem( L"tangentsSplitMirrored" ); bool tangentsSplitMirrored = param.GetValue(); param = prop.GetParameters().GetItem( L"tangentsSplitRotated" ); bool tangentsSplitRotated = param.GetValue(); param = prop.GetParameters().GetItem( L"tangentsUseParity" ); bool tangentsUseParity = param.GetValue(); param = prop.GetParameters().GetItem( L"numLodLevels" ); long numlods = (LONG)param.GetValue(); Ogre::XsiMeshExporter::LodData* lodData = 0; if (numlods > 0) { param = prop.GetParameters().GetItem( L"lodDistanceIncrement" ); float distanceInc = param.GetValue(); param = prop.GetParameters().GetItem(L"lodQuota"); CString quota = param.GetValue(); param = prop.GetParameters().GetItem(L"lodReduction"); float reduction = param.GetValue(); lodData = new Ogre::XsiMeshExporter::LodData; float currentInc = distanceInc; for (int l = 0; l < numlods; ++l) { lodData->distances.push_back(currentInc); currentInc += distanceInc; } lodData->quota = (quota == L"p") ? Ogre::ProgressiveMesh::VRQ_PROPORTIONAL : Ogre::ProgressiveMesh::VRQ_CONSTANT; if (lodData->quota == Ogre::ProgressiveMesh::VRQ_PROPORTIONAL) lodData->reductionValue = reduction * 0.01; else lodData->reductionValue = reduction; } param = prop.GetParameters().GetItem( L"exportSkeleton" ); bool exportSkeleton = param.GetValue(); param = prop.GetParameters().GetItem( L"exportVertexAnimation" ); bool exportVertexAnimation = param.GetValue(); param = prop.GetParameters().GetItem( L"exportMaterials" ); bool exportMaterials = param.GetValue(); param = prop.GetParameters().GetItem( L"copyTextures" ); bool copyTextures = param.GetValue(); // create singletons Ogre::ResourceGroupManager rgm; Ogre::MeshManager meshMgr; Ogre::SkeletonManager skelMgr; Ogre::MaterialManager matMgr; Ogre::DefaultHardwareBufferManager hardwareBufMgr; // determine number of exportsteps size_t numSteps = 3 + OGRE_XSI_NUM_MESH_STEPS; if (numlods > 0) numSteps++; if (edgeLists) numSteps++; if (tangents) numSteps++; if (exportSkeleton) numSteps += 3; Ogre::ProgressManager progressMgr(numSteps); // Any material prefix? We need that for mesh linking too param = prop.GetParameters().GetItem( L"materialPrefix" ); Ogre::String materialPrefix = XSItoOgre(XSI::CString(param.GetValue())); param = prop.GetParameters().GetItem( L"fps" ); float fps = param.GetValue(); if (fps == 0.0f) { OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "You must supply a valid value for 'FPS'", "OGRE Export"); } Ogre::AnimationList selAnimList; if (exportSkeleton || exportVertexAnimation) { param = prop.GetParameters().GetItem( L"animationList" ); GridData gd(param.GetValue()); for (int a = 0; a < gd.GetRowCount(); ++a) { if (gd.GetCell(ANIMATION_LIST_EXPORT_COL, a) == true) { Ogre::AnimationEntry ae; ae.animationName = XSItoOgre(XSI::CString(gd.GetCell(ANIMATION_LIST_NAME_COL, a))); ae.ikSampleInterval = gd.GetCell(ANIMATION_LIST_IKFREQ_COL, a); ae.startFrame = (LONG)gd.GetCell(ANIMATION_LIST_START_COL, a); ae.endFrame = (LONG)gd.GetCell(ANIMATION_LIST_END_COL, a); selAnimList.push_back(ae); } } } if (exportSkeleton) { param = prop.GetParameters().GetItem( L"targetSkeletonFileName" ); Ogre::String skeletonFileName = XSItoOgre(XSI::CString(param.GetValue())); if (skeletonFileName.empty()) { OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "You must supply a skeleton file name", "OGRE Exporter"); } // fix any omission of '.skeleton' if (!Ogre::StringUtil::endsWith(skeletonFileName, ".skeleton")) { skeletonFileName += ".skeleton"; } // Truncate the skeleton filename to just the name (no path) Ogre::String skelName = skeletonFileName; int pos = skeletonFileName.find_last_of("\\"); if (pos == Ogre::String::npos) { pos = skeletonFileName.find_last_of("/"); } if (pos != Ogre::String::npos) { skelName = skelName.substr(pos+1, skelName.size() - pos - 1); } // Do the mesh Ogre::DeformerMap& deformers = meshExporter.buildMeshForExport(mergeSubmeshes, exportChildren, edgeLists, tangents, tangentSemantic, tangentsSplitMirrored, tangentsSplitRotated, tangentsUseParity, exportVertexAnimation, selAnimList, fps, materialPrefix, lodData, skelName); // do the skeleton const Ogre::AxisAlignedBox& skelAABB = skelExporter.exportSkeleton(skeletonFileName, deformers, fps, selAnimList); // Do final mesh export meshExporter.exportMesh(meshFileName, skelAABB); } else { Ogre::AxisAlignedBox nullbb; // No skeleton meshExporter.buildMeshForExport(mergeSubmeshes, exportChildren, edgeLists, tangents, tangentSemantic, tangentsSplitMirrored, tangentsSplitRotated, tangentsUseParity, exportVertexAnimation, selAnimList, fps, materialPrefix, lodData); meshExporter.exportMesh(meshFileName, nullbb); } delete lodData; // Do we want to export materials too? if (exportMaterials) { param = prop.GetParameters().GetItem( L"targetMaterialFileName" ); Ogre::String materialFileName = XSItoOgre(XSI::CString(param.GetValue())); // fix any omission of '.material' if (!Ogre::StringUtil::endsWith(materialFileName, ".material")) { materialFileName += ".material"; } Ogre::XsiMaterialExporter matExporter; try { matExporter.exportMaterials(meshExporter.getMaterials(), meshExporter.getTextureProjectionMap(), materialFileName, copyTextures); } catch (Ogre::Exception& e) { // ignore, non-fatal and will be in log } } } } catch (Ogre::Exception& e) { // Will already have been logged to the Ogre log manager // Tell XSI app.LogMessage(OgretoXSI(e.getDescription()), XSI::siFatalMsg); app.LogMessage(OgretoXSI(e.getFullDescription()), XSI::siInfoMsg); } //DeleteObj( L"OgreMeshExportOptions" ); return st; }