public static ModelData CreateModelData(Transform model, List<Vector3> controlPoints, List<RotationPoint> rotationPoints, List<List<Vector3>> detailLoaPoints, int strength) { ModelData modelData = new ModelData(); modelData.model = GenerateNode(model); //PrintAllNodes(modelData.model, "-"); foreach(Vector3 point in controlPoints) { modelData.controlPoints.Add(new Vector() { x = point.x, y = point.y, z = point.z }); } foreach(List<Vector3> layer in detailLoaPoints) { // Find closest index int index; FindClosestIntersect.Search (controlPoints, layer [layer.Count / 2], out index); AnimationLayer animationLayer = new AnimationLayer() { startFrame = Math.Min(strength, index + 1), numFrames = Math.Max(index - strength, 0) }; foreach(Vector3 point in layer) { animationLayer.layerPoints.Add(new Vector() { x = point.x, y = point.y, z = point.z }); } modelData.animationLayers.Add (animationLayer); } if (rotationPoints != null) { foreach (RotationPoint rotPoint in rotationPoints) { swellanimations.RotationPoint nrp = new swellanimations.RotationPoint() { Rotation = new Vector() { x = rotPoint.rotation.eulerAngles.x, y = rotPoint.rotation.eulerAngles.y, z = rotPoint.rotation.eulerAngles.z } }; nrp.numFrames = Math.Min(strength, rotPoint.index + 1); nrp.startFrame = Math.Max(rotPoint.index - strength, 0); modelData.rotationpoints.Add(nrp); } } return modelData; }
public void DrawLayer(CustomSpriteBatch g, AnimationLayer ActiveLayer, bool IsInEditMode, bool ShowBorderBoxes, bool ShowNextPositions, AnimationLayer Parent, bool DrawChild = true) { if (!ActiveLayer.IsVisible) { return; } if (DrawChild) { if (ActiveLayer.LayerBlendState == AnimationLayer.LayerBlendStates.Add) { g.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); } else if (ActiveLayer.LayerBlendState == AnimationLayer.LayerBlendStates.Substract) { g.Begin(SpriteSortMode.BackToFront, AnimationClass.NegativeBlendState); } else { GraphicsDevice.Clear(ClearOptions.Stencil, Color.Black, 0, 0); g.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, AlwaysStencilState, null, null); DrawLayer(g, ActiveLayer, false, false, false, Parent, false); g.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp, EqualStencilState, null, null); for (int A = 0; A < ActiveLayer.ListVisibleObject.Count; A++) { ActiveLayer.ListVisibleObject[A].Draw(g, IsInEditMode); } } } if (ActiveLayer.LayerBlendState != AnimationLayer.LayerBlendStates.Merge) { for (int A = 0; A < ActiveLayer.ListVisibleObject.Count; A++) { ActiveLayer.ListVisibleObject[A].Draw(g, IsInEditMode); } } for (int M = 0; M < ActiveLayer.ListActiveMarker.Count; M++) { if (ActiveLayer.ListActiveMarker[M].Sprite != null) { SpriteEffects ActiveEffect = SpriteEffects.None; if (ActiveLayer.ListActiveMarker[M].ScaleFactor.X < 0) { ActiveEffect = SpriteEffects.FlipHorizontally; } if (ActiveLayer.ListActiveMarker[M].ScaleFactor.Y < 0) { ActiveEffect |= SpriteEffects.FlipVertically; } g.Draw(ActiveLayer.ListActiveMarker[M].Sprite, new Vector2(ActiveLayer.ListActiveMarker[M].Position.X, ActiveLayer.ListActiveMarker[M].Position.Y), null, Color.White, ActiveLayer.ListActiveMarker[M].Angle, new Vector2(ActiveLayer.ListActiveMarker[M].Sprite.Width / 2, ActiveLayer.ListActiveMarker[M].Sprite.Height / 2), new Vector2(Math.Abs(ActiveLayer.ListActiveMarker[M].ScaleFactor.X), Math.Abs(ActiveLayer.ListActiveMarker[M].ScaleFactor.Y)), ActiveEffect, ActiveLayer.ListActiveMarker[M].DrawingDepth); } } g.End(); if (DrawChild) { for (int L = 0; L < ActiveLayer.ListChildren.Count; L++) { DrawLayer(g, ActiveLayer.ListChildren[L], IsInEditMode, ShowBorderBoxes, ShowNextPositions, ActiveLayer); } } g.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); #region Edit Mode if (IsInEditMode) { for (int A = 0; A < ActiveLayer.ListVisibleObject.Count; A++) { int MinX, MinY, MaxX, MaxY; ActiveLayer.ListVisibleObject[A].GetMinMax(out MinX, out MinY, out MaxX, out MaxY); int VisibleObjectWidth = MaxX - MinX; int VisibleObjectHeight = MaxY - MinY; Color DrawColor = Color.Black; if (ListSelectedObjects.Contains(ActiveLayer.ListVisibleObject[A])) { DrawColor = Color.Red; ActiveLayer.ListVisibleObject[A].DrawExtra(g, sprPixel); } #region Draw next positions if (ShowNextPositions) { ActiveLayer.ListVisibleObject[A].DrawNextPositions(g, sprPixel, DrawColor); } #endregion if (ShowBorderBoxes) { g.Draw(sprPixel, new Rectangle(MinX, MinY, VisibleObjectWidth, 1), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0); g.Draw(sprPixel, new Rectangle(MinX, MinY, 1, VisibleObjectHeight), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0); g.Draw(sprPixel, new Rectangle(MinX, MaxY, VisibleObjectWidth, 1), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0); g.Draw(sprPixel, new Rectangle(MaxX, MinY, 1, VisibleObjectHeight), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0); } if (ListSelectedObjects.Contains(ActiveLayer.ListVisibleObject[A]) && MultipleSelectionRectangle.Width > 0) { g.Draw(sprPixel, new Rectangle((int)(ActiveLayer.ListVisibleObject[A].Position.X - 2) + 1, (int)(ActiveLayer.ListVisibleObject[A].Position.Y - 2) + 1, 3, 3), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0); } } for (int M = 0; M < ActiveLayer.ListActiveMarker.Count; M++) { int MinX, MinY, MaxX, MaxY; ActiveLayer.ListActiveMarker[M].GetMinMax(out MinX, out MinY, out MaxX, out MaxY); Color DrawColor = Color.Black; if (ListSelectedObjects.Contains(ActiveLayer.ListActiveMarker[M])) { DrawColor = Color.Red; } //Draw next positions if (ShowNextPositions) { ActiveLayer.ListActiveMarker[M].DrawNextPositionForMakers(g, sprPixel); } if (ShowBorderBoxes) { g.Draw(sprPixel, new Rectangle(MinX, MinY, ActiveLayer.ListActiveMarker[M].Width, 1), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0); g.Draw(sprPixel, new Rectangle(MinX, MinY, 1, ActiveLayer.ListActiveMarker[M].Height), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0); g.Draw(sprPixel, new Rectangle(MinX, MinY + ActiveLayer.ListActiveMarker[M].Height, ActiveLayer.ListActiveMarker[M].Width, 1), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0); g.Draw(sprPixel, new Rectangle(MinX + ActiveLayer.ListActiveMarker[M].Width, MinY, 1, ActiveLayer.ListActiveMarker[M].Height), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0); } if (ListSelectedObjects.Contains(ActiveLayer.ListActiveMarker[M]) && MultipleSelectionRectangle.Width > 0) { g.Draw(sprPixel, new Rectangle((int)(ActiveLayer.ListActiveMarker[M].Position.X - 2) + 1, (int)(ActiveLayer.ListActiveMarker[M].Position.Y - 2) + 1, 3, 3), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0); } } for (int P = 0; P < ActiveLayer.ListPolygonCutter.Count; P++) { if (ListSelectedObjects.Contains(ActiveLayer.ListPolygonCutter[P])) { ActiveLayer.ListPolygonCutter[P].DrawExtra(g, sprPixel); } } } #endregion g.End(); }
public void DrawLayer(CustomSpriteBatch g, AnimationLayer ActiveLayer, bool DrawMarker, AnimationLayer Parent, bool DrawChild = true) { if (DrawChild) { //TODO: Don't use Begin to use the transformationMatrix as it force the rendering making it impossible to properly use the drawing depth. if (ActiveLayer.LayerBlendState == AnimationLayer.LayerBlendStates.Add) { g.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, ActiveLayer.SamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, TransformationMatrix); } else if (ActiveLayer.LayerBlendState == AnimationLayer.LayerBlendStates.Substract) { g.Begin(SpriteSortMode.BackToFront, NegativeBlendState, ActiveLayer.SamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, TransformationMatrix); } else { GraphicsDevice.Clear(ClearOptions.Stencil, Color.Black, 0, 0); g.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, AlwaysStencilState, null, null); DrawLayer(g, Parent, false, null, false); g.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp, EqualStencilState, null, null); for (int A = 0; A < ActiveLayer.ListVisibleObject.Count; A++) { ActiveLayer.ListVisibleObject[A].Draw(g, false); } } } for (int A = 0; A < ActiveLayer.ListVisibleObject.Count; A++) { ActiveLayer.ListVisibleObject[A].Draw(g, false); } if (DrawMarker) { for (int M = 0; M < ActiveLayer.ListActiveMarker.Count; M++) { AnimationClass ActiveMarkerAnimation = ActiveLayer.ListActiveMarker[M].AnimationMarker; AnimationOriginTimeline ActiveMarkerOrigin = ActiveMarkerAnimation.AnimationOrigin; for (int L = 0; L < ActiveMarkerAnimation.ListAnimationLayer.BasicLayerCount; L++) { SpriteEffects ActiveEffect = SpriteEffects.None; if (ActiveLayer.ListActiveMarker[M].ScaleFactor.X < 0) { ActiveEffect = SpriteEffects.FlipHorizontally; } if (ActiveLayer.ListActiveMarker[M].ScaleFactor.Y < 0) { ActiveEffect |= SpriteEffects.FlipVertically; } int OriginX = (int)ActiveMarkerOrigin.Position.X; if ((ActiveEffect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally) { OriginX = Constants.Width - (int)ActiveMarkerOrigin.Position.X; } g.Draw(ActiveMarkerAnimation.ListAnimationLayer[ActiveMarkerAnimation.ListAnimationLayer.BasicLayerCount - L - 1].renderTarget, new Vector2(ActiveLayer.ListActiveMarker[M].Position.X, ActiveLayer.ListActiveMarker[M].Position.Y), null, Color.White, 0, new Vector2(OriginX, ActiveMarkerOrigin.Position.Y), new Vector2(Math.Abs(ActiveLayer.ListActiveMarker[M].ScaleFactor.X), Math.Abs(ActiveLayer.ListActiveMarker[M].ScaleFactor.Y)), ActiveEffect, ActiveLayer.ListActiveMarker[M].DrawingDepth); } } } g.End(); if (DrawChild) { for (int L = 0; L < ActiveLayer.ListChildren.Count; L++) { DrawLayer(g, ActiveLayer.ListChildren[L], DrawMarker, ActiveLayer, true); } } }
public virtual void OnMarkerTimelineSpawn(AnimationLayer ActiveLayer, MarkerTimeline ActiveMarker) { ActiveLayer.ListActiveMarker.Add(ActiveMarker); }
public void Remove(AnimationLayer AnimationLayerToRemove) { ListAnimationLayer.Remove(AnimationLayerToRemove); }
public void Add(AnimationLayer NewAnimationLayer) { ListAnimationLayer.Add(NewAnimationLayer); }
public void SetAnimation(AnimationName name, AnimationLayer layer, bool blocking = false) { if (DefaultClient.OptimizeForServer()) { return; } int layerId = GetLayerId(layer); if (animator.IsInTransition(layerId)) { return; } stateInfo = animator.GetCurrentAnimatorStateInfo(layerId); if (blockingId != -1) { AnimatorStateInfo blockInfo = animator.GetCurrentAnimatorStateInfo(blockingLayer); if (blockState == BlockState.PreAnimation) { if (blockInfo.fullPathHash == blockingId) { blockState = BlockState.Animation; } return; } else if (blockState == BlockState.Animation) { if (blockInfo.fullPathHash == blockingId) { return; } else { blockingId = -1; blockState = BlockState.None; } } } int triggerId = GetTriggerId(name, layer); int currentTrigger = GetCurrentTrigger(layer); if (blocking) { blockingId = triggerId; blockingLayer = layerId; blockState = BlockState.PreAnimation; } if (currentTrigger == triggerId) { if (Time.time - lastReset > 0.20 && currentTrigger != stateInfo.fullPathHash) { SetCurrentTrigger(layer, stateInfo.fullPathHash); lastReset = Time.time; } else { return; } } if (stateInfo.fullPathHash == triggerId) { return; } animator.SetTrigger(triggerId); SetCurrentTrigger(layer, triggerId); }
public AnimationDescription(string name, AnimationLayer layer) { this.Name = name; this.Layer = layer; }
private void SetCurrentTrigger(AnimationLayer layer, int triggerId) { currentLayerTrigger[layer] = triggerId; }
private int GetCurrentTrigger(AnimationLayer layer) { if (!currentLayerTrigger.ContainsKey(layer)) { currentLayerTrigger[layer] = -1; } return currentLayerTrigger[layer]; }
private int GetLayerId(AnimationLayer layer) { if (!layerIndex.ContainsKey(layer)) { layerIndex[layer] = animator.GetLayerIndex(layer.ToString()); } return layerIndex[layer]; }
private int GetTriggerId(AnimationName name, AnimationLayer layer) { if (!layers.ContainsKey(layer)) { layers[layer] = new Dictionary<AnimationName, int>(); } if (!layers[layer].ContainsKey(name)) { string pathName = layer.ToString() + "." + name.ToString(); int pathHash = Animator.StringToHash(pathName); layers[layer][name] = pathHash; triggerNames[pathHash] = pathName; } return layers[layer][name]; }
public void SetAnimation(AnimationName name, AnimationLayer layer, bool blocking=false) { if (DefaultClient.OptimizeForServer()) { return; } int layerId = GetLayerId(layer); if (animator.IsInTransition(layerId)) { return; } stateInfo = animator.GetCurrentAnimatorStateInfo(layerId); if (blockingId != -1) { AnimatorStateInfo blockInfo = animator.GetCurrentAnimatorStateInfo(blockingLayer); if (blockState == BlockState.PreAnimation) { if (blockInfo.fullPathHash == blockingId) { blockState = BlockState.Animation; } return; } else if (blockState == BlockState.Animation) { if (blockInfo.fullPathHash == blockingId) { return; } else { blockingId = -1; blockState = BlockState.None; } } } int triggerId = GetTriggerId(name, layer); int currentTrigger = GetCurrentTrigger(layer); if (blocking) { blockingId = triggerId; blockingLayer = layerId; blockState = BlockState.PreAnimation; } if (currentTrigger == triggerId) { if (Time.time - lastReset > 0.20 && currentTrigger != stateInfo.fullPathHash) { SetCurrentTrigger(layer, stateInfo.fullPathHash); lastReset = Time.time; } else { return; } } if (stateInfo.fullPathHash == triggerId) { return; } animator.SetTrigger(triggerId); SetCurrentTrigger(layer, triggerId); }
public static bool GetAnimationLayerHasPRSKeyFrames(AnimationLayer l) { return(l.HasPRSKeyFrames); }
public static int GetAnimationLayerKeyType(AnimationLayer l) { return((int)l.KeyType); }
void BuildLayer(AnimationLayer layerType, string layerName, List <GestureAction> actions, MenuActions.MenuAction parentAction) { var controller = GetController(layerType); //Add parameter if (side == GestureSide.Left || side == GestureSide.Both) { AddParameter(controller, "GestureLeft", AnimatorControllerParameterType.Int, 0); } if (side == GestureSide.Right || side == GestureSide.Both) { AddParameter(controller, "GestureRight", AnimatorControllerParameterType.Int, 0); } //Prepare layer var layer = GetControllerLayer(controller, layerName); layer.stateMachine.entryTransitions = null; layer.stateMachine.anyStateTransitions = null; layer.stateMachine.states = null; layer.stateMachine.entryPosition = StatePosition(-1, 0); layer.stateMachine.anyStatePosition = StatePosition(-1, 1); layer.stateMachine.exitPosition = StatePosition(-1, 2); //Default state AnimatorState defaultState = null; GestureAction defaultAction = null; var unusedGestures = new List <GestureEnum>(); unusedGestures.Add(GestureEnum.Neutral); unusedGestures.Add(GestureEnum.Fist); unusedGestures.Add(GestureEnum.OpenHand); unusedGestures.Add(GestureEnum.FingerPoint); unusedGestures.Add(GestureEnum.Victory); unusedGestures.Add(GestureEnum.RockNRoll); unusedGestures.Add(GestureEnum.HandGun); unusedGestures.Add(GestureEnum.ThumbsUp); //Build states int actionIter = 0; foreach (var action in this.actions) { //Check if valid if (!action.gestureTable.IsModified()) { EditorUtility.DisplayDialog("Build Warning", $"Simple Gesture {action.name} has no selected conditions.", "Okay"); continue; } //Build var state = layer.stateMachine.AddState(action.name, StatePosition(0, actionIter + 1)); state.motion = action.GetAnimation(layerType, true); actionIter += 1; //Conditions AddGestureCondition(GestureEnum.Neutral); AddGestureCondition(GestureEnum.Fist); AddGestureCondition(GestureEnum.OpenHand); AddGestureCondition(GestureEnum.FingerPoint); AddGestureCondition(GestureEnum.Victory); AddGestureCondition(GestureEnum.RockNRoll); AddGestureCondition(GestureEnum.HandGun); AddGestureCondition(GestureEnum.ThumbsUp); void AddGestureCondition(BaseActions.GestureEnum gesture) { if (!action.gestureTable.GetValue(gesture)) { return; } //Transition var transition = layer.stateMachine.AddAnyStateTransition(state); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = action.fadeIn; if (side == GestureSide.Left || side == GestureSide.Both) { transition.AddCondition(AnimatorConditionMode.Equals, (int)gesture, "GestureLeft"); } if (side == GestureSide.Right || side == GestureSide.Both) { transition.AddCondition(AnimatorConditionMode.Equals, (int)gesture, "GestureRight"); } //Parent if (parentAction != null && gesture != GestureEnum.Neutral) { parentAction.AddCondition(transition, true); } //Cleanup unusedGestures.Remove(gesture); } //Default if (action.gestureTable.neutral) { defaultState = state; defaultAction = action; } } //Default state if (defaultState == null) { defaultState = layer.stateMachine.AddState("Neutral", StatePosition(0, 0)); } layer.stateMachine.defaultState = defaultState; //Animation Layer Weight var layerWeight = defaultState.AddStateMachineBehaviour <VRC.SDK3.Avatars.Components.VRCAnimatorLayerControl>(); layerWeight.goalWeight = 1; layerWeight.layer = GetLayerIndex(controller, layer); layerWeight.blendDuration = 0; layerWeight.playable = VRC.SDKBase.VRC_AnimatorLayerControl.BlendableLayer.FX; //Default transitions foreach (var gesture in unusedGestures) { //Transition var transition = layer.stateMachine.AddAnyStateTransition(defaultState); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = defaultAction != null ? defaultAction.fadeIn : 0f; if (side == GestureSide.Left || side == GestureSide.Both) { transition.AddCondition(AnimatorConditionMode.Equals, (int)gesture, "GestureLeft"); } if (side == GestureSide.Right || side == GestureSide.Both) { transition.AddCondition(AnimatorConditionMode.Equals, (int)gesture, "GestureRight"); } } //Parent if (parentAction != null) { var transition = layer.stateMachine.AddAnyStateTransition(defaultState); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = defaultAction != null ? defaultAction.fadeIn : 0f; parentAction.AddCondition(transition, false); } }
private IEnumerator SetCurrentTrigger(AnimationLayer layer) { yield return new WaitForEndOfFrame(); int layerId = GetLayerId(layer); stateInfo = animator.GetCurrentAnimatorStateInfo(layerId); SetCurrentTrigger(layer, stateInfo.fullPathHash); }
void BuildLayer(AnimationLayer layerType, string layerName, List <VisemeAction> actions, MenuActions.MenuAction parentAction) { var controller = GetController(layerType); var VisemeValues = System.Enum.GetValues(typeof(VisemeEnum)).Cast <VisemeEnum>(); //Add parameter AddParameter(controller, "Viseme", AnimatorControllerParameterType.Int, 0); //Prepare layer var layer = GetControllerLayer(controller, layerName); layer.stateMachine.entryTransitions = null; layer.stateMachine.anyStateTransitions = null; layer.stateMachine.states = null; layer.stateMachine.entryPosition = StatePosition(-1, 0); layer.stateMachine.anyStatePosition = StatePosition(-1, 1); layer.stateMachine.exitPosition = StatePosition(-1, 2); //Default AnimatorState defaultState = null; VisemeAction defaultAction = null; var unusedValues = new List <VisemeEnum>(); foreach (var value in VisemeValues) { unusedValues.Add(value); } //Build states int actionIter = 0; foreach (var action in this.actions) { //Check if valid if (!action.visimeTable.IsModified()) { EditorUtility.DisplayDialog("Build Warning", $"Visemes {action.name} has no selected conditions.", "Okay"); continue; } //Build var state = layer.stateMachine.AddState(action.name, StatePosition(0, actionIter + 1)); state.motion = action.GetAnimation(layerType, true); actionIter += 1; //Conditions foreach (var value in VisemeValues) { AddCondition(value); } void AddCondition(BaseActions.VisemeEnum visime) { if (action.visimeTable.GetValue(visime)) { //Transition var transition = layer.stateMachine.AddAnyStateTransition(state); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = action.fadeIn; transition.canTransitionToSelf = false; transition.AddCondition(AnimatorConditionMode.Equals, (int)visime, "Viseme"); //Parent if (parentAction != null) { parentAction.AddCondition(transition, true); } //Cleanup unusedValues.Remove(visime); } } //Store default if (action.visimeTable.sil) { defaultState = state; defaultAction = action; } } //Default state if (defaultState == null) { defaultState = layer.stateMachine.AddState("Default", StatePosition(0, 0)); } layer.stateMachine.defaultState = defaultState; //Animation Layer Weight var layerWeight = defaultState.AddStateMachineBehaviour <VRC.SDK3.Avatars.Components.VRCAnimatorLayerControl>(); layerWeight.goalWeight = 1; layerWeight.layer = GetLayerIndex(controller, layer); layerWeight.blendDuration = 0; layerWeight.playable = VRC.SDKBase.VRC_AnimatorLayerControl.BlendableLayer.FX; //Default transitions foreach (var visime in unusedValues) { //Transition var transition = layer.stateMachine.AddAnyStateTransition(defaultState); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = defaultAction != null ? defaultAction.fadeIn : 0f; transition.canTransitionToSelf = false; transition.AddCondition(AnimatorConditionMode.Equals, (int)visime, "Viseme"); } //Parent if (parentAction != null) { var transition = layer.stateMachine.AddAnyStateTransition(defaultState); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = defaultAction != null ? defaultAction.fadeIn : 0f; transition.canTransitionToSelf = false; parentAction.AddCondition(transition, false); } }
private static async Task <AnimationLayer> initialLayer(Frame f) { //Animation a = new Animation(); //a.Layers = new List<AnimationLayer>(); var layer = new AnimationLayer(); layer.Ty = 4; layer.Ks = new KsClass(); layer.Ip = f.Index; layer.Op = f.Index + 1; //might not need +1 layer.St = layer.Ip; layer.Sr = 1; layer.Shapes = new List <LayerIt>(); foreach (var shape in f.Shapes) { var groupshape = new LayerIt() { }; groupshape.Ty = "gr"; groupshape.Nm = ""; groupshape.Bm = 0; groupshape.It = new List <ItIt>(); var shapeRect = new ItIt(); shapeRect.Ty = "rc"; shapeRect.Nm = ""; //shapeRect.D = 1; shapeRect.P = new PurplePosition() { K = new double[] { (shape.Start.X + shape.End.X) / 2, (shape.Start.Y + shape.End.Y) / 2 } }; shapeRect.S = new PurpleSize() { K = new CK() { AnythingArray = new double[] { shape.End.X + shape.Start.X, shape.End.Y + shape.Start.Y } } }; var shapeFl = new ItIt(); shapeFl.Ty = "fl"; shapeFl.C = new PurpleColor() { K = new int[] { shape.Color.R, shape.Color.G, 255 } }; var shapeTr = new ItIt(); shapeTr.Ty = "tr"; groupshape.It.Add(shapeRect); groupshape.It.Add(shapeFl); groupshape.It.Add(shapeTr); layer.Shapes.Add(groupshape); } //Layer l = new Layer(); //l.Type = 4; //l.Ks = new LayerKs(); return(layer); }
public override void OnMarkerTimelineSpawn(AnimationLayer ActiveLayer, MarkerTimeline ActiveMarker) { base.OnMarkerTimelineSpawn(ActiveLayer, ActiveMarker); ActiveMarker.UpdateAnimationObject(ActiveMarker.SpawnFrame); }
public void Insert(int Index, AnimationLayer NewAnimationLayer) { ListAnimationLayer.Insert(Index, NewAnimationLayer); }
public static IEnumerator AnimateLayer <TObject>( AnimationLayer a_AnimationLayer, TObject a_Object) where TObject : Graphic { float endTime = GetEndTime(a_AnimationLayer.animationDataList); Vector3 originalPosition = a_Object.transform.position; float deltaTime = 0.0f; while (deltaTime < endTime) { deltaTime += Time.deltaTime; foreach (AnimationData animationData in a_AnimationLayer.animationDataList) { if (a_Object.IsDestroyed()) { yield break; } switch (animationData.animationType) { case AnimationType.Fade: { if (animationData.animationCurves[0][0].time <= deltaTime) { a_Object.color = new Color( a_Object.color.r, a_Object.color.g, a_Object.color.b, animationData.animationCurves[0].Evaluate(deltaTime)); } } break; case AnimationType.Scale: { if (animationData.animationCurves[0][0].time <= deltaTime) { a_Object.transform.localScale = new Vector3( animationData.animationCurves[0].Evaluate(deltaTime), animationData.animationCurves[1].Evaluate(deltaTime)); } } break; case AnimationType.Rotate: { if (animationData.animationCurves[0][0].time <= deltaTime) { a_Object.transform.eulerAngles = new Vector3( animationData.animationCurves[0].Evaluate(deltaTime) * 360, animationData.animationCurves[1].Evaluate(deltaTime) * 360); } } break; case AnimationType.Translate: { if (animationData.animationCurves[0][0].time <= deltaTime) { a_Object.transform.position = new Vector3( originalPosition.x + animationData.animationCurves[0].Evaluate(deltaTime), originalPosition.y + animationData.animationCurves[1].Evaluate(deltaTime)); } } break; default: Debug.Log("Not Yet Implemented..."); break; } } yield return(null); } }
//The methods starting with "On" should only be called directly by the Timelines public virtual void OnVisibleTimelineSpawn(AnimationLayer ActiveLayer, VisibleTimeline ActiveTimeline) { ActiveLayer.ListVisibleObject.Add(ActiveTimeline); }
void Animations() { animationController = new AnimationController(SpriteInstance); var idleLayer = new AnimationLayer(); idleLayer.EveryFrameAction = () => { if (PassonClass.mariobig == true) { return("Idle_Big" + DirectionFacing); } return("Idle_small" + DirectionFacing); }; animationController.Layers.Add(idleLayer); var walkLayer = new AnimationLayer(); walkLayer.EveryFrameAction = () => { if (this.Velocity.X != 0) { if (PassonClass.mariobig == true) { return("Walking_Big" + DirectionFacing); } return("Walking_small" + DirectionFacing); } return(null); }; animationController.Layers.Add(walkLayer); var runLayer = new AnimationLayer(); runLayer.EveryFrameAction = () => { if (this.XVelocity != 0 && this.GroundMovement == PlatformerValuesStatic["Running"]) { if (PassonClass.mariobig == true) { return("Running_Big" + DirectionFacing); } return("Running_small" + DirectionFacing); } return(null); }; animationController.Layers.Add(runLayer); var skidLayer = new AnimationLayer(); skidLayer.EveryFrameAction = () => { if (this.XVelocity != 0 && this.HorizontalInput.Value != 0 && Math.Sign(XVelocity) != Math.Sign(this.HorizontalInput.Value)) { if (PassonClass.mariobig == true) { return("Drifting_Big" + DirectionFacing); } return("Drifting_small" + DirectionFacing); } return(null); }; animationController.Layers.Add(skidLayer); var jumpLayer = new AnimationLayer(); jumpLayer.EveryFrameAction = () => { if (this.IsOnGround == false) //&& YVelocity > 0 { if (PassonClass.mariobig == true) { return("Jumping_Big" + DirectionFacing); } return("Jumping_small" + DirectionFacing); } return(null); }; animationController.Layers.Add(jumpLayer); }
public virtual void OnPolygonCutterTimelineSpawn(AnimationLayer ActiveLayer, PolygonCutterTimeline ActivePolygonCutter) { ActiveLayer.ListPolygonCutter.Add(ActivePolygonCutter); }
private void InitLayout() { this.basicOverlay = new Overlay(); this.Children.Add(this.basicOverlay); this.box1 = new Box(Direction.Vertical); this.basicOverlay.Children.Add(this.box1); this.box2 = new Box(Direction.Horizontal); this.box1.Children.Add(this.box2); this.playerSlot3 = new PlayerSlotWidget(this); this.box2.Children.Add(this.playerSlot3); this.playerSlot4 = new PlayerSlotWidget(this); this.box2.Children.Add(this.playerSlot4); this.playerSlot5 = new PlayerSlotWidget(this); this.box2.Children.Add(this.playerSlot5); this.box3 = new Box(Direction.Horizontal); this.box1.Children.Add(this.box3); this.playerSlot2 = new PlayerSlotWidget(this); this.box3.Children.Add(this.playerSlot2); this.mainTable = new MainTableWidget(this); this.box3.Children.Add(this.mainTable); this.playerSlot6 = new PlayerSlotWidget(this); this.box3.Children.Add(this.playerSlot6); this.box4 = new Box(Direction.Horizontal); this.box1.Children.Add(this.box4); this.playerSlot1 = new PlayerSlotWidget(this); this.box4.Children.Add(this.playerSlot1); this.playerSlot0 = new PlayerSlotWidget(this, true); this.box4.Children.Add(this.playerSlot0); this.playerSlot7 = new PlayerSlotWidget(this); this.box4.Children.Add(this.playerSlot7); this.box5 = new Box(Direction.Horizontal); this.box1.Children.Add(this.box5); this.requestLabel = new Label(); this.requestLabel.Font = Pango.FontDescription.FromString("Sans Serif"); this.requestLabel.HorizAlignment = Alignment.Center; //this.requestLabel.OutlineWidth = 0.5; //this.requestLabel.OutlineColor = new Cairo.Color(1.0, 1.0, 1.0); this.box5.Children.Add(this.requestLabel); this.responseLabel = new Label(); this.responseLabel.Font = Pango.FontDescription.FromString("Sans Serif"); this.responseLabel.HorizAlignment = Alignment.Center; //this.responseLabel.OutlineWidth = 0.5; //this.responseLabel.OutlineColor = new Cairo.Color(1.0, 1.0, 1.0); this.box5.Children.Add(this.responseLabel); this.animLayer = new AnimationLayer(this); this.basicOverlay.Children.Add(this.animLayer); }
public static Animation ConvertFromAssimpScene(Ai.Scene aiScene, Ai.Animation aiAnimation, AnimationConverterOptions options) { var animation = new Animation(options.Version); animation.Duration = ConvertTime(aiAnimation.DurationInTicks, aiAnimation.TicksPerSecond); foreach (var aiChannel in aiAnimation.NodeAnimationChannels) { if (AssimpConverterCommon.MeshAttachmentNameRegex.IsMatch(aiChannel.NodeName)) { continue; } var nodeName = AssimpConverterCommon.UnescapeName(aiChannel.NodeName); Ai.Node node = aiScene.RootNode.FindNode(nodeName); if (node == null) { continue; } var controller = new AnimationController(options.Version) { TargetKind = TargetKind.Node, TargetName = nodeName, TargetId = GetTargetIdForNode(aiScene.RootNode, nodeName) }; var layer = new AnimationLayer(options.Version); // NodePRS only for now layer.KeyType = KeyType.NodePRS; // Fetch the unique key frame timings from all position, rotation and scale keys. var aiKeyTimings = aiChannel.PositionKeys .Select(x => x.Time) .Concat(aiChannel.RotationKeys.Select(x => x.Time)) .Concat(aiChannel.ScalingKeys.Select(x => x.Time)) .Distinct() .OrderBy(x => x) .ToList(); // Decompose the local transform of the affected node so we can use them as the base values for our keyframes node.Transform.Decompose(out var nodeBaseScale, out var nodeBaseRotation, out var nodeBaseTranslation); // Keep track of the last position, rotation and scale used to ensure that interpolation works properly var lastPosition = nodeBaseTranslation; var lastRotation = nodeBaseRotation; var lastScale = nodeBaseScale; for (var i = 0; i < aiKeyTimings.Count; i++) { var aiTime = aiKeyTimings[i]; // Start building the keyframe var key = new PRSKey(layer.KeyType) { Position = new Vector3(lastPosition.X, lastPosition.Y, lastPosition.Z), Rotation = new Quaternion(lastRotation.X, lastRotation.Y, lastRotation.Z, lastRotation.W), Scale = new Vector3(lastScale.X, lastScale.Y, lastScale.Z) }; // Fetch the Assimp keys for this time var aiPositionKey = aiChannel.PositionKeys.SingleOrDefault(x => x.Time == aiTime); var aiRotationKey = aiChannel.RotationKeys.SingleOrDefault(x => x.Time == aiTime); var aiScaleKey = aiChannel.ScalingKeys.SingleOrDefault(x => x.Time == aiTime); if (aiPositionKey != default) { key.Position = new Vector3(aiPositionKey.Value.X, aiPositionKey.Value.Y, aiPositionKey.Value.Z); lastPosition = aiPositionKey.Value; } if (aiRotationKey != default) { key.Rotation = new Quaternion(aiRotationKey.Value.X, aiRotationKey.Value.Y, aiRotationKey.Value.Z, aiRotationKey.Value.W); lastRotation = aiRotationKey.Value; } if (aiScaleKey != default) { key.Scale = new Vector3(aiScaleKey.Value.X, aiScaleKey.Value.Y, aiScaleKey.Value.Z); lastScale = aiScaleKey.Value; } key.Time = ConvertTime(aiTime, aiAnimation.TicksPerSecond); layer.Keys.Add(key); } controller.Layers.Add(layer); animation.Controllers.Add(controller); } return(animation); }
public static ModelData CreateModelData( Transform model, List <Vector3> controlPoints, List <RotationPoint> rotationPoints, List <List <Vector3> > detailLoaPoints, int numberOfFrames, int strength) { ModelData modelData = new ModelData(); modelData.numberOfFrames = numberOfFrames; modelData.model = GenerateNode(model); //PrintAllNodes(modelData.model, "-"); List <Vector3> interpolatedPoints = new List <Vector3>(); if (controlPoints.Count > 0) { // TODO: Implement this in c++ side. // TODO: Restore original speed after calculation. Vector3 previous = controlPoints[0]; foreach (Vector3 point in controlPoints) { float distance = Vector3.Distance(previous, point); // Add interpolate points for every step distance. float step = 0.01f; int extraPoints = (int)(distance / step); for (int i = 1; i <= extraPoints; i++) { Vector3 extra = Vector3.Lerp( previous, point, i / (float)extraPoints); interpolatedPoints.Add(extra); modelData.controlPoints.Add(new Vector() { x = extra.x, y = extra.y, z = extra.z }); } //Debug.Log(distance + " " + extraPoints); previous = point; // Add the current point. interpolatedPoints.Add(point); modelData.controlPoints.Add(new Vector() { x = point.x, y = point.y, z = point.z }); } } foreach (List <Vector3> layer in detailLoaPoints) { // Find closest index int index; FindClosestIntersect.Search(controlPoints, layer[layer.Count / 2], out index); AnimationLayer animationLayer = new AnimationLayer() { startFrame = Math.Min(strength, index + 1), numFrames = Math.Max(index - strength, 0) }; foreach (Vector3 point in layer) { animationLayer.layerPoints.Add(new Vector() { x = point.x, y = point.y, z = point.z }); } modelData.animationLayers.Add(animationLayer); } if (rotationPoints != null) { foreach (RotationPoint rotPoint in rotationPoints) { swellanimations.RotationPoint nrp = new swellanimations.RotationPoint() { Rotation = new Vector() { x = rotPoint.rotation.eulerAngles.x, y = rotPoint.rotation.eulerAngles.y, z = rotPoint.rotation.eulerAngles.z } }; //Debug.Log(rotPoint.rotation.eulerAngles.ToString()); int pointIndex = interpolatedPoints.IndexOf(rotPoint.position); int frameIndex = (int)(pointIndex / (float)interpolatedPoints.Count * numberOfFrames); nrp.numFrames = Math.Min(strength, frameIndex + 1); nrp.startFrame = Math.Max(frameIndex - strength, 0); modelData.rotationpoints.Add(nrp); } } return(modelData); }
private static Resource Load(Stream stream, bool leaveOpen, Type type) { if (stream.Length < ResourceFileHeader.SIZE) { throw new InvalidDataException("Stream is too small to be a valid resource file."); } using (var reader = new ResourceReader(stream, leaveOpen)) { var header = reader.ReadFileHeader(); Resource res; switch (header.Type) { case ResourceType.ModelPack: res = new ModelPack(header.Version); break; case ResourceType.ShaderCachePS3: if (type == typeof(Epl)) { res = new Epl(header.Version); } else { res = new ShaderCachePS3(header.Version); } break; case ResourceType.ShaderCachePSP2: res = new ShaderCachePSP2(header.Version); break; case ResourceType.ShaderCachePS4: res = new ShaderCachePS4(header.Version); break; // Custom case ResourceType.TextureMap: res = new TextureMap(header.Version); break; case ResourceType.TextureDictionary: res = new TextureDictionary(header.Version); break; case ResourceType.Texture: res = new Texture(header.Version); break; case ResourceType.ShaderPS3: res = new ShaderPS3(header.Version); break; case ResourceType.ShaderPSP2: res = new ShaderPSP2(header.Version); break; case ResourceType.ShaderPS4: res = new ShaderPS4(header.Version); break; case ResourceType.Model: res = new Model(header.Version); break; case ResourceType.Node: return(Node.ReadRecursive(reader, header.Version)); case ResourceType.UserPropertyDictionary: res = new UserPropertyDictionary(header.Version); break; case ResourceType.Morph: res = new Morph(header.Version); break; case ResourceType.MorphTarget: res = new MorphTarget(header.Version); break; case ResourceType.MorphTargetList: res = new MorphTargetList(header.Version); break; case ResourceType.MaterialDictionary: res = new MaterialDictionary(header.Version); break; case ResourceType.ChunkType000100F9: res = new ChunkType000100F9(header.Version); break; case ResourceType.ChunkType000100F8: return(new ChunkType000100F8(header.Version) { Data = reader.ReadBytes(reader.ReadInt32()) }); case ResourceType.AnimationPack: res = new AnimationPack(header.Version); break; case ResourceType.MaterialAttribute: return(MaterialAttribute.Read(reader, header.Version)); case ResourceType.Material: res = new Material(header.Version); break; case ResourceType.Light: res = new Light(header.Version); break; case ResourceType.Mesh: res = new Mesh(header.Version); break; case ResourceType.Camera: res = new Camera(header.Version); break; case ResourceType.Epl: { res = new Epl(header.Version); break; } case ResourceType.EplLeaf: res = new EplLeaf(header.Version); break; case ResourceType.Animation: res = new Animation(header.Version); break; case ResourceType.AnimationBit29Data: res = new AnimationBit29Data(header.Version); break; case ResourceType.AnimationLayer: res = new AnimationLayer(header.Version); break; case ResourceType.AnimationController: res = new AnimationController(header.Version); break; default: throw new InvalidDataException("Unknown/Invalid resource type"); } res.ReadCore(reader); if (res.ResourceType == ResourceType.ModelPack && type == typeof(AnimationPack)) { // Identify AnimationPack from a file with a model resource header var model = ( ModelPack )res; if (model.AnimationPack != null && model.ChunkType000100F8 == null && model.ChunkType000100F9 == null && model.Materials == null && model.Model == null && model.Textures == null) { res = model.AnimationPack; } } return(res); } }
private void InitMarkers(AnimationLayer ActiveLayer, Squad AttackingSquad, Squad EnemySquad) { Unit ActiveUnit = AttackingSquad.CurrentLeader; Unit EnemyUnit = EnemySquad.CurrentLeader; foreach (List <Timeline> ListActiveEvent in ActiveLayer.DicTimelineEvent.Values) { foreach (Timeline ActiveTimeline in ListActiveEvent) { MarkerTimeline ActiveMarkerEvent = ActiveTimeline as MarkerTimeline; if (ActiveMarkerEvent == null) { continue; } string AnimationPath; switch (ActiveMarkerEvent.MarkerType) { case "Support Stand": case "Support Standing": case "Enemy Standing": case "Enemy Stand": case "Enemy Default": ActiveMarkerEvent.AnimationMarker = new AnimationClass(EnemyUnit.Animations.Default.AnimationName); ActiveMarkerEvent.AnimationMarker.DicTimeline = DicTimeline; ActiveMarkerEvent.AnimationMarker.Load(); for (int L = ActiveMarkerEvent.AnimationMarker.ListAnimationLayer.Count - 1; L >= 0; --L) { InitMarkers(ActiveMarkerEvent.AnimationMarker.ListAnimationLayer[L], EnemySquad, AttackingSquad); } break; case "Enemy Wingman A Standing": case "Enemy Wingman 1 Standing": if (EnemySquad.CurrentWingmanA != null) { ActiveMarkerEvent.AnimationMarker = new AnimationClass(EnemySquad.CurrentWingmanA.Animations.Default.AnimationName); ActiveMarkerEvent.AnimationMarker.DicTimeline = DicTimeline; ActiveMarkerEvent.AnimationMarker.Load(); for (int L = ActiveMarkerEvent.AnimationMarker.ListAnimationLayer.Count - 1; L >= 0; --L) { InitMarkers(ActiveMarkerEvent.AnimationMarker.ListAnimationLayer[L], EnemySquad, AttackingSquad); } } break; case "Enemy Wingman B Standing": case "Enemy Wingman 2 Standing": if (EnemySquad.CurrentWingmanB != null) { ActiveMarkerEvent.AnimationMarker = new AnimationClass(EnemySquad.CurrentWingmanB.Animations.Default.AnimationName); ActiveMarkerEvent.AnimationMarker.DicTimeline = DicTimeline; ActiveMarkerEvent.AnimationMarker.Load(); for (int L = ActiveMarkerEvent.AnimationMarker.ListAnimationLayer.Count - 1; L >= 0; --L) { InitMarkers(ActiveMarkerEvent.AnimationMarker.ListAnimationLayer[L], EnemySquad, AttackingSquad); } } break; case "Enemy Hit": if (BattleResult.ArrayResult[0].AttackMissed) { AnimationPath = EnemyUnit.Animations.Default.AnimationName; } else { AnimationPath = EnemyUnit.Animations.Hit.AnimationName; } if (File.Exists("Content/Animations/" + AnimationPath + ".pea")) { ActiveMarkerEvent.AnimationMarker = new AnimationClass(AnimationPath); } else { ActiveMarkerEvent.AnimationMarker = new AnimationClass(EnemyUnit.Animations.Default.AnimationName); } ActiveMarkerEvent.AnimationMarker.DicTimeline = DicTimeline; ActiveMarkerEvent.AnimationMarker.Load(); for (int L = ActiveMarkerEvent.AnimationMarker.ListAnimationLayer.Count - 1; L >= 0; --L) { InitMarkers(ActiveMarkerEvent.AnimationMarker.ListAnimationLayer[L], EnemySquad, AttackingSquad); } break; case "Player Stand": case "Player Standing": case "Player Default": ActiveMarkerEvent.AnimationMarker = new AnimationClass(ActiveUnit.Animations.Default.AnimationName); ActiveMarkerEvent.AnimationMarker.DicTimeline = DicTimeline; ActiveMarkerEvent.AnimationMarker.Load(); for (int L = ActiveMarkerEvent.AnimationMarker.ListAnimationLayer.Count - 1; L >= 0; --L) { InitMarkers(ActiveMarkerEvent.AnimationMarker.ListAnimationLayer[L], AttackingSquad, EnemySquad); } break; default: AnimationPath = EnemyUnit.Animations.Default.AnimationName; if (ActiveMarkerEvent.MarkerType.StartsWith("Player ")) { AnimationPath = ActiveMarkerEvent.MarkerType.Split(new string[] { "Player " }, StringSplitOptions.RemoveEmptyEntries)[0]; } ActiveMarkerEvent.AnimationMarker = new AnimationClass(AnimationPath); ActiveMarkerEvent.AnimationMarker.DicTimeline = DicTimeline; ActiveMarkerEvent.AnimationMarker.Load(); for (int L = ActiveMarkerEvent.AnimationMarker.ListAnimationLayer.Count - 1; L >= 0; --L) { InitMarkers(ActiveMarkerEvent.AnimationMarker.ListAnimationLayer[L], AttackingSquad, EnemySquad); } break; } } } }