bool ofxAssimpModelLoader::processScene() { normalizeFactor = ofGetWidth() / 2.0; if(scene){ loadGLResources(); update(); calculateDimensions(); 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; } return false; }
//------------------------------------------- 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; } }
//------------------------------------------ void ofxAssimpModelLoader::loadModel(string modelName){ // if we have a model loaded, unload the f****r. if(scene != NULL) { aiReleaseImport(scene); scene = NULL; deleteGLResources(); } // Load our new path. string filepath = ofToDataPath(modelName); ofLog(OF_LOG_VERBOSE, "loading model %s", filepath.c_str()); // 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. scene = (aiScene*) aiImportFile(filepath.c_str(), aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_OptimizeGraph | aiProcess_Triangulate | aiProcess_FlipUVs | 0 ); if(scene){ ofLog(OF_LOG_VERBOSE, "initted scene with %i meshes & %i animations", scene->mNumMeshes, scene->mNumAnimations); getBoundingBoxWithMinVector(&scene_min, &scene_max); scene_center.x = (scene_min.x + scene_max.x) / 2.0f; scene_center.y = (scene_min.y + scene_max.y) / 2.0f; scene_center.z = (scene_min.z + scene_max.z) / 2.0f; // optional normalized scaling normalizedScale = scene_max.x-scene_min.x; normalizedScale = aisgl_max(scene_max.y - scene_min.y,normalizedScale); normalizedScale = aisgl_max(scene_max.z - scene_min.z,normalizedScale); normalizedScale = 1.f / normalizedScale; normalizedScale *= ofGetWidth() / 2.0; glPushAttrib(GL_ALL_ATTRIB_BITS); glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); loadGLResources(); glPopClientAttrib(); glPopAttrib(); if(getAnimationCount()) ofLog(OF_LOG_VERBOSE, "scene has animations"); else { ofLog(OF_LOG_VERBOSE, "no animations"); } } }
//------------------------------------------ bool ofxAssimpModelLoader::loadModel(string modelName, unsigned extraFlags /* = 0 */){ // if we have a model loaded, unload the f****r. if(scene != NULL){ clear(); } // Load our new path. filepath = modelName; string filepath = ofToDataPath(modelName); //theo added - so we can have models and their textures in sub folders modelFolder = ofFilePath::getEnclosingDirectory(filepath); ofLog(OF_LOG_VERBOSE, "loading model %s", filepath.c_str()); ofLog(OF_LOG_VERBOSE, "loading from folder %s", modelFolder.c_str()); // 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; flags |= extraFlags; /* if(optimize) flags |= aiProcess_ImproveCacheLocality | aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes | aiProcess_JoinIdenticalVertices | aiProcess_RemoveRedundantMaterials; */ scene = aiImportFile(filepath.c_str(), flags); if(scene){ calculateDimensions(); loadGLResources(); if(getAnimationCount()) ofLog(OF_LOG_VERBOSE, "scene has animations"); else { ofLog(OF_LOG_VERBOSE, "no animations"); } collectNodeTransforms(scene, scene->mRootNode); collectBoneTransforms(); return true; }else{ ofLog(OF_LOG_ERROR,string("ofxAssimpModelLoader: ") + aiGetErrorString()); return false; } }
//------------------------------------------- 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; } }