Compare commits

..

40 Commits

Author SHA1 Message Date
66a3171ccd add TextComponent 2025-10-31 00:53:18 +08:00
3272797873 添加 文本渲染 2025-10-30 23:32:20 +08:00
875a77ff5b add project work 2025-10-28 13:48:36 +08:00
9e0a2963e8 重新封装二进制文件读取 2025-10-27 12:35:51 +08:00
c5a88ac5e3 add c# debugging support 2025-10-26 16:35:02 +08:00
486b423343 add pausing and stepping 2025-10-26 15:49:45 +08:00
c7acb71355 添加文件监控 filewatch 2025-10-26 14:49:48 +08:00
477d6b9ffe add Assemble reloading 2025-10-26 13:40:19 +08:00
e8dec2e2d3 add FindEntityByName function 2025-10-26 13:12:04 +08:00
9c45444354 添加assimp库,修改mono的运行时的目录 2025-10-26 10:59:44 +08:00
1bdb1d240e 简单添加ScriptComponent序列化功能 2025-07-18 14:19:10 +08:00
e0bfdd9c4e 重构项目src框架,添加c#脚本功能 2025-07-13 00:38:11 +08:00
02c7e0fcf9 add SpriteRendererComponent's 'TexturePath' and 'TilingFactor' to serialize 2025-07-09 17:58:56 +08:00
dd0e9b678c if rgba.a==0 discard 2025-07-09 17:56:51 +08:00
d08285b62b add mouse right click to add multiple entity with some component 2025-07-09 17:55:57 +08:00
8436331a7a delete xhash.h 2025-07-09 17:54:27 +08:00
6d76832c1d add GetPath() and change operator== 2025-07-09 17:53:27 +08:00
aff8d1531c add return 2025-07-09 17:52:29 +08:00
365134ce77 simple change "relativePath" variable location 2025-07-09 17:51:42 +08:00
448c162705 simple debug info 2025-07-09 17:48:31 +08:00
71a5a994ff add selected entity outline rendering 2025-07-09 17:47:56 +08:00
7ec76e23d5 change SDLkey to KeyCode 2025-07-09 17:46:50 +08:00
b1afcc4166 add commandline to load scene file 2025-07-09 17:44:50 +08:00
77f3945ae9 change collider draw impl 2025-07-09 17:43:57 +08:00
f2422abfeb add GetPath() 2025-07-09 17:42:20 +08:00
7c5511aa43 add ApplicationSpecification 2025-07-09 17:41:24 +08:00
9a1700ebf8 change self Key impl 2025-07-09 17:39:36 +08:00
c17527e3b9 add ApplicationSpecification 2025-07-09 17:37:38 +08:00
37c17bdb5c 使用lambda函数和模板函数重构Copy组件功能 2025-07-06 12:58:48 +08:00
fadb73243d use KeyCode MouseButton replace int 2025-07-06 12:57:00 +08:00
ab4ca6285e use KeyCode MouseButton replace int 2025-07-06 12:56:22 +08:00
52463322dd 简单解决距离小于1 缩放bug 2025-07-06 12:53:53 +08:00
0a24a2f3c7 add new clas 2025-07-06 12:51:23 +08:00
9447453e47 修复可视化collider功能在旋转的模型中出现偏移bug 2025-06-25 12:18:37 +08:00
fdb1ada6cd 添加简单物理模拟模式功能 2025-06-24 22:08:22 +08:00
a32ce57503 添加组件圆,添加可视化碰撞器渲染 2025-06-24 17:24:56 +08:00
0032814ed6 修复三维控件和模型出现偏移问题 2025-06-22 21:54:24 +08:00
aecaf86dc0 添加简单场景ctrl+s保存功能 2025-06-20 21:07:40 +08:00
ea59c82f35 添加场景在运行时会临时复制一个场景功能,添加克隆实体功能 2025-06-18 20:59:26 +08:00
99782ea11b 简单添加UUID生成功能 2025-06-18 20:57:50 +08:00
1448 changed files with 371938 additions and 837 deletions

3
.gitignore vendored
View File

@ -10,5 +10,8 @@ bin-int/
cmake-build-debug/ cmake-build-debug/
cmake-build-release/ cmake-build-release/
# directories
build/
# Files # Files
*.user *.user

3
.gitmodules vendored
View File

@ -26,3 +26,6 @@
[submodule "Hazel/vendor/box2d"] [submodule "Hazel/vendor/box2d"]
path = Hazel/vendor/box2d path = Hazel/vendor/box2d
url = https://github.com/erincatto/box2d.git url = https://github.com/erincatto/box2d.git
[submodule "Hazel/vendor/freetype"]
path = Hazel/vendor/freetype
url = https://github.com/freetype/freetype.git

View File

@ -1,10 +1,9 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(Sandbox) # 占位符 project(Editor-Sandbox) # 占位符
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@ -15,16 +14,12 @@ if(MSVC)
endif () endif ()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
file(GLOB ASSETS Sandbox/assets/*)
file(COPY ${ASSETS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)
file(GLOB RESOURCES Sandbox/Resources/*)
file(COPY ${RESOURCES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources)
add_subdirectory(Hazel) add_subdirectory(Hazel)
add_subdirectory(Sandbox) add_subdirectory(Editor)
add_subdirectory(Sandbox)
add_subdirectory(Hazel-ScriptCore)
add_subdirectory(Editor/SandboxProject)
#add_subdirectory(Sandbox)

37
Editor/CMakeLists.txt Normal file
View File

@ -0,0 +1,37 @@
# Hazel-Editor
set(PROJECT_NAME "Editor")
project(${PROJECT_NAME})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# set MSVC output directory
if(MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif ()
file(GLOB ASSETS assets/*)
file(COPY ${ASSETS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)
file(GLOB RESOURCES Resources/*)
file(COPY ${RESOURCES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources)
# TODO: remove it later
file(GLOB MONO_DEP lib/mono)
file(COPY ${MONO_DEP} DESTINATION ${CMAKE_BINARY_DIR}/bin/Resources)
file(GLOB_RECURSE SOURCES
src/**.cpp
)
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE Hazel-shared)
# add Hazel-ScriptCore.dll dependence to auto build
#add_dependencies(${PROJECT_NAME} Hazel-ScriptCore)

View File

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 119 B

After

Width:  |  Height:  |  Size: 119 B

View File

Before

Width:  |  Height:  |  Size: 357 B

After

Width:  |  Height:  |  Size: 357 B

View File

Before

Width:  |  Height:  |  Size: 667 B

After

Width:  |  Height:  |  Size: 667 B

View File

Before

Width:  |  Height:  |  Size: 438 B

After

Width:  |  Height:  |  Size: 438 B

View File

Before

Width:  |  Height:  |  Size: 115 B

After

Width:  |  Height:  |  Size: 115 B

View File

@ -0,0 +1,29 @@
set(CSPROJECT_NAME Sandbox)
# set MSVC output directory
if(MSVC)
set(SCRIPT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin/Resources/Scripts")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${SCRIPT_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${SCRIPT_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${SCRIPT_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${SCRIPT_OUTPUT_DIR})
endif ()
enable_language(CSharp)
project(${CSPROJECT_NAME} LANGUAGES CSharp)
file(GLOB_RECURSE CS_SOURCES
Source/**
Properties/
)
add_library(${CSPROJECT_NAME} SHARED ${CS_SOURCES})
add_dependencies(${CSPROJECT_NAME} Hazel-ScriptCore)
set_property(TARGET ${CSPROJECT_NAME} PROPERTY VS_DOTNET_REFERENCE_Hazel-ScriptCore
Hazel-ScriptCore
)
target_link_libraries(${CSPROJECT_NAME} PRIVATE Hazel-ScriptCore)

View File

@ -0,0 +1,57 @@
using System;
using Hazel;
namespace Sandbox {
public class Camera : Entity
{
// private TransformComponent m_Transform;
// private RigidBody2DComponent m_Rigidbody;
public float MoveSpeed;
public float DistanceFromPlayer = 5;
private Entity m_Player;
void OnCreate()
{
Console.WriteLine($"Camera.OnCreate - {ID}");
m_Player = FindEntityByName("Player");
}
void OnUpdate(float ts)
{
if(m_Player != null)
{
Translation = new Vector3(m_Player.Translation.XY, DistanceFromPlayer);
}
// Console.WriteLine($"Player.OnUpdate: {ts}");
float speed = MoveSpeed;
Vector3 velocity = Vector3.Zero;
if(Input.IsKeyDown(KeyCode.UP))
velocity.Y = 1.0f;
else if(Input.IsKeyDown(KeyCode.DOWN))
velocity.Y = -1.0f;
if(Input.IsKeyDown(KeyCode.LEFT))
velocity.X = -1.0f;
else if(Input.IsKeyDown(KeyCode.RIGHT))
velocity.X = 1.0f;
// m_Rigidbody.ApplyLinearImpulse(velocity.XY * speed, Vector2.Zero, true);
velocity *= speed;
Vector3 translation = Translation;
translation += velocity * ts;
Translation = translation;
}
}
}

View File

@ -0,0 +1,55 @@
using System;
using Hazel;
namespace Sandbox {
public class Player : Entity
{
private TransformComponent m_Transform;
private RigidBody2DComponent m_Rigidbody;
public float Force;
public float Time;
void OnCreate()
{
Console.WriteLine($"Player.OnCreate - {ID}");
m_Transform = GetComponent<TransformComponent>();
m_Rigidbody = GetComponent<RigidBody2DComponent>();
}
void OnUpdate(float ts)
{
Time += ts;
float speed = Force;
Vector3 velocity = Vector3.Zero;
if(Input.IsKeyDown(KeyCode.W))
velocity.Y = 1.0f;
else if(Input.IsKeyDown(KeyCode.S))
velocity.Y = -1.0f;
if(Input.IsKeyDown(KeyCode.A))
velocity.X = -1.0f;
else if(Input.IsKeyDown(KeyCode.D))
velocity.X = 1.0f;
Entity cameraEntity = FindEntityByName("Camera");
if(cameraEntity != null)
{
Camera camera = cameraEntity.As<Camera>();
if(Input.IsKeyDown(KeyCode.Q))
camera.DistanceFromPlayer -= speed * 2.0f * ts;
else if(Input.IsKeyDown(KeyCode.E))
camera.DistanceFromPlayer += speed * 2.0f * ts;
}
m_Rigidbody.ApplyLinearImpulseToCenter(velocity.XY * speed, true);
}
}
}

View File

@ -0,0 +1,72 @@
// Basic circle Texture Shader
#type vertex
#version 450 core
layout(location = 0) in vec3 a_WorldPosition;
layout(location = 1) in vec3 a_LocalPosition;
layout(location = 2) in vec4 a_Color;
layout(location = 3) in float a_Thickness;
layout(location = 4) in float a_Fade;
layout(location = 5) in int a_EntityID;
layout(std140, binding = 0) uniform Camera
{
mat4 u_ViewProjection;
};
struct VertexOutput
{
vec3 LocalPosition;
vec4 Color;
float Thickness;
float Fade;
};
layout (location = 0) out VertexOutput Output;
layout (location = 4) out flat int v_EntityID;
void main()
{
Output.LocalPosition = a_LocalPosition;
Output.Color = a_Color;
Output.Thickness = a_Thickness;
Output.Fade = a_Fade;
v_EntityID = a_EntityID;
gl_Position = u_ViewProjection * vec4(a_WorldPosition, 1.0);
}
#type fragment
#version 450 core
layout(location = 0) out vec4 o_Color;
layout(location = 1) out int o_EntityID;
struct VertexOutput
{
vec3 LocalPosition;
vec4 Color;
float Thickness;
float Fade;
};
layout (location = 0) in VertexOutput Input;
layout (location = 4) in flat int v_EntityID;
void main()
{
float distance = 1.0f - length(Input.LocalPosition);
float circle = smoothstep(0.0f, Input.Fade, distance);
circle *= smoothstep(Input.Thickness + Input.Fade, Input.Thickness, distance);
if(circle == 0.0f)
discard;
o_Color = Input.Color;
o_Color.a *= circle;
o_EntityID = v_EntityID;
}

View File

@ -0,0 +1,49 @@
// Basic Line Texture Shader
#type vertex
#version 450 core
layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec4 a_Color;
layout(location = 2) in int a_EntityID;
layout(std140, binding = 0) uniform Camera
{
mat4 u_ViewProjection;
};
struct VertexOutput
{
vec4 Color;
};
layout (location = 0) out VertexOutput Output;
layout (location = 1) out flat int v_EntityID;
void main()
{
Output.Color = a_Color;
v_EntityID = a_EntityID;
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
}
#type fragment
#version 450 core
layout(location = 0) out vec4 o_Color;
layout(location = 1) out int o_EntityID;
struct VertexOutput
{
vec4 Color;
};
layout (location = 0) in VertexOutput Input;
layout (location = 1) in flat int v_EntityID;
void main()
{
o_Color = Input.Color;
o_EntityID = v_EntityID;
}

View File

@ -1,4 +1,4 @@
// Basic Texture Shader // Basic quad Texture Shader
#type vertex #type vertex
#version 450 core #version 450 core
@ -60,5 +60,8 @@ void main()
{ {
o_Color = texture(u_Textures[int(v_TexIndex)], Input.TexCoord * Input.TilingFactor) * Input.Color; o_Color = texture(u_Textures[int(v_TexIndex)], Input.TexCoord * Input.TilingFactor) * Input.Color;
if(o_Color.a == 0.0f)
discard;
o_EntityID = v_EntityID; o_EntityID = v_EntityID;
} }

View File

@ -0,0 +1,69 @@
// Basic MSDF Text Texture Shader
#type vertex
#version 450 core
layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec4 a_Color;
layout(location = 2) in vec2 a_TexCoord;
layout(location = 3) in int a_EntityID;
layout(std140, binding = 0) uniform Camera
{
mat4 u_ViewProjection;
};
layout (location = 0) out vec4 o_Color;
layout (location = 1) out vec2 o_TexCoord;
layout (location = 2) out flat int v_EntityID;
void main()
{
o_Color = a_Color;
o_TexCoord = a_TexCoord;
v_EntityID = a_EntityID;
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
}
#type fragment
#version 450 core
layout(location = 0) out vec4 o_Color;
layout(location = 1) out int o_EntityID;
layout (location = 0) in vec4 i_Color;
layout (location = 1) in vec2 i_TexCoord;
layout (location = 2) in flat int v_EntityID;
layout (binding = 0) uniform sampler2D u_FontAtlas;
float screenPxRange() {
const float pxRange = 2.0; // set to distance field's pixel range
vec2 unitRange = vec2(pxRange)/vec2(textureSize(u_FontAtlas, 0));
vec2 screenTexSize = vec2(1.0)/fwidth(i_TexCoord); // 使用 i_TexCoord
return max(0.5*dot(unitRange, screenTexSize), 1.0);
}
float median(float r, float g, float b) {
return max(min(r, g), min(max(r, g), b));
}
void main()
{
vec4 texColor = i_Color * texture(u_FontAtlas, i_TexCoord); // 使用 i_Color 和 i_TexCoord
vec3 msd = texture(u_FontAtlas, i_TexCoord).rgb; // 使用 i_TexCoord
float sd = median(msd.r, msd.g, msd.b);
float screenPxDistance = screenPxRange()*(sd - 0.5);
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
if (opacity == 0.0)
discard;
vec4 bgColor = vec4(0.0);
o_Color = mix(bgColor, i_Color, opacity); // 使用 i_Color
if (o_Color.a == 0.0)
discard;
o_EntityID = v_EntityID;
}

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 435 KiB

After

Width:  |  Height:  |  Size: 435 KiB

View File

Before

Width:  |  Height:  |  Size: 216 KiB

After

Width:  |  Height:  |  Size: 216 KiB

View File

Before

Width:  |  Height:  |  Size: 328 KiB

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More