mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-17 07:50:24 +01:00
Handle missing 3d models in example 07
No more crashing if some models are not found git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6435 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
41f2f8654f
commit
b3fff12423
@ -200,19 +200,20 @@ int main()
|
|||||||
selection is being performed. */
|
selection is being performed. */
|
||||||
scene::IAnimatedMeshSceneNode* node = 0;
|
scene::IAnimatedMeshSceneNode* node = 0;
|
||||||
|
|
||||||
video::SMaterial material;
|
|
||||||
|
|
||||||
// Add an MD2 node, which uses vertex-based animation.
|
// Add an MD2 node, which uses vertex-based animation.
|
||||||
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "faerie.md2"),
|
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "faerie.md2"),
|
||||||
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
|
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
|
||||||
|
if ( node )
|
||||||
|
{
|
||||||
node->setPosition(core::vector3df(-90,-15,-140)); // Put its feet on the floor.
|
node->setPosition(core::vector3df(-90,-15,-140)); // Put its feet on the floor.
|
||||||
node->setScale(core::vector3df(1.6f)); // Make it appear realistically scaled
|
node->setScale(core::vector3df(1.6f)); // Make it appear realistically scaled
|
||||||
node->setMD2Animation(scene::EMAT_POINT);
|
node->setMD2Animation(scene::EMAT_POINT);
|
||||||
node->setAnimationSpeed(20.f);
|
node->setAnimationSpeed(20.f);
|
||||||
|
video::SMaterial& material = node->getMaterial(0);
|
||||||
material.setTexture(0, driver->getTexture(mediaPath + "faerie2.bmp"));
|
material.setTexture(0, driver->getTexture(mediaPath + "faerie2.bmp"));
|
||||||
material.Lighting = true;
|
material.Lighting = true;
|
||||||
material.NormalizeNormals = true;
|
material.NormalizeNormals = true;
|
||||||
node->getMaterial(0) = material;
|
}
|
||||||
|
|
||||||
// Now create a triangle selector for it. The selector will know that it
|
// Now create a triangle selector for it. The selector will know that it
|
||||||
// is associated with an animated node, and will update itself as necessary.
|
// is associated with an animated node, and will update itself as necessary.
|
||||||
@ -223,6 +224,8 @@ int main()
|
|||||||
// And this B3D file uses skinned skeletal animation.
|
// And this B3D file uses skinned skeletal animation.
|
||||||
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "ninja.b3d"),
|
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "ninja.b3d"),
|
||||||
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
|
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
|
||||||
|
if ( node )
|
||||||
|
{
|
||||||
node->setScale(core::vector3df(10));
|
node->setScale(core::vector3df(10));
|
||||||
node->setPosition(core::vector3df(-75,-66,-80));
|
node->setPosition(core::vector3df(-75,-66,-80));
|
||||||
node->setRotation(core::vector3df(0,90,0));
|
node->setRotation(core::vector3df(0,90,0));
|
||||||
@ -233,10 +236,13 @@ int main()
|
|||||||
selector = smgr->createTriangleSelector(node, separateMeshBuffers);
|
selector = smgr->createTriangleSelector(node, separateMeshBuffers);
|
||||||
node->setTriangleSelector(selector);
|
node->setTriangleSelector(selector);
|
||||||
selector->drop();
|
selector->drop();
|
||||||
|
}
|
||||||
|
|
||||||
// This X files uses skeletal animation, but without skinning.
|
// This X files uses skeletal animation, but without skinning.
|
||||||
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "dwarf.x"),
|
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "dwarf.x"),
|
||||||
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
|
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
|
||||||
|
if ( node )
|
||||||
|
{
|
||||||
node->setPosition(core::vector3df(-70,-66,-30)); // Put its feet on the floor.
|
node->setPosition(core::vector3df(-70,-66,-30)); // Put its feet on the floor.
|
||||||
node->setRotation(core::vector3df(0,-90,0)); // And turn it towards the camera.
|
node->setRotation(core::vector3df(0,-90,0)); // And turn it towards the camera.
|
||||||
node->setAnimationSpeed(20.f);
|
node->setAnimationSpeed(20.f);
|
||||||
@ -244,10 +250,13 @@ int main()
|
|||||||
selector = smgr->createTriangleSelector(node, separateMeshBuffers);
|
selector = smgr->createTriangleSelector(node, separateMeshBuffers);
|
||||||
node->setTriangleSelector(selector);
|
node->setTriangleSelector(selector);
|
||||||
selector->drop();
|
selector->drop();
|
||||||
|
}
|
||||||
|
|
||||||
// And this mdl file uses skinned skeletal animation.
|
// And this mdl file uses skinned skeletal animation.
|
||||||
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "yodan.mdl"),
|
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "yodan.mdl"),
|
||||||
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
|
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
|
||||||
|
if ( node )
|
||||||
|
{
|
||||||
node->setPosition(core::vector3df(-90,-25,20));
|
node->setPosition(core::vector3df(-90,-25,20));
|
||||||
node->setScale(core::vector3df(0.8f));
|
node->setScale(core::vector3df(0.8f));
|
||||||
node->getMaterial(0).Lighting = true;
|
node->getMaterial(0).Lighting = true;
|
||||||
@ -257,9 +266,7 @@ int main()
|
|||||||
selector = smgr->createTriangleSelector(node, separateMeshBuffers);
|
selector = smgr->createTriangleSelector(node, separateMeshBuffers);
|
||||||
node->setTriangleSelector(selector);
|
node->setTriangleSelector(selector);
|
||||||
selector->drop();
|
selector->drop();
|
||||||
|
}
|
||||||
material.setTexture(0, 0);
|
|
||||||
material.Lighting = false;
|
|
||||||
|
|
||||||
// Add a light, so that the unselected nodes aren't completely dark.
|
// Add a light, so that the unselected nodes aren't completely dark.
|
||||||
scene::ILightSceneNode * light = smgr->addLightSceneNode(0, core::vector3df(-60,100,400),
|
scene::ILightSceneNode * light = smgr->addLightSceneNode(0, core::vector3df(-60,100,400),
|
||||||
@ -271,7 +278,9 @@ int main()
|
|||||||
scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
|
scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
|
||||||
|
|
||||||
// draw the selection triangle only as wireframe
|
// draw the selection triangle only as wireframe
|
||||||
material.Wireframe=true;
|
irr::video::SMaterial materialWireframe;
|
||||||
|
materialWireframe.Lighting = false;
|
||||||
|
materialWireframe.Wireframe=true;
|
||||||
|
|
||||||
while(device->run())
|
while(device->run())
|
||||||
if (device->isWindowActive())
|
if (device->isWindowActive())
|
||||||
@ -320,7 +329,7 @@ int main()
|
|||||||
|
|
||||||
// We need to reset the transform before doing our own rendering.
|
// We need to reset the transform before doing our own rendering.
|
||||||
driver->setTransform(video::ETS_WORLD, core::matrix4());
|
driver->setTransform(video::ETS_WORLD, core::matrix4());
|
||||||
driver->setMaterial(material);
|
driver->setMaterial(materialWireframe);
|
||||||
driver->draw3DTriangle(hitResult.Triangle, video::SColor(0,255,0,0)); // Show which triangle has been hit
|
driver->draw3DTriangle(hitResult.Triangle, video::SColor(0,255,0,0)); // Show which triangle has been hit
|
||||||
|
|
||||||
// We can check the flags for the scene node that was hit to see if it should be
|
// We can check the flags for the scene node that was hit to see if it should be
|
||||||
|
Loading…
Reference in New Issue
Block a user