[SOLVED] Understanding Khafile

Hi. I’m trying to understand more fully, how the khafile works.
So I have a few questions.

Question

  1. Does this line add any directory named “Sources” as a root… or something else? project.addSources('Sources');

  2. Are these lines added based on a haxe file in the engine, which requires these particular libraries?

project.addLibrary("C:/dev/armsdk/armory");
project.addLibrary("C:/dev/armsdk/iron");

I asked that because…

  1. I noticed only selected files from the Assets folder, are added to the khafile.
project.addAssets("C:/dev/armsdk/armory/Assets/brdf.png", { notinlist: true });
project.addAssets("C:/dev/armsdk/armory/Assets/smaa_area.png", { notinlist: true });
project.addAssets("C:/dev/armsdk/armory/Assets/smaa_search.png", { notinlist: true });
  1. How can I get the khafile to add my own assets from a folder? I added them manually, but once the project is loaded, the khafile removes them.
    Hence, I know there has to be a way to get the khafile to automatically add them as assets.

Thanks for any help.

Hi, there is some documentation about khafiles here, although it’s not really verbose and somewhat incomplete.

1.
This line specifies where the source code of your project is. It is more or less equivalent to -cp in Haxe’s .hxml files. For Armory, it’s the place where you normally write your Haxe traits and where the logic node Haxe sources and Main.hx (the game’s entry point) are generated.

You can use addSources() multiple times in a project, it doesn’t have anything to do with root folders, it’s just a place where the Haxe compiler searches for source files (and Khamake potentially also does some smaller things with that path along the way, I don’t know).

2.
Imagine addLibrary() as a slightly more specific addSource() call, it’s basically another folder where Haxe searches for sources, and the particular lines you pasted are for the Armory and Iron source code that your game needs in order to work. addLibrary() can also be used to reference haxelib libraries for example, although it is rather discouraged by the Kha developer.

3.
project.addAssets() is used to add assets like images, sounds, fonts, etc. to the compilation. Depending on the target platform, Khamake may decide to convert the assets to file formats better suited for that platform. The specific lines you shared add assets required by some of Armory’s shaders. There should be more addAssets() calls though in your file, pointing to project-specific assets and files containing information about the exported materials.

4.
The khafile is automatically generated by Armory when you build the game, so you shouldn’t remove or change any existing code from it as it might break your game. However, you can append more code to the end of the file by writing it to a text document inside Blender and then refer to that in Armory Project > Modules > Khafile.

If you put your assets inside a /Bundled folder in the project’s root directory, Armory will automatically add references to them in the khafile. Any folders inside of /Libraries are automatically added as libraries, and folders inside of /Subprojects are picked up as subprojects (libraries with their own khafile)

That’s what I am wondering about.
Looking at the directory - …armsdk\armory\Assets, I noticed 20 items, but only 3 are referenced in the khafile.
That’s why I asked if these files are added based on a haxe file in the armory, which only requires these particular assets?

I also considered that possibility, because when I add anything to the khafile manually, once the project is loaded, the khafile removes them.

Hence, I am not able to manually edit the khafile. I have to put the files in the relevant directories, and the khafile automatically updates once the project is loaded. Like you said…

You said…

I did not know about writing text files in Blender. I guess that mean appending the saved file with the .txt extension.

This is quite useful information.
l think you covered my questions. Thanks.