1
0
mirror of synced 2025-01-31 12:23:52 +01:00

ZSI progress

This commit is contained in:
KillzXGaming 2019-08-02 20:08:51 -04:00
parent 95a50d03ec
commit 9e5e8d72b5
8 changed files with 277 additions and 20 deletions

Binary file not shown.

View File

@ -88,11 +88,12 @@ namespace FirstPlugin
public void Load(System.IO.Stream stream)
{
Renderer = new CMB_Renderer();
DrawableContainer.Name = FileName;
DrawableContainer.Drawables.Add(Renderer);
Skeleton = new STSkeleton();
//These models/skeletons come out massive so scale them with an overridden scale
Skeleton.PreviewScale = Renderer.PreviewScale;
Skeleton.BonePointScale = 40;
DrawableContainer.Drawables.Add(Skeleton);
header = new Header();
@ -100,6 +101,8 @@ namespace FirstPlugin
Text = header.Name;
DrawableContainer.Name = Text;
//Load textures
if (header.SectionData.TextureChunk != null)
{
@ -243,7 +246,7 @@ namespace FirstPlugin
shape.Position.VertexData[v].Y,
shape.Position.VertexData[v].Z);
if (shape.Normal.VertexData != null)
if (shape.Normal.VertexData != null && shape.Normal.VertexData.Length > v)
{
vert.nrm = new OpenTK.Vector3(
shape.Normal.VertexData[v].X,
@ -251,7 +254,7 @@ namespace FirstPlugin
shape.Normal.VertexData[v].Z).Normalized();
}
if (shape.Color.VertexData != null)
if (shape.Color.VertexData != null && shape.Color.VertexData.Length > v)
{
vert.col = new OpenTK.Vector4(
shape.Color.VertexData[v].X,
@ -260,7 +263,7 @@ namespace FirstPlugin
shape.Color.VertexData[v].W).Normalized();
}
if (shape.TexCoord0.VertexData != null)
if (shape.TexCoord0.VertexData != null && shape.TexCoord0.VertexData.Length > v)
{
vert.uv0 = new OpenTK.Vector2(
shape.TexCoord0.VertexData[v].X,

View File

@ -86,50 +86,251 @@ namespace FirstPlugin
string CodeName = reader.ReadString(0x0C);
ReadScene(reader);
var Rooms = ReadRoomHeaders(reader, Version);
foreach (var room in Rooms)
LoadRooms(room, this);
// ReadSceneHeaders(reader, Version);
}
}
private void ReadScene(FileReader reader)
private void LoadRooms(RoomSetup roomSetup, TreeNode parentNode)
{
TreeNode RoomNode = new TreeNode("Room");
parentNode.Nodes.Add(RoomNode);
foreach (var mesh in roomSetup.Meshes)
RoomNode.Nodes.Add(mesh);
foreach (var room in roomSetup.SubSetups)
LoadRooms(room, parentNode);
}
public class Scene
{
public List<RoomSetup> RoomSetups = new List<RoomSetup>();
public List<EnvironmentSettings> EnvironmentSettings = new List<EnvironmentSettings>();
public List<Actor> Doors = new List<Actor>();
public List<string> Rooms = new List<string>();
}
private Scene ReadSceneHeaders(FileReader reader, GameVersion version)
{
Scene scene = new Scene();
int offset = 0;
long pos = reader.Position;
while (true)
{
reader.SeekBegin(pos + offset);
offset += 8;
reader.SetByteOrder(true);
uint cmd1 = reader.ReadUInt32();
reader.SetByteOrder(false);
uint cmd2 = reader.ReadUInt32();
reader.Seek(0x08);
var cmdType = cmd1 >> 24;
if (cmdType == (uint)HeaderCommands.End)
break;
reader.SeekBegin(pos + cmd2);
switch (cmdType)
{
case (uint)HeaderCommands.EnvironmentSettings:
{
Nodes.Add("EnvironmentSettings");
}
int numEnvironmentSettings = ((int)cmd1 >> 16) & 0xFF;
scene.EnvironmentSettings = ReadEnvironmentSettings(reader, version, numEnvironmentSettings);
break;
case (uint)HeaderCommands.DoorActor:
{
Nodes.Add("DoorActor");
}
int numDoorActors = ((int)cmd1 >> 16) & 0xFF;
scene.Doors = ReadDoorActors(reader, version, numDoorActors);
break;
case (uint)HeaderCommands.Rooms:
{
Nodes.Add("Rooms");
}
int numRooms = ((int)cmd1 >> 16) & 0xFF;
scene.Rooms = ReadRooms(reader, version, numRooms);
break;
case (uint)HeaderCommands.SkyboxSettings:
break;
}
}
return scene;
}
public List<EnvironmentSettings> ReadEnvironmentSettings(FileReader reader, GameVersion version, int numSettings)
{
List<EnvironmentSettings> settings = new List<EnvironmentSettings>();
for (int i = 0; i < numSettings; i++)
{
EnvironmentSettings setting = new EnvironmentSettings();
settings.Add(setting);
}
return settings;
}
public List<Actor> ReadDoorActors(FileReader reader, GameVersion version, int numActors)
{
List<Actor> actors = new List<Actor>();
for (int i = 0; i < numActors; i++)
{
Actor actor = new Actor();
actor.RoomFront = reader.ReadByte();
actor.TransitionEffectFront = reader.ReadByte();
actor.RoomBack = reader.ReadByte();
actor.TransitionEffectBack = reader.ReadByte();
actor.ActorID = reader.ReadUInt16();
actor.PositionX = reader.ReadUInt16();
actor.PositionY = reader.ReadUInt16();
actor.PositionZ = reader.ReadUInt16();
actor.RotationY = reader.ReadUInt16();
actor.Variable = reader.ReadUInt16();
actors.Add(actor);
}
return actors;
}
private List<string> ReadRooms(FileReader reader, GameVersion version, int numRooms)
{
List<string> rooms = new List<string>();
var roomSize = version == GameVersion.OOT3D ? 0x44 : 0x34;
long pos = reader.Position;
for (int i = 0; i < numRooms; i++)
{
reader.SeekBegin(pos + (i * roomSize));
rooms.Add(reader.ReadZeroTerminatedString());
}
return rooms;
}
/* private List<RoomSetup> ReadRooms(FileReader reader, GameVersion version, int numRooms)
{
List<RoomSetup> rooms = new List<RoomSetup>();
var roomSize = version == GameVersion.OOT3D ? 0x44 : 0x34;
long pos = reader.Position;
for (int i = 0; i < numRooms; i++)
{
reader.SeekBegin(pos + (i * roomSize));
rooms.AddRange(ReadRoomHeaders(reader, version));
}
return rooms;
}*/
private List<RoomSetup> ReadRoomHeaders(FileReader reader, GameVersion version)
{
List<RoomSetup> roomSetups = new List<RoomSetup>();
int offset = 0;
long pos = reader.Position;
while (true)
{
reader.SeekBegin(pos + offset);
offset += 8;
reader.SetByteOrder(true);
uint cmd1 = reader.ReadUInt32();
reader.SetByteOrder(false);
uint cmd2 = reader.ReadUInt32();
var cmdType = cmd1 >> 24;
if (cmdType == (uint)HeaderCommands.End)
break;
RoomSetup setup = new RoomSetup();
roomSetups.Add(setup);
Console.WriteLine((HeaderCommands)cmdType);
Console.WriteLine("cmd2 " + cmd2 + " start " + pos);
switch (cmdType)
{
case (uint)HeaderCommands.MultiSetup:
{
Nodes.Add("SkyboxSettings");
int numSetups = ((int)cmd1 >> 16) & 0xFF;
reader.SeekBegin(pos + cmd2);
for (int i = 0; i < numSetups; i++)
{
uint setupOffset = reader.ReadUInt32();
if (setupOffset == 0)
continue;
using (reader.TemporarySeek(pos + setupOffset, System.IO.SeekOrigin.Begin))
{
var subsetups = ReadRoomHeaders(reader, version);
setup.SubSetups.AddRange(subsetups);
}
}
}
break;
case (uint)HeaderCommands.Actor:
{
int numActors = ((int)cmd1 >> 16) & 0xFF;
reader.SeekBegin(pos + cmd2);
setup.Actors = ReadActors(reader, version, numActors);
}
break;
case (uint)HeaderCommands.Mesh:
{
reader.SeekBegin(pos + cmd2);
setup.Meshes = ReadMesh(reader);
}
break;
}
}
return roomSetups;
}
private List<Actor> ReadActors(FileReader reader, GameVersion verion, int numActors)
{
List<Actor> actors = new List<Actor>();
return actors;
}
private List<CMB> ReadMesh(FileReader reader )
{
List<CMB> Models = new List<CMB>();
reader.SetByteOrder(true);
uint flags = reader.ReadUInt32();
reader.SetByteOrder(false);
int meshType = ((int)flags >> 24);
int numMeshes = ((int)flags >> 16) & 0xFF;
int meshOffset = reader.ReadInt32();
if (numMeshes == 0x00)
return Models;
//There should be 1 or 2 meshes, (opaque and transparent)
if (numMeshes != 2 && numMeshes != 1)
throw new Exception($"Unexpected mesh count {numMeshes}. Expected 1 or 2");
if (meshType != 2)
throw new Exception($"Unexpected mesh tye {meshType}. Expected 2");
reader.SeekBegin(meshOffset + 32); //Relative to end of header
uint magic = reader.ReadUInt32();
uint fileSize = reader.ReadUInt32();
CMB cmb = new CMB();
cmb.IFileInfo = new IFileInfo();
cmb.Load(new System.IO.MemoryStream(reader.getSection((uint)meshOffset + 32, fileSize)));
Models.Add(cmb);
return Models;
}
public void Unload()
@ -141,5 +342,34 @@ namespace FirstPlugin
{
return null;
}
public class RoomSetup
{
public List<Actor> Actors = new List<Actor>();
public List<RoomSetup> SubSetups = new List<RoomSetup>();
public List<CMB> Meshes = new List<CMB>();
}
public class EnvironmentSettings
{
}
public class Actor
{
public byte RoomFront { get; set; }
public byte TransitionEffectFront { get; set; }
public byte RoomBack { get; set; }
public byte TransitionEffectBack { get; set; }
public ushort ActorID { get; set; }
public ushort PositionX;
public ushort PositionY;
public ushort PositionZ;
public ushort RotationY;
public ushort Variable;
}
}
}

View File

@ -357,6 +357,7 @@ namespace FirstPlugin
Formats.Add(typeof(G1T));
Formats.Add(typeof(BFLYT));
Formats.Add(typeof(CMB));
Formats.Add(typeof(ZSI));
//Unfinished wip formats not ready for use
if (Runtime.DEVELOPER_DEBUG_MODE)
@ -367,7 +368,6 @@ namespace FirstPlugin
Formats.Add(typeof(BFSAR));
Formats.Add(typeof(GFA));
Formats.Add(typeof(G1M));
Formats.Add(typeof(ZSI));
Formats.Add(typeof(MSBP));
}

View File

@ -21,6 +21,8 @@ namespace Toolbox.Library
{
public virtual float PreviewScale { get; set; } = 1.0f;
public virtual float BonePointScale { get; set; } = 1.0f;
public Vector3 position = new Vector3(0, 0, 0);
protected bool Selected = false;
@ -221,7 +223,7 @@ namespace Toolbox.Library
continue;
shader.SetVector4("boneColor", ColorUtility.ToVector4(boneColor));
shader.SetFloat("scale", Runtime.bonePointSize);
shader.SetFloat("scale", Runtime.bonePointSize * BonePointScale);
shader.SetMatrix4x4("ModelMatrix", ref bn.ModelMatrix);

View File

@ -58,6 +58,28 @@ namespace Toolbox.Library.IO
return signature == Identifier;
}
public int ReadInt32(int position)
{
long origin = this.Position;
SeekBegin(position);
int value = ReadInt32();
SeekBegin(origin + sizeof(int));
return value;
}
public uint ReadUInt32(int position)
{
long origin = this.Position;
SeekBegin(position);
uint value = ReadUInt32();
SeekBegin(origin + sizeof(uint));
return value;
}
public string ReadNameOffset(bool IsRelative, Type OffsetType, bool ReadNameLength = false, bool IsNameLengthShort = false)
{
long pos = Position;