like this one
you start the code below
you get this:
or this :
if you comment the line 67
Code: Select all
ScaleEntity(compteur, 1, coul_hauteur/100,1) ;<<<<<<<<<<<<< a activer pour avoir le relief dans l'image or desactive this ... for no 3D effect in picture
the code :
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic -image to scene3d
;
; By Zorro
;
; ------------------------------------------------------------
;
UsePNGImageDecoder()
UseJPEGImageDecoder()
#PB_Material_SpecularColor = 1
#PB_Material_AmbientColor = 2
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY
#CameraSpeed = 1
enumeration
#image
#Texture
#mesh
#entity
#material
EndEnumeration
Global compteur=0
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
; LoadTexture(#Texture, "soil_wall.jpg")
CreateTexture(#texture,256,256)
StartDrawing(TextureOutput(#Texture))
box(0,0,256,256,rgb(255,255,255))
StopDrawing()
CreateMaterial(#material, TextureID(#Texture))
imagePath.s= OpenFileRequester("ouvre image", "d:\", "*mp|*.jpg|*.png", 1 )
If LoadImage(#image,imagePath.s)
ResizeImage( #image,ImageWidth(#image)/10,ImageHeight(#image)/10)
Else
MessageRequester("erreur","l'image ne se charge pas ! ")
End
Endif
CreateCube(#mesh, 1) ; creer un mesh defaut
id_entity=CreateEntity(#pb_any, MeshID(#mesh), MaterialID(#material))
SetEntityMaterial(id_entity, MaterialID(#material))
ScaleEntity(id_entity, 1, 4,1)
StartDrawing(ImageOutput(#image))
compteur=0
For y=1 to ImageHeight(#image)-1
For x=1 to ImageWidth(#image)-1
coul= Point(x,y)
coul_hauteur=255-(red(coul)+green(coul)+blue(coul))/3
compteur=compteur+1
If coul_hauteur>10 or coul_hauteur< -10
CopyEntity(id_entity, compteur)
ScaleEntity(compteur, 1, coul_hauteur/100,1) ;<<<<<<<<<<<<< a activer pour avoir le relief dans l'image or desactive this ... for no 3D effect in picture
MoveEntity(compteur, X, 1, y )
material=CreateMaterial(#Pb_any, TextureID(#Texture))
SetEntityMaterial(id_entity, MaterialID(material))
SetMaterialColor(material,#PB_Material_AmbientColor, coul)
Endif
Next x
Next y
StopDrawing()
DisableMaterialLighting(#material, 1)
SetMaterialColor(#material, #PB_Material_AmbientColor, RGB(100, 100, 100))
SetMaterialColor(#material, #PB_Material_SpecularColor, RGB(255, 255, 255))
CreateLight(0, RGB(0,0,255), 100.0, 0, 0)
SetLightColor(0, #PB_Light_SpecularColor, RGB(255, 0, 0))
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 50, 40, 150)
CameraBackColor(0, RGB(255, 255, 255))
Repeat
Screen3DEvents()
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_PageDown)
KeyZ = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_PageUp)
KeyZ = #CameraSpeed
Else
KeyZ = 0
EndIf
EndIf
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX,KeyZ, KeyY)
RenderWorld()
Screen3DStats()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End