PageRenderTime 58ms CodeModel.GetById 19ms 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

Large files files are truncated, but you can click here to view the full file

  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. /*-------------------------------------…

Large files files are truncated, but you can click here to view the full file