Hello welcome to this tutorial um for how to make minecraft or a minecraft-like program of simulation uh using python and to make it very easy we’re using a 3d game engine called cena made by the brilliant peta amland thank you peter allen so this video is the first video In a new playlist but also the 23rd video in an old playlist in the old playlist i got to this stage where we can make terrains make them infinite in the sense i suppose it’s not really infinite because my computer will run out of memory at some point Um but as you can see we’re generating the terrain as we walk around quite efficiently uh we can mine and things like that but in the previous series i got to the stage where we’re wanting to create biomes so for example if we go up really high We could have like more like snowy kind of biomes if we walk over to the i’ll just pretend this is like the south lands then things should start going green there we go so i’ve got some very basic biomes uh happening so that’s what we’re gonna do um but Um so i’ll just speak to the the previous viewers of um of the last uh playlist if you’re on if this is for you uh video 23 then what we’re going to do is use a different technique to generate um our terrain which is a lot more efficient if I just turn off the generation um we should have like 60 frames per second oh there we go that’s a bit better because i’m kind of like looking at a lot of uh entities i guess or a lot of vertices up here um anyway it’s nice And silky smooth our um mining is still working and everything using a lot of the old techniques that i was doing before but instead of combining subsets into one entity to make things run efficiently we’re now going to use the mesh to generate um our terrain and i think one commenter Sorry i forgot your name i’ll try and find it maybe in the next video um you were asking about how do we use the mesh to generate the train and so i’m going to show you that okay so let’s get going okay let’s get going right and i think I’m going to keep these videos to about half an hour so they’re a bit more friendly a bit more manageable but if you’re new to using python don’t worry this is also a way to learn python um the first thing i’ll say is we’re not gonna write just one file we’re gonna Break our project into small manageable chunks called modules um so for example this is my main module which i made at the end of october it’s like the middle of november now it’s been so long since i’ve had a chance to make a video anyway this is less than 100 lines really tiny And in this first video we won’t do all of the the ins and outs we’ll just get the basics going this um we’ve got another module so another file so just a per it’s just a uh python file dot py file extension and how big is this yeah like 30 lines So that’s the purlin noise that’s looking after making our terrains bumpy and everything and then we’ve got the probably the biggest module and this is um looking after actually making the train i think this is rather large at the moment because it’s doing a lot Whereas to begin with we’ll make it do a lot less and maybe try and make it smaller i don’t know oh yes i’m not just looking at this block object and texture at this um all that you need to get your project going um is have a project folder mine’s called Python mesh craft tutorial 2021. so you need to make a nice project folder call it whatever you like then inside make a folder called assets that’s just traditional you could call it whatever you want but maybe call it what i’m calling it for now so that everything makes sense um so Inside assets at the moment we’ve just got two things and you can download this from the link that i’ll put in the description um you could make them yourself and probably later on when you want things to look the way you want them to look you’re Going to adapt these all they are is a simple block object so that’s a model of a block and then we’ve got a texture atlas which i’ll just open up actually so just place those two call them block dot obg and texture underscore atlas underscore three this is my third attempt dot png We’re using pngs because unlike jpegs pngs can include transparent colors so if we want glass and water and things like that or the spaces in between leaves we can do that later on um okay so download those from my github that’s in the link in the description You can download those and put those in a folder called assets and then what we’re going to do then is save all the modules that we make in here okay in your project folder and then a cena works really nicely it will be able to find all of the the assets and Things that we need as long as they’re kind of together in this folder hopefully that makes sense okay as always if you need help write a question in the comments and i or some other people will help you okay right so this is my code that’s as you can see is Working so i’m going to keep that up because i i can’t remember how to do everything so i’ve got that there so i’m going to make a new file um i just need to select you probably won’t have to do this in your ide But i do so um right so first thing we need to do is import uh cena uh which i’ve already done wrong i want to say from urcena import everything so we use the asterix or the star in uh in python now um that won’t work unless you’ve installed A cena already so it’s very easy to install a cena um and what i’m just going to do let’s just go to uh cena so that’s a cena engine.org and on here we’ve got all the information for getting started so literally to install a cena you need python 3.6 on your which you’ve Probably already got if you haven’t you can follow that link and then in the command line or the terminal you just need to write pip install er cena and then it’s done okay um if you need help getting the command or the terminal up maybe search for that yourself and I don’t need to teach you how to google but there you go so all the information to get started is here and so some things might go wrong so this further information will help you or if you get stuck put your um question in the comments and i or Someone else will try and help you out okay so we’ve got our cena so now we can create a window so we can say app that’ll just be the name of our app equals and we want a new asena object so that will have a capital u and brackets afterwards And now that we’ve created these objects this is like our and our environment a 3d environment like you might have in unity and it also has the window attached to it or as one of its properties so we can say app run and we should now we have to run this Into a window let’s make the window whoops oh yes before running it we need to save our python module so am i in the right place no i’m not so i want to go to yep my folder and then let’s call this the tradition is for your main file your main module Is to call it main and if you want to build this later on to make it an exe an executable file um probably a good idea to call it main right now okay but again you can call it whatever you like there we go so now um before we run it I think i can just say window color notice the american spelling of color equals um color dot uh let’s just go rgb i like using rgb i could just write pink i think i could just say pink something like that probably got it built in but I’m going to say rgb red green blue i want 200 red no green and 255 blue save that and let’s run it whoops the button moved there we go so if you’re using idle or something you might press what is it f5 to get it running I can’t remember well there we go so we’ve got and we’ve got automatically frames per second up there in our 3d environment uh we’ve got an exit button that didn’t used to work so i might not press it yet you can press shift q to close Things down let’s just see if that works oh that worked well done peta amalan that’s not working brilliant okay so what we want to do is get our um our terrain and our person moving around so we need a character controller so we need to write from what is it um a cena Dot prefabs first person controller import capital letter first person controller like that okay so now we can say um i’ll do this under the window i’ll say subject that’s what i like to call your main player you could call this me you could call it bob You could call it mama you could call it player i’m gonna call mine subject equals first person controller and again like this cena object this is going to be an object so this is going to be an entity in the world it’s going to be invisible But if we now use wsad and the mouse or the trackpad and then we should be able to move around the problem is we haven’t got any ground so let’s get doing that right right um so we want a new function called update so this is a it’s like a built-in function Um belonging to a cena where this function will just run over and over it will loop so we’ll iterate just run over and over and over looking for things to do and what we want to do in here is kind of like update the terrain um or something like that So i’m just going to comment that out so the hash symbol means comment out this line it’s a bit like in javascript or other languages like c languages if you do slash that will comment out that line so the computer won’t run it so that’s handy if you want to keep something but You don’t want it to actually like run um you don’t want to make a break point or anything okay so the reason why i’m commenting that out is because at the moment our program’s very simple so i just want to create maybe just one block of terrain Get that working make sure it looks okay and then we’ll move on to like updating it as we walk around so before well just once down here we’ll just say um i’ll call it paint the terrain now this function doesn’t exist so we need to make that but i don’t want To make this function inside this module because this module is just to do with moving the character around and setting up the window and things so i want to keep my module modules um tidy instead what i want to do is like i’ve imported the asena module i want to say Something like um from Um we’ll call it uh mesh terrain um import and we’ll call it um terrain there we go oh mesh terrain i guess mesh terrain like that so what does that mean it means go and find in the same folder a file called mesh terrain dot py but we Don’t write py there because it knows it’s always looking for a python file so we want to go and find a file called that and then from that file that module import a class or an object called mesh terrain so all we have to do Now and and then that class will have a function which we’ll write called paint the terrain so let’s just go and create this file first of all so i’m going to save the current file go to new file and let’s write python there we go so to make a new class you Just write class and then we want to call it mesh terrain there we go oh i forget whether i need brackets there or not i get mixed up with other programming languages there we go cool so now traditionally what we want to do is write oops a basic function called underscore underscore init Underscore underscore and you you can probably guess that stands for initialize and whenever we make a new object called or a mesh terrain object this function will run to set up that object um well done by the way if you’ve never done any object orientated programming like this you’ve never used classes and Things or maybe you’re new to python well done if you’re still listening because this is a little complicated but the good news is we’re probably past now the most complicated thing so if you’ve kind of understood what’s going on very well done um but you’ve made it Through the rest of it will make a lot more sense as we start using these things so anyway i’m back in my main module and so now i’ve got mesh terrain oh i’ve got to actually save this sorry now i’ve gone back to the uh the mesh terrain class let’s just save this Save and yep make sure you’re in the same folder so i’m in python mesh craft and there’s my main module and so i want to call this one um mesh all under uh sorry all lowercase mesh underscore terrain there we go save it so that’s called exactly what we’re expecting there mesh underscore Terrain cool so from there import mesh terrain so now just like we created a a player as the first person controller using this class this object i’m now going to create a terrain so i’ll call it terrain so that’s how in python to create a new variable you just write the variable Name you don’t have to do like let or public int terrain you just write terrain whatever your variable is called equals and now i can say mesh terrain because that is a thing it actually exists because we’re writing it in the other module so then down here i can say uh terrain So that’s my terrain object my mesh terrain could you go and paint some terrain and by that i just mean generate some terrain um some actually i’ll call it gen terrain there we go okay generate terrain it’s just because i think in my prepare code i’ll call it paint terrain Right so that will go and generate some terrain right so so we’ve got our main module ready it’s just waiting for us to actually write those functions so here we are um back with our dunder double underscored um initial uh initializing um function in other languages these are called Constructors because they construct that object when you first um assign them to a variable anyway the first thing that we’ve got to put in here is a like a temporary variable that just acts like a like a a reference to the object that you’ve made and each individual object for example I’ve made just one terrain here i could make another terrain i’ll call this one um canada in honor of from canada and then i can make one called india there we go wonderful india um and then i could say that also equals a mesh terrain there we go and i can say India there we go equals mesh terrain there we go so now i’ve got three of those objects and they’re all individuals they’re all independent separate from one another so when we’re doing stuff in their functions on those individual objects we want to know which object we’re talking about so Traditionally you’ll just write in python self and that reference just refers to each individual object that we’ve made um i like to call it this so the point there is that you could call that reference anything you want but it will always appear as the first argument the first parameter In in in here so we could also talk you know we could give it a position x and a position y and size and things like that but the reference to itself must be the first parameter anyway i’m going to call that but it doesn’t matter what you call it so i’m Going to call it this just to be different and there we go okay um then so we won’t do anything in there yet but then we need a generate terrain function don’t we and again we need that first parameter in there this and um right so that’s all we need in our class But we do need to do some stuff so what do you do in um in the initialization well you give that object all of its properties so um we definitely need we’re going to make up our terrain out of subsets but at the moment just for testing we just need one subset But i guess we should make them all now so we call this this dot subsets will equal a list so in python we call like arrays lists and just like other languages you use the square brackets there so that’s not going to be just one ver It’s not going to be a simple variable it’s going to be a list of values stored in that variable um let me just look at my prepared code what else do i kind of need um i can’t find my prepare code where is it oh here it is Oh yeah we’ll need um the block so we need to go get the object that we’re gonna build our terrain out of we need the texture obviously oh there’s our subsets oh how many subsets oh what’s the width of each subset um fine um maybe a counter for how many okay right so Back on here so we need uh this dot num subsets that’s how many subsets we just need one this dot sub width so that’s how many like blocks long a subset is going to be let’s just make that um i don’t know 32 by 32 so in other words Let’s draw ourselves a wonderful diagram so if we’ve got here’s our terrain we’re looking down on the terrain so bird’s eye view and so we could make it up of blocks i should have done something smaller i’m going as fast as i can [Laughter] here we go oh no oh god that’s horrible Okay so here’s our terrain made up of blocks looking down there we go so this will be the width or the sub width i call that sw for sub width and this will also be the sub width s w so however one two three four five six Seven eight nine one two three four five six so i need nine to go down as well if it’s an accurate diagram maybe nine nine by nine anyway that’s our sub width um so we we’ve asked for 32 so we should be have 32 blocks going this way right Um let’s go back to the code okay so we’ve got 32. um so we need to make an entity now so we’ll i guess i could do this here i could say um uh for i in a range from zero to um this dot number of subsets So i want to create some iteration a little loop that goes around how many subsets we need and i’m going to create a temporary variable i’ll just call it e equals a new entity okay now i’m using the asena entity object and it doesn’t know what that is this module Hasn’t imported cena yet so i just need to say from cena import i could import everything but actually i only need entity at the moment so i’ll just write entity so now it knows how to create um a sooner entities and i’ve got about six minutes left to Get something okay so what we can now do is assign the model of our entity and the model wants to be this dot block which i haven’t made yet so back in the initialize initializer we need this dot block equals and then i called it block.obj now because our main Module file our python file is in the same place although it’s in a subfolder called assets a cena will find this block object very easily so as long as they’re in like the same folders as long as it can be in a folder within that folder like i’ve done To keep it nice and tidy that’s fine but if i went and put those assets that block on the desktop this file wouldn’t or a cena wouldn’t be able to find it so it’s got to be in there and there’s our mesh tray okay then we also need a texture So we’ll say uh this dot texture equals what was it texture atlas three dot png there we go um i think in my code i’ve used load model there so let’s just do exactly what i’ve done i’m tempted just to leave it like this and see what happens but let’s just um Trust my prepared code there we go presumably that means i need to load in load model let’s just go and see what have i done oh i’ve just imported everything from a cena that’s really lazy okay oh and i’ve also called my texture texture atlas so let’s do that as well so From our cena let’s there we go we’ll just import everything that’s very bad and then we’ll call texture a texture atlas yeah because it isn’t really just a texture isn’t just like a grass block or a soil block it’s all of the blocks let me actually go and Show you that i didn’t show you earlier so this is what the texture atlas looks like it’s got all the different kinds of blocks that we might want included on it so i’ve just got some stones some like snowy soil some grass and a testing block where i wrote the Numbers on when i was creating this to test that it worked okay and i’ve got soil so as you can see there’s lots of space to add lots of more blocks on and if you wanted even more space than this i’ll show you how to do that in the code obviously As we get further on okay so uh four minutes to keep this within half an hour so what we were doing we were creating a model and then we want its texture to be um texture atlas so this dot texture atlas there we go sorry my comments were getting in the way weren’t They there we go like that so in python if you want to go over to a new line as long as you’re in brackets like i am here you can do that so i can do this as much as i like that’s fine um what you can’t do is this i can’t say Number of subsets equals newline one python doesn’t like that other programming languages that would be fine but not python it’s very careful about how it sets things out so all of our code looks nice and pythonic looks all the same anyway i’ve done this separated these lines so it’s all nice and neat Okay so we’ve created an entity there called e and we now want to store that entity on our subsets list so that later on we can go and like grab any area of the train we need to to do things to it like mining and building and things So that will come later anyway to get how do we get this object onto this list to do that we get our list so this dot subsets subsets and we say append in other programming languages and then put e in the brackets there and that’s it so now that means could you push This object onto that array onto that list in other languages you might see this push it does the same thing there we go so append i guess there’s a more accurate term it means add something to the end of something that’s what appending means like an appendage Something that goes on the end right that’s done so we’ve only got one subset so that go from zero well two zero this this should only run once because in a range it will be like one less than this number so we should get one subset if we get any problems it Probably is probably this not running correctly well running correctly but me doing it incorrectly anyway um so then we wanted to run yeah generate the terrain so um okay so we want to do uh where are we we want to do this we want to get let’s get a different color Let’s imagine that this is a position where we want to start generating this this subset this part of the terrain we want to count from minus half the width sub width divided by 2 or times 0.5 because this distance here is half the total so we want to start counting from minus Half the sub width and then we want to go all the way to um the whole sub width or from this point it’s just plus again the sub width divided by two because we’ve already done that first half so that’s part of our loop so let’s go And do that so we want to say well let’s first get a position should we call that x equals 0 and z equals zero i won’t say x and y because z means forward and backward in our 3d world x still means left and right but y is up and down So if we’re looking at the ground sorry if we’re looking bird’s-eye view at the ground this way up like forwards and backwards is zed or is left and right i should have done these bits a different color is x okay right so we want to say so z is zero so that’s Going to be zero zero in other words it’s going to be the middle of our subset here and so we’re gonna say 4 um let’s use k for k in range um so we want to go minus this dot sub width times 0.5 i guess i could save that Or store that in a single variable so i could say i call that d for distance equals this sub width times 0.5 so we’ve just got to make sure that our sub width is always a a square a a an even number which we could go and cleverly code but I’m not going to i’m going to leave my code rubbish so we want to go from minus d so that’s half the sub width to d so that’s positive half so that covers minus half to the whole half so it’s going so 32 cubes in total because half of 32 is 16. So that’s minus 16 that way and then plus 16 that way so it’s 16 altogether but then i want to do another loop inside that because i need to go up and or forwards and backwards so that’s the x direction and now we need the y direction the z direction So we want to say um uh j in range um and again it’s just going to be a square so it’s minus d uh d that’s easy so now what we want to do is um inside this loop we just want to say um call another function i think i have to Use this do i have to use this this um generate block we’ll call it and then so we’re going to make a new function that generates a block um well actually it’s just going to change the mesh and i’ve just noticed i’ve gone over half an hour so let’s try and keep This under 45 minutes and then at 45 minutes let’s keep it under two hours and so on and so forth anyway we want to pass in the position so we want to say um x plus k so whatever point that we’ve got to we start with the origin there but it Wants to be plus you know what block we’re currently working on so that would be the x and then the z will be z plus uh j there we go um okay right so let’s go and write this function um i guess i’ll write it up here so this is The initializing function and we need another function inside this class called gen block and again the first argument must be a reference to the object itself so we’ll call it this or equal that self um but then we’re going to take in an x position and a z position lovely okay um Now um i just need to remind myself how we’re going to do this so what we’re going to do to write some um commentary here we want to um we want to extend or add to the vertices so they’re points on a 3d model they’re Like corners of a 3d model add to the vertices um of our model of our terrain model um or rather our first subset so this is the only entity that exists here so and it’s it’s just got a block model at the moment no what am i doing no it’s This is wrong its model needs to be an empty mesh um it’s texture does want to be that that’s that’s fine that’s okay but um yeah this block wants to be that and the texture this is going to be that okay yeah oh so it’s good it was a good job that i Was talking through things so i see what’s going on okay so what we’re going to do we’re going to use the information of our block because this isn’t this isn’t a block object it’s not an entity it’s just some information some data about where the vertices are to make up a 3d model Um also uvs so that means where the texture wraps around the model so that that data is stored there we’re going to use that to kind of like imagine if our our empty mesh is just like a tablecloth and we’re just going to push a cube um from underneath the tablecloth and it Will make the shape of a um of a cube and then we’re going to say freeze that part of the tablecloth so imagine like making it um literally frozen with ice and then we could take out the block from underneath and it would stay that shape and then we Could move it along go to a different bit push the uh cube up into the tablecloth make that freeze and so on right excuse me okay sorry there’s just someone at the door um so let’s continue so in generate block yeah we’re trying to push our imaginary cube through our Tablecloth and then kind of freeze that information um so we just need a couple of lines there really to do that so let’s just go to my prepare code and do some wonderful copy and pasting um also we’ve just got to sort out the texture atlas so it’s not just as simple As adding a texture around the whole thing in fact should we go and do that now so we just want to as i’ve said here adjust the scale of our texture so i’m going to copy that line and go back to our mesh terrain module and then in the place where we’re just Creating our subsets or in our case just our one test subset we’re going to say ease texture so our entity’s texture scale so that’s like the size of it the dimensions is going to multiply itself by 64 because we’re using um i don’t know if you can quite see this But up to here is a 64 by 64 pixel um image so it’s very low resolution at 64. you know to mimic the um the the the minecraft kind of style so each square here is 16 by 16 giving us a total so that’s a resolution Of each face each side of our block obviously later on if you want to increase that you can and you can do it by obviously creating a new texture atlas in in paint pro or wherever you’re going to make it and then you’ll change this number so if you increase the resolution Your resolution might be 128 or something um anyway we’ll get to that later i should not mention it but we’re then going to divide it by the textures width so that means this textures total width which in my case is 512. so it’s 512 by 512. And that just gives us the scale that we want so that when we’re generating a block as you’ll see everything will fit correctly or should fit correctly okay so back to my prepared code and i want to find something called yeah generate block here we go um So the first thing i want to do is select our model or get hold of the model of the entity that we want to get hold of so that’s going to be our subset um where are we right so we’ll say this dot no model equals this dot uh subsets And we know we want um the the first subset so in other words we want zero the index zero um and then we want to get hold of your model that’s it so we’ve got hold off this empty this empty mesh if you like there we go uh let’s carry on Um right we could ignore most of all of this that that will come later on we just need these two lines um actually just this one line really so we want to extend so add to the current vertices that we’ve got on our model at the moment our model was Just an empty mesh anyway let’s just copy and paste this in to keep the video as short as possible okay we’re on 40 minutes so we’ve got just under five minutes so our model vertices dot vertically so that’s a list a list of all the the points that make up our model And we want to use the extend function so that begins there and ends there and then in square brackets because we’re going to have an internal loop here so for v in however many vertices our block model has got so this guy when we load in this block object Into our variable this dot block it’s going to take i should do some drawing i feel some drawing coming on um let’s find a new color yellow will that look okay so for a 3d um cube or a cube by definition there we go um actually i’ll make it wireframe There we go right so our 3d cube is going to have these corners like that so it’s going to be 4 times 6 in other words because it’s got six sides which is about 24. there we go about 24 but we’ve actually got um um another verb to see sorry vertex there I shouldn’t have joined that up another vertex there and another one so that i need another color here we can make each face be made up of a triangle so a triangle you may have heard of like triangle strips and things you can put triangles together to make a square and then you Put squares together to make a 3d model and so to define a triangle you need to give it points and these are what points in 3d space are what vert vertices are so actually we’ve got one two three four five six vertices vertices per side so we Haven’t got four vertices which would be much more efficient we’ve got six so six times six so we’ve got in total 36 and this solves a mystery i had in a previous video if you’ve watched my other videos this answers our previous question so we have 36 vertices in other words making up One single cube anyway that’s quite a lot of detail wasn’t it but now you know um so we’re getting hold of however many current vertices we’ve we’re going to get we’re going to add to those however many vertices we’ve got in in a block so it’s going to be those 36 Vertices that will describe the triangles and everything and then we’re going to give it um a center point which is going to be our x and z and y doesn’t exist at the moment so we need to actually get a height so this will be to do with that purlin noise um At the moment can i just give it something random so where are we in um generate the terrain we could say y equals rand um round range from minus one to one um and that will give us an eight back okay right um and then we want to pass into Generate block so we want its x position its y position in the middle and then its z position so then let’s go back to generate a block we want the x y and z so now for each uh vertex of those 36 in the like the recipe and the blueprint for our block It’s going to um not describe this very well so we’re going to sorry from the origin of our new block in the center point of the new block it’s going to um add the 36 around the origin there we go using this little bit of code in There that’s all i have to say there we go and yeah so that’s in other words how to use the mesh to change the shape of an entity instead of adding loads of different entities here we’re not adding any new cubes we’re not actually instantiating a new entity a new block We’re just changing the vertices right so once you’ve done that it won’t actually change anything until you regenerate the mesh of our subset entity so then what we want to do at the end of that is say um This dot subsets and again we know we’re talking about the first one on the list and um do i just say or do i just say sorry because i’ve already got hold of that subsets model do i just say model generate i think that’s what i need to say let’s Just go to my prepare code um it probably won’t be in here um also actually i should do the texturing as well oh this will be in paint terrain where is it and pause the video while i go and find where this is so i’ve i found it we’re right so i Didn’t have to look for it it’s just dot generate very good so there we go so this actually updates that dot generate actually updates our entity the or the mesh of our entity okay um oh yeah the the vertices we should put those in now or Yeah we sh we should go and do that i guess else we might not have anything to look at um so um this is a crucial thing right this line here so let’s just bang that in there we go so it’s very similar we’re getting hold of the model And then instead of the vertices we actually want things called uvs so that just means um the positions of the texture as we’re wrapping it around and again we’re just extending what to what we’ve already done so if we’re adding new blocks on we’re not deleting other stuff we’re Leaving all that data alone we’re just adding some new coordinates um and then again we’re using our our object our block that we’ve loaded in and we’re getting hold of its uvs because it’s going to be mapped in exactly the same way to every other block and we just need what position On this atlas that’s why it’s called an atlas because it’s like a map so you know for example this might be position one this is position two this is position three and so forth but notice you’ve got two dimensions so we need a an x coordinate and a y Coordinate um and uvs we’ve got uh the u coordinate um or uu coordinate is that going horizontal and the uv is going vertical up and down so it’s like x and y really i probably got that the wrong way around oh no u u and u v um so those don’t mean Anything at the moment so we just say u u equals how do i get my grass i can’t remember so we just want to aim for the top left and it depends on those coordinates depending on how big your terrain atlas is excuse me so Let’s just look in here uh what tile so where is grass it’s position eight and position seven so it’s kind of like backwards to what you might expect and it looks like x and y are kind of like one off from one another anyway so what do we want eight and then uv Equals seven so that will be um and i’ll just write a little note so this is the texture atlas uh position or coordinate really card for grass smiley face there we go good good good good right um and we’re about ready to run this i think um yep maine So right we don’t need india and canada’s uh terrains should need one terrain and we wanted to run generate terrain um but it’s not liking that what have i done wrong generate a block generate terrain is the problem in here uh no everything looks okay let’s just see what the problem is when I try and run it hopefully it’ll give me expected an indent block oh because sorry our um update function is empty so if you have if you want to have a function there but you don’t want to write anything in it yet you just want To kind of keep it there you must use the past keyword and then python’s happy it’s just like oh okay i’ll just run without doing anything okay right now let’s run um oh yeah our first person will just fall probably um no i haven’t even got that wrong float object okay Where are we in uh mesh terrain yeah when we’re going around a range in um a loop or some iteration these must be integers because you can’t go from like 0.2 to 5 or something like that so unless you’re doing something special so d must be an integer so i guess i could Just say um int wrap that in and it will convert it to an integer that should be fine let’s have a look i think i saved it oh we still have a pink window don’t we okay it’s um it’s just running forever let’s see what i’ve done wrong oh okay there’s our terrain So so it worked but i think um a key thing that i’ve done wrong there is after creating each block we’re then updating the the model’s um um mesh which we don’t need to do we need to do that once we’ve sorted out all the uh the shape Of all of the blocks then we can update it and we only have to update it once so let’s just do that um so we should do that and generate the terrain so after we’ve finished all of these then so this is again in the the sub width where we’re going Uh using our two loops to go across and then up and down across the x and up and down or forward and back to z so once we’ve done all that then we can say um terrain dot well it’d be nice to have it just update itself wouldn’t it um Sorry i can do that here kind of i said this dot subsets zero so we’re into about one subset um model generate so now we’re only calling that once here instead of every time we generate a new block which is very um inefficient as we just Saw um yeah the other problem is our player is just going to fall so after we’ve created our subject we’ll just say your gravity equals nothing zero okay so now we can just fly around i guess although we might be kind of like inside that terrain right so that was a lot faster And we can walk around um and as you can see we’ve got a proper block i haven’t my random is not really working well i expected it to be like up and down and things like that but there we go right i’ll sort that out later we don’t want just random terrain We want a proper uh purlin noise track so as you can see this is really efficient can we how big can we kind of go in the first instance so or the second instance i should say uh there we go sub width let’s just say 128 I’ll stop the video if it just like crashes my computer immediately um i think it’s already has it already crashed oh i tried to run it from mesh terrain again you’ve got to run the thing from your main module i can’t believe i went over 45 minutes Actually yeah i really can’t believe it yeah but i’m not going to do anything else so i’ve got time on my side and let’s just do something really interesting and i want to play with it but um yeah so that’s 128 by 128 blocks But when i do want to play with it now i do want it to work because then you can just see this the size of this so let’s just think about this um where am i setting the height oh yeah oh we’re just setting this once outside the Loop the point is that we want that to happen for every new block don’t we there we go hopefully that won’t slow it down too much because every function that you use you know within looping is going to add a little bit of time let’s just see one two five Six okay about six seconds but there we go now we’ve got a terrain which is absolutely massive um i haven’t got proper like collision texture working but that’s very very simple and people have seen the previous videos know how simple that’s going to be so that’s fine So there we go we’ve got a very big terrain here and we can just keep adding to the train make it absolutely massive and uh yeah there we go right let’s finish that there thank you very much for watching i’ll see you in the next one where we’ll get some more Interesting terrains and things and mining and everything else goodbye Video Information
This video, titled ‘Python Minecraft with Ursina: biomes with texture atlas, terrain from mesh – part 1 (part 22)’, was uploaded by Red Hen dev on 2021-11-14 12:15:44. It has garnered 11954 views and 172 likes. The duration of the video is 00:56:34 or 3394 seconds.
How to easily make a Minecraft -like game in python. We use Petter Amland’s wonderful Ursina 3D game engine (https://www.ursinaengine.org) to do so.
Playlist: https://youtube.com/playlist?list=PLmP1LNMzp97rIbwnGHhjjobHHqWekxy8Y
Code and assets: https://github.com/RedHenDev/ursina_tutorials/tree/main/python_meshCraft_tut_2021
In this video, we set up the project and create our first terrain by extending the vertices of the mesh of an Ursina Entity object. We prepare for biomes with a texture atlas and a system of ‘subsets’ to break up our terrain.
Thanks for watching!