本文整理汇总了C++中assimp::Importer::SetIOHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ Importer::SetIOHandler方法的具体用法?C++ Importer::SetIOHandler怎么用?C++ Importer::SetIOHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assimp::Importer
的用法示例。
在下文中一共展示了Importer::SetIOHandler方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scale
SkeletalAnimationModelLoader::SkeletalAnimationModelLoader(const std::string file, glm::quat rotation, float scal)
: transformation() {
//if(rotation){
aiVector3D scale(scal);
aiVector3D position(0.0);
const aiQuaternion rotat(rotation.w, rotation.x, rotation.y, rotation.z);
transformation = aiMatrix4x4Compose(scale, rotat, position);
//}
///////////////////////////////////*/
m_fileName = file;
Assimp::Importer importer;
importer.SetIOHandler(new CustomIOSystem());
const aiScene *scene = importer.ReadFile(file,
aiProcess_Triangulate |
aiProcess_GenSmoothNormals |
aiProcess_FlipUVs |
aiProcess_CalcTangentSpace); //*/
if (!scene) {
log_err("Failed to load mesh: %s", file.c_str());
} else {
MeshLoader::loadScene(scene);
read_Meshes_Channels_Bones(scene);
}
}
示例2: LoadScene
int LoadScene(tchar const *filename, aiScene const **scene)
{
if(scene == null || filename == null)
{
return E_POINTER;
}
Assimp::Importer *importer = new Assimp::Importer();
importer->SetIOHandler(new MyIOSystem());
importer->SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT);
#if defined(_DEBUG)
DefaultLogger::create("", Logger::VERBOSE, aiDefaultLogStream_DEBUGGER);
#endif
importer->ReadFile(filename, aiProcess_Triangulate | aiProcess_SortByPType);
#if defined(_DEBUG)
DefaultLogger::kill();
#endif
if(importer->GetScene() == null)
{
TRACE("Error loading %s: %s\n", filename, importer->GetErrorString());
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
}
*scene = importer->GetScene();
return S_OK;
}
示例3: ResourceIOSystem
RenderableMesh::RenderableMesh (std::string meshname)
{
Assimp::Importer importer;
importer.SetIOHandler(new ResourceIOSystem());
const aiScene* scene = importer.ReadFile(meshname, aiProcess_SortByPType|aiProcess_GenNormals|aiProcess_Triangulate|aiProcess_GenUVCoords|aiProcess_FlipUVs);
if (!scene)
{
ROS_ERROR("Could not load resource [%s]: %s", meshname.c_str(), importer.GetErrorString());
return;
}
fromAssimpScene(scene);
}
示例4: createMeshFromBinaryDAE
shapes::Mesh* createMeshFromBinaryDAE(const char* filename)
{
std::string resource_path(filename);
Assimp::Importer importer;
importer.SetIOHandler(new ResourceIOSystem());
const aiScene* scene = importer.ReadFile(resource_path, aiProcess_SortByPType|aiProcess_GenNormals|aiProcess_Triangulate|aiProcess_GenUVCoords|aiProcess_FlipUVs);
if (!scene)
{
ROS_ERROR("Could not load resource [%s]: %s", resource_path.c_str(), importer.GetErrorString());
return NULL;
}
return meshFromAssimpScene(resource_path, scene);
}
示例5: aiImportFileEx
// ------------------------------------------------------------------------------------------------
const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags,
aiFileIO* pFS)
{
ai_assert(NULL != pFile);
const aiScene* scene = NULL;
ASSIMP_BEGIN_EXCEPTION_REGION();
// create an Importer for this file
Assimp::Importer* imp = new Assimp::Importer();
#ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex);
#endif
// copy the global property lists to the Importer instance
imp->pimpl->mIntProperties = gIntProperties;
imp->pimpl->mFloatProperties = gFloatProperties;
imp->pimpl->mStringProperties = gStringProperties;
#ifdef AI_C_THREADSAFE
lock.unlock();
#endif
// setup a custom IO system if necessary
if (pFS) {
imp->SetIOHandler( new CIOSystemWrapper (pFS) );
}
// and have it read the file
scene = imp->ReadFile( pFile, pFlags);
// if succeeded, place it in the collection of active processes
if ( scene) {
#ifdef AI_C_THREADSAFE
lock.lock();
#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
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
return scene;
}
示例6: aiImportFileExWithProperties
// ------------------------------------------------------------------------------------------------
const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFlags,
aiFileIO* pFS,
const aiPropertyStore* props)
{
ai_assert(NULL != pFile);
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;
pimpl->mMatrixProperties = pp->matrices;
}
// setup a custom IO system if necessary
if (pFS) {
imp->SetIOHandler( new CIOSystemWrapper (pFS) );
}
// and have it read the file
scene = imp->ReadFile( pFile, pFlags);
// 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;
}
示例7: CustomIOSystem
MeshLoader::MeshLoader(const std::string file) {
m_fileName = file;
if (MeshLoader::sceneMeshRendererDataCache[m_fileName].size() > 0) {
m_entity = std::make_shared<Entity>();
for (auto meshRenderData : MeshLoader::sceneMeshRendererDataCache[m_fileName]) {
m_entity->addComponent<MeshRenderer>(meshRenderData.mesh, meshRenderData.material);
}
} else {
Assimp::Importer importer;
importer.SetIOHandler(new CustomIOSystem());
const aiScene *scene = importer.ReadFile(file,
aiProcess_Triangulate |
aiProcess_GenSmoothNormals |
aiProcess_FlipUVs |
aiProcess_CalcTangentSpace); //*/
if (!scene) {
log_err("Failed to load mesh: %s", file.c_str());
} else
loadScene(scene);
}
}
示例8: Load
S3DModel* CAssParser::Load(const std::string& modelFilePath)
{
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Loading model: %s", modelFilePath.c_str());
const std::string& modelPath = FileSystem::GetDirectory(modelFilePath);
const std::string& modelName = FileSystem::GetBasename(modelFilePath);
// Load the lua metafile. This contains properties unique to Spring models and must return a table
std::string metaFileName = modelFilePath + ".lua";
if (!CFileHandler::FileExists(metaFileName, SPRING_VFS_ZIP)) {
// Try again without the model file extension
metaFileName = modelPath + '/' + modelName + ".lua";
}
if (!CFileHandler::FileExists(metaFileName, SPRING_VFS_ZIP)) {
LOG_SL(LOG_SECTION_MODEL, L_INFO, "No meta-file '%s'. Using defaults.", metaFileName.c_str());
}
LuaParser metaFileParser(metaFileName, SPRING_VFS_MOD_BASE, SPRING_VFS_ZIP);
if (!metaFileParser.Execute()) {
LOG_SL(LOG_SECTION_MODEL, L_ERROR, "'%s': %s. Using defaults.", metaFileName.c_str(), metaFileParser.GetErrorLog().c_str());
}
// Get the (root-level) model table
const LuaTable& modelTable = metaFileParser.GetRoot();
if (!modelTable.IsValid()) {
LOG_SL(LOG_SECTION_MODEL, L_INFO, "No valid model metadata in '%s' or no meta-file", metaFileName.c_str());
}
// Create a model importer instance
Assimp::Importer importer;
// Create a logger for debugging model loading issues
Assimp::DefaultLogger::create("", Assimp::Logger::VERBOSE);
Assimp::DefaultLogger::get()->attachStream(new AssLogStream(), ASS_LOGGING_OPTIONS);
// Give the importer an IO class that handles Spring's VFS
importer.SetIOHandler(new AssVFSSystem());
// Speed-up processing by skipping things we don't need
importer.SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, ASS_IMPORTER_OPTIONS);
#ifndef BITMAP_NO_OPENGL
{
// Optimize VBO-Mesh sizes/ranges
GLint maxIndices = 1024;
GLint maxVertices = 1024;
// FIXME returns non-optimal data, at best compute it ourselves (pre-TL cache size!)
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices);
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices);
importer.SetPropertyInteger(AI_CONFIG_PP_SLM_VERTEX_LIMIT, maxVertices);
importer.SetPropertyInteger(AI_CONFIG_PP_SLM_TRIANGLE_LIMIT, maxIndices / 3);
}
#endif
// Read the model file to build a scene object
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Importing model file: %s", modelFilePath.c_str());
const aiScene* scene;
{
// ASSIMP spams many SIGFPEs atm in normal & tangent generation
ScopedDisableFpuExceptions fe;
scene = importer.ReadFile(modelFilePath, ASS_POSTPROCESS_OPTIONS);
}
if (scene != NULL) {
LOG_SL(LOG_SECTION_MODEL, L_INFO,
"Processing scene for model: %s (%d meshes / %d materials / %d textures)",
modelFilePath.c_str(), scene->mNumMeshes, scene->mNumMaterials,
scene->mNumTextures);
} else {
throw content_error("[AssimpParser] Model Import: " + std::string(importer.GetErrorString()));
}
S3DModel* model = new S3DModel();
model->name = modelFilePath;
model->type = MODELTYPE_ASS;
// Load textures
FindTextures(model, scene, modelTable, modelPath, modelName);
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Loading textures. Tex1: '%s' Tex2: '%s'", model->tex1.c_str(), model->tex2.c_str());
texturehandlerS3O->LoadS3OTexture(model);
// Load all pieces in the model
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Loading pieces from root node '%s'", scene->mRootNode->mName.data);
LoadPiece(model, scene->mRootNode, scene, modelTable);
// Update piece hierarchy based on metadata
BuildPieceHierarchy(model);
CalculateModelProperties(model, modelTable);
// Verbose logging of model properties
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->name: %s", model->name.c_str());
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->numobjects: %d", model->numPieces);
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->radius: %f", model->radius);
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->height: %f", model->height);
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->drawRadius: %f", model->drawRadius);
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->mins: (%f,%f,%f)", model->mins[0], model->mins[1], model->mins[2]);
//.........这里部分代码省略.........
示例9: Load
S3DModel* CAssParser::Load(const std::string& modelFilePath)
{
LOG_S(LOG_SECTION_MODEL, "Loading model: %s", modelFilePath.c_str() );
const std::string modelPath = FileSystem::GetDirectory(modelFilePath);
const std::string modelName = FileSystem::GetBasename(modelFilePath);
//! LOAD METADATA
//! Load the lua metafile. This contains properties unique to Spring models and must return a table
std::string metaFileName = modelFilePath + ".lua";
if (!CFileHandler::FileExists(metaFileName, SPRING_VFS_ZIP)) {
//! Try again without the model file extension
metaFileName = modelPath + '/' + modelName + ".lua";
}
LuaParser metaFileParser(metaFileName, SPRING_VFS_MOD_BASE, SPRING_VFS_ZIP);
if (!CFileHandler::FileExists(metaFileName, SPRING_VFS_ZIP)) {
LOG_S(LOG_SECTION_MODEL, "No meta-file '%s'. Using defaults.", metaFileName.c_str());
} else if (!metaFileParser.Execute()) {
LOG_SL(LOG_SECTION_MODEL, L_ERROR, "'%s': %s. Using defaults.", metaFileName.c_str(), metaFileParser.GetErrorLog().c_str());
}
//! Get the (root-level) model table
const LuaTable& metaTable = metaFileParser.GetRoot();
if (metaTable.IsValid()) {
LOG_S(LOG_SECTION_MODEL, "Found valid model metadata in '%s'", metaFileName.c_str());
}
//! LOAD MODEL DATA
//! Create a model importer instance
Assimp::Importer importer;
//! Create a logger for debugging model loading issues
Assimp::DefaultLogger::create("",Assimp::Logger::VERBOSE);
const unsigned int severity = Assimp::Logger::Debugging|Assimp::Logger::Info|Assimp::Logger::Err|Assimp::Logger::Warn;
Assimp::DefaultLogger::get()->attachStream( new AssLogStream(), severity );
//! Give the importer an IO class that handles Spring's VFS
importer.SetIOHandler( new AssVFSSystem() );
//! Speed-up processing by skipping things we don't need
importer.SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, aiComponent_CAMERAS|aiComponent_LIGHTS|aiComponent_TEXTURES|aiComponent_ANIMATIONS);
#ifndef BITMAP_NO_OPENGL
//! Optimize VBO-Mesh sizes/ranges
GLint maxIndices = 1024;
GLint maxVertices = 1024;
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices);
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices); //FIXME returns not optimal data, at best compute it ourself! (pre-TL cache size!)
importer.SetPropertyInteger(AI_CONFIG_PP_SLM_VERTEX_LIMIT, maxVertices);
importer.SetPropertyInteger(AI_CONFIG_PP_SLM_TRIANGLE_LIMIT, maxIndices/3);
#endif
//! Read the model file to build a scene object
LOG_S(LOG_SECTION_MODEL, "Importing model file: %s", modelFilePath.c_str() );
const aiScene* scene = importer.ReadFile( modelFilePath, ASS_POSTPROCESS_OPTIONS );
if (scene != NULL) {
LOG_S(LOG_SECTION_MODEL,
"Processing scene for model: %s (%d meshes / %d materials / %d textures)",
modelFilePath.c_str(), scene->mNumMeshes, scene->mNumMaterials,
scene->mNumTextures );
} else {
LOG_SL(LOG_SECTION_MODEL, L_ERROR, "Model Import: %s",
importer.GetErrorString());
}
SAssModel* model = new SAssModel;
model->name = modelFilePath;
model->type = MODELTYPE_ASS;
model->scene = scene;
//model->meta = &metaTable;
//! Gather per mesh info
CalculatePerMeshMinMax(model);
//! Assign textures
//! The S3O texture handler uses two textures.
//! The first contains diffuse color (RGB) and teamcolor (A)
//! The second contains glow (R), reflectivity (G) and 1-bit Alpha (A).
if (metaTable.KeyExists("tex1")) {
model->tex1 = metaTable.GetString("tex1", "default.png");
} else {
//! Search for a texture
std::vector<std::string> files = CFileHandler::FindFiles("unittextures/", modelName + ".*");
for(std::vector<std::string>::iterator fi = files.begin(); fi != files.end(); ++fi) {
model->tex1 = FileSystem::GetFilename(*fi);
break; //! there can be only one!
}
}
if (metaTable.KeyExists("tex2")) {
model->tex2 = metaTable.GetString("tex2", "");
} else {
//! Search for a texture
std::vector<std::string> files = CFileHandler::FindFiles("unittextures/", modelName + "2.*");
for(std::vector<std::string>::iterator fi = files.begin(); fi != files.end(); ++fi) {
model->tex2 = FileSystem::GetFilename(*fi);
break; //! there can be only one!
}
}
model->flipTexY = metaTable.GetBool("fliptextures", true); //! Flip texture upside down
model->invertTexAlpha = metaTable.GetBool("invertteamcolor", true); //! Reverse teamcolor levels
//.........这里部分代码省略.........
示例10: Load
S3DModel* CAssParser::Load(const std::string& modelFilePath)
{
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Loading model: %s", modelFilePath.c_str());
const std::string& modelPath = FileSystem::GetDirectory(modelFilePath);
const std::string& modelName = FileSystem::GetBasename(modelFilePath);
// Load the lua metafile. This contains properties unique to Spring models and must return a table
std::string metaFileName = modelFilePath + ".lua";
if (!CFileHandler::FileExists(metaFileName, SPRING_VFS_ZIP)) {
// Try again without the model file extension
metaFileName = modelPath + '/' + modelName + ".lua";
}
if (!CFileHandler::FileExists(metaFileName, SPRING_VFS_ZIP)) {
LOG_SL(LOG_SECTION_MODEL, L_INFO, "No meta-file '%s'. Using defaults.", metaFileName.c_str());
}
LuaParser metaFileParser(metaFileName, SPRING_VFS_MOD_BASE, SPRING_VFS_ZIP);
if (!metaFileParser.Execute()) {
LOG_SL(LOG_SECTION_MODEL, L_INFO, "'%s': %s. Using defaults.", metaFileName.c_str(), metaFileParser.GetErrorLog().c_str());
}
// Get the (root-level) model table
const LuaTable& modelTable = metaFileParser.GetRoot();
if (!modelTable.IsValid()) {
LOG_SL(LOG_SECTION_MODEL, L_INFO, "No valid model metadata in '%s' or no meta-file", metaFileName.c_str());
}
// Create a model importer instance
Assimp::Importer importer;
// Give the importer an IO class that handles Spring's VFS
importer.SetIOHandler(new AssVFSSystem());
// Speed-up processing by skipping things we don't need
importer.SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, ASS_IMPORTER_OPTIONS);
#ifndef BITMAP_NO_OPENGL
{
importer.SetPropertyInteger(AI_CONFIG_PP_SLM_VERTEX_LIMIT, maxVertices);
importer.SetPropertyInteger(AI_CONFIG_PP_SLM_TRIANGLE_LIMIT, maxIndices / 3);
}
#endif
// Read the model file to build a scene object
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Importing model file: %s", modelFilePath.c_str());
const aiScene* scene = nullptr;
{
// ASSIMP spams many SIGFPEs atm in normal & tangent generation
ScopedDisableFpuExceptions fe;
scene = importer.ReadFile(modelFilePath, ASS_POSTPROCESS_OPTIONS);
}
if (scene != nullptr) {
LOG_SL(LOG_SECTION_MODEL, L_INFO,
"Processing scene for model: %s (%d meshes / %d materials / %d textures)",
modelFilePath.c_str(), scene->mNumMeshes, scene->mNumMaterials,
scene->mNumTextures);
} else {
throw content_error("[AssimpParser] Model Import: " + std::string(importer.GetErrorString()));
}
ModelPieceMap pieceMap;
ParentNameMap parentMap;
S3DModel* model = new S3DModel();
model->name = modelFilePath;
model->type = MODELTYPE_ASS;
// Load textures
FindTextures(model, scene, modelTable, modelPath, modelName);
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Loading textures. Tex1: '%s' Tex2: '%s'", model->texs[0].c_str(), model->texs[1].c_str());
texturehandlerS3O->PreloadTexture(model, modelTable.GetBool("fliptextures", true), modelTable.GetBool("invertteamcolor", true));
// Load all pieces in the model
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Loading pieces from root node '%s'", scene->mRootNode->mName.data);
LoadPiece(model, scene->mRootNode, scene, modelTable, pieceMap, parentMap);
// Update piece hierarchy based on metadata
BuildPieceHierarchy(model, pieceMap, parentMap);
CalculateModelProperties(model, modelTable);
// Verbose logging of model properties
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->name: %s", model->name.c_str());
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->numobjects: %d", model->numPieces);
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->radius: %f", model->radius);
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->height: %f", model->height);
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->mins: (%f,%f,%f)", model->mins[0], model->mins[1], model->mins[2]);
LOG_SL(LOG_SECTION_MODEL, L_DEBUG, "model->maxs: (%f,%f,%f)", model->maxs[0], model->maxs[1], model->maxs[2]);
LOG_SL(LOG_SECTION_MODEL, L_INFO, "Model %s Imported.", model->name.c_str());
return model;
}