コード例 #1
0
            /// <summary>
            /// Generate normals for this Element.
            /// </summary>
            /// <param name="vertexArray">
            /// The <see cref="VertexArrayObject"/>
            /// </param>
            public override void GenerateNormals(VertexArrayObject vertexArray)
            {
                IVertexArray positionArray = vertexArray.GetVertexArray(VertexArraySemantic.Position);

                if (positionArray == null)
                {
                    throw new InvalidOperationException("position semantic not set");
                }

                IVertexArray normalArray = vertexArray.GetVertexArray(VertexArraySemantic.Normal);

                if (normalArray == null)
                {
                    throw new InvalidOperationException("normal semantic not set");
                }
                if (normalArray.Array == null)
                {
                    throw new InvalidOperationException("normal array not set");
                }

                if (positionArray.Array != null)
                {
                    positionArray.Array.Map();
                }
                normalArray.Array.Map();

                try {
                    switch (ElementsMode)
                    {
                    case PrimitiveType.Triangles:
                        switch (positionArray.ArraySection.ItemType)
                        {
                        case ArrayBufferItemType.Float3:
                            GenerateNormalsTriangle3f(positionArray, normalArray);
                            break;

                        case ArrayBufferItemType.Float4:
                            GenerateNormalsTriangle4f(positionArray, normalArray);
                            break;

                        default:
                            throw new NotSupportedException("normals generation not supported for elements of type " + positionArray.ArraySection.ItemType);
                        }
                        break;

                    default:
                        throw new NotSupportedException("normals generation not supported for primitive " + ElementsMode);
                    }
                } finally {
                    if (positionArray.Array != null)
                    {
                        positionArray.Array.Unmap();
                    }
                    normalArray.Array.Unmap();
                }
            }
コード例 #2
0
            /// <summary>
            /// Generate texture coordinates for this Element.
            /// </summary>
            /// <param name="vertexArray">
            /// The <see cref="VertexArrayObject"/>
            /// </param>
            public override void GenerateTexCoord(VertexArrayObject vertexArray, VertexArrayTexGenDelegate genTexCoordCallback)
            {
                IVertexArray positionArray = vertexArray.GetVertexArray(VertexArraySemantic.Position);

                if (positionArray == null)
                {
                    throw new InvalidOperationException("position semantic not set");
                }

                IVertexArray texArray = vertexArray.GetVertexArray(VertexArraySemantic.TexCoord);

                if (texArray == null)
                {
                    throw new InvalidOperationException("texture semantic not set");
                }
                if (texArray.Array == null)
                {
                    throw new InvalidOperationException("texture array not set");
                }

                if (positionArray.Array != null)
                {
                    positionArray.Array.Map();
                }
                texArray.Array.Map();
                ArrayIndices.Map();

                try {
                    switch (ElementsMode)
                    {
                    case PrimitiveType.Triangles:
                    case PrimitiveType.TriangleStrip:
                        switch (positionArray.ArraySection.ItemType)
                        {
                        case ArrayBufferItemType.Float3:
                            GenerateTexCoordsTriangle3f(positionArray, texArray, genTexCoordCallback);
                            break;

                        default:
                            throw new NotSupportedException("normals generation not supported for elements of type " + positionArray.ArraySection.ItemType);
                        }
                        break;

                    default:
                        throw new NotSupportedException("normals generation not supported for primitive " + ElementsMode);
                    }
                } finally {
                    if (positionArray.Array != null)
                    {
                        positionArray.Array.Unmap();
                    }
                    texArray.Array.Unmap();
                    ArrayIndices.Unmap();
                }
            }
コード例 #3
0
            /// <summary>
            /// Generate tangents for this Element.
            /// </summary>
            /// <param name="vertexArray">
            /// The <see cref="VertexArrayObject"/>
            /// </param>
            public override void GenerateTangents(VertexArrayObject vertexArray)
            {
                IVertexArray positionArray = vertexArray.GetVertexArray(VertexArraySemantic.Position);

                if (positionArray == null)
                {
                    throw new InvalidOperationException("position semantic not set");
                }
                IVertexArray texArray = vertexArray.GetVertexArray(VertexArraySemantic.TexCoord);

                if (texArray == null)
                {
                    throw new InvalidOperationException("texture semantic not set");
                }

                IVertexArray normalArray = vertexArray.GetVertexArray(VertexArraySemantic.Normal);

                if (normalArray == null)
                {
                    throw new InvalidOperationException("normal semantic not set");
                }
                if (normalArray.Array == null)
                {
                    throw new InvalidOperationException("normal array not set");
                }

                IVertexArray tanArray = vertexArray.GetVertexArray(VertexArraySemantic.Tangent);

                if (tanArray == null)
                {
                    throw new InvalidOperationException("tangent semantic not set");
                }
                if (tanArray.Array == null)
                {
                    throw new InvalidOperationException("tangent array not set");
                }

                IVertexArray bitanArray = vertexArray.GetVertexArray(VertexArraySemantic.Bitangent);

                if (bitanArray == null)
                {
                    throw new InvalidOperationException("bitangent semantic not set");
                }
                if (bitanArray.Array == null)
                {
                    throw new InvalidOperationException("bitangent array not set");
                }

                if (positionArray.Array != null)
                {
                    positionArray.Array.Map();
                }
                if (texArray.Array != null)
                {
                    texArray.Array.Map();
                }
                normalArray.Array.Map();
                tanArray.Array.Map();
                bitanArray.Array.Map();
                ArrayIndices.Map();

                try {
                    switch (ElementsMode)
                    {
                    case PrimitiveType.TriangleStrip:
                        switch (positionArray.ArraySection.ItemType)
                        {
                        case ArrayBufferItemType.Float3:
                            GenerateTangentsTriangleStrip3f(positionArray, normalArray, texArray, tanArray, bitanArray);
                            break;

                        default:
                            throw new NotSupportedException("normals generation not supported for elements of type " + positionArray.ArraySection.ItemType);
                        }
                        break;

                    default:
                        throw new NotSupportedException("normals generation not supported for primitive " + ElementsMode);
                    }
                } finally {
                    if (positionArray.Array != null)
                    {
                        positionArray.Array.Unmap();
                    }
                    if (texArray.Array != null)
                    {
                        texArray.Array.Unmap();
                    }
                    normalArray.Array.Unmap();
                    tanArray.Array.Unmap();
                    bitanArray.Array.Unmap();
                    ArrayIndices.Unmap();
                }
            }