[OvldGenCallTarget] public static void Line([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode, [OvldDefault(nameof(LineGeometry))] LineGeometry geometry, [OvldDefault(nameof(LineEndCaps))] LineEndCap endCaps, [OvldDefault(nameof(LineThicknessSpace))] ThicknessSpace thicknessSpace, Vector3 start, Vector3 end, [OvldDefault(nameof(Color))] Color colorStart, [OvldDefault(nameof(Color))] Color colorEnd, [OvldDefault(nameof(LineThickness))] float thickness, [OvldDefault(nameof(LineDashStyle))] DashStyle dashStyle = null) { Material mat = ShapesMaterialUtils.GetLineMat(geometry, endCaps)[blendMode]; ApplyGlobalProperties(mat); mat.SetColor(ShapesMaterialUtils.propColor, colorStart); mat.SetColor(ShapesMaterialUtils.propColorEnd, colorEnd); mat.SetVector(ShapesMaterialUtils.propPointStart, start); mat.SetVector(ShapesMaterialUtils.propPointEnd, end); mat.SetFloat(ShapesMaterialUtils.propThickness, thickness); mat.SetInt(ShapesMaterialUtils.propAlignment, (int)geometry); mat.SetInt(ShapesMaterialUtils.propThicknessSpace, (int)thicknessSpace); mat.SetInt(ShapesMaterialUtils.propScaleMode, (int)ScaleMode); ApplyDashSettings(mat, dashStyle, thickness, useType: geometry != LineGeometry.Volumetric3D); DrawMesh(Vector3.zero, Quaternion.identity, ShapesMeshUtils.GetLineMesh(geometry, endCaps), mat); }
[OvldGenCallTarget] static void Line([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode, [OvldDefault(nameof(LineGeometry))] LineGeometry geometry, [OvldDefault(nameof(LineEndCaps))] LineEndCap endCaps, [OvldDefault(nameof(LineThicknessSpace))] ThicknessSpace thicknessSpace, Vector3 start, Vector3 end, [OvldDefault(nameof(Color))] Color colorStart, [OvldDefault(nameof(Color))] Color colorEnd, [OvldDefault(nameof(LineThickness))] float thickness, [OvldDefault(nameof(LineDashStyle))] DashStyle dashStyle = null) { using (new IMDrawer( metaMpb: mpbLine, sourceMat: ShapesMaterialUtils.GetLineMat(geometry, endCaps)[blendMode], sourceMesh: ShapesMeshUtils.GetLineMesh(geometry, endCaps, DetailLevel))) { MetaMpb.ApplyDashSettings(mpbLine, dashStyle, thickness); mpbLine.color.Add(colorStart); mpbLine.colorEnd.Add(colorEnd); mpbLine.pointStart.Add(start); mpbLine.pointEnd.Add(end); mpbLine.thickness.Add(thickness); mpbLine.alignment.Add((float)geometry); mpbLine.thicknessSpace.Add((float)thicknessSpace); mpbLine.scaleMode.Add((float)ScaleMode); } }
public static Mesh GetLineMesh(LineGeometry geometry, LineEndCap endCaps) { switch (geometry) { case LineGeometry.Billboard: case LineGeometry.Flat2D: return(QuadMesh); case LineGeometry.Volumetric3D: return(endCaps == LineEndCap.Round ? CapsuleMesh : CylinderMesh); } return(default);
public static Mesh GetLineMesh(LineGeometry geometry, LineEndCap endCaps, DetailLevel detail) { switch (geometry) { case LineGeometry.Billboard: case LineGeometry.Flat2D: return(QuadMesh[0]); case LineGeometry.Volumetric3D: return(endCaps == LineEndCap.Round ? CapsuleMesh[(int)detail] : CylinderMesh[(int)detail]); } return(default);
public static ShapesMaterials GetLineMat(LineGeometry geometry, LineEndCap cap) { switch (geometry) { case LineGeometry.Billboard: case LineGeometry.Flat2D: return(matsLine[(int)cap]); case LineGeometry.Volumetric3D: return(matsLine3D[(int)cap]); default: throw new ArgumentOutOfRangeException(nameof(geometry), geometry, null); } }
[OvldGenCallTarget] public static void Line([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode, [OvldDefault(nameof(LineGeometry))] LineGeometry geometry, [OvldDefault(nameof(LineEndCaps))] LineEndCap endCaps, [OvldDefault(nameof(LineThicknessSpace))] ThicknessSpace thicknessSpace, Vector3 start, Vector3 end, [OvldDefault(nameof(Color))] Color colorStart, [OvldDefault(nameof(Color))] Color colorEnd, [OvldDefault(nameof(LineThickness))] float thickness, [OvldDefault(nameof(LineDashStyle))] DashStyle dashStyle = null) { Material mat = ShapesMaterialUtils.GetLineMat(geometry, endCaps)[blendMode]; ApplyGlobalProperties(mat); mat.SetColor(ShapesMaterialUtils.propColor, colorStart); mat.SetColor(ShapesMaterialUtils.propColorEnd, colorEnd); mat.SetVector(ShapesMaterialUtils.propPointStart, start); mat.SetVector(ShapesMaterialUtils.propPointEnd, end); mat.SetFloat(ShapesMaterialUtils.propThickness, thickness); mat.SetInt(ShapesMaterialUtils.propAlignment, (int)geometry); mat.SetInt(ShapesMaterialUtils.propThicknessSpace, (int)thicknessSpace); mat.SetInt(ShapesMaterialUtils.propScaleMode, (int)ScaleMode); bool dashed = dashStyle?.size > 0f; mat.SetFloat(ShapesMaterialUtils.propDashSize, dashed ? dashStyle.GetNetAbsoluteSize(true, thickness) : 0); if (dashed) { if (geometry != LineGeometry.Volumetric3D) { mat.SetInt(ShapesMaterialUtils.propDashType, (int)dashStyle.type); } mat.SetInt(ShapesMaterialUtils.propDashSpace, (int)dashStyle.space); mat.SetInt(ShapesMaterialUtils.propDashSnap, (int)dashStyle.snap); mat.SetFloat(ShapesMaterialUtils.propDashOffset, dashStyle.offset); mat.SetFloat(ShapesMaterialUtils.propDashSpacing, dashStyle.GetNetAbsoluteSpacing(true, thickness)); } DrawMesh(Vector3.zero, Quaternion.identity, ShapesMeshUtils.GetLineMesh(geometry, endCaps), mat); }
[OvldGenCallTarget] static void Line_Internal([OvldDefault(nameof(LineEndCaps))] LineEndCap endCaps, [OvldDefault(nameof(ThicknessSpace))] ThicknessSpace thicknessSpace, Vector3 start, Vector3 end, [OvldDefault(nameof(Color))] Color colorStart, [OvldDefault(nameof(Color))] Color colorEnd, [OvldDefault(nameof(Thickness))] float thickness) { using (new IMDrawer( metaMpb: mpbLine, sourceMat: ShapesMaterialUtils.GetLineMat(Draw.LineGeometry, endCaps)[Draw.BlendMode], sourceMesh: ShapesMeshUtils.GetLineMesh(Draw.LineGeometry, endCaps, DetailLevel))) { MetaMpb.ApplyDashSettings(mpbLine, thickness); mpbLine.color.Add(colorStart.ColorSpaceAdjusted()); mpbLine.colorEnd.Add(colorEnd.ColorSpaceAdjusted()); mpbLine.pointStart.Add(start); mpbLine.pointEnd.Add(end); mpbLine.thickness.Add(thickness); mpbLine.alignment.Add((float)Draw.LineGeometry); // this is redundant for 3D lines, but, that's okay, fixing that makes things messier mpbLine.thicknessSpace.Add((float)thicknessSpace); mpbLine.scaleMode.Add((float)ScaleMode); } }
void DrawShapes() { Vector2 center = position.size / 2; float fitRadius = Mathf.Min(position.width, position.height) / 2 - 8; // set doot positions float t = (float)EditorApplication.timeSinceStartup / 2; foreach (Doot doot in doots) { float ang = doot.angSpeed * t * ShapesMath.TAU + doot.angOffset; Vector2 dir = ShapesMath.AngToDir(ang); doot.pos = dir * (fitRadius * doot.radialOffset); } // mouse doot~ Vector2 mouseRawPos = Event.current.mousePosition - center; float maxRadius = fitRadius * DOOT_MAX_RADIUS; Vector2 mouseTargetPos = Vector2.ClampMagnitude(mouseRawPos, maxRadius); doots[0].pos = Vector2.Lerp(doots[0].pos, mouseTargetPos, mouseDootT); bool mouseOver = mouseOverWindow == this; mouseDootT = Mathf.Lerp(mouseDootT, mouseOver ? 1f : 0f, 0.05f); // save state Matrix4x4 prevMtx = Draw.Matrix; ShapesBlendMode prevBlendMode = Draw.BlendMode; ThicknessSpace prevDiscRadiusSpace = Draw.DiscRadiusSpace; ThicknessSpace prevLineThicknessSpace = Draw.LineThicknessSpace; LineGeometry prevLineGeometry = Draw.LineGeometry; ThicknessSpace prevRingThicknessSpace = Draw.RingThicknessSpace; LineEndCap prevLineEndCaps = Draw.LineEndCaps; // draw setup Draw.Matrix = Matrix4x4.TRS(new Vector3(center.x, center.y, 1f), Quaternion.identity, Vector3.one); Draw.BlendMode = ShapesBlendMode.Transparent; Draw.DiscRadiusSpace = ThicknessSpace.Meters; Draw.LineThicknessSpace = ThicknessSpace.Meters; Draw.LineGeometry = LineGeometry.Flat2D; Draw.RingThicknessSpace = ThicknessSpace.Meters; Draw.LineEndCaps = LineEndCap.Round; // Drawing Draw.RingGradientRadial(Vector3.zero, fitRadius, fitRadius * 0.1f, Color.black, new Color(0, 0, 0, 0)); Draw.Disc(Vector3.zero, fitRadius, Color.black); // edge noodles const int noodCount = 64; for (int i = 0; i < noodCount; i++) { float tDir = i / ((float)noodCount); float tAng = ShapesMath.TAU * tDir; Vector2 dir = ShapesMath.AngToDir(tAng); if (Mathf.Abs(dir.y) > 0.75f) { continue; } Vector2 root = dir * fitRadius; float distToNearest = float.MaxValue; for (int j = 0; j < doots.Length; j++) { distToNearest = Mathf.Min(distToNearest, Vector2.Distance(doots[j].pos, root)); } float distMod = Mathf.InverseLerp(fitRadius * 0.5f, fitRadius * 0.1f, distToNearest); float noodMaxOffset = fitRadius * (1 + 0.1f * distMod); Draw.Line(root, dir * noodMaxOffset, fitRadius * Mathf.Lerp(0.07f, 0.04f, distMod)); } // ring Draw.Ring(Vector3.zero, fitRadius, fitRadius * 0.0125f, colMain); // connecting lines for (int i = 0; i < doots.Length; i++) { Vector2 a = doots[i].pos; for (int j = i; j < doots.Length; j++) { Vector2 b = doots[j].pos; float dist = Vector2.Distance(a, b); float rangeValue = Mathf.InverseLerp(fitRadius * 1f, fitRadius * 0.02f, dist); if (rangeValue > 0) { Color col = Color.Lerp(colFade, colMain, rangeValue); Draw.Line(a, b, fitRadius * 0.015f * rangeValue, LineEndCap.Round, col); } } } // doots~ foreach (Doot doot in doots) { Draw.BlendMode = ShapesBlendMode.Transparent; Draw.Disc(doot.pos, fitRadius * 0.025f, Color.black); Draw.Disc(doot.pos, fitRadius * 0.015f, colMain); Draw.BlendMode = ShapesBlendMode.Additive; Color innerColor = colMain; innerColor.a = 0.25f; Color outerColor = Color.clear; Draw.DiscGradientRadial(doot.pos, fitRadius * 0.18f, innerColor, outerColor); } Draw.BlendMode = ShapesBlendMode.Multiplicative; Draw.DiscGradientRadial(Vector3.zero, fitRadius * 0.5f, Color.black, Color.clear); // restore state Draw.Matrix = prevMtx; Draw.BlendMode = prevBlendMode; Draw.DiscRadiusSpace = prevDiscRadiusSpace; Draw.LineThicknessSpace = prevLineThicknessSpace; Draw.LineGeometry = prevLineGeometry; Draw.RingThicknessSpace = prevRingThicknessSpace; Draw.LineEndCaps = prevLineEndCaps; }