/** * @inheritDoc */ //private Vector3 vector = new Vector3 (); //private float angle; public void UpdateTransform(Com.Viperstudio.Geom.Matrix matrix, DBTransform transform) { if (_display != null) { (_display as UnityBoneDisplay).Update(matrix); } }
public void FadeIn(Bone bone, AnimationState animationState, TransformTimeline timeline) { _bone = bone; _animationState = animationState; _timeline = timeline; _originTransform = _timeline.OriginTransform; _originPivot = _timeline.OriginPivot; //_originTransform.copy(_timeline.originTransform); /* * var bLRX:Number = _bone.origin.skewX + _bone.offset.skewX + _bone._tween.skewX; * var bLRY:Number = _bone.origin.skewY + _bone.offset.skewY + _bone._tween.skewY; * * _originTransform.skewX = bLRX + TransformUtils.formatRadian(_originTransform.skewX - bLRX); * _originTransform.skewY = bLRY + TransformUtils.formatRadian(_originTransform.skewY - bLRY); */ _tweenTransform = false; _tweenColor = false; _totalTime = _animationState.TotalTime; Transform.X = 0; Transform.Y = 0; Transform.ScaleX = 0; Transform.ScaleY = 0; Transform.SkewX = 0; Transform.SkewY = 0; Pivot.X = 0; Pivot.Y = 0; _durationTransform.X = 0; _durationTransform.Y = 0; _durationTransform.ScaleX = 0; _durationTransform.ScaleY = 0; _durationTransform.SkewX = 0; _durationTransform.SkewY = 0; _durationPivot.X = 0; _durationPivot.Y = 0; _currentFrame = null; switch (_timeline.FrameList.Count) { case 0: _bone.arriveAtFrame(null, this, _animationState, false); _updateState = 0; break; case 1: _updateState = -1; break; default: _updateState = 1; break; } }
public static void TransformToMatrix(DBTransform transform, Com.Viperstudio.Geom.Matrix matrix) { matrix.A = transform.ScaleX * (float)Math.Cos(transform.SkewY); matrix.B = transform.ScaleX * (float)Math.Sin(transform.SkewY); matrix.C = -transform.ScaleY * (float)Math.Sin(transform.SkewX); matrix.D = transform.ScaleY * (float)Math.Cos(transform.SkewX); matrix.Tx = transform.X; matrix.Ty = transform.Y; }
private void clearVaribles() { _updateState = 0; _bone = null; _animationState = null; _timeline = null; _currentFrame = null; _originTransform = null; _originPivot = null; }
/** * Cleans up any resources used by this DBObject instance. */ public virtual void Dispose() { UserData = null; _parent = null; _armature = null; _global = null; _origin = null; _offset = null; _tween = null; _globalTransformMatrix = null; }
public TimelineState() { Transform = new DBTransform(); Pivot = new Point(); //_originTransform = new DBTransform(); _durationTransform = new DBTransform(); _durationPivot = new Point(); _durationColor = new ColorTransform(); }
public DBObject() { _global = new DBTransform(); _origin = new DBTransform(); _offset = new DBTransform(); _tween = new DBTransform(); _tween.ScaleX = _tween.ScaleY = 0; _globalTransformMatrix = new Com.Viperstudio.Geom.Matrix(); _visible = true; }
public static void TransformPointWithParent(DBTransform transform, DBTransform parent) { TransformToMatrix(parent, _helpMatrix); _helpMatrix.Invert(); float x = transform.X; float y = transform.Y; transform.X = _helpMatrix.A * x + _helpMatrix.C * y + _helpMatrix.Tx; transform.Y = _helpMatrix.D * y + _helpMatrix.B * x + _helpMatrix.Ty; transform.SkewX = FormatRadian(transform.SkewX - parent.SkewX); transform.SkewY = FormatRadian(transform.SkewY - parent.SkewY); }
public static void GetTimelineTransform(TransformTimeline timeline, float position, DBTransform retult) { List <Frame> frameList = timeline.FrameList; int i = frameList.Count; TransformFrame currentFrame; float tweenEasing; float progress; TransformFrame nextFrame; while (i-- > 0) { currentFrame = frameList[i] as TransformFrame; if (currentFrame.Position <= position && currentFrame.Position + currentFrame.Duration > position) { tweenEasing = currentFrame.TweenEasing; if (i == frameList.Count - 1 || float.IsNaN(tweenEasing) || position == currentFrame.Position) { retult.Copy(currentFrame.Global); } else { progress = (position - currentFrame.Position) / currentFrame.Duration; if (tweenEasing != 0 && !float.IsNaN(tweenEasing)) { progress = TimelineState.GetEaseValue(progress, tweenEasing); } nextFrame = frameList[i + 1] as TransformFrame; retult.X = currentFrame.Global.X + (nextFrame.Global.X - currentFrame.Global.X) * progress; retult.Y = currentFrame.Global.Y + (nextFrame.Global.Y - currentFrame.Global.Y) * progress; retult.SkewX = TransformUtil.FormatRadian(currentFrame.Global.SkewX + (nextFrame.Global.SkewX - currentFrame.Global.SkewX) * progress); retult.SkewY = TransformUtil.FormatRadian(currentFrame.Global.SkewY + (nextFrame.Global.SkewY - currentFrame.Global.SkewY) * progress); retult.ScaleX = currentFrame.Global.ScaleX + (nextFrame.Global.ScaleX - currentFrame.Global.ScaleX) * progress; retult.ScaleY = currentFrame.Global.ScaleY + (nextFrame.Global.ScaleY - currentFrame.Global.ScaleY) * progress; } break; } } }
public void Update(float progress) { if (_updateState != 0) { if (_updateState > 0) { if (_timeline.Scale == 0f) { progress = 1f; } else { progress /= _timeline.Scale; } if (progress == 1f) { progress = 0.99999999f; } progress += _timeline.Offset; int loopCount = (int)progress; progress -= loopCount; // float playedTime = _totalTime * progress; bool isArrivedFrame = false; int frameIndex = 0; while (_currentFrame == null || playedTime > _currentFramePosition + _currentFrameDuration || playedTime < _currentFramePosition) { //Logger.Log ("updating " + playedTime); if (isArrivedFrame) { _bone.arriveAtFrame(_currentFrame, this, _animationState, true); } isArrivedFrame = true; if (_currentFrame != null) { //Logger.Log ("updating " + _timeline.Duration +" " + _currentFrame.Position + " " + _currentFrame.Duration); frameIndex = _timeline.FrameList.IndexOf(_currentFrame) + 1; if (frameIndex >= _timeline.FrameList.Count) { frameIndex = 0; } _currentFrame = _timeline.FrameList[frameIndex] as TransformFrame; } else { frameIndex = 0; _currentFrame = _timeline.FrameList[0] as TransformFrame; } _currentFrameDuration = _currentFrame.Duration; _currentFramePosition = _currentFrame.Position; //Logger.Log(playedTime + " " + _currentFramePosition + " " + ( _currentFrameDuration + _currentFramePosition)); } if (isArrivedFrame) { TweenActive = _currentFrame.DisplayIndex >= 0; frameIndex++; if (frameIndex >= _timeline.FrameList.Count) { frameIndex = 0; } TransformFrame nextFrame = _timeline.FrameList[frameIndex] as TransformFrame; if ( frameIndex == 0 && _animationState.Loop != 0 && _animationState.LoopCount >= Math.Abs(_animationState.Loop) - 1 && ((_currentFramePosition + _currentFrameDuration) / _totalTime + loopCount - _timeline.Offset) * _timeline.Scale > 0.99999999 ) { _updateState = 0; _tweenEasing = float.NaN; } else if (_currentFrame.DisplayIndex < 0 || nextFrame.DisplayIndex < 0 || !_animationState.TweenEnabled) { _tweenEasing = float.NaN; } else if (float.IsNaN(_animationState.Clip.TweenEasing)) { _tweenEasing = _currentFrame.TweenEasing; } else { _tweenEasing = _animationState.Clip.TweenEasing; } if (float.IsNaN(_tweenEasing)) { _tweenTransform = false; _tweenColor = false; } else { _durationTransform.X = nextFrame.Transform.X - _currentFrame.Transform.X; _durationTransform.Y = nextFrame.Transform.Y - _currentFrame.Transform.Y; _durationTransform.SkewX = nextFrame.Transform.SkewX - _currentFrame.Transform.SkewX; _durationTransform.SkewY = nextFrame.Transform.SkewY - _currentFrame.Transform.SkewY; _durationTransform.ScaleX = nextFrame.Transform.ScaleX - _currentFrame.Transform.ScaleX; _durationTransform.ScaleY = nextFrame.Transform.ScaleY - _currentFrame.Transform.ScaleY; if (frameIndex == 0) { _durationTransform.SkewX = TransformUtil.FormatRadian(_durationTransform.SkewX); _durationTransform.SkewY = TransformUtil.FormatRadian(_durationTransform.SkewY); } _durationPivot.X = nextFrame.Pivot.X - _currentFrame.Pivot.X; _durationPivot.Y = nextFrame.Pivot.Y - _currentFrame.Pivot.Y; if ( _durationTransform.X != 0 || _durationTransform.Y != 0 || _durationTransform.SkewX != 0 || _durationTransform.SkewY != 0 || _durationTransform.ScaleX != 0 || _durationTransform.ScaleY != 0 || _durationPivot.X != 0 || _durationPivot.Y != 0 ) { _tweenTransform = true; } else { _tweenTransform = false; } if (_currentFrame.Color != null && nextFrame.Color != null) { _durationColor.AlphaOffset = nextFrame.Color.AlphaOffset - _currentFrame.Color.AlphaOffset; _durationColor.RedOffset = nextFrame.Color.RedOffset - _currentFrame.Color.RedOffset; _durationColor.GreenOffset = nextFrame.Color.GreenOffset - _currentFrame.Color.GreenOffset; _durationColor.BlueOffset = nextFrame.Color.BlueOffset - _currentFrame.Color.BlueOffset; _durationColor.AlphaMultiplier = nextFrame.Color.AlphaMultiplier - _currentFrame.Color.AlphaMultiplier; _durationColor.RedMultiplier = nextFrame.Color.RedMultiplier - _currentFrame.Color.RedMultiplier; _durationColor.GreenMultiplier = nextFrame.Color.GreenMultiplier - _currentFrame.Color.GreenMultiplier; _durationColor.BlueMultiplier = nextFrame.Color.BlueMultiplier - _currentFrame.Color.BlueMultiplier; if ( _durationColor.AlphaOffset != 0 || _durationColor.RedOffset != 0 || _durationColor.GreenOffset != 0 || _durationColor.BlueOffset != 0 || _durationColor.AlphaMultiplier != 0 || _durationColor.RedMultiplier != 0 || _durationColor.GreenMultiplier != 0 || _durationColor.BlueMultiplier != 0 ) { _tweenColor = true; } else { _tweenColor = false; } } else if (_currentFrame.Color != null) { _tweenColor = true; _durationColor.AlphaOffset = -_currentFrame.Color.AlphaOffset; _durationColor.RedOffset = -_currentFrame.Color.RedOffset; _durationColor.GreenOffset = -_currentFrame.Color.GreenOffset; _durationColor.BlueOffset = -_currentFrame.Color.BlueOffset; _durationColor.AlphaMultiplier = 1 - _currentFrame.Color.AlphaMultiplier; _durationColor.RedMultiplier = 1 - _currentFrame.Color.RedMultiplier; _durationColor.GreenMultiplier = 1 - _currentFrame.Color.GreenMultiplier; _durationColor.BlueMultiplier = 1 - _currentFrame.Color.BlueMultiplier; } else if (nextFrame.Color != null) { _tweenColor = true; _durationColor.AlphaOffset = nextFrame.Color.AlphaOffset; _durationColor.RedOffset = nextFrame.Color.RedOffset; _durationColor.GreenOffset = nextFrame.Color.GreenOffset; _durationColor.BlueOffset = nextFrame.Color.BlueOffset; _durationColor.AlphaMultiplier = nextFrame.Color.AlphaMultiplier - 1; _durationColor.RedMultiplier = nextFrame.Color.RedMultiplier - 1; _durationColor.GreenMultiplier = nextFrame.Color.GreenMultiplier - 1; _durationColor.BlueMultiplier = nextFrame.Color.BlueMultiplier - 1; } else { _tweenColor = false; } } if (!_tweenTransform) { if (_animationState.Blend) { Transform.X = _originTransform.X + _currentFrame.Transform.X; Transform.Y = _originTransform.Y + _currentFrame.Transform.Y; Transform.SkewX = _originTransform.SkewX + _currentFrame.Transform.SkewX; Transform.SkewY = _originTransform.SkewY + _currentFrame.Transform.SkewY; Transform.ScaleX = _originTransform.ScaleX + _currentFrame.Transform.ScaleX; Transform.ScaleY = _originTransform.ScaleY + _currentFrame.Transform.ScaleY; Pivot.X = _originPivot.X + _currentFrame.Pivot.X; Pivot.Y = _originPivot.Y + _currentFrame.Pivot.Y; } else { Transform.X = _currentFrame.Transform.X; Transform.Y = _currentFrame.Transform.Y; Transform.SkewX = _currentFrame.Transform.SkewX; Transform.SkewY = _currentFrame.Transform.SkewY; Transform.ScaleX = _currentFrame.Transform.ScaleX; Transform.ScaleY = _currentFrame.Transform.ScaleY; Pivot.X = _currentFrame.Pivot.X; Pivot.Y = _currentFrame.Pivot.Y; } } if (!_tweenColor) { if (_currentFrame.Color != null) { _bone.updateColor( _currentFrame.Color.AlphaOffset, _currentFrame.Color.RedOffset, _currentFrame.Color.GreenOffset, _currentFrame.Color.BlueOffset, _currentFrame.Color.AlphaMultiplier, _currentFrame.Color.RedMultiplier, _currentFrame.Color.GreenMultiplier, _currentFrame.Color.BlueMultiplier, true ); } else if (_bone._isColorChanged) { _bone.updateColor(0, 0, 0, 0, 1, 1, 1, 1, false); } } _bone.arriveAtFrame(_currentFrame, this, _animationState, false); } if (_tweenTransform || _tweenColor) { progress = (playedTime - _currentFramePosition) / _currentFrameDuration; if (_tweenEasing != float.NaN && _tweenEasing != 0) { progress = GetEaseValue(progress, _tweenEasing); } } if (_tweenTransform) { DBTransform currentTransform = _currentFrame.Transform; Point currentPivot = _currentFrame.Pivot; if (_animationState.Blend) { Transform.X = _originTransform.X + currentTransform.X + _durationTransform.X * progress; Transform.Y = _originTransform.Y + currentTransform.Y + _durationTransform.Y * progress; Transform.SkewX = _originTransform.SkewX + currentTransform.SkewX + _durationTransform.SkewX * progress; Transform.SkewY = _originTransform.SkewY + currentTransform.SkewY + _durationTransform.SkewY * progress; Transform.ScaleX = _originTransform.ScaleX + currentTransform.ScaleX + _durationTransform.ScaleX * progress; Transform.ScaleY = _originTransform.ScaleY + currentTransform.ScaleY + _durationTransform.ScaleY * progress; Pivot.X = _originPivot.X + currentPivot.X + _durationPivot.X * progress; Pivot.Y = _originPivot.Y + currentPivot.Y + _durationPivot.Y * progress; } else { Transform.X = currentTransform.X + _durationTransform.X * progress; Transform.Y = currentTransform.Y + _durationTransform.Y * progress; Transform.SkewX = currentTransform.SkewX + _durationTransform.SkewX * progress; Transform.SkewY = currentTransform.SkewY + _durationTransform.SkewY * progress; Transform.ScaleX = currentTransform.ScaleX + _durationTransform.ScaleX * progress; Transform.ScaleY = currentTransform.ScaleY + _durationTransform.ScaleY * progress; Pivot.X = currentPivot.X + _durationPivot.X * progress; Pivot.Y = currentPivot.Y + _durationPivot.Y * progress; } } if (_tweenColor) { if (_currentFrame.Color != null) { _bone.updateColor( _currentFrame.Color.AlphaOffset + _durationColor.AlphaOffset * progress, _currentFrame.Color.RedOffset + _durationColor.RedOffset * progress, _currentFrame.Color.GreenOffset + _durationColor.GreenOffset * progress, _currentFrame.Color.BlueOffset + _durationColor.BlueOffset * progress, _currentFrame.Color.AlphaMultiplier + _durationColor.AlphaMultiplier * progress, _currentFrame.Color.RedMultiplier + _durationColor.RedMultiplier * progress, _currentFrame.Color.GreenMultiplier + _durationColor.GreenMultiplier * progress, _currentFrame.Color.BlueMultiplier + _durationColor.BlueMultiplier * progress, true ); } else { _bone.updateColor( _durationColor.AlphaOffset * progress, _durationColor.RedOffset * progress, _durationColor.GreenOffset * progress, _durationColor.BlueOffset * progress, 1 + _durationColor.AlphaMultiplier * progress, 1 + _durationColor.RedMultiplier * progress, 1 + _durationColor.GreenMultiplier * progress, 1 + _durationColor.BlueMultiplier * progress, true ); } } } else { _updateState = 0; if (_animationState.Blend) { Transform.Copy(_originTransform); Pivot.X = _originPivot.X; Pivot.Y = _originPivot.Y; } else { Transform.X = Transform.Y = Transform.SkewX = Transform.SkewY = Transform.ScaleX = Transform.ScaleY = 0; Pivot.X = 0; Pivot.Y = 0; } _currentFrame = _timeline.FrameList[0] as TransformFrame; TweenActive = _currentFrame.DisplayIndex >= 0; if (_currentFrame.Color != null) { _bone.updateColor( _currentFrame.Color.AlphaOffset, _currentFrame.Color.RedOffset, _currentFrame.Color.GreenOffset, _currentFrame.Color.BlueOffset, _currentFrame.Color.AlphaMultiplier, _currentFrame.Color.RedMultiplier, _currentFrame.Color.GreenMultiplier, _currentFrame.Color.BlueMultiplier, true ); } else { _bone.updateColor(0, 0, 0, 0, 1, 1, 1, 1, false); } _bone.arriveAtFrame(_currentFrame, this, _animationState, false); } } }