summaryrefslogtreecommitdiff
path: root/indra/llprimitive/lldaeloader.h
blob: c6e5ea42fca320c75d53f0f906a52587ce58af6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
 * @file lldaeloader.h
 * @brief LLDAELoader class definition
 *
 * $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$
 */

#ifndef LL_LLDAELOADER_H
#define LL_LLDAELOADER_H

#include "llmodelloader.h"

#ifndef LL_USESYSTEMLIBS
class DAE;
class daeElement;
class domProfile_COMMON;
class domInstance_geometry;
class domNode;
class domTranslate;
class domController;
class domSkin;
class domMesh;
#endif

class LLDAELoader : public LLModelLoader
{
public:
    typedef std::map<std::string, LLImportMaterial>                         material_map;
    typedef std::map<daeElement*, std::vector<LLPointer<LLModel> > >    dae_model_map;
    dae_model_map   mModelsMap;

    LLDAELoader(
        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,
        LLModelLoader::state_callback_t     state_cb,
        void*                               opaque_userdata,
        JointTransformMap&                  jointTransformMap,
        JointNameSet&                       jointsFromNodes,
        std::map<std::string, std::string>& jointAliasMap,
        U32                                 maxJointsPerMesh,
        U32                                 modelLimit,
        bool                                preprocess);
    virtual ~LLDAELoader() ;

    virtual bool OpenFile(const std::string& filename);

protected:

    void processElement(daeElement* element, bool& badElement, DAE* dae);
    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 );

    bool verifyCount( int expected, int result );

    //Verify that a controller matches vertex counts
    bool verifyController( domController* pController );

    static bool addVolumeFacesFromDomMesh(LLModel* model, domMesh* mesh, LLSD& log_msg);

    // 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);
    static size_t getSuffixPosition(std::string label);
    static std::string getLodlessLabel(daeElement *element);

    static std::string preprocessDAE(std::string filename);

private:
    U32 mGeneratedModelLimit; // Attempt to limit amount of generated submodels
    bool mPreprocessDAE;

};
#endif  // LL_LLDAELLOADER_H