//Author Jens Schwaiger
// For reading (simple) obj-files to polyhedrons
// `simple' means that 1) all vertex statements should come before the face statements,
// that 2) face informations with respect to texture and/or normal vectors are ignored and
// that 3) face statements only contain positive numbers (no relative positions).
// The reading process only takes into account lines starting with "v" or "f"
import three;
import light;
string truncate(string s, string mark="/"){ // cuts string s after the first appearence of the string mark
int pos=find(s,mark);
if(pos==-1) return s;
return erase(s,pos,-1);
}
string[] truncate(string[] s, string mark="/"){ // extension to arrays of strings
if(s.length==0) abort("array has length 0");
string[] tmp;
for(int i=0;i-1;--i){
int d1=(int)distsort[i][1];
int d2=(int)distsort[i][2];
triple u,v,w;
u=point(join[d1],0)-cofgr(join[d1]);
v=point(join[d1],1)-cofgr(join[d1]);
w=unit(cross(u,v));
if(dot(w,cam-cofgr(join[d1]))<0) w=-w;
real contrast=0.5*(dot(lt.source,w)+1);
filldraw(pic,project(join[d1],P),contrast*fcol[d2]+opacity(op),dcol[d2]);
}
write("Filling done.");
}
polyhedron objtopolyhedron(string datafile){
file in=word(line(input(datafile,check=true)));
triple[] vert;
polyhedron pol;
void Vertex(real x,real y ,real z){vert.push((x,y,z));}
void Face(int[] vertnr){
guide3 gh;
for(int i=0;iMore data may be found at http://www.cs.technion.ac.il/~irit/data/Viewpoint/
polyhedron[] parr={rotate(90,Y)*rotate(90,Z)*objtopolyhedron("galleon.obj")};
pen[] fcol1={rgb(0.5,0.2,0.2)};
pen[] dcol1={darkgrey};
filldraw(parr,fcol=fcol1,dcol=dcol1, op=1.0);
shipout(bbox(3mm,darkblue+3bp+miterjoin,FillDraw(paleyellow)));