refactor: io_bpy architecture revamp
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
# ##### END GPL LICENSE BLOCK #####
|
# ##### END GPL LICENSE BLOCK #####
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
from replication.protocol import ReplicatedDatablock
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'bl_object',
|
'bl_object',
|
||||||
@ -48,9 +49,14 @@ __all__ = [
|
|||||||
# if bpy.app.version[1] >= 91:
|
# if bpy.app.version[1] >= 91:
|
||||||
# __all__.append('bl_volume')
|
# __all__.append('bl_volume')
|
||||||
|
|
||||||
from . import bl_object, bl_action, bl_scene, bl_mesh, bl_collection
|
|
||||||
from replication.protocol import DataTranslationProtocol
|
from replication.protocol import DataTranslationProtocol
|
||||||
|
|
||||||
def types_to_register():
|
def get_data_translation_protocol()-> DataTranslationProtocol:
|
||||||
return __all__
|
""" Return a data translation protocol from implemented bpy types
|
||||||
|
"""
|
||||||
|
bpy_protocol = DataTranslationProtocol()
|
||||||
|
for module_name in __all__:
|
||||||
|
impl = globals().get(module_name)
|
||||||
|
if impl and hasattr(impl, "_type") and hasattr(impl, "_type"):
|
||||||
|
bpy_protocol.register_implementation(impl._type, impl._class)
|
||||||
|
return bpy_protocol
|
@ -295,11 +295,12 @@ def load_vertex_groups(dumped_vertex_groups: dict, target_object: bpy.types.Obje
|
|||||||
|
|
||||||
class BlObject(ReplicatedDatablock):
|
class BlObject(ReplicatedDatablock):
|
||||||
bl_id = "objects"
|
bl_id = "objects"
|
||||||
bl_class = bpy.types.Object
|
|
||||||
bl_check_common = False
|
bl_check_common = False
|
||||||
bl_icon = 'OBJECT_DATA'
|
bl_icon = 'OBJECT_DATA'
|
||||||
bl_reload_parent = False
|
bl_reload_parent = False
|
||||||
|
|
||||||
|
is_root = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def construct(data: dict) -> bpy.types.Object:
|
def construct(data: dict) -> bpy.types.Object:
|
||||||
datablock = None
|
datablock = None
|
||||||
@ -711,3 +712,6 @@ class BlObject(ReplicatedDatablock):
|
|||||||
deps.extend(find_geometry_nodes_dependencies(datablock.modifiers))
|
deps.extend(find_geometry_nodes_dependencies(datablock.modifiers))
|
||||||
|
|
||||||
return deps
|
return deps
|
||||||
|
|
||||||
|
_type = bpy.types.Object
|
||||||
|
_class = BlObject
|
Submodule multi_user/libs/replication updated: 0614a09e70...adf5d8be88
@ -51,7 +51,7 @@ from replication.interface import session
|
|||||||
from replication.porcelain import add, apply, commit
|
from replication.porcelain import add, apply, commit
|
||||||
from replication.repository import Repository
|
from replication.repository import Repository
|
||||||
|
|
||||||
from . import bl_types, environment, timers, ui, utils
|
from . import io_bpy, environment, timers, ui, utils
|
||||||
from .presence import SessionStatusWidget, renderer, view3d_find
|
from .presence import SessionStatusWidget, renderer, view3d_find
|
||||||
from .timers import registry
|
from .timers import registry
|
||||||
|
|
||||||
@ -189,29 +189,15 @@ class SessionStartOperator(bpy.types.Operator):
|
|||||||
|
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
|
|
||||||
bpy_protocol = DataTranslationProtocol()
|
bpy_protocol = io_bpy.get_data_translation_protocol()
|
||||||
supported_bl_types = []
|
|
||||||
|
|
||||||
# init the factory with supported types
|
# init the factory with supported types
|
||||||
for type in bl_types.types_to_register():
|
for impl in bpy_protocol.implementations.values():
|
||||||
type_module = getattr(bl_types, type)
|
if impl.__name__ not in settings.supported_datablocks:
|
||||||
name = [e.capitalize() for e in type.split('_')[1:]]
|
logging.info(f"{impl.__name__} not found, \
|
||||||
type_impl_name = 'Bl'+''.join(name)
|
|
||||||
type_module_class = getattr(type_module, type_impl_name)
|
|
||||||
|
|
||||||
supported_bl_types.append(type_module_class.bl_id)
|
|
||||||
|
|
||||||
if type_impl_name not in settings.supported_datablocks:
|
|
||||||
logging.info(f"{type_impl_name} not found, \
|
|
||||||
regenerate type settings...")
|
regenerate type settings...")
|
||||||
settings.generate_supported_types()
|
settings.generate_supported_types()
|
||||||
|
|
||||||
type_local_config = settings.supported_datablocks[type_impl_name]
|
|
||||||
|
|
||||||
bpy_protocol.register_type(
|
|
||||||
type_module_class.bl_class,
|
|
||||||
type_module_class)
|
|
||||||
|
|
||||||
if bpy.app.version[1] >= 91:
|
if bpy.app.version[1] >= 91:
|
||||||
python_binary_path = sys.executable
|
python_binary_path = sys.executable
|
||||||
else:
|
else:
|
||||||
@ -658,7 +644,7 @@ class ApplyArmatureOperator(bpy.types.Operator):
|
|||||||
|
|
||||||
if event.type == 'TIMER':
|
if event.type == 'TIMER':
|
||||||
if session and session.state == STATE_ACTIVE:
|
if session and session.state == STATE_ACTIVE:
|
||||||
nodes = session.list(filter=bl_types.bl_armature.BlArmature)
|
nodes = session.list(filter=io_bpy.bl_armature.BlArmature)
|
||||||
|
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
node_ref = session.repository.get_node(node)
|
node_ref = session.repository.get_node(node)
|
||||||
@ -857,8 +843,8 @@ class SessionLoadSaveOperator(bpy.types.Operator, ImportHelper):
|
|||||||
|
|
||||||
# init the factory with supported types
|
# init the factory with supported types
|
||||||
bpy_protocol = DataTranslationProtocol()
|
bpy_protocol = DataTranslationProtocol()
|
||||||
for type in bl_types.types_to_register():
|
for type in io_bpy.types_to_register():
|
||||||
type_module = getattr(bl_types, type)
|
type_module = getattr(io_bpy, type)
|
||||||
name = [e.capitalize() for e in type.split('_')[1:]]
|
name = [e.capitalize() for e in type.split('_')[1:]]
|
||||||
type_impl_name = 'Bl'+''.join(name)
|
type_impl_name = 'Bl'+''.join(name)
|
||||||
type_module_class = getattr(type_module, type_impl_name)
|
type_module_class = getattr(type_module, type_impl_name)
|
||||||
@ -928,7 +914,7 @@ classes = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
def update_external_dependencies():
|
def update_external_dependencies():
|
||||||
nodes_ids = session.list(filter=bl_types.bl_file.BlFile)
|
nodes_ids = session.list(filter=io_bpy.bl_file.BlFile)
|
||||||
for node_id in nodes_ids:
|
for node_id in nodes_ids:
|
||||||
node = session.repository.get_node(node_id)
|
node = session.repository.get_node(node_id)
|
||||||
if node and node.owner in [session.id, RP_COMMON] \
|
if node and node.owner in [session.id, RP_COMMON] \
|
||||||
|
@ -24,7 +24,7 @@ import os
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from . import bl_types, environment, addon_updater_ops, presence, ui
|
from . import io_bpy, environment, addon_updater_ops, presence, ui
|
||||||
from .utils import get_preferences, get_expanded_icon
|
from .utils import get_preferences, get_expanded_icon
|
||||||
from replication.constants import RP_COMMON
|
from replication.constants import RP_COMMON
|
||||||
from replication.interface import session
|
from replication.interface import session
|
||||||
@ -407,18 +407,17 @@ class SessionPrefs(bpy.types.AddonPreferences):
|
|||||||
def generate_supported_types(self):
|
def generate_supported_types(self):
|
||||||
self.supported_datablocks.clear()
|
self.supported_datablocks.clear()
|
||||||
|
|
||||||
for type in bl_types.types_to_register():
|
bpy_protocol = io_bpy.get_data_translation_protocol()
|
||||||
|
|
||||||
|
# init the factory with supported types
|
||||||
|
for impl in bpy_protocol.implementations.values():
|
||||||
new_db = self.supported_datablocks.add()
|
new_db = self.supported_datablocks.add()
|
||||||
|
|
||||||
type_module = getattr(bl_types, type)
|
new_db.name = impl.__name__
|
||||||
name = [e.capitalize() for e in type.split('_')[1:]]
|
new_db.type_name = impl.__name__
|
||||||
type_impl_name = 'Bl'+''.join(name)
|
|
||||||
type_module_class = getattr(type_module, type_impl_name)
|
|
||||||
new_db.name = type_impl_name
|
|
||||||
new_db.type_name = type_impl_name
|
|
||||||
new_db.use_as_filter = True
|
new_db.use_as_filter = True
|
||||||
new_db.icon = type_module_class.bl_icon
|
new_db.icon = impl.bl_icon
|
||||||
new_db.bl_name = type_module_class.bl_id
|
new_db.bl_name = impl.bl_id
|
||||||
|
|
||||||
|
|
||||||
def client_list_callback(scene, context):
|
def client_list_callback(scene, context):
|
||||||
@ -537,7 +536,7 @@ def register():
|
|||||||
|
|
||||||
prefs = bpy.context.preferences.addons[__package__].preferences
|
prefs = bpy.context.preferences.addons[__package__].preferences
|
||||||
if len(prefs.supported_datablocks) == 0:
|
if len(prefs.supported_datablocks) == 0:
|
||||||
logging.debug('Generating bl_types preferences')
|
logging.debug('Generating io_bpy preferences')
|
||||||
prefs.generate_supported_types()
|
prefs.generate_supported_types()
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_action import BlAction
|
from multi_user.io_bpy.bl_action import BlAction
|
||||||
|
|
||||||
INTERPOLATION = ['CONSTANT', 'LINEAR', 'BEZIER', 'SINE', 'QUAD', 'CUBIC', 'QUART', 'QUINT', 'EXPO', 'CIRC', 'BACK', 'BOUNCE', 'ELASTIC']
|
INTERPOLATION = ['CONSTANT', 'LINEAR', 'BEZIER', 'SINE', 'QUAD', 'CUBIC', 'QUART', 'QUINT', 'EXPO', 'CIRC', 'BACK', 'BOUNCE', 'ELASTIC']
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_armature import BlArmature
|
from multi_user.io_bpy.bl_armature import BlArmature
|
||||||
|
|
||||||
def test_armature(clear_blend):
|
def test_armature(clear_blend):
|
||||||
bpy.ops.object.armature_add()
|
bpy.ops.object.armature_add()
|
||||||
|
@ -4,7 +4,7 @@ import pytest
|
|||||||
from deepdiff import DeepDiff
|
from deepdiff import DeepDiff
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from multi_user.bl_types.bl_camera import BlCamera
|
from multi_user.io_bpy.bl_camera import BlCamera
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('camera_type', ['PANO','PERSP','ORTHO'])
|
@pytest.mark.parametrize('camera_type', ['PANO','PERSP','ORTHO'])
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_collection import BlCollection
|
from multi_user.io_bpy.bl_collection import BlCollection
|
||||||
|
|
||||||
def test_collection(clear_blend):
|
def test_collection(clear_blend):
|
||||||
# Generate a collection with childrens and a cube
|
# Generate a collection with childrens and a cube
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_curve import BlCurve
|
from multi_user.io_bpy.bl_curve import BlCurve
|
||||||
|
|
||||||
@pytest.mark.parametrize('curve_type', ['TEXT','BEZIER'])
|
@pytest.mark.parametrize('curve_type', ['TEXT','BEZIER'])
|
||||||
def test_curve(clear_blend, curve_type):
|
def test_curve(clear_blend, curve_type):
|
||||||
|
@ -4,7 +4,7 @@ import pytest
|
|||||||
from deepdiff import DeepDiff
|
from deepdiff import DeepDiff
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from multi_user.bl_types.bl_gpencil import BlGpencil
|
from multi_user.io_bpy.bl_gpencil import BlGpencil
|
||||||
|
|
||||||
|
|
||||||
def test_gpencil(clear_blend):
|
def test_gpencil(clear_blend):
|
||||||
|
@ -4,7 +4,7 @@ import pytest
|
|||||||
from deepdiff import DeepDiff
|
from deepdiff import DeepDiff
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from multi_user.bl_types.bl_lattice import BlLattice
|
from multi_user.io_bpy.bl_lattice import BlLattice
|
||||||
|
|
||||||
|
|
||||||
def test_lattice(clear_blend):
|
def test_lattice(clear_blend):
|
||||||
|
@ -4,7 +4,7 @@ import pytest
|
|||||||
from deepdiff import DeepDiff
|
from deepdiff import DeepDiff
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from multi_user.bl_types.bl_lightprobe import BlLightprobe
|
from multi_user.io_bpy.bl_lightprobe import BlLightprobe
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(bpy.app.version[1] < 83, reason="requires blender 2.83 or higher")
|
@pytest.mark.skipif(bpy.app.version[1] < 83, reason="requires blender 2.83 or higher")
|
||||||
|
@ -4,7 +4,7 @@ import pytest
|
|||||||
from deepdiff import DeepDiff
|
from deepdiff import DeepDiff
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from multi_user.bl_types.bl_light import BlLight
|
from multi_user.io_bpy.bl_light import BlLight
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('light_type', ['SPOT','SUN','POINT','AREA'])
|
@pytest.mark.parametrize('light_type', ['SPOT','SUN','POINT','AREA'])
|
||||||
|
@ -4,7 +4,7 @@ import pytest
|
|||||||
from deepdiff import DeepDiff
|
from deepdiff import DeepDiff
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from multi_user.bl_types.bl_material import BlMaterial
|
from multi_user.io_bpy.bl_material import BlMaterial
|
||||||
|
|
||||||
|
|
||||||
def test_material_nodes(clear_blend):
|
def test_material_nodes(clear_blend):
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_mesh import BlMesh
|
from multi_user.io_bpy.bl_mesh import BlMesh
|
||||||
|
|
||||||
@pytest.mark.parametrize('mesh_type', ['EMPTY','FILLED'])
|
@pytest.mark.parametrize('mesh_type', ['EMPTY','FILLED'])
|
||||||
def test_mesh(clear_blend, mesh_type):
|
def test_mesh(clear_blend, mesh_type):
|
||||||
|
@ -4,7 +4,7 @@ import pytest
|
|||||||
from deepdiff import DeepDiff
|
from deepdiff import DeepDiff
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from multi_user.bl_types.bl_metaball import BlMetaball
|
from multi_user.io_bpy.bl_metaball import BlMetaball
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('metaballs_type', ['PLANE','CAPSULE','BALL','ELLIPSOID','CUBE'])
|
@pytest.mark.parametrize('metaballs_type', ['PLANE','CAPSULE','BALL','ELLIPSOID','CUBE'])
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_object import BlObject
|
from multi_user.io_bpy.bl_object import BlObject
|
||||||
|
|
||||||
# Removed 'BUILD', 'SOFT_BODY' modifier because the seed doesn't seems to be
|
# Removed 'BUILD', 'SOFT_BODY' modifier because the seed doesn't seems to be
|
||||||
# correctly initialized (#TODO: report the bug)
|
# correctly initialized (#TODO: report the bug)
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_scene import BlScene
|
from multi_user.io_bpy.bl_scene import BlScene
|
||||||
from multi_user.utils import get_preferences
|
from multi_user.utils import get_preferences
|
||||||
|
|
||||||
def test_scene(clear_blend):
|
def test_scene(clear_blend):
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_speaker import BlSpeaker
|
from multi_user.io_bpy.bl_speaker import BlSpeaker
|
||||||
|
|
||||||
def test_speaker(clear_blend):
|
def test_speaker(clear_blend):
|
||||||
bpy.ops.object.speaker_add()
|
bpy.ops.object.speaker_add()
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_texture import BlTexture
|
from multi_user.io_bpy.bl_texture import BlTexture
|
||||||
|
|
||||||
TEXTURE_TYPES = ['NONE', 'BLEND', 'CLOUDS', 'DISTORTED_NOISE', 'IMAGE', 'MAGIC', 'MARBLE', 'MUSGRAVE', 'NOISE', 'STUCCI', 'VORONOI', 'WOOD']
|
TEXTURE_TYPES = ['NONE', 'BLEND', 'CLOUDS', 'DISTORTED_NOISE', 'IMAGE', 'MAGIC', 'MARBLE', 'MUSGRAVE', 'NOISE', 'STUCCI', 'VORONOI', 'WOOD']
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_volume import BlVolume
|
from multi_user.io_bpy.bl_volume import BlVolume
|
||||||
|
|
||||||
def test_volume(clear_blend):
|
def test_volume(clear_blend):
|
||||||
datablock = bpy.data.volumes.new("Test")
|
datablock = bpy.data.volumes.new("Test")
|
||||||
|
@ -5,7 +5,7 @@ from deepdiff import DeepDiff
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from multi_user.bl_types.bl_world import BlWorld
|
from multi_user.io_bpy.bl_world import BlWorld
|
||||||
|
|
||||||
def test_world(clear_blend):
|
def test_world(clear_blend):
|
||||||
datablock = bpy.data.worlds.new('test')
|
datablock = bpy.data.worlds.new('test')
|
||||||
|
Reference in New Issue
Block a user