Compare commits
3 Commits
655a188a69
...
3b9ff6c852
Author | SHA1 | Date |
---|---|---|
Jarrod Doyle | 3b9ff6c852 | |
Jarrod Doyle | f69a98e880 | |
Jarrod Doyle | 505adf5d44 |
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
|
||||
namespace KeepersCompound.LGS.Database.Chunks;
|
||||
|
@ -39,3 +40,37 @@ public class PropertyModelName : IChunk
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -103,6 +103,7 @@ public class DbFile
|
|||
"WREXT" => new WorldRep(),
|
||||
"BRLIST" => new BrList(),
|
||||
"P$ModelName" => new PropertyModelName(),
|
||||
"P$Scale" => new PropertyScale(),
|
||||
"LD$MetaProp" => new LinkDataMetaProp(),
|
||||
_ when entryName.StartsWith("L$") => new LinkChunk(),
|
||||
_ => new GenericChunk(),
|
||||
|
|
|
@ -105,12 +105,14 @@ public partial class Mission : Node3D
|
|||
if (
|
||||
_file.Chunks.TryGetValue("BRLIST", out var brListRaw) &&
|
||||
_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("LD$MetaProp", out var metaPropLinkDataRaw)
|
||||
)
|
||||
{
|
||||
var brList = (BrList)brListRaw;
|
||||
var modelNames = (PropertyModelName)modelNamesRaw;
|
||||
var scales = (PropertyScale)scalesRaw;
|
||||
var metaPropLinks = (LinkChunk)metaPropLinksRaw;
|
||||
var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw;
|
||||
|
||||
|
@ -130,18 +132,20 @@ public partial class Mission : Node3D
|
|||
var gamFile = new DbFile(paths[0]);
|
||||
if (gamFile.Chunks.TryGetValue("P$ModelName", out var gamChunk1) &&
|
||||
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}");
|
||||
modelNames.properties.AddRange(((PropertyModelName)gamChunk1).properties);
|
||||
metaPropLinks.links.AddRange(((LinkChunk)gamChunk2).links);
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlaceObjects(brList, modelNames, metaPropLinks, metaPropLinkData);
|
||||
PlaceObjects(brList, modelNames, scales, metaPropLinks, metaPropLinkData);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,6 +164,7 @@ public partial class Mission : Node3D
|
|||
private void PlaceObjects(
|
||||
BrList brList,
|
||||
PropertyModelName modelNames,
|
||||
PropertyScale scales,
|
||||
LinkChunk metapropLink,
|
||||
LinkDataMetaProp metaPropLinkData)
|
||||
{
|
||||
|
@ -175,20 +180,42 @@ public partial class Mission : Node3D
|
|||
// Determine if we have a model name :))
|
||||
var id = (int)brush.brushInfo;
|
||||
var modelName = "";
|
||||
var scale = Vector3.One;
|
||||
var scaleFound = false;
|
||||
while (true)
|
||||
{
|
||||
// See if there's a modelname property
|
||||
foreach (var prop in modelNames.properties)
|
||||
if (modelName == "")
|
||||
{
|
||||
if (prop.objectId == id)
|
||||
foreach (var prop in modelNames.properties)
|
||||
{
|
||||
modelName = prop.modelName;
|
||||
break;
|
||||
if (prop.objectId == id)
|
||||
{
|
||||
modelName = prop.modelName;
|
||||
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 prevId = id;
|
||||
for (var i = 0; i < length; i++)
|
||||
|
@ -223,7 +250,8 @@ public partial class Mission : Node3D
|
|||
var model = new Model
|
||||
{
|
||||
Position = pos,
|
||||
RotationDegrees = rot
|
||||
RotationDegrees = rot,
|
||||
Scale = scale,
|
||||
};
|
||||
if (objPath != null)
|
||||
{
|
||||
|
|
|
@ -5,8 +5,8 @@ namespace KeepersCompound.TMV;
|
|||
public static class Utils
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue