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


C# Mesh.LockVertexBuffer方法代码示例

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


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

示例1: CreateMesh

        protected override BulletMesh CreateMesh(Device device)
        {
            int totalTriangles = this.indices.Length /3;
            int totalVerts = this.vertices.Length;

            Mesh m = new Mesh(device, totalTriangles, totalVerts, MeshFlags.Use32Bit | MeshFlags.SystemMemory, VertexFormat.Position | VertexFormat.Normal);
            SlimDX.DataStream data = m.LockVertexBuffer(LockFlags.None);
            for (int i = 0; i < this.vertices.Length; i++)
            {
                    data.Write(this.vertices[i].X);
                    data.Write(this.vertices[i].Y);
                    data.Write(this.vertices[i].Z);

                    data.Write(0.0f);
                    data.Write(0.0f);
                    data.Write(0.0f);

                    //data.Write(this.texcoords[i]);

            }
            m.UnlockVertexBuffer();

            data = m.LockIndexBuffer(LockFlags.None);
            for (int i = 0; i < this.indices.Length; i++)
            {
                data.Write(this.indices[i]);
            }
            m.UnlockIndexBuffer();
            m.ComputeNormals();
            return null;// new BulletMesh(m);
        }
开发者ID:sunep,项目名称:dx11-vvvv,代码行数:31,代码来源:ConvexHullShapeDefinition.cs

示例2: render

        public override void render(float elapsedTime)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            time += elapsedTime;
            if (time > 1f)
            {
                Mesh d3dMesh = new Mesh(boxMesh.NumberTriangles, boxMesh.NumberVertices, MeshFlags.Managed, TgcSceneLoader.VertexColorVertexElements, d3dDevice);

                TgcSceneLoader.VertexColorVertex[] origVert = (TgcSceneLoader.VertexColorVertex[])boxMesh.D3dMesh.LockVertexBuffer(
                            typeof(TgcSceneLoader.VertexColorVertex), LockFlags.ReadOnly, boxMesh.D3dMesh.NumberVertices);

                boxMesh.D3dMesh.UnlockVertexBuffer();

                TgcSceneLoader.VertexColorVertex[] newVert = (TgcSceneLoader.VertexColorVertex[])d3dMesh.LockVertexBuffer(
                            typeof(TgcSceneLoader.VertexColorVertex), LockFlags.None, d3dMesh.NumberVertices);

                for (int i = 0; i < origVert.Length; i++)
                {
                    newVert[i] = origVert[i];
                }

                //d3dMesh.SetVertexBufferData(newVert, LockFlags.None);
                d3dMesh.UnlockVertexBuffer();

                boxMesh.changeD3dMesh(d3dMesh);

                time = 0;
            }

            boxMesh.render();
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:32,代码来源:EjemploDisposeMesh3.cs

示例3: Terrain

        /// <summary>
        /// Constructor for randomly generating terrian
        /// </summary>
        public Terrain()
        {
            //FileStream fs = new FileStream("heightdata.raw", FileMode.Open, FileAccess.Read);
            //BinaryReader r = new BinaryReader(fs);
            rand = new Random();

            width = rand.Next(2, 100);//64;//rand.Next(2, 50);
            tall = rand.Next(2, 100);//64;//rand.Next(2, 50);
            world = Matrix.Identity;

            Height = new int[width, tall];

            var vertices = new CustomVertex.VertexPositionColor[width * tall];
            var indicies = new short[(width - 1) * (tall - 1) * 3];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < tall; j++)
                {
                    //height[width - 1 - j, tall - 1 - i] = (int)(r.ReadByte() / 50);
                    Height[i, j] = rand.Next(0, 3);
                }
            }

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < tall; j++)
                {
                    vertices[i + j * width].Position = new Vector3(i, Height[i, j], j);
                    vertices[i + j * width].Color = Color.White.ToArgb();
                }
            }

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 0; j < tall - 1; j++)
                {
                    indicies[(i + j * (width - 1)) * 3] = (short)((i + 1) + (j + 1) * width);
                    indicies[(i + j * (width - 1)) * 3 + 1] = (short)((i + 1) + j * width);
                    indicies[(i + j * (width - 1)) * 3 + 2] = (short)(i + j * width);
                }
            }

            mesh = new Mesh(DeviceManager.LocalDevice, indicies.Length, vertices.Length,
                MeshFlags.Managed, CustomVertex.VertexPositionColor.Format);

            mesh.LockVertexBuffer(LockFlags.Discard).WriteRange<CustomVertex.VertexPositionColor>(vertices);
            mesh.UnlockVertexBuffer();

            mesh.LockIndexBuffer(LockFlags.Discard).WriteRange<short>(indicies);
            mesh.UnlockIndexBuffer();

            mesh.Optimize(MeshOptimizeFlags.AttributeSort | MeshOptimizeFlags.Compact);

            //r.Dispose();
            //fs.Dispose();
        }
开发者ID:senbeiwabaka,项目名称:Computer-Graphics-Project,代码行数:60,代码来源:Terrain.cs

示例4: CreateShape

        Mesh CreateShape(CollisionShape shape)
        {
            uint[] indices;
            BulletSharp.Math.Vector3[] vertices = CreateShape(shape, out indices);

            int vertexCount = vertices.Length / 2;
            int indexCount = (indices != null) ? indices.Length : vertexCount;
            bool index32 = indexCount > 65536;

            Mesh mesh = new Mesh(device, indexCount / 3, vertexCount,
                MeshFlags.SystemMemory | (index32 ? MeshFlags.Use32Bit : 0), VertexFormat.Position | VertexFormat.Normal);

            DataStream vertexBuffer = mesh.LockVertexBuffer(LockFlags.Discard);
            vertexBuffer.WriteRange(vertices);
            mesh.UnlockVertexBuffer();

            DataStream indexBuffer = mesh.LockIndexBuffer(LockFlags.Discard);
            if (index32)
            {
                if (indices == null)
                {
                    indices = new uint[indexCount];
                    uint i = 0;
                    while (i < indexCount)
                    {
                        indices[i] = i;
                        i++;
                    }
                }
                indexBuffer.WriteRange(indices);
            }
            else
            {
                ushort[] indices_s;
                if (indices == null)
                {
                    indices_s = new ushort[indexCount];
                    ushort i = 0;
                    while (i < indexCount)
                    {
                        indices_s[i] = i;
                        i++;
                    }
                }
                else
                {
                    indices_s = CompactIndexBuffer(indices);
                }
                indexBuffer.WriteRange(indices_s);
            }
            mesh.UnlockIndexBuffer();

            shapes.Add(shape, mesh);
            return mesh;
        }
开发者ID:rhynodegreat,项目名称:BulletSharpPInvoke,代码行数:55,代码来源:MeshFactory.cs

示例5: UpdateMesh

		//this method gets called, when Update() was called in evaluate,
		//or a graphics device asks for its mesh, here you can alter the data of the mesh
		protected override void UpdateMesh(Mesh mesh)
		{
			//do something with the mesh data
			var vertices = mesh.LockVertexBuffer(LockFlags.None);

			for (int i = 0; i < mesh.VertexCount; i++) {
				//get the vertex content
				var pos = vertices.Read<Vector3>();
				var norm = vertices.Read<Vector3>();

				pos.X = (pos.X + FRandomizeIn[i].X) % 2 - 0;
				pos.Y = (pos.Y + FRandomizeIn[i].Y) % 2 - 1;
				pos.Z = (pos.Z + FRandomizeIn[i].Z) % 2 - 0;

				//to write the data move the stream position back!
				vertices.Position -= mesh.BytesPerVertex;
				vertices.Write(pos);
				vertices.Write(norm);
			}

			mesh.UnlockVertexBuffer();
		}
开发者ID:elliotwoods,项目名称:VVVV.Nodes.KCParticles,代码行数:24,代码来源:EX9_GeometryS_HNode.cs

示例6: UpdateResource

        public void UpdateResource(IPluginOut ForPin, int OnDevice)
        {
            if (ForPin == this.FPinOutMesh)
            {

                bool update = this.FMeshes.ContainsKey(OnDevice);
                if (this.FInvalidate)
                {
                    RemoveResource(OnDevice);
                }

                if (!update)
                {
                    this.FInvalidate = true;
                }

                if (this.FInvalidate)
                {

                    Device dev = Device.FromPointer(new IntPtr(OnDevice));

                    List<Mesh> meshes = new List<Mesh>();
                    //Mesh.

                    for (int i = 0; i < this.FVertexList.Count; i++)
                    {

                        Mesh mesh = new Mesh(dev, this.FIndexList[i].Length / 3, this.FVertexList[i].Length, MeshFlags.Dynamic, VertexNormT2.Format);
                        DataStream vS = mesh.LockVertexBuffer(LockFlags.Discard);
                        DataStream iS = mesh.LockIndexBuffer(LockFlags.Discard);

                        FLogger.Log(LogType.Debug,this.FVertexList[i].Length.ToString());
                        FLogger.Log(LogType.Debug,this.FIndexList[i].Length.ToString());

                        vS.WriteRange(this.FVertexList[i]);
                        iS.WriteRange(this.FIndexList[i]);

                        mesh.UnlockVertexBuffer();
                        mesh.UnlockIndexBuffer();

                        meshes.Add(mesh);

                        FLogger.Log(LogType.Debug,meshes.Count.ToString());
                    }

                    try
                    {

                    Mesh merge = Mesh.Concatenate(dev, meshes.ToArray(), MeshFlags.Use32Bit | MeshFlags.Managed);
                    this.FMeshes.Add(OnDevice, merge);
                    //FLogger.Log(LogType.Debug,meshes.Count.ToString());
                    }
                    catch (Exception ex)
                    {
                    //FLogger.Log(LogType.Error,ex.Message);
                    }

                    foreach (Mesh m in meshes)
                    {
                        m.Dispose();
                    }

                    dev.Dispose();

                    this.FInvalidate = false;
                }
            }
        }
开发者ID:hrovac,项目名称:Addons,代码行数:68,代码来源:MeshJoin.cs

示例7: MeshClass

        /// <summary>
        /// For creating shape objects
        /// </summary>
        /// <param name="type">the name of the object you wish to create</param>
        public MeshClass(MeshType type = MeshType.Cube)
        {
            if (type == MeshType.Cube)
            {
                ObjectMesh = Mesh.CreateBox(Engine.GameEngine.LocalDevice.ThisDevice, 1f, 1f, 1f);

                ObjectMesh.ComputeNormals();

                ObjectMesh.Optimize(MeshOptimizeFlags.Compact);

                ApplyColor(Color.White);
            }
            else if (type == MeshType.Sphere)
            {
                ObjectMesh = Mesh.CreateSphere(Engine.GameEngine.LocalDevice.ThisDevice, .1f, 10, 10);

                ObjectMesh.ComputeNormals();
                ObjectMesh.Optimize(MeshOptimizeFlags.Compact);
                ApplyColor(Color.White);
            }
            else if (type == MeshType.Teapot)
            {
                ObjectMesh = Mesh.CreateTeapot(Engine.GameEngine.LocalDevice.ThisDevice);

                ObjectMesh.ComputeNormals();

                ObjectMesh.OptimizeInPlace(MeshOptimizeFlags.Compact);

                ApplyColor(Color.White);
            }
            else if (type == MeshType.Triangle)
            {
                VertexPositionColor[] ShapeVertices = new VertexPositionColor[] {
                    new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, 1f) },
                    new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, 1f) },
                    new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, -1f) },
                    new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, -1f) },
                    new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(0f, 1f, 0f) },
                };

                var ShapeIndices = new short[] {
                    0, 2, 1,    // base
                    1, 2, 3,
                    0, 1, 4,    // sides
                    1, 3, 4,
                    3, 2, 4,
                    2, 0, 4,
                };

                ObjectMesh = new Mesh(Engine.GameEngine.LocalDevice.ThisDevice, ShapeIndices.Length, ShapeVertices.Length, MeshFlags.Managed, VertexPositionColor.Format);

                ObjectMesh.LockVertexBuffer(LockFlags.None).WriteRange<VertexPositionColor>(ShapeVertices);
                ObjectMesh.UnlockVertexBuffer();

                ObjectMesh.LockIndexBuffer(LockFlags.None).WriteRange<short>(ShapeIndices);
                ObjectMesh.UnlockIndexBuffer();

                Mesh other = ObjectMesh.Clone(Engine.GameEngine.LocalDevice.ThisDevice, MeshFlags.Managed, ObjectMesh.VertexFormat | VertexFormat.Normal | VertexFormat.Texture2);
                ObjectMesh.Dispose();
                ObjectMesh = null;
                //other.ComputeNormals();
                ObjectMesh = other.Clone(Engine.GameEngine.LocalDevice.ThisDevice, MeshFlags.Managed, other.VertexFormat);
                other.Dispose();

                ObjectMesh.Optimize(MeshOptimizeFlags.Compact);

                ApplyColor(Color.White);
            }

            ObjectPosition = Vector3.Zero;
            ObjectRotate = Vector3.Zero;
            ObjectScale = new Vector3(1, 1, 1);
            _world = Matrix.Translation(ObjectPosition);
            IsShapeObject = true;
        }
开发者ID:senbeiwabaka,项目名称:MY3DEngine,代码行数:79,代码来源:MeshClass.cs

示例8: SaveMeshVertices

        public static void SaveMeshVertices(ref AnimatTools.Interfaces.StdXml oXml, string strName, Mesh myMesh, bool bSaveIndices)
        {
            CustomVertex.PositionNormalTextured[] cvVerts = new CustomVertex.PositionNormalTextured[myMesh.NumberVertices];

            oXml.AddChildElement(strName);
            oXml.IntoElem();  //Into the mesh

            GraphicsStream buffer = myMesh.LockVertexBuffer(LockFlags.ReadOnly);
            AnimatTools.Framework.Vec3d vVertex = new AnimatTools.Framework.Vec3d(null);

            for(int i=0; i<myMesh.NumberVertices; i++)
            {
                buffer.Position = i * myMesh.NumberBytesPerVertex;
                cvVerts[i] = (CustomVertex.PositionNormalTextured)buffer.Read(typeof(CustomVertex.PositionNormalTextured));
                //System.Diagnostics.Debug.WriteLine("v " + cvVerts[i].X + " " + cvVerts[i].Y + " " + cvVerts[i].Z);

                vVertex.X = cvVerts[i].X;// - this.AbsoluteLocation.X;
                vVertex.Y = cvVerts[i].Y;// - this.AbsoluteLocation.Y;
                vVertex.Z = cvVerts[i].Z;// - this.AbsoluteLocation.Z;

                Util.SaveVector(ref oXml, "Vector", vVertex);

                //Debug.WriteLine("data.Write(new CustomVertex.PositionTextured(" + vVertex.X + "f, " + vVertex.Y + "f, " + vVertex.Z + "f, 0f, 0f));");
                //if(i%3 == 0) Debug.WriteLine("");
                //Debug.WriteLine("V: " + i + "  (" + cvVerts[i].X + ", " + cvVerts[i].Y + ", " + cvVerts[i].Z + ", " + cvVerts[i].Nx + ", " + cvVerts[i].Ny + ", " + cvVerts[i].Nz + ")");
            }
            myMesh.UnlockVertexBuffer();

            if(bSaveIndices)
            {
                using (IndexBuffer ib = myMesh.IndexBuffer)
                {
                    GraphicsStream gs = ib.Lock(0, myMesh.NumberFaces*3*2, LockFlags.ReadOnly);

                    string strIndex = "";
                    short iIndex;
                    for(int i=0; i<myMesh.NumberFaces*3; i++)
                    {
                        gs.Position = i * 2;
                        iIndex = (short) gs.Read(typeof(short));

                        strIndex += iIndex.ToString();
                        if(i<gs.Length-1) strIndex += ",";
                    }

                    oXml.AddChildElement("IndexBuffer", strIndex);

                    ib.Unlock();
                }
            }

            oXml.OutOfElem();  //Out of the mesh
        }
开发者ID:NeuroRoboticTech,项目名称:AnimatLabVersion1,代码行数:53,代码来源:Util_DX.cs

示例9: fillVertexBuffer

            protected override void fillVertexBuffer(Mesh mesh)
            {
                List<KeyValuePair<byte, float>> blendData = new List<KeyValuePair<byte, float>>();
                byte[] blendIndices = new byte[MaxBlendIndexCount];
                float[] blendWeights = new float[MaxBlendIndexCount];
                byte blendIndex;
                float blendWeight, blendWeightSum;
                bool displayMaxNumInfluenceWarning = true;

                // get weight input element
                Document.Input weightInput = null;
                foreach (Document.Input input in skin.vertexWeights.inputs)
                    if (input.semantic == "WEIGHT")
                        weightInput = input;

                DataStream ds = mesh.LockVertexBuffer(LockFlags.None);
                try
                {
                    // Read out all blend weights and indices to build an offset table
                    uint[] offsets = new uint[skin.vertexWeights.count];
                    uint offset = 0;
                    for (int i = 0; i < offsets.Length; i++)
                    {
                        offsets[i] = offset;
                        offset += 2 * skin.vertexWeights.vcount[i];
                    }

                    for (int vertexIndex = 0; vertexIndex < VertexCount; vertexIndex++)
                    {
                        ds.WriteRange(VertexArray, vertexIndex * VertexStride, VertexStride);

                        int v = InvVertexMapping[vertexIndex];
                        offset = offsets[v];

                        // read in all blend indices, sort them by weight,
                        // select up to MaxBlendIndexCount and renormalize.
                        blendData.Clear();
                        for (int j = 0; j < skin.vertexWeights.vcount[v]; j++)
                        {
                            blendIndex = (byte) skin.vertexWeights.v[offset + 2 * j];
                            blendWeight = COLLADAUtil.GetSourceElement(
                                model.Doc,
                                weightInput,
                                skin.vertexWeights.v[offset + 2 * j + 1])[0];

                            // ignore blend indices with values greater than MaxSkinningMatrixCount
                            //if (blendIndex < MaxBlendIndexCount)
                            blendData.Add(new KeyValuePair<byte, float>(blendIndex, blendWeight));
                        }

                        blendData.Sort(
                            delegate(KeyValuePair<byte, float> firstPair, KeyValuePair<byte, float> secondPair)
                            {
                                return firstPair.Value.CompareTo(secondPair.Value);
                            });

                        blendWeightSum = 0;
                        for (int j = 0; j < MaxBlendIndexCount; j++)
                        {
                            if (j < blendData.Count)
                            {
                                blendIndices[j] = blendData[blendData.Count - 1 - j].Key;
                                blendWeights[j] = blendData[blendData.Count - 1 - j].Value;
                                blendWeightSum += blendData[blendData.Count - 1 - j].Value;
                            }
                            else
                            {
                                blendIndices[j] = 0;
                                blendWeights[j] = 0;
                            }
                        }

                        // There are only up to four influences allowed.
                        if (displayMaxNumInfluenceWarning && skin.vertexWeights.vcount[v] > 4)
                        {
                            COLLADAUtil.Log(COLLADALogType.Warning, "There are only up to four influences allowed. Skinning might be incorrect.");
                            displayMaxNumInfluenceWarning = false;
                        }

                        // renormalize
                        if (blendWeightSum > 0)
                        {
                            for (int j = 0; j < 4; j++)
                            {
                                blendWeights[j] = blendWeights[j] / blendWeightSum;
                            }
                        }

                        ds.WriteRange(blendIndices);
                        ds.WriteRange(blendWeights);
                    }
                }
                catch (Exception e)
                {
                    COLLADAUtil.Log(COLLADALogType.Error, e.Message + e.StackTrace);
                }
                finally
                {
                    mesh.UnlockVertexBuffer();
                }
//.........这里部分代码省略.........
开发者ID:vvvv,项目名称:ColladaSlimDX,代码行数:101,代码来源:COLLADAModel.cs

示例10: UpdateMesh

        //this method gets called, when Update() was called in evaluate,
        //or a graphics device asks for its mesh, here you can alter the data of the mesh
        void UpdateMesh(MeshData meshData, Mesh mesh)
        {
            FLogger.Log(LogType.Debug, "Updating Mesh...");
            //do something with the mesh data
            var vertices = mesh.LockVertexBuffer(LockFlags.None);

            for (int i = 0; i < mesh.VertexCount; i++)
            {
                //get the vertex content
                var pos = vertices.Read<Vector3>();
                var norm = vertices.Read<Vector3>();

                pos.X = (pos.X + meshData.Randomness.X) % 2 - 0;
                pos.Y = (pos.Y + meshData.Randomness.Y) % 2 - 1;
                pos.Z = (pos.Z + meshData.Randomness.Z) % 2 - 0;

                //to write the data move the stream position back!
                vertices.Position -= mesh.BytesPerVertex;
                vertices.Write(pos);
                vertices.Write(norm);
            }

            mesh.UnlockVertexBuffer();
        }
开发者ID:beyondtheline,项目名称:MarysGun,代码行数:26,代码来源:TemplateEX9Mesh.cs

示例11: FillVertexBuffer

        private void FillVertexBuffer(Mesh animationMesh, List<odfVertex> vertexList, float[][] vertexWeights, int selectedBoneIdx)
        {
            using (DataStream vertexStream = animationMesh.LockVertexBuffer(LockFlags.None))
            {
                Color4 col = new Color4(1f, 1f, 1f);
                for (int j = 0; j < vertexList.Count; j++)
                {
                    odfVertex vertex = vertexList[j];
            #if !DONT_MIRROR
                    Vector3 position = new Vector3(vertex.Position.X, vertex.Position.Y, -vertex.Position.Z);
                    Vector3 normal = new Vector3(vertex.Normal.X, vertex.Normal.Y, -vertex.Normal.Z);
            #else
                    Vector3 position = vertex.Position;
                    Vector3 normal = vertex.Normal;
            #endif
                    float[] boneWeights = vertexWeights[j];
                    vertexStream.Write(position.X);
                    vertexStream.Write(position.Y);
                    vertexStream.Write(position.Z);
                    vertexStream.Write(boneWeights[0]);
                    vertexStream.Write(boneWeights[1]);
                    vertexStream.Write(boneWeights[2]);
                    vertexStream.Write(vertex.BoneIndices[0]);
                    vertexStream.Write(vertex.BoneIndices[1]);
                    vertexStream.Write(vertex.BoneIndices[2]);
                    vertexStream.Write(vertex.BoneIndices[3]);
                    vertexStream.Write(normal.X);
                    vertexStream.Write(normal.Y);
                    vertexStream.Write(normal.Z);
                    if (selectedBoneIdx >= 0)
                    {
                        col.Red = 0f; col.Green = 0f; col.Blue = 0f;
                        byte[] boneIndices = vertex.BoneIndices;
                        for (int k = 0; k < boneIndices.Length; k++)
                        {
                            if (boneIndices[k] == 0xFF)
                            {
                                continue;
                            }

                            byte boneIdx = boneIndices[k];
                            if (boneIdx == selectedBoneIdx)
                            {
            /*								switch (cols)
                                {
                                case WeightsColourPreset.Greyscale:
                                    col.r = col.g = col.b = boneWeights[k];
                                    break;
                                case WeightsColourPreset.Metal:
                                    col.r = boneWeights[k] > 0.666f ? 1f : boneWeights[k] * 1.5f;
                                    col.g = boneWeights[k] * boneWeights[k] * boneWeights[k];
                                    break;
                                case WeightsColourPreset.Rainbow:*/
                                    if (boneWeights[k] > 0.75f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[k]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[k] > 0.5f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[k]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[k] > 0.25f)
                                    {
                                        col.Red = (boneWeights[k] - 0.25f) * 4f;
                                        col.Green = 1f;
                                        col.Blue = 0f;
                                    }
                                    else
                                    {
                                        col.Green = boneWeights[k] * 4f;
                                        col.Blue = 1f - boneWeights[k] * 4f;
                                    }
            /*									break;
                                }*/
                                break;
                            }
                        }
                    }
                    vertexStream.Write(col.ToArgb());
                    vertexStream.Write(vertex.UV[0]);
                    vertexStream.Write(vertex.UV[1]);
                }
                animationMesh.UnlockVertexBuffer();
            }
        }
开发者ID:hejob,项目名称:SB3Utility,代码行数:89,代码来源:RenderObjectODF.cs

示例12: CreateCylinderMesh


//.........这里部分代码省略.........
			                                                           	{
			                                                           		Position = vertexPos,
			                                                           		Texture = i < 6 ? startTextures[i] : default(Vector2),
			                                                           		Normal = i < 6 ? GetFlatNormal(vertexPos) : GetSideNormal(vertexPos, height, rtop, rbottom)
			                                                           	}));
			var indices = new List<Int16>
			              	{
			              		0, 1, 2,
			              		3, 4, 5,
			              		6, 7, 8,
			              		8, 9, 6
			              	};
			var attributes = new List<Int32> {0, 1, 2, 2};
			short prevtop = 2;
			short prevbot = 4;
			short prevtopside = 9;
			short prevbotside = 8;
			for(short i = 1; i < thetaDiv - 1; i++)
			{
				var vertcount = (short)(10 + 4 * i);
				// Top surface:
				Vector3 topPoint = topPoints[i + 1];
				vertices.Add(new CustomVertex
				             	{
				             		Position = topPoint,
				             		Texture = GetFlatTextureCoordinates(topPoint, rtop),
				             		Normal = GetFlatNormal(topPoint)
				             	});
				indices.Add(0);
				indices.Add(prevtop);
				indices.Add(vertcount);
				attributes.Add(0);
				// Bottom surface:
				Vector3 bottomPoint = bottomPoints[i + 1];
				vertices.Add(new CustomVertex
				             	{
				             		Position = bottomPoint,
				             		Texture = GetFlatTextureCoordinates(bottomPoint, rbottom),
				             		Normal = GetFlatNormal(bottomPoint)
				             	});
				indices.Add(3); //center
				indices.Add((short)(vertcount + 1)); //latest
				indices.Add(prevbot); //previous
				attributes.Add(1);
				// Side surface:
				vertices.Add(new CustomVertex
				             	{
				             		Position = bottomPoint,
				             		Normal = GetSideNormal(bottomPoint, height, rtop, rbottom)
				             	});
				vertices.Add(new CustomVertex
				             	{
				             		Position = topPoint,
				             		Normal = GetSideNormal(bottomPoint, height, rtop, rbottom)
				             	});
				indices.Add(prevtopside);
				indices.Add(prevbotside);
				indices.Add((short)(vertcount + 2));
				indices.Add((short)(vertcount + 2));
				indices.Add((short)(vertcount + 3));
				indices.Add(prevtopside);
				attributes.Add(2);
				attributes.Add(2);
				prevtop = vertcount;
				prevbot = (short)(vertcount + 1);
				prevbotside = (short)(vertcount + 2);
				prevtopside = (short)(vertcount + 3);
			}
			//top
			indices.Add(0);
			indices.Add(thetaDiv - 1);
			indices.Add(1);
			attributes.Add(0);
			indices.Add(3); //center
			indices.Add(5); //latest
			indices.Add(thetaDiv - 1);
			attributes.Add(1);
			indices.Add(prevtopside);
			indices.Add(prevbotside);
			indices.Add(7);
			indices.Add(7);
			indices.Add(6);
			indices.Add(prevtop);
			attributes.Add(2);
			attributes.Add(2);
			var mesh = new Mesh(device, indices.Count / 3, vertices.Count, MeshFlags.Managed, CustomVertex.TheVertexFormat);
			const LockFlags lockFlags = LockFlags.None;
			using(DataStream vertexStream = mesh.LockVertexBuffer(lockFlags),
			                 indexStream = mesh.LockIndexBuffer(lockFlags),
			                 attributeStream = mesh.LockAttributeBuffer(lockFlags))
			{
				vertices.ForEach(vertexStream.Write);
				indices.ForEach(indexStream.Write);
				attributes.ForEach(attributeStream.Write);
			}
			mesh.UnlockVertexBuffer();
			mesh.UnlockIndexBuffer();
			mesh.UnlockAttributeBuffer();
			return mesh;
		}
开发者ID:DmitryZyr,项目名称:CVARC,代码行数:101,代码来源:DirectXPrimitives.cs

示例13: ScaleMesh

        public static void ScaleMesh(Mesh d3dMesh, float fltX, float fltY, float fltZ)
        {
            if(fltX <= 0 || fltY <= 0 || fltZ <= 0)
                throw new System.Exception("Invalid scale value specified.");

            if(fltX == 1 && fltY == 1 && fltZ == 1)
                return;

            CustomVertex.PositionNormalTextured vVertex;
            GraphicsStream buffer = d3dMesh.LockVertexBuffer(LockFlags.None);

            for(int i=0; i<d3dMesh.NumberVertices; i++)
            {
                buffer.Position = i * d3dMesh.NumberBytesPerVertex;
                vVertex = (CustomVertex.PositionNormalTextured)buffer.Read(typeof(CustomVertex.PositionNormalTextured));

                vVertex.X *= (float) fltX;
                vVertex.Y *= (float) fltY;
                vVertex.Z *= (float) fltZ;

                buffer.Position = i * d3dMesh.NumberBytesPerVertex;
                buffer.Write(new CustomVertex.PositionNormalTextured(vVertex.X, vVertex.Y, vVertex.Z, vVertex.Nx, vVertex.Ny, vVertex.Nz, vVertex.Tu, vVertex.Tv));
            }
            d3dMesh.UnlockVertexBuffer();
        }
开发者ID:NeuroRoboticTech,项目名称:AnimatLabVersion1,代码行数:25,代码来源:Util_DX.cs

示例14: CreateTriangleMeshShape

        Mesh CreateTriangleMeshShape(TriangleMeshShape shape)
        {
            StridingMeshInterface meshInterface = shape.MeshInterface;

            BulletSharp.DataStream verts, indices;
            int numVerts, numFaces;
            PhyScalarType vertsType, indicesType;
            int vertexStride, indexStride;
            meshInterface.GetLockedReadOnlyVertexIndexData(out verts, out numVerts, out vertsType, out vertexStride,
                out indices, out indexStride, out numFaces, out indicesType);

            bool index32 = numVerts > 65536;

            Mesh mesh = new Mesh(device, numFaces, numVerts,
                 MeshFlags.SystemMemory | (index32 ? MeshFlags.Use32Bit : 0), VertexFormat.Position | VertexFormat.Normal);

            SlimDX.DataStream data = mesh.LockVertexBuffer(LockFlags.None);
            while (verts.Position < verts.Length)
            {
                Vector3 v = verts.Read<Vector3>();
                data.Write(v);

                verts.Position += vertexStride - 12;

                // Normals will be calculated later
                data.Position += 12;
            }
            mesh.UnlockVertexBuffer();

            data = mesh.LockIndexBuffer(LockFlags.None);
            while (indices.Position < indices.Length)
            {
                int index = indices.Read<int>();
                if (index32)
                    data.Write(index);
                else
                    data.Write((short)index);
            }
            mesh.UnlockVertexBuffer();

            mesh.ComputeNormals();

            shapes.Add(shape, mesh);
            return mesh;
        }
开发者ID:rhynodegreat,项目名称:BulletSharp,代码行数:45,代码来源:GraphicObjectFactory.cs

示例15: CreateStaticPlaneShape

        Mesh CreateStaticPlaneShape(StaticPlaneShape shape)
        {
            // Load shader
            if (planeShader == null)
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                Stream shaderStream = assembly.GetManifestResourceStream("DemoFramework.checker_shader.fx");

                planeShader = Effect.FromStream(device, shaderStream, ShaderFlags.None);
            }


            Vector3[] vertices = new Vector3[4 * 2];

            Mesh mesh = new Mesh(device, 2, 4, MeshFlags.SystemMemory, VertexFormat.Position | VertexFormat.Normal);

            Vector3 planeOrigin = shape.PlaneNormal * shape.PlaneConstant;
            Vector3 vec0, vec1;
            PlaneSpace1(shape.PlaneNormal, out vec0, out vec1);
            float size = 1000;

            Vector3[] verts = new Vector3[4]
                {
                    planeOrigin + vec0*size,
                    planeOrigin - vec0*size,
                    planeOrigin + vec1*size,
                    planeOrigin - vec1*size
                };

            SlimDX.DataStream vertexBuffer = mesh.LockVertexBuffer(LockFlags.Discard);
            vertexBuffer.Write(verts[0]);
            vertexBuffer.Position += 12;
            vertexBuffer.Write(verts[1]);
            vertexBuffer.Position += 12;
            vertexBuffer.Write(verts[2]);
            vertexBuffer.Position += 12;
            vertexBuffer.Write(verts[3]);
            vertexBuffer.Position += 12;
            mesh.UnlockVertexBuffer();

            SlimDX.DataStream indexBuffer = mesh.LockIndexBuffer(LockFlags.Discard);
            indexBuffer.Write((short)1);
            indexBuffer.Write((short)2);
            indexBuffer.Write((short)0);
            indexBuffer.Write((short)1);
            indexBuffer.Write((short)3);
            indexBuffer.Write((short)0);
            mesh.UnlockIndexBuffer();

            mesh.ComputeNormals();

            complexShapes.Add(shape, mesh);

            return mesh;
        }
开发者ID:rhynodegreat,项目名称:BulletSharp,代码行数:55,代码来源:GraphicObjectFactory.cs


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