[Addon / Script] "Fake" Python-Based Modifier Stack (experimental)


I have been experimenting with a python-based modifier stack a bit in October 2017, idea behind it was to let C and Python modifiers interact in a “fake” stack. Might perhaps only work for small test cases, and the python scripts being used would need to be coupled with cython / cffi modules optionally to gain more performance (in theory).

Anyway, i got here a blend with a script / addon which provides the modifier stack (and for now only integrates Array and Subsurf and a generic Python modifier), its purely python based. There is also a test script which can be executed from the stack in the blend. See the instructions in the screenshot and in the blend.

Note, it is VERY experimental and has a couple of issues, like incorrect subsurfing when rendering for example.

py_modifierstack_test9.blend (609 KB)

Edit: Update, python modifier stack should contain now all existing C Modifiers and provide the proper Add Modifier Menu.

py_modifierstack_test10.blend (856 KB)

Interesting, blender3d needs a custom modifier stack system. thks

Thank you for exploring this!

The main script seems to work really well and it’s very promising. The only main issue is responsiveness - it does not update when modifiers are enabled/disabled, added before or after.

Also had an error here:

Few tests (that are relatively common issues when working with game assets):

Fill Holes:

Triangulate NGeons:

Works very well, easy and straightforward! Just have to manually press the refresh every time (@responsiveness)

Hi :slight_smile:

Well, the modifier scripts are required to have a main(), a draw(), a register() and an unregister() function. The main() function additionally must return a Mesh datablock. (since the main script expects this there and makes “working copies”, stores also the properties being defined for / in the modifier script etc.) Please have a look at the mod_translate.py script for an (approximate) structure. Also it might be perhaps troublesome if (arbitrary) operators are called in the modifier script… hmmm “simple” ones might work though. Alternatively you might use bmesh to alter the given object (access the mesh via ob.data and make a bmesh from it) directly. This way you are not restricted to functionality of operators.

The error (probably because there are no properties defined, necessary if the modifier script provides UI elements) and the “missing” mesh from main() prevent the automatic updates i think. Furthermore, if something goes wrong as last resort delete the object which carries the modifier stack, since this deletes some custom props and internal storage variables which track the last parameter values and mesh datablock names for example (for the “working copy”).

Edit: Hmmm looks like it works properly atm only in object mode.

Edit2: Here a couple of fixes, but “show in editmode” wont work here since I use different work meshes, and subsurf still displays the wrong subsurf level after rendering (enable / disable preview eye icon fixes it), but in general rendering should consider now the render camera icon and animated modifiers should work now too.

py_modifierstack_test12.blend (680 KB)