Monday, July 7, 2008

Create a neat 3D customizable maze for MRDS/MSRS

For my masters, I want to create a maze environment for the robots to navigate through. I found that I could not use all of [Trevor Taylor's code], because there were some errors. They probably have something to do with using C# 2008 and the latest MRDS framework. So I just modified it so that it can be used. The error I got when I tried to run the original code was:

Could not load file or assembly 'DssCmdArgs, Version=2.0.730.3, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.


So I took the code I needed and removed the DssCmdArgs reference and the corresponding namespace
using Microsoft.Dss.Tools.CommandLine;

I also took the Maze generation code from Chapter 9 and made the solution a complete package. So now I have a maze mesh generation tool. It's awesome. Another change you will notice is that it is in black and white only. The generation code as described in Professional MRDS does not seem to work well with colours. I was getting a maze mesh with a 'roof' on it - exactly what I do not want.



So the first thing you'll want is the program. It uses all code from Trevor Taylor and Kyle Johns, who in turn modified a Depth First Search algorithm implemented [HERE]. I put it all together and modified it as described. It may not be the most elegant, but it works well. Click [HERE] to download the complete code. It draws the maze and the 'generate' button will create a '.obj' file type for you.

To see the maze in the simulation environment is fairly simple. Generate a mesh using bmp2mesh (or you can create an load your own - click "Browse") and make sure you remember where you saved the .obj file. The program automatically allocates a name to the same location as the image.

Next load a simulation environment. To load the mesh, you want a new entity. Choose a TriangleMeshEnvironmentEntity entity. Once you have returned to the normal edit screen select the TriangleMeshEnvironmentEntity. Then click ok, but do not be concerned about the errors (you could just paste the entire path of the '.obj' file if you are that concerned about seeing errors). You must click 'Edit Entity.' Modify the EntityState and select the '.obj' file you created using my program. I strongly recommend you apply an effect, like Terrain.fx. I am still working on textures.



It may take a few seconds, but the mesh should load. You will be interested to know, the entity itself generates a '.bos' file for you. The mesh is actually sitting below the floor, so you can raise it if you want the walls higher.



There are several reasons why I prefer my solution:
  • Complete: It works neatly and in one package
  • Error-free: There are no unnecessary dependencies in the code
  • Usability: The form doesn't re-size for every maze generated, rather, it just stretches the maze image

The main limitation of my program is that you may only use bitmap images. The code may be modified and extended to support other file formats, but it is unnecessary.

0 incoming messages (comments):