Added first version of ContentBuilder. It is NOT PRODUCTION READY currently.

This is will be the CLI-version of the ContentPipeline replacement of ANX. It is able to use ContentImporters to import assets.
This commit is contained in:
Glatzemann 2012-08-21 08:17:17 +00:00
parent 72f4828ade
commit 4234155c8c
15 changed files with 402 additions and 7 deletions

View File

@ -34,6 +34,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="AnxContentImporterContext.cs" />
<Compile Include="Audio\AudioContent.cs" />
<Compile Include="Audio\AudioFileType.cs" />
<Compile Include="Audio\AudioFormat.cs" />
@ -165,6 +166,10 @@
<Compile Include="Serialization\Compiler\SystemTypeWriters\NullableWriter.cs" />
<Compile Include="Serialization\Compiler\SystemTypeWriters\TimeSpanWriter.cs" />
<Compile Include="TargetPlatform.cs" />
<Compile Include="Tasks\BuildContent.cs" />
<Compile Include="Tasks\BuildItem.cs" />
<Compile Include="Tasks\BuildRequest.cs" />
<Compile Include="Tasks\ImporterManager.cs" />
<Compile Include="VideoContent.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,57 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Content.Pipeline.Tasks;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline
{
public class AnxContentImporterContext : ContentImporterContext
{
private string intermediateDirectory;
private ContentBuildLogger logger;
private string outputDirectory;
public AnxContentImporterContext(BuildContent buildContent, BuildItem buildItem, ContentBuildLogger logger)
{
this.logger = logger;
}
public override string IntermediateDirectory
{
get
{
return intermediateDirectory;
}
}
public override ContentBuildLogger Logger
{
get
{
return Logger;
}
}
public override string OutputDirectory
{
get
{
return outputDirectory;
}
}
public override void AddDependency(string filename)
{
throw new NotImplementedException();
}
}
}

View File

@ -16,15 +16,14 @@ namespace ANX.Framework.Content.Pipeline
{
protected ContentImporter()
{
throw new NotImplementedException();
// nothing to do here
}
public abstract T Import(string filename, ContentImporterContext context);
Object ANX.Framework.Content.Pipeline.IContentImporter.Import(string filename, ContentImporterContext context)
object IContentImporter.Import(string filename, ContentImporterContext context)
{
throw new NotImplementedException();
return this.Import(filename, context);
}
}
}

View File

@ -16,7 +16,7 @@ namespace ANX.Framework.Content.Pipeline
{
public ContentImporterContext()
{
throw new NotImplementedException();
//TODO: implement
}
public abstract string IntermediateDirectory { get; }

View File

@ -16,7 +16,7 @@ namespace ANX.Framework.Content.Pipeline
{
public ContentItem()
{
throw new NotImplementedException();
// nothing to do here
}
public ContentIdentity Identity

View File

@ -13,6 +13,7 @@ using ANX.Framework.Content.Pipeline.Graphics;
namespace ANX.Framework.Content.Pipeline
{
[ContentImporter(".fx")]
public class EffectImporter : ContentImporter<EffectContent>
{
public EffectImporter()
@ -21,7 +22,13 @@ namespace ANX.Framework.Content.Pipeline
public override EffectContent Import(string filename, ContentImporterContext context)
{
throw new NotImplementedException();
EffectContent content = new EffectContent()
{
EffectCode = System.IO.File.ReadAllText(filename),
Identity = new ContentIdentity(filename, null, null),
};
return content;
}
}
}

View File

@ -13,6 +13,7 @@ using ANX.Framework.Content.Pipeline.Graphics;
namespace ANX.Framework.Content.Pipeline
{
[ContentImporter]
public class FbxImporter : ContentImporter<NodeContent>
{
public FbxImporter()

View File

@ -0,0 +1,51 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline.Tasks
{
public class BuildContent
{
private ImporterManager importerManager;
public ImporterManager ImporterManager
{
get
{
if (this.importerManager == null)
{
this.importerManager = new ImporterManager();
}
return this.importerManager;
}
}
public void Execute(IEnumerable<BuildItem> itemsToBuild)
{
foreach (BuildItem buildItem in itemsToBuild)
{
var importedObject = ImportAsset(buildItem);
}
}
private object ImportAsset(BuildItem item)
{
IContentImporter instance = this.ImporterManager.GetInstance(item.BuildRequest.ImporterName);
ContentImporterContext context = new AnxContentImporterContext(this, item, null); //this.buildLogger);
//this.buildLogger.LogMessage(Resources.BuildLogImporting, new object[]
//{
// item.BuildRequest.SourceFilename,
// instance.GetType()
//});
return instance.Import(item.BuildRequest.SourceFilename, context);
}
}
}

View File

@ -0,0 +1,24 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline.Tasks
{
public class BuildItem
{
public BuildRequest BuildRequest
{
get;
set;
}
}
}

View File

@ -0,0 +1,23 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline.Tasks
{
public class BuildRequest
{
public String SourceFilename;
public String AssetName;
public string ImporterName;
public string ProcessorName;
}
}

View File

@ -0,0 +1,70 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline.Tasks
{
public class ImporterManager
{
private Dictionary<String, Type> importerTypes = new Dictionary<string,Type>();
public ImporterManager()
{
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type type in assembly.GetTypes())
{
ContentImporterAttribute[] value = (ContentImporterAttribute[]) type.GetCustomAttributes(typeof(ContentImporterAttribute), true);
if (value.Length > 0)
{
importerTypes[type.Name] = type;
}
}
}
}
public IContentImporter GetInstance(string importerName)
{
Type type;
if (!this.importerTypes.TryGetValue(importerName, out type))
{
throw new Exception(String.Format("can't find importer {0}", importerName));
}
return (IContentImporter)Activator.CreateInstance(type);
}
public static String GuessImporterByFileExtension(string filename)
{
String extension = System.IO.Path.GetExtension(filename);
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type type in assembly.GetTypes())
{
ContentImporterAttribute[] value = (ContentImporterAttribute[])type.GetCustomAttributes(typeof(ContentImporterAttribute), true);
foreach (ContentImporterAttribute cia in value)
{
foreach (string fe in cia.FileExtensions)
{
if (string.Equals(fe, extension, StringComparison.InvariantCultureIgnoreCase))
{
return type.Name;
}
}
}
}
}
return String.Empty;
}
}
}

View File

@ -170,6 +170,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metro", "Metro", "{32B91ACB
shader\Metro\SpriteBatch.fx = shader\Metro\SpriteBatch.fx
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContentBuilder", "Tools\ContentBuilder\ContentBuilder.csproj", "{10F7894D-E8B5-4DCA-BB08-5C99FA792388}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -638,6 +640,16 @@ Global
{47B802CC-069D-431E-BF15-E574EDD3BA5D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{47B802CC-069D-431E-BF15-E574EDD3BA5D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{47B802CC-069D-431E-BF15-E574EDD3BA5D}.Release|x86.ActiveCfg = Release|Any CPU
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Debug|Any CPU.ActiveCfg = Debug|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Debug|Mixed Platforms.Build.0 = Debug|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Debug|x86.ActiveCfg = Debug|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Debug|x86.Build.0 = Debug|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Release|Any CPU.ActiveCfg = Release|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Release|Mixed Platforms.ActiveCfg = Release|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Release|Mixed Platforms.Build.0 = Release|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Release|x86.ActiveCfg = Release|x86
{10F7894D-E8B5-4DCA-BB08-5C99FA792388}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -649,6 +661,7 @@ Global
{9588B0C3-E03A-4C71-89A4-2C8685D426F1} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
{F9177943-1590-49AE-987D-D6FAE30D96DD} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
{47B802CC-069D-431E-BF15-E574EDD3BA5D} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
{10F7894D-E8B5-4DCA-BB08-5C99FA792388} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
{5BE49183-2F6F-4527-AC90-D816911FCF90} = {D421509A-9AE3-4D7E-881B-EAFED598B028}
{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} = {D421509A-9AE3-4D7E-881B-EAFED598B028}
{B30DE9C2-0926-46B6-8351-9AF276C472D5} = {D421509A-9AE3-4D7E-881B-EAFED598B028}

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{10F7894D-E8B5-4DCA-BB08-5C99FA792388}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ContentBuilder</RootNamespace>
<AssemblyName>ContentBuilder</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ANX.Framework.Content.Pipeline\ANX.Framework.Content.Pipeline.csproj">
<Project>{2DAFDFC1-223B-4741-87BB-BE3D0A7617DB}</Project>
<Name>ANX.Framework.Content.Pipeline</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,46 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Content.Pipeline.Tasks;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ContentBuilder
{
class Program
{
static void Main(string[] args)
{
//
// Generate a list of items to build and set build parameters
//
List<BuildItem> itemsToBuild = new List<BuildItem>();
foreach (string arg in args)
{
if (!arg.StartsWith("/") && !arg.StartsWith("-"))
{
BuildItem buildItem = new BuildItem();
buildItem.BuildRequest = new BuildRequest();
buildItem.BuildRequest.ImporterName = ImporterManager.GuessImporterByFileExtension(arg);
buildItem.BuildRequest.SourceFilename = arg;
buildItem.BuildRequest.AssetName = System.IO.Path.GetFileNameWithoutExtension(arg);
itemsToBuild.Add(buildItem);
}
}
//
// Build the content
//
BuildContent buildContentTask = new BuildContent();
buildContentTask.Execute(itemsToBuild);
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die mit einer Assembly verknüpft sind.
[assembly: AssemblyTitle("ContentBuilder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ANX Developer Team")]
[assembly: AssemblyProduct("ContentBuilder")]
[assembly: AssemblyCopyright("Copyright © ANX Developer Team 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("1ae48f9d-83a9-4a93-bc9b-7a51a501a42b")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]