Ejemplo n.º 1
0
        public static (int VertsFixed, int TotalSourceVerts) FixBodyPiece(FlverSubmesh mesh, string bodyPieceType, out string possibleError)
        {
            possibleError = null;
            if (!MaterialToEmbeddedFlverMap.ContainsKey(bodyPieceType))
            {
                possibleError = "Invalid body piece type: '{bodyPieceType}' in material name of this body part. Below is a list of valid types:" +
                                " -HD_M\n" +
                                " -BD_M\n" +
                                " -AM_M\n" +
                                " -LG_M\n" +
                                " -HD_F\n" +
                                " -BD_F\n" +
                                " -AM_F\n" +
                                " -LG_F\n" +
                                " -HD_M_Hollow\n" +
                                " -BD_M_Hollow\n" +
                                " -AM_M_Hollow\n" +
                                " -LG_M_Hollow\n" +
                                " -HD_F_Hollow\n" +
                                " -BD_F_Hollow\n" +
                                " -AM_F_Hollow\n" +
                                " -LG_F_Hollow\n";
                return(-1, -1);
            }

            var flverName = MaterialToEmbeddedFlverMap[bodyPieceType];
            var flver     = GetFlver(flverName);

            List <FlverVertex> possibleVertices = new List <FlverVertex>();

            foreach (var v in flver.Submeshes[0].Vertices)
            {
                possibleVertices.Add(v);
            }

            int numberOfVertsFixed = 0;
            int totalVerts         = possibleVertices.Count;

            foreach (var v in mesh.Vertices)
            {
                foreach (var possible in possibleVertices)
                {
                    if (CheckIfVertexMatches(v, possible))
                    {
                        v.Position  = possible.Position;
                        v.Normal    = possible.Normal;
                        v.BiTangent = possible.BiTangent;

                        string targetBoneNameA = flver.GetBoneFromIndex(possible.BoneIndices.A)?.Name;
                        string targetBoneNameB = flver.GetBoneFromIndex(possible.BoneIndices.B)?.Name;
                        string targetBoneNameC = flver.GetBoneFromIndex(possible.BoneIndices.C)?.Name;
                        string targetBoneNameD = flver.GetBoneFromIndex(possible.BoneIndices.D)?.Name;

                        v.BoneIndices.A = mesh.FindOrAddBoneIndex(targetBoneNameA);
                        v.BoneIndices.B = mesh.FindOrAddBoneIndex(targetBoneNameB);
                        v.BoneIndices.C = mesh.FindOrAddBoneIndex(targetBoneNameC);
                        v.BoneIndices.D = mesh.FindOrAddBoneIndex(targetBoneNameD);

                        v.BoneWeights = possible.BoneWeights;

                        numberOfVertsFixed++;

                        possibleVertices.Remove(possible);
                    }
                }
            }

            return(numberOfVertsFixed, totalVerts);
        }
Ejemplo n.º 2
0
        public static (int VertsFixed, int TotalSourceVerts) FixBodyPiece(FlverSubmesh mesh, string bodyPieceType, out string possibleError)
        {
            possibleError = null;
            if (!MaterialToEmbeddedFlverMap.ContainsKey(bodyPieceType))
            {
                possibleError = $"Invalid body piece type: '{bodyPieceType}' in material name of this body part. Below is a list of valid types:" +
                                " -HD_M\n" +
                                " -BD_M\n" +
                                " -AM_M\n" +
                                " -LG_M\n" +
                                " -HD_F\n" +
                                " -BD_F\n" +
                                " -AM_F\n" +
                                " -LG_F\n" +
                                " -HD_M_Hollow\n" +
                                " -BD_M_Hollow\n" +
                                " -AM_M_Hollow\n" +
                                " -LG_M_Hollow\n" +
                                " -HD_F_Hollow\n" +
                                " -BD_F_Hollow\n" +
                                " -AM_F_Hollow\n" +
                                " -LG_F_Hollow\n";
                return(-1, -1);
            }

            var flverName = MaterialToEmbeddedFlverMap[bodyPieceType];
            var flver     = GetFlver(flverName);

            List <FlverVertex> possibleVertices = new List <FlverVertex>();

            foreach (var v in flver.Submeshes[0].Vertices)
            {
                possibleVertices.Add(v);
            }

            int numberOfVertsFixed = 0;
            int totalVerts         = possibleVertices.Count;

            //List<FlverVertex> possibleVertsCheckedOff = new List<FlverVertex>();

            foreach (var v in mesh.Vertices)
            {
                //(FlverVertex Vert, float Dist) closestDistance = (null, float.MaxValue);

                FlverVertex closest = null;

                foreach (var possible in possibleVertices)
                {
                    //float dist = ((Vector3)(possible.Position - v.Position)).LengthSquared();

                    //if (dist < closestDistance.Dist)
                    //    closestDistance = (possible, dist);

                    if (CheckIfVertexMatches(v, possible))
                    {
                        closest = possible;

                        v.Position  = closest.Position;
                        v.Normal    = closest.Normal;
                        v.BiTangent = closest.BiTangent;

                        string targetBoneNameA = closest.BoneIndices.A >= 0 ? flver.GetBoneFromIndex(flver.Submeshes[0].BoneIndices[closest.BoneIndices.A])?.Name : null;
                        string targetBoneNameB = closest.BoneIndices.B >= 0 ? flver.GetBoneFromIndex(flver.Submeshes[0].BoneIndices[closest.BoneIndices.B])?.Name : null;
                        string targetBoneNameC = closest.BoneIndices.C >= 0 ? flver.GetBoneFromIndex(flver.Submeshes[0].BoneIndices[closest.BoneIndices.C])?.Name : null;
                        string targetBoneNameD = closest.BoneIndices.D >= 0 ? flver.GetBoneFromIndex(flver.Submeshes[0].BoneIndices[closest.BoneIndices.D])?.Name : null;

                        v.BoneIndices.A = mesh.FindOrAddBoneIndex(targetBoneNameA);
                        v.BoneIndices.B = mesh.FindOrAddBoneIndex(targetBoneNameB);
                        v.BoneIndices.C = mesh.FindOrAddBoneIndex(targetBoneNameC);
                        v.BoneIndices.D = mesh.FindOrAddBoneIndex(targetBoneNameD);

                        v.BoneWeights = closest.BoneWeights;

                        v.UVs = closest.UVs;

                        numberOfVertsFixed++;
                    }
                }



                //if (possibleVertsCheckedOff.Count > 0)
                //{
                //    foreach (var checkoff in possibleVertsCheckedOff)
                //        possibleVertices.Remove(checkoff);
                //    possibleVertsCheckedOff.Clear();
                //}
            }

            return(numberOfVertsFixed, totalVerts);
        }