Sunday, February 25, 2007

Something Playable

After playing around with laying models, I figured I might as well go ahead and make something playable with it. So I managed to load in the Player, some models and animated models, and have the player run around in the scene taking pictures.


This is the default view of the scenes.

Switch to First person view to take pictures


After a couple of shots, press the right shoulder button to view the pictures you have taken. The current active one is indicated by the Bold Red number. Here are the run through of all the picture taken above:











Will upload the source code later tonight for Monday's Lab!
It's quite fun to play, running around shooting photos and all! All it needs now is a purpose for taking those photos...In other words, it needs a GAME :P

Friday, February 23, 2007

Playing around with Perspectives...

I was fiddling around with some XNA coding using mainly the Animation component, and it was quite simple to create a basic 3D universe and put models on them.
With whatever little math knowledge that i have, i created a simple perspective engine to see the 3d world from above and from first person.



See that guy above? He's our protagonist. He's standing between a copter and a Nissan car. At this moment, you can actually control him. Left/Right to rotate his orientation, Up and Down to move forward/ backwards.

Switch to first person view (Hold Space bar on Windows or Left Trigger on XBOX) from the above spot and this is what you see. Hold on to the trigger button to stay in First person mode. You can still move around, turn left or right and tilt up and down in first person mode.


Move him behind the car now, and look at the Car's plate number. I managed to find a way to tilt his head up and down to simulate looking up and down.


Here's the car's plate no.


And here's after i tilt up to focus on the copter.

This is just another view of the scene from the front of the car


Erik : I uploaded the Source code to our Project folder (not the CS4343 community), under the folder XNA, file name : 18862.rar. This is using the latest Animation Component source code, and if you look through the solution, you can see I am also playing around with another component to draw fonts in XNA, called Nuclex.Fonts, can be found here.

Next thing to do:
- Create some scenes
- Implement the Photo/ Scene Engine for the Gameplay
- Class/ Data structure/ XML ? For scalability

Wednesday, February 21, 2007

Steps to create a scene

I don't know whether this is necessary, but it's just something to hopefully get us kicking :P

  1. Choose your models and take note of which ones you are using
  2. Create a new working folder, call it Scene1 or whatever, then dump all the textures for all the models that you choose into that folder.
  3. Create a new Maya scene, import the models which you are going to use for the scene. Remember to check “Merge” to insert the model into your current scene.
  4. Before you make your animations, please save the scene first, as a sort of base for the animation. Basically this is just a preparation for the animation, so make sure you scale the models correctly, rotate them if their orientation is different etc.
  5. Now you can animate the models!
  6. Save the scene as another Maya file, call it according to your Scene Name, and enumerate it well. Eg : Scene1_1 means Scene 1 State 1 or something
  7. After you save the file, please export the scenes into .FBX, using the instructions I posted way earlier on, using the same name as the Maya scene name. If in doubt, then its okay, I will do the exporting, just as long as you have the Maya scene file saved.
  8. For subsequent scenes, this is a bit challenging, coz we need to figure out how to remove all animations and keep only the last frame (perhaps someone can teach me?) So say in one scene you are exploding the car, then the next scene you want to begin from the last frame of the previous scene as the first frame of the subsequent scene. I hope you get the idea.

I have also uploaded an excel file which contains our rough plan and story board for the scenes. It’s available here.

As you can see, under the worksheet EventTimeStamp(2), there's a list of events and what kind of things supposed to happen at which timestamp. For now, we try to make 2 scenes first. The first series of event time stamps is what me and Jing Ying discussed last Friday. The second one has not been polished.


So we kind of need to polish all these events, and start animating! Yeay!

Assets management

Hope everyone’s enjoying the holidays and break so far :P

I’ve been trying to reorganize stuff to make our project development much more manageable (trying to apply what Danien went through with us the past two weeks), but I have to say this: No matter how we organize it, it still is a hell of a work, haha!

So here it goes: an attempt to streamline our “Assets management”.

I have already downloaded, exported to fbx, resized the textures and tested each and every single of the Models on the XBOX360, and so far they seem to be correctly loaded without issues(some misplaced parts here and there, but its easily fixable)

I have put up an excel file listing all the tested/ working models, and I have uploaded it along with the whole Assets files to my server, you can find it under the folders NM4343->CS4343->Assets

Note : Uploading the files to my server is a temporary solution until we get a proper source control system. I will email you the password separately so we can upload files there.

If possible, re-create the same directory structures on your machine to make things easier to manage.

I know it is simpler to just upload one zipped file which recreates the hierarchy, but since the assets are too big, you might just want to create it yourself and download whatever models you need to create the scene.

For my case (just like on the ftp), I put everything under D:\CS4343 and the hierarchy goes like this:

D:\CS4343

  • Assets
    • Animated Models : To put all our animated scenes
      • Eg: Scene1 - my poor attempt at a scene. Its a plane crashing into a Nissan car.
    • Source Models: This is whatever source models which we used(nothing is uploaded to the server yet since the whole thing is damn big)
    • Source To Use: This is where I dumped all the models which has been touched up to work with XNA
  • Documents: To put all other documents (eg story boards, game play design etc)
  • Source: To put the source code for the game

We are going to be using the models from the “Source To Use” folder to create animated scenes for the game. If you open the folder, you will see many sub folders which contains both the model exported in .FBX along with the relevant textures. Please refer to the excel file for a complete listing of models and descriptions. (Last minute addition: the whole "Source To Use" folder has been compiled into one .rar file, much much easier to download. Just click here)

To use the models, open Maya and choose Import, and select the .fbx file. You will see that the textures will not show up. This is because the pointer Path to the textures are not correct, and to fix this, you actually need to go to the Hypershader under Rendering tools and point the textures to the correct path. But do not worry about this for now, just work with un-textured models first, I will fix it later (hopefully I can find a way to make the pipeline easier, if not, then I will do it manually for now)

Oh if you have read this, please put comments? just that i know that everything makes sense, or needs to be simplified or clarified? Cheers!

Monday, February 12, 2007

Scenes and events

i have done up the scenes and events in the old version of excel format. I would be transferring it onto the new one. But take a look at the scenes and events and see if they are do-able or not ya? Comments are welcomed! Oh the file is at the ivle our own community at the moment.

Saturday, February 10, 2007

XNA Animation Component now works on Xbox360!

After figuring out what Erik did to get the Flight Simulator to work on 360, using the same knowledge, I've been debugging the Animation component again and managed to fix it and at last get it to run on the XBOX360!
Deploying...


Crane animation, captured in low speed.

Here are the steps to compile your own Animation library from this component.
Note since this component is also a Work In Progress, what I've done here might be obsolete soon. But it's just great to finally be able to see something moving on the 360, so here it goes:

I used Release #17738 from the source control and do some minor tweaks to be able to get it to run.
1. Create a new solution, add a Windows Game Library project, I call it Animationx86. Include the source code for the Animation component and compile it. It should produce Animationx86.dll

2. Add another Windows game library project, call it Animation.Contentx86. Include references to the above project Animationx86 and .net frameworks:
  • CustomMarshalers
  • Microsoft.Xna.Framework.Content.Pipeline
  • System.Xml
Copy all files under the Content folder from the source package.
Now when you try to compile it, it will fail because it is looking for a .cs file which is not available in the source package.
I found out that it is actually a file from the earlier release, so for my case i used Release #17349 and include the file SkinTransformReader.cs into the Animationx86 project.
Recompile everything and it should now work, producing a Animation.Contentx86.dll content processor.

3. Now we need to modify something in the AnimatedModelProcessor.cs.
What we need to do now is to create a DirectX Effect configuration file. I don't understand why, but I just figured that the content processor fails to run when used in an xbox game on line 72:

CompiledEffect compiledEffect4 = processor.Process(effect, context);

So we need to create the effect by capturing the code and writing it to a file. Just write a file writer function (mine is called writeEffectToFile)

private void writeEffectToFile(String filePath, String content){
FileStream file = new FileStream("C:\\"+filePath, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write(content);
sw.Close();
file.Close();
}

and do this after line 69:

effect.EffectCode = BasicPaletteEffect.SourceCode4BonesPerVertex;
writeEffectToFile("SourceCode4BonesPerVertex.fx",effect.EffectCode.ToString());

You should now see a file SourceCode4BonesPerVertex.fx created under your root directory, and include it in your project. Now change line 72 into

CompiledEffect compiledEffect4 = Effect.CompileEffectFromFile("../Animation.Content/SourceCode4BonesPerVertex.fx", null, null, CompilerOptions.None, TargetPlatform.Xbox360);

Now your Animation.Contentx86 should work both on Windows and XBoX! And there goes the complicated part!

4. This time create a Xbox library project, call it Animation360, and add all the Source files from the Animationx86 project. If you try to compile it, it will fail because it is looking for SortedDictionary, so just change all declarations of SortedDictionary into SortedList.
Also, remove the file ModelViewer.cs from the project, since it is using a MouseState class not available for xbox360 and not essential at the moment (Need to tweak it into Gamepadstate later on so we can use the ModelViewer, quite useful)
Compile, and it should produce Animation360.dll

5. Create the Xbox Game, include reference to Animation360, include the Content Pipeline processor Animation.Contentx86, include a model (.fbx) and change the Content Processor into Model - Animation Library. Write your game code and deploy. It should now work perfectly!

Problems
- Not all animations can work! Sometimes it failed to build the BasicPaletteEffect on some animated models. I am still trying to figure out why.
- Some animations are not animated correctly. I am not sure whether this is the problem of the component or is it something to do with the settings during exporting to FBX. Hopefully its just the latter.

At least we're moving on, so I think we can start to combine the flight sim engine and animation component to start build up the game engine :D
So I guess its now time to get some Real work done? Hmmm ...

Thursday, February 08, 2007

I am now officially...

$79 poorer...I decided to just go ahead and shell out some bucks for a 4 months XNA Creators Club subscription. Here's what they kindly remind me after punch in the payment:

Note that your subscription will automatically renew to a 4-month subscription at the then current price, unless you change your renewal or cancel before your subscription ends.

Uhm, okay, yeah sure...

Anyway, I think the subscription would be of benefit to the project and also to satisfy my own curiosity in playing around with XNA.

So Erik, you have a reason to rejoice! I think it is possible to load in my profile to the XBOX at the lab and we can use the XNA using my account. Or I might just pass you the Hardrive to make things more convenient. Lets just hope that the subscription is tied only to the profile and not to the machine or any other things...




Maya Effects. One more bad news..

I've been doing some research on Maya effects as well, trying to learn how to create explosions and all that. Found this good reference:
http://petershipkov.com/development/overburn/overburn.htm

Kaboom!

This guys was kind enough to share some very interesting animations, but unfortunately, I could not manage to export it to an animation that we can use for the game. When I tried to load it using the utility that i wrote previously, it showed nothing.

So I played around with Maya, try to create a simple fire effect, which is quite straight forward:

And this is how it looks when you render it:

Cool huh?
Wait until you see it running on XNA:

Oh nooooooo! Again, the Animation component is the culprit... I think it doesn't know how to read or interpret the fire effects information stored in the animation...
So for now, it seems we couldn't use the fancy effects which are included in Maya...until I found out another way, the solution now is to create explosion/ fire animations using simple shapes with textures which we move around or somehow manipulate using simple transformations...

So sad..

Wednesday, February 07, 2007

The not so good news…

Warning: The following entry is very distressing. Proceed at your own risk.

First of all, apparently the author did acknowledge that his compiled XBOX360 Animation Components (the one which we have been trying to use) indeed HAVE problems.

This is what I understood to be the issue:

The component comprises of two parts: Animation.dll is the animation library itself and Animation.Content is the content pipeline.

Trying to recompile the Animation.dll as XBOX360 library, I encountered a problem:

  • The type or namespace name 'SortedDictionary' could not be found (are you missing a using directive or an assembly reference?)
  • The type or namespace name 'MouseState' could not be found (are you missing a using directive or an assembly reference?)

To solve the first one, I tried changing all declarations of SortedDictionary into SortedList instead. The MouseState issue is due to the ModelViewer class referencing to a mouse library which clearly only available in x86. So I just removed the ModelViewer class for now, since it’s just a utility to view models and not essential.

It compiles successfully after I made the above changes.

Now here’s the more daunting issue:

Apparently, Animation.Content can only be compiled as an x86 game library, because it is using XNA.Framework.Content.Pipeline and some other x86 only libraries.

So it seems for now there is NO WAY (well at least, not to my knowledge) to recompile it as a 360 library. My guess I that in the first place, content processors are meant to be for x86 only anyway.

So what I did is just make it as a Windows library instead, and I tried to compile it using the source code provided, making references to the above successfully compiled 360 Animation.dll. It failed to compile, because of some library conflicts:

The type 'Microsoft.Xna.Framework.Matrix' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Xna.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=51c3bfb2db46012c'. D:\XNA\Recompile\Animation\Animation.Content\X File\XModelImporter.cs 114 21 Animation.Content

So I cheated, I just created another Animation.dll for x86, call it Animationx86 and use it to build Animation.Content.dll. And it works! At least it does compile successfully…

Then finally I tried to create an XBOX360 game, use the above compiled Animation.Content as Content.Pipeline, and added reference to the compiled 360 Animation.dll. I put a model (.fbx), successfully change it to Model-Animation type ( meaning the content pipeline successfully loads the x86 Animation.Content.dll), and when I try to compile it, I got the following error:

Building content threw NullReferenceException: Object reference not set to an instance of an object. At Microsoft.Xna.Framework.Content.Pipeline.Processors.EffectProcessor.CreateContentIdentityFromErrorString(String& errorString, ContentIdentity oldContentId)

One last thing, I then try to create a Windows Game instead, using the Animationx86.dll and Animation.Content.dll, it works, it loads the model and animations.

In Summary, here's what I have tried so far:

Platform

Library

Compile

Run

x86

Animation

OK

OK

x86

Animation.Content with x86 Animation

OK

OK

xbox360

Animation

Can Compile with Minor tweaks (SortedList, removed ModelViewer)

Cannot Run

xbox360

Animation.Content with x360 Animation

Cannot Compile (Looking for x86 XNA framework)

Cannot Run

x86

Animation.Content with x360 Animation

Cannot Compile (Looking for x360 XNA framework)

Cannot Run

x86

X86 Game with x86 Animation.Content

OK

OK

xbox360

XBOX360 Game with x86 Animation.Content

Cannot Compile

Cannot Run


I have been trying to look for alternative Animation components to no avail, so looks like we are stuck with the codeplex one for now.

It seems there are other people facing the same issue, and the author has actually noted the issue and hopefully working on it, so for now, we can only wait for him to update his library to work for 360, which he claims to be Possible…

Note: The source code is in our CS4343 Community, Recompile.rar



Tuesday, February 06, 2007

Some good news...

Donny, it seems you solved the microsoft.xna.content.pipeline problem without realising it.
The reference file we couldn't find, is in the Xbox360\AnimationLoader360\bin\Xbox 360\Debug folder. So unless you've placed it there, and know it doesn't work, I think we're done with that problem :)
[EDIT] Of course, it could just be the .dll for the windows platform and not the one for the Xbox 360, but we'll find that out later...[/EDIT]

As for the effects.fx, but a stroke of luck, I think I found an alternate way of loading it that doesn't involve CompiledEffect and thus should work on the 360. I'll check that now, and see if I can get access to the 360 creators club account again...


Thursday, February 01, 2007

XNA 3D Animation: It works!

Hi Guys!

Before I say anything, I just wanna show you guys something, to illustrate the result of 4 sleepless nights...
Behold...
Models in XNA!!!! Animated!

Model Trial 1: Nissan Car (Without Image textures)





Model Trial 2: Helicopter (With Image Textures)



Model Trial 3: Truck (With Image Textures)


All of these models are freely available from the net, and converted from .3ds format to .fbx using Maya.

A quick run through of work-flow to create, animate and export to XNA:

1. Get your Models (duh!)

2. If the Models has textures, please copy them to the folder where your XNA Content assets will be included (I will explain the significance of this later on)

3. Now this is the most Tedious part: Apparently XNA only accepts textures whose resolutions are power of 2 ( see here for details), in other words, 2,4,8,16,32,64,128,256,512 etc, so if one of your texture is say, 300x500, please open using photo shop and resize it to say, 256x512. This is very Important! Otherwise the models will not be able to be imported into XNA, and I will have a hard time debugging which textures to fix later on.

4. Before you start animating, please test that the models will indeed run in XNA. I will (or Erik will :P) write a simple utility to test out whether the model and the textures are importable by XNA.

5. If the models is fine, then you can start animating the models.

6. When ready to Export to XNA, use the File->ExportAll Option from Maya to export to .fbx file. This is the settings which works all the time (so far) for me:


7. Export your models to the Content->Textures/ whatever path of the XNA source code which you are dedicating for Textures(Even if you are not coding it, please set it to the working directory, otherwise I will have to open one by one the FBX and do a replace and search for all). We will go through this in details later on.


8. Test the animation in XNA. For Multiple Animations, We have no choice but to create a second animation based on the same model, but when you export, just click "Export Animation-Only", like follow:
9. Save this to a Separate .fbx file. At this moment, it seems like the only way to have multiple animation in one .fbx is by opening up the animation only-.fbx and copying the animation information manually to the other .fbx which contains the model/ textures information. Until we can write a tools to automate this, we have to do this manually, so remember, rule of thumb:
- First animation : Export All
- Second animation onwards : Export Animation Only
- I will then integrate all the animation manually into the first animation file (the one which is to be imported)

10. At this moment, I am facing a problem with loading a model with lots of bones, because apparently the Animation Component library which I am using has a limitation of 56 bones

///
/// The max number of bones in the effects matrix palette.
///

public const int PALETTE_SIZE = 56;

I am not sure whether we would face this problem or not, but as we go along, we might need to investigate why, and how come the moment I change that value, the whole thing doesn't work anymore.

I think so far it looks quite promising:
  • We can load .FBX without having to export to the dreadful .x format.
  • We can load the textures, although a bit laborious as we have to manually change the texture resolutions to be powers of 2
  • We can embed more than one animations in one .fbx, again, laborious as we have to manually embed the animation one by one
  • The models render smoothly in XNA, so hopefully as we put more models on the screen at the same time, the performance will not suffer so much.
I will keep you guys updated for more developments!

-Donny