Пример #1
0
        public WorldEditorViewModel(WorldAsset worldAsset, Framework framework)
        {
            SceneManager = new SceneManager(framework.Device, framework.AssetManager);

            WorldEditor = new WorldEditor(worldAsset.World, framework.AssetManager);
            var terrain = new Terrain(framework.Device, framework.AssetManager, 128, 128, 20, new string[] { "Test/water.bmp", "Test/slime2.bmp", "Test/slime1.bmp" });
            SceneManager.AddRenderable(terrain);

            SceneManager.World = worldAsset.World;

            SceneManager.Camera.EyePos = new Vector3(0.0f, terrain.GetHeight(0, 0) + 10.0f, 0.0f);
            SceneManager.Camera.LookAt = new Vector3(100.0f, 0.0f, 100.0f);
            SceneManager.Camera.UpVec = Vector3.UnitY;
            SceneManager.Camera.FovY = new Radian(MathUtils.PI / 4);
            SceneManager.Camera.SetPlaneDistance(1.0f, 10000.0f);

            RenderViewModel = new RenderViewModel(framework, SceneManager);
            RenderViewModel.MouseMove += RenderViewModel_MouseMove;

            SaveCommand = new DelegateCommand(() =>
                {
                    worldAsset.World.Save(worldAsset.FullPath);
                    StatusBarService.StatusText = "World saved: " + worldAsset.ShortName;
                });
        }
Пример #2
0
        public LayoutEditorViewModel(LayoutAsset layoutAsset, Framework framework)
        {
            this.layoutAsset = layoutAsset;

            SceneManager = new SceneManager(framework.Device, framework.AssetManager);

            UpdateVisualTree();

            RenderViewModel = new RenderViewModel(framework, SceneManager);
            RenderViewModel.SizeChanged += ((o, e) =>
                {
                    layoutAsset.Layout.Size = new Size(RenderViewModel.Width, RenderViewModel.Height);
                });

            Elements = new ObservableCollection<UIElementEditor>() { UIElementEditor.Create(null, layoutAsset.Layout, framework.AssetManager) };
            Elements.First().TreeChanged += (o, e) => UpdateVisualTree();

            SaveCommand = new DelegateCommand(() =>
                {
                    layoutAsset.Layout.Save(layoutAsset.FullPath);
                    StatusBarService.StatusText = "Layout saved: " + layoutAsset.ShortName;
                });
            Document = new TextDocument();
            IsDesignMode = true;

            this.xmlUpdateTimer.Interval = TimeSpan.FromMilliseconds(500);
            this.xmlUpdateTimer.Tick += UpdateXmlDocument;
            UpdateXmlDocument(this, EventArgs.Empty);

            RenderViewModel.MouseMove += RenderViewModel_MouseMove;
            RenderViewModel.MouseDown += RenderViewModel_MouseDown;
            RenderViewModel.MouseUp += RenderViewModel_MouseUp;
        }
Пример #3
0
        private void RenderViewModel_MouseMove(object sender, RenderViewModel.MouseMoveEventArgs e)
        {
            if (e.Args.RightButton == MouseButtonState.Pressed)
            {
                var delta = e.Pos - this.mousePos;
                this.meshNode.Orientation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, new Radian(-delta.x * 0.01f));
                this.meshNode.Orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, new Radian(-delta.y * 0.01f)) * this.meshNode.Orientation;
            }

            this.mousePos = e.Pos;
        }
Пример #4
0
        private void RenderViewModel_MouseMove(object sender, RenderViewModel.MouseMoveEventArgs e)
        {
            if (e.Args.RightButton == MouseButtonState.Pressed)
            {
                float scale = 0.001f;
                var delta = e.Pos - this.mousePos;

                SceneManager.Camera.Yaw(new Radian(-delta.x * scale));
                SceneManager.Camera.Pitch(new Radian(-delta.y * scale));
            }

            this.mousePos = e.Pos;
        }
Пример #5
0
        public MaterialEditorViewModel(MaterialAsset materialAsset, Framework framework)
        {
            MaterialEditor = new MaterialEditor(materialAsset.Material);
            ResetCommand = new DelegateCommand<PropertyItem>((item) => System.Windows.MessageBox.Show(item.ToString()));
            AdvancedOptions = new List<MenuItem>();
            AdvancedOptions.Add(new MenuItem() { Header = "Reset", Command = ResetCommand });
            SaveCommand = new DelegateCommand(() =>
                {
                    materialAsset.Material.Save(materialAsset.FullPath);
                    StatusBarService.StatusText = "Material saved: " + materialAsset.ShortName;
                });

            var mesh = Mesh.CreateSphere(framework.Device, framework.AssetManager, materialAsset.Material, 5.0f, 80, 80);
            this.meshNode = new MeshNode(framework.Device, mesh);

            var sceneManager = new SceneManager(framework.Device, framework.AssetManager);
            sceneManager.LocateCameraLookingMesh(mesh);
            sceneManager.AddRenderable(this.meshNode);

            RenderViewModel = new RenderViewModel(framework, sceneManager);
            RenderViewModel.MouseMove += RenderViewModel_MouseMove;
        }
Пример #6
0
        public ImportMeshViewModel(Framework framework, Mesh mesh, string initialSaveFolder)
        {
            this.framework = framework;

            // Actually, import already done. See argument "mesh" :)
            Mesh = mesh;

            var sceneManager = new SceneManager(framework.Device, framework.AssetManager);
            sceneManager.LocateCameraLookingMesh(mesh);
            sceneManager.AddRenderable(new MeshNode(framework.Device, Mesh));
            
            RenderViewModel = new RenderViewModel(framework, sceneManager);

            MaterialEditor = new MaterialEditor(mesh.Material);
            SaveName = Path.GetFileNameWithoutExtension(Mesh.Name);
            SaveFolder = initialSaveFolder;

            OkCommand = new DelegateCommand(ExecuteOk, CanExecuteOk);
            CancelCommand = new DelegateCommand(() => { RequestCancel(); });
            BrowseCommand = new DelegateCommand(ExecuteBrowse);
            FlipVCommand = new DelegateCommand(() => Mesh.FlipTextureV());
        }
Пример #7
0
 private void RenderViewModel_MouseUp(object sender, RenderViewModel.MouseButtonEventArgs e)
 {
     this.layoutAsset.Layout.InjectMouseUpEvent(e.Pos.x, e.Pos.y, e.Args.ChangedButton.ToIreliaButton());
 }
Пример #8
0
        private void RenderViewModel_MouseMove(object sender, RenderViewModel.MouseMoveEventArgs e)
        {
            this.layoutAsset.Layout.InjectMouseMoveEvent(e.Pos.x, e.Pos.y);

            MousePos = e.Pos;
            OnPropertyChanged("MousePos");
        }