Notifications
Clear all

[Closed] Welding Texture Verts via MaxScript

I am attempting to use a script to weld the texture verts of all selected editable meshes in a scene. Assuming this is how it should be done. Step thru each selected mesh, apply an Unwrap_UVW modifier, select all texture verts, weld selected, collapse stack.

I can step thru each selected mesh, apply the modifier, but I am having problems selecting the texture verts. No matter what I have tried, nothing seems to work.

Can anyone help me out on this.

Thanks

9 Replies

here is the script function
should work.
but its rather slow due the fact u cant weld the vertices directly.
you have to open the uvw edit floater to press the weld selected via script.
maybe someone else got a better and faster script. but this should work at least g

function WeldTVVertices obj =
(
select obj
objUnwrapMod = Unwrap_UVW()
addModifier obj objUnwrapMod

   objUnwrap1=objUnwrapMod.unwrap
   objUnwrap2=objUnwrapMod.unwrap2
          
  -- weld all TV vertices
  objUnwrap1.edit()                     -------------opens the UW Edit Floater SLOW :(
  subObjectLevel = 1
  max select all
  objUnwrap1.setWeldThreshold 0.01
  objUnwrap1.weldSelected()          -----------presses the weld selected button

collapseStack obj
)

Thank you Snoelk.

Since I posted, I actually came to the same conclusion with the help of the listener and some well placed breakpoints in my script. I was still having a problem however and was going to post my script and my new problem. Everything worked fine in the listener, but in my script the UVW Edit dialog would never open, thus the tverts would never get selected or welded.

Your script does the trick. And yes, you are right, its SLOW especially when you have 80+ meshes in a collection you are attempting to do this to.

Its workable, but to lighten the load does anyone have a quick way to determine if two tverts are within the weld threshold. That would allow me to skip meshes where this isn’t needed.

Thanks again Snoelk,

BTW, why the objUnwrap2? I don’t see it used in your script, and when I left out, the script still works as expected. Just curious.

ooops its a part of a script of mine. and as i dont want to write down everytime all the uvw stuff i create same vars with all uv stuff

objUnwrap1=objUnwrapMod.unwrap
objUnwrap2=objUnwrapMod.unwrap2
objUnwrap5=objUnwrapMod.unwrap5

didnt checked and killed unused stuff. thats why ^^

for the other problem you have to create a array of all vertives (points3) and bitarray of them.
check the distance between them. if the distance between them then is lower then threshold remove from the bitarray list.
then select the verts with bitarray and weld
but its complicated.
dont know if its faster. the uv edit kills all performance. and to run through all verts wont make it faster i think.

did a smal script comparing point3 coords for the uv weld selection.
for small meshes its ok. but its sluggish. if the vertex count is to large its faster to select all and weld via button g
this function should be made via plugin an c++. everything else is to slow.

on my 400k vert levelmesh it took forever ^^

Okay, I’ve run into another issue.

I start Max, load my model, run the script… Nothing happens.

However, if I start Max, load my model, apply an Unwrap_UVW modifier and open the UVW Edit dialog, close the dialog, delete the modifier, run the script… Works fine.

:curious:
What would cause the edit dialog to not open during the script, unless I manually make it happen prior to running the script?

Oh, and since I am working with relatively small amounts of UV coordinates, I did write in a check which seems to speed the process up a bit.

Thanks,

whats your script look like.
did run in an equal case too.
forgot to assign a variable at start.
after the first run it knows and then it works.
or some variables are overwrite themself.

btw
looked into the source code in the sdk.
as i read, that the published functions of uvwunwrap, within the source code, also only presses the button in the dialog and THEN welds the verts i had to laugh rofl

1 Reply
(@michaeldarkangel)
Joined: 11 months ago

Posts: 0

Ah, so I’m missing a variable somewhere. Well aside from different naming and the check, this part of the script looks exactly like yours .


tVerts = node.numtverts
doWeld = 0
			
for doOnce = 1 to (tVerts - 1) do (
			
	for doAgain = (doOnce + 1) to tVerts do (
				
		if ((getTVert node doOnce) == (getTVert node doAgain)) then (
					
			doWeld = 1
						
		)
					
		if doWeld == 1 then exit
					
	)
				
	if doWeld == 1 then exit
				
)
			
if doWeld == 1 then (
			
	select node
	uvwUnwrap = Unwrap_UVW()
	addmodifier node uvwUnwrap
	nodeUnwrap = uvwUnwrap.unwrap
	nodeUnwrap.edit()
	subObjectLevel = 1
	max select all
	nodeUnwrap.setWeldThreshold 0.01
	nodeUnwrap.weldSelected()
				
	format "Tverts Welded in %
" node.name
				
	collapseStack node
	clearSelection()
				
)

So what variable do I need to set? Should I set uvwUnwrap, or nodeUnwrap, or both when initializing my script? Gonna try and see what happens :hmm:

So, is this telling me it’s a known issue :rolleyes:

Oh well,

pimped your script a little bit ^^
you can select multiple objects now and i tested it with new created objects.
no problems so far.
try if its working in your case
dont know for sure what was wrong with your script. maybe this node thing. dont know for sure. you didnt inserted a real selection for the script.


currentSelection = getCurrentSelection()
IsLegal = true
currentSelectionCount = currentSelection.count

if currentSelectionCount == 0 do
			(
				messageBox "No object selected" title:"Warning!"
				IsLegal = false
			)

			
for i = 1 to currentSelectionCount while isLegal do
			(
			CurrentObject = currentSelection[i]
			tVerts = CurrentObject.numtverts
			doWeld = true
			
			for doOnce = 1 to (tVerts - 1) while doWeld do 
					(						
					for doAgain = (doOnce + 1) to tVerts while doWeld do
							(
							if ((getTVert CurrentObject doOnce) == (getTVert CurrentObject doAgain)) do
									(								
									doWeld = false								
									)
							)							
					)
						
			if doWeld == false then 
					(						
					select CurrentObject
					uvwUnwrap = Unwrap_UVW()
					addmodifier CurrentObject uvwUnwrap
					nodeUnwrap = uvwUnwrap.unwrap
					nodeUnwrap.edit()
					subObjectLevel = 1
					max select all
					nodeUnwrap.setWeldThreshold 0.01
					nodeUnwrap.weldSelected()
								
					format "Tverts Welded in %
" CurrentObject.name
								
					collapseStack CurrentObject
					clearSelection()							
					)
			)

1 Reply
(@michaeldarkangel)
Joined: 11 months ago

Posts: 0

Well node is actually defined a lot earlier in the script and is one mesh in the collection. I basically just cut and pasted the area where I’m having the issue.

One other thing I have noted but as yet haven’t tested thoroughly. If I do not have the Modify Panel open/selected, the UVW Edit dialog doesn’t open and the blah, blah, blah…

Okay, while I was writing this I also tested something.

I put “max modify mode” at the beginning of that section of the script and now it runs every time.

I still have the issue of “Unknown Property in Undefined” error on the initial run from a fresh start. The script in question doesn’t like the checkboxes in a rollout from another script. But I’ll figure a way around that, and then all will be well with the world :love:

[edit]
Yay!!! :bounce: Finally figured it out. May not seem like it took very long, but the initial run crash error is something that has been a thorn in my side with every script involving a rollout that I’ve made.

To solve, I assigned a global variable named the same as the rollout in the declaration section of my script. Don’t know if it’s the right way to do it, but it works.

[/edit]

Thanks again Snoelk, you’ve been a big help :applause: