private Definition2D CreateDefinition2D(IDefinition def) { Definition2D result = new Definition2D(); result.Id = def.Id; result.DefinitionName = def.Name; // todo: get linkage names from export assests tags (in vex format) result.LinkageName = def.Name; result.Bounds = def.StrokeBounds; if (def is Timeline) { Timeline tlDef = (Timeline)def; result.FrameCount = tlDef.FrameCount; } else if (def is Symbol) { // Symbol instDef = (Symbol)def; // result.StartTime = (int)instDef.StartTime; // result.EndTime = (int)instDef.EndTime; ParseBodyImage(result, def); } return(result); }
private Definition2D GetTextDefinition(Matrix m, Text def) { Definition2D result = definitions.Find(d => d.DefinitionName == def.Name); if (result == null) { result = CreateTextDefinition(def); definitions.Add(result); } return(result); }
private void WriteJointData(List <V2DJoint> defJoints, Definition2D def) { Joint2D[] jts = new Joint2D[def.Joints.Count]; def.Joints.Values.CopyTo(jts, 0); List <Joint2D> jList = new List <Joint2D>(jts); jList.Sort(); foreach (Joint2D j in jList) { defJoints.Add(j.GetV2DJoint()); } }
public void Init(DDW.Swf.SwfCompilationUnit scu) { root = new Definition2D(); root.DefinitionName = V2D.ROOT_NAME; root.LinkageName = V2D.ROOT_NAME; root.Bounds = Rectangle.Empty; root.FrameCount = 1; definitions.Add(root); rootInstance = new Instance2D(V2D.ROOT_NAME, root.DefinitionName, 0, 0, 0, 1, 1); rootInstance.Definition = root; rootInstance.Transforms.Add(new Transform( 0, (uint)(scu.Header.FrameCount * (1000 / scu.Header.FrameRate)), new Matrix(1, 0, 0, 1, 0, 0), 1, ColorTransform.Identity)); parentStack.Push(rootInstance); }
private void GenerateJointActionData(Joint2D jnt, Definition2D body) { foreach (string k in codeData.Keys) { if (jnt.Name == k) { Dictionary <string, string> d = codeData[k]; foreach (string s in d.Keys) { if (jnt.data.ContainsKey(s)) { jnt.data[s] = d[s]; } else { jnt.data.Add(s, d[s]); } } } } }
private void GenerateJointData(Definition2D def) { if (!def.IsDefined) // todo: really really need to do this isDefined crap right. { foreach (Joint2D j in def.Joints.Values) { string jName = j.Name; EnsureBodyTags(j); string b1Name = j.data["body1"]; string b2Name = j.data["body2"]; Instance2D b1Body = (b1Name == V2D.ROOT_NAME) ? rootInstance : parentStack.Peek().Definition.GetChildByName(b1Name); Instance2D b2Body = (b2Name == V2D.ROOT_NAME) ? rootInstance : parentStack.Peek().Definition.GetChildByName(b2Name); V2DJointKind jointKind = j.JointKind; if (!j.data.ContainsKey("location")) { if (V2D.OUTPUT_TYPE == OutputType.Swf) { j.data.Add("location", "#" + j.Locations[0].ToString()); } else { j.data.Add("X", j.Locations[0].X.ToString()); j.data.Add("Y", j.Locations[0].Y.ToString()); } } if ((j.Locations.Count > 1) && (jointKind == V2DJointKind.Distance || jointKind == V2DJointKind.Pully)) { if (!j.data.ContainsKey("location2")) { if (V2D.OUTPUT_TYPE == OutputType.Swf) { j.data.Add("location2", "#" + j.Locations[1].ToString()); } else { j.data.Add("X2", j.Locations[1].X.ToString()); j.data.Add("Y2", j.Locations[1].Y.ToString()); } } if (jointKind == V2DJointKind.Pully) { Point groundAnchor1; Point groundAnchor2; if (b1Body.Transforms.Count > 1) { groundAnchor1 = new Point( b1Body.Transforms[1].Matrix.TranslateX, b1Body.Transforms[1].Matrix.TranslateY); groundAnchor2 = new Point( b2Body.Transforms[1].Matrix.TranslateX, b2Body.Transforms[1].Matrix.TranslateY); } else { groundAnchor1 = j.Transforms[0]; groundAnchor2 = j.Transforms[1]; } float d1x = groundAnchor1.X - j.Locations[0].X; // m1a.TranslateX; float d1y = groundAnchor1.Y - j.Locations[0].Y; //m1a.TranslateY; float d2x = groundAnchor2.X - j.Locations[1].X; //m2a.TranslateX; float d2y = groundAnchor2.Y - j.Locations[1].Y; //m2a.TranslateY; float maxLength1 = (float)Math.Sqrt(d1x * d1x + d1y * d1y); float maxLength2 = (float)Math.Sqrt(d2x * d2x + d2y * d2y); //j.data.Add("groundAnchor1", groundAnchor1.ToString()); //j.data.Add("groundAnchor2", groundAnchor2.ToString()); j.data.Add("groundAnchor1X", groundAnchor1.X.ToString()); j.data.Add("groundAnchor1Y", groundAnchor1.Y.ToString()); j.data.Add("groundAnchor2X", groundAnchor2.X.ToString()); j.data.Add("groundAnchor2Y", groundAnchor2.Y.ToString()); j.data.Add("maxLength1", maxLength1.ToString()); j.data.Add("maxLength2", maxLength2.ToString()); } } else if (b1Body.Transforms.Count > 1 || b2Body.Transforms.Count > 1) { List <Transform> tr = (b1Body.Transforms.Count > 1) ? b1Body.Transforms : b2Body.Transforms; if (jointKind == V2DJointKind.Revolute) { float start = (float)(tr[0].Matrix.GetMatrixComponents().Rotation / 180 * Math.PI); float rmin = (float)(tr[1].Matrix.GetMatrixComponents().Rotation / 180 * Math.PI); float rmax = (float)(tr[2].Matrix.GetMatrixComponents().Rotation / 180 * Math.PI); rmin = rmin - start; rmax = rmax - start; if (rmin > 0) { rmin = (float)(Math.PI * -2 + rmin); } j.data.Add("min", rmin.ToString()); j.data.Add("max", rmax.ToString()); } else if (jointKind == V2DJointKind.Prismatic) { Point a = new Point( tr[0].Matrix.TranslateX, tr[0].Matrix.TranslateY); Point p0 = new Point( tr[1].Matrix.TranslateX, tr[1].Matrix.TranslateY); Point p1 = new Point( tr[2].Matrix.TranslateX, tr[2].Matrix.TranslateY); double len = Math.Sqrt((p1.Y - p0.Y) * (p1.Y - p0.Y) + (p1.X - p0.X) * (p1.X - p0.X)); double r = ((p0.Y - a.Y) * (p0.Y - p1.Y) - (p0.X - a.X) * (p0.X - p1.X)) / (len * len); float axisX = p1.X - p0.X; float axisY = p1.Y - p0.Y; float maxAxis = Math.Abs(axisX) > Math.Abs(axisY) ? axisX : axisY; axisX /= maxAxis; axisY /= maxAxis; Point ap0 = new Point(p0.X - a.X, p0.Y - a.Y); Point ap1 = new Point(p1.X - a.X, p1.Y - a.Y); float min = (float)-(Math.Abs(r * len)); float max = (float)((1 - Math.Abs(r)) * len); // Point ab = new Point(b.X - a.X, b.Y - a.Y); // float r0 = (ap0.X * ab.X + ap0.Y * ab.Y) / (w * w); // dot product //float r1 = (ap1.X * ab.X + ap1.Y * ab.Y) / (w * w); // dot product j.data.Add("axisX", axisX.ToString()); j.data.Add("axisY", axisY.ToString()); j.data.Add("min", min.ToString()); j.data.Add("max", max.ToString()); } } } } }
private void ParseBodyImage(Definition2D b2d, IDefinition sy) { string bmpPath = AddSymbolImage(sy); }
private void EnsureDefinition(Instance inst, IDefinition def) { DefinitionKind dk = (DefinitionKind)def.UserData; bool addInst = (inst != null); Matrix m = (inst == null) ? Matrix.Identity : inst.Transformations[0].Matrix; if ((dk & DefinitionKind.Ignore) == 0) { if (((dk & DefinitionKind.JointMarker) != 0) && (inst != null)) { V2DJointKind jointKind = jointKindMap[jointKinds.IndexOf(def.Name)]; ParseJoint(jointKind, inst); } else if (((dk & DefinitionKind.ShapeMarker) != 0) && (inst != null)) { if (!parentStack.Peek().Definition.IsDefined) { parentStack.Peek().Definition.AddShapes(curVo, def, m); } } if ((dk & DefinitionKind.TextField) != 0) { Text txt = (Text)def; if (def.Name == null) { def.Name = "$tx_" + def.Id; } Definition2D d2d = GetTextDefinition(m, txt); if (txt.TextRuns.Count > 0 && !txt.TextRuns[0].isEditable) { AddSymbolImage(def); } if (addInst) { AddInstance(inst, def); } } if ((dk & DefinitionKind.Timeline) != 0) { Definition2D d2d = GetDefinition2D(m, def); Instance2D i2d; if (addInst) { i2d = AddInstance(inst, def); } else { i2d = CreateInstance2D(def); } parentStack.Push(i2d); ParseTimeline((Timeline)def); i2d.Definition.IsDefined = true; parentStack.Pop(); } if ((dk & DefinitionKind.Symbol) != 0) { // todo: this is just adding images //Body2D b2d = CreateBody2D(inst, def); if (def.Name == null) { def.Name = "$sym_" + def.Id; } Definition2D d2d = GetDefinition2D(m, def); AddSymbolImage(def); if (addInst) { AddInstance(inst, def); } } if ((dk & DefinitionKind.Vex2D) != 0) { Definition2D d2d = GetDefinition2D(m, def); if (!isDefined.Contains(def.Id)) { isDefined.Add(def.Id); d2d.AddShapes(curVo, def, m); //parentStack.Peek().Definition.AddShapes(curVo, def, m); } Instance2D i2d; if (addInst) { i2d = AddInstance(inst, def); } else { i2d = CreateInstance2D(def); } parentStack.Push(i2d); ParseTimeline((Timeline)def); i2d.Definition.IsDefined = true; parentStack.Pop(); } } if (!isDefined.Contains(def.Id)) { isDefined.Add(def.Id); } }