static void
colorf_write(float rgb[3], Lib3dsIo *io) {
    Lib3dsChunk c;

    c.chunk = CHK_COLOR_F;
    c.size = 18;
    lib3ds_chunk_write(&c, io);
    lib3ds_io_write_rgb(io, rgb);

    c.chunk = CHK_LIN_COLOR_F;
    c.size = 18;
    lib3ds_chunk_write(&c, io);
    lib3ds_io_write_rgb(io, rgb);
}
Example #2
0
static Lib3dsBool
colorf_write(Lib3dsRgba rgb, Lib3dsIo *io)
{
  Lib3dsChunk c;

  c.chunk=LIB3DS_COLOR_F;
  c.size=18;
  lib3ds_chunk_write(&c,io);
  lib3ds_io_write_rgb(io, rgb);

  c.chunk=LIB3DS_LIN_COLOR_F;
  c.size=18;
  lib3ds_chunk_write(&c,io);
  lib3ds_io_write_rgb(io, rgb);
  return(LIB3DS_TRUE);
}
Example #3
0
/*!
 * \ingroup atmosphere
 */
Lib3dsBool
lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
{
  if (atmosphere->fog.use) { /*---- LIB3DS_FOG ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_FOG;
    if (!lib3ds_chunk_write_start(&c,io)) {
      return(LIB3DS_FALSE);
    }
    lib3ds_io_write_float(io, atmosphere->fog.near_plane);
    lib3ds_io_write_float(io, atmosphere->fog.near_density);
    lib3ds_io_write_float(io, atmosphere->fog.far_plane);
    lib3ds_io_write_float(io, atmosphere->fog.far_density);
    {
      Lib3dsChunk c;
      c.chunk=LIB3DS_COLOR_F;
      c.size=18;
      lib3ds_chunk_write(&c,io);
      lib3ds_io_write_rgb(io, atmosphere->fog.col);
    }
    if (atmosphere->fog.fog_background) {
      Lib3dsChunk c;
      c.chunk=LIB3DS_FOG_BGND;
      c.size=6;
      lib3ds_chunk_write(&c,io);
    }
    if (!lib3ds_chunk_write_end(&c,io)) {
      return(LIB3DS_FALSE);
    }
  }

  if (atmosphere->layer_fog.use) { /*---- LIB3DS_LAYER_FOG ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_LAYER_FOG;
    c.size=40;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, atmosphere->layer_fog.near_y);
    lib3ds_io_write_float(io, atmosphere->layer_fog.far_y);
    lib3ds_io_write_float(io, atmosphere->layer_fog.near_y);
    lib3ds_io_write_dword(io, atmosphere->layer_fog.flags);
    {
      Lib3dsChunk c;
      c.chunk=LIB3DS_COLOR_F;
      c.size=18;
      lib3ds_chunk_write(&c,io);
      lib3ds_io_write_rgb(io, atmosphere->fog.col);
    }
  }

  if (atmosphere->dist_cue.use) { /*---- LIB3DS_DISTANCE_CUE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_DISTANCE_CUE;
    if (!lib3ds_chunk_write_start(&c,io)) {
      return(LIB3DS_FALSE);
    }
    lib3ds_io_write_float(io, atmosphere->dist_cue.near_plane);
    lib3ds_io_write_float(io, atmosphere->dist_cue.near_dimming);
    lib3ds_io_write_float(io, atmosphere->dist_cue.far_plane);
    lib3ds_io_write_float(io, atmosphere->dist_cue.far_dimming);
    if (atmosphere->dist_cue.cue_background) {
      Lib3dsChunk c;
      c.chunk=LIB3DS_DCUE_BGND;
      c.size=6;
      lib3ds_chunk_write(&c,io);
    }
    if (!lib3ds_chunk_write_end(&c,io)) {
      return(LIB3DS_FALSE);
    }
  }

  if (atmosphere->fog.use) { /*---- LIB3DS_USE_FOG ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_USE_FOG;
    c.size=6;
    lib3ds_chunk_write(&c,io);
  }

  if (atmosphere->layer_fog.use) { /*---- LIB3DS_USE_LAYER_FOG ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_USE_LAYER_FOG;
    c.size=6;
    lib3ds_chunk_write(&c,io);
  }

  if (atmosphere->dist_cue.use) { /*---- LIB3DS_USE_DISTANCE_CUE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_USE_V_GRADIENT;
    c.size=6;
    lib3ds_chunk_write(&c,io);
  }
  
  return(LIB3DS_TRUE);
}
Example #4
0
File: light.c Project: DYFeng/mrpt
/*!
 * \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);
}
void
lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
{
    if (atmosphere->use_fog)   /*---- LIB3DS_FOG ----*/
    {
        Lib3dsChunk c;
        c.chunk = CHK_FOG;
        lib3ds_chunk_write_start(&c, io);

        lib3ds_io_write_float(io, atmosphere->fog_near_plane);
        lib3ds_io_write_float(io, atmosphere->fog_near_density);
        lib3ds_io_write_float(io, atmosphere->fog_far_plane);
        lib3ds_io_write_float(io, atmosphere->fog_far_density);
        {
            Lib3dsChunk c;
            c.chunk = CHK_COLOR_F;
            c.size  = 18;
            lib3ds_chunk_write(&c, io);
            lib3ds_io_write_rgb(io, atmosphere->fog_color);
        }
        if (atmosphere->fog_background)
        {
            Lib3dsChunk c;
            c.chunk = CHK_FOG_BGND;
            c.size  = 6;
            lib3ds_chunk_write(&c, io);
        }

        lib3ds_chunk_write_end(&c, io);
    }

    if (atmosphere->use_layer_fog)   /*---- LIB3DS_LAYER_FOG ----*/
    {
        Lib3dsChunk c;
        c.chunk = CHK_LAYER_FOG;
        c.size  = 40;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, atmosphere->layer_fog_near_y);
        lib3ds_io_write_float(io, atmosphere->layer_fog_far_y);
        lib3ds_io_write_float(io, atmosphere->layer_fog_near_y);
        lib3ds_io_write_dword(io, atmosphere->layer_fog_flags);
        {
            Lib3dsChunk c;
            c.chunk = CHK_COLOR_F;
            c.size  = 18;
            lib3ds_chunk_write(&c, io);
            lib3ds_io_write_rgb(io, atmosphere->fog_color);
        }
    }

    if (atmosphere->use_dist_cue)   /*---- LIB3DS_DISTANCE_CUE ----*/
    {
        Lib3dsChunk c;
        c.chunk = CHK_DISTANCE_CUE;
        lib3ds_chunk_write_start(&c, io);

        lib3ds_io_write_float(io, atmosphere->dist_cue_near_plane);
        lib3ds_io_write_float(io, atmosphere->dist_cue_near_dimming);
        lib3ds_io_write_float(io, atmosphere->dist_cue_far_plane);
        lib3ds_io_write_float(io, atmosphere->dist_cue_far_dimming);
        if (atmosphere->dist_cue_background)
        {
            Lib3dsChunk c;
            c.chunk = CHK_DCUE_BGND;
            c.size  = 6;
            lib3ds_chunk_write(&c, io);
        }

        lib3ds_chunk_write_end(&c, io);
    }

    if (atmosphere->use_fog)   /*---- LIB3DS_USE_FOG ----*/
    {
        Lib3dsChunk c;
        c.chunk = CHK_USE_FOG;
        c.size  = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (atmosphere->use_layer_fog)   /*---- LIB3DS_USE_LAYER_FOG ----*/
    {
        Lib3dsChunk c;
        c.chunk = CHK_USE_LAYER_FOG;
        c.size  = 6;
        lib3ds_chunk_write(&c, io);
    }

    if (atmosphere->use_dist_cue)   /*---- LIB3DS_USE_DISTANCE_CUE ----*/
    {
        Lib3dsChunk c;
        c.chunk = CHK_USE_V_GRADIENT;
        c.size  = 6;
        lib3ds_chunk_write(&c, io);
    }
}