/Source/System/FileIO/WRL/OSGVRMLNodeHelper.cpp
C++ | 4404 lines | 3225 code | 852 blank | 327 comment | 650 complexity | 62a20f49afd395153da1be6af612e5b8 MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- /*---------------------------------------------------------------------------*\
- * OpenSG *
- * *
- * *
- * Copyright (C) 2000-2002 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 *
- * *
- * *
- * *
- * *
- * *
- * *
- \*---------------------------------------------------------------------------*/
- #include <cstdlib>
- #include <cstdio>
- #include "OSGConfig.h"
- #include <iostream>
- #include <fstream>
- #include "OSGVRMLNodeHelper.h"
- #include "OSGSingletonHolder.ins"
- #include "OSGScanParseSkel.h"
- #include "OSGSceneFileHandler.h"
- #include "OSGNameAttachment.h"
- #include "OSGNode.h"
- #include "OSGGroup.h"
- #include "OSGMaterialGroup.h"
- #include "OSGChunkMaterial.h"
- #include "OSGGeometry.h"
- #include "OSGGeoFunctions.h"
- #include "OSGChunkMaterial.h"
- #include "OSGMaterialChunk.h"
- #include "OSGBlendChunk.h"
- #include "OSGTextureObjChunk.h"
- #include "OSGTextureEnvChunk.h"
- #include "OSGImageFileHandler.h"
- #include "OSGSimpleGeometry.h"
- #include "OSGComponentTransform.h"
- #include "OSGInline.h"
- #include "OSGSwitch.h"
- #include "OSGTimeSensor.h"
- #include "OSGVRMLOrientationInterpolator.h"
- #include "OSGVRMLPositionInterpolator.h"
- #include "OSGVRMLCoordinateInterpolator.h"
- #include "OSGVRMLScalarInterpolator.h"
- #ifndef OSG_LOG_MODULE
- #define OSG_LOG_MODULE "VRMLLoader"
- #endif
- #define OSG_DEBUG_VRML
- #ifndef OSG_DO_DOC
- # ifdef OSG_DEBUG_VRML
- # define OSG_VRML_ARG(ARG) ARG
- # else
- # define OSG_VRML_ARG(ARG)
- # endif
- #else
- # define OSG_VRML_ARG(ARG) ARG
- #endif
- OSG_BEGIN_NAMESPACE
- OSG_DYNFIELDATTACHMENT_INST(VRMLGenericAttDesc)
- OSG_SINGLETON_INST(VRMLNodeHelperFactoryBase, addPostFactoryExitFunction)
- template class SingletonHolder<VRMLNodeHelperFactoryBase>;
- //---------------------------------------------------------------------------
- // Class
- //---------------------------------------------------------------------------
- VRMLNodeHelperFactoryBase::RegisterHelper::RegisterHelper(
- CreateHelper fCreate,
- const Char8 *szNodeName,
- InitFuncF fStaticInit)
- {
- VRMLNodeHelperFactory::the()->registerNodeHelper(fCreate,
- szNodeName);
- if(fStaticInit)
- addPostFactoryInitFunction(fStaticInit);
- }
- VRMLNodeHelperFactoryBase::VRMLNodeHelperFactoryBase(void) :
- _mRegisteredNodeHelperHash()
- {
- }
- VRMLNodeHelperFactoryBase::~VRMLNodeHelperFactoryBase(void)
- {
- }
- void VRMLNodeHelperFactoryBase::registerNodeHelper(
- CreateHelper fHelper,
- const Char8 *szNodeName)
- {
- if(szNodeName == NULL || fHelper == NULL)
- return;
- NameHelperCreateMap::iterator mNodeHelperIt =
- _mRegisteredNodeHelperHash.find(szNodeName);
-
- if(mNodeHelperIt == _mRegisteredNodeHelperHash.end())
- {
- _mRegisteredNodeHelperHash[szNodeName] = fHelper;
- PINFO << "Helper registered for "
- << szNodeName
- << std::endl;
- }
- else
- {
- PWARNING << "Helper already registered for %s "
- << szNodeName
- << std::endl;
- }
- }
- VRMLNodeHelper *VRMLNodeHelperFactoryBase::createHelper(
- const Char8 *szNodeName)
- {
- if(szNodeName == NULL)
- return NULL;
- NameHelperCreateMap::iterator mNodeHelperIt =
- _mRegisteredNodeHelperHash.find(szNodeName);
-
- if(mNodeHelperIt != _mRegisteredNodeHelperHash.end())
- {
- return (*mNodeHelperIt).second();
- }
- else
- {
- return NULL;
- }
- }
- /*! \defgroup GrpSystemFileIOVRML VRML-specific File Input/Output
- \ingroup GrpSystemFileIO
- See \ref PageSystemFileIO for details.
- */
- //---------------------------------------------------------------------------
- // Class
- //---------------------------------------------------------------------------
- /*! \class OSG::VRMLNodeDesc
- \ingroup GrpSystemFileIOVRML
- General VRML Node description
- */
- UInt32 VRMLNodeHelper::_uiIndent = 0;
- /*-------------------------------------------------------------------------*/
- /* Static Get */
- UInt32 VRMLNodeHelper::getIndent(void)
- {
- return _uiIndent;
- }
- void VRMLNodeHelper::incIndent(void)
- {
- _uiIndent += 4;
- }
- void VRMLNodeHelper::decIndent(void)
- {
- if(_uiIndent < 4)
- {
- // PWARNING << "Indent smaller 4 decremented" << std::endl;
- _uiIndent = 4;
- }
- _uiIndent -= 4;
- }
- void VRMLNodeHelper::resetIndent(void)
- {
- _uiIndent = 0;
- }
- /*-------------------------------------------------------------------------*/
- /* Constructors */
- #define OSG_INIT_DESC(VAR, TYPE, NAME) \
- VAR(TYPE::getClassType(), \
- NAME, \
- "VRML Helper", \
- 0, \
- 0, \
- true, \
- Field::SFDefaultFlags, \
- static_cast<FieldEditMethodSig>(&Node::invalidEditField), \
- NULL)
- VRMLNodeHelper::VRMLNodeHelper(void) :
- _bProtoInterfaceDone(false ),
- _pGenAttProto (NULL ),
- _pNodeProto (NULL ),
- _pNodeCoreProto (NULL ),
- OSG_INIT_DESC(_sfVec3fDesc,
- SFVec3f,
- "sfVec3fHelperDesc" ),
- OSG_INIT_DESC(_sfFCPtrDesc,
- SFUnrecFieldContainerPtr,
- "sfFCPtrHelperDesc" ),
- OSG_INIT_DESC(_sfImagePtrDesc,
- SFUnrecImagePtr,
- "sfImageHelperDesc" ),
- OSG_INIT_DESC(_sfReal32Desc,
- SFReal32,
- "sfReal32HelperDesc" ),
- OSG_INIT_DESC(_sfColor3fDesc,
- SFColor3f,
- "sfColor3fHelperDesc"),
- OSG_INIT_DESC(_mfStringDesc,
- MFString,
- "mfStringHelperDesc" ),
- OSG_INIT_DESC(_sfBoolDesc,
- SFBool,
- "sfBoolDesc" )
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Destructor */
- VRMLNodeHelper::~VRMLNodeHelper(void)
- {
- _pNodeProto = NULL;
- _pNodeCoreProto = NULL;
- _pGenAttProto = NULL;
- }
- /*-------------------------------------------------------------------------*/
- /* Helper */
- void VRMLNodeHelper::reset(void)
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Field */
- FieldContainerTransitPtr VRMLNodeHelper::beginNode(
- const Char8 *szTypename,
- const Char8 *szName,
- FieldContainer *pCurrentFC)
- {
- FieldContainerUnrecPtr returnValue = NULL;
- NodeUnrecPtr pNode = NULL;
- NodeCoreUnrecPtr pCore = NULL;
- VRMLGenericAttUnrecPtr pAtt = NULL;
- if(_pNodeProto != NULL)
- {
- returnValue = _pNodeProto->shallowCopy();
- if(_pNodeCoreProto != NULL)
- {
- FieldContainerTransitPtr pCoreClone
- = _pNodeCoreProto->shallowCopy();
- pNode = dynamic_pointer_cast<Node >(returnValue);
- pCore = dynamic_pointer_cast<NodeCore>(pCoreClone );
- pNode->setCore(pCore);
- }
- if(_pGenAttProto != NULL)
- {
- FieldContainer *pAttClone = _pGenAttProto->clone();
- pAtt = dynamic_cast<VRMLGenericAtt *>(pAttClone);
- pAtt->setVrmlNodeTypename(szTypename);
- OSG_ASSERT(pAttClone == pAtt);
- if(pAtt != NULL)
- {
- pAtt->setInternal(true);
- }
- if(pCore != NULL)
- {
- pCore->addAttachment(pAtt);
- }
- else
- {
- AttachmentContainer *pAttCnt =
- dynamic_pointer_cast<AttachmentContainer>(returnValue);
- if(pAttCnt != NULL)
- {
- pAttCnt->addAttachment(pAtt);
- }
- }
- }
- }
- return FieldContainerTransitPtr(returnValue);
- }
- void VRMLNodeHelper::endNode(FieldContainer *)
- {
- }
- void VRMLNodeHelper::mapFieldname(const std::string &, std::string &)
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Prototypes */
- void VRMLNodeHelper::init(const Char8 *szName)
- {
- _bProtoInterfaceDone = false;
- }
- /*-------------------------------------------------------------------------*/
- /* Node */
- bool VRMLNodeHelper::prototypeAddField(const Char8 *szFieldType,
- const UInt32 uiFieldTypeId,
- const Char8 *szFieldName)
- {
- bool returnValue = false;
- GetFieldHandlePtr pField = getField(_pNodeProto,
- _pNodeCoreProto,
- _pGenAttProto,
- szFieldName);
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLNodeDesc::prototypeAddField | getField "
- << szFieldName
- << " returned : "
- << pField
- << std::endl;
- #endif
- if(pField == NULL || pField->isValid() == false)
- {
- FieldDescriptionBase *pDesc = getFieldDescription(szFieldName,
- uiFieldTypeId);
- if(pDesc != NULL && _pGenAttProto != NULL)
- {
- _pGenAttProto->addField(*pDesc);
- pField = getField(_pNodeProto,
- _pNodeCoreProto,
- _pGenAttProto,
- szFieldName);
- delete pDesc;
- }
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLNodeDesc::prototypeAddField | field added : "
- << szFieldType
- << " "
- << uiFieldTypeId
- << " "
- << szFieldName
- << " "
- << pField
- << std::endl;
- #endif
- returnValue = (pField != NULL && pField->isValid());
- }
- else
- {
- #ifdef OSG_DEBUG_VRML
- incIndent();
- indentLog(getIndent(), PINFO);
- #endif
- PINFO << "VRMLNodeDesc::prototypeAddField | "
- << "Could not add field "
- << szFieldName
- << " a second time"
- << std::endl;
- #ifdef OSG_DEBUG_VRML
- decIndent();
- #endif
- }
- return returnValue;
- }
- void VRMLNodeHelper::endProtoInterface(void)
- {
- _bProtoInterfaceDone = true;
- }
- /*-------------------------------------------------------------------------*/
- /* Dump */
- void VRMLNodeHelper::getFieldAndDesc( FieldContainer * pFC,
- const Char8 * szFieldname,
- FieldContainer *&pFieldFC,
- EditFieldHandlePtr &pField,
- const FieldDescriptionBase *&pDesc)
- {
- if(szFieldname == NULL)
- return;
- FieldContainer *pTmpFC = NULL;
- Node *pNode = NULL;
- NodeCore *pNodeCore = NULL;
- pFieldFC = NULL;
- pField.reset();
- pDesc = NULL;
- if(pFC == NULL)
- {
- if(_bProtoInterfaceDone == false)
- {
- getField(szFieldname, pFieldFC, pField, pDesc);
- }
- return;
- }
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLNodeHelper::getFieldAndDesc : looking for "
- << szFieldname
- << std::endl;
- incIndent();
- #endif
- pDesc = pFC->getFieldDescription(szFieldname);
- if(pDesc != NULL)
- {
- pFieldFC = pFC;
- pField = pFC->editField(szFieldname);
- }
- else
- {
- if(pFC->getType().isNode() == true)
- {
- pNode = dynamic_cast<Node *>(pFC);
-
- pNodeCore = pNode->getCore();
- if(pNodeCore != NULL)
- {
- pDesc = pNodeCore->getFieldDescription(szFieldname);
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from nodecore : "
- << pDesc
- << std::endl;
- #endif
- if(pDesc != NULL)
- {
- pFieldFC = pNodeCore;
- pField = pNodeCore->editField(szFieldname);
- }
- else
- {
- pTmpFC = pNode->findAttachment(
- VRMLGenericAtt::getClassType().getGroupId());
- if(pTmpFC != NULL)
- {
- pDesc = pTmpFC->getFieldDescription(szFieldname);
- }
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from node attachment : "
- << pDesc << std::endl;
- #endif
- if(pDesc == NULL)
- {
- pTmpFC =
- pNodeCore->findAttachment(
- VRMLGenericAtt::getClassType().getGroupId());
-
- if(pTmpFC != NULL)
- {
- pDesc = pTmpFC->getFieldDescription(szFieldname);
- }
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from nodecore attachment : "
- << pDesc << std::endl;
- #endif
- }
- if(pDesc != NULL)
- {
- pFieldFC = pTmpFC;
- pField = pTmpFC->editField(szFieldname);
- }
- }
- }
- else
- {
- if(pDesc == NULL)
- {
- pTmpFC =
- pNode->findAttachment(
- VRMLGenericAtt::getClassType().getGroupId());
-
- if(pTmpFC != NULL)
- {
- pDesc = pTmpFC->getFieldDescription(szFieldname);
- }
-
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from node (no core) attachment : "
- << pDesc << std::endl;
- #endif
- }
-
- if(pDesc != NULL)
- {
- pFieldFC = pTmpFC;
- pField = pTmpFC->editField(szFieldname);
- }
- }
- }
- else if(pFC->getType().isNodeCore() == true)
- {
- pNodeCore = dynamic_cast<NodeCore *>(pFC);
- pTmpFC = pNodeCore->findAttachment(
- VRMLGenericAtt::getClassType().getGroupId());
- if(pTmpFC != NULL)
- {
- pDesc = pTmpFC->getFieldDescription(szFieldname);
- }
-
- if(pDesc != NULL)
- {
- pFieldFC = pTmpFC;
- pField = pTmpFC->editField(szFieldname);
- }
-
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from nodecore attachment : "
- << pDesc << std::endl;
- #endif
- }
- }
- #ifdef OSG_DEBUG_VRML
- decIndent();
- #endif
- }
- GetFieldHandlePtr VRMLNodeHelper::getField( FieldContainer *pFC1,
- FieldContainer *pFC2,
- VRMLGenericAtt *pGenAtt,
- const Char8 *szFieldname)
- {
- GetFieldHandlePtr returnValue;
- if(szFieldname == NULL)
- {
- return returnValue;
- }
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLNodeDesc::getField " << std::endl;
- incIndent();
- indentLog(getIndent(), PINFO);
- PINFO << "Trying to find field : " << szFieldname << std::endl;
- #endif
- if(pFC1 != NULL)
- {
- returnValue = pFC1->getField(szFieldname);
- }
- #ifdef OSG_DEBUG_VRML
- incIndent();
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from node : " << returnValue << std::endl;
- #endif
- if(returnValue == NULL)
- {
- if(pFC2 != NULL)
- {
- returnValue = pFC2->getField(szFieldname);
-
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from nodecore : " << returnValue << std::endl;
- #endif
- }
- else
- {
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "No core to check" << std::endl;
- #endif
- }
-
- if(returnValue == NULL)
- {
- if(pGenAtt != NULL)
- {
- returnValue = pGenAtt->getField(szFieldname);
- }
-
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from attachment : " << returnValue << std::endl;
- #endif
- }
- }
- #ifdef OSG_DEBUG_VRML
- decIndent();
- decIndent();
- #endif
- return returnValue;
- }
- void VRMLNodeHelper::getField(const Char8 * szFieldname,
- FieldContainer *&pFieldFC,
- EditFieldHandlePtr &pField,
- const FieldDescriptionBase *&pDesc )
- {
- pFieldFC = NULL;
- pField.reset();
- pDesc = NULL;
- if(szFieldname == NULL)
- {
- return;
- }
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLNodeDesc::getField " << std::endl;
- incIndent();
- indentLog(getIndent(), PINFO);
- PINFO << "Trying to find field : " << szFieldname << std::endl;
- #endif
- if(_pNodeProto != NULL)
- {
- pFieldFC = _pNodeProto;
- pField = _pNodeProto->editField (szFieldname);
- pDesc = _pNodeProto->getFieldDescription(szFieldname);
- }
- #ifdef OSG_DEBUG_VRML
- incIndent();
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from node : " << pDesc << " " << pField << std::endl;
- #endif
- if(pDesc == NULL)
- {
- if(_pNodeCoreProto != NULL)
- {
- pFieldFC = _pNodeCoreProto;
- pField = _pNodeCoreProto->editField (szFieldname);
- pDesc = _pNodeCoreProto->getFieldDescription(szFieldname);
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from nodecore : "
- << pDesc
- << " "
- << pField
- << std::endl;
- #endif
- }
- else
- {
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "No core to check" << std::endl;
- #endif
- }
- if(pDesc == NULL)
- {
- if(_pGenAttProto != NULL)
- {
- pFieldFC = _pGenAttProto;
- pField = _pGenAttProto->editField (szFieldname);
- pDesc = _pGenAttProto->getFieldDescription(szFieldname);
- }
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "Got this from attachment : "
- << pDesc
- << " "
- << pField
- << std::endl;
- #endif
- }
- }
- if(pDesc == NULL)
- {
- pFieldFC = NULL;
- }
- #ifdef OSG_DEBUG_VRML
- decIndent();
- decIndent();
- #endif
- }
- // HACK Should be somewhere else and automatic
- #define OSG_CREATE_DESC(TYPE) new TYPE::Description( \
- TYPE::getClassType(), \
- szFieldName, \
- "", \
- 0, \
- 0, \
- false, \
- OSG::Field::SFDefaultFlags, \
- static_cast<OSG::FieldIndexEditMethodSig>( \
- &VRMLGenericAtt::editDynamicField), \
- static_cast<OSG::FieldIndexGetMethodSig >( \
- &VRMLGenericAtt::getDynamicField ))
- #define OSG_CREATE_DESC_ELSE(TYPE) \
- else if(uiFieldTypeId == TYPE::getClassType().getId()) \
- { \
- returnValue = OSG_CREATE_DESC(TYPE); \
- }
- #define OSG_CREATE_PTRDESC(TYPE) new TYPE::Description( \
- TYPE::getClassType(), \
- szFieldName, \
- "", \
- 0, \
- 0, \
- false, \
- (OSG::Field::SFDefaultFlags | Field::FStdAccess), \
- static_cast<OSG::FieldIndexEditMethodSig>( \
- &VRMLGenericAtt::editDynamicField), \
- static_cast<OSG::FieldIndexGetMethodSig >( \
- &VRMLGenericAtt::getDynamicField ))
- #define OSG_CREATE_PTRDESC_ELSE(TYPE) \
- else if(uiFieldTypeId == TYPE::getClassType().getId()) \
- { \
- returnValue = OSG_CREATE_PTRDESC(TYPE); \
- }
- FieldDescriptionBase *VRMLNodeHelper::getFieldDescription(
- const Char8 *szFieldName,
- const UInt32 uiFieldTypeId)
- {
- FieldDescriptionBase *returnValue = NULL;
- if(uiFieldTypeId == SFBool::getClassType().getId())
- {
- returnValue = OSG_CREATE_DESC(SFBool);
- }
- OSG_CREATE_DESC_ELSE(SFInt32)
- OSG_CREATE_DESC_ELSE(MFInt32)
- OSG_CREATE_DESC_ELSE(SFString)
- OSG_CREATE_DESC_ELSE(MFString)
- OSG_CREATE_DESC_ELSE(SFReal32)
- OSG_CREATE_DESC_ELSE(MFReal32)
- OSG_CREATE_DESC_ELSE(SFTime)
- OSG_CREATE_DESC_ELSE(MFTime)
- OSG_CREATE_DESC_ELSE(SFVec2s)
- OSG_CREATE_DESC_ELSE(MFVec2f)
- OSG_CREATE_DESC_ELSE(SFVec2f)
- OSG_CREATE_DESC_ELSE(MFPnt3f)
- OSG_CREATE_DESC_ELSE(SFPnt3f)
- OSG_CREATE_DESC_ELSE(MFVec3f)
- OSG_CREATE_DESC_ELSE(SFVec3f)
- OSG_CREATE_DESC_ELSE(MFColor3f)
- OSG_CREATE_DESC_ELSE(SFColor3f)
- OSG_CREATE_DESC_ELSE(MFQuaternion)
- OSG_CREATE_DESC_ELSE(SFQuaternion)
- OSG_CREATE_PTRDESC_ELSE(SFUnrecFieldContainerPtr)
- OSG_CREATE_PTRDESC_ELSE(MFUnrecFieldContainerPtr)
- OSG_CREATE_PTRDESC_ELSE(SFUnrecImagePtr)
- if(returnValue == NULL)
- {
- FWARNING(("could not create field desc for %s (%d)\n",
- szFieldName,
- uiFieldTypeId));
- }
- return returnValue;
- }
- void VRMLNodeHelper::addFieldValue( EditFieldHandlePtr pField,
- const FieldDescriptionBase *pFieldDesc,
- const Char8 *szFieldVal)
- {
- if(pField != NULL && pField->isValid() == true)
- {
- pField->pushValueFromCString(szFieldVal);
- }
- }
- void VRMLNodeHelper::addImageValue( EditFieldHandlePtr ,
- const FieldDescriptionBase *,
- Image * )
- {
- FWARNING(("addImageValue not caught, something is strange\n"));
- }
- void VRMLNodeHelper::setContainerFieldValue(
- FieldContainer *pFC,
- const FieldDescriptionBase *pFieldDesc,
- FieldContainer *pFieldFC )
- {
- if((pFieldDesc != NULL ) &&
- (pFieldFC != NULL) )
- {
- FieldContainerPtrSFieldBase::EditHandlePtr pSFHandle =
- boost::dynamic_pointer_cast<
- FieldContainerPtrSFieldBase::EditHandle>(
- pFieldFC->editField(pFieldDesc->getFieldId()));
- FieldContainerPtrMFieldBase::EditHandlePtr pMFHandle =
- boost::dynamic_pointer_cast<
- FieldContainerPtrMFieldBase::EditHandle>(
- pFieldFC->editField(pFieldDesc->getFieldId()));
- if(pSFHandle != NULL && pSFHandle->isValid())
- {
- pSFHandle->set(pFC);
- }
- else if(pMFHandle != NULL && pMFHandle->isValid())
- {
- pMFHandle->add(pFC);
- }
- /*
- pFieldFC->pushToField(pFC,
- pFieldDesc->getFieldId());
- */
- }
- }
- /*-------------------------------------------------------------------------*/
- /* Get */
- //---------------------------------------------------------------------------
- // Class
- //---------------------------------------------------------------------------
- /*! \class OSG::VRMLDefaultHelper
- \ingroup GrpSystemFileIOVRML
- VRML Group description
- */
- VRMLNodeHelper *VRMLDefaultHelper::create(void)
- {
- return new VRMLDefaultHelper();
- }
- /*-------------------------------------------------------------------------*/
- /* Constructors */
- VRMLDefaultHelper::VRMLDefaultHelper(void) :
- Inherited()
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Destructor */
- VRMLDefaultHelper::~VRMLDefaultHelper(void)
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Helper */
- void VRMLDefaultHelper::init(const Char8 *szName)
- {
- Inherited::init(szName);
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "GroupHelper::init : " << szName << std::endl;
- #endif
- _pNodeProto = Node ::create();
- _pNodeCoreProto = Group::create();
- _pGenAttProto = VRMLGenericAtt::create();
- _pGenAttProto->setInternal(true);
- }
- FieldContainerTransitPtr VRMLDefaultHelper::beginNode(
- const Char8 *szTypename,
- const Char8 *szName,
- FieldContainer *pCurrentFC)
- {
- FWARNING(("Use default helper for %s, functionality currently not "
- "supported\n", szTypename));
- return Inherited::beginNode(szTypename, szName, pCurrentFC);
- }
- /*-------------------------------------------------------------------------*/
- /* Dump */
- void VRMLDefaultHelper::dump(const Char8 *)
- {
- }
- //---------------------------------------------------------------------------
- // Generic Helper with 1:1 mapping
- //---------------------------------------------------------------------------
- template<>
- VRMLNodeHelperFactoryBase::RegisterHelper
- VRMLGenericHelper<Group>::_regHelper(
- &VRMLGenericHelper<Group>::create,
- "Group",
- NULL);
- OSG_INST_GENERICVRMLHELPER(Group);
- template<>
- VRMLNodeHelperFactoryBase::RegisterHelper
- VRMLGenericHelper<ComponentTransform>::_regHelper(
- &VRMLGenericHelper<ComponentTransform>::create,
- "Transform",
- NULL);
- OSG_INST_GENERICVRMLHELPER(ComponentTransform);
- //---------------------------------------------------------------------------
- // Class
- //---------------------------------------------------------------------------
- /*! \class OSG::VRMLMaterialDesc
- \ingroup GrpSystemFileIOVRML
- VRML Material description
- */
- VRMLNodeHelper *VRMLMaterialHelper::create(void)
- {
- return new VRMLMaterialHelper();
- }
- /*-------------------------------------------------------------------------*/
- /* Constructors */
- VRMLMaterialHelper::VRMLMaterialHelper(void) :
- Inherited ( ),
- _defaultAmbientIntensity(),
- _defaultDiffuseColor (),
- _defaultEmissiveColor (),
- _defaultShininess (),
- _defaultSpecularColor (),
- _defaultTransparency (),
- _ambientIntensity (),
- _diffuseColor (),
- _emissiveColor (),
- _shininess (),
- _specularColor (),
- _transparency (),
- _pDefMat (NULL),
- _pMat (NULL),
-
- _szName ( )
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Destructor */
- VRMLMaterialHelper::~VRMLMaterialHelper(void)
- {
- _pDefMat = NULL;
- }
- /*-------------------------------------------------------------------------*/
- /* Helper */
- void VRMLMaterialHelper::init(const Char8 *OSG_VRML_ARG(szName))
- {
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "MaterialDesc::init : " << szName << std::endl;
- #endif
- }
- void VRMLMaterialHelper::reset(void)
- {
- _ambientIntensity.setValue(_defaultAmbientIntensity);
- _diffuseColor .setValue(_defaultDiffuseColor);
- _emissiveColor .setValue(_defaultEmissiveColor);
- _shininess .setValue(_defaultShininess);
- _specularColor .setValue(_defaultSpecularColor);
- _transparency .setValue(_defaultTransparency);
- _szName .erase ();
- _pMat = NULL;
- }
- Material *VRMLMaterialHelper::getDefaultMaterial(void)
- {
- return _pDefMat;
- }
- /*-------------------------------------------------------------------------*/
- /* Field */
- bool VRMLMaterialHelper::prototypeAddField(const Char8 *,
- const UInt32 ,
- const Char8 *szFieldname)
- {
- bool bFound = false;
- if(osgStringCaseCmp("ambientIntensity", szFieldname) == 0)
- {
- bFound = true;
- }
- else if(osgStringCaseCmp("diffuseColor", szFieldname) == 0)
- {
- bFound = true;
- }
- else if(osgStringCaseCmp("emissiveColor", szFieldname) == 0)
- {
- bFound = true;
- }
- else if(osgStringCaseCmp("shininess", szFieldname) == 0)
- {
- bFound = true;
- }
- else if(osgStringCaseCmp("specularColor", szFieldname) == 0)
- {
- bFound = true;
- }
- else if(osgStringCaseCmp("transparency", szFieldname) == 0)
- {
- bFound = true;
- }
- if(bFound == true)
- {
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "MaterialDesc::prototypeAddField : add part "
- << szFieldname
- << std::endl;
- #endif
- return true;
- }
- else
- {
- return false;
- }
- }
- void VRMLMaterialHelper::endProtoInterface(void)
- {
- Color4f cCol;
- MaterialChunkUnrecPtr pMatChunk;
- cCol.setValuesRGBA(_defaultDiffuseColor .getValue().red() *
- _defaultAmbientIntensity.getValue(),
- _defaultDiffuseColor .getValue().green() *
- _defaultAmbientIntensity.getValue(),
- _defaultDiffuseColor .getValue().blue() *
- _defaultAmbientIntensity.getValue(),
- 1.f - _defaultTransparency .getValue());
- _pDefMat = ChunkMaterial::create();
- pMatChunk = MaterialChunk::create();
- pMatChunk->setAmbient(cCol);
- cCol.setValuesRGBA (_defaultDiffuseColor.getValue()[0],
- _defaultDiffuseColor.getValue()[1],
- _defaultDiffuseColor.getValue()[2],
- 1.f - _defaultTransparency.getValue());
- pMatChunk->setDiffuse(cCol);
- cCol.setValuesRGBA (_defaultSpecularColor.getValue()[0],
- _defaultSpecularColor.getValue()[1],
- _defaultSpecularColor.getValue()[2],
- 1.f - _defaultTransparency.getValue());
- pMatChunk->setSpecular(cCol);
- pMatChunk->setShininess(_defaultShininess.getValue() * 128.f);
- cCol.setValuesRGBA (_defaultEmissiveColor.getValue()[0],
- _defaultEmissiveColor.getValue()[1],
- _defaultEmissiveColor.getValue()[2],
- 1.f - _defaultTransparency.getValue());
- pMatChunk->setEmission(cCol);
- _pDefMat->addChunk(pMatChunk);
- Inherited::endProtoInterface();
- }
- void VRMLMaterialHelper::getFieldAndDesc(
- FieldContainer *,
- const Char8 * szFieldname,
- FieldContainer *&pFieldFC,
- EditFieldHandlePtr &pField,
- const FieldDescriptionBase *&pDesc)
- {
- pFieldFC = NULL;
- pField.reset();
- pDesc = NULL;
- if(osgStringCaseCmp("ambientIntensity", szFieldname) == 0)
- {
- pFieldFC = NULL;
- if(_bProtoInterfaceDone == false)
- {
- pField =
- _sfReal32Desc.createEditHandler(&_defaultAmbientIntensity,
- NULL );
- }
- else
- {
- pField = _sfReal32Desc.createEditHandler(&_ambientIntensity,
- NULL );
- }
- pDesc = &_sfReal32Desc;
- }
- else if(osgStringCaseCmp("diffuseColor", szFieldname) == 0)
- {
- pFieldFC = NULL;
- if(_bProtoInterfaceDone == false)
- {
- pField = _sfColor3fDesc.createEditHandler(&_defaultDiffuseColor,
- NULL );
- }
- else
- {
- pField = _sfColor3fDesc.createEditHandler(&_diffuseColor,
- NULL );
- }
- pDesc = &_sfColor3fDesc;
- }
- else if(osgStringCaseCmp("emissiveColor", szFieldname) == 0)
- {
- pFieldFC = NULL;
- if(_bProtoInterfaceDone == false)
- {
- pField = _sfColor3fDesc.createEditHandler(&_defaultEmissiveColor,
- NULL );
- }
- else
- {
- pField = _sfColor3fDesc.createEditHandler(&_emissiveColor,
- NULL );
- }
- pDesc = &_sfColor3fDesc;
- }
- else if(osgStringCaseCmp("shininess", szFieldname) == 0)
- {
- pFieldFC = NULL;
- if(_bProtoInterfaceDone == false)
- {
- pField = _sfReal32Desc.createEditHandler(&_defaultShininess,
- NULL );
- }
- else
- {
- pField = _sfReal32Desc.createEditHandler(&_shininess,
- NULL );
- }
- pDesc = &_sfReal32Desc;
- }
- else if(osgStringCaseCmp("specularColor", szFieldname) == 0)
- {
- pFieldFC = NULL;
- if(_bProtoInterfaceDone == false)
- {
- pField = _sfColor3fDesc.createEditHandler(&_defaultSpecularColor,
- NULL );
- }
- else
- {
- pField = _sfColor3fDesc.createEditHandler(&_specularColor,
- NULL );
- }
- pDesc = &_sfColor3fDesc;
- }
- else if(osgStringCaseCmp("transparency", szFieldname) == 0)
- {
- pFieldFC = NULL;
- if(_bProtoInterfaceDone == false)
- {
- pField = _sfReal32Desc.createEditHandler(&_defaultTransparency,
- NULL );
- }
- else
- {
- pField = _sfReal32Desc.createEditHandler(&_transparency,
- NULL );
- }
- pDesc = &_sfReal32Desc;
- }
- }
- /*-------------------------------------------------------------------------*/
- /* Node */
- FieldContainerTransitPtr VRMLMaterialHelper::beginNode(
- const Char8 *,
- const Char8 *szName,
- FieldContainer * )
- {
- reset();
- _pMat = MaterialChunk::create();
- _szName = (szName != NULL) ? szName : "";
- return FieldContainerTransitPtr(_pMat);
- }
- void VRMLMaterialHelper::endNode(FieldContainer *)
- {
- if(_pMat != NULL)
- {
- Color4f cCol;
- cCol.setValuesRGBA (_diffuseColor .getValue().red() *
- _ambientIntensity.getValue(),
- _diffuseColor .getValue().green() *
- _ambientIntensity.getValue(),
- _diffuseColor .getValue().blue() *
- _ambientIntensity.getValue(),
- 1.f - _transparency.getValue());
- _pMat->setAmbient (cCol);
- cCol.setValuesRGBA (_diffuseColor.getValue()[0],
- _diffuseColor.getValue()[1],
- _diffuseColor.getValue()[2],
- 1.f - _transparency.getValue());
- _pMat->setDiffuse (cCol);
- cCol.setValuesRGBA (_specularColor.getValue()[0],
- _specularColor.getValue()[1],
- _specularColor.getValue()[2],
- 1.f - _transparency.getValue());
- _pMat->setSpecular (cCol);
- _pMat->setShininess(_shininess.getValue() * 128.f );
- cCol.setValuesRGBA (_emissiveColor.getValue()[0],
- _emissiveColor.getValue()[1],
- _emissiveColor.getValue()[2],
- 1.f - _transparency.getValue());
- _pMat->setEmission (cCol);
- }
- }
- /*-------------------------------------------------------------------------*/
- /* Type Specific */
- const std::string &VRMLMaterialHelper::getName(void) const
- {
- return _szName;
- }
- /*-------------------------------------------------------------------------*/
- /* Dump */
- void VRMLMaterialHelper::dump(const Char8 *)
- {
- }
- VRMLNodeHelperFactoryBase::RegisterHelper VRMLMaterialHelper::_regHelper(
- &VRMLMaterialHelper::create,
- "Material",
- NULL);
- //---------------------------------------------------------------------------
- // Class
- //---------------------------------------------------------------------------
- /*! \class OSG::VRMLShapeDesc
- \ingroup GrpSystemFileIOVRML
- VRML Shape description
- */
- VRMLNodeHelper *VRMLShapeHelper::create(void)
- {
- return new VRMLShapeHelper();
- }
- /*-------------------------------------------------------------------------*/
- /* Constructors */
- VRMLShapeHelper::VRMLShapeHelper(void) :
- Inherited ( ),
- _pMaterialHelper(NULL)
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Destructor */
- VRMLShapeHelper::~VRMLShapeHelper(void)
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Helper */
- void VRMLShapeHelper::init(const Char8 *szName)
- {
- Inherited::init(szName);
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "ShapeHelper::init : " << szName << std::endl;
- #endif
- _pNodeProto = Node ::create();
- _pNodeCoreProto = MaterialGroup::create();
- _pGenAttProto = VRMLGenericAtt::create();
- _pGenAttProto->setInternal(true);
- }
- void VRMLShapeHelper::setMaterialHelper(VRMLMaterialHelper *pMaterialHelper)
- {
- _pMaterialHelper = pMaterialHelper;
- }
- /*-------------------------------------------------------------------------*/
- /* Get */
- bool VRMLShapeHelper::prototypeAddField(const Char8 *szFieldType,
- const UInt32 uiFieldTypeId,
- const Char8 *szFieldname)
- {
- bool returnValue = false;
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLShapeHelper::prototypeAddField | add request : "
- << szFieldname
- << std::endl;
- #endif
- if(szFieldname == NULL)
- return false;
- incIndent();
- if(osgStringCaseCmp("geometry", szFieldname) == 0)
- {
- returnValue = true;
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLShapeHelper::prototypeAddField | request internal : "
- << szFieldname
- << " "
- << std::endl;
- #endif
- }
- if(osgStringCaseCmp("appearance", szFieldname) == 0)
- {
- returnValue = true;
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLShapeHelper::prototypeAddField | request internal : "
- << szFieldname
- << " "
- << std::endl;
- #endif
- }
- if(returnValue == false)
- {
- returnValue = Inherited::prototypeAddField(szFieldType,
- uiFieldTypeId,
- szFieldname);
- }
- #ifdef OSG_DEBUG_VRML
- decIndent();
- #endif
- return returnValue;
- }
- void VRMLShapeHelper::getFieldAndDesc(
- FieldContainer * pFC,
- const Char8 * szFieldname,
- FieldContainer *&pFieldFC,
- EditFieldHandlePtr &pField,
- const FieldDescriptionBase *&pDesc)
- {
- if(szFieldname == NULL)
- return;
- if(pFC == NULL)
- {
- if(_bProtoInterfaceDone == false)
- {
- Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
- }
- return;
- }
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLShapeHelper::getFieldAndDesc : looking for "
- << szFieldname
- << std::endl;
- incIndent();
- #endif
- if(osgStringCaseCmp("geometry", szFieldname) == 0)
- {
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLShapeHelper::getFieldAndDesc : request internal "
- << szFieldname
- << std::endl;
- #endif
- pFieldFC = pFC;
- pField = pFC->editField("children");
- pDesc = pFC->getFieldDescription("children");
- }
- else if(osgStringCaseCmp("appearance", szFieldname) == 0)
- {
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "VRMLShapeHelper::getFieldAndDesc : request internal "
- << szFieldname
- << std::endl;
- #endif
- Node *pNode = dynamic_cast<Node *>(pFC);
- if(pNode != NULL)
- {
- if(pNode->getCore() != NULL)
- {
- pFieldFC = pNode->getCore();
- pField = pNode->getCore()->editField("material");
- pDesc = pNode->getCore()->getFieldDescription("material");
- }
- }
- else
- {
- Inherited::getFieldAndDesc(pFC,
- szFieldname,
- pFC,
- pField,
- pDesc);
- }
- }
- else
- {
- Inherited::getFieldAndDesc(pFC,
- szFieldname,
- pFC,
- pField,
- pDesc);
- }
- #ifdef OSG_DEBUG_VRML
- decIndent();
- #endif
- }
- /*-------------------------------------------------------------------------*/
- /* Node */
- void VRMLShapeHelper::endNode(FieldContainer *pFC)
- {
- if(pFC != NULL)
- {
- Node *pNode = dynamic_cast<Node *>(pFC);
- if(pNode != NULL && pNode->getCore() == NULL)
- {
- PWARNING << "warning empty material, using default\n" << std::endl;
- MaterialGroupUnrecPtr pMatGroup = MaterialGroup::create();
- pMatGroup->setMaterial(_pMaterialHelper->getDefaultMaterial());
- pNode->setCore(pMatGroup);
- }
- else
- {
- MaterialGroup *pMatGroup;
- pMatGroup = dynamic_cast<MaterialGroup *>(pNode->getCore());
- if(pMatGroup != NULL)
- {
- if(pMatGroup->getMaterial() == NULL)
- {
- pMatGroup->setMaterial(
- _pMaterialHelper->getDefaultMaterial());
- }
- }
- }
- }
- #ifdef OSG_DEBUG_VRML
- // decIndent();
- indentLog(getIndent(), PINFO);
- PINFO << "End Shape " << &(*pFC) << std::endl;
- #endif
- }
- /*-------------------------------------------------------------------------*/
- /* Dump */
- void VRMLShapeHelper::dump(const Char8 *)
- {
- }
- VRMLNodeHelperFactoryBase::RegisterHelper VRMLShapeHelper::_regHelper(
- &VRMLShapeHelper::create,
- "Shape",
- NULL);
- //---------------------------------------------------------------------------
- // Class
- //---------------------------------------------------------------------------
- /*! \class OSG::VRMLAppearanceDesc
- \ingroup GrpSystemFileIOVRML
- VRML Appearance description
- */
- VRMLNodeHelper *VRMLAppearanceHelper::create(void)
- {
- return new VRMLAppearanceHelper();
- }
- /*-------------------------------------------------------------------------*/
- /* Constructors */
- VRMLAppearanceHelper::VRMLAppearanceHelper(void) :
- Inherited ( ),
- _pMaterialHelper(NULL)
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Destructor */
- VRMLAppearanceHelper::~VRMLAppearanceHelper(void)
- {
- }
- /*-------------------------------------------------------------------------*/
- /* Helper */
- void VRMLAppearanceHelper::init(const Char8 *szName)
- {
- Inherited::init(szName);
- #ifdef OSG_DEBUG_VRML
- indentLog(getIndent(), PINFO);
- PINFO << "ApperanceHelper::init : " << szName << std::endl;
- #endif
- _pNodeProto = ChunkMaterial::create();
- _pGenAttProto = VRMLGenericAtt::create();
- _pGenAttProto->setInternal(true);
- }
- void VRMLAppearanceHelper::setMaterialHelper(
- VRMLMaterialHelper *pMaterialHelper)
- {
- _pMaterialHelper = pMaterialHelper;
- }
- /*-------------------------------------…
Large files files are truncated, but you can click here to view the full file