feat: add initial texture support
This commit is contained in:
parent
1273ab2371
commit
1d03fe4975
@ -39,7 +39,8 @@ __all__ = [
|
|||||||
'bl_sound',
|
'bl_sound',
|
||||||
'bl_file',
|
'bl_file',
|
||||||
'bl_sequencer',
|
'bl_sequencer',
|
||||||
'bl_node_group'
|
'bl_node_group',
|
||||||
|
'bl_texture'
|
||||||
] # Order here defines execution order
|
] # Order here defines execution order
|
||||||
|
|
||||||
from . import *
|
from . import *
|
||||||
|
@ -35,7 +35,7 @@ def load_pose(target_bone, data):
|
|||||||
def find_data_from_name(name=None):
|
def find_data_from_name(name=None):
|
||||||
instance = None
|
instance = None
|
||||||
if not name:
|
if not name:
|
||||||
pass
|
pass
|
||||||
elif name in bpy.data.meshes.keys():
|
elif name in bpy.data.meshes.keys():
|
||||||
instance = bpy.data.meshes[name]
|
instance = bpy.data.meshes[name]
|
||||||
elif name in bpy.data.lights.keys():
|
elif name in bpy.data.lights.keys():
|
||||||
@ -78,6 +78,19 @@ def _is_editmode(object: bpy.types.Object) -> bool:
|
|||||||
child_data.is_editmode)
|
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):
|
class BlObject(BlDatablock):
|
||||||
bl_id = "objects"
|
bl_id = "objects"
|
||||||
bl_class = bpy.types.Object
|
bl_class = bpy.types.Object
|
||||||
@ -105,9 +118,9 @@ class BlObject(BlDatablock):
|
|||||||
data_id = data.get("data")
|
data_id = data.get("data")
|
||||||
|
|
||||||
object_data = get_datablock_from_uuid(
|
object_data = get_datablock_from_uuid(
|
||||||
data_uuid,
|
data_uuid,
|
||||||
find_data_from_name(data_id),
|
find_data_from_name(data_id),
|
||||||
ignore=['images']) #TODO: use resolve_from_id
|
ignore=['images']) # TODO: use resolve_from_id
|
||||||
instance = bpy.data.objects.new(object_name, object_data)
|
instance = bpy.data.objects.new(object_name, object_data)
|
||||||
instance.uuid = self.uuid
|
instance.uuid = self.uuid
|
||||||
|
|
||||||
@ -120,14 +133,15 @@ class BlObject(BlDatablock):
|
|||||||
data_id = data.get("data")
|
data_id = data.get("data")
|
||||||
|
|
||||||
if target.data and (target.data.name != data_id):
|
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
|
# vertex groups
|
||||||
if 'vertex_groups' in data:
|
if 'vertex_groups' in data:
|
||||||
target.vertex_groups.clear()
|
target.vertex_groups.clear()
|
||||||
for vg in data['vertex_groups']:
|
for vg in data['vertex_groups']:
|
||||||
vertex_group=target.vertex_groups.new(name = vg['name'])
|
vertex_group = target.vertex_groups.new(name=vg['name'])
|
||||||
point_attr='vertices' if 'vertices' in vg else 'points'
|
point_attr = 'vertices' if 'vertices' in vg else 'points'
|
||||||
for vert in vg[point_attr]:
|
for vert in vg[point_attr]:
|
||||||
vertex_group.add(
|
vertex_group.add(
|
||||||
[vert['index']], vert['weight'], 'REPLACE')
|
[vert['index']], vert['weight'], 'REPLACE')
|
||||||
@ -136,12 +150,12 @@ class BlObject(BlDatablock):
|
|||||||
if 'shape_keys' in data:
|
if 'shape_keys' in data:
|
||||||
target.shape_key_clear()
|
target.shape_key_clear()
|
||||||
|
|
||||||
object_data=target.data
|
object_data = target.data
|
||||||
|
|
||||||
# Create keys and load vertices coords
|
# Create keys and load vertices coords
|
||||||
for key_block in data['shape_keys']['key_blocks']:
|
for key_block in data['shape_keys']['key_blocks']:
|
||||||
key_data=data['shape_keys']['key_blocks'][key_block]
|
key_data = data['shape_keys']['key_blocks'][key_block]
|
||||||
target.shape_key_add(name = key_block)
|
target.shape_key_add(name=key_block)
|
||||||
|
|
||||||
loader.load(
|
loader.load(
|
||||||
target.data.shape_keys.key_blocks[key_block], key_data)
|
target.data.shape_keys.key_blocks[key_block], key_data)
|
||||||
@ -384,4 +398,7 @@ class BlObject(BlDatablock):
|
|||||||
# TODO: uuid based
|
# TODO: uuid based
|
||||||
deps.append(self.instance.instance_collection)
|
deps.append(self.instance.instance_collection)
|
||||||
|
|
||||||
|
if self.instance.modifiers:
|
||||||
|
deps.extend(find_textures_dependencies(self.instance.modifiers))
|
||||||
|
|
||||||
return deps
|
return deps
|
||||||
|
69
multi_user/bl_types/bl_texture.py
Normal file
69
multi_user/bl_types/bl_texture.py
Normal 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
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user