private void InitializeMaterialDrawingData()
        {
            uint numOfVertices = 18;
            LCC3Mesh mesh = new LCC3Mesh(0, "mymesh");
            LCC3VertexLocations locations = new LCC3VertexLocations(1, "locations");
            locations.AllocateVertexCapacity(numOfVertices);
            // Top face
            locations.SetLocation(new LCC3Vector(0.0f, 0.0f, 0.0f), 0);
            locations.SetLocation(new LCC3Vector(0.0f, 0.0f, 5.0f), 1);
            locations.SetLocation(new LCC3Vector(5.0f, 0.0f, 0.0f), 2);

            locations.SetLocation(new LCC3Vector(5.0f, 0.0f, 0.0f), 3);
            locations.SetLocation(new LCC3Vector(5.0f, 0.0f, 5.0f), 4);
            locations.SetLocation(new LCC3Vector(0.0f, 0.0f, 5.0f), 5);

            // Side front face
            locations.SetLocation(new LCC3Vector(0.0f, 0.0f, 5.0f), 6);
            locations.SetLocation(new LCC3Vector(0.0f, -5.0f, 5.0f), 7);
            locations.SetLocation(new LCC3Vector(5.0f, 0.0f, 5.0f), 8);

            locations.SetLocation(new LCC3Vector(5.0f, 0.0f, 5.0f), 9);
            locations.SetLocation(new LCC3Vector(5.0f, -5.0f, 5.0f), 10);
            locations.SetLocation(new LCC3Vector(0.0f, -5.0f, 5.0f), 11);

            // Side left face
            locations.SetLocation(new LCC3Vector(0.0f, 0.0f, 0.0f), 12);
            locations.SetLocation(new LCC3Vector(0.0f, -5.0f, 0.0f), 13);
            locations.SetLocation(new LCC3Vector(0.0f, 0.0f, 5.0f), 14);

            locations.SetLocation(new LCC3Vector(0.0f, 0.0f, 5.0f), 15);
            locations.SetLocation(new LCC3Vector(0.0f, -5.0f, 5.0f), 16);
            locations.SetLocation(new LCC3Vector(0.0f, -5.0f, 0.0f), 17);

            LCC3VertexNormals normals = new LCC3VertexNormals(1, "normals");
            normals.AllocateVertexCapacity(numOfVertices);
            // Top face normals
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, 1.0f, -1.0f).NormalizedVector(), 0);
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, 1.0f, 1.0f).NormalizedVector(), 1);
            normals.SetNormalAtIndex(new LCC3Vector(1.0f, 1.0f, -1.0f).NormalizedVector(), 2);

            normals.SetNormalAtIndex(new LCC3Vector(1.0f, 1.0f, -1.0f).NormalizedVector(), 3);
            normals.SetNormalAtIndex(new LCC3Vector(1.0f, 1.0f, 1.0f).NormalizedVector(), 4);
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, 1.0f, 1.0f).NormalizedVector(), 5);

            // Side front face normals
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, 1.0f, 1.0f).NormalizedVector(), 6);
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, -1.0f, 1.0f).NormalizedVector(), 7);
            normals.SetNormalAtIndex(new LCC3Vector(1.0f, 1.0f, 1.0f).NormalizedVector(), 8);

            normals.SetNormalAtIndex(new LCC3Vector(1.0f, 1.0f, 1.0f).NormalizedVector(), 9);
            normals.SetNormalAtIndex(new LCC3Vector(1.0f, -1.0f, 1.0f).NormalizedVector(), 10);
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, -1.0f, 1.0f).NormalizedVector(), 11);

            // Side left face normals
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, 1.0f, -1.0f).NormalizedVector(), 12);
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, -1.0f, -1.0f).NormalizedVector(), 13);
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, 1.0f, 1.0f).NormalizedVector(), 14);

            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, 1.0f, 1.0f).NormalizedVector(), 15);
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, -1.0f, 1.0f).NormalizedVector(), 16);
            normals.SetNormalAtIndex(new LCC3Vector(-1.0f, -1.0f, -1.0f).NormalizedVector(), 17);

            /*
            for (uint i=0; i < 6; i++)
            {
                normals.SetNormalAtIndex(new LCC3Vector(0.0f, 1.0f, 0.0f).NormalizedVector(), i);
                normals.SetNormalAtIndex(new LCC3Vector(0.0f, 0.0f, 1.0f).NormalizedVector(), i + 6);
                normals.SetNormalAtIndex(new LCC3Vector(-1.0f, 0.0f, 0.0f).NormalizedVector(), i + 12);
            }
            */

            LCC3VertexTextureCoordinates texCoords = new LCC3VertexTextureCoordinates(0, "texCoords");
            texCoords.AllocateVertexCapacity(numOfVertices);
            for (uint i=0; i < numOfVertices / 6; i++)
            {
                uint offset = i * 6;
                texCoords.SetTexCoord2FAtIndex(new CCTex2F(0.0f, 0.0f), 0 + offset);
                texCoords.SetTexCoord2FAtIndex(new CCTex2F(0.0f, 1.0f), 1 + offset);
                texCoords.SetTexCoord2FAtIndex(new CCTex2F(1.0f, 0.0f), 2 + offset);

                texCoords.SetTexCoord2FAtIndex(new CCTex2F(1.0f, 0.0f), 3 + offset);
                texCoords.SetTexCoord2FAtIndex(new CCTex2F(1.0f, 1.0f), 4 + offset);
                texCoords.SetTexCoord2FAtIndex(new CCTex2F(0.0f, 1.0f), 5 + offset);
            }

            LCC3VertexColors colors = new LCC3VertexColors(0, "colors");
            colors.AllocateVertexCapacity(numOfVertices);
            for (uint i=0; i < numOfVertices; i++)
            {
                colors.SetColor4FAtIndex(new CCColor4F(0.2f, 1.0f, 0.0f, 1.0f), i);
            }

            mesh.VertexLocations = locations;
            mesh.VertexNormals = normals;
            mesh.VertexTextureCoords = texCoords;
            //mesh.VertexColors = colors;

            LCC3Scene scene = new LCC3Scene();
            scene.AmbientLight = new CCColor4F(0.5f, 0.5f, 0.0f, 0.5f);

            LCC3Material defaultMaterial = new LCC3Material(0, "Default");
            defaultMaterial.ShaderProgram = _materialShaderProgram;
            defaultMaterial.AmbientColor = new CCColor4F(0.2f, 1.0f, 0.0f, 1.0f);
            defaultMaterial.DiffuseColor = new CCColor4F(0.2f, 1.0f, 0.0f, 0.0f);
            defaultMaterial.SpecularColor = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f);
            defaultMaterial.EmissionColor = new CCColor4F(0.2f, 1.0f, 0.0f, 1.0f);
            defaultMaterial.Shininess = 0.0f;
            defaultMaterial.ShouldUseLighting = true;

            LCC3MeshNode meshNode = new LCC3MeshNode();
            meshNode.Material = defaultMaterial;
            meshNode.Mesh = mesh;
            meshNode.Parent = scene;

            LCC3Light[] lights = new LCC3Light[(int)LCC3Light.DefaultMaxNumOfLights];
            for (int i = 0; i < LCC3Light.DefaultMaxNumOfLights; i++)
            {
                lights[i] = new LCC3Light();
                lights[i].Visible = true;
                lights[i].Location = (new LCC3Vector(0.0f, -1.0f, -0.2f)).NormalizedVector();
                lights[i].AmbientColor = new CCColor4F(0.0f, 0.5f, 0.0f, 1.0f);
                lights[i].DiffuseColor = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f);
                lights[i].SpecularColor = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f);
                }

            scene.Lights = lights;

            _drawingVisitor = new LCC3NodeDrawingVisitor();
            _drawingVisitor.CurrentColor = new CCColor4F(1.0f, 0.0f, 0.0f, 1.0f);
            _drawingVisitor.CurrentNode = meshNode;
            _drawingVisitor.StartingNode = meshNode;

            _drawingVisitor.ModelMatrix = LCC3Matrix4x4.CC3MatrixIdentity;
            _drawingVisitor.ViewMatrix = new LCC3Matrix4x4(_graphicsContext.ViewMatrix.XnaMatrix);
            _drawingVisitor.ProjMatrix = new LCC3Matrix4x4(_graphicsContext.ProjectionMatrix.XnaMatrix);

            _drawingVisitor.ProgramPipeline = _progPipeline;

            _progPipeline.BindProgramWithVisitor(_materialShaderProgram, _drawingVisitor);

            //_progPipeline.GenerateVertexBuffer();
        }
Example #2
0
        private void CreateVertexContent(LCC3VertexContent vtxContentTypes)
        {
            if (_vertexLocations == null)
            {
                this.VertexLocations = new LCC3VertexLocations(0, "locations");
            }

            if ((vtxContentTypes & LCC3VertexContent.VertexContentNormal) > 0)
            {
                if (_vertexNormals == null)
                {
                    this.VertexNormals = new LCC3VertexNormals(0, "normals");
                }
            }
            else
            {
                this.VertexNormals = null;
            }

            if ((vtxContentTypes & LCC3VertexContent.VertexContentTangent) > 0)
            {
                if (_vertexTangents == null)
                {
                    this.VertexTangents = new LCC3VertexTangents(0, "tangents");
                }
            }
            else
            {
                this.VertexTangents = null;
            }

            if ((vtxContentTypes & LCC3VertexContent.VertexContentBitangent) > 0)
            {
                if (_vertexBitangents == null)
                {
                    this.VertexBitangents = new LCC3VertexTangents(0, "bitangents");
                }
            }
            else
            {
                this.VertexBitangents = null;
            }

            if ((vtxContentTypes & LCC3VertexContent.VertexContentColor) > 0)
            {
                if (_vertexColors == null)
                {
                    LCC3VertexColors vCols = new LCC3VertexColors(0, "colors");
                    vCols.ElementType = LCC3ElementType.UnsignedByte;
                    this.VertexColors = vCols;
                }
            }
            else
            {
                this.VertexColors = null;
            }

            if ((vtxContentTypes & LCC3VertexContent.VertexContentTextureCoordinates) > 0)
            {
                if (_vertexTexCoords == null)
                {
                    this.VertexTextureCoords = new LCC3VertexTextureCoordinates(0, "texcoord");
                }
            }
            else
            {
                this.VertexTextureCoords = null;
            }

            if ((vtxContentTypes & LCC3VertexContent.VertexContentWeights) > 0)
            {
                if (_vertexWeights == null)
                {
                    this.VertexWeights = new LCC3VertexWeights(0, "weights");
                }
            }
            else
            {
                this.VertexWeights = null;
            }

            if ((vtxContentTypes & LCC3VertexContent.VertexContentMatrixIndices) > 0)
            {
                if (_vertexMatrixIndices == null)
                {
                    this.VertexMatrixIndices = new LCC3VertexMatrixIndices(0, "matrixIndices");
                }
            }
            else
            {
                this.VertexMatrixIndices = null;
            }

            if ((vtxContentTypes & LCC3VertexContent.VertexContentPointSize) > 0)
            {
                if (_vertexPointSizes == null)
                {
                    this.VertexPointSizes = new LCC3VertexPointSizes(0, "pointSizes");
                }
            }
            else
            {
                this.VertexPointSizes = null;
            }
        }