POV-Ray : Newsgroups : povray.programming : MESH object fields : MESH object fields Server Time
1 Jun 2024 08:26:29 EDT (-0400)
  MESH object fields  
From: David Curtis
Date: 13 Jun 2005 09:52:07
Message: <42ad8f87@news.povray.org>
Hi. I am writing here as a last resort. I've been looking at the source for
days now and I haven't seen anything that clues me in to what I'm doing
wrong.

I'm converting a mesh object and am having problems with vertex orientation
and normals. I had hoped that it was as easy as doing this:

void Add_Mesh(MESH *pObj)
{
  VECTOR p1, p2, p3;
  VECTOR n1, n2, n3;
  MESH_TRIANGLE *mt = pObj->Data->Triangles;
  SNGL_VECT *v = pObj->Data->Vertices;
  SNGL_VECT *n = pObj->Data->Normals;
  int i, j;

  for (i = 0, j = pObj->Data->Number_Of_Triangles; i < j; i++) {
    Assign_Vector(p1, v[mt[i].P1], v[mt[i].P1], v[mt[i].P1]);
    Assign_Vector(p2, v[mt[i].P2], v[mt[i].P2], v[mt[i].P2]);
    Assign_Vector(p3, v[mt[i].P3], v[mt[i].P3], v[mt[i].P3]);
    Assign_Vector(n1, n[mt[i].N1], n[mt[i].N1], n[mt[i].N1]);
    Assign_Vector(n2, n[mt[i].N2], n[mt[i].N2], n[mt[i].N2]);
    Assign_Vector(n3, n[mt[i].N3], n[mt[i].N3], n[mt[i].N3]);

    ll->AddItem(p1, p2);
    ll->AddItem(p2, p3);
    ll->AddItem(p1, p3);
    f3l->AddItem(p1, n1, p2, n2, p3, n2);
  }
}

This code produces the correct points on the mesh but the normals seem to be 
wrong and the front side of the triangle get flipped when crossing the x = z 
plane.
The reason I'm asking this question here is i'm wondering what I can do with
the Mesh vector Perp and smooth. Can I use them to decide if I need to swap
two vertices or flip normals? I need to have the front side defined
counter-clockwise..

I'd really appreciate any help on this issue. BTW this is for a opengl patch 
i'm working on.
 Thanks, Dave.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.