summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/UIPParser/Include/Qt3DSUIPParserObjectRefHelper.h
blob: fcd16985756f5b9a269e7cddbd3c826ed6f81cd2 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/****************************************************************************
**
** Copyright (C) 1993-2009 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#pragma once

//==============================================================================
//	Includes
//==============================================================================
#include "Qt3DSUIPParser.h"
#include "Qt3DSUIPParserImpl.h"

//==============================================================================
//	Namespace
//==============================================================================
namespace Q3DStudio {

//==============================================================================
/**
 *	@class	CUIPParserObjectRefHelper
 *	@brief	Class for parsing UIP file - Object Reference Helper
 */
class CUIPParserObjectRefHelper
{
    typedef qt3ds::foundation::CRegisteredString TStrType;

public:
    typedef eastl::hash_map<TStrType, TStrType> TStrToStrMap;

    /// Tree structure to cache scene graph information. This is used to resolve relative object
    /// reference
    struct SGraphNode
    {
        typedef eastl::vector<SGraphNode *> TGraphNodeList;

        TStrType m_Id; // node id
        TStrType m_Name; // name of the node. the name can be default from metadata, specified in
                         // graph section, or specified in logic section.
        TStrType m_Type; // for example: Layer, Camera, Model
        TStrType
            m_Class; // class id. usually used by Behavior or objects that have custom properties.
        void *m_ReaderContext; // Context to warp back to this node.
        void *m_MasterSlide;
        SGraphNode *m_Parent;
        TGraphNodeList m_Children;
        SGraphNode()
            : m_ReaderContext(NULL)
            , m_MasterSlide(NULL)
            , m_Parent(NULL)
        {
        }
    };
    //==============================================================================
    //	Fields
    //==============================================================================
private:
    typedef eastl::hash_set<TStrType> TImageNamePropertyList;
    IRuntimeMetaData &m_MetaData; ///< Reference to Metadata
    typedef eastl::hash_map<TStrType, SGraphNode *> TGraphNodeMap;
    SGraphNode *m_RootNode;
    TGraphNodeMap m_GraphNodeMap;
    TImageNamePropertyList m_SlideIdSet;

    // List of Image property names, for example diffusemap, normalmap, etc
    // This is to handle material and images. Material's Image properties point to instances.
    TImageNamePropertyList m_ImageNamePropertyList;
    TStrType m_MaterialStr;
    eastl::vector<void *> m_SceneGraphAliasList;

    typedef eastl::pair<eastl::string, eastl::string> TLightProbeAndNamePair;
    typedef eastl::map<eastl::string, eastl::string> TLightProbeIdToNameMap;
    TLightProbeIdToNameMap m_LayerImageIdToNameMap;
    //==============================================================================
    //	Methods
    //==============================================================================
public: // Construction
    CUIPParserObjectRefHelper(IRuntimeMetaData &inMetaData);
    virtual ~CUIPParserObjectRefHelper();

    void CacheGraph(qt3dsdm::IDOMReader &inReader, qt3dsdm::IDOMWriter &inWriter);
    SGraphNode *GetNode(const char *inId);
    SGraphNode *GetNode(eastl::string inId);
    TStrType GetName(const eastl::string &inId); // return the node name given the node id
    TStrType GetType(const eastl::string &inId); // return the node type given the node id
    TStrType GetClass(const eastl::string &inId); // return the node class given the node id

    TStrType ParseObjectRefId(const eastl::string &inObjectPath, const char8_t *inOwnerId);
    eastl::string BuildReferenceString(eastl::string inObjectPath);
    void MarkAllReferencedAttributes(eastl::string inId,
                                     const eastl::vector<eastl::string> &inReferences,
                                     qt3dsdm::IDOMReader &inReader,
                                     SParseElementManager &outIdAttributesMap);

private:
    void CacheSceneGraph(qt3dsdm::IDOMReader &inReader, SGraphNode *inParent = NULL);
    SGraphNode &CacheSceneGraphNode(qt3dsdm::IDOMReader &inReader, SGraphNode *inParent = NULL);
    void CacheStateGraph(qt3dsdm::IDOMReader &inReader);

    void CopySceneGraph(qt3dsdm::IDOMReader &inReader, qt3dsdm::IDOMWriter &inWriter,
                        qt3dsdm::IDOMWriter &inSlideWriter, TStrToStrMap &inMap,
                        const char *inAliasName, const char *inAliasId, SGraphNode &inParent);
    void CopyStates(qt3dsdm::IDOMReader &inReader, qt3dsdm::IDOMWriter &inSlideWriter,
                    TStrToStrMap &inMap, const char *inAliasName, const char *inAliasId);
    void CopyAttributes(qt3dsdm::IDOMReader &inReader, qt3dsdm::IDOMWriter &inSlideWriter,
                        TStrToStrMap &inMap, const char *inAliasName, const char *inAliasId);
    void CopyHierarchy(qt3dsdm::IDOMReader &inReader, qt3dsdm::IDOMWriter &inSlideWriter,
                       TStrToStrMap &inMap, const char *inAliasName, const char *inAliasId);
    void CopyStateCommands(qt3dsdm::IDOMReader &inReader, qt3dsdm::IDOMWriter &inWriter,
                           TStrToStrMap &oldToNewIdMap, const char *inAliasName,
                           const char *inOldId, const char *inNewId);
    // Helper method for Preseve Attributes
    SGraphNode *GetReferenceNode(SGraphNode *inInstance, eastl::string &inAssetName,
                                 eastl::vector<SGraphNode *> &outInstanceList,
                                 qt3dsdm::IDOMReader &inReader);
    bool MarkAttributeAsReferenced(SGraphNode *inBaseInstance,
                                   eastl::vector<SGraphNode *> &inInstanceList,
                                   eastl::string &inAttributeName, qt3dsdm::IDOMReader &inReader,
                                   SParseElementManager &outIdAttributesMap);
    void MarkPreserveFlag(SGraphNode *inInstance, eastl::string inProperty,
                          SParseElementManager &outIdAttributesMap);
    eastl::pair<const char8_t *, const char8_t *>
    ProcessAliasAttribute(const char8_t *inObjId,
                          eastl::pair<const char8_t *, const char8_t *> inAttribute,
                          eastl::string &ioStrBuilder, TStrToStrMap &inMap);

    eastl::string BuildAbsoluteReferenceString(eastl::string inId);
    eastl::string BuildAbsoluteReferenceString(SGraphNode *inNode);

    // Special case for material and images. Material's Image properties point to instances.
    void BuildImageNamePropertyList();
};

} // namespace Q3DStudio