Comment appliquer un materiel sur un mesh manuel
Publié : mer. 28/août/2013 12:42
Ne comprenant pas pourquoi je n'arrive pas à faire apparaître un matériel sur un mesh manuel issu de l'importation d'un fichier Wavefront (obj) http://www.purebasic.fr/french/viewtopi ... 13&t=13893 j'ai essayé de faire bêtement un cube manuel sur lequel j'ai tenté de faire apparaître une texture composée d'un fond jaune.
Malheureusement, cette texture n’apparaît pas !!
Etant plutôt très Noob dans le domaine de la 3D, J'aimerais savoir si les 3 lignes qui suivent sont utiles dans la conception d'un cube.
Malheureusement, cette texture n’apparaît pas !!
Code : Tout sélectionner
InitEngine3D()
InitKeyboard()
InitSprite()
Window = OpenWindow(#PB_Any,0,0,1024,768,"Cube")
OpenWindowedScreen(WindowID(window),0,0,1024,768)
AmbientColor(RGB(255, 255, 255))
CreateLight(#PB_Any,RGB(255, 255, 255), 0,50,50)
;Creation d'un mesh (ici un cube)
Mesh = CreateMesh(#PB_Any)
MeshVertexPosition(-100, 100, -100)
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)
MeshVertexPosition(100, 100, -100)
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)
MeshVertexPosition(100, -100, -100)
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)
MeshVertexPosition(-100, -100, -100)
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)
MeshVertexPosition(-100, 100, 100)
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)
MeshVertexPosition(100, 100, 100)
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)
MeshVertexPosition(100, -100, 100)
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)
MeshVertexPosition(-100, -100, 100)
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)
MeshFace(0, 2, 3)
MeshFace(0, 1, 2)
MeshFace(1, 6, 2)
MeshFace(1, 5, 6)
MeshFace(4, 6, 5)
MeshFace(4, 7, 6)
MeshFace(0, 7, 4)
MeshFace(0, 3, 7)
MeshFace(0, 5, 1)
MeshFace(0, 4, 5)
MeshFace(2, 7, 3)
MeshFace(2, 6, 7)
FinishMesh(#True)
Texture = CreateTexture(#PB_Any, 512, 512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()
Material = CreateMaterial(#PB_Any, TextureID(Texture))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(material))
EntityPhysicBody(Entity, #PB_Entity_StaticBody, 1, 1, 1)
WorldDebug(#PB_World_DebugBody)
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera,RGB(131, 204, 249))
While #True
event = WindowEvent()
If event = #PB_Event_CloseWindow
Break
EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
If KeyboardPushed(#PB_Key_Left)
y+1
EndIf
If KeyboardPushed(#PB_Key_Right)
y-1
EndIf
If KeyboardPushed(#PB_Key_Up)
x+1
EndIf
If KeyboardPushed(#PB_Key_Down)
x-1
EndIf
RotateEntity(Entity, x,y,z)
MoveCamera(Camera, 500, 500, 100, #PB_Absolute)
CameraLookAt(camera,0,0,0)
RenderWorld()
FlipBuffers()
Wend
Code : Tout sélectionner
MeshVertexNormal(0, 0, 0)
MeshVertexColor($FF0000)
MeshVertexTextureCoordinate(0, 1)