本文整理汇总了C#中ContentProcessorContext.AddDependency方法的典型用法代码示例。如果您正苦于以下问题:C# ContentProcessorContext.AddDependency方法的具体用法?C# ContentProcessorContext.AddDependency怎么用?C# ContentProcessorContext.AddDependency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentProcessorContext
的用法示例。
在下文中一共展示了ContentProcessorContext.AddDependency方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public override SpriteFontContent Process(FontDescription input,
ContentProcessorContext context)
{
{
//ファイル読み込み
string fullPath = Path.GetFullPath("kana_list.txt");
context.AddDependency(fullPath);
string letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);
//フォントの追加
foreach (char c in letters)
{
input.Characters.Add(c);
}
}
{
//ファイル読み込み
string fullPath = Path.GetFullPath("kanji_list.txt");
context.AddDependency(fullPath);
string letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);
//フォントの追加
foreach (char c in letters)
{
input.Characters.Add(c);
}
}
return base.Process(input, context);
}
示例2: Process
/// <summary>
/// The main Process method converts an intermediate format content pipeline
/// NodeContent tree to a ModelContent object with embedded animation data.
/// </summary>
public override ModelContent Process(NodeContent input, ContentProcessorContext context)
{
contentPath = Environment.CurrentDirectory;
using (XmlReader reader = XmlReader.Create(MaterialDataFilePath))
{
incomingMaterials = IntermediateSerializer.Deserialize<List<MaterialData>>(reader, null);
}
context.AddDependency(Path.Combine(Environment.CurrentDirectory, MaterialDataFilePath));
// Chain to the base ModelProcessor class so it can convert the model data.
ModelContent model = base.Process(input, context);
// Put the material's flags into the ModelMeshPartContent's Tag property.
foreach (ModelMeshContent mmc in model.Meshes)
{
foreach (ModelMeshPartContent mmpc in mmc.MeshParts)
{
MaterialData mat = incomingMaterials.Single(m => m.Name == mmpc.Material.Name);
MaterialInfo extraInfo = new MaterialInfo();
extraInfo.HandlingFlags = mat.HandlingFlags;
extraInfo.RenderState = mat.RenderState;
mmpc.Tag = extraInfo;
}
}
return model;
}
示例3: Process
public override CompiledEffectContent Process(EffectContent input, ContentProcessorContext context)
{
//System.Diagnostics.Debugger.Launch();
// If this isn't a MonoGame platform then do the default processing.
var platform = ContentHelper.GetMonoGamePlatform();
if (platform == MonoGamePlatform.None)
return base.Process(input, context);
var options = new Options();
options.SourceFile = input.Identity.SourceFilename;
options.Profile = platform == MonoGamePlatform.Windows8 ? ShaderProfile.DirectX_11 : ShaderProfile.OpenGL;
options.Debug = DebugMode == EffectProcessorDebugMode.Debug;
options.OutputFile = context.OutputFilename;
// Parse the MGFX file expanding includes, macros, and returning the techniques.
ShaderInfo shaderInfo;
try
{
shaderInfo = ShaderInfo.FromFile(options.SourceFile, options);
foreach (var dep in shaderInfo.Dependencies)
context.AddDependency(dep);
}
catch (Exception ex)
{
// TODO: Extract good line numbers from mgfx parser!
throw new InvalidContentException(ex.Message, input.Identity, ex);
}
// Create the effect object.
EffectObject effect = null;
var shaderErrorsAndWarnings = string.Empty;
try
{
effect = EffectObject.CompileEffect(shaderInfo, out shaderErrorsAndWarnings);
}
catch (ShaderCompilerException)
{
throw ProcessErrorsAndWarnings(shaderErrorsAndWarnings, input, context);
}
// Write out the effect to a runtime format.
CompiledEffectContent result;
try
{
using (var stream = new MemoryStream())
{
using (var writer = new BinaryWriter(stream))
effect.Write(writer, options);
result = new CompiledEffectContent(stream.GetBuffer());
}
}
catch (Exception ex)
{
throw new InvalidContentException("Failed to serialize the effect!", input.Identity, ex);
}
return result;
}
示例4: Process
public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
{
string path = Path.GetFullPath(m_FilePath);
context.AddDependency(path);
string content = File.ReadAllText(path, Encoding.UTF8);//FontDescription.txt文件必须保存成utf-8格式,此处也需使用utf-8读取
foreach (char c in content)//读取文件中字符,存放到FontDescription中
{
input.Characters.Add(c);
}
return base.Process(input, context);
}
示例5: Process
public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
{
// TODO: 处理输入对象,并返回修改的数据。
string fullPath = Path.GetFullPath(MessageFile);
context.AddDependency(fullPath);
string letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);
foreach (char c in letters)
{
input.Characters.Add(c);
}
return base.Process(input, context);
}
示例6: ConvertMaterial
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;
}
示例7: Process
public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
{
var fullPath = Path.GetFullPath(MessageFile);
context.AddDependency(fullPath);
var letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);
foreach (char c in letters)
{
if (c == '\r' || c == '\n')
{
continue;
}
input.Characters.Add(c);
}
return base.Process(input, context);
}
示例8: ProcessAnimations
/// <summary>
/// Entry point for animation processing.
/// </summary>
/// <param name="model"></param>
/// <param name="input"></param>
/// <param name="context"></param>
private void ProcessAnimations(ModelContent model, NodeContent input, ContentProcessorContext context, ContentIdentity sourceIdentity)
{
// First build a lookup table so we can determine the
// index into the list of bones from a bone name.
for (int i = 0; i < model.Bones.Count; i++)
{
bones[model.Bones[i].Name] = i;
}
// For saving the bone transforms
boneTransforms = new Matrix[model.Bones.Count];
//
// Collect up all of the animation data
//
ProcessAnimationsRecursive(input);
// Check to see if there's an animation clip definition
// Here, we're checking for a file with the _Anims suffix.
// So, if your model is named dude.fbx, we'd add dude_Anims.xml in the same folder
// and the pipeline will see the file and use it to override the animations in the
// original model file.
string SourceModelFile = sourceIdentity.SourceFilename;
string SourcePath = Path.GetDirectoryName(SourceModelFile);
string AnimFilename = Path.GetFileNameWithoutExtension(SourceModelFile);
AnimFilename += "_Anims.xml";
string AnimPath = Path.Combine(SourcePath, AnimFilename);
if (File.Exists(AnimPath))
{
// Add the filename as a dependency, so if it changes, the model is rebuilt
context.AddDependency(AnimPath);
// Load the animation definition from the XML file
AnimationDefinition AnimDef = context.BuildAndLoadAsset<XmlImporter, AnimationDefinition>(new ExternalReference<XmlImporter>(AnimPath), null);
if (modelExtra.Clips.Count > 0) //if there are some animations in our model
{
foreach (AnimationDefinition.ClipPart Part in AnimDef.ClipParts)
{
// Grab the main clip that we are using and copy to MainClip
AnimationClip MainClip = new AnimationClip();
float StartTime = GetTimeSpanForFrame(Part.StartFrame, AnimDef.OriginalFrameCount, modelExtra.Clips[AnimDef.OriginalClipName].Duration);
float EndTime = GetTimeSpanForFrame(Part.EndFrame, AnimDef.OriginalFrameCount, modelExtra.Clips[AnimDef.OriginalClipName].Duration);
MainClip.Duration = EndTime-StartTime;
MainClip.Name = modelExtra.Clips[AnimDef.OriginalClipName].Name;
// Process each of our new animation clip parts
for (int i = 0; i < modelExtra.Clips[AnimDef.OriginalClipName].Bones.Count; i++)
{
AnimationClip.Bone clipBone = new AnimationClip.Bone();
clipBone.Name = modelExtra.Clips[AnimDef.OriginalClipName].Bones[i].Name;
LinkedList<AnimationClip.Keyframe> keyframes = new LinkedList<AnimationClip.Keyframe>();
if (modelExtra.Clips[AnimDef.OriginalClipName].Bones[i].Keyframes.Count != 0)
{
for (int j = 0; j < modelExtra.Clips[AnimDef.OriginalClipName].Bones[i].Keyframes.Count; j++)
{
if ((modelExtra.Clips[AnimDef.OriginalClipName].Bones[i].Keyframes[j].Time >= StartTime) && (modelExtra.Clips[AnimDef.OriginalClipName].Bones[i].Keyframes[j].Time <= EndTime))
{
AnimationClip.Keyframe frame = new AnimationClip.Keyframe();
frame.Rotation = modelExtra.Clips[AnimDef.OriginalClipName].Bones[i].Keyframes[j].Rotation;
frame.Time = modelExtra.Clips[AnimDef.OriginalClipName].Bones[i].Keyframes[j].Time - StartTime;
frame.Translation = modelExtra.Clips[AnimDef.OriginalClipName].Bones[i].Keyframes[j].Translation;
keyframes.AddLast(frame);
//clipBone.Keyframes.Add(frame);
}
}
}
// LinearKeyframeReduction(keyframes);
clipBone.Keyframes = keyframes.ToList<AnimationClip.Keyframe>();
MainClip.Bones.Add(clipBone);
}
modelExtra.Clips.Add(Part.ClipName, MainClip);
}
}
}
// Ensure there is always a clip, even if none is included in the FBX
// That way we can create poses using FBX files as one-frame
// animation clips
if (modelExtra.Clips.Count == 0)
{
AnimationClip clip = new AnimationClip();
modelExtra.Clips.Add("Take 001",clip);
//.........这里部分代码省略.........
示例9: Split
public static void Split(AnimationContentDictionary animationDictionary, string splitFile, ContentIdentity contentIdentity, ContentProcessorContext context)
{
if (animationDictionary == null)
return;
if (string.IsNullOrEmpty(splitFile))
return;
if (contentIdentity == null)
throw new ArgumentNullException("contentIdentity");
if (context == null)
throw new ArgumentNullException("context");
if (animationDictionary.Count == 0)
{
context.Logger.LogWarning(null, contentIdentity, "The model does not have an animation. Animation splitting is skipped.");
return;
}
if (animationDictionary.Count > 1)
context.Logger.LogWarning(null, contentIdentity, "The model contains more than 1 animation. The animation splitting is performed on the first animation. Other animations are deleted!");
// Load XML file.
splitFile = ContentHelper.FindFile(splitFile, contentIdentity);
XDocument document = XDocument.Load(splitFile, LoadOptions.SetLineInfo);
// Let the content pipeline know that we depend on this file and we need to
// rebuild the content if the file is modified.
context.AddDependency(splitFile);
// Parse XML.
var animationsElement = document.Element("Animations");
if (animationsElement == null)
{
context.Logger.LogWarning(null, contentIdentity, "The animation split file \"{0}\" does not contain an <Animations> root node.", splitFile);
return;
}
var wrappedContext = new ContentPipelineContext(context);
var splits = ParseAnimationSplitDefinitions(animationsElement, contentIdentity, wrappedContext);
if (splits == null || splits.Count == 0)
{
context.Logger.LogWarning(null, contentIdentity, "The XML file with the animation split definitions is invalid or empty. Animation is not split.");
return;
}
// Split animations.
Split(animationDictionary, splits, contentIdentity, context);
}
示例10: ProcessAnimations
/// <summary>
/// Converts an intermediate format content pipeline AnimationContentDictionary
/// object to our runtime AnimationClip format.
/// </summary>
static Dictionary<string, AnimationClip> ProcessAnimations(
AnimationContentDictionary animations, IList<BoneContent> bones,
ContentProcessorContext context, ContentIdentity sourceIdentity)
{
// Build up a table mapping bone names to indices.
Dictionary<string, int> boneMap = new Dictionary<string, int>();
for (int i = 0; i < bones.Count; i++)
{
string boneName = bones[i].Name;
if (!string.IsNullOrEmpty(boneName))
boneMap.Add(boneName, i);
}
// Convert each animation in turn.
Dictionary<string, AnimationClip> animationClips;
animationClips = new Dictionary<string, AnimationClip>();
foreach (KeyValuePair<string, AnimationContent> animation in animations)
{
AnimationClip processed = ProcessAnimation(animation.Value, boneMap, animation.Key);
animationClips.Add(animation.Key, processed);
}
// Check to see if there's an animation clip definition
// Here, we're checking for a file with the _Anims suffix.
// So, if your model is named dude.fbx, we'd add dude_Anims.xml in the same folder
// and the pipeline will see the file and use it to override the animations in the
// original model file.
string SourceModelFile = sourceIdentity.SourceFilename;
string SourcePath = Path.GetDirectoryName(SourceModelFile);
string AnimFilename = Path.GetFileNameWithoutExtension(SourceModelFile);
AnimFilename += "_Anims.xml";
string AnimPath = Path.Combine(SourcePath, AnimFilename);
if (File.Exists(AnimPath))
{
context.AddDependency(AnimPath);
AnimationDefinition AnimDef = context.BuildAndLoadAsset<XmlImporter, AnimationDefinition>(new ExternalReference<XmlImporter>(AnimPath), null);
//breaks up original animation clips into new clips
if (animationClips.ContainsKey(AnimDef.originalClipName))
{
//graps main clip
AnimationClip MainClip = animationClips[AnimDef.originalClipName];
//remove original clip from animations
animationClips.Remove(AnimDef.originalClipName);
foreach (AnimationDefinition.clipPart Part in AnimDef.ClipParts)
{
//calculate frame times
TimeSpan StartTime = GetTimeSpanForFrame(Part.StartFrame, AnimDef.originalFrameCount, MainClip.Duration.Ticks);
TimeSpan EndTime = GetTimeSpanForFrame(Part.EndFrame, AnimDef.originalFrameCount, MainClip.Duration.Ticks);
//get keyframes for animation clip thats in start and end time
List<Keyframe> Keyframes = new List<Keyframe>();
foreach (Keyframe AnimFrame in MainClip.Keyframes)
{
if ((AnimFrame.Time >= StartTime) && (AnimFrame.Time <= EndTime))
{
Keyframe NewFrame = new Keyframe(AnimFrame.Bone, AnimFrame.Time - StartTime, AnimFrame.Transform);
Keyframes.Add(NewFrame);
}
}
//process events
/*List<AnimationEvent> Events = new List<AnimationEvent>();
if (Part.Events != null)
{
foreach (AnimationDefinition.clipPart.Event Event in Part.Events)
{
TimeSpan EventTime = GetTimeSpanForFrame(Event.Keyframe, AnimDef.originalFrameCount, MainClip.Duration.Ticks);
EventTime -= StartTime;
AnimationEvent newEvent = new AnimationEvent();
newEvent.EventTime = EventTime;
newEvent.EventName = Event.Name;
Events.Add(newEvent);
}
}*/
AnimationClip newClip = new AnimationClip(EndTime - StartTime, Keyframes, Part.ClipName);
animationClips[Part.ClipName] = newClip;
}
}
}
/* if (animationClips.Count == 0)
{
throw new InvalidContentException(
"Input file does not contain any animations.");
}*/
return animationClips;
//.........这里部分代码省略.........
示例11: AppendCharacters
/// <summary>
/// FontDescriptionにMessageFilenameで指定されたファイル内の文字を追加する
/// </summary>
void AppendCharacters(FontDescription input, ContentProcessorContext context)
{
// MessageFilenameは有効な文字列か?
if (String.IsNullOrEmpty(MessageFilename))
return;
if (!File.Exists(MessageFilename))
{
throw new FileNotFoundException(
String.Format( "MessageFilenameで指定されたファイル[{0}]が存在しません",
Path.GetFullPath(MessageFilename)));
}
// 指定されたファイルから文字列を読み込み、
// FontDescription.Charctarsに追加する
try
{
int totalCharacterCount = 0;
using (StreamReader sr = File.OpenText(MessageFilename))
{
string line;
while ( ( line = sr.ReadLine() ) != null )
{
totalCharacterCount += line.Length;
foreach( char c in line )
input.Characters.Add(c);
}
}
context.Logger.LogImportantMessage("使用文字数{0}, 総文字数:{1}",
input.Characters.Count, totalCharacterCount);
// CPにファイル依存していることを教える
context.AddDependency(Path.GetFullPath(MessageFilename));
}
catch (Exception e)
{
// 予期しない例外が発生
context.Logger.LogImportantMessage("例外発生!! {0}", e.Message);
throw e;
}
}
示例12: ParseSplitAnimationFile
// Parses the XML file defining the splits.
// This method returns null if the file is not found.
// This method returns an empty collection if the file does not contain any split definitions or
// if the format is invalid.
private static List<SplitDefinition> ParseSplitAnimationFile(string splitFile, ContentIdentity contentIdentity, ContentProcessorContext context)
{
// Get full path of XML file. File location is relative to the location of the model.
string sourcePath = Path.GetDirectoryName(contentIdentity.SourceFilename);
string splitFilePath = Path.GetFullPath(Path.Combine(sourcePath, splitFile));
XDocument document;
try
{
document = XDocument.Load(splitFilePath);
}
catch (FileNotFoundException)
{
return null;
}
var splits = new List<SplitDefinition>();
// Let the content pipeline know that we depend on this file and we need to rebuild the
// content if the file is modified.
context.AddDependency(splitFilePath);
var animationsNode = document.Element("Animations");
if (animationsNode == null)
{
context.Logger.LogWarning(null, contentIdentity, splitFile + " does not contain an <Animations> root node.");
return splits;
}
double? framerate = (double?)animationsNode.Element("Framerate");
foreach (var animationNode in animationsNode.Elements("Animation"))
{
var name = (string)animationNode.Attribute("Name");
if (string.IsNullOrEmpty(name))
{
string message = string.Format("{0} contains an <Animation> element with a missing or empty 'Name' attribute", splitFile);
throw new InvalidContentException(message, contentIdentity);
}
double? startTime = (double?)animationNode.Attribute("StartTime");
double? endTime = (double?)animationNode.Attribute("EndTime");
int? startFrame = (int?)animationNode.Attribute("StartFrame");
int? endFrame = (int?)animationNode.Attribute("EndFrame");
if (startTime == null && startFrame == null)
{
string message = string.Format("{0} contains an <Animation> element that does not contain a valid 'StartTime' or 'StartFrame' attribute.", splitFile);
throw new InvalidContentException(message, contentIdentity);
}
if (endTime == null && endFrame == null)
{
string message = string.Format("{0} contains an <Animation> element that does not contain a valid 'EndTime' or 'EndFrame' attribute.", splitFile);
throw new InvalidContentException(message, contentIdentity);
}
if (framerate == null && (startTime == null || endTime == null))
{
string message = string.Format("{0} must have a <Framerate> element if start and end are specified in 'frames'.", splitFile);
throw new InvalidContentException(message, contentIdentity);
}
startTime = startTime ?? startFrame.Value / framerate.Value;
endTime = endTime ?? endFrame.Value / framerate.Value;
TimeSpan start = new TimeSpan((long)(startTime.Value * TimeSpan.TicksPerSecond));
TimeSpan end = new TimeSpan((long)(endTime.Value * TimeSpan.TicksPerSecond));
if (start > end)
{
string message = string.Format("{0} contains an invalid <Animation> element: The start time is larger than the end time.", splitFile);
throw new InvalidContentException(message, contentIdentity);
}
splits.Add(new SplitDefinition { Name = name, StartTime = start, EndTime = end });
}
return splits;
}
示例13: ProcessAnimations
/// <summary>
/// Converts an intermediate format content pipeline AnimationContentDictionary
/// object to our runtime AnimationClip format.
/// </summary>
static Dictionary<string, AnimationClip> ProcessAnimations(
AnimationContentDictionary animations, IList<BoneContent> bones,
ContentProcessorContext context, ContentIdentity sourceIdentity)
{
// Build up a table mapping bone names to indices.
Dictionary<string, int> boneMap = new Dictionary<string, int>();
for (int i = 0; i < bones.Count; i++)
{
string boneName = bones[i].Name;
if (!string.IsNullOrEmpty(boneName))
boneMap.Add(boneName, i);
}
// Convert each animation in turn.
Dictionary<string, AnimationClip> animationClips;
animationClips = new Dictionary<string, AnimationClip>();
// We process the original animation first, so we can use their keyframes
foreach (KeyValuePair<string, AnimationContent> animation in animations)
{
AnimationClip processed = ProcessAnimation(animation.Value, boneMap, animation.Key);
animationClips.Add(animation.Key, processed);
}
// Check to see if there's an animation clip definition
// Here, we're checking for a file with the _Anims suffix.
// So, if your model is named dude.fbx, we'd add dude_Anims.xml in the same folder
// and the pipeline will see the file and use it to override the animations in the
// original model file.
string SourceModelFile = sourceIdentity.SourceFilename;
string SourcePath = Path.GetDirectoryName(SourceModelFile);
string AnimFilename = Path.GetFileNameWithoutExtension(SourceModelFile);
AnimFilename += "_Anims.xml";
string AnimPath = Path.Combine(SourcePath, AnimFilename);
if (File.Exists(AnimPath))
{
// Add the filename as a dependency, so if it changes, the model is rebuilt
context.AddDependency(AnimPath);
// Load the animation definition from the XML file
AnimationDefinition AnimDef = context.BuildAndLoadAsset<XmlImporter, AnimationDefinition>(new ExternalReference<XmlImporter>(AnimPath), null);
// Break up the original animation clips into our new clips
// First, we check if the clips contains our clip to break up
if (animationClips.ContainsKey(AnimDef.OriginalClipName))
{
// Grab the main clip that we are using
AnimationClip MainClip = animationClips[AnimDef.OriginalClipName];
// Now remove the original clip from our animations
animationClips.Remove(AnimDef.OriginalClipName);
// Process each of our new animation clip parts
foreach (AnimationDefinition.ClipPart Part in AnimDef.ClipParts)
{
// Calculate the frame times
TimeSpan StartTime = GetTimeSpanForFrame(Part.StartFrame, AnimDef.OriginalFrameCount, MainClip.Duration.Ticks);
TimeSpan EndTime = GetTimeSpanForFrame(Part.EndFrame, AnimDef.OriginalFrameCount, MainClip.Duration.Ticks);
// Get all the keyframes for the animation clip
// that fall within the start and end time
List<Keyframe> Keyframes = new List<Keyframe>();
foreach (Keyframe AnimFrame in MainClip.Keyframes)
{
if ((AnimFrame.Time >= StartTime) && (AnimFrame.Time <= EndTime))
{
Keyframe NewFrame = new Keyframe(AnimFrame.Bone, AnimFrame.Time - StartTime, AnimFrame.Transform);
Keyframes.Add(NewFrame);
}
}
// Process the events
List<AnimationEvent> Events = new List<AnimationEvent>();
if (Part.Events != null)
{
// Process each event
foreach (AnimationDefinition.ClipPart.Event Event in Part.Events)
{
// Get the event time within the animation
TimeSpan EventTime = GetTimeSpanForFrame(Event.Keyframe, AnimDef.OriginalFrameCount, MainClip.Duration.Ticks);
// Offset the event time so it is relative to the start of the animation
EventTime -= StartTime;
// Create the event
AnimationEvent NewEvent = new AnimationEvent();
NewEvent.EventTime = EventTime;
NewEvent.EventName = Event.Name;
Events.Add(NewEvent);
}
}
// Create the clip
//.........这里部分代码省略.........
示例14: Process
/// <summary>
/// The main Process method converts an intermediate format content pipeline
/// NodeContent tree to a ModelContent object with embedded animation data.
/// </summary>
public override ModelContent Process(NodeContent input, ContentProcessorContext context)
{
ValidateMesh(input, context, null);
// Find the skeleton.
BoneContent skeleton = MeshHelper.FindSkeleton(input);
if (skeleton == null)
throw new InvalidContentException("Input skeleton not found.");
// We don't want to have to worry about different parts of the model being
// in different local coordinate systems, so let's just bake everything.
FlattenTransforms(input, skeleton);
// Read the bind pose and skeleton hierarchy data.
IList<BoneContent> bones = MeshHelper.FlattenSkeleton(skeleton);
// This value must match the constant of the same name in the Constants.fxh file.
const int MAX_BONES = 72;
if (bones.Count > MAX_BONES)
{
throw new InvalidContentException(string.Format(
"Skeleton has {0} bones, but the maximum supported is {1}.",
bones.Count, MAX_BONES));
}
List<Matrix> bindPose = new List<Matrix>();
List<Matrix> inverseBindPose = new List<Matrix>();
List<int> skeletonHierarchy = new List<int>();
foreach (BoneContent bone in bones)
{
bindPose.Add(bone.Transform);
inverseBindPose.Add(Matrix.Invert(bone.AbsoluteTransform));
skeletonHierarchy.Add(bones.IndexOf(bone.Parent as BoneContent));
}
contentPath = Environment.CurrentDirectory;
using (XmlReader reader = XmlReader.Create(MaterialDataFilePath))
{
incomingMaterials = IntermediateSerializer.Deserialize<List<MaterialData>>(reader, null);
}
context.AddDependency(Path.Combine(Environment.CurrentDirectory, MaterialDataFilePath));
// Placeholder for when you could perform other ModelMeshPart/GeometryContent processing:
//TraverseGeometryContents(input);
AnimationPackageData incomingAnimation;
using (XmlReader reader = XmlReader.Create(AnimationPackageDataFilePath))
{
incomingAnimation = IntermediateSerializer.Deserialize<AnimationPackageData>(reader, null);
}
context.AddDependency(Path.Combine(Environment.CurrentDirectory, AnimationPackageDataFilePath));
// Convert animation data to our runtime format.
Dictionary<string, Clip> animationClips;
animationClips = ProcessAnimations(skeleton.Animations, bones, incomingAnimation.Clips);
// Chain to the base ModelProcessor class so it can convert the model data.
ModelContent model = base.Process(input, context);
int modelMaxWeightsPerVert = 0;
const string WEIGHTSPERVERT_PARAM_NAME = "gWeightsPerVert";
// Put the material's extra data into the ModelMeshPartContent's Tag property.
// Also, note the largest value of "WeightsPerVert" used in any material.
foreach (ModelMeshContent mmc in model.Meshes)
{
foreach (ModelMeshPartContent mmpc in mmc.MeshParts)
{
MaterialData mat = incomingMaterials.Single(m => m.Name == mmpc.Material.Name);
MaterialInfo extraInfo = new MaterialInfo();
extraInfo.HandlingFlags = mat.HandlingFlags;
extraInfo.RenderState = mat.RenderState;
mmpc.Tag = extraInfo;
EffectParam wpvEp = mat.EffectParams.Find(wpv => wpv.Name == WEIGHTSPERVERT_PARAM_NAME);
if (wpvEp != null)
{
modelMaxWeightsPerVert = Math.Max(modelMaxWeightsPerVert, (int)(wpvEp.Value));
}
}
}
// Store our custom animation data in the Tag property of the model.
SkinningData skinningData = new SkinningData(animationClips, bindPose, inverseBindPose, skeletonHierarchy, modelMaxWeightsPerVert);
model.Tag = new AnimationPackage(
skinningData,
incomingAnimation.AnimationStateDescriptions,
incomingAnimation.AnimationNodeDescriptions,
incomingAnimation.InitialStateName,
//.........这里部分代码省略.........
示例15: AppendCharacters
/// <summary>
/// FontDescription��MessageFilename�Ŏw�肳�ꂽ�t�@�C����̕�����lj�����
/// </summary>
void AppendCharacters(FontDescription input, ContentProcessorContext context)
{
// MessageFilename�͗L���ȕ����H
if (String.IsNullOrEmpty(MessageFilename))
return;
if (!File.Exists(MessageFilename))
{
throw new FileNotFoundException(
String.Format( "MessageFilename�Ŏw�肳�ꂽ�t�@�C��[{0}]�����݂��܂���",
Path.GetFullPath(MessageFilename)));
}
// �w�肳�ꂽ�t�@�C�����當�����ǂݍ��݁A
// FontDescription.Charctars�ɒlj�����
try
{
int totalCharacterCount = 0;
using (StreamReader sr = File.OpenText(MessageFilename))
{
string line;
while ( ( line = sr.ReadLine() ) != null )
{
totalCharacterCount += line.Length;
foreach( char c in line )
input.Characters.Add( c );
}
}
context.Logger.LogImportantMessage("�g�p������{0}, ��������:{1}",
input.Characters.Count, totalCharacterCount);
// CP�Ƀt�@�C���ˑ����Ă��邱�Ƃ������
context.AddDependency(Path.GetFullPath(MessageFilename));
}
catch (Exception e)
{
// �\�����Ȃ���O������
context.Logger.LogImportantMessage("��O����!! {0}", e.Message);
throw e;
}
}