ZBrushCentral

Scripting the detection of the presence of a mask?

Does anyone have a ZScript method to detect the presence of a partial (or full for that matter) mask?

My solution right now is to simply toggle the “viewmask” button on and off a couple of times. If a mask is present it will flash (darken) the masked parts which gives a visual confirmation… but how to verify the presence of a mask via scripting escapes me.

One possibility is to take a point count, press the hidepts button and take another point count and compare the two, but pressing the showpts button seems to destroy the mask except along the masked border… AND masks have a threshold intensity below which a point remains visible, so a low density mask may not be detected. Yes, you could save the mask using create alpha, but then each time you do that you generate another alpha - which pretty soon adds up.

And while I’m at it, it seems like it would be useful in 4.0 to be able to turn a mask off temporarily then turn it back on (not just Viewmask but actually disable its masking power.) Again, storing the mask as an alpha approximates that, but still, a new alpha is created each time… etc.

Ideas?

thanks, Sven

Hi Sven,

The way I would do it is to use the HidePt button, grab the info from the current tool to find if any points are hidden and then use ‘Undo’ to return to the masked state:

[IButton,TestForMask,,
	[IFreeze,
		[IPress,Tool:Masking:HidePt]
		[VarSet,totalPolys,[StrExtract,[IGetInfo,Tool:Current Tool],12,256]]
		[IPress,Edit:Tool:Undo]
	]
	[If,[StrFind,"HiddenPolys=",totalPolys]>-1,
		[VarSet,totalPolys,[StrExtract,totalPolys,([StrFind,"HiddenPolys=",totalPolys]+12),([StrFind,"HiddenPolys=",totalPolys]+13)]]
		[If,[Val,totalPolys] > 0,				
			[Note,"\Cff9923
 WARNING: \CffffffThe mesh has masked polys."]			
		]		
	]	
]

Not ideal, but I’ve not thought of any alternative. :slight_smile:

I agree it would be useful to be able to store masks (and UVs, and…) for re-use later.

I’ve just realized this method won’t work if the model is fully masked. Not sure how to get around that… :o

Ah yes, UNDO! That should work and should help me with a few other recent dilemmas as well. Thanks!

As for detecting - fully masked… perhaps including an Inverse command might be a solution?

Sven

I thought of Inverse but there’s no way of telling whether there’s a full mask or no mask in that HidePt doesn’t do anything either way. :frowning:

Hmm. Maybe I just found the simplest way of all (haven’t tried to script it yet) but it appears that if there is NO mask, and you press inverse, then the Viewmask button is enabled, press inverse again and the Viewmask button is disabled. If there is ANY mask present, Viewmask button STAYS enabled. With a full mask, the Viewmask button starts out enabled, then becomes disabled. Whatcha think?

Sven

Hah, perfect!

[IButton,TestForMask2,,
	[IFreeze,
		[IPress,Tool:Masking:Inverse]
		[IPress,Tool:Masking:Inverse]
	]
	[VarSet,mask,[IGet,Tool:Masking:ViewMask]]
	[If,mask,				
		[Note,"\Cff9923
 WARNING: \CffffffThe mesh has masked polys.",,1]
	,
		[Note,"No mask",,1]			
	]	
]

Marcus

Refining it:

[IButton, TestForMask3, ,
    [IFreeze,
        // save state of viewmask button
        [VarSet, ViewMaskFlag, [IGet, TOOL:Masking:ViewMask] ]
        // always set ViewMask off before testing
        [ISet, TOOL:Masking:ViewMask, 0 ]
        [IPress, TOOL:Masking:Inverse ]
        [VarSet, Test1, [IGet, TOOL:Masking:ViewMask ] ]
        [IPress, TOOL:Masking:Inverse ]
        [VarSet, Test2, [IGet, TOOL:Masking:ViewMask ] ]
    ]
    [If, (Test1 == 1) && (Test2 == 1),
        [Note, "Partial Mask", , 1 ]
    ]
    [If, (Test1 == 1) && (Test2 == 0),
        [Note, "No Mask", , 1 ]
    ]
    [If, (Test1 == 0) && (Test2 == 1),
        [Note, "Full Mask", , 1 ]
    ]
    // restore state of viewmask button
    [ISet, TOOL:Masking:ViewMask, ViewMaskFlag ]
]

Thanks for the help Marcus!

Sven

Ah, I’d forgotten about restoring the ViewMask button.

For the benefit of others, there’s a simple way to create a zscript ‘pseudo use case’ type coding when testing for a variety of things. The benefit of the Loop is that the remaining code is ignored as soon as as a result is found.

[Loop,1,
    [If, (Test1 == 1) && (Test2 == 1),
        [Note, "Partial Mask", , 1 ]
        [LoopExit]
    ]
    [If, (Test1 == 1) && (Test2 == 0),
        [Note, "No Mask", , 1 ]
        [LoopExit]
    ]
    [If, (Test1 == 0) && (Test2 == 1),
        [Note, "Full Mask", , 1 ]
        [LoopExit]
    ]
]

Though in this instance one could simplify the code (at the expense of some transparency):

[If, (Test1 == 1),
    [If,(Test2 == 1),
        [Note, "Partial Mask", , 1 ]
     ,
        [Note, "No Mask", , 1 ]
     ]
 ,
     [Note, "Full Mask", , 1 ]
 ]