I succeeded in creating a procedural mesh with everything I need (vertices, uv, normals, tangents and color information). But I can’t seem to make it cast any shadow. I’m setting the castShadow property to true on the mesh instance, but this doesn’t seem to make any difference.
var meshint = new pc.MeshInstance(node, mesh, material);
meshint.castShadow = true;
model.meshInstances.push(meshint);
Anybody with an idea about how to make a mesh cast shadows?
Ok, by stepping through the engine code I found out that on adding a model to a modelcomponent all the meshinstance properties concerning shadows are overwritten by the modelcomponent properties. So the solution is:
var node = new pc.GraphNode();
var model = new pc.Model();
model.graph = node;
//build mesh
this.entity.addComponent('model');
this.entity.model.castShadows = true;
this.entity.model.model = model;
Now I still have a problem left, the shadows look terrible as you can see in the screenshot (note that the back wall is completely flat, so why it is showing that pattern, I have no clue :s)
Thanks Will, I’ll go trough them! Also thanks for your post concerning the castShadows property. Your solution of adding the properties through the constructor looks cleaner!