예제 #1
0
//-----------------------------------------------------------------------------------------
void CPGInstanceManager::onSave(bool forced)
{
    Ogre::String dir = mOgitorsRoot->GetProjectOptions()->ProjectDir + "/PGInstances/";
    dir = OgitorsUtils::QualifyPath(dir);
    mSystem->MakeDirectory(dir);

    Ogre::String name = mName->get();
    std::replace(name.begin(), name.end(), '<', ' ');
    std::replace(name.begin(), name.end(), '>', ' ');
    std::replace(name.begin(), name.end(), '#', ' ');

    if(!mLastFileName.empty())
        mSystem->DeleteFile(mLastFileName);

    if(!mTempFileName.empty())
        mSystem->DeleteFile(mTempFileName);

    Ogre::String filename = OgitorsUtils::QualifyPath(dir + "/" + Ogre::StringConverter::toString(mObjectID->get()) + "_" + name + ".instance");

    mLastFileName = filename;

    _save(filename);

    mTempModified->set(false);
    mTempFileName = "";
}
예제 #2
0
//-----------------------------------------------------------------------------------------
void CPGInstanceManager::onSave(bool forced)
{
    Ogre::String dir = "/PGInstances/";
    OFS::OfsPtr& mFile = mOgitorsRoot->GetProjectFile();
    mFile->createDirectory(dir.c_str());

    Ogre::String name = mName->get();
    std::replace(name.begin(), name.end(), '<', ' ');
    std::replace(name.begin(), name.end(), '>', ' ');
    std::replace(name.begin(), name.end(), '#', ' ');

    if(!mLastFileName.empty())
        mFile->deleteFile(mLastFileName.c_str());

    if(!mTempFileName.empty())
        mFile->deleteFile(mTempFileName.c_str());

    Ogre::String filename = dir + Ogre::StringConverter::toString(mObjectID->get()) + "_" + name + ".instance";

    mLastFileName = filename;

    _save(filename);

    mTempModified->set(false);
    mTempFileName = "";
}
	//-----------------------------------------------------------------------
	void CoherentUIView::loadUrl(const Ogre::String& url)
	{
		if (mView)
		{
			std::wstring urlConverted(url.begin(), url.end());
			mView->Load(urlConverted.c_str());
		}
	}
예제 #4
0
//-----------------------------------------------------------------------------------------
TiXmlElement* CPGInstanceManager::exportDotScene(TiXmlElement *pParent)
{
    Ogre::String name = mName->get();
    std::replace(name.begin(), name.end(), '<', ' ');
    std::replace(name.begin(), name.end(), '>', ' ');
    std::replace(name.begin(), name.end(), '#', ' ');

    name = Ogre::StringConverter::toString(mObjectID->get()) + "_" + name;

    Ogre::String filename = "PGInstances/" + name + ".instance";

    TiXmlElement *pNode = pParent->InsertEndChild(TiXmlElement("node"))->ToElement();

    // node properties
    pNode->SetAttribute("name", mName->get().c_str());
    pNode->SetAttribute("id", Ogre::StringConverter::toString(mObjectID->get()).c_str());
    // position
    TiXmlElement *pPosition = pNode->InsertEndChild(TiXmlElement("position"))->ToElement();
    pPosition->SetAttribute("x", "0");
    pPosition->SetAttribute("y", "0");
    pPosition->SetAttribute("z", "0");
    // rotation
    TiXmlElement *pRotation = pNode->InsertEndChild(TiXmlElement("rotation"))->ToElement();
    pRotation->SetAttribute("qw", "1");
    pRotation->SetAttribute("qx", "0");
    pRotation->SetAttribute("qy", "0");
    pRotation->SetAttribute("qz", "0");
    // scale
    TiXmlElement *pScale = pNode->InsertEndChild(TiXmlElement("scale"))->ToElement();
    pScale->SetAttribute("x", "1");
    pScale->SetAttribute("y", "1");
    pScale->SetAttribute("z", "1");
    
    
    TiXmlElement *pPG = pNode->InsertEndChild(TiXmlElement("pagedgeometry"))->ToElement();
    pPG->SetAttribute("fileName", filename.c_str());
    pPG->SetAttribute("model", mModel->get().c_str());
    pPG->SetAttribute("pageSize", Ogre::StringConverter::toString(mPageSize->get()).c_str());
    pPG->SetAttribute("batchDistance", Ogre::StringConverter::toString(mBatchDistance->get()).c_str());
    pPG->SetAttribute("impostorDistance", Ogre::StringConverter::toString(mImpostorDistance->get()).c_str());
    pPG->SetAttribute("bounds", Ogre::StringConverter::toString(mBounds->get()).c_str());
    pPG->SetAttribute("castShadows", Ogre::StringConverter::toString(mCastShadows->get()).c_str());

    return pPG;
}
//----------------------------------------------------------------------------------------
int CDotSceneSerializer::Export(bool SaveAs, Ogre::String exportfile)
{
    OgitorsRoot *ogRoot = OgitorsRoot::getSingletonPtr();
    OgitorsSystem *mSystem = OgitorsSystem::getSingletonPtr();

    PROJECTOPTIONS *pOpt = ogRoot->GetProjectOptions();
    Ogre::String fileName = pOpt->ProjectName;

    UTFStringVector extlist;
    extlist.push_back(OTR("DotScene File"));
    extlist.push_back("*.scene");
    extlist.push_back(OTR("DotScene File"));
    extlist.push_back("*.xml");
    fileName = mSystem->DisplaySaveDialog(OTR("Export DotScene File"),extlist);
    if(fileName == "")
        return SCF_CANCEL;

    Ogre::String newDir = OgitorsUtils::ExtractFilePath(fileName);

    extractOFS(newDir);
    mSystem->DeleteFile(newDir + "/" + pOpt->ProjectName + ".ogscene");

    TiXmlDocument *pXMLDoc = new TiXmlDocument();
    pXMLDoc->InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", ""));
    pXMLDoc->InsertEndChild(TiXmlElement("scene"));

    // export basic info
    TiXmlElement *pRoot = pXMLDoc->RootElement();
    pRoot->SetAttribute("formatVersion", "1.0.0");
    pRoot->SetAttribute("generator", Ogre::String(Ogre::String("Ogitor SceneBuilder ") + Ogre::String(OGITOR_VERSION)).c_str());

    // export resource locations
    TiXmlElement *pResourceLocations = pRoot->InsertEndChild(TiXmlElement("resourceLocations"))->ToElement();

    for(unsigned int r = 0; r < pOpt->ResourceDirectories.size(); r++)
    {
        TiXmlElement *pResourceLocation = pResourceLocations->InsertEndChild(TiXmlElement("resourceLocation"))->ToElement();
        Ogre::String loc = pOpt->ResourceDirectories[r];

        pResourceLocation->SetAttribute("type", "FileSystem");

        std::replace(loc.begin(),loc.end(),'\\','/');

        if(loc[0] != '.')
            loc = "./" + loc;

        pResourceLocation->SetAttribute("name", loc.c_str());
    }

    //TODO: do we need all those object id's ?

    TiXmlElement *pEnvironment = pRoot->InsertEndChild(TiXmlElement("environment"))->ToElement();

    // export octree scenemanagers
    NameObjectPairList smList = ogRoot->GetObjectsByTypeName("OctreeSceneManager");
    NameObjectPairList::const_iterator smIt = smList.begin();
    while(smIt != smList.end())
    {
        TiXmlElement *result = smIt->second->exportDotScene(pEnvironment);
        saveUserData(smIt->second->getCustomProperties(), result);
        smIt++;
    }

    // export viewports
    NameObjectPairList vpList = ogRoot->GetObjectsByTypeName("Viewport Object");
    NameObjectPairList::const_iterator vpIt = vpList.begin();
    while(vpIt != vpList.end())
    {
        TiXmlElement *result = vpIt->second->exportDotScene(pEnvironment);
        saveUserData(vpIt->second->getCustomProperties(), result);
        vpIt++;
    }

    // export terrains
    NameObjectPairList terrainList = ogRoot->GetObjectsByType(ETYPE_TERRAIN_MANAGER);
    NameObjectPairList::const_iterator tlIt = terrainList.begin();
    while(tlIt != terrainList.end())
    {
        TiXmlElement *result = tlIt->second->exportDotScene(pRoot);
        saveUserData(tlIt->second->getCustomProperties(), result);
        tlIt++;
    }

    NameObjectPairList items = ogRoot->GetSceneManagerEditor()->getChildren();

    // export lights
    NameObjectPairList::const_iterator nodeIt = items.begin();

    while(nodeIt != items.end())
    {
        if(nodeIt->second->getEditorType() == ETYPE_LIGHT)
        {
            TiXmlElement *result = nodeIt->second->exportDotScene(pRoot);
            saveUserData(nodeIt->second->getCustomProperties(), result);
        }
        nodeIt++;
    }

    // export cameras
    nodeIt = items.begin();

    while(nodeIt != items.end())
    {
        if(nodeIt->second->getEditorType() == ETYPE_CAMERA)
        {
            TiXmlElement *result = nodeIt->second->exportDotScene(pRoot);
            saveUserData(nodeIt->second->getCustomProperties(), result);
        }
        nodeIt++;
    }

    // export nodes
    TiXmlElement *pNodes = pRoot->InsertEndChild(TiXmlElement("nodes"))->ToElement();
    nodeIt = items.begin();

    while(nodeIt != items.end())
    {
        if( nodeIt->second->getEditorType() != ETYPE_TERRAIN_MANAGER &&
                nodeIt->second->getEditorType() != ETYPE_LIGHT &&
                nodeIt->second->getEditorType() != ETYPE_CAMERA )
        {
            TiXmlElement *result = nodeIt->second->exportDotScene(pNodes);
            saveUserData(nodeIt->second->getCustomProperties(), result);
        }
        nodeIt++;
    }

    if (pXMLDoc->SaveFile(fileName.c_str()))
    {
        OgitorsSystem::getSingletonPtr()->DisplayMessageDialog(OTR("Scene has been exported succesfully"), DLGTYPE_OK);
        delete pXMLDoc;
    }
    else
        OgitorsSystem::getSingletonPtr()->DisplayMessageDialog(OTR("An error occured during export.. :("), DLGTYPE_OK);

    return SCF_OK;
}
예제 #6
0
//-----------------------------------------------------------------------------------------
void CPGInstanceManager::_onLoad()
{
    Ogre::String filename;

    if(mTempModified->get())
    {
        if(mTempFileName.empty())
            mTempFileName = OgitorsUtils::QualifyPath(mOgitorsRoot->GetProjectOptions()->ProjectDir + "/Temp/tmp" + Ogre::StringConverter::toString(mObjectID->get()) + ".instance");

        filename = mTempFileName;
    }
    else
    {
        Ogre::String name = mName->get();
        std::replace(name.begin(), name.end(), '<', ' ');
        std::replace(name.begin(), name.end(), '>', ' ');
        std::replace(name.begin(), name.end(), '#', ' ');

        name = Ogre::StringConverter::toString(mObjectID->get()) + "_" + name;

        filename = OgitorsUtils::QualifyPath(mOgitorsRoot->GetProjectOptions()->ProjectDir + "/PGInstances/" + name + ".instance");
    }

    std::ifstream stream(filename.c_str());

    if(!stream.is_open())
        return;

    if(!mTempModified->get())
        mLastFileName = filename;

    Ogre::StringVector list;

    char res[128];

    while(!stream.eof())
    {
        stream.getline(res, 128);
        Ogre::String resStr(res);
        OgitorsUtils::ParseStringVector(resStr, list);

        if(list.size() == 3)
        {
            PGInstanceInfo info;
            
            info.pos = Ogre::StringConverter::parseVector3(list[0]);
            info.scale = Ogre::StringConverter::parseReal(list[1]);
            info.yaw = Ogre::StringConverter::parseReal(list[2]);

            mInstanceList[mNextInstanceIndex++] = info;
        }
        else if(list.size() == 4)
        {
            PGInstanceInfo info;
            
            int index = Ogre::StringConverter::parseInt(list[0]);
            info.pos = Ogre::StringConverter::parseVector3(list[1]);
            info.scale = Ogre::StringConverter::parseReal(list[2]);
            info.yaw = Ogre::StringConverter::parseReal(list[3]);
            info.instance = 0;

            mInstanceList[index] = info;

            if(index >= mNextInstanceIndex)
                mNextInstanceIndex = index + 1;
        }
    }

    stream.close();
}
예제 #7
0
//-----------------------------------------------------------------------------------------
void CPGInstanceManager::_onLoad()
{
    Ogre::String filename;

    if(mTempModified->get())
    {
        if(mTempFileName.empty())
            mTempFileName = "/Temp/tmp" + Ogre::StringConverter::toString(mObjectID->get()) + ".instance";

        filename = mTempFileName;
    }
    else
    {
        Ogre::String name = mName->get();
        std::replace(name.begin(), name.end(), '<', ' ');
        std::replace(name.begin(), name.end(), '>', ' ');
        std::replace(name.begin(), name.end(), '#', ' ');

        filename = "/PGInstances/" + Ogre::StringConverter::toString(mObjectID->get()) + "_" + name + ".instance";
    }

    OFS::OFSHANDLE handle;

    OFS::OfsPtr& mFile = mOgitorsRoot->GetProjectFile();

    OFS::OfsResult ret = mFile->openFile(handle, filename.c_str());

    if(ret != OFS::OFS_OK)
        return;

    OFS::ofs64 file_size = 0;

    mFile->getFileSize(handle, file_size);

    if(file_size == 0)
    {
        mFile->closeFile(handle);
        return;
    }

    char *buffer = new char[(unsigned int)file_size];
    mFile->read(handle, buffer, (unsigned int)file_size);

    std::stringstream stream;
    stream << buffer;

    delete [] buffer;

    if(!mTempModified->get())
        mLastFileName = filename;

    Ogre::StringVector list;

    char res[128];

    while(!stream.eof())
    {
        stream.getline(res, 128);
        Ogre::String resStr(res);
        OgitorsUtils::ParseStringVector(resStr, list);

        if(list.size() == 3)
        {
            PGInstanceInfo info;

            info.pos = Ogre::StringConverter::parseVector3(list[0]);
            info.scale = Ogre::StringConverter::parseReal(list[1]);
            info.yaw = Ogre::StringConverter::parseReal(list[2]);

            mInstanceList[mNextInstanceIndex++] = info;
        }
        else if(list.size() == 4)
        {
            PGInstanceInfo info;

            int index = Ogre::StringConverter::parseInt(list[0]);
            info.pos = Ogre::StringConverter::parseVector3(list[1]);
            info.scale = Ogre::StringConverter::parseReal(list[2]);
            info.yaw = Ogre::StringConverter::parseReal(list[3]);
            info.instance = 0;

            mInstanceList[index] = info;

            if(index >= mNextInstanceIndex)
                mNextInstanceIndex = index + 1;
        }
    }
}