Running Visual Scripts with Bitbybit Runner
The Bitbybit platform allows you to create complex 3D geometry and interactive scenes using visual programming environments like Rete. But what if you want to take these creations and run them on your own website, outside of the Bitbybit editor? That's where the Bitbybit Runner comes in!
The Runner is a JavaScript library that can execute scripts exported from our visual editors (like Rete) directly in a browser environment, typically rendering the output using BabylonJS. This tutorial will guide you through the process of using an exported Rete script with the Bitbybit Runner.
The Rete Script: An Alloy Wheel Concept
First, let's look at the Rete script we'll be working with. This script designs a concept for an alloy wheel using various OpenCascade (OCCT) operations. It involves creating lines, rotating them, dividing wires, lofting surfaces, and applying fillets to create a detailed 3D model.
Below is an interactive preview of the Rete visual program. You can see the nodes and connections that define the geometry.
Exporting the Script for the Runner
When you are ready to use your Rete script outside the Bitbybit editor, you typically export it in a format that the runner can understand. This usually involves generating a JavaScript function that encapsulates the logic of your visual program. The Bitbybit platform provides an option to "Export to Runner", which gives you a JavaScript string for the Runner. You can even minify it.
The core of this exported JavaScript will be a self-executing asynchronous function that takes instances of BitByBit (the core library), bitbybit (the API access object), bitbybitRunnerResult (for outputs), and bitbybitRunnerInputs (for inputs) as arguments. This static model does not need any of those as it does not take any inputs or produce any outputs for the runner.
Live Demo: Understanding the Runner in Action
To see how all these pieces (HTML, Runner Library, and your exported script logic) come together, we've set up a live demonstration using StackBlitz.
Why is this StackBlitz demo important?
- Simulates Your Website: The StackBlitz environment effectively represents how this setup would work on your own website. It's a self-contained project with its own
index.html,styles.css, andscript.js– just like you would have if you were integrating this into your web application. - Practical Application: It moves beyond theory and shows a tangible example of the runner in use. You can inspect the code, see the rendered 3D output, and understand the minimal requirements for embedding Bitbybit-generated content.
- Deployment Context: This demonstrates that projects built this way are not confined to the Bitbybit platform. You can deploy these kinds of projects on your own hosting providers (like Netlify, Vercel, GitHub Pages, or your own servers) and have full control over the user experience and integration with other web technologies.
- Experimentation Sandbox: StackBlitz allows you (and your users) to fork the example and experiment with changes to the HTML, CSS, or even the
runnerOptionsinscript.jsto see immediate results.
By exploring the StackBlitz demo, you can gain confidence in how to take your visual programs from the Bitbybit editor and bring them to life anywhere on the web.
Setting up Your HTML Page
To use the runner on your own website, you'll need a basic HTML structure.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bitbybit Runner Example</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="styles.css" />
{/* Step 1: Include the Bitbybit Runner library */}
<script src="https://git-cdn.bitbybit.dev/latest/runner/bitbybit-runner-babylonjs.js"></script>
{/* Step 2: Include your custom script that uses the runner */}
<script defer type="module" src="script.js"></script>
</head>
<body>
<div className="example">
<a
class="logo"
href="https://bitbybit.dev"
target="_blank"
rel="noopener noreferrer"
>
<img
alt="Logo of Bit by bit developers company"
src="https://bitbybit.dev/logo-gold-small.png"
/>
<div>bitbybit.dev</div>
</a>
<h1>Runner Example - Alloy Wheel</h1>
{/* Step 3: Define a canvas element for rendering */}
<div className="myCanvasZone">
<canvas id="myCanvas"></canvas>
</div>
<a
href="https://bitbybit.dev/projects/public/EMfBhqxbI5DibbwVactv/script/7LRqBI8nFqx32lXiK3G1/script-rete-script-alloy-wheel-cad-model-in-project-3d-alloy-wheel-cad-concept-by-author-matas"
target="_blank"
rel="noopener noreferrer"
>
Link to original Rete script.
</a>
</div>
</body>
</html>
// Step 1: Define Runner Options
const runnerOptions = {
canvasId: 'myCanvas', // ID of the canvas element in your HTML
canvasZoneClass: 'myCanvasZone',// Class of the canvas container for resizing
enablePhysics: false, // Set to true if your script uses physics
enableOCCT: true, // Crucial: Set to true as our Rete script uses OCCT
enableJSCAD: false, // Set to true if using JSCAD
enableManifold: false, // Set to true if using Manifold
enableKeyEventListeners: false, // Enable if script needs to handle keyboard input (usually only Blockly or TypeScript...)
loadFonts: [], // Array of font file URLs if script uses custom 3D text fonts
};
// Step 2: Get the Runner Instance and Initialize
// The runner is globally available via window.bitbybitRunner after including the library.
const runner = window.bitbybitRunner.getRunnerInstance();
await runner.run(runnerOptions); // Asynchronously initializes the runner and BabylonJS scene
// Step 3: Define or Import Your Exported Rete Script
// This function returns the string of JavaScript code generated from your Rete editor.
// In a real application, this string might be loaded from a file, a database, or embedded directly.
function exportedScript() {
// This is the very long JavaScript string generated by "Export to Runner" from Rete.
// It starts with "!async function(e,t,s,n,r){..." where e=BitByBit, t=bitbybit, etc.
return '{"type":"rete","script":"!async function(e,t,s,n,r){let a={};a={x:[0],y:[0],z:[1],...a};const o=[{result:e.HS.executeBasedOnType(a,!1,(e=>t.vector.vectorXYZ(e))),transformers:[]}]; ... (rest of the very long exported JS string) ... }(BitByBit,bitbybit,bitbybitRunnerResult,bitbybitRunnerInputs,Bit);"}'
}
// Step 4: Execute the Script
// The second argument to executeScript can pass input values to your script if it's designed to accept them.
runner.executeScript(exportedScript(), {});
We also needed some styling to make it pretty... :)
body {
margin: 0;
background-color: #1a1c1f;
color: white;
font-weight: 400;
font-family: 'IBM Plex Sans', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
width: 100%;
height: 100%;
}
.example {
margin-top: 50px;
margin-bottom: 50px;
margin-left: 300px;
margin-right: 300px;
}
@media(max-width:1400px) {
.example {
margin-left: 100px;
margin-right: 100px;
}
}
@media(max-width:769px) {
.example {
margin-left: 20px;
margin-right: 20px;
}
}
#myCanvas {
display: block;
outline: none;
border: 1px solid white;
border-radius: 5px;
width: 100%;
}
.logo {
margin-bottom: 20px;
}
.logo img {
width: 50px;
height: 50px;
}
.myCanvasZone {
margin-top: 20px;
margin-bottom: 10px;
}
a {
color: white;
vertical-align: middle;
}
Conclusion
In this tutorial, you've learned the essential steps to take a visual script created in Bitbybit's Rete editor and run it on an external webpage. We covered how to set up a basic HTML page, include the Bitbybit Runner library, configure runner options (crucially, enabling the Bitbybit OCCT Kernel for our example), and finally, execute the exported JavaScript string representing your Rete program. This empowers you to integrate your powerful 3D creations and geometric algorithms directly into your own web projects.

