Exemple #1
0
 public static bool NearEqual(XwVector v1, XwVector v0)
 {
     return(XwVector.SubstractAndLength(v1, v0) < 0.0001);
 }
Exemple #2
0
        static int XwOptChecking(OptFile opt, int selectedMeshIndex)
        {
            int meshStart;
            int meshEnd;

            if (selectedMeshIndex < 0)
            {
                meshStart = 0;
                meshEnd   = opt.Meshes.Count;
            }
            else
            {
                meshStart = selectedMeshIndex;
                meshEnd   = meshStart + 1;

                if (meshStart >= opt.Meshes.Count)
                {
                    return(0);
                }
            }

            int facesCount = 0;

            for (int meshIndex = meshStart; meshIndex < meshEnd; meshIndex++)
            {
                var mesh = opt.Meshes[meshIndex];

                for (int lodIndex = 0; lodIndex < mesh.Lods.Count; lodIndex++)
                {
                    var lod = mesh.Lods[lodIndex];

                    for (int faceGroupIndex = 0; faceGroupIndex < lod.FaceGroups.Count; faceGroupIndex++)
                    {
                        var faceGroup = lod.FaceGroups[faceGroupIndex];

                        for (int faceIndex = 0; faceIndex < faceGroup.Faces.Count; faceIndex++)
                        {
                            var face = faceGroup.Faces[faceIndex];
                            facesCount++;

                            XwVector normal;
                            double   angle;
                            double   angleSum;
                            XwParseOpt(opt, meshIndex, face, out normal, out angle, out angleSum);

                            var sb = new StringBuilder();
                            sb.AppendFormat(CultureInfo.InvariantCulture, "M:{0} L:{1} B:{2} F:{3} [ ", meshIndex, lodIndex, faceGroupIndex, faceIndex);

                            for (int i = 0; i < face.VerticesCount; i++)
                            {
                                sb.AppendFormat(CultureInfo.InvariantCulture, "{0} ", face.VerticesIndex.AtIndex(i));
                            }

                            sb.Append("]");

                            if (Math.Abs(angleSum - 360.0) >= 2.0)
                            {
                                sb.AppendFormat(CultureInfo.InvariantCulture, " invalid {0}V face", face.VerticesCount);
                                Console.WriteLine(sb);

                                if (face.VerticesCount >= 4)
                                {
                                    double ebp50 = XwVector.SubstractAndLength(
                                        new XwVector(mesh.Vertices[face.VerticesIndex.AtIndex(0)]),
                                        new XwVector(mesh.Vertices[face.VerticesIndex.AtIndex(2)]));

                                    double ebp60 = XwVector.SubstractAndLength(
                                        new XwVector(mesh.Vertices[face.VerticesIndex.AtIndex(1)]),
                                        new XwVector(mesh.Vertices[face.VerticesIndex.AtIndex(3)]));

                                    int[] ebp134 = new int[3];
                                    int[] ebp1AC = new int[3];

                                    if (ebp60 >= ebp50)
                                    {
                                        for (int i = 0; i < 3; i++)
                                        {
                                            ebp134[i] = face.VerticesIndex.AtIndex(i);
                                            ebp1AC[i] = face.VerticesIndex.AtIndex(XwOptGetVertexIndex(i + 2, 4));
                                        }
                                    }
                                    else
                                    {
                                        for (int i = 0; i < 3; i++)
                                        {
                                            if (i < 2)
                                            {
                                                ebp134[i] = face.VerticesIndex.AtIndex(i);
                                            }
                                            else
                                            {
                                                ebp134[i] = face.VerticesIndex.AtIndex(3);
                                            }

                                            ebp1AC[i] = face.VerticesIndex.AtIndex(i + 1);
                                        }
                                    }
                                }
                            }
                            else if (Math.Abs(angle) > 80.0)
                            {
                                sb.AppendFormat(CultureInfo.InvariantCulture, " CW/CCW problem ? ({0:F1}°)", angle);
                                Console.WriteLine(sb);
                            }
                            else if (Math.Abs(angle) >= 2.0)
                            {
                                sb.AppendFormat(CultureInfo.InvariantCulture, " normal recomputed ! ({0:F1}°)", angle);
                                Console.WriteLine(sb);
                            }
                        }
                    }
                }
            }

            return(facesCount);
        }