Well ok, yes. In THAT way, it DOES matter. HOWEVER. I think if we mess with the below example, we should be able to just remove SOME of the non-needed points, and connect the points as triangles, that DO matter.
For instance, I have messed with a demo in order to **TRY** and create depth, and I actually succeeded 75%.
I would possibly like to see if there is a way to create the effect of taking a cloth, and putting it on an ordinary, every day object such as an apple. The cloth would then assume the shape of the apple, therefore, creating a 3d model out of the "2d" image. Let me know when you guys come up with something.
Without further adieu, here's the source:
Code: Select all
Declare DrawMatrix()
#Mode = 7 ; #Mode = 1 or #Mode = 7
Structure PointVertex
x.f
y.f
z.f
CompilerIf #Mode = 7
Size.f ;--- Only if Mode = 7
CompilerEndIf
Color.l;d3dcolor
EndStructure
ExamineDesktops()
MP_Graphics3D (DesktopWidth(0),DesktopHeight(0),0,3) ; Erstelle ein WindowsFenster #Window = 0
MP_Viewport(0,0,DesktopWidth(0),DesktopHeight(0)-5)
SetWindowTitle(0, "Pic_to_Mesh .. press Up, Down keys to move mesh forward/back | Left, Right keys to turn mesh left/right")
camera=MP_CreateCamera()
light=MP_CreateLight(2)
MP_LightSetColor (light, RGB(255,255,255))
texture2 = MP_CreateTextureColor(256, 256, MP_ARGB(0,255,255,255))
texture = MP_CreateTextureColor(256, 256, MP_ARGB(0,255,0,0))
plane = MP_CreatePlane(10, 10)
MP_EntitySetTexture(plane, texture2)
MP_RotateEntity(plane, 90, 0, 90)
MP_PositionEntity(plane, 0, -5, 0)
;MP_PositionCamera(camera, 0, 5, 20)
;MP_CameraLookAt(camera,0,0,0)
MP_PositionEntity(light, 0, 10, 20)
MP_EntityLookAt(light,0,0,0)
;==============================================================
UseJPEGImageDecoder()
; load image
Global image_id.i
image_id = LoadImage(#PB_Any, GetCurrentDirectory()+"woman.bmp")
;Dim image_pixel_data.b( ImageWidth(image_id), ImageHeight(image_id) )
Global size = Int(ImageWidth(image_id)*ImageHeight(image_id))
Global Entity= MP_CreatePrimitives (size, #Mode)
Global pointcloud_point_size.f = 1.50
DrawMatrix()
;==============================================================
MP_PositionEntity(light, 0 , 10, 10)
MP_EntityLookAt(light,0,0,0)
z.f=10
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
If MP_KeyDown(#PB_Key_Up)
z.f - 0.1
ElseIf MP_KeyDown(#PB_Key_Down)
z.f + 0.1
EndIf
If MP_KeyDown(#PB_Key_Left)
MP_TurnEntity(Entity,0, 1, 0)
ElseIf MP_KeyDown(#PB_Key_Right)
MP_TurnEntity(Entity,0, -1, 0)
EndIf
MP_PositionEntity(Entity, 0, 10, z)
MP_RenderWorld()
MP_Flip ()
Wend
Procedure DrawMatrix()
i=-1
*Memory = MP_GetMemPrimitives(Entity)
StartDrawing( ImageOutput( image_id ) )
For y = 0 To ImageHeight(image_id) - 1
For x = 0 To ImageWidth(image_id) - 1
r = Red(Point( x, y ))
g = Green(Point( x, y ))
b = Blue(Point( x, y ))
;r = MP_Red(Point( x, y ))
;g = MP_Green(Point( x, y ))
;b = MP_Blue(Point( x, y ))
i+1
*myvertex.PointVertex = *Memory + i * SizeOf(PointVertex)
*myvertex\x = x - ImageWidth(image_id)/2
*myvertex\y = y
If Y > ImageHeight(image_id)/2
*myvertex\z = (MP_Red(Point( x, y )-8))
EndIf
*myvertex\Size = pointcloud_point_size
*myvertex\color = MP_ARGB(0,r,g,b)
Next x
Next y
StopDrawing()
MP_ScaleEntity(Entity, 0.03, 0.03, 0.03)
;MP_MeshSetAlpha(Entity,2)
MP_PositionEntity(Entity, 0, 0, 0)
MP_RotateEntity(Entity,180,0,0)
MP_CloseMemPrimitives(Entity)
EndProcedure
I have also included the image I used:
Rename the above image to "woman.bmp" and make SURE that the file type is INDEED bitmap & not JPG.
Also, can someone tweak this code so that it gives depth to more than just half the image?
Thanks again, and I hope to continue this research with you guys!
Sincerely,
Mythros