Notifications
Clear all

[Closed] Moving Editpoly Faces in Local Space?

Hi, I’m pretty new to MaxScript and I’m just trying to figure some things out. I’m stuck on just trying to figure out how to do local translations with faces. I can get the faces to move in local space, but when I have a number of faces selected, the coordsys seems to move the faces along an average of all the face normals. What I really want is to get the same effect when you do a face extrude with the local normal option turned on. Here’s what I have so far, any help would be much appreciated.

fn moveFacesLocal obj =
      (
   	   local currentFaceNormal
   	   local currentFaceVerts
   	   local extrudeValue = [0,0,5.0]
   	   
   	   for i in obj.selectedFaces do
   	   (
   		   currentFaceNormal = polyop.getFaceNormal obj (i.index)		   
   		   currentFaceVerts = polyop.getVertsUsingFace obj obj.selectedFaces
   		   
   		   in coordsys (MatrixFromNormal (currentFaceNormal)) polyop.moveVert obj currentFaceVerts extrudeValue
   	   )
      )
      
   moveFacesLocal($)
2 Replies

Hi Jared,
in your code there are a couple of issues. The first is you don’t need to disturb matrices to perform a normal shift, because you already got the shift direction as face normal and need to specify only the amount. The second is when you have to rely on data from the current object, you shoud take them all before altering it. In your case, you where applying the shift to each vert multiple times in unpredictable directions, one for each face sharing the vert modified by previous vert shift. Finally what you need to perform the move in local are not the face normals, but the verts normal, and in the following code are calculated as the average of neighbour face normals.

function moveFacesLocal oPoly fHeight =
(
    if (classOf oPoly) != Editable_Poly do
        throw "Wrong input in function moveFacesLocal()"

    -- get current face selection
    local baFaceSel = polyOp.getFaceSelection oPoly

    -- stores normals of all faces in the edit poly
    -- because they will be accesed more than once each
    local iNumFaces = polyOp.getNumFaces oPoly
    local ap3FaceNormals = for i = 1 to iNumFaces collect (polyOp.getFaceNormal oPoly i)

    -- get verts correspondinge to current face selection
    local baVertSel = polyOp.getVertsUsingFace oPoly baFaceSel

    -- define a stroage for vert shift vectors
    local ap3VertSelShift = #()
    
    -- define a store for faces sharing each vert
    local baVertFaces #{}
    
    -- define a temporary variable to hold each vert shift value
    local p3VertNormal = [0,0,0]

    -- loop to build the array of shift vectors
    for iVert in baVertSel do
    (
        baVertFaces = polyOp.getFacesUsingVert oPoly iVert
        p3VertNormal = [0,0,0]

        -- get vert normal as the average of faces normal sharing the vert
        for iFace in baVertFaces do
        (
            p3VertNormal += ap3FaceNormals[iFace]
        )
        p3VertNormal /= baVertFaces.numberSet

        -- append the vert shift normal to the array of vectors
        -- multiplied by the provided height amount
        append ap3VertSelShift (p3VertNormal * fHeight)
    )
    -- perform the shift of all verts at once
    polyOp.moveVert oPoly baVertSel ap3VertSelShift
)

moveFacesLocal selection[1] 10
  • Enrico

That’s awesome, thank you so much