00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013 #ifndef _FBXSDK_FILEIO_COLLADA_UTILS_H_
00014 #define _FBXSDK_FILEIO_COLLADA_UTILS_H_
00015
00016 #include <map>
00017 #include <set>
00018 #include <vector>
00019
00020 #include <fbxsdk.h>
00021
00022 #include <components/libxml2-2.7.8/include/libxml/globals.h>
00023
00024 #include "fbxcolladatokens.h"
00025 #include "fbxcolladaiostream.h"
00026
00027 #include <fbxsdk/fbxsdk_nsbegin.h>
00028
00029 #ifndef INT_MAX
00030 #define INT_MAX 0x7FFFFFFF
00031 #endif
00032
00033 #ifndef CENTIMETERS_TO_INCHES
00034 #define CENTIMETERS_TO_INCHES 2.54f
00035 #endif
00036
00037 #ifndef RADIANS_TO_DEGREES
00038 #define RADIANS_TO_DEGREES 57.295799f
00039 #endif
00040
00041 enum DAE_Flow { kCOLLADAFlowIn, kCOLLADAFlowOut, kCOLLADAFlowInOut };
00042
00043 const int MATRIX_STRIDE = 16;
00044 const int VECTOR_STRIDE = 3;
00045
00046 const FbxString COLLADA_ID_PROPERTY_NAME = "COLLADA_ID";
00047
00048 class XmlNodeDeletionPolicy
00049 {
00050 public:
00051 static inline void DeleteIt(xmlNode ** ptr)
00052 {
00053 if (*ptr != NULL)
00054 {
00055 xmlFreeNode(*ptr);
00056 *ptr = NULL;
00057 }
00058 }
00059 };
00060
00061 typedef FbxScopedPtr<xmlNode, XmlNodeDeletionPolicy> XmlNodePtr;
00062
00063
00064 struct ColladaLayerTraits
00065 {
00066 ColladaLayerTraits()
00067 : mLayerType(FbxLayerElement::eUnknown), mLayerElementLength(0) {}
00068
00069 ColladaLayerTraits(FbxLayerElement::EType pType, int pLength)
00070 : mLayerType(pType), mLayerElementLength(pLength) {}
00071
00072
00073 FbxLayerElement::EType mLayerType;
00074
00075 int mLayerElementLength;
00076
00081 static const ColladaLayerTraits GetLayerTraits(const FbxString & pLabel);
00082 };
00083
00088 void DAE_AddNotificationError(const FbxManager * pSdkManger, const FbxString & pErrorMessage);
00089
00094 void DAE_AddNotificationWarning(const FbxManager * pSdkManger, const FbxString & pWarningMessage);
00095
00096 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector4>& arr);
00097 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector2>& arr);
00098 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<FbxColor>& arr);
00099 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxArray<double>& arr);
00100 void DAE_ExportArray(xmlNode* parentXmlNode, const char* id, FbxStringList& arr);
00101
00102
00103 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxStringList& accessorParams, FbxArray<double>& arr, bool isCommonProfile=true);
00104 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector4>& arr);
00105 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxVector2>& arr);
00106 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxColor>& arr);
00107 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxAMatrix>& arr);
00108 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxArray<FbxMatrix>& arr);
00109 xmlNode* DAE_ExportSource14(xmlNode* parentXmlNode, const char* id, FbxStringList& arr, const char* type, bool isCommonProfile=true);
00110
00111
00112 void DAE_ExportSourceArray(xmlNode* sourceNode, const char* id, FbxArray<FbxColor>& arr);
00113 void DAE_ExportSourceArray14(xmlNode* sourceNode, const char* id, FbxArray<FbxColor>& arr);
00114
00115 xmlNode* DAE_ExportAccessor(xmlNode* parentXmlNode, const char* id, const char* arrayRef, int count, int stride, const char* name, const char* type);
00116 xmlNode* DAE_ExportAccessor14(xmlNode* parentXmlNode, const char* id, const char* arrayRef, int count, int stride, const char* name, const char* type);
00117
00118 void DAE_AddXYZAccessor(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
00119 void DAE_AddSTAccessor(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
00120 void DAE_AddFlow(xmlNode* node, DAE_Flow flow);
00121 void DAE_AddXYZAccessor14(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
00122 void DAE_AddSTAccessor14(xmlNode* parentXmlNode, const char* profile, const char* arrayName, const char* arrayRef, int count);
00123
00124
00125 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxColor& color, DAE_Flow flow);
00126 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxVector4& vector, DAE_Flow flow);
00127 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, double value, DAE_Flow flow);
00128 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, bool value, DAE_Flow flow);
00129 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const char* type, const char* value, DAE_Flow flow);
00130
00131
00132 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxDouble3& color);
00133 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxColor& color);
00134 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const FbxVector4& vector);
00135 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, double value);
00136 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, bool value);
00137 xmlNode* DAE_AddParameter(xmlNode* parentXmlNode, const char* name, const char* type, const char* value);
00138 xmlNode* DAE_AddTechnique(xmlNode* parentXmlNode, const char* technique);
00139 void DAE_AddInput(xmlNode* parentXmlNode, const char* semantic, const char* source, int idx = -1);
00140 void DAE_AddInput14(xmlNode* parentXmlNode, const char* semantic, const char* source, int offset = -1, int set=-1);
00141
00142 FbxString matrixToString(const FbxAMatrix& mx);
00143
00144 typedef FbxArray<xmlNode*> CNodeList;
00145
00151 void findChildrenByType(xmlNode* pParentElement, const std::set<FbxString>& pTypes, CNodeList& pChildrenElements);
00152
00158 void findChildrenByType(xmlNode* pParentElement, const char * pType, CNodeList& pChildrenElements);
00159
00160 xmlNode* getSourceAccessor(xmlNode* sourceNode);
00161 xmlNode* getTechniqueNode(xmlNode* parent, const char * profile);
00162
00163
00164 inline double inchesToCentimeters(double val) { return floor(val / CENTIMETERS_TO_INCHES * 100000) / 100000; }
00165 inline double centimetersToInches(double val) { return floor(val * CENTIMETERS_TO_INCHES * 100000) / 100000; }
00166
00167 inline double degreesToRadians(double val) { return floor(val / RADIANS_TO_DEGREES * 100000) / 100000; }
00168 inline double radiansToDegrees(double val) { return floor(val * RADIANS_TO_DEGREES * 100000) / 100000; }
00169
00177 xmlNode* DAE_FindChildElementByAttribute(xmlNode* pParentElement, const char * pAttributeName,
00178 const char * pAttributeValue, const char * pDefaultAttributeValue = "");
00179
00186 xmlNode* DAE_FindChildElementByTag(xmlNode* pParentElement, const char * pTag, xmlNode* pFindFrom = NULL);
00187
00193 template <typename TYPE>
00194 void DAE_GetElementContent(xmlNode * pElement, TYPE & pData)
00195 {
00196 if (pElement != NULL)
00197 {
00198 xmlChar* lContent = xmlNodeGetContent(pElement);
00199 FromString(&pData, (const char *)lContent);
00200 FbxFree(lContent);
00201 }
00202 }
00203
00208 bool DAE_CheckCompatibility(xmlNode * pNodeElement);
00209
00214 void DAE_GetElementTag(xmlNode * pElement, FbxString & pTag);
00215
00221 const FbxString DAE_GetElementAttributeValue(xmlNode * pElement, const char * pAttributeName);
00222
00229 template <typename TYPE>
00230 bool DAE_GetElementAttributeValue(xmlNode * pElement, const char * pAttributeName, TYPE & pData)
00231 {
00232 if (!pElement || !pAttributeName)
00233 return false;
00234
00235 xmlChar * lPropertyValue = xmlGetProp(pElement, (const xmlChar *)pAttributeName);
00236 if (lPropertyValue)
00237 {
00238 FromString(&pData, (const char *)lPropertyValue);
00239 FbxFree(lPropertyValue);
00240 return true;
00241 }
00242 return false;
00243 }
00244
00245
00246
00247 template <>
00248 inline bool DAE_GetElementAttributeValue(xmlNode * pElement,
00249 const char * pAttributeName,
00250 FbxString & pData)
00251 {
00252 if (!pElement || !pAttributeName)
00253 return false;
00254
00255 xmlChar * lPropertyValue = xmlGetProp(pElement,
00256 (const xmlChar *)pAttributeName);
00257 if (lPropertyValue)
00258 {
00259 pData = (const char *)lPropertyValue;
00260 FbxFree(lPropertyValue);
00261 return true;
00262 }
00263 return false;
00264 }
00265
00272 bool DAE_CompareAttributeValue(xmlNode * pElement,
00273 const char * pAttributeName,
00274 const char * pValue);
00275
00280 const FbxString DAE_GetIDFromUrlAttribute(xmlNode * pElement);
00281
00286 const FbxString DAE_GetIDFromSourceAttribute(xmlNode * pElement);
00287
00293 const FbxString DAE_GetIDFromTargetAttribute(xmlNode * pElement);
00294
00300 void DAE_SetName(FbxObject * pObject, const FbxString & pName, const FbxString & pID);
00301
00310 xmlNode * DAE_GetSourceWithSemantic(xmlNode * pConsumerElement, const char * pSemantic,
00311 const std::map< FbxString, xmlNode* > & pSourceElements);
00312
00319 template <typename T>
00320 xmlNode * DAE_AddChildElement(xmlNode * pParentElement, const char * pTag,
00321 const T & pContent)
00322 {
00323 const FbxString lRepr = ToString(pContent);
00324 return xmlNewChild(pParentElement, NULL, (xmlChar *)pTag,
00325 (xmlChar *)lRepr.Buffer());
00326 }
00327
00328
00329 inline xmlNode * DAE_AddChildElement(xmlNode * pParentElement, const char * pTag)
00330 {
00331 return DAE_AddChildElement(pParentElement, pTag, FbxString());
00332 }
00333
00334
00335 inline xmlNode * DAE_NewElement(const char * pTag)
00336 {
00337 return xmlNewNode(NULL, reinterpret_cast<xmlChar*>(const_cast<char *>(pTag)));
00338 }
00339
00346 template <typename T>
00347 xmlAttr * DAE_AddAttribute(xmlNode * pElement, const FbxString & pAttributeName,
00348 const T & pAttributeValue)
00349 {
00350 const FbxString lRepr = ToString(pAttributeValue);
00351 return xmlNewProp(pElement, (xmlChar *)pAttributeName.Buffer(),
00352 (xmlChar *)lRepr.Buffer());
00353 }
00354
00359 const FbxSystemUnit DAE_ImportUnit(xmlNode * pUnitElement);
00360
00365 void IncreaseLclTranslationAnimation(FbxNode * pNode, FbxDouble3 & pOffset);
00366
00372 void RecursiveSearchElement(xmlNode * pBaseElement, const char * pTag, FbxArray<xmlNode*> & pResult);
00373
00374 #include <fbxsdk/fbxsdk_nsend.h>
00375
00376 #endif