# Unity Terrain Splatmap Playground

**URL:** <https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220>\
**Category:** Demos and projects\
**Created:** [April 1, 2024, 5:47am UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220 "2024-04-01T05:47:12Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 1, 2024, 5:47am UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/1 "2024-04-01T05:47:12Z")

</div>

This [Candyland Demo Playground](https://playground.babylonjs.com/?UnityToolkit#7ZVH05) was generated using Babylon Toolkit - Pro Edition 7.0.0 R1 (HAVOK)

It supports all the extra systems I had to create to be able export and re-create a Unity like Terrain System in BabylonJS.

The demo **candyland.gltf** is loaded along with a demo player character. You can smoothly walk, run, jump, etc… and traverse the terrain. It has several painted texture  
layers showing my extra Unity like **splatmap** system to render up to 64 painted texture layers with terrain collision

 ![Screenshot 2024-03-31 at 6.48.39 PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/e/7e8a1e5c7bb4f45f09eea2024a5c81447afe4be1.jpeg)

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 6, 2024, 10:02pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/3 "2024-04-06T22:02:36Z")

</div>

Yes, everything like the the terrain and player were setup in unity, exported as an interactive gltf (scripted logic is in the scene file via metadata).

Then we create a stand web project using babylon.js… the interactive scene is loaded and various elements, scripts, terrain setups, etc… are handled by the Babylon Toolkit GLTF Parser… and Voila … Your BabylonJS (native scene) exported from Unity with all the bells and whistles the Babylon Toolkit provides

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 7, 2024, 8:26pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/5 "2024-04-07T20:26:59Z")

</div>

There is no Unity logic exported. The scene is exported as gltf. The toolkit also stores metadata it needs to RE-CREATE the logic using BabylonJS code… regular typescript.

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [April 7, 2024, 8:54pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/6 "2024-04-07T20:54:01Z")

</div>

This is impressive! 😻

What are the benefits of creating the scene in Unity and export it to babylon.js? I don’t want to be a prick and disregard your work, technologically this is absolutely insane ❤ 💪 , but this scene can be easily created in babylon.js w/o Unity and the 100MB+ asset it had to download.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 8, 2024, 9:48pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/7 "2024-04-08T21:48:53Z")

</div>

Dunno that this scene is 100+MB. Only transfer about 50MB over network for me. And the demo is to show using the Unity Ecosystem to create a gltf. Mainly using Unity Terrain Builder with 7 different terrain textures that were **splatted** to paint the detail you see on the terrain, export a robot character using the Unity Starter asset with animation controller and blend tree animations smoothly transition walk, run, jump, falling and multiple landing animations… All with V2 havok physics for the terrain and a dynamic character controller for player movement. And all the OUT-THE-BOX and not even typing one single line of code for anything including the complex physics setup using Pro Class script components.

As the playground shows… its all easily loaded as with asset manager or any other  
babylon scene loading functions. Then of course you can add what ever logic you like using script components.

So its really about how you wanna build your game. I prefer to use the Unity Eco System And Tooling to create interactive gltf files and use script components to achieve the Unity style game mechanics for not things like Terrain Building, but lightmap baking, character animation, recast navigation mesh generation, detour path navigation, auto lod, all the unity colliders including wheel colliders for raycast vehicle. You can setup entire open worlds or very large cities with thousands of building and road colliders. Then export all that as an **interactive gltf** with all that pre-built functionality that you load into your project, no matter if use my scene viewer or your own project.

The following [Unity Starter Asset Playground](https://playground.babylonjs.com/index.html?BabylonToolkit#N1FY3E) show an example of how to use this interactive gltf in your own project. By loading a main level with all the fixings, lighting, skybox, environment, fog, etc. And a player character with two very powerful components on it. A **UNITY.CharacterController** and a **UNITY.AnimationState** component. We then at runtime attach a **3RD Person Player Controller** to show that you can do this from your own code, and use the demo asset to place whatever type player controller script to handle the overall movement of your character:

```auto
class Playground {
    public static async CreateScene(engine: BABYLON.Engine, canvas: HTMLCanvasElement): Promise<BABYLON.Scene> {
        // This initializes the babylon.toolkit.js runtime and the default unity.playground.js project script bundle
        await UNITY.SceneManager.InitializePlayground(engine, { showDefaultLoadingScreen: true, hideLoadingUIWithEngine: false });

        // This creates a basic babylon scene object (non-mesh)
        var scene = new BABYLON.Scene(engine);

        // This creates and positions a debug camera (non-mesh)
        var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
        camera.setTarget(BABYLON.Vector3.Zero());
        camera.attachControl(canvas, true);

        // This creates ambient light, aiming 0,1,0 - to the sky (non-mesh)
        var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
        light.intensity = 0.8;

        // This enables the havok physics engine
        globalThis.HKP = new BABYLON.HavokPlugin();
        scene.enablePhysics(new BABYLON.Vector3(0,-9.81,0), globalThis.HKP);
        
        // This loads the sample scene & player armature exported from a unity starter assets project
        // https://assetstore.unity.com/packages/essentials/starter-assets-character-controllers-urp-267961
        const assetsManager:BABYLON.AssetsManager = new BABYLON.AssetsManager(scene);
        assetsManager.addMeshTask("samplescene", null, UNITY.SceneManager.PlaygroundRepo, "samplescene.gltf");
        assetsManager.addMeshTask("playerarmature", null, UNITY.SceneManager.PlaygroundRepo, "playerarmature.gltf");
        await UNITY.SceneManager.LoadRuntimeAssets(assetsManager, ["samplescene.gltf", "playerarmature.gltf"], ()=> Playground.OnSceneReady(scene));

        return scene;
    }

    private static OnSceneReady(scene:BABYLON.Scene):void {
        // This get the play armature transform node from scene hierarchy
        const player = scene.getNodeByName("PlayerArmature") as BABYLON.TransformNode;

        // This instantiates a third person player controller script component from the babylon toolkit starter content package
        const controller = new PROJECT.ThirdPersonPlayerController(player, scene, { arrowKeyRotation: true, smoothMotionSpeed:true, smoothChangeRate: 25.0 });
        controller.enableInput = true;
        controller.attachCamera = true;
        controller.boomPosition.set(0, 0, -5);
        controller.moveSpeed = 5.335;
        controller.walkSpeed = 2.0;
        controller.jumpSpeed = 12.0;
        UNITY.SceneManager.AttachScriptComponent(controller, "PROJECT.ThirdPersonPlayerController");
        
        // This finally hides the playground screen loader
        UNITY.SceneManager.HideLoadingScreen(engine);
        UNITY.SceneManager.FocusRenderCanvas(scene);
    }
}

```

Anyways, sorry about the long winded response. But in short, you use the toolkit to make interactive gltf files that you load in your normal project. How interactive you make it is your choice. Can be an entire game or levels and individual assets. Its up to you.

But I cant see any other Game IDE for BabylonJS that lets do all that. I use it every day for work (most of which is under NDA so I **cant** show demos of the project without written permission from the client). But here is an **older prototype** that MVRK Dev Team including @Pryme8 made with the toolkit. [MVRK Racer](https://mvrkracer.mvrk.co)

**Note** : the networking server is down so stick to solo play. My newer shit way better quality. just cant show it right now

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [April 8, 2024, 11:25pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/8 "2024-04-08T23:25:51Z")

</div>

I can confidently say after learning to use it, the BJS Toolkit is the most powerful tool for scene creation that users have at their disposal.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 9, 2024, 11:55am UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/10 "2024-04-09T11:55:24Z")

</div>

Some more toolkit usage:

> [@Babylon Toolkit Legacy Physics Workflow](https://forum.babylonjs.com/t/babylon-toolkit-legacy-physics-workflow/49498):
>
> Yo @roland I revived the Babylon Toolkit-7.0.0-BULLET for Legacy Ammo.JS Physics Check this sweet workflow I use for driving games Note: I am waiting for @Cedric to get Raycast Vehicle Support for Havok Physics Until then i still have to rock Ammo.js for advanced vehicle physics

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [April 9, 2024, 12:13pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/11 "2024-04-09T12:13:39Z")

</div>

Now I got a better understanding what might be happening under the hood 🙂 Thank you and Kudos! 💪

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [April 9, 2024, 12:18pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/12 "2024-04-09T12:18:06Z")

</div>

@MackeyK24 I’d like to ask a question. I was working in Unity years ago before I switched to babylon.js and I liked the lightmap/ao generated by Unity a lot. They’re so much different from AOs which we generate in Blender nowadays. Do you think it could be possible to import our model from Blender (fbx export), generate the lightmaps and export the mesh to a format directly usable with babylon.js? If so, can it be automated, scripted somehow?

Thanks!

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [April 9, 2024, 12:18pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/13 "2024-04-09T12:18:44Z")

</div>

I’ve to try it out then!!

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 9, 2024, 7:25pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/14 "2024-04-09T19:25:21Z")

</div>

Yes you can do that. That is a very normal worlflow. Our Unity Technical Artist starts out in Maya. Gets the scene fleshed out there. Then brings into Unity and the lighting is setup, Materials, Skyboxes, Global Environment, Local Reflection Probes and Baked Lightmaps.

Then the toolkit exports everything out as **GLTF** with a bit of extra **Unity Metadata**. My babylon.toolkit.js runtime has the GLTF Parsers that run when you load that **GLTF** and that is were the **Magic Happens** 🙂

But I do not have any sort of unattended automated export. You must export the scene and or any individual assets using the various export options

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 29, 2024, 5:19am UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/15 "2024-04-29T05:19:13Z")

</div>

Yo @roland … Checkout the **built in compression** support for **webp** compressed textures and **gzipped** gltf scene files

> [@Compressed Interactive Unity GLTF Content](https://forum.babylonjs.com/t/compressed-interactive-unity-gltf-content/50105):
>
> [Compressed Interactive Unity GLTF Demo](https://playground.babylonjs.com/index.html?UnityToolkit#3T5CUF) This is a playground demonstrating the Babylon Toolkit support for generating compressed Interactive Unity GLTF Scene Files What makes the exported content interactive are the script components and game object setup like zero code physics configuration. You get all this by simply loading the Interactive Unity GLTF Scene File using any one the BabylonJS Scene Loaders or Asset Manager (And the babylon.toolkit.js runtime library is loaded of course). Wha…

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [May 3, 2024, 8:06pm UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/17 "2024-05-03T20:06:47Z")

</div>

Yes 👍

The above playground shows loading interactive gltf files each one has all its functionality defined in the gltf

The samplescene is the level, complete with lighting and environment like fog, it has all the physics setup automatically including compound colliders

The player armature has a physics based character controller and an animation state component (Unity Mechanim Style)

The playground show you can load these two files into any Babylon js environment with the Babylon.toolkit.js lib loaded

You can attach additional components at runtime which I am doing with the Third Person Player Controller component that lets move around, run, jump, etc… and all the animation are synced via Unity Style Animation functions like SetFloat and SetBool to update the properties of the animation state machine

All this by simply loading the interactive Unity GLTF that you create using my Babylon Toolkit

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [May 11, 2024, 9:11am UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/18 "2024-05-11T09:11:10Z")

</div>

This is awesome! Absolutely!

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [May 11, 2024, 9:11am UTC](https://forum.babylonjs.com/t/unity-terrain-splatmap-playground/49220/19 "2024-05-11T09:11:53Z")

</div>

You have to create an article/youtube video on this!
