2020-03-20 14:56:50 +01:00
|
|
|
# ##### 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 #####
|
|
|
|
|
|
|
|
|
2020-10-01 22:51:48 +02:00
|
|
|
import logging
|
|
|
|
from collections.abc import Iterable
|
|
|
|
|
2019-08-26 17:27:12 +02:00
|
|
|
import bpy
|
|
|
|
import mathutils
|
2020-11-04 22:41:24 +01:00
|
|
|
from replication.constants import DIFF_BINARY, DIFF_JSON, UP
|
2021-03-24 16:08:12 +01:00
|
|
|
from replication.protocol import ReplicatedDatablock
|
2021-03-26 12:30:15 +01:00
|
|
|
from replication.objects import Node
|
|
|
|
|
|
|
|
from uuid import uuid4
|
2019-08-26 17:27:12 +02:00
|
|
|
|
|
|
|
from .. import utils
|
2020-10-01 22:51:48 +02:00
|
|
|
from .dump_anything import Dumper, Loader
|
2020-03-30 14:31:35 +02:00
|
|
|
|
|
|
|
|
2020-10-01 22:51:48 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2021-03-26 12:30:15 +01:00
|
|
|
def resolve_datablock_from_root(node:Node, root)->object:
|
|
|
|
datablock_ref = utils.find_from_attr('uuid', node.uuid, root)
|
2019-09-18 17:54:02 +02:00
|
|
|
|
2021-03-26 12:30:15 +01:00
|
|
|
if not datablock_ref:
|
|
|
|
try:
|
|
|
|
datablock_ref = root[node.data['name']]
|
|
|
|
except Exception:
|
|
|
|
pass
|
2019-11-06 14:30:16 +01:00
|
|
|
|
2021-03-26 12:30:15 +01:00
|
|
|
return datablock_ref
|
2020-03-13 17:13:39 +01:00
|
|
|
|
2021-03-26 12:30:15 +01:00
|
|
|
def stamp_uuid(datablock):
|
|
|
|
if not datablock.uuid:
|
|
|
|
datablock.uuid = str(uuid4())
|