Simple 3ds saver - Version #0.7
Saves 2 triangles now you can upload in wings3D or sketchup etc.
I split it up in 2 parts, since the message will be too big, and cant post it then on the forum
--------------------------Part 1--------------------
Code:
// simple .3ds saver - Elout de Kok 2007 - update #7
// info on 3ds fileformat - http://www.wotsit.org/list.asp?fc=2
void setup()
{
save3ds();
println("saved the 3ds-file");
}
void save3ds()
{
int number_of_points=4;
int number_of_triangles=2;
float [] xyzpoints = {-10.0f,-5.0f,1.0f, 10.0f,-5.0f,1.0f, 1.0f,10.0f,1.0f, -1.0f, -4.0f, -10.0f};
int [] vertexes = {0,1,2, 1,3,2};
int [] mesh_version = {0x3D3E, 0x000A, 0x0000,0x0003,0x0000,0xAFFF,0x0080, 0x0000, 0xA000, 0x000E, 0x0000, 0x6564, 0x6166,0x6C75, 0x0074, 0xA030, 0x0018, 0x0000, 0x0011, 0x0009, 0x0000, 0xFFFF, 0x12FF, 0x0900, 0x0000, 0xFF00, 0xFFFF, 0xA040, 0x000E, 0x0000, 0x0030, 0x0008, 0x0000, 0x0000, 0xA020, 0x0018, 0x0000, 0x0011, 0x0009, 0x0000, 0xFFFF, 0x12FF, 0x0900, 0x0000, 0xFF00, 0xFFFF, 0xA050, 0x000E, 0x0000, 0x0030, 0x0008, 0x0000, 0x0000, 0xA010, 0x0018, 0x0000, 0x0011, 0x0009, 0x0000, 0xFFFF, 0x12FF, 0x0900, 0x0000, 0xFF00, 0xFFFF, 0xA100, 0x0008, 0x0000, 0x0003, 0x0100, 0x000A, 0x0000, 0x0000, 0x3F80};
int [] chunk_4160 = {0x4160, 0x0036, 0x0000, 0x0000, 0x3F80, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3F80, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3F80, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
int totalbytes=
6 // 0x4D4D Main chunk
+10 // header data
+148 // 0x3D3E Mesh version
+ 6 // 0x3D3D 3D editor chunk
+ 6 // 0x4000 Object block (with name of your object)
+ 6 // name
+ 6 // 0x4100 Triangular mesh
+ 54 // 4160 matrix chunk
+ ((number_of_points*3)*4)+4+4 // ox4110 points 44
+ ((number_of_triangles*8)+4+4) // ox4120 faces 16
+ 16 + (number_of_triangles*2) // 4130 material
+ 6+(number_of_triangles*4); // 4150 smoothing groups
byte[] nums = new byte[totalbytes]; // for the moment
int step=0;
writeshort(nums, step, (short) 0x4D4D); step+=2; //main chunk
writeshort(nums, step, (short) totalbytes); step+=2; //size of next chunks
writeshort(nums, step, (short) 0); step+=2;
writeshort(nums, step, (short) 0x0002); step+=2; // header data
writeshort(nums, step, (short) 0x000A); step+=2;
writeshort(nums, step, (short) 0x0000); step+=2;
writeshort(nums, step, (short) 0x0003); step+=2;
writeshort(nums, step, (short) 0x0000 ); step+=2;
writeshort(nums, step, (short) 0x3D3D); step+=2; //3D editor chunk
writeshort(nums, step, (short) (totalbytes-16) ); step+=2; //size of next chunks
writeshort(nums, step, (short) 0); step+=2;
for (int i=0;i<mesh_version.length;i++)
{
writeshort(nums, step, (short) mesh_version[i]); step+=2; //0x3D3E Mesh version
}
writeshort(nums, step, (short) 0x4000); step+=2; //Object block chunk
writeshort(nums, step, (short) (totalbytes-170) ); step+=2; //size of next chunks
writeshort(nums, step, (short) 0); step+=2;
writeshort(nums, step, (short) 0x7563); step+=2; //write name
writeshort(nums, step, (short) 0x6562); step+=2;
writeshort(nums, step, (short) 0x0031); step+=2;