I haven't used AppGameKit or AGK2 before and I don't intend on spending all of my time in it, but I picked it up in the Humble Bundle and I'd like to play about in my lunch breaks and spare time with a few things.
I know that this is primarily for 2d related projects (for the time being) due to the fairly limited 3d side of this tool, but I'd like to play about with the 3d anyway as I have some really interesting ideas for how I could create something entertaining in 3d without the use of any real animations outside of tweening things anyway.
I will get stuck with things, I might not be doing things the best possible way, but that is why I am making this post. I haven't found very many examples of using AppGameKit for 3d at all and it doesn't appear that many are trying to do much with it (at least publicly anyway) so I want to post my struggles and findings here for others looking to delve into the 3d aspects, if for nothing more than just a little fun or education purposes.
I am going to be using Tier 1 for all of this and my 'BASIC' knowledge is really limited going into this.
I don't know how often I can update this due to my active game development project with UE4, but I'll eventually make some videos when I learn some more and if I don't struggle too much I'll even enter the Indie game contest with my 3d sample game.
3D Experiments 01
The first objective here was to load an object with a texture and rotate it in the Y axis with the object scaled up for viewing purposes. Nice and simple, no over complications kind of like an advanced "hello world" of 3d with AGK2 I suppose you could say.
This is all from scratch based on whatever I can find in the documentation sections of AppGameKit on the website. I compiled a guide on Steam regarding this first Experiment:
http://steamcommunity.com/sharedfiles/filedetails/?id=478258116
The Code:
//////////////////////////////////
// Project: 3D Experiments 01 //
// Created: 2015-07-09 //
// Author: Patrick Griffiths //
//////////////////////////////////
// set window properties
SetWindowTitle( "3D Experiments 01" )
SetWindowSize( 1024, 768, 0 )
setclearcolor (30,30,60)
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
//set textures
testTex1 = loadImage("testimg.jpg")
//load model and set texture to it
mesh1 = loadObject ("mesh-pCube1.obj")
setobjectimage (mesh1,testTex1,0)
// position camera
movecameralocalZ (1,15)
do
// rotate objects
RotateObjectLocalY(mesh1, .4)
Print( ScreenFPS() )
Sync()
loop
The Explanation:
Quote: "// set window properties
SetWindowTitle( "3D Experiments 01" )
SetWindowSize( 1024, 768, 0 )
setclearcolor (30,60,30)"
Nothing special here, but I did add something... "setclearcolor" the rest comes as default when you start a new project. I added this because upon my first couple of attempts I was having a small error loading a texture onto the model although there were no compile errors, and I couldn't tell if the model was loading or not and I generally wanted to just change the colour to play it safe with being able to tell things apart anyway. There isn't anything special with the properties attached either. "setclearcolor (30,30,60)" is just "setclearcolor (R,G,B)" and I randomly chose numbers just to give things a change from black.
Quote: "//set textures
testTex1 = loadImage("testimg.jpg")"
Now as far as I understand this, we have to load in the texture and give it a name before we can apply it to anything like the model that we load in later... So what I did was, I stole a texture from the single 3d example provided with AppGameKit which was "mesh28-0.jpg" located in the media folder of that example (comes with your installation) and I chose to rename it and give it a simple name for testing.
Quote: "//load model and set texture to it
mesh1 = loadObject ("mesh-pCube1.obj")
setobjectimage (mesh1,testTex1,0)"
Here is where we load in the model with 'loadObject' where the object is placed into a 'media' folder within the project directory. If you want to be better organised you can also just create another folder for models and call that, like so: "models/mesh-pCube1.obj" as the media folder is the default location so you only declare your sub-folders and files within that folder. So we also have to give the model a name as an objectID so that we can refer to it within the code later and use that ID when we tell the code to place our loaded texture onto the model, I chose a simple "mesh1" for now. Also all I did was export a basic cube primitive from my preferred 3d software package for the model. So nothing special there.
Then I set the texture to the object by calling the object and then the texture that I loaded.
Quote: "// position camera
movecameralocalZ (1,15)"
For viewing purposes I moved the camera with this...
Quote: "// rotate objects
RotateObjectLocalY(mesh1, .4)"
Within the do loop I placed the code to rotate the object slowly to see the texture all around the mesh. As you can likely tell it rotates on the Y axis, then you define what rotates, for this instances it's the model that we loaded in earlier followed by how fast it rotates. I chose a .4 for that for no reason other than it wasn't too fast or too slow.
3D Experiments 02
My second objective would be to cycle through all models within a sub-directory of the media folder and load all of those in with certain textures applied to various models in a semi-modular way. For instance... I create a wall and placement of the wall in my 3d software, export them all and load in only one texture instance but apply it to multiple wall models. The only reason I am going to go that route is because I have no idea how to efficiently use the cloneObject command to make an instance of the model but use the placement I create within my 3d software, as right now it seems pretty limited as far as laying out a level in 3d with AppGameKit goes.
Not too much more complex but a nice progressive step compared to just loading a simple textured 3d object that rotates on screen...
**This experiment is a work in progress**
The Code:
//////////////////////////////////
// Project: 3D Experiments 02 //
// Created: 2015-07-09 //
// Author: Patrick Griffiths //
//////////////////////////////////
// set window properties
SetWindowTitle( "3D Experiments 02" )
SetWindowSize( 1024, 768, 0 )
setclearcolor (30,30,60)
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
// position camera
movecameralocalZ (1,15)
movecameralocalX (1,-.8)
gosub _load_Objects
do
Print( ScreenFPS() )
Sync()
loop
_load_Objects:
objmax=24
for obj=1 to objmax
obj$="models/mesh-pPlane"+str(obj)+".obj"
LoadObject(obj,obj$,0)
if obj>=16 and obj<=24
tex$="textures/wall.jpg"
else
tex$="textures/floor.jpg"
endif
teximg=LoadImage(tex$)
SetImageWrapU(teximg,1)
SetImageWrapV(teximg,1)
SetObjectImage(obj,teximg,0)
next obj
return
The Explanation:
I looked over the 3d example provided with the AppGameKit installation and stole some code after figuring out what everything did thanks to the documentation and I also went along and stole another texture from the media folder just to experimenting rapidly...
As you can see in the image, there is a little issue with the wall texture applying to the floor, but that is something I knew would happen due to a very small user error when I was creating the tile pieces in my 3d software, and naming on export... So let's just ignore that mishap for now because it's a tedious fix for what it's worth.
Quote: "// position camera
movecameralocalZ (1,15)
movecameralocalX (1,-.8)"
Just because I am a little OCD with things I manually adjusted the camera for a better view by slightly offsetting in the -X axis. Nothing big or impressive there though.
Quote: "gosub _load_Objects"
gosub as I understand allows you to tell the code to hop to a later portion of the code and in this instance I took a page out of the example 3d code provided and altered it to fit what was required after looking it over and reading through the documentation.
Quote: "_load_Objects:
objmax=24
for obj=1 to objmax
obj$="models/mesh-pPlane"+str(obj)+".obj"
LoadObject(obj,obj$,0)
if obj>=16 and obj<=24
tex$="textures/wall.jpg"
else
tex$="textures/floor.jpg"
endif
teximg=LoadImage(tex$)
SetImageWrapU(teximg,1)
SetImageWrapV(teximg,1)
SetObjectImage(obj,teximg,0)"
So, where we're going to be cycling through models within a sub-directory of the 'Media' folder we set a maximum, which I've used the amount of obj files in the folder as the max count, that you can see at objmax=24.
Quote: "
objmax=24
for obj=1 to objmax
obj$="models/mesh-pPlane"+str(obj)+".obj"
LoadObject(obj,obj$,0)"
Where my mesh exports from my 3d software were named mesh-pPlane we define the first section of the name and use "obj=1 to objmax" to say "add 1 to the srting (file name) before adding .obj to the maximum count of 24." at least this is how I understand the code in simple explanation terms. Then we take that and load the objects into the scene.
Quote: "if obj>=16 and obj<=24
tex$="textures/wall.jpg"
else
tex$="textures/floor.jpg"
endif"
Now this part I love... This is just using what we created before to cycle through the objects and load them into the scene but to define which texture is loaded to which object. Essentially saying this but in code "if the model number (the obj string) is equal to or greater (>=) and if the model number is equal to or lower than 24 then we use the wall texture, but if not, then we apply the floor texture"
Quote: " teximg=LoadImage(tex$)
SetImageWrapU(teximg,1)
SetImageWrapV(teximg,1)
SetObjectImage(obj,teximg,0)
next obj"
The next part is just loading the image defined with tex$ into the scene and applying to the objects. Followed by next obj to cycle through.
So far so good!! I don't quite know if I will have time to a third experiment today, but it has been fun so far just playing around, it's sad there aren't more examples for both 2d and 3d though... Hopefully the recent Humble Bundle may change that with a mass of users flowing in.
-----
Please if any of you more experienced members out there have any advice regarding how I am going about things in my code, please make suggestions with explanations and not just code snippets of what is better, it's best if you can educate myself and others who may view this on why the suggested edits are better.
Kind Regards,
Patrick.