-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Solid Point + Toggle Render Type submenu
- Added support for Solid Point regions - Added Toggle Render Type to the Edit submenu
- Loading branch information
Showing
7 changed files
with
215 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Veldrid.Utilities; | ||
|
||
namespace StudioCore.Scene.DebugPrimitives; | ||
|
||
public class DbgPrimSolidPoint : DbgPrimSolid | ||
{ | ||
private readonly DbgPrimGeometryData GeometryData; | ||
|
||
public override BoundingBox Bounds => new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); | ||
|
||
public DbgPrimSolidPoint(Transform location, float radius, Color color, int numVerticalSegments = 1, int numSidesPerSegment = 4) | ||
{ | ||
if (GeometryData != null) | ||
{ | ||
SetBuffers(GeometryData.GeomBuffer); | ||
} | ||
else | ||
{ | ||
NameColor = color; | ||
var vertices = new Vector3[numVerticalSegments + 2, numSidesPerSegment]; | ||
|
||
Vector3 topPoint = Vector3.UnitY * radius; | ||
Vector3 bottomPoint = -Vector3.UnitY * radius; | ||
|
||
for (int i = 0; i < numVerticalSegments; i++) | ||
{ | ||
for (int j = 0; j < numSidesPerSegment; j++) | ||
{ | ||
float horizontalAngle = j / (float)numSidesPerSegment * Utils.Pi * 2.0f; | ||
float verticalAngle = (i + 1) / (float)(numVerticalSegments + 1) * Utils.Pi - Utils.PiOver2; | ||
float altitude = (float)Math.Sin(verticalAngle); | ||
float horizontalDist = (float)Math.Cos(verticalAngle); | ||
|
||
vertices[i, j] = new Vector3( | ||
(float)Math.Cos(horizontalAngle) * horizontalDist, | ||
altitude, | ||
(float)Math.Sin(horizontalAngle) * horizontalDist) * radius; | ||
} | ||
} | ||
|
||
// Generate faces | ||
for (int j = 0; j < numSidesPerSegment; j++) | ||
{ | ||
int nextJ = (j + 1) % numSidesPerSegment; | ||
// Bottom cap | ||
AddTri(vertices[0, j], bottomPoint, vertices[0, nextJ], color); | ||
// Top cap | ||
AddTri(topPoint, vertices[numVerticalSegments - 1, j], vertices[numVerticalSegments - 1, nextJ], color); | ||
} | ||
|
||
for (int i = 0; i < numVerticalSegments - 1; i++) | ||
{ | ||
for (int j = 0; j < numSidesPerSegment; j++) | ||
{ | ||
int nextJ = (j + 1) % numSidesPerSegment; | ||
|
||
// Two triangles forming a quad | ||
AddTri(vertices[i, j], vertices[i + 1, j], vertices[i, nextJ], color); | ||
AddTri(vertices[i + 1, j], vertices[i + 1, nextJ], vertices[i, nextJ], color); | ||
} | ||
} | ||
|
||
GeometryData = new DbgPrimGeometryData { GeomBuffer = GeometryBuffer }; | ||
} | ||
|
||
Renderer.AddBackgroundUploadTask((d, cl) => | ||
{ | ||
UpdatePerFrameResources(d, cl, null); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using StudioCore.Scene; | ||
using System; | ||
using System.Drawing; | ||
using System.Numerics; | ||
using Veldrid.Utilities; | ||
|
||
namespace StudioCore.Scene.DebugPrimitives; | ||
|
||
|
||
public class DbgPrimWirePoint : DbgPrimWire | ||
{ | ||
private static readonly DbgPrimGeometryData GeometryData = null; | ||
|
||
public DbgPrimWirePoint(Transform location, float radius, Color color, int numVerticalSegments = 1, | ||
int numSidesPerSegment = 4) | ||
{ | ||
NameColor = color; | ||
|
||
if (GeometryData != null) | ||
{ | ||
SetBuffers(GeometryData.GeomBuffer); | ||
} | ||
else | ||
{ | ||
Vector3 topPoint = Vector3.UnitY * radius; | ||
Vector3 bottomPoint = -Vector3.UnitY * radius; | ||
var points = new Vector3[numVerticalSegments, numSidesPerSegment]; | ||
|
||
for (var i = 0; i < numVerticalSegments; i++) | ||
{ | ||
for (var j = 0; j < numSidesPerSegment; j++) | ||
{ | ||
var horizontalAngle = 1.0f * j / numSidesPerSegment * Utils.Pi * 2.0f; | ||
var verticalAngle = 1.0f * (i + 1) / (numVerticalSegments + 1) * Utils.Pi - Utils.PiOver2; | ||
var altitude = (float)Math.Sin(verticalAngle); | ||
var horizontalDist = (float)Math.Cos(verticalAngle); | ||
points[i, j] = new Vector3((float)Math.Cos(horizontalAngle) * horizontalDist, altitude, | ||
(float)Math.Sin(horizontalAngle) * horizontalDist) * radius; | ||
} | ||
} | ||
|
||
for (var i = 0; i < numVerticalSegments; i++) | ||
{ | ||
for (var j = 0; j < numSidesPerSegment; j++) | ||
{ | ||
// On the bottom, we must connect each to the bottom point | ||
if (i == 0) | ||
{ | ||
AddLine(points[i, j], bottomPoint, color); | ||
} | ||
|
||
// On the top, we must connect each point to the top | ||
// Note: this isn't "else if" because with 2 segments, | ||
// these are both true for the only ring | ||
if (i == numVerticalSegments - 1) | ||
{ | ||
AddLine(points[i, j], topPoint, color); | ||
} | ||
|
||
// Make vertical lines that connect from this | ||
// horizontal ring to the one above | ||
// Since we are connecting | ||
// (current) -> (the one above current) | ||
// we dont need to do this for the very last one. | ||
if (i < numVerticalSegments - 1) | ||
{ | ||
AddLine(points[i, j], points[i + 1, j], color); | ||
} | ||
|
||
|
||
// Make lines that connect points horizontally | ||
//---- if we reach end, we must wrap around, | ||
//---- otherwise, simply make line to next one | ||
if (j == numSidesPerSegment - 1) | ||
{ | ||
AddLine(points[i, j], points[i, 0], color); | ||
} | ||
else | ||
{ | ||
AddLine(points[i, j], points[i, j + 1], color); | ||
} | ||
} | ||
} | ||
|
||
Renderer.AddBackgroundUploadTask((d, cl) => | ||
{ | ||
UpdatePerFrameResources(d, cl, null); | ||
}); | ||
} | ||
} | ||
|
||
public bool RayCast(Ray ray, Matrix4x4 transform, out float dist) | ||
{ | ||
var radius = Vector3.TransformNormal(Vector3.UnitX, transform).Length(); | ||
Vector3 pos = Vector3.Transform(Vector3.Zero, transform); | ||
return Utils.RaySphereIntersection(ref ray, pos, radius, out dist); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters