Skip to content

Commit 4e947a8

Browse files
authored
Merge pull request WolvenKit#2682 from WolvenKit/fix/warn-if-mesh-has-no-bones
throw if bones are imported into a mesh without
2 parents 4294caf + d2b23d3 commit 4e947a8

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

WolvenKit.Modkit/RED4/Tools/MeshTools.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static bool ExportMesh(CR2WFile cr2W, FileInfo outfile, MeshExportArgs me
4646
catch (ArgumentNullException)
4747
{
4848
}
49-
49+
5050

5151
if (model == null)
5252
{
@@ -568,11 +568,11 @@ public static List<RawMeshContainer> ContainRawMesh(MemoryStream gfs, MeshesInfo
568568
info.appearances.Keys.FirstOrDefault("default") :
569569
"submesh_" + Convert.ToString(index).PadLeft(2, '0') + "_LOD_" + info.LODLvl[index];
570570
}
571-
571+
572572

573573
meshContainer.materialNames = new string[info.appearances.Count];
574574

575-
575+
576576
//var Mesh_apps = info.appearances.Keys.Select(key => Path.GetFileNameWithoutExtension(meshname)+'_' + key).ToList();
577577

578578
var apps = info.appearances.Keys.ToList();
@@ -655,6 +655,11 @@ public static (int numLodLevels, int numSubmeshesPerLod) GetLodInfo(CMesh mesh)
655655

656656
public static void UpdateMeshJoints(ref List<RawMeshContainer> meshes, RawArmature? existingJoints, RawArmature? incomingJoints, string fileName = "")
657657
{
658+
if (existingJoints is not { BoneCount: > 0 } && incomingJoints is { BoneCount: > 0 })
659+
{
660+
throw new WolvenKitException(0x2005, $"\nThe destination mesh has no bones");
661+
}
662+
658663
HashSet<string> bonesNotFound = [];
659664
// updating mesh bone indices
660665
if (existingJoints is { BoneCount: > 0 } && incomingJoints is { BoneCount: > 0 })
@@ -679,7 +684,7 @@ public static void UpdateMeshJoints(ref List<RawMeshContainer> meshes, RawArmatu
679684
}
680685

681686
var boneName = incomingJoints.Names[mesh.boneindices[e, eye]];
682-
687+
683688
var found = false;
684689
for (ushort r = 0; r < existingJoints.BoneCount; r++)
685690
{
@@ -714,8 +719,7 @@ public static void UpdateMeshJoints(ref List<RawMeshContainer> meshes, RawArmatu
714719

715720
if (bonesNotFound.Any())
716721
{
717-
throw new WolvenKitException(0x2005,
718-
$"\n{string.Join("\n", bonesNotFound)}");
722+
throw new WolvenKitException(0x2005, $"\n{string.Join("\n", bonesNotFound)}");
719723
}
720724
}
721725

@@ -876,7 +880,7 @@ public static void AddSubMeshesToModel(List<RawMeshContainer> meshes, Skin? skin
876880
ArgumentNullException.ThrowIfNull(mesh.weights);
877881
ArgumentNullException.ThrowIfNull(mesh.indices);
878882
ArgumentNullException.ThrowIfNull(mesh.garmentMorph);
879-
883+
880884

881885
Mesh? mes;
882886
Node? node;
@@ -899,7 +903,7 @@ public static void AddSubMeshesToModel(List<RawMeshContainer> meshes, Skin? skin
899903
ArgumentNullException.ThrowIfNull(mesh.materialNames, nameof(mesh.materialNames));
900904

901905
var prim = mes.CreatePrimitive();
902-
906+
903907
if (materials != null && materials.ContainsKey(mesh.materialNames[0]))
904908
{
905909
prim.Material = materials[mesh.materialNames[0]];

0 commit comments

Comments
 (0)