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 / Creating a single model from multiple objects?

Author
Message
DARKHALO2K
20
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 17th Apr 2016 14:12
Hi,

Is there a way to turn my individually textured and positioned models in to a single object? I've experimented with the mesh commands, looked at the help files, and searched the forum, but am yet to find a working solution.

My goal is to simply cut down on the number of objects drawn/in memory and whilst I intend to use single objects for levels in future, I'm currently using hundreds of individual cubes to create a retro stylised dungeon.

I did experiment with a culling routine but this only resulted in a gain of around 3fps as the game was still having to deal with the same number of objects.

Any help would be greatly appreciated.

SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 19th Apr 2016 23:33
Are you using a single image across all the objects?

If you have all your level objects using the same image it will be very easy to merge it all as one object. I can give you some solutions if thats the case.
DARKHALO2K
20
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 21st Apr 2016 07:08
I'm using individual textures, but even if I could combine objects of the same texture I would see my map made up of 10 objects rather than 1000.

I'd be grateful for any help.
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 21st Apr 2016 15:53
Are your objects made from agk commands or loaded in?

If loaded in and you can save as obj files i can writeup some quick code for you to merge them together. How are your levels drawn currently?
DARKHALO2K
20
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 21st Apr 2016 21:27
My levels are created by placing sprites on a grid. Each co-ordinate is then checked, with the image found dictating which object to create in 3D space. The objects are AppGameKit cubes and plains, though I could create suitable .obj models. I have considered re-creating my map in a model editor, but with very little time for development at the moment, a code based solution would be preferable.

My current map runs at 30fps on my Galaxy S5, but is about half the size (possibly only a third) of what I'd expect a full production level to be. However, running the same amount of entities with a map made from a single object runs at 60fps.

Thanks for your time and interest!
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 22nd Apr 2016 00:43
Perfect! I can help then

If you can send me a 2d map example i will write some code for you to convert it to a 3d map single model . once you see what i writeup for ya you should easily be able to add more custom shapes
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 23rd Apr 2016 15:48
actually... I've been thinking about this and thought maybe i should just release an update to my drawing program. post some videos on how it works etc. My drawing app has gotten very powerfull over the years and i see it very usefull for designing worlds or levels for agk even though it was built with darkbasic. File output is obj but if you are interested in using my objects included plugin for agk i also have a binary 3d format that can be saved as a fraction the size of an obj. Also that objects included functions i made also has code in there to build raw objects from scratch.


the trick i use is to build an obj file then load it back in. So really all you need to understand is the obj file format. Have some basic 3d knowledge how 3d is constructed.
i guess they made some commands to edit raw model info using memblocks but i havent looked into that at all.

soo... let me know what would help you the most and i'll see what i can do.

in the meantime i will upload my drawing app and make some videos using it.
DARKHALO2K
20
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 24th Apr 2016 21:58
Hi,

This code takes data created in AGK's Placement Editor to create a 3D map. Objects are setup according to the image found, with different i.d. variables used to set the object ranges.

I thought I'd be able to combine the objects in to a single mesh after being created, before moving on to the next group of objects, but I've been unsuccessful so far. I really appreciate your time with this.

SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 24th Apr 2016 22:23
so this code is only using boxes? do you also have something for floors and ceiling? if so we can cut down on these walls significantly.

I will write up some code to generate the 3d shapes combined as 1 object but it will be up to you to use these functions to create your scene. Give me a few hours to test out some code then i will upload it.

DARKHALO2K
20
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 24th Apr 2016 22:52
That's extremely kind, and very much appreciated. Thank you. I'd be more than happy to credit you in any suitable project, should you care to share your name along with any code.

I use the same method for setting up all objects in a level, but use plain objects instead of boxes for everything that isn't a wall or a door, as you can see in the screenshot below.

SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 25th Apr 2016 02:07 Edited at: 25th Apr 2016 04:05
here is the example of creating a scene from scratch and using a single atlas texture.

now use this code to build the level.... but if you have objects like doors they should be separate objects. Also be sure to turn off collision on your character block or it will collide with itself when you do sphere collision checks.

if you know some simple geometry shapes you could easily add more things to it using code as i did.
any more help needed...please let me know. Im fairly knowledgeable with 3d construction.

this is the code...but download the attachment so you get the image too.

Attachments

Login to view attachments
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 25th Apr 2016 02:22 Edited at: 25th Apr 2016 03:52
oh....when i say it could be optimized this is what i mean.

if a wall is joining another wall you currently have 2 extra wall faces being drawn that do not need to be drawn. This would need to be checked while counting array size and also again when you build the scene.

i didnt add a ceiling to that code but it is the exact same code for the floor except we need to change the triangles so they are flipped.

simply copy the floor function and change the normals to -1 on y axis and change


to this to flip the faces

dont forget the normals as the light reflection will be backwards if you dont change it.

if you like... i can code a better function for picking uv mapping if you want. for now its just setup to the exact pixel x,y start to x,y end. images on the vertical side are flipped so you need to say the top of the image is equal to 1.0 then subtract. [0.0 to 1.0] is the range of your texture loaded.

(this scene below is just 1 single object with 1 single texture) 64x64=4096 combined into 1

Attachments

Login to view attachments
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 25th Apr 2016 10:16 Edited at: 25th Apr 2016 10:28
Hi SoftMotion3D

Do you think it's possible to load several .obj file, merge them and save the result (merged object) in one .obj file ?

I use a lot af "parts of objects" (several .obj files) to create differents "objects" (made with all parts) in the game, but I would like to save first all the "big objects" and then load them in my game.

Example :
The parts (each part is an .obj file)


The object created with the parts, in my game (but all part are just cloneobject with original parts, so i would like to save the object created with its parts, and load only the saved new object )


Do you think it's possible ?
If yes, it would be awesome . I could create a lot of differents objects with just a few parts : objects, plants, trees, mecanics, machines, house, and so...
AGK2 tier1 - http://www.dracaena-studio.com
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 25th Apr 2016 13:28
Yup this is very possible. First you will need to make an atlas texture and i could writeup some code to combine the obj files together to form a single object. The frame rate will be very suprizing when it only needs to draw a single object for the scene.

What are you using for the level editor?

Im thinking you want to use these parts to make single objects... Is that correct? I made a tool that does this already... It just needs a help video to go withit. Ill make the help video tonight and post it with tool.
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 25th Apr 2016 13:54 Edited at: 25th Apr 2016 13:55
Quote: "What are you using for the level editor?"
I use Blender to create my level for the moment. May be, if Guru2agk is ready and great, I will use it ^^.

Quote: "Im thinking you want to use these parts to make single objects... Is that correct? "
YEs.
When installing the game, I would like to create all the single objects (from parts), and when loading the game, I will load those single objects.

So with a very little sized application, I could have a lot of differents objects, but with a good framerate .
For the moment, because i only use the parts, the frame rate isn't as good as it could be with 1000 single objects loaded (made with 10 différents parts) instead of 10000 parts (1000 X10) .

Im' really interesing by the technic to create the object dynamically in the game and saved in the media (write), not create the objects to place it in the media folder(read) of the apk., because, I can create the object in blender directly if it's what I would like ^^).
AGK2 tier1 - http://www.dracaena-studio.com
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 25th Apr 2016 17:19
Are your objects all using the same image id?

The first thing you need to do is create an atlas texture that has all the needed images.

Second i can put some code together that can merge them as 1 and remap the objects uv if nessesary. Then using simular code for darkhalo2k we can save it as a temp object just to load it back in as a single object.

Are your obj files triangular or quads? My code works for triangle only.
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 25th Apr 2016 19:20
I also have a binary format that i put together that is a small fraction the size of an obj file. Using this could be great cause you can extract it to obj files on the device after installing.

I have a scene i drew for my game thats 2mb as an obj file. Saved as my binary file its only 256k roughly.

Soo if space is a problem you could look at doing that also.

Let me know what ya need or want to try.

How did you makeout with my example darkhalo2k?
DARKHALO2K
20
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 25th Apr 2016 21:22
Thank you so much for sharing, SoftMotion3D. I've given the code a quick read through, and may try to create a simple map editor around it rather than trying to adapt my current code to suit.

Thanks again. You're a real credit to the community!
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 25th Apr 2016 21:53
Ah thats great to hear. Let me add 1 more thing to this. I will post code to turn an obj file to agk code so you can use other shapes in your program if you want to build scenes this way.

So the same way this program makes a floor could be a new function to create a custom loaded shape. Ill make it so it produces a text file you can just add back in as code to draw the object no longer needing the obj file.

Ill write this up tonight and post it. I think blendman could find use for this function writer also if he wants to make scenes with just code.
DARKHALO2K
20
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 25th Apr 2016 22:08
That would be brilliant, thank you. Again, I really appreciate your support and generosity, and if you'd care to share your name with me either here or in an email then I'd be sure to credit you in any project derived from this code.
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 26th Apr 2016 01:25 Edited at: 26th Apr 2016 01:31
this piece of code is a master piece!




so now you can make several obj files into agk code

this is the code here that makes the text file



uncomment that out to make your new function, locate the new text file generated and load it into notepad.
copy the data to your agk app your making.

i have included the cylinder function into the above code so you can see how it needs to be added in.

download attachment below
(please ignore my spelling errors.... it happens)

Attachments

Login to view attachments
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 26th Apr 2016 01:54
ok whats the best way to set uv mapping on an object drawn that was built to use a single image that we now want using an atlas texture? My drawing app is an answer to this.... and heres the directions.

first download this:
http://www.sheldonscreations.com/forum/index.php?topic=2.0

this is my drawing program ....now let me explain some quick basics to loading your obj file.... changing the atlas texture asignment.... then resaving it as a obj file.

instructions:
1) download the modelprop zip file
2) most likely need to tell windows to unblock the file before extracting the files from the zip
3) place the folder whereever you want.
4) locate your atlas texture you want to use... in the example above you can find a minecraft atlas texture.
5) know where your model is

//using the program
6) open model prop
7) goto -->file/clear [the program no longer starts new... if you exited or crashed with a scene it will be reloaded at startup]
8)goto --> file/import obj [not object....needs to be {import obj} ]
9)the file should have loaded

//setup the atlas texture
10) on the object tools tab there is a button that has a [p] in the image click this and load the atlas image into bank 1
11)the atlas should appear on the preview button
12)select your object [click on it]
13)press that texture preview button
14)now the uv mapping looks all messed up correct?
15) your atlas texture can be 16x16 or 8x8 images spread accross them
-p1 sets a texture uv map based on 16x16 grid and the p2 button does 8x8
ok
16)select your object...or make sure its still selected then click on that p1 or p2
17)a window came up with all sorts of colors. this was designed for use with my voxel editor but it also is used for setting uv mapping.
check where you image starts and then click the button
if it looks like you got the wrong one press it again and try another button. notice the last button you pressed is bigger then the others for reference.

18) once the uv set looks correct
19)goto --->file/export obj
20) save it as a different file to test it out.... dont overwrite the original just icase the uv mapping gets messed up

thats it and make sure you atlas texture....the images are all the same size and use a 16x16 grid image file or a 8x8. the minecraft one is a 512x512 using 16x16grid.

i will make some videos showing modelprops impressive features this weekend.... hopefully and ill upload to youtube and post the vids here for you to see.


SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 26th Apr 2016 05:08
ok quick video for that....

SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 26th Apr 2016 23:29 Edited at: 26th Apr 2016 23:36
Quote: "if you'd care to share your name with me either here or in an email then I'd be sure to credit you in any project derived from this code."


If you want to ... use freely of coarse!

you can reference me as sheldonscreations or by name Sheldon MacDonald.

if you need any more help please let me know.

cheers!
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 28th Apr 2016 00:07
i just had a thought blendman.

even if you are unable to re texture map your objects, you could at least combine all the objects that are of the same object just cloned. you could make all of those 1 single object easily.
if your using blender... i do know there is an option to turn a quad object into a triangle object. That last code i wrote for darkhalo2k will make an object creatable with code. id examine that example closely. If you need any help with it or me explaining it better let me know.
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 28th Apr 2016 12:52 Edited at: 28th Apr 2016 12:56
hi

Quote: "Are your objects all using the same image id? The first thing you need to do is create an atlas texture that has all the needed images."
Not for the moment, but I can make an atlas, when I will work again on my 3D game (dragonia) ^^.

Quote: "Second i can put some code together that can merge them as 1 and remap the objects uv if nessesary. Then using simular code for darkhalo2k we can save it as a temp object just to load it back in as a single object."

In fact, what I'm looking for is :
ok - create the part of objects (in blender), export them in .obj
ok - add the file in the APK/ exe PC version of my game
not ok - At the installation of the game : load each part and create the objects from those parts (and my txt file for objects -multi-part)
not ok - save the new object created with the parts in AppGameKit, save it in the write directory of the game.
not ok but if I have saved the object in .obj, it should be easy - Load the new Object (from write directory), when loading the game & level (I don't have to load the part, now I can have less objects than if I create them with the parts).


Quote: "Are your obj files triangular or quads? My code works for triangle only."
I can export with triangle from blender if needed.
AGK2 tier1 - http://www.dracaena-studio.com

Login to post a reply

Server time is: 2024-03-29 01:54:21
Your offset time is: 2024-03-29 01:54:21