Skip to content

Script writeScript

bandinopla edited this page Apr 11, 2025 · 2 revisions

Since the app exports a javascript, at some point a script will need to be created. The class in charge of orchestrating this process is the src/export/Script this class acts as the "document" that is being written. It contains methods to "write" the js code in a way that imports and definitions are automaticaly merged. And nodes and outlets both implement src/export/IScript

The process

When the app "saves" it will create a new Script() and collect each node that belongs to a group with exportsScript: true to call their writeScript(script) with the reference to this brand new script object. The nodes will then call, the respective writeScript of every input outlet to then use those references to build their node setup and be able to return.

The order

  1. node.writeScript() declared in Ǹode.ts first checks if it is cached if not, call step 2.
  2. node.writeNodeScript() This is where the node create the TSL Javascript...
  • output outlets might call get nodeDataType(): IDataType on the node to know what type of data it will return.
  1. for each input, the node will do: input.writeScript()
  2. each input will do: nodeOwner.writeScript()
  3. repeat 1...

writeNodeScript( script )

The idea of this method is to add the imports, declaration of functions or variables needed to eventually return a material usable in a THREE project. And eventually the return will be a string that will be the tsl node it defined. The return type is a name. The name of the variable that was used to define the tsl node. Each outlet when their writeScript is called will too call the writeScript of their owners, and the process will recursively do this all the way up to a node with no inputs.

Preview

While developing / working in the app, if a material output is plugged into the preview node, a "preview" script will be created and executed ( using eval ) to obtain the materials created by the nodes and they will be passed to the preview scene to see them.

Output

The output is obtained from doing script.toString() and the src/Editor is the one that starts the process on the .save() method.

Clone this wiki locally