[Livestream] 3D Mesh Generation In Godot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
oh i think i'm live okay hi welcome okay gotta test some things is my microphone okay because last time i accidentally used my um webcam microphone hello people welcome i guess that's a yes judging well the highs and hellos welcome um let me switch over to my powerpoints wait no i'm going to talk about the godot jam gokudojam first we got you covered lizzy well welcome everyone it's a bunch of people okay so this is another live stream for the gokudo jam and i have some cool things to show you there is for the gold and diamond tiers um a front row seat for uh asking questions to the godot developers adrian is going to do an indie interview with the with remy and juan it should be somewhere in here you can actually ask questions to the guido developers which is really cool also there is a discount code somewhere for the oh yes the theme energy source um there is a discount code for the t-shirts but i forgot what the discount code was let me look that up real quick um i will get back to that to you on that later or maybe adrian is in the chat and he can show the discount code for the t-shirts i am looking at the wrong chat here the chat is okay so what else do i have to promote for the gokudojam um oh yes if you finish your game and uploads an html build to gotham.io um actually one or it was five even five dollars will be dosing donated to the prize pool and the godot fund basically to the the goku dough jam by got7.io but you will also add you can also embed that gotham.io game into h.i.o you need to have it on each other io to make um to be eligible for prices and for the voting do you really use google firefox is better google google is a search engine firefox is a browser i actually made a powerpoint so 3d mesh generation in godot well fasten your seat belts let's go in this presentation i have a real live stream um which is basically presentation now i have a bunch of things that i want to show you so what you'll hopefully understand by the end of this live stream we will first cover basics of a 3d patch like what is a 3d mesh we'll have a look at vertices edges faces and triangles oh yes the gokujo t-shirt discount code is in the chat so check that out we will also have a look at indices so those vertices edges and faces and triangles is probably something you're familiar with if you are a 3d modeler using blender but indices is something you might not have might not have come across in blender we'll cover that we'll also talk about vertex normals what they are and the vertex properties like vertex colors and uv coordinates and then we'll talk about the five different ways of creating meshes within godot because there are a bunch of different ways you can create meshes and then mash generation with two exclamation marks we're actually going to be creating some meshes using code so let's get started what is a mesh indices now indices is plural for index but we'll cover that in a moment so what is a mesh a mesh is an object containing consisting out of triangles or lines consisting out of vertices which are points let me draw this out oh wait i have yes text so i have a pen so a virtue of vertex matt is going to be very angry angry if i call a virtuosity one vertices and an indices of if i mess up my plural are you going to do this with high tech math no this is actually quite simple but i need to concentrate um i have a mug and there's actual red bull in there okay um let's go vertices vertices are points in space 3d or 3d like these ones and you have one big list of vertices so this is number zero i'm trying to draw this with a mouse this is going to go terribly wrong but this is index zero this is one verbal vertex zero one and two so those are the vertices you have for a basic triangle a lot of people think if you have a mesh that it has to be 3d but no 2d meshes are also just a triangle like this then edges this is an edge that connects vertices faces often refers to a face on a 3d object and in this case we can just call it a triangle which is this part right here just the thing in the middle that is connected and closed off okay so now we have the basics let's move on what are indices in here i said one two three i am going to change that right now because that is incorrect this needs to be zero one and two okay um so we have these vertices which is zero one and two indices is the order that the mesh and vertices are connected to each other so ingodo and most graphical applications that like opengl you work with a clockwise winding order which is this way so we start at zero one and two and these are in the indices so connect vertex uh serial with one connect one with two and connect two um oh yeah this is the order i'm messing something up no i'm not this is triangle one two and three one two three and these will be connected in groups of three i also need to read the chat meanwhile the blue deer is a wild spirit that nobody can tame that no one can tame um someone is trying to tame the blue deer that is no you can't okay so indices is how you connect the vertices together then if we want to create a square instead of a triangle you will need two triangles actually because every mesh is consisting out of multiple triangles and um usually when you're modeling inside of blender you work with quads which are made out of one two three four points but actually if we for example raise this one you will see that there actually should be a line here because the the face is folded like this you can basically make any shape that you want out of triangles but for humans it's just so much easier to model with with squares but in the game engine usually well always the the mesh automatically gets triangulated so if we want to draw a quad we have these vertices and we have 0 1 two and three that is a beautiful three thank you um what we then want to do is connect them together so what we have is we want to connect the first triangle from 0 to 1 and then from 1 to 3 and then from 3 to 0. but for the second triangle we actually want to connect them to existing points so that we don't have six vertices but we can use four and they will be connected together so the second triangle will have indices of one two three and then we'll go back to one so that's how you draw a quad shape this the order that the indices connect affect anything yes it's very important to always do this in a clockwise winding order otherwise the face might get flipped or you connect the vertices together wrongly wrongly if that's even a word any moment you will see what will happen um oh um according to this powerpoint i will read the chat but i'm already mostly doing that i mean in the meanwhile let me check if everything is okay on youtube 23 people watching yes seems to be doing okay um i think that's good now let's move on so do people okay wait before we move on are there any questions about indices or virtues or anything else that we've talked about so far it's a similar approach to drawing in 2d i think just that you're adding a third axis yeah basically if you 2d meshes can be easily turned into 3d meshes because their adidas have a third axis indeed i think i don't know about the delay but mata no okay um let's move on the five different ways of creating meshes within godot there are five five different ways why let me explain but i might not really understand why either because four take another sip of the red bull where is my mouse these four are very similar in particular these two do basically the same but one is faster than the other we'll have a look at that in a moment this one is just complete something completely different but they provide you tools to create meshes within the editor but not the needing code let's move on to the first one which is the mesh data tool so the mesh data tool lets you edit existing meshes you will need to you to use this you will want to use this class when you want to modify an existing mesh and you need data you need access to the edge or phase data usually with the other classes you can't access these features but if you don't need those features it's better off using those other classes i will talk about in a moment for example i have a really janky example over here um i was trying to get to to make an example work but i didn't really have time csg counts as match generation um maybe i just wanted to include it because it involves creating meshes within godot without having to create a mesh outside of godot but in this case i've actually used suzanne the the blender monkey and i um i did something with it but it didn't really work out but yeah this is an example of what you can do with it you can actually grab uh you can grab all the vertices you can get the face count and then you can grab face vertices but let's not dive into the codes too deep for now because we will do that in a moment between your mesh and surface tool which is better we will get to that in a moment okay so let's move on in the powerpoint so much data tool you will want to use it when you need edge or face that data when you're going to manipulate an existing array mesh now remain mesh is just a mesh that you throw inside of a mesh instant mesh instance if you drag and dot obj file for example in here you can see it has those little three dots and a plus which is according to this an array mesh and you can access everything about that mesh using the mesh data tool you can access those extra features of edge and face data okay i lost my mouse again where is it there it is okay then immediate geometry which is another one is a class that is really easy out of all all of the other classes this one is the easiest to use and requires very little code to make a small mesh but the downside of this is that it's very slow and it is mostly well the best use case for this is when you want to really quickly throw together uh debug shapes for in your guido game for example if you have a physics character or just a character in general and you want to draw a line for a raycast or you want to draw a line for for example the velocity or if you're making a 3d card game and you want to draw the velocity and the steering in which you're going with a 2d well a 3d line in 3d space then this class is useful but it's slow and it's really not recommended to use this in your in your finished product and one thing it's a node so it's really easy to just do i have an example um well here i have an example hello and welcome um immediate geometry is one node that you can just add to the scene and on that you can add you can call all those functions we are going to quickly glance over what the code for that looks like if i can even find the window in all this mess where is it and here immediate geometry this is all the code that you need for creating a debug line so what happens is it extends the immediate geometry because when you add a code to that node you will want to use that class and then in the process function you first clear the entire mesh otherwise it will this by the way this code will run every frame in the process function but it will need to run every frame otherwise it gets deleted but first you need to clear the mesh from the last frame then you will start and you want to create a mesh consisting out of triangles which is smashed.primitive triangles then you will set a normal we will go over that in a moment and i kind of forgot to set up an example for that but i will try to explain what vertex normals are then setting up the uv apparently you don't have to do this if you're just going to draw a line but this draws a triangle i think because it has one uh one two and three vertices so we said the vertex normal the the uv coordinates and the vertex vertices so one two three you create them three points and in this order that you create them they will be connected you don't have to provide the indices and then you will just say and and this will draw a triangle it's easy it's quick but it's only useful really for debug shapes when testing your game that was immediate geometry the second one i think then surface tool again let me also read the chat there don't seem to be a lot of questions if you have any questions just or if it's going too fast just yeah like me in chat and okay surface tool surface tool is quite easy compared to the others this is more difficult but it's easy to use and it has a bunch of useful functions that you can use on the geometry which we'll also go for later then um lastly we'll note lassie of the four these are all they have to do with mesh generation and manipulation through code the last one of these is the array mesh which we are going to be having a look at with the code and which is the more difficult one or well the most difficult one of all the others but it is the fastest and the downside is that it has a couple of last couple well it doesn't have a lot compared to the surface tool it doesn't have all the useful functions for recalculating vertex normals for example we haven't talked about vertex normals yet but bear with me so for if you want to create a mesh in your game a big mesh that is not for debug purposes you will want to use surface tool because this is just easier to use and has useful functions or you want to use array mesh because it is a little bit more difficult to use but it's faster and we're going to be having a look at array mesh because it is in general just if you understand this one you will understand all the others okay welcome people please say so please say so if i go too fast i blame the red bull in my mug okay the array mash and then i read the chat which i already did is asking how i am doing today i am i am okay i guess i hope everyone is still following along i have read the chat let's continue cg compute solid geometry is for creating meshes within the editor without having to use code as it says in editor mess editing and is useful for prototyping levels and creating quick test geometry and good to know it's it's not very fast so if you want to create it in an entire level or gray box an entire level using this it's not very fast so in the end you will want to replace it with something powerpoint i understand this then all the others will be easy does that mean others are similar yes except the csg data tool um surface tool immediate geometry and array mesh are pretty much the same the only difference with are between them is how you use them the notation but once you understand the remash it's it's really the all the others will make sense let's compute solid geometry you can do boolean operations which i'm going to show right now um right here i have a spatial and a csg combiner csu combiner is basically an empty cg node all the if you search for csg these are all the different shapes available to you and this is g combiner which is like i said basically an empty one and what i did here is on the csd combiner you don't necessarily need the csg combiner i think i've added this thing a cylinder and a ctg sphere what they can then can do if i select the sphere i can set it to in the operation to subtract am i doing this right why is it not doing the thing oh this is not supposed to happen i think i can i move the mesh but the mesh itself doesn't move that's so weird let me get rid of the it's it's gone but it's still there okay that is not how it's supposed to go is there something that you can absolutely not do with array mesh that the others can do or is a remain mesh like the ultimate no actually the surface tool can do things that remain mesh can not but the main reason you will want to use that is performance if you want to make a minecraft clone and you really need the performance it's just best to go with c sharp and array mesh because fast language and the fastest chrome shape creation class you said the sphere as a childhood cube um this used to work before um i think a bunch of things are broken let's just retry the entire thing we have a csg in combiner cylinder yes now it's working and then we add a sphere we move that over we scale it down a bit move it up let's increase the radial segments and the rings to make it nice and smooth let's do the same for this one and now we can move it around here in the operation we can do boolean operations like um intersect this will save the space that is intersecting between both shapes and with subtract we can remove the cylinder from the other shape which looks pretty cool to be honest we scale it up as you can see it's not great but it gets the job done if you want to create simple geometry for your levels or just test geometry in general okay that is cesg which doesn't have a lot so hey eric welcome um let's move on to actual mesh generation via code oh according to this small kitten eating a waffle it is time to try out the code let's move this over and let's go where do i have oh i just closed the presentation i love that image so much okay we have an empty project right here let's get to the good part let's create a 3d scene a spatial and to that let's create a mesh instance which is a note that holds smashes then in the mesh property we will need to select an array mesh and that's all we have to do for that let's create a new script and let's call it the boom match or whatever let's just save it here let's hit create and [Music] let me look up the code that i saved beforehand okay so now we have a script that derives from mesh instance we want to create a let's just create a triangle first so what we want to do is we want to create one big array that is going to hold multiple arrays which might sound confusing but basically see an array mesh as um a thing that holds multiple arrays which is the measure array which holds the list for vertices the lists for vertex normals i should really explain vertex normals the list for uv coordinates and lists for indices let's have a look at vertex normals real quick vertex normals are basically where this no this vertex points towards we can visualize that in blender by going in this little menu and then visualizing um display vertex normals as you can see each voice cracks each vertex has a direction that it points to and what can happen is that you can't see your mesh because can we uh flip flip the normals oh it takes the uh what this is called the average so it moves in slight bits but it's basically in which the normal direction um in which direction the single vertex faces which might sound confusing but it is useful for when you want to shade the mesh smooth oh wait we can also visualize that in display splits normals i'm not entirely sure how these works work because if we now it's smooth shaded because it uses the average of all those of vertices to draw that line like in this angle you have it like this and the average outwards is in the center but if we then shade in shaded flat you'll see that these will be split up into multiple directions so when when you have one face all the vertices points one way uh in the direction of the face and this will cause the lighting to be um shaded flat let me also read the chat if we create a mesh using a particular method is there a way of exporting or transferring it over to one of the other mesh systems in godot do you meet do you mean switching between array mesh and um surface tool because there is no real reason to do that what you can do is use the mesh data tool so the mesh data tool was for for grabbing faces and particular edges you can do that actually with the array mesh and immediately after that editing it with the mesh data tool for rendering you could say that the normal is the direction in which the light will be reflected yes that exactly and it's also how normal maps work because those pixels will define in which way the light will bounce off so does each third only have one normal or just one normal for each face that is part of that is one part i don't really understand yet because in blender what we just saw is that it seems to be having multiple um normals poking out from it but if we select it it's only one normal or one vertex which might be a little bit confusing but let's just skip that for now i'm curious if someone knows how that works because it's one vertex but it seems to be having four vertex normals so we have one big array that contains multiple arrays now let's define those arrays which we'll be doing using this we will have an array for the colors which you will see in a moment vertex vertices can have colors and then have we have a list of the vertices which is very important and the other one that's also really important is the mash indices okay let's then uh the function ready yeah it's based each phase has separate vertex normals based on smoothing yes split normal is one normal for every face can you edit create edit phase normals in godot i am not sure about that because when you have those arrays you have vertex 1 2 and 3 for example or 0 1 and 2 and it looks in the same in the other array of the vertex normals it will index 0 the first vertex will correspond to the first vertex normal the second one will correspond to the second vertex normal we have normal one one normal per face multiple different directions facing per vertex and a hard edge yes okay but what we have to do is now resize the mesh array do this and we'll have a look at mesh that arraymax max is nine and these are all the lists that we can put into it we have an array of vertices an array of normals array of tangents which is a little bit too difficult to explain right now a list of colors a list of uvs list of uv2 which in which i think the map data can be stored you can also have bones and weights you can actually create a 3d model with bones using godot which is really cool good luck with stream thank you and raymax is just how many arrays you want in there but you stun it usually you just resize it with the max so nine arrays can fit into there and then what you want to do is we're actually skipping the vertex normals right now is we want to create in this array which consists out of factor of threes and has the vertices we want to add a vector three so we want to add a vertex as a specific position which will be minus one minus one zero so in a lower well if we look at their triangle basically this one in the lower left corner and then we want to create the other two right triangle so this has the other position this one is the one at the top and we will also in the indices append the the order so we have number zero indices for the indices and number one and number two so now we have our three vertices and we've put them in the list of indices in the order that we want to use them what we then want to do is we want to put these two arrays of the vertex vertices and indices we want to put them whoops oh yes no we want to put them in the the holder for all the other arrays so on position if you look at this this is position zero the first array we want to fill with all these vertices then the indices we will fill with the all the indices that we've created what we're then going to do is on the mesh of the mass mesh instance which is the array mesh we want to add a surface from arrays which is all these arrays that we've put in here and we want to define which type primitive type it is if we have a look at this there are a bunch of different primitive types you can make a mesh consisting out of points which for that indices are not really necessary because you're not connecting multiple vertices you can make it out of lines and every group of two so point one two this one will be a line and it will move on to the next two points and we'll create a line between those we have a line strip line loop triangles triangle strip and triangle fan which are a little bit difficult to explain right now i think that's it let's just run this shall we let's save it let's call it a full match i mean if we run this oh we first need to add a camera to this let's move it out and let's make its current if we then run this you'll see that we have created a triangle wow yeah if you want to do this in opengl oh boy you are in for a ride because is there an example here oh yeah you have all these buffers and uh you need oh all of this to create a triangle wow that's not even all you also have to create the window and stuff yeah opengl i'm happy that godot exists so we have a triangle but what happened is if we have might have accidentally let's let's just mess with this and let's change the order around and if we then run this it's invisible because it thinks okay the best way you can show you this is if we go into the function and in process let's just rotate it on the y axis by about seven times delta wait for it as you can see it created the shape on the other side because if you flip it the order is correct in clockwise order let's make it some falcon let's not ah from what i've heard howdy ivan hello from what i've heard it is you need like i don't know i have really a lot of code to make something really basic in vulcan it will be really fast and amazing but that's a lot of suffering you first have to go through i also wouldn't make a game without a game engine and because there is godot the easiest game engine i also wouldn't want to use anything bookido for my personal projects oh ivan of course is bobby hi bobby actually unity which is a thing to keep in mind when you create match using dough you can actually just use unity tutorials because the mesh creation process between opengl and all the other game engines is really simpler similar in the fact that you just have those couple of arrays filled with indices vertices vertex normals and we want to create a really specific shape in godot but you can't find a tutorial for that just look up what you need a unity tutorial for it because it's super easy to translate those but yeah if you create a triangle and you can't see it it's probably because you got the order wrong let's revert that now let's make this back to this and we have our triangle again i'm confused why can't we only see the triangle from one side it is because of backface culling for a game engine is so much faster to only run around the side or render to the site that you will see for example if you build a sphere you will only want to render the outside that the user will see and not all the insides you can actually make it render on both sides if we go on the mesh instance and we are going to go into where is it into geometry and then the material override on that we can create a new spatial material and in there we can go into flags or where is it parameters and we can see we have a look at the cool mode currently set to back so the back side will not be rendered you can also do the other way around that the front side will not be rendered and the back will or you can disable it if we then run it you will see if i'm correct that both sides will be rendered the order determines the normal direction yes basically yeah yeah and we wanted we set the vertex normals in the wrong direction it will also face the other way but in this way you can make both sides render set this to back because this is the default for basically everything in your game engine but as you can see in the geometry we have a material override which overwrites all the other materials created on your mesh if we have a look at suzanne the monkey and we have a look at whoops monkey at this mash instance we've added an obj file in here and if we click on that here yes if we click on that you'll see if we i close this that it has a surface surface one if we click on that you'll see that it has a name and a material within blender that basically corresponds to your material tab right here it turned it doesn't have a material but it exported with one as a default if you were to create multiple multiple materials in here um whoops it will use these names and that will correspond to this name and the material assigned to it is this spatial material so we can change the color and stuff you can also go into array mesh surface parameters and set the cool mode array mesh surface parameters yeah that's basically the the default material it comes with but i wanted to use the whoops the where is it explain the material override and if you have a look in here you can add a surface from arrays so basically a surface is one shape with a specific material if we want to add a completely different material that has a different shininess a different roughness we want to create a new surface with its own arrays of vertices and indices let's have a look at the chat okay so what else wanted did i want to explain oh maybe the different types of primitives i have another instance of guido open for that somewhere over here so this right here is a little software i put together a piece of software that lets you draw files in 3d and i'm using the array mesh for generating the uh the shapes the tiles which are basically the just squat meshes whoops yeah okay okay so as you can see it also does the back face cutting to make it easier to see but what i wanted to have a look at is how i drew the grid the grid and those origin lines for example the white lines you see right here and the red blue and green ones are also just meshes for example in this grid mesh i have those arrays of vertices and indices and then i have a size grid extends the grid size oh yeah grid size is the space between the lines and the grid extents is how many lines there will be i know that's the distance it will divide that up either way i am creating lines two by two so one vertex in this position and then one vertex there and using the primitive lines i can just render those lines and then one space further or one unit further i will create another pair of vertices at the position and it will automatically draw a line between those i have another example this is the intro clip i made recently you've been importing blender using the gl glib format seems to work quite well do you mean glb because you have gldf and glb gltf is an open source format that doesn't put the textures and stuff inside of a binary file and glb is like um it's compresses stuff and it's a lot harder to read for via code but it puts the resources inside of the file yeah i usually use gltf as well uh that's the thing we can also do have a look at how the obj file format works you know maybe let's do that right now we have suzanne if blunder doesn't crashes does it oh can i oh thank you goodbye suzanne let's create a cube mash and let's export it as an obj let's dump it in here let's call it cube.obj and we only want to export the selection let's export it and did we throw it in here nope did we throw it in here nope where did i leave it oh where is my cube did i do something wrong in blender let me export again export object this is completely the wrong folder good job lucy um 3d mesh tutorial this is the one that we want export okay there we go yes the obj file in all of its glory let's have a look at the code behind it okay so that's a lot of tabs i have open but as you can see this is an obj file first it starts with a couple of comments and um a hashtag is basically just the comments and it will be ignored the mtl lib the material library will is the file that the material is in you have a separate material file which we can also open up whoop we have a look at that in a moment so first it starts with an o which means it's an object and which is cube cube dot zero one i am not sure why it's cube cube cube cube oh it's basically yeah cube and then cube.001 is this this is the object then we have the list of vertices and obj is basically just a text file describing what the vertices are so yeah the first vertex is at this position minus one minus one one if we then have a look inside the blender and if if it's this one and press n this is minus one minus one one is that the first one yes so this is the first vertex and then we have all the others all one two three four five six seven eight all eight of them then we have the vertex texture which is the uv coordinates uv coordinates is let me have a look what is a good example i think this is pretty good okay so oh i remembered it wrong you have a u and a v and these are coordinates on the texture for each vertex there is a position on a texture and in here we have 0.3 and then 0. so this this one corresponds to this vertex and it is at for the u that's 0.375 and for the v that's 0 0. so 0 0 on the v and the u 0.3 so i would see about here that is where the first one starts if we then if can we have a look at that in blender let's go to [Music] uv editing whoops let me select a phase please which faces it this one and if i'm correct this might be the vertex we're talking about here 0.375 and 0 which is this uv coordinate so yeah these describe all these points where the texture is applied and this is the entire texture and we select everything and it's fold out like that cool formats would be easy to generate from a script or something yes which is what i've done over here if you go into obj export is a really simple obj exporter that i've made it basically is a function that has the save function in which you throw the list of vertices the list of vertex normals the uv coordinates the indices and the material that it uses then it will create a file it will open up the file it will add it comments like hey this is made using you the lucy program and then it will have an empty line and then it will print the material like lib uh library comment or command and it will use the name of the material that i've created in cyber goodell then it will create an object just called model and then it will print out every vertex in that virtually vertices array one problem or while a thing to really look out for is in the obj format is that it expects those extra zeros if you don't things gets kind of wonky so what i had to do is use it in this um yeah what do you call it it's a string um sorry i'm getting distracted i need more red bull it is like blue peter who is blue peter let me check how the stream is doing 24 people still watching nice oh we missed some comments the set the monkey on fire oh i'm not gonna set the monkey on fire yes thank you mylen string formatting reformat this to have six decimals and then we're putting in the the vertex coordinates so it will be printed like this with those extra zeros which is important blue beater is a kid's tv program from the uk ah never heard of that i am sorry so what we have is a list of vertices in this file then we have a list of texture coordinates or vertex texture or uv coordinates then we have a list of vertex normals which is the direction that these normals are facing use material apparently is not using the material smooth shading is off it seems yes i think if you turn this on it will turn on the smooth shading and this is kind of the difficult part this is the the the indices and this actually seems to be working with four points instead of triangles it creates oh wait i kind of forgot how this worked you have the order of one one and one how does this work again oh man um i i am not ready to explain this right now this is the order of the indices like connecting uh i don't quite remember how this worked because i have been messing with that so much and there is logic behind it but online you can if you search for ob j specs no wikipedia this this is a really retro looking page is for explaining everything about the about the wavefront obj file format all the commands that you can do like vertices products texture vp i have no clue how vp does but some other things that you can do is like bezier curves b splines matrix things taylor you put taylor in there i don't know what taylor is but if you're interested you can't read through all of this but there's so much i wonder from when this page was because this is a while look this looks like and this is so bright it is bright if you compared my webcam from this to this they did a lot of crafting and common catchphrase was here's one i made earlier i say that a lot it's six faces right each face has four vertices each vertex i am a little confused that line makes the face and what vertex it is what sorry okay so just for recap a vertex is a point yes a point in three space or 2d and a mesh is made out of vertices where every face is made out of triangles a vertex has a normal vector which is the average of the adjacent space and faces normals that last part depends on if you're using smooth shading or not but yes that's about correct oh home cart is going goodbye you're probably going too bad aren't you yeah it's late in india sorry thomas i'm a bit like brain fried the red bull is not helping and trying to understand this while streaming is a little bit stressful but okay so that's the obj file format we're just gonna move on i think what else did i want to show i'm probably going to put this link in the description which covers all the all the basics of what i've talked about like the different types the array mash the mesh data tool the surface tool immediate geometry and when to use them this part was a little bit confusing to me so virtually the summary versus our meshes are points is that one sentence uh maybe i should have picked a topic that i am a little bit more fully familiar about and that i am not getting getting lectured in the chat because that's quite distracting let's hope this is not too loud but whoops join me yeah okay so let's also have a look at redrawing the mesh every frame [Music] because how i did that little animation is here i have it the grid is that i have put the arrays inside of the process function so saw this stream on my dashboard so i decided to quickly say hi before going about my night good luck thank you um i have put these arrays inside of the process functions so they get recreated every single frame what you don't want is in the other way that we've done this in the other file whoops is creating an outside of here because what will happen is that it will get filled up really quickly and your computer is not going to like that because every frame you're putting in those vertices and if you're you have these arrays outside of there they will fill up really really quickly if you run it at 60 frames a second so what i do here is one really important thing is calling mesh dot clear surfaces so every frame you remove all the data then you draw the mesh and you add it just like regular so not in a process function cyber generation looks awesome thank you so what you just want to do is put everything in a process function then move these arrays inside the process function so that they um don't really fill up that quickly and then every frame you want to clear all the surfaces to have a clean slate to draw the mesh then you draw the mesh and you basically do that every frame that's what creates that effect by the way how's your godot tutorial going it's kind of destined i'm kind of desperate because i don't know what i'm doing um i'm sort of working on it but i'm also trying to not get myself burnt out like i have to work on a school project and it's just so much work i have to work from nine till five and next to that doing all these live streams and working on game jam stuff and after next to that also making videos it's not me money at least they're a resource to understand what codes code what code goes into each type of built for in function um values if you might not i should might know you have the ready function which just runs once once the node is ready and you will just run once process will run every frame then you have the physics process in which you will do physics calculations which i sometimes is kind of confusing where to put it in a process function or physics process but for this you just want to make it within process function i can't really give a clear answer right now to to the difference between physics process and process because that's a whole other story how do you move in and out of the process function i meant just like changing this from from riff from ready to to the process function so you don't we even if you stop animating it it will always redraw every frame but what are these errors oh it starts off with an empty array which is not really what you want but this is process rings at the steady frame rate yes it will also for physics calculations it needs to be run at 60 frames a second thank you for making this tutorial oh thanks i'm just worried i mean you're welcome like i try my best but i'm so tired the red bull is not helping red bull is gone okay i think i kind of showed everything that i want to show maybe it's also good to have a look at how you can add colliders for these objects so what i've done in this project um sorry if this question already came up i just joined isn't it really inefficient to redraw the versus vertices every frame or is it just standard in godot depends on what you want to do if you just want to redraw every if you want to animate the object then you will want to redraw every all the vertices every frame but if you're just going to make a static mesh that is not going to change you will want to just draw it in the ready function like this uh i want vacation and no more rebel um what was i talking about mesh colliders yes mask or mesh colliders which i have in this project i have let me see collision shape which is empty uh i think this remember correctly this is what generates the mesh and okay we have all the vertices tangents normal indices and then somewhere we also oh wow that's all so we have a collision shape which is this node which is currently empty it doesn't have a collision shape but what we want to change the shape to mesh that creates dry mesh shape we're just going to let godow like hey create a triangle mesh for me please and godot will do that so should we try that out do we have let's change back the cooling mode of what shall we do okay let's create a mesh instance and let's create a static body we'll drag that whoops we'll check the mesh under the static body and we'll have a collision shape it creates a big plane shape and then measure instance will also create a plane scale that up okay now this plane has collision or why is this complaining plane shapes don't work well and will be removed in future versions please don't use them then okay let's use a box shape then and increase this and increase that let's move up the camera let's also add a directional light because who doesn't want a little bit of light in our lives let's enable shadow okay now we have a basic setup of with a static body with a collision shape and we have our mesh instance that we generate during run time let's add a okay no wait let's add a widget body and to that we will add our mesh and we will also add a collision shape so what we are going to do is add a variable which is on red d and which is the pollution shape and we will want to get what do we want to get get known and we will want to go one up to the rigid body and then we want to use the collision shape did i write them correctly yes i did i think okay now we have the collision shape down here we will want to go on the relationship dot shape and we will just want to use the mesh that we've just created and we will just yell it to create rhymer shape so we just yell at the mesh create this for me or while yellow for to create a trying mesh and we'll put that in the collision shape if everything is all right let's change the color of our little triangle to bright red if we then run this where is it or triangle go you know what if we just connect the camera to our little guy it keeps falling really quickly maybe let's comment this out oh wait i think we might need to move this down a little yup wow did it basically just land on its sights and perfectly balance the sun itself plane shapes don't work well and it will be removed in future versions please don't use them could be a good meme not one of the best but it's something yeah oh man when working with unity so much stuff gets deprecated then you just want to use a library and it says this will be deprecated this is deprecated stick just so much let's rotate our rigid body a little bit whoops it still doesn't fall over how does that happen huh everyone use plane shapes exclusively so they have to keep you supporting them okay so we have created a rigid body a custom mesh and then we have creases a custom triangle mesh for it oh okay is there anything else that you folks want to see and really quickly check how many people are watching like 19 people still wow i would expect that triangle to fall over yes i don't get why the triangle is not falling over i angle it a little bit but it doesn't if i just angle it like this does it fall over it doesn't it does not work i mean let me move the camera over real quick those hands fall over can we see three collision shapes if we're going to do both visible collision shapes and then run it again yes it seems to be that it just created a triangle but maybe it doesn't have any weights to it this is magic you must have balanced it perfectly in the universe but it's at an angle why i don't know why this happens but whatever when you make the mesh array script tool can you oh a tool script i am very curious about that this is michael jackson smith graham on the lean yup thanks for showing us so much cool stuff yay you want to move a point and reform the mesh to range shaping in a game you use return if you have a terrain and you want to move it oh thomas were you the person that had the question about creating terrain with um overlapping where can a game where you shape the terrain well there are two different ways of creating terrain and shaping it if you're using height maps then it won't be able to have overlapping geometry but you've probably already seen this but we have a look at this um this is like the perfect add-on for voxel terrain which is basically 3d uh uh yeah how do you call that well it's voxels but then rounded off with algorithms and stuff and this is just a free add-on you can use which is nice for shaping through terrain oh it's also cool for using 3d purlin noise or just noise for drawing from yeah the voxel module yeah this one sorry it's just it looks so cool a bunch of sine waves okay before i get to this structure but this looks so cool i have seen that but way beyond me using it at this point will oh you want to move a point and reform the mesh like terrain shaping in the game would you just rerun the code each time you move a point yeah what you can do is divide the shape up or the train into multiple chunks that's how minecraft does it have small points that are small chunks and only update that part and if it's next to well that's more voxel-like it's a bit harder i need to do more research yeah and also not sure how you mean changing the terrain but yeah another i have a bunch of tabs open that i want to show you this is a cool tutorial that matt i don't know if matt's still in chat that rhymes although he used this for a game that is a unit tutorial which describes how you can create a mesh that has a certain width width these notes are amazing but you basically run it and then divide well subdivide this and you create a subdivided plane but what you can do with that is like we did like rebuild it every frame to animate it yeah create waves this person uses multiple waves through moving through each other so that it creates a more chaotic wave like formation and he has like four tutorials next one he creates the ocean shader and in this one he creates the buoyancy effect so that you can still move you can still move on top of the generated mesh which is so just so cool yeah but yeah you could just use these uh these unity tutorials and then translate them to godot which is quite easy help how do you use do a set of custom textures in trench boom melon you gotta wait for the trench broom tutorial i can also tell you in person but this is not really a trench broom um live stream it's more focused on just mesh generation i haven't heard of this creator of a check them out you mean this person or this add-on oh yeah no it's unity you can see by the super ugly gray colors don't get me wrong i don't hate unity but i hate those colors and i am so happy that you can you just use dark dark theme in the new versions for free which is not a feature you would want to pay so much money for so yeah you can change and create a mesh that is just ever changing and just redraw it every frame or divide it up into trunks to save on performance this is also a very cool website from a really cool or a good old creator and i think also contributor to the godot project he works on um really advanced oh i was just looking at the same preview but this person created a bunch of three modeling tools or for godot the reverse kinematics and this person also created tutorials video tutorials a bunch of cool 3d mesh generation tutorials but then using the surface tool including as a real now you can make a little minecraft game unity hate stream no no we're not going to do that this person talks about voxels and creating the mesh for it it provides all the code for free um talks about creating like the north east south south top and bottom parts of oh there's so much code but it's fun to mess around with because in minecraft you basically only render the top half of the or the faces that you can see and you you're not going to render every single cube these tutorials will get me started with creating meshes inside of guido i am going to put that in the description right now if i can do that can i do that while streaming service to tutorial i could also just paste the link in chat but this is for later and save i think that saved it and the serials should be in the description right now not sure if we can see the difference right here with the oh yes this person also goes over the basics of what are vertices what are indices this person talks about indices as the connections which is kind of true i guess but i will more say that the indices are the points that connect them together um actually let's compare oh my theme no thank you whoops basically this is the same code as we did for the array mesh as the surface tool you can see the only difference mainly is that you first in the ready function you create a variable that is the surface tool a new a new instance of a surface tool then on that surface tool we say begin then in there we tell it what type of primitive we want we want to use triangles and then you add the normal you can add an extra color per vertex and you can add the vertex you add a vertex 1 2 3 and then you add the indices and then you say surface tool dot commit and it creates the mesh you don't have to mess with all those arrays and that array with the multiple arrays as you can see this is just quicker and easier to use but because you've watched the remesh part you'll also just understand this because this is just a simpler version of of the array mesh yeah but yeah this is a slightly slower way of doing things but via code just the code writing the code is quicker because it's just easier it's more here to well it looks more like opengl i think opengl too we know you have mostly have open gel no wait this is more like opengl one it doesn't make any sense but i'm not going to go into that but there are completely different ways in opengl one you can describe it really easily and i lost it in a way like this and in opengl later versions of opengl it's just better to do it in a more um array mesh like structure okay i'm just gonna put this here not sure why i couldn't see your link you mean the link to this website i've put that in the description i could also post it in chat i think flip the floop there we go how long have i been streaming 98 minutes oops 98 how much is that i'm actually kind of tired so is there anything else that you guys want to see i wonder how many people are still there this stream didn't go as well as the last one because that one there were just so many people and it was a lot of fun but there's still 12 people watching it's like everybody left maybe it's because i picked it too technical topic and with the last the last tutorial it was a much more creative focused tutorial slash live stream thing oh math is still there hello i was mostly confused today wants to see you get some rest huh yeah i do too and that's a good question i was a performance manipulating the vertices in real time versus with shaders i'm actually not sure i would think that running running it on the gpu and manipulating a shape via vertex shaders would be more performant but i'm not sure if you can still manipulate the correlation shape via that also can the performance be improved by creating a c plus plus module which builds on a mesh on the mesh tool um it's not really a module i think if you just create a c plus class instead of a gd script if you just do the same as this but within a c plus plus script it should be like four times faster the only thing that isn't nice about shaders thing is that it only does does the looks and so yeah no collision yeah you're right matt probably would be interesting to see how to parse obj files to integrate them directly into demand dynamic meshes if you um is this the example with suzanne where are you suzanne i was thinking about creating a module gd extent oh oh sorry i thought c sharp you said c sharp you said c plus i'm sorry then it is a module i was thinking about creating a module slash gt extension for creating real-time fluid simulation that would be cool it would be really cool and that needs high performance yes then probably c plus plus is the way to go because that is just the fastest maybe also rust you also have rust bindings for godot which is basically just c plus plus both different syntax i think but about integrating an obj as an array mesh if you just import an obj and put it inside of your mesh instance it already is an array mesh so you can do with it what you want and i think with the mesh data tool you can just grab everything wait no maybe even now you can just grab all the all the vertices from this array mesh from the monkey and put them in your own uh arrays so you don't really need to parse an obj i think don't you need some rust yeah maybe i should gt extension extension still breaks for me a lot and usable ex so it's not usable to experiment yet oh gd extension is the new version of gd native right i hope so video 4.0 will cause some world peace you know maybe it's getting time to end the stream because there are so many people that are leaving and i think i've said what i wanted to say yes and you don't need to compile the engine again oh yes that sounds so much better i haven't messed with c plus plus in the gd native yet but sounds really tiring so you just have to compile the entire engine again we'll go to api it sounds powerful but yeah so i think i am going to end it here and flame lizard thank you for your cool insights and the things you're working on thanks for people for joining i i'm going to take a rest and i will probably be back on twitch somewhere soon i have to work on school projects and then i will be on live streaming on twitch probably once a week if i have the energy for that but i have to work on stuff anyways for school so yep see you then hopefully so see you on twitch yay okay then good bye [Music] oh thank you all oh there's okay goodbye where's the end button
Info
Channel: LucyLavend
Views: 2,076
Rating: undefined out of 5
Keywords: Godot, 3D, Mesh generation, Vertex, Normals, Indices, Godot 3, Godot tutorial, Generative art, Surface tool, MeshDataTool, SurfaceTool, ArrayMesh, CSG, ImmediateGeometry
Id: DoUTndJ-8oY
Channel Id: undefined
Length: 110min 24sec (6624 seconds)
Published: Mon Nov 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.