aboutsummaryrefslogtreecommitdiff
path: root/obj.h
blob: 5ca267639164f841af28d18bff6baea584b72e6a (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* vertex types */
enum {
	OBJVGeometric,
	OBJVTexture,
	OBJVNormal,
	OBJVParametric,
	OBJNVERT
};
/* element types */
enum {
	OBJEPoint,
	OBJELine,
	OBJEFace,
	OBJECurve,
	OBJECurve2,
	OBJESurface
};
/* grouping types */
enum {
	OBJGGlobal,
	OBJGSmoothing,
	OBJGMerging
};
/* object hash table size */
enum {
	OBJHTSIZE = 17
};

typedef union OBJVertex OBJVertex;
typedef struct OBJColor OBJColor;
typedef struct OBJVertexArray OBJVertexArray;
typedef struct OBJIndexArray OBJIndexArray;
typedef struct OBJMaterial OBJMaterial;
typedef struct OBJMaterlist OBJMaterlist;
typedef struct OBJElem OBJElem;
//typedef struct OBJGroup OBJGroup;
typedef struct OBJObject OBJObject;
typedef struct OBJ OBJ;

#pragma varargck type "O" OBJ*

union OBJVertex
{
	struct { double x, y, z, w; };	/* geometric */
	struct { double u, v, vv; };	/* texture and parametric */
	struct { double i, j, k; };	/* normal */
};

struct OBJColor
{
	double r, g, b;
};

struct OBJVertexArray
{
	OBJVertex *verts;
	int nvert;
};

struct OBJIndexArray
{
	int *indices;
	int nindex;
};

struct OBJMaterial
{
	char *name;
	OBJColor Ka;		/* ambient color */
	OBJColor Kd;		/* diffuse color */
	OBJColor Ks;		/* specular color */
	OBJColor Ke;		/* emissive color */
	double Ns;		/* specular highlight */
	double Ni;		/* index of refraction */
	double d;		/* dissolution factor */
	int illum;		/* illumination model */
	Memimage *map_Kd;	/* color texture file */
	OBJMaterial *next;
};

struct OBJMaterlist
{
	char *filename;
	OBJMaterial *mattab[OBJHTSIZE];
};

struct OBJElem
{
	OBJIndexArray indextab[OBJNVERT];
	int type;
	OBJMaterial *mtl;
	OBJElem *next;
};

//struct OBJGroup
//{
//	char *name;
//	int type;
//	OBJElem *elem0;
//	OBJGroup *next;
//};
//struct OBJObject
//{
//	char *name;
//	OBJGroup *grptab[OBJHTSIZE];
//	OBJObject *next;
//};

struct OBJObject
{
	char *name;
	OBJElem *child;
	OBJElem *lastone;
	OBJObject *next;
};

struct OBJ
{
	OBJVertexArray vertdata[OBJNVERT];
	OBJObject *objtab[OBJHTSIZE];
	OBJMaterlist *materials;
};

OBJ *objparse(char*);
void objfree(OBJ*);
OBJMaterlist *objmtlparse(char*);
void objmtlfree(OBJMaterlist*);

int OBJMaterlistfmt(Fmt*);
int OBJfmt(Fmt*);
void OBJfmtinstall(void);