About Store Forum Documentation Contact



Post Reply 
Rendering Custom Mesh Material Problem
Author Message
fatcoder Offline
Member

Post: #1
Rendering Custom Mesh Material Problem
I'm trying to render my own custom mesh (that I've created in code), but I can't get a material to show for it. It always just renders as the default white.

Basically I have a source mesh that I'm creating a MeshBase from like this.

Code:
MeshBase mb;
mb.create(srcMesh.parts(0).render);

I then create my own custom Mesh and add the MeshBase to it like this.

Code:
Mesh m;
m.add(mb);
m.setRender();

Finally, in the render function I'm doing this to render my custom mesh with the given material... nothing all that special.

Code:
m.setMaterial(Materials("Mtrl/Rock/0.mtrl"));
m.draw(MatrixIdentity);

For some reason, the mesh always just renders white. My material works fine as I can use it on other meshes no problem. It just doesn't show on this custom mesh. So obviously I'm setting up the custom mesh incorrectly. What am I doing wrong?
03-22-2011 02:01 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Rendering Custom Mesh Material Problem
Hi, at first look it seems ok.

but please call setMaterial not inside rendering, but after creating the mesh.
also after creating meshbase from MeshRender, check if it has texture coordinates (mb.vtx.tex is not null)
is 'srcMesh.parts(0)' ok? if you setMaterial for srcMesh.parts(0) and draw srcMesh.parts(0) instead of mesh, does it have material?
03-22-2011 02:43 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #3
RE: Rendering Custom Mesh Material Problem
I had a feeling it might have something to do with texture coordinates. It appears as though mb.vtx.tex0 doesn't have texture coordinates for any of the vertices.

If I try either of these, it works fine. Both the source mesh and the first mesh part render fine with the material applied.

Code:
srcMesh.setMaterial(Materials("Mtrl/Rock/0.mtrl"));
srcMesh.draw(MatrixIdentity);

Code:
MeshPart &part = srcMesh.parts(0);
part.setMaterial(Materials("Mtrl/Rock/0.mtrl"));
part.draw(MatrixIdentity);

The problem only seems to happen when I try creating my own MeshBase from the source's render mesh. The MeshBase only seems to have pos, nrm and color data for each vertex. It doesn't bring across texture coordinates. How do I ensure the texture coordinates come across too?

If it helps, my source mesh is actually the first mesh from an Area MeshGroup (i.e. a world Area).
03-22-2011 03:09 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Rendering Custom Mesh Material Problem
Ah, MeshRender from Area Terrain doesn't have texture coordinates.
after creating meshbase from meshrender you need to manually setup tex coords:
mb.texMap(..)
03-22-2011 03:37 PM
Find all posts by this user Quote this message in a reply
Post Reply