Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography


Featured Threads
  inspiration alert!!!
(36 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies)
  Maxforums.org Members Gallery
(516 replies)
  SON OF POST YOURSELF
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

[MAXScript] Rotate the pivot towards/away another object
show user profile  Nanne
Hi mates, I'm looking for a script or help with writing one (especially the math part :P) that takes the pivot of the selected objects and rotates it, so that the X-axis points away from another objects. It sounds as it should be simple, but I can't figure it out. Any tips on how to do it?

Kristoffer Helander
www.kristofferhelander.se
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 759 times
1/21/2016 12:39:30 PM (last edit: 1/21/2016 12:39:30 PM)
show user profile  Garp
LookAt constraint?




read 754 times
1/21/2016 12:42:45 PM (last edit: 1/21/2016 12:42:45 PM)
show user profile  Nanne
Ah, no I don't want to animate it or anything I just need to adjust a lot of pivot in a mechanical rig in order for it all to work properly when I link them all up.

Kristoffer Helander
www.kristofferhelander.se
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 749 times
1/21/2016 12:53:25 PM (last edit: 1/21/2016 12:53:25 PM)
show user profile  Nanne
This script rotates a box so that the Y-axis points towards a sphere in the scene, but I can't figure out how to make it the X-axis instead?

target = $Sphere001
n = $Box001
-- rotate teapot on local z axis so it points towards the vector (sphere position)
theDir = normalize (target.pos - n.pos) --a vector pointing from teapot to sphere position
theZ = normalize (n.transform.row3) --the local Z axis
theCross = cross theDir theZ --a vector perpendicular to both the Z and the direction vector
theDir2 = normalize (cross theZ theCross) --a vector perpendicular to the Z and the cross product = projection of the direction in local XY
theNewX = normalize (cross theDir2 theZ) --a vector perpendicular to both the projected direction and Z = the new local X
n.transform = matrix3 theNewX theDir2 theZ n.pos --make a matrix of the new X, Y and existing Z, keep the position

Also I need to only rotate the pivot, not the object itself :)

Kristoffer Helander
www.kristofferhelander.se
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 748 times
1/21/2016 12:54:58 PM (last edit: 1/21/2016 12:55:33 PM)
show user profile  Nanne
This code rotates the objects so the X-Axis points towards the other objects. Now I need to reverse it and make sure it's only the pivot that rotates.

v1=[1,0,0]
yAxis = v1*$.transform.rotationPart
pivPos = $.pos
objPos = $Sphere002.pos
ang = acos(dot(normalize (objPos-pivPos)) (normalize (yAxis)))
rot_box = if pivPos.x > objPos.x then eulerangles 0 0 ang else eulerangles 0 0 -ang
rotate $ rot_box

Kristoffer Helander
www.kristofferhelander.se
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 733 times
1/21/2016 1:25:04 PM (last edit: 1/21/2016 1:25:04 PM)
show user profile  Nanne
I think I figured it out! :)

--

v1=[1,0,0]
yAxis = v1*$.transform.rotationPart
pivPos = $.pos
objPos = $klumpLink001.pos
ang = acos(dot(normalize (objPos-pivPos)) (normalize (yAxis)))
rot_box = if pivPos.x > objPos.x then eulerangles 0 0 ang else eulerangles 0 0 -ang
--rotate $ rot_box

fn RotatePivotOnly obj rotation = (local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetpos*=RotValInv
obj.objectoffsetrot*=RotValInv
)

RotatePivotOnly $ (rot_box)
RotatePivotOnly $ (eulerangles 0 0 180)

--

However, sometimes it get's it wrong on the first go, but running the script multiple times eventually makes it right. Why is that?

Kristoffer Helander
www.kristofferhelander.se
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 720 times
1/21/2016 2:10:56 PM (last edit: 1/21/2016 2:10:56 PM)
#Maxforums IRC
Open chat window


Support Maxforums.org