mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2026-08-15 02:57:49 +04:00
fix textures UV. drop leftovers. properly map material_lo.
This commit is contained in:
@@ -88,7 +88,7 @@ public static class MshRestPoseBuilder
|
||||
{
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(node.ParentIndexOrMinusOne);
|
||||
return Convert.ToInt32(node.ParentIndexOrLink);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -134,7 +134,7 @@ public static class MshViewportLoader
|
||||
var outIndices = new List<uint>();
|
||||
var batchTriangleCount = 0;
|
||||
|
||||
var material = materialLibrary.FindMaterial(batch.MaterialIndex) ?? ViewportMaterial.Untextured;
|
||||
var material = materialLibrary.FindMaterial(batch.MaterialIndexLo) ?? ViewportMaterial.Untextured;
|
||||
var vertexColor = material.HasTexture ? Vector3.One : debugColor;
|
||||
|
||||
for (var i = 0; i + 2 < batch.IndexCount0x06; i += 3)
|
||||
@@ -156,7 +156,7 @@ public static class MshViewportLoader
|
||||
normal = Vector3.UnitY;
|
||||
else
|
||||
normal = Vector3.Normalize(normal);
|
||||
|
||||
|
||||
AddTriangleVertex(p0, vertexColor, normal, GetUv(uvs, vertexIndex0), vertices, outIndices, ref boundsMin, ref boundsMax);
|
||||
AddTriangleVertex(p1, vertexColor, normal, GetUv(uvs, vertexIndex1), vertices, outIndices, ref boundsMin, ref boundsMax);
|
||||
AddTriangleVertex(p2, vertexColor, normal, GetUv(uvs, vertexIndex2), vertices, outIndices, ref boundsMin, ref boundsMax);
|
||||
@@ -183,7 +183,7 @@ public static class MshViewportLoader
|
||||
return Vector2.Zero;
|
||||
|
||||
var uv = uvs[vertexIndex];
|
||||
return new Vector2(uv.U / 1024.0f, 1.0f - uv.V / 1024.0f);
|
||||
return new Vector2(uv.U / 1024.0f, uv.V / 1024.0f);
|
||||
}
|
||||
|
||||
private static Vector3 ToNumericsVector3(Common.Vector3 position)
|
||||
|
||||
@@ -46,9 +46,9 @@ public sealed class WeaMaterialLibrary
|
||||
|
||||
foreach (var materialRef in materialRefs)
|
||||
{
|
||||
var texture = TryLoadMaterialTexture(gl, materialFs, parseResult.Archive, materialRef.Name);
|
||||
var texture = TryLoadMaterialTexture(gl, materialFs, parseResult.Archive, materialRef.Name, out var texm);
|
||||
result[materialRef.Id] = texture != null
|
||||
? new ViewportMaterial(materialRef.Name, texture.Value)
|
||||
? new ViewportMaterial(materialRef.Name, texture.Value, texm)
|
||||
: new ViewportMaterial(materialRef.Name);
|
||||
}
|
||||
|
||||
@@ -194,9 +194,10 @@ public sealed class WeaMaterialLibrary
|
||||
}
|
||||
|
||||
private static uint? TryLoadMaterialTexture(
|
||||
GL gl, FileStream materialFs, NResArchive materialArchive, string materialName
|
||||
GL gl, FileStream materialFs, NResArchive materialArchive, string materialName, out TexmFile? texm
|
||||
)
|
||||
{
|
||||
texm = null;
|
||||
var entry = FindMaterialEntry(materialArchive, materialName);
|
||||
if (entry == null)
|
||||
return null;
|
||||
@@ -235,6 +236,7 @@ public sealed class WeaMaterialLibrary
|
||||
if (texmResult.TexmFile == null)
|
||||
return null;
|
||||
|
||||
texm = texmResult.TexmFile;
|
||||
var rgba = texmResult.TexmFile.GetRgba32BytesFromMipmap(0, out var width, out var height);
|
||||
return ViewportTextureLoader.CreateRgbaTexture(gl, rgba, width, height);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using TexmLib;
|
||||
|
||||
namespace NResUI.Rendering.Viewport;
|
||||
|
||||
public sealed class ViewportMaterial
|
||||
@@ -6,10 +8,13 @@ public sealed class ViewportMaterial
|
||||
public uint TextureHandle { get; }
|
||||
public bool HasTexture => TextureHandle != 0;
|
||||
|
||||
public ViewportMaterial(string name, uint textureHandle = 0)
|
||||
public TexmFile? Texm { get; }
|
||||
|
||||
public ViewportMaterial(string name, uint textureHandle = 0, TexmFile? texm = null)
|
||||
{
|
||||
Name = name;
|
||||
TextureHandle = textureHandle;
|
||||
Texm = texm;
|
||||
}
|
||||
|
||||
public static ViewportMaterial Untextured { get; } = new("Untextured");
|
||||
|
||||
Reference in New Issue
Block a user