/Rendering/ModelTests/ModelViewer.cs
C# | 137 lines | 93 code | 15 blank | 29 comment | 6 complexity | 3ddba7a827ebd0f84d8e1f5900db5ced MD5 | raw file
1using System.Collections.Generic; 2using Delta.ContentSystem.Rendering; 3using Delta.Engine; 4using Delta.InputSystem; 5using Delta.Rendering.Basics.Drawing; 6using Delta.Rendering.Basics.Fonts; 7using Delta.Rendering.Cameras; 8using Delta.Rendering.Models; 9using Delta.Utilities; 10using Delta.Utilities.Datatypes; 11using Delta.Utilities.Datatypes.Advanced; 12using NUnit.Framework; 13 14namespace Delta.Rendering.ModelTests 15{ 16 /// <summary> 17 /// Model viewer 18 /// </summary> 19 [Category("Visual")] 20 internal class ModelViewer 21 { 22 #region Start (Static) 23 /// <summary> 24 /// Start 25 /// </summary> 26 [Test] 27 public static void Start() 28 { 29 ModelViewer demo = new ModelViewer(); 30 31 // Start up the scene 32 Application.Start(delegate 33 { 34 demo.Run(); 35 }); 36 } 37 #endregion 38 39 #region Private 40 41 #region meshes (Private) 42 /// <summary> 43 /// The list of all meshes which are available by the content system. 44 /// </summary> 45 private readonly List<Mesh> meshes; 46 #endregion 47 48 #region currentMeshSelectionIndex (Private) 49 /// <summary> 50 /// The current index for the mesh (of the "meshes" list) that we draw 51 /// </summary> 52 private int currentMeshSelectionIndex; 53 #endregion 54 55 #region groundMesh (Private) 56 /// <summary> 57 /// Mesh for the ground for the rest of the models to stand on. 58 /// </summary> 59 private Mesh groundMesh = null; 60 #endregion 61 62 #region wasTouchPressed (Private) 63 /// <summary> 64 /// Was touch pressed 65 /// </summary> 66 private bool wasTouchPressed; 67 #endregion 68 69 #endregion 70 71 #region Constructors 72 /// <summary> 73 /// Create model viewer 74 /// </summary> 75 public ModelViewer() 76 { 77 meshes = new List<Mesh>(); 78 79 new LookAtCamera(new Vector(0, -5, 5)); 80 81 // Set the light direction (copied from the level data) 82 //Note: Added 100 to Z to make light come more from the top, looks 83 // better for most normal mapping surfaces! 84 Light.Direction = new Vector(-161.771f, -52.202f, 25 + 84.163f); 85 Light.Direction.Normalize(); 86 string[] contentNames = MeshData.GetAllContentNames(); 87 foreach (string name in contentNames) 88 { 89 meshes.Add(new Mesh(name)); 90 } 91 if (contentNames.Length == 0) 92 { 93 Log.Warning("There are no mesh files in the Content! " + 94 "Only adding default box now. Make sure to add some meshes " + 95 "to the Content!"); 96 meshes.Add(Mesh.CreateBox("", 5, 5, 5, MaterialData.Default)); 97 } 98 currentMeshSelectionIndex = 0; 99 } 100 #endregion 101 102 #region Run (Public) 103 /// <summary> 104 /// Run 105 /// </summary> 106 [Test] 107 public void Run() 108 { 109 if (Input.Keyboard.SpaceReleased || 110 wasTouchPressed && 111 Input.Touch.TouchIsPressed == false) 112 { 113 currentMeshSelectionIndex++; 114 currentMeshSelectionIndex %= meshes.Count; 115 } 116 wasTouchPressed = Input.Touch.TouchIsPressed; 117 118 Mesh currentMesh = meshes[currentMeshSelectionIndex]; 119 currentMesh.Draw(); 120 121 Font.DrawTopLeftInformation( 122 "Modelname: " + currentMesh.Name + "\n" + 123 "Material: " + currentMesh.Material); 124 125 // If no ground mesh was found, just display the grid 126 if (groundMesh == null) 127 { 128 Grid.Draw(); 129 } 130 else 131 { 132 groundMesh.Draw(); 133 } 134 } 135 #endregion 136 } 137}