mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 13:59:22 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
|
|
namespace Editor.MeshEditor;
|
|
|
|
[Title( "Quad" ), Icon( "rectangle" )]
|
|
public class QuadPrimitive : PrimitiveBuilder
|
|
{
|
|
[Hide] public override bool Is2D => true;
|
|
[Hide] private BBox _box;
|
|
|
|
public bool HasBackface { get; set; } = false;
|
|
|
|
public override void SetFromBox( BBox box ) => _box = box;
|
|
|
|
public override void Build( PolygonMesh mesh )
|
|
{
|
|
var mins = _box.Mins;
|
|
var maxs = _box.Maxs;
|
|
|
|
if ( _box.Size.x <= 0.0f )
|
|
{
|
|
// YZ plane
|
|
mesh.AddFace(
|
|
new Vector3( _box.Center.x, mins.y, mins.z ),
|
|
new Vector3( _box.Center.x, maxs.y, mins.z ),
|
|
new Vector3( _box.Center.x, maxs.y, maxs.z ),
|
|
new Vector3( _box.Center.x, mins.y, maxs.z )
|
|
);
|
|
if ( HasBackface )
|
|
{
|
|
mesh.AddFace(
|
|
new Vector3( _box.Center.x, mins.y, mins.z ),
|
|
new Vector3( _box.Center.x, mins.y, maxs.z ),
|
|
new Vector3( _box.Center.x, maxs.y, maxs.z ),
|
|
new Vector3( _box.Center.x, maxs.y, mins.z )
|
|
);
|
|
}
|
|
}
|
|
else if ( _box.Size.y <= 0.0f )
|
|
{
|
|
// XZ Plane
|
|
mesh.AddFace(
|
|
new Vector3( mins.x, _box.Center.y, mins.z ),
|
|
new Vector3( mins.x, _box.Center.y, maxs.z ),
|
|
new Vector3( maxs.x, _box.Center.y, maxs.z ),
|
|
new Vector3( maxs.x, _box.Center.y, mins.z )
|
|
);
|
|
if ( HasBackface )
|
|
{
|
|
mesh.AddFace(
|
|
new Vector3( mins.x, _box.Center.y, mins.z ),
|
|
new Vector3( maxs.x, _box.Center.y, mins.z ),
|
|
new Vector3( maxs.x, _box.Center.y, maxs.z ),
|
|
new Vector3( mins.x, _box.Center.y, maxs.z )
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// XY Plane
|
|
mesh.AddFace(
|
|
new Vector3( mins.x, mins.y, _box.Center.z ),
|
|
new Vector3( maxs.x, mins.y, _box.Center.z ),
|
|
new Vector3( maxs.x, maxs.y, _box.Center.z ),
|
|
new Vector3( mins.x, maxs.y, _box.Center.z )
|
|
);
|
|
if ( HasBackface )
|
|
{
|
|
mesh.AddFace(
|
|
new Vector3( mins.x, mins.y, _box.Center.z ),
|
|
new Vector3( mins.x, maxs.y, _box.Center.z ),
|
|
new Vector3( maxs.x, maxs.y, _box.Center.z ),
|
|
new Vector3( maxs.x, mins.y, _box.Center.z )
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|