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
#include "bob_dom_bob.h"
1
#include "bob_dom_bob.h"
-
 
2
 
-
 
3
#include "bob_stream_operators.h"
2
//---------------------------------------------------------------------------------
4
//---------------------------------------------------------------------------------
3
// BOB file
5
// BOB file
4
bool bob_dom_bob::load(unsigned char *data, size_t size)
6
bool bob_dom_bob::load(ibinaryfilestream& is)
5
{
7
{
6
	int pos = 0;
-
 
7
 
-
 
8
	if ( data[pos++] != hdr_begin )
-
 
9
		return false;
-
 
10
 
-
 
11
	// info section
-
 
12
	if ( data[pos] != bob_dom_info::hdr_begin )
-
 
13
		return false;
-
 
14
 
-
 
15
	return false;
-
 
16
}
-
 
17
 
-
 
18
bool bob_dom_bob::load(bob_dom_ibinaryfilestream& is)
-
 
19
{
-
 
20
	int hdr;	
8
	int hdr;
21
	is >> hdr;
9
	is >> hdr;
22
	if(hdr!=hdr_begin){
10
	if(hdr!=HDR_BEGIN){
23
		error(e_badHeader);
11
		error(e_badHeader);
24
		return false;
12
		return false;
25
	}
13
	}
26
	
14
 
27
	if(peek(is)==bob_dom_info::hdr_begin){
15
	if(peek(is)==bob_info::HDR_BEGIN){
28
		if(!info.load(is)){
16
		if(!info.load(is)){
29
			for(ErrorIterator &it=info.errors.begin(); it!=info.errors.end(); ++it){
17
			for(ErrorIterator &it=info.errors.begin(); it!=info.errors.end(); ++it){
30
				error(it->code, "info: %s", it->text);
18
				error(it->code, "info: %s", it->text);
31
			}
19
			}
32
			return false;
20
			return false;
33
		}
21
		}
34
	}
22
	}
35
	
23
 
36
	if(materials.load(is)==false){
24
	if(materials.load(is)==false){
37
		for(ErrorIterator &it=materials.errors.begin(); it!=materials.errors.end(); ++it){
25
		for(ErrorIterator &it=materials.errors.begin(); it!=materials.errors.end(); ++it){
38
			error(it->code, "materials->%s", it->text);
26
			error(it->code, "materials->%s", it->text);
39
			return false;
27
			return false;
40
		}
28
		}
41
	}
29
	}
42
	/*switch(m_settings->X3BOB()){
-
 
43
		case Settings::SwitchValue::on:
-
 
44
			bobType=bobX3;
-
 
45
			break;
-
 
46
		case Settings::SwitchValue::off:
-
 
47
			bobType=bobX2;
-
 
48
			break;
-
 
49
		default:
-
 
50
			if(materials.size() && materials.front()->type >= bob_dom_material::mat6)
-
 
51
				bobType=bobX3;
-
 
52
			else
-
 
53
				bobType=bobX2;
-
 
54
	}*/
30
 
55
	if(bodies.load(is)==false){
31
	if(bodies.load(is)==false){
56
		for(ErrorIterator &it=bodies.errors.begin(); it!=bodies.errors.end(); ++it){
32
		for(ErrorIterator &it=bodies.errors.begin(); it!=bodies.errors.end(); ++it){
57
			error(it->code, "bodies->%s", it->text);
33
			error(it->code, "bodies->%s", it->text);
58
		}
34
		}
59
		return false;
35
		return false;
60
	}
36
	}
61
	
37
 
62
	is >> hdr;
38
	is >> hdr;
63
	if(hdr!=hdr_end)
39
	if(hdr!=HDR_END)
64
		error(e_badEndHeader);
40
		error(e_badEndHeader);
65
		
41
 
66
	return(hdr==hdr_end && !is.fail());
42
	return(hdr==HDR_END && !is.fail());
67
}
43
}
68
//---------------------------------------------------------------------------------
44
//---------------------------------------------------------------------------------
69
bool bob_dom_bob::toFile(bob_dom_obinaryfilestream& os)
45
bool bob_dom_bob::toFile(obinaryfilestream& os)
70
{
46
{
71
	os << hdr_begin;
47
	os << HDR_BEGIN;
72
	info.toFile(os);
48
	info.toFile(os);
73
	materials.toFile(os);
49
	materials.toFile(os);
74
	bodies.toFile(os);
50
	bodies.toFile(os);
75
	os << hdr_end;
51
	os << HDR_END;
76
	return os.good();
52
	return os.good();
77
}
53
}
78
//---------------------------------------------------------------------------------
54
//---------------------------------------------------------------------------------
79
bool bob_dom_bob::toFile(bob_dom_otextfilestream& os)
55
bool bob_dom_bob::toFile(otextfilestream& os)
80
{
56
{
81
	info.toFile(os);
57
	info.toFile(os);
82
	os << endl;
58
	os << endl;
83
	materials.toFile(os);
59
	materials.toFile(os);
84
	if(materials.size())
60
	if(materials.size())
85
		os << endl;
61
		os << endl;
86
	bodies.toFile(os, m_settings, &materials);
62
	if(bodies.toFile(os, *m_settings, &materials)==false){
-
 
63
		for(bob_bodies::ErrorIterator &e_it=bodies.errors.begin(); e_it!=bodies.errors.end(); ++e_it){
-
 
64
			error(e_it->severity, e_it->code, "Bodies->%s", e_it->text);
-
 
65
		}
-
 
66
		return false;
-
 
67
	}
87
	return os.good();
68
	return os.good();
88
}
69
}
89
//---------------------------------------------------------------------------------
70
//---------------------------------------------------------------------------------
90
// MATERIAL  - object
71
// MATERIAL  - object
91
bool bob_dom_material1::load(bob_dom_ibinaryfilestream& is)
72
bool bob_material1::load(ibinaryfilestream& is)
92
{
73
{
93
	is >> index;
74
	is >> index;
94
	is >> textureID; // int?
75
	is >> textureID; // int?
95
	is >> ambient;
76
	is >> ambient;
96
	is >> diffuse;
77
	is >> diffuse;
97
	is >> specular;
78
	is >> specular;
98
	
79
 
99
	errorCode=is.fail() ? e_notEnoughData : e_noError;
80
	errorCode=is.fail() ? e_notEnoughData : e_noError;
100
	
81
 
101
	return !is.fail();
82
	return !is.fail();
102
}
83
}
103
//---------------------------------------------------------------------------------
84
//---------------------------------------------------------------------------------
104
bool bob_dom_material1::toFile(bob_dom_obinaryfilestream& os)
85
bool bob_material1::toFile(obinaryfilestream& os)
105
{
86
{
106
	os << index << textureID << ambient << diffuse << specular;
87
	os << index << textureID << ambient << diffuse << specular;
107
	
88
 
108
	return os.good();
89
	return os.good();
109
}
90
}
110
//---------------------------------------------------------------------------------
91
//---------------------------------------------------------------------------------
111
bool bob_dom_material1::toFile(bob_dom_otextfilestream& os)
92
bool bob_material1::toFile(otextfilestream& os)
112
{
93
{
113
	os << noSemicolons << "MATERIAL";
94
	os << noSemicolons << "MATERIAL";
114
	switch(type){
95
	switch(type){
115
		case mat3:
96
		case mat3:
116
			os << '3';
97
			os << '3';
Line 120... Line 101...
120
			break;
101
			break;
121
	}
102
	}
122
	os << ": " << autoSemicolons;
103
	os << ": " << autoSemicolons;
123
	os << index << textureID;
104
	os << index << textureID;
124
	os << ambient << diffuse << specular;
105
	os << ambient << diffuse << specular;
125
	
106
 
126
	return os.good();
107
	return os.good();
127
}
108
}
128
//---------------------------------------------------------------------------------
109
//---------------------------------------------------------------------------------
129
// MATERIAL 3 - object
110
// MATERIAL 3 - object
130
bool bob_dom_material3::load(bob_dom_ibinaryfilestream& is)
111
bool bob_material3::load(ibinaryfilestream& is)
131
{
112
{
132
	base::load(is);
113
	base::load(is);
133
	if(type > mat1){
114
	if(type > mat1){
134
		is >> transparency; // int?
115
		is >> transparency; // int?
135
		is >> selfIllumination;
116
		is >> selfIllumination;
Line 142... Line 123...
142
		is >> textureValue;
123
		is >> textureValue;
143
		is >> enviromentMap;
124
		is >> enviromentMap;
144
		is >> bumpMap;
125
		is >> bumpMap;
145
	}
126
	}
146
	errorCode=is.fail() ? e_notEnoughData : e_noError;
127
	errorCode=is.fail() ? e_notEnoughData : e_noError;
147
	
128
 
148
	return !is.fail();
129
	return !is.fail();
149
}
130
}
150
//---------------------------------------------------------------------------------
131
//---------------------------------------------------------------------------------
151
bool bob_dom_material3::toFile(bob_dom_obinaryfilestream& os)
132
bool bob_material3::toFile(obinaryfilestream& os)
152
{
133
{
153
	base::toFile(os);
134
	base::toFile(os);
154
	os << transparency << selfIllumination << shininess;
135
	os << transparency << selfIllumination << shininess;
155
	short s=0;
136
	short s=0;
156
	if(destinationBlend) s|=0x2;
137
	if(destinationBlend) s|=0x2;
157
	if(twoSided) s|=0x10;
138
	if(twoSided) s|=0x10;
158
	if(wireframe) s|=0x8;
139
	if(wireframe) s|=0x8;
159
	os << s;
140
	os << s;
160
	os << textureValue << enviromentMap << bumpMap;
141
	os << textureValue << enviromentMap << bumpMap;
161
	
142
 
162
	return os.good();
143
	return os.good();
163
}
144
}
164
//---------------------------------------------------------------------------------
145
//---------------------------------------------------------------------------------
165
bool bob_dom_material3::toFile(bob_dom_otextfilestream& os)
146
bool bob_material3::toFile(otextfilestream& os)
166
{
147
{
167
	base::toFile(os);
148
	base::toFile(os);
168
	os << autoSemicolons;
149
	os << autoSemicolons;
169
	os << transparency << selfIllumination << shininess;
150
	os << transparency << selfIllumination << shininess;
170
	os << noSemicolons << destinationBlend << ';' << twoSided << ';' << autoSemicolons << wireframe;
151
	os << noSemicolons << destinationBlend << ';' << twoSided << ';' << autoSemicolons << wireframe;
171
	os << textureValue;
152
	os << textureValue;
172
	os << enviromentMap << bumpMap;
153
	os << enviromentMap << bumpMap;
173
	return os.good();
154
	return os.good();
174
}
155
}
175
//---------------------------------------------------------------------------------
156
//---------------------------------------------------------------------------------
176
// MATERIAL5
157
// MATERIAL5
177
bool bob_dom_material5::load(bob_dom_ibinaryfilestream& is)
158
bool bob_material5::load(ibinaryfilestream& is)
178
{
159
{
179
	base::load(is);
160
	base::load(is);
180
	if(type > mat3)
161
	if(type > mat3)
181
		is >> lightMap;
162
		is >> lightMap;
182
	
163
 
183
	errorCode=is.fail() ? e_notEnoughData : e_noError;
164
	errorCode=is.fail() ? e_notEnoughData : e_noError;
184
	
165
 
185
	return !is.fail();
166
	return !is.fail();
186
}
167
}
187
//---------------------------------------------------------------------------------
168
//---------------------------------------------------------------------------------
188
bool bob_dom_material5::toFile(bob_dom_obinaryfilestream& os)
169
bool bob_material5::toFile(obinaryfilestream& os)
189
{
170
{
190
	base::toFile(os);
171
	base::toFile(os);
191
	os << lightMap;
172
	os << lightMap;
192
	return os.good();
173
	return os.good();
193
}
174
}
194
//---------------------------------------------------------------------------------
175
//---------------------------------------------------------------------------------
195
bool bob_dom_material5::toFile(bob_dom_otextfilestream& os)
176
bool bob_material5::toFile(otextfilestream& os)
196
{
177
{
197
	base::toFile(os);
178
	base::toFile(os);
198
	if(type > mat3)
179
	if(type > mat3)
199
		os << autoSemicolons << lightMap;
180
		os << autoSemicolons << lightMap;
200
	return os.good();
181
	return os.good();
Line 212... Line 193...
212
	"SPTYPE_STRING"
193
	"SPTYPE_STRING"
213
};
194
};
214
 
195
 
215
int material6_value::m_stringTypesCount=9;
196
int material6_value::m_stringTypesCount=9;
216
 
197
 
217
bob_error_codes material6_value::load(bob_dom_ibinaryfilestream &is)
198
bob_error_codes material6_value::load(ibinaryfilestream &is)
218
{
199
{
219
	is >> name;
200
	is >> name;
220
	if(is.fail()) return e_error;
201
	if(is.fail()) return e_error;
221
	short t;
202
	short t;
222
	is >> t;
203
	is >> t;
223
	type=(Type)t;
204
	type=(Type)t;
224
	
205
 
225
	switch(type){
206
	switch(type){
226
		case typeBool: // no break
207
		case typeBool: // no break
227
		case typeLong:
208
		case typeLong:
228
			is >> val.i;
209
			is >> val.i;
229
			break;
210
			break;
230
		case typeFloat:
211
		case typeFloat:
231
			is >> val.f;
212
			is >> val.f;
232
			break;
213
			break;
233
		case typeFloat4:
214
		case typeFloat4:
234
			is >> val.f4;
215
			is >> val.f4;
235
			break;
216
			break;
236
		case typeString:
217
		case typeString:
237
			is >> val.psz;
218
			is >> val.psz;
238
			break;
219
			break;
239
		default:	
220
		default:
240
			return e_unkMaterialValueType;
221
			return e_unkMaterialValueType;
241
	}
222
	}
242
	return is.fail() ? e_error : e_noError;
223
	return is.fail() ? e_error : e_noError;
243
}
224
}
244
//---------------------------------------------------------------------------------
225
//---------------------------------------------------------------------------------
245
bool material6_value::toFile(bob_dom_obinaryfilestream& os)
226
bool material6_value::toFile(obinaryfilestream& os)
246
{
227
{
247
	os << name << (short) type;
228
	os << name << (short) type;
248
	
229
 
249
	switch(type){
230
	switch(type){
250
		case typeBool: // no break
231
		case typeBool: // no break
251
		case typeLong:
232
		case typeLong:
252
			os << val.i;
233
			os << val.i;
253
			break;
234
			break;
254
		case typeFloat:
235
		case typeFloat:
255
			os << val.f;
236
			os << val.f;
256
			break;
237
			break;
257
		case typeFloat4:
238
		case typeFloat4:
258
			os << val.f4;
239
			os << val.f4;
259
			break;
240
			break;
260
		case typeString:
241
		case typeString:
261
			os << val.psz;
242
			os << val.psz;
262
			break;
243
			break;
263
		default:	
244
		default:
264
			return false;
245
			return false;
265
	}
246
	}
266
	return os.good();
247
	return os.good();
267
}
248
}
268
//---------------------------------------------------------------------------------
249
//---------------------------------------------------------------------------------
269
bool material6_value::toFile(bob_dom_otextfilestream& os)
250
bool material6_value::toFile(otextfilestream& os)
270
{
251
{
271
	int old=os.flags();
252
	int old=os.flags();
272
	os << noSemicolons << name << ';';
253
	os << noSemicolons << name << ';';
273
	
254
 
274
	os << typeName() << ';';
255
	os << typeName() << ';';
275
	
256
 
276
	switch(type){
257
	switch(type){
277
		case typeLong:
258
		case typeLong:
278
			os << val.i << ';';
259
			os << val.i << ';';
279
			break;
260
			break;
280
		case typeBool:
261
		case typeBool:
Line 298... Line 279...
298
	os.flags(old);
279
	os.flags(old);
299
	return os.good();
280
	return os.good();
300
}
281
}
301
//---------------------------------------------------------------------------------
282
//---------------------------------------------------------------------------------
302
// MATERIAL6_VALUES
283
// MATERIAL6_VALUES
303
bob_error_codes bob_dom_material6_values::load(bob_dom_ibinaryfilestream& is)
284
bob_error_codes bob_material6_values::load(ibinaryfilestream& is)
304
{
285
{
305
	short count;
286
	short count;
306
	material6_value *v;
287
	material6_value *v;
307
	
288
 
308
	bob_error_codes res;
289
	bob_error_codes res;
309
	
290
 
310
	is >> count;
291
	is >> count;
311
	for(int i=0; i < count; i++){
292
	for(int i=0; i < count; i++){
312
		v=new material6_value();
293
		v=new material6_value();
313
		if((res=v->load(is))!=e_noError) {
294
		if((res=v->load(is))!=e_noError) {
314
			delete v;
295
			delete v;
Line 317... Line 298...
317
		push_back(v);
298
		push_back(v);
318
	}
299
	}
319
	return is.fail() ? e_error : e_noError;
300
	return is.fail() ? e_error : e_noError;
320
}
301
}
321
//---------------------------------------------------------------------------------
302
//---------------------------------------------------------------------------------
322
bool bob_dom_material6_values::toFile(bob_dom_obinaryfilestream& os)
303
bool bob_material6_values::toFile(obinaryfilestream& os)
323
{
304
{
324
	os << (short)size();
305
	os << (short)size();
325
	for(iterator &it=begin(); it!=end(); ++it){
306
	for(iterator &it=begin(); it!=end(); ++it){
326
		it->toFile(os);
307
		it->toFile(os);
327
	}
308
	}
328
	return os.good();
309
	return os.good();
329
}
310
}
330
//---------------------------------------------------------------------------------
311
//---------------------------------------------------------------------------------
331
bool bob_dom_material6_values::toFile(bob_dom_otextfilestream& os)
312
bool bob_material6_values::toFile(otextfilestream& os)
332
{
313
{
333
	os << (int)size();
314
	os << (int)size();
334
	for(iterator &it=begin(); it!=end(); ++it){
315
	for(iterator &it=begin(); it!=end(); ++it){
335
		it->toFile(os);
316
		it->toFile(os);
336
	}
317
	}
337
	return os.good();
318
	return os.good();
338
}
319
}
339
//---------------------------------------------------------------------------------
320
//---------------------------------------------------------------------------------
340
// MATERIAL6 - big
321
// MATERIAL6 - big
341
bob_error_codes bob_dom_material6::Big::load(bob_dom_ibinaryfilestream& is)
322
bob_error_codes bob_material6::Big::load(ibinaryfilestream& is)
342
{
323
{
343
	bob_error_codes errorCode;
324
	bob_error_codes errorCode;
344
	
325
 
345
	is >> technique >> effect;
326
	is >> technique >> effect;
346
	
327
 
347
	errorCode=values.load(is);
328
	errorCode=values.load(is);
348
	
329
 
349
	return errorCode;
330
	return errorCode;
350
}
331
}
351
//---------------------------------------------------------------------------------
332
//---------------------------------------------------------------------------------
352
bool bob_dom_material6::Big::toFile(bob_dom_obinaryfilestream& os)
333
bool bob_material6::Big::toFile(obinaryfilestream& os)
353
{
334
{
354
	os << technique << effect;
335
	os << technique << effect;
355
	values.toFile(os);
336
	values.toFile(os);
356
	return os.good();
337
	return os.good();
357
}
338
}
358
//---------------------------------------------------------------------------------
339
//---------------------------------------------------------------------------------
359
bool bob_dom_material6::Big::toFile(bob_dom_otextfilestream& os)
340
bool bob_material6::Big::toFile(otextfilestream& os)
360
{
341
{
361
	int old=os.flags();
342
	int old=os.flags();
362
	os << autoSemicolons << technique << effect;
343
	os << autoSemicolons << technique << effect;
363
	values.toFile(os);
344
	values.toFile(os);
364
	os.flags(old);
345
	os.flags(old);
365
	return os.good();
346
	return os.good();
366
}
347
}
367
//---------------------------------------------------------------------------------
348
//---------------------------------------------------------------------------------
368
// MATERIAL 6 - small
349
// MATERIAL 6 - small
369
bob_error_codes bob_dom_material6::Small::load(bob_dom_ibinaryfilestream& is, int flags)
350
bob_error_codes bob_material6::Small::load(ibinaryfilestream& is, int flags)
370
{
351
{
371
	is >> textureFile;
352
	is >> textureFile;
372
	is >> ambient >> diffuse >> specular;
353
	is >> ambient >> diffuse >> specular;
373
	is >> transparency >> selfIllumination >> shininess;
354
	is >> transparency >> selfIllumination >> shininess;
374
	short s=flags;
355
	short s=flags;
Line 376... Line 357...
376
	destinationBlend = (s & 0x2) > 0;
357
	destinationBlend = (s & 0x2) > 0;
377
	twoSided = (s & 0x10) > 0;
358
	twoSided = (s & 0x10) > 0;
378
	wireframe = (s & 0x8) > 0;
359
	wireframe = (s & 0x8) > 0;
379
	is >> textureValue >> enviromentMap >> bumpMap >> lightMap;
360
	is >> textureValue >> enviromentMap >> bumpMap >> lightMap;
380
	is >> map4 >> map5;
361
	is >> map4 >> map5;
381
	
362
 
382
	return !is.fail() ? e_noError : e_notEnoughData;
363
	return !is.fail() ? e_noError : e_notEnoughData;
383
}
364
}
384
//---------------------------------------------------------------------------------
365
//---------------------------------------------------------------------------------
385
bool bob_dom_material6::Small::toFile(bob_dom_obinaryfilestream& os)
366
bool bob_material6::Small::toFile(obinaryfilestream& os)
386
{
367
{
387
	static char *empty="";
368
	static char *empty="";
388
	os << (textureFile ? textureFile : empty);
369
	os << (textureFile ? textureFile : empty);
389
	os << ambient << diffuse << specular;
370
	os << ambient << diffuse << specular;
390
	os << transparency << selfIllumination << shininess;
371
	os << transparency << selfIllumination << shininess;
391
	
372
 
392
	os << textureValue << enviromentMap << bumpMap << lightMap;
373
	os << textureValue << enviromentMap << bumpMap << lightMap;
393
	os << map4 << map5;
374
	os << map4 << map5;
394
	
375
 
395
	return os.good();
376
	return os.good();
396
}
377
}
397
//---------------------------------------------------------------------------------
378
//---------------------------------------------------------------------------------
398
bool bob_dom_material6::Small::toFile(bob_dom_otextfilestream& os)
379
bool bob_material6::Small::toFile(otextfilestream& os)
399
{
380
{
400
	os << (*textureFile==0 ? "NULL" : textureFile);
381
	os << (*textureFile==0 ? "NULL" : textureFile);
401
	os << ambient << diffuse << specular;
382
	os << ambient << diffuse << specular;
402
	os << transparency << selfIllumination << shininess;
383
	os << transparency << selfIllumination << shininess;
403
	os << noSemicolons << destinationBlend << ';' << twoSided << ';' << autoSemicolons << wireframe;
384
	os << noSemicolons << destinationBlend << ';' << twoSided << ';' << autoSemicolons << wireframe;
404
	os << textureValue;
385
	os << textureValue;
405
	os << enviromentMap << bumpMap << lightMap << map4 << map5;
386
	os << enviromentMap << bumpMap << lightMap << map4 << map5;
406
	return os.good();
387
	return os.good();
407
}
388
}
408
//---------------------------------------------------------------------------------
389
//---------------------------------------------------------------------------------
409
// MATERIAL 6
390
// MATERIAL 6
410
bool bob_dom_material6::load(bob_dom_ibinaryfilestream& is)
391
bool bob_material6::load(ibinaryfilestream& is)
411
{
392
{
412
	is >> index;
393
	is >> index;
413
	is >> flags;
394
	is >> flags;
414
	
395
 
415
	if(flags==Big::flag) {
396
	if(flags==Big::flag) {
416
		big=new Big();
397
		big=new Big();
417
		errorCode=big->load(is);
398
		errorCode=big->load(is);
418
	}
399
	}
419
	else{
400
	else{
420
		/*FILE *f=fopen("d:\\mat56.log", "a+");
401
		/*FILE *f=fopen("d:\\mat56.log", "a+");
421
		fprintf(f, "%s - flags: %d, offset 0x%x\n", is.name(), flags, is.tell());
402
		fprintf(f, "%s - flags: %d, offset 0x%x\n", is.name(), flags, is.tell());
422
		fclose(f);
403
		fclose(f);
423
		*/
404
		*/
424
	
405
 
425
		small=new Small();
406
		small=new Small();
426
		errorCode=small->load(is, flags);
407
		errorCode=small->load(is, flags);
427
	}
408
	}
428
		
409
 
429
	return errorCode==e_noError;
410
	return errorCode==e_noError;
430
}
411
}
431
//---------------------------------------------------------------------------------
412
//---------------------------------------------------------------------------------
432
bool bob_dom_material6::toFile(bob_dom_obinaryfilestream& os)
413
bool bob_material6::toFile(obinaryfilestream& os)
433
{
414
{
434
	bool bRes;
415
	bool bRes;
435
	
416
 
436
	os << index << flags;
417
	os << index << flags;
437
	if(big)
418
	if(big)
438
		bRes=big->toFile(os);
419
		bRes=big->toFile(os);
439
	else
420
	else
440
		bRes=small->toFile(os);
421
		bRes=small->toFile(os);
441
		
422
 
442
	return bRes;
423
	return bRes;
443
}
424
}
444
//---------------------------------------------------------------------------------
425
//---------------------------------------------------------------------------------
445
bool bob_dom_material6::toFile(bob_dom_otextfilestream& os)
426
bool bob_material6::toFile(otextfilestream& os)
446
{
427
{
447
	int old=os.flags();
428
	int old=os.flags();
448
	os << noSemicolons << "MATERIAL6: " 
429
	os << noSemicolons << "MATERIAL6: "
449
	<< autoSemicolons << index << noSemicolons << "0x" << hex << autoSemicolons << flags << dec;
430
	<< autoSemicolons << index << noSemicolons << "0x" << hex << autoSemicolons << flags << dec;
450
	
431
 
451
	if(big) 
432
	if(big)
452
		big->toFile(os);
433
		big->toFile(os);
453
	else if(small)
434
	else if(small)
454
		small->toFile(os);
435
		small->toFile(os);
455
	
436
 
456
	os.flags(old);
437
	os.flags(old);
457
	return os.good();
438
	return os.good();
458
}
439
}
459
//---------------------------------------------------------------------------------
440
//---------------------------------------------------------------------------------
460
// MATERIAL - section
441
// MATERIAL - section
461
bool bob_dom_materials::load(bob_dom_ibinaryfilestream& is)
442
bool bob_materials::load(ibinaryfilestream& is)
462
{
443
{
463
	int hdr;
444
	int hdr;
464
	bob_dom_material::materialType type;
445
	bob_material::materialType type;
465
	
446
 
466
	is >> hdr;
447
	is >> hdr;
-
 
448
	
467
	switch(hdr){
449
	switch(hdr){
468
		case hdr_mat5_begin:
450
		case HDR_MAT5_BEGIN:
469
			type=bob_dom_material::mat5;
451
			type=bob_material::mat5;
470
			break;
452
			break;
471
		case hdr_mat6_begin:
453
		case HDR_MAT6_BEGIN:
472
			type=bob_dom_material::mat6;
454
			type=bob_material::mat6;
473
			break;
455
			break;
474
		default:
456
		default:
475
			error(e_badHeader);
457
			error(e_badHeader);
476
			return false;
458
			return false;
477
	}
459
	}
478
	
460
 
479
	int matCount;
461
	int matCount;
480
	is >> matCount;
462
	is >> matCount;
481
 
463
 
482
	bob_dom_material *m;
464
	bob_material *m;
483
	for(int i=0; i < matCount; i++){
465
	for(int i=0; i < matCount; i++){
484
		switch(type) {
466
		switch(type) {
485
			case bob_dom_material::mat5:
467
			case bob_material::mat5:
486
				m=new bob_dom_material5();
468
				m=new bob_material5();
487
				break;
-
 
488
			case bob_dom_material::mat6:
-
 
489
				m=new bob_dom_material6();
-
 
490
				break;
469
				break;
-
 
470
			case bob_material::mat6:
-
 
471
				m=new bob_material6();
-
 
472
				break;
491
		}
473
		}
492
		if(m->load(is)==false){
474
		if(m->load(is)==false){
493
			error(m->errorCode, "material[%d]: %s", i, bob_traslate_error(m->errorCode));
475
			error(m->errorCode, "material[%d]: %s", i, bob_traslate_error(m->errorCode));
494
			delete m;
476
			delete m;
495
			return false;
477
			return false;
496
		}
478
		}
497
		else
479
		else
498
			push_back(m);
480
			push_back(m);
499
	}
481
	}
500
	is >> hdr;
482
	is >> hdr;
501
	if(hdr!=hdr_end)
483
	if(hdr!=HDR_END)
502
		error(e_badEndHeader);
484
		error(e_badEndHeader);
503
	
485
 
504
	return (hdr==hdr_end && !is.fail());
486
	return (hdr==HDR_END && !is.fail());
505
}
487
}
506
//---------------------------------------------------------------------------------
488
//---------------------------------------------------------------------------------
507
bool bob_dom_materials::toFile(bob_dom_obinaryfilestream& os)
489
bool bob_materials::toFile(obinaryfilestream& os)
508
{
490
{
509
	int hdr;
491
	int hdr;
510
	if(size() && front()->type==bob_dom_material::mat6)
492
	if(size() && front()->type==bob_material::mat6)
511
		hdr=hdr_mat6_begin;
493
		hdr=HDR_MAT6_BEGIN;
512
	else
494
	else
513
		hdr=hdr_mat5_begin;
495
		hdr=HDR_MAT5_BEGIN;
514
		
496
 
515
	os << hdr << (int)size();
497
	os << hdr << (int)size();
516
	for(iterator &it=begin(); it!=end(); ++it){
498
	for(iterator &it=begin(); it!=end(); ++it){
517
		it->toFile(os);
499
		it->toFile(os);
518
	}
500
	}
519
	os << hdr_end;
501
	os << HDR_END;
520
	return os.good();
502
	return os.good();
521
}
503
}
522
//---------------------------------------------------------------------------------
504
//---------------------------------------------------------------------------------
523
bool bob_dom_materials::toFile(bob_dom_otextfilestream& os)
505
bool bob_materials::toFile(otextfilestream& os)
524
{
506
{
525
	for(iterator &it=begin(); it!=end(); ++it){
507
	for(iterator &it=begin(); it!=end(); ++it){
526
		it->toFile(os);
508
		it->toFile(os);
527
		os << endl;
509
		os << endl;
528
	}
510
	}
529
	return os.good();
511
	return os.good();
530
}
512
}
531
//---------------------------------------------------------------------------------
513
//---------------------------------------------------------------------------------
532
// BODIES - section
514
// BODIES - section
533
bool bob_dom_bodies::load(bob_dom_ibinaryfilestream& is)
515
bool bob_bodies::load(ibinaryfilestream& is)
534
{
516
{
535
	int hdr;
517
	int hdr;
536
	is >> hdr;
518
	is >> hdr;
537
	if(hdr!=hdr_begin){
519
	if(hdr!=HDR_BEGIN){
538
		error(e_badHeader);
520
		error(e_badHeader);
539
		return false;
521
		return false;
540
	}
522
	}
541
	short bodyCount;
523
	short bodyCount;
542
	is >> bodyCount;
524
	is >> bodyCount;
543
	
525
 
544
	child_type *ch;
526
	child_type *ch;
545
	for(int i=0; i < bodyCount; i++){
527
	for(int i=0; i < bodyCount; i++){
546
		ch=createChild();
528
		ch=createChild();
547
		if(ch->load(is)==false){
529
		if(ch->load(is)==false){
548
			for(ErrorIterator &it=ch->errors.begin(); it!=ch->errors.end(); ++it){
530
			for(ErrorIterator &it=ch->errors.begin(); it!=ch->errors.end(); ++it){
549
				error(it->code, "body[%d]->%s", i, it->text);
531
				error(it->code, "body[%d]->%s", i, it->text);
550
			}
532
			}
551
			return false;
533
			return false;
552
		}
534
		}
553
	}
535
	}
554
	
536
 
555
	is >> hdr;
537
	is >> hdr;
556
	if(is.fail())
538
	if(is.fail())
557
		error(e_notEnoughData);
539
		error(e_notEnoughData);
558
		
540
 
559
	if(hdr!=hdr_end)
541
	if(hdr!=HDR_END)
560
		error(e_badEndHeader);
542
		error(e_badEndHeader);
561
	
543
 
562
	return hdr==hdr_end;
544
	return hdr==HDR_END;
563
}
545
}
564
//---------------------------------------------------------------------------------
546
//---------------------------------------------------------------------------------
565
bool bob_dom_bodies::toFile(bob_dom_obinaryfilestream& os)
547
bool bob_bodies::toFile(obinaryfilestream& os)
566
{
548
{
567
	os << hdr_begin << (short)size();
549
	os << HDR_BEGIN << (short)size();
568
	for(iterator &it=begin(); it!=end(); ++it){
550
	for(iterator &it=begin(); it!=end(); ++it){
569
		it->toFile(os);
551
		it->toFile(os);
570
	}
552
	}
571
	os << hdr_end;
553
	os << HDR_END;
572
	return os.good();
554
	return os.good();
573
}
555
}
574
//---------------------------------------------------------------------------------
556
//---------------------------------------------------------------------------------
575
bool bob_dom_bodies::toFile(bob_dom_otextfilestream& os, const Settings *settings, const bob_dom_materials *materials)
557
bool bob_bodies::toFile(otextfilestream& os, const Settings& settings, const bob_materials *materials)
576
{
558
{
577
	bool bRes=true;
-
 
578
	int i=1;
559
	int i=1;
579
	os << noSemicolons << "// beginning of bodies (" << (int)size() << ')' << endl;
560
	os << noSemicolons << "// beginning of bodies (" << (int)size() << ')' << endl;
580
	for(iterator &it=begin(); it!=end(); ++it, ++i){
561
	for(iterator &it=begin(); it!=end(); ++it, ++i){
581
		bRes&=it->toFile(os, settings, materials, i);
562
		if(it->toFile(os, settings, materials, i)==false){
-
 
563
			for(bob_body::ErrorIterator &e_it=it->errors.begin(); e_it!=it->errors.end(); ++e_it){
-
 
564
				error(e_it->severity, e_it->code, "Body[%d]->%s", i, e_it->text);
-
 
565
			}
-
 
566
			return false;
-
 
567
		}
582
		os << endl;
568
		os << endl;
583
	}
569
	}
584
	os << "// end of bodies" << endl;
570
	os << "// end of bodies" << endl;
585
	return bRes;
571
	return os.good();
586
}
572
}
587
//---------------------------------------------------------------------------------
573
//---------------------------------------------------------------------------------
588
// POINTS - section
574
// POINTS - section
589
bool bob_dom_points::load(bob_dom_ibinaryfilestream& is)
575
bool bob_vertices::load(ibinaryfilestream& is)
590
{
576
{
591
	int hdr;
577
	int hdr;
592
	is >> hdr;
578
	is >> hdr;
593
	if(hdr!=hdr_begin){
579
	if(hdr!=HDR_BEGIN){
594
		error(e_badHeader);
580
		error(e_badHeader);
595
		return false;
581
		return false;
596
	}
582
	}
597
	
583
 
598
	int pointCount;
584
	int pointCount;
599
	is >> pointCount;
585
	is >> pointCount;
600
	
586
 
601
	map.create(pointCount);
587
	map.create(pointCount);
602
	
588
 
603
	bob_dom_point *ch;
589
	bob_vertex *ch;
604
	for(int i=0; i < pointCount; i++){
590
	for(int i=0; i < pointCount; i++){
605
		ch=new bob_dom_point();
591
		ch=new bob_vertex();
606
		if(ch->load(is)==false){
592
		if(ch->load(is)==false){
607
			error(ch->errorCode, "point[%d]: %s", i, bob_traslate_error(ch->errorCode));
593
			error(ch->errorCode, "point[%d]: %s", i, bob_traslate_error(ch->errorCode));
608
			delete ch;
594
			delete ch;
609
			return false;
595
			return false;
610
		}
596
		}
611
		map.addPoint(ch);
597
		map.addPoint(ch);
612
		
598
 
613
	}
599
	}
614
	
-
 
615
	//printf("AVL Points: %d, compares: %d, average comp to find pnt: %d\n", pointCount, map.map2.m_compCount, map.map2.m_compCount / pointCount);
-
 
616
	
-
 
617
	//printf("TST: Points: %d, compares: %d, average comp to find pnt: %d\n", pointCount,map.m_compCount, map.m_compCount / pointCount);
-
 
618
	
600
 
619
	is >> hdr;
601
	is >> hdr;
620
	if(hdr!=hdr_end)
602
	if(hdr!=HDR_END)
621
		error(e_badEndHeader);
603
		error(e_badEndHeader);
622
		
604
 
623
	return hdr==hdr_end && !is.fail();
605
	return hdr==HDR_END && !is.fail();
624
}
606
}
625
//---------------------------------------------------------------------------------
607
//---------------------------------------------------------------------------------
626
bool bob_dom_points::toFile(bob_dom_obinaryfilestream& os)
608
bool bob_vertices::toFile(obinaryfilestream& os)
627
{
609
{
628
	os << hdr_begin;
610
	os << HDR_BEGIN;
629
	
611
 
630
	if(new_points.size()){
612
	if(new_vertices.size()){
631
		os << (int)new_points.size();
613
		os << (int)new_vertices.size();
632
		for(PointIterator &it=new_points.begin(); it!=new_points.end(); ++it){
614
		for(VertexIterator &it=new_vertices.begin(); it!=new_vertices.end(); ++it){
633
			it->toFile(os);
615
			it->toFile(os);
634
		}
616
		}
635
	}
617
	}
636
	else{
618
	else{
637
		os << (int)map.pointsSize();
619
		os << (int)map.pointsSize();
638
		for(bob_point_map::iterator &it=map.begin(); it!=map.end(); ++it){
620
		for(bob_point_map::iterator &it=map.begin(); it!=map.end(); ++it){
639
			it->toFile(os);
621
			it->toFile(os);
640
		}
622
		}
641
	}
623
	}
642
	os << hdr_end;
624
	os << HDR_END;
643
	return os.good();
625
	return os.good();
644
}
626
}
645
//---------------------------------------------------------------------------------
627
//---------------------------------------------------------------------------------
-
 
628
bool bob_vertices::toFile(otextfilestream& os, const Settings& settings)
-
 
629
{
-
 
630
	if(settings.rawMode())
-
 
631
		return outputRaw(os);
-
 
632
	else
-
 
633
		return outputBOD(os);
-
 
634
}
-
 
635
//---------------------------------------------------------------------------------
646
bool bob_dom_points::toFile(bob_dom_otextfilestream& os)
636
bool bob_vertices::outputBOD(otextfilestream& os)
647
{
637
{
648
	int oldf=os.flags();
638
	int oldf=os.flags();
649
	int i=0;
639
	int i=0;
650
	os << noSemicolons << "// beginning of points (" << (int)map.uniquePointsSize() << ')' << endl << autoSemicolons;
640
	os << noSemicolons << "// beginning of points (" << (int)map.uniquePointsSize() << ')' << endl << autoSemicolons;
651
	
641
 
652
	bob_dom_point *p;
642
	bob_vertex *p;
653
	while(p=map.nextUniquePoint()){
643
	while(p=map.nextUniquePoint()){
654
		p->toFile(os, i++);
644
		p->toFile(os, i++);
655
	}
645
	}
-
 
646
 
656
	os << noSemicolons << "-1; -1; -1; // points end" << endl << endl;
647
	os << noSemicolons << "-1; -1; -1; // points end" << endl << endl;
-
 
648
 
-
 
649
	os.flags(oldf);
-
 
650
	return os.good();
-
 
651
}
-
 
652
//---------------------------------------------------------------------------------
-
 
653
bool bob_vertices::outputRaw(otextfilestream& os)
-
 
654
{
-
 
655
	int oldf=os.flags();
-
 
656
	int i=0;
-
 
657
 
-
 
658
	os << noSemicolons << "// Vertices begin (" << (int)map.pointsSize() << " - " << (int)map.uniquePointsSize() << " unique)" << endl << autoSemicolons;
-
 
659
	for(bob_point_map::iterator &it=map.begin(); it!=map.end(); ++it, i++){
-
 
660
		os << autoSemicolons
-
 
661
		<< it->x << it->y << it->z;
-
 
662
 
-
 
663
		if(it->hasTextureCoords()){
-
 
664
			os << noSemicolons << "\t\tUV: " << autoSemicolons
-
 
665
			<< it->textureCoords.x << it->textureCoords.y;
-
 
666
		}
-
 
667
		
-
 
668
		if(it->flags & bob_vertex::FLAG_WEIRD_STUFF){
-
 
669
			os << noSemicolons << "\tWeird coords: " << autoSemicolons
-
 
670
			<< it->weirdCoords.x << it->weirdCoords.y;
-
 
671
		}
-
 
672
		
-
 
673
		os << noSemicolons << "\tNormal: " << autoSemicolons
-
 
674
		<< it->normalVector.x << it->normalVector.y << it->normalVector.z
-
 
675
		<< noSemicolons << "\tSGBits: " << it->sgbits;
-
 
676
 
-
 
677
		os << noSemicolons << " // " << i << endl;
-
 
678
	}
-
 
679
 
-
 
680
	os << noSemicolons << "-1; -1; -1; // Vertices end" << endl << endl;
657
	
681
	
658
	os.flags(oldf);
682
	os.flags(oldf);
659
	return os.good();
683
	return os.good();
660
}
684
}
661
//---------------------------------------------------------------------------------
685
//---------------------------------------------------------------------------------
662
// POINT - object
686
// POINT - object
663
double bob_dom_point::multiplier=1.52587890625; // == 100000 / 65535
687
bool bob_vertex::load(ibinaryfilestream&; is)
-
 
688
{
-
 
689
	/*
-
 
690
		possible types
-
 
691
		0x1F - normal + UV + 2 unk values
-
 
692
		0x1B - normal + UV
-
 
693
		0x19 - normal
-
 
694
	*/
-
 
695
 
-
 
696
	is >> flags >> *(vertex*)this;
-
 
697
	
-
 
698
	if((flags & FLAG_DEFAULT)!=FLAG_DEFAULT){
-
 
699
		errorCode=e_unkPointFlags;
-
 
700
		return false;
-
 
701
	}
-
 
702
 
-
 
703
	if(hasTextureCoords())
-
 
704
		is >> textureCoords;
-
 
705
	
-
 
706
	if(flags & FLAG_WEIRD_STUFF)
-
 
707
		is >> weirdCoords;
-
 
708
 
-
 
709
	is >> normalVector >> sgbits;
664
 
710
 
665
bool bob_dom_point::load(bob_dom_ibinaryfilestream& is)
-
 
666
{
-
 
667
	int size, v;
-
 
668
	
-
 
669
	is >> type;
-
 
670
	switch(type){
-
 
671
		case 0x1F:
-
 
672
			size=11;
-
 
673
			break;
-
 
674
		case 0x1B:
-
 
675
			size=9;
-
 
676
			break;
-
 
677
		case 0x19:
-
 
678
			size=7;
-
 
679
			break;
-
 
680
		default:
-
 
681
			errorCode=e_unkPointHeader;
-
 
682
			return false;
-
 
683
	}
-
 
684
	is >> x >> y >> z;
-
 
685
	is >> textureCoords.left >> textureCoords.right;
-
 
686
	
-
 
687
	for(int i=5; i < size; i++){
-
 
688
		is >> v;
-
 
689
		values.push_back(v);
-
 
690
	}
-
 
691
	
-
 
692
	if(is.fail())
711
	if(is.fail())
693
		errorCode=e_notEnoughData;
712
		errorCode=e_notEnoughData;
694
	
713
 
695
	return !is.fail();
714
	return !is.fail();
696
}
715
}
697
//---------------------------------------------------------------------------------
716
//---------------------------------------------------------------------------------
698
bool bob_dom_point::toFile(bob_dom_obinaryfilestream& os)
717
bool bob_vertex::toFile(obinaryfilestream& os)
699
{
718
{
700
	os << type << x << y << z << textureCoords.left << textureCoords.right;
719
	// set the default bits before outputting
-
 
720
	flags|=FLAG_DEFAULT;
-
 
721
 
701
	for(iterator &;it=values.begin(); it!=values.end(); ++it){
722
	os << flags << *(dynamic_cast<vertex*>;(this));
-
 
723
	if(hasTextureCoords())
-
 
724
		os << textureCoords;
-
 
725
 
-
 
726
	if(flags & FLAG_WEIRD_STUFF)
702
		os << *it;
727
		os << weirdCoords;
703
	}
728
		
-
 
729
	os << normalVector << sgbits;
-
 
730
 
-
 
731
	return os.good();
-
 
732
}
-
 
733
//---------------------------------------------------------------------------------
-
 
734
bool bob_vertex::toFile(otextfilestream& os, int idx)
-
 
735
{
-
 
736
	// autoSemicolons is set by parent (points)
-
 
737
 
-
 
738
	int coords[3];
-
 
739
	getBodCoords(coords);
-
 
740
 
-
 
741
	os << coords[0] << coords[1] << coords[2];
-
 
742
 
-
 
743
	os << noSemicolons << "// " << idx << endl << autoSemicolons;
704
	return os.good();
744
	return os.good();
705
}
745
}
706
//---------------------------------------------------------------------------------
746
//---------------------------------------------------------------------------------
-
 
747
// X3 vertex_data_record
707
bool bob_dom_point::toFile(bob_dom_otextfilestream& os, int idx)
748
bool bob_x3vertex_data_record::load(ibinaryfilestream& is)
708
{
749
{
709
	// autoSemicolons is set by parent (points)
750
	is >> pointIndex >> tangent >> unk;
710
	int x,y,z;
-
 
711
	
-
 
712
	__asm{
-
 
713
		mov eax, this
-
 
714
		
-
 
715
/*		fld multiplier
-
 
716
		fimul [eax].x
-
 
717
		fistp x*/
-
 
718
		
-
 
719
		fld multiplier
-
 
720
		fimul [eax].y
-
 
721
		fistp y
-
 
722
		
-
 
723
		fld multiplier
-
 
724
		fimul [eax].z
-
 
725
		fistp z
-
 
726
	}
-
 
727
	os << x << y << z;
-
 
728
	
-
 
729
	os << noSemicolons << "// " << idx << endl << autoSemicolons;
-
 
730
	return os.good();
-
 
731
}
-
 
732
//---------------------------------------------------------------------------------
-
 
733
// X3 UV record
-
 
734
bool bob_x3uv::load(bob_dom_ibinaryfilestream& is)
-
 
735
{
-
 
736
	is >> idx;
-
 
737
	for(int i=0; i < 6; i++){
-
 
738
		is >> values[i];
-
 
739
	}
-
 
740
	return !is.fail();
751
	return !is.fail();
741
}
752
}
742
//---------------------------------------------------------------------------------
753
//---------------------------------------------------------------------------------
743
bool bob_x3uv::toFile(bob_dom_obinaryfilestream& os)
754
bool bob_x3vertex_data_record::toFile(obinaryfilestream& os)
744
{
-
 
745
	os << idx;
-
 
746
	for(int i=0; i < 6; i++){
-
 
747
		os << values[i];
-
 
748
	}
-
 
749
	return os.good();
-
 
750
}
-
 
751
//---------------------------------------------------------------------------------
-
 
752
bool bob_x3uv::toFile(bob_dom_otextfilestream& os, int matIdx)
-
 
753
{
755
{
754
	int old=os.flags();
-
 
755
	os << autoSemicolons;
-
 
756
	os << matIdx << idx;
756
	os << pointIndex << tangent << unk;
757
	for(int i=0; i < 6; i++){
-
 
758
		os << values[i];
-
 
759
	}
-
 
760
	os.flags(old);
-
 
761
	return os.good();
757
	return os.good();
762
}
-
 
763
//---------------------------------------------------------------------------------
-
 
764
int compare_uv(const void *a, const void *b)
-
 
765
{
-
 
766
	const bob_x3uv *uv1=*((bob_x3uv**)a), *uv2=*((bob_x3uv**)b);
-
 
767
	return uv1->idx - uv2->idx;
-
 
768
}
758
}
-
 
759
//---------------------------------------------------------------------------------
-
 
760
/*int compare_x3vertex_rec(const void *a, const void *b)
-
 
761
{
-
 
762
	const bob_x3vertex_data_record *rec1=*((bob_x3vertex_data_record**)a), *rec2=*((bob_x3vertex_data_record**)b);
-
 
763
	return rec1->pointIndex - rec2->pointIndex;
-
 
764
}*/
769
//---------------------------------------------------------------------------------
765
//---------------------------------------------------------------------------------
770
// X3 uv list
766
// X3 uv list
771
bool bob_x3uv_list::load(bob_dom_ibinaryfilestream& is)
767
bool bob_x3vertex_data::load(ibinaryfilestream& is)
772
{
768
{
773
	int count;
769
	int count;
774
	bob_x3uv *uv;
770
	bob_x3vertex_data_record *rec;
775
	
771
 
776
	is >> count;
772
	is >> count;
777
	reserve(count);
773
	reserve(count);
778
	for(int i=0; i < count; i++){
774
	for(int i=0; i < count; i++){
779
		uv=new bob_x3uv();
775
		rec=new bob_x3vertex_data_record();
780
		if(!uv->load(is)){
776
		if(!rec->load(is)){
781
			delete uv;
777
			delete rec;
782
			return false;
778
			return false;
783
		}
779
		}
784
		push_back(uv);
780
		push_back(rec);
785
	}
781
	}
-
 
782
	
-
 
783
	/* 
-
 
784
		there should never be the need to compare the data, because they are written in the order of vertices,
-
 
785
		and thus their vertex indexes are always in sequence
-
 
786
	*/
786
	sort(compare_uv);
787
	//sort(compare_x3vertex_rec);
-
 
788
 
787
	return !is.fail();
789
	return !is.fail();
788
}
790
}
789
//---------------------------------------------------------------------------------
791
//---------------------------------------------------------------------------------
790
bool bob_x3uv_list::toFile(bob_dom_obinaryfilestream& os)
792
bool bob_x3vertex_data::toFile(obinaryfilestream& os)
791
{
-
 
792
	os << (int) size();
-
 
793
	for(iterator &it=begin(); it!=end(); ++it){
-
 
794
		it->toFile(os);
-
 
795
	}
-
 
796
	return os.good();
-
 
797
}
-
 
798
//---------------------------------------------------------------------------------
-
 
799
bool bob_x3uv_list::toFile(bob_dom_otextfilestream& os, int matIdx)
-
 
800
{
793
{
-
 
794
	os << (int) size();
801
	for(iterator &it=begin(); it!=end(); ++it){
795
	for(iterator &it=begin(); it!=end(); ++it){
802
		it->toFile(os, matIdx);
796
		it->toFile(os);
803
		os << endl;
-
 
804
	}
797
	}
805
	return os.good();
798
	return os.good();
806
}
799
}
807
//---------------------------------------------------------------------------------
800
//---------------------------------------------------------------------------------
808
 
801
 
809
// FACE LIST
802
// FACE LIST
810
bool bob_face_list::load(bob_dom_ibinaryfilestream& is, bool x3data)
803
bool bob_face_list::load(ibinaryfilestream& is, bool x3data)
811
{
804
{
812
	int count;
805
	int count;
813
	
806
 
814
	is >> materialIndex >> count;
807
	is >> materialIndex >> count;
815
	
808
 
816
	for(int i=0; i < count; i++){
809
	for(int i=0; i < count; i++){
817
		bob_dom_face *face=new bob_dom_face();
810
		bob_face *face=new bob_face();
818
		if(face->load(is)==false){
811
		if(face->load(is)==false){
819
			error(face->errorCode, "face[%d]: %s", i, bob_traslate_error(face->errorCode));
812
			error(face->errorCode, "face[%d]: %s", i, bob_traslate_error(face->errorCode));
820
			delete face;
813
			delete face;
821
			return false;
814
			return false;
822
		}
815
		}
823
		push_back(face);
816
		push_back(face);
824
	}
817
	}
825
	
818
 
826
	if(x3data && x3uvlist.load(is)==false) return false;
819
	if(x3data && x3vertexData.load(is)==false) return false;
827
	
820
 
828
	return !is.fail();
821
	return !is.fail();
829
}
822
}
830
//---------------------------------------------------------------------------------
823
//---------------------------------------------------------------------------------
831
bool bob_face_list::toFile(bob_dom_obinaryfilestream& os, bool x3data)
824
bool bob_face_list::toFile(obinaryfilestream& os, const bob_vertices& vertices, bool x3data)
832
{
825
{
833
	os << materialIndex << (int)size();
826
	os << materialIndex << (int)size();
834
	for(iterator &it=begin(); it!=end(); ++it){
827
	for(iterator &it=begin(); it!=end(); ++it){
835
		it->toFile(os);
828
		it->toFile(os);
836
	}
829
	}
837
	
830
 
838
	if(x3data)
831
	if(x3data)
-
 
832
		saveVertexTangents(os, vertices);
-
 
833
 
-
 
834
	return os.good();
-
 
835
}
-
 
836
//---------------------------------------------------------------------------------
-
 
837
bool bob_face_list::saveVertexTangents(obinaryfilestream& os, const bob_vertices& vertices)
-
 
838
{
-
 
839
	// the still unknown God damned vector
-
 
840
	vector vec1(0,0,1); // default value
-
 
841
	vector vec0(0,0,0); // zero value
-
 
842
	
-
 
843
	bool *vert_map=new bool[vertices.new_vertices.size()];
-
 
844
	memset(vert_map, 0, vertices.new_vertices.size() * sizeof(bool));
-
 
845
	
-
 
846
	size_t count_pos=os.tell();
-
 
847
	os << 123; // dummy count
-
 
848
	
-
 
849
	int idx, count=0;
-
 
850
	for(iterator &it=begin(); it!=end(); ++it){
-
 
851
		for(int i=0; i < 3; i++){
-
 
852
			idx=it->values[i];
-
 
853
			if(vert_map[idx]==false) {
-
 
854
				vector &tan=vertices.new_vertices[idx]->tangentVector;
-
 
855
				os << idx << tan << (tan.isZero() ? vec0 : vec1);
-
 
856
				vert_map[idx]=true;
-
 
857
				count++;
-
 
858
			}
-
 
859
		}
-
 
860
	}
-
 
861
	delete[] vert_map;
-
 
862
 
-
 
863
	// write the real count
839
		x3uvlist.toFile(os);
864
	size_t lastp=os.tell();
-
 
865
	os.seek((int)count_pos, mystream::stream_base::seek_begin);
-
 
866
	os << count;
-
 
867
	os.seek((int)lastp, mystream::stream_base::seek_begin);
-
 
868
 
-
 
869
	return os.good();
-
 
870
}
-
 
871
//---------------------------------------------------------------------------------
-
 
872
bool bob_face_list::outputX3VertexDataRaw(otextfilestream& os)
-
 
873
{
-
 
874
	if(x3vertexData.size()==0) return true;
-
 
875
	
-
 
876
	int old=os.flags();
-
 
877
	os << noSemicolons << "// Material " << materialIndex << endl;
-
 
878
	os << "// Material; point index; tangent; unknown" << endl << autoSemicolons;
-
 
879
	for(bob_x3vertex_data::const_iterator &it=x3vertexData.begin(); it!=x3vertexData.end(); ++it){
-
 
880
		os << materialIndex << it->pointIndex << it->tangent << it->unk << endl;
-
 
881
	}
-
 
882
	os << endl;
-
 
883
	os.flags(old);
-
 
884
	return os.good();
-
 
885
}
-
 
886
//---------------------------------------------------------------------------------
-
 
887
/*
-
 
888
bool bob_face_list::computeAndOutputTangents(otextfilestream& os, const bob_point_map& pointMap)
-
 
889
{
-
 
890
	vertex v1, v2, v3;
-
 
891
	geometry::point2d<double> w1,w2,w3;
-
 
892
	int i1,i2,i3;
-
 
893
	
-
 
894
	vector *tan1, *tan2;
-
 
895
	
-
 
896
	tan1=new vector[pointMap.pointsSize() * 2];
-
 
897
	tan2=tan1 + pointMap.pointsSize();
-
 
898
	
-
 
899
	for(iterator &it=begin(); it!=end(); ++it){
-
 
900
		
-
 
901
		i1=it->values[0]; i2=it->values[1]; i3=it->values[2];
-
 
902
		v1=*pointMap[i1];
-
 
903
		v2=*pointMap[i2];
-
 
904
		v3=*pointMap[i3];
-
 
905
		
-
 
906
		w1=pointMap[i1]->textureCoords;
-
 
907
		w2=pointMap[i2]->textureCoords;
-
 
908
		w3=pointMap[i3]->textureCoords;
-
 
909
		
-
 
910
		double x1 = v2.x - v1.x;
-
 
911
    double x2 = v3.x - v1.x;
-
 
912
    double y1 = v2.y - v1.y;
-
 
913
    double y2 = v3.y - v1.y;
-
 
914
    double z1 = v2.z - v1.z;
-
 
915
    double z2 = v3.z - v1.z;
-
 
916
    
-
 
917
    double s1 = w2.x - w1.x;
-
 
918
    double s2 = w3.x - w1.x;
-
 
919
    double t1 = w2.y - w1.y;
-
 
920
    double t2 = w3.y - w1.y;
-
 
921
    
-
 
922
    double cp=s1 * t2 - s2 * t1;
-
 
923
    
-
 
924
    if(cp!=0) {
-
 
925
			double r = 1.0 / cp;
-
 
926
			vector sdir((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r,
-
 
927
							(t2 * z1 - t1 * z2) * r);
-
 
928
			vector tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r,
-
 
929
							(s1 * z2 - s2 * z1) * r);
-
 
930
			
-
 
931
			tan1[i1] += sdir;
-
 
932
			tan1[i2] += sdir;
-
 
933
			tan1[i3] += sdir;
-
 
934
	    
-
 
935
			tan2[i1] += tdir;
-
 
936
			tan2[i2] += tdir;
-
 
937
			tan2[i3] += tdir;
-
 
938
		}
-
 
939
	}
-
 
940
 
-
 
941
	int oldf=os.flags();
-
 
942
	
-
 
943
	os << noSemicolons << "// vertex tangents" << autoSemicolons << endl;
-
 
944
	
-
 
945
	int i=0;
-
 
946
	for(bob_point_map::const_iterator &it=pointMap.begin(); it!=pointMap.end(); ++it, i++){
-
 
947
		const vector& n=it->normalVector;
-
 
948
		const vector& t=tan1[i];
-
 
949
		const vector& bt=tan2[i];
-
 
950
		
-
 
951
		// Gram-Schmidt orthogonalize
-
 
952
		vector tangent = (t - n * n.dot(t)).normalize();
-
 
953
		
-
 
954
		os << i << tangent << endl;
-
 
955
		
-
 
956
	}
-
 
957
	
-
 
958
	delete[] tan1;
-
 
959
	
-
 
960
	os.flags(oldf);
840
	
961
	
841
	return os.good();
962
	return os.good();
842
}
963
}*/
843
//---------------------------------------------------------------------------------
964
//---------------------------------------------------------------------------------
844
// PARTS - section PART
965
// PARTS - section PART
845
bool bob_dom_parts::load(bob_dom_ibinaryfilestream& is)
966
bool bob_parts::load(ibinaryfilestream& is)
846
{
967
{
847
	int hdr, count;
968
	int hdr, count;
848
	
969
 
849
	is >> hdr;
970
	is >> hdr;
850
	if(hdr!=hdr_begin){
971
	if(hdr!=HDR_BEGIN){
851
		error(e_badHeader);
972
		error(e_badHeader);
852
		return false;
973
		return false;
853
	}
974
	}
854
	
975
 
855
	is >> count;
976
	is >> count;
856
	
977
 
857
	bob_dom_part *part;
978
	bob_part *part;
858
	for(int i=0; i < count; i++){
979
	for(int i=0; i < count; i++){
859
		part=new bob_dom_part();
980
		part=new bob_part();
860
		if(!part->load(is)){
981
		if(!part->load(is)){
861
			for(ErrorIterator &it=part->errors.begin(); it!=part->errors.end(); ++it){
982
			for(ErrorIterator &it=part->errors.begin(); it!=part->errors.end(); ++it){
862
				error(it->severity, it->code, "part[%d]->%s", i, it->text);
983
				error(it->severity, it->code, "part[%d]->%s", i, it->text);
863
			}
984
			}
864
			delete part;
985
			delete part;
Line 866... Line 987...
866
		}
987
		}
867
		push_back(part);
988
		push_back(part);
868
	}
989
	}
869
 
990
 
870
	is >> hdr;
991
	is >> hdr;
871
	if(hdr!=hdr_end)
992
	if(hdr!=HDR_END)
872
		error(e_badEndHeader);
993
		error(e_badEndHeader);
873
	
994
 
874
	return hdr==hdr_end && !is.fail();
995
	return hdr==HDR_END && !is.fail();
875
}
996
}
876
//---------------------------------------------------------------------------------
997
//---------------------------------------------------------------------------------
877
bool bob_dom_parts::toFile(bob_dom_obinaryfilestream& os)
998
bool bob_parts::toFile(obinaryfilestream& os, const bob_vertices& vertices)
878
{
999
{
879
	os << hdr_begin << (int) size();
1000
	os << HDR_BEGIN << (int) size();
880
	for(iterator &it=begin(); it!=end(); ++it){
1001
	for(iterator &it=begin(); it!=end(); ++it){
881
		it->toFile(os);
1002
		it->toFile(os, vertices);
882
	}
-
 
883
	os << hdr_end;
-
 
884
	
-
 
885
	return os.good();
-
 
886
}
-
 
887
//---------------------------------------------------------------------------------
-
 
888
bool bob_dom_parts::toFile(bob_dom_otextfilestream& os, const Settings *settings, const bob_dom_materials *materials, const bob_point_map *pointMap)
-
 
889
{
-
 
890
	int i=1;
-
 
891
	for(iterator &it=begin(); it!=end(); ++it, ++i){
-
 
892
		it->toFile(os, settings, materials, pointMap, i);
-
 
893
	}
1003
	}
-
 
1004
	os << HDR_END;
-
 
1005
 
894
	return os.good();
1006
	return os.good();
895
}
1007
}
896
//---------------------------------------------------------------------------------
1008
//---------------------------------------------------------------------------------
897
bool bob_dom_part_x3vals::load(bob_dom_ibinaryfilestream& is)
1009
bool bob_parts::toFile(otextfilestream& os, const Settings& settings, const bob_materials *materials, const bob_point_map *pointMap)
898
{
1010
{
-
 
1011
	int i=1;
899
	for(int i=0; i &lt; 10; i++){
1012
	for(iterator &amp;it=begin(); it!=end(); ++it, ++i){
-
 
1013
		if(it->toFile(os, settings, materials, *pointMap, i)==false){
-
 
1014
			for(bob_part::ErrorIterator &e_it=it->errors.begin(); e_it!=it->errors.end(); ++e_it){
-
 
1015
				error(e_it->severity, e_it->code, "Part[%d]->%s", i, e_it->text);
-
 
1016
			}
900
		is >> m_values[i];
1017
			return false;
-
 
1018
		}
901
	}
1019
	}
-
 
1020
	return os.good();
-
 
1021
}
-
 
1022
//---------------------------------------------------------------------------------
-
 
1023
bool bob_part_collision_box::load(ibinaryfilestream& is)
-
 
1024
{
-
 
1025
	is >> sphereOffset >> sphereDiameter;
-
 
1026
	is >> boxOffset >> boxSize;
-
 
1027
	
902
	return !is.fail();
1028
	return !is.fail();
903
}
1029
}
904
//---------------------------------------------------------------------------------
1030
//---------------------------------------------------------------------------------
905
bool bob_dom_part_x3vals::toFile(bob_dom_obinaryfilestream& os)
1031
bool bob_part_collision_box::toFile(obinaryfilestream& os)
906
{
1032
{
907
	for(int i=0; i <; 10; i++){
1033
	os << sphereOffset <;< sphereDiameter;
908
		os << m_values[i];
1034
	os << boxOffset << boxSize;
909
	}
-
 
910
	return os.good();
1035
	return os.good();
911
}
1036
}
912
//---------------------------------------------------------------------------------
1037
//---------------------------------------------------------------------------------
913
bool bob_dom_part_x3vals::toFile(bob_dom_otextfilestream& os, bool bCommentItself)
1038
bool bob_part_collision_box::toFile(otextfilestream& os)
914
{
1039
{
915
	int old=os.flags();
1040
	int old=os.flags();
916
	
1041
 
917
	os << noSemicolons;
1042
	os << noSemicolons;
918
	if(bCommentItself)
-
 
919
		os << "// ";
-
 
920
	os << "PART_VALUES_RAW: " << autoSemicolons;
1043
	os << "/! COLLISION_BOX: " << autoSemicolons;
921
	for(int i=0; i < 10; i++){
-
 
922
		os << m_values[i];
-
 
923
	}
-
 
924
	
-
 
925
	os << endl;
-
 
926
	
1044
	
927
	/*os << noSemicolons << "// raw:" << endl;
-
 
928
	os << "// " << autoSemicolons;
-
 
929
	for(int i=0; i < 10; i++){
-
 
930
		os << m_values[i];
-
 
931
	}
-
 
932
	os << endl << */
-
 
933
	os << noSemicolons << "// point:" << endl;
1045
	os << boxOffset.x << boxOffset.y << boxOffset.z;
934
	os << "// " << autoSemicolons;
-
 
935
	for(int i=0; i < 10; i++){
-
 
936
		os << (int)(m_values[i] / bob_dom_point::multiplier);
1046
	os << sphereDiameter << boxSize.x << boxSize.y << boxSize.z;
937
	}
-
 
938
	
1047
	
939
	os << endl << noSemicolons << &quot;// float:" << endl;
1048
	os << noSemicolons <&lt; "!/" << autoSemicolons << endl;
940
	static const double multiplier=1.52587890625E-05; // 1/65535
-
 
941
	os << "// " << autoSemicolons;
-
 
942
	for(int i=0; i < 10; i++){
-
 
943
		os << (float)(m_values[i] * multiplier);
-
 
944
	}
1049
 
945
	os << endl;
-
 
946
	os.flags(old);
1050
	os.flags(old);
947
	return os.good();
1051
	return os.good();
948
}
1052
}
949
//---------------------------------------------------------------------------------
1053
//---------------------------------------------------------------------------------
950
// PARTS - object
1054
// PARTS - object
951
 
1055
 
952
const double bob_dom_part::multiplier=1.52587890625E-05; // == 1 / 65636
-
 
953
 
-
 
954
bool bob_dom_part::load(bob_dom_ibinaryfilestream& is)
1056
bool bob_part::load(ibinaryfilestream& is)
955
{
1057
{
956
	short count;
1058
	short count;
957
	
1059
 
958
 	is >> flags >> count;
1060
 	is >> flags >> count;
959
	
1061
 
960
	for(int i=0; i < count; i++){
1062
	for(int i=0; i < count; i++){
961
		bob_face_list *faces=new bob_face_list();
1063
		bob_face_list *faces=new bob_face_list();
962
		if(faces->load(is, (flags & x3flag) > 0)==false){
1064
		if(faces->load(is, (flags & FLAG_X3) > 0)==false){
963
			for(ErrorIterator &it=faces->errors.begin(); it!=faces->errors.end(); ++it){
1065
			for(ErrorIterator &it=faces->errors.begin(); it!=faces->errors.end(); ++it){
964
				error(it->severity, it->code, "face list[%d]->%s", i, it->text);
1066
				error(it->severity, it->code, "face list[%d]->%s", i, it->text);
965
			}
1067
			}
966
			delete faces;
1068
			delete faces;
967
			return false;
1069
			return false;
968
		}
1070
		}
969
		push_back(faces);
1071
		push_back(faces);
970
	}
1072
	}
971
	
1073
 
972
	if(flags & x3flag)
1074
	if(flags & FLAG_X3)
973
		values.load(is);
1075
		collisionBox.load(is);
974
 
1076
 
975
	return !is.fail();
1077
	return !is.fail();
976
}
1078
}
977
//---------------------------------------------------------------------------------
1079
//---------------------------------------------------------------------------------
978
bool bob_dom_part::toFile(bob_dom_obinaryfilestream& os)
1080
bool bob_part::toFile(obinaryfilestream& os, const bob_vertices& vertices)
979
{
1081
{
980
	os << flags << (short)size();
1082
	os << flags << (short)size();
981
	
1083
 
982
	for(iterator &it=begin(); it!=end(); ++it){
1084
	for(iterator &it=begin(); it!=end(); ++it){
983
		it->toFile(os, (flags & x3flag) > 0);
1085
		it->toFile(os, vertices, (flags & FLAG_X3) > 0);
984
	}
1086
	}
985
	
1087
 
986
	if(flags & x3flag)
1088
	if(flags & FLAG_X3)
987
		values.toFile(os);
1089
		collisionBox.toFile(os);
988
 
1090
 
989
	return os.good();
1091
	return os.good();
990
}
1092
}
991
//---------------------------------------------------------------------------------
1093
//---------------------------------------------------------------------------------
992
bool bob_dom_part::toFile(bob_dom_otextfilestream& os, const Settings *settings, const bob_dom_materials *materials, const bob_point_map *pointMap, int idx)
1094
bool bob_part::toFile(otextfilestream& os, const Settings& settings, const bob_materials *materials, const bob_point_map& pointMap, int idx)
-
 
1095
{
-
 
1096
	if(settings.rawMode())
-
 
1097
		return outputRaw(os, pointMap, idx);
-
 
1098
	else
-
 
1099
		return outputBOD(os, settings, materials, pointMap, idx);
-
 
1100
}
-
 
1101
//---------------------------------------------------------------------------------
-
 
1102
bool bob_part::outputBOD(otextfilestream& os, const Settings& settings, const bob_materials *materials, const bob_point_map& pointMap, int idx)
993
{
1103
{
994
	bob_dom_face *part;
1104
	bob_face *face;
995
	const bob_dom_point *pnt;
1105
	const bob_vertex *pnt;
996
	int line=0;
1106
	int line=0;
997
	int materialIndex;
1107
	int materialIndex;
998
	
1108
 
999
	int oldf=os.flags();
1109
	int oldf=os.flags();
1000
	
1110
 
1001
	size_t count=0;
-
 
1002
	for(iterator &it=begin(); it!=end(); ++it){
-
 
1003
		count+=it->size();
-
 
1004
	}
-
 
1005
	
-
 
1006
	os << noSemicolons << "// ----- part " << idx << " (" << (int)count << " faces) -----" << endl << autoSemicolons;
1111
	os << noSemicolons << "// ----- part " << idx << " (" << (int)numFaces() << " faces) -----" << endl << autoSemicolons;
1007
	for(iterator &it=begin(); it!=end(); ++it){
1112
	for(iterator &facelist_it=begin(); facelist_it!=end(); ++facelist_it){
1008
		materialIndex=it->materialIndex;
1113
		materialIndex=facelist_it->materialIndex;
1009
		
1114
 
1010
		for(bob_face_list::iterator &it2=it->begin(); it2!=it->end(); ++it2, ++line){
1115
		for(bob_face_list::iterator &face_it=facelist_it->begin(); face_it!=facelist_it->end(); ++face_it, ++line){
1011
			part=*it2;
1116
			face=*face_it;
1012
			
1117
 
1013
			os << autoSemicolons << materialIndex;
1118
			os << autoSemicolons << materialIndex;
1014
			for(int i=0; i < 3; i++){
1119
			for(int i=0; i < 3; i++){
1015
				os << pointMap->uniqueIndex(part->values[i]);
1120
				os << pointMap.uniqueIndex(face->values[i]);
1016
			}
1121
			}
1017
			
1122
 
1018
			pnt=(*pointMap)[part->values[0]];
1123
			pnt=pointMap[face->values[0]];
1019
			if(pnt==NULL){
1124
			if(pnt==NULL){
1020
				error(e_pointNotFound);
1125
				error(e_pointNotFound);
1021
				return false;
1126
				return false;
1022
			}
1127
			}
1023
			int SGBits=pnt->values.back();
1128
			int SGBits=pnt->sgbits;
1024
			int magic;
1129
			int magic = 1; // bit 1 is always set
1025
			
1130
 
1026
			/*
1131
			/*
1027
				meaning of "magic" number:
1132
				meaning of "magic" number:
1028
				-25: smoothing bits and UV coords
1133
				-25: smoothing bits and UV coords
1029
				-17: smoothing bits and no UV coords
1134
				-17: smoothing bits and no UV coords
1030
				-9: no smoothing and UV coords
1135
				-9: no smoothing and UV coords
1031
				-1: no smoothing and no UV coords
1136
				-1: no smoothing and no UV coords
1032
				
1137
 
1033
				--obsolete----------------------
1138
				--obsolete----------------------
1034
				old text from Checker's sources:
1139
				old text from Checker's sources:
1035
				if there are no materials used, magic is -17
1140
				if there are no materials used, magic is -17
1036
				if there are materials and last value of the first point is non zero,
1141
				if there are materials and last value of the first point is non zero,
1037
				magic is -25, otherwise it's -9
1142
				magic is -25, otherwise it's -9
1038
			*/
1143
			*/
1039
			
1144
 
1040
			const bob_dom_point *points_ar[3];
1145
			const bob_vertex *points_ar[3];
1041
			for(int i=0; i < 3; i++){
1146
			for(int i=0; i < 3; i++){
1042
				pnt=(*pointMap)[part->values[i]];
1147
				pnt=pointMap[face->values[i]];
1043
				if(pnt==NULL){
1148
				if(pnt==NULL){
1044
					error(e_pointNotFound);
1149
					error(e_pointNotFound);
1045
					return false;
1150
					return false;
1046
				}
1151
				}
1047
				points_ar[i]=pnt;
1152
				points_ar[i]=pnt;
1048
			}
1153
			}
1049
			
1154
 
1050
			bool bHasUV=false;
1155
			bool bHasUV=false;
1051
			for(int i=0; i < 3; i++){
1156
			for(int i=0; i < 3; i++){
1052
				if(bHasUV=(points_ar[i]->textureCoords.left!=0 || points_ar[i]->textureCoords.right!=0))
1157
				if(bHasUV=points_ar[i]->hasTextureCoords())
1053
					break;
1158
					break;
1054
			}
1159
			}
1055
			
1160
 
1056
			if(SGBits) {
-
 
1057
				if(bHasUV)
1161
			if(bHasUV)
1058
					magic=-25;
1162
				magic|=BOD_FLAG_UV;
1059
				else
1163
			if(SGBits)
1060
					magic=-17;
1164
				magic|=BOD_FLAG_SGBITS;
1061
			}
1165
 
1062
			else{
-
 
1063
				if(bHasUV)
-
 
1064
					magic=-9;
1166
			os << (magic * -1);
1065
				else
-
 
1066
					magic=-1;
1167
			if(SGBits!=0)
1067
			}
-
 
1068
			
-
 
1069
			os << magic;
1168
				os << SGBits;
1070
			if(SGBits!=0) os << SGBits;
-
 
1071
			
1169
 
1072
			// we have uv coords so lets output them
1170
			// we have uv coords, lets output them
1073
			if(bHasUV){
1171
			if(bHasUV){
1074
				double u, v;
-
 
1075
				for(int i=0; i < 3; i++){
1172
				for(int i=0; i < 3; i++){
-
 
1173
					
1076
					u=points_ar[i]->;textureCoords.left * multiplier;
1174
					os << points_ar[i]->;textureCoords; // correct output
-
 
1175
				}
-
 
1176
				
1077
					v=points_ar[i]-&gt;textureCoords.right * multiplier;
1177
				os << noSemicolons << "/! &quot;;
1078
				
1178
				
1079
					os << (float) u << (float) v;
1179
				outputNormals(os, points_ar);
1080
				}
1180
 
1081
				// those are the unknown values stored in point after texture coordinates
1181
				if(settings.extraPntInfo())
1082
				// I place them after bod part definition and behind comment, so they are invisible to 
-
 
1083
				// bod viewer and x2
1182
					outputExtraPtInfo(os, points_ar);
1084
				
1183
				
1085
				if(settings->extraPntInfo()){
-
 
1086
					bool bEmpty=true;
-
 
1087
					for(int i=0; i < 3; i++){
-
 
1088
						bEmpty&=(points_ar[i]->values.size() <= 1);
-
 
1089
					}
-
 
1090
					if(!bEmpty){
-
 
1091
						os << noSemicolons << "/! ";
1184
				os << noSemicolons << "!/ ";
1092
						for(int i=0; i < 3; i++){
-
 
1093
							os << "{ " << autoSemicolons;
-
 
1094
							bob_dom_point::const_iterator &last=--points_ar[i]->values.end();
-
 
1095
							double d;
-
 
1096
							for(bob_dom_point::const_iterator &it=points_ar[i]->values.begin(); it!=last; ++it){
-
 
1097
								d=*it * multiplier;
-
 
1098
								if(d==0)
-
 
1099
									os << 0;
-
 
1100
								else
-
 
1101
									os << (float)d;
-
 
1102
							}
-
 
1103
							os << noSemicolons << "} ";
-
 
1104
						}
-
 
1105
						os << "!/ " << autoSemicolons;
-
 
1106
					}
-
 
1107
				}
-
 
1108
			}
1185
			}
1109
			os << noSemicolons << "// " << line << endl;
1186
			os << noSemicolons << "// " << line << endl;
1110
		}
1187
		}
1111
	}
1188
	}
1112
	
1189
 
1113
	// x3 data
1190
	// x3 data
1114
	if(flags & x3flag){
1191
	if(flags & FLAG_X3){
1115
		os << "// x3 part values" << endl;
-
 
1116
		if(settings->extraX3BobInfo())
-
 
1117
			os << "/!" << endl;
-
 
1118
		values.toFile(os, settings->extraX3BobInfo()==false);
-
 
1119
		if(settings->extraX3BobInfo()) {
-
 
1120
			os << endl << "// secondary UVs (or whatever this is)" << endl;
-
 
1121
			for(iterator &it=begin(); it!=end(); ++it){
-
 
1122
				it->x3uvlist.toFile(os, it->materialIndex);
-
 
1123
			}
-
 
1124
			os << "!/" << endl;
1192
		collisionBox.toFile(os);
1125
		}
-
 
1126
	}
1193
	}
1127
 
1194
 
1128
	int bit=1;
1195
	int bit=1;
1129
	char str[21];
1196
	char str[21];
1130
	for(int i=19; i >= 0; i--){
1197
	for(int i=19; i >= 0; i--){
1131
		str[i]=flags & bit ? '1' : '0';
1198
		str[i]=flags & bit ? '1' : '0';
1132
		bit<<=1;
1199
		bit<<=1;
1133
	}
1200
	}
1134
	str[sizeof(str)-1]=0;
1201
	str[sizeof(str)-1]=0;
1135
	
1202
 
1136
	os << autoSemicolons  << "-99" << str << noSemicolons << "// part " << idx << " end" << endl;
1203
	os << autoSemicolons  << "-99" << str << noSemicolons << "// part " << idx << " end" << endl;
-
 
1204
 
-
 
1205
	os.flags(oldf);
-
 
1206
 
-
 
1207
	return os.good();
-
 
1208
}
-
 
1209
//---------------------------------------------------------------------------------
-
 
1210
bool bob_part::outputX3VertexData(otextfilestream& os, const bob_point_map& pointMap)
-
 
1211
{
-
 
1212
	int old=os.flags();
-
 
1213
	
-
 
1214
	os << endl << noSemicolons 
-
 
1215
	<< "// X3 vertex data (tangent and <unknown>)" << endl
-
 
1216
	<< autoSemicolons;
-
 
1217
 
-
 
1218
	int i=1;
-
 
1219
	for(iterator &facelist_it=begin(); facelist_it!=end(); ++facelist_it, i++){
-
 
1220
		facelist_it->outputX3VertexDataRaw(os);
-
 
1221
		
-
 
1222
		//facelist_it->computeAndOutputTangents(os, pointMap);
-
 
1223
	}
-
 
1224
	os.flags(old);
-
 
1225
	
-
 
1226
	return true;
-
 
1227
}
-
 
1228
//---------------------------------------------------------------------------------
-
 
1229
void bob_part::outputNormals(otextfilestream& os, const bob_vertex *points[])
-
 
1230
{
-
 
1231
	int oldf=os.flags();
-
 
1232
	bool bSame=true;
-
 
1233
	for(int i=1; i < 3; i++){
-
 
1234
		bSame&=points[i]->normalVector == points[i - 1]->normalVector;
-
 
1235
	}
-
 
1236
 
-
 
1237
	os << noSemicolons << "N: { " << autoSemicolons;
-
 
1238
	
-
 
1239
	for(int i=0; i < (bSame ? 1 : 3); i++){
-
 
1240
		os << points[i]->normalVector;
-
 
1241
	}
-
 
1242
	os << noSemicolons << "} ";
-
 
1243
	os.flags(oldf);
-
 
1244
}
-
 
1245
//---------------------------------------------------------------------------------
-
 
1246
// those are the unknown values stored in point after texture coordinates
-
 
1247
// I place them after bod part definition and behind comment, so they are invisible to
-
 
1248
// bod viewer and x2
-
 
1249
void bob_part::outputExtraPtInfo(otextfilestream& os, const bob_vertex *points[])
-
 
1250
{
-
 
1251
	int oldf=os.flags();
-
 
1252
 
-
 
1253
	bool bInfo=false;
-
 
1254
	for(int i=0; i < 3; i++){
-
 
1255
		bInfo|=(points[i]->flags & bob_vertex::FLAG_WEIRD_STUFF) > 0;
-
 
1256
	}
-
 
1257
	if(bInfo==false) return;
1137
	
1258
	
-
 
1259
	os << noSemicolons << "XPINFO: ";
-
 
1260
	for(int i=0; i < 3; i++){
-
 
1261
		os << noSemicolons << "{ " << autoSemicolons
-
 
1262
		<< points[i]->weirdCoords
-
 
1263
		<< noSemicolons << "} ";
-
 
1264
	}
1138
	os.flags(oldf);
1265
	os.flags(oldf);
1139
	
-
 
1140
	return os.good();
-
 
1141
}
1266
}
1142
//---------------------------------------------------------------------------------
1267
//---------------------------------------------------------------------------------
1143
// PART - object
1268
// PART - object
1144
bool bob_dom_face::load(bob_dom_ibinaryfilestream& is)
1269
bool bob_face::load(ibinaryfilestream& is)
1145
{
1270
{
1146
	for(int i=0; i < 4; i++){
1271
	for(int i=0; i < 3; i++){
1147
		is >> values[i];
1272
		is >> values[i];
1148
	}
1273
	}
-
 
1274
	is >> flags;
-
 
1275
 
1149
	if(is.fail()) 
1276
	if(is.fail())
1150
		errorCode=e_notEnoughData;
1277
		errorCode=e_notEnoughData;
1151
		
1278
 
1152
	return !is.fail();
1279
	return !is.fail();
1153
}
1280
}
1154
//---------------------------------------------------------------------------------
1281
//---------------------------------------------------------------------------------
1155
bool bob_dom_face::toFile(bob_dom_obinaryfilestream& os)
1282
bool bob_face::toFile(obinaryfilestream& os)
1156
{
1283
{
1157
	for(int i=0; i < 4; i++){
1284
	for(int i=0; i < 3; i++){
1158
		os << values[i];
1285
		os << values[i];
1159
	}
1286
	}
-
 
1287
	os << flags;
1160
	return os.good();
1288
	return os.good();
1161
}
1289
}
1162
//---------------------------------------------------------------------------------
1290
//---------------------------------------------------------------------------------
1163
bool bob_dom_body::load(bob_dom_ibinaryfilestream& is)
1291
bool bob_body::load(ibinaryfilestream& is)
1164
{
1292
{
1165
	is >> bodySize >> bodyFlags;
1293
	is >> bodySize >> bodyFlags;
1166
	if(peek(is)==bob_dom_bones::hdr_begin){
1294
	if(peek(is)==bob_bones::HDR_BEGIN){
1167
		if(!bones.load(is)){
1295
		if(!bones.load(is)){
1168
			for(ErrorIterator &it=bones.errors.begin(); it!=bones.errors.end(); ++it){
1296
			for(ErrorIterator &it=bones.errors.begin(); it!=bones.errors.end(); ++it){
1169
				error(it->code, "bones: %s", it->text);
1297
				error(it->code, "bones: %s", it->text);
1170
			}
1298
			}
1171
			return false;
1299
			return false;
1172
		}
1300
		}
1173
	}
1301
	}
1174
	if(peek(is)==bob_dom_points::hdr_begin){
1302
	if(peek(is)==bob_vertices::HDR_BEGIN){
1175
		if(points.load(is)==false){
1303
		if(vertices.load(is)==false){
1176
			for(ErrorIterator &it=points.errors.begin(); it!=points.errors.end(); ++it){
1304
			for(ErrorIterator &it=vertices.errors.begin(); it!=vertices.errors.end(); ++it){
1177
				error(it->code, "points->%s", it->text);
1305
				error(it->code, "vertices->%s", it->text);
1178
			}
1306
			}
1179
			return false;
1307
			return false;
1180
		}
1308
		}
1181
	}
1309
	}
1182
	if(peek(is)==bob_dom_weights::hdr_begin){
1310
	if(peek(is)==bob_weights::HDR_BEGIN){
1183
		if(!weights.load(is)){
1311
		if(!weights.load(is)){
1184
			for(ErrorIterator &it=weights.errors.begin(); it!=weights.errors.end(); ++it){
1312
			for(ErrorIterator &it=weights.errors.begin(); it!=weights.errors.end(); ++it){
1185
				error(it->code, "weights->%s", it->text);
1313
				error(it->code, "weights->%s", it->text);
1186
			}
1314
			}
1187
			return false;
1315
			return false;
1188
		}
1316
		}
1189
	}
1317
	}
1190
	if(peek(is)==bob_dom_parts::hdr_begin){
1318
	if(peek(is)==bob_parts::HDR_BEGIN){
1191
		if(parts.load(is)==false){
1319
		if(parts.load(is)==false){
1192
			for(ErrorIterator &it=parts.errors.begin(); it!=parts.errors.end(); ++it){
1320
			for(ErrorIterator &it=parts.errors.begin(); it!=parts.errors.end(); ++it){
1193
				error(it->code, "parts->%s", it->text);
1321
				error(it->code, "parts->%s", it->text);
1194
			}
1322
			}
1195
			return false;
1323
			return false;
1196
		}
1324
		}
1197
	}
1325
	}
1198
	return !is.fail();
1326
	return !is.fail();
1199
}
1327
}
1200
//---------------------------------------------------------------------------------
1328
//---------------------------------------------------------------------------------
1201
bool bob_dom_body::toFile(bob_dom_obinaryfilestream& os)
1329
bool bob_body::toFile(obinaryfilestream& os)
1202
{
1330
{
1203
	os << bodySize << bodyFlags;
1331
	os << bodySize << bodyFlags;
1204
	
1332
 
1205
	bones.toFile(os);
1333
	bones.toFile(os);
1206
	points.toFile(os);
1334
	vertices.toFile(os);
1207
	weights.toFile(os);
1335
	weights.toFile(os);
1208
	parts.toFile(os);
1336
	parts.toFile(os, vertices);
1209
	
1337
 
1210
	return os.good();
1338
	return os.good();
1211
}
1339
}
1212
//---------------------------------------------------------------------------------
1340
//---------------------------------------------------------------------------------
1213
bool bob_dom_body::toFile(bob_dom_otextfilestream& os, const Settings *settings, const bob_dom_materials *materials, int idx)
1341
bool bob_body::toFile(otextfilestream& os, const Settings& settings, const bob_materials *materials, int idx)
1214
{
1342
{
1215
	os << "// beginning of body " << idx << endl;
1343
	os << "// beginning of body " << idx << endl;
1216
	os << autoSemicolons << bodySize << endl << endl;
1344
	os << autoSemicolons << bodySize << endl << endl;
1217
	
1345
 
1218
	bones.toFile(os);
1346
	bones.toFile(os);
1219
	
1347
 
1220
	points.toFile(os);
1348
	vertices.toFile(os, settings);
1221
	
1349
 
1222
	weights.toFile(os, &points.map);
1350
	weights.toFile(os, &vertices.map);
1223
	
1351
 
1224
	parts.toFile(os, settings, materials, &points.map);
1352
	if(parts.toFile(os, settings, materials, &vertices.map)==false){
-
 
1353
		for(bob_parts::ErrorIterator &e_it=parts.errors.begin(); e_it!=parts.errors.end(); ++e_it){
-
 
1354
			error(e_it->severity, e_it->code, "Parts->%s", e_it->text);
-
 
1355
		}
-
 
1356
		return false;
1225
	
1357
	}
1226
	char str[17]; int bit=1;
1358
	char str[17]; int bit=1;
1227
	for(int i=15; i >= 0; i--){
1359
	for(int i=15; i >= 0; i--){
1228
		str[i]=bodyFlags & bit ? '1' : '0';
1360
		str[i]=bodyFlags & bit ? '1' : '0';
1229
		bit<<=1;
1361
		bit<<=1;
1230
	}
1362
	}
1231
	str[sizeof(str)-1]=0;
1363
	str[sizeof(str)-1]=0;
1232
	
1364
 
1233
	os << "-99" << str << noSemicolons << "// body " << idx << " end" << endl;
1365
	os << "-99" << str << noSemicolons << "// body " << idx << " end" << endl;
1234
	
1366
 
1235
	return os.good();
1367
	return os.good();
1236
}
1368
}
1237
//---------------------------------------------------------------------------------
1369
//---------------------------------------------------------------------------------
1238
// BONES
1370
// BONES
1239
bool bob_dom_bones::load(bob_dom_ibinaryfilestream& is)
1371
bool bob_bones::load(ibinaryfilestream& is)
1240
{
1372
{
1241
	int hdr, count;
1373
	int hdr, count;
1242
	is >> hdr;
1374
	is >> hdr;
1243
	if(hdr!=hdr_begin){
1375
	if(hdr!=HDR_BEGIN){
1244
		error(e_badHeader);
1376
		error(e_badHeader);
1245
		return false;
1377
		return false;
1246
	}
1378
	}
1247
	
1379
 
1248
	is >> count;
1380
	is >> count;
1249
	char *name;
1381
	char *name;
1250
	for(int i=0; i < count; i++){
1382
	for(int i=0; i < count; i++){
1251
		is >> name;
1383
		is >> name;
1252
		if(name==0){
1384
		if(name==0){
1253
			error(e_notEnoughData);
1385
			error(e_notEnoughData);
1254
			delete[] name;
1386
			delete[] name;
1255
			return false;
1387
			return false;
1256
		}
1388
		}
1257
		push_back(name);
1389
		push_back(name);
1258
	}
1390
	}
1259
	is >> hdr;
1391
	is >> hdr;
1260
	if(hdr!=hdr_end){
1392
	if(hdr!=HDR_END){
1261
		error(e_badEndHeader);
1393
		error(e_badEndHeader);
1262
		return false;
1394
		return false;
1263
	}
1395
	}
1264
	return true;
1396
	return true;
1265
}
1397
}
1266
//---------------------------------------------------------------------------------
1398
//---------------------------------------------------------------------------------
1267
bool bob_dom_bones::toFile(bob_dom_obinaryfilestream& os)
1399
bool bob_bones::toFile(obinaryfilestream& os)
1268
{
1400
{
1269
	if(size()==0) return true;
1401
	if(size()==0) return true;
1270
	
1402
 
1271
	os << hdr_begin << (int) size();
1403
	os << HDR_BEGIN << (int) size();
1272
	for(iterator &it=begin(); it!=end(); ++it){
1404
	for(iterator &it=begin(); it!=end(); ++it){
1273
		os << *it;
1405
		os << *it;
1274
	}
1406
	}
1275
	os << hdr_end;
1407
	os << HDR_END;
1276
	return os.good();
1408
	return os.good();
1277
}
1409
}
1278
//---------------------------------------------------------------------------------
1410
//---------------------------------------------------------------------------------
1279
bool bob_dom_bones::toFile(bob_dom_otextfilestream& os)
1411
bool bob_bones::toFile(otextfilestream& os)
1280
{
1412
{
1281
	if(size()==0) return true;
1413
	if(size()==0) return true;
1282
	os << noSemicolons << "BONES: " << autoSemicolons << (int)size() << endl;
1414
	os << noSemicolons << "BONES: " << autoSemicolons << (int)size() << endl;
1283
	for(iterator &it=begin(); it!=end(); ++it){
1415
	for(iterator &it=begin(); it!=end(); ++it){
1284
		os << *it << endl;
1416
		os << *it << endl;
Line 1286... Line 1418...
1286
	os << endl;
1418
	os << endl;
1287
	return os.good();
1419
	return os.good();
1288
}
1420
}
1289
//---------------------------------------------------------------------------------
1421
//---------------------------------------------------------------------------------
1290
// WEIGHTS - section
1422
// WEIGHTS - section
1291
bool bob_dom_weights::load(bob_dom_ibinaryfilestream& is)
1423
bool bob_weights::load(ibinaryfilestream& is)
1292
{
1424
{
1293
	int hdr;
1425
	int hdr;
1294
	is >> hdr;
1426
	is >> hdr;
1295
	if(hdr!=hdr_begin){
1427
	if(hdr!=HDR_BEGIN){
1296
		error(e_badHeader);
1428
		error(e_badHeader);
1297
		return false;
1429
		return false;
1298
	}
1430
	}
1299
	
1431
 
1300
	int count;
1432
	int count;
1301
	is >> count;
1433
	is >> count;
1302
	resize(count);
1434
	resize(count);
1303
	
1435
 
1304
	bob_dom_weight *ch;
1436
	bob_weight *ch;
1305
	for(int i=0; i < count; i++){
1437
	for(int i=0; i < count; i++){
1306
		ch=new bob_dom_weight();
1438
		ch=new bob_weight();
1307
		if(!ch->load(is)){
1439
		if(!ch->load(is)){
1308
			error(ch->errorCode, "weight[%d]: %s", i, bob_traslate_error(ch->errorCode));
1440
			error(ch->errorCode, "weight[%d]: %s", i, bob_traslate_error(ch->errorCode));
1309
			delete ch;
1441
			delete ch;
1310
			return false;
1442
			return false;
1311
		}
1443
		}
1312
		(*this)[i]=ch;
1444
		(*this)[i]=ch;
1313
	}
1445
	}
1314
	is >> hdr;
1446
	is >> hdr;
1315
	if(hdr!=hdr_end){
1447
	if(hdr!=HDR_END){
1316
		error(e_badEndHeader);
1448
		error(e_badEndHeader);
1317
		return false;
1449
		return false;
1318
	}
1450
	}
1319
	return true;
1451
	return true;
1320
}
1452
}
1321
//---------------------------------------------------------------------------------
1453
//---------------------------------------------------------------------------------
1322
bool bob_dom_weights::toFile(bob_dom_obinaryfilestream& os)
1454
bool bob_weights::toFile(obinaryfilestream& os)
1323
{
1455
{
1324
	if(new_weights.size()==0 && size()==0) return true;
1456
	if(new_weights.size()==0 && size()==0) return true;
1325
	
1457
 
1326
	os << hdr_begin;
1458
	os << HDR_BEGIN;
1327
	if(new_weights.size()){
1459
	if(new_weights.size()){
1328
		os << (int)new_weights.size();
1460
		os << (int)new_weights.size();
1329
		for(WeightList::iterator &it=new_weights.begin(); it!=new_weights.end(); ++it){
1461
		for(WeightList::iterator &it=new_weights.begin(); it!=new_weights.end(); ++it){
1330
			it->toFile(os);
1462
			it->toFile(os);
1331
		}
1463
		}
Line 1334... Line 1466...
1334
		os << (int)size();
1466
		os << (int)size();
1335
		for(iterator &it=begin(); it!=end(); ++it){
1467
		for(iterator &it=begin(); it!=end(); ++it){
1336
			it->toFile(os);
1468
			it->toFile(os);
1337
		}
1469
		}
1338
	}
1470
	}
1339
	
1471
 
1340
	os << hdr_end;
1472
	os << HDR_END;
1341
	return os.good();
1473
	return os.good();
1342
}
1474
}
1343
//---------------------------------------------------------------------------------
1475
//---------------------------------------------------------------------------------
1344
bool bob_dom_weights::toFile(bob_dom_otextfilestream& os, const bob_point_map *pointMap)
1476
bool bob_weights::toFile(otextfilestream& os, const bob_point_map *pointMap)
1345
{
1477
{
1346
	if(size()==0) return true;
1478
	if(size()==0) return true;
1347
	os << noSemicolons << "WEIGHTS " << autoSemicolons << (int) pointMap->uniquePointsSize() << endl;
1479
	os << noSemicolons << "WEIGHTS " << autoSemicolons << (int) pointMap->uniquePointsSize() << endl;
1348
	int i=0;
1480
	int i=0;
1349
	for(bob_point_map::const_index_iterator &it=pointMap->indexBegin(); it!=pointMap->indexEnd(); ++it){
1481
	for(bob_point_map::const_index_iterator &it=pointMap->indexBegin(); it!=pointMap->indexEnd(); ++it){
1350
		(*this)[*it]->toFile(os, i++);
1482
		(*this)[*it]->toFile(os, i++);
1351
	}
1483
	}
1352
	os << autoSemicolons << "-1" << endl << endl;
1484
	os << autoSemicolons << "-1" << endl << endl;
1353
	return os.good();
1485
	return os.good();
1354
}
1486
}
1355
//---------------------------------------------------------------------------------
1487
//---------------------------------------------------------------------------------
1356
// WEIGHT - object
1488
// WEIGHT - object
1357
bool bob_dom_weight::load(bob_dom_ibinaryfilestream& is)
1489
bool bob_weight::load(ibinaryfilestream& is)
1358
{
1490
{
1359
	short count;
1491
	short count;
1360
	value v;
1492
	value v;
1361
	
1493
 
1362
	is >> count;
1494
	is >> count;
1363
	
1495
 
1364
	for(int i=0; i < count; i++){
1496
	for(int i=0; i < count; i++){
1365
		is >> v.boneIdx >> v.boneCoefficient;
1497
		is >> v.boneIdx >> v.boneCoefficient;
1366
		values.push_back(v);
1498
		values.push_back(v);
1367
	}
1499
	}
1368
	
1500
 
1369
	return !is.fail();
1501
	return !is.fail();
1370
}
1502
}
1371
//---------------------------------------------------------------------------------
1503
//---------------------------------------------------------------------------------
1372
bool bob_dom_weight::toFile(bob_dom_obinaryfilestream& os)
1504
bool bob_weight::toFile(obinaryfilestream& os)
1373
{	
1505
{
1374
	os << (short) values.size();
1506
	os << (short) values.size();
1375
	
1507
 
1376
	value v;
1508
	value v;
1377
	for(iterator &it=values.begin(); it!=values.end(); ++it){
1509
	for(iterator &it=values.begin(); it!=values.end(); ++it){
1378
		v=*it;
1510
		v=*it;
1379
		os << v.boneIdx << v.boneCoefficient;
1511
		os << v.boneIdx << v.boneCoefficient;
1380
	}
1512
	}
1381
	return os.good();
1513
	return os.good();
1382
}
1514
}
1383
//---------------------------------------------------------------------------------
1515
//---------------------------------------------------------------------------------
1384
bool bob_dom_weight::toFile(bob_dom_otextfilestream& os, int idx)
1516
bool bob_weight::toFile(otextfilestream& os, int idx)
1385
{
1517
{
1386
	os << autoSemicolons;
1518
	os << autoSemicolons;
1387
	for(iterator &it=values.begin(); it!=values.end(); ++it){
1519
	for(iterator &it=values.begin(); it!=values.end(); ++it){
1388
		(*it).toFile(os);
1520
		(*it).toFile(os);
1389
	}
1521
	}
1390
	os << noSemicolons << "-1; // " << idx << endl;
1522
	os << noSemicolons << "-1; // " << idx << endl;
1391
	return os.good();
1523
	return os.good();
-
 
1524
}
-
 
1525
//---------------------------------------------------------------------------------
-
 
1526
bool bob_part::outputRaw(otextfilestream& os, const bob_point_map& pointMap, int idx)
-
 
1527
{
-
 
1528
	int oldf=os.flags();
-
 
1529
	os << noSemicolons << "// Part " << idx << endl << "// " << (int)numFaces() << " faces" << endl;
-
 
1530
	for(iterator& facelist_it=begin(); facelist_it!=end(); ++facelist_it){
-
 
1531
		os << noSemicolons << "// Material " << facelist_it->materialIndex << endl << autoSemicolons;
-
 
1532
		for(bob_face_list::iterator& face_it=facelist_it->begin(); face_it!=facelist_it->end(); ++face_it){
-
 
1533
			for(int i=0; i < 3; i++)
-
 
1534
				os << face_it->values[i];
-
 
1535
			os << face_it->flags;
-
 
1536
			
-
 
1537
			os << endl;
-
 
1538
		}
-
 
1539
	}
-
 
1540
	
-
 
1541
	bool bRes = true;
-
 
1542
	
-
 
1543
	if(flags & FLAG_X3) {
-
 
1544
		bRes = outputX3VertexData(os, pointMap);
-
 
1545
		
-
 
1546
		os << noSemicolons << "Collision sphere: offset: " << autoSemicolons << collisionBox.sphereOffset.x << collisionBox.sphereOffset.y << collisionBox.sphereOffset.z << noSemicolons << "diameter: " << autoSemicolons << collisionBox.sphereDiameter << endl;
-
 
1547
		os << noSemicolons << "Collision box: offset: " << autoSemicolons << collisionBox.boxOffset.x << collisionBox.boxOffset.y << collisionBox.boxOffset.z << noSemicolons << "size: " << autoSemicolons << collisionBox.boxSize.x << collisionBox.boxSize.y << collisionBox.boxSize.z << endl;
-
 
1548
	}
-
 
1549
	
-
 
1550
	os.flags(oldf);
-
 
1551
	return os.good() && bRes;
1392
}
1552
}
1393
//---------------------------------------------------------------------------------
1553
//---------------------------------------------------------------------------------