Javascript interop
The addon now supports exposing Godot nodes to the webview. It reflects methods/signals/properties.
An HTML slider that directly operates on a property:
<h2>rotate cube</h2>
<input oninput="onSliderChange(this.value)" type="range" [...]>
<div id="valueDisplay">Value: 0</div>
<script>
function onSliderChange(value) {
document.getElementById("valueDisplay").textContent = "value: " + value;
const [x, y, z] = $g.cube.rotation.value;
$g.cube.rotation.value = [x, (value/2) / 100, value / 100];
}
</script>
In the above example, we expose a MeshInstance3D
:
$WebView.set_context_node("cube", $some_cube)
Which is then available through $g.cube
in javascript.
We call this feature "Context objects" (documentation).
This feature took significant effort, and we hope you like it.
Visit the downloads page and grab yourself an evaluation build.
For help or feedback, reach out via: - Discord - Github issue tracker
Sander Ferdinand