Show soft selection on unselected mesh?


Currently using this with your makeWeightColor function, and it is working perfectly as far as I can tell. Thanks again!

fn vertColorFromSoftSel obj = (
	obj.showVertexColors = on
	obj.vertexColorsShaded = on

	for v = 1 to obj.numVerts do (
		local w = polyOp.getVDataValue obj 1 v
		polyop.setMapVert obj 0 v	((weightToColor w) as point4)



All right, one last thing I guess… right now it still only works when the node is selected with subselection on. Otherwise polyOp.getVDataValue <node> 1 <vertex> always returns 1.0.

If I first select the node and lock the soft selection, then deselect the node, it will return the correct values. But is there any way to do this without having to select the node at all?

(weightToColor w) as point4

is not necessary. the function as you can see has an option argument.

about a sub-selection level… i think it’s a limitation. probably using sdk is possible to force soft-selection level update. with pure mxs is probably not. but just in case i would check the state of baseobject instead of polyobject. maybe it updates.

other way is to calculate ‘soft selection’ weights yourself. the formula is known. as i remember it was posted (by Klvnk?) on this forum


Not sure what you mean by calculate the soft selection weights?


far distance is lower weight. selection you know, neighbors you can find… distance as well.
the formula is something about distance, falloff, pinch, and bubble… it was shown here


Oh yeah, that. Unfortunately that won’t work if painted soft selection is on, which for my purposes it will be. Given that, not sure if this is the most efficient way to get the desired result, but it works.

fn vertColorFromSoftSel obj = (
	-- Store selection and subobject level
	sel = selection as array
	setCommandPanelTaskMode #modify
	SOL = subObjectLevel

	-- Temporarily set object and subselection
	select obj
	if subObjectLevel == 0 do subObjectLevel = 1

	-- Set mapping and display
	polyOp.setMapSupport obj 0 true
	obj.showVertexColors = true
	obj.vertexColorsShaded = true
	obj.useSoftSel = true

	-- Set vertex colors
	for v = 1 to obj.numVerts do (
		local w = polyOp.getVDataValue obj.baseObject 1 v
		polyop.setMapVert obj 0 v	(makeWeightColor w asRGB:on)

	-- Restore selection and subobject level
	deselect selection
	select sel
	subObjectLevel = SOL



you can disable max redraw (including viewports and command panel). and no one will see your selecting-deselecting. i’ve cheated this way a lot :slight_smile:
also you can disable reference messages to make everything hidden for callbacks.


[left]Oh yeah, I’ve done that more than a few times myself. Dunno why I didn’t think of it for this :stuck_out_tongue:

EDIT: Hm, actually… disabling the messages seems to break the function because it prevents the subobject level from working.


you have to manually notify dependents about the change (check mxs help - notifyDependents - for details)


So here’s what I’ve got so far. What else can I do to make it faster?

fn colorFromFloat v = (
 	local c = red
 	c.h = (1.0 - v) * 170
 	c as point4
 fn softSelWeightArray obj = with redraw off (
 	-- Store selection and subobject level
 	local sel = selection as array
 	setCommandPanelTaskMode #modify
 	local SOL = subObjectLevel
 	store = (selection.count > 1 or not obj.isSelected)
 	if store do (deselect selection; select obj)
 	if SOL == 0 do subObjectLevel = 1
 	local wArray = (
 		for v = 1 to obj.numVerts collect
 		meshOp.getVDataValue obj.baseObject 1 v
 	if store do (deselect selection; select sel)
 	subObjectLevel = SOL
 fn vertColorFromWeights obj wArray: = (
 	if wArray == unsupplied do wArray = softSelWeightArray obj
 	meshOp.setMapSupport obj 0 true
 	meshOp.setSoftSel obj true
 	obj.showVertexColors = true
 	obj.vertexColorsShaded = true
 	obj.vertexColorType = 0
 	cArray = for v = 1 to obj.numVerts collect (colorFromFloat wArray[v])
 	for v = 1 to obj.numVerts do meshop.setMapVert obj 0 v cArray[v]


Hi! Is it possible to link where it was shown? I’m desperately trying to recreate soft selection because it only works in with subobject level and I need to achieve this result without modify menu. I’ve created a script with distance/amin/amax but it’s still not the same curve, as soft selection offers. Thanks in advance!


from meshadj.h

This function is available in release 3.0 and later only.
This is the standard affect region function, based on a distance and the three
affect region parameters (same as the editable mesh).
This function is a cubic curve which returns 1 at distance 0, 0 if distance is
greater than falloff, and other values for distance between 0 and falloff. To
“see” this function graphed, look at the curve in the Soft Selection parameters
in Edit Mesh, Editable Mesh, Mesh Select, or Volume Select. This function
currently is constructed as follows:

float u = ((falloff - dist)/falloff);
float u2 = u*u, s = 1.0f-u;
return (3*u*bubble*s + 3*u2*(1.0f-pinch))*s + u*u2


@Serejah Thank you! I’'ll take a look today.

suspendEditing which:#modify

falloff1 = 100
pinch = 0
bubble = 0;
tstrength = 40;

fn tu dist = (
	u = ((falloff1 - dist)/falloff1);
	u2 = u*u;
	s = 1.0-u;
	((3*u*bubble*s + 3*u2*(1.0-pinch))*s + u*u2)

dd = for v in $.verts collect 
	tt = for i in (polyop.getVertSelection $) collect distance v.pos (polyop.getVert $ i)
	amin tt

for k=1 to $.verts.count do (
	pos =polyop. getVert $ k
	polyop.setVert $ k [pos.x, pos.y, pos.z + (tstrength *  (tu dd[k]))]

resumeEditing which:#modify

my Version of soft selection on z axis. I’ve c++ version too but this is easier to test. It is smooth, nearly does it’s job, but gives me a strange mesh. I’m calculating distance using amin. What am I missing? :frowning:


Is there any way to turn off soft selection display in modify mode?

this one disables soft selection drawing until I change my modifier parameters or reselect the node.
I’d prefer to have an sdk way of doing so

max display mode
max backface cull toggle
max backface cull toggle
max modify mode


I don’t understand the question… ‘Use Affect Region’ (‘Use Soft Sel’) is a property (option) of some Object’s sub-object display.
It’s not an option of Modifier Panel.


I should have post a full example. Hope it is clear now what I want to achieve.

delete objects

p = Plane length:100 width:100 isSelected:on lengthsegs:30 widthsegs:30
convertToPoly p

max modify mode
vs = Vol__Select method:0 level:1 volume:4 UseAffectRegion:true 
vs.texture = Noise size:25 thresholdLow:0.35 thresholdHigh:0.65
modPanel.addModToSelection vs ui:on
modPanel.addModToSelection (relax Relax_Value:1 Keep_Boundary_Pts_Fixed:0 iterations:50)
-- uncomment to turn off soft-sel display
max display mode
max backface cull toggle
max backface cull toggle
max modify mode

IObjectDisplay2::PrepareDisplay seems like the best candidate to use, but I have no idea how-to… ideally I’d like to have a checkbox to show/hide current soft-sel in modifier paramblock

mode = getCVertMode p
setCVertMode p (not mode)
setCVertMode p mode

this is a little better

ps… no. it returns back after redraw.


turns out that it is enough to clear some DisplayFlags like this:


I do it right in ModifyObject method and wonder if it is correct or I should clear these flags somewhere else?


nice catch! :+1: