Building new Node types

This is a thread to discuss how to build new Node types in an add-on and any issues you might run into along the way.

This page provides a good starting point:

I’m following up here on @valentin’s suggestion to @alinashah to build a new node type that will execute a loop a certain number of times before stopping.

A bit about nodes:

Most tools use the default type of node (simply named “node”). This is a small program associated with a tool that gets saved and executed on the Node.js Edge Server. A good thing about nodes is that they continue to work even when the AR app is not open! This is why we can connect IoT devices together via their nodes, and the IoT devices still work together even when the app closes.

The default node type just forwards data to anything it is linked to. But there are other node types, too! For example, the limiter tool in the core-addon (the one that lets you set a threshold) uses a node type called “limiter” by passing in the string “limiter” for the second parameter instead of “node”: spatialInterface.initNode('in_out', 'limiter', 0, 0). This node type has a property called max that can be written to using the API spatialInterface.writePublicData("in_out", "max", limits.max) to configure a property in the node’s program.

Inside that node’s program, it compares the value it receives to its max to decide whether to output a 0 or a 1, accordingly. You might notice that the way a node is implemented looks pretty similar to how a logic block is implemented, so if you know how to build a logic block you are on track to build a node.

@dangond is currently in the process of building a new node type, so he can help answer some questions. He’s also uncovering some bugs related to nodes that we may have to fix in order for your new node to fully work.