Ejemplo n.º 1
0
/*!
 * \ingroup tracks
 */
Lib3dsBool
lib3ds_morph_track_read(Lib3dsMorphTrack *track, Lib3dsIo *io)
{
  /* This function was written by Stephane Denis on 5-18-04 */
    int i;
    Lib3dsMorphKey *k = 0;
    Lib3dsMorphKey *pk = 0;
    int keys;
    track->flags=lib3ds_io_read_word(io);
    lib3ds_io_read_dword(io);
    lib3ds_io_read_dword(io);
    keys=lib3ds_io_read_intd(io);

    for (i=0; i<keys; ++i) {
        k=lib3ds_morph_key_new();
        if (!lib3ds_tcb_read(&k->tcb, io)) {
            return(LIB3DS_FALSE);
        }
        if (!lib3ds_io_read_string(io, k->name, 11)) {
            return(LIB3DS_FALSE);
        }
        if (!track->keyL)
            track->keyL = k;
        else
            pk->next = k;
        pk = k;
    }
  return(LIB3DS_TRUE);
}
Ejemplo n.º 2
0
/*!
 * \ingroup tracks 
 */
Lib3dsBool
lib3ds_lin3_track_read(Lib3dsLin3Track *track, Lib3dsIo *io)
{
  int keys;
  int i,j;
  Lib3dsLin3Key *k;

  track->flags=lib3ds_io_read_word(io);
  lib3ds_io_read_dword(io);
  lib3ds_io_read_dword(io);
  keys=lib3ds_io_read_intd(io);

  for (i=0; i<keys; ++i) {
    k=lib3ds_lin3_key_new();
    if (!lib3ds_tcb_read(&k->tcb, io)) {
      return(LIB3DS_FALSE);
    }
    for (j=0; j<3; ++j) {
      k->value[j]=lib3ds_io_read_float(io);
    }
    lib3ds_lin3_track_insert(track, k);
  }
  lib3ds_lin3_track_setup(track);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 3
0
/*!
 * \ingroup tracks 
 */
Lib3dsBool
lib3ds_quat_track_read(Lib3dsQuatTrack *track, Lib3dsIo *io)
{
  int keys;
  int i,j;
  Lib3dsQuatKey *p,*k;

  track->flags=lib3ds_io_read_word(io);
  lib3ds_io_read_dword(io);
  lib3ds_io_read_dword(io);
  keys=lib3ds_io_read_intd(io);

  for (p=0,i=0; i<keys; p=k,++i) {
    k=lib3ds_quat_key_new();
    if (!lib3ds_tcb_read(&k->tcb, io)) {
      return(LIB3DS_FALSE);
    }
    k->angle=lib3ds_io_read_float(io);
    for (j=0; j<3; ++j) {
      k->axis[j]=lib3ds_io_read_float(io);
    }
    lib3ds_quat_track_insert(track, k);
  }
  lib3ds_quat_track_setup(track);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 4
0
void 
lib3ds_track_read(Lib3dsTrack *track, Lib3dsIo *io) {
    unsigned nkeys;
    unsigned i;

    track->flags = lib3ds_io_read_word(io);
    lib3ds_io_read_dword(io);
    lib3ds_io_read_dword(io);
    nkeys = lib3ds_io_read_intd(io);
    lib3ds_track_resize(track, nkeys);

    switch (track->type) {
        case LIB3DS_TRACK_BOOL:
            for (i = 0; i < nkeys; ++i) {
                track->keys[i].frame = lib3ds_io_read_intd(io);
                tcb_read(&track->keys[i], io);
            }
            break;

        case LIB3DS_TRACK_FLOAT:
            for (i = 0; i < nkeys; ++i) {
                track->keys[i].frame = lib3ds_io_read_intd(io);
                tcb_read(&track->keys[i], io);
                track->keys[i].value[0] = lib3ds_io_read_float(io);
            }
            break;

        case LIB3DS_TRACK_VECTOR:
            for (i = 0; i < nkeys; ++i) {
                track->keys[i].frame = lib3ds_io_read_intd(io);
                tcb_read(&track->keys[i], io);
                lib3ds_io_read_vector(io, track->keys[i].value);
            }
            break;

        case LIB3DS_TRACK_QUAT:
            for (i = 0; i < nkeys; ++i) {
                track->keys[i].frame = lib3ds_io_read_intd(io);
                tcb_read(&track->keys[i], io);
                track->keys[i].value[3] = lib3ds_io_read_float(io);
                lib3ds_io_read_vector(io, track->keys[i].value);
            }
            break;

        /*case LIB3DS_TRACK_MORPH:
            for (i = 0; i < nkeys; ++i) {
                track->keys[i].frame = lib3ds_io_read_intd(io);
                tcb_read(&track->keys[i].tcb, io);
                lib3ds_io_read_string(io, track->keys[i].data.m.name, 64);
            }
            break;*/

        default:
            break;
    }
}
Ejemplo n.º 5
0
static Lib3dsBool
layer_fog_read(Lib3dsLayerFog *fog, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;
  Lib3dsBool have_lin=LIB3DS_FALSE;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, io)) {
    return(LIB3DS_FALSE);
  }
  fog->near_y=lib3ds_io_read_float(io);
  fog->far_y=lib3ds_io_read_float(io);
  fog->density=lib3ds_io_read_float(io);
  fog->flags=lib3ds_io_read_dword(io);
  lib3ds_chunk_read_tell(&c, io);
  
  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_LIN_COLOR_F:
        lib3ds_io_read_rgb(io, fog->col);
        have_lin=LIB3DS_TRUE;
        break;
      case LIB3DS_COLOR_F:
        lib3ds_io_read_rgb(io, fog->col);
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
static void
layer_fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io)
{
    Lib3dsChunk c;
    uint16_t    chunk;
    int         have_lin = FALSE;

    lib3ds_chunk_read_start(&c, CHK_LAYER_FOG, io);

    at->layer_fog_near_y  = lib3ds_io_read_float(io);
    at->layer_fog_far_y   = lib3ds_io_read_float(io);
    at->layer_fog_density = lib3ds_io_read_float(io);
    at->layer_fog_flags   = lib3ds_io_read_dword(io);
    lib3ds_chunk_read_tell(&c, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0)
    {
        switch (chunk)
        {
        case CHK_LIN_COLOR_F:
            lib3ds_io_read_rgb(io, at->layer_fog_color);
            have_lin = TRUE;
            break;

        case CHK_COLOR_F:
            lib3ds_io_read_rgb(io, at->layer_fog_color);
            break;

        default:
            lib3ds_chunk_unknown(chunk, io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 7
0
/*!
 * Read 3ds file data into a Lib3dsFile object.
 *
 * \param file The Lib3dsFile object to be filled.
 * \param io A Lib3dsIo object previously set up by the caller.
 *
 * \return LIB3DS_TRUE on success, LIB3DS_FALSE on failure.
 *
 * \ingroup file
 */
Lib3dsBool
lib3ds_file_read(Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  if (!lib3ds_chunk_read_start(&c, 0, io)) {
    return(LIB3DS_FALSE);
  }
  switch (c.chunk) {
    case LIB3DS_MDATA:
      {
        lib3ds_chunk_read_reset(&c, io);
        if (!mdata_read(file, io)) {
          return(LIB3DS_FALSE);
        }
      }
      break;
    case LIB3DS_M3DMAGIC:
    case LIB3DS_MLIBMAGIC:
    case LIB3DS_CMAGIC:
      {
        while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
          switch (chunk) {
            case LIB3DS_M3D_VERSION:
              {
                file->mesh_version=lib3ds_io_read_dword(io);
              }
              break;
            case LIB3DS_MDATA:
              {
                lib3ds_chunk_read_reset(&c, io);
                if (!mdata_read(file, io)) {
                  return(LIB3DS_FALSE);
                }
              }
              break;
            case LIB3DS_KFDATA:
              {
                lib3ds_chunk_read_reset(&c, io);
                if (!kfdata_read(file, io)) {
                  return(LIB3DS_FALSE);
                }
              }
              break;
            default:
              lib3ds_chunk_unknown(chunk);
          }
        }
      }
      break;
    default:
      lib3ds_chunk_unknown(c.chunk);
      return(LIB3DS_FALSE);
  }

  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 8
0
/*!
 * \ingroup tracks 
 */
Lib3dsBool
lib3ds_bool_track_read(Lib3dsBoolTrack *track, Lib3dsIo *io)
{
  int keys;
  int i;
  Lib3dsBoolKey *k;

  track->flags=lib3ds_io_read_word(io);
  lib3ds_io_read_dword(io);
  lib3ds_io_read_dword(io);
  keys=lib3ds_io_read_intd(io);

  for (i=0; i<keys; ++i) {
    k=lib3ds_bool_key_new();
    if (!lib3ds_tcb_read(&k->tcb, io)) {
      return(LIB3DS_FALSE);
    }
    lib3ds_bool_track_insert(track, k);
  }
  
  return(LIB3DS_TRUE);
}
Ejemplo n.º 9
0
/*!
 * Reads a 3d-Studio chunk header from a little endian file stream.
 *
 * \param c  The chunk to store the data.
 * \param io The file stream.
 *
 * \return   True on success, False otherwise.
 */
void
lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io) {
    assert(c);
    assert(io);
    c->cur = lib3ds_io_tell(io);
    c->chunk = lib3ds_io_read_word(io);
    c->size = lib3ds_io_read_dword(io);
    c->end = c->cur + c->size;
    c->cur += 6;
    if (c->size < 6) {
        lib3ds_io_log(io, LIB3DS_LOG_ERROR, "Invalid chunk header.");
    }

}
Ejemplo n.º 10
0
/*!
 * \ingroup chunk
 *
 * Reads a 3d-Studio chunk header from a little endian file stream.
 *
 * \param c  The chunk to store the data.
 * \param io The file stream.
 *
 * \return   True on success, False otherwise.
 */
Lib3dsBool
lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io)
{
  ASSERT(c);
  ASSERT(io);
  c->cur=lib3ds_io_tell(io);
  c->chunk=lib3ds_io_read_word(io);
  c->size=lib3ds_io_read_dword(io);
  c->end=c->cur+c->size;
  c->cur+=6;
  if (lib3ds_io_error(io) || (c->size<6)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
  
}
Ejemplo n.º 11
0
/*!
 * \ingroup chunk
 */
Lib3dsWord
lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
{
  Lib3dsChunk d;

  if (c->cur>=c->end) {
    ASSERT(c->cur==c->end);
    return(0);
  }

  lib3ds_io_seek(io, (long)c->cur, LIB3DS_SEEK_SET);
  d.chunk=lib3ds_io_read_word(io);
  d.size=lib3ds_io_read_dword(io);
  lib3ds_chunk_debug_dump(&d);
  c->cur+=d.size;
  return(d.chunk);
}
Ejemplo n.º 12
0
uint16_t
lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io) {
    Lib3dsChunk d;

    if (c->cur >= c->end) {
        assert(c->cur == c->end);
        return 0;
    }

    lib3ds_io_seek(io, (long)c->cur, LIB3DS_SEEK_SET);
    d.chunk = lib3ds_io_read_word(io);
    d.size = lib3ds_io_read_dword(io);
    c->cur += d.size;

    if (io->log_func) {
        lib3ds_io_log(io, LIB3DS_LOG_INFO, "%s (0x%X) size=%lu", lib3ds_chunk_name(d.chunk), d.chunk, d.size);
    }

    return d.chunk;
}
Ejemplo n.º 13
0
static void
face_array_read(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;
    int i;
    uint16_t nfaces;

    lib3ds_chunk_read_start(&c, CHK_FACE_ARRAY, io);

    lib3ds_mesh_resize_faces(mesh, 0);
    nfaces = lib3ds_io_read_word(io);
    if (nfaces) {
        lib3ds_mesh_resize_faces(mesh, nfaces);
        for (i = 0; i < nfaces; ++i) {
            mesh->faces[i].index[0] = lib3ds_io_read_word(io);
            mesh->faces[i].index[1] = lib3ds_io_read_word(io);
            mesh->faces[i].index[2] = lib3ds_io_read_word(io);
            mesh->faces[i].flags = lib3ds_io_read_word(io);
        }
        lib3ds_chunk_read_tell(&c, io);

        while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
            switch (chunk) {
                case CHK_MSH_MAT_GROUP: {
                    char name[64];
                    unsigned n;
                    unsigned i;
                    int index;
                    int material;

                    lib3ds_io_read_string(io, name, 64);
                    material = lib3ds_file_material_by_name(file, name);

                    n = lib3ds_io_read_word(io);
                    for (i = 0; i < n; ++i) {
                        index = lib3ds_io_read_word(io);
                        if (index < mesh->nfaces) {
                            mesh->faces[index].material = material;
                        } else {
                            // TODO warning
                        }
                    }
                    break;
                }

                case CHK_SMOOTH_GROUP: {
                    int i;
                    for (i = 0; i < mesh->nfaces; ++i) {
                        mesh->faces[i].smoothing_group = lib3ds_io_read_dword(io);
                    }
                    break;
                }

                case CHK_MSH_BOXMAP: {
                    lib3ds_io_read_string(io, mesh->box_front, 64);
                    lib3ds_io_read_string(io, mesh->box_back, 64);
                    lib3ds_io_read_string(io, mesh->box_left, 64);
                    lib3ds_io_read_string(io, mesh->box_right, 64);
                    lib3ds_io_read_string(io, mesh->box_top, 64);
                    lib3ds_io_read_string(io, mesh->box_bottom, 64);
                    break;
                }

                default:
                    lib3ds_chunk_unknown(chunk,io);
            }
        }

    }
    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 14
0
static Lib3dsBool
face_array_read(Lib3dsMesh *mesh, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;
  int i;
  int faces;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_FACE_ARRAY, io)) {
    return(LIB3DS_FALSE);
  }
  lib3ds_mesh_free_face_list(mesh);
  
  faces=lib3ds_io_read_word(io);
  if (faces) {
    if (!lib3ds_mesh_new_face_list(mesh, faces)) {
      LIB3DS_ERROR_LOG;
      return(LIB3DS_FALSE);
    }
    for (i=0; i<faces; ++i) {
      strcpy(mesh->faceL[i].material, "");
      mesh->faceL[i].points[0]=lib3ds_io_read_word(io);
      mesh->faceL[i].points[1]=lib3ds_io_read_word(io);
      mesh->faceL[i].points[2]=lib3ds_io_read_word(io);
      mesh->faceL[i].flags=lib3ds_io_read_word(io);
    }
    lib3ds_chunk_read_tell(&c, io);

    while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
      switch (chunk) {
        case LIB3DS_SMOOTH_GROUP:
          {
            unsigned i;

            for (i=0; i<mesh->faces; ++i) {
              mesh->faceL[i].smoothing=lib3ds_io_read_dword(io);
            }
          }
          break;
        case LIB3DS_MSH_MAT_GROUP:
          {
            char name[64];
            unsigned faces;
            unsigned i;
            unsigned index;

            if (!lib3ds_io_read_string(io, name, 64)) {
              return(LIB3DS_FALSE);
            }
            faces=lib3ds_io_read_word(io);
            for (i=0; i<faces; ++i) {
              index=lib3ds_io_read_word(io);
              ASSERT(index<mesh->faces);
              strcpy(mesh->faceL[index].material, name);
            }
          }
          break;
        case LIB3DS_MSH_BOXMAP:
          {
            char name[64];

            if (!lib3ds_io_read_string(io, name, 64)) {
              return(LIB3DS_FALSE);
            }
            strcpy(mesh->box_map.front, name);
            if (!lib3ds_io_read_string(io, name, 64)) {
              return(LIB3DS_FALSE);
            }
            strcpy(mesh->box_map.back, name);
            if (!lib3ds_io_read_string(io, name, 64)) {
              return(LIB3DS_FALSE);
            }
            strcpy(mesh->box_map.left, name);
            if (!lib3ds_io_read_string(io, name, 64)) {
              return(LIB3DS_FALSE);
            }
            strcpy(mesh->box_map.right, name);
            if (!lib3ds_io_read_string(io, name, 64)) {
              return(LIB3DS_FALSE);
            }
            strcpy(mesh->box_map.top, name);
            if (!lib3ds_io_read_string(io, name, 64)) {
              return(LIB3DS_FALSE);
            }
            strcpy(mesh->box_map.bottom, name);
          }
          break;
        default:
          lib3ds_chunk_unknown(chunk);
      }
    }
    
  }
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 15
0
/*!
 * Read 3ds file data into a Lib3dsFile object.
 *
 * \param file The Lib3dsFile object to be filled.
 * \param io A Lib3dsIo object previously set up by the caller.
 *
 * \return LIB3DS_TRUE on success, LIB3DS_FALSE on failure.
 */
int
lib3ds_file_read(Lib3dsFile *file, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;
    Lib3dsIoImpl *impl;

    lib3ds_io_setup(io);
    impl = (Lib3dsIoImpl*)io->impl;

    if (setjmp(impl->jmpbuf) != 0) {
        lib3ds_io_cleanup(io);
        return FALSE;
    }

    lib3ds_chunk_read_start(&c, 0, io);
    switch (c.chunk) {
        case CHK_MDATA: {
            lib3ds_chunk_read_reset(&c, io);
            mdata_read(file, io);
            break;
        }

        case CHK_M3DMAGIC:
        case CHK_MLIBMAGIC:
        case CHK_CMAGIC: {
            while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
                switch (chunk) {
                    case CHK_M3D_VERSION: {
                        file->mesh_version = lib3ds_io_read_dword(io);
                        break;
                    }

                    case CHK_MDATA: {
                        lib3ds_chunk_read_reset(&c, io);
                        mdata_read(file, io);
                        break;
                    }

                    case CHK_KFDATA: {
                        lib3ds_chunk_read_reset(&c, io);
                        kfdata_read(file, io);
                        break;
                    }

                    default:
                        lib3ds_chunk_unknown(chunk, io);
                }
            }
            break;
        }

        default:
            lib3ds_chunk_unknown(c.chunk, io);
            return FALSE;
    }

    lib3ds_chunk_read_end(&c, io);

    memset(impl->jmpbuf, 0, sizeof(impl->jmpbuf));
    lib3ds_io_cleanup(io);
    return TRUE;
}