Blender to Godot shape keys

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my name is Brian Carey and I want to build a video game today we're gonna learn how to use shape keys we're gonna figure out shape keys in blender 2.8 and we're gonna figure out how to shoot that shape key data from blender over into the Godot game engine we're gonna learn what shape keys are how to use them how to control them what they can do what they can't do how to export them over into Godot and how to control that shape key with a script my name is Brian Carey and I am the savvy barbarian [Music] so today is all about shape keys so we're gonna start in blender and we're gonna end over in the Godot game engine Jake keys are very useful they're one of your animation tools the one you probably are most familiar with is using armatures to control animation and the other one however is shape keys you usually use shape keys for things like morphing objects from one thing into another for example when you're picking out your characters face at the beginning of the video game and you're in Skyrim and you're trying to build your hero or build the hot chick and you're adjusting the distance of the eyes and changing the shape of the mouth they're using shape keys this is how they do that and this is where we're gonna show you today this is blender we're using 2.82 aid and we might as well start with the starter cube and his name is Jeffrey and I've added a little extra geometry as you can see here at least I hope you can see the lines as YouTube's tends to to create degrade the video a little bit so what we're gonna do is we're gonna change Jeffrey from a cube into a pyramid and maybe we'll add an extra shape key too just to see how that works shape keys are actually pretty simple all you need to do is come over here to this little vertex tab and give that a click and there's a section here called shape keys so shape keys are basically where you're going to start with an object where all the vertices are in one configuration and you're going to finish where and all the vertices have moved or all or some of the vertices have moved to a new orientation so we're gonna take a snapshot of what this object looks like now right now we go into edit mode we can see I've just have a couple extra vertices here but I have the basic cube and when I go over to shape keys all I gotta do is click this here plus button and that is gonna add something called the basis now the basis is kind of blenders way of holding the starter data like where did all my vertices start they're all starting here they're all starting in this in this basis so it's gonna keep track of where all your vertices are and then we're gonna make changes based on this so the trick is you want to click this plus symbol a second time and once we click that we're gonna end up with another thing called key one so now we have got basis and we've got key one we're gonna change key one and we're gonna rename that to peer amid and now we got a pyramid now if I'm if I have this selected if I have basis selected and then I go into edit mode any changes that I made here are going to be part of the new and permanent shape so this is kind of the the neutral position the neutral face on your character the starting position of your morphing object so to speak so what we want to do is make sure that pyramid is selected and not basis now any changes that we'd be that we're gonna make are going to be applied to this pyramid shaped key and we'll leave our basis alone so I'm going to go into a pyramid here I'm going to select let's just say it's select all most of the top row of these vertices I'm gonna front view now drag those down and we'll drag that down a little bit more so it looks roughly like that it's not perfect but sometimes like leave edit mode you can see it's like my changes are gone because I'm actually still looking at the basis so my pyramid here has this 0 next to it and this is the value so the value here as I drift this from 0 to 1 and where that is is this is the minimum ranges set to 0 and the maximum range is 1 as I go from 0 to 1 you can see I'm shifting from my basis shape to my key one that happening pyramid to my pyramid shape and it's just about that easy now just for fun let's make a second shape key on this same object and see what happens I'm gonna start with the basis again and I'm gonna click + one more time and this time instead of leaving this key to will call this will call this floor right so I'll make the floor bigger so we're gonna do is with floor selected and not basis I'll go into edit mode and I'm gonna select this bottom face and I'm just gonna scale that out a little bit see what happens scale okay and that's it now when I come back into object mode as you can see my changes are stored in floor and I'm back looking at my basis again when I show what is in my value here for floor you can see there's my changes for floor if I select pyramid and change the value I can see I've got a pyramid in fact I can have them both on at the same time I can have them at different points in their values to make new shapes and then if use this little arrow right there you can actually create new shapes if you want where'd that go new shape from mix we could save this as a whole new shape key if we wanted to so I've got these two shapes here I've got the pyramid and I've got the floor now one thing this is a mistake that I made early on and a lot of people do that they get confused with how shape Keys really work each vertice in this object is gonna start at its location in base and it is going to move to its final location depending on how far your value is in the shape key that you're applying to it so let me jump over to another another object here so here here is another Jeffry this is this is gonna be fake Jeffry this isn't the the one we were just working on well export that one to go down in just a moment so let me add a few loop cuts here to give that a little bit more geometry and then I'm just gonna select the top face now what we're gonna do is we're gonna start this off with same as we did before we're gonna create a basis and then we're gonna keep it create a shape key and the shape key were going to be calling that twist right and so this is this is an interesting limitation of shape keys and you'll want to be aware of this so if we go into edit mode and we've got twist selected first we reading the shape key we're not editing the basis am I gonna top view I'm just gonna rotate the face 90 degrees turn that on with some influence on the other layers so you can see that's doing just what I want and it looks like I've twisted this thing just right and so that's my shape key so now let's test this out a little bit when I adjust the value and go from my shape keys from my basis to my twist you can see it looks pretty good but something's a little bit wrong when you look at this top face look at the size of this face look at the size of the square when I adjust this value and start to apply my shape key twist you see the square is actually getting smaller it's full size and then it's getting smaller and then it gets bigger again what's happening there you see we wanted this to do is to start let's just focus in on this one vertex we wanted this particular vertex we rotated at 90 degrees and we wanted it to rotate out like this and land right here at this end position but that's not what's happening what's actually happening is this vertex is moving in in a deadly straight line from here to here now watch this once again as I adjust the value of the shape key watch that watch this vertex right here it's moving not out in a curve it's moving in a straight line from point A to point B and that's why the shape key seems to be doing some strange things shape keys don't actually do rotation the vertex is gonna move in a straight line from its starting basis wherever that vertex was in its starting position to its final position however far along you are in the value so if you can get that to spin the way you want you can get that to spin like a record if you'd like to but you're not doing it with shape keys you'll be doing that with an armature because when you use a shape key it does not rotate okay so we'll jump back here to our original one here where we have Jeffrey is changing from the basis and we've got this this pyramid shape that he can do and we've also got this this floor shape down here that he can do now we're going to export that into the Godot game engine and here's how we're gonna do that step one do not use the colada or better colada exporter that is not the way any longer preferred method now is to use the gltf exporter so we're gonna do file export and select gltf 2.0 from the list this guy right here if this side panel isn't here you need to press the N key and that will open up this panel typically I like to use the embedded instead of binary it tends to bring over my materials a lot better I'm going to include only my selected object my transform here I'm gonna use leave Y up checked if you want to know more about that I mentioned that a little bit in the previous video so I'm gonna have a little link up here at the top corner and I'll probably put a link in the show notes so if you want to see what that's all about but short version is if that's not checked your object will make it over to Godot but it'll be flopped over on its side 90 degrees this is actually really critical here this apply modifiers is it's not implemented great so what's gonna happen is if you check this box it will apply modifiers like say your mirror modifier or your bevel modifier or whatever the other modifiers that you have but for some reason and I don't yet know if this is a blender thing or GL tf2 thing or if this is a Godot thing but somebody along the lines thinks that shape keys are a modifier shape keys are not a modifier they're an animation tool they're not even in the modifiers list so if you have apply modifiers turned on and a shape key turned on your shape key is broken like it'll come over into Godot but you won't actually be able to use that so I can demonstrate that I'm gonna create a new project real quick and I'm gonna call it kill me so I remember to delete this later create the folder I'm gonna pick opengl ss3 and create it okay I've got a project so in blender I'm gonna turn on my pyramid and I'll give that a value of one and then I'll go ahead and do file export GL tf2 so in blender I'm gonna export this to this new project folder that I've made and it's gonna be called jeffrey cube gltf I'm gonna click export and then when I go over into Godot so here in Godot here is my jeffrey cube gltf so this is the file that blender exported for me I give that a click and of course I select open anyways and you can see there's my pyramid and what it's done is it has applied the shape key so if I go to the mesh and then I go over and look at this I've got some new things here on here under shape keys there's my floor and there's my pyramid now my pyramids it at a scale of 1 so it looks like it's already turned on the trick is I can't actually turn it off it just doesn't work I can slide this and slide this up and down all day long and it doesn't do a thing so that's the problem when you're in blender if you apply the modifiers when you do the export it's going to totally ruin your shape key so let's head back over into blender real quick and this time we're gonna do the exact same thing we did before we still have our object selected we'll do file export GL tf2 and we're gonna do everything exactly the same except for an our geometry we're gonna turn off apply modifiers do not apply modifiers I suggest that you apply the modifiers yourself before you do this export and don't trust the exporter to apply the modifiers for you it's better if you have a lot of modifiers you might want to apply them in a certain order to make sure that they come over the way that you want and then you don't have to rely on this just leave it off most of the time we'll flip back over into Godot and this time we'll close and reopen that don't save I'm gonna just make sure that that rien ports re-import and reopen open anyways now it's still there but when I go to my mesh you can see it's it's a one because it was a one when we saved it in blender when we exported it our shape keys value was set to a 1 and it respected that but now when I switch this value of this pyramid I can actually turn that on and off I can edit my other shape key as well when I change the value it respects them both I can do variations in whatever I want so that worked exactly the way that it's supposed to so the next trick is how we're going to control this in code we might want to go into a script and actually be able to change this in code and actually alter these values so let's have a peek at that right now first thing I need to do is stop playing with the gltf format so I'm gonna save the scene save seen as and I'll call it jeffrey cube dot t sen the text scene format that Godot provides us so I'll go ahead and click Save and then I'm gonna close out of my gltf version and I'm gonna open my t SCM version and this is what I'm gonna use from this point forward that gltf version it's just for transferring the data from blender over into gota and then we never want to use it again so I'm gonna go into Geoffrey's parent object here the spatial object and I'm gonna click this little object right here this icon to create a new script so I'm gonna go ahead and click create and then we're gonna see if we can figure out how to edit Geoffrey and move him from the square into the pyramid anytime we want to the object that we're working on is Geoffrey here and it's the mesh is where these blend shapes are being stored so the pyramid if I float over this for a moment it shows me blend underscore shapes slash pyramid we need to remember that you know would be really cool is if you could just like control click or click and drag that or something and just drop that path right into your script wouldn't it be cool I don't think you can do that if somebody knows how to do that show me otherwise may the Lords of Godot add that feature someday so we're gonna go into this script and we're gonna we're gonna change us based on whether or not we hit the spacebar so we'll verify what we're gonna hit here worth the inputs so pride if I go to project and project settings and go to the input map tab you can see if I hit the space key that is going to send Godot the user interface except so I'm gonna press space and it's gonna send except to Godot so we'll add a function called input and that is going to we're gonna want to check and see if we've pressed that spacebar so we'll say if input dot is action pressed and the thing we've chosen is accept so we'll put that in there so if we've hit the spacebar then we need to do something now what I want to do is check the value of this so this pyramid for example let's do the pyramid blend underscore shapes slash pyramid I'm only going to come back here three more times because I can't remember it blend blend blend underscore shapes slash pyramid alright so we'll go back to our script and we're gonna say I don't know we need a variable Bob Bob is a terrible name for a variable never use that so Bob is going to be equal to and we're gonna do is we're just gonna use the get command we're gonna say get and actually not gonna get it off of this level we need to get it off of Jeff read-only so we dump that real quick so we will say Jeffrey and then we'll say get and then we will say lend my needs being quotes quote blend underscore shapes slash here amid okay did I get that right blend underscore shape slash pyramid was blend underscore shapes slash pyramid alright how to make sure I spelled that right now this is gonna work right so Bob is equal to whatever value is being stored there and the value that's being stored there it's gonna be a 0 or 1 right pyramid can be a 0 or 1 or anywhere in between so back to the script what we're gonna say is if Bob equals 0 then we're gonna do something otherwise we're gonna do something else so the thing that we're gonna do is we are going to see if Bob is 0 that means the pyramid is the shape key is basically off then we are going to now use the set command that's probably the easiest way for us to access that value so we're just gonna say Jeffrey dot set and then we're gonna give it the exact same string that we did before I'll just copy it real quick cuz I'm lazy and lazy is a good thing because it makes you find easier ways to do things so set this is the parameter that we're gonna change and we'll do comma and then we need to provided value so then we're gonna say you're equal to a 1 so if Bob which is the value in the shape key if this is a zero then we'll set it to a 1 I'm gonna copy all of that otherwise Jeffrey is going to be equal to a zero so in theory if I type this right when we run this we'll hit the spacebar and when I do it's gonna switch back and forth between a pyramid and a cube well to save this real quick oh I forgot the one of the most important things and that is you've got to actually have a world with a camera and a light and I did none of those things so let's do that real quick so we'll make a new we've seen a new 3d scene and we'll call this place world this is real fast so we'll just add a camera and we will give that a little bit more space in the negative Z direction and we'll also add a light directional light that sounds good I'll just get it out of the way and maybe you rotate that down a little bit now we're gonna select the world and then I'm going to select the link button here and I'm now gonna select the gltf version I'm going to select the TSC n version the goat version that we've got the script attached to once we give that a click we need just my camera real quick and now we run this we should have something to actually look at let's save our scene I'm gonna call this world that T Sen and like this up and see what happens so here's our object if I hit the spacebar it turns into a pyramid and I hit it again turns back into a cube so it's doing we wanted we are accessing our shape key from Jeffrey on the mesh we're accessing our shape Pete here that's pyramid and everything's going to plan now it looks it looks terrible so I think in the next video I'm gonna show you how to make it more from one shape to another over time so we're gonna be learning about tweens next and godot tweens are pretty cool and I think they warrant a little bit of their own video because there's there's a lot to them you can do very powerful tool and people don't use them enough in their homegrown video games but they can really add a lot of professional polish so all we did obviously was switch back and forth but tweens are coming up next so stay tuned for that next video what over already are you kidding did you get a chance to ohh oh my chair just broke again why does that keep happening before you go do me a solid and click like and subscribe down at the bottom this is a new channel and it's just incredibly helpful for me to come up even show in search results if you if you were to give a like and subscribe and hit the bell icon so you're notified of videos when they come out you want to see some more I should save some some videos up here and over there give that a look and I will see you next time this is Bryan Carey reminding you to be a scholar and a barbarian [Music]
Info
Channel: Savvy Barbarian
Views: 2,894
Rating: undefined out of 5
Keywords: how to, savvy, barbarian, savvy barbarian, gltf, gltf2, blender, blender guru, godot, godot guru, linux gamer, indie games, indie game dev, foss, linux, ubuntu, debian, 3d assets, modeling, import, export, blender to godot, godot import 3d model, godot import assets, blender 2.8, blender 2.82a, godot 3, tutorial, godot workflow, workflow, workflow hell, 3d modeling, shape keys, shapekeys, tips and tricks, godot import, blender export, import from blender, blender godot shape keys
Id: HTzo7ZxDDkk
Channel Id: undefined
Length: 23min 44sec (1424 seconds)
Published: Wed May 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.