Pointers on how to use Nine

Sep 21, 2011 at 2:06 PM

After reviewing quite a number of XNA 'game engine' tutorials and projects, I've recently spent a bit with Nine. I've studied the samples and read a lot of source code, and I thoroughly approve of the approach taken with XNA integration. Nine would have most of what I would need to produce the kind of game(s) I have in mind, and in many ways goes beyond what I need. It has cameras, lights, materials, meshes, animation, particles, geometry, collisions, shadows etc that would easily cover what I need. It seems a bit light on in the areas of input and 2D dialogs, but those are things I think I can handle. Although it has the lower level stuff, it seems to lack an object manager, scene manager and storage but I see those on the roadmap and it shouldn't be too hard to produce something simple meanwhile.

My question is: how to use the things that are there? The samples are good as far as they go, but there are so many features in the feature list and in the source code with no clear indication how they go together. The documentation is simply an extract of the source code comments, and mostly consists of one liners. The source is easy enough to read, but it's like a box full of Lego bricks. Massive potential, but where to start?

Specifically, the things I am struggling to understand are: the pipeline importers/processors; scene management; ray tracing and model picking; collisions; scene authoring.

I guess what I'm asking is whether there are any samples, no matter how basic or unpolished, that show how to use these features. Either that or any notes, references or pointers to that I could use to write my own samples.

Any assistance much appreciated.

Sep 21, 2011 at 9:00 PM
Edited Sep 21, 2011 at 9:32 PM

Hi dyork11,

Did you take a look at the samples from the last revision?

Besides looking on the code from last revisions, i was also browsing through the code of the Isle game (Change Set 19696). From what I understand, the author is transforming his XNA 3 game to a XNA 4 engine. As i noticed, a lot of things are taken from there, edited, reorganized and improved (checking for new commits every day). The game also contains a GUI library, that is easy portable to XNA 4.

Isles Game is a place worth looking into, and helps understand some concepts upon which the engine is built.

I guess yufeih will come with a much more helpful answer tomorrow :)

 

EDIT: Generally speaking, i've got the same impression about Lego bricks. It would be really helpful if yufeih could sketch a diagram showing which parts interact with each others, and mark the ones that are not yet implemented, because we are seeing just what has been done so far, and cant grasp the whole picture. Pointing out the missing parts, at least as some abstract components would help a lot.

Sep 22, 2011 at 1:16 AM

Hi Sidhnor -- thanks for the helpful reply.

I didn't look into Isles because it seemed very old: 2009, with XNA 2.0 dependencies. I've now checked the history and it seems to have been updated to XNA 3.0 at 19696. There are some further changes, but the entire thing was deleted at 36017, well before much of the new stuff was added. I'll have a look anyway, but don't hold high hopes.

The samples I've studied are as at Nine 1.0.0.0 revision 57036. There are 9 samples, of which 7 are similar to the ones in the Gallery on the front page, but not quite the same. I can't see a lot in the way of updated samples in the history between 57036 and the current revision 62362. I guess I should download 62362 and diff it, but do you think that will solve my problem or just add more Lego pieces?

I'm prepared to spend some time and effort on this and possibly contribute to the engine, but unless I can find a way in it could finish up just being all too hard. Can I ask what you are using it for, and how far in you've managed to get?

Coordinator
Sep 22, 2011 at 6:55 AM
Edited Sep 22, 2011 at 6:56 AM

Hi dyork11,

I totally understand your concern, so I was trying to close the gap between a mass of Lego bricks and a finished piece.

Nine 1.0 was a collection of reusable pieces, each individual functionality can be intregrated easily into an existing game. But it lacks a way to unify and group them together. So I was working towards a 1.2 release that will have a centrialized way to manage scenes and objects, handle object picking and authoring though the content pipeline. But it is not finished yet, you can get the idea from the Game sample in the latest source code, it's not quite finished up, but it should provide you with a clue of where I am heading.

"I guess what I'm asking is whether there are any samples, no matter how basic or unpolished, that show how to use these features. Either that or any notes, references or pointers to that I could use to write my own samples."

Unfornately there aren't much samples and documentations besides the ones provided with the source code, because I haven't got enough time to work on it :-) I'm not a good writer, so I think I am going to finish the object model first. But if anyone would like to help, I would definitely love to share where to go for to implement a specific feature.

"It would be really helpful if yufeih could sketch a diagram showing which parts interact with each others, and mark the ones that are not yet implemented, because we are seeing just what has been done so far, and cant grasp the whole picture. Pointing out the missing parts, at least as some abstract components would help a lot."

Thanks for the comment, it's really a good suggestion. I did had a picture in my head, so I think I should illustrate that.

 

Sep 22, 2011 at 7:32 AM
yufeih wrote:

Unfornately there aren't much samples and documentations besides the ones provided with the source code, because I haven't got enough time to work on it :-) I'm not a good writer, so I think I am going to finish the object model first. But if anyone would like to help, I would definitely love to share where to go for to implement a specific feature

I would like to help.

Coordinator
Sep 22, 2011 at 9:17 AM

Cool, I'm going to add you as a developer so there's no need to apply patches everytime :-)

Cheers.

Sep 23, 2011 at 7:32 AM

OK, it does look like I should be working with the tip (more or less) rather than ancient history. I've diff'ed some of the code and there is lots of good stuff, plus the Game project. Only problem is: it won't build.

I assume the idea is: set vcvars to VS2010 then run build.bat? No joy.

First time: builds a couple of projects, then errors:

Nine.Content.Model.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.
Nine.Content.Reader.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.
Nine.Content.Writer.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.

Second time, won't build at all. It destroys the *.generated.cs files. Looks like you've got a circular build.

So far I can't figure out how the build works well enough to debug it. Any clues appreciated.

Coordinator
Sep 23, 2011 at 8:42 AM
At the time if the text template failed the build would fail. You have to manually clean the contents (not deleting them) of the *.cs files under Tools\TextTemplates\ folder. In the future I'll add a script to clear that automatically :-(

The error you encountered seems to be that the t4 engine cannot locate "Microsoft.Xna.Framework.Graphics.dll", so make sure it is there in the GAC.
If that always fail, you need to do a fresh checkout, then build Nine.sln directly, or comment out these lines in Build/Framework.bat then run the build by double click Build.bat (You might have to right click and select Run As Administrator if you have UAC enabled)

pushd Tools\TextTemplates
for /f "delims=" %%i in ('dir /b /a-d "*.tt"') do (
"%CommonProgramFiles%\Microsoft Shared\TextTemplating\1.2\texttransform.exe" -out %%~ni.Generated.cs %%i
"%CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\10.0\texttransform.exe" -out %%~ni.Generated.cs %%i
)

popd
call %msbuild% %flags% Framework\Nine\Nine.csproj
call %msbuild% %flags% Framework\Nine.Graphics\Nine.Graphics.csproj

pushd Tools\TextTemplates
for /f "delims=" %%i in ('dir /b /a-d "*.tt"') do (
"%CommonProgramFiles%\Microsoft Shared\TextTemplating\1.2\texttransform.exe" -out %%~ni.Generated.cs %%i
"%CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\10.0\texttransform.exe" -out %%~ni.Generated.cs %%i
)

popd
Let's hope you could make it :-)
Sep 23, 2011 at 11:20 AM

Yes, I figured that out now. The relevant lines are these:

<#@ assembly name="System.Core" #>
<#@ assembly name="Microsoft.Xna.Framework" #>
<#@ assembly name="Microsoft.Xna.Framework.Graphics" #>
<#@ assembly name="System.Windows.Forms" #>

The first two are OK, third fails. The only suggestion I have is that there is nothing here to select an XNA version, and I have multiple versions installed. If it chose XNA 3.1, there is no Framework.Graphics to go with that. Just an idea. :)

Yes, it builds in VS from a fresh checkout, but the references in Sample are broken, so nothing there builds. Is this because the BAT files do something the SLN doesn't? I didn't see anywhere updating the GAC.

Anyway, the good news is that by manually fixing the references, the Game project builds and runs. That lets me see the scene manager in action, which is something I was hoping for. I assume a world editor is just around the corner?

I have enough to play with for now, but I think you do yourself a disservice by not spending just a little time to push out an update with good samples and a bit more class-level documentation. This is the best FOSS framework I've found with a fair bit of looking, and it deserves to be better known.

Sep 24, 2011 at 11:17 AM

Couple of follow on questions...

The documentation requires Sandcastle to build, yes? Any particular version? I would like to be able to get that.

Is there any easy way to find out what input the various pipeline processors use? From reading the source I can see how to track down any specific tag, but it's not so easy to see which tags are available. Or is that in the docs?

What is it that drives animation? Why do some dudes walk and others don't, and how would I invoke a different animation for a particular dude?

Any help much appreciated.

dy

Coordinator
Sep 24, 2011 at 12:54 PM
I think it should be the latest version of Sandcastle. I mean Sandcastle Help File Builder, a Gui extension to sandcastle.

I don't quite get your second question, a content processor always has an input type and an output type, you can see it from the signature of its parent ContentProcessor<TInput, TOutput>.

For your third question, the final rendered output of a model is determined by its material, if a material does not support hardware skinning, then the animation is ignored. In this case, DualTexture/Basic/AlphaTest and some custom materials do not support skinning, so the model is static. If you are using ModelMaterial, you can enabled skinning by setting SkinningEnabled to true.

I think there is a DrawableModel.Animatioins, you can call the AnimationPlayer.Play method with the name of the animation track. For more advanced animation scenarios, check out the animation sample and create a custom BoneAnimation and play that using the AnimationPlayer.

Thanks.
Sep 24, 2011 at 3:08 PM

Re Q2: I'm trying to create a Scene file. The question is: what determines valid tags for the Item Type, and within an item, what determines valid tags for property values.

I see that SkyBoxContent is a partial class in TextTemplates\Nine.Graphics.Content.Model.Generated.cs, and its properties are Texture, Transform and Visible. I can trace that through to Nine.Graphics.ObjectModel.SkyBox and see the code.

Perhaps the answer is simply: whatever you find in Nine.Graphics.Content.Model.Generated.cs are valid items and properties in a Scene file. Or is it not that simple?

Q1, Q3: thanks -- that will keep me moving.

dy

Coordinator
Sep 25, 2011 at 2:41 AM
Yes, you can lookup the properties in the Nine.Graphics.Content.Model.Generated.cs file, but types that can be added to a scene must be under the Nine.Content.Pipeline.Graphics.ObjectModel namespace.

What would make lives easier is to have an Xml Schema that includes all the possible types and properties, however, the Xna xml file format uses the "Type" attribute to determine which type to use when working with polymorphisms, while an Xml Schema uses element names, so there's no way to create such schema. We either forget about Xna schema or looking for alternative serializers (namely XmlSerializer and XamlSerializer in my head), I'm still investigating the possibility of using something to replace the Xna intermediate serializer, but for now, you have to manually look into our content class definition. Luckily, most of the properties are sorted alphabetically, makes it easier to manage the order of the properties.

Ofcourse for the long term, I would love to have an editor or an exporter that transforms a scene into this Xml file directly. You never want to write these Xmls for a real game level!
Sep 25, 2011 at 11:11 AM

I'm not too troubled by the use of Types. This is good enough for now and in due course a world editor should make it academic. There are more pressing problems.

Q1.Any suggestions how to get the Build to work? If you recall, it can't find my Xna.Framework.Graphics (which works fine in other XNA 4.0 projects).

Q2. If no, how do I get the Sample references to link to the Nine assemblies? The references have no path; they work fine if I hand fix them all, but that shouldn't be necessary. I don't see any GAC stuff.

Q3. I have a (minimal) working Scene.xml using my own skybox and textured models and a couple of lights (Great!). What I don't have is the kind of brain that can compute transformation matrices on the fly. Suggestions?

Q4. The models seem to be loaded anonymously. Is there a way to name them so they can be retrieved and manipulated by run-time code?

Q5. I've been looking for a suitable camera: with look at perspective, up is up, and better control over how it moves. I guess I'll need to roll my own?

Q6. Do you have any plans for enhancing the Input system, or should I plan on some work there too?

Sorry about the questions, but these are things I'm having difficulty figuring out -- any answers much appreciated.

dy

 

Coordinator
Sep 25, 2011 at 11:59 AM
Edited Sep 25, 2011 at 12:01 PM
Q1: Try modify the t4 template to use "Microsoft.Xna.Framework.Graphics, Version 4.0.0.0" or "Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553" instead of "Microsoft.Xna.Framework.Graphics". I haven't tried, but that might work. If it did work, please submit a patch :-)

Q2: It is stored in the registry, Framework.bat contains the code to register the assemblies. (refer to http://msdn.microsoft.com/en-us/library/ff966437.aspx)

Q3: I will add the Position/Rotation/Scale properties to the models. But like I said, you never wanted to manually write these xml files for a real game, so before we introduce an level editor (Could take forever to make that), you should figure out a way to create levels (Any editor that can produce a readable format) and convert them into our Xml format.

Q4: Yes, using any of the Scene.Find method. Please note that at the current stage, the Scene class is pretty preliminary and we're going to add more funtionality to it.

Q5: Yes, because cameras are very different for each game. You can take a look at the QuaternionCamera and derive one from it.

Q6: I'm interested in what kind of funtionality do you want for an input system. Do you want an input system that could power a sophisticated UI, or Keyboard mapping or gesture recognition? Our input system is just an event driven wrapper around the traditional pulled model.

Thanks.
Sep 26, 2011 at 5:35 AM

Q1: Solved. "Microsoft.Xna.Framework.Graphics, Version 4.0.0.0" is the answer. Hopefully I can submit a patch if/when I figure out how. Now the build works, except it breaks on Silverlight, Sandcastle and Wix (I don't have the necessary bits). Also: lots of errors on missing/ambiguous DisplayName (see Q7).

Q2: Solved. I had updated the registry but with the wrong path. Fixed the path, all worked. Now the samples work (except one). Customer effects has an error to do with "mixed shader model". Changing the vertex shader in check3d.fx fixes it. Could be a bug?

        VertexShader = compile vs_3_0 mainVS();
        //VertexShader = compile vs_2_0 mainVS(); //bug???

Q3: It's not just models with the Transform problem: textures and lights have it too. Without having thought about it much, I would expect to use a Scene.xml per level for static scenery and a LevelX.xml for the game play arena. A Scene editor just has to (a) display the scene (b) insert/delete/select an asset (c) present a .NET property page for editing its properties (including Scale/Rotate/Translate). How hard can that be? :)

Q4: Not solved. Scene.Find() works on where the thing now is, but I want to choose by identity. I think you need a Name property and a Scene.FindByname().

Q5: Cameras. Quaternion has some good basics, but too low level.  I'll put some thoughts into a separate post.

Q6: Input. Separate post for that too.


Q7: Errors building the samples, every sample has one like this. Only since successfully running the build.bat. Not if I build in VS.

D:\MyDocs\Active\vs10-xna4\Samples\nine-62362\Samples\DebuggerPrimitives\DebuggerPrimitives\DebuggerPrimitiveGame.cs(26,6): error CS0246: The type or namespace name 'DisplayName' could not be found (are you missing a using directive or an assembly reference?)
D:\MyDocs\Active\vs10-xna4\Samples\nine-62362\Samples\DebuggerPrimitives\DebuggerPrimitives\DebuggerPrimitiveGame.cs(26,6): error CS0104: 'DisplayNameAttribute' is an ambiguous reference between 'Nine.DisplayNameAttribute' and 'System.ComponentModel.DisplayNameAttribute'

Sep 26, 2011 at 2:18 PM

Q1: sorry, build problems are still not solved. I still can't get the build to work if the *.generated.cs don't already exist. Any build error tends to destroy those files, and then I have to copy them back from the repository. I've given up -- the only reliable way for me is to build in VS.

Minor bug: Nine.Pipeline is not included in the build for Platform:x86 (or anything else except Mixed).

Q7: goes away if I build in VS, so another reason to regard the batch build as broken for now.

Coordinator
Sep 28, 2011 at 7:09 AM

I think it might be caused by a mixed installation of Xna 3.1 and 4.0, I'll try to reproduce that environment.

Sep 30, 2011 at 11:14 AM

Could be. I would recommend adding at least version no to each of your usings to avoid ambiguity. It looks like just a minor fix, not worth spending much time on.

The real problem (for me) is the circular build. I've tried to figure out how to build the template generated code from scratch, but there is something I don't get. There seems to be a pre-compile with TEXT_TEMPLATE defined, but that pre-compile fails unless the generated code is already present. I can't see how to fix that.

I would also like to be able to do an x86 only, PC only, Debug build. That's broken too, but I was able to fix the solution (other than the circular template problem). I still can't do it in batch.

I'll raise tickets for these if you'd prefer it.

Coordinator
Oct 5, 2011 at 11:01 AM
Edited Oct 5, 2011 at 11:02 AM

I've tested on my 2 machines with both 3.1 and 4.0 installed, builds successfully.

Can you show me the build log? Fresh checkout and run "Build.bat >> log.txt" from command line.

Oct 6, 2011 at 12:01 AM

That was the easy bit. How to upload the file?

Command line:

Build.bat >> log.txt 2>&1

Chunk of log:

Done Building Project "D:\temp\nine-62362\Framework\Nine.Graphics\Nine.Graphics.csproj" (default targets).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.21
Nine.Content.Model.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.
Nine.Content.Reader.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.
Nine.Content.Writer.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.
Nine.Graphics.Content.Model.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.
Nine.Graphics.Content.Reader.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.
Nine.Graphics.Content.Writer.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.
Nine.Graphics.Materials.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.Xna.Framework.Graphics' could not be found
The system cannot find the path specified.

Content of Nine.Content.Model.generated.cs (ie destroyed)

ErrorGeneratingOutput
Second run with #include edited.

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.86
Nine.Content.Model.tt(-1,-1) : error : The host threw an exception while trying to resolve the assembly reference 'Microsoft.Xna.Framework, Version 4.0.0.0'. The transformation will not be run. The following Exception was thrown:
System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
   at System.Reflection.AssemblyName.nInit(Assembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
   at System.Reflection.AssemblyName.nInit()
   at System.Reflection.AssemblyName..ctor(String assemblyName)
   at Microsoft.VisualStudio.TextTemplating.GlobalAssemblyCacheHelper.GetLocation(String strongName)
   at Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost.ResolveAssemblyReference(String assemblyReference)
   at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String generatorCode, ITextTemplatingEngineHost host, TemplateProcessingSession session)
Nine.Content.Model.tt(-1,-1) : error : The host threw an exception while trying to resolve the assembly reference 'Microsoft.Xna.Framework.Graphics, Version 4.0.0.0'. The transformation will not be run. The following Exception was thrown:
System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
   at System.Reflection.AssemblyName.nInit(Assembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
   at System.Reflection.AssemblyName.nInit()
   at System.Reflection.AssemblyName..ctor(String assemblyName)
   at Microsoft.VisualStudio.TextTemplating.GlobalAssemblyCacheHelper.GetLocation(String strongName)
   at Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost.ResolveAssemblyReference(String assemblyReference)
   at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String generatorCode, ITextTemplatingEngineHost host, TemplateProcessingSession session)