since version: 0.0.5
This feature makes it possible to expose Godot nodes/classes to the javascript runtime, which is quite powerful, as it fully reflects them (properties/methods/signals), and should cover your gdscript<->javascript communication needs.
Passing a Camera3D
(which inherits from Node
) to javascript:
$WebView.set_context_node("camera", $cam)
Then, in javascript:
window.addEventListener("godot.ready", event => {
// property access
console.log("camera fov: ", $g.camera.fov.value);
// listen to changes
$g.camera.fov.on("changed", (value) => {
console.log("fov changed: ", value);
});
// changing the value will update it on the Godot side too
$g.camera.fov.value = 60;
// rotate the camera a bit
const [x, y, z] = $g.camera.rotation.value;
$g.camera.rotation.value = [x, y, z + 40];
// connect to a signal (camera removed from the scene)
$g.camera.connect("tree_exited", () => {
console.log("camera was removed");
});
});
Visit the relevant help sections for more information about this feature.