Moderator: coordinators


jeanphi wrote:Hi,
Ok, that confirms my guess: the vertices are rotated but not the normals, no wonder you get inconsistent normals and strange shading, but everything looks ok in 3DS. The exporter should either output a transform and keep the geometry unchanged, or it should transform both the vertices and the normals (don't apply translation to the normals though).
Jeanphi
int i, c;
// init
numfaces = 0;
isPortal = false;
isTriMesh = false;
faces = NULL;
vertices = NULL;
verticesIndex = NULL;
normals = NULL;
uvs = NULL;
Object* obj;
ObjectState os = p_node->EvalWorldState(0);
obj = os.obj;
switch(os.obj->SuperClassID())
{
case GEOMOBJECT_CLASS_ID:
TSTR s_nName(p_node->GetName());
// Convert the node geometry to a triangle based mesh
TriObject *p_triobj;
BOOL fConvertedToTriObject = obj->CanConvertToType(triObjectClassID) && (p_triobj = (TriObject*)obj->ConvertToType(0, triObjectClassID)) != NULL;
if (!fConvertedToTriObject)
return;
Mesh *p_trimesh = &p_triobj->mesh;
p_trimesh->buildNormals(); // just make sure we have vertex normals
int i_faceCount = p_trimesh->getNumFaces(); // Check how many face we have to loop for
Matrix3 m3_nodeTransform = p_node->GetObjectTM(0); // Get the node transform at frame 0
DWORD triIndex = 0;
if (i_faceCount < 1)
return;
isTriMesh = true;
name = s_nName;
material = p_node->GetMtl();
numfaces = i_faceCount;
numvertices = i_faceCount * 3;
numnormals = i_faceCount * 3;
numuvs = i_faceCount * 3;
faces = new Point3[i_faceCount];
vertices = new Point3[i_faceCount * 3];
verticesIndex = new bool[i_faceCount * 3];
normals = new Point3[i_faceCount * 3];
uvs = new Point3[i_faceCount * 3];
isPortal = false;
if (material)
{
if (material->ClassID() == LUXRENDER_PORTALMATERIAL_ID)
isPortal = true;
}
c = 0;
for (i = 0; i < i_faceCount; i++)
{
int vert;
Point3 v;
// fill face index
faces[i] = Point3(c , c + 1, c + 2);
Face* p_face = &p_trimesh->faces[i];
TVFace* p_tvface = &p_trimesh->tvFace[i];
for(vert = 0; vert < 3; vert++)
{
int id = (c + vert);
int i_vertex = p_face->getVert(vert);
vertices[id] = (p_trimesh->getVert(i_vertex)) * m3_nodeTransform;
normals[id] = GetVertexNormal(p_trimesh, i, p_trimesh->getRVertPtr(i_vertex));
normals[id].Normalize();
if (p_trimesh->numTVerts > 0)
uvs[id] = p_trimesh->getTVert(p_tvface->getTVert(vert));
}
c += 3;
}
//OptimizeFaceIndices();
}

patro wrote:I did a test on the fly....
by replacing the "normal N" value with the one of "float uv"
and it's working no shading problem on the rotated triangle mesh!
I also play in the same way with the chamfercylinder from this scene
download/file.php?id=10130&t=1
and here the resulting render
[2010-09-14 17:58:15 Error: 43] Number of "N"s for mesh must match "P"s
Users browsing this forum: No registered users and 1 guest