ynput / ayon-maya

Maya addon for AYON
Apache License 2.0
6 stars 6 forks source link

Load Image Plane: Allow to load detached like orthographic default does in Maya #119

Open BigRoy opened 2 weeks ago

BigRoy commented 2 weeks ago

Is there an existing issue for this?

Please describe the feature you have in mind and explain what the current shortcomings are?

The Image Plane loader loads attached to a camera, even the orthographic ones. However, by default when you load an image plane using Maya itself to an orthographic camera (tested in Maya 2025.2) Maya loads it 'detached' but just initializes it with a transform aiming at the camera.

Currently we offer no means to create them detached. Add options to create the image planes in 'detached' mode.

How would you imagine the implementation of the feature?

Either match Maya's default behavior and create in detached mode for orthographic cameras automatically - or add an extra toggle or setting in the "select camera" that sets the attached or detached mode (that toggle could also auto-switch when selecting an orthographic or perspective camera if those settings do make more sense as defaults respectively).

Are there any labels you wish to add?

Describe alternatives you've considered:

Let users do this manually after load - but I don't know of any way to do it in the UI. You can do it via code, by e.g. selecting the image plane and running imagePlane -e -detach.

Additional context:

Came up on discord here


Maya triggers via the UI:

importImagePlane { "topShape" };

Which triggers createImagePlane which has different logic for orthographic cameras to perspective cameras:

global proc string[] createImagePlane (string $camera)                                          
{
    //Initialize the parameters
    setOptionVars();

    // query orthographic flag of the camera.
    int $isOrtho = `camera -q -o $camera`;

    // Initialize the command's parameters
    float $width  = `optionVar -query freeImageWidth`;
    float $height = `optionVar -query freeImageHeight`;
    int    $mr      = `optionVar -query freeImageMR`;

    // create image plane
    string $newImagePlane[];

    string $attrName;

    string $lookThruCamera = `lookThru -q`;

    if ( $isOrtho == 1 ) {

        float $widthOrtho = `camera -q -orthographicWidth $camera`;

        // for orthographic camera, create free imageplane.
        $newImagePlane = `imagePlane -width $widthOrtho -height $widthOrtho -maintainRatio $mr -lookThrough $lookThruCamera`;

        // align imageplane to camera by orient-constraint.
        // OGS_TODO: no support for camera instance case, since just use $cameraTransforms[0].
        string $cameraTransforms[] = `listTransforms $camera`;

        // set camera rotation to imageplane
        $attrName = $cameraTransforms[0] + ".rotate";
        float $rot[] = `getAttr $attrName`;
        $attrName = $newImagePlane[0] + ".rotate";
        setAttr $attrName $rot[0] $rot[1] $rot[2];

        if ($cameraTransforms[0] != "top" && $cameraTransforms[0] != "side" && $cameraTransforms[0] != "front")
        {
            string $camreraTranslate = $cameraTransforms[0] + ".translate";
            float   $translate[] = `getAttr $camreraTranslate`; 
            move -worldSpace -moveXYZ $translate[0] $translate[1] $translate[2] $newImagePlane[0];
            move -relative -objectSpace 0 0 -5 $newImagePlane[0];
        }

    } else {

        // for perspective camera, create imageplane in underworld of the camera.
        // We will consider that if user(s) detach the image plane from the camera 
        // and the image plane will still respect the optionVars

        $newImagePlane = `imagePlane -camera $camera -width $width -height $height -maintainRatio $mr`;
    }

    // make camera visible to ensure the image plane outline is drawn and selectable.
    // consider cases where the camera name may be the same as another camera,
    // but inside a different hierarchy.
    //
    string $parents[] = `listRelatives -fullPath -parent $camera`;
    for ($item in $parents) showHidden $item;        

    return $newImagePlane;
}

In Maya 2025.2 when you have an attached image plane to an orthographic camera it behaves very erratically. It incorrectly updates the scale with the orthographic camera on zooming in and out and only updates when selecting the image plane - which makes it behave very confusingly. See:

https://github.com/user-attachments/assets/f5d131c5-7637-40be-86e0-56ab4a3f8644