Ejemplo n.º 1
0
void
lib3ds_material_read(Lib3dsMaterial *material, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;

    assert(material);
    lib3ds_chunk_read_start(&c, CHK_MAT_ENTRY, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
        case CHK_MAT_NAME: {
            lib3ds_io_read_string(io, material->name, 64);
            lib3ds_io_log(io, LIB3DS_LOG_INFO, "  NAME=%s", material->name);
            break;
        }

        case CHK_MAT_AMBIENT: {
            lib3ds_chunk_read_reset(&c, io);
            color_read(material->ambient, io);
            break;
        }

        case CHK_MAT_DIFFUSE: {
            lib3ds_chunk_read_reset(&c, io);
            color_read(material->diffuse, io);
            break;
        }

        case CHK_MAT_SPECULAR: {
            lib3ds_chunk_read_reset(&c, io);
            color_read(material->specular, io);
            break;
        }

        case CHK_MAT_SHININESS: {
            lib3ds_chunk_read_reset(&c, io);
            int_percentage_read(&material->shininess, io);
            break;
        }

        case CHK_MAT_SHIN2PCT: {
            lib3ds_chunk_read_reset(&c, io);
            int_percentage_read(&material->shin_strength, io);
            break;
        }

        case CHK_MAT_TRANSPARENCY: {
            lib3ds_chunk_read_reset(&c, io);
            int_percentage_read(&material->transparency, io);
            break;
        }

        case CHK_MAT_XPFALL: {
            lib3ds_chunk_read_reset(&c, io);
            int_percentage_read(&material->falloff, io);
            break;
        }

        case CHK_MAT_SELF_ILPCT: {
            lib3ds_chunk_read_reset(&c, io);
            int_percentage_read(&material->self_illum, io);
            break;
        }

        case CHK_MAT_USE_XPFALL: {
            material->use_falloff = TRUE;
            break;
        }

        case CHK_MAT_REFBLUR: {
            lib3ds_chunk_read_reset(&c, io);
            int_percentage_read(&material->blur, io);
            break;
        }

        case CHK_MAT_USE_REFBLUR: {
            material->use_blur = TRUE;
            break;
        }

        case CHK_MAT_SHADING: {
            material->shading = lib3ds_io_read_intw(io);
            break;
        }

        case CHK_MAT_SELF_ILLUM: {
            material->self_illum_flag = TRUE;
            break;
        }

        case CHK_MAT_TWO_SIDE: {
            material->two_sided = TRUE;
            break;
        }

        case CHK_MAT_DECAL: {
            material->map_decal = TRUE;
            break;
        }

        case CHK_MAT_ADDITIVE: {
            material->is_additive = TRUE;
            break;
        }

        case CHK_MAT_FACEMAP: {
            material->face_map = TRUE;
            break;
        }

        case CHK_MAT_PHONGSOFT: {
            material->soften = TRUE;
            break;
        }

        case CHK_MAT_WIRE: {
            material->use_wire = TRUE;
            break;
        }

        case CHK_MAT_WIREABS: {
            material->use_wire_abs = TRUE;
            break;
        }
        case CHK_MAT_WIRE_SIZE: {
            material->wire_size = lib3ds_io_read_float(io);
            break;
        }

        case CHK_MAT_TEXMAP: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->texture1_map, io);
            break;
        }

        case CHK_MAT_TEXMASK: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->texture1_mask, io);
            break;
        }

        case CHK_MAT_TEX2MAP: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->texture2_map, io);
            break;
        }

        case CHK_MAT_TEX2MASK: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->texture2_mask, io);
            break;
        }

        case CHK_MAT_OPACMAP: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->opacity_map, io);
            break;
        }

        case CHK_MAT_OPACMASK: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->opacity_mask, io);
            break;
        }

        case CHK_MAT_BUMPMAP: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->bump_map, io);
            break;
        }
        case CHK_MAT_BUMPMASK: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->bump_mask, io);
            break;
        }
        case CHK_MAT_SPECMAP: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->specular_map, io);
            break;
        }

        case CHK_MAT_SPECMASK: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->specular_mask, io);
            break;
        }

        case CHK_MAT_SHINMAP: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->shininess_map, io);
            break;
        }

        case CHK_MAT_SHINMASK: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->shininess_mask, io);
            break;
        }

        case CHK_MAT_SELFIMAP: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->self_illum_map, io);
            break;
        }

        case CHK_MAT_SELFIMASK: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->self_illum_mask, io);
            break;
        }

        case CHK_MAT_REFLMAP: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->reflection_map, io);
            break;
        }

        case CHK_MAT_REFLMASK: {
            lib3ds_chunk_read_reset(&c, io);
            texture_map_read(&material->reflection_mask, io);
            break;
        }

        case CHK_MAT_ACUBIC: {
            lib3ds_io_read_intb(io);
            material->autorefl_map_anti_alias = lib3ds_io_read_intb(io);
            material->autorefl_map_flags = lib3ds_io_read_intw(io);
            material->autorefl_map_size = lib3ds_io_read_intd(io);
            material->autorefl_map_frame_step = lib3ds_io_read_intd(io);
            break;
        }

        default:
            lib3ds_chunk_unknown(chunk, io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 2
0
/*!
 * \ingroup material
 */
Lib3dsBool
lib3ds_material_read(Lib3dsMaterial *material, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  ASSERT(material);
  if (!lib3ds_chunk_read_start(&c, LIB3DS_MAT_ENTRY, io)) {
    return(LIB3DS_FALSE);
  }

  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_MAT_NAME:
        {
          if (!lib3ds_io_read_string(io, material->name, 64)) {
            return(LIB3DS_FALSE);
          }
          lib3ds_chunk_dump_info("  NAME=%s", material->name);
        }
        break;
      case LIB3DS_MAT_AMBIENT:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!color_read(material->ambient, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_DIFFUSE:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!color_read(material->diffuse, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SPECULAR:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!color_read(material->specular, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SHININESS:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!int_percentage_read(&material->shininess, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SHIN2PCT:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!int_percentage_read(&material->shin_strength, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_TRANSPARENCY:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!int_percentage_read(&material->transparency, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_XPFALL:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!int_percentage_read(&material->falloff, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SELF_ILPCT:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!int_percentage_read(&material->self_ilpct, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_USE_XPFALL:
        {
          material->use_falloff=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_REFBLUR:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!int_percentage_read(&material->blur, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_USE_REFBLUR:
        {
          material->use_blur=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_SHADING:
        {
          material->shading=lib3ds_io_read_intw(io);
        }
        break;
      case LIB3DS_MAT_SELF_ILLUM:
        {
          material->self_illum=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_TWO_SIDE:
        {
          material->two_sided=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_DECAL:
        {
          material->map_decal=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_ADDITIVE:
        {
          material->additive=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_FACEMAP:
        {
          material->face_map=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_PHONGSOFT:
        {
          material->soften=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_WIRE:
        {
          material->use_wire=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_WIREABS:
        {
          material->use_wire_abs=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_WIRE_SIZE:
        {
          material->wire_size=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_MAT_TEXMAP:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->texture1_map, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_TEXMASK:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->texture1_mask, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_TEX2MAP:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->texture2_map, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_TEX2MASK:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->texture2_mask, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_OPACMAP:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->opacity_map, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_OPACMASK:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->opacity_mask, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_BUMPMAP:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->bump_map, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_BUMPMASK:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->bump_mask, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SPECMAP:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->specular_map, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SPECMASK:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->specular_mask, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SHINMAP:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->shininess_map, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SHINMASK:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->shininess_mask, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SELFIMAP:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->self_illum_map, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SELFIMASK:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->self_illum_mask, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_REFLMAP:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->reflection_map, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_REFLMASK:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!texture_map_read(&material->reflection_mask, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_ACUBIC:
        {
          lib3ds_io_read_intb(io);
          material->autorefl_map.level=lib3ds_io_read_intb(io);
          material->autorefl_map.flags=lib3ds_io_read_intw(io);
          material->autorefl_map.size=lib3ds_io_read_intd(io);
          material->autorefl_map.frame_step=lib3ds_io_read_intd(io);
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }

  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}