示例#1
0
static void
point_array_write(Lib3dsMesh *mesh, Lib3dsIo *io) {
    Lib3dsChunk c;
    int i;

    c.chunk = CHK_POINT_ARRAY;
    c.size = 8 + 12 * mesh->nvertices;
    lib3ds_chunk_write(&c, io);

    lib3ds_io_write_word(io, (uint16_t) mesh->nvertices);

    if (lib3ds_matrix_det(mesh->matrix) >= 0.0f) {
        for (i = 0; i < mesh->nvertices; ++i) {
            lib3ds_io_write_vector(io, mesh->vertices[i]);
        }
    } else {
        /* Flip X coordinate of vertices if mesh matrix
           has negative determinant */
        float inv_matrix[4][4], M[4][4];
        float tmp[3];

        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_io_write_vector(io, tmp);
        }
    }
}
示例#2
0
文件: tcb.c 项目: MTolba/mrpt
/*!
 * \ingroup tcb
 */
Lib3dsBool
lib3ds_tcb_write(Lib3dsTcb *tcb, Lib3dsIo *io)
{
    lib3ds_io_write_intd(io, tcb->frame);
    lib3ds_io_write_word(io, tcb->flags);
    if (tcb->flags&LIB3DS_USE_TENSION) {
        lib3ds_io_write_float(io, tcb->tens);
    }
    if (tcb->flags&LIB3DS_USE_CONTINUITY) {
        lib3ds_io_write_float(io, tcb->cont);
    }
    if (tcb->flags&LIB3DS_USE_BIAS) {
        lib3ds_io_write_float(io, tcb->bias);
    }
    if (tcb->flags&LIB3DS_USE_EASE_TO) {
        lib3ds_io_write_float(io, tcb->ease_to);
    }
    if (tcb->flags&LIB3DS_USE_EASE_FROM) {
        lib3ds_io_write_float(io, tcb->ease_from);
    }
    if (lib3ds_io_error(io)) {
        return(LIB3DS_FALSE);
    }
    return(LIB3DS_TRUE);
}
/*!
 * Writes a 3d-Studio chunk header into a little endian file stream.
 *
 * \param c  The chunk to be written.
 * \param io The file stream.
 *
 * \return   True on success, False otherwise.
 */
void
lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
{
    assert(c);
    lib3ds_io_write_word(io, c->chunk);
    lib3ds_io_write_dword(io, c->size);
}
示例#4
0
void
lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io) {
    assert(c);
    c->size = 0;
    c->cur = lib3ds_io_tell(io);
    lib3ds_io_write_word(io, c->chunk);
    lib3ds_io_write_dword(io, c->size);
}
示例#5
0
static void
flag_array_write(Lib3dsMesh *mesh, Lib3dsIo *io) {
    Lib3dsChunk c;
    int i;

    if (!mesh->vflags) {
        return;
    }

    c.chunk = CHK_POINT_FLAG_ARRAY;
    c.size = 8 + 2 * mesh->nvertices;
    lib3ds_chunk_write(&c, io);

    lib3ds_io_write_word(io, (uint16_t) mesh->nvertices);
    for (i = 0; i < mesh->nvertices; ++i) {
        lib3ds_io_write_word(io, mesh->vflags[i]);
    }
}
示例#6
0
static Lib3dsBool
flag_array_write(Lib3dsMesh *mesh, Lib3dsIo *io)
{
  Lib3dsChunk c;
  unsigned i;
  
  if (!mesh->flags || !mesh->flagL) {
    return(LIB3DS_TRUE);
  }
  ASSERT(mesh->flags<0x10000);
  c.chunk=LIB3DS_POINT_FLAG_ARRAY;
  c.size=8+2*mesh->flags;
  lib3ds_chunk_write(&c, io);
  
  lib3ds_io_write_word(io, (Lib3dsWord)mesh->flags);
  for (i=0; i<mesh->flags; ++i) {
    lib3ds_io_write_word(io, mesh->flagL[i]);
  }
  return(LIB3DS_TRUE);
}
void
lib3ds_track_write(Lib3dsTrack *track, Lib3dsIo *io) {
    int i;

    lib3ds_io_write_word(io, (uint16_t)track->flags);
    lib3ds_io_write_dword(io, 0);
    lib3ds_io_write_dword(io, 0);
    lib3ds_io_write_dword(io, track->nkeys);

    switch (track->type) {
        case LIB3DS_TRACK_BOOL:
            for (i = 0; i < track->nkeys; ++i) {
                lib3ds_io_write_intd(io, track->keys[i].frame);
                tcb_write(&track->keys[i], io);
            }
            break;

        case LIB3DS_TRACK_FLOAT:
            for (i = 0; i < track->nkeys; ++i) {
                lib3ds_io_write_intd(io, track->keys[i].frame);
                tcb_write(&track->keys[i], io);
                lib3ds_io_write_float(io, track->keys[i].value[0]);
            }
            break;

        case LIB3DS_TRACK_VECTOR:
            for (i = 0; i < track->nkeys; ++i) {
                lib3ds_io_write_intd(io, track->keys[i].frame);
                tcb_write(&track->keys[i], io);
                lib3ds_io_write_vector(io, track->keys[i].value);
            }
            break;

        case LIB3DS_TRACK_QUAT:
            for (i = 0; i < track->nkeys; ++i) {
                lib3ds_io_write_intd(io, track->keys[i].frame);
                tcb_write(&track->keys[i], io);
                lib3ds_io_write_float(io, track->keys[i].value[3]);
                lib3ds_io_write_vector(io, track->keys[i].value);
            }
            break;

        /*case LIB3DS_TRACK_MORPH:
            for (i = 0; i < track->nkeys; ++i) {
                lib3ds_io_write_intd(io, track->keys[i].frame);
                tcb_write(&track->keys[i].tcb, io);
                lib3ds_io_write_string(io, track->keys[i].data.m.name);
            }
            break;*/
    }
}
/*!
 * \ingroup chunk
 *
 * Writes a 3d-Studio chunk header into a little endian file stream.
 *
 * \param c  The chunk to be written.
 * \param io The file stream.
 *
 * \return   True on success, False otherwise.
 */
Lib3dsBool
lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
{
  ASSERT(c);
  if (!lib3ds_io_write_word(io, c->chunk)) {
    LIB3DS_ERROR_LOG;
    return(LIB3DS_FALSE);
  }
  if (!lib3ds_io_write_dword(io, c->size)) {
    LIB3DS_ERROR_LOG;
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
/*!
 * \ingroup chunk
 */
Lib3dsBool
lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io)
{
  ASSERT(c);
  c->size=0;
  c->cur=lib3ds_io_tell(io);
  if (!lib3ds_io_write_word(io, c->chunk)) {
    return(LIB3DS_FALSE);
  }
  if (!lib3ds_io_write_dword(io, c->size)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
示例#10
0
static void
texco_array_write(Lib3dsMesh *mesh, Lib3dsIo *io) {
    Lib3dsChunk c;
    int i;

    if (!mesh->texcos) {
        return;
    }

    c.chunk = CHK_TEX_VERTS;
    c.size = 8 + 8 * mesh->nvertices;
    lib3ds_chunk_write(&c, io);

    lib3ds_io_write_word(io, mesh->nvertices);
    for (i = 0; i < mesh->nvertices; ++i) {
        lib3ds_io_write_float(io, mesh->texcos[i][0]);
        lib3ds_io_write_float(io, mesh->texcos[i][1]);
    }
}
void
tcb_write(Lib3dsKey *key, Lib3dsIo *io) {
    lib3ds_io_write_word(io, key->flags);
    if (key->flags & LIB3DS_KEY_USE_TENS) {
        lib3ds_io_write_float(io, key->tens);
    }
    if (key->flags & LIB3DS_KEY_USE_CONT) {
        lib3ds_io_write_float(io, key->cont);
    }
    if (key->flags & LIB3DS_KEY_USE_BIAS) {
        lib3ds_io_write_float(io, key->bias);
    }
    if (key->flags & LIB3DS_KEY_USE_EASE_TO) {
        lib3ds_io_write_float(io, key->ease_to);
    }
    if (key->flags & LIB3DS_KEY_USE_EASE_FROM) {
        lib3ds_io_write_float(io, key->ease_from);
    }
}
示例#12
0
文件: tracks.c 项目: refnum/quesa
/*!
 * \ingroup tracks 
 */
Lib3dsBool
lib3ds_bool_track_write(Lib3dsBoolTrack *track, Lib3dsIo *io)
{
  Lib3dsBoolKey *k;
  Lib3dsDword num=0;
  for (k=track->keyL; k; k=k->next) {
    ++num;
  }
  lib3ds_io_write_word(io, (Lib3dsWord)track->flags);
  lib3ds_io_write_dword(io, 0);
  lib3ds_io_write_dword(io, 0);
  lib3ds_io_write_dword(io, num);

  for (k=track->keyL; k; k=k->next) {
    if (!lib3ds_tcb_write(&k->tcb,io)) {
      return(LIB3DS_FALSE);
    }
  }
  return(LIB3DS_TRUE);
}
示例#13
0
static Lib3dsBool
point_array_write(Lib3dsMesh *mesh, Lib3dsIo *io)
{
  Lib3dsChunk c;
  unsigned i;

  if (!mesh->points || !mesh->pointL) {
    return(LIB3DS_TRUE);
  }
  ASSERT(mesh->points<0x10000);
  c.chunk=LIB3DS_POINT_ARRAY;
  c.size=8+12*mesh->points;
  lib3ds_chunk_write(&c, io);
  
  lib3ds_io_write_word(io, (Lib3dsWord)mesh->points);
  for (i=0; i<mesh->points; ++i) {
    lib3ds_io_write_vector(io, mesh->pointL[i].pos);
  }
  return(LIB3DS_TRUE);
}
示例#14
0
static Lib3dsBool
point_array_write(Lib3dsMesh *mesh, Lib3dsIo *io)
{
  Lib3dsChunk c;
  unsigned i;

  if (!mesh->points || !mesh->pointL) {
    return(LIB3DS_TRUE);
  }
  ASSERT(mesh->points<0x10000);
  c.chunk=LIB3DS_POINT_ARRAY;
  c.size=8+12*mesh->points;
  lib3ds_chunk_write(&c, io);
  
  lib3ds_io_write_word(io, (Lib3dsWord)mesh->points);

  if (lib3ds_matrix_det(mesh->matrix) >= 0.0f) {
    for (i=0; i<mesh->points; ++i) {
      lib3ds_io_write_vector(io, mesh->pointL[i].pos);
    }
  }
  else {
    /* Flip X coordinate of vertices if mesh matrix 
       has negative determinant */
    Lib3dsMatrix inv_matrix, M;
    Lib3dsVector tmp;

    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_io_write_vector(io, tmp);
    }
  }

  return(LIB3DS_TRUE);
}
示例#15
0
static Lib3dsBool
texel_array_write(Lib3dsMesh *mesh, Lib3dsIo *io)
{
  Lib3dsChunk c;
  unsigned i;
  
  if (!mesh->texels || !mesh->texelL) {
    return(LIB3DS_TRUE);
  }
  ASSERT(mesh->texels<0x10000);
  c.chunk=LIB3DS_TEX_VERTS;
  c.size=8+8*mesh->texels;
  lib3ds_chunk_write(&c, io);
  
  lib3ds_io_write_word(io, (Lib3dsWord)mesh->texels);
  for (i=0; i<mesh->texels; ++i) {
    lib3ds_io_write_float(io, mesh->texelL[i][0]);
    lib3ds_io_write_float(io, mesh->texelL[i][1]);
  }
  return(LIB3DS_TRUE);
}
示例#16
0
文件: tracks.c 项目: refnum/quesa
/*!
 * \ingroup tracks 
 */
Lib3dsBool
lib3ds_quat_track_write(Lib3dsQuatTrack *track, Lib3dsIo *io)
{
  Lib3dsQuatKey *k;
  Lib3dsDword num=0;
  for (k=track->keyL; k; k=k->next) {
    ++num;
  }
  lib3ds_io_write_word(io, (Lib3dsWord)track->flags);
  lib3ds_io_write_dword(io, 0);
  lib3ds_io_write_dword(io, 0);
  lib3ds_io_write_dword(io, num);

  for (k=track->keyL; k; k=k->next) {
    if (!lib3ds_tcb_write(&k->tcb,io)) {
      return(LIB3DS_FALSE);
    }
    lib3ds_io_write_float(io, k->angle);
    lib3ds_io_write_vector(io, k->axis);
  }
  return(LIB3DS_TRUE);
}
示例#17
0
static void
face_array_write(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io) {
    Lib3dsChunk c;

    if (mesh->nfaces == 0) {
        return;
    }
    c.chunk = CHK_FACE_ARRAY;
    lib3ds_chunk_write_start(&c, io);

    {
        int i;

        lib3ds_io_write_word(io, (uint16_t) mesh->nfaces);
        for (i = 0; i < mesh->nfaces; ++i) {
            lib3ds_io_write_word(io, mesh->faces[i].index[0]);
            lib3ds_io_write_word(io, mesh->faces[i].index[1]);
            lib3ds_io_write_word(io, mesh->faces[i].index[2]);
            lib3ds_io_write_word(io, mesh->faces[i].flags);
        }
    }

    {
        /*---- MSH_CHK_MAT_GROUP ----*/
        Lib3dsChunk c;
        int i, j;
        uint16_t num;
        char *matf = (char*)calloc(sizeof(char), mesh->nfaces);
		((Lib3dsIoImpl*)io->impl)->tmp_mem = matf;
        assert(matf);

        for (i = 0; i < mesh->nfaces; ++i) {
            if (!matf[i] && (mesh->faces[i].material >= 0) && (mesh->faces[i].material < file->nmaterials)) {
                matf[i] = 1;
                num = 1;

                for (j = i + 1; j < mesh->nfaces; ++j) {
                    if (mesh->faces[i].material == mesh->faces[j].material) ++num;
                }

                c.chunk = CHK_MSH_MAT_GROUP;
                c.size = 6 + (uint32_t)strlen(file->materials[mesh->faces[i].material]->name) + 1 + 2 + 2 * num;
                lib3ds_chunk_write(&c, io);
                lib3ds_io_write_string(io, file->materials[mesh->faces[i].material]->name);
                lib3ds_io_write_word(io, num);
                lib3ds_io_write_word(io, (uint16_t) i);

                for (j = i + 1; j < mesh->nfaces; ++j) {
                    if (mesh->faces[i].material == mesh->faces[j].material) {
                        lib3ds_io_write_word(io, (uint16_t) j);
                        matf[j] = 1;
                    }
                }
            }
        }
        ((Lib3dsIoImpl*)io->impl)->tmp_mem = NULL;
        free(matf);
    }

    {
        /*---- SMOOTH_GROUP ----*/
        Lib3dsChunk c;
        int i;

        c.chunk = CHK_SMOOTH_GROUP;
        c.size = 6 + 4 * mesh->nfaces;
        lib3ds_chunk_write(&c, io);

        for (i = 0; i < mesh->nfaces; ++i) {
            lib3ds_io_write_dword(io, mesh->faces[i].smoothing_group);
        }
    }

    {
        /*---- MSH_BOXMAP ----*/
        Lib3dsChunk c;

        if (strlen(mesh->box_front) ||
            strlen(mesh->box_back) ||
            strlen(mesh->box_left) ||
            strlen(mesh->box_right) ||
            strlen(mesh->box_top) ||
            strlen(mesh->box_bottom)) {

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

            lib3ds_io_write_string(io, mesh->box_front);
            lib3ds_io_write_string(io, mesh->box_back);
            lib3ds_io_write_string(io, mesh->box_left);
            lib3ds_io_write_string(io, mesh->box_right);
            lib3ds_io_write_string(io, mesh->box_top);
            lib3ds_io_write_string(io, mesh->box_bottom);

            lib3ds_chunk_write_end(&c, io);
        }
    }

    lib3ds_chunk_write_end(&c, io);
}
static Lib3dsBool
texture_map_write(Lib3dsWord chunk, Lib3dsTextureMap *map, Lib3dsIo *io)
{
  Lib3dsChunk c;

  if (strlen(map->name)==0) {
    return(LIB3DS_TRUE);
  }
  c.chunk=chunk;
  if (!lib3ds_chunk_write_start(&c,io)) {
    return(LIB3DS_FALSE);
  }
  
  int_percentage_write(map->percent,io);

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

  { /*---- LIB3DS_MAT_MAP_TILING ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_TILING;
    c.size=8;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_word(io, (Lib3dsWord)map->flags);
  }
  
  { /*---- LIB3DS_MAT_MAP_TEXBLUR ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_TEXBLUR;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, map->blur);
  }

  { /*---- LIB3DS_MAT_MAP_USCALE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_USCALE;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, map->scale[0]);
  }

  { /*---- LIB3DS_MAT_MAP_VSCALE ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_VSCALE;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, map->scale[1]);
  }

  { /*---- LIB3DS_MAT_MAP_UOFFSET ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_UOFFSET;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, map->offset[0]);
  }

  { /*---- LIB3DS_MAT_MAP_VOFFSET ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_VOFFSET;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, map->offset[1]);
  }

  { /*---- LIB3DS_MAT_MAP_ANG ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_ANG;
    c.size=10;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_float(io, map->rotation);
  }

  { /*---- LIB3DS_MAT_MAP_COL1 ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_COL1;
    c.size=9;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_1[0]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_1[1]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_1[2]+0.5));
  }

  { /*---- LIB3DS_MAT_MAP_COL2 ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_COL2;
    c.size=9;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_2[0]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_2[1]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_2[2]+0.5));
  }
  
  { /*---- LIB3DS_MAT_MAP_RCOL ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_RCOL;
    c.size=9;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_r[0]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_r[1]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_r[2]+0.5));
  }

  { /*---- LIB3DS_MAT_MAP_GCOL ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_GCOL;
    c.size=9;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_g[0]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_g[1]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_g[2]+0.5));
  }
  
  { /*---- LIB3DS_MAT_MAP_BCOL ----*/
    Lib3dsChunk c;
    c.chunk=LIB3DS_MAT_MAP_BCOL;
    c.size=9;
    lib3ds_chunk_write(&c,io);
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_b[0]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_b[1]+0.5));
    lib3ds_io_write_byte(io, (Lib3dsByte)floor(255.0*map->tint_b[2]+0.5));
  }

  if (!lib3ds_chunk_write_end(&c,io)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
示例#19
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);
}
示例#20
0
文件: node.c 项目: GYengera/mrpt
/*!
 * \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);
}
示例#21
0
/*!
 * \ingroup mesh
 */
Lib3dsBool
lib3ds_mesh_write(Lib3dsMesh *mesh, Lib3dsIo *io)
{
  Lib3dsChunk c;

  c.chunk=LIB3DS_N_TRI_OBJECT;
  if (!lib3ds_chunk_write_start(&c,io)) {
    return(LIB3DS_FALSE);
  }
  if (!point_array_write(mesh, io)) {
    return(LIB3DS_FALSE);
  }
  if (!texel_array_write(mesh, io)) {
    return(LIB3DS_FALSE);
  }

  if (mesh->map_data.maptype!=LIB3DS_MAP_NONE) { /*---- LIB3DS_MESH_TEXTURE_INFO ----*/
    Lib3dsChunk c;
    int i,j;
    
    c.chunk=LIB3DS_MESH_TEXTURE_INFO;
    c.size=92;
    if (!lib3ds_chunk_write(&c,io)) {
      return(LIB3DS_FALSE);
    }

    lib3ds_io_write_word(io, mesh->map_data.maptype);

    for (i=0; i<2; ++i) {
      lib3ds_io_write_float(io, mesh->map_data.tile[i]);
    }
    for (i=0; i<3; ++i) {
      lib3ds_io_write_float(io, mesh->map_data.pos[i]);
    }
    lib3ds_io_write_float(io, mesh->map_data.scale);

    for (i=0; i<4; i++) {
      for (j=0; j<3; j++) {
        lib3ds_io_write_float(io, mesh->map_data.matrix[i][j]);
      }
    }
    for (i=0; i<2; ++i) {
      lib3ds_io_write_float(io, mesh->map_data.planar_size[i]);
    }
    lib3ds_io_write_float(io, mesh->map_data.cylinder_height);
  }

  if (!flag_array_write(mesh, io)) {
    return(LIB3DS_FALSE);
  }
  { /*---- LIB3DS_MESH_MATRIX ----*/
    Lib3dsChunk c;
    int i,j;

    c.chunk=LIB3DS_MESH_MATRIX;
    c.size=54;
    if (!lib3ds_chunk_write(&c,io)) {
      return(LIB3DS_FALSE);
    }
    for (i=0; i<4; i++) {
      for (j=0; j<3; j++) {
        lib3ds_io_write_float(io, mesh->matrix[i][j]);
      }
    }
  }

  if (mesh->color) { /*---- LIB3DS_MESH_COLOR ----*/
    Lib3dsChunk c;
    
    c.chunk=LIB3DS_MESH_COLOR;
    c.size=7;
    if (!lib3ds_chunk_write(&c,io)) {
      return(LIB3DS_FALSE);
    }
    lib3ds_io_write_byte(io, mesh->color);
  }
  if (!face_array_write(mesh, io)) {
    return(LIB3DS_FALSE);
  }

  if (!lib3ds_chunk_write_end(&c,io)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
示例#22
0
static Lib3dsBool
face_array_write(Lib3dsMesh *mesh, Lib3dsIo *io)
{
  Lib3dsChunk c;
  
  if (!mesh->faces || !mesh->faceL) {
    return(LIB3DS_TRUE);
  }
  ASSERT(mesh->faces<0x10000);
  c.chunk=LIB3DS_FACE_ARRAY;
  if (!lib3ds_chunk_write_start(&c, io)) {
    return(LIB3DS_FALSE);
  }
  {
    unsigned i;

    lib3ds_io_write_word(io, (Lib3dsWord)mesh->faces);
    for (i=0; i<mesh->faces; ++i) {
      lib3ds_io_write_word(io, mesh->faceL[i].points[0]);
      lib3ds_io_write_word(io, mesh->faceL[i].points[1]);
      lib3ds_io_write_word(io, mesh->faceL[i].points[2]);
      lib3ds_io_write_word(io, mesh->faceL[i].flags);
    }
  }

  { /*---- MSH_MAT_GROUP ----*/
    Lib3dsChunk c;
    unsigned i,j;
    Lib3dsWord num;
    char *matf=calloc(sizeof(char), mesh->faces);
    if (!matf) {
      return(LIB3DS_FALSE);
    }
    
    for (i=0; i<mesh->faces; ++i) {
      if (!matf[i] && strlen(mesh->faceL[i].material)) {
        matf[i]=1;
        num=1;
        
        for (j=i+1; j<mesh->faces; ++j) {
          if (strcmp(mesh->faceL[i].material, mesh->faceL[j].material)==0) ++num;
        }
        
        c.chunk=LIB3DS_MSH_MAT_GROUP;
        c.size=6+ (Lib3dsDword)strlen(mesh->faceL[i].material)+1 +2+2*num;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_string(io, mesh->faceL[i].material);
        lib3ds_io_write_word(io, num);
        lib3ds_io_write_word(io, (Lib3dsWord)i);
        
        for (j=i+1; j<mesh->faces; ++j) {
          if (strcmp(mesh->faceL[i].material, mesh->faceL[j].material)==0) {
            lib3ds_io_write_word(io, (Lib3dsWord)j);
            matf[j]=1;
          }
        }
      }      
    }
    free(matf);
  }

  { /*---- SMOOTH_GROUP ----*/
    Lib3dsChunk c;
    unsigned i;
    
    c.chunk=LIB3DS_SMOOTH_GROUP;
    c.size=6+4*mesh->faces;
    lib3ds_chunk_write(&c, io);
    
    for (i=0; i<mesh->faces; ++i) {
      lib3ds_io_write_dword(io, mesh->faceL[i].smoothing);
    }
  }
  
  { /*---- MSH_BOXMAP ----*/
    Lib3dsChunk c;

    if (strlen(mesh->box_map.front) ||
      strlen(mesh->box_map.back) ||
      strlen(mesh->box_map.left) ||
      strlen(mesh->box_map.right) ||
      strlen(mesh->box_map.top) ||
      strlen(mesh->box_map.bottom)) {
    
      c.chunk=LIB3DS_MSH_BOXMAP;
      if (!lib3ds_chunk_write_start(&c, io)) {
        return(LIB3DS_FALSE);
      }
      
      lib3ds_io_write_string(io, mesh->box_map.front);
      lib3ds_io_write_string(io, mesh->box_map.back);
      lib3ds_io_write_string(io, mesh->box_map.left);
      lib3ds_io_write_string(io, mesh->box_map.right);
      lib3ds_io_write_string(io, mesh->box_map.top);
      lib3ds_io_write_string(io, mesh->box_map.bottom);
      
      if (!lib3ds_chunk_write_end(&c, io)) {
        return(LIB3DS_FALSE);
      }
    }
  }

  if (!lib3ds_chunk_write_end(&c, io)) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
示例#23
0
文件: viewport.c 项目: Aharobot/mrpt
/*!
 * \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);
}
示例#24
0
void
lib3ds_mesh_write(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io) {
    Lib3dsChunk c;

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

    point_array_write(mesh, io);
    texco_array_write(mesh, io);

    if (mesh->map_type != LIB3DS_MAP_NONE) {   /*---- LIB3DS_MESH_TEXTURE_INFO ----*/
        Lib3dsChunk c;
        int i, j;

        c.chunk = CHK_MESH_TEXTURE_INFO;
        c.size = 92;
        lib3ds_chunk_write(&c, io);

        lib3ds_io_write_word(io, (uint16_t)mesh->map_type);

        for (i = 0; i < 2; ++i) {
            lib3ds_io_write_float(io, mesh->map_tile[i]);
        }
        lib3ds_io_write_vector(io, mesh->map_pos);
        lib3ds_io_write_float(io, mesh->map_scale);

        for (i = 0; i < 4; i++) {
            for (j = 0; j < 3; j++) {
                lib3ds_io_write_float(io, mesh->map_matrix[i][j]);
            }
        }
        for (i = 0; i < 2; ++i) {
            lib3ds_io_write_float(io, mesh->map_planar_size[i]);
        }
        lib3ds_io_write_float(io, mesh->map_cylinder_height);
    }

    flag_array_write(mesh, io);

    {
        /*---- LIB3DS_MESH_MATRIX ----*/
        Lib3dsChunk c;
        int i, j;

        c.chunk = CHK_MESH_MATRIX;
        c.size = 54;
        lib3ds_chunk_write(&c, io);
        for (i = 0; i < 4; i++) {
            for (j = 0; j < 3; j++) {
                lib3ds_io_write_float(io, mesh->matrix[i][j]);
            }
        }
    }

    if (mesh->color) {   /*---- LIB3DS_MESH_COLOR ----*/
        Lib3dsChunk c;

        c.chunk = CHK_MESH_COLOR;
        c.size = 7;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_byte(io, (uint8_t)mesh->color);
    }

    face_array_write(file, mesh, io);

    lib3ds_chunk_write_end(&c, io);
}
示例#25
0
static void
texture_map_write(uint16_t chunk, Lib3dsTextureMap *map, Lib3dsIo *io) {
    Lib3dsChunk c;

    if (strlen(map->name) == 0) {
        return;
    }
    c.chunk = chunk;
    lib3ds_chunk_write_start(&c, io);

    int_percentage_write(map->percent, io);

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

    {   /*---- CHK_MAT_MAP_TILING ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_TILING;
        c.size = 8;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_word(io, (uint16_t)map->flags);
    }

    {   /*---- CHK_MAT_MAP_TEXBLUR ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_TEXBLUR;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, map->blur);
    }

    {   /*---- CHK_MAT_MAP_USCALE ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_USCALE;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, map->scale[0]);
    }

    {   /*---- CHK_MAT_MAP_VSCALE ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_VSCALE;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, map->scale[1]);
    }

    {   /*---- CHK_MAT_MAP_UOFFSET ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_UOFFSET;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, map->offset[0]);
    }

    {   /*---- CHK_MAT_MAP_VOFFSET ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_VOFFSET;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, map->offset[1]);
    }

    {   /*---- CHK_MAT_MAP_ANG ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_ANG;
        c.size = 10;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_float(io, map->rotation);
    }

    {   /*---- CHK_MAT_MAP_COL1 ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_COL1;
        c.size = 9;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[0] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[1] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_1[2] + 0.5));
    }

    {   /*---- CHK_MAT_MAP_COL2 ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_COL2;
        c.size = 9;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[0] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[1] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_2[2] + 0.5));
    }

    {   /*---- CHK_MAT_MAP_RCOL ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_RCOL;
        c.size = 9;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[0] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[1] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_r[2] + 0.5));
    }

    {   /*---- CHK_MAT_MAP_GCOL ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_GCOL;
        c.size = 9;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[0] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[1] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_g[2] + 0.5));
    }

    {   /*---- CHK_MAT_MAP_BCOL ----*/
        Lib3dsChunk c;
        c.chunk = CHK_MAT_MAP_BCOL;
        c.size = 9;
        lib3ds_chunk_write(&c, io);
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[0] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[1] + 0.5));
        lib3ds_io_write_byte(io, (uint8_t)floor(255.0*map->tint_b[2] + 0.5));
    }

    lib3ds_chunk_write_end(&c, io);
}