Methode um Mesh.Box automatisch zu texturieren?

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von ~blaze~.

    Methode um Mesh.Box automatisch zu texturieren?

    Hallo

    Diese Frage bezieht sich auf Managed DirectX.
    Ich suche schon seit längerem eine Methode, um ein Mesh.Box - Objekt auf ALLEN Seiten mit einer(?) Textur zu überziehen.
    Das Problem liegt darin, dass der Befehl nur Positions-, nicht aber Texturdaten erstellt.
    Deshalb benötige ich einen Algorithmus, der eine(?) Textur um einen Würfel legt.
    Ich brauch keinen C&P Code, nur einen Denkanstoß, wie man die Texturkoordinaten setzen könnte.

    Vielen Dank,
    SᴛᴀʀGᴀᴛᴇ01
    Wenn du das Mesh entsprechend erstelltst, heißt nicht ReadOnly sondern Writeable, dann kannst du den VertexBuffer bearbeiten und entsprechend UV Koordinaten hinzufügen...
    msdn.microsoft.com/en-us/libra…b297092%28v=vs.85%29.aspx
    Ich wollte auch mal ne total überflüssige Signatur:
    ---Leer---
    Danke :)
    Mein eigentliches Problem ist aber, aus den Positionsdaten die Texturdaten zu errechnen, so dass sich eine Textur um einen Würfel/Quader legen lässt.
    Daher wie ich die Daten verändere ist nicht das Problem, das weiß ich ^^
    Ich benötige nur eine Vorgehensweise die V und U Daten zu errechnen
    SᴛᴀʀGᴀᴛᴇ01
    da gibt es so gesehen nichts großes zu rechnen, es sei denn du willst es auf eine spezielle Art drüber legen, also musst du das gegebenenfalls nochmals erklären.

    Denn sogesehen gibst du einem Vertex nur eine UV Koordinate, welche eine Angabe in Prozent darstellt-> 0,0 entspricht dabei der linken oberen Ecke des Bildes und 1,1(=100%,100%) der rechten oberen...
    Ich wollte auch mal ne total überflüssige Signatur:
    ---Leer---
    Ich habs fertig, wens interressiert:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Shared Function TexturedBox(ByRef device As Direct3D.Device, width As Single, height As Single, depth As Single) As Direct3D.Mesh
    2. Dim adjacency As GraphicsStream = Nothing
    3. Dim box As Mesh = Mesh.Box(device, width, height, depth, adjacency)
    4. Dim texturedBox__1 As New Mesh(box.NumberFaces, box.NumberVertices, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, device)
    5. Dim ranks As Integer() = New Integer(0) {}
    6. ranks(0) = box.NumberVertices
    7. Dim arr As System.Array = box.VertexBuffer.Lock(0, GetType(CustomVertex.PositionNormal), LockFlags.None, ranks)
    8. Using vb As VertexBuffer = texturedBox__1.VertexBuffer
    9. Dim data As System.Array = vb.Lock(0, GetType(CustomVertex.PositionNormalTextured), LockFlags.None, ranks)
    10. Dim ges As String = ""
    11. For i As Integer = 0 To arr.Length - 1
    12. Dim pn As Direct3D.CustomVertex.PositionNormal = DirectCast(arr.GetValue(i), CustomVertex.PositionNormal)
    13. Dim pnt As Direct3D.CustomVertex.PositionNormalTextured = DirectCast(data.GetValue(i), CustomVertex.PositionNormalTextured)
    14. pnt.X = pn.X
    15. pnt.Y = pn.Y
    16. pnt.Z = pn.Z
    17. pnt.Nx = pn.Nx
    18. pnt.Ny = pn.Ny
    19. pnt.Nz = pn.Nz
    20. Select Case i
    21. 'Rechts
    22. Case Is = 0
    23. pnt.Tu = 1
    24. pnt.Tv = 1
    25. Case Is = 1
    26. pnt.Tu = 2 / 3
    27. pnt.Tv = 1
    28. Case Is = 2
    29. pnt.Tu = 2 / 3
    30. pnt.Tv = 1 / 2
    31. Case Is = 3
    32. pnt.Tu = 1
    33. pnt.Tv = 1 / 2
    34. 'Oben
    35. Case Is = 6
    36. pnt.Tu = 1 / 3
    37. pnt.Tv = 1 / 2
    38. Case Is = 7
    39. pnt.Tu = 1 / 3
    40. pnt.Tv = 0
    41. Case Is = 4
    42. pnt.Tu = 2 / 3
    43. pnt.Tv = 0
    44. Case Is = 5
    45. pnt.Tu = 2 / 3
    46. pnt.Tv = 1 / 2
    47. 'Links
    48. Case Is = 8
    49. pnt.Tu = 0
    50. pnt.Tv = 1 / 2
    51. Case Is = 9
    52. pnt.Tu = 1 / 3
    53. pnt.Tv = 1 / 2
    54. Case Is = 10
    55. pnt.Tu = 1 / 3
    56. pnt.Tv = 1
    57. Case Is = 11
    58. pnt.Tu = 0
    59. pnt.Tv = 1
    60. 'Unten
    61. Case Is = 15
    62. pnt.Tu = 0
    63. pnt.Tv = 0
    64. Case Is = 12
    65. pnt.Tu = 1 / 3
    66. pnt.Tv = 0
    67. Case Is = 13
    68. pnt.Tu = 1 / 3
    69. pnt.Tv = 1 / 2
    70. Case Is = 14
    71. pnt.Tu = 0
    72. pnt.Tv = 1 / 2
    73. 'Vorne
    74. Case Is = 16
    75. pnt.Tu = 2 / 3
    76. pnt.Tv = 1
    77. Case Is = 17
    78. pnt.Tu = 1 / 3
    79. pnt.Tv = 1
    80. Case Is = 18
    81. pnt.Tu = 1 / 3
    82. pnt.Tv = 1 / 2
    83. Case Is = 19
    84. pnt.Tu = 2 / 3
    85. pnt.Tv = 1 / 2
    86. 'Hinten
    87. Case Is = 23
    88. pnt.Tu = 1
    89. pnt.Tv = 1 / 2
    90. Case Is = 22
    91. pnt.Tu = 1
    92. pnt.Tv = 0
    93. Case Is = 21
    94. pnt.Tu = 2 / 3
    95. pnt.Tv = 0
    96. Case Is = 20
    97. pnt.Tu = 2 / 3
    98. pnt.Tv = 1 / 2
    99. End Select
    100. data.SetValue(pnt, i)
    101. Next
    102. vb.Unlock()
    103. box.VertexBuffer.Unlock()
    104. End Using
    105. ranks(0) = box.NumberFaces * 3
    106. arr = box.LockIndexBuffer(GetType(Short), LockFlags.None, ranks)
    107. texturedBox__1.IndexBuffer.SetData(arr, 0, LockFlags.None)
    108. box.Dispose()
    109. Array.Clear(arr, 0, arr.Length)
    110. adjacency.Dispose()
    111. Array.Clear(ranks, 0, ranks.Length)
    112. Return texturedBox__1
    113. End Function


    Die Funktion setzt die Texturkoordinaten für einen Würfel für soeine Textur:
    [1][2][3]
    [4][5][6]
    Also ein Bild, unterteilt in 6 Segmente
    1 = Unten, 2 = Oben, 3 = Hinten, 4 = Links, 5 = Vorne, 6 = Rechts
    SᴛᴀʀGᴀᴛᴇ01
    Hi
    das Select Case in der Schleife macht keinen Sinn. Da setzt du es sogar lieber manuell. Überleg dir doch mal, wie du das per Bits, Bitshifts und Bitweise Verundungen lösen könntest, das wäre in Kombination mit dem Hochzählen der For-Schleife eine elegante Art.
    Übrigens dürfte das Laden der pnt aus dem Array unnötig sein, da du eh alle Werte setzt. Structs brauchen ja keine Initialisierung, da sie i.A. eh auf dem Stapel verarbeitet werden.
    Funktioniert eigentlich der Vertexpuffer von Box1 danach noch? Dispose aus Using sollte ja eigentlich die Resourcen freigeben.

    Gruß
    ~blaze~