Hi there.
I have to say, I write this from my little experience with AGK. Someone correct me if I'm wrong
The way agk works, loading 3D objects and then having to texturize them manually,which sometimes could be tedious, what many programmers use to do, is to create the whole level in a 3D program without textures and then manually assign the textures in AppGameKit . Other programmers choose to texturize the entire level in their favorite 3D program.
When we load an entire level in AppGameKit and then we check the number of meshes, we will expect to find as many meshes as objects have the scene that we have created.
We work in our 3D programm.
Imagine a room with four walls, floor, ceiling, a window and a door...that is eight objects.Now imagine that we apply a texture for the walls another for the ceiling one for the floor, and two more for the window and the door.
That will be five textures in the scene since the four walls share texture .Now we export to .x and load the level in AppGameKit .Even though we expect the level to have eight meshes, when AppGameKit loads the object, it will keep all meshes with the same texture in a group as janbo commented here .
https://forum.thegamecreators.com/thread/221104
we will find in the object as many meshes as different textures are used in the scene.
The same happens if we export a scene with three objects..two of them with texture and one without . The object in AppGameKit will have just two meshes.
If the mesh is not created when loading the object in AppGameKit, we will not be able to change the texture of some parts of the scene with different texture simply because we see that one texture gives it a better look than another.
What I have create here in this snippet, is a couple of functions to load our objects in Agk with just one command "function " with all textures.
// Project: Load textures automatically
// Created: 2019-01-01
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Load textures automatically" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
`Loading 3D Object with two meshes
loadobject(1,"box3.x")
`Texturing all meshes with "textu(xxx) function
textu(1)
`Loading same object with A U T O M A T I C A L L Y T E X T U R E S
Load3D(2,"box3.x")
setobjectposition(2,60,0,0)
`Loading 3D object with Three objecs BUT ... only two meshes
load3D(3,"box5.x")
setobjectposition(3,60,0,60)
`Loading 3D object single mesh
load3D(4,"ball.x")
setobjectposition(4,0,17,0)
`Creating a Sphere in AGK
createobjectsphere(5,20,18,18)
setobjectposition(5,0,0,60)
textu(5) `Using textu(xxx) function with an AGK primitive ....nothing happens...it doesn't have any texture
setcameraposition(1,-80,80,-80)
SetCameraLookAt(1,0,0,0,0)
do
Print( ScreenFPS() )
Sync()
loop
function textu(n)
seterrormode(1) `...this line must be revised
tt$= GetObjectTextureName(n,1)
if tt$ >""
ima=1
while getimageexists(ima)
ima=ima+1
endwhile
ms=GetObjectNumMeshes(n)
for i= 1 to ms
textu$=GetObjectTextureName(n,i)
loadimage(ima,textu$)
setobjectmeshimage(n,i,ima,1)
inc ima
next
ms=0
endif
endfunction
function load3D(n,name$)
loadobject(n,name$)
textu(n)
endfunction
I'm not a grumpy grandpa