/// <summary>
		/// Builds asset
		/// </summary>
		/// <param name="buildContext"></param>
		public override void Build ( BuildContext buildContext )
		{														   
			string tempFileName		= buildContext.GetTempFileName( AssetPath, ".fnt" );
			string resolvedPath		= buildContext.Resolve( SourceFile );	

			//	Launch 'bmfont.com' with temporary output file :
			buildContext.RunTool( @"bmfont.com",  string.Format("-c \"{0}\" -o \"{1}\"", resolvedPath, tempFileName ) );


			//	load temporary output :
			SpriteFont.FontFile font;
			using ( var stream = File.OpenRead( tempFileName ) ) {
				font = SpriteFont.FontLoader.Load( stream );
			}


			//	perform some checks :
			if (font.Common.Pages!=1) {
				throw new ContentException("Only one page of font image is supported");
			}


			//	patch font description and add children (e.g. "secondary") content :
			using ( var stream = buildContext.OpenTargetStream( this ) ) {

				using ( var sw = new BinaryWriter( stream ) ) {

					var xml = SpriteFont.FontLoader.SaveToString( font );
					sw.Write( xml );

					//	write pages :
					foreach (var p in font.Pages) {

						var pageFile	=	Path.Combine( Path.GetDirectoryName( tempFileName ), p.File );

						if ( Path.GetExtension( pageFile ).ToLower() == ".dds" ) {

							buildContext.CopyTo( pageFile, sw );

						} else {

							ImageFileTextureAsset.RunNVCompress( buildContext, pageFile, pageFile + ".dds", true, false, false, true, true, false, ImageFileTextureAsset.TextureCompression.RGB );

							buildContext.CopyTo( pageFile + ".dds", sw );

						}
					}
				}
			}
		}
		/// <summary>
		/// Builds asset
		/// </summary>
		/// <param name="buildContext"></param>
		public override void Build ( BuildContext buildContext )
		{
			var resolvedPath	=	buildContext.Resolve( SourceFile );
			var destPath		=	buildContext.GetTempFileName( Hash, ".scene" );
			var cmdLine			=	string.Format("\"{0}\" /out:\"{1}\" /merge:{2} {4} {5}", 
				resolvedPath, destPath, 
				MergeTolerance, 
				null, 
				ImportAnimation ? "/anim":"", 
				ImportGeometry ? "/geom":"" 
			);

			buildContext.RunTool( "Native.Fbx.exe", cmdLine );

			using ( var target = buildContext.OpenTargetStream( this ) ) {
				buildContext.CopyTo( destPath, target );
			}
		}
示例#3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="buildContext"></param>
		public override void Build ( BuildContext buildContext )
		{
			//
			//	Get combinations :
			//
			var combDecl	=	File.ReadAllLines( buildContext.Resolve( SourceFile ) )
									.Where( line0 => line0.Trim().StartsWith("$ubershader") )
									.ToList();

			var defineList = new List<string>();

			foreach ( var comb in combDecl ) {
				var ue = new UbershaderEnumerator( comb.Trim(), "$ubershader" );
				defineList.AddRange( ue.DefineList );
			}


			//
			//	Start listing builder :
			//	
			ListingPath	=	buildContext.GetTempFileName( AssetPath, ".html" );
			var htmlBuilder = new StringBuilder();

			htmlBuilder.AppendFormat("<pre>");
			htmlBuilder.AppendLine("<b>Ubershader assembly listing</b>");
			htmlBuilder.AppendLine("");
			htmlBuilder.AppendLine("<b>Source:</b> <i>" + AssetPath + "</i>" );
			htmlBuilder.AppendLine("");
			htmlBuilder.AppendLine("<b>Declarations:</b>");

			foreach ( var comb in combDecl ) {
				htmlBuilder.AppendLine("  <i>" + comb + "</i>");
			}
			htmlBuilder.AppendLine("");


			var usdb = new List<UsdbEntry>();

			//
			//	Build all :
			//
			foreach ( var defines in defineList ) {

				var id		=	defineList.IndexOf( defines );

				var psbc	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".PS.dxbc" );
				var vsbc	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".VS.dxbc" );
				var gsbc	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".GS.dxbc" );
				var hsbc	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".HS.dxbc" );
				var dsbc	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".DS.dxbc" );
				var csbc	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".CS.dxbc" );

				var pshtm	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".PS.html" );
				var vshtm	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".VS.html" );
				var gshtm	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".GS.html" );
				var hshtm	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".HS.html" );
				var dshtm	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".DS.html" );
				var cshtm	=	buildContext.GetTempFileName(AssetPath, "." + id.ToString("D4") + ".CS.html" );

				var ps = Compile( buildContext, SourceFile, "ps_5_0", PSEntryPoint, defines, psbc, pshtm );
				var vs = Compile( buildContext, SourceFile, "vs_5_0", VSEntryPoint, defines, vsbc, vshtm );
				var gs = Compile( buildContext, SourceFile, "gs_5_0", GSEntryPoint, defines, gsbc, gshtm );
				var hs = Compile( buildContext, SourceFile, "hs_5_0", HSEntryPoint, defines, hsbc, hshtm );
				var ds = Compile( buildContext, SourceFile, "ds_5_0", DSEntryPoint, defines, dsbc, dshtm );
				var cs = Compile( buildContext, SourceFile, "cs_5_0", CSEntryPoint, defines, csbc, cshtm );
				

				htmlBuilder.AppendFormat( (vs.Length==0) ? ".. " : "<a href=\"{0}\">vs</a> ", Path.GetFileName(vshtm) );
				htmlBuilder.AppendFormat( (ps.Length==0) ? ".. " : "<a href=\"{0}\">ps</a> ", Path.GetFileName(pshtm) );
				htmlBuilder.AppendFormat( (hs.Length==0) ? ".. " : "<a href=\"{0}\">hs</a> ", Path.GetFileName(hshtm) );
				htmlBuilder.AppendFormat( (ds.Length==0) ? ".. " : "<a href=\"{0}\">ds</a> ", Path.GetFileName(dshtm) );
				htmlBuilder.AppendFormat( (gs.Length==0) ? ".. " : "<a href=\"{0}\">gs</a> ", Path.GetFileName(gshtm) );
				htmlBuilder.AppendFormat( (cs.Length==0) ? ".. " : "<a href=\"{0}\">cs</a> ", Path.GetFileName(cshtm) );

				htmlBuilder.Append( "[" + defines + "]<br>" );

				usdb.Add( new UsdbEntry( defines, ps, vs, gs, hs, ds, cs ) );
			}

			File.WriteAllText( buildContext.GetTempFileName(AssetPath, ".html"), htmlBuilder.ToString() );


			//
			//	Write ubershader :
			//
			using ( var fs = buildContext.OpenTargetStream( this ) ) {

				using ( var bw = new BinaryWriter( fs ) ) {

					bw.Write( new[]{'U','S','D','B'});

					bw.Write( usdb.Count );

					foreach ( var entry in usdb ) {

						bw.Write( entry.Defines );

						bw.Write( new[]{'P','S','B','C'});
						bw.Write( entry.PSBytecode.Length );
						bw.Write( entry.PSBytecode );

						bw.Write( new[]{'V','S','B','C'});
						bw.Write( entry.VSBytecode.Length );
						bw.Write( entry.VSBytecode );

						bw.Write( new[]{'G','S','B','C'});
						bw.Write( entry.GSBytecode.Length );
						bw.Write( entry.GSBytecode );

						bw.Write( new[]{'H','S','B','C'});
						bw.Write( entry.HSBytecode.Length );
						bw.Write( entry.HSBytecode );

						bw.Write( new[]{'D','S','B','C'});
						bw.Write( entry.DSBytecode.Length );
						bw.Write( entry.DSBytecode );

						bw.Write( new[]{'C','S','B','C'});
						bw.Write( entry.CSBytecode.Length );
						bw.Write( entry.CSBytecode );
					}
				}
			}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="buildContext"></param>
		public override void Build ( BuildContext buildContext )
		{
			var fileNames	=	buildContext.ExpandAndResolveSearchPatterns( Dependencies );
			var images		=	fileNames
								.Select( fn => Image.LoadTga( fn ) )
								.OrderByDescending( img0 => img0.Width * img0.Height )
								.ThenByDescending( img1 => img1.Width )
								.ThenByDescending( img2 => img2.Height )
								.ToList();

			if (!images.Any()) {
				throw new InvalidOperationException("At least one subimage must be added to teh texture atlas");
			}


			//
			//	Pack atlas :
			//			
			AtlasNode root = new AtlasNode(0,0, Width, Height, Padding );

			foreach ( var img in images ) {
				var n = root.Insert( img );
				if (n==null) {
					throw new InvalidOperationException("No enough room to place image");
				}
			}

			//
			//	Create image and fill it with atlas elements :
			//	
			var targetImage	=	new Image( Width, Height );
			targetImage.Fill( FillColor );

			root.WriteImages( targetImage );

			//
			//	Save and compress :
			//
			var tgaOutput	=	buildContext.GetTempFileName( AssetPath, ".tga" );
			var ddsOutput	=	buildContext.GetTempFileName( AssetPath, ".dds" );
			Image.SaveTga( targetImage, tgaOutput );

			var compression =	UseDXT ? ImageFileTextureAsset.TextureCompression.BC3 : ImageFileTextureAsset.TextureCompression.RGB;
			ImageFileTextureAsset.RunNVCompress( buildContext, tgaOutput, ddsOutput, NoMips, false, false, true, true, false, compression );


			//
			//	Write binary blob (text + dds texture):
			//
			using ( var fs = buildContext.OpenTargetStream( this ) ) {
				var bw = new BinaryWriter( fs );

				bw.Write(new[]{'A','T','L','S'});
				bw.Write( images.Count ); 

				root.WriteLayout( bw );

				bw.Write( (int)(new FileInfo(ddsOutput).Length) );
				
				using ( var dds = File.OpenRead( ddsOutput ) ) {
					dds.CopyTo( fs );
				}
			}
		}
示例#5
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="buildContext"></param>
		public override void Build ( BuildContext buildContext )
		{
			Misc.SaveObjectToXml( this, GetType(), buildContext.OpenTargetStream( this ) );
		}
		/// <summary>
		/// Builds asset
		/// </summary>
		/// <param name="buildContext"></param>
		public override void Build ( BuildContext buildContext )
		{
			using ( var target = buildContext.OpenTargetStream( this ) ) {
				buildContext.CopyTo( SourceFile, target );
			}
		}
		public override void Build ( BuildContext buildContext )
		{
			var src	=	buildContext.Resolve( SourceFile );
			var dst	=	buildContext.GetTempFileName( Hash, ".dds" );

			RunNVCompress( buildContext, src, dst, NoMips, Fast, ToNormal, Color, Alpha, Normal, Compression );

			using ( var target = buildContext.OpenTargetStream( this ) ) {
				buildContext.CopyTo( dst, target );
			}
		}