0.522.0.5220281 (+ Font Type Support & Bug Fixes)
This commit is contained in:
@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using RobloxFiles.Enums;
|
||||
|
||||
namespace RobloxFiles.DataTypes
|
||||
{
|
||||
public class CFrame
|
||||
{
|
||||
private float m14, m24, m34;
|
||||
private readonly float m14, m24, m34;
|
||||
|
||||
private readonly float m11 = 1, m12, m13;
|
||||
private readonly float m21, m22 = 1, m23;
|
||||
@ -18,28 +17,23 @@ namespace RobloxFiles.DataTypes
|
||||
public float Y => m24;
|
||||
public float Z => m34;
|
||||
|
||||
public Vector3 Position
|
||||
{
|
||||
get => new Vector3(X, Y, Z);
|
||||
public Vector3 Position => new Vector3(m41, m42, m43);
|
||||
public CFrame Rotation => (this - Position);
|
||||
|
||||
set
|
||||
{
|
||||
Contract.Requires(value != null);
|
||||
public Vector3 XVector => new Vector3(m11, m21, m31);
|
||||
public Vector3 YVector => new Vector3(m12, m22, m32);
|
||||
public Vector3 ZVector => new Vector3(m13, m23, m33);
|
||||
|
||||
m14 = value.X;
|
||||
m24 = value.Y;
|
||||
m34 = value.Z;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 RightVector => new Vector3( m11, m21, m31);
|
||||
public Vector3 UpVector => new Vector3( m12, m22, m32);
|
||||
public Vector3 LookVector => new Vector3(-m13, -m23, -m33);
|
||||
public Vector3 RightVector => XVector;
|
||||
public Vector3 UpVector => YVector;
|
||||
public Vector3 LookVector => -ZVector;
|
||||
|
||||
public Vector3 ColumnX => new Vector3(m11, m12, m13);
|
||||
public Vector3 ColumnY => new Vector3(m21, m22, m23);
|
||||
public Vector3 ColumnZ => new Vector3(m31, m32, m33);
|
||||
|
||||
public static readonly CFrame Identity = new CFrame();
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var components = GetComponents();
|
||||
@ -96,23 +90,20 @@ namespace RobloxFiles.DataTypes
|
||||
|
||||
public CFrame(Vector3 eye, Vector3 look)
|
||||
{
|
||||
Vector3 zAxis = (eye - look).Unit;
|
||||
Vector3 xAxis = Vector3.Up.Cross(zAxis);
|
||||
Vector3 yAxis = zAxis.Cross(xAxis);
|
||||
Vector3 zAxis = (eye - look).Unit,
|
||||
xAxis = Vector3.Up.Cross(zAxis),
|
||||
yAxis = zAxis.Cross(xAxis);
|
||||
|
||||
if (xAxis.Magnitude == 0)
|
||||
{
|
||||
xAxis = Vector3.z;
|
||||
yAxis = Vector3.x;
|
||||
zAxis = Vector3.y;
|
||||
|
||||
if (zAxis.Y < 0)
|
||||
{
|
||||
xAxis = new Vector3(0, 0, -1);
|
||||
yAxis = new Vector3(1, 0, 0);
|
||||
zAxis = new Vector3(0, -1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
xAxis = new Vector3(0, 0, 1);
|
||||
yAxis = new Vector3(1, 0, 0);
|
||||
zAxis = new Vector3(0, 1, 0);
|
||||
xAxis = -xAxis;
|
||||
zAxis = -zAxis;
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,9 +114,9 @@ namespace RobloxFiles.DataTypes
|
||||
|
||||
public CFrame(float nx, float ny, float nz, float i, float j, float k, float w)
|
||||
{
|
||||
float ii = i * i;
|
||||
float jj = j * j;
|
||||
float kk = k * k;
|
||||
float ii = i * i,
|
||||
jj = j * j,
|
||||
kk = k * k;
|
||||
|
||||
m14 = nx;
|
||||
m24 = ny;
|
||||
@ -308,18 +299,18 @@ namespace RobloxFiles.DataTypes
|
||||
|
||||
public static CFrame FromAxisAngle(Vector3 axis, float theta)
|
||||
{
|
||||
Vector3 u = VectorAxisAngle(axis, Vector3.Up, theta);
|
||||
Vector3 b = VectorAxisAngle(axis, Vector3.Back, theta);
|
||||
Vector3 r = VectorAxisAngle(axis, Vector3.Right, theta);
|
||||
Vector3 r = VectorAxisAngle(axis, Vector3.x, theta),
|
||||
u = VectorAxisAngle(axis, Vector3.y, theta),
|
||||
b = VectorAxisAngle(axis, Vector3.z, theta);
|
||||
|
||||
return new CFrame(0, 0, 0, r.X, u.X, b.X, r.Y, u.Y, b.Y, r.Z, u.Z, b.Z);
|
||||
}
|
||||
|
||||
public static CFrame FromEulerAnglesXYZ(float x, float y, float z)
|
||||
{
|
||||
CFrame cfx = FromAxisAngle(Vector3.Right, x),
|
||||
cfy = FromAxisAngle(Vector3.Up, y),
|
||||
cfz = FromAxisAngle(Vector3.Back, z);
|
||||
CFrame cfx = FromAxisAngle(Vector3.x, x),
|
||||
cfy = FromAxisAngle(Vector3.y, y),
|
||||
cfz = FromAxisAngle(Vector3.z, z);
|
||||
|
||||
return cfx * cfy * cfz;
|
||||
}
|
||||
@ -386,7 +377,13 @@ namespace RobloxFiles.DataTypes
|
||||
|
||||
public float[] GetComponents()
|
||||
{
|
||||
return new float[] { m14, m24, m34, m11, m12, m13, m21, m22, m23, m31, m32, m33 };
|
||||
return new float[]
|
||||
{
|
||||
m14, m24, m34,
|
||||
m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
m31, m32, m33
|
||||
};
|
||||
}
|
||||
|
||||
public EulerAngles ToEulerAngles() => new EulerAngles
|
||||
@ -411,28 +408,27 @@ namespace RobloxFiles.DataTypes
|
||||
|
||||
public bool IsAxisAligned()
|
||||
{
|
||||
float[] matrix = GetComponents();
|
||||
|
||||
byte sum0 = 0,
|
||||
sum1 = 0;
|
||||
|
||||
for (int i = 3; i < 12; i++)
|
||||
var tests = new float[3]
|
||||
{
|
||||
float t = Math.Abs(matrix[i]);
|
||||
XVector.Dot(Vector3.x),
|
||||
YVector.Dot(Vector3.y),
|
||||
ZVector.Dot(Vector3.z)
|
||||
};
|
||||
|
||||
if (t.FuzzyEquals(1, 1e-8f))
|
||||
{
|
||||
// Approximately ±1
|
||||
sum1++;
|
||||
}
|
||||
else if (t.FuzzyEquals(0, 1e-8f))
|
||||
{
|
||||
// Approximately ±0
|
||||
sum0++;
|
||||
}
|
||||
foreach (var test in tests)
|
||||
{
|
||||
float dot = Math.Abs(test);
|
||||
|
||||
if (dot.FuzzyEquals(1))
|
||||
continue;
|
||||
|
||||
if (dot.FuzzyEquals(0))
|
||||
continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return (sum0 == 6 && sum1 == 3);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsLegalOrientId(int orientId)
|
||||
@ -450,7 +446,6 @@ namespace RobloxFiles.DataTypes
|
||||
|
||||
int xNormal = ColumnX.ToNormalId();
|
||||
int yNormal = ColumnY.ToNormalId();
|
||||
|
||||
int orientId = (6 * xNormal) + yNormal;
|
||||
|
||||
if (!IsLegalOrientId(orientId))
|
||||
|
52
DataTypes/FontFace.cs
Normal file
52
DataTypes/FontFace.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using RobloxFiles.Enums;
|
||||
|
||||
namespace RobloxFiles.DataTypes
|
||||
{
|
||||
// Implementation of Roblox's Font datatype.
|
||||
// Renamed to FontFace to avoid disambiguation with System.Font and the Font enum.
|
||||
|
||||
public class FontFace
|
||||
{
|
||||
public readonly Content Family = "rbxasset://fonts/families/LegacyArial.json";
|
||||
public readonly FontWeight Weight = FontWeight.Regular;
|
||||
public readonly FontStyle Style = FontStyle.Normal;
|
||||
|
||||
public FontFace(Content family, FontWeight weight = FontWeight.Regular, FontStyle style = FontStyle.Normal)
|
||||
{
|
||||
Family = family;
|
||||
Weight = weight;
|
||||
Style = style;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Font {{ Family = {Family}, Weight = {Weight}, Style = {Style}}}";
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = Family.GetHashCode()
|
||||
^ Weight.GetHashCode()
|
||||
^ Style.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is FontFace font))
|
||||
return false;
|
||||
|
||||
if (Family != font.Family)
|
||||
return false;
|
||||
|
||||
if (Weight != font.Weight)
|
||||
return false;
|
||||
|
||||
if (Style != font.Style)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,8 +12,8 @@
|
||||
|
||||
public Rect(Vector2 min = null, Vector2 max = null)
|
||||
{
|
||||
Min = min ?? Vector2.Zero;
|
||||
Max = max ?? Vector2.Zero;
|
||||
Min = min ?? Vector2.zero;
|
||||
Max = max ?? Vector2.zero;
|
||||
}
|
||||
|
||||
public Rect(float minX, float minY, float maxX, float maxY)
|
||||
|
@ -1,28 +1,14 @@
|
||||
using System;
|
||||
#pragma warning disable IDE1006 // Naming Styles
|
||||
using System;
|
||||
|
||||
namespace RobloxFiles.DataTypes
|
||||
{
|
||||
|
||||
public class Vector2
|
||||
{
|
||||
public readonly float X, Y;
|
||||
public override string ToString() => $"{X}, {Y}";
|
||||
|
||||
public float Magnitude
|
||||
{
|
||||
get
|
||||
{
|
||||
float product = Dot(this);
|
||||
double magnitude = Math.Sqrt(product);
|
||||
|
||||
return (float)magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 Unit
|
||||
{
|
||||
get { return this / Magnitude; }
|
||||
}
|
||||
|
||||
public Vector2(float x = 0, float y = 0)
|
||||
{
|
||||
X = x;
|
||||
@ -34,18 +20,21 @@ namespace RobloxFiles.DataTypes
|
||||
X = coords.Length > 0 ? coords[0] : 0;
|
||||
Y = coords.Length > 1 ? coords[1] : 0;
|
||||
}
|
||||
|
||||
public float Magnitude => (float)Math.Sqrt(X*X + Y*Y);
|
||||
public Vector2 Unit => this / Magnitude;
|
||||
|
||||
private delegate Vector2 Operator(Vector2 a, Vector2 b);
|
||||
|
||||
private static Vector2 UpcastFloatOp(Vector2 vec, float num, Operator upcast)
|
||||
{
|
||||
Vector2 numVec = new Vector2(num, num);
|
||||
var numVec = new Vector2(num, num);
|
||||
return upcast(vec, numVec);
|
||||
}
|
||||
|
||||
private static Vector2 UpcastFloatOp(float num, Vector2 vec, Operator upcast)
|
||||
{
|
||||
Vector2 numVec = new Vector2(num, num);
|
||||
var numVec = new Vector2(num, num);
|
||||
return upcast(numVec, vec);
|
||||
}
|
||||
|
||||
@ -70,29 +59,17 @@ namespace RobloxFiles.DataTypes
|
||||
public static Vector2 operator /(Vector2 v, float n) => UpcastFloatOp(v, n, div);
|
||||
public static Vector2 operator /(float n, Vector2 v) => UpcastFloatOp(n, v, div);
|
||||
|
||||
public static Vector2 operator -(Vector2 v)
|
||||
{
|
||||
return new Vector2(-v.X, -v.Y);
|
||||
}
|
||||
public static Vector2 operator -(Vector2 v) => new Vector2(-v.X, -v.Y);
|
||||
|
||||
public static Vector2 Zero => new Vector2(0, 0);
|
||||
public static Vector2 zero => new Vector2(0, 0);
|
||||
public static Vector2 one => new Vector2(1, 1);
|
||||
|
||||
public float Dot(Vector2 other)
|
||||
{
|
||||
float dotX = X * other.X;
|
||||
float dotY = Y * other.Y;
|
||||
|
||||
return dotX + dotY;
|
||||
}
|
||||
|
||||
public Vector2 Cross(Vector2 other)
|
||||
{
|
||||
float crossX = X * other.Y;
|
||||
float crossY = Y * other.X;
|
||||
|
||||
return new Vector2(crossX, crossY);
|
||||
}
|
||||
public static Vector2 x => new Vector2(1, 0);
|
||||
public static Vector2 y => new Vector2(0, 1);
|
||||
|
||||
public float Dot(Vector2 other) => (X * other.X) + (Y * other.Y);
|
||||
public Vector2 Cross(Vector2 other) => new Vector2(X * other.Y, Y * other.X);
|
||||
|
||||
public Vector2 Lerp(Vector2 other, float t)
|
||||
{
|
||||
return this + (other - this) * t;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using RobloxFiles.Enums;
|
||||
|
||||
namespace RobloxFiles.DataTypes
|
||||
@ -19,7 +18,7 @@ namespace RobloxFiles.DataTypes
|
||||
return (float)magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Vector3 Unit
|
||||
{
|
||||
get { return this / Magnitude; }
|
||||
@ -60,7 +59,7 @@ namespace RobloxFiles.DataTypes
|
||||
}
|
||||
|
||||
private delegate Vector3 Operator(Vector3 a, Vector3 b);
|
||||
|
||||
|
||||
private static Vector3 UpcastFloatOp(Vector3 vec, float num, Operator upcast)
|
||||
{
|
||||
Vector3 numVec = new Vector3(num, num, num);
|
||||
@ -73,36 +72,39 @@ namespace RobloxFiles.DataTypes
|
||||
return upcast(numVec, vec);
|
||||
}
|
||||
|
||||
private static readonly Operator add = new Operator((a, b) => new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z));
|
||||
private static readonly Operator sub = new Operator((a, b) => new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z));
|
||||
private static readonly Operator mul = new Operator((a, b) => new Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z));
|
||||
private static readonly Operator div = new Operator((a, b) => new Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z));
|
||||
private static readonly Operator add = (a, b) => new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
||||
private static readonly Operator sub = (a, b) => new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
||||
private static readonly Operator mul = (a, b) => new Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z);
|
||||
private static readonly Operator div = (a, b) => new Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
|
||||
|
||||
public static Vector3 operator +(Vector3 a, Vector3 b) => add(a, b);
|
||||
public static Vector3 operator +(Vector3 v, float n) => UpcastFloatOp(v, n, add);
|
||||
public static Vector3 operator +(float n, Vector3 v) => UpcastFloatOp(n, v, add);
|
||||
public static Vector3 operator +(Vector3 v, float n) => UpcastFloatOp(v, n, add);
|
||||
public static Vector3 operator +(float n, Vector3 v) => UpcastFloatOp(n, v, add);
|
||||
|
||||
public static Vector3 operator -(Vector3 a, Vector3 b) => sub(a, b);
|
||||
public static Vector3 operator -(Vector3 v, float n) => UpcastFloatOp(v, n, sub);
|
||||
public static Vector3 operator -(float n, Vector3 v) => UpcastFloatOp(n, v, sub);
|
||||
public static Vector3 operator -(Vector3 v, float n) => UpcastFloatOp(v, n, sub);
|
||||
public static Vector3 operator -(float n, Vector3 v) => UpcastFloatOp(n, v, sub);
|
||||
|
||||
public static Vector3 operator *(Vector3 a, Vector3 b) => mul(a, b);
|
||||
public static Vector3 operator *(Vector3 v, float n) => UpcastFloatOp(v, n, mul);
|
||||
public static Vector3 operator *(float n, Vector3 v) => UpcastFloatOp(n, v, mul);
|
||||
public static Vector3 operator *(Vector3 v, float n) => UpcastFloatOp(v, n, mul);
|
||||
public static Vector3 operator *(float n, Vector3 v) => UpcastFloatOp(n, v, mul);
|
||||
|
||||
public static Vector3 operator /(Vector3 a, Vector3 b) => div(a, b);
|
||||
public static Vector3 operator /(Vector3 v, float n) => UpcastFloatOp(v, n, div);
|
||||
public static Vector3 operator /(float n, Vector3 v) => UpcastFloatOp(n, v, div);
|
||||
public static Vector3 operator /(Vector3 v, float n) => UpcastFloatOp(v, n, div);
|
||||
public static Vector3 operator /(float n, Vector3 v) => UpcastFloatOp(n, v, div);
|
||||
|
||||
public static Vector3 operator -(Vector3 v)
|
||||
{
|
||||
return new Vector3(-v.X, -v.Y, -v.Z);
|
||||
}
|
||||
public static Vector3 operator -(Vector3 v) => new Vector3(-v.X, -v.Y, -v.Z);
|
||||
|
||||
public static readonly Vector3 zero = new Vector3(0, 0, 0);
|
||||
public static readonly Vector3 one = new Vector3(1, 1, 1);
|
||||
|
||||
public static readonly Vector3 Zero = new Vector3(0, 0, 0);
|
||||
public static readonly Vector3 Right = new Vector3(1, 0, 0);
|
||||
public static readonly Vector3 Up = new Vector3(0, 1, 0);
|
||||
public static readonly Vector3 Back = new Vector3(0, 0, 1);
|
||||
public static readonly Vector3 x = new Vector3(1, 0, 0);
|
||||
public static readonly Vector3 y = new Vector3(0, 1, 0);
|
||||
public static readonly Vector3 z = new Vector3(0, 0, 1);
|
||||
|
||||
public static Vector3 Right => x;
|
||||
public static Vector3 Up => y;
|
||||
public static Vector3 Back => z;
|
||||
|
||||
public float Dot(Vector3 other)
|
||||
{
|
||||
|
Reference in New Issue
Block a user