Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Converting Physical Materials inside multi/sub-object to Standard Legacy

Converting Physical Materials inside multi/sub-object to Standard Legacy

cadcajun
Participant Participant
269 Views
5 Replies
Message 1 of 6

Converting Physical Materials inside multi/sub-object to Standard Legacy

cadcajun
Participant
Participant

Hi,

I have a particularly specific problem where I need to convert several Multi/Sub-object materials that contain only Physical Materials to versions that use Standard (Legacy) materials. I've found a few scripts that can do this when the Physical Materials are directly assigned to an object, but they don't work with Multi/Subs. I only need the diffuse channel to be mapped between Physical and Standard. I've attached a screenshot and a demo scene of what I'm trying to accomplish. 

example.png

Here's the original script I found:

-- Credit to dmitriy.shpilevoy on Autodesk Fourms for this!
-- https://forums.autodesk.com/t5/3ds-max-programming-forum/simple-physical-to-standard-legacy-material-converter/td-p/10173340#M5535
for physMat in scenematerials where (classOf physMat == PhysicalMaterial) do (
    stnMat = standardMaterial name:(physMat.name)
    stnMat.diffuse = physMat.base_color
    stnMat.adLock = false
    stnMat.ambient = (color 0 0 0)
    for obj in objects where obj.mat == physMat do (
        obj.material = stnMat
    )
)

 

And what I managed to do in MaxScript:

 

-- Credit to dmitriy.shpilevoy Autodesk Fourms for this!
-- https://forums.autodesk.com/t5/3ds-max-programming-forum/simple-physical-to-standard-legacy-material-converter/td-p/10173340#M5535
for mPhysMat in scenematerials where (classOf mPhysMat == MultiMaterial) do (
	format "\nPHYSICAL: \nName: %,\nNumsubs: %,\nSubMatCount: %,\nMatID-List: %,\nMatList: %\n" mPhysMat.name mPhysMat.numsubs mPhysMat.materialList.count mPhysMat.materialIdList mPhysMat.materialList
	--Create new multimaterial with same array size as original. Assign IDs. Set submaterials to legacy
	mStdMat = MultiMaterial name:(mPhysMat.name+"_standard") numsubs:mPhysMat.materialList.count 
 	mStdMat.materialIDList = mPhysMat.materialIdList
	--mStdMat.material
 	for i = 1 to mStdMat.materialList.count do (

		stdName = mStdMat.materialList[i].name
 		mStdMat.material[i] = standardMaterial name:(stdName)
		mStdMat.material[i].diffuse = (color 32 0 0)
 		)
	format "\nLEGACY:\nName: %,\nNumsubs: %,\nSubMatCount: %,\nMatID-List: %,\nMatList: %\n" mStdMat.name mStdMat.numsubs mStdMat.materialList.count mStdMat.materialIdList mStdMat.materialList
	)

Thanks!

0 Likes
Accepted solutions (2)
270 Views
5 Replies
Replies (5)
Message 2 of 6

A娘
Advocate
Advocate
Accepted solution

 

for m in getclassinstances physicalmaterial do
(
	nm = standardmaterial ()
	--( new mat initialize)
	replaceinstances m nm
)

 

Message 3 of 6

MartinBeh
Advisor
Advisor

@A娘 wrote:

 

for m in getclassinstances physicalmaterial do
(
	nm = standardmaterial ()
	--( new mat initialize)
	replaceinstances m nm
)

Will this also transfer the bitmaps in the diffuse slot and/or diffuse color values?

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 4 of 6

A娘
Advocate
Advocate

write transfer logic with nm  by yourself before replaceinstances

0 Likes
Message 5 of 6

MartinBeh
Advisor
Advisor
Accepted solution

Here is my proposal, based on what @A娘 already had:

for m in getclassinstances physicalmaterial do
(
	oldcol = m.base_color
	oldmap = m.base_color_map
	nm = standardmaterial ()
	nm.diffuse = oldcol
	nm.diffuseMap = oldmap
	replaceinstances m nm
)
Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
Message 6 of 6

cadcajun
Participant
Participant

This works flawlessly! Thank you so much!

0 Likes