Refactor LLDAELoader

- Many instances of null-checking if statements include both variable declaration and initialization (for scoping)
- Modern(ish) C++ conventions (e.g. range-based for loops, auto keyword)
- Local variable caching for array/iterator elements
- const keyword for variables that should not be mutated (optimization possible)
- const keyword for instance methods that should not mutate (affects LLModelLoader in one case)
- Consistent usage of un/signed types for array indexing
- Better readability/simplicity of branching
- Consolidated extractTranslation/ViaElement logic (reusability)
- Formatting
- Changes based on code review
This commit is contained in:
Tarocco
2020-10-09 15:31:01 -07:00
committed by Liru Færs
parent c1aa88c720
commit d49c38bf18
3 changed files with 743 additions and 862 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -5,21 +5,21 @@
* $LicenseInfo:firstyear=2013&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2013, Linden Research, Inc.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -42,13 +42,13 @@ class domMesh;
class LLDAELoader : public LLModelLoader
{
public:
typedef std::map<std::string, LLImportMaterial> material_map;
typedef std::map<std::string, LLImportMaterial> material_map;
typedef std::map<daeElement*, std::vector<LLPointer<LLModel> > > dae_model_map;
dae_model_map mModelsMap;
dae_model_map mModelsMap;
LLDAELoader(
std::string filename,
S32 lod,
std::string filename,
S32 lod,
LLModelLoader::load_callback_t load_cb,
LLModelLoader::joint_lookup_func_t joint_lookup_func,
LLModelLoader::texture_load_func_t texture_load_func,
@@ -56,11 +56,11 @@ public:
void* opaque_userdata,
JointTransformMap& jointTransformMap,
JointNameSet& jointsFromNodes,
std::map<std::string, std::string>& jointAliasMap,
std::map<std::string, std::string>& jointAliasMap,
U32 maxJointsPerMesh,
U32 modelLimit,
bool preprocess);
virtual ~LLDAELoader() ;
virtual ~LLDAELoader();
virtual bool OpenFile(const std::string& filename);
@@ -69,28 +69,27 @@ protected:
void processElement(daeElement* element, bool& badElement, DAE* dae, daeElement* domRoot);
void processDomModel(LLModel* model, DAE* dae, daeElement* pRoot, domMesh* mesh, domSkin* skin);
material_map getMaterials(LLModel* model, domInstance_geometry* instance_geo, DAE* dae);
LLImportMaterial profileToMaterial(domProfile_COMMON* material, DAE* dae);
LLColor4 getDaeColor(daeElement* element);
daeElement* getChildFromElement( daeElement* pElement, std::string const & name );
bool isNodeAJoint( domNode* pNode );
void processJointNode( domNode* pNode, std::map<std::string,LLMatrix4>& jointTransforms );
void extractTranslation( domTranslate* pTranslate, LLMatrix4& transform );
void extractTranslationViaElement( daeElement* pTranslateElement, LLMatrix4& transform );
void extractTranslationViaSID( daeElement* pElement, LLMatrix4& transform );
void buildJointToNodeMappingFromScene( daeElement* pRoot );
void processJointToNodeMapping( domNode* pNode );
void processChildJoints( domNode* pParentNode );
material_map getMaterials(LLModel* model, domInstance_geometry* instance_geo, DAE* dae) const;
LLImportMaterial profileToMaterial(domProfile_COMMON* material, DAE* dae) const;
LLColor4 getDaeColor(daeElement* element) const;
bool verifyCount( int expected, int result );
daeElement* getChildFromElement(daeElement* pElement, std::string const& name);
bool isNodeAJoint(const domNode* pNode) const;
void processJointNode(domNode* pNode, JointTransformMap& jointTransforms);
void extractTranslation(const domTranslate* pTranslate, LLMatrix4& transform) const;
void extractTranslationViaSID(daeElement* pElement, LLMatrix4& transform) const;
void buildJointToNodeMappingFromScene(daeElement* pRoot);
void processJointToNodeMapping(domNode* pNode);
void processChildJoints(domNode* pParentNode);
bool verifyCount(const size_t expected, const size_t result) const;
//Verify that a controller matches vertex counts
bool verifyController( domController* pController );
bool verifyController(const domController* pController) const;
static bool addVolumeFacesFromDomMesh(LLModel* model, domMesh* mesh);
static bool createVolumeFacesFromDomMesh(LLModel* model, domMesh *mesh);
static bool createVolumeFacesFromDomMesh(LLModel* model, domMesh* mesh);
static LLModel* loadModelFromDomMesh(domMesh* mesh);
@@ -99,11 +98,11 @@ protected:
//
bool loadModelsFromDomMesh(domMesh* mesh, std::vector<LLModel*>& models_out, U32 submodel_limit);
static std::string getElementLabel(daeElement *element);
static size_t getSuffixPosition(std::string label);
static std::string getLodlessLabel(daeElement *element);
static std::string getElementLabel(daeElement* element);
static size_t getSuffixPosition(const std::string label);
static std::string getLodlessLabel(daeElement* element);
static std::string preprocessDAE(std::string filename);
static std::string preprocessDAE(const std::string filename);
private:
U32 mGeneratedModelLimit; // Attempt to limit amount of generated submodels

View File

@@ -180,7 +180,7 @@ public:
//-----------------------------------------------------------------------------
// isNodeAJoint()
//-----------------------------------------------------------------------------
bool isNodeAJoint(const char* name)
bool isNodeAJoint(const char* name) const
{
return name != NULL && mJointMap.find(name) != mJointMap.end();
}