diff --git a/Source/System/FileIO/Collada/OSGColladaCOLLADA.cpp b/Source/System/FileIO/Collada/OSGColladaCOLLADA.cpp new file mode 100644 index 000000000..458343908 --- /dev/null +++ b/Source/System/FileIO/Collada/OSGColladaCOLLADA.cpp @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------*\ + * OpenSG * + * * + * * + * Copyright (C) 2009 by the OpenSG Forum * + * * + * www.opensg.org * + * * + * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * + * * +\*---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*\ + * License * + * * + * This library is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Library General Public License as published * + * by the Free Software Foundation, version 2. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * + * * +\*---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*\ + * Changes * + * * + * * + * * + * * + * * + * * +\*---------------------------------------------------------------------------*/ + +#if __GNUC__ >= 4 || __GNUC_MINOR__ >=3 +#pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + +#include "OSGColladaCOLLADA.h" + +#ifdef OSG_WITH_COLLADA + +#include "OSGColladaLog.h" +#include "OSGColladaScene.h" + +#include + +OSG_BEGIN_NAMESPACE + +ColladaElementRegistrationHelper ColladaCOLLADA::_regHelper( + &ColladaCOLLADA::create, "COLLADA"); + + +ColladaElementTransitPtr +ColladaCOLLADA::create(daeElement *elem, ColladaGlobal *global) +{ + return ColladaElementTransitPtr(new ColladaCOLLADA(elem, global)); +} + +void +ColladaCOLLADA::read(void) +{ + OSG_COLLADA_LOG(("ColladaCOLLADA::read\n")); + + domCOLLADARef collada = getDOMElementAs(); + domCOLLADA::domSceneRef scene = collada->getScene(); + + ColladaSceneRefPtr colScene = getUserDataAs(scene); + + if(colScene == NULL) + { + colScene = dynamic_pointer_cast( + ColladaElementFactory::the()->create(scene, getGlobal())); + + colScene->read(); + } + + colScene->process(); +} + +ColladaCOLLADA::ColladaCOLLADA(daeElement *elem, ColladaGlobal *global) + : Inherited(elem, global) +{ +} + +ColladaCOLLADA::~ColladaCOLLADA(void) +{ +} + +OSG_END_NAMESPACE + +#endif // OSG_WITH_COLLADA diff --git a/Source/System/FileIO/Collada/OSGColladaCOLLADA.h b/Source/System/FileIO/Collada/OSGColladaCOLLADA.h new file mode 100644 index 000000000..9398390d2 --- /dev/null +++ b/Source/System/FileIO/Collada/OSGColladaCOLLADA.h @@ -0,0 +1,103 @@ +/*---------------------------------------------------------------------------*\ + * OpenSG * + * * + * * + * Copyright (C) 2009 by the OpenSG Forum * + * * + * www.opensg.org * + * * + * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * + * * +\*---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*\ + * License * + * * + * This library is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Library General Public License as published * + * by the Free Software Foundation, version 2. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * + * * +\*---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*\ + * Changes * + * * + * * + * * + * * + * * + * * +\*---------------------------------------------------------------------------*/ + +#ifndef _OSGCOLLADACOLLADA_H_ +#define _OSGCOLLADACOLLADA_H_ + +#include "OSGConfig.h" + +#ifdef OSG_WITH_COLLADA + +#include "OSGColladaElement.h" +#include "OSGColladaElementFactoryHelper.h" + +OSG_BEGIN_NAMESPACE + +class OSG_FILEIO_DLLMAPPING ColladaCOLLADA : public ColladaElement +{ + /*========================== PUBLIC =================================*/ + public: + /*---------------------------------------------------------------------*/ + /*! \name Types */ + /*! \{ */ + + typedef ColladaElement Inherited; + typedef ColladaCOLLADA Self; + + OSG_GEN_INTERNAL_MEMOBJPTR(ColladaCOLLADA); + + /*! \} */ + /*---------------------------------------------------------------------*/ + /*! \name Create */ + /*! \{ */ + + static ColladaElementTransitPtr + create(daeElement *elem, ColladaGlobal *global); + + /*! \} */ + /*---------------------------------------------------------------------*/ + /*! \name Reading */ + /*! \{ */ + + virtual void read(void); + + /*! \} */ + /*========================= PROTECTED ===============================*/ + protected: + /*---------------------------------------------------------------------*/ + /*! \name Constructors/Destructor */ + /*! \{ */ + + ColladaCOLLADA(daeElement *elem, ColladaGlobal *global); + virtual ~ColladaCOLLADA(void ); + + /*! \} */ + /*---------------------------------------------------------------------*/ + + static ColladaElementRegistrationHelper _regHelper; +}; + +OSG_GEN_MEMOBJPTR(ColladaCOLLADA); + +OSG_END_NAMESPACE + +// #include "OSGColladaCOLLADA.inl" + +#endif // OSG_WITH_COLLADA + +#endif // _OSGCOLLADACOLLADA_H_ diff --git a/Source/System/FileIO/Collada/OSGColladaGlobal.cpp b/Source/System/FileIO/Collada/OSGColladaGlobal.cpp index 48e20b339..bf4e3f3b8 100644 --- a/Source/System/FileIO/Collada/OSGColladaGlobal.cpp +++ b/Source/System/FileIO/Collada/OSGColladaGlobal.cpp @@ -45,7 +45,7 @@ #ifdef OSG_WITH_COLLADA #include "OSGColladaLog.h" -#include "OSGColladaScene.h" +#include "OSGColladaCOLLADA.h" #include "OSGColladaElementFactory.h" #include "OSGColladaOptions.h" @@ -105,15 +105,15 @@ ColladaGlobal::read(std::istream &is, const std::string &fileName) _docPath = fileName; - DAE *dae = new DAE; - dae->open(fileName.c_str()); + _dae = new DAE; + _dae->open(fileName.c_str()); - rootN = doRead(dae); + rootN = doRead(); - dae->clear(); - delete dae; - - _docPath.clear(); + _docPath. clear(); + _dae ->clear(); + delete _dae; + _dae = NULL; return rootN; } @@ -137,10 +137,12 @@ ColladaGlobal::read(DAE *dae, const std::string &fileName) _pathHandler.setBaseFile (fileName.c_str()); _docPath = fileName; + _dae = dae; - rootN = doRead(dae); + rootN = doRead(); _docPath.clear(); + _dae = NULL; return rootN; } @@ -159,7 +161,6 @@ ColladaGlobal::ColladaGlobal(void) , _pathHandler() , _docPath () , _dae (NULL) - , _docRoot () , _rootN (NULL) { } @@ -170,16 +171,13 @@ ColladaGlobal::~ColladaGlobal(void) _dae = NULL; } -/*! Read the file stored in _docPath from the DAE \dae. +/*! Read the file stored in _docPath from the DAE _dae. */ NodeTransitPtr -ColladaGlobal::doRead(DAE *dae) +ColladaGlobal::doRead(void) { NodeTransitPtr rootN(NULL); - _dae = dae; - _docRoot = _dae->getRoot(_docPath); - if(_statColl == NULL) _statColl = new StatCollector; @@ -189,23 +187,14 @@ ColladaGlobal::doRead(DAE *dae) _statColl->reset (StatElemDescBase::RESET_ALWAYS); - if(_docRoot != NULL) + domCOLLADARef docRoot = _dae->getRoot(_docPath); + + if(docRoot != NULL) { - domCOLLADA::domSceneRef scene = _docRoot->getScene(); - - if(scene != NULL) - { - ColladaSceneRefPtr colScene = dynamic_pointer_cast( - ColladaElementFactory::the()->create(scene, this)); - - colScene->read (); - colScene->process(); - } - else - { - SWARNING << "ColladaGlobal::read: No tag found in file [" - << _docPath << "]." << std::endl; - } + ColladaCOLLADARefPtr colCOL = dynamic_pointer_cast( + ColladaElementFactory::the()->create(docRoot, this)); + + colCOL->read(); } else { @@ -216,8 +205,6 @@ ColladaGlobal::doRead(DAE *dae) rootN = _rootN; - _docRoot = NULL; - _dae = NULL; _elemStore.clear(); #ifndef OSG_COLLADA_SILENT diff --git a/Source/System/FileIO/Collada/OSGColladaGlobal.h b/Source/System/FileIO/Collada/OSGColladaGlobal.h index 4512d98c7..e77722473 100644 --- a/Source/System/FileIO/Collada/OSGColladaGlobal.h +++ b/Source/System/FileIO/Collada/OSGColladaGlobal.h @@ -159,7 +159,7 @@ class OSG_FILEIO_DLLMAPPING ColladaGlobal : public MemoryObject /*! \name Read */ /*! \{ */ - NodeTransitPtr doRead(DAE *dae); + NodeTransitPtr doRead(void); /*! \} */ /*---------------------------------------------------------------------*/ @@ -173,7 +173,6 @@ class OSG_FILEIO_DLLMAPPING ColladaGlobal : public MemoryObject std::string _docPath; DAE *_dae; - domCOLLADARef _docRoot; NodeUnrecPtr _rootN; };