|
Trouble implementing marching cubes
#447240
11/28/14 02:44
11/28/14 02:44
|
Joined: Oct 2003
Posts: 4,131
Matt_Aufderheide
OP
Expert
|
OP
Expert
Joined: Oct 2003
Posts: 4,131
|
i'm trying to implement marching cubes using Paul Bourke's code example:http://paulbourke.net/geometry/polygonise/
I can get everything to compile and actually create a mesh using the TUST dynamic model functions...seems to sort of work except all the faces are connected wrong. Anyone have an idea?
I set up a voxel field like so: for(x=0;x<voxel_num;x++) { for(y=0;y<voxel_num;y++) { for(z=0;z<voxel_num;z++) { if (y<4) { voxel[x][y][z]=1; } else { voxel[x][y][z]=0;
Here is my function to polygonize the voxel field: for(x=0;x<voxel_num;x++) { for(y=0;y<voxel_num;y++) { for(z=0;z<voxel_num;z++) { GRIDCELL CELL; TRIANGLE TRI[5]; vec_set(CELL.p[0],vector(x,y,z)); vec_set(CELL.p[1],vector(x+1,y,z)); vec_set(CELL.p[2],vector(x,y+1,z)); vec_set(CELL.p[3],vector(x+1,y+1,z)); vec_set(CELL.p[4],vector(x,y,z+1)); vec_set(CELL.p[5],vector(x+1,y,z+1)); vec_set(CELL.p[6],vector(x,y+1,z+1)); vec_set(CELL.p[7],vector(x+1,y+1,z+1));
CELL.val[0]=voxel[x][y][z]; CELL.val[1]=voxel[x+1][y][z]; CELL.val[2]=voxel[x][y+1][z]; CELL.val[3]=voxel[x+1][y+1][z]; CELL.val[4]=voxel[x][y][z+1]; CELL.val[5]=voxel[x+1][y][z+1]; CELL.val[6]=voxel[x][y+1][z+1]; CELL.val[7]=voxel[x+1][y+1][z+1]; int i=0; int p=0; int q=0; p= Polygonise(CELL,0.5,TRI);
for (i=0;i<p;i++) { for (q=0;q<3;q++) { DYNAMIC_FACE FACE; FACE.v.x=TRI[i].p[q].x; FACE.v.y=TRI[i].p[q].y; FACE.v.z=TRI[i].p[q].z; dmdl_add_face(myModel, FACE);
Last edited by Matt_Aufderheide; 11/28/14 02:46.
|
|
|
Re: Trouble implementing marching cubes
[Re: Matt_Aufderheide]
#447241
11/28/14 07:28
11/28/14 07:28
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
a triangle has 3 vertices , a face has 3 vertices
v [0] , v [1] , v [2]
just saying...
Compulsive compiler
|
|
|
Re: Trouble implementing marching cubes
[Re: Matt_Aufderheide]
#447250
11/28/14 11:31
11/28/14 11:31
|
Joined: Oct 2003
Posts: 4,131
Matt_Aufderheide
OP
Expert
|
OP
Expert
Joined: Oct 2003
Posts: 4,131
|
ok I figured it out...my setup should be like this:
vec_set(CELL.p[0],vector(x,y,z)); vec_set(CELL.p[1],vector(x+1,y,z)); vec_set(CELL.p[2],vector(x+1,y,z+1)); vec_set(CELL.p[3],vector(x,y,z+1)); vec_set(CELL.p[4],vector(x,y+1,z)); vec_set(CELL.p[5],vector(x+1,y+1,z)); vec_set(CELL.p[6],vector(x+1,y+1,z+1)); vec_set(CELL.p[7],vector(x,y+1,z+1));
CELL.val[0]=voxel[x][y][z]; CELL.val[1]=voxel[x+1][y][z]; CELL.val[2]=voxel[x+1][y][z+1]; CELL.val[3]=voxel[x][y][z+1]; CELL.val[4]=voxel[x][y+1][z]; CELL.val[5]=voxel[x+1][y+1][z]; CELL.val[6]=voxel[x+1][y+1][z+1]; CELL.val[7]=voxel[x][y+1][z+1];
|
|
|
|