1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
42 #include "OSGConfig.h"
47 #include "OSGVRMLNodeHelper.h"
48 #include "OSGSingletonHolder.ins"
50 #include "OSGFieldDescFactory.h"
52 #include "OSGScanParseSkel.h"
53 #include "OSGSceneFileHandler.h"
54 #include "OSGNameAttachment.h"
57 #include "OSGMaterialGroup.h"
58 #include "OSGChunkMaterial.h"
59 #include "OSGGeometry.h"
60 #include "OSGGeoFunctions.h"
61 #include "OSGChunkMaterial.h"
62 #include "OSGMaterialChunk.h"
63 #include "OSGBlendChunk.h"
64 #include "OSGTextureObjChunk.h"
65 #include "OSGTextureEnvChunk.h"
66 #include "OSGImageFileHandler.h"
67 #include "OSGSimpleGeometry.h"
68 #include "OSGComponentTransform.h"
69 #include "OSGInline.h"
70 #include "OSGSwitch.h"
71 #include "OSGTimeSensor.h"
72 #include "OSGVRMLOrientationInterpolator.h"
73 #include "OSGVRMLPositionInterpolator.h"
74 #include "OSGVRMLCoordinateInterpolator.h"
75 #include "OSGVRMLNormalInterpolator.h"
76 #include "OSGVRMLScalarInterpolator.h"
78 #include "OSGTypedGeoIntegralProperty.h"
80 #ifndef OSG_LOG_MODULE
81 #define OSG_LOG_MODULE "VRMLLoader"
84 //#define OSG_DEBUG_VRML
87 # ifdef OSG_DEBUG_VRML
88 # define OSG_VRML_ARG(ARG) ARG
90 # define OSG_VRML_ARG(ARG)
93 # define OSG_VRML_ARG(ARG) ARG
98 OSG_DYNFIELDATTACHMENT_INST(VRMLGenericAttDesc
)
100 OSG_SINGLETON_INST(VRMLNodeHelperFactoryBase
, addPostFactoryExitFunction
)
102 template class SingletonHolder
<VRMLNodeHelperFactoryBase
>;
104 //---------------------------------------------------------------------------
106 //---------------------------------------------------------------------------
108 VRMLNodeHelperFactoryBase::RegisterHelper::RegisterHelper(
109 CreateHelper fCreate
,
110 const Char8
*szNodeName
,
111 InitFuncF fStaticInit
)
113 VRMLNodeHelperFactory::the()->registerNodeHelper(fCreate
,
117 addPostFactoryInitFunction(fStaticInit
);
121 VRMLNodeHelperFactoryBase::VRMLNodeHelperFactoryBase(void) :
122 _mRegisteredNodeHelperHash()
126 VRMLNodeHelperFactoryBase::~VRMLNodeHelperFactoryBase(void)
130 void VRMLNodeHelperFactoryBase::registerNodeHelper(
131 CreateHelper fHelper
,
132 const Char8
*szNodeName
)
134 if(szNodeName
== NULL
|| fHelper
== NULL
)
137 NameHelperCreateMap::iterator mNodeHelperIt
=
138 _mRegisteredNodeHelperHash
.find(szNodeName
);
141 if(mNodeHelperIt
== _mRegisteredNodeHelperHash
.end())
143 _mRegisteredNodeHelperHash
[szNodeName
] = fHelper
;
145 PINFO
<< "Helper registered for "
151 PWARNING
<< "Helper already registered for %s "
157 VRMLNodeHelper
*VRMLNodeHelperFactoryBase::createHelper(
158 const Char8
*szNodeName
)
160 if(szNodeName
== NULL
)
163 NameHelperCreateMap::iterator mNodeHelperIt
=
164 _mRegisteredNodeHelperHash
.find(szNodeName
);
167 if(mNodeHelperIt
!= _mRegisteredNodeHelperHash
.end())
169 return (*mNodeHelperIt
).second();
178 //---------------------------------------------------------------------------
180 //---------------------------------------------------------------------------
182 UInt32
VRMLNodeHelper::_uiIndent
= 0;
184 /*-------------------------------------------------------------------------*/
187 UInt32
VRMLNodeHelper::getIndent(void)
192 void VRMLNodeHelper::incIndent(void)
197 void VRMLNodeHelper::decIndent(void)
201 // PWARNING << "Indent smaller 4 decremented" << std::endl;
209 void VRMLNodeHelper::resetIndent(void)
214 /*-------------------------------------------------------------------------*/
217 #define OSG_INIT_DESC(VAR, TYPE, NAME) \
218 VAR(TYPE::getClassType(), \
224 Field::SFDefaultFlags, \
225 static_cast<FieldEditMethodSig>(&Node::invalidEditField), \
228 VRMLNodeHelper::VRMLNodeHelper(void) :
229 _bProtoInterfaceDone(false ),
230 _pGenAttProto (NULL
),
232 _pNodeCoreProto (NULL
),
234 OSG_INIT_DESC(_sfVec3fDesc
,
236 "sfVec3fHelperDesc" ),
238 OSG_INIT_DESC(_sfFCPtrDesc
,
239 SFUnrecFieldContainerPtr
,
240 "sfFCPtrHelperDesc" ),
242 OSG_INIT_DESC(_sfImagePtrDesc
,
244 "sfImageHelperDesc" ),
246 OSG_INIT_DESC(_sfReal32Desc
,
248 "sfReal32HelperDesc" ),
250 OSG_INIT_DESC(_sfColor3fDesc
,
252 "sfColor3fHelperDesc"),
254 OSG_INIT_DESC(_mfStringDesc
,
256 "mfStringHelperDesc" ),
258 OSG_INIT_DESC(_sfBoolDesc
,
264 /*-------------------------------------------------------------------------*/
267 VRMLNodeHelper::~VRMLNodeHelper(void)
270 _pNodeCoreProto
= NULL
;
271 _pGenAttProto
= NULL
;
274 /*-------------------------------------------------------------------------*/
278 void VRMLNodeHelper::reset(void)
283 /*-------------------------------------------------------------------------*/
286 FieldContainerTransitPtr
VRMLNodeHelper::beginNode(
287 const Char8
*szTypename
,
289 FieldContainer
*pCurrentFC
)
291 FieldContainerUnrecPtr returnValue
= NULL
;
292 NodeUnrecPtr pNode
= NULL
;
293 NodeCoreUnrecPtr pCore
= NULL
;
294 VRMLGenericAttUnrecPtr pAtt
= NULL
;
296 if(_pNodeProto
!= NULL
)
298 returnValue
= _pNodeProto
->shallowCopy();
300 if(_pNodeCoreProto
!= NULL
)
302 FieldContainerTransitPtr pCoreClone
303 = _pNodeCoreProto
->shallowCopy();
305 pNode
= dynamic_pointer_cast
<Node
>(returnValue
);
306 pCore
= dynamic_pointer_cast
<NodeCore
>(pCoreClone
);
308 pNode
->setCore(pCore
);
311 if(_pGenAttProto
!= NULL
)
313 FieldContainer
*pAttClone
= _pGenAttProto
->clone();
315 pAtt
= dynamic_cast<VRMLGenericAtt
*>(pAttClone
);
317 OSG_ASSERT(pAttClone
== pAtt
);
321 pAtt
->setVrmlNodeTypename(szTypename
);
322 pAtt
->setInternal (true);
327 pCore
->addAttachment(pAtt
);
331 AttachmentContainer
*pAttCnt
=
332 dynamic_pointer_cast
<AttachmentContainer
>(returnValue
);
336 pAttCnt
->addAttachment(pAtt
);
342 return FieldContainerTransitPtr(returnValue
);
345 void VRMLNodeHelper::endNode(FieldContainer
*)
349 void VRMLNodeHelper::mapFieldname(const std::string
&, std::string
&)
353 /*-------------------------------------------------------------------------*/
356 void VRMLNodeHelper::init(const Char8
*szName
)
358 _bProtoInterfaceDone
= false;
361 /*-------------------------------------------------------------------------*/
364 bool VRMLNodeHelper::prototypeAddField(const Char8
*szFieldType
,
365 const UInt32 uiFieldTypeId
,
366 const Char8
*szFieldName
)
368 bool returnValue
= false;
371 GetFieldHandlePtr pField
= getField(_pNodeProto
,
376 #ifdef OSG_DEBUG_VRML
377 indentLog(getIndent(), PINFO
);
378 PINFO
<< "VRMLNodeDesc::prototypeAddField | getField "
385 if(pField
== NULL
|| pField
->isValid() == false)
387 FieldDescriptionBase
*pDesc
= getFieldDescription(szFieldName
,
390 if(pDesc
!= NULL
&& _pGenAttProto
!= NULL
)
392 _pGenAttProto
->addField(*pDesc
);
394 pField
= getField(_pNodeProto
,
402 #ifdef OSG_DEBUG_VRML
403 indentLog(getIndent(), PINFO
);
404 PINFO
<< "VRMLNodeDesc::prototypeAddField | field added : "
415 returnValue
= (pField
!= NULL
&& pField
->isValid());
419 #ifdef OSG_DEBUG_VRML
421 indentLog(getIndent(), PINFO
);
423 PINFO
<< "VRMLNodeDesc::prototypeAddField | "
424 << "Could not add field "
429 #ifdef OSG_DEBUG_VRML
437 void VRMLNodeHelper::endProtoInterface(void)
439 _bProtoInterfaceDone
= true;
442 /*-------------------------------------------------------------------------*/
445 void VRMLNodeHelper::getFieldAndDesc( FieldContainer
* pFC
,
446 const Char8
* szFieldname
,
447 FieldContainer
*&pFieldFC
,
448 EditFieldHandlePtr
&pField
,
449 const FieldDescriptionBase
*&pDesc
)
451 if(szFieldname
== NULL
)
454 FieldContainer
*pTmpFC
= NULL
;
456 NodeCore
*pNodeCore
= NULL
;
464 if(_bProtoInterfaceDone
== false)
466 getField(szFieldname
, pFieldFC
, pField
, pDesc
);
471 #ifdef OSG_DEBUG_VRML
472 indentLog(getIndent(), PINFO
);
473 PINFO
<< "VRMLNodeHelper::getFieldAndDesc : looking for "
480 pDesc
= pFC
->getFieldDescription(szFieldname
);
485 pField
= pFC
->editField(szFieldname
);
489 if(pFC
->getType().isNode() == true)
491 pNode
= dynamic_cast<Node
*>(pFC
);
493 pNodeCore
= pNode
->getCore();
495 if(pNodeCore
!= NULL
)
497 pDesc
= pNodeCore
->getFieldDescription(szFieldname
);
499 #ifdef OSG_DEBUG_VRML
500 indentLog(getIndent(), PINFO
);
501 PINFO
<< "Got this from nodecore : "
508 pFieldFC
= pNodeCore
;
509 pField
= pNodeCore
->editField(szFieldname
);
513 pTmpFC
= pNode
->findAttachment(
514 VRMLGenericAtt::getClassType().getGroupId());
518 pDesc
= pTmpFC
->getFieldDescription(szFieldname
);
521 #ifdef OSG_DEBUG_VRML
522 indentLog(getIndent(), PINFO
);
523 PINFO
<< "Got this from node attachment : "
524 << pDesc
<< std::endl
;
530 pNodeCore
->findAttachment(
531 VRMLGenericAtt::getClassType().getGroupId());
535 pDesc
= pTmpFC
->getFieldDescription(szFieldname
);
538 #ifdef OSG_DEBUG_VRML
539 indentLog(getIndent(), PINFO
);
540 PINFO
<< "Got this from nodecore attachment : "
541 << pDesc
<< std::endl
;
548 pField
= pTmpFC
->editField(szFieldname
);
557 pNode
->findAttachment(
558 VRMLGenericAtt::getClassType().getGroupId());
562 pDesc
= pTmpFC
->getFieldDescription(szFieldname
);
565 #ifdef OSG_DEBUG_VRML
566 indentLog(getIndent(), PINFO
);
567 PINFO
<< "Got this from node (no core) attachment : "
568 << pDesc
<< std::endl
;
575 pField
= pTmpFC
->editField(szFieldname
);
579 else if(pFC
->getType().isNodeCore() == true)
581 pNodeCore
= dynamic_cast<NodeCore
*>(pFC
);
583 pTmpFC
= pNodeCore
->findAttachment(
584 VRMLGenericAtt::getClassType().getGroupId());
588 pDesc
= pTmpFC
->getFieldDescription(szFieldname
);
594 pField
= pTmpFC
->editField(szFieldname
);
597 #ifdef OSG_DEBUG_VRML
598 indentLog(getIndent(), PINFO
);
599 PINFO
<< "Got this from nodecore attachment : "
600 << pDesc
<< std::endl
;
605 #ifdef OSG_DEBUG_VRML
610 GetFieldHandlePtr
VRMLNodeHelper::getField( FieldContainer
*pFC1
,
611 FieldContainer
*pFC2
,
612 VRMLGenericAtt
*pGenAtt
,
613 const Char8
*szFieldname
)
615 GetFieldHandlePtr returnValue
;
617 if(szFieldname
== NULL
)
622 #ifdef OSG_DEBUG_VRML
623 indentLog(getIndent(), PINFO
);
624 PINFO
<< "VRMLNodeDesc::getField " << std::endl
;
628 indentLog(getIndent(), PINFO
);
629 PINFO
<< "Trying to find field : " << szFieldname
<< std::endl
;
634 returnValue
= pFC1
->getField(szFieldname
);
637 #ifdef OSG_DEBUG_VRML
640 indentLog(getIndent(), PINFO
);
641 PINFO
<< "Got this from node : " << returnValue
<< std::endl
;
644 if(returnValue
== NULL
)
648 returnValue
= pFC2
->getField(szFieldname
);
650 #ifdef OSG_DEBUG_VRML
651 indentLog(getIndent(), PINFO
);
652 PINFO
<< "Got this from nodecore : " << returnValue
<< std::endl
;
657 #ifdef OSG_DEBUG_VRML
658 indentLog(getIndent(), PINFO
);
659 PINFO
<< "No core to check" << std::endl
;
664 if(returnValue
== NULL
)
668 returnValue
= pGenAtt
->getField(szFieldname
);
671 #ifdef OSG_DEBUG_VRML
672 indentLog(getIndent(), PINFO
);
673 PINFO
<< "Got this from attachment : " << returnValue
<< std::endl
;
679 #ifdef OSG_DEBUG_VRML
688 void VRMLNodeHelper::getField(const Char8
* szFieldname
,
689 FieldContainer
*&pFieldFC
,
690 EditFieldHandlePtr
&pField
,
691 const FieldDescriptionBase
*&pDesc
)
697 if(szFieldname
== NULL
)
702 #ifdef OSG_DEBUG_VRML
703 indentLog(getIndent(), PINFO
);
704 PINFO
<< "VRMLNodeDesc::getField " << std::endl
;
708 indentLog(getIndent(), PINFO
);
709 PINFO
<< "Trying to find field : " << szFieldname
<< std::endl
;
712 if(_pNodeProto
!= NULL
)
714 pFieldFC
= _pNodeProto
;
715 pField
= _pNodeProto
->editField (szFieldname
);
716 pDesc
= _pNodeProto
->getFieldDescription(szFieldname
);
719 #ifdef OSG_DEBUG_VRML
722 indentLog(getIndent(), PINFO
);
723 PINFO
<< "Got this from node : " << pDesc
<< " " << pField
<< std::endl
;
728 if(_pNodeCoreProto
!= NULL
)
730 pFieldFC
= _pNodeCoreProto
;
731 pField
= _pNodeCoreProto
->editField (szFieldname
);
732 pDesc
= _pNodeCoreProto
->getFieldDescription(szFieldname
);
734 #ifdef OSG_DEBUG_VRML
735 indentLog(getIndent(), PINFO
);
736 PINFO
<< "Got this from nodecore : "
745 #ifdef OSG_DEBUG_VRML
746 indentLog(getIndent(), PINFO
);
747 PINFO
<< "No core to check" << std::endl
;
754 if(_pGenAttProto
!= NULL
)
756 pFieldFC
= _pGenAttProto
;
757 pField
= _pGenAttProto
->editField (szFieldname
);
758 pDesc
= _pGenAttProto
->getFieldDescription(szFieldname
);
761 #ifdef OSG_DEBUG_VRML
762 indentLog(getIndent(), PINFO
);
763 PINFO
<< "Got this from attachment : "
778 #ifdef OSG_DEBUG_VRML
785 FieldDescriptionBase
*VRMLNodeHelper::getFieldDescription(
786 const Char8
*szFieldName
,
787 const UInt32 uiFieldTypeId
)
789 FieldDescriptionBase
*returnValue
= NULL
;
791 returnValue
= FieldDescFactory::the()->createIdx(
794 static_cast<OSG::FieldIndexEditMethodSig
>(
795 &VRMLGenericAtt::editDynamicField
),
796 static_cast<OSG::FieldIndexGetMethodSig
>(
797 &VRMLGenericAtt::getDynamicField
));
800 if(returnValue
== NULL
)
802 FWARNING(("could not create field desc for %s (%d)\n",
810 void VRMLNodeHelper::addFieldValue( EditFieldHandlePtr pField
,
811 const FieldDescriptionBase
*pFieldDesc
,
812 const Char8
*szFieldVal
)
814 if(pField
!= NULL
&& pField
->isValid() == true)
816 pField
->pushValueFromCString(szFieldVal
);
820 void VRMLNodeHelper::addImageValue( EditFieldHandlePtr
,
821 const FieldDescriptionBase
*,
824 FWARNING(("addImageValue not caught, something is strange\n"));
827 void VRMLNodeHelper::setContainerFieldValue(
829 const FieldDescriptionBase
*pFieldDesc
,
830 FieldContainer
*pFieldFC
)
832 if((pFieldDesc
!= NULL
) &&
835 FieldContainerPtrSFieldBase::EditHandlePtr pSFHandle
=
836 boost::dynamic_pointer_cast
<
837 FieldContainerPtrSFieldBase::EditHandle
>(
838 pFieldFC
->editField(pFieldDesc
->getFieldId()));
840 FieldContainerPtrMFieldBase::EditHandlePtr pMFHandle
=
841 boost::dynamic_pointer_cast
<
842 FieldContainerPtrMFieldBase::EditHandle
>(
843 pFieldFC
->editField(pFieldDesc
->getFieldId()));
845 if(pSFHandle
!= NULL
&& pSFHandle
->isValid())
849 else if(pMFHandle
!= NULL
&& pMFHandle
->isValid())
854 pFieldFC->pushToField(pFC,
855 pFieldDesc->getFieldId());
860 /*-------------------------------------------------------------------------*/
870 //---------------------------------------------------------------------------
872 //---------------------------------------------------------------------------
874 VRMLNodeHelper
*VRMLDefaultHelper::create(void)
876 return new VRMLDefaultHelper();
879 /*-------------------------------------------------------------------------*/
882 VRMLDefaultHelper::VRMLDefaultHelper(void) :
887 /*-------------------------------------------------------------------------*/
890 VRMLDefaultHelper::~VRMLDefaultHelper(void)
894 /*-------------------------------------------------------------------------*/
897 void VRMLDefaultHelper::init(const Char8
*szName
)
899 Inherited::init(szName
);
901 #ifdef OSG_DEBUG_VRML
902 indentLog(getIndent(), PINFO
);
903 PINFO
<< "GroupHelper::init : " << szName
<< std::endl
;
906 _pNodeProto
= Node ::create();
907 _pNodeCoreProto
= Group::create();
909 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
910 _pGenAttProto
->setInternal(true);
913 FieldContainerTransitPtr
VRMLDefaultHelper::beginNode(
914 const Char8
*szTypename
,
916 FieldContainer
*pCurrentFC
)
918 FWARNING(("Use default helper for %s, functionality currently not "
919 "supported\n", szTypename
));
921 return Inherited::beginNode(szTypename
, szName
, pCurrentFC
);
924 /*-------------------------------------------------------------------------*/
927 void VRMLDefaultHelper::dump(const Char8
*)
935 //---------------------------------------------------------------------------
936 // Generic Helper with 1:1 mapping
937 //---------------------------------------------------------------------------
940 VRMLNodeHelperFactoryBase::RegisterHelper
941 VRMLGenericHelper
<Group
>::_regHelper(
942 &VRMLGenericHelper
<Group
>::create
,
946 OSG_INST_GENERICVRMLHELPER(Group
);
949 VRMLNodeHelperFactoryBase::RegisterHelper
950 VRMLGenericHelper
<ComponentTransform
>::_regHelper(
951 &VRMLGenericHelper
<ComponentTransform
>::create
,
955 OSG_INST_GENERICVRMLHELPER(ComponentTransform
);
959 //---------------------------------------------------------------------------
961 //---------------------------------------------------------------------------
963 VRMLNodeHelper
*VRMLMaterialHelper::create(void)
965 return new VRMLMaterialHelper();
968 /*-------------------------------------------------------------------------*/
971 VRMLMaterialHelper::VRMLMaterialHelper(void) :
974 _defaultAmbientIntensity(),
975 _defaultDiffuseColor (),
976 _defaultEmissiveColor (),
977 _defaultShininess (),
978 _defaultSpecularColor (),
979 _defaultTransparency (),
981 _ambientIntensity (),
995 /*-------------------------------------------------------------------------*/
998 VRMLMaterialHelper::~VRMLMaterialHelper(void)
1003 /*-------------------------------------------------------------------------*/
1006 void VRMLMaterialHelper::init(const Char8
*OSG_VRML_ARG(szName
))
1008 #ifdef OSG_DEBUG_VRML
1009 indentLog(getIndent(), PINFO
);
1010 PINFO
<< "MaterialDesc::init : " << szName
<< std::endl
;
1015 void VRMLMaterialHelper::reset(void)
1017 _ambientIntensity
.setValue(_defaultAmbientIntensity
);
1018 _diffuseColor
.setValue(_defaultDiffuseColor
);
1019 _emissiveColor
.setValue(_defaultEmissiveColor
);
1020 _shininess
.setValue(_defaultShininess
);
1021 _specularColor
.setValue(_defaultSpecularColor
);
1022 _transparency
.setValue(_defaultTransparency
);
1029 Material
*VRMLMaterialHelper::getDefaultMaterial(void)
1034 /*-------------------------------------------------------------------------*/
1037 bool VRMLMaterialHelper::prototypeAddField(const Char8
*,
1039 const Char8
*szFieldname
)
1041 bool bFound
= false;
1043 if(osgStringCaseCmp("ambientIntensity", szFieldname
) == 0)
1047 else if(osgStringCaseCmp("diffuseColor", szFieldname
) == 0)
1051 else if(osgStringCaseCmp("emissiveColor", szFieldname
) == 0)
1055 else if(osgStringCaseCmp("shininess", szFieldname
) == 0)
1059 else if(osgStringCaseCmp("specularColor", szFieldname
) == 0)
1063 else if(osgStringCaseCmp("transparency", szFieldname
) == 0)
1070 #ifdef OSG_DEBUG_VRML
1071 indentLog(getIndent(), PINFO
);
1072 PINFO
<< "MaterialDesc::prototypeAddField : add part "
1084 void VRMLMaterialHelper::endProtoInterface(void)
1087 MaterialChunkUnrecPtr pMatChunk
;
1089 cCol
.setValuesRGBA(_defaultDiffuseColor
.getValue().red() *
1090 _defaultAmbientIntensity
.getValue(),
1091 _defaultDiffuseColor
.getValue().green() *
1092 _defaultAmbientIntensity
.getValue(),
1093 _defaultDiffuseColor
.getValue().blue() *
1094 _defaultAmbientIntensity
.getValue(),
1095 1.f
- _defaultTransparency
.getValue());
1097 _pDefMat
= ChunkMaterial::create();
1099 pMatChunk
= MaterialChunk::create();
1101 pMatChunk
->setAmbient(cCol
);
1103 cCol
.setValuesRGBA (_defaultDiffuseColor
.getValue()[0],
1104 _defaultDiffuseColor
.getValue()[1],
1105 _defaultDiffuseColor
.getValue()[2],
1106 1.f
- _defaultTransparency
.getValue());
1108 pMatChunk
->setDiffuse(cCol
);
1110 cCol
.setValuesRGBA (_defaultSpecularColor
.getValue()[0],
1111 _defaultSpecularColor
.getValue()[1],
1112 _defaultSpecularColor
.getValue()[2],
1113 1.f
- _defaultTransparency
.getValue());
1114 pMatChunk
->setSpecular(cCol
);
1116 pMatChunk
->setShininess(_defaultShininess
.getValue() * 128.f
);
1118 cCol
.setValuesRGBA (_defaultEmissiveColor
.getValue()[0],
1119 _defaultEmissiveColor
.getValue()[1],
1120 _defaultEmissiveColor
.getValue()[2],
1121 1.f
- _defaultTransparency
.getValue());
1122 pMatChunk
->setEmission(cCol
);
1124 _pDefMat
->addChunk(pMatChunk
);
1126 Inherited::endProtoInterface();
1130 void VRMLMaterialHelper::getFieldAndDesc(
1132 const Char8
* szFieldname
,
1133 FieldContainer
*&pFieldFC
,
1134 EditFieldHandlePtr
&pField
,
1135 const FieldDescriptionBase
*&pDesc
)
1141 if(osgStringCaseCmp("ambientIntensity", szFieldname
) == 0)
1145 if(_bProtoInterfaceDone
== false)
1148 _sfReal32Desc
.createEditHandler(&_defaultAmbientIntensity
,
1153 pField
= _sfReal32Desc
.createEditHandler(&_ambientIntensity
,
1157 pDesc
= &_sfReal32Desc
;
1159 else if(osgStringCaseCmp("diffuseColor", szFieldname
) == 0)
1163 if(_bProtoInterfaceDone
== false)
1165 pField
= _sfColor3fDesc
.createEditHandler(&_defaultDiffuseColor
,
1170 pField
= _sfColor3fDesc
.createEditHandler(&_diffuseColor
,
1174 pDesc
= &_sfColor3fDesc
;
1176 else if(osgStringCaseCmp("emissiveColor", szFieldname
) == 0)
1180 if(_bProtoInterfaceDone
== false)
1182 pField
= _sfColor3fDesc
.createEditHandler(&_defaultEmissiveColor
,
1187 pField
= _sfColor3fDesc
.createEditHandler(&_emissiveColor
,
1191 pDesc
= &_sfColor3fDesc
;
1193 else if(osgStringCaseCmp("shininess", szFieldname
) == 0)
1197 if(_bProtoInterfaceDone
== false)
1199 pField
= _sfReal32Desc
.createEditHandler(&_defaultShininess
,
1204 pField
= _sfReal32Desc
.createEditHandler(&_shininess
,
1208 pDesc
= &_sfReal32Desc
;
1210 else if(osgStringCaseCmp("specularColor", szFieldname
) == 0)
1214 if(_bProtoInterfaceDone
== false)
1216 pField
= _sfColor3fDesc
.createEditHandler(&_defaultSpecularColor
,
1221 pField
= _sfColor3fDesc
.createEditHandler(&_specularColor
,
1225 pDesc
= &_sfColor3fDesc
;
1227 else if(osgStringCaseCmp("transparency", szFieldname
) == 0)
1231 if(_bProtoInterfaceDone
== false)
1233 pField
= _sfReal32Desc
.createEditHandler(&_defaultTransparency
,
1238 pField
= _sfReal32Desc
.createEditHandler(&_transparency
,
1242 pDesc
= &_sfReal32Desc
;
1246 /*-------------------------------------------------------------------------*/
1249 FieldContainerTransitPtr
VRMLMaterialHelper::beginNode(
1251 const Char8
*szName
,
1256 _pMat
= MaterialChunk::create();
1258 _szName
= (szName
!= NULL
) ? szName
: "";
1260 return FieldContainerTransitPtr(_pMat
);
1263 void VRMLMaterialHelper::endNode(FieldContainer
*)
1269 cCol
.setValuesRGBA (_diffuseColor
.getValue().red() *
1270 _ambientIntensity
.getValue(),
1271 _diffuseColor
.getValue().green() *
1272 _ambientIntensity
.getValue(),
1273 _diffuseColor
.getValue().blue() *
1274 _ambientIntensity
.getValue(),
1275 1.f
- _transparency
.getValue());
1277 _pMat
->setAmbient (cCol
);
1279 cCol
.setValuesRGBA (_diffuseColor
.getValue()[0],
1280 _diffuseColor
.getValue()[1],
1281 _diffuseColor
.getValue()[2],
1282 1.f
- _transparency
.getValue());
1283 _pMat
->setDiffuse (cCol
);
1285 cCol
.setValuesRGBA (_specularColor
.getValue()[0],
1286 _specularColor
.getValue()[1],
1287 _specularColor
.getValue()[2],
1288 1.f
- _transparency
.getValue());
1289 _pMat
->setSpecular (cCol
);
1291 _pMat
->setShininess(_shininess
.getValue() * 128.f
);
1293 cCol
.setValuesRGBA (_emissiveColor
.getValue()[0],
1294 _emissiveColor
.getValue()[1],
1295 _emissiveColor
.getValue()[2],
1296 1.f
- _transparency
.getValue());
1297 _pMat
->setEmission (cCol
);
1302 /*-------------------------------------------------------------------------*/
1305 const std::string
&VRMLMaterialHelper::getName(void) const
1310 /*-------------------------------------------------------------------------*/
1313 void VRMLMaterialHelper::dump(const Char8
*)
1317 VRMLNodeHelperFactoryBase::RegisterHelper
VRMLMaterialHelper::_regHelper(
1318 &VRMLMaterialHelper::create
,
1326 //---------------------------------------------------------------------------
1328 //---------------------------------------------------------------------------
1330 VRMLNodeHelper
*VRMLShapeHelper::create(void)
1332 return new VRMLShapeHelper();
1336 /*-------------------------------------------------------------------------*/
1339 VRMLShapeHelper::VRMLShapeHelper(void) :
1341 _pMaterialHelper(NULL
)
1345 /*-------------------------------------------------------------------------*/
1348 VRMLShapeHelper::~VRMLShapeHelper(void)
1352 /*-------------------------------------------------------------------------*/
1355 void VRMLShapeHelper::init(const Char8
*szName
)
1357 Inherited::init(szName
);
1359 #ifdef OSG_DEBUG_VRML
1360 indentLog(getIndent(), PINFO
);
1361 PINFO
<< "ShapeHelper::init : " << szName
<< std::endl
;
1364 _pNodeProto
= Node ::create();
1365 _pNodeCoreProto
= MaterialGroup::create();
1367 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
1368 _pGenAttProto
->setInternal(true);
1371 void VRMLShapeHelper::setMaterialHelper(VRMLMaterialHelper
*pMaterialHelper
)
1373 _pMaterialHelper
= pMaterialHelper
;
1376 /*-------------------------------------------------------------------------*/
1379 bool VRMLShapeHelper::prototypeAddField(const Char8
*szFieldType
,
1380 const UInt32 uiFieldTypeId
,
1381 const Char8
*szFieldname
)
1383 bool returnValue
= false;
1385 #ifdef OSG_DEBUG_VRML
1386 indentLog(getIndent(), PINFO
);
1387 PINFO
<< "VRMLShapeHelper::prototypeAddField | add request : "
1392 if(szFieldname
== NULL
)
1397 if(osgStringCaseCmp("geometry", szFieldname
) == 0)
1401 #ifdef OSG_DEBUG_VRML
1402 indentLog(getIndent(), PINFO
);
1403 PINFO
<< "VRMLShapeHelper::prototypeAddField | request internal : "
1410 if(osgStringCaseCmp("appearance", szFieldname
) == 0)
1414 #ifdef OSG_DEBUG_VRML
1415 indentLog(getIndent(), PINFO
);
1417 PINFO
<< "VRMLShapeHelper::prototypeAddField | request internal : "
1424 if(returnValue
== false)
1426 returnValue
= Inherited::prototypeAddField(szFieldType
,
1431 #ifdef OSG_DEBUG_VRML
1438 void VRMLShapeHelper::getFieldAndDesc(
1439 FieldContainer
* pFC
,
1440 const Char8
* szFieldname
,
1441 FieldContainer
*&pFieldFC
,
1442 EditFieldHandlePtr
&pField
,
1443 const FieldDescriptionBase
*&pDesc
)
1445 if(szFieldname
== NULL
)
1450 if(_bProtoInterfaceDone
== false)
1452 Inherited::getField(szFieldname
, pFieldFC
, pField
, pDesc
);
1458 #ifdef OSG_DEBUG_VRML
1459 indentLog(getIndent(), PINFO
);
1460 PINFO
<< "VRMLShapeHelper::getFieldAndDesc : looking for "
1467 if(osgStringCaseCmp("geometry", szFieldname
) == 0)
1469 #ifdef OSG_DEBUG_VRML
1470 indentLog(getIndent(), PINFO
);
1471 PINFO
<< "VRMLShapeHelper::getFieldAndDesc : request internal "
1476 pField
= pFC
->editField("children");
1477 pDesc
= pFC
->getFieldDescription("children");
1479 else if(osgStringCaseCmp("appearance", szFieldname
) == 0)
1481 #ifdef OSG_DEBUG_VRML
1482 indentLog(getIndent(), PINFO
);
1483 PINFO
<< "VRMLShapeHelper::getFieldAndDesc : request internal "
1488 Node
*pNode
= dynamic_cast<Node
*>(pFC
);
1492 if(pNode
->getCore() != NULL
)
1494 pFieldFC
= pNode
->getCore();
1495 pField
= pNode
->getCore()->editField("material");
1496 pDesc
= pNode
->getCore()->getFieldDescription("material");
1501 Inherited::getFieldAndDesc(pFC
,
1510 Inherited::getFieldAndDesc(pFC
,
1517 #ifdef OSG_DEBUG_VRML
1522 /*-------------------------------------------------------------------------*/
1526 void VRMLShapeHelper::endNode(FieldContainer
*pFC
)
1530 Node
*pNode
= dynamic_cast<Node
*>(pFC
);
1532 if(pNode
!= NULL
&& pNode
->getCore() == NULL
)
1534 PWARNING
<< "warning empty material, using default\n" << std::endl
;
1536 MaterialGroupUnrecPtr pMatGroup
= MaterialGroup::create();
1538 pMatGroup
->setMaterial(_pMaterialHelper
->getDefaultMaterial());
1540 pNode
->setCore(pMatGroup
);
1544 MaterialGroup
*pMatGroup
;
1546 pMatGroup
= dynamic_cast<MaterialGroup
*>(pNode
->getCore());
1548 if(pMatGroup
!= NULL
)
1550 if(pMatGroup
->getMaterial() == NULL
)
1552 pMatGroup
->setMaterial(
1553 _pMaterialHelper
->getDefaultMaterial());
1558 if(pNode
->getNChildren() > 0)
1560 Node
*pChild
= pNode
->getChild(0);
1564 Geometry
*pShapeGeo
= pChild
->getCore
<Geometry
>();
1565 MaterialGroup
*pShapeMat
= pNode
->getCore
<MaterialGroup
>();
1567 if(pShapeGeo
!= NULL
&& pShapeMat
!= NULL
)
1569 pShapeGeo
->setMaterial(pShapeMat
->getMaterial());
1575 #ifdef OSG_DEBUG_VRML
1578 indentLog(getIndent(), PINFO
);
1579 PINFO
<< "End Shape " << &(*pFC
) << std::endl
;
1583 /*-------------------------------------------------------------------------*/
1586 void VRMLShapeHelper::dump(const Char8
*)
1590 VRMLNodeHelperFactoryBase::RegisterHelper
VRMLShapeHelper::_regHelper(
1591 &VRMLShapeHelper::create
,
1598 //---------------------------------------------------------------------------
1600 //---------------------------------------------------------------------------
1602 VRMLNodeHelper
*VRMLAppearanceHelper::create(void)
1604 return new VRMLAppearanceHelper();
1607 /*-------------------------------------------------------------------------*/
1610 VRMLAppearanceHelper::VRMLAppearanceHelper(void) :
1612 _pMaterialHelper(NULL
)
1616 /*-------------------------------------------------------------------------*/
1619 VRMLAppearanceHelper::~VRMLAppearanceHelper(void)
1623 /*-------------------------------------------------------------------------*/
1626 void VRMLAppearanceHelper::init(const Char8
*szName
)
1628 Inherited::init(szName
);
1630 #ifdef OSG_DEBUG_VRML
1631 indentLog(getIndent(), PINFO
);
1632 PINFO
<< "ApperanceHelper::init : " << szName
<< std::endl
;
1635 _pNodeProto
= ChunkMaterial::create();
1637 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
1638 _pGenAttProto
->setInternal(true);
1641 void VRMLAppearanceHelper::setMaterialHelper(
1642 VRMLMaterialHelper
*pMaterialHelper
)
1644 _pMaterialHelper
= pMaterialHelper
;
1647 /*-------------------------------------------------------------------------*/
1650 bool VRMLAppearanceHelper::prototypeAddField(const Char8
*szFieldType
,
1651 const UInt32 uiFieldTypeId
,
1652 const Char8
*szFieldname
)
1654 if(szFieldname
== NULL
)
1657 if(osgStringCaseCmp("material", szFieldname
) == 0)
1661 else if(osgStringCaseCmp("texture", szFieldname
) == 0)
1665 else if(osgStringCaseCmp("textureTransform", szFieldname
) == 0)
1671 return Inherited::prototypeAddField(szFieldType
,
1677 void VRMLAppearanceHelper::getFieldAndDesc(
1678 FieldContainer
* pFC
,
1679 const Char8
* szFieldname
,
1680 FieldContainer
*&pFieldFC
,
1681 EditFieldHandlePtr
&pField
,
1682 const FieldDescriptionBase
*&pDesc
)
1685 #ifdef OSG_DEBUG_VRML
1686 indentLog(getIndent(), PINFO
);
1687 PINFO
<< "VRMLAppearanceHelper::getFieldAndDesc : looking for "
1694 if(_bProtoInterfaceDone
== false)
1696 Inherited::getField(szFieldname
, pFieldFC
, pField
, pDesc
);
1702 if(szFieldname
== NULL
)
1707 if(osgStringCaseCmp("material", szFieldname
) == 0)
1709 #ifdef OSG_DEBUG_VRML
1710 indentLog(getIndent(), PINFO
);
1711 PINFO
<< "VRMLAppearanceDesc::getFieldAndDesc : request internal "
1716 pField
= pFC
->editField("chunks");
1717 pDesc
= pFC
->getFieldDescription("chunks");
1719 else if(osgStringCaseCmp("texture", szFieldname
) == 0)
1721 #ifdef OSG_DEBUG_VRML
1722 indentLog(getIndent(), PINFO
);
1723 PINFO
<< "VRMLAppearanceHelper::getFieldAndDesc : request internal "
1729 pField
= pFC
->editField("chunks");
1730 pDesc
= pFC
->getFieldDescription("chunks");
1732 else if(osgStringCaseCmp("textureTransform", szFieldname
) == 0)
1734 #ifdef OSG_DEBUG_VRML
1735 indentLog(getIndent(), PINFO
);
1736 PINFO
<< "VRMLAppearanceDesc::getFieldAndDesc : request internal "
1742 pField
= pFC
->editField("chunks");
1743 pDesc
= pFC
->getFieldDescription("chunks");
1747 Inherited::getFieldAndDesc(pFC
,
1754 #ifdef OSG_DEBUG_VRML
1759 /*-------------------------------------------------------------------------*/
1763 void VRMLAppearanceHelper::endNode(FieldContainer
*pFC
)
1767 ChunkMaterial
*pChunkMat
= dynamic_cast<ChunkMaterial
*>(pFC
);
1769 if(pChunkMat
!= NULL
)
1771 TextureObjChunk
*pTexC
=
1772 dynamic_cast<TextureObjChunk
*>(
1773 pChunkMat
->find(TextureObjChunk::getClassType()));
1775 TextureEnvChunkUnrecPtr pTexE
=
1776 dynamic_cast<TextureEnvChunk
*>(
1777 pChunkMat
->find(TextureEnvChunk::getClassType()));
1782 if ((pChunkMat
->isTransparent() == true) ||
1784 pTexC
->getImage() != NULL
&&
1785 pTexC
->getImage()->hasAlphaChannel() == true ))
1787 BlendChunkUnrecPtr pBlendChunk
= OSG::BlendChunk::create();
1790 pTexC
->getImage() != NULL
&&
1791 pTexC
->getImage()->isAlphaBinary() == true)
1793 pBlendChunk
->setAlphaFunc(GL_NOTEQUAL
);
1794 pBlendChunk
->setAlphaValue(0);
1798 pBlendChunk
->setSrcFactor (GL_SRC_ALPHA
);
1799 pBlendChunk
->setDestFactor(GL_ONE_MINUS_SRC_ALPHA
);
1802 pChunkMat
->addChunk(pBlendChunk
);
1809 pTexE
= TextureEnvChunk::create();
1811 pChunkMat
->addChunk(pTexE
);
1814 MaterialChunk
*pMatC
=
1815 dynamic_cast<MaterialChunk
*>(
1816 pChunkMat
->find(MaterialChunk::getClassType()));
1820 pTexE
->setEnvMode(GL_REPLACE
);
1824 pTexE
->setEnvMode(GL_MODULATE
);
1829 // This works around the problem that MaterialChunks can not have
1830 // NameAttachments on them (they are attachments themselves).
1832 // If the ChunkMaterial (which corresponds to the VRML Appearance Node)
1833 // has no name of its own, the material's name is set instead.
1835 // BEGIN Material name hack
1837 AttachmentContainer
*attCon
=
1838 dynamic_cast<AttachmentContainer
*>(pFC
);
1839 bool pushNames
= false;
1841 if(SceneFileHandler::the()->getOptionAs("wrl",
1843 pushNames
) == false)
1848 if(( attCon
!= NULL
) &&
1849 ( pushNames
== true ) &&
1850 (_pMaterialHelper
!= NULL
) &&
1851 (_pMaterialHelper
->getName().empty() == false) )
1853 FieldContainer
*att
= attCon
->findAttachment(
1854 Name::getClassType().getGroupId());
1858 // ChunkMaterial (Appearance) already has a NameAttachment
1859 Name
*nameAtt
= dynamic_cast<Name
*>(att
);
1863 if(nameAtt
->getFieldPtr()->getValue().empty())
1865 nameAtt
->editFieldPtr()->getValue().assign(
1866 _pMaterialHelper
->getName());
1872 setName(attCon
, _pMaterialHelper
->getName());
1876 // END Material name hack
1881 #ifdef OSG_DEBUG_VRML
1884 indentLog(getIndent(), PINFO
);
1885 PINFO
<< "End Appearance " << std::endl
;
1889 /*-------------------------------------------------------------------------*/
1892 /*-------------------------------------------------------------------------*/
1895 void VRMLAppearanceHelper::dump(const Char8
*)
1899 VRMLNodeHelperFactoryBase::RegisterHelper
VRMLAppearanceHelper::_regHelper(
1900 &VRMLAppearanceHelper::create
,
1907 //---------------------------------------------------------------------------
1909 //---------------------------------------------------------------------------
1911 VRMLNodeHelper
*VRMLIndexedGeometryHelper::create(void)
1913 return new VRMLIndexedGeometryHelper();
1916 /*-------------------------------------------------------------------------*/
1919 VRMLIndexedGeometryHelper::VRMLIndexedGeometryHelper(void) :
1921 _bIsFaceSet (false ),
1922 _uiPropertyIndex(Geometry::PositionsIndex
)
1926 /*-------------------------------------------------------------------------*/
1929 VRMLIndexedGeometryHelper::~VRMLIndexedGeometryHelper(void)
1933 /*-------------------------------------------------------------------------*/
1936 void VRMLIndexedGeometryHelper::init(const Char8
*szName
)
1938 Inherited::init(szName
);
1940 #ifdef OSG_DEBUG_VRML
1941 indentLog(getIndent(), PINFO
);
1942 PINFO
<< "GeoDesc::init : " << szName
<< std::endl
;
1945 _pNodeProto
= Node ::create();
1946 _pNodeCoreProto
= Geometry ::create();
1948 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
1949 _pGenAttProto
->setInternal(true);
1951 if(osgStringCaseCmp("IndexedFaceSet", szName
) == 0)
1957 /*-------------------------------------------------------------------------*/
1960 bool VRMLIndexedGeometryHelper::prototypeAddField(const Char8
*szFieldType
,
1961 const UInt32 uiFieldTypeId
,
1962 const Char8
*szFieldname
)
1964 bool bFound
= false;
1966 if(szFieldname
== NULL
)
1969 if(osgStringCaseCmp("coord", szFieldname
) == 0)
1973 else if(osgStringCaseCmp("normal", szFieldname
) == 0)
1977 else if(osgStringCaseCmp("color", szFieldname
) == 0)
1981 else if(osgStringCaseCmp("texCoord", szFieldname
) == 0)
1988 #ifdef OSG_DEBUG_VRML
1989 indentLog(getIndent(), PINFO
);
1990 PINFO
<< "GeoDesc::prototypeAddField : internal "
1991 << szFieldname
<< std::endl
;
1998 return Inherited::prototypeAddField(szFieldType
,
2005 void VRMLIndexedGeometryHelper::getFieldAndDesc(
2006 FieldContainer
* pFC
,
2007 const Char8
* szFieldname
,
2008 FieldContainer
*&pFieldFC
,
2009 EditFieldHandlePtr
&pField
,
2010 const FieldDescriptionBase
*&pDesc
)
2012 #ifdef OSG_DEBUG_VRML
2013 indentLog(getIndent(), PINFO
);
2014 PINFO
<< "GeoDesc::getFieldAndDesc : request "
2019 if(szFieldname
== NULL
)
2024 if(_bProtoInterfaceDone
== false)
2026 Inherited::getField(szFieldname
, pFieldFC
, pField
, pDesc
);
2032 Node
*pNode
= dynamic_cast<Node
*>(pFC
);
2036 PWARNING
<< "GeoDesc::getFieldAndDesc : No Node" << std::endl
;
2040 NodeCore
*pNodeCore
= pNode
->getCore();
2042 Geometry
*pGeo
= dynamic_cast<Geometry
*>(pNodeCore
);
2046 PWARNING
<< "GeoDesc::getFieldAndDesc : No Geo" << std::endl
;
2050 if(osgStringCaseCmp("coord", szFieldname
) == 0)
2052 #ifdef OSG_DEBUG_VRML
2053 indentLog(getIndent(), PINFO
);
2054 PINFO
<< "GeoDesc::getFieldAndDesc : internal "
2055 << szFieldname
<< std::endl
;
2060 pDesc
= &_sfFCPtrDesc
;
2062 _uiPropertyIndex
= Geometry::PositionsIndex
;
2064 else if(osgStringCaseCmp("normal", szFieldname
) == 0)
2066 #ifdef OSG_DEBUG_VRML
2067 indentLog(getIndent(), PINFO
);
2068 PINFO
<< "GeoDesc::getFieldAndDesc : internal "
2069 << szFieldname
<< std::endl
;
2074 pDesc
= &_sfFCPtrDesc
;
2076 _uiPropertyIndex
= Geometry::NormalsIndex
;
2078 else if(osgStringCaseCmp("color", szFieldname
) == 0)
2080 #ifdef OSG_DEBUG_VRML
2081 indentLog(getIndent(), PINFO
);
2082 PINFO
<< "GeoDesc::getFieldAndDesc : internal "
2083 << szFieldname
<< std::endl
;
2088 pDesc
= &_sfFCPtrDesc
;
2090 _uiPropertyIndex
= Geometry::ColorsIndex
;
2092 else if(osgStringCaseCmp("texCoord", szFieldname
) == 0)
2094 #ifdef OSG_DEBUG_VRML
2095 indentLog(getIndent(), PINFO
);
2096 PINFO
<< "GeoDesc::getFieldAndDesc : internal "
2097 << szFieldname
<< std::endl
;
2102 pDesc
= &_sfFCPtrDesc
;
2104 _uiPropertyIndex
= Geometry::TexCoordsIndex
;
2108 Inherited::getFieldAndDesc(pGeo
,
2116 /*-------------------------------------------------------------------------*/
2121 void VRMLIndexedGeometryHelper::endNode(FieldContainer
*pFC
)
2124 Geometry
*pGeo
= NULL
;
2131 pNode
= dynamic_cast<Node
*>(pFC
);
2138 pGeo
= dynamic_cast<Geometry
*>(pNode
->getCore());
2145 EditFieldHandlePtr pField
;
2146 const FieldDescriptionBase
*pDesc
= NULL
;
2147 FieldContainer
*pDummyFC
= NULL
;
2150 MFInt32
*pCoordIndex
= NULL
;
2151 MFInt32
*pNormalIndex
= NULL
;
2152 MFInt32
*pColorIndex
= NULL
;
2153 MFInt32
*pTexCoordIndex
= NULL
;
2154 SFBool
*pConvex
= NULL
;
2155 SFBool
*pCcw
= NULL
;
2156 SFBool
*pNormalPerVertex
= NULL
;
2157 SFBool
*pColorPerVertex
= NULL
;
2158 SFReal32
*pCreaseAngle
= NULL
;
2160 Inherited::getFieldAndDesc(pFC
,
2168 MFInt32::EditHandlePtr pValField
=
2169 boost::dynamic_pointer_cast
<MFInt32::EditHandle
>(pField
);
2171 if(pValField
!= NULL
&& pValField
->isValid())
2173 pCoordIndex
= pValField
->getField();
2177 Inherited::getFieldAndDesc(pFC
,
2185 MFInt32::EditHandlePtr pValField
=
2186 boost::dynamic_pointer_cast
<MFInt32::EditHandle
>(pField
);
2188 if(pValField
!= NULL
&& pValField
->isValid())
2190 pNormalIndex
= pValField
->getField();
2194 Inherited::getFieldAndDesc(pFC
,
2202 MFInt32::EditHandlePtr pValField
=
2203 boost::dynamic_pointer_cast
<MFInt32::EditHandle
>(pField
);
2205 if(pValField
!= NULL
&& pValField
->isValid())
2207 pColorIndex
= pValField
->getField();
2211 Inherited::getFieldAndDesc(pFC
,
2219 MFInt32::EditHandlePtr pValField
=
2220 boost::dynamic_pointer_cast
<MFInt32::EditHandle
>(pField
);
2222 if(pValField
!= NULL
&& pValField
->isValid())
2224 pTexCoordIndex
= pValField
->getField();
2230 Inherited::getFieldAndDesc(pFC
,
2238 SFBool::EditHandlePtr pValField
=
2239 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
2241 if(pValField
!= NULL
&& pValField
->isValid())
2243 pConvex
= pValField
->getField();
2247 Inherited::getFieldAndDesc(pFC
,
2255 SFBool::EditHandlePtr pValField
=
2256 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
2258 if(pValField
!= NULL
&& pValField
->isValid())
2260 pCcw
= pValField
->getField();
2264 Inherited::getFieldAndDesc(pFC
,
2272 SFBool::EditHandlePtr pValField
=
2273 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
2275 if(pValField
!= NULL
&& pValField
->isValid())
2277 pNormalPerVertex
= pValField
->getField();
2281 Inherited::getFieldAndDesc(pFC
,
2289 SFBool::EditHandlePtr pValField
=
2290 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
2292 if(pValField
!= NULL
&& pValField
->isValid())
2294 pColorPerVertex
= pValField
->getField();
2298 Inherited::getFieldAndDesc(pFC
,
2306 SFReal32::EditHandlePtr pValField
=
2307 boost::dynamic_pointer_cast
<SFReal32::EditHandle
>(pField
);
2309 if(pValField
!= NULL
&& pValField
->isValid())
2311 pCreaseAngle
= pValField
->getField();
2315 if(_bIsFaceSet
== true)
2317 if(pCoordIndex
!= NULL
&&
2318 pCoordIndex
->size() > 2 &&
2319 pNormalIndex
!= NULL
&&
2320 pColorIndex
!= NULL
&&
2321 pTexCoordIndex
!= NULL
&&
2324 pNormalPerVertex
!= NULL
&&
2325 pColorPerVertex
!= NULL
&&
2326 pCreaseAngle
!= NULL
)
2328 #ifdef OSG_DEBUG_VRML
2329 indentLog(getIndent(), PINFO
);
2330 PINFO
<< "Geo create faceset " << &(*pNode
) << std::endl
;
2333 setIndexFromIndexedX3DData(pGeo
,
2334 pCoordIndex
->getValues(),
2335 pNormalIndex
->getValues(),
2336 pColorIndex
->getValues(),
2337 pTexCoordIndex
->getValues(),
2339 pConvex
->getValue() ,
2341 pNormalPerVertex
->getValue() ,
2342 pColorPerVertex
->getValue() ,
2343 false); // create normal; not yet :)
2345 //if (pConvex->getValue() == false)
2346 // createConvexPrimitives( pGeo );
2348 // TODO: Need some option _uiOptions param
2349 //createSharedIndex( pGeo);
2351 //if((0 != (_uiOptions & VRMLFile::CreateNormals) ) &&
2352 // (pGeo->getNormals() == NULL))
2354 if(pGeo
->getNormals() == NULL
)
2356 #ifdef OSG_DEBUG_VRML
2357 indentLog(getIndent(), PINFO
);
2358 PINFO
<< "Geo create normals " << &(*pNode
) << std::endl
;
2361 OSG::calcVertexNormals(pGeo
, pCreaseAngle
->getValue());
2366 #if 0 // What's the point of doing that?
2367 PWARNING
<< "Invalid geometry replaced by a group" << std::endl
;
2369 GroupPtr pGr
= Group::create();
2371 MFNodePtr pGeoParents
= pGeo
->getParents ();
2372 MFNodePtr::iterator parentsIt
= pGeoParents
.begin();
2373 MFNodePtr::iterator endParents
= pGeoParents
.end ();
2375 // this makes pGeo invalid!
2376 while(parentsIt
!= endParents
)
2378 (*parentsIt
)->setCore(pGr
);
2388 std::vector
<Int32
> dummyVec
;
2389 bool dummybool
= false;
2391 if(pCoordIndex
!= NULL
&&
2392 pCoordIndex
->size() > 1 &&
2393 pColorIndex
!= NULL
&&
2394 pColorPerVertex
!= NULL
)
2396 #ifdef OSG_DEBUG_VRML
2397 indentLog(getIndent(), PINFO
);
2398 PINFO
<< "Geo create lineset " << &(*pNode
) << std::endl
;
2401 setIndexFromIndexedX3DData(pGeo
,
2402 pCoordIndex
->getValues(),
2404 pColorIndex
->getValues(),
2410 pColorPerVertex
->getValue() ,
2411 false); // create normal; not yet :)
2415 #if 0 // What's the point of doing that?
2416 PWARNING
<< "Invalid geometry replaced by a group" << std::endl
;
2418 GroupPtr pGr
= Group::create();
2420 MFNodePtr pGeoParents
= pGeo
->getParents ();
2421 MFNodePtr::iterator parentsIt
= pGeoParents
.begin();
2422 MFNodePtr::iterator endParents
= pGeoParents
.end ();
2424 // this makes pGeo invalid!
2425 while(parentsIt
!= endParents
)
2427 (*parentsIt
)->setCore(pGr
);
2436 #ifdef OSG_DEBUG_VRML
2439 indentLog(getIndent(), PINFO
);
2440 PINFO
<< "End Geo " << &(*pNode
) << std::endl
;
2445 void VRMLIndexedGeometryHelper::setContainerFieldValue(
2446 FieldContainer
*pFC
,
2447 const FieldDescriptionBase
*pFieldDesc
,
2448 FieldContainer
*pFieldFC
)
2451 dynamic_cast<Geometry
*>(pFieldFC
);
2453 GeoVectorProperty
*pVecProp
=
2454 dynamic_cast<GeoVectorProperty
*>(pFC
);
2456 if(pGeo
!= NULL
&& pVecProp
!= NULL
)
2458 pGeo
->setProperty(pVecProp
, _uiPropertyIndex
);
2462 PWARNING
<< "GeoDesc::getFieldAndDesc : No Geo" << std::endl
;
2466 /*-------------------------------------------------------------------------*/
2469 void VRMLIndexedGeometryHelper::dump(const Char8
*)
2474 VRMLNodeHelperFactoryBase::RegisterHelper
2475 VRMLIndexedGeometryHelper::_regHelperIFS(
2476 &VRMLIndexedGeometryHelper::create
,
2480 VRMLNodeHelperFactoryBase::RegisterHelper
2481 VRMLIndexedGeometryHelper::_regHelperILS(
2482 &VRMLIndexedGeometryHelper::create
,
2490 //---------------------------------------------------------------------------
2492 //---------------------------------------------------------------------------
2494 VRMLNodeHelper
*VRMLPointSetGeometryHelper::create(void)
2496 return new VRMLPointSetGeometryHelper();
2499 /*-------------------------------------------------------------------------*/
2502 VRMLPointSetGeometryHelper::VRMLPointSetGeometryHelper(void) :
2504 _uiPropertyIndex(Geometry::PositionsIndex
)
2508 /*-------------------------------------------------------------------------*/
2511 VRMLPointSetGeometryHelper::~VRMLPointSetGeometryHelper(void)
2515 /*-------------------------------------------------------------------------*/
2518 void VRMLPointSetGeometryHelper::init(const Char8
*szName
)
2520 Inherited::init(szName
);
2522 #ifdef OSG_DEBUG_VRML
2523 indentLog(getIndent(), PINFO
);
2524 PINFO
<< "GeoDesc::init : " << szName
<< std::endl
;
2527 _pNodeProto
= Node ::create();
2528 _pNodeCoreProto
= Geometry ::create();
2530 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
2531 _pGenAttProto
->setInternal(true);
2534 /*-------------------------------------------------------------------------*/
2537 bool VRMLPointSetGeometryHelper::prototypeAddField(const Char8
*szFieldType
,
2538 const UInt32 uiFieldTypeId
,
2539 const Char8
*szFieldname
)
2541 bool bFound
= false;
2543 if(szFieldname
== NULL
)
2546 if(osgStringCaseCmp("coord", szFieldname
) == 0)
2550 else if(osgStringCaseCmp("color", szFieldname
) == 0)
2557 #ifdef OSG_DEBUG_VRML
2558 indentLog(getIndent(), PINFO
);
2559 PINFO
<< "GeoDesc::prototypeAddField : internal "
2560 << szFieldname
<< std::endl
;
2567 return Inherited::prototypeAddField(szFieldType
,
2574 void VRMLPointSetGeometryHelper::getFieldAndDesc(
2575 FieldContainer
* pFC
,
2576 const Char8
* szFieldname
,
2577 FieldContainer
*&pFieldFC
,
2578 EditFieldHandlePtr
&pField
,
2579 const FieldDescriptionBase
*&pDesc
)
2581 #ifdef OSG_DEBUG_VRML
2582 indentLog(getIndent(), PINFO
);
2583 PINFO
<< "GeoDesc::getFieldAndDesc : request "
2588 if(szFieldname
== NULL
)
2593 if(_bProtoInterfaceDone
== false)
2595 Inherited::getField(szFieldname
, pFieldFC
, pField
, pDesc
);
2601 Node
*pNode
= dynamic_cast<Node
*>(pFC
);
2605 PWARNING
<< "GeoDesc::getFieldAndDesc : No Node" << std::endl
;
2609 NodeCore
*pNodeCore
= pNode
->getCore();
2611 Geometry
*pGeo
= dynamic_cast<Geometry
*>(pNodeCore
);
2615 PWARNING
<< "GeoDesc::getFieldAndDesc : No Geo" << std::endl
;
2619 if(osgStringCaseCmp("coord", szFieldname
) == 0)
2621 #ifdef OSG_DEBUG_VRML
2622 indentLog(getIndent(), PINFO
);
2623 PINFO
<< "GeoDesc::getFieldAndDesc : internal "
2624 << szFieldname
<< std::endl
;
2629 pDesc
= &_sfFCPtrDesc
;
2631 _uiPropertyIndex
= Geometry::PositionsIndex
;
2633 else if(osgStringCaseCmp("color", szFieldname
) == 0)
2635 #ifdef OSG_DEBUG_VRML
2636 indentLog(getIndent(), PINFO
);
2637 PINFO
<< "GeoDesc::getFieldAndDesc : internal "
2638 << szFieldname
<< std::endl
;
2643 pDesc
= &_sfFCPtrDesc
;
2645 _uiPropertyIndex
= Geometry::ColorsIndex
;
2649 Inherited::getFieldAndDesc(pGeo
,
2657 /*-------------------------------------------------------------------------*/
2662 void VRMLPointSetGeometryHelper::endNode(FieldContainer
*pFC
)
2665 Geometry
*pGeo
= NULL
;
2672 pNode
= dynamic_cast<Node
*>(pFC
);
2679 pGeo
= dynamic_cast<Geometry
*>(pNode
->getCore());
2686 GeoVectorProperty
*pPnts
= pGeo
->getProperty(Geometry::PositionsIndex
);
2691 GeoUInt32PropertyUnrecPtr lens
= GeoUInt32Property::create();
2692 GeoUInt8PropertyUnrecPtr types
= GeoUInt8Property ::create();
2694 types
->push_back(GL_POINTS
);
2695 lens
->push_back(pPnts
->size());
2697 pGeo
->setTypes (types
);
2698 pGeo
->setLengths(lens
);
2701 EditFieldHandlePtr pField
;
2702 const FieldDescriptionBase
*pDesc
= NULL
;
2703 FieldContainer
*pDummyFC
= NULL
;
2707 if(_bIsFaceSet
== true)
2709 if(pCoordIndex
!= NULL
&&
2710 pCoordIndex
->size() > 2 &&
2711 pNormalIndex
!= NULL
&&
2712 pColorIndex
!= NULL
&&
2713 pTexCoordIndex
!= NULL
&&
2716 pNormalPerVertex
!= NULL
&&
2717 pColorPerVertex
!= NULL
&&
2718 pCreaseAngle
!= NULL
)
2720 #ifdef OSG_DEBUG_VRML
2721 indentLog(getIndent(), PINFO
);
2722 PINFO
<< "Geo create faceset " << &(*pNode
) << std::endl
;
2725 setIndexFromIndexedX3DData(pGeo
,
2726 pCoordIndex
->getValues(),
2727 pNormalIndex
->getValues(),
2728 pColorIndex
->getValues(),
2729 pTexCoordIndex
->getValues(),
2731 pConvex
->getValue() ,
2733 pNormalPerVertex
->getValue() ,
2734 pColorPerVertex
->getValue() ,
2735 false); // create normal; not yet :)
2737 //if (pConvex->getValue() == false)
2738 // createConvexPrimitives( pGeo );
2740 // TODO: Need some option _uiOptions param
2741 //createSharedIndex( pGeo);
2743 //if((0 != (_uiOptions & VRMLFile::CreateNormals) ) &&
2744 // (pGeo->getNormals() == NULL))
2746 if(pGeo
->getNormals() == NULL
)
2748 #ifdef OSG_DEBUG_VRML
2749 indentLog(getIndent(), PINFO
);
2750 PINFO
<< "Geo create normals " << &(*pNode
) << std::endl
;
2753 OSG::calcVertexNormals(pGeo
, pCreaseAngle
->getValue());
2758 #if 0 // What's the point of doing that?
2759 PWARNING
<< "Invalid geometry replaced by a group" << std::endl
;
2761 GroupPtr pGr
= Group::create();
2763 MFNodePtr pGeoParents
= pGeo
->getParents ();
2764 MFNodePtr::iterator parentsIt
= pGeoParents
.begin();
2765 MFNodePtr::iterator endParents
= pGeoParents
.end ();
2767 // this makes pGeo invalid!
2768 while(parentsIt
!= endParents
)
2770 (*parentsIt
)->setCore(pGr
);
2780 std::vector
<Int32
> dummyVec
;
2781 bool dummybool
= false;
2783 if(pCoordIndex
!= NULL
&&
2784 pCoordIndex
->size() > 1 &&
2785 pColorIndex
!= NULL
&&
2786 pColorPerVertex
!= NULL
)
2788 #ifdef OSG_DEBUG_VRML
2789 indentLog(getIndent(), PINFO
);
2790 PINFO
<< "Geo create lineset " << &(*pNode
) << std::endl
;
2793 setIndexFromIndexedX3DData(pGeo
,
2794 pCoordIndex
->getValues(),
2796 pColorIndex
->getValues(),
2802 pColorPerVertex
->getValue() ,
2803 false); // create normal; not yet :)
2807 #if 0 // What's the point of doing that?
2808 PWARNING
<< "Invalid geometry replaced by a group" << std::endl
;
2810 GroupPtr pGr
= Group::create();
2812 MFNodePtr pGeoParents
= pGeo
->getParents ();
2813 MFNodePtr::iterator parentsIt
= pGeoParents
.begin();
2814 MFNodePtr::iterator endParents
= pGeoParents
.end ();
2816 // this makes pGeo invalid!
2817 while(parentsIt
!= endParents
)
2819 (*parentsIt
)->setCore(pGr
);
2829 #ifdef OSG_DEBUG_VRML
2832 indentLog(getIndent(), PINFO
);
2833 PINFO
<< "End Geo " << &(*pNode
) << std::endl
;
2838 void VRMLPointSetGeometryHelper::setContainerFieldValue(
2839 FieldContainer
*pFC
,
2840 const FieldDescriptionBase
*pFieldDesc
,
2841 FieldContainer
*pFieldFC
)
2844 dynamic_cast<Geometry
*>(pFieldFC
);
2846 GeoVectorProperty
*pVecProp
=
2847 dynamic_cast<GeoVectorProperty
*>(pFC
);
2849 if(pGeo
!= NULL
&& pVecProp
!= NULL
)
2851 pGeo
->setProperty(pVecProp
, _uiPropertyIndex
);
2855 PWARNING
<< "GeoDesc::getFieldAndDesc : No Geo" << std::endl
;
2859 /*-------------------------------------------------------------------------*/
2862 void VRMLPointSetGeometryHelper::dump(const Char8
*)
2867 VRMLNodeHelperFactoryBase::RegisterHelper
2868 VRMLPointSetGeometryHelper::_regHelperPS(
2869 &VRMLPointSetGeometryHelper::create
,
2877 //---------------------------------------------------------------------------
2879 //---------------------------------------------------------------------------
2881 VRMLNodeHelper
*VRMLGeometryPartHelper::create(void)
2883 return new VRMLGeometryPartHelper();
2886 /*-------------------------------------------------------------------------*/
2889 VRMLGeometryPartHelper::VRMLGeometryPartHelper(void) :
2898 /*-------------------------------------------------------------------------*/
2901 VRMLGeometryPartHelper::~VRMLGeometryPartHelper(void)
2905 /*-------------------------------------------------------------------------*/
2908 void VRMLGeometryPartHelper::init(const Char8
*szName
)
2910 if(osgStringCaseCmp("Coordinate", szName
) == 0)
2912 _szVRMLPartname
= "point";
2913 _szOSGPartname
= "values";
2914 _szOSGProtoname
= "GeoPnt3fProperty";
2916 else if(osgStringCaseCmp("Normal", szName
) == 0)
2918 _szVRMLPartname
= "vector";
2919 _szOSGPartname
= "values";
2920 _szOSGProtoname
= "GeoVec3fProperty";
2922 else if(osgStringCaseCmp("Color", szName
) == 0)
2924 _szVRMLPartname
= "color";
2925 _szOSGPartname
= "values";
2926 _szOSGProtoname
= "GeoColor3fProperty";
2928 else if(osgStringCaseCmp("TextureCoordinate", szName
) == 0)
2930 _szVRMLPartname
= "point";
2931 _szOSGPartname
= "values";
2932 _szOSGProtoname
= "GeoVec2fProperty";
2935 #ifdef OSG_DEBUG_VRML
2936 indentLog(getIndent(), PINFO
);
2937 PINFO
<< "GeoPartDesc::init : "
2939 << _szVRMLPartname
<< " "
2940 << _szOSGPartname
<< " "
2941 << _szOSGProtoname
<< " "
2946 FieldContainerFactory::the()->createContainer(_szOSGProtoname
.c_str());
2948 if(_pNodeProto
== NULL
)
2950 PWARNING
<< "ERROR no prototype available for "
2955 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
2956 _pGenAttProto
->setInternal(true);
2959 /*-------------------------------------------------------------------------*/
2962 bool VRMLGeometryPartHelper::prototypeAddField(const Char8
*szFieldType
,
2963 const UInt32 uiFieldTypeId
,
2964 const Char8
*szFieldname
)
2966 bool bFound
= false;
2968 if(_szVRMLPartname
== szFieldname
)
2970 #ifdef OSG_DEBUG_VRML
2971 indentLog(getIndent(), PINFO
);
2972 PINFO
<< "GeoPartDesc::prototypeAddField : add part "
2987 return Inherited::prototypeAddField(szFieldType
,
2993 void VRMLGeometryPartHelper::getFieldAndDesc(
2994 FieldContainer
* pFC
,
2995 const Char8
* szFieldname
,
2996 FieldContainer
*&pFieldFC
,
2997 EditFieldHandlePtr
&pField
,
2998 const FieldDescriptionBase
*&pDesc
)
3000 #ifdef OSG_DEBUG_VRML
3001 indentLog(getIndent(), PINFO
);
3002 PINFO
<< "VRMLGeometryPartDesc::getFieldAndDesc : looking for "
3007 if(szFieldname
== NULL
)
3012 if(_bProtoInterfaceDone
== false)
3014 Inherited::getField(szFieldname
, pFieldFC
, pField
, pDesc
);
3022 if(_szVRMLPartname
== szFieldname
)
3024 #ifdef OSG_DEBUG_VRML
3025 indentLog(getIndent(), PINFO
);
3026 PINFO
<< "VRMLGeometryPartDesc::getFieldAndDesc : request internal "
3034 pDesc
= pFC
->getFieldDescription(_szOSGPartname
.c_str());
3035 pField
= pFC
->editField (_szOSGPartname
.c_str());
3039 PWARNING
<< "VRMLGeometryPartDesc::getFieldAndDesc : could not"
3049 Inherited::getFieldAndDesc(pFC
,
3056 #ifdef OSG_DEBUG_VRML
3061 /*-------------------------------------------------------------------------*/
3064 void VRMLGeometryPartHelper::mapFieldname(const std::string
&,
3065 std::string
&szFieldName
)
3067 szFieldName
.assign("values");
3071 /*-------------------------------------------------------------------------*/
3074 void VRMLGeometryPartHelper::dump(const Char8
*)
3079 VRMLNodeHelperFactoryBase::RegisterHelper
3080 VRMLGeometryPartHelper::_regHelperCoordinate(
3081 &VRMLGeometryPartHelper::create
,
3085 VRMLNodeHelperFactoryBase::RegisterHelper
3086 VRMLGeometryPartHelper::_regHelperNormal(
3087 &VRMLGeometryPartHelper::create
,
3091 VRMLNodeHelperFactoryBase::RegisterHelper
3092 VRMLGeometryPartHelper::_regHelperColor(
3093 &VRMLGeometryPartHelper::create
,
3097 VRMLNodeHelperFactoryBase::RegisterHelper
3098 VRMLGeometryPartHelper::_regHelperTexCoordinate(
3099 &VRMLGeometryPartHelper::create
,
3100 "TextureCoordinate",
3106 //---------------------------------------------------------------------------
3108 //---------------------------------------------------------------------------
3110 VRMLNodeHelper
*VRMLGeometryObjectHelper::create(void)
3112 return new VRMLGeometryObjectHelper();
3115 /*-------------------------------------------------------------------------*/
3118 VRMLGeometryObjectHelper::VRMLGeometryObjectHelper(void) :
3120 _eVRMLObjectType(UnknownGeo
)
3124 /*-------------------------------------------------------------------------*/
3127 VRMLGeometryObjectHelper::~VRMLGeometryObjectHelper(void)
3131 /*-------------------------------------------------------------------------*/
3134 void VRMLGeometryObjectHelper::init(const Char8
*szName
)
3136 #ifdef OSG_DEBUG_VRML
3137 indentLog(getIndent(), PINFO
);
3138 PINFO
<< "GeoObjDesc::init : "
3144 if(osgStringCaseCmp("Box", szName
) == 0)
3146 _eVRMLObjectType
= BoxGeo
;
3148 else if(osgStringCaseCmp("Sphere", szName
) == 0)
3150 _eVRMLObjectType
= SphereGeo
;
3152 else if(osgStringCaseCmp("Cone", szName
) == 0)
3154 _eVRMLObjectType
= ConeGeo
;
3156 else if(osgStringCaseCmp("Cylinder", szName
) == 0)
3158 _eVRMLObjectType
= CylinderGeo
;
3160 else if(osgStringCaseCmp("Teapot", szName
) == 0)
3162 _eVRMLObjectType
= TeapotGeo
;
3164 else if(osgStringCaseCmp("Plane", szName
) == 0)
3166 _eVRMLObjectType
= PlaneGeo
;
3169 _pNodeProto
= Node::create();
3171 if(_pNodeProto
== NULL
)
3173 PWARNING
<< "GeoObjDesc::init : no prototype available" << std::endl
;
3176 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
3177 _pGenAttProto
->setInternal(true);
3180 /*-------------------------------------------------------------------------*/
3183 /*-------------------------------------------------------------------------*/
3186 void VRMLGeometryObjectHelper::endNode(FieldContainer
*pFC
)
3188 EditFieldHandlePtr pField
;
3189 const FieldDescriptionBase
*pDesc
= NULL
;
3190 FieldContainer
*pDummyFC
= NULL
;
3196 pNode
= dynamic_cast<Node
*>(pFC
);
3201 if(_eVRMLObjectType
== BoxGeo
)
3203 Inherited::getFieldAndDesc(pFC
,
3209 EditFieldHandlePtr pFieldInv
;
3211 Inherited::getFieldAndDesc(pFC
,
3219 SFVec3f::EditHandlePtr pValField
=
3220 boost::dynamic_pointer_cast
<SFVec3f::EditHandle
>(pField
);
3222 SFBool::EditHandlePtr pValFieldInv
=
3223 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pFieldInv
);
3225 bool bInv
= pValFieldInv
!= NULL
?
3226 pValFieldInv
->getField()->getValue() : false;
3228 if(pValField
!= NULL
&& pValField
->isValid())
3230 SFVec3f
*pVec
= pValField
->getField();
3232 GeometryUnrecPtr pGeo
= makeBoxGeo(pVec
->getValue()[0],
3233 pVec
->getValue()[1],
3234 pVec
->getValue()[2],
3240 pNode
->setCore(pGeo
);
3244 else if(_eVRMLObjectType
== ConeGeo
)
3246 SFReal32
*pBotRad
= NULL
;
3247 SFReal32
*pHeight
= NULL
;
3248 SFBool
*pSide
= NULL
;
3249 SFBool
*pBottom
= NULL
;
3251 Inherited::getFieldAndDesc(pFC
,
3259 SFReal32::EditHandlePtr pValField
=
3260 boost::dynamic_pointer_cast
<SFReal32::EditHandle
>(pField
);
3262 if(pValField
!= NULL
&& pValField
->isValid())
3264 pBotRad
= pValField
->getField();
3268 Inherited::getFieldAndDesc(pFC
,
3276 SFReal32::EditHandlePtr pValField
=
3277 boost::dynamic_pointer_cast
<SFReal32::EditHandle
>(pField
);
3279 if(pValField
!= NULL
&& pValField
->isValid())
3281 pHeight
= pValField
->getField();
3285 Inherited::getFieldAndDesc(pFC
,
3293 SFBool::EditHandlePtr pValField
=
3294 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
3296 if(pValField
!= NULL
&& pValField
->isValid())
3298 pSide
= pValField
->getField();
3302 Inherited::getFieldAndDesc(pFC
,
3310 SFBool::EditHandlePtr pValField
=
3311 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
3313 if(pValField
!= NULL
&& pValField
->isValid())
3315 pBottom
= pValField
->getField();
3319 if(pBotRad
!= NULL
&&
3324 #ifdef OSG_DEBUG_VRML
3325 indentLog(getIndent(), PINFO
);
3326 PINFO
<< "VRMLGeometryObjectDesc::endNode : Create cone"
3330 GeometryUnrecPtr pGeo
= makeConeGeo(pHeight
->getValue(),
3331 pBotRad
->getValue(),
3334 pBottom
->getValue());
3336 pNode
->setCore(pGeo
);
3339 else if(_eVRMLObjectType
== CylinderGeo
)
3341 SFBool
*pBottom
= NULL
;
3342 SFReal32
*pHeight
= NULL
;
3343 SFReal32
*pRadius
= NULL
;
3344 SFBool
*pSide
= NULL
;
3345 SFBool
*pTop
= NULL
;
3347 Inherited::getFieldAndDesc(pFC
,
3355 SFBool::EditHandlePtr pValField
=
3356 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
3358 if(pValField
!= NULL
&& pValField
->isValid())
3360 pBottom
= pValField
->getField();
3364 Inherited::getFieldAndDesc(pFC
,
3372 SFReal32::EditHandlePtr pValField
=
3373 boost::dynamic_pointer_cast
<SFReal32::EditHandle
>(pField
);
3375 if(pValField
!= NULL
&& pValField
->isValid())
3377 pHeight
= pValField
->getField();
3381 Inherited::getFieldAndDesc(pFC
,
3389 SFReal32::EditHandlePtr pValField
=
3390 boost::dynamic_pointer_cast
<SFReal32::EditHandle
>(pField
);
3392 if(pValField
!= NULL
&& pValField
->isValid())
3394 pRadius
= pValField
->getField();
3398 Inherited::getFieldAndDesc(pFC
,
3406 SFBool::EditHandlePtr pValField
=
3407 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
3409 if(pValField
!= NULL
&& pValField
->isValid())
3411 pSide
= pValField
->getField();
3415 Inherited::getFieldAndDesc(pFC
,
3423 SFBool::EditHandlePtr pValField
=
3424 boost::dynamic_pointer_cast
<SFBool::EditHandle
>(pField
);
3426 if(pValField
!= NULL
&& pValField
->isValid())
3428 pTop
= pValField
->getField();
3433 if(pBottom
!= NULL
&&
3439 #ifdef OSG_DEBUG_VRML
3440 indentLog(getIndent(), PINFO
);
3441 PINFO
<< "VRMLGeometryObjectDesc::endNode : Create cylinder"
3445 GeometryUnrecPtr pGeo
= makeCylinderGeo(pHeight
->getValue(),
3446 pRadius
->getValue(),
3450 pBottom
->getValue());
3452 pNode
->setCore(pGeo
);
3455 else if(_eVRMLObjectType
== SphereGeo
)
3457 SFReal32
*pSize
= NULL
;
3458 SFInt32
*pResolution
= NULL
;
3460 Inherited::getFieldAndDesc(pFC
,
3468 SFReal32::EditHandlePtr pValField
=
3469 boost::dynamic_pointer_cast
<SFReal32::EditHandle
>(pField
);
3471 if(pValField
!= NULL
&& pValField
->isValid())
3473 pSize
= pValField
->getField();
3477 Inherited::getFieldAndDesc(pFC
,
3485 SFInt32::EditHandlePtr pValField
=
3486 boost::dynamic_pointer_cast
<SFInt32::EditHandle
>(pField
);
3488 if(pValField
!= NULL
&& pValField
->isValid())
3490 pResolution
= pValField
->getField();
3494 if(pSize
!= NULL
&& pResolution
!= NULL
)
3496 GeometryUnrecPtr pGeo
=
3497 makeLatLongSphereGeo(pResolution
->getValue(),
3498 pResolution
->getValue() * 2,
3499 pSize
->getValue());
3501 pNode
->setCore(pGeo
);
3504 else if(_eVRMLObjectType
== TeapotGeo
)
3506 SFReal32
*pScale
= NULL
;
3507 SFInt32
*pDepth
= NULL
;
3509 Inherited::getFieldAndDesc(pFC
,
3517 SFReal32::EditHandlePtr pValField
=
3518 boost::dynamic_pointer_cast
<SFReal32::EditHandle
>(pField
);
3520 if(pValField
!= NULL
&& pValField
->isValid())
3522 pScale
= pValField
->getField();
3526 Inherited::getFieldAndDesc(pFC
,
3534 SFInt32::EditHandlePtr pValField
=
3535 boost::dynamic_pointer_cast
<SFInt32::EditHandle
>(pField
);
3537 if(pValField
!= NULL
&& pValField
->isValid())
3539 pDepth
= pValField
->getField();
3543 GeometryUnrecPtr pGeo
= makeTeapotGeo(
3544 (pDepth
!= NULL
) ? pDepth
->getValue() : 5,
3545 (pScale
!= NULL
) ? pScale
->getValue() : 1.f
);
3547 pNode
->setCore(pGeo
);
3550 else if(_eVRMLObjectType
== PlaneGeo
)
3552 SFVec2s
*pResolution
= NULL
;
3553 SFVec2f
*pSize
= NULL
;
3555 Inherited::getFieldAndDesc(pFC
,
3563 SFVec2s::EditHandlePtr pValField
=
3564 boost::dynamic_pointer_cast
<SFVec2s::EditHandle
>(pField
);
3566 if(pValField
!= NULL
&& pValField
->isValid())
3568 pResolution
= pValField
->getField();
3572 Inherited::getFieldAndDesc(pFC
,
3580 SFVec2f::EditHandlePtr pValField
=
3581 boost::dynamic_pointer_cast
<SFVec2f::EditHandle
>(pField
);
3583 if(pValField
!= NULL
&& pValField
->isValid())
3585 pSize
= pValField
->getField();
3589 GeometryUnrecPtr pGeo
= makePlaneGeo(
3590 (pSize
!= NULL
) ? pSize
->getValue()[0] : 1.f
,
3591 (pSize
!= NULL
) ? pSize
->getValue()[1] : 1.f
,
3592 (pResolution
!= NULL
) ? pResolution
->getValue()[0] : 5,
3593 (pResolution
!= NULL
) ? pResolution
->getValue()[1] : 5);
3595 pNode
->setCore(pGeo
);
3600 /*-------------------------------------------------------------------------*/
3603 void VRMLGeometryObjectHelper::dump(const Char8
*)
3607 VRMLNodeHelperFactoryBase::RegisterHelper
3608 VRMLGeometryObjectHelper::_regHelperBox(
3609 &VRMLGeometryObjectHelper::create
,
3613 VRMLNodeHelperFactoryBase::RegisterHelper
3614 VRMLGeometryObjectHelper::_regHelperSphere(
3615 &VRMLGeometryObjectHelper::create
,
3619 VRMLNodeHelperFactoryBase::RegisterHelper
3620 VRMLGeometryObjectHelper::_regHelperCone(
3621 &VRMLGeometryObjectHelper::create
,
3625 VRMLNodeHelperFactoryBase::RegisterHelper
3626 VRMLGeometryObjectHelper::_regHelperCylinder(
3627 &VRMLGeometryObjectHelper::create
,
3631 VRMLNodeHelperFactoryBase::RegisterHelper
3632 VRMLGeometryObjectHelper::_regHelperTeapot(
3633 &VRMLGeometryObjectHelper::create
,
3637 VRMLNodeHelperFactoryBase::RegisterHelper
3638 VRMLGeometryObjectHelper::_regHelperPlane(
3639 &VRMLGeometryObjectHelper::create
,
3645 //---------------------------------------------------------------------------
3647 //---------------------------------------------------------------------------
3649 /*-------------------------------------------------------------------------*/
3652 VRMLTextureHelper::VRMLTextureHelper(void) :
3663 /*-------------------------------------------------------------------------*/
3666 VRMLTextureHelper::~VRMLTextureHelper(void)
3670 /*-------------------------------------------------------------------------*/
3673 /*-------------------------------------------------------------------------*/
3676 bool VRMLTextureHelper::prototypeAddField(const Char8
*,
3678 const Char8
*szFieldname
)
3680 bool bFound
= false;
3682 if(osgStringCaseCmp("repeatS", szFieldname
) == 0)
3686 else if(osgStringCaseCmp("repeatT", szFieldname
) == 0)
3693 #ifdef OSG_DEBUG_VRML
3694 indentLog(getIndent(), PINFO
);
3695 PINFO
<< "ImageTextureDesc::prototypeAddField : add part "
3709 void VRMLTextureHelper::getFieldAndDesc(
3711 const Char8
* szFieldname
,
3712 FieldContainer
*&pFieldFC
,
3713 EditFieldHandlePtr
&pField
,
3714 const FieldDescriptionBase
*&pDesc
)
3720 if(osgStringCaseCmp("repeatS", szFieldname
) == 0)
3722 if(_bProtoInterfaceDone
== false)
3724 pField
= _sfBoolDesc
.createEditHandler(&_defaultRepeatS
,
3729 pField
= _sfBoolDesc
.createEditHandler(&_repeatS
,
3733 pDesc
= &_sfBoolDesc
;
3735 else if(osgStringCaseCmp("repeatT", szFieldname
) == 0)
3737 if(_bProtoInterfaceDone
== false)
3739 pField
= _sfBoolDesc
.createEditHandler(&_defaultRepeatT
,
3744 pField
= _sfBoolDesc
.createEditHandler(&_repeatT
,
3748 pDesc
= &_sfBoolDesc
;
3752 /*-------------------------------------------------------------------------*/
3755 FieldContainerTransitPtr
VRMLTextureHelper::beginNode(
3760 TextureObjChunkTransitPtr returnValue
= TextureObjChunk::create();
3762 #ifdef OSG_DEBUG_VRML
3763 indentLog(getIndent(), PINFO
);
3764 PINFO
<< "Begin Texture "
3765 << ((returnValue
== NULL
) ? "invalid obj" : "valid obj")
3771 _repeatS
= _defaultRepeatS
;
3772 _repeatT
= _defaultRepeatT
;
3774 return FieldContainerTransitPtr(returnValue
);
3777 void VRMLTextureHelper::endNode(FieldContainer
*pFC
)
3780 TextureObjChunk
*pTexture
= NULL
;
3782 ImageUnrecPtr pImage
= NULL
;
3784 pTexture
= dynamic_cast<TextureObjChunk
*>(pFC
);
3787 if(pTexture
!= NULL
)
3789 for(UInt32 i
= 0; i
< _url
.size(); ++i
)
3791 #ifdef OSG_DEBUG_VRML
3792 PNOTICE
<< "VRMLImageTextureDesc::endNode : Reading texture "
3793 << _url
[i
].c_str() << std::endl
;
3796 #ifdef OSG_VRML_IMAGETEXTURE_MAP
3797 UrlImageMap::iterator mIt
= _urlImageMap
.find(_url
[i
]);
3799 if(mIt
!= _urlImageMap
.end())
3801 pImage
= mIt
->second
;
3805 pImage
= ImageFileHandler::the()->read(_url
[i
].c_str());
3809 _urlImageMap
[_url
[i
]] = pImage
;
3813 pImage
= ImageFileHandler::the()->read(_url
[0].c_str());
3822 pImage
->setForceAlphaBinary(pImage
->calcIsAlphaBinary());
3824 pTexture
->setImage(pImage
);
3826 if(_repeatS
.getValue() == true)
3828 pTexture
->setWrapS(GL_REPEAT
);
3832 pTexture
->setWrapS(GL_CLAMP_TO_EDGE
);
3834 if(_repeatT
.getValue() == true)
3836 pTexture
->setWrapT(GL_REPEAT
);
3840 pTexture
->setWrapT(GL_CLAMP_TO_EDGE
);
3845 PWARNING
<< "VRMLImageTextureDesc::endNode : "
3846 << "Couldn't read texture "
3854 PWARNING
<< "VRMLImageTextureDesc::endNode : Invalid texture ptr"
3858 #ifdef OSG_DEBUG_VRML
3861 indentLog(getIndent(), PINFO
);
3862 PINFO
<< "End ImageTexture "
3863 << _url
[0].c_str() << " "
3864 << _repeatS
.getValue() << " "
3865 << _repeatT
.getValue() << " "
3866 << &(*pFC
) << std::endl
;
3871 /*-------------------------------------------------------------------------*/
3874 void VRMLTextureHelper::dump(const Char8
*)
3881 //---------------------------------------------------------------------------
3883 //---------------------------------------------------------------------------
3885 VRMLNodeHelper
*VRMLImageTextureHelper::create(void)
3887 return new VRMLImageTextureHelper();
3890 /*-------------------------------------------------------------------------*/
3893 VRMLImageTextureHelper::VRMLImageTextureHelper(void) :
3899 #ifdef OSG_VRML_IMAGETEXTURE_MAP
3905 /*-------------------------------------------------------------------------*/
3908 VRMLImageTextureHelper::~VRMLImageTextureHelper(void)
3912 /*-------------------------------------------------------------------------*/
3915 /*-------------------------------------------------------------------------*/
3918 bool VRMLImageTextureHelper::prototypeAddField(const Char8
*szFieldType
,
3919 const UInt32 uiFieldTypeId
,
3920 const Char8
*szFieldname
)
3922 bool bFound
= false;
3924 if(osgStringCaseCmp("url", szFieldname
) == 0)
3930 bFound
= Inherited::prototypeAddField(szFieldType
,
3937 #ifdef OSG_DEBUG_VRML
3938 indentLog(getIndent(), PINFO
);
3939 PINFO
<< "ImageTextureDesc::prototypeAddField : add part "
3953 void VRMLImageTextureHelper::getFieldAndDesc(
3954 FieldContainer
* pFC
,
3955 const Char8
* szFieldname
,
3956 FieldContainer
*&pFieldFC
,
3957 EditFieldHandlePtr
&pField
,
3958 const FieldDescriptionBase
*&pDesc
)
3964 if(osgStringCaseCmp("url", szFieldname
) == 0)
3966 if(_bProtoInterfaceDone
== false)
3968 pField
= _mfStringDesc
.createEditHandler(&_defaultURL
,
3973 pField
= _mfStringDesc
.createEditHandler(&_url
,
3977 pDesc
= &_mfStringDesc
;
3981 Inherited::getFieldAndDesc(pFC
,
3989 /*-------------------------------------------------------------------------*/
3992 FieldContainerTransitPtr
VRMLImageTextureHelper::beginNode(
3993 const Char8
*szTypename
,
3994 const Char8
*szName
,
3995 FieldContainer
*pCurrentFC
)
3997 FieldContainerTransitPtr returnValue
=
3998 Inherited::beginNode(szTypename
, szName
, pCurrentFC
);
4000 #ifdef OSG_DEBUG_VRML
4001 indentLog(getIndent(), PINFO
);
4002 PINFO
<< "Begin ImageTexture "
4003 << ((returnValue
== NULL
) ? "invalid obj" : "valid obj")
4014 void VRMLImageTextureHelper::endNode(FieldContainer
*pFC
)
4016 TextureObjChunk
*pTexture
= NULL
;
4018 ImageUnrecPtr pImage
= NULL
;
4020 pTexture
= dynamic_cast<TextureObjChunk
*>(pFC
);
4023 if(pTexture
!= NULL
&& _url
.size() != 0)
4026 for(UInt32 i
= 0; i
< _url
.size(); ++i
)
4028 #ifdef OSG_DEBUG_VRML
4029 PNOTICE
<< "VRMLImageTextureDesc::endNode : Reading texture "
4030 << _url
[i
].c_str() << std::endl
;
4033 #ifdef OSG_VRML_IMAGETEXTURE_MAP
4034 UrlImageMap::iterator mIt
= _urlImageMap
.find(_url
[i
]);
4036 if(mIt
!= _urlImageMap
.end())
4038 pImage
= mIt
->second
;
4042 pImage
= ImageFileHandler::the()->read(_url
[i
].c_str());
4046 _urlImageMap
[_url
[i
]] = pImage
;
4050 pImage
= ImageFileHandler::the()->read(_url
[0].c_str());
4059 pImage
->setForceAlphaBinary(pImage
->calcIsAlphaBinary());
4061 pTexture
->setImage(pImage
);
4063 if(_repeatS
.getValue() == true)
4065 pTexture
->setWrapS(GL_REPEAT
);
4069 pTexture
->setWrapS(GL_CLAMP_TO_EDGE
);
4071 if(_repeatT
.getValue() == true)
4073 pTexture
->setWrapT(GL_REPEAT
);
4077 pTexture
->setWrapT(GL_CLAMP_TO_EDGE
);
4082 PWARNING
<< "VRMLImageTextureDesc::endNode : "
4083 << "Couldn't read texture "
4091 PWARNING
<< "VRMLImageTextureDesc::endNode : Invalid texture ptr"
4095 #ifdef OSG_DEBUG_VRML
4098 indentLog(getIndent(), PINFO
);
4099 PINFO
<< "End ImageTexture "
4100 << _url
[0].c_str() << " "
4101 << _repeatS
.getValue() << " "
4102 << _repeatT
.getValue() << " "
4103 << &(*pFC
) << std::endl
;
4107 /*-------------------------------------------------------------------------*/
4110 void VRMLImageTextureHelper::dump(const Char8
*)
4115 VRMLNodeHelperFactoryBase::RegisterHelper
VRMLImageTextureHelper::_regHelper(
4116 &VRMLImageTextureHelper::create
,
4123 //---------------------------------------------------------------------------
4125 //---------------------------------------------------------------------------
4127 VRMLNodeHelper
*VRMLPixelTextureHelper::create(void)
4129 return new VRMLPixelTextureHelper();
4132 /*-------------------------------------------------------------------------*/
4135 VRMLPixelTextureHelper::VRMLPixelTextureHelper(void) :
4141 /*-------------------------------------------------------------------------*/
4144 VRMLPixelTextureHelper::~VRMLPixelTextureHelper(void)
4148 /*-------------------------------------------------------------------------*/
4151 void VRMLPixelTextureHelper::addImageValue(
4152 EditFieldHandlePtr
,
4153 const FieldDescriptionBase
*,
4159 /*-------------------------------------------------------------------------*/
4162 bool VRMLPixelTextureHelper::prototypeAddField(const Char8
*szFieldType
,
4163 const UInt32 uiFieldTypeId
,
4164 const Char8
*szFieldname
)
4166 bool bFound
= false;
4168 if(osgStringCaseCmp("image", szFieldname
) == 0)
4174 bFound
= Inherited::prototypeAddField(szFieldType
,
4181 #ifdef OSG_DEBUG_VRML
4182 indentLog(getIndent(), PINFO
);
4183 PINFO
<< "ImageTextureDesc::prototypeAddField : add part "
4197 void VRMLPixelTextureHelper::getFieldAndDesc(
4198 FieldContainer
* pFC
,
4199 const Char8
* szFieldname
,
4200 FieldContainer
*&pFieldFC
,
4201 EditFieldHandlePtr
&pField
,
4202 const FieldDescriptionBase
*&pDesc
)
4208 if(osgStringCaseCmp("image", szFieldname
) == 0)
4212 pDesc
= &_sfImagePtrDesc
;
4216 Inherited::getFieldAndDesc(pFC
,
4224 /*-------------------------------------------------------------------------*/
4227 FieldContainerTransitPtr
VRMLPixelTextureHelper::beginNode(
4228 const Char8
*szTypename
,
4229 const Char8
*szName
,
4230 FieldContainer
*pCurrentFC
)
4232 FieldContainerTransitPtr returnValue
=
4233 Inherited::beginNode(szTypename
, szName
, pCurrentFC
);
4235 #ifdef OSG_DEBUG_VRML
4236 indentLog(getIndent(), PINFO
);
4237 PINFO
<< "Begin PixelTexture "
4238 << ((returnValue
== NULL
) ? "invalid obj" : "valid obj")
4247 void VRMLPixelTextureHelper::endNode(FieldContainer
*pFC
)
4249 TextureObjChunk
*pTexture
= NULL
;
4251 pTexture
= dynamic_cast<TextureObjChunk
*>(pFC
);
4254 if(pTexture
!= NULL
)
4258 _pImage
->setForceAlphaBinary(_pImage
->calcIsAlphaBinary());
4260 pTexture
->setImage(_pImage
);
4262 if(_repeatS
.getValue() == true)
4264 pTexture
->setWrapS(GL_REPEAT
);
4268 pTexture
->setWrapS(GL_CLAMP_TO_EDGE
);
4270 if(_repeatT
.getValue() == true)
4272 pTexture
->setWrapT(GL_REPEAT
);
4276 pTexture
->setWrapT(GL_CLAMP_TO_EDGE
);
4282 PWARNING
<< "VRMLPixelTextureDesc::endNode : Invalid texture ptr"
4288 #ifdef OSG_DEBUG_VRML
4291 indentLog(getIndent(), PINFO
);
4292 PINFO
<< "End PixelTexture "
4293 << _repeatS
.getValue() << " "
4294 << _repeatT
.getValue() << " "
4295 << &(*pFC
) << std::endl
;
4299 /*-------------------------------------------------------------------------*/
4302 void VRMLPixelTextureHelper::dump(const Char8
*)
4307 VRMLNodeHelperFactoryBase::RegisterHelper
VRMLPixelTextureHelper::_regHelper(
4308 &VRMLPixelTextureHelper::create
,
4316 //---------------------------------------------------------------------------
4318 //---------------------------------------------------------------------------
4320 VRMLNodeHelper
*VRMLInlineHelper::create(void)
4322 return new VRMLInlineHelper();
4325 /*-------------------------------------------------------------------------*/
4328 VRMLInlineHelper::VRMLInlineHelper(void) :
4333 /*-------------------------------------------------------------------------*/
4336 VRMLInlineHelper::~VRMLInlineHelper(void)
4340 /*-------------------------------------------------------------------------*/
4343 void VRMLInlineHelper::init(const Char8
*szName
)
4345 Inherited::init(szName
);
4347 #ifdef OSG_DEBUG_VRML
4348 indentLog(getIndent(), PINFO
);
4349 PINFO
<< "InlineHelper::init : " << szName
<< std::endl
;
4352 _pNodeProto
= Node ::create();
4353 _pNodeCoreProto
= Inline::create();
4355 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
4356 _pGenAttProto
->setInternal(true);
4359 /*-------------------------------------------------------------------------*/
4362 void VRMLInlineHelper::endNode(FieldContainer
*pFC
)
4364 Node
*pNode
= dynamic_cast<Node
*>(pFC
);
4368 Inline
*pInline
= dynamic_cast<Inline
*>(pNode
->getCore());
4372 pInline
->postOSGLoading(NULL
);
4377 /*-------------------------------------------------------------------------*/
4380 void VRMLInlineHelper::dump(const Char8
*)
4385 VRMLNodeHelperFactoryBase::RegisterHelper
VRMLInlineHelper::_regHelper(
4386 &VRMLInlineHelper::create
,
4393 //---------------------------------------------------------------------------
4395 //---------------------------------------------------------------------------
4397 VRMLNodeHelper
*VRMLSwitchHelper::create(void)
4399 return new VRMLSwitchHelper();
4403 /*-------------------------------------------------------------------------*/
4406 VRMLSwitchHelper::VRMLSwitchHelper(void) :
4411 /*-------------------------------------------------------------------------*/
4414 VRMLSwitchHelper::~VRMLSwitchHelper(void)
4418 /*-------------------------------------------------------------------------*/
4421 void VRMLSwitchHelper::init(const Char8
*szName
)
4423 Inherited::init(szName
);
4425 #ifdef OSG_DEBUG_VRML
4426 indentLog(getIndent(), PINFO
);
4427 PINFO
<< "SwitchHelper::init : " << szName
<< std::endl
;
4430 _pNodeProto
= Node ::create();
4431 _pNodeCoreProto
= Switch::create();
4433 _pGenAttProto
= VRMLGenericAtt::createLocal(FCLocal::Cluster
);
4434 _pGenAttProto
->setInternal(true);
4437 /*-------------------------------------------------------------------------*/
4440 bool VRMLSwitchHelper::prototypeAddField(const Char8
*szFieldType
,
4441 const UInt32 uiFieldTypeId
,
4442 const Char8
*szFieldname
)
4444 bool returnValue
= false;
4446 #ifdef OSG_DEBUG_VRML
4447 indentLog(getIndent(), PINFO
);
4448 PINFO
<< "VRMLSwitchHelper::prototypeAddField | add request : "
4453 if(szFieldname
== NULL
)
4458 if(osgStringCaseCmp("choice", szFieldname
) == 0)
4462 #ifdef OSG_DEBUG_VRML
4463 indentLog(getIndent(), PINFO
);
4464 PINFO
<< "VRMLSwitchHelper::prototypeAddField | request internal : "
4471 if(osgStringCaseCmp("whichChoice", szFieldname
) == 0)
4475 #ifdef OSG_DEBUG_VRML
4476 indentLog(getIndent(), PINFO
);
4478 PINFO
<< "VRMLSwitchHelper::prototypeAddField | request internal : "
4485 if(returnValue
== false)
4487 returnValue
= Inherited::prototypeAddField(szFieldType
,
4492 #ifdef OSG_DEBUG_VRML
4499 void VRMLSwitchHelper::getFieldAndDesc(
4500 FieldContainer
* pFC
,
4501 const Char8
* szFieldname
,
4502 FieldContainer
*&pFieldFC
,
4503 EditFieldHandlePtr
&pField
,
4504 const FieldDescriptionBase
*&pDesc
)
4506 if(szFieldname
== NULL
)
4511 if(_bProtoInterfaceDone
== false)
4513 Inherited::getField(szFieldname
, pFieldFC
, pField
, pDesc
);
4519 #ifdef OSG_DEBUG_VRML
4520 indentLog(getIndent(), PINFO
);
4521 PINFO
<< "VRMLSwitchHelper::getFieldAndDesc : looking for "
4528 if(osgStringCaseCmp("choice", szFieldname
) == 0)
4530 #ifdef OSG_DEBUG_VRML
4531 indentLog(getIndent(), PINFO
);
4532 PINFO
<< "VRMLSwitchHelper::getFieldAndDesc : request internal "
4537 pField
= pFC
->editField("children");
4538 pDesc
= pFC
->getFieldDescription("children");
4540 else if(osgStringCaseCmp("whichChoice", szFieldname
) == 0)
4542 #ifdef OSG_DEBUG_VRML
4543 indentLog(getIndent(), PINFO
);
4544 PINFO
<< "VRMLSwitchHelper::getFieldAndDesc : request internal "
4549 Node
*pNode
= dynamic_cast<Node
*>(pFC
);
4553 if(pNode
->getCore() != NULL
)
4555 pFieldFC
= pNode
->getCore();
4556 pField
= pNode
->getCore()->editField("choice");
4557 pDesc
= pNode
->getCore()->getFieldDescription("choice");
4562 Inherited::getFieldAndDesc(pFC
,
4571 Inherited::getFieldAndDesc(pFC
,
4578 #ifdef OSG_DEBUG_VRML
4583 /*-------------------------------------------------------------------------*/
4587 /*-------------------------------------------------------------------------*/
4590 void VRMLSwitchHelper::dump(const Char8
*)
4594 VRMLNodeHelperFactoryBase::RegisterHelper
VRMLSwitchHelper::_regHelper(
4595 &VRMLSwitchHelper::create
,
4600 //---------------------------------------------------------------------------
4601 // Generic Helper with 1:1 mapping
4602 //---------------------------------------------------------------------------
4604 OSG_INST_GENERICVRMLHELPER(TimeSensor
);
4607 bool VRMLGenericHelper
<TimeSensor
>::initStatic(void)
4613 VRMLNodeHelperFactoryBase::RegisterHelper
4614 VRMLGenericHelper
<TimeSensor
>::_regHelper(
4615 &VRMLGenericHelper
<TimeSensor
>::create
,
4617 &VRMLGenericHelper
<TimeSensor
>::initStatic
);
4619 OSG_INST_GENERICVRMLHELPER(VRMLOrientationInterpolator
);
4622 bool VRMLGenericHelper
<VRMLOrientationInterpolator
>::initStatic(void)
4624 _mFieldNameMap
[std::string("fraction")] = std::string("inValue" );
4625 _mFieldNameMap
[std::string("value" )] = std::string("outValue");
4631 VRMLNodeHelperFactoryBase::RegisterHelper
4632 VRMLGenericHelper
<VRMLOrientationInterpolator
>::_regHelper(
4633 &VRMLGenericHelper
<VRMLOrientationInterpolator
>::create
,
4634 "OrientationInterpolator",
4635 &VRMLGenericHelper
<VRMLOrientationInterpolator
>::initStatic
);
4638 OSG_INST_GENERICVRMLHELPER(VRMLPositionInterpolator
);
4641 bool VRMLGenericHelper
<VRMLPositionInterpolator
>::initStatic(void)
4643 _mFieldNameMap
[std::string("fraction")] = std::string("inValue" );
4644 _mFieldNameMap
[std::string("value" )] = std::string("outValue");
4650 VRMLNodeHelperFactoryBase::RegisterHelper
4651 VRMLGenericHelper
<VRMLPositionInterpolator
>::_regHelper(
4652 &VRMLGenericHelper
<VRMLPositionInterpolator
>::create
,
4653 "PositionInterpolator",
4654 &VRMLGenericHelper
<VRMLPositionInterpolator
>::initStatic
);
4656 OSG_INST_GENERICVRMLHELPER(VRMLCoordinateInterpolator
);
4659 bool VRMLGenericHelper
<VRMLCoordinateInterpolator
>::initStatic(void)
4661 _mFieldNameMap
[std::string("fraction")] = std::string("inValue" );
4662 _mFieldNameMap
[std::string("value" )] = std::string("outValue");
4668 VRMLNodeHelperFactoryBase::RegisterHelper
4669 VRMLGenericHelper
<VRMLCoordinateInterpolator
>::_regHelper(
4670 &VRMLGenericHelper
<VRMLCoordinateInterpolator
>::create
,
4671 "CoordinateInterpolator",
4672 &VRMLGenericHelper
<VRMLCoordinateInterpolator
>::initStatic
);
4674 OSG_INST_GENERICVRMLHELPER(VRMLNormalInterpolator
);
4677 bool VRMLGenericHelper
<VRMLNormalInterpolator
>::initStatic(void)
4679 _mFieldNameMap
[std::string("fraction")] = std::string("inValue" );
4680 _mFieldNameMap
[std::string("value" )] = std::string("outValue");
4686 VRMLNodeHelperFactoryBase::RegisterHelper
4687 VRMLGenericHelper
<VRMLNormalInterpolator
>::_regHelper(
4688 &VRMLGenericHelper
<VRMLNormalInterpolator
>::create
,
4689 "NormalInterpolator",
4690 &VRMLGenericHelper
<VRMLNormalInterpolator
>::initStatic
);
4692 OSG_INST_GENERICVRMLHELPER(VRMLScalarInterpolator
);
4695 bool VRMLGenericHelper
<VRMLScalarInterpolator
>::initStatic(void)
4697 _mFieldNameMap
[std::string("fraction")] = std::string("inValue" );
4698 _mFieldNameMap
[std::string("value" )] = std::string("outValue");
4704 VRMLNodeHelperFactoryBase::RegisterHelper
4705 VRMLGenericHelper
<VRMLScalarInterpolator
>::_regHelper(
4706 &VRMLGenericHelper
<VRMLScalarInterpolator
>::create
,
4707 "ScalarInterpolator",
4708 &VRMLGenericHelper
<VRMLScalarInterpolator
>::initStatic
);