Exemplo n.º 1
0
        /// <summary>
        /// Загрузка данных
        /// </summary>
        protected override void Load()
        {
            UpdateTitle();
            if (scene == null)
            {
                scene = new Scene();

                camHolder          = new Entity();
                camHolder.Position = Vec3.UnitY * 0.3f;
                camHolder.Angles   = new Vec3(30, 135, 0);
                scene.Entities.Add(camHolder);

                cam          = new Camera();
                scene.Camera = cam;
                cam.Parent   = camHolder;

                fpsCam          = new Camera();
                fpsCam.Range    = new Vec2(0.001f, 160f);
                fpsCam.Position = Vec3.Zero;

                grid = new Entity();
                grid.AddComponent(new WireGridComponent()
                {
                    CellCount    = 30,
                    CellSize     = 0.1f,
                    GroupedCells = 5
                });
                scene.Entities.Add(grid);

                cellGizmo = new WireCubeComponent()
                {
                    WireColor = Color.Green,
                    Position  = Vec3.UnitY * 0.5f
                };
                grid.AddComponent(cellGizmo);

                fpsGrid = new Entity();
                fpsGrid.AddComponent(new WireGridComponent()
                {
                    CellCount    = 60,
                    CellSize     = 10f,
                    GroupedCells = 5
                });
                fpsGrid.Position = Vec3.UnitZ * 99;
                fpsGrid.Angles   = new Vec3(90, 0, 0);
                scene.Entities.Add(fpsGrid);
            }

            // Загрузка модели
            if (model != null)
            {
                scene.Entities.Remove(model);
            }
            model          = ModelLoader.FromFile(File.ProjectPath);
            model.Position = Vec3.Zero;
            scene.Entities.Add(model);

            // Дистанция до модели
            range                 = 2f;
            cam.LocalPosition     = Vec3.UnitZ * -range;
            selectedSurface       = -1;
            textureHoveredSurface = -1;

            // Поиск всех поверхностей модели
            surfaces = model.GetComponents <MeshComponent>();
            volumes  = new TrimeshVolumeComponent[surfaces.Length];
            for (int i = 0; i < surfaces.Length; i++)
            {
                volumes[i] = new TrimeshVolumeComponent()
                {
                    Vertices = surfaces[i].Vertices,
                    Indices  = surfaces[i].Indices
                };
                model.AddComponent(volumes[i]);
            }

            // Данные о поверхностях
            surfData = new SurfaceData[surfaces.Length];
            for (int i = 0; i < surfaces.Length; i++)
            {
                surfData[i] = new SurfaceData();
            }

            // Создание списка
            int idx = 0;

            NSListView.NSListViewItem[] surfItems = new NSListView.NSListViewItem[surfaces.Length];
            foreach (MeshComponent mc in surfaces)
            {
                NSListView.NSListViewItem itm = new NSListView.NSListViewItem();
                itm.SubItems = new List <NSListView.NSListViewSubItem>(new NSListView.NSListViewSubItem[] {
                    new NSListView.NSListViewSubItem()
                    {
                        Text = (idx + 1).ToString()
                    },
                    new NSListView.NSListViewSubItem()
                    {
                        Text = ""
                    },
                    new NSListView.NSListViewSubItem()
                    {
                        Text = (mc.Vertices.Length).ToString()
                    },
                    new NSListView.NSListViewSubItem()
                    {
                        Text = (mc.Indices.Length / 3).ToString()
                    },
                });
                surfItems[idx] = itm;
                idx++;
            }
            (Form as ModelForm).surfacesList.Items = surfItems;

            // Создание луча
            ray = new Ray(new Entity[] { model });

            // Поиск аниматора
            animator = model.GetComponent <AnimatorComponent>();
            if (animator != null)
            {
                if (!(Form as ModelForm).propertyTabs.TabPages.Contains((Form as ModelForm).animationPage))
                {
                    (Form as ModelForm).propertyTabs.TabPages.Add((Form as ModelForm).animationPage);
                }

                List <int> frameTimes        = new List <int>();
                AnimatedMeshComponent[] amsh = model.GetComponents <AnimatedMeshComponent>();
                foreach (AnimatedMeshComponent am in amsh)
                {
                    if (am.Frames != null)
                    {
                        foreach (AnimatedMeshComponent.Frame fr in am.Frames)
                        {
                            if (!frameTimes.Contains((int)fr.Time))
                            {
                                frameTimes.Add((int)fr.Time);
                            }
                        }
                    }
                }
                int[] frameTimeArr = frameTimes.ToArray();
                NSAnimationView.PointKey[] pointKeys = new NSAnimationView.PointKey[frameTimeArr.Length];
                for (int i = 0; i < pointKeys.Length; i++)
                {
                    pointKeys[i] = new NSAnimationView.PointKey(frameTimeArr[i]);
                }
                (Form as ModelForm).animationTracker.PointKeys = pointKeys;
                (Form as ModelForm).animationTracker.Length    = animator.FrameCount;
            }
            else
            {
                if ((Form as ModelForm).propertyTabs.TabPages.Contains((Form as ModelForm).animationPage))
                {
                    (Form as ModelForm).propertyTabs.TabPages.Remove((Form as ModelForm).animationPage);
                }
            }

            // Настройка интерфейса
            (Form as ModelForm).cellGizmoButton.Checked   = false;
            (Form as ModelForm).firstPersonButton.Checked = false;
        }
Exemplo 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;
        }