1/****************************************************************************************
2
3 Copyright (C) 2015 Autodesk, Inc.
4 All rights reserved.
5
6 Use of this software is subject to the terms of the Autodesk license agreement
7 provided at the time of installation or download, or which otherwise accompanies
8 this software in either electronic or hard copy form.
9
10****************************************************************************************/
11
12//! \file fbxsystemunit.h
13#ifndef _FBXSDK_CORE_SYSTEM_UNIT_H_
14#define _FBXSDK_CORE_SYSTEM_UNIT_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/base/fbxstring.h>
19#include <fbxsdk/core/base/fbxarray.h>
20
21#include <fbxsdk/fbxsdk_nsbegin.h>
22
23class FbxAMatrix;
24class FbxScene;
25class FbxNode;
26class FbxAnimCurveNode;
27
28/** \brief This class describes the units of measurement used within a particular scene.
29 * \nosubgrouping
30 */
31class FBXSDK_DLL FbxSystemUnit
32{
33public:
34
35 /** Struct to define various options that you can use to convert the system unit of a scene.
36 * The default values are:
37 * mConvertRrsNodes = true
38 * mConvertLimits = true
39 * mConvertClusters = true
40 * mConvertLightIntensity = true
41 * mConvertPhotometricLProperties = true
42 * mConvertCameraClipPlanes = true
43 *
44 * The default configuration have been tested to give the best conversion results in the majority of the case.
45 * \remark Changing any of these values will have a direct impact on the whole scene behavior.
46 */
47 struct ConversionOptions
48 {
49 //! This flag indicates whether or not to convert the nodes that do not inherit their parent's scale.
50 bool mConvertRrsNodes;
51
52 //! This flag indicates whether or not to convert limits.
53 bool mConvertLimits;
54
55 //! This flag indicates whether or not to convert clusters.
56 bool mConvertClusters;
57
58 //! This flag indicates whether or not to convert the light intensity property.
59 bool mConvertLightIntensity;
60
61 //! This flag indicates whether or not to convert photometric lights properties.
62 bool mConvertPhotometricLProperties;
63
64 //! This flag indicates whether or not to convert the cameras clip planes.
65 bool mConvertCameraClipPlanes;
66 };
67
68 FbxSystemUnit();
69
70 /** Constructor.
71 * \param pScaleFactor The equivalent number of centimeters in the new system unit.
72 * For example, an inch unit uses a scale factor of 2.54.
73 * \param pMultiplier A multiplier factor of pScaleFactor.
74 */
75 FbxSystemUnit(double pScaleFactor, double pMultiplier = 1.0);
76
77 /** Destructor.
78 */
79 ~FbxSystemUnit();
80
81 //! Predefined system unit for millimeters.
82 static const FbxSystemUnit mm;
83
84 //! Predefined system unit for decimeters.
85 static const FbxSystemUnit dm;
86
87 //! Predefined system unit for centimeters.
88 static const FbxSystemUnit cm;
89
90 //! Predefined system unit for meters.
91 static const FbxSystemUnit m;
92
93 //! Predefined system unit for kilometers.
94 static const FbxSystemUnit km;
95
96 //! Predefined system unit for inches.
97 static const FbxSystemUnit Inch;
98
99 //! Predefined system unit for feet.
100 static const FbxSystemUnit Foot;
101
102 //! Predefined system unit for miles.
103 static const FbxSystemUnit Mile;
104
105 //! Predefined system unit for yards.
106 static const FbxSystemUnit Yard;
107
108 #define FBXSDK_SYSTEM_UNIT_PREDEF_COUNT 9
109
110 //! Points to a FbxSystemUnit array to store the predefined system units. The array size is FBXSDK_SYSTEM_UNIT_PREDEF_COUNT.
111 static const FbxSystemUnit *sPredefinedUnits;
112
113 //! Stores the default conversion options.
114 static const ConversionOptions DefaultConversionOptions;
115
116 /** Converts a scene from its system units to this system unit.
117 * \param pScene The scene to convert.
118 * \param pOptions Conversion options, see:FbxSystemUnit::ConversionOptions.
119 */
120 void ConvertScene( FbxScene* pScene, const ConversionOptions& pOptions = DefaultConversionOptions ) const;
121
122 /** Converts the child (or children) of the given node from the system unit to this system unit.
123 * Unlike the ConvertScene() method, this method does not set the axis system
124 * of the scene to which the pRoot node belongs. It also does not adjust FbxPose
125 * as they are not stored under the scene, and not under a particular node.
126 * \param pRoot The given node.
127 * \param pSrcUnit The source system unit.
128 * \param pOptions Conversion options, see:FbxSystemUnit::ConversionOptions.
129 */
130 void ConvertChildren( FbxNode* pRoot, const FbxSystemUnit& pSrcUnit, const ConversionOptions& pOptions = DefaultConversionOptions ) const;
131
132 /** Converts a scene from its system unit to this system unit, using the specified
133 * Fbx_Root node. This method is provided for backwards compatibility only
134 * and instead you should use ConvertScene( FbxScene* , const ConversionOptions& ) whenever possible.
135 * \param pScene The scene to convert.
136 * \param pFbxRoot The Fbx_Root node to use for conversion.
137 * \param pOptions Conversion options, see:FbxSystemUnit::ConversionOptions
138 */
139 void ConvertScene( FbxScene* pScene, FbxNode* pFbxRoot, const ConversionOptions& pOptions = DefaultConversionOptions ) const;
140
141 /** Returns the system unit's scale factor, relative to centimeters.
142 * This factor scales system unit values to centimeters. If you want to scale values to centimeters, use this value.
143 * Ignore the "multiplier" (returned by GetMultiplier()) value.
144 * \return The the system unit's scale factor, relative to centimeters.
145 */
146 double GetScaleFactor() const;
147
148 /** Returns a unit label for the current scale factor.
149 * \param pAbbreviated If \c true, returns abbreviated string.
150 * \return The unit label for the current scale factor.
151 */
152 FbxString GetScaleFactorAsString(bool pAbbreviated = true) const;
153
154 /** Returns a unit label for the current scale factor.
155 * The first letter of the label is in upper case and the label should be pluralized.
156 * \return The unit label for the current scale factor.
157 */
158 FbxString GetScaleFactorAsString_Plurial() const;
159
160 /** Returns the multiplier factor of the system unit.
161 */
162 double GetMultiplier() const;
163
164 /** Equivalence operator.
165 * \param pOther Another system unit compared with this system unit.
166 * \return \c True if equal, \c false otherwise.
167 */
168 bool operator==(const FbxSystemUnit& pOther) const;
169
170 /** Non-equivalence operator.
171 * \param pOther Another system unit compared with this system unit.
172 * \return \c True if unequal, \c false otherwise.
173 */
174 bool operator!=(const FbxSystemUnit& pOther) const;
175
176 /** Assignment operation.
177 * \param pSystemUnit Unit system assigned to this one.
178 */
179 FbxSystemUnit& operator=(const FbxSystemUnit& pSystemUnit);
180
181 /** Returns the conversion factor from this system unit to the target system unit, excluding the multiplier factor.
182 * \param pTarget The target system unit.
183 */
184 double GetConversionFactorTo( const FbxSystemUnit& pTarget ) const;
185
186 /** Returns the conversion factor from the source system unit to this system unit, excluding the multiplier factor.
187 * \param pSource The source system unit.
188 */
189 double GetConversionFactorFrom( const FbxSystemUnit& pSource ) const;
190
191/*****************************************************************************************************************************
192** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
193*****************************************************************************************************************************/
194#ifndef DOXYGEN_SHOULD_SKIP_THIS
195private:
196 void ApplyMultiplier(FbxNode* pRoot, bool pSubChildrenOnly) const;
197 void ConvertSTProperties(FbxArray<FbxNode*>& pNodes, double pConversionFactor) const;
198 void ConvertSProperty(FbxArray<FbxNode*>& pNodes, double pConversionFactor) const;
199 void ConvertAnimCurveNode(FbxArray<FbxAnimCurveNode*>& pFCurves, double pConversionFactor) const;
200 double GetConversionFactor(double pTargetScaleFactor, double pSourceScaleFactor) const;
201 void AdjustPivots(FbxNode* pNode, double pConversionFactor, FbxAMatrix& pOriginalGlobalM ) const;
202 void AdjustLimits(FbxNode* pNode, double pConversionFactor) const;
203 void AdjustPoses(FbxScene* pScene, double pConversionFactor) const;
204 void AdjustCluster(FbxNode* pNode, double pConversionFactor) const;
205 void AdjustLightIntensity(FbxNode* pNode, const double pConversionFactor) const;
206 void AdjustPhotometricLightProperties(FbxNode* pNode, const double pConversionFactor) const;
207 void AdjustCameraClipPlanes(FbxNode* pNode, const double pConversionFactor) const;
208 void ConvertChildren(FbxNode* pRoot, const FbxSystemUnit& pSrcUnit, bool pSubChildrenOnly, const ConversionOptions& pOptions) const;
209
210 double mScaleFactor;
211 double mMultiplier;
212
213 friend class FbxGlobalSettings;
214#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
215};
216
217#include <fbxsdk/fbxsdk_nsend.h>
218
219#endif /* _FBXSDK_CORE_SYSTEM_UNIT_H_ */
220