Skip to content

Editor Script

Usage

  1. Write the script by referring to the writing style of the Template and Example.
  2. Import the script into the editor.
  3. Select the script you want to execute and click the Execute button in the Inspector.
  • Register to the menu bar
    1. Place the script in the Scripts/_Editor folder.
    2. Export a menuPath string in the script. The string value will be the name displayed in the menu bar. You can use / to separate levels.
    3. If you need to add an icon to a script registered in the menu bar, you first need to import an image into the editor to convert it to .tex format, then place it in the Scripts/_Editor/Icons folder, and name it the same as the menuPath string value in the script.

TIP

Registered menu bar items require an editor restart to take effect.

Hooks

The editor provides a total of 2 hooks, see BST/_Typings/editorApi/exportFuncs.d.ts.

ts
export const menuPath: string

Used to register the script to the menu bar.

execute

ts
export const execute: () => void

Executed when the execute button is clicked.

Modules

The editor provides the following 6 modules:

For details, see BST/_Typings/editorApi/modules.

To import modules, use the following syntax:

js
import {
  // modules
  editor,
  console,
  file,
  scene,
  dialogWindowManager,
  math,

  // basic data types
  Float2,
  Float3,
  Float4,
  Bool3,
  ColorRGBA,
  Trans,
  Quaternion,
} from "editorApi"

WARNING

Editor scripts cannot import custom modules.

Template

See BST/Templates/editorTemplate.js.

Example

See BST/Samples/editorSamples.

Released under the MIT License.