fork download
  1. scene::IAnimatedMesh* IrrlichtManager::LoadMesh(const Config& config, const c8* filename, bool animated)
  2. {
  3. if ( !filename || !strlen(filename) )
  4. return NULL;
  5.  
  6. u32 beginTime = GetIrrlichtTimer()->getRealTime();
  7.  
  8. io::path extension;
  9. core::getFileNameExtension(extension, filename);
  10. extension.make_lower();
  11.  
  12. // some models might want special handling
  13. // bool isLmo = (extension == ".lmo");
  14. bool isX = (extension == ".x");
  15.  
  16. // load a mesh into the engine
  17. bool wasCached = IsMeshInCache(filename);
  18. scene::IAnimatedMesh* m = mSceneManager->getMesh(filename);
  19. if (!m)
  20. {
  21. return NULL;
  22. }
  23. //fprintf(stderr, "loaded mesh %s\n", filename);
  24.  
  25. if ( !wasCached )
  26. {
  27. LOG.DebugLn("Time meshloading: ", core::stringc(GetIrrlichtTimer()->getRealTime() - beginTime).c_str());
  28.  
  29. // Let's fix some stuff which couldn't easily be set in the modeling tool (or would have gotten lost on export)
  30. SetMaterialTypeByTextureName(m, video::EMT_TRANSPARENT_ALPHA_CHANNEL, "alpha");
  31. SetMaterialTypeByTextureName(m, video::EMT_SOLID, "race_light01");
  32. SetMaterialTypeByTextureName(m, video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF, "mask");
  33.  
  34. if ( isX && animated )
  35. {
  36. SetSpecularMaterial(m, 0, 0, 0);
  37. }
  38.  
  39. setMaterialFlags(config, m);
  40.  
  41. // must be after SetMaterialTypeByTextureName as it replaces those materials again
  42. SetES2ShaderMaterials(m);
  43.  
  44. if ( !animated )
  45. {
  46. // Reduce number of vertices by welding those which are identical.
  47. // TODO: There might be a way to preprocess that, but probably difficult without changing the file-format.
  48. // Because I have the suspicion those are create by the obj loader and are not cause by duplicates in the obj file itself (it also has some - but I don't think that many)
  49. // So maybe another solution would be fixing that in the obj loader (or maybe it's fixed there already just not in the lmo loader? Not tried.)
  50. u32 weldTime = GetIrrlichtTimer()->getRealTime();
  51. //scene::IMesh * weldedMesh = mSceneManager->getMeshManipulator()->createMeshWelded(m->getMesh(0)); // too slow
  52. scene::IMesh * weldedMesh = ExtIrr::CreateMeshWelded(m->getMesh(0));
  53. LOG.DebugLn("Time createMeshWelded: ", core::stringc(GetIrrlichtTimer()->getRealTime() - weldTime).c_str());
  54. weldTime = GetIrrlichtTimer()->getRealTime();
  55. scene::IAnimatedMesh* m2 = mSceneManager->getMeshManipulator()->createAnimatedMesh(weldedMesh, m->getMeshType ());
  56. weldedMesh->drop();
  57. weldedMesh = NULL;
  58. LOG.DebugLn("Time createAnimatedMesh: ", core::stringc(GetIrrlichtTimer()->getRealTime() - weldTime).c_str());
  59. if ( m2 )
  60. {
  61. LOG.DebugLn("Old num vertices: ", core::stringc(getMeshVertexCount(m)).c_str());
  62. LOG.DebugLn("New num vertices: ", core::stringc(getMeshVertexCount(m2)).c_str());
  63. scene::IMeshCache * meshCache = mSceneManager->getMeshCache ();
  64. meshCache->removeMesh(m);
  65. meshCache->addMesh(filename, m2);
  66. m = m2;
  67. m2->drop();
  68. m2 = NULL;
  69. }
  70.  
  71. // In our case only the .X files are animated. So all others can be static
  72. m->getMesh(0)->setHardwareMappingHint(scene::EHM_STATIC, scene::EBT_VERTEX_AND_INDEX);
  73. }
  74. else
  75. {
  76. // Don't actually notice any speed difference when setting this.
  77. m->getMesh(0)->setHardwareMappingHint(scene::EHM_STATIC, scene::EBT_INDEX);
  78. }
  79. }
  80.  
  81. return m;
  82. }
  83.  
  84.  
  85. scene::ISceneNode* IrrlichtManager::LoadModel(const Config& config, const c8* fileModel, scene::ITriangleSelector** createSelector)
  86. {
  87. u32 beginTime = GetIrrlichtTimer()->getRealTime();
  88.  
  89. scene::IAnimatedMesh* m = LoadMesh(config, fileModel, false);
  90. if (!m)
  91. {
  92. return NULL;
  93. }
  94.  
  95. // set default material properties
  96. scene::ISceneNode* meshResult = NULL;
  97.  
  98. // Octree might still make sense if EHM_STATIC doesn't work on a platform.
  99. // But needs profiling and a way to figure out _if_ EHM_STATIC does not work (unfortunately some Android devices seem to lie about it).
  100. // meshResult = mSceneManager->addOctreeSceneNode(m, /*parent*/NULL, /*id*/-1, /*minimalPolysPerNode*/ 128);
  101. meshResult = mSceneManager->addMeshSceneNode(m);
  102.  
  103. if ( createSelector )
  104. {
  105. *createSelector = meshResult->getTriangleSelector();
  106. if ( *createSelector )
  107. {
  108. (*createSelector)->grab();
  109. }
  110. else
  111. {
  112. LOG.LogLn(LP_WARN, "mesh had no triangle selector: ", fileModel);
  113.  
  114. // We got no loopings, so we can be sure we never collide against triangles with normals pointing downwards.
  115. // So we can kick them out and only collide against the rest.
  116. scene::IMesh * reducedMesh = ExtIrr::CreateSubMeshForNormal(m->getMesh(0), irr::core::vector3df(0, 1, 0), -0.5f);
  117.  
  118. // create some fitting triangle-selector. Best choice depends a lot on level layout.
  119. //*createSelector = mSceneManager->createOctreeTriangleSelector(reducedMesh, meshResult, 32 );
  120.  
  121. float cellSize = config.GetHoverRadius() * 2.f + 1.f; // We know we use radius*2 in physics - so this way never more than 4 cells are checked
  122. *createSelector = new GridTriangleSelector(reducedMesh, meshResult, cellSize);
  123.  
  124. reducedMesh->drop();
  125. LOG.DebugLn("Time created selector: ", core::stringc(GetIrrlichtTimer()->getRealTime() - beginTime).c_str());
  126. }
  127. }
  128.  
  129. meshResult->setName(fileModel); // Having the name makes debugging a lot easier
  130. meshResult->setAutomaticCulling(scene::EAC_BOX); // EAC_OFF EAC_BOX EAC_FRUSTUM_BOX EAC_FRUSTUM_SPHERE
  131. meshResult->setDebugDataVisible(false);
  132.  
  133. // LOG.DebugLn("Time LoadModel sum: ", core::stringc(GetIrrlichtTimer()->getRealTime() - beginTime).c_str());
  134.  
  135. return meshResult;
  136. }
  137.  
  138. scene::IAnimatedMeshSceneNode* IrrlichtManager::LoadAnimatedModel(const Config& config, const c8* fileModel)
  139. {
  140. // load a model-mesh into the engine
  141. scene::IAnimatedMesh* m = LoadMesh(config, fileModel, true);
  142. if (!m)
  143. {
  144. return NULL;
  145. }
  146. //printf("loaded model %s\n", filename_);
  147.  
  148. // set default material properties
  149. scene::IAnimatedMeshSceneNode* meshResult = NULL;
  150. meshResult = mSceneManager->addAnimatedMeshSceneNode(m);
  151.  
  152. meshResult->setDebugDataVisible(false);
  153. meshResult->setAutomaticCulling(scene::EAC_OFF); // EAC_OFF EAC_BOX EAC_FRUSTUM_BOX EAC_FRUSTUM_SPHERE
  154.  
  155. return meshResult;
  156. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘scene’ does not name a type
 scene::IAnimatedMesh* IrrlichtManager::LoadMesh(const Config& config, const c8* filename, bool animated)
 ^
prog.cpp:85:1: error: ‘scene’ does not name a type
 scene::ISceneNode* IrrlichtManager::LoadModel(const Config& config, const c8* fileModel, scene::ITriangleSelector** createSelector)
 ^
prog.cpp:138:1: error: ‘scene’ does not name a type
 scene::IAnimatedMeshSceneNode* IrrlichtManager::LoadAnimatedModel(const Config& config, const c8* fileModel)
 ^
stdout
Standard output is empty