# Svelte-Babylon WIP (Use Babylon in markup, A-Frame style)

**URL:** <https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049>\
**Category:** Demos and projects\
**Tags:** tutorial\
**Created:** [April 16, 2021, 3:08am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049 "2021-04-16T03:08:08Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogueyoshi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rogueyoshi/32/15604_2.png) [@rogueyoshi](https://forum.babylonjs.com/u/rogueyoshi)\
**Post date:** [April 16, 2021, 3:08am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/1 "2021-04-16T03:08:08Z")

</div>

code example:

```
<BabylonEngine>
	<BabylonScene>
		<BabylonCamera position={new BABYLON.Vector3(0, 5, -10)} target={BABYLON.Vector3.Zero()} />
		<BabylonHemisphericLight direction={new BABYLON.Vector3(0, 1, 0)} intensity={0.7} />
		<!-- Below is two-way binding between spherePosition and position -->
		<BabylonSphere bind:position={spherePosition} options={{ diameter: 2, segments: 32 }} />
		<BabylonGround options={{ width: 6, height: 6 }} />
	</BabylonScene>
</BabylonEngine>

```

[Live playaround REPL](https://svelte.dev/repl/3aa641515a99443c9f1036712f62fe90?version=3.37.0)

The idea is to let you declaratively define Babylon scene and entities, with potential for prefab-like components. The best thing about Svelte is Reactive Programming… Just use your objects where you want, whether in markup or confined to scripts and not have to worry about updates. I have some cleaning up to do before it’s ready to be published. Svelte components are a given, and I could theoretically export to Web Components so anyone could use Babylon like they would A-Frame regardless of their framework.

video demonstration:

> <https://twitter.com/rogueyoshi_FGC/status/1382886646543224838>

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 16, 2021, 3:20am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/2 "2021-04-16T03:20:22Z")

</div>

Very cool @rogueyoshi ! Love Svelte. Love Babylon. Perfect combo.

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 16, 2021, 3:43am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/3 "2021-04-16T03:43:09Z")

</div>

@rogueyoshi do you think this would be a viable, performant approach to creating a game level editor, with a reactive svelte UI and svelte Babylon components - adding/removing and changing properties of game entities?

I’m wondering how well it would scale or whether there’d be a better approach.

---

<div class="post-metadata">

**Author:** ![rogueyoshi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rogueyoshi/32/15604_2.png) [@rogueyoshi](https://forum.babylonjs.com/u/rogueyoshi)\
**Post date:** [April 16, 2021, 5:36am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/4 "2021-04-16T05:36:19Z")

</div>

@inteja That’s an interesting idea. You could probably easily serialize it all. But first the base engine stuff has to be ported over for Svelte, so components for all the entity types, or possibly a generic entity component that you can pass stuff into could suffice too.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 16, 2021, 11:43am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/5 "2021-04-16T11:43:34Z")

</div>

This is coooool 🙂 @RaananW might love this one

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [April 16, 2021, 11:48am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/6 "2021-04-16T11:48:06Z")

</div>

Amazing! Thanks for sharing

Can’t wait to try it myself 🙂

---

<div class="post-metadata">

**Author:** ![rogueyoshi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rogueyoshi/32/15604_2.png) [@rogueyoshi](https://forum.babylonjs.com/u/rogueyoshi)\
**Post date:** [April 16, 2021, 8:28pm UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/7 "2021-04-16T20:28:05Z")

</div>

> <https://twitter.com/rogueyoshi_FGC/status/1383154955373191172>

> <https://twitter.com/rogueyoshi_FGC/status/1383155028056236040>

First version with ported starter code is done. Over the weekend and beyond I’ll be continually adding to it for what my work project requires. PRs are welcome.

---

<div class="post-metadata">

**Author:** ![rogueyoshi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rogueyoshi/32/15604_2.png) [@rogueyoshi](https://forum.babylonjs.com/u/rogueyoshi)\
**Post date:** [April 17, 2021, 5:55am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/8 "2021-04-17T05:55:30Z")

</div>

Made a Svelte REPL post too. You can tinker with it live like the Babylon Playground:

> **[Loading... • REPL • Svelte](https://svelte.dev/repl/3aa641515a99443c9f1036712f62fe90?version=3.37.0)**
>
> Cybernetically enhanced web apps

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [April 20, 2021, 11:42am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/9 "2021-04-20T11:42:53Z")

</div>

That’s really nice! I never used Svetle, but it seems very readable and makes a lot of sense to me 🙂

How long does it take to implement such a component? If I want to use different types of meshes, will I need to implement the components for them, or is there some form of shortcut (for example always bind position)?

---

<div class="post-metadata">

**Author:** ![rogueyoshi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rogueyoshi/32/15604_2.png) [@rogueyoshi](https://forum.babylonjs.com/u/rogueyoshi)\
**Post date:** [April 20, 2021, 6:15pm UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/10 "2021-04-20T18:15:48Z")

</div>

Similarly to A-Frame’s ECS Components, Svelte has Svelte Actions. The plan is to make reusable Actions for stuff that is shared across entity types (position, material, etc.). This will need some forward thinking for implementation to avoid pigeonholing. For now, I’m just directly exposing props as needed and adding Reactive Statements for props to assign them to the Babylon entity (or run the related function).

> <https://github.com/SectorXUSA/svelte-babylon/issues/8>
>
> Need to think about how to approach this is an extensible manner. For now I thin…k I want to only expose props absolutely needed by entity constructors, I'm also considering passing back references to the entity itself as well for flexibility. \[Svelte Actions\](https://svelte.dev/tutorial/actions) lend extremely well to ECS. Ideally I'd want the use of them to behave similar to using \[A-Frame component modules\](https://aframe.io/docs/1.2.0/core/component.html).

EDIT: having problems with my post link limitations. Can’t link to the Svelte docs on the subjects. Added the links to that PR though. Apparently my posts are getting flagged as spam?

EDIT2: anyways for now, you can duplicate one of the entity components, and simply export the props you want and just create reactive "$: " statements to do what you want with them automatically as changed. It’s on the TODO to add boilerplate for making your own.

---

<div class="post-metadata">

**Author:** ![DarraghBurke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/darraghburke/32/10621_2.png) [@DarraghBurke](https://forum.babylonjs.com/u/DarraghBurke)\
**Post date:** [October 22, 2021, 6:01pm UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/11 "2021-10-22T18:01:47Z")

</div>

Hey! Just wondering if there’s been any progress on this, I’ve been wanting to give this a try once it gets to a more developed point 🙂 I am a big fan of Svelte and I think this project has huge potential!

---

<div class="post-metadata">

**Author:** ![rogueyoshi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rogueyoshi/32/15604_2.png) [@rogueyoshi](https://forum.babylonjs.com/u/rogueyoshi)\
**Post date:** [November 28, 2021, 10:06pm UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/13 "2021-11-28T22:06:21Z")

</div>

I want to return to working on it with some AR examples once WebXR Depth API and the other latest features gets supported officially by Babylon (so I don’t have much time to dedicate since my has demands for bleeding edge WebXR stuff). If you are used to using Babylon and Svelte individually, adding new components to do what you should not be too troublesome, and I will answer any questions.

---

<div class="post-metadata">

**Author:** ![dpuru](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dpuru/32/5971_2.png) [@dpuru](https://forum.babylonjs.com/u/dpuru)\
**Post date:** [December 3, 2021, 4:16am UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/14 "2021-12-03T04:16:49Z")

</div>

I am so excited to find this thread! I love svelte and I love babylonjs… and i found this after searching for something similar for babylon, after Rich Harris open sourced [svelte.cubed](https://svelte-cubed.vercel.app/)

---

<div class="post-metadata">

**Author:** ![tijmenvangulik](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tijmenvangulik/32/15762_2.png) [@tijmenvangulik](https://forum.babylonjs.com/u/tijmenvangulik)\
**Post date:** [December 3, 2021, 6:02pm UTC](https://forum.babylonjs.com/t/svelte-babylon-wip-use-babylon-in-markup-a-frame-style/20049/15 "2021-12-03T18:02:01Z")

</div>

I also love the concept. I remember that there was also an react implementation which also does do something similar:  
[brianzinn/react-babylonjs: React for Babylon 3D engine (github.com)](https://github.com/brianzinn/react-babylonjs)  
[React-babylonjs v3 - Demos and projects - Babylon.js](https://forum.babylonjs.com/t/react-babylonjs-v3/17350)
