Hi mate, thank you. Unfortunately that did not help. I've prepared a full example here, if you would be so kind to take a look at it:
Code: Select all
#include <irrlicht.h>
#include "SMesh.h"
#include "SMeshBuffer.h"
#include "ISceneNodeAnimator.h"
#include "CSceneNodeAnimatorCameraRTS.h"
#include <ILightSceneNode.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
int main()
{
IrrlichtDevice *device = createDevice(video::EDT_OPENGL, dimension2d<u32>(640, 480), 16, false, false, false, 0);
if (!device)
return 1;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
array<vector3df> vertices;
vertices.push_back(vector3df(-10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, -10.0f, 10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, 10.0f));
vertices.push_back(vector3df(-10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, 10.0f));
vertices.push_back(vector3df(-10.0f, -10.0f, 10.0f));
vertices.push_back(vector3df(-10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(-10.0f, -10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, -10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, -10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(-10.0f, 10.0f, 10.0f));
vertices.push_back(vector3df(10.0f, -10.0f, 10.0f));
SMesh* mesh = new SMesh();
SMeshBuffer* meshBuffer = new SMeshBuffer();
mesh->addMeshBuffer(meshBuffer);
for (u32 i = 0; i != vertices.size(); i=i+3)
{
vector3df normal = core::plane3df(vertices[i], vertices[i + 1], vertices[i + 2]).Normal;
video::SColor color(255, 255, 0, 0);
meshBuffer->Vertices.push_back(video::S3DVertex(vertices[i], normal, color, vector2df()));
meshBuffer->Vertices.push_back(video::S3DVertex(vertices[i + 1], normal, color, vector2df()));
meshBuffer->Vertices.push_back(video::S3DVertex(vertices[i + 2], normal, color, vector2df()));
meshBuffer->Indices.push_back(i);
meshBuffer->Indices.push_back(i + 1);
meshBuffer->Indices.push_back(i + 2);
}
SAnimatedMesh* animMesh = 0;
if (0 != mesh->getMeshBufferCount())
{
mesh->recalculateBoundingBox();
animMesh = new SAnimatedMesh();
animMesh->Type = EAMT_OBJ;
animMesh->addMesh(mesh);
animMesh->recalculateBoundingBox();
}
mesh->drop();
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(animMesh);
node->setMaterialFlag(EMF_LIGHTING, true);
node->setMaterialFlag(EMF_GOURAUD_SHADING, true);
node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
smgr->getMeshManipulator()->recalculateNormals(node->getMesh(), true, true);
smgr->setAmbientLight(SColorf(0, 1, 0, 1));
ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 50, 0.02);
camera->setPosition(vector3df(-50, -50, -50));
camera->setTarget(vector3df(0, 0, 0));
while (device->run())
{
driver->beginScene(true, true, SColor(255, 100, 101, 140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Firstly my cube was black (with light turned on), I've added ambient green light and now it is green. But there is no shading on it: