diff --git a/Assets/Scripts/Game/Entity.cs b/Assets/Scripts/Game/Entity.cs index 9b27ff5..d61fbb8 100644 --- a/Assets/Scripts/Game/Entity.cs +++ b/Assets/Scripts/Game/Entity.cs @@ -143,7 +143,8 @@ public class Entity meshRenderer.enabled = true; } - var textures = aliasModel.Textures; - visualStyle.SetAliasModelTextures(material, textures.MainTexture, textures.FullBrightTexture); + var textures = aliasModel.Textures.PrimaryTextures; + if (textures != null) + visualStyle.SetAliasModelTextures(material, textures.MainTexture, textures.FullBrightTexture); } } diff --git a/Assets/Scripts/Modules/RenderModule.cs b/Assets/Scripts/Modules/RenderModule.cs index ac6bf8e..9470c54 100644 --- a/Assets/Scripts/Modules/RenderModule.cs +++ b/Assets/Scripts/Modules/RenderModule.cs @@ -20,25 +20,10 @@ public partial class RenderModule AliasModel aliasModel = new AliasModel(name, header, frameType); aliasModel.ImportMeshData(poseVertices, triangles, stVertices); + aliasModel.Textures.Import(uq.GameAssets, glTextures, fbTextures); uq.GameAssets.AddAliasModel(aliasModel); - // DEBUG kept for reference for the moment, how to address skins & texture frames, and full-bright textures - uint texNum = glTextures[0][0].texNum; - if (uq.GameAssets.TryGetTexture(texNum, out var texture)) - { - aliasModel.Textures.MainTexture = texture; - } - - if (fbTextures != null && fbTextures[0] != null && fbTextures[0][0] != null) - { - var fbTexNum = fbTextures[0][0].texNum; - if (uq.GameAssets.TryGetTexture(fbTexNum, out var fbTexture)) - { - aliasModel.Textures.FullBrightTexture = fbTexture; - } - } - return 1; } diff --git a/Assets/Scripts/Support/TextureSet.cs b/Assets/Scripts/Support/TextureSet.cs index fbdf58e..6332133 100644 --- a/Assets/Scripts/Support/TextureSet.cs +++ b/Assets/Scripts/Support/TextureSet.cs @@ -4,9 +4,79 @@ using UnityEngine; public class TextureSet { - public Texture2D MainTexture { get; set; } - - public Texture2D FullBrightTexture { get; set; } + public List Skins { get; } = new List(); + + public TexturePair PrimaryTextures => Skins.Count > 0 && Skins[0].Frames.Count > 0 ? Skins[0].Frames[0] : null; + + public bool Import(GameAssets assets, QGLTexture[][] textures, QGLTexture[][] fullBrights) + { + if (textures == null) + return false; + + for (int skinIndex = 0; skinIndex < textures.Length; skinIndex++) + { + if (textures[skinIndex] == null) + break; + + var skin = new TextureSkin(); + if (skin.Import(assets, textures[skinIndex], + fullBrights != null && skinIndex < fullBrights.Length ? fullBrights[skinIndex] : null)) + { + Skins.Add(skin); + } + } + + return true; + } +} + +public class TextureSkin +{ + public List Frames { get; } = new List(); + + public bool Import(GameAssets assets, QGLTexture[] textures, QGLTexture[] fullBrights) + { + if (textures == null) + return false; + + for (int frameIndex = 0; frameIndex < textures.Length; frameIndex++) + { + if (textures[frameIndex] == null) + break; + + var frame = new TexturePair(); + if (frame.Import(assets, textures[frameIndex], + fullBrights != null && frameIndex < fullBrights.Length ? fullBrights[frameIndex] : null)) + { + Frames.Add(frame); + } + } + + return true; + } +} + +public class TexturePair +{ + public Texture2D MainTexture { get; private set; } - // TODO: organize into skins, frames/groups + public Texture2D FullBrightTexture { get; private set; } + + public bool Import(GameAssets assets, QGLTexture texture, QGLTexture fullBright) + { + if (texture == null) + return false; + + if (assets.TryGetTexture(texture.texNum, out var mainTexture)) + { + MainTexture = mainTexture; + } + + if (fullBright != null && assets.TryGetTexture(fullBright.texNum, out var fullBrightTexture)) + { + FullBrightTexture = fullBrightTexture; + } + + return true; + } }