refactor: imports
This commit is contained in:
parent
fef088e39b
commit
776664149e
@ -24,7 +24,7 @@ from enum import Enum
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import (
|
||||
Dumper, Loader, np_dump_collection, np_load_collection)
|
||||
Dumper, Loader, np_dump_collection, np_load_collection, remove_items_from_dict)
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
|
||||
@ -41,8 +41,6 @@ KEYFRAME = [
|
||||
'interpolation',
|
||||
]
|
||||
|
||||
# TODO: Automatic enum and numpy dump and loading
|
||||
|
||||
|
||||
def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy:bool =True) -> dict:
|
||||
""" Dump a sigle curve to a dict
|
||||
@ -65,7 +63,7 @@ def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy:bool =True) -> dict:
|
||||
fcurve_data['keyframe_points'] = np_dump_collection(points, KEYFRAME)
|
||||
|
||||
else: # Legacy method
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
fcurve_data["keyframe_points"] = []
|
||||
|
||||
for k in fcurve.keyframe_points:
|
||||
@ -109,12 +107,13 @@ def load_fcurve(fcurve_data, fcurve):
|
||||
)
|
||||
|
||||
keycache = copy.copy(dumped_keyframe_point)
|
||||
keycache = utils.dump_anything.remove_items_from_dict(
|
||||
keycache = remove_items_from_dict(
|
||||
keycache,
|
||||
["co", "handle_left", "handle_right", 'type']
|
||||
)
|
||||
|
||||
utils.dump_anything.load(new_kf, keycache)
|
||||
loader = Loader()
|
||||
loader.load(new_kf, keycache)
|
||||
|
||||
new_kf.type = dumped_keyframe_point['type']
|
||||
new_kf.handle_left = [
|
||||
@ -157,7 +156,7 @@ class BlAction(BlDatablock):
|
||||
|
||||
def _dump(self, pointer=None):
|
||||
assert(pointer)
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.exclude_filter = [
|
||||
'name_full',
|
||||
'original',
|
||||
|
@ -19,8 +19,9 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from .. import presence, operators
|
||||
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .. import presence, operators, utils
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
|
||||
@ -97,7 +98,8 @@ class BlArmature(BlDatablock):
|
||||
[bone]['parent']]
|
||||
new_bone.use_connect = bone_data['use_connect']
|
||||
|
||||
utils.dump_anything.load(new_bone, bone_data)
|
||||
loader = Loader()
|
||||
loader.load(new_bone, bone_data)
|
||||
|
||||
if bpy.context.mode != 'OBJECT':
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
@ -110,7 +112,7 @@ class BlArmature(BlDatablock):
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 4
|
||||
dumper.include_filter = [
|
||||
'bones',
|
||||
|
@ -19,7 +19,7 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
|
||||
@ -36,20 +36,21 @@ class BlCamera(BlDatablock):
|
||||
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
utils.dump_anything.load(target, data)
|
||||
loader = Loader()
|
||||
loader.load(target, data)
|
||||
|
||||
dof_settings = data.get('dof')
|
||||
|
||||
# DOF settings
|
||||
if dof_settings:
|
||||
utils.dump_anything.load(target.dof, dof_settings)
|
||||
loader.load(target.dof, dof_settings)
|
||||
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
|
||||
# TODO: background image support
|
||||
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 2
|
||||
dumper.include_filter = [
|
||||
"name",
|
||||
|
@ -48,7 +48,6 @@ class BlCollection(BlDatablock):
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
# Load other meshes metadata
|
||||
# dump_anything.load(target, data)
|
||||
target.name = data["name"]
|
||||
|
||||
# link objects
|
||||
|
@ -20,9 +20,9 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from ..libs.replication.replication.data import ReplicatedDatablock
|
||||
from ..libs.replication.replication.constants import (UP, DIFF_BINARY)
|
||||
from ..libs import dump_anything
|
||||
|
||||
|
||||
def has_action(target):
|
||||
@ -42,7 +42,7 @@ def has_driver(target):
|
||||
|
||||
|
||||
def dump_driver(driver):
|
||||
dumper = dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 6
|
||||
data = dumper.dump(driver)
|
||||
|
||||
@ -50,6 +50,7 @@ def dump_driver(driver):
|
||||
|
||||
|
||||
def load_driver(target_datablock, src_driver):
|
||||
loader = Loader()
|
||||
drivers = target_datablock.animation_data.drivers
|
||||
src_driver_data = src_driver['driver']
|
||||
new_driver = drivers.new(src_driver['data_path'])
|
||||
@ -57,7 +58,7 @@ def load_driver(target_datablock, src_driver):
|
||||
# Settings
|
||||
new_driver.driver.type = src_driver_data['type']
|
||||
new_driver.driver.expression = src_driver_data['expression']
|
||||
dump_anything.load(new_driver, src_driver)
|
||||
loader.load(new_driver, src_driver)
|
||||
|
||||
# Variables
|
||||
for src_variable in src_driver_data['variables']:
|
||||
@ -70,7 +71,7 @@ def load_driver(target_datablock, src_driver):
|
||||
src_target_data = src_var_data['targets'][src_target]
|
||||
new_var.targets[src_target].id = utils.resolve_from_id(
|
||||
src_target_data['id'], src_target_data['id_type'])
|
||||
dump_anything.load(
|
||||
loader.load(
|
||||
new_var.targets[src_target], src_target_data)
|
||||
|
||||
# Fcurve
|
||||
@ -82,8 +83,7 @@ def load_driver(target_datablock, src_driver):
|
||||
|
||||
for index, src_point in enumerate(src_driver['keyframe_points']):
|
||||
new_point = new_fcurve[index]
|
||||
dump_anything.load(
|
||||
new_point, src_driver['keyframe_points'][src_point])
|
||||
loader.load(new_point, src_driver['keyframe_points'][src_point])
|
||||
|
||||
|
||||
class BlDatablock(ReplicatedDatablock):
|
||||
@ -127,10 +127,11 @@ class BlDatablock(ReplicatedDatablock):
|
||||
self.pointer = datablock_ref
|
||||
|
||||
def _dump(self, pointer=None):
|
||||
dumper = Dumper()
|
||||
data = {}
|
||||
# Dump animation data
|
||||
if has_action(pointer):
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.include_filter = ['action']
|
||||
data['animation_data'] = dumper.dump(pointer.animation_data)
|
||||
|
||||
@ -143,7 +144,7 @@ class BlDatablock(ReplicatedDatablock):
|
||||
data.update(dumped_drivers)
|
||||
|
||||
if self.is_library:
|
||||
data.update(dump_anything.dump(pointer))
|
||||
data.update(dumper.dump(pointer))
|
||||
else:
|
||||
data.update(self._dump_implementation(data, pointer=pointer))
|
||||
|
||||
|
@ -21,6 +21,7 @@ import mathutils
|
||||
import os
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
def dump_image(image):
|
||||
@ -83,7 +84,7 @@ class BlImage(BlDatablock):
|
||||
assert(pointer)
|
||||
data = {}
|
||||
data['pixels'] = dump_image(pointer)
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 2
|
||||
dumper.include_filter = [
|
||||
"name",
|
||||
|
@ -19,7 +19,7 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from ..libs import dump_anything
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@ class BlLibrary(BlDatablock):
|
||||
|
||||
def dump(self, pointer=None):
|
||||
assert(pointer)
|
||||
return dump_anything.dump(pointer, 1)
|
||||
dumper = Dumper()
|
||||
return dumper.dump(pointer, 1)
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
|
||||
@ -35,11 +35,12 @@ class BlLight(BlDatablock):
|
||||
return bpy.data.lights.new(data["name"], data["type"])
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
utils.dump_anything.load(target, data)
|
||||
loader = Loader()
|
||||
loader.load(target, data)
|
||||
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 3
|
||||
dumper.include_filter = [
|
||||
"name",
|
||||
|
@ -20,7 +20,7 @@ import bpy
|
||||
import mathutils
|
||||
import logging
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -42,14 +42,15 @@ class BlLightprobe(BlDatablock):
|
||||
logger.warning("Lightprobe replication only supported since 2.83. See https://developer.blender.org/D6396")
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
utils.dump_anything.load(target, data)
|
||||
loader = Loader()
|
||||
loader.load(target, data)
|
||||
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
if bpy.app.version[1] < 83:
|
||||
logger.warning("Lightprobe replication only supported since 2.83. See https://developer.blender.org/D6396")
|
||||
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 1
|
||||
dumper.include_filter = [
|
||||
"name",
|
||||
|
@ -21,7 +21,7 @@ import mathutils
|
||||
import logging
|
||||
|
||||
from .. import utils
|
||||
from ..libs import dump_anything
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -34,9 +34,10 @@ def load_node(node_data, node_tree):
|
||||
:arg node_tree: target node_tree
|
||||
:type node_tree: bpy.types.NodeTree
|
||||
"""
|
||||
loader = Loader()
|
||||
target_node = node_tree.nodes.new(type=node_data["bl_idname"])
|
||||
|
||||
dump_anything.load(target_node, node_data)
|
||||
loader.load(target_node, node_data)
|
||||
|
||||
|
||||
|
||||
@ -93,7 +94,7 @@ def dump_node(node):
|
||||
:retrun: dict
|
||||
"""
|
||||
|
||||
node_dumper = dump_anything.Dumper()
|
||||
node_dumper = Dumper()
|
||||
node_dumper.depth = 1
|
||||
node_dumper.exclude_filter = [
|
||||
"dimensions",
|
||||
@ -125,7 +126,7 @@ def dump_node(node):
|
||||
dumped_node['inputs'] = {}
|
||||
|
||||
for i in node.inputs:
|
||||
input_dumper = dump_anything.Dumper()
|
||||
input_dumper = Dumper()
|
||||
input_dumper.depth = 2
|
||||
input_dumper.include_filter = ["default_value"]
|
||||
|
||||
@ -133,7 +134,7 @@ def dump_node(node):
|
||||
dumped_node['inputs'][i.name] = input_dumper.dump(
|
||||
i)
|
||||
if hasattr(node, 'color_ramp'):
|
||||
ramp_dumper = dump_anything.Dumper()
|
||||
ramp_dumper = Dumper()
|
||||
ramp_dumper.depth = 4
|
||||
ramp_dumper.include_filter = [
|
||||
'elements',
|
||||
@ -143,7 +144,7 @@ def dump_node(node):
|
||||
]
|
||||
dumped_node['color_ramp'] = ramp_dumper.dump(node.color_ramp)
|
||||
if hasattr(node, 'mapping'):
|
||||
curve_dumper = dump_anything.Dumper()
|
||||
curve_dumper = Dumper()
|
||||
curve_dumper.depth = 5
|
||||
curve_dumper.include_filter = [
|
||||
'curves',
|
||||
@ -167,12 +168,13 @@ class BlMaterial(BlDatablock):
|
||||
return bpy.data.materials.new(data["name"])
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
loader = Loader()
|
||||
target.name = data['name']
|
||||
if data['is_grease_pencil']:
|
||||
if not target.is_grease_pencil:
|
||||
bpy.data.materials.create_gpencil_data(target)
|
||||
|
||||
dump_anything.load(
|
||||
loader.load(
|
||||
target.grease_pencil, data['grease_pencil'])
|
||||
|
||||
|
||||
@ -182,7 +184,7 @@ class BlMaterial(BlDatablock):
|
||||
|
||||
target.node_tree.nodes.clear()
|
||||
|
||||
dump_anything.load(target,data)
|
||||
loader.load(target,data)
|
||||
|
||||
# Load nodes
|
||||
for node in data["node_tree"]["nodes"]:
|
||||
@ -195,7 +197,7 @@ class BlMaterial(BlDatablock):
|
||||
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
mat_dumper = dump_anything.Dumper()
|
||||
mat_dumper = Dumper()
|
||||
mat_dumper.depth = 2
|
||||
mat_dumper.exclude_filter = [
|
||||
"is_embed_data",
|
||||
@ -223,7 +225,7 @@ class BlMaterial(BlDatablock):
|
||||
|
||||
data["node_tree"]["links"] = dump_links(pointer.node_tree.links)
|
||||
elif pointer.is_grease_pencil:
|
||||
gp_mat_dumper = dump_anything.Dumper()
|
||||
gp_mat_dumper = Dumper()
|
||||
gp_mat_dumper.depth = 3
|
||||
|
||||
gp_mat_dumper.include_filter = [
|
||||
|
@ -19,7 +19,6 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import (
|
||||
Dumper, Loader, np_dump_collection_primitive, np_load_collection_primitives,
|
||||
np_dump_collection, np_load_collection)
|
||||
@ -75,7 +74,8 @@ class BlMetaball(BlDatablock):
|
||||
return bpy.data.metaballs.new(data["name"])
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
utils.dump_anything.load(target, data)
|
||||
loader = Loader()
|
||||
loader.load(target, data)
|
||||
|
||||
target.elements.clear()
|
||||
|
||||
@ -86,7 +86,7 @@ class BlMetaball(BlDatablock):
|
||||
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 1
|
||||
dumper.exclude_filter = [
|
||||
"is_editmode",
|
||||
|
@ -20,7 +20,7 @@ import bpy
|
||||
import mathutils
|
||||
import logging
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -28,8 +28,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def load_pose(target_bone, data):
|
||||
target_bone.rotation_mode = data['rotation_mode']
|
||||
|
||||
utils.dump_anything.load(target_bone, data)
|
||||
loader = Loader()
|
||||
loader.load(target_bone, data)
|
||||
|
||||
|
||||
class BlObject(BlDatablock):
|
||||
@ -89,7 +89,8 @@ class BlObject(BlDatablock):
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
# Load transformation data
|
||||
utils.dump_anything.load(target, data)
|
||||
loader = Loader()
|
||||
loader.load(target, data)
|
||||
|
||||
# Pose
|
||||
if 'pose' in data:
|
||||
@ -103,7 +104,7 @@ class BlObject(BlDatablock):
|
||||
if not bg_target:
|
||||
bg_target = target.pose.bone_groups.new(name=bg_name)
|
||||
|
||||
utils.dump_anything.load(bg_target, bg_data)
|
||||
loader.load(bg_target, bg_data)
|
||||
# target.pose.bone_groups.get
|
||||
|
||||
# Bones
|
||||
@ -112,7 +113,7 @@ class BlObject(BlDatablock):
|
||||
bone_data = data['pose']['bones'].get(bone)
|
||||
|
||||
if 'constraints' in bone_data.keys():
|
||||
utils.dump_anything.load(target_bone, bone_data['constraints'])
|
||||
loader.load(target_bone, bone_data['constraints'])
|
||||
|
||||
|
||||
load_pose(target_bone, bone_data)
|
||||
@ -140,7 +141,7 @@ class BlObject(BlDatablock):
|
||||
key_data = data['shape_keys']['key_blocks'][key_block]
|
||||
target.shape_key_add(name=key_block)
|
||||
|
||||
utils.dump_anything.load(
|
||||
loader.load(
|
||||
target.data.shape_keys.key_blocks[key_block], key_data)
|
||||
for vert in key_data['data']:
|
||||
target.data.shape_keys.key_blocks[key_block].data[vert].co = key_data['data'][vert]['co']
|
||||
@ -153,7 +154,7 @@ class BlObject(BlDatablock):
|
||||
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 1
|
||||
dumper.include_filter = [
|
||||
"name",
|
||||
@ -263,7 +264,7 @@ class BlObject(BlDatablock):
|
||||
# SHAPE KEYS
|
||||
object_data = pointer.data
|
||||
if hasattr(object_data, 'shape_keys') and object_data.shape_keys:
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 2
|
||||
dumper.include_filter = [
|
||||
'reference_key',
|
||||
|
@ -19,7 +19,7 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
class BlScene(BlDatablock):
|
||||
@ -38,7 +38,8 @@ class BlScene(BlDatablock):
|
||||
def _load_implementation(self, data, target):
|
||||
target = self.pointer
|
||||
# Load other meshes metadata
|
||||
utils.dump_anything.load(target, data)
|
||||
loader = Loader()
|
||||
loader.load(target, data)
|
||||
|
||||
# Load master collection
|
||||
for object in data["collection"]["objects"]:
|
||||
@ -71,7 +72,7 @@ class BlScene(BlDatablock):
|
||||
assert(pointer)
|
||||
data = {}
|
||||
|
||||
scene_dumper = utils.dump_anything.Dumper()
|
||||
scene_dumper = Dumper()
|
||||
scene_dumper.depth = 1
|
||||
scene_dumper.include_filter = [
|
||||
'name',
|
||||
|
@ -19,7 +19,7 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
|
||||
@ -32,7 +32,8 @@ class BlSpeaker(BlDatablock):
|
||||
bl_icon = 'SPEAKER'
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
utils.dump_anything.load(target, data)
|
||||
loader = Loader()
|
||||
loader.load(target, data)
|
||||
|
||||
def _construct(self, data):
|
||||
return bpy.data.speakers.new(data["name"])
|
||||
@ -40,7 +41,7 @@ class BlSpeaker(BlDatablock):
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper = Dumper()
|
||||
dumper.depth = 1
|
||||
dumper.include_filter = [
|
||||
"muted",
|
||||
|
@ -19,9 +19,9 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
from .bl_material import load_links, load_node,dump_node, dump_links
|
||||
from .bl_material import load_links, load_node, dump_node, dump_links
|
||||
|
||||
|
||||
class BlWorld(BlDatablock):
|
||||
@ -54,7 +54,7 @@ class BlWorld(BlDatablock):
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
|
||||
world_dumper = utils.dump_anything.Dumper()
|
||||
world_dumper = Dumper()
|
||||
world_dumper.depth = 2
|
||||
world_dumper.exclude_filter = [
|
||||
"preview",
|
||||
|
@ -135,10 +135,8 @@ def get_bb_coords_from_obj(object, parent=None):
|
||||
def get_view_matrix():
|
||||
area, region, rv3d = view3d_find()
|
||||
|
||||
if area and region and rv3d:
|
||||
matrix_dumper = utils.dump_anything.Dumper()
|
||||
|
||||
return matrix_dumper.dump(rv3d.view_matrix)
|
||||
if area and region and rv3d:
|
||||
return [list(v) for v in rv3d.view_matrix]
|
||||
|
||||
def update_presence(self, context):
|
||||
global renderer
|
||||
|
@ -28,7 +28,6 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from . import environment, presence
|
||||
from .libs import dump_anything
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.WARNING)
|
||||
|
Loading…
Reference in New Issue
Block a user