Notifications
Clear all

[Closed] Help needed in scripted manipulator plugin

hey guys …

so, this is where i’m stuck …
I’m trying to write a scripted manipulator plugin, one which’d allow
me to rotate the selected object in the manipulate mode.

The below code does work, and it allows me to rotate the selected object
in the manipulate mode, but I have very little control over the rotation …
I mean its really hard to go in the +ve and -ve direction

The code below is what I’ve copied from maxscript reference, where I found a radius
manipulaion plugin, and I modified it to suit my needs. (It currently is set up to
rotate the selected object in the local z axis.)

 
plugin simpleManipulator TestRotateManip 
name:"TestRotate" 
invisible:true
(
local g = [0, 0, 1], r = [1, 1, 0] 
local curNode = selection[1] 
local initLen = 0; 
local oldProj = [0,0,0]
local gizSize = (try(curNode.max.z - curNode.min.z)catch(5))
 
on canManipulate target return (try($.isselected)catch(false)) 
on updateGizmos do 
(
this.clearGizmos()
giz = manip.makeCircle [0,0,0] gizSize 6
--giz = manip.makeTorus [0,0,0] 20 1 6 6 
-- Add the circle to the manipulator 
this.addGizmoShape giz gizmoActiveViewportOnly g r 
--this.addGizmoMesh ($ESkel_Master.mesh) 0 g r 
--print gizSize;
)
 
 
on mouseMove m which do 
(
	 local pl = manip.makePlaneFromNormal z_axis [0, 0, 0], 
	 projectedPoint = [0,0,0]
 
	 -- Compute the hit-ray in local coordinates 
	 viewRay = this.getLocalViewRay m
	 -- Intersect the plane with the view ray 
	 res = pl.intersect viewRay &projectedPoint
 
	 difProj = oldProj - projectedPoint ------ this is where I am stuck
	 len = distance difProj oldProj	 -------
 
	 --angleee = acos(dot (normalize [0,0,0]) (normalize projectedPoint))
 
	 if (res) then 
	 (
		 if len > initLen then 
		 (
			 in coordsys local rotate node (angleaxis (node.rotation.z + \
			 (length projectedPoint)/10) [0,0,1]) 
		 )
		 else in coordsys local rotate node (angleaxis (node.rotation.z - (length \
		 projectedPoint)/10) [0,0,1]) 
 
		initLen = len
	 )
oldProj = projectedPoint 
)
)
 

just copy/paste and run the code .
Select any object (non-biped) and then click on the manipulate button.
Now you should be able to rotate the selected object in local zee

any help is greatly appreciated. Please do let me know if I didn’t make myself clear.

Thanks
shibu

1 Reply

ok … got it …

added a mouse tool in there, and it works fine