-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransferObjMatrixToCamera.py
More file actions
36 lines (26 loc) · 1.34 KB
/
Copy pathtransferObjMatrixToCamera.py
File metadata and controls
36 lines (26 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import maya.cmds as cmds
'''
transferObjMatrixToCam.py
This script will transfre selected object to a duplicated camera.It's useful for stablizing obj.
Select obj and then camera. Choose one frame as reset frame, and run the script.
You can then duplicate obj without animation at rest frame, and view from new camera,
It should looks identical in viewport comparing to the original camera and moving obj
'''
#require select select obj and camera,
#The script will also use current frame as rest position
sel = cmds.ls(sl=True, l=True)
mat1 = cmds.createNode('multMatrix')
mat2 = cmds.createNode('multMatrix')
mat3 = cmds.createNode('multMatrix')
mat4 = cmds.createNode('decomposeMatrix')
nCam = cmds.duplicate(sel[1], rr=True)
cmds.connectAttr('%s.worldMatrix[0]'%sel[1], '%s.matrixIn[0]'%mat1)
cmds.connectAttr('%s.inverseMatrix'%sel[0], '%s.matrixIn[1]'%mat1)
cmds.connectAttr('%s.worldMatrix[0]'%sel[0], '%s.matrixIn[0]'%mat3)
cmds.connectAttr('%s.matrixSum'%mat1, '%s.matrixIn[0]'%mat2)
cmds.connectAttr('%s.matrixSum'%mat3, '%s.matrixIn[1]'%mat2)
cmds.connectAttr('%s.matrixSum'%mat2, '%s.inputMatrix'%mat4)
cmds.connectAttr('%s.outputTranslate'%mat4, '%s.translate'%nCam[0])
cmds.connectAttr('%s.outputRotate'%mat4, '%s.rotate'%nCam[0])
cmds.connectAttr('%s.outputScale'%mat4, '%s.scale'%nCam[0])
cmds.setAttr("%s.frozen"%mat3, 1)