Three Script Module
Write JavaScript for your scene, share it across nodes
- module
At some point the fixed set of Three nodes isn't enough - you want a material recipe that takes a dozen parameters, or a geometry that's a specific formula. That's what WASThreeScriptModule is for. It lets you write JavaScript that runs in the browser and builds several named resources in one place, then hands them out through Three Import Material, Three Import Geometry and Three Import Object. It's the escape hatch that turns the node set into an open programming environment.
How it works
The node takes two inputs: a module_name and a javascript body. The body runs in your browser and must return an object whose keys are the names of the resources it built. Those names are what Three Import Material and friends reference, so a module named "my_palette" returning { gold, chrome, matte } can feed materials into any number of Three Mesh nodes.
The performance design is the point: the module runs once per viewer load, not once per node. So a palette of materials shared across many meshes is built a single time, instead of every mesh that references it rebuilding the whole thing. It pairs with the pack's deduplication - identical descriptors share one browser-side resource - so a scene with fifty meshes sharing a module-built material stays cheap.
What it can reach
Here's the honest warning, straight from the node's description: "The code runs in your browser, with the same reach as any frontend extension." The JavaScript has full access to the ComfyUI frontend environment - not sandboxed, not restricted to some toy API. That's what makes it powerful, and it's also why you should only run a workflow carrying custom JavaScript if you trust where it came from. This is the same trust model as any frontend extension, and a shared workflow with an embedded Script Module is effectively running arbitrary code in your browser. Treat downloaded graphs with JavaScript bodies the way you'd treat a random browser extension.
What's actually useful to build
In practice people use this for the stuff that would otherwise mean fifty copies of the same node settings:
- a material library - standard/physical/shader materials parameterized and returned by name,
- custom geometries that are easier expressed in code than in a dozen node parameters,
- reusable helper objects - a light rig, a grid, an assembled prop.
The three consumer nodes - Three Import Material, Three Import Geometry, Three Import Object - are how those named resources get pulled back into the node graph, which is what makes the module reusable across the whole scene rather than a one-shot experiment.
Install
WASThreeScriptModule ships with WAS Node Suite v3. Install via ComfyUI Manager (search WAS Node Suite v3) or:
cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git
Restart after. Requires ComfyUI 0.14.0+ and Python 3.10+. If the node's missing from Add Node, check features.threejs in <ComfyUI user dir>/was-node-suite/config.yaml - the key defaults on in current releases but is what gates the whole Three family.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| module_name | STRING | custom | Label for this module, such as 'palette'. Two modules may not share a name. |
| javascript | STRING | return { gold: new THREE.MeshStandardMaterial({color: "#d8b24a", metalness: 0.8, roughness: 0.2}), ring: new THREE.TorusGeometry(1, 0.2, 24, 96) }; | A body returning named resources, as `return {gold: new THREE.MeshStandardMaterial({})};`. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| module | THREE_MODULE | The named resources, for any of the Three Import nodes. |