Home Technical Talk

MaxScript: How to Mold a Road to a Hill

Hello,

I'm using MaxScript for a uni module and my idea to create a scene generator. I'm keeping it simple for now and sticking with just a hilly scene.

I have managed to create a road using a box, a line and an extrude along spline function. What I need the road to do now is mold to the hilly scene. How would I go about doing this?

I have found some code that causes teapots to stick to each face on a plane, I was wondering if I would use something similar?
obj = $Plane001
converttopoly obj
for i = 1 to (polyop.getnumfaces obj) do
(
tp = teapot radius:3 pos:((polyop.getfacecenter obj i)+[0,0,10]) name: (uniquename (obj.name + "_tp")) segs:1
tp.material = meditmaterials[1]
)
converttomesh obj
for i in (execute ("$" + (obj.name + "_tp") + "*")) do
(
r = ray i.pos [0,0,-1]
fid = (intersectrayex obj r)[2] - 1
bc = (intersectrayex obj r)[3]
controller = attachment()
controller.node = obj
i.pos.controller = controller
addnewkey i.pos.controller 0f
k = attachctrl.getkey i.pos.controller 1
k.face = fid
k.coord = bc
)

Thanks

Replies

  • Eric Chadwick
    These old scripts might give you some ideas. http://www.cnc-toolkit.com/maxscript.html
  • Quickwits92
    Aha, thank you but I managed to find something.

    My problem with it though is that it only moves one of my trees to the floor because ti requires the tree to be selected. I am importing the trees using xreferencing in a loop so it will make x number of trees. The problem is, when I tell it to select xrefTree, it will only select the one tree.

    Any ideas?

    Thanks
  • Quickwits92
    Okay, I have sorted out the tree problem now. My next issue is trying to do something similar with the road. Here is the code that makes the trees align to the plane.
    fn find_intersection z_plane objects_to_z =
    (
    local r = ray objects_to_z.pos[0,0,-1]
    local nodeMaxZ = z_plane.max.z
    r.pos.z = nodeMaxZ+0.0001* abs nodeMaxZ
    intersectRay z_plane r
    )

    for i in selection do
    (
    int_point = find_intersection $Plane001 i
    if int_point != undefined then i.pos = int_point.pos
    )

    I need to find some way of making the road do this. I think it lies in using this kinda of code on the all the vertex in the shape.

    Thanks
Sign In or Register to comment.