FBX C++ API Reference
fbxcolladautils.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2017 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 #include <fbxsdk/scene/fbxscene.h>
23 
24 #include <components/libxml2-2.7.8/include/libxml/globals.h>
25 
26 #include <fbxsdk/fbxsdk_nsbegin.h>
27 
29 {
30 public:
32  virtual ~FbxRenamingStrategyCollada();
33 
34  virtual void CleanUp();
35  virtual bool DecodeScene(FbxScene* pScene);
36  virtual bool EncodeScene(FbxScene* pScene);
37  virtual bool DecodeString(FbxNameHandler& pName);
38  virtual bool EncodeString(FbxNameHandler& pName, bool pIsPropertyName = false);
39 };
40 
41 
42 #ifndef INT_MAX
43  #define INT_MAX 0x7FFFFFFF
44 #endif
45 
46 #ifndef CENTIMETERS_TO_INCHES
47  #define CENTIMETERS_TO_INCHES 2.54f
48 #endif
49 
50 #ifndef RADIANS_TO_DEGREES
51  #define RADIANS_TO_DEGREES 57.295799f
52 #endif
53 
55 
56 const int MATRIX_STRIDE = 16;
57 const int VECTOR_STRIDE = 3;
58 
59 #define COLLADA_ID_PROPERTY_NAME "COLLADA_ID"
60 
62 {
63 public:
64  static inline void DeleteIt(xmlNode ** ptr)
65  {
66  if (*ptr != NULL)
67  {
68  xmlFreeNode(*ptr);
69  *ptr = NULL;
70  }
71  }
72 };
73 
77 
78 // Some information connecting COLLADA layer string, such as "NORMAL" or "UV", to FBX layer element type.
80 {
82  : mLayerType(FbxLayerElement::eUnknown), mLayerElementLength(0) {}
83 
85  : mLayerType(pType), mLayerElementLength(pLength) {}
86 
87  // Type of FBX element layer
89  // Count of double of each element in FBX element layer
91 
96  static const ColladaLayerTraits GetLayerTraits(const FbxString & pLabel);
97 };
98 
103 void DAE_AddNotificationError(const FbxManager * pSdkManger, const FbxString & pErrorMessage);
104 
109 void DAE_AddNotificationWarning(const FbxManager * pSdkManger, const FbxString & pWarningMessage);
110 
111 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector4>& arr);
112 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector2>& arr);
113 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxColor>& arr);
114 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<double>& arr);
115 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxStringList& arr);
116 
117 // Syntax modification - for COLLADA 1.4
118 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxStringList& accessorParams, FbxArray<double>& arr, bool isCommonProfile=true);
119 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector4>& arr);
120 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector2>& arr);
121 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxColor>& arr);
122 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxAMatrix>& arr);
123 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxMatrix>& arr);
124 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxStringList& arr, const char* type, bool isCommonProfile=true);
125 
126 
127 void DAE_ExportSourceArray(xmlNode* sourceNode, const char* id, FbxArray<FbxColor>& arr);
128 void DAE_ExportSourceArray14(xmlNode* sourceNode, const char* id, FbxArray<FbxColor>& arr);
129 
130 xmlNode* DAE_ExportAccessor(xmlNode* parentXmlNode, const char* id, const char* arrayRef, int count, int stride, const char* name, const char* type);
131 xmlNode* DAE_ExportAccessor14(xmlNode* parentXmlNode, const char* id, const char* arrayRef, int count, int stride, const char* name, const char* type);
132 
133 void DAE_AddXYZAccessor(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
134 void DAE_AddSTAccessor(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
135 void DAE_AddFlow(xmlNode* node, DAE_Flow flow);
136 void DAE_AddXYZAccessor14(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
137 void DAE_AddSTAccessor14(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
138 
139 // AddParameter functions for COLLADA 1.3.
140 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxColor& color, DAE_Flow flow);
141 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxVector4& vector, DAE_Flow flow);
142 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, double value, DAE_Flow flow);
143 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, bool value, DAE_Flow flow);
144 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const char* type, const char* value, DAE_Flow flow);
145 
146 // Overload functions without DAE_Flow, for COLLADA 1.4.
147 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxDouble3& color);
148 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxColor& color);
149 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxVector4& vector);
150 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, double value);
151 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, bool value);
152 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const char* type, const char* value);
153 xmlNode* DAE_AddTechnique(xmlNode* parentXmlNode, const char* technique);
154 void DAE_AddInput(xmlNode* parentXmlNode, const char* semantic, const char* source, int idx = -1);
155 void DAE_AddInput14(xmlNode* parentXmlNode, const char* semantic, const char* source, int offset = -1, int set=-1);
156 
158 
160 
166 void findChildrenByType(xmlNode* pParentElement, const FbxSet<FbxString>& pTypes, CNodeList& pChildrenElements);
167 
173 void findChildrenByType(xmlNode* pParentElement, const char * pType, CNodeList& pChildrenElements);
174 
175 xmlNode* getSourceAccessor(xmlNode* sourceNode);
176 xmlNode* getTechniqueNode(xmlNode* parent, const char * profile);
177 
178 // Conversions
179 inline double inchesToCentimeters(double val) { return FbxFloor(val / CENTIMETERS_TO_INCHES * 100000) / 100000; }
180 inline double centimetersToInches(double val) { return FbxFloor(val * CENTIMETERS_TO_INCHES * 100000) / 100000; }
181 
182 inline double degreesToRadians(double val) { return FbxFloor(val / RADIANS_TO_DEGREES * 100000) / 100000; }
183 inline double radiansToDegrees(double val) { return FbxFloor(val * RADIANS_TO_DEGREES * 100000) / 100000; }
184 
192 xmlNode* DAE_FindChildElementByAttribute(xmlNode* pParentElement, const char * pAttributeName,
193  const char * pAttributeValue, const char * pDefaultAttributeValue = "");
194 
201 xmlNode* DAE_FindChildElementByTag(xmlNode* pParentElement, const char * pTag, xmlNode* pFindFrom = NULL);
202 
207 template <typename TYPE>
208 void DAE_GetElementContent(xmlNode * pElement, TYPE & pData)
209 {
210  if (pElement != NULL)
211  {
212  FbxAutoFreePtr<xmlChar> lContent(xmlNodeGetContent(pElement));
213  FromString(&pData, (const char *)lContent.Get());
214  }
215 }
216 
221 bool DAE_CheckCompatibility(xmlNode * pNodeElement);
222 
227 void DAE_GetElementTag(xmlNode * pElement, FbxString & pTag);
228 
234 const FbxString DAE_GetElementAttributeValue(xmlNode * pElement, const char * pAttributeName);
235 
242 template <typename TYPE>
243 bool DAE_GetElementAttributeValue(xmlNode * pElement, const char * pAttributeName, TYPE & pData)
244 {
245  if (!pElement || !pAttributeName)
246  return false;
247 
248  FbxAutoFreePtr<xmlChar> lPropertyValue(xmlGetProp(pElement, (const xmlChar *)pAttributeName));
249  if (lPropertyValue)
250  {
251  FromString(&pData, (const char *)lPropertyValue.Get());
252  return true;
253  }
254  return false;
255 }
256 
257 // Special instantiation for string;
258 // Omit the whitespaces, just return the whole string
259 template <>
260 inline bool DAE_GetElementAttributeValue(xmlNode * pElement,
261  const char * pAttributeName,
262  FbxString & pData)
263 {
264  if (!pElement || !pAttributeName)
265  return false;
266 
267  FbxAutoFreePtr<xmlChar> lPropertyValue(xmlGetProp(pElement, (const xmlChar *)pAttributeName));
268  if (lPropertyValue)
269  {
270  pData = (const char *)lPropertyValue.Get();
271  return true;
272  }
273  return false;
274 }
275 
282 bool DAE_CompareAttributeValue(xmlNode * pElement,
283  const char * pAttributeName,
284  const char * pValue);
285 
291 const FbxString DAE_GetIDFromUrlAttribute(xmlNode * pElement, FbxString& pExternalRef);
292 
297 const FbxString DAE_GetIDFromSourceAttribute(xmlNode * pElement);
298 
304 const FbxString DAE_GetIDFromTargetAttribute(xmlNode * pElement);
305 
311 void DAE_SetName(FbxObject * pObject, const FbxString & pName, const FbxString & pID);
312 
322 xmlNode * DAE_GetSourceWithSemantic(xmlNode * pConsumerElement, const char * pSemantic,
323  const SourceElementMapType & pSourceElements);
324 
331 template <typename T>
332 xmlNode * DAE_AddChildElement(xmlNode * pParentElement, const char * pTag,
333  const T & pContent)
334 {
335  const FbxString lRepr = ToString(pContent);
336  return xmlNewChild(pParentElement, NULL, (xmlChar *)pTag,
337  (xmlChar *)lRepr.Buffer());
338 }
339 
340 // Create a child element with empty content.
341 inline xmlNode * DAE_AddChildElement(xmlNode * pParentElement, const char * pTag)
342 {
343  return DAE_AddChildElement(pParentElement, pTag, FbxString());
344 }
345 
346 // Create a new element with empty content.
347 inline xmlNode * DAE_NewElement(const char * pTag)
348 {
349  return xmlNewNode(NULL, reinterpret_cast<xmlChar*>(const_cast<char *>(pTag)));
350 }
351 
358 template <typename T>
359 xmlAttr * DAE_AddAttribute(xmlNode * pElement, const FbxString & pAttributeName,
360  const T & pAttributeValue)
361 {
362  const FbxString lRepr = ToString(pAttributeValue);
363  return xmlNewProp(pElement, (xmlChar *)pAttributeName.Buffer(),
364  (xmlChar *)lRepr.Buffer());
365 }
366 
371 const FbxSystemUnit DAE_ImportUnit(xmlNode * pUnitElement);
372 
377 void IncreaseLclTranslationAnimation(FbxNode * pNode, FbxDouble3 & pOffset);
378 
384 void RecursiveSearchElement(xmlNode * pBaseElement, const char * pTag, FbxArray<xmlNode*> & pResult);
385 
386 #include <fbxsdk/fbxsdk_nsend.h>
387 
388 #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)
virtual bool DecodeString(FbxNameHandler &pString)=0
This method find the original name of a given string.
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)
Type * Get() const
Retrieve the pointer it holds.
Definition: fbxalloc.h:200
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.
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, FbxString &pExternalRef)
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)
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.
Base class for renaming strategy.
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)
This class contains the description of a 3D scene.
Definition: fbxscene.h:61
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)
virtual void CleanUp()
clean up the name cells.
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)
virtual bool EncodeString(FbxNameHandler &pString, bool pIsPropertyName=false)=0
This method find the renaming name of a given string.
#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.
#define FBXSDK_DLL
Definition: fbxarch.h:173
FbxMap< FbxString, xmlNode *> SkinMapType
A name is a case-sensitive string ID of a property, a node, a node attribute, a texture, etc.
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...
const int VECTOR_STRIDE
double inchesToCentimeters(double val)
void DAE_AddSTAccessor(xmlNode *parentXmlNode, const char *profile, const char *arrayName, const char *arrayRef, int count)
virtual bool EncodeScene(FbxScene *pScene)=0
This method renames all the names in the scene.
virtual bool DecodeScene(FbxScene *pScene)=0
This method put all the names in the scene back to the original values.
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.