id="code_img_closed_846a2545-d7a9-43b3-bce5-623296fdc441" class="code_img_closed"
class="code_img_opened" Onclick="cnblogs_code_hide(‘846a2545-d7a9-43b3-bce5-623296fdc441‘,event)"
1 ///
2 /// Creates a plane as a submesh of the given mesh
3 ///
4 [OgreVersion( 1, 7, 2 )]
5 private static void _createPlane( Mesh mesh )
6 {
7 var sub = mesh.CreateSubMesh();
8 var vertices = new float[32]
9 {
10 -100, -100, 0, // pos
11 0, 0, 1, // normal
12 0, 1, // texcoord
13 100, -100, 0, 0, 0, 1, 1, 1, 100, 100, 0, 0, 0, 1, 1, 0, -100, 100, 0, 0, 0, 1, 0, 0
14 };
15
16 mesh.SharedVertexData = new VertexData();
17 mesh.SharedVertexData.vertexCount = 4;
18 var decl = mesh.SharedVertexData.vertexDeclaration;
19 var binding = mesh.SharedVertexData.vertexBufferBinding;
20
21 var offset = 0;
22 decl.AddElement( 0, offset, VertexElementType.Float3, VertexElementSemantic.Position );
23 offset += VertexElement.GetTypeSize( VertexElementType.Float3 );
24 decl.AddElement( 0, offset, VertexElementType.Float3, VertexElementSemantic.Normal );
25 offset += VertexElement.GetTypeSize( VertexElementType.Float3 );
26 decl.AddElement( 0, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 );
27 offset += VertexElement.GetTypeSize( VertexElementType.Float2 );
28
29 var vbuf = HardwareBufferManager.Instance.CreateVertexBuffer( decl, 4, BufferUsage.StaticWriteOnly );
30 binding.SetBinding( 0, vbuf );
31
32 vbuf.WriteData( 0, vbuf.Size, vertices, true );
33
34 sub.useSharedVertices = true;
35 var ibuf = HardwareBufferManager.Instance.CreateIndexBuffer( IndexType.Size16, 6, BufferUsage.StaticWriteOnly );
36
37 var faces = new short[6]
38 {
39 0, 1, 2, 0, 2, 3
40 };
41 sub.IndexData.indexBuffer = ibuf;
42 sub.IndexData.indexCount = 6;
43 sub.IndexData.indexStart = 0;
44 ibuf.WriteData( 0, ibuf.Size, faces, true );
45
46 mesh.BoundingBox = new AxisAlignedBox( new Vector3( -100, -100, 0 ), new Vector3( 100, 100, 0 ) );
47 mesh.BoundingSphereRadius = Utility.Sqrt( 100*100 + 100*100 );
48 }