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


C# Mesh.UnlockIndexBuffer方法代码示例

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


在下文中一共展示了Mesh.UnlockIndexBuffer方法的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: 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

示例3: ColoredSphere


//.........这里部分代码省略.........

            Mesh mesh = new Mesh(numFaces, numVertices, MeshFlags.Managed, CustomVertex.PositionColored.Format, device);

            // Get the original sphere's vertex buffer.
            int[] ranks = new int[1];
            ranks[0] = mesh.NumberVertices;
            System.Array arr = mesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionColored), LockFlags.None, ranks);

            // Set the vertex buffer
            int vertIndex = 0;
            CustomVertex.PositionColored pnt;
            Point3d v;

            // bottom fade
            double latitude = startLat - ((endLat - startLat) / 4);
            if (latitude < startLat - 1) latitude = startLat - 1;
            for (int slice = 0; slice <= slices; slice++)
            {
                pnt = new CustomVertex.PositionColored();
                double longitude = 180.0 - ((double)slice / slices * 360.0);
                v = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                pnt.X = (float)v.X;
                pnt.Y = (float)v.Y;
                pnt.Z = (float)v.Z;
                pnt.Color = Color.FromArgb(255, horizonColor.R, horizonColor.G, horizonColor.B).ToArgb();
                arr.SetValue(pnt, vertIndex++);
            }
            // stacks and slices
            for (int stack = 1; stack < stacks; stack++)
            {
                //latitude = startLat + ((double)(stack-1)/(stacks-1f)*(double)(endLat - startLat));
                double linear = (double)(stack - 1) / (stacks - 1f);
                double k = 1 - Math.Cos(linear * Math.PI / 2);
                latitude = startLat + (k * (endLat - startLat));
                //double colorFactorZ = (float)(stack-1)/(stacks-1f);   // coef zenith color
                double colorFactorZ = linear;                           // coef zenith color
                double colorFactorH = 1 - colorFactorZ;                 // coef horizon color
                double alphaFactor = 1 - (linear * linear * linear);    // coef alpha transparency
                if (alphaFactor > 1) alphaFactor = 1f;
                for (int slice = 0; slice <= slices; slice++)
                {
                    pnt = new CustomVertex.PositionColored();
                    double longitude = 180.0 - ((double)slice / slices * 360.0);
                    v = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                    pnt.X = (float)v.X;
                    pnt.Y = (float)v.Y;
                    pnt.Z = (float)v.Z;
                    pnt.Color = Color.FromArgb(
                              (int)(255f * alphaFactor),
                              (int)(horizonColor.R * colorFactorH + zenithColor.R * colorFactorZ),
                              (int)(horizonColor.G * colorFactorH + zenithColor.G * colorFactorZ),
                              (int)(horizonColor.B * colorFactorH + zenithColor.B * colorFactorZ)).ToArgb();
                    arr.SetValue(pnt, vertIndex++);
                }
            }
            // top fade
            latitude = endLat + ((endLat - startLat) / 10);
            for (int slice = 0; slice <= slices; slice++)
            {
                pnt = new CustomVertex.PositionColored();
                double longitude = 180 - ((double)slice / slices * 360.0);
                v = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                pnt.X = (float)v.X;
                pnt.Y = (float)v.Y;
                pnt.Z = (float)v.Z;
                pnt.Color = Color.FromArgb(0, zenithColor.R, zenithColor.G, zenithColor.B).ToArgb();
                arr.SetValue(pnt, vertIndex++);
            }

            mesh.VertexBuffer.Unlock();
            ranks[0] = indexCount;
            arr = mesh.LockIndexBuffer(typeof(short), LockFlags.None, ranks);
            int i = 0;
            short bottomVertex = 0;
            short topVertex = 0;

            // stacks and slices
            for (short x = 0; x < stacks; x++)
            {
                bottomVertex = (short)((slices + 1) * x);
                topVertex = (short)(bottomVertex + slices + 1);
                for (int y = 0; y < slices; y++)
                {
                    arr.SetValue(bottomVertex, i++);
                    arr.SetValue((short)(topVertex + 1), i++);
                    arr.SetValue(topVertex, i++);
                    arr.SetValue(bottomVertex, i++);
                    arr.SetValue((short)(bottomVertex + 1), i++);
                    arr.SetValue((short)(topVertex + 1), i++);
                    bottomVertex++;
                    topVertex++;
                }
            }

            mesh.UnlockIndexBuffer();
            mesh.IndexBuffer.SetData(arr, 0, LockFlags.None);
            //mesh.ComputeNormals();

            return mesh;
        }
开发者ID:paladin74,项目名称:Dapple,代码行数:101,代码来源:SkyGradient.cs

示例4: UpdateResource

		public void UpdateResource(IPluginOut ForPin, Device OnDevice)
		{
			if (this.FInvalidate || !this.FMeshes.ContainsKey(OnDevice))
			{
				//Destroy old mesh
				DestroyResource(ForPin, OnDevice, false);

				if (this.FInput[0] == null) { return; }

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

				Frame frame = FInput[0];
				if (frame.Loaded)
				{
					Mesh mesh = new Mesh(OnDevice, frame.Indices.Length / 3, frame.Vertices.Length, MeshFlags.Dynamic | MeshFlags.Use32Bit, Frame.VertexDeclaration);
				
					DataStream vS = mesh.LockVertexBuffer(LockFlags.Discard);
					DataStream iS = mesh.LockIndexBuffer(LockFlags.Discard);

					vS.WriteRange(frame.FormattedVertices);
					iS.WriteRange(frame.Indices);

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

					this.FMeshes.Add(OnDevice, mesh);
				}
			}   
		}
开发者ID:keith06,项目名称:VVVV.Nodes.Image,代码行数:29,代码来源:MeshNode.cs

示例5: d3d_DxRestore

		/// <summary>
		/// Restore the mesh when the DirectX device is restored
		/// </summary>
		void d3d_DxRestore(Direct3d d3d, Device dx)
		{
			// If the direct3d device wasn't lost in the first place, don't restore it.
			// This happens the first timeMs around.
			if (mMesh != null)
				return;

			// Restore mesh			
			mMesh = new Mesh(mNumFaces, mNumVertices, mFlags, mVertexFormat, dx);
			Debug.Assert(mMesh.NumberBytesPerVertex == mNumBytesPerVertex);

			// Copy pathIndex buffer
			GraphicsStream stream = mMesh.LockIndexBuffer(LockFlags.Discard);
			stream.Write(mIndexBufferCopy);
			mMesh.UnlockIndexBuffer();
			
			// Copy vertex buffer
			stream = mMesh.LockVertexBuffer(LockFlags.Discard);
			stream.Write(mVertexBufferCopy);
			mMesh.UnlockVertexBuffer();

			// Copy attribute buffer
			int[] attributeBuffer = mMesh.LockAttributeBufferArray(LockFlags.Discard);
			mAttributeBufferCopy.CopyTo(attributeBuffer, 0);
			mMesh.UnlockAttributeBuffer(attributeBuffer);

			mIndexBufferCopy = null;
			mVertexBufferCopy = null;
			mAttributeBufferCopy = null;
		}
开发者ID:kasertim,项目名称:sentience,代码行数:33,代码来源:Direct3d.cs

示例6: fillIndexBuffer

 protected virtual void fillIndexBuffer(Mesh mesh)
 {
     DataStream ds = mesh.LockIndexBuffer(LockFlags.None);
     ds.WriteRange(IndexArray);
     mesh.UnlockIndexBuffer();
 }
开发者ID:vvvv,项目名称:ColladaSlimDX,代码行数:6,代码来源:COLLADAModel.cs

示例7: ColoredSpherePartial


//.........这里部分代码省略.........
            double camHead = Math.Acos((Math.Sin(camera.Latitude.Radians) - Math.Sin(camLat) * Math.Cos(d)) / (Math.Sin(d) * Math.Cos(camLat)));
            if (Math.Sign(camera.Longitude.Radians - camLon) < 0) camHead = Math.PI * 2 - camHead;
            if (double.IsNaN(camHead)) camHead = 0;
            camHead = MathEngine.RadiansToDegrees(camHead);
            double startLon = -camHead - 180 + (lonSpan / 2);

            Mesh mesh = new Mesh(numFaces, numVertices, MeshFlags.Managed, CustomVertex.PositionColored.Format, device);

            // Get the original sphere's vertex buffer.
            int[] ranks = new int[1];
            ranks[0] = mesh.NumberVertices;
            System.Array arr = mesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionColored), LockFlags.None, ranks);

            // Set the vertex buffer
            int vertIndex = 0;
            CustomVertex.PositionColored pnt;
            Point3d v;

            // bottom fade
            double latitude = startLat - ((endLat - startLat) / 10);
            if (latitude < startLat - 1) latitude = startLat - 1;
            for (int slice = 0; slice <= slices; slice++)
            {
                pnt = new CustomVertex.PositionColored();
                double longitude = startLon - ((float)slice / slices * lonSpan);
                v = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                v.TransformCoordinate(SkyGradientTrans);
                pnt.X = (float)v.X;
                pnt.Y = (float)v.Y;
                pnt.Z = (float)v.Z;
                pnt.Color = System.Drawing.Color.FromArgb(0, 0, 0, 0).ToArgb();
                arr.SetValue(pnt, vertIndex++);
            }
            // stacks and slices
            for (int stack = 1; stack < stacks; stack++)
            {
                //latitude = startLat + ((float)(stack-1)/(stacks-1f)*(float)(endLat - startLat));
                double linear = (float)(stack - 1) / (stacks - 1f);
                double k = 1 - Math.Cos((float)(stack - 1) / (stacks - 1f) * Math.PI / 2);
                latitude = startLat + (k * k * k * (float)(endLat - startLat));
                double alphaFactor = 1 - (linear * linear * linear);	// coef alpha transparency
                if (alphaFactor > .8) alphaFactor = .8f;
                for (int slice = 0; slice <= slices; slice++)
                {
                    pnt = new CustomVertex.PositionColored();
                    double longitude = startLon - ((float)slice / slices * lonSpan);
                    v = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                    v.TransformCoordinate(SkyGradientTrans);
                    pnt.X = (float)v.X;
                    pnt.Y = (float)v.Y;
                    pnt.Z = (float)v.Z;
                    pnt.Color = getAtmosphereColor(drawArgs, pnt);
                    arr.SetValue(pnt, vertIndex++);
                }
            }
            // top fade
            latitude = endLat + ((endLat - startLat) / 10);
            for (int slice = 0; slice <= slices; slice++)
            {
                pnt = new CustomVertex.PositionColored();
                double longitude = startLon - ((float)slice / slices * lonSpan);
                v = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                v.TransformCoordinate(SkyGradientTrans);
                pnt.X = (float)v.X;
                pnt.Y = (float)v.Y;
                pnt.Z = (float)v.Z;
                pnt.Color = System.Drawing.Color.FromArgb(0, 0, 0, 0).ToArgb();
                arr.SetValue(pnt, vertIndex++);
            }

            mesh.VertexBuffer.Unlock();
            ranks[0] = indexCount;
            arr = mesh.LockIndexBuffer(typeof(short), LockFlags.None, ranks);
            int i = 0;
            short bottomVertex = 0;
            short topVertex = 0;

            // stacks and slices
            for (short x = 0; x < stacks; x++)
            {
                bottomVertex = (short)((slices + 1) * x);
                topVertex = (short)(bottomVertex + slices + 1);
                for (int y = 0; y < slices; y++)
                {
                    arr.SetValue(bottomVertex, i++);
                    arr.SetValue((short)(topVertex + 1), i++);
                    arr.SetValue(topVertex, i++);
                    arr.SetValue(bottomVertex, i++);
                    arr.SetValue((short)(bottomVertex + 1), i++);
                    arr.SetValue((short)(topVertex + 1), i++);
                    bottomVertex++;
                    topVertex++;
                }
            }

            mesh.UnlockIndexBuffer();
            mesh.IndexBuffer.SetData(arr, 0, LockFlags.None);

            return mesh;
        }
开发者ID:paladin74,项目名称:Dapple,代码行数:101,代码来源:World.cs

示例8: CreateShape

        Mesh CreateShape(CollisionShape shape)
        {
            uint[] indices;
            BulletSharp.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:WebFreak001,项目名称:BulletSharp,代码行数:55,代码来源:MeshFactory.cs

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

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

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

示例12: CreateConvexHullShape

        Mesh CreateConvexHullShape(ConvexHullShape shape)
        {
            ShapeHull hull = new ShapeHull(shape);
            hull.BuildHull(shape.Margin);

            UIntArray hullIndices = hull.Indices;
            Vector3Array points = hull.Vertices;


            int vertexCount = hull.NumIndices;
            int faceCount = hull.NumTriangles;

            bool index32 = vertexCount > 65536;

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


            SlimDX.DataStream indices = mesh.LockIndexBuffer(LockFlags.Discard);
            int i;
            if (index32)
            {
                for (i = 0; i < vertexCount; i++)
                    indices.Write(i);
            }
            else
            {
                for (i = 0; i < vertexCount; i++)
                    indices.Write((short)i);
            }
            mesh.UnlockIndexBuffer();

            SlimDX.DataStream verts = mesh.LockVertexBuffer(LockFlags.Discard);
            Vector3 scale = Vector3.Multiply(shape.LocalScaling, 1.0f + shape.Margin);
            for (i = 0; i < vertexCount; i += 3)
            {
                verts.Write(Vector3.Modulate(points[(int)hullIndices[i]], scale));
                verts.Position += 12;
                verts.Write(Vector3.Modulate(points[(int)hullIndices[i+1]], scale));
                verts.Position += 12;
                verts.Write(Vector3.Modulate(points[(int)hullIndices[i+2]], scale));
                verts.Position += 12;
            }
            mesh.UnlockVertexBuffer();

            mesh.ComputeNormals();
            shapes.Add(shape, mesh);

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

示例13: CreateGImpactMeshShape

        Mesh CreateGImpactMeshShape(GImpactMeshShape shape)
        {
            BulletSharp.DataStream verts, indices;
            int numVerts, numFaces;
            PhyScalarType vertsType, indicesType;
            int vertexStride, indexStride;
            shape.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 vertexBuffer = mesh.LockVertexBuffer(LockFlags.Discard);
            while (vertexBuffer.Position < vertexBuffer.Length)
            {
                vertexBuffer.Write(verts.Read<Vector3>());
                vertexBuffer.Position += 12;
            }
            mesh.UnlockVertexBuffer();

            SlimDX.DataStream indexBuffer = mesh.LockIndexBuffer(LockFlags.Discard);
            if (index32)
            {
                while (indexBuffer.Position < indexBuffer.Length)
                    indexBuffer.Write(indices.Read<int>());
            }
            else
            {
                while (indexBuffer.Position < indexBuffer.Length)
                    indexBuffer.Write((short)indices.Read<int>());
            }
            mesh.UnlockIndexBuffer();

            mesh.ComputeNormals();
            shapes.Add(shape, mesh);

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

示例14: LoadMesh

        /// <summary>
        /// Creates the D3D-mesh from the loaded vertices and the ADTStaticData.Indices. Writes the indicies and vertices
        /// to the buffers of the mesh.
        /// </summary>
        private void LoadMesh()
        {
            mMesh = new Mesh(Game.GameManager.GraphicsThread.GraphicsManager.Device,
                256, 145, MeshFlags.Managed, Wotlk.ADTVertex.FVF);

            var vb = mMesh.LockVertexBuffer(LockFlags.None);
            vb.WriteRange(vertices);
            mMesh.UnlockVertexBuffer();

            var ib = mMesh.LockIndexBuffer(LockFlags.None);
            ib.WriteRange(ADTStaticData.Indices);
            mMesh.UnlockIndexBuffer();
        }
开发者ID:remixod,项目名称:sharpwow,代码行数:17,代码来源:ADTChunk.cs

示例15: BuildGridGeometry

        void BuildGridGeometry()
        {
            Vector3[] globalverts, gridverts;
            int[] globalindices, gridindices, gridindices2;

            float dx = 10.0f;
            float dz = 10.0f;

            // Generate global grid
            GenTriGrid(inputImageHeight, inputImageWidth, dx, dz, new Vector3(0.0f, -1000f, 0f), out globalverts, out globalindices);

            // Number of sub-grids
            int nGridsY = GetGoodAverage(inputImageHeight);
            int nGridsX = GetGoodAverage(inputImageWidth);

            // Subgrid size
            int GridW = inputImageWidth / nGridsX;
            int GridD = inputImageHeight / nGridsY;

            int gridNumVerts = (GridW+1) * (GridD+1);
            int gridNumTris = (GridD ) * (GridW ) * 2;

            // Generate subgrid indices
            GenTriGrid(GridD+1, GridW+1, dx, dz, new Vector3(0.0f, -5000f, 0f), out gridverts, out gridindices);
            GenTriGrid(GridD, GridW, dx, dz, new Vector3(0.0f, -5000f, 0f), out gridverts, out gridindices2);

            // Define some often used variables
            bool overflowX = false, overflowY = false;
            float w = (GridW*nGridsX) * dx;
            float d = (GridD * nGridsY) * dz;
            Vector3 normal = new Vector3(0f, 1f, 0f);
            Mesh mesh;
            VertexPositionNormalTextured[] vertexData = new VertexPositionNormalTextured[gridNumVerts];
            int subgridX, subgridY, globalIndex, gridIndex;

            // foreach subgrid
            for (int gridX = 0; gridX < nGridsX; gridX++)
            {
                for (int gridY = 0; gridY < nGridsY; gridY++)
                {
                    overflowY = false;
                    overflowX = false;
                    mesh = new Mesh(Renderer.Instance.device, gridNumTris, gridNumVerts, MeshFlags.Use32Bit, VertexPositionNormalTextured.Format);

                    // Check for overflow
                    if ((gridX+1) * (GridW + 1) > inputImageWidth)
                        overflowX = true;
                    else if ((gridY+1) * (GridD + 1) > inputImageHeight)
                        overflowY = true;
                    if (overflowY || overflowX)
                    {
                    }
                    else
                    {
                        for (int subD = 0; subD < GridD + 1; ++subD)
                        {
                            for (int subW = 0; subW < GridW + 1; ++subW)
                            {
                                subgridX = gridX * GridW + subW;
                                subgridY = gridY * GridD + subD;
                                globalIndex = (subgridY * inputImageHeight) + subgridX;
                                gridIndex = (subD * (GridD + 1)) + subW;

                                vertexData[gridIndex].Position = globalverts[globalIndex];
                                //vertexData[gridIndex].Y += GetHeightFromImage(subgridY, subgridX) * scale;
                                vertexData[gridIndex].Position.Y += SampleHeightMap3x3(subgridY, subgridX) * scale;
                                vertexData[gridIndex].Normal = normal;
                                vertexData[gridIndex].TextureCoordinate = new Vector2((vertexData[gridIndex].Position.X + (0.5f * w)) / w, (vertexData[gridIndex].Position.Z - (0.5f * d)) / -d);
                            }
                        }

                        DataStream gs = mesh.LockVertexBuffer(LockFlags.None);
                        gs.WriteRange<VertexPositionNormalTextured>(vertexData);
                        gs.Seek(0, SeekOrigin.Begin);
                        // Todo: Fix AABB and frustrum culling
                        Vector3 min, max;
                        //Geometry.ComputeBoundingBox(gs, gridNumVerts, VertexPositionNormalTextured.Format, out min, out max);
                        mesh.UnlockVertexBuffer();

                        //int[] meshIndices = new int[gridNumTris * 3];
                        DataStream ds = mesh.LockAttributeBuffer(LockFlags.None);
                        for (int i = 0; i < gridNumTris; ++i)
                        {
                            ds.Write<int>(0);
                        }
                        mesh.UnlockAttributeBuffer();

                        //meshIndices = ;
                        gs = mesh.LockIndexBuffer(LockFlags.None);
                        gs.WriteRange<int>(gridindices);
                        mesh.UnlockIndexBuffer();

                        //gs = mesh.LockAttributeBuffer(LockFlags.None);
                        //gs.Write(meshAttr);

                        mesh.ComputeNormals();
                        int[] adj = new int[mesh.FaceCount * 3];
                        mesh.GenerateAdjacency(float.Epsilon);
                        //mesh.OptimizeInPlace(MeshFlags.OptimizeAttributeSort | MeshFlags.OptimizeVertexCache | MeshFlags.OptimizeCompact, adj);
                        Mesh newmesh = mesh.Clone(Renderer.Instance.device, MeshFlags.Managed, VertexPosTexNormalTanBitan.Elements);
//.........这里部分代码省略.........
开发者ID:maesse,项目名称:CubeHags,代码行数:101,代码来源:HeightMap.cs


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