fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / WRL / OSGVRMLNodeHelper.cpp
blob74fadb198842873c7ab4f26d508c960fb432013b
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
44 #include <iostream>
45 #include <fstream>
47 #include "OSGVRMLNodeHelper.h"
48 #include "OSGSingletonHolder.ins"
50 #include "OSGFieldDescFactory.h"
52 #include "OSGScanParseSkel.h"
53 #include "OSGSceneFileHandler.h"
54 #include "OSGNameAttachment.h"
55 #include "OSGNode.h"
56 #include "OSGGroup.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"
82 #endif
84 //#define OSG_DEBUG_VRML
86 #ifndef OSG_DO_DOC
87 # ifdef OSG_DEBUG_VRML
88 # define OSG_VRML_ARG(ARG) ARG
89 # else
90 # define OSG_VRML_ARG(ARG)
91 # endif
92 #else
93 # define OSG_VRML_ARG(ARG) ARG
94 #endif
96 OSG_BEGIN_NAMESPACE
98 OSG_DYNFIELDATTACHMENT_INST(VRMLGenericAttDesc)
100 OSG_SINGLETON_INST(VRMLNodeHelperFactoryBase, addPostFactoryExitFunction)
102 template class SingletonHolder<VRMLNodeHelperFactoryBase>;
104 //---------------------------------------------------------------------------
105 // Class
106 //---------------------------------------------------------------------------
108 VRMLNodeHelperFactoryBase::RegisterHelper::RegisterHelper(
109 CreateHelper fCreate,
110 const Char8 *szNodeName,
111 InitFuncF fStaticInit)
113 VRMLNodeHelperFactory::the()->registerNodeHelper(fCreate,
114 szNodeName);
116 if(fStaticInit)
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)
135 return;
137 NameHelperCreateMap::iterator mNodeHelperIt =
138 _mRegisteredNodeHelperHash.find(szNodeName);
141 if(mNodeHelperIt == _mRegisteredNodeHelperHash.end())
143 _mRegisteredNodeHelperHash[szNodeName] = fHelper;
145 PINFO << "Helper registered for "
146 << szNodeName
147 << std::endl;
149 else
151 PWARNING << "Helper already registered for %s "
152 << szNodeName
153 << std::endl;
157 VRMLNodeHelper *VRMLNodeHelperFactoryBase::createHelper(
158 const Char8 *szNodeName)
160 if(szNodeName == NULL)
161 return NULL;
163 NameHelperCreateMap::iterator mNodeHelperIt =
164 _mRegisteredNodeHelperHash.find(szNodeName);
167 if(mNodeHelperIt != _mRegisteredNodeHelperHash.end())
169 return (*mNodeHelperIt).second();
171 else
173 return NULL;
178 //---------------------------------------------------------------------------
179 // Class
180 //---------------------------------------------------------------------------
182 UInt32 VRMLNodeHelper::_uiIndent = 0;
184 /*-------------------------------------------------------------------------*/
185 /* Static Get */
187 UInt32 VRMLNodeHelper::getIndent(void)
189 return _uiIndent;
192 void VRMLNodeHelper::incIndent(void)
194 _uiIndent += 4;
197 void VRMLNodeHelper::decIndent(void)
199 if(_uiIndent < 4)
201 // PWARNING << "Indent smaller 4 decremented" << std::endl;
203 _uiIndent = 4;
206 _uiIndent -= 4;
209 void VRMLNodeHelper::resetIndent(void)
211 _uiIndent = 0;
214 /*-------------------------------------------------------------------------*/
215 /* Constructors */
217 #define OSG_INIT_DESC(VAR, TYPE, NAME) \
218 VAR(TYPE::getClassType(), \
219 NAME, \
220 "VRML Helper", \
221 0, \
222 0, \
223 true, \
224 Field::SFDefaultFlags, \
225 static_cast<FieldEditMethodSig>(&Node::invalidEditField), \
226 NULL)
228 VRMLNodeHelper::VRMLNodeHelper(void) :
229 _bProtoInterfaceDone(false ),
230 _pGenAttProto (NULL ),
231 _pNodeProto (NULL ),
232 _pNodeCoreProto (NULL ),
234 OSG_INIT_DESC(_sfVec3fDesc,
235 SFVec3f,
236 "sfVec3fHelperDesc" ),
238 OSG_INIT_DESC(_sfFCPtrDesc,
239 SFUnrecFieldContainerPtr,
240 "sfFCPtrHelperDesc" ),
242 OSG_INIT_DESC(_sfImagePtrDesc,
243 SFUnrecImagePtr,
244 "sfImageHelperDesc" ),
246 OSG_INIT_DESC(_sfReal32Desc,
247 SFReal32,
248 "sfReal32HelperDesc" ),
250 OSG_INIT_DESC(_sfColor3fDesc,
251 SFColor3f,
252 "sfColor3fHelperDesc"),
254 OSG_INIT_DESC(_mfStringDesc,
255 MFString,
256 "mfStringHelperDesc" ),
258 OSG_INIT_DESC(_sfBoolDesc,
259 SFBool,
260 "sfBoolDesc" )
264 /*-------------------------------------------------------------------------*/
265 /* Destructor */
267 VRMLNodeHelper::~VRMLNodeHelper(void)
269 _pNodeProto = NULL;
270 _pNodeCoreProto = NULL;
271 _pGenAttProto = NULL;
274 /*-------------------------------------------------------------------------*/
275 /* Helper */
278 void VRMLNodeHelper::reset(void)
283 /*-------------------------------------------------------------------------*/
284 /* Field */
286 FieldContainerTransitPtr VRMLNodeHelper::beginNode(
287 const Char8 *szTypename,
288 const Char8 *szName,
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);
319 if(pAtt != NULL)
321 pAtt->setVrmlNodeTypename(szTypename);
322 pAtt->setInternal (true);
325 if(pCore != NULL)
327 pCore->addAttachment(pAtt);
329 else
331 AttachmentContainer *pAttCnt =
332 dynamic_pointer_cast<AttachmentContainer>(returnValue);
334 if(pAttCnt != NULL)
336 pAttCnt->addAttachment(pAtt);
342 return FieldContainerTransitPtr(returnValue);
345 void VRMLNodeHelper::endNode(FieldContainer *)
349 void VRMLNodeHelper::mapFieldname(const std::string &, std::string &)
353 /*-------------------------------------------------------------------------*/
354 /* Prototypes */
356 void VRMLNodeHelper::init(const Char8 *szName)
358 _bProtoInterfaceDone = false;
361 /*-------------------------------------------------------------------------*/
362 /* Node */
364 bool VRMLNodeHelper::prototypeAddField(const Char8 *szFieldType,
365 const UInt32 uiFieldTypeId,
366 const Char8 *szFieldName)
368 bool returnValue = false;
371 GetFieldHandlePtr pField = getField(_pNodeProto,
372 _pNodeCoreProto,
373 _pGenAttProto,
374 szFieldName);
376 #ifdef OSG_DEBUG_VRML
377 indentLog(getIndent(), PINFO);
378 PINFO << "VRMLNodeDesc::prototypeAddField | getField "
379 << szFieldName
380 << " returned : "
381 << pField
382 << std::endl;
383 #endif
385 if(pField == NULL || pField->isValid() == false)
387 FieldDescriptionBase *pDesc = getFieldDescription(szFieldName,
388 uiFieldTypeId);
390 if(pDesc != NULL && _pGenAttProto != NULL)
392 _pGenAttProto->addField(*pDesc);
394 pField = getField(_pNodeProto,
395 _pNodeCoreProto,
396 _pGenAttProto,
397 szFieldName);
399 delete pDesc;
402 #ifdef OSG_DEBUG_VRML
403 indentLog(getIndent(), PINFO);
404 PINFO << "VRMLNodeDesc::prototypeAddField | field added : "
405 << szFieldType
406 << " "
407 << uiFieldTypeId
408 << " "
409 << szFieldName
410 << " "
411 << pField
412 << std::endl;
413 #endif
415 returnValue = (pField != NULL && pField->isValid());
417 else
419 #ifdef OSG_DEBUG_VRML
420 incIndent();
421 indentLog(getIndent(), PINFO);
422 #endif
423 PINFO << "VRMLNodeDesc::prototypeAddField | "
424 << "Could not add field "
425 << szFieldName
426 << " a second time"
427 << std::endl;
429 #ifdef OSG_DEBUG_VRML
430 decIndent();
431 #endif
434 return returnValue;
437 void VRMLNodeHelper::endProtoInterface(void)
439 _bProtoInterfaceDone = true;
442 /*-------------------------------------------------------------------------*/
443 /* Dump */
445 void VRMLNodeHelper::getFieldAndDesc( FieldContainer * pFC,
446 const Char8 * szFieldname,
447 FieldContainer *&pFieldFC,
448 EditFieldHandlePtr &pField,
449 const FieldDescriptionBase *&pDesc)
451 if(szFieldname == NULL)
452 return;
454 FieldContainer *pTmpFC = NULL;
455 Node *pNode = NULL;
456 NodeCore *pNodeCore = NULL;
458 pFieldFC = NULL;
459 pField.reset();
460 pDesc = NULL;
462 if(pFC == NULL)
464 if(_bProtoInterfaceDone == false)
466 getField(szFieldname, pFieldFC, pField, pDesc);
469 return;
471 #ifdef OSG_DEBUG_VRML
472 indentLog(getIndent(), PINFO);
473 PINFO << "VRMLNodeHelper::getFieldAndDesc : looking for "
474 << szFieldname
475 << std::endl;
477 incIndent();
478 #endif
480 pDesc = pFC->getFieldDescription(szFieldname);
482 if(pDesc != NULL)
484 pFieldFC = pFC;
485 pField = pFC->editField(szFieldname);
487 else
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 : "
502 << pDesc
503 << std::endl;
504 #endif
506 if(pDesc != NULL)
508 pFieldFC = pNodeCore;
509 pField = pNodeCore->editField(szFieldname);
511 else
513 pTmpFC = pNode->findAttachment(
514 VRMLGenericAtt::getClassType().getGroupId());
516 if(pTmpFC != NULL)
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;
525 #endif
527 if(pDesc == NULL)
529 pTmpFC =
530 pNodeCore->findAttachment(
531 VRMLGenericAtt::getClassType().getGroupId());
533 if(pTmpFC != NULL)
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;
542 #endif
545 if(pDesc != NULL)
547 pFieldFC = pTmpFC;
548 pField = pTmpFC->editField(szFieldname);
552 else
554 if(pDesc == NULL)
556 pTmpFC =
557 pNode->findAttachment(
558 VRMLGenericAtt::getClassType().getGroupId());
560 if(pTmpFC != NULL)
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;
569 #endif
572 if(pDesc != NULL)
574 pFieldFC = pTmpFC;
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());
586 if(pTmpFC != NULL)
588 pDesc = pTmpFC->getFieldDescription(szFieldname);
591 if(pDesc != NULL)
593 pFieldFC = pTmpFC;
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;
601 #endif
605 #ifdef OSG_DEBUG_VRML
606 decIndent();
607 #endif
610 GetFieldHandlePtr VRMLNodeHelper::getField( FieldContainer *pFC1,
611 FieldContainer *pFC2,
612 VRMLGenericAtt *pGenAtt,
613 const Char8 *szFieldname)
615 GetFieldHandlePtr returnValue;
617 if(szFieldname == NULL)
619 return returnValue;
622 #ifdef OSG_DEBUG_VRML
623 indentLog(getIndent(), PINFO);
624 PINFO << "VRMLNodeDesc::getField " << std::endl;
626 incIndent();
628 indentLog(getIndent(), PINFO);
629 PINFO << "Trying to find field : " << szFieldname << std::endl;
630 #endif
632 if(pFC1 != NULL)
634 returnValue = pFC1->getField(szFieldname);
637 #ifdef OSG_DEBUG_VRML
638 incIndent();
640 indentLog(getIndent(), PINFO);
641 PINFO << "Got this from node : " << returnValue << std::endl;
642 #endif
644 if(returnValue == NULL)
646 if(pFC2 != NULL)
648 returnValue = pFC2->getField(szFieldname);
650 #ifdef OSG_DEBUG_VRML
651 indentLog(getIndent(), PINFO);
652 PINFO << "Got this from nodecore : " << returnValue << std::endl;
653 #endif
655 else
657 #ifdef OSG_DEBUG_VRML
658 indentLog(getIndent(), PINFO);
659 PINFO << "No core to check" << std::endl;
660 #endif
664 if(returnValue == NULL)
666 if(pGenAtt != NULL)
668 returnValue = pGenAtt->getField(szFieldname);
671 #ifdef OSG_DEBUG_VRML
672 indentLog(getIndent(), PINFO);
673 PINFO << "Got this from attachment : " << returnValue << std::endl;
674 #endif
679 #ifdef OSG_DEBUG_VRML
680 decIndent();
681 decIndent();
682 #endif
684 return returnValue;
688 void VRMLNodeHelper::getField(const Char8 * szFieldname,
689 FieldContainer *&pFieldFC,
690 EditFieldHandlePtr &pField,
691 const FieldDescriptionBase *&pDesc )
693 pFieldFC = NULL;
694 pField.reset();
695 pDesc = NULL;
697 if(szFieldname == NULL)
699 return;
702 #ifdef OSG_DEBUG_VRML
703 indentLog(getIndent(), PINFO);
704 PINFO << "VRMLNodeDesc::getField " << std::endl;
706 incIndent();
708 indentLog(getIndent(), PINFO);
709 PINFO << "Trying to find field : " << szFieldname << std::endl;
710 #endif
712 if(_pNodeProto != NULL)
714 pFieldFC = _pNodeProto;
715 pField = _pNodeProto->editField (szFieldname);
716 pDesc = _pNodeProto->getFieldDescription(szFieldname);
719 #ifdef OSG_DEBUG_VRML
720 incIndent();
722 indentLog(getIndent(), PINFO);
723 PINFO << "Got this from node : " << pDesc << " " << pField << std::endl;
724 #endif
726 if(pDesc == NULL)
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 : "
737 << pDesc
738 << " "
739 << pField
740 << std::endl;
741 #endif
743 else
745 #ifdef OSG_DEBUG_VRML
746 indentLog(getIndent(), PINFO);
747 PINFO << "No core to check" << std::endl;
748 #endif
752 if(pDesc == NULL)
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 : "
764 << pDesc
765 << " "
766 << pField
767 << std::endl;
768 #endif
773 if(pDesc == NULL)
775 pFieldFC = NULL;
778 #ifdef OSG_DEBUG_VRML
779 decIndent();
780 decIndent();
781 #endif
785 FieldDescriptionBase *VRMLNodeHelper::getFieldDescription(
786 const Char8 *szFieldName,
787 const UInt32 uiFieldTypeId)
789 FieldDescriptionBase *returnValue = NULL;
791 returnValue = FieldDescFactory::the()->createIdx(
792 uiFieldTypeId,
793 szFieldName,
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",
803 szFieldName,
804 uiFieldTypeId));
807 return returnValue;
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 *,
822 Image * )
824 FWARNING(("addImageValue not caught, something is strange\n"));
827 void VRMLNodeHelper::setContainerFieldValue(
828 FieldContainer *pFC,
829 const FieldDescriptionBase *pFieldDesc,
830 FieldContainer *pFieldFC )
832 if((pFieldDesc != NULL ) &&
833 (pFieldFC != 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())
847 pSFHandle->set(pFC);
849 else if(pMFHandle != NULL && pMFHandle->isValid())
851 pMFHandle->add(pFC);
854 pFieldFC->pushToField(pFC,
855 pFieldDesc->getFieldId());
860 /*-------------------------------------------------------------------------*/
861 /* Get */
870 //---------------------------------------------------------------------------
871 // Class
872 //---------------------------------------------------------------------------
874 VRMLNodeHelper *VRMLDefaultHelper::create(void)
876 return new VRMLDefaultHelper();
879 /*-------------------------------------------------------------------------*/
880 /* Constructors */
882 VRMLDefaultHelper::VRMLDefaultHelper(void) :
883 Inherited()
887 /*-------------------------------------------------------------------------*/
888 /* Destructor */
890 VRMLDefaultHelper::~VRMLDefaultHelper(void)
894 /*-------------------------------------------------------------------------*/
895 /* Helper */
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;
904 #endif
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,
915 const Char8 *szName,
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 /*-------------------------------------------------------------------------*/
925 /* Dump */
927 void VRMLDefaultHelper::dump(const Char8 *)
935 //---------------------------------------------------------------------------
936 // Generic Helper with 1:1 mapping
937 //---------------------------------------------------------------------------
939 template<>
940 VRMLNodeHelperFactoryBase::RegisterHelper
941 VRMLGenericHelper<Group>::_regHelper(
942 &VRMLGenericHelper<Group>::create,
943 "Group",
944 NULL);
946 OSG_INST_GENERICVRMLHELPER(Group);
948 template<>
949 VRMLNodeHelperFactoryBase::RegisterHelper
950 VRMLGenericHelper<ComponentTransform>::_regHelper(
951 &VRMLGenericHelper<ComponentTransform>::create,
952 "Transform",
953 NULL);
955 OSG_INST_GENERICVRMLHELPER(ComponentTransform);
959 //---------------------------------------------------------------------------
960 // Class
961 //---------------------------------------------------------------------------
963 VRMLNodeHelper *VRMLMaterialHelper::create(void)
965 return new VRMLMaterialHelper();
968 /*-------------------------------------------------------------------------*/
969 /* Constructors */
971 VRMLMaterialHelper::VRMLMaterialHelper(void) :
972 Inherited ( ),
974 _defaultAmbientIntensity(),
975 _defaultDiffuseColor (),
976 _defaultEmissiveColor (),
977 _defaultShininess (),
978 _defaultSpecularColor (),
979 _defaultTransparency (),
981 _ambientIntensity (),
982 _diffuseColor (),
983 _emissiveColor (),
984 _shininess (),
985 _specularColor (),
986 _transparency (),
988 _pDefMat (NULL),
989 _pMat (NULL),
991 _szName ( )
995 /*-------------------------------------------------------------------------*/
996 /* Destructor */
998 VRMLMaterialHelper::~VRMLMaterialHelper(void)
1000 _pDefMat = NULL;
1003 /*-------------------------------------------------------------------------*/
1004 /* Helper */
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;
1011 #endif
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);
1024 _szName .erase ();
1026 _pMat = NULL;
1029 Material *VRMLMaterialHelper::getDefaultMaterial(void)
1031 return _pDefMat;
1034 /*-------------------------------------------------------------------------*/
1035 /* Field */
1037 bool VRMLMaterialHelper::prototypeAddField(const Char8 *,
1038 const UInt32 ,
1039 const Char8 *szFieldname)
1041 bool bFound = false;
1043 if(osgStringCaseCmp("ambientIntensity", szFieldname) == 0)
1045 bFound = true;
1047 else if(osgStringCaseCmp("diffuseColor", szFieldname) == 0)
1049 bFound = true;
1051 else if(osgStringCaseCmp("emissiveColor", szFieldname) == 0)
1053 bFound = true;
1055 else if(osgStringCaseCmp("shininess", szFieldname) == 0)
1057 bFound = true;
1059 else if(osgStringCaseCmp("specularColor", szFieldname) == 0)
1061 bFound = true;
1063 else if(osgStringCaseCmp("transparency", szFieldname) == 0)
1065 bFound = true;
1068 if(bFound == true)
1070 #ifdef OSG_DEBUG_VRML
1071 indentLog(getIndent(), PINFO);
1072 PINFO << "MaterialDesc::prototypeAddField : add part "
1073 << szFieldname
1074 << std::endl;
1075 #endif
1076 return true;
1078 else
1080 return false;
1084 void VRMLMaterialHelper::endProtoInterface(void)
1086 Color4f cCol;
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(
1131 FieldContainer *,
1132 const Char8 * szFieldname,
1133 FieldContainer *&pFieldFC,
1134 EditFieldHandlePtr &pField,
1135 const FieldDescriptionBase *&pDesc)
1137 pFieldFC = NULL;
1138 pField.reset();
1139 pDesc = NULL;
1141 if(osgStringCaseCmp("ambientIntensity", szFieldname) == 0)
1143 pFieldFC = NULL;
1145 if(_bProtoInterfaceDone == false)
1147 pField =
1148 _sfReal32Desc.createEditHandler(&_defaultAmbientIntensity,
1149 NULL );
1151 else
1153 pField = _sfReal32Desc.createEditHandler(&_ambientIntensity,
1154 NULL );
1157 pDesc = &_sfReal32Desc;
1159 else if(osgStringCaseCmp("diffuseColor", szFieldname) == 0)
1161 pFieldFC = NULL;
1163 if(_bProtoInterfaceDone == false)
1165 pField = _sfColor3fDesc.createEditHandler(&_defaultDiffuseColor,
1166 NULL );
1168 else
1170 pField = _sfColor3fDesc.createEditHandler(&_diffuseColor,
1171 NULL );
1174 pDesc = &_sfColor3fDesc;
1176 else if(osgStringCaseCmp("emissiveColor", szFieldname) == 0)
1178 pFieldFC = NULL;
1180 if(_bProtoInterfaceDone == false)
1182 pField = _sfColor3fDesc.createEditHandler(&_defaultEmissiveColor,
1183 NULL );
1185 else
1187 pField = _sfColor3fDesc.createEditHandler(&_emissiveColor,
1188 NULL );
1191 pDesc = &_sfColor3fDesc;
1193 else if(osgStringCaseCmp("shininess", szFieldname) == 0)
1195 pFieldFC = NULL;
1197 if(_bProtoInterfaceDone == false)
1199 pField = _sfReal32Desc.createEditHandler(&_defaultShininess,
1200 NULL );
1202 else
1204 pField = _sfReal32Desc.createEditHandler(&_shininess,
1205 NULL );
1208 pDesc = &_sfReal32Desc;
1210 else if(osgStringCaseCmp("specularColor", szFieldname) == 0)
1212 pFieldFC = NULL;
1214 if(_bProtoInterfaceDone == false)
1216 pField = _sfColor3fDesc.createEditHandler(&_defaultSpecularColor,
1217 NULL );
1219 else
1221 pField = _sfColor3fDesc.createEditHandler(&_specularColor,
1222 NULL );
1225 pDesc = &_sfColor3fDesc;
1227 else if(osgStringCaseCmp("transparency", szFieldname) == 0)
1229 pFieldFC = NULL;
1231 if(_bProtoInterfaceDone == false)
1233 pField = _sfReal32Desc.createEditHandler(&_defaultTransparency,
1234 NULL );
1236 else
1238 pField = _sfReal32Desc.createEditHandler(&_transparency,
1239 NULL );
1242 pDesc = &_sfReal32Desc;
1246 /*-------------------------------------------------------------------------*/
1247 /* Node */
1249 FieldContainerTransitPtr VRMLMaterialHelper::beginNode(
1250 const Char8 *,
1251 const Char8 *szName,
1252 FieldContainer * )
1254 reset();
1256 _pMat = MaterialChunk::create();
1258 _szName = (szName != NULL) ? szName : "";
1260 return FieldContainerTransitPtr(_pMat);
1263 void VRMLMaterialHelper::endNode(FieldContainer *)
1265 if(_pMat != NULL)
1267 Color4f cCol;
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 /*-------------------------------------------------------------------------*/
1303 /* Type Specific */
1305 const std::string &VRMLMaterialHelper::getName(void) const
1307 return _szName;
1310 /*-------------------------------------------------------------------------*/
1311 /* Dump */
1313 void VRMLMaterialHelper::dump(const Char8 *)
1317 VRMLNodeHelperFactoryBase::RegisterHelper VRMLMaterialHelper::_regHelper(
1318 &VRMLMaterialHelper::create,
1319 "Material",
1320 NULL);
1326 //---------------------------------------------------------------------------
1327 // Class
1328 //---------------------------------------------------------------------------
1330 VRMLNodeHelper *VRMLShapeHelper::create(void)
1332 return new VRMLShapeHelper();
1336 /*-------------------------------------------------------------------------*/
1337 /* Constructors */
1339 VRMLShapeHelper::VRMLShapeHelper(void) :
1340 Inherited ( ),
1341 _pMaterialHelper(NULL)
1345 /*-------------------------------------------------------------------------*/
1346 /* Destructor */
1348 VRMLShapeHelper::~VRMLShapeHelper(void)
1352 /*-------------------------------------------------------------------------*/
1353 /* Helper */
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;
1362 #endif
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 /*-------------------------------------------------------------------------*/
1377 /* Get */
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 : "
1388 << szFieldname
1389 << std::endl;
1390 #endif
1392 if(szFieldname == NULL)
1393 return false;
1395 incIndent();
1397 if(osgStringCaseCmp("geometry", szFieldname) == 0)
1399 returnValue = true;
1401 #ifdef OSG_DEBUG_VRML
1402 indentLog(getIndent(), PINFO);
1403 PINFO << "VRMLShapeHelper::prototypeAddField | request internal : "
1404 << szFieldname
1405 << " "
1406 << std::endl;
1407 #endif
1410 if(osgStringCaseCmp("appearance", szFieldname) == 0)
1412 returnValue = true;
1414 #ifdef OSG_DEBUG_VRML
1415 indentLog(getIndent(), PINFO);
1417 PINFO << "VRMLShapeHelper::prototypeAddField | request internal : "
1418 << szFieldname
1419 << " "
1420 << std::endl;
1421 #endif
1424 if(returnValue == false)
1426 returnValue = Inherited::prototypeAddField(szFieldType,
1427 uiFieldTypeId,
1428 szFieldname);
1431 #ifdef OSG_DEBUG_VRML
1432 decIndent();
1433 #endif
1435 return returnValue;
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)
1446 return;
1448 if(pFC == NULL)
1450 if(_bProtoInterfaceDone == false)
1452 Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
1455 return;
1458 #ifdef OSG_DEBUG_VRML
1459 indentLog(getIndent(), PINFO);
1460 PINFO << "VRMLShapeHelper::getFieldAndDesc : looking for "
1461 << szFieldname
1462 << std::endl;
1464 incIndent();
1465 #endif
1467 if(osgStringCaseCmp("geometry", szFieldname) == 0)
1469 #ifdef OSG_DEBUG_VRML
1470 indentLog(getIndent(), PINFO);
1471 PINFO << "VRMLShapeHelper::getFieldAndDesc : request internal "
1472 << szFieldname
1473 << std::endl;
1474 #endif
1475 pFieldFC = pFC;
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 "
1484 << szFieldname
1485 << std::endl;
1486 #endif
1488 Node *pNode = dynamic_cast<Node *>(pFC);
1490 if(pNode != NULL)
1492 if(pNode->getCore() != NULL)
1494 pFieldFC = pNode->getCore();
1495 pField = pNode->getCore()->editField("material");
1496 pDesc = pNode->getCore()->getFieldDescription("material");
1499 else
1501 Inherited::getFieldAndDesc(pFC,
1502 szFieldname,
1503 pFC,
1504 pField,
1505 pDesc);
1508 else
1510 Inherited::getFieldAndDesc(pFC,
1511 szFieldname,
1512 pFC,
1513 pField,
1514 pDesc);
1517 #ifdef OSG_DEBUG_VRML
1518 decIndent();
1519 #endif
1522 /*-------------------------------------------------------------------------*/
1523 /* Node */
1526 void VRMLShapeHelper::endNode(FieldContainer *pFC)
1528 if(pFC != NULL)
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);
1542 else
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);
1562 if(pChild != NULL)
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
1576 // decIndent();
1578 indentLog(getIndent(), PINFO);
1579 PINFO << "End Shape " << &(*pFC) << std::endl;
1580 #endif
1583 /*-------------------------------------------------------------------------*/
1584 /* Dump */
1586 void VRMLShapeHelper::dump(const Char8 *)
1590 VRMLNodeHelperFactoryBase::RegisterHelper VRMLShapeHelper::_regHelper(
1591 &VRMLShapeHelper::create,
1592 "Shape",
1593 NULL);
1598 //---------------------------------------------------------------------------
1599 // Class
1600 //---------------------------------------------------------------------------
1602 VRMLNodeHelper *VRMLAppearanceHelper::create(void)
1604 return new VRMLAppearanceHelper();
1607 /*-------------------------------------------------------------------------*/
1608 /* Constructors */
1610 VRMLAppearanceHelper::VRMLAppearanceHelper(void) :
1611 Inherited ( ),
1612 _pMaterialHelper(NULL)
1616 /*-------------------------------------------------------------------------*/
1617 /* Destructor */
1619 VRMLAppearanceHelper::~VRMLAppearanceHelper(void)
1623 /*-------------------------------------------------------------------------*/
1624 /* Helper */
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;
1633 #endif
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 /*-------------------------------------------------------------------------*/
1648 /* Field */
1650 bool VRMLAppearanceHelper::prototypeAddField(const Char8 *szFieldType,
1651 const UInt32 uiFieldTypeId,
1652 const Char8 *szFieldname)
1654 if(szFieldname == NULL)
1655 return false;
1657 if(osgStringCaseCmp("material", szFieldname) == 0)
1659 return true;
1661 else if(osgStringCaseCmp("texture", szFieldname) == 0)
1663 return true;
1665 else if(osgStringCaseCmp("textureTransform", szFieldname) == 0)
1667 return true;
1669 else
1671 return Inherited::prototypeAddField(szFieldType,
1672 uiFieldTypeId,
1673 szFieldname);
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 "
1688 << szFieldname
1689 << std::endl;
1690 #endif
1692 if(pFC == NULL)
1694 if(_bProtoInterfaceDone == false)
1696 Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
1699 return;
1702 if(szFieldname == NULL)
1703 return;
1705 incIndent();
1707 if(osgStringCaseCmp("material", szFieldname) == 0)
1709 #ifdef OSG_DEBUG_VRML
1710 indentLog(getIndent(), PINFO);
1711 PINFO << "VRMLAppearanceDesc::getFieldAndDesc : request internal "
1712 << szFieldname
1713 << std::endl;
1714 #endif
1715 pFieldFC = pFC;
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 "
1724 << szFieldname
1725 << std::endl;
1726 #endif
1728 pFieldFC = pFC;
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 "
1737 << szFieldname
1738 << std::endl;
1739 #endif
1741 pFieldFC = pFC;
1742 pField = pFC->editField("chunks");
1743 pDesc = pFC->getFieldDescription("chunks");
1745 else
1747 Inherited::getFieldAndDesc(pFC,
1748 szFieldname,
1749 pFC,
1750 pField,
1751 pDesc);
1754 #ifdef OSG_DEBUG_VRML
1755 decIndent();
1756 #endif
1759 /*-------------------------------------------------------------------------*/
1760 /* Node */
1763 void VRMLAppearanceHelper::endNode(FieldContainer *pFC)
1765 if(pFC != NULL)
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) ||
1783 (pTexC != NULL &&
1784 pTexC->getImage() != NULL &&
1785 pTexC->getImage()->hasAlphaChannel() == true ))
1787 BlendChunkUnrecPtr pBlendChunk = OSG::BlendChunk::create();
1789 if(pTexC != NULL &&
1790 pTexC->getImage() != NULL &&
1791 pTexC->getImage()->isAlphaBinary() == true)
1793 pBlendChunk->setAlphaFunc(GL_NOTEQUAL);
1794 pBlendChunk->setAlphaValue(0);
1796 else
1798 pBlendChunk->setSrcFactor (GL_SRC_ALPHA);
1799 pBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
1802 pChunkMat->addChunk(pBlendChunk);
1805 if(pTexC != NULL)
1807 if(pTexE == NULL)
1809 pTexE = TextureEnvChunk::create();
1811 pChunkMat->addChunk(pTexE);
1814 MaterialChunk *pMatC =
1815 dynamic_cast<MaterialChunk *>(
1816 pChunkMat->find(MaterialChunk::getClassType()));
1818 if(pMatC == NULL)
1820 pTexE->setEnvMode(GL_REPLACE);
1822 else
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",
1842 "pushNames",
1843 pushNames) == false)
1845 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());
1856 if(att != NULL)
1858 // ChunkMaterial (Appearance) already has a NameAttachment
1859 Name *nameAtt = dynamic_cast<Name *>(att);
1861 if(nameAtt != NULL)
1863 if(nameAtt->getFieldPtr()->getValue().empty())
1865 nameAtt->editFieldPtr()->getValue().assign(
1866 _pMaterialHelper->getName());
1870 else
1872 setName(attCon, _pMaterialHelper->getName());
1876 // END Material name hack
1881 #ifdef OSG_DEBUG_VRML
1882 // decIndent();
1884 indentLog(getIndent(), PINFO);
1885 PINFO << "End Appearance " << std::endl;
1886 #endif
1889 /*-------------------------------------------------------------------------*/
1890 /* Field Value */
1892 /*-------------------------------------------------------------------------*/
1893 /* Dump */
1895 void VRMLAppearanceHelper::dump(const Char8 *)
1899 VRMLNodeHelperFactoryBase::RegisterHelper VRMLAppearanceHelper::_regHelper(
1900 &VRMLAppearanceHelper::create,
1901 "Appearance",
1902 NULL);
1907 //---------------------------------------------------------------------------
1908 // Class
1909 //---------------------------------------------------------------------------
1911 VRMLNodeHelper *VRMLIndexedGeometryHelper::create(void)
1913 return new VRMLIndexedGeometryHelper();
1916 /*-------------------------------------------------------------------------*/
1917 /* Constructors */
1919 VRMLIndexedGeometryHelper::VRMLIndexedGeometryHelper(void) :
1920 Inherited ( ),
1921 _bIsFaceSet (false ),
1922 _uiPropertyIndex(Geometry::PositionsIndex)
1926 /*-------------------------------------------------------------------------*/
1927 /* Destructor */
1929 VRMLIndexedGeometryHelper::~VRMLIndexedGeometryHelper(void)
1933 /*-------------------------------------------------------------------------*/
1934 /* Helper */
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;
1943 #endif
1945 _pNodeProto = Node ::create();
1946 _pNodeCoreProto = Geometry ::create();
1948 _pGenAttProto = VRMLGenericAtt::createLocal(FCLocal::Cluster);
1949 _pGenAttProto->setInternal(true);
1951 if(osgStringCaseCmp("IndexedFaceSet", szName) == 0)
1953 _bIsFaceSet = true;
1957 /*-------------------------------------------------------------------------*/
1958 /* Get */
1960 bool VRMLIndexedGeometryHelper::prototypeAddField(const Char8 *szFieldType,
1961 const UInt32 uiFieldTypeId,
1962 const Char8 *szFieldname)
1964 bool bFound = false;
1966 if(szFieldname == NULL)
1967 return false;
1969 if(osgStringCaseCmp("coord", szFieldname) == 0)
1971 bFound = true;
1973 else if(osgStringCaseCmp("normal", szFieldname) == 0)
1975 bFound = true;
1977 else if(osgStringCaseCmp("color", szFieldname) == 0)
1979 bFound = true;
1981 else if(osgStringCaseCmp("texCoord", szFieldname) == 0)
1983 bFound = true;
1986 if(bFound == true)
1988 #ifdef OSG_DEBUG_VRML
1989 indentLog(getIndent(), PINFO);
1990 PINFO << "GeoDesc::prototypeAddField : internal "
1991 << szFieldname << std::endl;
1992 #endif
1994 return true;
1996 else
1998 return Inherited::prototypeAddField(szFieldType,
1999 uiFieldTypeId,
2000 szFieldname);
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 "
2015 << szFieldname
2016 << std::endl;
2017 #endif
2019 if(szFieldname == NULL)
2020 return;
2022 if(pFC == NULL)
2024 if(_bProtoInterfaceDone == false)
2026 Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
2029 return;
2032 Node *pNode = dynamic_cast<Node *>(pFC);
2034 if(pNode == NULL)
2036 PWARNING << "GeoDesc::getFieldAndDesc : No Node" << std::endl;
2037 return;
2040 NodeCore *pNodeCore = pNode->getCore();
2042 Geometry *pGeo = dynamic_cast<Geometry *>(pNodeCore);
2044 if(pGeo == NULL)
2046 PWARNING << "GeoDesc::getFieldAndDesc : No Geo" << std::endl;
2047 return;
2050 if(osgStringCaseCmp("coord", szFieldname) == 0)
2052 #ifdef OSG_DEBUG_VRML
2053 indentLog(getIndent(), PINFO);
2054 PINFO << "GeoDesc::getFieldAndDesc : internal "
2055 << szFieldname << std::endl;
2056 #endif
2058 pFieldFC = pGeo;
2059 pField.reset();
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;
2070 #endif
2072 pFieldFC = pGeo;
2073 pField.reset();
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;
2084 #endif
2086 pFieldFC = pGeo;
2087 pField.reset();
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;
2098 #endif
2100 pFieldFC = pGeo;
2101 pField.reset();
2102 pDesc = &_sfFCPtrDesc;
2104 _uiPropertyIndex = Geometry::TexCoordsIndex;
2106 else
2108 Inherited::getFieldAndDesc(pGeo,
2109 szFieldname,
2110 pFieldFC,
2111 pField,
2112 pDesc);
2116 /*-------------------------------------------------------------------------*/
2117 /* Node */
2121 void VRMLIndexedGeometryHelper::endNode(FieldContainer *pFC)
2123 Node *pNode = NULL;
2124 Geometry *pGeo = NULL;
2126 if(pFC == NULL)
2128 return;
2131 pNode = dynamic_cast<Node *>(pFC);
2133 if(pNode == NULL)
2135 return;
2138 pGeo = dynamic_cast<Geometry *>(pNode->getCore());
2140 if(pGeo == NULL)
2142 return;
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,
2161 "coordIndex",
2162 pDummyFC,
2163 pField,
2164 pDesc);
2166 if(pField != NULL)
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,
2178 "normalIndex",
2179 pDummyFC,
2180 pField,
2181 pDesc);
2183 if(pField != NULL)
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,
2195 "colorIndex",
2196 pDummyFC,
2197 pField,
2198 pDesc);
2200 if(pField != NULL)
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,
2212 "texCoordIndex",
2213 pDummyFC,
2214 pField,
2215 pDesc);
2217 if(pField != NULL)
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,
2231 "convex",
2232 pDummyFC,
2233 pField,
2234 pDesc);
2236 if(pField != NULL)
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,
2248 "ccw",
2249 pDummyFC,
2250 pField,
2251 pDesc);
2253 if(pField != NULL)
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,
2265 "normalPerVertex",
2266 pDummyFC,
2267 pField,
2268 pDesc);
2270 if(pField != NULL)
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,
2282 "colorPerVertex",
2283 pDummyFC,
2284 pField,
2285 pDesc);
2287 if(pField != NULL)
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,
2299 "creaseAngle",
2300 pDummyFC,
2301 pField,
2302 pDesc);
2304 if(pField != NULL)
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 &&
2322 pConvex != NULL &&
2323 pCcw != 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;
2331 #endif
2333 setIndexFromIndexedX3DData(pGeo,
2334 pCoordIndex ->getValues(),
2335 pNormalIndex ->getValues(),
2336 pColorIndex ->getValues(),
2337 pTexCoordIndex ->getValues(),
2338 GL_POLYGON,
2339 pConvex ->getValue() ,
2340 pCcw ->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;
2359 #endif
2361 OSG::calcVertexNormals(pGeo, pCreaseAngle->getValue());
2364 else
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);
2380 ++parentsIt;
2382 pGeo = NULL;
2383 #endif
2386 else
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;
2399 #endif
2401 setIndexFromIndexedX3DData(pGeo,
2402 pCoordIndex ->getValues(),
2403 dummyVec ,
2404 pColorIndex ->getValues(),
2405 dummyVec ,
2406 GL_LINE_STRIP,
2407 dummybool,
2408 dummybool,
2409 dummybool,
2410 pColorPerVertex->getValue() ,
2411 false); // create normal; not yet :)
2413 else
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);
2429 ++parentsIt;
2431 pGeo = NULL;
2432 #endif
2436 #ifdef OSG_DEBUG_VRML
2437 // decIndent();
2439 indentLog(getIndent(), PINFO);
2440 PINFO << "End Geo " << &(*pNode) << std::endl;
2441 #endif
2445 void VRMLIndexedGeometryHelper::setContainerFieldValue(
2446 FieldContainer *pFC,
2447 const FieldDescriptionBase *pFieldDesc,
2448 FieldContainer *pFieldFC )
2450 Geometry *pGeo =
2451 dynamic_cast<Geometry *>(pFieldFC);
2453 GeoVectorProperty *pVecProp =
2454 dynamic_cast<GeoVectorProperty *>(pFC);
2456 if(pGeo != NULL && pVecProp != NULL)
2458 pGeo->setProperty(pVecProp, _uiPropertyIndex);
2460 else
2462 PWARNING << "GeoDesc::getFieldAndDesc : No Geo" << std::endl;
2466 /*-------------------------------------------------------------------------*/
2467 /* Dump */
2469 void VRMLIndexedGeometryHelper::dump(const Char8 *)
2474 VRMLNodeHelperFactoryBase::RegisterHelper
2475 VRMLIndexedGeometryHelper::_regHelperIFS(
2476 &VRMLIndexedGeometryHelper::create,
2477 "IndexedFaceSet",
2478 NULL);
2480 VRMLNodeHelperFactoryBase::RegisterHelper
2481 VRMLIndexedGeometryHelper::_regHelperILS(
2482 &VRMLIndexedGeometryHelper::create,
2483 "IndexedLineSet",
2484 NULL);
2490 //---------------------------------------------------------------------------
2491 // Class
2492 //---------------------------------------------------------------------------
2494 VRMLNodeHelper *VRMLPointSetGeometryHelper::create(void)
2496 return new VRMLPointSetGeometryHelper();
2499 /*-------------------------------------------------------------------------*/
2500 /* Constructors */
2502 VRMLPointSetGeometryHelper::VRMLPointSetGeometryHelper(void) :
2503 Inherited ( ),
2504 _uiPropertyIndex(Geometry::PositionsIndex)
2508 /*-------------------------------------------------------------------------*/
2509 /* Destructor */
2511 VRMLPointSetGeometryHelper::~VRMLPointSetGeometryHelper(void)
2515 /*-------------------------------------------------------------------------*/
2516 /* Helper */
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;
2525 #endif
2527 _pNodeProto = Node ::create();
2528 _pNodeCoreProto = Geometry ::create();
2530 _pGenAttProto = VRMLGenericAtt::createLocal(FCLocal::Cluster);
2531 _pGenAttProto->setInternal(true);
2534 /*-------------------------------------------------------------------------*/
2535 /* Get */
2537 bool VRMLPointSetGeometryHelper::prototypeAddField(const Char8 *szFieldType,
2538 const UInt32 uiFieldTypeId,
2539 const Char8 *szFieldname)
2541 bool bFound = false;
2543 if(szFieldname == NULL)
2544 return false;
2546 if(osgStringCaseCmp("coord", szFieldname) == 0)
2548 bFound = true;
2550 else if(osgStringCaseCmp("color", szFieldname) == 0)
2552 bFound = true;
2555 if(bFound == true)
2557 #ifdef OSG_DEBUG_VRML
2558 indentLog(getIndent(), PINFO);
2559 PINFO << "GeoDesc::prototypeAddField : internal "
2560 << szFieldname << std::endl;
2561 #endif
2563 return true;
2565 else
2567 return Inherited::prototypeAddField(szFieldType,
2568 uiFieldTypeId,
2569 szFieldname);
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 "
2584 << szFieldname
2585 << std::endl;
2586 #endif
2588 if(szFieldname == NULL)
2589 return;
2591 if(pFC == NULL)
2593 if(_bProtoInterfaceDone == false)
2595 Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
2598 return;
2601 Node *pNode = dynamic_cast<Node *>(pFC);
2603 if(pNode == NULL)
2605 PWARNING << "GeoDesc::getFieldAndDesc : No Node" << std::endl;
2606 return;
2609 NodeCore *pNodeCore = pNode->getCore();
2611 Geometry *pGeo = dynamic_cast<Geometry *>(pNodeCore);
2613 if(pGeo == NULL)
2615 PWARNING << "GeoDesc::getFieldAndDesc : No Geo" << std::endl;
2616 return;
2619 if(osgStringCaseCmp("coord", szFieldname) == 0)
2621 #ifdef OSG_DEBUG_VRML
2622 indentLog(getIndent(), PINFO);
2623 PINFO << "GeoDesc::getFieldAndDesc : internal "
2624 << szFieldname << std::endl;
2625 #endif
2627 pFieldFC = pGeo;
2628 pField.reset();
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;
2639 #endif
2641 pFieldFC = pGeo;
2642 pField.reset();
2643 pDesc = &_sfFCPtrDesc;
2645 _uiPropertyIndex = Geometry::ColorsIndex;
2647 else
2649 Inherited::getFieldAndDesc(pGeo,
2650 szFieldname,
2651 pFieldFC,
2652 pField,
2653 pDesc);
2657 /*-------------------------------------------------------------------------*/
2658 /* Node */
2662 void VRMLPointSetGeometryHelper::endNode(FieldContainer *pFC)
2664 Node *pNode = NULL;
2665 Geometry *pGeo = NULL;
2667 if(pFC == NULL)
2669 return;
2672 pNode = dynamic_cast<Node *>(pFC);
2674 if(pNode == NULL)
2676 return;
2679 pGeo = dynamic_cast<Geometry *>(pNode->getCore());
2681 if(pGeo == NULL)
2683 return;
2686 GeoVectorProperty *pPnts = pGeo->getProperty(Geometry::PositionsIndex);
2688 if(pPnts == NULL)
2689 return;
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 );
2700 #if 0
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 &&
2714 pConvex != NULL &&
2715 pCcw != 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;
2723 #endif
2725 setIndexFromIndexedX3DData(pGeo,
2726 pCoordIndex ->getValues(),
2727 pNormalIndex ->getValues(),
2728 pColorIndex ->getValues(),
2729 pTexCoordIndex ->getValues(),
2730 GL_POLYGON,
2731 pConvex ->getValue() ,
2732 pCcw ->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;
2751 #endif
2753 OSG::calcVertexNormals(pGeo, pCreaseAngle->getValue());
2756 else
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);
2772 ++parentsIt;
2774 pGeo = NULL;
2775 #endif
2778 else
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;
2791 #endif
2793 setIndexFromIndexedX3DData(pGeo,
2794 pCoordIndex ->getValues(),
2795 dummyVec ,
2796 pColorIndex ->getValues(),
2797 dummyVec ,
2798 GL_LINE_STRIP,
2799 dummybool,
2800 dummybool,
2801 dummybool,
2802 pColorPerVertex->getValue() ,
2803 false); // create normal; not yet :)
2805 else
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);
2821 ++parentsIt;
2823 pGeo = NULL;
2824 #endif
2827 #endif
2829 #ifdef OSG_DEBUG_VRML
2830 // decIndent();
2832 indentLog(getIndent(), PINFO);
2833 PINFO << "End Geo " << &(*pNode) << std::endl;
2834 #endif
2838 void VRMLPointSetGeometryHelper::setContainerFieldValue(
2839 FieldContainer *pFC,
2840 const FieldDescriptionBase *pFieldDesc,
2841 FieldContainer *pFieldFC )
2843 Geometry *pGeo =
2844 dynamic_cast<Geometry *>(pFieldFC);
2846 GeoVectorProperty *pVecProp =
2847 dynamic_cast<GeoVectorProperty *>(pFC);
2849 if(pGeo != NULL && pVecProp != NULL)
2851 pGeo->setProperty(pVecProp, _uiPropertyIndex);
2853 else
2855 PWARNING << "GeoDesc::getFieldAndDesc : No Geo" << std::endl;
2859 /*-------------------------------------------------------------------------*/
2860 /* Dump */
2862 void VRMLPointSetGeometryHelper::dump(const Char8 *)
2867 VRMLNodeHelperFactoryBase::RegisterHelper
2868 VRMLPointSetGeometryHelper::_regHelperPS(
2869 &VRMLPointSetGeometryHelper::create,
2870 "PointSet",
2871 NULL);
2877 //---------------------------------------------------------------------------
2878 // Class
2879 //---------------------------------------------------------------------------
2881 VRMLNodeHelper *VRMLGeometryPartHelper::create(void)
2883 return new VRMLGeometryPartHelper();
2886 /*-------------------------------------------------------------------------*/
2887 /* Constructors */
2889 VRMLGeometryPartHelper::VRMLGeometryPartHelper(void) :
2890 Inherited (),
2892 _szVRMLPartname(),
2893 _szOSGPartname (),
2894 _szOSGProtoname()
2898 /*-------------------------------------------------------------------------*/
2899 /* Destructor */
2901 VRMLGeometryPartHelper::~VRMLGeometryPartHelper(void)
2905 /*-------------------------------------------------------------------------*/
2906 /* Helper */
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 : "
2938 << szName << " "
2939 << _szVRMLPartname << " "
2940 << _szOSGPartname << " "
2941 << _szOSGProtoname << " "
2942 << std::endl;
2943 #endif
2945 _pNodeProto =
2946 FieldContainerFactory::the()->createContainer(_szOSGProtoname.c_str());
2948 if(_pNodeProto == NULL)
2950 PWARNING << "ERROR no prototype available for "
2951 << _szOSGProtoname
2952 << std::endl;
2955 _pGenAttProto = VRMLGenericAtt::createLocal(FCLocal::Cluster);
2956 _pGenAttProto->setInternal(true);
2959 /*-------------------------------------------------------------------------*/
2960 /* Field */
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 "
2973 << szFieldname
2974 << std::endl;
2975 #endif
2977 bFound = true;
2981 if(bFound == true)
2983 return true;
2985 else
2987 return Inherited::prototypeAddField(szFieldType,
2988 uiFieldTypeId,
2989 szFieldname);
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 "
3003 << szFieldname
3004 << std::endl;
3005 #endif
3007 if(szFieldname == NULL)
3008 return;
3010 if(pFC == NULL)
3012 if(_bProtoInterfaceDone == false)
3014 Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
3017 return;
3020 incIndent();
3022 if(_szVRMLPartname == szFieldname)
3024 #ifdef OSG_DEBUG_VRML
3025 indentLog(getIndent(), PINFO);
3026 PINFO << "VRMLGeometryPartDesc::getFieldAndDesc : request internal "
3027 << szFieldname
3028 << " return "
3029 << _szOSGPartname
3030 << std::endl;
3031 #endif
3033 pFieldFC = pFC;
3034 pDesc = pFC->getFieldDescription(_szOSGPartname.c_str());
3035 pField = pFC->editField (_szOSGPartname.c_str());
3037 if(pField == NULL)
3039 PWARNING << "VRMLGeometryPartDesc::getFieldAndDesc : could not"
3040 << " map : "
3041 << szFieldname
3042 << " to "
3043 << _szOSGPartname
3044 << std::endl;
3047 else
3049 Inherited::getFieldAndDesc(pFC,
3050 szFieldname,
3051 pFieldFC,
3052 pField,
3053 pDesc);
3056 #ifdef OSG_DEBUG_VRML
3057 decIndent();
3058 #endif
3061 /*-------------------------------------------------------------------------*/
3062 /* Node */
3064 void VRMLGeometryPartHelper::mapFieldname(const std::string &,
3065 std::string &szFieldName)
3067 szFieldName.assign("values");
3071 /*-------------------------------------------------------------------------*/
3072 /* Dump */
3074 void VRMLGeometryPartHelper::dump(const Char8 *)
3079 VRMLNodeHelperFactoryBase::RegisterHelper
3080 VRMLGeometryPartHelper::_regHelperCoordinate(
3081 &VRMLGeometryPartHelper::create,
3082 "Coordinate",
3083 NULL);
3085 VRMLNodeHelperFactoryBase::RegisterHelper
3086 VRMLGeometryPartHelper::_regHelperNormal(
3087 &VRMLGeometryPartHelper::create,
3088 "Normal",
3089 NULL);
3091 VRMLNodeHelperFactoryBase::RegisterHelper
3092 VRMLGeometryPartHelper::_regHelperColor(
3093 &VRMLGeometryPartHelper::create,
3094 "Color",
3095 NULL);
3097 VRMLNodeHelperFactoryBase::RegisterHelper
3098 VRMLGeometryPartHelper::_regHelperTexCoordinate(
3099 &VRMLGeometryPartHelper::create,
3100 "TextureCoordinate",
3101 NULL);
3106 //---------------------------------------------------------------------------
3107 // Class
3108 //---------------------------------------------------------------------------
3110 VRMLNodeHelper *VRMLGeometryObjectHelper::create(void)
3112 return new VRMLGeometryObjectHelper();
3115 /*-------------------------------------------------------------------------*/
3116 /* Constructors */
3118 VRMLGeometryObjectHelper::VRMLGeometryObjectHelper(void) :
3119 Inherited ( ),
3120 _eVRMLObjectType(UnknownGeo)
3124 /*-------------------------------------------------------------------------*/
3125 /* Destructor */
3127 VRMLGeometryObjectHelper::~VRMLGeometryObjectHelper(void)
3131 /*-------------------------------------------------------------------------*/
3132 /* Helper */
3134 void VRMLGeometryObjectHelper::init(const Char8 *szName)
3136 #ifdef OSG_DEBUG_VRML
3137 indentLog(getIndent(), PINFO);
3138 PINFO << "GeoObjDesc::init : "
3139 << szName << " "
3140 << _eVRMLObjectType
3141 << std::endl;
3142 #endif
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 /*-------------------------------------------------------------------------*/
3181 /* Field */
3183 /*-------------------------------------------------------------------------*/
3184 /* Node */
3186 void VRMLGeometryObjectHelper::endNode(FieldContainer *pFC)
3188 EditFieldHandlePtr pField;
3189 const FieldDescriptionBase *pDesc = NULL;
3190 FieldContainer *pDummyFC = NULL;
3191 Node *pNode = NULL;
3193 if(pFC == NULL)
3194 return;
3196 pNode = dynamic_cast<Node *>(pFC);
3198 if(pNode == NULL)
3199 return;
3201 if(_eVRMLObjectType == BoxGeo)
3203 Inherited::getFieldAndDesc(pFC,
3204 "size",
3205 pDummyFC,
3206 pField,
3207 pDesc);
3209 EditFieldHandlePtr pFieldInv;
3211 Inherited::getFieldAndDesc(pFC,
3212 "invert",
3213 pDummyFC,
3214 pFieldInv,
3215 pDesc);
3217 if(pField != NULL)
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],
3238 bInv );
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,
3252 "bottomRadius",
3253 pDummyFC,
3254 pField,
3255 pDesc);
3257 if(pField != NULL)
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,
3269 "height",
3270 pDummyFC,
3271 pField,
3272 pDesc);
3274 if(pField != NULL)
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,
3286 "side",
3287 pDummyFC,
3288 pField,
3289 pDesc);
3291 if(pField != NULL)
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,
3303 "bottom",
3304 pDummyFC,
3305 pField,
3306 pDesc);
3308 if(pField != NULL)
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 &&
3320 pHeight != NULL &&
3321 pSide != NULL &&
3322 pBottom != NULL)
3324 #ifdef OSG_DEBUG_VRML
3325 indentLog(getIndent(), PINFO);
3326 PINFO << "VRMLGeometryObjectDesc::endNode : Create cone"
3327 << std::endl;
3328 #endif
3330 GeometryUnrecPtr pGeo = makeConeGeo(pHeight->getValue(),
3331 pBotRad->getValue(),
3333 pSide ->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,
3348 "bottom",
3349 pDummyFC,
3350 pField,
3351 pDesc);
3353 if(pField != NULL)
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,
3365 "height",
3366 pDummyFC,
3367 pField,
3368 pDesc);
3370 if(pField != NULL)
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,
3382 "radius",
3383 pDummyFC,
3384 pField,
3385 pDesc);
3387 if(pField != NULL)
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,
3399 "side",
3400 pDummyFC,
3401 pField,
3402 pDesc);
3404 if(pField != NULL)
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,
3416 "top",
3417 pDummyFC,
3418 pField,
3419 pDesc);
3421 if(pField != NULL)
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 &&
3434 pHeight != NULL &&
3435 pRadius != NULL &&
3436 pSide != NULL &&
3437 pTop != NULL)
3439 #ifdef OSG_DEBUG_VRML
3440 indentLog(getIndent(), PINFO);
3441 PINFO << "VRMLGeometryObjectDesc::endNode : Create cylinder"
3442 << std::endl;
3443 #endif
3445 GeometryUnrecPtr pGeo = makeCylinderGeo(pHeight->getValue(),
3446 pRadius->getValue(),
3448 pSide ->getValue(),
3449 pTop ->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,
3461 "radius",
3462 pDummyFC,
3463 pField,
3464 pDesc);
3466 if(pField != NULL)
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,
3478 "resolution",
3479 pDummyFC,
3480 pField,
3481 pDesc);
3483 if(pField != NULL)
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,
3510 "scale",
3511 pDummyFC,
3512 pField,
3513 pDesc);
3515 if(pField != NULL)
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,
3527 "depth",
3528 pDummyFC,
3529 pField,
3530 pDesc);
3532 if(pField != NULL)
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,
3556 "resolution",
3557 pDummyFC,
3558 pField,
3559 pDesc);
3561 if(pField != NULL)
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,
3573 "size",
3574 pDummyFC,
3575 pField,
3576 pDesc);
3578 if(pField != NULL)
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 /*-------------------------------------------------------------------------*/
3601 /* Dump */
3603 void VRMLGeometryObjectHelper::dump(const Char8 *)
3607 VRMLNodeHelperFactoryBase::RegisterHelper
3608 VRMLGeometryObjectHelper::_regHelperBox(
3609 &VRMLGeometryObjectHelper::create,
3610 "Box",
3611 NULL);
3613 VRMLNodeHelperFactoryBase::RegisterHelper
3614 VRMLGeometryObjectHelper::_regHelperSphere(
3615 &VRMLGeometryObjectHelper::create,
3616 "Sphere",
3617 NULL);
3619 VRMLNodeHelperFactoryBase::RegisterHelper
3620 VRMLGeometryObjectHelper::_regHelperCone(
3621 &VRMLGeometryObjectHelper::create,
3622 "Cone",
3623 NULL);
3625 VRMLNodeHelperFactoryBase::RegisterHelper
3626 VRMLGeometryObjectHelper::_regHelperCylinder(
3627 &VRMLGeometryObjectHelper::create,
3628 "Cylinder",
3629 NULL);
3631 VRMLNodeHelperFactoryBase::RegisterHelper
3632 VRMLGeometryObjectHelper::_regHelperTeapot(
3633 &VRMLGeometryObjectHelper::create,
3634 "Teapot",
3635 NULL);
3637 VRMLNodeHelperFactoryBase::RegisterHelper
3638 VRMLGeometryObjectHelper::_regHelperPlane(
3639 &VRMLGeometryObjectHelper::create,
3640 "Plane",
3641 NULL);
3645 //---------------------------------------------------------------------------
3646 // Class
3647 //---------------------------------------------------------------------------
3649 /*-------------------------------------------------------------------------*/
3650 /* Constructors */
3652 VRMLTextureHelper::VRMLTextureHelper(void) :
3653 Inherited (),
3655 _defaultRepeatS(),
3656 _defaultRepeatT(),
3658 _repeatS (),
3659 _repeatT ()
3663 /*-------------------------------------------------------------------------*/
3664 /* Destructor */
3666 VRMLTextureHelper::~VRMLTextureHelper(void)
3670 /*-------------------------------------------------------------------------*/
3671 /* Helper */
3673 /*-------------------------------------------------------------------------*/
3674 /* Field */
3676 bool VRMLTextureHelper::prototypeAddField(const Char8 *,
3677 const UInt32 ,
3678 const Char8 *szFieldname)
3680 bool bFound = false;
3682 if(osgStringCaseCmp("repeatS", szFieldname) == 0)
3684 bFound = true;
3686 else if(osgStringCaseCmp("repeatT", szFieldname) == 0)
3688 bFound = true;
3691 if(bFound == true)
3693 #ifdef OSG_DEBUG_VRML
3694 indentLog(getIndent(), PINFO);
3695 PINFO << "ImageTextureDesc::prototypeAddField : add part "
3696 << szFieldname
3697 << std::endl;
3698 #endif
3700 return true;
3702 else
3704 return false;
3709 void VRMLTextureHelper::getFieldAndDesc(
3710 FieldContainer *,
3711 const Char8 * szFieldname,
3712 FieldContainer *&pFieldFC,
3713 EditFieldHandlePtr &pField,
3714 const FieldDescriptionBase *&pDesc)
3716 pFieldFC = NULL;
3717 pField.reset();
3718 pDesc = NULL;
3720 if(osgStringCaseCmp("repeatS", szFieldname) == 0)
3722 if(_bProtoInterfaceDone == false)
3724 pField = _sfBoolDesc.createEditHandler(&_defaultRepeatS,
3725 NULL );
3727 else
3729 pField = _sfBoolDesc.createEditHandler(&_repeatS,
3730 NULL );
3733 pDesc = &_sfBoolDesc;
3735 else if(osgStringCaseCmp("repeatT", szFieldname) == 0)
3737 if(_bProtoInterfaceDone == false)
3739 pField = _sfBoolDesc.createEditHandler(&_defaultRepeatT,
3740 NULL );
3742 else
3744 pField = _sfBoolDesc.createEditHandler(&_repeatT,
3745 NULL );
3748 pDesc = &_sfBoolDesc;
3752 /*-------------------------------------------------------------------------*/
3753 /* Node */
3755 FieldContainerTransitPtr VRMLTextureHelper::beginNode(
3756 const Char8 *,
3757 const Char8 *,
3758 FieldContainer *)
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")
3766 << std::endl;
3768 incIndent();
3769 #endif
3771 _repeatS = _defaultRepeatS;
3772 _repeatT = _defaultRepeatT;
3774 return FieldContainerTransitPtr(returnValue);
3777 void VRMLTextureHelper::endNode(FieldContainer *pFC)
3779 #if 0
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;
3794 #endif
3796 #ifdef OSG_VRML_IMAGETEXTURE_MAP
3797 UrlImageMap::iterator mIt = _urlImageMap.find(_url[i]);
3799 if(mIt != _urlImageMap.end())
3801 pImage = mIt->second;
3803 else
3805 pImage = ImageFileHandler::the()->read(_url[i].c_str());
3807 if(pImage != NULL)
3809 _urlImageMap[_url[i]] = pImage;
3812 #else
3813 pImage = ImageFileHandler::the()->read(_url[0].c_str());
3814 #endif
3816 if(pImage != NULL)
3817 break;
3820 if(pImage != NULL)
3822 pImage->setForceAlphaBinary(pImage->calcIsAlphaBinary());
3824 pTexture->setImage(pImage);
3826 if(_repeatS.getValue() == true)
3828 pTexture->setWrapS(GL_REPEAT);
3830 else
3832 pTexture->setWrapS(GL_CLAMP_TO_EDGE);
3834 if(_repeatT.getValue() == true)
3836 pTexture->setWrapT(GL_REPEAT);
3838 else
3840 pTexture->setWrapT(GL_CLAMP_TO_EDGE);
3843 else
3845 PWARNING << "VRMLImageTextureDesc::endNode : "
3846 << "Couldn't read texture "
3847 << _url[0].c_str()
3848 << " !!!"
3849 << std::endl;
3852 else
3854 PWARNING << "VRMLImageTextureDesc::endNode : Invalid texture ptr"
3855 << std::endl;
3858 #ifdef OSG_DEBUG_VRML
3859 decIndent();
3861 indentLog(getIndent(), PINFO);
3862 PINFO << "End ImageTexture "
3863 << _url[0].c_str() << " "
3864 << _repeatS.getValue() << " "
3865 << _repeatT.getValue() << " "
3866 << &(*pFC) << std::endl;
3867 #endif
3868 #endif
3871 /*-------------------------------------------------------------------------*/
3872 /* Dump */
3874 void VRMLTextureHelper::dump(const Char8 *)
3881 //---------------------------------------------------------------------------
3882 // Class
3883 //---------------------------------------------------------------------------
3885 VRMLNodeHelper *VRMLImageTextureHelper::create(void)
3887 return new VRMLImageTextureHelper();
3890 /*-------------------------------------------------------------------------*/
3891 /* Constructors */
3893 VRMLImageTextureHelper::VRMLImageTextureHelper(void) :
3894 Inherited (),
3896 _defaultURL (),
3897 _url ()
3899 #ifdef OSG_VRML_IMAGETEXTURE_MAP
3900 , _urlImageMap ()
3901 #endif
3905 /*-------------------------------------------------------------------------*/
3906 /* Destructor */
3908 VRMLImageTextureHelper::~VRMLImageTextureHelper(void)
3912 /*-------------------------------------------------------------------------*/
3913 /* Helper */
3915 /*-------------------------------------------------------------------------*/
3916 /* Field */
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)
3926 bFound = true;
3928 else
3930 bFound = Inherited::prototypeAddField(szFieldType,
3931 uiFieldTypeId,
3932 szFieldname);
3935 if(bFound == true)
3937 #ifdef OSG_DEBUG_VRML
3938 indentLog(getIndent(), PINFO);
3939 PINFO << "ImageTextureDesc::prototypeAddField : add part "
3940 << szFieldname
3941 << std::endl;
3942 #endif
3944 return true;
3946 else
3948 return false;
3953 void VRMLImageTextureHelper::getFieldAndDesc(
3954 FieldContainer * pFC,
3955 const Char8 * szFieldname,
3956 FieldContainer *&pFieldFC,
3957 EditFieldHandlePtr &pField,
3958 const FieldDescriptionBase *&pDesc)
3960 pFieldFC = NULL;
3961 pField.reset();
3962 pDesc = NULL;
3964 if(osgStringCaseCmp("url", szFieldname) == 0)
3966 if(_bProtoInterfaceDone == false)
3968 pField = _mfStringDesc.createEditHandler(&_defaultURL,
3969 NULL );
3971 else
3973 pField = _mfStringDesc.createEditHandler(&_url,
3974 NULL);
3977 pDesc = &_mfStringDesc;
3979 else
3981 Inherited::getFieldAndDesc(pFC,
3982 szFieldname,
3983 pFieldFC,
3984 pField,
3985 pDesc);
3989 /*-------------------------------------------------------------------------*/
3990 /* Node */
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")
4004 << std::endl;
4006 incIndent();
4007 #endif
4009 _url.clear();
4011 return returnValue;
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;
4031 #endif
4033 #ifdef OSG_VRML_IMAGETEXTURE_MAP
4034 UrlImageMap::iterator mIt = _urlImageMap.find(_url[i]);
4036 if(mIt != _urlImageMap.end())
4038 pImage = mIt->second;
4040 else
4042 pImage = ImageFileHandler::the()->read(_url[i].c_str());
4044 if(pImage != NULL)
4046 _urlImageMap[_url[i]] = pImage;
4049 #else
4050 pImage = ImageFileHandler::the()->read(_url[0].c_str());
4051 #endif
4053 if(pImage != NULL)
4054 break;
4057 if(pImage != NULL)
4059 pImage->setForceAlphaBinary(pImage->calcIsAlphaBinary());
4061 pTexture->setImage(pImage);
4063 if(_repeatS.getValue() == true)
4065 pTexture->setWrapS(GL_REPEAT);
4067 else
4069 pTexture->setWrapS(GL_CLAMP_TO_EDGE);
4071 if(_repeatT.getValue() == true)
4073 pTexture->setWrapT(GL_REPEAT);
4075 else
4077 pTexture->setWrapT(GL_CLAMP_TO_EDGE);
4080 else
4082 PWARNING << "VRMLImageTextureDesc::endNode : "
4083 << "Couldn't read texture "
4084 << _url[0].c_str()
4085 << " !!!"
4086 << std::endl;
4089 else
4091 PWARNING << "VRMLImageTextureDesc::endNode : Invalid texture ptr"
4092 << std::endl;
4095 #ifdef OSG_DEBUG_VRML
4096 decIndent();
4098 indentLog(getIndent(), PINFO);
4099 PINFO << "End ImageTexture "
4100 << _url[0].c_str() << " "
4101 << _repeatS.getValue() << " "
4102 << _repeatT.getValue() << " "
4103 << &(*pFC) << std::endl;
4104 #endif
4107 /*-------------------------------------------------------------------------*/
4108 /* Dump */
4110 void VRMLImageTextureHelper::dump(const Char8 *)
4115 VRMLNodeHelperFactoryBase::RegisterHelper VRMLImageTextureHelper::_regHelper(
4116 &VRMLImageTextureHelper::create,
4117 "ImageTexture",
4118 NULL);
4123 //---------------------------------------------------------------------------
4124 // Class
4125 //---------------------------------------------------------------------------
4127 VRMLNodeHelper *VRMLPixelTextureHelper::create(void)
4129 return new VRMLPixelTextureHelper();
4132 /*-------------------------------------------------------------------------*/
4133 /* Constructors */
4135 VRMLPixelTextureHelper::VRMLPixelTextureHelper(void) :
4136 Inherited( ),
4137 _pImage (NULL)
4141 /*-------------------------------------------------------------------------*/
4142 /* Destructor */
4144 VRMLPixelTextureHelper::~VRMLPixelTextureHelper(void)
4148 /*-------------------------------------------------------------------------*/
4149 /* Helper */
4151 void VRMLPixelTextureHelper::addImageValue(
4152 EditFieldHandlePtr ,
4153 const FieldDescriptionBase *,
4154 Image *pImage )
4156 _pImage = pImage;
4159 /*-------------------------------------------------------------------------*/
4160 /* Field */
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)
4170 bFound = true;
4172 else
4174 bFound = Inherited::prototypeAddField(szFieldType,
4175 uiFieldTypeId,
4176 szFieldname);
4179 if(bFound == true)
4181 #ifdef OSG_DEBUG_VRML
4182 indentLog(getIndent(), PINFO);
4183 PINFO << "ImageTextureDesc::prototypeAddField : add part "
4184 << szFieldname
4185 << std::endl;
4186 #endif
4188 return true;
4190 else
4192 return false;
4197 void VRMLPixelTextureHelper::getFieldAndDesc(
4198 FieldContainer * pFC,
4199 const Char8 * szFieldname,
4200 FieldContainer *&pFieldFC,
4201 EditFieldHandlePtr &pField,
4202 const FieldDescriptionBase *&pDesc)
4204 pFieldFC = NULL;
4205 pField.reset();
4206 pDesc = NULL;
4208 if(osgStringCaseCmp("image", szFieldname) == 0)
4210 pFieldFC = _pImage;
4211 pField.reset();
4212 pDesc = &_sfImagePtrDesc;
4214 else
4216 Inherited::getFieldAndDesc(pFC,
4217 szFieldname,
4218 pFieldFC,
4219 pField,
4220 pDesc);
4224 /*-------------------------------------------------------------------------*/
4225 /* Node */
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")
4239 << std::endl;
4241 incIndent();
4242 #endif
4244 return returnValue;
4247 void VRMLPixelTextureHelper::endNode(FieldContainer *pFC)
4249 TextureObjChunk *pTexture = NULL;
4251 pTexture = dynamic_cast<TextureObjChunk *>(pFC);
4254 if(pTexture != NULL)
4256 if(_pImage != NULL)
4258 _pImage->setForceAlphaBinary(_pImage->calcIsAlphaBinary());
4260 pTexture->setImage(_pImage);
4262 if(_repeatS.getValue() == true)
4264 pTexture->setWrapS(GL_REPEAT);
4266 else
4268 pTexture->setWrapS(GL_CLAMP_TO_EDGE);
4270 if(_repeatT.getValue() == true)
4272 pTexture->setWrapT(GL_REPEAT);
4274 else
4276 pTexture->setWrapT(GL_CLAMP_TO_EDGE);
4280 else
4282 PWARNING << "VRMLPixelTextureDesc::endNode : Invalid texture ptr"
4283 << std::endl;
4286 _pImage = NULL;
4288 #ifdef OSG_DEBUG_VRML
4289 decIndent();
4291 indentLog(getIndent(), PINFO);
4292 PINFO << "End PixelTexture "
4293 << _repeatS.getValue() << " "
4294 << _repeatT.getValue() << " "
4295 << &(*pFC) << std::endl;
4296 #endif
4299 /*-------------------------------------------------------------------------*/
4300 /* Dump */
4302 void VRMLPixelTextureHelper::dump(const Char8 *)
4307 VRMLNodeHelperFactoryBase::RegisterHelper VRMLPixelTextureHelper::_regHelper(
4308 &VRMLPixelTextureHelper::create,
4309 "PixelTexture",
4310 NULL);
4316 //---------------------------------------------------------------------------
4317 // Class
4318 //---------------------------------------------------------------------------
4320 VRMLNodeHelper *VRMLInlineHelper::create(void)
4322 return new VRMLInlineHelper();
4325 /*-------------------------------------------------------------------------*/
4326 /* Constructors */
4328 VRMLInlineHelper::VRMLInlineHelper(void) :
4329 Inherited()
4333 /*-------------------------------------------------------------------------*/
4334 /* Destructor */
4336 VRMLInlineHelper::~VRMLInlineHelper(void)
4340 /*-------------------------------------------------------------------------*/
4341 /* Helper */
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;
4350 #endif
4352 _pNodeProto = Node ::create();
4353 _pNodeCoreProto = Inline::create();
4355 _pGenAttProto = VRMLGenericAtt::createLocal(FCLocal::Cluster);
4356 _pGenAttProto->setInternal(true);
4359 /*-------------------------------------------------------------------------*/
4360 /* Field */
4362 void VRMLInlineHelper::endNode(FieldContainer *pFC)
4364 Node *pNode = dynamic_cast<Node *>(pFC);
4366 if(pNode != NULL)
4368 Inline *pInline = dynamic_cast<Inline *>(pNode->getCore());
4370 if(pInline != NULL)
4372 pInline->postOSGLoading(NULL);
4377 /*-------------------------------------------------------------------------*/
4378 /* Dump */
4380 void VRMLInlineHelper::dump(const Char8 *)
4385 VRMLNodeHelperFactoryBase::RegisterHelper VRMLInlineHelper::_regHelper(
4386 &VRMLInlineHelper::create,
4387 "Inline",
4388 NULL);
4393 //---------------------------------------------------------------------------
4394 // Class
4395 //---------------------------------------------------------------------------
4397 VRMLNodeHelper *VRMLSwitchHelper::create(void)
4399 return new VRMLSwitchHelper();
4403 /*-------------------------------------------------------------------------*/
4404 /* Constructors */
4406 VRMLSwitchHelper::VRMLSwitchHelper(void) :
4407 Inherited()
4411 /*-------------------------------------------------------------------------*/
4412 /* Destructor */
4414 VRMLSwitchHelper::~VRMLSwitchHelper(void)
4418 /*-------------------------------------------------------------------------*/
4419 /* Helper */
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;
4428 #endif
4430 _pNodeProto = Node ::create();
4431 _pNodeCoreProto = Switch::create();
4433 _pGenAttProto = VRMLGenericAtt::createLocal(FCLocal::Cluster);
4434 _pGenAttProto->setInternal(true);
4437 /*-------------------------------------------------------------------------*/
4438 /* Get */
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 : "
4449 << szFieldname
4450 << std::endl;
4451 #endif
4453 if(szFieldname == NULL)
4454 return false;
4456 incIndent();
4458 if(osgStringCaseCmp("choice", szFieldname) == 0)
4460 returnValue = true;
4462 #ifdef OSG_DEBUG_VRML
4463 indentLog(getIndent(), PINFO);
4464 PINFO << "VRMLSwitchHelper::prototypeAddField | request internal : "
4465 << szFieldname
4466 << " "
4467 << std::endl;
4468 #endif
4471 if(osgStringCaseCmp("whichChoice", szFieldname) == 0)
4473 returnValue = true;
4475 #ifdef OSG_DEBUG_VRML
4476 indentLog(getIndent(), PINFO);
4478 PINFO << "VRMLSwitchHelper::prototypeAddField | request internal : "
4479 << szFieldname
4480 << " "
4481 << std::endl;
4482 #endif
4485 if(returnValue == false)
4487 returnValue = Inherited::prototypeAddField(szFieldType,
4488 uiFieldTypeId,
4489 szFieldname);
4492 #ifdef OSG_DEBUG_VRML
4493 decIndent();
4494 #endif
4496 return returnValue;
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)
4507 return;
4509 if(pFC == NULL)
4511 if(_bProtoInterfaceDone == false)
4513 Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
4516 return;
4519 #ifdef OSG_DEBUG_VRML
4520 indentLog(getIndent(), PINFO);
4521 PINFO << "VRMLSwitchHelper::getFieldAndDesc : looking for "
4522 << szFieldname
4523 << std::endl;
4525 incIndent();
4526 #endif
4528 if(osgStringCaseCmp("choice", szFieldname) == 0)
4530 #ifdef OSG_DEBUG_VRML
4531 indentLog(getIndent(), PINFO);
4532 PINFO << "VRMLSwitchHelper::getFieldAndDesc : request internal "
4533 << szFieldname
4534 << std::endl;
4535 #endif
4536 pFieldFC = pFC;
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 "
4545 << szFieldname
4546 << std::endl;
4547 #endif
4549 Node *pNode = dynamic_cast<Node *>(pFC);
4551 if(pNode != NULL)
4553 if(pNode->getCore() != NULL)
4555 pFieldFC = pNode->getCore();
4556 pField = pNode->getCore()->editField("choice");
4557 pDesc = pNode->getCore()->getFieldDescription("choice");
4560 else
4562 Inherited::getFieldAndDesc(pFC,
4563 szFieldname,
4564 pFC,
4565 pField,
4566 pDesc);
4569 else
4571 Inherited::getFieldAndDesc(pFC,
4572 szFieldname,
4573 pFC,
4574 pField,
4575 pDesc);
4578 #ifdef OSG_DEBUG_VRML
4579 decIndent();
4580 #endif
4583 /*-------------------------------------------------------------------------*/
4584 /* Node */
4587 /*-------------------------------------------------------------------------*/
4588 /* Dump */
4590 void VRMLSwitchHelper::dump(const Char8 *)
4594 VRMLNodeHelperFactoryBase::RegisterHelper VRMLSwitchHelper::_regHelper(
4595 &VRMLSwitchHelper::create,
4596 "Switch",
4597 NULL);
4600 //---------------------------------------------------------------------------
4601 // Generic Helper with 1:1 mapping
4602 //---------------------------------------------------------------------------
4604 OSG_INST_GENERICVRMLHELPER(TimeSensor);
4606 template<>
4607 bool VRMLGenericHelper<TimeSensor>::initStatic(void)
4609 return true;
4612 template<>
4613 VRMLNodeHelperFactoryBase::RegisterHelper
4614 VRMLGenericHelper<TimeSensor>::_regHelper(
4615 &VRMLGenericHelper<TimeSensor>::create,
4616 "TimeSensor",
4617 &VRMLGenericHelper<TimeSensor>::initStatic);
4619 OSG_INST_GENERICVRMLHELPER(VRMLOrientationInterpolator);
4621 template<>
4622 bool VRMLGenericHelper<VRMLOrientationInterpolator>::initStatic(void)
4624 _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
4625 _mFieldNameMap[std::string("value" )] = std::string("outValue");
4627 return true;
4630 template<>
4631 VRMLNodeHelperFactoryBase::RegisterHelper
4632 VRMLGenericHelper<VRMLOrientationInterpolator>::_regHelper(
4633 &VRMLGenericHelper<VRMLOrientationInterpolator>::create,
4634 "OrientationInterpolator",
4635 &VRMLGenericHelper<VRMLOrientationInterpolator>::initStatic);
4638 OSG_INST_GENERICVRMLHELPER(VRMLPositionInterpolator);
4640 template<>
4641 bool VRMLGenericHelper<VRMLPositionInterpolator>::initStatic(void)
4643 _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
4644 _mFieldNameMap[std::string("value" )] = std::string("outValue");
4646 return true;
4649 template<>
4650 VRMLNodeHelperFactoryBase::RegisterHelper
4651 VRMLGenericHelper<VRMLPositionInterpolator>::_regHelper(
4652 &VRMLGenericHelper<VRMLPositionInterpolator>::create,
4653 "PositionInterpolator",
4654 &VRMLGenericHelper<VRMLPositionInterpolator>::initStatic);
4656 OSG_INST_GENERICVRMLHELPER(VRMLCoordinateInterpolator);
4658 template<>
4659 bool VRMLGenericHelper<VRMLCoordinateInterpolator>::initStatic(void)
4661 _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
4662 _mFieldNameMap[std::string("value" )] = std::string("outValue");
4664 return true;
4667 template<>
4668 VRMLNodeHelperFactoryBase::RegisterHelper
4669 VRMLGenericHelper<VRMLCoordinateInterpolator>::_regHelper(
4670 &VRMLGenericHelper<VRMLCoordinateInterpolator>::create,
4671 "CoordinateInterpolator",
4672 &VRMLGenericHelper<VRMLCoordinateInterpolator>::initStatic);
4674 OSG_INST_GENERICVRMLHELPER(VRMLNormalInterpolator);
4676 template<>
4677 bool VRMLGenericHelper<VRMLNormalInterpolator>::initStatic(void)
4679 _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
4680 _mFieldNameMap[std::string("value" )] = std::string("outValue");
4682 return true;
4685 template<>
4686 VRMLNodeHelperFactoryBase::RegisterHelper
4687 VRMLGenericHelper<VRMLNormalInterpolator>::_regHelper(
4688 &VRMLGenericHelper<VRMLNormalInterpolator>::create,
4689 "NormalInterpolator",
4690 &VRMLGenericHelper<VRMLNormalInterpolator>::initStatic);
4692 OSG_INST_GENERICVRMLHELPER(VRMLScalarInterpolator);
4694 template<>
4695 bool VRMLGenericHelper<VRMLScalarInterpolator>::initStatic(void)
4697 _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
4698 _mFieldNameMap[std::string("value" )] = std::string("outValue");
4700 return true;
4703 template<>
4704 VRMLNodeHelperFactoryBase::RegisterHelper
4705 VRMLGenericHelper<VRMLScalarInterpolator>::_regHelper(
4706 &VRMLGenericHelper<VRMLScalarInterpolator>::create,
4707 "ScalarInterpolator",
4708 &VRMLGenericHelper<VRMLScalarInterpolator>::initStatic);
4710 OSG_END_NAMESPACE