//------------------------------------------- bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){ normalizeFactor = ofGetWidth() / 2.0; // only ever give us triangles. aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT ); aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_NORMALIZE, true); // aiProcess_FlipUVs is for VAR code. Not needed otherwise. Not sure why. unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_Triangulate | aiProcess_FlipUVs; if(optimize) flags |= aiProcess_ImproveCacheLocality | aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes | aiProcess_JoinIdenticalVertices | aiProcess_RemoveRedundantMaterials; if(scene){ clear(); } scene = aiImportFileFromMemory(buffer.getBinaryBuffer(), buffer.size(), flags, extension); if(scene){ calculateDimensions(); loadGLResources(); if(getAnimationCount()) ofLog(OF_LOG_VERBOSE, "scene has animations"); else { ofLog(OF_LOG_VERBOSE, "no animations"); } return true; }else{ ofLog(OF_LOG_ERROR,string("ofxAssimpModelLoader: ") + aiGetErrorString()); return false; } }
bool Scene::load(const ofBuffer& buffer, bool optimize, Handedness handness, const char* extension) { unload(); unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality; if (optimize) { flags |= aiProcess_ImproveCacheLocality | aiProcess_JoinIdenticalVertices | aiProcess_RemoveRedundantMaterials; } if (handness == LEFT_HANDED) { flags |= aiProcess_ConvertToLeftHanded; } scene = aiImportFileFromMemory(buffer.getBinaryBuffer(), buffer.size(), flags, extension); string err_str = aiGetErrorString(); if (!err_str.empty()) { ofLogError("ofxAssimp::Scene::load") << err_str; } assert(scene); setupResources(); setupNodes(); setupAnimations(); return true; }
//------------------------------------------- bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){ normalizeFactor = ofGetWidth() / 2.0; if(scene != NULL){ clear(); } // only ever give us triangles. aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT ); aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_NORMALIZE, true); // aiProcess_FlipUVs is for VAR code. Not needed otherwise. Not sure why. unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_Triangulate | aiProcess_FlipUVs; if(optimize) flags |= aiProcess_ImproveCacheLocality | aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes | aiProcess_JoinIdenticalVertices | aiProcess_RemoveRedundantMaterials; scene = aiImportFileFromMemory(buffer.getBinaryBuffer(), buffer.size(), flags, extension); if(scene){ calculateDimensions(); loadGLResources(); update(); if(getAnimationCount()) ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): scene has " << getAnimationCount() << "animations"; else { ofLogVerbose("ofxAssimpModelLoader") << "loadMode(): no animations"; } ofAddListener(ofEvents().exit,this,&ofxAssimpModelLoader::onAppExit); return true; }else{ ofLogError("ofxAssimpModelLoader") << "loadModel(): " + (string) aiGetErrorString(); clear(); return false; } }