zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lib3ds_material.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 1996-2008 by Jan Eric Kyprianidis <www.kyprianidis.com>
3  All rights reserved.
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 2.1 of the License, or
8  (at your option) any later version.
9 
10  Thisprogram is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program; If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "lib3ds_impl.h"
19 
20 
21 static void
23  map->flags = 0x10;
24  map->percent = 1.0f;
25  map->scale[0] = 1.0f;
26  map->scale[1] = 1.0f;
27 }
28 
29 
39 lib3ds_material_new(const char* name) {
40  Lib3dsMaterial *mat;
41 
42  mat = (Lib3dsMaterial*)calloc(sizeof(Lib3dsMaterial), 1);
43  if (!mat) {
44  return(0);
45  }
46 
47  if (name) {
48  strcpy(mat->name, name);
49  }
50  mat->ambient[0] = mat->ambient[1] = mat->ambient[2] = 0.588235f;
51  mat->diffuse[0] = mat->diffuse[1] = mat->diffuse[2] = 0.588235f;
52  mat->specular[0] = mat->specular[1] = mat->specular[2] = 0.898039f;
53  mat->shininess = 0.1f;
54  mat->wire_size = 1.0f;
55  mat->shading = 3;
56 
73 
74  return(mat);
75 }
76 
77 
78 void
80  memset(material, 0, sizeof(Lib3dsMaterial));
81  free(material);
82 }
83 
84 
85 static void
86 color_read(float rgb[3], Lib3dsIo *io) {
87  Lib3dsChunk c;
89  int have_lin = FALSE;
90 
91  lib3ds_chunk_read_start(&c, 0, io);
92 
93  while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
94  switch (chunk) {
95  case CHK_LIN_COLOR_24: {
96  int i;
97  for (i = 0; i < 3; ++i) {
98  rgb[i] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
99  }
100  have_lin = TRUE;
101  break;
102  }
103 
104  case CHK_COLOR_24: {
105  /* gamma corrected color chunk
106  replaced in 3ds R3 by LIN_COLOR_24 */
107  if (!have_lin) {
108  int i;
109  for (i = 0; i < 3; ++i) {
110  rgb[i] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
111  }
112  }
113  break;
114  }
115 
116  case CHK_LIN_COLOR_F: {
117  int i;
118  for (i = 0; i < 3; ++i) {
119  rgb[i] = lib3ds_io_read_float(io);
120  }
121  have_lin = TRUE;
122  break;
123  }
124 
125  case CHK_COLOR_F: {
126  if (!have_lin) {
127  int i;
128  for (i = 0; i < 3; ++i) {
129  rgb[i] = lib3ds_io_read_float(io);
130  }
131  }
132  break;
133  }
134 
135  default:
136  lib3ds_chunk_unknown(chunk, io);
137  }
138  }
139 
140  lib3ds_chunk_read_end(&c, io);
141 }
142 
143 
144 static void
146  Lib3dsChunk c;
147  uint16_t chunk;
148 
149  lib3ds_chunk_read_start(&c, 0, io);
150 
151  while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
152  switch (chunk) {
153  case CHK_INT_PERCENTAGE: {
155  *p = (float)(1.0 * i / 100.0);
156  break;
157  }
158 
159  default:
160  lib3ds_chunk_unknown(chunk, io);
161  }
162  }
163 
164  lib3ds_chunk_read_end(&c, io);
165 }
166 
167 
168 static void
170  Lib3dsChunk c;
171  uint16_t chunk;
172 
173  lib3ds_chunk_read_start(&c, 0, io);
174 
175  while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
176  switch (chunk) {
177  case CHK_INT_PERCENTAGE: {
178  map->percent = 1.0f * lib3ds_io_read_intw(io) / 100.0f;
179  break;
180  }
181 
182  case CHK_MAT_MAPNAME: {
183  lib3ds_io_read_string(io, map->name, 64);
184  lib3ds_io_log(io, LIB3DS_LOG_INFO, " NAME=%s", map->name);
185  break;
186  }
187 
188  case CHK_MAT_MAP_TILING: {
189  map->flags = lib3ds_io_read_word(io);
190  break;
191  }
192 
193  case CHK_MAT_MAP_TEXBLUR:
194  map->blur = lib3ds_io_read_float(io);
195  break;
196 
197  case CHK_MAT_MAP_USCALE:
198  map->scale[0] = lib3ds_io_read_float(io);
199  break;
200 
201  case CHK_MAT_MAP_VSCALE: {
202  map->scale[1] = lib3ds_io_read_float(io);
203  break;
204  }
205  case CHK_MAT_MAP_UOFFSET: {
206  map->offset[0] = lib3ds_io_read_float(io);
207  break;
208  }
209 
210  case CHK_MAT_MAP_VOFFSET: {
211  map->offset[1] = lib3ds_io_read_float(io);
212  break;
213  }
214 
215  case CHK_MAT_MAP_ANG: {
216  map->rotation = lib3ds_io_read_float(io);
217  break;
218  }
219 
220  case CHK_MAT_MAP_COL1: {
221  map->tint_1[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
222  map->tint_1[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
223  map->tint_1[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
224  break;
225  }
226 
227  case CHK_MAT_MAP_COL2: {
228  map->tint_2[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
229  map->tint_2[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
230  map->tint_2[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
231  break;
232  }
233 
234  case CHK_MAT_MAP_RCOL: {
235  map->tint_r[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
236  map->tint_r[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
237  map->tint_r[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
238  break;
239  }
240 
241  case CHK_MAT_MAP_GCOL: {
242  map->tint_g[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
243  map->tint_g[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
244  map->tint_g[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
245  break;
246  }
247 
248  case CHK_MAT_MAP_BCOL: {
249  map->tint_b[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
250  map->tint_b[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
251  map->tint_b[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
252  break;
253  }
254 
255  default:
256  lib3ds_chunk_unknown(chunk,io);
257  }
258  }
259 
260  lib3ds_chunk_read_end(&c, io);
261 }
262 
263 
264 void
266  Lib3dsChunk c;
267  uint16_t chunk;
268 
269  assert(material);
271 
272  while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
273  switch (chunk) {
274  case CHK_MAT_NAME: {
275  lib3ds_io_read_string(io, material->name, 64);
276  lib3ds_io_log(io, LIB3DS_LOG_INFO, " NAME=%s", material->name);
277  break;
278  }
279 
280  case CHK_MAT_AMBIENT: {
281  lib3ds_chunk_read_reset(&c, io);
282  color_read(material->ambient, io);
283  break;
284  }
285 
286  case CHK_MAT_DIFFUSE: {
287  lib3ds_chunk_read_reset(&c, io);
288  color_read(material->diffuse, io);
289  break;
290  }
291 
292  case CHK_MAT_SPECULAR: {
293  lib3ds_chunk_read_reset(&c, io);
294  color_read(material->specular, io);
295  break;
296  }
297 
298  case CHK_MAT_SHININESS: {
299  lib3ds_chunk_read_reset(&c, io);
300  int_percentage_read(&material->shininess, io);
301  break;
302  }
303 
304  case CHK_MAT_SHIN2PCT: {
305  lib3ds_chunk_read_reset(&c, io);
306  int_percentage_read(&material->shin_strength, io);
307  break;
308  }
309 
310  case CHK_MAT_TRANSPARENCY: {
311  lib3ds_chunk_read_reset(&c, io);
312  int_percentage_read(&material->transparency, io);
313  break;
314  }
315 
316  case CHK_MAT_XPFALL: {
317  lib3ds_chunk_read_reset(&c, io);
318  int_percentage_read(&material->falloff, io);
319  break;
320  }
321 
322  case CHK_MAT_SELF_ILPCT: {
323  lib3ds_chunk_read_reset(&c, io);
324  int_percentage_read(&material->self_illum, io);
325  break;
326  }
327 
328  case CHK_MAT_USE_XPFALL: {
329  material->use_falloff = TRUE;
330  break;
331  }
332 
333  case CHK_MAT_REFBLUR: {
334  lib3ds_chunk_read_reset(&c, io);
335  int_percentage_read(&material->blur, io);
336  break;
337  }
338 
339  case CHK_MAT_USE_REFBLUR: {
340  material->use_blur = TRUE;
341  break;
342  }
343 
344  case CHK_MAT_SHADING: {
345  material->shading = lib3ds_io_read_intw(io);
346  break;
347  }
348 
349  case CHK_MAT_SELF_ILLUM: {
350  material->self_illum_flag = TRUE;
351  break;
352  }
353 
354  case CHK_MAT_TWO_SIDE: {
355  material->two_sided = TRUE;
356  break;
357  }
358 
359  case CHK_MAT_DECAL: {
360  material->map_decal = TRUE;
361  break;
362  }
363 
364  case CHK_MAT_ADDITIVE: {
365  material->is_additive = TRUE;
366  break;
367  }
368 
369  case CHK_MAT_FACEMAP: {
370  material->face_map = TRUE;
371  break;
372  }
373 
374  case CHK_MAT_PHONGSOFT: {
375  material->soften = TRUE;
376  break;
377  }
378 
379  case CHK_MAT_WIRE: {
380  material->use_wire = TRUE;
381  break;
382  }
383 
384  case CHK_MAT_WIREABS: {
385  material->use_wire_abs = TRUE;
386  break;
387  }
388  case CHK_MAT_WIRE_SIZE: {
389  material->wire_size = lib3ds_io_read_float(io);
390  break;
391  }
392 
393  case CHK_MAT_TEXMAP: {
394  lib3ds_chunk_read_reset(&c, io);
395  texture_map_read(&material->texture1_map, io);
396  break;
397  }
398 
399  case CHK_MAT_TEXMASK: {
400  lib3ds_chunk_read_reset(&c, io);
401  texture_map_read(&material->texture1_mask, io);
402  break;
403  }
404 
405  case CHK_MAT_TEX2MAP: {
406  lib3ds_chunk_read_reset(&c, io);
407  texture_map_read(&material->texture2_map, io);
408  break;
409  }
410 
411  case CHK_MAT_TEX2MASK: {
412  lib3ds_chunk_read_reset(&c, io);
413  texture_map_read(&material->texture2_mask, io);
414  break;
415  }
416 
417  case CHK_MAT_OPACMAP: {
418  lib3ds_chunk_read_reset(&c, io);
419  texture_map_read(&material->opacity_map, io);
420  break;
421  }
422 
423  case CHK_MAT_OPACMASK: {
424  lib3ds_chunk_read_reset(&c, io);
425  texture_map_read(&material->opacity_mask, io);
426  break;
427  }
428 
429  case CHK_MAT_BUMPMAP: {
430  lib3ds_chunk_read_reset(&c, io);
431  texture_map_read(&material->bump_map, io);
432  break;
433  }
434  case CHK_MAT_BUMPMASK: {
435  lib3ds_chunk_read_reset(&c, io);
436  texture_map_read(&material->bump_mask, io);
437  break;
438  }
439  case CHK_MAT_SPECMAP: {
440  lib3ds_chunk_read_reset(&c, io);
441  texture_map_read(&material->specular_map, io);
442  break;
443  }
444 
445  case CHK_MAT_SPECMASK: {
446  lib3ds_chunk_read_reset(&c, io);
447  texture_map_read(&material->specular_mask, io);
448  break;
449  }
450 
451  case CHK_MAT_SHINMAP: {
452  lib3ds_chunk_read_reset(&c, io);
453  texture_map_read(&material->shininess_map, io);
454  break;
455  }
456 
457  case CHK_MAT_SHINMASK: {
458  lib3ds_chunk_read_reset(&c, io);
459  texture_map_read(&material->shininess_mask, io);
460  break;
461  }
462 
463  case CHK_MAT_SELFIMAP: {
464  lib3ds_chunk_read_reset(&c, io);
465  texture_map_read(&material->self_illum_map, io);
466  break;
467  }
468 
469  case CHK_MAT_SELFIMASK: {
470  lib3ds_chunk_read_reset(&c, io);
471  texture_map_read(&material->self_illum_mask, io);
472  break;
473  }
474 
475  case CHK_MAT_REFLMAP: {
476  lib3ds_chunk_read_reset(&c, io);
477  texture_map_read(&material->reflection_map, io);
478  break;
479  }
480 
481  case CHK_MAT_REFLMASK: {
482  lib3ds_chunk_read_reset(&c, io);
483  texture_map_read(&material->reflection_mask, io);
484  break;
485  }
486 
487  case CHK_MAT_ACUBIC: {
490  material->autorefl_map_flags = lib3ds_io_read_intw(io);
491  material->autorefl_map_size = lib3ds_io_read_intd(io);
493  break;
494  }
495 
496  default:
497  lib3ds_chunk_unknown(chunk, io);
498  }
499  }
500 
501  lib3ds_chunk_read_end(&c, io);
502 }
503 
504 
505 static void
506 color_write(float rgb[3], Lib3dsIo *io) {
507  Lib3dsChunk c;
508 
509  c.chunk = CHK_COLOR_24;
510  c.size = 9;
511  lib3ds_chunk_write(&c, io);
512  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*rgb[0] + 0.5));
513  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*rgb[1] + 0.5));
514  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*rgb[2] + 0.5));
515 
517  c.size = 9;
518  lib3ds_chunk_write(&c, io);
519  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*rgb[0] + 0.5));
520  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*rgb[1] + 0.5));
521  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*rgb[2] + 0.5));
522 }
523 
524 
525 static void
527  Lib3dsChunk c;
528 
530  c.size = 8;
531  lib3ds_chunk_write(&c, io);
532  lib3ds_io_write_intw(io, (uint8_t)floor(100.0*p + 0.5));
533 }
534 
535 
536 static void
538  Lib3dsChunk c;
539 
540  if (strlen(map->name) == 0) {
541  return;
542  }
543  c.chunk = chunk;
544  lib3ds_chunk_write_start(&c, io);
545 
546  int_percentage_write(map->percent, io);
547 
548  { /*---- CHK_MAT_MAPNAME ----*/
549  Lib3dsChunk c;
551  c.size = 6 + (uint32_t)strlen(map->name) + 1;
552  lib3ds_chunk_write(&c, io);
553  lib3ds_io_write_string(io, map->name);
554  }
555 
556  { /*---- CHK_MAT_MAP_TILING ----*/
557  Lib3dsChunk c;
559  c.size = 8;
560  lib3ds_chunk_write(&c, io);
562  }
563 
564  { /*---- CHK_MAT_MAP_TEXBLUR ----*/
565  Lib3dsChunk c;
567  c.size = 10;
568  lib3ds_chunk_write(&c, io);
569  lib3ds_io_write_float(io, map->blur);
570  }
571 
572  { /*---- CHK_MAT_MAP_USCALE ----*/
573  Lib3dsChunk c;
575  c.size = 10;
576  lib3ds_chunk_write(&c, io);
577  lib3ds_io_write_float(io, map->scale[0]);
578  }
579 
580  { /*---- CHK_MAT_MAP_VSCALE ----*/
581  Lib3dsChunk c;
583  c.size = 10;
584  lib3ds_chunk_write(&c, io);
585  lib3ds_io_write_float(io, map->scale[1]);
586  }
587 
588  { /*---- CHK_MAT_MAP_UOFFSET ----*/
589  Lib3dsChunk c;
591  c.size = 10;
592  lib3ds_chunk_write(&c, io);
593  lib3ds_io_write_float(io, map->offset[0]);
594  }
595 
596  { /*---- CHK_MAT_MAP_VOFFSET ----*/
597  Lib3dsChunk c;
599  c.size = 10;
600  lib3ds_chunk_write(&c, io);
601  lib3ds_io_write_float(io, map->offset[1]);
602  }
603 
604  { /*---- CHK_MAT_MAP_ANG ----*/
605  Lib3dsChunk c;
607  c.size = 10;
608  lib3ds_chunk_write(&c, io);
610  }
611 
612  { /*---- CHK_MAT_MAP_COL1 ----*/
613  Lib3dsChunk c;
615  c.size = 9;
616  lib3ds_chunk_write(&c, io);
617  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[0] + 0.5));
618  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[1] + 0.5));
619  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[2] + 0.5));
620  }
621 
622  { /*---- CHK_MAT_MAP_COL2 ----*/
623  Lib3dsChunk c;
625  c.size = 9;
626  lib3ds_chunk_write(&c, io);
627  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[0] + 0.5));
628  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[1] + 0.5));
629  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[2] + 0.5));
630  }
631 
632  { /*---- CHK_MAT_MAP_RCOL ----*/
633  Lib3dsChunk c;
635  c.size = 9;
636  lib3ds_chunk_write(&c, io);
637  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[0] + 0.5));
638  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[1] + 0.5));
639  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[2] + 0.5));
640  }
641 
642  { /*---- CHK_MAT_MAP_GCOL ----*/
643  Lib3dsChunk c;
645  c.size = 9;
646  lib3ds_chunk_write(&c, io);
647  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[0] + 0.5));
648  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[1] + 0.5));
649  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[2] + 0.5));
650  }
651 
652  { /*---- CHK_MAT_MAP_BCOL ----*/
653  Lib3dsChunk c;
655  c.size = 9;
656  lib3ds_chunk_write(&c, io);
657  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[0] + 0.5));
658  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[1] + 0.5));
659  lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[2] + 0.5));
660  }
661 
662  lib3ds_chunk_write_end(&c, io);
663 }
664 
665 
666 void
668  Lib3dsChunk c;
669 
670  c.chunk = CHK_MAT_ENTRY;
671  lib3ds_chunk_write_start(&c, io);
672 
673  { /*---- CHK_MAT_NAME ----*/
674  Lib3dsChunk c;
675  c.chunk = CHK_MAT_NAME;
676  c.size = 6 + (uint32_t)strlen(material->name) + 1;
677  lib3ds_chunk_write(&c, io);
678  lib3ds_io_write_string(io, material->name);
679  }
680 
681  { /*---- CHK_MAT_AMBIENT ----*/
682  Lib3dsChunk c;
684  c.size = 24;
685  lib3ds_chunk_write(&c, io);
686  color_write(material->ambient, io);
687  }
688 
689  { /*---- CHK_MAT_DIFFUSE ----*/
690  Lib3dsChunk c;
692  c.size = 24;
693  lib3ds_chunk_write(&c, io);
694  color_write(material->diffuse, io);
695  }
696 
697  { /*---- CHK_MAT_SPECULAR ----*/
698  Lib3dsChunk c;
700  c.size = 24;
701  lib3ds_chunk_write(&c, io);
702  color_write(material->specular, io);
703  }
704 
705  { /*---- CHK_MAT_SHININESS ----*/
706  Lib3dsChunk c;
708  c.size = 14;
709  lib3ds_chunk_write(&c, io);
710  int_percentage_write(material->shininess, io);
711  }
712 
713  { /*---- CHK_MAT_SHIN2PCT ----*/
714  Lib3dsChunk c;
716  c.size = 14;
717  lib3ds_chunk_write(&c, io);
718  int_percentage_write(material->shin_strength, io);
719  }
720 
721  { /*---- CHK_MAT_TRANSPARENCY ----*/
722  Lib3dsChunk c;
724  c.size = 14;
725  lib3ds_chunk_write(&c, io);
726  int_percentage_write(material->transparency, io);
727  }
728 
729  { /*---- CHK_MAT_XPFALL ----*/
730  Lib3dsChunk c;
731  c.chunk = CHK_MAT_XPFALL;
732  c.size = 14;
733  lib3ds_chunk_write(&c, io);
734  int_percentage_write(material->falloff, io);
735  }
736 
737  if (material->use_falloff) { /*---- CHK_MAT_USE_XPFALL ----*/
738  Lib3dsChunk c;
740  c.size = 6;
741  lib3ds_chunk_write(&c, io);
742  }
743 
744  { /*---- CHK_MAT_SHADING ----*/
745  Lib3dsChunk c;
747  c.size = 8;
748  lib3ds_chunk_write(&c, io);
749  lib3ds_io_write_intw(io, material->shading);
750  }
751 
752  { /*---- CHK_MAT_REFBLUR ----*/
753  Lib3dsChunk c;
755  c.size = 14;
756  lib3ds_chunk_write(&c, io);
757  int_percentage_write(material->blur, io);
758  }
759 
760  if (material->use_blur) { /*---- CHK_MAT_USE_REFBLUR ----*/
761  Lib3dsChunk c;
763  c.size = 6;
764  lib3ds_chunk_write(&c, io);
765  }
766 
767  if (material->self_illum_flag) { /*---- CHK_MAT_SELF_ILLUM ----*/
768  Lib3dsChunk c;
770  c.size = 6;
771  lib3ds_chunk_write(&c, io);
772  }
773 
774  if (material->two_sided) { /*---- CHK_MAT_TWO_SIDE ----*/
775  Lib3dsChunk c;
777  c.size = 6;
778  lib3ds_chunk_write(&c, io);
779  }
780 
781  if (material->map_decal) { /*---- CHK_MAT_DECAL ----*/
782  Lib3dsChunk c;
783  c.chunk = CHK_MAT_DECAL;
784  c.size = 6;
785  lib3ds_chunk_write(&c, io);
786  }
787 
788  if (material->is_additive) { /*---- CHK_MAT_ADDITIVE ----*/
789  Lib3dsChunk c;
791  c.size = 6;
792  lib3ds_chunk_write(&c, io);
793  }
794 
795  if (material->use_wire) { /*---- CHK_MAT_WIRE ----*/
796  Lib3dsChunk c;
797  c.chunk = CHK_MAT_WIRE;
798  c.size = 6;
799  lib3ds_chunk_write(&c, io);
800  }
801 
802  if (material->use_wire_abs) { /*---- CHK_MAT_WIREABS ----*/
803  Lib3dsChunk c;
805  c.size = 6;
806  lib3ds_chunk_write(&c, io);
807  }
808 
809  { /*---- CHK_MAT_WIRE_SIZE ----*/
810  Lib3dsChunk c;
812  c.size = 10;
813  lib3ds_chunk_write(&c, io);
814  lib3ds_io_write_float(io, material->wire_size);
815  }
816 
817  if (material->face_map) { /*---- CHK_MAT_FACEMAP ----*/
818  Lib3dsChunk c;
820  c.size = 6;
821  lib3ds_chunk_write(&c, io);
822  }
823 
824  if (material->soften) { /*---- CHK_MAT_PHONGSOFT ----*/
825  Lib3dsChunk c;
827  c.size = 6;
828  lib3ds_chunk_write(&c, io);
829  }
830 
837  texture_map_write(CHK_MAT_BUMPMAP, &material->bump_map, io);
847 
848  { /*---- CHK_MAT_ACUBIC ----*/
849  Lib3dsChunk c;
850  c.chunk = CHK_MAT_ACUBIC;
851  c.size = 18;
852  lib3ds_chunk_write(&c, io);
853  lib3ds_io_write_intb(io, 0);
858  }
859 
860  lib3ds_chunk_write_end(&c, io);
861 }
Lib3dsTextureMap self_illum_map
Definition: lib3ds.h:261
void lib3ds_io_write_intw(Lib3dsIo *io, int16_t w)
Definition: lib3ds_io.c:368
int16_t lib3ds_io_read_intw(Lib3dsIo *io)
Definition: lib3ds_io.c:203
LIB3DSAPI void lib3ds_material_free(Lib3dsMaterial *material)
else Out of place iCCP chunk
Definition: pngrutil.c:1260
int face_map
Definition: lib3ds.h:243
static void texture_map_write(uint16_t chunk, Lib3dsTextureMap *map, Lib3dsIo *io)
void lib3ds_io_write_intd(Lib3dsIo *io, int32_t d)
Definition: lib3ds_io.c:384
int32_t lib3ds_io_read_intd(Lib3dsIo *io)
Definition: lib3ds_io.c:219
int autorefl_map_frame_step
Definition: lib3ds.h:268
float specular[3]
Definition: lib3ds.h:230
float transparency
Definition: lib3ds.h:235
static void initialize_texture_map(Lib3dsTextureMap *map)
static void color_write(float rgb[3], Lib3dsIo *io)
static void int_percentage_read(float *p, Lib3dsIo *io)
unsigned short uint16_t
int use_wire
Definition: lib3ds.h:246
Lib3dsTextureMap texture1_mask
Definition: lib3ds.h:250
float scale[2]
Definition: lib3ds.h:197
Lib3dsTextureMap specular_map
Definition: lib3ds.h:257
static void color_read(float rgb[3], Lib3dsIo *io)
void lib3ds_io_write_byte(Lib3dsIo *io, uint8_t b)
Definition: lib3ds_io.c:310
SDL_EventEntry * free
Definition: SDL_events.c:80
int autorefl_map_size
Definition: lib3ds.h:267
int use_wire_abs
Definition: lib3ds.h:247
Lib3dsTextureMap texture1_map
Definition: lib3ds.h:249
#define memset
Definition: SDL_malloc.c:633
static void texture_map_read(Lib3dsTextureMap *map, Lib3dsIo *io)
char name[64]
Definition: lib3ds.h:227
LIB3DSAPI Lib3dsMaterial * lib3ds_material_new(const char *name)
void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:140
EGLImageKHR EGLint * name
Definition: eglext.h:284
float wire_size
Definition: lib3ds.h:248
int8_t lib3ds_io_read_intb(Lib3dsIo *io)
Definition: lib3ds_io.c:190
#define assert(x)
Definition: SDL_malloc.c:1234
Lib3dsTextureMap bump_mask
Definition: lib3ds.h:256
float self_illum
Definition: lib3ds.h:239
void lib3ds_io_write_intb(Lib3dsIo *io, int8_t b)
Definition: lib3ds_io.c:356
float percent
Definition: lib3ds.h:195
#define calloc
Definition: SDL_malloc.c:636
unsigned flags
Definition: lib3ds.h:194
uint32_t size
Definition: lib3ds_impl.h:297
unsigned autorefl_map_flags
Definition: lib3ds.h:265
int two_sided
Definition: lib3ds.h:244
uint16_t lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:68
float tint_g[3]
Definition: lib3ds.h:203
float rotation
Definition: lib3ds.h:199
Lib3dsTextureMap specular_mask
Definition: lib3ds.h:258
void lib3ds_io_write_string(Lib3dsIo *io, const char *s)
Definition: lib3ds_io.c:443
float tint_b[3]
Definition: lib3ds.h:204
void lib3ds_material_write(Lib3dsMaterial *material, Lib3dsIo *io)
Lib3dsTextureMap reflection_mask
Definition: lib3ds.h:264
void lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:119
uint8_t lib3ds_io_read_byte(Lib3dsIo *io)
Definition: lib3ds_io.c:143
int autorefl_map_anti_alias
Definition: lib3ds.h:266
void lib3ds_io_write_float(Lib3dsIo *io, float l)
Definition: lib3ds_io.c:402
Lib3dsTextureMap opacity_mask
Definition: lib3ds.h:254
float diffuse[3]
Definition: lib3ds.h:229
void lib3ds_chunk_read_reset(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:90
float shin_strength
Definition: lib3ds.h:232
float tint_1[3]
Definition: lib3ds.h:200
GLfloat GLfloat p
Definition: glew.h:14938
static void int_percentage_write(float p, Lib3dsIo *io)
const GLfloat * c
Definition: glew.h:14913
uint16_t lib3ds_io_read_word(Lib3dsIo *io)
Definition: lib3ds_io.c:156
Lib3dsTextureMap texture2_mask
Definition: lib3ds.h:252
void lib3ds_material_read(Lib3dsMaterial *material, Lib3dsIo *io)
double floor(double x)
Definition: s_floor.c:40
float lib3ds_io_read_float(Lib3dsIo *io)
Definition: lib3ds_io.c:237
Lib3dsTextureMap reflection_map
Definition: lib3ds.h:263
#define FALSE
Definition: ftobjs.h:57
short int16_t
Definition: types.h:8
int use_falloff
Definition: lib3ds.h:240
int map_decal
Definition: lib3ds.h:245
int use_blur
Definition: lib3ds.h:233
void lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:96
float falloff
Definition: lib3ds.h:236
unsigned char uint8_t
unsigned int uint32_t
Lib3dsTextureMap opacity_map
Definition: lib3ds.h:253
float offset[2]
Definition: lib3ds.h:198
float blur
Definition: lib3ds.h:234
void lib3ds_io_read_string(Lib3dsIo *io, char *s, int buflen)
Definition: lib3ds_io.c:285
Lib3dsTextureMap shininess_map
Definition: lib3ds.h:259
int self_illum_flag
Definition: lib3ds.h:238
void lib3ds_io_log(Lib3dsIo *io, Lib3dsLogLevel level, const char *format,...)
Definition: lib3ds_io.c:100
char name[64]
Definition: lib3ds.h:193
void lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:111
float shininess
Definition: lib3ds.h:231
void lib3ds_chunk_read_start(Lib3dsChunk *c, uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:50
float ambient[3]
Definition: lib3ds.h:228
Lib3dsTextureMap texture2_map
Definition: lib3ds.h:251
float tint_r[3]
Definition: lib3ds.h:202
Lib3dsTextureMap shininess_mask
Definition: lib3ds.h:260
uint16_t chunk
Definition: lib3ds_impl.h:296
int i
Definition: pngrutil.c:1377
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLfloat *params GLenum GLint GLenum GLenum GLvoid *pixels GLenum GLint GLenum GLint *params GLenum GLenum GLint *params GLenum GLsizei const GLvoid *pointer GLenum GLenum const GLint *params GLenum GLfloat GLfloat GLint GLint const GLfloat *points GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat *points GLint GLfloat GLfloat GLint GLfloat GLfloat v2 GLenum GLenum const GLint *params GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum map
Definition: SDL_glfuncs.h:268
Lib3dsTextureMap self_illum_mask
Definition: lib3ds.h:262
#define TRUE
Definition: ftobjs.h:53
int is_additive
Definition: lib3ds.h:237
void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:129
float tint_2[3]
Definition: lib3ds.h:201
void lib3ds_io_write_word(Lib3dsIo *io, uint16_t w)
Definition: lib3ds_io.c:322
Lib3dsTextureMap bump_map
Definition: lib3ds.h:255