[Closed] Make planar spline verts?
Is there a way/script that allows you to make the spline verts planar?
you can’t do it with the scale tool,
i did notice that there were some mirroring tools in the spline object rollout, haven’t used them though.
would be nice and quick for me if they could
this is not a problem… just needs to know the plane parameters. but the question is – what do you want to do with in and out tangents? simply project them to the same plane?
Took this from the help. It was wrapped up in extra coolness that made it “not work”. Rather than figure out how to make it work (ongoing annoyance with maxscript, the various contexts code can not run in) I stripped stuff out. Seems to work for some simple test cases. Drag and drop from script editor to a button.
new_z = $.pos.z
for s = 1 to (numSplines $) do
(
for k = 1 to (numKnots $ s) do
(
knt = getKnotPoint $ s k
in_vec = getInVec $ s k
out_vec = getOutVec $ s k
knt.z = in_vec.z = out_vec.z = new_z
setInVec $ s k in_vec
setOutVec $ s k out_vec
setKnotPoint $ s k knt
)–end k loop
)–end s loop
updateshape $
hey guys, thanks for the replies, very happy to see its doable.
as far as the tangents, i just need the planar for the default ‘corner’ tangent, then once aligned i’ll change the tangent types.
gruhn:
it works, but it flattens the whole spline,
what i was looking for was selecting to points on a spline, and say im in Top view, wanting the two points (out of a spline with 10 points) to be lined up in a specific axis, such as Y.
so the other points wouldn’t be affected, regardless of their world position. instead of making the entire spline planar.
edit: i forgot to mention that it does not seem that you can ‘undo’ your script operation. not a big deal really, just thought i’d throw that in there
thanks for the help
bumpity bump
would pay for a script that could do this, 20 bones to u if u build it they will come.
how much are you ready to pay your dentist per hour? or a lower? or a plumber? probably you can easy pay them a hundred bucks per hour.
but are you really ready to pay $800 to someone who can make your script? does it sound too much? why? just a day of work…
http://remusjuncu.com/phone/files/planarKnots.mse
done… but it will close the dialog after each run :wavey:
@denisT
😮 $800 :bounce:
what is the reason to hide the code if it doesn’t make you money anyway?
try(destroydialog planarPoints) catch()
rollout planarPoints "Planar Points by denisT" width:200
(
radiobuttons type_rb "Projection Axis:" labels:#("X", "Y", "Z", "View") default:3 columns:4 align:#left offset:[0,-3]
checkbox selected_ch "Selected Points" checked:off offset:[0,4]
checkbox tangents_ch "Include Tangents" checked:on offset:[0,0]
checkbox average_ch "Average Position" checked:on
button planar_bt "Planar" width:190 offset:[0,4]
fn makePlane pos:[0,0,0] =
(
case type_rb.state of
(
0: ray pos x_axis
1: ray pos y_axis
2: ray pos z_axis
4: ray pos (normalize (inverse (getViewTM()))[3])
default: ray pos z_axis
)
)
fn averageShapePointPos sp selected:off = if iskindof sp SplineShape do
(
pos = [0,0,0]
count = 0
for c=1 to numsplines sp do
(
knots = if selected then getKnotSelection sp c else #{1..numknots sp c} as array
count += knots.count
for k in knots do pos += getKnotPoint sp c k
)
pos/count
)
mapped fn planarShapePoints sp includeTangents:on selected:off planeAxis:(ray [0,0,0] [0,0,1]) = if iskindof sp SplineShape do
(
fn planar p tm =
(
p *= inverse tm
p.z = 0
p * tm
)
converttosplineshape sp
tm = translate (matrixfromnormal planeAxis.dir) planeAxis.pos
for c=1 to numsplines sp do
(
knots = if selected then getKnotSelection sp c else #{1..numknots sp c} as array
for k in knots do
(
setKnotPoint sp c k (planar (getKnotPoint sp c k) tm)
if includeTangents do
(
setInVec sp c k (planar (getInVec sp c k) tm)
setOutVec sp c k (planar (getOutVec sp c k) tm)
)
)
)
updateshape sp
)
on planar_bt pressed do undo "Planar Knots" on
(
sps = for node in getCurrentSelection() where iskindof node SplineShape collect node
if sps.count > 0 do
(
suspendediting()
pos = [0,0,0]
if average_ch.state do
(
for sp in sps do pos += averageShapePointPos sp selected:selected_ch.state
pos/sps.count
)
axis = makePlane pos:pos
planarShapePoints sps includeTangents:tangents_ch.state selected:selected_ch.state planeAxis:axis
resumeediting()
)
)
)
createdialog planarPoints
Old habit i guess
global planarKnots
try destroyDialog planarKnots catch ()
rollout planarKnots "PlanarKnots" width:179 height:82 (
checkButton average_ckb "Average Axis" pos:[4,4] width:84 height:18 checked:true
spinner pos_spn "" pos:[89,5] width:84 height:16 range:[-1e9,1e9,0] type:#worldunits scale:0.1 enabled:false
radioButtons axis_rdo "" pos:[4,25] width:178 height:16 labels:#("view", "x", "y", "z") columns:4
button planar_btn "Make Planar Knots" pos:[4,45] width:170 height:19
hyperlink remusjuncu "remusjuncu.com/" pos:[18,65] address:"http://remusjuncu.com/" visitedColor:(color 0 0 245)
hyperlink rappatools3 "rappatools3" pos:[105,65] address:"http://remusjuncu.com/rappatools/" visitedColor:(color 0 0 245)
fn planarSplineKnots obj:selection[1] objMod:(Modpanel.getcurrentObject()) selLevel:subobjectlevel = if classOf objMod == Line or classOf objMod == SplineShape then with undo "planarKnots" on try (
local vAxis = case ::planarKnots.axis_rdo.state of (
1: (
local camdir = (Inverse(getViewTM())).row3
local dirs = #(acos (dot camdir [1,0,0]), acos (dot camdir [-1,0,0]), acos (dot camdir [0,1,0]), acos (dot camdir [0,-1,0]), acos (dot camdir [0,0,1]), acos (dot camdir [0,0,-1]))
local axisA = #(1, 1, 2, 2, 3, 3)
local thisOne = finditem dirs (amin dirs)
axisA[thisOne]
)
2: 1
3: 2
4: 3
)
local selKnots = #()
struct kPoint (indx, p, s, i, o)
for s = 1 to numsplines obj do for v in getknotselection obj s do append selKnots (kPoint indx:v p:(getknotpoint obj s v) s:s i:(getInVec obj s v) o:(getOutVec obj s v))
if selKnots.count != 0 then (
local theCenter = case planarKnots.average_ckb.checked of (
true: (
centerP3 = [0,0,0]
for i in selKnots do centerP3 += i.p
centerP3 / selKnots.count
)
false: [::planarKnots.pos_spn.value, ::planarKnots.pos_spn.value, ::planarKnots.pos_spn.value]
)
case vAxis of (
1: for i in selKnots do ( i.p.x = theCenter.x ; setKnotPoint obj i.s i.indx i.p )
2: for i in selKnots do ( i.p.y = theCenter.y ; setKnotPoint obj i.s i.indx i.p )
3: for i in selKnots do ( i.p.z = theCenter.z ; setKnotPoint obj i.s i.indx i.p )
)
)
updateShape obj
) Catch ()
on planar_btn pressed do planarSplineKnots()
on average_ckb changed state do ( pos_spn.enabled = not state )
)
createDialog planarKnots style:#(#style_SysMenu, #style_ToolWindow)
well, at least i get a happy ending after all the drama,
rappy i bought your rappatools, pm if you not happy with that, will work something more out