Exemplo n.º 1
0
static Lib3dsBool
named_object_read(Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;
  char name[64];
  Lib3dsWord chunk;
  Lib3dsMesh *mesh = NULL;
  Lib3dsCamera *camera = NULL;
  Lib3dsLight *light = NULL;
  Lib3dsDword object_flags;

  if (!lib3ds_chunk_read_start(&c, LIB3DS_NAMED_OBJECT, io)) {
    return(LIB3DS_FALSE);
  }
  if (!lib3ds_io_read_string(io, name, 64)) {
    return(LIB3DS_FALSE);
  }
  lib3ds_chunk_dump_info("  NAME=%s", name);
  lib3ds_chunk_read_tell(&c, io);

  object_flags = 0;
  while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
    switch (chunk) {
      case LIB3DS_N_TRI_OBJECT:
        {
          mesh=lib3ds_mesh_new(name);
          if (!mesh) {
            return(LIB3DS_FALSE);
          }
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_mesh_read(mesh, io)) {
            return(LIB3DS_FALSE);
          }
          lib3ds_file_insert_mesh(file, mesh);
        }
        break;
      
      case LIB3DS_N_CAMERA:
        {
          camera=lib3ds_camera_new(name);
          if (!camera) {
            return(LIB3DS_FALSE);
          }
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_camera_read(camera, io)) {
            return(LIB3DS_FALSE);
          }
          lib3ds_file_insert_camera(file, camera);
        }
        break;
      
      case LIB3DS_N_DIRECT_LIGHT:
        {
          light=lib3ds_light_new(name);
          if (!light) {
            return(LIB3DS_FALSE);
          }
          lib3ds_chunk_read_reset(&c, io);
          if (!lib3ds_light_read(light, io)) {
            return(LIB3DS_FALSE);
          }
          lib3ds_file_insert_light(file, light);
        }
        break;
      
      case LIB3DS_OBJ_HIDDEN:
        object_flags |= LIB3DS_OBJECT_HIDDEN;
        break;

      case LIB3DS_OBJ_DOESNT_CAST:
        object_flags |= LIB3DS_OBJECT_DOESNT_CAST;
        break;

      case LIB3DS_OBJ_VIS_LOFTER:
        object_flags |= LIB3DS_OBJECT_VIS_LOFTER;
        break;

      case LIB3DS_OBJ_MATTE:
        object_flags |= LIB3DS_OBJECT_MATTE;
        break;

      case LIB3DS_OBJ_DONT_RCVSHADOW:
        object_flags |= LIB3DS_OBJECT_DONT_RCVSHADOW;
        break;

      case LIB3DS_OBJ_FAST:
        object_flags |= LIB3DS_OBJECT_FAST;
        break;

      case LIB3DS_OBJ_FROZEN:
        object_flags |= LIB3DS_OBJECT_FROZEN;
        break;

      default:
        lib3ds_chunk_unknown(chunk);
    }
  }

  if (mesh)
    mesh->object_flags = object_flags;
  if (camera)
    camera->object_flags = object_flags;
  if (light)
    light->object_flags = object_flags;
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Exemplo n.º 2
0
static Lib3dsBool
named_object_read(Lib3dsFile *file, FILE *f)
{
    Lib3dsChunk c;
    char name[64];
    Lib3dsWord chunk;

    if (!lib3ds_chunk_read_start(&c, LIB3DS_NAMED_OBJECT, f)) {
        return(LIB3DS_FALSE);
    }
    if (!lib3ds_string_read(name, 64, f)) {
        return(LIB3DS_FALSE);
    }
    lib3ds_chunk_dump_info("  NAME=%s", name);
    lib3ds_chunk_read_tell(&c, f);

    while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
        switch (chunk) {
        case LIB3DS_N_TRI_OBJECT:
        {
            Lib3dsMesh *mesh;

            mesh=lib3ds_mesh_new(name);
            if (!mesh) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_mesh_read(mesh, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_mesh(file, mesh);
        }
        break;
        case LIB3DS_N_CAMERA:
        {
            Lib3dsCamera *camera;

            camera=lib3ds_camera_new(name);
            if (!camera) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_camera_read(camera, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_camera(file, camera);
        }
        break;
        case LIB3DS_N_DIRECT_LIGHT:
        {
            Lib3dsLight *light;

            light=lib3ds_light_new(name);
            if (!light) {
                return(LIB3DS_FALSE);
            }
            lib3ds_chunk_read_reset(&c, f);
            if (!lib3ds_light_read(light, f)) {
                return(LIB3DS_FALSE);
            }
            lib3ds_file_insert_light(file, light);
        }
        break;
        default:
            lib3ds_chunk_unknown(chunk);
        }
    }

    lib3ds_chunk_read_end(&c, f);
    return(LIB3DS_TRUE);
}
Exemplo n.º 3
0
static void
named_object_read(Lib3dsFile *file, Lib3dsIo *io) {
    Lib3dsChunk c;
    char name[64];
    uint16_t chunk;
    Lib3dsMesh *mesh = NULL;
    Lib3dsCamera *camera = NULL;
    Lib3dsLight *light = NULL;
    uint32_t object_flags;

    lib3ds_chunk_read_start(&c, CHK_NAMED_OBJECT, io);
    
    lib3ds_io_read_string(io, name, 64);
    lib3ds_io_log(io, LIB3DS_LOG_INFO, "  NAME=%s", name);
    lib3ds_chunk_read_tell(&c, io);

    object_flags = 0;
    while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
        switch (chunk) {
            case CHK_N_TRI_OBJECT: {
                mesh = lib3ds_mesh_new(name);
                lib3ds_file_insert_mesh(file, mesh, -1);
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_mesh_read(file, mesh, io);
                break;
            }

            case CHK_N_CAMERA: {
                camera = lib3ds_camera_new(name);
                lib3ds_file_insert_camera(file, camera, -1);
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_camera_read(camera, io);
                break;
            }

            case CHK_N_DIRECT_LIGHT: {
                light = lib3ds_light_new(name);
                lib3ds_file_insert_light(file, light, -1);
                lib3ds_chunk_read_reset(&c, io);
                lib3ds_light_read(light, io);
                break;
            }

            case CHK_OBJ_HIDDEN:
                object_flags |= LIB3DS_OBJECT_HIDDEN;
                break;

            case CHK_OBJ_DOESNT_CAST:
                object_flags |= LIB3DS_OBJECT_DOESNT_CAST;
                break;

            case CHK_OBJ_VIS_LOFTER:
                object_flags |= LIB3DS_OBJECT_VIS_LOFTER;
                break;

            case CHK_OBJ_MATTE:
                object_flags |= LIB3DS_OBJECT_MATTE;
                break;

            case CHK_OBJ_DONT_RCVSHADOW:
                object_flags |= LIB3DS_OBJECT_DONT_RCVSHADOW;
                break;

            case CHK_OBJ_FAST:
                object_flags |= LIB3DS_OBJECT_FAST;
                break;

            case CHK_OBJ_FROZEN:
                object_flags |= LIB3DS_OBJECT_FROZEN;
                break;

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

    if (mesh)
        mesh->object_flags = object_flags;
    if (camera)
        camera->object_flags = object_flags;
    if (light)
        light->object_flags = object_flags;

    lib3ds_chunk_read_end(&c, io);
}