@ -19,7 +19,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import mathutils
|
import mathutils
|
||||||
|
|
||||||
from ..libs.overrider import Overrider
|
|
||||||
from .. import utils
|
from .. import utils
|
||||||
from .. import presence, operators
|
from .. import presence, operators
|
||||||
from .bl_datablock import BlDatablock
|
from .bl_datablock import BlDatablock
|
||||||
|
@ -26,22 +26,6 @@ from .bl_datablock import BlDatablock
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def load_constraints(target, data):
|
|
||||||
for local_constraint in target.constraints:
|
|
||||||
if local_constraint.name not in data:
|
|
||||||
target.constraints.remove(local_constraint)
|
|
||||||
|
|
||||||
for constraint in data:
|
|
||||||
target_constraint = target.constraints.get(constraint)
|
|
||||||
|
|
||||||
if not target_constraint:
|
|
||||||
target_constraint = target.constraints.new(
|
|
||||||
data[constraint]['type'])
|
|
||||||
|
|
||||||
utils.dump_anything.load(
|
|
||||||
target_constraint, data[constraint])
|
|
||||||
|
|
||||||
|
|
||||||
def load_pose(target_bone, data):
|
def load_pose(target_bone, data):
|
||||||
target_bone.rotation_mode = data['rotation_mode']
|
target_bone.rotation_mode = data['rotation_mode']
|
||||||
|
|
||||||
@ -105,32 +89,7 @@ class BlObject(BlDatablock):
|
|||||||
|
|
||||||
def load_implementation(self, data, target):
|
def load_implementation(self, data, target):
|
||||||
# Load transformation data
|
# Load transformation data
|
||||||
rot_mode = 'rotation_quaternion' if data['rotation_mode'] == 'QUATERNION' else 'rotation_euler'
|
utils.dump_anything.load(target, data)
|
||||||
target.rotation_mode = data['rotation_mode']
|
|
||||||
target.location = data['location']
|
|
||||||
setattr(target, rot_mode, data[rot_mode])
|
|
||||||
target.scale = data['scale']
|
|
||||||
|
|
||||||
target.name = data["name"]
|
|
||||||
# Load modifiers
|
|
||||||
if hasattr(target, 'modifiers'):
|
|
||||||
# TODO: smarter selective update
|
|
||||||
target.modifiers.clear()
|
|
||||||
|
|
||||||
for modifier in data['modifiers']:
|
|
||||||
target_modifier = target.modifiers.get(modifier)
|
|
||||||
|
|
||||||
if not target_modifier:
|
|
||||||
target_modifier = target.modifiers.new(
|
|
||||||
data['modifiers'][modifier]['name'], data['modifiers'][modifier]['type'])
|
|
||||||
|
|
||||||
utils.dump_anything.load(
|
|
||||||
target_modifier, data['modifiers'][modifier])
|
|
||||||
|
|
||||||
# Load constraints
|
|
||||||
# Object
|
|
||||||
if hasattr(target, 'constraints') and 'constraints' in data:
|
|
||||||
load_constraints(target, data['constraints'])
|
|
||||||
|
|
||||||
# Pose
|
# Pose
|
||||||
if 'pose' in data:
|
if 'pose' in data:
|
||||||
@ -153,28 +112,14 @@ class BlObject(BlDatablock):
|
|||||||
bone_data = data['pose']['bones'].get(bone)
|
bone_data = data['pose']['bones'].get(bone)
|
||||||
|
|
||||||
if 'constraints' in bone_data.keys():
|
if 'constraints' in bone_data.keys():
|
||||||
load_constraints(
|
utils.dump_anything.load(target_bone, bone_data['constraints'])
|
||||||
target_bone, bone_data['constraints'])
|
|
||||||
|
|
||||||
load_pose(target_bone, bone_data)
|
load_pose(target_bone, bone_data)
|
||||||
|
|
||||||
if 'bone_index' in bone_data.keys():
|
if 'bone_index' in bone_data.keys():
|
||||||
target_bone.bone_group = target.pose.bone_group[bone_data['bone_group_index']]
|
target_bone.bone_group = target.pose.bone_group[bone_data['bone_group_index']]
|
||||||
|
|
||||||
# Load relations
|
|
||||||
if 'children' in data.keys():
|
|
||||||
for child in data['children']:
|
|
||||||
bpy.data.objects[child].parent = self.pointer
|
|
||||||
|
|
||||||
# Load empty representation
|
|
||||||
target.empty_display_size = data['empty_display_size']
|
|
||||||
target.empty_display_type = data['empty_display_type']
|
|
||||||
|
|
||||||
# Instancing
|
|
||||||
target.instance_type = data['instance_type']
|
|
||||||
if data['instance_type'] == 'COLLECTION':
|
|
||||||
target.instance_collection = bpy.data.collections[data['instance_collection']]
|
|
||||||
|
|
||||||
# vertex groups
|
# vertex groups
|
||||||
if 'vertex_groups' in data:
|
if 'vertex_groups' in data:
|
||||||
target.vertex_groups.clear()
|
target.vertex_groups.clear()
|
||||||
@ -238,7 +183,6 @@ class BlObject(BlDatablock):
|
|||||||
data["modifiers"] = {}
|
data["modifiers"] = {}
|
||||||
for index, modifier in enumerate(pointer.modifiers):
|
for index, modifier in enumerate(pointer.modifiers):
|
||||||
data["modifiers"][modifier.name] = dumper.dump(modifier)
|
data["modifiers"][modifier.name] = dumper.dump(modifier)
|
||||||
data["modifiers"][modifier.name]['m_index'] = index
|
|
||||||
|
|
||||||
# CONSTRAINTS
|
# CONSTRAINTS
|
||||||
# OBJECT
|
# OBJECT
|
||||||
|
@ -15,11 +15,13 @@
|
|||||||
#
|
#
|
||||||
# ##### END GPL LICENSE BLOCK #####
|
# ##### END GPL LICENSE BLOCK #####
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import bpy.types as T
|
import bpy.types as T
|
||||||
import mathutils
|
import mathutils
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def remove_items_from_dict(d, keys, recursive=False):
|
def remove_items_from_dict(d, keys, recursive=False):
|
||||||
copy = dict(d)
|
copy = dict(d)
|
||||||
@ -316,19 +318,29 @@ class Loader:
|
|||||||
CONSTRUCTOR_ADD = "add"
|
CONSTRUCTOR_ADD = "add"
|
||||||
|
|
||||||
constructors = {
|
constructors = {
|
||||||
T.ColorRampElement: (CONSTRUCTOR_NEW, ["position"]),
|
T.ColorRampElement: (CONSTRUCTOR_NEW, ["position"], True),
|
||||||
T.ParticleSettingsTextureSlot: (CONSTRUCTOR_ADD, [])
|
T.ParticleSettingsTextureSlot: (CONSTRUCTOR_ADD, [], False),
|
||||||
|
T.Modifier: (CONSTRUCTOR_NEW, ["name", "type"], True),
|
||||||
|
T.Constraint: (CONSTRUCTOR_NEW, ["type"], True),
|
||||||
|
# T.VertexGroup: (CONSTRUCTOR_NEW, ["name"], True),
|
||||||
}
|
}
|
||||||
element_type = element.bl_rna_property.fixed_type
|
element_type = element.bl_rna_property.fixed_type
|
||||||
|
|
||||||
constructor = constructors.get(type(element_type))
|
constructor = constructors.get(type(element_type))
|
||||||
|
|
||||||
if constructor is None: # collection type not supported
|
if constructor is None: # collection type not supported
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Try to clear existing
|
||||||
|
if constructor[2]:
|
||||||
|
getattr(element.read(), 'clear')()
|
||||||
|
|
||||||
for dumped_element in dump.values():
|
for dumped_element in dump.values():
|
||||||
try:
|
try:
|
||||||
constructor_parameters = [dumped_element[name]
|
constructor_parameters = [dumped_element[name]
|
||||||
for name in constructor[1]]
|
for name in constructor[1]]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("Collection load error, missing parameters.")
|
logger.error("Collection load error, missing parameters.")
|
||||||
continue # TODO handle error
|
continue # TODO handle error
|
||||||
new_element = getattr(element.read(), constructor[0])(
|
new_element = getattr(element.read(), constructor[0])(
|
||||||
*constructor_parameters)
|
*constructor_parameters)
|
||||||
@ -354,6 +366,8 @@ class Loader:
|
|||||||
pointer.write(bpy.data.meshes.get(dump))
|
pointer.write(bpy.data.meshes.get(dump))
|
||||||
elif isinstance(rna_property_type, T.Material):
|
elif isinstance(rna_property_type, T.Material):
|
||||||
pointer.write(bpy.data.materials.get(dump))
|
pointer.write(bpy.data.materials.get(dump))
|
||||||
|
elif isinstance(rna_property_type, T.Collection):
|
||||||
|
pointer.write(bpy.data.collections.get(dump))
|
||||||
|
|
||||||
def _load_matrix(self, matrix, dump):
|
def _load_matrix(self, matrix, dump):
|
||||||
matrix.write(mathutils.Matrix(dump))
|
matrix.write(mathutils.Matrix(dump))
|
||||||
@ -386,8 +400,8 @@ class Loader:
|
|||||||
continue # TODO error handling
|
continue # TODO error handling
|
||||||
try:
|
try:
|
||||||
self._load_any(default.extend(k), v)
|
self._load_any(default.extend(k), v)
|
||||||
except:
|
except Exception as e:
|
||||||
pass
|
logger.error(e)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def match_subset_all(self):
|
def match_subset_all(self):
|
||||||
|
Submodule multi_user/libs/replication updated: 7077c12562...42b3a31b8e
Reference in New Issue
Block a user