Exemple #1
0
        public override TileMapContent Process(
            XmlDocument input, ContentProcessorContext context)
        {
            TileMapContent map = new TileMapContent();

            XmlNodeList colLayers = input.GetElementsByTagName("CollisionLayer");

            foreach (XmlNode layer in colLayers)
            {
                map.CollisionLayers.Add(
                    context.BuildAsset <XmlDocument,
                                        CollisionLayerContent>(
                        new ExternalReference <XmlDocument>(layer.InnerText),
                        "CollisionLayerProcessor"));
            }

            //System.Diagnostics.Debugger.Launch();

            XmlNodeList tileLayers = input.GetElementsByTagName("TileLayer");

            foreach (XmlNode layer in tileLayers)
            {
                map.TileLayers.Add(
                    context.BuildAsset <XmlDocument, TileLayerContent>(
                        new ExternalReference <XmlDocument>(layer.InnerText),
                        "TileLayerProcessor"));
            }
            return(map);
        }
Exemple #2
0
        /// <summary>
        /// Generates a terrain mesh from an input heightfield texture.
        /// </summary>
        public override TerrainModelContent Process(Texture2DContent input,
                                                    ContentProcessorContext context)
        {
            Texture2DContent texture = context.Convert <Texture2DContent, Texture2DContent>(input, "FloatingPointTextureProcessor");

            PixelBitmapContent <float> heightfield = (PixelBitmapContent <float>)texture.Mipmaps[0];

            float[,] heights = new float[heightfield.Width, heightfield.Height];
            for (int y = 0; y < heightfield.Height; y++)
            {
                for (int x = 0; x < heightfield.Width; x++)
                {
                    heights[x, y] = heightfield.GetPixel(x, y);
                }
            }

            HeightMapContent heightMap = new HeightMapContent(heightfield.Width, heightfield.Height, heights, VerticalScale, HorizontalScale);

            string directory = Path.GetDirectoryName(input.Identity.SourceFilename);
            string texture1  = Path.Combine(directory, ColorTexture);
            string texture2  = Path.Combine(directory, DetailTexture);

            // Create a material, and point it at our terrain texture.
            DualTextureMaterialContent material = new DualTextureMaterialContent
            {
                Texture  = context.BuildAsset <TextureContent, TextureContent>(new ExternalReference <TextureContent>(texture1), null),
                Texture2 = context.BuildAsset <TextureContent, TextureContent>(new ExternalReference <TextureContent>(texture2), null),
            };

            TerrainModelContentBuilder terrainModelContentBuilder = new TerrainModelContentBuilder(PatchSize, Tau, heightMap, material, DetailTextureTiling, HorizontalScale);

            return(terrainModelContentBuilder.Build(context));
        }
Exemple #3
0
        public void LoadTextureReferences(TiledMap map, ContentProcessorContext context)
        {
            TextureReferences = new Dictionary <string, ExternalReference <Texture2DContent> >();
            foreach (var tileset in map.Tilesets)
            {
                if (
                    tileset.Properties.ContainsKey(TilesetParser.IgnoreTilesetTextureFlag) &&
                    bool.Parse(tileset.Properties[TilesetParser.IgnoreTilesetTextureFlag])
                    )
                {
                    continue;                     // Skip texture, if we won't need it.
                }
                foreach (var path in tileset.TexturePaths)
                {
                    if (TextureReferences.ContainsKey(path))
                    {
                        continue;
                    }
                    var assetReference = new ExternalReference <Texture2DContent>(TiledMapImporter.TmxRootDir + "/" + path);
                    TextureReferences.Add(path, context.BuildAsset <Texture2DContent, Texture2DContent>(assetReference, "", null, "", ""));
                }
            }

            foreach (var imageLayer in map.ImageLayers)
            {
                if (TextureReferences.ContainsKey(imageLayer.TexturePath))
                {
                    continue;
                }
                var asserReference = new ExternalReference <Texture2DContent>(TiledMapImporter.TmxRootDir + "/" + imageLayer.TexturePath);
                TextureReferences.Add(imageLayer.TexturePath, context.BuildAsset <Texture2DContent, Texture2DContent>(asserReference, "", null, "", ""));
            }
        }
Exemple #4
0
    protected virtual ExternalReference<CompiledEffectContent> OnBuildEffect(ExternalReference<EffectContent> effect, ContentProcessorContext context)
    {

      return context.BuildAsset<EffectContent, CompiledEffectContent>(effect, typeof(EffectProcessor).Name);
#else
      if (string.IsNullOrEmpty(ContentHelper.GetMonoGamePlatform()))
        return context.BuildAsset<EffectContent, CompiledEffectContent>(effect, typeof(EffectProcessor).Name);
      else
        return context.BuildAsset<EffectContent, CompiledEffectContent>(effect, "MGEffectProcessor");

    }
Exemple #5
0
    protected virtual ExternalReference<TextureContent> OnBuildTexture(string textureName, ExternalReference<TextureContent> texture, ContentProcessorContext context)
    {
      // Processor parameters are stored in opaque data!
      var processorParameters = texture.OpaqueData;

      return context.BuildAsset<TextureContent, TextureContent>(texture, typeof(DRTextureProcessor).Name, processorParameters, typeof(DRTextureImporter).Name, null);
    }
Exemple #6
0
        protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context)
        {
            OpaqueDataDictionary pparams = new OpaqueDataDictionary( );

            pparams["ColorKeyEnabled"]            = false;
            pparams["GenerateMipmaps"]            = this.GenerateMipmaps;
            pparams["TextureFormat"]              = this.TextureFormat;
            pparams["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo;
            pparams["PremultiplyTextureAlpha"]    = false;

            string exePath    = Application.ExecutablePath;
            string appDir     = exePath.Replace(Path.GetFileName(exePath), string.Empty);
            string shaderPath = Path.Combine(appDir, DATA_DIR + @"\game.fx");

            EffectMaterialContent vixenMaterial = new EffectMaterialContent( );

            vixenMaterial.Effect         = new ExternalReference <EffectContent>(shaderPath);
            vixenMaterial.CompiledEffect = context.BuildAsset <EffectContent, CompiledEffectContent>(vixenMaterial.Effect, "EffectProcessor");

            foreach (KeyValuePair <string, ExternalReference <TextureContent> > texture in material.Textures)
            {
                switch (texture.Key)
                {
                case C4D_DMAP:
                    vixenMaterial.Textures.Add(KEY_DMAP, texture.Value);
                    break;

                case C4D_NMAP:
                    vixenMaterial.Textures.Add(KEY_NMAP, texture.Value);
                    break;

                case C4D_SMAP:
                    vixenMaterial.Textures.Add(KEY_SMAP, texture.Value);
                    break;

                case C4D_EMAP:
                    vixenMaterial.Textures.Add(KEY_EMAP, texture.Value);
                    break;
                }
            }

            if (!vixenMaterial.Textures.ContainsKey(KEY_DMAP))
            {
                vixenMaterial.Textures[KEY_DMAP] = new ExternalReference <TextureContent>(Path.Combine(appDir, DATA_DIR + @"\dmap.tga"));
            }
            if (!vixenMaterial.Textures.ContainsKey(KEY_NMAP))
            {
                vixenMaterial.Textures[KEY_DMAP] = new ExternalReference <TextureContent>(Path.Combine(appDir, DATA_DIR + @"\nmap.tga"));
            }
            if (!vixenMaterial.Textures.ContainsKey(KEY_SMAP))
            {
                vixenMaterial.Textures[KEY_DMAP] = new ExternalReference <TextureContent>(Path.Combine(appDir, DATA_DIR + @"\smap.tga"));
            }
            if (!vixenMaterial.Textures.ContainsKey(KEY_EMAP))
            {
                vixenMaterial.Textures[KEY_DMAP] = new ExternalReference <TextureContent>(Path.Combine(appDir, DATA_DIR + @"\emap.tga"));
            }

            return(context.Convert <MaterialContent, MaterialContent>(vixenMaterial, typeof(MaterialProcessor).Name, pparams));
        }
        /// <summary>
        /// Iterates all of the tile sets and builds external references to the textures. Useful if you want to just
        /// load the resulting map and not have to also load up textures. The external reference is stored on the
        /// TileSet's Texture field so make sure you serialize that if you call this method.
        /// </summary>
        public static void BuildTileSetTextures(MapContent input, ContentProcessorContext context, string textureRoot = "")
        {
            foreach (var tileSet in input.TileSets)
            {
                // get the real path to the image
                string path = Path.Combine(textureRoot, tileSet.Image);

                // the asset name is the entire path, minus extension, after the content directory
                string asset = string.Empty;
                if (path.StartsWith(Directory.GetCurrentDirectory()))
                    asset = path.Remove(tileSet.Image.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1);
                else
                    asset = Path.GetFileNameWithoutExtension(path);

                // build the asset as an external reference
                OpaqueDataDictionary data = new OpaqueDataDictionary();
                data.Add("GenerateMipmaps", false);
                data.Add("ResizeToPowerOfTwo", false);
                data.Add("TextureFormat", TextureProcessorOutputFormat.Color);
                data.Add("ColorKeyEnabled", tileSet.ColorKey.HasValue);
                data.Add("ColorKeyColor", tileSet.ColorKey.HasValue ? tileSet.ColorKey.Value : Microsoft.Xna.Framework.Color.Magenta);
                tileSet.Texture = context.BuildAsset<Texture2DContent, Texture2DContent>(
                    new ExternalReference<Texture2DContent>(path), null, data, null, asset);
            }
        }
Exemple #8
0
 /// <summary>
 /// Builds Distorter textures with the DisplacementMapProcessor
 /// </summary>
 protected override ExternalReference <TextureContent> BuildTexture(
     string textureName, ExternalReference <TextureContent> texture,
     ContentProcessorContext context)
 {
     return(context.BuildAsset <TextureContent,
                                TextureContent>(texture, "DisplacementMapProcessor"));
 }
        public void BuildExternalReference <TInput>(ContentProcessorContext context, string source, OpaqueDataDictionary parameters = null)
        {
            var sourceAsset       = new ExternalReference <TInput>(source);
            var externalReference = context.BuildAsset <TInput, TInput>(sourceAsset, "", parameters, "", "");

            _externalReferences.Add(source, externalReference);
        }
Exemple #10
0
        /// <summary>
        /// Processes the raw .tsx XML and creates a TilesetContent
        /// for use in an XNA framework game
        /// </summary>
        /// <param name="input">The XML string</param>
        /// <param name="context">The pipeline context</param>
        /// <returns>A TilesetContent instance corresponding to the tsx input</returns>
        public override TOutput Process(TInput input, ContentProcessorContext context)
        {
            // Process the Tilesets
            for (int i = 0; i < input.Tilesets.Count; i++)
            {
                var tileset = input.Tilesets[i];
                ExternalReference <TilesetContent> externalRef = new ExternalReference <TilesetContent>(tileset.Source);
                tileset.Reference = context.BuildAsset <TilesetContent, TilesetContent>(externalRef, "TilesetProcessor");
            }

            foreach (TilemapLayerContent layer in input.Layers)
            {
                List <uint> dataIds = new List <uint>();
                foreach (var id in layer.DataString.Split(','))
                {
                    dataIds.Add(uint.Parse(id));
                }
                ;
                layer.Data = dataIds.ToArray();
            }

            foreach (TilemapObjectContent obj in input.Objects)
            {
            }

            // The tileset has been processed
            return(input);
        }
        public override AnimationsData Process(AnimationsData input, ContentProcessorContext context)
        {
            // Save spritesheet texture
            var spriteSheetAsset = Path.Combine(input.FilePath, input.SpriteSheetFilename);

            string assetName;

            if (spriteSheetAsset.StartsWith(Directory.GetCurrentDirectory()))
            {
                assetName = spriteSheetAsset.Substring(Directory.GetCurrentDirectory().Length + 1);
            }
            else
            {
                assetName = Path.GetFileName(spriteSheetAsset);
            }

            // Remove file extension
            assetName = Path.Combine(Path.GetDirectoryName(assetName), Path.GetFileNameWithoutExtension(assetName));

            input.SpriteSheetRef = context.BuildAsset <SpriteSheetData, SpriteSheetData>(
                new ExternalReference <SpriteSheetData>(spriteSheetAsset),
                "DarkFunctionSpritesProcessor",
                null,
                "DarkFunctionSpritesImporter",
                assetName);

            return(input);
        }
    private void ProcessTextures(ThemeContent theme, ContentProcessorContext context)
    {
      theme.Textures = new NamedObjectCollection<ThemeTextureContent>();

      var document = theme.Description;
      if (document.Root == null)
      {
        string message = string.Format("Root element \"<Theme>\" is missing in XML.");
        throw new InvalidContentException(message, theme.Identity);
      }

      if (document.Root.Elements("Texture").Any())
      {
        // Issue error because theme file is using old alpha version format.
        throw new InvalidContentException("Given theme file is using a format which is no longer supported. All textures need to be defined inside a 'Textures' node.", theme.Identity);
      }

      var texturesElement = document.Root.Element("Textures");
      if (texturesElement == null)
        throw new InvalidContentException("Given theme file does not contain a 'Textures' node.", theme.Identity);

      foreach (var textureElement in texturesElement.Elements("Texture"))
      {
        string name = GetMandatoryAttribute(textureElement, "Name", theme.Identity);
        bool isDefault = (bool?)textureElement.Attribute("IsDefault") ?? false;
        string filename = GetMandatoryAttribute(textureElement, "File", theme.Identity);
        bool premultiplyAlpha = (bool?)textureElement.Attribute("PremultiplyAlpha") ?? true;

        // Get path of texture relative to root directory without file extension.
        string textureSourcePath = FindFile(theme, filename);
        string relativeTextureSourcePath =
            _sourceRootDirectoryUri.MakeRelativeUri(new Uri(textureSourcePath)).OriginalString;
        relativeTextureSourcePath = Uri.UnescapeDataString(relativeTextureSourcePath);
        string extension = Path.GetExtension(relativeTextureSourcePath);
        relativeTextureSourcePath = relativeTextureSourcePath.Remove(
          relativeTextureSourcePath.Length - extension.Length, extension.Length);

        // Build Texture.
        var processorParameters = new OpaqueDataDictionary();
        processorParameters.Add("PremultiplyAlpha", premultiplyAlpha);
        var textureReference = context.BuildAsset<TextureContent, TextureContent>(
          new ExternalReference<TextureContent>(textureSourcePath),
          "TextureProcessor",
          processorParameters,
          "TextureImporter",
          relativeTextureSourcePath);

        var texture = new ThemeTextureContent
        {
          Name = name,
          IsDefault = isDefault,
          Texture = textureReference,
        };

        theme.Textures.Add(texture);
      }

      if (theme.Textures.Count == 0)
        throw new InvalidContentException("The UI theme does not contain any textures. At least 1 texture is required.", theme.Identity);
    }
Exemple #13
0
        /// <summary>
        /// Iterates all of the tile sets and builds external references to the textures. Useful if you want to just
        /// load the resulting map and not have to also load up textures. The external reference is stored on the
        /// TileSet's Texture field so make sure you serialize that if you call this method.
        /// </summary>
        public static void BuildTileSetTextures(MapContent input, ContentProcessorContext context, string textureRoot = "")
        {
            foreach (var tileSet in input.TileSets)
            {
                // get the real path to the image
                string path = Path.Combine(textureRoot, tileSet.Image);

                // the asset name is the entire path, minus extension, after the content directory
                string asset = string.Empty;
                if (path.StartsWith(Directory.GetCurrentDirectory()))
                {
                    asset = path.Remove(tileSet.Image.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1);
                }
                else
                {
                    asset = Path.GetFileNameWithoutExtension(path);
                }

                // build the asset as an external reference
                OpaqueDataDictionary data = new OpaqueDataDictionary();
                data.Add("GenerateMipmaps", false);
                data.Add("ResizeToPowerOfTwo", false);
                data.Add("TextureFormat", TextureProcessorOutputFormat.Color);
                data.Add("ColorKeyEnabled", tileSet.ColorKey.HasValue);
                data.Add("ColorKeyColor", tileSet.ColorKey.HasValue ? tileSet.ColorKey.Value : Microsoft.Xna.Framework.Color.Magenta);
                tileSet.Texture = context.BuildAsset <Texture2DContent, Texture2DContent>(
                    new ExternalReference <Texture2DContent>(path), null, data, null, asset);
            }
        }
Exemple #14
0
        private string BuildTexture(string textureName)
        {
            if (textureName == null || textureName.Length == 0)
            {
                return("");
            }

            string assetLocation = new FileInfo(rootPath).DirectoryName + @"/" + textureName;
            string comparePath   = rootPath;

            if (importTextures)
            {
                OpaqueDataDictionary processorParameters = new OpaqueDataDictionary();
                processorParameters.Add("ColorKeyColor", this.colourKeyColour);
                processorParameters.Add("ColorKeyEnabled", this.ColorKeyEnabled);
                processorParameters.Add("TextureFormat", this.TextureFormat);
                processorParameters.Add("GenerateMipmaps", this.GenerateMipmaps);
                processorParameters.Add("ResizeToPowerOfTwo", this.ResizeTexturesToPowerOfTwo);

                ExternalReference <TextureContent> texture = context.BuildAsset <TextureContent, TextureContent>(new ExternalReference <TextureContent>(textureName, new ContentIdentity(rootPath)), typeof(TextureProcessor).Name, processorParameters, null, null);
                assetLocation = texture.Filename;
                comparePath   = context.OutputFilename;
            }
            else
            {
                if (!File.Exists(assetLocation))
                {
                    context.Logger.LogWarning("", new ContentIdentity(rootPath), "File not found:\t{1} ({0})", textureName, @".\" + GetSharedPath(assetLocation, comparePath) + new FileInfo(assetLocation).Extension);
                    return("");
                }
            }

            return(GetSharedPath(assetLocation, comparePath));
        }
Exemple #15
0
        public override AnimationData Process(AnimationData input, ContentProcessorContext context)
        {
            var inRef = new ExternalReference <TextureContent>(input.sheet);

            input.sheetRef = context.BuildAsset <TextureContent, TextureContent>(inRef, "TextureProcessor");
            return(input);
        }
Exemple #16
0
        private MagmaModelContent ProcessContainerFile(
            NodeContent input,
            ContentProcessorContext context
            )
        {
#if DEBUG
            context.Logger.LogImportantMessage("  processing file as a model container");
#endif

            int    startIndex = input.Identity.SourceFilename.LastIndexOf("Content\\") + "Content\\".Length;
            int    endIndex   = input.Identity.SourceFilename.LastIndexOf('\\') + 1;
            string dir        = input.Identity.SourceFilename.Substring(startIndex, endIndex - startIndex);

            // parameters to be passed into the processor
            OpaqueDataDictionary dictionary = new OpaqueDataDictionary();
            dictionary.Add("CallRecursive", true);

            foreach (NodeContent child in input.Children)
            {
#if DEBUG
                context.Logger.LogImportantMessage("  spawning a new build process for {0}", child.Name);
#endif

                dictionary["CurrentGroup"] = child.Name;

                context.BuildAsset <NodeContent, MagmaModelContent>(
                    new ExternalReference <NodeContent>(input.Identity.SourceFilename),
                    this.GetType().Name, dictionary, GetContainerGroupImporter(), dir + child.Name);
            }

            RemoveTextureReferences(input, context);

            return(BaseProcessing(input, context));
        }
Exemple #17
0
        /// <summary>
        /// builds an external reference to a texture
        /// </summary>
        internal static ExternalReference <TextureContent> BuildTexture(string file, ContentProcessorContext context)
        {
            ExternalReference <Texture2DContent> tex = new ExternalReference <Texture2DContent>(file);

            tex.Name = Path.GetFileNameWithoutExtension(file);

            CreateDictionaryIfNecessary();

            //string extension = Path.GetExtension(file);
            //UseBlackAsAlpha = extension.ToLower() == ".bmp";


            //if (UseBlackAsAlpha)
            //{
            //    TextureProcessor.ColorKeyColor = Color.Black;
            //    TextureProcessor.ColorKeyEnabled = true;
            //}
            //else
            //{
            //    TextureProcessor.ColorKeyEnabled = false;
            //}


            return(context.BuildAsset <Texture2DContent, TextureContent>(
                       tex,
                       typeof(TextureProcessor).Name,
                       dictionary,
                       "TextureImporter",
                       null // Passing null lets the content pipeline decide on the default name, which is what we want.
                       ));
        }
Exemple #18
0
        public override LevelContent Process(OelContent input, ContentProcessorContext context)
        {
            if (string.IsNullOrEmpty(this.OgmoProjectFile))
            {
                throw new Exception("No project file specified.");
            }
            if (!this.OgmoProjectFile.EndsWith(".oep"))
            {
                this.OgmoProjectFile += ".oep";
            }
            string         projectPath    = Path.GetFullPath(Path.Combine(input.Directory, this.OgmoProjectFile));
            string         projectAsset   = projectPath.Remove(projectPath.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1);
            ProjectContent projectContent = context.BuildAndLoadAsset <OepContent, ProjectContent>(
                new ExternalReference <OepContent>(projectPath),
                "OepProcessor",
                new OpaqueDataDictionary(),
                "OepImporter");
            LevelContent levelContent = new LevelContent(projectContent, input.Document);

            levelContent.ProjectReference = context.BuildAsset <OepContent, ProjectContent>(
                new ExternalReference <OepContent>(projectPath),
                "OepProcessor",
                new OpaqueDataDictionary(),
                "OepImporter",
                projectAsset);
            return(levelContent);
        }
        public override SpriteSheetData Process(SpriteSheetData input, ContentProcessorContext context)
        {
            // Save spritesheet texture
            var sourceAsset = Path.Combine(input.FilePath, input.ImageFilename);

            string assetName;

            if (sourceAsset.StartsWith(Directory.GetCurrentDirectory()))
            {
                assetName = sourceAsset.Substring(Directory.GetCurrentDirectory().Length + 1);
            }
            else
            {
                assetName = Path.GetFileName(sourceAsset);
            }

            // Remove file extension
            assetName = Path.Combine(Path.GetDirectoryName(assetName), Path.GetFileNameWithoutExtension(assetName));

            input.ImageRef = context.BuildAsset <TextureContent, TextureContent>(
                new ExternalReference <TextureContent>(sourceAsset),
                "TextureProcessor",
                null,
                "TextureImporter",
                assetName);

            return(input);
        }
Exemple #20
0
        protected override MaterialContent ConvertMaterial(MaterialContent material,
                                                           ContentProcessorContext context)
        {
            EffectMaterialContent lppMaterial = new EffectMaterialContent();

            OpaqueDataDictionary processorParameters = new OpaqueDataDictionary();

            processorParameters["ColorKeyColor"]              = this.ColorKeyColor;
            processorParameters["ColorKeyEnabled"]            = false;
            processorParameters["TextureFormat"]              = this.TextureFormat;
            processorParameters["GenerateMipmaps"]            = this.GenerateMipmaps;
            processorParameters["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo;
            processorParameters["PremultiplyTextureAlpha"]    = false;
            processorParameters["ColorKeyEnabled"]            = false;

            lppMaterial.Effect         = new ExternalReference <EffectContent>(_customFx.Length == 0 ? "shaders/LPPMainEffect.fx" : _customFx);
            lppMaterial.CompiledEffect = context.BuildAsset <EffectContent, CompiledEffectContent>(lppMaterial.Effect, "EffectProcessor");

            // copy the textures in the original material to the new lpp
            // material
            ExtractTextures(lppMaterial, material);
            //extract the extra parameters
            ExtractDefines(lppMaterial, material, context);

            // and convert the material using the NormalMappingMaterialProcessor,
            // who has something special in store for the normal map.
            return(context.Convert <MaterialContent, MaterialContent>
                       (lppMaterial, typeof(LightPrePassMaterialProcessor).Name, processorParameters));
        }
Exemple #21
0
        /// <summary>
        /// Processes the raw .tsx XML and creates a TilesetContent
        /// for use in an XNA framework game
        /// </summary>
        /// <param name="input">The XML string</param>
        /// <param name="context">The pipeline context</param>
        /// <returns>A TilesetContent instance corresponding to the tsx input</returns>
        public override TOutput Process(TInput input, ContentProcessorContext context)
        {
            // Process the Tilesets
            for (int i = 0; i < input.Tilesets.Count; i++)
            {
                var tileset = input.Tilesets[i];
                ExternalReference <TilesetContent> externalRef = new ExternalReference <TilesetContent>(tileset.Source);
                tileset.Reference = context.BuildAsset <TilesetContent, TilesetContent>(externalRef, "TilesetProcessor");
            }

            foreach (TilemapLayerContent layer in input.Layers)
            {
                List <uint> dataIds = new List <uint>();
                foreach (var id in layer.DataString.Split(','))
                {
                    dataIds.Add(uint.Parse(id));
                }
                ;
                layer.Data = dataIds.ToArray();
            }

            // Correction for tile objects X,Y being left,bottom origin instead of left,top
            foreach (TilemapObjectGroupContent objectGroup in input.ObjectGroups)
            {
                foreach (ObjectGroupObjects groupObject in objectGroup.Objects)
                {
                    groupObject.Y -= input.TileHeight;
                }
            }

            // The tileset has been processed
            return(input);
        }
Exemple #22
0
        /// <summary>
        /// Processes a compiled material and prepares it for disk writing.
        /// </summary>
        /// <param name="input">The CompiledMaterial instance to process.</param>
        /// <param name="context">The current content processor context.</param>
        /// <returns></returns>
        public override CompiledMaterial Process(CompiledMaterial input, ContentProcessorContext context)
        {
            input.compiledEffect = context.BuildAsset <EffectContent, CompiledEffectContent>(new ExternalReference <EffectContent>(string.Format("{0}{1}.fx", Path.GetFullPath("Effects/"), input.effect)), "EffectProcessor");

            // TODO: ExternalReference to textures, or leave management to run-time renderer?

            return(input);
        }
Exemple #23
0
 //build default texture accompany
 public void BuildTextures(ContentProcessorContext context)
 {
     //build texture.xnb files
     for (int i = 0; i < textures.Count; i++)
     {
         textures[i] = context.BuildAsset <TextureContent, TextureContent>(textures[i], "TextureProcessor");
     }
 }
        protected override ExternalReference<CompiledEffectContent> BuildEffect(ExternalReference<EffectContent> effect, ContentProcessorContext context)
        {
            OpaqueDataDictionary processorParameters = new OpaqueDataDictionary();

            if (context.Parameters.ContainsKey("Defines"))
                processorParameters.Add("Defines", context.Parameters["Defines"]);

            return context.BuildAsset<EffectContent, CompiledEffectContent>(effect, "DeferredRendererFXProcessor", processorParameters, "EffectImporter", effect.Name);
        }
Exemple #25
0
        public static ExternalReference <SpriteEditorSceneContent> CreateAndBuildExternalReference(
            string name, ContentProcessorContext context)
        {
            ExternalReference <SpriteEditorSceneContent> returnObject =
                new ExternalReference <FlatRedBall.Content.SpriteEditorSceneContent>(name);

            return(context.BuildAsset <SpriteEditorSceneContent, SpriteEditorSceneContent>(
                       returnObject, typeof(SceneFileProcessor).Name));
        }
 /// <summary>
 /// Builds an External Reference for use in the content pipeline
 /// </summary>
 public static ExternalReference <AnimationChainListSaveContent> BuildExternalReference(string path, ContentProcessorContext context)
 {
     return(context.BuildAsset <AnimationChainListSaveContent, AnimationChainListSaveContent>(
                new ExternalReference <AnimationChainListSaveContent>(path),
                typeof(AnimationChainArrayProcessor).Name,
                context.Parameters,
                typeof(AnimationChainArrayImporter).Name,
                null));
 }
Exemple #27
0
        protected override ExternalReference <CompiledEffectContent> BuildEffect(ExternalReference <EffectContent> effect, ContentProcessorContext context)
        {
            OpaqueDataDictionary processorParameters = new OpaqueDataDictionary();

            if (context.Parameters.ContainsKey("Defines"))
            {
                processorParameters.Add("Defines", context.Parameters["Defines"]);
            }
            return(context.BuildAsset <EffectContent, CompiledEffectContent>(effect, "LightPrePassFXProcessor", processorParameters, "EffectImporter", effect.Name));
        }
Exemple #28
0
 public virtual ExternalReference <TextureContent> BuildControlTexture(
     ContentProcessorContext context, string path)
 {
     return(context.BuildAsset <TextureContent, TextureContent>(
                new ExternalReference <TextureContent>(path),
                "SplatWeightProcessor",
                null,
                "TextureImporter",
                path.Substring(0, path.IndexOf('.'))));
 }
Exemple #29
0
        public override TOutput Process(TInput input, ContentProcessorContext context)
        {
            for (int i = 0; i < input.Count; i++)
            {
                Spawn s = input[i];
                ExternalReference <TextureContent> tc = new ExternalReference <TextureContent>(s.TextureFileName);
                s.Texture = context.BuildAsset <TextureContent, TextureContent>(tc, "TextureProcessor");
            }

            return(input);
        }
        public override ProjectContent Process(OepContent input, ContentProcessorContext context)
        {
            ProjectContent projectContent   = new ProjectContent(input.Document);
            string         workingDirectory = Path.GetFullPath(Path.Combine(input.Directory, projectContent.Settings.WorkingDirectory));

            foreach (TilesetContent tileset in projectContent.Tilesets)
            {
                string assetPath          = Path.Combine(workingDirectory, tileset.TextureFile);
                string asset              = assetPath.Remove(assetPath.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1);
                OpaqueDataDictionary data = new OpaqueDataDictionary();
                data.Add("GenerateMipmaps", false);
                data.Add("ResizeToPowerOfTwo", false);
                data.Add("TextureFormat", TextureProcessorOutputFormat.Color);
                data.Add("ColorKeyEnabled", false);
                data.Add("ColorKeyColor", Microsoft.Xna.Framework.Color.Magenta);
                tileset.TextureReference = context.BuildAsset <TextureContent, TextureContent>(
                    new ExternalReference <TextureContent>(assetPath),
                    "TextureProcessor",
                    data,
                    "TextureImporter",
                    asset);
            }
            foreach (ObjectTemplateContent obj in projectContent.Objects)
            {
                string assetPath          = Path.Combine(workingDirectory, obj.TextureFile);
                string asset              = assetPath.Remove(assetPath.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1);
                OpaqueDataDictionary data = new OpaqueDataDictionary();
                data.Add("GenerateMipmaps", false);
                data.Add("ResizeToPowerOfTwo", false);
                data.Add("TextureFormat", TextureProcessorOutputFormat.Color);
                data.Add("ColorKeyEnabled", false);
                data.Add("ColorKeyColor", Microsoft.Xna.Framework.Color.Magenta);
                obj.TextureReference = context.BuildAsset <TextureContent, TextureContent>(
                    new ExternalReference <TextureContent>(assetPath),
                    "TextureProcessor",
                    data,
                    "TextureImporter",
                    asset);
            }
            return(projectContent);
        }
        protected override ExternalReference<TextureContent> BuildTexture(string textureName, ExternalReference<TextureContent> texture, ContentProcessorContext context)
        {
            // Named textures will each have their own custom processor
            switch (textureName) {
                case HMModelProcessor.SPECULAR_MAP_KEY:
                    return context.BuildAsset<TextureContent, TextureContent>(texture, typeof (HMSpecularProcessor).Name);

                default:
                    // Default processing for all others
                    return base.BuildTexture(textureName, texture, context);
            }
        }
        protected override ExternalReference <TextureContent> BuildTexture(string textureName, ExternalReference <TextureContent> texture, ContentProcessorContext context)
        {
            OpaqueDataDictionary processorParameters = new OpaqueDataDictionary();

            processorParameters.Add("ColorKeyColor", this.ColorKeyColor);
            processorParameters.Add("ColorKeyEnabled", this.ColorKeyEnabled);
            processorParameters.Add("TextureFormat", this.TextureFormat);
            processorParameters.Add("GenerateMipmaps", this.GenerateMipmaps);
            processorParameters.Add("ResizeToPowerOfTwo", this.ResizeTexturesToPowerOfTwo);
            processorParameters.Add("ForceDXT5", this.ForceDXT5);
            return(context.BuildAsset <TextureContent, TextureContent>(texture, typeof(Dxt5TextureProcessor).Name, processorParameters, null, null));
        }
        private int torso_frames; //animation offset, for legs

        #endregion Fields

        #region Methods

        public void buildTextures(ContentProcessorContext context)
        {
            Dictionary<string, ExternalReference<TextureContent>>.Enumerator e = materials_list.GetEnumerator();
              built_textures = new List<ExternalReference<TextureContent>>();
              while (e.MoveNext())
              {
            ExternalReference<TextureContent> t = e.Current.Value;
            ExternalReference<TextureContent> builtTexture = context.BuildAsset<TextureContent, TextureContent>(t, "TextureProcessor");
            builtTexture.Name = e.Current.Key;
            built_textures.Add(builtTexture);
              }
        }
        /// <summary>
        /// Builds texture content.
        /// </summary>
        /// <param name="textureName">The name of the texture. This should correspond to the key used to store the texture in Textures.</param>
        /// <param name="texture">The asset to build. This should be a member of Textures.</param>
        /// <param name="context">Context for the specified processor.</param>
        /// <returns>The built texture content.</returns>
        /// <remarks>textureName can be used to determine which processor to use. For example, if a texture is being used as a normal map, the user may not want to use the ModelTextureProcessor on it, which compresses textures.</remarks>
        protected virtual ExternalReference <TextureContent> BuildTexture(string textureName, ExternalReference <TextureContent> texture, ContentProcessorContext context)
        {
            var parameters = new OpaqueDataDictionary();

            parameters.Add("ColorKeyColor", ColorKeyColor);
            parameters.Add("ColorKeyEnabled", ColorKeyEnabled);
            parameters.Add("GenerateMipmaps", GenerateMipmaps);
            parameters.Add("PremultiplyAlpha", PremultiplyTextureAlpha);
            parameters.Add("ResizeToPowerOfTwo", ResizeTexturesToPowerOfTwo);
            parameters.Add("TextureFormat", TextureFormat);

            return(context.BuildAsset <TextureContent, TextureContent>(texture, "TextureProcessor", parameters, "TextureImporter", null));
        }
        protected override ExternalReference<TextureContent> BuildTexture(string textureName, ExternalReference<TextureContent> texture,
            ContentProcessorContext context)
        {
            if (textureName == NormalMappingModelProcessor.NormalMapKey)
            {
                // put the normal map through the special NormalMapTextureProcessor,
                // which will convert it to a signed format.
                return context.BuildAsset<TextureContent, TextureContent>(texture,
                    typeof(NormalMapTextureProcessor).Name);
            }

            // Apply default processing to all other textures.
            return base.BuildTexture(textureName, texture, context);
        }
        protected override ExternalReference<TextureContent>  BuildTexture(string textureName, ExternalReference<TextureContent> texture, ContentProcessorContext context)
        {
            // Fallback if we aren't buiding for iOS.
            var platform = ContentHelper.GetMonoGamePlatform();
            if (platform != MonoGamePlatform.iOS)
                return base.BuildTexture(textureName, texture, context);
        
            var processorParameters = new OpaqueDataDictionary();
            processorParameters.Add("ColorKeyColor", this.ColorKeyColor);
            processorParameters.Add("ColorKeyEnabled", this.ColorKeyEnabled);
            processorParameters.Add("TextureFormat", this.TextureFormat);
            processorParameters.Add("GenerateMipmaps", this.GenerateMipmaps);
            processorParameters.Add("ResizeToPowerOfTwo", this.ResizeTexturesToPowerOfTwo);
            processorParameters.Add("PremultiplyAlpha", this.PremultiplyTextureAlpha);

            return context.BuildAsset<TextureContent, TextureContent>(texture, typeof(MGTextureProcessor).Name, processorParameters, null, null);
        }
        protected override MaterialContent ConvertMaterial(MaterialContent material,
           ContentProcessorContext context)
        {
            EffectMaterialContent lppMaterial = new EffectMaterialContent();

            OpaqueDataDictionary processorParameters = new OpaqueDataDictionary();
            processorParameters["ColorKeyColor"] = this.ColorKeyColor;
            processorParameters["ColorKeyEnabled"] = this.ColorKeyEnabled;
            processorParameters["TextureFormat"] = this.TextureFormat;
            processorParameters["GenerateMipmaps"] = this.GenerateMipmaps;
            processorParameters["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo;
            processorParameters["PremultiplyTextureAlpha"] = false;
            processorParameters["ColorKeyEnabled"] = false;

            lppMaterial.Effect = new ExternalReference<EffectContent>("shaders/LPPMainEffect.fx");
            lppMaterial.CompiledEffect = context.BuildAsset<EffectContent, CompiledEffectContent>(lppMaterial.Effect, "EffectProcessor");

            //extract the extra parameters
            ExtractDefines(lppMaterial, material, context);

            // copy the textures in the original material to the new normal mapping
            // material. this way the diffuse texture is preserved. The
            // PreprocessSceneHierarchy function has already added the normal map
            // texture to the Textures collection, so that will be copied as well.
            foreach (KeyValuePair<String, ExternalReference<TextureContent>> texture
                in material.Textures)
            {
                lppMaterial.Textures.Add(texture.Key, texture.Value);
            }

            try
            {
                lppMaterial.OpaqueData.Add("DiffuseColor", new Vector4((Vector3)material.OpaqueData["DiffuseColor"], (float)material.OpaqueData["Alpha"]));
                lppMaterial.OpaqueData.Add("SpecularColor", material.OpaqueData["SpecularColor"]);
                lppMaterial.OpaqueData.Add("SpecularPower", material.OpaqueData["SpecularPower"]);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            // and convert the material using the NormalMappingMaterialProcessor,
            // who has something special in store for the normal map.
            return context.Convert<MaterialContent, MaterialContent>
                (lppMaterial, typeof(LightPrePassMaterialProcessor).Name, processorParameters);
        }
		protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context)
		{
			if (string.IsNullOrEmpty(StitchedEffect))
				throw new Exception("Stitched Effect property must be set for StitchUp Model Processor.");

			string fullPath = Path.GetFullPath(Path.Combine(new FileInfo(material.Identity.SourceFilename).DirectoryName, StitchedEffect));
			context.AddDependency(fullPath);

			EffectMaterialContent effectMaterial = new EffectMaterialContent
			{
				CompiledEffect = context.BuildAsset<StitchedEffectContent, CompiledEffectContent>(new ExternalReference<StitchedEffectContent>(fullPath), typeof(StitchedEffectProcessor).Name),
				Identity = material.Identity,
				Name = material.Name
			};

			return effectMaterial;
		}
        public static ExternalReference<Texture2DContent> LoadTexture(string imagePath, Color? color_key, ContentProcessorContext context, string textureRoot = "")
        {
            string path = Path.Combine(textureRoot, imagePath);

                // the asset name is the entire path, minus extension, after the content directory
                string asset = string.Empty;
                if (path.StartsWith(Directory.GetCurrentDirectory()))
                    asset = path.Remove(imagePath.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1);
                else
                    asset = Path.GetFileNameWithoutExtension(path);

                // build the asset as an external reference
                OpaqueDataDictionary data = new OpaqueDataDictionary();
                data.Add("GenerateMipmaps", false);
                data.Add("ResizeToPowerOfTwo", false);
                data.Add("TextureFormat", TextureProcessorOutputFormat.Color);
                data.Add("ColorKeyEnabled", color_key.HasValue);
                data.Add("ColorKeyColor", color_key.HasValue ? color_key.Value : Microsoft.Xna.Framework.Color.Magenta);

                return context.BuildAsset<Texture2DContent, Texture2DContent>(
                    new ExternalReference<Texture2DContent>(path), null, data, null, asset);
        }
		protected override ExternalReference<CompiledEffectContent> BuildEffect(ExternalReference<EffectContent> effect, ContentProcessorContext context)
		{
			return context.BuildAsset<EffectContent, CompiledEffectContent>(effect, typeof(MGEffectProcessor).Name);
		}
 protected virtual ExternalReference<DRMaterialContent> OnBuildMaterial(ExternalReference<DRMaterialContent> material, ContentProcessorContext context)
 {
     return context.BuildAsset<DRMaterialContent, DRMaterialContent>(material, typeof(DRMaterialProcessor).Name, null, typeof(DRMaterialImporter).Name, null);
 }
Exemple #42
0
 public static string BuildTextureExternal(ContentProcessorContext context, string texPath)
 {
     var dir = Path.GetDirectoryName(texPath);
     return Path.Combine(dir, Path.GetFileNameWithoutExtension(context.BuildAsset<TextureContent, TextureContent>(new ExternalReference<TextureContent>(texPath), "TextureProcessor").Filename));
 }
        protected override MaterialContent ConvertMaterial(MaterialContent material,
           ContentProcessorContext context)
        {
            EffectMaterialContent lppMaterial = new EffectMaterialContent();

            OpaqueDataDictionary processorParameters = new OpaqueDataDictionary();
            processorParameters["ColorKeyColor"] = this.ColorKeyColor;
            processorParameters["ColorKeyEnabled"] = false;
            processorParameters["TextureFormat"] = this.TextureFormat;
            processorParameters["GenerateMipmaps"] = this.GenerateMipmaps;
            processorParameters["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo;
            processorParameters["PremultiplyTextureAlpha"] = false;
            processorParameters["ColorKeyEnabled"] = false;

            lppMaterial.Effect = new ExternalReference<EffectContent>(_customFx.Length == 0 ? "shaders/LPPMainEffect.fx" : _customFx);
            lppMaterial.CompiledEffect = context.BuildAsset<EffectContent, CompiledEffectContent>(lppMaterial.Effect, "EffectProcessor");

            // copy the textures in the original material to the new lpp
            // material
            ExtractTextures(lppMaterial, material);
            //extract the extra parameters
            ExtractDefines(lppMaterial, material, context);

            // and convert the material using the NormalMappingMaterialProcessor,
            // who has something special in store for the normal map.
            return context.Convert<MaterialContent, MaterialContent>
                (lppMaterial, typeof(LightPrePassMaterialProcessor).Name, processorParameters);
        }
        /// <summary>
        /// Builds a texture for use by this material.
        /// </summary>
        protected override ExternalReference<TextureContent> BuildTexture(
                                            string textureName,
                                            ExternalReference<TextureContent> texture,
                                            ContentProcessorContext context)
        {
            // Use our custom CubemapProcessor for the environment map texture.
            if (textureName == "EnvironmentMap")
            {
                return context.BuildAsset<TextureContent,
                                          TextureContent>(texture, "CubemapProcessor");
            }

            // Apply default processing to all other textures.
            return base.BuildTexture(textureName, texture, context);
        }
        protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context)
        {
            EffectMaterialContent deferredShadingMaterial = new EffectMaterialContent();
            deferredShadingMaterial.Effect = new ExternalReference<EffectContent>("../../GraphicsLibrary/GraphicsContent/Shaders/Deferred Rendering/RenderGBuffer.fx");
            deferredShadingMaterial.CompiledEffect = context.BuildAsset<EffectContent, CompiledEffectContent>(deferredShadingMaterial.Effect, "EffectProcessor");

            // copy the textures in the original material to the new normal mapping
            // material, if they are relevant to our renderer. The
            // LookUpTextures function has added the normal map and specular map
            // textures to the Textures collection, so that will be copied as well.
            foreach (KeyValuePair<String, ExternalReference<TextureContent>> texture in material.Textures)
            {
                if (texture.Key.Contains("DiffuseMap") || texture.Key.Contains("Texture"))
                    deferredShadingMaterial.Textures.Add(texture.Key, texture.Value);

                if (texture.Key.Contains("NormalMap"))
                    deferredShadingMaterial.Textures.Add(texture.Key, texture.Value);

                if (texture.Key.Contains("SpecularMap"))
                    deferredShadingMaterial.Textures.Add(texture.Key, texture.Value);

                if (texture.Key.Contains("EmissiveMap"))
                    deferredShadingMaterial.Textures.Add(texture.Key, texture.Value);
            }

            //extract the extra parameters
            ExtractDefines(deferredShadingMaterial, material, context);

            // Return material
            return context.Convert<MaterialContent, MaterialContent>(deferredShadingMaterial, typeof(DeferredRendererMaterialProcessor).Name);
        }
        /// <summary>
        /// builds an external reference to a texture
        /// </summary>
        internal static ExternalReference<TextureContent> BuildTexture(string file, ContentProcessorContext context)
        {
            ExternalReference<Texture2DContent> tex = new ExternalReference<Texture2DContent>(file);

            tex.Name = Path.GetFileNameWithoutExtension(file);

            CreateDictionaryIfNecessary();

            //string extension = Path.GetExtension(file);
            //UseBlackAsAlpha = extension.ToLower() == ".bmp";


            //if (UseBlackAsAlpha)
            //{
            //    TextureProcessor.ColorKeyColor = Color.Black;
            //    TextureProcessor.ColorKeyEnabled = true;
            //}
            //else
            //{
            //    TextureProcessor.ColorKeyEnabled = false;
            //}


            return context.BuildAsset<Texture2DContent, TextureContent>(
                    tex,
                    typeof(TextureProcessor).Name,
                    dictionary,
                    "TextureImporter",
                    null // Passing null lets the content pipeline decide on the default name, which is what we want.
                    );
        }
Exemple #47
0
 public static string BuildFontExternal(ContentProcessorContext context, string fontPath)
 {
     var dir = Path.GetDirectoryName(fontPath);
     return Path.Combine(dir, Path.GetFileNameWithoutExtension(context.BuildAsset<FontDescription, SpriteFontContent>(new ExternalReference<FontDescription>(fontPath), "FontDescriptionProcessor").Filename));
 }