PureBasic Forum
https://www.purebasic.fr/english/

Problem with MeshIndex() (maybe bug) !?
https://www.purebasic.fr/english/viewtopic.php?f=36&t=73213
Page 1 of 1

Author:  Psychophanta [ Thu Jul 18, 2019 1:10 pm ]
Post subject:  Problem with MeshIndex() (maybe bug) !?

Program flux is halted at the time the MeshIndex() is reached.
The received message after halt the program is this:
https://ibb.co/QH7tb3n

Author:  applePi [ Thu Jul 18, 2019 4:14 pm ]
Post subject:  Re: Problem with MeshIndex() (maybe bug) !?

Hi Psychophanta
how this happened ? i have tried to replicate the error but can't.
the test below is adapted from Meshmanual2.pb
here we draw 4 vertices which have automatically vertex indices 0,1,2,3 . after that we connect every 3 vertices with
MeshIndex(0): MeshIndex(1): MeshIndex(2)
MeshIndex(0): MeshIndex(2): MeshIndex(3)
to make 2 triangles (instead of using MeshFace() function)
even we have 4 vertices but the number of indices is 6 as can be seen
if there is a bug it should be that if we replace MeshIndex(3) with MeshIndex(100) it does not throw an error but instead it does not draw the second triangle without giving an error that there is no vertex 100
Code:
#CameraSpeed = 1
#scale = 3

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/fonts", #PB_3DArchive_FileSystem)
   
  InitSprite()
  InitKeyboard()
  InitMouse()
 
  If Screen3DRequester()
   
    ;- Material
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    MaterialCullingMode(0,  #PB_Material_NoCulling )
    MaterialShadingMode(0, #PB_Material_Wireframe)


   
    ;- Mesh Plane (using MeshIndex)
    CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Static)
   
    MeshVertexPosition(-10, -10, 0) ; vertex index 0
    MeshVertexPosition(-10, 10, 0) ; vertex index 1
    MeshVertexPosition( 10, 10, 0) ; vertex index 2
    MeshVertexPosition( 10, -10, 0) ; vertex index 3
   
    ; Define usage of vertices by referring To the indexes
    MeshIndex(0): MeshIndex(1): MeshIndex(2)
    MeshIndex(0): MeshIndex(2): MeshIndex(3)
    FinishMesh(#True)
    plane2= CreateEntity(#PB_Any, MeshID(0), MaterialID(0))
   
    SetMeshMaterial(0, MaterialID(0))
   
    ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 0, 100, #PB_Absolute)
    CameraFOV(0, 40)
   
    CameraBackColor(0, RGB(0, 0, 40))
   
    ;-Light
    CreateLight(0, RGB(255,255,255), -10, 60, 10)
    AmbientColor(RGB(90, 90, 90))
   
    Debug Str(MeshVertexCount(0))
    Debug MeshIndexCount(0)

   
    Repeat
      Screen3DEvents()
     
      ExamineKeyboard()
     
      RotateEntity(Plane2, 0.3, -0.3, -0.3, #PB_Relative)
      RenderWorld()
     
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
 
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End




Author:  Psychophanta [ Fri Jul 19, 2019 1:39 pm ]
Post subject:  Re: Problem with MeshIndex() (maybe bug) !?

Then the meaning of MeshIndex() is 100% missunderstood by me, after reading the manual about it.

We can not do such like:
Code:
      UpdateMesh(0,0)
      MeshIndex(2); <- refer to mesh index 2
      MeshVertexPosition(20,10, 0) ; vertex index 2
      FinishMesh(#False)

So, to modify a random index in a mesh, we are forced to pass throw every index; from 0 upto the one we want to refer to.
:cry:

Author:  applePi [ Fri Jul 19, 2019 7:24 pm ]
Post subject:  Re: Problem with MeshIndex() (maybe bug) !?

HaHa :D :D the old historic topic, the MeshIndex() is used like meshFace() with #PB_Mesh_TriangleList option in CreateMesh() but its privilege is for constructing Lines mesh , in Docs:"
Quote:
When using the mode #PB_Mesh_LineList or #PB_Mesh_LineStrip, there are only two vertices per line, so MeshIndex() needs to be used in this case.


Quote:
"Psychophanta said: So, to modify a random index in a mesh, we are forced to pass throw every index; from 0 upto the one we want to refer to."

No we can't change one specific vertex data alone using its index number without updating all the mesh vertices in the case of a mesh attached to a Node, look my second and third example here viewtopic.php?f=36&t=71450 but don't be cheated by some engines such as blitz3D they provide functions for changing one vertex but behind the scene they update all the mesh (simply they are cheating), this is because the way the mesh data is stored in the graphics card. ( i remember reading something about the storage of mesh data in the Graphics cards memory in response to a user asked for a function to alter one vertex only)
if Michael the developer of MP3D engine for purebasic is here then we will ask him how he implement the functions to change one vertex only in DirectX 9 which he was using?? like MP_VertexSetX(Entity, index, x.f)
MP_VertexSetY
MP_VertexSetZ

on the other hand , and even the all mesh needs to update why purebasic does not relief the users and provide that functions to change one vertex only such as UpdateVertex(#mesh, vertexIndex,x,y,z,color), ... . or SetVertexData(#mesh, vertexIndex,x,y,z,color) and all the process of updating all mesh is done behind the scene without the trouble letting this task to the user.
a small working example from mp3d engine for purebasic (i have it installed in PB 5.31) like this to deform the vertices of a Sphere easily :
Code:
MP_Graphics3D (640,480,0,1) ; Erstelle ein WindowsFenster #Window = 0
SetWindowTitle(0, "3D Darstellung eine Würfels")
camera=MP_CreateCamera() ; Kamera erstellen
light=MP_CreateLight(1) ; Es werde Licht
Mesh=MP_CreateSphere(20) ; Und jetzt eine Würfel
MP_PositionEntity (Mesh,0,0,5) ; Position des Würfels
For n = 1 To MP_CountVertices(Mesh) Step 12
      MP_VertexSetX (Mesh, n, MP_VertexGetX(Mesh, n) * 1.5)
      MP_VertexSetY (Mesh, n, MP_VertexGetY(Mesh, n) * 1.5)
      MP_VertexSetZ (Mesh, n, MP_VertexGetZ(Mesh, n) * 1.5)
     
Next
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
      MP_TurnEntity (Mesh,0.1,0.1,0.1)
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
Wend

Author:  Psychophanta [ Fri Jul 19, 2019 8:10 pm ]
Post subject:  Re: Problem with MeshIndex() (maybe bug) !?

Oh, yes, I know already MP3D, I've used it.
But about 1 year ago I decided to migrate to the native 3D in PB (by the way, I still ignore what is the physics engine used in the PB 3D engine).
This is one of my latests works made in MP3D:
https://www.youtube.com/watch?v=hJSbVOHRfrU

And looks like the MP_VertexSetX(), MP_VertexSetY(), MP_VertexSetZ(), does not process all the previous indexes, but just the especified one.
Probably that's why the morph demos made with 3D plots is always faster with the MP3D than the native 3D engine.
Also I have noticed that the Freeing and Creating meshes is too slow in ATI/AMD cards using the PB native 3D Engine, in comparison with nVidia. But using MP3D is no difference.
Definitely, if MP3D had support, and if it would be available for linux and mac, then it would be a serious and real adversary to PB 3D engine.

I remember those examples in the link you point, which are great.
But at the moment this statement:
Quote:
"change index vertex ramdomly is not possible, but just secuentially starting form the index 0"
is not a bug, but a feature. :? :lol:

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/