private void DoCutOverrideModeHandles(Ferr2D_Path path, Ferr2DT_PathTerrain terrain, Matrix4x4 mat, Transform camTransform) { List <List <int> > segments = new List <List <int> >(); List <Ferr2DT_TerrainDirection> dirs = new List <Ferr2DT_TerrainDirection>(); List <Vector2> rawVerts = path.GetVertsRaw(); // cut the terrain into segments, we need segment info to draw these points segments = terrain.GetSegments(rawVerts, out dirs); for (int s = 0; s < segments.Count; s++) { List <int> currSeg = segments[s]; List <Vector2> currVerts = Ferr2D_Path.IndicesToList(rawVerts, currSeg); List <Ferr2DT_PathTerrain.CutOverrides> overrides = Ferr2D_Path.IndicesToList(terrain.cutOverrides, currSeg); // find information about this segment Ferr2DT_TerrainDirection currDir = dirs[s]; Ferr2DT_SegmentDescription desc = default(Ferr2DT_SegmentDescription); if (currDir != Ferr2DT_TerrainDirection.None) { desc = terrain.TerrainMaterial.GetDescriptor(currDir); } else { desc = terrain.GetDescription(currSeg); } // if there's no body segment choices, don't bother with the rest of this if (desc.body.Length < 2) { continue; } Vector2 capLeftSlideDir = (currVerts[1] - currVerts[0]); Vector2 capRightSlideDir = (currVerts[currVerts.Count - 2] - currVerts[currVerts.Count - 1]); capLeftSlideDir.Normalize(); capRightSlideDir.Normalize(); currVerts[0] -= capLeftSlideDir * desc.capOffset; currVerts[currVerts.Count - 1] -= capRightSlideDir * desc.capOffset; float distance = Ferr2D_Path.GetSegmentLength(currVerts); // how many texture cuts are there on the segment float bodyWidth = desc.body[0].width * (terrain.TerrainMaterial.edgeMaterial.mainTexture.width / terrain.pixelsPerUnit); int textureCuts = Mathf.Max(1, Mathf.FloorToInt(distance / bodyWidth + 0.5f)); // data is attached to the points still, check if we've switched to a new point int activePt = -1; int activeLocalCut = -1; for (int c = 0; c < textureCuts; c++) { float pctGlobal = c / (float)textureCuts; int ptLocal = 0; float pctLocal = 0; Ferr2D_Path.PathGlobalPercentToLocal(currVerts, pctGlobal, out ptLocal, out pctLocal, distance, false); if (ptLocal != activePt) { // if they size down, we need to shorten the data too if (activePt != -1) { CapListSize <int>(ref overrides[activePt].data, activeLocalCut + 3); } activePt = ptLocal; activeLocalCut = 0; if (overrides[activePt].data == null) { overrides[activePt].data = new List <int>(); } } while (activeLocalCut >= overrides[activePt].data.Count) { overrides[activePt].data.Add(0); } CapFunction cap = CapDotAuto; int activeOverride = overrides[activePt].data[activeLocalCut]; if (activeOverride != 0) { if (activeOverride == 1) { cap = CapDot1; } else if (activeOverride == 2) { cap = CapDot2; } else if (activeOverride == 3) { cap = CapDot3; } else if (activeOverride == 4) { cap = CapDot4; } else if (activeOverride == 5) { cap = CapDot5; } else if (activeOverride >= 6) { cap = CapDotN; } } if (Event.current.alt) { cap = CapDotReset; } int ptShow = 0; float pctShow = 0; Ferr2D_Path.PathGlobalPercentToLocal(currVerts, pctGlobal + (1f / textureCuts) * 0.5f, out ptShow, out pctShow, distance, false); Vector2 pt = Ferr2D_Path.LinearGetPt(currVerts, ptShow, pctShow, false); Vector3 pos = mat.MultiplyPoint3x4(pt); float sc = HandleScale(pos) * 0.5f; if (Handles.Button(pos, camTransform.rotation, sc, sc, cap)) { Undo.RecordObject(terrain, "Lock Texture Segment"); overrides[activePt].data[activeLocalCut] = Event.current.alt ? 0 : (activeOverride + 1) % (desc.body.Length + 1); EditorUtility.SetDirty(terrain); GUI.changed = true; } activeLocalCut += 1; } if (activePt != -1) { CapListSize <int>(ref overrides[activePt].data, activeLocalCut + 3); } } }
private void LegacyAddVertexColumn(Ferr2DT_SegmentDescription aDesc, List <Vector2> aSegment, List <float> aSegmentScale, bool aClosed, Ferr2D_DynamicMesh mesh, Rect body, float d, float yOff, bool aConnectFace, float slicePercent, int ptLocal, float pctLocal, ref int p1, ref int p2, ref int p3) { Vector2 pos1 = smoothPath ? Ferr2D_Path.HermiteGetPt(aSegment, ptLocal, pctLocal, aClosed) : Ferr2D_Path.LinearGetPt(aSegment, ptLocal, pctLocal, aClosed); Vector2 n1 = smoothPath ? Ferr2D_Path.HermiteGetNormal(aSegment, ptLocal, pctLocal, aClosed) : Ferr2D_Path.LinearGetNormal(aSegment, ptLocal, pctLocal, aClosed); float s = aClosed ? Mathf.Lerp(aSegmentScale[ptLocal], aSegmentScale[(ptLocal + 1) % aSegmentScale.Count], pctLocal) : Mathf.Lerp(aSegmentScale[ptLocal], aSegmentScale[Mathf.Min(ptLocal + 1, aSegmentScale.Count - 1)], pctLocal); // this compensates for scale distortion when corners are very sharp, but the normals are not long enough to keep the edge the appropriate width // not actually a problem for smooth paths if (!smoothPath) { n1.Normalize(); float rootScale = 1f / Mathf.Abs(Mathf.Cos(Vector2.Angle(Ferr2D_Path.GetSegmentNormal(ptLocal, aSegment, aClosed), n1) * Mathf.Deg2Rad)); s = s * rootScale; } int v1 = mesh.AddVertex(pos1.x + n1.x * (d * s + yOff), pos1.y + n1.y * (d * s + yOff), -slantAmount + aDesc.zOffset, Mathf.Lerp(body.x, body.xMax, slicePercent), fill == Ferr2DT_FillMode.InvertedClosed ? body.yMax : body.y); int v2 = mesh.AddVertex(pos1.x - n1.x * (d * s - yOff), pos1.y - n1.y * (d * s - yOff), slantAmount + aDesc.zOffset, Mathf.Lerp(body.x, body.xMax, slicePercent), fill == Ferr2DT_FillMode.InvertedClosed ? body.y : body.yMax); int v3 = splitMiddle ? mesh.AddVertex(pos1.x + n1.x * yOff, pos1.y + n1.y * yOff, aDesc.zOffset, Mathf.Lerp(body.x, body.xMax, slicePercent), Mathf.Lerp(body.y, body.yMax, 0.5f)) : -1; if (aConnectFace) { if (!splitMiddle) { mesh.AddFace(v2, p2, p1, v1); } else { mesh.AddFace(v2, p2, p3, v3); mesh.AddFace(v3, p3, p1, v1); } } p1 = v1; p2 = v2; p3 = v3; }