// - meshtest v.02 - 17 sept 2003
// elout
int mywidth=550;
int myheight=550;
float zpos;
//------mouse rotation stuff
int mx,my,sx=140,sy=120, middenx,middeny;
float xangle,yangle,zangle;
int no_vertex;
float [] point_buff = new float[5000];
int pointbuffcounter=0;
int no_faces;
int [] face_buff = new int [5000];
int facebuffcounter=0;
// my personal textbuffer -> now max 5000 lines
int my_textbuffersize=5000;
String [] my_textbuffer = new String[my_textbuffersize];
int number_of_textlines;
void setup()
{
size(mywidth,myheight);
background(0, 0, 0);
zpos=0.0f;
middenx=width/2;
middeny=height/2;
lights();
noStroke();
//load a textfile - make sure the text-file is in your data directory
String lines[] = loadStrings("fox.ASE");
//println("--------------------------start-----------------");
//check the 3D data that`s loaded
number_of_textlines=lines.length;
for (int i= 0; i < lines.length; i++)
{
String llist[] = splitStrings(lines[i]); // '\t'
for (int j= 0; j < llist.length; j++)
{
if (llist[j].equals("*MESH_NUMVERTEX"))
{
//get no. of vertex;
int intlist[] = splitInts(llist[j+1]);
no_vertex=intlist[0];
//println("VERTEX= " + no_vertex);
}
if (llist[j].equals("*MESH_NUMFACES"))
{
int intlist[] = splitInts(llist[j+1]);
no_faces=intlist[0];
//println("FACES= " + no_faces);
}
if (llist[j].equals("*MESH_VERTEX"))
{
float floatlist1[] = splitFloats(llist[j+2]);
point_buff[pointbuffcounter]=floatlist1[0];
float floatlist2[] = splitFloats(llist[j+3]);
point_buff[pointbuffcounter+1]=floatlist2[0];
float floatlist3[] = splitFloats(llist[j+4]);
point_buff[pointbuffcounter+2]=floatlist3[0];
//println("x "+point_buff[pointbuffcounter]+" y "+point_buff[pointbuffcounter+1]+" z "+point_buff[pointbuffcounter+2]);
pointbuffcounter=pointbuffcounter+3;
}
if (llist[j].equals("*MESH_FACE"))
{
int intlist1[] = splitInts(llist[j+3]);
face_buff[facebuffcounter]=intlist1[0];
int intlist2[] = splitInts(llist[j+5]);
face_buff[facebuffcounter+1]=intlist2[0];
int intlist3[] = splitInts(llist[j+7]);
face_buff[facebuffcounter+2]=intlist3[0];
//println("a "+face_buff[facebuffcounter]+" b "+face_buff[facebuffcounter+1]+" c "+face_buff[facebuffcounter+2]);
facebuffcounter=facebuffcounter+3;
}
}
}
}
void loop()
{
translate(width/2, height/2, zpos);
//rotate using mouseposition
mx=mouseX;
my=mouseY;
if ( mx > middenx){sx=0-((middenx-mx));}
else{sx=((mx-middenx));}
if ( my > middeny){sy=0-((middeny-my));}
else{sy=((my-middeny));}
xangle= xangle+(sy/1800.0f);
yangle= yangle+((sx-sy)/1800.0f);
zangle= zangle+(sx/1800.0f);
rotateX(xangle);
rotateY(yangle);
rotateZ(zangle);
//zoom in/out using arrow keys
if(keyPressed)
{
if (key == 40)
{
zpos=zpos-20.0f;
}
if (key == 38)
{
zpos=zpos+20.0f;
}
}
//draw the 3D model
fill(200,220,220);
beginShape(TRIANGLES);
for (int i=0;i