User Tools

Site Tools


hpl1:tutorials:tutorial_2_-_level_creation

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hpl1:tutorials:tutorial_2_-_level_creation [2020/02/08 14:57]
muffin old revision restored (2010/11/04 07:05)
hpl1:tutorials:tutorial_2_-_level_creation [2020/02/08 15:05] (current)
muffin
Line 63: Line 63:
 All basic geometry can be created like this. But for more complex geometry and if you want to optimize you can do a couple of things. Geometry in the game automatically gets collisions that are exact copies of their original form. This is not very efficient, most of the time you want to replace the colliders with more simple colliders of your own. To do this you do the following: All basic geometry can be created like this. But for more complex geometry and if you want to optimize you can do a couple of things. Geometry in the game automatically gets collisions that are exact copies of their original form. This is not very efficient, most of the time you want to replace the colliders with more simple colliders of your own. To do this you do the following:
  
-Rename your original mesh it so that it ends with “_nocollide” or begins with "​nocollide__ckgedit____>​, this tells the game that it wont create any colliders for the mesh. Now create your own simple colliders by for example creating a cube and name it “_collider_box_1” group it with your original geometry and make sure the collider has the same texture as the geometry. Now the game will only use the colliders you have created. At times you might have smaller details, say a wooden stick lying on the floor, often in games you do not want it to have any collision at all. Append the “_nocollide”(or begin with"​____nocollide__ckgedit> ​to it and make no new colliders to accomplish this.+Rename your original mesh it so that it ends with “_nocollide” or begins with “nocollide_”, this tells the game that it wont create any colliders for the mesh. Now create your own simple colliders by for example creating a cube and name it “_collider_box_1” group it with your original geometry and make sure the collider has the same texture as the geometry. Now the game will only use the colliders you have created. At times you might have smaller details, say a wooden stick lying on the floor, often in games you do not want it to have any collision at all. Append the “_nocollide”(or begin with“nocollide_” ​to it and make no new colliders to accomplish this.
  
-You can also appen “_noshadow”(or begin with "​noshadow__ckgedit____>​) to a node, making the name “pipes_nocollide_noshadow” this tells the game that this object should not cast a shadow. This is very useful for small details or objects located in such a way that there really is no point in the casting a shadow. For full details check the [[:​hpl1:​documentation:​content_creation_document|HPL-Engine© Content Creation]]. ===== TUTORIAL 2.4 – Using portals ===== Portals is a way to divide a level into areas that limits how much the engine is rendering. Portals is a must to optimize levels, in particular complex levels with lots of details. Lets use our level and add another room to it, splitting the level in to parts by creating a portal in between them. This tutorial gives some help, for more help and more details check the [[:​hpl1:​documentation:​content_creation_document|HPL-Engine© Content Creation]]. For this tutorial that document is a must, portals are a pickle to fiddle with. Open your project for mystuff_level. If you have not done anything specific, the 6 sides of the cube that you extracted should be in a group. If they are not, group them. Name the group “_roomFIRSTROOM”. “_room” tells the game that it's a room and FIRSTROOM is the name of the room, this could just as well be simple number or a combination. Duplicate your group so that you get an exact copy of the room and move the group to the side of the first group. Rename this group “_roomSECONDROOM”. Make sure the rooms are side by side, touching each other along a wall. Delete the two walls that are against each other. This should create a room that is twice the size of your original room. Create a new point light in the new room, make it the same size, but just to ease telling the two rooms apart colour the light red. Now export the level overwriting you previous “mystuff_level.dae”. Using HPLHelper open the level in the Scene tab and make sure StartPos: says link1 before clicking view. Now that you are looking at your level you will notice that the walls that you deleted are pure black. With the “W A S D” keyboard keys and your mouse you can fly around, fly torwards the black wall and through it. You should now enter the new room you created with the red light in it. What this means is that you have told the engine that you have two rooms by creating two groups of polygons and calling the groups “_roomSOMETHING”. The game now only renders the room that you are in and not the rest of the level, of course you do not want it to be like this here. You want to be able to stand in FIRSTROOM and look into SECONDROOM. This is where the portals come in! To create a portal, make a plane in your 3D editor. Rename the node “_portal1_roomSECONDROOM”,​ and put this plane into the group that you call _roomFIRSTROOM. This is the first portal that belongs to the FIRSTROOM group. It leads to the room(group) _roomSECONDROOM. Now move the portal so that it covers the whole area between the two rooms, make sure the normal is pointing towards the centre of the FIRSTROOM. Now make a duplicate of the portal plane. Move the new portal plane into the _roomSECONDROOM group. Rename it “_portal1_roomFIRSTROOM” and reverse/​invert the normal so that it points to the centre of the SECONDROOM GROUP. What you now have is two rooms, each with a portal plane pointing towards the centre of their own room group. The portal names says what room they lead two, meaning that these two portals leads to the each others groups. Save and export the level overwriting “mystuff_level.dae” and take the level for a spin using HPLHelper. If all is right, you should now be able to see from the start location into the new room with the red light. If you move to the new room you should be able to turn around and look into the first room. If it's not working, try and redo it and read this document carefully as well as the content creation documents part on portals. To learn how to use more than one portal in a room and how to link several rooms together you will have to read the [[:​hpl1:​documentation:​content_creation_document|HPL-Engine© Content Creation]]. This example did not create a portal system that is of much use from an optimizing view. Since you have two rooms connected like this, not matter where you are in the rooms you will always see the other room, the idea with portals is to split up a level into several rooms where many of the portals do not see each other. By doing this you limit how far the game renders, if all the portals see each other it would be the same as having the whole level in one group. A tip to see how a level is divided is to open a level from Penumbra in the HPLHelper. For example if you open level01_04_storage.dae. When you view the level, press the 2 key on the keyboard. This will show the portals and the bounding boxes for the rooms. If you also press the 7 key, you will see how the much of the level the game is rendering. Move around a little and you can see how it dynamically changes what it renders of the level. If you analyse the level you might notice that there are some walls sticking out, these walls have a primary function to block portals from seeing each other, making the level more efficient to render. It's this type of level building you need to have in mind. ===== TUTORIAL 2.5 – Linking two levels together. ===== The last tutorial for level creation is how to link to levels together using the _start and _area_link boxes. To make this work you will need a script file for your level, there is an empty script file in tutorials/​tutorial2 called “tut_level.hps”. Copy this file to your mystuff folder. Rename the file “mystuff_level.hps” and open it in a text editor. As you can see it's quite empty, it contains the different foundation parts that you use for different things when writing scripts for a level. For the scripts we are going to do now you will use this part: '' ​void OnStart() { } '' ​  As you can see this area already has some script in it: '' ​//SET UP LINKS SetupLink( ​__GESHI_____QUOT__warp__GESHI_____QUOT__, // Link name ''​ __''​GESHI_QUOT__mystuff_____level.dae__GESHI_QUOT__, //New map __GESHI_____QUOTlink__1__GESHI_____QUOT__, // Positon on new map __ GESHI_QUOTGESHI_QUOT__,__ GESHI_QUOTGESHI_QUOT__, //Stop and end sound. 0.5f , 0.5f);// Fade out and in time (seconds). ​__''​__ ​  Link name, this is the area that the player can interact with to initate the loading of a new level. New map, the name of the new level and link1 is the area where the player will start when entering that new level. If you so far have named you level ”mystuff_level.dae” and added a link1 _start to it the script is ready to be used with only a slight modification. Links can also be used to travel between different locations in a single level. To try this out we are going to use the ”mystuff_level.dae” we already have and add a new area to it. Open the project in your 3D editor, create a new cube that is about 1m*1m*1m in size and place it in an location on the opposite side of the room from your ”_start_link1” cube. Rename this new cube to ”_area_link_warp”. This will create an area in the game that will bring up the door icon when you are close, if you click with the left mouse button you will activate the area and be transportaed to link1 in the map ”mystuff_level.dae”. Since this is the map you are already in you will simply be warped back to your starting location. To make it easier finding the ”_area_link_warp” cube, lets add a point light where the area is. Make it bright green and set the X scale to 2, making the radius of the light 2 meters. Export your level and overwrite the old ”mystuff_level.dae”. Make sure that you have copied the script file to the same location and that you have neamed it ”mystuff_level.hps” as we said in the beggining of this chapter. Now launch Penumbra and start a new game, you should see a green light and if you walk over to it and interact you should be transported back to the start. Lets do the same but use two different levels. First go back to your current project in the 3D editor and create another cube that you place in another location and rename it ”_area_link_travel”. Do the same here that you add a light to make it easier finding the location, this time make it bright blue. Export this level and overwrite the previous ”mystuff_level.dae”. Now, in your 3D editor delete the refernece for the wood box and also change the main lights in the room(the ones that are 5 meters) to any other bright colour you like. We do this simply to quickly make a level that looks different from the one we already have. Continue on and rename you ”_start_link1” to ”_start_newmap” and change your ”_area_link_warp” to ”_area_link_travelback” we do this not because we have to but because you need to practice renaming and later editing the script. Last delte the ”_area_link_travel” cube and the light for it as well. Export this level to collada and name it ”mystuff_level2.dae”. You should now have to maps, mystuff_level1.dae and mystuff_level2.dae. Go back to your ”mystuff_level.hps” script file and select the SET UP LINKS part and make a copy of it, your script file should then look like this: '' ​void OnStart() { //SET UP LINKS SetupLink( ​__GESHI_____QUOT__warp__GESHI_____QUOT__, // Link name ''​ __''​GESHI_QUOT__mystuff_____level.dae__GESHI_QUOT__, //New map __GESHI_____QUOT__link1__GESHI_____QUOT__, // Positon on new map __ GESHI_QUOTGESHI_QUOT__,__ GESHI_QUOTGESHI_QUOT__, //Stop and end sound. 0.5f , 0.5f);// Fade out and in time (seconds). //SET UP LINKS SetupLink( ​__GESHI_____QUOT__travel__GESHI_____QUOT__, // Link name __ GESHI_QUOT__mystuff_____level2.dae__GESHI_QUOT__, //New map __GESHI_____QUOT__newmap__GESHI_____QUOT__, // Positon on new map __ GESHI_QUOTGESHI_QUOT__,__ GESHI_QUOTGESHI_QUOT__, //Stop and end sound. 0.5f , 0.5f);// Fade out and in time (seconds). } __''​__ ​  Edit the second SET UP LINKS so that the link name is ”travel”,​ the new map is ”mystuff_level2.dae” and position changed to ”newmap”. Save the script file. You now have the script file ready for ”mystuff_level.dae” but you will also need one for your new ”mystuff_level2.dae”. Make a copy of the script file and rename it ” mystuff_level2.hps”. Open this new script file in a text editor and delete one of the SET UP LINKS so that you get a script file that looks like this: '' ​void OnStart() { //SET UP LINKS SetupLink( ​__GESHI_____QUOT__travelback__GESHI_____QUOT__, // Link name ''​ __''​GESHI_QUOT__mystuff_____level.dae__GESHI_QUOT__, //New map __GESHI_____QUOT__link1__GESHI_____QUOT__, // Positon on new map __ GESHI_QUOTGESHI_QUOT__,__ GESHI_QUOTGESHI>​_, //Stop and end sound. 0.5f , 0.5f);// Fade out and in time (seconds). } ''​+You can also appen “_noshadow”(or begin with “noshadow_”) to a node, making the name “pipes_nocollide_noshadow” this tells the game that this object should not cast a shadow. This is very useful for small details or objects located in such a way that there really is no point in the casting a shadow. For full details check the [[:​hpl1:​documentation:​content_creation_document|HPL-Engine© Content Creation]]. 
 + 
 +===== TUTORIAL 2.4 – Using portals ===== 
 + 
 +Portals is a way to divide a level into areas that limits how much the engine is rendering. Portals is a must to optimize levels, in particular complex levels with lots of details. Lets use our level and add another room to it, splitting the level in to parts by creating a portal in between them. This tutorial gives some help, for more help and more details check the [[:​hpl1:​documentation:​content_creation_document|HPL-Engine© Content Creation]]. For this tutorial that document is a must, portals are a pickle to fiddle with. 
 + 
 +Open your project for mystuff_level. If you have not done anything specific, the 6 sides of the cube that you extracted should be in a group. If they are not, group them. Name the group “_roomFIRSTROOM”. “_room” tells the game that it's a room and FIRSTROOM is the name of the room, this could just as well be simple number or a combination. 
 + 
 +Duplicate your group so that you get an exact copy of the room and move the group to the side of the first group. Rename this group “_roomSECONDROOM”. Make sure the rooms are side by side, touching each other along a wall. Delete the two walls that are against each other. This should create a room that is twice the size of your original room. 
 + 
 +Create a new point light in the new room, make it the same size, but just to ease telling the two rooms apart colour the light red. Now export the level overwriting you previous “mystuff_level.dae”. 
 + 
 +Using HPLHelper open the level in the Scene tab and make sure StartPos: says link1 before clicking view. Now that you are looking at your level you will notice that the walls that you deleted are pure black. With the “W A S D” keyboard keys and your mouse you can fly around, fly torwards the black wall and through it. You should now enter the new room you created with the red light in it. 
 + 
 +What this means is that you have told the engine that you have two rooms by creating two groups of polygons and calling the groups “_roomSOMETHING”. The game now only renders the room that you are in and not the rest of the level, of course you do not want it to be like this here. You want to be able to stand in FIRSTROOM and look into SECONDROOM. This is where the portals come in! 
 + 
 +To create a portal, make a plane in your 3D editor. Rename the node “_portal1_roomSECONDROOM”,​ and put this plane into the group that you call _roomFIRSTROOM. 
 + 
 +This is the first portal that belongs to the FIRSTROOM group. It leads to the room(group) _roomSECONDROOM. Now move the portal so that it covers the whole area between the two rooms, make sure the normal is pointing towards the centre of the FIRSTROOM. 
 + 
 +Now make a duplicate of the portal plane. Move the new portal plane into the _roomSECONDROOM group. Rename it “_portal1_roomFIRSTROOM” and reverse/​invert the normal so that it points to the centre of the SECONDROOM GROUP. 
 + 
 +What you now have is two rooms, each with a portal plane pointing towards the centre of their own room group. The portal names says what room they lead two, meaning that these two portals leads to the each others groups. Save and export the level overwriting “mystuff_level.dae” and take the level for a spin using HPLHelper. 
 + 
 +If all is right, you should now be able to see from the start location into the new room with the red light. If you move to the new room you should be able to turn around and look into the first room. 
 + 
 +If it's not working, try and redo it and read this document carefully as well as the content creation documents part on portals. To learn how to use more than one portal in a room and how to link several rooms together you will have to read the [[:​hpl1:​documentation:​content_creation_document|HPL-Engine© Content Creation]]. 
 + 
 +This example did not create a portal system that is of much use from an optimizing view. Since you have two rooms connected like this, not matter where you are in the rooms you will always see the other room, the idea with portals is to split up a level into several rooms where many of the portals do not see each other. By doing this you limit how far the game renders, if all the portals see each other it would be the same as having the whole level in one group. 
 + 
 +A tip to see how a level is divided is to open a level from Penumbra in the HPLHelper. For example if you open level01_04_storage.dae. When you view the level, press the 2 key on the keyboard. This will show the portals and the bounding boxes for the rooms. If you also press the 7 key, you will see how the much of the level the game is rendering. Move around a little and you can see how it dynamically changes what it renders of the level. If you analyse the level you might notice that there are some walls sticking out, these walls have a primary function to block portals from seeing each other, making the level more efficient to render. It's this type of level building you need to have in mind. 
 + 
 +===== TUTORIAL 2.5 – Linking two levels together. ===== 
 + 
 +The last tutorial for level creation is how to link to levels together using the _start and _area_link boxes. To make this work you will need a script file for your level, there is an empty script file in tutorials/​tutorial2 called “tut_level.hps”. Copy this file to your mystuff folder. Rename the file “mystuff_level.hps” and open it in a text editor. As you can see it's quite empty, it contains the different foundation parts that you use for different things when writing scripts for a level. For the scripts we are going to do now you will use this part: 
 + 
 +<code c++> 
 +void OnStart() 
 +{ 
 + 
 +} 
 +</​code>​ 
 + 
 +As you can see this area already has some script in it: 
 + 
 +<code c++> 
 +    ​//SET UP LINKS 
 +    ​SetupLink( ​   "​warp"​, //Link name 
 +            "​mystuff_level.dae", //New map 
 +            "​link1"​, //Positon on new map 
 +            ""​,""​, //Stop and end sound. 
 +            ​0.5f , 0.5f);//​Fade out and in time (seconds). 
 +</​code>​ 
 + 
 +Link name, this is the area that the player can interact with to initate the loading of a new level. New map, the name of the new level and link1 is the area where the player will start when entering that new level. If you so far have named you level ”mystuff_level.dae” and added a link1 _start to it the script is ready to be used with only a slight modification. 
 + 
 +Links can also be used to travel between different locations in a single level. To try this out we are going to use the ”mystuff_level.dae” we already have and add a new area to it. 
 + 
 +Open the project in your 3D editor, create a new cube that is about 1m*1m*1m in size and place it in an location on the opposite side of the room from your ”_start_link1” cube. Rename this new cube to ”_area_link_warp”. This will create an area in the game that will bring up the door icon when you are close, if you click with the left mouse button you will activate the area and be transportaed to link1 in the map ”mystuff_level.dae”. Since this is the map you are already in you will simply be warped back to your starting location. 
 + 
 +To make it easier finding the ”_area_link_warp” cube, lets add a point light where the area is. Make it bright green and set the X scale to 2, making the radius of the light 2 meters. 
 + 
 +Export your level and overwrite the old ”mystuff_level.dae”. Make sure that you have copied the script file to the same location and that you have neamed it ”mystuff_level.hps” as we said in the beggining of this chapter. Now launch Penumbra and start a new game, you should see a green light and if you walk over to it and interact you should be transported back to the start. 
 + 
 +Lets do the same but use two different levels. First go back to your current project in the 3D editor and create another cube that you place in another location and rename it ”_area_link_travel”. Do the same here that you add a light to make it easier finding the location, this time make it bright blue. Export this level and overwrite the previous ”mystuff_level.dae”. 
 + 
 +Now, in your 3D editor delete the refernece for the wood box and also change the main lights in the room(the ones that are 5 meters) to any other bright colour you like. We do this simply to quickly make a level that looks different from the one we already have. 
 + 
 +Continue on and rename you ”_start_link1” to ”_start_newmap” and change your ”_area_link_warp” to ”_area_link_travelback” we do this not because we have to but because you need to practice renaming and later editing the script. Last delte the ”_area_link_travel” cube and the light for it as well. Export this level to collada and name it ”mystuff_level2.dae”. 
 + 
 +You should now have to maps, mystuff_level1.dae and mystuff_level2.dae. 
 + 
 +Go back to your ”mystuff_level.hps” script file and select the SET UP LINKS part and make a copy of it, your script file should then look like this: 
 + 
 +<code c++> 
 +void OnStart() 
 +{ 
 + 
 +    ​//SET UP LINKS 
 +    ​SetupLink( ​   "​warp"​, //Link name 
 +            "​mystuff_level.dae", //New map 
 +            "​link1"​, //Positon on new map 
 +            ""​,""​, //Stop and end sound. 
 +            ​0.5f , 0.5f);//​Fade out and in time (seconds). 
 + 
 +    ​//SET UP LINKS 
 +    ​SetupLink( ​   "​travel"​, //Link name 
 +            "​mystuff_level2.dae", //New map 
 +            "​newmap"​, //Positon on new map 
 +            ""​,""​, //Stop and end sound. 
 +            ​0.5f , 0.5f);//​Fade out and in time (seconds). 
 +} 
 +</​code>​ 
 + 
 +Edit the second SET UP LINKS so that the link name is ”travel”,​ the new map is ”mystuff_level2.dae” and position changed to ”newmap”. Save the script file. 
 + 
 +You now have the script file ready for ”mystuff_level.dae” but you will also need one for your new ”mystuff_level2.dae”. Make a copy of the script file and rename it ” mystuff_level2.hps”. Open this new script file in a text editor and delete one of the SET UP LINKS so that you get a script file that looks like this: 
 + 
 +<code c++> 
 +void OnStart() 
 +{ 
 + 
 +    ​//SET UP LINKS 
 +    ​SetupLink( ​   "​travelback"​, //Link name 
 +            "​mystuff_level.dae", //New map 
 +            "​link1"​, //Positon on new map 
 +            ""​,""​, //Stop and end sound. 
 +            ​0.5f , 0.5f);//​Fade out and in time (seconds). 
 +} 
 +</​code>​
  
 Rename the link, new map and position to be as they are above. ”travelback” is the name of the link in you new ”mystuff_level2.dae” level that will activate to take you back to your first map and make you start in ”link1”. Rename the link, new map and position to be as they are above. ”travelback” is the name of the link in you new ”mystuff_level2.dae” level that will activate to take you back to your first map and make you start in ”link1”.
hpl1/tutorials/tutorial_2_-_level_creation.1581173826.txt.gz · Last modified: 2020/02/08 14:57 by muffin