Compare commits

..

1 Commits

Author SHA1 Message Date
Swann Martinez
d93c227521 feat: initial material input support 2023-02-20 14:09:35 +01:00
6 changed files with 61 additions and 24 deletions

View File

@ -19,7 +19,7 @@
bl_info = { bl_info = {
"name": "Multi-User", "name": "Multi-User",
"author": "Swann Martinez", "author": "Swann Martinez",
"version": (0, 5, 8), "version": (0, 5, 7),
"description": "Enable real-time collaborative workflow inside blender", "description": "Enable real-time collaborative workflow inside blender",
"blender": (2, 82, 0), "blender": (2, 82, 0),
"location": "3D View > Sidebar > Multi-User tab", "location": "3D View > Sidebar > Multi-User tab",

View File

@ -64,7 +64,7 @@ def load_node(node_data: dict, node_tree: bpy.types.ShaderNodeTree):
if idx < len(inputs_data) and hasattr(inpt, "default_value"): if idx < len(inputs_data) and hasattr(inpt, "default_value"):
loaded_input = inputs_data[idx] loaded_input = inputs_data[idx]
try: try:
if inpt.type in ['OBJECT', 'COLLECTION']: if inpt.type in ['OBJECT', 'COLLECTION', 'MATERIAL']:
inpt.default_value = get_datablock_from_uuid(loaded_input, None) inpt.default_value = get_datablock_from_uuid(loaded_input, None)
else: else:
inpt.default_value = loaded_input inpt.default_value = loaded_input
@ -80,7 +80,7 @@ def load_node(node_data: dict, node_tree: bpy.types.ShaderNodeTree):
if idx < len(outputs_data) and hasattr(output, "default_value"): if idx < len(outputs_data) and hasattr(output, "default_value"):
loaded_output = outputs_data[idx] loaded_output = outputs_data[idx]
try: try:
if output.type in ['OBJECT', 'COLLECTION']: if output.type in ['OBJECT', 'COLLECTION', 'MATERIAL']:
output.default_value = get_datablock_from_uuid(loaded_output, None) output.default_value = get_datablock_from_uuid(loaded_output, None)
else: else:
output.default_value = loaded_output output.default_value = loaded_output
@ -351,6 +351,11 @@ def get_node_tree_dependencies(node_tree: bpy.types.NodeTree) -> list:
def has_texture(node): return ( def has_texture(node): return (
node.type in ['ATTRIBUTE_SAMPLE_TEXTURE','TEXTURE'] and node.texture) node.type in ['ATTRIBUTE_SAMPLE_TEXTURE','TEXTURE'] and node.texture)
def has_material(node): return (
node.type == 'MATERIAL' and node.inputs[2].default_value is not None
)
deps = [] deps = []
for node in node_tree.nodes: for node in node_tree.nodes:
@ -360,7 +365,9 @@ def get_node_tree_dependencies(node_tree: bpy.types.NodeTree) -> list:
deps.append(node.node_tree) deps.append(node.node_tree)
elif has_texture(node): elif has_texture(node):
deps.append(node.texture) deps.append(node.texture)
elif has_material(node):
print(node.inputs[2].default_value.name)
deps.append(node.inputs[2].default_value)
return deps return deps

View File

@ -26,8 +26,8 @@ import numpy as np
BPY_TO_NUMPY_TYPES = { BPY_TO_NUMPY_TYPES = {
'FLOAT': np.float32, 'FLOAT': np.float32,
'INT': np.int32, 'INT': np.int32,
'BOOL': bool, 'BOOL': np.bool,
'BOOLEAN': bool} 'BOOLEAN': np.bool}
PRIMITIVE_TYPES = ['FLOAT', 'INT', 'BOOLEAN'] PRIMITIVE_TYPES = ['FLOAT', 'INT', 'BOOLEAN']

View File

@ -31,11 +31,13 @@ DEFAULT_CACHE_DIR = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "cache") os.path.dirname(os.path.abspath(__file__)), "cache")
REPLICATION_DEPENDENCIES = { REPLICATION_DEPENDENCIES = {
"zmq", "zmq",
"deepdiff" "deepdiff==5.7.0"
} }
LIBS = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs") LIBS = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
REPLICATION = os.path.join(LIBS,"replication") REPLICATION = os.path.join(LIBS,"replication")
PYTHON_PATH = None
SUBPROCESS_DIR = None
rtypes = [] rtypes = []
@ -48,13 +50,13 @@ def module_can_be_imported(name: str) -> bool:
return False return False
def install_pip(python_path): def install_pip():
# pip can not necessarily be imported into Blender after this # pip can not necessarily be imported into Blender after this
subprocess.run([str(python_path), "-m", "ensurepip"]) subprocess.run([str(PYTHON_PATH), "-m", "ensurepip"])
def install_requirements(python_path:str, module_requirement: str, install_dir: str): def install_package(name: str, install_dir: str):
logging.info(f"Installing {module_requirement} dependencies in {install_dir}") logging.info(f"installing {name} version...")
env = os.environ env = os.environ
if "PIP_REQUIRE_VIRTUALENV" in env: if "PIP_REQUIRE_VIRTUALENV" in env:
# PIP_REQUIRE_VIRTUALENV is an env var to ensure pip cannot install packages outside a virtual env # PIP_REQUIRE_VIRTUALENV is an env var to ensure pip cannot install packages outside a virtual env
@ -63,7 +65,23 @@ def install_requirements(python_path:str, module_requirement: str, install_dir:
# env var for the subprocess. # env var for the subprocess.
env = os.environ.copy() env = os.environ.copy()
del env["PIP_REQUIRE_VIRTUALENV"] del env["PIP_REQUIRE_VIRTUALENV"]
subprocess.run([str(python_path), "-m", "pip", "install", "-r", f"{install_dir}/{module_requirement}/requirements.txt", "-t", install_dir], env=env) subprocess.run([str(PYTHON_PATH), "-m", "pip", "install", f"{name}", "-t", install_dir], env=env)
if name in sys.modules:
del sys.modules[name]
def check_package_version(name: str, required_version: str):
logging.info(f"Checking {name} version...")
out = subprocess.run([str(PYTHON_PATH), "-m", "pip", "show", name], capture_output=True)
version = VERSION_EXPR.search(out.stdout.decode())
if version and version.group() == required_version:
logging.info(f"{name} is up to date")
return True
else:
logging.info(f"{name} need an update")
return False
def get_ip(): def get_ip():
@ -99,7 +117,21 @@ def remove_paths(paths: list):
if path in sys.path: if path in sys.path:
logging.debug(f"Removing {path} dir from the path.") logging.debug(f"Removing {path} dir from the path.")
sys.path.remove(path) sys.path.remove(path)
def install_modules(dependencies: list, python_path: str, install_dir: str):
global PYTHON_PATH, SUBPROCESS_DIR
PYTHON_PATH = Path(python_path)
SUBPROCESS_DIR = PYTHON_PATH.parent
if not module_can_be_imported("pip"):
install_pip()
for package_name in dependencies:
if not module_can_be_imported(package_name):
install_package(package_name, install_dir=install_dir)
module_can_be_imported(package_name)
def register(): def register():
if bpy.app.version >= (2,91,0): if bpy.app.version >= (2,91,0):
@ -107,21 +139,12 @@ def register():
else: else:
python_binary_path = bpy.app.binary_path_python python_binary_path = bpy.app.binary_path_python
python_path = Path(python_binary_path)
for module_name in list(sys.modules.keys()): for module_name in list(sys.modules.keys()):
if 'replication' in module_name: if 'replication' in module_name:
del sys.modules[module_name] del sys.modules[module_name]
setup_paths([LIBS, REPLICATION]) setup_paths([LIBS, REPLICATION])
install_modules(REPLICATION_DEPENDENCIES, python_binary_path, install_dir=LIBS)
if not module_can_be_imported("pip"):
install_pip(python_path)
deps_not_installed = [package_name for package_name in REPLICATION_DEPENDENCIES if not module_can_be_imported(package_name)]
if any(deps_not_installed):
install_requirements(python_path, module_requirement='replication', install_dir=LIBS)
def unregister(): def unregister():
remove_paths([REPLICATION, LIBS]) remove_paths([REPLICATION, LIBS])

@ -1 +1 @@
Subproject commit 3e9eb4f5c052177c2fe1e16ff5d1f042456c30d0 Subproject commit b60feead9d30c0888767fa9ad1df21a40b89c05f

View File

@ -44,6 +44,13 @@ DEFAULT_PRESETS = {
"admin_password": "admin", "admin_password": "admin",
"server_password": "" "server_password": ""
}, },
"public session" : {
"server_name": "public session",
"ip": "51.75.71.183",
"port": 5555,
"admin_password": "",
"server_password": ""
},
} }
def randomColor(): def randomColor():