nView

The Blender Add-on that Taught Me to Be a Smart Programmer

Rewind to the summer of 2021. Someone shared with me a Blender tutorial on hiding parts of their scene to make the 3D viewport run faster. He asked for help to make it more automatic, so that:

Throughout an animation, only show the objects visible to the 3D camera.

I gave some suggestions to solve the problem. As we talked, I realized: wait, I know how to do this. I can code a Blender add-on to solve this.

This wouldn’t be that hard, right? 🙄

The Blessing of Automation

I started coding buttons, their settings, and a panel to put them on. High ambitions got the best of me. Code files grew long. Testing took longer. I worried about the all-too-easy possibility of (re)introducing bugs as I coded.

But a previous job of mine gave me a valuable idea: automated testing. Write some tests, run a script, and it tells me if all the tests passed. No manual testing.

Turns out, someone had beaten me to it, with a Python library called blender-addon-tester. It had some problems and requires more handholding than any developer would like.

But I got it working. And when it worked, boy, my productivity went through the roof.

Testing used to take an hour of checking all the use cases, from common to “I hope an artist wouldn’t think to use it this way”. But now, once tests are written, they are tested within seconds.

It’s saved me time - time and time again. I’ve implemented, tested, and packaged bugfixes within an hour of reading the customer issue. I could experiment with different implementations and immediately see if behavior has changed. All with full confidence that my changes weren’t breaking nView.

Immediate validation is invaluable to a programmer. That’s when coding really becomes creative.

The Error that Introduced nView V3

Fast forward to early 2023. nView is a well-oiled machine. It even had a couple of regular fans. But one bug report came in that changed everything: the redo panel didn’t work. Not fully, anyway.

In Blender, you don't have to fiddle with settings before you click a button. You click first. Then a "redo panel" pops up with the settings used. You can change them there and get an updated result. These settings are remembered the next time you press the button.

Except I made nView forget. I coded nView to overwrite those remembered settings with the settings from its panel, no matter what.

This wasn’t just an error. nView was going against Blender’s user experience guidelines (I know the page itself admits it’s a work in progress, but guidelines are there for a reason). Worse yet, other aspects of nView did too.

I realized nView needed some real change in its user experience, no, its workflow. Something that would make nView like an extension of Blender than scripts hiding in its own little bubble.

So this is what I did:

Decluttered the panel

I moved the properties out of the panel. I hadn’t realized how busy the panel was until I changed it. Here’s a comparison (notice the “Object Types” and “Camera” subpanels are collapsed and not showing their full size):

Yeah, 90% of the previous panel was just settings. But now, the new panel is so decluttered you’re actually okay with reading the text!

The Quest for Optimization

But I couldn’t convince customers to abandon the panel of settings if the operations were still slow. I had to improve performance.

I remembered an old joke: “the best way to optimize Python code is to not run it in Python.” But some Python libraries use other, faster languages under the hood to go fast, like numpy.

numpy is a Python math library. But it’s programmed by nerds - math nerds. I still don’t understand it. It has its own syntax, its own workflow.

But it’s fast. Ridiculously fast.

With help from Stack Overflow, I got some code samples working. I tried an optimization or two and ran my automated tests.

They finished - five times faster. And successfully. I couldn’t believe it.

If your code generates or manipulates lists of numbers, and it’s running slow enough to notice, use numpy! And when you understand it, let me know. I’d like to learn it too.

What would I have done differently?

I should have focused on the customer first with the user interface. Now, before any coding, I ask myself, “What buttons would the user like to press?” That question alone would have saved me so much time then.

Business school students are laughing. Customers are the focal point of everything in business. But as a developer, it’s so easy to get lost in loving the solution that you forget to prioritize the customers and their problems.

Since you’re still reading, check out the nView on the Blender Market. Enjoy!