bool AURenMesh::LoadFromFileImport( const std::string& strFilename )
{
#ifndef NO_ASSIMP
	Assimp::Importer importer;

	const aiScene* pScene = importer.ReadFile( strFilename, aiProcessPreset_TargetRealtime_Fast );

	if (!pScene || pScene->mNumMeshes == 0)
	{
		return false;
	}

	ProcessScene(pScene);
	
	return true;
#else
    assert( false );
    return false;
#endif
}
Example #2
0
void Model::loadModel(std::string path) {
	// Read file via ASSIMP
	Assimp::Importer importer;
	const aiScene* scene = importer.ReadFile(path,
			aiProcess_Triangulate | aiProcess_FlipUVs
					| aiProcess_CalcTangentSpace);
	// Check for errors
	if (!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE
			|| !scene->mRootNode) // if is Not Zero
			{
		std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString()
				<< std::endl;
		return;
	}
	// Retrieve the directory path of the filepath
	this->directory = path.substr(0, path.find_last_of('/'));

	// Process ASSIMP's root node recursively
	this->processNode(scene->mRootNode, scene);
}
Example #3
0
TEST_F( utIssues, OpacityBugWhenExporting_727 ) {
    float opacity;
    aiScene *scene( TestModelFacttory::createDefaultTestModel( opacity ) );
    Assimp::Importer importer;
    Assimp::Exporter exporter;
                
    std::string path = "dae";
    const aiExportFormatDesc *desc( exporter.GetExportFormatDescription( 0 ) );
    EXPECT_NE( desc, nullptr );
    path.append( desc->fileExtension );
    EXPECT_EQ( AI_SUCCESS, exporter.Export( scene, desc->id, path ) );
    const aiScene *newScene( importer.ReadFile( path, 0 ) );
    EXPECT_TRUE( NULL != newScene );
    float newOpacity;
    if ( newScene->mNumMaterials > 0 ) {
        std::cout << "Desc = " << desc->description << "\n";
        EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) );
        EXPECT_EQ( opacity, newOpacity );
    }
}
Example #4
0
Model::Model(string file)
{
	if (!Globals::File_Exists(FOLDER+file)) {
		cout << "File " << FOLDER + file << " does not exist. Can not load model." << endl;
		return;
	}

	path = FOLDER + file.substr(0, file.find_last_of('/')) + '/';
	Assimp::Importer importer;
	const aiScene* scene = importer.ReadFile(FOLDER + file, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals | aiProcess_CalcTangentSpace);

	if (!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
	{
		cout << "ERROR::ASSIMP::" << importer.GetErrorString() << endl;
		return;
	}

	processNode(scene->mRootNode, scene);
	
}
Example #5
0
// ------------------------------------------------------------------------------------------------
const aiScene* aiImportFileFromMemoryWithProperties( 
	const char* pBuffer,
	unsigned int pLength,
	unsigned int pFlags,
	const char* pHint,
	const aiPropertyStore* props)
{
	ai_assert(NULL != pBuffer && 0 != pLength);

	const aiScene* scene = NULL;
	ASSIMP_BEGIN_EXCEPTION_REGION();

	// create an Importer for this file
	Assimp::Importer* imp = new Assimp::Importer();

	// copy properties
	if(props) {
		const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
		ImporterPimpl* pimpl = imp->Pimpl();
		pimpl->mIntProperties = pp->ints;
		pimpl->mFloatProperties = pp->floats;
		pimpl->mStringProperties = pp->strings;
	}

	// and have it read the file from the memory buffer
	scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);

	// if succeeded, store the importer in the scene and keep it alive
	if( scene)	{
		 ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
		 priv->mOrigImporter = imp;
	} 
	else	{
		// if failed, extract error code and destroy the import
		gLastErrorString = imp->GetErrorString();
		delete imp;
	}
	// return imported data. If the import failed the pointer is NULL anyways
	ASSIMP_END_EXCEPTION_REGION(const aiScene*);
	return scene;
}
Example #6
0
MeshData LoadMesh( const std::string& pFile)
{

   MeshData mesh;

	//check if file exists
	std::ifstream fin(pFile.c_str());
	if(!fin.fail()) 
   {
		fin.close();
	}
	else
   {
		printf("Couldn't open file: %s\n", pFile.c_str());
		printf("%s\n", importer.GetErrorString());
		return mesh;
	}

	mesh.mScene = importer.ReadFile( pFile, aiProcessPreset_TargetRealtime_Quality);//|aiProcess_FlipWindingOrder);

	// If the import failed, report it
	if( !mesh.mScene)
	{
		printf("%s\n", importer.GetErrorString());
		return mesh;
	}

	// Now we can access the file's contents.
	printf("Import of scene %s succeeded.", pFile.c_str());

	GetBoundingBox(mesh.mScene, &mesh.mBbMin, &mesh.mBbMax);
   aiVector3D diff = mesh.mBbMax-mesh.mBbMin;
   float w = std::max(diff.x, std::max(diff.y, diff.z));

	mesh.mScaleFactor = 1.0f / w;

	
   BufferIndexedVerts(mesh);
   mesh.mNumIndices = mesh.mScene->mMeshes[0]->mNumFaces*3;
	return mesh;
}
Example #7
0
void Mesh::parseAI(const char* path){
   Assimp::Importer importer;
   const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_JoinIdenticalVertices);

   skeleton = Skeleton(scene);

   if(!scene) {
      ERROR("Could not import file: " << path);
      ERROR("Reason: " << importer.GetErrorString());
      exit(1);
   }
   debugNodes(scene->mRootNode, 0);
   const aiMesh* mesh = scene->mMeshes[0];

   for(unsigned int v=0; v<mesh->mNumVertices; v++){
      vertices.push_back(glm::vec3(mesh->mVertices[v][0],
                                   mesh->mVertices[v][1],
                                   mesh->mVertices[v][2]));
   }

   for(unsigned int n=0; n<mesh->mNumVertices; n++){
      normals.push_back(glm::vec3(mesh->mNormals[n][0],
                                   mesh->mNormals[n][1],
                                   mesh->mNormals[n][2]));
   }

   for(unsigned int f=0; f<mesh->mNumFaces; f++){
      aiFace face = mesh->mFaces[f];
      if(face.mNumIndices != 3) {
         ERROR("NON-TRIANGULAR POLY");
      }
      indeces.push_back(glm::uvec3(face.mIndices[0],
                                   face.mIndices[1],
                                   face.mIndices[2]));
   }

   for(unsigned int u=0; u<mesh->mNumVertices; u++){
      uvs.push_back(glm::vec2(mesh->mTextureCoords[0][u].x, mesh->mTextureCoords[0][u].y));
   }
   reset();
}
Example #8
0
Mesh * LoadMesh(const char * filename)
{
	// Create an instance of the Importer class
	Assimp::Importer importer;
	// And have it read the given file with some example postprocessing
	// Usually - if speed is not the most important aspect for you - you'll 
	// propably to request more postprocessing than we do in this example.
	const aiScene* aiscene = importer.ReadFile( filename, 
		aiProcess_CalcTangentSpace       | 
		aiProcess_Triangulate            |
		aiProcess_JoinIdenticalVertices  |
		aiProcess_SortByPType);

	// If the import failed, report it
	if( !aiscene)
	{
		printf("%s \n", importer.GetErrorString());
		return NULL;
	}

	aiMesh * aimesh;
	Mesh * mesh = new Mesh();

	std::vector<vec3> vertex;
	std::vector<vec3> normal;
	std::vector<vec3> tangent;
	std::vector<vec2> texCoord;

	// Now we can access the file's contents.
	for(u32 i=0; i<aiscene->mNumMeshes(); ++i)
	{
		aimesh = aiscene->mMeshes[i];

		if(aimesh->HasPositions())
		{

		}
	}

	return mesh;
}
int SceneLoader::LoadFile(const char* filename)
{
	Assimp::Importer importer;

	const aiScene *scene = importer.ReadFile(filename, 0);
	scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace | aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_JoinIdenticalVertices);
	if (!scene)
	{
		std::stringstream oss;
		oss << "ERROR - File: " << filename << " not found." << std::endl;
		std::string debugMsg(oss.str());
		OutputDebugStringA(debugMsg.c_str());
		return false;
	}
	DrawableObject *newObject = new DrawableObject();
	std::vector<Vertex> vertexList;
	std::vector<UINT> indexList;
	std::stringstream oss;
	for (unsigned int i = 0; i < scene->mRootNode->mNumChildren; ++i)
	{
		bool successfulLoad = true;
		aiNode* currentNode = scene->mRootNode->mChildren[i];
		BuildShaders(d3dDevice, *newObject, mShaderManager);
		for (unsigned int j = 0; j < currentNode->mNumMeshes; ++j)
		{
			ProcessMesh(d3dDevice, *scene->mMeshes[currentNode->mMeshes[j]], *newObject, vertexList, indexList, scene->mMeshes[currentNode->mMeshes[j]]->mMaterialIndex - 1);
			//LoadMaterials(d3dDevice, scene->mMeshes[currentNode->mMeshes[j]]->mMaterialIndex, *newObject, scene);
			oss << "MatIndex = " << scene->mMeshes[currentNode->mMeshes[j]]->mMaterialIndex << "\n";
		}
	}
	std::string debugMsg(oss.str());
	OutputDebugStringA(debugMsg.c_str());
	for (unsigned int i = 0; i < scene->mNumMaterials; ++i)
	{
		LoadMaterials(d3dDevice, i, *newObject, scene);
	}
	newObject->GetMeshData()->Initialize(d3dDevice, vertexList, indexList);
	mDrawableObjects.push_back(newObject);

	return mDrawableObjects.size() - 1;
}
Example #10
0
// ------------------------------------------------------------------------------------------------
const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, 
	aiFileIO* pFS)
{
	ai_assert(NULL != pFile);

	// create an Importer for this file
	Assimp::Importer* imp = new Assimp::Importer;

	// copy the global property lists to the Importer instance
	// (we are a friend of Importer)
	imp->pimpl->mIntProperties = gIntProperties;
	imp->pimpl->mFloatProperties = gFloatProperties;
	imp->pimpl->mStringProperties = gStringProperties;

	// setup a custom IO system if necessary
	if (pFS)
	{
		imp->SetIOHandler( new CIOSystemWrapper (pFS) );
	}

	// and have it read the file
	const aiScene* scene = imp->ReadFile( pFile, pFlags);

	// if succeeded, place it in the collection of active processes
	if( scene)
	{
#if (defined AI_C_THREADSAFE)
		boost::mutex::scoped_lock lock(gMutex);
#endif
		gActiveImports[scene] = imp;
	} 
	else
	{
		// if failed, extract error code and destroy the import
		gLastErrorString = imp->GetErrorString();
		delete imp;
	}

	// return imported data. If the import failed the pointer is NULL anyways
	return scene;
}
Example #11
0
std::shared_ptr<Scene> SceneFactory::CreateFromFile(const std::string& filename) {
	Assimp::Importer importer;
	const aiScene* scene = importer.ReadFile(filename,
		aiProcess_Triangulate |
		aiProcess_GenNormals |
		aiProcess_ImproveCacheLocality |
		aiProcess_JoinIdenticalVertices |
		aiProcess_PreTransformVertices);

	if (scene == NULL) {
		std::printf("\nImport failed:\n\t");
		auto errorString = importer.GetErrorString();
		std::printf(errorString);
		std::printf("\n");
		return nullptr;
	}
	Scene::vertexList vertices = GetVertices(scene);
	Scene::triangleList faces = GetFaces(scene);
	Scene::materialList materials = GetMaterials(scene);
	return std::shared_ptr<Scene>(new Scene(vertices, faces, materials));
}
Example #12
0
std::shared_ptr<MeshData> RE::FileSystem::LoadModel(const std::wstring &filePath)
{
    const std::string sFilePaths{ filePath.begin(), filePath.end() };
    Assimp::Importer importer;

    const aiScene *scene = importer.ReadFile(sFilePaths,
        aiProcess_CalcTangentSpace | 
        aiProcess_Triangulate | 
        aiProcess_JoinIdenticalVertices |
        aiProcess_SortByPType | 
        aiProcess_ConvertToLeftHanded |
        aiProcess_FixInfacingNormals
        );
   
    if (!scene)
    {
        Log::Get().Write(std::string("[FileSystem] Assimp importer could not read mesh file:") + importer.GetErrorString());
    }

    return std::make_shared<MeshData>(ProcessAssimpScene(scene->mRootNode, scene));
}
Example #13
0
void Mesh::Load()
{
	Clear();

	Assimp::Importer importer;

	const aiScene* scene = importer.ReadFile(sFilepath.c_str(), 
		aiProcess_Triangulate | aiProcess_GenSmoothNormals | 
		aiProcess_FlipUVs);

	if(scene)
	{
		InitMesh(scene, sFilepath);
	}
	else
	{
		std::cout << "Cannot find " << sFilepath << " " << importer.GetErrorString() << std::endl;
		//throw std::runtime_error(std::string("Error Parsing: ") + sFilepath +
			//std::string("\n") + importer.GetErrorString());
	}
}
Example #14
0
// ------------------------------------------------------------------------------------------------
// Returns the error text of the last failed import process.
aiBool aiIsExtensionSupported(const char* szExtension)
{
    ai_assert(NULL != szExtension);
    aiBool candoit=AI_FALSE;
    ASSIMP_BEGIN_EXCEPTION_REGION();

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

    if (!gActiveImports.empty()) {
        return ((*(gActiveImports.begin())).second->IsExtensionSupported( szExtension )) ? AI_TRUE : AI_FALSE;
    }

    // fixme: no need to create a temporary Importer instance just for that ..
    Assimp::Importer tmp;
    candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;

    ASSIMP_END_EXCEPTION_REGION(aiBool);
    return candoit;
}
Example #15
0
const std::vector<Mesh> & Mesh::loadModel(const std::string & modelName) {
	static std::unordered_map<std::string, std::vector<Mesh>> meshMap;
	if (meshMap.count(modelName) == 0) {
		Assimp::Importer importer;
		auto scene = importer.ReadFile(modelName,
									   aiProcess_GenNormals |
									   aiProcess_JoinIdenticalVertices |
									   aiProcess_Triangulate |
									   aiProcess_ImproveCacheLocality |
									   aiProcess_RemoveRedundantMaterials |
									   aiProcess_FlipUVs/* |
									   aiProcess_RemoveComponent*/);
		if (!scene) {
			throw std::runtime_error("Could not load model: " + modelName);
		}
		std::vector<Mesh> meshData;
		loadMesh(modelName, meshData, scene->mRootNode, scene);
		meshMap.emplace(modelName, std::move(meshData));
	}
	return meshMap[modelName];
}
Example #16
0
sceneLoader::sceneLoader(const char* filename)
{
	Assimp::Importer importer;
	//Initialize DevIL
	initDevIL(); 
	
	const aiScene* scene=importer.ReadFile(filename, 
											aiProcess_GenSmoothNormals|
											aiProcess_Triangulate|
											aiProcess_CalcTangentSpace|
											aiProcess_FlipUVs);

	if(scene->mFlags==AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) 
	{ 
      fprintf( stderr, "Couldn't load model, Error Importing Asset" );	   
	  return;
	} 

	recursiveProcess(scene->mRootNode, scene);

}
Example #17
0
bool Mesh::LoadMesh(const std::string& Filename)
{
    // Release the previously loaded mesh (if it exists)
    Clear();
    
    bool Ret = false;
    Assimp::Importer Importer;

    const aiScene* pScene = Importer.ReadFile(Filename.c_str(), aiProcess_Triangulate |
                                                                aiProcess_GenSmoothNormals |
                                                                aiProcess_FlipUVs |
                                                                aiProcess_CalcTangentSpace);    
    if (pScene) {
        Ret = InitFromScene(pScene, Filename);
    }
    else {
        printf("Error parsing '%s': '%s'\n", Filename.c_str(), Importer.GetErrorString());
    }

    return Ret;
}
Example #18
0
void Model::loadModel(std::string path)
{
	Assimp::Importer import;
	//http://assimp.sourceforge.net/lib_html/postprocess_8h.html
	//aiProcess_GenNormals 
	//aiProcess_GenSmoothNormals 
	//											 triangulate			 flip uv y			 avoid duplicate verts			   make norms if not	  make bitangent and tangent
	const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_JoinIdenticalVertices | aiProcess_GenNormals | aiProcess_CalcTangentSpace);

	if (!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
	{
		std::string str = "ASSIMP ERROR: \""; str += path; str += "\" NOT LOADED;";
		Logger::Log(str);
		return;
	}
	
	int foundSlash = 0;
	int foundDot = path.size()-1;
	for (int i = 0; i != path.size() - 1; ++i)
	{
		if (path[i] == '/' || path[i] == '\\')
			foundSlash = i+1;

		if (path[i] == '.')
			foundDot = i;
	}

	fileName = "";
	for (int i = foundSlash; i != foundDot; ++i)
	{
		fileName += path[i];
	}

	this->directory = path.substr(0, path.find_last_of('/'));

	this->processNode(scene->mRootNode, scene);

	std::string str = "Model ASSIMP: \""; str += path; str += "\" LOADED;";
	Logger::Log(str);
}
Resource* ResourceManager::LoadMesh(std::string filepath)
{
	Assimp::Importer importer;

	const aiScene* scene = importer.ReadFile(filepath, aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);
	
	// NOTE: Depending on what ReadFile returns, this may not work as intended
	if (!scene)
	{
#if DEBUG
		Debug::LogError("[ResourceManager] Assimp importer could not read file.");
#endif
		return 0;
	}
	MeshData data = AssimpProcessScene(scene->mRootNode, scene);
	
	Mesh* mesh = new Mesh(data);

	mesh->IncreaseReferenceCount();
	resourceCollection[filepath] = mesh;
	return dynamic_cast<Resource*>(mesh);
}
Example #20
0
bool ModelLoader::Load( std::string filename, Vertex::VERTEX_TYPE type ) {
	// reset extents
	minX = minY = minZ = FLT_MAX;
	maxX = maxY = maxZ = FLT_MIN;

	Assimp::Importer importer;
	std::string file = modelDir+filename;
	Assimp::DefaultLogger::get()->info( "Importing: "+file );
	scene = importer.ReadFile( file,
		//aiProcess_CalcTangentSpace|
		aiProcess_ImproveCacheLocality|
		//aiProcess_MakeLeftHanded|
		aiProcess_FlipWindingOrder|
		aiProcess_Triangulate|
		//aiProcess_JoinIdenticalVertices|
		aiProcess_SortByPType|
		aiProcess_FlipUVs
		);

	if( !scene ) {
		Assimp::DefaultLogger::get()->error( importer.GetErrorString() );
		return false;
	}
	if( !scene->HasMeshes() ) {
		Assimp::DefaultLogger::get()->error( "File contains no mesh" );
		return false;
	}
	aiMesh* sceneMesh = scene->mMeshes[0];
	CreateVertexBuffer( sceneMesh, type );
	CreateIndexBuffer( sceneMesh->mFaces, sceneMesh->mNumFaces );
	
	if( scene->HasAnimations() ) {
		CreateSkeleton( sceneMesh->mBones, sceneMesh->mNumBones );
		CreateBoneHierarchy();
		CreateAnimations();
	}
	
	return true;
}
Example #21
0
bool Mesh::LoadMesh(const std::string& Filename)
{

    Clear();

    bool Ret = false;

    Assimp::Importer Importer;

    const aiScene* pScene = Importer.ReadFile(Filename.c_str(),
                                    aiProcess_Triangulate | aiProcess_GenSmoothNormals|
                                    aiProcess_FlipUVs);

    if (pScene){
        Ret = InitFromScene(pScene, Filename);
    }
    else {
        printf("Error parsing '%s': '%s'\n", Filename.c_str(), Importer.GetErrorString());
    }

    return Ret;
}
Example #22
0
void Model::loadModel(string path)
{
	Assimp::Importer importer;
	/*
	aiProcess_FlipUVs: 基于y轴翻转纹理坐标(前面的教程中有)
	aiProcess_Triangulate: 如果模型不是(全部)由三角形组成,应该转换所有的模型的原始几何形状为三角形。
	aiProcess_GenNormals: 如果模型没有包含法线向量,就为每个顶点创建法线。
	aiProcess_SplitLargeMeshes: 把大的网格成几个小的的下级网格,当你渲染有一个最大数量顶点的限制时或者只能处理小块网格时很有用。
	aiProcess_OptimizeMeshes: 和上个选项相反,它把几个网格结合为一个更大的网格。以减少绘制函数调用的次数的方式来优化。
	*/
	const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
	
	if (!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
	{
		cout << "ERROR::ASSIMP::" << importer.GetErrorString() << endl;
		return;
	}

	this->directory = path.substr(0, path.find_last_of('/')) + "/";

	this->processNode(scene->mRootNode, scene);
}
Example #23
0
int ModelImpAI::ReadFile(const std::string& file_path)
{
	Assimp::Importer importer;
	const aiScene* scene = importer.ReadFile( file_path, 
		aiProcess_CalcTangentSpace       | 
		aiProcess_Triangulate            |
		aiProcess_JoinIdenticalVertices
		);

	assert(scene->mNumMeshes == 1);			//only deals with one mesh per file(scene) for now
	aiMesh* mesh = scene->mMeshes[0];
	assert(mesh->HasNormals());						//assert for normals
	assert(mesh->HasTextureCoords(0));				//assert for texture coordinates
	for(int i=0; i<mesh->mNumFaces; i++)
	{
		const aiFace* face = &mesh->mFaces[i];
		assert(face->mNumIndices == 3);
		Triangle* t = new Triangle;
		for(int j=0; j<face->mNumIndices; j++)
		{
			int index = face->mIndices[j];
			
			t->vertices[j][0] =  mesh->mVertices[index].x;
			t->vertices[j][1] =  mesh->mVertices[index].y;
			t->vertices[j][2] =  mesh->mVertices[index].z;

			t->normals[j][0] =  mesh->mNormals[index].x;
			t->normals[j][1] =  mesh->mNormals[index].y;
			t->normals[j][2] =  mesh->mNormals[index].z;

			t->uvs[j][0] = mesh->mTextureCoords[0][index].x;
			t->uvs[j][1] = mesh->mTextureCoords[0][index].y;
		}

		triangles_.push_back(t);
	}

	return 1;
}
Example #24
0
TEST_F(utObjImportExport, homogeneous_coordinates_Test) {
    static const std::string ObjModel =
        "v -0.500000 0.000000 0.400000 0.50000\n"
        "v -0.500000 0.000000 -0.800000 1.00000\n"
        "v 0.500000 1.000000 -0.800000 0.5000\n"
        "f 1 2 3\nB";

    Assimp::Importer myimporter;
    const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure);
    EXPECT_NE(nullptr, scene);

    EXPECT_EQ(scene->mNumMeshes, 1U);
    const aiMesh *mesh = scene->mMeshes[0];
    EXPECT_EQ(mesh->mNumVertices, 3U);
    EXPECT_EQ(mesh->mNumFaces, 1U);
    const aiFace face = mesh->mFaces[0];
    EXPECT_EQ(face.mNumIndices, 3U);
    const aiVector3D vertice = mesh->mVertices[0];
    EXPECT_EQ(vertice.x, -1.0f);
    EXPECT_EQ(vertice.y, 0.0f);
    EXPECT_EQ(vertice.z, 0.8f);
}
Example #25
0
Apsis::Model::Thing::Thing(const char* path) {
  Assimp::Importer Importer;

  const aiScene* pScene = Importer.ReadFile(path, aiProcess_Triangulate |
                                                  aiProcess_GenSmoothNormals |
                                                  aiProcess_FlipUVs);

  if (pScene == NULL) {
    throw "Cannot load 3d object. No suitable importer.";
  }

  unsigned int numberOfMeshes    = pScene->mNumMeshes;
  unsigned int numberOfMaterials = pScene->mNumMaterials;

  for (unsigned int i = 0; i < numberOfMeshes; i++) {
    _addMesh(pScene->mMeshes[i]);
  }

  for (unsigned int i = 0; i < numberOfMaterials; i++) {
    _addMaterial(pScene->mMaterials[i]);
  }
}
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);
		}
	}
Example #27
0
File: vmodel.cpp Project: vukbyk/rg
void vModel::loadModel(const char* modelFile)
{
    Assimp::Importer importer;
    //aiProcessPreset_TargetRealtime_Fast has the configs you'll need
    const aiScene *scene = importer.ReadFile(modelFile, aiProcessPreset_TargetRealtime_Fast);
    //assuming you only want the first mesh
    aiMesh *mesh = scene->mMeshes[0];

    numVerts = mesh->mNumFaces*3;

    vertexArray = new float[mesh->mNumFaces*3*3];
    normalArray = new float[mesh->mNumFaces*3*3];
    uvArray = new float[mesh->mNumFaces*3*2];

    for(unsigned int i=0;i<mesh->mNumFaces;i++)
    {
    const aiFace& face = mesh->mFaces[i];

        for(int j=0;j<3;j++)
        {
            aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
            memcpy(uvArray,&uv,sizeof(float)*2);
            uvArray+=2;

            aiVector3D normal = mesh->mNormals[face.mIndices[j]];
            memcpy(normalArray,&normal,sizeof(float)*3);
            normalArray+=3;

            aiVector3D pos = mesh->mVertices[face.mIndices[j]];
            memcpy(vertexArray,&pos,sizeof(float)*3);
            vertexArray+=3;
        }
    }

    uvArray-=mesh->mNumFaces*3*2;
    normalArray-=mesh->mNumFaces*3*3;
    vertexArray-=mesh->mNumFaces*3*3;
}
	bool BasicMesh::LoadMesh(const std::string & filename)
	{
		// Release the previously loaded mesh (if it exists)
		Clear();

		// Create the VAO
		glGenVertexArrays(1, &m_VAO);
		glBindVertexArray(m_VAO);

		// Create the buffers for the vertices attributes
		glGenBuffers(2, m_Buffers);

		bool Ret = false;
		Assimp::Importer Importer;

		const aiScene* pScene = Importer.ReadFile(filename.c_str(), aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_FindDegenerates | aiProcess_CalcTangentSpace);

		if (pScene)
		{
			Ret = InitFromScene(pScene);
		}

		else
		{
			printf("Error parsing '%s': '%s'\n", filename.c_str(), Importer.GetErrorString());
		}

		// Make sure the VAO is not changed from the outside
		glBindVertexArray(0);

		//// can delete the damn buffers alr
		if (m_Buffers[0] != 0)
		{
			glDeleteBuffers(sizeof(m_Buffers) / sizeof(m_Buffers[0]), m_Buffers);
		}

		return false;
	}
Example #29
0
// No VAO Created
bool GLModel::LoadVertexData()
{
    //Clear
    for(size_t i=0; i<this->positions->size(); i++)
    {
        this->positions->at(i).clear();
        this->normals->at(i).clear();
    }
    for(size_t i=0; i<this->faces->size(); i++)
        this->faces->at(i).clear();

    Assimp::Importer Importer;

    const aiScene* scene = Importer.ReadFile(filename,
            aiProcess_Triangulate | 
            aiProcess_GenSmoothNormals | 
            aiProcess_FlipUVs | 
            aiProcess_JoinIdenticalVertices);
    if (scene) 
    {
        this->faces->resize(scene->mNumMeshes);
        this->positions->resize(scene->mNumMeshes);
        for(unsigned int i=0; i<scene->mNumMeshes; i++)
        {
            const aiMesh* mesh = scene->mMeshes[i];
            this->AddVertexData(mesh, i);
        }

        return true;
    }
    else 
    {
        std::cerr << "[E] Could not load " << filename << std::endl;
        std::cerr << Importer.GetErrorString() << std::endl;
    }

    return false;
}
Example #30
0
void GameObj::load_model(string path){

    if(loaded_meshes.count(path) > 0){
		//We have already loaded this model
        meshes = loaded_meshes[path];
		return;
	}

	Assimp::Importer import;
	const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);	

    if(!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) 
    {
        cout << "Error::ASSIMP::" << import.GetErrorString() << endl;
        return;
    }
	mesh_dir = path.substr(0, path.find_last_of('/'));

	process_node(scene->mRootNode, scene);

	//Store the loaded meshes for use in other objects
	loaded_meshes[path] = meshes;
}