public void Execute(int index) { // If index is different, this means this line entity was already in the // array, there for this is a duplicate and we can skip it. if (LineEntities.IndexOf <Entity>(LineEntities[index]) != index) { return; } newKnotData = Ecb.SetBuffer <LineKnotData>(index, LineEntities[index]); line = Lines[LineEntities[index]]; lineProfile = LineProfiles.Exists(line.Profile) ? LineProfiles[line.Profile] : LineProfile.Default(); var b1 = BezierData[index].B1; var b2 = BezierData[index].B2; SetKnotsForBezier(b1); if (!b1.c2.IsCloseTo(b2.c2, lineProfile.KnotSpacing)) { SetKnotsForBezier(new float3x3(b1.c2, math.lerp(b1.c2, b2.c2, 0.5f), b2.c2)); } SetKnotsForBezier(b2, true); AdjustHeight(HeightBezierData[index]); var jpA = LineJoinPoints[index].A; var jpB = LineJoinPoints[index].B; if (newKnotData.Length > 0) { jpA.Pivot = newKnotData[0].Position; jpB.Pivot = newKnotData[newKnotData.Length - 1].Position; } LineJoinPoints[index] = new JoinPointPair { A = jpA, B = jpB }; }
public void Execute(int index) { var modifiers = LineTool.Data.Modifiers; var jp1 = LineJoinPoints[index].A; var jp2 = LineJoinPoints[index].B; var pointAIsConnected = JoinPoints.Exists(jp1.JoinToPointEntity); var pointBIsConnected = JoinPoints.Exists(jp2.JoinToPointEntity); var pointA = jp1.Pivot; var pointB = jp2.Pivot; // Two curves b1, b2 float3x3 b1, b2; // c0 is the origin b1.c0 = pointA; b2.c0 = pointB; // If join points invalid or not connected initialise to facing other point jp1.Direction = jp1.Direction.Equals(float3.zero) || float.IsNaN(jp1.Direction.x) || !pointBIsConnected && !pointAIsConnected ? Normalize(pointB - pointA) : jp1.Direction; jp2.Direction = jp2.Direction.Equals(float3.zero) || float.IsNaN(jp2.Direction.x) || !pointAIsConnected && !pointBIsConnected ? Normalize(pointA - pointB) : jp2.Direction; var forwards = new float3x2(jp1.Direction, jp2.Direction); var distances = new float2( Distance(pointA, pointB, forwards.c0), Distance(pointB, pointA, forwards.c1)); var scales = new float2( Scale(modifiers.From.Size, distances.x), Scale(modifiers.To.Size, distances.y)); if (pointAIsConnected && !pointBIsConnected) { distances.y = 0f; b1.c1 = GetOrigin(); jp2.Direction = Normalize(b1.c1 - b2.c0); b1.c2 = Target(b1.c1, b2.c0, distances.x, distances.y, scales.x, scales.y, modifiers.From.Ratio); b2.c2 = b2.c1 = b2.c0; } else if (!pointAIsConnected && pointBIsConnected) { distances.x = 0f; b2.c1 = GetEnd(); // Do Rotate jp1.Direction = Normalize(b2.c1 - b1.c0); b2.c2 = Target(b2.c1, b1.c0, distances.y, distances.x, scales.y, scales.x, modifiers.To.Ratio); b1.c2 = b1.c1 = b1.c0; } else { if (!pointAIsConnected) { jp1.Direction = Normalize(b2.c0 - b1.c0); } if (!pointBIsConnected) { jp2.Direction = Normalize(b1.c0 - b2.c0); } b1.c1 = GetOrigin(); b2.c1 = GetEnd(); b1.c2 = Target(b1.c1, b2.c1, distances.x, distances.y, scales.x, scales.y, modifiers.From.Ratio); b2.c2 = Target(b2.c1, b1.c1, distances.y, distances.x, scales.y, scales.x, modifiers.To.Ratio); } BezierData[index] = new BezierData { B1 = b1, B2 = b2 }; LineJoinPoints[index] = new JoinPointPair { A = jp1, B = jp2 }; float3 GetOrigin() { return(GetControlPoint(forwards.c0, pointA, distances.x, scales.x, modifiers.From.Ratio)); } float3 GetEnd() { return(GetControlPoint(forwards.c1, pointB, distances.y, scales.y, modifiers.To.Ratio)); }