A few posts back I reported that I had finished converting everything to get my XNA 3.1 code to work in XNA 4.0. Well I was close and everything worked on the PC but when I came to test on the Xbox I had some errors. Proper game stopping exceptions.
It's taken a few hours on and off to narrow down the problem and it's fixed now. The problem was code I had written to replace point sprites in one of my particle systems. Point sprites are no longer available in XNA. That is not a problem because triangle lists do the job just as well. The trouble was that I did not fully understand how vertexBuffers work and that the Xbox cannot reuse vertices until the GPU has finished with them.
In my defence the posts I read to find out how to resolve my issues were posted by some well respected programmers who were also caught out by the Xbox behaviour.
If you want to know more the comments in the code for the particle system sample were useful:
http://create.msdn.com/en-US/education/catalog/sample/particle_3d
As were the comments in the following old post:
http://forums.create.msdn.com/forums/t/33931.aspx
Now at last I can get on with editing some models and creating some more animations for use in the game.
Sunday, 12 December 2010
Saturday, 4 December 2010
Blender to XNA to be included in the next release of Blender
There is a good chance that the script I have just written to export from Blender to XNA will be included in the next release of Blender. Apparently it has to be tested and approved by some of the Blender administrators but it is already on their SVN server.
The instructions are now on a Blender Wiki page:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Blender-toXNA
The instructions are now on a Blender Wiki page:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Blender-toXNA
Tuesday, 30 November 2010
Blender 2.5 to XNA 4 animated FBX models
The following post is out of date because as from Blender 2.56 the scripts mentioned are all shipped with Blender. See the following post for more up to date information:
http://blog.diabolicalgame.co.uk/2011/07/exporting-animated-models-from-blender.html
==
Following on from my previous post on this subject I have managed to create an FBX exporter script for Blender 2.55 Beta that works with keyframe animations and imports in to XNA 4.0.
Due to the limitations with the Autodesk FBX importer that ships with XNA 4.0 the animations need to be loaded individually from separate FBX files but there are simple solutions available to work with that. Details and other links are in the Instructions with each of the following projects:
The package with several XNA FBX exporters for Blender 2.5 can be downloaded from:
http://code.google.com/p/blender-to-xna/
The most recent instructions are on the Blender Wiki:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Blender-toXNA
An XNA model viewer that has an option to load FBX files as separate animations:
https://code.google.com/p/take-extractor/
The XNA TakeExtractor project also demonstrates how to rotate models and their animations within the pipeline. That is useful for adjusting Blender models which face Z up to XNA's default which is Y up. Use a rotation while loading of X = 90, Y = 0, Z = 180. I think that ends up facing backwards because that is how my entire game appears to work and there is too much code for me to bother to change it!
http://blog.diabolicalgame.co.uk/2011/07/exporting-animated-models-from-blender.html
==
Following on from my previous post on this subject I have managed to create an FBX exporter script for Blender 2.55 Beta that works with keyframe animations and imports in to XNA 4.0.
Due to the limitations with the Autodesk FBX importer that ships with XNA 4.0 the animations need to be loaded individually from separate FBX files but there are simple solutions available to work with that. Details and other links are in the Instructions with each of the following projects:
The package with several XNA FBX exporters for Blender 2.5 can be downloaded from:
http://code.google.com/p/blender-to-xna/
The most recent instructions are on the Blender Wiki:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Blender-toXNA
An XNA model viewer that has an option to load FBX files as separate animations:
https://code.google.com/p/take-extractor/
The XNA TakeExtractor project also demonstrates how to rotate models and their animations within the pipeline. That is useful for adjusting Blender models which face Z up to XNA's default which is Y up. Use a rotation while loading of X = 90, Y = 0, Z = 180. I think that ends up facing backwards because that is how my entire game appears to work and there is too much code for me to bother to change it!
Friday, 26 November 2010
Blender 2.5 to XNA 4 animated model pipeline
See the future linked post for more up to date information:
http://blog.diabolicalgame.co.uk/2011/07/exporting-animated-models-from-blender.html
The following is a bit out of date. If you want to know how to get models from Blender to XNA read the above linked post not this one.
==
It's been a while since I posted because I have been struggling with a problem since I finished the conversion to XNA 4.
As mentioned in my previous post, animated models from Blender would no longer display properly in XNA. If I had imported the animation in XNA 3.1 they would still work in 4.0 but when I tried to save new animations from the models using XNA 4, the animations were distorted.
I tried fixing the FBX exporter from Blender but the FBX file format is not documented making it difficult. To cut a long story short I have ended up with a solution that uses separate files for the animations.
The model, bones and bind pose are loaded in to XNA using FBX. Each animation is exported from Blender as a list of bone transform matrices. Those can then be imported in to XNA and converted to the AnimationClip format used by the Microsoft Skinning Sample. Edit: I now have FBX working see my next post.
The process takes a few steps but works with the models I have been using. It needs more testing with other models.
The package with several exporters for Blender 2.5 can be downloaded from:
http://code.google.com/p/blender-to-xna/
The most recent instructions are on the Blender Wiki:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Blender-toXNA
The XNA sample and model viewer demonstrating how to import the animations can be downloaded from:
https://code.google.com/p/take-extractor/
Both are on Google Code, if the links do not initially work, wait an hour and try again. Google appear to have frequent outages but none so far have lasted longer than an hour.
There are still several limitations with the pipeline some are the same limitations as with earlier versions of XNA and Blender:
- All parts (Blender Objects) of a model must have the same centre (Origin, ideally at Zero)
- All parts of the model must have a scale of 1.0
- Every vertex must be weight painted or added to the bone vertex group for animation.
- The model has to be loaded in XNA before the animations can be converted to AnimationClip format.
At the moment the animations cannot be rotated in the content pipeline! [Fixed, see future posts] My next job is to work out the maths to rotate the animations as they are imported.
==
Please make sure you read my future posts. I have done a lot more work to get it all working properly.
http://blog.diabolicalgame.co.uk/2011/07/exporting-animated-models-from-blender.html
The following is a bit out of date. If you want to know how to get models from Blender to XNA read the above linked post not this one.
==
It's been a while since I posted because I have been struggling with a problem since I finished the conversion to XNA 4.
As mentioned in my previous post, animated models from Blender would no longer display properly in XNA. If I had imported the animation in XNA 3.1 they would still work in 4.0 but when I tried to save new animations from the models using XNA 4, the animations were distorted.
I tried fixing the FBX exporter from Blender but the FBX file format is not documented making it difficult. To cut a long story short I have ended up with a solution that uses separate files for the animations.
The model, bones and bind pose are loaded in to XNA using FBX. Each animation is exported from Blender as a list of bone transform matrices. Those can then be imported in to XNA and converted to the AnimationClip format used by the Microsoft Skinning Sample. Edit: I now have FBX working see my next post.
The process takes a few steps but works with the models I have been using. It needs more testing with other models.
The package with several exporters for Blender 2.5 can be downloaded from:
http://code.google.com/p/blender-to-xna/
The most recent instructions are on the Blender Wiki:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Blender-toXNA
The XNA sample and model viewer demonstrating how to import the animations can be downloaded from:
https://code.google.com/p/take-extractor/
Both are on Google Code, if the links do not initially work, wait an hour and try again. Google appear to have frequent outages but none so far have lasted longer than an hour.
There are still several limitations with the pipeline some are the same limitations as with earlier versions of XNA and Blender:
- All parts (Blender Objects) of a model must have the same centre (Origin, ideally at Zero)
- All parts of the model must have a scale of 1.0
- Every vertex must be weight painted or added to the bone vertex group for animation.
- The model has to be loaded in XNA before the animations can be converted to AnimationClip format.
At the moment the animations cannot be rotated in the content pipeline! [Fixed, see future posts] My next job is to work out the maths to rotate the animations as they are imported.
==
Please make sure you read my future posts. I have done a lot more work to get it all working properly.
Monday, 15 November 2010
Dude for Blender
I have converted the Dude from the Microsoft XNA Skinning Sample in to Blender format. The transfer is not ideal but is enough to provide a starting point.
Dude in Blender
I have added an armature (bones) for animation and a test action called 'Walk'. This is for my own purposes but may be useful to others. It gives an idea of scale and a suitable mesh quality for use in games. Please note that my test animation is very poor.
Download Model
Dude for Blender (9.5Mb) March 2009 (Imperial scale)
Test Dude Animations (8.5Mb) November 2010 (Metric scale)
Dude in Blender
I have added an armature (bones) for animation and a test action called 'Walk'. This is for my own purposes but may be useful to others. It gives an idea of scale and a suitable mesh quality for use in games. Please note that my test animation is very poor.
Download Model
Dude for Blender (9.5Mb) March 2009 (Imperial scale)
Test Dude Animations (8.5Mb) November 2010 (Metric scale)
Saturday, 30 October 2010
Finished converting to XNA 4.0
At last I have done the final bit so that I can say I have everything in XNA 4.0 that I had in XNA 3.1
This final part was not a code change to the game but is a way to get animations from my models created in Blender in to XNA. In XNA 3.1 the FBX importer could read multiple takes from one FBX file and I took advantage of that to import all the animations. That is no longer built in to the FBX importer.
I am rather pleased with my solution. It is much more elegant than before. I have created myself a WinForm based application that can read FBX files created from Blender. It can split them in to one file per take and export the animation key frames in to the format I need.
Compared to games it is not a very pretty presentation. Functional with a text status window.
I can create a config file per model so that the extraction, conversion and renaming of takes, to match my in game requirements, is reproducible. I should probably have done it this way in the first place.
If you are interested the source code can be downloaded from:
http://code.google.com/p/take-extractor/
I can now remove a lot of redundant code from my game editor.
Edit: I spoke too soon. The animations do not work properly from XNA 4.0 so I still need an XNA 3.1 utility just to get the animations right. The game will still be in XNA 4.0! I'm trying to find an alternate exporter for Blender or other method to be able to use only XNA 4.
This final part was not a code change to the game but is a way to get animations from my models created in Blender in to XNA. In XNA 3.1 the FBX importer could read multiple takes from one FBX file and I took advantage of that to import all the animations. That is no longer built in to the FBX importer.
I am rather pleased with my solution. It is much more elegant than before. I have created myself a WinForm based application that can read FBX files created from Blender. It can split them in to one file per take and export the animation key frames in to the format I need.
Compared to games it is not a very pretty presentation. Functional with a text status window.
I can create a config file per model so that the extraction, conversion and renaming of takes, to match my in game requirements, is reproducible. I should probably have done it this way in the first place.
If you are interested the source code can be downloaded from:
http://code.google.com/p/take-extractor/
I can now remove a lot of redundant code from my game editor.
Edit: I spoke too soon. The animations do not work properly from XNA 4.0 so I still need an XNA 3.1 utility just to get the animations right. The game will still be in XNA 4.0! I'm trying to find an alternate exporter for Blender or other method to be able to use only XNA 4.
Monday, 18 October 2010
Anti-Aliasing with XNA 4
I've spent all weekend struggling with getting Anti-Aliasing (AA) working with XNA 4. I compared my old XNA 3.1 version with my updated XNA 4 version and noticed that the graphics on the menus looked awful on the new one!
This was obviously because AA, multi-sampling, was not enabled on the new version. Some of the settings used to enable this in XNA 3.1 had been replaced in XNA 4. I therefore spent a lot of the weekend on the assumption that I just needed to get the settings right within XNA.
I asked for help on the XNA forums so you can read the saga there as well.
To demonstrate the problem, the following rather rough picture is a small portion of the screen illustrating the effect:
The following much smoother shot shows what I was expecting:
To cut a long frustrating story short. On advice I created a small app that had nothing but one model and a background and that helped to narrow the problem down. It was not within the XNA code but it was in the HLSL shader code.
These three lines turn off anti-aliasing in XNA 4.0 and do nothing in XNA 3.1!
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
I removed those three lines and everything was back to what I expected. This is the end result:
I've gone a little further and checked out the other options for the texture filters when set within the HLSL fx file. I got the options from the following web page:
http://msdn.microsoft.com/en-us/library/bb322811(VS.85).aspx
The results are:
Min, Mag and Mip filters = Point -> AA gets turned off
Min, Mag and Mip filters = Linear -> AA works
Min and Mag filters = Anisotropic -> AA works
Mip filter = None -> AA works but the result was grainy
Min and Mag filters = PyramidalQuad -> Failed to compile
Min and Mag filters = GaussianQuad -> Failed to compile
My conclusion is that I should remove everything from my HLSL effect files that can now be set within XNA 4.0 and I should set those from within XNA. As always one of Shawn Hargreaves blog posts is most useful for that.
[Edit: change of plan again. I completely re-wrote my shaders and now the filtering is in XNA code... again.]
This was obviously because AA, multi-sampling, was not enabled on the new version. Some of the settings used to enable this in XNA 3.1 had been replaced in XNA 4. I therefore spent a lot of the weekend on the assumption that I just needed to get the settings right within XNA.
I asked for help on the XNA forums so you can read the saga there as well.
To demonstrate the problem, the following rather rough picture is a small portion of the screen illustrating the effect:
The following much smoother shot shows what I was expecting:
To cut a long frustrating story short. On advice I created a small app that had nothing but one model and a background and that helped to narrow the problem down. It was not within the XNA code but it was in the HLSL shader code.
These three lines turn off anti-aliasing in XNA 4.0 and do nothing in XNA 3.1!
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
I removed those three lines and everything was back to what I expected. This is the end result:
I've gone a little further and checked out the other options for the texture filters when set within the HLSL fx file. I got the options from the following web page:
http://msdn.microsoft.com/en-us/library/bb322811(VS.85).aspx
The results are:
Min, Mag and Mip filters = Point -> AA gets turned off
Min, Mag and Mip filters = Linear -> AA works
Min and Mag filters = Anisotropic -> AA works
Mip filter = None -> AA works but the result was grainy
Min and Mag filters = PyramidalQuad -> Failed to compile
Min and Mag filters = GaussianQuad -> Failed to compile
My conclusion is that I should remove everything from my HLSL effect files that can now be set within XNA 4.0 and I should set those from within XNA. As always one of Shawn Hargreaves blog posts is most useful for that.
[Edit: change of plan again. I completely re-wrote my shaders and now the filtering is in XNA code... again.]
Subscribe to:
Posts (Atom)






