in the following example (in windows) we attach the 3d line mesh to node then if we want to free the mesh we should first detach it from node
If KeyboardReleased(#PB_Key_Space)
DetachNodeObject(#node, MeshID(0))
FreeMesh(0)
EndIf
also using
KeyboardReleased instead
KeyboardPushed
here before we exit we should add :
DetachNodeObject(#node, MeshID(0))
FreeMesh(0)
to the program closing procedure when we press we press ESC or click 'X'
may be this needs a more looking since pressing 'x' should free everything. but temporary we can free the resources first ourself
here press
Space key before closing the program to detach the mesh from the node and then free the mesh
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - CreateLine3D
;
; (c) 2011 - Fantaisie Software
;
; ------------------------------------------------------------
;
#CameraSpeed = 1
#node = 35
IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
; Line3D
;
CreateLine3D(0, 0, 0, 0, RGB(255, 0, 0), 10, 0, 0, RGB(255, 0, 0))
CreateNode(#node, 0, 0, 0)
AttachNodeObject(#node,MeshID(0))
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 5, 5, 5, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
Repeat
Screen3DEvents()
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Space)
DetachNodeObject(#node, MeshID(0))
FreeMesh(0)
EndIf
EndIf
RotateNode(#node,1,1,0,#PB_Relative)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
Screen3DStats()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
other approach is to use something like this to draw a 3d line
CreateMesh(0,
#PB_Mesh_LineList, #PB_Mesh_Static)
MeshVertexPosition(-5, 0, -5)
MeshVertexColor(RGB(255,0,0))
MeshVertexPosition(-5, 0, 5)
MeshVertexColor(RGB(0,255,0))
FinishMesh(#True)
look example
MeshManual2.pb
below we will draw 2 lines
here we can attach the mesh to entity and do what we want, i have'nt tested it with a node.
Code: Select all
#CameraSpeed = 1
IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
CreateMesh(0, #PB_Mesh_LineList , #PB_Mesh_Static)
MeshVertexPosition(-5, 0, -5)
MeshVertexColor(RGB(255,0,0))
MeshVertexPosition(-5, 0, 5)
MeshVertexColor(RGB(0,255,0))
MeshVertexPosition(-10, 0, -5)
MeshVertexColor(RGB(255,0,0))
MeshVertexPosition(-10, 0, 5)
FinishMesh(#True)
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
SetMeshMaterial(0, MaterialID(0))
CreateEntity(0,MeshID(0),MaterialID(0) )
; Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 20, 5, 20, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
Repeat
Screen3DEvents()
If ExamineKeyboard()
EndIf
RotateEntity(0, 0,1,0,#PB_Relative)
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