本文整理汇总了C++中Importer::GetErrorString方法的典型用法代码示例。如果您正苦于以下问题:C++ Importer::GetErrorString方法的具体用法?C++ Importer::GetErrorString怎么用?C++ Importer::GetErrorString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Importer
的用法示例。
在下文中一共展示了Importer::GetErrorString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
//.........这里部分代码省略.........
示例2: 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());
}
//.........这里部分代码省略.........
示例3: 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;
}