question

Alan Jones avatar image
Alan Jones asked ·

Control Maya modifying camera attributes on camera type selection

Hi all,

So I've implemented a custom Arnold camera node, created a CExtension which registers an mtoa translator and it all successfully goes through.

However, this type of camera is more akin to an othographic camera than a perspective one, but every time the camera type is chosen in the Arnold section of the camera, it disables the orthographic setting.

Is there some one I can hook myself in to these callbacks so that I can control what is set and adjusted when my camera type is selected? (If so, how? :P)

Cheers,

Alan.

arnoldmtoamayaui
5 comments
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Uh oh - guessing the answer may be no? Either that or it's very ugly.

Seems there is a MNodeMessage which has a parameter changed callback, but that requires a specific node for it to be registered for.

There's a MDGMessage that I could use to detect when a node is added, check if it's a camera node, then register the aforementioned MNodeMessage for it's parameter changes.

However, that may or may not trigger when a scene is opened (unclear from docs whether an existing node in a scene being loaded would count as an add - to be continued)

0 Likes 0 · ·

Also unclear whether callbacks are persisted, not in docs either. If both of those are false, then there's an MSceneMessage which has an opened callback that I could use to go and run through the entire scene, find all cameras and register the MNodeMessage callback mentioned at the start.

However, if there are other callbacks coming into play then those could change the values before I get them if it executes first. Or they may also execute afterwards and overwrite my changes. Or infinite loop.

Anyone at Autodesk able to confirm/deny any of this? (or provide a solution that would work)

0 Likes 0 · ·

Hi @Alan Jones

I'll ask the MtoA devs to take a look at these questions...

0 Likes 0 · ·
Show more comments
Sebastien Blaineau-Ortega avatar image
Sebastien Blaineau-Ortega answered ·

Hi Alan,

it might be too late for the feature you needed to implement, but we addressed this limitation in the latest MtoA 4.0.3 that was just released.

You need to set a metadata orthographic = true for this node, please let us know if you need any help to implement it.

Thanks

1 comment Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Thanks very much, Sebastien. Most appreciated.

0 Likes 0 · ·
Stephen Blair avatar image
Stephen Blair answered ·

Here's something that might help:


def cameraTranslatorChanged(transPlug, *args):
    "called to sync .orthographic when .aiTranslator changes"
    if not core.arnoldIsCurrentRenderer(): return
    fnCam = om.MFnCamera(transPlug.node())
    currTrans = transPlug.asString()
    orthoPlug = fnCam.findPlug('orthographic')
    isOrtho = orthoPlug.asBool()
    #print "cameraTranslatorChanged", fnCam.name(), currTrans, isOrtho
    # when a file is opening, we need to choose one attribute to lead, because
    # the order that attributes are set is unpredictable. This fixes a case
    # where translators may have gotten out of sync
    if om.MFileIO.isOpeningFile():
        if isOrtho and currTrans != 'orthographic':
            orthoPlug.setBool(True)
    else:
        if not isOrtho and currTrans == 'orthographic':
            orthoPlug.setBool(True)
        elif isOrtho and currTrans != 'orthographic':
            orthoPlug.setBool(False)
#
def getCameraDefault(obj):
    isOrtho = om.MFnDependencyNode(obj).findPlug("orthographic").asBool()
    default = 'orthographic' if isOrtho else 'perspective'
    return default
#
templates.registerDefaultTranslator('camera', getCameraDefault)
templates.registerDefaultTranslator('stereoRigCamera', getCameraDefault)
#
callbacks.addAttributeChangedCallbacks('camera',
                                       [('aiTranslator', cameraTranslatorChanged),
                                        ('orthographic', cameraOrthographicChanged)])
#
callbacks.addAttributeChangedCallbacks('stereoRigCamera',
                                       [('aiTranslator', cameraTranslatorChanged),
                                        ('orthographic', cameraOrthographicChanged)


2 comments Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Thanks, Stephen. Are callbacks the best way to do this? i.e. is there nothing I should be doing in either my Arnold cpp code, mtoa translator, or elsewhere that provides this information in a manner your APIs expect?

Just checking as while this will work if my plugin is the only one checking, there could potentially be conflicts if another was doing the same thing. So it feels like there should be APIs available for custom cameras to register some properties of themselves.

Cheers,

Alan.

0 Likes 0 · ·

Doing callbacks such as this, still get written over by the mtoa scripts, so there is no way to package a plugin for distribution which works around this.

0 Likes 0 · ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.