PageRenderTime 69ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/Source/System/FileIO/WRL/OSGVRMLNodeHelper.cpp

https://github.com/danguilliams/OpenSGDevMaster_Toolbox
C++ | 4404 lines | 3225 code | 852 blank | 327 comment | 650 complexity | 62a20f49afd395153da1be6af612e5b8 MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause
  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. \*---------------------------------------------------------------------------*/
  38. #include <cstdlib>
  39. #include <cstdio>
  40. #include "OSGConfig.h"
  41. #include <iostream>
  42. #include <fstream>
  43. #include "OSGVRMLNodeHelper.h"
  44. #include "OSGSingletonHolder.ins"
  45. #include "OSGScanParseSkel.h"
  46. #include "OSGSceneFileHandler.h"
  47. #include "OSGNameAttachment.h"
  48. #include "OSGNode.h"
  49. #include "OSGGroup.h"
  50. #include "OSGMaterialGroup.h"
  51. #include "OSGChunkMaterial.h"
  52. #include "OSGGeometry.h"
  53. #include "OSGGeoFunctions.h"
  54. #include "OSGChunkMaterial.h"
  55. #include "OSGMaterialChunk.h"
  56. #include "OSGBlendChunk.h"
  57. #include "OSGTextureObjChunk.h"
  58. #include "OSGTextureEnvChunk.h"
  59. #include "OSGImageFileHandler.h"
  60. #include "OSGSimpleGeometry.h"
  61. #include "OSGComponentTransform.h"
  62. #include "OSGInline.h"
  63. #include "OSGSwitch.h"
  64. #include "OSGTimeSensor.h"
  65. #include "OSGVRMLOrientationInterpolator.h"
  66. #include "OSGVRMLPositionInterpolator.h"
  67. #include "OSGVRMLCoordinateInterpolator.h"
  68. #include "OSGVRMLScalarInterpolator.h"
  69. #ifndef OSG_LOG_MODULE
  70. #define OSG_LOG_MODULE "VRMLLoader"
  71. #endif
  72. #define OSG_DEBUG_VRML
  73. #ifndef OSG_DO_DOC
  74. # ifdef OSG_DEBUG_VRML
  75. # define OSG_VRML_ARG(ARG) ARG
  76. # else
  77. # define OSG_VRML_ARG(ARG)
  78. # endif
  79. #else
  80. # define OSG_VRML_ARG(ARG) ARG
  81. #endif
  82. OSG_BEGIN_NAMESPACE
  83. OSG_DYNFIELDATTACHMENT_INST(VRMLGenericAttDesc)
  84. OSG_SINGLETON_INST(VRMLNodeHelperFactoryBase, addPostFactoryExitFunction)
  85. template class SingletonHolder<VRMLNodeHelperFactoryBase>;
  86. //---------------------------------------------------------------------------
  87. // Class
  88. //---------------------------------------------------------------------------
  89. VRMLNodeHelperFactoryBase::RegisterHelper::RegisterHelper(
  90. CreateHelper fCreate,
  91. const Char8 *szNodeName,
  92. InitFuncF fStaticInit)
  93. {
  94. VRMLNodeHelperFactory::the()->registerNodeHelper(fCreate,
  95. szNodeName);
  96. if(fStaticInit)
  97. addPostFactoryInitFunction(fStaticInit);
  98. }
  99. VRMLNodeHelperFactoryBase::VRMLNodeHelperFactoryBase(void) :
  100. _mRegisteredNodeHelperHash()
  101. {
  102. }
  103. VRMLNodeHelperFactoryBase::~VRMLNodeHelperFactoryBase(void)
  104. {
  105. }
  106. void VRMLNodeHelperFactoryBase::registerNodeHelper(
  107. CreateHelper fHelper,
  108. const Char8 *szNodeName)
  109. {
  110. if(szNodeName == NULL || fHelper == NULL)
  111. return;
  112. NameHelperCreateMap::iterator mNodeHelperIt =
  113. _mRegisteredNodeHelperHash.find(szNodeName);
  114. if(mNodeHelperIt == _mRegisteredNodeHelperHash.end())
  115. {
  116. _mRegisteredNodeHelperHash[szNodeName] = fHelper;
  117. PINFO << "Helper registered for "
  118. << szNodeName
  119. << std::endl;
  120. }
  121. else
  122. {
  123. PWARNING << "Helper already registered for %s "
  124. << szNodeName
  125. << std::endl;
  126. }
  127. }
  128. VRMLNodeHelper *VRMLNodeHelperFactoryBase::createHelper(
  129. const Char8 *szNodeName)
  130. {
  131. if(szNodeName == NULL)
  132. return NULL;
  133. NameHelperCreateMap::iterator mNodeHelperIt =
  134. _mRegisteredNodeHelperHash.find(szNodeName);
  135. if(mNodeHelperIt != _mRegisteredNodeHelperHash.end())
  136. {
  137. return (*mNodeHelperIt).second();
  138. }
  139. else
  140. {
  141. return NULL;
  142. }
  143. }
  144. /*! \defgroup GrpSystemFileIOVRML VRML-specific File Input/Output
  145. \ingroup GrpSystemFileIO
  146. See \ref PageSystemFileIO for details.
  147. */
  148. //---------------------------------------------------------------------------
  149. // Class
  150. //---------------------------------------------------------------------------
  151. /*! \class OSG::VRMLNodeDesc
  152. \ingroup GrpSystemFileIOVRML
  153. General VRML Node description
  154. */
  155. UInt32 VRMLNodeHelper::_uiIndent = 0;
  156. /*-------------------------------------------------------------------------*/
  157. /* Static Get */
  158. UInt32 VRMLNodeHelper::getIndent(void)
  159. {
  160. return _uiIndent;
  161. }
  162. void VRMLNodeHelper::incIndent(void)
  163. {
  164. _uiIndent += 4;
  165. }
  166. void VRMLNodeHelper::decIndent(void)
  167. {
  168. if(_uiIndent < 4)
  169. {
  170. // PWARNING << "Indent smaller 4 decremented" << std::endl;
  171. _uiIndent = 4;
  172. }
  173. _uiIndent -= 4;
  174. }
  175. void VRMLNodeHelper::resetIndent(void)
  176. {
  177. _uiIndent = 0;
  178. }
  179. /*-------------------------------------------------------------------------*/
  180. /* Constructors */
  181. #define OSG_INIT_DESC(VAR, TYPE, NAME) \
  182. VAR(TYPE::getClassType(), \
  183. NAME, \
  184. "VRML Helper", \
  185. 0, \
  186. 0, \
  187. true, \
  188. Field::SFDefaultFlags, \
  189. static_cast<FieldEditMethodSig>(&Node::invalidEditField), \
  190. NULL)
  191. VRMLNodeHelper::VRMLNodeHelper(void) :
  192. _bProtoInterfaceDone(false ),
  193. _pGenAttProto (NULL ),
  194. _pNodeProto (NULL ),
  195. _pNodeCoreProto (NULL ),
  196. OSG_INIT_DESC(_sfVec3fDesc,
  197. SFVec3f,
  198. "sfVec3fHelperDesc" ),
  199. OSG_INIT_DESC(_sfFCPtrDesc,
  200. SFUnrecFieldContainerPtr,
  201. "sfFCPtrHelperDesc" ),
  202. OSG_INIT_DESC(_sfImagePtrDesc,
  203. SFUnrecImagePtr,
  204. "sfImageHelperDesc" ),
  205. OSG_INIT_DESC(_sfReal32Desc,
  206. SFReal32,
  207. "sfReal32HelperDesc" ),
  208. OSG_INIT_DESC(_sfColor3fDesc,
  209. SFColor3f,
  210. "sfColor3fHelperDesc"),
  211. OSG_INIT_DESC(_mfStringDesc,
  212. MFString,
  213. "mfStringHelperDesc" ),
  214. OSG_INIT_DESC(_sfBoolDesc,
  215. SFBool,
  216. "sfBoolDesc" )
  217. {
  218. }
  219. /*-------------------------------------------------------------------------*/
  220. /* Destructor */
  221. VRMLNodeHelper::~VRMLNodeHelper(void)
  222. {
  223. _pNodeProto = NULL;
  224. _pNodeCoreProto = NULL;
  225. _pGenAttProto = NULL;
  226. }
  227. /*-------------------------------------------------------------------------*/
  228. /* Helper */
  229. void VRMLNodeHelper::reset(void)
  230. {
  231. }
  232. /*-------------------------------------------------------------------------*/
  233. /* Field */
  234. FieldContainerTransitPtr VRMLNodeHelper::beginNode(
  235. const Char8 *szTypename,
  236. const Char8 *szName,
  237. FieldContainer *pCurrentFC)
  238. {
  239. FieldContainerUnrecPtr returnValue = NULL;
  240. NodeUnrecPtr pNode = NULL;
  241. NodeCoreUnrecPtr pCore = NULL;
  242. VRMLGenericAttUnrecPtr pAtt = NULL;
  243. if(_pNodeProto != NULL)
  244. {
  245. returnValue = _pNodeProto->shallowCopy();
  246. if(_pNodeCoreProto != NULL)
  247. {
  248. FieldContainerTransitPtr pCoreClone
  249. = _pNodeCoreProto->shallowCopy();
  250. pNode = dynamic_pointer_cast<Node >(returnValue);
  251. pCore = dynamic_pointer_cast<NodeCore>(pCoreClone );
  252. pNode->setCore(pCore);
  253. }
  254. if(_pGenAttProto != NULL)
  255. {
  256. FieldContainer *pAttClone = _pGenAttProto->clone();
  257. pAtt = dynamic_cast<VRMLGenericAtt *>(pAttClone);
  258. pAtt->setVrmlNodeTypename(szTypename);
  259. OSG_ASSERT(pAttClone == pAtt);
  260. if(pAtt != NULL)
  261. {
  262. pAtt->setInternal(true);
  263. }
  264. if(pCore != NULL)
  265. {
  266. pCore->addAttachment(pAtt);
  267. }
  268. else
  269. {
  270. AttachmentContainer *pAttCnt =
  271. dynamic_pointer_cast<AttachmentContainer>(returnValue);
  272. if(pAttCnt != NULL)
  273. {
  274. pAttCnt->addAttachment(pAtt);
  275. }
  276. }
  277. }
  278. }
  279. return FieldContainerTransitPtr(returnValue);
  280. }
  281. void VRMLNodeHelper::endNode(FieldContainer *)
  282. {
  283. }
  284. void VRMLNodeHelper::mapFieldname(const std::string &, std::string &)
  285. {
  286. }
  287. /*-------------------------------------------------------------------------*/
  288. /* Prototypes */
  289. void VRMLNodeHelper::init(const Char8 *szName)
  290. {
  291. _bProtoInterfaceDone = false;
  292. }
  293. /*-------------------------------------------------------------------------*/
  294. /* Node */
  295. bool VRMLNodeHelper::prototypeAddField(const Char8 *szFieldType,
  296. const UInt32 uiFieldTypeId,
  297. const Char8 *szFieldName)
  298. {
  299. bool returnValue = false;
  300. GetFieldHandlePtr pField = getField(_pNodeProto,
  301. _pNodeCoreProto,
  302. _pGenAttProto,
  303. szFieldName);
  304. #ifdef OSG_DEBUG_VRML
  305. indentLog(getIndent(), PINFO);
  306. PINFO << "VRMLNodeDesc::prototypeAddField | getField "
  307. << szFieldName
  308. << " returned : "
  309. << pField
  310. << std::endl;
  311. #endif
  312. if(pField == NULL || pField->isValid() == false)
  313. {
  314. FieldDescriptionBase *pDesc = getFieldDescription(szFieldName,
  315. uiFieldTypeId);
  316. if(pDesc != NULL && _pGenAttProto != NULL)
  317. {
  318. _pGenAttProto->addField(*pDesc);
  319. pField = getField(_pNodeProto,
  320. _pNodeCoreProto,
  321. _pGenAttProto,
  322. szFieldName);
  323. delete pDesc;
  324. }
  325. #ifdef OSG_DEBUG_VRML
  326. indentLog(getIndent(), PINFO);
  327. PINFO << "VRMLNodeDesc::prototypeAddField | field added : "
  328. << szFieldType
  329. << " "
  330. << uiFieldTypeId
  331. << " "
  332. << szFieldName
  333. << " "
  334. << pField
  335. << std::endl;
  336. #endif
  337. returnValue = (pField != NULL && pField->isValid());
  338. }
  339. else
  340. {
  341. #ifdef OSG_DEBUG_VRML
  342. incIndent();
  343. indentLog(getIndent(), PINFO);
  344. #endif
  345. PINFO << "VRMLNodeDesc::prototypeAddField | "
  346. << "Could not add field "
  347. << szFieldName
  348. << " a second time"
  349. << std::endl;
  350. #ifdef OSG_DEBUG_VRML
  351. decIndent();
  352. #endif
  353. }
  354. return returnValue;
  355. }
  356. void VRMLNodeHelper::endProtoInterface(void)
  357. {
  358. _bProtoInterfaceDone = true;
  359. }
  360. /*-------------------------------------------------------------------------*/
  361. /* Dump */
  362. void VRMLNodeHelper::getFieldAndDesc( FieldContainer * pFC,
  363. const Char8 * szFieldname,
  364. FieldContainer *&pFieldFC,
  365. EditFieldHandlePtr &pField,
  366. const FieldDescriptionBase *&pDesc)
  367. {
  368. if(szFieldname == NULL)
  369. return;
  370. FieldContainer *pTmpFC = NULL;
  371. Node *pNode = NULL;
  372. NodeCore *pNodeCore = NULL;
  373. pFieldFC = NULL;
  374. pField.reset();
  375. pDesc = NULL;
  376. if(pFC == NULL)
  377. {
  378. if(_bProtoInterfaceDone == false)
  379. {
  380. getField(szFieldname, pFieldFC, pField, pDesc);
  381. }
  382. return;
  383. }
  384. #ifdef OSG_DEBUG_VRML
  385. indentLog(getIndent(), PINFO);
  386. PINFO << "VRMLNodeHelper::getFieldAndDesc : looking for "
  387. << szFieldname
  388. << std::endl;
  389. incIndent();
  390. #endif
  391. pDesc = pFC->getFieldDescription(szFieldname);
  392. if(pDesc != NULL)
  393. {
  394. pFieldFC = pFC;
  395. pField = pFC->editField(szFieldname);
  396. }
  397. else
  398. {
  399. if(pFC->getType().isNode() == true)
  400. {
  401. pNode = dynamic_cast<Node *>(pFC);
  402. pNodeCore = pNode->getCore();
  403. if(pNodeCore != NULL)
  404. {
  405. pDesc = pNodeCore->getFieldDescription(szFieldname);
  406. #ifdef OSG_DEBUG_VRML
  407. indentLog(getIndent(), PINFO);
  408. PINFO << "Got this from nodecore : "
  409. << pDesc
  410. << std::endl;
  411. #endif
  412. if(pDesc != NULL)
  413. {
  414. pFieldFC = pNodeCore;
  415. pField = pNodeCore->editField(szFieldname);
  416. }
  417. else
  418. {
  419. pTmpFC = pNode->findAttachment(
  420. VRMLGenericAtt::getClassType().getGroupId());
  421. if(pTmpFC != NULL)
  422. {
  423. pDesc = pTmpFC->getFieldDescription(szFieldname);
  424. }
  425. #ifdef OSG_DEBUG_VRML
  426. indentLog(getIndent(), PINFO);
  427. PINFO << "Got this from node attachment : "
  428. << pDesc << std::endl;
  429. #endif
  430. if(pDesc == NULL)
  431. {
  432. pTmpFC =
  433. pNodeCore->findAttachment(
  434. VRMLGenericAtt::getClassType().getGroupId());
  435. if(pTmpFC != NULL)
  436. {
  437. pDesc = pTmpFC->getFieldDescription(szFieldname);
  438. }
  439. #ifdef OSG_DEBUG_VRML
  440. indentLog(getIndent(), PINFO);
  441. PINFO << "Got this from nodecore attachment : "
  442. << pDesc << std::endl;
  443. #endif
  444. }
  445. if(pDesc != NULL)
  446. {
  447. pFieldFC = pTmpFC;
  448. pField = pTmpFC->editField(szFieldname);
  449. }
  450. }
  451. }
  452. else
  453. {
  454. if(pDesc == NULL)
  455. {
  456. pTmpFC =
  457. pNode->findAttachment(
  458. VRMLGenericAtt::getClassType().getGroupId());
  459. if(pTmpFC != NULL)
  460. {
  461. pDesc = pTmpFC->getFieldDescription(szFieldname);
  462. }
  463. #ifdef OSG_DEBUG_VRML
  464. indentLog(getIndent(), PINFO);
  465. PINFO << "Got this from node (no core) attachment : "
  466. << pDesc << std::endl;
  467. #endif
  468. }
  469. if(pDesc != NULL)
  470. {
  471. pFieldFC = pTmpFC;
  472. pField = pTmpFC->editField(szFieldname);
  473. }
  474. }
  475. }
  476. else if(pFC->getType().isNodeCore() == true)
  477. {
  478. pNodeCore = dynamic_cast<NodeCore *>(pFC);
  479. pTmpFC = pNodeCore->findAttachment(
  480. VRMLGenericAtt::getClassType().getGroupId());
  481. if(pTmpFC != NULL)
  482. {
  483. pDesc = pTmpFC->getFieldDescription(szFieldname);
  484. }
  485. if(pDesc != NULL)
  486. {
  487. pFieldFC = pTmpFC;
  488. pField = pTmpFC->editField(szFieldname);
  489. }
  490. #ifdef OSG_DEBUG_VRML
  491. indentLog(getIndent(), PINFO);
  492. PINFO << "Got this from nodecore attachment : "
  493. << pDesc << std::endl;
  494. #endif
  495. }
  496. }
  497. #ifdef OSG_DEBUG_VRML
  498. decIndent();
  499. #endif
  500. }
  501. GetFieldHandlePtr VRMLNodeHelper::getField( FieldContainer *pFC1,
  502. FieldContainer *pFC2,
  503. VRMLGenericAtt *pGenAtt,
  504. const Char8 *szFieldname)
  505. {
  506. GetFieldHandlePtr returnValue;
  507. if(szFieldname == NULL)
  508. {
  509. return returnValue;
  510. }
  511. #ifdef OSG_DEBUG_VRML
  512. indentLog(getIndent(), PINFO);
  513. PINFO << "VRMLNodeDesc::getField " << std::endl;
  514. incIndent();
  515. indentLog(getIndent(), PINFO);
  516. PINFO << "Trying to find field : " << szFieldname << std::endl;
  517. #endif
  518. if(pFC1 != NULL)
  519. {
  520. returnValue = pFC1->getField(szFieldname);
  521. }
  522. #ifdef OSG_DEBUG_VRML
  523. incIndent();
  524. indentLog(getIndent(), PINFO);
  525. PINFO << "Got this from node : " << returnValue << std::endl;
  526. #endif
  527. if(returnValue == NULL)
  528. {
  529. if(pFC2 != NULL)
  530. {
  531. returnValue = pFC2->getField(szFieldname);
  532. #ifdef OSG_DEBUG_VRML
  533. indentLog(getIndent(), PINFO);
  534. PINFO << "Got this from nodecore : " << returnValue << std::endl;
  535. #endif
  536. }
  537. else
  538. {
  539. #ifdef OSG_DEBUG_VRML
  540. indentLog(getIndent(), PINFO);
  541. PINFO << "No core to check" << std::endl;
  542. #endif
  543. }
  544. if(returnValue == NULL)
  545. {
  546. if(pGenAtt != NULL)
  547. {
  548. returnValue = pGenAtt->getField(szFieldname);
  549. }
  550. #ifdef OSG_DEBUG_VRML
  551. indentLog(getIndent(), PINFO);
  552. PINFO << "Got this from attachment : " << returnValue << std::endl;
  553. #endif
  554. }
  555. }
  556. #ifdef OSG_DEBUG_VRML
  557. decIndent();
  558. decIndent();
  559. #endif
  560. return returnValue;
  561. }
  562. void VRMLNodeHelper::getField(const Char8 * szFieldname,
  563. FieldContainer *&pFieldFC,
  564. EditFieldHandlePtr &pField,
  565. const FieldDescriptionBase *&pDesc )
  566. {
  567. pFieldFC = NULL;
  568. pField.reset();
  569. pDesc = NULL;
  570. if(szFieldname == NULL)
  571. {
  572. return;
  573. }
  574. #ifdef OSG_DEBUG_VRML
  575. indentLog(getIndent(), PINFO);
  576. PINFO << "VRMLNodeDesc::getField " << std::endl;
  577. incIndent();
  578. indentLog(getIndent(), PINFO);
  579. PINFO << "Trying to find field : " << szFieldname << std::endl;
  580. #endif
  581. if(_pNodeProto != NULL)
  582. {
  583. pFieldFC = _pNodeProto;
  584. pField = _pNodeProto->editField (szFieldname);
  585. pDesc = _pNodeProto->getFieldDescription(szFieldname);
  586. }
  587. #ifdef OSG_DEBUG_VRML
  588. incIndent();
  589. indentLog(getIndent(), PINFO);
  590. PINFO << "Got this from node : " << pDesc << " " << pField << std::endl;
  591. #endif
  592. if(pDesc == NULL)
  593. {
  594. if(_pNodeCoreProto != NULL)
  595. {
  596. pFieldFC = _pNodeCoreProto;
  597. pField = _pNodeCoreProto->editField (szFieldname);
  598. pDesc = _pNodeCoreProto->getFieldDescription(szFieldname);
  599. #ifdef OSG_DEBUG_VRML
  600. indentLog(getIndent(), PINFO);
  601. PINFO << "Got this from nodecore : "
  602. << pDesc
  603. << " "
  604. << pField
  605. << std::endl;
  606. #endif
  607. }
  608. else
  609. {
  610. #ifdef OSG_DEBUG_VRML
  611. indentLog(getIndent(), PINFO);
  612. PINFO << "No core to check" << std::endl;
  613. #endif
  614. }
  615. if(pDesc == NULL)
  616. {
  617. if(_pGenAttProto != NULL)
  618. {
  619. pFieldFC = _pGenAttProto;
  620. pField = _pGenAttProto->editField (szFieldname);
  621. pDesc = _pGenAttProto->getFieldDescription(szFieldname);
  622. }
  623. #ifdef OSG_DEBUG_VRML
  624. indentLog(getIndent(), PINFO);
  625. PINFO << "Got this from attachment : "
  626. << pDesc
  627. << " "
  628. << pField
  629. << std::endl;
  630. #endif
  631. }
  632. }
  633. if(pDesc == NULL)
  634. {
  635. pFieldFC = NULL;
  636. }
  637. #ifdef OSG_DEBUG_VRML
  638. decIndent();
  639. decIndent();
  640. #endif
  641. }
  642. // HACK Should be somewhere else and automatic
  643. #define OSG_CREATE_DESC(TYPE) new TYPE::Description( \
  644. TYPE::getClassType(), \
  645. szFieldName, \
  646. "", \
  647. 0, \
  648. 0, \
  649. false, \
  650. OSG::Field::SFDefaultFlags, \
  651. static_cast<OSG::FieldIndexEditMethodSig>( \
  652. &VRMLGenericAtt::editDynamicField), \
  653. static_cast<OSG::FieldIndexGetMethodSig >( \
  654. &VRMLGenericAtt::getDynamicField ))
  655. #define OSG_CREATE_DESC_ELSE(TYPE) \
  656. else if(uiFieldTypeId == TYPE::getClassType().getId()) \
  657. { \
  658. returnValue = OSG_CREATE_DESC(TYPE); \
  659. }
  660. #define OSG_CREATE_PTRDESC(TYPE) new TYPE::Description( \
  661. TYPE::getClassType(), \
  662. szFieldName, \
  663. "", \
  664. 0, \
  665. 0, \
  666. false, \
  667. (OSG::Field::SFDefaultFlags | Field::FStdAccess), \
  668. static_cast<OSG::FieldIndexEditMethodSig>( \
  669. &VRMLGenericAtt::editDynamicField), \
  670. static_cast<OSG::FieldIndexGetMethodSig >( \
  671. &VRMLGenericAtt::getDynamicField ))
  672. #define OSG_CREATE_PTRDESC_ELSE(TYPE) \
  673. else if(uiFieldTypeId == TYPE::getClassType().getId()) \
  674. { \
  675. returnValue = OSG_CREATE_PTRDESC(TYPE); \
  676. }
  677. FieldDescriptionBase *VRMLNodeHelper::getFieldDescription(
  678. const Char8 *szFieldName,
  679. const UInt32 uiFieldTypeId)
  680. {
  681. FieldDescriptionBase *returnValue = NULL;
  682. if(uiFieldTypeId == SFBool::getClassType().getId())
  683. {
  684. returnValue = OSG_CREATE_DESC(SFBool);
  685. }
  686. OSG_CREATE_DESC_ELSE(SFInt32)
  687. OSG_CREATE_DESC_ELSE(MFInt32)
  688. OSG_CREATE_DESC_ELSE(SFString)
  689. OSG_CREATE_DESC_ELSE(MFString)
  690. OSG_CREATE_DESC_ELSE(SFReal32)
  691. OSG_CREATE_DESC_ELSE(MFReal32)
  692. OSG_CREATE_DESC_ELSE(SFTime)
  693. OSG_CREATE_DESC_ELSE(MFTime)
  694. OSG_CREATE_DESC_ELSE(SFVec2s)
  695. OSG_CREATE_DESC_ELSE(MFVec2f)
  696. OSG_CREATE_DESC_ELSE(SFVec2f)
  697. OSG_CREATE_DESC_ELSE(MFPnt3f)
  698. OSG_CREATE_DESC_ELSE(SFPnt3f)
  699. OSG_CREATE_DESC_ELSE(MFVec3f)
  700. OSG_CREATE_DESC_ELSE(SFVec3f)
  701. OSG_CREATE_DESC_ELSE(MFColor3f)
  702. OSG_CREATE_DESC_ELSE(SFColor3f)
  703. OSG_CREATE_DESC_ELSE(MFQuaternion)
  704. OSG_CREATE_DESC_ELSE(SFQuaternion)
  705. OSG_CREATE_PTRDESC_ELSE(SFUnrecFieldContainerPtr)
  706. OSG_CREATE_PTRDESC_ELSE(MFUnrecFieldContainerPtr)
  707. OSG_CREATE_PTRDESC_ELSE(SFUnrecImagePtr)
  708. if(returnValue == NULL)
  709. {
  710. FWARNING(("could not create field desc for %s (%d)\n",
  711. szFieldName,
  712. uiFieldTypeId));
  713. }
  714. return returnValue;
  715. }
  716. void VRMLNodeHelper::addFieldValue( EditFieldHandlePtr pField,
  717. const FieldDescriptionBase *pFieldDesc,
  718. const Char8 *szFieldVal)
  719. {
  720. if(pField != NULL && pField->isValid() == true)
  721. {
  722. pField->pushValueFromCString(szFieldVal);
  723. }
  724. }
  725. void VRMLNodeHelper::addImageValue( EditFieldHandlePtr ,
  726. const FieldDescriptionBase *,
  727. Image * )
  728. {
  729. FWARNING(("addImageValue not caught, something is strange\n"));
  730. }
  731. void VRMLNodeHelper::setContainerFieldValue(
  732. FieldContainer *pFC,
  733. const FieldDescriptionBase *pFieldDesc,
  734. FieldContainer *pFieldFC )
  735. {
  736. if((pFieldDesc != NULL ) &&
  737. (pFieldFC != NULL) )
  738. {
  739. FieldContainerPtrSFieldBase::EditHandlePtr pSFHandle =
  740. boost::dynamic_pointer_cast<
  741. FieldContainerPtrSFieldBase::EditHandle>(
  742. pFieldFC->editField(pFieldDesc->getFieldId()));
  743. FieldContainerPtrMFieldBase::EditHandlePtr pMFHandle =
  744. boost::dynamic_pointer_cast<
  745. FieldContainerPtrMFieldBase::EditHandle>(
  746. pFieldFC->editField(pFieldDesc->getFieldId()));
  747. if(pSFHandle != NULL && pSFHandle->isValid())
  748. {
  749. pSFHandle->set(pFC);
  750. }
  751. else if(pMFHandle != NULL && pMFHandle->isValid())
  752. {
  753. pMFHandle->add(pFC);
  754. }
  755. /*
  756. pFieldFC->pushToField(pFC,
  757. pFieldDesc->getFieldId());
  758. */
  759. }
  760. }
  761. /*-------------------------------------------------------------------------*/
  762. /* Get */
  763. //---------------------------------------------------------------------------
  764. // Class
  765. //---------------------------------------------------------------------------
  766. /*! \class OSG::VRMLDefaultHelper
  767. \ingroup GrpSystemFileIOVRML
  768. VRML Group description
  769. */
  770. VRMLNodeHelper *VRMLDefaultHelper::create(void)
  771. {
  772. return new VRMLDefaultHelper();
  773. }
  774. /*-------------------------------------------------------------------------*/
  775. /* Constructors */
  776. VRMLDefaultHelper::VRMLDefaultHelper(void) :
  777. Inherited()
  778. {
  779. }
  780. /*-------------------------------------------------------------------------*/
  781. /* Destructor */
  782. VRMLDefaultHelper::~VRMLDefaultHelper(void)
  783. {
  784. }
  785. /*-------------------------------------------------------------------------*/
  786. /* Helper */
  787. void VRMLDefaultHelper::init(const Char8 *szName)
  788. {
  789. Inherited::init(szName);
  790. #ifdef OSG_DEBUG_VRML
  791. indentLog(getIndent(), PINFO);
  792. PINFO << "GroupHelper::init : " << szName << std::endl;
  793. #endif
  794. _pNodeProto = Node ::create();
  795. _pNodeCoreProto = Group::create();
  796. _pGenAttProto = VRMLGenericAtt::create();
  797. _pGenAttProto->setInternal(true);
  798. }
  799. FieldContainerTransitPtr VRMLDefaultHelper::beginNode(
  800. const Char8 *szTypename,
  801. const Char8 *szName,
  802. FieldContainer *pCurrentFC)
  803. {
  804. FWARNING(("Use default helper for %s, functionality currently not "
  805. "supported\n", szTypename));
  806. return Inherited::beginNode(szTypename, szName, pCurrentFC);
  807. }
  808. /*-------------------------------------------------------------------------*/
  809. /* Dump */
  810. void VRMLDefaultHelper::dump(const Char8 *)
  811. {
  812. }
  813. //---------------------------------------------------------------------------
  814. // Generic Helper with 1:1 mapping
  815. //---------------------------------------------------------------------------
  816. template<>
  817. VRMLNodeHelperFactoryBase::RegisterHelper
  818. VRMLGenericHelper<Group>::_regHelper(
  819. &VRMLGenericHelper<Group>::create,
  820. "Group",
  821. NULL);
  822. OSG_INST_GENERICVRMLHELPER(Group);
  823. template<>
  824. VRMLNodeHelperFactoryBase::RegisterHelper
  825. VRMLGenericHelper<ComponentTransform>::_regHelper(
  826. &VRMLGenericHelper<ComponentTransform>::create,
  827. "Transform",
  828. NULL);
  829. OSG_INST_GENERICVRMLHELPER(ComponentTransform);
  830. //---------------------------------------------------------------------------
  831. // Class
  832. //---------------------------------------------------------------------------
  833. /*! \class OSG::VRMLMaterialDesc
  834. \ingroup GrpSystemFileIOVRML
  835. VRML Material description
  836. */
  837. VRMLNodeHelper *VRMLMaterialHelper::create(void)
  838. {
  839. return new VRMLMaterialHelper();
  840. }
  841. /*-------------------------------------------------------------------------*/
  842. /* Constructors */
  843. VRMLMaterialHelper::VRMLMaterialHelper(void) :
  844. Inherited ( ),
  845. _defaultAmbientIntensity(),
  846. _defaultDiffuseColor (),
  847. _defaultEmissiveColor (),
  848. _defaultShininess (),
  849. _defaultSpecularColor (),
  850. _defaultTransparency (),
  851. _ambientIntensity (),
  852. _diffuseColor (),
  853. _emissiveColor (),
  854. _shininess (),
  855. _specularColor (),
  856. _transparency (),
  857. _pDefMat (NULL),
  858. _pMat (NULL),
  859. _szName ( )
  860. {
  861. }
  862. /*-------------------------------------------------------------------------*/
  863. /* Destructor */
  864. VRMLMaterialHelper::~VRMLMaterialHelper(void)
  865. {
  866. _pDefMat = NULL;
  867. }
  868. /*-------------------------------------------------------------------------*/
  869. /* Helper */
  870. void VRMLMaterialHelper::init(const Char8 *OSG_VRML_ARG(szName))
  871. {
  872. #ifdef OSG_DEBUG_VRML
  873. indentLog(getIndent(), PINFO);
  874. PINFO << "MaterialDesc::init : " << szName << std::endl;
  875. #endif
  876. }
  877. void VRMLMaterialHelper::reset(void)
  878. {
  879. _ambientIntensity.setValue(_defaultAmbientIntensity);
  880. _diffuseColor .setValue(_defaultDiffuseColor);
  881. _emissiveColor .setValue(_defaultEmissiveColor);
  882. _shininess .setValue(_defaultShininess);
  883. _specularColor .setValue(_defaultSpecularColor);
  884. _transparency .setValue(_defaultTransparency);
  885. _szName .erase ();
  886. _pMat = NULL;
  887. }
  888. Material *VRMLMaterialHelper::getDefaultMaterial(void)
  889. {
  890. return _pDefMat;
  891. }
  892. /*-------------------------------------------------------------------------*/
  893. /* Field */
  894. bool VRMLMaterialHelper::prototypeAddField(const Char8 *,
  895. const UInt32 ,
  896. const Char8 *szFieldname)
  897. {
  898. bool bFound = false;
  899. if(osgStringCaseCmp("ambientIntensity", szFieldname) == 0)
  900. {
  901. bFound = true;
  902. }
  903. else if(osgStringCaseCmp("diffuseColor", szFieldname) == 0)
  904. {
  905. bFound = true;
  906. }
  907. else if(osgStringCaseCmp("emissiveColor", szFieldname) == 0)
  908. {
  909. bFound = true;
  910. }
  911. else if(osgStringCaseCmp("shininess", szFieldname) == 0)
  912. {
  913. bFound = true;
  914. }
  915. else if(osgStringCaseCmp("specularColor", szFieldname) == 0)
  916. {
  917. bFound = true;
  918. }
  919. else if(osgStringCaseCmp("transparency", szFieldname) == 0)
  920. {
  921. bFound = true;
  922. }
  923. if(bFound == true)
  924. {
  925. #ifdef OSG_DEBUG_VRML
  926. indentLog(getIndent(), PINFO);
  927. PINFO << "MaterialDesc::prototypeAddField : add part "
  928. << szFieldname
  929. << std::endl;
  930. #endif
  931. return true;
  932. }
  933. else
  934. {
  935. return false;
  936. }
  937. }
  938. void VRMLMaterialHelper::endProtoInterface(void)
  939. {
  940. Color4f cCol;
  941. MaterialChunkUnrecPtr pMatChunk;
  942. cCol.setValuesRGBA(_defaultDiffuseColor .getValue().red() *
  943. _defaultAmbientIntensity.getValue(),
  944. _defaultDiffuseColor .getValue().green() *
  945. _defaultAmbientIntensity.getValue(),
  946. _defaultDiffuseColor .getValue().blue() *
  947. _defaultAmbientIntensity.getValue(),
  948. 1.f - _defaultTransparency .getValue());
  949. _pDefMat = ChunkMaterial::create();
  950. pMatChunk = MaterialChunk::create();
  951. pMatChunk->setAmbient(cCol);
  952. cCol.setValuesRGBA (_defaultDiffuseColor.getValue()[0],
  953. _defaultDiffuseColor.getValue()[1],
  954. _defaultDiffuseColor.getValue()[2],
  955. 1.f - _defaultTransparency.getValue());
  956. pMatChunk->setDiffuse(cCol);
  957. cCol.setValuesRGBA (_defaultSpecularColor.getValue()[0],
  958. _defaultSpecularColor.getValue()[1],
  959. _defaultSpecularColor.getValue()[2],
  960. 1.f - _defaultTransparency.getValue());
  961. pMatChunk->setSpecular(cCol);
  962. pMatChunk->setShininess(_defaultShininess.getValue() * 128.f);
  963. cCol.setValuesRGBA (_defaultEmissiveColor.getValue()[0],
  964. _defaultEmissiveColor.getValue()[1],
  965. _defaultEmissiveColor.getValue()[2],
  966. 1.f - _defaultTransparency.getValue());
  967. pMatChunk->setEmission(cCol);
  968. _pDefMat->addChunk(pMatChunk);
  969. Inherited::endProtoInterface();
  970. }
  971. void VRMLMaterialHelper::getFieldAndDesc(
  972. FieldContainer *,
  973. const Char8 * szFieldname,
  974. FieldContainer *&pFieldFC,
  975. EditFieldHandlePtr &pField,
  976. const FieldDescriptionBase *&pDesc)
  977. {
  978. pFieldFC = NULL;
  979. pField.reset();
  980. pDesc = NULL;
  981. if(osgStringCaseCmp("ambientIntensity", szFieldname) == 0)
  982. {
  983. pFieldFC = NULL;
  984. if(_bProtoInterfaceDone == false)
  985. {
  986. pField =
  987. _sfReal32Desc.createEditHandler(&_defaultAmbientIntensity,
  988. NULL );
  989. }
  990. else
  991. {
  992. pField = _sfReal32Desc.createEditHandler(&_ambientIntensity,
  993. NULL );
  994. }
  995. pDesc = &_sfReal32Desc;
  996. }
  997. else if(osgStringCaseCmp("diffuseColor", szFieldname) == 0)
  998. {
  999. pFieldFC = NULL;
  1000. if(_bProtoInterfaceDone == false)
  1001. {
  1002. pField = _sfColor3fDesc.createEditHandler(&_defaultDiffuseColor,
  1003. NULL );
  1004. }
  1005. else
  1006. {
  1007. pField = _sfColor3fDesc.createEditHandler(&_diffuseColor,
  1008. NULL );
  1009. }
  1010. pDesc = &_sfColor3fDesc;
  1011. }
  1012. else if(osgStringCaseCmp("emissiveColor", szFieldname) == 0)
  1013. {
  1014. pFieldFC = NULL;
  1015. if(_bProtoInterfaceDone == false)
  1016. {
  1017. pField = _sfColor3fDesc.createEditHandler(&_defaultEmissiveColor,
  1018. NULL );
  1019. }
  1020. else
  1021. {
  1022. pField = _sfColor3fDesc.createEditHandler(&_emissiveColor,
  1023. NULL );
  1024. }
  1025. pDesc = &_sfColor3fDesc;
  1026. }
  1027. else if(osgStringCaseCmp("shininess", szFieldname) == 0)
  1028. {
  1029. pFieldFC = NULL;
  1030. if(_bProtoInterfaceDone == false)
  1031. {
  1032. pField = _sfReal32Desc.createEditHandler(&_defaultShininess,
  1033. NULL );
  1034. }
  1035. else
  1036. {
  1037. pField = _sfReal32Desc.createEditHandler(&_shininess,
  1038. NULL );
  1039. }
  1040. pDesc = &_sfReal32Desc;
  1041. }
  1042. else if(osgStringCaseCmp("specularColor", szFieldname) == 0)
  1043. {
  1044. pFieldFC = NULL;
  1045. if(_bProtoInterfaceDone == false)
  1046. {
  1047. pField = _sfColor3fDesc.createEditHandler(&_defaultSpecularColor,
  1048. NULL );
  1049. }
  1050. else
  1051. {
  1052. pField = _sfColor3fDesc.createEditHandler(&_specularColor,
  1053. NULL );
  1054. }
  1055. pDesc = &_sfColor3fDesc;
  1056. }
  1057. else if(osgStringCaseCmp("transparency", szFieldname) == 0)
  1058. {
  1059. pFieldFC = NULL;
  1060. if(_bProtoInterfaceDone == false)
  1061. {
  1062. pField = _sfReal32Desc.createEditHandler(&_defaultTransparency,
  1063. NULL );
  1064. }
  1065. else
  1066. {
  1067. pField = _sfReal32Desc.createEditHandler(&_transparency,
  1068. NULL );
  1069. }
  1070. pDesc = &_sfReal32Desc;
  1071. }
  1072. }
  1073. /*-------------------------------------------------------------------------*/
  1074. /* Node */
  1075. FieldContainerTransitPtr VRMLMaterialHelper::beginNode(
  1076. const Char8 *,
  1077. const Char8 *szName,
  1078. FieldContainer * )
  1079. {
  1080. reset();
  1081. _pMat = MaterialChunk::create();
  1082. _szName = (szName != NULL) ? szName : "";
  1083. return FieldContainerTransitPtr(_pMat);
  1084. }
  1085. void VRMLMaterialHelper::endNode(FieldContainer *)
  1086. {
  1087. if(_pMat != NULL)
  1088. {
  1089. Color4f cCol;
  1090. cCol.setValuesRGBA (_diffuseColor .getValue().red() *
  1091. _ambientIntensity.getValue(),
  1092. _diffuseColor .getValue().green() *
  1093. _ambientIntensity.getValue(),
  1094. _diffuseColor .getValue().blue() *
  1095. _ambientIntensity.getValue(),
  1096. 1.f - _transparency.getValue());
  1097. _pMat->setAmbient (cCol);
  1098. cCol.setValuesRGBA (_diffuseColor.getValue()[0],
  1099. _diffuseColor.getValue()[1],
  1100. _diffuseColor.getValue()[2],
  1101. 1.f - _transparency.getValue());
  1102. _pMat->setDiffuse (cCol);
  1103. cCol.setValuesRGBA (_specularColor.getValue()[0],
  1104. _specularColor.getValue()[1],
  1105. _specularColor.getValue()[2],
  1106. 1.f - _transparency.getValue());
  1107. _pMat->setSpecular (cCol);
  1108. _pMat->setShininess(_shininess.getValue() * 128.f );
  1109. cCol.setValuesRGBA (_emissiveColor.getValue()[0],
  1110. _emissiveColor.getValue()[1],
  1111. _emissiveColor.getValue()[2],
  1112. 1.f - _transparency.getValue());
  1113. _pMat->setEmission (cCol);
  1114. }
  1115. }
  1116. /*-------------------------------------------------------------------------*/
  1117. /* Type Specific */
  1118. const std::string &VRMLMaterialHelper::getName(void) const
  1119. {
  1120. return _szName;
  1121. }
  1122. /*-------------------------------------------------------------------------*/
  1123. /* Dump */
  1124. void VRMLMaterialHelper::dump(const Char8 *)
  1125. {
  1126. }
  1127. VRMLNodeHelperFactoryBase::RegisterHelper VRMLMaterialHelper::_regHelper(
  1128. &VRMLMaterialHelper::create,
  1129. "Material",
  1130. NULL);
  1131. //---------------------------------------------------------------------------
  1132. // Class
  1133. //---------------------------------------------------------------------------
  1134. /*! \class OSG::VRMLShapeDesc
  1135. \ingroup GrpSystemFileIOVRML
  1136. VRML Shape description
  1137. */
  1138. VRMLNodeHelper *VRMLShapeHelper::create(void)
  1139. {
  1140. return new VRMLShapeHelper();
  1141. }
  1142. /*-------------------------------------------------------------------------*/
  1143. /* Constructors */
  1144. VRMLShapeHelper::VRMLShapeHelper(void) :
  1145. Inherited ( ),
  1146. _pMaterialHelper(NULL)
  1147. {
  1148. }
  1149. /*-------------------------------------------------------------------------*/
  1150. /* Destructor */
  1151. VRMLShapeHelper::~VRMLShapeHelper(void)
  1152. {
  1153. }
  1154. /*-------------------------------------------------------------------------*/
  1155. /* Helper */
  1156. void VRMLShapeHelper::init(const Char8 *szName)
  1157. {
  1158. Inherited::init(szName);
  1159. #ifdef OSG_DEBUG_VRML
  1160. indentLog(getIndent(), PINFO);
  1161. PINFO << "ShapeHelper::init : " << szName << std::endl;
  1162. #endif
  1163. _pNodeProto = Node ::create();
  1164. _pNodeCoreProto = MaterialGroup::create();
  1165. _pGenAttProto = VRMLGenericAtt::create();
  1166. _pGenAttProto->setInternal(true);
  1167. }
  1168. void VRMLShapeHelper::setMaterialHelper(VRMLMaterialHelper *pMaterialHelper)
  1169. {
  1170. _pMaterialHelper = pMaterialHelper;
  1171. }
  1172. /*-------------------------------------------------------------------------*/
  1173. /* Get */
  1174. bool VRMLShapeHelper::prototypeAddField(const Char8 *szFieldType,
  1175. const UInt32 uiFieldTypeId,
  1176. const Char8 *szFieldname)
  1177. {
  1178. bool returnValue = false;
  1179. #ifdef OSG_DEBUG_VRML
  1180. indentLog(getIndent(), PINFO);
  1181. PINFO << "VRMLShapeHelper::prototypeAddField | add request : "
  1182. << szFieldname
  1183. << std::endl;
  1184. #endif
  1185. if(szFieldname == NULL)
  1186. return false;
  1187. incIndent();
  1188. if(osgStringCaseCmp("geometry", szFieldname) == 0)
  1189. {
  1190. returnValue = true;
  1191. #ifdef OSG_DEBUG_VRML
  1192. indentLog(getIndent(), PINFO);
  1193. PINFO << "VRMLShapeHelper::prototypeAddField | request internal : "
  1194. << szFieldname
  1195. << " "
  1196. << std::endl;
  1197. #endif
  1198. }
  1199. if(osgStringCaseCmp("appearance", szFieldname) == 0)
  1200. {
  1201. returnValue = true;
  1202. #ifdef OSG_DEBUG_VRML
  1203. indentLog(getIndent(), PINFO);
  1204. PINFO << "VRMLShapeHelper::prototypeAddField | request internal : "
  1205. << szFieldname
  1206. << " "
  1207. << std::endl;
  1208. #endif
  1209. }
  1210. if(returnValue == false)
  1211. {
  1212. returnValue = Inherited::prototypeAddField(szFieldType,
  1213. uiFieldTypeId,
  1214. szFieldname);
  1215. }
  1216. #ifdef OSG_DEBUG_VRML
  1217. decIndent();
  1218. #endif
  1219. return returnValue;
  1220. }
  1221. void VRMLShapeHelper::getFieldAndDesc(
  1222. FieldContainer * pFC,
  1223. const Char8 * szFieldname,
  1224. FieldContainer *&pFieldFC,
  1225. EditFieldHandlePtr &pField,
  1226. const FieldDescriptionBase *&pDesc)
  1227. {
  1228. if(szFieldname == NULL)
  1229. return;
  1230. if(pFC == NULL)
  1231. {
  1232. if(_bProtoInterfaceDone == false)
  1233. {
  1234. Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
  1235. }
  1236. return;
  1237. }
  1238. #ifdef OSG_DEBUG_VRML
  1239. indentLog(getIndent(), PINFO);
  1240. PINFO << "VRMLShapeHelper::getFieldAndDesc : looking for "
  1241. << szFieldname
  1242. << std::endl;
  1243. incIndent();
  1244. #endif
  1245. if(osgStringCaseCmp("geometry", szFieldname) == 0)
  1246. {
  1247. #ifdef OSG_DEBUG_VRML
  1248. indentLog(getIndent(), PINFO);
  1249. PINFO << "VRMLShapeHelper::getFieldAndDesc : request internal "
  1250. << szFieldname
  1251. << std::endl;
  1252. #endif
  1253. pFieldFC = pFC;
  1254. pField = pFC->editField("children");
  1255. pDesc = pFC->getFieldDescription("children");
  1256. }
  1257. else if(osgStringCaseCmp("appearance", szFieldname) == 0)
  1258. {
  1259. #ifdef OSG_DEBUG_VRML
  1260. indentLog(getIndent(), PINFO);
  1261. PINFO << "VRMLShapeHelper::getFieldAndDesc : request internal "
  1262. << szFieldname
  1263. << std::endl;
  1264. #endif
  1265. Node *pNode = dynamic_cast<Node *>(pFC);
  1266. if(pNode != NULL)
  1267. {
  1268. if(pNode->getCore() != NULL)
  1269. {
  1270. pFieldFC = pNode->getCore();
  1271. pField = pNode->getCore()->editField("material");
  1272. pDesc = pNode->getCore()->getFieldDescription("material");
  1273. }
  1274. }
  1275. else
  1276. {
  1277. Inherited::getFieldAndDesc(pFC,
  1278. szFieldname,
  1279. pFC,
  1280. pField,
  1281. pDesc);
  1282. }
  1283. }
  1284. else
  1285. {
  1286. Inherited::getFieldAndDesc(pFC,
  1287. szFieldname,
  1288. pFC,
  1289. pField,
  1290. pDesc);
  1291. }
  1292. #ifdef OSG_DEBUG_VRML
  1293. decIndent();
  1294. #endif
  1295. }
  1296. /*-------------------------------------------------------------------------*/
  1297. /* Node */
  1298. void VRMLShapeHelper::endNode(FieldContainer *pFC)
  1299. {
  1300. if(pFC != NULL)
  1301. {
  1302. Node *pNode = dynamic_cast<Node *>(pFC);
  1303. if(pNode != NULL && pNode->getCore() == NULL)
  1304. {
  1305. PWARNING << "warning empty material, using default\n" << std::endl;
  1306. MaterialGroupUnrecPtr pMatGroup = MaterialGroup::create();
  1307. pMatGroup->setMaterial(_pMaterialHelper->getDefaultMaterial());
  1308. pNode->setCore(pMatGroup);
  1309. }
  1310. else
  1311. {
  1312. MaterialGroup *pMatGroup;
  1313. pMatGroup = dynamic_cast<MaterialGroup *>(pNode->getCore());
  1314. if(pMatGroup != NULL)
  1315. {
  1316. if(pMatGroup->getMaterial() == NULL)
  1317. {
  1318. pMatGroup->setMaterial(
  1319. _pMaterialHelper->getDefaultMaterial());
  1320. }
  1321. }
  1322. }
  1323. }
  1324. #ifdef OSG_DEBUG_VRML
  1325. // decIndent();
  1326. indentLog(getIndent(), PINFO);
  1327. PINFO << "End Shape " << &(*pFC) << std::endl;
  1328. #endif
  1329. }
  1330. /*-------------------------------------------------------------------------*/
  1331. /* Dump */
  1332. void VRMLShapeHelper::dump(const Char8 *)
  1333. {
  1334. }
  1335. VRMLNodeHelperFactoryBase::RegisterHelper VRMLShapeHelper::_regHelper(
  1336. &VRMLShapeHelper::create,
  1337. "Shape",
  1338. NULL);
  1339. //---------------------------------------------------------------------------
  1340. // Class
  1341. //---------------------------------------------------------------------------
  1342. /*! \class OSG::VRMLAppearanceDesc
  1343. \ingroup GrpSystemFileIOVRML
  1344. VRML Appearance description
  1345. */
  1346. VRMLNodeHelper *VRMLAppearanceHelper::create(void)
  1347. {
  1348. return new VRMLAppearanceHelper();
  1349. }
  1350. /*-------------------------------------------------------------------------*/
  1351. /* Constructors */
  1352. VRMLAppearanceHelper::VRMLAppearanceHelper(void) :
  1353. Inherited ( ),
  1354. _pMaterialHelper(NULL)
  1355. {
  1356. }
  1357. /*-------------------------------------------------------------------------*/
  1358. /* Destructor */
  1359. VRMLAppearanceHelper::~VRMLAppearanceHelper(void)
  1360. {
  1361. }
  1362. /*-------------------------------------------------------------------------*/
  1363. /* Helper */
  1364. void VRMLAppearanceHelper::init(const Char8 *szName)
  1365. {
  1366. Inherited::init(szName);
  1367. #ifdef OSG_DEBUG_VRML
  1368. indentLog(getIndent(), PINFO);
  1369. PINFO << "ApperanceHelper::init : " << szName << std::endl;
  1370. #endif
  1371. _pNodeProto = ChunkMaterial::create();
  1372. _pGenAttProto = VRMLGenericAtt::create();
  1373. _pGenAttProto->setInternal(true);
  1374. }
  1375. void VRMLAppearanceHelper::setMaterialHelper(
  1376. VRMLMaterialHelper *pMaterialHelper)
  1377. {
  1378. _pMaterialHelper = pMaterialHelper;
  1379. }
  1380. /*-------------------------------------------------------------------------*/
  1381. /* Field */
  1382. bool VRMLAppearanceHelper::prototypeAddField(const Char8 *szFieldType,
  1383. const UInt32 uiFieldTypeId,
  1384. const Char8 *szFieldname)
  1385. {
  1386. if(szFieldname == NULL)
  1387. return false;
  1388. if(osgStringCaseCmp("material", szFieldname) == 0)
  1389. {
  1390. return true;
  1391. }
  1392. else if(osgStringCaseCmp("texture", szFieldname) == 0)
  1393. {
  1394. return true;
  1395. }
  1396. else if(osgStringCaseCmp("textureTransform", szFieldname) == 0)
  1397. {
  1398. return true;
  1399. }
  1400. else
  1401. {
  1402. return Inherited::prototypeAddField(szFieldType,
  1403. uiFieldTypeId,
  1404. szFieldname);
  1405. }
  1406. }
  1407. void VRMLAppearanceHelper::getFieldAndDesc(
  1408. FieldContainer * pFC,
  1409. const Char8 * szFieldname,
  1410. FieldContainer *&pFieldFC,
  1411. EditFieldHandlePtr &pField,
  1412. const FieldDescriptionBase *&pDesc)
  1413. {
  1414. #ifdef OSG_DEBUG_VRML
  1415. indentLog(getIndent(), PINFO);
  1416. PINFO << "VRMLAppearanceHelper::getFieldAndDesc : looking for "
  1417. << szFieldname
  1418. << std::endl;
  1419. #endif
  1420. if(pFC == NULL)
  1421. {
  1422. if(_bProtoInterfaceDone == false)
  1423. {
  1424. Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
  1425. }
  1426. return;
  1427. }
  1428. if(szFieldname == NULL)
  1429. return;
  1430. incIndent();
  1431. if(osgStringCaseCmp("material", szFieldname) == 0)
  1432. {
  1433. #ifdef OSG_DEBUG_VRML
  1434. indentLog(getIndent(), PINFO);
  1435. PINFO << "VRMLAppearanceDesc::getFieldAndDesc : request internal "
  1436. << szFieldname
  1437. << std::endl;
  1438. #endif
  1439. pFieldFC = pFC;
  1440. pField = pFC->editField("chunks");
  1441. pDesc = pFC->getFieldDescription("chunks");
  1442. }
  1443. else if(osgStringCaseCmp("texture", szFieldname) == 0)
  1444. {
  1445. #ifdef OSG_DEBUG_VRML
  1446. indentLog(getIndent(), PINFO);
  1447. PINFO << "VRMLAppearanceHelper::getFieldAndDesc : request internal "
  1448. << szFieldname
  1449. << std::endl;
  1450. #endif
  1451. pFieldFC = pFC;
  1452. pField = pFC->editField("chunks");
  1453. pDesc = pFC->getFieldDescription("chunks");
  1454. }
  1455. else if(osgStringCaseCmp("textureTransform", szFieldname) == 0)
  1456. {
  1457. #ifdef OSG_DEBUG_VRML
  1458. indentLog(getIndent(), PINFO);
  1459. PINFO << "VRMLAppearanceDesc::getFieldAndDesc : request internal "
  1460. << szFieldname
  1461. << std::endl;
  1462. #endif
  1463. pFieldFC = pFC;
  1464. pField = pFC->editField("chunks");
  1465. pDesc = pFC->getFieldDescription("chunks");
  1466. }
  1467. else
  1468. {
  1469. Inherited::getFieldAndDesc(pFC,
  1470. szFieldname,
  1471. pFC,
  1472. pField,
  1473. pDesc);
  1474. }
  1475. #ifdef OSG_DEBUG_VRML
  1476. decIndent();
  1477. #endif
  1478. }
  1479. /*-------------------------------------------------------------------------*/
  1480. /* Node */
  1481. void VRMLAppearanceHelper::endNode(FieldContainer *pFC)
  1482. {
  1483. if(pFC != NULL)
  1484. {
  1485. ChunkMaterial *pChunkMat = dynamic_cast<ChunkMaterial *>(pFC);
  1486. if(pChunkMat != NULL)
  1487. {
  1488. TextureObjChunk *pTexC =
  1489. dynamic_cast<TextureObjChunk *>(
  1490. pChunkMat->find(TextureObjChunk::getClassType()));
  1491. TextureEnvChunkUnrecPtr pTexE =
  1492. dynamic_cast<TextureEnvChunk *>(
  1493. pChunkMat->find(TextureEnvChunk::getClassType()));
  1494. if ((pChunkMat->isTransparent() == true) ||
  1495. (pTexC != NULL &&
  1496. pTexC->getImage() != NULL &&
  1497. pTexC->getImage()->hasAlphaChannel() == true ))
  1498. {
  1499. BlendChunkUnrecPtr pBlendChunk = OSG::BlendChunk::create();
  1500. if(pTexC != NULL &&
  1501. pTexC->getImage() != NULL &&
  1502. pTexC->getImage()->isAlphaBinary() == true)
  1503. {
  1504. pBlendChunk->setAlphaFunc(GL_NOTEQUAL);
  1505. pBlendChunk->setAlphaValue(0);
  1506. }
  1507. else
  1508. {
  1509. pBlendChunk->setSrcFactor (GL_SRC_ALPHA);
  1510. pBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
  1511. }
  1512. pChunkMat->addChunk(pBlendChunk);
  1513. }
  1514. if(pTexC != NULL)
  1515. {
  1516. if(pTexE == NULL)
  1517. {
  1518. pTexE = TextureEnvChunk::create();
  1519. pChunkMat->addChunk(pTexE);
  1520. }
  1521. MaterialChunk *pMatC =
  1522. dynamic_cast<MaterialChunk *>(
  1523. pChunkMat->find(MaterialChunk::getClassType()));
  1524. if(pMatC == NULL)
  1525. {
  1526. pTexE->setEnvMode(GL_REPLACE);
  1527. }
  1528. else
  1529. {
  1530. pTexE->setEnvMode(GL_MODULATE);
  1531. }
  1532. }
  1533. }
  1534. // This works around the problem that MaterialChunks can not have
  1535. // NameAttachments on them (they are attachments themselves).
  1536. //
  1537. // If the ChunkMaterial (which corresponds to the VRML Appearance Node)
  1538. // has no name of its own, the material's name is set instead.
  1539. // BEGIN Material name hack
  1540. AttachmentContainer *attCon =
  1541. dynamic_cast<AttachmentContainer *>(pFC);
  1542. bool pushNames = false;
  1543. if(SceneFileHandler::the()->getOptionAs("wrl",
  1544. "pushNames",
  1545. pushNames) == false)
  1546. {
  1547. pushNames = false;
  1548. }
  1549. if(( attCon != NULL ) &&
  1550. ( pushNames == true ) &&
  1551. (_pMaterialHelper != NULL ) &&
  1552. (_pMaterialHelper->getName().empty() == false) )
  1553. {
  1554. FieldContainer *att = attCon->findAttachment(
  1555. Name::getClassType().getGroupId());
  1556. if(att != NULL)
  1557. {
  1558. // ChunkMaterial (Appearance) already has a NameAttachment
  1559. Name *nameAtt = dynamic_cast<Name *>(att);
  1560. if(nameAtt != NULL)
  1561. {
  1562. if(nameAtt->getFieldPtr()->getValue().empty())
  1563. {
  1564. nameAtt->editFieldPtr()->getValue().assign(
  1565. _pMaterialHelper->getName());
  1566. }
  1567. }
  1568. }
  1569. else
  1570. {
  1571. setName(attCon, _pMaterialHelper->getName());
  1572. }
  1573. }
  1574. // END Material name hack
  1575. }
  1576. #ifdef OSG_DEBUG_VRML
  1577. // decIndent();
  1578. indentLog(getIndent(), PINFO);
  1579. PINFO << "End Appearance " << std::endl;
  1580. #endif
  1581. }
  1582. /*-------------------------------------------------------------------------*/
  1583. /* Field Value */
  1584. /*-------------------------------------------------------------------------*/
  1585. /* Dump */
  1586. void VRMLAppearanceHelper::dump(const Char8 *)
  1587. {
  1588. }
  1589. VRMLNodeHelperFactoryBase::RegisterHelper VRMLAppearanceHelper::_regHelper(
  1590. &VRMLAppearanceHelper::create,
  1591. "Appearance",
  1592. NULL);
  1593. //---------------------------------------------------------------------------
  1594. // Class
  1595. //---------------------------------------------------------------------------
  1596. /*! \class OSG::VRMLIndexedGeometryHelper
  1597. \ingroup GrpSystemFileIOVRML
  1598. VRML Geometry description
  1599. */
  1600. VRMLNodeHelper *VRMLIndexedGeometryHelper::create(void)
  1601. {
  1602. return new VRMLIndexedGeometryHelper();
  1603. }
  1604. /*-------------------------------------------------------------------------*/
  1605. /* Constructors */
  1606. VRMLIndexedGeometryHelper::VRMLIndexedGeometryHelper(void) :
  1607. Inherited ( ),
  1608. _bIsFaceSet (false ),
  1609. _uiPropertyIndex(Geometry::PositionsIndex)
  1610. {
  1611. }
  1612. /*-------------------------------------------------------------------------*/
  1613. /* Destructor */
  1614. VRMLIndexedGeometryHelper::~VRMLIndexedGeometryHelper(void)
  1615. {
  1616. }
  1617. /*-------------------------------------------------------------------------*/
  1618. /* Helper */
  1619. void VRMLIndexedGeometryHelper::init(const Char8 *szName)
  1620. {
  1621. Inherited::init(szName);
  1622. #ifdef OSG_DEBUG_VRML
  1623. indentLog(getIndent(), PINFO);
  1624. PINFO << "GeoDesc::init : " << szName << std::endl;
  1625. #endif
  1626. _pNodeProto = Node ::create();
  1627. _pNodeCoreProto = Geometry ::create();
  1628. _pGenAttProto = VRMLGenericAtt::create();
  1629. _pGenAttProto->setInternal(true);
  1630. if(osgStringCaseCmp("IndexedFaceSet", szName) == 0)
  1631. {
  1632. _bIsFaceSet = true;
  1633. }
  1634. }
  1635. /*-------------------------------------------------------------------------*/
  1636. /* Get */
  1637. bool VRMLIndexedGeometryHelper::prototypeAddField(const Char8 *szFieldType,
  1638. const UInt32 uiFieldTypeId,
  1639. const Char8 *szFieldname)
  1640. {
  1641. bool bFound = false;
  1642. if(szFieldname == NULL)
  1643. return false;
  1644. if(osgStringCaseCmp("coord", szFieldname) == 0)
  1645. {
  1646. bFound = true;
  1647. }
  1648. else if(osgStringCaseCmp("normal", szFieldname) == 0)
  1649. {
  1650. bFound = true;
  1651. }
  1652. else if(osgStringCaseCmp("color", szFieldname) == 0)
  1653. {
  1654. bFound = true;
  1655. }
  1656. else if(osgStringCaseCmp("texCoord", szFieldname) == 0)
  1657. {
  1658. bFound = true;
  1659. }
  1660. if(bFound == true)
  1661. {
  1662. #ifdef OSG_DEBUG_VRML
  1663. indentLog(getIndent(), PINFO);
  1664. PINFO << "GeoDesc::prototypeAddField : internal "
  1665. << szFieldname << std::endl;
  1666. #endif
  1667. return true;
  1668. }
  1669. else
  1670. {
  1671. return Inherited::prototypeAddField(szFieldType,
  1672. uiFieldTypeId,
  1673. szFieldname);
  1674. }
  1675. }
  1676. void VRMLIndexedGeometryHelper::getFieldAndDesc(
  1677. FieldContainer * pFC,
  1678. const Char8 * szFieldname,
  1679. FieldContainer *&pFieldFC,
  1680. EditFieldHandlePtr &pField,
  1681. const FieldDescriptionBase *&pDesc)
  1682. {
  1683. #ifdef OSG_DEBUG_VRML
  1684. indentLog(getIndent(), PINFO);
  1685. PINFO << "GeoDesc::getFieldAndDesc : request "
  1686. << szFieldname
  1687. << std::endl;
  1688. #endif
  1689. if(szFieldname == NULL)
  1690. return;
  1691. if(pFC == NULL)
  1692. {
  1693. if(_bProtoInterfaceDone == false)
  1694. {
  1695. Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
  1696. }
  1697. return;
  1698. }
  1699. Node *pNode = dynamic_cast<Node *>(pFC);
  1700. if(pNode == NULL)
  1701. {
  1702. PWARNING << "GeoDesc::getFieldAndDesc : No Node" << std::endl;
  1703. return;
  1704. }
  1705. NodeCore *pNodeCore = pNode->getCore();
  1706. Geometry *pGeo = dynamic_cast<Geometry *>(pNodeCore);
  1707. if(pGeo == NULL)
  1708. {
  1709. PWARNING << "GeoDesc::getFieldAndDesc : No Geo" << std::endl;
  1710. return;
  1711. }
  1712. if(osgStringCaseCmp("coord", szFieldname) == 0)
  1713. {
  1714. #ifdef OSG_DEBUG_VRML
  1715. indentLog(getIndent(), PINFO);
  1716. PINFO << "GeoDesc::getFieldAndDesc : internal "
  1717. << szFieldname << std::endl;
  1718. #endif
  1719. pFieldFC = pGeo;
  1720. pField.reset();
  1721. pDesc = &_sfFCPtrDesc;
  1722. _uiPropertyIndex = Geometry::PositionsIndex;
  1723. }
  1724. else if(osgStringCaseCmp("normal", szFieldname) == 0)
  1725. {
  1726. #ifdef OSG_DEBUG_VRML
  1727. indentLog(getIndent(), PINFO);
  1728. PINFO << "GeoDesc::getFieldAndDesc : internal "
  1729. << szFieldname << std::endl;
  1730. #endif
  1731. pFieldFC = pGeo;
  1732. pField.reset();
  1733. pDesc = &_sfFCPtrDesc;
  1734. _uiPropertyIndex = Geometry::NormalsIndex;
  1735. }
  1736. else if(osgStringCaseCmp("color", szFieldname) == 0)
  1737. {
  1738. #ifdef OSG_DEBUG_VRML
  1739. indentLog(getIndent(), PINFO);
  1740. PINFO << "GeoDesc::getFieldAndDesc : internal "
  1741. << szFieldname << std::endl;
  1742. #endif
  1743. pFieldFC = pGeo;
  1744. pField.reset();
  1745. pDesc = &_sfFCPtrDesc;
  1746. _uiPropertyIndex = Geometry::ColorsIndex;
  1747. }
  1748. else if(osgStringCaseCmp("texCoord", szFieldname) == 0)
  1749. {
  1750. #ifdef OSG_DEBUG_VRML
  1751. indentLog(getIndent(), PINFO);
  1752. PINFO << "GeoDesc::getFieldAndDesc : internal "
  1753. << szFieldname << std::endl;
  1754. #endif
  1755. pFieldFC = pGeo;
  1756. pField.reset();
  1757. pDesc = &_sfFCPtrDesc;
  1758. _uiPropertyIndex = Geometry::TexCoordsIndex;
  1759. }
  1760. else
  1761. {
  1762. Inherited::getFieldAndDesc(pGeo,
  1763. szFieldname,
  1764. pFieldFC,
  1765. pField,
  1766. pDesc);
  1767. }
  1768. }
  1769. /*-------------------------------------------------------------------------*/
  1770. /* Node */
  1771. void VRMLIndexedGeometryHelper::endNode(FieldContainer *pFC)
  1772. {
  1773. Node *pNode = NULL;
  1774. Geometry *pGeo = NULL;
  1775. if(pFC == NULL)
  1776. {
  1777. return;
  1778. }
  1779. pNode = dynamic_cast<Node *>(pFC);
  1780. if(pNode == NULL)
  1781. {
  1782. return;
  1783. }
  1784. pGeo = dynamic_cast<Geometry *>(pNode->getCore());
  1785. if(pGeo == NULL)
  1786. {
  1787. return;
  1788. }
  1789. EditFieldHandlePtr pField;
  1790. const FieldDescriptionBase *pDesc = NULL;
  1791. FieldContainer *pDummyFC = NULL;
  1792. MFInt32 *pCoordIndex = NULL;
  1793. MFInt32 *pNormalIndex = NULL;
  1794. MFInt32 *pColorIndex = NULL;
  1795. MFInt32 *pTexCoordIndex = NULL;
  1796. SFBool *pConvex = NULL;
  1797. SFBool *pCcw = NULL;
  1798. SFBool *pNormalPerVertex = NULL;
  1799. SFBool *pColorPerVertex = NULL;
  1800. SFReal32 *pCreaseAngle = NULL;
  1801. Inherited::getFieldAndDesc(pFC,
  1802. "coordIndex",
  1803. pDummyFC,
  1804. pField,
  1805. pDesc);
  1806. if(pField != NULL)
  1807. {
  1808. MFInt32::EditHandlePtr pValField =
  1809. boost::dynamic_pointer_cast<MFInt32::EditHandle>(pField);
  1810. if(pValField != NULL && pValField->isValid())
  1811. {
  1812. pCoordIndex = pValField->getField();
  1813. }
  1814. }
  1815. Inherited::getFieldAndDesc(pFC,
  1816. "normalIndex",
  1817. pDummyFC,
  1818. pField,
  1819. pDesc);
  1820. if(pField != NULL)
  1821. {
  1822. MFInt32::EditHandlePtr pValField =
  1823. boost::dynamic_pointer_cast<MFInt32::EditHandle>(pField);
  1824. if(pValField != NULL && pValField->isValid())
  1825. {
  1826. pNormalIndex = pValField->getField();
  1827. }
  1828. }
  1829. Inherited::getFieldAndDesc(pFC,
  1830. "colorIndex",
  1831. pDummyFC,
  1832. pField,
  1833. pDesc);
  1834. if(pField != NULL)
  1835. {
  1836. MFInt32::EditHandlePtr pValField =
  1837. boost::dynamic_pointer_cast<MFInt32::EditHandle>(pField);
  1838. if(pValField != NULL && pValField->isValid())
  1839. {
  1840. pColorIndex = pValField->getField();
  1841. }
  1842. }
  1843. Inherited::getFieldAndDesc(pFC,
  1844. "texCoordIndex",
  1845. pDummyFC,
  1846. pField,
  1847. pDesc);
  1848. if(pField != NULL)
  1849. {
  1850. MFInt32::EditHandlePtr pValField =
  1851. boost::dynamic_pointer_cast<MFInt32::EditHandle>(pField);
  1852. if(pValField != NULL && pValField->isValid())
  1853. {
  1854. pTexCoordIndex = pValField->getField();
  1855. }
  1856. }
  1857. Inherited::getFieldAndDesc(pFC,
  1858. "convex",
  1859. pDummyFC,
  1860. pField,
  1861. pDesc);
  1862. if(pField != NULL)
  1863. {
  1864. SFBool::EditHandlePtr pValField =
  1865. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  1866. if(pValField != NULL && pValField->isValid())
  1867. {
  1868. pConvex = pValField->getField();
  1869. }
  1870. }
  1871. Inherited::getFieldAndDesc(pFC,
  1872. "ccw",
  1873. pDummyFC,
  1874. pField,
  1875. pDesc);
  1876. if(pField != NULL)
  1877. {
  1878. SFBool::EditHandlePtr pValField =
  1879. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  1880. if(pValField != NULL && pValField->isValid())
  1881. {
  1882. pCcw = pValField->getField();
  1883. }
  1884. }
  1885. Inherited::getFieldAndDesc(pFC,
  1886. "normalPerVertex",
  1887. pDummyFC,
  1888. pField,
  1889. pDesc);
  1890. if(pField != NULL)
  1891. {
  1892. SFBool::EditHandlePtr pValField =
  1893. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  1894. if(pValField != NULL && pValField->isValid())
  1895. {
  1896. pNormalPerVertex = pValField->getField();
  1897. }
  1898. }
  1899. Inherited::getFieldAndDesc(pFC,
  1900. "colorPerVertex",
  1901. pDummyFC,
  1902. pField,
  1903. pDesc);
  1904. if(pField != NULL)
  1905. {
  1906. SFBool::EditHandlePtr pValField =
  1907. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  1908. if(pValField != NULL && pValField->isValid())
  1909. {
  1910. pColorPerVertex = pValField->getField();
  1911. }
  1912. }
  1913. Inherited::getFieldAndDesc(pFC,
  1914. "creaseAngle",
  1915. pDummyFC,
  1916. pField,
  1917. pDesc);
  1918. if(pField != NULL)
  1919. {
  1920. SFReal32::EditHandlePtr pValField =
  1921. boost::dynamic_pointer_cast<SFReal32::EditHandle>(pField);
  1922. if(pValField != NULL && pValField->isValid())
  1923. {
  1924. pCreaseAngle = pValField->getField();
  1925. }
  1926. }
  1927. if(_bIsFaceSet == true)
  1928. {
  1929. if(pCoordIndex != NULL &&
  1930. pCoordIndex->size() > 2 &&
  1931. pNormalIndex != NULL &&
  1932. pColorIndex != NULL &&
  1933. pTexCoordIndex != NULL &&
  1934. pConvex != NULL &&
  1935. pCcw != NULL &&
  1936. pNormalPerVertex != NULL &&
  1937. pColorPerVertex != NULL &&
  1938. pCreaseAngle != NULL)
  1939. {
  1940. #ifdef OSG_DEBUG_VRML
  1941. indentLog(getIndent(), PINFO);
  1942. PINFO << "Geo create faceset " << &(*pNode) << std::endl;
  1943. #endif
  1944. setIndexFromIndexedX3DData(pGeo,
  1945. pCoordIndex ->getValues(),
  1946. pNormalIndex ->getValues(),
  1947. pColorIndex ->getValues(),
  1948. pTexCoordIndex ->getValues(),
  1949. GL_POLYGON,
  1950. pConvex ->getValue() ,
  1951. pCcw ->getValue() ,
  1952. pNormalPerVertex->getValue() ,
  1953. pColorPerVertex ->getValue() ,
  1954. false); // create normal; not yet :)
  1955. //if (pConvex->getValue() == false)
  1956. // createConvexPrimitives( pGeo );
  1957. // TODO: Need some option _uiOptions param
  1958. //createSharedIndex( pGeo);
  1959. //if((0 != (_uiOptions & VRMLFile::CreateNormals) ) &&
  1960. // (pGeo->getNormals() == NULL))
  1961. if(pGeo->getNormals() == NULL)
  1962. {
  1963. #ifdef OSG_DEBUG_VRML
  1964. indentLog(getIndent(), PINFO);
  1965. PINFO << "Geo create normals " << &(*pNode) << std::endl;
  1966. #endif
  1967. OSG::calcVertexNormals(pGeo, pCreaseAngle->getValue());
  1968. }
  1969. }
  1970. else
  1971. {
  1972. #if 0 // What's the point of doing that?
  1973. PWARNING << "Invalid geometry replaced by a group" << std::endl;
  1974. GroupPtr pGr = Group::create();
  1975. MFNodePtr pGeoParents = pGeo->getParents ();
  1976. MFNodePtr::iterator parentsIt = pGeoParents.begin();
  1977. MFNodePtr::iterator endParents = pGeoParents.end ();
  1978. // this makes pGeo invalid!
  1979. while(parentsIt != endParents)
  1980. {
  1981. (*parentsIt)->setCore(pGr);
  1982. ++parentsIt;
  1983. }
  1984. pGeo = NULL;
  1985. #endif
  1986. }
  1987. }
  1988. else
  1989. {
  1990. std::vector<Int32> dummyVec;
  1991. bool dummybool = false;
  1992. if(pCoordIndex != NULL &&
  1993. pCoordIndex->size() > 1 &&
  1994. pColorIndex != NULL &&
  1995. pColorPerVertex != NULL)
  1996. {
  1997. #ifdef OSG_DEBUG_VRML
  1998. indentLog(getIndent(), PINFO);
  1999. PINFO << "Geo create lineset " << &(*pNode) << std::endl;
  2000. #endif
  2001. setIndexFromIndexedX3DData(pGeo,
  2002. pCoordIndex ->getValues(),
  2003. dummyVec ,
  2004. pColorIndex ->getValues(),
  2005. dummyVec ,
  2006. GL_LINES,
  2007. dummybool,
  2008. dummybool,
  2009. dummybool,
  2010. pColorPerVertex->getValue() ,
  2011. false); // create normal; not yet :)
  2012. }
  2013. else
  2014. {
  2015. #if 0 // What's the point of doing that?
  2016. PWARNING << "Invalid geometry replaced by a group" << std::endl;
  2017. GroupPtr pGr = Group::create();
  2018. MFNodePtr pGeoParents = pGeo->getParents ();
  2019. MFNodePtr::iterator parentsIt = pGeoParents.begin();
  2020. MFNodePtr::iterator endParents = pGeoParents.end ();
  2021. // this makes pGeo invalid!
  2022. while(parentsIt != endParents)
  2023. {
  2024. (*parentsIt)->setCore(pGr);
  2025. ++parentsIt;
  2026. }
  2027. pGeo = NULL;
  2028. #endif
  2029. }
  2030. }
  2031. #ifdef OSG_DEBUG_VRML
  2032. // decIndent();
  2033. indentLog(getIndent(), PINFO);
  2034. PINFO << "End Geo " << &(*pNode) << std::endl;
  2035. #endif
  2036. }
  2037. void VRMLIndexedGeometryHelper::setContainerFieldValue(
  2038. FieldContainer *pFC,
  2039. const FieldDescriptionBase *pFieldDesc,
  2040. FieldContainer *pFieldFC )
  2041. {
  2042. Geometry *pGeo =
  2043. dynamic_cast<Geometry *>(pFieldFC);
  2044. GeoVectorProperty *pVecProp =
  2045. dynamic_cast<GeoVectorProperty *>(pFC);
  2046. if(pGeo != NULL && pVecProp != NULL)
  2047. {
  2048. pGeo->setProperty(pVecProp, _uiPropertyIndex);
  2049. }
  2050. else
  2051. {
  2052. PWARNING << "GeoDesc::getFieldAndDesc : No Geo" << std::endl;
  2053. }
  2054. }
  2055. /*-------------------------------------------------------------------------*/
  2056. /* Dump */
  2057. void VRMLIndexedGeometryHelper::dump(const Char8 *)
  2058. {
  2059. }
  2060. VRMLNodeHelperFactoryBase::RegisterHelper
  2061. VRMLIndexedGeometryHelper::_regHelperIFS(
  2062. &VRMLIndexedGeometryHelper::create,
  2063. "IndexedFaceSet",
  2064. NULL);
  2065. VRMLNodeHelperFactoryBase::RegisterHelper
  2066. VRMLIndexedGeometryHelper::_regHelperILS(
  2067. &VRMLIndexedGeometryHelper::create,
  2068. "IndexedLineSet",
  2069. NULL);
  2070. //---------------------------------------------------------------------------
  2071. // Class
  2072. //---------------------------------------------------------------------------
  2073. /*! \class OSG::VRMLGeometryPartHelper
  2074. \ingroup GrpSystemFileIOVRML
  2075. VRML Geometry Part Set description
  2076. */
  2077. VRMLNodeHelper *VRMLGeometryPartHelper::create(void)
  2078. {
  2079. return new VRMLGeometryPartHelper();
  2080. }
  2081. /*-------------------------------------------------------------------------*/
  2082. /* Constructors */
  2083. VRMLGeometryPartHelper::VRMLGeometryPartHelper(void) :
  2084. Inherited (),
  2085. _szVRMLPartname(),
  2086. _szOSGPartname (),
  2087. _szOSGProtoname()
  2088. {
  2089. }
  2090. /*-------------------------------------------------------------------------*/
  2091. /* Destructor */
  2092. VRMLGeometryPartHelper::~VRMLGeometryPartHelper(void)
  2093. {
  2094. }
  2095. /*-------------------------------------------------------------------------*/
  2096. /* Helper */
  2097. void VRMLGeometryPartHelper::init(const Char8 *szName)
  2098. {
  2099. if(osgStringCaseCmp("Coordinate", szName) == 0)
  2100. {
  2101. _szVRMLPartname = "point";
  2102. _szOSGPartname = "values";
  2103. _szOSGProtoname = "GeoPnt3fProperty";
  2104. }
  2105. else if(osgStringCaseCmp("Normal", szName) == 0)
  2106. {
  2107. _szVRMLPartname = "vector";
  2108. _szOSGPartname = "values";
  2109. _szOSGProtoname = "GeoVec3fProperty";
  2110. }
  2111. else if(osgStringCaseCmp("Color", szName) == 0)
  2112. {
  2113. _szVRMLPartname = "color";
  2114. _szOSGPartname = "values";
  2115. _szOSGProtoname = "GeoColor3fProperty";
  2116. }
  2117. else if(osgStringCaseCmp("TextureCoordinate", szName) == 0)
  2118. {
  2119. _szVRMLPartname = "point";
  2120. _szOSGPartname = "values";
  2121. _szOSGProtoname = "GeoVec2fProperty";
  2122. }
  2123. #ifdef OSG_DEBUG_VRML
  2124. indentLog(getIndent(), PINFO);
  2125. PINFO << "GeoPartDesc::init : "
  2126. << szName << " "
  2127. << _szVRMLPartname << " "
  2128. << _szOSGPartname << " "
  2129. << _szOSGProtoname << " "
  2130. << std::endl;
  2131. #endif
  2132. _pNodeProto =
  2133. FieldContainerFactory::the()->createContainer(_szOSGProtoname.c_str());
  2134. if(_pNodeProto == NULL)
  2135. {
  2136. PWARNING << "ERROR no prototype available for "
  2137. << _szOSGProtoname
  2138. << std::endl;
  2139. }
  2140. _pGenAttProto = VRMLGenericAtt::create();
  2141. _pGenAttProto->setInternal(true);
  2142. }
  2143. /*-------------------------------------------------------------------------*/
  2144. /* Field */
  2145. bool VRMLGeometryPartHelper::prototypeAddField(const Char8 *szFieldType,
  2146. const UInt32 uiFieldTypeId,
  2147. const Char8 *szFieldname)
  2148. {
  2149. bool bFound = false;
  2150. if(_szVRMLPartname == szFieldname)
  2151. {
  2152. #ifdef OSG_DEBUG_VRML
  2153. indentLog(getIndent(), PINFO);
  2154. PINFO << "GeoPartDesc::prototypeAddField : add part "
  2155. << szFieldname
  2156. << std::endl;
  2157. #endif
  2158. bFound = true;
  2159. }
  2160. if(bFound == true)
  2161. {
  2162. return true;
  2163. }
  2164. else
  2165. {
  2166. return Inherited::prototypeAddField(szFieldType,
  2167. uiFieldTypeId,
  2168. szFieldname);
  2169. }
  2170. }
  2171. void VRMLGeometryPartHelper::getFieldAndDesc(
  2172. FieldContainer * pFC,
  2173. const Char8 * szFieldname,
  2174. FieldContainer *&pFieldFC,
  2175. EditFieldHandlePtr &pField,
  2176. const FieldDescriptionBase *&pDesc)
  2177. {
  2178. #ifdef OSG_DEBUG_VRML
  2179. indentLog(getIndent(), PINFO);
  2180. PINFO << "VRMLGeometryPartDesc::getFieldAndDesc : looking for "
  2181. << szFieldname
  2182. << std::endl;
  2183. #endif
  2184. if(szFieldname == NULL)
  2185. return;
  2186. if(pFC == NULL)
  2187. {
  2188. if(_bProtoInterfaceDone == false)
  2189. {
  2190. Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
  2191. }
  2192. return;
  2193. }
  2194. incIndent();
  2195. if(_szVRMLPartname == szFieldname)
  2196. {
  2197. #ifdef OSG_DEBUG_VRML
  2198. indentLog(getIndent(), PINFO);
  2199. PINFO << "VRMLGeometryPartDesc::getFieldAndDesc : request internal "
  2200. << szFieldname
  2201. << " return "
  2202. << _szOSGPartname
  2203. << std::endl;
  2204. #endif
  2205. pFieldFC = pFC;
  2206. pDesc = pFC->getFieldDescription(_szOSGPartname.c_str());
  2207. pField = pFC->editField (_szOSGPartname.c_str());
  2208. if(pField == NULL)
  2209. {
  2210. PWARNING << "VRMLGeometryPartDesc::getFieldAndDesc : could not"
  2211. << " map : "
  2212. << szFieldname
  2213. << " to "
  2214. << _szOSGPartname
  2215. << std::endl;
  2216. }
  2217. }
  2218. else
  2219. {
  2220. Inherited::getFieldAndDesc(pFC,
  2221. szFieldname,
  2222. pFieldFC,
  2223. pField,
  2224. pDesc);
  2225. }
  2226. #ifdef OSG_DEBUG_VRML
  2227. decIndent();
  2228. #endif
  2229. }
  2230. /*-------------------------------------------------------------------------*/
  2231. /* Node */
  2232. void VRMLGeometryPartHelper::mapFieldname(const std::string &,
  2233. std::string &szFieldName)
  2234. {
  2235. szFieldName.assign("values");
  2236. }
  2237. /*-------------------------------------------------------------------------*/
  2238. /* Dump */
  2239. void VRMLGeometryPartHelper::dump(const Char8 *)
  2240. {
  2241. }
  2242. VRMLNodeHelperFactoryBase::RegisterHelper
  2243. VRMLGeometryPartHelper::_regHelperCoordinate(
  2244. &VRMLGeometryPartHelper::create,
  2245. "Coordinate",
  2246. NULL);
  2247. VRMLNodeHelperFactoryBase::RegisterHelper
  2248. VRMLGeometryPartHelper::_regHelperNormal(
  2249. &VRMLGeometryPartHelper::create,
  2250. "Normal",
  2251. NULL);
  2252. VRMLNodeHelperFactoryBase::RegisterHelper
  2253. VRMLGeometryPartHelper::_regHelperColor(
  2254. &VRMLGeometryPartHelper::create,
  2255. "Color",
  2256. NULL);
  2257. VRMLNodeHelperFactoryBase::RegisterHelper
  2258. VRMLGeometryPartHelper::_regHelperTexCoordinate(
  2259. &VRMLGeometryPartHelper::create,
  2260. "TextureCoordinate",
  2261. NULL);
  2262. //---------------------------------------------------------------------------
  2263. // Class
  2264. //---------------------------------------------------------------------------
  2265. /*! \class OSG::VRMLGeometryObjectDesc
  2266. \ingroup GrpSystemFileIOVRML
  2267. VRML Geometry Object Set description
  2268. */
  2269. VRMLNodeHelper *VRMLGeometryObjectHelper::create(void)
  2270. {
  2271. return new VRMLGeometryObjectHelper();
  2272. }
  2273. /*-------------------------------------------------------------------------*/
  2274. /* Constructors */
  2275. VRMLGeometryObjectHelper::VRMLGeometryObjectHelper(void) :
  2276. Inherited ( ),
  2277. _eVRMLObjectType(UnknownGeo)
  2278. {
  2279. }
  2280. /*-------------------------------------------------------------------------*/
  2281. /* Destructor */
  2282. VRMLGeometryObjectHelper::~VRMLGeometryObjectHelper(void)
  2283. {
  2284. }
  2285. /*-------------------------------------------------------------------------*/
  2286. /* Helper */
  2287. void VRMLGeometryObjectHelper::init(const Char8 *szName)
  2288. {
  2289. #ifdef OSG_DEBUG_VRML
  2290. indentLog(getIndent(), PINFO);
  2291. PINFO << "GeoObjDesc::init : "
  2292. << szName << " "
  2293. << _eVRMLObjectType
  2294. << std::endl;
  2295. #endif
  2296. if(osgStringCaseCmp("Box", szName) == 0)
  2297. {
  2298. _eVRMLObjectType = BoxGeo;
  2299. }
  2300. else if(osgStringCaseCmp("Sphere", szName) == 0)
  2301. {
  2302. _eVRMLObjectType = SphereGeo;
  2303. }
  2304. else if(osgStringCaseCmp("Cone", szName) == 0)
  2305. {
  2306. _eVRMLObjectType = ConeGeo;
  2307. }
  2308. else if(osgStringCaseCmp("Cylinder", szName) == 0)
  2309. {
  2310. _eVRMLObjectType = CylinderGeo;
  2311. }
  2312. else if(osgStringCaseCmp("Teapot", szName) == 0)
  2313. {
  2314. _eVRMLObjectType = TeapotGeo;
  2315. }
  2316. else if(osgStringCaseCmp("Plane", szName) == 0)
  2317. {
  2318. _eVRMLObjectType = PlaneGeo;
  2319. }
  2320. _pNodeProto = Node::create();
  2321. if(_pNodeProto == NULL)
  2322. {
  2323. PWARNING << "GeoObjDesc::init : no prototype available" << std::endl;
  2324. }
  2325. _pGenAttProto = VRMLGenericAtt::create();
  2326. _pGenAttProto->setInternal(true);
  2327. }
  2328. /*-------------------------------------------------------------------------*/
  2329. /* Field */
  2330. /*-------------------------------------------------------------------------*/
  2331. /* Node */
  2332. void VRMLGeometryObjectHelper::endNode(FieldContainer *pFC)
  2333. {
  2334. EditFieldHandlePtr pField;
  2335. const FieldDescriptionBase *pDesc = NULL;
  2336. FieldContainer *pDummyFC = NULL;
  2337. Node *pNode = NULL;
  2338. if(pFC == NULL)
  2339. return;
  2340. pNode = dynamic_cast<Node *>(pFC);
  2341. if(pNode == NULL)
  2342. return;
  2343. if(_eVRMLObjectType == BoxGeo)
  2344. {
  2345. Inherited::getFieldAndDesc(pFC,
  2346. "size",
  2347. pDummyFC,
  2348. pField,
  2349. pDesc);
  2350. if(pField != NULL)
  2351. {
  2352. SFVec3f::EditHandlePtr pValField =
  2353. boost::dynamic_pointer_cast<SFVec3f::EditHandle>(pField);
  2354. if(pValField != NULL && pValField->isValid())
  2355. {
  2356. SFVec3f *pVec = pValField->getField();
  2357. GeometryUnrecPtr pGeo = makeBoxGeo(pVec->getValue()[0],
  2358. pVec->getValue()[1],
  2359. pVec->getValue()[2],
  2360. 1,
  2361. 1,
  2362. 1);
  2363. pNode->setCore(pGeo);
  2364. }
  2365. }
  2366. }
  2367. else if(_eVRMLObjectType == ConeGeo)
  2368. {
  2369. SFReal32 *pBotRad = NULL;
  2370. SFReal32 *pHeight = NULL;
  2371. SFBool *pSide = NULL;
  2372. SFBool *pBottom = NULL;
  2373. Inherited::getFieldAndDesc(pFC,
  2374. "bottomRadius",
  2375. pDummyFC,
  2376. pField,
  2377. pDesc);
  2378. if(pField != NULL)
  2379. {
  2380. SFReal32::EditHandlePtr pValField =
  2381. boost::dynamic_pointer_cast<SFReal32::EditHandle>(pField);
  2382. if(pValField != NULL && pValField->isValid())
  2383. {
  2384. pBotRad = pValField->getField();
  2385. }
  2386. }
  2387. Inherited::getFieldAndDesc(pFC,
  2388. "height",
  2389. pDummyFC,
  2390. pField,
  2391. pDesc);
  2392. if(pField != NULL)
  2393. {
  2394. SFReal32::EditHandlePtr pValField =
  2395. boost::dynamic_pointer_cast<SFReal32::EditHandle>(pField);
  2396. if(pValField != NULL && pValField->isValid())
  2397. {
  2398. pHeight = pValField->getField();
  2399. }
  2400. }
  2401. Inherited::getFieldAndDesc(pFC,
  2402. "side",
  2403. pDummyFC,
  2404. pField,
  2405. pDesc);
  2406. if(pField != NULL)
  2407. {
  2408. SFBool::EditHandlePtr pValField =
  2409. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  2410. if(pValField != NULL && pValField->isValid())
  2411. {
  2412. pSide = pValField->getField();
  2413. }
  2414. }
  2415. Inherited::getFieldAndDesc(pFC,
  2416. "bottom",
  2417. pDummyFC,
  2418. pField,
  2419. pDesc);
  2420. if(pField != NULL)
  2421. {
  2422. SFBool::EditHandlePtr pValField =
  2423. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  2424. if(pValField != NULL && pValField->isValid())
  2425. {
  2426. pBottom = pValField->getField();
  2427. }
  2428. }
  2429. if(pBotRad != NULL &&
  2430. pHeight != NULL &&
  2431. pSide != NULL &&
  2432. pBottom != NULL)
  2433. {
  2434. #ifdef OSG_DEBUG_VRML
  2435. indentLog(getIndent(), PINFO);
  2436. PINFO << "VRMLGeometryObjectDesc::endNode : Create cone"
  2437. << std::endl;
  2438. #endif
  2439. GeometryUnrecPtr pGeo = makeConeGeo(pHeight->getValue(),
  2440. pBotRad->getValue(),
  2441. 32,
  2442. pSide ->getValue(),
  2443. pBottom->getValue());
  2444. pNode->setCore(pGeo);
  2445. }
  2446. }
  2447. else if(_eVRMLObjectType == CylinderGeo)
  2448. {
  2449. SFBool *pBottom = NULL;
  2450. SFReal32 *pHeight = NULL;
  2451. SFReal32 *pRadius = NULL;
  2452. SFBool *pSide = NULL;
  2453. SFBool *pTop = NULL;
  2454. Inherited::getFieldAndDesc(pFC,
  2455. "bottom",
  2456. pDummyFC,
  2457. pField,
  2458. pDesc);
  2459. if(pField != NULL)
  2460. {
  2461. SFBool::EditHandlePtr pValField =
  2462. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  2463. if(pValField != NULL && pValField->isValid())
  2464. {
  2465. pBottom = pValField->getField();
  2466. }
  2467. }
  2468. Inherited::getFieldAndDesc(pFC,
  2469. "height",
  2470. pDummyFC,
  2471. pField,
  2472. pDesc);
  2473. if(pField != NULL)
  2474. {
  2475. SFReal32::EditHandlePtr pValField =
  2476. boost::dynamic_pointer_cast<SFReal32::EditHandle>(pField);
  2477. if(pValField != NULL && pValField->isValid())
  2478. {
  2479. pHeight = pValField->getField();
  2480. }
  2481. }
  2482. Inherited::getFieldAndDesc(pFC,
  2483. "radius",
  2484. pDummyFC,
  2485. pField,
  2486. pDesc);
  2487. if(pField != NULL)
  2488. {
  2489. SFReal32::EditHandlePtr pValField =
  2490. boost::dynamic_pointer_cast<SFReal32::EditHandle>(pField);
  2491. if(pValField != NULL && pValField->isValid())
  2492. {
  2493. pRadius = pValField->getField();
  2494. }
  2495. }
  2496. Inherited::getFieldAndDesc(pFC,
  2497. "side",
  2498. pDummyFC,
  2499. pField,
  2500. pDesc);
  2501. if(pField != NULL)
  2502. {
  2503. SFBool::EditHandlePtr pValField =
  2504. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  2505. if(pValField != NULL && pValField->isValid())
  2506. {
  2507. pSide = pValField->getField();
  2508. }
  2509. }
  2510. Inherited::getFieldAndDesc(pFC,
  2511. "top",
  2512. pDummyFC,
  2513. pField,
  2514. pDesc);
  2515. if(pField != NULL)
  2516. {
  2517. SFBool::EditHandlePtr pValField =
  2518. boost::dynamic_pointer_cast<SFBool::EditHandle>(pField);
  2519. if(pValField != NULL && pValField->isValid())
  2520. {
  2521. pTop = pValField->getField();
  2522. }
  2523. }
  2524. if(pBottom != NULL &&
  2525. pHeight != NULL &&
  2526. pRadius != NULL &&
  2527. pSide != NULL &&
  2528. pTop != NULL)
  2529. {
  2530. #ifdef OSG_DEBUG_VRML
  2531. indentLog(getIndent(), PINFO);
  2532. PINFO << "VRMLGeometryObjectDesc::endNode : Create cylinder"
  2533. << std::endl;
  2534. #endif
  2535. GeometryUnrecPtr pGeo = makeCylinderGeo(pHeight->getValue(),
  2536. pRadius->getValue(),
  2537. 32,
  2538. pSide ->getValue(),
  2539. pTop ->getValue(),
  2540. pBottom->getValue());
  2541. pNode->setCore(pGeo);
  2542. }
  2543. }
  2544. else if(_eVRMLObjectType == SphereGeo)
  2545. {
  2546. SFReal32 *pSize = NULL;
  2547. SFInt32 *pResolution = NULL;
  2548. Inherited::getFieldAndDesc(pFC,
  2549. "radius",
  2550. pDummyFC,
  2551. pField,
  2552. pDesc);
  2553. if(pField != NULL)
  2554. {
  2555. SFReal32::EditHandlePtr pValField =
  2556. boost::dynamic_pointer_cast<SFReal32::EditHandle>(pField);
  2557. if(pValField != NULL && pValField->isValid())
  2558. {
  2559. pSize = pValField->getField();
  2560. }
  2561. }
  2562. Inherited::getFieldAndDesc(pFC,
  2563. "resolution",
  2564. pDummyFC,
  2565. pField,
  2566. pDesc);
  2567. if(pField != NULL)
  2568. {
  2569. SFInt32::EditHandlePtr pValField =
  2570. boost::dynamic_pointer_cast<SFInt32::EditHandle>(pField);
  2571. if(pValField != NULL && pValField->isValid())
  2572. {
  2573. pResolution = pValField->getField();
  2574. }
  2575. }
  2576. if(pSize != NULL && pResolution != NULL)
  2577. {
  2578. GeometryUnrecPtr pGeo =
  2579. makeLatLongSphereGeo(pResolution->getValue(),
  2580. pResolution->getValue() * 2,
  2581. pSize ->getValue());
  2582. pNode->setCore(pGeo);
  2583. }
  2584. }
  2585. else if(_eVRMLObjectType == TeapotGeo)
  2586. {
  2587. SFReal32 *pScale = NULL;
  2588. SFInt32 *pDepth = NULL;
  2589. Inherited::getFieldAndDesc(pFC,
  2590. "scale",
  2591. pDummyFC,
  2592. pField,
  2593. pDesc);
  2594. if(pField != NULL)
  2595. {
  2596. SFReal32::EditHandlePtr pValField =
  2597. boost::dynamic_pointer_cast<SFReal32::EditHandle>(pField);
  2598. if(pValField != NULL && pValField->isValid())
  2599. {
  2600. pScale = pValField->getField();
  2601. }
  2602. }
  2603. Inherited::getFieldAndDesc(pFC,
  2604. "depth",
  2605. pDummyFC,
  2606. pField,
  2607. pDesc);
  2608. if(pField != NULL)
  2609. {
  2610. SFInt32::EditHandlePtr pValField =
  2611. boost::dynamic_pointer_cast<SFInt32::EditHandle>(pField);
  2612. if(pValField != NULL && pValField->isValid())
  2613. {
  2614. pDepth = pValField->getField();
  2615. }
  2616. }
  2617. GeometryUnrecPtr pGeo = makeTeapotGeo(
  2618. (pDepth != NULL) ? pDepth->getValue() : 5,
  2619. (pScale != NULL) ? pScale->getValue() : 1.f);
  2620. pNode->setCore(pGeo);
  2621. }
  2622. else if(_eVRMLObjectType == PlaneGeo)
  2623. {
  2624. SFVec2s *pResolution = NULL;
  2625. SFVec2f *pSize = NULL;
  2626. Inherited::getFieldAndDesc(pFC,
  2627. "resolution",
  2628. pDummyFC,
  2629. pField,
  2630. pDesc);
  2631. if(pField != NULL)
  2632. {
  2633. SFVec2s::EditHandlePtr pValField =
  2634. boost::dynamic_pointer_cast<SFVec2s::EditHandle>(pField);
  2635. if(pValField != NULL && pValField->isValid())
  2636. {
  2637. pResolution = pValField->getField();
  2638. }
  2639. }
  2640. Inherited::getFieldAndDesc(pFC,
  2641. "size",
  2642. pDummyFC,
  2643. pField,
  2644. pDesc);
  2645. if(pField != NULL)
  2646. {
  2647. SFVec2f::EditHandlePtr pValField =
  2648. boost::dynamic_pointer_cast<SFVec2f::EditHandle>(pField);
  2649. if(pValField != NULL && pValField->isValid())
  2650. {
  2651. pSize = pValField->getField();
  2652. }
  2653. }
  2654. GeometryUnrecPtr pGeo = makePlaneGeo(
  2655. (pSize != NULL) ? pSize ->getValue()[0] : 1.f,
  2656. (pSize != NULL) ? pSize ->getValue()[1] : 1.f,
  2657. (pResolution != NULL) ? pResolution->getValue()[0] : 5,
  2658. (pResolution != NULL) ? pResolution->getValue()[1] : 5);
  2659. pNode->setCore(pGeo);
  2660. }
  2661. }
  2662. /*-------------------------------------------------------------------------*/
  2663. /* Dump */
  2664. void VRMLGeometryObjectHelper::dump(const Char8 *)
  2665. {
  2666. }
  2667. VRMLNodeHelperFactoryBase::RegisterHelper
  2668. VRMLGeometryObjectHelper::_regHelperBox(
  2669. &VRMLGeometryObjectHelper::create,
  2670. "Box",
  2671. NULL);
  2672. VRMLNodeHelperFactoryBase::RegisterHelper
  2673. VRMLGeometryObjectHelper::_regHelperSphere(
  2674. &VRMLGeometryObjectHelper::create,
  2675. "Sphere",
  2676. NULL);
  2677. VRMLNodeHelperFactoryBase::RegisterHelper
  2678. VRMLGeometryObjectHelper::_regHelperCone(
  2679. &VRMLGeometryObjectHelper::create,
  2680. "Cone",
  2681. NULL);
  2682. VRMLNodeHelperFactoryBase::RegisterHelper
  2683. VRMLGeometryObjectHelper::_regHelperCylinder(
  2684. &VRMLGeometryObjectHelper::create,
  2685. "Cylinder",
  2686. NULL);
  2687. VRMLNodeHelperFactoryBase::RegisterHelper
  2688. VRMLGeometryObjectHelper::_regHelperTeapot(
  2689. &VRMLGeometryObjectHelper::create,
  2690. "Teapot",
  2691. NULL);
  2692. VRMLNodeHelperFactoryBase::RegisterHelper
  2693. VRMLGeometryObjectHelper::_regHelperPlane(
  2694. &VRMLGeometryObjectHelper::create,
  2695. "Plane",
  2696. NULL);
  2697. //---------------------------------------------------------------------------
  2698. // Class
  2699. //---------------------------------------------------------------------------
  2700. /*! \class OSG::VRMLTextureHelper
  2701. \ingroup GrpSystemFileIOVRML
  2702. VRML Texture description
  2703. */
  2704. /*-------------------------------------------------------------------------*/
  2705. /* Constructors */
  2706. VRMLTextureHelper::VRMLTextureHelper(void) :
  2707. Inherited (),
  2708. _defaultRepeatS(),
  2709. _defaultRepeatT(),
  2710. _repeatS (),
  2711. _repeatT ()
  2712. {
  2713. }
  2714. /*-------------------------------------------------------------------------*/
  2715. /* Destructor */
  2716. VRMLTextureHelper::~VRMLTextureHelper(void)
  2717. {
  2718. }
  2719. /*-------------------------------------------------------------------------*/
  2720. /* Helper */
  2721. /*-------------------------------------------------------------------------*/
  2722. /* Field */
  2723. bool VRMLTextureHelper::prototypeAddField(const Char8 *,
  2724. const UInt32 ,
  2725. const Char8 *szFieldname)
  2726. {
  2727. bool bFound = false;
  2728. if(osgStringCaseCmp("repeatS", szFieldname) == 0)
  2729. {
  2730. bFound = true;
  2731. }
  2732. else if(osgStringCaseCmp("repeatT", szFieldname) == 0)
  2733. {
  2734. bFound = true;
  2735. }
  2736. if(bFound == true)
  2737. {
  2738. #ifdef OSG_DEBUG_VRML
  2739. indentLog(getIndent(), PINFO);
  2740. PINFO << "ImageTextureDesc::prototypeAddField : add part "
  2741. << szFieldname
  2742. << std::endl;
  2743. #endif
  2744. return true;
  2745. }
  2746. else
  2747. {
  2748. return false;
  2749. }
  2750. }
  2751. void VRMLTextureHelper::getFieldAndDesc(
  2752. FieldContainer *,
  2753. const Char8 * szFieldname,
  2754. FieldContainer *&pFieldFC,
  2755. EditFieldHandlePtr &pField,
  2756. const FieldDescriptionBase *&pDesc)
  2757. {
  2758. pFieldFC = NULL;
  2759. pField.reset();
  2760. pDesc = NULL;
  2761. if(osgStringCaseCmp("repeatS", szFieldname) == 0)
  2762. {
  2763. if(_bProtoInterfaceDone == false)
  2764. {
  2765. pField = _sfBoolDesc.createEditHandler(&_defaultRepeatS,
  2766. NULL );
  2767. }
  2768. else
  2769. {
  2770. pField = _sfBoolDesc.createEditHandler(&_repeatS,
  2771. NULL );
  2772. }
  2773. pDesc = &_sfBoolDesc;
  2774. }
  2775. else if(osgStringCaseCmp("repeatT", szFieldname) == 0)
  2776. {
  2777. if(_bProtoInterfaceDone == false)
  2778. {
  2779. pField = _sfBoolDesc.createEditHandler(&_defaultRepeatT,
  2780. NULL );
  2781. }
  2782. else
  2783. {
  2784. pField = _sfBoolDesc.createEditHandler(&_repeatT,
  2785. NULL );
  2786. }
  2787. pDesc = &_sfBoolDesc;
  2788. }
  2789. }
  2790. /*-------------------------------------------------------------------------*/
  2791. /* Node */
  2792. FieldContainerTransitPtr VRMLTextureHelper::beginNode(
  2793. const Char8 *,
  2794. const Char8 *,
  2795. FieldContainer *)
  2796. {
  2797. TextureObjChunkTransitPtr returnValue = TextureObjChunk::create();
  2798. #ifdef OSG_DEBUG_VRML
  2799. indentLog(getIndent(), PINFO);
  2800. PINFO << "Begin Texture "
  2801. << ((returnValue == NULL) ? "invalid obj" : "valid obj")
  2802. << std::endl;
  2803. incIndent();
  2804. #endif
  2805. _repeatS = _defaultRepeatS;
  2806. _repeatT = _defaultRepeatT;
  2807. return FieldContainerTransitPtr(returnValue);
  2808. }
  2809. void VRMLTextureHelper::endNode(FieldContainer *pFC)
  2810. {
  2811. #if 0
  2812. TextureObjChunk *pTexture = NULL;
  2813. ImageUnrecPtr pImage = NULL;
  2814. pTexture = dynamic_cast<TextureObjChunk *>(pFC);
  2815. if(pTexture != NULL)
  2816. {
  2817. for(UInt32 i = 0; i < _url.size(); ++i)
  2818. {
  2819. #ifdef OSG_DEBUG_VRML
  2820. PNOTICE << "VRMLImageTextureDesc::endNode : Reading texture "
  2821. << _url[i].c_str() << std::endl;
  2822. #endif
  2823. #ifdef OSG_VRML_IMAGETEXTURE_MAP
  2824. UrlImageMap::iterator mIt = _urlImageMap.find(_url[i]);
  2825. if(mIt != _urlImageMap.end())
  2826. {
  2827. pImage = mIt->second;
  2828. }
  2829. else
  2830. {
  2831. pImage = ImageFileHandler::the()->read(_url[i].c_str());
  2832. if(pImage != NULL)
  2833. {
  2834. _urlImageMap[_url[i]] = pImage;
  2835. }
  2836. }
  2837. #else
  2838. pImage = ImageFileHandler::the()->read(_url[0].c_str());
  2839. #endif
  2840. if(pImage != NULL)
  2841. break;
  2842. }
  2843. if(pImage != NULL)
  2844. {
  2845. pImage->setForceAlphaBinary(pImage->calcIsAlphaBinary());
  2846. pTexture->setImage(pImage);
  2847. if(_repeatS.getValue() == true)
  2848. {
  2849. pTexture->setWrapS(GL_REPEAT);
  2850. }
  2851. else
  2852. {
  2853. pTexture->setWrapS(GL_CLAMP);
  2854. }
  2855. if(_repeatT.getValue() == true)
  2856. {
  2857. pTexture->setWrapT(GL_REPEAT);
  2858. }
  2859. else
  2860. {
  2861. pTexture->setWrapT(GL_CLAMP);
  2862. }
  2863. }
  2864. else
  2865. {
  2866. PWARNING << "VRMLImageTextureDesc::endNode : "
  2867. << "Couldn't read texture "
  2868. << _url[0].c_str()
  2869. << " !!!"
  2870. << std::endl;
  2871. }
  2872. }
  2873. else
  2874. {
  2875. PWARNING << "VRMLImageTextureDesc::endNode : Invalid texture ptr"
  2876. << std::endl;
  2877. }
  2878. #ifdef OSG_DEBUG_VRML
  2879. decIndent();
  2880. indentLog(getIndent(), PINFO);
  2881. PINFO << "End ImageTexture "
  2882. << _url[0].c_str() << " "
  2883. << _repeatS.getValue() << " "
  2884. << _repeatT.getValue() << " "
  2885. << &(*pFC) << std::endl;
  2886. #endif
  2887. #endif
  2888. }
  2889. /*-------------------------------------------------------------------------*/
  2890. /* Dump */
  2891. void VRMLTextureHelper::dump(const Char8 *)
  2892. {
  2893. }
  2894. //---------------------------------------------------------------------------
  2895. // Class
  2896. //---------------------------------------------------------------------------
  2897. /*! \class OSG::VRMLImageTextureHelper
  2898. \ingroup GrpSystemFileIOVRML
  2899. VRML Texture description
  2900. */
  2901. VRMLNodeHelper *VRMLImageTextureHelper::create(void)
  2902. {
  2903. return new VRMLImageTextureHelper();
  2904. }
  2905. /*-------------------------------------------------------------------------*/
  2906. /* Constructors */
  2907. VRMLImageTextureHelper::VRMLImageTextureHelper(void) :
  2908. Inherited (),
  2909. _defaultURL (),
  2910. _url ()
  2911. {
  2912. }
  2913. /*-------------------------------------------------------------------------*/
  2914. /* Destructor */
  2915. VRMLImageTextureHelper::~VRMLImageTextureHelper(void)
  2916. {
  2917. }
  2918. /*-------------------------------------------------------------------------*/
  2919. /* Helper */
  2920. /*-------------------------------------------------------------------------*/
  2921. /* Field */
  2922. bool VRMLImageTextureHelper::prototypeAddField(const Char8 *szFieldType,
  2923. const UInt32 uiFieldTypeId,
  2924. const Char8 *szFieldname )
  2925. {
  2926. bool bFound = false;
  2927. if(osgStringCaseCmp("url", szFieldname) == 0)
  2928. {
  2929. bFound = true;
  2930. }
  2931. else
  2932. {
  2933. bFound = Inherited::prototypeAddField(szFieldType,
  2934. uiFieldTypeId,
  2935. szFieldname);
  2936. }
  2937. if(bFound == true)
  2938. {
  2939. #ifdef OSG_DEBUG_VRML
  2940. indentLog(getIndent(), PINFO);
  2941. PINFO << "ImageTextureDesc::prototypeAddField : add part "
  2942. << szFieldname
  2943. << std::endl;
  2944. #endif
  2945. return true;
  2946. }
  2947. else
  2948. {
  2949. return false;
  2950. }
  2951. }
  2952. void VRMLImageTextureHelper::getFieldAndDesc(
  2953. FieldContainer * pFC,
  2954. const Char8 * szFieldname,
  2955. FieldContainer *&pFieldFC,
  2956. EditFieldHandlePtr &pField,
  2957. const FieldDescriptionBase *&pDesc)
  2958. {
  2959. pFieldFC = NULL;
  2960. pField.reset();
  2961. pDesc = NULL;
  2962. if(osgStringCaseCmp("url", szFieldname) == 0)
  2963. {
  2964. if(_bProtoInterfaceDone == false)
  2965. {
  2966. pField = _mfStringDesc.createEditHandler(&_defaultURL,
  2967. NULL );
  2968. }
  2969. else
  2970. {
  2971. pField = _mfStringDesc.createEditHandler(&_url,
  2972. NULL);
  2973. }
  2974. pDesc = &_mfStringDesc;
  2975. }
  2976. else
  2977. {
  2978. Inherited::getFieldAndDesc(pFC,
  2979. szFieldname,
  2980. pFieldFC,
  2981. pField,
  2982. pDesc);
  2983. }
  2984. }
  2985. /*-------------------------------------------------------------------------*/
  2986. /* Node */
  2987. FieldContainerTransitPtr VRMLImageTextureHelper::beginNode(
  2988. const Char8 *szTypename,
  2989. const Char8 *szName,
  2990. FieldContainer *pCurrentFC)
  2991. {
  2992. FieldContainerTransitPtr returnValue =
  2993. Inherited::beginNode(szTypename, szName, pCurrentFC);
  2994. #ifdef OSG_DEBUG_VRML
  2995. indentLog(getIndent(), PINFO);
  2996. PINFO << "Begin ImageTexture "
  2997. << ((returnValue == NULL) ? "invalid obj" : "valid obj")
  2998. << std::endl;
  2999. incIndent();
  3000. #endif
  3001. _url.clear();
  3002. return returnValue;
  3003. }
  3004. void VRMLImageTextureHelper::endNode(FieldContainer *pFC)
  3005. {
  3006. TextureObjChunk *pTexture = NULL;
  3007. ImageUnrecPtr pImage = NULL;
  3008. pTexture = dynamic_cast<TextureObjChunk *>(pFC);
  3009. if(pTexture != NULL && _url.size() != 0)
  3010. {
  3011. for(UInt32 i = 0; i < _url.size(); ++i)
  3012. {
  3013. #ifdef OSG_DEBUG_VRML
  3014. PNOTICE << "VRMLImageTextureDesc::endNode : Reading texture "
  3015. << _url[i].c_str() << std::endl;
  3016. #endif
  3017. #ifdef OSG_VRML_IMAGETEXTURE_MAP
  3018. UrlImageMap::iterator mIt = _urlImageMap.find(_url[i]);
  3019. if(mIt != _urlImageMap.end())
  3020. {
  3021. pImage = mIt->second;
  3022. }
  3023. else
  3024. {
  3025. pImage = ImageFileHandler::the()->read(_url[i].c_str());
  3026. if(pImage != NULL)
  3027. {
  3028. _urlImageMap[_url[i]] = pImage;
  3029. }
  3030. }
  3031. #else
  3032. pImage = ImageFileHandler::the()->read(_url[0].c_str());
  3033. #endif
  3034. if(pImage != NULL)
  3035. break;
  3036. }
  3037. if(pImage != NULL)
  3038. {
  3039. pImage->setForceAlphaBinary(pImage->calcIsAlphaBinary());
  3040. pTexture->setImage(pImage);
  3041. if(_repeatS.getValue() == true)
  3042. {
  3043. pTexture->setWrapS(GL_REPEAT);
  3044. }
  3045. else
  3046. {
  3047. pTexture->setWrapS(GL_CLAMP);
  3048. }
  3049. if(_repeatT.getValue() == true)
  3050. {
  3051. pTexture->setWrapT(GL_REPEAT);
  3052. }
  3053. else
  3054. {
  3055. pTexture->setWrapT(GL_CLAMP);
  3056. }
  3057. }
  3058. else
  3059. {
  3060. PWARNING << "VRMLImageTextureDesc::endNode : "
  3061. << "Couldn't read texture "
  3062. << _url[0].c_str()
  3063. << " !!!"
  3064. << std::endl;
  3065. }
  3066. }
  3067. else
  3068. {
  3069. PWARNING << "VRMLImageTextureDesc::endNode : Invalid texture ptr"
  3070. << std::endl;
  3071. }
  3072. #ifdef OSG_DEBUG_VRML
  3073. decIndent();
  3074. indentLog(getIndent(), PINFO);
  3075. PINFO << "End ImageTexture "
  3076. << _url[0].c_str() << " "
  3077. << _repeatS.getValue() << " "
  3078. << _repeatT.getValue() << " "
  3079. << &(*pFC) << std::endl;
  3080. #endif
  3081. }
  3082. /*-------------------------------------------------------------------------*/
  3083. /* Dump */
  3084. void VRMLImageTextureHelper::dump(const Char8 *)
  3085. {
  3086. }
  3087. VRMLNodeHelperFactoryBase::RegisterHelper VRMLImageTextureHelper::_regHelper(
  3088. &VRMLImageTextureHelper::create,
  3089. "ImageTexture",
  3090. NULL);
  3091. //---------------------------------------------------------------------------
  3092. // Class
  3093. //---------------------------------------------------------------------------
  3094. /*! \class OSG::VRMLPixelTextureHelper
  3095. \ingroup GrpSystemFileIOVRML
  3096. VRML Texture description
  3097. */
  3098. VRMLNodeHelper *VRMLPixelTextureHelper::create(void)
  3099. {
  3100. return new VRMLPixelTextureHelper();
  3101. }
  3102. /*-------------------------------------------------------------------------*/
  3103. /* Constructors */
  3104. VRMLPixelTextureHelper::VRMLPixelTextureHelper(void) :
  3105. Inherited( ),
  3106. _pImage (NULL)
  3107. {
  3108. }
  3109. /*-------------------------------------------------------------------------*/
  3110. /* Destructor */
  3111. VRMLPixelTextureHelper::~VRMLPixelTextureHelper(void)
  3112. {
  3113. }
  3114. /*-------------------------------------------------------------------------*/
  3115. /* Helper */
  3116. void VRMLPixelTextureHelper::addImageValue(
  3117. EditFieldHandlePtr ,
  3118. const FieldDescriptionBase *,
  3119. Image *pImage )
  3120. {
  3121. _pImage = pImage;
  3122. }
  3123. /*-------------------------------------------------------------------------*/
  3124. /* Field */
  3125. bool VRMLPixelTextureHelper::prototypeAddField(const Char8 *szFieldType,
  3126. const UInt32 uiFieldTypeId,
  3127. const Char8 *szFieldname )
  3128. {
  3129. bool bFound = false;
  3130. if(osgStringCaseCmp("image", szFieldname) == 0)
  3131. {
  3132. bFound = true;
  3133. }
  3134. else
  3135. {
  3136. bFound = Inherited::prototypeAddField(szFieldType,
  3137. uiFieldTypeId,
  3138. szFieldname);
  3139. }
  3140. if(bFound == true)
  3141. {
  3142. #ifdef OSG_DEBUG_VRML
  3143. indentLog(getIndent(), PINFO);
  3144. PINFO << "ImageTextureDesc::prototypeAddField : add part "
  3145. << szFieldname
  3146. << std::endl;
  3147. #endif
  3148. return true;
  3149. }
  3150. else
  3151. {
  3152. return false;
  3153. }
  3154. }
  3155. void VRMLPixelTextureHelper::getFieldAndDesc(
  3156. FieldContainer * pFC,
  3157. const Char8 * szFieldname,
  3158. FieldContainer *&pFieldFC,
  3159. EditFieldHandlePtr &pField,
  3160. const FieldDescriptionBase *&pDesc)
  3161. {
  3162. pFieldFC = NULL;
  3163. pField.reset();
  3164. pDesc = NULL;
  3165. if(osgStringCaseCmp("image", szFieldname) == 0)
  3166. {
  3167. pFieldFC = _pImage;
  3168. pField.reset();
  3169. pDesc = &_sfImagePtrDesc;
  3170. }
  3171. else
  3172. {
  3173. Inherited::getFieldAndDesc(pFC,
  3174. szFieldname,
  3175. pFieldFC,
  3176. pField,
  3177. pDesc);
  3178. }
  3179. }
  3180. /*-------------------------------------------------------------------------*/
  3181. /* Node */
  3182. FieldContainerTransitPtr VRMLPixelTextureHelper::beginNode(
  3183. const Char8 *szTypename,
  3184. const Char8 *szName,
  3185. FieldContainer *pCurrentFC)
  3186. {
  3187. FieldContainerTransitPtr returnValue =
  3188. Inherited::beginNode(szTypename, szName, pCurrentFC);
  3189. #ifdef OSG_DEBUG_VRML
  3190. indentLog(getIndent(), PINFO);
  3191. PINFO << "Begin PixelTexture "
  3192. << ((returnValue == NULL) ? "invalid obj" : "valid obj")
  3193. << std::endl;
  3194. incIndent();
  3195. #endif
  3196. return returnValue;
  3197. }
  3198. void VRMLPixelTextureHelper::endNode(FieldContainer *pFC)
  3199. {
  3200. TextureObjChunk *pTexture = NULL;
  3201. pTexture = dynamic_cast<TextureObjChunk *>(pFC);
  3202. if(pTexture != NULL)
  3203. {
  3204. if(_pImage != NULL)
  3205. {
  3206. _pImage->setForceAlphaBinary(_pImage->calcIsAlphaBinary());
  3207. pTexture->setImage(_pImage);
  3208. if(_repeatS.getValue() == true)
  3209. {
  3210. pTexture->setWrapS(GL_REPEAT);
  3211. }
  3212. else
  3213. {
  3214. pTexture->setWrapS(GL_CLAMP);
  3215. }
  3216. if(_repeatT.getValue() == true)
  3217. {
  3218. pTexture->setWrapT(GL_REPEAT);
  3219. }
  3220. else
  3221. {
  3222. pTexture->setWrapT(GL_CLAMP);
  3223. }
  3224. }
  3225. }
  3226. else
  3227. {
  3228. PWARNING << "VRMLPixelTextureDesc::endNode : Invalid texture ptr"
  3229. << std::endl;
  3230. }
  3231. _pImage = NULL;
  3232. #ifdef OSG_DEBUG_VRML
  3233. decIndent();
  3234. indentLog(getIndent(), PINFO);
  3235. PINFO << "End PixelTexture "
  3236. << _repeatS.getValue() << " "
  3237. << _repeatT.getValue() << " "
  3238. << &(*pFC) << std::endl;
  3239. #endif
  3240. }
  3241. /*-------------------------------------------------------------------------*/
  3242. /* Dump */
  3243. void VRMLPixelTextureHelper::dump(const Char8 *)
  3244. {
  3245. }
  3246. VRMLNodeHelperFactoryBase::RegisterHelper VRMLPixelTextureHelper::_regHelper(
  3247. &VRMLPixelTextureHelper::create,
  3248. "PixelTexture",
  3249. NULL);
  3250. //---------------------------------------------------------------------------
  3251. // Class
  3252. //---------------------------------------------------------------------------
  3253. /*! \class OSG::VRMLInlineHelper
  3254. \ingroup GrpSystemFileIOVRML
  3255. VRML Group description
  3256. */
  3257. VRMLNodeHelper *VRMLInlineHelper::create(void)
  3258. {
  3259. return new VRMLInlineHelper();
  3260. }
  3261. /*-------------------------------------------------------------------------*/
  3262. /* Constructors */
  3263. VRMLInlineHelper::VRMLInlineHelper(void) :
  3264. Inherited()
  3265. {
  3266. }
  3267. /*-------------------------------------------------------------------------*/
  3268. /* Destructor */
  3269. VRMLInlineHelper::~VRMLInlineHelper(void)
  3270. {
  3271. }
  3272. /*-------------------------------------------------------------------------*/
  3273. /* Helper */
  3274. void VRMLInlineHelper::init(const Char8 *szName)
  3275. {
  3276. Inherited::init(szName);
  3277. #ifdef OSG_DEBUG_VRML
  3278. indentLog(getIndent(), PINFO);
  3279. PINFO << "InlineHelper::init : " << szName << std::endl;
  3280. #endif
  3281. _pNodeProto = Node ::create();
  3282. _pNodeCoreProto = Inline::create();
  3283. _pGenAttProto = VRMLGenericAtt::create();
  3284. _pGenAttProto->setInternal(true);
  3285. }
  3286. /*-------------------------------------------------------------------------*/
  3287. /* Field */
  3288. void VRMLInlineHelper::endNode(FieldContainer *pFC)
  3289. {
  3290. Node *pNode = dynamic_cast<Node *>(pFC);
  3291. if(pNode != NULL)
  3292. {
  3293. Inline *pInline = dynamic_cast<Inline *>(pNode->getCore());
  3294. if(pInline != NULL)
  3295. {
  3296. pInline->postOSGLoading();
  3297. }
  3298. }
  3299. }
  3300. /*-------------------------------------------------------------------------*/
  3301. /* Dump */
  3302. void VRMLInlineHelper::dump(const Char8 *)
  3303. {
  3304. }
  3305. VRMLNodeHelperFactoryBase::RegisterHelper VRMLInlineHelper::_regHelper(
  3306. &VRMLInlineHelper::create,
  3307. "Inline",
  3308. NULL);
  3309. //---------------------------------------------------------------------------
  3310. // Class
  3311. //---------------------------------------------------------------------------
  3312. /*! \class OSG::VRMLSwitchHelper
  3313. \ingroup GrpSystemFileIOVRML
  3314. VRML Swich description
  3315. */
  3316. VRMLNodeHelper *VRMLSwitchHelper::create(void)
  3317. {
  3318. return new VRMLSwitchHelper();
  3319. }
  3320. /*-------------------------------------------------------------------------*/
  3321. /* Constructors */
  3322. VRMLSwitchHelper::VRMLSwitchHelper(void) :
  3323. Inherited()
  3324. {
  3325. }
  3326. /*-------------------------------------------------------------------------*/
  3327. /* Destructor */
  3328. VRMLSwitchHelper::~VRMLSwitchHelper(void)
  3329. {
  3330. }
  3331. /*-------------------------------------------------------------------------*/
  3332. /* Helper */
  3333. void VRMLSwitchHelper::init(const Char8 *szName)
  3334. {
  3335. Inherited::init(szName);
  3336. #ifdef OSG_DEBUG_VRML
  3337. indentLog(getIndent(), PINFO);
  3338. PINFO << "SwitchHelper::init : " << szName << std::endl;
  3339. #endif
  3340. _pNodeProto = Node ::create();
  3341. _pNodeCoreProto = Switch::create();
  3342. _pGenAttProto = VRMLGenericAtt::create();
  3343. _pGenAttProto->setInternal(true);
  3344. }
  3345. /*-------------------------------------------------------------------------*/
  3346. /* Get */
  3347. bool VRMLSwitchHelper::prototypeAddField(const Char8 *szFieldType,
  3348. const UInt32 uiFieldTypeId,
  3349. const Char8 *szFieldname)
  3350. {
  3351. bool returnValue = false;
  3352. #ifdef OSG_DEBUG_VRML
  3353. indentLog(getIndent(), PINFO);
  3354. PINFO << "VRMLSwitchHelper::prototypeAddField | add request : "
  3355. << szFieldname
  3356. << std::endl;
  3357. #endif
  3358. if(szFieldname == NULL)
  3359. return false;
  3360. incIndent();
  3361. if(osgStringCaseCmp("choice", szFieldname) == 0)
  3362. {
  3363. returnValue = true;
  3364. #ifdef OSG_DEBUG_VRML
  3365. indentLog(getIndent(), PINFO);
  3366. PINFO << "VRMLSwitchHelper::prototypeAddField | request internal : "
  3367. << szFieldname
  3368. << " "
  3369. << std::endl;
  3370. #endif
  3371. }
  3372. if(osgStringCaseCmp("whichChoice", szFieldname) == 0)
  3373. {
  3374. returnValue = true;
  3375. #ifdef OSG_DEBUG_VRML
  3376. indentLog(getIndent(), PINFO);
  3377. PINFO << "VRMLSwitchHelper::prototypeAddField | request internal : "
  3378. << szFieldname
  3379. << " "
  3380. << std::endl;
  3381. #endif
  3382. }
  3383. if(returnValue == false)
  3384. {
  3385. returnValue = Inherited::prototypeAddField(szFieldType,
  3386. uiFieldTypeId,
  3387. szFieldname);
  3388. }
  3389. #ifdef OSG_DEBUG_VRML
  3390. decIndent();
  3391. #endif
  3392. return returnValue;
  3393. }
  3394. void VRMLSwitchHelper::getFieldAndDesc(
  3395. FieldContainer * pFC,
  3396. const Char8 * szFieldname,
  3397. FieldContainer *&pFieldFC,
  3398. EditFieldHandlePtr &pField,
  3399. const FieldDescriptionBase *&pDesc)
  3400. {
  3401. if(szFieldname == NULL)
  3402. return;
  3403. if(pFC == NULL)
  3404. {
  3405. if(_bProtoInterfaceDone == false)
  3406. {
  3407. Inherited::getField(szFieldname, pFieldFC, pField, pDesc);
  3408. }
  3409. return;
  3410. }
  3411. #ifdef OSG_DEBUG_VRML
  3412. indentLog(getIndent(), PINFO);
  3413. PINFO << "VRMLSwitchHelper::getFieldAndDesc : looking for "
  3414. << szFieldname
  3415. << std::endl;
  3416. incIndent();
  3417. #endif
  3418. if(osgStringCaseCmp("choice", szFieldname) == 0)
  3419. {
  3420. #ifdef OSG_DEBUG_VRML
  3421. indentLog(getIndent(), PINFO);
  3422. PINFO << "VRMLSwitchHelper::getFieldAndDesc : request internal "
  3423. << szFieldname
  3424. << std::endl;
  3425. #endif
  3426. pFieldFC = pFC;
  3427. pField = pFC->editField("children");
  3428. pDesc = pFC->getFieldDescription("children");
  3429. }
  3430. else if(osgStringCaseCmp("whichChoice", szFieldname) == 0)
  3431. {
  3432. #ifdef OSG_DEBUG_VRML
  3433. indentLog(getIndent(), PINFO);
  3434. PINFO << "VRMLSwitchHelper::getFieldAndDesc : request internal "
  3435. << szFieldname
  3436. << std::endl;
  3437. #endif
  3438. Node *pNode = dynamic_cast<Node *>(pFC);
  3439. if(pNode != NULL)
  3440. {
  3441. if(pNode->getCore() != NULL)
  3442. {
  3443. pFieldFC = pNode->getCore();
  3444. pField = pNode->getCore()->editField("choice");
  3445. pDesc = pNode->getCore()->getFieldDescription("choice");
  3446. }
  3447. }
  3448. else
  3449. {
  3450. Inherited::getFieldAndDesc(pFC,
  3451. szFieldname,
  3452. pFC,
  3453. pField,
  3454. pDesc);
  3455. }
  3456. }
  3457. else
  3458. {
  3459. Inherited::getFieldAndDesc(pFC,
  3460. szFieldname,
  3461. pFC,
  3462. pField,
  3463. pDesc);
  3464. }
  3465. #ifdef OSG_DEBUG_VRML
  3466. decIndent();
  3467. #endif
  3468. }
  3469. /*-------------------------------------------------------------------------*/
  3470. /* Node */
  3471. /*-------------------------------------------------------------------------*/
  3472. /* Dump */
  3473. void VRMLSwitchHelper::dump(const Char8 *)
  3474. {
  3475. }
  3476. VRMLNodeHelperFactoryBase::RegisterHelper VRMLSwitchHelper::_regHelper(
  3477. &VRMLSwitchHelper::create,
  3478. "Switch",
  3479. NULL);
  3480. //---------------------------------------------------------------------------
  3481. // Generic Helper with 1:1 mapping
  3482. //---------------------------------------------------------------------------
  3483. template<>
  3484. bool VRMLGenericHelper<TimeSensor>::initStatic(void)
  3485. {
  3486. return true;
  3487. }
  3488. template<>
  3489. VRMLNodeHelperFactoryBase::RegisterHelper
  3490. VRMLGenericHelper<TimeSensor>::_regHelper(
  3491. &VRMLGenericHelper<TimeSensor>::create,
  3492. "TimeSensor",
  3493. &VRMLGenericHelper<TimeSensor>::initStatic);
  3494. OSG_INST_GENERICVRMLHELPER(TimeSensor);
  3495. template<>
  3496. bool VRMLGenericHelper<VRMLOrientationInterpolator>::initStatic(void)
  3497. {
  3498. _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
  3499. _mFieldNameMap[std::string("value" )] = std::string("outValue");
  3500. return true;
  3501. }
  3502. template<>
  3503. VRMLNodeHelperFactoryBase::RegisterHelper
  3504. VRMLGenericHelper<VRMLOrientationInterpolator>::_regHelper(
  3505. &VRMLGenericHelper<VRMLOrientationInterpolator>::create,
  3506. "OrientationInterpolator",
  3507. &VRMLGenericHelper<VRMLOrientationInterpolator>::initStatic);
  3508. OSG_INST_GENERICVRMLHELPER(VRMLOrientationInterpolator);
  3509. template<>
  3510. bool VRMLGenericHelper<VRMLPositionInterpolator>::initStatic(void)
  3511. {
  3512. _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
  3513. _mFieldNameMap[std::string("value" )] = std::string("outValue");
  3514. return true;
  3515. }
  3516. template<>
  3517. VRMLNodeHelperFactoryBase::RegisterHelper
  3518. VRMLGenericHelper<VRMLPositionInterpolator>::_regHelper(
  3519. &VRMLGenericHelper<VRMLPositionInterpolator>::create,
  3520. "PositionInterpolator",
  3521. &VRMLGenericHelper<VRMLPositionInterpolator>::initStatic);
  3522. OSG_INST_GENERICVRMLHELPER(VRMLPositionInterpolator);
  3523. template<>
  3524. bool VRMLGenericHelper<VRMLCoordinateInterpolator>::initStatic(void)
  3525. {
  3526. _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
  3527. _mFieldNameMap[std::string("value" )] = std::string("outValue");
  3528. return true;
  3529. }
  3530. template<>
  3531. VRMLNodeHelperFactoryBase::RegisterHelper
  3532. VRMLGenericHelper<VRMLCoordinateInterpolator>::_regHelper(
  3533. &VRMLGenericHelper<VRMLCoordinateInterpolator>::create,
  3534. "CoordinateInterpolator",
  3535. &VRMLGenericHelper<VRMLCoordinateInterpolator>::initStatic);
  3536. OSG_INST_GENERICVRMLHELPER(VRMLCoordinateInterpolator);
  3537. template<>
  3538. bool VRMLGenericHelper<VRMLScalarInterpolator>::initStatic(void)
  3539. {
  3540. _mFieldNameMap[std::string("fraction")] = std::string("inValue" );
  3541. _mFieldNameMap[std::string("value" )] = std::string("outValue");
  3542. return true;
  3543. }
  3544. template<>
  3545. VRMLNodeHelperFactoryBase::RegisterHelper
  3546. VRMLGenericHelper<VRMLScalarInterpolator>::_regHelper(
  3547. &VRMLGenericHelper<VRMLScalarInterpolator>::create,
  3548. "ScalarInterpolator",
  3549. &VRMLGenericHelper<VRMLScalarInterpolator>::initStatic);
  3550. OSG_INST_GENERICVRMLHELPER(VRMLScalarInterpolator);
  3551. OSG_END_NAMESPACE