Results 1 to 7 of 7

Thread: Entities again...

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

    Entities again...

    This is about Entities in general because I intend to do something

    I don't know if I already asked: Is there a way to create an Entity from something that I create with TBGL_GBufferDefineFromArray? So the entity-camera-view even in other FOV-settings is correct?

    Another thing:
    Is it possible to receive the number of Texture-Slot which was assigned to myEntity by TBGL_EntitySetTexture? Or do I need append this to Entity-Userdata-Slot - I would like to avoid useless variables since all Entities have those lovely Get+Set-methods and that additional variable would apply to each and every entity... That would be a great help if I want to manage a textures-pool, so I know which textures are still needed when unloading something or if space is needed.

    Did I understand correct: TBGL_Entity_etName()-methods allow to append/re-read ANY string as a name or identifier?
    But I miss a function for fast-retrieve
    EntityID = TBGL_EntityIDFromName(scene, "the desired identity") which would upvalue the Name-Property - but still great to use in combination with CallIfExists "Update_" + TBGL_EntityGetName(...)

    To the help:
    TBGL_EntitySetUserData + TBGL_EntityGetUserDataPointer,
    in the example
    '...
    
    dim temporary as tUserBox at TBGL_EntityGetUserDataPointer(%SCENE1, %eBox1) 
    msgbox hWnd, "Box1 weights"+STR$(tempvar.weight)+" kilograms and is made of "+tempvar.materialName      
    
    ' -- Move memory overlay to retrieve data for box2 
    SetAt(tempvar, TBGL_EntityGetUserDataPointer(%SCENE1, %eBox2)) 
    msgbox hWnd, "Box2 weights"+STR$(tempvar.weight)+" kilograms and is made of "+tempvar.materialName
    
    Dim temporary is confusing me in both examples...

    Last edited by ReneMiner; 12-05-2013 at 22:01.
    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,

    1/ Entity from GBUffer - I would suggest using user defined entity for this (the function slot approach). You can store the GBuffer handle in user entity data then.

    2/ I will add TBGL_EntityGetTexture to retrieve the texture index

    3/ Find entity by name - I understand it would be nice to have, but I would suggest using entity data signature instead - it will be faster. You can read about it here.

    4/ TBGL_EntitySetUserData / TBGL_EntityGetUserDataPointer - it is the principle used in custom entities. TBGL_EntitySetUserData takes the variable you pass (even UDT) and copies it inside the entity. TBGL_EntityGetUserDataPointer allows to retrieve the pointer to the local data copy anytime later.

    The code could look like this too:
    ' -- Create virtual variable to be able to touch the data later
    dim tempVar as tUserBox at 0
    
    ' -- Initialize the variable to work with Box1 data
    tempVar = TBGL_EntityGetUserDataPointer(%SCENE1, %eBox1) 
    msgbox hWnd, "Box1 weights"+STR$(tempVar.weight)+" kilograms and is made of "+tempVar.materialName      
    
    ' -- Initialize the variable to work with Box2 data (we recycle the temporary variable here, that is why I call it ...temporary)
    tempVar = TBGL_EntityGetUserDataPointer(%SCENE1, %eBox2)
    msgbox hWnd, "Box2 weights"+STR$(tempVar.weight)+" kilograms and is made of "+tempVar.materialName
    

    Petr
    Last edited by Petr Schreiber; 13-05-2013 at 10:06.
    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,535
    Rep Power
    171
    temporary = tempvar.weight & tempvar.materialName ? I don't get it- where does the tempvar come from? Is that typo?

    I think I'll read some more about signature...

    Edit: I read about signature...see article,

    I think there's also some typo in code-example 7:
    DIM AppleBoxes(1) AS LONG
    DIM nAppleBoxes AS LONG
    
    nAppleBoxes = TBGL_EntityEnumByDataSignature(%sScene, AppleBoxes, %signatureBoxOfApples) 
    
    FOR i = 1 TO AppleBoxes_Count 
      MSGBOX 0, "Entity #"+AppleBoxes(i) +" is apple box"
    NEXT
    
    AppleBoxes_Count or nAppleBoxes ?
    Last edited by ReneMiner; 13-05-2013 at 08:39.
    I think there are missing some Forum-sections as beta-testing and support

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

    now I understand why you were confused:
    • tempVar should be temporary (will be fixed in help file of next TBGL release)
    • nAppleBoxes should be AppleBoxes_Count (fixed)


    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

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

    from m15 to entiy...

    Current I plan to drag some models into my terrains so there will be some trees, bushes, rocks etc. Loading times to load models into TBGL are only acceptable for m15-format currently so I might start with them to get the script-skeleton together. Now I still have loads of questions because I have not used m15 that much:

    To load M15 the syntax is as follows:

    TBGL_m15LoadModel ModelFile, TextureSubdirectory, ModelID, TargetedDisplayList, NormalVectorMethod

    Now help says about TextureSubdirectory-parameter:

    Contains path to the subdirectory with textures that model will need. If empty string is specified, it presumes "Textures\" subdirectory
    Now I wonder: Textures\-subdirectory of what: of current app? or of Modelfile-parameter if it's a full-path? Will it search on same path (next to model) for textures also? How will I know if it has found the texture?
    I fear the new method TBGL_EntityGetTexture won't tell me the number of the used texture-slot if I make an Entity of the M15-model then. Remarks in TBGL_EntityCreateModelSlot :
    Effects of TBGL_EntitySetColor and TBGL_EntitySetTexture have effect only in context of scene system and do not override real data in stored model.
    This allows some tricks which save memory a lot - you can create 10 instances of model #1, each with different color and texture.
    Using conventional TBGL commands you would have to load model 10 times.

    let me think their textures (m15/Entitiy) get handled seperately.

    That brings me to the thought: Will M15 affect the amount of 1024 available texture-slots?
    If no - M15 would offer a cool additional storage place for textures...
    If yes - how can I find out which slots were used?
    I saw a (is it new? just discovered it) method TBGL_TextureGetList which is not explained much in help-will it return as String as:
    "brick.bmp,gravel.bmp,[empty slot],water.bmp,,,,,[1011 * comma]"?
    Or will empty slots not appear? That would be bad...

    Next Question is about TargetedDisplayList-parameter:

    It says it can create a Display-List in Range from 1 to 255 or none - i assume if I don't create a displaylist I still can create an entity of it - or are M15 limited to 255 entity-"templates" in memory? I thought there were 1024 DL-slots available... Can I shift/copy the Display-List-data into another DL-slot somehow and release the m15-model from memory thereafter?

    What will happen if I load/or user drags in a model that has more than NumVertices specified in

    TBGL_m15InitModelBuffers NumModels, NumVertices

    Will pc explode or GPU get fried? will the program freeze or TBGL crash?
    Or will TBGL just not load this model?

    And some general thoughts into Entity-direction from m15-sight:
    Would there be a way to get m15-data to Entity (except parsing the file-text and squeeze it into display-list) loaded from m15-file directly whithout initializing m15ModelBuffer? Like this:
    ParentEntityID = TBGL_EntityCreateFromFileM15(sceneID, TBGL_EntityGetFreeID( sceneID, StartingEntityID ), sFilename, lChildren(), sTextures() )
    
    which loads the m15-data to some Entity-slot and creates children-entities itself and assigns them to free slots which follow,
    return ParentID if succeeds or 0 if fails. Function could apply textures optional - but has to be possible to get untextured entities returned.

    Children() and Textures() could behave as passed array x() in "Parse(myText, x, $crlf)" and should hold the list of child-entity-IDs and the names of Texturefiles.
    Their Ubounds will tell how much and their content the needed information. Other way - just pass single string byref can return a string of longs or delimited texture-filenames which user can parse himself if needed.

    I think this would build a bridge from the past to the future and could result in a useful skeleton for later entity-loading-functions from other 3d-mesh-data-formats...
    Last edited by ReneMiner; 17-05-2013 at 10:06.
    I think there are missing some Forum-sections as beta-testing and support

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

    texture path for tbgl_m15LoadModel is relative to script file, but you can specify full path too. If you want it to be relative to model file, you can use the power of FILE module, like:
    String modelFile = "C:\Data\MyModel.m15"
    tbgl_m15LoadModel modelFile, File_PathSplit(modelFile, %Path_RootPath)+"\Textures", 1, 0, %TBGL_NORMAL_SMOOTH
    
    The models use the shared pool of 1024 textures, but they do it in kind of smart way. If you have 3 different models, but all use the same texture, then the texture is not loaded 3 times, but loaded just for first model and the other 2 models don't load it and just use that texture. It is good way to save GPU memory.

    The textures used by M15 files appear in TBGL_GetTextureNames.

    The TargetDisplayList - good catch, it is not limited to 1..255 but to 1..1024 or other, if you use TBGL_NewListSpace to allocate custom list. I will correct it in help file. I guess this will be wrong on more places, I will need to make deep check.

    What will happen if I load/or user drags in a model that has more than NumVertices specified in
    Every time you do this, a little kitten dies! No, seriously, the loading will continue. There might be a speed penalty, but model should load fine.

    Regarding TBGL_EntityCreateFromFileM15, I will think about it.


    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

  7. #7
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,535
    Rep Power
    171
    The problem about texture-path is not splitting the path but what textures have to be loaded. I would need to check inside the m15-file in advance which texture-files are needed and search for their locations. So if I have those textures already in "my pool" - I would need to change the texture-ID in the model-slot somehow- probably impossible. On the other side - I would have to search for their location in TBGL_GetTextureList or to search through all slots using to find out their slot and update my pool then. Since m15 is limited to bmp/tga it's not such big a problem because the filenames appear then.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. little sphero and effect example with entities
    By Lionheart008 in forum TBGL General
    Replies: 7
    Last Post: 08-04-2009, 14:20
  2. Scenes and Entities
    By Intio in forum thinBasic General
    Replies: 2
    Last Post: 09-12-2008, 20:44
  3. Bone deformation and entities
    By Michael Hartlef in forum TBGL General
    Replies: 7
    Last Post: 16-02-2008, 02:16
  4. SampleScripts: Moving in 3D using entities
    By Petr Schreiber in forum TBGL General
    Replies: 3
    Last Post: 13-01-2008, 21:51
  5. TBGL 0.2.1 - Entities out of cage !
    By Petr Schreiber in forum TBGL General
    Replies: 21
    Last Post: 28-10-2007, 15:16

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
  •