Results 1 to 3 of 3

Thread: Use of TBGL_NewListSpace or Poke$(Varptr(DISPLAYLIST/@Entity)...?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171

    Use of TBGL_NewListSpace or Poke$(Varptr(DISPLAYLIST/@Entity)...?

    I'm currently thinking about saving 3d-stuff and I want it fast. (but the re-loading of data - not the solution for my problem )

    My Vertices, Normals, Colors and UV are all stored to Global udt-Arrays and I have an additional Triangle-Type to indicate which of them to use at what corner. I already send this data to Displaylist so I can display them as some Entity. The thing is, all my position-vectors, normal-vectors, texels and colors are all seperate and unique and the triangle-udt holds their indexes or indices - which indicate what to use at which corner. They real "vertices" get composed from their single properties inside their parenting faces corner. So far...

    Here's overview of my types that make the mesh:
    (I'm using Doubles because I do a lot of calculation with these. In general Singles would be precise enough for just-display-purpose.)
    Uses "TBGL"
    
    Type t_vec3d
      X As Double
      Y As Double
      Z As Double
    End Type
    
    Type t_Texel
      U As Double
      V As Double
    End Type
    
    Type t_Triangle
      V(3)    As Long      ' these hold indices of position-vectors
      N(3)    As Long      ' normal -vector to the corner
      T(3)    As Long      ' texel (UV)
      C(3)    As Long      ' Color 
      
      nX      As Double     ' those are for Face-Normals and to place the
      nY      As Double     ' camera when supposed to look at triangle
      nZ      As Double
    
      cX      As Double     ' center-position, needed to order and sort
      cY      As Double
      cZ      As Double  
      
      Grp     As Long
      Checked As Boolean
    End Type         
    ' ----------------------------- 
    ' these hold the data:
     
    Dim Vec()  As t_Vec3d       : Dim nVecs As Long
    Dim Nml()  As t_Vec3d       : Dim nNmls As Long
    Dim Txl()  As t_Texel         : Dim nTxls As Long
    Dim Col()  As TBGL_TRGB    : Dim nCols As Long
    
    Dim Tri()  As t_Triangle      : Dim nTriangles As Long
    
    Organized nearly .obj - everything is just once in memory - different from .obj is, that I use only triangles and no other kinds of faces (which are all made from triangles anyway)...

    The displaylist and also m15-format works another way - there are no indices and vertices are just in order, so every data-component is in there a few times - this might be the way they get drawn fastest but on one hand it's a large waste of space and almost impossible to organize data that way for an app that has to calculate and keep connections between these vertices (are the corners of two faces at same point etc. would use a lot of calculating and temporary storing of meantime-results or lists of things...)

    Additional I have some type to group triangles that shall use same texture + material, looks alike this - I omit some from the original-type because they're just temporary related to the group for current session.

    Type t_MeshGroup
      
      Identity   As String        ' the Identity is just to allow the user
                                       ' to identify his groups as "roof", "wall" etc.
    
      Members    As String
      Texture    As String       ' store Texture-Filename of this group here
     
      Ambient    As TBGL_TRGBA
      Diffuse    As TBGL_TRGBA
      Emissive   As TBGL_TRGBA
      Specular   As TBGL_TRGBA
      SpecExp    As Byte
     
      ' -- current session values i omit here
      '...
    End Type
    Dim Group() As t_MeshGroup  : Dim nGroups As Long
    ReDim Group(1) : nGroups = 1 ' lower bound is 1 here, there's always one...
                                             '(a triangle that has .Grp = 0 is a deleted one)
    
    The Members-String insice this Type gets composed as follows: If a triangle gets created or joins this group, I just do this:
    Group(Group_Current).Members += MKL$(NewMembersIndex)
    ' later I just dim a virtual long array over this to read members out
    
    Every group makes basically one Entity...
    Group1 will probably be the parent, all additional will be childs...
    together they make the mesh...

    .m15 won't allow me to put the material-data into the file...

    I like using Entity...

    Is there a possibility to make a String from all my Data and to poke it into an Entity or DisplayList in one step?
    I mean I would organize the string as Entity needs it in advance - even make all singles from doubles here - no problem - it's not about the speed here in this current app - but about the speed in another app that should make use of 3d-stuff, drawn with the app I'm currently creating. I also might create a loading-routine that does the Parse data + Poke$ to Entity for every single group then
    I want to load data later in another app and if I would have to organize the whole displaylist for everything that gets loaded then - that might be very slow and knocks all that follows out.
    And FunctionSlot? I have not really understood yet how this works but I think that needs a Function that gets called when Entity shall be drawn and that seems also to be a speed-problem. And it doees not seem to differ very much from the way I do it now - I also call some function to create Entity from a displaylist-slot which i set up in that function...

    TBGL_NewListSpace?/TBGL_NewList don't return a pointer where I cound poke data
    - anybody some idea how to flush all data to tbgl-entity at once?
    So later I could fast read-in a file as string,
    parse into groups
    poke groups-data$ to Entity
    apply material
    next group/Entity
    Last edited by ReneMiner; 08-04-2013 at 12:10.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    Hi Rene,

    I completely understand your motivation. The problem is for example display lists have completely platform specific internal format, so any peek/poke is not possible.

    I think one possible solution for this situation would be forging of specifications for precisely defined 3D format, for which we could create import tools and special compiled module for fast loading.

    Engines such as Unity also first import all the media into its own internal format, and then work with it. I tried this approach with M15, I think it works, but I am not sure M15 was designed well - as we discussed earlier, I designed it on High school studies and it is a bit evident it was done by unexperienced kid :P


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    You might have read the other thread in the meantime (String in String) so might be there could be a way to read the file directly to displaylist. So we don't need to invent a format - we can use TBGL. It's just have to sort the data into the display-list and somehow this could be a direction.

    Maybe TBGL could load diplaylist from data, structured as the displaylist would be typed in. So is not new format but filling data in from file and not from script itself- the hook right now is,
    'I had to read in a line, "TBGL_Vertex 1.2, 3.4, 5.6"
    'parse it to statement, argument[,argument[,...]]]
    select case argument(1)
       case "TBGL_NewList"
          TBGL_NewList val(argument(2)) + some passed parameter
       case "TBGL_BeginPoly"
          TBGL_BeginPoly Val(argument(2))
       Case "TBGL_Vertex"
          TBGL_Vertex Val(argument(2)), Val(argument(3)), Val(argument(4))
    ' etc...
    End Select
    
    so would be great if TB(GL) could read in the values direct this way.
    Last edited by ReneMiner; 09-04-2013 at 16:52.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Varptr() as a function-parameter?
    By ReneMiner in forum thinBasic General
    Replies: 2
    Last Post: 20-02-2013, 21:58
  2. TBGL-DisplayList-Tinker-Tool
    By ReneMiner in forum TBGL Scripts and Projects
    Replies: 12
    Last Post: 20-11-2012, 18:58
  3. cast convert / varptr / peek
    By largo_winch in forum thinBasic General
    Replies: 3
    Last Post: 28-09-2012, 11:39

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •