mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2025-01-09 23:03:27 +08:00
Fixed embedded textures replacement from ModelForm
This commit is contained in:
parent
8ea3327810
commit
19565e7d74
@ -1349,6 +1349,115 @@ namespace CodeWalker.Forms
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void UpdateEmbeddedTextures(DrawableBase dwbl)
|
||||
{
|
||||
if (dwbl == null) return;
|
||||
|
||||
var sg = dwbl.ShaderGroup;
|
||||
var td = sg?.TextureDictionary;
|
||||
var sd = sg?.Shaders?.data_items;
|
||||
|
||||
if (td == null) return;
|
||||
if (sd == null) return;
|
||||
|
||||
var updated = false;
|
||||
foreach (var s in sd)
|
||||
{
|
||||
if (s?.ParametersList == null) continue;
|
||||
foreach (var p in s.ParametersList.Parameters)
|
||||
{
|
||||
if (p.Data is TextureBase tex)
|
||||
{
|
||||
var tex2 = td.Lookup(tex.NameHash);
|
||||
if ((tex2 != null) && (tex != tex2))
|
||||
{
|
||||
p.Data = tex2;//swap the parameter out for the new embedded texture
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!updated) return;
|
||||
|
||||
foreach (var model in dwbl.AllModels)
|
||||
{
|
||||
if (model?.Geometries == null) continue;
|
||||
foreach (var geom in model.Geometries)
|
||||
{
|
||||
geom.UpdateRenderableParameters = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void UpdateEmbeddedTextures()
|
||||
{
|
||||
if (Ydr != null)
|
||||
{
|
||||
if (Ydr.Loaded)
|
||||
{
|
||||
UpdateEmbeddedTextures(Ydr.Drawable);
|
||||
}
|
||||
}
|
||||
else if (Ydd != null)
|
||||
{
|
||||
if (Ydd.Loaded)
|
||||
{
|
||||
foreach (var kvp in Ydd.Dict)
|
||||
{
|
||||
UpdateEmbeddedTextures(kvp.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Ypt != null)
|
||||
{
|
||||
if ((Ypt.Loaded) && (Ypt.DrawableDict != null))
|
||||
{
|
||||
foreach (var kvp in Ypt.DrawableDict)
|
||||
{
|
||||
UpdateEmbeddedTextures(kvp.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Yft != null)
|
||||
{
|
||||
if (Yft.Loaded)
|
||||
{
|
||||
if (Yft.Fragment != null)
|
||||
{
|
||||
var f = Yft.Fragment;
|
||||
|
||||
UpdateEmbeddedTextures(f.Drawable);
|
||||
UpdateEmbeddedTextures(f.DrawableCloth);
|
||||
|
||||
if (f.DrawableArray?.data_items != null)
|
||||
{
|
||||
foreach (var d in f.DrawableArray.data_items)
|
||||
{
|
||||
UpdateEmbeddedTextures(d);
|
||||
}
|
||||
}
|
||||
|
||||
var c = f.PhysicsLODGroup?.PhysicsLOD1?.Children?.data_items;
|
||||
if (c != null)
|
||||
{
|
||||
foreach (var child in c)
|
||||
{
|
||||
if (child != null)
|
||||
{
|
||||
UpdateEmbeddedTextures(child.Drawable1);
|
||||
UpdateEmbeddedTextures(child.Drawable2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnLightFormClosed()
|
||||
{
|
||||
lightForm = null;
|
||||
@ -2077,10 +2186,9 @@ namespace CodeWalker.Forms
|
||||
|
||||
if (td != null)
|
||||
{
|
||||
YtdForm f = new YtdForm();
|
||||
f.Show();
|
||||
YtdForm f = new YtdForm(null, this);
|
||||
f.Show(this);
|
||||
f.LoadTexDict(td, fileName);
|
||||
//f.LoadYtd(ytd);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -250,6 +250,9 @@ namespace CodeWalker.Forms
|
||||
|
||||
tex.Name = CurrentTexture.Name;
|
||||
tex.NameHash = CurrentTexture.NameHash;
|
||||
tex.Usage = CurrentTexture.Usage;
|
||||
tex.UsageFlags = CurrentTexture.UsageFlags;
|
||||
tex.Unknown_32h = CurrentTexture.Unknown_32h;
|
||||
|
||||
var textures = new List<Texture>();
|
||||
foreach (var t in TexDict.Textures.data_items)
|
||||
@ -337,7 +340,7 @@ namespace CodeWalker.Forms
|
||||
{
|
||||
if (ModelForm == null) return;
|
||||
|
||||
//TODO: live update of model form view when changes have been made...
|
||||
ModelForm.UpdateEmbeddedTextures();
|
||||
}
|
||||
|
||||
private void UpdateFormTitle()
|
||||
|
Loading…
Reference in New Issue
Block a user