-
Notifications
You must be signed in to change notification settings - Fork 49
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
Blender Integration #361
Comments
Here's some implementation details I was thinking about. I mentioned doing some initial work already on the Avalon gitter here. Containers and Instances Using the new Blender 2.8 Collections as the object set-like container for loaded content and using them as the set for publish instances. Though I have started a discussion on custom properties on Collections as I wasn't able to completely get it to a user-friendly state. Avalon menu I was unable in Blender 2.8 to get the Avalon menu in the top menu bar (in the File Menu) so for now I pushed it into the View Menus, see: Pyblish QML + Blender Even though Pyblish doesn't have a Blender host integration it seemed to run fine on the first tries. See: Reference gitter conversation here Blender 2.8 + PyQt5 I have been unable so far to run PyQt5 stable inside Blender 2.8 (it's using Python 3.7) as it seems to hang the Blender UI and holds the main thread. I've been able to get it working without holding the UI but then it crashed on reopen or performing actions. This still needs further investigation. Reading over Blender forums it should be possible to operate Qt inside of Blender - albeit not super easy of the bat. |
Aside from listening in on the application quit signal; what else do you need PyQt for inside of Blender? I'd imagine we could find similar signals native to Blender and let Qt exist only external to Blender, like how it does from Maya. |
I think you're referring to the Pyblish QML logic as I mentioned PyQt5. But I was intending to run Qt for the Avalon tools like the Creator, Loader, and Scene Inventory (Manager). I went for PyQt5 since Blender is on Python 3.7 so I felt there was no need to use PyQt4 or PySide as PyQt5 could be pip installed to Python 3.7. |
- Shows Avalon menu in viewport, is able to run Pyblish QML. - Note that the code is not fully functional. - The Qt tools do not work yet, they hang Blender as they keep up the main thread.
I've pushed the current state of the Blender integration work so other coulds fiddle around if they wanted:
PyQt5 install for Blender 2.8 Note that Blender will need PyQt5 to even come close to starting Avalon tools. (Even for Pyblish QML as it will try to import Qt in the host to show a Splash Screen. This dependency could be removed/fixed in Pyblish QML but the dependency is currently there.)
Install avalon on Blender launch You'll need to set the For example, I've added this in the Blender
|
I am able to run a Qt interface without hanging Blender and both running in parallel. Here's an example of the code: class QtModalOperator(bpy.types.Operator):
"""A base class for Operators that run a Qt interface."""
def modal(self, context, event):
if self._app:
self._app.processEvents()
return {'PASS_THROUGH'}
return {"FINISHED"}
def execute(self, context):
"""Execute the Operator.
The child class must implement execute() and call super to trigger this
class' execute() at the beginning. The execute() method must finally
return {'RUNNING_MODAL"}
Note that the Qt code should *not* call QApplication.exec_() as it
seems that magically the Qt application already processes straight
away in Blender. Maybe due to:
https://stackoverflow.com/questions/28060218/where-is-pyqt-event
-loop-running
"""
from avalon.vendor.Qt import QtWidgets
self._app = QtWidgets.QApplication.instance()
if not self._app:
self._app = QtWidgets.QApplication(["blender"])
class CreatorOperator(QtModalOperator):
"""Launch Avalon Creator.."""
bl_idname = "object.avalon_creator"
bl_label = "Create.."
def execute(self, context):
# Initialize Qt operator execution
super(CreatorOperator, self).execute(context)
from ..tools import creator
creator.show()
return {'RUNNING_MODAL'} However, trying to access Blender's |
Gah, yes, you are right. Of course we need Avalon GUIs too. :)
You probably need to build it. Else you can get subtle and difficult-to-debug errors like that context error. Worst case you'll need to build not only PyQt but also Qt. :S It depends on how Blender was built, they need the same compiler version and flags throughout. The same is true for Maya. |
The context error is not related to Qt but I believe it's related to calling import bpy
context = bpy.context Which is invalid when "inside the context of the Operator" - if that makes sense? |
So I have made some very good progress regarding this - basically the UIs work without hanging Blender and I am able to use the Creator to create an instance and able to Load an Alembic through the pipeline too + show it in the Scene Inventory. Again, still a draft. Resolved Blender Qt hanging blender issuesTo get the Qt UIs to run they needed to trigger as modal operators, see here. Resolved Blender context is incorrect issueThe Note: Note that with the errors you are able to see them (just briefly) in the System Console that comes with Blender, so you are able to debug - but you need to restart Blender. I actually believe the same behavior happens when you run PyQt5 standalone in Python 3, and for example you raise an error from a method that is triggered by a QPushButton then it crashes the Python console - but I haven't checked. How to more explicitly get these errors to show and run it "safer" for developing purposes I am not sure. Again the current state of the code can be found here:
|
Actually, other people seem to confirm this PyQt5 behavior - see here and here. Using those workarounds Blender continues to "survive" and the errors are printed to the System Console. It's helpful at least for development/debugging even though according to those Stackoverflow answers it's bad practice. :) |
I suspect this isn't a crash, but a change in how exceptions are handled in PyQt5 under Python 3 versus 2. From what I understand, it's a change to the Edit: I had a look at those links you posted, and basically repeated what you already found out for yourself. :) Good to have a third opinion at least! |
Having a look at threading-related matters for Pyblish QML. For completeness, the issue relates to Pyblish QML running in a separate Python process, and communicate with Blender via The result is your plug-in and all of the calls made to Blender operates entirely in this separate thread. Blender, like Maya, Houdini, Nuke and pretty much any DCC I can think of, doesn't like being interacted with from a different thread than the so-called "main thread". The way Pyblish QML manages this in Maya and friends is via an application supplied, aptly named The problem isn't unique to Pyblish QML either; anything running in a thread, wanting to integrate without blocking user input, has the same problem. Looking here shows us one approach. In a nutshell:
It'd work, but is a little complicated. |
There was another discussion about running Qt interfaces in Blender on Avalon Gitter without locking up the Blender GUI |
Just a quick update on my progress. Running Avalon apps from within BlenderApp execution from within Blender seems to work fine for the most part. The apps don't block the Blender UI and also when you access
I didn't have time to thoroughly investigate the first 2 issues. I also don't consider them to be 'criticial', so I will leave them alone for now. Containers and InstancesJust like @BigRoy did here, I also use collections to store custom data for Avalon. As he found out on Blender Artists there is no simple way to make these available to the user, so they can be changed. You can register 'custom properties', but you have to know in advance what kind of information you will store. Doing it this way will make it very rigid and you will not be able to simply add studio specific properties. If you dynamically add a property (for example What I intend to do is add all the information to a 'dynamically assigned' ConfigI started to make a config based on Colorlbeed's config that integrates Blender 2.80. It's all very much work in progress and so far only used to test things and figure out how stuff could work. TestingIf you would like to see what I've done so far and give it a go, you can find it here. Reporting any issues or giving suggestions will be greatly appreciated! As a final remark: the next couple of weeks I won't be available. After that I plan to continue working on this. |
Just created a PR: #466 |
So far the use of Qt apps inside of Blender actually seem to work quite okay. But there are still some issues. The main issue is that (when I tested it quickly) it's totally unusable on macOS. That is quite unfortunate, but I expect most people are using Linux or Windows, so I will leave it alone for now. Furthermore there is a difference between Linux and Windows: in Windows only the Global Context is available if you do Another problem is how the Qt window is kept 'alive'. A modal operator is abused to trigger So in the planned documentation for the Blender part I would like to make it clear, that you should only expect to have the Global Context available. Some library functions can be added to 'ease the pain', for example for getting the selected objects. To do some quick testing with different methods, I made this snippet. Just save it, load it in the Script Editor in Blender and do Alt + p or press the Run Script button. Just make the changes you want and run it again. |
Just committed some changes (#466). The most important one is that instead of a timed modal operator I switched to using
So things are looking good as far as I am concerned. :) |
…fresh_bug Loader: asset refresh bug
Issue
Implement Blender as Avalon integration so that the tools can operate and prepare an example studio configuration to show a Creator + Publish + Loader action as initial setup.
If anyone knows anyone with a good Blender background or Blender + pipeline related experience I'd be happy to get in touch with them and ping them about some Blender workflow things.
I'm focusing currently on Blender 2.8+ (on beta now) and am working on this in my spare time.
The text was updated successfully, but these errors were encountered: