Beispiel #1
0
        public static Mesh Create(Vector3 position, Quaternion rotation, float edge, Shader shader, ISampler normalSampler)
        {
            float h = edge / 2;
            var vertices = new[]
            {
                new Vector3(-h, h, -h),
                new Vector3(h, h, -h),
                new Vector3(h, h, h),
                new Vector3(-h, h, h),
                new Vector3(-h, -h, -h),
                new Vector3(h, -h, -h),
                new Vector3(h, -h, h),
                new Vector3(-h, -h, h)
            };
            var triangles = new[]
            {
                new Triangle(0, 1, 2),
                new Triangle(2, 3, 0),
                new Triangle(0, 3, 7),
                new Triangle(0, 7, 4),
                new Triangle(1, 0, 4),
                new Triangle(1, 4, 5),
                new Triangle(2, 1, 5),
                new Triangle(2, 5, 6),
                new Triangle(3, 2, 6),
                new Triangle(3, 6, 7),
                new Triangle(4, 6, 5),
                new Triangle(4, 7, 6)
            };

            return new Mesh(vertices, triangles, position, rotation, shader, normalSampler);
        }
        /// <summary>
        ///     Creates triangle approximation of a sphere
        /// </summary>
        /// <param name="position">Center of the sphere</param>
        /// <param name="rotation">Spheres rotation</param>
        /// <param name="radius">Radius of the sphere</param>
        /// <param name="rings">Nummber of horizontal vertex rings approximating the sphere. Poles not included</param>
        /// <param name="segments">Number of segments per ring</param>
        /// <param name="shader">Shader to use for the mesh</param>
        /// <param name="normalSampler">Normal sampler to use for the mesh</param>
        public static Mesh Create(Vector3 position, Quaternion rotation, double radius, int rings, int segments, Shader shader,
            ISampler normalSampler)
        {
            Vector3[] vertices = BuildVertices(radius, segments, rings);
            Triangle[] triangles = BuildTriangles(segments, rings);

            return new Mesh(vertices, triangles, position, rotation, shader, normalSampler);
        }
Beispiel #3
0
 public Mesh(Vector3[] vertices, Triangle[] triangles, Vector3 position, Quaternion rotation, Shader shader, ISampler normalSampler)
 {
     Vertices = vertices;
     _triangles = triangles;
     Shader = shader;
     Position = position;
     Rotation = rotation;
     _normalSampler = normalSampler;
     Init();
 }
Beispiel #4
0
        public static Mesh Create(Vector3 position, Quaternion rotation, Vector3 forward, Vector3 right, float edge, Shader shader,
            ISampler normalSampler)
        {
            float halfEdge = edge / 2;
            var vertices = new[]
            {
                (forward + right) * halfEdge,
                (forward - right) * halfEdge,
                (right - forward) * halfEdge,
                (-1 * forward - right) * halfEdge
            };
            var triangles = new[]
            {
                new Triangle(0, 1, 2),
                new Triangle(1, 3, 2)
            };

            return new Mesh(vertices, triangles, position, rotation, shader, normalSampler);
        }