fbxreadercollada14.h

Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2012 Autodesk, Inc.
00004    All rights reserved.
00005  
00006    Use of this software is subject to the terms of the Autodesk license agreement
00007    provided at the time of installation or download, or which otherwise accompanies
00008    this software in either electronic or hard copy form.
00009  
00010 ****************************************************************************************/
00011 
00013 #ifndef _FBXSDK_FILEIO_COLLADA_READER_H_
00014 #define _FBXSDK_FILEIO_COLLADA_READER_H_
00015 
00016 #include "fbxcolladautils.h"
00017 #include "fbxcolladanamespace.h"
00018 
00019 #include <fbxsdk/fbxsdk_nsbegin.h>
00020 
00021 class FbxAnimLayer;
00022 
00052 class FbxReaderCollada : public FbxReader 
00053 {
00054 public:
00059 
00064     FbxReaderCollada(FbxManager& pManager, int pID); 
00065     
00067     virtual ~FbxReaderCollada();
00068     
00070 
00075     
00080     virtual bool FileOpen(char* pFileName);
00081     
00085     virtual bool FileClose();
00086 
00090     virtual bool IsFileOpen();
00091     
00093 
00098 
00103     virtual bool GetReadOptions(bool pParseFileAsNeeded = true){ return true; }
00104 
00110     virtual bool GetAxisInfo(FbxAxisSystem* pAxisSystem, FbxSystemUnit* pSystemUnits);
00111 
00115     virtual FbxArray<FbxTakeInfo*>* GetTakeInfo();
00116 
00121     virtual bool Read(FbxDocument* pDocument);
00122 
00124 
00126     //
00127     //  WARNING!
00128     //
00129     //  Anything beyond these lines may not be documented accurately and is 
00130     //  subject to change without notice.
00131     //
00133 
00134 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00135 
00136 private:
00137 
00142 
00148     bool ReadCollada(FbxScene &pScene, xmlNode* pXmlNode);
00149 
00155     bool ImportVisualScene(xmlNode* pXmlNode, FbxScene * pScene);
00156 
00162     bool ImportVisualSceneMax3DExtension(xmlNode * pTechniqueElement, FbxScene * pScene);
00163 
00169     bool ImportVisualSceneFCOLLADAExtension(xmlNode * pTechniqueElement, FbxScene * pScene);
00170 
00176     bool ImportVisualSceneMayaExtension(xmlNode * pTechniqueElement, FbxScene * pScene);
00177 
00186     bool ImportAsset(xmlNode* pXmlNode, FbxGlobalSettings & pGlobalSettings, FbxDocumentInfo &pSceneInfo);
00187 
00195     FbxNode * ImportNode(xmlNode* pXmlNode);
00196 
00202     bool ImportNodeFCOLLADAExtension(xmlNode* pTechniqueElement, FbxNode * pNode);
00203 
00209     bool ImportNodeXSIExtension(xmlNode* pTechniqueElement, FbxNode * pNode);
00210 
00216     bool ImportNodeFBXExtension(xmlNode* pTechniqueElement, FbxNode * pNode);
00217 
00224     FbxGeometry * ImportGeometry(const FbxString & pGeometryID, const FbxDynamicArray<FbxString> & pMaterialSequence);
00225 
00230     bool ImportSkin(xmlNode* pSkinElement);
00231 
00237     FbxGeometry * ImportMorph(xmlNode * pMorphElement, const FbxDynamicArray<FbxString> & pMaterialSequence);
00238 
00244     FbxGeometry * ImportController(const FbxString & pControllerID, const FbxDynamicArray<FbxString> & pMaterialSequence);
00245 
00251     FbxCamera * ImportCamera(xmlNode* pXmlNode);
00252 
00258     FbxLight * ImportLight(xmlNode* pXmlNode);
00259 
00264     FbxSurfaceMaterial * ImportMaterial(xmlNode* pXmlNode);
00265 
00270     FbxSurfaceMaterial * ImportEffect(xmlNode* pEffectElement);
00271 
00277     FbxSurfaceMaterial * ImportEffectNVidiaExtension(xmlNode * pEffectElement);
00278 
00284     FbxFileTexture * ImportTexture(xmlNode* pXmlNode);
00285 
00290     FbxFileTexture * ImportImage(xmlNode* pXmlNode);
00291 
00299     FbxGeometry * ImportMesh(xmlNode* pXmlNode, const FbxDynamicArray<FbxString> & pMaterialSequence);
00300 
00307     bool ImportVertices(xmlNode* pVerticesElement, FbxGeometry * pGeometry);
00308 
00316     bool ImportPolygons(xmlNode* pXmlNode, FbxMesh& pMesh, const FbxDynamicArray<FbxString> & pMaterialSequence);
00317 
00324     bool ImportTransforms(xmlNode* pXmlNode, FbxNode* pNode);
00325 
00331     int ImportRotationElement(xmlNode* pXmlNode, FbxVector4& pRotationVector);
00332 
00337     void SetRotationOrder(FbxNode * pNode, const std::vector<int> & pRotationOrder);
00338 
00348     bool ImportLookAt(xmlNode* pXmlNode, FbxVector4& lCameraPosition, 
00349                                          FbxVector4& lInterestPosition, FbxVector4& lUpVector,
00350                                          FbxAMatrix& lCameraTransformMatrix);
00351 
00353 
00354 
00359     
00366     bool IsNodeExportable(FbxString lId);
00367     
00372     bool CheckColladaVersion(const FbxString & pVersionString);
00373 
00375 
00376 
00381 
00385     void AddNotificationError( FbxString pError );
00386 
00390     void AddNotificationWarning( FbxString pWarning );
00392 
00393 private:
00399     bool ImportScene(xmlNode * pColladaNode);
00400 
00404     void Preprocess(xmlNode * pColladaElement);
00405 
00408     void BuildUpLibraryMap();
00409 
00414     void BuildUpLibraryMap(xmlNode * pElement, const FbxString & pElementTag);
00415 
00423     bool ConnectMaterialsToNode(FbxNode * pNode, xmlNode * pElement, FbxDynamicArray<FbxString> & pMaterialSequence);
00424 
00430     bool ImportTransparent(xmlNode * pElement, FbxSurfaceLambert * pSurfaceMaterial);
00431 
00432     // Some traits with a typed element.
00433     struct LibraryTypeTraits
00434     {
00435         FbxString library_tag;
00436         FbxString element_tag;
00437     };
00438 
00444     FbxObject * GetLibrary(const LibraryTypeTraits & pTypeTraits, const FbxString & pID);
00445     FbxObject * GetLibrary(const LibraryTypeTraits & pTypeTraits, xmlNode * pElement);
00446 
00452     bool ImportMatrixAnimation(FbxNode * pNode, const FbxString & pAnimationChannelID);
00453 
00460     bool ImportPropertyAnimation(FbxProperty & pProperty, const FbxString & pAnimationChannelID, const char * pChannelName = NULL);
00461 
00466     FbxAnimLayer * GetAnimLayer(const FbxString & pAnimationID);
00467 
00472     double GetLocalUnitConversion(xmlNode * pElement);
00473 
00478     void SetProperty(xmlNode* pPropertyElement, FbxProperty & pProperty);
00479 
00485     void ImportPropertyValue(FbxObject * pObject, const char * pPropertyName,
00486                              xmlNode * pPropertyValueElement);
00487 
00488 private:
00489     FbxFile*               mFileObject;
00490     FbxString                 mFileName;
00491 
00492     // XML lib stuff
00493     xmlDocPtr               mXmlDoc;
00494 
00495     FbxAnimLayer* mAnimLayer;
00496     FbxScene * mScene;
00497 
00498     // Save the global settings and document info in pre-reading
00499     FbxGlobalSettings * mGlobalSettings;
00500     FbxDocumentInfo * mDocumentInfo;
00501     FbxArray<FbxTakeInfo*> mTakeInfo;
00502 
00503     xmlNode * mColladaElement;
00504 
00505     struct ColladaElementData
00506     {
00507         explicit ColladaElementData(xmlNode * pElement = NULL)
00508             : mColladaElement(pElement), mFBXObject(NULL) {}
00509         xmlNode * mColladaElement;
00510         FbxObject * mFBXObject;
00511     };
00512     typedef std::map<FbxString, ColladaElementData> ColladaElementMapType;
00513     ColladaElementMapType mColladaElements;
00514 
00515     LibraryTypeTraits mEffectTypeTraits;
00516     LibraryTypeTraits mMaterialTypeTraits;
00517     LibraryTypeTraits mImageTypeTraits;
00518     LibraryTypeTraits mGeometryTypeTraits;
00519     LibraryTypeTraits mControllerTypeTraits;
00520     LibraryTypeTraits mLightTypeTraits;
00521     LibraryTypeTraits mCameraTypeTraits;
00522     LibraryTypeTraits mNodeTypeTraits;
00523     LibraryTypeTraits mAnimationTypeTraits;
00524 
00525     typedef std::map< FbxString, std::vector<xmlNode*> > AnimationMapType;
00526     AnimationMapType mAnimationElements;
00527 
00528     typedef std::map< FbxString, xmlNode* > SourceElementMapType;
00529     SourceElementMapType mSourceElements;
00530 
00531     struct AnimationClipData
00532     {
00533         AnimationClipData(const FbxString & pID) : mID(pID), mAnimLayer(NULL) {}
00534 
00535         FbxString mID;                                // ID of animation clip
00536         std::set<FbxString> mAnimationElementIDs;     // IDs of animation belong to this animation clip
00537         FbxAnimLayer * mAnimLayer;                 // The corresponding animation layer
00538     };
00539     std::vector<AnimationClipData> mAnimationClipData;
00540 
00541     // Map from skin ID to skin element.
00542     typedef std::map<FbxString, xmlNode *> SkinMapType;
00543     SkinMapType mSkinElements;
00544 
00545     // There are two distinct namespaces for node ID & SID mapping.
00546     // One with ID and the other with SID.
00547     typedef std::map<FbxString, FbxNode *> NodeMapType;
00548     NodeMapType mIDNamespaceNodes;
00549     NodeMapType mSIDNamespaceNodes;
00550 
00551     // Record the nodes which are to connect to its target node.
00552     // Save the ID of the target node if a node has its target
00553     std::map<FbxNode *, FbxString> mTargetIDs;
00554 
00555     FbxColladaNamespace mNamespace;
00556 
00557 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00558 };
00559 
00560 #include <fbxsdk/fbxsdk_nsend.h>
00561 
00562 #endif /* _FBXSDK_FILEIO_COLLADA_READER_H_ */