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 ); } } }
XMLElement* Mesh::GenerateMeshSegment(XMLDocument* doc, X3DObject& mesh, bool shouldExport, CString exportPath) { XMLElement* root = nullptr; if (MeshIsMassPrimitive(mesh)) { Primitives* primitive = new Primitives(); root = primitive->WritePrimitive(doc, mesh); delete primitive; } else { root = doc->NewElement("shape"); root->SetAttribute(Constants::attrType, "ply"); root->InsertEndChild(WriteElement(doc, Constants::attrString, Constants::attrFilename, (mesh.GetFullName() + L".ply").GetAsciiString())); XMLElement* trElement = doc->NewElement("transform"); trElement->SetAttribute(Constants::attrName, "toWorld"); root->InsertEndChild(trElement); MATH::CTransformation transform = mesh.GetKinematics().GetGlobal().GetTransform(); trElement->InsertEndChild(WriteElementScale(doc, mesh)); trElement->InsertEndChild(WriteSubElementRotation(doc, "x", transform.GetRotX())); trElement->InsertEndChild(WriteSubElementRotation(doc, "y", transform.GetRotY())); trElement->InsertEndChild(WriteSubElementRotation(doc, "z", transform.GetRotZ())); trElement->InsertEndChild(WriteElementTranslate(doc, mesh)); Mitsuba::Material* material = new Mitsuba::Material(); material->WriteMeshMaterial(doc, root, mesh); delete material; if (shouldExport) { bool isSolid = false; bool isSubdivide = false; LONG subLevel = 0; Property prop; mesh.GetPropertyFromName(L"MaSsObjectProperty", prop); if (prop.IsValid()) { isSolid = prop.GetParameterValue(L"isSolid"); isSubdivide = prop.GetParameterValue(L"isSubdivide"); subLevel = prop.GetParameterValue(L"subLevel"); } if (!isSubdivide) { Mitsuba::ExportPLY* exportPly = new Mitsuba::ExportPLY(); exportPly->ExportPlyMeshBinary(mesh, exportPath, mesh.GetFullName() + L".ply", isSolid); delete exportPly; } else { /*#we should subdivide this mesh and then export #lm("We should subdivide the mesh") subOps = ap.ApplyOp("MeshSubdivideWithCenter", mesh) subMesh = ap.Selection(0) subOp = subOps(0) ap.SetValue(subOp.SubdivisionDepth, subLevel) ap.FreezeObj(subMesh, "", "") tM = mesh.Kinematics.Global.Transform.Matrix4 oTrans = subMesh.Kinematics.Global.Transform tM.InvertInPlace() oTrans.SetMatrix4(tM) subMesh.Kinematics.Global.Transform = oTrans ap.ResetTransform(subMesh, "siCtr", "siSRT", "siXYZ") ExportPlyMesh02(subMesh, exportPath, mesh.FullName + ".ply") ap.DeleteObj(subMesh)*/ } } } return root; }
/** 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; }