Page 1 sur 1
Comment utiliser SetMeshData()
Publié : jeu. 06/sept./2018 22:53
par threedslider
Dites, comment on utilise correctement pour la commande SetMeshData pour changer le mesh ?? Un exemple court dont vous pourriez me montrer, c'est possible ça ?
Merci

Modération : Le titre "
Purebasic commands" n'étant pas parlant, il est remplacé par "Comment utiliser la commande
SetMeshData()
Re: Purebasic commands
Publié : ven. 07/sept./2018 9:53
par Marc56
Il y a un exemple dans le répertoire examples\3D du répertoire d'installation de purebasic
Re: Comment utiliser SetMeshData()
Publié : ven. 07/sept./2018 11:40
par falsam
threedslider a écrit :Un exemple court dont vous pourriez me montrer, c'est possible ça ?
C'est possible et pour cela on va travailler avec un cube.
Le principe sera le suivant :
1 - Obtenir la cartographie du mesh (Vertices, faces, etc ...) dans un tableau : GetMeshData()
2 - Effectuer les transformations dans le tableau obtenu.
3 - Faire la mise à jour du mesh : SetMeshData()
■ Préambule
- Le mesh (
Maillage) d'un cube est composé de six faces.
- Chaque face est matérialisée par 4 Vertices
- Un vertex (
pluriel : vertices) est défini par un point dans l'espace 3d avec les composantes x y z,
- Chaque vertex du cube est numéroté de 0 à 23
Voici donc notre cube représenté par un mesh de 24 vertices (0->23)
Il est inutile de connaitre la position de l'entité utilisant le mesh pour travailler sur le mesh.
Re: Comment utiliser SetMeshData()
Publié : ven. 07/sept./2018 11:41
par falsam
■ Obtenir la cartographie d'un mesh : GetMeshData()
Nous allons nous interesser à l'arête du cube matérialisé par les points (3, 10, 16) et (6, 11, 19) avec ce code
Code : Tout sélectionner
EnableExplicit
Enumeration Window
#mf
EndEnumeration
Define Event, Camera, Mesh, Entity
; 0 - Declaration d'un tableau contenant la cartographie d'un mesh
Define Dim MeshData.PB_MeshVertex(0)
;Initialisation minimum de l'environnement 3D
InitEngine3D() : InitKeyboard() : InitSprite()
;Fenetre
OpenWindow(#mf, 0, 0, 1024, 768, "Cartographie d'un mesh")
OpenWindowedScreen(WindowID(#mf), 0, 0, 1024, 768)
;Caméra & Lumiére
Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(Camera, 5, 5, 5)
CameraLookAt(Camera, 0, 0, 0)
CreateLight(#PB_Any, RGB(255, 255, 255), -100, 200, 100)
;Création d'un cube (Mesh) de taille 2
Mesh = CreateCube(#PB_Any, 2)
;1 - Obtenir la cartographie du mesh avant transformation (Vertices, faces, etc ...)
GetMeshData(Mesh, 0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(Mesh)-1)
;Affichage des variables
; 1 - Clique sur l'onglet Tableaux
; 2 - Clique droit sur MeshData.PB_MeshVertex(23)
; 3 - Examine les coordonnées x y et z de chacun de points
ShowVariableViewer()
Entity = CreateEntity(#PB_Any , MeshID(Mesh), #PB_Material_None)
;Loop
While #True
;Evenement window
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
;Evenement clavier
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
Break
EndIf
EndIf
RotateEntity(Entity, 0, 0.3, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Wend

Aide
https://www.purebasic.com/french/docume ... hdata.html
Re: Comment utiliser SetMeshData()
Publié : ven. 07/sept./2018 11:44
par falsam
Modifier la cartographie d'un mesh : SetMeshData()
L'objectif est d'obtenir une face inclinée du cube.
Code : Tout sélectionner
EnableExplicit
Enumeration Window
#mf
EndEnumeration
Define Event, Camera, Mesh, Entity
; 0 - Declaration d'un tableau contenant la cartographie d'un mesh
Define Dim MeshData.PB_MeshVertex(0)
;Initialisation minimum de l'environnement 3D
InitEngine3D() : InitKeyboard() : InitSprite()
;Fenetre
OpenWindow(#mf, 0, 0, 1024, 768, "Cartographie d'un mesh")
OpenWindowedScreen(WindowID(#mf), 0, 0, 1024, 768)
;Caméra & Lumiére
Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(Camera, 5, 5, 5)
CameraLookAt(Camera, 0, 0, 0)
CreateLight(#PB_Any, RGB(255, 255, 255), -100, 200, 100)
;Création d'un cube (Mesh) de taille 2
Mesh = CreateCube(#PB_Any, 2)
;1 - Obtenir la cartographie du mesh avant transformation (Vertices, faces, etc ...)
GetMeshData(Mesh, 0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(Mesh)-1)
;2 - Transformation du mesh
MeshData(3)\x = 0
MeshData(10)\x = 0
MeshData(16)\x = 0
MeshData(6)\x = 0
MeshData(11)\x = 0
MeshData(19)\x = 0
ShowVariableViewer()
;3 - Mise à jour du mesh
SetMeshData(Mesh, 0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(Mesh)-1)
Entity = CreateEntity(#PB_Any , MeshID(Mesh), #PB_Material_None)
;Loop
While #True
;Evenement window
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
;Evenement clavier
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
Break
EndIf
EndIf
RotateEntity(Entity, 0, 0.3, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Wend

Aide :
https://www.purebasic.com/french/docume ... hdata.html
Comment utiliser SetMeshData()
Publié : ven. 07/sept./2018 11:56
par falsam
Un autre exemple reprenant les fonctions GetMeshData() et SetMeshData() pour créer une pyramide.
https://www.purebasic.fr/french/viewtop ... 13&t=17212
Re: Comment utiliser SetMeshData()
Publié : sam. 08/sept./2018 17:53
par threedslider
Merci beaucoup falsam !
Je vais me mettre sérieusement à Purebasic
