diff options
author | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2016-03-21 11:00:22 -0400 |
---|---|---|
committer | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2016-03-21 11:00:22 -0400 |
commit | 2afde26d93cc8773f5e84d187844f909347fc1bf (patch) | |
tree | 5857549829b90f047ae094ebd9b6a9d2817d59aa /indra/llprimitive | |
parent | 132a2587dff85006636d8092ae1b34081f12fe69 (diff) | |
parent | 4aae7b51616c0963af4668442bdb5bfaba8c5044 (diff) |
merge
Diffstat (limited to 'indra/llprimitive')
-rw-r--r-- | indra/llprimitive/lldaeloader.cpp | 115 | ||||
-rw-r--r-- | indra/llprimitive/lldaeloader.h | 15 |
2 files changed, 73 insertions, 57 deletions
diff --git a/indra/llprimitive/lldaeloader.cpp b/indra/llprimitive/lldaeloader.cpp index 07bb3fb1d4..50875669fa 100644 --- a/indra/llprimitive/lldaeloader.cpp +++ b/indra/llprimitive/lldaeloader.cpp @@ -62,6 +62,9 @@ #include "glh/glh_linear.h" #include "llmatrix4a.h" +#include <boost/regex.hpp> +#include <boost/algorithm/string/replace.hpp> + std::string colladaVersion[VERSIONTYPE_COUNT+1] = { "1.4.0", @@ -236,7 +239,10 @@ LLModel::EModelStatus load_face_from_dom_triangles(std::vector<LLVolumeFace>& fa // Don't share verts within the same tri, degenerate // - if ((indices.size() % 3) && (indices[indices.size()-1] != shared_index)) + U32 indx_size = indices.size(); + U32 verts_new_tri = indx_size % 3; + if ((verts_new_tri < 1 || indices[indx_size - 1] != shared_index) + && (verts_new_tri < 2 || indices[indx_size - 2] != shared_index)) { found = true; indices.push_back(shared_index); @@ -812,7 +818,8 @@ LLDAELoader::LLDAELoader( JointNameSet& jointsFromNodes, std::map<std::string, std::string>& jointAliasMap, U32 maxJointsPerMesh, - U32 modelLimit) + U32 modelLimit, + bool preprocess) : LLModelLoader( filename, lod, @@ -826,7 +833,7 @@ LLDAELoader::LLDAELoader( jointAliasMap, maxJointsPerMesh), mGeneratedModelLimit(modelLimit), - mForceIdNaming(false) + mPreprocessDAE(preprocess) { } @@ -850,7 +857,16 @@ bool LLDAELoader::OpenFile(const std::string& filename) { //no suitable slm exists, load from the .dae file DAE dae; - domCOLLADA* dom = dae.open(filename); + domCOLLADA* dom; + if (mPreprocessDAE) + { + dom = dae.openFromMemory(filename, preprocessDAE(filename).c_str()); + } + else + { + LL_INFOS() << "Skipping dae preprocessing" << LL_ENDL; + dom = dae.open(filename); + } if (!dom) { @@ -878,7 +894,7 @@ bool LLDAELoader::OpenFile(const std::string& filename) daeInt count = db->getElementCount(NULL, COLLADA_TYPE_MESH); - daeDocument* doc = dae.getDoc(mFilename); + daeDocument* doc = dae.getDoc(filename); if (!doc) { LL_WARNS() << "can't find internal doc" << LL_ENDL; @@ -949,32 +965,6 @@ bool LLDAELoader::OpenFile(const std::string& filename) mTransform.condition(); - mForceIdNaming = false; - std::vector<std::string> checkNames; - for (daeInt idx = 0; idx < count; ++idx) - { - domMesh* mesh = NULL; - db->getElement((daeElement**)&mesh, idx, NULL, COLLADA_TYPE_MESH); - - if (mesh) - { - std::string name = getLodlessLabel(mesh, false); - - std::vector<std::string>::iterator it; - it = std::find(checkNames.begin(), checkNames.end(), name); - if (it != checkNames.end()) - { - LL_WARNS() << "document has duplicate names, using IDs instead" << LL_ENDL; - mForceIdNaming = true; - break; - } - else - { - checkNames.push_back(name); - } - } - } - U32 submodel_limit = count > 0 ? mGeneratedModelLimit/count : 0; for (daeInt idx = 0; idx < count; ++idx) { //build map of domEntities to LLModel @@ -1082,6 +1072,41 @@ bool LLDAELoader::OpenFile(const std::string& filename) return true; } +std::string LLDAELoader::preprocessDAE(std::string filename) +{ + // Open a DAE file for some preprocessing (like removing space characters in IDs), see MAINT-5678 + std::ifstream inFile; + inFile.open(filename.c_str(), std::ios_base::in); + std::stringstream strStream; + strStream << inFile.rdbuf(); + std::string buffer = strStream.str(); + + LL_INFOS() << "Preprocessing dae file to remove spaces from the names, ids, etc." << LL_ENDL; + + try + { + boost::regex re("\"[\\w\\.@#$-]*(\\s[\\w\\.@#$-]*)+\""); + boost::sregex_iterator next(buffer.begin(), buffer.end(), re); + boost::sregex_iterator end; + while (next != end) + { + boost::smatch match = *next; + std::string s = match.str(); + LL_INFOS() << s << " found" << LL_ENDL; + boost::replace_all(s, " ", "_"); + LL_INFOS() << "Replacing with " << s << LL_ENDL; + boost::replace_all(buffer, match.str(), s); + next++; + } + } + catch (boost::regex_error &) + { + LL_INFOS() << "Regex error" << LL_ENDL; + } + + return buffer; +} + void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, domMesh* mesh, domSkin* skin) { llassert(model && dae && mesh && skin); @@ -1978,7 +2003,7 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da if (model->mLabel.empty()) { - label = getLodlessLabel(instance_geo, mForceIdNaming); + label = getLodlessLabel(instance_geo); llassert(!label.empty()); @@ -2193,17 +2218,12 @@ LLImportMaterial LLDAELoader::profileToMaterial(domProfile_COMMON* material, DAE return mat; } -std::string LLDAELoader::getElementLabel(daeElement *element) -{ - return getElementLabel(element, mForceIdNaming); -} - // try to get a decent label for this element -std::string LLDAELoader::getElementLabel(daeElement *element, bool forceIdNaming) +std::string LLDAELoader::getElementLabel(daeElement *element) { // if we have a name attribute, use it std::string name = element->getAttribute("name"); - if (name.length() && !forceIdNaming) + if (name.length()) { return name; } @@ -2226,7 +2246,7 @@ std::string LLDAELoader::getElementLabel(daeElement *element, bool forceIdNaming // if parent has a name or ID, use it std::string name = parent->getAttribute("name"); - if (!name.length() || forceIdNaming) + if (!name.length()) { name = std::string(parent->getID()); } @@ -2269,9 +2289,9 @@ size_t LLDAELoader::getSuffixPosition(std::string label) } // static -std::string LLDAELoader::getLodlessLabel(daeElement *element, bool forceIdNaming) +std::string LLDAELoader::getLodlessLabel(daeElement *element) { - std::string label = getElementLabel(element, forceIdNaming); + std::string label = getElementLabel(element); size_t ext_pos = getSuffixPosition(label); if (ext_pos != -1) { @@ -2342,13 +2362,8 @@ bool LLDAELoader::addVolumeFacesFromDomMesh(LLModel* pModel,domMesh* mesh) return (status == LLModel::NO_ERRORS); } -LLModel* LLDAELoader::loadModelFromDomMesh(domMesh *mesh) -{ - return loadModelFromDomMesh(mesh, mForceIdNaming); -} - //static -LLModel* LLDAELoader::loadModelFromDomMesh(domMesh *mesh, bool forceIdNaming) +LLModel* LLDAELoader::loadModelFromDomMesh(domMesh *mesh) { LLVolumeParams volume_params; volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE); @@ -2356,7 +2371,7 @@ LLModel* LLDAELoader::loadModelFromDomMesh(domMesh *mesh, bool forceIdNaming) createVolumeFacesFromDomMesh(ret, mesh); if (ret->mLabel.empty()) { - ret->mLabel = getElementLabel(mesh, forceIdNaming); + ret->mLabel = getElementLabel(mesh); } return ret; } @@ -2374,7 +2389,7 @@ bool LLDAELoader::loadModelsFromDomMesh(domMesh* mesh, std::vector<LLModel*>& mo LLModel* ret = new LLModel(volume_params, 0.f); - std::string model_name = getLodlessLabel(mesh, mForceIdNaming); + std::string model_name = getLodlessLabel(mesh); ret->mLabel = model_name + lod_suffix[mLod]; llassert(!ret->mLabel.empty()); diff --git a/indra/llprimitive/lldaeloader.h b/indra/llprimitive/lldaeloader.h index 852dc1b3ac..4e990dbe5e 100644 --- a/indra/llprimitive/lldaeloader.h +++ b/indra/llprimitive/lldaeloader.h @@ -58,7 +58,8 @@ public: JointNameSet& jointsFromNodes, std::map<std::string, std::string>& jointAliasMap, U32 maxJointsPerMesh, - U32 modelLimit); + U32 modelLimit, + bool preprocess); virtual ~LLDAELoader() ; virtual bool OpenFile(const std::string& filename); @@ -91,22 +92,22 @@ protected: static bool addVolumeFacesFromDomMesh(LLModel* model, domMesh* mesh); static bool createVolumeFacesFromDomMesh(LLModel* model, domMesh *mesh); - static LLModel* loadModelFromDomMesh(domMesh* mesh, bool forceIdNaming); - LLModel* loadModelFromDomMesh(domMesh* mesh); + static LLModel* loadModelFromDomMesh(domMesh* mesh); // Loads a mesh breaking it into one or more models as necessary // to get around volume face limitations while retaining >8 materials // bool loadModelsFromDomMesh(domMesh* mesh, std::vector<LLModel*>& models_out, U32 submodel_limit); - static std::string getElementLabel(daeElement *element, bool forceIdNaming); - std::string getElementLabel(daeElement *element); + static std::string getElementLabel(daeElement *element); static size_t getSuffixPosition(std::string label); - static std::string getLodlessLabel(daeElement *element, bool forceIdNaming = false); + static std::string getLodlessLabel(daeElement *element); + + static std::string preprocessDAE(std::string filename); private: U32 mGeneratedModelLimit; // Attempt to limit amount of generated submodels - bool mForceIdNaming; + bool mPreprocessDAE; }; #endif // LL_LLDAELLOADER_H |