Blender – Making an UV Map for many seperate tiles but spare me the hand work :D

NOTICE : I just found out you just can select all seperated objects, go into Edit Mode and then create a UV Map for all of them at once. But I will let stand this article here for documentation purposes. 😀

I have a set of tiles, for example a castle. So I wanted to use just one UV Map for all of them, but I still needed them as single objects.

Doing this by hand is tedious. So I managed to find and adapt two python scripts, who do this for you.

As you can see every object has a name, that I will later need in the game engine, for example in Unity3D, to make a Prefab out of it.

So with every object selected, I use a script I adapted to generate a vertex group for every object for all its verticies in one group, which is named exactly as the object is named.

import bpy

selection_names = [obj.name for obj in bpy.context.selected_objects]

#adds all vertices to a vertix group with the object name

for name in selection_names:
    vg = bpy.data.objects[name].vertex_groups.new(name=name)
    verts = []
    for vert in bpy.data.objects[name].data.vertices:
        verts.append(vert.index)
    vg.add(verts, 1.0, 'ADD')

After that I join all the objects with Ctrl-J as usual, resulting in only one Object but all the vertex groups are still set correctly.

Then I auto-create the UV Map for the single object.

With this script ( I have to find where I found it again and by whom ) then I automatically seperate every object using the vertex groups and the name of the vertex group.

# coding=utf8
import bpy


def main():
    origin_name = bpy.context.active_object.name
    keys = bpy.context.object.vertex_groups.keys()
    real_keys = []
    for gr in keys:
        bpy.ops.object.mode_set(mode="EDIT")
        # Set the vertex group as active
        bpy.ops.object.vertex_group_set_active(group=gr)

        # Deselect all verts and select only current VG
        bpy.ops.mesh.select_all(action='DESELECT')
        bpy.ops.object.vertex_group_select()
        # bpy.ops.mesh.select_all(action='INVERT')
        try:
            bpy.ops.mesh.separate(type="SELECTED")
            real_keys.append(gr)
        except:
            pass
    for i in range(1, len(real_keys) + 1):
        bpy.data.objects['{}.{:03d}'.format(origin_name, i)].name = '{}.{}'.format(
            origin_name, real_keys[i - 1])


if __name__ == '__main__':
    main()

After that I have all the objects seperated named correctly, using their part of the shared UVMAP. 😀

Now I use the combined one to paint it in a PBR Software like Substance Painter or Armor Paint to generate the big texture using the combined texture.

This approach saves me hours. It might not be the best thing to use big 2K textures but it saves loading time and makes changing whole tilesets textures easier.

The Generic Menu – bon appetité – Part 1

(this article is more for myself and for future documentation, but it might be interesting for people struggling with Generic Menus.)

For my Interaction Project one main goal is that you can add Flags easily to an Actionable Object Flag Dependency.

Meaning : If there is a chest which can be opened, then you add a flag to it like „open“. The open and the close action then depend and act on the state of that flag.

For adding a flag dependency to an Actionable Object, I wanted a fast, organized and quick way to choose a flag. For this I use an Generic Menu in the Editor Script for the Flag Dependency Class, a custom Property Drawer.

(Of course, if you have multiple chest this gets a bit confusing when they have the same name, but I will add a menu entry for the flags in the current editied AO. Also there are some more ways to group AOs, like region, area, group, scene…)

My first approach used simply the flag names. But this did not work out. I need a unique identifier for each flag. That is necessary cause Actionable Objects Flag Dependencies can depend on flags from other AOs. Also to be able to clone an Actionable Object easily, for example windows or doors, you need to be able to create the flags with the same name but with another unique identifier.

Also there was one small problem I solved for this to work : Since there can be more than one Action in an AO logically, the menu in each of these has to report to the AO which Action actually used a menu to create a new flag dependency.

I solved this by adding the unique property path to the return value of the selected menu item.

flagNameToAdd = property.propertyPath + "\n" + flagNameToAdd;

Here I still use the flag name instead of the flag uniquie uint identifier.

Then the next „trick“ I used is to place the selected menu item string into an member of the FlagDependencyDrawer. In the next OnGUI the drawer checks if the member variable is empty, if not, it parses the content and creates the Flag Property accordingly. It also makes sure that the string is for this drawer, which seems a bit redundent, but seemed necessary at the time.

if (property.propertyPath == propertyPath)

Getting a human-readably entry (like a key) from your Input Map in Unity3D

I am using the „new“ Input System of Unity, which I really like.

For my Interaction Project I needed the mapping of an action in a human readable form.

First add

using UnityEngine.InputSystem;

Then, in your class where you need it, for example a config dialog, or in my case, to show the correct key for an action on an Actionable Object when the player looks on it.

	public PlayerInput playerInput;

	public InputActionMap actionMap;

You can either drop the PlayerInput component in your Game Gameobject into it in the Inspector or just let it be initialized in the Start method.

Also in the Start() method :

		if (playerInput == null)
			playerInput  = GetComponent<PlayerInput>();

		actionMap = playerInput.currentActionMap;

        

        ReadOnlyArray<InputBinding> actions = playerInput.actions["Interaction1"].bindings;

		foreach(InputBinding binding in actions)
        {
			Debug.Log(binding .ToDisplayString());
        }

Interaction1 is the action I am looking for. I then iterate through all the bindings and display them as a readable string. (In this case I only have one binding though)

The action is mapped to the keyboard key E, so I get a plain and nice E as result, which is exactly what I needed.

References :

Unity3D Input System Reference

Unity3D Input System Reference – ToDisplayString

Running Unity3D WebGL with a local Apache Server

Well, it is much easier than I thought. If you know Apache, that is.

I tried to use the Live Server Plugin from Visual Code first, but that has no gzip module, so it can not be used for compressed builds. Meaning : You always would have to compile twice, and that I find stupid.

So I installed the Windows Apache Binaries from here for example, which have libz and even the Brokoli ? compression modules enabled by default.

„Running Unity3D WebGL with a local Apache Server“ weiterlesen

2021. Happy new yeah.

While still working on perfecting my Interaction Project, a little framework to easily create interaction between objects based on a easy to manage flag system, I am running into old problems when creating a WebGL Build for the current mini-game.

  1. The script at (localhost:x) embroid1.framework.js.gz was loaded, even if its MIME-Typ („application/gzip“) is no valid MIME-Type for JavaScript
  2. Uncaught SyntaxError: illegal character U+001F embroid1.framework.js.gz:1
  3. Uncaught ReferenceError: unityFramework is not defined onload http://localhost:x/Build/embroid1.loader.js:1

I had this before. I solved it. But it was quite a long time ago last year.

I will find the solution again and then post it here.

Also hopefully more posts about my Interaction Project this month and some cc0 textures / materials I made with the Substance Suite, with which I have fallen in love.

The flag of Interaction – more about the FlagSystem of Interaction Project

To speed up the whole flag system handling, I wrote a custom inspector for the ActionableObject class.

The flags for the Actionable Object can easily be created/deleted in the custom inspector. Also the initial status can be set.

Important is here that by creating/deleting Flags for that ActionableObject they automatically get registered in the Flag System Manager.

With this other ActionableObjects as well every other Object that uses the flag system can access the flags in their Actions.

Every AO or any object that wants to use Flags need a FlagDependency List.

A custom property drawer for it handles everything inside it, so there is no need for any calls to the class which the FlagDependency List is part of.

But how to keep track of all the flags of all objects ? Here comes the „Add Flag Dependency“ Button into play. This button opens a menu that has a list of all available flags for all Objects that have registered flags.

So much for that now.

Footsteps on terrain.

While the basic system of the InterAction Project is now working fine and bug free (as far as I can tell) and with A LOT of error preventing checks and feedback on them (no automated test for now, but this will come), I actually try to implement footsteps on terrain.

For normal meshes I have done a working solution with a custom FeetSoundMaterial.

I also found a way to get the dominant texture at the position of the terrain where the player (or any other moving entity) stands as an index.

BUT since I am using the experimental terrain tools, I was curious if I could use the enhanced layer system of the terrain tools package.

I drove deep into the source of the terrain tool packages, actually very interesting.

Would it not be cool if I just could enhance the scriptables Layer and add there my footstep audio files as list ? Then I just would need to retrieve the layer (not the TerrainLayer, that class is a sealed object, so I sadly can not make a derived class from it, which would be the coolest way.)

But I would have to change a lot in the editor implementation of the terrain tools to be able to use my own Layer scriptables. So it seems I have to go the boring way and just make another class which combines the TerrainLayer index with the fitting footsteps. Which also means I have to keep track of the indexes and changes there by hand, which is very boring.

Make some noise (with your feet) (InterAction Project Status Update)

The InterAction Project has two different kinds of Player steering modes : One for Adventure-like games and one that is more the classic FPS steering. But despite which is used : You probably need footsteps.

The character controller I am writing for the InterAction Project (which of course does not have to be used) makes use of a set of components that provide foot step sounds, depending on the material the player is walking on.

For now it is supporting only meshes, but the terrain support is nearly done.

If you want to have foot steps while moving on a surface, you simply assign a FeetSoundMaterial component to it. Then you can assing multiple footstep sounds to this Material. Everything else is done by the FeetSoundManager component attached to the player.

The feet sound manager casts a ray down to the surface and retrieves the FeetSoundMaterial. It then takes the AudioClip[] array it gets from the FeetSoundMaterial and plays a random footstep sound IF no other footstep is playing.

Of course this could be done much better. Like a library of footsteps groups and then using the mesh material to select which group to use, just as an example.

But for now this works fine. 😀

[InterAction Project] Quest Nodes and FlagDependentObstacles

After hardening the whole system and capseling it into its own project, I can move on with other needed functionalites for it. Ah yes, also I versioned it with git, since my ultimate goal is it, to publish InterAction System on GitHub.

I needed for my adventure game the Quest Nodes and obstacles. The Quest Nodes (you could also call them location triggers) were allready in places, but not using the Flag System.

A QuestNode is a box collider set to a trigger, that, for now plays a sound and shows a message, optionally depending on flag settings.

A FlagDependent Obstacle is basicly the same, but instead of triggern it blocks passage depending on flags.

More about Actionable Objects. ( InterAction Project Series )

Let’s have a look how this little system I am doing enables the player to open and close this power block door, as a simple example.

The orange door you see in the scene view in the picture above has a component called ActionableObject. If the layer „ActionableObjects“ exists, a GameObject with this component on it will be set to this layer. This is needed because the raytracing of the EyeModule only hits on objects in this layer. (If the layer does not exist, errors will be thrown, but there is a convient editor menu where you can create all needed layers without having to add them manually.)

„More about Actionable Objects. ( InterAction Project Series )“ weiterlesen