2023-08-16 00:20:26 +10:00
|
|
|
# SPDX-FileCopyrightText: 2020-2023 Blender Authors
|
2023-06-15 13:09:04 +10:00
|
|
|
#
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2023-06-15 13:09:04 +10:00
|
|
|
|
2021-02-21 21:21:18 +11:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-07-02 10:40:19 +02:00
|
|
|
import bpy
|
2021-03-23 16:08:02 +11:00
|
|
|
from bpy.types import Operator
|
2022-11-16 12:06:14 +01:00
|
|
|
from bpy.app.translations import (
|
|
|
|
pgettext_data as data_,
|
2024-01-11 19:49:03 +01:00
|
|
|
pgettext_rpt as rpt_,
|
2022-11-16 12:06:14 +01:00
|
|
|
)
|
2022-10-05 17:53:28 +02:00
|
|
|
|
|
|
|
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
from bpy_extras.asset_utils import (
|
|
|
|
SpaceAssetInfo,
|
|
|
|
)
|
|
|
|
|
2020-12-16 18:02:40 +11:00
|
|
|
|
2021-09-23 14:43:21 +02:00
|
|
|
class AssetBrowserMetadataOperator:
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
2023-09-19 14:41:34 +02:00
|
|
|
if not SpaceAssetInfo.is_asset_browser_poll(context) or not context.asset:
|
2021-09-23 14:43:21 +02:00
|
|
|
return False
|
|
|
|
|
2023-09-19 14:41:34 +02:00
|
|
|
if not context.asset.local_id:
|
2021-09-23 14:43:21 +02:00
|
|
|
Operator.poll_message_set(
|
|
|
|
"Asset metadata from external asset libraries can't be "
|
|
|
|
"edited, only assets stored in the current file can"
|
|
|
|
)
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class ASSET_OT_tag_add(AssetBrowserMetadataOperator, Operator):
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
"""Add a new keyword tag to the active asset"""
|
|
|
|
|
|
|
|
bl_idname = "asset.tag_add"
|
|
|
|
bl_label = "Add Asset Tag"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
|
|
|
def execute(self, context):
|
2024-05-29 13:47:28 +02:00
|
|
|
active_asset = context.asset
|
2024-06-27 10:57:33 +02:00
|
|
|
active_asset.metadata.tags.new(data_("Tag"))
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
2021-09-23 14:43:21 +02:00
|
|
|
class ASSET_OT_tag_remove(AssetBrowserMetadataOperator, Operator):
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
"""Remove an existing keyword tag from the active asset"""
|
|
|
|
|
|
|
|
bl_idname = "asset.tag_remove"
|
|
|
|
bl_label = "Remove Asset Tag"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
2021-09-23 14:43:21 +02:00
|
|
|
if not super().poll(context):
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
return False
|
|
|
|
|
2023-09-19 14:41:34 +02:00
|
|
|
active_asset = context.asset
|
|
|
|
asset_metadata = active_asset.metadata
|
2021-09-23 14:43:21 +02:00
|
|
|
return asset_metadata.active_tag in range(len(asset_metadata.tags))
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
2023-09-19 14:41:34 +02:00
|
|
|
active_asset = context.asset
|
|
|
|
asset_metadata = active_asset.metadata
|
2021-09-23 14:43:21 +02:00
|
|
|
tag = asset_metadata.tags[asset_metadata.active_tag]
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
|
2021-09-23 14:43:21 +02:00
|
|
|
asset_metadata.tags.remove(tag)
|
|
|
|
asset_metadata.active_tag -= 1
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
2021-07-02 10:40:19 +02:00
|
|
|
class ASSET_OT_open_containing_blend_file(Operator):
|
|
|
|
"""Open the blend file that contains the active asset"""
|
|
|
|
|
|
|
|
bl_idname = "asset.open_containing_blend_file"
|
|
|
|
bl_label = "Open Blend File"
|
|
|
|
bl_options = {'REGISTER'}
|
|
|
|
|
|
|
|
_process = None # Optional[subprocess.Popen]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
2023-09-19 14:41:34 +02:00
|
|
|
asset = getattr(context, "asset", None)
|
2021-07-02 10:40:19 +02:00
|
|
|
|
2023-09-19 14:41:34 +02:00
|
|
|
if not asset:
|
2021-07-02 10:40:19 +02:00
|
|
|
cls.poll_message_set("No asset selected")
|
|
|
|
return False
|
2023-09-19 14:41:34 +02:00
|
|
|
if asset.local_id:
|
2021-07-02 10:40:19 +02:00
|
|
|
cls.poll_message_set("Selected asset is contained in the current file")
|
|
|
|
return False
|
2024-07-07 17:21:55 +02:00
|
|
|
# This could become a built-in query, for now this is good enough.
|
|
|
|
if asset.full_library_path.endswith(".asset.blend"):
|
|
|
|
cls.poll_message_set(
|
2025-01-14 12:46:40 +11:00
|
|
|
"Selected asset is contained in a file managed by the asset system, manual edits should be avoided",
|
|
|
|
)
|
2024-07-07 17:21:55 +02:00
|
|
|
return False
|
2021-07-02 10:40:19 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
def execute(self, context):
|
2023-09-19 14:41:34 +02:00
|
|
|
asset = context.asset
|
2021-07-02 10:40:19 +02:00
|
|
|
|
2023-09-19 14:41:34 +02:00
|
|
|
if asset.local_id:
|
2021-07-02 10:40:19 +02:00
|
|
|
self.report({'WARNING'}, "This asset is stored in the current blend file")
|
|
|
|
return {'CANCELLED'}
|
|
|
|
|
2023-09-19 14:41:34 +02:00
|
|
|
asset_lib_path = asset.full_library_path
|
2021-07-02 10:40:19 +02:00
|
|
|
self.open_in_new_blender(asset_lib_path)
|
|
|
|
|
|
|
|
wm = context.window_manager
|
|
|
|
self._timer = wm.event_timer_add(0.1, window=context.window)
|
|
|
|
wm.modal_handler_add(self)
|
|
|
|
|
|
|
|
return {'RUNNING_MODAL'}
|
|
|
|
|
|
|
|
def modal(self, context, event):
|
|
|
|
if event.type != 'TIMER':
|
|
|
|
return {'PASS_THROUGH'}
|
|
|
|
|
|
|
|
if self._process is None:
|
|
|
|
self.report({'ERROR'}, "Unable to find any running process")
|
|
|
|
self.cancel(context)
|
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
|
|
returncode = self._process.poll()
|
|
|
|
if returncode is None:
|
|
|
|
# Process is still running.
|
|
|
|
return {'RUNNING_MODAL'}
|
|
|
|
|
|
|
|
if returncode:
|
2024-04-27 16:02:36 +10:00
|
|
|
self.report({'WARNING'}, rpt_("Blender sub-process exited with error code {:d}").format(returncode))
|
2021-07-02 10:40:19 +02:00
|
|
|
|
2021-11-23 18:40:31 +01:00
|
|
|
if bpy.ops.asset.library_refresh.poll():
|
|
|
|
bpy.ops.asset.library_refresh()
|
2021-07-02 10:40:19 +02:00
|
|
|
|
|
|
|
self.cancel(context)
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
def cancel(self, context):
|
|
|
|
wm = context.window_manager
|
|
|
|
wm.event_timer_remove(self._timer)
|
|
|
|
|
|
|
|
def open_in_new_blender(self, filepath):
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
cli_args = [bpy.app.binary_path, str(filepath)]
|
|
|
|
self._process = subprocess.Popen(cli_args)
|
|
|
|
|
|
|
|
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
classes = (
|
|
|
|
ASSET_OT_tag_add,
|
|
|
|
ASSET_OT_tag_remove,
|
2021-07-02 10:40:19 +02:00
|
|
|
ASSET_OT_open_containing_blend_file,
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
)
|