private void LoadModel(string file) { if (!string.IsNullOrEmpty(file)) { var folder = Path.GetDirectoryName(file); var data = File.ReadAllText(file); _model = NursiaModel.LoadFromJson(data, n => { using (var stream = File.OpenRead(Path.Combine(folder, n))) { return(Texture2D.FromStream(GraphicsDevice, stream)); } }); _mainPanel._comboAnimations.Items.Clear(); _mainPanel._comboAnimations.Items.Add(new ListItem(null)); foreach (var pair in _model.Animations) { _mainPanel._comboAnimations.Items.Add( new ListItem(pair.Key) { Tag = pair.Value }); } _scene.Models.Clear(); _scene.Models.Add(_model); } // Reset camera _scene.Camera.SetLookAt(new Vector3(10, 10, 10), Vector3.Zero); }
private NursiaModel LoadModel(string file) { var folder = Path.GetDirectoryName(file); var data = File.ReadAllText(file); var result = NursiaModel.LoadFromJson(data, n => LoadTexture(Path.Combine(folder, n))); _scene.Models.Add(result); // Reset camera _scene.Camera.SetLookAt(new Vector3(10, 10, 10), Vector3.Zero); return(result); }
private void DrawModel(NursiaModel model) { if (!_beginCalled) { throw new Exception("Begin wasnt called"); } model.UpdateNodesAbsoluteTransforms(); using (var transformScope = new TransformScope(_context, model.Transform)) { foreach (var mesh in model.Meshes) { DrawMeshNode(mesh); } } }
protected override void LoadContent() { base.LoadContent(); _spriteBatch = new SpriteBatch(GraphicsDevice); // UI MyraEnvironment.Game = this; _mainPanel = new MainPanel(); Desktop.Root = _mainPanel; // Nursia Nrs.Game = this; var folder = @"C:\Projects\Nursia\samples"; // Model _model = LoadModel(Path.Combine(folder, @"models\knight.g3dj")); _model.Transform = Matrix.CreateTranslation(new Vector3(0, 10, 0)); _model.CurrentAnimation = _model.Animations["Attack"]; // Terrain var grassy = LoadTexture(Path.Combine(folder, @"terrain\grassy2.png")); _scene.Terrain = new Terrain(400); // Generate height var generator = new HeightMapGenerator(); GenerationConfig.Instance.WorldSize = (int)_scene.Terrain.Size; var heightMap = generator.Generate(); _scene.Terrain.HeightFunc = (x, z) => { if (x < 0) { x = 0; } if (x >= heightMap.GetLength(0)) { x = heightMap.GetLength(0) - 1; } if (z < 0) { z = 0; } if (z >= heightMap.GetLength(1)) { z = heightMap.GetLength(1) - 1; } var result = (heightMap[(int)x, (int)z] * 100) - 50; return(result); /* int r = (int)(x / 100) + (int)(z / 100); * * return r % 2 == 0 ? -10 : 10;*/ }; _scene.Terrain.SetTexture(grassy); // Water _scene.WaterTiles.Add(new WaterTile(0, 0, 0, _scene.Terrain.Size)); // Skybox var skyboxFolder = Path.Combine(folder, "skybox"); var texture = new TextureCube(GraphicsDevice, 1024, false, SurfaceFormat.Color); byte[] data = null; LoadColors(Path.Combine(skyboxFolder, @"negX.png"), out data); texture.SetData(CubeMapFace.NegativeX, data); LoadColors(Path.Combine(skyboxFolder, @"negY.png"), out data); texture.SetData(CubeMapFace.NegativeY, data); LoadColors(Path.Combine(skyboxFolder, @"negZ.png"), out data); texture.SetData(CubeMapFace.NegativeZ, data); LoadColors(Path.Combine(skyboxFolder, @"posX.png"), out data); texture.SetData(CubeMapFace.PositiveX, data); LoadColors(Path.Combine(skyboxFolder, @"posY.png"), out data); texture.SetData(CubeMapFace.PositiveY, data); LoadColors(Path.Combine(skyboxFolder, @"posZ.png"), out data); texture.SetData(CubeMapFace.PositiveZ, data); _scene.Skybox = new Skybox(100) { Texture = texture }; _scene.Lights.Add(new DirectLight { Color = Color.White, Position = new Vector3(10000, 10000, -10000), Direction = new Vector3(0, -1, 0) }); _controller = new CameraInputController(_scene.Camera); }