Notifications
Clear all

[Closed] Scripted Material – callback on render?

I’m trying to make a material that switches (between 2 options) based on a user-entered userproperty expression.

My current hurdle is getting a reference to the node the material is attached to (yes, a material is applied to multiple nodes). How do I get a callback when it’s evaluated for a particular node?

Heres the script so far (started with the LPM Render Switcher plugin/script):


struct exprEvalResult
(
	validSyntax = false,
	nodeFound = false,
	message = "",
	switch = false
)

plugin material userPropSwitcher
	name: "CKD Switcher"
	category: "CKD"
	classID: #(0x626d61f2, 0x4ccb7d32)
	extends: Shellac 
	replaceUI: true 
	version: 1
(
	fn expValid str =
	(
		return exprEvalResult validSyntax:true nodeFound:true switch:true
	)

	parameters main rollout:params
	(
		expressionStr type:#string ui:expUI
	
		matA type:#material ui:matAUI
		matB type:#material ui:matBUI

		on matA set value do if(switch == 0) then delegate.shellacMtl1 = value
		on matB set value do if(switch == 1) then delegate.shellacMtl1 = value
		
		on expressionStr set value do 
		(
			result = expValid(value as string)
			
			if(result.validSyntax and result.nodeFound) then
			(
				if(result.switch == false) then
					delegate.shellacMtl1 = matA
				else if(result.switch == true) then
					delegate.shellacMtl1 = matB		
			)
		)
	)

	rollout params "CKD Switcher"
	(
		label expLabel "Expression" pos:[6,8] width:50 height:13
		editText expUI "" pos:[70,4] width:200 height:21
	
		label matALabel "Base Mtl" pos:[5,29] width:50 height:13
		materialButton matAUI "" pos:[70,26] width:200 height:21 
		
		label matBLabel "Switch Mtl" pos:[6,51] width:50 height:13
		materialButton matBUI "" pos:[70,48] width:200 height:21 
	)
	
	on create do
	(
		matA = standard()
		currentMtl = meditMaterials[activeMeditSlot]

		keepOldMtl = false
		
		if(MatEditor.isOpen() and (superclassof currentMtl) == material) then
		(
			keepOldMtl = queryBox "Keep Old Material?"
			if keepOldMtl then matA = currentMtl
		)	

		matB=standard()
		delegate.shellacMtl1 = matA
		delegate.shellacMtl2 = matB
	)
)