Viewport Label

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 12 December 2013   #1
Viewport Label

Can I make a viewport gw.text-like thing which is clickable?
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 12 December 2013   #2
Originally Posted by DaveWortley: Can I make a viewport gw.text-like thing which is clickable?

This fn by Raphael 'Insanto' Steves is used for ScriptSpotter script. Maybe can help you somehow.
fn drawtext text:"mouseOverText" pos:[100,100] mPos:mouse.pos = --function to draw the screenText and check if mouse is hovering, does not update the screen after drawing
(
   local mouseOverText = off
   local te = gw.getTextExtent text
   local b1 = Box2 pos.x pos.y te.x te.y
   local b2 = Box2 pos.x (pos.y-te.y) te.x te.y
   gw.setTransform(Matrix3 1)
   if contains b2 mouse.pos do (mouseOverText = on)
   gw.wText [pos.x, pos.y, 0] text color:(if not mouseOverText then color 150 180 210 else color 177 88 22)
   gw.enlargeUpdateRect b1 --b1 --#whole
   return mouseOverText
)--END drawtext FN
drawtext text:"mouseOverText"
registerRedrawViewsCallback drawtext
--unRegisterRedrawViewsCallback drawtext 
__________________
Looking in the right side. [bgaTools]
 
Old 12 December 2013   #3
Hmm that gets me a nice label, and if you pan the viewport with your mouse over the label it picks up, but I'm not sure it'll give me a click event... Needs some kind of hit test but whether that would hamper max overall too much....
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 12 December 2013   #4
Originally Posted by DaveWortley: Hmm that gets me a nice label, and if you pan the viewport with your mouse over the label it picks up, but I'm not sure it'll give me a click event... Needs some kind of hit test but whether that would hamper max overall too much....

This can capture mouse click-move
unRegisterRedrawViewsCallback drawtext
 fn drawtext text:"mouseOverText" pos:[100,100] mPos:mouse.pos =
 (
    local mouseOverText = off
    local te = gw.getTextExtent text
    local b1 = Box2 pos.x pos.y te.x te.y
    local b2 = Box2 pos.x (pos.y-te.y) te.x te.y
    gw.setTransform(Matrix3 1)
    if contains b2 mouse.pos do (mouseOverText = on)
    gw.wText [pos.x, pos.y, 0] text color:(if not mouseOverText then color 150 180 210 else color 177 88 22)
    gw.enlargeUpdateRect b1
    return (if mouseOverText and mouse.mode == 2 do (messagebox "Mouse Moved" beep:off ; mouseOverText = off))
 )--END drawtext FN
 drawtext text:"mouseOverText"
 registerRedrawViewsCallback drawtext

I not know why mouse.mode == 1 not work here.
__________________
Looking in the right side. [bgaTools]
 
Old 12 December 2013   #5
Also you can try when mouse over viewport text to run simple tool (lButton event). Maybe this is not good method
__________________
Looking in the right side. [bgaTools]
 
Old 01 January 2014   #6
This is what I've been doing with this.. I've made a script which adds a label to the viewport to indicate whether the camera is locked or not, which hopefully will help in that old annoying situation where a camera gets nudged accidentally. I'd like to have it so the label is clickable so that I could have a toggle to lock/unlock, but I guess this will just have to go in a quad menu unless anyone else can think of a good hack?

unregisterRedrawViewsCallback drawtextCamLock
fn drawtextCamLock = 
	(
		if viewport.gettype() == #view_camera do
		(
			--is Camera Locked
			local dtext = "[Camera Unlocked ]"
			local textColour 
			if (for i = 1 to 9 where (getTransformLockFlags (viewport.getcamera()))[i] == true collect i).count == 9 then 
			(
				dtext = "[Camera Locked ]" 
				textColour = (color 196 196 196)
				if (viewport.getcamera()).target != undefined do
				(
					if (for i = 1 to 9 where (getTransformLockFlags (viewport.getcamera()).target)[i] == true collect i).count != 9 do
					(
						dtext = "[Camera Locked, Target Unlocked ]" 
						textColour = (color 255 0 0)
					)	
				)
				
			)	
			else 
			(
				dtext = "[Camera Unlocked ]"
				textColour = (color 255 0 0)
			)
			if checkParent (viewport.getcamera()) == "xref" do
			(
				dtext = "[XRef Scene Camera ]"
				textColour = (color 196 196 196)
			)
			local camtext = ("[" + (viewport.getcamera()).name + "]")
			
			local viewportstyle
			if NitrousGraphicsManager.GetActiveViewportSetting() != undefined then
				viewportstyle = ((NitrousGraphicsManager.GetActiveViewportSetting(  )).VisualStyleMode)
			else
			(
				viewportstyle = case viewport.GetRenderLevel() of
				(
					#smoothhighlights : "[ Smooth + Highlights"
					#wireFrame : "[ Wireframe"
					#smooth : "[ Smooth"
					#facethighlights : "[ Facets//Hi"
					#facet : "[ Facets"
					#flat : "[ Flat"
					#litwireframe : "[ Lit Wires"
					#Box : "[ Box"
					#hiddenline : "[ Hidden Line"
				)
			)
				
			local edgesOn = if (viewport.GetShowEdgeFaces()) then 75 else 0
			local isDisabled = if viewport.isenabled() then 0 else 80
			local pos = [(gw.getTextExtent camtext)[1] + (gw.getTextExtent viewportstyle)[1] + edgesOn + isDisabled + 50,18]
			gw.setTransform(Matrix3 1)
			gw.wText [pos.x, pos.y, 0] dtext color:textColour
			
		)
	)--END drawtext FN
	drawtextCamLock()
	registerRedrawViewsCallback drawtextCamLock
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/

Last edited by DaveWortley : 01 January 2014 at 11:00 AM.
 
Old 01 January 2014   #7
I don't know if this can help you, but you can try it.
 
Old 01 January 2014   #8
Originally Posted by DaveWortley: This is what I've been doing with this.. I've made a script which adds a label to the viewport to indicate whether the camera is locked or not, which hopefully will help in that old annoying situation where a camera gets nudged accidentally.

do you want to make it nice or just functional right?
why do you try to put 'lock' info into a viewport?
you can do it with macro button placed in any toolbar.
 
Old 01 January 2014   #9
BTW... all getTransformLockFlags set doesn't mean that the node's transform locked. you still can change it by script, or moving its parent for example... and if you can't change a camera scale but can change its focus where is a difference?
 
Old 01 January 2014   #10
hopefully i didn't forget anything:

macroScript CAM_Locked
	tooltip:"Toggle Active Camera Lock" 
	category:"CAM"
	buttontext:"CAM Locked"
	autoUndoEnabled:off
(
	fn isLocked cam: = 
	(
		if cam == unsupplied do cam = getActiveCamera()
		iskindof cam camera and (LockedTracksMan.GetLocked cam cam 0 off) and
		(
			cam.target == undefined or LockedTracksMan.GetLocked cam.target cam 0 off
		)
	)
	fn toggleLock cam: = 
	(
		if cam == unsupplied do cam = getActiveCamera()
		if iskindof cam camera do
		(
			act = isLocked cam:cam
			LockedTracksMan.SetLocks (not act) cam cam 0 off
			if cam.target != undefined do LockedTracksMan.SetLocks (not act) cam.target cam 0 off
		)
	)
	on isEnabled do (viewport.gettype() == #view_camera)
	on isChecked do isLocked()
	on execute do undo "Toggle Camera Lock" on toggleLock()
)
 
Old 01 January 2014   #11
Denis is right, of course. However setting the TM locks and adding a script controller to the fov was sufficient for my case here. My primitive implementation changed the wirecolor of locked cameras to indicate when it had happened. We have a script to manage cameras here now which does pretty much the same thing, but grabs the hierarchy/rig for the camera and locks this too.

edit: Very nice approach, Denis.
__________________
Regards,
Pete

Read my technical blog - lonerobot.net
 
Old 01 January 2014   #12
It's easily possible to nudge a camera if you middle-click in an inactive camera viewport, happens all the time. I've tried a few approaches in the past to automatically lock cameras on file open, or give tools to lock cameras but I've found the guys tend to get frustrated as they go to move a camera and can't, or simply can't be bothered to lock the camera, or don't think about it.

This approach is about giving the user information, and warning in a non-intrusive way. I don't want to use complex locks in case someone needs to unlock a camera and doesn't have access to the script, so just locking the transform flags will be fine for now.

We have a custom toolbar which is on all our machines which has quick links to our tools and scripts, so I have a button for locking/unlocking the camera, but it would be a lot nicer if it was possible to do this in one click in the viewport.
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 01 January 2014   #13
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:46 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.