Notifications
Clear all

[Closed] Pivot inside bounding box

I’m using this code from denisT to check if pivot is inside bounding box:


 struct bounds (bmin, bmax)
     fn isPointInsideBBox pos bbox = 
     (
     	pos.x >= bbox.bmin.x and pos.x <= bbox.bmax.x \
     	and
     	pos.y >= bbox.bmin.y and pos.y <= bbox.bmax.y \
     	and
     	pos.z >= bbox.bmin.z and pos.z <= bbox.bmax.z
     )
     fn isPivotInsideBBox node bbType:#world = 
     (
     	tm = case of
     	(
    		(bbType == #local): node.objectTransform
		(iskindof bbType Matrix3): bbType
    		default: matrix3 1
     	)
     	bbox = nodeGetBoundingBox node tm
     	bbox = bounds bmin:bbox[1] bmax:bbox[2]
     		
     	isPointInsideBBox (node.pivot*(inverse tm)) bbox
     )
     isPivotInsideBBox $ bbType:#local

Now i’m wondering, how could i add some threshold value in there? Like i could make the boundingbox virtually smaller or larger by some percent and to allow pivot be outside the actual boundingbox. I tried multiplying bbox in isPointInsideBBox -function but it didn’t work with rotated object.

1 Reply

you have to scale bbox (if you need change it by %), or resize (if you want to use absolute value):


fn scaleBBox bbox factor:0.5 = 
(
	size = bbox[2]-bbox[1]
	delta = size * (1.0 - factor)
	bbox[1] += delta/2
	bbox[2] -= delta/2
	bbox
)
fn resizeBBox bbox value:1.0 = 
(
	bbox[1] -= value/2
	bbox[2] += value/2
	bbox
)

i use the same amount for all three dimensions. if you want to have unique amount for each dimension use a point3 for ‘factor’ and ‘value’ instead of just a float.