public static Rect AtlasField(IFerr2DTMaterial aMat, Rect aRect, Texture aTexture) { EditorGUILayout.BeginHorizontal(GUILayout.Height(64)); GUILayout.Space(5); GUILayout.Space(64); Rect r = GUILayoutUtility.GetLastRect(); float max = Mathf.Max(1, Mathf.Max(aRect.width, aRect.height)); r.width = Mathf.Max(1, (aRect.width / max) * 64); r.height = Mathf.Max(1, (aRect.height / max) * 64); GUI.DrawTexture(new Rect(r.x - 1, r.y - 1, r.width + 2, 1), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(r.x - 1, r.yMax + 1, r.width + 2, 1), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(r.x - 1, r.y - 1, 1, r.height + 2), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(r.xMax, r.y - 1, 1, r.height + 2), EditorGUIUtility.whiteTexture); GUI.DrawTextureWithTexCoords(r, aTexture, aMat.ToUV(aRect)); GUILayout.Space(10); Rect result = aMat.ToNative(EditorGUILayout.RectField(aMat.ToPixels(aRect))); EditorGUILayout.EndHorizontal(); return(result); }
private void LegacyAddFill(bool aSkirt, bool aFullBuild) { IFerr2DTMaterial mat = TerrainMaterial; float texWidth = mat.edgeMaterial ? 256 : mat.edgeMaterial.mainTexture.width; float fillDist = (mat.ToUV(mat.GetBody((Ferr2DT_TerrainDirection)0, 0)).width *(texWidth / pixelsPerUnit)) / (Mathf.Max(1, splitCount)) * splitDist; List <Vector2> fillVerts = GetSegmentsCombined(fillDist); Vector2 scale = Vector2.one; // scale is different for the fill texture if (mat.fillMaterial != null && mat.fillMaterial.mainTexture != null) { scale = new Vector2( mat.fillMaterial.mainTexture.width / pixelsPerUnit, mat.fillMaterial.mainTexture.height / pixelsPerUnit); } if (aSkirt) { Vector2 start = fillVerts[0]; Vector2 end = fillVerts[fillVerts.Count - 1]; fillVerts.Add(new Vector2(end.x, fillY)); fillVerts.Add(new Vector2(Mathf.Lerp(end.x, start.x, 0.33f), fillY)); fillVerts.Add(new Vector2(Mathf.Lerp(end.x, start.x, 0.66f), fillY)); fillVerts.Add(new Vector2(start.x, fillY)); } int offset = DMesh.VertCount; List <int> indices = Ferr2D_Triangulator.GetIndices(ref fillVerts, true, fill == Ferr2DT_FillMode.InvertedClosed, invertFillBorder, fillSplit && aFullBuild ? fillSplitDistance : 0); for (int i = 0; i < fillVerts.Count; i++) { DMesh.AddVertex(fillVerts[i].x, fillVerts[i].y, fillZ, (fillVerts[i].x + uvOffset.x + transform.position.x) / scale.x, (fillVerts[i].y + uvOffset.y + transform.position.y) / scale.y); } for (int i = 0; i < indices.Count; i += 3) { try { DMesh.AddFace(indices[i] + offset, indices[i + 1] + offset, indices[i + 2] + offset); } catch { } } }
private void LegacyAddCap(List <Vector2> aSegment, Ferr2DT_SegmentDescription aDesc, bool aInner, float aDir, float aScale, bool aSmooth) { IFerr2DTMaterial mat = TerrainMaterial; Ferr2D_DynamicMesh mesh = DMesh; int index = 0; Vector2 dir = Vector2.zero; if (aDir < 0) { index = 0; dir = aSegment[0] - aSegment[1]; } else { index = aSegment.Count - 1; dir = aSegment[aSegment.Count - 1] - aSegment[aSegment.Count - 2]; } dir.Normalize(); Vector2 norm = aSmooth ? Ferr2D_Path.HermiteGetNormal(aSegment, index, 0, false): Ferr2D_Path.GetNormal(aSegment, index, false); Vector2 pos = aSegment[index]; float yOff = fill == Ferr2DT_FillMode.InvertedClosed ? -aDesc.yOffset : aDesc.yOffset; Rect cap; if (aDir < 0) { if (fill == Ferr2DT_FillMode.InvertedClosed) { cap = (!aInner && aDesc.innerRightCap.width > 0) ? mat.ToUV(aDesc.innerRightCap) : mat.ToUV(aDesc.rightCap); } else { cap = (aInner && aDesc.innerLeftCap.width > 0) ? mat.ToUV(aDesc.innerLeftCap) : mat.ToUV(aDesc.leftCap); } } else { if (fill == Ferr2DT_FillMode.InvertedClosed) { cap = (!aInner && aDesc.innerLeftCap.width > 0) ? mat.ToUV(aDesc.innerLeftCap) : mat.ToUV(aDesc.leftCap); } else { cap = (aInner && aDesc.innerRightCap.width > 0) ? mat.ToUV(aDesc.innerRightCap) : mat.ToUV(aDesc.rightCap); } } float width = cap.width * unitsPerUV.x; float scale = (cap.height / 2) * unitsPerUV.y * aScale; float minU = fill == Ferr2DT_FillMode.InvertedClosed ? cap.xMax : cap.x; float maxU = fill == Ferr2DT_FillMode.InvertedClosed ? cap.x : cap.xMax; float minV = fill == Ferr2DT_FillMode.InvertedClosed ? cap.yMax : cap.y; float maxV = fill == Ferr2DT_FillMode.InvertedClosed ? cap.y : cap.yMax; if (aDir >= 0) { float t = minU; minU = maxU; maxU = t; } int v1 = mesh.AddVertex(pos + dir * width + norm * (scale + yOff), -slantAmount + aDesc.zOffset, new Vector2(minU, minV)); int v2 = mesh.AddVertex(pos + norm * (scale + yOff), -slantAmount + aDesc.zOffset, new Vector2(maxU, minV)); int v15 = splitMiddle ? mesh.AddVertex(pos + dir * width + (norm * yOff), aDesc.zOffset, new Vector2(minU, cap.y + (cap.height / 2))) : -1; int v25 = splitMiddle ? mesh.AddVertex(pos + (norm * yOff), aDesc.zOffset, new Vector2(maxU, cap.y + (cap.height / 2))) : -1; int v3 = mesh.AddVertex(pos - norm * (scale - yOff), slantAmount + aDesc.zOffset, new Vector2(maxU, maxV)); int v4 = mesh.AddVertex(pos + dir * width - norm * (scale - yOff), slantAmount + aDesc.zOffset, new Vector2(minU, maxV)); if (splitMiddle && aDir < 0) { mesh.AddFace(v1, v2, v25, v15); mesh.AddFace(v15, v25, v3, v4); } else if (splitMiddle && aDir >= 0) { mesh.AddFace(v2, v1, v15, v25); mesh.AddFace(v25, v15, v4, v3); } else if (aDir < 0) { mesh.AddFace(v1, v2, v3, v4); } else { mesh.AddFace(v2, v1, v4, v3); } }
public static void ShowSample(IFerr2DTMaterial aMat, Ferr2DT_TerrainDirection aDir, float aWidth) { if (aMat.edgeMaterial == null || aMat.edgeMaterial.mainTexture == null) { return; } Ferr2DT_SegmentDescription desc = aMat.GetDescriptor(aDir); float totalWidth = desc.leftCap.width + desc.rightCap.width + (desc.body[0].width * 3); float sourceHeight = MaxHeight(desc); float scale = Mathf.Min(aWidth / totalWidth, 64 / sourceHeight); GUILayout.Space(sourceHeight * scale); float x = GUILayoutUtility.GetLastRect().x; float y = GUILayoutUtility.GetLastRect().y; if (desc.leftCap.width != 0) { float yOff = ((sourceHeight - desc.leftCap.height) / 2) * scale; GUI.DrawTextureWithTexCoords(new Rect(x, y + yOff, desc.leftCap.width * scale, desc.leftCap.height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.leftCap)); x += desc.leftCap.width * scale; } for (int i = 0; i < 3; i++) { int id = (2 - i) % desc.body.Length; float yOff = ((sourceHeight - desc.body[id].height) / 2) * scale; GUI.DrawTextureWithTexCoords(new Rect(x, y + yOff, desc.body[id].width * scale, desc.body[id].height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.body[id])); x += desc.body[id].width * scale; } if (desc.leftCap.width != 0) { float yOff = ((sourceHeight - desc.rightCap.height) / 2) * scale; GUI.DrawTextureWithTexCoords(new Rect(x, y + yOff, desc.rightCap.width * scale, desc.rightCap.height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.rightCap)); } }