Beispiel #1
0
/*!
 * \ingroup shadow 
 */
Lib3dsBool
lib3ds_shadow_write(Lib3dsShadow *shadow, Lib3dsIo *io)
{
  if (fabs(shadow->lo_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_LO_SHADOW_BIAS ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_LO_SHADOW_BIAS;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, shadow->lo_bias);
  }

  if (fabs(shadow->hi_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_HI_SHADOW_BIAS ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_HI_SHADOW_BIAS;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, shadow->hi_bias);
  }

  if (shadow->map_size) { /*---- LIB3DS_SHADOW_MAP_SIZE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SHADOW_MAP_SIZE;
    c.size=8;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_intw(io, shadow->map_size);
  }
  
  if (shadow->samples) { /*---- LIB3DS_SHADOW_SAMPLES ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SHADOW_SAMPLES;
    c.size=8;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_intw(io, shadow->samples);
  }

  if (shadow->range) { /*---- LIB3DS_SHADOW_RANGE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SHADOW_RANGE;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_intd(io, shadow->range);
  }

  if (fabs(shadow->filter)>LIB3DS_EPSILON) { /*---- LIB3DS_SHADOW_FILTER ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_SHADOW_FILTER;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, shadow->filter);
  }
  if (fabs(shadow->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_RAY_BIAS ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_RAY_BIAS;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, shadow->ray_bias);
  }
  return(LIB3DS_TRUE);
}
Beispiel #2
0
static void
int_percentage_write(float p, Lib3dsIo *io) {
    Lib3dsChunk c;

    c.chunk = CHK_INT_PERCENTAGE;
    c.size = 8;
    lib3ds_chunk_write(&c, io);
    lib3ds_io_write_intw(io, (uint8_t)floor(100.0*p + 0.5));
}
Beispiel #3
0
static Lib3dsBool
kfdata_write(Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;

  if (!file->nodes) {
    return(LIB3DS_TRUE);
  }
  
  c.chunk=LIB3DS_KFDATA;
  if (!lib3ds_chunk_write_start(&c,io)) {
    return(LIB3DS_FALSE);
  }
  
  { /*---- LIB3DS_KFHDR ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_KFHDR;
    c.size=6 + 2 + (Lib3dsDword)strlen(file->name)+1 +4;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_intw(io, file->keyf_revision);
    lib3ds_io_write_string(io, file->name);
    lib3ds_io_write_intd(io, file->frames);
  }
  { /*---- LIB3DS_KFSEG ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_KFSEG;
    c.size=14;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_intd(io, file->segment_from);
    lib3ds_io_write_intd(io, file->segment_to);
  }
  { /*---- LIB3DS_KFCURTIME ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_KFCURTIME;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_intd(io, file->current_frame);
  }
  lib3ds_viewport_write(&file->viewport_keyf, io);
  
  {
    Lib3dsNode *p;
    for (p=file->nodes; p!=0; p=p->next) {
      if (!lib3ds_node_write(p, file, io)) {
        return(LIB3DS_FALSE);
      }
      if (!nodes_write(p, file, io)) {
        return(LIB3DS_FALSE);
      }
    }
  }
  
  if (!lib3ds_chunk_write_end(&c,io)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
static Lib3dsBool
int_percentage_write(Lib3dsFloat p, Lib3dsIo *io)
{
  Lib3dsChunk c;

  c.chunk=LIB3DS_INT_PERCENTAGE;
  c.size=8;
  lib3ds_chunk_write(&c,io);
  lib3ds_io_write_intw(io, (Lib3dsByte)floor(100.0*p+0.5));

  return(LIB3DS_TRUE);
}
Beispiel #5
0
static void
kfdata_write(Lib3dsFile *file, Lib3dsIo *io) {
    Lib3dsChunk c;

    if (!file->nodes) {
        return;
    }

    c.chunk = CHK_KFDATA;
    lib3ds_chunk_write_start(&c, io);

    { /*---- LIB3DS_KFHDR ----*/
        Lib3dsChunk c;
        c.chunk = CHK_KFHDR;
        c.size = 6 + 2 + (uint32_t)strlen(file->name) + 1 + 4;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_intw(io, (int16_t)file->keyf_revision);
        lib3ds_io_write_string(io, file->name);
        lib3ds_io_write_intd(io, file->frames);
    }
    { /*---- LIB3DS_KFSEG ----*/
        Lib3dsChunk c;
        c.chunk = CHK_KFSEG;
        c.size = 14;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_intd(io, file->segment_from);
        lib3ds_io_write_intd(io, file->segment_to);
    }
    { /*---- LIB3DS_KFCURTIME ----*/
        Lib3dsChunk c;
        c.chunk = CHK_KFCURTIME;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_intd(io, file->current_frame);
    }
    lib3ds_viewport_write(&file->viewport_keyf, io);

    {
        uint16_t default_id = 0;
        nodes_write(file->nodes, &default_id, 65535, io);
    }

    lib3ds_chunk_write_end(&c, io);
}
void
lib3ds_shadow_write(Lib3dsShadow *shadow, Lib3dsIo *io) {
    if (fabs(shadow->low_bias) > LIB3DS_EPSILON) { /*---- CHK_LO_SHADOW_BIAS ----*/
        Lib3dsChunk c;
        c.chunk = CHK_LO_SHADOW_BIAS;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, shadow->low_bias);
    }

    if (fabs(shadow->hi_bias) > LIB3DS_EPSILON) { /*---- CHK_HI_SHADOW_BIAS ----*/
        Lib3dsChunk c;
        c.chunk = CHK_HI_SHADOW_BIAS;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, shadow->hi_bias);
    }

    if (shadow->map_size) { /*---- CHK_SHADOW_MAP_SIZE ----*/
        Lib3dsChunk c;
        c.chunk = CHK_SHADOW_MAP_SIZE;
        c.size = 8;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_intw(io, shadow->map_size);
    }

    if (fabs(shadow->filter) > LIB3DS_EPSILON) { /*---- CHK_SHADOW_FILTER ----*/
        Lib3dsChunk c;
        c.chunk = CHK_SHADOW_FILTER;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, shadow->filter);
    }
    if (fabs(shadow->ray_bias) > LIB3DS_EPSILON) { /*---- CHK_RAY_BIAS ----*/
        Lib3dsChunk c;
        c.chunk = CHK_RAY_BIAS;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, shadow->ray_bias);
    }
}
Beispiel #7
0
void
lib3ds_material_write(Lib3dsMaterial *material, Lib3dsIo *io) {
    Lib3dsChunk c;

    c.chunk = CHK_MAT_ENTRY;
    lib3ds_chunk_write_start(&c, io);

    {   /*---- CHK_MAT_NAME ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_NAME;
        c.size = 6 + (uint32_t)strlen(material->name) + 1;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_string(io, material->name);
    }

    {   /*---- CHK_MAT_AMBIENT ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_AMBIENT;
        c.size = 24;
        lib3ds_chunk_write(&c, io);
        color_write(material->ambient, io);
    }

    {   /*---- CHK_MAT_DIFFUSE ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_DIFFUSE;
        c.size = 24;
        lib3ds_chunk_write(&c, io);
        color_write(material->diffuse, io);
    }

    {   /*---- CHK_MAT_SPECULAR ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_SPECULAR;
        c.size = 24;
        lib3ds_chunk_write(&c, io);
        color_write(material->specular, io);
    }

    {   /*---- CHK_MAT_SHININESS ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_SHININESS;
        c.size = 14;
        lib3ds_chunk_write(&c, io);
        int_percentage_write(material->shininess, io);
    }

    {   /*---- CHK_MAT_SHIN2PCT ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_SHIN2PCT;
        c.size = 14;
        lib3ds_chunk_write(&c, io);
        int_percentage_write(material->shin_strength, io);
    }

    {   /*---- CHK_MAT_TRANSPARENCY ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_TRANSPARENCY;
        c.size = 14;
        lib3ds_chunk_write(&c, io);
        int_percentage_write(material->transparency, io);
    }

    {   /*---- CHK_MAT_XPFALL ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_XPFALL;
        c.size = 14;
        lib3ds_chunk_write(&c, io);
        int_percentage_write(material->falloff, io);
    }

    if (material->use_falloff) { /*---- CHK_MAT_USE_XPFALL ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_USE_XPFALL;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    {   /*---- CHK_MAT_SHADING ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_SHADING;
        c.size = 8;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_intw(io, material->shading);
    }

    {   /*---- CHK_MAT_REFBLUR ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_REFBLUR;
        c.size = 14;
        lib3ds_chunk_write(&c, io);
        int_percentage_write(material->blur, io);
    }

    if (material->use_blur) { /*---- CHK_MAT_USE_REFBLUR ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_USE_REFBLUR;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (material->self_illum_flag) { /*---- CHK_MAT_SELF_ILLUM ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_SELF_ILLUM;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (material->two_sided) { /*---- CHK_MAT_TWO_SIDE ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_TWO_SIDE;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (material->map_decal) { /*---- CHK_MAT_DECAL ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_DECAL;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (material->is_additive) { /*---- CHK_MAT_ADDITIVE ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_ADDITIVE;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (material->use_wire) { /*---- CHK_MAT_WIRE ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_WIRE;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (material->use_wire_abs) { /*---- CHK_MAT_WIREABS ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_WIREABS;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    {   /*---- CHK_MAT_WIRE_SIZE ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_WIRE_SIZE;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, material->wire_size);
    }

    if (material->face_map) { /*---- CHK_MAT_FACEMAP ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_FACEMAP;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (material->soften) { /*---- CHK_MAT_PHONGSOFT ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_PHONGSOFT;
        c.size = 6;
        lib3ds_chunk_write(&c, io);
    }

    texture_map_write(CHK_MAT_TEXMAP, &material->texture1_map, io);
    texture_map_write(CHK_MAT_TEXMASK, &material->texture1_mask, io);
    texture_map_write(CHK_MAT_TEX2MAP, &material->texture2_map, io);
    texture_map_write(CHK_MAT_TEX2MASK, &material->texture2_mask, io);
    texture_map_write(CHK_MAT_OPACMAP, &material->opacity_map, io);
    texture_map_write(CHK_MAT_OPACMASK, &material->opacity_mask, io);
    texture_map_write(CHK_MAT_BUMPMAP, &material->bump_map, io);
    texture_map_write(CHK_MAT_BUMPMASK, &material->bump_mask, io);
    texture_map_write(CHK_MAT_SPECMAP, &material->specular_map, io);
    texture_map_write(CHK_MAT_SPECMASK, &material->specular_mask, io);
    texture_map_write(CHK_MAT_SHINMAP, &material->shininess_map, io);
    texture_map_write(CHK_MAT_SHINMASK, &material->shininess_mask, io);
    texture_map_write(CHK_MAT_SELFIMAP, &material->self_illum_map, io);
    texture_map_write(CHK_MAT_SELFIMASK, &material->self_illum_mask, io);
    texture_map_write(CHK_MAT_REFLMAP,  &material->reflection_map, io);
    texture_map_write(CHK_MAT_REFLMASK,  &material->reflection_mask, io);

    {   /*---- CHK_MAT_ACUBIC ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_ACUBIC;
        c.size = 18;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_intb(io, 0);
        lib3ds_io_write_intb(io, material->autorefl_map_anti_alias);
        lib3ds_io_write_intw(io, material->autorefl_map_flags);
        lib3ds_io_write_intd(io, material->autorefl_map_size);
        lib3ds_io_write_intd(io, material->autorefl_map_frame_step);
    }

    lib3ds_chunk_write_end(&c, io);
}
Beispiel #8
0
/*!
 * \ingroup node
 */
Lib3dsBool
lib3ds_node_write(Lib3dsNode *node, Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;

  switch (node->type) {
    case LIB3DS_AMBIENT_NODE:
      c.chunk=LIB3DS_AMBIENT_NODE_TAG;
      break;
    case LIB3DS_OBJECT_NODE:
      c.chunk=LIB3DS_OBJECT_NODE_TAG;
      break;
    case LIB3DS_CAMERA_NODE:
      c.chunk=LIB3DS_CAMERA_NODE_TAG;
      break;
    case LIB3DS_TARGET_NODE:
      c.chunk=LIB3DS_TARGET_NODE_TAG;
      break;
    case LIB3DS_LIGHT_NODE:
      if (lib3ds_file_node_by_name(file, node->name, LIB3DS_SPOT_NODE)) {
        c.chunk=LIB3DS_SPOTLIGHT_NODE_TAG;
      }
      else {
        c.chunk=LIB3DS_LIGHT_NODE_TAG;
      }
      break;
    case LIB3DS_SPOT_NODE:
      c.chunk=LIB3DS_L_TARGET_NODE_TAG;
      break;
    default:
      return(LIB3DS_FALSE);
  }
  if (!lib3ds_chunk_write_start(&c,io)) {
    return(LIB3DS_FALSE);
  }

  { /*---- LIB3DS_NODE_ID ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_NODE_ID;
    c.size=8;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_intw(io, node->node_id);
  }

  { /*---- LIB3DS_NODE_HDR ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_NODE_HDR;
    c.size=6+ 1+(Lib3dsDword)strlen(node->name) +2+2+2;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_string(io, node->name);
    lib3ds_io_write_word(io, node->flags1);
    lib3ds_io_write_word(io, node->flags2);
    lib3ds_io_write_word(io, node->parent_id);
  }

  switch (c.chunk) {
    case LIB3DS_AMBIENT_NODE_TAG:
      { /*---- LIB3DS_COL_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_COL_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.ambient.col_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      break;
    case LIB3DS_OBJECT_NODE_TAG:
      { /*---- LIB3DS_PIVOT ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_PIVOT;
        c.size=18;
        lib3ds_chunk_write(&c,io);
        lib3ds_io_write_vector(io, node->data.object.pivot);
      }
      { /*---- LIB3DS_INSTANCE_NAME ----*/
        Lib3dsChunk c;
        const char *name;
        if (strlen(node->data.object.instance)) {
          name=node->data.object.instance;

          c.chunk=LIB3DS_INSTANCE_NAME;
          c.size=6+1+(Lib3dsDword)strlen(name);
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_string(io, name);
        }
      }
      {
        int i;
        for (i=0; i<3; ++i) {
          if ((fabs(node->data.object.bbox_min[i])>LIB3DS_EPSILON) ||
            (fabs(node->data.object.bbox_max[i])>LIB3DS_EPSILON)) {
            break;
          }
        }
        
        if (i<3) { /*---- LIB3DS_BOUNDBOX ----*/
          Lib3dsChunk c;
          c.chunk=LIB3DS_BOUNDBOX;
          c.size=30;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, node->data.object.bbox_min);
          lib3ds_io_write_vector(io, node->data.object.bbox_max);
        }
      }
      { /*---- LIB3DS_POS_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_POS_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.object.pos_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_ROT_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_ROT_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_quat_track_write(&node->data.object.rot_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_SCL_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_SCL_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.object.scl_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      if (node->data.object.hide_track.keyL) { /*---- LIB3DS_HIDE_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_HIDE_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_bool_track_write(&node->data.object.hide_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      if (fabs(node->data.object.morph_smooth)>LIB3DS_EPSILON){ /*---- LIB3DS_MORPH_SMOOTH ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_MORPH_SMOOTH;
        c.size=10;
        lib3ds_chunk_write(&c,io);
        lib3ds_io_write_float(io, node->data.object.morph_smooth);
      }
      break;
    case LIB3DS_CAMERA_NODE_TAG:
      { /*---- LIB3DS_POS_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_POS_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.camera.pos_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_FOV_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_FOV_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin1_track_write(&node->data.camera.fov_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_ROLL_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_ROLL_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin1_track_write(&node->data.camera.roll_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      break;
    case LIB3DS_TARGET_NODE_TAG:
      { /*---- LIB3DS_POS_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_POS_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.target.pos_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      break;
    case LIB3DS_LIGHT_NODE_TAG:
      { /*---- LIB3DS_POS_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_POS_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.light.pos_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_COL_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_COL_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.light.col_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      break;
    case LIB3DS_SPOTLIGHT_NODE_TAG:
      { /*---- LIB3DS_POS_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_POS_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.light.pos_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_COL_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_COL_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.light.col_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_HOT_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_HOT_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin1_track_write(&node->data.light.hotspot_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_FALL_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_FALL_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin1_track_write(&node->data.light.falloff_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      { /*---- LIB3DS_ROLL_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_ROLL_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin1_track_write(&node->data.light.roll_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      break;
    case LIB3DS_L_TARGET_NODE_TAG:
      { /*---- LIB3DS_POS_TRACK_TAG ----*/
        Lib3dsChunk c;
        c.chunk=LIB3DS_POS_TRACK_TAG;
        if (!lib3ds_chunk_write_start(&c,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_lin3_track_write(&node->data.spot.pos_track,io)) {
          return(LIB3DS_FALSE);
        }
        if (!lib3ds_chunk_write_end(&c,io)) {
          return(LIB3DS_FALSE);
        }
      }
      break;
    default:
      return(LIB3DS_FALSE);
  }

  if (!lib3ds_chunk_write_end(&c,io)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
Beispiel #9
0
void
lib3ds_node_write(Lib3dsNode *node, uint16_t node_id, uint16_t parent_id, Lib3dsIo *io) {
    Lib3dsChunk c;

    switch (node->type) {
        case LIB3DS_NODE_AMBIENT_COLOR:
            c.chunk = CHK_AMBIENT_NODE_TAG;
            break;

        case LIB3DS_NODE_MESH_INSTANCE:
            c.chunk = CHK_OBJECT_NODE_TAG;
            break;

        case LIB3DS_NODE_CAMERA:
            c.chunk = CHK_CAMERA_NODE_TAG;
            break;

        case LIB3DS_NODE_CAMERA_TARGET:
            c.chunk = CHK_TARGET_NODE_TAG;
            break;

        case LIB3DS_NODE_OMNILIGHT:
            c.chunk = CHK_LIGHT_NODE_TAG;
            break;

        case LIB3DS_NODE_SPOTLIGHT:
            c.chunk = CHK_SPOTLIGHT_NODE_TAG;
            break;

        case LIB3DS_NODE_SPOTLIGHT_TARGET:
            c.chunk = CHK_L_TARGET_NODE_TAG;
            break;

        default:
            assert(0);
            return;
    }

    lib3ds_chunk_write_start(&c, io);

    { /*---- CHK_NODE_ID ----*/
        Lib3dsChunk c;
        c.chunk = CHK_NODE_ID;
        c.size = 8;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_intw(io, node_id);
    }

    { /*---- CHK_NODE_HDR ----*/
        Lib3dsChunk c;
        c.chunk = CHK_NODE_HDR;
        c.size = 6 + 1 + (uint32_t)strlen(node->name) + 2 + 2 + 2;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_string(io, node->name);
        lib3ds_io_write_word(io, node->flags & 0xffff);
        lib3ds_io_write_word(io, (node->flags >> 16) & 0xffff);
        lib3ds_io_write_word(io, parent_id);
    }

    switch (c.chunk) {
        case CHK_AMBIENT_NODE_TAG: {
            Lib3dsAmbientColorNode *n = (Lib3dsAmbientColorNode*)node;
            if (n->color_track.nkeys) { /*---- CHK_COL_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_COL_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->color_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            break;
        }

        case CHK_OBJECT_NODE_TAG: {
            Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;
            { /*---- CHK_PIVOT ----*/
                Lib3dsChunk c;
                c.chunk = CHK_PIVOT;
                c.size = 18;
                lib3ds_chunk_write(&c, io);
                lib3ds_io_write_vector(io, n->pivot);
            }

            { /*---- CHK_INSTANCE_NAME ----*/
                Lib3dsChunk c;
                const char *name;
                if (strlen(n->instance_name)) {
                    name = n->instance_name;

                    c.chunk = CHK_INSTANCE_NAME;
                    c.size = 6 + 1 + (uint32_t)strlen(name);
                    lib3ds_chunk_write(&c, io);
                    lib3ds_io_write_string(io, name);
                }
            }
            {
                int i;
                for (i = 0; i < 3; ++i) {
                    if ((fabs(n->bbox_min[i]) > LIB3DS_EPSILON) ||
                        (fabs(n->bbox_max[i]) > LIB3DS_EPSILON)) {
                        break;
                    }
                }

                if (i < 3) { /*---- CHK_BOUNDBOX ----*/
                    Lib3dsChunk c;
                    c.chunk = CHK_BOUNDBOX;
                    c.size = 30;
                    lib3ds_chunk_write(&c, io);
                    lib3ds_io_write_vector(io, n->bbox_min);
                    lib3ds_io_write_vector(io, n->bbox_max);
                }
            }

            if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_POS_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->pos_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->rot_track.nkeys) { /*---- CHK_ROT_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_ROT_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->rot_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->scl_track.nkeys) { /*---- LIB3DS_SCL_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_SCL_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->scl_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->hide_track.nkeys) { /*---- CHK_HIDE_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_HIDE_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->hide_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (fabs(n->morph_smooth) > LIB3DS_EPSILON) { /*---- CHK_MORPH_SMOOTH ----*/
                Lib3dsChunk c;
                c.chunk = CHK_MORPH_SMOOTH;
                c.size = 10;
                lib3ds_chunk_write(&c, io);
                lib3ds_io_write_float(io, n->morph_smooth);
            }
            break;
        }

        case CHK_CAMERA_NODE_TAG: {
            Lib3dsCameraNode *n = (Lib3dsCameraNode*)node;
            if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_POS_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->pos_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->fov_track.nkeys) { /*---- CHK_FOV_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_FOV_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->fov_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->roll_track.nkeys) { /*---- CHK_ROLL_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_ROLL_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->roll_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            break;
        }

        case CHK_TARGET_NODE_TAG: {
            Lib3dsTargetNode *n = (Lib3dsTargetNode*)node;
            if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_POS_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->pos_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            break;
        }

        case CHK_LIGHT_NODE_TAG: {
            Lib3dsOmnilightNode *n = (Lib3dsOmnilightNode*)node;
            if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_POS_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->pos_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->color_track.nkeys) { /*---- CHK_COL_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_COL_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->color_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            break;
        }

        case CHK_SPOTLIGHT_NODE_TAG: {
            Lib3dsSpotlightNode *n = (Lib3dsSpotlightNode*)node;
            if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_POS_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->pos_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->color_track.nkeys) { /*---- CHK_COL_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_COL_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->color_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->hotspot_track.nkeys) { /*---- CHK_HOT_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_HOT_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->hotspot_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->falloff_track.nkeys) { /*---- CHK_FALL_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_FALL_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->falloff_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            if (n->roll_track.nkeys) { /*---- CHK_ROLL_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_ROLL_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->roll_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            break;
        }

        case CHK_L_TARGET_NODE_TAG: {
            Lib3dsTargetNode *n = (Lib3dsTargetNode*)node;
            if (n->pos_track.nkeys) { /*---- CHK_POS_TRACK_TAG ----*/
                Lib3dsChunk c;
                c.chunk = CHK_POS_TRACK_TAG;
                lib3ds_chunk_write_start(&c, io);
                lib3ds_track_write(&n->pos_track, io);
                lib3ds_chunk_write_end(&c, io);
            }
            break;
        }

        default:
            break;
    }

    lib3ds_chunk_write_end(&c, io);
}
Beispiel #10
0
/*!
 * \ingroup light
 */
Lib3dsBool
lib3ds_light_write(Lib3dsLight *light, Lib3dsIo *io)
{
  Lib3dsChunk c;

  c.chunk=LIB3DS_N_DIRECT_LIGHT;
  if (!lib3ds_chunk_write_start(&c,io)) {
    return(LIB3DS_FALSE);
  }
  lib3ds_io_write_vector(io, light->position);
  { /*---- LIB3DS_COLOR_F ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_COLOR_F;
    c.size=18;
    lib3ds_chunk_write(&c, io);
    lib3ds_io_write_rgb(io, light->color);
  }
  if (light->off) { /*---- LIB3DS_DL_OFF ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_DL_OFF;
    c.size=6;
    lib3ds_chunk_write(&c, io);
  }
  { /*---- LIB3DS_DL_OUTER_RANGE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_DL_OUTER_RANGE;
    c.size=10;
    lib3ds_chunk_write(&c, io);
    lib3ds_io_write_float(io, light->outer_range);
  }
  { /*---- LIB3DS_DL_INNER_RANGE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_DL_INNER_RANGE;
    c.size=10;
    lib3ds_chunk_write(&c, io);
    lib3ds_io_write_float(io, light->inner_range);
  }
  { /*---- LIB3DS_DL_MULTIPLIER ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_DL_MULTIPLIER;
    c.size=10;
    lib3ds_chunk_write(&c, io);
    lib3ds_io_write_float(io, light->multiplier);
  }
  if (light->attenuation) { /*---- LIB3DS_DL_ATTENUATE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_DL_ATTENUATE;
    c.size=6;
    lib3ds_chunk_write(&c, io);
  }

  if (light->spot_light) {
    Lib3dsChunk c;

    c.chunk=LIB3DS_DL_SPOTLIGHT;
    if (!lib3ds_chunk_write_start(&c,io)) {
      return(LIB3DS_FALSE);
    }
    lib3ds_io_write_vector(io, light->spot);
    lib3ds_io_write_float(io, light->hot_spot);
    lib3ds_io_write_float(io, light->fall_off);
    
    { /*---- LIB3DS_DL_SPOT_ROLL ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_SPOT_ROLL;
      c.size=10;
      lib3ds_chunk_write(&c, io);
      lib3ds_io_write_float(io, light->roll);
    }
    if (light->shadowed) { /*---- LIB3DS_DL_SHADOWED ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_SHADOWED;
      c.size=6;
      lib3ds_chunk_write(&c, io);
    }
    if ((fabs(light->shadow_bias)>LIB3DS_EPSILON) ||
      (fabs(light->shadow_filter)>LIB3DS_EPSILON) ||
      (light->shadow_size!=0)) { /*---- LIB3DS_DL_LOCAL_SHADOW2 ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_LOCAL_SHADOW2;
      c.size=16;
      lib3ds_chunk_write(&c, io);
      lib3ds_io_write_float(io, light->shadow_bias);
      lib3ds_io_write_float(io, light->shadow_filter);
      lib3ds_io_write_intw(io, light->shadow_size);
    }
    if (light->see_cone) { /*---- LIB3DS_DL_SEE_CONE ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_SEE_CONE;
      c.size=6;
      lib3ds_chunk_write(&c, io);
    }
    if (light->rectangular_spot) { /*---- LIB3DS_DL_SPOT_RECTANGULAR ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_SPOT_RECTANGULAR;
      c.size=6;
      lib3ds_chunk_write(&c, io);
    }
    if (fabs(light->spot_aspect)>LIB3DS_EPSILON) { /*---- LIB3DS_DL_SPOT_ASPECT ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_SPOT_ASPECT;
      c.size=10;
      lib3ds_chunk_write(&c, io);
      lib3ds_io_write_float(io, light->spot_aspect);
    }
    if (light->use_projector) { /*---- LIB3DS_DL_SPOT_PROJECTOR ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_SPOT_PROJECTOR;
      c.size=10;
      lib3ds_chunk_write(&c, io);
      lib3ds_io_write_string(io, light->projector);
    }
    if (light->spot_overshoot) { /*---- LIB3DS_DL_SPOT_OVERSHOOT ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_SPOT_OVERSHOOT;
      c.size=6;
      lib3ds_chunk_write(&c, io);
    }
    if (fabs(light->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_DL_RAY_BIAS ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_RAY_BIAS;
      c.size=10;
      lib3ds_chunk_write(&c, io);
      lib3ds_io_write_float(io, light->ray_bias);
    }
    if (light->ray_shadows) { /*---- LIB3DS_DL_RAYSHAD ----*/
      Lib3dsChunk c;
      c.chunk=LIB3DS_DL_RAYSHAD;
      c.size=6;
      lib3ds_chunk_write(&c, io);
    }
    if (!lib3ds_chunk_write_end(&c,io)) {
      return(LIB3DS_FALSE);
    }
  }
  if (!lib3ds_chunk_write_end(&c,io)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
Beispiel #11
0
/*!
 * \ingroup viewport 
 */
Lib3dsBool
lib3ds_viewport_write(Lib3dsViewport *viewport, Lib3dsIo *io)
{
  if (viewport->layout.views) {
    Lib3dsChunk c;
    unsigned i;

    c.chunk=LIB3DS_VIEWPORT_LAYOUT;
    if (!lib3ds_chunk_write_start(&c,io)) {
      return(LIB3DS_FALSE);
    }

    lib3ds_io_write_word(io, viewport->layout.style);
    lib3ds_io_write_intw(io, viewport->layout.active);
    lib3ds_io_write_intw(io, 0);
    lib3ds_io_write_intw(io, viewport->layout.swap);
    lib3ds_io_write_intw(io, 0);
    lib3ds_io_write_intw(io, viewport->layout.swap_prior);
    lib3ds_io_write_intw(io, viewport->layout.swap_view);
    
    {
      Lib3dsChunk c;
      c.chunk=LIB3DS_VIEWPORT_SIZE;
      c.size=14;
      lib3ds_chunk_write(&c,io);
      lib3ds_io_write_intw(io, viewport->layout.position[0]);
      lib3ds_io_write_intw(io, viewport->layout.position[1]);
      lib3ds_io_write_intw(io, viewport->layout.size[0]);
      lib3ds_io_write_intw(io, viewport->layout.size[1]);
    }

    for (i=0; i<viewport->layout.views; ++i) {
      Lib3dsChunk c;
      c.chunk=LIB3DS_VIEWPORT_DATA_3;
      c.size=55;
      lib3ds_chunk_write(&c,io);

      lib3ds_io_write_intw(io, 0);
      lib3ds_io_write_word(io, viewport->layout.viewL[i].axis_lock);
      lib3ds_io_write_intw(io, viewport->layout.viewL[i].position[0]);
      lib3ds_io_write_intw(io, viewport->layout.viewL[i].position[1]);
      lib3ds_io_write_intw(io, viewport->layout.viewL[i].size[0]);
      lib3ds_io_write_intw(io, viewport->layout.viewL[i].size[1]);
      lib3ds_io_write_word(io, viewport->layout.viewL[i].type);
      lib3ds_io_write_float(io, viewport->layout.viewL[i].zoom);
      lib3ds_io_write_vector(io, viewport->layout.viewL[i].center);
      lib3ds_io_write_float(io, viewport->layout.viewL[i].horiz_angle);
      lib3ds_io_write_float(io, viewport->layout.viewL[i].vert_angle);
      lib3ds_io_write(io, viewport->layout.viewL[i].camera,11);
    }

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

  if (viewport->default_view.type) {
    Lib3dsChunk c;

    c.chunk=LIB3DS_DEFAULT_VIEW;
    if (!lib3ds_chunk_write_start(&c,io)) {
      return(LIB3DS_FALSE);
    }

    switch (viewport->default_view.type) {
      case LIB3DS_VIEW_TYPE_TOP:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_TOP;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_BOTTOM:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_BOTTOM;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_LEFT:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_LEFT;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_RIGHT:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_RIGHT;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_FRONT:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_FRONT;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_BACK:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_BACK;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_USER:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_USER;
          c.size=34;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
          lib3ds_io_write_float(io, viewport->default_view.horiz_angle);
          lib3ds_io_write_float(io, viewport->default_view.vert_angle);
          lib3ds_io_write_float(io, viewport->default_view.roll_angle);
        }
        break;
      case LIB3DS_VIEW_TYPE_CAMERA:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_CAMERA;
          c.size=17;
          lib3ds_chunk_write(&c, io);
          lib3ds_io_write(io, viewport->default_view.camera, 11);
        }
        break;
    }

    if (!lib3ds_chunk_write_end(&c, io)) {
      return(LIB3DS_FALSE);
    }
  }
  return(LIB3DS_TRUE);
}