示例#1
0
        private void testEncoder(MeshEncoder encoder)
        {
            MemoryStream  memory = new MemoryStream();
            CtmFileWriter writer = new CtmFileWriter(memory, encoder);

            writer.encode(quad, null);

            memory.Seek(0, SeekOrigin.Begin);
            Stream        readMemory = new MemoryStream(memory.ToArray());
            CtmFileReader reader     = new CtmFileReader(readMemory);
            Mesh          m          = reader.decode();

            m.checkIntegrity();

            MG2Encoder mg2 = encoder as MG2Encoder;

            if (mg2 == null)
            {
                Assert.AreEqual(quad, m);
            }
            else
            {
                MG2MeshEqualsTest(mg2, quad, m);
            }
        }
示例#2
0
        private void MG2MeshEqualsTest(MG2Encoder enc, Mesh orig, Mesh read)
        {
            Assert.AreEqual(orig.getTriangleCount(), read.getTriangleCount(), "Trianglecount differs");
            Assert.AreEqual(orig.getVertexCount(), read.getVertexCount(), "Vertexcount differs");
            Assert.AreEqual(orig.hasNormals(), read.hasNormals(), "Only one has normals");

            Grid grid = enc.setupGrid(orig.vertices);

            SortableVertex[] sorted   = enc.sortVertices(grid, orig.vertices);
            int[]            indexLUT = new int[sorted.Length];
            for (int i = 0; i < sorted.Length; ++i)
            {
                indexLUT [sorted [i].originalIndex] = i;
            }

            for (int i = 0; i < orig.getVertexCount(); i++)
            {
                int newIndex = indexLUT [i];

                for (int e = 0; e < Mesh.CTM_POSITION_ELEMENT_COUNT; e++)
                {
                    Assert.IsTrue(compare(orig.vertices [i * 3 + e], read.vertices [newIndex * 3 + e], enc.vertexPrecision * 2),
                                  "positions not in precision");
                }
                if (orig.hasNormals())
                {
                    for (int e = 0; e < Mesh.CTM_NORMAL_ELEMENT_COUNT; e++)
                    {
                        Assert.IsTrue(compare(orig.normals [i * 3 + e], read.normals [newIndex * 3 + e], enc.normalPrecision * 10),
                                      "normals not in precision");
                    }
                }
            }

            testAttributeArrays(orig.texcoordinates, read.texcoordinates, indexLUT);
            testAttributeArrays(orig.attributs, read.attributs, indexLUT);
        }