Graphite icon indicating copy to clipboard operation
Graphite copied to clipboard

Tracking Issue: Instances tables

Open Keavon opened this issue 1 year ago • 0 comments

  • [x] 1. Write the Instances<T> struct. Wrap VectorData to become Instances<VectorData>, ImageFrame to become Instances<ImageFrame>, GraphicGroup to become Instances<GraphicGroup>, which lets us leave transform/alpha_blending alone for now. Places that read the single piece of data now read from a "getter" function that calls .next().expect("...") and write to a "setter" function that loops through each row (but there's just 1 presently). (#2230)
  • [x] 2. Move the transform/alpha_blending up a level, which removes those fields from VectorData, ImageFrame, and GraphicGroup. (#2249)
  • [x] 3. Since the ImageFrame<P> struct now has only one field left (pub image: Image<P>), delete this redundant struct and replace its usage in Instances<ImageFrame<P>> with Instances<Image<P>>. (#2256)
  • [x] 4. Wrap ArtboardGroup to become Instances<ArtboardGroup>. Since the ArtboardGroup struct now has only one field (artboards: Vec<(Artboard, Option<NodeId>)>), delete this redundant struct and replace its usage with Instances<Artboard>. Move the Option<NodeId> to be an attribute called source_node_id in Instances<T>. (#2265)
  • [x] 5. Since the GraphicGroup struct now has only one field left (elements: Vec<(GraphicElement, Option<NodeId>)>), delete this redundant struct and replace its usage in Instances<GraphicGroup> with Instances<GraphicElement>. Move the Option<NodeId> to the source_node_id attribute in Instances<T>. At this point, we have multi-row tables for group data but single-row image and vector data tables. (#2363)
  • [x] 6. Remove all usages of .one_instance_ref() and .one_instance_mut() by replacing their usages with loops or fold/reduce as needed in the nodes that currently expect one value but now need to work on multiple rows of values. Once this is done, nodes won't panic when we have a zero-row table. So we can replace usages of the form VectorDataTable::new(VectorData::empty()) with an actual empty table. Now, we have nodes that can accept table data of any row counts, and will often map N rows to N rows, but we don't have any nodes that actually produce more than 1 row as output yet unless given more than 1 row. But the repeat style nodes all currently output groups, not multi-rows of vector or raster, which we change in the next step. (db34ac3f53b5e9905a71b48fa464e8ca8f52293d, 2cee9e24cd43b2fadefbcfccf03f91417a665dd2, #2672, #2684, #2689)
  • [x] 7. Change RasterFrame (an enum of ImageFrameTable<Color> = Instances<Image<Color>> and TextureFrameTable = Instances<ImageTexture> variants) to RasterTable = Instances<Raster>, where Raster is an enum of Image<Color> and ImageTexture variants. (~~#2693~~, 5cacab2e390d658e022f7c07305be18787c3db53, 6111440afd932bbd4640eda6fe45eec5d759340f)
  • [x] 8. Change the Repeat/Circular Repeat/Copy to Points node to no longer create a level of grouping, so they map from Instances<T> to Instances<T>, not from Instances<T> to Instances<GraphicElement>, now that we have (in the previous step) ensured all other nodes are able to work correctly with multiple instances instead of assuming a single instance. Investigate also doing this for the Merge node, making it generic over its input types, so we can have homogenous layer stacks to keep the data entropy down. (#2697, #2699)
  • [ ] 9. Clean up all terminology and naming.

Initial

type GraphicElement = VectorData | GraphicGroup;

struct VectorData {
    transform: DAffine2,
}

struct GraphicGroup {
    transform: DAffine2,
    elements: Vec<GraphicElement>,
}

Wrapped in table

type GraphicElement = VectorDataTable | GraphicGroupTable;

struct VectorData {
    // transform has been moved to the table
}
type VectorDataTable = struct Instances<VectorData> {
    transform: Vec<DAffine2>, // count = 1
    instance: Vec<VectorData>, // count = 1
}

struct GraphicGroup {
    // transform has been moved to the table, but not up to the parent group
    elements: Vec<GraphicElement>,
}
type GraphicGroupTable = struct Instances<GraphicGroup> {
    transform: Vec<DAffine2>, // count = 1, parent to all in self.instance[0].elements
    instance: Vec<GraphicGroup>, // count = 1
}

(Inlined GraphicGroup)

type GraphicElement = VectorDataTable | GraphicGroupTable;

struct VectorData {
    // transform has been moved to the table
}
type VectorDataTable = struct Instances<VectorData> {
    transform: Vec<DAffine2>, // count = 1
    instance: Vec<VectorData>, // count = 1
}

type GraphicGroupTable = struct Instances<Vec<GraphicElement>> {
    transform: Vec<DAffine2>, // count = 1, parent to all in self.instance[0]
    instance: Vec<Vec<GraphicElement>>, // count = 1
}
// Document root
// ├─ Top folder
// │  ├─ Inner vector 1
// │  └─ Inner vector 2
// └─ Top vector

// Document root
GraphicGroupTable {
    transform: vec![ // count = 1
        DAffine2::IDENTITY,
    ],
    instance: vec![ // count = 1
        vec![
            // Top folder
            GraphicGroupTable {
                transform: vec![ // count = 1
                    DAffine2::TOP_FOLDER,
                ],
                instance: vec![ // count = 1
                    vec![
                        // Inner vector 1
                        VectorDataTable {
                            transform: vec![ // count = 1
                                DAffine2::INNER_VECTOR_1,
                            ],
                            instance: vec![ // count = 1
                                VectorData {},
                            ],
                        },
                        // Inner vector 2
                        VectorDataTable {
                            transform: vec![ // count = 1
                                DAffine2::INNER_VECTOR_2,
                            ],
                            instance: vec![ // count = 1
                                VectorData {},
                            ],
                        },
                    ],
                ],
            },
            // Top vector
            VectorDataTable {
                transform: vec![ // count = 1
                    DAffine2::TOP_VECTOR,
                ],
                instance: vec![ // count = 1
                    VectorData {},
                ],
            },
        ],
    ],
}

Flattened GraphicGroup with transform moved to parent

type GraphicElement = VectorDataTable | GraphicGroupTable;

struct VectorData {
    // transform has been moved to the table
}
type VectorDataTable = struct Instances<VectorData> {
    transform: Vec<DAffine2>, // count = 1
    instance: Vec<VectorData>, // count = 1
}

type GraphicGroupTable = struct Instances<GraphicElement> {
    transform: Vec<DAffine2>, // parent to its corresponding element in self.instance
    instance: Vec<GraphicElement>,
}
// Document root
// ├─ Top folder
// │  ├─ Inner vector 1
// │  └─ Inner vector 2
// └─ Top vector

// Document root
GraphicGroupTable {
    transform: vec![
        DAffine2::TOP_FOLDER,
        DAffine2::TOP_VECTOR,
    ],
    instance: vec![
        // Top folder
        GraphicGroupTable {
            transform: vec![
                DAffine2::IDENTITY, // from the Merge layer node
                DAffine2::IDENTITY, // from the Merge layer node
            ],
            instance: vec![
                // Inner vector 1
                VectorDataTable {
                    transform: vec![ // count = 1
                        DAffine2::INNER_VECTOR_1,
                    ],
                    instance: vec![ // count = 1
                        VectorData {},
                    ],
                },
                // Inner vector 2
                VectorDataTable {
                    transform: vec![ // count = 1
                        DAffine2::INNER_VECTOR_2,
                    ],
                    instance: vec![ // count = 1
                        VectorData {},
                    ],
                },
            ],
        },
        // Top vector
        VectorDataTable {
            transform: vec![ // count = 1
                DAffine2::IDENTITY,
            ],
            instance: vec![ // count = 1
                VectorData {},
            ],
        },
    ],
}

Keavon avatar Jul 15 '24 08:07 Keavon