More colors for Geometry object

Apr 11, 2010 at 1:56 PM

I made my own rectangle class as a descendant of Geometry class. Here is the code.

public class Rectangle : Geometry
    {
        private bool _isLoaded = false;

        protected override void OnLoaded()
        {
            _isLoaded = true;
            Prepare();
            base.OnLoaded();
        }

        private void Prepare()
        {
            if (!_isLoaded)
            {
                return;
            }

            float halfWidth = (float)Width / 2f;
            float halfHeight = (float)Height / 2f;

            Vertex a = new Vertex(-halfWidth, 0, +halfHeight);
            Vertex b = new Vertex(+halfWidth, 0, +halfHeight);
            Vertex c = new Vertex(-halfWidth, 0, -halfHeight);
            Vertex d = new Vertex(+halfWidth, 0, -halfHeight);

            GeometryContext.AllocateVertices(4);
            GeometryContext.SetVertex(0, a);
            GeometryContext.SetVertex(1, b);
            GeometryContext.SetVertex(2, c);
            GeometryContext.SetVertex(3, d);

            GeometryContext.AllocateFaces(2);
            GeometryContext.SetFace(0, new Face(2, 1, 0) { Normal = Vector.Up, DiffuseA = 2, DiffuseB = 1, DiffuseC = 0 });
            GeometryContext.SetFace(1, new Face(1, 2, 3) { Normal = Vector.Up, DiffuseA = 1, DiffuseB = 2, DiffuseC = 3 });

            GeometryHelper.CalculateVertexNormals(GeometryContext);
        }

    }

I can colorize it as a whole object with single color but I don't know how to paint both triangles (faces) with different colors. This has no effect:

 

GeometryContext.SetFace(0, new Face(2, 1, 0) { Color = [paramColor1], Normal = Vector.Up, DiffuseA = 2, DiffuseB = 1, DiffuseC = 0 });
GeometryContext.SetFace(1, new Face(1, 2, 3) { Color = [paramColor2], Normal = Vector.Up, DiffuseA = 1, DiffuseB = 2, DiffuseC = 3 });

Any suggestions?

 

 

 

Coordinator
Apr 12, 2010 at 8:14 AM

That is a bug, it will in fact consider the color of the Face and even the color of the Vertex, but its a bug for now.

The only way around it would be to set two different materials for each of the Faces for now.