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


C++ MeshPtr::addVBO方法代码示例

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


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

示例1: processMesh

void ModelLoader::processMesh(const aiScene *aiscene, ScenePtr &scene, aiMesh * mesh, MeshPtr &glMesh, const glm::mat4 &model) {
	//Properties
	glMesh->shaderConf.shadingType = "lighting";
	glMesh->shaderConf.lightingFct = "phong";
	glMesh->name = mesh->mName.C_Str();
	glMesh->vertexCount = mesh->mNumVertices;
	glMesh->model = model;

	//Vertex geometry
	VBOFactory vboFactory;
	vboFactory.setVertexCount(mesh->mNumVertices);

	//Position
	vboFactory.setData(VertexPosition, &mesh->mVertices[0][0]);

	//Normals
	if (mesh->HasNormals()) {
		vboFactory.setData(VertexNormal, &mesh->mNormals[0][0]);
	}

	if (mesh->HasTangentsAndBitangents()) {
		vboFactory.setData(VertexTangent, &mesh->mTangents[0][0]);
		vboFactory.setData(VertexBitangent, &mesh->mBitangents[0][0]);
	}

	//Texture coords
	std::vector<GLfloat> texCoords;
	if (mesh->HasTextureCoords(0)) {
		//Une petite correction s'impose Vec3 -> Vec2
		texCoords.reserve(2 * mesh->mNumVertices);
		for (int i = 0; i < mesh->mNumVertices; i++) {
			texCoords.push_back(mesh->mTextureCoords[0][i].x);
			texCoords.push_back(mesh->mTextureCoords[0][i].y);
		}
		vboFactory.setData(VertexTexCoord, &texCoords[0]);
	}

	IBOFactory iboFactory;
	//Indices
	std::vector<GLuint> indices;
	indices.reserve(mesh->mNumFaces * 3);
	for (GLuint i = 0; i < mesh->mNumFaces; i++) {
		aiFace face = mesh->mFaces[i];
		for (int j = 0; j < face.mNumIndices; j++)
			indices.push_back(face.mIndices[j]);
	}
	iboFactory.setData(&indices[0], indices.size());

	//Set mesh VBO and IBO
	glMesh->addVBO(vboFactory.getBlockVBO());
	glMesh->addIBO(iboFactory.getIBO(), indices.size());

	//Compute AABB
	computeAABB(mesh, glMesh->bBox);

	//Material
	if (mesh->mMaterialIndex >= 0) {
		aiMaterial *material = aiscene->mMaterials[mesh->mMaterialIndex];

		//Constants
		aiString name;
		material->Get(AI_MATKEY_NAME, name);
		glMesh->material.name = name.C_Str();

		aiColor3D color(0.f, 0.f, 0.f);
		material->Get(AI_MATKEY_COLOR_AMBIENT, color);
		glMesh->material.addProperty(Ka, aiToGLM(color));

		material->Get(AI_MATKEY_COLOR_DIFFUSE, color);
		glMesh->material.addProperty(Kd, aiToGLM(color));

		material->Get(AI_MATKEY_COLOR_SPECULAR, color);
		glMesh->material.addProperty(Ks, aiToGLM(color));

		float shininess = 0;
		material->Get(AI_MATKEY_SHININESS, shininess);
		glMesh->material.addProperty(Shininess, shininess);

		//Textures
		loadTextures(scene, material, glMesh, aiTextureType_AMBIENT, TextureType::Ambient);
		loadTextures(scene, material, glMesh, aiTextureType_DIFFUSE, TextureType::Diffuse);
		loadTextures(scene, material, glMesh, aiTextureType_SPECULAR, TextureType::Specular);
		loadTextures(scene, material, glMesh, aiTextureType_NORMALS, TextureType::Normal);
		//La Height Map peut être la Normal map
		if (!(glMesh->material.textureTypes & TextureType::Normal)) {
			loadTextures(scene, material, glMesh, aiTextureType_HEIGHT, TextureType::Normal);
		}

		//Si pas de diffuse map mais une ambient map, ambient map = diffuse map
		if ((glMesh->material.textureTypes & Diffuse) && !(glMesh->material.textureTypes & Ambient)) {
			loadTextures(scene, material, glMesh, aiTextureType_DIFFUSE, TextureType::Ambient);
		}
	}
}
开发者ID:valche5,项目名称:ValEngine,代码行数:94,代码来源:ModelLoader.cpp


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