refactor tables to calculate the index of the the row in the vec of instances

This commit is contained in:
indierusty
2025-06-28 08:39:18 +05:30
parent db141046a3
commit b1ee9cf412
7 changed files with 184 additions and 165 deletions
@@ -1481,7 +1481,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
DocumentNode {
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::network(concrete!(graphene_std::vector::VectorDataInstancesModification), 1)],
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::network(concrete!(graphene_std::vector::VectorDataModification), 1)],
manual_composition: Some(generic!(T)),
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::vector::vector_data::modification::PathModifyNode")),
..Default::default()
@@ -1495,7 +1495,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
}),
inputs: vec![
NodeInput::value(TaggedValue::VectorData(VectorDataTable::default()), true),
NodeInput::value(TaggedValue::VectorDataInstancesModification(Default::default()), false),
NodeInput::value(TaggedValue::VectorDataModification(Default::default()), false),
],
..Default::default()
},
@@ -5,7 +5,7 @@ use glam::{DAffine2, DVec2};
use graph_craft::document::NodeId;
use graphene_std::renderer::{ClickTarget, ClickTargetType, Quad};
use graphene_std::transform::Footprint;
use graphene_std::vector::{PointId, VectorData};
use graphene_std::vector::{PointId, VectorData, VectorDataTable};
use std::collections::{HashMap, HashSet};
use std::num::NonZeroU64;
@@ -20,9 +20,9 @@ pub struct DocumentMetadata {
pub upstream_footprints: HashMap<NodeId, Footprint>,
pub local_transforms: HashMap<NodeId, DAffine2>,
pub structure: HashMap<LayerNodeIdentifier, NodeRelations>,
pub click_targets: HashMap<LayerNodeIdentifier, Vec<ClickTarget>>,
pub click_targets: HashMap<LayerNodeIdentifier, HashMap<usize, Vec<ClickTarget>>>,
pub clip_targets: HashSet<NodeId>,
pub vector_modify: HashMap<NodeId, VectorData>,
pub vector_modify: HashMap<NodeId, VectorDataTable>,
/// Transform from document space to viewport space.
pub document_to_viewport: DAffine2,
}
@@ -14,7 +14,7 @@ use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, No
use graph_craft::{Type, concrete};
use graphene_std::renderer::{ClickTarget, ClickTargetType, Quad};
use graphene_std::transform::Footprint;
use graphene_std::vector::{PointId, VectorData, VectorModificationType};
use graphene_std::vector::{PointId, VectorData, VectorDataTable, VectorModificationType};
use interpreted_executor::dynamic_executor::ResolvedDocumentNodeTypes;
use interpreted_executor::node_registry::NODE_REGISTRY;
use serde_json::{Value, json};
@@ -3178,15 +3178,27 @@ impl NodeNetworkInterface {
(layer_widths, chain_widths, has_left_input_wire)
}
pub fn compute_modified_vector_table(&self, layer: LayerNodeIdentifier) -> Option<VectorDataTable> {
todo!()
}
pub fn compute_modified_vector(&self, layer: LayerNodeIdentifier) -> Option<VectorData> {
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, self);
if let Some(vector_data) = graph_layer.upstream_node_id_from_name("Path").and_then(|node| self.document_metadata.vector_modify.get(&node)) {
let mut modified = vector_data.clone();
if let Some(TaggedValue::VectorModification(modification)) = graph_layer.find_input("Path", 1) {
modification.apply(&mut modified);
let vector_data = graph_layer.upstream_node_id_from_name("Path").and_then(|node| self.document_metadata.vector_modify.get(&node));
let modification = graph_layer.find_input("Path", 1);
match (vector_data, modification) {
(Some(vector_data), Some(TaggedValue::VectorDataModification(modification))) => {
let mut vector_data = vector_data.clone();
for (index, vector_data_instance) in vector_data.instance_mut_iter().enumerate() {
if let Some(vector_modification) = modification.get(&index) {
vector_modification.apply(vector_data_instance.instance);
}
}
return Some(vector_data);
}
return Some(modified);
_ => {}
}
self.document_metadata
@@ -3361,7 +3373,7 @@ impl NodeNetworkInterface {
};
{
let mut value = node.inputs.get_mut(1).and_then(|input| input.as_value_mut());
let Some(TaggedValue::VectorModification(modification)) = value.as_deref_mut() else {
let Some(TaggedValue::VectorDataModification(modification)) = value.as_deref_mut() else {
panic!("Path node does not have modification input");
};
@@ -745,7 +745,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
let path_node_type = resolve_document_node_type("Path").expect("Path node does not exist.");
let path_node = path_node_type.node_template_input_override([
Some(NodeInput::value(TaggedValue::VectorData(VectorDataTable::new(vector_data)), true)),
Some(NodeInput::value(TaggedValue::VectorModification(Default::default()), false)),
Some(NodeInput::value(TaggedValue::VectorDataModification(Default::default()), false)),
]);
// Get the "Spline" node definition and wire it up with the "Path" node as input