Custom engine on playground for TypeScript

How can i properly create a custom engine IN TYPESCRIPT so i can set legact V1 audioEngine = true;

Note: this following only seems to work with javascript:

var createEngine = async function () {
    console.log("GOT HERE");
    const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
    const opts: BABYLON.EngineOptions = {
        audioEngine: true,            // Legacy V1 Audio
    };

    // WebGPU if available
    if ((navigator as any).gpu) {
        const e = new BABYLON.WebGPUEngine(canvas, opts as any);
        await e.initAsync();
        return e;
    }

    // WebGL fallback
    return new BABYLON.Engine(canvas, true, opts, false);
};

I tried:

    public static async CreateEngine(canvas: HTMLCanvasElement, engineOptions: BABYLON.EngineOptions = { audioEngine: true }): Promise<BABYLON.AbstractEngine> {
        console.warn("@@@ CreateEngine...");
        // Prefer WebGPU if available in the browser
        if ((navigator as any).gpu) {
            const webgpu = new BABYLON.WebGPUEngine(canvas, engineOptions as any);
            await webgpu.initAsync();
            return webgpu;
        }
        // Fallback to WebGL
        return new BABYLON.Engine(canvas, true, engineOptions);
    }

Appearently there are issues with V2 Audio Engine and mutiple StaticSounds that have spatial enabled… Only One truly respects the maxDistance, when listenerAutoUpdate = true and spatialAutoUpdate = true

Nothing seems to work for create custom engine with TypeScript :frowning:

cc @docEdub

cc @RaananW too

Yo @RaananW or @sebavan … You guys got any idea how I a can use CreateEngine in typescript mode ?

Hey @Deltakosh , Do you know How i can use CreateEngine on TypeScript playground so i can enable Legacy Audio ? I seem to have a problem with mutiple V2 spatial sounds, so i must use legacy V1 audio engine on the playground, for now.

I working on those couple demos with the big exported HDR race tracks from Unity. that i wanted to get on the playground in time for the V9 video release.

If it just not possible to run V1 audio engine in TypeScript, let me know and i will make alternate plans, liked host my own index page and controlling, there OR allthough I HATE PLAIN JAVASCRIPT WITH A PASSION, and never use it, i will have to rewrite my demo playground in plain old javascript… argh

export async function createEngine

1 Like

OMG, THANK YOU @RaananW

1 Like

Something bothered me a bit and I dug a bit more - you just needed to export the var and it would have worked as well (i.e. export var createEngine = function..., so just FYI :slight_smile:

1 Like