First/auxiliary_progs/stl_to_source_code.c

55 lines
1.0 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
//TODO:
//Don't hard code the size of the model!!!
//Detect binary stl
//Do automaitic scaling
//FIX THE HORRIBLE PARSING
//do the float to u32 in software
#define LINE_SIZE 500
//#define SCALE 2
//#define YOFFSET 1
#define SCALE 5
#define YOFFSET 1
union U32FLOAT_RETURN{
float f;
uint32_t u;
};
int main(){
union U32FLOAT_RETURN x,y,z, x0,y0,z0;
int point=1;
char *line=malloc(LINE_SIZE);
printf("DDW $0x00006E9A\n");
while(fgets(line,LINE_SIZE,stdin)!= NULL){
if(strncmp(line," vertex",14)==0){
if(sscanf(line+14,"%f %f %f\n",&x.f,&z.f,&y.f)==3){
x.f/=SCALE;
y.f/=SCALE;
z.f/=SCALE;
y.f=-y.f;
y.f+=YOFFSET;
if(point==3){
printf("DDW $0x%08x\nDDW $0x%08x\nDDW $0x%08x\n",x0.u,y0.u,z0.u);
point=1;
}else if(point==1){
x0.f=x.f,y0.f=y.f,z0.f=z.f;
point++;
}else{
point++;
}
printf("DDW $0x%08x\nDDW $0x%08x\nDDW $0x%08x\n",x.u,y.u,z.u);
}else
break;
}
}
}