refactor: io_bpy architecture revamp
This commit is contained in:
59
multi_user/io_bpy/bl_datablock.py
Normal file
59
multi_user/io_bpy/bl_datablock.py
Normal file
@ -0,0 +1,59 @@
|
||||
# ##### BEGIN GPL LICENSE BLOCK #####
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
|
||||
import logging
|
||||
from collections.abc import Iterable
|
||||
|
||||
import bpy
|
||||
import mathutils
|
||||
from replication.constants import DIFF_BINARY, DIFF_JSON, UP
|
||||
from replication.protocol import ReplicatedDatablock
|
||||
from replication.objects import Node
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
from .. import utils
|
||||
from .dump_anything import Dumper, Loader
|
||||
|
||||
|
||||
def get_datablock_from_uuid(uuid, default, ignore=[]):
|
||||
if not uuid:
|
||||
return default
|
||||
for category in dir(bpy.data):
|
||||
root = getattr(bpy.data, category)
|
||||
if isinstance(root, Iterable) and category not in ignore:
|
||||
for item in root:
|
||||
if getattr(item, 'uuid', None) == uuid:
|
||||
return item
|
||||
return default
|
||||
|
||||
|
||||
def resolve_datablock_from_root(node:Node, root)->object:
|
||||
datablock_ref = utils.find_from_attr('uuid', node.uuid, root)
|
||||
|
||||
if not datablock_ref:
|
||||
try:
|
||||
datablock_ref = root[node.data['name']]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return datablock_ref
|
||||
|
||||
def stamp_uuid(datablock):
|
||||
if not datablock.uuid:
|
||||
datablock.uuid = str(uuid4())
|
Reference in New Issue
Block a user