il faut adapter les coordonnées uv de la texture, plusieurs façons de faire, en voici une :
Code : Tout sélectionner
;Naissance d'un cube : Premiere chute
UsePNGImageDecoder()
; Coordonnées x,y,z de la caméra
Define.f CamX, CamY, CamZ
InitEngine3D()
Parse3DScripts()
InitKeyboard()
InitSprite()
window = OpenWindow(#PB_Any,0,0,1024,768,"Histoire d'un cube")
OpenWindowedScreen(WindowID(window),0,0,1024,768)
;
; Naissance d'un cube
; Une forme : C'est notre MESH qui ici sera un cube
Cube_Mesh = CreateMesh(#PB_Any)
;Haut
MeshVertexPosition(-0.5, 0.5,0.5)
MeshVertexNormal(0, 1, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.25)
MeshVertexPosition(-0.5, 0.5,-0.5)
MeshVertexNormal(0, 1, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.50)
MeshVertexPosition(0.5, 0.5,-0.5)
MeshVertexNormal(0, 1, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.50)
MeshVertexPosition(0.5, 0.5,0.5)
MeshVertexNormal(0, 1, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.25)
MeshFace(2, 1, 0)
MeshFace(3, 2, 0)
;dessous
AddSubMesh()
MeshVertexPosition(-0.5, -0.5,0.5)
MeshVertexNormal(0, -1, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.75)
MeshVertexPosition(-0.5, -0.5,-0.5)
MeshVertexNormal(0, -1, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 1.00)
MeshVertexPosition(0.5, -0.5,-0.5)
MeshVertexNormal(0, -1, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 1.00)
MeshVertexPosition(0.5, -0.5,0.5)
MeshVertexNormal(0, -1, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.75)
MeshFace(0, 1, 2)
MeshFace(0, 2, 3)
;arriere
AddSubMesh()
MeshVertexPosition(-0.5, -0.5,-0.5)
MeshVertexNormal(0, 0, -1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.5)
MeshVertexPosition(-0.5, 0.5,-0.5)
MeshVertexNormal(0, 0, -1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.75)
MeshVertexPosition(0.5, 0.5,-0.5)
MeshVertexNormal(0, 0, -1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.75)
MeshVertexPosition(0.5, -0.5,-0.5)
MeshVertexNormal(0, 0, -1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.5)
MeshFace(0, 1, 2)
MeshFace(0, 2, 3)
;avant
AddSubMesh()
MeshVertexPosition(-0.5, -0.5,0.5)
MeshVertexNormal(0, 0, 1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.0)
MeshVertexPosition(-0.5, 0.5,0.5)
MeshVertexNormal(0, 0, 1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.25)
MeshVertexPosition(0.5, 0.5,0.5)
MeshVertexNormal(0, 0, 1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.25)
MeshVertexPosition(0.5, -0.5,0.5)
MeshVertexNormal(0, 0, 1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.0)
MeshFace(2, 1, 0)
MeshFace(3, 2, 0)
;gauche
AddSubMesh()
MeshVertexPosition(-0.5, -0.5,-0.5)
MeshVertexNormal(-1, 0, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.00, 0.25)
MeshVertexPosition(-0.5, 0.5,-0.5)
MeshVertexNormal(-1, 0, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.00, 0.50)
MeshVertexPosition(-0.5, 0.5,0.5)
MeshVertexNormal(-1, 0, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.50)
MeshVertexPosition(-0.5, -0.5,0.5)
MeshVertexNormal(-1, 0, 0)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.33, 0.25)
MeshFace(2, 1, 0)
MeshFace(3, 2, 0)
;droit
AddSubMesh()
MeshVertexPosition(0.5, -0.5,-0.5)
MeshVertexNormal(0, 0, 1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.25)
MeshVertexPosition(0.5, 0.5,-0.5)
MeshVertexNormal(0, 0, 1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0.66, 0.50)
MeshVertexPosition(0.5, 0.5,0.5)
MeshVertexNormal(0, 0, 1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(1.00, 0.50)
MeshVertexPosition(0.5, -0.5,0.5)
MeshVertexNormal(0, 0, 1)
MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(1.00, 0.25)
MeshFace(0, 1, 2)
MeshFace(0, 2, 3)
FinishMesh(1)
Ground_Mesh = CreatePlane(#PB_Any, 10, 10, 3, 3, 3, 3)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Texture = LoadTexture(#PB_Any,"de.png")
; StartDrawing(TextureOutput(Texture))
; Box(0,0,512,512,RGB(0, 0, 0))
; Box(1,1,510,510,RGB(255, 216, 0))
; StopDrawing()
; Un MATERIEL c'est la partie visible de notre cube qui sera constitué de notre texture
Material = CreateMaterial(#PB_Any,TextureID(texture))
; Création d'un cube en hauteur
; CreateEntity() permet de définir les coordonnées x,y,z lors de la création d'une entité
Cube_Entity = CreateEntity(#PB_Any, MeshID(Cube_Mesh), MaterialID(Material), 0, 6, 0)
CreateEntityBody(Cube_Entity, #PB_Entity_BoxBody,0.1,0.1,0.1)
RotateEntity(Cube_Entity, Random(180), Random(180), Random(180), #PB_Absolute)
; Création du sol
Ground_Entity = CreateEntity(#PB_Any, MeshID(Ground_Mesh), MaterialID(Material), 0, -2, 0)
CreateEntityBody(Ground_Entity, #PB_Entity_StaticBody, 0, 0.1, 0.1)
;
;Lumiere et ombre
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -1.8, 10, 5)
WorldShadows(#PB_Shadow_Additive)
;
; Une camera
Camera = CreateCamera(#PB_Any,0,0,100,100)
CamX=2.0
CamY=1.0
CamZ=15
; La caméra regarde en direction du point au coordonnées x=0, y=0, z=0
CameraLookAt(camera,0,0,0)
While #True
Event = WindowEvent()
ExamineKeyboard()
; Touche Escape pour fermer l'application
If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
Break
EndIf
If KeyboardPushed(#PB_Key_Left)
CamX-0.2
ElseIf KeyboardPushed(#PB_Key_Right)
CamX+0.2
EndIf
If KeyboardPushed(#PB_Key_Up)
CamY+0.2
ElseIf KeyboardPushed(#PB_Key_Down)
CamY-0.2
EndIf
MoveCamera(camera, CamX, CamY, CamZ, #PB_Absolute)
; Affiche le rendu de la scène
RenderWorld()
FlipBuffers()
Wend