Пример #1
0
        public void PointCloudTest()
        {
            List <Vector3> vertices = new List <Vector3>();
            List <Vector3> normals  = new List <Vector3>();
            List <int>     indices  = new List <int>();

            uint[] colours;
            Common.MakeHiResSphere(vertices, indices, normals);

            // Build per vertex colours with colour cycling.
            colours = new uint[vertices.Count];
            for (int i = 0; i < colours.Length; ++i)
            {
                colours[i] = Colour.Cycle(i).Value;
            }

            PointCloud cloud = new PointCloud(1, vertices.Count);

            cloud.AddPoints(vertices);
            cloud.AddNormals(normals);
            cloud.AddColours(colours);

            ShapeTestFramework.CreateShapeFunction create = () => { return(new PointCloudShape()); };
            ShapeTestFramework.TestShape(new PointCloudShape(cloud, 41, 1, 8), create, ValidatePointCloudShape);

            // Run a cloud with an indexed sub-set.
            uint[] indexedSubSet = new uint[vertices.Count / 2];
            for (uint i = 0; i < indexedSubSet.Length; ++i)
            {
                indexedSubSet[i] = i;
            }

            ShapeTestFramework.TestShape(new PointCloudShape(cloud, 41, 1, 8).SetIndices(indexedSubSet), create, ValidatePointCloudShape);
        }
Пример #2
0
        public void TestMeshShape()
        {
            List <Vector3> vertices = new List <Vector3>();
            List <int>     indices  = new List <int>();
            List <Vector3> normals  = new List <Vector3>();

            uint[] colours;
            Common.MakeHiResSphere(vertices, indices, normals);

            colours = new uint[vertices.Count];
            for (int i = 0; i < colours.Length; ++i)
            {
                colours[i] = Colour.Cycle(i).Value;
            }

            ShapeTestFramework.CreateShapeFunction create = () => { return(new MeshShape()); };

            // Validate all constructors, though not necessarily all default argument settings.
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray()), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray(), new Vector3(1.2f, 2.3f, 3.4f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray(), new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray(), new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f), new Vector3(1, 2, 3)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray(), 42, 1), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray(), 41, new Vector3(1.2f, 2.3f, 3.4f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray(), 42, new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f), new Vector3(1, 2, 3)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray(), 41, 1, new Vector3(1.2f, 2.3f, 3.4f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray(), 42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f), new Vector3(1, 2, 3)), create, ValidateMeshShape);

            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray()), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), new Vector3(1.2f, 2.3f, 3.4f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f), new Vector3(1, 2, 3)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), 42, 1), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), 42, new Vector3(1.2f, 2.3f, 3.4f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), 42, new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), 42, new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f), new Vector3(1, 2, 3)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), 42, 1, new Vector3(1.2f, 2.3f, 3.4f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), 42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f)), create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray(), 42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Quaternion(Vector3.One.Normalised, 15.0f * (float)Math.PI / 180.0f), new Vector3(1, 2, 3)), create, ValidateMeshShape);

            // Validate with normals.
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray())
            {
                Normals = normals.ToArray()
            }, create, ValidateMeshShape);
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Voxels, vertices.ToArray()).SetUniformNormal(Vector3.One), create, ValidateMeshShape);

            // Try with colours.
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Points, vertices.ToArray())
            {
                Colours = colours
            }, create, ValidateMeshShape);

            // And one with the lot.
            ShapeTestFramework.TestShape(new MeshShape(Net.MeshDrawType.Triangles, vertices.ToArray(), indices.ToArray())
            {
                Normals = normals.ToArray(), Colours = colours
            }, create, ValidateMeshShape);
        }
Пример #3
0
 public void StarTest()
 {
     ShapeTestFramework.CreateShapeFunction create = () => { return(new Star()); };
     ShapeTestFramework.TestShape(new Star(), create);
     ShapeTestFramework.TestShape(new Star(42), create);
     ShapeTestFramework.TestShape(new Star(42, 1), create);
     ShapeTestFramework.TestShape(new Star(42, new Vector3(1.2f, 2.3f, 3.4f), 0.75f), create);
     ShapeTestFramework.TestShape(new Star(42, 1, new Vector3(1.2f, 2.3f, 3.4f), 0.75f), create);
 }
Пример #4
0
 public void PlaneTest()
 {
     ShapeTestFramework.CreateShapeFunction create = () => { return(new Plane()); };
     ShapeTestFramework.TestShape(new Plane(), create);
     ShapeTestFramework.TestShape(new Plane(42), create);
     ShapeTestFramework.TestShape(new Plane(42, 1), create);
     ShapeTestFramework.TestShape(new Plane(42, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0.7f, 1.2f, 3.0f), 3.2f, 0.75f), create);
     ShapeTestFramework.TestShape(new Plane(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0.7f, 1.2f, 3.0f), 3.2f, 0.75f), create);
     ShapeTestFramework.TestShape(new Plane(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0.7f, 1.2f, 3.0f)), create);
 }
Пример #5
0
 public void ConeTest()
 {
     ShapeTestFramework.CreateShapeFunction create = () => { return(new Cone()); };
     ShapeTestFramework.TestShape(new Cone(), create);
     ShapeTestFramework.TestShape(new Cone(42), create);
     ShapeTestFramework.TestShape(new Cone(42, 1), create);
     ShapeTestFramework.TestShape(new Cone(42, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(1, 1, 1).Normalised, 2.0f, 12.0f * (float)Math.PI / 180.0f), create);
     ShapeTestFramework.TestShape(new Cone(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(1, 1, 1).Normalised, 2.0f, 12.0f * (float)Math.PI / 180.0f), create);
     ShapeTestFramework.TestShape(new Cone(42, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0, 0, 0), 1.05f), create);
     ShapeTestFramework.TestShape(new Cone(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0, 0, 0), 1.05f), create);
 }
Пример #6
0
 public void CylinderTest()
 {
     ShapeTestFramework.CreateShapeFunction create = () => { return(new Cylinder()); };
     ShapeTestFramework.TestShape(new Cylinder(), create);
     ShapeTestFramework.TestShape(new Cylinder(42), create);
     ShapeTestFramework.TestShape(new Cylinder(42, 1), create);
     ShapeTestFramework.TestShape(new Cylinder(42, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(1, 1, 1).Normalised, 2.2f, 0.25f), create);
     ShapeTestFramework.TestShape(new Cylinder(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(1, 1, 1).Normalised, 2.2f, 0.25f), create);
     ShapeTestFramework.TestShape(new Cylinder(42, new Vector3(-1.0f, -0.5f, -0.25f), new Vector3(0.25f, 0.25f, 1.0f).Normalised, 0.15f), create);
     ShapeTestFramework.TestShape(new Cylinder(42, 1, new Vector3(-1.0f, -0.5f, -0.25f), new Vector3(0.25f, 0.25f, 1.0f).Normalised, 0.15f), create);
 }
Пример #7
0
 public void BoxTest()
 {
     ShapeTestFramework.CreateShapeFunction create = () => { return(new Box()); };
     ShapeTestFramework.TestShape(new Box(), create);
     ShapeTestFramework.TestShape(new Box(42), create);
     ShapeTestFramework.TestShape(new Box(42, 1), create);
     ShapeTestFramework.TestShape(new Box(42, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0.7f, 1.2f, 3.0f)), create);
     ShapeTestFramework.TestShape(new Box(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0.7f, 1.2f, 3.0f)), create);
     ShapeTestFramework.TestShape(new Box(42, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0.7f, 1.2f, 3.0f), new Quaternion(Vector3.One.Normalised, 18.0f * (float)Math.PI / 180.0f)), create);
     ShapeTestFramework.TestShape(new Box(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0.7f, 1.2f, 3.0f), new Quaternion(Vector3.One.Normalised, 18.0f * (float)Math.PI / 180.0f)), create);
 }
Пример #8
0
 public void ArrowTest()
 {
     ShapeTestFramework.CreateShapeFunction create = () => { return(new Arrow()); };
     ShapeTestFramework.TestShape(new Arrow(), create);
     ShapeTestFramework.TestShape(new Arrow(42), create);
     ShapeTestFramework.TestShape(new Arrow(42, 1), create);
     ShapeTestFramework.TestShape(new Arrow(42, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0, 0, 0), 0.05f), create);
     ShapeTestFramework.TestShape(new Arrow(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(0, 0, 0), 0.05f), create);
     ShapeTestFramework.TestShape(new Arrow(42, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(1, 1, 1).Normalised, 2.0f, 0.05f), create);
     ShapeTestFramework.TestShape(new Arrow(42, 1, new Vector3(1.2f, 2.3f, 3.4f), new Vector3(1, 1, 1).Normalised, 2.0f, 0.05f), create);
 }
Пример #9
0
 public void Text2DTest()
 {
     ShapeTestFramework.CreateShapeFunction create = () => { return(new Text2D()); };
     ShapeTestFramework.TestShape(new Text2D(), create);
     ShapeTestFramework.TestShape(new Text2D("Seven and a half..."), create, ValidateText2D);
     ShapeTestFramework.TestShape(new Text2D("The answer is...", 42), create, ValidateText2D);
     ShapeTestFramework.TestShape(new Text2D("The answer is...", 42, 1), create, ValidateText2D);
     ShapeTestFramework.TestShape(new Text2D("Seven and a half...", new Vector3(1.2f, 2.3f, 3.4f))
     {
         InWorldSpace = true
     }, create, ValidateText2D);
     ShapeTestFramework.TestShape(new Text2D("The answer is...", 42, new Vector3(1.2f, 2.3f, 3.4f))
     {
         InWorldSpace = false
     }, create, ValidateText2D);
     ShapeTestFramework.TestShape(new Text2D("The answer is...", 42, 1, new Vector3(1.2f, 2.3f, 3.4f)), create, ValidateText2D);
 }
Пример #10
0
 public void Text3DTest()
 {
     ShapeTestFramework.CreateShapeFunction create = () => { return(new Text3D()); };
     ShapeTestFramework.TestShape(new Text3D(), create, ValidateText3D);
     ShapeTestFramework.TestShape(new Text3D("Seven and a half..."), create, ValidateText3D);
     ShapeTestFramework.TestShape(new Text3D("The answer is...", 42), create, ValidateText3D);
     ShapeTestFramework.TestShape(new Text3D("The answer is...", 42, 1), create, ValidateText3D);
     ShapeTestFramework.TestShape(new Text3D("Seven and a half...", new Vector3(1.2f, 2.3f, 3.4f))
     {
         ScreenFacing = true
     }, create, ValidateText3D);
     ShapeTestFramework.TestShape(new Text3D("The answer is...", 42, new Vector3(1.2f, 2.3f, 3.4f))
     {
         ScreenFacing = false
     }, create, ValidateText3D);
     ShapeTestFramework.TestShape(new Text3D("The answer is...", 42, 1, new Vector3(1.2f, 2.3f, 3.4f))
     {
         Facing = Vector3.One.Normalised
     }, create, ValidateText3D);
 }
Пример #11
0
        public void TestMeshSet()
        {
            List <Vector3>      vertices    = new List <Vector3>();
            List <int>          indices     = new List <int>();
            List <int>          wireIndices = new List <int>();
            List <Vector3>      normals     = new List <Vector3>();
            List <MeshResource> meshes      = new List <MeshResource>();

            uint[] colours;
            Common.MakeHiResSphere(vertices, indices, normals);

            // Build per vertex colours with colour cycling.
            colours = new uint[vertices.Count];
            for (int i = 0; i < colours.Length; ++i)
            {
                colours[i] = Colour.Cycle(i).Value;
            }

            // Build a wire frame sphere (with many redundant lines).
            wireIndices.Capacity = indices.Count * 2;
            for (int i = 0; i + 2 < indices.Count; i += 3)
            {
                wireIndices.Add(indices[i + 0]);
                wireIndices.Add(indices[i + 1]);
                wireIndices.Add(indices[i + 1]);
                wireIndices.Add(indices[i + 2]);
                wireIndices.Add(indices[i + 2]);
                wireIndices.Add(indices[i + 0]);
            }

            // Create a mesh part.
            uint       nextId = 1;
            SimpleMesh part;

            // Vertices and indices only.
            part = new SimpleMesh(nextId++, Net.MeshDrawType.Triangles);
            part.AddVertices(vertices);
            part.AddIndices(indices);
            meshes.Add(part);

            // Vertices, indices and colours.
            part = new SimpleMesh(nextId++, Net.MeshDrawType.Triangles);
            part.AddVertices(vertices);
            part.AddIndices(indices);
            part.AddColours(colours);
            meshes.Add(part);

            // Points and colours only (essentially a point cloud)
            part = new SimpleMesh(nextId++, Net.MeshDrawType.Points);
            part.AddVertices(vertices);
            part.AddColours(colours);
            meshes.Add(part);

            // Lines
            part = new SimpleMesh(nextId++, Net.MeshDrawType.Triangles);
            part.AddVertices(vertices);
            part.AddIndices(wireIndices);
            meshes.Add(part);

            // One with the lot.
            part = new SimpleMesh(nextId++, Net.MeshDrawType.Triangles);
            part.AddVertices(vertices);
            part.AddNormals(normals);
            part.AddColours(colours);
            part.AddIndices(indices);
            meshes.Add(part);

            ShapeTestFramework.CreateShapeFunction create = () => { return(new MeshSet()); };

            // Simple test first. One part.
            ShapeTestFramework.TestShape(new MeshSet(42).AddPart(meshes[0]), create, ValidateMeshSetShape);

            // Now a multi-part MeshSet.
            MeshSet set = new MeshSet(42, 1);
            Matrix4 transform;

            for (int i = 0; i < meshes.Count; ++i)
            {
                transform             = Rotation.ToMatrix4(new Quaternion(new Vector3(i, i + 1, i - 3).Normalised, (float)Math.PI * (i + 1) * 6.0f / 180.0f));
                transform.Translation = new Vector3(i, i - 3.2f, 1.5f * i);
                transform.ApplyScaling(new Vector3(0.75f, 0.75f, 0.75f));
                set.AddPart(meshes[i], transform);
            }
            ShapeTestFramework.TestShape(set, create, ValidateMeshSetShape);
        }