Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography



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.
Photobucket

read 73 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))
  )
  else
   polyOp.setVert $ i ((polyOp.getVert $ i) + MoveRel * VertVec)
  )

 forceCompleteRedraw
)

read 25 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:
https://en.wikipedia.org/wiki/Laplacian_smoothing

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 :)


Photobucket

read 14 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 4 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 4 times
6/23/2017 12:52:16 AM (last edit: 6/23/2017 12:52:16 AM)
#Maxforums IRC
Open chat window


Support Maxforums.org