POV-Ray : Newsgroups : povray.programming : Why there are no mesh creation functions? : Re: Why there are no mesh creation functions? Server Time
28 Jul 2024 14:26:43 EDT (-0400)
  Re: Why there are no mesh creation functions?  
From: Nicolas Calimet
Date: 8 Dec 2000 15:14:17
Message: <3A31520D.D69CA600@free.fr>
>   I'm making a test object which creates a triangle mesh, but I'm really
> discouraged due to the amount of work it apparently needs...

	Yes, I exactly experienced that when creating my patch based moslty
on meshes. That was a "little" pain in the *** especially since I was inves-
tigating the POV code for the first time. If you get rid off hash tables
(because creating a mesh internally) it's not *that* hard. Also there is
some redondant code when testing degenerate triangles. Exactly some kinda
garbage due to the lack of clear-and-easy functions.

	Actually, in this case (internal mesh construction), the code
is about the following - there is no garanty to work since it's only
part of my code. Hope it's useful for you... but as such it does not
solve the need of mesh creation functions.


/*---------------------------------------------------------------------*/
long          i, vertices, triangles, normals;
VECTOR        P1, P2, P3, N1, N2, N3, N;
MESH          *m;
MESH_TRIANGLE *Triangle;

/* initialize the mesh structure first */

/* mem alloc */
m->Data->Vertices = (SNGL_VECT *)POV_MALLOC(vertices * sizeof(SNGL_VECT),
    "mesh data");
m->Data->Triangles = (MESH_TRIANGLE *)POV_MALLOC(triangles *
    sizeof(MESH_TRIANGLE), "mesh data");
m->Data->Normals = (SNGL_VECT *)POV_MALLOC((normals + triangles) *
    sizeof(SNGL_VECT), "mesh data");

/* create vertices */
for(i=0; i < vertices; i++) {
  m->Data->Vertices[i][0]= float_val;
  m->Data->Vertices[i][1]= float_val;
  m->Data->Vertices[i][2]= float_val;
}

/* vertex normals only, triangle normals will be further calculated */
for(i=0; i < normals; i++) {
  m->Data->Normals[i][0]= float_val;
  m->Data->Normals[i][1]= float_val;
  m->Data->Normals[i][2]= float_val;
}

/* compute triangles */
for(i=0; i < triangles; i++) {
  Triangle = &(m->Data->Triangles[i]);
  Init_Mesh_Triangle(Triangle);

  /* get triangle indices */
  Triangle->N1 = Triangle->P1 = long_value;  /* zero-based index */
  Triangle->N2 = Triangle->P2 = long_value;
  Triangle->N3 = Triangle->P3 = long_value;

  /* get vertex coordinates and normals */
  Assign_SNGL_Vect(P1, m->Data->Vertices[Triangle->P1]);
  Assign_SNGL_Vect(P2, m->Data->Vertices[Triangle->P2]);
  Assign_SNGL_Vect(P3, m->Data->Vertices[Triangle->P3]);
  Assign_SNGL_Vect(N1, m->Data->Normals[Triangle->N1]);
  Assign_SNGL_Vect(N2, m->Data->Normals[Triangle->N2]);
  Assign_SNGL_Vect(N3, m->Data->Normals[Triangle->N3]);

  /* compute triangle normal and add it to vertex normals */
  if( Compute_Mesh_Triangle(Triangle, (smooth) ? 1:0, P1, P2, P3, N) ) {
    Assign_SNGL_Vect(m->Data->Normals[normals+i], N);
    Triangle->Normal_Ind = normals + i;
  }
}

/* now we have vertex normals + triangle normals */
m->Data->Number_Of_Normals += triangles;

/* create a global texture, should be a function */
m->Texture = Create_Texture();
m->Texture->Pigment = Create_Pigment();
m->Texture->Pigment->Type = PLAIN_PATTERN;
Assign_Colour(m->Texture->Pigment->Colour, thecolour); /* e.g. black */
m->Texture->Finish = Create_Finish();

/* bounding box */
Compute_Mesh_BBox(m);

/* parse object modifiers ... */
/*---------------------------------------------------------------------*/


*** Nicolas Calimet
*** http://pov4grasp.free.fr


Post a reply to this message

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