/// <summary> /// Loads a Skeleton from the given FilePath. Assumes the loading is from the ContentPaths.Dev. /// </summary> /// <param name="filePath">The file path.</param> /// <returns>The loaded Skeleton, or null if the Skeleton failed to load.</returns> public static Skeleton LoadSkeleton(string filePath) { var skeletonName = Path.GetFileNameWithoutExtension(filePath); var realFilePath = Skeleton.GetFilePath(skeletonName, ContentPaths.Dev); // Make sure the file exists if (!File.Exists(realFilePath)) { const string errmsg = "Failed to load Skeleton `{0}` from `{1}` - file does not exist."; var err = string.Format(errmsg, skeletonName, filePath); MessageBox.Show(err); return null; } // Try to load the skeleton Skeleton ret; try { ret = new Skeleton(skeletonName, ContentPaths.Dev); } catch (Exception ex) { const string errmsg = "Failed to load Skeleton `{0}` from `{1}`:{2}{3})"; var err = string.Format(errmsg, skeletonName, filePath, Environment.NewLine, ex); MessageBox.Show(err); return null; } return ret; }
/// <summary> /// Draws a <see cref="Skeleton"/>. /// </summary> /// <param name="skeleton">The <see cref="Skeleton"/> to draw.</param> /// <param name="camera">Camera to use.</param> /// <param name="sb">The <see cref="ISpriteBatch"/> to draw with.</param> /// <param name="selectedNode">The <see cref="SkeletonNode"/> to draw as selected.</param> public static void Draw(Skeleton skeleton, ICamera2D camera, ISpriteBatch sb, SkeletonNode selectedNode = null) { if (skeleton == null) { Debug.Fail("skeleton is null."); return; } if (skeleton.RootNode == null) { Debug.Fail("skeleton contains no root node."); return; } if (sb == null) { Debug.Fail("sb is null."); return; } if (sb.IsDisposed) { Debug.Fail("sb is disposed."); return; } if (camera == null) { Debug.Fail("camera is null."); return; } RecursiveDraw(camera, sb, selectedNode, skeleton.RootNode, 0); }
/// <summary> /// Gets a SkeletonSet for the standing Skeleton. /// </summary> /// <returns>A SkeletonSet for the standing Skeleton.</returns> public static SkeletonSet GetStandingSkeletonSet() { var newSkeleton = new Skeleton(StandingSkeletonName, ContentPaths.Dev); var nFrame0 = new SkeletonFrame(StandingSkeletonName, newSkeleton); var newSet = new SkeletonSet(new[] { nFrame0 }); return newSet; }
/// <summary> /// Initializes a new instance of the <see cref="SkeletonFrame"/> class. /// </summary> /// <param name="fileName">Path to the file used to load the frame</param> /// <param name="skeleton">Skeleton to use for the frame</param> /// <param name="delay">Amount of time the animation will stay on this frame in milliseconds. /// A value of 0 will result in the delay being found by the other frame - useful for stopped animation frames.</param> /// <exception cref="ArgumentNullException"><paramref name="skeleton" /> is <c>null</c>.</exception> public SkeletonFrame(string fileName, Skeleton skeleton, float delay = 0f) { if (skeleton == null) throw new ArgumentNullException("skeleton"); _fileName = fileName; _skeleton = skeleton; _delay = delay; }
/// <summary> /// Attaches the <see cref="SkeletonBodyItem"/> to a <see cref="Skeleton"/> using the name of the joints. /// </summary> /// <param name="skeleton"><see cref="Skeleton"/> to attach to.</param> internal void Attach(Skeleton skeleton) { // Source node if (skeleton == null) Source = null; else Source = skeleton.FindNode(ItemInfo.SourceName); // Destination node if (skeleton == null || ItemInfo.DestName.Length == 0) Dest = null; else Dest = skeleton.FindNode(ItemInfo.DestName); }
/// <summary> /// Attaches the body to a <see cref="Skeleton"/>. /// </summary> /// <param name="skeleton"><see cref="Skeleton"/> to attach to.</param> public void Attach(Skeleton skeleton) { if (skeleton == null) { Debug.Fail("skeleton is null."); return; } _skeleton = skeleton; foreach (var bodyItem in BodyItems) { bodyItem.Attach(skeleton); } }
/// <summary> /// Recursively copies the IsModifier property of the nodes in the <paramref name="source"/> Skeleton /// to this Skeleton. /// </summary> /// <param name="source">Source skeleton to copy the IsModifier property values from.</param> public void CopyIsModifier(Skeleton source) { CopyIsModifier(source._rootNode, _rootNode); }
/// <summary> /// Recursively copies the length of one set of nodes to another set of nodes /// </summary> /// <param name="src">Source skeleton to copy from</param> /// <param name="dest">Destination skeleton to copy to</param> public static void CopyLength(Skeleton src, Skeleton dest) { if (src == null) { Debug.Fail("src is null."); return; } if (dest == null) { Debug.Fail("dest is null."); return; } CopyIsModifier(src._rootNode, dest._rootNode); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.Load"/> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (DesignMode) return; // Create the engine objects _drawingManager = new DrawingManager(GameScreen.RenderWindow); _camera = new Camera2D(new Vector2(GameScreen.Width, GameScreen.Height)) { KeepInMap = false }; _content = ContentManager.Create(); _font = _content.LoadFont("Font/Arial", 14, ContentLevel.GameScreen); GrhInfo.Load(ContentPaths.Dev, _content); // Create the skeleton-related objects _skeleton = new Skeleton(); var frameSkeleton = new Skeleton(SkeletonLoader.StandingSkeletonName, ContentPaths.Dev); var frame = new SkeletonFrame(SkeletonLoader.StandingSkeletonName, frameSkeleton); _skeletonAnim = new SkeletonAnimation(GetTime(), frame); LoadFrame(Skeleton.GetFilePath(SkeletonLoader.StandingSkeletonName, ContentPaths.Dev)); LoadAnim(SkeletonSet.GetFilePath(SkeletonLoader.WalkingSkeletonSetName, ContentPaths.Dev)); LoadBody(SkeletonBodyInfo.GetFilePath(SkeletonLoader.BasicSkeletonBodyName, ContentPaths.Dev)); LoadSkelSets(ContentPaths.Build.Grhs + "\\Character\\Skeletons"); _watch.Start(); ResetCamera(); GameScreen.MouseWheel += GameScreen_MouseWheel; }
void LoadFrame(Skeleton skel) { _skeleton = skel; if (_frameBody != null) _frameBody.Attach(_skeleton); SelectedNode = _skeleton.RootNode; UpdateFrameNodeCBs(); }
/// <summary> /// Loads a SkeletonSet from a string array. /// </summary> /// <param name="framesTxt">Array containing the text for each frame in the format name/time, where /// name is the name of the skeleton model and time is the delay time of the frame.</param> /// <returns> /// The loaded SkeletonSet. /// </returns> /// <exception cref="ArgumentNullException"><paramref name="framesTxt"/> is null or empty.</exception> /// <exception cref="ArgumentException">framesTxt is null or empty.</exception> public static SkeletonSet LoadSkeletonSetFromString(string[] framesTxt) { if (framesTxt == null || framesTxt.Length == 0) { const string errmsg = "framesTxt cannot be null or empty."; throw new ArgumentException(errmsg, "framesTxt"); } var sep = new[] { "/" }; var frames = new SkeletonFrame[framesTxt.Length]; for (var i = 0; i < frames.Length; i++) { // Split up the time and frame name var frameInfo = framesTxt[i].Split(sep, StringSplitOptions.RemoveEmptyEntries); // If there is a defined time, use it float frameTime; if (frameInfo.Length == 1 || !Parser.Invariant.TryParse(frameInfo[1], out frameTime)) frameTime = 200f; if (frameTime <= 0) return null; // Create the keyframe var newSkeleton = new Skeleton(frameInfo[0], ContentPaths.Dev); frames[i] = new SkeletonFrame(frameInfo[0], newSkeleton, frameTime); } return new SkeletonSet(frames); }
/// <summary> /// Initializes a new instance of the <see cref="SkeletonBody"/> class. /// </summary> /// <param name="bodyInfo"><see cref="SkeletonBodyInfo"/> to create the <see cref="SkeletonBody"/> from.</param> /// <param name="skeleton"><see cref="Skeleton"/> to attach to.</param> public SkeletonBody(SkeletonBodyInfo bodyInfo, Skeleton skeleton) : this(bodyInfo) { Attach(skeleton); }
/// <summary> /// Reads the <see cref="SkeletonFrame"/> from an <see cref="IValueReader"/>. /// </summary> /// <param name="reader">The <see cref="IValueReader"/> to read from.</param> /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load additional assets.</param> public void Read(IValueReader reader, ContentPaths contentPath) { _delay = reader.ReadFloat(_delayValueKey); _fileName = reader.ReadString(_fileNameValueKey); _skeleton = new Skeleton(_fileName, contentPath); }
/// <summary> /// Initializes a new instance of the <see cref="SkeletonAnimation"/> class. /// </summary> /// <param name="currentTime">The current time.</param> /// <param name="skeletonSet"><see cref="SkeletonSet"/> to use for the keyframes.</param> /// <exception cref="ArgumentNullException"><paramref name="skeletonSet" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException">skeletonSet contains no KeyFrames.</exception> public SkeletonAnimation(TickCount currentTime, SkeletonSet skeletonSet) { if (skeletonSet == null) throw new ArgumentNullException("skeletonSet"); if (skeletonSet.KeyFrames.Length == 0) throw new ArgumentException("skeletonSet contains no KeyFrames.", "skeletonSet"); _lastTime = currentTime; _skelSet = skeletonSet; _currFrame = _skelSet.KeyFrames[0]; _nextFrame = _skelSet.KeyFrames.Length > 1 ? _skelSet.KeyFrames[1] : _skelSet.KeyFrames[0]; _skel = CurrentFrame.Skeleton.DeepCopy(); }
/// <exception cref="ArgumentNullException"><paramref name="set" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="skel" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="set"/> contians no KeyFrames.</exception> public static SkeletonSet CreateSmoothedSet(SkeletonSet set, Skeleton skel) { if (set == null) throw new ArgumentNullException("set"); if (skel == null) throw new ArgumentNullException("skel"); if (set.KeyFrames.Length == 0) throw new ArgumentException("Parameter `set` contians no KeyFrames.", "set"); // Create the new frames var frames = new SkeletonFrame[set.KeyFrames.Length + 2]; // Move the old frames into the new frames array for (var i = 0; i < set.KeyFrames.Length; i++) { frames[i + 1] = set.KeyFrames[i]; } // Set the first and last frame to the skeleton var lastFrame = frames.Length - 1; frames[0] = new SkeletonFrame(string.Empty, skel, frames[1].Delay); frames[lastFrame] = new SkeletonFrame(string.Empty, skel, frames[lastFrame - 1].Delay); // Copy over the IsModifier properties from the last frame from the old set // This is required to properly animate the new skeleton set // The last frame is used instead of the first since it is more important that // we transist out of the animation smoother than translating in, under the rare // and undesirable case that all IsModifier properties are not equal frames[0].Skeleton.CopyIsModifier(frames[lastFrame - 1].Skeleton); return new SkeletonSet(frames); }
/// <summary> /// Initializes a new instance of the <see cref="SkeletonBodyItem"/> class. /// </summary> /// <param name="itemInfo">SkeletonBodyItemInfo to create the SkeletonBodyItem from</param> /// <param name="skeleton">Skeleton to attach to</param> public SkeletonBodyItem(SkeletonBodyItemInfo itemInfo, Skeleton skeleton) : this(itemInfo) { Attach(skeleton); }