Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Featured Threads
  inspiration alert!!!
(37 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies) Members Gallery
(516 replies)
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

Relax vertices script
show user profile  3joez
Dear fronats, how would you go in scripting a relax function for some selected vertices?

Here's my pseudo code. I'm trying to figure out the last part where you actually need to tell maxscript how much each vertex needs to be moved(or relaxed).

1. Get the selcted vertices in an array
2. Find the average position of all vertices
3. Move each vertex towards that averaged point (how? how much?)

PS. I'm not trying to use the relax modifier. I need to script the function.
read 367 times
6/19/2017 2:05:16 PM (last edit: 6/19/2017 2:05:16 PM)
show user profile  Mr.Burns
This is a very simple script that I've only tested briefly.
You can either set a fixed amount by which each selected vertex should be moved towards the center (MoveAbs) or a relative amount (MoveRel; 0.5 being 50 %). You can switch between the two by setting DoMoveAbs to true or false.

VertSel = (polyOp.getVertSelection $ ) as array
VertCenter = [0, 0, 0]
VertVec = [0, 0, 0]
MoveAbs = 10
MoveRel = 0.5
DoMoveAbs = true

if VertSel.count > 0 then
 for i = 1 to VertSel.count do
  VertCenter += (polyOp.getVert $ VertSel[i])

 VertCenter /= VertSel.count

 for i in VertSel do
  VertVec = VertCenter - polyOp.getVert $ i

  if DoMoveAbs then
   if (length VertVec) > 0.001 then
    polyOp.setVert $ i ((polyOp.getVert $ i) + MoveAbs * (normalize VertVec))
   polyOp.setVert $ i ((polyOp.getVert $ i) + MoveRel * VertVec)


read 319 times
6/21/2017 10:36:47 PM (last edit: 6/21/2017 10:39:29 PM)
show user profile  3joez
Thx MrBurns. I think though I'm looking more into something like that:

Where you actually calculate the neighbor vertices and so on...(I think Blender has this algorithm implemented).

I'm now trying to figure out the formula but if somebody has any kind of insight about interpreting that, please share :)

read 308 times
6/22/2017 12:25:40 PM (last edit: 6/22/2017 12:27:09 PM)
show user profile  ScotlandDave
I'm pretty sure this is how Subdivision algorithms generally work, they take weighted averages of surrounding points to generate a smooth mesh and interpolate those points to generate the new subdivided points/edges..

There's plenty of references around for subdiv algorithms if you want to google that - basically i'd be looking at subdivs algorithms but without subdivs part. Pixars OpenSubdivs is totally open source and available to look at, but is pretty complex in that it has a whole ecosystem of supporting classes etc etc ( and is C++) ..

Website | Blog | Contact | Vimeo

read 298 times
6/23/2017 12:41:24 AM (last edit: 6/23/2017 12:41:24 AM)
show user profile  ScotlandDave
What i think the general approach would be ( in pseudo-code ):

For each vertex:
Get all polygons the vert belongs to
Find the average of all the points in those polygons ( weight how each point contributes to that average by their distance from the vertex in question )
Store that weighted average vector position to an array

Then iterate through the array, applying each vector position you've stored to each vertex.

This way it calculates all average ( smoothed ) positions based on the source mesh, and then applies them. If you actually apply the average as you iterate through, the verts averages will take into account the newly smoothed positions, which you don't really want.

Website | Blog | Contact | Vimeo

read 298 times
6/23/2017 12:52:16 AM (last edit: 6/23/2017 12:52:16 AM)
show user profile  ScotlandDave
I couldn't resist..

This is using neighbouring polygons, but could just as easily grab the verts from all connected edges to get the average.

Works on the currently selected object ( must be Editable Poly - easy enough to do a conversion if necessary ):

Download Script:

function getAverage vertID =
-- Iterate through all polies ( faces ) connected to this vert, and for each poly, iterate through all of its verts, adding each vert position to
-- an array. At the end, run through the array, add all the positions together, then divide by array count to get average position.

faceVertPositions = #()

for f = 1 to ($.GetVertexFaceCount vertID) do
-- Get Each Face that uses this Vert..
faceID = $.GetVertexFace vertID f
faceVertCount = $.GetFaceDegree faceID

for fv = 1 to (faceVertCount) do
-- Get Each Vert from this Face and add it's position to the Array..
faceVertID = $.GetFaceVertex faceID fv
append faceVertPositions ($.GetVertex faceVertID)

-- Add all the stored positions together..
vertPos = [0,0,0]
for pos in faceVertPositions do
vertPos += pos

-- Return the average position..
return vertPos / faceVertPositions.count


function IterateVerts =
numVerts = $.GetNumVertices()
smoothVertPositionsArray = #()

in coordsys local --use local object space
-- Loop through all points and get the smooth averaged position
for i = 1 to numVerts do
append smoothVertPositionsArray (getAverage i)

-- Loop through all points and apply the stored smooth averaged positions
for i = 1 to numVerts do
polyOp.SetVert $ i smoothVertPositionsArray[i]



Website | Blog | Contact | Vimeo

read 291 times
6/23/2017 12:41:33 PM (last edit: 6/23/2017 12:43:39 PM)
show user profile  Garp
Funny way:

read 287 times
6/23/2017 1:38:57 PM (last edit: 6/23/2017 1:39:35 PM)
show user profile  3joez
Thx guys. Let me study a bit the thing.
read 265 times
6/26/2017 10:37:40 AM (last edit: 6/26/2017 10:37:40 AM)
#Maxforums IRC
Open chat window