Yes, I think this should do the trick:
Not as smooth as Rhino, though, it will jump around a bit when snapping. Set the number of sides before you start drag-creating it, it will only respect the picked direction on creation, not when changing the params later on.
-- visit My webSite at: www.aslan3d.com
-- contact with my by: aslan.tamjidi@gmail.com
plugin shape NGonExt
name:"NGonExt" category:"Splines" replaceUI:on
extends:NGon classID:#(0x117e72e, 0x5ba1ec54)
usePBValidity:on
(
fn getRot vec =
(
local rot = atan2 vec.x vec.y
if rot > 0 then rot else 360d0 + rot
)
fn updateRadius = this.radius =
0.5d0 * this.edgeLength / (if this.type == 1 then tan else sin) (180d0 / this.sides)
fn updateEdgeLength =
(
disableRefMsgs()
this.params.spnEdgeLength.value =
2 * this.radius * (if this.type == 1 then tan else sin) (180d0 / this.sides)
enableRefMsgs()
)
parameters main rollout:params
(
radius type:#worldUnits default:0 ui:spnRadius
type type:#integer default:2 ui:rbType
sides type:#integer default:5 ui:spnSides
edgeLength type:#worldunits ui:spnEdgeLength
cornerRad type:#worldunits default:0 ui:spnCornerRadius
circular type:#boolean default:off ui:chxCircular
on edgeLength set val do updateRadius()
on sides set val do (delegate.nSides = val; updateRadius())
on type set index do (delegate.scribe = index - 1; updateRadius())
on radius set val do (delegate.radius = val; updateEdgeLength())
on cornerRad set val do delegate.cornerRadius = val
on circular set state do delegate.circular = state
)
rollout params "NGon by Aslan3D.com" width:150
(
spinner spnRadius "Radius: " range:[0,1e6,10] type:#worldunits fieldWidth:70
radioButtons rbType labels:#("Inscribed", "Circumscribed") columns:2 offsets:#([2, 0], [-10, 0]) default:2
spinner spnSides "Sides: " range:[3,100,6] type:#integer fieldWidth:70
spinner spnEdgeLength "Edge Length: " range:[0,1e6,10] type:#worldunits fieldWidth:70
spinner spnCornerRadius "Corner radius: " range:[0,1e6,0] type:#worldunits fieldWidth:70
checkBox chxCircular "Circular" checked:off align:#center
)
tool create numPoints:2
(
local startPos, invTM, zDir, angle, vec
local targetPos, dist, roet
on mousePoint click do if click == 1 do
(
zDir = nodeTM.row3
angle = 90 - 180d0 / sides
invTM = inverseHighPrecision nodeTM
startPos = nodeTM.translation = worldPoint
)
on mouseMove click do if click == 2 do
(
vec = worldPoint - startPos
dist = .5 * length vec * tan angle
edgeLength = (gridDist.x^2 + gridDist.y^2)^.5
targetPos = startPos + vec / 2 + dist * cross zDir (normalize vec)
rot = getRot (normalize (targetPos * invTM - startPos * invTM)) + 90
nodeTM = angleAxis rot zDir as matrix3 * transMatrix targetPos
)
)
)