Author: Nako

Binary Search For Duplicate Data

GOAL

The goal of this article it to describe an algorithm to find first target item or last target item from sorted list with duplication using binary search and how to implement them in C++.

What is binary search?

Binary search is one of the search algorithms, that finds position or judges existence of an target value on sorted array.

Binary search compares the current value defined as a half of target range of the array to the target value. Binary search compares the middle element of current target range in the array to the target value. The current target range is narrowed according to the result of comparison as below.

What if there are same values in the array?

If there are same values, the found element can be first one, last one or other. How can we change this algorithm to search for the smallest or largest element?

Find first index

If the value currently focused is equal to the target value, the current value is contained to the next range as a max value. End the process when min index equal to max index, then check if the min value is equal to the target value.

(more…)

[Trouble Shooting] Human Fall Flat Workshop in Unity

An error “ArgumentException: Input Axis Joystick Look Horizontal is not setup.” occurred when Play button clicked.

Some people have the similar problem as I have.
ArgumentException: Input Axis Joystick Look Horizontal is not setup.
Error: Input Axis Not Set Up

It’s easy to solve. Put “<SteamLibrary>\steamapps\common\Human Fall Flat\WorkshopPackage\ProjectSettings” into <UnityProjects>\<Project directory>.

The following is the detail of this problem.

Problem

I followed the guide to start creating workshop of Human Fall Flat in Unity. When I start “Play” mode, I couldn’t control the Human and he was twisted!!

The following is the detail of the error.

ArgumentException: Input Axis Joystick Look Horizontal is not setup.
 To change the input settings use: Edit -> Project Settings -> Input
HumanControls.get_calc_joyLook ()
HumanControls.ReadInput (System.Single& walkForward, System.Single& walkRight, System.Single& cameraPitch, System.Single& cameraYaw, System.Single& leftExtend, System.Single& rightExtend, System.Boolean& jump, System.Boolean& playDead, System.Boolean& shooting)
Multiplayer.NetPlayer.PreFixedUpdate ()
Multiplayer.NetGame.PreFixedUpdate ()
Multiplayer.NetGamePre.FixedUpdate ()

Cause

“Input Axis <NAME> is not setup.” means that the input axis named “NAME” is not defined in Input Manager. Click “Edit” > “Project Settings” > “Input” and check the list of input axis. There is no axis named “Joystick Look Horizontal”.

The project settings, including the “Input Axis”, are defined in the “ProjectSettings” directory in steamapps. Therefore, you need to place this ProjectSettings directory in your own project directory. In my case, I placed a wrong one.

Solution

Close unity project. And put the “ProjectSettings” into the project directory.

Result

You can control the character with no error.

Error “Docker.ApiServices.WSL2.WslKernelUpdateNotInstalledException”

This is a trouble shooting log.

Problem

I downloaded the installer of Docker-Desktop from download page here. And executed the installer and start Docker. Then the error was displayed after starting Docker-Desktop.

Cause

Let’s see the window behind the exception window by Microsoft .NET Framework.

The WSL 2 Linux kernel is now installed using a separate MSI update package.
Please click the link and follow the instructions to install the kernel update:
http://aka.ms/wsl2kernel.

Press Restart after installing the Linux kernel.

That’s the cause of the error. We should install “WSL 2” by ourselves now.

Solution

Install WSL 2 Linux kernel whose installer is in http://aka.ms/wsl2kernel.

from wsl_update_x64.msi

After installing WSL 2, restart the Docker-Desktop.

The window displayed when started successfully

[Trouble Shooting] Cannot Use Library In Jupyter Notebook

Environment

Python 3.8.4
pip 20.1.1

Problem

I installed “matblotlib” by using pip3 command on the terminal as below. I can import matplotlib on the terminal.

% pip3 install matplotlib 
% python3
Python 3.8.4 (default, Jul 14 2020, 02:58:48) 
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> 

In jupyter notebook,

import matplotlib
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-0484cd13f94d> in <module>
----> 1 import matplotlib

ModuleNotFoundError: No module named 'matplotlib'

Check the situation

The reference path for jupyter notebook might differ from the one of host python3.

Jupyter notebook refers the python 3.8 in jupyterlab/2.2.0/libexec/lib

import sys
print(sys.version)
print(sys.path)

3.8.4 (default, Jul 14 2020, 02:58:48) 
[Clang 11.0.3 (clang-1103.0.32.62)]
['/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python38.zip', '/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python3.8', '/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python3.8/lib-dynload', '/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8', '', '/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python3.8/site-packages', '/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python3.8/site-packages/IPython/extensions', '/Users/<username>/.ipython']

On terminal, Python3 is in /usr/local/Cellar.

>>> import sys
>>> print(sys.version)
>>> print(sys.path)

3.8.4 (default, Jul 14 2020, 02:58:48) 
[Clang 11.0.3 (clang-1103.0.32.62)]

['', '/usr/local/Cellar/python@3.8/3.8.4/Frameworks/Python.framework/Versions/3.8/lib/python38.zip', '/usr/local/Cellar/python@3.8/3.8.4/Frameworks/Python.framework/Versions/3.8/lib/python3.8', '/usr/local/Cellar/python@3.8/3.8.4/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload', '/usr/local/lib/python3.8/site-packages']

Cause

In my case, the problem caused by homebrew. Installation of Jupyter Lab or Jupyter Notebook with brew command caused the different reference to python3 as above.

We can check the list of installed items with the following command on the terminal.

% brew list
autoconf	ipython		openssl@1.1	python@3.8	xz
flake8		jupyterlab	pandoc		readline	zeromq
gdbm		libyaml		perl		ruby
gettext		lua		pkg-config	sqlite
icu4c		node		pyenv		vim

Solution

My solutions is to uninstall jupyterlab with brew command and install it again with pip3.

% brew uninstall jupyterlab
Uninstalling /usr/local/Cellar/jupyterlab/2.2.0... (7,150 files, 106.8MB)

% python3 -m pip install jupyterlab
Collecting jupyterlab
  Downloading jupyterlab-3.1.7-py3-none-any.whl (8.5 MB)
     |████████████████████████████████| 8.5 MB 136 kB/s 
...

Start Jupyter Lab from the terminal.

% jupyter lab

I found another it could be a solution for similar problem to install ipykernel. Check ModuleNotFound Error for matplotlib for detail.

Token Authentication For GitHub

GOAL

Today’s goal is to setup for using token-based authentication in GitHub.

Background

In July 2020, we announced our intent to require the use of token-based authentication (for example, a personal access, OAuth, or GitHub App installation token) for all authenticated Git operations. Beginning August 13, 2021, we will no longer accept account passwords when authenticating Git operations on GitHub.com.

from “Token authentication requirements for Git operations”

Refer to “Token authentication requirements for Git operations” in the GitHub blog for more information.

Environment

Windows10
Git 2.19.0
GitHub

Method

See Creating a personal access token.

You can use generated token instead of the password for GitHub in Git Bash or Git GUI.

[Trouble Shooting] error “fatal: refusing to merge unrelated histories” in Git

Problem

When I tried to pull from remote repository, the error “fatal: refusing to merge unrelated histories” occurred. How can I solve it?

$ git pull origin main
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/s-nako/ColorSelector
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> origin/main
fatal: refusing to merge unrelated histories

Cause

This error occurs because “pull” command is targeted for 2 branches that has same root. In my case, remote main was generated on GItHub and local main was generated in local directory by “git init”.

Solution

Use “–allow-unrelated-histories” option for pull command as below.

$ git pull origin main --allow-unrelated-histories
From https://github.com/s-nako/ColorSelector
 * branch            main       -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

Blender Addon Naming Rules

GOAL

Today’s goal is to list naming rules and conventions of Blender addon.

Reference:
AddonPreferences(bpy_struct) from Blender 2.93.2 Release Candidate Python API documentation
Script Meta Info from wiki.blender.org

Environment

Blender 2.83 (Python 3.7.4)
Windows10

directory_name and file_name.py

Addon directory and files are snake_case with only lower cases. See examples in your addon directory, C:/Program Files/Blender Foundation/Blender 2.83/2.83/scripts/addons.

Addon Name

Addon name defined in bl_info is defined with the first letter of each word capitalized.

Class Name

2.8x enforces naming conventions for class name. Refer to “Class Registration” > “Naming” in “Blender 2.80: Addon API” reference for details.

The naming convention is UPPER_CASE_{SEPARATOR}_mixed_case. And {SEPARATOR} is defined according to the type of class as below.

  • Header -> _HT_
  • Menu -> _MT_
  • Operator -> _OT_
  • Panel -> _PT_
  • UIList -> _UL_

The followings are examples of panel class name.

# Header
# from "oscurart_tools" addon
class OSSELECTION_HT_OscSelection(bpy.types.Header):
    bl_label = "Selection Osc"
    bl_space_type = "VIEW_3D"

# Menu
# from "space_view3d_spacebar_menu" addon
class VIEW3D_MT_Space_Dynamic_Menu(Menu):
    bl_label = "Dynamic Context Menu"

class VIEW3D_MT_View_Menu(Menu):
    bl_label = "View"

# Operator
# from "add_camera_rigs" addon
class ADD_CAMERA_RIGS_OT_set_scene_camera(Operator):
    bl_idname = "add_camera_rigs.set_scene_camera"
    bl_label = "Make Camera Active"
    bl_description = "Makes the camera parented to this rig the active scene camera"

# Panels
# from "add_camera_rigs" addon
class ADD_CAMERA_RIGS_PT_camera_rig_ui(Panel, CameraRigMixin)
    bl_label = "Camera Rig"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = 'Item'

# UIList
# from "cycles" addon
class CYCLES_RENDER_UL_aov(bpy.types.UIList):
    def draw_item(self, ...

 bl_idname

bl_idname is specified to access the operator from python script in Blender. The bl_idname consists of snake_case words connected with dots.

# bl_idname in cycle/operators.py in cycle addon

class CYCLES_OT_use_shading_nodes(Operator):
    bl_idname = "cycles.use_shading_nodes"

class CYCLES_OT_add_aov(bpy.types.Operator):
    bl_idname="cycles.add_aov"

class CYCLES_OT_remove_aov(bpy.types.Operator):
    bl_idname="cycles.remove_aov"

class CYCLES_OT_denoise_animation(Operator):
    bl_idname = "cycles.denoise_animation"

class CYCLES_OT_merge_images(Operator):
    bl_idname = "cycles.merge_images"

 For headers, menus and panels, the bl_idname is expected to match the class name (automatic if none is specified). Refer to “Class Registration” > “Naming” in “Blender 2.80: Addon API” reference.

Other – PEP 8

Basically the naming rules of module, variable and so on is compliant with PEP 8.

variable = "hello"
variable_two = 2

def function_name(arg_name):
    pass

class ClassName():
    def __init__(self, arg_name):
        self.variable = 1
    def method_name(self):
        pass

How To Use Human Meta-Rig in Rigify

GOAL

Today’s goal is to summarize the rigging method of Human Meta-Rig with Rigify addon in Blender.

I used a human model with MakeHuman.

Environment

Blender 2.83
Windows10

Method

1. Add Human meta rig

Activate addon “RIgging: Rigify” at first.

Import the model with Y-axis front.

Change the mode to “Object Mode” and click Add > Armature > Human(Meta-Rig).

Open metarig tab > Viewport Display and check “In Front” on to show the rig in front of all in the 3D View.

The human rig with “In Front” on

2. Adjust bones

Adjust rig size and locations of bone to fit the target mesh.
Don’t change the transforms of the object. Be sure to change transforms in “Edit Mode” not in “Object Mode“.

(more…)

How To Fix Texture Colored Pink In Blender

Problem

When I open Blender file, the textured model is rendered with pink single-colored texture. How can I fix it?

Texture node on Node Editor

Environment

Blender 2.8.3(LTS)
Windows10

Cause

Pink means missing texture. Blender couldn’t find the specified texture.

Solution

References: You can find solutions in the followings in most cases.
Why are all the textures in my file pink?
Pink textures in Blender and how to avoid them

However, this sometimes occurred when the texture is just overwritten. In that case, I fixed by following steps below.

1. Disconnect Image Texture Node from Base Color socket of Shader Node.

2. Reset texture in Image Texture Node on Node Editor

3. Reconnect Nodes