Пример #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);
}
Пример #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);
}
Пример #3
0
static Lib3dsBool
kfdata_read(Lib3dsFile *file, FILE *f)
{
    Lib3dsChunk c;
    Lib3dsWord chunk;

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

    while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
        switch (chunk) {
        case LIB3DS_KFHDR:
        {
            file->keyf_revision=lib3ds_word_read(f);
            if (!lib3ds_string_read(file->name, 12+1, f)) {
                return(LIB3DS_FALSE);
            }
            file->frames=lib3ds_intd_read(f);
        }
        break;
        case LIB3DS_KFSEG:
        {
            file->segment_from=lib3ds_intd_read(f);
            file->segment_to=lib3ds_intd_read(f);
        }
        break;
        case LIB3DS_KFCURTIME:
        {
            file->current_frame=lib3ds_intd_read(f);
        }
        break;
        case LIB3DS_VIEWPORT_LAYOUT:
        case LIB3DS_DEFAULT_VIEW:
        {
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_viewport_read(&file->viewport_keyf, f)) {
                return(LIB3DS_FALSE);
            }
        }
        break;
        case LIB3DS_AMBIENT_NODE_TAG:
        {
            Lib3dsNode *node;

            node=lib3ds_node_new_ambient();
            if (!node) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_node_read(node, file, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_node(file, node);
        }
        break;
        case LIB3DS_OBJECT_NODE_TAG:
        {
            Lib3dsNode *node;

            node=lib3ds_node_new_object();
            if (!node) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_node_read(node, file, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_node(file, node);
        }
        break;
        case LIB3DS_CAMERA_NODE_TAG:
        {
            Lib3dsNode *node;

            node=lib3ds_node_new_camera();
            if (!node) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_node_read(node, file, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_node(file, node);
        }
        break;
        case LIB3DS_TARGET_NODE_TAG:
        {
            Lib3dsNode *node;

            node=lib3ds_node_new_target();
            if (!node) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_node_read(node, file, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_node(file, node);
        }
        break;
        case LIB3DS_LIGHT_NODE_TAG:
        case LIB3DS_SPOTLIGHT_NODE_TAG:
        {
            Lib3dsNode *node;

            node=lib3ds_node_new_light();
            if (!node) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_node_read(node, file, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_node(file, node);
        }
        break;
        case LIB3DS_L_TARGET_NODE_TAG:
        {
            Lib3dsNode *node;

            node=lib3ds_node_new_spot();
            if (!node) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_node_read(node, file, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_node(file, node);
        }
        break;
        default:
            lib3ds_chunk_unknown(chunk);
        }
    }

    lib3ds_chunk_read_end(&c, f);
    return(LIB3DS_TRUE);
}
Пример #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);
}
Пример #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);
}