image to scene

Everything related to 3D programming
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

image to scene

Post by dobro »

you take a 800x600 image (not too big)
like this one
Image

you start the code below

you get this:
Image

or this :
Image

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
no relief in the image, only around
Image



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

Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: image to scene

Post by Fig »

Nicely done !
On my computer, I have to set antialisianing mode to None on screen3drequester,
though.



Un effet très sympa sympa, vu les gifs! :D
par contre ça ne se lance pas chez moi. Après l'écran screen3drequester, plus rien... Je fais quelque chose mal, peut être... :|

edit: OK, j'ai trouvé, je laissais les paramètres par défaut alors que je devais retirer l'anti aliasing mode manifestement. Maintenant ça fonctionne ! :D
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
Post Reply