[MaxScript] MultiMaterial-like scripted plugin


#1

Hi All,

I’m experimenting with a scripted material plugin, and I want to expose the material array (tab) of material.
Exposing Mtl1 and Mtl2 works fine. But when it comes to the #materialtab, I can’t figure out how to expose it in the material editor. I’m mainly concerned for the node knobs, in the material editor. As an alternative, I was wondering if there is a way to dynamically add parameters in the parameters block so I can treat them as “single” materials? I can dynamically update the UI so, that’ would be fine.

image

plugin material TestMtl name:"Test Material" classID:#(695421,446582) extends:Standard replaceUI:true version:1
(
	
	parameters main rollout:properties_ro (
		Mtl1 type:#material ui:mtl1_btn
		Mtl2 type:#material ui:mtl2_btn
		Mtls type:#materialTab tabSizeVariable:true
	)
	
	rollout properties_ro "Properties"
	(
		materialbutton mtl1_btn "Render material" width:300 
		materialbutton mtl2_btn "Render material" width:300
	)
	
)

#2

any ideas on this one? :confused:


#3

Do you mean something like this?

plugin material TestMtl name:"Test Material" classID:#(695421,446582) extends:Standard replaceUI:true version:1
(
	
	parameters main rollout:properties_ro
	(
		Mtls type:#materialTab tabSize:3 tabSizeVariable:true ui:(mtl1_btn, mtl2_btn, mtl3_btn)
	)
	
	rollout properties_ro "Properties"
	(
		materialbutton mtl1_btn "Render material" width:300 
		materialbutton mtl2_btn "Render material" width:300
		materialbutton mtl3_btn "Render material" width:300
	)
	
)

#4

that (with the parenthesis) I didn’t know! Great stuff, many thanks @PolyTools3D!
One question though. If I want to add/remove materials in the MaterialTab, is there a dynamic way where I can change the UI parameter?
My goal is to be able to add/remove materials similar to the Multi-Material.


#5

To resize a tab you can use the count property or set an index:

tab.count = N
or
tab[N] = X

Don’t know though if it will work well with materialTab/materialButton.


#6

I probably didn’t explained it properly.
In your example, you manually pre-defined the ui property to this value of (mtl1_btn, mtl2_btn, mtl3_btn).
How can you add/remove other ui controls when you change the size of the tab? How can you dynamically set the ui to two buttons ui:(mtl1_btn, mtl2_btn) or four buttons ui:(mtl1_btn, mtl2_btn, mtl3_btn, mtl4_btn) programable?


#7

I don’t know if it is possible to dynamically add/remove UI elements from a tab parameter.

What you can do is to set them to undefined and show/hide the associated control. But that won’t change the tab size.


#8

Yeah, I wonder how they do it in the multi-material? :thinking:


#9

You can take a look at the source “multi.cpp”.


#10

You lost me somewhere at the .cpp :joy::joy:
OK, I might collect my courage and try that. Many thanks for all your replies.


#11

It is a 3000 lines code, not to digest in a few minutes.

But if I had to guess, since you can only see a maximum of 10 materials at the time, I think it only uses 10 buttons and store the materials in a tab that is not linked to the controls. Instead it could reassign the materials to each control when you scroll.

That way you can have a resizable materials tab and you would only need to create controls for 10 materials. If you have less than 10 then simply hide them or move off-screen.


#13

With MultiMaterial, you’re not limited to just 10 materials. You can pretty much set whatever number you want and it will display all the materials. I’m trying to have a look today on the C++ code today as you suggested but my first 3-4 minutes were scary! hahahah

I did just found that the “Set Number” button, triggers this function SetNumMats in the “multi.cpp” file.


#14

I meant the 10 material buttons you see in the properties rollout, not the knobs in the Slate Editor.

The UI controls associated with a property do not seem to have any effect in the amount of knobs you see in the Slate Editor. Instead, they seem to be linked to the initial size of the materialTab.

Check this two simple examples. Unfortunately they don’t seem to update when you resize the tab.

plugin material TestMtl1 name:"Test Material 1" classID:#(111111,111111) extends:Standard replaceUI:true version:1
(
	parameters main rollout:properties_ro
	(
		Mtls type:#materialTab tabSize:5 tabSizeVariable:true
	)
	
	rollout properties_ro "Properties"
	(
	)
)

plugin material TestMtl2 name:"Test Material 2" classID:#(222222,222222) extends:Standard replaceUI:true version:1
(
	parameters main rollout:properties_ro
	(
		Mtls type:#materialTab tabSize:15 tabSizeVariable:true
	)
	
	rollout properties_ro "Properties"
	(
	)
)

#15

yeah, that’s the main issue I noticed, plus the fact that when you change the tabsize, let’s say from 5 to 10, if you dynamically update the UI from 5 to 10 buttons, there doesn’t seem to be a way to link the buttons with “UI” property in the parameter block.

Here’s an example below:

plugin material TestMtl2 name:"Test Material 2" classID:#(222222,222222) extends:Standard replaceUI:true version:1
(
	local properties_ro
	parameters main rollout:properties_ro
	(
		Mtls type:#materialTab tabSize:2 tabSizeVariable:true ui:(mtl1, mtl2)
	)

	fn generateRollout count = (
		removeRollout properties_ro;
		local str = "rollout properties2_ro \"Configurable materials\" (\n"
		for i=1 to count do ( str += "\tmaterialbutton mtl" + i as string + " \"\" width:260\n" )
		str += ")"
		properties_ro = execute str
		addRollout properties_ro
		
		for i=1 to count do (
			properties_ro.controls[i].material = this.Mtls[i]
		)
	)
	
	rollout main_ro "Set" (
		spinner mtslCount "Count.........................................." width:260 fieldWidth:48 type:#integer range:[1,20,2] align:#center
		button setMtls "Set" width:260
		
		on setMtls pressed do (
			generateRollout mtslCount.value
		)
	)
	rollout properties_ro "Properties" (
		materialButton mtl1 width:260
		materialButton mtl2 width:260
	)
)

And here’s a screen recording