I seem to be unable to get materials with normal maps defined to show up when I have a custom geometry created from scratch. Works just fine with a material with only a diffuse map, but when you add the normal map, all you get is a black model. Attached is a quick test I made. It has one box model (created from Box.mdl) and one quad that is created from scratch. The box shows the material just fine, but the quad end up black. Any idea what’s going on?
Node* boxNode = scene_->CreateChild("Box");
boxNode->SetPosition(Vector3(0, 0, 0));
Model* boxModel = cache->GetResource<Model>("Models/Box.mdl");
StaticModel* boxObject = boxNode->CreateComponent<StaticModel>();
boxObject->SetModel(boxModel);
Material *material = cache->GetResource<Material>("Materials/Stone.xml");
boxObject->SetMaterial(material);
const unsigned numVertices = 6;
float vertexData[] = {
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f
};
const unsigned short indexData[] = {
0, 1, 2,
3, 4, 5
};
SharedPtr<Model> fromScratchModel(new Model(context_));
SharedPtr<VertexBuffer> vb(new VertexBuffer(context_));
SharedPtr<IndexBuffer> ib(new IndexBuffer(context_));
SharedPtr<Geometry> geom(new Geometry(context_));
vb->SetShadowed(true);
vb->SetSize(numVertices, MASK_POSITION|MASK_NORMAL|MASK_TEXCOORD1);
vb->SetData(vertexData);
ib->SetShadowed(true);
ib->SetSize(numVertices, false);
ib->SetData(indexData);
geom->SetVertexBuffer(0, vb);
geom->SetIndexBuffer(ib);
geom->SetDrawRange(TRIANGLE_LIST, 0, numVertices);
fromScratchModel->SetNumGeometries(1);
fromScratchModel->SetGeometry(0, 0, geom);
fromScratchModel->SetBoundingBox(BoundingBox(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f)));
Node* node = scene_->CreateChild("FromScratchObject");
node->SetPosition(Vector3(0.0f, 2.0f, 0.0f));
StaticModel* object = node->CreateComponent<StaticModel>();
object->SetModel(fromScratchModel);
Material *mat = cache->GetResource<Material>("Materials/Stone.xml");
object->SetMaterial(mat);