@threlte/rapier 3.0.0-next.7 → 3.0.0-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Colliders/AutoColliders.svelte +12 -6
- package/dist/components/Colliders/Collider.svelte +12 -6
- package/dist/components/RigidBody/RigidBody.svelte +11 -5
- package/dist/lib/createRapierContext.js +1 -1
- package/package.json +2 -2
- package/dist/hooks/useHasEventListener.d.ts +0 -3
- package/dist/hooks/useHasEventListener.js +0 -11
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
<script lang="ts">import { ActiveCollisionTypes, CoefficientCombineRule } from '@dimforge/rapier3d-compat';
|
|
2
|
-
import {
|
|
2
|
+
import { createParentObject3DContext, useParentObject3D, watch } from '@threlte/core';
|
|
3
3
|
import { onDestroy, onMount } from 'svelte';
|
|
4
4
|
import { Group } from 'three';
|
|
5
5
|
import { useCollisionGroups } from '../../hooks/useCollisionGroups';
|
|
6
6
|
import { useRapier } from '../../hooks/useRapier';
|
|
7
7
|
import { useRigidBody } from '../../hooks/useRigidBody';
|
|
8
|
-
import { useCreateEvent } from '../../lib/useCreateEvent';
|
|
9
|
-
import { useParentRigidbodyObject } from '../../lib/rigidBodyObjectContext';
|
|
10
8
|
import { applyColliderActiveEvents } from '../../lib/applyColliderActiveEvents';
|
|
11
9
|
import { createCollidersFromChildren } from '../../lib/createCollidersFromChildren';
|
|
12
10
|
import { eulerToQuaternion } from '../../lib/eulerToQuaternion';
|
|
11
|
+
import { useParentRigidbodyObject } from '../../lib/rigidBodyObjectContext';
|
|
12
|
+
import { useCreateEvent } from '../../lib/useCreateEvent';
|
|
13
13
|
let { shape = 'convexHull', restitution, restitutionCombineRule, friction, frictionCombineRule, sensor, contactForceEventThreshold, density, mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame, refresh = $bindable(() => create()), colliders = $bindable(), oncreate, oncollisionenter, oncollisionexit, oncontact, onsensorenter, onsensorexit, children } = $props();
|
|
14
14
|
const group = new Group();
|
|
15
15
|
const { updateRef } = useCreateEvent(oncreate);
|
|
@@ -70,8 +70,14 @@ onMount(() => {
|
|
|
70
70
|
* Cleanup
|
|
71
71
|
*/
|
|
72
72
|
onDestroy(cleanup);
|
|
73
|
+
const parent3DObject = useParentObject3D();
|
|
74
|
+
createParentObject3DContext(group);
|
|
75
|
+
watch(parent3DObject, (parent) => {
|
|
76
|
+
parent?.add(group);
|
|
77
|
+
return () => {
|
|
78
|
+
parent?.remove(group);
|
|
79
|
+
};
|
|
80
|
+
});
|
|
73
81
|
</script>
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
{@render children?.({ colliders: colliders ?? [], refresh })}
|
|
77
|
-
</SceneGraphObject>
|
|
83
|
+
{@render children?.({ colliders: colliders ?? [], refresh })}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<script lang="ts">import { ActiveCollisionTypes, CoefficientCombineRule, Collider, ColliderDesc } from '@dimforge/rapier3d-compat';
|
|
2
|
-
import {
|
|
2
|
+
import { createParentObject3DContext, useParentObject3D, useTask, watch } from '@threlte/core';
|
|
3
3
|
import { onDestroy, onMount, tick } from 'svelte';
|
|
4
4
|
import { Object3D, Quaternion, Vector3 } from 'three';
|
|
5
5
|
import { useCollisionGroups } from '../../hooks/useCollisionGroups';
|
|
6
6
|
import { useRapier } from '../../hooks/useRapier';
|
|
7
7
|
import { useRigidBody } from '../../hooks/useRigidBody';
|
|
8
|
-
import { useParentRigidbodyObject } from '../../lib/rigidBodyObjectContext';
|
|
9
|
-
import { useCreateEvent } from '../../lib/useCreateEvent';
|
|
10
8
|
import { applyColliderActiveEvents } from '../../lib/applyColliderActiveEvents';
|
|
11
9
|
import { eulerToQuaternion } from '../../lib/eulerToQuaternion';
|
|
12
10
|
import { getWorldPosition, getWorldQuaternion } from '../../lib/getWorldTransforms';
|
|
11
|
+
import { useParentRigidbodyObject } from '../../lib/rigidBodyObjectContext';
|
|
13
12
|
import { scaleColliderArgs } from '../../lib/scaleColliderArgs';
|
|
13
|
+
import { useCreateEvent } from '../../lib/useCreateEvent';
|
|
14
14
|
let { shape, args, type, restitution, restitutionCombineRule, friction, frictionCombineRule, sensor, contactForceEventThreshold, density, mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame, collider = $bindable(), refresh = $bindable(() => {
|
|
15
15
|
if (!collider)
|
|
16
16
|
return;
|
|
@@ -134,8 +134,14 @@ onDestroy(() => {
|
|
|
134
134
|
world.removeCollider(collider, true);
|
|
135
135
|
collider = undefined;
|
|
136
136
|
});
|
|
137
|
+
const parent3DObject = useParentObject3D();
|
|
138
|
+
createParentObject3DContext(object);
|
|
139
|
+
watch(parent3DObject, (parent) => {
|
|
140
|
+
parent?.add(object);
|
|
141
|
+
return () => {
|
|
142
|
+
parent?.remove(object);
|
|
143
|
+
};
|
|
144
|
+
});
|
|
137
145
|
</script>
|
|
138
146
|
|
|
139
|
-
|
|
140
|
-
{@render children?.({ collider })}
|
|
141
|
-
</SceneGraphObject>
|
|
147
|
+
{@render children?.({ collider })}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<script lang="ts">import {
|
|
1
|
+
<script lang="ts">import { createParentObject3DContext, useParentObject3D, watch } from '@threlte/core';
|
|
2
2
|
import { onDestroy, setContext, tick } from 'svelte';
|
|
3
3
|
import { Object3D, Vector3 } from 'three';
|
|
4
|
-
import { initializeRigidBodyUserData, setInitialRigidBodyState } from '../../lib/createPhysicsTasks';
|
|
5
4
|
import { useRapier } from '../../hooks/useRapier';
|
|
5
|
+
import { initializeRigidBodyUserData, setInitialRigidBodyState } from '../../lib/createPhysicsTasks';
|
|
6
6
|
import { getWorldPosition, getWorldQuaternion, getWorldScale } from '../../lib/getWorldTransforms';
|
|
7
7
|
import { parseRigidBodyType } from '../../lib/parseRigidBodyType';
|
|
8
8
|
import { setParentRigidbodyObject } from '../../lib/rigidBodyObjectContext';
|
|
@@ -116,8 +116,14 @@ onDestroy(() => {
|
|
|
116
116
|
removeRigidBodyFromContext(rigidBodyInternal);
|
|
117
117
|
world.removeRigidBody(rigidBodyInternal);
|
|
118
118
|
});
|
|
119
|
+
const parent3DObject = useParentObject3D();
|
|
120
|
+
createParentObject3DContext(object);
|
|
121
|
+
watch(parent3DObject, (parent) => {
|
|
122
|
+
parent?.add(object);
|
|
123
|
+
return () => {
|
|
124
|
+
parent?.remove(object);
|
|
125
|
+
};
|
|
126
|
+
});
|
|
119
127
|
</script>
|
|
120
128
|
|
|
121
|
-
|
|
122
|
-
{@render children?.({ rigidBody: rigidBodyInternal })}
|
|
123
|
-
</SceneGraphObject>
|
|
129
|
+
{@render children?.({ rigidBody: rigidBodyInternal })}
|
|
@@ -47,7 +47,7 @@ export const createRapierContext = (worldArgs, options) => {
|
|
|
47
47
|
};
|
|
48
48
|
const framerate = currentWritable(options.framerate ?? 'varying');
|
|
49
49
|
const simulationOffset = currentWritable(1);
|
|
50
|
-
const updateRigidBodySimulationData = currentWritable(
|
|
50
|
+
const updateRigidBodySimulationData = currentWritable(framerate.current === 'varying');
|
|
51
51
|
const { simulationStage, synchronizationStage } = createPhysicsStages(framerate, simulationOffset, updateRigidBodySimulationData, options);
|
|
52
52
|
const autostart = options.autoStart ?? true;
|
|
53
53
|
const paused = writable(!autostart);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/rapier",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.9",
|
|
4
4
|
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Components and hooks to use the Rapier physics engine in Threlte",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"type-fest": "^4.15.0",
|
|
32
32
|
"typescript": "^5.4.5",
|
|
33
33
|
"vite": "^5.2.8",
|
|
34
|
-
"@threlte/core": "8.0.0-next.
|
|
34
|
+
"@threlte/core": "8.0.0-next.17"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@dimforge/rapier3d-compat": ">=0.12",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const useHasEventListeners = () => {
|
|
2
|
-
// const component = get_current_component()
|
|
3
|
-
const hasEventListeners = (type) => {
|
|
4
|
-
// const callbacks = component.$$.callbacks
|
|
5
|
-
return true;
|
|
6
|
-
// return type in callbacks && (callbacks[type] as any[]).length > 0
|
|
7
|
-
};
|
|
8
|
-
return {
|
|
9
|
-
hasEventListeners
|
|
10
|
-
};
|
|
11
|
-
};
|