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


C# Mesh.SetVertexBufferData方法代码示例

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


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

示例1: CreateGroundPlane

        public void CreateGroundPlane(float minValue, float size, float uvScale)
        {
            VertexElement[] vElements = new VertexElement[]
            {
               new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
               new VertexElement(0, 12, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                new VertexElement(0, 20, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
               new VertexElement(0, 32, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
               VertexElement.VertexDeclarationEnd
            };

            model = new Mesh(2, 4, MeshFlags.Managed | MeshFlags.Use32Bit, vElements, device);

            Vertex[] vertexList = new Vertex[4];

            // Initialize the values for the 4 vertexes.
            vertexList[0].Position = new Vector3(-size, minValue, -size);
            vertexList[0].Normal = new Vector3(0, 1.0f, 0);
            vertexList[0].TexCoord = new Vector2(0, 0);

            vertexList[1].Position = new Vector3(-size, minValue, size);
            vertexList[1].Normal = new Vector3(0, 1.0f, 0);
            vertexList[1].TexCoord = new Vector2(0, uvScale);

            vertexList[2].Position = new Vector3(size, minValue, -size);
            vertexList[2].Normal = new Vector3(0, 1.0f, 0);
            vertexList[2].TexCoord = new Vector2(uvScale, 0);

            vertexList[3].Position = new Vector3(size, minValue, size);
            vertexList[3].Normal = new Vector3(0, 1.0f, 0);
            vertexList[3].TexCoord = new Vector2(uvScale, uvScale);

            int[] indexList = { 0, 3, 2, 1, 3, 0 };

            model.SetIndexBufferData(indexList, LockFlags.None);
            model.SetVertexBufferData(vertexList, LockFlags.None);

            TangentBuilder.CalculateTangents(model);
        }
开发者ID:TheKeg,项目名称:Polyviewer,代码行数:39,代码来源:GroundPlane.cs

示例2: 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

示例3: buildMesh

        /// <summary>
        /// Copies over the vertex and index buffers and calls the function within
        /// the model class to build a Mesh class.
        /// </summary>
        private void buildMesh()
        {
            VertexElement[] vElements = new VertexElement[]
            {
               new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
               new VertexElement(0, 12, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                new VertexElement(0, 20, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
               new VertexElement(0, 32, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
               VertexElement.VertexDeclarationEnd
            };

            // Creates a new mesh
            try
            {
                mesh = new Mesh(faceList.Count, vertexInfo.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vElements, device);

                mesh.SetVertexBufferData(vertexInfo.ToArray(), LockFlags.None);
                mesh.SetIndexBufferData(faceList.ToArray(), LockFlags.None);
            }
            catch(DirectXException)
            {
                MessageBox.Show("A problem occured with the model", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                faceList.Clear();
                vertexInfo.Clear();
                vertexList.Clear();
                mesh = new Mesh(1, 1, MeshFlags.Managed, vElements, device);
                return;
            }

            // Try loop to generate normals (if needed), tangents and binormals.
            try
            {
                // Generates a list of adjacent faces used for generating normals.
                int[] adjacency = new int[mesh.NumberFaces * 3];
                mesh.GenerateAdjacency(0, adjacency);

                if(!hasNormals)
                    mesh.ComputeNormals(adjacency);

                TangentBuilder.CalculateTangents(mesh);
            }
            catch (DirectXException dxe)
            {
                Console.WriteLine(dxe);
            }
        }
开发者ID:TheKeg,项目名称:Polyviewer,代码行数:50,代码来源:ObjectLoader.cs

示例4: mergeTwoMeshes

        /// <summary>
        /// Une dos meshes en uno solo.
        /// Crea un nuevo mesh con un merge de los dos. Toma el nombre, layer, userProperties, etc del primer mesh.
        /// No se hace dispose de los dos meshes originales.
        /// Ambos mesh tienen que ser del mismo RenderType.
        /// No se puede hacer merge de un mesh con Lightmap
        /// </summary>
        /// <param name="mesh1">Primer mesh</param>
        /// <param name="mesh2">Segundo mesh</param>
        /// <returns>Nueve mesh con el merge de los dos</returns>
        public TgcMesh mergeTwoMeshes(TgcMesh mesh1, TgcMesh mesh2)
        {
            //Chequear que sea mismo tipo de malla
            if (mesh1.RenderType != mesh2.RenderType)
            {
                throw new Exception("Se intentó juntar dos Mallas de formato distintos: " + mesh1.Name + " y " + mesh2.Name);
            }

            //Por ahora no se pueden unificar LightMaps
            if (mesh1.RenderType == TgcMesh.MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP)
            {
                throw new Exception("Actualmente no esta soportado juntar dos Mallas que tienen LightMaps: " + mesh1.Name + " y " + mesh2.Name);
            }

            //Crear Mesh de D3D
            int triCount = mesh1.NumberTriangles + mesh2.NumberTriangles;
            int vertexCount = mesh1.NumberVertices + mesh2.NumberVertices;
            VertexElement[] vertexElements = mesh1.RenderType == TgcMesh.MeshRenderType.VERTEX_COLOR ? TgcSceneLoader.VertexColorVertexElements : TgcSceneLoader.DiffuseMapVertexElements;
            Mesh mesh = new Mesh(triCount, vertexCount, MeshFlags.Managed, vertexElements, GuiController.Instance.D3dDevice);

            //VertexColor
            if (mesh1.RenderType == TgcMesh.MeshRenderType.VERTEX_COLOR)
            {
                //Cargar VertexBuffer
                TgcSceneLoader.VertexColorVertex[] vertsData = new TgcSceneLoader.VertexColorVertex[vertexCount];
                //Agregar los datos del mesh1
                TgcSceneLoader.VertexColorVertex[] verts1 = (TgcSceneLoader.VertexColorVertex[])mesh1.D3dMesh.LockVertexBuffer(
                    typeof(TgcSceneLoader.VertexColorVertex), LockFlags.ReadOnly, mesh1.D3dMesh.NumberVertices);
                for (int i = 0; i < verts1.Length; i++)
                {
                    verts1[i].Position = TgcVectorUtils.transform(verts1[i].Position, mesh1.Transform);
                }
                Array.Copy(verts1, vertsData, verts1.Length);
                mesh1.D3dMesh.UnlockVertexBuffer();
                verts1 = null;

                //Agregar los datos del mesh1
                TgcSceneLoader.VertexColorVertex[] verts2 = (TgcSceneLoader.VertexColorVertex[])mesh2.D3dMesh.LockVertexBuffer(
                    typeof(TgcSceneLoader.VertexColorVertex), LockFlags.ReadOnly, mesh2.D3dMesh.NumberVertices);
                for (int i = 0; i < verts2.Length; i++)
                {
                    verts2[i].Position = TgcVectorUtils.transform(verts2[i].Position, mesh2.Transform);
                }
                Array.Copy(verts2, 0, vertsData, mesh1.NumberVertices, verts2.Length);
                mesh2.D3dMesh.UnlockVertexBuffer();
                verts2 = null;

                mesh.SetVertexBufferData(vertsData, LockFlags.None);
            }
            //DiffuseMap
            else if (mesh1.RenderType == TgcMesh.MeshRenderType.DIFFUSE_MAP)
            {
                //Cargar VertexBuffer
                TgcSceneLoader.DiffuseMapVertex[] vertsData = new TgcSceneLoader.DiffuseMapVertex[vertexCount];

                //Agregar los datos del mesh1 (aplicarle la transformacion actual)
                TgcSceneLoader.DiffuseMapVertex[] verts1 = (TgcSceneLoader.DiffuseMapVertex[])mesh1.D3dMesh.LockVertexBuffer(
                    typeof(TgcSceneLoader.DiffuseMapVertex), LockFlags.ReadOnly, mesh1.D3dMesh.NumberVertices);
                for (int i = 0; i < verts1.Length; i++)
                {
                    verts1[i].Position = TgcVectorUtils.transform(verts1[i].Position, mesh1.Transform);
                }
                Array.Copy(verts1, vertsData, verts1.Length);
                mesh1.D3dMesh.UnlockVertexBuffer();
                verts1 = null;

                //Agregar los datos del mesh1
                TgcSceneLoader.DiffuseMapVertex[] verts2 = (TgcSceneLoader.DiffuseMapVertex[])mesh2.D3dMesh.LockVertexBuffer(
                    typeof(TgcSceneLoader.DiffuseMapVertex), LockFlags.ReadOnly, mesh2.D3dMesh.NumberVertices);
                for (int i = 0; i < verts2.Length; i++)
                {
                    verts2[i].Position = TgcVectorUtils.transform(verts2[i].Position, mesh2.Transform);
                }
                Array.Copy(verts2, 0, vertsData, mesh1.NumberVertices, verts2.Length);
                mesh2.D3dMesh.UnlockVertexBuffer();
                verts2 = null;

                mesh.SetVertexBufferData(vertsData, LockFlags.None);
            }

            //Cargar indexBuffer en forma plana
            using (IndexBuffer ib = mesh.IndexBuffer)
            {
                short[] indices = new short[vertexCount];
                for (int i = 0; i < indices.Length; i++)
                {
                    indices[i] = (short)i;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }
//.........这里部分代码省略.........
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:101,代码来源:TgcSceneExporter.cs

示例5: RebuildMesh

        public void RebuildMesh(Device device)
        {
            List<CustomVertex.PositionColored> vertList = new List<CustomVertex.PositionColored>();
            List<UInt16> faceIndexList = new List<UInt16>();

            Vector3 up = new Vector3(0, 1, 0);

            #region Segment vert/face creation
            UInt16 highestFaceIndex = 0;

            for (int i = 0; i < splineData.Path.Count - 1; i++) // don't process the last knot
            {
                Vector3 thisKnot = new Vector3(splineData.Path[i].Position.X, splineData.Path[i].Position.Y, splineData.Path[i].Position.Z);
                Vector3 nextKnot = new Vector3(splineData.Path[i + 1].Position.X, splineData.Path[i + 1].Position.Y, splineData.Path[i + 1].Position.Z);

                Vector3 directionToNextKnot = Vector3.Normalize(nextKnot - thisKnot);
                Vector3 perpendicularDirection = Vector3.Cross(directionToNextKnot, up);

                // verts for knot 1
                CustomVertex.PositionColored vert1_1; // top vert 1 (0)
                CustomVertex.PositionColored vert1_2; // top vert 2 (1)
                CustomVertex.PositionColored vert1_3; // bottom vert 1 (2)
                CustomVertex.PositionColored vert1_4; // bottom vert 2 (3)

                // verts for knot 2
                CustomVertex.PositionColored vert2_1; // top vert 1 (4)
                CustomVertex.PositionColored vert2_2; // top vert 2 (5)
                CustomVertex.PositionColored vert2_3; // bottom vert 1 (6)
                CustomVertex.PositionColored vert2_4; // bottom vert 2 (7)

                // move top verts
                vert1_1 = new CustomVertex.PositionColored((thisKnot + (perpendicularDirection * splineMeshRadius)), Color.White.ToArgb());
                vert1_2 = new CustomVertex.PositionColored((thisKnot + (perpendicularDirection * (splineMeshRadius * -1))), Color.White.ToArgb());

                vert2_1 = new CustomVertex.PositionColored((nextKnot + (perpendicularDirection * splineMeshRadius)), Color.White.ToArgb());
                vert2_2 = new CustomVertex.PositionColored((nextKnot + (perpendicularDirection * (splineMeshRadius * -1))), Color.White.ToArgb());

                // move bottom verts
                vert1_3 = new CustomVertex.PositionColored(vert1_1.Position - (up * splineMeshRadius), Color.White.ToArgb());
                vert1_4 = new CustomVertex.PositionColored(vert1_2.Position - (up * splineMeshRadius), Color.White.ToArgb());

                vert2_3 = new CustomVertex.PositionColored(vert2_1.Position - (up * splineMeshRadius), Color.White.ToArgb());
                vert2_4 = new CustomVertex.PositionColored(vert2_2.Position - (up * splineMeshRadius), Color.White.ToArgb());

                List<UInt16> thisKnotFaceIndexes = new List<UInt16>
                {
                    // far side
                    4,0,6,
                    6,2,0,

                    // bottom
                    6,2,3,
                    3,7,6,

                    // our side
                    7,3,1,
                    7,5,1,

                    // top
                    1,5,4,
                    4,0,1
                };

                for (int faceIndx = 0; faceIndx < thisKnotFaceIndexes.Count(); faceIndx++)
                {
                    thisKnotFaceIndexes[faceIndx] += (UInt16)vertList.Count(); // this is the wrong approach because it's the verts we're indexing, not the faces!
                    if (thisKnotFaceIndexes[faceIndx] > highestFaceIndex) highestFaceIndex = thisKnotFaceIndexes[faceIndx];
                }

                // add verts to vert list and faces to face list
                vertList.Add(vert1_1);
                vertList.Add(vert1_2);
                vertList.Add(vert1_3);
                vertList.Add(vert1_4);
                vertList.Add(vert2_1);
                vertList.Add(vert2_2);
                vertList.Add(vert2_3);
                vertList.Add(vert2_4);

                faceIndexList.AddRange(thisKnotFaceIndexes);
            }
            #endregion

            vertices = vertList.ToArray();
            faceIndeces = faceIndexList.ToArray();

            // build bounding sphere
            Vector3 center;
            float radius = Geometry.ComputeBoundingSphere(vertices, CustomVertex.PositionColored.Format, out center);
            bounds = new BoundingSphere(center.ToVertex(), radius);

            // build actual mesh from face index array and vbuf
            mesh = new Mesh(faceIndexList.Count() / 3, vertList.Count(), MeshFlags.Managed, CustomVertex.PositionColored.Format, device);

            // Apply the buffers
            mesh.SetVertexBufferData(vertices, LockFlags.None);
            mesh.IndexBuffer.SetData(faceIndeces, 0, LockFlags.None);

            // create a vertexHandle
            if (vertexHandleMesh == null) vertexHandleMesh = Mesh.Box(device, 1, 1, 1);
//.........这里部分代码省略.........
开发者ID:Radfordhound,项目名称:sa_tools,代码行数:101,代码来源:SplineData.cs

示例6: updateMesh

        /// <summary>
        /// Actualizar vertexBuffer de mesh original en base a la estructura interna del editablePoly
        /// </summary>
        private void updateMesh()
        {
            //Cambio la estructura interna del mesh, crear uno nuevo
            if (recreateMesh)
            {
                //Crear nuevo mesh con una cantidad distinta de triangulos y vertices
                Mesh newD3dMesh = null;
                int triCount = indexBuffer.Length / 3;
                int vertCount = indexBuffer.Length;
                int w = 0;
                int delTriIdx = 0;
                switch (mesh.RenderType)
                {
                    case TgcMesh.MeshRenderType.VERTEX_COLOR:
                        newD3dMesh = new Mesh(triCount, vertCount, MeshFlags.Managed, TgcSceneLoader.VertexColorVertexElements, GuiController.Instance.D3dDevice);
                        TgcSceneLoader.VertexColorVertex[] origVert1 = (TgcSceneLoader.VertexColorVertex[])mesh.D3dMesh.LockVertexBuffer(
                            typeof(TgcSceneLoader.VertexColorVertex), LockFlags.ReadOnly, mesh.D3dMesh.NumberVertices);
                        mesh.D3dMesh.UnlockVertexBuffer();
                        TgcSceneLoader.VertexColorVertex[] newVert1 = (TgcSceneLoader.VertexColorVertex[])newD3dMesh.LockVertexBuffer(
                            typeof(TgcSceneLoader.VertexColorVertex), LockFlags.None, newD3dMesh.NumberVertices);
                        for (int i = 0; i < origVert1.Length; i += 3)
                        {
                            if (delTriIdx < deletedTriangles.Count && i == deletedTriangles[delTriIdx])
                            {
                                delTriIdx++;
                            }
                            else
                            {
                                newVert1[w++] = origVert1[i];
                                newVert1[w++] = origVert1[i + 1];
                                newVert1[w++] = origVert1[i + 2];
                            }
                        }
                        mesh.D3dMesh.UnlockVertexBuffer();
                        newD3dMesh.SetVertexBufferData(newVert1, LockFlags.None);
                        newD3dMesh.UnlockVertexBuffer();
                        break;
                    case TgcMesh.MeshRenderType.DIFFUSE_MAP:
                        newD3dMesh = new Mesh(triCount, vertCount, MeshFlags.Managed, TgcSceneLoader.DiffuseMapVertexElements, GuiController.Instance.D3dDevice);
                        TgcSceneLoader.DiffuseMapVertex[] origVert2 = (TgcSceneLoader.DiffuseMapVertex[])mesh.D3dMesh.LockVertexBuffer(
                            typeof(TgcSceneLoader.DiffuseMapVertex), LockFlags.ReadOnly, mesh.D3dMesh.NumberVertices);
                        mesh.D3dMesh.UnlockVertexBuffer();
                        TgcSceneLoader.DiffuseMapVertex[] newVert2 = (TgcSceneLoader.DiffuseMapVertex[])newD3dMesh.LockVertexBuffer(
                            typeof(TgcSceneLoader.DiffuseMapVertex), LockFlags.None, newD3dMesh.NumberVertices);
                        for (int i = 0; i < origVert2.Length; i += 3)
                        {
                            if (delTriIdx < deletedTriangles.Count && i == deletedTriangles[delTriIdx])
                            {
                                delTriIdx++;
                            }
                            else
                            {
                                newVert2[w++] = origVert2[i];
                                newVert2[w++] = origVert2[i + 1];
                                newVert2[w++] = origVert2[i + 2];
                            }
                        }
                        newD3dMesh.SetVertexBufferData(newVert2, LockFlags.None);
                        newD3dMesh.UnlockVertexBuffer();
                        break;
                    case TgcMesh.MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP:
                        newD3dMesh = new Mesh(triCount, vertCount, MeshFlags.Managed, TgcSceneLoader.DiffuseMapAndLightmapVertexElements, GuiController.Instance.D3dDevice);
                        TgcSceneLoader.DiffuseMapAndLightmapVertex[] origVert3 = (TgcSceneLoader.DiffuseMapAndLightmapVertex[])mesh.D3dMesh.LockVertexBuffer(
                            typeof(TgcSceneLoader.DiffuseMapAndLightmapVertex), LockFlags.ReadOnly, mesh.D3dMesh.NumberVertices);
                        mesh.D3dMesh.UnlockVertexBuffer();
                        TgcSceneLoader.DiffuseMapAndLightmapVertex[] newVert3 = (TgcSceneLoader.DiffuseMapAndLightmapVertex[])newD3dMesh.LockVertexBuffer(
                            typeof(TgcSceneLoader.DiffuseMapAndLightmapVertex), LockFlags.None, newD3dMesh.NumberVertices);
                        for (int i = 0; i < origVert3.Length; i += 3)
                        {
                            if (delTriIdx < deletedTriangles.Count && i == deletedTriangles[delTriIdx])
                            {
                                delTriIdx++;
                            }
                            else
                            {
                                newVert3[w++] = origVert3[i];
                                newVert3[w++] = origVert3[i + 1];
                                newVert3[w++] = origVert3[i + 2];
                            }
                        }
                        mesh.D3dMesh.UnlockVertexBuffer();
                        newD3dMesh.SetVertexBufferData(newVert3, LockFlags.None);
                        newD3dMesh.UnlockVertexBuffer();
                        break;
                }
                //Cambiar mesh
                mesh.changeD3dMesh(newD3dMesh);
                deletedTriangles.Clear();
            }

            //Aplicar movimiento de vertices
            for (int i = 0; i < vertices.Count; i++)
            {
                vertices[i].position += vertices[i].movement;
                vertices[i].movement = new Vector3(0, 0, 0);
            }

//.........这里部分代码省略.........
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:101,代码来源:EditablePoly.cs

示例7: CalculateTangents


//.........这里部分代码省略.........
            for (int i = 0; i < model.NumberVertices; i++)
            {
                final.Add((Vertex)vb.Read(typeof(Vertex)));
                tan1.Add(new Vector3());
                tan2.Add(new Vector3());
            }

            // Various variables used in the calculation.
            int i1, i2, i3;
            Vector3 v1, v2, v3;
            Vector2 w1, w2, w3;

            float x1, x2, y1, y2, z1, z2;
            float s1, s2, t1, t2, r;

            // Loop through and calculate the tangent information.
            for (int i = 0; i < model.NumberFaces; i++)
            {
                i1 = (int)ib.Read(typeof(int));
                i2 = (int)ib.Read(typeof(int));
                i3 = (int)ib.Read(typeof(int));

                // Get the vertex values for the 3 vertices of a face.
                Vertex vertex1 = final[i1];
                Vertex vertex2 = final[i2];
                Vertex vertex3 = final[i3];

                // Get the positions.
                v1 = vertex1.Position;
                v2 = vertex2.Position;
                v3 = vertex3.Position;

                // Get the texture coordinates.
                w1 = vertex1.TexCoord;
                w2 = vertex2.TexCoord;
                w3 = vertex3.TexCoord;

                x1 = v2.X - v1.X;
                x2 = v3.X - v1.X;
                y1 = v2.Y - v1.Y;
                y2 = v3.Y - v1.Y;
                z1 = v2.Z - v1.Z;
                z2 = v3.Z - v1.Z;

                s1 = w2.X - w1.X;
                s2 = w3.X - w1.X;
                t1 = w2.Y - w1.Y;
                t2 = w3.Y - w1.Y;

                r = 1.0F / (s1 * t2 - s2 * t1);

                // Calculate the direction of the vector
                Vector3 sdir = new Vector3((t2 * x1 - t1 * x2) * r,
                                                    (t2 * y1 - t1 * y2) * r,
                                                    (t2 * z1 - t1 * z2) * r);
                // Calculate the direction of the uv
                Vector3 tdir = new Vector3((s1 * x2 - s2 * x1) * r,
                                                    (s1 * y2 - s2 * y1) * r,
                                                    (s1 * z2 - s2 * z1) * r);

                Vector3 temp1 = tan1[i1];
                Vector3 temp2 = tan1[i2];
                Vector3 temp3 = tan1[i3];
                Vector3 temp4 = tan2[i1];
                Vector3 temp5 = tan2[i2];
                Vector3 temp6 = tan2[i3];

                tan1[i1] = temp1 + sdir;
                tan1[i2] = temp2 + sdir;
                tan1[i3] = temp3 + sdir;

                tan2[i1] = temp4 + tdir;
                tan2[i2] = temp5 + tdir;
                tan2[i3] = temp6 + tdir;
            }

            for (int i = 0; i < model.NumberVertices; i++)
            {
                Vertex tempVertex = final[i];

                Vector3 n = tempVertex.Normal;
                Vector3 t = tan1[i];

                Vector3 temp = (t - n * Vector3.Dot(n, t));
                temp.Normalize();

                // Gram-Schmidt orthogonalize
                tempVertex.Tangent = new Vector4(temp.X, temp.Y, temp.Z, 1.0f);

                // Calculate the handedness
                tempVertex.Tangent.W = (Vector3.Dot(Vector3.Cross(n, t), tan2[i]) < 0.0F) ? -1.0F : 1.0F;

                final[i] = tempVertex;
            }

            ib.Close();
            vb.Close();

            model.SetVertexBufferData(final.ToArray(), LockFlags.None);
        }
开发者ID:TheKeg,项目名称:Polyviewer,代码行数:101,代码来源:TangentBuilder.cs

示例8: createMovementGizmo


//.........这里部分代码省略.........
            vertices[2 * eachVLength + 0].Position = new Vector3(0f, 0f, 13f);
            vertices[2 * eachVLength + 1].Position = new Vector3(0f, 1.0f, 10f);
            vertices[2 * eachVLength + 2].Position = new Vector3(0.7f, 0.7f, 10f);
            vertices[2 * eachVLength + 3].Position = new Vector3(1.0f, 0.0f, 10f);
            vertices[2 * eachVLength + 4].Position = new Vector3(0.7f, -0.7f, 10f);
            vertices[2 * eachVLength + 5].Position = new Vector3(0f, -1.0f, 10f);
            vertices[2 * eachVLength + 6].Position = new Vector3(-0.7f, -0.7f, 10f);
            vertices[2 * eachVLength + 7].Position = new Vector3(-1.0f, 0.0f, 10f);
            vertices[2 * eachVLength + 8].Position = new Vector3(-0.7f, 0.7f, 10f);

            // Z Top Shaft (Not Visible)
            vertices[2 * eachVLength + 9].Position = new Vector3(-0.25f, 0.25f, 5f);
            vertices[2 * eachVLength + 10].Position = new Vector3(0.25f, 0.25f, 5f);
            vertices[2 * eachVLength + 11].Position = new Vector3(0.25f, -0.25f, 5f);
            vertices[2 * eachVLength + 12].Position = new Vector3(-0.25f, -0.25f, 5f);
            vertices[2 * eachVLength + 13].Position = new Vector3(-0.25f, 0.25f, 10f);
            vertices[2 * eachVLength + 14].Position = new Vector3(0.25f, 0.25f, 10f);
            vertices[2 * eachVLength + 15].Position = new Vector3(0.25f, -0.25f, 10f);
            vertices[2 * eachVLength + 16].Position = new Vector3(-0.25f, -0.25f, 10f);

            // X Bottom Square Basic
            /*// Debugging only. These are NOT visible!
            for (int i = 0; i < 7; i++)
                vertices[3 * eachVLength + i].Color = Color.Yellow.ToArgb();
            */
            vertices[3 * eachVLength + 0].Position = new Vector3(0f, 0f, 0f);
            vertices[3 * eachVLength + 1].Position = new Vector3(5f, 0f, 0f);
            vertices[3 * eachVLength + 2].Position = new Vector3(0f, 5f, 0f);
            vertices[3 * eachVLength + 3].Position = new Vector3(0f, 0f, 5f);
            vertices[3 * eachVLength + 4].Position = new Vector3(5f, 5f, 0f);
            vertices[3 * eachVLength + 5].Position = new Vector3(5f, 0f, 5f);
            vertices[3 * eachVLength + 6].Position = new Vector3(0f, 5f, 5f);

            m.SetVertexBufferData(vertices, LockFlags.None);

            #region Indices Declaration

            short[] indices = new short[eachILength * 6 + 18];
            for (int i = 0; i < 3; i++)
            {
                // Cone
                indices[i * eachILength + 0] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 1] = (short)(i * eachVLength + 1);
                indices[i * eachILength + 2] = (short)(i * eachVLength + 2);

                indices[i * eachILength + 3] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 4] = (short)(i * eachVLength + 2);
                indices[i * eachILength + 5] = (short)(i * eachVLength + 3);

                indices[i * eachILength + 6] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 7] = (short)(i * eachVLength + 3);
                indices[i * eachILength + 8] = (short)(i * eachVLength + 4);

                indices[i * eachILength + 9] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 10] = (short)(i * eachVLength + 4);
                indices[i * eachILength + 11] = (short)(i * eachVLength + 5);

                indices[i * eachILength + 12] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 13] = (short)(i * eachVLength + 5);
                indices[i * eachILength + 14] = (short)(i * eachVLength + 6);

                indices[i * eachILength + 15] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 16] = (short)(i * eachVLength + 6);
                indices[i * eachILength + 17] = (short)(i * eachVLength + 7);

                indices[i * eachILength + 18] = (short)(i * eachVLength + 0);
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:67,代码来源:Gizmo.cs

示例9: 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

示例10: Init

        public static void Init(Device device, Bitmap unknownBitmap)
        {
            SquareMesh = new Mesh(2, 6, MeshFlags.Managed, CustomVertex.PositionTextured.Format, device);
            List<short> ib = new List<short>();
            for (int i = 0; i < SquareVerts.Length; i++)
                ib.Add((short)(i));
            SquareMesh.SetVertexBufferData(SquareVerts, LockFlags.None);
            SquareMesh.SetIndexBufferData(ib.ToArray(), LockFlags.None);

            QuestionMark = unknownBitmap != null ? new Texture(device, unknownBitmap, Usage.None, Pool.Managed) : new Texture(device, 16, 16, 0, Usage.None, Format.A16B16G16R16, Pool.Managed);
        }
开发者ID:Radfordhound,项目名称:sa_tools,代码行数:11,代码来源:ObjectHelper.cs


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