Node Importer::applySceneImports(const std::string& scenePath, const std::string& resourceRoot) { std::string path; std::string fullPath = resourceRoot + scenePath; m_sceneQueue.push_back(fullPath); while (true) { { std::unique_lock<std::mutex> lock(sceneMutex); m_condition.wait(lock, [&, this]{ if (m_sceneQueue.empty()) { // Not busy at all? if (progressCounter == 0) { return true; } } else { // More work and not completely busy? if (progressCounter < MAX_SCENE_DOWNLOAD) { return true; } } return false; }); if (m_sceneQueue.empty()) { if (progressCounter == 0) { break; } continue; } path = m_sceneQueue.back(); m_sceneQueue.pop_back(); if (m_scenes.find(path) != m_scenes.end()) { continue; } } // TODO: generic handling of uri if (isUrl(path)) { progressCounter++; startUrlRequest(path, [&, p = path](std::vector<char>&& rawData) { if (!rawData.empty()) { std::unique_lock<std::mutex> lock(sceneMutex); processScene(p, std::string(rawData.data(), rawData.size())); } progressCounter--; m_condition.notify_all(); }); } else { std::unique_lock<std::mutex> lock(sceneMutex); processScene(path, getSceneString(path)); } } auto root = importScenes(fullPath); return root; }
//! //! Constructor of the Model2SceneNode class. //! //! \param name The name to give the new mesh node. //! \param parameterRoot A copy of the parameter tree specific for the type of the node. //! Model2SceneNode::Model2SceneNode ( const QString &name, ParameterGroup *parameterRoot ) : GeometryNode(name, parameterRoot, "SceneNode"), m_sceneNode(0), m_entity(0), m_entityContainer(0), m_oldResourceGroupName(""), m_size(1.0,1.0,1.0) { // create the mandatory vtk table input parameter - multiplicity ONE OR MORE VTKTableParameter * inputVTKTableParameter = new VTKTableParameter(m_inputVTKTableParameterName); inputVTKTableParameter->setMultiplicity(1); inputVTKTableParameter->setPinType(Parameter::PT_Input); inputVTKTableParameter->setSelfEvaluating(true); parameterRoot->addParameter(inputVTKTableParameter); connect(inputVTKTableParameter, SIGNAL(dirtied()), SLOT(processScene())); // set affections and functions addAffection("Geometry File", m_outputGeometryName); setChangeFunction("Geometry File", SLOT(geometryFileChanged())); setCommandFunction("Geometry File", SLOT(geometryFileChanged())); connect(this, SIGNAL(frameChanged(int)), SLOT(updateAll())); // set affections and functions setChangeFunction("Size", SLOT(sizeChanged())); setCommandFunction("Size", SLOT(sizeChanged())); createSceneNode(); INC_INSTANCE_COUNTER }
void DotSceneLoader::parseDotScene(const Ogre::String &SceneName, const Ogre::String &groupName, Ogre::SceneManager *yourSceneMgr, Ogre::SceneNode *pAttachNode, const Ogre::String &sPrependNode) { // set up shared object values m_sGroupName = groupName; mSceneMgr = yourSceneMgr; m_sPrependNode = sPrependNode; staticObjects.clear(); dynamicObjects.clear(); rapidxml::xml_document<> XMLDoc; // character type defaults to char rapidxml::xml_node<>* XMLRoot; Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(SceneName, groupName ); char* scene = strdup(stream->getAsString().c_str()); XMLDoc.parse<0>(scene); // Grab the scene node XMLRoot = XMLDoc.first_node("scene"); // Validate the File if( getAttrib(XMLRoot, "formatVersion", "") == "") { Ogre::LogManager::getSingleton().logMessage( "[DotSceneLoader] Error: Invalid .scene File. Missing <scene>" ); return; } // figure out where to attach any nodes we create mAttachNode = pAttachNode; if(!mAttachNode) mAttachNode = mSceneMgr->getRootSceneNode(); // Process the scene processScene(XMLRoot); }
void DotSceneLoader::compileResource(const char* fileName, std::map<std::string, std::string>& options) { staticObjects.clear(); dynamicObjects.clear(); try { TiXmlDocument xmlDoc; TiXmlElement *xmlRoot; xmlDoc.LoadFile(fileName); if(xmlDoc.Error()) { return; } xmlRoot = xmlDoc.RootElement(); if(std::string(xmlRoot->Value()) != "scene") { return; } scene = new Scene(file::getFilename(fileName), manager); rootNode = scene->getRoot(); processScene(xmlRoot); scene->createSceneTree(); std::string outputName = file::getPath(fileName) + "/" + file::getFilename(fileName) + ".scene"; FileStream fileStream(outputName); ResourceBinStream resourceStream(fileStream); SceneUtils::write(resourceStream, *manager, scene); } catch(...) { } delete scene; }
//------------------------------------------ bool ofxAssimpModelLoader::loadModel(string modelName, bool optimize){ file.open(modelName, ofFile::ReadOnly, true); // Since it may be a binary file we should read it in binary -Ed if(!file.exists()) { ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): model does not exist: \"" << modelName << "\""; return false; } ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): loading \"" << file.getFileName() << "\" from \"" << file.getEnclosingDirectory() << "\""; if(scene.get() != nullptr){ clear(); // we reset the shared_ptr explicitly here, to force the old // aiScene to be deleted **before** a new aiScene is created. scene.reset(); } // sets various properties & flags to a default preference unsigned int flags = initImportProperties(optimize); // loads scene from file scene = shared_ptr<const aiScene>(aiImportFileExWithProperties(file.getAbsolutePath().c_str(), flags, NULL, store.get()), aiReleaseImport); bool bOk = processScene(); return bOk; }
bool Parser::leerFichero(const std::string &strName, Globals *pGlobals) { m_pGlobals = pGlobals; // Inicializamos el puntero para rellenar los datos. m_fileEscena.open(strName.c_str()); // Abrimos el fichero. if(!m_fileEscena.is_open()) { m_nError = 7; return false; } if(!m_fileEscena.good()) { if(m_fileEscena.bad()) m_nError = 4; else if(m_fileEscena.fail()) m_nError = 5; else m_nError = 6; return false; } do { if(!ignorarChars()) { if(!m_bEOF) // No hemos llegado al fin de archivo. Error. return false; } else { std::string strEtiqueta; if(readToken(strEtiqueta)) { // Procesar las etiquetas encontradas. if(strEtiqueta == "config") { if(!processConfig()) return false; } else if(strEtiqueta == "scene") { if(!processScene()) return false; } else { m_nError = 0; // Etiqueta desconocida. return false; } } else { m_nError = 0; // Etiqueta desconocida. return false; } } } while(!m_bEOF); m_nError = 10; // Si llegamos hasta aquí, es que el fichero se ha leido return true; // bien y al completo. }
//--------------------------------------------------------------------- void SceneResource::load(const Util::Wstring & resourcePath) { Util::String strPath = Util::WstringToString(resourcePath); mXmlReader = boost::make_shared<Util::XmlReader>(strPath); const Util::XmlNode * rootNode = mXmlReader->getRootNode(); IF_NULL_EXCEPTION(rootNode, strPath + " donnot have root node!"); const Util::XmlNode * sceneNode = mXmlReader->getFirstNode(rootNode, "scene"); IF_NULL_EXCEPTION(sceneNode, strPath + " donnot have scene node!"); processScene(sceneNode); }
bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){ ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): loading from memory buffer \"." << extension << "\""; if(scene != NULL){ clear(); } // sets various properties & flags to a default preference unsigned int flags = initImportProperties(optimize); // loads scene from memory buffer - note this will not work for multipart files (obj, md3, etc) scene = shared_ptr<const aiScene>(aiImportFileFromMemoryWithProperties(buffer.getBinaryBuffer(), buffer.size(), flags, extension, store.get()), aiReleaseImport); bool bOk = processScene(); return bOk; }
VirtualRobot::ScenePtr SceneIO::createSceneFromString( const std::string &xmlString, const std::string &basePath /*= ""*/ ) { // copy string content to char array char* y = new char[xmlString.size() + 1]; strncpy(y, xmlString.c_str(), xmlString.size() + 1); VirtualRobot::ScenePtr scene; try { rapidxml::xml_document<char> doc; // character type defaults to char doc.parse<0>(y); // 0 means default parse flags rapidxml::xml_node<char>* sceneXMLNode = doc.first_node("Scene"); scene = processScene(sceneXMLNode, basePath); } catch (rapidxml::parse_error& e) { delete[] y; THROW_VR_EXCEPTION("Could not parse data in xml definition" << endl << "Error message:" << e.what() << endl << "Position: " << endl << e.where<char>() << endl); return ScenePtr(); } catch (VirtualRobot::VirtualRobotException&) { // rethrow the current exception delete[] y; throw; } catch (std::exception& e) { delete[] y; THROW_VR_EXCEPTION("Error while parsing xml definition" << endl << "Error code:" << e.what() << endl); return ScenePtr(); } catch (...) { delete[] y; THROW_VR_EXCEPTION("Error while parsing xml definition" << endl); return ScenePtr(); } delete[] y; return scene; }
bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){ ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): loading from memory buffer \"." << extension << "\""; if(scene.get() != nullptr){ clear(); // we reset the shared_ptr explicitly here, to force the old // aiScene to be deleted **before** a new aiScene is created. scene.reset(); } // sets various properties & flags to a default preference unsigned int flags = initImportProperties(optimize); // loads scene from memory buffer - note this will not work for multipart files (obj, md3, etc) scene = shared_ptr<const aiScene>(aiImportFileFromMemoryWithProperties(buffer.getData(), buffer.size(), flags, extension, store.get()), aiReleaseImport); bool bOk = processScene(); return bOk; }
//! //! Change function for the Geometry File parameter. //! void Model2SceneNode::geometryFileChanged () { // load new mesh and skeleton if (loadMesh()) processScene(); }
DotSceneLoader::DotSceneLoader() : #ifdef USE_OGRE_TERRAIN mSceneMgr(0), mTerrainGroup(0) { mTerrainGlobalOptions = OGRE_NEW Ogre::TerrainGlobalOptions(); #else mSceneMgr(0) { #endif } DotSceneLoader::~DotSceneLoader() { #ifdef USE_OGRE_TERRAIN if (mTerrainGroup) { OGRE_DELETE mTerrainGroup; } OGRE_DELETE mTerrainGlobalOptions; #endif } /* void ParseStringVector( const Ogre::String &str, const Ogre::StringVector &list ) { list.clear(); Ogre::StringUtil::trim(str, true, true); if (str == "") return; int pos = str.find(";"); while (pos != -1) { list.push_back(str.substr(0, pos)); str.erase(0, pos + 1); pos = str.find(";"); } if (str != "") list.push_back(str); } */ void DotSceneLoader::parseDotScene(const Ogre::String &SceneName, const Ogre::String &groupName, Ogre::SceneManager *yourSceneMgr, Ogre::SceneNode *pAttachNode, const Ogre::String &sPrependNode) { // set up shared object values m_sGroupName = groupName; mSceneMgr = yourSceneMgr; m_sPrependNode = sPrependNode; staticObjects.clear(); dynamicObjects.clear(); // character type defaults to char rapidxml::xml_document<> XMLDoc; rapidxml::xml_node<>* XMLRoot; Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(SceneName, groupName); char* scene = strdup(stream->getAsString().c_str()); XMLDoc.parse<0> (scene); // Grab the scene node XMLRoot = XMLDoc.first_node("scene"); // figure out where to attach any nodes we create mAttachNode = pAttachNode; if (!mAttachNode) mAttachNode = mSceneMgr->getRootSceneNode(); // Process the scene processScene(XMLRoot); delete scene; }