Graphite
Graphite copied to clipboard
Tracking Issue: Instances tables
- [x] 1. Write the
Instances<T>struct. WrapVectorDatato becomeInstances<VectorData>,ImageFrameto becomeInstances<ImageFrame>,GraphicGroupto becomeInstances<GraphicGroup>, which lets us leavetransform/alpha_blendingalone 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_blendingup a level, which removes those fields fromVectorData,ImageFrame, andGraphicGroup. (#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 inInstances<ImageFrame<P>>withInstances<Image<P>>. (#2256) - [x] 4. Wrap
ArtboardGroupto becomeInstances<ArtboardGroup>. Since theArtboardGroupstruct now has only one field (artboards: Vec<(Artboard, Option<NodeId>)>), delete this redundant struct and replace its usage withInstances<Artboard>. Move theOption<NodeId>to be an attribute calledsource_node_idinInstances<T>. (#2265) - [x] 5. Since the
GraphicGroupstruct now has only one field left (elements: Vec<(GraphicElement, Option<NodeId>)>), delete this redundant struct and replace its usage inInstances<GraphicGroup>withInstances<GraphicElement>. Move theOption<NodeId>to thesource_node_idattribute inInstances<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 formVectorDataTable::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 ofImageFrameTable<Color> = Instances<Image<Color>>andTextureFrameTable = Instances<ImageTexture>variants) toRasterTable = Instances<Raster>, whereRasteris an enum ofImage<Color>andImageTexturevariants. (~~#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>toInstances<T>, not fromInstances<T>toInstances<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 {},
],
},
],
}