本文整理汇总了C++中assimp::Importer::ApplyPostProcessing方法的典型用法代码示例。如果您正苦于以下问题:C++ Importer::ApplyPostProcessing方法的具体用法?C++ Importer::ApplyPostProcessing怎么用?C++ Importer::ApplyPostProcessing使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assimp::Importer
的用法示例。
在下文中一共展示了Importer::ApplyPostProcessing方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFile
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;
}
示例2: loadScene
ScenePtr ModelLoader::loadScene(const std::string & path) {
//Création de la scène
ScenePtr scene(new Scene);
SceneObjectPtr &rootObject = scene->getRootObject();
//Chargement du modèle dans assimp
Assimp::Importer importer;
const aiScene *aiScene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_CalcTangentSpace);
if (!aiScene) {
throw std::runtime_error(importer.GetErrorString());
}
importer.ApplyPostProcessing(aiProcess_GenNormals);
if (!aiScene || aiScene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !aiScene->mRootNode) {
cout << "ERROR::ASSIMP::" << importer.GetErrorString() << endl;
return ScenePtr(nullptr);
}
m_directory = path.substr(0, path.find_last_of('/'));
processNode(aiScene, scene, aiScene->mRootNode, rootObject, glm::mat4());
importer.FreeScene();
return std::move(scene);
}
示例3: loadMesh
MeshPtr Helper::loadMesh(std::string path){
MeshPtr res = nullptr;
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(path.c_str(),aiProcess_Triangulate|aiProcess_GenSmoothNormals|aiProcess_GenUVCoords|aiProcess_CalcTangentSpace);
scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
if(!scene){
cout<<"ERROR LOADING MESH: "<<path<<endl;
return nullptr;
}
for(int i=0;i<scene->mNumMeshes;i++){
GeometryPtr meshGEO = GeometryPtr(new Geometry());
MaterialPtr meshMAT = MaterialPtr(new Material());
const aiMesh* mesh = scene->mMeshes[i];
const aiVector3D Zero3D(0.0f,0.0f,0.0f);
const aiColor4D EmptyColor(0.0f,0.0f,0.0f,0.0f);
for(unsigned int i=0;i<mesh->mNumVertices;i++){
const aiVector3D* pPos = &(mesh->mVertices[i]);
const aiVector3D* pNormal = mesh->HasNormals()? &(mesh->mNormals[i]):&Zero3D;
const aiColor4D* pColor =mesh->HasVertexColors(0)? (mesh->mColors[i]):&EmptyColor;
const aiVector3D* pTexCoord = mesh->HasTextureCoords(0)? &(mesh->mTextureCoords[0][i]):&Zero3D;
const aiVector3D* pTangent = mesh->HasTangentsAndBitangents()? &(mesh->mTangents[i]):&Zero3D;
cout<<pTangent->x<<" | "<<pTangent->y<<" | "<<pTangent->z<<endl;
glm::vec3 pos = glm::vec3(pPos->x,pPos->y,pPos->z);
glm::vec3 norm = glm::vec3(pNormal->x,pNormal->y,pNormal->z);
glm::vec3 col = glm::vec3(pColor->r,pColor->g,pColor->b);
glm::vec2 tex = glm::vec2(pTexCoord->x,pTexCoord->y);
glm::vec3 tan = glm::vec3(pTangent->x,pTangent->y,pTangent->z);
meshGEO->pushVertex(Vertex(pos,col,tex,norm,tan));
}
for(unsigned int i=0;i<mesh->mNumFaces;i++){
const aiFace& face = mesh->mFaces[i];
meshGEO->pushFace(face.mIndices[0],face.mIndices[1],face.mIndices[2]);
}
string Dir = Helper::getDirectory(path);
aiString texPath;
if(AI_SUCCESS == scene->mMaterials[mesh->mMaterialIndex]->GetTexture(aiTextureType_DIFFUSE,0,&texPath)){
meshMAT->diffuse = TexturePtr(new Texture(Dir+texPath.data,0));
}
if(AI_SUCCESS == scene->mMaterials[mesh->mMaterialIndex]->GetTexture(aiTextureType_HEIGHT,0,&texPath)){
meshMAT->normal = TexturePtr(new Texture(Dir+texPath.data,0));
}
if(res == nullptr){
res = MeshPtr(new Mesh(meshGEO,meshMAT));
}else{
res->addSubMesh(MeshPtr(new Mesh(meshGEO,meshMAT)));
}
}
return res;
}
示例4: loadFromFile
bool StaticMesh::loadFromFile(const std::string& infile)
{
Assimp::Importer imp;
// Load scene and grab first mesh only
imp.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE,
aiPrimitiveType_LINE |
aiPrimitiveType_POINT |
aiPrimitiveType_POLYGON, nullptr);
#ifdef DEBUG
std::cout << "Calling Assimp::Importer::ReadFile...\n";
#endif // DEBUG
const aiScene *scene = imp.ReadFile(infile, aiProcessPreset_TargetRealtime_Quality
& (!aiProcess_SplitLargeMeshes));
#ifdef DEBUG
std::cout << "Checking for a mesh...\n";
#endif // DEBUG
if(scene == nullptr)
return false;
else if(!scene->HasMeshes())
return false;
imp.ApplyPostProcessing(aiProcess_JoinIdenticalVertices);
// Will only load one mesh
const aiMesh *mesh = scene->mMeshes[0];
#ifdef DEBUG
std::cout << "Checking mesh has what we need...\n";
#endif // DEBUG
// Don't process special mesh types
if(!mesh->HasPositions() ||
!mesh->HasFaces())
return false;
vertexCount = mesh->mNumVertices;
triangleCount = mesh->mNumFaces;
// Check what attributes are in the mesh and
// calculate total count of floats
std::size_t componentCount = components.vertex = 3;
if(mesh->HasNormals())
{
componentCount += components.normal = 3;
#ifdef DEBUG
std::cout << "Has normals\n";
#endif // DEBUG
}
if(mesh->HasTangentsAndBitangents())
{
componentCount += (components.tangentBitangent = 3) * 2;
#ifdef DEBUG
std::cout << "Has tangents and bitangents\n";
#endif // DEBUG
}
if(mesh->HasTextureCoords(0))
{
componentCount += components.texture = 3;
#ifdef DEBUG
std::cout << "Has texture coordinates\n";
#endif // DEBUG
}
// Scale size for size of float
std::size_t totalSize = componentCount * sizeof(float) * vertexCount;
#ifdef DEBUG
std::cout << totalSize << std::endl;
std::cout << "Allocating and mapping vertex buffer...\n";
#endif // DEBUG
// Set size and map buffer
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, totalSize, nullptr, GL_STATIC_DRAW);
GLfloat *mapPtr = (GLfloat*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
// glNamedBufferDataEXT(buffer, totalSize, nullptr, GL_STATIC_DRAW);
// GLfloat *mapPtr = (GLfloat*) glMapNamedBufferEXT(buffer, GL_WRITE_ONLY);
if(mapPtr == nullptr)
return false;
#ifdef DEBUG
std::cout << "Worked!\n";
#endif // DEBUG
// Load all attributes into mapped buffer
for(unsigned int i = 0; i < vertexCount; ++i)
{
GLfloat *head = mapPtr + i * componentCount;
*head++ = mesh->mVertices[i].x;
*head++ = mesh->mVertices[i].y;
*head++ = mesh->mVertices[i].z;
if(mesh->HasNormals())
{
*head++ = mesh->mNormals[i].x;
*head++ = mesh->mNormals[i].y;
*head++ = mesh->mNormals[i].z;
//.........这里部分代码省略.........