public void SetInteriorColor(System.Windows.Media.SolidColorBrush brush) { bool was_running = Writer.IsRunning(); if (was_running) { Writer.Stop(); } //change out the color! CurrentAnimations.Clear(); AnimationDescriptor desc = new AnimationDescriptor(); desc.Animation = new SolidColor(new Color(brush.Color.R, brush.Color.G, brush.Color.B), 50); desc.CurrentFrame = 0; desc.Chain = PortSide; CurrentAnimations.Add(desc); desc = new AnimationDescriptor(); desc.Animation = new SolidColor(new Color(brush.Color.R, brush.Color.G, brush.Color.B), 50); desc.CurrentFrame = 0; desc.Chain = StarbordSide; CurrentAnimations.Add(desc); if (was_running) { Writer.Start(ComPort); } }
/// <summary> /// Frees up all resources used by this GDAnimStorageItem /// </summary> /// <param name="force">Whether to free up all AnimationDescriptor strips and frames</param> public void Free(bool force) { // If the freeing is forced, remove all textures from memory if (force) { // If we have an undisposed strip, dispose it if (AnimDesc.Strip != null && !AnimDesc.Strip.IsDisposed) { AnimDesc.Strip.Dispose(); } // Iterate through all the animation frames if (AnimDesc.Frames != null) { foreach (Texture2D text in AnimDesc.Frames) { // If the frame texture is undisposed, dispose it if (!text.IsDisposed) { text.Dispose(); } } } // Clear out all variables from the descriptor as well AnimDesc.Strip = null; AnimDesc.Frames = null; } AnimDesc = new AnimationDescriptor(); }
private float[] ReadValuesForDescriptor4_12Rotation(uint offset, AnimationDescriptor descriptor) { return((descriptor.m_ConstantValue) ? Read4_12Rotation((uint)(offset + (descriptor.m_StartOffset * 2)), 1) : Read4_12Rotation((uint)(offset + (descriptor.m_StartOffset * 2)), (int)(m_BCA.m_NumFrames / ((descriptor.m_Interpolate == 1) ? 2u : 1u) + (uint)descriptor.m_Interpolate))); }
public void SetRainbow() { bool was_running = Writer.IsRunning(); if (was_running) { Writer.Stop(); } CurrentAnimations.Clear(); AnimationDescriptor desc = new AnimationDescriptor(); desc.Animation = new RainbowCircle(); desc.CurrentFrame = 0; desc.Chain = PortSide; CurrentAnimations.Add(desc); desc = new AnimationDescriptor(); desc.Animation = new RainbowCircle(); desc.CurrentFrame = 0; desc.Chain = StarbordSide; CurrentAnimations.Add(desc); if (was_running) { Writer.Start(ComPort); } }
/// <summary> /// Gets an AnimationDescriptor assigned with the given keyname /// </summary> /// <param name="keyName">The keyname to look for</param> /// <returns>The AnimationDescriptor assigned with that keyname</returns> public static AnimationDescriptor Get(string keyName) { AnimationDescriptor desc = Content[keyName].AnimDesc; desc.Name = keyName; return(desc); }
/// <summary> /// Removes the AnimationDescriptor binded to the given keyName from the storage. /// It does not free the AnimationDescriptor, but instead only wipes out any reference of it from the storage. /// </summary> /// <param name="keyName">The keyName that is binded to an AnimationDescriptor</param> /// <returns>The removed AnimationDescriptor</returns> public static AnimationDescriptor Remove(string keyName) { // Get a temp copy of the descriptor AnimationDescriptor desc = Get(keyName); // Remove it from the contents Content.Remove(keyName); // Return the copy of the descriptor return(desc); }
public AnimationDescriptor LoadAnimation(string filePath) { if (_animations.ContainsKey(filePath)) { return(_animations[filePath]); } var animation = AnimationDescriptor.Load(filePath); _animations.Add(filePath, animation); return(animation); }
/// <summary> /// Adds an AnimationDescriptor directly into the dictionary, and assign a key to it /// </summary> /// <param name="desc">The AnimationDescriptor object</param> /// <param name="keyName">The key used to refere to the item</param> public static AnimationDescriptor Add(AnimationDescriptor desc, string keyName) { // Check if the key already exists if (Content.ContainsKey(keyName)) { throw new ArgumentException("The given key name " + keyName + " already exists in the dictionary", "keyName"); } desc.Name = keyName; Content[keyName] = new GDAnimStorageItem(desc, keyName); return(desc); }
public FileInfo AddAnimation(string filePath) { var animation = AnimationDescriptor.Create(); animation.Name = Path.GetFileNameWithoutExtension(filePath); animation.Save(filePath); var animationFile = new FileInfo(filePath); _animationFiles.Add(filePath, animationFile); this.AnimationAdded?.Invoke(this, new FileEventArgs(animationFile)); return(animationFile); }
public DockAnimationEditor(Project project, string text, Image icon, FileInfo file) : this() { _project = project; _regularDockText = text; _unsavedDockText = text + "*"; DockText = text; Icon = icon; _file = file; _animationDescription = _project.LoadAnimation(file.FullName); this.txtSurfaceTexPath.Text = _animationDescription.SurfaceAnimation.TexturePath; this.txtSurfaceFrameTime.Text = _animationDescription.SurfaceAnimation.FrameTime.ToString(); this.txtSurfaceFrameWidth.Text = _animationDescription.SurfaceAnimation.FrameWidth.ToString(); this.txtSurfaceFrameHeight.Text = _animationDescription.SurfaceAnimation.FrameHeight.ToString(); this.txtSurfaceLoopCount.Text = _animationDescription.SurfaceAnimation.LoopCount.ToString(); this.txtSubSurfaceTexPath.Text = _animationDescription.SubSurfaceAnimation.TexturePath; this.txtSubSurfaceFrameTime.Text = _animationDescription.SubSurfaceAnimation.FrameTime.ToString(); this.txtSubSurfaceFrameWidth.Text = _animationDescription.SubSurfaceAnimation.FrameWidth.ToString(); this.txtSubSurfaceFrameHeight.Text = _animationDescription.SubSurfaceAnimation.FrameHeight.ToString(); this.txtSubSurfaceLoopCount.Text = _animationDescription.SubSurfaceAnimation.LoopCount.ToString(); _subSurfaceAnimation = new Animation(_animationDescription); _surfaceAnimation = new Animation(_animationDescription); _subSurfaceAnimation.Play(); _surfaceAnimation.Play(); this.subSurfaceAnimView.OnDraw = OnSubAnimDraw; this.surfaceAnimView.OnDraw = OnSurfAnimDraw; this.subSurfaceAnimView.OnUpdate = OnSubAnimUpdate; this.surfaceAnimView.OnUpdate = OnSurfAnimUpdate; }
public AnimationData(BCA bca, uint offset, int boneID) { m_BCA = bca; m_ScaleX = new AnimationDescriptor(m_BCA.m_File, offset + 0x00); m_ScaleY = new AnimationDescriptor(m_BCA.m_File, offset + 0x04); m_ScaleZ = new AnimationDescriptor(m_BCA.m_File, offset + 0x08); m_RotationX = new AnimationDescriptor(m_BCA.m_File, offset + 0x0C); m_RotationY = new AnimationDescriptor(m_BCA.m_File, offset + 0x10); m_RotationZ = new AnimationDescriptor(m_BCA.m_File, offset + 0x14); m_TranslationX = new AnimationDescriptor(m_BCA.m_File, offset + 0x18); m_TranslationY = new AnimationDescriptor(m_BCA.m_File, offset + 0x1C); m_TranslationZ = new AnimationDescriptor(m_BCA.m_File, offset + 0x20); m_ScaleXValues = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleX); m_ScaleYValues = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleY); m_ScaleZValues = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleZ); m_RotationXValues = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationX); m_RotationYValues = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationY); m_RotationZValues = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationZ); m_TranslationXValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationX); m_TranslationYValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationY); m_TranslationZValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationZ); }
public AnimationDescriptors(Animation _animation, Animation _source) { AnimationDescriptorsResource adr = Resources.Load("AnimationDescriptorsResource", typeof(AnimationDescriptorsResource)) as AnimationDescriptorsResource; if (adr != null) { m_animations = new AnimationDescriptor[adr.m_descriptors.Length]; _source = (GameObject.Instantiate(_source.gameObject) as GameObject).GetComponent <Animation>(); for (int i = 0; i < adr.m_descriptors.Length; ++i) { AnimationClip clip = _source.GetClip(adr.m_descriptors[i].m_name); if (clip == null) { Debug.LogError("No se encuentra la animacion " + adr.m_descriptors[i].m_name + " " + _source.GetClipCount()); } else { _animation.AddClip(clip, adr.m_descriptors[i].m_name); m_animations[i] = new AnimationDescriptor(_animation[adr.m_descriptors[i].m_name], adr.m_descriptors[i].m_velocity); } } GameObject.Destroy(_source.gameObject); } }
public Animation(AnimationDescriptor description) : base(description) { }
public static void Load() { Monster = new AnimationDescriptor(SpriteSheets.Monster, 0.5f, 1, 2); NPC = new AnimationDescriptor(SpriteSheets.NPC, 0.5f, 1, 2); NPCAlerted = new AnimationDescriptor(SpriteSheets.NPC, 0.5f, 4, 5); }
private float[] ReadValuesForDescriptor4_12Rotation(uint offset, AnimationDescriptor descriptor) { return (descriptor.m_ConstantValue) ? Read4_12Rotation((uint)(offset + (descriptor.m_StartOffset * 2)), 1) : Read4_12Rotation((uint)(offset + (descriptor.m_StartOffset * 2)), (int)(m_BCA.m_NumFrames / ((descriptor.m_Interpolate == 1) ? 2u : 1u) + (uint)descriptor.m_Interpolate)); }
private float GetFrameValueForDescriptor(AnimationDescriptor descriptor, float[] values, int frameNum, bool isRotation = false) { float val; if (descriptor.m_ConstantValue) { val = values[0]; } else { if (descriptor.m_Interpolate == 1) { // Odd frames if ((frameNum & 1) != 0) { if ((frameNum >> 1) + 1 > values.Length - 1) { // if floor(frameNum / 2) + 1 > number of values, use floor(frameNum / 2) val = values[frameNum >> 1]; } else if (frameNum == (m_BCA.m_NumFrames - 1)) { // else if it's the last frame, don't interpolate val = values[(frameNum >> 1) + 1]; } else // else interpolate between current and next values { /* The below code checks for and corrects the following scenario: * Example: * The rotation of a bone is set to use interpolation and has the values -170 followed by 170. * Here, during interpolation the mid-point will be calculated as 0 instead of 180 as (-170 + 170) / 2 equals 0. * What we want is for the second value to be -190 so that during interpolation the midpoint is calculated as * (-170 + -190) / 2 equals -180 * * To correct this, the code checks: * 1) * eg. -170, 170: change to -170, -190 * eg. -5, 5: don't change * if (val1 < 0 && val2 > 0) * if ( abs(val2 - (val1 + 360)) < abs(val2 - val1)) then val2 -= 360 * // If the difference between values 1 and 2 is smaller when both are less than zero, make both less than zero * 2) * eg. 170, -170: change to 170, 190 * eg. 5, -5: don't change * if (val1 > 0 && val2 < 0) * if (abs(val1 - (val2 + 360)) < abs(val1 - val2)) then val2 += 360 * // If the difference between values 1 and 2 is smaller when both are greater then zero, math both greater than zero * * (Degrees used instead of radians to aid understanding) */ float val1 = values[frameNum >> 1]; float val2 = values[(frameNum >> 1) + 1]; if (isRotation) { if (val1 < 0f && val2 > 0f) { if (Math.Abs(val2 - (val1 + (Math.PI * 2f))) < Math.Abs(val2 - val1)) { val2 -= (float)(Math.PI * 2f); } } else if (val1 > 0f && val2 < 0f) { if (Math.Abs(val1 - (val2 + (Math.PI * 2f))) < Math.Abs(val1 - val2)) { val2 += (float)(Math.PI * 2f); } } } val = (val1 + val2) / 2f; } } else { // Even frames val = values[frameNum >> 1]; } } else { val = values[frameNum]; } } return val; }
private float GetFrameValueForDescriptor(AnimationDescriptor descriptor, float[] values, int frameNum, bool isRotation = false) { float val; if (descriptor.m_ConstantValue) { val = values[0]; } else { if (descriptor.m_Interpolate == 1) { // Odd frames if ((frameNum & 1) != 0) { if ((frameNum >> 1) + 1 > values.Length - 1) { // if floor(frameNum / 2) + 1 > number of values, use floor(frameNum / 2) val = values[frameNum >> 1]; } else if (frameNum == (m_BCA.m_NumFrames - 1)) { // else if it's the last frame, don't interpolate val = values[(frameNum >> 1) + 1]; } else // else interpolate between current and next values { /* The below code checks for and corrects the following scenario: * Example: * The rotation of a bone is set to use interpolation and has the values -170 followed by 170. * Here, during interpolation the mid-point will be calculated as 0 instead of 180 as (-170 + 170) / 2 equals 0. * What we want is for the second value to be -190 so that during interpolation the midpoint is calculated as * (-170 + -190) / 2 equals -180 * * To correct this, the code checks: * 1) * eg. -170, 170: change to -170, -190 * eg. -5, 5: don't change * if (val1 < 0 && val2 > 0) * if ( abs(val2 - (val1 + 360)) < abs(val2 - val1)) then val2 -= 360 * // If the difference between values 1 and 2 is smaller when both are less than zero, make both less than zero * 2) * eg. 170, -170: change to 170, 190 * eg. 5, -5: don't change * if (val1 > 0 && val2 < 0) * if (abs(val1 - (val2 + 360)) < abs(val1 - val2)) then val2 += 360 * // If the difference between values 1 and 2 is smaller when both are greater then zero, math both greater than zero * * (Degrees used instead of radians to aid understanding) */ float val1 = values[frameNum >> 1]; float val2 = values[(frameNum >> 1) + 1]; if (isRotation) { if (val1 < 0f && val2 > 0f) { if (Math.Abs(val2 - (val1 + (Math.PI * 2f))) < Math.Abs(val2 - val1)) { val2 -= (float)(Math.PI * 2f); } } else if (val1 > 0f && val2 < 0f) { if (Math.Abs(val1 - (val2 + (Math.PI * 2f))) < Math.Abs(val1 - val2)) { val2 += (float)(Math.PI * 2f); } } } val = (val1 + val2) / 2f; } } else { // Even frames val = values[frameNum >> 1]; } } else { val = values[frameNum]; } } return(val); }
/// <summary> /// Creates a new instance of the GDAnimStorageItem class /// </summary> /// <param name="desc">The AnimationDescriptor to assign to this GDAnimStorageItem</param> /// <param name="name">The name to assign to this GDAnimStorageItem</param> public GDAnimStorageItem(AnimationDescriptor desc, string name) { AnimDesc = desc; Name = name; }