Skip to content

Commit 94be6c9

Browse files
[Math] Change AABB to be a readonly struct and remove computed values;
[Rendering] Added IRenderSystem WorldVisibilityChanged property; [Rendering] Added Material StateHash; [Rendering] Added logic to detect when shader handles are no longer valid; [Rendering] Fixed Meshes not always being updated during a reload; [Editor] Fix List object picker having the wrong ID; [Editor] Silently succeed when EditorUtils.CopyDirectory doesn't have a source directory;
1 parent 709a9c7 commit 94be6c9

26 files changed

+457
-383
lines changed

Engine/Core/Math/AABB.cs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,38 @@
1-
using MessagePack;
2-
using System;
3-
using System.Numerics;
1+
using System.Numerics;
42
using System.Runtime.InteropServices;
53

64
namespace Staple;
75

86
/// <summary>
97
/// Axis Aligned Bounding Box
108
/// </summary>
11-
[Serializable]
129
[StructLayout(LayoutKind.Sequential, Pack = 0)]
13-
[MessagePackObject]
1410
public struct AABB
1511
{
1612
/// <summary>
1713
/// The center of the box
1814
/// </summary>
19-
[Key(0)]
20-
public Vector3 center;
15+
public readonly Vector3 center;
2116

2217
/// <summary>
2318
/// The extents of the box (distance from the box as a radius)
2419
/// </summary>
25-
[Key(1)]
26-
public Vector3 extents;
20+
public readonly Vector3 extents;
2721

2822
/// <summary>
2923
/// The minimum position of the box
3024
/// </summary>
31-
[IgnoreMember]
32-
public readonly Vector3 Min => new(center.X - extents.X, center.Y - extents.Y, center.Z - extents.Z);
25+
public readonly Vector3 min;
3326

3427
/// <summary>
3528
/// The maximum position of the box
3629
/// </summary>
37-
[IgnoreMember]
38-
public readonly Vector3 Max => new(center.X + extents.X, center.Y + extents.Y, center.Z + extents.Z);
30+
public readonly Vector3 max;
3931

4032
/// <summary>
4133
/// The size of the box
4234
/// </summary>
43-
[IgnoreMember]
44-
public readonly Vector3 Size => extents * 2;
35+
public readonly Vector3 size;
4536

4637
/// <summary>
4738
/// Creates an Axis Aligned Bounding Box from a center and size
@@ -51,8 +42,12 @@ public struct AABB
5142
public AABB(Vector3 center, Vector3 size)
5243
{
5344
this.center = center;
45+
this.size = size;
5446

5547
extents = size / 2;
48+
49+
min = new(center.X - extents.X, center.Y - extents.Y, center.Z - extents.Z);
50+
max = new(center.X + extents.X, center.Y + extents.Y, center.Z + extents.Z);
5651
}
5752

5853
public override readonly string ToString()
@@ -67,30 +62,26 @@ public override readonly string ToString()
6762
/// <returns>Whether it contains a point</returns>
6863
public readonly bool Contains(Vector3 point)
6964
{
70-
//Slight optimization to prevent many function calls
71-
var min = Min;
72-
var max = Max;
73-
7465
return point.X >= min.X && point.Y >= min.Y && point.Z >= min.Z &&
7566
point.X <= max.X && point.Y <= max.Y && point.Z <= max.Z;
7667
}
7768

7869
/// <summary>
79-
/// Expands the box's size by an amount
70+
/// Creates an expanded form of this box with an increased size
8071
/// </summary>
8172
/// <param name="amount">The amount as a float</param>
82-
public void Expand(float amount)
73+
public readonly AABB Expanded(float amount)
8374
{
84-
extents += Vector3.One * (amount / 2);
75+
return new AABB(center, size * amount);
8576
}
8677

8778
/// <summary>
88-
/// Expands the box's size by an amount
79+
/// Creates an expanded form of this box with an increased size
8980
/// </summary>
9081
/// <param name="amount">The amount as a Vector3</param>
91-
public void Expand(Vector3 amount)
82+
public readonly AABB Expanded(Vector3 amount)
9283
{
93-
extents += amount / 2;
84+
return new AABB(center, size + amount);
9485
}
9586

9687
/// <summary>

Engine/Core/Math/Ray.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ bool RaySlabIntersect(float start, float dir, float min, float max)
7979
return true;
8080
}
8181

82-
if(RaySlabIntersect(ray.position.X, ray.direction.X, aabb.Min.X, aabb.Max.X) == false)
82+
if(RaySlabIntersect(ray.position.X, ray.direction.X, aabb.min.X, aabb.max.X) == false)
8383
{
8484
return false;
8585
}
8686

87-
if (RaySlabIntersect(ray.position.Y, ray.direction.Y, aabb.Min.Y, aabb.Max.Y) == false)
87+
if (RaySlabIntersect(ray.position.Y, ray.direction.Y, aabb.min.Y, aabb.max.Y) == false)
8888
{
8989
return false;
9090
}
9191

92-
if (RaySlabIntersect(ray.position.Z, ray.direction.Z, aabb.Min.Z, aabb.Max.Z) == false)
92+
if (RaySlabIntersect(ray.position.Z, ray.direction.Z, aabb.min.Z, aabb.max.Z) == false)
9393
{
9494
return false;
9595
}
@@ -152,27 +152,26 @@ public static bool IntersectsAABB(Ray ray, AABB aabb, Transform transform, out f
152152
switch (i)
153153
{
154154
case 0:
155-
boxMin = aabb.Min.X;
156-
boxMax = aabb.Max.X;
155+
boxMin = aabb.min.X;
156+
boxMax = aabb.max.X;
157157

158158
break;
159159

160160
case 1:
161-
boxMin = aabb.Min.Y;
162-
boxMax = aabb.Max.Y;
161+
boxMin = aabb.min.Y;
162+
boxMax = aabb.max.Y;
163163

164164
break;
165165

166166
case 2:
167-
boxMin = aabb.Min.Z;
168-
boxMax = aabb.Max.Z;
167+
boxMin = aabb.min.Z;
168+
boxMax = aabb.max.Z;
169169

170170
break;
171171
}
172172

173173
if (Math.Abs(denominatorLength) > 0.00001)
174174
{
175-
176175
var min = (nominatorLength + boxMin) / denominatorLength;
177176
var max = (nominatorLength + boxMax) / denominatorLength;
178177

0 commit comments

Comments
 (0)