Skip to content
Permalink
ce1061e9b5
Go to file
 
 
Cannot retrieve contributors at this time
121 lines (103 sloc) 3.74 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
using GameFormatReader.Common;
namespace SuperBMDLib.Util
{
public static class StreamUtility
{
public static void PadStreamWithString(EndianBinaryWriter writer, int padValue)
{
string padding = "Model made with SuperBMD by Gamma.";
// Pad up to a 32 byte alignment
// Formula: (x + (n-1)) & ~(n-1)
long nextAligned = (writer.BaseStream.Length + (padValue - 1)) & ~(padValue - 1);
long delta = nextAligned - writer.BaseStream.Length;
writer.BaseStream.Position = writer.BaseStream.Length;
for (int i = 0; i < delta; i++)
{
writer.Write(padding[i]);
}
}
public static void PadStreamWithStringByOffset(EndianBinaryWriter writer, int offset, int padValue)
{
string padding = "Model made with SuperBMD by Gamma.";
// Pad up to a 32 byte alignment
// Formula: (x + (n-1)) & ~(n-1)
long nextAligned = (offset + (padValue - 1)) & ~(padValue - 1);
long delta = nextAligned - offset;
writer.BaseStream.Position = writer.BaseStream.Length;
for (int i = 0; i < delta; i++)
{
writer.Write(padding[i]);
}
}
public static void PadStreamWithZero(EndianBinaryWriter writer, int padValue)
{
// Pad up to a 32 byte alignment
// Formula: (x + (n-1)) & ~(n-1)
long nextAligned = (writer.BaseStream.Length + (padValue - 1)) & ~(padValue - 1);
long delta = nextAligned - writer.BaseStream.Length;
writer.BaseStream.Position = writer.BaseStream.Length;
for (int i = 0; i < delta; i++)
{
writer.Write((byte)0);
}
}
public static void Write(this EndianBinaryWriter writer, Vector3 vec3)
{
writer.Write(vec3.X);
writer.Write(vec3.Y);
writer.Write(vec3.Z);
}
public static void Write(this EndianBinaryWriter writer, Vector2 vec2)
{
writer.Write(vec2.X);
writer.Write(vec2.Y);
}
public static void Write(this EndianBinaryWriter writer, Color color)
{
writer.Write((byte)(color.R * 255));
writer.Write((byte)(color.G * 255));
writer.Write((byte)(color.B * 255));
writer.Write((byte)(color.A * 255));
}
public static void Write(this EndianBinaryWriter writer, Matrix3x4 mat)
{
writer.Write(mat.M11);
writer.Write(mat.M12);
writer.Write(mat.M13);
writer.Write(mat.M14);
writer.Write(mat.M21);
writer.Write(mat.M22);
writer.Write(mat.M23);
writer.Write(mat.M24);
writer.Write(mat.M31);
writer.Write(mat.M32);
writer.Write(mat.M33);
writer.Write(mat.M34);
}
public static void Write(this EndianBinaryWriter writer, Matrix4 mat)
{
writer.Write(mat.M11);
writer.Write(mat.M12);
writer.Write(mat.M13);
writer.Write(mat.M14);
writer.Write(mat.M21);
writer.Write(mat.M22);
writer.Write(mat.M23);
writer.Write(mat.M24);
writer.Write(mat.M31);
writer.Write(mat.M32);
writer.Write(mat.M33);
writer.Write(mat.M34);
writer.Write(mat.M41);
writer.Write(mat.M42);
writer.Write(mat.M43);
writer.Write(mat.M44);
}
}
}
You can’t perform that action at this time.