Пример #1
0
        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.NodeReplace(null, new Node(list[1].Name)
                {
                    MeshGroup = list[1]
                });
            }
        }
Пример #2
0
        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.NodeReplace(null, new Node(list[1].Name)
                {
                    MeshGroup = list[1]
                });
            }
        }
Пример #3
0
        public static string NodeReduce(this ModelModifier modifier)
        {
            var count       = modifier.Model.Nodes.Count;
            var removeNames = new List <string>();

            // ノードを削除する
            foreach (var node in modifier.Model.GetRemoveNodes())
            {
                modifier.NodeReplace(node, null);
                removeNames.Add($"[{node.Name}]");
            }

            // 削除されたノードを参照する頂点バッファを修正する
            foreach (var meshGroup in modifier.Model.MeshGroups)
            {
                var skin = meshGroup.Skin;
                if (skin != null && skin.Joints.Contains(null))
                {
                    foreach (var mesh in meshGroup.Meshes)
                    {
                        skin.FixBoneWeight(mesh.VertexBuffer.Joints, mesh.VertexBuffer.Weights);
                    }
                }
            }

            var joined = string.Join("", removeNames);

            return($"NodeReduce: {count} => {modifier.Model.Nodes.Count}");
            // return $"NodeReduce: {joined}";
        }
Пример #4
0
        /// <summary>
        // [Debug向け]secondaryを除去
        /// </summary>
        public static void RemoveSecondary(this Model model)
        {
            var secondary = model.Nodes
                            .FirstOrDefault(x =>
                                            (x.Name == "secondary" || x.Name == "SpringBone") &&
                                            x.Parent == model.Root &&
                                            x.Children.Count == 0)
            ;

            if (secondary != null)
            {
                var mod = new ModelModifier(model);
                mod.NodeReplace(secondary, null);
            }
        }
Пример #5
0
        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);
            }
            modifier.NodeMeshClear();
            modifier.NodeReplace(null, meshNode);

            var names = string.Join("", meshes);

            // return $"SingleMesh: {names}";
            return($"SingleMesh: {count} => {modifier.Model.MeshGroups.Sum(x => x.Meshes.Count)}");
        }