I have written script in Threejs Editor and got the code using the publish option , now if the frontend or UI wants to play that script how can one do it?

Hey my first question in the threejs journey
I am putting the code here which i got from the threejs editor

Also is there a better way to do this, other than using script if i will have more than 10 different animations script.The script i have written plays the animation which is already on the model.glb
Don’t if the code will be there in this folder so pasting for reference

let mixer; // Global mixer
const clock = new THREE.Clock(); // Clock to track time

function init() {
    mixer = new THREE.AnimationMixer(scene); // Use the global mixer

    this.traverse((object) => {
        if (object.animations.length != 0) {
            const clips = object.animations;
            const clip = THREE.AnimationClip.findByName(clips, 'EXT_DOOR_LB_ANIM');
            if (clip) {
                const action = mixer.clipAction(clip);
                console.log("action", action);
				action.stop().play();
            }
        }
    });
}
function animate() {
    requestAnimationFrame(animate);

    const delta = clock.getDelta(); // Get the time since the last frame

    // Update the mixer if it has been initialized
    if (mixer) mixer.update(delta);

    renderer.render(scene, camera);
}

animate(); // Start the animation loop

The source to the script is in the app.json
I think you can do something like:

import {Player} from "./app.js"

new Player().play()

Thanks
One more doubt
As you can see in my script i have added an custom function animation
1)can i make custom events in the list of events?
2)how can i expose some variables? might be frontend will access the variables exposed and set some values

I’m not sure TBH… I just figured out what I told you by looking at app.js and app.json in your .zip

It’s only about 2 pages of code… perhaps you can look at app.js and see where you can insert your logic or how to access internals.

There aren’t many “rules” about how to use the output of the editor… i think its encouraged that you hack it to make it useful for your use case.

There is a object on all threejs Object3D derived classes… (which is basically every node type) called .userData that you can stuff your own data into, and which threejs will serialize along with the objects data when using threejs serialization.

So in your script, you could look for data in the object.userData

and communicate with the script via that object. That’s just one thought off the top of my head.