Пример #1
0
    bool ValidateMesh(Shape shape, GameObject obj)
    {
        MeshHandler.MeshDataComponent meshData = obj.GetComponent <MeshHandler.MeshDataComponent>();
        if (meshData == null)
        {
            Debug.LogError("Missing mesh data object.");
            return(false);
        }

        bool ok = true;

        ok = ValidateVectors("Vertex", meshData.Vertices, _sampleMesh.Vertices()) && ok;
        ok = ValidateVectors("Normal", meshData.Normals, _sampleMesh.Normals()) && ok;
        ok = ValidateIndices("Index", meshData.Indices, _sampleMesh.Indices4()) && ok;

        return(ok);
    }
    bool ValidateMeshSet(Shape shape, Shape referenceShape, MessageHandler handler)
    {
        MeshSetHandler meshSetHandler = (MeshSetHandler)handler;

        MeshSetHandler.PartSet parts     = meshSetHandler.ShapeCache.GetShapeData <MeshSetHandler.PartSet>(shape.ID);
        Tes.Handlers.MeshCache meshCache = (Tes.Handlers.MeshCache)_tes.GetHandler((ushort)RoutingID.Mesh);
        MeshSet meshSetReference         = (MeshSet)referenceShape;
        bool    ok = true;

        // Validate the number of parts.
        if (parts.MeshIDs.Length != meshSetReference.PartCount)
        {
            Debug.LogError("Part count mismatch.");
            return(false);
        }

        // Validate each part.
        for (int i = 0; i < meshSetReference.PartCount; ++i)
        {
            MeshResource referenceMesh = meshSetReference.PartResource(i);
            if (parts.MeshIDs[i] != referenceMesh.ID)
            {
                Debug.LogError($"Part resource mismatch. {parts.MeshIDs[i]} != {meshSetReference.PartResource(i).ID}");
                ok = false;
                continue;
            }

            // Resolve the mesh resource from the cache.
            Tes.Handlers.MeshCache.MeshDetails meshDetails = meshCache.GetEntry(parts.MeshIDs[i]);

            if (meshDetails == null)
            {
                Debug.LogError($"Unable to resolve mesh resource {parts.MeshIDs[i]}");
                ok = false;
                continue;
            }

            // Validate mesh content.
            ok = ValidateVectors("Vertex", meshDetails.Mesh.Vertices, referenceMesh.Vertices()) && ok;
            if (meshDetails.Mesh.HasNormals)
            {
                Vector3[] normals = meshDetails.Mesh.Normals;
                if (referenceMesh.Normals().Length == 1)
                {
                    // Single uniform normal will have been expanded. Extract just the first normal.
                    normals = new Vector3[] { meshDetails.Mesh.Normals[0] };
                }
                ok = ValidateVectors("Normal", normals, referenceMesh.Normals()) && ok;
            }
            else
            {
                if (referenceMesh.Normals() != null && referenceMesh.Normals().Length > 0)
                {
                    Debug.LogError("Missing normals.");
                    ok = false;
                }
            }
            if (meshDetails.Mesh.IndexCount > 0)
            {
                ok = ValidateIndices("Index", meshDetails.Mesh.Indices, referenceMesh.Indices4()) && ok;
            }
            else
            {
                if (referenceMesh.Indices4() != null && referenceMesh.Indices4().Length > 0)
                {
                    Debug.LogError("Missing indices.");
                    ok = false;
                }
            }
        }

        return(ok);
    }
Пример #3
0
        public void ValidateMesh(MeshResource mesh, MeshResource reference)
        {
            Assert.Equal(reference.ID, mesh.ID);
            Assert.Equal(reference.TypeID, mesh.TypeID);
            Assert.Equal(reference.Transform, mesh.Transform);
            Assert.Equal(reference.Tint, mesh.Tint);
            Assert.Equal(reference.DrawType, mesh.DrawType);
            Assert.Equal(reference.IndexSize, mesh.IndexSize);
            Assert.Equal(reference.VertexCount(), mesh.VertexCount());
            Assert.Equal(reference.IndexCount(), mesh.IndexCount());

            if (mesh.VertexCount() > 0)
            {
                Assert.NotNull(reference.Vertices());
                Assert.NotNull(mesh.Vertices());

                Vector3 refv, meshv;
                for (int i = 0; i < mesh.VertexCount(); ++i)
                {
                    refv  = reference.Vertices()[i];
                    meshv = mesh.Vertices()[i];
                    Assert.Equal(refv.X, meshv.X);
                    Assert.Equal(refv.Y, meshv.Y);
                    Assert.Equal(refv.Z, meshv.Z);
                }
            }

            if (mesh.IndexCount() > 0)
            {
                if (reference.IndexSize == 2)
                {
                    Assert.NotNull(mesh.Indices2());

                    for (int i = 0; i < mesh.IndexCount(); ++i)
                    {
                        Assert.Equal(reference.Indices2()[i], mesh.Indices2()[i]);
                    }
                }
                else
                {
                    Assert.NotNull(reference.Indices4());
                    Assert.NotNull(mesh.Indices4());

                    for (int i = 0; i < mesh.IndexCount(); ++i)
                    {
                        Assert.Equal(reference.Indices4()[i], mesh.Indices4()[i]);
                    }
                }
            }

            if (mesh.Normals() != null)
            {
                Assert.NotNull(mesh.Normals());

                Vector3 refn, meshn;
                for (int i = 0; i < mesh.VertexCount(); ++i)
                {
                    refn  = reference.Normals()[i];
                    meshn = mesh.Normals()[i];
                    Assert.Equal(refn.X, meshn.X);
                    Assert.Equal(refn.Y, meshn.Y);
                    Assert.Equal(refn.Z, meshn.Z);
                }
            }

            if (mesh.Colours() != null)
            {
                Assert.NotNull(mesh.Colours());

                for (int i = 0; i < mesh.VertexCount(); ++i)
                {
                    Assert.Equal(reference.Colours()[i], mesh.Colours()[i]);
                }
            }

            if (mesh.UVs() != null)
            {
                Assert.NotNull(mesh.UVs());

                Vector2 refuv, meshuv;
                for (int i = 0; i < mesh.VertexCount(); ++i)
                {
                    refuv  = reference.UVs()[i];
                    meshuv = mesh.UVs()[i];
                    Assert.Equal(refuv.X, meshuv.X);
                    Assert.Equal(refuv.Y, meshuv.Y);
                }
            }
        }