Condence material ID, bitmaps and material IDs

I have a multi-subobject material with nearly 500 sub-objects. most of the slots are the same exact bitmap. is there a way to get rid of the materials with duplicated bitmaps? also is there a way to change material IDs of the model to match the new reduced Multi-subobject?
I have a feeling I seen a script like this somewhere, but can not remember what it was called.

Comments

Comment viewing options

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

Almost there !

How about the model Material ID side of things ? any way to update the Model's IDs so that they point to the same bitmap that they had before the script?

barigazy's picture

...

Method that I posted is 30% accurate. I only filter bitmaps in diffuse map slot and submats names. There are many options that should be checked before you sets model's ID. Problem with model will be if it have different Id's then multimaterial. Also comparation of materials and maps (procedural and bitmaps) is quite complex. If you are looking more then 80% accuracy that tool will be probably commercial. Mayby someone else can you help with that.

bga

tuxmask75's picture

Thanks !

I appreciate the hard work, Now for a commercial tool that does this, anyone know of one off the top of there head?

barigazy's picture

...

First you need to answer on some questions:
1. Submaterials are ??? Standardmaterial, VrayMtl, Arch&Design
2. You want to exclude all mtls with same bitmap in which slot? Diffuse, Bump etc.
3. If duplicate submaterials are also used in the scene then what?

bga

tuxmask75's picture

hmm..

1 Standard materials
2: diffuse
3: condense them as well, and then also change material ID's to match the bitmap materials. ( if material ID 1,2, and 200 use a same bitmaps, than all material IDs 1 2 and 200 on the model will become whatever ID that the new Condensed material has set up for that ID/bitmap.
( err unless there is a better way to do this)

barigazy's picture

...

I did not tested this but you can try on material in active material editor slot.
Pick one multimaterial and run this code

fn condenseMmat mmat =
(
	if isKindof mmat Multimaterial do
	(
		local newMtlList = #(), newMtlNames = #()
		for m in 1 to mmat.materialList.count where isKindOf (mmat.materialList)[m] Standardmaterial do
		(
			curMtl = (mmat.materialList)[m] 
			if newMtlList.count == 0 then 
			(
				append newMtlList curMtl 
				if (isKindOf curMtl.DiffuseMap BitmapTex) then append newMtlNames curMtl.DiffuseMap.filename else append newMtlNames curMtl.name
			)
			else
			(
				idx = if (isKindOf curMtl.DiffuseMap BitmapTex) then findItem newMtlNames curMtl.DiffuseMap.filename else findItem newMtlNames curMtl.name
				if idx == 0 do
				(
					append newMtlList curMtl 
					if (isKindOf curMtl.DiffuseMap BitmapTex) then append newMtlNames curMtl.DiffuseMap.filename else append newMtlNames curMtl.name
				)					
			)
		)
		mmat.materialList = newMtlList ; free newMtlNames ; free newMtlList --; mmat.materialIDList = (#{1..newMtlList.count} as array)
	) ; mmat
)
condenseMmat meditMaterials[activeMeditSlot]

bga

barigazy's picture

...optimized version

fn condenseMmat mmat = if isKindof mmat Multimaterial do
(
	local newMtlList = #(), newMtlNames = #()
	for m in 1 to mmat.materialList.count where isKindOf (mmat.materialList)[m] Standardmaterial do
	(
		curMtl = (mmat.materialList)[m] ; collectMtl = false
		collectMtl = if newMtlList.count == 0 then true else 
		(
			if (isKindOf curMtl.DiffuseMap BitmapTex) then (findItem newMtlNames curMtl.DiffuseMap.filename) == 0 else (findItem newMtlNames curMtl.name) == 0
		)
		if collectMtl do
		(
			append newMtlList curMtl 
			if (isKindOf curMtl.DiffuseMap BitmapTex) then append newMtlNames curMtl.DiffuseMap.filename else append newMtlNames curMtl.name
		)
	) ; mmat.materialList = newMtlList ; free newMtlNames ; free newMtlList ; mmat
)
condenseMmat meditMaterials[activeMeditSlot]

bga

Comment viewing options

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