Irrlicht中使用createHillPlaneMesh创建地面无显示问题求助
Troubleshooting Irrlicht Hill Plane Not Rendering
Hey there, let's get to the bottom of why your generated hill plane isn't showing up! After looking through your code, I can spot a couple of key missing steps and tweaks needed to get that floor rendering properly.
Key Issues in Your addMapFloor Function
- You created a mesh but didn't add it to the scene: The
createHillPlaneMeshmethod only generates raw mesh data—it doesn't create a visible scene node that Irrlicht can render. You need to explicitly add this mesh to the scene manager as a mesh node. - Material handling has unnecessary overhead and missing settings: You're allocating a new
SMaterialbut not attaching it correctly, and you're skipping critical material flags (like disabling lighting, which can make unlit objects invisible by default).
Fixed addMapFloor Code
Here's the revised function that addresses these issues:
void Eo::Scene::addMapFloor() { irr::core::dimension2d<irr::f32> tileSize(100.0, 100.0); irr::core::dimension2d<irr::u32> tileCount(50, 50); irr::f32 hillHeight = 0; irr::core::dimension2d<irr::f32> countHills(20.0, 20.0); irr::core::dimension2d<irr::f32> textureRepeatCount(1.0, 1.0); // Create the hill plane mesh (we'll use the node's built-in material instead of allocating a new one) irr::scene::IMesh* floorMesh = _sceneManager->getGeometryCreator()->createHillPlaneMesh( tileSize, tileCount, nullptr, hillHeight, countHills, textureRepeatCount); if (!floorMesh) { // Handle mesh creation failure if needed return; } // Add the mesh as a scene node to make it visible in the scene irr::scene::IMeshSceneNode* floorNode = _sceneManager->addMeshSceneNode(floorMesh); if (!floorNode) { // Clean up mesh if node creation fails to avoid memory leaks floorMesh->drop(); return; } // Configure material settings for visibility floorNode->setMaterialFlag(irr::video::EMF_LIGHTING, false); // Disable lighting (critical for unlit objects) floorNode->setMaterialFlag(irr::video::EMF_WIREFRAME, true); // Keep your wireframe mode floorNode->getMaterial(0).ColorMaterial = irr::video::ECP_BLUE; // Set the blue color material // Optional: Add the same texture as your cubes if wanted // floorNode->setMaterialTexture(0, _device.get_driver()->getTexture("../assets/img/texture.jpg")); // Drop the mesh since the scene node now holds a reference to it floorMesh->drop(); }
Additional Checks to Ensure Visibility
- Verify Camera Position: Make sure your camera is positioned above the ground plane (e.g.,
camera->setPosition(irr::core::vector3df(0, 100.0f, -200.0f))andcamera->setTarget(irr::core::vector3df(0, 0, 0))). If the camera is below or behind the plane, you won't see it. - Check Mesh Scale: Your plane is 5000x5000 units (50 tiles × 100 units each). Ensure your camera's field of view and position are set to capture this large area.
- Memory Management: Always call
drop()on meshes after adding them to a scene node—this avoids memory leaks since the scene node takes ownership of the mesh once added.
内容的提问来源于stack exchange,提问作者Benjamin Sx
相关产品推荐
相关产品推荐

