Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / MeshMemblock Function

Author
Message
puzzler2018
User Banned
Posted: 19th Sep 2018 18:25 Edited at: 19th Sep 2018 18:32
Thanks Furbarpk - your comments greatly received.

Can anyone help in my trying to convert a string float into a float please - I thought Val did it - but that rounding it up / down

v -1.029329 4.293293 1.203920

with

x#= Val(GetStringToken(line$," ",1))
y#= Val(GetStringToken(line$," ",2))
z#= Val(GetStringToken(line$," ",3))

result

x#=1.000000 y#=4.00000 z#=1.00000

Mind gone blank...


EDIT - ValFloat ( ) Doh!
puzzler2018
User Banned
Posted: 19th Sep 2018 19:11
OK here is a little info on how OBJ files are built

We would have to store each vertex (V) into its array and nomals (VN) and Texture UV (VT) and then finally Faces (F)


vertex as float[] // eg v 1.276477 0.200934 -0.387665
normals as float[] // eg vn vn -0.5346 0.3304 -0.7779
faces as float[] // eg f 5//9 21//9 29//9
textures as float[] // eg vt 0.500 1 [0]

// with face elements these are index references of the above array indexes
//
// f v1 v2 v3 // This will be the indexes of the Vertex 1 2 and 3 in the vertex array
// f v1/vt1 v2/vt2 v3/vt3 // This one has texture / UV assigned to the object and the first is the index in the vertex array and the 2nd is the texture array
// f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 // This one has texture / UV assigned and Normals to the object and the first is the index in the vertex array and the 2nd is the texture array and the index in normals arra
/
/ The f data is normally at the end of the OBJ file, so

// What we would have to do first is grab the Vs data into the Vertex array
// then the VNs into the Normal array
// then the VTs into the texture array
// then use the F(aces) data to pick out which index that it requires from the above arrays to build the OBJ structure vertex using the AddVertex command

All will be revealed pretty soon with a fully functional object loader

I know we have one "LoadObject()" I know i know, but this will be a bit different cause it all will be ended up into its own mesh array

by doing this, you can "Load objects" onto the same mesh array and then build the final object - which may have say 10 OBJ models on it

All will come clear later in the week



puzzler2018
User Banned
Posted: 19th Sep 2018 22:11
wouldnt be fantastic to have a command like

CreateMeshObectShatter

which works it all out to be able to shatter objects thats loaded onto the mesh

one thing at a time puzzler
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 19th Sep 2018 22:27
Quote: "I thought Val did it - but that rounding it up / down"

x# = ValFloat(GetStringToken(l, ",", 1))
fubar
puzzler2018
User Banned
Posted: 19th Sep 2018 22:33 Edited at: 19th Sep 2018 22:34
That just boomed me - I found ValFloat - an OBJ file is seperated by a space

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Sep 2018 22:38
you could throw all those tables into a type so it's all one neat package, then your function can just return the mesh type or a mesh type array for multiple meshes
type mesh
vertex as float[]
normals as float[]
faces as float[]
textures as float[]
endtype
puzzler2018
User Banned
Posted: 19th Sep 2018 22:41
Spot on
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 19th Sep 2018 23:12 Edited at: 19th Sep 2018 23:14
Havent tested but something like this

I left out the face data because wasn't sure what "/" was about
fubar
puzzler2018
User Banned
Posted: 19th Sep 2018 23:21 Edited at: 19th Sep 2018 23:27
Wow - thanks.

The double \\ seperates each of the F's

f 1,2,3 - no texture or normal

f 1\\1 2\\2 3\\3 - has vertex / normal indexing data

f 1\\1\\1 2\\2\\2 3\\3\\2 - has vertex / normal/UV indexing data

All corresponding to the array thats been loaded

Wow ! Thanks


EDIT forward slashes ////// my apolgies



Ico-sphere here
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 19th Sep 2018 23:27 Edited at: 19th Sep 2018 23:31
What are you trying to actually do??

You can load any obj file you like using loadobject()

...then create a mesh memblock from it using CreateMemblockFromObjectMesh()


then in that memblock you have

All the vertices - Use GetMeshMemblockVertex....
All the normals - Use GetMeshMemblockVertexNormal....
All the texture coords - Use GetMeshMemblockVertex....
And all the faces - Use GetMemblockInt (use the index offset- every 3 indices is a face)

You could just copy all this data easily into your type structure if you wanted....

or, not even bother to copy to a structure and just edit data in place....which would be quicker to work with anyways due to the fact that agk's arrays are really linked lists internally.

So if your just wanting to learn from doing this...then ok cool, no probs. Go for it.... If its so you can more esily understand the structure of the 3d info then ....sure ...fair enough....go for it
I actually did this for .ms3d and .x files so i could auto load textures and assign them to meshes so it can be useful.

....but writing a loader/parser isnt needed as AppGameKit will load obj (text and binary versions of files) as well as LOADS of other 3d formats too and give you the data with about 2/3 lines of code?? Plus there are built in functions to acces al the vertex, texture data etc....

Im just curious as to why the need to parse when AppGameKit will do it? Im not trying to be negative...just unsure as to if there is a need?

Anyway...good luck
puzzler2018
User Banned
Posted: 19th Sep 2018 23:31 Edited at: 19th Sep 2018 23:34
we could do that its a bonus if know how how OBJ file format is made.

Your idea will be a different functions whether the need of them

Thanks for you input and certainly wont go be dismissed

Cheers
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 19th Sep 2018 23:34
your welcome

I believe when it is understood and the data manipulated this way it would be very easy to write our own obj files which at present is on TGC's todo list
Which would be fantastic for Minecraft as one program could create the world and another would just load an object file(well your mesh that you create
for the world) This would improve loadtimes immensely and maybe even make it suitable for a mobile device. Even if you had to have your own variation
of the saved obj file this would be leaps and bounds ahead. (getting excited again here lol)
fubar
puzzler2018
User Banned
Posted: 19th Sep 2018 23:38
I agree - load one object - saved in array to be able be cloned as such. one load - 100 added to a mesh at different locations via that 1st objects, excellent
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 19th Sep 2018 23:38 Edited at: 19th Sep 2018 23:45
Quote: "What are you trying to actually do??"

It could come in very handy for moving faces without using memblocks
which with some work could send all faces in all directions randomly ideally a great object explosion
especially if each face could be made into its own obj. Im sure there is much more it can do but that's what I see atm
fubar
puzzler2018
User Banned
Posted: 19th Sep 2018 23:45 Edited at: 19th Sep 2018 23:51
AGK LoadObject() loads single objects and memory infuriating as we have found

My version be able to load obect directly onto to a mesh with x#, y#, z# eventually as it primary position on that mesh

Just incase some are confused

EDIT - Furbark You will have to recreate the mesh object. So this will be better with Static objects like buildings etc or use Setobjectvericesx / y/ z just at that location

Rebuilding an object of maybe a vast size will be very slow.

Unless you just have ordinary objects thats made up of individual objects in the render distance you have,
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 19th Sep 2018 23:49 Edited at: 19th Sep 2018 23:56
If you want to move faces or add them then a memblock is the only way.....just changing values or adding to your type structure still requires you to move them into a memblock to view or use them or display them anyway.

Plus...dont for get you can just save the memblock very quickly then reload it later at lightning speed....and create your 3d object again with about 2 commands instead of loads of lines of parsing. The memblock file is also much more compact then a text obj file too so smaller and quicker too.

if you want to set an objects location offset from zero then use set object pivot...it will allow you to move all the vertices by a set amount. So a mesh loaded and its x,y,z offset using 3 lines off code.

It is definately quicker to load obj files then add them into a mesh one at a time with the inbuilt functions then hand parse it in interpreted basic.

Combining one mesh into another really is just acase of copying the vertices and indices into a larger memblock....its what i did on a thread with the agk loaded as voxels...one easy function. I'll post it up if wanted....but im sure you would learn from doing it too so nevermind.

Im not trying to be harsh in anyway....just wanting to point out that this is all doable at present with almost no effort. I guess being to have a data structure is nice but im kind of nt seeing the need to parse?

Anyway...cool....have fun. Great work
puzzler2018
User Banned
Posted: 19th Sep 2018 23:54
Your cool bengismo - you bring lots of ideas / draw backs - and thats the idea of a community

Thanks for your input - most welcoming


puzzler2018
User Banned
Posted: 20th Sep 2018 00:10 Edited at: 20th Sep 2018 00:14
So, if

f 1 5 6

then with my command would be

addvertex ( vertex[1].x#, vertex[1].y#, vertex[1].z#,vertex[1].z, normals[1].x#, normals[1].y#, normals[1].y#,textures[1].u#,textures[1].v#,color)
addvertex ( vertex[1].x#, vertex[1].y#, vertex[5].z#,vertex[1].z, normals[5].x#, normals[5].y#, normals[5].y#,textures[5].u#,textures[5].v#,color)
addvertex ( vertex[1].x#, vertex[1].y#, vertex[6].z#,vertex[1].z, normals[6].x#, normals[6].y#, normals[6].y#,textures[6].u#,textures[6].v#,color)


easy peasy (i hope)

puzzler2018
User Banned
Posted: 20th Sep 2018 00:23 Edited at: 20th Sep 2018 00:25
So, if

v 1 5 6
fn 2 7 8
ft 2 1 2
f 3 1 2

then with my command would be

f3 - addvertex ( vertex[1].x#, vertex[1].y#, vertex[1].z#,vertex[1].z, normals[2].x#, normals[2].y#, normals[2].y#,textures[2].u#,textures[2].v#,color)
f1 - addvertex ( vertex[5].x#, vertex[5].y#, vertex[5].z#,vertex[1].z, normals[7].x#, normals[7].y#, normals[7].y#,textures[1].u#,textures[1].v#,color)
f2 - addvertex ( vertex[6].x#, vertex[6].y#, vertex[6].z#,vertex[1].z, normals[8].x#, normals[8].y#, normals[8].y#,textures[2].u#,textures[2].v#,color)

Anyway - sleep
puzzler2018
User Banned
Posted: 20th Sep 2018 00:49
explosions with this will need some working out - hopefully by weekend i will have this built

but really not sure how we going to do explosions - needs some thinking
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Sep 2018 01:33 Edited at: 20th Sep 2018 03:03
edit
puzzler2018
User Banned
Posted: 20th Sep 2018 07:18 Edited at: 20th Sep 2018 07:25
Ive had a thought on explosions

We could add a Piece[] type variable too



Then can have either 1 whole OBJect in the 1st peice [0]. or multiple of chopped up peices making up that single object to start with. [0] [1] [2] .....

Then can use the normal setobjectposition/ rotation on the peices instead. so that will look like the peices of that 1 object is come apart
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 20th Sep 2018 08:27 Edited at: 20th Sep 2018 08:40
if your not going to use physics pieces pieces may need

That way you just set the direction ammounts in each direction and angle rotations both of which might range from -1.0 to 1.0 for example
and in your explosion of bits you just do something like

if you did it that way you could have a loop of pieces moving at different speeds and rotations not so sure if you would need the current location
or current rotation angle but if you wanted to put the pieces back after for some reason you may need the original positions but don't think you need
the original piece location and angle as that can be got from other elements of type object.
fubar
puzzler2018
User Banned
Posted: 20th Sep 2018 10:04
Thanks - some good useful idea here

We can make a few loadobject functions to work with either the Peices if one so wanted to and indeed one for the use with the normal standard way that AGKs physics uses.
puzzler2018
User Banned
Posted: 21st Sep 2018 18:24 Edited at: 21st Sep 2018 18:24
My first version of this object loader



Please use the ICO.OBJ into the media folder - could be any OBJ but that would require testing, im sure it will load ok but Normals is way off! at the moment!

Attachments

Login to view attachments
puzzler2018
User Banned
Posted: 21st Sep 2018 19:21 Edited at: 21st Sep 2018 19:35
Maybe better with this "free" obj to identify any normal issues or maybe perhaps something else ive forgotten


EDIT - Ignore this object - after checling this has polygon structure - with 4 sections on a face

eg of the Faces - this has 4 equaling a polygon



This capability will come later once sussed out whats gone wrong with the previous post

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Sep 2018 22:24
Well done just tested it with your ico.obj object and looks fine to me
fubar
puzzler2018
User Banned
Posted: 21st Sep 2018 22:29
AGKs vesion compared to mine -- looks like the normals or something for lighting is not the same
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Sep 2018 22:52
Have you tried moving your created mesh object near the agk object
perhaps with keyboard and you will then know if its just the positioning
fubar
puzzler2018
User Banned
Posted: 21st Sep 2018 23:03
Yes and still the same - one half of the icosphere OBJ looks perfect and the other half goes dark gray cause normals are not right - perfect on AppGameKit object

Cant you see that too
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Sep 2018 23:05
hahahah looks fine without my glasses
fubar
puzzler2018
User Banned
Posted: 21st Sep 2018 23:06
Bless you
puzzler2018
User Banned
Posted: 21st Sep 2018 23:38
can anyone else see a difference
puzzler2018
User Banned
Posted: 22nd Sep 2018 00:07 Edited at: 22nd Sep 2018 00:14
There is a reason why im doing this - this is to be able to add OBJects to a single mesh and what ever location you like - hundreds of times onto a mesh. So my work is will be good for world 3d games

Jusr incase your wondering what is this feller going on about with these functions.

Hope you beginners find them useful to make bigger world games

EDIT - Memblock programming is the way forward

I loved - LBA 2 anyone remember that beast
puzzler2018
User Banned
Posted: 22nd Sep 2018 00:45
Here is what I have at moment



Normals needs figuring out im not happy with it

puzzler2018
User Banned
Posted: 22nd Sep 2018 01:00 Edited at: 22nd Sep 2018 01:02
I really do need to take my hat off and bow to Paul in his knowledge - its 2nd to none
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Sep 2018 03:23 Edited at: 22nd Sep 2018 03:25
perhaps you need to SetObjectCullMode( objID, 0) mode 0=both front and back drawn

oh forget that I see what you've done you've moved the object lol and I thought for a sec it wasn't showing
fubar
puzzler2018
User Banned
Posted: 22nd Sep 2018 03:48 Edited at: 22nd Sep 2018 03:51
We got the wrong end of the stick. nothing to do with culling, i just got my code wrong

Could Someone please help/explain whats wrong with my normals/code.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 22nd Sep 2018 04:41 Edited at: 22nd Sep 2018 04:43
I tried the code and see the basic form of the model seems to be there but can't really tell if the normals are messed up, some faces are missing entirely or the scale of the faces is off.

Maybe try a more basic model. I knocked out a very simple model and tested with it and your code threw an error so that might be a clue to something not sure really.

Anyway, the very simple model and corresponding texture map is attached if you want to test with them and see if it helps to track it down.

Attachments

Login to view attachments
puzzler2018
User Banned
Posted: 22nd Sep 2018 04:44
Thanks -Ill give things a try in the morning
puzzler2018
User Banned
Posted: 24th Sep 2018 17:57 Edited at: 24th Sep 2018 17:59
Im still fighting with the normals - it will not beat me..

Created a proper instance command (which will populate the true data loaded from the V/VNs/VTs instead of a pointer


Here is an example of the code in action

Attachments

Login to view attachments
puzzler2018
User Banned
Posted: 24th Sep 2018 18:56 Edited at: 24th Sep 2018 18:59
Must admit - I like this one



Again use that ICO.OBJ to work

Catch up later on in week for more
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 24th Sep 2018 21:09
Looks good
fubar
puzzler2018
User Banned
Posted: 24th Sep 2018 21:26
Cheers - now you will have eventually the option to import your OBJ files to a certain location on a mesh instead of just the basic AppGameKit primitives

I havent seen this functionality AppGameKit Tier 1 so thought id develop something to do this
puzzler2018
User Banned
Posted: 24th Sep 2018 21:40
There is a method in my madness to devvelop all this - promise
puzzler2018
User Banned
Posted: 25th Sep 2018 20:02 Edited at: 25th Sep 2018 20:13
On that last example it seem to took forever to load and not many objects to be fair.

I shall try and make use of the copymemblock function to see if this speeds up true instancing - as the built in AppGameKit commands are C++ which is a zillion times faster in processing anyway

Catch up around weekend for this one

EDIT -

and I would like to convert what we have already into



So objectmesh is an array of potential many different models that can be reused over and over

objectmesh[1].id = box
objectmesh[2].id = cube
objectmesh[3].id = man
..
..
..

becareful of your high poly counts on your models though

puzzler2018
User Banned
Posted: 27th Sep 2018 23:30
Have I upset anyone
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 27th Sep 2018 23:48
not that I know of
Just waiting to see whats next !!!
fubar
puzzler2018
User Banned
Posted: 27th Sep 2018 23:51
great- catch up on weekend
puzzler2018
User Banned
Posted: 28th Sep 2018 00:01 Edited at: 28th Sep 2018 00:03
Any one else other than me fubarpk - i know you would answer as best you can. its more to others

Login to post a reply

Server time is: 2024-04-28 01:53:03
Your offset time is: 2024-04-28 01:53:03