Beispiel #1
0
	void x3ds_definition::ensure_camera()
	{
		if (m_file->cameras == NULL)
		{
			// Fabricate camera

			Lib3dsCamera* camera = lib3ds_camera_new("Perscpective");

			float size;
			Lib3dsVector bmin, bmax;
			get_bounding_center(bmin, bmax, camera->target, &size);

			memcpy(camera->position, camera->target, sizeof(camera->position));
			camera->position[0] = bmax[0] + 0.75f * size;
			camera->position[1] = bmin[1] - 0.75f * size;
			camera->position[2] = bmax[2] + 0.75f * size;

			// hack
			Lib3dsMatrix m;
			lib3ds_matrix_identity(m);
			lib3ds_matrix_rotate_z(m, 1.6f);	// PI/2
			lib3ds_matrix_rotate_y(m, 0.3f);
			
			lib3ds_vector_transform(camera->position, m, camera->position);

			camera->near_range = (camera->position[0] - bmax[0] ) * 0.5f;
			camera->far_range = (camera->position[0] - bmin[0] ) * 3.0f;
			lib3ds_file_insert_camera(m_file, camera);
		}
	}
Beispiel #2
0
static Lib3dsBool
named_object_read(Lib3dsFile *file, FILE *f)
{
    Lib3dsChunk c;
    char name[64];
    Lib3dsWord chunk;

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

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

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

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

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

    lib3ds_chunk_read_end(&c, f);
    return(LIB3DS_TRUE);
}
Beispiel #3
0
/*!
* Load the model from .3ds file.
*/
static void
load_model(void)
{
  file=lib3ds_file_load(filepath);
  if (!file) {
    puts("3dsplayer: Error: Loading 3DS file failed.\n");
    exit(1);
  }

  /* No nodes?  Fabricate nodes to display all the meshes. */
  if( !file->nodes )
  {
    Lib3dsMesh *mesh;
    Lib3dsNode *node;

    for(mesh = file->meshes; mesh != NULL; mesh = mesh->next)
    {
      node = lib3ds_node_new_object();
      strcpy(node->name, mesh->name);
      node->parent_id = LIB3DS_NO_PARENT;
      lib3ds_file_insert_node(file, node);
    }
  }

  lib3ds_file_eval(file, 1.0f);
  lib3ds_file_bounding_box_of_nodes(file, LIB3DS_TRUE, LIB3DS_FALSE, LIB3DS_FALSE, bmin, bmax);
  sx = bmax[0] - bmin[0];
  sy = bmax[1] - bmin[1];
  sz = bmax[2] - bmin[2];
  size = MAX(sx, sy); size = MAX(size, sz);
  cx = (bmin[0] + bmax[0])/2;
  cy = (bmin[1] + bmax[1])/2;
  cz = (bmin[2] + bmax[2])/2;


  /* No cameras in the file?  Add four */

  if( !file->cameras ) {

    /* Add some cameras that encompass the bounding box */

    Lib3dsCamera *camera = lib3ds_camera_new("Camera_X");
    camera->target[0] = cx;
    camera->target[1] = cy;
    camera->target[2] = cz;
    memcpy(camera->position, camera->target, sizeof(camera->position));
    camera->position[0] = bmax[0] + 1.5 * MAX(sy,sz);
    camera->near_range = ( camera->position[0] - bmax[0] ) * .5;
    camera->far_range = ( camera->position[0] - bmin[0] ) * 2;
    lib3ds_file_insert_camera(file, camera);

    /* Since lib3ds considers +Y to be into the screen, we'll put
    * this camera on the -Y axis, looking in the +Y direction.
    */
    camera = lib3ds_camera_new("Camera_Y");
    camera->target[0] = cx;
    camera->target[1] = cy;
    camera->target[2] = cz;
    memcpy(camera->position, camera->target, sizeof(camera->position));
    camera->position[1] = bmin[1] - 1.5 * MAX(sx,sz);
    camera->near_range = ( bmin[1] - camera->position[1] ) * .5;
    camera->far_range = ( bmax[1] - camera->position[1] ) * 2;
    lib3ds_file_insert_camera(file, camera);

    camera = lib3ds_camera_new("Camera_Z");
    camera->target[0] = cx;
    camera->target[1] = cy;
    camera->target[2] = cz;
    memcpy(camera->position, camera->target, sizeof(camera->position));
    camera->position[2] = bmax[2] + 1.5 * MAX(sx,sy);
    camera->near_range = ( camera->position[2] - bmax[2] ) * .5;
    camera->far_range = ( camera->position[2] - bmin[2] ) * 2;
    lib3ds_file_insert_camera(file, camera);

    camera = lib3ds_camera_new("Camera_ISO");
    camera->target[0] = cx;
    camera->target[1] = cy;
    camera->target[2] = cz;
    memcpy(camera->position, camera->target, sizeof(camera->position));
    camera->position[0] = bmax[0] + .75 * size;
    camera->position[1] = bmin[1] - .75 * size;
    camera->position[2] = bmax[2] + .75 * size;
    camera->near_range = ( camera->position[0] - bmax[0] ) * .5;
    camera->far_range = ( camera->position[0] - bmin[0] ) * 3;
    lib3ds_file_insert_camera(file, camera);
  }


  /* No lights in the file?  Add some. */

  if (file->lights == NULL)
  {
    Lib3dsLight *light;

    light = lib3ds_light_new("light0");
    light->spot_light = 0;
    light->see_cone = 0;
    light->color[0] = light->color[1] = light->color[2] = .6;
    light->position[0] = cx + size * .75;
    light->position[1] = cy - size * 1.;
    light->position[2] = cz + size * 1.5;
    light->position[3] = 0.;
    light->outer_range = 100;
    light->inner_range = 10;
    light->multiplier = 1;
    lib3ds_file_insert_light(file, light);

    light = lib3ds_light_new("light1");
    light->spot_light = 0;
    light->see_cone = 0;
    light->color[0] = light->color[1] = light->color[2] = .3;
    light->position[0] = cx - size;
    light->position[1] = cy - size;
    light->position[2] = cz + size * .75;
    light->position[3] = 0.;
    light->outer_range = 100;
    light->inner_range = 10;
    light->multiplier = 1;
    lib3ds_file_insert_light(file, light);

    light = lib3ds_light_new("light2");
    light->spot_light = 0;
    light->see_cone = 0;
    light->color[0] = light->color[1] = light->color[2] = .3;
    light->position[0] = cx;
    light->position[1] = cy + size;
    light->position[2] = cz + size;
    light->position[3] = 0.;
    light->outer_range = 100;
    light->inner_range = 10;
    light->multiplier = 1;
    lib3ds_file_insert_light(file, light);

  }

  if (!file->cameras) {
    fputs("3dsplayer: Error: No Camera found.\n", stderr);
    lib3ds_file_free(file);
    file=0;
    exit(1);
  }
  if (!camera) {
    camera=file->cameras->name;
  }

  lib3ds_file_eval(file,0.);
}
Beispiel #4
0
static Lib3dsBool
named_object_read(Lib3dsFile *file, Lib3dsIo *io)
{
  Lib3dsChunk c;
  char name[64];
  Lib3dsWord chunk;
  Lib3dsMesh *mesh = NULL;
  Lib3dsCamera *camera = NULL;
  Lib3dsLight *light = NULL;
  Lib3dsDword object_flags;

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

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

      case LIB3DS_OBJ_DOESNT_CAST:
        object_flags |= LIB3DS_OBJECT_DOESNT_CAST;
        break;

      case LIB3DS_OBJ_VIS_LOFTER:
        object_flags |= LIB3DS_OBJECT_VIS_LOFTER;
        break;

      case LIB3DS_OBJ_MATTE:
        object_flags |= LIB3DS_OBJECT_MATTE;
        break;

      case LIB3DS_OBJ_DONT_RCVSHADOW:
        object_flags |= LIB3DS_OBJECT_DONT_RCVSHADOW;
        break;

      case LIB3DS_OBJ_FAST:
        object_flags |= LIB3DS_OBJECT_FAST;
        break;

      case LIB3DS_OBJ_FROZEN:
        object_flags |= LIB3DS_OBJECT_FROZEN;
        break;

      default:
        lib3ds_chunk_unknown(chunk);
    }
  }

  if (mesh)
    mesh->object_flags = object_flags;
  if (camera)
    camera->object_flags = object_flags;
  if (light)
    light->object_flags = object_flags;
  
  lib3ds_chunk_read_end(&c, io);
  return(LIB3DS_TRUE);
}
Beispiel #5
0
/*!
* Load the model from .3ds file.
*/
static void
load_model(void) {
	file = lib3ds_file_open(filepath);
	if (!file) {
		puts("3dsplayer: Error: Loading 3DS file failed.\n");
		exit(1);
	}
	
	
	/* No nodes? Fabricate nodes to display all the meshes. */
	if (!file->nodes) {
		Lib3dsNode *node;
		int i;
		for (i = 0; i < file->nmeshes; ++i) {
			Lib3dsMesh *mesh = file->meshes[i];
			node = lib3ds_node_new(LIB3DS_NODE_MESH_INSTANCE);
			strcpy(node->name, mesh->name);
			lib3ds_file_insert_node(file, node, NULL);
		}
	}
	
	
	lib3ds_file_eval(file, 0.0f);
	lib3ds_file_bounding_box_of_nodes(file, 1, 0, 0, bmin, bmax, NULL);
	sx = bmax[0] - bmin[0];
	sy = bmax[1] - bmin[1];
	sz = bmax[2] - bmin[2];
	size = MAX(sx, sy);
	size = MAX(size, sz);
	cx = (bmin[0] + bmax[0]) / 2;
	cy = (bmin[1] + bmax[1]) / 2;
	cz = (bmin[2] + bmax[2]) / 2;
	
	
	
	
	/* No cameras in the file? Add four */
	
	
	if (!file->ncameras) {
		
		
		/* Add some cameras that encompass the bounding box */
		
		
		Lib3dsCamera *camera = lib3ds_camera_new("Camera_X");
		camera->target[0] = cx;
		camera->target[1] = cy;
		camera->target[2] = cz;
		memcpy(camera->position, camera->target, sizeof(camera->position));
		camera->position[0] = bmax[0] + 1.5 * MAX(sy, sz);
		camera->near_range = (camera->position[0] - bmax[0]) * .5;
		camera->far_range = (camera->position[0] - bmin[0]) * 2;
		lib3ds_file_insert_camera(file, camera, -1);
		
		
		/* Since lib3ds considers +Y to be into the screen, we'll put
		* this camera on the -Y axis, looking in the +Y direction.
		*/
		camera = lib3ds_camera_new("Camera_Y");
		camera->target[0] = cx;
		camera->target[1] = cy;
		camera->target[2] = cz;
		memcpy(camera->position, camera->target, sizeof(camera->position));
		camera->position[1] = bmin[1] - 1.5 * MAX(sx, sz);
		camera->near_range = (bmin[1] - camera->position[1]) * .5;
		camera->far_range = (bmax[1] - camera->position[1]) * 2;
		lib3ds_file_insert_camera(file, camera, -1);
		
		
		camera = lib3ds_camera_new("Camera_Z");
		camera->target[0] = cx;
		camera->target[1] = cy;
		camera->target[2] = cz;
		memcpy(camera->position, camera->target, sizeof(camera->position));
		camera->position[2] = bmax[2] + 1.5 * MAX(sx, sy);
		camera->near_range = (camera->position[2] - bmax[2]) * .5;
		camera->far_range = (camera->position[2] - bmin[2]) * 2;
		lib3ds_file_insert_camera(file, camera, -1);
		
		
		camera = lib3ds_camera_new("Camera_ISO");
		camera->target[0] = cx;
		camera->target[1] = cy;
		camera->target[2] = cz;
		memcpy(camera->position, camera->target, sizeof(camera->position));
		camera->position[0] = bmax[0] + .75 * size;
		camera->position[1] = bmin[1] - .75 * size;
		camera->position[2] = bmax[2] + .75 * size;
		camera->near_range = (camera->position[0] - bmax[0]) * .5;
		camera->far_range = (camera->position[0] - bmin[0]) * 3;
		lib3ds_file_insert_camera(file, camera, -1);
	}
	
	
	/* No lights in the file? Add some. */
	
	
	if (!file->nlights) {
		Lib3dsLight *light;
		
		
		light = lib3ds_light_new("light0");
		light->spot_light = 0;
		light->see_cone = 0;
		light->color[0] = light->color[1] = light->color[2] = .6;
		light->position[0] = cx + size * .75;
		light->position[1] = cy - size * 1.;
		light->position[2] = cz + size * 1.5;
		light->position[3] = 0.;
		light->outer_range = 100;
		light->inner_range = 10;
		light->multiplier = 1;
		lib3ds_file_insert_light(file, light, -1);
		
		
		light = lib3ds_light_new("light1");
		light->spot_light = 0;
		light->see_cone = 0;
		light->color[0] = light->color[1] = light->color[2] = .3;
		light->position[0] = cx - size;
		light->position[1] = cy - size;
		light->position[2] = cz + size * .75;
		light->position[3] = 0.;
		light->outer_range = 100;
		light->inner_range = 10;
		light->multiplier = 1;
		lib3ds_file_insert_light(file, light, -1);
		
		
		light = lib3ds_light_new("light2");
		light->spot_light = 0;
		light->see_cone = 0;
		light->color[0] = light->color[1] = light->color[2] = .3;
		light->position[0] = cx;
		light->position[1] = cy + size;
		light->position[2] = cz + size;
		light->position[3] = 0.;
		light->outer_range = 100;
		light->inner_range = 10;
		light->multiplier = 1;
		lib3ds_file_insert_light(file, light, -1);
	}
	
	
	camera = file->cameras[0]->name;
	
	
	lib3ds_file_eval(file, 0);
}
Beispiel #6
0
static void
named_object_read(Lib3dsFile *file, Lib3dsIo *io) {
    Lib3dsChunk c;
    char name[64];
    uint16_t chunk;
    Lib3dsMesh *mesh = NULL;
    Lib3dsCamera *camera = NULL;
    Lib3dsLight *light = NULL;
    uint32_t object_flags;

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

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

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

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

            case CHK_OBJ_HIDDEN:
                object_flags |= LIB3DS_OBJECT_HIDDEN;
                break;

            case CHK_OBJ_DOESNT_CAST:
                object_flags |= LIB3DS_OBJECT_DOESNT_CAST;
                break;

            case CHK_OBJ_VIS_LOFTER:
                object_flags |= LIB3DS_OBJECT_VIS_LOFTER;
                break;

            case CHK_OBJ_MATTE:
                object_flags |= LIB3DS_OBJECT_MATTE;
                break;

            case CHK_OBJ_DONT_RCVSHADOW:
                object_flags |= LIB3DS_OBJECT_DONT_RCVSHADOW;
                break;

            case CHK_OBJ_FAST:
                object_flags |= LIB3DS_OBJECT_FAST;
                break;

            case CHK_OBJ_FROZEN:
                object_flags |= LIB3DS_OBJECT_FROZEN;
                break;

            default:
                lib3ds_chunk_unknown(chunk, io);
        }
    }

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

    lib3ds_chunk_read_end(&c, io);
}
Beispiel #7
0
int main(int argc, char **argv) {
    Lib3dsFile *file = lib3ds_file_new();
    file->frames = 360;
    
    {
        Lib3dsMaterial *mat = lib3ds_material_new("c_tex");
        lib3ds_file_insert_material(file, mat, -1);
        strcpy(mat->texture1_map.name, "cube.tga");
        mat->texture1_map.percent = 1.0;

        mat = lib3ds_material_new("c_red");
        lib3ds_file_insert_material(file, mat, -1);
        mat->diffuse[0] = 1.0;
        mat->diffuse[1] = 0.0;
        mat->diffuse[2] = 0.0;

        mat = lib3ds_material_new("c_blue");
        lib3ds_file_insert_material(file, mat, -1);
        mat->diffuse[0] = 0.0;
        mat->diffuse[1] = 0.0;
        mat->diffuse[2] = 1.0;
    }

    {
        int i, j;
        Lib3dsMesh *mesh = lib3ds_mesh_new("cube");
        Lib3dsMeshInstanceNode *inst;        
        lib3ds_file_insert_mesh(file, mesh, -1);

        lib3ds_mesh_resize_vertices(mesh, 8, 1, 0);
        for (i = 0; i < 8; ++i) {
            lib3ds_vector_copy(mesh->vertices[i], g_vertices[i]);
            mesh->texcos[i][0] = g_texcoords[i][0];
            mesh->texcos[i][1] = g_texcoords[i][1];
        }

        lib3ds_mesh_resize_faces(mesh, 12);
        for (i = 0; i < 12; ++i) {
            for (j = 0; j < 3; ++j) {
                mesh->faces[i].index[j] = g_indices[i][j];
            }
        }

        for (i = 0; i < 8; ++i) {
            mesh->faces[i].material = 0;
        }
        for (i = 0; i < 2; ++i) {
            mesh->faces[8+i].material = 1;
        }
        for (i = 0; i < 2; ++i) {
            mesh->faces[10+i].material = 2;
        }

        inst = lib3ds_node_new_mesh_instance(mesh, "01", NULL, NULL, NULL);
        lib3ds_file_append_node(file, (Lib3dsNode*)inst, NULL);
    }

    {
        Lib3dsCamera *camera;
        Lib3dsCameraNode *n;
        Lib3dsTargetNode *t;
        int i;

        camera = lib3ds_camera_new("camera01");
        lib3ds_file_insert_camera(file, camera, -1);
        lib3ds_vector_make(camera->position, 0.0, -100, 0.0);
        lib3ds_vector_make(camera->target, 0.0, 0.0, 0.0);

        n = lib3ds_node_new_camera(camera);
        t = lib3ds_node_new_camera_target(camera);
        lib3ds_file_append_node(file, (Lib3dsNode*)n, NULL);
        lib3ds_file_append_node(file, (Lib3dsNode*)t, NULL);

        lib3ds_track_resize(&n->pos_track, 37);
        for (i = 0; i <= 36; i++) {
            n->pos_track.keys[i].frame = 10 * i;
            lib3ds_vector_make(n->pos_track.keys[i].value, 
                (float)(100.0 * cos(2 * M_PI * i / 36.0)), 
                (float)(100.0 * sin(2 * M_PI * i / 36.0)), 
                50.0
            );
        }
    }

    if (!lib3ds_file_save(file, "cube.3ds")) {
        fprintf(stderr, "ERROR: Saving 3ds file failed!\n");
    }
    lib3ds_file_free(file);
}
Beispiel #8
0
// TODO: Build own exporter class
void objectExporter::on_buttonBox_accepted()
{
    QString fileName = QFileDialog::getSaveFileName(gloParent, "Save 3ds Object", ".", "3D Object (*.3ds)", 0, 0);

    QList<trackHandler*> trackList = gloParent->getTrackList();
    trackHandler* curTrack = trackList[ui->trackBox->currentIndex()];

    trackMesh* mesh = curTrack->mMesh;

    QVector<float> *vertices = new QVector<float>();
    QVector<unsigned int> *indices = new QVector<unsigned int>();
    QVector<unsigned int> *borders = new QVector<unsigned int>();

    Lib3dsFile *file = lib3ds_file_new();
    file->frames = 360;

    {
        Lib3dsMaterial* mat = lib3ds_material_new("coaster");
        lib3ds_file_insert_material(file, mat, -1);
        mat->diffuse[0] = curTrack->trackColors[0].red()/255.f;
        mat->diffuse[1] = curTrack->trackColors[0].green()/255.f;
        mat->diffuse[2] = curTrack->trackColors[0].blue()/255.f;
    }

    {
        for(int section = 0; section < curTrack->trackData->lSections.size(); ++section) {
            vertices->clear();
            indices->clear();
            borders->clear();
            mesh->build3ds(section, vertices, indices, borders);

            float* fvertices = new float[vertices->size()];
            for(int i = 0; i < vertices->size()/3; ++i) {
                fvertices[3*i+0] = vertices->at(3*i+0);
                fvertices[3*i+1] = -vertices->at(3*i+2);
                fvertices[3*i+2] = vertices->at(3*i+1);

                //exportScreen->doFastExport();
            }
            for(int subIndex = 0; subIndex < borders->size()-2; subIndex+= 2) {
                int fromVIndex = borders->at(subIndex)/3;
                int toVIndex = borders->at(subIndex+2)/3;
                int fromIIndex = borders->at(subIndex+1)/3;
                int toIIndex = borders->at(subIndex+3)/3;

                int i, j;
                QString name = QString::number(section).append(QString("_").append(QString::number(subIndex/2)));
                Lib3dsMesh *mesh = lib3ds_mesh_new(name.toLocal8Bit().data());
                Lib3dsMeshInstanceNode *inst;
                lib3ds_file_insert_mesh(file, mesh, -1);

                lib3ds_mesh_resize_vertices(mesh, toVIndex-fromVIndex, 1, 0);
                for (i = 0; i < toVIndex-fromVIndex; ++i) {
                    lib3ds_vector_copy(mesh->vertices[i], &fvertices[(i+fromVIndex)*3]);
                    mesh->texcos[i][0] = 0.f;
                    mesh->texcos[i][1] = 0.f;
                }

                lib3ds_mesh_resize_faces(mesh, toIIndex-fromIIndex);
                for (i = 0; i < toIIndex-fromIIndex; ++i) {
                    for (j = 0; j < 3; ++j) {
                        mesh->faces[i].index[j] = indices->at(3*(i+fromIIndex)+j)-fromVIndex;
                        mesh->faces[i].material = 0;
                    }
                }
                inst = lib3ds_node_new_mesh_instance(mesh, name.toLocal8Bit().data(), NULL, NULL, NULL);
                lib3ds_file_append_node(file, (Lib3dsNode*)inst, NULL);
            }
            delete[] fvertices;
        }
    }

    {
        Lib3dsCamera *camera;
        Lib3dsCameraNode *n;
        Lib3dsTargetNode *t;
        int i;

        camera = lib3ds_camera_new("camera01");
        lib3ds_file_insert_camera(file, camera, -1);
        lib3ds_vector_make(camera->position, 0.0, -100, 0.0);
        lib3ds_vector_make(camera->target, 0.0, 0.0, 0.0);

        n = lib3ds_node_new_camera(camera);
        t = lib3ds_node_new_camera_target(camera);
        lib3ds_file_append_node(file, (Lib3dsNode*)n, NULL);
        lib3ds_file_append_node(file, (Lib3dsNode*)t, NULL);

        lib3ds_track_resize(&n->pos_track, 37);
        for (i = 0; i <= 36; i++) {
            n->pos_track.keys[i].frame = 10 * i;
            lib3ds_vector_make(n->pos_track.keys[i].value,
                (float)(100.0 * cos(2 * F_PI * i / 36.0)),
                (float)(100.0 * sin(2 * F_PI * i / 36.0)),
                50.0
            );
        }
    }

    if (!lib3ds_file_save(file, fileName.toLocal8Bit().data())) {
         qDebug("ERROR: Saving 3ds file failed!\n");
    }
    lib3ds_file_free(file);

    delete indices;
    delete vertices;
}