5. Examples
5.1. Example 1 - Hello!
The following Graph takes a string input Binding called Name
, appends it to the string "Hello, "
, and uses the
DebugLog
Node to print out the resulting string. Note that because this Graph has no Bindings or Nodes that use
Resource<T> types, a Catalog file is not required.
- Graph
hello.ubp.json
{
"version": "0.2.0",
"nodes": [
{
"id": "BEvdkjZCwl8qD055QozRn",
"type": "Entry",
"inputs": [],
"outputs": [
{
"id": "Exec",
"type": "exec"
}
]
},
{
"id": "MdJXyUsqtoli7gjdGO59R",
"type": "DebugLog",
"inputs": [
{
"id": "Exec",
"type": "exec",
"value": null
},
{
"id": "Message",
"type": "string",
"value": ""
}
],
"outputs": [
{
"id": "Exec",
"type": "exec"
}
]
},
{
"id": "fKGLkFH1mrFDWDVG2NS9l",
"type": "Append",
"inputs": [
{
"id": "A",
"type": "string",
"value": "Hello, "
},
{
"id": "B",
"type": "string"
}
],
"outputs": [
{
"id": "String",
"type": "string"
}
]
},
{
"id": "ZqJWjQv1X7r4UHL1ez7hg",
"type": "Input",
"inputs": [
{
"id": "Input",
"type": "unknown",
"value": "Name"
}
],
"outputs": [
{
"id": "Value",
"type": "string"
}
]
}
],
"connections": [
{
"source": "BEvdkjZCwl8qD055QozRn",
"target": "MdJXyUsqtoli7gjdGO59R",
"sourceKey": "Exec",
"targetKey": "Exec"
},
{
"source": "ZqJWjQv1X7r4UHL1ez7hg",
"target": "fKGLkFH1mrFDWDVG2NS9l",
"sourceKey": "Value",
"targetKey": "B"
},
{
"source": "fKGLkFH1mrFDWDVG2NS9l",
"target": "MdJXyUsqtoli7gjdGO59R",
"sourceKey": "String",
"targetKey": "Message"
}
],
"bindings": [
{
"id": "Name",
"scope": "input",
"type": "string",
"value": ""
}
],
"fns": {}
}
5.2. Example 2 - Instantiating a Mesh
In this example, the Graph has an Binding of type Resource<Mesh>
, which it instantiates in the scene with the
SpawnMesh
Node. It then sets the first MeshRenderer
as an output Binding. This could allow other Graphs to use that
value to apply a material to the mesh. The Catalog file contains the Resource entry for the mesh, which is hosted
online. Notice that the value of the Mesh
Binding - my-mesh-resource
- matches the id
field in the Catalog.
- Graph
- Catalog
mesh.ubp.json
{
"version": "0.2.0",
"nodes": [
{
"id": "F6LffngtRl6R6Jw1I3FAe",
"type": "Entry",
"inputs": [],
"outputs": [
{
"id": "Exec",
"type": "exec"
}
]
},
{
"id": "60qKMsQ9rrWuhu3VPBtH2",
"type": "SpawnMesh",
"inputs": [
{
"id": "Exec",
"value": null,
"type": "exec"
},
{
"id": "Resource",
"value": "",
"type": "Resource<Mesh>"
},
{
"id": "Parent",
"value": null,
"type": "SceneNode"
},
{
"id": "Config",
"value": null,
"type": "MeshConfig"
}
],
"outputs": [
{
"id": "Exec",
"type": "exec"
},
{
"id": "Scene Nodes",
"type": "Array<SceneNode>"
},
{
"id": "Renderers",
"type": "Array<MeshRenderer>"
}
]
},
{
"id": "3tz2NP4tUBnqytZPpO5wX",
"type": "Input",
"inputs": [
{
"id": "Input",
"value": "Parent",
"type": "unknown"
}
],
"outputs": [
{
"id": "Value",
"type": "SceneNode"
}
]
},
{
"id": "kiZp9B73SNNvx9BfxTnZM",
"type": "Input",
"inputs": [
{
"id": "Input",
"value": "Config",
"type": "unknown"
}
],
"outputs": [
{
"id": "Value",
"type": "MeshConfig"
}
]
},
{
"id": "lAhHgq8bxnM9ztik7cpUq",
"type": "First",
"inputs": [
{
"id": "Array",
"value": null,
"type": "Array<MeshRenderer>"
}
],
"outputs": [
{
"id": "Element",
"type": "MeshRenderer"
}
]
},
{
"id": "o3MtpEo67tixMfnFAwUJr",
"type": "Input",
"inputs": [
{
"id": "Input",
"value": "Mesh",
"type": "unknown"
}
],
"outputs": [
{
"id": "Value",
"type": "Resource<Mesh>"
}
]
},
{
"id": "k9lnQ2C6XsbuiCuzwOdOx",
"type": "Set",
"inputs": [
{
"id": "Input",
"value": "SpawnedRenderer",
"type": "unknown"
},
{
"id": "Exec",
"value": null,
"type": "exec"
},
{
"id": "Value",
"value": null,
"type": "MeshRenderer"
}
],
"outputs": [
{
"id": "Exec",
"type": "exec"
}
]
}
],
"connections": [
{
"source": "F6LffngtRl6R6Jw1I3FAe",
"target": "60qKMsQ9rrWuhu3VPBtH2",
"sourceKey": "Exec",
"targetKey": "Exec"
},
{
"source": "3tz2NP4tUBnqytZPpO5wX",
"target": "60qKMsQ9rrWuhu3VPBtH2",
"sourceKey": "Value",
"targetKey": "Parent"
},
{
"source": "kiZp9B73SNNvx9BfxTnZM",
"target": "60qKMsQ9rrWuhu3VPBtH2",
"sourceKey": "Value",
"targetKey": "Config"
},
{
"source": "60qKMsQ9rrWuhu3VPBtH2",
"target": "lAhHgq8bxnM9ztik7cpUq",
"sourceKey": "Renderers",
"targetKey": "Array"
},
{
"source": "o3MtpEo67tixMfnFAwUJr",
"target": "60qKMsQ9rrWuhu3VPBtH2",
"sourceKey": "Value",
"targetKey": "Resource"
},
{
"source": "60qKMsQ9rrWuhu3VPBtH2",
"target": "k9lnQ2C6XsbuiCuzwOdOx",
"sourceKey": "Exec",
"targetKey": "Exec"
},
{
"source": "lAhHgq8bxnM9ztik7cpUq",
"target": "k9lnQ2C6XsbuiCuzwOdOx",
"sourceKey": "Element",
"targetKey": "Value"
}
],
"bindings": [
{
"id": "Parent",
"scope": "input",
"type": "SceneNode",
"value": null
},
{
"id": "Config",
"scope": "input",
"type": "MeshConfig",
"value": null
},
{
"id": "Mesh",
"scope": "var",
"type": "Resource<Mesh>",
"value": "my-mesh-resource"
},
{
"id": "SpawnedRenderer",
"scope": "output",
"type": "MeshRenderer",
"value": null
}
],
"fns": {}
}
catalog.json
{
"version": "0.2.0",
"resources": [
{
"id": "my-mesh-resource",
"uri": "https://example.com/my-mesh.glb",
"hash": ""
}
]
}