forked from Misaki/GhostEngine
Enhance graphics engine and code organization
Added `InternalsVisibleTo` attribute for "Ghost.Graphics" and "Ghost.Editor" in `AssemblyInfo.cs`. Added a new `EngineAssemblyAttribute` in `EngineAssemblyAttribute.cs`. Added a reference to `Misaki.HighPerformance.Unsafe` in `Ghost.Core.csproj`. Added a new `Bounds` struct to represent axis-aligned bounding boxes in `Bounds.cs`. Added new `Color32` and `Color128` structs for color representation in `Color.cs`. Changed the namespace from `Ghost.Editor.Controls` to `Ghost.Editor.Core.Controls` in multiple files. Changed the implicit conversion operator in `ConstPtr<T>` to use a more descriptive parameter name in `ConstPtr.cs`. Changed the `Mesh` class to use `Color128` instead of `Color32` for color representation. Enhanced the `TypeCache` class to load types from assemblies marked with `EngineAssemblyAttribute`. Enhanced the `ProjectService` class to improve the `GetAllProjectAsync` method by filtering out bad projects. Enhanced the `GraphicsPipeline` class to support both DX12 and D3D12 graphics APIs. Enhanced the `Shader` class to include methods for compiling HLSL shaders and managing root signatures. Enhanced the `MeshRenderPass` class to utilize the new shader compilation methods. Refactored the `AppStateMachine` class to use private fields instead of static fields for state management. Refactored the `ComponentDataView` class to use the new namespace and improve organization. Refactored project references in `Ghost.Graphics.csproj` to include new dependencies and remove outdated ones. Made various adjustments to ensure consistency and improve code quality across multiple files.
This commit is contained in:
@@ -8,15 +8,17 @@ public static class MeshBuilder
|
||||
/// <summary>
|
||||
/// Creates a unit cube centered at the origin with size 1.
|
||||
/// </summary>
|
||||
public static Mesh CreateCube(float size = 1.0f, Color32 color = default)
|
||||
public static Mesh CreateCube(float size = 1.0f, Color128 color = default, Vector3 offset = default)
|
||||
{
|
||||
var half = size * 0.5f;
|
||||
var mesh = new Mesh(24, 36);
|
||||
|
||||
var corners = new Vector3[]
|
||||
{
|
||||
new(-half, -half, -half), new( half, -half, -half), new( half, half, -half), new(-half, half, -half),
|
||||
new(-half, -half, half), new( half, -half, half), new( half, half, half), new(-half, half, half)
|
||||
new Vector3(-half, -half, -half) + offset, new Vector3( half, -half, -half) + offset,
|
||||
new Vector3( half, half, -half) + offset, new Vector3(-half, half, -half) + offset,
|
||||
new Vector3(-half, -half, half) + offset, new Vector3( half, -half, half) + offset,
|
||||
new Vector3( half, half, half) + offset, new Vector3(-half, half, half) + offset
|
||||
};
|
||||
|
||||
int[][] faces =
|
||||
@@ -47,8 +49,8 @@ public static class MeshBuilder
|
||||
mesh.AddVertex(new(corners[face[i]].AsVector4(), Vector4.Zero, Vector4.Zero, color, uvs[i].AsVector4()));
|
||||
}
|
||||
|
||||
mesh.AddTriangle(baseIndex + 0, baseIndex + 1, baseIndex + 2);
|
||||
mesh.AddTriangle(baseIndex + 0, baseIndex + 2, baseIndex + 3);
|
||||
mesh.AddTriangle((int)baseIndex + 0, (int)baseIndex + 1, (int)baseIndex + 2);
|
||||
mesh.AddTriangle((int)baseIndex + 0, (int)baseIndex + 2, (int)baseIndex + 3);
|
||||
}
|
||||
|
||||
mesh.ComputeNormal();
|
||||
@@ -59,7 +61,7 @@ public static class MeshBuilder
|
||||
/// <summary>
|
||||
/// Creates a plane on the XZ axis centered at the origin.
|
||||
/// </summary>
|
||||
public static Mesh CreatePlane(float width = 1.0f, float depth = 1.0f, Color32 color = default)
|
||||
public static Mesh CreatePlane(float width = 1.0f, float depth = 1.0f, Color128 color = default)
|
||||
{
|
||||
var hw = width * 0.5f;
|
||||
var hd = depth * 0.5f;
|
||||
@@ -81,7 +83,7 @@ public static class MeshBuilder
|
||||
/// <summary>
|
||||
/// Creates a UV sphere centered at the origin.
|
||||
/// </summary>
|
||||
public static Mesh CreateSphere(int latitudeSegments = 16, int longitudeSegments = 24, float radius = 0.5f, Color32 color = default)
|
||||
public static Mesh CreateSphere(int latitudeSegments = 16, int longitudeSegments = 24, float radius = 0.5f, Color128 color = default)
|
||||
{
|
||||
var mesh = new Mesh((latitudeSegments + 1) * (longitudeSegments + 1), latitudeSegments * longitudeSegments * 6);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user