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 3D Object and automatically assign textures - RESOLVED

Author
Message
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Mar 2018 08:43 Edited at: 13th Mar 2018 08:43
Hey,

There doesn't seem to be a week goes by without someone asking for this so here it is:

But first, an explanation for why AppGameKit behaves the way it does when loading objects.
Whilst it is perfectly possible to create Desktop Apps with AppGameKit, a large part of its appeal is its ability to perform well on mobile platforms. While many modern mobile devices now have processors that can outperform some entry level laptops, they still have quite a limited amount of memory. If AppGameKit were to load the texture for each object as the object was loaded then your mobile device could rapidly run out of memory if the same texture were used on multiple objects and had to have multiple copies of it sat in RAM. So it doesn't do that. It asks you to take care of your own memory management (to a degree) by forcing you to load only the textures you need.

That doesn't seem to be enough for a lot of people and they still want the texture loaded automatically. So here's what you do:
Step 1: Download the attached code and save it somewhere safe (Projects folder sounds good!)
Step 2: #include the code in any of your own code that loads 3D objects
Step 4: Load the object by calling Load3Dobject(filename$) or Load3DobjectWithChildren(filename$)

"Hey! What happened to Step 3" I hear you ask.
That needs more explanation (and is probably the bit that will put people off)
Step 3: You need a separate text file for each object which holds a list of the textures and stages to put them in. I don't see that as a big issue personally because you have separate text files for Atlas textures and this is no different.

For example:
Let's say you have an object and two textures:
MyObject.FBX
diffuse_texture.png
normal_map.png

You would create a text file called "MyObject textures.txt"
And it would contain:
0:diffuse_texture.png
1:normal_map.png

Now when you load the object, it will open the text file and read it. Then place diffuse_texture.png into stage 0 and normal_map.png into stage 1.
You could ask "What's the point, doesn't that defeat the object of saving RAM by loading only single instance of a texture" and you'd be right, but there is another function going on in the background which stops that from happening. So if you then load another object that uses the same textures, they won't be re-loaded but instead use the same images as the previous object.
There are some string comparisons going on in order to perform that, so it will add a millisecond or two to the load time but I think that's a small price to pay.

Small caveat: I've just knocked this code together and haven't been able to test it but it dry runs perfectly well.
Fully tested - It works as advertised

Give me a shout if you have any questions,

Scraggle

Attachments

Login to view attachments
MikeHart
AGK Bronze Backer
20
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 26th Mar 2018 12:22
Thanks for sharing.

What about a model with multible texture for different paerts of the model?
Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200. Using AGK2 Tier 1.
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 27th Mar 2018 09:04
Hey Scraggle,
this is a good point. It was nice in DBC/DBP not to care about multi layer textures.

It should be easier with some sort of object-inspector plugin.
As fas as I know, AppGameKit is using assimp for the 3d object loading:

[href] http://assimp.sourceforge.net/main_viewer.html[/href]
If we get some information how to get ASSIMP working in a Tier2 Plugin project linked to loaded files,
we could create plugins for each platform in order to read out the information from the file. It would work without a definition file.

Nice work.


[/url]
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 30th Mar 2018 10:16
Yes, ill take a look a this. Id love to have autoload texture(maybe if it officially support it can have a FLAG to load auto or manually in the load function)
Nice work!!!!
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Mar 2018 11:14 Edited at: 30th Mar 2018 11:29
Great work scraggle...

But ......you still have to create a text file and put filenames in the text file and then place that in your folder and update that file any time you change textures or update a model.

It moves the writing of texture filenames from inside AppGameKit code to a text file outside of AppGameKit code. Its no less actual work. Its actually slightly more work to create the text file and fill it then it is to write texturefilenames in the code. (Sorry, im really not trying to be negative and its great code....but its a workaround, not really a resolution in my opinion - No lightmaps? ...And..Object base colors....that could be set and loaded from a model file...Its stored in MS3D files and 3DS and FBX but its not used when loaded into AGK...multitextured models etc??)

Your code is a great fix for now.....

but, Id still like to see an additional function in AppGameKit (or even a few functions)
LoadObjectAndTextures() which logically loads textures (from filenames in the model file) as the object is loaded and can even apply texture to submeshes and apply light maps and object colours etc....

Ideally the new function should also have an option to check if the models texture filename(s) already exist as an already loaded texture and used that image (like scraggles code does - Thats Nice work!! - Like an image manager)

We could also do with GetObjectMeshImage() to be able to get at the ID's of autoloaded images used in multitextured objects too.


I got code working for reading texture filenames straight from an MS3D file so you can wrap autoloading of that type of model (with multi textures and object colours etc..!!) without even using a text file but I still think its a workaround and it should be added in AppGameKit as part of the load process. Im considering doing the same autoloader for collada(.dae) but would much prefer it optimised and built into AppGameKit as its a lot of file parsing to do in basic which is probably already getting done in AGKs base code any way. (Asimp library is it??)

EDIT: Sorry if i sound negative about something thats actually really good.

Login to post a reply

Server time is: 2024-04-19 23:48:41
Your offset time is: 2024-04-19 23:48:41