-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimize.c
65 lines (61 loc) · 1.43 KB
/
optimize.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define XSIZE 1000
#define YSIZE 1000
#define ZSIZE 200
float xyz[XSIZE][YSIZE][ZSIZE];
/**
* This program read the output of the modified minetestmapper found in this same directory
* minetestmapper.py output a cvs list of lightstone_red_off minetest stones.
**/
int main(int argc,char **argv)
{
memset(&xyz,0,sizeof(xyz));
int x,y,z,r,haut;
float decalx,decaly,decalcube;
while ( (r = fscanf(stdin, "%d,%d,%d", &x,&y,&z)) == 3 ) {
assert(x < XSIZE);
assert(y < YSIZE);
assert(z < ZSIZE);
xyz[x][y][z] = 1;
}
/* now optimize */
//printf("translate([%d,%d,%d]) cube([1,1,1]);\n",x,y,z);
for (x=0 ; x < XSIZE ; x++){
for (y=0 ; y < YSIZE ; y++){
for (z=0 ; z < ZSIZE ; z++){
if (xyz[x][y][z] == 1){
int f,count;
count =0;
for (f =z ; f < ZSIZE ; f++){
if (xyz[x][y][f] ==1){
count++;
} else {
//printf("making xyz -> %d,%d,%d %d\n",x,y,z,count);
xyz[x][y][z] = count;
int g;
for (g =z+1 ; g < z + count ; g++){
xyz[x][y][g] =0;
}
}
}
}
}
}
}
printf("union () { \n");
for (x=0 ; x < XSIZE ; x++){
for (y=0 ; y < YSIZE ; y++){
for (z=0 ; z < ZSIZE ; z++){
if (xyz[x][y][z] > 0){
haut = xyz[x][y][z];
printf("translate([%d,%d,%d]) cube([1.001,1.001,%d]);\n",x,y,z,haut);
}
}
}
}
printf("}\n");
return 0;
}