technical architecture.

3dsmax DirectX oddity

by on Nov.25, 2008, under maxscript, utility

Basic Problem: IT has enforced a Screensaver password policy here now Now, with the D3D view port driver, when you come back from a locked workstation, it doesn’t always instantiate the DX display correctly. we’re noticing on our workstations that it will come back working to a point.. IE: All of the geometry on screen is selectable, but only ~20% of it is displayed with edges in max.

a hack to fix it without having to restart max every time the computer locks on you, I’ve found i can Disable and then Enable the Direct3D Cached meshes.. this works.. in a crappy sort of way.

Here’s some code that toggles the d3d cached.. it also helps to show how to access things in max that are not readily open to the maxscript language, by using windows messaging to “push” buttons on dialogs! most credit to Richard at cgtalk!

 
toolTip="toggle the Use Cached D3DXMeshes Viewport"
buttonText="toggle the Use Cached D3DXMeshes Viewport"
 
--start macro
 
-----------------------------------------------------------------------------------------------
--
-- toggles the "Use Cached D3DXMeshes" checkbox of the Viewport configuration
--
-----------------------------------------------------------------------------------------------
 
--diable it while
 dialogMonitorOps.enabled = false
 global prefsDialog_hwnd = undefined
 global retMessage=""
 fn toggleCachedD3DMeshes = (
 
	 --Constants for sendMessage method	
	local BM_GETSTATE = 0xF2
	local BM_CLICK = 0xF5
	local BM_SETCHECK = 0xF1
	local BST_CHECKED = 0x1	 
 
 	local hwnd = dialogMonitorOps.getWindowHandle()
 	local dialogTitle = uiAccessor.getWindowText hwnd
 	if (dialogTitle != undefined) then (
 		if (dialogTitle == "Preference Settings") then (
			prefsDialog_hwnd = hwnd
			format "We're in the preferences dialog\n" 
			local hwnd_children = uiAccessor.getChildWindows hwnd
 			for i = 1 to hwnd_children.count do (
 				local hwnd_child_title = uiAccessor.getWindowText hwnd_children[i]
				if (findString hwnd_child_title "Configure Driver..." == 1) then (
					format "found config button... pressing\n"
					local hwnd_config = hwnd_children[i]
 					uiAccessor.pressButton hwnd_config
					)
				)
			)
		else if (dialogTitle == "Configure Direct3D") then (
			local hwnd_children = uiAccessor.getChildWindows hwnd
 			for i = 1 to hwnd_children.count do (
 				local hwnd_child_title = uiAccessor.getWindowText hwnd_children[i]
				if (findString hwnd_child_title "Use Cached D3DXMeshes" == 1) then (
					format "found the cached button\n"
					local hwnd_cached = hwnd_children[i]
					local CheckState = windows.sendMessage hwnd_cached BM_GETSTATE 0 0
					local IsChecked = bit.get CheckState BST_CHECKED
					format "the checkbox was: %\n" IsChecked
					-- Uncheck it
					if IsChecked then
					(
						windows.sendMessage hwnd_cached BM_CLICK 0 0
						windows.sendMessage hwnd_cached BM_SETCHECK 0 0
						format "Cached D3DXMeshes has been disabled.\n"
						format "Pressing OK on the ConfigureD3D page\n"
						uiAccessor.sendMessageID hwnd #IDOK
						format "Pressing OK on the Preferences page\n"
						uiAccessor.sendMessageID prefsDialog_hwnd #IDOK
						retMessage="Turning the CachedD3DXMeshes *OFF*"
					)
					-- Check it
					else if not IsChecked then
					(
						windows.sendMessage hwnd_cached BM_CLICK 0 0
						windows.sendMessage hwnd_cached BM_SETCHECK 1 0
						format "Cached D3DXMeshes has been enabled.\n"
						format "Pressing OK on the ConfigureD3D page\n"
						uiAccessor.sendMessageID hwnd #IDOK
						format "Pressing OK on the Preferences page\n"
						uiAccessor.sendMessageID prefsDialog_hwnd #IDOK
						retMessage="Turning the CachedD3DXMeshes *ON*"
					)
 				)
 			)
 		)
 	)
	true
 
 )
 
fn toggleUseCache =
(
	dialogMonitorOps.interactive = false
	dialogMonitorOps.unregisterNotification id:#setD3DCache
	dialogMonitorOps.registerNotification toggleCachedD3DMeshes id:#setD3DCache
	dialogMonitorOps.enabled = true
	--run it
	max file preferences
	--disable it!
	dialogMonitorOps.enabled = false
	dialogMonitorOps.unregisterNotification id:#setD3DCache
	--messagebox retMessage
)
 
toggleUseCache()
format retMessage
:, ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!