Пример #1
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);
}
Пример #2
0
/*!
 * \ingroup material
 */
Lib3dsBool
lib3ds_material_write(Lib3dsMaterial *material, FILE *f)
{
  Lib3dsChunk c;

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

  { /*---- LIB3DS_MAT_NAME ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_NAME;
    c.size=6+strlen(material->name)+1;
    lib3ds_chunk_write(&c,f);
    lib3ds_string_write(material->name,f);
  }

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

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

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

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

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

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

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

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

  { /*---- LIB3DS_MAT_SHADING ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_SHADING;
    c.size=8;
    lib3ds_chunk_write(&c,f);
    lib3ds_intw_write(material->shading,f);
  }

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

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

  if (material->self_illum) { /*---- LIB3DS_MAT_SELF_ILLUM ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_SELF_ILLUM;
    c.size=6;
    lib3ds_chunk_write(&c,f);
  }

  if (material->two_sided) { /*---- LIB3DS_MAT_TWO_SIDE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_TWO_SIDE;
    c.size=6;
    lib3ds_chunk_write(&c,f);
  }
  
  if (material->map_decal) { /*---- LIB3DS_MAT_DECAL ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_DECAL;
    c.size=6;
    lib3ds_chunk_write(&c,f);
  }

  if (material->additive) { /*---- LIB3DS_MAT_ADDITIVE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_ADDITIVE;
    c.size=6;
    lib3ds_chunk_write(&c,f);
  }

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

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

  { /*---- LIB3DS_MAT_WIRE_SIZE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_WIRE_SIZE;
    c.size=10;
    lib3ds_chunk_write(&c,f);
    lib3ds_float_write(material->wire_size,f);
  }

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

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

  if (!texture_map_write(LIB3DS_MAT_TEXMAP, &material->texture1_map, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_TEXMASK, &material->texture1_mask, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_TEX2MAP, &material->texture2_map, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_TEX2MASK, &material->texture2_mask, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_OPACMAP, &material->opacity_map, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_OPACMASK, &material->opacity_mask, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_BUMPMAP, &material->bump_map, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_BUMPMASK, &material->bump_mask, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_SPECMAP, &material->specular_map, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_SPECMASK, &material->specular_mask, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_SHINMAP, &material->shininess_map, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_SHINMASK, &material->shininess_mask, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_SELFIMAP, &material->self_illum_map, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_SELFIMASK, &material->self_illum_mask, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_REFLMAP,  &material->reflection_map, f)) {
    return(LIB3DS_FALSE);
  }
  if (!texture_map_write(LIB3DS_MAT_REFLMASK,  &material->reflection_mask, f)) {
    return(LIB3DS_FALSE);
  }

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