aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_max/imp_max_callbacks.c
blob: 219ad4fc36dbe84d534e9b99fd335d1d167132a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
/* $Id$ */

/*
    libg3d - 3D object loading library

    Copyright (C) 2005-2009  Markus Dahms <mad@automagically.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <string.h>
#include <g3d/material.h>
#include <g3d/stream.h>
#include <g3d/debug.h>

#include "imp_max_callbacks.h"

static gchar *max_read_wchar(G3DStream *stream, guint32 n)
{
	gint32 i;
	gunichar2 *u16text;
	gchar *text;
	GError *error = NULL;

	u16text = g_new0(gunichar2, n + 1);
	for(i = 0; i < n; i ++) {
		u16text[i] = g3d_stream_read_int16_le(stream);
	}

	text = g_utf16_to_utf8(u16text, n, NULL, NULL, &error);
	if(error != NULL) {
		g_warning("UTF-16 to UTF-8 conversion failed: %s",
			error->message);
		g_error_free(error);
	}
	g_free(u16text);

	return text;
}

gboolean max_cb_debug_int32(MaxGlobalData *global, MaxLocalData *local)
{
	union {
		gint32 i;
		G3DFloat f;
	} u;

	while(local->nb >= 4) {
		u.i = g3d_stream_read_int32_le(global->stream);
		local->nb -= 4;
#if DEBUG > 0
		g_debug("|%s[D32] 0x%08x, %d, %.2f", debug_pad(local->level),
			u.i, u.i, u.f);
#endif
	}
	return TRUE;
}

gboolean max_cb_debug_wchars(MaxGlobalData *global, MaxLocalData *local)
{
	gchar *str;
	guint32 len;

	len = local->nb / 2;
	str = max_read_wchar(global->stream, len);
	local->nb -= len * 2;
#if DEBUG > 0
	g_debug("|%s[TEXT] %s (%d)", debug_pad(local->level),
		str, len);
#endif
	g_free(str);

	return TRUE;
}

gboolean max_cb_debug_string(MaxGlobalData *global, MaxLocalData *local)
{
	gchar *str;
	guint32 len;

	g_return_val_if_fail(local->nb >= 4, FALSE);
	len = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;
	if(len > local->nb)
		len = local->nb;

	str = g_new0(gchar, len + 1);
	g3d_stream_read(global->stream, str, len);
	local->nb -= len;
#if DEBUG > 0
	g_debug("|%s[TEXT] %s (%d)", debug_pad(local->level),
		str, len);
#endif
	g_free(str);

	return TRUE;
}

gboolean max_cb_0x0001_0x0005(MaxGlobalData *global, MaxLocalData *local)
{
	gchar *str;
	gint32 len, i, w3[3], cnt = 0;

	if(local->nb < 4)
		return FALSE;

	/* flags? */
	i = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;

#if DEBUG > 0
	g_debug("|%s[PROP] 0x%08x", debug_pad(local->level), i);
#endif

	while(local->nb > 0) {
		len = g3d_stream_read_int32_le(global->stream);
		local->nb -= 4;
		str = g_malloc0(len + 1);
		g3d_stream_read(global->stream, str, len);
		local->nb -= len;
		for(i = 0; i < 3; i ++)
			w3[i] = g3d_stream_read_int16_le(global->stream);
		local->nb -= 6;
		cnt ++;
#if DEBUG > 0
		g_debug("|%s[PROP]  %04d: '%s' (%d bytes) [%d, %d, %d]",
			debug_pad(local->level),
			cnt, str, len,
			w3[0], w3[1], w3[2]);
#endif
		g_free(str);
	}
	return TRUE;
}

gboolean max_cb_IDFILE_0x1201(MaxGlobalData *global, MaxLocalData *local)
{
	guint16 width, height;

	width = g3d_stream_read_int16_le(global->stream);
	height = g3d_stream_read_int16_le(global->stream);
	local->nb -= 4;
#if DEBUG > 0
	g_debug("|%s[IMG] %u x %u", debug_pad(local->level), width, height);
#endif
	return TRUE;
}

/* vertex data */
gboolean max_cb_0x08FE_0x0100(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 num;
	gint i, j;
	G3DObject *object;

	if(local->nb < 4)
		return FALSE;

	/* vertices */
	num = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;
	object = (G3DObject *)local->object;
	if(object == NULL) {
		g_warning("MAX: 0x08FE::0x0100: no object");
		return FALSE;
	}

#if DEBUG > 0
	g_debug("|%s[VERT] %d vertices", debug_pad(local->level), num);
#endif
	global->vertex_offset = object->vertex_count;
	object->vertex_count += num;
	object->vertex_data = g_realloc(object->vertex_data,
		object->vertex_count * 3 * sizeof(G3DFloat));

	for(i = 0; i < num; i ++) {
		if(local->nb < 16)
			return FALSE;
		g3d_stream_read_int32_le(global->stream); /* always 0 */
		for(j = 0; j < 3; j ++)
			object->vertex_data[(global->vertex_offset + i) * 3 + j] =
				g3d_stream_read_float_le(global->stream);
		local->nb -= 16;
	}
	return TRUE;
}

/* lines (vertex indices) */
gboolean max_cb_0x08FE_0x010A(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 num;
	gint i, j;
	guint32 v[3];

	if(local->nb < 4)
		return FALSE;

	num = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;

#if DEBUG > 0
	g_debug("|%s[LINE] %d lines", debug_pad(local->level), num);
#endif
	for(i = 0; i < num; i ++) {
		if(local->nb < 12)
			return FALSE;
		for(j = 0; j < 3; j ++) {
			v[j] = g3d_stream_read_int32_le(global->stream);
		}
		local->nb -= 12;

#if DEBUG > 1
		g_debug("|%s[LINE] 0x%08x: (%d => %d)", debug_pad(local->level),
			v[0], v[1], v[2]);
#endif
	}
	return TRUE;
}

/* polygon data */
gboolean max_cb_0x08FE_0x011A(MaxGlobalData *global, MaxLocalData *local)
{
	gint32 i;
	guint32 numpoly, type, numvert, cntpoly = 0;
	G3DObject *object = (G3DObject *)local->object;
	G3DFace *face;
	G3DMaterial *material;

	g_return_val_if_fail(local->nb >= 4, FALSE);
	g_return_val_if_fail(object != NULL, FALSE);

	material = (G3DMaterial *)g_slist_nth_data(global->model->materials,
		(global->vertex_offset ? 1 : 0));
	g_return_val_if_fail(material != NULL, FALSE);

	numpoly = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;
#if DEBUG > 0
	g_debug("|%s[POLY] %d polygons to read", debug_pad(local->level),
		numpoly);
#endif
	while(local->nb >= 4) {
		numvert = g3d_stream_read_int32_le(global->stream);
		local->nb -= 4;
#if DEBUG > 0
		g_debug("|%s[POLY] %04d: %d vertices", debug_pad(local->level),
		cntpoly, numvert);
#endif
		g_return_val_if_fail(numvert >= 3, FALSE);

		face = g_new0(G3DFace, 1);
		face->material = material;
		face->vertex_count = numvert;
		face->vertex_indices = g_new0(guint32, numvert);
		object->faces = g_slist_append(object->faces, face);
		for(i = 0; i < numvert; i ++) {
			face->vertex_indices[i] =
				global->vertex_offset +
				g3d_stream_read_int32_le(global->stream);
			local->nb -= 4;
			g_return_val_if_fail(
				face->vertex_indices[i] < object->vertex_count, FALSE);
		}
		type = g3d_stream_read_int16_le(global->stream);
		local->nb -= 2;

		if(type & 0xFFC6) {
			g_warning("MAX: 0x011A: unhandled 0x%08x", type);
#if DEBUG > 0
			numvert = MIN(local->nb / 2, 20);
			for(i = 0; i < numvert; i ++) {
				g_debug("|%s[POLY] 0x%04x", debug_pad(local->level),
					g3d_stream_read_int16_le(global->stream));
				local->nb -= 2;
			}
#endif
			return FALSE;
		}

		/* FIXME: order of additional data most likely wrong */
		for(i = 3; i < numvert; i ++) {
			g3d_stream_read_int32_le(global->stream);
			g3d_stream_read_int32_le(global->stream);
			local->nb -= 8;
		}
		if(type & 0x0001) {
			g3d_stream_read_int32_le(global->stream);
			local->nb -= 4;
		}
		if(type & 0x0008) {
			g3d_stream_read_int16_le(global->stream);
			local->nb -= 2;
		}
		if(type & 0x0010) {
			g3d_stream_read_int32_le(global->stream);
			local->nb -= 4;
		}
		cntpoly ++;
	}
#if DEBUG > 0
	g_debug("|%s[POLY] %d faces added to object", debug_pad(local->level),
		cntpoly);
#endif
	return TRUE;
}

/* texture vertices */
gboolean max_cb_0x08FE_0x0128(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 num;
	G3DObject *object = (G3DObject *)local->object;

	g_return_val_if_fail(local->nb >= 4, FALSE);
	g_return_val_if_fail(object != NULL, FALSE);

	num = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;

#if DEBUG > 0
	g_debug("|%s[TEXV] %d texture vertices", debug_pad(local->level), num);
#endif
	return TRUE;
}

/* texture indices */
gboolean max_cb_0x08FE_0x012B(MaxGlobalData *global, MaxLocalData *local)
{
	gint i;
	guint32 *vdata, vcnt, maxidx = 0, numpoly = 0, maxvcnt = 0;
#if 0
	G3DObject *object = (G3DObject *)local->object;
	G3DFace *face;

	g_return_val_if_fail(object != NULL, FALSE);
#endif

	while(local->nb >= 4) {
		vcnt = g3d_stream_read_int32_le(global->stream);
		local->nb -= 4;
		if(vcnt > maxvcnt)
			maxvcnt = vcnt;
#if 0
		face = g_new0(G3DFace, 1);
		face->vertex_count = vcnt;
#endif
		if(local->nb < (vcnt * 4)) {
#if DEBUG > 0
			g_debug("|%s[TIDX] %d polygons, max index: %d, max vcnt: %d "
				"(nb=%d, vcnt=%d)", debug_pad(local->level),
				numpoly, maxidx, maxvcnt, local->nb, vcnt);
#endif

			return FALSE;
		}
		vdata = g_new0(guint32, vcnt);
		numpoly ++;
		for(i = 0; i < vcnt; i ++) {
			vdata[i] = g3d_stream_read_int32_le(global->stream);
			local->nb -= 4;
			if(vdata[i] > maxidx)
				maxidx = vdata[i];
		}
#if 1
		g_free(vdata);
#endif
	}
#if DEBUG > 0
	g_debug("|%s[TIDX] %d polygons, max index: %d, max vcnt: %d",
		debug_pad(local->level), numpoly, maxidx, maxvcnt);
#endif
	return TRUE;
}

/* geometric object */
gboolean max_cb_IDROOT_IDGEOM(MaxGlobalData *global, MaxLocalData *local)
{
	G3DObject *object;

	object = g_new0(G3DObject, 1);
	object->name = g_strdup_printf("0x%04X object @ 0x%08x",
		local->id, (guint32)g3d_stream_tell(global->stream));
	local->object = object;
	global->model->objects = g_slist_append(global->model->objects, object);

	global->object = object;
	global->vertex_offset = 0;

	return TRUE;
}

/* mesh */
gboolean max_cb_IDGEOM_0x08FE(MaxGlobalData *global, MaxLocalData *local)
{
	g_return_val_if_fail(global->object != NULL, FALSE);
	return TRUE;
}

/* object name */
gboolean max_cb_IDGEOM_0x0962(MaxGlobalData *global, MaxLocalData *local)
{
	G3DObject *object = (G3DObject *)local->object;
	gchar *name;
	gint32 len;

	g_return_val_if_fail(object != NULL, FALSE);

	g_free(object->name);
	len = local->nb / 2;
	name = max_read_wchar(global->stream, len);
	object->name = g_strdup_printf("%s (0x%08x)",
		name, (guint32)g3d_stream_tell(global->stream) - len - 6);
	g_free(name);
#if DEBUG > 0
	g_debug("|%s[NAME] %s", debug_pad(local->level), object->name);
#endif
	local->nb -= len * 2;

	return TRUE;
}

/* single face */
gboolean max_cb_0x0118_0x0110(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 num;
	gint i;
	G3DObject *object = (G3DObject *)local->object;
	G3DMaterial *mat;
	G3DFace *face;

	g_return_val_if_fail(local->nb >= 4, FALSE);
	g_return_val_if_fail(object != NULL, FALSE);

	mat = (G3DMaterial *)g_slist_nth_data(global->model->materials,
		(global->vertex_offset ? 1 : 0));

	num = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;

	face = g_new0(G3DFace, 1);
	face->vertex_count = num;
	face->vertex_indices = g_new0(guint32, num);
	face->material = mat;
	object->faces = g_slist_append(object->faces, face);

	g_return_val_if_fail(local->nb >= (num * 4), FALSE);
	for(i = 0; i < num; i ++) {
		face->vertex_indices[i] =
			global->vertex_offset +
			g3d_stream_read_int32_le(global->stream);
		local->nb -= 4;
		if(face->vertex_indices[i] >= object->vertex_count) {
			g_warning("MAX: 0x0118::0x0110: vertex index (%d) >= "
				"vertex count (%d)",
				face->vertex_indices[i],
				object->vertex_count);
			face->vertex_indices[i] = 0;
		}
	}
	return TRUE;
}

/* triangles */
gboolean max_cb_0x08FE_0x0912(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 num;
	gint i, j;
	G3DObject *object;
	G3DFace *face;
	G3DMaterial *mat;

	mat = (G3DMaterial *)g_slist_nth_data(global->model->materials,
		(global->vertex_offset ? 1 : 0));

	if(local->nb < 4)
		return FALSE;

	/* faces */
	num = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;
	object = (G3DObject *)local->object;
	if(object == NULL) {
		g_warning("MAX: 0x08FE::0x0912: no object");
		return FALSE;
	}
#if DEBUG > 0
	g_debug("|%s[TRIS] %d triangles", debug_pad(local->level), num);
#endif
	for(i = 0; i < num; i ++) {
		face = g_new0(G3DFace, 1);
		face->vertex_count = 3;
		face->vertex_indices = g_new0(guint32, 3);
		face->material = mat;
		object->faces = g_slist_append(object->faces, face);

		if(local->nb < 20)
			return FALSE;
		for(j = 0; j < 3; j ++) {
			face->vertex_indices[j] =
				global->vertex_offset +
				g3d_stream_read_int32_le(global->stream);
			if(face->vertex_indices[j] >= object->vertex_count) {
				g_warning("MAX: 0x08FE::0x0912: vertex index too high"
					" (%d (0x%08x) >= %d)",
					face->vertex_indices[j], face->vertex_indices[j],
					object->vertex_count);
				face->vertex_indices[j] = 0;
			}
		}
		/* unknown for now */
		g3d_stream_read_int32_le(global->stream);
		g3d_stream_read_int32_le(global->stream);
		local->nb -= 20;
	}
	return TRUE;
}

/* vertices */
gboolean max_cb_0x08FE_0x0914(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 num;
	gint i, j;
	G3DObject *object = (G3DObject *)local->object;

	g_return_val_if_fail(local->nb >= 4, FALSE);
	g_return_val_if_fail(object != NULL, FALSE);

	/* vertices */
	num = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;
#if DEBUG > 0
	g_debug("|%s[VERT] %d vertices", debug_pad(local->level), num);
#endif
	global->vertex_offset = object->vertex_count;
	object->vertex_count += num;
	object->vertex_data = g_realloc(object->vertex_data,
		object->vertex_count * 3 * sizeof(G3DFloat));

	for(i = 0; i < num; i ++) {
		if(local->nb < 12)
			return FALSE;
		for(j = 0; j < 3; j ++)
			object->vertex_data[(global->vertex_offset + i) * 3 + j] =
				g3d_stream_read_float_le(global->stream);
		local->nb -= 12;
	}
	return TRUE;
}

/* texture vertices */
gboolean max_cb_0x08FE_0x0916(MaxGlobalData *global, MaxLocalData *local)
{
	return max_cb_0x08FE_0x0128(global, local);
}

/* texture triangles */
gboolean max_cb_0x08FE_0x0918(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 cnttris = 0;

	while(local->nb >= 12) {
		cnttris ++;

		g3d_stream_read_int32_le(global->stream);
		g3d_stream_read_int32_le(global->stream);
		g3d_stream_read_int32_le(global->stream);
		local->nb -= 12;
	}

#if DEBUG > 0
	g_debug("|%s[TEXI] %d textured triangles (%d bytes left)",
		debug_pad(local->level), cnttris, local->nb);
#endif
	return 0;
}

/* vertices */
gboolean max_cb_0x08FE_0x2394(MaxGlobalData *global, MaxLocalData *local)
{
	return max_cb_0x08FE_0x0914(global, local);
}

/* triangles */
gboolean max_cb_0x08FE_0x2396(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 num;
	gint32 i, j;
	G3DObject *object = (G3DObject *)local->object;
	G3DFace *face;
	G3DMaterial *mat;

	mat = (G3DMaterial *)g_slist_nth_data(global->model->materials,
		(global->vertex_offset ? 1 : 0));

	g_return_val_if_fail(local->nb >= 4, FALSE);
	g_return_val_if_fail(object != NULL, FALSE);

	/* faces */
	num = g3d_stream_read_int32_le(global->stream);
	local->nb -= 4;
#if DEBUG > 0
	g_debug("|%s[TRIS] %d triangles", debug_pad(local->level), num);
#endif
	for(i = 0; i < num; i ++) {
		g_return_val_if_fail(local->nb >= 12, FALSE);

		face = g_new0(G3DFace, 1);
		face->vertex_count = 3;
		face->vertex_indices = g_new0(guint32, 3);
		face->material = mat;
		object->faces = g_slist_append(object->faces, face);

		g_return_val_if_fail(local->nb >= 12, FALSE);
		for(j = 0; j < 3; j ++) {
			face->vertex_indices[j] =
				global->vertex_offset +
				g3d_stream_read_int32_le(global->stream);
			local->nb -= 4;
			if(face->vertex_indices[j] >= object->vertex_count) {
				g_warning("MAX: 0x08FE::0x2396: vertex index too high"
					" (%d (0x%08x) >= %d)",
					face->vertex_indices[j], face->vertex_indices[j],
					object->vertex_count);
				face->vertex_indices[j] = 0;
			}
		}
	}
	return TRUE;
}

/* material */
gboolean max_cb_IDMATG_0x4000(MaxGlobalData *global, MaxLocalData *local)
{
	G3DMaterial *material;

	if(strcmp(global->subfile, "Scene") != 0)
		return FALSE;

	material = g3d_material_new();
	material->name = g_strdup_printf("0x4000 material @ 0x%08x",
		(guint32)g3d_stream_tell(global->stream));
	local->object = material;
	global->model->materials = g_slist_append(global->model->materials,
		material);
	return TRUE;
}

/* material name */
gboolean max_cb_0x4000_0x4001(MaxGlobalData *global, MaxLocalData *local)
{
	guint32 len;
	G3DMaterial *material = (G3DMaterial *)local->object;

	g_return_val_if_fail(material != NULL, FALSE);
	if(material->name)
		g_free(material->name);
	len = local->nb / 2;
	material->name = max_read_wchar(global->stream, len);
	local->nb -= len * 2;
#if DEBUG > 0
	g_debug("|%s[MATN] %s", debug_pad(local->level), material->name);
#endif
	return TRUE;
}

/* material color */
gboolean max_cb_0x4000_0x4030(MaxGlobalData *global, MaxLocalData *local)
{
	G3DMaterial *material = (G3DMaterial *)local->object;

	g_return_val_if_fail(material != NULL, FALSE);
	g_return_val_if_fail(local->nb >= 16, FALSE);

	material->r = g3d_stream_read_float_le(global->stream);
	material->g = g3d_stream_read_float_le(global->stream);
	material->b = g3d_stream_read_float_le(global->stream);
	material->a = g3d_stream_read_float_le(global->stream);
	local->nb -= 16;
#if DEBUG > 0
	g_debug("|%s[MATC] %.2f, %.2f, %.2f, %.2f", debug_pad(local->level),
		material->r, material->g, material->b, material->a);
#endif
	return TRUE;
}