i agree there is a need for single vertex access even it is slow, it is needed (in principle and not if it is speedy or not). single vertex Get and Set is available in blitz3D and in Xors3D.
the following will change the vertex 3 position by pressing Z but it works if we setmeshdata the whole mesh from 0 to 3. according to docs :
SetMeshData(#Mesh, SubMesh, DataArray(), Flags, FirstIndex, LastIndex)
FirstIndex, LastIndex First and last index to set the data to.
so if we make it like:
MeshData(3)\y + 0.2
SetMeshData(#pyramid,0, MeshData(), #PB_Mesh_Vertex,
3, 3)
it will not behave as expected ie changing only vertex 3 in the mesh, the mesh will be destroyed.
Code: Select all
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
InitEngine3D()
InitSprite()
InitKeyboard()
; get screen size
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)
OpenWindow(0, 0, 0, DesktopW, DesktopH, "triangular pyramid, ... press Z to change vertex 3 position")
OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
CreateMaterial(0, LoadTexture(0, "Geebee2.bmp"))
MaterialCullingMode(0, #PB_Material_NoCulling)
MaterialShadingMode(0, #PB_Material_Wireframe)
;DisableMaterialLighting(0, #True)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 3, 10, #PB_Absolute)
;MoveCamera(0, 0, 10, 0.01, #PB_Absolute)
CameraLookAt(0,0,0,0)
CameraBackColor(0, RGB(155, 155, 255))
CreateLight(0, RGB(255,255,255),0,50,0)
LightLookAt(0, 0,0,0)
CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
SetMeshMaterial(0, MaterialID(0))
MeshVertexPosition(-2, 0, 1)
;MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0,0)
MeshVertexPosition(2, 0, 1)
;MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(0,1)
MeshVertexPosition(0, 0, -2)
;MeshVertexColor(RGB(255,255,255))
MeshVertexTextureCoordinate(1,1)
MeshVertexPosition(0, 2, 0) ; the top vertex ; change 2 to any value
;MeshVertexColor(RGB(0,255,0))
MeshVertexTextureCoordinate(1,0)
MeshFace(0,1,2)
MeshFace(0,1,3)
MeshFace(1,2,3)
MeshFace(2,0,3)
FinishMesh(#True)
CreateEntity(0, MeshID(0), #PB_Material_None )
CreateSphere(1,0.1)
CreateEntity(1, MeshID(1), #PB_Material_None, 0,0,0)
;http://eusebeia.dyndns.org/4d/tetrahedron
;https://math.stackexchange.com/questions/755312/show-that-two-points-from-four-are-at-a-distance-leq-sqrt3-in-an-equilater
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
;Debug MeshVertexCount(0)-1
Repeat
Repeat
Event = WindowEvent()
Until Event = 0
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Z)
MeshData(3)\y + 0.2
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
EndIf
RotateEntity(0, 0, 1, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
here is the example in xors3d (available in this forum) for changing one vertex using xVertexCoords (but note it is an abandonware and not supported any more, and it needs DX9, don't know if it works in PBx64, i run it in PBx32 in winxp)
from xors3d docs:
xVertexCoords(Surface *surface, int vertex, float x, float y, float z)
Sets the geometric coordinates of an existing vertex.
xVertexX (Surface *surface, int vertex)
Returns the x coordinate of a vertex.
xVertexY ...
xVertexZ ...
Code: Select all
SetCurrentDirectory("..\..\dll")
; Include header file
IncludeFile "..\..\xors3d.pbi"
xCreateLog()
; setup maximum supported AntiAlias Type
xSetAntiAliasType(xGetMaxAntiAlias())
; set application window caption
xAppTitle("Example Xors3D: Press Arrow Keys to deform the triangle in real time (changing upper vertex position")
; initialize graphics mode
xKey("074P6-kglOy-7DWEA-gCrv4-z6RS8")
xSetEngineSetting("Splash::TilingTime", "0.0")
xSetEngineSetting("Splash::AfterTilingTime", "0.0")
xGraphics3D(800, 600, 32, #False, #True)
; hide mouse pointer
;xHidePointer()
; enable antialiasing
xAntiAlias(#True)
Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure
Global.l light, mesh, surf, cam, i, v1, v2, v3, brush, tri1, tot
Global.f x,y,z,r,g,b
light = xCreateLight(1)
mesh = xCreateMesh ()
xMeshPrimitiveType (mesh, 4)
surf = xCreateSurface(mesh, brush)
xSurfacePrimitiveType (surf, 4)
tot+1
v1 = xAddVertex(surf, -50, -50, 0, 0, 1)
xVertexColor(surf, v1, 0, 0, 255, 1)
v2 = xAddVertex(surf, 50, -50, 0, 0, 1)
xVertexColor(surf, v2, 0, 255, 0, 1)
v3 = xAddVertex(surf, 0, 50, 0, 0, 1)
xVertexColor(surf, v3, 255, 0, 0, 1)
tri1 = xAddTriangle(surf, v1, v2, v3)
;creating the camera
cam = xCreateCamera()
xPositionEntity(mesh, 0,0,400)
xPositionEntity(cam, 0, 0, 0)
;xPointEntity(cam, mesh) ; let the camera look always to the mesh
xFlipMesh(mesh)
xEntityFX(mesh, 1|2|18)
xUpdateNormals(mesh)
y.f=50 : x.f = 0
While(Not (xKeyHit(#KEY_ESCAPE) Or xWinMessage("WM_CLOSE")))
If xKeyDown(#KEY_Up)
y+0.5
xVertexCoords(surf, 2, x,y,0)
ElseIf xKeyDown(#KEY_Down)
y-0.5
xVertexCoords(surf, 2, x,y,0)
ElseIf xKeyDown(#KEY_Left)
x-0.5
xVertexCoords(surf, 2, x,y,0)
ElseIf xKeyDown(#KEY_right)
x+0.5
xVertexCoords(surf, 2, x,y,0)
EndIf
;xTurnEntity(mesh, 0, 1, 0)
xRenderWorld()
xText(10, 10, "FPS: " + xGetFPS())
xText(10, 30, "Tri: " + Str(xCountTriangles(surf)))
xFlip()
Wend
End
Note: that it is not impossible that the other engines are cheating, ie they provide Get/ Set one vertex for convenience only while internally they flush all the mesh even if you change one vertex only.