Ejemplo n.º 1
0
        void ValidateMeshSetShape(Shape shapeArg, Shape referenceArg, Dictionary <ulong, Resource> resources)
        {
            ShapeTestFramework.ValidateShape(shapeArg, referenceArg, resources);
            MeshSet shape     = (MeshSet)shapeArg;
            MeshSet reference = (MeshSet)referenceArg;

            Assert.Equal(reference.PartCount, shape.PartCount);

            Net.ObjectAttributes attrRef  = new Net.ObjectAttributes();
            Net.ObjectAttributes attrMesh = new Net.ObjectAttributes();
            for (int i = 0; i < shape.PartCount; ++i)
            {
                // Transforms may not be exactly equal. We need to convert to PRS components and compare approximate equality
                // there as this is what the transfer does.
                attrRef.SetFromTransform(reference.PartTransformAt(i));
                attrMesh.SetFromTransform(shape.PartTransformAt(i));

                AssertExt.Near(attrRef.X, attrMesh.X, 1e-3f);
                AssertExt.Near(attrRef.Y, attrMesh.Y, 1e-3f);
                AssertExt.Near(attrRef.Z, attrMesh.Z, 1e-3f);

                AssertExt.Near(attrRef.RotationX, attrMesh.RotationX, 1e-3f);
                AssertExt.Near(attrRef.RotationY, attrMesh.RotationY, 1e-3f);
                AssertExt.Near(attrRef.RotationZ, attrMesh.RotationZ, 1e-3f);
                AssertExt.Near(attrRef.RotationW, attrMesh.RotationW, 1e-3f);

                AssertExt.Near(attrRef.ScaleX, attrMesh.ScaleX, 1e-3f);
                AssertExt.Near(attrRef.ScaleY, attrMesh.ScaleY, 1e-3f);
                AssertExt.Near(attrRef.ScaleZ, attrMesh.ScaleZ, 1e-3f);

                // Shape will only have a placeholder resource. Lookup in resources.
                MeshResource mesh = (MeshResource)resources[shape.PartAt(i).UniqueKey()];
                ValidateMesh(mesh, reference.PartAt(i));
            }
        }
Ejemplo n.º 2
0
        public void ValidateText3D(Shape shapeArg, Shape referenceArg, Dictionary <ulong, Resource> resources)
        {
            ShapeTestFramework.ValidateShape(shapeArg, referenceArg, resources);
            Text3D shape     = (Text3D)shapeArg;
            Text3D reference = (Text3D)referenceArg;

            Assert.Equal(reference.Text, shape.Text);
        }
Ejemplo n.º 3
0
        public void ValidatePointCloudShape(Shape shapeArg, Shape referenceArg, Dictionary <ulong, Resource> resources)
        {
            ShapeTestFramework.ValidateShape(shapeArg, referenceArg, resources);
            PointCloudShape shape     = (PointCloudShape)shapeArg;
            PointCloudShape reference = (PointCloudShape)referenceArg;

            Assert.Equal(reference.PointScale, shape.PointScale);
            Assert.NotNull(reference.PointCloud);
            Assert.NotNull(shape.PointCloud);

            Assert.Equal(reference.PointCloud.ID, shape.PointCloud.ID);

            // Resolve the mesh resource.
            Resource resource;

            Assert.True(resources.TryGetValue(shape.PointCloud.UniqueKey(), out resource));
            // Remember, resource will be a SimpleMesh, not a PointCloud.
            MeshResource cloud = (MeshResource)resource;

            ValidateMesh(cloud, reference.PointCloud);
        }
Ejemplo n.º 4
0
        public void CollationTest(bool compress)
        {
            // Allocate encoder.
            CollatedPacketEncoder encoder = new CollatedPacketEncoder(compress);

            // Create a mesh object to generate some messages.
            List <Vector3> vertices = new List <Vector3>();
            List <Vector3> normals  = new List <Vector3>();
            List <int>     indices  = new List <int>();

            Common.MakeLowResSphere(vertices, indices, normals);

            MeshShape mesh = new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray());

            mesh.ID      = 42;
            mesh.Normals = normals.ToArray();

            // Use the encoder as a connection.
            // The Create() call will pack the mesh create message and multiple data messages.
            int wroteBytes = encoder.Create(mesh);

            Assert.True(wroteBytes > 0);
            Assert.True(encoder.FinaliseEncoding());

            // Allocate a reader. Contains a CollatedPacketDecoder.
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(encoder.Buffer, 0, encoder.Count);
            PacketStreamReader     decoder      = new PacketStreamReader(memoryStream);

            PacketBuffer packet;
            MeshShape    readMesh       = new MeshShape();
            int          packetCount    = 0;
            long         processedBytes = 0;

            while ((packet = decoder.NextPacket(ref processedBytes)) != null)
            {
                NetworkReader reader = new NetworkReader(packet.CreateReadStream(true));
                ++packetCount;
                Assert.True(packet.ValidHeader);
                Assert.Equal(packet.Header.Marker, PacketHeader.PacketMarker);
                Assert.Equal(packet.Header.VersionMajor, PacketHeader.PacketVersionMajor);
                Assert.Equal(packet.Header.VersionMinor, PacketHeader.PacketVersionMinor);

                Assert.Equal(packet.Header.RoutingID, mesh.RoutingID);

                // Peek the shape ID.
                uint shapeId = packet.PeekUInt32(PacketHeader.Size);
                Assert.Equal(shapeId, mesh.ID);

                switch ((ObjectMessageID)packet.Header.MessageID)
                {
                case ObjectMessageID.Create:
                    Assert.True(readMesh.ReadCreate(packet, reader));
                    break;

                case ObjectMessageID.Update:
                    Assert.True(readMesh.ReadUpdate(packet, reader));
                    break;

                case ObjectMessageID.Data:
                    Assert.True(readMesh.ReadData(packet, reader));
                    break;
                }
            }

            Assert.True(packetCount > 0);
            // FIXME: Does not match, but results are fine. processedBytes is 10 greater than wroteBytes.
            //Assert.Equal(processedBytes, wroteBytes);

            // Validate what we've read back.
            ShapeTestFramework.ValidateShape(readMesh, mesh, new Dictionary <ulong, Resource>());
        }
Ejemplo n.º 5
0
        public void ValidateMeshShape(Shape shapeArg, Shape referenceArg, Dictionary <ulong, Resource> resources)
        {
            ShapeTestFramework.ValidateShape(shapeArg, referenceArg, resources);
            MeshShape shape     = (MeshShape)shapeArg;
            MeshShape reference = (MeshShape)referenceArg;

            Assert.Equal(shape.DrawType, reference.DrawType);
            if (reference.Vertices != null)
            {
                Assert.NotNull(shape.Vertices);
                Assert.Equal(reference.Vertices.Length, shape.Vertices.Length);
                bool verticesMatch = true;
                for (int i = 0; i < shape.Vertices.Length; ++i)
                {
                    if (reference.Vertices[i] != shape.Vertices[i])
                    {
                        verticesMatch = false;
                        _output.WriteLine("vertex mismatch [{0}] : ({1},{2},{3}) != ({4},{5},{6})",
                                          i, reference.Vertices[i].X, reference.Normals[i].Y, reference.Normals[i].Z,
                                          shape.Normals[i].X, shape.Normals[i].Y, shape.Normals[i].Z);
                    }
                }

                Assert.True(verticesMatch);
            }

            if (reference.Normals != null)
            {
                Assert.NotNull(shape.Normals);
                Assert.Equal(reference.Normals.Length, shape.Normals.Length);
                bool normalsMatch = true;
                for (int i = 0; i < shape.Normals.Length; ++i)
                {
                    if (reference.Normals[i].X != shape.Normals[i].X ||
                        reference.Normals[i].Y != shape.Normals[i].Y ||
                        reference.Normals[i].Z != shape.Normals[i].Z)
                    {
                        normalsMatch = false;
                        _output.WriteLine("normal mismatch [{0}] : ({1},{2},{3}) != ({4},{5},{6})",
                                          i, reference.Normals[i].X, reference.Normals[i].Y, reference.Normals[i].Z,
                                          shape.Normals[i].X, shape.Normals[i].Y, shape.Normals[i].Z);
                    }
                }

                Assert.True(normalsMatch);
            }

            if (reference.Colours != null)
            {
                Assert.NotNull(shape.Colours);
                Assert.Equal(reference.Colours.Length, shape.Colours.Length);
                bool coloursMatch = true;
                for (int i = 0; i < shape.Colours.Length; ++i)
                {
                    if (reference.Colours[i] != shape.Colours[i])
                    {
                        _output.WriteLine("colour mismatch [{0}] : 0x{1} != 0x{2}",
                                          i, reference.Colours[i].ToString("x"), shape.Colours[i].ToString("x"));
                        coloursMatch = false;
                    }
                }

                Assert.True(coloursMatch);
            }

            if (reference.Indices != null)
            {
                Assert.NotNull(shape.Indices);
                Assert.Equal(reference.Indices.Length, shape.Indices.Length);
                bool indicesMatch = true;
                for (int i = 0; i < shape.Indices.Length; ++i)
                {
                    if (reference.Indices[i] != shape.Indices[i])
                    {
                        _output.WriteLine("index mismatch [{0}] : {1} != {2}",
                                          i, reference.Indices[i], shape.Indices[i]);
                        indicesMatch = false;
                    }
                }

                Assert.True(indicesMatch);
            }
        }