public SsInterpolatable Interpolate(SsCurveParams curve, float time, SsInterpolatable start_, SsInterpolatable end_, int startTime, int endTime) { var start = (SsPoint)start_; var end = (SsPoint)end_; X = SsInterpolation.Interpolate(curve, time, start.X, end.X, startTime, endTime); Y = SsInterpolation.Interpolate(curve, time, start.Y, end.Y, startTime, endTime); return(this); }
public SsInterpolatable Interpolate(SsCurveParams curve, float time, SsInterpolatable start_, SsInterpolatable end_, int startTime, int endTime) { var start = (SsPaletteKeyValue)start_; var end = (SsPaletteKeyValue)end_; Use = SsInterpolation.Interpolate(curve, time, start.Use ? 1f : 0f, end.Use ? 1f : 0f, startTime, endTime) >= 0.5f ? true : false; Page = SsInterpolation.Interpolate(curve, time, start.Page, end.Page, startTime, endTime); Block = (byte)SsInterpolation.Interpolate(curve, time, start.Block, end.Block, startTime, endTime); return(this); }
public SsInterpolatable Interpolate(SsCurveParams curve, float time, SsInterpolatable start_, SsInterpolatable end_, int startTime, int endTime) { var start = (SsColorRef)start_; var end = (SsColorRef)end_; R = (byte)SsInterpolation.Interpolate(curve, time, start.R, end.R, startTime, endTime); G = (byte)SsInterpolation.Interpolate(curve, time, start.G, end.G, startTime, endTime); B = (byte)SsInterpolation.Interpolate(curve, time, start.B, end.B, startTime, endTime); A = (byte)SsInterpolation.Interpolate(curve, time, start.A, end.A, startTime, endTime); return(this); }
public SsInterpolatable Interpolate(SsCurveParams curve, float time, SsInterpolatable start_, SsInterpolatable end_, int startTime, int endTime) { var start = (SsRect)start_; var end = (SsRect)end_; Left = SsInterpolation.Interpolate(curve, time, start.Left, end.Left, startTime, endTime); Top = SsInterpolation.Interpolate(curve, time, start.Top, end.Top, startTime, endTime); Right = SsInterpolation.Interpolate(curve, time, start.Right, end.Right, startTime, endTime); Bottom = SsInterpolation.Interpolate(curve, time, start.Bottom, end.Bottom, startTime, endTime); return(this); }
public SsInterpolatable Interpolate(SsCurveParams curve, float time, SsInterpolatable start_, SsInterpolatable end_, int startTime, int endTime) { var start = (SsVertexKeyValue)start_; var end = (SsVertexKeyValue)end_; // use curve params as blend ratio between start key and end key. float rate = SsInterpolation.Interpolate(curve, time, 0.0f, 1.0f, startTime, endTime); // lerp value from start to end. SsCurveParams linearCurve = new SsCurveParams(); linearCurve.Type = SsInterpolationType.Linear; for (int i = 0; i < Vertices.Length; ++i) { Vertices[i].Interpolate(linearCurve, rate, start.Vertices[i], end.Vertices[i], startTime, endTime); } return(this); }
GetBlendedColor(SsColorRef src, SsColorBlendOperation op) { Color c = (Color)src; if (op == SsColorBlendOperation.Mul) { // to decrease vertex color's effect, must come near color value to 1 #if false // lerp with C# c.r = SsInterpolation.Linear(1f - c.a, c.r, 1f); c.g = SsInterpolation.Linear(1f - c.a, c.g, 1f); c.b = SsInterpolation.Linear(1f - c.a, c.b, 1f); // shader: combine texture * primary, texture #else // lerp with shader // shader is like this: // combine primary lerp (primary) constant=(1,1,1,1), texture // combine previous * texture, texture #endif } return(c); }
CreateAttrValues(int frameNum) { if (frameNum <= 0) { Debug.LogWarning("No keys to precalculate."); return; } FrameNum = frameNum; // if (keyFrameLists == null) // { // Debug.LogError("Key frame list must be prepared."); // return; // } #if _DEBUG SsDebugLog.PrintLn("CreateAttrValues()"); SsDebugLog.PrintLn("Name: " + Name); #endif // create temporary key frame list // keyFrameLists = new List<SsKeyFrameInterface>[(int)SsKeyAttr.Num]; // keyFrameLists[(int)SsKeyAttr.PosX] = PosXKeys; // create attribute value lists for (int attrIdx = 0; attrIdx < (int)SsKeyAttr.Num; ++attrIdx) { SsKeyAttr attr = (SsKeyAttr)attrIdx; int keyNum = GetKeyNumOf(attr); // skip non-key attribute if (keyNum <= 0) { continue; } int curKeyIndex = 0; SsKeyFrameInterface curKey = GetKey(attr, 0); int nextKeyIndex = 0; SsKeyFrameInterface nextKey = null; int valuesNum = 1; if (keyNum > 1) { nextKey = GetKey(attr, 1); nextKeyIndex = 1; // consolidate identical values if possible for (int i = 1; i < keyNum; ++i) { SsKeyFrameInterface key = GetKey(attr, i); if (!key.EqualsValue(curKey)) { // give up consolidating valuesNum = frameNum; break; } } } else if (keyNum == 1) { if (attr == SsKeyAttr.Hide) { SsBoolKeyFrame hideKey = (SsBoolKeyFrame)curKey; if (hideKey.Value == false) { valuesNum = frameNum; } } } SsKeyAttrDesc attrDesc = SsKeyAttrDescManager.GetById(attr); switch (attr) { case SsKeyAttr.PosX: PosXValues = new SsIntAttrValue[valuesNum]; break; case SsKeyAttr.PosY: PosYValues = new SsIntAttrValue[valuesNum]; break; case SsKeyAttr.Angle: AngleValues = new SsFloatAttrValue[valuesNum]; break; case SsKeyAttr.ScaleX: ScaleXValues = new SsFloatAttrValue[valuesNum]; break; case SsKeyAttr.ScaleY: ScaleYValues = new SsFloatAttrValue[valuesNum]; break; case SsKeyAttr.Trans: TransValues = new SsFloatAttrValue[valuesNum]; break; case SsKeyAttr.Prio: PrioValues = new SsIntAttrValue[valuesNum]; break; case SsKeyAttr.FlipH: FlipHValues = new SsBoolAttrValue[valuesNum]; break; case SsKeyAttr.FlipV: FlipVValues = new SsBoolAttrValue[valuesNum]; break; case SsKeyAttr.Hide: HideValues = new SsBoolAttrValue[valuesNum]; break; case SsKeyAttr.PartsCol: PartsColValues = new SsColorBlendAttrValue[valuesNum]; break; case SsKeyAttr.PartsPal: PartsPalValues = new SsPaletteAttrValue[valuesNum]; break; case SsKeyAttr.Vertex: VertexValues = new SsVertexAttrValue[valuesNum]; break; case SsKeyAttr.User: UserValues = new SsUserDataAttrValue[valuesNum]; break; case SsKeyAttr.Sound: SoundValues = new SsSoundAttrValue[valuesNum]; break; case SsKeyAttr.ImageOffsetX: ImageOffsetXValues = new SsIntAttrValue[valuesNum]; break; case SsKeyAttr.ImageOffsetY: ImageOffsetYValues = new SsIntAttrValue[valuesNum]; break; case SsKeyAttr.ImageOffsetW: ImageOffsetWValues = new SsIntAttrValue[valuesNum]; break; case SsKeyAttr.ImageOffsetH: ImageOffsetHValues = new SsIntAttrValue[valuesNum]; break; case SsKeyAttr.OriginOffsetX: OriginOffsetXValues = new SsIntAttrValue[valuesNum]; break; case SsKeyAttr.OriginOffsetY: OriginOffsetYValues = new SsIntAttrValue[valuesNum]; break; } // mark that this attribute is used. _hasAttrFlags |= (SsKeyAttrFlags)(1 << attrIdx); #if _DEBUG SsDebugLog.Print(string.Format("\tAttr[{0}]: {1}\n", attrIdx, attrDesc.Attr)); #endif for (int frame = 0; frame < valuesNum; ++frame) { if (nextKey != null && frame >= nextKey.Time) { // advance to next keyed frame curKeyIndex = nextKeyIndex; curKey = nextKey; ++nextKeyIndex; nextKey = nextKeyIndex < keyNum?GetKey(attr, nextKeyIndex) : null; } // base typed value SsAttrValue v = null; // create new value to add SsBoolAttrValue boolValue = null; SsIntAttrValue intValue = null; SsFloatAttrValue floatValue = null; // SsPointAttrValue pointValue = null; SsPaletteAttrValue paletteValue = null; SsColorBlendAttrValue colorBlendValue = null; SsVertexAttrValue vertexValue = null; SsUserDataAttrValue userValue = null; SsSoundAttrValue soundValue = null; switch (attrDesc.ValueType) { case SsKeyValueType.Data: ///< actually decimal or integer switch (attrDesc.CastType) { default: v = intValue = new SsIntAttrValue(); break; case SsKeyCastType.Float: case SsKeyCastType.Degree: v = floatValue = new SsFloatAttrValue(); break; } break; case SsKeyValueType.Param: ///< actually boolean v = boolValue = new SsBoolAttrValue(); break; // case SsKeyValueType.Point: ///< x,y // v = pointValue = new SsPointAttrValue(); // break; case SsKeyValueType.Palette: ///< left,top,right,bottom v = paletteValue = new SsPaletteAttrValue(); break; case SsKeyValueType.Color: ///< single or vertex colors v = colorBlendValue = new SsColorBlendAttrValue(); break; case SsKeyValueType.Vertex: ///< vertex positions relative to origin v = vertexValue = new SsVertexAttrValue(); break; case SsKeyValueType.User: ///< user defined data(numeric|point|rect|string...) v = userValue = new SsUserDataAttrValue(); break; case SsKeyValueType.Sound: ///< sound id, volume, note on... v = soundValue = new SsSoundAttrValue(); break; } #if false // move this care to runtime if (attrDesc.Attr == SsKeyAttr.Hide && frame < curKey.Time) { // "hide" needs special care, it will be true before first key. boolValue.Value = true; } else #endif if (attrDesc.NeedsInterpolatable && nextKey != null && frame >= curKey.Time) { bool doInterpolate = true; if (attrDesc.Attr == SsKeyAttr.PartsCol) { var curCbk = (SsColorBlendKeyValue)curKey.ObjectValue; var nextCbk = (SsColorBlendKeyValue)nextKey.ObjectValue; // if current and next key has no target, new value simply refers current key. if (curCbk.Target == SsColorBlendTarget.None && nextCbk.Target == SsColorBlendTarget.None) { v.RefKeyIndex = curKeyIndex; doInterpolate = false; } } if (doInterpolate) { // needs interpolation object res; if (frame == curKey.Time) { // use start key value as is. res = curKey.ObjectValue; } else { // interpolate curKey~nextKey res = SsInterpolation.InterpolateKeyValue(curKey, nextKey, frame); } try{ // can't restore primitive type from the boxed through casting. if (boolValue) { boolValue.Value = System.Convert.ToBoolean(res); } else if (intValue) { intValue.Value = System.Convert.ToInt32(res); } else if (floatValue) { floatValue.Value = System.Convert.ToSingle(res); } else { v.SetValue(res); } }catch { Debug.LogError("[INTERNAL] failed to unbox: " + res); } if (attrDesc.Attr == SsKeyAttr.PartsCol) { var curCbk = (SsColorBlendKeyValue)curKey.ObjectValue; var nextCbk = (SsColorBlendKeyValue)nextKey.ObjectValue; // if current or next key has vertex colors, key between them should have vertex colors. if (curCbk.Target == SsColorBlendTarget.Vertex || nextCbk.Target == SsColorBlendTarget.Vertex) { var newCbk = colorBlendValue.Value; newCbk.Target = SsColorBlendTarget.Vertex; // use next key operation. newCbk.Operation = nextCbk.Operation; } } } } else { // just use the value at last referred key frame. v.RefKeyIndex = curKeyIndex; } #if _DEBUG if (v.Value != null) { SsDebugLog.Print(string.Format("\t\tframe[{0}]: {1}\n", frame, v.Value)); } #endif // add value to the relative array switch (attr) { case SsKeyAttr.PosX: PosXValues[frame] = intValue; break; case SsKeyAttr.PosY: PosYValues[frame] = intValue; break; case SsKeyAttr.Angle: AngleValues[frame] = floatValue; break; case SsKeyAttr.ScaleX: ScaleXValues[frame] = floatValue; break; case SsKeyAttr.ScaleY: ScaleYValues[frame] = floatValue; break; case SsKeyAttr.Trans: TransValues[frame] = floatValue; break; case SsKeyAttr.Prio: PrioValues[frame] = intValue; break; case SsKeyAttr.FlipH: FlipHValues[frame] = boolValue; break; case SsKeyAttr.FlipV: FlipVValues[frame] = boolValue; break; case SsKeyAttr.Hide: HideValues[frame] = boolValue; break; case SsKeyAttr.PartsCol: PartsColValues[frame] = colorBlendValue; break; case SsKeyAttr.PartsPal: PartsPalValues[frame] = paletteValue; break; case SsKeyAttr.Vertex: VertexValues[frame] = vertexValue; break; case SsKeyAttr.User: UserValues[frame] = userValue; break; case SsKeyAttr.Sound: SoundValues[frame] = soundValue; break; case SsKeyAttr.ImageOffsetX: ImageOffsetXValues[frame] = intValue; break; case SsKeyAttr.ImageOffsetY: ImageOffsetYValues[frame] = intValue; break; case SsKeyAttr.ImageOffsetW: ImageOffsetWValues[frame] = intValue; break; case SsKeyAttr.ImageOffsetH: ImageOffsetHValues[frame] = intValue; break; case SsKeyAttr.OriginOffsetX: OriginOffsetXValues[frame] = intValue; break; case SsKeyAttr.OriginOffsetY: OriginOffsetYValues[frame] = intValue; break; } } } // set having transparency flag HasTrancparency = false; if (HasAttrFlags(SsKeyAttrFlags.Trans)) { // if opacity value under 1 exists in some keys, we recognize this will be transparent at some frames foreach (SsFloatKeyFrame e in TransKeys) { if (e.Value < 1f) { HasTrancparency = true; break; } } } }