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 / Load Object with Color

Author
Message
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 11th Feb 2017 12:06 Edited at: 7th Jan 2018 22:11
Hey,
I have another quick question.

Can you Load an object with its Diffuse Color ?
It is not working for .obj files and its associated .mtl files

Do I need another format ?
I don't want to bake textures for so many objects ...also it would save space.
Again using the 3D city models from Kenny
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 13th Feb 2017 10:37
AGK doesn't load .mtl files. I believe that it doesn't display vertex colours either, but you can use a custom shader to display them.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Feb 2017 14:47 Edited at: 7th Jan 2018 22:11
Thanks for your answer

I knew it ...damn...
I need to parse the color from the .mtl files then and attach them to a custom color shader or the vertex attributes.

Hm lets see:
I can predefine the color value of each material I found in the .mtl file and give it a fixed place in a shader constant.
But how would I determine which vertex of my object is grass and which one is concrete...

Or I update the mesh using the memblock commands, so it does have Vertex color + a custom shader that uses vertex color?
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 13th Feb 2017 15:17
Save in a format which stores vertex colour, like a .x file.
Then your shader need only take the data from the object directly.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Feb 2017 16:14 Edited at: 7th Jan 2018 22:11
You think AppGameKit reads the color from that file and passes it to the vertex data ?
Do you have experience with it ?

I'll try it...

[Edit]
No success using a custom shader with vertex color.
I checked the vertex data and there was only position normal and uv data loaded by AGK.
I guess I have to manipulate the vertex data though.
[/Edit]
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Feb 2017 20:08 Edited at: 7th Jan 2018 22:11
If I Try to manipulate the Vertex data so it contains the position, normals, uv and the color I get an error
If I change it to only position and normal for example it crashes
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Feb 2017 21:48 Edited at: 7th Jan 2018 22:11
Sorry for the triple post.

[Edit] Updated Code:

[/Edit]
I used a part of the code in a game before

If you want to try it just load an object and call the AddColorToObject(ObjectID) function on it.
You will need a custom shader which includes the vertex color of course.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 15th Mar 2017 21:18 Edited at: 7th Jan 2018 22:11
Can somebody confirm that it is not possible to load objects with color ?
I want to call this a bug
or how should I proceed ?
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 16th Mar 2017 09:04
No, I do not believe that it is possible to load an .obj file with vertex colour, materials, textures or anything else.

They way I deal with this is to have a separate data file for each model that contains information for that model that is used in game, such as: colour, health, speed, texture file name, sound effect file name and so on. I also include the file name for the model within the data file. This way all the media required for the game is contained in one file.

In the code, I then read the data file, which will get the model file name - the colour, texture and whatever - then I load the model and other media afterward.
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 16th Mar 2017 12:17 Edited at: 7th Jan 2018 22:12
Yeah in some games projects I did the same, but that doesn't help me this time as I need different colours for each vertex of the object.
I could bake a texture to the model, but that is memory wastage and would take very long for all the models also the texture doesn't fit exactly every time.
The color is there(.x) but AppGameKit doesn't load it.
I did try to manipulate the mesh data to contain the color.
But if I add the color attribute to it it crashes
There are normally 3 attributes position,normal and uv.
when I add a 4th attribute it crashes...if I overwrite the uv for the color attribute it crashes.

It is a sort of deal breaker for me
Preben
AGK Studio Developer
19
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 20th Mar 2017 15:07
It should work when you read what paul writes in the doc ?

Try this:
Load a animated object using LoadObjectWithChildren and do this:



Use tmpobj, and In your vertex shader try this:
attribute vec4 vertexcolor;

And check if you get some random colors in the vertex shader

best regards Preben Eriksen,
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 20th Mar 2017 19:34 Edited at: 7th Jan 2018 22:12
Hey Preben
I got a fully Green object, I guess because it doesn't have bones ? or just one straight.
So I could maybe work out something from here.

But
Quote: "It should work when you read what paul writes in the doc ?"
where can I read that ??
I know that he wrote something about vertex color in here: CreateMemblockFromObjectMesh, so I thought I should manipulate the attributes in the object header.
But the offset is normally under index 60, so why do you change something at 81...i.e why are the bone indices outside of 60 and where can I read about that.
Or are you changing the actual Vertex Data ?
Also what do you think I should do next ...or could you create a little demo for me ?

I added a test object for you if you are so keen and make a little demo
And to be serious, it should be easier to load objects with color, not ?

Attachments

Login to view attachments
Preben
AGK Studio Developer
19
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 20th Mar 2017 22:23
If you used attribute vec4 vertexcolor; and got green then it worked , and it should be possible to use the vertexcolor.

Yes it was the same i read:
Quote: " the attribute names recognised by AppGameKit are "position", "normal", "uv", "uv1", "boneweights", and "boneindices", however you may add attributes with any name you like as long as you write a matching shader that has the same names. "


Quote: "But the offset is normally under index 60,"

No that depends on how many attributes the object you load has, so it can differ.
When you read the header:
newmem = CreateMemblockFromObjectMesh(newobj,a)
numvert = GetMemblockInt(newmem,0)
numindices = GetMemblockInt(newmem,4) // 0 = 3 vert-polygon , > 0 shared vert.
numattributes = GetMemblockInt(newmem,8) // attributes per vertex,
numsinglevertsize = GetMemblockInt(newmem,12) // size of a single vertex
offsetvert = GetMemblockInt(newmem,16) // start off vertex data
offsetindex = GetMemblockInt(newmem,20) // start off indices data
you should use offsetvert to get the vertex offset.

Quote: "why are the bone indices outside of 60"

When you load a animated object then the attribute "name" boneindices will be at 81+ , the header will differ depending on how many attributes the model have.
You can see it if you try to use "CreateFileFromMemblock" and check the file

Yes it would be very useful to have vertex color , mainly you could use it for "speed" just thing how fast you could render without using a single texture

Im currently working on some terrain conversions, https://forum.game-guru.com/thread/217668#msg2575253 , but when im done with that, i will take a look at this and see if its possible. If its possible im not sure how to use it , as you would have to make your own object loader to make it fully functional , thats something i dont want to do


best regards Preben Eriksen,
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 20th Mar 2017 22:51 Edited at: 7th Jan 2018 22:12
I don't want to sound rude, but your last post had no to little news for me
As I wrote some kind of object creator myself as you can see above (not including the parsing of the color data from the object file)

At least I can be sure I did it right ?!
because... I still get en error if I include a 4. attribute

So still not sure to how get everything together.
And thank you for helping me out, I'll be happy if you look into it again.

Quote: "mainly you could use it for "speed" just thing how fast you could render without using a single texture"

That's exactly what im going for, because of the limited fillrate of mobile phones
Also these kind of game graphics is well received these days...Also I'm playing with virtual reality (made a barrel distortion shader for the lens correction) and I can need a little extra speed for that
I'm working on too much at the same time
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 21st Mar 2017 00:07 Edited at: 21st Mar 2017 00:10
I would be happy to hear how this turns out as well.
There's so much variation in what get's loaded / registered from x/y/z versions of different file formats (no blame on TGC here)

I had to tweak the direct X exporter in lightwave so much to get a version of an animation I could use.
I have a suite of 3D packages which a funnel objects and animations through just to get them to work sometimes.

[edit] personally, I'd just rather AppGameKit read the vertex colors set out in the source object as well as a lot of other things, like scale without having to bake.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 21st Mar 2017 14:27 Edited at: 7th Jan 2018 22:12
Sometimes I'm a bit hastily
As I have it working now.

Image of Random Vertex Color



Use SetObjectAttribute(Object,Bistmask) on the object and take the bitmask %0111 = Normal+UV+VertexColor for example
Now I'll try to extract the color data from the object files

[Edit]
I can now extract the Vertex colors from .x files but it seems that there is still a shared vertex problem as some take the color of neighbour vertices.
Might be that I just saved it wrong
Here is the reference: Road Tile

Image of extracted VertexColor data


[Editception]
I realised that the original .obj files only have materials and no vertexcolor data
I made vertexcolor out of materialcolor, but that doesn't work as they are per face and not per vertex, I think, because I can't find another link between materials and vertices jet, so that sets me back.
Or does somebody know if/how you can convert materials to vertexcolor in a modelling program ?
[/Editception]
[/Edit]

Attachments

Login to view attachments
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 21st Mar 2017 23:17
Meshlab has texture->vertex colour (and so much more)
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 22nd Mar 2017 16:28 Edited at: 7th Jan 2018 22:12
Great Tool, nice finding, thanks !
In my case I needed face->vertex colour
But the average model does have textures and no materials, so you are right in most cases if someone need vertex colours in the future

So here is my library so far:
Function List

Library


There is a huge potential for improvements but it works for now.
Actualy, I need Material Color because they are per face but I don't know how to achieve it, I only know Vertices,UV and Normals maybe bones
I know that three vertices creates a triangle-face/polygon...

AGK____________________________________________________________MeshLab

Attachments

Login to view attachments
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 22nd Mar 2017 22:10
In your example, what's it supposed to look like (object colored in the 3D package)
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 23rd Mar 2017 00:09 Edited at: 7th Jan 2018 22:12
It should look like this:

I can make it look like Kennys original Road Tile in MeshLab, using facecolors.

Attachments

Login to view attachments
CodeName
7
Years of Service
User Offline
Joined: 30th Dec 2016
Location:
Posted: 7th Apr 2017 05:29
if I do remember correctly from milkshape 3d, you have to reset the normals..?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Apr 2017 09:35 Edited at: 26th Apr 2017 09:36
I have made a series of keyboard macros that does a pretty good job of sorting out the normals for kenny's models (Not perfect).



To process the models you'll need MeshLab, Ultimate Unwrap (UU) and AutoHotKey (AHK) https://autohotkey.com/download/

In the attached project you see there are two AHK scripts. You will need to modify them to point to where the .obj files are (There must not be any .3ds or .x files in the directory)
- First run ObjTo3ds.ahk (This uses MeshLab to load the .obj and save it as a .3ds. It needs this step because UU does a horrible job of converting .obj meshes)
- Then run 3dsToX.ahk (This uses UU to load the .3ds files and save them as .X files)
- All up they take about an hour on my machine

VERY IMPORTANT: WHEN RUNNING THESE MACROS DO NOT USE YOUR COMPUTER

I have already run those macros so you'll see that the v2 directory is populated with .obj, .3ds and .X files

I hacked together a viewer which is the AppGameKit App in the attachment. You can see that the majority of meshes display properly and the materials map correctly (It reads the .X files and extracts the colors and applies them to the model, very messy atm, im sure you could make a nice little function out of it janbo)

Instructions : Click on the right hand side of the screen for the next model, left hand side for the previous model

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-25 22:11:21
Your offset time is: 2024-04-25 22:11:21