Apply TxtRepl properties

This commit is contained in:
Jarrod Doyle 2024-08-31 12:00:07 +01:00
parent ab34a78739
commit 4ab115440c
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 48 additions and 0 deletions

View File

@ -232,6 +232,10 @@ public partial class Mission : Node3D
var modelNameProp = objHierarchy.GetProperty<PropModelName>(id, "P$ModelName"); var modelNameProp = objHierarchy.GetProperty<PropModelName>(id, "P$ModelName");
var scaleProp = objHierarchy.GetProperty<PropScale>(id, "P$Scale"); var scaleProp = objHierarchy.GetProperty<PropScale>(id, "P$Scale");
var renderTypeProp = objHierarchy.GetProperty<PropRenderType>(id, "P$RenderTyp"); var renderTypeProp = objHierarchy.GetProperty<PropRenderType>(id, "P$RenderTyp");
var txtRepl0 = objHierarchy.GetProperty<PropString>(id, "P$OTxtRepr0");
var txtRepl1 = objHierarchy.GetProperty<PropString>(id, "P$OTxtRepr1");
var txtRepl2 = objHierarchy.GetProperty<PropString>(id, "P$OTxtRepr2");
var txtRepl3 = objHierarchy.GetProperty<PropString>(id, "P$OTxtRepr3");
var renderMode = renderTypeProp == null ? PropRenderType.Mode.Normal : renderTypeProp.mode; var renderMode = renderTypeProp == null ? PropRenderType.Mode.Normal : renderTypeProp.mode;
if (modelNameProp == null || renderMode == PropRenderType.Mode.NotRendered) if (modelNameProp == null || renderMode == PropRenderType.Mode.NotRendered)
@ -251,6 +255,50 @@ public partial class Mission : Node3D
model.Position = pos; model.Position = pos;
model.RotationDegrees = rot; model.RotationDegrees = rot;
model.Scale = scale; model.Scale = scale;
bool GetTextReplPath(PropString prop, out string path)
{
path = "";
if (prop == null)
{
return false;
}
path = prop.value;
if (path.StartsWith("fam", StringComparison.OrdinalIgnoreCase))
{
path = _installPaths.GetTexturePath(_campaignName, path);
return path != null;
}
// gonna assume obj lol
path = _installPaths.GetObjectTexturePath(_campaignName, path);
return path != null;
}
var repls = new PropString[] { txtRepl0, txtRepl1, txtRepl2, txtRepl3 };
for (var i = 0; i < 4; i++)
{
if (GetTextReplPath(repls[i], out var path))
{
var overrideMat = new StandardMaterial3D
{
AlbedoTexture = TextureLoader.LoadTexture(path)
};
var surfaceCount = model.Mesh.GetSurfaceCount();
for (var idx = 0; idx < surfaceCount; idx++)
{
var surfaceMat = model.Mesh.SurfaceGetMaterial(idx);
if (surfaceMat.HasMeta($"TxtRepl{i}"))
{
model.SetSurfaceOverrideMaterial(idx, overrideMat);
}
}
}
}
AddChild(model); AddChild(model);
} }
} }