mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-24 09:56:09 +00:00
Rename CubeData to CubeMesh and add Cube base class
This commit is contained in:
@@ -152,7 +152,8 @@
|
||||
</Compile>
|
||||
<Compile Include="Rendering\Camera\Camera.cs" />
|
||||
<Compile Include="Rendering\Camera\PerspectiveCamera.cs" />
|
||||
<Compile Include="Rendering\CubeData.cs" />
|
||||
<Compile Include="Rendering\Cube.cs" />
|
||||
<Compile Include="Rendering\CubeMesh.cs" />
|
||||
<Compile Include="Rendering\CubeGroupMesh.cs" />
|
||||
<Compile Include="Rendering\FrameBuffer.cs" />
|
||||
<Compile Include="Rendering\IndexBuffer.cs" />
|
||||
|
||||
125
PCK-Studio/Rendering/Cube.cs
Normal file
125
PCK-Studio/Rendering/Cube.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using OpenTK;
|
||||
using PckStudio.Extensions;
|
||||
using PckStudio.Internal;
|
||||
|
||||
namespace PckStudio.Rendering
|
||||
{
|
||||
internal class Cube
|
||||
{
|
||||
internal Vector3 Position
|
||||
{
|
||||
get => _position;
|
||||
set => _position = value;
|
||||
}
|
||||
|
||||
internal Vector3 Size
|
||||
{
|
||||
get => _size;
|
||||
set => _size = value;
|
||||
}
|
||||
|
||||
internal Vector2 Uv
|
||||
{
|
||||
get => _uv;
|
||||
set => _uv = value;
|
||||
}
|
||||
|
||||
internal float Inflate
|
||||
{
|
||||
get => _inflate;
|
||||
set => _inflate = value;
|
||||
}
|
||||
|
||||
internal bool MirrorTexture
|
||||
{
|
||||
get => _mirrorTexture;
|
||||
set => _mirrorTexture = value;
|
||||
}
|
||||
|
||||
internal bool FlipZMapping
|
||||
{
|
||||
get => _flipZMapping;
|
||||
set => _flipZMapping = value;
|
||||
}
|
||||
|
||||
public Vector3 Center => Position + Size / 2f;
|
||||
|
||||
internal enum Face
|
||||
{
|
||||
Back,
|
||||
Front,
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
internal static Cube FromSkinBox(SkinBOX skinBOX)
|
||||
{
|
||||
return new Cube(skinBOX.Pos.ToOpenTKVector(), skinBOX.Size.ToOpenTKVector(), skinBOX.UV.ToOpenTKVector(), skinBOX.Scale, skinBOX.Mirror, skinBOX.Type == "HEAD" || skinBOX.Type == "HEADWEAR");
|
||||
}
|
||||
|
||||
public Cube() { }
|
||||
|
||||
public Cube(Vector3 position, Vector3 size, Vector2 uv, float inflate, bool mirrorTexture, bool flipZMapping)
|
||||
{
|
||||
_position = position;
|
||||
_size = size;
|
||||
_uv = uv;
|
||||
_inflate = inflate;
|
||||
_mirrorTexture = mirrorTexture;
|
||||
_flipZMapping = flipZMapping;
|
||||
}
|
||||
|
||||
public Vector3 GetFaceCenter(Face face)
|
||||
{
|
||||
var result = Center;
|
||||
switch (face)
|
||||
{
|
||||
case Face.Top:
|
||||
result.Y -= Size.Y / 2f;
|
||||
return result;
|
||||
case Face.Bottom:
|
||||
result.Y += Size.Y / 2f;
|
||||
return result;
|
||||
case Face.Back:
|
||||
result.Z -= Size.Z / 2f;
|
||||
return result;
|
||||
case Face.Front:
|
||||
result.Z += Size.Z / 2f;
|
||||
return result;
|
||||
case Face.Left:
|
||||
result.X -= Size.X / 2f;
|
||||
return result;
|
||||
case Face.Right:
|
||||
result.X += Size.X / 2f;
|
||||
return result;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public BoundingBox GetBoundingBox()
|
||||
{
|
||||
Vector3 halfSize = Size / 2f;
|
||||
Vector3 halfSizeInflated = halfSize + new Vector3(Inflate);
|
||||
Vector3 start = Center - halfSizeInflated;
|
||||
Vector3 end = Center + halfSizeInflated;
|
||||
return new BoundingBox(start, end);
|
||||
}
|
||||
|
||||
|
||||
protected Vector3 _position = Vector3.Zero;
|
||||
protected Vector3 _size = Vector3.One;
|
||||
protected Vector2 _uv = Vector2.Zero;
|
||||
protected float _inflate = 0f;
|
||||
protected bool _mirrorTexture = false;
|
||||
protected bool _flipZMapping = false;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace PckStudio.Rendering
|
||||
{
|
||||
internal class CubeGroupMesh : GenericMesh<TextureVertex>
|
||||
{
|
||||
private List<CubeData> cubes;
|
||||
private List<CubeMesh> cubes;
|
||||
|
||||
public float Inflate { get; set; } = 0f;
|
||||
public Vector3 Translation { get; set; } = Vector3.Zero;
|
||||
@@ -36,7 +36,7 @@ namespace PckStudio.Rendering
|
||||
|
||||
internal CubeGroupMesh(string name) : base(name, PrimitiveType.Triangles)
|
||||
{
|
||||
cubes = new List<CubeData>(5);
|
||||
cubes = new List<CubeMesh>(5);
|
||||
}
|
||||
|
||||
internal CubeGroupMesh(string name, float inflate)
|
||||
@@ -47,9 +47,7 @@ namespace PckStudio.Rendering
|
||||
|
||||
internal void AddSkinBox(SkinBOX skinBox)
|
||||
{
|
||||
AddCube(skinBox.Pos.ToOpenTKVector(), skinBox.Size.ToOpenTKVector(), skinBox.UV.ToOpenTKVector(), skinBox.Scale + Inflate, skinBox.Mirror,
|
||||
skinBox.Type == "HEAD" ||
|
||||
skinBox.Type == "HEADWEAR");
|
||||
cubes.Add(CubeMesh.Create(skinBox));
|
||||
}
|
||||
|
||||
internal void ClearData()
|
||||
@@ -61,6 +59,7 @@ namespace PckStudio.Rendering
|
||||
/// <summary>
|
||||
/// Uploads MeshData
|
||||
/// </summary>
|
||||
// TODO: rename function
|
||||
internal void UploadData()
|
||||
{
|
||||
ResetBuffers();
|
||||
@@ -80,10 +79,19 @@ namespace PckStudio.Rendering
|
||||
|
||||
internal void AddCube(Vector3 position, Vector3 size, Vector2 uv, float inflate = 0f, bool mirrorTexture = false, bool flipZMapping = false)
|
||||
{
|
||||
var cube = new CubeData(position, size, uv, Inflate + inflate, mirrorTexture, flipZMapping);
|
||||
var cube = new CubeMesh(position, size, uv, Inflate + inflate, mirrorTexture, flipZMapping);
|
||||
cubes.Add(cube);
|
||||
}
|
||||
|
||||
internal void RemoveCube(int index)
|
||||
{
|
||||
if (!cubes.IndexInRange(index))
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
cubes.RemoveAt(index);
|
||||
UploadData();
|
||||
}
|
||||
|
||||
internal void ReplaceCube(int index, Vector3 position, Vector3 size, Vector2 uv, float inflate = 0f, bool mirrorTexture = false)
|
||||
{
|
||||
if (!cubes.IndexInRange(index))
|
||||
@@ -113,7 +121,7 @@ namespace PckStudio.Rendering
|
||||
if (!cubes.IndexInRange(index))
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
return cubes[index].Center + Transform;
|
||||
return cubes[index].Center + Transform + Offset;
|
||||
}
|
||||
|
||||
internal OutlineDefinition GetOutline(int index)
|
||||
@@ -121,13 +129,13 @@ namespace PckStudio.Rendering
|
||||
if (!cubes.IndexInRange(index))
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
CubeData cube = cubes[index];
|
||||
CubeMesh cube = cubes[index];
|
||||
OutlineDefinition outline = cube.GetOutline();
|
||||
outline.verticies = outline.verticies.Select(pos => pos + Transform).ToArray();
|
||||
return outline;
|
||||
}
|
||||
|
||||
internal Vector3 GetFaceCenter(int index, CubeData.CubeFace face)
|
||||
internal Vector3 GetFaceCenter(int index, Cube.Face face)
|
||||
{
|
||||
if (!cubes.IndexInRange(index))
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
@@ -21,14 +21,16 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenTK;
|
||||
using PckStudio.Extensions;
|
||||
using PckStudio.Internal;
|
||||
|
||||
namespace PckStudio.Rendering
|
||||
{
|
||||
internal class CubeData
|
||||
internal class CubeMesh : Cube
|
||||
{
|
||||
internal bool ShouldRender { get; set; } = true;
|
||||
|
||||
internal Vector3 Position
|
||||
internal new Vector3 Position
|
||||
{
|
||||
get => _position;
|
||||
set
|
||||
@@ -41,7 +43,7 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
internal Vector3 Size
|
||||
internal new Vector3 Size
|
||||
{
|
||||
get => _size;
|
||||
set
|
||||
@@ -54,7 +56,7 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
internal Vector2 Uv
|
||||
internal new Vector2 Uv
|
||||
{
|
||||
get => _uv;
|
||||
set
|
||||
@@ -67,7 +69,7 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
internal float Inflate
|
||||
internal new float Inflate
|
||||
{
|
||||
get => _inflate;
|
||||
set
|
||||
@@ -80,7 +82,7 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
internal bool MirrorTexture
|
||||
internal new bool MirrorTexture
|
||||
{
|
||||
get => _mirrorTexture;
|
||||
set
|
||||
@@ -93,7 +95,7 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
internal bool FlipZMapping
|
||||
internal new bool FlipZMapping
|
||||
{
|
||||
get => _flipZMapping;
|
||||
set
|
||||
@@ -106,46 +108,6 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
internal Vector3 Center => Position + Size / 2f;
|
||||
|
||||
internal enum CubeFace
|
||||
{
|
||||
Back,
|
||||
Front,
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
internal Vector3 GetFaceCenter(CubeFace face)
|
||||
{
|
||||
var result = Center;
|
||||
switch (face)
|
||||
{
|
||||
case CubeFace.Top:
|
||||
result.Y -= Size.Y / 2f;
|
||||
return result;
|
||||
case CubeFace.Bottom:
|
||||
result.Y += Size.Y / 2f;
|
||||
return result;
|
||||
case CubeFace.Back:
|
||||
result.Z -= Size.Z / 2f;
|
||||
return result;
|
||||
case CubeFace.Front:
|
||||
result.Z += Size.Z / 2f;
|
||||
return result;
|
||||
case CubeFace.Left:
|
||||
result.X -= Size.X / 2f;
|
||||
return result;
|
||||
case CubeFace.Right:
|
||||
result.X += Size.X / 2f;
|
||||
return result;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
internal OutlineDefinition GetOutline()
|
||||
{
|
||||
List<Vector3> verts = new List<Vector3>();
|
||||
@@ -193,18 +155,6 @@ namespace PckStudio.Rendering
|
||||
return outline;
|
||||
}
|
||||
|
||||
private void UpdateVertices()
|
||||
{
|
||||
vertices = GetCubeVertexData();
|
||||
}
|
||||
|
||||
private Vector3 _position = Vector3.Zero;
|
||||
private Vector3 _size = Vector3.One;
|
||||
private Vector2 _uv = Vector2.Zero;
|
||||
private float _inflate = 0f;
|
||||
private bool _mirrorTexture = false;
|
||||
private bool _flipZMapping = false;
|
||||
|
||||
private static int[] indicesData = [
|
||||
// Face 1 (Back)
|
||||
0, 1, 2,
|
||||
@@ -228,16 +178,14 @@ namespace PckStudio.Rendering
|
||||
|
||||
private TextureVertex[] vertices;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="size"></param>
|
||||
/// <param name="uv"></param>
|
||||
/// <param name="inflate"></param>
|
||||
/// <param name="mirrorTexture"></param>
|
||||
/// <param name="flipZMapping">Flips the bottom face mapping of the uv mapping</param>
|
||||
public CubeData(bool enabled, Vector3 position, Vector3 size, Vector2 uv, float inflate, bool mirrorTexture, bool flipZMapping)
|
||||
public CubeMesh(bool enabled, Vector3 position, Vector3 size, Vector2 uv, float inflate, bool mirrorTexture, bool flipZMapping)
|
||||
: base()
|
||||
{
|
||||
ShouldRender = enabled;
|
||||
Position = position;
|
||||
@@ -258,11 +206,16 @@ namespace PckStudio.Rendering
|
||||
/// <param name="inflate"></param>
|
||||
/// <param name="mirrorTexture"></param>
|
||||
/// <param name="flipZMapping">Flips the bottom face mapping of the uv mapping</param>
|
||||
public CubeData(Vector3 position, Vector3 size, Vector2 uv, float inflate, bool mirrorTexture, bool flipZMapping)
|
||||
public CubeMesh(Vector3 position, Vector3 size, Vector2 uv, float inflate, bool mirrorTexture, bool flipZMapping)
|
||||
: this(true, position, size, uv, inflate, mirrorTexture, flipZMapping)
|
||||
{
|
||||
}
|
||||
|
||||
public CubeMesh(Cube cube)
|
||||
: this(cube.Position, cube.Size, cube.Uv, cube.Inflate, cube.MirrorTexture, cube.FlipZMapping)
|
||||
{
|
||||
}
|
||||
|
||||
private TextureVertex[] GetCubeVertexData()
|
||||
{
|
||||
int mirror = MirrorTexture ? 1 : 0;
|
||||
@@ -270,11 +223,9 @@ namespace PckStudio.Rendering
|
||||
|
||||
Vector2 uv = Uv;
|
||||
|
||||
Vector3 halfSize = Size / 2f;
|
||||
Vector3 halfSizeInflated = halfSize + new Vector3(Inflate);
|
||||
|
||||
Vector3 from = Center - halfSizeInflated;
|
||||
Vector3 to = Center + halfSizeInflated;
|
||||
BoundingBox boundingBox = GetBoundingBox();
|
||||
Vector3 from = boundingBox.Start;
|
||||
Vector3 to = boundingBox.End;
|
||||
|
||||
var back = new TextureVertex[]
|
||||
{
|
||||
@@ -335,6 +286,11 @@ namespace PckStudio.Rendering
|
||||
return vertices.ToArray();
|
||||
}
|
||||
|
||||
private void UpdateVertices()
|
||||
{
|
||||
vertices = GetCubeVertexData();
|
||||
}
|
||||
|
||||
internal TextureVertex[] GetVertices()
|
||||
{
|
||||
return vertices;
|
||||
@@ -344,5 +300,10 @@ namespace PckStudio.Rendering
|
||||
{
|
||||
return indicesData;
|
||||
}
|
||||
|
||||
internal static CubeMesh Create(SkinBOX skinBox)
|
||||
{
|
||||
return new CubeMesh(FromSkinBox(skinBox));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -546,27 +546,27 @@ namespace PckStudio.Rendering
|
||||
// Skeleton draw context
|
||||
{
|
||||
VertexArray lineVAO = new VertexArray();
|
||||
Vector3 bodyCenterTop = body.GetFaceCenter(0, CubeData.CubeFace.Top);
|
||||
Vector3 bodyCenterBottom = body.GetFaceCenter(0, CubeData.CubeFace.Bottom);
|
||||
Vector3 bodyCenterTop = body.GetFaceCenter(0, Cube.Face.Top);
|
||||
Vector3 bodyCenterBottom = body.GetFaceCenter(0, Cube.Face.Bottom);
|
||||
ColorVertex[] data = [
|
||||
new ColorVertex(head.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(head.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
new ColorVertex(bodyCenterBottom, lineColor),
|
||||
|
||||
new ColorVertex(rightArm.GetFaceCenter(0, CubeData.CubeFace.Bottom), lineColor),
|
||||
new ColorVertex(rightArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(rightArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(leftArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(rightArm.GetFaceCenter(0, Cube.Face.Bottom), lineColor),
|
||||
new ColorVertex(rightArm.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
new ColorVertex(rightArm.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
new ColorVertex(leftArm.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
|
||||
new ColorVertex(leftArm.GetFaceCenter(0, CubeData.CubeFace.Bottom), lineColor),
|
||||
new ColorVertex(leftArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(leftArm.GetFaceCenter(0, Cube.Face.Bottom), lineColor),
|
||||
new ColorVertex(leftArm.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
|
||||
new ColorVertex(rightLeg.GetFaceCenter(0, CubeData.CubeFace.Bottom), lineColor),
|
||||
new ColorVertex(rightLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(rightLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(leftLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(rightLeg.GetFaceCenter(0, Cube.Face.Bottom), lineColor),
|
||||
new ColorVertex(rightLeg.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
new ColorVertex(rightLeg.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
new ColorVertex(leftLeg.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
|
||||
new ColorVertex(leftLeg.GetFaceCenter(0, CubeData.CubeFace.Bottom), lineColor),
|
||||
new ColorVertex(leftLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
|
||||
new ColorVertex(leftLeg.GetFaceCenter(0, Cube.Face.Bottom), lineColor),
|
||||
new ColorVertex(leftLeg.GetFaceCenter(0, Cube.Face.Top), lineColor),
|
||||
];
|
||||
VertexBuffer buffer = new VertexBuffer();
|
||||
buffer.SetData(data);
|
||||
|
||||
Reference in New Issue
Block a user