-
Notifications
You must be signed in to change notification settings - Fork 49
Add Blender 2.80 support (this will resolve #361) #466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jasperges
wants to merge
35
commits into
getavalon:master
Choose a base branch
from
jasperges:add-blender28-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1a7911d
Add Blender 2.80 support
jasperges baf6c49
Some style changes and cleanup
jasperges d83484c
Fix: renamed open_file and save_file in __all__
jasperges 4e2ab62
Fix: fix line lenght + unused var
jasperges 0fbe9aa
Merge remote-tracking branch 'upstream/master' into add-blender28-sup…
jasperges a1bf183
Style fix
jasperges ee2954b
Import QtWidgets with namespace
jasperges 809e53d
Style changes
jasperges aafbf85
Merge branch 'master' into add-blender28-support
jasperges 16bd950
Merge branch 'master' into add-blender28-support
jasperges d3a4865
Merge branch 'master' into add-blender28-support
jasperges 4be0f7c
Merge remote-tracking branch 'upstream/master' into add-blender28-sup…
jasperges ea5b85f
Merge branch 'master' into add-blender28-support
jasperges 5bc3bb3
Add bpy.context wrapper
jasperges bf54052
Use bpy.context wrapper in TestApp
jasperges 0570d60
Add `bpy.context` wrapper
jasperges 834371b
Revert adding the bpy wrapper
jasperges 2433fdc
Add library function to get selected objects
jasperges 0a655ea
Make Avalon imports relative
jasperges d2ec489
Add note to change to `bpy.app.timers`
jasperges a78b312
Remove hardcoded 'scene' directory
jasperges 3d46168
Use `bpy.app.timers` and remove test app
jasperges 0840537
Cleanup
jasperges cc205ba
Merge branch 'master' into blender28-dev
jasperges d14d97b
Merge branch 'master' into blender28-dev
jasperges 23331c4
Refactor to find_submodule (needed after merge of #501)
jasperges 37c2fa8
Remove teardown function
jasperges 12633c7
Make sure only 1 timer is registered for Qt apps
jasperges 5019142
Fix check for self._window
jasperges cff9ad6
Exclude blender from tests
jasperges 945c7a3
Merge branch 'master' into blender28-dev
jasperges a320eb3
Rename avalon_setup → setup_avalon and add comment about sys.excepthook
jasperges 33d6e0c
Merge branch 'master' into blender28-dev
jasperges fe4bd5c
Remove unneeded `config` variable from blender (un)install
jasperges fd10091
Remove unused import + fix indentation
jasperges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Public API | ||
|
||
Anything that isn't defined here is INTERNAL and unreliable for external use. | ||
|
||
""" | ||
|
||
from .pipeline import ( | ||
install, | ||
uninstall, | ||
Creator, | ||
Loader, | ||
ls, | ||
publish, | ||
containerise, | ||
) | ||
|
||
from .workio import ( | ||
open_file, | ||
save_file, | ||
current_file, | ||
has_unsaved_changes, | ||
file_extensions, | ||
work_root, | ||
) | ||
|
||
from .lib import ( | ||
lsattr, | ||
lsattrs, | ||
read, | ||
maintained_selection, | ||
get_selection, | ||
# unique_name, | ||
) | ||
|
||
|
||
__all__ = [ | ||
"install", | ||
"uninstall", | ||
"Creator", | ||
"Loader", | ||
"ls", | ||
"publish", | ||
"containerise", | ||
|
||
# Workfiles API | ||
"open_file", | ||
"save_file", | ||
"current_file", | ||
"has_unsaved_changes", | ||
"file_extensions", | ||
"work_root", | ||
|
||
# Utility functions | ||
"maintained_selection", | ||
"lsattr", | ||
"lsattrs", | ||
"read", | ||
"get_selection", | ||
# "unique_name", | ||
] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
"""Standalone helper functions.""" | ||
|
||
import contextlib | ||
from typing import Dict, List, Union | ||
|
||
import bpy | ||
|
||
from ..lib import logger | ||
from . import pipeline | ||
|
||
|
||
def imprint(node: bpy.types.bpy_struct_meta_idprop, data: Dict): | ||
r"""Write `data` to `node` as userDefined attributes | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Arguments: | ||
node: Long name of node | ||
data: Dictionary of key/value pairs | ||
|
||
Example: | ||
>>> import bpy | ||
>>> def compute(): | ||
... return 6 | ||
... | ||
>>> bpy.ops.mesh.primitive_cube_add() | ||
>>> cube = bpy.context.view_layer.objects.active | ||
>>> imprint(cube, { | ||
... "regularString": "myFamily", | ||
... "computedValue": lambda: compute() | ||
... }) | ||
... | ||
>>> cube['avalon']['computedValue'] | ||
6 | ||
""" | ||
|
||
imprint_data = dict() | ||
|
||
for key, value in data.items(): | ||
if value is None: | ||
continue | ||
|
||
if callable(value): | ||
# Support values evaluated at imprint | ||
value = value() | ||
|
||
if not isinstance(value, (int, float, bool, str, list)): | ||
raise TypeError(f"Unsupported type: {type(value)}") | ||
|
||
imprint_data[key] = value | ||
|
||
pipeline.metadata_update(node, imprint_data) | ||
|
||
|
||
def lsattr(attr: str, | ||
value: Union[str, int, bool, List, Dict, None] = None) -> List: | ||
r"""Return nodes matching `attr` and `value` | ||
|
||
Arguments: | ||
attr: Name of Blender property | ||
value: Value of attribute. If none | ||
is provided, return all nodes with this attribute. | ||
|
||
Example: | ||
>>> lsattr("id", "myId") | ||
... [bpy.data.objects["myNode"] | ||
>>> lsattr("id") | ||
... [bpy.data.objects["myNode"], bpy.data.objects["myOtherNode"]] | ||
|
||
Returns: | ||
list | ||
""" | ||
|
||
return lsattrs({attr: value}) | ||
|
||
|
||
def lsattrs(attrs: Dict) -> List: | ||
r"""Return nodes with the given attribute(s). | ||
|
||
Arguments: | ||
attrs: Name and value pairs of expected matches | ||
|
||
Example: | ||
>>> lsattrs({"age": 5}) # Return nodes with an `age` of 5 | ||
# Return nodes with both `age` and `color` of 5 and blue | ||
>>> lsattrs({"age": 5, "color": "blue"}) | ||
|
||
Returns a list. | ||
|
||
""" | ||
|
||
# For now return all objects, not filtered by scene/collection/view_layer. | ||
matches = set() | ||
for coll in dir(bpy.data): | ||
if not isinstance( | ||
getattr(bpy.data, coll), | ||
bpy.types.bpy_prop_collection, | ||
): | ||
continue | ||
for node in getattr(bpy.data, coll): | ||
for attr, value in attrs.items(): | ||
avalon_prop = node.get(pipeline.AVALON_PROPERTY) | ||
if not avalon_prop: | ||
continue | ||
if (avalon_prop.get(attr) | ||
and (value is None or avalon_prop.get(attr) == value)): | ||
jasperges marked this conversation as resolved.
Show resolved
Hide resolved
|
||
matches.add(node) | ||
return list(matches) | ||
|
||
|
||
def read(node: bpy.types.bpy_struct_meta_idprop): | ||
"""Return user-defined attributes from `node`""" | ||
|
||
data = dict(node.get(pipeline.AVALON_PROPERTY)) | ||
|
||
# Ignore hidden/internal data | ||
data = { | ||
key: value | ||
for key, value in data.items() if not key.startswith("_") | ||
} | ||
|
||
return data | ||
|
||
|
||
def get_selection() -> List[bpy.types.Object]: | ||
"""Return the selected objects from the current scene.""" | ||
return [obj for obj in bpy.context.scene.objects if obj.select_get()] | ||
|
||
|
||
@contextlib.contextmanager | ||
def maintained_selection(): | ||
r"""Maintain selection during context | ||
|
||
Example: | ||
>>> with maintained_selection(): | ||
... # Modify selection | ||
... bpy.ops.object.select_all(action='DESELECT') | ||
>>> # Selection restored | ||
""" | ||
|
||
previous_selection = get_selection() | ||
previous_active = bpy.context.view_layer.objects.active | ||
try: | ||
yield | ||
finally: | ||
# Clear the selection | ||
for node in get_selection(): | ||
node.select_set(state=False) | ||
if previous_selection: | ||
for node in previous_selection: | ||
try: | ||
node.select_set(state=True) | ||
except ReferenceError: | ||
# This could happen if a selected node was deleted during | ||
# the context. | ||
logger.exception("Failed to reselect") | ||
continue | ||
try: | ||
bpy.context.view_layer.objects.active = previous_active | ||
except ReferenceError: | ||
# This could happen if the active node was deleted during the | ||
# context. | ||
logger.exception("Failed to set active object.") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.