[Closed] Four lines to create a grid,by script,could be done?
See the picture please*^_^*
So,is there a way to done it like that by maxscript?
Thank you!
Yes, you can do it in Max, manually or with MaxScript.
- Create your 4 segments shape.
- Add a Surface modifier.
- Add an EditPoly modifier.
I realized it might not work in all cases, depending on the shapes.
So, here is a little utility that will hopefully create the surface you need.
Pick up your 4 shapes and the click on Build Shape. If the surface is distorted try reversing the shapes (R button). This process can be automated if you would like.
try (destroydialog ::RO_SPLINES_SURFACE) catch()
rollout RO_SPLINES_SURFACE "Spline Surface" width:196 height:240
(
fn FilterShapes obj =
(
superclassof obj == shape and isproperty obj "numsplines" and obj.numsplines == 1
)
label lbl1 "Top:" pos:[8,16] width:48
label lbl2 "Bottom:" pos:[8,48] width:48
label lbl3 "Left:" pos:[8,80] width:48
label lbl4 "Right:" pos:[8,112] width:48
pickbutton bt1 "Top" pos:[56, 8] width:96 height:32 autoDisplay:on filter:FilterShapes
pickbutton bt2 "Bottom" pos:[56, 40] width:96 height:32 autoDisplay:on filter:FilterShapes
pickbutton bt3 "Left" pos:[56, 72] width:96 height:32 autoDisplay:on filter:FilterShapes
pickbutton bt4 "Right" pos:[56,104] width:96 height:32 autoDisplay:on filter:FilterShapes
button bt1r "R" pos:[156, 8] width:32 height:32
button bt2r "R" pos:[156, 40] width:32 height:32
button bt3r "R" pos:[156, 72] width:32 height:32
button bt4r "R" pos:[156,104] width:32 height:32
groupBox grp1 "Subdivisions:" pos:[8,144] width:180 height:48
spinner spn1 "Width:" pos:[ 16,164] fieldwidth:34 range:[4,100,10] type:#integer
spinner spn2 "Height:" pos:[100,164] fieldwidth:34 range:[4,100,10] type:#integer
button bt_build "Build Surface" pos:[8,200] width:180 height:32
local surf
fn BuildSurface =
(
top = bt1.object
bottom = bt2.object
left = bt3.object
right = bt4.object
if top == undefined do return messagebox "Invalid Top Shape"
if left == undefined do return messagebox "Invalid Left Shape"
if bottom == undefined do return messagebox "Invalid Bottom Shape"
if right == undefined do return messagebox "Invalid Right Shape"
sx = spn1.value
sy = spn2.value
topPos = for j = 0. to 1. by (1./sx) collect lengthInterp top 1 j
bottomPos = for j = 0. to 1. by (1./sx) collect lengthInterp bottom 1 j
leftPos = for j = 0. to 1. by (1./sy) collect lengthInterp left 1 j
rightPos = for j = 0. to 1. by (1./sy) collect lengthInterp right 1 j
_left = for j = 1 to ((sx+1)*(sy+1)) by (sx+1) collect j
_right = for j = (sx+1) to ((sx+1)*(sy+1)) by (sx+1) collect j
_top = for j = (((sx+1)*sy)+1) to (((sx+1)*sy)+1+sx) collect j
_bottom = for j = 1 to (sx+1) collect j
undo off
(
if surf != undefined and not isdeleted surf do delete surf
surf = converttopoly (plane width:sx length:sy widthsegs:sx lengthsegs:sy wirecolor:[150,220,50])
for j = 1 to topPos.count do polyop.setvert surf _top[j] topPos[j]
for j = 1 to leftPos.count do polyop.setvert surf _left[j] leftPos[j]
for j = 1 to bottomPos.count do polyop.setvert surf _bottom[j] bottomPos[j]
for j = 1 to rightPos.count do polyop.setvert surf _right[j] rightPos[j]
surf.relaxAmount = 1
surf.relaxIterations = sx*sy*10
surf.editablepoly.relax()
)
)
fn ReverseShape mShape =
(
reverse mShape 1
updateshape mShape
BuildSurface()
)
on bt_build pressed do BuildSurface()
on bt1r pressed do if bt1.object != undefined do ReverseShape bt1.object
on bt2r pressed do if bt2.object != undefined do ReverseShape bt2.object
on bt3r pressed do if bt3.object != undefined do ReverseShape bt3.object
on bt4r pressed do if bt4.object != undefined do ReverseShape bt4.object
)
createdialog RO_SPLINES_SURFACE
EDIT1: Code improvements
If i do this:
…
–surf.relaxAmount = 1
–surf.relaxIterations = sxsy10
–surf.editablepoly.relax()
…
Can we get a algorithm about directly calculate the vertexs x,y,z just like do with surf.editablepoly.relax() ?
Special thanks to PolyTools3D!
Thanks guys!
The relax algorithm is very straightforward:
For each iteration, set each vertex position to the average of its neighbors (edge connected).
If you want to avoid the outer vertices, just don’t modify their position.