Apply a step value in SetHandle function
-
Hi,
REAL MYOBJECT_HEIGHT { UNIT METER; CUSTOMGUI REALSLIDER; MIN 0; MAXSLIDER 200.0; STEP 20;}I have an object that have a Description Resource element with "20" as STEP value and I want to apply the STEP value on the height value of the SetHandle() function
def SetHandle(self, op, handle_index, handle_position, info): handle_origin = HandleInfo() self.GetHandle(op, handle_index, handle_origin) data = op.GetDataInstance() if data is None or not self.handle: return height = data.GetFloat(c4d.LKC_KINOFLO_HEIGHT) value = (handle_position - handle_origin.position) * info.direction if handle_index == 0: op[c4d.MYOBJECT_HEIGHT] += valueThanks.
-
@mfersaoui
I found something like this:op[c4d.MYOBJECT_HEIGHT] += value mod = op[c4d.MYOBJECT_HEIGHT] % 20 op[c4d.MYOBJECT_HEIGHT] = op[c4d.MYOBJECT_HEIGHT] if mod == 0 else (op[c4d.MYOBJECT_HEIGHT] - mod) + 20 -
Hi,
this is probably a question of taste, but to me your solution seems a bit complicated. A quantized value can be expressed just as
quant_value = int(value / stride) * stride, wherevalueandstrideare floating point values. You can replaceintwithmath.floorormath.ceilif you do not want to round to the closest neighbour, but always to the lower or higher neighbour.Cheers,
zipit -
@zipit
Hi,
Thank you.