Permalink
Browse files

WIP: changed IO option handling to provide helper functions : correct…

…ly interpret <source>/<accessor> data : remove process() function except on InstanceElments

git-svn-id: https://opensg.vrsource.org/svn/trunk@2245 4683daeb-ad0f-0410-a623-93161e962ae5
  • Loading branch information...
1 parent cbb7d57 commit 44c2bfcb2af3ce5bb684bb1e52bf1a35f3cfed83 cneumann committed Dec 29, 2009
Showing with 2,005 additions and 160 deletions.
  1. +24 −20 Source/System/FileIO/Base/OSGIOFileTypeBase.cpp
  2. +27 −0 Source/System/FileIO/Base/OSGIOFileTypeBase.h
  3. +126 −34 Source/System/FileIO/Base/OSGIOFileTypeBase.inl
  4. +323 −0 Source/System/FileIO/Collada/OSGColladaEffect.cpp
  5. +143 −0 Source/System/FileIO/Collada/OSGColladaEffect.h
  6. +1 −2 Source/System/FileIO/Collada/OSGColladaElement.h
  7. +109 −19 Source/System/FileIO/Collada/OSGColladaGeometry.cpp
  8. +0 −2 Source/System/FileIO/Collada/OSGColladaGeometry.h
  9. +5 −4 Source/System/FileIO/Collada/OSGColladaGlobal.cpp
  10. +122 −0 Source/System/FileIO/Collada/OSGColladaImage.cpp
  11. +106 −0 Source/System/FileIO/Collada/OSGColladaImage.h
  12. +158 −0 Source/System/FileIO/Collada/OSGColladaInstanceEffect.cpp
  13. +116 −0 Source/System/FileIO/Collada/OSGColladaInstanceEffect.h
  14. +63 −0 Source/System/FileIO/Collada/OSGColladaInstanceGeometry.cpp
  15. +11 −0 Source/System/FileIO/Collada/OSGColladaInstanceGeometry.h
  16. +205 −0 Source/System/FileIO/Collada/OSGColladaInstanceMaterial.cpp
  17. +146 −0 Source/System/FileIO/Collada/OSGColladaInstanceMaterial.h
  18. +0 −11 Source/System/FileIO/Collada/OSGColladaInstantiableElement.cpp
  19. +0 −3 Source/System/FileIO/Collada/OSGColladaInstantiableElement.h
  20. +104 −0 Source/System/FileIO/Collada/OSGColladaMaterial.cpp
  21. +103 −0 Source/System/FileIO/Collada/OSGColladaMaterial.h
  22. +31 −19 Source/System/FileIO/Collada/OSGColladaNode.cpp
  23. +8 −1 Source/System/FileIO/Collada/OSGColladaNode.h
  24. +26 −1 Source/System/FileIO/Collada/OSGColladaOptions.cpp
  25. +10 −0 Source/System/FileIO/Collada/OSGColladaOptions.h
  26. +2 −4 Source/System/FileIO/Collada/OSGColladaScene.cpp
  27. +2 −2 Source/System/FileIO/Collada/OSGColladaScene.h
  28. +12 −21 Source/System/FileIO/Collada/OSGColladaSource.cpp
  29. +4 −3 Source/System/FileIO/Collada/OSGColladaSource.h
  30. +18 −12 Source/System/FileIO/Collada/OSGColladaVisualScene.cpp
  31. +0 −2 Source/System/FileIO/Collada/OSGColladaVisualScene.h
View
44 Source/System/FileIO/Base/OSGIOFileTypeBase.cpp
@@ -120,55 +120,59 @@ void
}
}
-/*! Sets the option \a name to \a value overwriting any previous value.
+/*! Sets the option \a name to \a value in \a optSet overwriting
+ any previous value.
+ \param[in] optSet OptionSet to modify.
\param[in] name Name of the option.
\param[in[ value Value of the option.
*/
void
- IOFileTypeBase::setOption(
- const std::string &name, const std::string &value)
+IOFileTypeBase::setOption(
+ OptionSet &optSet, const std::string &name, const std::string &value)
{
- _optStack.top()[name] = IOOption(name, value);
+ optSet[name] = IOOption(name, value);
}
-/*! Removes the option \a name. If the option is not present \c false is
- returned, \c true otherwise.
+/*! Removes the option \a name from \a optSet. If the option is not present
+ \c false is returned, \c true otherwise.
- \param[in] name Name of the option.
+ \param[in] optSet OptionSet to modify.
+ \param[in] name Name of the option.
\return Whether the option was successfully removed.
*/
bool
- IOFileTypeBase::unsetOption(const std::string &name)
+IOFileTypeBase::unsetOption(OptionSet &optSet, const std::string &name)
{
bool retVal = false;
- OptionSet::iterator oIt = _optStack.top().find(name);
+ OptionSet::iterator oIt = optSet.find(name);
- if(oIt != _optStack.top().end())
+ if(oIt != optSet.end())
{
- _optStack.top().erase(oIt);
+ optSet.erase(oIt);
retVal = true;
}
return retVal;
}
-/*! Attempts to return the value associated with option \a name in \a value.
- If the option is not present \c false is returned, \c true otherwise and
- only in this case value is being set.
+/*! Attempts to return the \a value associated with option \a name
+ in \a optSet. If the option is not present \c false is returned,
+ \c true otherwise and only in this case value is being set.
- \param[in] name Name of the option.
- \param[out] value Value of option.
+ \param[in] optSet OptionSet to read.
+ \param[in] name Name of the option.
+ \param[out] value Value of option.
\return Whether the option is present.
*/
bool
- IOFileTypeBase::getOption(
- std::string const &name, std::string &value) const
+IOFileTypeBase::getOption(
+ const OptionSet &optSet, std::string const &name, std::string &value)
{
bool retVal = false;
- OptionSet::const_iterator oIt = _optStack.top().find(name);
+ OptionSet::const_iterator oIt = optSet.find(name);
- if(oIt != _optStack.top().end())
+ if(oIt != optSet.end())
{
value = oIt->second.optValue;
retVal = true;
View
27 Source/System/FileIO/Base/OSGIOFileTypeBase.h
@@ -92,6 +92,33 @@ class OSG_SYSTEM_DLLMAPPING IOFileTypeBase
/*! \} */
/*---------------------------------------------------------------------*/
+ /*! \name Option Handling Helpers */
+ /*! \{ */
+
+ static bool hasOption (const OptionSet &optSet,
+ const std::string &name );
+
+ template <class ValueTypeT>
+ static bool setOptionAs( OptionSet &optSet,
+ const std::string &name,
+ const ValueTypeT &value );
+ static void setOption ( OptionSet &optSet,
+ const std::string &name,
+ const std::string &value );
+
+ static bool unsetOption( OptionSet &optSet,
+ const std::string &name );
+
+ template <class ValueTypeT>
+ static bool getOptionAs(const OptionSet &optSet,
+ const std::string &name,
+ ValueTypeT &value );
+ static bool getOption (const OptionSet &optSet,
+ const std::string &name,
+ std::string &value );
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
/*! \name Option Handling */
/*! \{ */
View
160 Source/System/FileIO/Base/OSGIOFileTypeBase.inl
@@ -38,10 +38,96 @@
OSG_BEGIN_NAMESPACE
+/*! Returns whether an option with the given \a name is present in \a optSet.
+
+ \param[in] optSet OptionSet to check.
+ \param[in] name Name of the option.
+ \return Whether the option is present.
+ */
+inline bool
+IOFileTypeBase::hasOption(const OptionSet &optSet, const std::string &name)
+{
+ return (optSet.find(name) != optSet.end());
+}
+
+/*! Attempts to set option \a name to \a value in \a optSet.
+ If successful \c true is returned, false otherwise.
+ For the operation to succeed a \c boost::lexical_cast<> from the given type
+ has to succeed, usually that means an appropriate overload of
+ \c operator<< has to be available.
+
+ \param[in] optSet OptionSet to modify.
+ \param[in] name Name of the option.
+ \param[in] value Value of the option.
+ \return Whether the value was set successfully.
+ */
+template <class ValueTypeT>
+inline bool
+IOFileTypeBase::setOptionAs(
+ OptionSet &optSet, const std::string &name, const ValueTypeT &value)
+{
+ bool retVal = false;
+
+ try
+ {
+ setOption(optSet, name, boost::lexical_cast<std::string>(value));
+ retVal = true;
+ }
+ catch(boost::bad_lexical_cast &blc)
+ {
+ SWARNING << "IOFileTypeBase::setOptionAs: Failed to store value "
+ << "for option [" << name << "] : "
+ << blc.what() << std::endl;
+ }
+
+ return retVal;
+}
+
+/*! Attempts to return the \a value associated with option \a name in \a optSet
+ as the requested type.
+ If the option is not present \c false is returned, \c true otherwise and
+ only in this case value is being set.
+ For the operation to succeed a \c boost::lexical_cast<> to the requested
+ type has to succeed, usually that means an appropriate overload of
+ \c operator>> has to be available.
+
+ \param[in] optSet OptionSet to read.
+ \param[in] name Name of the option.
+ \param[out] value Value of option.
+ \return Whether the option is present.
+ */
+template <class ValueTypeT>
+inline bool
+IOFileTypeBase::getOptionAs(
+ const OptionSet &optSet, const std::string &name, ValueTypeT &value)
+{
+ bool retVal = false;
+ std::string valueStr;
+
+ if(getOption(optSet, name, valueStr) == true)
+ {
+ try
+ {
+ value = boost::lexical_cast<ValueTypeT>(valueStr);
+ retVal = true;
+ }
+ catch(boost::bad_lexical_cast &blc)
+ {
+ SWARNING << "IOFileTypeBase::getOptionAs: Failed to extract "
+ << "value of option [" << name << "] from string ["
+ << valueStr << "] : "
+ << blc.what() << std::endl;
+ }
+ }
+
+ return retVal;
+}
+
+
/*! Returns the currently active option set, i.e. the top of the options stack.
*/
inline IOFileTypeBase::OptionSet const &
- IOFileTypeBase::getOptions (void) const
+ IOFileTypeBase::getOptions(void) const
{
return _optStack.top();
}
@@ -62,7 +148,7 @@ inline IOFileTypeBase::OptionSet &
inline bool
IOFileTypeBase::hasOption(std::string const &name) const
{
- return (_optStack.top().find(name) != _optStack.top().end());
+ return hasOption(_optStack.top(), name);
}
/*! Attempts to set option \a name to \a value.
@@ -80,21 +166,30 @@ inline bool
IOFileTypeBase::setOptionAs(
const std::string &name, const ValueTypeT &value)
{
- bool retVal = false;
-
- try
- {
- _optStack.top()[name] =
- IOOption(name, boost::lexical_cast<std::string>(value));
- retVal = true;
- }
- catch(boost::bad_lexical_cast &)
- {
- FWARNING(("IOFileTypeBase::setOptionAs: Failed to store value "
- "for option [%s].\n", name.c_str()));
- }
-
- return retVal;
+ return setOptionAs(_optStack.top(), name, value);
+}
+
+/*! Sets the option \a name to \a value overwriting any previous value.
+
+ \param[in] name Name of the option.
+ \param[in[ value Value of the option.
+ */
+inline void
+IOFileTypeBase::setOption(const std::string &name, const std::string &value)
+{
+ setOption(_optStack.top(), name, value);
+}
+
+/*! Removes the option \a name. If the option is not present
+ \c false is returned, \c true otherwise.
+
+ \param[in] name Name of the option.
+ \return Whether the option was successfully removed.
+ */
+inline bool
+IOFileTypeBase::unsetOption(const std::string &name)
+{
+ return unsetOption(_optStack.top(), name);
}
/*! Attempts to return the value associated with option \a name in \a value
@@ -114,24 +209,21 @@ inline bool
IOFileTypeBase::getOptionAs(
const std::string &name, ValueTypeT &value) const
{
- bool retVal = false;
- OptionSet::const_iterator oIt = _optStack.top().find(name);
-
- if(oIt != _optStack.top().end())
- {
- try
- {
- value = boost::lexical_cast<ValueTypeT>(oIt->second.optValue);
- retVal = true;
- }
- catch(boost::bad_lexical_cast &)
- {
- FWARNING(("IOFileTypeBase::getOptionAs: Failed to extract value "
- "of option [%s].\n", name.c_str()));
- }
- }
+ return getOptionAs(_optStack.top(), name, value);
+}
+
+/*! Attempts to return the \a value associated with option \a name.
+ If the option is not present \c false is returned,
+ \c true otherwise and only in this case value is being set.
- return retVal;
+ \param[in] name Name of the option.
+ \param[out] value Value of option.
+ \return Whether the option is present.
+ */
+inline bool
+IOFileTypeBase::getOption(const std::string &name, std::string &value) const
+{
+ return getOption(_optStack.top(), name, value);
}
OSG_END_NAMESPACE
View
323 Source/System/FileIO/Collada/OSGColladaEffect.cpp
@@ -0,0 +1,323 @@
+/*---------------------------------------------------------------------------*\
+ * 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 "OSGColladaEffect.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaLog.h"
+#include "OSGColladaImage.h"
+#include "OSGColladaInstanceEffect.h"
+
+#include "OSGChunkMaterial.h"
+#include "OSGMaterialChunk.h"
+
+#include <dom/domEffect.h>
+#include <dom/domInstance_effect.h>
+#include <dom/domProfile_COMMON.h>
+#include <dom/domProfile_GLSL.h>
+#include <dom/domProfile_CG.h>
+
+OSG_BEGIN_NAMESPACE
+
+ColladaElementRegistrationHelper ColladaEffect::_regHelper(
+ &ColladaEffect::create, "effect");
+
+
+ColladaElementTransitPtr
+ColladaEffect::create(daeElement *elem, ColladaGlobal *global)
+{
+ return ColladaElementTransitPtr(new ColladaEffect(elem, global));
+}
+
+void
+ColladaEffect::read(void)
+{
+ OSG_COLLADA_LOG(("ColladaEffect::read\n"));
+
+ domEffectRef effect = getDOMElementAs<domEffect>();
+ const domImage_Array &images = effect->getImage_array();
+
+ readImageArray(images);
+
+ const domFx_profile_abstract_Array &profiles =
+ effect->getFx_profile_abstract_array();
+
+ for(UInt32 i = 0; i < profiles.getCount(); ++i)
+ {
+ if(domProfile_COMMON::ID() == profiles[i]->typeID())
+ {
+ readProfileCommon(daeSafeCast<domProfile_COMMON>(profiles[i]));
+ }
+ else if(domProfile_GLSL::ID() == profiles[i]->typeID())
+ {
+ readProfileGLSL(daeSafeCast<domProfile_GLSL>(profiles[i]));
+ }
+ else if(domProfile_CG::ID() == profiles[i]->typeID())
+ {
+ readProfileCG(daeSafeCast<domProfile_CG>(profiles[i]));
+ }
+ }
+}
+
+Material *
+ColladaEffect::createInstance(ColladaInstanceElement *colInstElem)
+{
+ OSG_COLLADA_LOG(("ColladaEffect::createInstance\n"));
+
+ MaterialUnrecPtr retVal = NULL;
+ domEffectRef effect = getDOMElementAs<domEffect>();
+ ColladaInstanceEffectRefPtr colInstEffect =
+ dynamic_cast<ColladaInstanceEffect *>(colInstElem);
+ domInstance_effectRef instEffect =
+ colInstElem->getDOMElementAs<domInstance_effect>();
+
+ const domFx_profile_abstract_Array &profiles =
+ effect->getFx_profile_abstract_array();
+
+ for(UInt32 i = 0; i < profiles.getCount(); ++i)
+ {
+ if(domProfile_COMMON::ID() == profiles[i]->typeID())
+ {
+ retVal = createInstanceProfileCommon(
+ daeSafeCast<domProfile_COMMON>(profiles[i]),
+ effect, instEffect);
+ }
+ else if(domProfile_GLSL::ID() == profiles[i]->typeID())
+ {
+ retVal = createInstanceProfileGLSL(
+ daeSafeCast<domProfile_GLSL>(profiles[i]),
+ effect, instEffect);
+ }
+ else if(domProfile_CG::ID() == profiles[i]->typeID())
+ {
+ retVal = createInstanceProfileCG(
+ daeSafeCast<domProfile_CG>(profiles[i]),
+ effect, instEffect);
+ }
+ }
+
+ // XXX TODO: do we always need to create a new material?
+ editInstStore().push_back(retVal);
+
+ return retVal;
+}
+
+ColladaEffect::ColladaEffect(daeElement *elem, ColladaGlobal *global)
+ : Inherited(elem, global)
+{
+}
+
+ColladaEffect::~ColladaEffect(void)
+{
+}
+
+void
+ColladaEffect::readProfileCommon(domProfile_COMMON *prof)
+{
+ if(prof == NULL)
+ {
+ SWARNING << "ColladaEffect::readProfileCommon: No DOM element or "
+ << "incorrect type." << std::endl;
+ return;
+ }
+
+ readImageArray(prof->getImage_array());
+
+ domProfile_COMMON::domTechniqueRef tech = prof->getTechnique();
+
+ readImageArray(tech->getImage_array());
+}
+
+void
+ColladaEffect::readProfileGLSL(domProfile_GLSL *prof)
+{
+ SWARNING << "ColladaEffect::readProfileGLSL: NIY." << std::endl;
+}
+
+void
+ColladaEffect::readProfileCG(domProfile_CG *prof)
+{
+ SWARNING << "ColladaEffect::readProfileCG: NIY." << std::endl;
+}
+
+Material *
+ColladaEffect::createInstanceProfileCommon(
+ domProfile_COMMON *prof, domEffect *effect,
+ domInstance_effect *instEffect )
+{
+ OSG_COLLADA_LOG(("ColladaEffect::createInstanceProfileCommon\n"));
+
+ domProfile_COMMON::domTechniqueRef tech = prof->getTechnique();
+
+ domCommon_color_or_texture_typeRef emission = NULL;
+ domCommon_color_or_texture_typeRef ambient = NULL;
+ domCommon_color_or_texture_typeRef diffuse = NULL;
+ domCommon_color_or_texture_typeRef specular = NULL;
+
+ if(tech->getConstant() != NULL)
+ {
+ domProfile_COMMON::domTechnique::domConstantRef constant =
+ tech->getConstant();
+
+ emission = constant->getEmission();
+ }
+ else if(tech->getLambert() != NULL)
+ {
+ domProfile_COMMON::domTechnique::domLambertRef lambert =
+ tech->getLambert();
+
+ emission = lambert->getEmission();
+ ambient = lambert->getAmbient ();
+ diffuse = lambert->getDiffuse ();
+ }
+ else if(tech->getPhong() != NULL)
+ {
+ domProfile_COMMON::domTechnique::domPhongRef phong =
+ tech->getPhong();
+
+ emission = phong->getEmission();
+ ambient = phong->getAmbient ();
+ diffuse = phong->getDiffuse ();
+ specular = phong->getSpecular();
+ }
+ else if(tech->getBlinn() != NULL)
+ {
+ domProfile_COMMON::domTechnique::domBlinnRef blinn =
+ tech->getBlinn();
+
+ emission = blinn->getEmission();
+ ambient = blinn->getAmbient ();
+ diffuse = blinn->getDiffuse ();
+ specular = blinn->getSpecular();
+ }
+
+ ChunkMaterialUnrecPtr mat = ChunkMaterial::create();
+ MaterialChunkUnrecPtr matChunk = MaterialChunk::create();
+
+ if(emission != NULL)
+ {
+ domCommon_color_or_texture_type::domColorRef color =
+ emission->getColor ();
+ domCommon_color_or_texture_type::domParamRef param =
+ emission->getParam ();
+ domCommon_color_or_texture_type::domTextureRef texture =
+ emission->getTexture();
+
+ if(color != NULL)
+ {
+ Color4f colVal(color->getValue()[0],
+ color->getValue()[1],
+ color->getValue()[2],
+ color->getValue()[3] );
+
+ matChunk->setEmission(colVal);
+ }
+ else if(param != NULL)
+ {
+
+ }
+ else if(texture != NULL)
+ {
+ }
+ }
+
+ // XXX TODO: return constructed material
+ return NULL;
+}
+
+Material *
+ColladaEffect::createInstanceProfileGLSL(
+ domProfile_GLSL *prof, domEffect *effect,
+ domInstance_effect *instEffect )
+{
+ SWARNING << "ColladaEffect::createInstanceProfileGLSL: NIY" << std::endl;
+
+ return NULL;
+}
+
+Material *
+ColladaEffect::createInstanceProfileCG(
+ domProfile_CG *prof, domEffect *effect,
+ domInstance_effect *instEffect )
+{
+ SWARNING << "ColladaEffect::createInstanceProfileCG: NIY" << std::endl;
+
+ return NULL;
+}
+
+void
+ColladaEffect::readImageArray(const domImage_Array &images)
+{
+ for(UInt32 i = 0; i < images.getCount(); ++i)
+ {
+ ColladaImageRefPtr colImg = getUserDataAs<ColladaImage>(images[i]);
+
+ if(colImg == NULL)
+ {
+ colImg = dynamic_pointer_cast<ColladaImage>(
+ ColladaElementFactory::the()->create(
+ images[i], getGlobal()));
+
+ colImg->read();
+ }
+ }
+}
+
+void
+ColladaEffect::fillTexColor(
+ domCommon_color_or_texture_type *colTex,
+ domCommon_color_or_texture_type::domColorRef &colOut,
+ domCommon_color_or_texture_type::domTextureRef &texOut )
+{
+ if(colTex != NULL)
+ {
+ colOut = colTex->getColor ();
+ texOut = colTex->getTexture();
+ }
+}
+
+
+
+OSG_END_NAMESPACE
+
+#endif // OSG_WITH_COLLADA
View
143 Source/System/FileIO/Collada/OSGColladaEffect.h
@@ -0,0 +1,143 @@
+/*---------------------------------------------------------------------------*\
+ * 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 _OSGCOLLADAEFFECT_H_
+#define _OSGCOLLADAEFFECT_H_
+
+#include "OSGConfig.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaInstantiableElement.h"
+#include "OSGColladaElementFactoryHelper.h"
+#include "OSGMaterial.h"
+
+#include <dom/domImage.h>
+#include <dom/domCommon_color_or_texture_type.h>
+
+// forward decl
+class domProfile_COMMON;
+class domProfile_GLSL;
+class domProfile_CG;
+class domEffect;
+class domInstance_effect;
+
+
+OSG_BEGIN_NAMESPACE
+
+class OSG_FILEIO_DLLMAPPING ColladaEffect : public ColladaInstantiableElement
+{
+ /*========================== PUBLIC =================================*/
+ public:
+ /*---------------------------------------------------------------------*/
+ /*! \name Types */
+ /*! \{ */
+
+ typedef ColladaInstantiableElement Inherited;
+ typedef ColladaEffect Self;
+
+ OSG_GEN_INTERNAL_MEMOBJPTR(ColladaEffect);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Create */
+ /*! \{ */
+
+ static ColladaElementTransitPtr
+ create(daeElement *elem, ColladaGlobal *global);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Reading */
+ /*! \{ */
+
+ virtual void read (void );
+ virtual Material *createInstance(ColladaInstanceElement *instElem);
+
+ /*! \} */
+ /*========================= PROTECTED ===============================*/
+ protected:
+ /*---------------------------------------------------------------------*/
+ /*! \name Constructors/Destructor */
+ /*! \{ */
+
+ ColladaEffect(daeElement *elem, ColladaGlobal *global);
+ virtual ~ColladaEffect(void );
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Profile Handlers */
+ /*! \{ */
+
+ virtual void readProfileCommon(domProfile_COMMON *prof);
+ virtual void readProfileGLSL (domProfile_GLSL *prof);
+ virtual void readProfileCG (domProfile_CG *prof);
+
+ virtual Material *createInstanceProfileCommon(
+ domProfile_COMMON *prof, domEffect *effect,
+ domInstance_effect *instEffect );
+ virtual Material *createInstanceProfileGLSL(
+ domProfile_GLSL *prof, domEffect *effect,
+ domInstance_effect *instEffect );
+ virtual Material *createInstanceProfileCG(
+ domProfile_CG *prof, domEffect *effect,
+ domInstance_effect *instEffect );
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+
+
+
+ void readImageArray(const domImage_Array &images);
+ void fillTexColor (
+ domCommon_color_or_texture_type *colTex,
+ domCommon_color_or_texture_type::domColorRef &colOut,
+ domCommon_color_or_texture_type::domTextureRef &texOut );
+
+ static ColladaElementRegistrationHelper _regHelper;
+};
+
+OSG_GEN_MEMOBJPTR(ColladaEffect);
+
+OSG_END_NAMESPACE
+
+// #include "OSGColladaEffect.inl"
+
+#endif // OSG_WITH_COLLADA
+
+#endif // _OSGCOLLADAEFFECT_H_
View
3 Source/System/FileIO/Collada/OSGColladaElement.h
@@ -81,8 +81,7 @@ class OSG_FILEIO_DLLMAPPING ColladaElement : public MemoryObject
/*! \name Reading */
/*! \{ */
- virtual void read (void ) = 0;
- virtual FieldContainer *process(ColladaElement *parent) = 0;
+ virtual void read(void) = 0;
/*! \} */
/*---------------------------------------------------------------------*/
View
128 Source/System/FileIO/Collada/OSGColladaGeometry.cpp
@@ -36,12 +36,17 @@
* *
\*---------------------------------------------------------------------------*/
+#if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+
#include "OSGColladaGeometry.h"
#ifdef OSG_WITH_COLLADA
#include "OSGColladaLog.h"
#include "OSGColladaSource.h"
+#include "OSGColladaInstanceGeometry.h"
#include "OSGGeometry.h"
#include "OSGGroup.h"
#include "OSGTypedGeoVectorProperty.h"
@@ -87,28 +92,26 @@ ColladaGeometry::read(void)
readMesh(mesh);
}
-FieldContainer *
-ColladaGeometry::process(ColladaElement *parent)
-{
- SFATAL << "ColladaGeometry::process: <geometry> must be "
- << "instantiated to use."
- << std::endl;
-
- OSG_ASSERT(false);
-}
-
Node *
ColladaGeometry::createInstance(ColladaInstanceElement *colInstElem)
{
SWARNING << "ColladaGeometry::createInstance: NIY" << std::endl;
+ typedef ColladaInstanceGeometry::MaterialMap MaterialMap;
+ typedef ColladaInstanceGeometry::MaterialMapConstIt MaterialMapConstIt;
+
+ ColladaInstanceGeometryRefPtr colInstGeo =
+ dynamic_cast<ColladaInstanceGeometry *>(colInstElem);
+
// XXX TODO - reuse geometry if possible
// - handle <bind_material>
- NodeUnrecPtr groupN = makeCoredNode<Group>();
+ const MaterialMap &matMap = colInstGeo->getMaterialMap();
- GeoStoreConstIt gsIt = _geoStore.begin();
- GeoStoreConstIt gsEnd = _geoStore.end ();
+ NodeUnrecPtr groupN = makeCoredNode<Group>();
+
+ GeoStoreConstIt gsIt = _geoStore.begin();
+ GeoStoreConstIt gsEnd = _geoStore.end ();
for(; gsIt != gsEnd; ++gsIt)
{
@@ -135,15 +138,41 @@ ColladaGeometry::createInstance(ColladaInstanceElement *colInstElem)
}
groupN->addChild(geoN);
+
+
+ MaterialMapConstIt mmIt = matMap.find(gsIt->_matSymbol);
+
+ if(mmIt == matMap.end())
+ {
+ SWARNING << "ColladaGeometry::createInstance: No material found "
+ << "for symbol [" << gsIt->_matSymbol << "]."
+ << std::endl;
+ continue;
+ }
+
+ Material *material = mmIt->second->process(NULL);
+
+ if(material == NULL)
+ {
+ SWARNING << "ColladaGeometry::createInstance: No material created "
+ << "for symbol [" << gsIt->_matSymbol << "]."
+ << std::endl;
+ continue;
+ }
+
+ geo->setMaterial(material);
}
+ // XXX TODO: do we need to always generate a new geo?
editInstStore().push_back(groupN);
return groupN;
}
ColladaGeometry::ColladaGeometry(daeElement *elem, ColladaGlobal *global)
- : Inherited(elem, global)
+ : Inherited (elem, global)
+ , _sourceMap()
+ , _geoStore ()
{
}
@@ -262,6 +291,11 @@ ColladaGeometry::readLines(domMesh *mesh, domLines *lines)
_geoStore[geoIdx]._types ->push_back(GL_LINES);
_geoStore[geoIdx]._lengths->push_back(length );
+
+ OSG_COLLADA_LOG(("ColladaGeometry::readLines: material symbol [%s] "
+ "vertices [%d]\n",
+ (lines->getMaterial() != NULL ? lines->getMaterial() : ""),
+ length));
}
void
@@ -281,6 +315,7 @@ ColladaGeometry::readLineStrips(domMesh *mesh, domLinestrips *lineStrips)
const domP_Array &pArray = lineStrips->getP_array();
UInt32 currIdx = 0;
UInt32 length = 0;
+ UInt32 verts = 0;
for(UInt32 i = 0; i < pArray.getCount(); ++i)
{
@@ -302,8 +337,16 @@ ColladaGeometry::readLineStrips(domMesh *mesh, domLinestrips *lineStrips)
_geoStore[geoIdx]._types ->push_back(GL_LINE_STRIP);
_geoStore[geoIdx]._lengths->push_back(length );
- length = 0;
+ verts += length;
+ length = 0;
}
+
+ OSG_COLLADA_LOG(("ColladaGeometry::readLineStrips: material symbol [%s] "
+ "vertices [%d] strips [%d]\n",
+ (lineStrips->getMaterial() != NULL ?
+ lineStrips->getMaterial() : ""), verts,
+ _geoStore[geoIdx]._lengths->size()));
+
}
void
@@ -323,6 +366,7 @@ ColladaGeometry::readPolygons(domMesh *mesh, domPolygons *polygons)
const domP_Array &pArray = polygons->getP_array();
UInt32 currIdx = 0;
UInt32 length = 0;
+ UInt32 verts = 0;
for(UInt32 i = 0; i < pArray.getCount(); ++i)
{
@@ -344,7 +388,8 @@ ColladaGeometry::readPolygons(domMesh *mesh, domPolygons *polygons)
_geoStore[geoIdx]._types ->push_back(GL_POLYGON);
_geoStore[geoIdx]._lengths->push_back(length );
- length = 0;
+ verts += length;
+ length = 0;
}
const domPolygons::domPh_Array &phArray = polygons->getPh_array();
@@ -374,7 +419,8 @@ ColladaGeometry::readPolygons(domMesh *mesh, domPolygons *polygons)
_geoStore[geoIdx]._types ->push_back(GL_POLYGON);
_geoStore[geoIdx]._lengths->push_back(length );
- length = 0;
+ verts += length;
+ length = 0;
if(phArray[i]->getH_array().getCount() > 0)
{
@@ -383,6 +429,12 @@ ColladaGeometry::readPolygons(domMesh *mesh, domPolygons *polygons)
<< "] holes in polygon." << std::endl;
}
}
+
+ OSG_COLLADA_LOG(("ColladaGeometry::readPolygons: material symbol [%s] "
+ "vertices [%d] polygons [%d]\n",
+ (polygons->getMaterial() != NULL ?
+ polygons->getMaterial() : ""), verts,
+ _geoStore[geoIdx]._lengths->size()));
}
void
@@ -402,6 +454,8 @@ ColladaGeometry::readPolyList(domMesh *mesh, domPolylist *polyList)
const domListOfUInts &pList = polyList->getP ()->getValue();
const domListOfUInts &vList = polyList->getVcount()->getValue();
UInt32 currIdx = 0;
+ UInt32 verts = 0;
+ UInt32 prims = 0;
bool useQuads = true;
// check if all polys are quads
@@ -431,6 +485,9 @@ ColladaGeometry::readPolyList(domMesh *mesh, domPolylist *polyList)
_geoStore[geoIdx]._types ->push_back(GL_QUADS );
_geoStore[geoIdx]._lengths->push_back(4 * vList.getCount());
+
+ verts += 4 * vList.getCount();
+ prims += vList.getCount();
}
else
{
@@ -448,8 +505,18 @@ ColladaGeometry::readPolyList(domMesh *mesh, domPolylist *polyList)
_geoStore[geoIdx]._types ->push_back(GL_POLYGON);
_geoStore[geoIdx]._lengths->push_back(vList[i] );
+
+ verts += vList[i];
+ prims += 1;
}
}
+
+ OSG_COLLADA_LOG(("ColladaGeometry::readPolyList: material symbol [%s] "
+ "vertices [%d] %s [%d]\n",
+ (polyList->getMaterial() != NULL ?
+ polyList->getMaterial() : ""),
+ verts,
+ (useQuads == true ? "quads" : "polygons"), prims));
}
void
@@ -485,6 +552,12 @@ ColladaGeometry::readTriangles(domMesh *mesh, domTriangles *triangles)
_geoStore[geoIdx]._types ->push_back(GL_TRIANGLES);
_geoStore[geoIdx]._lengths->push_back(length );
+
+ OSG_COLLADA_LOG(("ColladaGeometry::readTriangles: material symbol [%s] "
+ "vertices [%d] triangles [%d]\n",
+ (triangles->getMaterial() != NULL ?
+ triangles->getMaterial() : ""),
+ length, length/3));
}
void
@@ -504,6 +577,7 @@ ColladaGeometry::readTriFans(domMesh *mesh, domTrifans *triFans)
const domP_Array &pArray = triFans->getP_array();
UInt32 currIdx = 0;
UInt32 length = 0;
+ UInt32 verts = 0;
for(UInt32 i = 0; i < pArray.getCount(); ++i)
{
@@ -525,8 +599,15 @@ ColladaGeometry::readTriFans(domMesh *mesh, domTrifans *triFans)
_geoStore[geoIdx]._types ->push_back(GL_TRIANGLE_FAN);
_geoStore[geoIdx]._lengths->push_back(length );
- length = 0;
+ verts += length;
+ length = 0;
}
+
+ OSG_COLLADA_LOG(("ColladaGeometry::readTriFans: material symbol [%s] "
+ "vertices [%d] fans [%d]\n",
+ (triFans->getMaterial() != NULL ?
+ triFans->getMaterial() : ""), verts,
+ _geoStore[geoIdx]._lengths->size()));
}
void
@@ -546,6 +627,7 @@ ColladaGeometry::readTriStrips(domMesh *mesh, domTristrips *triStrips)
const domP_Array &pArray = triStrips->getP_array();
UInt32 currIdx = 0;
UInt32 length = 0;
+ UInt32 verts = 0;
for(UInt32 i = 0; i < pArray.getCount(); ++i)
{
@@ -567,8 +649,16 @@ ColladaGeometry::readTriStrips(domMesh *mesh, domTristrips *triStrips)
_geoStore[geoIdx]._types ->push_back(GL_TRIANGLE_STRIP);
_geoStore[geoIdx]._lengths->push_back(length );
- length = 0;
+ verts += length;
+ length = 0;
}
+
+ OSG_COLLADA_LOG(("ColladaGeometry::readTriStrips: material symbol [%s] "
+ "vertices [%d] strips [%d]\n",
+ (triStrips->getMaterial() != NULL ?
+ triStrips->getMaterial() : ""), verts,
+ _geoStore[geoIdx]._lengths->size()));
+
}
UInt32
View
2 Source/System/FileIO/Collada/OSGColladaGeometry.h
@@ -98,8 +98,6 @@ class OSG_FILEIO_DLLMAPPING ColladaGeometry : public ColladaInstantiableElement
/*! \{ */
virtual void read (void );
- virtual FieldContainer *process (ColladaElement *parent );
-
virtual Node *createInstance(ColladaInstanceElement *instElem);
/*! \} */
View
9 Source/System/FileIO/Collada/OSGColladaGlobal.cpp
@@ -4,6 +4,7 @@
#ifdef OSG_WITH_COLLADA
#include "OSGColladaLog.h"
+#include "OSGColladaScene.h"
#include "OSGColladaElementFactory.h"
#include "OSGColladaOptions.h"
@@ -118,11 +119,11 @@ ColladaGlobal::doRead(DAE *dae)
if(scene != NULL)
{
- ColladaElementRefPtr sceneElem =
- ColladaElementFactory::the()->create(scene, this);
+ ColladaSceneRefPtr colScene = dynamic_pointer_cast<ColladaScene>(
+ ColladaElementFactory::the()->create(scene, this));
- sceneElem->read ( );
- sceneElem->process(NULL);
+ colScene->read ();
+ colScene->process();
}
else
{
View
122 Source/System/FileIO/Collada/OSGColladaImage.cpp
@@ -0,0 +1,122 @@
+/*---------------------------------------------------------------------------*\
+ * 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 "OSGColladaImage.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaLog.h"
+#include "OSGImageFileHandler.h"
+
+#include <dom/domImage.h>
+
+OSG_BEGIN_NAMESPACE
+
+ColladaElementRegistrationHelper ColladaImage::_regHelper(
+ &ColladaImage::create, "image");
+
+ColladaElementTransitPtr
+ColladaImage::create(daeElement *elem, ColladaGlobal *global)
+{
+ return ColladaElementTransitPtr(new ColladaImage(elem, global));
+}
+
+void
+ColladaImage::read(void)
+{
+ OSG_COLLADA_LOG(("ColladaImage::read\n"));
+
+ domImageRef image = getDOMElementAs<domImage>();
+
+ domImage::domInit_fromRef initFrom = image->getInit_from();
+
+ if(initFrom != NULL)
+ {
+ daeURI imageURI = initFrom->getValue();
+ std::string imagePath = imageURI.path();
+
+ OSG_COLLADA_LOG(("ColladaImage::read: URI [%s] path [%s]\n",
+ imageURI.getURI(), imagePath.c_str()));
+
+#ifdef WIN32
+ if(imagePath.size() > 3 &&
+ imagePath[0] == '/' &&
+ imagePath[2] == ':' )
+ {
+ _image =
+ ImageFileHandler::the()->read(imagePath.substr(1).c_str());
+ }
+ else
+ {
+ _image = ImageFileHandler::the()->read(imagePath.c_str());
+ }
+#else
+ _image = ImageFileHandler::the()->read(imagePath.c_str());
+#endif
+
+ if(_image == NULL)
+ {
+ SWARNING << "ColladaImage::read: Loading of image ["
+ << imagePath << "] failed." << std::endl;
+ }
+ }
+ else
+ {
+ SWARNING << "ColladaImage::read: No <init_from> tag found."
+ << std::endl;
+ }
+}
+
+ColladaImage::ColladaImage(daeElement *elem, ColladaGlobal *global)
+ : Inherited(elem, global)
+ , _image (NULL)
+{
+}
+
+ColladaImage::~ColladaImage(void)
+{
+}
+
+OSG_END_NAMESPACE
+
+#endif // OSG_WITH_COLLADA
+
View
106 Source/System/FileIO/Collada/OSGColladaImage.h
@@ -0,0 +1,106 @@
+/*---------------------------------------------------------------------------*\
+ * 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 _OSGCOLLADAIMAGE_H_
+#define _OSGCOLLADAIMAGE_H_
+
+#include "OSGConfig.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaElement.h"
+#include "OSGColladaElementFactoryHelper.h"
+#include "OSGImage.h"
+
+OSG_BEGIN_NAMESPACE
+
+class OSG_FILEIO_DLLMAPPING ColladaImage : public ColladaElement
+{
+ /*========================== PUBLIC =================================*/
+ public:
+ /*---------------------------------------------------------------------*/
+ /*! \name Types */
+ /*! \{ */
+
+ typedef ColladaElement Inherited;
+ typedef ColladaImage Self;
+
+ OSG_GEN_INTERNAL_MEMOBJPTR(ColladaImage);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Create */
+ /*! \{ */
+
+ static ColladaElementTransitPtr
+ create(daeElement *elem, ColladaGlobal *global);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Reading */
+ /*! \{ */
+
+ virtual void read(void);
+
+ /*! \} */
+ /*========================= PROTECTED ===============================*/
+ protected:
+ /*---------------------------------------------------------------------*/
+ /*! \name Constructors/Destructor */
+ /*! \{ */
+
+ ColladaImage(daeElement *elem, ColladaGlobal *global);
+ virtual ~ColladaImage(void );
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+
+ static ColladaElementRegistrationHelper _regHelper;
+
+ ImageUnrecPtr _image;
+};
+
+OSG_GEN_MEMOBJPTR(ColladaImage);
+
+OSG_END_NAMESPACE
+
+// #include "OSGColladaImage.inl"
+
+#endif // OSG_WITH_COLLADA
+
+#endif // _OSGCOLLADAIMAGE_H_
View
158 Source/System/FileIO/Collada/OSGColladaInstanceEffect.cpp
@@ -0,0 +1,158 @@
+/*---------------------------------------------------------------------------*\
+ * 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 "OSGColladaInstanceEffect.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaLog.h"
+
+#include <dom/domInstance_effect.h>
+
+OSG_BEGIN_NAMESPACE
+
+ColladaElementRegistrationHelper ColladaInstanceEffect::_regHelper(
+ &ColladaInstanceEffect::create, "instance_effect");
+
+ColladaElementTransitPtr
+ColladaInstanceEffect::create(daeElement *elem, ColladaGlobal *global)
+{
+ return ColladaElementTransitPtr(new ColladaInstanceEffect(elem, global));
+}
+
+void
+ColladaInstanceEffect::read(void)
+{
+ OSG_COLLADA_LOG(("ColladaInstanceEffect::read\n"));
+
+ ColladaEffectRefPtr colEffect = getSourceElem();
+
+ if(colEffect == NULL)
+ {
+ colEffect = dynamic_pointer_cast<ColladaEffect>(
+ ColladaElementFactory::the()->create(
+ getSourceDOMElem(), getGlobal()));
+
+ colEffect->read();
+ }
+
+ domInstance_effectRef instEffect = getDOMElementAs<domInstance_effect>();
+
+ const domInstance_effect::domTechnique_hint_Array &techHints =
+ instEffect->getTechnique_hint_array();
+
+ if(techHints.getCount() > 0)
+ {
+ SWARNING << "ColladaInstanceEffect::read: Ignoring ["
+ << techHints.getCount() << "] <technique_hint> elements."
+ << std::endl;
+ }
+
+ const domInstance_effect::domSetparam_Array &setParams =
+ instEffect->getSetparam_array();
+
+ if(setParams.getCount() > 0)
+ {
+ SWARNING << "ColladaInstanceEffect::read: Ignoring ["
+ << setParams.getCount() << "] <setparam> elements."
+ << std::endl;
+ }
+}
+
+FieldContainer *
+ColladaInstanceEffect::process(ColladaElement *parent)
+{
+ OSG_COLLADA_LOG(("ColaldaInstanceEffect::process\n"));
+
+ ColladaEffectRefPtr colEffect = getSourceElem();
+
+ return colEffect->createInstance(this);
+}
+
+ColladaEffect *
+ColladaInstanceEffect::getSourceElem(void) const
+{
+ ColladaEffect *retVal = NULL;
+ domEffectRef sourceElem = getSourceDOMElem();
+
+ if(sourceElem != NULL)
+ {
+ retVal = getUserDataAs<ColladaEffect>(sourceElem);
+ }
+
+ return retVal;
+}
+
+domEffect *
+ColladaInstanceEffect::getSourceDOMElem(void) const
+{
+ domEffectRef retVal = NULL;
+ domInstance_effectRef instEffect = getDOMElementAs<domInstance_effect>();
+
+ if(instEffect->getUrl().getElement() != NULL)
+ {
+ retVal = daeSafeCast<domEffect>(instEffect->getUrl().getElement());
+ }
+ else
+ {
+ SWARNING << "ColladaInstanceEffet::getSourceDOMElem: "
+ << "can not resolve URL [" << instEffect->getUrl().str()
+ << "]." << std::endl;
+ }
+
+ return retVal;
+}
+
+ColladaInstanceEffect::ColladaInstanceEffect(
+ daeElement *elem, ColladaGlobal *global)
+
+ : Inherited(elem, global)
+{
+}
+
+ColladaInstanceEffect::~ColladaInstanceEffect(void)
+{
+}
+
+OSG_END_NAMESPACE
+
+#endif // OSG_WITH_COLLADA
View
116 Source/System/FileIO/Collada/OSGColladaInstanceEffect.h
@@ -0,0 +1,116 @@
+/*---------------------------------------------------------------------------*\
+ * 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 _OSGCOLLADAINSTANCEEFFECT_H_
+#define _OSGCOLLADAINSTANCEEFFECT_H_
+
+#include "OSGConfig.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaInstanceElement.h"
+#include "OSGColladaEffect.h"
+#include "OSGColladaElementFactoryHelper.h"
+
+#include <dom/domEffect.h>
+
+OSG_BEGIN_NAMESPACE
+
+class OSG_FILEIO_DLLMAPPING ColladaInstanceEffect
+ : public ColladaInstanceElement
+{
+ /*========================== PUBLIC =================================*/
+ public:
+ /*---------------------------------------------------------------------*/
+ /*! \name Types */
+ /*! \{ */
+
+ typedef ColladaInstanceElement Inherited;
+ typedef ColladaInstanceEffect Self;
+
+ OSG_GEN_INTERNAL_MEMOBJPTR(ColladaInstanceEffect);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Craete */
+ /*! \{ */
+
+ static ColladaElementTransitPtr
+ create(daeElement *elem, ColladaGlobal *global);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Reading */
+ /*! \{ */
+
+ virtual void read (void );
+ virtual FieldContainer *process(ColladaElement *parent);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Access */
+ /*! \{ */
+
+ virtual ColladaEffect *getSourceElem (void) const;
+ virtual domEffect *getSourceDOMElem(void) const;
+
+ /*! \} */
+ /*========================= PROTECTED ===============================*/
+ protected:
+ /*---------------------------------------------------------------------*/
+ /*! \name Constructors/Destructor */
+ /*! \{ */
+
+ ColladaInstanceEffect(daeElement *elem, ColladaGlobal *global);
+ virtual ~ColladaInstanceEffect(void );
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+
+ static ColladaElementRegistrationHelper _regHelper;
+};
+
+OSG_GEN_MEMOBJPTR(ColladaInstanceEffect);
+
+OSG_END_NAMESPACE
+
+// #include "OSGColladaInstanceEffect.inl"
+
+#endif // OSG_WITH_COLLADA
+
+#endif // _OSGCOLLADAINSTANCEEFFECT_H_
View
63 Source/System/FileIO/Collada/OSGColladaInstanceGeometry.cpp
@@ -36,13 +36,20 @@
* *
\*---------------------------------------------------------------------------*/
+#if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+
#include "OSGColladaInstanceGeometry.h"
#ifdef OSG_WITH_COLLADA
#include "OSGColladaLog.h"
#include <dom/domInstance_geometry.h>
+#include <dom/domInstance_material.h>
+#include <dom/domBind_material.h>
+#include <dom/domParam.h>
OSG_BEGIN_NAMESPACE
@@ -71,11 +78,59 @@ ColladaInstanceGeometry::read(void)
colGeo->read();
}
+
+ domInstance_geometryRef instGeo = getDOMElementAs<domInstance_geometry>();
+ domBind_materialRef bindMat = instGeo->getBind_material ();
+
+ if(bindMat == NULL)
+ {
+ SWARNING << "ColladaInstanceGeometry::read: No <bind_material> found."
+ << std::endl;
+ return;
+ }
+
+ domBind_material::domTechnique_commonRef techCom =
+ bindMat->getTechnique_common();
+ const domInstance_material_Array &instMatArray =
+ techCom->getInstance_material_array();
+
+ for(UInt32 i = 0; i < instMatArray.getCount(); ++i)
+ {
+ ColladaInstanceMaterialRefPtr colInstMat =
+ getUserDataAs<ColladaInstanceMaterial>(instMatArray[i]);
+
+ if(colInstMat == NULL)
+ {
+ colInstMat = dynamic_pointer_cast<ColladaInstanceMaterial>(
+ ColladaElementFactory::the()->create(
+ instMatArray[i], getGlobal()));
+
+ colInstMat->read();
+ }
+
+ _matMap[colInstMat->getSymbol()] = colInstMat;
+
+ OSG_COLLADA_LOG(("ColladaInstanceGeometry::read: binding symbol [%s] "
+ "to target [%s]\n",
+ colInstMat->getSymbol().c_str(),
+ instMatArray[i]->getTarget().getURI()));
+ }
+
+ const domParam_Array &params = bindMat->getParam_array();
+
+ if(params.getCount() > 0)
+ {
+ SWARNING << "ColladaInstanceGeometry::read: Ignoring ["
+ << params.getCount() << "] <param> elements."
+ << std::endl;
+ }
}
Node *
ColladaInstanceGeometry::process(ColladaElement *parent)
{
+ OSG_COLLADA_LOG(("ColladaInstanceGeometry::process\n"));
+
ColladaGeometryRefPtr colGeo = getSourceElem();
return colGeo->createInstance(this);
@@ -109,16 +164,24 @@ ColladaInstanceGeometry::getSourceDOMElem(void) const
return retVal;
}
+const ColladaInstanceGeometry::MaterialMap &
+ColladaInstanceGeometry::getMaterialMap(void) const
+{
+ return _matMap;
+}
+
ColladaInstanceGeometry::ColladaInstanceGeometry(
daeElement *elem, ColladaGlobal *global)
: Inherited(elem, global)
+ , _matMap ()
{
}
ColladaInstanceGeometry::~ColladaInstanceGeometry(void)
{
}
+
OSG_END_NAMESPACE
#endif // OSG_WITH_COLLADA
View
11 Source/System/FileIO/Collada/OSGColladaInstanceGeometry.h
@@ -45,6 +45,7 @@
#include "OSGColladaInstanceElement.h"
#include "OSGColladaGeometry.h"
+#include "OSGColladaInstanceMaterial.h"
#include "OSGColladaElementFactoryHelper.h"
#include <dom/domGeometry.h>
@@ -65,6 +66,12 @@ class OSG_FILEIO_DLLMAPPING ColladaInstanceGeometry
OSG_GEN_INTERNAL_MEMOBJPTR(ColladaInstanceGeometry);
+ // map material symbol to material instance
+ typedef std::map<std::string,
+ ColladaInstanceMaterialRefPtr> MaterialMap;
+ typedef MaterialMap::iterator MaterialMapIt;
+ typedef MaterialMap::const_iterator MaterialMapConstIt;
+
/*! \} */
/*---------------------------------------------------------------------*/
/*! \name Craete */
@@ -89,6 +96,8 @@ class OSG_FILEIO_DLLMAPPING ColladaInstanceGeometry
virtual ColladaGeometry *getSourceElem (void) const;
virtual domGeometry *getSourceDOMElem(void) const;
+ const MaterialMap &getMaterialMap (void) const;
+
/*! \} */
/*========================= PROTECTED ===============================*/
protected:
@@ -103,6 +112,8 @@ class OSG_FILEIO_DLLMAPPING ColladaInstanceGeometry
/*---------------------------------------------------------------------*/
static ColladaElementRegistrationHelper _regHelper;
+
+ MaterialMap _matMap;
};
OSG_GEN_MEMOBJPTR(ColladaInstanceGeometry);
View
205 Source/System/FileIO/Collada/OSGColladaInstanceMaterial.cpp
@@ -0,0 +1,205 @@
+/*---------------------------------------------------------------------------*\
+ * 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 "OSGColladaInstanceMaterial.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaLog.h"
+
+#include <dom/domInstance_material.h>
+
+OSG_BEGIN_NAMESPACE
+
+ColladaElementRegistrationHelper ColladaInstanceMaterial::_regHelper(
+ &ColladaInstanceMaterial::create, "instance_material");
+
+ColladaElementTransitPtr
+ColladaInstanceMaterial::create(daeElement *elem, ColladaGlobal *global)
+{
+ return ColladaElementTransitPtr(new ColladaInstanceMaterial(elem, global));
+}
+
+void
+ColladaInstanceMaterial::read(void)
+{
+ OSG_COLLADA_LOG(("ColladaInstanceMaterial::read\n"));
+
+ ColladaMaterialRefPtr colMat = getSourceElem ();
+
+ if(colMat == NULL)
+ {
+ colMat = dynamic_pointer_cast<ColladaMaterial>(
+ ColladaElementFactory::the()->create(
+ getSourceDOMElem(), getGlobal()));
+
+ colMat->read();
+ }
+
+ domInstance_materialRef instMat =
+ getDOMElementAs<domInstance_material>();
+ const domInstance_material::domBind_Array &binds =
+ instMat->getBind_array();
+
+ _bindStore.resize(binds.getCount());
+
+ for(UInt32 i = 0; i < binds.getCount(); ++i)
+ {
+ std::string target = binds[i]->getTarget();
+ std::string semantic;
+
+ if(binds[i]->getSemantic() != NULL)
+ {
+ semantic = binds[i]->getSemantic();
+ }
+
+ OSG_COLLADA_LOG(("ColladaInstanceMaterial::read: "
+ "<bind> semantic [%s] target [%s]\n",
+ semantic.c_str(), target.c_str()));
+
+ _bindStore[i].semantic = semantic;
+ _bindStore[i].target = target;
+ }
+
+ const domInstance_material::domBind_vertex_input_Array &bindVerts =
+ instMat->getBind_vertex_input_array();
+
+ _bindVertexStore.resize(bindVerts.getCount());
+
+ for(UInt32 i = 0; i < bindVerts.getCount(); ++i)
+ {
+ std::string semantic = bindVerts[i]->getSemantic ();
+ std::string inSemantic = bindVerts[i]->getInput_semantic();
+ UInt32 inSet = bindVerts[i]->getInput_set ();
+
+ OSG_COLLADA_LOG(("ColladaInstanceMaterial::read "
+ "<bind_vertex_input> semantic [%s] "
+ "inSemantic [%s] inSet [%d]\n",
+ semantic.c_str(), inSemantic.c_str(), inSet));
+
+ _bindVertexStore[i].semantic = semantic;
+ _bindVertexStore[i].inSemantic = inSemantic;
+ _bindVertexStore[i].inSet = inSet;
+ }
+
+ if(instMat->getSymbol() != NULL)
+ {
+ _symbol = instMat->getSymbol();
+ }
+ else
+ {
+ SFATAL << "ColladaInstanceMaterial::read: No symbol."
+ << std::endl;
+ }
+}
+
+Material *
+ColladaInstanceMaterial::process(ColladaElement *parent)
+{
+ ColladaMaterialRefPtr colMat = getSourceElem();
+
+ return colMat->createInstance(this);
+}
+
+ColladaMaterial *
+ColladaInstanceMaterial::getSourceElem(void) const
+{
+ ColladaMaterial *retVal = NULL;
+ domMaterialRef sourceElem = getSourceDOMElem();
+
+ if(sourceElem != NULL)
+ {
+ retVal = getUserDataAs<ColladaMaterial>(sourceElem);
+ }
+
+ return retVal;
+}
+
+domMaterial *
+ColladaInstanceMaterial::getSourceDOMElem(void) const
+{
+ domMaterialRef retVal = NULL;
+ domInstance_materialRef instMat = getDOMElementAs<domInstance_material>();
+
+ if(instMat->getTarget().getElement() != NULL)
+ {
+ retVal = daeSafeCast<domMaterial>(instMat->getTarget().getElement());
+ }
+
+ return retVal;
+}
+
+const std::string &
+ColladaInstanceMaterial::getSymbol(void) const
+{
+ return _symbol;
+}
+
+const ColladaInstanceMaterial::BindStore &
+ColladaInstanceMaterial::getBindStore(void) const
+{
+ return _bindStore;
+}
+
+const ColladaInstanceMaterial::BindVertexStore &
+ColladaInstanceMaterial::getBindVertexStore(void) const
+{
+ return _bindVertexStore;
+}
+
+ColladaInstanceMaterial::ColladaInstanceMaterial(
+ daeElement *elem, ColladaGlobal *global)
+
+ : Inherited (elem, global)
+ , _symbol ()
+ , _bindStore ()
+ , _bindVertexStore()
+{
+}
+
+ColladaInstanceMaterial::~ColladaInstanceMaterial(void)
+{
+}
+
+OSG_END_NAMESPACE
+
+#endif // OSG_WITH_COLLADA
View
146 Source/System/FileIO/Collada/OSGColladaInstanceMaterial.h
@@ -0,0 +1,146 @@
+/*---------------------------------------------------------------------------*\
+ * 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 _OSGCOLLADAINSTANCEMATERIAL_H_
+#define _OSGCOLLADAINSTANCEMATERIAL_H_
+
+#include "OSGConfig.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaInstanceElement.h"
+#include "OSGColladaMaterial.h"
+#include "OSGColladaElementFactoryHelper.h"
+
+#include <dom/domMaterial.h>
+
+OSG_BEGIN_NAMESPACE
+
+class OSG_FILEIO_DLLMAPPING ColladaInstanceMaterial
+ : public ColladaInstanceElement
+{
+ /*========================== PUBLIC =================================*/
+ public:
+ /*---------------------------------------------------------------------*/
+ /*! \name Types */
+ /*! \{ */
+
+ typedef ColladaInstanceElement Inherited;
+ typedef ColladaInstanceMaterial Self;
+
+ OSG_GEN_INTERNAL_MEMOBJPTR(ColladaInstanceMaterial);
+
+ struct BindInfo
+ {
+ std::string semantic;
+ std::string target;
+ };
+
+ typedef std::vector<BindInfo> BindStore;
+ typedef BindStore::iterator BindStoreIt;
+ typedef BindStore::const_iterator BindStoreConstIt;
+
+ struct BindVertexInfo
+ {
+ std::string semantic;
+ std::string inSemantic;
+ UInt32 inSet;
+ };
+
+ typedef std::vector<BindVertexInfo> BindVertexStore;
+ typedef BindVertexStore::iterator BindVertexStoreIt;
+ typedef BindVertexStore::const_iterator BindVertexStoreConstIt;
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Craete */
+ /*! \{ */
+
+ static ColladaElementTransitPtr
+ create(daeElement *elem, ColladaGlobal *global);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Reading */
+ /*! \{ */
+
+ virtual void read (void );
+ virtual Material *process(ColladaElement *parent);
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+ /*! \name Access */
+ /*! \{ */
+
+ virtual ColladaMaterial *getSourceElem (void) const;
+ virtual domMaterial *getSourceDOMElem (void) const;
+
+ const std::string &getSymbol (void) const;
+
+ const BindStore &getBindStore (void) const;
+ const BindVertexStore &getBindVertexStore(void) const;
+
+ /*! \} */
+ /*========================= PROTECTED ===============================*/
+ protected:
+ /*---------------------------------------------------------------------*/
+ /*! \name Constructors/Destructor */
+ /*! \{ */
+
+ ColladaInstanceMaterial(daeElement *elem, ColladaGlobal *global);
+ virtual ~ColladaInstanceMaterial(void );
+
+ /*! \} */
+ /*---------------------------------------------------------------------*/
+
+ static ColladaElementRegistrationHelper _regHelper;
+
+ std::string _symbol;
+ BindStore _bindStore;
+ BindVertexStore _bindVertexStore;
+};
+
+OSG_GEN_MEMOBJPTR(ColladaInstanceMaterial);
+
+OSG_END_NAMESPACE
+
+// #include "OSGColladaInstanceMaterial.inl"
+
+#endif // OSG_WITH_COLLADA
+
+#endif // _OSGCOLLADAINSTANCEMATERIAL_H_
View
11 Source/System/FileIO/Collada/OSGColladaInstantiableElement.cpp
@@ -42,17 +42,6 @@
OSG_BEGIN_NAMESPACE
-FieldContainer *
-ColladaInstantiableElement::process(ColladaElement *parent)
-{
- SFATAL << "ColladaInstantiableElement::process: "
- << "InstantiableElements must be created from their "
- << "respective <instance_*> elements with createInstance()"
- << std::endl;
-
- return NULL;
-}
-
ColladaInstantiableElement::ColladaInstantiableElement(
daeElement *elem, ColladaGlobal *global)
View
3 Source/System/FileIO/Collada/OSGColladaInstantiableElement.h
@@ -82,9 +82,6 @@ class OSG_FILEIO_DLLMAPPING ColladaInstantiableElement : public ColladaElement
virtual void
read (void ) = 0;
virtual FieldContainer *
- process (ColladaElement *parent );
-
- virtual FieldContainer *
createInstance(ColladaInstanceElement *instElem) = 0;
/*! \} */
View
104 Source/System/FileIO/Collada/OSGColladaMaterial.cpp
@@ -0,0 +1,104 @@
+/*---------------------------------------------------------------------------*\
+ * 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 "OSGColladaMaterial.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaLog.h"
+#include "OSGColladaInstanceMaterial.h"
+#include "OSGColladaInstanceEffect.h"
+
+#include <dom/domMaterial.h>
+#include <dom/domInstance_effect.h>
+
+OSG_BEGIN_NAMESPACE
+
+ColladaElementRegistrationHelper ColladaMaterial::_regHelper(
+ &ColladaMaterial::create, "material");
+
+
+ColladaElementTransitPtr
+ColladaMaterial::create(daeElement *elem, ColladaGlobal *global)
+{
+ return ColladaElementTransitPtr(new ColladaMaterial(elem, global));
+}
+
+void
+ColladaMaterial::read(void)
+{
+ OSG_COLLADA_LOG(("ColladaMaterial::read\n"));
+
+ domMaterialRef material = getDOMElementAs<domMaterial>();
+ domInstance_effectRef instEffect = material->getInstance_effect();
+ ColladaInstanceEffectRefPtr colInstEffect =
+ getUserDataAs<ColladaInstanceEffect>(instEffect);
+
+ if(colInstEffect == NULL)
+ {
+ colInstEffect = dynamic_pointer_cast<ColladaInstanceEffect>(
+ ColladaElementFactory::the()->create(instEffect, getGlobal()));
+
+ colInstEffect->read();
+ }
+}
+
+Material *
+ColladaMaterial::createInstance(ColladaInstanceElement *colInstElem)
+{
+ SWARNING << "ColladaMaterial::craeteInstance: NIY" << std::endl;
+
+ return NULL;
+}
+
+ColladaMaterial::ColladaMaterial(daeElement *elem, ColladaGlobal *global)
+ : Inherited(elem, global)
+{
+}
+
+ColladaMaterial::~ColladaMaterial(void)
+{
+}
+
+OSG_END_NAMESPACE
+
+#endif // OSG_WITH_COLLADA
View
103 Source/System/FileIO/Collada/OSGColladaMaterial.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 _OSGCOLLADAMATERIAL_H_
+#define _OSGCOLLADAMATERIAL_H_
+
+#include "OSGConfig.h"
+
+#ifdef OSG_WITH_COLLADA
+
+#include "OSGColladaInstantiableElement.h"
+#include "OSGColladaElementFactoryHelper.h"