feat: add initial texture support

This commit is contained in:
Swann 2020-12-02 11:24:26 +01:00
parent 1273ab2371
commit 1d03fe4975
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB
3 changed files with 97 additions and 10 deletions

View File

@ -39,7 +39,8 @@ __all__ = [
'bl_sound',
'bl_file',
'bl_sequencer',
'bl_node_group'
'bl_node_group',
'bl_texture'
] # Order here defines execution order
from . import *

View File

@ -78,6 +78,19 @@ def _is_editmode(object: bpy.types.Object) -> bool:
child_data.is_editmode)
def find_textures_dependencies(collection):
""" Check collection
"""
textures = []
for item in collection:
for attr in dir(item):
inst = getattr(item, attr)
if issubclass(type(inst), bpy.types.Texture) and inst is not None:
textures.append(inst)
return textures
class BlObject(BlDatablock):
bl_id = "objects"
bl_class = bpy.types.Object
@ -120,7 +133,8 @@ class BlObject(BlDatablock):
data_id = data.get("data")
if target.data and (target.data.name != data_id):
target.data = get_datablock_from_uuid(data_uuid, find_data_from_name(data_id), ignore=['images'])
target.data = get_datablock_from_uuid(
data_uuid, find_data_from_name(data_id), ignore=['images'])
# vertex groups
if 'vertex_groups' in data:
@ -384,4 +398,7 @@ class BlObject(BlDatablock):
# TODO: uuid based
deps.append(self.instance.instance_collection)
if self.instance.modifiers:
deps.extend(find_textures_dependencies(self.instance.modifiers))
return deps

View File

@ -0,0 +1,69 @@
# ##### 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 #####
import bpy
import mathutils
from .dump_anything import Loader, Dumper
from .bl_datablock import BlDatablock
class BlTexture(BlDatablock):
bl_id = "textures"
bl_class = bpy.types.Texture
bl_delay_refresh = 1
bl_delay_apply = 1
bl_automatic_push = True
bl_check_common = False
bl_icon = 'TEXTURE'
def _load_implementation(self, data, target):
loader = Loader()
loader.load(target, data)
def _construct(self, data):
return bpy.data.textures.new(data["name"], data["type"])
def _dump_implementation(self, data, instance=None):
assert(instance)
dumper = Dumper()
dumper.depth = 1
dumper.exclude_filter = []
data = dumper.dump(instance)
color_ramp = getattr(instance, 'color_ramp', None)
if color_ramp:
dumper.depth = 4
data['color_ramp'] = dumper.dump(color_ramp)
return data
def _resolve_deps_implementation(self):
# TODO: resolve material
deps = []
image = getattr(self.instance,"image", None)
if image:
deps.append(image)
return deps