Skip to content

Commit

Permalink
Updated engon from monorepo commit fbb0ebef77617d25c7b905f727b1d245bf…
Browse files Browse the repository at this point in the history
…672605
  • Loading branch information
Griperis committed Mar 27, 2024
1 parent 3a49845 commit 3f155b5
Show file tree
Hide file tree
Showing 33 changed files with 773 additions and 682 deletions.
12 changes: 8 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@
bl_info = {
"name": "engon",
"author": "polygoniq xyz s.r.o.",
"version": (1, 0, 2), # bump doc_url as well!
"version": (1, 0, 3), # bump doc_url as well!
"blender": (3, 3, 0),
"location": "polygoniq tab in the sidebar of the 3D View window",
"description": "",
"category": "Object",
"doc_url": "https://docs.polygoniq.com/engon/1.0.2/",
"doc_url": "https://docs.polygoniq.com/engon/1.0.3/",
"tracker_url": "https://polygoniq.com/discord/"
}

Expand All @@ -136,7 +136,7 @@ def register():

# We need to call the first pack refresh manually, then it's called when paths change
bpy.app.timers.register(
lambda: preferences.get_preferences(bpy.context).refresh_packs(),
lambda: preferences.prefs_utils.get_preferences(bpy.context).refresh_packs(),
first_interval=0,
# This is important. If an existing blend file is opened with double-click or on command
# line with e.g. "blender.exe path/to/blend", this register() is called in the startup blend
Expand All @@ -146,7 +146,7 @@ def register():
)

# Make engon preferences open after first registration
prefs = preferences.get_preferences(bpy.context)
prefs = preferences.prefs_utils.get_preferences(bpy.context)
if prefs.first_time_register:
polib.ui_bpy.expand_addon_prefs(__package__)
prefs.first_time_register = False
Expand All @@ -173,3 +173,7 @@ def unregister():
del sys.modules[module_name]

addon_updater_ops.unregister()

# We clear the master 'polib' icon manager to prevent ResourceWarning and leaks.
# If other addons uses the icon_manager, the previews will be reloaded on demand.
polib.ui_bpy.icon_manager.clear()
2 changes: 1 addition & 1 deletion aquatiq/paint_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def execute(self, context: bpy.types.Context):
active_object.data.use_paint_mask_vertex = False
active_object.data.use_paint_mask = False
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
prefs = preferences.get_preferences(context).aquatiq_preferences
prefs = preferences.prefs_utils.get_preferences(context).aquatiq_preferences
context.tool_settings.vertex_paint.brush.color = [prefs.draw_mask_factor] * 3

return {'FINISHED'}
Expand Down
2 changes: 1 addition & 1 deletion aquatiq/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def draw_material_limitations(self, layout: bpy.types.UILayout, obj: bpy.types.O

def draw_vertex_paint_ui(self, context: bpy.types.Context):
layout = self.layout
prefs = preferences.get_preferences(context).aquatiq_preferences
prefs = preferences.prefs_utils.get_preferences(context).aquatiq_preferences
brush = context.tool_settings.vertex_paint.brush
unified_settings = context.tool_settings.unified_paint_settings

Expand Down
5 changes: 2 additions & 3 deletions aquatiq/puddles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import logging
import mathutils
import polib
from .. import preferences
from .. import asset_helpers
logger = logging.getLogger(f"polygoniq.{__name__}")

Expand All @@ -36,8 +35,8 @@ def ensure_puddles_nodegroup(context: bpy.types.Context) -> None:
puddle_nodegroup = bpy.data.node_groups.get(asset_helpers.AQ_PUDDLES_NODEGROUP_NAME, None)
if puddle_nodegroup is not None:
return
prefs = preferences.get_preferences(context).general_preferences
material_library_path = prefs.get_main_material_library("aquatiq", "aq_Library_Materials.blend")
material_library_path = asset_helpers.get_asset_pack_library_path(
"aquatiq", asset_helpers.AQ_MATERIALS_LIBRARY_BLEND)

if material_library_path is None:
raise RuntimeError("Material library path of aquatiq not found!")
Expand Down
14 changes: 14 additions & 0 deletions asset_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import typing
import bpy
import enum
import os
import glob
import collections
import logging
import polib
Expand All @@ -39,11 +41,16 @@
AQ_MASKABLE_NODE_GROUP_NAMES = {"aq_Fountain", AQ_PUDDLES_NODEGROUP_NAME}
AQ_RIVER_GENERATOR_NODE_GROUP_NAME = "aq_Generator_River"
AQ_RAIN_GENERATOR_NODE_GROUP_NAME = "aq_Rain-Generator_Rain"
AQ_MATERIALS_LIBRARY_BLEND = "aq_Library_Materials.blend"

# botaniq constants
BOTANIQ_ALL_SEASONS_RAW = "spring-summer-autumn-winter"
BQ_COLLECTION_NAME = "botaniq"
BQ_VINE_GENERATOR_NODE_GROUP_NAME = "bq_Vine_Generator"
BQ_ANIM_LIBRARY_BLEND = "bq_Library_Animation_Data.blend"

# traffiq constants
TQ_MODIFIER_LIBRARY_BLEND = "tq_Library_Modifiers.blend"


PARTICLE_SYSTEM_PREFIX = f"engon_{polib.asset_pack_bpy.PARTICLE_SYSTEM_TOKEN}_"
Expand Down Expand Up @@ -111,6 +118,13 @@ def get_materialiq_texture_sizes_enum_items():
(str(size), str(size), f"materialiq texture size: {size}") for size in texture_sizes]


def get_asset_pack_library_path(engon_feature: str, library_blend_name: str) -> typing.Optional[str]:
for pack in asset_registry.instance.get_packs_by_engon_feature(engon_feature):
for lib in glob.iglob(os.path.join(pack.install_path, "blends", "**", library_blend_name), recursive=True):
return lib
return None


def exclude_variant_from_asset_name(asset_name: str) -> str:
"""Given a full asset name of a plain asset (not particle system!) this function will generate
a key of the asset that contains all parts of the asset name except the variant. This is useful
Expand Down
22 changes: 20 additions & 2 deletions asset_pack_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ class InstallerOperation(enum.Enum):
class InstallerStatus(enum.Enum):
READY = "Ready"
NOT_FOUND = "Not Found"
CANCELED = "Canceled"
ABORTED = "Aborted"
FINISHED = "Finished"
NOT_READY = "Not Ready"
EXIT = "Exit"
# This status serves for our custom cancel button in versions before 4.1.0
# TODO: Remove this status when we drop support for Blender versions before 4.1.0
CANCELED = "Canceled"


INSTALLER_OPERATION_DESCRIPTIONS: typing.Dict[InstallerStatus, str] = {
Expand All @@ -57,7 +60,8 @@ class InstallerStatus(enum.Enum):
InstallerStatus.CANCELED: "_ACTION_ was canceled.",
InstallerStatus.ABORTED: "_ACTION_ was unsuccessful.",
InstallerStatus.FINISHED: "_ACTION_ was successful.",
InstallerStatus.NOT_READY: "_ACTION_ is not ready to proceed. Resolve the issue(s) below."
InstallerStatus.NOT_READY: "_ACTION_ is not ready to proceed. Resolve the issue(s) below.",
InstallerStatus.EXIT: "Exited _ACTION_."
}


Expand Down Expand Up @@ -291,6 +295,11 @@ def cancel_installer_operation(self) -> None:
self._error_messages.clear()
self.status = InstallerStatus.CANCELED

def exit_installer_operation(self) -> None:
self._warning_messages.clear()
self._error_messages.clear()
self.status = InstallerStatus.EXIT

def get_installer_status_description(self) -> str:
"""Return the status description containing the current operation name."""

Expand Down Expand Up @@ -754,4 +763,13 @@ def check_should_dialog_close(self) -> bool:

def invoke(self, context: bpy.types.Context, event: bpy.types.Event):
polib.ui_bpy.center_mouse(context)
# When the dialog is supposed to close, we don't want to show the OK and Cancel buttons
if self.check_should_dialog_close():
return context.window_manager.invoke_popup(self, width=550)
return context.window_manager.invoke_props_dialog(self, width=550)

# Since Blender 4.1.0 there is a cancel button in the dialog window
# This method is called when the cancel button is clicked
# This method is also called when user clicks outside of the operator dialog window
def cancel(self, context: bpy.types.Context):
instance.exit_installer_operation()
24 changes: 20 additions & 4 deletions asset_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(
self.index_paths = index_paths
self.file_id_prefix = file_id_prefix

# Initialize IconManager
# Initialize PreviewManager for icons
self.pack_icon: typing.Optional[str] = None
self.vendor_icon: typing.Optional[str] = None
valid_icon_paths: typing.List[str] = []
Expand All @@ -174,8 +174,9 @@ def __init__(
f"Asset pack icon '{icon_path}' not found on path '{icon_fullpath}'!")
valid_icon_paths.append(icon_fullpath)

self.icon_manager = polib.ui_bpy.IconManager(
include_polib_icons=False, additional_paths=valid_icon_paths)
self.icon_manager = polib.preview_manager_bpy.PreviewManager()
for path in valid_icon_paths:
self.icon_manager.add_preview_path(path)

# we remember which providers we registered to MAPR to be able to unregister them
self.asset_providers: typing.List[mapr.asset_provider.AssetProvider] = []
Expand Down Expand Up @@ -391,6 +392,21 @@ def get_install_paths_by_engon_feature(self) -> typing.Dict[str, typing.List[str
output_dict[feature] = [pack.install_path for pack in asset_packs]
return output_dict

def register_pack_from_pack_info_path(self, pack_info_path: str, refresh_registry: bool = True) -> None:
asset_pack = AssetPack.load_from_json(pack_info_path)
logger.info(f"Registering asset pack '{asset_pack.full_name}' from '{pack_info_path}'")
self._register_pack(asset_pack)
if refresh_registry:
self._registry_refreshed()

def unregister_pack_from_pack_info_path(self, pack_info_path: str, refresh_registry: bool = True) -> None:
asset_pack = self.get_pack_by_pack_info_path(pack_info_path)
assert asset_pack is not None
logger.info(f"Unregistering asset pack '{asset_pack.full_name}' from '{pack_info_path}'")
self._unregister_pack(asset_pack)
if refresh_registry:
self._registry_refreshed()

def refresh_packs_from_pack_info_paths(self, pack_info_files: typing.Iterable[str]) -> None:
input_pack_info_files: typing.Set[str] = set(pack_info_files)
logger.info(
Expand Down Expand Up @@ -435,7 +451,7 @@ def _registry_refreshed(self) -> None:

def reload_asset_pack_icons():
for asset_pack in instance.get_registered_packs():
asset_pack.icon_manager.reload()
asset_pack.icon_manager.clear()


instance.on_refresh.append(reload_asset_pack_icons)
3 changes: 2 additions & 1 deletion blend_maintenance/migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class MigrateFromMaterialiq4(bpy.types.Operator):
"Finds materialiq4 materials and replaces them with their equivalents from the latest version of materialiq"

def execute(self, context: bpy.types.Context):
spawn_options = preferences.get_preferences(context).mapr_preferences.spawn_options
spawn_options = preferences.prefs_utils.get_preferences(
context).mapr_preferences.spawn_options
asset_provider = asset_registry.instance.master_asset_provider
file_provider = asset_registry.instance.master_file_provider
spawner = mapr.blender_asset_spawner.AssetSpawner(asset_provider, file_provider)
Expand Down
Loading

0 comments on commit 3f155b5

Please sign in to comment.