"Blender and 3D Art anyone can make using Python" - Sam Bishop (PyCon AU 2023)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign hello and welcome to the final section of pycon we'll be beginning with a talk by Sam Bishop who is going to be telling us a bit about blender and 3D art they're a professional software developer an amateur rocker scientist which I'm told is less impressive than it sounds they love python Jango cats working on software and Hardware and everything space take it away Sam all right [Applause] okay so I'm Sam Bishop I'm a freelance software developer and a consultant as well I'm also working on space robots at Tetra orbital I am here to talk about blender and python contact details are on the bottom of the slide there so if you want to reach out to me you can get to me there and we'll start with the obvious question what is blender for those of you who aren't familiar blender is a one of the older open source projects initial work started with ton Rosenthal in-house engineer at Neo Geo which was a Dutch Animation studio and this work started in the December of 1993 the first working build he had that had any kind of feature at all was in 94 in 95 they had their first useful version of it and the world got its first visual look at blender in 1998 when they released it as shareware for the SGI Erics operating system which is probably something that some of you have never even heard of um but after the various Tech bubble things happened around the end of the year 2000 some bankruptcies happen some corporate trading happens and in 2002 ton is successful in spearheading a public campaign to gather funds and open source the project by buying out the intellectual property and interestingly the name blender actually comes from a song by Swiss band yellow from their album baby which was used by Neo Geo way back in the day as part of showreel um and since being open sourced blender has grown significantly over those 21 years and it has gained notoriety with things like its open movie projects which have developed a significant Show reel of blender's capability for itself and highlighting what can be done with open source software and helping push forward new releases of blender several of these movie projects have involved developing brand new features for rent and green and other capabilities blender did not have at the start of the decision to make that movie one of the ones that isn't on that slide involves doing rotoscoping and real-time visual effects overlays there are many features that blender has pushed forward or significantly improved as part of this active use cycle where they decide we are doing this and they have to make it work the third one in the top right there cindel was actually sintel sorry it was actually a test bed for the Alpha version of blender 2.8 and so they were using the development preview for the entire development of this movie making sure that every feature that they added and changed in 2.8 was going to be useful for real users when they released and it's a pretty impressive thing for them to have been doing this for 21 years and blender has a lot in it and I've only got 30 minutes so I'm going to try and not leave you feeling like this has happened I'm going to try and actually leave you feeling like you could pick this up and do things because current blender has a lot in it I was not kidding blender has a absolute ludicrous amount of tools inside of it it has tools for modeling sculpting rigging animation visual effects a non-linear video editor like Adobe Premiere is actually inside of blender it has multiple rendering engines it has physics simulations for rigid bodies cloths fluids hair and fur particles and smoke and in addition to all of the 3D capabilities you can see right there it has 2D Vector animation capabilities and editing in a 3D World so you can actually take your 2D vectors and move them around in 3D to do all kinds of crazy awesome stuff and you just saw a customization of the rendering there when they did the wonderful sort of Van Gogh effect and it is just an insanely powerful package and it is also insanely flexible in a moment you're going to see customizations to the UI and extensions to the physics engine where people have started pushing it and customizing it and scripting it and in that case adding new widgets to control it like a gear stiff to make that swipe turn into a road through a whole dynamic tree of nodes they've customized and overall it is one of the most powerful software packages I have ever worked with you know it is insane and it has a python interface which you can see right there that is a capability that does not come stock he has written his own script there and that is actually puppeting that model in real time using that Xbox 360 controller like a virtual Puppeteer powered by python and speaking of that python let's have a look at what python is inside of blender so python in blender is actually a full python installation just like if you went and downloaded python 310 off buyer.org and actually had it installed by itself it has its own complete python environment an interpreter site packages it comes bundled with several major python packages from Pi Pi it does ship with numpy and it has a built-in version of that and a number of other libraries which help it do significant amounts of data processing that it needs to do thousands of geometry pieces all the time when it's doing things for your animations or rendering or anything else you do with it and it has its own C apis which are bundled up into a python package that is the blender API which they pre-bundle into that python environment when they ship you blender and so there is a lot going on but at the end of the day when you actually try to use it as a user there are three ways you use it as a user you're either using it via scripts or packages or add-ons add-ons are basically the blender word for a plugin we'll get to some of those in a moment the packages are just like Pi Pi just like any other python environment you can download and install I'll show you a thing to help with that later it is a little bit clunky to try and do it by hand but it's not too hard to use just like any other python packages once you know the right place to do it but let's start with the scripting because it's the easiest so I've got a really simple script here now this script is just going to do us a little four by four grid of Cubes it's a nice simple demo it just shows two for loops and a really simple one blender API call there the bpi.ops.mesh dot primitive it just Chucks a cube in the world so I'm going to Chuck that script into blender which will look something like that and then I'm going to run it and get something like that which is a very simple demo it's not visually interesting but it does show the core principle you just Chuck it in run it and there you go so let's do something more complicated let's try and make it more visually interesting what we'll do is we'll make a bigger grid and we'll rotate them so that way we'll actually have a preceding effect where all of them move so that they have corners aimed towards the origin and we get a nice kind of a mosaic effect we'll take some trigonometry at the bottom of that existing Loop we'll make it a bigger grid and we'll grab that script and we'll Chuck it into blender again it'll look something just like that and then when you run it what you'll do is you'll get something that looks more like that so you can see that as you approach that zero point on those Crossing axes it aligns towards the center and we get kind of this Mosaic progression effect it's again a fairly simple script but you can see how that small addition at the end of that little bit of trigonometry gives us something visual and you can sort of start to think well what else can I do okay well let's take this up to a third dimension we're on a 3D package after all let's do something 3D rather than just kind of a 2d looking thing so we've got another layer to our for Loop we've got three dimensions in play now and instead of aiming the corners because it looks a bit better in 3D to do it this way I switched over to aiming one of the sides towards the middle so rather than having sort of awkward edges and Corners sticking out it's a bit easy to see what it looks like when the sides are just aimed towards the middle and again we'll take the simple script it's just got one more nested slightly different trigonometry at the end we'll grab that script we'll pop it into blender we'll run it and then we get something like that which is a five by five grid and we've got that spread out in space you can see the inside there you can see how they're running through and how they all as it turns around angles and aims them all in there again very simple script did not take long to sit down and just whip this up very basic nothing complicated now let's try and make something a little bit more visually interesting these have been very basic demos I'm just chucking cubes in the world and it's not the most interesting thing to look at so let's try and make something more visually interesting we'll take the same thing and modify it again so what we'll do this time is we'll skip anything on the inside of that Cube because it is a cube that we're making at the end of the day it's a grid of points in three-dimensional space but it's full let's get rid of the inside we don't need it and then what we'll do is instead of using cubes we'll use cones we'll get a more interesting outside look and what we'll do as well is we'll move it so that it squished together and then that squish together will overlap and give us like a solid object that we could do something like say 3D print or put it in the world and make it look like a real object and we'll take that slightly modified script which is otherwise pretty much the same as the one we just did the big spread out one but a couple of parameters modified and one thing swapped for another so we'll Chuck it in blender again and what we get when we run it is we get a thwomp sort of looking spiky Cube thing which is definitely more visually interesting than something that we had earlier but again it's just a very small modification to a series of iterations and it's easy to sort of play around with and start getting a feel for how you can make more complicated things with these scripts I've got a script demo at the end that really shows off how you can stack these things and that's at the end so let's go into the add-ons so CA is a node-based geometry plugin an add-on technically um that I wasn't actually able to run on Apple silicon so it is a great one I've used it before I've had to grab the gifts off their GitHub repo show off the capabilities um it is a useful set of over 250 nodes that you can link together and I'll explain this nodes and linking stuff in another in the next slide next demo bit and those allow you to build a series of events changed together that take data in process that data produce outputs to the end of that chain that give you various forms of geometry you can see in a couple of those gifts if your eyesight's good enough that you're manipulating these properties and things change about the geometry in the world because you have direct access to those properties just like if you were running a script going in and calling the function with a different variable except those are accessible to you in the UI with nice and easy to manipulate sliders so showing this off a bit better will be sphere shock now spur shock is named spiritual because that's Russian for grasshopper and it's a plug-in for blender which was designed to create a similar capability and it is the older of these two plugins a similar capability to the node-based editing feature of rhino which is a CAD software package a proprietary one that most people haven't used but it is a very powerful way of linking everything together in this visual processing way and they just basically copied the name and picked a different language so it gives us these nodes and you can see them down the bottom and what I've done is I've started with the simplest one I can think of give me a box and then I asked it to go and make that box a rendered object in the world with a nice little pink pink plastic nice and simple uh now okay I've just got a box what can I do with it um let's bevel the edges of my box I've grabbed the bevel node I've chucked the bevel node into the script chain and then set some properties and it's beveled my box um okay it still looks pretty simple I've just rounded the corners off okay let's do something more a inset Chuck in the inset node and then perform an out inset which is a little funky until you understand the math behind it but it pulls these edges out and inserts them slightly and it gives us this kind of cut crystal looking effect which looked a lot nicer when I played around with it but it was a bit hard to see on the screen when I did it in like a translucent Crystal so I just stuck with the pink plastic but it's a good demonstration of how you can chain these things together quite simply and play around with them and manipulate them until you start to get something you like the look of now that's just the basics of using these kind of node-based tools where these two add-ons are interesting is that they have the ability to have python plugins inside of them so you can write Python scripts pull those into these two add-ons as nodes and make your own nodes with python so in this case here I've got a very simple demo I've got a python script this spershock attractor here I'm going to pass the data from that into a pipe and then I'm going to turn that pipe into a mesh with some properties there I've picked a bronze material just for example to keep it different can't keep making everything pink so I've got that script here and that's what that script looks like there's some stuff in the doc string at the top that tells spur shock what the inputs and outputs need to be and then there's just the script for the rest of the block there now when I load that in and I run that chain of nodes in searchok what I get is I get a little fractal attractor there rendered in bronze it's not fancy it's a fairly straightforward sort of application I just found a function that made some points in a line that I liked and chucked it in and made some stuff with it now that's one tiny example but there are more because you can build a whole library of these you can make a whole package of extensions to spurtshock and sawka based on this principle you can build your own library of functions for yourself and import them into blender for these plugins to use you can extend the plugins and there are existing extensions there are people who have made libraries already like spiritual open 3D and spiritual Beamish that have expanded the capability of spershock and given it more power than it has out of the box and that node-based editing can go a long way so what about getting some basic data in there there's been a couple of people this weekend talk about data visualization in 3D and various things like that so let's have a look at some of the data visualization options if you have a bunch of data and you think you could do something pretty with it in blender well there's multiple blad-ons and plugins again so here are three example ones these seem well supported they ran when I checked them blender plots blend database and data effects but I'll get back to burn to plots at the end but I'm going to demo blendfig which is yet another one so what I've gone is I've just used the same lorentz thing again because I had it handy and I'm like well yeah I can ask for more dots great more dots and then I've asked it to do a scatter plot so with that scatter plot down there at the end it's just going to do the rendering of our scatter plot now it looks pretty boring right now it's not the most interesting thing I think it looked better in bronze but it is more well defined so okay what can I do with that well I'm going to use blender's built-in equivalent just for chalk and saw car because after the success of these plugins the blender developers were like you know that's not a bad idea maybe we should have a thing that does that and so they it built their own and now we have three options on this table all of which have different capabilities and strengths and weaknesses there are things that you can do in Saw car that are not in blender built-in geometry nodes or in Search oxnodes and vice versa for all three so what I've done here just to show off these geometry nodes is I've just taken that mesh because what I got from the scatter plot was just a straight line of dots connected with you know lines and I've asked blender to treat it as a curve and then I've asked blender to take a stop shape from its default primitive box and turn that star shape into a pipe via extruding a curve with the mesh and then I've asked it to cover it in a like a blue edge light sort of cyberpunk sound texture looks kind of kind of when I get that it's kind of like a bit of a black hole kind of a collision sort of a look which looks a bit better when you kind of have less clutter around it um but these are just the tips of the iceberg there is so many plugins out there thousands on GitHub hundreds of thousands of scripts that have been written over the years there is an absolute mountain of content out there for blender um some of these are more useful to you as a beginner trying to get started and learn than others which is why these two are the first ones so open with IDE is a really tiny one script file you can just load it like a plugin and then you get a button that opens those scripts that I was demonstrating earlier in something like vs code so you can get intellisense autocomplete you can install the blender environment and it can actually know what those packages contain which makes it a lot easier to edit bigger scripts like the one at the end and then there's a script that you'll easily take care of pip installing for you because as I mentioned earlier that self-contained environment can be a little hard to work with sometimes especially if you have multiple copies of blender for some reason like having multiple long-term stable ones because say a plugin might not work which can happen in the open source world as we all know so having an easy way to not muck around and reliably go in and make sure that that version of blender has that particular python Library you want to use is a really handy thing to do so let's look at a few we can actually use again some of these are add-ons and some of these are packages that you would have to pip install their documentation covers that but I just wanted to show off a few really useful ones that you can play around with without needing to know the ins and outs of blender super well so there's geometry script which can automate creating those geometry nodes I showed earlier if you want to play around with building a big sequence of them you might want to make that repeatable so that you don't make a mistake when you blow it all the way and try and make it again so you can automate that Creation with this library then if you do play around with it by hand and you want to kind of reliably reproduce that well there's a library to go the other direction there's node to python which will take a set of nodes and turn them into Python scripts so you can play around in either direction and still keep these things for working out future versions there's things like a solar system simulator someone was like I can't want to make some stuff orbit but I don't really know how to animate it for that and I'm like well okay I'll do the physics and so they put in a kiplarian integrator and did all the physics there with some python libraries that they install as well and what you have is the ability to just Chuck objects into a blender environment give them the correct parameters and then blend it just orbits them for you you don't have to do any hard work it's nice and simple um and speaking of complicated things done simple molecular Dynamics and other visualization thing so you can load up a bunch of chemical data on say a smaller molecule or a complete protein as is visualized there in the GIF and it will do a full demonstration of that including using some math behind the scenes to work out when things should be moving around in sort of a random rounding motion like some of these things do apparently and that adds some of its own geometry nodes in there as well so another powerful plugin to do this kind of visualization of complicated information to a more simple version of the information there is things like a music visualization plugin so you can visualize music into your environment as either a background effect or tied into something else that's just one of their quick demos and again there are so many of these out there that once you start looking you'll probably find something that does what you kind of want or shows how you can start working it out yourself in particular there is an absolute plethora of procedural content generation plugins and add-ons for blender and not to mention how many of the various python libraries you could use to sort of Cobble together your own procedural generation tools as well this tree generator here I actually cover in more detail in a 2001 sorry 2021 pycon Au talk about procedural content generation which mentions a few other blender add-ons that can do procedural content as well and if you do get really into all of this and you do actually want to start showing off to the world how you're doing this all the time there's actually a Discord plugin so you can put your current what am I doing in blender into a Discord um and after showing all of those things I'm going to use a slightly more visually interesting demo because all the demos up to this point have been pretty simple I mean sure that your fractal with the blue was nice but I think we can go a little bit better with the time we have left so uh one final demo I'm going to pull in numpy and I'm going to use that blender plots Library I pointed out earlier because it does generate plots slightly differently to the other libraries which is useful for what I want to do in a moment and then I'm going to use the palatable Library which I've installed via Pi Pi which is a library full of plot gradients for when you're generating different plots and want to color all your data correctly so I've gone and pulled out one of their particular color gradients and I'm giving it a nice name so that I could play with it later and I'm chucking in a simple little helper function I use quite frequently to get myself pairs from an iterable so if I have one two three four it'll return a set of tuples to me so I've got one two two three three four handy sometimes when you want to kind of build lists of things like this so now I'm going to give myself another function that's going to Generate random points between two spheres so if I've got a big sphere and then a smaller sphere it'll give me a random distribution of dots in the space between them which you'll see what that's for in a second so it does a bunch of numpy stuff some trigonometry and it gives me those random points now I'm going to have to get some more information from those points I'm going to have to work out how to aim them somewhere so what I'm going to do is I'm going to do some more trigonometry with numpy and I'm going to work out how to rotate in the world for blender to aim something from that random Point towards a direction that I want to point it in and so we've got that function now added to the script here and then what we'll do is we'll tie them together so I'm going to generate a list of pairs of adjacent colors and that's just going to give me a nice little list of tuples then I'm going to get a list of how many things I want to put at each step of my script that's just a little step sequence of powers and then I'm going to get a list of Upper and Lower bounds for those spheres so that I get kind of a progressive stacking effect and then I'm just going to do a single for Loop here and I'm going to generate multiple plots I'm going to generate the points rotate them so that it knows where to go and then scatter plot them using that blender plot library to do the scatter plot and when I Chuck it all into blender and just hit the render button to see it with the preview I get this and it doesn't look particularly impressive in black and white but when you see how it turns out with the gradient I think it actually looks quite good uh and that was about two hours it wasn't particularly hard to work out how to put this together once I sort of realized I could do the scatter plot and muck around with the colors and just play around with it in the space it it can be pretty simple to start stacking the things you know into these kinds of contexts and coming up with really interesting things you like the look of so with all that in mind that's the last of the demo there and hopefully you don't feel like you've just watched a tutorial that skips the middle steps hopefully you do feel like you can actually try to you know start doing some of these things because these are fairly straightforward starting steps and there is of course time for questions [Applause] thank you Sam does anyone have a question oh and I do have it open in blender if you want to see it and actually see it fully in blender foreign that was great uh is there a limit to what uh sort of imports you can put in um is there capability for adding machine learning rights oh definitely there are a number of add-ons out there that do things like machine learning on data sets and one of the things that people have started doing is using machine learning to process the environment you saw there the what in that early video that was showing off the 3.6 release that show reel included someone who'd used a machine learning software package to emulate the van Gogh's style Isle of painting in the rendering layer so that the environment was done in regular geometry but when it was rendered out it kind of had that van Gogh swirly little line effects applied at the final rendering pass layer awesome cheers is it possible to uh from end to end Control Blender from a python script yes as in without like touching the interface at all yes just completely there's actually a full head loss mode oh perfect which gets a significant amount of use so it's it's not like a niche feature like the Chrome headless was for a while it it actually gets used extremely Often by people doing large renderings if you are doing a batch rendering for a movie you may be rendering thousands of frames what you'll do is you'll set up your automation pipeline to farm that job out and you'll use the blender command line interface to say render this particular frame from this file and so they do heavily use it and fully know that it works yeah yeah you could pass a script in and run the script from the outside generate this and then render it out if you were to add all the extra camera positioning information and set everything up correctly I didn't really want to show that because that kind of requires a lot of understanding of the way the 3D spaces work with stuff like rendering and textures and lighting and it's a bit more than I thought was sort of appropriate for 30 minute demo when you know something like this is actually quite straightforward to show but at the at the same time positioning a camera correctly in the world lighting it correctly and and showing all the detail can be you know significantly more tricky than just having it open and and being able to just sort of pan it around so that people can see how it's built up of the layers because you can see that the different layers get stacked together creating this sort of progressive effect as it sort of moves out through the stack again it was fairly straightforward to sort of Chuck together once I saw one of these libraries do a scatter plot um yeah more questions there's still some time one I can try and render a proper one um is there support for um sorry words hmm uh what was I asking it's gone um having like a time-based animations oh definitely to have it you know moving and animating yeah absolutely there was actually one of the slides had a video sorry a gif from one of those packages that has that kind of functionality built in uh let me just jump back to the presentation and I might be able to quickly jump to it without taking too much of the time that's left we should have further back here that one there is actually doing a time-based animation for the music passed in um as well as that one's doing it based on the data from the chemical information and the add-on here yeah there we go so the blender plots Library does actually have the capability of doing time-based animations in there as well so that and all the way back at the very early one on or car that one on the top right corner actually is doing it with the timeline running down the bottom so that is actually Computing some of those properties based on the current frame of the timeline set up so it's using that frame to determine some of the properties that it passes into the math so no no it really isn't because like I said blender has so many features inside of it that you you will routinely forget that it's got those things like I do have to keep remembering it has a full Adobe Premiere style non-linear video editor inside of it because why would it need that oh it needs that to composite a complete movie I think we've still got about two more minutes so feel feel free I'm enough for one more question do you know some examples of movies made with blender oh yeah yeah it was uh this slide right here uh they've done the more than these there's actually several extra ones um this was just the nine ones that fit prettiest when I sort of tried to find a set that looked nice on screen together they've done a number of these I think they're up to about 15 now these are all short movies uh the one in the middle was hoping to get enough funds raised to try and make a feature-length movie that didn't quite pan out but they definitely did make a absolutely spectacular set of fur shaders for that cheap [Music] really like you look at the difference in definition between the fur in the sheep in the center and the fur in the fuzzy animals in the top frame above it and and there's a significant Improvement in terms of being able to both artistically control the fur as well as have it be a higher definition and less shortcuts necessary to render it but again more rendering power with a more recent movie too so they kind of could cheat a little bit but yeah blender has a lot of these examples out there I believe it has been used at least in part in a number of major movies I don't have those memorized off the top of my head I just know I came across them in the list of examples um I wanted to more focus on ones that I knew wouldn't accidentally get any video de-listed from the internet because these are all Creative Commons licensed thank you Sam for this wonderful combination of programming and art um thank you here is your customary mug and thank you card
Info
Channel: PyCon AU
Views: 823
Rating: undefined out of 5
Keywords: SamBishop, pyconau, pyconau_2023
Id: IDhkJYAYJ2A
Channel Id: undefined
Length: 29min 4sec (1744 seconds)
Published: Thu Aug 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.