Using BabylonJS Editor and BabylonJS Toolkit

Both the Editor and Toolkit look really good. And offer valuable items. Are they supposed to be used together?

I do see main.ts - which instantiates the App on loaded:

E:\Dev\Repos\r2d2Proton\BabylonTest\src\main.ts

import './style.css';
import { App } from './App';

// Initialize the app when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
	const app = new App();
	app.init();
}); 

App has a lot of imports { Scene } and { Engine } and { HavokPlugin } and HavokPhysics. My first attempt is to comment out the loadScene and create an inline replacement. But I suspect this can be created better than that. Hence my question. Follow the natural progress of the Editor Sample flow. At some point move the assets under my test project folder too. Still learning about the setup though.

E:\Dev\Repos\r2d2Proton\BabylonTest\src\App.ts

import "@babylonjs/core/Physics";
import { loadScene } from "babylonjs-editor-tools";
import { scriptsMap } from "./scripts";

export class App {
	private _canvas: HTMLCanvasElement;
	private _engine: Engine | null = null;
	private _scene: Scene | null = null;

	constructor() {
		const canvasElement = document.getElementById('canvas') as HTMLCanvasElement;
		if (!canvasElement) {
			throw new Error('Canvas element not found');
		}
		this._canvas = canvasElement;
	}

	public async init(): Promise<void> {
		this._engine = new Engine(this._canvas, true, {
			stencil: true,
			antialias: true,
			audioEngine: true,
			adaptToDeviceRatio: true,
			disableWebGL2Support: false,
			useHighPrecisionFloats: true,
			powerPreference: "high-performance",
			failIfMajorPerformanceCaveat: false,
		});

		this._scene = new Scene(this._engine);

		await this._handleLoad();

		// Handle window resize
		const handleResize = () => {
			this._engine?.resize();
		};

		window.addEventListener("resize", handleResize);

		// Start render loop
		this._engine.runRenderLoop(() => {
			this._scene?.render();
		});
	}

	private async _handleLoad(): Promise<void> {
		if (!this._engine || !this._scene) {return;}

		//const havok = await HavokPhysics();
		//this._scene.enablePhysics(new Vector3(0, -981, 0), new HavokPlugin(true, havok));

		//SceneLoaderFlags.ForceFullSceneLoadingForIncremental = true;
		//await loadScene("/scene/", "example.babylon", this._scene, scriptsMap, {
		//	quality: "high",
		//});
		//
		//if (this._scene.activeCamera) {
		//	this._scene.activeCamera.attachControl();
		//}
		var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
		camera.setTarget(BABYLON.Vector3.Zero());
		
		await DemoScene.Load(scene);
	}

	public dispose(): void {
		this._scene?.dispose();
		this._engine?.dispose();
	}
} 

class DemoScene {
    private static ScriptBundleUrl:string = TOOLKIT.SceneManager.PlaygroundCdn + "default.playground.js";

    public static async Load(scene:BABYLON.Scene): Promise<void> {
        
        await TOOLKIT.SceneManager.InitializePlayground(scene.getEngine(), { showDefaultLoadingScreen: true, hideLoadingUIWithEngine: false });
        globalThis.SCRIPTBUNDLE_JS = globalThis.SCRIPTBUNDLE_JS || await BABYLON.Tools.LoadScriptAsync(DemoScene.ScriptBundleUrl);
        
        // @ts-ignore - This initializes fresh physics for this scene
        globalThis.HK = await HavokPhysics();
        globalThis.HKP = new BABYLON.HavokPlugin(false);
        scene.enablePhysics(new BABYLON.Vector3(0,-9.81,0), globalThis.HKP);

        // This cleans up globals when the scene is disposed
        const cleanupGlobals = () => {
            if (globalThis["HKP"]) delete globalThis["HKP"];
            if (globalThis["HK"]) delete globalThis["HK"];
        };
        scene.onDisposeObservable.addOnce(cleanupGlobals);
        
        const assetsManager = new BABYLON.AssetsManager(scene);
        assetsManager.addMeshTask("samplescene", null, TOOLKIT.SceneManager.PlaygroundRepo, "samplescene.gltf");
        assetsManager.addMeshTask("playerarmature", null, TOOLKIT.SceneManager.PlaygroundRepo, "playerarmature.gltf");
        await TOOLKIT.SceneManager.LoadRuntimeAssets(assetsManager, ["samplescene.gltf", "playerarmature.gltf"], ()=> {

            try {
                const player = scene.getNodeByName("PlayerArmature") as BABYLON.TransformNode;
                if (player != null) {
                    const controller = new PROJECT.ThirdPersonPlayerController(player, scene, { arrowKeyRotation: true, smoothMotionSpeed:true, smoothChangeRate: 25.0 });
                    controller.enableInput = true;
                    controller.attachCamera = true;
                    controller.moveSpeed = 5.335;
                    controller.walkSpeed = 2.0;
                    controller.jumpSpeed = 12.0;
                }
            } catch (e) {
                console.error("Failed to attach player controller", e);
            } finally {
                TOOLKIT.SceneManager.HideLoadingScreen(scene.getEngine());
                TOOLKIT.SceneManager.FocusRenderCanvas(scene);
            }
        });
    }
}


Are there Toolkit samples/starter-kits that are configured for the Editor?

Or how to properly modify the Toolkit Sample to match the Editor Sample?

Hey @r2d2Proton !

The Editor was not designed to work with the Toolkit first.
I understand that you chose the “Vanilla” template from the Editor and you are editing the main entry point (the class App). You can do whatever you want in that file.

The await loadScene(...) that you commented is the equivalent of appending a scene to the one passed as parameter and performs script attachment (Babylon.js Editor Documentation).

I’m not convinced the editor and toolkit will work together. I would suggest to choose one and keep on that one. What do you think @MackeyK24 ?

1 Like

Thank you for the response @julien-moreau

Is the BabylonJS GUI (https://gui.babylonjs.com/) folded into the Editor?
The GUI looks goofy.

Does the Editor have the Animation retargeting?

Or the latest Inspector?

Or latest BabylonJS features?

On startup I would like both the Dashboard and Editor to remember which display, position, and size. Basically, remember their state.

And create the folder - whether a new project or new asset testing and not require an empty folder.

Maybe a derivative of BabylonJS Playground should mature into a full-scene editor. Playground makes sense when you want to test features of the engine, or assets. A game engine needs to fold in all aspects of development.

The Havok Physics engine is really nice. Hence why I am back.

The flexibility of the BabylonJS is really nice.

I am doing some testing with .NET MAUI and BabylonJS ( GitHub - r2d2Proton/WebTest: .NET MAUI Babylon Test Framework · GitHub ).

But from my testing, my observations, with .NET MAUI, some complex Lottie animations do not playback correctly. And SVG aint supported on Windows.

.NET MAUI Android SVG works perfectly.

The best I can tell, .NET MAUI XAML works really well on Windows and Android. An option to render controls on the device using native - OS specific features is there. Personally, I do not use them. I prefer the same look across devices for my apps. But that is preference that can be overridden by the user.

If the babylon.toolkit.js runtime was loaded in the Babylon Editor like we do the playground, then yes, I could make them play nice together :slight_smile:

1 Like

@julien-moreau @MackeyK24 here are some videos I uploaded.

Two are DirectX12 tests. The others are a game I wrote with UE4 C++. Stopped using Unreal Engine because Epic does not use the same version. Trying other tests now with BabylonJS and Havoc Physics.

I am figuring out what is officially supported. . . and what is add-on. What is open-source. What is free.

As you know, the Playground, as nice as it may be, is still lacking. Items do not jump out either - it was a stunner that the GUI is in a different direction. No hint whatsoever that there is one.

I tried Google YouTube share - a goofy URL - one that lacks trust:

1 Like

I love the HavokPhysics plugin compared to all the previous plugin like cannon and ammo.

here are some havok vehicle physics demo i am working on:

2 Likes

Years ago (~1986/1987) I migrated a law firm’s important documents from a Macintosh to a PC using Xtalk and a cable. Never really followed Apple. Read Microsoft invested $100M in Apple to keep them afloat. It appears Apple developer features are right on point:

I do not know if these are the right choices . . but far and away better supported and ingrained within the entire ecosystem. I am switching to Apple.