当前位置: 首页>>代码示例>>C++>>正文


C++ Importer::ReadFile方法代码示例

本文整理汇总了C++中Importer::ReadFile方法的典型用法代码示例。如果您正苦于以下问题:C++ Importer::ReadFile方法的具体用法?C++ Importer::ReadFile怎么用?C++ Importer::ReadFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Importer的用法示例。


在下文中一共展示了Importer::ReadFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: exporterTest

    virtual bool exporterTest() {
        Importer importer;
        Exporter exporter;
        const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0);
        EXPECT_NE(nullptr, scene);
        EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "ply", ASSIMP_TEST_MODELS_DIR "/PLY/cube_test.ply"));

        return true;
    }
开发者ID:dellis1972,项目名称:assimp,代码行数:9,代码来源:utPLYImportExport.cpp

示例2: importAsset

bool AssimpWrapper::importAsset( const IO::Uri &file, ui32 flags ) {
    if ( !file.isValid() ) {
        osre_error( Tag, "URI " + file.getUri() + " is invalid " );
        return false;
    }

    unsigned int importFlags = aiProcess_CalcTangentSpace
        | aiProcess_GenSmoothNormals
        | aiProcess_JoinIdenticalVertices
        | aiProcess_ImproveCacheLocality
        | aiProcess_LimitBoneWeights
        | aiProcess_RemoveRedundantMaterials
        | aiProcess_SplitLargeMeshes
        | aiProcess_Triangulate
        | aiProcess_GenUVCoords
        | aiProcess_SortByPType;
    flags = importFlags;

    m_root = AssetRegistry::getPath( "media" );
    m_absPathWithFile = AssetRegistry::resolvePathFromUri( file );

    String filename;
    Directory::getDirectoryAndFile(m_absPathWithFile, m_root, filename);
    filename = m_root + filename;
    Importer myImporter;
    const aiScene *scene = myImporter.ReadFile( filename, flags );
    if ( nullptr == scene ) {
        m_root = "";
        m_absPathWithFile = "";
        return false;
    }
    convertSceneToModel( scene );
    m_model->setMeshArray( m_meshArray );

    return true;
}
开发者ID:kimkulling,项目名称:osre,代码行数:36,代码来源:AssimpWrapper.cpp

示例3: main

int main(int argc, char* argv[])
{
	using namespace std;
	using namespace Assimp;
	using namespace DirectX;


#pragma region Exporter
	Importer importer;
	unsigned int flags = 
		aiProcess_GenSmoothNormals |
		aiProcess_Triangulate |
		aiProcess_JoinIdenticalVertices |
		aiProcess_SortByPType |
		aiProcess_FlipWindingOrder;
	const aiScene* scene = importer.ReadFile(argv[1], flags);
	string modelFileName;
	for (size_t i = 0; argv[1][i] != '.'; i++)
	{
		modelFileName.push_back(argv[1][i]);
	}
	modelFileName.append(".mesh");
	ofstream bout(modelFileName.c_str(), ios_base::binary);
	if (bout.is_open() && scene)
	{
		if (scene->HasMeshes())
		{
			//Flag Header
			char headerString[] = { 'F','U', 'L', 'L', 'S', 'A', 'I', 'L' };
			bout.write(headerString, sizeof headerString / sizeof(char));

			//File Name
			uint8_t modelNameLength = static_cast<uint8_t>(modelFileName.size());
			bout.write(reinterpret_cast<char*>(&modelNameLength), sizeof modelNameLength);
			bout.write(modelFileName.c_str(), modelNameLength);

			//Number of Meshes
			uint8_t numOfMeshes = static_cast<uint8_t>(scene->mNumMeshes);
			bout.write(reinterpret_cast<char*>(&numOfMeshes), sizeof numOfMeshes);
			for (size_t meshIndex = 0; meshIndex < numOfMeshes; meshIndex++)
			{
				auto currentMesh = scene->mMeshes[meshIndex];

				//Pos
				uint32_t numOfVertices = currentMesh->mNumVertices;
				bout.write(reinterpret_cast<char*>(&numOfVertices), sizeof numOfVertices);
				bout.write(reinterpret_cast<char*>(currentMesh->mVertices), numOfVertices * sizeof(aiVector3D));

				//Normal
				bout.write(reinterpret_cast<char*>(currentMesh->mNormals), numOfVertices * sizeof(aiVector3D));

				//UV
				bout.write(reinterpret_cast<char*>(currentMesh->mTextureCoords[0]), numOfVertices * sizeof(aiVector3D));

				//Indices
				uint32_t numOfIndices = currentMesh->mNumFaces * 3;
				bout.write(reinterpret_cast<char*>(&numOfIndices), sizeof numOfIndices);
				for (size_t eachFace = 0; eachFace < currentMesh->mNumFaces; eachFace++)
				{
					for (size_t i = 0; i < 3; i++)
					{
						bout.write(reinterpret_cast<char*>(&currentMesh->mFaces[eachFace].mIndices[i]), sizeof(unsigned int));
					}
					
				}
				
			}
		}
	}
#pragma endregion

#pragma region Importer
	ifstream bin(modelFileName, ios_base::binary);
	ofstream text("log.txt");
	if (bin.is_open())
	{
		char header[8];
		bin.read(header, 8);
		if (strcmp(header,"FULLSAIL"))
		{
			uint8_t modelNameLength = 0;
			bin.read(reinterpret_cast<char*>(&modelNameLength), sizeof modelNameLength);
			text << "Model Name Length: " << (int)modelNameLength << "\n";

			string modelName;
			modelName.resize(modelNameLength);
			bin.read(&modelName[0],  modelNameLength * sizeof (char));
			text << "Model Name: "<< modelName << endl;

			uint8_t numOfMeshes = 0;
			bin.read(reinterpret_cast<char*>(&numOfMeshes), sizeof numOfMeshes);
			text << "Number of meshes: " << (int)numOfMeshes << "\n";


			for (size_t eachMesh = 0; eachMesh < numOfMeshes; eachMesh++)
			{
				uint32_t numOfVertices = 0;
				bin.read(reinterpret_cast<char*>(&numOfVertices), sizeof numOfVertices);
				text << "Number of Vertices for " << eachMesh << ": " << (int)numOfVertices << "\n";
				vector<XMFLOAT3> pos;
//.........这里部分代码省略.........
开发者ID:locpk,项目名称:ModelLoader,代码行数:101,代码来源:Maincpp.cpp

示例4: fin

Modell::Modell(glm::mat4& matrix, const char * modelpath)
{
	mat = matrix;

	Importer importer;
	const aiScene* scene = NULL;
	
	//gibt es die Datei
	std::ifstream fin(modelpath);
	if(!fin.fail()) {
		fin.close();
	}
	else{
		printf("Fehler beim laden des Modells: %s\n", modelpath);
		printf("%s\n", importer.GetErrorString());
		system("PAUSE");
		exit(EXIT_FAILURE);
	}

	scene = importer.ReadFile( modelpath,/* aiProcess_Triangulate | */aiProcessPreset_TargetRealtime_Quality);

	if( !scene)
	{
		printf("%s\n", importer.GetErrorString());
		system("PAUSE");
		exit(EXIT_FAILURE);
	}else{
		mesh = scene->mMeshes[0];

		int indexcount = mesh->mNumFaces * 3;
		int vertexcount = mesh->mNumVertices *3;
		int normcount = mesh->mNumVertices *3;
		int uvCoordcount = mesh->mNumVertices *2;

		for (unsigned int i = 0; i < mesh->mNumFaces; ++i) 
		{
            const aiFace* face = &mesh->mFaces[i];
			
			unsigned int index = face->mIndices[0];
			indices.push_back(index);

			index = face->mIndices[1];
			indices.push_back(index);

			index = face->mIndices[2];
			indices.push_back(index);
        }


		//index = 0;
		for (unsigned int i = 0; i < mesh->mNumVertices; ++i) 
		{
			glm::vec3 positions;

			positions.x = mesh->mVertices[i].x;
			positions.y = mesh->mVertices[i].y;
			positions.z = mesh->mVertices[i].z;

			pos.push_back(positions);

			glm::vec3 norm;
			norm.x = mesh->mNormals[i].x;
			norm.y = mesh->mNormals[i].y;
			norm.z = mesh->mNormals[i].z;

			normals.push_back(norm);

			glm::vec2 tex;
			//es koennten auch mehrere texturen am objekt sein. Wir supporten vorerst nur eine
			if (mesh->mTextureCoords[0]) 
			{
				tex.x = mesh->mTextureCoords[0][i].x;
				tex.y = mesh->mTextureCoords[0][i].y;

				uvs.push_back(tex);
			}
		}
		if (mesh->mMaterialIndex >= 0) {

		aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
		aiColor3D colorDIF (0.f,0.f,0.f);
		aiColor3D colorSPEC (0.f,0.f,0.f);
		material->Get(AI_MATKEY_COLOR_DIFFUSE,colorDIF);
		material->Get(AI_MATKEY_COLOR_DIFFUSE,colorSPEC);

		diffuseMAT.r = colorDIF.r;
		diffuseMAT.g = colorDIF.g;
		diffuseMAT.b = colorDIF.b;

		specularMAT.r = colorSPEC.r;
		specularMAT.g = colorSPEC.g;
		specularMAT.b = colorSPEC.b;

		Texture textureloader;
		diffuseMaps = textureloader.loadMaterialTextures(modelpath, material, aiTextureType_DIFFUSE, "diffuse");
		//textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end());

		specularMaps = textureloader.loadMaterialTextures(modelpath, material, aiTextureType_SPECULAR, "specular");
		//textures.insert(textures.end(), specularMaps.begin(), specularMaps.end());
	}
//.........这里部分代码省略.........
开发者ID:Honesch,项目名称:ThrowIt,代码行数:101,代码来源:Modell.cpp

示例5: nullVec

void DDEngine::ModelObject::loadGeometry(std::vector<Mesh>& meshes)
{
	Importer importer;
	const aiScene* scene = importer.ReadFile(modelPath,
		aiProcess_Triangulate |
		aiProcess_ConvertToLeftHanded |
		aiProcess_FlipUVs |
		aiProcess_SortByPType |
		aiProcess_OptimizeMeshes |
		aiProcess_OptimizeGraph |
		aiProcess_FixInfacingNormals |
		aiProcess_CalcTangentSpace
		);

	if (!scene) {
		Win32Utils::showMessage("Error during loading object.", importer.GetErrorString());
		return;
	}

	const aiVector3D nullVec(0.0f, 0.0f, 0.0f);

	for (size_t i = 0; i < scene->mNumMeshes; i++) {
		const aiMesh* mesh = scene->mMeshes[i];
		Mesh ddeMesh;

		for (size_t j = 0; j < mesh->mNumVertices; j++) {

			const aiVector3D* pos = &(mesh->mVertices[j]);
			const aiVector3D* nor = mesh->HasNormals() ? &(mesh->mNormals[j]) : &nullVec;
			const aiVector3D* tan = mesh->HasTangentsAndBitangents() ? &(mesh->mTangents[j]) : &nullVec;
			const aiVector3D* tex = mesh->HasTextureCoords(0) ? &(mesh->mTextureCoords[0][j]) : &nullVec;

			#define VB(x, y, z, u, v, nx, ny, nz, tx, ty, tz, tw) ddeMesh.VB(VertexPositionNormalTangentTexture(XMFLOAT3(x, y, z), XMFLOAT3(nx, ny, nz), XMFLOAT4(tx, ty, tz, tw), XMFLOAT2(u, v)))

			VB(
				pos->x, pos->y, pos->z,
				tex->x, tex->y,
				nor->x, nor->y, nor->z,
				tan->x, tan->y, tan->z, 0.0f
			);

			ddeMesh.materialIndex = mesh->mMaterialIndex;

		}

		for (size_t j = 0; j < mesh->mNumFaces; j++) {

			const aiFace& face = mesh->mFaces[j];

			switch (face.mNumIndices) {
				case 1: ddeMesh.topology = PrimitiveTopology::POINT_LIST; break;
				case 2: ddeMesh.topology = PrimitiveTopology::LINE_LIST; break;
				case 3: ddeMesh.topology = PrimitiveTopology::TRIANGLE_LIST; break;
				default: ddeMesh.topology = PrimitiveTopology::UNDEFINED; break;
			}

			for (size_t index = 0; index < face.mNumIndices; index++) {
				ddeMesh.IB(face.mIndices[index]);
			}

		}

		meshes.push_back(ddeMesh);
	}

	for (size_t i = 0; i < scene->mNumMaterials; i++) {
		const aiMaterial* material = scene->mMaterials[i];
		Material ddeMaterial;
		ddeMaterial.index = i;

		if (material->GetTextureCount(aiTextureType_DIFFUSE) > 0) {
			aiString Path;

			if (material->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) {
				Texture tex;
				tex.type = Texture::TextureType::DIFFUSE;

				ShaderResourceView* texture = nullptr;

				std::string path = Path.data;
				std::size_t ext = path.find(".tga");
				ScratchImage image;
				HRESULT hr = -1;

				std::string currentPath = FileUtils::getPath(modelPath) + "/";
				tex.path = currentPath + path;

				if (ext != std::string::npos) {
					hr = LoadFromTGAFile(StringUtils::toWstring(currentPath + path).c_str(), nullptr, image);
				}
				else {
					texture = TextureUtils::createTexture(currentPath + path, *Ctx);
				}

				if (SUCCEEDED(hr)) {
					hr = CreateShaderResourceView(Ctx->device, image.GetImages(), image.GetImageCount(), image.GetMetadata(), &texture);
				}

				if (texture) {
					tex.texture = texture;
//.........这里部分代码省略.........
开发者ID:Toby91,项目名称:DDEngine,代码行数:101,代码来源:ModelObject.cpp

示例6: Import

bool CImporter::Import(const string& filename)
{
	unsigned int flags = aiProcess_JoinIdenticalVertices;
	flags |= aiProcess_FlipUVs;
	flags |= aiProcess_Triangulate;
	flags |= aiProcess_GenSmoothNormals;
	flags |= aiProcess_LimitBoneWeights;
	flags |= aiProcess_ValidateDataStructure;
	flags |= aiProcess_ImproveCacheLocality;
	flags |= aiProcess_RemoveRedundantMaterials;
	flags |= aiProcess_FixInfacingNormals;
	flags |= aiProcess_FindInvalidData;
	flags |= aiProcess_OptimizeMeshes;
	flags |= aiProcess_SplitByBoneCount;
	flags |= aiProcess_TransformUVCoords;
	flags |= aiProcess_SortByPType;
	flags |= aiProcess_RemoveComponent;
	flags |= aiProcess_MakeLeftHanded;
	//flags |= aiProcess_FlipWindingOrder;
	//flags |= aiProcess_OptimizeGraph;

	Importer importer;
	if (!importer.ValidateFlags(flags))
	{
		qCritical("Import flags not supported");
		return false;
	}

	if (!importer.IsExtensionSupported(('.' % GetExtension(filename)).toLocal8Bit().constData()))
	{
		qCritical("This file format isn't supported");
		return false;
	}

	importer.SetPropertyInteger(AI_CONFIG_PP_LBW_MAX_WEIGHTS, 2);
	importer.SetPropertyInteger(AI_CONFIG_PP_SBBC_MAX_BONES, MAX_BONES);
	importer.SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, aiComponent_TANGENTS_AND_BITANGENTS
		| aiComponent_COLORS
		| aiComponent_TEXTURES
		| aiComponent_LIGHTS
		| aiComponent_CAMERAS);

	m_scene = (aiScene*)importer.ReadFile(filename.toLocal8Bit().constData(), flags);
	if (!m_scene)
	{
		qCritical(importer.GetErrorString());
		return false;
	}

	if (!m_scene->HasMeshes() || !m_scene->mRootNode || m_scene->mRootNode->mNumChildren == 0)
	{
		qCritical("No meshes in this scene");
		return false;
	}

	m_obj3D = m_mesh->m_elements[0].obj = new CObject3D(m_mesh->m_device);
	m_obj3D->m_ID = _getNewID();

	const string filenameToLower = QFileInfo(filename).fileName().toLower();

	if (filenameToLower.startsWith("mvr")
		|| filenameToLower.startsWith("part")
		|| filenameToLower.startsWith("item"))
		m_externBones = true;

	_importScene();

	if (!m_obj3D->InitDeviceObjects())
	{
		qCritical(("Can't init object3D device objects '" % filename % "'").toLocal8Bit().data());
		return false;
	}

	importer.FreeScene();
	return true;
}
开发者ID:ServerGame,项目名称:ATools,代码行数:76,代码来源:Importer.cpp

示例7: exception

			shared_ptr<drawBasement::IModel> load(drawBasement::IDrawFactory* df,IFileService* ff,shared_ptr<IFile> fi){
				using namespace Assimp;
				Importer Imp;
				u32 size = fi->getFileSize();
				void* buf = malloc(size);
				fi->read((char*)buf,size);
				const aiScene* pScene = Imp.ReadFile(fi->getAbsolutePath().c_str(),aiProcess_Triangulate | aiProcess_GenSmoothNormals);
				free(buf);

				const aiVector3D Zero3D(0.0f, 0.0f, 0.0f);
				auto model = new drawBasement::CModel;
				model->modelPath = fi->getAbsolutePath();
				//骨骼动画初始化
				if(pScene->HasAnimations()){
					model->mBoneAnimator = shared_ptr<drawBasement::CBoneAnimator>(new drawBasement::CBoneAnimator);
					buildBoneAnimations(pScene->mAnimations[0],pScene->mRootNode,model);
					model->mBoneAnimator->mMaxFrames = pScene->mAnimations[0]->mDuration;
					model->mBoneAnimator->mFramePerSecond = pScene->mAnimations[0]->mTicksPerSecond;
				}
				mat4 zeroMat;
				ZeroMemory(&zeroMat,sizeof(mat4));
				//模型数据初始化
				for(unsigned int i=0;i<pScene->mNumMeshes;++i){
					const aiMesh* paiMesh = pScene->mMeshes[i];
					auto vbuf = df->createVertexBuffer();
					vbuf->setElemtSize(3);
					vbuf->reSizeBuffer(sizeof(vector3df)*paiMesh->mNumVertices);
					vector3df* vb = (vector3df*)vbuf->lock();

					auto nbuf = df->createVertexBuffer();
					nbuf->setElemtSize(3);
					nbuf->reSizeBuffer(sizeof(vector3df)*paiMesh->mNumVertices);
					vector3df* nb = (vector3df*)nbuf->lock();

					auto tbuf = df->createVertexBuffer();
					tbuf->setElemtSize(2);
					tbuf->reSizeBuffer(sizeof(vector2df)*paiMesh->mNumVertices);
					vector2df* tb = (vector2df*)tbuf->lock();
					
					for (unsigned int i = 0 ; i < paiMesh->mNumVertices ; i++) {
						const aiVector3D* pPos      = &(paiMesh->mVertices[i]);
						const aiVector3D* pNormal   = &(paiMesh->mNormals[i]);
						const aiVector3D* pTexCoord = paiMesh->HasTextureCoords(0) ? &(paiMesh->mTextureCoords[0][i]) : &Zero3D;
						vb[i].X=pPos->x;
						vb[i].Y=pPos->y;
						vb[i].Z=pPos->z;

						tb[i].X=pTexCoord->x;
						tb[i].Y=pTexCoord->y;

						nb[i].X=pNormal->x;
						nb[i].Y=pNormal->y;
						nb[i].Z=pNormal->z;
						
					}

					auto ibuf = df->createIndexBuffer();
					ibuf->setIndexNums(paiMesh->mNumFaces*3);
					ibuf->setPrimityType(drawBasement::EPT_TRIANGLES);
					ibuf->reSizeBuffer(paiMesh->mNumFaces*3*ibuf->getIndexType());
					u16* ib = (u16*)ibuf->lock();
					for (unsigned int i = 0 ; i < paiMesh->mNumFaces ; i++) {
						const aiFace& Face = paiMesh->mFaces[i];
						ib[i*3+0]=Face.mIndices[0];
						ib[i*3+1]=Face.mIndices[1];
						ib[i*3+2]=Face.mIndices[2];
					}
					tbuf->initialBuffer();
					nbuf->initialBuffer();
					vbuf->initialBuffer();
					ibuf->initialBuffer();
					u32 bsize = 4*sizeof(u32)*paiMesh->mNumVertices;
					shared_ptr<drawBasement::IDrawBuffer> bbuf = 0;
					shared_ptr<drawBasement::IDrawBuffer> bwbuf = 0;
					if(paiMesh->HasBones()){
						bbuf = df->createVertexBuffer();
						bwbuf = df->createVertexBuffer();
						bbuf->reSizeBuffer(bsize);
						bbuf->setElemtSize(4);
						bbuf->setDataType(drawBasement::EDT_UINT);
						bwbuf->reSizeBuffer(bsize);
						bwbuf->setElemtSize(4);


						u32* bb = (u32*)bbuf->lock();
						f32* bwb = (f32*)bwbuf->lock();
						ZeroMemory(bb,bsize);
						ZeroMemory(bwb,bsize);
						for(u32 i=0;i<paiMesh->mNumBones;++i){
							auto bone = model->mBoneAnimator->findBones(paiMesh->mBones[i]->mName.C_Str());
							if(((drawBasement::CBone*)bone.get())->isinitial){
								((drawBasement::CBone*)bone.get())->isinitial=false;
								memcpy(&((drawBasement::CBone*)bone.get())->boneOffset,&paiMesh->mBones[i]->mOffsetMatrix,sizeof(f32)*16);
								((drawBasement::CBone*)bone.get())->boneOffset=((drawBasement::CBone*)bone.get())->boneOffset.getTransposed();
							}
							u32 bid = bone->getBoneIdx();
							for(u32 bi=0;bi<paiMesh->mBones[i]->mNumWeights;++bi){
								u32 vid = paiMesh->mBones[i]->mWeights[bi].mVertexId;
								f32 vw = paiMesh->mBones[i]->mWeights[bi].mWeight;
								AddBoneData(bb+vid*4,bwb+vid*4,bid,vw);
//.........这里部分代码省略.........
开发者ID:skatebill,项目名称:MyEngineVersion3,代码行数:101,代码来源:CAssimpPhraser.cpp


注:本文中的Importer::ReadFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。