Refactor Vector3Field and update project structure

Changed Vector3Field.cs to derive from ValueControl<Vector3> and use NumberBox controls for better UI handling.
Changed EditorControls.xaml to update resource paths for new controls.
Changed InternalControls.xaml to simplify the resource dictionary by removing unnecessary references.
Changed IComponentEditor.cs to reflect updates in the component editor's lifecycle methods.
Changed project files for Ghost.Editor and Ghost.Core to include new dependencies and project references.
Changed FileExtensions.cs and IInspectorService.cs to align with the new namespace structure.
Changed Result.cs to enhance error handling and success checking methods.
Changed TypeHandle.cs to improve type handling compatibility.
Changed AssemblyInfo.cs files to include new assembly visibility attributes for better encapsulation.
Added new graphics-related classes and interfaces in the Ghost.Engine project, including IGraphicsDevice and DX12GraphicsDevice.
Added a new Mesh class to handle 3D mesh data and provide methods for creating geometric shapes.
Added GraphicsPipeline.cs to manage the graphics rendering loop and device initialization.
Added ScenePage.xaml and ScenePage.xaml.cs to create a new page for rendering scenes.
Updated HierarchyPage.xaml.cs and InspectorPage.xaml.cs to use the new service locator pattern for service retrieval.
Updated LandingWindow.xaml.cs and EngineEditorWindow.xaml.cs to utilize the new service locator pattern for better service access.
Updated Logger.cs to enhance logging capabilities with optional stack traces and assertion logging.
Updated QueryFilter.cs and QueryEnumerable.cs to use the new TypeHandle structure for improved efficiency.
Updated WorldNode.cs and WorldNodeSerializer.cs to enhance serialization and management of world nodes.
Updated AssetDatabase and related classes to improve asset management and metadata generation.
Updated Ghost.UnitTest.csproj to include new project references and package dependencies for unit tests.
This commit is contained in:
2025-06-27 20:02:02 +09:00
parent 1724072f7e
commit 4110c166cf
191 changed files with 2286 additions and 1462 deletions

View File

@@ -0,0 +1,126 @@
using Ghost.Graphics.Data;
using System.Numerics;
namespace Ghost.Graphics.Utilities;
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)
{
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)
};
int[][] faces =
[
[0,1,2,3],
[5,4,7,6],
[4,0,3,7],
[1,5,6,2],
[3,2,6,7],
[4,5,1,0]
];
var uvs = new Vector2[] { new(0, 0), new(1, 0), new(1, 1), new(0, 1) };
foreach (var face in faces)
{
var baseIndex = mesh.VertexCount;
for (var i = 0; i < 4; i++)
{
mesh.AddVertex(corners[face[i]], Vector3.Zero, Vector4.Zero, color, uvs[i]);
}
mesh.AddTriangle(baseIndex + 0, baseIndex + 1, baseIndex + 2);
mesh.AddTriangle(baseIndex + 0, baseIndex + 2, baseIndex + 3);
}
mesh.ComputeNormal();
mesh.ComputeTangents();
return mesh;
}
/// <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)
{
var hw = width * 0.5f;
var hd = depth * 0.5f;
var mesh = new Mesh(4, 6);
mesh.AddVertex(new(-hw, 0, -hd), Vector3.Zero, Vector4.Zero, color, new(0, 0));
mesh.AddVertex(new(hw, 0, -hd), Vector3.Zero, Vector4.Zero, color, new(1, 0));
mesh.AddVertex(new(hw, 0, hd), Vector3.Zero, Vector4.Zero, color, new(1, 1));
mesh.AddVertex(new(-hw, 0, hd), Vector3.Zero, Vector4.Zero, color, new(0, 1));
mesh.AddTriangle(0, 1, 2);
mesh.AddTriangle(0, 2, 3);
mesh.ComputeNormal();
mesh.ComputeTangents();
return mesh;
}
/// <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)
{
var mesh = new Mesh((latitudeSegments + 1) * (longitudeSegments + 1), latitudeSegments * longitudeSegments * 6);
// Vertices
for (var lat = 0; lat <= latitudeSegments; lat++)
{
var theta = (float)lat / latitudeSegments * MathF.PI;
var sinTheta = MathF.Sin(theta);
var cosTheta = MathF.Cos(theta);
for (var lon = 0; lon <= longitudeSegments; lon++)
{
var phi = (float)lon / longitudeSegments * 2 * MathF.PI;
var sinPhi = MathF.Sin(phi);
var cosPhi = MathF.Cos(phi);
var x = cosPhi * sinTheta;
var y = cosTheta;
var z = sinPhi * sinTheta;
mesh.AddVertex(
position: new Vector3(x, y, z) * radius,
normal: Vector3.Zero,
tangent: Vector4.Zero,
color: color,
uv: new Vector2((float)lon / longitudeSegments, (float)lat / latitudeSegments)
);
}
}
// Indices
for (var lat = 0; lat < latitudeSegments; lat++)
{
for (var lon = 0; lon < longitudeSegments; lon++)
{
var i0 = lat * (longitudeSegments + 1) + lon;
var i1 = i0 + longitudeSegments + 1;
var i2 = i1 + 1;
var i3 = i0 + 1;
mesh.AddTriangle(i0, i1, i2);
mesh.AddTriangle(i0, i2, i3);
}
}
mesh.ComputeNormal();
mesh.ComputeTangents();
return mesh;
}
}