Skip to content

<World>

This component provides the basic physics context and loads rapier.

All components that rely on physics (e.g. <RigidBody> or <Collider>) must be a child of <World>.

A typical structure of a physics-enabled wrapper component might look like this:

Wrapper.svelte
<script lang="ts">
import { Canvas } from '@threlte/core'
import { World } from '@threlte/rapier'
import Scene from './Scene.svelte'
</script>
<Canvas>
<World>
<Scene />
<!-- Everything is happening inside this component -->
</World>
</Canvas>

This structure ensures that all components inside the component <Scene> have access to the physics context.

rapier is a Rust-based physics engine and as such bundled and used as a WASM module. If loading of rapier fails for any reason, a slot with the name fallback is mounted to e.g. display a fallback scene without physics.

Wrapper.svelte
<script lang="ts">
import { Canvas } from '@threlte/core'
import { World } from '@threlte/rapier'
import Scene from './Scene.svelte'
import FallbackScene from './FallbackScene.svelte'
</script>
<Canvas>
<World>
<Scene />
{#snippet fallback()}
<FallbackScene />
{/snippet}
</World>
</Canvas>