本文整理汇总了C++中assimp::Importer类的典型用法代码示例。如果您正苦于以下问题:C++ Importer类的具体用法?C++ Importer怎么用?C++ Importer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Importer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFromFileImport
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
}
示例2: loadModel
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);
}
示例3:
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 );
}
}
示例4:
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);
}
示例5: aiImportFileFromMemoryWithProperties
// ------------------------------------------------------------------------------------------------
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;
}
示例6: LoadMesh
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;
}
示例7: 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;
}
示例8: aiImportFileEx
// ------------------------------------------------------------------------------------------------
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;
}
示例9: GetVertices
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));
}
示例10:
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));
}
示例11: Load
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());
}
}
示例12: aiIsExtensionSupported
// ------------------------------------------------------------------------------------------------
// 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;
}
示例13: runtime_error
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];
}
示例14: fprintf
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);
}
示例15: loadModel
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);
}