# PureBasic Forum

 It is currently Mon May 25, 2020 8:41 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 12 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Plotting in 3D _ BiomorphsPosted: Tue Jan 29, 2013 9:46 am

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1403
the new introduction of #PB_Mesh_PointList for the CreateMesh function enable us to plot points in the three dimension the easy way so we can use ;
MeshVertexPosition(x, y, z)
MeshVertexColor(RGB(255,0,0))
this is demonstrated in the official example MeshManual2.pb in Examples\3D folder. it can be used to plot galaxies in 3D and the stars clusters inside it .
i will use this sort of plotting to plot the Biomorph 2D in 3D (a fractal creature) so we can rotate it and looking to it from different angles, the algorithm used from the http://www.madteddy.com/biomorph.htm , the site may be closed so look at its copy at WebArchive... to see more variations.
for the keys usage look the title bar, to manual or automatic rotation, scaling, up, down, near, far movements.
i have used also the ogre mesh viewer posted recently...
save the program to Examples\3D folder
More ideas are welcome

Code:
Enumeration
#MESH
#TEX_plane
#MAT
#MAT_plane
#plane
#LIGHT
#CAMERA_ONE
#BUTTON
#mainwin
EndEnumeration
;constants for the biomorph function
#constreal = 0.5
#constimag = 0
#screenheight = 500
#screenwidth = 500

Quit.b = #False
rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 2.2: depth.f=0

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "PgUp PgD scale mesh..Arrows for rotation, space: stop/rotate,  QA Up/Down, WS far/near", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#BUTTON, 0, DesktopHeight(0)-60, 60, 30, "rotate/stop")

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-70, 0, 0, 0)

InitKeyboard()
SetFrameRate(60)

Parse3DScripts()

CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf

SkyDome("clouds.jpg", 100) ;for blue color background

;- Mesh Stars
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #False)

SetMeshMaterial(1, MaterialID(0))
Global Stars = CreateNode(#PB_Any)
AttachNodeObject(Stars, MeshID(1))
Procedure Biomorph()
aspectratio.f = #screenwidth / #screenheight
ymax.f = 10
ymin.f = -ymax
xmax.f = ymax * aspectratio
xmin.f = -xmax
ilimit.l = #screenheight - 1
jlimit.l = #screenwidth - 1
x.f: y.f: x0.f: y0.f: xx.f: yy.f
xmax.f = ymax * aspectratio

For i = 0 To ilimit
For j = 0 To jlimit
x0 = xmin + (xmax - xmin) * j / jlimit
y0 = -ymin - (ymax - ymin) * i / ilimit
x = x0
y = y0
For n = 1 To 100
xx = x * (x * x - 3 * y * y) + #constreal:   ; THIS Line And the Next give the cube
yy = y * (3 * x * x - y * y) + #constimag: ; of the Number, plus a constant
x = xx
y = yy
If Abs(x) > 10 Or Abs(y) > 10 Or x * x + y + y > Pow(10,2)
n = 100
EndIf
Next n
If Abs(x) < 10 Or Abs(y) < 10

;Plot(j,i, RGB(0,0,0))
MeshVertexPosition(x0, y0, 0)
MeshVertexColor(RGB(0,0,0))

Else

;Plot(j,i, RGB(255, 255, 255 ))
MeshVertexPosition(x0, y0, 0)
MeshVertexColor(RGB(255,255,0))

EndIf

Next j
Next i
FinishMesh(#False)

EndProcedure

Biomorph()  ; calling the biomorph generator function
;Main loop
Repeat
Event = WindowEvent()
Case #BUTTON
If rot = 0
rot = 1
rotx= rotx0:roty=roty0:rotz=rotz0 ; restore rotation status
stopFlag = 1

Else
rot = 0
rotx0= rotx:roty0=roty:rotz0=rotz ;back up rotation status
rotx=0:roty=0:rotz=0
stopFlag = 0

EndIf

EndSelect
EndIf
If stopFlag=1
x + rotx
y + roty
z + rotz
EndIf

RotateNode(Stars, x, y, z)

RenderWorld()
FlipBuffers()

ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)  ; rotate left
rotx=1:roty=0:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Down) ; rotate right
rotx=-1:roty=0:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Right)   ; rotate up
rotx=0:roty=1:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Left) ; rotate down
rotx=0:roty=-1:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
EndIf

If KeyboardPushed(#PB_Key_PageUp) ; scale up model
xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
ScaleNode(Stars,xs,ys,zs)

ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
xs = 0.9:ys = 0.9:zs= 0.9
ScaleNode(Stars,xs,ys,zs)

EndIf
If KeyboardPushed(#PB_Key_Q) ; up move
up + 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_A) ; down move
up - 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_W) ; forward move
depth - 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_S) ; inward move
depth + 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)

EndIf
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf

Until Quit = #True Or Event = #PB_Event_CloseWindow

PS: the figure are more realistic when we don't plot the lines 104-105 (ie the yellow colored dots)
MeshVertexPosition(x0, y0, 0)
MeshVertexColor(RGB(255,255,0))
so comment it to see the following figure:

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Thu Jan 31, 2013 5:50 pm

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1403
So we can save the mesh as a file from what have been created in the above post even it is just points. how is this possible, i have no idea since i know the mesh composed from triangles which are made from connected vertices.

reported here ... that to Create an entity we need FinishMesh(#True).
the procedure is this:
CreateMesh(1, #PB_Mesh_PointList, #True)
fractal algorithm ...
MeshVertexPosition(x0, y0, 0)
MeshVertexColor(RGB(0,0,0))
FinishMesh(#True)
CreateEntity(1, MeshID(1), MaterialID(0))
ScaleEntity(1,0.3,0.3,0.3)
MoveEntity(1,-2,1.5,-2)

CreateMesh(2, #PB_Mesh_PointList, #True)
CreateEntity(2, MeshID(1), MaterialID(0))
ScaleEntity(2,0.1,0.1,0.1)
MoveEntity(2,2,1.5,2)
SaveMesh(1, "biomorph.mesh")
you can view the model using djes model viewer or my windows model viewer in this page viewtopic.php?f=36&t=51163
i have used the mesh 1 for entitiy 2 until we are able to use CopyMesh in the next PB beta, it is fixed as reported here ...

there is a tiny problem , i can't view the model biomorph.mesh with OgreMeshy, nor with Show Mesh, only with purebasic posted viewers. (Edit: we can also view those meshes with OgreMax viewers i have tried the winviewer http://www.ogremax.com/downloads )
save the file to Examples\3D and when run look the biomorph.mesh in the same folder. you can texture the model to appear as a sunflower using LoadTexture.
Code:
Enumeration
#MESH
#TEX_plane
#MAT
#MAT_plane
#plane
#LIGHT
#CAMERA_ONE
#mainwin
EndEnumeration
#constreal = 0.5
#constimag = 0
#screenheight = 500
#screenwidth = 500
#listPoints = 1

Quit.b = #False

rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 2.2: depth.f=0

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "Biomorph _ then save to *.mesh file", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-70, 0, 0, 0)

InitKeyboard()
SetFrameRate(60)

Parse3DScripts()

CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf

SkyDome("clouds.jpg", 100) ;for blue color background

;- Mesh Stars
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #True)

SetMeshMaterial(1, MaterialID(0))

aspectratio.f = #screenwidth / #screenheight
ymax.f = 10
ymin.f = -ymax
xmax.f = ymax * aspectratio
xmin.f = -xmax
ilimit.l = #screenheight - 1
jlimit.l = #screenwidth - 1
x.f: y.f: x0.f: y0.f: xx.f: yy.f
xmax.f = ymax * aspectratio

For i = 0 To ilimit
For j = 0 To jlimit
x0 = xmin + (xmax - xmin) * j / jlimit
y0 = -ymin - (ymax - ymin) * i / ilimit
x = x0
y = y0
For n = 1 To 100
xx = x * (x * x - 3 * y * y) + #constreal:   ; THIS Line And the Next give the cube
yy = y * (3 * x * x - y * y) + #constimag: ; of the Number, plus a constant
x = xx
y = yy
If Abs(x) > 10 Or Abs(y) > 10 Or x * x + y + y > Pow(10,2)
n = 100
EndIf
Next n
If Abs(x) < 10 Or Abs(y) < 10

;Plot(j,i, RGB(0,0,0))
MeshVertexPosition(x0, y0, 0)
MeshVertexColor(RGB(0,0,0))

EndIf

Next j
Next i
FinishMesh(#True )
CreateEntity(1, MeshID(1), MaterialID(0))
ScaleEntity(1,0.3,0.3,0.3)
MoveEntity(1,-2,1.5,-2)

CreateMesh(2, #PB_Mesh_PointList, #True)

CreateEntity(2, MeshID(1), MaterialID(0))
ScaleEntity(2,0.1,0.1,0.1)
MoveEntity(2,2,1.5,2)
SaveMesh(1, "biomorph.mesh")

;Main loop
Repeat
Event = WindowEvent()

RenderWorld()
FlipBuffers()

ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf

Until Quit = #True Or Event = #PB_Event_CloseWindow

Last edited by applePi on Tue Feb 05, 2013 9:23 am, edited 2 times in total.

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Thu Jan 31, 2013 5:58 pm
 User

Joined: Wed May 05, 2004 8:21 pm
Posts: 36
Location: An outer spiral arm of the Milky Way
That really is awesome and shows some useful techniques , thanks for sharing and for the link to Mad Teddy's site too!

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Fri Feb 01, 2013 3:44 pm

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1403
thank you fiver
i want to add more entertainment, this is to read image pixels colors and attach it to the vertices , i will use einstein picture:

just convert it to BMP file
then just like we have done with biomorph fractal we do here. but note that if you want to save it to mesh file (uncomment SaveMesh(1, "einstein.mesh")) and then displaying it by Ogre Mesh Viewer it will show only uniform dots, because we have read all image pixels. in this case we may use LoadTexture einstein.bmp to see einstein resurrected.
i will search if there is a program to convert image to lines with voids between.
save the program to examples\3D together with einstein.bmp
the program output like this:

PS: Edit: i have found one way, save the picture from the windows paint to monochrome bitmap, and the picture will contains only black and white,
change the corresponding code to :
If Point( x, y )<> 16777215 ; ie exclude white color
MeshVertexPosition(x, y, 0)
MeshVertexColor(Point( x, y ))
EndIf

and the output will be like this,

and the produced einstein.mesh can be seen by the model viewer without the need to apply eintein.bmp over it.
needs PB v5.10b+
Code:
Enumeration
#MESH
#TEX_plane
#MAT
#MAT_plane
#plane
#LIGHT
#CAMERA_ONE
#mainwin
EndEnumeration
#constreal = 0.5
#constimag = 0
#screenheight = 500
#screenwidth = 500
#listPoints = 1

Quit.b = #False

rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 2.2: depth.f=0

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), " ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-70, 0, 0, 0)

InitKeyboard()
SetFrameRate(60)

Parse3DScripts()

CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf

SkyDome("clouds.jpg", 100) ;for blue color background

;- Mesh Stars
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #True)

SetMeshMaterial(1, MaterialID(0))
Procedure test()
Define image_id.i

image_id = LoadImage( #PB_Any, "einstein.bmp" )
Dim image_pixel_data.b( ImageWidth(image_id), ImageHeight(image_id) )

StartDrawing( ImageOutput( image_id ) )
For y = 0 To ImageHeight(image_id) - 1
For x = 0 To ImageWidth(image_id) - 1
MeshVertexPosition(x, y, 0)
MeshVertexColor(Point( x, y ))

Next x
Next y
StopDrawing()
FreeImage(image_id)
FinishMesh(#True )

EndProcedure

test()

CreateEntity(1, MeshID(1), MaterialID(0))
ScaleEntity(1,0.02,0.02,0.02)
RotateEntity(1, -180, 0, 0 )
MoveEntity(1,-5,4.0,-2)

CreateMesh(2, #PB_Mesh_PointList, #True)

CreateEntity(2, MeshID(1), MaterialID(0))
ScaleEntity(2,0.01,0.01,0.01)
RotateEntity(2, -180, -60, 0 )
MoveEntity(2,1,3.0,2)
;SaveMesh(1, "einstein.mesh")

;Main loop
incr.f=0.7
Repeat
Event = WindowEvent()
y.f+incr
If y>80 Or y<-10:incr=-1*incr:EndIf
RotateEntity(1, -180, y, 0)
RenderWorld()
FlipBuffers()

ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf

Until Quit = #True Or Event = #PB_Event_CloseWindow

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Tue Jan 07, 2014 3:38 am
 Enthusiast

Joined: Mon Aug 19, 2013 3:28 pm
Posts: 267
I've been working on the point cloud PLY format for a while now, and I need some assistance, everybody! I have successfully gotten this demo to write out each Vertex X & Y coordinate, but the problem is with the rest of the PLY file. I don't know how to add RGB to this demo PLY file as well as getting it to open in Meshlab... If you can do both these things, that would be great, and one step closer to turning a 2D heightmap / monochrome, into a 3D model.

Einstein_Revived.pb:

Code:
Enumeration
#MESH
#TEX_plane
#MAT
#MAT_plane
#plane
#LIGHT
#CAMERA_ONE
#mainwin
EndEnumeration
#constreal = 0.5
#constimag = 0
#screenheight = 500
#screenwidth = 500
#listPoints = 1

Quit.b = #False

rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 2.2: depth.f=0

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, 800, 600, " ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, WindowWidth(#mainwin), WindowHeight(#mainwin)-70, 0, 0, 0)

InitKeyboard()
SetFrameRate(60)

Parse3DScripts()

CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf

SkyDome("clouds.jpg", 100) ;for blue color background

;- Mesh Stars
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #True)

SetMeshMaterial(1, MaterialID(0))
Procedure test()

Define image_id.i

image_id = LoadImage( #PB_Any, "einstein.bmp" )
Dim image_pixel_data.b( ImageWidth(image_id), ImageHeight(image_id) )

;Write PLY file
ply_write = CreateFile(#PB_Any, "einstein.ply")

WriteStringN(ply_write, "ply")
WriteStringN(ply_write, "")

;Write PLY file type - is it ASCII or Binary, and what format version number?
WriteStringN(ply_write, "format ascii 1.0")
WriteStringN(ply_write, "")

WriteStringN(ply_write, "comment blah")
WriteStringN(ply_write, "")

;Define Vertex Element, currently "0" of them in file
WriteStringN(ply_write, "element vertex 0")
WriteStringN(ply_write, "")

;X coordinate of Vertex point
WriteStringN(ply_write, "property float x")
;Y coordinate of Vertex point
WriteStringN(ply_write, "property float y")
;Z coordinate of Vertex point (if any)
WriteStringN(ply_write, "property float z")
WriteStringN(ply_write, "")

;There are 0 faces in the file
WriteStringN(ply_write, "element face 0")
WriteStringN(ply_write, "")

;Property list (uchar int vertex_index { "vertex_indices" is a list of ints }
WriteStringN(ply_write, "property list uchar int vertex_index")
WriteStringN(ply_write, "")

;Write PLY footer
WriteStringN(ply_write, "")

;ply
;format ascii 1.0           { ascii/binary, format version number }
;comment made by Greg Turk  { comments keyword specified, like all lines }
;comment this file is a cube
;element vertex 8           { Define "vertex" element, 8 of them in file }
;property float x           { vertex contains float "x" coordinate }
;property float y           { y coordinate is also a vertex property }
;property float z           { z coordinate, too }
;element face 6             { there are 6 "face" elements in the file }
;property List uchar int vertex_index { "vertex_indices" is a List of ints }
;0 0 0                      { start of vertex List }
;0 0 1
;0 1 1
;0 1 0
;1 0 0
;1 0 1
;1 1 1
;1 1 0
;4 0 1 2 3                  { start of face List }
;4 7 6 5 4
;4 0 4 5 1
;4 1 5 6 2
;4 2 6 7 3
;4 3 7 4 0

StartDrawing( ImageOutput( image_id ) )

For y = 0 To ImageHeight(image_id) - 1

For x = 0 To ImageWidth(image_id) - 1

If Point( x, y ) <> 16777215 ; ie exclude white color

MeshVertexPosition(x, y, 0)
MeshVertexColor(Point( x, y ))

;Start of vertex list
WriteStringN(ply_write, Str(Int(x))+" "+Str(Int(y))+" "+Str(Int(0)))

EndIf

Next x

Next y

WriteStringN(ply_write, "")

For y = 0 To ImageHeight(image_id) - 1

For x = 0 To ImageWidth(image_id) - 1

If Point( x, y ) <> 16777215 ; ie exclude white color

;Start of face list
WriteStringN(ply_write, Str(Int(0))+" "+Str(Int(0))+" "+Str(Int(0))+" "+Str(Int(0))+" "+Str(Int(0)))

EndIf

Next x

Next y

WriteStringN(ply_write, "")

StopDrawing()

FreeImage(image_id)

DeleteFile("einstein.ply")

FinishMesh(#True )

EndProcedure

test()

CreateEntity(1, MeshID(1), MaterialID(0))
ScaleEntity(1,0.02,0.02,0.02)
RotateEntity(1, -180, 0, 0 )
MoveEntity(1,-5,4.0,-2)

CreateMesh(2, #PB_Mesh_PointList, #True)

CreateEntity(2, MeshID(1), MaterialID(0))
ScaleEntity(2,0.01,0.01,0.01)
RotateEntity(2, -180, -60, 0 )
MoveEntity(2,1,3.0,2)
SaveMesh(1, "einstein.mesh")

;Main loop
incr.f=0.7
Repeat
Event = WindowEvent()
y.f+incr
If y>80 Or y<-10:incr=-1*incr:EndIf
RotateEntity(1, -180, y, 0)
RenderWorld()
FlipBuffers()

ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf

Until Quit = #True Or Event = #PB_Event_CloseWindow

Einstein.ply:

http://pastebin.com/zg8uqp9a

This is the standard "PLY" Polygon format:

http://www.dcs.ed.ac.uk/teaching/cs4/ww ... b/ply.html

Code:
Another Example
Here is another cube definition:
ply
format ascii 1.0
comment author: Greg Turk
comment object: another cube
element vertex 8
property float x
property float y
property float z
property red uchar { start of vertex color }
property green uchar
property blue uchar
element face 7
property list uchar int vertex_index { number of vertices for each face }
element edge 5 { five edges in object }
property int vertex1 { index to first vertex of edge }
property int vertex2 { index to second vertex }
property uchar red { start of edge color }
property uchar green
0 0 0 255 0 0 { start of vertex list }
0 0 1 255 0 0
0 1 1 255 0 0
0 1 0 255 0 0
1 0 0 0 0 255
1 0 1 0 0 255
1 1 1 0 0 255
1 1 0 0 0 255
3 0 1 2 { start of face list, begin with a triangle }
3 0 2 3 { another triangle }
4 7 6 5 4 { now some quadrilaterals }
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0
0 1 255 255 255 { start of edge list, begin with white edge }
1 2 255 255 255
2 3 255 255 255
3 0 255 255 255
2 0 0 0 0 { end with a single black line }

This file specifies a red, green and blue value for each vertex. To illustrate the variable-length nature of vertex_index, the first two faces of the object are triangles instead of a single square. This means that the number of faces in the object is 7. This object also contains a list of edges. Each edge contains two pointers to the vertices that delinate the edge. Each edge also has a color. The five edges defined above were specified so as to highlight the two triangles in the file. The first four edges are white, and they surround the two triangles. The final edge is black, and it is the edge that separates the triangles.

Thank You once again for your assistance, all!

Have a wonderful evening!

Mythros

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Tue Jan 07, 2014 10:37 am

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1403
i have done some research for the ply files
for your file einstein.ply : needs some changes to be displayed in mesh lab like this

element vertex 11024
use "vertex_indices" and not vertex_index:
property list uchar int vertex_indices
Edit: error, it works with the 2 version whether vertex_index or vertex_indices
attached the file again below
it seems the color are done in Ply files like this:
uf you have used:
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue

then there should be info for the vertex something like this: 6 numbers
0 0 1 0 255 0
means point(0,0,1) have green color rgb(0,255,0)
experiment also with: property uchar alpha
attached a working black/white einstein.ply and a working colored cube
http://www.2shared.com/file/6sX1CLyw/ply_models.html
the models in site http://graphics.stanford.edu/data/3Dscanrep/ are too big and it is binary and if we have loaded it with meshLab export it again to stanford polygon ply format which are text and not binary (too big , i found the editor EmEditor the most convenient to open, just right click and choose emeditor to open.
so we can have einstein.ply with color and even with alpha. use my post here http://www.forums.purebasic.com/english ... 36&t=57555
to cast the ambassadors picture to a colored mesh. i hope it will work i will try that later

Last edited by applePi on Wed Jan 08, 2014 7:24 am, edited 1 time in total.

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Tue Jan 07, 2014 9:34 pm

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1403
Edited Jan 08
change your code like the following and you will get a ply file with color can be opened in MeshLab

i have used rd.f = Red(Point( x, y )) to get the red components of a point and so the green and the blue.
the line element vertex 20179 should represent the points we want to draw.
the property uchar alpha seems don't work
use this picture but change it to BMP file

the code display this picture

Code:
Enumeration
#MESH
#TEX_plane
#MAT
#MAT_plane
#plane
#LIGHT
#CAMERA_ONE
#mainwin
EndEnumeration
#constreal = 0.5
#constimag = 0
#screenheight = 500
#screenwidth = 500
#listPoints = 1

Quit.b = #False

rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 2.2: depth.f=0

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, 800, 600, " ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, WindowWidth(#mainwin), WindowHeight(#mainwin)-70, 0, 0, 0)

InitKeyboard()
SetFrameRate(60)

CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf

SkyDome("clouds.jpg", 100) ;for blue color background

;- Mesh Stars
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #True)

SetMeshMaterial(1, MaterialID(0))
Procedure test()

Define image_id.i

image_id = LoadImage( #PB_Any, "mickey4.bmp" )
Dim image_pixel_data.b( ImageWidth(image_id), ImageHeight(image_id) )

;Write PLY file
ply_write = CreateFile(#PB_Any, "micky.ply")

WriteStringN(ply_write, "ply")

;Write PLY file type - is it ASCII or Binary, and what format version number?
WriteStringN(ply_write, "format ascii 1.0")

WriteStringN(ply_write, "comment blah")

;Define Vertex Element, currently "0" of them in file
WriteStringN(ply_write, "element vertex 20179")

;X coordinate of Vertex point
WriteStringN(ply_write, "property float x")
;Y coordinate of Vertex point
WriteStringN(ply_write, "property float y")
;Z coordinate of Vertex point (if any)
WriteStringN(ply_write, "property float z")
;WriteStringN(ply_write, "")
WriteStringN(ply_write, "property uchar red")
WriteStringN(ply_write, "property uchar green")
WriteStringN(ply_write, "property uchar blue")
WriteStringN(ply_write, "property uchar alpha")
;There are 0 faces in the file
WriteStringN(ply_write, "element face 0")

;Property list (uchar int vertex_index { "vertex_indices" is a list of ints }
WriteStringN(ply_write, "property list uchar int vertex_index")

;Write PLY footer

;ply
;format ascii 1.0           { ascii/binary, format version number }
;comment made by Greg Turk  { comments keyword specified, like all lines }
;comment this file is a cube
;element vertex 8           { Define "vertex" element, 8 of them in file }
;property float x           { vertex contains float "x" coordinate }
;property float y           { y coordinate is also a vertex property }
;property float z           { z coordinate, too }
;property uchar red
;property uchar green
;property uchar blue
;property uchar alpha
;element face 6             { there are 6 "face" elements in the file }
;property List uchar int vertex_index { "vertex_indices" is a List of ints }
;0 0 0                      { start of vertex List }
;0 0 1
;0 1 1
;0 1 0
;1 0 0
;1 0 1
;1 1 1
;1 1 0
;4 0 1 2 3                  { start of face List }
;4 7 6 5 4
;4 0 4 5 1
;4 1 5 6 2
;4 2 6 7 3
;4 3 7 4 0

StartDrawing( ImageOutput( image_id ) )

For y = 0 To ImageHeight(image_id) - 1

For x = 0 To ImageWidth(image_id) - 1

If Point( x, y ) <> RGB(255,128,64) ; ie exclude white color
numOfPoints + 1
MeshVertexPosition(x, y, 0)
MeshVertexColor(Point( x, y ))
rd.f = Red(Point( x, y ))
gr.f = Green(Point( x, y ))
bl.f = Blue(Point( x, y ))

;Start of vertex list
WriteStringN(ply_write, Str(Int(x))+" "+Str(Int(y))+" "+Str(Int(0))+" "+Str(Int(rd))+" "+Str(Int(gr))+" "+Str(Int(bl))+" "+Str(Int(200)))

EndIf

Next x

Next y
Debug "mumber of points = " + Str(numOfPoints)
WriteStringN(ply_write, "")

StopDrawing()

FreeImage(image_id)

;DeleteFile("micky.ply")

FinishMesh(#True )

EndProcedure

test()

CreateEntity(1, MeshID(1), MaterialID(0))
ScaleEntity(1,0.02,0.02,0.02)
RotateEntity(1, -180, 0, 0 )
MoveEntity(1,-5, 4.5, -2)

CreateMesh(2, #PB_Mesh_PointList, #True)

CreateEntity(2, MeshID(1), MaterialID(0))
ScaleEntity(2,0.01,0.01,0.01)
RotateEntity(2, -180, -60, 0 )
MoveEntity(2,1,3.0,2)
SaveMesh(1, "micky_mesh.mesh")

;Main loop
incr.f=0.7
Repeat
Event = WindowEvent()
y.f+incr
If y>80 Or y<-10:incr=-1*incr:EndIf
RotateEntity(1, -180, y, 0)
RenderWorld()
FlipBuffers()

ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf

Until Quit = #True Or Event = #PB_Event_CloseWindow

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Fri Jan 10, 2014 8:57 pm
 Enthusiast

Joined: Mon Aug 19, 2013 3:28 pm
Posts: 267
Ok, so now how do we give it depth based on the RGB(A?) values of each pixel?

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Fri Jan 10, 2014 10:50 pm
 Enthusiast

Joined: Sun Jul 29, 2012 10:33 pm
Posts: 750
Location: United States
If you want to convert an image to a 3d model. I'd recommend converting your image to gray scale which will make calculating the depth a lot easier.
I usually have the black pixels equal 0 and white pixels equal the max height.

This how the I do the calculation.
Height=(MaxHeight/255)*GrayValue

If you have a pixel with a gray value of 200 and your max height is 30 units. The equation would go like this.
Height=(30/255)*200
So, a pixel with a gray value of 200 would be at a height of 23.529 units.
I believe this is how most terrain generators work. At least this is how I built mine.

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Mon Jan 13, 2014 4:56 pm
 Enthusiast

Joined: Mon Aug 19, 2013 3:28 pm
Posts: 267
Thanks, but this doesn't really help me... @applepi, how would we make a photo into a complete 3D model?

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Mon Jan 13, 2014 7:51 pm

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1403
i don't know how to do that, sorry Mythros . it is evident that this topic is a science by its own , how you will interpret a one picture to 3D model other than the terrain like topography as suggested by Samuel, this is impossible, we will need at least 2 pictures taken from 2 places, then we will need a mathematician to interpret the 2 matrices.
they said ((The software reconstructs a 3D model with corresponding texture from a 2D movie file. The resulting model can be imported in any 3D application like Blender, ZBrush©, Maya© or 3DS Max©))
i have tried it but i have failed to get it to work, if you succeed then please describe what to do step by step may be in a new thread to be known for all. there is no help at all in the program.

but i see in the left margin of the site http://scandraid.sourceforge.net/ a lot of programs and some are using laser pointers. i have blurred vision in my eyes from a few days , so i will follow the subject later.

Top

 Post subject: Re: Plotting in 3D _ BiomorphsPosted: Tue Jan 14, 2014 12:00 am
 Enthusiast

Joined: Mon Aug 19, 2013 3:28 pm
Posts: 267
Edit:

Wrong Topic

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 12 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 6 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite