feat: custom cache directory in userpref
This commit is contained in:
@ -42,7 +42,7 @@ def client_list_callback(scene, context):
|
|||||||
|
|
||||||
items = [(RP_COMMON, RP_COMMON, "")]
|
items = [(RP_COMMON, RP_COMMON, "")]
|
||||||
|
|
||||||
username = bpy.context.preferences.addons[__package__].preferences.username
|
username = utils.get_preferences().username
|
||||||
cli = operators.client
|
cli = operators.client
|
||||||
if cli:
|
if cli:
|
||||||
client_ids = cli.online_users.keys()
|
client_ids = cli.online_users.keys()
|
||||||
|
@ -2,15 +2,16 @@ import bpy
|
|||||||
import mathutils
|
import mathutils
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .. import utils, environment
|
from .. import utils
|
||||||
from .bl_datablock import BlDatablock
|
from .bl_datablock import BlDatablock
|
||||||
|
|
||||||
def dump_image(image):
|
def dump_image(image):
|
||||||
pixels = None
|
pixels = None
|
||||||
if image.source == "GENERATED":
|
if image.source == "GENERATED":
|
||||||
|
prefs = utils.get_preferences()
|
||||||
img_name = "{}.png".format(image.name)
|
img_name = "{}.png".format(image.name)
|
||||||
|
|
||||||
image.filepath_raw = os.path.join(environment.CACHE_DIR, img_name)
|
image.filepath_raw = os.path.join(prefs.cache_directory, img_name)
|
||||||
image.file_format = "PNG"
|
image.file_format = "PNG"
|
||||||
image.save()
|
image.save()
|
||||||
|
|
||||||
@ -43,10 +44,11 @@ class BlImage(BlDatablock):
|
|||||||
|
|
||||||
def load(self, data, target):
|
def load(self, data, target):
|
||||||
image = target
|
image = target
|
||||||
|
prefs = utils.get_preferences()
|
||||||
|
|
||||||
img_name = "{}.png".format(image.name)
|
img_name = "{}.png".format(image.name)
|
||||||
|
|
||||||
img_path = os.path.join(environment.CACHE_DIR, img_name)
|
img_path = os.path.join(prefs.cache_directory, img_name)
|
||||||
|
|
||||||
file = open(img_path, 'wb')
|
file = open(img_path, 'wb')
|
||||||
file.write(data["pixels"])
|
file.write(data["pixels"])
|
||||||
|
@ -88,7 +88,7 @@ class DynamicRightSelectTimer(Timer):
|
|||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
session = operators.client
|
session = operators.client
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
|
|
||||||
if session and session.state['STATE'] == STATE_ACTIVE:
|
if session and session.state['STATE'] == STATE_ACTIVE:
|
||||||
# Find user
|
# Find user
|
||||||
@ -220,7 +220,7 @@ class ClientUpdate(Timer):
|
|||||||
self.handle_quit = False
|
self.handle_quit = False
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
session = getattr(operators, 'client', None)
|
session = getattr(operators, 'client', None)
|
||||||
renderer = getattr(presence, 'renderer', None)
|
renderer = getattr(presence, 'renderer', None)
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ logger = logging.getLogger(__name__)
|
|||||||
logger.setLevel(logging.WARNING)
|
logger.setLevel(logging.WARNING)
|
||||||
|
|
||||||
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
||||||
CACHE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache")
|
DEFAULT_CACHE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache")
|
||||||
PYTHON_PATH = None
|
PYTHON_PATH = None
|
||||||
SUBPROCESS_DIR = None
|
SUBPROCESS_DIR = None
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class SessionStartOperator(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
global client, delayables, ui_context, server_process
|
global client, delayables, ui_context, server_process
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
runtime_settings = context.window_manager.session
|
runtime_settings = context.window_manager.session
|
||||||
users = bpy.data.window_managers['WinMan'].online_users
|
users = bpy.data.window_managers['WinMan'].online_users
|
||||||
|
|
||||||
@ -482,7 +482,7 @@ def depsgraph_evaluation(scene):
|
|||||||
context = bpy.context
|
context = bpy.context
|
||||||
blender_depsgraph = bpy.context.view_layer.depsgraph
|
blender_depsgraph = bpy.context.view_layer.depsgraph
|
||||||
dependency_updates = [u for u in blender_depsgraph.updates]
|
dependency_updates = [u for u in blender_depsgraph.updates]
|
||||||
session_infos = bpy.context.preferences.addons[__package__].preferences
|
session_infos = utils.get_preferences()
|
||||||
|
|
||||||
# NOTE: maybe we don't need to check each update but only the first
|
# NOTE: maybe we don't need to check each update but only the first
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
from . import utils, bl_types
|
from . import utils, bl_types, environment
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -53,6 +53,10 @@ class SessionPrefs(bpy.types.AddonPreferences):
|
|||||||
('STRICT', 'strict', 'strict right repartition'),
|
('STRICT', 'strict', 'strict right repartition'),
|
||||||
('COMMON', 'common', 'relaxed right repartition')},
|
('COMMON', 'common', 'relaxed right repartition')},
|
||||||
default='COMMON')
|
default='COMMON')
|
||||||
|
cache_directory: bpy.props.StringProperty(
|
||||||
|
name="cache directory",
|
||||||
|
subtype="DIR_PATH",
|
||||||
|
default=environment.DEFAULT_CACHE_DIR)
|
||||||
# for UI
|
# for UI
|
||||||
category: bpy.props.EnumProperty(
|
category: bpy.props.EnumProperty(
|
||||||
name="Category",
|
name="Category",
|
||||||
@ -79,6 +83,11 @@ class SessionPrefs(bpy.types.AddonPreferences):
|
|||||||
description="net",
|
description="net",
|
||||||
default=True
|
default=True
|
||||||
)
|
)
|
||||||
|
conf_session_cache_expanded: bpy.props.BoolProperty(
|
||||||
|
name="Cache",
|
||||||
|
description="cache",
|
||||||
|
default=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
@ -139,6 +148,15 @@ class SessionPrefs(bpy.types.AddonPreferences):
|
|||||||
row = box.row()
|
row = box.row()
|
||||||
row.label(text="Start with an empty scene:")
|
row.label(text="Start with an empty scene:")
|
||||||
row.prop(self, "start_empty", text="")
|
row.prop(self, "start_empty", text="")
|
||||||
|
|
||||||
|
# CACHE SETTINGS
|
||||||
|
box = grid.box()
|
||||||
|
box.prop(
|
||||||
|
self, "conf_session_cache_expanded", text="Cache",
|
||||||
|
icon='DISCLOSURE_TRI_DOWN' if self.conf_session_cache_expanded
|
||||||
|
else 'DISCLOSURE_TRI_RIGHT')
|
||||||
|
if self.conf_session_cache_expanded:
|
||||||
|
box.row().prop(self, "cache_directory", text="Cache directory")
|
||||||
|
|
||||||
def generate_supported_types(self):
|
def generate_supported_types(self):
|
||||||
self.supported_datablocks.clear()
|
self.supported_datablocks.clear()
|
||||||
|
@ -204,7 +204,7 @@ class DrawFactory(object):
|
|||||||
self.d2d_items.clear()
|
self.d2d_items.clear()
|
||||||
|
|
||||||
def draw_client_selection(self, client_id, client_color, client_selection):
|
def draw_client_selection(self, client_id, client_color, client_selection):
|
||||||
local_user = bpy.context.preferences.addons[__package__].preferences.username
|
local_user = utils.get_preferences().username
|
||||||
|
|
||||||
if local_user != client_id:
|
if local_user != client_id:
|
||||||
self.flush_selection(client_id)
|
self.flush_selection(client_id)
|
||||||
@ -261,7 +261,7 @@ class DrawFactory(object):
|
|||||||
|
|
||||||
def draw_client_camera(self, client_id, client_location, client_color):
|
def draw_client_camera(self, client_id, client_location, client_color):
|
||||||
if client_location:
|
if client_location:
|
||||||
local_user = bpy.context.preferences.addons[__package__].preferences.username
|
local_user = utils.get_preferences().username
|
||||||
|
|
||||||
if local_user != client_id:
|
if local_user != client_id:
|
||||||
try:
|
try:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
from . import operators
|
from . import operators, utils
|
||||||
from .libs.replication.replication.constants import (ADDED, ERROR, FETCHED,
|
from .libs.replication.replication.constants import (ADDED, ERROR, FETCHED,
|
||||||
MODIFIED, RP_COMMON, UP,
|
MODIFIED, RP_COMMON, UP,
|
||||||
STATE_ACTIVE, STATE_AUTH,
|
STATE_ACTIVE, STATE_AUTH,
|
||||||
@ -140,7 +140,7 @@ class SESSION_PT_settings_network(bpy.types.Panel):
|
|||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
|
||||||
runtime_settings = context.window_manager.session
|
runtime_settings = context.window_manager.session
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
|
|
||||||
# USER SETTINGS
|
# USER SETTINGS
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
@ -186,7 +186,7 @@ class SESSION_PT_settings_user(bpy.types.Panel):
|
|||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
|
||||||
runtime_settings = context.window_manager.session
|
runtime_settings = context.window_manager.session
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
# USER SETTINGS
|
# USER SETTINGS
|
||||||
@ -215,7 +215,7 @@ class SESSION_PT_settings_replication(bpy.types.Panel):
|
|||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
|
||||||
runtime_settings = context.window_manager.session
|
runtime_settings = context.window_manager.session
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
|
|
||||||
# Right managment
|
# Right managment
|
||||||
if runtime_settings.session_mode == 'HOST':
|
if runtime_settings.session_mode == 'HOST':
|
||||||
@ -259,7 +259,7 @@ class SESSION_PT_user(bpy.types.Panel):
|
|||||||
layout = self.layout
|
layout = self.layout
|
||||||
online_users = context.window_manager.online_users
|
online_users = context.window_manager.online_users
|
||||||
selected_user = context.window_manager.user_index
|
selected_user = context.window_manager.user_index
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
active_user = online_users[selected_user] if len(online_users)-1>=selected_user else 0
|
active_user = online_users[selected_user] if len(online_users)-1>=selected_user else 0
|
||||||
|
|
||||||
|
|
||||||
@ -293,7 +293,7 @@ class SESSION_PT_user(bpy.types.Panel):
|
|||||||
class SESSION_UL_users(bpy.types.UIList):
|
class SESSION_UL_users(bpy.types.UIList):
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
|
||||||
session = operators.client
|
session = operators.client
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
is_local_user = item.username == settings.username
|
is_local_user = item.username == settings.username
|
||||||
ping = '-'
|
ping = '-'
|
||||||
frame_current = '-'
|
frame_current = '-'
|
||||||
@ -368,7 +368,7 @@ class SESSION_PT_services(bpy.types.Panel):
|
|||||||
|
|
||||||
|
|
||||||
def draw_property(context, parent, property_uuid, level=0):
|
def draw_property(context, parent, property_uuid, level=0):
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
runtime_settings = context.window_manager.session
|
runtime_settings = context.window_manager.session
|
||||||
item = operators.client.get(uuid=property_uuid)
|
item = operators.client.get(uuid=property_uuid)
|
||||||
|
|
||||||
@ -449,7 +449,7 @@ class SESSION_PT_outliner(bpy.types.Panel):
|
|||||||
|
|
||||||
if hasattr(context.window_manager, 'session'):
|
if hasattr(context.window_manager, 'session'):
|
||||||
# Filters
|
# Filters
|
||||||
settings = bpy.context.preferences.addons[__package__].preferences
|
settings = utils.get_preferences()
|
||||||
runtime_settings = context.window_manager.session
|
runtime_settings = context.window_manager.session
|
||||||
flow = layout.grid_flow(
|
flow = layout.grid_flow(
|
||||||
row_major=True,
|
row_major=True,
|
||||||
|
@ -37,7 +37,7 @@ def find_from_attr(attr_name, attr_value, list):
|
|||||||
|
|
||||||
def get_datablock_users(datablock):
|
def get_datablock_users(datablock):
|
||||||
users = []
|
users = []
|
||||||
supported_types = bpy.context.preferences.addons[__package__].preferences.supported_datablocks
|
supported_types = get_preferences().supported_datablocks
|
||||||
if hasattr(datablock, 'users_collection') and datablock.users_collection:
|
if hasattr(datablock, 'users_collection') and datablock.users_collection:
|
||||||
users.extend(list(datablock.users_collection))
|
users.extend(list(datablock.users_collection))
|
||||||
if hasattr(datablock, 'users_scene') and datablock.users_scene:
|
if hasattr(datablock, 'users_scene') and datablock.users_scene:
|
||||||
@ -59,12 +59,14 @@ def random_string_digits(stringLength=6):
|
|||||||
lettersAndDigits = string.ascii_letters + string.digits
|
lettersAndDigits = string.ascii_letters + string.digits
|
||||||
return ''.join(random.choices(lettersAndDigits, k=stringLength))
|
return ''.join(random.choices(lettersAndDigits, k=stringLength))
|
||||||
|
|
||||||
|
|
||||||
def randomColor():
|
def randomColor():
|
||||||
r = random.random()
|
r = random.random()
|
||||||
v = random.random()
|
v = random.random()
|
||||||
b = random.random()
|
b = random.random()
|
||||||
return [r, v, b]
|
return [r, v, b]
|
||||||
|
|
||||||
|
|
||||||
def clean_scene():
|
def clean_scene():
|
||||||
for type_name in dir(bpy.data):
|
for type_name in dir(bpy.data):
|
||||||
try:
|
try:
|
||||||
@ -166,3 +168,6 @@ def resolve_from_id(id, optionnal_type=None):
|
|||||||
return root[id]
|
return root[id]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_preferences():
|
||||||
|
return bpy.context.preferences.addons[__package__].preferences
|
Reference in New Issue
Block a user