Пример #1
0
static void RegisterAssimpModelParsers(C3DModelLoader::ParserMap& parsers, CAssParser* assParser) {
	std::string extension;
	std::string extensions;
	Assimp::Importer importer;

	// get a ";" separated list of format extensions ("*.3ds;*.lwo;*.mesh.xml;...")
	importer.GetExtensionList(extensions);

	// do not ignore the last extension
	extensions += ";";

	LOG("[%s] supported Assimp model formats: %s",
			__FUNCTION__, extensions.c_str());

	size_t i = 0;
	size_t j = 0;

	// split the list, strip off the "*." extension prefixes
	while ((j = extensions.find(";", i)) != std::string::npos) {
		extension = extensions.substr(i, j - i);
		extension = extension.substr(extension.find("*.") + 2);

		StringToLowerInPlace(extension);

		if (parsers.find(extension) == parsers.end()) {
			parsers[extension] = assParser;
		}

		i = j + 1;
	}
}
Пример #2
0
static void RegisterAssimpModelFormats(C3DModelLoader::FormatMap& formats) {
	std::string extension;
	std::string extensions;
	Assimp::Importer importer;

	// get a ";" separated list of format extensions ("*.3ds;*.lwo;*.mesh.xml;...")
	importer.GetExtensionList(extensions);

	// do not ignore the last extension
	extensions += ";";

	LOG("[%s] supported Assimp model formats: %s",
			__FUNCTION__, extensions.c_str());

	size_t curIdx = 0;
	size_t nxtIdx = 0;

	// split the list, strip off the "*." extension prefixes
	while ((nxtIdx = extensions.find(";", curIdx)) != std::string::npos) {
		extension = extensions.substr(curIdx, nxtIdx - curIdx);
		extension = extension.substr(extension.find("*.") + 2);
		extension = StringToLower(extension);

		if (formats.find(extension) == formats.end()) {
			formats[extension] = MODELTYPE_ASS;
		}

		curIdx = nxtIdx + 1;
	}
}
Пример #3
0
// ------------------------------------------------------------------------------------------------
// Get a list of all file extensions supported by ASSIMP
void aiGetExtensionList(aiString* szOut)
{
	ai_assert(NULL != szOut);
	ASSIMP_BEGIN_EXCEPTION_REGION();

	// FIXME: no need to create a temporary Importer instance just for that .. 
	Assimp::Importer tmp;
	tmp.GetExtensionList(*szOut);

	ASSIMP_END_EXCEPTION_REGION(void);
}
Пример #4
0
// ------------------------------------------------------------------------------------------------
// Get a list of all file extensions supported by ASSIMP
void aiGetExtensionList(aiString* szOut)
{
    ai_assert(NULL != szOut);
    ASSIMP_BEGIN_EXCEPTION_REGION();

#ifdef AI_C_THREADSAFE
    boost::mutex::scoped_lock lock(gMutex);
#endif

    if (!gActiveImports.empty()) {
        (*(gActiveImports.begin())).second->GetExtensionList(*szOut);
        return;
    }
    // fixme: no need to create a temporary Importer instance just for that ..
    Assimp::Importer tmp;
    tmp.GetExtensionList(*szOut);

    ASSIMP_END_EXCEPTION_REGION(void);
}
Пример #5
0
// ------------------------------------------------------------------------------------------------
// Get a list of all file extensions supported by ASSIMP
void aiGetExtensionList(aiString* szOut)
{
	ai_assert(NULL != szOut);

	// lock the mutex
#if (defined AI_C_THREADSAFE)
	boost::mutex::scoped_lock lock(gMutex);
#endif

	if (!gActiveImports.empty())
	{
		(*(gActiveImports.begin())).second->GetExtensionList(*szOut);
		return;
	}
	// need to create a temporary Importer instance.
	// TODO: Find a better solution ...
	Assimp::Importer* pcTemp = new Assimp::Importer();
	pcTemp->GetExtensionList(*szOut);
	delete pcTemp;
}
Пример #6
0
void HKWindow::addSourceModelsTriggered() {
	Assimp::Importer importer;
	std::string extensions_assimp = "";
	importer.GetExtensionList(extensions_assimp);

	QStringList extensions= QString(extensions_assimp.c_str()).split(";");
	extensions.removeOne("*");

	// Build Extensions String for Open Dialog
	QString extensions_str = "All supported formats (";
	foreach(QString extension, extensions)
		extensions_str += extension + " ";
	extensions_str += ");;";

	// Specific filters
	foreach(QString extension, extensions) {
		size_t index = importer.GetImporterIndex(extension.toStdString().c_str());
		if (index != -1) {
			const aiImporterDesc *description = importer.GetImporterInfo(index);
			extensions_str += QString("%1 (%2);;").arg(description->mName).arg(extension);
		}
	}
Пример #7
0
int main (int argc, char *argv[], char **env_var_ptr)
{
    int i=0;
    int mtlIndex=0;
    char out_filename[256];
    char mdl_filename[256];
    bool skinned=false;
    bool all=false;

    uint32_t hash=0;

    Hash_key simplek("SIMPLE");
    hash=simplek;
    printf("SIMPLE %u\n",hash);

    char *filename=argv[argc-1];
    strcpy(out_filename,filename);


    for (i=1; i< argc; i++) {
      if (!strcmp(argv[i],"-h"))
      {
          printHelp(argc,argv);
          exit(1);
      }

      if (!strcmp(argv[i],"-t"))
      {
          Hash_key key(argv[i+1]);
          hash=key;
      }

      if (!strcmp(argv[i],"-d"))
      {
          printAll=true;
      }

      if (!strcmp(argv[i],"-s"))
      {
          skinned=true;
      }

      if (!strcmp(argv[i],"-a"))
      {
          all=true;
      }


      if (!strcmp(argv[i],"-i"))
      {
          mtlIndex=atoi(argv[i+1]);
      }


      if (!strcmp(argv[i],"-o"))
      {
        strcpy(out_filename,argv[i+1]);
      }

      // printf("\narg%d=%s", i, argv[i]);
     }


    // Extract base
    char *pExt = strrchr(out_filename, '.');
    if (pExt != NULL)
        strcpy(pExt, ".pkg");
    else
        strcat(out_filename, ".pkg");

    Assimp::Importer importer;

    //const aiScene* scene = importer.ReadFile(filename,NULL);
    //             aiProcess_GenSmoothNormals |
    //          |  aiProcess_SortByPType

    const aiScene* scene = importer.ReadFile(filename,
            aiProcess_RemoveRedundantMaterials |
            aiProcess_Triangulate | aiProcess_GenSmoothNormals
            );

    if (scene==NULL)
    {
        std::string tmp;
        printf("Not able to read file error:%s\n",importer.GetErrorString());



        importer.GetExtensionList(tmp);
        printf("Supported extensions %s \n",tmp.c_str());
        exit(-1);

    }

    printf ("Found %d meshes\n",scene->mNumMeshes);
    printf ("Found %d materials\n",scene->mNumMaterials);
    printf ("Found %d animations\n",scene->mNumAnimations);


    std::vector<unsigned short int> indexTotal;
    std::vector<Vertex_t>           vrtxTotal;

    if (scene->HasMeshes())
        {
            // Each mesh is extracted to a mdl file.
            for (unsigned int ii = 0; ii < scene->mNumMeshes; ++ii)
            {
                std::vector<unsigned short int> indexes;
                t_mesh   tmp;
                tmp.indexes.clear();
                tmp.vrtx.clear();
                tmp.material=0;

                processMesh(scene->mMeshes[ii],tmp.vrtx,tmp.indexes,tmp.material,skinned);
                m_meshes.push_back(tmp);


                int offset=vrtxTotal.size();
                for(int q=0;q<tmp.vrtx.size();q++)
                {
                    vrtxTotal.push_back(tmp.vrtx[q]);
                }
                for(int q=0;q<tmp.indexes.size();q++)
                {
                    indexTotal.push_back(offset+tmp.indexes[q]);
                    int qk=offset+tmp.indexes[q];
                    printf("index %d ",offset+tmp.indexes[q]);
                    printf("(%f,%f,%f)\n",vrtxTotal[qk].pos[0],vrtxTotal[qk].pos[1],vrtxTotal[qk].pos[2]);
                }

                //printf("Mesh %d Has %d vertices and material %d\n",ii,scene->mMeshes[ii]->mNumVertices,tmp.material);
                aiMesh *mesh=scene->mMeshes[ii];

                char Buff[512];
                sprintf(Buff,"%d-%s.mdl",ii,mesh->mName.C_Str());

                std::string filename;

                if(mesh->mMaterialIndex  >= 0)
                {

                  aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];


                   filename = textureFilename(material,aiTextureType_DIFFUSE);
                }

                Hash_key key(filename.c_str());
                hash=key;


                writeToMdlFile(Buff,tmp.vrtx,tmp.indexes,skinned,hash);
                mdlFiles.push_back(std::string(Buff));


                if(mesh->mMaterialIndex  >= 0)
                {



                    aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];

                    //textureFilename =


                    //vector<Texture> diffuseMaps = this->loadMaterialTextures(material,
                    //                                    aiTextureType_DIFFUSE, "texture_diffuse");
                    //textures_loaded.insert(textures_loaded.end(), diffuseMaps.begin(), diffuseMaps.end());
                    //vector<Texture> specularMaps = this->loadMaterialTextures(material,
                    //                                    aiTextureType_SPECULAR, "texture_specular");
                    //textures_loaded.insert(textures_loaded.end(), specularMaps.begin(), specularMaps.end());

                }




                //scene->mMaterials[material]->GetTexture()
                //if (ii==extractMeshnum )
                //{
                //    char Buff[512];
                //    sprintf(Buff,"%d-%s",ii,out_filename);
                //    writeToMdlFile(Buff,tmp.vrtx,tmp.indexes,skinned,hash);
                //}

            }

            mergeToPkg(out_filename);
            //writeToMdlFile(out_filename,vrtxTotal,indexTotal,skinned,hash);


#if 0

            // This extracts all meshes to a single file :-P
            if (scene->HasMeshes())
                {
                    for (unsigned int ii = 0; ii < scene->mNumMeshes; ++ii)
                    {
                        std::vector<unsigned short int> indexes;
                        t_mesh   tmp;
                        tmp.indexes.clear();
                        tmp.vrtx.clear();
                        tmp.material=0;

                        processMesh(scene->mMeshes[ii],tmp.vrtx,tmp.indexes,tmp.material,skinned);
                        m_meshes.push_back(tmp);


                        int offset=vrtxTotal.size();
                        for(int q=0;q<tmp.vrtx.size();q++)
                        {
                            vrtxTotal.push_back(tmp.vrtx[q]);
                        }
                        for(int q=0;q<tmp.indexes.size();q++)
                        {
                            indexTotal.push_back(offset+tmp.indexes[q]);
                            int qk=offset+tmp.indexes[q];
                            printf("index %d ",offset+tmp.indexes[q]);
                            printf("(%f,%f,%f)\n",vrtxTotal[qk].pos[0],vrtxTotal[qk].pos[1],vrtxTotal[qk].pos[2]);
                        }

                        printf("Mesh %d Has %d vertices and material %d\n",ii,scene->mMeshes[ii]->mNumVertices,tmp.material);
                        //scene->mMaterials[material]->GetTexture()
                        if (ii==extractMeshnum )
                        {
                            char Buff[512];
                            sprintf(Buff,"%d-%s",ii,out_filename);
                            writeToMdlFile(Buff,tmp.vrtx,tmp.indexes,skinned,hash);
                        }

                    }

                    writeToMdlFile(out_filename,vrtxTotal,indexTotal,skinned,hash);
            }

            // All meshes are cached, extract nodes
            if (scene->mRootNode != NULL)
            {
                Node *rootNode = new Node;
                processNode(scene, scene->mRootNode, 0, *rootNode);

                allUsedMeshes.clear();
                allUsedIndexes.clear();

                mergeAllNodes(rootNode,scene);

                writeToMdlFile(out_filename,allUsedMeshes,allUsedIndexes,skinned,hash);
                //m_rootNode.reset(rootNode);


            }
            else
            {
                printf("Error loading model, No ROOT node");
                exit(-1);
            }
#endif



        }
        else
        {
            printf("Error: No meshes found");
            return false;
        }

    for (unsigned int ii = 0; ii < scene->mNumMaterials; ++ii)
    {
        //printf("Material %d has %d textures\n",ii,scene->mMaterials[ii]->GetTextureCount());
                //QSharedPointer<MaterialInfo> mater = processMaterial(scene->mMaterials[ii]);
                //m_materials.push_back(mater);
    }



}
Пример #8
0
// ------------------------------------------------------------------------------
// Application entry point
int main (int argc, char* argv[])
{
	if (argc <= 1)	{
		printf("assimp: No command specified. Use \'assimp help\' for a detailed command list\n");
		return 0;
	}

	// assimp version
	// Display version information
	if (! strcmp(argv[1], "version")) {
		const unsigned int flags = aiGetCompileFlags();
		printf(AICMD_MSG_ABOUT,
			aiGetVersionMajor(),
			aiGetVersionMinor(),
			(flags & ASSIMP_CFLAGS_DEBUG ?			"-debug "   : ""),
			(flags & ASSIMP_CFLAGS_NOBOOST ?		"-noboost " : ""),
			(flags & ASSIMP_CFLAGS_SHARED ?			"-shared "  : ""),
			(flags & ASSIMP_CFLAGS_SINGLETHREADED ? "-st "      : ""),
			(flags & ASSIMP_CFLAGS_STLPORT ?		"-stlport " : ""),
			aiGetVersionRevision());

		return 0;
	}

	// assimp help
	// Display some basic help (--help and -h work as well 
	// because people could try them intuitively)
	if (!strcmp(argv[1], "help") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
		printf("%s",AICMD_MSG_HELP);
		return 0;
	}

	// assimp cmpdump
	// Compare two mini model dumps (regression suite) 
	if (! strcmp(argv[1], "cmpdump")) {
		return Assimp_CompareDump (&argv[2],argc-2);
	}

	// construct global importer and exporter instances
	Assimp::Importer imp;
	imp.SetPropertyBool("GLOB_MEASURE_TIME",true);
	globalImporter = &imp;

#ifndef ASSIMP_BUILD_NO_EXPORT
	// 
	Assimp::Exporter exp;
	globalExporter = &exp;
#endif

	// assimp listext
	// List all file extensions supported by Assimp
	if (! strcmp(argv[1], "listext")) {
		aiString s;
		imp.GetExtensionList(s);

		printf("%s\n",s.data);
		return 0;
	}

#ifndef ASSIMP_BUILD_NO_EXPORT
	// assimp listexport
	// List all export file formats supported by Assimp (not the file extensions, just the format identifiers!)
	if (! strcmp(argv[1], "listexport")) {
		aiString s;
		
		for(size_t i = 0, end = exp.GetExportFormatCount(); i < end; ++i) {
			const aiExportFormatDesc* const e = exp.GetExportFormatDescription(i);
			s.Append( e->id );
			if (i!=end-1) {
				s.Append("\n");
			}
		}

		printf("%s\n",s.data);
		return 0;
	}


	// assimp exportinfo
	// stat an export format
	if (! strcmp(argv[1], "exportinfo")) {
		aiString s;

		if (argc<3) {
			printf("Expected file format id\n");
			return -11;
		}

		for(size_t i = 0, end = exp.GetExportFormatCount(); i < end; ++i) {
			const aiExportFormatDesc* const e = exp.GetExportFormatDescription(i);
			if (!strcmp(e->id,argv[2])) {
				printf("%s\n%s\n%s\n",e->id,e->fileExtension,e->description);
				return 0;
			}
		}
		
		printf("Unknown file format id: \'%s\'\n",argv[2]);
		return -12;
	}

	// assimp export
	// Export a model to a file
	if (! strcmp(argv[1], "export")) {
		return Assimp_Export (&argv[2],argc-2);
	}

#endif

	// assimp knowext
	// Check whether a particular file extension is known by us, return 0 on success
	if (! strcmp(argv[1], "knowext")) {
		if (argc<3) {
			printf("Expected file extension");
			return -10;
		}
		const bool b = imp.IsExtensionSupported(argv[2]);
		printf("File extension \'%s\'  is %sknown\n",argv[2],(b?"":"not "));
		return b?0:-1;
	}

	// assimp info
	// Print basic model statistics
	if (! strcmp(argv[1], "info")) {
		return Assimp_Info ((const char**)&argv[2],argc-2);
	}

	// assimp dump 
	// Dump a model to a file 
	if (! strcmp(argv[1], "dump")) {
		return Assimp_Dump (&argv[2],argc-2);
	}

	// assimp extract 
	// Extract an embedded texture from a file
	if (! strcmp(argv[1], "extract")) {
		return Assimp_Extract (&argv[2],argc-2);
	}

	// assimp testbatchload
	// Used by /test/other/streamload.py to load a list of files
	// using the same importer instance to check for incompatible
	// importers.
	if (! strcmp(argv[1], "testbatchload")) {
		return Assimp_TestBatchLoad (&argv[2],argc-2);
	}

	printf("Unrecognized command. Use \'assimp help\' for a detailed command list\n");
	return 1;
}
Пример #9
0
int main(int argc, char **argv)
{

	//Initializes console Position
	HWND hWnd = GetConsoleWindow();
	MoveWindow(hWnd, 1350, 0, 500, 1000, TRUE);
	std::cout << "GameArtsEngine" << std::endl;


	//Initializes SDL and gets everything set up 
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window *window = SDL_CreateWindow("GameArtsEngine", 40, 40, windowWidth, windowHeight, SDL_WINDOW_OPENGL);
	SDL_GLContext glcontext = SDL_GL_CreateContext(window);

	//Initializes our Glew
	glewInit();

	//Initializes our Engine
	iGAEngine->initGL(windowWidth, windowHeight);

	aiString list;
	Assimp::Importer imp;
	imp.GetExtensionList(list);
	std::cout << list.C_Str() << std::endl;




										/**************************************ALL THE ONE TIME SCENE SETUP GOES HERE*******************************************/

	
	//Creates a basic Light for our scene --> will eventually be moved to the Engine itself
	mainLight = new Light(LIGHT_POINT);
	mainLight->setDiffuse(2, 2, 2, 1);
	mainLight->setExponent(10);
	mainLight->setPosition(-5,25,5);

	
	//Load Textures
	defaultTexture = iGAEngine->loadTexture("Assets/Textures/ModelgridTexture.jpg");

	//Load Models->Primitives ------------------------ENABLE IF YOU NEED PRIMITIVES---------------------------------
	teapodModel = new meshLoader("Assets/Models/Primitives/teapod.dae");
	cylinderModel = new meshLoader("Assets/Models/Primitives/cylinder.dae");
	sphereModel = new meshLoader("Assets/Models/Primitives/sphere.dae");
	cubeModel = new meshLoader("Assets/Models/Primitives/cube.dae");
	

	//Load Models->GameModels

	//-----------------------------------------------------------------------------------------SHADERSETUP--------------------------------------------
	
	if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader){

		cout << endl << "SHADER LOG: -------------------------------------------------------- BEGIN" << endl;
		
		// Simple Normal Shader without SpecMap
		normalShader = new Shader("normal.vert", "normal.frag");
		normalShader->useShader();
		normalShader->setAttribute1i("diffuseMap0", 0);
		normalShader->setAttribute1i("normalMap1", 1);
		normalShader->setAttribute1f("SpecularPower", 2.0f);
		normalShader->setAttribute4f("Specular", 0.5, 0.5, 0.5, 1.0);
		normalShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
		normalShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
		normalShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);

		// Normal Shader with SpecMap
		normalSpecShader = new Shader("normalSpec.vert", "normalSpec.frag");
		normalSpecShader->useShader();
		normalSpecShader->setAttribute1i("diffuseMap0", 0);
		normalSpecShader->setAttribute1i("normalMap1", 1);
		normalSpecShader->setAttribute1i("specularMap2", 2);
		normalSpecShader->setAttribute1f("SpecularPower", 2.0f);
		normalSpecShader->setAttribute4f("Specular", 0.5, 0.5, 0.5, 1.0);
		normalSpecShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
		normalSpecShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
		normalSpecShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);

		// Simple LambertShader with DiffuseMap
		diffuseShader = new Shader("lambertDiffuse.vert", "lambertDiffuse.frag");
		diffuseShader->useShader();
		diffuseShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
		diffuseShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
		diffuseShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);


		lambertShader_static = new Shader("lambert_static.vert", "lambert_static.frag");
		lambertShader_static->useShader();
		lambertShader_static->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
		lambertShader_static->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
		lambertShader_static->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);
		
		cout << endl << "SHADER LOG: ---------------------------------------------------------- END" << endl;

	}
	else{
		cout << endl << "GLSL not supported" << endl;
	}

	//-----------------------------------------------------------------------------------------SHADERSETUP--------------------------------------------




										/**************************************ALL THE ONE TIME SCENE SETUP GOES HERE*******************************************/

	
	// Main Engine Loop
	bool isRunning = true;
	SDL_Event  event;

	while (isRunning )
	{
		//Gets states of the Mouse and stroes them in the struct
		SDL_GetMouseState(&mouseState.x, &mouseState.y);
		mouseState.LeftButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1);
		mouseState.MiddleButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2);
		mouseState.RightButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3);

		drawMainScene(window); // calls stuff that needs to update every frame
		
		//Event loop
		while (SDL_PollEvent(&event)){

			if (event.type == SDL_QUIT)
				isRunning = false;
		}


		if (viewportNavigation())
			isRunning = false;
	}

	delete teapodModel;
	delete lambertShader_static;
	delete diffuseShader;
	delete normalShader;
	delete normalSpecShader;

	GAEngine::Unitialize();


	SDL_Quit();

	return 1;

}