Page 1 of 1

Problem-question for GetMeshData()

Posted: Thu May 09, 2024 8:35 am
by Psychophanta
I have an array:

Code: Select all

Dim vertices.MeshVertex(60)
I create a mesh, fill it with 61 vertex, etc. And it goes all fine.
But;
When I do:

Code: Select all

UpdateMesh(#mesh,0)
todovertice(); <- repositionating 61 vertex
FinishMesh(0)
NormalizeMesh(#mesh,0)
UpdateMeshBoundingBox(#mesh)
GetMeshData(#mesh,0,vertices.MeshVertex(),#PB_Mesh_Vertex,0,7)
I receive error array out of bounds when recalling again 'todovertice()'.
Is it normal?

Re: Problem-question for GetMeshData()

Posted: Thu May 09, 2024 10:35 am
by minimy
Hi Psychophanta! I think with MeshVertexCount()-1 must run well.

Re: Problem-question for GetMeshData()

Posted: Thu May 09, 2024 8:53 pm
by minimy
Hi again Psicofanta ;-)
Example: If you have a plane of 8x8 tiles you have 81 vertex.. What 81?... Yes because to make 8 tiles we need 9 vertex, and then your bucle must be from 0 to 80, no 0 to 81.
Use MeshVertexCount to know how many vertex have the mesh, and use this: MeshVertexCount(mymesh)-1. This should work.
Greetings!!

Re: Problem-question for GetMeshData()

Posted: Fri May 10, 2024 5:44 pm
by Psychophanta
Sorry mini, but the only i must know, in the example, is the mesh has more than 7 indexes. I don't need at all to know the total amount of indexes of the mesh; if it has more than 7, it should work, as i can understand.
So, there seems the issue is related to another things.

Ok, I post the complete tip to show. Look at the lin 97, if you uncomment it, then the error comes.

Code: Select all

;/ inits
If InitEngine3D(#PB_Engine3D_NoLog,#PB_Compiler_Home+"Compilers\Engine3d.dll")=0
  MessageRequester("Error","The 3D Engine can't be initialized",0):End
EndIf
AntialiasingMode(#PB_AntialiasingMode_x4)
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,800,600,"cuerpo TID",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,800,600,1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
#luz=0
#camara=0
#pivotcamara=0
#pivot=1
#textura=0
#material=0
#malla=0
;\
Structure Vector3D
  x.f:y.f:z.f:m.f
EndStructure
Macro ProductoEscalar(a,b)
  (a#\x*b#\x+a#\y*b#\y+a#\z*b#\z)
EndMacro
Macro getmodulo(v)
  (Sqr#ProductoEscalar(v#,v#))
EndMacro
Macro ProductoVectorial(in1,in2,out,in1x=x,in1y=y,in1z=z,in2x=x,in2y=y,in2z=z,outx=x,outy=y,outz=z); <- Calculates the vectorial product of two 3D vectors. Just modify this procedure to get the vectorial product for 4D, 5D, 6D or any dimension you need.
  out#\outx#=in1#\in1y#*in2#\in2z#-in1#\in1z#*in2#\in2y#
  out#\outy#=in1#\in1z#*in2#\in2x#-in1#\in1x#*in2#\in2z#
  out#\outz#=in1#\in1x#*in2#\in2y#-in1#\in1y#*in2#\in2x#
EndMacro
Procedure.b MouseButtonEdgeDetection(mbutton.b)
  Static mb.b:Protected i.b=1<<mbutton
  If MouseButton(mbutton);<-if current key status is PUSHED
    If mb&i=0:mb|i:ProcedureReturn 1:EndIf;<-if previous key status was NOT PUSHED, then assign previous state to current one, and EXIT.
  ElseIf mb&i;<-else (if previous key status was PUSHED and current key status is NOT PUSHED):
    mb!i:ProcedureReturn -1;<-set previous key status to NOT PUSHED.
  EndIf
  ProcedureReturn 0
EndProcedure
Macro PonerVertice(posx,posy,posz,texcoordu,texcoordv,color)
  MeshVertex(posx#,posy#,posz#,texcoordu#,texcoordv#,color#)
;   MeshVertexPosition(posx#,posy#,posz#)
;   MeshVertexTextureCoordinate(texcoordu#,texcoordv#)
;   MeshVertexColor(color#)
EndMacro
Macro RND(v1,v2,ndecimales=3); maximo 'ndecimales' = 9
  ;genera un nĂºmero aleatorio entre los valores v1 y v2
  ;NOTE: usar con variables de punto flotante para que esta macro funcione correctamente
  (Random(1E#ndecimales#)*(v2#-v1#)/1E#ndecimales#+v1#)
EndMacro
CreateLight(#luz,$EEEEEE,4,4,2,#PB_Light_Point):SetLightColor(#luz,#PB_Light_DiffuseColor,$EEEEEE):MoveLight(#luz,4,4,2,#PB_Absolute)
CreateCamera(#camara,0,0,100,100):CreateNode(#pivotcamara,0,0,0):AttachNodeObject(#pivotcamara,CameraID(#camara)):CameraRange(#camara,0.1,1000):CameraBackColor(#camara,$181911)
MoveCamera(#camara,0,0,45,#PB_Absolute)
CreateMaterial(#material,0,$33E7FF):DisableMaterialLighting(#material,1)
eje.Vector3D
ele.Vector3D
ene.Vector3D
#nvertices=60000
Dim vertices.MeshVertex(#nvertices)
Macro todovertice(rotax=RND(-1,1,6),rotay=RND(-1,1,6),rotaz=RND(-1,1,6))
  vertices(0)\x=RND(-0.2,0.2,6):vertices(0)\y=RND(-0.2,0.2,6):vertices(0)\z=RND(-0.2,0.2,6)
  MeshVertexPosition(vertices(0)\x,vertices(0)\y,vertices(0)\z):MeshVertexColor($43D4E2):MeshIndex(0)
  ele\x=vertices(0)\x-0:ele\y=vertices(0)\y-0:ele\z=vertices(0)\z-0
  For t.u=1 To #nvertices
    eje\x=rotax#:eje\y=rotay#:eje\z=rotaz#
    ProductoVectorial(ele,eje,ene):ene\m=getmodulo(ene)
    long.f=RND(0.1,1,6)
    ene\x*long/ene\m:ene\y*long/ene\m:ene\z*long/ene\m
    vertices(t)\x=vertices(t-1)\x+ene\x:vertices(t)\y=vertices(t-1)\y+ene\y:vertices(t)\z=vertices(t-1)\z+ene\z
    MeshVertexPosition(vertices(t)\x,vertices(t)\y,vertices(t)\z):MeshVertexColor($43D4E2):MeshIndex(t)
    ele\x=vertices(t)\x-vertices(t-1)\x:ele\y=vertices(t)\y-vertices(t-1)\y:ele\z=vertices(t)\z-vertices(t-1)\z
  Next
EndMacro
CreateMesh(#malla,#PB_Mesh_LineStrip,#PB_Mesh_Static)
todovertice(0,0)
FinishMesh(0)
SetMeshMaterial(#malla,MaterialID(#material))
CreateNode(#pivot):AttachNodeObject(#pivot,MeshID(#malla))
Repeat:Repeat:evento.i=WindowEvent():Until evento=#PB_Event_None
  ExamineMouse():ExamineKeyboard()
  CursorX.f=WindowMouseX(0):CursorY.f=WindowMouseY(0):mdx.f=MouseDeltaX()/200:mdy.f=MouseDeltaY()/200:mdz.f=MouseWheel()/2
  If mdx Or mdy Or mdz
    If MouseButton(#PB_MouseButton_Right)
      MoveCamera(#camara,mdx,-mdy,0,#PB_Local)
    Else
      RotateNode(#pivotcamara,-mdy*6,-mdx*6,0,#PB_Relative)
      MoveCamera(#camara,0,0,-mdz,#PB_Relative)
    EndIf
  EndIf
  If KeyboardReleased(#PB_Key_Up)
    UpdateMesh(#malla,0)
    todovertice(0,0)
    FinishMesh(0)
    NormalizeMesh(#malla,0)
    UpdateMeshBoundingBox(#malla)
    ;GetMeshData(#malla,0,vertices.MeshVertex(),#PB_Mesh_Vertex,0,7); <- error
  ElseIf MouseButtonEdgeDetection(#PB_MouseButton_Left)=1
    SetMeshData(#malla,0,vertices.MeshVertex(),#PB_Mesh_Vertex,0,7)
    NormalizeMesh(#malla,0)
    UpdateMeshBoundingBox(#malla)
  ElseIf KeyboardReleased(#PB_Key_Right):anchuradelinea.a+1:glLineWidth_(anchuradelinea)
  ElseIf KeyboardReleased(#PB_Key_Left):anchuradelinea.a-1:glLineWidth_(anchuradelinea)
  EndIf
  TimeSinceLastFrame.i=RenderWorld(50)
  FlipBuffers()
  StartDrawing(WindowOutput(0))
  DrawText(1,1,"vertices: "+Str(MeshVertexCount(#malla,0)))
  StopDrawing()
  Delay(13)
Until KeyboardPushed(#PB_Key_Escape)

Re: Problem-question for GetMeshData()

Posted: Fri May 10, 2024 7:51 pm
by juergenkulow

Code: Select all

; After GetMeshData ArraySize of vertices is 7. For loop to 60000 stops at vertices(8). 
GetMeshData(#malla,0,       vertices(),#PB_Mesh_Vertex,0,7)
;                                                        ^
Debug "GET ArraySize:"+Str(ArraySize(vertices()))+" #nvertices:"+Str(#nvertices)
;GET ArraySize:7 #nvertices:60000
#nvertices=60000
Dim vertices.MeshVertex(#nvertices)
Macro todovertice(rotax=RND(-1,1,6),rotay=RND(-1,1,6),rotaz=RND(-1,1,6))
  ...
  For t.u=1 To #nvertices
    ...    
    vertices(t)\x=vertices(t-1)\x+ene\x
    ...
  Next
EndMacro

Re: Problem-question for GetMeshData()

Posted: Fri May 10, 2024 9:47 pm
by minimy
Awesome!... with PB6.02 uncommented line 97 no give error. :lol:

Re: Problem-question for GetMeshData()

Posted: Fri May 10, 2024 11:33 pm
by SeregaZ
Can you help to create two models with this arrays ? not clear at all what i should store in that array. i try to millions programs blender and etc, then convert them to mesh... but i seamsed i am do something wrong.

CreateCube of PB - work perfect! when i use texture - it lays exactly where i need - sides of cube.

when i try to load from other programs happen that different things:
1. some sides of Cube is transparent. i should see front of Cube, but they dissapear and i see back side of cube... like i was sit inside cube.
2. texture lays on somewhere another, but not left top corner of each side of Cube.
for those cases some one says it just 3d program, that i use is crap. i download blender and try to make with it, then convert with OgreAssimpConverter and it add new strange cases to my suffering:
3. texture is not apply to that new meshes at all. they still stay white. it is same code, as before and with old mesh it work fine (except 2 case, where it lays with wrong place, but it appear. here is not appear at all)
4. blender (2.8, for windows 7) have some Legacy Mesh switcher. i turn on it and my cube (not cube actualy, but height is lower than sides - width 128px, height 68px) have wrong position. it stays on a ground narrow part, not wide part as it was before.

i need only two, not very complex, meshes. is any passibility to make them with this Array MeshVertex ? is any simpliest example with explanation as for a kid - to understand how to create mesh by manualy with this Array ? i need Cube with 128x128x64 and cutted that cube to half. like triangle, but 3d triangle as cube. and with top left point of each sides for attach texture. and some times i will need to attach different texture on different side.

Image

maybe it is exist some PB program, that will make 100% of compatibility with PB projects for making meshes ?


and OgreAssimpConverter for 3 case, where texture is not apply for mesh - create two files actually. mesh, that i plug into my code and second one - *.material file. maybe i need to plug it somehow too ? it will solve problem with texture attaching ?

****
it was brain explow, but probably i am done. anyway will be nice to see some usefull convert program, that will work correct, without all of that shaman's dances with tamburine.

Re: Problem-question for GetMeshData()

Posted: Sat May 11, 2024 5:51 am
by Psychophanta
Hello @SeregaZ.
Your post has no relation with the thread, but what i can say is that blender is powerful enough to do what you want, as i understand it.
You just need to rise up a little more in the painful learnig curve of blender3D.
For conversions, i use sometimes this software 'Accutrans3D', which is freeware for 3a day period, but i purchased it:
http://www.micromouse.ca/

Re: Problem-question for GetMeshData()

Posted: Sat May 11, 2024 7:20 am
by SeregaZ
you mean it can convert file from blender to mesh, that will accept PB ?

Re: Problem-question for GetMeshData()

Posted: Sat May 11, 2024 12:41 pm
by minimy
Hello SeregaZ, use this software, is the easy way for low poly objects direct to ogre mesh.
http://www.delgine.com
Greetings!!

Re: Problem-question for GetMeshData()

Posted: Sat May 11, 2024 2:38 pm
by Psychophanta
SeregaZ wrote: Sat May 11, 2024 7:20 am you mean it can convert file from blender to mesh, that will accept PB ?
Not sure. Time ago i do not use it.
Old versions do not export PB<->blender, but newer ones may be. The case is that software converts lots of formats.