mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-30 12:36:35 +00:00
ModelReader/Writer - Rename ModelReader/Writer to ModelFileReader/Writer and add support for PS4 models.bin files
This commit is contained in:
@@ -6,14 +6,14 @@ using System.Text;
|
||||
|
||||
namespace PckStudio.Classes.IO.Model
|
||||
{
|
||||
public class ModelReader : StreamDataReader<ModelFile>
|
||||
public class ModelFileReader : StreamDataReader<ModelFile>
|
||||
{
|
||||
public static ModelFile Read(Stream stream, bool useLittleEndian = false)
|
||||
public static ModelFile Read(Stream stream)
|
||||
{
|
||||
return new ModelReader(useLittleEndian).ReadFromStream(stream);
|
||||
return new ModelFileReader().ReadFromStream(stream);
|
||||
}
|
||||
|
||||
private ModelReader(bool useLittleEndian) : base(useLittleEndian)
|
||||
private ModelFileReader() : base(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -32,7 +32,12 @@ namespace PckStudio.Classes.IO.Model
|
||||
int partCount = ReadInt(stream);
|
||||
for (; 0 < partCount; partCount--)
|
||||
{
|
||||
string partname = ReadString(stream);
|
||||
string partName = ReadString(stream);
|
||||
if (version > 1)
|
||||
{
|
||||
string partParentName = ReadString(stream);
|
||||
Debug.WriteLineIf(partParentName.Length > 0, partParentName, category: nameof(ModelFileReader));
|
||||
}
|
||||
float x = ReadFloat(stream);
|
||||
float y = ReadFloat(stream);
|
||||
float z = ReadFloat(stream);
|
||||
@@ -40,13 +45,13 @@ namespace PckStudio.Classes.IO.Model
|
||||
float yaw = ReadFloat(stream);
|
||||
float pitch = ReadFloat(stream);
|
||||
float roll = ReadFloat(stream);
|
||||
var part = new ModelFile.Model.Part(partname, (x, y, z), (yaw, pitch, roll));
|
||||
var part = new ModelFile.Model.Part(partName, (x, y, z), (yaw, pitch, roll));
|
||||
if (version > 0)
|
||||
{
|
||||
float _1 = ReadFloat(stream);
|
||||
float _2 = ReadFloat(stream);
|
||||
float _3 = ReadFloat(stream);
|
||||
Debug.WriteLine("[{0}]: {1}, {2}, {3}", nameof(ModelReader), _1, _2, _3);
|
||||
Debug.WriteLine(string.Format("{0}, {1}, {2}", _1, _2, _3), category: nameof(ModelFileReader));
|
||||
}
|
||||
|
||||
int boxCount = ReadInt(stream);
|
||||
|
||||
@@ -8,23 +8,26 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace PckStudio.Classes.IO.Model
|
||||
{
|
||||
internal class ModelWriter : StreamDataWriter
|
||||
internal class ModelFileWriter : StreamDataWriter
|
||||
{
|
||||
private ModelFile _modelFile;
|
||||
public static void Write(Stream stream, ModelFile modelFile)
|
||||
private int _fileVersion;
|
||||
public static void Write(Stream stream, ModelFile modelFile, int fileVersion = 1)
|
||||
{
|
||||
new ModelWriter(modelFile, false).WriteToStream(stream);
|
||||
new ModelFileWriter(modelFile, fileVersion).WriteToStream(stream);
|
||||
}
|
||||
|
||||
public ModelWriter(ModelFile modelFile, bool littleEndian) : base(littleEndian)
|
||||
public ModelFileWriter(ModelFile modelFile, int fileVersion) : base(false)
|
||||
{
|
||||
_modelFile = modelFile;
|
||||
if (fileVersion < 0 || fileVersion > 2)
|
||||
throw new InvalidDataException(nameof(fileVersion));
|
||||
_fileVersion = fileVersion;
|
||||
}
|
||||
|
||||
protected override void WriteToStream(Stream stream)
|
||||
{
|
||||
int version = 0;
|
||||
WriteInt(stream, version);
|
||||
WriteInt(stream, _fileVersion);
|
||||
WriteInt(stream, _modelFile.Models.Count);
|
||||
foreach (var model in _modelFile.Models)
|
||||
{
|
||||
@@ -35,6 +38,12 @@ namespace PckStudio.Classes.IO.Model
|
||||
foreach (var part in model.parts)
|
||||
{
|
||||
WriteString(stream, part.name);
|
||||
|
||||
if (_fileVersion > 1)
|
||||
{
|
||||
WriteString(stream, model.parts[0].name.Equals(part.name) ? string.Empty : model.parts[0].name);
|
||||
}
|
||||
|
||||
WriteFloat(stream, part.position.x);
|
||||
WriteFloat(stream, part.position.y);
|
||||
WriteFloat(stream, part.position.z);
|
||||
@@ -43,7 +52,7 @@ namespace PckStudio.Classes.IO.Model
|
||||
WriteFloat(stream, part.rotation.pitch);
|
||||
WriteFloat(stream, part.rotation.roll);
|
||||
|
||||
if (version > 0)
|
||||
if (_fileVersion > 0)
|
||||
{
|
||||
WriteFloat(stream, 0.0f);
|
||||
WriteFloat(stream, 0.0f);
|
||||
|
||||
Reference in New Issue
Block a user