-
-
Notifications
You must be signed in to change notification settings - Fork 116
/
World.svelte
83 lines (74 loc) · 2.28 KB
/
World.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<script
context="module"
lang="ts"
>
import RAPIER from '@dimforge/rapier3d-compat'
import { onMount } from 'svelte'
import { writable } from 'svelte/store'
/**
* RAPIER.init() should only be called once
*/
const initialized = writable(false)
</script>
<script lang="ts">
import InnerWorld from './InnerWorld.svelte'
import type { WorldProps } from './World.svelte'
// TODO: should this be Required<WorldProps> instead?
type $$Props = WorldProps
// self
export let gravity: $$Props['gravity'] = undefined
export let rawIntegrationParameters: $$Props['rawIntegrationParameters'] = undefined
export let rawIslands: $$Props['rawIslands'] = undefined
export let rawBroadPhase: $$Props['rawBroadPhase'] = undefined
export let rawNarrowPhase: $$Props['rawNarrowPhase'] = undefined
export let rawBodies: $$Props['rawBodies'] = undefined
export let rawColliders: $$Props['rawColliders'] = undefined
export let rawImpulseJoints: $$Props['rawImpulseJoints'] = undefined
export let rawMultibodyJoints: $$Props['rawMultibodyJoints'] = undefined
export let rawCCDSolver: $$Props['rawCCDSolver'] = undefined
export let rawQueryPipeline: $$Props['rawQueryPipeline'] = undefined
export let rawPhysicsPipeline: $$Props['rawPhysicsPipeline'] = undefined
export let rawSerializationPipeline: $$Props['rawSerializationPipeline'] = undefined
export let rawDebugRenderPipeline: $$Props['rawDebugRenderPipeline'] = undefined
/**
* This is passed to the useTask handler.
* Use this to control when the rapier physics engine is updating the scene.
* @default undefined
*/
export let stage: $$Props['stage'] = undefined
let error = false
const init = async () => {
if ($initialized) return
try {
await RAPIER.init()
$initialized = true
} catch (e) {
error = true
}
}
onMount(init)
</script>
{#if $initialized}
<InnerWorld
{gravity}
{rawIntegrationParameters}
{rawIslands}
{rawBroadPhase}
{rawNarrowPhase}
{rawBodies}
{rawColliders}
{rawImpulseJoints}
{rawMultibodyJoints}
{rawCCDSolver}
{rawQueryPipeline}
{rawPhysicsPipeline}
{rawSerializationPipeline}
{rawDebugRenderPipeline}
{stage}
>
<slot />
</InnerWorld>
{/if}
{#if error}
<slot name="fallback" />
{/if}