Compare commits
1 Commits
triangle-r
...
master
Author | SHA1 | Date | |
---|---|---|---|
478e30b24b |
@ -4,6 +4,7 @@
|
|||||||
<option name="projectPerEditor">
|
<option name="projectPerEditor">
|
||||||
<map>
|
<map>
|
||||||
<entry key="GLTFViewer/BaseOpenTKControl.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
<entry key="GLTFViewer/BaseOpenTKControl.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
||||||
|
<entry key="GLTFViewer/Engine/Ui/Controls/BaseOpenTKControl.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
||||||
<entry key="GLTFViewer/Engine/Ui/Controls/BasePropertyViewerControl.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
<entry key="GLTFViewer/Engine/Ui/Controls/BasePropertyViewerControl.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
||||||
<entry key="GLTFViewer/Engine/Ui/Controls/BaseSceneTreeControl.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
<entry key="GLTFViewer/Engine/Ui/Controls/BaseSceneTreeControl.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
||||||
<entry key="GLTFViewer/Engine/Ui/Controls/MainUI.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
<entry key="GLTFViewer/Engine/Ui/Controls/MainUI.axaml" value="GLTFViewer/GLTFViewer.csproj" />
|
||||||
|
@ -15,6 +15,7 @@ A simple application to load GLTF scenes and render the model(s) in a lit scene
|
|||||||
|
|
||||||
## Development Status
|
## Development Status
|
||||||
- 01/15/2025 Update 1: Successfully have Avalonia project set up with a BaseOpenTK control rendering the OpenTK context. Also have a Renerer class to seperate out the rendering code from the control, but it's empty for now. There is also some boilerplate UI for the inspector, but its only visual and will need to be filled out.
|
- 01/15/2025 Update 1: Successfully have Avalonia project set up with a BaseOpenTK control rendering the OpenTK context. Also have a Renerer class to seperate out the rendering code from the control, but it's empty for now. There is also some boilerplate UI for the inspector, but its only visual and will need to be filled out.
|
||||||
|
- 01/15/2025 Update 2: Have some basic UI and Node structure. Now deciding how best to load models, render them, and handling scenes.
|
||||||
|
|
||||||
## Development Environment
|
## Development Environment
|
||||||
- OS: Linux (NixOS)
|
- OS: Linux (NixOS)
|
||||||
|
8
GLTFViewer/GLTFViewer/Engine/Nodes/Mesh.cs
Normal file
8
GLTFViewer/GLTFViewer/Engine/Nodes/Mesh.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace GLTFViewer.Engine;
|
||||||
|
|
||||||
|
public class Mesh : Node
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -6,22 +6,32 @@ namespace GLTFViewer.Engine;
|
|||||||
|
|
||||||
public class Node
|
public class Node
|
||||||
{
|
{
|
||||||
public string Name { get; }
|
public string Name { get; set; } = "Node";
|
||||||
public ObservableCollection<Node> Children { get; }
|
public ObservableCollection<Node> Children { get; } = [];
|
||||||
public ObservableCollection<NodeProperty> Properties { get; }
|
public ObservableCollection<NodeProperty> Properties { get; } = [];
|
||||||
|
|
||||||
public Node(string name)
|
public virtual void Update()
|
||||||
{
|
{
|
||||||
Name = name;
|
foreach (var node in Children)
|
||||||
Children = new ObservableCollection<Node>();
|
{
|
||||||
Properties = new ObservableCollection<NodeProperty>();
|
node.Update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node(string name, ObservableCollection<Node> children)
|
public virtual void EnterScene()
|
||||||
{
|
{
|
||||||
Name = name;
|
foreach (var node in Children)
|
||||||
Children = children;
|
{
|
||||||
Properties = new ObservableCollection<NodeProperty>();
|
node.EnterScene();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void ExitScene()
|
||||||
|
{
|
||||||
|
foreach (var node in Children)
|
||||||
|
{
|
||||||
|
node.ExitScene();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddChild(Node child)
|
public void AddChild(Node child)
|
@ -8,123 +8,21 @@ namespace GLTFViewer.Rendering;
|
|||||||
|
|
||||||
public class Renderer
|
public class Renderer
|
||||||
{
|
{
|
||||||
private int _vao;
|
|
||||||
private int _vbo;
|
|
||||||
private int _shaderProgram;
|
|
||||||
|
|
||||||
public void Initialize(GlInterface gl)
|
public void Initialize(GlInterface gl)
|
||||||
{
|
{
|
||||||
GLLoader.LoadBindings(new AvaloniaBindingsContext(gl));
|
GLLoader.LoadBindings(new AvaloniaBindingsContext(gl));
|
||||||
GL.ClearColor(1, 1, 1, 1);
|
GL.ClearColor(1,1,1,1);
|
||||||
|
|
||||||
// Vertex data for a triangle
|
|
||||||
float[] vertices = {
|
|
||||||
0.0f, 0.5f, 0.0f, // Top vertex
|
|
||||||
-0.5f, -0.5f, 0.0f, // Bottom left vertex
|
|
||||||
0.5f, -0.5f, 0.0f // Bottom right vertex
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create and bind the VAO
|
|
||||||
_vao = GL.GenVertexArray();
|
|
||||||
GL.BindVertexArray(_vao);
|
|
||||||
|
|
||||||
// Create and bind the VBO
|
|
||||||
_vbo = GL.GenBuffer();
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo);
|
|
||||||
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsage.StaticDraw);
|
|
||||||
|
|
||||||
// Vertex shader source code
|
|
||||||
string vertexShaderSource = @"
|
|
||||||
#version 330 core
|
|
||||||
layout(location = 0) in vec3 aPos;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vec4(aPos, 1.0);
|
|
||||||
}";
|
|
||||||
|
|
||||||
// Fragment shader source code
|
|
||||||
string fragmentShaderSource = @"
|
|
||||||
#version 330 core
|
|
||||||
out vec4 FragColor;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
FragColor = vec4(0.0, 0.0, 1.0, 1.0); // Blue color
|
|
||||||
}";
|
|
||||||
|
|
||||||
// Compile vertex shader
|
|
||||||
int vertexShader = GL.CreateShader(ShaderType.VertexShader);
|
|
||||||
GL.ShaderSource(vertexShader, vertexShaderSource);
|
|
||||||
GL.CompileShader(vertexShader);
|
|
||||||
CheckShaderCompileStatus(vertexShader);
|
|
||||||
|
|
||||||
// Compile fragment shader
|
|
||||||
int fragmentShader = GL.CreateShader(ShaderType.FragmentShader);
|
|
||||||
GL.ShaderSource(fragmentShader, fragmentShaderSource);
|
|
||||||
GL.CompileShader(fragmentShader);
|
|
||||||
CheckShaderCompileStatus(fragmentShader);
|
|
||||||
|
|
||||||
// Link shaders into a program
|
|
||||||
_shaderProgram = GL.CreateProgram();
|
|
||||||
GL.AttachShader(_shaderProgram, vertexShader);
|
|
||||||
GL.AttachShader(_shaderProgram, fragmentShader);
|
|
||||||
GL.LinkProgram(_shaderProgram);
|
|
||||||
CheckProgramLinkStatus(_shaderProgram);
|
|
||||||
|
|
||||||
// Clean up shaders as they are no longer needed
|
|
||||||
GL.DeleteShader(vertexShader);
|
|
||||||
GL.DeleteShader(fragmentShader);
|
|
||||||
|
|
||||||
// Specify the layout of the vertex data
|
|
||||||
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
|
|
||||||
GL.EnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
// Unbind the VAO
|
|
||||||
GL.BindVertexArray(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(GlInterface gl, int width, int height, int fbo)
|
public void Render(GlInterface gl, int width, int height, int fbo)
|
||||||
{
|
{
|
||||||
GL.Viewport(0, 0, width, height);
|
GL.Viewport(0, 0, width, height);
|
||||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
|
|
||||||
// Use the shader program
|
|
||||||
GL.UseProgram(_shaderProgram);
|
|
||||||
|
|
||||||
// Bind the VAO
|
|
||||||
GL.BindVertexArray(_vao);
|
|
||||||
|
|
||||||
// Draw the triangle
|
|
||||||
GL.DrawArrays(PrimitiveType.Triangles, 0, 3);
|
|
||||||
|
|
||||||
// Unbind the VAO
|
|
||||||
GL.BindVertexArray(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deinitialize(GlInterface gl)
|
public void Deinitialize(GlInterface gl)
|
||||||
{
|
{
|
||||||
GL.DeleteVertexArray(_vao);
|
|
||||||
GL.DeleteBuffer(_vbo);
|
|
||||||
GL.DeleteProgram(_shaderProgram);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckShaderCompileStatus(int shader)
|
|
||||||
{
|
|
||||||
GL.GetShaderi(shader, ShaderParameterName.CompileStatus, out int status);
|
|
||||||
if (status == (int)All.False)
|
|
||||||
{
|
|
||||||
GL.GetShaderInfoLog(shader, out var infoLog);
|
|
||||||
throw new Exception($"Shader compilation failed: {infoLog}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckProgramLinkStatus(int program)
|
|
||||||
{
|
|
||||||
GL.GetProgrami(program, ProgramProperty.LinkStatus, out int status);
|
|
||||||
if (status == (int)All.False)
|
|
||||||
{
|
|
||||||
GL.GetProgramInfoLog(program, out var infoLog);
|
|
||||||
throw new Exception($"Program linking failed: {infoLog}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AvaloniaBindingsContext : IBindingsContext
|
private class AvaloniaBindingsContext : IBindingsContext
|
||||||
@ -141,4 +39,5 @@ public class Renderer
|
|||||||
return _gl.GetProcAddress(procName);
|
return _gl.GetProcAddress(procName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,10 +6,8 @@ namespace GLTFViewer.Engine.Ui;
|
|||||||
|
|
||||||
public class SceneTree
|
public class SceneTree
|
||||||
{
|
{
|
||||||
public Node Root { get; } = new Node("root");
|
|
||||||
|
|
||||||
private TreeView _sceneTreeView;
|
private TreeView _sceneTreeView;
|
||||||
private ObservableCollection<Node> _nodes;
|
private ObservableCollection<Node> _nodes = [];
|
||||||
|
|
||||||
public SceneTree(TreeView sceneTreeView)
|
public SceneTree(TreeView sceneTreeView)
|
||||||
{
|
{
|
||||||
@ -20,15 +18,6 @@ public class SceneTree
|
|||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
Root.AddProperty(new NodeProperty<string>("TestPropertyString", "TestValue"));
|
|
||||||
Root.AddProperty(new NodeProperty<int>("TestPropertyInt", 42));
|
|
||||||
|
|
||||||
|
|
||||||
_nodes = new ObservableCollection<Node>()
|
|
||||||
{
|
|
||||||
Root
|
|
||||||
};
|
|
||||||
|
|
||||||
_sceneTreeView.ItemsSource = _nodes;
|
_sceneTreeView.ItemsSource = _nodes;
|
||||||
_sceneTreeView.ItemTemplate = new FuncTreeDataTemplate<Node>(
|
_sceneTreeView.ItemTemplate = new FuncTreeDataTemplate<Node>(
|
||||||
(node, _) =>
|
(node, _) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user