Files
multi-user/multi_user/io_bpy/bl_world.py

73 lines
2.1 KiB
Python
Raw Normal View History

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 #####
2019-09-23 22:13:06 +02:00
import bpy
import mathutils
from .dump_anything import Loader, Dumper
2019-09-23 22:13:06 +02:00
from .bl_datablock import BlDatablock
from .bl_material import (load_node_tree,
dump_node_tree,
2020-10-13 17:10:25 +02:00
get_node_tree_dependencies)
2019-09-23 22:13:06 +02:00
class BlWorld(BlDatablock):
bl_id = "worlds"
bl_class = bpy.types.World
2020-09-17 22:47:11 +02:00
bl_check_common = True
bl_icon = 'WORLD_DATA'
bl_reload_parent = False
def construct(data: dict) -> object:
2019-09-23 22:13:06 +02:00
return bpy.data.worlds.new(data["name"])
def load(data: dict, datablock: object):
2020-09-29 11:47:48 +02:00
loader = Loader()
loader.load(target, data)
2020-10-13 17:10:25 +02:00
2019-09-23 22:13:06 +02:00
if data["use_nodes"]:
if target.node_tree is None:
target.use_nodes = True
load_node_tree(data['node_tree'], target.node_tree)
2019-09-23 22:13:06 +02:00
def dump(datablock: object) -> dict:
assert(instance)
2019-09-23 22:13:06 +02:00
2020-04-01 11:34:24 +02:00
world_dumper = Dumper()
world_dumper.depth = 1
world_dumper.include_filter = [
"use_nodes",
"name",
2020-09-29 11:47:48 +02:00
"color"
2019-09-24 11:51:26 +02:00
]
data = world_dumper.dump(instance)
if instance.use_nodes:
data['node_tree'] = dump_node_tree(instance.node_tree)
2020-03-26 17:13:48 +01:00
2019-09-23 22:13:06 +02:00
return data
@staticmethod
def resolve_deps(datablock: object) -> [object]:
2019-09-23 22:13:06 +02:00
deps = []
if datablock.use_nodes:
deps.extend(get_node_tree_dependencies(datablock.node_tree))
2019-09-23 22:13:06 +02:00
return deps