feat: color_ramp loading
This commit is contained in:
@ -6,6 +6,15 @@ from .. import utils
|
|||||||
from .bl_datablock import BlDatablock
|
from .bl_datablock import BlDatablock
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
def clean_color_ramp(target_ramp):
|
||||||
|
# clear existing
|
||||||
|
try:
|
||||||
|
for key in target_ramp.elements:
|
||||||
|
target_ramp.elements.remove(key)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_node(target_node_tree, source):
|
def load_node(target_node_tree, source):
|
||||||
target_node = target_node_tree.nodes.get(source["name"])
|
target_node = target_node_tree.nodes.get(source["name"])
|
||||||
@ -15,12 +24,18 @@ def load_node(target_node_tree, source):
|
|||||||
|
|
||||||
target_node = target_node_tree.nodes.new(type=node_type)
|
target_node = target_node_tree.nodes.new(type=node_type)
|
||||||
|
|
||||||
|
# Clean color ramp before loading it
|
||||||
|
if source['type'] == 'VALTORGB':
|
||||||
|
clean_color_ramp(target_node.color_ramp)
|
||||||
|
|
||||||
utils.dump_anything.load(
|
utils.dump_anything.load(
|
||||||
target_node, source)
|
target_node,
|
||||||
|
source)
|
||||||
|
|
||||||
if source['type'] == 'TEX_IMAGE':
|
if source['type'] == 'TEX_IMAGE':
|
||||||
target_node.image = bpy.data.images[source['image']]
|
target_node.image = bpy.data.images[source['image']]
|
||||||
|
|
||||||
|
|
||||||
for input in source["inputs"]:
|
for input in source["inputs"]:
|
||||||
if hasattr(target_node.inputs[input], "default_value"):
|
if hasattr(target_node.inputs[input], "default_value"):
|
||||||
try:
|
try:
|
||||||
@ -115,10 +130,20 @@ class BlMaterial(BlDatablock):
|
|||||||
nodes[node.name]['inputs'] = {}
|
nodes[node.name]['inputs'] = {}
|
||||||
|
|
||||||
for i in node.inputs:
|
for i in node.inputs:
|
||||||
|
|
||||||
if hasattr(i, 'default_value'):
|
if hasattr(i, 'default_value'):
|
||||||
nodes[node.name]['inputs'][i.name] = input_dumper.dump(
|
nodes[node.name]['inputs'][i.name] = input_dumper.dump(
|
||||||
i)
|
i)
|
||||||
|
if hasattr(node, 'color_ramp'):
|
||||||
|
ramp_dumper = utils.dump_anything.Dumper()
|
||||||
|
ramp_dumper.depth = 4
|
||||||
|
ramp_dumper.include_filter = [
|
||||||
|
'elements',
|
||||||
|
'alpha',
|
||||||
|
'color',
|
||||||
|
'position'
|
||||||
|
]
|
||||||
|
nodes[node.name]['color_ramp'] = ramp_dumper.dump(node.color_ramp)
|
||||||
|
|
||||||
data["node_tree"]['nodes'] = nodes
|
data["node_tree"]['nodes'] = nodes
|
||||||
data["node_tree"]["links"] = links_dumper.dump(pointer.node_tree.links)
|
data["node_tree"]["links"] = links_dumper.dump(pointer.node_tree.links)
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ class BlScene(BlDatablock):
|
|||||||
target.world = bpy.data.worlds[data['world']]
|
target.world = bpy.data.worlds[data['world']]
|
||||||
|
|
||||||
# Annotation
|
# Annotation
|
||||||
|
|
||||||
if 'grease_pencil' in data.keys():
|
if 'grease_pencil' in data.keys():
|
||||||
target.grease_pencil = bpy.data.grease_pencils[data['grease_pencil']]
|
target.grease_pencil = bpy.data.grease_pencils[data['grease_pencil']]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user