Custom Node API

The custom node API provides an easy way to create your custom nodes. While Polygonjs Already offer many different nodes for different situations, there might be cases when you would want to:

  • Integrate with a custom library.
  • Experiment different ways to create geometry.
  • Create a custom material.
  • Or simply do things that Polygonjs has not thought of yet.

You can use the presets available in the code editor and read the comments available. This should give you a good start in understanding what methods should be edited in your node.

The most important ones are:

create_params(){}

This is where you will add the parameters available to the node interface.

You would typically write this to create a single parameter called amount of type float and with a default value of 1.

create_params(){
	this.add_param( POLY.ParamType.FLOAT, 'amount', 1 )
}

And then you would need a cook method, which is called each time your node is computed (or cooked):

cook(input_contents){
	const core_group = input_contents[0]
	console.log(this._param_amount)
	this.set_core_group(core_group)
}

This would do nothing, as it would simply take the input and set it as the output. But it would print in the developer console the value of the amount parameter.

The whole code for the node would look like this:

// Custom Geometry nodes must inherit from POLY.CustomNode.SOP
class MoveOnePoint extends POLY.CustomNode.SOP {
	constructor(){
		super();
		this.set_inputs_count(1)
	}

	create_params() {
		this.add_param( POLY.ParamType.FLOAT, 'amount', 1 )
	}

	cook(input_contents){
		const core_group = input_contents[0]
		console.log(this._param_amount)
		this.set_core_group(core_group)
	}
}

And that's it! That's all you need to know to create your own node inside Polygonjs. With this in mind, try using the editor below and use the presets to load different examples:

Create a Custom Geometry Node

View Full Screen

Create a Custom Material

While the tutorial above only shows an example of a custom Geometry node, you can also create a custom Material. Use the presets shown in the tutorial to see different examples of materials.