Skip to content

Commit

Permalink
maybe-lastjutsu
Browse files Browse the repository at this point in the history
Co-Authored-By: Lorenzo Federici <federici.l30@gmail.com>
Co-Authored-By: Andrian Melnic <andrianmelnic29@gmail.com>
  • Loading branch information
3 people committed Jun 17, 2022
1 parent e436dd4 commit c98b963
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 108 deletions.
26 changes: 5 additions & 21 deletions install-dependencies.command
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,17 @@ fi
BLENDER_SCRIPTS_DIR="/Applications/Blender.app/Contents/Resources/2.92/scripts"
BLENDER_MODULE_DIR="/Applications/Blender.app/Contents/Resources/2.92/scripts/modules"

# create the 'modules' directory in blender if not already there
mkdir -p "$BLENDER_SCRIPTS_DIR"/modules
# make sure pip version is up-to-date
pip install -t $BLENDER_MODULE_DIR -U pip
# install dependencies
echo "\n${bold}> installing pip modules...${normal}"
pip install -t $BLENDER_MODULE_DIR wget numpy scipy chumpy opencv-python resampy python-speech-features tensorflow==1.15.2 scikit-learn image ipython matplotlib trimesh pyrender
pip install -t $BLENDER_MODULE_DIR --upgrade protobuf==3.20.0
pip install -t $BLENDER_MODULE_DIR https://github.com/MPI-IS/mesh/releases/download/v0.4/psbody_mesh-0.4-cp37-cp37m-macosx_10_9_x86_64.whl
cp $SCRIPT_PATH /Applications/Blender.app/Contents/Resources/2.92/scripts/modules/OpenGL/platform/ctypesloader.py

# # create a hidden directory for the venv in the home
# echo "\n${bold}> creating the python virtual environment${normal}"
# mkdir -p .virtualenvs
# # create the virtual environment and activate it
# python3 -m venv .virtualenvs/vocablender
# source .virtualenvs/vocablender/bin/activate
# # make sure pip version is up-to-date
# pip install -U pip
# echo " ${bold}ok${normal}"
# # install dependencies
# echo "\n${bold}> installing pip modules...${normal}"
# pip install wget numpy scipy chumpy opencv-python resampy python-speech-features tensorflow==1.15.2 scikit-learn image ipython matplotlib trimesh pyrender
# pip install --upgrade protobuf==3.20.0
# cp $SCRIPT_PATH .virtualenvs/vocablender/lib/python3.7/site-packages/OpenGL/platform/ctypesloader.py
# echo " ${bold}ok${normal}"

# # install mesh lib
# echo "\n${bold}> installing psbody-mesh...${normal}"
# pip install https://github.com/MPI-IS/mesh/releases/download/v0.4/psbody_mesh-0.4-cp37-cp37m-macosx_10_9_x86_64.whl
# echo " ${bold}ok${normal}"
echo " ${bold}ok${normal}"

# reset the python system version
pyenv local system
Expand Down
24 changes: 9 additions & 15 deletions install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,18 @@ else
exit 1
fi

# create a hidden directory for the venv in the home
echo "\n${bold}> creating the python virtual environment${normal}"
mkdir -p .virtualenvs
# create the virtual environment and activate it
python3 -m venv .virtualenvs/vocablender
source .virtualenvs/vocablender/bin/activate
BLENDER_SCRIPTS_DIR="/Applications/Blender.app/Contents/Resources/2.92/scripts"
BLENDER_MODULE_DIR="/Applications/Blender.app/Contents/Resources/2.92/scripts/modules"

# create the 'modules' directory in blender if not already there
mkdir -p "$BLENDER_SCRIPTS_DIR"/modules
# make sure pip version is up-to-date
pip install -U pip
echo " ${bold}ok${normal}"
pip install -t $BLENDER_MODULE_DIR -U pip
# install dependencies
echo "\n${bold}> installing pip modules...${normal}"
pip install wget numpy scipy chumpy opencv-python resampy python-speech-features tensorflow==1.15.2 scikit-learn image ipython matplotlib trimesh pyrender
pip install --upgrade protobuf==3.20.0
echo " ${bold}ok${normal}"

# install mesh lib
echo "\n${bold}> installing psbody-mesh...${normal}"
pip install https://github.com/MPI-IS/mesh/releases/download/v0.4/psbody_mesh-0.4-cp37-cp37m-linux_x86_64.whl
pip install -t $BLENDER_MODULE_DIR wget numpy scipy chumpy opencv-python resampy python-speech-features tensorflow==1.15.2 scikit-learn image ipython matplotlib trimesh pyrender
pip install -t $BLENDER_MODULE_DIR --upgrade protobuf==3.20.0
pip install -t $BLENDER_MODULE_DIR https://github.com/MPI-IS/mesh/releases/download/v0.4/psbody_mesh-0.4-cp37-cp37m-macosx_10_9_x86_64.whl
echo " ${bold}ok${normal}"

# reset the python system version
Expand Down
108 changes: 42 additions & 66 deletions voca-addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import shutil
from collections import namedtuple
from sys import platform


# CLASSES = []
# PROPS = {}
import time

# Declare all modules that this add-on depends on, that may need to be installed. The package and (global) name can be
# set to None, if they are equal to the module name. See import_module and ensure_and_import_module for the explanation
Expand All @@ -42,6 +39,17 @@

dependencies_installed = False

PROP_DEP = [
('installing', bpy.props.BoolProperty(default = False)),
('uninstalling', bpy.props.BoolProperty(default = False))
]

def refresh_all_areas():
for wm in bpy.data.window_managers:
for w in wm.windows:
for area in w.screen.areas:
area.tag_redraw()

def install_pip():
try:
# Check if pip is already installed
Expand Down Expand Up @@ -87,38 +95,6 @@ def install_and_import_module(module_name, package_name=None, global_name=None,
import_module(module_name, global_name, importable)


# def install_and_import_modules():
# # Create a copy of the environment variables and modify them for the subprocess call
# environ_copy = dict(os.environ)
# environ_copy["PYTHONNOUSERSITE"] = "1"

# temp_abs_dir = "/Users/sasageyo/Downloads/voca-blender/voca-addon/requirements.txt"
# subprocess.run([sys.executable, "-m", "pip", "install", "-r", temp_abs_dir], check=True, env=environ_copy)

# # The installation succeeded, attempt to import the module again
# for dependency in dependencies:
# import_module(dependency.module, dependency.name, dependency.importable)

# # fix protobuf module version
# subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "protobuf==3.20.0"], check=True, env=environ_copy)

# # install Mesh from remote wheel
# temp_whl = "https://github.com/MPI-IS/mesh/releases/download/v0.4/psbody_mesh-0.4-cp37-cp37m-macosx_10_9_x86_64.whl"
# subprocess.run([sys.executable, "-m", "pip", "install", temp_whl], check=True, env=environ_copy)

# # fix the OpenGL package
# src = "/Users/sasageyo/Downloads/voca-blender/script-utils/ctypesloader.py"
# dst = "/Applications/Blender.app/Contents/Resources/2.92/python/lib/python3.7/site-packages/OpenGL/platform/ctypesloader.py"
# try:
# shutil.copy(src, dst)
# print("File copied successfully.")
# except shutil.SameFileError:
# print("Source and destination represents the same file.")
# except PermissionError:
# print("Permission denied.")
# except:
# print("Error occurred while copying file.")

def complete_installation():
# Create a copy of the environment variables and modify them for the subprocess call
environ_copy = dict(os.environ)
Expand Down Expand Up @@ -147,24 +123,13 @@ def complete_installation():
except:
print("Error occurred while copying file.")

# def uninstall_modules():
# # Create a copy of the environment variables and modify them for the subprocess call
# environ_copy = dict(os.environ)
# environ_copy["PYTHONNOUSERSITE"] = "1"

# temp_abs_dir = "/Users/sasageyo/Downloads/voca-blender/voca-addon/requirements.txt"
# subprocess.run([sys.executable, "-m", "pip", "uninstall", "-y" "-r", temp_abs_dir], check=True, env=environ_copy)

def uninstall_modules():
# Create a copy of the environment variables and modify them for the subprocess call
environ_copy = dict(os.environ)
environ_copy["PYTHONNOUSERSITE"] = "1"

for dependency in dependencies:
# module_to_remove = dependency.package
# if dependency.package is None:
# module_to_remove = dependency.module

module_to_remove = dependency.module if dependency.package is None else dependency.package

subprocess.run([sys.executable, "-m", "pip", "uninstall", "-y", module_to_remove], check=True, env=environ_copy)
Expand Down Expand Up @@ -201,11 +166,6 @@ def custom_un_register(mode):
for klass in CLASSES:
bpy.utils.unregister_class(klass)


# GLOBAL Var ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class EXAMPLE_PT_warning_panel(bpy.types.Panel):
bl_label = "Dependencies Warning"
bl_category = "VOCA"
Expand All @@ -219,17 +179,20 @@ def poll(self, context):
def draw(self, context):
layout = self.layout

lines = [f"Please install the missing dependencies for the \"{bl_info.get('name')}\" add-on.",
f"1. Open the preferences (Edit > Preferences > Add-ons).",
f"2. Search for the \"{bl_info.get('name')}\" add-on.",
f"3. Open the details section of the add-on.",
f"4. Click on the \"{EXAMPLE_OT_install_dependencies.bl_label}\" button.",
f" This will download and install the missing Python packages, if Blender has the required",
f" permissions."]

if not context.scene.installing :
lines = [f"Please install the missing dependencies for the \"{bl_info.get('name')}\" add-on.",
f"1. Open the preferences (Edit > Preferences > Add-ons).",
f"2. Search for the \"{bl_info.get('name')}\" add-on.",
f"3. Open the details section of the add-on.",
f"4. Click on the \"{EXAMPLE_OT_install_dependencies.bl_label}\" button.",
f" This will download and install the missing Python packages, if Blender has the required",
f" permissions."]
else :
lines = [f"Installing the addon's dependencies",
f"Please, wait until the end of the process."]

for line in lines:
layout.label(text=line)


class EXAMPLE_OT_install_dependencies(bpy.types.Operator):
bl_idname = "example.install_dependencies"
Expand All @@ -246,15 +209,24 @@ def poll(self, context):

def execute(self, context):
try:
# change ui and refresh
context.scene.installing = True
refresh_all_areas()
context.area.tag_redraw()
time.sleep(1)
context.area.tag_redraw()
# start install ->
install_pip()
# install_and_import_modules()
for dependency in dependencies:
install_and_import_module(module_name=dependency.module,
package_name=dependency.package,
global_name=dependency.name,
importable=dependency.importable)

complete_installation()
# <- end install
# change ui and refresh
context.scene.installing = False
refresh_all_areas()

except (subprocess.CalledProcessError, ImportError) as err:
self.report({"ERROR"}, str(err))
Expand Down Expand Up @@ -299,8 +271,9 @@ class EXAMPLE_preferences(bpy.types.AddonPreferences):

def draw(self, context):
layout = self.layout
layout.operator(EXAMPLE_OT_install_dependencies.bl_idname, icon="CONSOLE")
layout.operator(EXAMPLE_OT_uninstall_dependencies.bl_idname, icon="CONSOLE")
row = layout.row()
row.operator(EXAMPLE_OT_install_dependencies.bl_idname, icon="CONSOLE")
row.operator(EXAMPLE_OT_uninstall_dependencies.bl_idname, icon="CONSOLE")

preference_classes = (EXAMPLE_PT_warning_panel,
EXAMPLE_OT_install_dependencies,
Expand All @@ -314,6 +287,8 @@ def register():

for cls in preference_classes:
bpy.utils.register_class(cls)
for (prop_name, prop_value) in PROP_DEP:
setattr(bpy.types.Scene, prop_name, prop_value)

try:
for dependency in dependencies:
Expand All @@ -326,10 +301,11 @@ def register():
# Don't register other panels, operators etc.
print("error, some packages are missing")


def unregister():
for cls in preference_classes:
bpy.utils.unregister_class(cls)
for (prop_name, prop_value) in PROP_DEP:
delattr(bpy.types.Scene, prop_name)

if dependencies_installed:
custom_un_register(False)
Expand Down
2 changes: 1 addition & 1 deletion voca-addon/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def execute(self, context):

# Call Import Meshes
try:
bpy.ops.opr.meshimport('EXEC_DEFAULT')
bpy.ops.opr.meshimport('EXEC_DEFAULT', choice = 2)
except Exception as e:
self.report({"ERROR"}, ("Errore: " + str(e)))

Expand Down
4 changes: 2 additions & 2 deletions voca-addon/smpl_webuser/posemapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
'''

import chumpy as ch
# import numpy as np
# import cv2
import numpy as np
import cv2


class Rodrigues(ch.Ch):
Expand Down
6 changes: 3 additions & 3 deletions voca-addon/smpl_webuser/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

__all__ = ['load_model', 'save_model']

# import numpy as np
import numpy as np
import _pickle as pickle
# import chumpy as ch
# from chumpy.ch import MatVecMult
import chumpy as ch
from chumpy.ch import MatVecMult
from . posemapper import posemap
from . verts import verts_core

Expand Down

0 comments on commit c98b963

Please sign in to comment.