accumulating mesh points gradualy
Posted: Sun Jul 19, 2015 2:33 pm
accumulating mesh points gradualy
to see the accumulation of points step by step (useful in ray tracing viewing), i suggest to plot 50000 points (or more) at once to a meaningless shapeless and unnoticed one point
then we save the contents of that mesh to an array:
after that we correct every MeshData(indx)\x|y|z item according to the desired formula such as the result of ray tracing or other things. then we save the corrected MeshData() to the mesh again with:
here the points does not accumulate in reality but it is completely new thicker or thinner mesh every time(compare with the previous example, press Z/X to increase or decrease mesh vertices).
to see the accumulation of points step by step (useful in ray tracing viewing), i suggest to plot 50000 points (or more) at once to a meaningless shapeless and unnoticed one point
Code: Select all
Global Dim MeshData.PB_MeshVertex(0)
For i=1 To 50000 ; just a shapeless mesh for the usage later
MeshVertexPosition(0,0,0) ; plotted to the same point 0,0,0
Next
FinishMesh(#True)Code: Select all
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)Code: Select all
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
Code: Select all
Enumeration
#sphere = 20
#machine
EndEnumeration
Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
RandomSeed(Random(100000, 1))
ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure
Global Dim MeshData.PB_MeshVertex(0)
#CameraSpeed = 1
Global indx
Global srcX.f = 0: Global srcZ.f = 10 : Global angle.f: Global randomize
Define.f KeyX, KeyY, MouseX, MouseY
Declare CreateMatrix()
Declare DrawMatrix()
ExamineDesktops()
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0,0,0,DesktopWidth(0), DesktopHeight(0),"mouse/arrow keys for the camera",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,DesktopWidth(0), DesktopHeight(0),1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/skybox.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
Global monitor=CreateSprite(#PB_Any,120,40)
;- Material
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
CreateMaterial(1, LoadTexture(1, "terrain_texture.jpg"))
CreateMaterial(2, LoadTexture(2, "clouds.jpg"))
;-Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,0,10,30, #PB_Absolute)
CameraLookAt(0, 5, 0, 0)
CameraBackColor(0, RGB(0, 0, 0))
;-Light
CreateLight(0, RGB(255, 255, 255), 20, 150, 120)
AmbientColor(RGB(90, 90, 90))
CreateCube(#machine, 2)
CreateEntity(#machine, MeshID(#machine), MaterialID(2), 0,1,20)
CreateSphere(#sphere, 4, 32,32)
;LoadMesh(#sphere, "Barrel.mesh");
;LoadMesh(#sphere, "PureBasic.mesh")
CreateEntity(#sphere, MeshID(#sphere), MaterialID(1), 0,0,0)
;ScaleEntity(#sphere, 0.2, 0.2, 1)
EntityPhysicBody(#sphere, #PB_Entity_StaticBody, 0)
;-Mesh
CreateMatrix()
Global srcX.f = 0: Global srcZ.f = 10
Global radius.f = Sqr(srcX*srcX+srcZ*srcZ) ; distance of lazer scanner machine from the center
Global vertTot
Repeat
WindowEvent()
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
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)
MouseY = -(MouseDeltaY()/10)
EndIf
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RotateEntity(0, 0, 0.5, 0, #PB_Relative)
If indx < 50000
DrawMatrix()
EndIf
indx+1
RenderWorld()
StartDrawing(SpriteOutput(monitor))
;DrawText(5,20,"FPS : "+Str(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
DrawText(5,5,"vertex = " + Str(indx))
StopDrawing()
DisplaySprite(monitor,0,0)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
End
;-Procedures
Procedure DrawMatrix()
angle.f + 0.5 ; the rotaion angle of the scanning machine
srcX = radius * Sin(Radian(angle)) ; formula for the circular motion
srcZ = radius * Cos(Radian(angle)) ; formula for the circular motion
MoveEntity(#machine, srcX, 2, srcZ, #PB_Absolute)
EntityLookAt(#machine, 0, 2, 0)
EntityFixedYawAxis(#machine, 1 , 0, 1, 0)
res = RayCollide(srcX, 2, srcZ, RandF(-4,4), RandF(-4,4), RandF(-4,4))
;res = RayCast(srcX, 2, srcZ, RandF(-4,4), RandF(-4,4), RandF(-4,4), -1)
If res
x.f = PickX(): y.f=PickY():z.f=PickZ()
CreateLine3D(11, EntityX(#machine), EntityY(#machine), EntityZ(#machine), RGB(0, 255, 0), x, y, z, RGB(0, 255, 0))
;Debug StrF(x)+" "+StrF(y)+" " +StrF(z)
MeshData(indx)\x = x
MeshData(indx)\y = y
MeshData(indx)\z = z
EndIf
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
For i=1 To 50000 ; just a shapeless mesh for the usage later
MeshVertexPosition(0,0,0) ; plotted to the same point 0,0,0
MeshVertexColor(RGB(255,255,0))
Next
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(0))
CreateEntity(0, MeshID(0), #PB_Material_None, 10,0,0)
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
EndProcedure
Code: Select all
Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
#CameraSpeed = 1
Global Nb=3000
Define.f KeyX, KeyY, MouseX, MouseY
Declare UpdateMatrix()
Declare CreateMatrix()
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
;- Material
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
;-Mesh
CreateMatrix()
;-Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,0,50,80, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, RGB(0, 0, 0))
;-Light
CreateLight(0, RGB(255, 255, 255), 20, 150, 120)
AmbientColor(RGB(90, 90, 90))
Repeat
Screen3DEvents()
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
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)
MouseY = -(MouseDeltaY()/10)
EndIf
If KeyboardPushed(#PB_Key_Z)
Nb+20
ElseIf KeyboardPushed(#PB_Key_X)
Nb-20
EndIf
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RotateNode(0, 0, 0.5, 0, #PB_Relative)
; Waves
UpdateMatrix()
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
;-Procedures
Procedure DrawMatrix()
For b=0 To Nb
;les coordonnées de vertex
MeshVertexPosition(RandF(-4,4), RandF(0,8), RandF(-4,4))
MeshVertexColor(RGB(255,255,0))
Next b
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
DrawMatrix()
FinishMesh(#False)
SetMeshMaterial(0, MaterialID(0))
CreateNode(0)
AttachNodeObject(0, MeshID(0))
ScaleNode(0, 2, 2, 2)
EndProcedure
Procedure UpdateMatrix()
UpdateMesh(0, 0)
DrawMatrix()
FinishMesh(#False)
EndProcedure