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


C# Geometry.SetVertexBuffer方法代码示例

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


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

示例1: CreateScene


//.........这里部分代码省略.........
					}
				}
			}
			else
			{
				Log.Write(LogLevel.Error, "Failed to lock the model vertex buffer to get original vertices");
				return;
			}

			// Create StaticModels in the scene. Clone the model for each so that we can modify the vertex data individually
			for (int y = -1; y <= 1; ++y)
			{
				for (int x = -1; x <= 1; ++x)
				{
					Node node = scene.CreateChild("Object");
					node.Position = (new Vector3(x * 2.0f, 0.0f, y * 2.0f));
					StaticModel sm = node.CreateComponent<StaticModel>();
					Model cloneModel = originalModel.Clone();
					sm.Model = (cloneModel);
					// Store the cloned vertex buffer that we will modify when animating
					animatingBuffers.Add(cloneModel.GetGeometry(0, 0).GetVertexBuffer(0));
				}
			}

			// Finally create one model (pyramid shape) and a StaticModel to display it from scratch
			// Note: there are duplicated vertices to enable face normals. We will calculate normals programmatically
			{
				const uint numVertices = 18;
				float[] vertexData =
				{
					// Position             Normal
					0.0f, 0.5f, 0.0f,       0.0f, 0.0f, 0.0f,
					0.5f, -0.5f, 0.5f,      0.0f, 0.0f, 0.0f,
					0.5f, -0.5f, -0.5f,     0.0f, 0.0f, 0.0f,

					0.0f, 0.5f, 0.0f,       0.0f, 0.0f, 0.0f,
					-0.5f, -0.5f, 0.5f,     0.0f, 0.0f, 0.0f,
					0.5f, -0.5f, 0.5f,      0.0f, 0.0f, 0.0f,

					0.0f, 0.5f, 0.0f,       0.0f, 0.0f, 0.0f,
					-0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,
					-0.5f, -0.5f, 0.5f,     0.0f, 0.0f, 0.0f,

					0.0f, 0.5f, 0.0f,       0.0f, 0.0f, 0.0f,
					0.5f, -0.5f, -0.5f,     0.0f, 0.0f, 0.0f,
					-0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,

					0.5f, -0.5f, -0.5f,     0.0f, 0.0f, 0.0f,
					0.5f, -0.5f, 0.5f,      0.0f, 0.0f, 0.0f,
					-0.5f, -0.5f, 0.5f,     0.0f, 0.0f, 0.0f,

					0.5f, -0.5f, -0.5f,     0.0f, 0.0f, 0.0f,
					-0.5f, -0.5f, 0.5f,     0.0f, 0.0f, 0.0f,
					-0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f
				};

				short[] indexData =
				{
					0, 1, 2,
					3, 4, 5,
					6, 7, 8,
					9, 10, 11,
					12, 13, 14,
					15, 16, 17
				};

				Model fromScratchModel = new Model();
				VertexBuffer vb = new VertexBuffer(Context, false);
				IndexBuffer ib = new IndexBuffer(Context, false);
				Geometry geom = new Geometry();

				// Shadowed buffer needed for raycasts to work, and so that data can be automatically restored on device loss
				vb.Shadowed = true;
				vb.SetSize(numVertices, ElementMask.Position | ElementMask.Normal, false);
				vb.SetData(vertexData);

				ib.Shadowed = true;
				ib.SetSize(numVertices, false, false);
				ib.SetData(indexData);

				geom.SetVertexBuffer(0, vb, uint.MaxValue);
				geom.IndexBuffer = ib;
				geom.SetDrawRange(PrimitiveType.TriangleList, 0, numVertices, true);

				fromScratchModel.NumGeometries = 1;
				fromScratchModel.SetGeometry(0, 0, geom);
				fromScratchModel.BoundingBox = new BoundingBox(new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, 0.5f, 0.5f));

				Node node = scene.CreateChild("FromScratchObject");
				node.Position = (new Vector3(0.0f, 3.0f, 0.0f));
				StaticModel sm = node.CreateComponent<StaticModel>();
				sm.Model = fromScratchModel;
			}

			// Create the camera
			CameraNode = new Node();
			CameraNode.Position = (new Vector3(0.0f, 2.0f, -20.0f));
			Camera camera = CameraNode.CreateComponent<Camera>();
			camera.FarClip = 300.0f;
		}
开发者ID:jiailiuyan,项目名称:urho-samples,代码行数:101,代码来源:DynamicGeometry.cs

示例2: CreateModelFromVertexData

		unsafe Model CreateModelFromVertexData(SurfaceDto surface)
		{
			var model = new Model();
			var vertexBuffer = new VertexBuffer(Context, false);
			var indexBuffer = new IndexBuffer(Context, false);
			var geometry = new Geometry();

			vertexBuffer.Shadowed = true;
			vertexBuffer.SetSize((uint)surface.VertexData.Length, ElementMask.Position | ElementMask.Normal | ElementMask.Color, false);

			fixed (SpatialVertexDto* p = &surface.VertexData[0])
				vertexBuffer.SetData(p);

			var indexData = surface.IndexData;
			indexBuffer.Shadowed = true;
			indexBuffer.SetSize((uint)indexData.Length, false, false);
			indexBuffer.SetData(indexData);

			geometry.SetVertexBuffer(0, vertexBuffer);
			geometry.IndexBuffer = indexBuffer;
			geometry.SetDrawRange(PrimitiveType.TriangleList, 0, (uint)indexData.Length, 0, (uint)surface.VertexData.Length, true);

			model.NumGeometries = 1;
			model.SetGeometry(0, 0, geometry);
			model.BoundingBox = new BoundingBox(new Vector3(-1.26f, -1.26f, -1.26f), new Vector3(1.26f, 1.26f, 1.26f));

			return model;
		}
开发者ID:xamarin,项目名称:urho-samples,代码行数:28,代码来源:UrhoApp.cs


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