hi,
Sorry for the late reply, but this needed investigation and test from my side and communication between me and the dev.
You can create the NodeTemplate that way. I am using the class GradientWorkaround to create the template.
NodesLib::BuildNodeFromDescription must be called with false set to not create the dependency wires.
NodeTemplate t = NodesLib::CreateLazyTemplate(firstNodeId,
[firstNodeId]() -> Result<NodeTemplate>
{
iferr_scope;
maxon::nodes::NodeTemplate templ = maxon::nodes::NodesLib::BuildNodeFromDescription(firstNodeId, CoreNodesNodeSystemClass(), false) iferr_return;
templ = GradientWorkaround::CreateInit(templ) iferr_return;
return templ;
}, CoreNodesNodeSystemClass()) iferr_return;
The class itself look like this. We can create a gradient node inside the usernode itself and connect the ports. This is done inside the function InstantiateImpl.
class GradientWorkaround : public maxon::Component<GradientWorkaround, maxon::nodes::NodeTemplateInterface>
{
MAXON_COMPONENT(NORMAL, maxon::nodes::NodeTemplateBaseClass);
public:
maxon::ResultOk<void> Init(const maxon::nodes::NodeTemplate& templ)
{
_wrapped = templ;
return maxon::OK;
}
MAXON_METHOD maxon::Result<Bool> SupportsImpl(const maxon::nodes::NodeSystemClass& cls) const
{
return cls.IsSubclassOf(CoreNodesNodeSystemClass());
}
MAXON_METHOD maxon::Result<maxon::nodes::NodeSystem> InstantiateImpl(const maxon::nodes::InstantiationTrace& parent, const maxon::nodes::TemplateArguments& args) const
{
iferr_scope;
maxon::nodes::NodeSystem sys = _wrapped.Instantiate(parent, args) iferr_return;
maxon::nodes::MutableRoot root = sys.BeginInstantiationModification(self) iferr_return;
// Asset ID : net.maxon.pattern.node.generator.gradient
const AssetRepositoryRef& repository = AssetInterface::GetBuiltinRepository();
nodes::NodeTemplate gradient = nodes::NodesLib::LoadTemplate(repository, Id("net.maxon.pattern.node.generator.gradient")) iferr_return;
MutableNode gradientNode = root.AddChild(Id("Gradient"), gradient) iferr_return;
const maxon::nodes::MutablePort output = root.GetOutputs().FindPort(maxon::Id("testoutput")) iferr_return;
const maxon::nodes::MutablePort gradientPort = root.GetInputs().FindPort(maxon::Id("gradient")) iferr_return;
const maxon::nodes::MutablePort gradientResult = gradientNode.GetOutputs().FindPort(maxon::Id("result")) iferr_return;
const maxon::nodes::MutablePort gradientGradient = gradientNode.GetInputs().FindPort(maxon::Id("gradient")) iferr_return;
gradientResult.Connect(output) iferr_return;
gradientPort.Connect(gradientGradient) iferr_return;
sys = root.EndModification() iferr_return;
return sys;
}
private:
maxon::nodes::NodeTemplate _wrapped;
};
MAXON_COMPONENT_CLASS_REGISTER(GradientWorkaround, "net.maxonexample.nodes.class.gradientworkaround");
It is just like having a group of nodes and propagated ports.
Cheers,
Manuel