mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-14 20:54:16 +01:00
Export material names
This commit is contained in:
parent
36cbca4684
commit
3cd438bb5d
2 changed files with 27 additions and 15 deletions
|
|
@ -27,9 +27,9 @@ public class MeshExporter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Mesh Export(MdlFile mdl, byte lod, ushort meshIndex, GltfSkeleton? skeleton)
|
public static Mesh Export(MdlFile mdl, byte lod, ushort meshIndex, MaterialBuilder[] materials, GltfSkeleton? skeleton)
|
||||||
{
|
{
|
||||||
var self = new MeshExporter(mdl, lod, meshIndex, skeleton?.Names);
|
var self = new MeshExporter(mdl, lod, meshIndex, materials, skeleton?.Names);
|
||||||
return new Mesh(self.BuildMeshes(), skeleton?.Joints);
|
return new Mesh(self.BuildMeshes(), skeleton?.Joints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,18 +42,22 @@ public class MeshExporter
|
||||||
private MdlStructs.MeshStruct XivMesh
|
private MdlStructs.MeshStruct XivMesh
|
||||||
=> _mdl.Meshes[_meshIndex];
|
=> _mdl.Meshes[_meshIndex];
|
||||||
|
|
||||||
|
private readonly MaterialBuilder _material;
|
||||||
|
|
||||||
private readonly Dictionary<ushort, int>? _boneIndexMap;
|
private readonly Dictionary<ushort, int>? _boneIndexMap;
|
||||||
|
|
||||||
private readonly Type _geometryType;
|
private readonly Type _geometryType;
|
||||||
private readonly Type _materialType;
|
private readonly Type _materialType;
|
||||||
private readonly Type _skinningType;
|
private readonly Type _skinningType;
|
||||||
|
|
||||||
private MeshExporter(MdlFile mdl, byte lod, ushort meshIndex, IReadOnlyDictionary<string, int>? boneNameMap)
|
private MeshExporter(MdlFile mdl, byte lod, ushort meshIndex, MaterialBuilder[] materials, IReadOnlyDictionary<string, int>? boneNameMap)
|
||||||
{
|
{
|
||||||
_mdl = mdl;
|
_mdl = mdl;
|
||||||
_lod = lod;
|
_lod = lod;
|
||||||
_meshIndex = meshIndex;
|
_meshIndex = meshIndex;
|
||||||
|
|
||||||
|
_material = materials[XivMesh.MaterialIndex];
|
||||||
|
|
||||||
if (boneNameMap != null)
|
if (boneNameMap != null)
|
||||||
_boneIndexMap = BuildBoneIndexMap(boneNameMap);
|
_boneIndexMap = BuildBoneIndexMap(boneNameMap);
|
||||||
|
|
||||||
|
|
@ -134,13 +138,7 @@ public class MeshExporter
|
||||||
);
|
);
|
||||||
var meshBuilder = (IMeshBuilder<MaterialBuilder>)Activator.CreateInstance(meshBuilderType, name)!;
|
var meshBuilder = (IMeshBuilder<MaterialBuilder>)Activator.CreateInstance(meshBuilderType, name)!;
|
||||||
|
|
||||||
// TODO: share materials &c
|
var primitiveBuilder = meshBuilder.UsePrimitive(_material);
|
||||||
var materialBuilder = new MaterialBuilder()
|
|
||||||
.WithDoubleSide(true)
|
|
||||||
.WithMetallicRoughnessShader()
|
|
||||||
.WithChannelParam(KnownChannel.BaseColor, KnownProperty.RGBA, new Vector4(1, 1, 1, 1));
|
|
||||||
|
|
||||||
var primitiveBuilder = meshBuilder.UsePrimitive(materialBuilder);
|
|
||||||
|
|
||||||
// Store a list of the glTF indices. The list index will be equivalent to the xiv (submesh) index.
|
// Store a list of the glTF indices. The list index will be equivalent to the xiv (submesh) index.
|
||||||
var gltfIndices = new List<int>();
|
var gltfIndices = new List<int>();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Penumbra.GameData.Files;
|
using Penumbra.GameData.Files;
|
||||||
|
using SharpGLTF.Materials;
|
||||||
using SharpGLTF.Scenes;
|
using SharpGLTF.Scenes;
|
||||||
using SharpGLTF.Transforms;
|
using SharpGLTF.Transforms;
|
||||||
|
|
||||||
|
|
@ -25,12 +26,13 @@ public class ModelExporter
|
||||||
public static Model Export(MdlFile mdl, IEnumerable<XivSkeleton>? xivSkeleton)
|
public static Model Export(MdlFile mdl, IEnumerable<XivSkeleton>? xivSkeleton)
|
||||||
{
|
{
|
||||||
var gltfSkeleton = xivSkeleton != null ? ConvertSkeleton(xivSkeleton) : null;
|
var gltfSkeleton = xivSkeleton != null ? ConvertSkeleton(xivSkeleton) : null;
|
||||||
var meshes = ConvertMeshes(mdl, gltfSkeleton);
|
var materials = ConvertMaterials(mdl);
|
||||||
|
var meshes = ConvertMeshes(mdl, materials, gltfSkeleton);
|
||||||
return new Model(meshes, gltfSkeleton);
|
return new Model(meshes, gltfSkeleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Convert a .mdl to a mesh (group) per LoD. </summary>
|
/// <summary> Convert a .mdl to a mesh (group) per LoD. </summary>
|
||||||
private static List<MeshExporter.Mesh> ConvertMeshes(MdlFile mdl, GltfSkeleton? skeleton)
|
private static List<MeshExporter.Mesh> ConvertMeshes(MdlFile mdl, MaterialBuilder[] materials, GltfSkeleton? skeleton)
|
||||||
{
|
{
|
||||||
var meshes = new List<MeshExporter.Mesh>();
|
var meshes = new List<MeshExporter.Mesh>();
|
||||||
|
|
||||||
|
|
@ -41,7 +43,7 @@ public class ModelExporter
|
||||||
// TODO: consider other types of mesh?
|
// TODO: consider other types of mesh?
|
||||||
for (ushort meshOffset = 0; meshOffset < lod.MeshCount; meshOffset++)
|
for (ushort meshOffset = 0; meshOffset < lod.MeshCount; meshOffset++)
|
||||||
{
|
{
|
||||||
var mesh = MeshExporter.Export(mdl, lodIndex, (ushort)(lod.MeshIndex + meshOffset), skeleton);
|
var mesh = MeshExporter.Export(mdl, lodIndex, (ushort)(lod.MeshIndex + meshOffset), materials, skeleton);
|
||||||
meshes.Add(mesh);
|
meshes.Add(mesh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -49,6 +51,18 @@ public class ModelExporter
|
||||||
return meshes;
|
return meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Compose textures for use with these materials
|
||||||
|
/// <summary> Build placeholder materials for each of the material slots in the .mdl. </summary>
|
||||||
|
private static MaterialBuilder[] ConvertMaterials(MdlFile mdl)
|
||||||
|
=> mdl.Materials
|
||||||
|
.Select(name =>
|
||||||
|
new MaterialBuilder(name)
|
||||||
|
.WithMetallicRoughnessShader()
|
||||||
|
.WithDoubleSide(true)
|
||||||
|
.WithChannelParam(KnownChannel.BaseColor, KnownProperty.RGBA, Vector4.One)
|
||||||
|
)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
/// <summary> Convert XIV skeleton data into a glTF-compatible node tree, with mappings. </summary>
|
/// <summary> Convert XIV skeleton data into a glTF-compatible node tree, with mappings. </summary>
|
||||||
private static GltfSkeleton? ConvertSkeleton(IEnumerable<XivSkeleton> skeletons)
|
private static GltfSkeleton? ConvertSkeleton(IEnumerable<XivSkeleton> skeletons)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue