Esempio n. 1
0
        /// <summary>
        /// Сохранение файла
        /// </summary>
        public override void Save()
        {
            ChunkedFile cf = new ChunkedFile();

            cf.Root.Name = "Skybox";

            // Запись текстур
            ChunkedFile.KeyValueChunk textureChunk = new ChunkedFile.KeyValueChunk("Texture");
            textureChunk.Values.Add("Front", sky[Skybox.Side.Front] != null ?        sky[Skybox.Side.Front].Link : "");
            textureChunk.Values.Add("Right", sky[Skybox.Side.Right] != null ?        sky[Skybox.Side.Right].Link : "");
            textureChunk.Values.Add("Back", sky[Skybox.Side.Back] != null ?         sky[Skybox.Side.Back].Link : "");
            textureChunk.Values.Add("Left", sky[Skybox.Side.Left] != null ?         sky[Skybox.Side.Left].Link : "");
            textureChunk.Values.Add("Top", sky[Skybox.Side.Top] != null ?          sky[Skybox.Side.Top].Link : "");
            textureChunk.Values.Add("Bottom", sky[Skybox.Side.Bottom] != null ?       sky[Skybox.Side.Bottom].Link : "");
            cf.Root.Children.Add(textureChunk);

            // Запись данных редактора
            ChunkedFile.DataChunk editorChunk = new ChunkedFile.DataChunk("Editor");
            MemoryStream          ms          = new MemoryStream();
            BinaryWriter          bw          = new BinaryWriter(ms);

            bw.Write((float)cam.Angles.X);
            bw.Write((float)cam.Angles.Y);
            bw.Write((bool)(Form as SkyboxForm).skyGizmoButton.Checked);
            bw.Close();
            editorChunk.Data = ms.ToArray();
            cf.Root.Children.Add(editorChunk);

            // Сохранение
            saving = true;
            cf.Save(File.FullPath);
            Project.Notify(File);
            saving = false;
            Saved  = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Загрузка и инициализация
        /// </summary>
        protected override void Load()
        {
            // Инициализация графики
            if (scene == null)
            {
                // Создание сцены
                scene = new Scene();

                // Камера
                cam          = new Camera();
                scene.Camera = cam;

                // Создание скайбокса
                sky       = new Skybox();
                scene.Sky = sky;

                // Направляющие
                WireCubeComponent c = new WireCubeComponent();
                c.WireColor = Color.Lime;
                c.WireWidth = 3f;
                wireGuides  = new Entity();
                wireGuides.AddComponent(c);
                wireGuides.Position = Vec3.Zero;
                scene.Entities.Add(wireGuides);
            }

            // Загрузка данных
            UpdateTitle();

            ChunkedFile cf = new ChunkedFile(File.FullPath);

            if (cf.Root.Name == "Skybox")
            {
                // Конвертация формы
                SkyboxForm frm = Form as SkyboxForm;

                // Поиск чанка с текстурами
                ChunkedFile.KeyValueChunk textureChunk = (ChunkedFile.KeyValueChunk)cf.Root.GetChunk("Texture");
                if (textureChunk != null)
                {
                    frm.topSkyTexture.File    = Project.GetEntry(textureChunk.Values["Top"]);
                    frm.bottomSkyTexture.File = Project.GetEntry(textureChunk.Values["Bottom"]);
                    frm.leftSkyTexture.File   = Project.GetEntry(textureChunk.Values["Left"]);
                    frm.rightSkyTexture.File  = Project.GetEntry(textureChunk.Values["Right"]);
                    frm.frontSkyTexture.File  = Project.GetEntry(textureChunk.Values["Front"]);
                    frm.backSkyTexture.File   = Project.GetEntry(textureChunk.Values["Back"]);
                }

                // Получение чанка для редактора
                ChunkedFile.DataChunk editorChunk = (ChunkedFile.DataChunk)cf.Root.GetChunk("Editor");
                if (editorChunk != null)
                {
                    MemoryStream ms = new MemoryStream(editorChunk.Data);
                    BinaryReader br = new BinaryReader(ms);
                    float        cx = br.ReadSingle();
                    float        cy = br.ReadSingle();
                    cam.Angles = new Vec3(cx, cy, 0f);
                    (Form as SkyboxForm).skyGizmoButton.Checked = br.ReadBoolean();
                    br.Close();
                }
            }
            Saved = true;
        }