1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Private Function CreateTexturedBox(ByVal device As Direct3D.Device, ByVal width As Single, ByVal height As Single, ByVal depth As Single) As Direct3D.Mesh
Dim adjacency As GraphicsStream
Dim box As Mesh = Mesh.Box(device, width, height, depth, adjacency)
Dim texturedBox As Mesh = New Mesh(box.NumberFaces, box.NumberVertices, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, device)
' Get the original mesh's vertex buffer.
Dim ranks(0) As Integer
ranks(0) = box.NumberVertices
Dim arr As System.Array = box.VertexBuffer.Lock(0, (New CustomVertex.PositionNormal).GetType(), LockFlags.None, ranks)
' Set the vertex buffer
Dim data As System.Array = texturedBox.VertexBuffer.Lock(0, (New CustomVertex.PositionNormalTextured).GetType(), LockFlags.None, ranks)
Dim i As Integer
For i = 0 To arr.Length - 1
Dim pn As Direct3D.CustomVertex.PositionNormal = arr.GetValue(i)
Dim pnt As Direct3D.CustomVertex.PositionNormalTextured = data.GetValue(i)
pnt.X = pn.X
pnt.Y = pn.Y
pnt.Z = pn.Z
pnt.Nx = pn.Nx
pnt.Ny = pn.Ny
pnt.Nz = pn.Nz
pnt.Tu = pnt.X + width / 2
pnt.Tv = 1.0F - pnt.Y + height / 2
data.SetValue(pnt, i)
Next
texturedBox.VertexBuffer.Unlock()
box.VertexBuffer.Unlock()
' Set the index buffer.
ranks(0) = box.NumberFaces * 3
arr = box.LockIndexBuffer((New Short).GetType(), LockFlags.None, ranks)
texturedBox.IndexBuffer.SetData(arr, 0, LockFlags.None)
Return texturedBox
End Function |
Partager