Smarter Collapsing

collapse stack without collapsing the Meshsmooth, Turbosmooth, UVW or Unwrap UWV modifiers while preserving instances.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
artrender.info's picture

hey, Anubis! I like your idea

hey, Anubis! I like your idea with collapsing only upper modifiers, but your script has a lot of errors!

miauu's picture

.

Fix the errors and post the result. :)

Anubis's picture

hi Daniel

Are all this modifiers on top of the stack? And there also not other kind of modifiers in-between, rihgt? If not, the final result would be unexpected, actually undesirable.

I'll presume that the modifiers you want to preserve are on top of the stack, and will post something (UNtested), and can't say is it better than Branko's idea :))

fn customCollapse force:off = if selection.count > 0 do
(
	local modClasses = filterString (
		@"TurboSmooth
		MeshSmoothMod
		MapMod
		Unwrap UVW"), "\n\t"
 
	local arrObj = #(), oldSel, modIndex, run
	local rptInstances = #(), trueInstances
 
	max create mode
	oldSel = selection as array
 
	while selection.count > 0 do
	(
		InstanceMgr.GetInstances $ &rptInstances
		trueInstances = for n in rptInstances where \
		(areNodesInstances selection[1] n) collect n
		append arrObj selection[1]
		deselect trueInstances
		deselect selection[1]
	)
 
	if force do
	(
		for obj in arrObj where \
		obj.modifiers.count == 0 do
		(
			if validModifier obj Turn_To_Mesh do
			(addModifier obj (Turn_To_Mesh());
			collapseStack obj)
		)
	)
 
	arrObj = for obj in arrObj where \
	obj.modifiers.count > 0 collect obj
 
	for obj in arrObj do
	(
		modIndex = obj.modifiers.count
		run = (modIndex > 1)
		while run do
		(
			if findItem modClasses (getClassName \
			obj.modifiers[modIndex]) == 0 then
			(modIndex -= 1) else (run = false)
			if run do run = (modIndex > 0)
		)
		modIndex += 1
		if modIndex <= obj.modifiers.count do
		maxOps.CollapseNodeTo obj modIndex off
 
		if obj.modifiers.count == 1 and \
		findItem modClasses (getClassName \
		obj.modifiers[1]) == 0 do
		collapseStack obj
	)
	select oldSel
)
 
-- Usage:
customCollapse force:on -- collapse all selected
customCollapse() -- skip selected without modifiers

my recent MAXScripts RSS (archive here)

barigazy's picture

try this

fn smartCollaps = if selection.count != 0 do
(
	max create mode
	local modClasses = #("TurboSmooth","MeshSmoothMod","MapMod","Unwrap UVW")
	local modArr = #(), ins = #()
	while selection.count > 0 do
	(
		obj = if (InstanceMgr.GetInstances selection[1] &ins) > 0 then ins[1] else selection[1]
		if (modCnt = obj.modifiers.count) > 0 do
		(
			for m = modCnt to 1 by -1 where findItem modClasses (getClassName obj.modifiers[m]) != 0 do
			(
				append modArr obj.modifiers[m] ; deleteModifier obj m
			)
			if (modCnt = obj.modifiers.count) > 0 do maxOps.CollapseNodeTo obj 1 off
			if (maCnt = modArr.count) != 0 do for c = 1 to maCnt do addModifier obj modArr[c]
			if ins.count != 0 then deselect ins else deselect obj
		)
		if ins.count != 0 then deselect ins else deselect obj
		free modArr ; free ins
	)
)

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.