Skip to content

Commit

Permalink
Фикс непонятной поломки моделей, фикс поломки статических моделей пос…
Browse files Browse the repository at this point in the history
…ле удаления мешей
  • Loading branch information
VaIeroK committed Nov 10, 2022
1 parent 6bdc76f commit d932457
Show file tree
Hide file tree
Showing 11 changed files with 797 additions and 1,368 deletions.
61 changes: 61 additions & 0 deletions OGF tool/Classes/Collision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;

namespace OGF_tool
{
public class BBox
{
public float[] min;
public float[] max;

public BBox()
{
min = new float[3];
max = new float[3];
}

public void Load(XRayLoader xr_loader)
{
min = xr_loader.ReadVector();
max = xr_loader.ReadVector();
}

public byte[] data()
{
List<byte> temp = new List<byte>();

temp.AddRange(FVec.GetBytes(min));
temp.AddRange(FVec.GetBytes(max));

return temp.ToArray();
}
};

public class BSphere
{
public float[] c;
public float r;

public BSphere()
{
c = new float[3];
r = 0.0f;
}

public void Load(XRayLoader xr_loader)
{
c = xr_loader.ReadVector();
r = xr_loader.ReadFloat();
}

public byte[] data()
{
List<byte> temp = new List<byte>();

temp.AddRange(FVec.GetBytes(c));
temp.AddRange(BitConverter.GetBytes(r));

return temp.ToArray();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,113 +4,6 @@

namespace OGF_tool
{
public class BBox
{
public float[] min;
public float[] max;

public BBox()
{
min = new float[3];
max = new float[3];
}

public void Load(XRayLoader xr_loader)
{
min = xr_loader.ReadVector();
max = xr_loader.ReadVector();
}

public byte[] data()
{
List<byte> temp = new List<byte>();

temp.AddRange(FVec.GetBytes(min));
temp.AddRange(FVec.GetBytes(max));

return temp.ToArray();
}
};

public class BSphere
{
public float[] c;
public float r;

public BSphere()
{
c = new float[3];
r = 0.0f;
}

public void Load(XRayLoader xr_loader)
{
c = xr_loader.ReadVector();
r = xr_loader.ReadFloat();
}

public byte[] data()
{
List<byte> temp = new List<byte>();

temp.AddRange(FVec.GetBytes(c));
temp.AddRange(BitConverter.GetBytes(r));

return temp.ToArray();
}
};

public class OGF_Header
{
public byte format_version;
public byte type;
public short shader_id;
public BBox bb;
public BSphere bs;

public OGF_Header()
{
bb = new BBox();
bs = new BSphere();
format_version = 4;
type = 0;
shader_id = 0;
}

public void Load(XRayLoader xr_loader)
{
format_version = xr_loader.ReadByte();
type = xr_loader.ReadByte();
shader_id = (short)xr_loader.ReadUInt16();

if (format_version == 4)
{
bb.Load(xr_loader);
bs.Load(xr_loader);
}
}

public byte[] data()
{
List<byte> temp = new List<byte>();

temp.AddRange(BitConverter.GetBytes((uint)OGF.OGF_HEADER));
temp.AddRange(BitConverter.GetBytes((format_version == 4 ? 44 : 4)));

temp.Add(format_version);
temp.Add(type);
temp.AddRange(BitConverter.GetBytes(shader_id));

if (format_version == 4)
{
temp.AddRange(bb.data());
temp.AddRange(bs.data());
}

return temp.ToArray();
}
};

public class OGF_Child
{
public string m_texture;
Expand Down Expand Up @@ -306,6 +199,11 @@ public bool Load(XRayLoader xr_loader)
FVF = links = xr_loader.ReadUInt32();
uint verts = xr_loader.ReadUInt32();

if (Header.IsStaticSingle())
links = 0;
else
FVF = 0;

for (int i = 0; i < verts; i++)
{
SSkelVert Vert = new SSkelVert();
Expand Down Expand Up @@ -353,7 +251,6 @@ public bool Load(XRayLoader xr_loader)
Vert.offs = xr_loader.ReadVector();
Vert.norm = xr_loader.ReadVector();
Vert.uv = xr_loader.ReadVector2();
links = 0;
break;
}
Vertices.Add(Vert);
Expand Down Expand Up @@ -482,10 +379,19 @@ private byte[] GetVertsChunk()
{
List<byte> temp = new List<byte>();

if (LinksCount() == 0)
if (Header.IsStaticSingle())
temp.AddRange(BitConverter.GetBytes(FVF));
else
{
if (links == 0)
{
AutoClosingMessageBox.Show("Error! Links in dynamic model should not be a zero. Set to 1.", "Error", 10000, System.Windows.Forms.MessageBoxIcon.Error);
links = 1;
}

temp.AddRange(BitConverter.GetBytes(links));
}

temp.AddRange(BitConverter.GetBytes(Vertices.Count));

for (int i = 0; i < Vertices.Count; i++)
Expand Down
141 changes: 141 additions & 0 deletions OGF tool/Classes/OGF Chunks/Header.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;

namespace OGF_tool
{
public class OGF_Header
{
public byte format_version;
public byte type;
public short shader_id;
public BBox bb;
public BSphere bs;

public OGF_Header()
{
bb = new BBox();
bs = new BSphere();
format_version = 4;
type = 0;
shader_id = 0;
}

public void Load(XRayLoader xr_loader)
{
format_version = xr_loader.ReadByte();
type = xr_loader.ReadByte();
shader_id = (short)xr_loader.ReadUInt16();

if (format_version == 4)
{
bb.Load(xr_loader);
bs.Load(xr_loader);
}
}

public byte[] data()
{
List<byte> temp = new List<byte>();

temp.AddRange(BitConverter.GetBytes((uint)OGF.OGF_HEADER));
temp.AddRange(BitConverter.GetBytes((format_version == 4 ? 44 : 4)));

temp.Add(format_version);
temp.Add(type);
temp.AddRange(BitConverter.GetBytes(shader_id));

if (format_version == 4)
{
temp.AddRange(bb.data());
temp.AddRange(bs.data());
}

return temp.ToArray();
}

public bool IsProgressive()
{
if (format_version == 4)
return type == (byte)ModelType.MT4_PROGRESSIVE || type == (byte)ModelType.MT4_SKELETON_GEOMDEF_PM;
else
return type == (byte)ModelType.MT3_PROGRESSIVE || type == (byte)ModelType.MT3_SKELETON_GEOMDEF_PM;
}

public bool IsSkeleton()
{
if (format_version == 4)
return type == (byte)ModelType.MT4_SKELETON_ANIM || type == (byte)ModelType.MT4_SKELETON_RIGID;
else
return type == (byte)ModelType.MT3_SKELETON_ANIM || type == (byte)ModelType.MT3_SKELETON_RIGID;
}

public bool IsAnimated()
{
if (format_version == 4)
return type == (byte)ModelType.MT4_SKELETON_ANIM;
else
return type == (byte)ModelType.MT3_SKELETON_ANIM;
}

public bool IsStatic()
{
if (format_version == 4)
return type == (byte)ModelType.MT4_HIERRARHY;
else
return type == (byte)ModelType.MT3_HIERRARHY;
}

public bool IsStaticSingle()
{
if (format_version == 4)
return type == (byte)ModelType.MT4_NORMAL || type == (byte)ModelType.MT4_PROGRESSIVE;
else
return type == (byte)ModelType.MT3_NORMAL || type == (byte)ModelType.MT3_PROGRESSIVE || type == (byte)ModelType.MT3_PROGRESSIVE2;
}

public byte Skeleton()
{
if (format_version == 4)
return (byte)ModelType.MT4_SKELETON_RIGID;
else
return (byte)ModelType.MT3_SKELETON_RIGID;
}


public void Animated()
{
if (format_version == 4)
type = (byte)ModelType.MT4_SKELETON_ANIM;
else
type = (byte)ModelType.MT3_SKELETON_ANIM;
}

public void Static(List<OGF_Child> childs)
{
if (childs.Count == 1)
{
StaticSingle(childs);
return;
}

if (format_version == 4)
type = (byte)ModelType.MT4_HIERRARHY;
else
type = (byte)ModelType.MT3_HIERRARHY;
}

public void StaticSingle(List<OGF_Child> childs)
{
if (childs.Count > 1)
{
Static(childs);
return;
}

if (format_version == 4)
type = (childs[0].SWI.Count > 0) ? (byte)ModelType.MT4_PROGRESSIVE : (byte)ModelType.MT4_NORMAL;
else
type = (childs[0].SWI.Count > 0) ? (byte)ModelType.MT3_PROGRESSIVE : (byte)ModelType.MT3_NORMAL;
}
};
}
Loading

0 comments on commit d932457

Please sign in to comment.