Communication between the published scene/Player, and the other page elements

I am wondering if there is a more elegant way to do this.

Right now, I am setting type=hidden input fields in the main page… and from inside of the scene, I am able to use document.getElementById(‘hiddeninput’).value; to pass variables back and forth.

Is there a better way to communicate with scripts inside of the three.js scene? The way I am doing it works, but I would imagine it is a pretty clunky and slow way to so it. I am using the Three.js editor to publish scenes, it is really nice, and I would really like to stay within that scheme.

Thanks :slight_smile:

AFAIK no, at least when you work with plain HTML and JavaScript. Of course you can use an UI library like React or angular when developing web based user interfaces and then benefit from data-binding concepts. However, such a dependency will also add additional overhead to your app. And you have to invest some time in initial training if you are not yet familiar with it. It really depends on the scale and complexity of your project. And on your personal preferences^^.

1 Like

Hard to tell what you mean, but I think you just want to share JavaScript values between scripts, not have them bound to UI elements? I think because you are using hidden UI elements you are not trying to get data that users have typed into input fields.

You could create an object on the global/window scope which can be accessed from anywhere.

window.myObject = {};
window.myObject.variable1 = true;

then in another script


Thank you Cal! That worked! :slight_smile: