Compare commits

...

3 Commits

Author SHA1 Message Date
Jarrod Doyle 3b9ff6c852
Jankily read scale in for models 2024-08-25 11:54:33 +01:00
Jarrod Doyle f69a98e880
Let vec3 conversion skip scaling 2024-08-25 11:54:21 +01:00
Jarrod Doyle 505adf5d44
Add scale property support 2024-08-25 11:53:50 +01:00
4 changed files with 75 additions and 11 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Numerics;
using System.Text; using System.Text;
namespace KeepersCompound.LGS.Database.Chunks; namespace KeepersCompound.LGS.Database.Chunks;
@ -39,3 +40,37 @@ public class PropertyModelName : IChunk
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
} }
public class PropertyScale : IChunk
{
public record Property
{
public int objectId;
public int length;
public Vector3 scale;
public Property(BinaryReader reader)
{
objectId = reader.ReadInt32();
length = (int)reader.ReadUInt32();
scale = reader.ReadVec3();
}
}
public ChunkHeader Header { get; set; }
public List<Property> properties;
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
{
properties = new List<Property>();
while (reader.BaseStream.Position < entry.Offset + entry.Size + 24)
{
properties.Add(new Property(reader));
}
}
public void WriteData(BinaryWriter writer)
{
throw new System.NotImplementedException();
}
}

View File

@ -103,6 +103,7 @@ public class DbFile
"WREXT" => new WorldRep(), "WREXT" => new WorldRep(),
"BRLIST" => new BrList(), "BRLIST" => new BrList(),
"P$ModelName" => new PropertyModelName(), "P$ModelName" => new PropertyModelName(),
"P$Scale" => new PropertyScale(),
"LD$MetaProp" => new LinkDataMetaProp(), "LD$MetaProp" => new LinkDataMetaProp(),
_ when entryName.StartsWith("L$") => new LinkChunk(), _ when entryName.StartsWith("L$") => new LinkChunk(),
_ => new GenericChunk(), _ => new GenericChunk(),

View File

@ -105,12 +105,14 @@ public partial class Mission : Node3D
if ( if (
_file.Chunks.TryGetValue("BRLIST", out var brListRaw) && _file.Chunks.TryGetValue("BRLIST", out var brListRaw) &&
_file.Chunks.TryGetValue("P$ModelName", out var modelNamesRaw) && _file.Chunks.TryGetValue("P$ModelName", out var modelNamesRaw) &&
_file.Chunks.TryGetValue("P$Scale", out var scalesRaw) &&
_file.Chunks.TryGetValue("L$MetaProp", out var metaPropLinksRaw) && _file.Chunks.TryGetValue("L$MetaProp", out var metaPropLinksRaw) &&
_file.Chunks.TryGetValue("LD$MetaProp", out var metaPropLinkDataRaw) _file.Chunks.TryGetValue("LD$MetaProp", out var metaPropLinkDataRaw)
) )
{ {
var brList = (BrList)brListRaw; var brList = (BrList)brListRaw;
var modelNames = (PropertyModelName)modelNamesRaw; var modelNames = (PropertyModelName)modelNamesRaw;
var scales = (PropertyScale)scalesRaw;
var metaPropLinks = (LinkChunk)metaPropLinksRaw; var metaPropLinks = (LinkChunk)metaPropLinksRaw;
var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw; var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw;
@ -130,18 +132,20 @@ public partial class Mission : Node3D
var gamFile = new DbFile(paths[0]); var gamFile = new DbFile(paths[0]);
if (gamFile.Chunks.TryGetValue("P$ModelName", out var gamChunk1) && if (gamFile.Chunks.TryGetValue("P$ModelName", out var gamChunk1) &&
gamFile.Chunks.TryGetValue("L$MetaProp", out var gamChunk2) && gamFile.Chunks.TryGetValue("L$MetaProp", out var gamChunk2) &&
gamFile.Chunks.TryGetValue("LD$MetaProp", out var gamChunk3)) gamFile.Chunks.TryGetValue("LD$MetaProp", out var gamChunk3) &&
gamFile.Chunks.TryGetValue("P$Scale", out var gamChunk4))
{ {
GD.Print($"Pre-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}"); GD.Print($"Pre-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}");
modelNames.properties.AddRange(((PropertyModelName)gamChunk1).properties); modelNames.properties.AddRange(((PropertyModelName)gamChunk1).properties);
metaPropLinks.links.AddRange(((LinkChunk)gamChunk2).links); metaPropLinks.links.AddRange(((LinkChunk)gamChunk2).links);
metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamChunk3).linkData); metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamChunk3).linkData);
scales.properties.AddRange(((PropertyScale)gamChunk4).properties);
GD.Print($"Post-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}"); GD.Print($"Post-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}");
} }
} }
} }
PlaceObjects(brList, modelNames, metaPropLinks, metaPropLinkData); PlaceObjects(brList, modelNames, scales, metaPropLinks, metaPropLinkData);
} }
} }
@ -160,6 +164,7 @@ public partial class Mission : Node3D
private void PlaceObjects( private void PlaceObjects(
BrList brList, BrList brList,
PropertyModelName modelNames, PropertyModelName modelNames,
PropertyScale scales,
LinkChunk metapropLink, LinkChunk metapropLink,
LinkDataMetaProp metaPropLinkData) LinkDataMetaProp metaPropLinkData)
{ {
@ -175,9 +180,13 @@ public partial class Mission : Node3D
// Determine if we have a model name :)) // Determine if we have a model name :))
var id = (int)brush.brushInfo; var id = (int)brush.brushInfo;
var modelName = ""; var modelName = "";
var scale = Vector3.One;
var scaleFound = false;
while (true) while (true)
{ {
// See if there's a modelname property // See if there's a modelname property
if (modelName == "")
{
foreach (var prop in modelNames.properties) foreach (var prop in modelNames.properties)
{ {
if (prop.objectId == id) if (prop.objectId == id)
@ -186,9 +195,27 @@ public partial class Mission : Node3D
break; break;
} }
} }
if (modelName != "") break; }
// No modelname so check for a parent if (!scaleFound)
{
foreach (var prop in scales.properties)
{
if (prop.objectId == id)
{
scale = prop.scale.ToGodotVec3(false);
scaleFound = true;
break;
}
}
}
if (modelName != "" && scaleFound)
{
break;
}
// Check for a parent
var length = metapropLink.links.Count; var length = metapropLink.links.Count;
var prevId = id; var prevId = id;
for (var i = 0; i < length; i++) for (var i = 0; i < length; i++)
@ -223,7 +250,8 @@ public partial class Mission : Node3D
var model = new Model var model = new Model
{ {
Position = pos, Position = pos,
RotationDegrees = rot RotationDegrees = rot,
Scale = scale,
}; };
if (objPath != null) if (objPath != null)
{ {

View File

@ -5,8 +5,8 @@ namespace KeepersCompound.TMV;
public static class Utils public static class Utils
{ {
const float InverseScale = 4.0f; const float InverseScale = 4.0f;
public static Godot.Vector3 ToGodotVec3(this Vector3 vec) public static Godot.Vector3 ToGodotVec3(this Vector3 vec, bool scale = true)
{ {
return new Godot.Vector3(vec.Y, vec.Z, vec.X) / InverseScale; return new Godot.Vector3(vec.Y, vec.Z, vec.X) / (scale ? InverseScale : 1.0f);
} }
} }