Ejemplo n.º 1
0
        public DragData(object source, object sourceObject)
        {
            Source = source;
            SourceObject = sourceObject;

            Parameters = new Mogre.NameValuePairList();
        }
Ejemplo n.º 2
0
        public override void ProcessParameters(Mogre.NameValuePairList parameters)
        {
            Mogre.NameValuePairList.Iterator ni;

            if ((ni = parameters.Find("Name")) != parameters.End())
            {
                this.name = ni.Value;
            }

            if ((ni = parameters.Find("Position")) != parameters.End())
            {
                this.position = Mogre.StringConverter.ParseVector3(ni.Value);
            }

            if ((ni = parameters.Find("Orientation")) != parameters.End())
            {
                this.orientation = Mogre.StringConverter.ParseQuaternion(ni.Value);
            }

            if ((ni = parameters.Find("ClipDistance")) != parameters.End())
            {
                this.clipDistance = MogreX.StringConverter.ParseVector2(ni.Value);
            }

            if ((ni = parameters.Find("FOV")) != parameters.End())
            {
                this.fov = Mogre.StringConverter.ParseReal(ni.Value);
            }
        }
Ejemplo n.º 3
0
        public override void ProcessParameters(Mogre.NameValuePairList parameters)
        {
            Mogre.NameValuePairList.Iterator ni;

            if ((ni = parameters.Find("Name")) != parameters.End())
            {
                this.name = ni.Value;
            }

            if ((ni = parameters.Find("Position")) != parameters.End())
            {
                this.position = Mogre.StringConverter.ParseVector3(ni.Value);
            }

            if ((ni = parameters.Find("Orientation")) != parameters.End())
            {
                this.orientation = Mogre.StringConverter.ParseQuaternion(ni.Value);
            }

            if ((ni = parameters.Find("Scale")) != parameters.End())
            {
                this.scale = Mogre.StringConverter.ParseVector3(ni.Value);
            }

            if ((ni = parameters.Find("AutoTrackTarget")) != parameters.End())
            {
                this.autoTrackTarget = ni.Value;
            }
        }
Ejemplo n.º 4
0
        public override void GetObjectProperties(Mogre.NameValuePairList retList)
        {
            retList.Clear();
            retList["Name"]             = this.name;
            retList["SceneManagerType"] = SceneMangerType;
            retList["Ambient"]          = Mogre.StringConverter.ToString(this.ambient);
            retList["SkyBoxActive"]     = Mogre.StringConverter.ToString(this.skyBoxActive);
            retList["SkyBoxMaterial"]   = this.skyBoxMaterial;
            retList["SkyBoxDistance"]   = Mogre.StringConverter.ToString(this.skyBoxDistance);

            switch (this.fogMode)
            {
            case Mogre.FogMode.FOG_NONE:
                retList["FogMode"] = "None";
                break;

            case Mogre.FogMode.FOG_LINEAR:
                retList["FogMode"] = "Linear";
                break;

            case Mogre.FogMode.FOG_EXP:
                retList["FogMode"] = "Exp";
                break;

            case Mogre.FogMode.FOG_EXP2:
                retList["FogMode"] = "Exp2";
                break;
            }

            retList["FogColour"]  = Mogre.StringConverter.ToString(this.fogColour);
            retList["FogStart"]   = Mogre.StringConverter.ToString(this.fogStart);
            retList["FogEnd"]     = Mogre.StringConverter.ToString(this.fogEnd);
            retList["FogDensity"] = Mogre.StringConverter.ToString(this.fogDensity);
        }
Ejemplo n.º 5
0
        public DragData(object source, object sourceObject)
        {
            Source       = source;
            SourceObject = sourceObject;

            Parameters = new Mogre.NameValuePairList();
        }
        private void ClearEditors()
        {
            this.activeDragData = null;

            DestroyGizmo();

            // Make sure to unload all the viewports first, since they are dependent on SceneManager
            // but they share the same parent with scene manager and scene manager may get deleted before they do
            foreach (KeyValuePair <string, BaseEditor> it in this.namesByType[(int)EditorType.Viewport])
            {
                it.Value.UnLoad();
            }

            this.rootEditor.Destroy(false);
            this.rootEditor = null;

            ActiveViewport          = null;
            this.sceneManager       = null;
            this.sceneManagerEditor = null;
            this.selectedEditor     = null;
            this.objCounter         = 0;
            IsSceneModified         = false;
            IsSceneLoaded           = false;
            this.nameList.Clear();
            this.updateList.Clear();
            SceneUpdated = null;

            foreach (KeyValuePair <string, BaseEditorFactory> it in this.editorObjectFactories)
            {
                if (it.Value != null)
                {
                    it.Value.InstanceCount = 0;
                }
            }

            foreach (NameObjectPairList it in this.namesByType)
            {
                it.Clear();
            }

            foreach (NameObjectPairList it in this.namesByTypeID)
            {
                it.Clear();
            }

            BaseEditor parent = null;

            Mogre.NameValuePairList parameters = new Mogre.NameValuePairList();
            this.rootEditor = BaseEditor.Factory.CreateObject(ref parent, parameters);

            this.gizmoNode    = null;
            this.gizmoX       = null;
            this.gizmoY       = null;
            this.gizmoZ       = null;
            this.oldGizmoMode = EditorTools.None;
            this.oldGizmoAxis = AxisType.None;
        }
Ejemplo n.º 7
0
 public override void GetObjectProperties(Mogre.NameValuePairList retList)
 {
     retList.Clear();
     retList["Name"]            = this.name;
     retList["Position"]        = Mogre.StringConverter.ToString(this.position);
     retList["Orientation"]     = Mogre.StringConverter.ToString(this.orientation);
     retList["Scale"]           = Mogre.StringConverter.ToString(this.scale);
     retList["AutoTrackTarget"] = this.autoTrackTarget;
 }
Ejemplo n.º 8
0
 public override void GetObjectProperties(Mogre.NameValuePairList retList)
 {
     retList.Clear();
     retList["Name"]         = Name;
     retList["Position"]     = Mogre.StringConverter.ToString(Position);
     retList["Orientation"]  = Mogre.StringConverter.ToString(Orientation);
     retList["ClipDistance"] = Mogre.StringConverter.ToString(ClipDistance);
     retList["FOV"]          = Mogre.StringConverter.ToString(FOV);
 }
Ejemplo n.º 9
0
        public override void ProcessParameters(Mogre.NameValuePairList parameters)
        {
            Mogre.NameValuePairList.Iterator ni;

            if ((ni = parameters.Find("Name")) != parameters.End())
            {
                this.name = ni.Value;
            }
        }
Ejemplo n.º 10
0
        public override BaseEditor CreateObject(ref BaseEditor parent, Mogre.NameValuePairList parameters)
        {
            SceneManagerEditor editor = new SceneManagerEditor();

            editor.ProcessParameters(parameters);
            editor.Parent = parent;
            editor.Load();

            InstanceCount++;
            return(editor);
        }
Ejemplo n.º 11
0
        public override void GetObjectProperties(Mogre.NameValuePairList retList)
        {
            base.GetObjectProperties(retList);

            retList["MeshFile"]    = this.meshFile;
            retList["CastShadows"] = Mogre.StringConverter.ToString(this.castShadows);

            for (int i = 0; i < this.subMeshes.Count; ++i)
            {
                string paramName = "SubEntity" + Mogre.StringConverter.ToString(i) + ".";
                retList[paramName + "Visible"]  = Mogre.StringConverter.ToString(this.subMeshes[i].Visible);
                retList[paramName + "Material"] = this.subMeshes[i].Material;
            }
        }
Ejemplo n.º 12
0
        public override BaseEditor CreateObject(ref BaseEditor parent, Mogre.NameValuePairList parameters)
        {
            CameraEditor obj = new CameraEditor();

            Mogre.NameValuePairList.Iterator ni;
            if ((ni = parameters.Find("Init")) != parameters.End())
            {
                parameters["Name"] = "Camera" + MogitorsRoot.Instance.CreateUniqueID("Camera", "", -1);
            }

            obj.ProcessParameters(parameters);
            obj.Parent = parent;

            InstanceCount++;
            return(obj);
        }
Ejemplo n.º 13
0
        public override BaseEditor CreateObject(ref BaseEditor parent, Mogre.NameValuePairList parameters)
        {
            MaterialEditor obj = new MaterialEditor();

            Mogre.NameValuePairList.Iterator ni;
            if ((ni = parameters.Find("Init")) != parameters.End())
            {
                parameters["Name"] = "Material" + MogitorsRoot.Instance.CreateUniqueID("Material", "", 1);
            }

            obj.ProcessParameters(parameters);
            parent     = MogitorsRoot.Instance.SceneManagerEditor;
            obj.Parent = parent;

            InstanceCount++;
            return(obj);
        }
Ejemplo n.º 14
0
        void MogitorsRoot.IDragDropHandler.OnDragDrop(DragData dragData, Mogre.Viewport vp, Mogre.Vector2 position)
        {
            if (dragData.Object != null)
            {
                Mogre.NameValuePairList parameters = new Mogre.NameValuePairList();
                dragData.Object.GetObjectProperties(parameters);
                dragData.Object.Destroy(false);
                dragData.Object = null;

                dragData.Parameters["Position"] = parameters["Position"];

                MogitorsRoot.Instance.CreateEditorObject(null, dragData.ObjectType, dragData.Parameters, true, true);
            }

            dragData.Parameters.Clear();
            dragData.ObjectType = "";
            dragData.Object = null;
        }
Ejemplo n.º 15
0
        void MogitorsRoot.IDragDropHandler.OnDragDrop(DragData dragData, Mogre.Viewport vp, Mogre.Vector2 position)
        {
            if (dragData.Object != null)
            {
                Mogre.NameValuePairList parameters = new Mogre.NameValuePairList();
                dragData.Object.GetObjectProperties(parameters);
                dragData.Object.Destroy(false);
                dragData.Object = null;

                dragData.Parameters["Position"] = parameters["Position"];

                MogitorsRoot.Instance.CreateEditorObject(null, dragData.ObjectType, dragData.Parameters, true, true);
            }

            dragData.Parameters.Clear();
            dragData.ObjectType = "";
            dragData.Object     = null;
        }
Ejemplo n.º 16
0
        public override BaseEditor CreateObject(ref BaseEditor parent, Mogre.NameValuePairList parameters)
        {
            EntityEditor editor = new EntityEditor();

            if (parameters.Find("MeshFile") == parameters.End())
            {
                parameters["MeshFile"] = "scbCamera.mesh";
            }

            if (parameters.Find("Init") != parameters.End())
            {
                string entName = Path.GetFileNameWithoutExtension(parameters["MeshFile"]);
                parameters["Name"] = entName + MogitorsRoot.Instance.CreateUniqueID(entName, "", -1);
            }

            editor.ProcessParameters(parameters);
            editor.Parent = parent;

            InstanceCount++;
            return(editor);
        }
Ejemplo n.º 17
0
        public override void ProcessParameters(Mogre.NameValuePairList parameters)
        {
            base.ProcessParameters(parameters);

            Mogre.NameValuePairList.Iterator ni;

            if ((ni = parameters.Find("MeshFile")) != parameters.End())
            {
                this.meshFile = ni.Value;
            }

            if ((ni = parameters.Find("CastShadows")) != parameters.End())
            {
                this.castShadows = Mogre.StringConverter.ParseBool(ni.Value);
            }

            foreach (KeyValuePair <string, string> param in parameters)
            {
                if (!param.Key.StartsWith("SubEntity"))
                {
                    continue;
                }

                string valStr = param.Key;
                valStr = valStr.Remove(0, 9);

                if (valStr.EndsWith("Visible"))
                {
                    valStr = valStr.Remove(valStr.Length - 8, 8);
                    int ID = Mogre.StringConverter.ParseInt(valStr);
                    GetSubMesh(ID).Visible = Mogre.StringConverter.ParseBool(param.Value);
                }
                else if (valStr.EndsWith("Material"))
                {
                    valStr = valStr.Remove(valStr.Length - 9, 9);
                    int ID = Mogre.StringConverter.ParseInt(valStr);
                    GetSubMesh(ID).Material = param.Value;
                }
            }
        }
Ejemplo n.º 18
0
        public void AfterLoadScene()
        {
            CreateGizmo();
            GizmoMode = EditorTools.Select;
            ViewportEditor.ResetCommonValues();

            if (ActiveViewport == null)
            {
                Mogre.NameValuePairList parameters = new Mogre.NameValuePairList();
                parameters.Clear();
                parameters["Name"]   = "Viewport1";
                parameters["Colour"] = "0 0 0";
                parameters["Index"]  = "1";
                ActiveViewport       = CreateEditorObject(null, "Viewport Object", parameters, false, false) as ViewportEditor;
            }

            system.UpdateLoadProgress(60, "Loading scene objects");

            this.rootEditor.Load();
            this.rootEditor.LoadAllChildren();

            if (SceneUpdated != null)
            {
                SceneUpdated(this, new SceneUpdatedEventArgs(SceneManager, ActiveViewport.CameraEditor.Camera, RenderTarget));
            }
            SceneUpdated = null;

            FillTreeView();

            system.UpdateLoadProgress(100, "Rendering...");

            IsSceneLoaded   = true;
            IsSceneModified = false;

            if (SceneLoaded != null)
            {
                SceneLoaded(this, EventArgs.Empty);
            }
        }
        public BaseEditor CreateEditorObject(BaseEditor parent, string objectTypeString, Mogre.NameValuePairList param, bool addToTreeList, bool display)
        {
            if (parent == null)
            {
                Mogre.NameValuePairList.Iterator ni;
                if ((ni = param.Find("ParentNode")) != param.End())
                {
                    parent = FindObject(ni.Value, 0);
                }

                if (parent == null)
                {
                    if (SceneManager == null)
                    {
                        parent = this.rootEditor;
                    }
                    else
                    {
                        parent = SceneManagerEditor;
                    }
                }
            }

            BaseEditorFactory factory = GetEditorObjectFactory(objectTypeString);

            if (factory == null)
            {
                return(null);
            }

            BaseEditor obj = factory.CreateObject(ref parent, param);

            if (obj == null)
            {
                return(null);
            }

            RegisterObjectName(obj.Name, obj);

            parent.AddChild(obj);

            if (addToTreeList)
            {
                object handle = this.system.InsertTreeItem(parent.TreeItemHandle, obj.Name, obj.ObjectTypeID, System.Windows.Media.Colors.Black);
                obj.TreeItemHandle = handle;
            }

            if (display)
            {
                obj.Load();
                obj.UpdateTreeView();
            }

            IsSceneModified = true;
            return(obj);
        }
Ejemplo n.º 20
0
 public override void GetObjectProperties(Mogre.NameValuePairList retList)
 {
     retList.Clear();
     retList["Name"] = this.name;
 }
Ejemplo n.º 21
0
        public override void ProcessParameters(Mogre.NameValuePairList parameters)
        {
            Mogre.NameValuePairList.Iterator ni;

            if ((ni = parameters.Find("Name")) != parameters.End())
            {
                this.name = ni.Value;
            }

            if ((ni = parameters.Find("SkyBoxMaterial")) != parameters.End())
            {
                this.skyBoxMaterial = ni.Value;
            }

            if ((ni = parameters.Find("Ambient")) != parameters.End())
            {
                this.ambient = Mogre.StringConverter.ParseColourValue(ni.Value);
            }

            if ((ni = parameters.Find("FogColour")) != parameters.End())
            {
                this.fogColour = Mogre.StringConverter.ParseColourValue(ni.Value);
            }

            if ((ni = parameters.Find("SkyBoxActive")) != parameters.End())
            {
                this.skyBoxActive = Mogre.StringConverter.ParseBool(ni.Value);
            }

            if ((ni = parameters.Find("SkyBoxDistance")) != parameters.End())
            {
                this.skyBoxDistance = Mogre.StringConverter.ParseReal(ni.Value);
            }

            if ((ni = parameters.Find("FogStart")) != parameters.End())
            {
                this.fogStart = Mogre.StringConverter.ParseReal(ni.Value);
            }

            if ((ni = parameters.Find("FogEnd")) != parameters.End())
            {
                this.fogEnd = Mogre.StringConverter.ParseReal(ni.Value);
            }

            if ((ni = parameters.Find("FogDensity")) != parameters.End())
            {
                this.fogDensity = Mogre.StringConverter.ParseReal(ni.Value);
            }

            if ((ni = parameters.Find("FogMode")) != parameters.End())
            {
                string val = ni.Value.ToLower();
                if (val == "none")
                {
                    this.fogMode = Mogre.FogMode.FOG_NONE;
                }
                else if (val == "linear")
                {
                    this.fogMode = Mogre.FogMode.FOG_LINEAR;
                }
                else if (val == "exp")
                {
                    this.fogMode = Mogre.FogMode.FOG_EXP;
                }
                else if (val == "exp2")
                {
                    this.fogMode = Mogre.FogMode.FOG_EXP2;
                }
            }
        }
Ejemplo n.º 22
0
        public override SceneFileResult Export(bool saveAs)
        {
            MogitorsRoot   mogRoot = MogitorsRoot.Instance;
            MogitorsSystem system  = MogitorsSystem.Instance;

            ProjectOptions opt      = mogRoot.ProjectOptions;
            string         fileName = system.CombinePath(opt.ProjectDir, opt.ProjectName + ".mogscene");

            // If saveAs is true, use the MogitorsSystem Function to retrieve
            // a FileName and also copy the contents of current scene to the new location
            if (saveAs)
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.FileName   = "";
                dlg.DefaultExt = ".mogscene";
                dlg.Filter     = "Mogitor Scene File (.mogscene)|*.mogscene";

                Nullable <bool> result = dlg.ShowDialog();
                if (result != true)
                {
                    return(SceneFileResult.Cancel);
                }

                fileName = dlg.FileName;

                string oldProjDir  = opt.ProjectDir;
                string oldProjName = opt.ProjectName;

                opt.ProjectName = system.ExtractFileName(fileName);
                opt.ProjectDir  = system.ExtractFilePath(fileName);

                mogRoot.AdjustUserResourceDirectories(oldProjDir);

                string newDir = opt.ProjectDir;

                system.MakeDirectory(newDir);
                system.CopyFilesEx(oldProjDir, newDir);

                string delFileStr = system.GetFullPath(system.CombinePath(opt.ProjectDir, oldProjName + ".mogscene"));
                system.DeleteFile(delFileStr);
            }

            XmlTextWriter textWriter = new XmlTextWriter(fileName, System.Text.Encoding.Unicode);

            textWriter.Formatting = Formatting.Indented;
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("MogitorScene");
            mogRoot.WriteProjectOptions(textWriter, true);

            ObjectVector objectList = new ObjectVector();

            for (EditorType type = 0; type < EditorType.LastEditor; ++type)
            {
                mogRoot.GetObjectList(type, objectList);
                foreach (BaseEditor obj in objectList)
                {
                    // If object does not have a parent, then it is not part of the scene
                    if (obj.Parent == null)
                    {
                        continue;
                    }

                    if (obj.IsSerializable)
                    {
                        textWriter.WriteStartElement("Object");
                        textWriter.WriteStartAttribute("Type");
                        textWriter.WriteValue(obj.ObjectTypeName);
                        textWriter.WriteEndAttribute();

                        // If obj's parent name is "" then the parent is this.rootEditor
                        if (obj.Parent.Name != "")
                        {
                            textWriter.WriteStartAttribute("ParentNode");
                            textWriter.WriteValue(obj.Parent.Name);
                            textWriter.WriteEndAttribute();
                        }
                        Mogre.NameValuePairList theList = new Mogre.NameValuePairList();
                        obj.GetObjectProperties(theList);
                        foreach (KeyValuePair <string, string> it in theList)
                        {
                            textWriter.WriteStartAttribute(it.Key);
                            textWriter.WriteValue(it.Value);
                            textWriter.WriteEndAttribute();
                        }
                        textWriter.WriteEndElement();
                    }
                    obj.OnSave();
                }
            }

            textWriter.WriteEndElement();
            textWriter.WriteEndDocument();
            textWriter.Close();

            mogRoot.IsSceneModified = false;

            if (saveAs)
            {
                mogRoot.TerminateScene();
                mogRoot.LoadScene(fileName);
            }
            return(SceneFileResult.Ok);
        }
Ejemplo n.º 23
0
        public override SceneFileResult Import(string importFile)
        {
            MogitorsRoot   mogRoot = MogitorsRoot.Instance;
            MogitorsSystem system  = MogitorsSystem.Instance;

            if (importFile == "")
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.FileName   = "";
                dlg.DefaultExt = ".mogscene";
                dlg.Filter     = "Mogitor Scene File (.mogscene)|*.mogscene";
                Nullable <bool> result = dlg.ShowDialog();
                if (result != true)
                {
                    return(SceneFileResult.Cancel);
                }
                importFile = dlg.FileName;
            }

            string filePath = system.ExtractFilePath(importFile);
            string fileName = system.ExtractFileName(importFile);

            XmlTextReader textReader = new XmlTextReader(importFile);

            system.UpdateLoadProgress(5, "Loading scene objects");

            if (!textReader.ReadToFollowing("MogitorScene"))
            {
                return(SceneFileResult.ErrParse);
            }

            // Check version
            string fileVersion = textReader.GetAttribute("Version");

            if (fileVersion != null)
            {
                if (int.Parse(fileVersion) != 1)
                {
                    return(SceneFileResult.ErrParse);
                }
            }

            // Read project options
            if (textReader.ReadToFollowing("ProjectOptions") == true)
            {
                system.UpdateLoadProgress(15, "Parsing project options");
                mogRoot.LoadProjectOptions(textReader);

                mogRoot.ProjectOptions.ProjectDir  = filePath;
                mogRoot.ProjectOptions.ProjectName = fileName;

                mogRoot.PrepareProjectResources();
            }

            //// Moves the reader back to the "MogitorScene" element node.
            //textReader.MoveToElement();

            system.UpdateLoadProgress(30, "Creating scene objects");

            // Load objects
            Mogre.NameValuePairList param = new Mogre.NameValuePairList();
            while (textReader.ReadToNextSibling("Object"))
            {
                string objectType = textReader.GetAttribute("Type");
                if (objectType == "")
                {
                    continue;
                }

                param.Clear();
                while (textReader.MoveToNextAttribute())
                {
                    param.Insert(textReader.Name, textReader.Value);
                }

                BaseEditor result = MogitorsRoot.Instance.CreateEditorObject(null, objectType, param, false, false);
            }

            mogRoot.AfterLoadScene();

            return(SceneFileResult.Ok);
        }
Ejemplo n.º 24
0
        public void AfterLoadScene()
        {
            CreateGizmo();
            GizmoMode = EditorTools.Select;
            ViewportEditor.ResetCommonValues();

            if (ActiveViewport == null)
            {
                Mogre.NameValuePairList parameters = new Mogre.NameValuePairList();
                parameters.Clear();
                parameters["Name"] = "Viewport1";
                parameters["Colour"] = "0 0 0";
                parameters["Index"] = "1";
                ActiveViewport = CreateEditorObject(null, "Viewport Object", parameters, false, false) as ViewportEditor;
            }

            system.UpdateLoadProgress(60, "Loading scene objects");

            this.rootEditor.Load();
            this.rootEditor.LoadAllChildren();

            if (SceneUpdated != null)
                SceneUpdated(this, new SceneUpdatedEventArgs(SceneManager, ActiveViewport.CameraEditor.Camera, RenderTarget));
            SceneUpdated = null;

            FillTreeView();

            system.UpdateLoadProgress(100, "Rendering...");

            IsSceneLoaded = true;
            IsSceneModified = false;

            if (SceneLoaded != null)
                SceneLoaded(this, EventArgs.Empty);
        }
Ejemplo n.º 25
0
        public override SceneFileResult Export(bool saveAs)
        {
            MogitorsRoot mogRoot = MogitorsRoot.Instance;
            MogitorsSystem system = MogitorsSystem.Instance;

            ProjectOptions opt = mogRoot.ProjectOptions;
            string fileName = system.CombinePath(opt.ProjectDir, opt.ProjectName + ".mogscene");

            // If saveAs is true, use the MogitorsSystem Function to retrieve
            // a FileName and also copy the contents of current scene to the new location
            if (saveAs)
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.FileName = "";
                dlg.DefaultExt = ".mogscene";
                dlg.Filter = "Mogitor Scene File (.mogscene)|*.mogscene";

                Nullable<bool> result = dlg.ShowDialog();
                if (result != true)
                    return SceneFileResult.Cancel;

                fileName = dlg.FileName;

                string oldProjDir = opt.ProjectDir;
                string oldProjName = opt.ProjectName;

                opt.ProjectName = system.ExtractFileName(fileName);
                opt.ProjectDir = system.ExtractFilePath(fileName);

                mogRoot.AdjustUserResourceDirectories(oldProjDir);

                string newDir = opt.ProjectDir;

                system.MakeDirectory(newDir);
                system.CopyFilesEx(oldProjDir, newDir);

                string delFileStr = system.GetFullPath(system.CombinePath(opt.ProjectDir, oldProjName + ".mogscene"));
                system.DeleteFile(delFileStr);
            }

            XmlTextWriter textWriter = new XmlTextWriter(fileName, System.Text.Encoding.Unicode);
            textWriter.Formatting = Formatting.Indented;
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("MogitorScene");
            mogRoot.WriteProjectOptions(textWriter, true);

            ObjectVector objectList = new ObjectVector();
            for (EditorType type = 0; type < EditorType.LastEditor; ++type)
            {
                mogRoot.GetObjectList(type, objectList);
                foreach (BaseEditor obj in objectList)
                {
                    // If object does not have a parent, then it is not part of the scene
                    if (obj.Parent == null)
                        continue;

                    if (obj.IsSerializable)
                    {
                        textWriter.WriteStartElement("Object");
                        textWriter.WriteStartAttribute("Type");
                        textWriter.WriteValue(obj.ObjectTypeName);
                        textWriter.WriteEndAttribute();

                        // If obj's parent name is "" then the parent is this.rootEditor
                        if (obj.Parent.Name != "")
                        {
                            textWriter.WriteStartAttribute("ParentNode");
                            textWriter.WriteValue(obj.Parent.Name);
                            textWriter.WriteEndAttribute();
                        }
                        Mogre.NameValuePairList theList = new Mogre.NameValuePairList();
                        obj.GetObjectProperties(theList);
                        foreach (KeyValuePair<string, string> it in theList)
                        {
                            textWriter.WriteStartAttribute(it.Key);
                            textWriter.WriteValue(it.Value);
                            textWriter.WriteEndAttribute();
                        }
                        textWriter.WriteEndElement();
                    }
                    obj.OnSave();
                }
            }

            textWriter.WriteEndElement();
            textWriter.WriteEndDocument();
            textWriter.Close();

            mogRoot.IsSceneModified = false;

            if (saveAs)
            {
                mogRoot.TerminateScene();
                mogRoot.LoadScene(fileName);
            }
            return SceneFileResult.Ok;
        }
Ejemplo n.º 26
0
        public override SceneFileResult Import(string importFile)
        {
            MogitorsRoot mogRoot = MogitorsRoot.Instance;
            MogitorsSystem system = MogitorsSystem.Instance;

            if (importFile == "")
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.FileName = "";
                dlg.DefaultExt = ".mogscene";
                dlg.Filter = "Mogitor Scene File (.mogscene)|*.mogscene";
                Nullable<bool> result = dlg.ShowDialog();
                if (result != true)
                {
                    return SceneFileResult.Cancel;
                }
                importFile = dlg.FileName;
            }

            string filePath = system.ExtractFilePath(importFile);
            string fileName = system.ExtractFileName(importFile);

            XmlTextReader textReader = new XmlTextReader(importFile);

            system.UpdateLoadProgress(5, "Loading scene objects");

            if (!textReader.ReadToFollowing("MogitorScene"))
                return SceneFileResult.ErrParse;

            // Check version
            string fileVersion = textReader.GetAttribute("Version");
            if (fileVersion != null)
            {
                if (int.Parse(fileVersion) != 1)
                    return SceneFileResult.ErrParse;
            }

            // Read project options
            if (textReader.ReadToFollowing("ProjectOptions") == true)
            {
                system.UpdateLoadProgress(15, "Parsing project options");
                mogRoot.LoadProjectOptions(textReader);

                mogRoot.ProjectOptions.ProjectDir = filePath;
                mogRoot.ProjectOptions.ProjectName = fileName;

                mogRoot.PrepareProjectResources();
            }

            //// Moves the reader back to the "MogitorScene" element node.
            //textReader.MoveToElement();

            system.UpdateLoadProgress(30, "Creating scene objects");

            // Load objects
            Mogre.NameValuePairList param = new Mogre.NameValuePairList();
            while (textReader.ReadToNextSibling("Object"))
            {
                string objectType = textReader.GetAttribute("Type");
                if (objectType == "")
                    continue;

                param.Clear();
                while (textReader.MoveToNextAttribute())
                {
                    param.Insert(textReader.Name, textReader.Value);
                }

                BaseEditor result = MogitorsRoot.Instance.CreateEditorObject(null, objectType, param, false, false);
            }

            mogRoot.AfterLoadScene();

            return SceneFileResult.Ok;
        }
Ejemplo n.º 27
0
        private void treeControl_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeViewItem treeItem = e.NewValue as TreeViewItem;
            if (treeItem == null)
                return;

            if (treeItem.Parent == null)
            {
                if (MogitorsRoot.Instance.Selected != null)
                    MogitorsRoot.Instance.Selected.IsSelected = false;
                MogitorsRoot.Instance.RootEditor.IsSelected = true;
                return;
            }

            IconTextItem item = treeItem.Header as IconTextItem;
            if (item == null)
            {
                e.Handled = true;
                return;
            }

            int id = (treeItem.Tag != null) ? (int)treeItem.Tag : 0;

            int level = 0;
            while (treeItem.Tag != null)
            {
                treeItem = treeItem.Parent as TreeViewItem;
                item = treeItem.Header as IconTextItem;
                ++level;
            }

            string name = item.Name;

            MogitorsRoot mogRoot = MogitorsRoot.Instance;

            if (this.materialEditor == null || name != this.materialEditor.Name ||
                level != this.materialEditor.PropertyLevel ||
                id != this.materialEditor.PropertyId)
            {
                if (mogRoot.Selected != null)
                    mogRoot.Selected.IsSelected = false;

                if (this.materialEditor != null)
                    this.materialEditor.Destroy(false);

                BaseEditor parentEd = null;
                Mogre.NameValuePairList parameters = new Mogre.NameValuePairList();
                parameters["Name"] = name;

                this.materialEditor = MaterialEditor.Factory.CreateObject(ref parentEd, parameters) as MaterialEditor;
                if (this.materialEditor != null && this.materialEditor.Load())
                {
                    this.materialEditor.TreeItemHandle = treeItem;
                    this.materialEditor.SetPropertiesLevel(level, id);
                    this.materialEditor.IsSelected = true;
                }
            }
        }
Ejemplo n.º 28
0
 public virtual void ProcessParameters(Mogre.NameValuePairList parameters)
 {
 }
Ejemplo n.º 29
0
 public virtual BaseEditor CreateObject(ref BaseEditor parent, Mogre.NameValuePairList parameters)
 {
     InstanceCount++;
     return(new BaseEditor());
 }
Ejemplo n.º 30
0
 public virtual void GetObjectProperties(Mogre.NameValuePairList retList)
 {
     retList.Clear();
     retList["Name"] = Name;
 }
Ejemplo n.º 31
0
        private void treeControl_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            TreeViewItem treeItem = e.NewValue as TreeViewItem;

            if (treeItem == null)
            {
                return;
            }

            if (treeItem.Parent == null)
            {
                if (MogitorsRoot.Instance.Selected != null)
                {
                    MogitorsRoot.Instance.Selected.IsSelected = false;
                }
                MogitorsRoot.Instance.RootEditor.IsSelected = true;
                return;
            }

            IconTextItem item = treeItem.Header as IconTextItem;

            if (item == null)
            {
                e.Handled = true;
                return;
            }

            int id = (treeItem.Tag != null) ? (int)treeItem.Tag : 0;

            int level = 0;

            while (treeItem.Tag != null)
            {
                treeItem = treeItem.Parent as TreeViewItem;
                item     = treeItem.Header as IconTextItem;
                ++level;
            }

            string name = item.Name;

            MogitorsRoot mogRoot = MogitorsRoot.Instance;

            if (this.materialEditor == null || name != this.materialEditor.Name ||
                level != this.materialEditor.PropertyLevel ||
                id != this.materialEditor.PropertyId)
            {
                if (mogRoot.Selected != null)
                {
                    mogRoot.Selected.IsSelected = false;
                }

                if (this.materialEditor != null)
                {
                    this.materialEditor.Destroy(false);
                }

                BaseEditor parentEd = null;
                Mogre.NameValuePairList parameters = new Mogre.NameValuePairList();
                parameters["Name"] = name;

                this.materialEditor = MaterialEditor.Factory.CreateObject(ref parentEd, parameters) as MaterialEditor;
                if (this.materialEditor != null && this.materialEditor.Load())
                {
                    this.materialEditor.TreeItemHandle = treeItem;
                    this.materialEditor.SetPropertiesLevel(level, id);
                    this.materialEditor.IsSelected = true;
                }
            }
        }