mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-28 18:45:33 +00:00
Remove ModelFile processing (Moved to OMI lib)
This commit is contained in:
@@ -1,118 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace PckStudio.Classes.FileTypes
|
||||
{
|
||||
[Serializable]
|
||||
internal class ModelNotFoundException : Exception
|
||||
{
|
||||
public ModelNotFoundException()
|
||||
{
|
||||
}
|
||||
|
||||
public ModelNotFoundException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public ModelNotFoundException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected ModelNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class ModelFile
|
||||
{
|
||||
public List<Model> Models { get; } = new List<Model>();
|
||||
|
||||
public void AddModel(Model model)
|
||||
{
|
||||
Models.Add(model);
|
||||
}
|
||||
|
||||
bool Contains(string name) => Models.FindIndex(m => m.name == name) > -1;
|
||||
|
||||
/// <exception cref="ModelNotFoundException"></exception>
|
||||
Model GetModelByName(string name)
|
||||
{
|
||||
return Contains(name) ? Models.First(m => m.name.Equals(name)) : throw new ModelNotFoundException(nameof(name));
|
||||
}
|
||||
|
||||
public struct Model
|
||||
{
|
||||
public readonly string name;
|
||||
public Size textureSize;
|
||||
public List<Part> parts { get; } = new List<Part>();
|
||||
|
||||
public Model(string name, int textureWidth, int textureHeight)
|
||||
{
|
||||
this.name = name;
|
||||
textureSize = new Size(textureWidth, textureHeight);
|
||||
}
|
||||
|
||||
public struct Part
|
||||
{
|
||||
public string name;
|
||||
public (float x, float y, float z) position;
|
||||
public (float yaw, float pitch, float roll) rotation;
|
||||
public List<Box> Boxes { get; } = new List<Box>();
|
||||
|
||||
public struct Box
|
||||
{
|
||||
public (float x, float y, float z) Position;
|
||||
public (int width, int height, int length) Size;
|
||||
public float U, V;
|
||||
public float Scale;
|
||||
public bool Mirror;
|
||||
|
||||
public Box((float x, float y, float z) position,
|
||||
(int width, int height, int length) size,
|
||||
float u, float v, float scale, bool mirror)
|
||||
{
|
||||
Position = position;
|
||||
Size = size;
|
||||
U = u;
|
||||
V = v;
|
||||
Scale = scale;
|
||||
Mirror = mirror;
|
||||
}
|
||||
}
|
||||
|
||||
public Part(string name,
|
||||
(float x, float y, float z) pos,
|
||||
(float yaw, float pitch, float roll) rot) : this(name)
|
||||
{
|
||||
position = pos;
|
||||
rotation = rot;
|
||||
}
|
||||
|
||||
public Part(string name)
|
||||
{
|
||||
this.name = name;
|
||||
this.position = (0, 0, 0);
|
||||
this.rotation = (0, 0, 0);
|
||||
}
|
||||
|
||||
public void AddBox((float x, float y, float z) position,
|
||||
(int width, int height, int length) size,
|
||||
float u, float v, float scale, bool mirror)
|
||||
{
|
||||
Boxes.Add(new Box(position, size, u, v, scale, mirror));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void AddPart(Part part)
|
||||
{
|
||||
parts.Add(part);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
using PckStudio.Classes.FileTypes;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace PckStudio.Classes.IO.Model
|
||||
{
|
||||
public class ModelFileReader : StreamDataReader<ModelFile>
|
||||
{
|
||||
public static ModelFile Read(Stream stream)
|
||||
{
|
||||
return new ModelFileReader().ReadFromStream(stream);
|
||||
}
|
||||
|
||||
private ModelFileReader() : base(false)
|
||||
{
|
||||
}
|
||||
|
||||
protected override ModelFile ReadFromStream(Stream stream)
|
||||
{
|
||||
var modelFile = new ModelFile();
|
||||
int version = ReadInt(stream);
|
||||
int modelCount = ReadInt(stream);
|
||||
for (; 0 < modelCount; modelCount--)
|
||||
{
|
||||
string name = ReadString(stream);
|
||||
int width = ReadInt(stream);
|
||||
int height = ReadInt(stream);
|
||||
var model = new ModelFile.Model(name, width, height);
|
||||
|
||||
int partCount = ReadInt(stream);
|
||||
for (; 0 < partCount; partCount--)
|
||||
{
|
||||
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);
|
||||
|
||||
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));
|
||||
if (version > 0)
|
||||
{
|
||||
float _1 = ReadFloat(stream);
|
||||
float _2 = ReadFloat(stream);
|
||||
float _3 = ReadFloat(stream);
|
||||
Debug.WriteLine(string.Format("{0}, {1}, {2}", _1, _2, _3), category: nameof(ModelFileReader));
|
||||
}
|
||||
|
||||
int boxCount = ReadInt(stream);
|
||||
for (; 0 < boxCount; boxCount--)
|
||||
{
|
||||
var pos = (ReadFloat(stream), ReadFloat(stream), ReadFloat(stream));
|
||||
var size = (ReadInt(stream), ReadInt(stream), ReadInt(stream));
|
||||
float u = ReadFloat(stream), v = ReadFloat(stream);
|
||||
float scale = ReadFloat(stream);
|
||||
bool mirrored = ReadBool(stream);
|
||||
part.AddBox(pos, size, u, v, scale, mirrored);
|
||||
}
|
||||
model.AddPart(part);
|
||||
}
|
||||
modelFile.AddModel(model);
|
||||
|
||||
}
|
||||
return modelFile;
|
||||
}
|
||||
|
||||
private string ReadString(Stream stream)
|
||||
{
|
||||
short length = ReadShort(stream);
|
||||
return ReadString(stream, length, Encoding.ASCII);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
using PckStudio.Classes.FileTypes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PckStudio.Classes.IO.Model
|
||||
{
|
||||
internal class ModelFileWriter : StreamDataWriter
|
||||
{
|
||||
private ModelFile _modelFile;
|
||||
private int _fileVersion;
|
||||
public static void Write(Stream stream, ModelFile modelFile, int fileVersion = 1)
|
||||
{
|
||||
new ModelFileWriter(modelFile, fileVersion).WriteToStream(stream);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
WriteInt(stream, _fileVersion);
|
||||
WriteInt(stream, _modelFile.Models.Count);
|
||||
foreach (var model in _modelFile.Models)
|
||||
{
|
||||
WriteString(stream, model.name);
|
||||
WriteInt(stream, model.textureSize.Width);
|
||||
WriteInt(stream, model.textureSize.Height);
|
||||
WriteInt(stream, model.parts.Count);
|
||||
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);
|
||||
|
||||
WriteFloat(stream, part.rotation.yaw);
|
||||
WriteFloat(stream, part.rotation.pitch);
|
||||
WriteFloat(stream, part.rotation.roll);
|
||||
|
||||
if (_fileVersion > 0)
|
||||
{
|
||||
WriteFloat(stream, 0.0f);
|
||||
WriteFloat(stream, 0.0f);
|
||||
WriteFloat(stream, 0.0f);
|
||||
}
|
||||
|
||||
WriteInt(stream, part.Boxes.Count);
|
||||
foreach (var box in part.Boxes)
|
||||
{
|
||||
WriteFloat(stream, box.Position.x);
|
||||
WriteFloat(stream, box.Position.y);
|
||||
WriteFloat(stream, box.Position.z);
|
||||
|
||||
WriteInt(stream, box.Size.width);
|
||||
WriteInt(stream, box.Size.height);
|
||||
WriteInt(stream, box.Size.length);
|
||||
|
||||
WriteFloat(stream, box.U);
|
||||
WriteFloat(stream, box.V);
|
||||
WriteFloat(stream, box.Scale);
|
||||
|
||||
WriteBool(stream, box.Mirror);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteString(Stream stream, string s)
|
||||
{
|
||||
WriteShort(stream, (short)s.Length);
|
||||
WriteString(stream, s, Encoding.ASCII);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,6 @@
|
||||
<Compile Include="Classes\API\PCKCenter\SaveLocalJSON.cs" />
|
||||
<Compile Include="Classes\FileTypes\MaterialsFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\CSMBFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\ModelFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\PCKAudioFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\Binka.cs" />
|
||||
<Compile Include="Classes\FileTypes\CSM.cs" />
|
||||
@@ -180,8 +179,6 @@
|
||||
<Compile Include="Classes\IO\CSMB\CSMBFileWriter.cs" />
|
||||
<Compile Include="Classes\IO\Materials\MaterialsReader.cs" />
|
||||
<Compile Include="Classes\IO\Materials\MaterialsWriter.cs" />
|
||||
<Compile Include="Classes\IO\Model\ModelFileReader.cs" />
|
||||
<Compile Include="Classes\IO\Model\ModelFileWriter.cs" />
|
||||
<Compile Include="Classes\IO\PCK\PCKAudioFileReader.cs" />
|
||||
<Compile Include="Classes\IO\PCK\PCKAudioFileWriter.cs" />
|
||||
<Compile Include="Classes\IO\Sounds\SoundIO.cs" />
|
||||
|
||||
2
Vendor/OMI-Lib
vendored
2
Vendor/OMI-Lib
vendored
Submodule Vendor/OMI-Lib updated: f94605028c...c2207ce4db
Reference in New Issue
Block a user