当前位置: 首页>>代码示例>>C#>>正文


C# Mesh.GetAttributes方法代码示例

本文整理汇总了C#中Mesh.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.GetAttributes方法的具体用法?C# Mesh.GetAttributes怎么用?C# Mesh.GetAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mesh的用法示例。


在下文中一共展示了Mesh.GetAttributes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderMesh

        public override void RenderMesh(Mesh mesh)
        {
            BeginMode primitiveType = BeginMode.Triangles;
            if (mesh.PrimitiveType == Mesh.PrimitiveTypes.Triangles)
                primitiveType = BeginMode.Triangles;
            else if (mesh.PrimitiveType == Mesh.PrimitiveTypes.TriangleStrip)
                primitiveType = BeginMode.TriangleStrip;
            else if (mesh.PrimitiveType == Mesh.PrimitiveTypes.TriangleFan)
                primitiveType = BeginMode.TriangleFan;
            else if (mesh.PrimitiveType == Mesh.PrimitiveTypes.Quads)
                primitiveType = BeginMode.Quads;
            else if (mesh.PrimitiveType == Mesh.PrimitiveTypes.Quads)
                primitiveType = BeginMode.QuadStrip;
            else if (mesh.PrimitiveType == Mesh.PrimitiveTypes.Patches)
                primitiveType = BeginMode.Patches;
            else if (mesh.PrimitiveType == Mesh.PrimitiveTypes.Points)
                primitiveType = BeginMode.Points;
            else if (mesh.PrimitiveType == Mesh.PrimitiveTypes.Lines)
                primitiveType = BeginMode.Lines;

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

            GL.BindBuffer(BufferTarget.ArrayBuffer, mesh.vbo);
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.POSITIONS))
            {
                GL.EnableVertexAttribArray(0);
                GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, mesh.vertexSize * sizeof(float), mesh.GetAttributes().GetPositionOffset());
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS0))
            {
                GL.EnableVertexAttribArray(1);
                GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, mesh.vertexSize * sizeof(float), mesh.GetAttributes().GetTexCoord0Offset());
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS1))
            {
                GL.EnableVertexAttribArray(2);
                GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, mesh.vertexSize * sizeof(float), mesh.GetAttributes().GetTexCoord1Offset());
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.NORMALS))
            {
                GL.EnableVertexAttribArray(3);
                GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, mesh.vertexSize * sizeof(float), mesh.GetAttributes().GetNormalOffset());
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TANGENTS))
            {
                GL.EnableVertexAttribArray(4);
                GL.VertexAttribPointer(4, 3, VertexAttribPointerType.Float, false, mesh.vertexSize * sizeof(float), mesh.GetAttributes().GetTangentOffset());
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BITANGENTS))
            {
                GL.EnableVertexAttribArray(5);
                GL.VertexAttribPointer(5, 3, VertexAttribPointerType.Float, false, mesh.vertexSize * sizeof(float), mesh.GetAttributes().GetBitangentOffset());
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BONEWEIGHTS))
            {
                GL.EnableVertexAttribArray(6);
                GL.VertexAttribPointer(6, 4, VertexAttribPointerType.Float, false, mesh.vertexSize * sizeof(float), mesh.GetAttributes().GetBoneWeightOffset());
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BONEINDICES))
            {
                GL.EnableVertexAttribArray(7);
                GL.VertexAttribPointer(7, 4, VertexAttribPointerType.Float, false, mesh.vertexSize * sizeof(float), mesh.GetAttributes().GetBoneIndexOffset());
            }

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.ibo);
            GL.DrawElements(primitiveType, mesh.size, DrawElementsType.UnsignedInt, 0);

            if (mesh.GetAttributes().HasAttribute(VertexAttributes.POSITIONS)) GL.DisableVertexAttribArray(0);
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS0)) GL.DisableVertexAttribArray(1);
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS1)) GL.DisableVertexAttribArray(2);
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.NORMALS)) GL.DisableVertexAttribArray(3);
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TANGENTS)) GL.DisableVertexAttribArray(4);
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BITANGENTS)) GL.DisableVertexAttribArray(5);
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BONEWEIGHTS)) GL.DisableVertexAttribArray(6);
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BONEINDICES)) GL.DisableVertexAttribArray(7);
        }
开发者ID:ajmd17,项目名称:apexengine-sharp,代码行数:76,代码来源:GLRenderer.cs

示例2: CreateFloatBuffer

        public static float[] CreateFloatBuffer(Mesh mesh)
        {
            List<Vertex> a = mesh.vertices;
            int vertSize = 0;
            int prevSize = 0;
            int offset = 0;

            if (mesh.GetAttributes().HasAttribute(VertexAttributes.POSITIONS))
            {
                offset += prevSize * 4;
                mesh.GetAttributes().SetPositionOffset(offset);
                prevSize = 3;
                vertSize += prevSize;
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS0))
            {
                offset += prevSize * 4;
                mesh.GetAttributes().SetTexCoord0Offset(offset);
                prevSize = 2;
                vertSize += prevSize;
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS1))
            {
                offset += prevSize * 4;
                mesh.GetAttributes().SetTexCoord1Offset(offset);
                prevSize = 2;
                vertSize += prevSize;
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.NORMALS))
            {
                offset += prevSize * 4;
                mesh.GetAttributes().SetNormalOffset(offset);
                prevSize = 3;
                vertSize += prevSize;
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TANGENTS))
            {
                offset += prevSize * 4;
                mesh.GetAttributes().SetTangentOffset(offset);
                prevSize = 3;
                vertSize += prevSize;
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BITANGENTS))
            {
                offset += prevSize * 4;
                mesh.GetAttributes().SetBitangentOffset(offset);
                prevSize = 3;
                vertSize += prevSize;
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BONEWEIGHTS))
            {
                offset += prevSize * 4;
                mesh.GetAttributes().SetBoneWeightOffset(offset);
                prevSize = 4;
                vertSize += prevSize;
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.BONEINDICES))
            {
                offset += prevSize * 4;
                mesh.GetAttributes().SetBoneIndexOffset(offset);
                prevSize = 4;
                vertSize += prevSize;
            }
            mesh.vertexSize = vertSize;

            List<float> floatBuffer = new List<float>();
            for (int i = 0; i < mesh.vertices.Count; i++)
            {
                if (mesh.GetAttributes().HasAttribute(VertexAttributes.POSITIONS))
                {
                    if (mesh.vertices[i].GetPosition() != null)
                    {
                        floatBuffer.Add(mesh.vertices[i].GetPosition().x);
                        floatBuffer.Add(mesh.vertices[i].GetPosition().y);
                        floatBuffer.Add(mesh.vertices[i].GetPosition().z);
                    }
                }
                if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS0))
                {
                    if (mesh.vertices[i].GetTexCoord0() != null)
                    {
                        floatBuffer.Add(mesh.vertices[i].GetTexCoord0().x);
                        floatBuffer.Add(mesh.vertices[i].GetTexCoord0().y);
                    }
                }
                if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS1))
                {
                    if (mesh.vertices[i].GetTexCoord1() != null)
                    {
                        floatBuffer.Add(mesh.vertices[i].GetTexCoord1().x);
                        floatBuffer.Add(mesh.vertices[i].GetTexCoord1().y);
                    }
                }
                if (mesh.GetAttributes().HasAttribute(VertexAttributes.NORMALS))
                {
                    if (mesh.vertices[i].GetNormal() != null)
                    {
                        floatBuffer.Add(mesh.vertices[i].GetNormal().x);
                        floatBuffer.Add(mesh.vertices[i].GetNormal().y);
                        floatBuffer.Add(mesh.vertices[i].GetNormal().z);
//.........这里部分代码省略.........
开发者ID:ajmd17,项目名称:apexengine-sharp,代码行数:101,代码来源:MeshUtil.cs

示例3: SaveMesh

        private static void SaveMesh(Mesh mesh, XmlWriter writer)
        {
            writer.WriteStartElement(TOKEN_MESH);

            List<Vector3f> positions = new List<Vector3f>();
            List<Vector3f> normals = new List<Vector3f>();
            List<Vector2f> texcoords0 = new List<Vector2f>();
            List<Vector2f> texcoords1 = new List<Vector2f>();
            List<BoneAssign> boneAssigns = new List<BoneAssign>();

            List<int> facesP = new List<int>();
            List<int> facesN = new List<int>();
            List<int> facesT0 = new List<int>();
            List<int> facesT1 = new List<int>();
            List<Vertex> tmpVerts = new List<Vertex>();

            for (int i = 0; i < mesh.indices.Count; i++)
            {
                tmpVerts.Add(mesh.vertices[mesh.indices[i]]);
            }
            for (int i = 0; i < tmpVerts.Count; i++)
            {
                Vertex v = tmpVerts[i];
                if (!positions.Contains(v.GetPosition()))
                    positions.Add(v.GetPosition());
                if (!normals.Contains(v.GetNormal()))
                    normals.Add(v.GetNormal());
                if (!texcoords0.Contains(v.GetTexCoord0()))
                    texcoords0.Add(v.GetTexCoord0());
                if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS1))
                {
                    if (!texcoords1.Contains(v.GetTexCoord1()))
                        texcoords1.Add(v.GetTexCoord1());
                }
                facesP.Add(positions.IndexOf(v.GetPosition()));
                facesN.Add(normals.IndexOf(v.GetNormal()));
                facesT0.Add(texcoords0.IndexOf(v.GetTexCoord0()));
                if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS1))
                {
                    facesT1.Add(texcoords1.IndexOf(v.GetTexCoord1()));
                }
                for (int j = 0; j < 4; j++)
                {
                    if (tmpVerts[i].GetBoneWeight(j) > 0f)
                    {
                        boneAssigns.Add(new BoneAssign(i,
                                        tmpVerts[i].GetBoneWeight(j),
                                        (int)tmpVerts[i].GetBoneIndex(j)));
                    }
                }
            }
            writer.WriteAttributeString(TOKEN_HAS_POSITIONS, (facesP.Count > 0).ToString());
            writer.WriteAttributeString(TOKEN_HAS_NORMALS, (facesN.Count > 0).ToString());
            writer.WriteAttributeString(TOKEN_HAS_TEXCOORDS, (facesT0.Count > 0).ToString());

            writer.WriteStartElement(TOKEN_VERTICES);

            for (int i = 0; i < positions.Count; i++)
            {
                writer.WriteStartElement(TOKEN_POSITION);
                writer.WriteAttributeString("x", positions[i].x.ToString());
                writer.WriteAttributeString("y", positions[i].y.ToString());
                writer.WriteAttributeString("z", positions[i].z.ToString());
                writer.WriteEndElement();
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.NORMALS))
            {
                for (int i = 0; i < normals.Count; i++)
                {
                    writer.WriteStartElement(TOKEN_NORMAL);
                    writer.WriteAttributeString("x", normals[i].X.ToString());
                    writer.WriteAttributeString("y", normals[i].Y.ToString());
                    writer.WriteAttributeString("z", normals[i].Z.ToString());
                    writer.WriteEndElement();
                }
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS0))
            {
                for (int i = 0; i < texcoords0.Count; i++)
                {
                    writer.WriteStartElement(TOKEN_TEXCOORD0);
                    writer.WriteAttributeString("x", texcoords0[i].X.ToString());
                    writer.WriteAttributeString("y", texcoords0[i].Y.ToString());
                    writer.WriteEndElement();
                }
            }
            if (mesh.GetAttributes().HasAttribute(VertexAttributes.TEXCOORDS1))
            {
                for (int i = 0; i < texcoords1.Count; i++)
                {
                    writer.WriteStartElement(TOKEN_TEXCOORD1);
                    writer.WriteAttributeString("x", texcoords1[i].X.ToString());
                    writer.WriteAttributeString("y", texcoords1[i].Y.ToString());
                    writer.WriteEndElement();
                }
            }

            writer.WriteEndElement(); // vertices

            writer.WriteStartElement(TOKEN_FACES);
//.........这里部分代码省略.........
开发者ID:ajmd17,项目名称:apexengine-sharp,代码行数:101,代码来源:ApxExporter.cs


注:本文中的Mesh.GetAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。