using Assimp; using LearnOpenTK.Common; using OpenTK.Mathematics; namespace TheLabs; public class LevelLoader { private Shader _shader; private Texture _texture; private Texture _normalTexture; private Material _material; private Lighting _lighting; public LevelLoader(Shader shader, Texture texture, Texture normalTexture, Material material, Lighting lighting) { _shader = shader; _texture = texture; _normalTexture = normalTexture; _material = material; _lighting = lighting; } public void LoadLevel(string filepath, SceneNode rootenode, List colliders) { Mesh _mesh = ShapeFactory.CreateTexturedCube(); RenderObject renderObject = new RenderObject(_mesh, _shader, _texture, _material, _lighting); renderObject.NormalMap = _normalTexture; renderObject.UseTexture = true; if (!File.Exists(filepath)) { throw new FileNotFoundException("The specified level file was not found.", filepath); } string[] lines = File.ReadAllLines(filepath); float spacing = 1.0f; for (int z = 0; z < lines.Length; z++) { string line = lines[z]; for (int x = 0; x < line.Length; x++) { char tile = line[x]; SceneNode floorNode = new SceneNode(renderObject); floorNode.Position = new Vector3(x * spacing, -0.5f, z * spacing); floorNode.Scale = new Vector3(1.0f, 0.1f, 1.0f); rootenode.AddChild(floorNode); if (tile == '1') { BoxCollider wallCollider = new BoxCollider(new Vector3(x, 0, z), new Vector3(1, 1, 1)); colliders.Add(wallCollider); SceneNode wallNode = new SceneNode(renderObject); wallNode.Position = new Vector3(x * spacing, 0.0f, z * spacing); rootenode.AddChild(wallNode); } } } } }