void OgreNetworkReply::abort() { if (!mDataStream.isNull()) { mDataStream->close(); mDataStream.setNull(); } }
//----------------------------------------------------------------------------------------- void CTerrainGroupEditor::importFullTerrainFromHeightMap() { UTFStringVector extlist; extlist.push_back(OTR("PNG Grayscale")); extlist.push_back("*.png"); extlist.push_back(OTR("Raw 32bit Float File")); extlist.push_back("*.raw;*.ohm;*.f32;*.r32"); Ogre::UTFString defaultPath = mSystem->GetSetting("system", "ExportTerrainPath", ""); Ogre::String filename = mSystem->DisplayOpenDialog(OTR("Import Heightmap"), extlist, defaultPath); if(filename == "") return; mSystem->SetSetting("system", "ExportTerrainPath", OgitorsUtils::ExtractFilePath(filename)); Ogre::NameValuePairList params; if(!mSystem->DisplayImportHeightMapDialog(params)) return; Ogre::Real fScale = Ogre::StringConverter::parseReal(params["scale"]); Ogre::Real fBias = Ogre::StringConverter::parseReal(params["bias"]); Ogre::String normal = params["normal"]; Ogre::String diffuse = params["diffuse"]; bool flipV = Ogre::StringConverter::parseBool(params["inverted"]); float *data = 0; float *flipBV = 0; Ogre::String namePart = OgitorsUtils::ExtractFileName(filename); namePart.erase(0, namePart.find(".")); int imgW = 0; int imgH = 0; if(namePart == ".png") { std::fstream fstr(filename.c_str(), std::ios::in|std::ios::binary); Ogre::DataStreamPtr stream = Ogre::DataStreamPtr(OGRE_NEW Ogre::FileStreamDataStream(&fstr, false)); Ogre::Image img; img.load(stream); data = OGRE_ALLOC_T(float, img.getWidth() * img.getHeight(), Ogre::MEMCATEGORY_GEOMETRY); Ogre::PixelBox pb(img.getWidth(), img.getHeight(), 1, Ogre::PF_FLOAT32_R, data); Ogre::PixelUtil::bulkPixelConversion(img.getPixelBox(), pb); imgW = img.getWidth(); imgH = img.getHeight(); img.freeMemory(); stream.setNull(); }
/* Loads an XmlDocument from a filename. * Requires: * @filename The xml filename * Returns: * @doc The xmlDocument or 0 if error */ TiXmlDocument *Util::loadXmlDocument(const char *fname) { ASSERT(fname); TiXmlDocument *XMLDoc = 0; try { // Strip the path Ogre::String basename, path; Ogre::StringUtil::splitFilename(fname, basename, path); // we will hardcode the groupName Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton(). openResource( basename, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); //DataStreamPtr pStream = ResourceGroupManager::getSingleton(). // openResource( SceneName, groupName ); Ogre::String data = pStream->getAsString(); // Open the .scene File XMLDoc = new TiXmlDocument(); XMLDoc->Parse( data.c_str() ); pStream->close(); pStream.setNull(); if( XMLDoc->Error() ) { //We'll just log, and continue on gracefully debug("Couldn't load the %s xml\n", fname); delete XMLDoc; return 0; } } catch(...) { //We'll just log, and continue on gracefully debug("Error creating TiXmlDocument for %s\n", fname); delete XMLDoc; return 0; } // Close the XML File return XMLDoc; }
void Level::parseLevelFile(const Ogre::String &FileName, const Ogre::String &groupName, Ogre::SceneManager *sceneMgr, Ogre::SceneNode *AttachNode, const Ogre::String &prependNode) { mGroupName = groupName; mSceneMgr = sceneMgr; mPrependNode = prependNode; TiXmlDocument *mXMLDoc = 0; TiXmlElement *mXMLRoot = 0; try { Ogre::String basename, path; Ogre::StringUtil::splitFilename(FileName, basename, path); Ogre::DataStreamPtr spStream = Ogre::ResourceGroupManager::getSingleton().openResource(basename,groupName); Ogre::String data = spStream->getAsString(); mXMLDoc = new TiXmlDocument(); mXMLDoc->Parse(data.c_str()); spStream->close(); spStream.setNull(); mXMLRoot = mXMLDoc->RootElement(); mAttachNode = AttachNode; if(!mAttachNode) mAttachNode = mSceneMgr->getRootSceneNode(); parseScene(mXMLRoot); delete mXMLDoc; } catch(Ogre::Exception e) { Ogre::LogManager::getSingleton().logMessage("Level failed to load"); delete mXMLDoc; } }
bool openXMLDocument(const gkString& fileName, TiXmlDocument &XMLDoc, const gkString& resGroupName) { try { //open from file if (!Ogre::ResourceGroupManager::getSingletonPtr()) return openXMLDocumentOnFile(fileName, XMLDoc); //open from resource // Strip the path gkString basename, path; Ogre::StringUtil::splitFilename(fileName, basename, path); Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton(). openResource( basename, resGroupName ); gkString data = pStream->getAsString(); // Open the .scene File XMLDoc.Parse( data.c_str() ); pStream->close(); pStream.setNull(); if (XMLDoc.Error()) { gkPrintf("[XML] Error - The TiXmlDocument reported an error: %s", XMLDoc.ErrorDesc()); return false; } } catch(Ogre::Exception &e) { gkPrintf("[XML] Error - creating TiXmlDocument %s %s", fileName.c_str(), e.getDescription().c_str()); return false; } return true; }
//-------------------------------------------------------------------------- void FLevelFileSerializer::importFLevelFile( Ogre::DataStreamPtr &stream, FLevelFile* pDest ) { size_t start_position( stream->tell() ); readFileHeader( stream ); uint32 section_offsets[ m_header.section_count ]; readInts( stream, section_offsets, m_header.section_count ); Ogre::DataStreamPtr section; for( size_t i(0); i < m_header.section_count; ++i ) { size_t current_offset( stream->tell() - start_position ); size_t section_gap( section_offsets[i] - current_offset ); if( current_offset > section_offsets[i] ) { OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS ,"FLevel sections overlap" ,"FLevelFileSerializer::importFLevelFile" ); } else if( section_gap ) { stream->skip( section_gap ); Ogre::LogManager::getSingleton().stream() << "Warning: skiping gap in front of section " << i << " gap size " << section_gap << " FLevelFileSerializer::importFLevelFile"; } readSectionData( stream, section ); readSection( section, pDest, i ); section->close(); section.setNull(); } readEnd( stream ); }