Wednesday, December 11, 2013

THE ASSET PIPELINE EDITOR - PART 4

On part 3 of the series, I talked about some of the features related to solutions and projects. So now it's time for me to refer to another key feature of the editor: building assets.

The picture below shows the last state of the solution we were using as an example for the series:


Let me remind you that the raw files named "bkgClouds" were bound to different source files: one sized 640x400 texels and another sized 320x200 texels.

Since the APE does not come bundled with any import/write units other than the pass-through ones, y clicking in one of the raw files we'll get the following view on the raw file tab:


Thus, as you can see, the pass-through importer is assigned by default to all the raw files in the solution. This default importer has no properties we can modify since all it does is to copy the source file associated to each raw file to the destination folder without any kind of processing/formatting.

However, there is one property that I'd like to highlight here that I didn't mention on my previous posts, and that is the checkbox named "Build Asset ?". If you have been following the series then you'll likely remember that for solutions and projects you could indicate the actions to execute for building and copying/moving, right? Well, this checkbox allows us to override those settings for a specific raw file, so if we unmark it, no build/copy actions will be applied to that raw file.

In fact, if you carefully look at the first screenshot above corresponding to the solution tree, you will notice a checkbox beside some of the nodes. By checking/unchecking that control not only we can include/exclude a raw file for build/copy actions but also the nodes of an entire folder or container. And yes, when you save solutions and projects, this selections are also persisted. Nice!

Now, how can we build an entire solution or a specific project? Glad you asked. Please take a look at the picture below and follow the numbers:


First, for each project at a time, check the Project tab and select the corresponding values for each field. In particular for this example, we need to set the build/copy actions and indicate the correct path to copy/move the asset files. For now, we disregard the Group Id field and the writers grid since we have only one writer we can use at this moment and thus we have no use for the former.

Second, we indicate which nodes among the containers, folders and raw files must be included in or excluded from the build process by checking/unchecking the respective checkbox.

Third, we select the correct writer for the project ("Default Writer") for the compilation profile to use ("Debug", as shown in the picture above).

Fourth, we select whether to build the entire solution (that is to say, all projects) or one project (the one shown in the Project tab). Also, we indicate the target compilation profile (the one that corresponds to your game's executing assemby, as compiled in Visual Studio, Xamarin Studio, Eclipse, Netbeans or other).

Having done that, we also need to indicate for the solution whether we want our asset files copied or moved to their final location ...


Then, we are ready to go. So all we need to do is compile the solution or project by clicking the "Build" button (the arrow in green).


You can also build the solution or project using menu options, "F5" for the entire solution or "Control + F5" for the selected project.

Now, what result shall we obtain for our example? To see that, we pick one of the projects in the solution explorer and open its folder with the "Open In Explorer" menu option, say, the iPhone.


You will get as an asset file a copy of the image sized 320x200 texels. And believe me when I say that if we built the entire solution (or only the Windows project) we also get the image sized 640x400 texels as an asset file located in the path corresponding to the Windows project.

But this isn't all we get as the picture below shows:


The Ape mantains a repository on the corresponding path for our solution, but is also moves/copy the obtained files with the correct path structure to the location you specify as an output folder, adjusted for the corresponding compilation profile. Since we said we wanted all our asset copied, the "local" repository keeps a copy of all asset files. Otherwise, no local copies would exist.

Again, when we compile the solution we also obtain the asset for non selected projects -provided they are alos marked for build + copy/move actions.

Now, when your game expects a file with a specific format (other than public ones like png, jpg, wav, wmv, and so on so forth) and or a specific file extension, then the above example is not useful for you. Therefore, for the following example I'll use a Texture2D importer and a XNA-like writer for a Monogame project. But please remember that you can use the APE for any game engine not related to XNA/Monogame, provided that the corresponding import/write units are plugged into the editor.

So, allow me to introduce you to a nice feature that the APE has: clean solution/project.



Both operations are similar, being the only difference that cleaning the solution will clear the content of all projects. This operations must be used with caution since they will delete the entire content of the folders indicated in the corresponding lines and not only raw files and nested folders. So before pressing start we should check that the paths are right. You can always cancel the operation by clicking the cancel button or by closing the window -in case you need to. And you can indicate whether to clean one folder (the local folder or the output folder), both folders or none. This is indeed a handy and powerful feature, don't you think?

Ok, after cleaning the solution and adding the corresponding import/write units to the editor we are now able to reload our solution and once we get it, we need to get something like this:


In order to get it, first we need to select the only raw file we have on the Windows Project. Then, we need to select the category "Textures" (1) and finally select the importer named "Xna Texture Importer" (2), which in this case is selected by default. As you can see we get some information about the importer and, in this case, a couple of read-only properties ("Group Id" and "Is Source File Also Copied ?").

As a result of the above we can now realize in practice how the Group Id field on the Project tab can be used (3): a value of zero indicates that we want to target XNA/Monogame's HiDef profile and a value above it the Reach profile.

If we expand the panel with the properties for the 2D Texture Processor we'll get:


I won't explain each of the fields you see there. Some of them are similar to what we had on XNA's CP GUI but there are some additional ones -which I believe speak for them-selves. All I can say is that this is not a mock-up; in fact, it's a real processor in alpha stage currently consuming WPF's bindings for WIC. During the campaign at IndieGoGo I'll give more details about this.

After tweaking some of the parameters, let's have a look at the formatter:


Nothing to do here. The "Xna Binary Formatter" will give the proper format to the asset data but with one difference for those of us accustomed to XNA's CP (given the way I've implemented these import/write units): the XNA's header for the asset file is not included as part of the format. That will be added by the writer later on. Needless to say that you can design your import/write units so that the formatter includes the header instead of the writer, which is fantastic given that it shows how flexible the APE really is!!!

Ok then, and please again follow the numbers, before proceeding to compile the texture asset for the Windows project we'll need to get something like ...


First, we select the Window project.

Second, we need to set the proper writer for the compilation profile we are going to use (in this case, for "Debug").

Third, we need to select the "Normal" compression mode on the Writers panel instead of the "Automatic" one that is shown in the picture above. Why? Because I haven't implemented yet the so called LZX compression -which is a real pain, believe me- or any other compression for the writer.

I'd like to add a side note here: do you notice the data displayed on the writer panel for the Xna Writer? (default, version, etc.) In particular check the following three: "Writes checksum", "Requires password", "Encodes Data". These fields if marked as "Yes" indicate that the writer May or May Not do the associated task (depending on whether is activated manually/automatically as implemented by us), like calculating an writing an MD5/SHA checksum somewhere into the asset file, adding password protection and or encoding/encrypting the asset file. And if marked as "No" then the writer does not support that action.

Fourth, and this is really important: we need to save the solution!!! (this is required to apply changes)

Fifth, we need to indicate that we're going to build only a project (the selected one) for the "Debug" compilation profile.

Finally, build the assets by pressing the corresponding menu option, button or keyboard shortcut ("Control + F5"), being the result in the local repository the following:


This is a well-formatted xnb file with pre-multiplied alpha, a mip-mapped chain and its top-most texture resized to the nearest power-of-two value for 640x400 texels (I leave the answer to the latter as homework for you). Since this asset file is not LZX-compressed, its size on disk is rather high. Again, a copy of this file is located on the output folder that the XNA/Monogame solution uses.

Finally, if we run the game's solution with a line like the following within the method of the LoadContent operation ...


   this.texture = this.Content.Load<Texture2D>("textures/backgrounds/bkgClouds");
      

... and the corresponding one on the Draw method, as shown in the trailer for the APE, we'll get something like this on a WindowsGL-targeted game using Monogame (and please don't ask me "why do you need mipmaps for this example?"):


Enough said!

In the following parts we'll be getting into more technical stuff.

Cheers!
~Pete

Tuesday, December 10, 2013

THE ASSET PIPELINE EDITOR - PART 3

On part 2 of the series, I talked about some basic features of the APE, so it's time to show how to change the structure of a project and populate it with some raw files, that is, before starting to build assets.

I could begin this post by telling you how to create a new solution from scratch, but instead, I'll show you a nice small feature the editor has that allows you to open recent solutions, which spares you from having to use the Open Solution menu option ("Control + O") and browse folders until you locate the solution file.

Recent Solution List

Do you notice the small red (almost transparent) cross beside the only entry in the list of recent solutions? If you press it, you will be prompted to confirm entry's removal from the list. The cool thing is that APE does not need to restart in order to refresh the list. Ditto for "Clear All ..." option.

Once the solution is loaded we can start modifying the tree structure to meet the needs for our game. This is how the solution looks like so far:

The Solution So Far

Let's add a couple of nested folders to the Windows_Own container by selecting the "Add Folder" menu option (or clicking "Control + Shift + F") twice. Now our solution looks like this:


By default, folders will be created with the name "folder_<#>", so let's renamed them with a meaningful word (by double-clicking the node):


Better, right? But wait a minute! What if we want to have a similar structure on the default container? All you have to do is open a context menu for the node you want to copy (right-click over "textures") and you will be presented with this:

\
You have two options there: either you move or copy the node and all of its content to another non-nested location; in this case, to the Windows_Default container. Note: if you try to move or copy the "images" folder into the "backgrounds" folder the operation will fail.

Since we want to replicate the structure, we then select the copy option. Then, by opening the context menu fro the default container we will get the following:


By pressing paste, the new structure for our solution will look like this:


It's important to mention here than we could have obtained the same result by using drag'n'drop. Yes! Dragging the textures folder and dropping it onto the default container would have been allowed. In fact, when you drag'n'drop nodes in the solution explorer, the APE asks us what we want to do with them: move, copy or cancel.

Also, it's worth mentioning that, in this case, we could have copied the whole content of the self container ("Windows_Own") by using the context menu for the container. That is also allowed. The difference is that in this case the container it-self won't be moved or copied, just its child nodes.

Now, let's add some raw files. Shall we?

There are three ways to add raw files to containers or folders: (a) you select the container/folder and then use the "Add Raw File" menu option/button (or press "Control + Shift + R"), (b) you select the container/folder, open the context menu for it and click on the  "Add Raw File" option, or (c) you use drag'n'drop (you can import raw files into your solution by dragging them from the explorer and dropping them onto the container/folder).

In the picture below, you can see how to use the context menu for the target folder.


One important feature to mention here is that you can import more than one file at a time (batching) with any of the three ways the editor offers, including drag'n'drop.

For the example, we just added a nice cloud background to the backgrounds folder:


The picture above shows a lot of new information about the editor:

1. The name given to the added raw file is its filename (without the extension, if any). This is true provided that the name does not exist in the same "relative" location of the solution's structure, or else it will be renamed to "file_<#>".

2. On the container tab, the editor will show you the proper previewer for the file (remember that if none is found it will just show the system icon for it).

3. A new tab gets enabled: "Raw File". Here is were you tweak import settings for the raw file. The APE will try to assign an importer to it based on the file extension, giving priority to the importers marked as default (more on this on later posts).

4. The source file is copied into the "Sources" folder for the solution. This folder works as a repository for the entire solution, so you cannot have two source files co-existing with the same name on the folder since one of them will be replaced. This has nothing to do with the names you give to the nodes on the solution explorer (you can have two nodes with the same name in different "relative" locations on the solution tree).

In order to change the name of the raw file we could do it in the same way as before by double clicking on the node, but in this case we will use the "Name" field on the raw file tab and rename the node to "bkgClouds".

Now, before showing you how the structure of the solution currently looks like, let's add a new project for, say, the iPhone platform. And here it is ...


As you can see the default containers on both projects have the same exact structure; however, the self containers are different. In effect, that is the purpose of self containers.

Although the "bkgClouds" raw file is present in both default containers, it is treated as a deep copy; so mirror operations are bound only to add/remove/copy/move. For properties, like importer, processor and formatter-like settings, each node is independent, so you can have one set of settings for the raw file for the iPhone and a different set its sibbling on Windows. Really great!

Now, what if you want to import two different source files but keeping them under the same raw file on different projects? Let me translate it with an example ... say that you want to replace the source image for bkgClouds but only on the iPhone project with a lower_res version, well ... yes, you can! How? Simple. Look at the picture below:


On the Raw File tab there is field named "File" with a button labeled "..." (marked all in red), which shows the location to the source file in the solution. When you click on the button you can browse your folders until you get the file you desire.


In this case, we'll select the 320x200 texels version of the cloud image for the iPhone platform to get this window:


The APE will prompt us to confirm the operation and also it'll let us delete the existing source file if needed. Since this is not the case, given that we need both of them (one for Windows and the new one for iPhone) we let this checkbox unmarked.


Once the operation completes, the image previewer for the "bkgClouds" raw file on the iPhone project will show the new information. Now we have two different source files for the same logical name. And therefore, after building assets, when you load the "bkgClouds" texture on your game, you will get the 640x400 version on Windows and the 320x200 on the iPhone. No need to add "_640x400" or "_320x200" to the load operation.

Let's have a look at our solution's Source folder:

As you can see, the respository has both source files for the same raw file. And I guess that you now fully understand the difference between "source" and "raw"" file (if not, the former is the actual file and the latter its representation on the solution's tree).

Ok, before finishing this post, let me show you one more relevant feature the APE offers. For this task, say that you accidentally messed with the Source folder and deleted one of the images; for instance, the one ending in _640x400. What would happen? Well, when you re-open the editor, you will see the following:


The APE is indicating you that the solution is corrupted and also marks the path to the offending raw file. To fix it, you can either manually copy+paste the source file to the Sources folder or you can use the Raw File tab -as we did before- by clicking the "..." button beside the "File" field and browsing to the location of the source file.

In order to valdiate the solution you have to options, either you save, close and re-open the solution (in which case the APE will warn you that you are attempting to save a corrupt solution) or use the validate menu option ("Control + Shift + V") ...


Having finished the validation processed, the editor will look like this:


So, we can now safely continue to work normally with our solution and save it whenever we want.

Btw, you can browse to the folder where you solution is located by using the "Open In Explorer" menu item (ditto for projects) ...


And you'll get to ...


Do you notice the icon on "MySolution"? When the editor is closed you can open it and also load the solution by clicking its file. Indeed. The APE will open and load the solution for you.

Ok guys, this is all for this post. On my next post we'll talk about building assets.

See ya!
~Pete

Monday, December 09, 2013

THE ASSET PIPELINE EDITOR - PART 2

Continuing with the second part of the series, and before writing about technical stuff (the coding side), let me introduce you to the editor it-self.

When the Ape starts, the editor looks like the picture below:

Main Window

By default, the only tab that is enabled is the one named "General", where you can configure general settings to control the editor's behavior. There are a few options that speak for them-selves, like "Automatic check for updates", so I will refer to others which I believe deserve a few words since they will affect each solution/project created in a cascade manner:

1. Default Main Folder: every time you create a new solution, this is the folder that will be shown by default on the Folder dialog. Think of it as the directory that will hold your solutions and projects.

2. Default Root Folder: for every project created, this is the relative root folder assigned by default to each container. For those like me who come from XNA-based games, this is usally set to "content".

3. Default Build Action: this is the action to execute when building assets from raw files in solutions/projects, which can be "Build Always", "Build If Newer" and "Do Not Build".

4. Default Copy Action: this is the action to execute when copying assets after a build action finishes on a project, which can be "Copy Always", "Copy If Newer" and "Do Not Copy". You will see later that this also refers to "moving assets".

5. Available Platforms: this is the platforms that a solution can support and you can add/remove custom platforms to the ones provided by default. The one marked with an asterisk "(*)" indicates the project that will be automatically added when a new solution is created.

6. Default Writers Per Profile: this control has two purposes; you can add/remove/modify custom compilation profiles as well as the write units assigned by default to each and every one of them; again, the compilation profile marked with an asterisk "(*)" indicates the one that will be selected by default when a new solution is created.

Add Compilation Profile Window

When you add a new profile, you can set its name, the relative folder where assets will copy/move when built, and the default write unit for it. We'll get to the concept of a write unit on a later post.

7.  Default Importers Per Category: every import unit corresponds to a category (that you can set when creating the importer), so what you can define here is which will be the default importer for each category. When you add a raw file, the editor will find the category it fits in and from there it will try to assign the default importer; if no importer is found, it will move to a default category and importer (pass through).

Note: both, import and write units are plugged into to the APE as add-ons, so when you execute the tool, the editor will automatically create the collection of available import and write units.

8. Save/Reload Settings: when you change general settings you have to options: either you save the settings for future use or you reoad settings previously saved; if no settings are found (or saved settings get corrputed) the APE will generate and save default settings for you.

Now, what are Solutions and Projects?

A solution is the root node in the APE's logical tree which will directly hold projects as its child nodes. In other words, is the root node that will contain asset projects.

A project is the node that will contain the structure that will be used to build assets for a specific target platform. You can have as many projects you want on a solution but only one per target platform.

When you build a solution, all the project it contains will be built (unless you specify not to build one or more projects). Conversely, when you execute the build action on a specific project, the other will remain intact.

In order to create a new solution, you can open the "File" menu and select the "New Solution" option, click on the "New Solution" icon on the main tool bar, or press "Control + Shift + N".

New Solution Window

When you do that, a pop-ip window will prompt you to enter specific information like the name to give to your new solution, the folder where the solution file will be saved, whether a subfolder with the name you enter must be created or not and the "Output folder".

The latter is quite important since it indicates the path to the root folder where all assets generated for the default project will be copied or moved. It works like this, say you have a Visual Studio solution for a game you are developing (or a repository for the assets, not the raw files- to be used); you browse to this path, you select it, and from there the APE will append at build time the relative folders corresponding to the selected compilation profile as well as to each container, when it corresponds.

The initial structure of a solution is the following:

Initial Structure Of A Solution

Being the only project created the one that corresponds to the target platform inidicated as the default one on the general settings.

As you can see in the picture above there are two more nodes that are created by default within the project: the initial containers ending in "_Default" and "_Own".

The former holds raw files shared with all projects. Thus, when you add a new raw file to that container, a new node will be also added to the default containers in all remaining projects, with the same name.

And the latter holds raw files assigned only to that project. So, this container is where you put raw files that you don't want to share with other projects.

Now, there is a third type of container: partial containers (to which I also refer sometimes as "shared" containers).

Add New Shared Container

Say that you have three projects in the solution (Windows, XBoxOne, PS4) and you want to share content on the first two (Windows and XBoxOne); well, in order to do that you create a partial container for the windows project, add the XBox One platform and presto!

To add more projects to your solution you either select the "Add Project" item on the "Solution" menu, you click the "Create Project" button or press "Control + Shift + P".

Add Project To Solution

Again, you will be prompted to specify the output folder for the new project.

Ok, moving on ...

When you create or load a new solution, you will see that other tabs will get enabled: "Solution", "Project" and "Container".

Many options in the Solution tab are similar to the ones found in the General tab; in fact, this is where you start to benefit from the cascade approach given that you have the possibility to override the default values given to each "shared" option.

Solution Tab

But there is one more relevant option you can set for a solution: "Move Assets". The only explanation I will post for now is that when you build assets, the APE save them on a specific repository for each project and then, copy or moves each asset to its final destination folder (the one located in the output folder for a project).

For projects, the logic is the same as before, tweak parameters to override default values coming from the solution or general settings.

Project Tab

Here you can also indicate:

1. Group Id: even though you can set different behaviors per platform, you can also indicate affinity among specific platforms in order to set the course of action for import/write units. For instance, for XNA-based projects, and id of zero ("0") would mean a "HiDef" profile meanwhile one ("1") or above would mean "Reach" profile.

2. Copy To: remember that for new solutions you had to sepcify the output folder for the initial project? Well, you will have to do the same for the new project. So, each project can have its own output path, which is strongly recommended so that you avoid the risk of overwriting asset files.

3. Default Writers: not only you can override the values that come from the solution or general settings, but also you can change the folder that will be added to the output path when building assets for a specific compilation profile (like Debug, Release, etc.).

Regarding the Container tab, there is no much you can do there other than change the root folder, which is initially set to its default value (usually, "Content").

Container Tab

For default and self containers, names cannot be changed. For partial containers, you can set a different name, and you will also get a list of the projects it shares content with.

There is another tab that is also activated when a solution is created or loaded ("Writers") but I will refer to it on my next post.

Before reaching the end of this part, I would like to refer to the search tool, which you can use when you want to find nodes in the solution that start with a specific character or group of characters ("Control+F").

Search Tool

The beauty of this control is that you can do a new search recursively, that is, on top a previous search. So if you first search for "Windows" and then for "myImage", you will get all the nodes (and its children) that start with "myImage" within the nodes that start with "Windows". By the way, the top-most node (the solution) is not considered for this feature, so the result it would have been the same if you had entered "my" instead of "myImage".

By pressing the "Reset Search" button or "Control+Alt+F" the whole solution is again displayed on the explorer.

This is a powerful tool and I'm planing to extend it with additional features in the middle run.

Well, that's it for now. On part 3 I will talk about adding raw files, compiling projects and a few more useful features available on the APE.

Stay tuned,
~Pete