PDA

View Full Version : Manipulators Gismo Pos


MerlinEl
10-25-2009, 12:41 PM
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
--manip zero is teaken 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:%\twhich:%\tpickpoint:%\n" m which gpos[which+1]
)
)



It is there any way to keep them inside? Based on BoundingBox not pivot?

SyncViewS
10-25-2009, 01:01 PM
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:%\twhich:%\tpickpoint:%\n" m which gpos[which+1]
)
)
- Enrico

MerlinEl
10-25-2009, 01:21 PM
Hi Enrico

Im apologize for my english , but you get it right :beer:

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...)


http://img2.imageshack.us/img2/7272/manipi.jpg

SyncViewS
10-25-2009, 02:08 PM
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:%\twhich:%\tpickpoint:%\n" m which gpos[which+1]
)
)
- Enrico

MerlinEl
10-25-2009, 02:27 PM
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 :thumbsup:

MerlinEl
10-25-2009, 04:04 PM
when one node is attached to another ,then gismos should be in the middle ...
is not right ?

http://img101.imageshack.us/img101/1314/manip3.jpg



(
--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:%\twhich:%\tlocal_pp:%\n" m which gpos[which+1]
undo "Pivot Plant" on in coordsys node.transform point pos:gpos[which+1]
)
)
--restore
manipulateMode = old_manip
)

SyncViewS
10-25-2009, 04:24 PM
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

Bobo
10-25-2009, 04:38 PM
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:%\twhich:%\tpickpoint:%\n" m which gpos[which+1]
)
)

denisT
10-25-2009, 04:44 PM
(
--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:%\twhich:%\tlocal_pp:%\n" m which gpos[which+1]
undo "Pivot Plant" on in coordsys node.transform point pos:gpos[which+1]
)
)
--restore
manipulateMode = old_manip
)

SyncViewS
10-25-2009, 04:52 PM
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:%\twhich:%\tlocal_pp:%\n" m which gpos[which+1]
undo "Pivot Plant" on in coordsys node.transform point pos:gpos[which+1]
)
)
--restore
manipulateMode = old_manip
)
- Enrico

denisT
10-25-2009, 05:06 PM
to be 100% correct you have to compensate not reset XForm...

MerlinEl
10-25-2009, 05:54 PM
Wow! I didnt expect so many answers :)

well I made some quick tests with these nice modifications.
In most situations works good, but sometimes neds to reset x-form in zero rotation
and after turn it back.

I will test it again to morow .... I cant decide which method will be better heh
all of them is good!

thanks a lot guys :wavey:

denisT
10-25-2009, 06:11 PM
Wow! I didnt expect so many answers :)

well I made some quick tests with these nice modifications.
In most situations works good, but sometimes neds to reset x-form in zero rotation
and after turn it back.

I will test it again to morow .... I cant decide wich method will be better heh
all of them is good!

thanks a lot guys :wavey:


my method doesn't need reset xform

denisT
10-25-2009, 06:27 PM
if you want to create a point helper in right place using my code you have to change

undo "Pivot Plant" on in coordsys node.objecttransform point pos:gpos[which+1]


i didn't touch this piece of code...

MerlinEl
10-25-2009, 06:27 PM
right Denis! please can you try this ?

here... in the the last line in code
is final peace which is supposed to move node pivot to gismo center
if mesh is not rotated ,is working.



--denis
(
--store and refresh Manipulators
local old_sel = selection as array
manipulateMode = off
clearselection()
manipulateMode = on
select old_sel
--action
plugin simpleManipulator mc2ManipHandleTest
name:"test"
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:%\twhich:%\tlocal_pp:%\n" m which gpos[which+1]
undo "Pivot Plant" on in coordsys node.transform
(
-- point pos:gpos[which+1]
node.pivot = gpos[which+1]
)
)
)
)

denisT
10-25-2009, 07:00 PM
it has to be:

undo "Pivot Plant" on
(
--in coordsys node.objecttransform point pos:gpos[which+1]
node.pivot = gpos[which+1]*node.objecttransform
)

MerlinEl
10-25-2009, 08:23 PM
Denis? ....:beer: yea! ,we did it :-) (looks like a magic cube is not? ;-)


http://img510.imageshack.us/img510/3791/manip4.jpg

here is full version with all parts :


--Pivot Planter for Editable Poly
(
local sel = selection as array
if sel.count == 1 do
(
--refresh Manipulators
manipulateMode = off
clearselection()
manipulateMode = on
select sel
sel[1].xray = true

--Start
plugin simpleManipulator mc2PivotPlanter
name:"Pivot Planter"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0], y = [1, 1, 0], b = [0, 0, 1]
local gpos = #()
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
local tm = node.objecttransform
local bmin = local_bbox[1]*(inverse tm)
local 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
local p3 = [bmin.x,center.y,center.z] --front
local p4 = [bmax.x,center.y,center.z] --back
local p5 = [center.x,bmin.x,center.z] --left
local p6 = [center.x,bmax.x,center.z] --right

local p7 = bmin --LFD min
local p8 = [bmin.x, bmin.y, bmax.z] --LFU
local p9 = [bmin.x, bmax.y, bmax.z] --LBU
local p10 = [bmin.x, bmax.y, bmin.z] --LBD
local p11 = [bmax.x, bmax.y, bmin.z] --RBD
local p12 = bmax --RBU max
local p13 = [bmax.x, bmin.y, bmax.z] --RFU
local p14 = [bmax.x, bmin.y, bmin.z] --RFD

local p15 = [bmin.x, bmin.y, center.z] --LFM
local p16 = [bmin.x, center.y, bmax.z] --LUM
local p17 = [bmin.x, bmax.y, center.z] --LBM
local p18 = [bmin.x, center.y, bmin.z] --LDM
local p19 = [bmax.x, center.y, bmin.z] --RDM
local p20 = [bmax.x, bmax.y, center.z] --RBM
local p21 = [bmax.x, center.y, bmax.z] --RUM
local p22 = [bmax.x, bmin.y, center.z] --RFM
local p23 = [center.x, bmin.y, bmax.z] --FM
local p24 = [center.x, bmax.y, bmax.z] --UM
local p25 = [center.x, bmax.y, bmin.z] --BM
local p26 = [center.x, bmin.y, bmin.z] --DM


--collect positions for later use
gpos = #(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,
p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,p26)

--create gismos in cros
this.addGizmoMarker #asterisk p0 0 y r --#diamond p0 0 g r
this.addGizmoMarker #circle p1 0 g r
this.addGizmoMarker #circle p2 0 g r
this.addGizmoMarker #circle p3 0 g r
this.addGizmoMarker #circle p4 0 g r
this.addGizmoMarker #circle p5 0 g r
this.addGizmoMarker #circle p6 0 g r

--create gismos in corners
this.addGizmoMarker #asterisk p7 0 y r
this.addGizmoMarker #asterisk p8 0 y r
this.addGizmoMarker #asterisk p9 0 y r
this.addGizmoMarker #asterisk p10 0 y r
this.addGizmoMarker #asterisk p11 0 y r
this.addGizmoMarker #asterisk p12 0 y r
this.addGizmoMarker #asterisk p13 0 y r
this.addGizmoMarker #asterisk p14 0 y r

--create gismos in middle
this.addGizmoMarker #smallHollowBox p15 0 y r
this.addGizmoMarker #smallHollowBox p16 0 y r
this.addGizmoMarker #smallHollowBox p17 0 y r
this.addGizmoMarker #smallHollowBox p18 0 y r
this.addGizmoMarker #smallHollowBox p19 0 y r
this.addGizmoMarker #smallHollowBox p20 0 y r
this.addGizmoMarker #smallHollowBox p21 0 y r
this.addGizmoMarker #smallHollowBox p22 0 y r
this.addGizmoMarker #smallHollowBox p23 0 y r
this.addGizmoMarker #smallHollowBox p24 0 y r
this.addGizmoMarker #smallHollowBox p25 0 y r
this.addGizmoMarker #smallHollowBox p26 0 y r

return "Plant Pivot Here"
)
on mouseUp m which do -- m --> Point2 screen pixel coordinates, which --> gismo number
(
--format "m:%\twhich:%\tlocal_pp:%\n" m which gpos[which+1]
undo "Pivot Plant" on node.pivot = gpos[which+1]*node.objecttransform
)
)
)
)
--many thanks to Enrico, DenisT and Bobo



Thanks to All again :-)

denisT
10-25-2009, 08:48 PM
it can manipulate any valid node excluding itself ;)

SyncViewS
10-25-2009, 09:10 PM
Just tried it, nice script! Glad to have been of help, but Denis did the big step :D
Cheers!

- Enrico

CGTalk Moderation
10-25-2009, 09:10 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.