Ejemplo n.º 1
0
static Lib3dsBool
ambient_read(Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;
  Lib3dsBool have_lin=LIB3DS_FALSE;

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

  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_LIN_COLOR_F:
        {
          int i;
          for (i=0; i<3; ++i) {
            file->ambient[i]=lib3ds_io_read_float(io);
          }
        }
        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_io_read_float(io);
            }
          }
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 2
0
static Lib3dsBool
fog_read(Lib3dsFog *fog, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_FOG, io)) {
    return(LIB3DS_FALSE);
  }
  fog->near_plane = lib3ds_io_read_float(io);
  fog->near_density=lib3ds_io_read_float(io);
  fog->far_plane=lib3ds_io_read_float(io);
  fog->far_density=lib3ds_io_read_float(io);
  lib3ds_chunk_read_tell(&c, io);
  
  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_LIN_COLOR_F:
        {
          int i;
          for (i=0; i<3; ++i) {
            fog->col[i]=lib3ds_io_read_float(io);
          }
        }
        break;
      case LIB3DS_COLOR_F:
        break;
      case LIB3DS_FOG_BGND:
        {
          fog->fog_background=LIB3DS_TRUE;
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 3
0
static void
ambient_read(Lib3dsFile *file, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;
    int have_lin = FALSE;

    lib3ds_chunk_read_start(&c, CHK_AMBIENT_LIGHT, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
            case CHK_LIN_COLOR_F: {
                int i;
                for (i = 0; i < 3; ++i) {
                    file->ambient[i] = lib3ds_io_read_float(io);
                }
                have_lin = TRUE;
                break;
            }

            case CHK_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_io_read_float(io);
                    }
                }
                break;
            }

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 4
0
/*!
 * Read a camera definition from a file.
 *
 * This function is called by lib3ds_file_read(), and you probably
 * don't want to call it directly.
 *
 * \param camera A Lib3dsCamera to be filled in.
 * \param io A Lib3dsIo object previously set up by the caller.
 *
 * \return LIB3DS_TRUE on success, LIB3DS_FALSE on failure.
 *
 * \see lib3ds_file_read
 *
 * \ingroup camera
 */
Lib3dsBool
lib3ds_camera_read(Lib3dsCamera *camera, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_N_CAMERA, io)) {
    return(LIB3DS_FALSE);
  }
  {
    int i;
    for (i=0; i<3; ++i) {
      camera->position[i]=lib3ds_io_read_float(io);
    }
    for (i=0; i<3; ++i) {
      camera->target[i]=lib3ds_io_read_float(io);
    }
  }
  camera->roll=lib3ds_io_read_float(io);
  {
    float s;
    s=lib3ds_io_read_float(io);
    if (fabs(s)<LIB3DS_EPSILON) {
      camera->fov=45.0;
    }
    else {
      camera->fov=2400.0f/s;
    }
  }
  lib3ds_chunk_read_tell(&c, io);
  
  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_CAM_SEE_CONE:
        {
          camera->see_cone=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_CAM_RANGES:
        {
          camera->near_range=lib3ds_io_read_float(io);
          camera->far_range=lib3ds_io_read_float(io);
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 5
0
static Lib3dsBool
v_gradient_read(Lib3dsBackground *background, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;
  int index[2];
  Lib3dsRgb col[2][3];
  int have_lin=0;
  

  if (!lib3ds_chunk_read_start(&c, LIB3DS_V_GRADIENT, io)) {
    return(LIB3DS_FALSE);
  }
  background->gradient.percent=lib3ds_io_read_float(io);
  lib3ds_chunk_read_tell(&c, io);

  index[0]=index[1]=0;
  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_COLOR_F:
        lib3ds_io_read_rgb(io, col[0][index[0]]);
        index[0]++;
        break;
      case LIB3DS_LIN_COLOR_F:
        lib3ds_io_read_rgb(io, col[1][index[1]]);
        index[1]++;
        have_lin=1;
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  {
    int i;
    for (i=0; i<3; ++i) {
      background->gradient.top[i]=col[have_lin][0][i];
      background->gradient.middle[i]=col[have_lin][1][i];
      background->gradient.bottom[i]=col[have_lin][2][i];
    }
  }
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 6
0
static void
v_gradient_read(Lib3dsBackground *background, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;
    int index[2];
    float col[2][3][3];
    int have_lin = 0;

    lib3ds_chunk_read_start(&c, CHK_V_GRADIENT, io);

    background->gradient_percent = lib3ds_io_read_float(io);
    lib3ds_chunk_read_tell(&c, io);

    index[0] = index[1] = 0;
    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
            case CHK_COLOR_F:
                lib3ds_io_read_rgb(io, col[0][index[0]]);
                index[0]++;
                break;

            case CHK_LIN_COLOR_F:
                lib3ds_io_read_rgb(io, col[1][index[1]]);
                index[1]++;
                have_lin = 1;
                break;

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }
    {
        int i;
        for (i = 0; i < 3; ++i) {
            background->gradient_top[i] = col[have_lin][0][i];
            background->gradient_middle[i] = col[have_lin][1][i];
            background->gradient_bottom[i] = col[have_lin][2][i];
        }
    }
    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 7
0
/*!
 * \ingroup tracks 
 */
Lib3dsBool
lib3ds_lin1_track_read(Lib3dsLin1Track *track, Lib3dsIo *io)
{
  int keys;
  int i;
  Lib3dsLin1Key *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_lin1_key_new();
    if (!lib3ds_tcb_read(&k->tcb, io)) {
      return(LIB3DS_FALSE);
    }
    k->value=lib3ds_io_read_float(io);
    lib3ds_lin1_track_insert(track, k);
  }
  lib3ds_lin1_track_setup(track);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 8
0
Archivo: node.c Proyecto: 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);
}
Ejemplo n.º 9
0
static void
spotlight_read(Lib3dsLight *light, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;
    int i;

    lib3ds_chunk_read_start(&c, CHK_DL_SPOTLIGHT, io);

    light->spot_light = TRUE;
    for (i = 0; i < 3; ++i) {
        light->target[i] = lib3ds_io_read_float(io);
    }
    light->hotspot = lib3ds_io_read_float(io);
    light->falloff = lib3ds_io_read_float(io);
    lib3ds_chunk_read_tell(&c, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
            case CHK_DL_SPOT_ROLL: 
                light->roll = lib3ds_io_read_float(io);
                break;

            case CHK_DL_SHADOWED: {
                light->shadowed = TRUE;
                break;
            }

            case CHK_DL_LOCAL_SHADOW2: {
                light->shadow_bias = lib3ds_io_read_float(io);
                light->shadow_filter = lib3ds_io_read_float(io);
                light->shadow_size = lib3ds_io_read_intw(io);
                break;
            }

            case CHK_DL_SEE_CONE: {
                light->see_cone = TRUE;
                break;
            }

            case CHK_DL_SPOT_RECTANGULAR: {
                light->rectangular_spot = TRUE;
                break;
            }

            case CHK_DL_SPOT_ASPECT: {
                light->spot_aspect = lib3ds_io_read_float(io);
                break;
            }

            case CHK_DL_SPOT_PROJECTOR: {
                light->use_projector = TRUE;
                lib3ds_io_read_string(io, light->projector, 64);
                break;
            }

            case CHK_DL_SPOT_OVERSHOOT: {
                light->spot_overshoot = TRUE;
                break;
            }

            case CHK_DL_RAY_BIAS: {
                light->ray_bias = lib3ds_io_read_float(io);
                break;
            }

            case CHK_DL_RAYSHAD: {
                light->ray_shadows = TRUE;
                break;
            }

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
0
static Lib3dsBool
mdata_read(Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_MDATA, io)) {
    return(LIB3DS_FALSE);
  }
  
  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_MESH_VERSION:
        {
          file->mesh_version=lib3ds_io_read_intd(io);
        }
        break;
      case LIB3DS_MASTER_SCALE:
        {
          file->master_scale=lib3ds_io_read_float(io);
        }
        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, io);
          if (!lib3ds_shadow_read(&file->shadow, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_VIEWPORT_LAYOUT:
      case LIB3DS_DEFAULT_VIEW:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_viewport_read(&file->viewport, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_O_CONSTS:
        {
          int i;
          for (i=0; i<3; ++i) {
            file->construction_plane[i]=lib3ds_io_read_float(io);
          }
        }
        break;
      case LIB3DS_AMBIENT_LIGHT:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!ambient_read(file, io)) {
            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, io);
          if (!lib3ds_background_read(&file->background, io)) {
            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, io);
          if (!lib3ds_atmosphere_read(&file->atmosphere, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      case LIB3DS_MAT_ENTRY:
        {
          Lib3dsMaterial *material;

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

  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 12
0
static Lib3dsBool
color_read(Lib3dsRgba rgb, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;
  Lib3dsBool have_lin=LIB3DS_FALSE;

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

  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_LIN_COLOR_24:
        {
          int i;
          for (i=0; i<3; ++i) {
            rgb[i]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          }
          rgb[3]=1.0f;
        }
        have_lin=LIB3DS_TRUE;
        break;
      case LIB3DS_COLOR_24:
        /* gamma corrected color chunk
           replaced in 3ds R3 by LIN_COLOR_24 */
        if (!have_lin) {
          int i;
          for (i=0; i<3; ++i) {
            rgb[i]=1.0f*lib3ds_io_read_byte(io)/255.0f;
          }
          rgb[3]=1.0f;
        }
        break;
      case LIB3DS_LIN_COLOR_F:
        {
          int i;
          for (i=0; i<3; ++i) {
            rgb[i]=lib3ds_io_read_float(io);
          }
          rgb[3]=1.0f;
        }
        have_lin=LIB3DS_TRUE;
        break;
      case LIB3DS_COLOR_F:
        if (!have_lin) {
          int i;
          for (i=0; i<3; ++i) {
            rgb[i]=lib3ds_io_read_float(io);
          }
          rgb[3]=1.0f;
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 13
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);
}
Ejemplo n.º 14
0
void
lib3ds_light_read(Lib3dsLight *light, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;

    lib3ds_chunk_read_start(&c, CHK_N_DIRECT_LIGHT, io);

    {
        int i;
        for (i = 0; i < 3; ++i) {
            light->position[i] = lib3ds_io_read_float(io);
        }
    }
    lib3ds_chunk_read_tell(&c, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
            case CHK_COLOR_F: {
                int i;
                for (i = 0; i < 3; ++i) {
                    light->color[i] = lib3ds_io_read_float(io);
                }
                break;
            }

            case CHK_DL_OFF: 
                light->off = TRUE;
                break;

            case CHK_DL_OUTER_RANGE: 
                light->outer_range = lib3ds_io_read_float(io);
                break;

            case CHK_DL_INNER_RANGE: 
                light->inner_range = lib3ds_io_read_float(io);
                break;

            case CHK_DL_MULTIPLIER: 
                light->multiplier = lib3ds_io_read_float(io);
                break;

            case CHK_DL_EXCLUDE: {
                /* FIXME: */
                lib3ds_chunk_unknown(chunk, io);
                break;
            }

            case CHK_DL_ATTENUATE: 
                light->attenuation = lib3ds_io_read_float(io);
                break;

            case CHK_DL_SPOTLIGHT: {
                lib3ds_chunk_read_reset(&c, io);
                spotlight_read(light, io);
                break;
            }

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 15
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);
}
Ejemplo n.º 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);
}
Ejemplo n.º 17
0
Archivo: light.c Proyecto: DYFeng/mrpt
/*!
 * \ingroup light
 */
Lib3dsBool
lib3ds_light_read(Lib3dsLight *light, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_N_DIRECT_LIGHT, io)) {
    return(LIB3DS_FALSE);
  }
  {
    int i;
    for (i=0; i<3; ++i) {
      light->position[i]=lib3ds_io_read_float(io);
    }
  }
  lib3ds_chunk_read_tell(&c, io);
  
  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_COLOR_F:
        {
          int i;
          for (i=0; i<3; ++i) {
            light->color[i]=lib3ds_io_read_float(io);
          }
        }
        break;
      case LIB3DS_DL_OFF:
        {
          light->off=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_DL_OUTER_RANGE:
        {
          light->outer_range=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_DL_INNER_RANGE:
        {
          light->inner_range=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_DL_MULTIPLIER:
        {
          light->multiplier=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_DL_EXCLUDE:
        {
          /* FIXME: */
          lib3ds_chunk_unknown(chunk);
        }
      case LIB3DS_DL_ATTENUATE:
        {
          light->attenuation=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_DL_SPOTLIGHT:
        {
          lib3ds_chunk_read_reset(&c, io);
          if (!spotlight_read(light, io)) {
            return(LIB3DS_FALSE);
          }
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 18
0
Archivo: light.c Proyecto: DYFeng/mrpt
/*!
 * \ingroup light
 */
static Lib3dsBool
spotlight_read(Lib3dsLight *light, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;
  int i;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_DL_SPOTLIGHT, io)) {
    return(LIB3DS_FALSE);
  }
  light->spot_light=LIB3DS_TRUE;
  for (i=0; i<3; ++i) {
    light->spot[i]=lib3ds_io_read_float(io);
  }
  light->hot_spot = lib3ds_io_read_float(io);
  light->fall_off = lib3ds_io_read_float(io);
  lib3ds_chunk_read_tell(&c, io);
  
  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_DL_SPOT_ROLL:
        {
          light->roll=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_DL_SHADOWED:
        {
          light->shadowed=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_DL_LOCAL_SHADOW2:
        {
          light->shadow_bias=lib3ds_io_read_float(io);
          light->shadow_filter=lib3ds_io_read_float(io);
          light->shadow_size=lib3ds_io_read_intw(io);
        }
        break;
      case LIB3DS_DL_SEE_CONE:
        {
          light->see_cone=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_DL_SPOT_RECTANGULAR:
        {
          light->rectangular_spot=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_DL_SPOT_ASPECT:
        {
          light->spot_aspect=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_DL_SPOT_PROJECTOR:
        {
          light->use_projector=LIB3DS_TRUE;
          if (!lib3ds_io_read_string(io, light->projector, 64)) {
            return(LIB3DS_FALSE);
          }
        }
      case LIB3DS_DL_SPOT_OVERSHOOT:
        {
          light->spot_overshoot=LIB3DS_TRUE;
        }
        break;
      case LIB3DS_DL_RAY_BIAS:
        {
          light->ray_bias=lib3ds_io_read_float(io);
        }
        break;
      case LIB3DS_DL_RAYSHAD:
        {
          light->ray_shadows=LIB3DS_TRUE;
        }
        break;
      default:
        lib3ds_chunk_unknown(chunk);
    }
  }
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 19
0
/*!
 * \ingroup material
 */
Lib3dsBool
lib3ds_material_read(Lib3dsMaterial *material, Lib3dsIo *io)
{
  Lib3dsChunk c;
  Lib3dsWord chunk;

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

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

  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Ejemplo n.º 20
0
void
lib3ds_material_read(Lib3dsMaterial *material, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        default:
            lib3ds_chunk_unknown(chunk, io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 21
0
static void
mdata_read(Lib3dsFile *file, Lib3dsIo *io) {
    Lib3dsChunk c;
    uint16_t chunk;

    lib3ds_chunk_read_start(&c, CHK_MDATA, io);

    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
            case CHK_MESH_VERSION: {
                file->mesh_version = lib3ds_io_read_intd(io);
                break;
            }

            case CHK_MASTER_SCALE: {
                file->master_scale = lib3ds_io_read_float(io);
                break;
            }

            case CHK_SHADOW_MAP_SIZE:
            case CHK_LO_SHADOW_BIAS:
            case CHK_HI_SHADOW_BIAS:
            case CHK_SHADOW_SAMPLES:
            case CHK_SHADOW_RANGE:
            case CHK_SHADOW_FILTER:
            case CHK_RAY_BIAS: {
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_shadow_read(&file->shadow, io);
                break;
            }

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

            case CHK_O_CONSTS: {
                int i;
                for (i = 0; i < 3; ++i) {
                    file->construction_plane[i] = lib3ds_io_read_float(io);
                }
                break;
            }

            case CHK_AMBIENT_LIGHT: {
                lib3ds_chunk_read_reset(&c, io);
                ambient_read(file, io);
                break;
            }

            case CHK_BIT_MAP:
            case CHK_SOLID_BGND:
            case CHK_V_GRADIENT:
            case CHK_USE_BIT_MAP:
            case CHK_USE_SOLID_BGND:
            case CHK_USE_V_GRADIENT: {
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_background_read(&file->background, io);
                break;
            }

            case CHK_FOG:
            case CHK_LAYER_FOG:
            case CHK_DISTANCE_CUE:
            case CHK_USE_FOG:
            case CHK_USE_LAYER_FOG:
            case CHK_USE_DISTANCE_CUE: {
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_atmosphere_read(&file->atmosphere, io);
                break;
            }

            case CHK_MAT_ENTRY: {
                Lib3dsMaterial *material = lib3ds_material_new(NULL);
                lib3ds_file_insert_material(file, material, -1);
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_material_read(material, io);
                break;
            }

            case CHK_NAMED_OBJECT: {
                lib3ds_chunk_read_reset(&c, io);
                named_object_read(file, io);
                break;
            }

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

    lib3ds_chunk_read_end(&c, io);
}
Ejemplo n.º 22
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);
}
Ejemplo n.º 23
0
/*!
 * \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);
}