t'as aussi la façon manuelle
on créé les sommets (MeshVertex)
puis on les assemble par face (MeshFace)
attention : avec MeshFace, l'ordre des sommets à son importance, il definit le "devant" et le "derriere" de la face
par defaut, les faces ne sont visible que si elle sont vu de devant
MeshFace(0,1,2) <> MeshFace(0,2,1)
Code:
EnableExplicit
Declare CreateBox(Mesh.i, Size.f = 1.0)
Declare AddMesh(Mesh, NewX.f=0 , NewY.f=0, NewZ.f=0, ScaleX.f=1, ScaleY.f=1, ScaleZ.f=1, RotateX.f=0, RotateY.f=0, RotateZ.f=0)
;Scene
Global Camera, Light
Global xx.f=0.5
Global yy.f=0.5
Global zz.f=0.5
;Summary
Declare GameLoad()
Declare RenderGame3D()
GameLoad()
Procedure GameLoad()
Protected Window, n
If InitEngine3D() And InitKeyboard() And InitSprite() And InitMouse() And InitSound()
Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
SetWindowColor(Window, 0)
;-[Screen]
OpenWindowedScreen(WindowID(Window),0, 0, WindowWidth(Window) , WindowHeight(Window))
KeyboardMode(#PB_Keyboard_International)
; On indique ou se trouve les textures
Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
;-Camera
Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
CameraBackColor(Camera, RGB(0, 0, 0))
MoveCamera(Camera, 0, 0, -100)
CameraLookAt(Camera, 0, 0, 0)
;-Light
Light = CreateLight(#PB_Any, RGB(255, 255, 255), 0, 1000, 0)
AmbientColor(RGB(64, 64, 64))
;-1 Création de l'entité sans material
CreateEntity(0, MeshID(CreateBox(#PB_Any, 20)), #PB_Material_None, 0, 0, 0)
;-2 Création des materiaux (Les textures) pour chacune des faces
CreateMaterial(0, TextureID(LoadTexture(-1, "Dirt.jpg")))
CreateMaterial(1, TextureID(LoadTexture(-1, "Caisse.png")))
CreateMaterial(2, TextureID(LoadTexture(-1, "Geebee2.bmp")))
CreateMaterial(3, TextureID(LoadTexture(-1, "MRAMOR6X6.jpg")))
CreateMaterial(4, TextureID(LoadTexture(-1, "soil_wall.jpg")))
CreateMaterial(5, TextureID(LoadTexture(-1, "grass.jpg")))
;-2 - Application du material sur chaque face du mesh
SetEntityMaterial(0, MaterialID(0), 0) ;UP face
SetEntityMaterial(0, MaterialID(1), 1) ;Down face
SetEntityMaterial(0, MaterialID(2), 2) ;Front face
SetEntityMaterial(0, MaterialID(3), 3) ;Back face
SetEntityMaterial(0, MaterialID(4), 4) ;Left face
SetEntityMaterial(0, MaterialID(5), 5) ;Right face
;-Loop
While #True
;Evenement fenetre
Repeat : Until WindowEvent() = 0
;Traitement 3D
FlipBuffers()
RotateEntity(0, xx, yy, zz, #PB_Relative)
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
End
EndIf
EndIf
If ExamineMouse()
EndIf
RenderWorld()
Wend
Else
Debug "Ooops ! probleme d'initialisation"
EndIf
EndProcedure
; // Ce qui suit peut être placer dans un include (module ou pas)
;Result = CreateBox(#Mesh, Size)
Procedure CreateBox(Mesh.i, Size.f = 1.0)
Protected s.f=size/2
If Mesh = #PB_Any
Mesh = CreateMesh(#PB_Any, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
Else
CreateMesh(Mesh, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
EndIf
AddSubMesh();haut
MeshVertex(-s,s,-s,0,0,0)
MeshVertex( s,s,-s,1,0,0)
MeshVertex(-s,s, s,0,1,0)
MeshVertex( s,s, s,1,1,0)
MeshFace(0,3,1):MeshFace(0,2,3)
AddSubMesh();bas
MeshVertex(-s,-s,-s,0,0,0)
MeshVertex( s,-s,-s,1,0,0)
MeshVertex(-s,-s, s,0,1,0)
MeshVertex( s,-s, s,1,1,0)
MeshFace(0,1,3):MeshFace(0,3,2)
AddSubMesh();gauche
MeshVertex(-s,-s,-s,0,0,0)
MeshVertex(-s, s,-s,1,0,0)
MeshVertex(-s,-s, s,0,1,0)
MeshVertex(-s, s, s,1,1,0)
MeshFace(0,3,1):MeshFace(0,2,3)
AddSubMesh();droite
MeshVertex(s,-s,-s,0,0,0)
MeshVertex(s, s,-s,1,0,0)
MeshVertex(s,-s, s,0,1,0)
MeshVertex(s, s, s,1,1,0)
MeshFace(0,1,3):MeshFace(0,3,2)
AddSubMesh();avant
MeshVertex(-s,-s,-s,0,0,0)
MeshVertex( s,-s,-s,1,0,0)
MeshVertex(-s, s,-s,0,1,0)
MeshVertex( s, s,-s,1,1,0)
MeshFace(0,3,1):MeshFace(0,2,3)
AddSubMesh();arriere
MeshVertex(-s,-s,s,0,0,0)
MeshVertex( s,-s,s,1,0,0)
MeshVertex(-s, s,s,0,1,0)
MeshVertex( s, s,s,1,1,0)
MeshFace(0,1,3):MeshFace(0,3,2)
FinishMesh(#True)
NormalizeMesh(mesh)
ProcedureReturn Mesh
EndProcedure