Created editor project and moved Editor there

This commit is contained in:
Simon Lübeß
2021-09-16 13:19:25 +02:00
parent f6b073557a
commit 0079b80b1c
11 changed files with 279 additions and 10 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
FileVersion = 1 FileVersion = 1
Projects = {Sandbox = {Path = "Sandbox"}, GlitchyEngine = {Path = "GlitchyEngine"}, GlitchLog = {Path = "GlitchLog"}, DirectX = {Path = "GlitchyEngine/vendor/directx/DirectX"}, ImGui = {Path = "GlitchyEngine/vendor/imgui-beef/ImGui"}, ImGuiImplWin32 = {Path = "GlitchyEngine/vendor/imgui-beef/ImGuiImplWin32"}, ImGuiImplDX11 = {Path = "GlitchyEngine/vendor/imgui-beef/ImGuiImplDX11"}, DirectXTK = {Path = "GlitchyEngine/vendor/DirectXTK/DirectXTK-beef"}, LodePng = {Path = "vendor/lodepng-beef/lodepng-beef"}, FreeType = {Path = "GlitchyEngine/vendor/freetype"}, cgltf-beef = {Path = "GlitchyEngine/vendor/gltf/cgltf-beef"}} Projects = {Sandbox = {Path = "Sandbox"}, GlitchyEngine = {Path = "GlitchyEngine"}, GlitchLog = {Path = "GlitchLog"}, DirectX = {Path = "GlitchyEngine/vendor/directx/DirectX"}, ImGui = {Path = "GlitchyEngine/vendor/imgui-beef/ImGui"}, ImGuiImplWin32 = {Path = "GlitchyEngine/vendor/imgui-beef/ImGuiImplWin32"}, ImGuiImplDX11 = {Path = "GlitchyEngine/vendor/imgui-beef/ImGuiImplDX11"}, DirectXTK = {Path = "GlitchyEngine/vendor/DirectXTK/DirectXTK-beef"}, LodePng = {Path = "vendor/lodepng-beef/lodepng-beef"}, FreeType = {Path = "GlitchyEngine/vendor/freetype"}, cgltf-beef = {Path = "GlitchyEngine/vendor/gltf/cgltf-beef"}, GlitchyEditor = {Path = "GlitchyEditor"}}
[Workspace] [Workspace]
StartupProject = "Sandbox" StartupProject = "GlitchyEditor"
[Configs.Debug.Win64] [Configs.Debug.Win64]
AllocType = "CRT" AllocType = "CRT"
+10
View File
@@ -0,0 +1,10 @@
FileVersion = 1
Dependencies = {corlib = "*", GlitchLog = "*", GlitchyEngine = "*"}
[Project]
Name = "GlitchyEditor"
TargetType = "BeefGUIApplication"
StartupObject = "GlitchyEngine.Program"
[Configs.Debug.Win64]
CLibType = "DynamicDebug"
@@ -0,0 +1,31 @@
cbuffer Constants : register(b0)
{
float4x4 ViewProjection;
float4 Color;
};
struct VS_Input
{
float4 Position : POSITION;
};
struct PS_Input
{
float4 Position : SV_Position;
};
PS_Input VS(VS_Input input)
{
PS_Input output;
output.Position = mul(ViewProjection, input.Position);
return output;
}
float4 PS(PS_Input input) : SV_Target0
{
return Color;
}
#effect[VS=VS, PS=PS]
@@ -0,0 +1,37 @@
Texture2D Texture : register(t0);
SamplerState Sampler : register(s0);
struct VS_Input
{
float2 Position : POSITION;
float4x4 Tranform : TRANSFORM;
float4 Color : COLOR;
float4 UVTransform : TEXCOORD;
};
struct PS_Input
{
float4 Position : SV_Position;
float2 TexCoord : TEXCOORD0;
float4 Color : COLOR;
};
PS_Input VS(VS_Input input)
{
PS_Input output;
output.Position = mul(float4(input.Position, 0.0f, 1.0f), input.Tranform);
output.TexCoord = input.UVTransform.xy + input.UVTransform.zw * input.Position;
output.Color = input.Color;
return output;
}
float4 PS(PS_Input input) : SV_Target0
{
float4 color = input.Color * Texture.Sample(Sampler, input.TexCoord);
return color;
}
#effect[VS=VS, PS=PS]
@@ -0,0 +1,84 @@
cbuffer SceneConstants
{
float4x4 ViewProjection = float4x4(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
}
cbuffer ObjectConstants
{
float4x4 Transform;
}
cbuffer Constants
{
float4 BaseColor;
float3 LightDir;
}
cbuffer SkinningMatrices
{
matrix SkinningMatrices[255];
float3x3 InvTransSkinningMatrices[255];
}
struct VS_IN
{
float3 Position : POSITION;
float3 Normal : NORMAL;
uint4 JointIndices : JOINTS_0;
float4 JointWeights : WEIGHTS_0;
};
struct PS_IN
{
float4 Position : SV_POSITION;
float3 Normal : NORMAL;
};
PS_IN VS(VS_IN input)
{
PS_IN output;
// Unanimated position in modelspace
float4 positionRaw = float4(input.Position, 1);
// Calculate animated position in modelspace
float4 position =
mul(SkinningMatrices[input.JointIndices.x], positionRaw) * input.JointWeights.x +
mul(SkinningMatrices[input.JointIndices.y], positionRaw) * input.JointWeights.y +
mul(SkinningMatrices[input.JointIndices.z], positionRaw) * input.JointWeights.z +
mul(SkinningMatrices[input.JointIndices.w], positionRaw) * input.JointWeights.w;
float3 normal =
mul(InvTransSkinningMatrices[input.JointIndices.x], input.Normal) * input.JointWeights.x +
mul(InvTransSkinningMatrices[input.JointIndices.y], input.Normal) * input.JointWeights.y +
mul(InvTransSkinningMatrices[input.JointIndices.z], input.Normal) * input.JointWeights.z +
mul(InvTransSkinningMatrices[input.JointIndices.w], input.Normal) * input.JointWeights.w;
//position = saturate(position - 1000) + positionRaw;
//float4 position = mul(SkinningMatrices[input.JointIndices.x], positionRaw);
float4 worldPosition = mul(Transform, position);
output.Position = mul(ViewProjection, worldPosition);
output.Normal = mul((float3x3)Transform, normal);
return output;
}
float4 PS(PS_IN input) : SV_TARGET
{
input.Normal = normalize(input.Normal);
float shading = dot(LightDir, input.Normal);
//float shading = dot(LightDir, LightDir) + 1;
shading = clamp(shading, 0.0f, 1.0f);
return BaseColor * shading;
}
#effect[VS=VS,PS=PS]
@@ -3,7 +3,7 @@ using GlitchyEngine.World;
using System; using System;
using GlitchyEngine.Math; using GlitchyEngine.Math;
namespace GlitchyEngine.Editor namespace GlitchyEditor.EditWindows
{ {
class ComponentEditWindow class ComponentEditWindow
{ {
@@ -3,10 +3,11 @@ using GlitchyEngine.World;
using ImGui; using ImGui;
using System; using System;
using System.Collections; using System.Collections;
using GlitchyEngine;
namespace GlitchyEngine.Editor namespace GlitchyEditor.EditWindows
{ {
using internal GlitchyEngine.Editor; using internal GlitchyEditor;
/// A window for viewing and editing the scene hierarchy /// A window for viewing and editing the scene hierarchy
class EntityHierarchyWindow class EntityHierarchyWindow
@@ -3,8 +3,9 @@ using ImGui;
using System; using System;
using System.Collections; using System.Collections;
using GlitchyEngine.Collections; using GlitchyEngine.Collections;
using GlitchyEditor.EditWindows;
namespace GlitchyEngine.Editor namespace GlitchyEditor
{ {
class Editor class Editor
{ {
+19
View File
@@ -0,0 +1,19 @@
using System;
using GlitchyEngine;
namespace GlitchyEditor
{
class SandboxApp : Application
{
public this()
{
PushLayer(new EditorLayer());
}
[Export, LinkName("CreateApplication")]
public static Application CreateApplication()
{
return new SandboxApp();
}
}
}
+90
View File
@@ -0,0 +1,90 @@
using GlitchyEditor.EditWindows;
using GlitchyEngine;
using GlitchyEngine.Events;
using GlitchyEngine.ImGui;
using GlitchyEngine.Renderer;
using GlitchyEngine.World;
using ImGui;
namespace GlitchyEditor
{
class EditorLayer : Layer
{
RasterizerState _rasterizerState ~ _?.ReleaseRef();
RasterizerState _rasterizerStateClockWise ~ _?.ReleaseRef();
GraphicsContext _context ~ _?.ReleaseRef();
DepthStencilTarget _depthTarget ~ _?.ReleaseRef();
BlendState _alphaBlendState ~ _?.ReleaseRef();
BlendState _opaqueBlendState ~ _?.ReleaseRef();
EcsWorld _world = new EcsWorld() ~ delete _;
Editor _editor = new Editor(_world) ~ delete _;
public this() : base("Example")
{
Application.Get().Window.IsVSync = false;
InitGraphics();
InitEcs();
}
private void InitGraphics()
{
_context = Application.Get().Window.Context..AddRef();
_depthTarget = new DepthStencilTarget(_context, _context.SwapChain.Width, _context.SwapChain.Height);
RasterizerStateDescription rsDesc = .(.Solid, .Back, true);
_rasterizerState = new RasterizerState(_context, rsDesc);
rsDesc.FrontCounterClockwise = false;
_rasterizerStateClockWise = new RasterizerState(_context, rsDesc);
BlendStateDescription blendDesc = .();
blendDesc.RenderTarget[0] = .(true, .SourceAlpha, .InvertedSourceAlpha, .Add, .SourceAlpha, .InvertedSourceAlpha, .Add, .All);
_alphaBlendState = new BlendState(_context, blendDesc);
_opaqueBlendState = new BlendState(_context, .Default);
}
private void InitEcs()
{
_world.Register<DebugNameComponent>();
_world.Register<TransformComponent>();
_world.Register<ParentComponent>();
_world.Register<MeshComponent>();
_world.Register<MeshRendererComponent>();
_world.Register<SkinnedMeshRendererComponent>();
_world.Register<CameraComponent>();
_world.Register<AnimationComponent>();
}
public override void Update(GameTime gameTime)
{
RenderCommand.Clear(null, .(0.2f, 0.2f, 0.2f));
_depthTarget.Clear(1.0f, 0, .Depth);
_context.SetRenderTarget(null);
_depthTarget.Bind();
_context.BindRenderTargets();
_context.SetViewport(_context.SwapChain.BackbufferViewport);
}
public override void OnEvent(Event event)
{
EventDispatcher dispatcher = EventDispatcher(event);
dispatcher.Dispatch<ImGuiRenderEvent>(scope (e) => OnImGuiRender(e));
}
private bool OnImGuiRender(ImGuiRenderEvent event)
{
_editor.Update();
return false;
}
}
}
-4
View File
@@ -11,7 +11,6 @@ using GlitchyEngine.World;
using System.Collections; using System.Collections;
using GlitchyEngine.Content; using GlitchyEngine.Content;
using GlitchyEngine.Renderer.Animation; using GlitchyEngine.Renderer.Animation;
using GlitchyEngine.Editor;
namespace Sandbox namespace Sandbox
{ {
@@ -74,8 +73,6 @@ namespace Sandbox
EcsWorld _world = new EcsWorld() ~ delete _; EcsWorld _world = new EcsWorld() ~ delete _;
Editor _editor = new Editor(_world) ~ delete _;
// OrthographicCameraController _cameraController ~ delete _; // OrthographicCameraController _cameraController ~ delete _;
PerspectiveCameraController _cameraController ~ delete _; PerspectiveCameraController _cameraController ~ delete _;
@@ -544,7 +541,6 @@ namespace Sandbox
private bool OnImGuiRender(ImGuiRenderEvent e) private bool OnImGuiRender(ImGuiRenderEvent e)
{ {
_editor.Update();
/* /*
ImGui.Begin("Test"); ImGui.Begin("Test");