How to get only a z depth graph in graph editor of a object with respect to a moving camera


How do I get the object space with respect to camera so that the translation z displays depth with respect to the camera.

I think this is what I’d do

  1. Parent constrain a locator to the camera
  2. Add an aim constraint to the locator, pointing Z at your object
  3. Make a second locator, child of the first.
  4. Parent Constrain that locator to your object.
  5. Bake the motion of the second locator, and delete the constraint.
  6. Bake the motion of the first locator, and delete the constraint.
  7. Filter the z-depth curves on your second locator

Then you can just constrain back to that second locator, and bake the motion when you’re done.

Hey thanks,
But as u suggested if i parent constraint the first loactor to the camera then we cannot add the aim constraint to the same locator as the rotation axis is also connected. Is it ok if i use the point constraint on the locator and then aim constraint.?

Yeah, do the thing that works.

thank you so much it is working, I have written a script to modify the move manipulator along a custom axis and assigned it a short cut. i have to adjust the manipulator on the frames i have to animate.
so on every frame i have to use the shortcut and change the manipulator, if I do it on one frame, is there a way to update it automatically to that custom axis if i go to next frame.

mode = cmds.manipMoveContext(“Move”, q=True, m=True)
if mode == 0 or mode == 2:
cmds.manipMoveContext(“Move”, e=True, epm=True, ah=0, m=6, ot=t)

else:
cmds.manipMoveContext(“Move”, e=True, epm=True, ah=0, m=0)

OK, First things first. You should never ever ever ever ever use short flags on a script you plan on keeping or sharing. If you don’t use that maya command for a while, you will forget what those short flags are. And having to look up every single flag to figure out what a script is doing just sucks.


That locator should be the child of an object that’s already aligned it’s Z-axis, so I’m pretty sure you can just put your move manipulator in parent mode.

Hey thank you for that important note you gave me and sorry if you had to go through that trouble . But as you said that locator is already aligned to z axis . This is a different part of the script in which suppose I want to do it jus for few frames in between the animation then I can use this shortcut and easily change it instead of running through this whole process . So to check between frames instead of using shortcut every frame jus use it once and it will update the direction when I move to next frame.

Don’t worry about the short name thing at all. It’s just a thing I try to nip in the bud early. I just get passionate about it so people will actually fix it :slight_smile:

OK, different part of the script then…
I have some ideas:

Maybe you could make a script job that updates your custom axis every frame. I don’t like script jobs, but it might work.

I’d probably just write that whole setup with the locators as a script, and assign that to a hotkey. Then I’d write a teardown script that removes the setup and bakes out the changes as another hotkey.

Or maybe you build the setup once, and write a script that repositions the target without changing the animation, that way you can just go through and hit a hotkey to switch target objects. Then finally have a script that bakes everything back to worldspace.

Or maybe if you’re REALLY serious about this … I think you could write a custom manipulator using the API that tracks a given object. I have no clue how to do that though. I’ve never worked with custom manipulators.

Ok . I’ll try out the way you suggested and see how far it works for me. Thank you for guiding me.

Hey,
to select the camera and object i have used ls orderedselection option, so how can i check whether the first selection is a camera.? else to display error saying first select camera then object .?
allobj = []
allobj = cmds.ls(orderedSelection = True)

for obj in allobj :
if cmds.nodeType(obj[0]) == ‘camera’:
print obj

else : 
    print "select camera first then object"

I don’t have access to maya right now to check, but that’s definitely the structure of how to do it.

Another small thing: three back-ticks surrounding some text will make it keep the formatting

```
allobj = cmds.ls(orderedSelection = True)

for obj in allobj :
if cmds.nodeType(obj[0]) == ‘camera’:
print obj
else :
print “select camera first then object”

```

will give you this:

allobj = cmds.ls(orderedSelection = True)

for obj in allobj :
    if cmds.nodeType(obj[0]) == 'camera':
        print obj
    else : 
        print "select camera first then object"

Also, you don’t need to declare variables in Python, so you can just directly set allObj to the selection, just like I wrote it here.

Hey i tried it out but it is giving an error.

Error: No object matches name: c

Traceback (most recent call last):

File “”, line 12, in

RuntimeError: No object matches name: c

and sometimes :

Error: No object matches name: p

Traceback (most recent call last):

File “”, line 12, in

RuntimeError: No object matches name: p

the file contains a camera named cam and pSphere so with this script it is comparing the first letter that is c or p depending on the first selection, if in the nodeType(obj[0]) i write only nodeType(obj) then either i select camera or other object it displays the same else statement.

if cmds.nodeType(obj[0]) == 'camera':
should be
if cmds.nodeType(obj) == 'camera':

yes i tried this too if i use only obj then i should the camera name for print obj. But it is still printing
select camera first then object, even if i select camera first

You testing the condition on every object - i’m assuming you want to check the selection length and then the type of the first object being a camera.

selection = cmds.ls(orderedSelection = True)

if len(selection) == 2:

    if  cmds.nodeType(selection[0]) == 'camera':

        # Your code...

    else:
       cmds.warning("Select camera first!")

else:
   cmds.warning("Must select two objects.")


it is the same code u suggested bt even if i select camera first still it is displaying the warning to select camera first.