Home Technical Talk

How to manipulate vertex positions of Edit Poly modifier with MaxScript?

MaxScript is strange.

Some of the more difficult or intricate tasks it pretty much does for you, and yet some of the absolute simplest tasks like modifying a vertex position is difficult or undocumented.

The Editable Mesh or Editable Poly methods don't work on the EP modifier, and I can't find anything suggesting how this is done in the MaxScript help.

I just want to write a quick randomise script, manipulating vertices, should bde very, very simple - but strangely, changing the positions of Edit Poly vertices doesn't seem that simple.

Does anyone know how it's done?

Cheers,
RumbleSushi

Replies

  • MattLichy
    Yeah, Edit_Poly and Mesh Modifier stuff is stupid. I also hate having to deal with Edit Poly and Edit Mesh types in scripts, but I do sometimes, and othertimes I just tell the user they need to use Edit Poly.

    I just came up with this, I think this is what you want


    Edit:
    (
    	local theMesh = selection[1]
    	
    	if selection.count == 1 then
    	(
    		if classof theMesh.modifiers[1] == Edit_Poly then
    		(
    			SetCommandPanelTaskMode #modify
    			subObjectLevel = 1
    			
    			for vert in (theMesh.mesh.verts as bitarray) do
    			(
    				theMesh.modifiers[#Edit_Poly].Select #Vertex #{vert}
    				theMesh.modifiers[#Edit_Poly].MoveSelection [(random -10 10),(random -10 10),(random -10 10)]
    				theMesh.modifiers[#Edit_Poly].Select #Vertex #{}
    				theMesh.modifiers[#Edit_Poly].Commit ()
    			)
    		)
    	)
    )
    
    


    Really, the best way to do this is just use an Edit Poly or Edit Mesh and use the polyop or meshop methods. Using the EditPoly Modifier takes much more time to process the verts than polyop does.
  • MattLichy
    If you run this code, its like 100x faster than using EditPoly Modifier
    (
    	local theMesh = selection[1]
    
    	if selection.count == 1 then
    	(
    		if classof theMesh == Editable_Poly then
    		(
    			for vert in (theMesh.mesh.verts as bitarray) do
    			(
    				polyop.setVert theMesh vert [((polyop.getVert theMesh vert).x) + (random -100 100),((polyop.getVert theMesh vert).y)+(random -100 100),((polyop.getVert theMesh vert).z) + (random -100 100)]
    			)
    		)
    	)
    )
    
    
  • cw
    Offline / Send Message
    cw polycounter lvl 17
    also, it's usually worth thinking if there is a max way of doing what you want, and scripting that, usually is faster for max (noise modifier for instance sounds like what you are doing somewhat?)

    good luck!
  • rumblesushi
    Thanks for the posts guys. I'll give that a try cw.

    Cheers for the code Matt, much appreciated, it looks to be exactly what I want ;)

    I had no idea that manipulating modifiers would be difficult, or any different actually. I would have thought Max would make controlling them more seamless to be honest, ie have an internal wrapper that does the business, and the user just controls them as if they were an editable poly or mesh.

    I would just convert, because honestly, I hate working with a stack. I much prefer the cleanness of constantly collapsing to edit poly.

    The thing is, I have to keep my stack, because it's a driving game course made with line and sweep, and I have to keep the line there in case I need to change the shape of various parts of the track.

    All I want this to do by the way is manipulate a selection of vertices, in this case applying a slight randomisation to a ring of vertices that represent mountain tops, to make it look a bit more natural etc.
  • MattLichy
    Yeah, or u could just try doing a noise modifier like cw said. But yeah, maxs internal workings are all over the place. THey keep v1 stuff and keep adding more and more shit and dont fix underlying problems.
  • cw
    Offline / Send Message
    cw polycounter lvl 17
    To be clear, I was angling towards the idea that rather than write your own maxscript routine to move vert positions by noise or random amount, you could write a maxscript to add noise modifier with desired properties and so on, just saves you some scripting time, and possibly execute faster as it is built in max code doing the positioning. :D

    Good luck! :)
  • rumblesushi
    As it happens, Noise does exactly what I want. I want some natural, perlin noise style randomisation. It's something I could do in my engine at runtime, but it would be more hassle than in Max.

    I didn't even think to look for a PN function in Max ;)

    And if there's anything more unique I want to do with vertex positions, I can use the code Matt posted.

    By the way I agree Matt. Max is an impressive and powerful program and in some ways MS is very easy, but very much all over the place ;)
Sign In or Register to comment.