Scene.h

00001 /****************************************************************************************
00002 THIS CODE IS PUBLISHED AS A SAMPLE ONLY AND IS PROVIDED "AS IS".
00003 IN NO EVENT SHALL SOFTIMAGE, AVID TECHNOLOGY, INC. AND/OR THEIR RESPECTIVE 
00004 SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00005 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00006 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00007 CONNECTION WITH THE USE OR PERFORMANCE OF THIS CODE . 
00008  
00009 COPYRIGHT NOTICE. Copyright © 1999-2002 Avid Technology Inc. . All rights reserved. 
00010 
00011 SOFTIMAGE is a registered trademark of Avid Technology Inc. or its subsidiaries 
00012 or divisions. Windows NT is a registered trademark of Microsoft Corp. All other
00013 trademarks contained herein are the property of their respective owners. 
00014 ****************************************************************************************/
00015 
00016 #ifndef _SCENE_H
00017 #define _SCENE_H
00018 
00019 #include "Template.h"
00020 #include "Logger.h"
00021 
00022 class CSLScene;
00023 class CSLModel;
00024 class CSLAmbience;
00025 class CSLAngle;
00026 class CSLCoordinateSystem;
00027 class CSLFileInfo;
00028 class CSLSceneInfo;
00029 class CSLEnvelopeList;
00030 class CSLMaterialLibrary;
00031 class CSLFog;
00032 class CSLActionFCurve;
00033 class CSLFCurve;
00034 class CSLTransform;
00035 class CSLAction;
00036 class CSLShapeAnimation;
00037 class CSLVisibility;
00038 class CSLXSIMaterial;
00039 class CSLImageLibrary;
00040 class CSLImage;
00041 class CSLXSIShader;
00042 
00048 class XSIEXPORT CSLUnresolvedElement
00049 {
00050 public:
00051     CSLUnresolvedElement
00052     ( 
00053         CSLTemplate *in_pUnresolvedObject,  
00054         CSLTemplate *in_pUnresolvedParent = 0,  
00055         SI_Char *in_pReferenceName = 0,
00056         void *in_pUserData = 0
00057     );
00058 
00062     inline CSLTemplate* UnresolvedObject();
00063 
00067     inline CSLTemplate* UnresolvedParent();
00068 
00072     inline SI_Char*  ReferenceName();
00073 
00077     inline void*         UserData();
00078 
00079 private:
00080     CSLTemplate *m_pUnresolvedObject;
00081     CSLTemplate *m_pUnresolvedParent;
00082     SI_Char *m_pReferenceName;
00083     void *m_pUserData;
00084 
00085     // This member is here to allow future improvement of the class.
00086     void *m_pReserved;
00087 };
00088 
00089 inline CSLTemplate* CSLUnresolvedElement::UnresolvedObject()
00090 {
00091     return m_pUnresolvedObject;
00092 }
00093 
00094 inline CSLTemplate* CSLUnresolvedElement::UnresolvedParent()
00095 {
00096     return m_pUnresolvedParent;
00097 }
00098 inline SI_Char* CSLUnresolvedElement::ReferenceName()
00099 {
00100     return m_pReferenceName;
00101 }
00102 
00103 inline void* CSLUnresolvedElement::UserData()
00104 {
00105     return m_pUserData;
00106 }
00107 
00108 #ifdef  FTK_KERNEL
00109 typedef std::multimap<SI_Char *, CSLUnresolvedElement, StrLessPred> CSLUnresolvedMap;
00110 typedef CSLUnresolvedMap::iterator CSLUnresolvedMapIterator;
00111 typedef std::pair<CSLUnresolvedMapIterator,CSLUnresolvedMapIterator> CSLUnresolvedMapRange;
00112 
00113 typedef SI_StrMap<CSLModel *> CSLModelMap;
00114 typedef CSLModelMap::iterator CSLModelMapIterator;
00115 #else
00116 typedef void CSLUnresolvedMap;
00117 typedef void CSLModelMap;
00118 #endif
00119 
00126 struct XSIEXPORT SLContext
00127 {
00128 public:
00129     SLContext();
00130     SI_Void AddOrphan(CSLTemplate *in_pOrphanTemplate); 
00132     CSLTemplate *m_pCurrentTemplate;                    
00133     CSLModel *m_pCurrentModel;                          
00134     CSLScene *m_pScene;                                 
00135     CSLMaterialLibrary *m_pMaterialLibrary;             
00136     CSLXSIMaterial *m_pCurrentMaterial;                 
00137     CSIBCArray<CSLTemplate *> *m_pOrphanList;           
00138     void *m_pTemplateUserData;                          
00139     CSLUnresolvedMap *m_pUnresolvedMap;                 
00140     CSLModelMap *m_pModelMap;                           
00141     CSLImageLibrary *m_pImageLibrary;                   
00142     CSLImage *m_pCurrentImage;                          
00143     CSLXSIShader *m_pCurrentXSIShader;                  
00144     void *m_pUserData;                                  
00146 private:
00147     // This member is here to allow future improvement of the class.
00148     void *m_pReserved;
00149 };
00150 
00151 typedef CSLTemplate *(*CSLCALLBACK) (CdotXSITemplate *in_pTemplate, SLContext *in_pContext);
00152 typedef SI_Error (*CSLPOSTCHILDRENCALLBACK) (CSLTemplate *in_pTemplate, SLContext *in_pContext);
00153 typedef SI_Error (*CSLLOADCALLBACK) (SLContext *in_pContext);
00154 
00171 class XSIEXPORT SLTemplateCallback
00172 {
00173 public: 
00174     SLTemplateCallback();
00175     void Clear();
00176 
00177     CSLLOADCALLBACK m_PreLoadCallback;
00178     CSLCALLBACK m_Callback;
00179     CSLPOSTCHILDRENCALLBACK m_PostChildrenCallback;
00180     CSLLOADCALLBACK m_PostLibraryCallback;
00181     CSLLOADCALLBACK m_PostLoadCallback;
00182 
00183     void *m_pUserData;
00184 
00185 private:
00186     // This member is here to allow future improvement of the class.
00187     void *m_pReserved;
00188 };
00189 
00197 class XSIEXPORT CSLScene
00198 {
00199 public:
00201     // Construction/destruction
00203     CSLScene();
00204     virtual ~CSLScene();
00205 
00207     // File manipulation functions.
00209 
00214     SI_Error Open(SI_Char *in_szFileName);
00215 
00222     SI_Error Open(SI_Char *in_szFileName, SI_READ_CALLBACK_FNC in_pFunc);
00223 
00231     SI_Error Create(SI_Char *in_szFileName, SI_Int in_nVersionMajor, SI_Int in_nVersionMinor, SI_Int in_nFormat = FORMAT_TEXT);
00232 
00239     SI_Error Create(SI_Int in_nVersionMajor, SI_Int in_nVersionMinor, SI_Int in_nFormat = FORMAT_TEXT);
00240 
00245     SI_Error Open(CXSIParser * in_parser);
00249     SI_Error Read();
00250 
00254     virtual SI_Error Write();
00255 
00260     virtual SI_Error Write(SI_Char* in_szFileName);
00261 
00265     SI_Error Close();
00266 
00271     CSLModel*           FindModel(SI_Char* in_szModelName);
00272 
00278     CSLModel*           FindModelRecursively(SI_Char* in_szModelName, CSLModel* in_pModel);
00279 
00287     CSLAnimatableType*  FindParameter(SI_Char* in_szParameterName);
00288 
00294     SI_Error            GetValue(SI_Char* in_szParameterName, SI_Float* out_pfValue);
00295 
00301     SI_Error            SetValue(SI_Char* in_szParameterName, SI_Float in_fValue);
00302 
00304     // Accessors
00306     
00310     CSLAmbience *Ambience();
00311 
00315     CSLAmbience *CreateAmbience();
00316 
00320     SI_Error DestroyAmbience();
00321 
00325     CSLCoordinateSystem* CoordinateSystem();
00326 
00330     CSLEnvelopeList* EnvelopeList();
00331     
00335     CSLFog* Fog();
00336 
00340     CSLMaterialLibrary* GetMaterialLibrary();
00341 
00345     CSLModel *Root();
00346 
00350     CXSIParser* Parser();
00351 
00355     CSLAngle* Angle();
00356     
00360     CSLFileInfo* FileInfo();
00361 
00365     CSLSceneInfo* SceneInfo();
00366 
00370     CSLLogger* Logger();
00371 
00375     CSIBCString &FileName();
00376 
00380     CSLImageLibrary* GetImageLibrary();
00381 
00385     SI_Error DestroyFog();
00386 
00390     CSLFog* CreateFog();
00391 
00395     SI_Error DestroyEnvelopeList();
00396 
00400     virtual CSLEnvelopeList* CreateEnvelopeList();
00401 
00406     virtual CSLImageLibrary* CreateImageLibrary();
00407 
00412     SI_Error DestroyImageLibrary();
00413     
00414     
00416     // Connection functions.
00418     
00423     virtual CSLMaterialLibrary* ConnectMaterialLibrary(CSLMaterialLibrary *in_pNewMaterialLibrary);
00424 
00429     CSLAngle* ConnectAngle(CSLAngle *in_pNewAngle);
00430 
00435     CSLFileInfo* ConnectFileInfo(CSLFileInfo *in_pNewFileInfo);
00436 
00441     CSLSceneInfo* ConnectSceneInfo(CSLSceneInfo* in_pToConnect);
00442 
00447     CSLFog* ConnectFog( CSLFog *in_pNewFog );
00448 
00453     CSLAmbience* ConnectAmbience( CSLAmbience *in_pNewAmbience );
00454 
00459     CSLCoordinateSystem* ConnectCoordinateSystem( CSLCoordinateSystem *in_pNewCoordSystem );
00460 
00465     CSLEnvelopeList* ConnectEnvelopeList( CSLEnvelopeList* in_pNewEnvList );
00466 
00472     CSLImageLibrary* ConnectImageLibrary( CSLImageLibrary* in_pImageLibrary );
00473 
00508     SI_Error RegisterCallback(SI_Char *in_pName, SLTemplateCallback *in_pTemplateCallback);
00509 
00514     SI_Error UnregisterCallback(SI_Char *in_pName);
00515 
00519     SI_Error UnregisterAllCallbacks();
00520 
00525     SLTemplateCallback *Callback(SI_Char *in_pName);
00526 
00528     // Coherancy functions
00530     virtual SI_Error Fix();
00531     virtual SI_Error Synchronize();
00532 
00534     // Utility functions
00536     SI_Error RemoveTemplate(CdotXSITemplate *in_pElement);
00537     SI_Error ClearSLObjectArray(CSIBCArray<CSLTemplate *> *in_pArray);
00538 
00544     SI_Bool SupportsTemplates( SI_Int in_nMajor, SI_Int in_nMinor );
00545 
00549     SI_Void SetWarningCallback ( SI_WARNING_CALLBACK_FNC in_pfncCallback ) { m_pfncCallback = in_pfncCallback; };
00550 
00554     SI_Void SetReadCallback ( SI_READ_CALLBACK_FNC in_pfncCallback ) { m_pfncReadCallback = in_pfncCallback; };
00561     SI_Error    GetRefCount( CSLTemplate                ** in_ppObjects,
00562                              SI_Int                     ** out_ppRefCounts,
00563                              SI_Int                     in_iObjectCount,
00564                              CSLTemplate::ETemplateType in_eType );
00565 
00566 
00567     static CSLScene * CreateScene();
00568 protected:
00569 
00570     SI_Error    GetRefCountRecursively      ( CSLModel* in_pModel, 
00571                                                     CSLTemplate** in_ppObjects, 
00572                                                     SI_Int**    out_ppRefCounts, 
00573                                                     SI_Int      in_iObjectCount, 
00574                                                     CSLTemplate::ETemplateType in_eType );
00575 
00576 
00577 protected:
00578     CSLModel    * FindFullyQualifiedObject( SI_Char * in_pName, SI_Char ** out_pContainer, SI_Char ** out_pParameter );
00579     virtual SI_Error PopulateScene();
00580     SI_Error ReadTemplateRecursively(CdotXSITemplate *in_pTemplate, SLContext *in_pContext);
00581     SI_Error ExecutePreLoadCallbacks(SLContext *in_pContext);
00582     SI_Error ExecutePostLibraryCallbacks(SLContext *in_pContext);
00583     SI_Error ExecutePostLoadCallbacks(SLContext *in_pContext);
00584     virtual SI_Error RegisterAllCallbacks();
00585     SI_Error Clear();
00586 
00587 #ifdef  FTK_KERNEL
00588     typedef SI_StrMap<SLTemplateCallback> CSLCallbackMap;
00589     typedef CSLCallbackMap::iterator CSLCallbackMapIterator;
00590 #else
00591     typedef void    CSLCallbackMap;
00592 #endif
00593 
00594     CSLSceneInfo* m_pSceneInfo;
00595     CSLFileInfo* m_pFileInfo;
00596     CSLAmbience* m_pAmbience;
00597     CSLAngle* m_pAngle;
00598     CSLFog* m_pFog;
00599     CSLEnvelopeList* m_pEnvelopeList;
00600     CSLMaterialLibrary* m_pMaterialLibrary;
00601     CSLCoordinateSystem* m_pCoordinateSystem;
00602     CXSIParser* m_pParser;
00603     CSLCallbackMap* m_pCallbackMap;
00604     CSLModel *m_pRoot;
00605     CSLLogger m_Logger;
00606     CSLImageLibrary *m_pImageLibrary;
00607 
00608     CSIBCString m_FileName;
00609 
00610     SI_WARNING_CALLBACK_FNC m_pfncCallback;
00611     SI_READ_CALLBACK_FNC    m_pfncReadCallback;
00612 
00613     // This member is here to allow future improvement of the class.
00614     void *m_pReserved;
00615 };
00616 
00617 #endif