Multisub material Collapsed ID's

Hey all

I have got a 700 ID multisub that I can clean up to about 50 materials but the ID numbers persist and is used in the scene. I need all ID numbers to be lower than ID 99 to be able to use it in Unreal Engine.
I hope to have ID 1-50 in the end in stead of ID 1,14,57,201,453,etc,etc. and that the scene can match it.
Does a script exist that can change all material ID's in the scene so they can match newly changed ID of the Multisub material?
This is not something I am going to do only once, the plan is to automate the process so I can do it again and again.

Hope you understand my question.
I use 3ds max 2017

Jakob

Comments

Comment viewing options

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

Multisub material Collapsed ID's

Thank you for your answer.
I am aware that it is alot of work. I did some manual work on this. I wrote down all 57 sub ID numbers and what it was (id 336 concrete, etc, etc) and next to it, the new comparison number. selected all geometry and put an instanced edit poly on them. And then selected all of one ID and converted it to the new ID numbers. It took two hours for the entire scene.

jahman's picture

.

Haven't seen such script yet.
Are you aware of the fact that you'll have to change all objects face materials IDs to match new condensed multi-material's ids? It can be a tough task, depending on your scene complexity and objects modifier stack.

-- select any poly object with applied multimaterial
 
-- select and clean multi-material of selected object
Clean_MultiMaterial.MMCleanActions.CleanMaterailsAll()
 
struct MtlID ( mtl, oldID, newID )
 
mtl = $.material
mtls = mtl.materialList
newMultiMtlState = for i=1 to mtl.materialList.count where mtls[i] != undefined collect 
(
	oldMtlID = mtl.materialIDList[i]
	newMtlID = i
 
	mtl.materialIDList[i] = newMtlID
 
	-- collect MtlID struct
	MtlID mtl:mtls[i] oldID:oldMtlID newID:newMtlID
)
 
 
-- change objects face-material-IDs
-- works with collapsed poly objects only
for item in newMultiMtlState where item.oldID != item.newID do
(
	-- find all nodes that are dependent of this material
	nodes = refs.dependentNodes item.mtl
        nodes = makeUniqueArray nodes
 
	for n in nodes do
	(
		affected_faces = #{}
 
		-- if face material id is equal to previous mtl ID then add this face to affected
		for f=1 to polyop.getNumFaces n where polyop.getFaceMatID n f == item.oldID do affected_faces[f] = true
 
		-- set new mtl ID to all affected faces at once
		polyop.setFaceMatID n affected_faces item.newID
 
	)
 
)

Comment viewing options

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