Skip to content

Commit

Permalink
changed: handle top level <COLLADA> tag through element factory
Browse files Browse the repository at this point in the history
git-svn-id: https://opensg.vrsource.org/svn/trunk@2253 4683daeb-ad0f-0410-a623-93161e962ae5
  • Loading branch information
cneumann committed Dec 29, 2009
1 parent 3830d5e commit fdaf217
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 35 deletions.
96 changes: 96 additions & 0 deletions 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 <dom/domCOLLADA.h>

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>();
domCOLLADA::domSceneRef scene = collada->getScene();

ColladaSceneRefPtr colScene = getUserDataAs<ColladaScene>(scene);

if(colScene == NULL)
{
colScene = dynamic_pointer_cast<ColladaScene>(
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
103 changes: 103 additions & 0 deletions 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_
53 changes: 20 additions & 33 deletions Source/System/FileIO/Collada/OSGColladaGlobal.cpp
Expand Up @@ -45,7 +45,7 @@
#ifdef OSG_WITH_COLLADA

#include "OSGColladaLog.h"
#include "OSGColladaScene.h"
#include "OSGColladaCOLLADA.h"
#include "OSGColladaElementFactory.h"
#include "OSGColladaOptions.h"

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -159,7 +161,6 @@ ColladaGlobal::ColladaGlobal(void)
, _pathHandler()
, _docPath ()
, _dae (NULL)
, _docRoot ()
, _rootN (NULL)
{
}
Expand All @@ -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;

Expand All @@ -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<ColladaScene>(
ColladaElementFactory::the()->create(scene, this));

colScene->read ();
colScene->process();
}
else
{
SWARNING << "ColladaGlobal::read: No <scene> tag found in file ["
<< _docPath << "]." << std::endl;
}
ColladaCOLLADARefPtr colCOL = dynamic_pointer_cast<ColladaCOLLADA>(
ColladaElementFactory::the()->create(docRoot, this));

colCOL->read();
}
else
{
Expand All @@ -216,8 +205,6 @@ ColladaGlobal::doRead(DAE *dae)

rootN = _rootN;

_docRoot = NULL;
_dae = NULL;
_elemStore.clear();

#ifndef OSG_COLLADA_SILENT
Expand Down
3 changes: 1 addition & 2 deletions Source/System/FileIO/Collada/OSGColladaGlobal.h
Expand Up @@ -159,7 +159,7 @@ class OSG_FILEIO_DLLMAPPING ColladaGlobal : public MemoryObject
/*! \name Read */
/*! \{ */

NodeTransitPtr doRead(DAE *dae);
NodeTransitPtr doRead(void);

/*! \} */
/*---------------------------------------------------------------------*/
Expand All @@ -173,7 +173,6 @@ class OSG_FILEIO_DLLMAPPING ColladaGlobal : public MemoryObject
std::string _docPath;

DAE *_dae;
domCOLLADARef _docRoot;

NodeUnrecPtr _rootN;
};
Expand Down

0 comments on commit fdaf217

Please sign in to comment.