Skip to content

Commit

Permalink
Version 0.1. Removed dependencies from binvox, trimesh, open3d. Auto-…
Browse files Browse the repository at this point in the history
…install dependencies, mirroring, post-generation utilities
  • Loading branch information
pKrime committed Jul 17, 2021
1 parent f28ff66 commit e94f835
Show file tree
Hide file tree
Showing 20 changed files with 3,459 additions and 430 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
__pycache__
_additional_modules
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "RigNet"]
path = RigNet
url = https://github.com/zhan-xu/RigNet.git
url = https://github.com/pKrime/RigNet.git
161 changes: 146 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# bRigNet
bRigNet
---------
Neural Rigging for [blender](https://www.blender.org/ "Blender Home Page") using [RigNet](https://zhan-xu.github.io/rig-net/ "RigNet Home Page")

Blender is the open source 3D application from the Blender Foundation. RigNet has been presented in the following papers
Blender is the open source 3D application from the Blender Foundation. RigNet is the Machine Learning prediction
for articulated characters. It has a dual license, GPL3 for open source projects, commercial otherwise.
It was presented in the following papers

```
@InProceedings{AnimSkelVolNet,
Expand All @@ -23,31 +25,147 @@ Blender is the open source 3D application from the Blender Foundation. RigNet ha
}
```

**Warning:** this addon is experimental, the install procedure is clumsy and the code could be better.
Everything about it could change, hopefully in good.

## Setup
Follow [RigNet instruction](https://github.com/zhan-xu/RigNet "RigNet repository")
and create a Python environment with all required packages

For compatibility reasons, [Pillow](https://python-pillow.org/) must be installed in blender.
You can install pip following [this guide](http://www.codeplastic.com/2019/03/12/how-to-install-python-modules-in-blender/ "pip in blender"),
then
bRigNet requires SciPy, PyTorch and torch-geometric, along with torch-scatter and torch-sparse.

## Installation

Download the Neural Rigging add-on as a .zip file and install it from the blender addons window,
or copy the code to the blender scripts path

### Install dependencies via "Install" button

At present, the CUDA toolkit from nVidia is required, it can be found at the
[manifacturer website](https://developer.nvidia.com)

A dependency installer is available in the preferences.

* Install CUDA. At present prebuilt packages support versions 10.1, 10.2, 11.1
* In the addon preferences, make sure that the Cuda version is detected correctly.
* Hit the "Install" button. It can take time!

Alternatively, Environment managers, like conda or virtualenv can be used to ease the install.

### Install dependencies using *conda*

Anaconda is a data science platform from Anaconda Inc., it can be downloaded from the
[company website](https://www.anaconda.com/).

A lightweight version called [Miniconda](https://docs.conda.io/en/latest/miniconda.html) is available.
Both versions include the package manager 'conda' used in the following steps.

- Open a Miniconda or Anaconda prompt
- Create a Conda Environment and activate it

```
[BLENDER_DIR]\[BLENDER_VER]\python\bin\python -m pip install --upgrade Pillow
conda create -n brignet python=3.7
conda activate brignet_deps
```

## Installation
- Install PyTorch. If CUDA is installed, the CUDA version can be queried in a command prompt. For example

Download bRigNet as a .zip file and install it from the blender addons window,
or copy the code to the blender scripts path
```
nvcc --version
```
```
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:32:27_Pacific_Daylight_Time_2019
Cuda compilation tools, release 10.2, V10.2.89
```

In this case PyTorch can be installed in the command prompt via

```
conda install pytorch==1.8.1 cudatoolkit=10.2 -c pytorch
```

More complete information on the PyTorch command line can be found at the [PyTorch website](https://pytorch.org/)
The install command on non-cuda devices is

```
conda install pytorch==1.8.1 cpuonly -c pytorch
```

- Install torch utilities. The syntax follows the pattern

```
pip install [package-name] -f https://pytorch-geometric.com/whl/torch-[version]+cu[cuda-version].html
```

```
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.1+cu102.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.1+cu102.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.1+cu102.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.1+cu102.html
pip install torch-geometric
```

Alternatively, pip can try and build the libraries. Even if part of torch-sparse fails without a proper environment,
the rilevant modules are usually built

```
pip install torch-scatter
pip install torch-sparse
pip install torch-geometric
```

The directory of each environment can be obtained via

```
conda info --envs
```

The environment directory can be set in the "Additional Modules" setting of the bRigNet preferences

### Install dependencies using virtualenv

virtualenv can be used to create a Python environment with the required packages.
First, python 3.7 must be installed on the system. It can be found at https://www.python.org/downloads/

Make sure that **Add Python 3.7 to PATH** is checked in the setup options.

Usually, python comes with its package manager installed (pip). Please, refer
to the [pip documentation](https://pypi.org/project/pip/) if pip is not present in your system.

Next step is to install virtualenv. Open a command prompt and reach a folder where python packages will be kept
please execute.

```
pip install virtualenv
```

then create the virtual environment and activate it

```
virtualenv brignet_deps
cd brignet_deps
Scripts\activate
```

now we can install the torch library. At present, version 1.8.1 is provided.
torch-geometric provides prebuilt packages for CUDA 10.1, 10.2, 11.1

CUDA 10.2 is used in this example:

```
pip install torch==1.8.1+cu102 -f https://download.pytorch.org/whl/torch_stable.html
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.1+cu102.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.1+cu102.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.1+cu102.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.1+cu102.html
pip install torch-geometric
```

the virtual environment directory can be set as the "Additional modules path" in the brignet preferences

## Usage
Enable *bRigNet* in the blender addons, the preferences will show up.
Set the Modules path properties to the RigNet environment from the previous step

RigNet requires a trained model. They have made theirs available at [this address](https://umass.box.com/s/l7dxfayrubf5qzxcyg7can715xnislwm)
RigNet requires a trained model. They have made theirs available at [this address](https://umass-my.sharepoint.com/:u:/g/personal/zhanxu_umass_edu/EYKLCvYTWFJArehlo3-H2SgBABnY08B4k5Q14K7H1Hh0VA)
The checkpoint folder can be copied to the RigNet subfolder.
A different location can be set in the addon preferences.

Expand All @@ -63,6 +181,19 @@ on which to transfer the final weights
Rigs generated using RigNet from the command line can be loaded via the **Load Skeleton** panel.
Please select the *.obj and *.txt file and press the button **Load Rignet character**

## Training

The blender addon doesn't cover training yet. If you want to train your own model, please follow the instructions
from the [RigNet project](https://github.com/zhan-xu/RigNet#training).

## Disclaimer

This blender implementation of RigNet and the author of this add-on are NOT associated with the University of
Massachusetts Amherst.

This add-on has received a research grant from the Blender Foundation.

## License

bRigNet is released under the GNU General Public License version 3. RigNet is licensed under the General Public License Version 3 (GPLv3), or under a Commercial License.
This addon is released under the GNU General Public License version 3 (GPLv3).
The RigNet subfolder is licensed under the General Public License Version 3 (GPLv3), or under a Commercial License.
44 changes: 28 additions & 16 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,62 @@


bl_info = {
"name": "bRigNet",
"version": (0, 0, 1),
"name": "Neural Rigging",
"version": (0, 1, 0),
"author": "Paolo Acampora",
"blender": (2, 90, 0),
"description": "Armature and Weights prediction using RigNet",
"location": "Armature properties",
"location": "3D Viewport",
"doc_url": "https://github.com/pKrime/brignet",
"category": "Rigging",
}

import bpy

from . import brignet, preferences, loadskeleton
from . import postgen_utils
from .ui import menus

from importlib import reload
try:
reload(brignet)
reload(preferences)
reload(loadskeleton)
reload(postgen_utils)
except NameError:
pass

from .brignet import BrignetPanel, BrigNetPredict, BrignetRemesh, BrignetCollection
from .preferences import BrignetPrefs
from .preferences import BrignetPrefs, BrignetEnvironment
from .loadskeleton import LoadRignetSkeleton, LoadSkeletonPanel

from .postgen_utils import NamiFy, ExtractMetarig, SpineFix, MergeBones


# REGISTER #

def register():
from importlib import reload
try:
reload(brignet)
reload(preferences)
reload(loadskeleton)
except NameError:
pass

brignet.register_properties()
bpy.utils.register_class(BrignetEnvironment)
bpy.utils.register_class(BrignetPrefs)
bpy.utils.register_class(BrignetCollection)
bpy.utils.register_class(BrignetRemesh)
bpy.utils.register_class(BrigNetPredict)

bpy.utils.register_class(NamiFy)
bpy.utils.register_class(ExtractMetarig)
bpy.utils.register_class(SpineFix)
bpy.utils.register_class(MergeBones)

bpy.utils.register_class(BrignetPanel)
bpy.utils.register_class(LoadRignetSkeleton)
bpy.utils.register_class(LoadSkeletonPanel)

if not BrignetPrefs.append_rignet():
print("RigNet not found, please set in bRigNet preferences")
if not BrignetPrefs.append_modules():
BrignetPrefs.check_cuda()
if not BrignetPrefs.add_module_paths():
print("Modules path not found, please set in bRigNet preferences")
BrignetPrefs.check_modules()

bpy.types.VIEW3D_MT_pose_context_menu.append(menus.pose_context_options)


def unregister():
Expand All @@ -79,11 +83,19 @@ def unregister():
# if we have failed to load rignetconnect, we have no device to clear
pass

bpy.types.VIEW3D_MT_pose_context_menu.remove(menus.pose_context_options)
BrignetPrefs.reset_module_paths()

bpy.utils.unregister_class(BrignetPanel)
bpy.utils.unregister_class(BrignetPrefs)
bpy.utils.unregister_class(BrignetEnvironment)
bpy.utils.unregister_class(BrignetCollection)
bpy.utils.unregister_class(BrignetRemesh)
bpy.utils.unregister_class(BrigNetPredict)
bpy.utils.unregister_class(NamiFy)
bpy.utils.unregister_class(ExtractMetarig)
bpy.utils.unregister_class(SpineFix)
bpy.utils.unregister_class(MergeBones)
bpy.utils.unregister_class(LoadSkeletonPanel)
bpy.utils.unregister_class(LoadRignetSkeleton)
brignet.unregister_properties()
Loading

0 comments on commit e94f835

Please sign in to comment.