Exemplo n.º 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;
                });
        }
Exemplo n.º 2
0
        public RenderViewModel(Framework fw, SceneManager sceneManager)
        {
            this.framework = fw;
            this.sceneManager = sceneManager;

            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }
Exemplo n.º 3
0
 public void SceneManager_Render_Test()
 {
     var sceneMgr = new SceneManager(Device, AssetManager);
     sceneMgr.AddRenderable(TestHelpers.CreateRenderableMock(Device));
     sceneMgr.AddSprite(TestHelpers.CreateSpriteMock(Device));
     Assert.IsTrue(sceneMgr.Render(RenderSystem, RenderSystem.PrimaryRenderTarget, false));
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
 protected override bool RenderThumbnail(RenderTarget renderTarget)
 {
     var sceneManager = new SceneManager(this.framework.Device, this.framework.AssetManager);
     sceneManager.AddRenderable(new MeshNode(this.framework.Device, Mesh));
     sceneManager.LocateCameraLookingMesh(Mesh);
     return sceneManager.Render(this.framework.Renderer, renderTarget, false);
 }
Exemplo n.º 6
0
 protected override bool RenderThumbnail(RenderTarget renderTarget)
 {
     var mesh = Mesh.CreateSphere(this.framework.Device, this.framework.AssetManager, Material, 5.0f, 80, 80);
     var sceneManager = new SceneManager(this.framework.Device, this.framework.AssetManager);
     sceneManager.AddRenderable(new MeshNode(this.framework.Device, mesh));
     sceneManager.LocateCameraLookingMesh(mesh);
     return sceneManager.Render(this.framework.Renderer, renderTarget, false);
 }
Exemplo n.º 7
0
        public void SceneManager_AddRemoveSprite_Test()
        {
            var sceneMgr = new SceneManager(Device, AssetManager);
            var sprite = TestHelpers.CreateSpriteMock(Device);

            Assert.IsTrue(sceneMgr.AddSprite(sprite));
            Assert.IsFalse(sceneMgr.AddSprite(sprite));

            Assert.IsTrue(sceneMgr.RemoveSprite(sprite));
            Assert.IsFalse(sceneMgr.RemoveSprite(sprite));
        }
Exemplo n.º 8
0
        public void SceneManager_AddRemoveRenderable_Test()
        {
            var sceneMgr = new SceneManager(Device, AssetManager);
            var renderable = TestHelpers.CreateRenderableMock(Device);

            Assert.IsTrue(sceneMgr.AddRenderable(renderable));
            Assert.IsFalse(sceneMgr.AddRenderable(renderable));

            Assert.IsTrue(sceneMgr.RemoveRenderable(renderable));
            Assert.IsFalse(sceneMgr.RemoveRenderable(renderable));
        }
Exemplo n.º 9
0
        public void SceneManager_SetWorld_Test()
        {
            var sceneMgr = new SceneManager(Device, AssetManager);

            var world = new World(Device, "world", AssetManager);
            var args = new AssetLoadArguments();
            args.Add("cube", true);
            world.Skybox.SkyTexture = AssetManager.Load(@"Test\SpaceSkyCubeMap.dds", args) as CubeTexture;

            sceneMgr.World = world;
            Assert.AreEqual(world, sceneMgr.World);
        }
Exemplo n.º 10
0
        public Asteroid(Framework framework, SceneManager sceneManager, int type)
        {
            string meshFile = @"RocketCommander\asteroid" + (type + 1).ToString() + ".meshb";
            Mesh = framework.AssetManager.Load(meshFile) as Mesh;

            var random = new Random();
            float[] scalings = new float[] {0.0249557421f, 0.01308855f, 0.0136641478f, 0.0136658037f, 0.008148187f};
            float scale = random.Next(minScale, maxScale) * scalings[type];

            MeshNode = new MeshNode(framework.Device, Mesh)
            {
                Scale = new Vector3(scale, scale, scale)
            };

            sceneManager.AddRenderable(MeshNode);
        }
Exemplo n.º 11
0
        public SmallAsteroid(Framework framework, SceneManager sceneManager, int type)
        {
            string meshFile = @"RocketCommander\SmallAsteroid" + (type + 1).ToString() + ".meshb";
            Mesh = framework.AssetManager.Load(meshFile) as Mesh;

            var random = new Random();
            float[] scalings = new float[] {0.00243701926f, 0.00213851035f, 0.00200786744f};
            float scale = (smallAsteroidSize + RandomHelper.GetRandomFloat(-2.5f, 5.0f)) * scalings[type];

            MeshNode = new MeshNode(framework.Device, this.Mesh)
            {
                Scale = new Vector3(scale, scale, scale)
            };

            sceneManager.AddRenderable(MeshNode);
        }
Exemplo n.º 12
0
        public Item(Framework framework, SceneManager sceneManager, Type type)
        {
            ItemType = type;

            string meshFile = @"RocketCommander\" + Enum.GetName(typeof(Type), ItemType) + ".meshb";
            Mesh = framework.AssetManager.Load(meshFile) as Mesh;

            float[] scalings = new float[] { 0.006876214f, 0.009066273f, 0.0125944568f, 0.0146259107f, 0.0168181341f };
            float scale = scalings[(int)type];

            MeshNode = new MeshNode(framework.Device, Mesh)
            {
                Scale = new Vector3(scale, scale, scale)
            };

            sceneManager.AddRenderable(MeshNode);
        }
Exemplo n.º 13
0
        public Game(string title, int width, int height)
        {
            Width = width;
            Height = height;

            this.form = new Form()
            {
                Text = title,
                ClientSize = new System.Drawing.Size(Width, Height)
            };

            // Initialize render system
            string mediaPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../Media");
            RenderSettings.MediaPath = Path.GetFullPath(mediaPath);

            this.framework = new Framework(form.Handle, Width, Height, RenderSettings.MediaPath);
            this.sceneManager = new SceneManager(this.framework.Device, this.framework.AssetManager);
            this.sceneManager.Camera.AspectRatio = (float)Width / (float)Height;
        }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
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());
        }