Step 1: Load 3D World Studio
Design a map in 3D World Studio, apply textures to faces as needed, and save as a .3dw file. I saved mine as Test01.3dw You can use one of the demo maps that comes with 3D World Studio or create your own. To make it interesting, use a texture that has a noticable repeating pattern. Here is one of the demo maps as I'm applying some of my textures to it: Image coming soon, CodePlex must be full again :(

Step 2: Create surface files
I used three textures for this map, so I need to define three Surface Files to describe how shaders will render these surfaces. On the walls I've applied brick02.png, and here is the surface file that I'll place in the folder next to my Test01.3dw file:

<surface effect="Effects\Standard.fx" assetName="Content\Effects\Standard">
	<texture parameter="DiffuseTexture" assetName="Content\Textures\Brick02">Textures\Brick02.png</texture>

It should be pretty easy to see where this is going. Here is a snippet from the Standard.fx file that shows you how that parameter attribute comes in handy:

uniform extern texture DiffuseTexture;
sampler DiffuseSampler = sampler_state
    Texture = <DiffuseTexture>;
    AddressU = Wrap;
    AddressV = Wrap;
    MaxAnisotropy = 16;

Step 3: Add the StrangeThings content pipeline to your project
You can either add the source code, or a built version, or start from the project found on the Source Control tab. Check the Game Studio Express and/or MSBuild documentation for whichever method you're using. I have two projects of interest:
  • StrangeThings.ContentPipeline - This project loads .3dw files and creates GSE .xnb files. You do not need to deploy this project.
  • StrangeThings.Framework - This project contains the Level object which you will use to render your levels. This project must be deployed with your game.

Step 4: Add a Level to your game
Typically, some folder structure similar to the following is used. Add these folders and files to your project as needed. They will of course vary based on usage:
|  \--Effects\
|  |  \  +Standard.fx
|  \--Textures\
|  |  |  +Brick02.png
|  |  |  +Wall01.png
|  |  \  +Stone22.png
|  |  +Test01.3dw
|  |  +Brick02.xml
|  |  +Wall01.xml
|  \  +Stone22.xml
|  +MyGame.cs
\  +Program.cs

Note: When you add the following files, add them with the settings 'Build Action = Content', 'Copy to Output Director = Do not copy', 'XNA Framework Content = False':
  • Standard.fx
  • Brick02.png
  • Wall01.png
  • Stone22.png
  • Brick02.xml
  • Wall01.xml
  • Stone22.xml
(These files are here just to make it easy to click on them and edit them. The Content Pipeline will load and build them as needed. Oh, and as an aside, any edits you make to any of these files will cause rebuild of your level the next time you build - which is quite handy :)

Add the 'Test01.3dw' file with these settings:
  • Asset Name = Test01
  • Build Action = Content
  • Content Importer = StrangeThings Level Importer (.3dw)
  • Content Processor = StrangeThings Level Processor (.3dw)
  • Copy to Output Directory = Do not copy
  • XNA Framework Content = True

Step 5: Fill in the missing pieces
At this point, you may find yourself lacking shaders, textures, etc. Feel free to steal (per my License) any of my assets or find your own. Check the XNA Creators Club site or Turbo Squid for anything you need.

Step 6: Add the needed code to your game!
In your LoadGraphicsContent() method override, you should do something similar to the following:
protected override void LoadGraphicsContent(bool loadAllContent)
    if (loadAllContent)
        ContentManager manager = new ContentManager(this);
        this._level = manager.Load<StrangeThings.Framework.Level>("Content\\Test01");

(This loads the pre-built content into a StrangeThings Level object - your code may vary greatly)

In your Draw() method override, you will have to come up with the following things on your own:
  • WorldViewProjection matrix: Load each shader you reference in your Surface Files and set the WVP matrix as needed. I don't do this for you, so you'll have to do it once per frame on your own.
  • Camera Position: This is the Vector3 position of the viewers eyeball.
  • Camera Frustum: Your camera class (not provided) should have this value - I need it for visibility determination.

Then, call the Level.Draw(), something like this:
this._level.Draw(this._camera.Position, this._camera.Frustum);

  • Each of the effects you reference in surface file will automatically set it's textures before drawing.
  • You can load the effect to set values by using the AssetName specified in the appropriate Surface Files.
  • If you have one effect that has a large number of parameters, you can specify different asset names in your Surface Files, but still specify the same .fx file. This will cause the .fx file to be built a second time, which may make it easy to use. Or not, it's all up to you.
  • You must set any non-texture parameters yourself. These might include: Time values, WVP Matrices, etc.

Last edited Mar 11, 2007 at 10:34 PM by Johnnylightbulb, version 1


No comments yet.