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


C# Mesh.SetAttributeTable方法代码示例

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


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

示例1: RebuildAsync

        private void RebuildAsync(Object deviceObj)
        {
            try
            {
                Device device = (Device)deviceObj;

                // Rebuild
                if (_bitmap == null)
                {
                    _bitmap = new Bitmap(1, 1);
                    _valid = true;
                }
                else
                {
                    try
                    {
                        _imageTexture = Texture.FromBitmap(device, _bitmap, Usage.Dynamic, Pool.Default);

                        // Set up the material
                        _imageMaterial = new Material();
                        _imageMaterial.Diffuse = _color;

                        // Set up the rectangular mesh
                        CustomVertex.PositionNormalTextured[] verts = new CustomVertex.PositionNormalTextured[4];

                        verts[0].Position = new Vector3(0, 0, -_height);
                        verts[0].Normal = new Vector3(0, 1, 0);
                        verts[0].Tu = 0; verts[0].Tv = 1;

                        verts[1].Position = new Vector3(_width, 0, -_height);
                        verts[1].Normal = new Vector3(0, 1, 0);
                        verts[1].Tu = 1; verts[1].Tv = 1;

                        verts[2].Position = new Vector3(_width, 0, 0);
                        verts[2].Normal = new Vector3(0, 1, 0);
                        verts[2].Tu = 1; verts[2].Tv = 0;

                        verts[3].Position = new Vector3(0, 0, 0);
                        verts[3].Normal = new Vector3(0, 1, 0);
                        verts[3].Tu = 0; verts[3].Tv = 0;

                        AttributeRange[] attributes = new AttributeRange[1];
                        attributes[0].AttributeId = 0;
                        attributes[0].FaceCount = 2;
                        attributes[0].FaceStart = 0;
                        attributes[0].VertexCount = 4;
                        attributes[0].VertexStart = 0;

                        short[] indices = new short[]
                        {
                            0, 1, 2,
                            0, 2, 3
                        };

                        _imageSprite = new Mesh(2, 4, 0, CustomVertex.PositionNormalTextured.Format, device);

                        _imageSprite.SetVertexBufferData(verts, LockFlags.Discard);
                        _imageSprite.SetIndexBufferData(indices, LockFlags.Discard);
                        _imageSprite.SetAttributeTable(attributes);

                        _valid = true;
                    }
                    catch (Exception)
                    {
                        _valid = false;
                        _imageTexture = null;
                        _imageSprite = null;
                        return;
                    }
                }
            }
            catch (Exception)
            {
                _valid = false;
                _imageTexture = null;
                _imageSprite = null;
            }
            finally
            {
                _building = false;
            }
        }
开发者ID:TomNZ,项目名称:Console-Wrapper,代码行数:82,代码来源:ImageSprite.cs

示例2: createHillObject

            /// <summary>
            /// The create hill object.
            /// </summary>
            /// <param name="device">The device.</param>
            /// <param name="hillPoints">The hill points.</param>
            /// <returns></returns>
            /// <remarks></remarks>
            public static Mesh createHillObject(Device device, List<Vector3> hillPoints)
            {
                Mesh mesh;

                short[] arrayIndices = new short[(hillPoints.Count * 2 - 1) * 6];
                CustomVertex.PositionTextured[] arrayVertices = new CustomVertex.PositionTextured[hillPoints.Count * 2];
                AttributeRange attributeRange = new AttributeRange();

                // Create mesh with desired vertex format and desired size
                mesh = new Mesh(
                    arrayIndices.Length / 3,
                    arrayVertices.Length,
                    MeshFlags.SystemMemory,
                    CustomVertex.PositionTextured.Format,
                    device);

                // For each point in the height field calculate the x, y, z and
                // texture coordinates.
                for (int y = 0; y < hillPoints.Count; y++)
                {
                    CustomVertex.PositionTextured vertex = new CustomVertex.PositionTextured(
                        hillPoints[y].X, hillPoints[y].Y, hillPoints[y].Z, 0, 0);
                    arrayVertices[y * 2] = vertex;
                    vertex = new CustomVertex.PositionTextured(
                        hillPoints[y].X, hillPoints[y].Y, hillPoints[y].Z + hillHeight, 0, 0);
                    arrayVertices[y * 2 + 1] = vertex;
                }

                // Calculate the index buffer.
                for (int y = 0; y < hillPoints.Count; y++)
                {
                    int arrayIndex = (y * 2) * 6;
                    int vertexIndex = y * 2;

                    if (y != hillPoints.Count - 1)
                    {
                        arrayIndices[arrayIndex + 0] = (short)vertexIndex;
                        arrayIndices[arrayIndex + 1] = (short)(vertexIndex + 1);
                        arrayIndices[arrayIndex + 2] = (short)(vertexIndex + 2);
                        arrayIndices[arrayIndex + 3] = (short)(vertexIndex + 2);
                        arrayIndices[arrayIndex + 4] = (short)(vertexIndex + 1);
                        arrayIndices[arrayIndex + 5] = (short)(vertexIndex + 3);
                    }
                    else
                    {
                        arrayIndices[arrayIndex + 0] = (short)vertexIndex;
                        arrayIndices[arrayIndex + 1] = (short)(vertexIndex + 1);
                        arrayIndices[arrayIndex + 2] = 0;
                        arrayIndices[arrayIndex + 3] = 0;
                        arrayIndices[arrayIndex + 4] = (short)(vertexIndex + 1);
                        arrayIndices[arrayIndex + 5] = 1;
                    }
                }

                // There is only one attribute value for this mesh.
                // By specifying an attribute range the DrawSubset function
                // does not have to scan the entire mesh for all faces that are
                // are marked with a particular attribute id.
                attributeRange.AttributeId = 0;
                attributeRange.FaceStart = 0;
                attributeRange.FaceCount = arrayIndices.Length / 3;
                attributeRange.VertexStart = 0;
                attributeRange.VertexCount = arrayVertices.Length;

                mesh.VertexBuffer.SetData(arrayVertices, 0, LockFlags.None);
                mesh.IndexBuffer.SetData(arrayIndices, 0, LockFlags.None);
                mesh.SetAttributeTable(new[] { attributeRange });

                return mesh;
            }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:77,代码来源:SpawnLoads.cs

示例3: CreateMesh

        private void CreateMesh()
        {
            AttributeRange attributeRange = new AttributeRange();

            meshTerrain = new Mesh(indicesMesh.Length / 3, vertices.Length, MeshFlags.SystemMemory, CustomVertex.PositionColored.Format, map.device);
            attributeRange.AttributeId = 0;
            attributeRange.FaceStart = 0;
            attributeRange.FaceCount = indicesMesh.Length / 3;
            attributeRange.VertexStart = 0;
            attributeRange.VertexCount = vertices.Length;

            meshTerrain.VertexBuffer.SetData(vertices, 0, LockFlags.None);
            meshTerrain.IndexBuffer.SetData(indicesMesh, 0, LockFlags.None);
            meshTerrain.SetAttributeTable(new AttributeRange[] { attributeRange });
        }
开发者ID:mnieznalska,项目名称:mobmap,代码行数:15,代码来源:Map3dDraw.cs

示例4: CreateConeLimit

        public static Mesh CreateConeLimit(Microsoft.DirectX.Direct3D.Device d3dDevice, float fltHalfAngle, float fltHeight, int iSides)
        {
            Mesh mesh;
            AttributeRange ar = new AttributeRange();

            float fltRotAmnt = Geometry.DegreeToRadian(360.0f/iSides);

            //create indices
            short[] aryIndices = new short[iSides * 3];

            //create vertices
            CustomVertex.PositionNormal[] aryVerts = new CustomVertex.PositionNormal[iSides + 1];

            //create mesh with desired vertex format and desired size
            mesh = new Mesh(aryIndices.Length/3, aryVerts.Length, MeshFlags.SystemMemory, CustomVertex.PositionNormal.Format, d3dDevice);

            //caclulate the bottom radius vertices
            Vector3 v3Current = new Vector3(0, 0,0);
            aryVerts[0].Position = v3Current;

            v3Current.Z = fltHeight;
            v3Current.TransformCoordinate(Matrix.RotationX(fltHalfAngle));

            aryVerts[1].Position = v3Current;

            for(int i=2; i<iSides + 1; i++)
            {
                v3Current.TransformCoordinate(Matrix.RotationZ(fltRotAmnt));
                aryVerts[i].Position = v3Current;
            }

            //calculate the indices
            int j =0;
            for(int i=0; i<aryIndices.Length; i+=3)
            {
                //get first triangle
                aryIndices[i] = (short)(0);
                aryIndices[i+1] = (short)(j + 2);
                aryIndices[i+2] = (short)(j + 1);

                if(i == aryIndices.Length - 3)
                {
                    aryIndices[i] =	(short)(0);
                    aryIndices[i+1] = (short)(1);
                    aryIndices[i+2] = (short)(j + 1);

                    /*	TODO:  Remove when done
                    Debug.WriteLine("\nj = " + j.ToString());
                    Debug.WriteLine(aryIndices[i]);
                    Debug.WriteLine(aryIndices[i+1]);
                    Debug.WriteLine(aryIndices[i+2]);
                    Debug.WriteLine(aryIndices[i+3]);
                    Debug.WriteLine(aryIndices[i+4]);
                    Debug.WriteLine(aryIndices[i+5]);
                    */
                }
                j++;
            }

            //			aryIndices[0] = 0;
            //			aryIndices[1] = 2;
            //			aryIndices[2] = 1;
            //			aryIndices[3] = 0;
            //			aryIndices[4] = 3;
            //			aryIndices[5] = 2;
            //			aryIndices[6] = 0;
            //			aryIndices[7] = 4;
            //			aryIndices[8] = 3;
            //			aryIndices[9] = 0;
            //			aryIndices[10] = 1;
            //			aryIndices[11] = 4;

            ar.AttributeId = 0;
            ar.FaceStart = 0;
            ar.FaceCount = aryIndices.Length/3;
            ar.VertexStart = 0;
            ar.VertexCount = aryVerts.Length;

            //set the mesh
            mesh.VertexBuffer.SetData(aryVerts, 0, LockFlags.None);
            mesh.IndexBuffer.SetData(aryIndices, 0, LockFlags.None);
            mesh.SetAttributeTable(new AttributeRange[]{ar});

            mesh.ComputeNormals();

            return (mesh);
        }
开发者ID:NeuroRoboticTech,项目名称:AnimatLabVersion1,代码行数:87,代码来源:Util_DX.cs

示例5: RebuildAsync

        private void RebuildAsync(Object deviceObj)
        {
            try
            {
                Device device = (Device)deviceObj;

                // Rebuild
                if (_line.Equals(""))
                {
                    _lineSprite = null;
                    _valid = true;
                }
                else
                {
                    try
                    {
                        int firstTick = Environment.TickCount;
                        System.Drawing.Font font = new System.Drawing.Font(_fontFace, _fontSize);
                        Bitmap b = new Bitmap(_lineWidth, _lineHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                        Graphics g = Graphics.FromImage(b);
                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                        g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, b.Width, b.Height));

                        g.DrawString(_displayString, font, new SolidBrush(Color.White), new PointF(0, 0));
                        //TextRenderer.DrawText(g, _displayString, font, new Point(0, 0), Color.White);

                        _lineTexture = Texture.FromBitmap(device, b, Usage.None, Pool.Managed);

                        //_lineTexture = new Texture(device, (int)_lineWidth * (int)Math.Pow(2.0, (double)mipLevels), (int)_lineHeight * (int)Math.Pow(2.0, (double)mipLevels), mipLevels + 1, Usage.RenderTarget, Format.Unknown, Pool.Default);

                        //Surface s = _lineTexture.GetSurfaceLevel(mipLevels);
                        //SurfaceLoader.FromSurface(s, Surface.FromBitmap(device, b, Pool.Default), Filter.Box, 0xFF0000);

                        g.Dispose();

                        //for (int i = 1; i <= mipLevels; i++)
                        //{
                        //    int width = _lineWidth * (int)Math.Pow(2.0, (double)i);
                        //    int height = _lineHeight * (int)Math.Pow(2, (double)i);

                        //    b = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        //    font = new System.Drawing.Font(_fontFace, _fontSize * (float)Math.Pow(2, (double)i));

                        //    g = Graphics.FromImage(b);
                        //    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                        //    g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, b.Width, b.Height));
                        //    g.DrawString(displayString, font, new SolidBrush(Color.White), new PointF(0, 0));

                        //    s = _lineTexture.GetSurfaceLevel(mipLevels - i);
                        //    SurfaceLoader.FromSurface(s, Surface.FromBitmap(device, b, Pool.Default), Filter.Box, 0xFF0000);

                        //    g.Dispose();
                        //}

                        // Set up the material
                        _lineMaterial = new Material();
                        _lineMaterial.Diffuse = _line.Color;
                        //_lineMaterial.Ambient = GetColor(_line.Type);

                        // Set up the rectangular mesh
                        CustomVertex.PositionNormalTextured[] verts = new CustomVertex.PositionNormalTextured[4];

                        verts[0].Position = new Vector3(0, 0, -_lineHeight);
                        verts[0].Normal = new Vector3(0, 1, 0);
                        verts[0].Tu = 0; verts[0].Tv = 1;

                        verts[1].Position = new Vector3(_lineWidth, 0, -_lineHeight);
                        verts[1].Normal = new Vector3(0, 1, 0);
                        verts[1].Tu = 1; verts[1].Tv = 1;

                        verts[2].Position = new Vector3(_lineWidth, 0, 0);
                        verts[2].Normal = new Vector3(0, 1, 0);
                        verts[2].Tu = 1; verts[2].Tv = 0;

                        verts[3].Position = new Vector3(0, 0, 0);
                        verts[3].Normal = new Vector3(0, 1, 0);
                        verts[3].Tu = 0; verts[3].Tv = 0;

                        AttributeRange[] attributes = new AttributeRange[1];
                        attributes[0].AttributeId = 0;
                        attributes[0].FaceCount = 2;
                        attributes[0].FaceStart = 0;
                        attributes[0].VertexCount = 4;
                        attributes[0].VertexStart = 0;

                        short[] indices = new short[]
                        {
                            0, 1, 2,
                            0, 2, 3
                        };

                        _lineSprite = new Mesh(2, 4, 0, CustomVertex.PositionNormalTextured.Format, device);

                        _lineSprite.SetVertexBufferData(verts, LockFlags.Discard);
                        _lineSprite.SetIndexBufferData(indices, LockFlags.Discard);
                        _lineSprite.SetAttributeTable(attributes);

//.........这里部分代码省略.........
开发者ID:TomNZ,项目名称:Console-Wrapper,代码行数:101,代码来源:LineSprite.cs

示例6: GenerateMesh

        /// <summary>
        /// Generates a mesh from the parsed 
        /// information of the file
        /// </summary>
        private void GenerateMesh(Device d3dDevice)
        {
            if(m_alNormals.Count == 0)
                throw new System.Exception("No normals were found for this mesh.");

            if(m_intNumFaces == 0)
                throw new System.Exception("No faces were found for this mesh.");

            if(m_intNumVerts == 0)
                throw new System.Exception("No vertices were found for this mesh.");

            //create a mesh with Poisiton, Normal, and Texture info.  Even if it doesn't contain TextCoords
            m_d3dMesh = new Mesh(m_intNumFaces, m_intNumVerts, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, d3dDevice);

            //index array
            short[] aryIndices = new short[m_alVertFormat.Count];
            CustomVertex.PositionNormalTextured[] aryVerts = new CustomVertex.PositionNormalTextured[m_intNumVerts];

            Vector3 v, t, n;
            CustomVertex.PositionNormalTextured cvVert;

            //loop through each face and apply the format
            for(int i=0; i<m_intNumFaces * 3; i++)
            {
                //parse the vertex information
                string[] aryVertInfo = (string[])m_alVertFormat[i];

                //first one is vertex index
                short index = short.Parse(aryVertInfo[0]);

                //OBJ format starts at 1 not 0
                index--;

                //set the index arry
                aryIndices[i] = index;
                v = (Vector3)m_alVertices[index];

                t = new Vector3(0,0,0);
                //parse the texture coords
                if( aryVertInfo.Length == 3)
                {
                    index = short.Parse(aryVertInfo[1]);
                    index--;

                    //set the texture coordinate
                    t = (Vector3)m_alTextCoords[index];

                    index = short.Parse(aryVertInfo[2]);
                    index--;

                    //set the normal
                    n = (Vector3)m_alNormals[index];
                }
                else
                {
                    index = short.Parse(aryVertInfo[1]);
                    index--;

                    //set the normal
                    n = (Vector3)m_alNormals[index];
                }

                cvVert = aryVerts[aryIndices[i]];

                cvVert.Position = v;

                cvVert.Normal = n;

                cvVert.Tu = t.X;
                cvVert.Tv = t.Y;

                aryVerts[aryIndices[i]] = cvVert;

            }//end for loop

            m_d3dMesh.VertexBuffer.SetData(aryVerts,0, LockFlags.None);
            m_d3dMesh.IndexBuffer.SetData(aryIndices,0,LockFlags.None);

            AttributeRange ar = new AttributeRange();
            ar.AttributeId = 0;
            ar.FaceCount = m_intNumFaces;
            ar.FaceStart = 0;
            ar.VertexCount = m_intNumVerts;
            ar.VertexStart = 0;

            m_d3dMesh.SetAttributeTable(new AttributeRange[] {ar});

            int[] adj = new int[m_intNumFaces * 3];
            m_d3dMesh.GenerateAdjacency(0.01f, adj);
            m_d3dMesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache | MeshFlags.OptimizeIgnoreVerts, adj);
            m_d3dMesh.ComputeNormals();

            m_bLoaded = true;
        }
开发者ID:NeuroRoboticTech,项目名称:AnimatLabVersion1,代码行数:98,代码来源:OBJLoader.cs


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