This function writes all the vertices (made up of several repeated models) into a text file...
Quote:

function write_segment_file()
{
// wait(1);

// return;
var file_handle = file_open_append("anomaly_model.txt");
var seg_loc = 1;

float cx;
float cy;
float cz;
// file_str_write(file_handle,"test");

VECTOR seg_vec;
vec_zero(seg_vec);

while(seg_loc <= ent_vertices(my))//checks if current vertex exists
{
vec_for_vertex (seg_vec,my,seg_loc);

cx = seg_vec.x;
cy = seg_vec.y;
cz = seg_vec.z;

file_asc_write(file_handle,10);//line feed

file_var_write(file_handle,cx);
file_var_write(file_handle,cy);
file_var_write(file_handle,cz);

file_str_write(file_handle,";");

seg_loc += 1;


wait(1);
}

file_close(file_handle);

segments_written += 1;//counts up to total_segments
}


This one then writes all the triangles, based on the original model's ascii file that I got with MED. It has to add the total number of vertices (skill3) to the base number for it to work as one big model.

Quote:

function write_triangle_file()
{
var file_handle = file_open_append("anomaly_model.txt");
var total_tris = ent_status(my,4);
var tri_loc = 0;

while(tri_loc <= total_tris)//
{
file_asc_write(file_handle,10);//line feed

if(tri_loc == 0)
{
tri_1 = 2 + my.skill3;
tri_2 = 1 + my.skill3;
tri_3 = 0 + my.skill3;
}

if(tri_loc == 1)
{
tri_1 = 3 + my.skill3;
tri_2 = 2 + my.skill3;
tri_3 = 0 + my.skill3;
}

if(tri_loc == 2)
{
tri_1 = 4 + my.skill3;
tri_2 = 7 + my.skill3;
tri_3 = 6 + my.skill3;
}

if(tri_loc == 3)
{
tri_1 = 5 + my.skill3;
tri_2 = 4 + my.skill3;
tri_3 = 6 + my.skill3;
}

if(tri_loc == 4)
{
tri_1 = 8 + my.skill3;
tri_2 = 11 + my.skill3;
tri_3 = 10 + my.skill3;
}

if(tri_loc == 5)
{
tri_1 = 9 + my.skill3;
tri_2 = 8 + my.skill3;
tri_3 = 10 + my.skill3;
}

if(tri_loc == 6)
{
tri_1 = 12 + my.skill3;
tri_2 = 15 + my.skill3;
tri_3 = 14 + my.skill3;
}

if(tri_loc == 7)
{
tri_1 = 13 + my.skill3;
tri_2 = 12 + my.skill3;
tri_3 = 14 + my.skill3;
}

if(tri_loc == 8)
{
tri_1 = 16 + my.skill3;
tri_2 = 19 + my.skill3;
tri_3 = 18 + my.skill3;
}

if(tri_loc == 9)
{
tri_1 = 17 + my.skill3;
tri_2 = 16 + my.skill3;
tri_3 = 18 + my.skill3;
}

if(tri_loc == 10)
{
tri_1 = 20 + my.skill3;
tri_2 = 23 + my.skill3;
tri_3 = 22 + my.skill3;
}

if(tri_loc == 11)
{
tri_1 = 21 + my.skill3;
tri_2 = 20 + my.skill3;
tri_3 = 22 + my.skill3;
}

if(tri_loc == 12)
{
tri_1 = 16 + my.skill3;
tri_2 = 17 + my.skill3;
tri_3 = 0 + my.skill3;
}

if(tri_loc == 13)
{
tri_1 = 1 + my.skill3;
tri_2 = 16 + my.skill3;
tri_3 = 0 + my.skill3;
}

if(tri_loc == 14)
{
tri_1 = 11 + my.skill3;
tri_2 = 8 + my.skill3;
tri_3 = 1 + my.skill3;
}

if(tri_loc == 15)
{
tri_1 = 2 + my.skill3;
tri_2 = 11 + my.skill3;
tri_3 = 1 + my.skill3;
}

if(tri_loc == 16)
{
tri_1 = 3 + my.skill3;
tri_2 = 0 + my.skill3;
tri_3 = 13 + my.skill3;
}

if(tri_loc == 17)
{
tri_1 = 14 + my.skill3;
tri_2 = 3 + my.skill3;
tri_3 = 13 + my.skill3;
}

if(tri_loc == 18)
{
tri_1 = 2 + my.skill3;
tri_2 = 3 + my.skill3;
tri_3 = 20 + my.skill3;
}

if(tri_loc == 19)
{
tri_1 = 21 + my.skill3;
tri_2 = 2 + my.skill3;
tri_3 = 20 + my.skill3;
}

if(tri_loc == 20)
{
tri_1 = 4 + my.skill3;
tri_2 = 5 + my.skill3;
tri_3 = 18 + my.skill3;
}

if(tri_loc == 21)
{
tri_1 = 19 + my.skill3;
tri_2 = 4 + my.skill3;
tri_3 = 18 + my.skill3;
}

if(tri_loc == 22)
{
tri_1 = 15 + my.skill3;
tri_2 = 12 + my.skill3;
tri_3 = 5 + my.skill3;
}

if(tri_loc == 23)
{
tri_1 = 6 + my.skill3;
tri_2 = 15 + my.skill3;
tri_3 = 5 + my.skill3;
}

if(tri_loc == 24)
{
tri_1 = 9 + my.skill3;
tri_2 = 10 + my.skill3;
tri_3 = 7 + my.skill3;
}

if(tri_loc == 25)
{
tri_1 = 4 + my.skill3;
tri_2 = 9 + my.skill3;
tri_3 = 7 + my.skill3;
}

if(tri_loc == 26)
{
tri_1 = 6 + my.skill3;
tri_2 = 7 + my.skill3;
tri_3 = 22 + my.skill3;
}

if(tri_loc == 27)
{
tri_1 = 23 + my.skill3;
tri_2 = 6 + my.skill3;
tri_3 = 22 + my.skill3;
}

if(tri_loc == 28)
{
tri_1 = 19 + my.skill3;
tri_2 = 16 + my.skill3;
tri_3 = 8 + my.skill3;
}

if(tri_loc == 29)
{
tri_1 = 9 + my.skill3;
tri_2 = 19 + my.skill3;
tri_3 = 8 + my.skill3;
}

if(tri_loc == 30)
{
tri_1 = 21 + my.skill3;
tri_2 = 22 + my.skill3;
tri_3 = 10 + my.skill3;
}

if(tri_loc == 31)
{
tri_1 = 11 + my.skill3;
tri_2 = 21 + my.skill3;
tri_3 = 10 + my.skill3;
}

if(tri_loc == 32)
{
tri_1 = 17 + my.skill3;
tri_2 = 18 + my.skill3;
tri_3 = 12 + my.skill3;
}

if(tri_loc == 33)
{
tri_1 = 13 + my.skill3;
tri_2 = 17 + my.skill3;
tri_3 = 12 + my.skill3;
}

if(tri_loc == 34)
{
tri_1 = 23 + my.skill3;
tri_2 = 20 + my.skill3;
tri_3 = 14 + my.skill3;
}

if(tri_loc == 35)
{
tri_1 = 15 + my.skill3;
tri_2 = 23 + my.skill3;
tri_3 = 14 + my.skill3;
}

if(tri_loc == 36)
{
tri_1 = 17 + my.skill3;
tri_2 = 13 + my.skill3;
tri_3 = 0 + my.skill3;
}

if(tri_loc == 37)
{
tri_1 = 21 + my.skill3;
tri_2 = 11 + my.skill3;
tri_3 = 2 + my.skill3;
}

if(tri_loc == 38)
{
tri_1 = 23 + my.skill3;
tri_2 = 15 + my.skill3;
tri_3 = 6 + my.skill3;
}

if(tri_loc == 39)
{
tri_1 = 19 + my.skill3;
tri_2 = 9 + my.skill3;
tri_3 = 4 + my.skill3;
}

if(tri_loc == 40)
{
tri_1 = 12 + my.skill3;
tri_2 = 18 + my.skill3;
tri_3 = 5 + my.skill3;
}

if(tri_loc == 41)
{
tri_1 = 14 + my.skill3;
tri_2 = 20 + my.skill3;
tri_3 = 3 + my.skill3;
}

if(tri_loc == 42)
{
tri_1 = 10 + my.skill3;
tri_2 = 22 + my.skill3;
tri_3 = 7 + my.skill3;
}

if(tri_loc == 43)
{
tri_1 = 8 + my.skill3;
tri_2 = 16 + my.skill3;
tri_3 = 1 + my.skill3;
}

file_var_write(file_handle,tri_1);
file_var_write(file_handle,tri_2);
file_var_write(file_handle,tri_3);

file_str_write(file_handle,";");

tri_loc += 1;

wait(1);
}

file_close(file_handle);
}


There's one other function that comes before these two, it sets up the file and writes the beginning parts:

Quote:

function write_export_file()
{
//HERE IT WILL OPEN FILE AND WRITE IN TOTAL NUMBER OF VERTICES//////////////////////////////////////////////////////////////////////////////
var file_handle = file_open_append("anomaly_model.txt");//opens file to write anomaly model

file_var_write(file_handle,vertex_total);//vertex_total will be inserted after file header
file_asc_write(file_handle,59);//;

file_close(file_handle);

wait(1);//waits until vertex_total is written

write_start = 1;//begin writing segment data to file

while(segments_written < total_segments)
{
//waits until all segments have written their data to export file
wait(1);
}

file_handle = file_open_append("anomaly_model.txt");//opens file to write anomaly model

// Once all vertices are written, write the file closing text
file_asc_write(file_handle,10);//line feed
file_asc_write(file_handle,10);//line feed

file_asc_write(file_handle,84);//T
file_asc_write(file_handle,114);//r
file_asc_write(file_handle,105);//i
file_asc_write(file_handle,97);//a
file_asc_write(file_handle,110);//n
file_asc_write(file_handle,103);//g
file_asc_write(file_handle,108);//l
file_asc_write(file_handle,101);//e
file_asc_write(file_handle,115);//s
file_asc_write(file_handle,58);//:
file_asc_write(file_handle,32);//space
// file_asc_write(file_handle,48);//0

file_var_write(file_handle,total_triangles);//writes total number of triangles to the export file

file_asc_write(file_handle,59);//;

file_close(file_handle);

wait(1);//waits until vertex_total is written

write_triangles = 1;//begin writing segment data to file

//write triangles
while(triangles_written <= total_triangles)
{
//waits until all segments have written their data to export file
wait(1);
}

file_handle = file_open_append("anomaly_model.txt");//writes the last bit of closing info

file_asc_write(file_handle,10);//line feed

file_asc_write(file_handle,125);//close parenthesis
file_asc_write(file_handle,59);//;

file_asc_write(file_handle,10);//line feed
file_asc_write(file_handle,10);//line feed
file_asc_write(file_handle,10);//line feed

//then close the file
file_close(file_handle);

}


Also, in each segment entity, there is a while loop. In this loop, it checks if the "write_start" variable has been changed to 1, which is done in the "write_export_file" function above...

Quote:

if(write_start == 1 && my.skill2 == 0)
{
write_segment_file();//writes the coordinates for this anomaly to a file
my.skill2 = 1;//prevents this segment from writing its data more than once
}

if(write_triangles == 1 && my.skill2 == 1)
{
write_triangle_file();//write the segments triangle data to file
my.skill2 = 2;//prevents this segment from writing triangles more than once
}


And one more thing, before the while loop, each segment entity sets up it's parameters like this:

Quote:

total_segments += 1;//used by model export to determine total number of segments that need to be written
my.skill3 = vertex_total;//sets the current vertex number for exported file
total_triangles += ent_status(my,4);
vertex_total += ent_vertices(my);//add this segments number of vertices to the total count


Sorry if this is confusing. It does work, and I was able to export my "Anomalies" and even upload them to Sketchfab, and Shapeways for 3D printing. If here's an easier way to do it, I'd love to hear about it.

You can see the results here: http://www.schmidt-gallery.com/3D.html

Last edited by Dooley; 06/10/16 09:34.