Ejemplo n.º 1
0
/*!
 * \ingroup tcb 
 */
Lib3dsBool
lib3ds_tcb_read(Lib3dsTcb *tcb, FILE *f)
{
  Lib3dsWord flags;
  
  tcb->frame=lib3ds_intd_read(f);
  tcb->flags=flags=lib3ds_word_read(f);
  if (flags&LIB3DS_USE_TENSION) {
    tcb->tens=lib3ds_float_read(f);
  }
  if (flags&LIB3DS_USE_CONTINUITY) {
    tcb->cont=lib3ds_float_read(f);
  }
  if (flags&LIB3DS_USE_BIAS) {
    tcb->bias=lib3ds_float_read(f);
  }
  if (flags&LIB3DS_USE_EASE_TO) {
    tcb->ease_to=lib3ds_float_read(f);
  }
  if (flags&LIB3DS_USE_EASE_FROM) {
    tcb->ease_from=lib3ds_float_read(f);
  }
  if (ferror(f)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
Ejemplo n.º 2
0
/*!
 * \ingroup shadow 
 */
Lib3dsBool
lib3ds_shadow_read(Lib3dsShadow *shadow, FILE *f)
{
  Lib3dsChunk c;

  if (!lib3ds_chunk_read(&c, f)) {
    return(LIB3DS_FALSE);
  }
  
  switch (c.chunk) {
    case LIB3DS_SHADOW_MAP_SIZE:
      {
        shadow->map_size=lib3ds_intw_read(f);
      }
      break;
    case LIB3DS_LO_SHADOW_BIAS:
      {
          shadow->lo_bias=lib3ds_float_read(f);
      }
      break;
    case LIB3DS_HI_SHADOW_BIAS:
      {
        shadow->hi_bias=lib3ds_float_read(f);
      }
      break;
    case LIB3DS_SHADOW_SAMPLES:
      {
        shadow->samples=lib3ds_intw_read(f);
      }
      break;
    case LIB3DS_SHADOW_RANGE:
      {
        shadow->range=lib3ds_intd_read(f);
      }
      break;
    case LIB3DS_SHADOW_FILTER:
      {
        shadow->filter=lib3ds_float_read(f);
      }
      break;
    case LIB3DS_RAY_BIAS:
      {
        shadow->ray_bias=lib3ds_float_read(f);
      }
      break;
  }
  
  return(LIB3DS_TRUE);
}
Ejemplo n.º 3
0
static Lib3dsBool
ambient_read(Lib3dsFile *file, FILE *f)
{
    Lib3dsChunk c;
    Lib3dsWord chunk;
    Lib3dsBool have_lin=LIB3DS_FALSE;

    if (!lib3ds_chunk_read_start(&c, LIB3DS_AMBIENT_LIGHT, f)) {
        return(LIB3DS_FALSE);
    }

    while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
        switch (chunk) {
        case LIB3DS_LIN_COLOR_F:
        {
            int i;
            for (i=0; i<3; ++i) {
                file->ambient[i]=lib3ds_float_read(f);
            }
        }
        have_lin=LIB3DS_TRUE;
        break;
        case LIB3DS_COLOR_F:
        {
            /* gamma corrected color chunk
               replaced in 3ds R3 by LIN_COLOR_24 */
            if (!have_lin) {
                int i;
                for (i=0; i<3; ++i) {
                    file->ambient[i]=lib3ds_float_read(f);
                }
            }
        }
        break;
        default:
            lib3ds_chunk_unknown(chunk);
        }
    }

    lib3ds_chunk_read_end(&c, f);
    return(LIB3DS_TRUE);
}
Ejemplo n.º 4
0
static Lib3dsBool
mdata_read(Lib3dsFile *file, FILE *f)
{
    Lib3dsChunk c;
    Lib3dsWord chunk;

    if (!lib3ds_chunk_read_start(&c, LIB3DS_MDATA, f)) {
        return(LIB3DS_FALSE);
    }

    while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
        switch (chunk) {
        case LIB3DS_MESH_VERSION:
        {
            file->mesh_version=lib3ds_intd_read(f);
        }
        break;
        case LIB3DS_MASTER_SCALE:
        {
            file->master_scale=lib3ds_float_read(f);
        }
        break;
        case LIB3DS_SHADOW_MAP_SIZE:
        case LIB3DS_LO_SHADOW_BIAS:
        case LIB3DS_HI_SHADOW_BIAS:
        case LIB3DS_SHADOW_SAMPLES:
        case LIB3DS_SHADOW_RANGE:
        case LIB3DS_SHADOW_FILTER:
        case LIB3DS_RAY_BIAS:
        {
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_shadow_read(&file->shadow, f)) {
                return(LIB3DS_FALSE);
            }
        }
        break;
        case LIB3DS_VIEWPORT_LAYOUT:
        case LIB3DS_DEFAULT_VIEW:
        {
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_viewport_read(&file->viewport, f)) {
                return(LIB3DS_FALSE);
            }
        }
        break;
        case LIB3DS_O_CONSTS:
        {
            int i;
            for (i=0; i<3; ++i) {
                file->construction_plane[i]=lib3ds_float_read(f);
            }
        }
        break;
        case LIB3DS_AMBIENT_LIGHT:
        {
            lib3ds_chunk_read_reset(&c, f);
            if (!ambient_read(file, f)) {
                return(LIB3DS_FALSE);
            }
        }
        break;
        case LIB3DS_BIT_MAP:
        case LIB3DS_SOLID_BGND:
        case LIB3DS_V_GRADIENT:
        case LIB3DS_USE_BIT_MAP:
        case LIB3DS_USE_SOLID_BGND:
        case LIB3DS_USE_V_GRADIENT:
        {
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_background_read(&file->background, f)) {
                return(LIB3DS_FALSE);
            }
        }
        break;
        case LIB3DS_FOG:
        case LIB3DS_LAYER_FOG:
        case LIB3DS_DISTANCE_CUE:
        case LIB3DS_USE_FOG:
        case LIB3DS_USE_LAYER_FOG:
        case LIB3DS_USE_DISTANCE_CUE:
        {
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_atmosphere_read(&file->atmosphere, f)) {
                return(LIB3DS_FALSE);
            }
        }
        break;
        case LIB3DS_MAT_ENTRY:
        {
            Lib3dsMaterial *material;

            material=lib3ds_material_new();
            if (!material) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_material_read(material, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_material(file, material);
        }
        break;
        case LIB3DS_NAMED_OBJECT:
        {
            lib3ds_chunk_read_reset(&c, f);
            if (!named_object_read(file, f)) {
                return(LIB3DS_FALSE);
            }
        }
        break;
        default:
            lib3ds_chunk_unknown(chunk);
        }
    }

    lib3ds_chunk_read_end(&c, f);
    return(LIB3DS_TRUE);
}
Ejemplo n.º 5
0
/*!
 * \ingroup material
 */
Lib3dsBool
lib3ds_material_read(Lib3dsMaterial *material, FILE *f)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

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

  while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
    switch (chunk) {
      case LIB3DS_MAT_NAME:
        {
          if (!lib3ds_string_read(material->name, 64, f)) {
            return(LIB3DS_FALSE);
          }
          lib3ds_chunk_dump_info("  NAME=%s", material->name);
        }
        break;
      case LIB3DS_MAT_AMBIENT:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!color_read(material->ambient, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_DIFFUSE:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!color_read(material->diffuse, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SPECULAR:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!color_read(material->specular, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SHININESS:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!int_percentage_read(&material->shininess, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SHIN2PCT:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!int_percentage_read(&material->shin_strength, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_TRANSPARENCY:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!int_percentage_read(&material->transparency, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_XPFALL:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!int_percentage_read(&material->falloff, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_USE_XPFALL:
        {
          material->use_falloff=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_REFBLUR:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!int_percentage_read(&material->blur, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_USE_REFBLUR:
        {
          material->use_blur=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_MAT_SHADING:
        {
          material->shading=lib3ds_intw_read(f);
        }
        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_float_read(f);
        }
        break;
      case LIB3DS_MAT_TEXMAP:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->texture1_map, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_TEXMASK:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->texture1_mask, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_TEX2MAP:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->texture2_map, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_TEX2MASK:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->texture2_mask, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_OPACMAP:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->opacity_map, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_OPACMASK:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->opacity_mask, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_BUMPMAP:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->bump_map, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_BUMPMASK:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->bump_mask, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SPECMAP:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->specular_map, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SPECMASK:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->specular_mask, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SHINMAP:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->shininess_map, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SHINMASK:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->shininess_mask, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SELFIMAP:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->self_illum_map, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_SELFIMASK:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->self_illum_mask, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_REFLMAP:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->reflection_map, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_REFLMASK:
        {
          lib3ds_chunk_read_reset(&c, f);
          if (!texture_map_read(&material->reflection_mask, f)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_ACUBIC:
        {
          lib3ds_intb_read(f);
          material->autorefl_map.level=lib3ds_intb_read(f);
          material->autorefl_map.flags=lib3ds_intw_read(f);
          material->autorefl_map.size=lib3ds_intd_read(f);
          material->autorefl_map.frame_step=lib3ds_intd_read(f);
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }

  lib3ds_chunk_read_end(&c, f);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 6
0
static Lib3dsBool
texture_map_read(Lib3dsTextureMap *map, FILE *f)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  if (!lib3ds_chunk_read_start(&c, 0, f)) {
    return(LIB3DS_FALSE);
  }

  while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
    switch (chunk) {
      case LIB3DS_INT_PERCENTAGE:
        {
          map->percent=1.0f*lib3ds_intw_read(f)/100.0f;
        }
        break;
      case LIB3DS_MAT_MAPNAME:
        {
          if (!lib3ds_string_read(map->name, 64, f)) {
            return(LIB3DS_FALSE);
          }
          lib3ds_chunk_dump_info("  NAME=%s", map->name);
        }
        break;
      case LIB3DS_MAT_MAP_TILING:
        {
          map->flags=lib3ds_word_read(f);
        }
        break;
      case LIB3DS_MAT_MAP_TEXBLUR:
        {
          map->blur=lib3ds_float_read(f);
        }
        break;
      case LIB3DS_MAT_MAP_USCALE:
        {
          map->scale[0]=lib3ds_float_read(f);
        }
        break;
      case LIB3DS_MAT_MAP_VSCALE:
        {
          map->scale[1]=lib3ds_float_read(f);
        }
        break;
      case LIB3DS_MAT_MAP_UOFFSET:
        {
          map->offset[0]=lib3ds_float_read(f);
        }
        break;
      case LIB3DS_MAT_MAP_VOFFSET:
        {
          map->offset[1]=lib3ds_float_read(f);
        }
        break;
      case LIB3DS_MAT_MAP_ANG:
        {
          map->rotation=lib3ds_float_read(f);
        }
        break;
      case LIB3DS_MAT_MAP_COL1:
        {
          map->tint_1[0]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_1[1]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_1[2]=1.0f*lib3ds_byte_read(f)/255.0f;
        }
        break;
      case LIB3DS_MAT_MAP_COL2:
        {
          map->tint_2[0]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_2[1]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_2[2]=1.0f*lib3ds_byte_read(f)/255.0f;
        }
        break;
      case LIB3DS_MAT_MAP_RCOL:
        {
          map->tint_r[0]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_r[1]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_r[2]=1.0f*lib3ds_byte_read(f)/255.0f;
        }
        break;
      case LIB3DS_MAT_MAP_GCOL:
        {
          map->tint_g[0]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_g[1]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_g[2]=1.0f*lib3ds_byte_read(f)/255.0f;
        }
        break;
      case LIB3DS_MAT_MAP_BCOL:
        {
          map->tint_b[0]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_b[1]=1.0f*lib3ds_byte_read(f)/255.0f;
          map->tint_b[2]=1.0f*lib3ds_byte_read(f)/255.0f;
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, f);
  return(LIB3DS_TRUE);
}