Page 1 of 2

Needed engine3d internals info to build own SetMeshData() fu

Posted: Tue Sep 13, 2011 1:23 pm
by Psychophanta
Needed engine3d library internals info to perform custom Get/SetMeshData() function.

I mean,
wanted to know about the Mesh base memory and its size and structure after a mesh is created with CreateMesh(), CreateCube(), CreateCylinder(), etc.

THX!

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Tue Sep 13, 2011 1:36 pm
by DarkDragon
Guy, how about using AddMeshVertex(x, y, z) and AddMeshFace(Vertex1, Vertex2, Vertex3)? SetMeshData was replaced by that and for GetMeshData ... just let a copy of the memory stay in your code.

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Tue Sep 13, 2011 1:44 pm
by Psychophanta
DarkDragon wrote:Guy, how about using AddMeshVertex(x, y, z) and AddMeshFace(Vertex1, Vertex2, Vertex3)? Set-/GetMeshData was replaced by that.
Don't want to just add but also to modify previously stablished mesh vertexes, faces, colors, etc. Modify its position relative to its node. But modify vertex properties, not submeshes properties like TransformMesh() does.

TransformMesh() is not enough because it is no able to modify vertex position but complete meshes or submeshes.
Ans besides of that AddMeshVertex(x, y, z) and AddMeshFace(Vertex1, Vertex2, Vertex3),etc. are too slow if you want to real-timed modify or set up a complete big mesh in comparison with a 'copymemory' like command.

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Tue Sep 13, 2011 1:54 pm
by DarkDragon
Psychophanta wrote:
DarkDragon wrote:Guy, how about using AddMeshVertex(x, y, z) and AddMeshFace(Vertex1, Vertex2, Vertex3)? Set-/GetMeshData was replaced by that.
Don't want to just add but also to modify previously stablished mesh vertexes, faces, colors, etc. Modify its position relative to its node. But modify vertex properties, not submeshes properties like TransformMesh() does.

TransformMesh() is not enough because it is no able to modify vertex position but complete meshes or submeshes.
Ans besides of that AddMeshVertex(x, y, z) and AddMeshFace(Vertex1, Vertex2, Vertex3),etc. are too slow if you want to real-timed modify or set up a complete big mesh in comparison with a 'copymemory' like command.
Why don't you use Blender then? Or if it is for a model editing software: OpenGL or DirectX?

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Tue Sep 13, 2011 2:11 pm
by Psychophanta
DarkDragon wrote:Why don't you use Blender then? Or if it is for a model editing software: OpenGL or DirectX?
Because i want to do it via PB programming.

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Tue Sep 13, 2011 10:29 pm
by Guimauve
DarkDragon wrote:Why don't you use Blender then?
In the case of using static mesh it's OK, but the current PB mesh system is not suitable for Procedural morphing mesh generation.

And this is the main problem with this current implementation.

Best regards.
Guimauve

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Wed Sep 14, 2011 6:16 am
by DarkDragon
Guimauve wrote:
DarkDragon wrote:Why don't you use Blender then?
In the case of using static mesh it's OK, but the current PB mesh system is not suitable for Procedural morphing mesh generation.
Procedural morphing mesh generation? You mean bone animation?! This is possible with Blender and PureBasic.
The spring ist made with it: http://www.youtube.com/watch?v=pW8CUhe-Rfg
LOD is also possible .. dunno what you want. Everything else is bad for the bottleneck if you aren't able to use geometry shaders (but you are with purebasic!).

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Wed Sep 14, 2011 9:48 am
by Psychophanta
Is not that kind of animation Bradan, as i said there is no way to modify in realtime the vertex position.

For example,
do you remember this?
http://www.purebasic.fr/english/viewtop ... =12&t=8367
Well, it is for PB4.00 and in the newest PB release (PB4.60RC1) there is not possible to do that, is it?

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Wed Sep 14, 2011 7:11 pm
by DarkDragon
Psychophanta wrote:Is not that kind of animation Bradan, as i said there is no way to modify in realtime the vertex position.

For example,
do you remember this?
http://www.purebasic.fr/english/viewtop ... =12&t=8367
Well, it is for PB4.00 and in the newest PB release (PB4.60RC1) there is not possible to do that, is it?
I don't know what this code was about.
Create a new mesh, and store the data inside if you are too lazy for shaders.

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Thu Sep 15, 2011 8:38 am
by Psychophanta
DarkDragon wrote:I don't know what this code was about.
You can always run it on PB4.00 and see.
DarkDragon wrote:Create a new mesh, and store the data inside
That is just the "how to" i am asking for in the first post; store the full mesh data inside with a unique command.

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Fri Oct 07, 2011 12:31 pm
by DarkDragon
Psychophanta wrote:
DarkDragon wrote:Create a new mesh, and store the data inside
That is just the "how to" i am asking for in the first post; store the full mesh data inside with a unique command.
How about this, then? It is as efficient as SetMeshData would be.

Code: Select all

Macro Check(Status, Error, EndProgram = 1)
  If Not Status
    MessageRequester("ERROR", Error)
    CompilerIf EndProgram
      End
    CompilerEndIf
  EndIf
EndMacro

Structure MeshVertex
  X.f
  Y.f
  Z.f
EndStructure

Structure MeshNormal
  X.f
  Y.f
  Z.f
EndStructure

Structure MeshColor
  RGB.l
EndStructure

Structure MeshUV
  U.f
  V.f
EndStructure

Structure MeshFace
  V1.i
  V2.i
  V3.i
EndStructure

Procedure.i CreateMeshEx(Mesh.i, *PointerVertex.MeshVertex, *PointerColor.MeshColor, *PointerNormal.MeshNormal, *PointerUV.MeshUV, *PointerFace.MeshFace, Vertices.i, Faces.i)
  Protected K.i
  Protected MeshNumber.i
  Protected Result.i = 0
  
  If *PointerVertex = #Null Or *PointerFace = #Null
    ProcedureReturn Result
  EndIf
  
  If Mesh = #PB_Any
    MeshNumber = CreateMesh(Mesh)
    Result = MeshNumber
  Else
    Result = CreateMesh(Mesh)
    MeshNumber = Mesh
  EndIf
  
  If Result <> 0
    AddSubMesh()
    
    For K = 1 To Vertices
      AddMeshVertex(*PointerVertex\X, *PointerVertex\Y, *PointerVertex\Z)
      
      If *PointerColor <> #Null
        MeshVertexColor(*PointerColor\RGB)
        *PointerColor + SizeOf(MeshColor)
      EndIf
      
      If *PointerNormal <> #Null
        MeshVertexNormal(*PointerNormal\X, *PointerNormal\Y, *PointerNormal\Z)
        *PointerNormal + SizeOf(MeshNormal)
      EndIf
      
      If *PointerUV <> #Null
        MeshVertexTextureCoordinate(*PointerUV\U, *PointerUV\V)
        *PointerUV + SizeOf(MeshUV)
      EndIf
      
      *PointerVertex + SizeOf(MeshVertex)
    Next K
    
    For K = 1 To Faces
      AddMeshFace(*PointerFace\V1, *PointerFace\V2, *PointerFace\V3)
      *PointerFace + SizeOf(MeshFace)
    Next K
    
    FinishMesh()
  EndIf
  
  ProcedureReturn Result
EndProcedure

Check(InitEngine3D(), "InitEngine3D failed.")
Check(InitSprite(), "InitSprite failed.")
Check(InitKeyboard(), "InitKeyboard failed.")

Check(ExamineDesktops(), "ExamineDesktops failed.")

Check(OpenScreen(DesktopWidth(0), DesktopHeight(0), 32, "Test"), "OpenScreen failed.")

WorldShadows(#PB_Shadow_Modulative)

CreateTexture(0, 64, 64)
StartDrawing(TextureOutput(0))
Box(0, 0, 32, 32, RGB(0, 0, 255))
Box(32, 0, 32, 32, RGB(0, 255, 0))
Box(32, 32, 32, 32, RGB(255, 0, 0))
Box(0, 32, 32, 32, RGB(255, 255, 0))
StopDrawing()

CreateMaterial(0, TextureID(0))

CreateMeshEx(0, ?DataVertices, #Null, ?DataNormal, ?DataUV, ?DataFaces, 4, 2)
Check(CreateEntity(0, MeshID(0), MaterialID(0)), "CreateEntity failed")

CreateLight(0, RGB(255, 255, 255), 100.0, 0, 0)
LightSpecularColor(0, RGB(255, 0, 0))

Check(CreateCamera(0, 0, 0, 100, 100), "CreateCamera failed")

CameraLocate(0, 5, 5, -10)
CameraLookAt(0, 0, 0, 0)

Define Timer = ElapsedMilliseconds()
Define Mode = 0

Repeat
  ClearScreen(0)
  RenderWorld()
  FlipBuffers()
  
  If ElapsedMilliseconds() - Timer > 1000
    If Mode = 0
      CreateMeshEx(0, ?DataVertices2, #Null, ?DataNormal, ?DataUV2, ?DataFaces, 3, 1)
      Check(CreateEntity(0, MeshID(0), MaterialID(0)), "CreateEntity failed")
      Mode = 1
    Else
      CreateMeshEx(0, ?DataVertices, #Null, ?DataNormal, ?DataUV, ?DataFaces, 4, 2)
      Check(CreateEntity(0, MeshID(0), MaterialID(0)), "CreateEntity failed")
      Mode = 0
    EndIf
    Timer = ElapsedMilliseconds()
  EndIf
  
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End

DataSection
  DataVertices:
    Data.f -0.5,  0.5,  0.0
    Data.f  0.5,  0.5,  0.0
    Data.f  0.5, -0.5,  0.0
    Data.f -0.5, -0.5,  0.0
    
  DataVertices2:
    Data.f -0.75,  0.75,  0.0
    Data.f  0.75,  0.75,  0.0
    Data.f  0.75, -0.75,  0.0
    Data.f -0.75, -0.75,  0.0
    
  DataNormal:
    Data.f  0.0,  0.0,  1.0
    Data.f  0.0,  0.0,  1.0
    Data.f  0.0,  0.0,  1.0
    Data.f  0.0,  0.0,  1.0
    
  DataUV:
    Data.f  0.0,  0.0
    Data.f  1.0,  0.0
    Data.f  1.0,  1.0
    Data.f  0.0,  1.0
    
  DataUV2:
    Data.f  1.0,  1.0
    Data.f  0.0,  1.0
    Data.f  0.0,  0.0
    Data.f  1.0,  0.0
    
  DataFaces:
    Data.i 0, 1, 2
    Data.i 0, 2, 3
EndDataSection

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Fri Oct 07, 2011 3:43 pm
by Psychophanta
Your program example does not work here.
Anyway you say efficient? are you crazy?
It is not an unique command! far of this it includes loops, so it is useless for almost anything!

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Fri Oct 07, 2011 3:58 pm
by DarkDragon
Psychophanta wrote:Your program example does not work here.
Anyway you say efficient? are you crazy?
I did not say it is efficient. I said it is same efficient as SetMeshData! GeometryPrograms FTW - they are the only way to go on with such things.
SetMeshData will load the full data again and again to the GPU, as vertex buffers are needed there.
Here it works. PB 4.60 RC 1 is required.
Psychophanta wrote:It is not an unique command!
Sure, but you can convert your code to it, or are you really sooo lazy?
Psychophanta wrote:far of this it includes loops, so it is useless for almost anything!
Copying memory will always be of Theta(n) runtime. My loops are all Theta(n).

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Sat Oct 08, 2011 12:02 am
by Psychophanta
Can not test it because program is not able to open screen. The debugger does not complain but the screen is not open at all.
But i seriously doubt your function works as fast as SetMeshData() did.

Re: Needed engine3d internals info to build own SetMeshData(

Posted: Sat Oct 08, 2011 8:06 am
by DarkDragon
Psychophanta wrote:Can not test it because program is not able to open screen. The debugger does not complain but the screen is not open at all.
Then you may change this to a fixed resolution which works for you:

Code: Select all

Check(ExamineDesktops(), "ExamineDesktops failed.")

Check(OpenScreen(DesktopWidth(0), DesktopHeight(0), 32, "Test"), "OpenScreen failed.")
But you still need PB 4.6 RC 1 because of TextureOutput.
Psychophanta wrote:But i seriously doubt your function works as fast as SetMeshData() did.
Sure, what do you think does SetMeshData do? It copies the mesh to the GPU again (this is what FinishMesh does at the end). It isn't very different from this and it may only be a constant term less in time. As I said already: you should create your mesh on GPU with geometry shaders, not on CPU.