Hi vobla
Good work.
I have a few suggestion if your interested.
1)Use a different line for comments.It would make your
code easier to read.
2)You don't need to initialize $i and $j to 0.
3)Right now,your faces(normals) are facing down toward -Y.It might
be better to have them facing up.You just have to reverse the winding(the
order you're adding the vertices)Seen from the top,you're going counter clock wise.
Go clock wise.
4)You could also calculate the UV coords so that your mesh would show a
complete texture,seen from the top.
Texture coords are:
Image UVcoords
Bottom left 0,0
Bottom right 1,0
Top left 0,1
Top right 1,1
So,you can calculate them in a way similar to the one you used for the vertices.
Hope it helps.
Welcome to Anim8or.
Claude