Added write support for binary files!
Holy cow, this took a lot of work. I think I may need to do a few more things before I consider this a 1.0 release, but I'm glad to have finally overcome this hurdle!
This commit is contained in:
@ -335,5 +335,55 @@ namespace RobloxFiles.DataTypes
|
||||
|
||||
return new float[] { x, y, z };
|
||||
}
|
||||
|
||||
public bool IsAxisAligned()
|
||||
{
|
||||
float[] matrix = GetComponents();
|
||||
|
||||
byte sum0 = 0,
|
||||
sum1 = 0;
|
||||
|
||||
for (int i = 3; i < 12; i++)
|
||||
{
|
||||
float t = matrix[i];
|
||||
|
||||
if (Math.Abs(t - 1f) < 10e-5f)
|
||||
{
|
||||
// Approximately ±1
|
||||
sum1++;
|
||||
}
|
||||
else if (Math.Abs(t) < 10e-5f)
|
||||
{
|
||||
// Approximately ±0
|
||||
sum0++;
|
||||
}
|
||||
}
|
||||
|
||||
return (sum0 == 6 && sum1 == 3);
|
||||
}
|
||||
|
||||
private static bool IsLegalOrientId(int orientId)
|
||||
{
|
||||
int xNormalAbs = (orientId / 6) % 3;
|
||||
int yNormalAbs = orientId % 3;
|
||||
|
||||
return (xNormalAbs != yNormalAbs);
|
||||
}
|
||||
|
||||
public int GetOrientId()
|
||||
{
|
||||
if (!IsAxisAligned())
|
||||
return -1;
|
||||
|
||||
int xNormal = RightVector.ToNormalId();
|
||||
int yNormal = UpVector.ToNormalId();
|
||||
|
||||
int orientId = (6 * xNormal) + yNormal;
|
||||
|
||||
if (!IsLegalOrientId(orientId))
|
||||
return -1;
|
||||
|
||||
return orientId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,9 +125,30 @@ namespace RobloxFiles.DataTypes
|
||||
return this + (other - this) * t;
|
||||
}
|
||||
|
||||
public bool isClose(Vector3 other, float epsilon = 0.0f)
|
||||
public bool IsClose(Vector3 other, float epsilon = 0.0f)
|
||||
{
|
||||
return (other - this).Magnitude <= Math.Abs(epsilon);
|
||||
}
|
||||
|
||||
public int ToNormalId()
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
NormalId normalId = (NormalId)i;
|
||||
Vector3 normal = FromNormalId(normalId);
|
||||
|
||||
float dotProd = normal.Dot(this);
|
||||
|
||||
if (Math.Abs(dotProd - 1f) < 10e-5f)
|
||||
{
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user