
This commit introduces the first version of an exporter to Pixar's Universal Scene Description (USD) format. Reviewed By: sergey, LazyDodo Differential Revision: https://developer.blender.org/D6287 - The USD libraries are built by `make deps`, but not yet built by install_deps.sh. - Only experimental support for instancing; by default all duplicated objects are made real in the USD file. This is fine for exporting a linked-in posed character, not so much for thousands of pebbles etc. - The way materials and UV coordinates and Normals are exported is going to change soon. - This patch contains LazyDodo's fixes for building on Windows in D5359. == Meshes == USD seems to support neither per-material nor per-face-group double-sidedness, so we just use the flag from the first non-empty material slot. If there is no material we default to double-sidedness. Each UV map is stored on the mesh in a separate primvar. Materials can refer to these UV maps, but this is not yet exported by Blender. The primvar name is the same as the UV Map name. This is to allow the standard name "st" for texture coordinates by naming the UV Map as such, without having to guess which UV Map is the "standard" one. Face-varying mesh normals are written to USD. When the mesh has custom loop normals those are written. Otherwise the poly flag `ME_SMOOTH` is inspected to determine the normals. The UV maps and mesh normals take up a significant amount of space, so exporting them is optional. They're still enabled by default, though. For comparison: a shot of Spring (03_035_A) is 1.2 GiB when exported with UVs and normals, and 262 MiB without. We probably have room for optimisation of written UVs and normals. The mesh subdivision scheme isn't using the default value 'Catmull Clark', but uses 'None', indicating we're exporting a polygonal mesh. This is necessary for USD to understand our normals; otherwise the mesh is always rendered smooth. In the future we may want to expose this choice of subdivision scheme to the user, or auto-detect it when we actually support exporting pre-subdivision meshes. A possible optimisation could be to inspect whether all polygons are smooth or flat, and mark the USD mesh as such. This can be added when needed. == Animation == Mesh and transform animation are now written when passing `animation=True` to the export operator. There is no inspection of whether an object is actually animated or not; USD can handle deduplication of static values for us. The administration of which timecode to use for the export is left to the file-format-specific concrete subclasses of `AbstractHierarchyIterator`; the abstract iterator itself doesn't know anything about the passage of time. This will allow subclasses for the frame-based USD format and time-based Alembic format. == Support for simple preview materials == Very simple versions of the materials are now exported, using only the viewport diffuse RGB, metallic, and roughness. When there are multiple materials, the mesh faces are stored as geometry subset and each material is assigned to the appropriate subset. If there is only one material this is skipped. The first material if any) is always applied to the mesh itself (regardless of the existence of geometry subsets), because the Hydra viewport doesn't support materials on subsets. See https://github.com/PixarAnimationStudios/USD/issues/542 for more info. Note that the geometry subsets are not yet time-sampled, so it may break when an animated mesh changes topology. Materials are exported as a flat list under a top-level '/_materials' namespace. This inhibits instancing of the objects using those materials, so this is subject to change. == Hair == Only the parent strands are exported, and only with a constant colour. No UV coordinates, no information about the normals. == Camera == Only perspective cameras are supported for now. == Particles == Particles are only written when they are alive, which means that they are always visible (there is currently no code that deals with marking them as invisible outside their lifespan). Particle-system-instanced objects are exported by suffixing the object name with the particle's persistent ID, giving each particle XForm a unique name. == Instancing/referencing == This exporter has experimental support for instancing/referencing. Dupli-object meshes are now written to USD as references to the original mesh. This is still very limited in correctness, as there are issues referencing to materials from a referenced mesh. I am still committing this, as it gives us a place to start when continuing the quest for proper instancing in USD. == Lights == USD does not directly support spot lights, so those aren't exported yet. It's possible to add this in the future via the UsdLuxShapingAPI. The units used for the light intensity are also still a bit of a mystery. == Fluid vertex velocities == Currently only fluid simulations (not meshes in general) have explicit vertex velocities. This is the most important case for exporting velocities, though, as the baked mesh changes topology all the time, and thus computing the velocities at import time in a post-processing step is hard. == The Building Process == - USD is built as monolithic library, instead of 25 smaller libraries. We were linking all of them as 'whole archive' anyway, so this doesn't affect the final file size. It does, however, make life easier with respect to linking order, and handling upstream changes. - The JSON files required by USD are installed into datafiles/usd; they are required on every platform. Set the `PXR_PATH_DEBUG` to any value to have the USD library print the paths it uses to find those files. - USD is patched so that it finds the aforementioned JSON files in a path that we pass to it from Blender. - USD is patched to have a `PXR_BUILD_USD_TOOLS` CMake option to disable building the tools in its `bin` directory. This is sent as a pull request at https://github.com/PixarAnimationStudios/USD/pull/1048
829 lines
25 KiB
Python
829 lines
25 KiB
Python
# ##### 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 2
|
|
# 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, write to the Free Software Foundation,
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
#
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
# <pep8 compliant>
|
|
import bpy
|
|
from bpy.types import Header, Menu, Panel
|
|
|
|
class TOPBAR_HT_upper_bar(Header):
|
|
bl_space_type = 'TOPBAR'
|
|
|
|
def draw(self, context):
|
|
region = context.region
|
|
|
|
if region.alignment == 'RIGHT':
|
|
self.draw_right(context)
|
|
else:
|
|
self.draw_left(context)
|
|
|
|
def draw_left(self, context):
|
|
layout = self.layout
|
|
|
|
window = context.window
|
|
screen = context.screen
|
|
|
|
TOPBAR_MT_editor_menus.draw_collapsible(context, layout)
|
|
|
|
layout.separator()
|
|
|
|
if not screen.show_fullscreen:
|
|
layout.template_ID_tabs(
|
|
window, "workspace",
|
|
new="workspace.add",
|
|
menu="TOPBAR_MT_workspace_menu",
|
|
)
|
|
else:
|
|
layout.operator(
|
|
"screen.back_to_previous",
|
|
icon='SCREEN_BACK',
|
|
text="Back to Previous",
|
|
)
|
|
|
|
def draw_right(self, context):
|
|
layout = self.layout
|
|
|
|
window = context.window
|
|
screen = context.screen
|
|
scene = window.scene
|
|
|
|
# If statusbar is hidden, still show messages at the top
|
|
if not screen.show_statusbar:
|
|
layout.template_reports_banner()
|
|
layout.template_running_jobs()
|
|
|
|
# Active workspace view-layer is retrieved through window, not through workspace.
|
|
layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
|
|
|
|
row = layout.row(align=True)
|
|
row.template_search(
|
|
window, "view_layer",
|
|
scene, "view_layers",
|
|
new="scene.view_layer_add",
|
|
unlink="scene.view_layer_remove")
|
|
|
|
|
|
class TOPBAR_PT_tool_settings_extra(Panel):
|
|
"""
|
|
Popover panel for adding extra options that don't fit in the tool settings header
|
|
"""
|
|
bl_idname = "TOPBAR_PT_tool_settings_extra"
|
|
bl_region_type = 'HEADER'
|
|
bl_space_type = 'TOPBAR'
|
|
bl_label = "Extra Options"
|
|
|
|
def draw(self, context):
|
|
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
|
|
layout = self.layout
|
|
|
|
# Get the active tool
|
|
space_type, mode = ToolSelectPanelHelper._tool_key_from_context(context)
|
|
cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
|
|
item, tool, _ = cls._tool_get_active(context, space_type, mode, with_icon=True)
|
|
if item is None:
|
|
return
|
|
|
|
# Draw the extra settings
|
|
item.draw_settings(context, layout, tool, extra=True)
|
|
|
|
|
|
class TOPBAR_PT_tool_fallback(Panel):
|
|
bl_space_type = 'VIEW_3D'
|
|
bl_region_type = 'HEADER'
|
|
bl_label = "Layers"
|
|
bl_ui_units_x = 8
|
|
|
|
def draw(self, context):
|
|
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
|
|
layout = self.layout
|
|
|
|
tool_settings = context.tool_settings
|
|
ToolSelectPanelHelper.draw_fallback_tool_items(layout, context)
|
|
if tool_settings.workspace_tool_type == 'FALLBACK':
|
|
tool = context.tool
|
|
ToolSelectPanelHelper.draw_active_tool_fallback(context, layout, tool)
|
|
|
|
|
|
class TOPBAR_PT_gpencil_layers(Panel):
|
|
bl_space_type = 'VIEW_3D'
|
|
bl_region_type = 'HEADER'
|
|
bl_label = "Layers"
|
|
bl_ui_units_x = 14
|
|
|
|
@classmethod
|
|
def poll(cls, context):
|
|
if context.gpencil_data is None:
|
|
return False
|
|
|
|
ob = context.object
|
|
if ob is not None and ob.type == 'GPENCIL':
|
|
return True
|
|
|
|
return False
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
gpd = context.gpencil_data
|
|
|
|
# Grease Pencil data...
|
|
if (gpd is None) or (not gpd.layers):
|
|
layout.operator("gpencil.layer_add", text="New Layer")
|
|
else:
|
|
self.draw_layers(context, layout, gpd)
|
|
|
|
def draw_layers(self, context, layout, gpd):
|
|
row = layout.row()
|
|
|
|
col = row.column()
|
|
layer_rows = 10
|
|
col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index",
|
|
rows=layer_rows, sort_reverse=True, sort_lock=True)
|
|
|
|
gpl = context.active_gpencil_layer
|
|
if gpl:
|
|
srow = col.row(align=True)
|
|
srow.prop(gpl, "blend_mode", text="Blend")
|
|
|
|
srow = col.row(align=True)
|
|
srow.prop(gpl, "opacity", text="Opacity", slider=True)
|
|
srow.prop(gpl, "mask_layer", text="",
|
|
icon='MOD_MASK' if gpl.mask_layer else 'LAYER_ACTIVE')
|
|
|
|
srow = col.row(align=True)
|
|
srow.prop(gpl, "use_solo_mode", text="Show Only On Keyframed")
|
|
|
|
col = row.column()
|
|
|
|
sub = col.column(align=True)
|
|
sub.operator("gpencil.layer_add", icon='ADD', text="")
|
|
sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
|
|
|
|
gpl = context.active_gpencil_layer
|
|
if gpl:
|
|
sub.menu("GPENCIL_MT_layer_context_menu", icon='DOWNARROW_HLT', text="")
|
|
|
|
if len(gpd.layers) > 1:
|
|
col.separator()
|
|
|
|
sub = col.column(align=True)
|
|
sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
|
|
sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
|
|
|
|
col.separator()
|
|
|
|
sub = col.column(align=True)
|
|
sub.operator("gpencil.layer_isolate", icon='HIDE_OFF', text="").affect_visibility = True
|
|
sub.operator("gpencil.layer_isolate", icon='LOCKED', text="").affect_visibility = False
|
|
|
|
|
|
class TOPBAR_MT_editor_menus(Menu):
|
|
bl_idname = "TOPBAR_MT_editor_menus"
|
|
bl_label = ""
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
|
|
if context.area.show_menus:
|
|
layout.menu("TOPBAR_MT_app", text="", icon='BLENDER')
|
|
else:
|
|
layout.menu("TOPBAR_MT_app", text="Blender")
|
|
|
|
layout.menu("TOPBAR_MT_file")
|
|
layout.menu("TOPBAR_MT_edit")
|
|
|
|
layout.menu("TOPBAR_MT_render")
|
|
|
|
layout.menu("TOPBAR_MT_window")
|
|
layout.menu("TOPBAR_MT_help")
|
|
|
|
|
|
class TOPBAR_MT_app(Menu):
|
|
bl_label = "Blender"
|
|
|
|
def draw(self, _context):
|
|
layout = self.layout
|
|
|
|
layout.operator("wm.splash")
|
|
|
|
layout.separator()
|
|
|
|
layout.menu("TOPBAR_MT_app_support")
|
|
|
|
layout.separator()
|
|
|
|
layout.menu("TOPBAR_MT_app_about")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("preferences.app_template_install", text="Install Application Template...")
|
|
|
|
|
|
class TOPBAR_MT_file(Menu):
|
|
bl_label = "File"
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
|
|
layout.operator_context = 'INVOKE_AREA'
|
|
layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
|
|
layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
|
|
layout.menu("TOPBAR_MT_file_open_recent")
|
|
layout.operator("wm.revert_mainfile")
|
|
layout.menu("TOPBAR_MT_file_recover")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator_context = 'EXEC_AREA' if context.blend_data.is_saved else 'INVOKE_AREA'
|
|
layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
|
|
|
|
layout.operator_context = 'INVOKE_AREA'
|
|
layout.operator("wm.save_as_mainfile", text="Save As...")
|
|
layout.operator_context = 'INVOKE_AREA'
|
|
layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True
|
|
|
|
layout.separator()
|
|
|
|
layout.operator_context = 'INVOKE_AREA'
|
|
layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
|
|
layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
|
|
layout.menu("TOPBAR_MT_file_previews")
|
|
|
|
layout.separator()
|
|
|
|
layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
|
|
layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
|
|
|
|
layout.separator()
|
|
|
|
layout.menu("TOPBAR_MT_file_external_data")
|
|
|
|
layout.separator()
|
|
|
|
layout.menu("TOPBAR_MT_file_defaults")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("wm.quit_blender", text="Quit", icon='QUIT')
|
|
|
|
|
|
class TOPBAR_MT_file_new(Menu):
|
|
bl_label = "New File"
|
|
|
|
@staticmethod
|
|
def app_template_paths():
|
|
import os
|
|
|
|
template_paths = bpy.utils.app_template_paths()
|
|
|
|
# expand template paths
|
|
app_templates = []
|
|
for path in template_paths:
|
|
for d in os.listdir(path):
|
|
if d.startswith(("__", ".")):
|
|
continue
|
|
template = os.path.join(path, d)
|
|
if os.path.isdir(template):
|
|
# template_paths_expand.append(template)
|
|
app_templates.append(d)
|
|
|
|
return sorted(app_templates)
|
|
|
|
@staticmethod
|
|
def draw_ex(layout, _context, *, use_splash=False, use_more=False):
|
|
layout.operator_context = 'INVOKE_DEFAULT'
|
|
|
|
# Limit number of templates in splash screen, spill over into more menu.
|
|
paths = TOPBAR_MT_file_new.app_template_paths()
|
|
splash_limit = 5
|
|
|
|
if use_splash:
|
|
icon = 'FILE_NEW'
|
|
show_more = len(paths) > (splash_limit - 1)
|
|
if show_more:
|
|
paths = paths[:splash_limit - 2]
|
|
elif use_more:
|
|
icon = 'FILE_NEW'
|
|
paths = paths[splash_limit - 2:]
|
|
show_more = False
|
|
else:
|
|
icon = 'NONE'
|
|
show_more = False
|
|
|
|
# Draw application templates.
|
|
if not use_more:
|
|
props = layout.operator("wm.read_homefile", text="General", icon=icon)
|
|
props.app_template = ""
|
|
|
|
for d in paths:
|
|
props = layout.operator(
|
|
"wm.read_homefile",
|
|
text=bpy.path.display_name(d),
|
|
icon=icon,
|
|
)
|
|
props.app_template = d
|
|
|
|
layout.operator_context = 'EXEC_DEFAULT'
|
|
|
|
if show_more:
|
|
layout.menu("TOPBAR_MT_templates_more", text="...")
|
|
|
|
def draw(self, context):
|
|
TOPBAR_MT_file_new.draw_ex(self.layout, context)
|
|
|
|
|
|
class TOPBAR_MT_file_recover(Menu):
|
|
bl_label = "Recover"
|
|
|
|
def draw(self, _context):
|
|
layout = self.layout
|
|
|
|
layout.operator("wm.recover_last_session", text="Last Session")
|
|
layout.operator("wm.recover_auto_save", text="Auto Save...")
|
|
|
|
|
|
class TOPBAR_MT_file_defaults(Menu):
|
|
bl_label = "Defaults"
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
prefs = context.preferences
|
|
|
|
layout.operator_context = 'INVOKE_AREA'
|
|
|
|
if any(bpy.utils.app_template_paths()):
|
|
app_template = prefs.app_template
|
|
else:
|
|
app_template = None
|
|
|
|
if app_template:
|
|
layout.label(text=bpy.path.display_name(app_template, has_ext=False))
|
|
|
|
layout.operator("wm.save_homefile")
|
|
props = layout.operator("wm.read_factory_settings")
|
|
if app_template:
|
|
props.app_template = app_template
|
|
|
|
|
|
class TOPBAR_MT_app_about(Menu):
|
|
bl_label = "About"
|
|
|
|
def draw(self, _context):
|
|
layout = self.layout
|
|
|
|
layout.operator("wm.url_open_preset", text="Release Notes", icon='URL').type = 'RELEASE_NOTES'
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("wm.url_open_preset", text="Blender Website", icon='URL').type = 'BLENDER'
|
|
layout.operator("wm.url_open_preset", text="Credits", icon='URL').type = 'CREDITS'
|
|
|
|
layout.separator()
|
|
|
|
layout.operator(
|
|
"wm.url_open", text="License", icon='URL',
|
|
).url = "https://www.blender.org/about/license/"
|
|
|
|
|
|
class TOPBAR_MT_app_support(Menu):
|
|
bl_label = "Support Blender"
|
|
|
|
def draw(self, _context):
|
|
layout = self.layout
|
|
|
|
layout.operator("wm.url_open_preset", text="Development Fund", icon='FUND').type = 'FUND'
|
|
|
|
layout.separator()
|
|
|
|
layout.operator(
|
|
"wm.url_open", text="Blender Store", icon='URL',
|
|
).url = "https://store.blender.org"
|
|
|
|
|
|
class TOPBAR_MT_templates_more(Menu):
|
|
bl_label = "Templates"
|
|
|
|
def draw(self, context):
|
|
bpy.types.TOPBAR_MT_file_new.draw_ex(self.layout, context, use_more=True)
|
|
|
|
|
|
class TOPBAR_MT_file_import(Menu):
|
|
bl_idname = "TOPBAR_MT_file_import"
|
|
bl_label = "Import"
|
|
|
|
def draw(self, _context):
|
|
if bpy.app.build_options.collada:
|
|
self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)")
|
|
if bpy.app.build_options.alembic:
|
|
self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
|
|
|
|
|
|
class TOPBAR_MT_file_export(Menu):
|
|
bl_idname = "TOPBAR_MT_file_export"
|
|
bl_label = "Export"
|
|
|
|
def draw(self, context):
|
|
if bpy.app.build_options.collada:
|
|
self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
|
|
if bpy.app.build_options.alembic:
|
|
self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
|
|
if bpy.app.build_options.usd and context.preferences.experimental.use_usd_exporter:
|
|
self.layout.operator("wm.usd_export", text="Universal Scene Description (.usd, .usdc, .usda)")
|
|
|
|
|
|
class TOPBAR_MT_file_external_data(Menu):
|
|
bl_label = "External Data"
|
|
|
|
def draw(self, _context):
|
|
layout = self.layout
|
|
|
|
icon = 'CHECKBOX_HLT' if bpy.data.use_autopack else 'CHECKBOX_DEHLT'
|
|
layout.operator("file.autopack_toggle", icon=icon)
|
|
|
|
layout.separator()
|
|
|
|
pack_all = layout.row()
|
|
pack_all.operator("file.pack_all")
|
|
pack_all.active = not bpy.data.use_autopack
|
|
|
|
unpack_all = layout.row()
|
|
unpack_all.operator("file.unpack_all")
|
|
unpack_all.active = not bpy.data.use_autopack
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("file.make_paths_relative")
|
|
layout.operator("file.make_paths_absolute")
|
|
layout.operator("file.report_missing_files")
|
|
layout.operator("file.find_missing_files")
|
|
|
|
|
|
class TOPBAR_MT_file_previews(Menu):
|
|
bl_label = "Data Previews"
|
|
|
|
def draw(self, _context):
|
|
layout = self.layout
|
|
|
|
layout.operator("wm.previews_ensure")
|
|
layout.operator("wm.previews_batch_generate")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("wm.previews_clear")
|
|
layout.operator("wm.previews_batch_clear")
|
|
|
|
|
|
class TOPBAR_MT_render(Menu):
|
|
bl_label = "Render"
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
|
|
rd = context.scene.render
|
|
|
|
layout.operator("render.render", text="Render Image", icon='RENDER_STILL').use_viewport = True
|
|
props = layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION')
|
|
props.animation = True
|
|
props.use_viewport = True
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("sound.mixdown", text="Render Audio...")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("render.view_show", text="View Render")
|
|
layout.operator("render.play_rendered_anim", text="View Animation")
|
|
|
|
layout.separator()
|
|
|
|
layout.prop(rd, "use_lock_interface", text="Lock Interface")
|
|
|
|
|
|
class TOPBAR_MT_edit(Menu):
|
|
bl_label = "Edit"
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
|
|
layout.operator("ed.undo")
|
|
layout.operator("ed.redo")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("ed.undo_history", text="Undo History...")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("screen.repeat_last")
|
|
layout.operator("screen.repeat_history", text="Repeat History...")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("screen.redo_last", text="Adjust Last Operation...")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("wm.search_menu", text="Operator Search...", icon='VIEWZOOM')
|
|
|
|
layout.separator()
|
|
|
|
# Mainly to expose shortcut since this depends on the context.
|
|
props = layout.operator("wm.call_panel", text="Rename Active Item...")
|
|
props.name = "TOPBAR_PT_name"
|
|
props.keep_open = False
|
|
|
|
layout.operator("wm.batch_rename")
|
|
|
|
layout.separator()
|
|
|
|
# Should move elsewhere (impacts outliner & 3D view).
|
|
tool_settings = context.tool_settings
|
|
layout.prop(tool_settings, "lock_object_mode")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
|
|
|
|
|
|
class TOPBAR_MT_window(Menu):
|
|
bl_label = "Window"
|
|
|
|
def draw(self, context):
|
|
import sys
|
|
|
|
layout = self.layout
|
|
|
|
layout.operator("wm.window_new")
|
|
layout.operator("wm.window_new_main")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("screen.workspace_cycle", text="Next Workspace").direction = 'NEXT'
|
|
layout.operator("screen.workspace_cycle", text="Previous Workspace").direction = 'PREV'
|
|
|
|
layout.separator()
|
|
|
|
layout.prop(context.screen, "show_statusbar")
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("screen.screenshot")
|
|
|
|
if sys.platform[:3] == "win":
|
|
layout.separator()
|
|
layout.operator("wm.console_toggle", icon='CONSOLE')
|
|
|
|
if context.scene.render.use_multiview:
|
|
layout.separator()
|
|
layout.operator("wm.set_stereo_3d")
|
|
|
|
|
|
class TOPBAR_MT_help(Menu):
|
|
bl_label = "Help"
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
|
|
show_developer = context.preferences.view.show_developer_ui
|
|
|
|
layout.operator("wm.url_open_preset", text="Manual", icon='HELP').type = 'MANUAL'
|
|
|
|
layout.operator(
|
|
"wm.url_open", text="Tutorials", icon='URL',
|
|
).url = "https://www.blender.org/tutorials"
|
|
layout.operator(
|
|
"wm.url_open", text="Support", icon='URL',
|
|
).url = "https://www.blender.org/support"
|
|
|
|
layout.separator()
|
|
|
|
layout.operator(
|
|
"wm.url_open", text="User Communities", icon='URL',
|
|
).url = "https://www.blender.org/community/"
|
|
layout.operator(
|
|
"wm.url_open", text="Developer Community", icon='URL',
|
|
).url = "https://devtalk.blender.org"
|
|
|
|
layout.separator()
|
|
|
|
layout.operator(
|
|
"wm.url_open", text="Python API Reference", icon='URL',
|
|
).url = bpy.types.WM_OT_doc_view._prefix
|
|
|
|
if show_developer:
|
|
layout.operator(
|
|
"wm.url_open", text="Developer Documentation", icon='URL',
|
|
).url = "https://wiki.blender.org/wiki/Main_Page"
|
|
|
|
layout.operator("wm.operator_cheat_sheet", icon='TEXT')
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("wm.url_open_preset", text="Report a Bug", icon='URL').type = 'BUG'
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("wm.sysinfo")
|
|
|
|
|
|
class TOPBAR_MT_file_context_menu(Menu):
|
|
bl_label = "File Context Menu"
|
|
|
|
def draw(self, _context):
|
|
layout = self.layout
|
|
|
|
layout.operator_context = 'INVOKE_AREA'
|
|
layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
|
|
layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
|
|
layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
|
|
|
|
layout.separator()
|
|
|
|
layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
|
|
layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
|
|
|
|
|
|
class TOPBAR_MT_workspace_menu(Menu):
|
|
bl_label = "Workspace"
|
|
|
|
def draw(self, _context):
|
|
layout = self.layout
|
|
|
|
layout.operator("workspace.duplicate", text="Duplicate", icon='DUPLICATE')
|
|
if len(bpy.data.workspaces) > 1:
|
|
layout.operator("workspace.delete", text="Delete", icon='REMOVE')
|
|
|
|
layout.separator()
|
|
|
|
layout.operator("workspace.reorder_to_front", text="Reorder to Front", icon='TRIA_LEFT_BAR')
|
|
layout.operator("workspace.reorder_to_back", text="Reorder to Back", icon='TRIA_RIGHT_BAR')
|
|
|
|
layout.separator()
|
|
|
|
# For key binding discoverability.
|
|
props = layout.operator("screen.workspace_cycle", text="Previous Workspace")
|
|
props.direction = 'PREV'
|
|
props = layout.operator("screen.workspace_cycle", text="Next Workspace")
|
|
props.direction = 'NEXT'
|
|
|
|
|
|
# Grease Pencil Object - Primitive curve
|
|
class TOPBAR_PT_gpencil_primitive(Panel):
|
|
bl_space_type = 'VIEW_3D'
|
|
bl_region_type = 'HEADER'
|
|
bl_label = "Primitives"
|
|
|
|
def draw(self, context):
|
|
settings = context.tool_settings.gpencil_sculpt
|
|
|
|
layout = self.layout
|
|
# Curve
|
|
layout.template_curve_mapping(settings, "thickness_primitive_curve", brush=True)
|
|
|
|
|
|
# Grease Pencil Fill
|
|
class TOPBAR_PT_gpencil_fill(Panel):
|
|
bl_space_type = 'VIEW_3D'
|
|
bl_region_type = 'HEADER'
|
|
bl_label = "Advanced"
|
|
|
|
def draw(self, context):
|
|
paint = context.tool_settings.gpencil_paint
|
|
brush = paint.brush
|
|
gp_settings = brush.gpencil_settings
|
|
|
|
layout = self.layout
|
|
# Fill
|
|
row = layout.row(align=True)
|
|
row.prop(gp_settings, "fill_factor", text="Resolution")
|
|
if gp_settings.fill_draw_mode != 'STROKE':
|
|
row = layout.row(align=True)
|
|
row.prop(gp_settings, "show_fill", text="Ignore Transparent Strokes")
|
|
row = layout.row(align=True)
|
|
row.prop(gp_settings, "fill_threshold", text="Threshold")
|
|
|
|
|
|
# Only a popover
|
|
class TOPBAR_PT_name(Panel):
|
|
bl_space_type = 'TOPBAR' # dummy
|
|
bl_region_type = 'HEADER'
|
|
bl_label = "Rename Active Item"
|
|
bl_ui_units_x = 14
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
|
|
# Edit first editable button in popup
|
|
def row_with_icon(layout, icon):
|
|
row = layout.row()
|
|
row.activate_init = True
|
|
row.label(icon=icon)
|
|
return row
|
|
|
|
mode = context.mode
|
|
scene = context.scene
|
|
space = context.space_data
|
|
space_type = None if (space is None) else space.type
|
|
found = False
|
|
if space_type == 'SEQUENCE_EDITOR':
|
|
layout.label(text="Sequence Strip Name")
|
|
item = getattr(scene.sequence_editor, "active_strip")
|
|
if item:
|
|
row = row_with_icon(layout, 'SEQUENCE')
|
|
row.prop(item, "name", text="")
|
|
found = True
|
|
elif space_type == 'NODE_EDITOR':
|
|
layout.label(text="Node Label")
|
|
item = context.active_node
|
|
if item:
|
|
row = row_with_icon(layout, 'NODE')
|
|
row.prop(item, "label", text="")
|
|
found = True
|
|
else:
|
|
if mode == 'POSE' or (mode == 'WEIGHT_PAINT' and context.pose_object):
|
|
layout.label(text="Bone Name")
|
|
item = context.active_pose_bone
|
|
if item:
|
|
row = row_with_icon(layout, 'BONE_DATA')
|
|
row.prop(item, "name", text="")
|
|
found = True
|
|
elif mode == 'EDIT_ARMATURE':
|
|
layout.label(text="Bone Name")
|
|
item = context.active_bone
|
|
if item:
|
|
row = row_with_icon(layout, 'BONE_DATA')
|
|
row.prop(item, "name", text="")
|
|
found = True
|
|
else:
|
|
layout.label(text="Object Name")
|
|
item = context.object
|
|
if item:
|
|
row = row_with_icon(layout, 'OBJECT_DATA')
|
|
row.prop(item, "name", text="")
|
|
found = True
|
|
|
|
if not found:
|
|
row = row_with_icon(layout, 'ERROR')
|
|
row.label(text="No active item")
|
|
|
|
|
|
classes = (
|
|
TOPBAR_HT_upper_bar,
|
|
TOPBAR_MT_file_context_menu,
|
|
TOPBAR_MT_workspace_menu,
|
|
TOPBAR_MT_editor_menus,
|
|
TOPBAR_MT_app,
|
|
TOPBAR_MT_app_about,
|
|
TOPBAR_MT_app_support,
|
|
TOPBAR_MT_file,
|
|
TOPBAR_MT_file_new,
|
|
TOPBAR_MT_file_recover,
|
|
TOPBAR_MT_file_defaults,
|
|
TOPBAR_MT_templates_more,
|
|
TOPBAR_MT_file_import,
|
|
TOPBAR_MT_file_export,
|
|
TOPBAR_MT_file_external_data,
|
|
TOPBAR_MT_file_previews,
|
|
TOPBAR_MT_edit,
|
|
TOPBAR_MT_render,
|
|
TOPBAR_MT_window,
|
|
TOPBAR_MT_help,
|
|
TOPBAR_PT_tool_fallback,
|
|
TOPBAR_PT_tool_settings_extra,
|
|
TOPBAR_PT_gpencil_layers,
|
|
TOPBAR_PT_gpencil_primitive,
|
|
TOPBAR_PT_gpencil_fill,
|
|
TOPBAR_PT_name,
|
|
)
|
|
|
|
if __name__ == "__main__": # only for live edit.
|
|
from bpy.utils import register_class
|
|
for cls in classes:
|
|
register_class(cls)
|