public static StoryboardObject Create(BinaryReader reader, StringCacheTable cache) { StoryboardObject obj = null; var id = reader.ReadByte(); switch (id) { case 1: obj = new StoryboardAnimation(); break; case 2: obj = new StoryboardBackgroundObject(); //clean default commands because there will be added by binary file. foreach (var cmd in obj.CommandMap.Values.SelectMany(x => x).ToArray()) { obj.RemoveCommand(cmd); } break; default: obj = new StoryboardObject(); break; } obj.OnDeserialize(reader, cache); return(obj); }
public override void Execute(StoryboardObject @object, float current_value) { float relative_time = current_value; if (current_value < StartTime) { relative_time = timeline.StartTime - 1; } else if (current_value > EndTime) { relative_time = timeline.EndTime + 1; } else if (CostTime != 0) { relative_time = (current_value - StartTime) % CostTime; } var command = timeline.PickCommand(relative_time); if (command != null) { command.Execute(@object, relative_time); #if DEBUG @object.MarkCommandExecuted(command); #endif } }
public static void CompareStoryboardObjectTransform(StoryboardObject a, StoryboardObject b) { Assert.AreEqual(a.Color.ToString(), b.Color.ToString()); Assert.AreEqual(a.IsAdditive, b.IsAdditive); Assert.AreEqual(a.IsHorizonFlip, b.IsHorizonFlip); Assert.AreEqual(a.IsVerticalFlip, b.IsVerticalFlip); Assert.AreEqual(a.Rotate.ToString(), b.Rotate.ToString()); Assert.AreEqual(a.Scale.ToString(), b.Scale.ToString()); Assert.AreEqual(a.Postion.ToString(), b.Postion.ToString()); }
public override void Execute(StoryboardObject @object, float time) { if (StartTime == EndTime || (StartTime <= time && time <= EndTime)) { ApplyValue(@object, true); } else { ApplyValue(@object, false); } }
public override void Discard(StoryboardObject storyboardObject) { storyboardObjects.Remove(storyboardObject); if (storyboardObject is DisplayableObject displayableObject) { displayableObjects.Remove(displayableObject); } if (storyboardObject is EventObject eventObject) { eventObjects.Remove(eventObject); } }
public static byte GetObjectTypeId(StoryboardObject obj) { if (obj is StoryboardAnimation) { return(1); } if (obj is StoryboardBackgroundObject) { return(2); } return(0); }
public override void Execute(StoryboardObject @object, float time) { if (Trigged) { //executed,recovery status and reset if (last_trigged_time + CostTime <= time) { Trigged = false; Reset(true); } } }
public static async Task DrawObject(WebGLContext gl, StoryboardObject obj) { if (!textureResourceMap.TryGetValue(obj.ImageFilePath, out var textureResource)) { return; } ChangeAdditiveStatus(gl, obj.IsAdditive); var is_xflip = Math.Sign(obj.Scale.X); var is_yflip = Math.Sign(obj.Scale.Y); //adjust scale transform which value is negative var horizon_flip = obj.IsHorizonFlip | (is_xflip < 0); var vertical_flip = obj.IsHorizonFlip | (is_yflip < 0); float scalex = is_xflip * obj.Scale.X * textureResource.Size.Width; float scaley = is_yflip * obj.Scale.Y * textureResource.Size.Height; await shader.UpdateColor(gl, obj.Color.X, obj.Color.Y, obj.Color.Z, obj.Color.W); await shader.UpdateFlip(gl, horizon_flip? -1 : 1, vertical_flip? -1 : 1); //anchor await shader.UpdateAnchor(gl, obj.OriginOffset.X, obj.OriginOffset.Y); //Create ModelMatrix Matrix3 model = Matrix3.Zero; float cosa = (float)Math.Cos(obj.Rotate); float sina = (float)Math.Sin(obj.Rotate); model.Row0.X = cosa * scalex; model.Row0.Y = -sina * scalex; model.Row1.X = sina * scaley; model.Row1.Y = cosa * scaley; model.Row2.X = obj.Postion.X - SB_WIDTH / 2f; model.Row2.Y = -obj.Postion.Y + SB_HEIGHT / 2f; unsafe { fixed(float *ptr = &martrix3Buffer[0]) { Unsafe.CopyBlock(ptr, &model.Row0.X, 9 * sizeof(float)); } } await shader.UpdateModel(gl, false, martrix3Buffer); await shader.UpdateTexture(gl, textureResource.Texture); await gl.DrawArraysAsync(Primitive.TRIANGLE_FAN, 0, 4); }
public override void Execute(StoryboardObject @object, float current_value) { current_value -= StartTime; var command = timeline.PickCommand(current_value); if (command != null) { command.Execute(@object, current_value); #if DEBUG @object.MarkCommandExecuted(command); #endif } }
private void PickObject(float x, float y) { int last_order_index = Window?.SelectObject?.Z ?? -1; StoryboardObject obj = null; foreach (var temp in StoryboardInstanceManager.ActivityInstance.Updater.UpdatingStoryboardObjects) { if (temp.Z > last_order_index && (obj == null ? true : (temp.Z < obj.Z)) && IsPointInObjectArea(temp, x, y)) { obj = temp; } } Window.SelectObject = obj; }
static void _Main(string[] args) { var simple_commands = new[] { "_M,0,0,5000,0,0,640,480", "_S,0,0,2500,0,1,0", " L,0,10", "__F,0,0,150,0,1", "__F,0,250,400,1,0" }; var commands = simple_commands.Select(line => Parser.CommandParser.CommandParserIntance.Parse(line)).SelectMany(q => q).ToList(); var sub_command = commands.AsEnumerable().Reverse().Take(2); var loop_command = commands.OfType <LoopCommand>().FirstOrDefault(); loop_command.AddSubCommand(sub_command); loop_command.UpdateSubCommand(); commands = commands.Except(sub_command).ToList(); foreach (var c in commands) { Console.WriteLine(c.ToString()); } Console.WriteLine("Start calculate .....\n"); StoryboardObject storyboard_object = new StoryboardObject(); storyboard_object.ImageFilePath = "star.png"; storyboard_object.AddCommandRange(commands); storyboard_object.CalculateAndApplyBaseFrameTime(); for (int time = 0; time < 5000; time += 500) { storyboard_object.Update(time); Console.WriteLine($"Current time:{time} object alpha = {storyboard_object.Color.W} , position = {storyboard_object.Postion} , scale = {storyboard_object.Scale}"); } Console.ReadLine(); }
public static void CompareStoryboardObjects(StoryboardObject a, StoryboardObject b) { a.ResetTransform(); b.ResetTransform(); //选取optimzed范围内的raw物件的命令作为时间参照,否则optimzer时间范围外面的命令/时间,因为有优化器提前对optimzer计算导致对比失败 foreach (var command in b.CommandMap.Values.SelectMany(l => l).Where(x => b.FrameStartTime <= x.StartTime && x.EndTime <= b.FrameEndTime)) { var time = (float)(command.StartTime != command.EndTime ? (command.StartTime + (command.EndTime - command.StartTime) * Math.Max(0.1, rand.NextDouble())) : command.EndTime + 1); Update(time); CompareStoryboardObjectTransform(a, b); } void Update(float t) { a.Update(t); b.Update(t); } CompareStoryboardObjectTransform(a, b); }
public static string GetStoryboardIdentityName(StoryboardObject obj) => $"_{obj.FileLine}_" + string.Join("", obj.ImageFilePath.ToLower().Replace('/', '_').Replace('\\', '_').Replace('.', '_').Where(x => (x >= 'a' && x <= 'z') || (x >= '0' && x <= '9') || x == '_'));
public abstract void ApplyValue(StoryboardObject @object, bool value);
public void Add(StoryboardObject @object) { register_trigger_objects.Add(@object); }
public void Remove(StoryboardObject @object) { register_trigger_objects.Remove(@object); }
private static Property ApplyOriginOffset(StoryboardObject obj, KeyFrames[] key_frames, (int width, int height) size, Selector selector)
public SpriteInstanceGroup GetSprite(StoryboardObject obj) => GetSprite(obj.ImageFilePath);
public void Suggest(StoryboardObject obj, string message) { Suggest($"在line {obj.FileLine}物件\"{obj.ImageFilePath}\"," + message); }
private static void Draw(StoryboardObject obj) { //todo . gugu Console.WriteLine($"draw {obj.ToString()}"); }
/// <summary> /// 钦定触发器绑定的物件,一次性的 /// </summary> /// <param name="obj"></param> public void BindObject(StoryboardObject obj) { Debug.Assert(bind_object == null, "Not allow trigger command bind more Storyboard objects"); bind_object = obj ?? throw new ArgumentNullException(nameof(obj)); }
public abstract void Execute(StoryboardObject @object, float time);
public static (KeyFrames[] keyframes, Selector selector) ConvertStoryboardObject(StoryboardObject obj, string dir_path) { var obj_name = GetStoryboardIdentityName(obj); Selector selector = new Selector($".{obj_name}"); //temp solve obj.AddCommand(new FadeCommand() { EndTime = obj.FrameStartTime, StartTime = 0, StartValue = 0, EndValue = 0 }); obj.AddCommand(new FadeCommand() { EndTime = obj.FrameEndTime + 1, StartTime = obj.FrameEndTime, StartValue = 0, EndValue = 0 }); SetupBaseTransform(selector, obj); var size = SetupWidthHeightProperties(obj, selector, dir_path); var animation_key_frames = obj.CommandMap.Values .Where(x => CanConvert(x)) .Select(x => (ConverterTimelineToKeyFrames(x, $"k{(CREATED_ID++).ToString()}"), x)).ToArray(); var animation_prop = new Property("animation", string.Join(",", animation_key_frames.Select(x => BuildAnimationValues(x.Item1)))); selector.Properties.Add(animation_prop); selector.Properties.Add(new Property("background-image", $"url(\"{System.Text.RegularExpressions.Regex.Escape(obj.ImageFilePath)}\")")); selector.Properties.Add(new Property("background-blend-mode", "multiply")); selector.Properties.Add(position_fix_prop); var key_frames = animation_key_frames.Select(x => x.Item1.frames).ToArray(); ApplyOriginOffset(obj, key_frames, size, selector); return(key_frames, selector); }
public void ExcplictSelect(StoryboardObject obj) { Debug.Assert(comboBox1.Items.OfType <StoryboardObject>().Contains(obj)); comboBox1.SelectedItem = obj; }
private bool IsPointInObjectArea(StoryboardObject obj, float x, float y) { Vector2 obj_pos = new Vector2(obj.Postion.X, obj.Postion.Y); float radio = (float)StoryboardWindow.CurrentWindow.Width / (float)StoryboardWindow.CurrentWindow.Height; float view_width = RenderKernel.SB_HEIGHT * radio; Vector2 mouse_scale = new Vector2(view_width / StoryboardWindow.CurrentWindow.Width, RenderKernel.SB_HEIGHT / StoryboardWindow.CurrentWindow.Height); var mouse_point = new Vector2(x, y) * mouse_scale; mouse_point.X -= (view_width - RenderKernel.SB_WIDTH) / 2.0f; Vector3[] points = new Vector3[4]; var group = StoryboardInstanceManager.ActivityInstance.Resource.GetSprite(obj.ImageFilePath); if (group == null) { return(false); } int w = (int)(group.Texture.Width * Math.Abs(obj.Scale.X)); int h = (int)(group.Texture.Height * Math.Abs(obj.Scale.Y)); Vector2 anchor = new Vector2(obj.OriginOffset.X, obj.OriginOffset.Y) + new Vector2(0.5f, 0.5f); anchor.X *= w; anchor.Y *= h; Vector2[] vertices = new Vector2[4]; vertices[0].X = 0; vertices[0].Y = 0; vertices[1].X = w; vertices[1].Y = 0; vertices[2].X = w; vertices[2].Y = h; vertices[3].X = 0; vertices[3].Y = h; float cosa = (float)Math.Cos(obj.Rotate * DEG2RAD); float sina = (float)Math.Sin(obj.Rotate * DEG2RAD); for (int i = 0; i < vertices.Length; i++) { var v = vertices[i] - anchor; v.X = v.X * cosa + v.Y * sina; v.Y = v.X * sina - v.Y * cosa; v += obj_pos; points[i] = new Vector3(mouse_point - v); } Vector3 v1 = Vector3.Cross(points[0], points[1]).Normalized(); Vector3 v2 = Vector3.Cross(points[1], points[2]).Normalized(); Vector3 v3 = Vector3.Cross(points[2], points[3]).Normalized(); Vector3 v4 = Vector3.Cross(points[3], points[0]).Normalized(); if (Vector3.Dot(v1, v2) > 0.9999f && Vector3.Dot(v2, v3) > 0.9999f && Vector3.Dot(v3, v4) > 0.9999f && Vector3.Dot(v4, v1) > 0.9999f) { return(true); } return(false); }
internal void AddNeedResortObject(StoryboardObject obj) { }
public void UpdateCurrentStoryboardObject() { var time = MusicPlayerManager.ActivityPlayer.CurrentTime; if (SelectObject != null) { if (SelectObject != last_obj) { //这里是物件装载一次的 Text = SelectObject.ImageFilePath; AnchorLabel.Text = SelectObject.OriginOffset.ToString(); OrderLabel.Text = SelectObject.Z.ToString(); TimeLabel.Text = $"{SelectObject.FrameStartTime}~{SelectObject.FrameEndTime}"; #if DEBUG checkBox1.Checked = SelectObject.DebugShow; #endif trigger_status_cache.Clear(); command_node_map.Clear(); button1.Enabled = SelectObject.ContainTrigger; try { pictureBox1.Image = null; var path = StoryboardInstanceManager.ActivityInstance.Resource.GetSprite(SelectObject).Texture.filePath; var img = Bitmap.FromFile(path); if (img != null) { var prev_imgae = pictureBox1.Image; pictureBox1.Image = img; prev_imgae?.Dispose(); } } catch { } } //这里是要实时更新的 PositionLabel.Text = SelectObject.Postion.ToString(); #if DEBUG SelectObject.DebugShow = checkBox1.Checked; #endif int r = SelectObject.Color.X, g = SelectObject.Color.Y, b = SelectObject.Color.Z; ColorLabel.Text = $"{r},{g},{b}"; try { ColorLabel.ForeColor = Color.FromArgb(r, g, b); ColorLabel.BackColor = Color.FromArgb(255 - r, 255 - g, 255 - b); } catch (Exception e) { Log.Error(e.Message); } var a = SelectObject.Rotate * 180 / Math.PI; a = a > 360 ? a % 360 : (a < 0?(360 - ((-a) % 360)):a); AngleLabel.Text = $"{a}°"; AlphaLabel.Text = SelectObject.Color.W.ToString(); ScaleLabel.Text = SelectObject.Scale.ToString(); ParameterLabel.Text = $"{(SelectObject.IsAdditive ? "A" : " ")}{(SelectObject.IsHorizonFlip ? "H" : " ")}{(SelectObject.IsVerticalFlip ? "V" : " ")}"; MarkdoneLabel.Text = (SelectObject.FrameStartTime <= time && time <= SelectObject.FrameEndTime).ToString(); UpdateCommandNode(); } else { if (SelectObject != last_obj) { PositionLabel.Text = string.Empty; ColorLabel.Text = string.Empty; AngleLabel.Text = string.Empty; AlphaLabel.Text = string.Empty; ParameterLabel.Text = string.Empty; MarkdoneLabel.Text = string.Empty; AnchorLabel.Text = string.Empty; TimeLabel.Text = string.Empty; this.Text = string.Empty; OrderLabel.Text = string.Empty; ColorLabel.ForeColor = Color.White; ColorLabel.BackColor = Color.White; command_node_map.Clear(); } } ShowCommandList(); last_obj = SelectObject; }