opendesigndev / octopus-specs

Octopus format specification (OpenAPI)
https://main.d215pdpdn4c7ow.amplifyapp.com/
2 stars 3 forks source link

Octopus 3 mask proposal #56

Closed scoiatael closed 1 year ago

scoiatael commented 1 year ago

In GitLab by @viktorchlumsky on Oct 27, 2021, 11:23

Example case

Artboard: clipping-mask-example

Mask: clipping-mask-mask

Layer hierarchy in editor UI: image

Current state

Layers in editor UI order, everyone must hope that nothing comes between layer X and layers maskedBy X.

{
    "layers": [
        { "id": "Regular layer E" },
        { "id": "Masked layer D", "clipped": true, "maskedBy": "Masking group G" },
        { "id": "Masked layer C", "clipped": true, "maskedBy": "Masking group G" },
        {
            "id": "Masking group G",
            "clippingMode": "photoshopClippingMask",
            "children": [
                { "id": "Masking layer B" },
                { "id": "Masking layer A" }
            ]
        }
    ]
}

Variant A - inlays as they are currently used in Rendering

Layers in drawing order, any layer can have an array of inlays - descendant layers.

{
    "layers": [
        {
            "id": "Masking group G",
            "clippingMode": "photoshopClippingMask",
            "children": [
                { "id": "Masking layer A" },
                { "id": "Masking layer B" }
            ],
            "inlays": [
                { "id": "Masked layer C" },
                { "id": "Masked layer D" }
            ]
        },
        { "id": "Regular layer E" }
    ]
}

Main downside is that traversal of layer tree requires not only children of group layers but also "inlays" of all layers.

Variant B - special mask group layer type

The mask group does not represent an actual layer / group layer, but serves as a special node in the hierarchy.

Variant B1

In the B1 variant, the first child of a mask group is the mask.

{
    "layers": [
        {
            "type": "maskGroup",
            "id": "XYZ",
            "clippingMode": "photoshopClippingMask",
            "children": [
                {
                    "type": "group",
                    "id": "Masking group G",
                    "children": [
                        { "type": "shape", "id": "Masking layer A" },
                        { "type": "shape", "id": "Masking layer B" }
                    ]
                },
                { "type": "shape", "id": "Masked layer C" },
                { "type": "shape", "id": "Masked layer D" }
            ]
        },
        { "type": "shape", "id": "Regular layer E" }
    ]
}

The main upside is that traversal of the layer tree always only uses the children array and nothing else.

Variant B2

In the B2 variant, the mask is not part of the children array, but a separate member. This is better in that no element of the array has a special meaning just because of its array index. On the other hand, traversing all layers no longer requires reading children arrays only.

{
    "layers": [
        {
            "type": "maskGroup",
            "id": "XYZ",
            "clippingMode": "photoshopClippingMask",
            "mask": {
                "type": "group",
                "id": "Masking group G",
                "children": [
                    { "type": "shape", "id": "Masking layer A" },
                    { "type": "shape", "id": "Masking layer B" }
                ]
            },
            "children": [
                { "type": "shape", "id": "Masked layer C" },
                { "type": "shape", "id": "Masked layer D" }
            ]
        },
        { "type": "shape", "id": "Regular layer E" }
    ]
}
scoiatael commented 1 year ago

In GitLab by @janroztocil on Oct 27, 2021, 11:36

moved to opendesign/octopus#5