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 / Mesh Creator from an image,

Author
Message
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jan 2019 16:42 Edited at: 2nd Jan 2019 18:37
Mesh Creator from an image,

This program creates a heap of blocks based on an image and then
when the "M" key is pressed, theyre are all merged into one mesh
object. Which will eventually allow the user to save them into one
mesh obj file


The merging takes a little while and the object will become red once its done

It does this by using a 64 by 64 image I recommend using this file "map.png"


Eventually my aim is to make a low poly mesh from a height map file

try changing these by commenting out one and uncommenting the other
fubar
puzzler2018
User Banned
Posted: 2nd Jan 2019 17:18
Very well done and nicely acheived - although merging time is quiet slow, but that could be optimised somehow

Great work..
puzzler2018
User Banned
Posted: 2nd Jan 2019 17:21
Like for example

We see the gray road - and a quite large area - so this could be something like createobjectbox( lengthofgrayareain X direction, 1, lengthofgrayareain Z direction )

instead of small individual cubes that spread over say 9 small cube areas - we could have 1 box that spreads over that area

using like a Greedy Algorithm techniques
puzzler2018
User Banned
Posted: 2nd Jan 2019 17:33 Edited at: 2nd Jan 2019 17:40
Example of this type of alogythm



fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jan 2019 18:23 Edited at: 2nd Jan 2019 18:47
Thanks
I think that greedy method might also work for the smoothing just not sure if that's beyond me lol

if you replace the smoothheightFunction()
with this normalHeightFunction() it may be more useful it atleast it don't don't mess up on the edges
have been thinking now, could have a box you can draw in that creates the objects after (no preview)
then just merge and eventually save



Quote: "although merging time is quiet slow, but that could be optimised somehow"

yeh it is a little slow but works ok for the present, that was why I added the dohousekeeping()
function which removes all the black no sized boxes. Which from the example cuts back from
4096 objects to 2020. Theres allot of objects merging and not sure how I could work the greedy
method atm to improve it more. but the code could easily become a simple 3D voxel Editor.
Where you draw color pixels in a box representing the height you want
fubar
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Jan 2019 19:03
Quote: "just not sure if that's beyond me lol"

Never say die !
I'm not a grumpy grandpa
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Jan 2019 19:03
Quote: "just not sure if that's beyond me lol"

Never say die !
I'm not a grumpy grandpa
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jan 2019 19:20 Edited at: 2nd Jan 2019 19:23
it could be used for a sideways 3D Scroller
try this code


with this image "map2.png"
theres only 512 objects created in this one so the merge into one mesh is very fast
fubar
puzzler2018
User Banned
Posted: 2nd Jan 2019 19:24
Excellent my good fellow...
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jan 2019 19:32
Thanks How is the obj saver you was working with chafari going?, have you got it working with meshes yet ?
fubar
puzzler2018
User Banned
Posted: 2nd Jan 2019 19:36 Edited at: 2nd Jan 2019 19:37
Certainly have



If this works - then by all means pop it onto your Snippets thread

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 00:02
Thanks Puzzler that should come in handy

think im going to have to rewrite the merge function



Think what I need is to have a big_object memblock
which keeps track of the total vertexs, indexes and attributes
and append the vertices,normals,uvs and faces of all of the objects
fubar
puzzler2018
User Banned
Posted: 3rd Jan 2019 07:03
Yeah sound good to me, we can populate all those information into a type - if it doesn't already exist in the exporter

type _model
objid
vertices as float[]
indexes as float[]
normals as float[]
uvs as float[]
endtype
bigobject as _model[]

don't make the meshes too large to update as this will affect performance rebuilding.

So maybe perhaps smaller models joined together.

The last example seems pretty fast on the merge cause it was decent size to update.

but then it wouldn't matter if not planning on updating the meshes during run time, but rather just building them in level starts
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 10:15
Thanks
Its either that or rewrite the save function, which i tried with a for/next loop to save all the meshindexes
so i also tried a for/next saving all the objects into one final.obj that was just crazy as it created a file
over the size of a 100 mb. my thinking was that addobjectmeshfrommemblock wasnt saving all the data
when i try and save the finalobject as one mesh its really only saving one block so there must be something
im not understaningd and perhaps the addobjectmeshfrommemblock isnt adding the data correctly.
I will try and dump the data ine the final mesh/memblock to see if that makes any sence
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 10:28 Edited at: 3rd Jan 2019 10:49
using this code


this image "Map3.png"

and after (M)merging and (S)saving it creates
http://users.tpg.com.au/subarpk/final.obj

Which cant be viewed in any 3D program

the debug info for 17objects merged shows which is probably why
fubar
puzzler2018
User Banned
Posted: 3rd Jan 2019 11:53
I see how the obj is constructured. - a multitude of

like this


Because of this, I think each set requires a G inbetween.

Like this



I will test after work.. but im pretty sure this will be it



fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 12:47 Edited at: 3rd Jan 2019 13:01
Thanks you gave me some great ideas

The save function now works for all the mesh
if I load into lithunwrap it works but I have to zoom right out
couldn't find it in blender
fubar
puzzler2018
User Banned
Posted: 3rd Jan 2019 12:49
Cool, I think some of the end indexes on the Faces maybe not 100%, blender likes a good index structure, so maybe a bad index on the last f

24 for example maybe not a valid index.

Count the VT and Vs to make sure the latter of the Fs match up.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 13:15 Edited at: 3rd Jan 2019 13:45
that might be it, but it could also be the zoom angle as I had to zoom quite allot
but that will do for now until I figure how to centre the mesh


interestingly enough if I export in lithunwrap

the same object becomes http://users.tpg.com.au/subarpk/test.obj


and restructuring the obj file like lithunwrap does



gets it to load in blender but not AppGameKit unless I save it again from blender then it will load in agk

fubar
puzzler2018
User Banned
Posted: 3rd Jan 2019 13:44
Great work here. Now we will need to do a comparison. Maybe first is to count them all up on pop at the end starting with #s and if they are correct on all certs. Indexes. Faces etc to the unwrap onem then we are very close

I'll take a look after work
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 13:49 Edited at: 3rd Jan 2019 13:50
Thanks
your at work im about to go to bed lol but im an insomniac at times

A quick cold shower for me its so hot in Australia atm its 1215am
and the bureau of meteorology is saying its 30c around 86f think that temp
must be wrong they prob went to bed but its still quite warm for night
fubar
puzzler2018
User Banned
Posted: 3rd Jan 2019 18:38
OK cool - i just tried it and it looks like it builds a large cube, meshing them together and then Saving it

it views ok in Windows 10 file explorer preview.

and in Blender, it seems to not bring anything in, not even an Error message to suggest anything wrong.

In blender - are we sure its just not in a different area of the 3D space? or do we think it generally doesnt import.

I dont have any other like unwrap software to test.

Also, when viewing in the App - the block looks like say a 5x5 cube (square), but viewing in the windows explorer (attached) it looks like a 1 x 5 rectangular cube.

is there something im missing that it may not be dong all the mesh?

Resulting OBJ from your latest code results in the attached OBJ



Attachments

Login to view attachments
puzzler2018
User Banned
Posted: 3rd Jan 2019 18:49 Edited at: 3rd Jan 2019 18:53
I have put back a for loop to go through all the objects that are in the mesh



at least now it brings in all the Objects into the OBJ.

Is this something you was looking to do too?

EDIT - and this version now imports into my blender (i think its just a huge scaling issue on your last attempt)

Attachments

Login to view attachments
puzzler2018
User Banned
Posted: 3rd Jan 2019 19:23
Something is still wrong somewhere - where is creating a huge cube now.like it has X, Y and Z depths (equalling a large rectangular cube.

Even though its just a thin rectangle cube with Y=0 depth

Its doing the same on my greedy algorthm work - just a massive cube...

Something is just not quiet riight - ill fix and repost if i can figure it out

puzzler2018
User Banned
Posted: 3rd Jan 2019 19:35 Edited at: 3rd Jan 2019 19:36
I know what its doing, its just creating a cube at 0,0,0 translation - for all of them - well that will be a cube...

and if you have 100 of them at the same translation location then it will be a cube. - but rendering 100 objects at the same location will make system grind to a halt cause the GPU will have write conflicts all over the shop

We need to figure a way to save the true positioning data somehow and use this information for each cube and "add" to the vertices of the scene

Check out the repeating V's to show this premise..

Great - thats my next job!!
puzzler2018
User Banned
Posted: 3rd Jan 2019 20:07
A quick example to put the theory into practice.



Im on with the problem solving it now

Bear with me
puzzler2018
User Banned
Posted: 3rd Jan 2019 21:11
Ok cool, this is the reason, we have Verts

v 1 2 3
v 4 5 6
v 7 8 9

and we haves faces indexes to the verts

f 1/1/1
f 2/2/2
f 3/3/3

When we create data for the new object, it repeats likewise
object 2
f 1/1/1
f 2/2/2
f 3/3/3

object3

f 1/1/1
f 2/2/2
f 3/3/3

object4
f 1/1/1
f 2/2/2
f 3/3/3


but this shouldnt happen - the faces need to be continuous - even though seperated out into individual objects

lke

object 2
f 1/1/1
f 2/2/2
f 3/3/3

object3

f 5/5/5
f 6/6/6
f 7/7/7

object4
f 8/8/8
f 9/9/9
f 10/10/10

etc

Damm that was difficult to fathom, bear with me whilst code that up
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 21:11
Thanks
it should be 17 cubes side by side, thats why it appears as a large rectangle
potentially each cube can be a different height as its read from the image
but i think we are closer than what might appear the main issue being able
to load it back into AppGameKit
fubar
puzzler2018
User Banned
Posted: 3rd Jan 2019 21:13
Yeah - all the faces are using the same vetexes index and shouldnt be.... Doh! my bad... But thats all good reason why need testing... The code only worked with 1 object.

This has been all a good learning curve
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 21:29
I think whats needed is to add a loop of str(GetObjectNumMeshes( objid ) ) as there are 17 meshes
fubar
puzzler2018
User Banned
Posted: 3rd Jan 2019 21:32 Edited at: 3rd Jan 2019 21:34
Dammm there is that to think about too, but promise the faces require to be incremental too

Lets work with the example I sent cause that will be easier to work with to resolve the face incremental and then work on the individual meshes cause i think that will be another challenge an half

Ill send the faces fix when i have resolved it

By all means you keep cracking on at your side too.
puzzler2018
User Banned
Posted: 3rd Jan 2019 21:35 Edited at: 3rd Jan 2019 21:38
Here is code I have so far



You will see that 2 cubes are seperated now but just not quiet right
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 21:42
ok off for coffee only just woke up lol
fubar
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Jan 2019 21:54 Edited at: 3rd Jan 2019 21:57
Hi there

The way Obj works, is
v
vt
vn
f

I've seen somewhere .
v
vn
vt
f


When we writte to export an Obj. the way the f's is not always
1/1/1 2/2/2 3/3/3

In my exporter , in order to have good normals , what I do is:

f 2/2/4 1/3/4 3/1/4 4/4/4
f 6/6/8 5/7/8 7/5/8 8/8/8
f 10/10/12 9/11/12 11/9/12 12/12/12
f 14/14/16 13/15/16 15/13/16 16/16/16
f 18/18/20 17/19/20 19/17/20 20/20/20
f 22/22/24 21/23/24 23/21/24 24/24/24
Here you have to notice that I have four groups of values ...this is not common in the majority of cases but for boxes this the best way, as we can make two triangles just with four vertex.

Edit.
You can see that faces jump every 4 vertex .
The texture coodinates jumps in a different order
And the same happens with the normals order
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 3rd Jan 2019 21:54
Nice - mine is strong black with 9 sugars lol

Here is a slightly better variant



Getting there slowly
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Jan 2019 22:02
That looks better puzzler , but still if you give image to the object , you will see that all faces are cated by half. This is because the face order . And you have to change the face order to look outside.

I will try to do this for you . Let me a couple of minutes.
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 3rd Jan 2019 22:14
Thanks

But still not quite right when add others into the mix - with non indexes



Shall fix during weekend.
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 3rd Jan 2019 22:18
It looks like your very close

I wrote something similar last year and the final single mesh renders really quickly compared to loads of cubes!
Even a 256x256 heightmap image (shown in top right below) creates a single mesh fairly quick if its done right.
Deleting internal faces helps massively when creating the mesh from the heightmap info both in terms of rendering speed and how quickly a final mesh is put together. No point in having them as they can never be seen by the player
I never bothered saving as an obj though....i either saved the mesh memblock directly to file (as thats very quick to load) or saved to ms3d format.



Keep going...great work.

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Jan 2019 22:22 Edited at: 3rd Jan 2019 22:26
@puzzler Do you mind if I try fo find the problem ? at the moment with boxes ....



Edit. That is really nice Bengismo !!

I'm with you Bengismo...I prefer .x than Obj.. The format .x has even animation and for me it es easier to parse than Obj due to the amount of differents models of Obj...
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 3rd Jan 2019 22:28
Im not taking over Fubarpks thread but sure every little knowledge helps.

and indeed bengismo, awesome work as you usually do and thanks.
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Jan 2019 22:37
Quote: " im not taking over Fubarpks thread but sure every little knowledge helps."


Ok ....we can open a new thread....at the moment, I made a little change in the face order and now boxes looks with the face facing out ...in Deep Exploration...at the moment it doesn't load in AGK.
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 3rd Jan 2019 22:44 Edited at: 3rd Jan 2019 22:44
Cool

Unless Fubarpk accepts your ideas too then for me post your ideas away..I feel it is important to what we trying to achieve
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jan 2019 22:49
Quote: "im not taking over Fubarpks thread but sure every little knowledge helps.""

I don't mind at all more minds make light work

ok so I added an array of all the meshes for the type as follows


but it still only shows one block I was pretty sure that would work
fubar
puzzler2018
User Banned
Posted: 3rd Jan 2019 22:55
You havent added the incremental faces, so all its doing is

v 1
v 2
v 3

f 1
f 2
f 3
f 1
f 2
f 3
f 1
f 2
f 3
f 1
f 2
f 3

instead what it should be doing is

v 1
v 2
v 3

f 1
f 2
f 3
f 4
f 5
f 6
f 7
f 8
f 9
etc
cause all its doing is repeating over the same vertex indices - ie cube 1 instead of individual cubes
puzzler2018
User Banned
Posted: 3rd Jan 2019 23:05 Edited at: 3rd Jan 2019 23:06
Replace with - with what we have so far

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Jan 2019 23:42 Edited at: 3rd Jan 2019 23:44
@puzzler /fubarpk The function is neraly working..... What I have seen here ...
puzzler , you are writing f's in a bucle FOR/NEXT like:

for i=0 to (IC / 3)-1
WriteLine(fw,"f " index1 , index2, index3 ....

What I do is :

for i= 0 to ic-1
writeline(fw, f index1,index2,index3
writeline(fw f index3,index2,index4
next

I make two triangles in every loop in order to have control in the texture coords. Not sure if that make any sense .
This is the code I use to export boxes, and it works ok . we can even load them in Agk.


I have to say that this code works only with boxes....I have to find out how to mix boxes cones , spheres cylinder and what not but all of them use different index data .
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 3rd Jan 2019 23:47 Edited at: 3rd Jan 2019 23:47
Dammmm you done it again..

Im sure a thanks all round - for cubes.

Dammmm to myself by the way
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th Jan 2019 00:26
you got it
fubar
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 4th Jan 2019 00:32
Feel free to use it as you want. I'm still working int other interesting projects .
I'm not a grumpy grandpa
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th Jan 2019 00:35 Edited at: 4th Jan 2019 03:36
Edited it now gets rid of that lonely cube one the edge and tidied up the code somewhat

Thanks guys I put what was resolved into what we had
and this is what there is


still need to do some code housekeeping but it works

Interestingly enough its allot quicker with larger meshes to save them out as one object and then load them in
than using the merge function I commented out. Try with the original map.png
fubar

Login to post a reply

Server time is: 2024-11-23 11:47:49
Your offset time is: 2024-11-23 11:47:49