Subversion Repositories spk

Rev

Rev 1 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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