Subversion Repositories spk

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
/*
114 cycrow 2
  defines the bod_bob_parser - class that can parse bod format and create
1 cycrow 3
  bob_dom_bob object
4
*/
5
 
6
#ifndef BOD_BOB_PARSER_INCLUDED
7
#define BOD_BOB_PARSER_INCLUDED
8
 
9
#include "bob_dom_bob.h"
10
#include "bod_text_parser.h"
11
#include "token_stream.h"
12
#include "settings.h"
13
#include "bod_parser_base.h"
14
 
114 cycrow 15
#include "../common/ptr_list.h"
16
#include "geometry.h"
17
 
1 cycrow 18
class bod_bob_parser : public bod_parser_base
19
{
20
	private:
114 cycrow 21
		struct SameVertices;
22
		struct SameSG_UVs;
23
 
24
		struct uv_coord : geometry::point2d<double>
1 cycrow 25
		{
114 cycrow 26
			friend SameSG_UVs;
27
			private:
28
				static geometry::point2d<double> NULL_COORDS;
29
 
30
				bool isNull () const { return *this==NULL_COORDS; }
31
 
32
			public:
33
				SameSG_UVs *parent;
34
				int vertexIndex;
35
 
36
				uv_coord(SameSG_UVs *p, double x, double y)
37
					: geometry::point2d<double>(x,y), parent(p) { }
38
 
39
				bob_vertex * createBOBVertex()
40
				{
41
					bob_vertex *v=new bob_vertex(parent->parent->x, parent->parent->y, parent->parent->z);
42
					v->sgbits=parent->sgbits;
43
					if(!isNull()){
44
						v->textureCoords.x=x;
45
						v->textureCoords.y=y;
46
						v->flags|=bob_vertex::FLAG_UV;
47
					}
48
					return v;
49
				}
1 cycrow 50
		};
114 cycrow 51
 
52
		struct SameSG_UVs : public ptr_list<ext::simple_list<uv_coord*> >
1 cycrow 53
		{
114 cycrow 54
			public:
55
				SameVertices *parent;
56
				int sgbits;
57
 
58
				SameSG_UVs (SameVertices *p, int sg)
59
					: sgbits(sg) { parent=p; }
60
 
61
				uv_coord * findUV(double x, double y)
62
				{
63
					for(iterator &it=begin(); it!=end(); ++it){
64
						if(it->x==x && it->y==y)
65
							return *it;
66
					}
67
					return 0;
1 cycrow 68
				}
114 cycrow 69
				uv_coord * createUV(double x, double y)
70
				{
71
					uv_coord *uv=new uv_coord(this, x,y);
72
					push_back(uv);
73
					return uv;
1 cycrow 74
				}
114 cycrow 75
 
76
				uv_coord * findNullUV()
77
				{
78
					return findUV(uv_coord::NULL_COORDS.x, uv_coord::NULL_COORDS.y);
79
				}
80
 
81
				uv_coord * createNullUV()
82
				{
83
					return createUV(uv_coord::NULL_COORDS.x, uv_coord::NULL_COORDS.y);
84
				}
1 cycrow 85
		};
114 cycrow 86
 
87
		struct SameVertices : public vertex, public ptr_list<ext::simple_list<SameSG_UVs*> >
1 cycrow 88
		{
114 cycrow 89
			SameVertices(int x, int y, int z)
1 cycrow 90
			{
114 cycrow 91
				this->x=conversion::vertex_bod2bob(x);
92
				this->y=conversion::vertex_bod2bob(y);
93
				this->z=conversion::vertex_bod2bob(z);
1 cycrow 94
			}
95
 
114 cycrow 96
			SameSG_UVs * findTextureCoords(int sgbits)
1 cycrow 97
			{
98
				for(iterator &it=begin(); it!=end(); ++it){
114 cycrow 99
					//if(it->sgbits==sgbits) return *it;
100
					/* changed and not tested - taken from max2msh by mindblast */
101
					if(it->sgbits & sgbits) return *it;
1 cycrow 102
				}
114 cycrow 103
				SameSG_UVs *uvs=new SameSG_UVs(this, sgbits);
104
				push_back(uvs);
105
				return uvs;
1 cycrow 106
			}
114 cycrow 107
 
1 cycrow 108
		};
114 cycrow 109
 
1 cycrow 110
	protected:
111
		const Settings *m_settings;
114 cycrow 112
 
1 cycrow 113
		bool checkImmediatePlacement(const bod_bob_parser::token *token1, const bod_bob_parser::token *token2);
114 cycrow 114
 
1 cycrow 115
	private:
114 cycrow 116
		typedef ext::simple_list<SameVertices*> VertexList;
117
		typedef ptr_list<ext::array<SameVertices*> > VertexArray;
118
		typedef ptr_list<ext::array<bob_weight*> > WeightArray;
119
 
120
		const bob_materials *m_materials;
121
		VertexArray m_vertices;
1 cycrow 122
		WeightArray m_weights;
114 cycrow 123
 
1 cycrow 124
	private:
114 cycrow 125
		bool loadMatRGB(token_stream& is, bob_material5::rgb& rgb);
126
		bool loadMatPair(token_stream& is, bob_material5::pair& pair);
127
		bool loadMatPair(token_stream& is, bob_material6::Small::pair& pair);
128
		bool loadMat(bob_material5 *mat, token_stream &is);
129
		bool loadMat(bob_material6 *mat, token_stream &is);
1 cycrow 130
		bool loadMaterial(bob_dom_bob *bob, token_stream& is);
131
		bool loadBody(bob_dom_bob *bob, token_stream& is);
114 cycrow 132
		bool loadVertices(bob_body *body, token_stream& is, VertexList& points);
133
		bool loadPart(bob_body *body, token_stream& is);
134
		bool loadFace(int matIdx, bob_body& body, bob_part& part, token_stream& is);
1 cycrow 135
		bool flagsFromString(token_stream& is, int& flags);
136
 
114 cycrow 137
		void computeVertexTangents(bob_body& body);
138
 
1 cycrow 139
		material6_value * loadMat6Value(token_stream& is);
114 cycrow 140
 
141
		bool loadMaterial6Small(bob_material6 *mat, token_stream &is);
142
		bool loadMaterial6Big(bob_material6 *mat, token_stream &is);
143
 
144
		bool loadSpecialValues(bob_vertex *points[3], token_stream& is);
145
		bool loadSpecialPointValues(token_stream& is, bob_vertex *point);
146
		bool loadFaceNormal(token_stream& is, bob_vertex *points[3]);
147
 
148
		bool loadBones(bob_body *body, token_stream& is);
149
		bool loadWeights(bob_body *body, token_stream& is);
150
 
151
		bool loadCollisionBoxData(token_stream& is, bob_part& part);
152
 
1 cycrow 153
		void deleteTempData()
154
		{
114 cycrow 155
			m_vertices.clear();
1 cycrow 156
			m_weights.clear();
157
		}
114 cycrow 158
 
1 cycrow 159
	public:
114 cycrow 160
 
1 cycrow 161
		bod_bob_parser(const Settings *settings) { m_settings=settings; }
162
		~bod_bob_parser() { deleteTempData(); }
114 cycrow 163
 
1 cycrow 164
		bob_dom_bob * loadBOB(token_stream& is, bool bEmbedded);
114 cycrow 165
 
166
		bool compile(token_stream& is, obinaryfilestream& os, bool bEmbedded);
1 cycrow 167
};
168
 
169
#endif //!defined(BOD_BOB_PARSER_INCLUDED)