just follow the cylinder base vertices, while it is moving and rotating , record its positions, and do MeshVertexPosition(x,y,z)
this was not possible until DK_PETER have posted a great idea , look here
viewtopic.php?f=36&t=61455#p524313
in short: we position a new node at every vertex of a mesh, and then we attach all the nodes and the entity itself to a main node. then we move/rotate the main node, at the same time we commit MeshVertexPosition at every node x,y,z positions
what to do ?: press Z to move the cylinder and to create new vertices. press Space to finalise the mesh and to triangulate the mesh. i have used the procedure in setmeshdata.pb to weave the triangles
Note: while you press Z to create new vertices you see points , it is just a visual representation of the vertices we still making and can't be displayed yet, it is borrowed from a points cloud we create for this purpose only.
Happy the Longest Moon Eclipse of the Century today
Code: Select all
Enumeration
#PointsCloud
#cyl
#Tube
EndEnumeration
Declare DrawTriangles()
Global Dim MeshData.PB_MeshVertex(0)
#CameraSpeed = 1
Global indx, mainnode, NbZ, NbX, rot, flag, meshflag
NbX = 15
Global srcX.f = 0: Global srcY.f = 0 : 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)," Z: make new vertices,...., Space: finish the mesh .............. 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/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
Global monitor=CreateSprite(#PB_Any,120,40)
;- Material
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
MaterialCullingMode(0, #PB_Material_NoCulling )
CreateMaterial(1, LoadTexture(1, "terrain_texture.jpg"))
CreateMaterial(2, LoadTexture(2, "clouds.jpg"))
MaterialShadingMode(2, #PB_Material_Wireframe)
MaterialCullingMode(2, #PB_Material_NoCulling )
;-Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,0,20,50, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, RGB(0, 0, 0))
CameraRenderMode(0, #PB_Camera_Wireframe)
;-Light
CreateLight(0, RGB(255, 255, 255), 20, 150, 120)
AmbientColor(RGB(90, 90, 90))
CreateCylinder(#cyl, 2, 2, NbX, 2, 0)
CreateEntity(#cyl, MeshID(#cyl), MaterialID(2))
;-create a mesh of points lists , just to give a visual positions of the vertices you make with MeshVertexPosition
CreateMatrix()
;get the mesh data of a cylinder
GetMeshData(#cyl,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#cyl)-1)
;create a master node and attach the cylinder to it
mainnode = CreateNode(#PB_Any,0, 0, 0)
AttachNodeObject(mainnode, EntityID(#cyl))
;create number of nodes = number of vertices of a cylinder base
Global Dim n(NbX)
For i = 0 To NbX : n(i) = CreateNode(#PB_Any) : Next
For i = 0 To NbX
;move the nodes to the cylinder base vertices coordinates
MoveNode(n(i),MeshData(i)\x, MeshData(i)\y, MeshData(i)\z, #PB_Absolute)
AttachNodeObject(mainnode, NodeID(n(i)))
Next
Global.f x,y,z
Global indx
CreateMesh(#Tube, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
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
If KeyboardPushed(#PB_Key_Z)
If flag = 1:Goto ext: EndIf
meshflag = 1
GetMeshData(#PointsCloud,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#PointsCloud)-1)
angle.f + 5 ; the rotaion angle of the scanning machine
srcX = 1 * Sin(Radian(angle)) ; formula for the circular motion
srcY = 1 * Cos(Radian(angle)) ; formula for the circular motion
RotateNode(mainnode, 0, 0, -5, #PB_Relative);#PB_Absolute)
MoveNode(mainnode, srcX,srcY,0,#PB_Relative);#PB_Absolute)
For i=0 To NbX
MeshVertexPosition(NodeX(n(i)), NodeY(n(i)), NodeZ(n(i)))
MeshData(indx)\x = NodeX(n(i))
MeshData(indx)\y = NodeY(n(i))
MeshData(indx)\z = NodeZ(n(i))
indx+1
Next
NbZ+1
SetMeshData(#PointsCloud,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#PointsCloud)-1)
ext:
EndIf
If KeyboardReleased(#PB_Key_Space)
If meshflag = 0: Goto exit:EndIf
If flag = 1: Debug "sorry the mesh is finalized": Goto exit: EndIf
HideEntity(#cyl, 1)
HideEntity(#PointsCloud, 1)
DrawTriangles()
rot = 1
flag = 1
exit:
EndIf
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)
MouseY = -(MouseDeltaY()/10)
EndIf
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
If flag = 1
RotateEntity(#Tube, 0, rot/2, 0, #PB_Relative)
EndIf
RenderWorld()
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(#cyl, srcX, 2, srcZ, #PB_Absolute)
EntityLookAt(#cyl, 0, 2, 0)
EntityFixedYawAxis(#cyl, 1 , 0, 1, 0)
MeshData(indx)\x = x
MeshData(indx)\y = y
MeshData(indx)\z = z
EndProcedure
Procedure CreateMatrix()
CreateMesh(#PointsCloud, #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,255))
Next
FinishMesh(#True)
SetMeshMaterial(#PointsCloud, MaterialID(0))
CreateEntity(#PointsCloud, MeshID(#PointsCloud), #PB_Material_None, 0,0,0)
EndProcedure
Procedure DrawTriangles()
Protected.l a, b, c, Nb
Protected.w P1, P2, P3, P4
NbZ-1
Nb=NbX+1
For b=0 To NbZ-1
For a=0 To NbX-1
P1=a+(b*Nb)
P2=P1+1
P3=a+(b+1)*Nb
P4=P3+1
MeshFace(P3, P2, P1)
MeshFace(P2, P3, P4)
Next
Next
FinishMesh(#True)
SetMeshMaterial(#Tube, MaterialID(0))
CreateEntity(#Tube, MeshID(#Tube), #PB_Material_None)
EndProcedure