Snippets

John Martini Node Properties - Floating dialog for editing node properties in 3ds Max

Created by John Martini

File NodeProperties.ms Added

  • Ignore whitespace
  • Hide word diff
+/*
+	John Martini
+
+	- Version:001
+		Initial release
+*/
+
+try(destroyDialog ::rlNodeProperties)catch()
+rollout rlNodeProperties "Node Properties"
+(
+	local gpA = [10,10]
+	local gpB = [10,240]
+	local nodes = #()
+	local callbackContainer
+
+	groupbox gbObjectProperties "Object Properties" pos:gpA width:185 height:225
+		editText uiLayerName "Layer:" width:160 readonly:true pos:(gpA + [10,20])
+		checkbox uiRenderable "Renderable" pos:(gpA + [10,40])
+		checkbox uiInheritVisibility "Inherit Visibility" pos:(gpA + [10,60])
+		checkbox uiVisibleToCamera "Visible To Camera" pos:(gpA + [10,80])
+		checkbox uiVisibleToReflectionRefraction "Visible To Reflection/Refraction" pos:(gpA + [10,100])
+		checkbox uiReceiveShadows "Receive Shadows" pos:(gpA + [10,120])
+		checkbox uiCastShadows "Cast Shadows" pos:(gpA + [10,140])
+		checkbox uiApplyAtmospherics "Apply Atmospherics" pos:(gpA + [10,160])
+		checkbox uiRenderOccludedObjects "Render Occluded Objects" pos:(gpA + [10,180])
+		spinner uiObjectID "Object ID Channel: " range:[0,1e9,0] fieldwidth:55 type:#integer pos:(gpA + [10,200])
+	groupbox gbVrayProperties "Vray Properties" pos:gpB width:185 height:265
+		checkbox uiMatteObject "Matte Object" pos:(gpB + [10,20])
+		checkbox uiMatteForReflectionRefraction "Matte for Reflection/Refraction" pos:(gpB + [10,40])
+		spinner uiAlphaContribution "Alpha Contribution: " range:[-1.0,1.0,1.0] fieldwidth:55 type:#float pos:(gpB + [10,60])
+		groupbox gbVrayDirectLight "Direct Light" pos:(gpB + [10,80]) width:165 height:65
+			checkbox uiLightShadows "Shadows" pos:(gpB + [20,100])
+			checkbox uiLightShadowsAffectAlpha "Affect Alpha" pos:(gpB + [20,120])
+		groupbox gbVrayReflectionRefractionGI "Reflection/Refraction/GI" pos:(gpB + [10,150]) width:165 height:105
+			spinner uiReflectionContribution "Refl Contribution: " range:[0.0,1.0,1.0] fieldwidth:45 type:#float pos:(gpB + [22,170])
+			spinner uiRefractionContribution "Refr Contribution: " range:[0.0,1.0,1.0] fieldwidth:45 type:#float pos:(gpB + [20,190])
+			spinner uiGiContribution "GI Contribution: " range:[0.0,1.0,1.0] fieldwidth:45 type:#float pos:(gpB + [30,210])
+			checkbox uiNoGiOnMattes "No GI On Other Mattes" pos:(gpB + [20,230])
+
+	fn CollectPropertyValues property:undefined type:#node =
+	(
+		local values = #()
+		local curSel = getCurrentSelection()
+
+		case type of
+		(
+			#vray :
+			(
+				for n in curSel do
+				(
+					result = getUserProp n property
+					if result == undefined then
+					(
+						--if undefined then return the vray default value
+						case property of
+						(
+							"VRay_MoBlur_GeomSamples": append values 2
+							"VRay_GI_Generate": append values True
+							"VRay_GI_Receive": append values True
+							"VRay_GI_Multipier": append values 1.000000
+							"VRay_GI_GenerateMultipier": append values 1.000000
+							"VRay_GI_SubdivsMultiplier": append values 1.000000
+							"VRay_Caustics_Generate": append values True
+							"VRay_Caustics_Receive": append values True
+							"VRay_Caustics_Multipier": append values 1.000000
+							"VRay_MoBlur_DefaultGeomSamples": append values True
+							"VRay_Matte_Enable": append values False
+							"VRay_Matte_Alpha": append values 1.000000
+							"VRay_Matte_Shadows": append values False
+							"VRay_Matte_ShadowAlpha": append values False
+							"VRay_Matte_ShadowColor": append values [0,0,0]
+							"VRay_Matte_ShadowBrightness": append values 1.000000
+							"VRay_Matte_ReflectionAmount": append values 1.000000
+							"VRay_Matte_RefractionAmount": append values 1.000000
+							"VRay_Matte_GIAmount": append values 1.000000
+							"VRay_Matte_GI_OtherMattes": append values True
+							"VRay_GI_SurfaceID": append values 0
+							"VRay_GI_VisibleToGI": append values True
+							"VRay_GI_VisibleToReflections": append values True
+							"VRay_GI_VisibleToRefractions": append values True
+							"VRay_Secondary_Matte_Enable": append values False
+						)
+					)
+					else
+					(
+						append values result
+					)
+				)
+			)
+			#node :
+			(
+				for n in curSel where isProperty n property do
+				(
+					append values (getProperty n property)
+				)
+			)
+			#layer :
+			(
+				for n in curSel do
+				(
+					append values n.layer.name
+				)
+			)
+		)
+
+		return values
+	)
+
+	fn isAllPropsSame values:#() =
+	(
+		for v in values do
+			if values[1] != v do return false
+		return true
+	)
+
+	fn calcState property:undefined type:#node =
+	(
+		if selection.count >= 1 then
+		(
+			-- collect array of property values
+			local tmpValues = CollectPropertyValues property:property type:type
+			
+			-- check to see if all property values are the same
+			local match = isAllPropsSame values:tmpValues
+			
+			-- 0 = false / 1 = true / 2 = indeterminate 
+			if match then
+			(
+				--if they all match return its value
+				return tmpValues[1]
+			)else(
+				-- if they don't all match then return 'indeterminate'
+				return "mismatch" --intermediate result
+			)
+		)
+		else
+		(
+			return undefined
+		)
+	)
+
+	fn SetUIControl ctrl: value: =
+	(
+		-- CHECKBOX ACTIONS
+		if classof value == BooleanClass do
+		(
+	 		if value == false do 
+	 		(
+	 			if classof ctrl == CheckBoxControl do ctrl.triState = 0
+	 			if classof ctrl == SpinnerControl do ctrl.indeterminate = false
+	 		)
+
+			if value == true do 
+			(
+				if classof ctrl == CheckBoxControl do ctrl.triState = 1
+				if classof ctrl == SpinnerControl do ctrl.indeterminate = false
+			)
+		)
+
+		-- INTEGER ACTIONS
+		if classof value == Integer do
+		(
+			if classof ctrl == SpinnerControl do ctrl.value = value
+		)
+		if classof value == Float do
+		(
+			if classof ctrl == SpinnerControl do ctrl.value = value
+		)
+		if classof value == string AND value != "mismatch" do
+		(
+			if classof ctrl == EditTextControl do ctrl.text = value
+		)
+
+		-- ALL INDETERMINATE ACTIONS
+		if value == "mismatch" do 
+		(
+			if classof ctrl == CheckBoxControl do ctrl.triState = 2
+			if classof ctrl == SpinnerControl do ctrl.indeterminate = true
+			if classof ctrl == EditTextControl do ctrl.text = ""
+		)
+	)
+
+	fn EnableUI state:(selection.count >=1) =
+	(
+		rlNodeProperties.controls.enabled = state
+
+		--## check/compare settings for selected nodes Object Properties
+		results_layer = calcState type:#layer
+		results_renderable = calcState property:#renderable
+		results_inheritVisibility = calcState property:#inheritVisibility
+		results_primaryVisibility = calcState property:#primaryVisibility
+		results_secondaryVisibility = calcState property:#secondaryVisibility
+		results_receiveShadows = calcState property:#receiveShadows
+		results_castShadows = calcState property:#castShadows
+		results_applyAtmospherics = calcState property:#applyAtmospherics
+		results_renderOccluded = calcState property:#renderOccluded
+		results_ObjectID = calcState property:#gBufferChannel
+		--## check Vray Properties
+		results_VRayMatteEnable = calcState property:"VRay_Matte_Enable" type:#vray
+		results_VRaySecondaryMatteEnable = calcState property:"VRay_Secondary_Matte_Enable" type:#vray
+		results_VRayMatteAlpha = calcState property:"VRay_Matte_Alpha" type:#vray
+		results_VRayMatteShadows = calcState property:"VRay_Matte_Shadows" type:#vray
+		results_VRayMatteShadowAlpha = calcState property:"VRay_Matte_ShadowAlpha" type:#vray
+		results_VRayMatteReflectionAmount = calcState property:"VRay_Matte_ReflectionAmount" type:#vray
+		results_VRayMatteRefractionAmount = calcState property:"VRay_Matte_RefractionAmount" type:#vray
+		results_VRayMatteGIAmount = calcState property:"VRay_Matte_GIAmount" type:#vray
+		results_VRayMatteGIOtherMattes = calcState property:"VRay_Matte_GI_OtherMattes" type:#vray
+
+		--## set the state of the UI Controls
+		SetUIControl ctrl:uiLayerName value:results_layer
+		SetUIControl ctrl:uiRenderable value:results_renderable
+		SetUIControl ctrl:uiInheritVisibility value:results_inheritVisibility
+		SetUIControl ctrl:uiVisibleToCamera value:results_primaryVisibility
+		SetUIControl ctrl:uiVisibleToReflectionRefraction value:results_secondaryVisibility
+		SetUIControl ctrl:uiReceiveShadows value:results_receiveShadows
+		SetUIControl ctrl:uiCastShadows value:results_castShadows
+		SetUIControl ctrl:uiApplyAtmospherics value:results_applyAtmospherics
+		SetUIControl ctrl:uiRenderOccludedObjects value:results_renderOccluded
+		SetUIControl ctrl:uiObjectID value:results_ObjectID
+
+		SetUIControl ctrl:uiMatteObject value:results_VRayMatteEnable
+		SetUIControl ctrl:uiMatteForReflectionRefraction value:results_VRaySecondaryMatteEnable
+		SetUIControl ctrl:uiAlphaContribution value:results_VRayMatteAlpha
+		SetUIControl ctrl:uiLightShadows value:results_VRayMatteShadows
+		SetUIControl ctrl:uiLightShadowsAffectAlpha value:results_VRayMatteShadowAlpha
+		SetUIControl ctrl:uiReflectionContribution value:results_VRayMatteReflectionAmount
+		SetUIControl ctrl:uiRefractionContribution value:results_VRayMatteRefractionAmount
+		SetUIControl ctrl:uiGiContribution value:results_VRayMatteGIAmount
+		SetUIControl ctrl:uiNoGiOnMattes value:results_VRayMatteGIOtherMattes
+	)
+
+	fn SetVrayUserProps name:"" value:undefined =
+	(
+		local curSel = getCurrentSelection()
+		for n in curSel do
+		(
+			setUserProp n name value
+		)
+	)
+
+	fn PopupDockMenu =
+	(
+		rcmenu rcOptions
+		(
+			menuItem miFloat "Float"
+			menuItem miDockLeft "Dock Left"
+			menuItem miDockRight "Dock Right"
+
+			on miFloat picked do
+			(
+				try(cui.UnRegisterDialogBar rlNodeProperties)catch()
+			)
+			on miDockLeft picked do
+			(
+				try(cui.UnRegisterDialogBar rlNodeProperties)catch()
+				cui.registerdialogbar rlNodeProperties style:#(#cui_dock_left, #cui_floatable, #cui_dock_right)
+				cui.dockdialogbar rlNodeProperties #cui_dock_left
+			)
+			on miDockRight picked do
+			(
+				try(cui.UnRegisterDialogBar rlNodeProperties)catch()
+				cui.registerdialogbar rlNodeProperties style:#(#cui_dock_left, #cui_floatable, #cui_dock_right)
+				cui.dockdialogbar rlNodeProperties #cui_dock_right
+			)
+		)
+		popupmenu rcOptions pos:mouse.screenpos
+	)
+
+	fn updateHandler event nodes = 
+	(
+		--t1 = timestamp()
+		--m1 = heapfree
+		EnableUI()
+		--format "time:% memory:%\n" (timestamp() - t1) (m1 - heapfree)		
+	)
+
+	on uiRenderable changed state do (getCurrentSelection()).renderable = state
+	on uiInheritVisibility changed state do (getCurrentSelection()).inheritVisibility = state
+	on uiVisibleToCamera changed state do (getCurrentSelection()).primaryVisibility = state
+	on uiVisibleToReflectionRefraction changed state do (getCurrentSelection()).secondaryVisibility = state
+	on uiReceiveShadows changed state do (getCurrentSelection()).receiveShadows = state
+	on uiCastShadows changed state do (getCurrentSelection()).castShadows = state
+	on uiApplyAtmospherics changed state do (getCurrentSelection()).applyAtmospherics = state
+	on uiRenderOccludedObjects changed state do (getCurrentSelection()).renderOccluded = state
+	on uiObjectID changed value do (getCurrentSelection()).gbufferchannel = value
+	on uiMatteObject changed state do
+	(
+		if state then
+		(
+			uiAlphaContribution.value = -1.0
+			SetVrayUserProps name:"VRay_Matte_Alpha" value:-1.0
+		)else(
+			uiAlphaContribution.value = 1.0
+			SetVrayUserProps name:"VRay_Matte_Alpha" value:1.0
+		)
+		SetVrayUserProps name:"VRay_Matte_Enable" value:state
+	)
+	on uiMatteForReflectionRefraction changed state do SetVrayUserProps name:"VRay_Secondary_Matte_Enable" value:state
+	on uiAlphaContribution changed val do SetVrayUserProps name:"VRay_Matte_Alpha" value:val
+	on uiLightShadows changed state do SetVrayUserProps name:"VRay_Matte_Shadows" value:state
+	on uiLightShadowsAffectAlpha changed state do SetVrayUserProps name:"VRay_Matte_ShadowAlpha" value:state
+	on uiReflectionContribution changed val do SetVrayUserProps name:"VRay_Matte_ReflectionAmount" value:val
+	on uiRefractionContribution changed val do SetVrayUserProps name:"VRay_Matte_RefractionAmount" value:val
+	on uiGiContribution changed val do SetVrayUserProps name:"VRay_Matte_GIAmount" value:val
+	on uiNoGiOnMattes changed state do SetVrayUserProps name:"VRay_Matte_GI_OtherMattes" value:state
+
+	on rlNodeProperties rbuttonup pt do
+	(
+		PopupDockMenu()
+	)
+
+	on rlNodeProperties open do
+	(
+		callbackContainer = NodeEventCallback mouseUp:true delay:1 all:UpdateHandler
+		EnableUI()
+	)
+
+	on rlNodeProperties close do
+	(
+		callbackContainer.enabled = off
+		callbackContainer = undefined
+		gc light:true
+	)
+)
+createDialog rlNodeProperties 205 515 style:#(#style_SysMenu, #style_ToolWindow)
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.