MCPcopy Index your code
hub / github.com/processing/p5.js / bridge

Method bridge

src/strands/strands_node.js:40–91  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

38 };
39 }
40 bridge(value) {
41 const { dag, cfg } = this.strandsContext;
42 const orig = getNodeDataFromID(dag, this.id);
43 const baseType = orig?.baseType ?? BaseType.FLOAT;
44
45 let newValueID;
46 if (value?.isStrandsNode) {
47 newValueID = value.id;
48 } else {
49 const newVal = primitiveConstructorNode(
50 this.strandsContext,
51 { baseType, dimension: this.dimension },
52 value
53 );
54 newValueID = newVal.id;
55 }
56
57 // For varying variables, we need both assignment generation AND a way to reference by identifier
58 if (this._originalIdentifier) {
59 // Create a variable node for the target (the varying variable)
60 const { id: targetVarID } = variableNode(
61 this.strandsContext,
62 { baseType: this._originalBaseType, dimension: this._originalDimension },
63 this._originalIdentifier
64 );
65
66 // Create assignment node for GLSL generation
67 const assignmentNode = createNodeData({
68 nodeType: NodeType.ASSIGNMENT,
69 dependsOn: [targetVarID, newValueID],
70 phiBlocks: []
71 });
72 const assignmentID = getOrCreateNode(dag, assignmentNode);
73 recordInBasicBlock(cfg, cfg.currentBlock, assignmentID);
74
75 // Simply update this node to be a variable node with the identifier
76 // This ensures it always generates the variable name in expressions
77 const variableNodeData = createNodeData({
78 nodeType: NodeType.VARIABLE,
79 baseType: this._originalBaseType,
80 dimension: this._originalDimension,
81 identifier: this._originalIdentifier
82 });
83 const variableID = getOrCreateNode(dag, variableNodeData);
84
85 this.id = variableID; // Point to the variable node for expression generation
86 } else {
87 this.id = newValueID; // For non-varying variables, just update to new value
88 }
89
90 return this;
91 }
92 bridgeSwizzle(swizzlePattern, value) {
93 const { dag, cfg } = this.strandsContext;
94 const orig = getNodeDataFromID(dag, this.id);

Callers

nothing calls this directly

Calls 6

getNodeDataFromIDFunction · 0.90
primitiveConstructorNodeFunction · 0.90
variableNodeFunction · 0.90
createNodeDataFunction · 0.90
getOrCreateNodeFunction · 0.90
recordInBasicBlockFunction · 0.90

Tested by

no test coverage detected