refactor: io_bpy architecture revamp

This commit is contained in:
Swann 2021-04-21 11:10:24 +02:00
parent 845bb11b8e
commit da349dd4a9
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB
49 changed files with 53 additions and 58 deletions

View File

@ -16,6 +16,7 @@
# ##### END GPL LICENSE BLOCK #####
import bpy
from replication.protocol import ReplicatedDatablock
__all__ = [
'bl_object',
@ -48,9 +49,14 @@ __all__ = [
# if bpy.app.version[1] >= 91:
# __all__.append('bl_volume')
from . import bl_object, bl_action, bl_scene, bl_mesh, bl_collection
from replication.protocol import DataTranslationProtocol
def types_to_register():
return __all__
def get_data_translation_protocol()-> DataTranslationProtocol:
""" 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

View File

@ -295,11 +295,12 @@ def load_vertex_groups(dumped_vertex_groups: dict, target_object: bpy.types.Obje
class BlObject(ReplicatedDatablock):
bl_id = "objects"
bl_class = bpy.types.Object
bl_check_common = False
bl_icon = 'OBJECT_DATA'
bl_reload_parent = False
is_root = False
@staticmethod
def construct(data: dict) -> bpy.types.Object:
datablock = None
@ -711,3 +712,6 @@ class BlObject(ReplicatedDatablock):
deps.extend(find_geometry_nodes_dependencies(datablock.modifiers))
return deps
_type = bpy.types.Object
_class = BlObject

@ -1 +1 @@
Subproject commit 0614a09e70cb52e57c4f3bb1b9e02876f8b6c6cd
Subproject commit adf5d8be885d383faa259e55d928e6bf7a5c2641

View File

@ -51,7 +51,7 @@ from replication.interface import session
from replication.porcelain import add, apply, commit
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 .timers import registry
@ -189,29 +189,15 @@ class SessionStartOperator(bpy.types.Operator):
handler.setFormatter(formatter)
bpy_protocol = DataTranslationProtocol()
supported_bl_types = []
bpy_protocol = io_bpy.get_data_translation_protocol()
# init the factory with supported types
for type in bl_types.types_to_register():
type_module = getattr(bl_types, type)
name = [e.capitalize() for e in type.split('_')[1:]]
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, \
for impl in bpy_protocol.implementations.values():
if impl.__name__ not in settings.supported_datablocks:
logging.info(f"{impl.__name__} not found, \
regenerate type settings...")
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:
python_binary_path = sys.executable
else:
@ -658,7 +644,7 @@ class ApplyArmatureOperator(bpy.types.Operator):
if event.type == 'TIMER':
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:
node_ref = session.repository.get_node(node)
@ -857,8 +843,8 @@ class SessionLoadSaveOperator(bpy.types.Operator, ImportHelper):
# init the factory with supported types
bpy_protocol = DataTranslationProtocol()
for type in bl_types.types_to_register():
type_module = getattr(bl_types, type)
for type in io_bpy.types_to_register():
type_module = getattr(io_bpy, type)
name = [e.capitalize() for e in type.split('_')[1:]]
type_impl_name = 'Bl'+''.join(name)
type_module_class = getattr(type_module, type_impl_name)
@ -928,7 +914,7 @@ classes = (
)
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:
node = session.repository.get_node(node_id)
if node and node.owner in [session.id, RP_COMMON] \

View File

@ -24,7 +24,7 @@ import os
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 replication.constants import RP_COMMON
from replication.interface import session
@ -407,18 +407,17 @@ class SessionPrefs(bpy.types.AddonPreferences):
def generate_supported_types(self):
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()
type_module = getattr(bl_types, type)
name = [e.capitalize() for e in type.split('_')[1:]]
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.name = impl.__name__
new_db.type_name = impl.__name__
new_db.use_as_filter = True
new_db.icon = type_module_class.bl_icon
new_db.bl_name = type_module_class.bl_id
new_db.icon = impl.bl_icon
new_db.bl_name = impl.bl_id
def client_list_callback(scene, context):
@ -537,7 +536,7 @@ def register():
prefs = bpy.context.preferences.addons[__package__].preferences
if len(prefs.supported_datablocks) == 0:
logging.debug('Generating bl_types preferences')
logging.debug('Generating io_bpy preferences')
prefs.generate_supported_types()

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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']

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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):
bpy.ops.object.armature_add()

View File

@ -4,7 +4,7 @@ import pytest
from deepdiff import DeepDiff
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'])

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
from uuid import uuid4
import bpy
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):
# Generate a collection with childrens and a cube

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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'])
def test_curve(clear_blend, curve_type):

View File

@ -4,7 +4,7 @@ import pytest
from deepdiff import DeepDiff
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):

View File

@ -4,7 +4,7 @@ import pytest
from deepdiff import DeepDiff
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):

View File

@ -4,7 +4,7 @@ import pytest
from deepdiff import DeepDiff
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")

View File

@ -4,7 +4,7 @@ import pytest
from deepdiff import DeepDiff
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'])

View File

@ -4,7 +4,7 @@ import pytest
from deepdiff import DeepDiff
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):

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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'])
def test_mesh(clear_blend, mesh_type):

View File

@ -4,7 +4,7 @@ import pytest
from deepdiff import DeepDiff
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'])

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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
# correctly initialized (#TODO: report the bug)

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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
def test_scene(clear_blend):

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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):
bpy.ops.object.speaker_add()

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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']

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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):
datablock = bpy.data.volumes.new("Test")

View File

@ -5,7 +5,7 @@ from deepdiff import DeepDiff
import bpy
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):
datablock = bpy.data.worlds.new('test')