Texture browser: save Node document with downloaded image.
This commit is contained in:
parent
8edf9c7428
commit
56b622a723
@ -17,6 +17,7 @@
|
|||||||
# ##### END GPL LICENSE BLOCK #####
|
# ##### END GPL LICENSE BLOCK #####
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import functools
|
import functools
|
||||||
@ -37,6 +38,8 @@ from . import cache
|
|||||||
SUBCLIENT_ID = 'PILLAR'
|
SUBCLIENT_ID = 'PILLAR'
|
||||||
TEXTURE_NODE_TYPES = {'texture', 'hdri', 'HDRI_FILE'}
|
TEXTURE_NODE_TYPES = {'texture', 'hdri', 'HDRI_FILE'}
|
||||||
|
|
||||||
|
RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
|
||||||
|
|
||||||
_pillar_api = {} # will become a mapping from bool (cached/non-cached) to pillarsdk.Api objects.
|
_pillar_api = {} # will become a mapping from bool (cached/non-cached) to pillarsdk.Api objects.
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
uncached_session = requests.session()
|
uncached_session = requests.session()
|
||||||
@ -856,3 +859,21 @@ async def attach_file_to_group(file_path: pathlib.Path,
|
|||||||
extra_where=user_id and {'user': user_id})
|
extra_where=user_id and {'user': user_id})
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
|
||||||
|
def node_to_id(node: pillarsdk.Node) -> dict:
|
||||||
|
"""Converts a Node to a dict we can store in an ID property.
|
||||||
|
|
||||||
|
ID properties only support a handful of Python classes, so we have
|
||||||
|
to convert datetime.datetime to a string and remove None values.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def to_rna(value):
|
||||||
|
if isinstance(value, dict):
|
||||||
|
return {k: to_rna(v) for k, v in value.items()}
|
||||||
|
if isinstance(value, datetime.datetime):
|
||||||
|
return value.strftime(RFC1123_DATE_FORMAT)
|
||||||
|
return value
|
||||||
|
|
||||||
|
as_dict = to_rna(node.to_dict())
|
||||||
|
return pillarsdk.utils.remove_none_attributes(as_dict)
|
||||||
|
@ -816,10 +816,17 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
def texture_downloaded(file_path, file_desc, *args):
|
def texture_downloaded(file_path, file_desc, *args):
|
||||||
nonlocal select_dblock
|
nonlocal select_dblock
|
||||||
|
|
||||||
|
node = item.node
|
||||||
|
if isinstance(node, HdriFileNode):
|
||||||
|
# We want to obtain the real node, not the fake one.
|
||||||
|
node = self.menu_item_stack[-1].node
|
||||||
|
|
||||||
self.log.info('Texture downloaded to %r.', file_path)
|
self.log.info('Texture downloaded to %r.', file_path)
|
||||||
image_dblock = bpy.data.images.load(filepath=file_path)
|
image_dblock = bpy.data.images.load(filepath=file_path)
|
||||||
image_dblock['bcloud_file_uuid'] = file_desc['_id']
|
image_dblock['bcloud_file_uuid'] = file_desc['_id']
|
||||||
image_dblock['bcloud_texture_node_uuid'] = item.node_uuid
|
image_dblock['bcloud_node_uuid'] = node['_id']
|
||||||
|
image_dblock['bcloud_node_type'] = node.node_type
|
||||||
|
image_dblock['bcloud_node'] = pillar.node_to_id(node)
|
||||||
|
|
||||||
# Select the image in the image editor (if the context is right).
|
# Select the image in the image editor (if the context is right).
|
||||||
# Just set the first image we download,
|
# Just set the first image we download,
|
||||||
|
Reference in New Issue
Block a user