run_js
Run arbitrary JavaScript code with access to the Three.js scene, renderer, and camera. Returns the execution result for debugging or live inspection.
Instructions
Execute arbitrary JavaScript with access to scene, renderer, camera. Returns the result. Runtime only (lost on reload). If the code mutates scene state, ASK the user first: runtime preview or persistent code change?
SHADER PATCHING RECIPE — when modifying materials via onBeforeCompile:
Reset patch flags: mat._curvedWorldPatched = false; mat._windPatched = false;
Delete old shader refs: delete mat.userData.shakeShader; stop old animations via mesh.userData._stopShake?.();
ONE onBeforeCompile pass (never chain) — include curved world + your effect together
Replace '#include <project_vertex>' with full transform: USE_BATCHING/USE_INSTANCING guards → effect in world space → curved world (worldPos.y -= dist²0.005) → viewMatrixworldPos → gl_Position
Declare uniforms before main(): shader.vertexShader.replace('void main() {', 'uniform float uTime;\nvoid main() {')
Set mat.customProgramCacheKey = () => 'effect-' + Date.now(); — forces recompilation
mat.needsUpdate = true;
Animate uniforms via requestAnimationFrame loop
Use transformed.y for height-based effects (local vertex Y), worldPos for spatial phase
Debug only — page reload will reset. No code changes needed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript code. Available vars: scene, renderer, camera, gl. Use return for results. |