1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2019, assimp team
6 
7 
8 All rights reserved.
9 
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the
12 following conditions are met:
13 
14 * Redistributions of source code must retain the above
15   copyright notice, this list of conditions and the
16   following disclaimer.
17 
18 * Redistributions in binary form must reproduce the above
19   copyright notice, this list of conditions and the
20   following disclaimer in the documentation and/or other
21   materials provided with the distribution.
22 
23 * Neither the name of the assimp team, nor the names of its
24   contributors may be used to endorse or promote products
25   derived from this software without specific prior
26   written permission of the assimp team.
27 
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 
40 ----------------------------------------------------------------------
41 */
42 
43 /** @file  MakeLeftHandedProcess.h
44  *  @brief Defines a bunch of post-processing steps to handle
45  *    coordinate system conversions.
46  *
47  *  - LH to RH
48  *  - UV origin upper-left to lower-left
49  *  - face order cw to ccw
50  */
51 #ifndef AI_CONVERTTOLHPROCESS_H_INC
52 #define AI_CONVERTTOLHPROCESS_H_INC
53 
54 #include <assimp/types.h>
55 
56 #include "Common/BaseProcess.h"
57 
58 struct aiMesh;
59 struct aiNodeAnim;
60 struct aiNode;
61 struct aiMaterial;
62 
63 namespace Assimp    {
64 
65 // -----------------------------------------------------------------------------------
66 /** @brief The MakeLeftHandedProcess converts all imported data to a left-handed
67  *   coordinate system.
68  *
69  * This implies a mirroring of the Z axis of the coordinate system. But to keep
70  * transformation matrices free from reflections we shift the reflection to other
71  * places. We mirror the meshes and adapt the rotations.
72  *
73  * @note RH-LH and LH-RH is the same, so this class can be used for both
74  */
75 class MakeLeftHandedProcess : public BaseProcess
76 {
77 
78 
79 public:
80     MakeLeftHandedProcess();
81     ~MakeLeftHandedProcess();
82 
83     // -------------------------------------------------------------------
84     bool IsActive( unsigned int pFlags) const;
85 
86     // -------------------------------------------------------------------
87     void Execute( aiScene* pScene);
88 
89 protected:
90 
91     // -------------------------------------------------------------------
92     /** Recursively converts a node and all of its children
93      */
94     void ProcessNode( aiNode* pNode, const aiMatrix4x4& pParentGlobalRotation);
95 
96     // -------------------------------------------------------------------
97     /** Converts a single mesh to left handed coordinates.
98      * This means that positions, normals and tangents are mirrored at
99      * the local Z axis and the order of all faces are inverted.
100      * @param pMesh The mesh to convert.
101      */
102     void ProcessMesh( aiMesh* pMesh);
103 
104     // -------------------------------------------------------------------
105     /** Converts a single material to left-handed coordinates
106      * @param pMat Material to convert
107      */
108     void ProcessMaterial( aiMaterial* pMat);
109 
110     // -------------------------------------------------------------------
111     /** Converts the given animation to LH coordinates.
112      * The rotation and translation keys are transformed, the scale keys
113      * work in local space and can therefore be left untouched.
114      * @param pAnim The bone animation to transform
115      */
116     void ProcessAnimation( aiNodeAnim* pAnim);
117 };
118 
119 
120 // ---------------------------------------------------------------------------
121 /** Postprocessing step to flip the face order of the imported data
122  */
123 class FlipWindingOrderProcess : public BaseProcess
124 {
125     friend class Importer;
126 
127 public:
128     /** Constructor to be privately used by Importer */
129     FlipWindingOrderProcess();
130 
131     /** Destructor, private as well */
132     ~FlipWindingOrderProcess();
133 
134     // -------------------------------------------------------------------
135     bool IsActive( unsigned int pFlags) const;
136 
137     // -------------------------------------------------------------------
138     void Execute( aiScene* pScene);
139 
140 protected:
141     void ProcessMesh( aiMesh* pMesh);
142 };
143 
144 // ---------------------------------------------------------------------------
145 /** Postprocessing step to flip the UV coordinate system of the import data
146  */
147 class FlipUVsProcess : public BaseProcess
148 {
149     friend class Importer;
150 
151 public:
152     /** Constructor to be privately used by Importer */
153     FlipUVsProcess();
154 
155     /** Destructor, private as well */
156     ~FlipUVsProcess();
157 
158     // -------------------------------------------------------------------
159     bool IsActive( unsigned int pFlags) const;
160 
161     // -------------------------------------------------------------------
162     void Execute( aiScene* pScene);
163 
164 protected:
165     void ProcessMesh( aiMesh* pMesh);
166     void ProcessMaterial( aiMaterial* mat);
167 };
168 
169 } // end of namespace Assimp
170 
171 #endif // AI_CONVERTTOLHPROCESS_H_INC
172