예제 #1
0
Lib3dsLoader::Lib3dsLoader(string filename) :
	model(0),
	numFacesCached(0)
{
	// TODO: Error handling. 
	model = lib3ds_file_load(filename.c_str());
}
예제 #2
0
// load the model, and if the texture has textures, then apply them on the geometric primitives
void Model::loadFile(const char *name)
{
	filename = name;
	// load file
	file = lib3ds_file_load(filename);
	if(!file) // if we were not able to load the file
	{
		// give some errors
		std::string event = "Error loading: ";
		std::string online = "On line 61 in file ";
		online.append(__FILE__);
		event.append(filename);
		std::cout << event << std::endl;
		std::cout << online << std::endl;
		std::cerr << "3DS Error" << std::endl;
		exit(1);
	}
	lib3ds_file_eval(file, 0); // set current frame to 0
	// apply texture to all meshes that have texels
	Lib3dsMesh *mesh;
	for(mesh = file->meshes;mesh != 0;mesh = mesh->next)
	{
		if(mesh->texels) //if there's texels for the mesh
			ApplyTexture(mesh); //then apply texture to it
	}
	if(file->lights) //if we have lights in our model
		CreateLightList();
}
예제 #3
0
int
main(int argc, char **argv)
{
  Lib3dsFile *f=0;

  parse_args(argc, argv);
  f=lib3ds_file_load(filename);
  if (!f)
  {
    fprintf(stderr, "***ERROR***\nLoading file %s failed\n", filename);
    exit(1);
  }
  if (output)
  {
    dump_m_file(f,output);
  }
  else
  {
    fprintf(stderr, "***ERROR***\nNo output file specified.\n");
    exit(1);
  }

  lib3ds_file_free(f);
  return(0);
}
예제 #4
0
파일: 3ds2m.c 프로젝트: kasicass/frustum
int
main(int argc, char **argv)
{
  Lib3dsFile *f=0;

  parse_args(argc, argv);
  f=lib3ds_file_load(filename);
  if (!f) {
    fprintf(stderr, "***ERROR***\nLoading file %s failed\n", filename);
    exit(1);
  }
  if (output) {
    FILE *o=fopen(output, "w+");
    if (!o) {
      fprintf(stderr, "***ERROR***\nCan't open %s for writing\n", output);
      exit(1);
    }
    dump_m_file(f,o);
    fclose(o);
  }
  else {
    dump_m_file(f,stdout);
  }

  lib3ds_file_free(f);
  return(0);
}
예제 #5
0
	x3ds_definition::x3ds_definition(player* player, const char* url) : 
		character_def(player),
		m_file(NULL)
	{
		m_file = lib3ds_file_load(url);
		if (m_file == NULL)
		{
			static int n = 0;
			if (n < 1)
			{
				n++;
				log_error("can't load '%s'\n", url);
			}
			return;
		}

		// load textures
	  for (Lib3dsMaterial* p = m_file->materials; p != 0; p = p->next)
		{
			load_texture(p->texture1_map.name);
			load_texture(p->bump_map.name);
		}

		ensure_camera();
		ensure_lights();
		ensure_nodes();

		lib3ds_file_eval(m_file, 0.);
	}
예제 #6
0
Scene *load_scene(const char *fname) {

	Lib3dsFile *file;
	if(!(file = lib3ds_file_load(fname))) {
		error("%s: could not load %s", __func__, fname);
		return 0;
	}
	lib3ds_file_eval(file, 0);

	Scene *scene = new Scene;

	load_objects(file, scene);
	load_lights(file, scene);
	load_cameras(file, scene);

	construct_hierarchy(file, scene);

	/*
	std::list<Object*> *obj_list = scene->get_objects_list();
	std::list<Object*>::iterator iter = obj_list->begin();
	while(iter != obj_list->end()) {
		fix_hierarchy(*iter++);
	}
	*/
	
	lib3ds_file_free(file);

	return scene;
}
int main(void) {

  Lib3dsFile *model = NULL;
  int n_meshes = 0;
  int n_faces  = 0;
  Lib3dsMesh *mesh;
  long n_points = 0;
  long n_texcoords = 0;
  
  printf("info3ds: starting up!\n");

  model = lib3ds_file_load("cube.3ds");
  
  if (!model) {
    printf("info3ds: error loading file\n");
  }
  
  /* count meshes (a linked list)*/
  for (mesh = model->meshes; mesh != NULL; mesh = mesh->next) {
    n_meshes ++;
    
    n_faces += mesh->faces;
    n_points += mesh->points;
    n_texcoords += mesh->texels;
  }
  
  printf("info3ds: number of meshes %d\n",n_meshes);
  printf("info3ds: number of faces %d\n",n_faces);
  printf("info3ds: number of points %ld\n",n_points);
  printf("info3ds: number of texcoords %ld\n",n_texcoords);

  
}
예제 #8
0
int main(int argc, char **argv)
{
	Lib3dsFile *f = NULL;
	FILE *o = NULL;

	parse_args(argc, argv);
	f = lib3ds_file_load(input_file);
	if (!f)
	{
		fprintf(stderr, "***ERROR***\nLoading file %s failed\n", input_file);
		exit(1);
	}
	o = fopen(output_file, "w+");
	if (!o)
	{
		fprintf(stderr, "***ERROR***\nCan't open %s for writing\n", output_file);
		exit(1);
	}
	dump_wzm_file(f, o, swapYZ, invertUV, reverseWinding, baseTexFlags, scaleFactor);
	fclose(o);

	lib3ds_file_free(f);

	return 0;
}
예제 #9
0
    /*!
     * See \ref Loader3ds::loadFromFile
     */
    dcollide::Proxy* Loader3dsInternal::loadFromFile(dcollide::World* world, const char* fileName, dcollide::ProxyTypes proxyType) {
        mData->mProxy2Transformation.clear();
        mData->mProxy2TextureInformation.clear();
        if (!fileName) {
            // TODO: exception?
            return 0;
        }

        mFile = lib3ds_file_load(fileName);
        if (!mFile) {
            std::cout << dc_funcinfo << "unable to load " << fileName << std::endl;
            return 0;
        }

        // AB: some files don't store nodes and just want exactly one node per mesh.
        //     atm we don't support that.
        if (!mFile->nodes) {
            std::cout << dc_funcinfo << "File " << fileName << " does not contain any nodes. mesh-only files not supported currently." << std::endl;
            lib3ds_file_free(mFile);
            mFile = 0;
            return 0;
        }

        // 3ds stores several frames, we want the first
        lib3ds_file_eval(mFile, 0);

        if (!checkUniqueMeshMaterial()) {
            std::cerr << dc_funcinfo << "the file " << fileName << " contains at least one mesh with different materials. this is not supported by this modelloader, only the first material will be used!" << std::endl;
        }

        dcollide::Proxy* topObject = world->createProxy(proxyType);
        mData->mProxy2Transformation.insert(std::make_pair(topObject, Loader3ds::TransformationNode()));

        Lib3dsMatrix identityMatrix;
        lib3ds_matrix_identity(identityMatrix);
        Lib3dsNode* node = mFile->nodes;
        while (node) {
            // node->type can be object, light, camera, ...
            // -> only object nodes are relevant to us
            if (node->type == LIB3DS_OBJECT_NODE) {
                if (!loadNode(world, topObject, node, &identityMatrix)) {
                    std::cerr << dc_funcinfo << "Loading node from " << fileName << " failed" << std::endl;
                    // TODO: is MyObjectNode::mProxy being deleted?
                    delete topObject;
                    lib3ds_file_free(mFile);
                    mFile = 0;
                    return 0;
                }
            }

            node = node->next;
        }

        lib3ds_file_free(mFile);
        mFile = 0;
        return topObject;
    }
예제 #10
0
Lib3dsFile * load3ds(char* name) {
    Lib3dsFile * model;
    model = lib3ds_file_load(name);
    if(!model) {
        printf("Error: wrong model3ds file path: %s\n", name);
        exit(1);
    }
//    printf("nmeshes = %d\n", model -> frames);
    return model;
}
Model3DS::Model3DS(const char *name)
{
    file=lib3ds_file_load(name);

    if (!file) {
      puts("3dsplayer: Error: Loading 3DS file failed.\n");
      exit(1);
    }
    lib3ds_file_eval(file,0);
}
예제 #12
0
파일: dsmodel.cpp 프로젝트: FerryT/OGO-2.3
Object::Object(std:: string filename)
{
        m_TotalFaces = 0;
        
        m_model = lib3ds_file_load(filename.c_str());
        // If loading the model failed, we throw an exception
        if(!m_model)
        {
                throw strcat("Unable to load ", filename.c_str());
        }
}
예제 #13
0
파일: 3ds2rib.c 프로젝트: Neoniet/upspring
int
main(int argc, char **argv)
{
  Lib3dsFile *f=0;
  FILE *o;

  parse_args(argc, argv);
  f=lib3ds_file_load(filename);
  if (!f) {
    fprintf(stderr, "***ERROR***\nLoading file %s failed\n", filename);
    exit(1);
  }

  if (output) {
    o=fopen(output, "w+");
    if (!o) {
      fprintf(stderr, "***ERROR***\nCan't open %s for writing\n", output);
      exit(1);
    }
  }
  else {
    o=stdout;
  }

  fprintf(o, "Option \"searchpath\" \"shader\" [\".:../shaders:&\"]\n");
  if (flags&LIB3DS2RIB_ALL) {
    int i;
    for (i=f->segment_from; i<=f->segment_to; ++i) {
      lib3ds_file_eval(f,1.0f*i);
      create_rib(f,o,i);
    }
  }
  else
  if (downcuts) {
    int i;
    int delta=f->segment_to-f->segment_from;
    for (i=0; i<downcuts; ++i) {
      float frame=f->segment_from+1.0f*i*delta/(downcuts-1);
      lib3ds_file_eval(f, frame);
      create_rib(f,o,i);
    }
  }
  else {  
    lib3ds_file_eval(f,frame);
    create_rib(f,o, (int)frame);
  }

  if (o!=stdout) {
    fclose(o);
  }
  lib3ds_file_free(f);
  return(0);
}
예제 #14
0
// Load 3DS model
CModel3DS::CModel3DS(std::string filename)
{
	m_TotalFaces = 0;
	
	m_model = lib3ds_file_load(filename.c_str());
	// If loading the model failed, we throw an exception
	if(!m_model)
	{
		throw strcat((char*)"Unable to load ", (char*)filename.c_str());
	}
	
}
예제 #15
0
파일: 3dsdump.c 프로젝트: 34985086/meshlab
int
main(int argc, char **argv)
{
  Lib3dsFile *f=0;

  parse_args(argc, argv);

  lib3ds_chunk_enable_dump(flags&LIB3DSDUMP_STRUCTURE, flags&LIB3DSDUMP_UNKNOWN);
  f=lib3ds_file_load(filename);
  if (!f) {
    fprintf(stderr, "***ERROR***\nLoading file %s failed\n", filename);
    exit(1);
  }

  if (flags&LIB3DSDUMP_MATERIALS) {
    printf("Dumping materials:\n");
    lib3ds_file_dump_materials(f);
    printf("\n");
  }
  if (flags&LIB3DSDUMP_TRIMESHES) {
    printf("Dumping meshes:\n");
    lib3ds_file_dump_meshes(f);
    printf("\n");
  }
  if (flags&LIB3DSDUMP_INSTANCES) {
    printf("Dumping instances:\n");
    lib3ds_file_dump_instances(f);
    printf("\n");
  }
  if (flags&LIB3DSDUMP_CAMERAS) {
    printf("Dumping cameras:\n");
    lib3ds_file_dump_cameras(f);
    printf("\n");
  }
  if (flags&LIB3DSDUMP_LIGHTS) {  
    printf("Dumping lights:\n");
    lib3ds_file_dump_lights(f);
    printf("\n");
  }
  if (flags&LIB3DSDUMP_NODES) {
    printf("Dumping node hierarchy:\n");
    lib3ds_file_dump_nodes(f);
    printf("\n");
  }
  if (output && (flags&LIB3DSDUMP_WRITE_3DS)) {
    if (!lib3ds_file_save(f, output)) {
      printf("***ERROR**** Writing %s\n", output);
    }
  }

  lib3ds_file_free(f);
  return(0);
}
SkeletalObject::SkeletalObject(const char* filename)
{

	m_TotalFaces = 0;
	m_model = lib3ds_file_load(filename);
	// If loading the model failed, we throw an exception
	if(!m_model)
	{
		cout << ("Unable to load ", filename);
	}
	Lib3dsMesh* mesh = lib3ds_file_mesh_by_name(m_model,"filename");


}
예제 #17
0
Object_3DS::Object_3DS(const char* filename):file(NULL)
{
#ifdef HAS_LIB3DS
    file=lib3ds_file_load(filename);
    if(!file)
    {
        MSG_ERROR("Can't load 3ds file %s",filename);
    }
    else
        lib3ds_file_eval(file,0);
#else
    MSG_ERROR("Object_3DS can't be used. Please ensure lib3ds is linked correctly!");
#endif
}
예제 #18
0
파일: m3ds.cpp 프로젝트: anirul/3DStereo
bool m3ds::load(std::string& filename) {
	m_filename = filename;
	m_file = lib3ds_file_load(filename.c_str());
	if (!m_file)
		return false;
	lib3ds_file_eval(m_file, 0.0f);
	std::map<std::string, texture*>::iterator ite;
	ite = texlib::instance()->find("default.tga");
	if (ite == texlib::instance()->end()) {
		tga_tex* tex = new tga_tex("models\\3ds\\default.tga");
		texlib::instance()->insert(
			texlib::value_type(std::string("default.tga"), tex));
	}
	return true;
}
예제 #19
0
/**
 * Model3DS
 * Konstruktor. Lädt das Modell.
 * @param filepointer der 3ds-Dateis
 * @param tex Enum der Textur
 */
Model3DS::Model3DS(FILE* f, GLuint tex) {
	m_TotalFaces = 0;
	m_tex = tex;
	m_model = lib3ds_file_load(f);
	// If loading the model failed, we throw an exception
	if(!m_model)
	{
		LOGI("Unable to load model\n");
	}
	else
	{
		CreateVBO();
	}

}
예제 #20
0
TriMesh *load_mesh(const char *fname, const char *name) {
	TriMesh *mesh = 0;
	
	Lib3dsFile *file = lib3ds_file_load(fname);
	if(file && name) {
		Scene *scene = new Scene;
		load_objects(file, scene);

		Object *obj = scene->get_object(name);
		if(obj) {
			mesh = new TriMesh;
			*mesh = obj->get_mesh();
		}
		lib3ds_file_free(file);
		return mesh;
	}

	mesh = load_mesh_ply(fname);
	return mesh;
}
예제 #21
0
파일: 3dsplay.c 프로젝트: kasicass/frustum
/*!
 *
 */
static void
init(void) 
{
  glClearColor(0.5, 0.5, 0.5, 1.0);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glDepthFunc(GL_LEQUAL);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);
  glCullFace(GL_BACK);
  //glDisable(GL_NORMALIZE);
  //glPolygonOffset(1.0, 2);


  file=lib3ds_file_load(filename);
  if (!file) {
    puts("***ERROR*** Loading 3DS file failed.");
    exit(1);
  }
  if (!file->cameras) {
    puts("***ERROR*** No Camera found.");
    lib3ds_file_free(file);
    file=0;
    exit(1);
  }
  if (!camera) {
    camera=file->cameras->name;
  }
  camera_menu_id=glutCreateMenu(camera_menu);
  {
    Lib3dsCamera *c;
    int i;
    for (c=file->cameras,i=0; c; c=c->next,++i) {
      glutAddMenuEntry(c->name, i);
    }
  }
  glutAttachMenu(0);

  lib3ds_file_eval(file,0);
}
예제 #22
0
int main(int argc, char **argv)
{
	Lib3dsFile *f=0;
	FILE	*inputM2,*outputM2;

	if(argc<3)
	{
		printf("3ds To M2 Converter v1.1 (July 29th, 2006)\n");
		printf(" (Original Version July 23rd, 2006)\n");
		printf(" by John \"Cryect\" Rittenhouse\n\n");
		printf(" 3dsToM2 <3ds File Name> <M2 File Name> <Optional Scale>\n");
		return 0;
	}
	
	f=lib3ds_file_load(argv[1]);

	if(!f)
	{
		printf("ERROR: Unable to load 3ds file %s\n",argv[1]);
		return 0;
	}

	outputM2=fopen(argv[2],"wb");
	if(!outputM2)
	{
		printf("ERROR: Unable to open M2 file for writing %s\n",argv[2]);
		lib3ds_file_free(f);
		return 0;
	}
	
	if(argc>3)
		Scale=atof(argv[3]);
	else
		Scale=1;

	convert3ds(outputM2, f);
	fclose(outputM2);
	lib3ds_file_free(f);

	printf("3ds to M2 conversion completed\n");
}
예제 #23
0
		CModel3ds(vbcString filename, string texPath)
		{
			_File3ds = lib3ds_file_load(filename.c_str());
			
			if(_File3ds == 0)
			{
				printf("Some problem occured while loading model!\n");
				return;
			}

			_Materials = new CMaterials(_File3ds, texPath);

			unsigned int meshesCount = 0;
			Lib3dsMesh* mesh;
			
			// meshes counting
			for( mesh = _File3ds->meshes; mesh != NULL; mesh = mesh->next )
			{
				meshesCount++;
			}

			_Meshes.reserve(meshesCount);

			// Read all meshes from file			
			for( mesh = _File3ds->meshes; mesh != NULL; mesh = mesh->next )
			{
				CMesh3ds* mesh3ds = new CMesh3ds(mesh, _Materials);
				mesh3ds->loadGeometry();
				
				_Meshes.push_back(mesh3ds);
			}

			if( _File3ds )
			{
				lib3ds_file_free(_File3ds);
				_File3ds = 0;
			}
		}
예제 #24
0
nebu_Mesh_3DSFile* nebu_Mesh_Load3DSFile(const char *filename)
{
	return lib3ds_file_load(filename);
}
예제 #25
0
파일: model.cpp 프로젝트: zanneth/ZGE
ZModel::ZModel(std::string filename) :
    _faces_count(0),
    _vertices_count(0),
    _render_mode(ZRENDER_MODE_TRIANGLES)
{
    ZRenderContext *ctx = ZRenderContext::get_current_context();
    zassert(ctx, "invalid context");

    _vertex_array = ctx->create_vertex_array();
    _vertex_vbo = ctx->create_graphics_buffer();
    _normal_vbo = ctx->create_graphics_buffer();

    ZBufferAttribute vertex_attrib = {
        .components_per_vertex = 3,
        .component_type = ZCOMPONENT_TYPE_FLOAT,
        .normalized = false,
        .stride = 0,
        .offset = 0
    };
    _vertex_vbo->add_attribute(vertex_attrib);

    ZBufferAttribute normal_attrib = {
        .components_per_vertex = 3,
        .component_type = ZCOMPONENT_TYPE_FLOAT,
        .normalized = false,
        .stride = 0,
        .offset = 0
    };
    _normal_vbo->add_attribute(normal_attrib);

    _vertex_array->add_buffer(_vertex_vbo, ZVERTEX_ATTRIB_POSITION);
    _vertex_array->add_buffer(_normal_vbo, ZVERTEX_ATTRIB_NORMAL);

    if (filename.length()) {
        load_file(filename);
    }
}

ZGeometryRef ZModel::copy() const
{
    return std::make_shared<ZModel>(*this);
}

#pragma mark - Loading from Files

void ZModel::load_file(std::string filename)
{
    Lib3dsFile *model_file = lib3ds_file_load(filename.c_str());
    if (!model_file) {
        ZException e(ZFILE_EXCEPTION_CODE);
        e.extra_info = "Unable to load file " + filename;
        throw e;
    }

    if (model_file->meshes == nullptr) {
        ZException e(ZENGINE_EXCEPTION_CODE);
        e.extra_info = "Model file " + filename + " contains no meshes.";
        throw e;
    }

    // load information about the model
    _name = model_file->name;

    size_t total_faces = 0;
    size_t total_vertices = 0;
    std::vector<std::array<float, 3>> vertices;
    std::vector<std::array<float, 3>> normals;

    // copy data for each mesh from model file
    Lib3dsMesh *mesh = model_file->meshes;
    do {
        size_t mesh_faces_count = mesh->faces;
        size_t mesh_vertices_count = mesh->points;

        float (*calculated_normals)[3] = new float[mesh_faces_count * 3][3];
        lib3ds_mesh_calculate_normals(mesh, calculated_normals);

        unsigned cur_normals_idx = 0;
        for (unsigned j = 0; j < mesh_faces_count; ++j) {
            Lib3dsFace *face = &mesh->faceL[j];
            for (unsigned k = 0; k < 3; ++k) {
                vertices.push_back(__copy_vertex_data<float, 3>(mesh->pointL[face->points[k]].pos));
                normals.push_back(__copy_vertex_data<float, 3>(calculated_normals[cur_normals_idx++]));
            }
        }

        total_faces += mesh_faces_count;
        total_vertices += mesh_vertices_count;
        delete [] calculated_normals;
    } while ((mesh = mesh->next));

    // load data into each VBO
#define VEC_ARR_DATA_SZ(vec) (vec.size() * 3 * sizeof(decltype(vec)::value_type::value_type))
    ZBufferUsage static_draw = { ZBUFFER_USAGE_FREQUENCY_STATIC, ZBUFFER_USAGE_NATURE_DRAW };
    _vertex_vbo->load_data(vertices.data(), VEC_ARR_DATA_SZ(vertices), static_draw);
    _normal_vbo->load_data(normals.data(), VEC_ARR_DATA_SZ(normals), static_draw);

    _faces_count = total_faces;
    _vertices_count = total_vertices;

    lib3ds_file_free(model_file);
}

#pragma mark - Accessors

std::string ZModel::get_name() const {
    return _name;
}
ZRenderMode ZModel::get_render_mode() const {
    return _render_mode;
}
void ZModel::set_render_mode(ZRenderMode mode) {
    _render_mode = mode;
}

#pragma mark - Drawing

void ZModel::render(ZRenderContextRef context)
{
    ZGeometry::render(context);

    context->set_depth_testing_enabled(true);
    context->draw_array(_render_mode, _vertex_array, 0, _faces_count * 3);
    context->set_depth_testing_enabled(false);
}
예제 #26
0
// Create an GLC_World from an input 3DS File
GLC_World* GLC_3dsToWorld::CreateWorldFrom3ds(QFile &file)
{
	clear();
	m_FileName= file.fileName();

	//////////////////////////////////////////////////////////////////
	// Test if the file exist and can be opened
	//////////////////////////////////////////////////////////////////
	if (!file.open(QIODevice::ReadOnly))
	{
		QString message(QString("GLC_3dsToWorld::CreateWorldFrom3ds File ") + m_FileName + QString(" doesn't exist"));
		GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::FileNotFound);
		throw(fileFormatException);
	}
	// Close the file before open it with lib3ds
	file.close();

	//////////////////////////////////////////////////////////////////
	// Init member
	//////////////////////////////////////////////////////////////////
	m_pWorld= new GLC_World;

	//Load 3ds File
	m_pLib3dsFile=lib3ds_file_load(m_FileName.toLocal8Bit().data());
	if (!m_pLib3dsFile)
	{
		QString message= "GLC_3dsToWorld::CreateWorldFrom3ds : Loading Failed";
		GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::FileNotSupported);
		clear();
		throw(fileFormatException);
	}
	// Evaluate Nodes Matrix for the first frame (Needed by instances)
	lib3ds_file_eval(m_pLib3dsFile, 0.0);
	m_CurrentQuantumValue= m_InitQuantumValue;
	m_PreviousQuantumValue= m_CurrentQuantumValue;

	emit currentQuantum(m_CurrentQuantumValue);
	// Count the number of meshes
	for(Lib3dsMesh *pMesh= m_pLib3dsFile->meshes; pMesh != NULL; pMesh = pMesh->next)
	{
		++m_NumberOfMeshes;
	}
	// Check if there is some meshes in the 3ds file
	if (0 == m_NumberOfMeshes)
	{
		QString message= "GLC_3dsToWorld::CreateWorldFrom3ds : No mesh found !";
		GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::NoMeshFound);
		clear();
		throw(fileFormatException);
	}

	// Create GLC_3DViewInstance with Node
	for (Lib3dsNode *pNode=m_pLib3dsFile->nodes; pNode!=0; pNode=pNode->next)
	{
		createMeshes(m_pWorld->rootOccurence(), pNode);
	}

	// Load unloaded mesh name
	for(Lib3dsMesh *pMesh= m_pLib3dsFile->meshes; pMesh != NULL; pMesh = pMesh->next)
	{
		if (!m_LoadedMeshes.contains(QString(pMesh->name)))
		{
			//qDebug() << "Mesh without parent found" << QString(pMesh->name);
			Lib3dsNode *pNode= lib3ds_node_new_object();
			strcpy(pNode->name, pMesh->name);
			pNode->parent_id= LIB3DS_NO_PARENT;
			lib3ds_file_insert_node(m_pLib3dsFile, pNode);
			createMeshes(m_pWorld->rootOccurence(), pNode);
		}
	}

	// Free Lib3dsFile and all its ressources
	lib3ds_file_free(m_pLib3dsFile);
	m_pLib3dsFile= NULL;
	emit currentQuantum(100);
	// Create the world bounding box
	m_pWorld->collection()->boundingBox();
	return m_pWorld;
}
예제 #27
0
    /*!
     * See \ref Loader3ds::loadFromFileToOneMesh
     */
    dcollide::Mesh* Loader3dsInternal::loadFromFileToOneMesh(const char* fileName, TextureInformation* textureInformation) {
        // AB:
        // we cannot load texture information here, because we are merging all
        // meshes into a single one.
        // -> adjusting the texels may still be possible, however if the model
        //    uses > 1 texture, we can't change that.

        mData->mProxy2Transformation.clear();
        mData->mProxy2TextureInformation.clear();
        if (!fileName) {
            throw dcollide::NullPointerException("fileName");
        }

        mFile = lib3ds_file_load(fileName);
        if (!mFile) {
            std::cout << dc_funcinfo << "unable to load " << fileName << std::endl;
            return 0;
        }

        // AB: some files don't store nodes and just want exactly one node per mesh.
        //     atm we don't support that.
        if (!mFile->nodes) {
            std::cout << dc_funcinfo << "File " << fileName << " does not contain any nodes. mesh-only files not supported currently." << std::endl;
            lib3ds_file_free(mFile);
            mFile = 0;
            return 0;
        }

        // 3ds stores several frames, we want the first
        lib3ds_file_eval(mFile, 0);

        std::list<Lib3dsNode*> nodes;
        Lib3dsNode* node = mFile->nodes;
        while (node) {
            nodes.push_back(node);
            node = node->next;
        }

        bool texelLoadError = false;
        std::vector<dcollide::Vector3> texels;
        std::vector<dcollide::Vertex*> vertices;
        std::vector<dcollide::Triangle*> triangles;
        std::vector<int> indices;
        while (!nodes.empty()) {
            Lib3dsNode* node = nodes.front();
            nodes.pop_front();

            for (Lib3dsNode* n = node->childs; n; n = n->next) {
                nodes.push_back(n);
            }

            // node->type can be object, light, camera, ...
            // -> only object nodes are relevant to us
            if (node->type != LIB3DS_OBJECT_NODE) {
                continue;
            }

            if (strcmp(node->name, "$$$DUMMY") == 0) {
                // AB: nodes with this name are only transformation nodes, i.e. they
                // don't have a mesh, only a matrix.
                continue;
            }

            unsigned int pointOffset = vertices.size();

            Lib3dsMesh* mesh = lib3ds_file_mesh_by_name(mFile, node->name);
            Lib3dsMatrix origMeshMatrix;
            lib3ds_matrix_copy(origMeshMatrix, mesh->matrix);
            lib3ds_matrix_inv(origMeshMatrix); // 3ds stores inverted mesh matrix
            dcollide::Matrix meshMatrix(&origMeshMatrix[0][0]);
            dcollide::Matrix nodeMatrix(&node->matrix[0][0]);

            Lib3dsObjectData* data = &node->data.object;
            nodeMatrix.translate(dcollide::Vector3(-data->pivot[0], -data->pivot[1], -data->pivot[2]));

            dcollide::Matrix matrix = nodeMatrix;
            matrix.multiply(&meshMatrix);

            for (unsigned int i = 0; i < mesh->points; i++) {
                Lib3dsPoint* p = &mesh->pointL[i];
                dcollide::Vector3 pos;
                matrix.transform(&pos, dcollide::Vector3(
                            p->pos[0],
                            p->pos[1],
                            p->pos[2]
                            ));
                vertices.push_back(new dcollide::Vertex(pos));
            }

            for (unsigned int i = 0; i < mesh->faces; i++) {
                Lib3dsFace* f = &mesh->faceL[i];
                indices.push_back(f->points[0] + pointOffset);
                indices.push_back(f->points[1] + pointOffset);
                indices.push_back(f->points[2] + pointOffset);
            }

            if (textureInformation) {
                TextureInformation t = loadTextureInformation(node);
                const std::vector<dcollide::Vector3>& nodeTexels = t.getTexels();
                if (mesh->texelL && nodeTexels.size() != mesh->texels) {
                    dcollide::warning() << "texturing problem in " << fileName;
                    dcollide::warning() << "invalid texel count loaded: have=" << nodeTexels.size() << " expected=" << mesh->texels;
                    dcollide::warning() << "adding dummy texels...";
                    for (unsigned int i = 0; i < mesh->texels; i++) {
                        texels.push_back(dcollide::Vector3(0.0, 0.0, 0.0));
                    }
//                    texelLoadError = true;
                } else {
                    for (unsigned int i = 0; i < nodeTexels.size(); i++) {
                        texels.push_back(nodeTexels[i]);
                    }
                }
            }
        }

        if (textureInformation) {
            if (!texelLoadError) {
                textureInformation->setTextured(true);
                textureInformation->setTextureFileName("deformable.tga");
                textureInformation->setTexels(texels);
            } else {
                textureInformation->setTextured(false);
            }
        }

        lib3ds_file_free(mFile);
        mFile = 0;

        dcollide::Mesh* mesh = new dcollide::Mesh(vertices, indices);
        return mesh;
    }
예제 #28
0
int main(int argc,char **argv)
{
   char *title="Einstein Explorer - SR v1.36 (Mark Hale)";
   int width=400, height=400;
#ifdef HAVE_LIB3DS
   if(argc==2) {
      file=lib3ds_file_load(argv[1]);
      eesrSetObject(draw3DS);
   }
#endif
/*
   printf("Special Relativity CAVE(tm) demo. By Bruno Barberi Gnecco and Mark Hale.\n");
   printf("Arguments are:\n"
	  "\t-wX\tWindow width. Default: 400.\n"
	  "\t-hX\tWindow height. Default: 400.\n"
	  "\t-s\tStereo mode.\n"
	  "\t-nX\tNumber of screens. Default: 5.\n"
	  "Anything else show this help.\n");

   while ( argc > 1 ) {
      switch ( argv[argc-1][1] ) {
      	 case 'h':
	    height = atoi(&argv[argc-1][2]);
	    break;
      	 case 'w':
	    width = atoi(&argv[argc-1][2]);
	    break;
      	 case 'n':
	    screens = atoi(&argv[argc-1][2]);
	    break;
      	 case 's':
	    stereo = TRUE;
	    break;
	 default:
	    exit(0);
	    break;
      }	  
      argc--;
   }
   GLUTCAVE_SET_SCREENS(screens);
*/
   glutInitWindowSize(width, height);
   glutInit(&argc, argv);
   if(stereo)
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STEREO);
   else
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

#ifdef HAVE_GLUTCAVE
   GLUTCAVE_CREATE_SUBWINDOWS_BEGIN(title, width, height);
#else
   glutCreateWindow(title);
#endif
   eesrInit();
   glutReshapeFunc(Reshape);
   glutDisplayFunc(Display);
   glutKeyboardFunc(Key);
   glutSpecialFunc(Special);
   glutMouseFunc(Mouse);
   glutMotionFunc(Motion);
   /* help menu */
   helpMID=glutCreateMenu(HelpMenu);
   glutAddMenuEntry("Arrow keys  :  left/right/forward/backward movement",1);
   glutAddMenuEntry("Page up/down  :  up/down movement",2);
   glutAddMenuEntry("<,>  :  rotate about the rotation axis",3);
   glutAddMenuEntry("1,2,3  :  select x/y/z axis component",4);
   glutAddMenuEntry("Home,End  :  increase/decrease current axis component",5);
   glutAddMenuEntry("+,-  :  increase/decrease speed",6);
   glutAddMenuEntry("t  :  increase time",7);
   glutAddMenuEntry("m  :  toggle menus/mouse movement",8);
   /* control menu */
   controlMID=glutCreateMenu(ControlMenu);
   glutAddMenuEntry("(right click for options)",1);
   glutAddMenuEntry("Pos:   +0.0,-12.5,+0.0",2);
   glutAddMenuEntry("Angle: +0.0",3);
   glutAddMenuEntry("Axis:  +0.0,+1.0,+0.0",4);
   glutAddMenuEntry("Speed: +0.00",5);
   glutAddSubMenu("Help",helpMID);
   glutAttachMenu(GLUT_LEFT_BUTTON);
   /* frame menu */
   frameMID=glutCreateMenu(FrameMenu);
   glutAddMenuEntry("World",1);
   glutAddMenuEntry("Object",2);
   /* object menu */
   objectMID=glutCreateMenu(ObjectMenu);
   glutAddMenuEntry("Lattice",1);
   glutAddMenuEntry("Car",2);
   glutAddMenuEntry("Aeroplane",3);
   glutAddMenuEntry("Sphere",4);
   glutAddMenuEntry("Rotating wheel",5);
   /* graphics menu */
   graphicsMID=glutCreateMenu(GraphicsMenu);
   glutAddMenuEntry("Wireframe on/off",1);
   glutAddMenuEntry("Texture on/off",2);
   glutAddMenuEntry("Fog on/off",3);
   /* options menu */
   optionMID=glutCreateMenu(OptionMenu);
   glutAddMenuEntry("(left click for controls)",1);
   glutAddSubMenu("Frame",frameMID);
   glutAddSubMenu("Object",objectMID);
   glutAddMenuEntry("Doppler on/off",2);
   glutAddSubMenu("Graphics",graphicsMID);
   glutAddMenuEntry("Exit",3);
   glutAttachMenu(GLUT_RIGHT_BUTTON);
#ifdef HAVE_GLUTCAVE
   GLUTCAVE_CREATE_SUBWINDOWS_END();
#endif
   glutMainLoop();
   return 0;
}
예제 #29
0
파일: 3dsplay.c 프로젝트: gdh1995/GhostFace
/*!
* 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.);
}
예제 #30
0
// load the model, and if the texture has textures, then apply them on the geometric primitives
void Model::LoadFile(const char *name)
{
	if(glIsEnabled(GL_LIGHTING))
	 lightEnabled = true;
	 else
	 lightEnabled = false;
	filename = name;
	// load file
	file = lib3ds_file_load(filename);
	if(!file) // if we were not able to load the file
	{
		// give some errors
		string event = "Error loading: ";
		event.append(filename);
		cout << event << endl;
		exit(1);
	}
	
//Node:
	/* No nodes?  Fabricate nodes to display all the meshes. */  
	if( !file->nodes )  
	{  
		cout << "No node found"<< endl;
		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);  
		} 
		//goto Node;
	}  
	
	static Lib3dsVector bmin, bmax;  
	static float    sx, sy, sz, size;   /* bounding box dimensions */  
	static float    cx, cy, cz;     /* bounding box center */  
	
 
	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;  
	
	
	
	
	lib3ds_file_eval(file, 0); // set current frame to 0
	// apply texture to all meshes that have texels
	
	
	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);  
		
	}  
	
	
	
	
	
	
	
	
	Lib3dsMesh *mesh;
	for(mesh = file->meshes;mesh != 0;mesh = mesh->next)
	{
		if(mesh->texels) //if there's texels for the mesh
			ApplyTexture(mesh); //then apply texture to it
	}
	if(file->lights) //if we have lights in our model
		CreateLightList();
}