OpenGEXImporter.cpp 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2016, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER
  34. #include "OpenGEXImporter.h"
  35. #include "DefaultIOSystem.h"
  36. #include <assimp/DefaultLogger.hpp>
  37. #include "MakeVerboseFormat.h"
  38. #include "StringComparison.h"
  39. #include <openddlparser/OpenDDLParser.h>
  40. #include <assimp/scene.h>
  41. #include <assimp/ai_assert.h>
  42. #include <vector>
  43. static const std::string OpenGexExt = "ogex";
  44. static const aiImporterDesc desc = {
  45. "Open Game Engine Exchange",
  46. "",
  47. "",
  48. "",
  49. aiImporterFlags_SupportTextFlavour,
  50. 0,
  51. 0,
  52. 0,
  53. 0,
  54. OpenGexExt.c_str()
  55. };
  56. namespace Grammar {
  57. static const std::string MetricType = "Metric";
  58. static const std::string Metric_DistanceType = "distance";
  59. static const std::string Metric_AngleType = "angle";
  60. static const std::string Metric_TimeType = "time";
  61. static const std::string Metric_UpType = "up";
  62. static const std::string NameType = "Name";
  63. static const std::string ObjectRefType = "ObjectRef";
  64. static const std::string MaterialRefType = "MaterialRef";
  65. static const std::string MetricKeyType = "key";
  66. static const std::string GeometryNodeType = "GeometryNode";
  67. static const std::string CameraNodeType = "CameraNode";
  68. static const std::string LightNodeType = "LightNode";
  69. static const std::string GeometryObjectType = "GeometryObject";
  70. static const std::string CameraObjectType = "CameraObject";
  71. static const std::string LightObjectType = "LightObject";
  72. static const std::string TransformType = "Transform";
  73. static const std::string MeshType = "Mesh";
  74. static const std::string VertexArrayType = "VertexArray";
  75. static const std::string IndexArrayType = "IndexArray";
  76. static const std::string MaterialType = "Material";
  77. static const std::string ColorType = "Color";
  78. static const std::string ParamType = "Param";
  79. static const std::string TextureType = "Texture";
  80. static const std::string AttenType = "Atten";
  81. static const std::string DiffuseColorToken = "diffuse";
  82. static const std::string SpecularColorToken = "specular";
  83. static const std::string EmissionColorToken = "emission";
  84. static const std::string DiffuseTextureToken = "diffuse";
  85. static const std::string DiffuseSpecularTextureToken = "specular";
  86. static const std::string SpecularPowerTextureToken = "specular_power";
  87. static const std::string EmissionTextureToken = "emission";
  88. static const std::string OpacyTextureToken = "opacity";
  89. static const std::string TransparencyTextureToken = "transparency";
  90. static const std::string NormalTextureToken = "normal";
  91. enum TokenType {
  92. NoneType = -1,
  93. MetricToken,
  94. NameToken,
  95. ObjectRefToken,
  96. MaterialRefToken,
  97. MetricKeyToken,
  98. GeometryNodeToken,
  99. CameraNodeToken,
  100. LightNodeToken,
  101. GeometryObjectToken,
  102. CameraObjectToken,
  103. LightObjectToken,
  104. TransformToken,
  105. MeshToken,
  106. VertexArrayToken,
  107. IndexArrayToken,
  108. MaterialToken,
  109. ColorToken,
  110. ParamToken,
  111. TextureToken,
  112. AttenToken
  113. };
  114. static const std::string ValidMetricToken[ 4 ] = {
  115. Metric_DistanceType,
  116. Metric_AngleType,
  117. Metric_TimeType,
  118. Metric_UpType
  119. };
  120. static int isValidMetricType( const char *token ) {
  121. if( nullptr == token ) {
  122. return false;
  123. }
  124. int idx( -1 );
  125. for( size_t i = 0; i < 4; i++ ) {
  126. if( ValidMetricToken[ i ] == token ) {
  127. idx = (int) i;
  128. break;
  129. }
  130. }
  131. return idx;
  132. }
  133. static TokenType matchTokenType( const char *tokenType ) {
  134. if( MetricType == tokenType ) {
  135. return MetricToken;
  136. } else if( NameType == tokenType ) {
  137. return NameToken;
  138. } else if( ObjectRefType == tokenType ) {
  139. return ObjectRefToken;
  140. } else if( MaterialRefType == tokenType ) {
  141. return MaterialRefToken;
  142. } else if( MetricKeyType == tokenType ) {
  143. return MetricKeyToken;
  144. } else if ( GeometryNodeType == tokenType ) {
  145. return GeometryNodeToken;
  146. } else if ( CameraNodeType == tokenType ) {
  147. return CameraNodeToken;
  148. } else if ( LightNodeType == tokenType ) {
  149. return LightNodeToken;
  150. } else if ( GeometryObjectType == tokenType ) {
  151. return GeometryObjectToken;
  152. } else if ( CameraObjectType == tokenType ) {
  153. return CameraObjectToken;
  154. } else if ( LightObjectType == tokenType ) {
  155. return LightObjectToken;
  156. } else if( TransformType == tokenType ) {
  157. return TransformToken;
  158. } else if( MeshType == tokenType ) {
  159. return MeshToken;
  160. } else if( VertexArrayType == tokenType ) {
  161. return VertexArrayToken;
  162. } else if( IndexArrayType == tokenType ) {
  163. return IndexArrayToken;
  164. } else if( MaterialType == tokenType ) {
  165. return MaterialToken;
  166. } else if ( ColorType == tokenType ) {
  167. return ColorToken;
  168. } else if ( ParamType == tokenType ) {
  169. return ParamToken;
  170. } else if( TextureType == tokenType ) {
  171. return TextureToken;
  172. } else if ( AttenType == tokenType ) {
  173. return AttenToken;
  174. }
  175. return NoneType;
  176. }
  177. } // Namespace Grammar
  178. namespace Assimp {
  179. namespace OpenGEX {
  180. USE_ODDLPARSER_NS
  181. //------------------------------------------------------------------------------------------------
  182. static void propId2StdString( Property *prop, std::string &name, std::string &key ) {
  183. name = key = "";
  184. if ( nullptr == prop ) {
  185. return;
  186. }
  187. if ( nullptr != prop->m_key ) {
  188. name = prop->m_key->m_buffer;
  189. if ( Value::ddl_string == prop->m_value->m_type ) {
  190. key = prop->m_value->getString();
  191. }
  192. }
  193. }
  194. //------------------------------------------------------------------------------------------------
  195. OpenGEXImporter::VertexContainer::VertexContainer()
  196. : m_numVerts( 0 )
  197. , m_vertices( nullptr )
  198. , m_numColors( 0 )
  199. , m_colors( nullptr )
  200. , m_numNormals( 0 )
  201. , m_normals( nullptr )
  202. , m_numUVComps()
  203. , m_textureCoords() {
  204. // empty
  205. }
  206. //------------------------------------------------------------------------------------------------
  207. OpenGEXImporter::VertexContainer::~VertexContainer() {
  208. delete[] m_vertices;
  209. delete[] m_colors;
  210. delete[] m_normals;
  211. for(auto &texcoords : m_textureCoords) {
  212. delete [] texcoords;
  213. }
  214. }
  215. //------------------------------------------------------------------------------------------------
  216. OpenGEXImporter::RefInfo::RefInfo( aiNode *node, Type type, std::vector<std::string> &names )
  217. : m_node( node )
  218. , m_type( type )
  219. , m_Names( names ) {
  220. // empty
  221. }
  222. //------------------------------------------------------------------------------------------------
  223. OpenGEXImporter::RefInfo::~RefInfo() {
  224. // empty
  225. }
  226. //------------------------------------------------------------------------------------------------
  227. OpenGEXImporter::OpenGEXImporter()
  228. : m_root( nullptr )
  229. , m_nodeChildMap()
  230. , m_meshCache()
  231. , m_mesh2refMap()
  232. , m_ctx( nullptr )
  233. , m_metrics()
  234. , m_currentNode( nullptr )
  235. , m_currentVertices()
  236. , m_currentMesh( nullptr )
  237. , m_currentMaterial( nullptr )
  238. , m_currentLight( nullptr )
  239. , m_currentCamera( nullptr )
  240. , m_tokenType( Grammar::NoneType )
  241. , m_materialCache()
  242. , m_cameraCache()
  243. , m_lightCache()
  244. , m_nodeStack()
  245. , m_unresolvedRefStack() {
  246. // empty
  247. }
  248. //------------------------------------------------------------------------------------------------
  249. OpenGEXImporter::~OpenGEXImporter() {
  250. m_ctx = nullptr;
  251. }
  252. //------------------------------------------------------------------------------------------------
  253. bool OpenGEXImporter::CanRead( const std::string &file, IOSystem *pIOHandler, bool checkSig ) const {
  254. bool canRead( false );
  255. if( !checkSig ) {
  256. canRead = SimpleExtensionCheck( file, OpenGexExt.c_str() );
  257. } else {
  258. static const char *token[] = { "Metric", "GeometryNode", "VertexArray (attrib", "IndexArray" };
  259. canRead = BaseImporter::SearchFileHeaderForToken( pIOHandler, file, token, 4 );
  260. }
  261. return canRead;
  262. }
  263. //------------------------------------------------------------------------------------------------
  264. void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pScene, IOSystem *pIOHandler ) {
  265. // open source file
  266. IOStream *file = pIOHandler->Open( filename, "rb" );
  267. if( !file ) {
  268. throw DeadlyImportError( "Failed to open file " + filename );
  269. }
  270. std::vector<char> buffer;
  271. TextFileToBuffer( file, buffer );
  272. OpenDDLParser myParser;
  273. myParser.setBuffer( &buffer[ 0 ], buffer.size() );
  274. bool success( myParser.parse() );
  275. if( success ) {
  276. m_ctx = myParser.getContext();
  277. pScene->mRootNode = new aiNode;
  278. pScene->mRootNode->mName.Set( filename );
  279. handleNodes( m_ctx->m_root, pScene );
  280. }
  281. copyMeshes( pScene );
  282. copyCameras( pScene );
  283. copyLights( pScene );
  284. resolveReferences();
  285. createNodeTree( pScene );
  286. }
  287. //------------------------------------------------------------------------------------------------
  288. const aiImporterDesc *OpenGEXImporter::GetInfo() const {
  289. return &desc;
  290. }
  291. //------------------------------------------------------------------------------------------------
  292. void OpenGEXImporter::SetupProperties( const Importer *pImp ) {
  293. if( nullptr == pImp ) {
  294. return;
  295. }
  296. }
  297. //------------------------------------------------------------------------------------------------
  298. void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
  299. if( nullptr == node ) {
  300. return;
  301. }
  302. DDLNode::DllNodeList childs = node->getChildNodeList();
  303. for( DDLNode::DllNodeList::iterator it = childs.begin(); it != childs.end(); ++it ) {
  304. Grammar::TokenType tokenType( Grammar::matchTokenType( ( *it )->getType().c_str() ) );
  305. switch( tokenType ) {
  306. case Grammar::MetricToken:
  307. handleMetricNode( *it, pScene );
  308. break;
  309. case Grammar::NameToken:
  310. handleNameNode( *it, pScene );
  311. break;
  312. case Grammar::ObjectRefToken:
  313. handleObjectRefNode( *it, pScene );
  314. break;
  315. case Grammar::MaterialRefToken:
  316. handleMaterialRefNode( *it, pScene );
  317. break;
  318. case Grammar::MetricKeyToken:
  319. break;
  320. case Grammar::GeometryNodeToken:
  321. handleGeometryNode( *it, pScene );
  322. break;
  323. case Grammar::CameraNodeToken:
  324. handleCameraNode( *it, pScene );
  325. break;
  326. case Grammar::LightNodeToken:
  327. handleLightNode( *it, pScene );
  328. break;
  329. case Grammar::GeometryObjectToken:
  330. handleGeometryObject( *it, pScene );
  331. break;
  332. case Grammar::CameraObjectToken:
  333. handleCameraObject( *it, pScene );
  334. break;
  335. case Grammar::LightObjectToken:
  336. handleLightObject( *it, pScene );
  337. break;
  338. case Grammar::TransformToken:
  339. handleTransformNode( *it, pScene );
  340. break;
  341. case Grammar::MeshToken:
  342. handleMeshNode( *it, pScene );
  343. break;
  344. case Grammar::VertexArrayToken:
  345. handleVertexArrayNode( *it, pScene );
  346. break;
  347. case Grammar::IndexArrayToken:
  348. handleIndexArrayNode( *it, pScene );
  349. break;
  350. case Grammar::MaterialToken:
  351. handleMaterialNode( *it, pScene );
  352. break;
  353. case Grammar::ColorToken:
  354. handleColorNode( *it, pScene );
  355. break;
  356. case Grammar::ParamToken:
  357. handleParamNode( *it, pScene );
  358. break;
  359. case Grammar::TextureToken:
  360. handleTextureNode( *it, pScene );
  361. break;
  362. default:
  363. break;
  364. }
  365. }
  366. }
  367. //------------------------------------------------------------------------------------------------
  368. void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
  369. if( nullptr == node || nullptr == m_ctx ) {
  370. return;
  371. }
  372. if( m_ctx->m_root != node->getParent() ) {
  373. return;
  374. }
  375. Property *prop( node->getProperties() );
  376. while( nullptr != prop ) {
  377. if( nullptr != prop->m_key ) {
  378. if( Value::ddl_string == prop->m_value->m_type ) {
  379. std::string valName( ( char* ) prop->m_value->m_data );
  380. int type( Grammar::isValidMetricType( valName.c_str() ) );
  381. if( Grammar::NoneType != type ) {
  382. Value *val( node->getValue() );
  383. if( nullptr != val ) {
  384. if( Value::ddl_float == val->m_type ) {
  385. m_metrics[ type ].m_floatValue = val->getFloat();
  386. } else if( Value::ddl_int32 == val->m_type ) {
  387. m_metrics[ type ].m_intValue = val->getInt32();
  388. } else if( Value::ddl_string == val->m_type ) {
  389. m_metrics[type].m_stringValue = std::string( val->getString() );
  390. } else {
  391. throw DeadlyImportError( "OpenGEX: invalid data type for Metric node." );
  392. }
  393. }
  394. }
  395. }
  396. }
  397. prop = prop->m_next;
  398. }
  399. }
  400. //------------------------------------------------------------------------------------------------
  401. void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) {
  402. if( nullptr == m_currentNode ) {
  403. throw DeadlyImportError( "No current node for name." );
  404. return;
  405. }
  406. Value *val( node->getValue() );
  407. if( nullptr != val ) {
  408. if( Value::ddl_string != val->m_type ) {
  409. throw DeadlyImportError( "OpenGEX: invalid data type for value in node name." );
  410. return;
  411. }
  412. const std::string name( val->getString() );
  413. if( m_tokenType == Grammar::GeometryNodeToken || m_tokenType == Grammar::LightNodeToken
  414. || m_tokenType == Grammar::CameraNodeToken ) {
  415. m_currentNode->mName.Set( name.c_str() );
  416. } else if( m_tokenType == Grammar::MaterialToken ) {
  417. }
  418. }
  419. }
  420. //------------------------------------------------------------------------------------------------
  421. static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
  422. ai_assert( nullptr != node );
  423. Reference *ref = node->getReferences();
  424. if( nullptr != ref ) {
  425. for( size_t i = 0; i < ref->m_numRefs; i++ ) {
  426. Name *currentName( ref->m_referencedName[ i ] );
  427. if( nullptr != currentName && nullptr != currentName->m_id ) {
  428. const std::string name( currentName->m_id->m_buffer );
  429. if( !name.empty() ) {
  430. names.push_back( name );
  431. }
  432. }
  433. }
  434. }
  435. }
  436. //------------------------------------------------------------------------------------------------
  437. void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
  438. if( nullptr == m_currentNode ) {
  439. throw DeadlyImportError( "No parent node for name." );
  440. return;
  441. }
  442. std::vector<std::string> objRefNames;
  443. getRefNames( node, objRefNames );
  444. // when we are dealing with a geometry node prepare the mesh cache
  445. if ( m_tokenType == Grammar::GeometryNodeToken ) {
  446. m_currentNode->mNumMeshes = static_cast<unsigned int>(objRefNames.size());
  447. m_currentNode->mMeshes = new unsigned int[ objRefNames.size() ];
  448. if ( !objRefNames.empty() ) {
  449. m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
  450. }
  451. }
  452. }
  453. //------------------------------------------------------------------------------------------------
  454. void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  455. if( nullptr == m_currentNode ) {
  456. throw DeadlyImportError( "No parent node for name." );
  457. return;
  458. }
  459. std::vector<std::string> matRefNames;
  460. getRefNames( node, matRefNames );
  461. if( !matRefNames.empty() ) {
  462. m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MaterialRef, matRefNames ) );
  463. }
  464. }
  465. //------------------------------------------------------------------------------------------------
  466. void OpenGEXImporter::handleGeometryNode( DDLNode *node, aiScene *pScene ) {
  467. aiNode *newNode = new aiNode;
  468. pushNode( newNode, pScene );
  469. m_tokenType = Grammar::GeometryNodeToken;
  470. m_currentNode = newNode;
  471. handleNodes( node, pScene );
  472. popNode();
  473. }
  474. //------------------------------------------------------------------------------------------------
  475. void OpenGEXImporter::handleCameraNode( DDLNode *node, aiScene *pScene ) {
  476. aiCamera *camera( new aiCamera );
  477. m_cameraCache.push_back( camera );
  478. m_currentCamera = camera;
  479. aiNode *newNode = new aiNode;
  480. pushNode( newNode, pScene );
  481. m_tokenType = Grammar::CameraNodeToken;
  482. m_currentNode = newNode;
  483. handleNodes( node, pScene );
  484. popNode();
  485. m_currentCamera->mName.Set( newNode->mName.C_Str() );
  486. }
  487. //------------------------------------------------------------------------------------------------
  488. void OpenGEXImporter::handleLightNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  489. aiLight *light( new aiLight );
  490. m_lightCache.push_back( light );
  491. m_currentLight = light;
  492. aiNode *newNode = new aiNode;
  493. m_tokenType = Grammar::LightNodeToken;
  494. m_currentNode = newNode;
  495. pushNode( newNode, pScene );
  496. handleNodes( node, pScene );
  497. popNode();
  498. m_currentLight->mName.Set( newNode->mName.C_Str() );
  499. }
  500. //------------------------------------------------------------------------------------------------
  501. void OpenGEXImporter::handleGeometryObject( DDLNode *node, aiScene *pScene ) {
  502. // parameters will be parsed normally in the tree, so just go for it
  503. handleNodes( node, pScene );
  504. }
  505. //------------------------------------------------------------------------------------------------
  506. void OpenGEXImporter::handleCameraObject( ODDLParser::DDLNode *node, aiScene *pScene ) {
  507. // parameters will be parsed normally in the tree, so just go for it
  508. handleNodes( node, pScene );
  509. }
  510. //------------------------------------------------------------------------------------------------
  511. void OpenGEXImporter::handleLightObject( ODDLParser::DDLNode *node, aiScene *pScene ) {
  512. Property *prop( node->findPropertyByName( "type" ) );
  513. if ( nullptr != prop ) {
  514. if ( nullptr != prop->m_value ) {
  515. std::string typeStr( prop->m_value->getString() );
  516. if ( "point" == typeStr ) {
  517. m_currentLight->mType = aiLightSource_POINT;
  518. } else if ( "spot" == typeStr ) {
  519. m_currentLight->mType = aiLightSource_SPOT;
  520. } else if ( "infinite" == typeStr ) {
  521. m_currentLight->mType = aiLightSource_DIRECTIONAL;
  522. }
  523. }
  524. }
  525. // parameters will be parsed normally in the tree, so just go for it
  526. handleNodes( node, pScene );
  527. }
  528. //------------------------------------------------------------------------------------------------
  529. static void setMatrix( aiNode *node, DataArrayList *transformData ) {
  530. ai_assert( nullptr != node );
  531. ai_assert( nullptr != transformData );
  532. float m[ 16 ];
  533. size_t i( 1 );
  534. Value *next( transformData->m_dataList->m_next );
  535. m[ 0 ] = transformData->m_dataList->getFloat();
  536. while( next != nullptr ) {
  537. m[ i ] = next->getFloat();
  538. next = next->m_next;
  539. i++;
  540. }
  541. node->mTransformation.a1 = m[ 0 ];
  542. node->mTransformation.a2 = m[ 4 ];
  543. node->mTransformation.a3 = m[ 8 ];
  544. node->mTransformation.a4 = m[ 12 ];
  545. node->mTransformation.b1 = m[ 1 ];
  546. node->mTransformation.b2 = m[ 5 ];
  547. node->mTransformation.b3 = m[ 9 ];
  548. node->mTransformation.b4 = m[ 13 ];
  549. node->mTransformation.c1 = m[ 2 ];
  550. node->mTransformation.c2 = m[ 6 ];
  551. node->mTransformation.c3 = m[ 10 ];
  552. node->mTransformation.c4 = m[ 14 ];
  553. node->mTransformation.d1 = m[ 3 ];
  554. node->mTransformation.d2 = m[ 7 ];
  555. node->mTransformation.d3 = m[ 11 ];
  556. node->mTransformation.d4 = m[ 15 ];
  557. }
  558. //------------------------------------------------------------------------------------------------
  559. void OpenGEXImporter::handleTransformNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  560. if( nullptr == m_currentNode ) {
  561. throw DeadlyImportError( "No parent node for name." );
  562. return;
  563. }
  564. DataArrayList *transformData( node->getDataArrayList() );
  565. if( nullptr != transformData ) {
  566. if( transformData->m_numItems != 16 ) {
  567. throw DeadlyImportError( "Invalid number of data for transform matrix." );
  568. return;
  569. }
  570. setMatrix( m_currentNode, transformData );
  571. }
  572. }
  573. //------------------------------------------------------------------------------------------------
  574. void OpenGEXImporter::handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  575. m_currentMesh = new aiMesh;
  576. const size_t meshidx( m_meshCache.size() );
  577. m_meshCache.push_back( m_currentMesh );
  578. Property *prop = node->getProperties();
  579. if( nullptr != prop ) {
  580. std::string propName, propKey;
  581. propId2StdString( prop, propName, propKey );
  582. if( "primitive" == propName ) {
  583. if ( "points" == propKey ) {
  584. m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_POINT;
  585. } else if ( "lines" == propKey ) {
  586. m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
  587. } else if( "triangles" == propKey ) {
  588. m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
  589. } else if ( "quads" == propKey ) {
  590. m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON;
  591. } else {
  592. DefaultLogger::get()->warn( propKey + " is not supported primitive type." );
  593. }
  594. }
  595. }
  596. handleNodes( node, pScene );
  597. DDLNode *parent( node->getParent() );
  598. if( nullptr != parent ) {
  599. const std::string &name = parent->getName();
  600. m_mesh2refMap[ name ] = meshidx;
  601. }
  602. }
  603. //------------------------------------------------------------------------------------------------
  604. enum MeshAttribute {
  605. None,
  606. Position,
  607. Color,
  608. Normal,
  609. TexCoord
  610. };
  611. //------------------------------------------------------------------------------------------------
  612. static MeshAttribute getAttributeByName( const char *attribName ) {
  613. ai_assert( nullptr != attribName );
  614. if ( 0 == strncmp( "position", attribName, strlen( "position" ) ) ) {
  615. return Position;
  616. } else if ( 0 == strncmp( "color", attribName, strlen( "color" ) ) ) {
  617. return Color;
  618. } else if( 0 == strncmp( "normal", attribName, strlen( "normal" ) ) ) {
  619. return Normal;
  620. } else if( 0 == strncmp( "texcoord", attribName, strlen( "texcoord" ) ) ) {
  621. return TexCoord;
  622. }
  623. return None;
  624. }
  625. //------------------------------------------------------------------------------------------------
  626. static void fillVector3( aiVector3D *vec3, Value *vals ) {
  627. ai_assert( nullptr != vec3 );
  628. ai_assert( nullptr != vals );
  629. float x( 0.0f ), y( 0.0f ), z( 0.0f );
  630. Value *next( vals );
  631. x = next->getFloat();
  632. next = next->m_next;
  633. y = next->getFloat();
  634. next = next->m_next;
  635. if( nullptr != next ) {
  636. z = next->getFloat();
  637. }
  638. vec3->Set( x, y, z );
  639. }
  640. //------------------------------------------------------------------------------------------------
  641. static void fillColor4( aiColor4D *col4, Value *vals ) {
  642. ai_assert( nullptr != col4 );
  643. ai_assert( nullptr != vals );
  644. Value *next( vals );
  645. col4->r = next->getFloat();
  646. next = next->m_next;
  647. col4->g = next->getFloat();
  648. next = next->m_next;
  649. col4->b = next->getFloat();
  650. next = next->m_next;
  651. col4->a = next->getFloat();
  652. }
  653. //------------------------------------------------------------------------------------------------
  654. static size_t countDataArrayListItems( DataArrayList *vaList ) {
  655. size_t numItems( 0 );
  656. if( nullptr == vaList ) {
  657. return numItems;
  658. }
  659. DataArrayList *next( vaList );
  660. while( nullptr != next ) {
  661. if( nullptr != vaList->m_dataList ) {
  662. numItems++;
  663. }
  664. next = next->m_next;
  665. }
  666. return numItems;
  667. }
  668. //------------------------------------------------------------------------------------------------
  669. static void copyVectorArray( size_t numItems, DataArrayList *vaList, aiVector3D *vectorArray ) {
  670. for( size_t i = 0; i < numItems; i++ ) {
  671. Value *next( vaList->m_dataList );
  672. fillVector3( &vectorArray[ i ], next );
  673. vaList = vaList->m_next;
  674. }
  675. }
  676. //------------------------------------------------------------------------------------------------
  677. static void copyColor4DArray( size_t numItems, DataArrayList *vaList, aiColor4D *colArray ) {
  678. for ( size_t i = 0; i < numItems; i++ ) {
  679. Value *next( vaList->m_dataList );
  680. fillColor4( &colArray[ i ], next );
  681. }
  682. }
  683. //------------------------------------------------------------------------------------------------
  684. void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  685. if( nullptr == node ) {
  686. throw DeadlyImportError( "No parent node for name." );
  687. return;
  688. }
  689. Property *prop( node->getProperties() );
  690. if( nullptr != prop ) {
  691. std::string propName, propKey;
  692. propId2StdString( prop, propName, propKey );
  693. MeshAttribute attribType( getAttributeByName( propKey.c_str() ) );
  694. if( None == attribType ) {
  695. return;
  696. }
  697. DataArrayList *vaList = node->getDataArrayList();
  698. if( nullptr == vaList ) {
  699. return;
  700. }
  701. const size_t numItems( countDataArrayListItems( vaList ) );
  702. if( Position == attribType ) {
  703. m_currentVertices.m_numVerts = numItems;
  704. m_currentVertices.m_vertices = new aiVector3D[ numItems ];
  705. copyVectorArray( numItems, vaList, m_currentVertices.m_vertices );
  706. } else if ( Color == attribType ) {
  707. m_currentVertices.m_numColors = numItems;
  708. m_currentVertices.m_colors = new aiColor4D[ numItems ];
  709. copyColor4DArray( numItems, vaList, m_currentVertices.m_colors );
  710. } else if( Normal == attribType ) {
  711. m_currentVertices.m_numNormals = numItems;
  712. m_currentVertices.m_normals = new aiVector3D[ numItems ];
  713. copyVectorArray( numItems, vaList, m_currentVertices.m_normals );
  714. } else if( TexCoord == attribType ) {
  715. m_currentVertices.m_numUVComps[ 0 ] = numItems;
  716. m_currentVertices.m_textureCoords[ 0 ] = new aiVector3D[ numItems ];
  717. copyVectorArray( numItems, vaList, m_currentVertices.m_textureCoords[ 0 ] );
  718. }
  719. }
  720. }
  721. //------------------------------------------------------------------------------------------------
  722. void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  723. if( nullptr == node ) {
  724. throw DeadlyImportError( "No parent node for name." );
  725. return;
  726. }
  727. if( nullptr == m_currentMesh ) {
  728. throw DeadlyImportError( "No current mesh for index data found." );
  729. return;
  730. }
  731. DataArrayList *vaList = node->getDataArrayList();
  732. if( nullptr == vaList ) {
  733. return;
  734. }
  735. const size_t numItems( countDataArrayListItems( vaList ) );
  736. m_currentMesh->mNumFaces = static_cast<unsigned int>(numItems);
  737. m_currentMesh->mFaces = new aiFace[ numItems ];
  738. m_currentMesh->mNumVertices = static_cast<unsigned int>(numItems * 3);
  739. m_currentMesh->mVertices = new aiVector3D[ m_currentMesh->mNumVertices ];
  740. bool hasColors( false );
  741. if ( m_currentVertices.m_numColors > 0 ) {
  742. m_currentMesh->mColors[0] = new aiColor4D[ m_currentVertices.m_numColors ];
  743. hasColors = true;
  744. }
  745. bool hasNormalCoords( false );
  746. if ( m_currentVertices.m_numNormals > 0 ) {
  747. m_currentMesh->mNormals = new aiVector3D[ m_currentMesh->mNumVertices ];
  748. hasNormalCoords = true;
  749. }
  750. bool hasTexCoords( false );
  751. if ( m_currentVertices.m_numUVComps[ 0 ] > 0 ) {
  752. m_currentMesh->mTextureCoords[ 0 ] = new aiVector3D[ m_currentMesh->mNumVertices ];
  753. hasTexCoords = true;
  754. }
  755. unsigned int index( 0 );
  756. for( size_t i = 0; i < m_currentMesh->mNumFaces; i++ ) {
  757. aiFace &current( m_currentMesh->mFaces[ i ] );
  758. current.mNumIndices = 3;
  759. current.mIndices = new unsigned int[ current.mNumIndices ];
  760. Value *next( vaList->m_dataList );
  761. for( size_t indices = 0; indices < current.mNumIndices; indices++ ) {
  762. const int idx( next->getUnsignedInt32() );
  763. ai_assert( static_cast<size_t>( idx ) <= m_currentVertices.m_numVerts );
  764. ai_assert( index < m_currentMesh->mNumVertices );
  765. aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] );
  766. m_currentMesh->mVertices[ index ].Set( pos.x, pos.y, pos.z );
  767. if ( hasColors ) {
  768. aiColor4D &col = m_currentVertices.m_colors[ idx ];
  769. m_currentMesh->mColors[ 0 ][ index ] = col;
  770. }
  771. if ( hasNormalCoords ) {
  772. aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] );
  773. m_currentMesh->mNormals[ index ].Set( normal.x, normal.y, normal.z );
  774. }
  775. if ( hasTexCoords ) {
  776. aiVector3D &tex = ( m_currentVertices.m_textureCoords[ 0 ][ idx ] );
  777. m_currentMesh->mTextureCoords[ 0 ][ index ].Set( tex.x, tex.y, tex.z );
  778. }
  779. current.mIndices[ indices ] = index;
  780. index++;
  781. next = next->m_next;
  782. }
  783. vaList = vaList->m_next;
  784. }
  785. }
  786. //------------------------------------------------------------------------------------------------
  787. static void getColorRGB( aiColor3D *pColor, DataArrayList *colList ) {
  788. if( nullptr == pColor || nullptr == colList ) {
  789. return;
  790. }
  791. ai_assert( 3 == colList->m_numItems );
  792. Value *val( colList->m_dataList );
  793. pColor->r = val->getFloat();
  794. val = val->getNext();
  795. pColor->g = val->getFloat();
  796. val = val->getNext();
  797. pColor->b = val->getFloat();
  798. }
  799. //------------------------------------------------------------------------------------------------
  800. enum ColorType {
  801. NoneColor = 0,
  802. DiffuseColor,
  803. SpecularColor,
  804. EmissionColor,
  805. LightColor
  806. };
  807. //------------------------------------------------------------------------------------------------
  808. static ColorType getColorType( Text *id ) {
  809. if ( nullptr == id ) {
  810. return NoneColor;
  811. }
  812. if( *id == Grammar::DiffuseColorToken ) {
  813. return DiffuseColor;
  814. } else if( *id == Grammar::SpecularColorToken ) {
  815. return SpecularColor;
  816. } else if( *id == Grammar::EmissionColorToken ) {
  817. return EmissionColor;
  818. } else if ( *id == "light" ) {
  819. return LightColor;
  820. }
  821. return NoneColor;
  822. }
  823. //------------------------------------------------------------------------------------------------
  824. void OpenGEXImporter::handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  825. m_currentMaterial = new aiMaterial;
  826. m_materialCache.push_back( m_currentMaterial );
  827. m_tokenType = Grammar::MaterialToken;
  828. handleNodes( node, pScene );
  829. }
  830. //------------------------------------------------------------------------------------------------
  831. void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  832. if( nullptr == node ) {
  833. return;
  834. }
  835. Property *prop = node->findPropertyByName( "attrib" );
  836. if( nullptr != prop ) {
  837. if( nullptr != prop->m_value ) {
  838. DataArrayList *colList( node->getDataArrayList() );
  839. if( nullptr == colList ) {
  840. return;
  841. }
  842. aiColor3D col;
  843. getColorRGB( &col, colList );
  844. const ColorType colType( getColorType( prop->m_key ) );
  845. if( DiffuseColor == colType ) {
  846. m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_DIFFUSE );
  847. } else if( SpecularColor == colType ) {
  848. m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_SPECULAR );
  849. } else if( EmissionColor == colType ) {
  850. m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_EMISSIVE );
  851. } else if ( LightColor == colType ) {
  852. m_currentLight->mColorDiffuse = col;
  853. }
  854. }
  855. }
  856. }
  857. //------------------------------------------------------------------------------------------------
  858. void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  859. if( nullptr == node ) {
  860. return;
  861. }
  862. Property *prop = node->findPropertyByName( "attrib" );
  863. if( nullptr != prop ) {
  864. if( nullptr != prop->m_value ) {
  865. Value *val( node->getValue() );
  866. if( nullptr != val ) {
  867. aiString tex;
  868. tex.Set( val->getString() );
  869. if( prop->m_value->getString() == Grammar::DiffuseTextureToken ) {
  870. m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
  871. } else if( prop->m_value->getString() == Grammar::SpecularPowerTextureToken ) {
  872. m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_SPECULAR( 0 ) );
  873. } else if( prop->m_value->getString() == Grammar::EmissionTextureToken ) {
  874. m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_EMISSIVE( 0 ) );
  875. } else if( prop->m_value->getString() == Grammar::OpacyTextureToken ) {
  876. m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_OPACITY( 0 ) );
  877. } else if( prop->m_value->getString() == Grammar::TransparencyTextureToken ) {
  878. // ToDo!
  879. // m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
  880. } else if( prop->m_value->getString() == Grammar::NormalTextureToken ) {
  881. m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_NORMALS( 0 ) );
  882. } else {
  883. ai_assert( false );
  884. }
  885. }
  886. }
  887. }
  888. }
  889. //------------------------------------------------------------------------------------------------
  890. void OpenGEXImporter::handleParamNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  891. if ( nullptr == node ) {
  892. return;
  893. }
  894. Property *prop = node->findPropertyByName( "attrib" );
  895. if ( nullptr == prop ) {
  896. return;
  897. }
  898. if ( nullptr != prop->m_value ) {
  899. Value *val( node->getValue() );
  900. if ( nullptr == val ) {
  901. return;
  902. }
  903. const float floatVal( val->getFloat() );
  904. if ( prop->m_value != nullptr ) {
  905. if ( 0 == ASSIMP_strincmp( "fov", prop->m_value->getString(), 3 ) ) {
  906. m_currentCamera->mHorizontalFOV = floatVal;
  907. } else if ( 0 == ASSIMP_strincmp( "near", prop->m_value->getString(), 3 ) ) {
  908. m_currentCamera->mClipPlaneNear = floatVal;
  909. } else if ( 0 == ASSIMP_strincmp( "far", prop->m_value->getString(), 3 ) ) {
  910. m_currentCamera->mClipPlaneFar = floatVal;
  911. }
  912. }
  913. }
  914. }
  915. //------------------------------------------------------------------------------------------------
  916. void OpenGEXImporter::handleAttenNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
  917. if ( nullptr == node ) {
  918. return;
  919. }
  920. Property *prop = node->findPropertyByName( "curve" );
  921. if ( nullptr != prop ) {
  922. if ( nullptr != prop->m_value ) {
  923. Value *val( node->getValue() );
  924. const float floatVal( val->getFloat() );
  925. if ( 0 == strncmp( "scale", prop->m_value->getString(), strlen( "scale" ) ) ) {
  926. m_currentLight->mAttenuationQuadratic = floatVal;
  927. }
  928. }
  929. }
  930. }
  931. //------------------------------------------------------------------------------------------------
  932. void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
  933. ai_assert( nullptr != pScene );
  934. if( m_meshCache.empty() ) {
  935. return;
  936. }
  937. pScene->mNumMeshes = static_cast<unsigned int>(m_meshCache.size());
  938. pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ];
  939. std::copy( m_meshCache.begin(), m_meshCache.end(), pScene->mMeshes );
  940. }
  941. //------------------------------------------------------------------------------------------------
  942. void OpenGEXImporter::copyCameras( aiScene *pScene ) {
  943. ai_assert( nullptr != pScene );
  944. if ( m_cameraCache.empty() ) {
  945. return;
  946. }
  947. pScene->mNumCameras = static_cast<unsigned int>(m_cameraCache.size());
  948. pScene->mCameras = new aiCamera*[ pScene->mNumCameras ];
  949. std::copy( m_cameraCache.begin(), m_cameraCache.end(), pScene->mCameras );
  950. }
  951. //------------------------------------------------------------------------------------------------
  952. void OpenGEXImporter::copyLights( aiScene *pScene ) {
  953. ai_assert( nullptr != pScene );
  954. if ( m_lightCache.empty() ) {
  955. return;
  956. }
  957. pScene->mNumLights = static_cast<unsigned int>(m_lightCache.size());
  958. pScene->mLights = new aiLight*[ pScene->mNumLights ];
  959. std::copy( m_lightCache.begin(), m_lightCache.end(), pScene->mLights );
  960. }
  961. //------------------------------------------------------------------------------------------------
  962. void OpenGEXImporter::resolveReferences() {
  963. if( m_unresolvedRefStack.empty() ) {
  964. return;
  965. }
  966. RefInfo *currentRefInfo( nullptr );
  967. for( std::vector<RefInfo*>::iterator it = m_unresolvedRefStack.begin(); it != m_unresolvedRefStack.end(); ++it ) {
  968. currentRefInfo = *it;
  969. if( nullptr != currentRefInfo ) {
  970. aiNode *node( currentRefInfo->m_node );
  971. if( RefInfo::MeshRef == currentRefInfo->m_type ) {
  972. for( size_t i = 0; i < currentRefInfo->m_Names.size(); i++ ) {
  973. const std::string &name( currentRefInfo->m_Names[ i ] );
  974. ReferenceMap::const_iterator it( m_mesh2refMap.find( name ) );
  975. if( m_mesh2refMap.end() != it ) {
  976. unsigned int meshIdx = static_cast<unsigned int>(m_mesh2refMap[ name ]);
  977. node->mMeshes[ i ] = meshIdx;
  978. }
  979. }
  980. } else if( RefInfo::MaterialRef == currentRefInfo->m_type ) {
  981. // ToDo!
  982. } else {
  983. throw DeadlyImportError( "Unknown reference info to resolve." );
  984. }
  985. }
  986. }
  987. }
  988. //------------------------------------------------------------------------------------------------
  989. void OpenGEXImporter::createNodeTree( aiScene *pScene ) {
  990. if( nullptr == m_root ) {
  991. return;
  992. }
  993. if( m_root->m_children.empty() ) {
  994. return;
  995. }
  996. pScene->mRootNode->mNumChildren = static_cast<unsigned int>(m_root->m_children.size());
  997. pScene->mRootNode->mChildren = new aiNode*[ pScene->mRootNode->mNumChildren ];
  998. std::copy( m_root->m_children.begin(), m_root->m_children.end(), pScene->mRootNode->mChildren );
  999. }
  1000. //------------------------------------------------------------------------------------------------
  1001. void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
  1002. ai_assert( nullptr != pScene );
  1003. if ( nullptr == node ) {
  1004. return;
  1005. }
  1006. ChildInfo *info( nullptr );
  1007. if( m_nodeStack.empty() ) {
  1008. node->mParent = pScene->mRootNode;
  1009. NodeChildMap::iterator it( m_nodeChildMap.find( node->mParent ) );
  1010. if( m_nodeChildMap.end() == it ) {
  1011. info = new ChildInfo;
  1012. m_root = info;
  1013. m_nodeChildMap[ node->mParent ] = info;
  1014. } else {
  1015. info = it->second;
  1016. }
  1017. info->m_children.push_back( node );
  1018. } else {
  1019. aiNode *parent( m_nodeStack.back() );
  1020. ai_assert( nullptr != parent );
  1021. node->mParent = parent;
  1022. NodeChildMap::iterator it( m_nodeChildMap.find( node->mParent ) );
  1023. if( m_nodeChildMap.end() == it ) {
  1024. info = new ChildInfo;
  1025. m_nodeChildMap[ node->mParent ] = info;
  1026. } else {
  1027. info = it->second;
  1028. }
  1029. info->m_children.push_back( node );
  1030. }
  1031. m_nodeStack.push_back( node );
  1032. }
  1033. //------------------------------------------------------------------------------------------------
  1034. aiNode *OpenGEXImporter::popNode() {
  1035. if( m_nodeStack.empty() ) {
  1036. return nullptr;
  1037. }
  1038. aiNode *node( top() );
  1039. m_nodeStack.pop_back();
  1040. return node;
  1041. }
  1042. //------------------------------------------------------------------------------------------------
  1043. aiNode *OpenGEXImporter::top() const {
  1044. if( m_nodeStack.empty() ) {
  1045. return nullptr;
  1046. }
  1047. return m_nodeStack.back();
  1048. }
  1049. //------------------------------------------------------------------------------------------------
  1050. void OpenGEXImporter::clearNodeStack() {
  1051. m_nodeStack.clear();
  1052. }
  1053. //------------------------------------------------------------------------------------------------
  1054. } // Namespace OpenGEX
  1055. } // Namespace Assimp
  1056. #endif // ASSIMP_BUILD_NO_OPENGEX_IMPORTER