Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (8 posts)

Content building at runtime

Last post 11/9/2009 8:24 PM by NamicGames. 7 replies.
  • 11/8/2009 3:23 AM

    Content building at runtime

    Hey I am working on a level editor, and I need to be able to build models at runtime. I have found plenty of samples for this but none of them work with 3.1 ...

    http://www.codeplex.com/wikipage?ProjectName=xnadevru&title=XNA%20Content%20Builder%20(XCB) this is one of them and I get "Could not load file or assembly 'Microsoft.Xna.Framework.Game, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d' or one of its dependencies. The system cannot find the file specified." once I update all references.

    I also tried XNA sample, but one I update references to 3.1 and build engine to 3.5 I get 
    "Could not load file or assembly 'Microsoft.Xna.Framework.Game, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d' or one of its dependencies. The system cannot find the file specified."

    Could anyone give an advise of anything uptodate I could look at?
  • 11/8/2009 3:55 AM In reply to

    Re: Content building at runtime

    Answer
    Reply Quote
    by XNA sample I presume you mean the winforms content loading sample.

    In ContentBuilder.cs try changing line 34 to

    const string xnaVersion = ", Version=3.1.0.0, PublicKeyToken=6d5c3888ef60e27d";  

    and lines 168-170 to:
    msBuildProject.AddNewImport("$(MSBuildExtensionsPath)\\Microsoft\\XNA " + 
                                            "Game Studio\\v3.1\\Microsoft.Xna.GameStudio" + 
                                            ".ContentPipeline.targets"null); 



  • 11/8/2009 4:04 AM In reply to

    Re: Content building at runtime

    Corey S:
    by XNA sample I presume you mean the winforms content loading sample.

    In ContentBuilder.cs try changing line 34 to

    const string xnaVersion = ", Version=3.1.0.0, PublicKeyToken=6d5c3888ef60e27d";  

    and lines 168-170 to:
    msBuildProject.AddNewImport("$(MSBuildExtensionsPath)\\Microsoft\\XNA " + 
                                            "Game Studio\\v3.1\\Microsoft.Xna.GameStudio" + 
                                            ".ContentPipeline.targets"null); 





    Great that worked thanks! Now any idea how can I pass custom Content Processor properties? I know they build with
    contentBuilder.Add(fileName, "Model"null"ModelProcessor"); 
    function. But besides that I also need to pass model processor properties like specular/bump maps, rotation, scale, etc.

    Thanks
  • 11/8/2009 5:05 AM In reply to

    Re: Content building at runtime

    I don't remember off the top of my head, but properties are probably set by adding metadata to the BuildItem added to the temporary MSBuild project (metadata is added by calling BuildItem.SetMetadata).  Usually what I do when I need to figure out how something is done for a Content project, is I'll do it in Visual Studio and then look at what happens in the actual text of the .contentproj file. Then I just replicate that using the MSBuild classes.
  • 11/8/2009 6:50 AM In reply to

    Re: Content building at runtime

    Answer
    Reply Quote
    These are the values I use at the moment, including format. I think it's fairly complete, but this probably isn't a very good way to go about it.
    Ideally, I would get the Importer class, and use a PropertyGrid for that class instead, or just display a list of properties and go through the list, setting ProcessorParameters_PropertyName to the value displayed by the PropertyGrid for converting. I never got around to doing this though. Also, keep in mind, if you ever upgrade to a newer version of XNA, your currently run-time built content will no longer work. You can't load content built by a previous version of XNA. I've tried a few ways to get around it, but didn't manage, so what I do now instead is just have the ContentBuilder class have a ProjectPath property (fairly easy to generate off of the Base Directory if you know the Content Project name [usually just Content]), and then it copies the file to the Content folder before building it, and edits the Content.contentproj file to include the change. It's not an ideal way, but it works I believe.

    Anywho, for what you actually asked (note that Item is the BuildItem returned when you add the file to the MSBuild Project):

        /// <summary> 
        /// Specifies the TextureFormat to use when saving a file. 
        /// </summary> 
        public enum TextureFormat { 
            /// <summary> 
            /// The texture should be in Color format. This is usually used for things like height maps and color maps. 
            /// </summary> 
            Color, 
            /// <summary> 
            /// The texture should be in DxtCompressed format. This is used for most general textures. This is the default format. 
            /// </summary> 
            DxtCompressed, 
            /// <summary> 
            /// The texture should remain in its default format. 
            /// </summary> 
            NoChange 
        } 

    switch (Processor) { 
                    case "TextureProcessor"
                        Item.SetMetadata("ProcessorParameters_GenerateMipmaps", GenerateMipmaps.ToString()); 
                        Item.SetMetadata("ProcessorParameters_ResizeToPowerOfTwo", ResizeToPowerOfTwo.ToString()); 
                        Item.SetMetadata("ProcessorParameters_TextureFormat", TextureFormat.ToString()); 
                        ImporterName = "TextureImporter"
                        break
                    case "FontDescriptionProcessor"
                        ImporterName = "FontDescriptionImporter"
                        break
                    case "EffectProcessor"
                        ImporterName = "EffectImporter"
                        break
                    case "ModelProcessor"
                        Item.SetMetadata("ProcessorParameters_ColorKeyColor", ColorKeyColor.R + ", " + ColorKeyColor.G + ", " + ColorKeyColor.B + ", " + ColorKeyColor.A); 
                        Item.SetMetadata("ProcessorParameters_ColorKeyEnabled", ColorKeyEnabled.ToString()); 
                        Item.SetMetadata("ProcessorParameters_GenerateMipmaps", GenerateMipmaps.ToString()); 
                        Item.SetMetadata("ProcessorParameters_GenerateTangentFrames", GenerateTangentFrames.ToString()); 
                        Item.SetMetadata("ProcessorParameters_ResizeTexturesToPowerOfTwo", ResizeTexturesToPowerOfTwo.ToString()); 
                        Item.SetMetadata("ProcessorParameters_Scale", Scale.ToString()); 
                        Item.SetMetadata("ProcessorParameters_SwapWindingOrder", SwapWindingOrder.ToString()); 
                        Item.SetMetadata("ProcessorParameters_TextureFormat", TextureFormat.ToString()); 
                        Item.SetMetadata("ProcessorParameters_RotationX", RotationX.ToString()); 
                        Item.SetMetadata("ProcessorParameters_RotationY", RotationY.ToString()); 
                        Item.SetMetadata("ProcessorParameters_RotationZ", RotationZ.ToString()); 
                        break
                    default
                        Debug.WriteLine("Unknown content processor: \"" + Processor + "\"."); 
                        break
                } 

  • 11/8/2009 8:11 PM In reply to

    Re: Content building at runtime

    Thanks Kapps I will try that in a few. I decided to post this here if anyone else will have problems with content loading.

    As Corey mentioned these changes make the ORIGINAL WinForms smaple to work with new references, but this is was not everything needed to get my project working using WinForms code.
    Ive also had to add two changes:
    1. Change platform to x86 (doesnt work with x64)
    2. Add app.config file like shown here http://forums.xna.com/forums/p/15214/79777.aspx

    Edit: I am still having problems passing custom processor to ContentBuilder. I am trying to use kW Animation processor, and I am getting "Cannot find processor" error. I am not sure what I need to do, besides adding kW processor in references.

    There is this line in ContentBuilder.cs I figured would be responsible for adding new processor 
     static string[] pipelineAssemblies =  
            {  
                "Microsoft.Xna.Framework.Content.Pipeline.FBXImporter" + xnaVersion,  
                "Microsoft.Xna.Framework.Content.Pipeline.XImporter" + xnaVersion,  
                "Microsoft.Xna.Framework.Content.Pipeline.TextureImporter" + xnaVersion,  
                "Microsoft.Xna.Framework.Content.Pipeline.EffectImporter" + xnaVersion,  
                "KiloWatt.Base.Animation.AnimationSetReader, KiloWatt.Base",  //I added this
            }; 
    but I have no idea what should be added in there.
  • 11/9/2009 5:45 PM In reply to

    Re: Content building at runtime

    Answer
    Reply Quote
    This is a list of assembly names, not type names, so you should add the filename (including path) of the importer DLL.
  • 11/9/2009 8:24 PM In reply to

    Re: Content building at runtime

    got everything working thanks!
Page 1 of 1 (8 posts) Previous Discussion Next Discussion