MRO based Dumper resolution system
parent
e4ca202608
commit
94627debc6
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
|
@ -5,6 +7,8 @@ from pprint import pprint
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
format_token = "#FMT:NODE_KIT#"
|
format_token = "#FMT:NODE_KIT#"
|
||||||
|
|
||||||
|
@ -29,14 +33,16 @@ def get_default(prop: bpy.types.Property):
|
||||||
return prop.default
|
return prop.default
|
||||||
|
|
||||||
|
|
||||||
def get_dumper(bl_object: bpy.types.bpy_struct):
|
def get_dumper(bl_object: bpy.types.bpy_struct) -> type[Dumper]:
|
||||||
"""Get the corresponding dumper for a given Blender object, or its closest base type"""
|
"""Get the corresponding dumper for a given Blender object, or its closest base type using its MRO"""
|
||||||
for dp in dumpers:
|
|
||||||
if isinstance(bl_object, dp.bl_type): # TODO: Cascade system
|
|
||||||
return dp
|
|
||||||
|
|
||||||
return Dumper or None
|
for cls in bl_object.__class__.mro():
|
||||||
|
dumper_map = DumperRegistry().dumper_map
|
||||||
|
if cls in dumper_map:
|
||||||
|
return dumper_map[cls]
|
||||||
|
|
||||||
|
# Fallback to base Dumper if no matches are found
|
||||||
|
return Dumper
|
||||||
|
|
||||||
def get_current_node_tree(data):
|
def get_current_node_tree(data):
|
||||||
if data.get("_new", {}).get("type") == "GeometryNodeTree":
|
if data.get("_new", {}).get("type") == "GeometryNodeTree":
|
||||||
|
@ -780,31 +786,19 @@ class ViewLayers(PropCollection):
|
||||||
Dumper.load(value, view_layer)
|
Dumper.load(value, view_layer)
|
||||||
|
|
||||||
|
|
||||||
dumpers = [
|
class DumperRegistry:
|
||||||
CompositorNodeRLayers,
|
"""Singleton-like class that holds a map of all parsers, constructed on first instantiation"""
|
||||||
CompositorNodeGlare,
|
dumper_map = None
|
||||||
Node,
|
|
||||||
NodeSocket,
|
def __init__(self):
|
||||||
NodeTree,
|
if self.dumper_map is None:
|
||||||
NodeLink,
|
self.construct_dumper_map()
|
||||||
NodeTreeInterface,
|
|
||||||
NodeTreeInterfaceSocket,
|
@classmethod
|
||||||
NodeGeometryRepeatOutputItems,
|
def construct_dumper_map(cls):
|
||||||
Image,
|
cls.dumper_map = {}
|
||||||
Material,
|
|
||||||
Object,
|
for subclass in utils.all_subclasses(Dumper):
|
||||||
Scene,
|
assert hasattr(subclass, "bl_type")
|
||||||
Collection,
|
cls.dumper_map[subclass.bl_type] = subclass
|
||||||
ViewLayer,
|
print(cls.dumper_map)
|
||||||
CurveMapPoints,
|
|
||||||
ColorRampElements,
|
|
||||||
NodeInputs,
|
|
||||||
NodeOutputs,
|
|
||||||
Nodes,
|
|
||||||
ViewLayers,
|
|
||||||
PropCollection,
|
|
||||||
AOVs,
|
|
||||||
PropArray,
|
|
||||||
CompositorNodeOutputFileLayerSlots,
|
|
||||||
CompositorNodeOutputFileFileSlots,
|
|
||||||
]
|
|
Loading…
Reference in New Issue