/Rendering/ModelTests/ModelViewer.cs
C# | 137 lines | 93 code | 15 blank | 29 comment | 6 complexity | 3ddba7a827ebd0f84d8e1f5900db5ced MD5 | raw file
Possible License(s): Apache-2.0
- using System.Collections.Generic;
- using Delta.ContentSystem.Rendering;
- using Delta.Engine;
- using Delta.InputSystem;
- using Delta.Rendering.Basics.Drawing;
- using Delta.Rendering.Basics.Fonts;
- using Delta.Rendering.Cameras;
- using Delta.Rendering.Models;
- using Delta.Utilities;
- using Delta.Utilities.Datatypes;
- using Delta.Utilities.Datatypes.Advanced;
- using NUnit.Framework;
-
- namespace Delta.Rendering.ModelTests
- {
- /// <summary>
- /// Model viewer
- /// </summary>
- [Category("Visual")]
- internal class ModelViewer
- {
- #region Start (Static)
- /// <summary>
- /// Start
- /// </summary>
- [Test]
- public static void Start()
- {
- ModelViewer demo = new ModelViewer();
-
- // Start up the scene
- Application.Start(delegate
- {
- demo.Run();
- });
- }
- #endregion
-
- #region Private
-
- #region meshes (Private)
- /// <summary>
- /// The list of all meshes which are available by the content system.
- /// </summary>
- private readonly List<Mesh> meshes;
- #endregion
-
- #region currentMeshSelectionIndex (Private)
- /// <summary>
- /// The current index for the mesh (of the "meshes" list) that we draw
- /// </summary>
- private int currentMeshSelectionIndex;
- #endregion
-
- #region groundMesh (Private)
- /// <summary>
- /// Mesh for the ground for the rest of the models to stand on.
- /// </summary>
- private Mesh groundMesh = null;
- #endregion
-
- #region wasTouchPressed (Private)
- /// <summary>
- /// Was touch pressed
- /// </summary>
- private bool wasTouchPressed;
- #endregion
-
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create model viewer
- /// </summary>
- public ModelViewer()
- {
- meshes = new List<Mesh>();
-
- new LookAtCamera(new Vector(0, -5, 5));
-
- // Set the light direction (copied from the level data)
- //Note: Added 100 to Z to make light come more from the top, looks
- // better for most normal mapping surfaces!
- Light.Direction = new Vector(-161.771f, -52.202f, 25 + 84.163f);
- Light.Direction.Normalize();
- string[] contentNames = MeshData.GetAllContentNames();
- foreach (string name in contentNames)
- {
- meshes.Add(new Mesh(name));
- }
- if (contentNames.Length == 0)
- {
- Log.Warning("There are no mesh files in the Content! " +
- "Only adding default box now. Make sure to add some meshes " +
- "to the Content!");
- meshes.Add(Mesh.CreateBox("", 5, 5, 5, MaterialData.Default));
- }
- currentMeshSelectionIndex = 0;
- }
- #endregion
-
- #region Run (Public)
- /// <summary>
- /// Run
- /// </summary>
- [Test]
- public void Run()
- {
- if (Input.Keyboard.SpaceReleased ||
- wasTouchPressed &&
- Input.Touch.TouchIsPressed == false)
- {
- currentMeshSelectionIndex++;
- currentMeshSelectionIndex %= meshes.Count;
- }
- wasTouchPressed = Input.Touch.TouchIsPressed;
-
- Mesh currentMesh = meshes[currentMeshSelectionIndex];
- currentMesh.Draw();
-
- Font.DrawTopLeftInformation(
- "Modelname: " + currentMesh.Name + "\n" +
- "Material: " + currentMesh.Material);
-
- // If no ground mesh was found, just display the grid
- if (groundMesh == null)
- {
- Grid.Draw();
- }
- else
- {
- groundMesh.Draw();
- }
- }
- #endregion
- }
- }