예제 #1
0
파일: tcb.c 프로젝트: MTolba/mrpt
/*!
 * \ingroup tcb
 */
Lib3dsBool
lib3ds_tcb_read(Lib3dsTcb *tcb, Lib3dsIo *io)
{
    Lib3dsWord flags;

    tcb->frame=lib3ds_io_read_intd(io);
    tcb->flags=flags=lib3ds_io_read_word(io);
    if (flags&LIB3DS_USE_TENSION) {
        tcb->tens=lib3ds_io_read_float(io);
    }
    if (flags&LIB3DS_USE_CONTINUITY) {
        tcb->cont=lib3ds_io_read_float(io);
    }
    if (flags&LIB3DS_USE_BIAS) {
        tcb->bias=lib3ds_io_read_float(io);
    }
    if (flags&LIB3DS_USE_EASE_TO) {
        tcb->ease_to=lib3ds_io_read_float(io);
    }
    if (flags&LIB3DS_USE_EASE_FROM) {
        tcb->ease_from=lib3ds_io_read_float(io);
    }
    if (lib3ds_io_error(io)) {
        return(LIB3DS_FALSE);
    }
    return(LIB3DS_TRUE);
}
예제 #2
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);
}
예제 #3
0
파일: tracks.c 프로젝트: refnum/quesa
/*!
 * \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);
}
예제 #4
0
파일: tracks.c 프로젝트: refnum/quesa
/*!
 * \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);
}
예제 #5
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;
    }
}
예제 #6
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.");
    }

}
예제 #7
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);
  
}
예제 #8
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);
}
예제 #9
0
static void 
tcb_read(Lib3dsKey *key, Lib3dsIo *io) {
    key->flags = lib3ds_io_read_word(io);
    if (key->flags & LIB3DS_KEY_USE_TENS) {
        key->tens = lib3ds_io_read_float(io);
    }
    if (key->flags & LIB3DS_KEY_USE_CONT) {
        key->cont = lib3ds_io_read_float(io);
    }
    if (key->flags & LIB3DS_KEY_USE_BIAS) {
        key->bias = lib3ds_io_read_float(io);
    }
    if (key->flags & LIB3DS_KEY_USE_EASE_TO) {
        key->ease_to = lib3ds_io_read_float(io);
    }
    if (key->flags & LIB3DS_KEY_USE_EASE_FROM) {
        key->ease_from = lib3ds_io_read_float(io);
    }
}
예제 #10
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;
}
예제 #11
0
파일: tracks.c 프로젝트: refnum/quesa
/*!
 * \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);
}
예제 #12
0
/*!
 * \ingroup mesh
 */
Lib3dsBool
lib3ds_mesh_read(Lib3dsMesh *mesh, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_N_TRI_OBJECT, io)) {
    return(LIB3DS_FALSE);
  }

  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_MESH_MATRIX:
        {
          int i,j;
          
          lib3ds_matrix_identity(mesh->matrix);
          for (i=0; i<4; i++) {
            for (j=0; j<3; j++) {
              mesh->matrix[i][j]=lib3ds_io_read_float(io);
            }
          }
        }
        break;
      case LIB3DS_MESH_COLOR:
        {
          mesh->color=lib3ds_io_read_byte(io);
        }
        break;
      case LIB3DS_POINT_ARRAY:
        {
          unsigned i,j;
          unsigned points;
          
          lib3ds_mesh_free_point_list(mesh);
          points=lib3ds_io_read_word(io);
          if (points) {
            if (!lib3ds_mesh_new_point_list(mesh, points)) {
              LIB3DS_ERROR_LOG;
              return(LIB3DS_FALSE);
            }
            for (i=0; i<mesh->points; ++i) {
              for (j=0; j<3; ++j) {
                mesh->pointL[i].pos[j]=lib3ds_io_read_float(io);
              }
            }
            ASSERT((!mesh->flags) || (mesh->points==mesh->flags));
            ASSERT((!mesh->texels) || (mesh->points==mesh->texels));
          }
        }
        break;
      case LIB3DS_POINT_FLAG_ARRAY:
        {
          unsigned i;
          unsigned flags;
          
          lib3ds_mesh_free_flag_list(mesh);
          flags=lib3ds_io_read_word(io);
          if (flags) {
            if (!lib3ds_mesh_new_flag_list(mesh, flags)) {
              LIB3DS_ERROR_LOG;
              return(LIB3DS_FALSE);
            }
            for (i=0; i<mesh->flags; ++i) {
              mesh->flagL[i]=lib3ds_io_read_word(io);
            }
            ASSERT((!mesh->points) || (mesh->flags==mesh->points));
            ASSERT((!mesh->texels) || (mesh->flags==mesh->texels));
          }
        }
        break;
      case LIB3DS_FACE_ARRAY:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!face_array_read(mesh, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MESH_TEXTURE_INFO:
        {
          int i,j;

          for (i=0; i<2; ++i) {
            mesh->map_data.tile[i]=lib3ds_io_read_float(io);
          }
          for (i=0; i<3; ++i) {
            mesh->map_data.pos[i]=lib3ds_io_read_float(io);
          }
          mesh->map_data.scale=lib3ds_io_read_float(io);

          lib3ds_matrix_identity(mesh->map_data.matrix);
          for (i=0; i<4; i++) {
            for (j=0; j<3; j++) {
              mesh->map_data.matrix[i][j]=lib3ds_io_read_float(io);
            }
          }
          for (i=0; i<2; ++i) {
            mesh->map_data.planar_size[i]=lib3ds_io_read_float(io);
          }
          mesh->map_data.cylinder_height=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_TEX_VERTS:
        {
          unsigned i;
          unsigned texels;
          
          lib3ds_mesh_free_texel_list(mesh);
          texels=lib3ds_io_read_word(io);
          if (texels) {
            if (!lib3ds_mesh_new_texel_list(mesh, texels)) {
              LIB3DS_ERROR_LOG;
              return(LIB3DS_FALSE);
            }
            for (i=0; i<mesh->texels; ++i) {
              mesh->texelL[i][0]=lib3ds_io_read_float(io);
              mesh->texelL[i][1]=lib3ds_io_read_float(io);
            }
            ASSERT((!mesh->points) || (mesh->texels==mesh->points));
            ASSERT((!mesh->flags) || (mesh->texels==mesh->flags));
          }
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  {
    unsigned j;

    for (j=0; j<mesh->faces; ++j) {
      ASSERT(mesh->faceL[j].points[0]<mesh->points);
      ASSERT(mesh->faceL[j].points[1]<mesh->points);
      ASSERT(mesh->faceL[j].points[2]<mesh->points);
      lib3ds_vector_normal(
        mesh->faceL[j].normal,
        mesh->pointL[mesh->faceL[j].points[0]].pos,
        mesh->pointL[mesh->faceL[j].points[1]].pos,
        mesh->pointL[mesh->faceL[j].points[2]].pos
      );
    }
  }

  if (lib3ds_matrix_det(mesh->matrix) < 0.0)
  {
    /* Flip X coordinate of vertices if mesh matrix 
       has negative determinant */
    Lib3dsMatrix inv_matrix, M;
    Lib3dsVector tmp;
    unsigned i;

    lib3ds_matrix_copy(inv_matrix, mesh->matrix);
    lib3ds_matrix_inv(inv_matrix);

    lib3ds_matrix_copy(M, mesh->matrix);
    lib3ds_matrix_scale_xyz(M, -1.0f, 1.0f, 1.0f);
    lib3ds_matrix_mult(M, inv_matrix);

    for (i=0; i<mesh->points; ++i) {
      lib3ds_vector_transform(tmp, M, mesh->pointL[i].pos);
      lib3ds_vector_copy(mesh->pointL[i].pos, tmp);
    }
  }

  lib3ds_chunk_read_end(&c, io);

  return(LIB3DS_TRUE);
}
예제 #13
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);
}
예제 #14
0
static void
texture_map_read(Lib3dsTextureMap *map, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;

    lib3ds_chunk_read_start(&c, 0, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
        case CHK_INT_PERCENTAGE: {
            map->percent = 1.0f * lib3ds_io_read_intw(io) / 100.0f;
            break;
        }

        case CHK_MAT_MAPNAME: {
            lib3ds_io_read_string(io, map->name, 64);
            lib3ds_io_log(io, LIB3DS_LOG_INFO, "  NAME=%s", map->name);
            break;
        }

        case CHK_MAT_MAP_TILING: {
            map->flags = lib3ds_io_read_word(io);
            break;
        }

        case CHK_MAT_MAP_TEXBLUR:
            map->blur = lib3ds_io_read_float(io);
            break;

        case CHK_MAT_MAP_USCALE:
            map->scale[0] = lib3ds_io_read_float(io);
            break;

        case CHK_MAT_MAP_VSCALE: {
            map->scale[1] = lib3ds_io_read_float(io);
            break;
        }
        case CHK_MAT_MAP_UOFFSET: {
            map->offset[0] = lib3ds_io_read_float(io);
            break;
        }

        case CHK_MAT_MAP_VOFFSET: {
            map->offset[1] = lib3ds_io_read_float(io);
            break;
        }

        case CHK_MAT_MAP_ANG: {
            map->rotation = lib3ds_io_read_float(io);
            break;
        }

        case CHK_MAT_MAP_COL1: {
            map->tint_1[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_1[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_1[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            break;
        }

        case CHK_MAT_MAP_COL2: {
            map->tint_2[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_2[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_2[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            break;
        }

        case CHK_MAT_MAP_RCOL: {
            map->tint_r[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_r[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_r[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            break;
        }

        case CHK_MAT_MAP_GCOL: {
            map->tint_g[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_g[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_g[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            break;
        }

        case CHK_MAT_MAP_BCOL: {
            map->tint_b[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_b[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            map->tint_b[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
            break;
        }

        default:
            lib3ds_chunk_unknown(chunk,io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
예제 #15
0
파일: node.c 프로젝트: GYengera/mrpt
/*!
 * \ingroup node
 */
Lib3dsBool
lib3ds_node_read(Lib3dsNode *node, Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  ASSERT(node);
  if (!lib3ds_chunk_read_start(&c, 0, io)) {
    return(LIB3DS_FALSE);
  }
  switch (c.chunk) {
    case LIB3DS_AMBIENT_NODE_TAG:
    case LIB3DS_OBJECT_NODE_TAG:
    case LIB3DS_CAMERA_NODE_TAG:
    case LIB3DS_TARGET_NODE_TAG:
    case LIB3DS_LIGHT_NODE_TAG:
    case LIB3DS_SPOTLIGHT_NODE_TAG:
    case LIB3DS_L_TARGET_NODE_TAG:
      break;
    default:
      return(LIB3DS_FALSE);
  }

  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_NODE_ID:
        {
          node->node_id=lib3ds_io_read_word(io);
          lib3ds_chunk_dump_info("  ID = %d", (short)node->node_id);
        }
        break;
      case LIB3DS_NODE_HDR:
        {
          if (!lib3ds_io_read_string(io, node->name, 64)) {
            return(LIB3DS_FALSE);
          }
          node->flags1=lib3ds_io_read_word(io);
          node->flags2=lib3ds_io_read_word(io);
          node->parent_id=lib3ds_io_read_word(io);
          lib3ds_chunk_dump_info("  NAME =%s", node->name);
          lib3ds_chunk_dump_info("  PARENT=%d", (short)node->parent_id);
        }
        break;
      case LIB3DS_PIVOT:
        {
          if (node->type==LIB3DS_OBJECT_NODE) {
            int i;
            for (i=0; i<3; ++i) {
              node->data.object.pivot[i]=lib3ds_io_read_float(io);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_INSTANCE_NAME:
        {
          if (node->type==LIB3DS_OBJECT_NODE) {
            if (!lib3ds_io_read_string(io, node->data.object.instance, 64)) {
              return(LIB3DS_FALSE);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_BOUNDBOX:
        {
          if (node->type==LIB3DS_OBJECT_NODE) {
            int i;
            for (i=0; i<3; ++i) {
              node->data.object.bbox_min[i]=lib3ds_io_read_float(io);
            }
            for (i=0; i<3; ++i) {
              node->data.object.bbox_max[i]=lib3ds_io_read_float(io);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_COL_TRACK_TAG:
        {
          Lib3dsBool result=LIB3DS_TRUE;
          
          switch (node->type) {
            case LIB3DS_AMBIENT_NODE:
              result=lib3ds_lin3_track_read(&node->data.ambient.col_track, io);
              break;
            case LIB3DS_LIGHT_NODE:
              result=lib3ds_lin3_track_read(&node->data.light.col_track, io);
              break;
            default:
              lib3ds_chunk_unknown(chunk);
          }
          if (!result) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_POS_TRACK_TAG:
        {
          Lib3dsBool result=LIB3DS_TRUE;

          switch (node->type) {
            case LIB3DS_OBJECT_NODE:
              result=lib3ds_lin3_track_read(&node->data.object.pos_track, io);
              break;
            case LIB3DS_CAMERA_NODE:
              result=lib3ds_lin3_track_read(&node->data.camera.pos_track, io);
              break;
            case LIB3DS_TARGET_NODE:
              result=lib3ds_lin3_track_read(&node->data.target.pos_track, io);
              break;
            case LIB3DS_LIGHT_NODE:
              result=lib3ds_lin3_track_read(&node->data.light.pos_track, io);
              break;
            case LIB3DS_SPOT_NODE:
              result=lib3ds_lin3_track_read(&node->data.spot.pos_track, io);
              break;
            default:
              lib3ds_chunk_unknown(chunk);
          }
          if (!result) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_ROT_TRACK_TAG:
        {
          if (node->type==LIB3DS_OBJECT_NODE) {
            if (!lib3ds_quat_track_read(&node->data.object.rot_track, io)) {
              return(LIB3DS_FALSE);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_SCL_TRACK_TAG:
        {
          if (node->type==LIB3DS_OBJECT_NODE) {
            if (!lib3ds_lin3_track_read(&node->data.object.scl_track, io)) {
              return(LIB3DS_FALSE);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_FOV_TRACK_TAG:
        {
          if (node->type==LIB3DS_CAMERA_NODE) {
            if (!lib3ds_lin1_track_read(&node->data.camera.fov_track, io)) {
              return(LIB3DS_FALSE);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_HOT_TRACK_TAG:
        {
          if (node->type==LIB3DS_LIGHT_NODE) {
            if (!lib3ds_lin1_track_read(&node->data.light.hotspot_track, io)) {
              return(LIB3DS_FALSE);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_FALL_TRACK_TAG:
        {
          if (node->type==LIB3DS_LIGHT_NODE) {
            if (!lib3ds_lin1_track_read(&node->data.light.falloff_track, io)) {
              return(LIB3DS_FALSE);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_ROLL_TRACK_TAG:
        {
          Lib3dsBool result=LIB3DS_TRUE;

          switch (node->type) {
            case LIB3DS_CAMERA_NODE:
              result=lib3ds_lin1_track_read(&node->data.camera.roll_track, io);
              break;
            case LIB3DS_LIGHT_NODE:
              result=lib3ds_lin1_track_read(&node->data.light.roll_track, io);
              break;
            default:
              lib3ds_chunk_unknown(chunk);
          }
          if (!result) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_HIDE_TRACK_TAG:
        {
          if (node->type==LIB3DS_OBJECT_NODE) {
            if (!lib3ds_bool_track_read(&node->data.object.hide_track, io)) {
              return(LIB3DS_FALSE);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_MORPH_SMOOTH:
        {
          if (node->type==LIB3DS_OBJECT_NODE) {
            node->data.object.morph_smooth=lib3ds_io_read_float(io);
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      case LIB3DS_MORPH_TRACK_TAG:
        {
          if (node->type==LIB3DS_OBJECT_NODE) {
            if (!lib3ds_morph_track_read(&node->data.object.morph_track, io)) {
              return(LIB3DS_FALSE);
            }
          }
          else {
            lib3ds_chunk_unknown(chunk);
          }
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }

  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
예제 #16
0
static Lib3dsBool
texture_map_read(Lib3dsTextureMap *map, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

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

  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_INT_PERCENTAGE:
        {
          map->percent=1.0f*lib3ds_io_read_intw(io)/100.0f;
        }
        break;
      case LIB3DS_MAT_MAPNAME:
        {
          if (!lib3ds_io_read_string(io, map->name, 64)) {
            return(LIB3DS_FALSE);
          }
          lib3ds_chunk_dump_info("  NAME=%s", map->name);
        }
        break;
      case LIB3DS_MAT_MAP_TILING:
        {
          map->flags=lib3ds_io_read_word(io);
        }
        break;
      case LIB3DS_MAT_MAP_TEXBLUR:
        {
          map->blur=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_MAT_MAP_USCALE:
        {
          map->scale[0]=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_MAT_MAP_VSCALE:
        {
          map->scale[1]=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_MAT_MAP_UOFFSET:
        {
          map->offset[0]=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_MAT_MAP_VOFFSET:
        {
          map->offset[1]=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_MAT_MAP_ANG:
        {
          map->rotation=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_MAT_MAP_COL1:
        {
          map->tint_1[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_1[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_1[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
        }
        break;
      case LIB3DS_MAT_MAP_COL2:
        {
          map->tint_2[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_2[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_2[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
        }
        break;
      case LIB3DS_MAT_MAP_RCOL:
        {
          map->tint_r[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_r[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_r[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
        }
        break;
      case LIB3DS_MAT_MAP_GCOL:
        {
          map->tint_g[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_g[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_g[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
        }
        break;
      case LIB3DS_MAT_MAP_BCOL:
        {
          map->tint_b[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_b[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          map->tint_b[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
예제 #17
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);
}
예제 #18
0
static void
kfdata_read(Lib3dsFile *file, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;
    unsigned num_nodes = 0;
    Lib3dsNode *last = NULL;

    lib3ds_chunk_read_start(&c, CHK_KFDATA, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
            case CHK_KFHDR: {
                file->keyf_revision = lib3ds_io_read_word(io);
                lib3ds_io_read_string(io, file->name, 12 + 1);
                file->frames = lib3ds_io_read_intd(io);
                break;
            }

            case CHK_KFSEG: {
                file->segment_from = lib3ds_io_read_intd(io);
                file->segment_to = lib3ds_io_read_intd(io);
                break;
            }

            case CHK_KFCURTIME: {
                file->current_frame = lib3ds_io_read_intd(io);
                break;
            }

            case CHK_VIEWPORT_LAYOUT:
            case CHK_DEFAULT_VIEW: {
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_viewport_read(&file->viewport_keyf, io);
                break;
            }

            case CHK_AMBIENT_NODE_TAG: 
            case CHK_OBJECT_NODE_TAG: 
            case CHK_CAMERA_NODE_TAG: 
            case CHK_TARGET_NODE_TAG: 
            case CHK_LIGHT_NODE_TAG: 
            case CHK_SPOTLIGHT_NODE_TAG: 
            case CHK_L_TARGET_NODE_TAG: {
                Lib3dsNodeType type = (Lib3dsNodeType)0;
                Lib3dsNode *node;

                switch (chunk) {
                    case CHK_AMBIENT_NODE_TAG: 
                        type = LIB3DS_NODE_AMBIENT_COLOR;
                        break;
                    case CHK_OBJECT_NODE_TAG: 
                        type = LIB3DS_NODE_MESH_INSTANCE;
                        break;
                    case CHK_CAMERA_NODE_TAG: 
                        type = LIB3DS_NODE_CAMERA;
                        break;
                    case CHK_TARGET_NODE_TAG: 
                        type = LIB3DS_NODE_CAMERA_TARGET;
                        break;
                    case CHK_LIGHT_NODE_TAG: 
                        type = LIB3DS_NODE_OMNILIGHT;
                        break;
                    case CHK_SPOTLIGHT_NODE_TAG: 
                        type = LIB3DS_NODE_SPOTLIGHT;
                        break;
                    case CHK_L_TARGET_NODE_TAG:
                        type = LIB3DS_NODE_SPOTLIGHT_TARGET;
                        break;
                }

                node = lib3ds_node_new(type);
                node->node_id = (unsigned short)(num_nodes++);
                if (last) {
                    last->next = node;
                } else {
                    file->nodes = node;
                }
                node->user_ptr = last;
                last = node;
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_node_read(node, io);
                break;
            }

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

    {
        Lib3dsNode **nodes = (Lib3dsNode**)malloc(num_nodes * sizeof(Lib3dsNode*));
        unsigned i;
        Lib3dsNode *p, *q, *parent;

        p = file->nodes;
        for (i = 0; i < num_nodes; ++i) {
            nodes[i] = p;
            p = p->next;
        }
        qsort(nodes, num_nodes, sizeof(Lib3dsNode*), compare_node_id);

        p = last;
        while (p) {
            q = (Lib3dsNode*)p->user_ptr;
            if (p->user_id != 65535) {
                parent = *(Lib3dsNode**)bsearch(&p->user_id, nodes, num_nodes, sizeof(Lib3dsNode*), compare_node_id2);
                if (parent) {
                    q->next = p->next;    
                    p->next = parent->childs;
                    p->parent = parent;
                    parent->childs = p;
                } else {
                    /* TODO: warning */
                }
            }
            p->user_id = 0;
            p->user_ptr = NULL;
            p = q;
        }
        free(nodes);
    }

    lib3ds_chunk_read_end(&c, io);
}
예제 #19
0
void
lib3ds_node_read(Lib3dsNode *node, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;

    assert(node);
    lib3ds_chunk_read_start(&c, 0, io);

    switch (c.chunk) {
        case CHK_AMBIENT_NODE_TAG:
        case CHK_OBJECT_NODE_TAG:
        case CHK_CAMERA_NODE_TAG:
        case CHK_TARGET_NODE_TAG:
        case CHK_LIGHT_NODE_TAG:
        case CHK_SPOTLIGHT_NODE_TAG:
        case CHK_L_TARGET_NODE_TAG:
            break;
        default:
            return;
    }

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0)  {
        switch (chunk) {
            case CHK_NODE_ID: {
                node->node_id = lib3ds_io_read_word(io);
                lib3ds_io_log_indent(io, 1);
                lib3ds_io_log(io, LIB3DS_LOG_INFO, "ID=%d", (short)node->node_id);
                lib3ds_io_log_indent(io, -1);
                break;
            }

            case CHK_NODE_HDR: {
                lib3ds_io_read_string(io, node->name, 64);
                node->flags = lib3ds_io_read_word(io);
                node->flags |= ((uint32_t)lib3ds_io_read_word(io)) << 16;
                node->user_id = lib3ds_io_read_word(io);

                lib3ds_io_log_indent(io, 1);
                lib3ds_io_log(io, LIB3DS_LOG_INFO, "NAME=%s", node->name);
                lib3ds_io_log(io, LIB3DS_LOG_INFO, "PARENT=%d", (short)node->user_id);
                lib3ds_io_log_indent(io, -1);
                break;
            }

            case CHK_PIVOT: {
                if (node->type == LIB3DS_NODE_MESH_INSTANCE) {
                    Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                    lib3ds_io_read_vector(io, n->pivot);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_INSTANCE_NAME: {
                if (node->type == LIB3DS_NODE_MESH_INSTANCE) {
                    Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                    lib3ds_io_read_string(io, n->instance_name, 64);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_BOUNDBOX: {
                if (node->type == LIB3DS_NODE_MESH_INSTANCE) {
                    Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                    lib3ds_io_read_vector(io, n->bbox_min);
                    lib3ds_io_read_vector(io, n->bbox_max);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_COL_TRACK_TAG: {
                Lib3dsTrack *track = 0;
                switch (node->type) {
                    case LIB3DS_NODE_AMBIENT_COLOR: {
                        Lib3dsAmbientColorNode *n = (Lib3dsAmbientColorNode*)node;
                        track = &n->color_track;
                        break;
                    }
                    case LIB3DS_NODE_OMNILIGHT: {
                        Lib3dsOmnilightNode *n = (Lib3dsOmnilightNode*)node;
                        track = &n->color_track;
                        break;
                    }
                    case LIB3DS_NODE_SPOTLIGHT: {
                        Lib3dsSpotlightNode *n = (Lib3dsSpotlightNode*)node;
                        track = &n->color_track;
                        break;
                    }
                    default:
                        lib3ds_chunk_unknown(chunk, io);
                }
                if (track) {
                    lib3ds_track_read(track, io);
                }
                break;
            }

            case CHK_POS_TRACK_TAG: {
                Lib3dsTrack *track = 0;
                switch (node->type) {
                    case LIB3DS_NODE_MESH_INSTANCE: {
                        Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                        track = &n->pos_track;
                        break;
                    }
                    case LIB3DS_NODE_CAMERA: {
                        Lib3dsCameraNode *n = (Lib3dsCameraNode*)node;
                        track = &n->pos_track;
                        break;
                    }
                    case LIB3DS_NODE_CAMERA_TARGET: {
                        Lib3dsTargetNode *n = (Lib3dsTargetNode*)node;
                        track = &n->pos_track;
                        break;
                    }
                    case LIB3DS_NODE_OMNILIGHT: {
                        Lib3dsOmnilightNode *n = (Lib3dsOmnilightNode*)node;
                        track = &n->pos_track;
                        break;
                    }
                    case LIB3DS_NODE_SPOTLIGHT: {
                        Lib3dsSpotlightNode *n = (Lib3dsSpotlightNode*)node;
                        track = &n->pos_track;
                        break;
                    }
                    case LIB3DS_NODE_SPOTLIGHT_TARGET: {
                        Lib3dsTargetNode *n = (Lib3dsTargetNode*)node;
                        track = &n->pos_track;
                        break;
                    }
                    default:
                        lib3ds_chunk_unknown(chunk, io);
                }
                if (track) {
                    lib3ds_track_read(track, io);
                }
                break;
            }

            case CHK_ROT_TRACK_TAG: {
                if (node->type == LIB3DS_NODE_MESH_INSTANCE) {
                    Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                    n->rot_track.type = LIB3DS_TRACK_QUAT;
                    lib3ds_track_read(&n->rot_track, io);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_SCL_TRACK_TAG: {
                if (node->type == LIB3DS_NODE_MESH_INSTANCE) {
                    Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                    n->scl_track.type = LIB3DS_TRACK_VECTOR;
                    lib3ds_track_read(&n->scl_track, io);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_FOV_TRACK_TAG: {
                if (node->type == LIB3DS_NODE_CAMERA) {
                    Lib3dsCameraNode *n = (Lib3dsCameraNode*)node;
                    n->fov_track.type = LIB3DS_TRACK_FLOAT;
                    lib3ds_track_read(&n->fov_track, io);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_HOT_TRACK_TAG: {
                if (node->type == LIB3DS_NODE_SPOTLIGHT) {
                    Lib3dsSpotlightNode *n = (Lib3dsSpotlightNode*)node;
                    n->hotspot_track.type = LIB3DS_TRACK_FLOAT;
                    lib3ds_track_read(&n->hotspot_track, io);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_FALL_TRACK_TAG: {
                if (node->type == LIB3DS_NODE_SPOTLIGHT) {
                    Lib3dsSpotlightNode *n = (Lib3dsSpotlightNode*)node;
                    n->falloff_track.type= LIB3DS_TRACK_FLOAT;
                    lib3ds_track_read(&n->falloff_track, io);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_ROLL_TRACK_TAG: {
                switch (node->type) {
                    case LIB3DS_NODE_CAMERA: {
                        Lib3dsCameraNode *n = (Lib3dsCameraNode*)node;
                        n->roll_track.type = LIB3DS_TRACK_FLOAT;
                        lib3ds_track_read(&n->roll_track, io);
                        break;
                    }
                    case LIB3DS_NODE_SPOTLIGHT: {
                        Lib3dsSpotlightNode *n = (Lib3dsSpotlightNode*)node;
                        n->roll_track.type = LIB3DS_TRACK_FLOAT;
                        lib3ds_track_read(&n->roll_track, io);
                        break;
                    }
                    default:
                        lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_HIDE_TRACK_TAG: {
                if (node->type == LIB3DS_NODE_MESH_INSTANCE) {
                    Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                    n->hide_track.type = LIB3DS_TRACK_BOOL;
                    lib3ds_track_read(&n->hide_track, io);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
                break;
            }

            case CHK_MORPH_SMOOTH: {
                if (node->type == LIB3DS_NODE_MESH_INSTANCE) {
                    Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                    n->morph_smooth = lib3ds_io_read_float(io);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
            }
            break;

            /*
            case LIB3DS_MORPH_TRACK_TAG: {
                if (node->type == LIB3DS_NODE_MESH_INSTANCE) {
                    Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
                    n->morph_track = lib3ds_track_new(node, LIB3DS_TRACK_MORPH, 0);
                    lib3ds_track_read(n->morph_track, io);
                } else {
                    lib3ds_chunk_unknown(chunk, io);
                }
            }
            break;
            */

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
예제 #20
0
static Lib3dsBool
kfdata_read(Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;
  Lib3dsDword node_number = 0;

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

          node=lib3ds_node_new_ambient();
          if (!node) {
            return(LIB3DS_FALSE);
          }
          node->node_id=node_number++;
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_node_read(node, file, io)) {
            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);
          }
          node->node_id=node_number++;
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_node_read(node, file, io)) {
            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);
          }
          node->node_id=node_number++;
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_node_read(node, file, io)) {
            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);
          }
          node->node_id=node_number++;
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_node_read(node, file, io)) {
            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);
          }
          node->node_id=node_number++;
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_node_read(node, file, io)) {
            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);
          }
          node->node_id=node_number++;
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_node_read(node, file, io)) {
            return(LIB3DS_FALSE);
          }
          lib3ds_file_insert_node(file, node);
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }

  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
예제 #21
0
void
lib3ds_mesh_read(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;

    lib3ds_chunk_read_start(&c, CHK_N_TRI_OBJECT, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
            case CHK_MESH_MATRIX: {
                int i, j;

                lib3ds_matrix_identity(mesh->matrix);
                for (i = 0; i < 4; i++) {
                    for (j = 0; j < 3; j++) {
                        mesh->matrix[i][j] = lib3ds_io_read_float(io);
                    }
                }
                break;
            }

            case CHK_MESH_COLOR: {
                mesh->color = lib3ds_io_read_byte(io);
                break;
            }

            case CHK_POINT_ARRAY: {
                int i;
                uint16_t nvertices = lib3ds_io_read_word(io);
                lib3ds_mesh_resize_vertices(mesh, nvertices, mesh->texcos != NULL, mesh->vflags != NULL);
                for (i = 0; i < mesh->nvertices; ++i) {
                    lib3ds_io_read_vector(io, mesh->vertices[i]);
                }
                break;
            }

            case CHK_POINT_FLAG_ARRAY: {
                int i;
                uint16_t nflags = lib3ds_io_read_word(io);
                uint16_t nvertices = (mesh->nvertices >= nflags)? mesh->nvertices : nflags;
                lib3ds_mesh_resize_vertices(mesh, nvertices, mesh->texcos != NULL, 1);
                for (i = 0; i < nflags; ++i) {
                    mesh->vflags[i] = lib3ds_io_read_word(io);
                }
                break;
            }

            case CHK_FACE_ARRAY: {
                lib3ds_chunk_read_reset(&c, io);
                face_array_read(file, mesh, io);
                break;
            }

            case CHK_MESH_TEXTURE_INFO: {
                int i, j;

                //FIXME: mesh->map_type = lib3ds_io_read_word(io);

                for (i = 0; i < 2; ++i) {
                    mesh->map_tile[i] = lib3ds_io_read_float(io);
                }
                for (i = 0; i < 3; ++i) {
                    mesh->map_pos[i] = lib3ds_io_read_float(io);
                }
                mesh->map_scale = lib3ds_io_read_float(io);

                lib3ds_matrix_identity(mesh->map_matrix);
                for (i = 0; i < 4; i++) {
                    for (j = 0; j < 3; j++) {
                        mesh->map_matrix[i][j] = lib3ds_io_read_float(io);
                    }
                }
                for (i = 0; i < 2; ++i) {
                    mesh->map_planar_size[i] = lib3ds_io_read_float(io);
                }
                mesh->map_cylinder_height = lib3ds_io_read_float(io);
                break;
            }

            case CHK_TEX_VERTS: {
                int i;
                uint16_t ntexcos = lib3ds_io_read_word(io);
                uint16_t nvertices = (mesh->nvertices >= ntexcos)? mesh->nvertices : ntexcos;;
                if (!mesh->texcos) {
                    lib3ds_mesh_resize_vertices(mesh, nvertices, 1, mesh->vflags != NULL);
                }
                for (i = 0; i < ntexcos; ++i) {
                    mesh->texcos[i][0] = lib3ds_io_read_float(io);
                    mesh->texcos[i][1] = lib3ds_io_read_float(io);
                }
                break;
            }

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

    if (lib3ds_matrix_det(mesh->matrix) < 0.0) {
        /* Flip X coordinate of vertices if mesh matrix
           has negative determinant */
        float inv_matrix[4][4], M[4][4];
        float tmp[3];
        int i;

        lib3ds_matrix_copy(inv_matrix, mesh->matrix);
        lib3ds_matrix_inv(inv_matrix);

        lib3ds_matrix_copy(M, mesh->matrix);
        lib3ds_matrix_scale(M, -1.0f, 1.0f, 1.0f);
        lib3ds_matrix_mult(M, M, inv_matrix);

        for (i = 0; i < mesh->nvertices; ++i) {
            lib3ds_vector_transform(tmp, M, mesh->vertices[i]);
            lib3ds_vector_copy(mesh->vertices[i], tmp);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
예제 #22
0
파일: viewport.c 프로젝트: Aharobot/mrpt
/*!
 * \ingroup viewport 
 */
Lib3dsBool
lib3ds_viewport_read(Lib3dsViewport *viewport, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  if (!lib3ds_chunk_read_start(&c, 0, io)) {
    return(LIB3DS_FALSE);
  }
  
  switch (c.chunk) {
    case LIB3DS_VIEWPORT_LAYOUT:
      {
        int cur=0;
        viewport->layout.style=lib3ds_io_read_word(io);
        viewport->layout.active=lib3ds_io_read_intw(io);
        lib3ds_io_read_intw(io);
        viewport->layout.swap=lib3ds_io_read_intw(io);
        lib3ds_io_read_intw(io);
        viewport->layout.swap_prior=lib3ds_io_read_intw(io);
        viewport->layout.swap_view=lib3ds_io_read_intw(io);
        lib3ds_chunk_read_tell(&c, io);
        while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
          switch (chunk) {
            case LIB3DS_VIEWPORT_SIZE:
              {
                viewport->layout.position[0]=lib3ds_io_read_word(io);
                viewport->layout.position[1]=lib3ds_io_read_word(io);
                viewport->layout.size[0]=lib3ds_io_read_word(io);
                viewport->layout.size[1]=lib3ds_io_read_word(io);
              }
              break;
            case LIB3DS_VIEWPORT_DATA_3:
              {
                lib3ds_viewport_set_views(viewport,cur+1);
                lib3ds_io_read_intw(io);
                viewport->layout.viewL[cur].axis_lock=lib3ds_io_read_word(io);
                viewport->layout.viewL[cur].position[0]=lib3ds_io_read_intw(io);
                viewport->layout.viewL[cur].position[1]=lib3ds_io_read_intw(io);
                viewport->layout.viewL[cur].size[0]=lib3ds_io_read_intw(io);
                viewport->layout.viewL[cur].size[1]=lib3ds_io_read_intw(io);
                viewport->layout.viewL[cur].type=lib3ds_io_read_word(io);
                viewport->layout.viewL[cur].zoom=lib3ds_io_read_float(io);
                lib3ds_io_read_vector(io, viewport->layout.viewL[cur].center);
                viewport->layout.viewL[cur].horiz_angle=lib3ds_io_read_float(io);
                viewport->layout.viewL[cur].vert_angle=lib3ds_io_read_float(io);
                lib3ds_io_read(io, viewport->layout.viewL[cur].camera, 11);
                ++cur;
              }
              break;
            case LIB3DS_VIEWPORT_DATA:
              /* 3DS R2 & R3 chunk
                 unsupported */
              break;
            default:
              lib3ds_chunk_unknown(chunk);
          }
        }
      }
      break;
    case LIB3DS_DEFAULT_VIEW:
      {
        memset(&viewport->default_view,0,sizeof(Lib3dsDefaultView));
        while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
          switch (chunk) {
            case LIB3DS_VIEW_TOP:
              {
                viewport->default_view.type=LIB3DS_VIEW_TYPE_TOP;
                lib3ds_io_read_vector(io, viewport->default_view.position);
                viewport->default_view.width=lib3ds_io_read_float(io);
              }
              break;
            case LIB3DS_VIEW_BOTTOM:
              {
                viewport->default_view.type=LIB3DS_VIEW_TYPE_BOTTOM;
                lib3ds_io_read_vector(io, viewport->default_view.position);
                viewport->default_view.width=lib3ds_io_read_float(io);
              }
              break;
            case LIB3DS_VIEW_LEFT:
              {
                viewport->default_view.type=LIB3DS_VIEW_TYPE_LEFT;
                lib3ds_io_read_vector(io, viewport->default_view.position);
                viewport->default_view.width=lib3ds_io_read_float(io);
              }
              break;
            case LIB3DS_VIEW_RIGHT:
              {
                viewport->default_view.type=LIB3DS_VIEW_TYPE_RIGHT;
                lib3ds_io_read_vector(io, viewport->default_view.position);
                viewport->default_view.width=lib3ds_io_read_float(io);
              }
              break;
            case LIB3DS_VIEW_FRONT:
              {
                viewport->default_view.type=LIB3DS_VIEW_TYPE_FRONT;
                lib3ds_io_read_vector(io, viewport->default_view.position);
                viewport->default_view.width=lib3ds_io_read_float(io);
              }
              break;
            case LIB3DS_VIEW_BACK:
              {
                viewport->default_view.type=LIB3DS_VIEW_TYPE_BACK;
                lib3ds_io_read_vector(io, viewport->default_view.position);
                viewport->default_view.width=lib3ds_io_read_float(io);
              }
              break;
            case LIB3DS_VIEW_USER:
              {
                viewport->default_view.type=LIB3DS_VIEW_TYPE_USER;
                lib3ds_io_read_vector(io, viewport->default_view.position);
                viewport->default_view.width=lib3ds_io_read_float(io);
                viewport->default_view.horiz_angle=lib3ds_io_read_float(io);
                viewport->default_view.vert_angle=lib3ds_io_read_float(io);
                viewport->default_view.roll_angle=lib3ds_io_read_float(io);
              }
              break;
            case LIB3DS_VIEW_CAMERA:
              {
                viewport->default_view.type=LIB3DS_VIEW_TYPE_CAMERA;
                lib3ds_io_read(io, viewport->default_view.camera, 11);
              }
              break;
            default:
              lib3ds_chunk_unknown(chunk);
          }
        }
      }
      break;
  }

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