fbxsdk/fileio/collada/fbxcolladautils.h Source File

fbxcolladautils.h
Go to the documentation of this file.
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 
13 #ifndef _FBXSDK_FILEIO_COLLADA_UTILS_H_
14 #define _FBXSDK_FILEIO_COLLADA_UTILS_H_
15 
16 #include <fbxsdk.h>
17 
20 
21 #include <components/libxml2-2.7.8/include/libxml/globals.h>
22 
23 #include <fbxsdk/fbxsdk_nsbegin.h>
24 
25 #ifndef INT_MAX
26  #define INT_MAX 0x7FFFFFFF
27 #endif
28 
29 #ifndef CENTIMETERS_TO_INCHES
30  #define CENTIMETERS_TO_INCHES 2.54f
31 #endif
32 
33 #ifndef RADIANS_TO_DEGREES
34  #define RADIANS_TO_DEGREES 57.295799f
35 #endif
36 
38 
39 const int MATRIX_STRIDE = 16;
40 const int VECTOR_STRIDE = 3;
41 
42 #define COLLADA_ID_PROPERTY_NAME "COLLADA_ID"
43 
45 {
46 public:
47  static inline void DeleteIt(xmlNode ** ptr)
48  {
49  if (*ptr != NULL)
50  {
51  xmlFreeNode(*ptr);
52  *ptr = NULL;
53  }
54  }
55 };
56 
60 
61 // Some information connecting COLLADA layer string, such as "NORMAL" or "UV", to FBX layer element type.
63 {
66 
68  : mLayerType(pType), mLayerElementLength(pLength) {}
69 
70  // Type of FBX element layer
72  // Count of double of each element in FBX element layer
74 
79  static const ColladaLayerTraits GetLayerTraits(const FbxString & pLabel);
80 };
81 
86 void DAE_AddNotificationError(const FbxManager * pSdkManger, const FbxString & pErrorMessage);
87 
92 void DAE_AddNotificationWarning(const FbxManager * pSdkManger, const FbxString & pWarningMessage);
93 
94 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector4>& arr);
95 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector2>& arr);
96 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxColor>& arr);
97 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<double>& arr);
98 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxStringList& arr);
99 
100 // Syntax modification - for COLLADA 1.4
101 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxStringList& accessorParams, FbxArray<double>& arr, bool isCommonProfile=true);
102 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector4>& arr);
103 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector2>& arr);
104 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxColor>& arr);
105 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxAMatrix>& arr);
106 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxMatrix>& arr);
107 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxStringList& arr, const char* type, bool isCommonProfile=true);
108 
109 
110 void DAE_ExportSourceArray(xmlNode* sourceNode, const char* id, FbxArray<FbxColor>& arr);
111 void DAE_ExportSourceArray14(xmlNode* sourceNode, const char* id, FbxArray<FbxColor>& arr);
112 
113 xmlNode* DAE_ExportAccessor(xmlNode* parentXmlNode, const char* id, const char* arrayRef, int count, int stride, const char* name, const char* type);
114 xmlNode* DAE_ExportAccessor14(xmlNode* parentXmlNode, const char* id, const char* arrayRef, int count, int stride, const char* name, const char* type);
115 
116 void DAE_AddXYZAccessor(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
117 void DAE_AddSTAccessor(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
118 void DAE_AddFlow(xmlNode* node, DAE_Flow flow);
119 void DAE_AddXYZAccessor14(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
120 void DAE_AddSTAccessor14(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
121 
122 // AddParameter functions for COLLADA 1.3.
123 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxColor& color, DAE_Flow flow);
124 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxVector4& vector, DAE_Flow flow);
125 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, double value, DAE_Flow flow);
126 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, bool value, DAE_Flow flow);
127 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const char* type, const char* value, DAE_Flow flow);
128 
129 // Overload functions without DAE_Flow, for COLLADA 1.4.
130 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxDouble3& color);
131 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxColor& color);
132 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxVector4& vector);
133 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, double value);
134 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, bool value);
135 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const char* type, const char* value);
136 xmlNode* DAE_AddTechnique(xmlNode* parentXmlNode, const char* technique);
137 void DAE_AddInput(xmlNode* parentXmlNode, const char* semantic, const char* source, int idx = -1);
138 void DAE_AddInput14(xmlNode* parentXmlNode, const char* semantic, const char* source, int offset = -1, int set=-1);
139 
141 
143 
149 void findChildrenByType(xmlNode* pParentElement, const FbxSet<FbxString>& pTypes, CNodeList& pChildrenElements);
150 
156 void findChildrenByType(xmlNode* pParentElement, const char * pType, CNodeList& pChildrenElements);
157 
158 xmlNode* getSourceAccessor(xmlNode* sourceNode);
159 xmlNode* getTechniqueNode(xmlNode* parent, const char * profile);
160 
161 // Conversions
162 inline double inchesToCentimeters(double val) { return FbxFloor(val / CENTIMETERS_TO_INCHES * 100000) / 100000; }
163 inline double centimetersToInches(double val) { return FbxFloor(val * CENTIMETERS_TO_INCHES * 100000) / 100000; }
164 
165 inline double degreesToRadians(double val) { return FbxFloor(val / RADIANS_TO_DEGREES * 100000) / 100000; }
166 inline double radiansToDegrees(double val) { return FbxFloor(val * RADIANS_TO_DEGREES * 100000) / 100000; }
167 
175 xmlNode* DAE_FindChildElementByAttribute(xmlNode* pParentElement, const char * pAttributeName,
176  const char * pAttributeValue, const char * pDefaultAttributeValue = "");
177 
184 xmlNode* DAE_FindChildElementByTag(xmlNode* pParentElement, const char * pTag, xmlNode* pFindFrom = NULL);
185 
190 template <typename TYPE>
191 void DAE_GetElementContent(xmlNode * pElement, TYPE & pData)
192 {
193  if (pElement != NULL)
194  {
195  FbxAutoFreePtr<xmlChar> lContent(xmlNodeGetContent(pElement));
196  FromString(&pData, (const char *)lContent.Get());
197  }
198 }
199 
204 bool DAE_CheckCompatibility(xmlNode * pNodeElement);
205 
210 void DAE_GetElementTag(xmlNode * pElement, FbxString & pTag);
211 
217 const FbxString DAE_GetElementAttributeValue(xmlNode * pElement, const char * pAttributeName);
218 
225 template <typename TYPE>
226 bool DAE_GetElementAttributeValue(xmlNode * pElement, const char * pAttributeName, TYPE & pData)
227 {
228  if (!pElement || !pAttributeName)
229  return false;
230 
231  FbxAutoFreePtr<xmlChar> lPropertyValue(xmlGetProp(pElement, (const xmlChar *)pAttributeName));
232  if (lPropertyValue)
233  {
234  FromString(&pData, (const char *)lPropertyValue.Get());
235  return true;
236  }
237  return false;
238 }
239 
240 // Special instantiation for string;
241 // Omit the whitespaces, just return the whole string
242 template <>
243 inline bool DAE_GetElementAttributeValue(xmlNode * pElement,
244  const char * pAttributeName,
245  FbxString & pData)
246 {
247  if (!pElement || !pAttributeName)
248  return false;
249 
250  FbxAutoFreePtr<xmlChar> lPropertyValue(xmlGetProp(pElement, (const xmlChar *)pAttributeName));
251  if (lPropertyValue)
252  {
253  pData = (const char *)lPropertyValue.Get();
254  return true;
255  }
256  return false;
257 }
258 
265 bool DAE_CompareAttributeValue(xmlNode * pElement,
266  const char * pAttributeName,
267  const char * pValue);
268 
273 const FbxString DAE_GetIDFromUrlAttribute(xmlNode * pElement);
274 
279 const FbxString DAE_GetIDFromSourceAttribute(xmlNode * pElement);
280 
286 const FbxString DAE_GetIDFromTargetAttribute(xmlNode * pElement);
287 
293 void DAE_SetName(FbxObject * pObject, const FbxString & pName, const FbxString & pID);
294 
304 xmlNode * DAE_GetSourceWithSemantic(xmlNode * pConsumerElement, const char * pSemantic,
305  const SourceElementMapType & pSourceElements);
306 
313 template <typename T>
314 xmlNode * DAE_AddChildElement(xmlNode * pParentElement, const char * pTag,
315  const T & pContent)
316 {
317  const FbxString lRepr = ToString(pContent);
318  return xmlNewChild(pParentElement, NULL, (xmlChar *)pTag,
319  (xmlChar *)lRepr.Buffer());
320 }
321 
322 // Create a child element with empty content.
323 inline xmlNode * DAE_AddChildElement(xmlNode * pParentElement, const char * pTag)
324 {
325  return DAE_AddChildElement(pParentElement, pTag, FbxString());
326 }
327 
328 // Create a new element with empty content.
329 inline xmlNode * DAE_NewElement(const char * pTag)
330 {
331  return xmlNewNode(NULL, reinterpret_cast<xmlChar*>(const_cast<char *>(pTag)));
332 }
333 
340 template <typename T>
341 xmlAttr * DAE_AddAttribute(xmlNode * pElement, const FbxString & pAttributeName,
342  const T & pAttributeValue)
343 {
344  const FbxString lRepr = ToString(pAttributeValue);
345  return xmlNewProp(pElement, (xmlChar *)pAttributeName.Buffer(),
346  (xmlChar *)lRepr.Buffer());
347 }
348 
353 const FbxSystemUnit DAE_ImportUnit(xmlNode * pUnitElement);
354 
359 void IncreaseLclTranslationAnimation(FbxNode * pNode, FbxDouble3 & pOffset);
360 
366 void RecursiveSearchElement(xmlNode * pBaseElement, const char * pTag, FbxArray<xmlNode*> & pResult);
367 
368 #include <fbxsdk/fbxsdk_nsend.h>
369 
370 #endif /* _FBXSDK_FILEIO_COLLADA_UTILS_H_ */
FbxMap< FbxString, xmlNode * > SourceElementMapType
xmlNode * DAE_ExportAccessor(xmlNode *parentXmlNode, const char *id, const char *arrayRef, int count, int stride, const char *name, const char *type)
FbxAutoPtr mimics the auto_ptr class template implementation available in the C++ Standard Library...
Definition: fbxalloc.h:190
xmlNode * DAE_ExportSource14(xmlNode *parentXmlNode, const char *id, FbxStringList &accessorParams, FbxArray< double > &arr, bool isCommonProfile=true)
void DAE_AddInput(xmlNode *parentXmlNode, const char *semantic, const char *source, int idx=-1)
SDK object manager.
Definition: fbxmanager.h:56
void DAE_AddInput14(xmlNode *parentXmlNode, const char *semantic, const char *source, int offset=-1, int set=-1)
FbxArray< xmlNode * > CNodeList
const FbxString ToString(const T &pValue)
DAE_Flow
void DAE_AddXYZAccessor(xmlNode *parentXmlNode, const char *profile, const char *arrayName, const char *arrayRef, int count)
bool FromString(T *pDest, const char *pSourceBegin, const char **pSourceEnd=((void *) 0))
Convert part of the source string into destination type.
#define NULL
Definition: fbxarch.h:210
Array that stores pairs of FbxString and a pointer.
Utility class to manipulate strings.
Definition: fbxstring.h:66
void DAE_AddNotificationWarning(const FbxManager *pSdkManger, const FbxString &pWarningMessage)
Emit warning message.
void DAE_AddXYZAccessor14(xmlNode *parentXmlNode, const char *profile, const char *arrayName, const char *arrayRef, int count)
ColladaLayerTraits(FbxLayerElement::EType pType, int pLength)
void DAE_GetElementContent(xmlNode *pElement, TYPE &pData)
Get the content of a XML element.
void DAE_GetElementTag(xmlNode *pElement, FbxString &pTag)
Get the tag of the specific element.
Type * Get() const
Retrieve the pointer it holds.
Definition: fbxalloc.h:200
Class to represent colors in RGBA format using doubles.
void DAE_AddNotificationError(const FbxManager *pSdkManger, const FbxString &pErrorMessage)
Emit error message.
double centimetersToInches(double val)
const FbxString DAE_GetIDFromUrlAttribute(xmlNode *pElement)
Get the ID of another element from the url attribute of the given element.
const FbxSystemUnit DAE_ImportUnit(xmlNode *pUnitElement)
Import a COLLADA unit element into a FBX system unit.
xmlNode * DAE_GetSourceWithSemantic(xmlNode *pConsumerElement, const char *pSemantic, const SourceElementMapType &pSourceElements)
Get the COLLADA source element with a semantic meaning and a consumer element; The COLLADA input elem...
bool DAE_CompareAttributeValue(xmlNode *pElement, const char *pAttributeName, const char *pValue)
Compare the value of specific attribute of specific element with given value.
xmlNode * DAE_ExportAccessor14(xmlNode *parentXmlNode, const char *id, const char *arrayRef, int count, int stride, const char *name, const char *type)
float FbxFloor(const float x)
Definition: fbxmath.h:134
xmlNode * DAE_AddChildElement(xmlNode *pParentElement, const char *pTag, const T &pContent)
Add a child element with specific content.
FbxAutoPtr< xmlNode, XmlNodeDeletionPolicy > XmlNodePtr
void DAE_SetName(FbxObject *pObject, const FbxString &pName, const FbxString &pID)
Set the name of the object with a given name.
This class implements an efficient map based on key comparison, which stores key-value pairs...
Definition: fbxmap.h:68
double radiansToDegrees(double val)
void RecursiveSearchElement(xmlNode *pBaseElement, const char *pTag, FbxArray< xmlNode * > &pResult)
Search the elements with given tag, push the found results to the end of the given array...
xmlNode * DAE_FindChildElementByAttribute(xmlNode *pParentElement, const char *pAttributeName, const char *pAttributeValue, const char *pDefaultAttributeValue="")
Find a child element with a given attribute value.
void DAE_ExportArray(xmlNode *parentXmlNode, const char *id, FbxArray< FbxVector4 > &arr)
The base class of most FBX objects.
Definition: fbxobject.h:157
#define RADIANS_TO_DEGREES
const FbxString DAE_GetIDFromTargetAttribute(xmlNode *pElement)
Get the ID of another element from the target attribute of the given element.
FbxLayerElement::EType mLayerType
xmlNode * DAE_NewElement(const char *pTag)
Represents an element in the scene graph.
Definition: fbxnode.h:72
xmlNode * getTechniqueNode(xmlNode *parent, const char *profile)
void DAE_AddFlow(xmlNode *node, DAE_Flow flow)
This class implements an efficient set based on value comparison, which stores values.
Definition: fbxset.h:25
char * Buffer()
Non-const buffer access.
const FbxString DAE_GetIDFromSourceAttribute(xmlNode *pElement)
Get the ID of another element from the source attribute of the given element.
void DAE_ExportSourceArray(xmlNode *sourceNode, const char *id, FbxArray< FbxColor > &arr)
EType
Layer Element type identifier.
Definition: fbxlayer.h:75
Scoped pointer for FbxMalloc allocations, which call FbxFree() to deallocate.
Definition: fbxalloc.h:253
xmlNode * getSourceAccessor(xmlNode *sourceNode)
#define CENTIMETERS_TO_INCHES
A four double mathematic vector class.
Definition: fbxvector4.h:25
bool DAE_CheckCompatibility(xmlNode *pNodeElement)
Check whether this node is compatible to FBX transform structure.
xmlNode * DAE_AddParameter(xmlNode *parentXmlNode, const char *name, const FbxColor &color, DAE_Flow flow)
FBX SDK affine matrix class.
void DAE_AddSTAccessor14(xmlNode *parentXmlNode, const char *profile, const char *arrayName, const char *arrayRef, int count)
void DAE_ExportSourceArray14(xmlNode *sourceNode, const char *id, FbxArray< FbxColor > &arr)
This class describes the units of measurement used within a particular scene.
Definition: fbxsystemunit.h:31
xmlNode * DAE_AddTechnique(xmlNode *parentXmlNode, const char *technique)
const FbxString DAE_GetElementAttributeValue(xmlNode *pElement, const char *pAttributeName)
Get the value of an attribute of an element.
static const ColladaLayerTraits GetLayerTraits(const FbxString &pLabel)
Construct traits according to COLLADA layer string.
FbxMap< FbxString, xmlNode * > SkinMapType
const int VECTOR_STRIDE
double inchesToCentimeters(double val)
void DAE_AddSTAccessor(xmlNode *parentXmlNode, const char *profile, const char *arrayName, const char *arrayRef, int count)
double degreesToRadians(double val)
void IncreaseLclTranslationAnimation(FbxNode *pNode, FbxDouble3 &pOffset)
If the specific node has animation on its local translation, increase every key by the offset...
void findChildrenByType(xmlNode *pParentElement, const FbxSet< FbxString > &pTypes, CNodeList &pChildrenElements)
Find children elements whose type is included in a list of type.
Base class for elements of layers (FbxLayer).
Definition: fbxlayer.h:38
const int MATRIX_STRIDE
Class for array of basic elements such as pointers and basic types.
Definition: fbxarray.h:23
static void DeleteIt(xmlNode **ptr)
xmlAttr * DAE_AddAttribute(xmlNode *pElement, const FbxString &pAttributeName, const T &pAttributeValue)
Add an attribute for a element.
FbxString matrixToString(const FbxAMatrix &mx)
xmlNode * DAE_FindChildElementByTag(xmlNode *pParentElement, const char *pTag, xmlNode *pFindFrom=((void *) 0))
Find a child element with a given tag.