In this tutorial we load the model we created into the Jmonkey engine and view it. Open Jmonkey and under file select new project. Under categories select JME3 and under projects select Basic Game then click next. On the next tab name your project Cow Invasion the click the finish button.
Jmonkey will create a project containing the assets folders for us. Next we want to load the model into our project. Click the green button with the white arrow to load a model.
In the dialogue select open model then browse to the folder containing the model. Jmonkey can load blender , .obj and 3ds files. You can download plug-ins to make more formats available. Select next then on the following screen you will see a model preview window and the status showing what parts of the model loaded successfully. Click next and you will be asked if you want to load the original files in the folder. I decline this option as I only want to use the .j3o format.
In the project panel on the left side expand out the project assets folder. Then expand models. You will see a new folder added containing your model. Notice the model is automatically converted and given the .j30 format. Now we want to add the model into our code. Expand the source package folder then expand the my game folder. Double click the Main java file. Now let's edit the code.
We want to add in the following imports for ambient light , color and spatial.
import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
Now navigate the file and find the simpleinitapp method. Delete the contents within and add the following code.
Spatial Farm = assetManager.loadModel("Models/Farm/Farm.j3o");
Farm.scale(0.05f, 0.05f, 0.05f);
rootNode.attachChild(Farm);
AmbientLight sun = new AmbientLight();
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
The first thing we do is create a spatial. Spatials are our 3d objects and contain data about our models. We use the asset manager to find the file. By default asset manage starts in our project asset folder. We navigate from there down into the models folder then into the farm folder. Next we call the scale method to scale down the farm. By default the farm is very large so we scale it on the x,y,z(Width,Height,Depth) by .05 this will shrink the farm down.
Next we add the model to our scene using the rootNode.attachChild method. We pass the spatial as the only parameter. We will come back to nodes later but for now you only need to know that the root node contains all of the objects and data in our scene.
Next create an ambient light the use the setColor method to set it's color to White. An ambient light scatters light evenly on all objects in our scene. With out lighting we would not be able to see any objects in our scene. Finally we add the light to the root node with the addLight method. Passing the light as the only parameter.
Once you are done save your project and press F6 or the green triangle to run the project. You can use the W,A,S,D keys to move and the drag the mouse to rotate the camera.
In our next tutorial we will add some more movement and collision detection to the scene.
Open Source
Sunday, April 27, 2014
Creating 3d video games 5 - Completing th farm model.
In the previous tutorial we made the landscape for our farm. Now we want to add in the barns and hay bales to complete the model. Here is a link to the completed model http://sourceforge.net/projects/jmonkeytutorial/files/latest/download?source=directory
I used a prefabricated barn model to save time. To the load the barn into the scene we use the plug-ins import 3ds. The dialogue will ask you to browse to the folder containing the file. You want to leave the other settings at default the select ok. Once the barn is loaded you notice it is a little small. Use the object mode scale to resize the barn to roughly 1/10 the size of the farm. Then press Ctrl + C to copy the barn then press Ctrl+V to paste the copy. Rename them to Barn1 and Barn2 respectively. Use the move and rotate functions under object mode to position to the layout we did in tutorial 2.
Next we create 3 square bales of hay. Select cube under the item creation panel and change default height, width and depth to 56. Using the top or front view make the cube one grid wide. In the materials panel select the hay material we added previously then assign it to the cube. Make two more copies of the cube. Rename each cube to bale1,2, and 3. Now use the move tool to reposition them according to our layout. It doesn't have to be exact just close.
The finished model should look something like this.
In the next tutorial we will load the model into Jmonkey and view the scene.
I used a prefabricated barn model to save time. To the load the barn into the scene we use the plug-ins import 3ds. The dialogue will ask you to browse to the folder containing the file. You want to leave the other settings at default the select ok. Once the barn is loaded you notice it is a little small. Use the object mode scale to resize the barn to roughly 1/10 the size of the farm. Then press Ctrl + C to copy the barn then press Ctrl+V to paste the copy. Rename them to Barn1 and Barn2 respectively. Use the move and rotate functions under object mode to position to the layout we did in tutorial 2.
Next we create 3 square bales of hay. Select cube under the item creation panel and change default height, width and depth to 56. Using the top or front view make the cube one grid wide. In the materials panel select the hay material we added previously then assign it to the cube. Make two more copies of the cube. Rename each cube to bale1,2, and 3. Now use the move tool to reposition them according to our layout. It doesn't have to be exact just close.
The finished model should look something like this.
In the next tutorial we will load the model into Jmonkey and view the scene.
Monday, March 10, 2014
Creating 3d video games 4 - Modeling the farm
In this lesson we will start modeling our farm. Previously I stated we will be using Blender for the modeling but due to technical issues with Blender and it's overall not user friendly interface I decided to model with another free 3d Modeling package. I will still be using Blender for animation and model conversion but for Modeling I will be using an oldie but goodie Deled 3d. You can download Deled 3d from http://www.delgine.com/
Keep in mind this guide is not intended to be a full 3d modeling tutorial. I'm going to assume you know some basics , if you want to learn more about modeling with Blender and Deled 3d there are lots of tutorials available online and creating another tutorial would just be reinventing the wheel.
To start we are going to create the basic farm exterior. I'm going to use a square instead of a rectangle. Once you have loaded Deled 3d go to the create/edit panel and under the item creation panel select Rectangle.
Next select the top view window. Before we draw the rectangle make sure the snap to grid function is enabled. You can toggle it on or off with f8 or go to view > options > environment and select snap to grid. Snap to grid will automatically position our shape along the lines of the windows grid. In top view we want to create a square 16 x 16 units long. Hold the left mouse button down then drag the mouse 16 squares down and 16 square to the right. Try to position your square to the center of the screen.
Try to keep the Rectangle close to the grid lines as possible. Don't be concerned if you're a little off. The snap to grid function will correct this for you. Select the 3d view the hold the right mouse button then move the mouse to pan your camera view down. You should see the rectangle in center of the screen.
Now we are going to create the fence on the border of the farm. To do this we are going to use a series of rectangles which will paste a repeating texture of a fence onto. Like I said nothing fancy. Select front view window and select Rectangle from item creation. Now draw a rectangle 1x2 units on the grid(1 high 2 wide).
Shift left click the rectangle you just created to select it. In the geometry tool box make sure the MOVE option is selected. Now move the rectangle to the back left corner of the farm. You can do this by holding the left mouse button and dragging the mouse. Use the top and front view to move the rectangle and snap to grid will help you place the rectangle on the corner.
The picture about is how the model should look so far. Now we will use the extrude tool to create a series of rectangle polygons. Select the rectangle then under the create/edit panel select edge in the edit mode tab. In the geometry toolbox select extrude. Select the front view and use the middle mouse button to zoom towards the rectangle. Each edge will now have a square on its center. Select the right edge by left clicking the square at its center then hold the left mouse button down and drag the edge to the right two units on the grid. Release the mouse and the edge will snap to the grid. Repeat this process until the rectangle covers the entire back border or the farm.
Now we are going to copy this border and position it on each edge of the farm model. Select the rectangle border then press Ctl+C to copy it then Ctl+V to paste it. Make sure you select object mode from edit mode panel first. Using the top view port position the copied border onto the adjacent edge of the farm. Then press Ctl+V to make another copy. We need to rotate this copy first before we position it. In the geometry tool box select rotate the under the rotate properties menu(at the bottom of the create/edit panel) enter 90 into the Y box and press enter. Your border should be rotated parallel to left and right edge of the farm. Now position this border and repeat the same process for the other side. Once you are done your model should look like this.
Now we have our base for the farm we need to add some textures. In the next two tutorials. We will use Gimp to make a simple grass texture. Then we will learn how to paste a repeatable fence texture onto our farms border using UV wrapping.
Keep in mind this guide is not intended to be a full 3d modeling tutorial. I'm going to assume you know some basics , if you want to learn more about modeling with Blender and Deled 3d there are lots of tutorials available online and creating another tutorial would just be reinventing the wheel.
To start we are going to create the basic farm exterior. I'm going to use a square instead of a rectangle. Once you have loaded Deled 3d go to the create/edit panel and under the item creation panel select Rectangle.
Next select the top view window. Before we draw the rectangle make sure the snap to grid function is enabled. You can toggle it on or off with f8 or go to view > options > environment and select snap to grid. Snap to grid will automatically position our shape along the lines of the windows grid. In top view we want to create a square 16 x 16 units long. Hold the left mouse button down then drag the mouse 16 squares down and 16 square to the right. Try to position your square to the center of the screen.
Try to keep the Rectangle close to the grid lines as possible. Don't be concerned if you're a little off. The snap to grid function will correct this for you. Select the 3d view the hold the right mouse button then move the mouse to pan your camera view down. You should see the rectangle in center of the screen.
Now we are going to create the fence on the border of the farm. To do this we are going to use a series of rectangles which will paste a repeating texture of a fence onto. Like I said nothing fancy. Select front view window and select Rectangle from item creation. Now draw a rectangle 1x2 units on the grid(1 high 2 wide).
Shift left click the rectangle you just created to select it. In the geometry tool box make sure the MOVE option is selected. Now move the rectangle to the back left corner of the farm. You can do this by holding the left mouse button and dragging the mouse. Use the top and front view to move the rectangle and snap to grid will help you place the rectangle on the corner.
The picture about is how the model should look so far. Now we will use the extrude tool to create a series of rectangle polygons. Select the rectangle then under the create/edit panel select edge in the edit mode tab. In the geometry toolbox select extrude. Select the front view and use the middle mouse button to zoom towards the rectangle. Each edge will now have a square on its center. Select the right edge by left clicking the square at its center then hold the left mouse button down and drag the edge to the right two units on the grid. Release the mouse and the edge will snap to the grid. Repeat this process until the rectangle covers the entire back border or the farm.
Now we are going to copy this border and position it on each edge of the farm model. Select the rectangle border then press Ctl+C to copy it then Ctl+V to paste it. Make sure you select object mode from edit mode panel first. Using the top view port position the copied border onto the adjacent edge of the farm. Then press Ctl+V to make another copy. We need to rotate this copy first before we position it. In the geometry tool box select rotate the under the rotate properties menu(at the bottom of the create/edit panel) enter 90 into the Y box and press enter. Your border should be rotated parallel to left and right edge of the farm. Now position this border and repeat the same process for the other side. Once you are done your model should look like this.
Now we have our base for the farm we need to add some textures. In the next two tutorials. We will use Gimp to make a simple grass texture. Then we will learn how to paste a repeatable fence texture onto our farms border using UV wrapping.
Wednesday, March 5, 2014
Creating 3d video games 3 - Crash course in 3d graphics
Before we begin using Blender to model our 3d world let's cover some basic 3d graphic terminology. Having an in depth knowledge of 3d graphics isn't always necessary for creating video games but some basic knowledge is required. Even if you don't plan on creating or editing 3d models for your game I would suggest learning some of the basics to help you better communicate with your modeling team.
3d coordinates
A 3d coordinate system shows a location in 3d space by using three axises represented by X,Y and Z(x,y,z). The above graph shows a common 3d coordinate system.Where X is width , Y is height and Z is depth. Each axis is represented by a line. Where the three lines intersect is known as the origin. The origin is the center of our 3d world. In order to find a location in 3d space we start by counting out how many units (inches,feet,world) the object is from the origin. Note each direction is represented by a positive or negative. An object at position (10,-15,5) Would be 10 units to the right , 15 units below and 5 units forward of the center of origin.
Polygon or Face
Polygons or faces are any shape with a flat surface. Above we have some examples of polygons. A polygon can have an unlimited number of sides but must have at least 3 sides. The most basic polygon shape being a triangle.
Edge or Line
An edge is represented by a line. These lines make up the border of our polygon. For example our triangle has 3 edges. These are the three lines that connect to make up our shape.
Vertex or Point
A vertex (plural vertices) is represent by a single point in 3d space (x,y,z). Look at the image above you will see white dots that mark where each edge connects. This white dot represents a vertex. Vertices represent where two or more edges connect.
Model
A model is a 3d object made up of polygons. Models can be something simple such as a cube or plain or complex such as a human or animal. Below is a wire frame 3d model of simple cube. The vertices have been marked. Notice it is possible for polygons to share edges and vertices with other polygons.
Now you have learned some basic 3d terminology we will move on to creating our first 3d stage. For those of you who would like to learn more about 3d graphics visit http://chortle.ccsu.edu/vectorlessons/vectorindex.html The people at Central Connecticut have provided a free course along with download in computer graphics.
3d coordinates
A 3d coordinate system shows a location in 3d space by using three axises represented by X,Y and Z(x,y,z). The above graph shows a common 3d coordinate system.Where X is width , Y is height and Z is depth. Each axis is represented by a line. Where the three lines intersect is known as the origin. The origin is the center of our 3d world. In order to find a location in 3d space we start by counting out how many units (inches,feet,world) the object is from the origin. Note each direction is represented by a positive or negative. An object at position (10,-15,5) Would be 10 units to the right , 15 units below and 5 units forward of the center of origin.
Polygon or Face
Polygons or faces are any shape with a flat surface. Above we have some examples of polygons. A polygon can have an unlimited number of sides but must have at least 3 sides. The most basic polygon shape being a triangle.
Edge or Line
An edge is represented by a line. These lines make up the border of our polygon. For example our triangle has 3 edges. These are the three lines that connect to make up our shape.
Vertex or Point
A vertex (plural vertices) is represent by a single point in 3d space (x,y,z). Look at the image above you will see white dots that mark where each edge connects. This white dot represents a vertex. Vertices represent where two or more edges connect.
Model
A model is a 3d object made up of polygons. Models can be something simple such as a cube or plain or complex such as a human or animal. Below is a wire frame 3d model of simple cube. The vertices have been marked. Notice it is possible for polygons to share edges and vertices with other polygons.
Now you have learned some basic 3d terminology we will move on to creating our first 3d stage. For those of you who would like to learn more about 3d graphics visit http://chortle.ccsu.edu/vectorlessons/vectorindex.html The people at Central Connecticut have provided a free course along with download in computer graphics.
Tuesday, March 4, 2014
Creating 3d video games 2 - Story and concept
Before we begin making our video game we need to have a story or plot to set the game to. Since we are creating a small simple game our story will also be short and simple. The background for our game begins when a hostile alien race lands on earth and plants a virus onto farmer Jenkins dairy cows. The cows are now transformed into bloodthirsty killers whose only goal is to wipe humanity off the face of earth. In an effort to contain the killer cows you have been employed by the local authorities to destroy all the cows on Jenkins farm.
Now we have our story we can work out the basic concept and game setting. Since we only have one area for our game(Jenkins farm). Our game will consist of one stage. A farm setting will also be easy to create. Only few structures such as barns and some fences will be needed. Now is a time when you will want to rough draft your stage design on paper. I already have my stage design laid out. A rough draft doesn't need to be super detailed or fancy this is just an abstract blueprint for your game. Here is my first draft of Jenkins farm.
Red = barn
Yellow = hay bail
Green dot = tree
Brown = fence
I have a simple rectangle shaped farm surrounded by a fence. Inside the fence I have a couple barn structures and hay bails. I added a few trees for extra detail. This is the basic layout for the farm. More detail and structure can be added as necessary.
Now we have our plot and a basic layout for our game stage we need to determine what type of game this will be. I chose to make this game in the style of a first person shooter. This will require less character animation and first person shooters are overall easier to make.
Finally we need to determine the overall objective of the game. We want to kill all the cows but to make the game more competitive I will have a reward system. You get money for each cow kill and a bonus for completing the stage fast. You will also receive bonus money for accuracy. The more shots you land the more money you receive. The goal of this game will be to complete the stage as quickly and accurately as possible.
Some optional things you can add into the game will be power ups or different weapon types. Since we are trying to keep the game as simple as possible for learning purposes we will use only 1 weapon and no power ups.
Now we have a story and game concept let's start creating our farm stage. In the next lesson you will get a crash course in basic 3d graphics.
Thursday, February 27, 2014
Creating 3d video games 1 - Introduction to game design
Video games have come a long way since the days of pong and pac-man. They evolved from simple squares and bricks chasing each other about the screen into complex multidimensional worlds. Have you ever wondered what goes into the creation of video games or even thought about making a video game yourself ? The task of creating a video game can seem overwhelming and finding a place to start can be confusing. This guide will help you begin your journey into the world of video game development. Keep in mind this guide is designed for hobbyist and low budget game developers. Most of the tools referenced here are free and/or open source. My best advice for you a you begin your journey is persistence. Video game creation consist of multiple task that will require you to master multiple software tools such as 3d modeling and programming so be patient and don't give up. Are you ready ? Then let's jump right in.
Video game creation requires multiple tasks coming together to make one complete piece of work. To best explain the process it's easier to look at each task involved with the creation process individually. I have broken this down into three basic tasks , concept and story , graphics design , and programming.
Let's start with concept and story. All good games begin with a concept. For example , maybe you want to create a new style of first person shooter games. Before you can even begin developing the game you need a story to base your game on. Maybe you are a lone gunman trying to save a planet from an alien invasion or maybe you are squad of highly trained armed forces chasing enemies from planet to planet across the universe. Each of these games would require a different level of depth in your story which would change the design process dramatically. Creating one small world would be a much easier task then creating an entire universe with multiple planets.
Large scale games especially those with intense graphics can be very expensive. Before your game vision become to lofty you need to think of what is your budget and time limit. Perhaps if you're a hobbyist you may want to start by creating a simple game that can be done solely. Something like Pac-Man or Tetris. These types of games can be made in a few short days using today's modern technology.
The best part of concepts and stories is they don't require any special high tech tools. A simple pen and paper along with your imagination is all you need. However it's important to consider what resources you have before you start designing your game. Someone who has never dabbled in the world of game design should probably start small and try to create a simple game first then work your way up to something more complex.
Once you have your games concept and stories it's time to move onto the next step in the process , graphics. Graphics would include any images , models , and for simplicities sake audio in the game. There are tons of different tools for creating graphics. Such as Blender for 3d modeling and Gimp for creating great textures. Both of these are free to use however each one has a steep learning curve and will require months if not years to master , however these are very popular and also the tools we use for our game design needs. There are also other cheap 3d modeler tools such 3d Crafter. I would take time in considering what graphics tools you will use because every tool has a different learning curve and switching modeling software mid project can cause lots of complications. Blender and Gimp are always safe choices because they support multiple formats and are very popular with large arrays of tutorials and how to's.
For game audio you can search the internet for thousands of free sounds or use simple sound editing software such a Audacity along with a simple home recording equipment such a computer microphone to achieve the desired sounds you want.
The final and most complicated step of game creation is programming. There are dozens of programming languages to choose from. Currently C/C ++ being the most popular. Choosing what programming language to use will effect every other aspect of game creation. My personal favorite has become Java. The beauty of Java is it is not platform dependent. Java also is the language used by Jmonkey which is a platform independent game creation system. Which means you can write one piece of code that can run on multiple operating systems such as Windows , Macintosh and Linux. Some languages such as C# can only be used to create programs for one operating system.
Once you have chosen what modeling tools and language you will be using to create your game you are on the path to making your first game. Take you time in choosing your programming language and modeling tools because once you learn one set switching to another can be difficult. I suggest researching on the web before you make your pick. My best advice especially if you plan on following this blog is to learn Blender and Gimp for modeling , Java and Jmonkey for programming. These are popular and relatively easy to use.
Good luck in journey. Please feel free to ask any questions about game development and I'll be happy to help you out.
Subscribe to:
Posts (Atom)