void ContinuousModel::processModelCalculation(Vector* Statek1, Vector* Statek, Vector* Inputs, double integrationInterval) { int numIntegrationSteps=1; if(integrationInterval>maxTimeIntegration) { numIntegrationSteps=floor(integrationInterval/maxTimeIntegration); timeIntegration=integrationInterval/numIntegrationSteps; } else { numIntegrationSteps=1; timeIntegration=integrationInterval; } // printf("numsteps=%d, intInt=%f, maxTime=%f\n",numIntegrationSteps,integrationInterval,maxTimeIntegration); for(int i=1;i<=numIntegrationSteps;i++) { //Model::processModel(Statek1,Statek,Inputs); processModel(Statek1,Statek,Inputs); if(i<=numIntegrationSteps) { Statek->copy(Statek1); //printf("step %d",i); //Statek1->mostrar(); } } return; }
void ModelLoader::processNode(aiNode *node, const aiScene *scene) { // process all the node's meshes (if any) for (unsigned int i = 0; i < node->mNumMeshes; i++) { aiMesh *mesh = scene->mMeshes[node->mMeshes[i]]; currentScene.models.push_back(processModel(mesh, scene)); } // then do the same for each of its children for (unsigned int i = 0; i < node->mNumChildren; i++) { processNode(node->mChildren[i], scene); } }
/** * Extracts JSON model from a string input * @param input JSON string * @param model model to fill in */ static void parseModelData(const std::string& input, MatModel& model) { JSONNode nd = libjson::parse(input); bool modelset = false; for (auto i = nd.begin(); i != nd.end(); i++) { if (i->name() == JsonNames::modelname) { processModel(*i, model); modelset = true; break; } } if (!modelset) BNB_ERROR_REPORT("Model data missing\n"); }
/* \brief import Assimp file */ int _glhckImportAssimp(glhckObject *object, const char *file, const glhckImportModelParameters *params, glhckGeometryIndexType itype, glhckGeometryVertexType vtype) { const struct aiScene *scene; glhckObject *first = NULL; unsigned int aflags; CALL(0, "%p, %s, %p", object, file, params); /* import the model using assimp * TODO: make import hints tunable? * Needs changes to import protocol! */ aflags = aiProcessPreset_TargetRealtime_Fast | aiProcess_OptimizeGraph; if (!params->animated && params->flatten) aflags |= aiProcess_PreTransformVertices; scene = aiImportFile(file, aflags); if (!scene) goto assimp_fail; /* mark ourself as special root object. * this makes most functions called on root object echo to children */ object->flags |= GLHCK_OBJECT_ROOT; /* this is going to be the first object in mesh, * the object returned by this importer is just invisible root object. */ if (!(first = glhckObjectNew())) goto fail; glhckObjectAddChild(object, first); glhckObjectFree(first); /* process the model */ if (processModel(file, object, first, scene, scene->mRootNode, itype, vtype, params) != RETURN_OK) goto fail; /* process the animated model part */ if (params->animated && processBonesAndAnimations(object, scene) != RETURN_OK) goto fail; /* close file */ NULLDO(aiReleaseImport, scene); RET(0, "%d", RETURN_OK); return RETURN_OK; assimp_fail: DEBUG(GLHCK_DBG_ERROR, aiGetErrorString()); fail: IFDO(aiReleaseImport, scene); IFDO(glhckObjectFree, first); RET(0, "%d", RETURN_FAIL); return RETURN_FAIL; }
void action(iscore::ActionManager& mgr, iscore::MaybeDocument doc) override { if(!doc) { setEnabled(mgr, false); return; } auto focus = doc->focus.get(); if(!focus) { setEnabled(mgr, false); return; } auto lm = dynamic_cast<const Process::LayerModel*>(focus); if(!lm) { setEnabled(mgr, false); return; } auto proc = dynamic_cast<const Scenario::ScenarioInterface*>(&lm->processModel()); if(!proc) { setEnabled(mgr, false); return; } const auto& sel = doc->selectionStack.currentSelection(); auto res = any_of(sel, [] (auto obj) { auto ptr = obj.data(); return bool(dynamic_cast<const Scenario::ConstraintModel*>(ptr)) || bool(dynamic_cast<const Scenario::EventModel*>(ptr)) || bool(dynamic_cast<const Scenario::StateModel*>(ptr)); }); setEnabled(mgr, res); }
bool ModelData::loadModel(const std::string &filePath, const bool createVoxelRep) { std::string path = Framework::Utils::FindFileOrThrow(filePath, false); std::cout << "Loading Model: (" << path << ") \n"; // Create an instance of the Importer class // 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. //aiPropertyStore* props = aiCreatePropertyStore(); //aiSetImportPropertyFloat(props, AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.f); /* const aiScene* scene = importer.ReadFile(path, aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType | aiProcess_GenSmoothNormals); //*/ try { //const aiScene* scene = importer.ReadFile(path, aiProcessPreset_TargetRealtime_Quality); const aiScene* scene = importer.ReadFile(path, aiProcessPreset_TargetRealtime_Fast); // If the import failed, report it if (!scene) { //LOG HERE return false; } // Now we can access the file's contents. if (!processModel()){ std::cerr << "Unable to load model: (" << path << ") \n"; return false; } if (createVoxelRep) modelVoxels = new Voxel_Rep(importer, this->descType()); else modelVoxels = new Voxel_Rep(this->descType()); } catch (std::runtime_error& re) { std::cerr << "Runtime Error: (" << re.what() << ") " << "\n"; return false; } catch (std::out_of_range& oor) { std::cerr << "Iterator, Out-of-Range Error: (" << oor.what() << ")\nCouldn't load model." << "\n"; return false; } catch (std::exception& e2) { std::cerr << e2.what() << "\n"; return false; } std::cout << "Finished Loading Model: (" << path << ") \n"; return true; }
const ProcessModel& LayerModel::model() const { return static_cast<const ProcessModel&>(processModel()); }
static int processModel(const char *file, glhckObject *object, glhckObject *current, const struct aiScene *sc, const struct aiNode *nd, glhckGeometryIndexType itype, glhckGeometryVertexType vtype, const glhckImportModelParameters *params) { unsigned int m, f; unsigned int numVertices = 0, numIndices = 0; unsigned int ioffset, voffset; glhckImportIndexData *indices = NULL; glhckImportVertexData *vertexData = NULL; glhckMaterial *material = NULL; glhckTexture **textureList = NULL, *texture = NULL; glhckAtlas *atlas = NULL; const struct aiMesh *mesh; const struct aiFace *face; int canFreeCurrent = 0; int hasTexture = 0; assert(file); assert(object && current); assert(sc && nd); /* combine && atlas loading path */ if (params->flatten) { /* prepare atlas for texture combining */ if (!(atlas = glhckAtlasNew())) goto assimp_no_memory; /* texturelist for offseting coordinates */ if (!(textureList = _glhckCalloc(nd->mNumMeshes, sizeof(_glhckTexture*)))) goto assimp_no_memory; /* gather statistics */ for (m = 0; m != nd->mNumMeshes; ++m) { mesh = sc->mMeshes[nd->mMeshes[m]]; if (!mesh->mVertices) continue; for (f = 0; f != mesh->mNumFaces; ++f) { face = &mesh->mFaces[f]; if (!face) goto fail; numIndices += face->mNumIndices; } numVertices += mesh->mNumVertices; if ((texture = textureFromMaterial(file, sc->mMaterials[mesh->mMaterialIndex]))) { glhckAtlasInsertTexture(atlas, texture); glhckTextureFree(texture); textureList[m] = texture; hasTexture = 1; } } /* allocate vertices */ if (!(vertexData = _glhckCalloc(numVertices, sizeof(glhckImportVertexData)))) goto assimp_no_memory; /* allocate indices */ if (!(indices = _glhckMalloc(numIndices * sizeof(glhckImportIndexData)))) goto assimp_no_memory; /* pack combined textures */ if (hasTexture) { if (glhckAtlasPack(atlas, GLHCK_RGBA, 1, 0, glhckTextureDefaultParameters()) != RETURN_OK) goto fail; } else { NULLDO(glhckAtlasFree, atlas); NULLDO(_glhckFree, textureList); } /* join vertex data */ for (m = 0, ioffset = 0, voffset = 0; m != nd->mNumMeshes; ++m) { mesh = sc->mMeshes[nd->mMeshes[m]]; if (!mesh->mVertices) continue; if (textureList) texture = textureList[m]; else texture = NULL; joinMesh(mesh, voffset, indices+ioffset, vertexData+voffset, atlas, texture); for (f = 0; f != mesh->mNumFaces; ++f) { face = &mesh->mFaces[f]; if (!face) goto fail; ioffset += face->mNumIndices; } voffset += mesh->mNumVertices; } /* create material */ if (hasTexture && !(material = glhckMaterialNew(texture))) goto assimp_no_memory; /* finally build the model */ if (buildModel(current, numIndices, numVertices, indices, vertexData, itype, vtype) == RETURN_OK) { _glhckObjectFile(current, nd->mName.data); if (material) glhckObjectMaterial(current, material); if (!(current = glhckObjectNew())) goto fail; glhckObjectAddChild(object, current); glhckObjectFree(current); canFreeCurrent = 1; } /* free stuff */ IFDO(glhckAtlasFree, atlas); IFDO(glhckMaterialFree, material); IFDO(_glhckFree, textureList); NULLDO(_glhckFree, vertexData); NULLDO(_glhckFree, indices); } else { /* default loading path */ for (m = 0, ioffset = 0, voffset = 0; m != nd->mNumMeshes; ++m) { mesh = sc->mMeshes[nd->mMeshes[m]]; if (!mesh->mVertices) continue; /* gather statistics */ numIndices = 0; for (f = 0; f != mesh->mNumFaces; ++f) { face = &mesh->mFaces[f]; if (!face) goto fail; numIndices += face->mNumIndices; } numVertices = mesh->mNumVertices; // FIXME: create materialFromAssimpMaterial // that returns glhckMaterial with correct stuff /* get texture */ hasTexture = 0; if ((texture = textureFromMaterial(file, sc->mMaterials[mesh->mMaterialIndex]))) hasTexture = 1; /* create material */ if (hasTexture && !(material = glhckMaterialNew(texture))) goto assimp_no_memory; /* allocate vertices */ if (!(vertexData = _glhckCalloc(numVertices, sizeof(glhckImportVertexData)))) goto assimp_no_memory; /* allocate indices */ if (!(indices = _glhckMalloc(numIndices * sizeof(glhckImportIndexData)))) goto assimp_no_memory; /* fill arrays */ joinMesh(mesh, 0, indices, vertexData, NULL, NULL); /* build model */ if (buildModel(current, numIndices, numVertices, indices, vertexData, itype, vtype) == RETURN_OK) { /* FIXME: UGLY */ char pointer[16]; snprintf(pointer, sizeof(pointer), "%p", mesh); _glhckObjectFile(current, pointer); if (material) glhckObjectMaterial(current, material); if (!(current = glhckObjectNew())) goto fail; glhckObjectAddChild(object, current); glhckObjectFree(current); canFreeCurrent = 1; } /* free stuff */ NULLDO(_glhckFree, vertexData); NULLDO(_glhckFree, indices); IFDO(glhckTextureFree, texture); IFDO(glhckMaterialFree, material); } } /* process childrens */ for (m = 0; m != nd->mNumChildren; ++m) { if (processModel(file, object, current, sc, nd->mChildren[m], itype, vtype, params) == RETURN_OK) { if (!(current = glhckObjectNew())) goto fail; glhckObjectAddChild(object, current); glhckObjectFree(current); canFreeCurrent = 1; } } /* we din't do anything to the next * allocated object, so free it */ if (canFreeCurrent) glhckObjectRemoveFromParent(current); return RETURN_OK; assimp_no_memory: DEBUG(GLHCK_DBG_ERROR, "Assimp not enough memory."); fail: IFDO(_glhckFree, vertexData); IFDO(_glhckFree, indices); IFDO(_glhckFree, textureList); IFDO(glhckTextureFree, texture); IFDO(glhckMaterialFree, material); IFDO(glhckAtlasFree, atlas); if (canFreeCurrent) glhckObjectRemoveFromParent(current); return RETURN_FAIL; }