Jul 16 2015

Using Sketchup Models in MonoGame

I recently ran into this minor problem when working with MonoGame, and I couldn’t find a guide that covered the entire process so I thought I would collect the different steps together here.

First, after creating the 3D model in Sketchup (I was using the latest 2015 version), you should export the model in the .dae format; you can do this with File->Export->3D Model. Unfortunately, the .dae model format is not supported by the current MonoGame pipeline (I am talking about this tool), or at least the build process was unable to complete for me, freezing after creating an empty .xnb file.

Thankfully a tool I had previously used was helpful here, the FBX Converter (I used version 2013.3) made by AutoDesk, which can similarly be used to convert old format .fbx files from blender into a new format that can be used in MonoGame. The converter can be downloaded for free here, and this video should show you how to use it (although the process is pretty simple – add a file on the left hand side, make sure the FBX 2013 format is selected, and press the convert button in the bottom right).

After you have converted the file into the .fbx format, you can add it to the MonoGame Pipeline like any other file. If the model has attached textures, be sure to keep the folder that contains them (the folder will be named the same as your model) in the same directory as the .fbx model, and the pipeline will copy it automatically to the output directory with the .xnb when it builds.

Although at this point the same model would draw fine for me in XNA 4, I found that in MonoGame 4 I needed to use the following code to make it render properly:

            GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            GraphicsDevice.SamplerStates[0] = SamplerState.AnisotropicWrap;
            GraphicsDevice.BlendState = BlendState.Opaque;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

Source.

After this I simply used the Model.Draw() method without any problems.

Note: This is using the free version of Sketchup, from what I have read if you have the pro version then there is a built in fbx exporter – although you still may need to use the FBX converter like if you were trying to use a model from Blender.

Aug 07 2013

Using Awesomium with MonoGame – Backspace

A problem with the code presented in my previous post is that it won’t work with the special case of the Backspace key, however it can still be handled with a few small additions, based on the code I found in this question on the Awesomium forums. I have changed my code to the following:

Read the rest of this entry »

Aug 07 2013

Using Awesomium with MonoGame

I have been recently working on incorporating the Awesomium framework into a MonoGame project I am working on, however actually getting it functional was proving a bit of a problem. There are a lot of examples of Awesomium working in XNA out there, but none that I could find for MonoGame – and the XNA samples proved not to work when ported directly across.

Read the rest of this entry »

Feb 23 2013

Generating Planets – Part Four – A Tree Structure

This post is going to continue on from the previous one with building systems that we will need, but not actually linking them back into the current code yet. This post is going to focus on how we can organize the faces of our icosahedron into a tree like structure.

You may have heard of a quadtree or an octree before, depending on how much you have investigated procedural generation before. They are both tree data structures that are commonly used in terrain generation. In a quadtree each node has four children, so this is used for our square based grids, while in an octree each node has eight children, making it useful for 3D voxel grids.

Read the rest of this entry »

Feb 18 2013

Generating Planets – Part Three – Traversing The Grid

A major problem with our subdivided icosahedron is that its a lot harder to move around the grid than it is with a simple square grid. Where in the latter you just increase the x or y co-ordinates to move through the array, our problem requires a more complex solution, one regrettably more complex than the solutions to the previous problem we have encountered.

Being able to move around the grid is an important feature for improving our planet as it will allow us to implement pathfinding which has uses in generation such as plotting the path of a river.

Read the rest of this entry »

Feb 12 2013

Generating Planets – Part Two – Terrain

So, in the previous post we generated our sphere, and in this post we are going to turn our smooth sphere into a planet with terrain. I am going to assume you already have a basic understanding of how fractal terrain generation works on a square grid, but if not you should first read this article.

With our subdivided icosahedron the terrain generation works in very much the same way, each time we are generating a new vertex we average it between the two parent vertices and then assign it a random modifier of its own. Depending on how exactly you implemented your algorithm this may require a number of different steps, but in this post I will describe it as if you are using a similar set up to the code linked in my previous post.

Read the rest of this entry »

Feb 10 2013

Generating Planets – Part One – Theory

Over the last two days I have been working on some code to generate planets in MonoGame, the content of this post however is general enough to be transferred to any language you wish to use.

When I first started investigating planet generation I hoped to be able to transfer the code I developed for my square grid heightmap terrain (for which a biome map is pictured below) onto a sphere. The problem with this however is that you can’t wrap a square grid around a sphere without some distortion as you go towards the poles.

Read the rest of this entry »

Aug 20 2011

XNA 4 Console Available!

My XNA 4 Console Developer console is now available for download! More details on its use here.

The console focuses on allowing you to write to it, rather than sending input to it, but the latter may be added in time.

Aug 15 2011

XNA Developer Console

Today I have been working on a Dev Console, similar in function to the native Console class, except that it is inside the game instead of in cmd. I want to make the class completely self contained so it can be easily dropped into any project.

Once complete, which shouldn’t take longer than another day, it should be an immense help to my development process as it means I will no longer need to use a string of breakpoints to track a variables progress. After cleaning the code up a bit I will release the class here for anyone to use. I aim to include the following features in the class by tomorrow, but almost all of them are complete at this point:

  • Entirely static – should be equally accessible from any class in the project.
  • Methods for defining the width, height and position of the console on the screen.
  • Functionality for clearing the console.
  • Methods to write either a single line or a list or array of lines.
  • Both of the above including an optional sender variable to be displayed after the message. All lines will display an index number justified to four places, e.g. 0001, 0002 … 0103.
  • Contains Update and Draw methods that allow for scrolling up and down the window with either the mouse wheel or chosen keys.
  • Options for displaying the console, for example key toggle or push to display.

An example line output would be:

0001: Variable A set to 100 [Project.Game1]

Eventually I would like to  include the following features, but they will most likely be added on my own need-to-use basis:

  • Input; reading lines and then executing a method defined by the input.
  • Ability to quickly drag-and-drop the window around the screen for custom positioning while in-game.
  • Output saved to a text file.
  • Customizable syntax options.
  • Indentation options to indicate lines having parents.
  • A sort of region option in order to expand or collapse areas of the list.
  • A ‘light’ version of the console that doesn’t include the built in update and draw methods and associated variables – simply supplying a list of strings to be interpreted by a UI of your choice.

Aug 14 2011

C# – Listing enumerations with their properties

A small supplementary post about how to list every element of an enumeration alongside a property derived from a method that uses the element.

I encountered this problem when wanting to list the various biomes in my World Generation project alongside the color they were represented by on the terrain. The first step was to convert the enumeration to an array of strings (listing each of the enum’s elements), which can easily be achieved with the following code:

string[] biomes = Enum.GetNames(typeof(BiomeType));

Where BiomeType was the name of the enum. This was all very well to write as a list to the screen but now I wanted to be able to covert each of the elements back from its string form to its enumeration form, in order to pass it through the method that returns the terrain color. After some investigation I found the following method to achieve this:

(BiomeType)Enum.Parse(typeof(BiomeType), biome))

Again where BiomeType was the name of the enumeration and biome was the element in string form.

Hopefully this short post will help at least one person at some point!

Older posts «