Example #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;
        }