summaryrefslogtreecommitdiffstats
path: root/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.h
blob: 8935f28b3afbac305faf06da2b72340c5c727183 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/****************************************************************************
**
** Copyright (C) 1999-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-EXCEPT$
** 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 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** 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$
**
****************************************************************************/

//==============================================================================
// Includes
//==============================================================================
#pragma once

#include <vector>
#include "Qt3DSImportTranslation.h"
#include "Qt3DSImportTranslationCommon.h"

namespace qt3dsimp {

typedef enum _ETransformType {
    ETransformType_Matrix4x4,
    ETransformType_Rotation3, // rotation defined with 3 angles
    ETransformType_Rotation4, // rotation defined with an axis and angle
    ETransformType_Translate3,
    ETransformType_Scale3,
    ETransformType_Unknown
} ETransformType;

class INodeTransform
{
public:
    virtual ~INodeTransform() {}
    virtual operator float *() const = 0;
    virtual ETransformType GetType() const = 0;
};

class NodeTransform : public INodeTransform
{
public:
    NodeTransform(ETransformType inType)
    {
        m_Data = NULL;
        switch (inType) {
        case ETransformType_Matrix4x4:
            m_Data = new float[16];
            break;
        case ETransformType_Rotation3:
            m_Data = new float[3];
            break;
        case ETransformType_Rotation4:
            m_Data = new float[4];
            break;
        case ETransformType_Translate3:
            m_Data = new float[3];
            break;
        case ETransformType_Scale3:
            m_Data = new float[3];
            break;
        default:
            break;
        }

        m_Type = inType;
    }

    ~NodeTransform() { delete[] m_Data; }

    operator float *() const override { return m_Data; }

    ETransformType GetType() const override { return m_Type; }

    static void Delete(INodeTransform *inTransform) { delete inTransform; }

protected:
    float *m_Data;
    ETransformType m_Type;
};

typedef std::vector<INodeTransform *> TTransformList;

typedef enum _ETextureMapType {
    ETextureMapTypeDiffuse,
    ETextureMapTypeOpacity,
    ETextureMapTypeSpecular,
    ETextureMapTypeRoughness,
    ETextureMapTypeEmissive
} ETextureMapType;

typedef enum _EMatCommonProfileTechnique {
    EMatCommonProfileTechnique_Blinn,
    EMatCommonProfileTechnique_Constant,
    EMatCommonProfileTechnique_Lambert,
    EMatCommonProfileTechnique_Phong,
    EMatCommonProfileTechnique_Count
} EMatCommonProfileTechnique;

typedef enum _EMatOpaqueType // refer to domFx_opaque_enum
{ EMatOpaqueType_A_ONE, // When a transparent opaque attribute is set to A_ONE, it means the
                        // transparency information will be taken from the alpha channel of the
                        // color, texture, or parameter supplying the value. The value of 1.0 is
                        // opaque in this mode.
  EMatOpaqueType_RGB_ZERO, // When a transparent opaque attribute is set to RGB_ZERO, it means the
                           // transparency information will be taken from the red, green, and blue
                           // channels of the color, texture, or parameter supplying the value. Each
                           // channel is modulated independently. The value of 0.0 is opaque in this
                           // mode.
} EMatOpaqueType;

typedef struct _SFloatFlag
{
    float m_Value; // the value of this struct
    bool m_Flag; // to indicate if this value presents in SceneGraph
    _SFloatFlag()
        : m_Value(0.0f)
        , m_Flag(false)
    {
    }
    void SetValue(float inValue)
    {
        m_Value = inValue;
        m_Flag = true;
    }
} SFloatFlag;

typedef struct _SLongFlag
{
    long m_Value; // the value of this struct
    bool m_Flag; // to indicate if this value presents in SceneGraph
    _SLongFlag()
        : m_Value(0)
        , m_Flag(false)
    {
    }
    void SetValue(long inValue)
    {
        m_Value = inValue;
        m_Flag = true;
    }
} SLongFlag;

typedef struct _SColorOrTexture
{
    typedef enum _Type {
        None, // This information doesn't present in SceneGraph or of Param Type
        Color, // Color type
        Texture, // Texture type
    } Type;

    Type m_Type;
    float m_Color[4]; // the color, if present
    _SColorOrTexture()
        : m_Type(None)
    {
        m_Color[0] = m_Color[1] = m_Color[2] = m_Color[3] = 0.0f;
    }
    void SetColor(const float inColor[])
    {
        m_Color[0] = inColor[0];
        m_Color[1] = inColor[1];
        m_Color[2] = inColor[2];
        m_Color[3] = inColor[3];
        m_Type = Color;
    }
    void SetColor(float c0, float c1, float c2, float c3)
    {
        m_Color[0] = c0;
        m_Color[1] = c1;
        m_Color[2] = c2;
        m_Color[3] = c3;
        m_Type = Color;
    }
    void SetTexture() { m_Type = Texture; }
} SColorOrTexture;

//==============================================================================
// To store information regarding texture parameters which normally stored under <extra> tag
//==============================================================================
typedef struct _STextureParameters
{
    SFloatFlag m_coverageU;
    SFloatFlag m_coverageV;
    SFloatFlag m_repeatU;
    SFloatFlag m_repeatV;
    SFloatFlag m_offsetU;
    SFloatFlag m_offsetV;
    SFloatFlag m_rotateUV;
    SLongFlag m_wrapU;
    SLongFlag m_wrapV;
    SLongFlag m_mirrorU;
    SLongFlag m_mirrorV;
    bool m_Flag; // to indicate if dae contains texture parameters information
    _STextureParameters()
        : m_Flag(false)
    {
    }
} STextureParameters;

//==============================================================================
// To store information regarding material parameters which normally stored under <extra> tag
//==============================================================================
typedef struct _SMaterialExtraParameters
{
    SFloatFlag m_SpecLevel;
    SFloatFlag m_EmissionLevel;
    bool m_Flag; // to indicate if dae contains profile_COMMON technique extra information
    _SMaterialExtraParameters()
        : m_Flag(false)
    {
    }
} SMaterialExtraParameters;

//==============================================================================
// To store information regarding material parameters which stored under profile_COMMON technique
//==============================================================================
typedef struct _SMaterialParameters
{
    EMatCommonProfileTechnique m_TechniqueType;
    SColorOrTexture m_Emission;
    SColorOrTexture m_Ambient;
    SColorOrTexture m_Diffuse;
    SColorOrTexture m_Specular;
    SFloatFlag m_Shininess;
    SColorOrTexture m_Reflective;
    SFloatFlag m_Reflectivity;
    SColorOrTexture m_Transparent;
    SLongFlag m_TransparentOpaqueType;
    SFloatFlag m_Transparency;
    SFloatFlag m_Index_of_refraction;
    SMaterialExtraParameters m_Extra;

    _SMaterialParameters()
        : m_TechniqueType(EMatCommonProfileTechnique_Count)
    {
    }
    _SMaterialParameters(EMatCommonProfileTechnique inTechniqueType)
        : m_TechniqueType(inTechniqueType)
    {
    }
} SMaterialParameters;

//==============================================================================
// To store information regarding animation keyframes
//==============================================================================
typedef struct _SKeyframeParameters
{
    float m_KeyframeTime;
    float m_Value;
    float m_INTANGENTX;
    float m_INTANGENTY;
    float m_OUTTANGENTX;
    float m_OUTTANGENTY;

    _SKeyframeParameters(float inKeyframeTime, float inValue, float inINTANGENTX,
                         float inINTANGENTY, float inOUTTANGENTX, float inOUTTANGENTY)
        : m_KeyframeTime(inKeyframeTime)
        , m_Value(inValue)
        , m_INTANGENTX(inINTANGENTX)
        , m_INTANGENTY(inINTANGENTY)
        , m_OUTTANGENTX(inOUTTANGENTX)
        , m_OUTTANGENTY(inOUTTANGENTY)
    {
    }

} SKeyframeParameters;

//==============================================================================
// To store information regarding skelatal animations
//==============================================================================
typedef struct _SJointInfo
{
    int m_JointID;
    int m_ParentID;
    float m_invBindPose[16];
    float m_localToGlobalBoneSpace[16];

    _SJointInfo(int jointIndex, int parentID, float *invBindPose, float *localToGlobal)
        : m_JointID(jointIndex)
        , m_ParentID(parentID)
    {
        ::memcpy(m_invBindPose, invBindPose, sizeof(float) * 16);
        ::memcpy(m_localToGlobalBoneSpace, localToGlobal, sizeof(float) * 16);
    }

} SJointInfo;

//==============================================================================
// Templatized container for floats
//==============================================================================
template <size_t N>
struct _SVector
{
    float m_Data[N];

    bool operator<(const struct _SVector<N> &inVector) const
    {
        return ::memcmp(m_Data, inVector.m_Data, sizeof(m_Data)) < 0;
    }

    operator float *() { return m_Data; }

    operator const float *() const { return m_Data; }
};

typedef struct _SVector<4> SVector4;
typedef struct _SVector<3> SVector3;
typedef struct _SVector<2> SVector2;

class Import;

typedef enum _EAuthoringToolType {
    EAuthoringToolType_Unknown = 0,
    EAuthoringToolType_NextGen_Max,
    EAuthoringToolType_NextGen_Maya,
    EAuthoringToolType_FCollada_Max,
    EAuthoringToolType_FCollada_Maya,
    EAuthoringToolType_SketchUp,
    EAuthoringToolType_Cinema4D,
    EAuthoringToolType_StudioCORE,
    EAuthoringToolType_FBX_Max,
    EAuthoringToolType_FBX_Modo,
    EAuthoringToolType_FBX_Maya,
    EAuthoringToolType_FBX_Blender
} EAuthoringToolType;

//==============================================================================
// Function interfaces for a translation class to allow much easier (and typed)
// data writing to the base import library.
//==============================================================================
class ISceneGraphTranslation
{
protected:
    virtual ~ISceneGraphTranslation() {}

public:
    virtual void Release() = 0;

    virtual void SetAuthoringTool(EAuthoringToolType inAuthoringToolType,
                                  long inAuthoringToolVersion) = 0;

    virtual void PushLight(const char *inName) = 0;
    virtual void SetLightProperties(int type, const SFloat4 &color, double intensity,
                                    double linearfade, double quadfade, bool shadows) = 0;
    virtual void PopLight() = 0;
    virtual void PushCamera(const char *inName) = 0;
    virtual void SetCameraProperties(double clipstart, double clipend, bool ortho, double fov) = 0;
    virtual void PopCamera() = 0;
    virtual void PushGroup(const char *inName) = 0;
    virtual void SetGroupSkeletonId(long inId) = 0;
    virtual void SetIgnoresParentTransform(bool inValue) = 0;
    virtual void PopGroup() = 0;
    virtual void PushModel(const char *inName) = 0;
    virtual void SetModelSkeletonRoot(long inId) = 0;
    virtual void PopModel() = 0;
    virtual void PushMaterial(const char *inName) = 0;
    virtual void PopMaterial(long inStartFaceIndex, long inNumberOfFaces) = 0;
    virtual void PushTexture(const char *inName, const char *inSourcePath, long inMapType) = 0;
    virtual void PopTexture() = 0;

    // Translation failed, mark top object as invalid.
    virtual void MarkInvalid() = 0;

    virtual void SetTransforms(const TTransformList &inTransforms) = 0;
    virtual void SetGeometry(TFloatsList &ioVertices, TFloatsList &ioNormals,
                             TFloatsList &ioTexCoords, TFloatsList &ioTexCoords2,
                             TFloatsList &ioTexTangents, TFloatsList &ioTexBinormals,
                             TFloatsList &ioWeights, TFloatsList &ioBoneIndex,
                             TFloatsList &ioColors, TLongsList &ioFaceIndicies) = 0;
    virtual void SetMaterial(const SMaterialParameters &inMaterialParameters) = 0;
    virtual void SetTexture(long inMapType, const STextureParameters &inTextureParameters) = 0;
    virtual void SetJointNode(SJointInfo &inJointInfo) = 0;

    virtual long CacheAnimationTrack() = 0;
    virtual void ApplyAnimationTrack(long inAnimationTrackIndex) = 0;
    virtual void SetAnimationTrack(const char *inBasePropertyName,
                                   const char *inSubPropertyName) = 0;
    virtual void CacheAnimationKey(const char *inBaseProperty, const char *inSubPropertyName,
                                   const SKeyframeParameters &inParameters) = 0;

    virtual void LogWarning(ESceneGraphWarningCode inWarningCode, const char *inAssociatedName) = 0;

    static ISceneGraphTranslation &CreateTranslation(Import &import, ISGTranslationLog &log);
};
}