[Closed] Manipulators Gismo Pos
Hi
I have one object and thre gismo points inside.
but when the object moves out of [0,0,0] position ,
then gismos losing theirs offset.
Im tryed many ways to keep them inside, but no success…:hmm:
here is the script:
plugin simpleManipulator mc2ManipHandleTest
name:"test"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0]
local gpos = #()
on canManipulate target return (classOf target == Editable_Poly)
on updateGizmos do
(
-- Clear the current gizmo cache
this.clearGizmos()
local bbox_size = node.max - node.min -- w l h
--build bbox points from [0,0,0] , center bottom and top
local p0 = [0,0,bbox_size.z/2] --center
local p1 = [0,0,0] --bottom
local p2 = [0,0,bbox_size.z] --top
[color=SeaGreen]--manip zero is teaken from node pivot, must be recalculated relative to BBox obj
p0 += node.pos [color=Green]--p0 *= node.pos
p1 += node.pos
p2 += node.pos[/color][/color]
--add result to an array for latest use
gpos += #(p0,p1,p2)
--create gismos
this.addGizmoMarker #diamond p0 0 g r
this.addGizmoMarker #HollowBox p1 0 g r
this.addGizmoMarker #HollowBox p2 0 g r
return "point"
)
on mouseUp m which do -- m = Point2 screen pixel coordinates, which is gismo number
(
format "m:% which:% pickpoint:%
" m which gpos[which+1]
)
)
It is there any way to keep them inside? Based on BoundingBox not pivot?
Hi Merlin, I’m not sure to understand your issue, anyway you could try the following script. It keeps the offset while dragging the EditablePoly. The drawback is that bounding box max and min “change” as the node is rotated (try to see the effect). I hope this helps.
plugin simpleManipulator mc2ManipHandleTest
name:"test"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0]
local gpos = #()
on canManipulate target return (classOf target == Editable_Poly)
on updateGizmos do
(
-- Clear the current gizmo cache
this.clearGizmos()
local bbox_size = node.max - node.min -- w l h
--build bbox points from [0,0,0], center bottom and top
local p0 = [0,0,0] --center
local p1 = [0,0,-bbox_size.z/2] --bottom
local p2 = [0,0,bbox_size.z/2] --top
--manip zero is taken from node pivot, must be recalculated relative to BBox obj
-- p0 += node.pos --p0 *= node.pos
-- p1 += node.pos
-- p2 += node.pos
--add result to an array for latest use
gpos += #(p0,p1,p2)
--create gismos
this.addGizmoMarker #diamond p0 0 g r
this.addGizmoMarker #HollowBox p1 0 g r
this.addGizmoMarker #HollowBox p2 0 g r
return "point"
)
on mouseUp m which do -- m = Point2 screen pixel coordinates, which is gismo number
(
format "m:% which:% pickpoint:%
" m which gpos[which+1]
)
)
- Enrico
Hi Enrico
Im apologize for my english , but you get it right
The problem is when the node is rotating…
what I must to do?
get the true size of bbox while is rotated (but how…)
or
create a new bouding box from vertices? (but how…)
Hi Merlin, don’t worry, your English is more than enough, and mine is far from perfect
You should get bounding box in local coordinates to be consistent with the node transformations. This should work as expected.
plugin simpleManipulator mc2ManipHandleTest
name:"test"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0]
local gpos = #()
on canManipulate target return (classOf target == Editable_Poly)
on updateGizmos do
(
-- Clear the current gizmo cache
this.clearGizmos()
local localBBox = nodeGetBoundingBox node node.transform
local bbox_size = localBBox[2] - localBBox[1] -- w l h
--build bbox points from [0,0,0], center bottom and top
local p0 = [0,0,bbox_size.z/2] --center
local p1 = [0,0,0] --bottom
local p2 = [0,0,bbox_size.z] --top
--add result to an array for latest use
gpos += #(p0,p1,p2)
--create gismos
this.addGizmoMarker #diamond p0 0 g r
this.addGizmoMarker #HollowBox p1 0 g r
this.addGizmoMarker #HollowBox p2 0 g r
return "point"
)
on mouseUp m which do -- m = Point2 screen pixel coordinates, which is gismo number
(
format "m:% which:% pickpoint:%
" m which gpos[which+1]
)
)
- Enrico
Yes Yes , thats it!
local local_bbox = nodeGetBoundingBox node node.transform --min / max
local bbox_size = local_bbox[2] - local_bbox[1] -- w l h
thank you Enrico
when one node is attached to another ,then gismos should be in the middle …
is not right ?
(
--store and refresh Manipulators
local old_sel = selection as array
local old_manip = manipulateMode
manipulateMode = off
clearselection()
manipulateMode = on
select old_sel
--action
plugin simpleManipulator mc2PivotPlanter
name:"mc2PivotPlanter"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0]
local gpos = #(), local_bbox, bbox_size
on canManipulate target return (classOf target == Editable_Poly)
on updateGizmos do
(
-- Clear the current gizmo cache
this.clearGizmos()
local local_bbox = nodeGetBoundingBox node node.transform
local bbox_size = local_bbox[2] - local_bbox[1] -- w l h
--build bbox points from [0,0,0], center, bottom and top
local p0 = [0,0,bbox_size.z/2] --center
local p1 = [0,0,0] --bottom
local p2 = [0,0,bbox_size.z] --top
gpos = #(p0,p1,p2)
--create gismos
this.addGizmoMarker #diamond p0 0 g r
this.addGizmoMarker #HollowBox p1 0 g r
this.addGizmoMarker #HollowBox p2 0 g r
return "point"
)
on mouseUp m which do -- m --> Point2 screen pixel coordinates, which --> gismo number
(
format "m:% which:% local_pp:%
" m which gpos[which+1]
undo "Pivot Plant" on in coordsys node.transform point pos:gpos[which+1]
)
)
--restore
manipulateMode = old_manip
)
At first blush I’d say “yes, it is”, but with the current code the answer is “no, it isn’t”. I need to run some tests but I guess the issue is here:
local local_bbox = nodeGetBoundingBox node node.transform
To get the local Bounding Box, coordinates are transformed into local space using the Node transform matrix. When you attach a node to another, the transform matrix is not changed to the average of the two nodes.
I’m quite sure it can be solved, I’m going to give it a try.
- Enrico
How about using the actual center?
Only a box has the pivot point at the bottom, normal geometry doesn’t have to…
plugin simpleManipulator mc2ManipHandleTest
name:"test"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0]
local gpos = #()
on canManipulate target return (classOf target == Editable_Poly)
on updateGizmos do
(
-- Clear the current gizmo cache
this.clearGizmos()
local localBBox = nodeGetBoundingBox node node.transform
local localCenter = node.center * inverse node.transform
local bbox_size = localBBox[2] - localBBox[1] -- w l h
--build bbox points from [0,0,0], center bottom and top
local p0 =localCenter --center
local p1 = localCenter-[0,0,bbox_size.z/2] --bottom
local p2 = localCenter+[0,0,bbox_size.z/2] --top
--add result to an array for latest use
gpos += #(p0,p1,p2)
--create gismos
this.addGizmoMarker #diamond p0 0 g r
this.addGizmoMarker #HollowBox p1 0 g r
this.addGizmoMarker #HollowBox p2 0 g r
return "point"
)
on mouseUp m which do -- m = Point2 screen pixel coordinates, which is gismo number
(
format "m:% which:% pickpoint:%
" m which gpos[which+1]
)
)
(
--store and refresh Manipulators
local old_sel = selection as array
local old_manip = manipulateMode
manipulateMode = off
clearselection()
manipulateMode = on
select old_sel
--action
plugin simpleManipulator mc2PivotPlanter
name:"mc2PivotPlanter"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0]
local gpos = #(), local_bbox, bbox_size
on canManipulate target return (classOf target == Editable_Poly)
on updateGizmos do
(
-- Clear the current gizmo cache
this.clearGizmos()
-- manipulator's transform in nodes's LOCAL coord system
local local_bbox = nodeLocalBoundingBox node
-- compensate not reset xform
tm = node.objecttransform
bmin = local_bbox[1]*(inverse tm)
bmax = local_bbox[2]*(inverse tm)
local bbox_size = local_bbox[2] - local_bbox[1] -- w l h
local center = (bmin + bmax)/2
local p0 = center --center
local p1 = [center.x,center.y,bmin.z] --bottom
local p2 = [center.x,center.y,bmax.z] --top
gpos = #(p0,p1,p2)
--create gismos
this.addGizmoMarker #diamond p0 0 g r
this.addGizmoMarker #HollowBox p1 0 g r
this.addGizmoMarker #HollowBox p2 0 g r
return "point"
)
on mouseUp m which do -- m --> Point2 screen pixel coordinates, which --> gismo number
(
format "m:% which:% local_pp:%
" m which gpos[which+1]
undo "Pivot Plant" on in coordsys node.transform point pos:gpos[which+1]
)
)
--restore
manipulateMode = old_manip
)
Well, after all these, here’s mine too
(
--store and refresh Manipulators
local old_sel = selection as array
local old_manip = manipulateMode
manipulateMode = off
clearselection()
manipulateMode = on
select old_sel
--action
plugin simpleManipulator mc2PivotPlanter
name:"mc2PivotPlanter"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0]
local gpos = #(), local_bbox, bbox_size
on canManipulate target return (classOf target == Editable_Poly)
on updateGizmos do
(
-- Clear the current gizmo cache
this.clearGizmos()
local local_bbox = nodeGetBoundingBox node node.transform
local bbox_size = local_bbox[2] - local_bbox[1] -- w l h
local bbox_center = local_bbox[1] + ((local_bbox[2] - local_bbox[1]) / 2)
--build bbox points from [0,0,0], center, bottom and top
local p0 = bbox_center --center
local p1 = bbox_center - [0, 0, bbox_size.z/2] --bottom
local p2 = bbox_center + [0, 0, bbox_size.z/2] --top
gpos = #(p0,p1,p2)
--create gismos
this.addGizmoMarker #diamond p0 0 g r
this.addGizmoMarker #HollowBox p1 0 g r
this.addGizmoMarker #HollowBox p2 0 g r
return "point"
)
on mouseUp m which do -- m --> Point2 screen pixel coordinates, which --> gismo number
(
format "m:% which:% local_pp:%
" m which gpos[which+1]
undo "Pivot Plant" on in coordsys node.transform point pos:gpos[which+1]
)
)
--restore
manipulateMode = old_manip
)
- Enrico