SyntaxBomb - Indie Coders

Languages & Coding => AGK => Topic started by: RemiD on February 24, 2018, 11:10:02 PM

Title: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on February 24, 2018, 11:10:02 PM
Hello,

Since some of you guys have a good experience using AGK, can you please give me some infos :

Is it possible to create surfaces, vertices, triangles ?

If yes,
how many vertices, and how many triangles are allowed in a surface ?

With Blitz3d, there is a limit, which is apparently arbitrary, around 32000 vertices and 32000 triangles in a surface, or you can get a "memory access violation" at renderworld().

And this is really really annoying when trying to build 3d environments by assembling premade parts (or generating the parts) with code.

Just curious...

Thanks,
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Qube on February 24, 2018, 11:28:53 PM
AGK can do this with a mix of memblock mesh commands. I don't know of any limits as the docs make no reference ( that I can see ) to limits.

The is this from one of updates :

Quote
Removed the 2 million vertex limit on meshes, now only limited by memory

https://www.appgamekit.com/documentation/Reference/Memblock.htm

AddObjectMeshFromMemblock
CreateMemblockFromObjectMesh
CreateObjectFromMeshMemblock
GetMeshMemblockVertexAlpha
GetMeshMemblockVertexBlue
GetMeshMemblockVertexGreen
GetMeshMemblockVertexNormalX
GetMeshMemblockVertexNormalY
GetMeshMemblockVertexNormalZ
GetMeshMemblockVertexRed
GetMeshMemblockVertexU
GetMeshMemblockVertexV
GetMeshMemblockVertexX
GetMeshMemblockVertexY
GetMeshMemblockVertexZ
SetMeshMemblockVertexColor
SetMeshMemblockVertexNormal
SetMeshMemblockVertexPosition
SetMeshMemblockVertexUV
SetObjectMeshFromMemblock
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: GaborD on February 25, 2018, 01:53:00 AM
I haven't done much with mesh generation yet, but my first tests worked great.
Can tell you more soon, planning on playing around more with it. Will see if I can reach the limits. :p
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on February 25, 2018, 07:46:16 AM
Quote
Removed the 2 million vertex limit on meshes, now only limited by memory
oh ! that would be good  :o
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on February 25, 2018, 09:24:53 AM
@RemiD

I knew you couldn't resist the 'Dark' side.  ;D
May the source be with you.

Enjoy buddy.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on February 25, 2018, 09:34:47 AM
@Rick>>i am still a BB coder, i am just curious ;)
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Kronos on February 25, 2018, 12:38:01 PM
Could someone do a quick demo of creating a mesh from scratch in AGK because I can't figure it out.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 02, 2018, 10:33:42 AM
@Kronos>>AGK is apparently the new great language / engine, but still no example to create a simple 3d mesh, you know what i mean ?

a simple mesh in blitzbasic (1 surface, 3 vertices, 1 triangle)
Code: [Select]
Mesh = CreateMesh()
Surface = CreateSurface(Mesh)
V0% = AddVertex(Surface,-0.5,0.0,-0.5)
V1% = AddVertex(Surface,0.0,0.0,0.5)
V2% = AddVertex(Surface,0.5,0.0,-0.5)
AddTriangle(Surface,V0,V1,V2)
UpdateNormals(Mesh)
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 02, 2018, 06:18:05 PM
I know what you mean.  :P
But it's a bit of a different philosophy; I guess they figure everyone even remotely serious about game making is using external tools for 3d models, not primitives, in code built meshes etc anyway, and in that light it's working great.

However.. for a people who like to tinker and wanna go down the road of exploration or do things differently then you might have to make a few mind leaps.

Basically afaik everything is possible but you'd use memory blocks to make things in. Similar as banks I guess?

Code examples [deleted due to objection by the original creator]:

Random Texture Creator
Code: [Select]


Or:

Generator Audio
Code: [Select]

So basically you can make use and create all you like, however you can also make requests for commands you find are missing as it is very much in development still.



Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 02, 2018, 07:10:07 PM
Thanks for the example to create a texture, can you show us what it outputs ? (or describe it)

In blitzbasic it would be something like :
Code: [Select]
Texture = CreateTexture(width,height,flags) ;flags -> 1: color , 2 : alpha , 4 : mask
SetBuffer(TextureBuffer(Texture))
 ClsColor(000,000,000) : Cls() ;put a black background
 WritePix(X,Y,R,G,B,A) ;write a texel at X,Y of the R,G,B color with A transparency


Quote
I guess they figure everyone even remotely serious about game making is using external tools for 3d models, not primitives
Where have you seen that i use primitives in my games ?
It can be useful to be able to analyze the surface(s), material(s), texture(s), joints/bones, of a mesh and then to create surfaces, vertices, triangles, materials, textures, joints/bones, depending on the datas gathered, and even "serious" unity / unreal users understand that :
->if you want to merge all surfaces which share the same material/texture in one surface one texture (faster to render)
->if you want to merge premade parts in one surface one material one texture (a custom character is made of several premade parts like body, head, hair, clothes, armors...)
->if you want to create a texture atlas and change the vertices uvs (several textures put in one big texture)
->if you want to create meshes made of premade parts, proceduraly (to have different environments, more diversity)
->if you want to add some effects like scratches / blood on the texture of a character or scratches / damages on the texture of a vehicle.
->if you want to create custom effects like volumetric glow, volumetric light rays, glow rects (ala doom3), texels emitting particles...

Really it can be useful...


( i am still waiting for an example to create a simple 3d mesh (1 surface, 3 vertices, 1 triangle) in AGK :P )
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Qube on March 02, 2018, 07:55:11 PM
Quote
( i am still waiting for an example to create a simple 3d mesh (1 surface, 3 vertices, 1 triangle) in AGK :P )
Here's something to shut you up :P - It creates a cube in code.

Written by puzzler2018 on the AGK forums :

Code: [Select]
function createobjectOurOwn()
 
    objfile = OpenToWrite("cube.obj")
    WriteLine(objfile,"v -0.500000 -0.500000 0.500000")
WriteLine(objfile,"v 0.500000 -0.500000 0.500000")
WriteLine(objfile,"v -0.500000 0.500000 0.500000")
WriteLine(objfile,"v 0.500000 0.500000 0.500000")
WriteLine(objfile,"v -0.500000 0.500000 -0.500000")
WriteLine(objfile,"v 0.500000 0.500000 -0.500000")
WriteLine(objfile,"v -0.500000 -0.500000 -0.500000")
WriteLine(objfile,"v 0.500000 -0.500000 -0.500000")
WriteLine(objfile,"vt 0.000000 0.000000")
WriteLine(objfile,"vt 1.000000 0.000000")
WriteLine(objfile,"vt 0.000000 1.000000")
WriteLine(objfile,"vt 1.000000 1.000000")
WriteLine(objfile,"vn 0.000000 0.000000 1.000000")
WriteLine(objfile,"vn 0.000000 1.000000 0.000000")
WriteLine(objfile,"vn 0.000000 0.000000 -1.000000")
WriteLine(objfile,"vn 0.000000 -1.000000 0.000000")
WriteLine(objfile,"vn 1.000000 0.000000 0.000000")
WriteLine(objfile,"vn -1.000000 0.000000 0.000000")
WriteLine(objfile,"s 1")
WriteLine(objfile,"f 1/1/1 2/2/1 3/3/1")
WriteLine(objfile,"f 3/3/1 2/2/1 4/4/1")
WriteLine(objfile,"s 2")
WriteLine(objfile,"f 3/1/2 4/2/2 5/3/2")
WriteLine(objfile,"f 5/3/2 4/2/2 6/4/2")
WriteLine(objfile,"s 3")
WriteLine(objfile,"f 5/4/3 6/3/3 7/2/3")
WriteLine(objfile,"f 7/2/3 6/3/3 8/1/3")
WriteLine(objfile,"s 4")
WriteLine(objfile,"f 7/1/4 8/2/4 1/3/4")
WriteLine(objfile,"f 1/3/4 8/2/4 2/4/4")
WriteLine(objfile,"s 5")
WriteLine(objfile,"f 2/1/5 8/2/5 4/3/5")
WriteLine(objfile,"f 4/3/5 8/2/5 6/4/5")
WriteLine(objfile,"s 6")
WriteLine(objfile,"f 7/1/6 1/2/6 5/3/6")
WriteLine(objfile,"f 5/3/6 1/2/6 3/4/6")
 
CloseFile(objfile)
cube=LoadObject("cube.obj")
endfunction cube
[/quote]
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 02, 2018, 07:58:04 PM
@Qube>>thanks, but that's not what i have asked, your code example shows how to write datas in an obj file. :P

I will try to search the AGK forum, there must be an example somewhere !

Oups, apparently no result for AGK... ;)

1 result for darkbasic here : https://forum.thegamecreators.com/thread/115155#msg1309221
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: TomToad on March 02, 2018, 09:12:51 PM
For creating a mesh, you start by creating a memblock.  You then fill the memblock with all the information about the mesh.  Then you use CreateObjectFromMeshMemblock() (http://"https://www.appgamekit.com/documentation/Reference/Memblock/CreateObjectFromMeshMemblock.htm") to create the 3d object.  You can use SetObjectMeshFromMemblock() to modify an existing object.

More complicated than B3D, but doable.  I'll see if I can knock up an example for you, if I can figure out how to properly fill out the fields :)
Here is an example of modifying an existing mesh.
Code: [Select]
box = CreateObjectBox(10,10,10)
meshmemblock = CreateMemblockFromObjectMesh(box,1)
direction as float = 1.0
time as float
wait as float = 5.0
vertex as integer[2] = [1,19,20]

do
time = GetFrameTime()
RotateObjectLocalX(box,.1)
RotateObjectLocalY(box,.2)
RotateObjectLocalZ(box,.3)
for i = 0 to 2
SetMeshMemblockVertexPosition(meshmemblock,vertex[i],
GetMeshMemblockVertexX(meshmemblock,vertex[i])+direction*time,
GetMeshMemblockVertexY(meshmemblock,vertex[i])+direction*time,
GetMeshMemblockVertexZ(meshmemblock,vertex[i])+direction*time)
next
wait = wait - time
if wait <= 0.0
wait = 5.0
direction = -direction
endif
SetObjectMeshFromMemblock(box,1,meshmemblock)
sync()
loop
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 02, 2018, 09:21:00 PM
@RemiD:
Quote
( i am still waiting for an example to create a simple 3d mesh (1 surface, 3 vertices, 1 triangle) in AGK :P )
I knew of course you were gonna say that..  :D
But if you're waiting for me to do it then it's gonna take a loooong time for I'm far too busy to delve into that.

Quote
Really it can be useful...
No doubt about that.

I'd like to see a few commands like that. Someone said the current approach has to do with opengl/es??



Here are some other interesting threads(unrelated)..

Making a simple Old School Style FPS Game in AppGameKit 2
(https://i.imgur.com/JlCg045.gif)
https://forum.thegamecreators.com/thread/221520?page=2

Landscape shader
https://forum.thegamecreators.com/thread/221599?page=1#msg2619814





@TomToad:
Now there's a nice demonstration of the concept.
This deserves to also be posted on the AGK and also on their Online Commands Help, right here I'd say:
https://www.appgamekit.com/documentation/Reference/Memblock/SetMeshMemblockVertexPosition.htm


Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 02, 2018, 10:13:56 PM
@TomToad>>thanks, but apparently your code example shows how to change the positions of the vertices of an existing surface/mesh, but not how to create a new mesh / surface, vertices, triangles.

And from what i understand in the code, a "memblock" in agk, is what we call a "surface" in blitzbasic / unity.
Oh no ! apparently it is different, a memblock is more like a bank, isn't it ? What a mess !  ;D

From what i can read here : https://www.appgamekit.com/documentation/Reference/Memblock.htm

I don't see a command to create a vertex or a triangle, you can get some vertex properties or set some vertex properties, but that's all...

Oh well, back to blitzbasic !
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 02, 2018, 10:15:09 PM
@RemiD:

Quote
Thanks for the example to create a texture, can you show us what it outputs ? (or describe it)

Already posted it before, check out the woodtexture on the stairs railing and the pole:
(http://i63.tinypic.com/2lximoo.jpg)

[deleted code due to objection of original creator]

Random Texture Demo using the function:
Code: [Select]

(http://i66.tinypic.com/16iil2f.jpg)

Really like the powerful effect of such a small function.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 02, 2018, 10:24:19 PM
@RemiD
Quote
And from what i understand in the code, a "memblock" in agk, is what we call a "surface" in blitzbasic / unity.

Here's my 50cents:  ;)

No, for if you check the other examples(soundgenerator, texture creation) you see they all use memblocks. It's more like Blitz'es memorybanks or a buffer I think.
You can use them for anything really. Handy for manipulating files, like images, sound, meshes or other kinds of structured data.

Memblock related commands:
•CreateMemblockFromSound ( soundID )
•CreateSoundFromMemblock ( memID )
•CopyMemblock ( memSrcID, memDstID, srcOffset, dstOffset, size )
•CreateMemblock ( memID, size )
•DeleteMemblock ( memID )
•GetMemblockByte ( memID, offset )
•GetMemblockByteSigned ( memID, offset )
•GetMemblockExists ( memID )
•GetMemblockFloat ( memID, offset )
•GetMemblockInt ( memID, offset )
•GetMemblockShort ( memID, offset )
•GetMemblockSize ( memID )
•GetMemblockString ( memID, offset, length )
•SetMemblockByte ( memID, offset, value )
•SetMemblockByteSigned ( memID, offset, value )
•SetMemblockFloat ( memID, offset, value )
•SetMemblockInt ( memID, offset, value )
•SetMemblockShort ( memID, offset, value )
•SetMemblockString ( memID, offset, value )
•CreateFileFromMemblock ( filename, memID )
•CreateMemblockFromFile ( filename )
•CreateImageFromMemblock ( imageID, memID )
•CreateMemblockFromImage ( imageID )
•AddObjectMeshFromMemblock ( objID, memID )
•CreateMemblockFromObjectMesh ( objID, meshIndex )
•CreateObjectFromMeshMemblock ( memID )
•GetMeshMemblockVertexAlpha ( memID, vertexIndex )
•GetMeshMemblockVertexBlue ( memID, vertexIndex )
•GetMeshMemblockVertexGreen ( memID, vertexIndex )
•GetMeshMemblockVertexNormalX ( memID, vertexIndex )
•GetMeshMemblockVertexNormalY ( memID, vertexIndex )
•GetMeshMemblockVertexNormalZ ( memID, vertexIndex )
•GetMeshMemblockVertexRed ( memID, vertexIndex )
•GetMeshMemblockVertexU ( memID, vertexIndex )
•GetMeshMemblockVertexV ( memID, vertexIndex )
•GetMeshMemblockVertexX ( memID, vertexIndex )
•GetMeshMemblockVertexY ( memID, vertexIndex )
•GetMeshMemblockVertexZ ( memID, vertexIndex )
•SetMeshMemblockVertexColor ( memID, vertexIndex, red, green, blue, alpha )
•SetMeshMemblockVertexNormal ( memID, vertexIndex, x, y, z )
•SetMeshMemblockVertexPosition ( memID, vertexIndex, x, y, z )
•SetMeshMemblockVertexUV ( memID, vertexIndex, u, v )
•SetObjectMeshFromMemblock ( objID, meshIndex, memID )


Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 02, 2018, 10:33:28 PM
Quote
It's more like Blitz'es memorybanks or a buffer I think.
yes i agree, i edited my post while you were writing this post...
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 02, 2018, 10:45:47 PM
Quote
It's more like Blitz'es memorybanks or a buffer I think.
yes i agree, i edited my post while you were writing this post...

D.. Now I have to re-re-edit my post not too look silly again.. lol

But you are right: there are no AddVertex() or DeleteVertex() commands afaik.
Unless SetMeshMemblockVertexPosition ( memID, vertexIndex, x, y, z ) add's one if it doesn't exits yet?


Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 03, 2018, 08:40:28 AM
No, apparently you can't create a vertex or create a triangle, you can only analyze an existing surface or modify an existing surface. Or if it is possible, where are the commands ?

That may be why the code example that Qube posted shows how to export (save) a mesh as an obj file and then load it...

Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: TomToad on March 03, 2018, 10:15:47 AM
I am very close to getting a triangle done. Unfortunately,I ran out of time and won't be back at my computer for the next 12 hours. Creating a mesh is a little complicated as you also need to provide information for the shaders, even if you don't use one as AGK still uses a default shader.  Fortunately, once you create the long and difficult mesh header, you can just copy it over to any mesh using the same structure, just change the vertex count and offset to point to the right locations.

Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 03, 2018, 10:23:57 AM
@TomToad
That's sounds really interesting. Can't wait to see how that works.

BTW: hope you don't mind, but I think your previous example is a pretty good demo of the commands, so I submitted it to the AGK command help like this:

Code: [Select]
// Project: CreateObjectFromMeshMemblock
// Created: 2018-03-02
// By: TomToad

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "CreateObjectFromMeshMemblock" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts


box = CreateObjectBox(10,10,10)
meshmemblock = CreateMemblockFromObjectMesh(box,1)
direction as float = 1.0
time as float
wait as float = 5.0
vertex as integer[2] = [1,19,20]

do
time = GetFrameTime()
RotateObjectLocalX(box,.1)
RotateObjectLocalY(box,.2)
RotateObjectLocalZ(box,.3)
for i = 0 to 2
SetMeshMemblockVertexPosition(meshmemblock,vertex[i],
GetMeshMemblockVertexX(meshmemblock,vertex[i])+direction*time,
GetMeshMemblockVertexY(meshmemblock,vertex[i])+direction*time,
GetMeshMemblockVertexZ(meshmemblock,vertex[i])+direction*time)

next
wait = wait - time
if wait <= 0.0
wait = 5.0
direction = -direction
endif
SetObjectMeshFromMemblock(box,1,meshmemblock)
sync()
loop

At: https://www.appgamekit.com/documentation/Reference/Memblock/SetMeshMemblockVertexPosition.htm
Currently waiting for approval..
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 03, 2018, 11:07:31 AM
@TomToad>>curious to see your code example...

I suppose that you can create custom functions to read write in memblocks (in AGK), similarly that what we do to read write in banks (in blitzbasic), it would simplify things greatly !
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Naughty Alien on March 03, 2018, 11:50:07 AM
@TomToad>>curious to see your code example...

I suppose that you can create custom functions to read write in memblocks (in AGK), similarly that what we do to read write in banks (in blitzbasic), it would simplify things greatly !

...yes..actually, you can write in C++ (AGK) and then export plugin for AGK to use and expand API on the way you like it..thats my work in progress right now (rewriting old Lotus particle system for B3D, for AGK, as a plugin)..
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 03, 2018, 02:36:18 PM
At Naughty Alien
Quote
...yes..actually, you can write in C++ (AGK) and then export plugin for AGK to use and expand API on the way you like it..thats my work in progress right now (rewriting old Lotus particle system for B3D, for AGK, as a plugin)..

That's great used to love that. Had a demo of it long time ago, but can't remember all the features though. I take that it holds advantages over the AGK's build in particle system?
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Naughty Alien on March 03, 2018, 02:44:15 PM
At Naughty Alien
Quote
...yes..actually, you can write in C++ (AGK) and then export plugin for AGK to use and expand API on the way you like it..thats my work in progress right now (rewriting old Lotus particle system for B3D, for AGK, as a plugin)..

That's great used to love that. Had a demo of it long time ago, but can't remember all the features though. I take that it holds advantages over the AGK's build in particle system?

..in essence it is Lotus'ed AGK particle system..more a system which allows me to copy/paste some code i used before (i had Lotus rewritten for NF/C++/) , and added some neat features including physics particles, soft particles, etc..
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 03, 2018, 07:09:02 PM
Wow that are indeed nice features you've added.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 03, 2018, 07:18:31 PM
Got some feedback from janbo on the AGK forums about RemiD's question:

Quote
In the Minecraft clone thread for example I posted code to create separate faces for cubes from memblock it can also be used to generate all sorts of models.
 This is the important part:
Code: [Select]
function CreateFace(CubeX,CubeY,CubeZ,Direction)
    if Cube[CubeX,CubeY,CubeZ].Face[Direction]=0
        Size#=0.5
 
        MemblockID=CreateMeshMemblock()
 
        select Direction
            case DUP:
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+0,CubeX-Size#,CubeY+Size#,CubeZ+Size#)     // Vertex
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+3*4,0,1,0)     // Normals
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+6*4,0,0)       // UV
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+8*4,CubeX-Size#,CubeY+Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+11*4,0,1,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+14*4,0,1)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+16*4,CubeX+Size#,CubeY+Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+19*4,0,1,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+22*4,1,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+24*4,CubeX+Size#,CubeY+Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+27*4,0,1,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+30*4,1,1)
            endcase
            case DDOWN:
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+0,CubeX-Size#,CubeY-Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+3*4,0,-1,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+6*4,0,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+8*4,CubeX-Size#,CubeY-Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+11*4,0,-1,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+14*4,0,1)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+16*4,CubeX+Size#,CubeY-Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+19*4,0,-1,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+22*4,1,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+24*4,CubeX+Size#,CubeY-Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+27*4,0,-1,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+30*4,1,1)
            endcase
            case DRIGHT:
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+0,CubeX+Size#,CubeY-Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+3*4,1,0,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+6*4,1,1)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+8*4,CubeX+Size#,CubeY+Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+11*4,1,0,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+14*4,1,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+16*4,CubeX+Size#,CubeY-Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+19*4,1,0,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+22*4,0,1)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+24*4,CubeX+Size#,CubeY+Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+27*4,1,0,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+30*4,0,0)
            endcase
            case DLEFT:
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+0,CubeX-Size#,CubeY+Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+3*4,-1,0,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+6*4,0,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+8*4,CubeX-Size#,CubeY-Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+11*4,-1,0,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+14*4,0,1)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+16*4,CubeX-Size#,CubeY+Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+19*4,-1,0,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+22*4,1,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+24*4,CubeX-Size#,CubeY-Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+27*4,-1,0,0)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+30*4,1,1)
            endcase
            case DFRONT:
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+0,CubeX-Size#,CubeY+Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+3*4,0,0,-1)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+6*4,0,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+8*4,CubeX-Size#,CubeY-Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+11*4,0,0,-1)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+14*4,0,1)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+16*4,CubeX+Size#,CubeY+Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+19*4,0,0,-1)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+22*4,1,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+24*4,CubeX+Size#,CubeY-Size#,CubeZ-Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+27*4,0,0,-1)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+30*4,1,1)
            endcase
            case DBACK:
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+0,CubeX+Size#,CubeY+Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+3*4,0,0,1)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+6*4,0,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+8*4,CubeX+Size#,CubeY-Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+11*4,0,0,1)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+14*4,0,1)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+16*4,CubeX-Size#,CubeY+Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+19*4,0,0,1)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+22*4,1,0)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+24*4,CubeX-Size#,CubeY-Size#,CubeZ+Size#)
                SetMemblockVec3(MemblockID,VERTEX_OFFSET+27*4,0,0,1)
                SetMemblockVec2(MemblockID,VERTEX_OFFSET+30*4,1,1)
            endcase
        endselect
 
        //~ Indices
        SetMemblockInt(MemblockID,IndexOffset+0*4,0)
        SetMemblockInt(MemblockID,IndexOffset+1*4,1)
        SetMemblockInt(MemblockID,IndexOffset+2*4,2)
        SetMemblockInt(MemblockID,IndexOffset+3*4,2)
        SetMemblockInt(MemblockID,IndexOffset+4*4,1)
        SetMemblockInt(MemblockID,IndexOffset+5*4,3)
 
        Cube[CubeX,CubeY,CubeZ].Face[Direction]=BuildMeshMemblock(MemblockID)
 
        SetFaceTexture(CubeX,CubeY,CubeZ,Direction)
    endif
endfunction
 
// here starts the memblock manipulation functions
function CreateMeshMemblock()
    VertexCount=4
    IndexCount=6
    Attributes=3
    VertexSize=3*4+3*4+2*4
    IndexOffset=VERTEX_OFFSET+(VertexCount*VertexSize)
 
    MemblockID=Creatememblock(VERTEX_OFFSET+(VertexCount*VertexSize)+(IndexCount*4))
    SetMemblockInt(MemblockID,0,VertexCount)
    SetMemblockInt(MemblockID,4,IndexCount)
    SetMemblockInt(MemblockID,8,Attributes)
    SetMemblockInt(MemblockID,12,VertexSize)
    SetMemblockInt(MemblockID,16,VERTEX_OFFSET)
    SetMemblockInt(MemblockID,20,IndexOffset)
 
    AttributeOffset=24
    SetMemblockByte(MemblockID,AttributeOffset,0) // Float type component
    SetMemblockByte(MemblockID,AttributeOffset+1,3) // number of components
    SetMemblockByte(MemblockID,AttributeOffset+2,0) // normalize flag
    SetMemblockByte(MemblockID,AttributeOffset+3,12) // string length
    SetMemblockString(MemblockID,AttributeOffset+4,"position"+chr(0)) // string
 
    inc AttributeOffset,16
    SetMemblockByte(MemblockID,AttributeOffset,0) // Float type component
    SetMemblockByte(MemblockID,AttributeOffset+1,3) // number of components
    SetMemblockByte(MemblockID,AttributeOffset+2,0) // normalize flag
    SetMemblockByte(MemblockID,AttributeOffset+3,8) // string length
    SetMemblockString(MemblockID,AttributeOffset+4,"normal"+chr(0)) // string
 
    inc AttributeOffset,12
    SetMemblockByte(MemblockID,AttributeOffset,0) // Float type component
    SetMemblockByte(MemblockID,AttributeOffset+1,2) // number of components
    SetMemblockByte(MemblockID,AttributeOffset+2,0) // normalize flag
    SetMemblockByte(MemblockID,AttributeOffset+3,4) // string length
    SetMemblockString(MemblockID,AttributeOffset+4,"uv"+chr(0)) // string
endfunction MemblockID
 
function BuildMeshMemblock(MemblockID)
    ObjectID=CreateObjectFromMeshMemblock(MemblockID)
    DeleteMemblock(MemblockID)
endfunction ObjectID
 
function SetMemblockVec3(MemblockID,Offset,x#,y#,z#)
    SetMemblockFloat(MemblockID,Offset,x#)
    SetMemblockFloat(MemblockID,Offset+4,y#)
    SetMemblockFloat(MemblockID,Offset+8,z#)
endfunction
 
function SetMemblockVec2(MemblockID,Offset,u#,v#)
    SetMemblockFloat(MemblockID,Offset,u#)
    SetMemblockFloat(MemblockID,Offset+4,v#)
endfunction
Quote
In the CreateFace() function I set the vertex position, normal an uv coordinate for every vertex of one side of the cube.

 You need these steps:
 1. MemblockID=CreateMeshMemblock() // generate the mesh
 2.
 - SetMemblockVec3(MemblockID,VERTEX_OFFSET+0,0,0,0) // set Vertex position (you can also use SetMeshMemblockVertexPosition() here)
 - SetMemblockVec3(MemblockID,VERTEX_OFFSET+3*4,0,1,0) // Normals
 - SetMemblockVec2(MemblockID,VERTEX_OFFSET+6*4,0,0) // UV
 3. SetMemblockInt(MemblockID,IndexOffset+0*4,0) // (optional) set the indices
 4. ObjectID=BuildMeshMemblock(MemblockID) // finish and return the object ID

[Edit] I wonder how we are supposed to remove a mesh from an object previously added with AddObjectMeshFromMemblock[/Edit]
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 03, 2018, 07:18:55 PM
I rather meant to code specific functions (for AGK) to help read / write in banks (memblocks) to simplify the code syntax... it is probably what the functions CreateMesh(), CreateSurface(Mesh), AddVertex(Surface,X,Y,Z), AddTriangle(Surface,V0I,V1I,V2I), and others surface / vertex / triangle related functions, in Blitzbasic, do...
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: TomToad on March 04, 2018, 09:09:27 AM
Ok, I now have my triangle appearing on the screen.
Code: [Select]
// Project: triangle
// Created: 2018-03-03

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "triangle" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

//first we will create a memblock to hold the mesh
memblock = CreateMemblock(160)

//Now we need to fill it with mesh data
SetMemblockInt(memblock,0,3) //3 vertices
SetMemblockInt(memblock,4,3) //3 indices, not necissary for simple triangle, but we do it here for completeness
SetMemblockint(memblock,8,3) //Our mesh has 3 attributes, position, normal, color
Setmemblockint(memblock,12,28) //number of bytes each vertext takes up. x,y,z,nx,ny,nz,color * 4
SetMemblockInt(memblock,16,64) //offset to vertex data
SetMemblockInt(memblock,20,148) //offset to index data

//Attribute information, I'm combining all bytes into a single int. 
//   Little endiness means order is string length, normal flag, component count, data type (data will
//   be written to the MemBlock in reverse order).
SetMemBlockInt(memblock,24,0x0C000300) //float, 3 components, no normalizing, position
SetMemblockString(memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300) //same as position, but for normals
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x08010401) //For color we have byte, 4 components, normalize data
SetMemblockString(memblock,56,"color")

//Now we can enter vertex data

Vertex as float[8] = [5.0,-5.0,0.0,-5.0,-5.0,0.0,0.0,5.0,0.0]
Color as integer[2] = [0xFFFF0000,0xFF00FF00,0xFF0000FF]

for i = 0 to 2
SetMemblockFloat(memblock,64+i*28,Vertex[i*3]) //x
SetMemblockFloat(memblock,68+i*28,Vertex[i*3+1]) //y
SetMemblockFloat(memblock,72+i*28,Vertex[i*3+2]) //z
SetMemblockFloat(memblock,76+i*28,0.0) //nx
SetMemblockFloat(memblock,80+i*28,0.0) //ny
SetMemblockFloat(memblock,84+i*28,-1.0) //nz
SetMemblockInt(memblock,88+i*28,Color[i]) //color
next
 // Now the index data
 SetMemblockInt(memblock,148,0)
 SetMemblockInt(memblock,152,2)
 SetMemblockInt(memblock,156,1)

//Now to create the object
triangle = CreateObjectFromMeshMemblock(memblock)


do
   

    Print( ScreenFPS() )
    Sync()
loop
A few things to note.  I packed the attribute data (4 bytes) into one integer.  The order of the bytes are reversed since integers are little endian and the bytes will be reversed when written to memory.

AGK allows different attributes to be defined.  My example only defines position, normal, and color.  Just add the attributes you want and define them in the vertex information.  You can even define custom attributes as long as you write a shader that takes care of them.  A complete list of standard attributes are in the AGK command help for CreateObjectFromMeshMemblock().

I found trying to define the header the most complicated part of the code.  Won't be so difficult now that I know how to do it.  When I get the time, I'll write out a short tutorial explaining just what each of the fields are for.  Once the header is created, it can be copied to any mesh memblock that uses the same structure.

One negative that I found is that you need to be able to determine how big to create the memblock before you start adding the data.  There doesn't seem to be an easy way to expand memblock size without creating a new one and copying over the data.  That is only a problem if you don't know ahead of time how many vertices and indices your mesh will need. It might be easier to create the structure using a custom type and then creating the memblock when you are done with that.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 04, 2018, 09:48:52 AM
@TomToad>>thanks for the code example, it looks quite complicated to create just a simple 3d triangle. I find it already complex enough to find which vertices indexes to use to create a triangle procedurally so i if we have to also calculate the specific "memory block" to write / read in, well a good way to become insane imo... Unless if somebody writes functions that simplify this process...

Not something i want to try at the moment. (but thanks)
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 04, 2018, 06:49:04 PM
@TomToad

Simply: wow!
Bit complicated but it shows that it can be done.

Quote
I'll write out a short tutorial explaining just what each of the fields are for.  Once the header is created, it can be copied to any mesh memblock that uses the same structure.
That be really great. I'm sure a lot of people would benefit from that.


I hope you submitted the example to https://www.appgamekit.com/documentation/Reference/Memblock/CreateObjectFromMeshMemblock.htm

If you didn't yet, then I can do it for you(with your permission) and nominate you for one of these badge thingies they apparently are using for honoring people that contribute to the community, if you care for that of course..


Your other example has been validated and accepted btw, see:
https://www.appgamekit.com/documentation/Reference/Memblock/SetMeshMemblockVertexPosition.htm
So you are now 'immortalized' in the AGK help file. 8)

Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 04, 2018, 07:42:22 PM
As i said previously, the functions (in Blitz3d) to create a mesh, surface, vertices, triangles, or to get properties from the surface, vertices, triangles, or to set the properties of the surface, vertices, triangles, are probably "shortcuts" to read/write in memory banks, so you could probably code similar functions for AGK, once you understand how it works...
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 06, 2018, 05:35:43 PM
I've launched a thread on the AGK forum, might be interesting regarding the opinions about this over there:
https://forum.thegamecreators.com/thread/221755

Apparently it raised some discussions, which- you never know- may lead to new command implementations.
Fingers x-ed.

[EDIT]
See TomToad's excellent tutorial:
https://www.syntaxbomb.com/index.php/topic,4235.0.html
Direct link:
http://www.tomtoad.com/AGK2/Tutorial/ProceduralMesh/ProceduralMeshAGK.html

(BTW: nominated TomToad for a AGK badge)  :)
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: TomToad on March 06, 2018, 10:17:40 PM
Here is a first attempt at adding mesh helper functions to AGK2. Save this as "mesh.agc"
Code: [Select]

Type Vertex
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
color as integer
endtype

Type Triangle
v1 as integer
v2 as integer
v3 as integer
endtype

Type Mesh
VertexList as Vertex[]
TriangleList as Triangle[]
endtype

Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, color as integer)
vert as vertex
vert.x = x
vert.y = y
vert.z = z
vert.nx = nx
vert.ny = ny
vert.nz = nz
vert.u = u
vert.v = v
vert.color = color
m.VertexList.Insert(vert)
endfunction

Function AddTriangle(m ref as Mesh, v1 as integer, v2 as integer, v3 as integer)
t as Triangle
t.v1 = v1
t.v2 = v2
t.v3 = v3
m.TriangleList.Insert(t)
endfunction

Function CreateObjectFromMesh(m ref as mesh)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 3
IndexOffset = 72 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,4)
SetMemblockInt(memblock,12,36)
SetmemblockInt(memblock,16,72)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
SetMemblockInt(memblock,60,0x08010401)
SetMemblockString(memblock,64,"color")

for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,72+i*36,m.VertexList[i].x)
SetMemblockFloat(memblock,76+i*36,m.VertexList[i].y)
SetMemblockFloat(memblock,80+i*36,m.VertexList[i].z)
SetMemblockFloat(memblock,84+i*36,m.VertexList[i].nx)
SetMemblockFloat(memblock,88+i*36,m.VertexList[i].ny)
SetMemblockFloat(memblock,92+i*36,m.VertexList[i].nz)
SetMemblockFloat(memblock,96+i*36,m.VertexList[i].u)
SetMemblockFloat(memblock,100+i*36,m.VertexList[i].v)
SetMemblockInt(memblock,104+i*36,m.VertexList[i].color)
next

for i = 0 to m.TriangleList.Length
SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1)
SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2)
SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3)
next
id = CreateObjectFromMeshMemblock(memblock)
DeleteMemblock(memblock)
endfunction id

Example of usage.  For this example to work, copy the file "mesh3-1.jpg" from the "AppGameKit\Samples\3D\3D-FirstPersonExample\media" folder to the project media folder, or save your own texture and change line 78 accordingly.
Code: [Select]
// Project: Cube
// Created: 2018-03-06

#insert "mesh.agc"
// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Cube" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

cube as Mesh

//face 1
AddVertex(Cube,-5,-5,-5,0,0,-1,0,1,0xFFFFFFFF) //0
AddVertex(Cube,-5,5,-5,0,0,-1,0,0,0xFFFFFFFF) //1
AddVertex(Cube,5,5,-5,0,0,-1,1,0,0xFFFFFFFF) //2
AddVertex(Cube,5,-5,-5,0,0,-1,1,1,0xFFFFFFFF) //3

AddTriangle(Cube,0,2,1)
AddTriangle(Cube,0,3,2)

//face 2
AddVertex(Cube,5,5,-5,1,0,0,0,0,0xFF0000FF) //4
AddVertex(Cube,5,5,5,1,0,0,1,0,0xFF0000FF) //5
AddVertex(Cube,5,-5,5,1,0,0,1,1,0xFF0000FF) //6
AddVertex(Cube,5,-5,-5,1,0,0,0,1,0xFF0000FF) //7

AddTriangle(Cube,4,7,5)
AddTriangle(Cube,5,7,6)

//face 3
AddVertex(Cube,5,5,5,0,0,1,0,0,0xFF00FF00) //8
AddVertex(Cube,5,-5,5,0,0,1,0,1,0xFF00FF00) //9
AddVertex(Cube,-5,-5,5,0,0,1,1,1,0xFF00FF00) //10
AddVertex(Cube,-5,5,5,0,0,1,1,0,0xFF00FF00) //11

AddTriangle(Cube,8,9,10)
AddTriangle(Cube,10,11,8)

//face 4
AddVertex(Cube,-5,5,5,-1,0,0,0,0,0xFFFF0000) //12
AddVertex(Cube,-5,5,-5,-1,0,0,1,0,0xFFFF0000) //13
AddVertex(Cube,-5,-5,-5,-1,0,0,1,1,0xFFFF0000) //14
AddVertex(Cube,-5,-5,5,-1,0,0,0,1,0xFFFF0000) //15

AddTriangle(Cube,12,14,13)
AddTriangle(Cube,14,12,15)

//face 5
AddVertex(Cube,-5,5,5,0,1,0,0,0,0xFF00FFFF) //16
AddVertex(Cube,5,5,5,0,1,0,1,0,0xFF00FFFF) //17
AddVertex(Cube,5,5,-5,0,1,0,1,1,0xFF00FFFF) //18
AddVertex(Cube,-5,5,-5,0,1,0,0,1,0xFF00FFFF) //19

AddTriangle(Cube,16,18,17)
AddTriangle(Cube,16,19,18)

//face 6
AddVertex(Cube,5,-5,-5,0,-1,0,1,0,0xFFFFFF00) //20
AddVertex(Cube,-5,-5,-5,0,-1,0,0,0,0xFFFFFF00) //21
AddVertex(Cube,-5,-5,5,0,-1,0,0,1,0xFFFFFF00) //22
AddVertex(Cube,5,-5,5,0,-1,0,1,1,0xFFFFFF00) //23

Addtriangle(Cube,20,21,22)
Addtriangle(Cube,20,22,23)

cubeObject = CreateObjectFromMesh(cube)
image = loadimage("mesh3-1.jpg")
SetObjectImage(cubeObject,image,0)
do
    RotateObjectLocalX(cubeObject,.1)
    RotateObjectLocalY(cubeObject,.2)
    RotateObjectLocalZ(cubeObject,.3)

    Print( ScreenFPS() )
    Sync()
loop
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on March 06, 2018, 11:47:40 PM
Works like a charm.
(http://i68.tinypic.com/2hz1pwy.jpg)
Time for experiments.. Ehrr.. 00:46 : No-no, need to kick myself and go to bed. Have to get up in 5hrs ;)

Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Qube on March 07, 2018, 04:40:02 AM
Quote
Here is a first attempt at adding mesh helper functions to AGK2.
Super cool beans, nice one ;D - * shifty sideways looks * have you figured out how to delete bits yet? * continued shifty sideways looks *
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 07, 2018, 06:37:49 AM
@TomToad>>very good ! thanks :)


I don't use AGK, but i am curious about what it can do.

Can somebody please try to create a surface proceduraly to see if there is a vertices / triangles limit per surface (with Blitz3d, it would be around 32000 vertices / 32000 triangles per surface)

Here is a code example that you can convert :
Code: [Select]
Graphics3D(640,480,32,2)

SeedRnd(MilliSecs())

Global Camera = CreateCamera()
CameraRange(Camera,0.1,100)
CameraClsColor(Camera,000,000,000)

Mesh = CreateMesh()
Surface = CreateSurface(Mesh)
VerticesCount% = 0
TrianglesCount% = 0

PositionEntity(Camera,0,0,-10,True)

Repeat
 
 Surface = GetSurface(Mesh,1)
 VerticesCount = VerticesCount + 1
 V0I% = VerticesCount-1
 AddVertex( Surface, Rnd(-1.5,+1.5), Rnd(+1,+4), Rnd(-1,+1) )
 VerticesCount = VerticesCount + 1
 V1I% = VerticesCount-1
 AddVertex( Surface, Rnd(+4,+1), Rnd(-1,-4), Rnd(-1,+1) )
 VerticesCount = VerticesCount + 1
 V2I% = VerticesCount-1
 AddVertex( Surface, Rnd(-1,-4), Rnd(-1,-4), Rnd(-1,+1) )
 
 TrianglesCount = TrianglesCount + 1
 TI% = TrianglesCount-1
 AddTriangle( Surface, V0I, V1I, V2I )
 
 ;UpdateNormals(Mesh)

 WireFrame(True)

 SetBuffer(BackBuffer())
 RenderWorld()

 Text(0,0,"VerticesCount = "+VerticesCount)
 Text(0,10,"TrianglesCount = "+TrianglesCount)

 Flip(1)

Until( MAV = True )

End()
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 07, 2018, 02:55:42 PM
Quote
(with Blitz3d, it would be around 32000 vertices / 32000 triangles per surface)
i have tested this code on 3 different computers and the limit seems quite random... (with Blitz3d), this arbitrary limit is really really really annoying ! (because of that, if i want to merge many vertices / triangles in one surface, instead i have to create several surfaces, and it is a mess to keep track of what is what...) I hope that AGK does not have the same arbitrary limit...
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Naughty Alien on March 07, 2018, 03:31:03 PM
Blitz3D uses unsigned 16-bit vertex buffers, which means 65535 vertices in Blitz3D should be fine as DX7 says , dwVertexCount
The number of vertices in the array. The maximum number of vertices allowed is D3DMAXNUMVERTICES (0xFFFF)
.

..Im sure AGK is well over this ancient limit..ill test tomorrow large mesh and see how it goes..
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 07, 2018, 03:57:10 PM
Quote
which means 65535 vertices in Blitz3D should be fine
in theory, maybe, but in practice, no, the MAV happens with less than 32000 triangles (depending on the computer), this is weird (and annoying)

tested on 3 different computers :
MAV when the surface has 54615 vertices and 18205 triangles...
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: TomToad on March 07, 2018, 06:38:01 PM
If I remember correctly,Blitz3d had a maximum limit of 65535 vertices, but depending on video card memory size and driver capabilities, the actual number could be less. As I understand, this was a DirectX 7 problem and not aB3D problem.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Naughty Alien on March 08, 2018, 02:40:42 AM
Quote
which means 65535 vertices in Blitz3D should be fine
in theory, maybe, but in practice, no, the MAV happens with less than 32000 triangles (depending on the computer), this is weird (and annoying)

tested on 3 different computers :
MAV when the surface has 54615 vertices and 18205 triangles...

..tested just now and it works fine for me...however even that (65535 vertices) is still poor limitation, so for folks such as yourself who is building quite neat procedural cave system, down to triangle, I believe, B3D is bad choice of tool..
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 08, 2018, 10:34:41 AM
Quote
so for folks such as yourself who is building quite neat procedural cave system, down to triangle, I believe, B3D is bad choice of tool..
i know that this limitation is annoying, but i manage to achieve what i achieve because i have a good understanding and experience with Blitz3d, so learning a new language / engine is useless for me at the moment, but maybe later, if i create something good enough...
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: TomToad on March 08, 2018, 11:53:33 AM
Ok, did a test of 1,002,001 vertices and 2,000,000 triangles.  Rendered at around 72 FPS on my laptop.

A couple of limitations that I've noticed.

1. Memblocks are limited to only 100,000,000 bytes in size.  So your mesh needs to fit in that.  It appears that you will reach that memblock limit before you will reach the max vertex limit (whatever that is)

2. creating a mesh that size procedurally takes a long time.  It took about 30 seconds to create the mesh using the mesh.agc functions I posted before.

Test code below.  You need the mesh.agc file I posted before, and the mesh3-1.jpg file as well.
Code: [Select]
// Project: maxverts
// Created: 2018-03-08
#insert "mesh.agc"
// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "maxverts" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
Setcameraposition(1,0,0,0)
SetCameraRotation(1,0,0,0)

grid as Mesh
for y = 0 to 1000
for x = 0 to 1000
AddVertex(grid,x-500,y-500,999,0,0,-1,mod(x,2),mod(y,2),0xFFFFFFFF)
next x
if mod(y,100) = 0
Print (y)
sync()
endif
next y

for y = 0 to 999
for x = 0 to 999
v1 = x+y*1001
v2 = x+y*1001+1
v3 = x+(y+1)*1001
v4 = x+(y+1)*1001+1
AddTriangle(grid,v1,v2,v3)
AddTriangle(grid,v2,v4,v3)
next
if mod(y,100) = 0
print (y)
sync()
endif
next

gridObject = CreateObjectFromMesh(grid)
image = LoadImage("mesh3-1.jpg")
SetObjectImage(gridObject,image,0)

do
   

    Print( ScreenFPS() )
    print("Vertex = "+str(grid.VertexList.Length+1))
    Print("Triangle = "+str(grid.TriangleList.Length+1))
    Sync()
loop
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: RemiD on March 08, 2018, 05:53:40 PM
Quote
did a test of 1,002,001 vertices and 2,000,000 triangles.  Rendered at around 72 FPS on my laptop.
that's good ! i keep this in mind...
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Qube on May 22, 2018, 01:03:37 AM
On the TGC forums in the AGK section a user called puzzler2018 is having an issue about Rick Nasher posting code that puzzler2018 has written on another site ( namely this one ) (https://forum.thegamecreators.com/thread/221599?page=3)

Not sure if it's to do with not seeking permission first and / or crediting the original author. Either way, could those involved talk to each other and do some bro hugs and stuff like that :)
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on May 22, 2018, 07:26:50 PM
I explained my view and took down right away his Texture Creation function from here for I do not want anybody to have an issue with me or misunderstand. Just thought it was a pretty good example of how to achieve things in AGK.
Perhaps I forgot to mention his name in the discussion I had with RemiD about what's possible in AGK, which would be a neat thing to do, but never meant to pretend this was my own. Was just an example.

I'd think he rather would be proud to see his creation being used, but was a silly assumption.

Guess I'm still stuck in Blitz3d mode where peeps shared code carelessly. Sigh.. :(
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Qube on May 22, 2018, 07:49:29 PM
Quote
I'd think he rather would be proud to see his creation being used, but was a silly assumption.
Some people are a little over sensitive I guess ::)

Quote
I'd think he rather would be proud to see his creation being used, but was a silly assumption.
You would of thought so. It's not like you were claiming the full source of a game as your own.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on May 22, 2018, 10:05:41 PM
Yup, I even demonstrated to him what nice things could be done with it and he seemed fine with it.
Whenever I release sources of my own using code/help of others I always credit them. Was just posting it as an example without thinking for I think we all can learn from each others code.

TomToad also did some really nice code examples of poorly documented commands, which AGK team added to the official examples and I've asked them to reward him with some badges, like half a year ago or so, but they didn't reply. Perhaps was talking to different departments/channels for when asked RickV directly for some badges of my own for my Steam review/promotions he was pretty generous. Come to think of it, might ask for him via that road.

I don't know what happened, perhaps puzzler2018 had a change of heart. I vaguely recall a sour discussion in another thread between him and others about his skills, which wasn't too kind for he did code some pretty interesting things, but I didn't get into that, was not a thread I followed/interested in(minecraft clone or so).

Anyway, hope he's ok now.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: GaborD on May 24, 2018, 11:40:27 AM
I couldn't resist, had to test how far we can push AGK polycount wise.
It's all about massaging the bottlenecks in my opinion, the engine can actually handle a lot.
The thing I love about AGK is that it gives the user so much control. We can optimize a lot of things.

Here is a quick bruteforce terrain test, 2 million polies at 1300FPS on a GTX1070. (I took out LOD, to push polycount  >:D )
Polycount fetched with GetPolygonsDrawn(), should be accurate.
This could be quite a bit faster, but I also bruteforced texturing and fillrate with non-LODded 4K textures and per pixel realtime lighting. (really wanted to see how much AGK can handle)

(https://i.imgur.com/7IVULp8.jpg)


And a small particle test with 130K polies (64K independently spawned and moved particles, two tris each) running at 3600FPS:

(https://i.imgur.com/aCCUBNB.jpg)

Video of it here:



I think AGK can perform in the top league.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Rick Nasher on May 24, 2018, 10:22:24 PM
Wowzers! Your visuals are great(and I'm a sucker for that).

Also: my lappies GPU just chocked and got green with envy. lol
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: MikeHart on May 25, 2018, 06:53:55 AM
I am preaching this since M.S. closed the doors. The API and the engine of AGK is awesome.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Derron on May 25, 2018, 07:24:12 AM
API and engine: this is like the "modules" in BlitzMax, Monkey (and so Cerberus-X), ...  so if someone with knowledge put in some effort, this is for sure possible with "M.S. languages" too.

And I bet that performance wise there would not be any big difference (maybe here and there but neglectable). Doesn't "mojo" have some shader-capability?
https://github.com/bmx-ng/mky.mod
While surely buggy and non-optimized or lacking "hooks" (read: changing behaviour in different steps of the rendering process) it might still be able to produce the same graphical output than GaborD's AGK samples.


bye
Ron
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: MikeHart on May 25, 2018, 07:40:39 AM
Of course, it is possible with a lot of languages, not only the BRL ones. My point is... AGK is available. You can use it NOW. And there is more than just a render API.
That is why I made these AGK Tier2 targets for CX. I would be very proud to reach that level with CX one day. But who knows.  :)
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Derron on May 25, 2018, 09:02:02 AM
I would prefer Cerberus (if it hadn't have this case-sensitivity ... it's what I dislike at Java - albeit you are most often enforced to use a proper IDE like intelliJ taking care of it already). AGK misses much (basic) OOP I am used to be able to use in BlitzMax (and other languages). Nonetheless I like the new options you give to Cerberus with your new "target" - do not forget that it adds another thing to maintain. So best thing is, if you automated that process, means new versions just need a "createTarget.bat"-call ;-) (eg. Brucey surely has some wrapper-generators taking care of the basic stuff like const-extraction).


Argh, if only Bmx-NG received such an attention ... people like to see good looking screenshots and interpret them as "proof for capability". And this is true: in most "hobbyist" languages the showcase-section exposes a mediocre quality of projects. 1-man-shows etc.
Images like the one GaborD presented are nice "example showcase entries" to promote capability of a language (even if most comes from the shaders).


bye
Ron
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: GaborD on May 25, 2018, 10:03:39 AM
For me it's all about ease of use and quick iteration.
The only engines I found so far that offer that while also offering full control, good rendertex support and high raw speed are NB (dead), C3D (cancelled) and AGK.
Time is the most important indie-dev currency.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Derron on May 25, 2018, 10:15:39 AM
Yes - this is why we use "game dev languages" - means they already provide a lot of convenience stuff without the "chaperon/clucking" unity/ue/... does.

At the end it means that someone needs to do the tedious work so others could do a "LoadImage(x)" or "SetShader(shader, entrypoint)". The more it hides from the "indie game dev" the better - but it should allow to adjust stuff. BlitzMax modules hide a lot of stuff already - it is just... outdated/aged in many regions (renderpaths, audio, ...) and would need a big overhaul. Chicken egg problem arising: nobody wants to invest time for overhauling so nobody will use the modules as they are not as convenient/feature-rich/... as other products. And as they are free products, nobody get paid for doing things. People should consider gifting some money (of what they earned with their products) to the devs of free products they use - encourages the devs and is good for your soul.

For BlitzMax the problem is, that Brucey has the knowledge to do stuff - but lacks of information on how "modern graphic stuff" is working. Means he needs to read about stuff and then to wrap his brain around these things. Would be better if someone with graphics knowledge would guide/assist him - or even better, someone with knowledge in both worlds is doing stuff. Eg. col did a pretty cool job with unifying the "render 2 texture" functionality into one code base (still there is the SDL support missing ;-)). Maybe he could come up with a shader-solution too?


Sorry for derailing this thread more and more (...hey I am on my way to my 1000th post...).


bye
Ron
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: MikeHart on May 25, 2018, 11:19:16 AM
Nonetheless I like the new options you give to Cerberus with your new "target" - do not forget that it adds another thing to maintain. So best thing is, if you automated that process, means new versions just need a "createTarget.bat"-call
thanks. Well it is called AGKBuildTarget, but yes... automation is the key here :-) New AGK installed, run the script, point to the AGK installation, voila. Unless TGC decides to alter its file structures, I have nothing to maintain.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: col on June 01, 2018, 01:32:57 PM
Off-topic
Quote
Maybe he could come up with a shader-solution too?
I do have a system in place for shaders... getting it working nicely with the Max2D graphics contexts is another thing.
Another factor is what are the intentions of using shaders with Max2D? i.e. What would one expect from having 2D shader support?

AGK is looking pretty awesome :)
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Derron on June 02, 2018, 06:36:24 AM
@ shader support
Hmm, for the same stuff as in other languages?

- preprocessing (?)
- postprocessing
- ...

stuff you do in 2D games. Dunno how people use it in 3D engines (missing personal experience there). In 2D I would have used it for "water backgrounds" at a certain "z index" (so more a 2D in 3D). means you could render 2D islands sprites covered by shaderized water around it ... hmm this more and more sounds as if you needed 3D.
Postprocessing and the likes: to blur/freeze/desaturate a screen before eg. rendering an ingame-popup-menu.
As said I am not used to use shaders and others here might have way more ideas of what usage shaders in "2D" could have.


bye
Ron
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: TomToad on June 02, 2018, 09:50:29 AM
Off-topic
I do have a system in place for shaders... getting it working nicely with the Max2D graphics contexts is another thing.

I managed to get shaders to work in Max2D a while ago.  Posted a thread with some of the experiments I did on the blitzbasic forum.  It isn't as difficult to do as one might think, Max2D are really just 3D textured quads that always face the camera.

http://mojolabs.nz/posts.php?topic=105697
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: col on June 02, 2018, 10:52:03 AM
Hi TomToad,

Derron and I are referring to a single command set that will work with all 3 standard ( plus I'm sure Derron favours SDL too ) graphics contexts. For GL, D3D9 and D3D11.
This means to abstract away the underlying access to the shader uniforms/constants/samplers/textures etc.

For Max2D let's assume for the moment that only vertex and pixel shaders are being used.
There are some subtle differences between Dx and GL, for example in GL you access a uniform ( in Dx its a called a constant ) by querying the shader program which includes both a vertex and pixel shader. In Dx the vertex and pixel shaders are queried individually for their 'variables'.

To get over these issues and create a single code base for all 3 I created a TShaderFramework, TShaderProgram, TVertexShader and TPixelShader, TShaderUniform, TShaderTexture and TShaderSampler. Each one abstracts away the underlying gpu API required to set their datas.

TShaderFramework
    This just helps reduce name clashing for functions/methods but also identifies the underlying graphics context - gl, d3d9 or d3d11. The TShaderFramework has methods to create a vertex shader and pixel shaders ( which could, in the future, be extended to support the shaders for geometry and tesselation ). They return an appropriate instance of each which is where the compiled shader binary lives. TShaderFramework is used  to create an instance of TShaderProgram too.

TVertexShader TPixelShader
    You create these passing in your shader source code as standard text ( GLSL for GL, and HLSL for D3D9/D3D11 ). The shader gets compiled into binary form and held in these.

TShaderProgram
    You create a TShaderProgram using a TVertexShader and a TPixelShader, which for GL links the binaries ( Dx doesn't require linking ). The TShaderProgram auto creates instances of TShaderUniform, TShaderTexture, TShaderSampler as required for the shaders using the underlying gpu API reflection methods. TShaderProgram has methods to query for those shader 'variable' instances. As a part of those 'variables' it also sets up 'cpu backing memory' so that you can set values without the shader being in use at the time the 'value' is set. When the shader is then set to be used the values are passed to the shader/gpu as required.

TShaderUniform, TShaderSampler, TShaderTexture
    Have methods to set floats, ints, matrix, sampler and texture as appropriate. Some are not used in GL and D3D9. Some are required for D3D11.

The latter types is where it all starts to get gritty when setting things up with Max2D due to Max2D hiding away the current gpu state. I guess you can query for the state when needed but that's where it all starts to get a little messy :/
If you/anyone have some ideas and suggestions on how to clean that bit up then that would be awesome  :)


I guess 2D special effects would be 'nice', most of which require more than one texture.
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Derron on June 02, 2018, 11:31:43 AM
@ Qube
I think it might be possible to split the "blitzmax shader" posts into a new thread - sorry for derailing ;-)


@ Col
Thanks for that elaborative explanation.

I think as "vanilla blitzmax" can use Brucey's "MaxMod/brl.mod and MaxMod/pub.mod" it should be fairly doable to add or change some stuff in that modules - eg to expose data which is set to private for now. Also your needed adjustments for Render2Texture could find its way into the maxmod-repos.
But already asking for this exposes that you have knowledge about this specific parts which others surely do not have. So our chances to help are very....limited. Sorry.


@ TomToad
Thanks for your link - but as Col already wrote I am more interested in some cross-platform approach. So yes, it should work with all the "official" supported render paths (ogl, dx9, dx11 - and throw out on dx7 ?). SDL would be cool as it allows usage with Android/iOS then.


@ special effects
Dunno if this is a shader, but the "torch effect" (black screen with torch-areas lightening up the playground) could surely be done via shader - or some kind of "fog" (instead of having multiple layers of high-res/app-res textures moving in parallax-esque ways along the screen)

bye
Ron
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: Kryzon on August 23, 2018, 12:57:29 PM
TShaderFramework
TVertexShader, TPixelShader
TShaderProgram
TShaderUniform, TShaderSampler, TShaderTexture
I think your classes got the T virus. Here, let me help:

ShaderFramework
VertexShader, PixelShader
ShaderProgram
ShaderUniform, ShaderSampler, ShaderTexture
Title: Re: curious about what AGK allows for surfaces (verticescount, trianglescount)
Post by: col on August 23, 2018, 04:58:23 PM
Haha, yep bitten by the BMax T Virus

Thanks for the antidote :)
SimplePortal 2.3.6 © 2008-2014, SimplePortal