Beispiel #1
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);
        }