Re: Mesh deformation in PB5.20?
Posted: Thu Jul 11, 2013 7:56 pm
i have done some tests today and found that the vertex is not the index, in the pyramid example above there are 4 vertices which make 12 indexes from 0 to 11, ie 3 for every face, and every vertex can have several indexes like this picture:

in the following program press S to show a list of indices attach to every vertex. so it is useless to change the index coordinates since every vertex have several indices ie Labels. if someone else have more suggestions please post. it is good Psychophanta posted his question since now i know more about some secrets. and Comtois have done good job. since this is a beta version and needs any suggestion. i think the current situation are good.
@Comtois: in line 88 RotateEntity(0,0,rot,0) uncomment it: i can't make the pyramid rotate around itself but it is rotating in a big circle

in the following program press S to show a list of indices attach to every vertex. so it is useless to change the index coordinates since every vertex have several indices ie Labels. if someone else have more suggestions please post. it is good Psychophanta posted his question since now i know more about some secrets. and Comtois have done good job. since this is a beta version and needs any suggestion. i think the current situation are good.
@Comtois: in line 88 RotateEntity(0,0,rot,0) uncomment it: i can't make the pyramid rotate around itself but it is rotating in a big circle
Code: Select all
Enumeration
#MESH
#LIGHT
#CAMERA
#mainwin
EndEnumeration
Structure Vector3
x.f
y.f
z.f
EndStructure
Define.Vector3 v1, v2, v3
Global x.f = 0
Global y.f = 10
Global z.f = -30
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "press S to show indices, press Arrows change vertex 3 ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define.f KeyX, KeyY
Declare UpdateMatrix()
Declare CreateMatrix()
Declare DrawMatrix()
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
Add3DArchive("/", #PB_3DArchive_FileSystem)
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
MaterialShadingMode(0, #PB_Material_Wireframe )
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateMatrix()
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 50, #PB_Absolute)
CameraFOV(0, 70)
CameraBackColor(0, $330000)
CameraLookAt(0,0,0,0)
CreateLight(0, RGB(255,255,255), 10, 60, -10)
AmbientColor(RGB(90, 90, 90))
Repeat
Event = WindowEvent()
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F2)
MaterialShadingMode(0, #PB_Material_Wireframe)
ElseIf KeyboardReleased(#PB_Key_F3)
MaterialShadingMode(0, #PB_Material_Solid)
EndIf
If KeyboardPushed(#PB_Key_Right)
x + 0.4 :UpdateMatrix()
ElseIf KeyboardPushed(#PB_Key_Left)
x - 0.4 :UpdateMatrix()
EndIf
If KeyboardPushed(#PB_Key_Up)
y + 0.4:UpdateMatrix()
ElseIf KeyboardPushed(#PB_Key_Down)
y - 0.4 :UpdateMatrix()
ElseIf KeyboardReleased(#PB_Key_S)
;SaveMesh(0,"pyramid.mesh")
For i=0 To 11
vx = MeshData(MeshDataInd(i)\Index)\x
vy = MeshData(MeshDataInd(i)\Index)\y
vz = MeshData(MeshDataInd(i)\Index)\z
Debug "index "+Str(indx) +" = " + Str(vx)+" "+Str(vy)+" " +Str(vz)+" "
indx + 1
Next
EndIf
EndIf
rot.f+0.6
;RotateEntity(0,0,rot,0)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure DrawMatrix()
MeshVertexPosition(-20, -20, -20) ;vertex 0
MeshVertexColor(RGB(255, 0, 0))
MeshVertexPosition(20, -20, -20) ; vertex 1
MeshVertexColor(RGB(0, 255, 0))
MeshVertexPosition(0, -20, -40) ; vertex 2
MeshVertexColor(RGB(255, 220, 0))
MeshVertexPosition(0, 10,-30) ; vertex 3
MeshFace(0, 1, 2)
MeshFace(1, 2, 3)
MeshFace(1, 0, 3)
MeshFace(0, 3, 2)
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #True)
DrawMatrix()
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(0))
CreateEntity(0, MeshID(0), #PB_Material_None)
ScaleEntity(0, 2, 2, 2)
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
GetMeshData(0,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(0, 0)-1)
EndProcedure
Procedure UpdateMatrix()
MeshData(3)\x = x
MeshData(3)\y = y
MeshData(3)\z = z
;vx = MeshData(MeshDataInd(10)\Index)\x
;vy = MeshData(MeshDataInd(10)\Index)\y
;vz = MeshData(MeshDataInd(10)\Index)\z
;MessageRequester("", Str(vx)+" "+Str(vy)+" " +Str(vz)+" ")
;Debug Str(vx)+" "+Str(vy)+" " +Str(vz)+" "
;MessageRequester("", Str(MeshIndexCount(0, 0)-1))
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
SetMeshData(0,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshVertexCount(0)-1)
EndProcedure