public static void SepareteByHeadBone(this ModelModifier modifier, MeshGroup mesh, HashSet <int> boneIndices) { var(with, without) = mesh.SepareteByHeadBone(boneIndices); var list = new List <MeshGroup>(); if (with != null) { list.Add(with); } if (without != null) { list.Add(without); } // 分割モデルで置き換え if (list.Any()) { modifier.MeshReplace(mesh, list[0]); // rename node modifier.Model.Nodes.Find(x => x.MeshGroup == list[0]).Name = list[0].Name; } if (list.Count > 1) { // 頭と胴体で分割後2つ以上ある場合、2つ目を追加する modifier.MeshReplace(null, list[1]); modifier.NodeAdd(new Node(list[1].Name) { MeshGroup = list[1] }); } }
public static void SepareteByMorphTarget(this ModelModifier modifier, MeshGroup mesh) { var(with, without) = mesh.SepareteByMorphTarget(); var list = new List <MeshGroup>(); if (with != null) { list.Add(with); } if (without != null) { list.Add(without); } // 分割モデルで置き換え if (list.Any()) { modifier.MeshReplace(mesh, list[0]); // rename node modifier.Model.Nodes.Find(x => x.MeshGroup == list[0]).Name = list[0].Name; } if (list.Count > 1) { // morph無しと有り両方存在する場合に2つ目を追加する modifier.MeshReplace(null, list[1]); modifier.NodeAdd(new Node(list[1].Name) { MeshGroup = list[1] }); } }
public static string SingleMesh(this ModelModifier modifier, string name) { var count = modifier.Model.MeshGroups.Sum(x => x.Meshes.Count); var meshes = modifier.Model.Root.Traverse() .Select(x => x.MeshGroup) .Where(x => x != null) .Select(x => $"[{x.Name}]") .ToArray(); if (meshes.Length == 0) { return("SingleMesh: no mesh. do nothing"); } if (meshes.Length <= 1) { return("SingleMesh: one mesh. do nothing"); } var mesh = modifier.Model.CreateSingleMesh(name); var meshNode = new Node(mesh.Name) { MeshGroup = mesh, }; mesh.Skin.Root = meshNode; // fix bone weight (0, x, 0, 0) => (x, 0, 0, 0) // mesh.Meshes[0].VertexBuffer.FixBoneWeight(); // replace morphAnimation reference ReplaceMorphTargetAnimationNode(modifier.Model.Animations, meshNode); // update Model foreach (var x in modifier.Model.MeshGroups.ToArray()) { modifier.MeshReplace(x, mesh); } foreach (var node in modifier.Model.Nodes) { if (node.MeshGroup != null) { node.MeshGroup = null; modifier.MeshNodeReplace(node, meshNode); } } modifier.NodeAdd(meshNode); var names = string.Join("", meshes); // return $"SingleMesh: {names}"; return($"SingleMesh: {count} => {modifier.Model.MeshGroups.Sum(x => x.Meshes.Count)}"); }