@threlte/rapier 0.0.1

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.
Files changed (56) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +19 -0
  3. package/dist/CHANGELOG.md +103 -0
  4. package/dist/LICENSE.md +21 -0
  5. package/dist/README.md +19 -0
  6. package/dist/components/Colliders/AutoColliders.svelte +74 -0
  7. package/dist/components/Colliders/AutoColliders.svelte.d.ts +33 -0
  8. package/dist/components/Colliders/Collider.svelte +119 -0
  9. package/dist/components/Colliders/Collider.svelte.d.ts +32 -0
  10. package/dist/components/CollisionGroups/CollisionGroups.svelte +31 -0
  11. package/dist/components/CollisionGroups/CollisionGroups.svelte.d.ts +21 -0
  12. package/dist/components/Debug/Debug.svelte +30 -0
  13. package/dist/components/Debug/Debug.svelte.d.ts +60 -0
  14. package/dist/components/RigidBody/RigidBody.svelte +111 -0
  15. package/dist/components/RigidBody/RigidBody.svelte.d.ts +39 -0
  16. package/dist/components/World/InnerWorld.svelte +32 -0
  17. package/dist/components/World/InnerWorld.svelte.d.ts +32 -0
  18. package/dist/components/World/World.svelte +63 -0
  19. package/dist/components/World/World.svelte.d.ts +33 -0
  20. package/dist/hooks/useCollisionGroups.d.ts +5 -0
  21. package/dist/hooks/useCollisionGroups.js +52 -0
  22. package/dist/hooks/useFrameHandler.d.ts +2 -0
  23. package/dist/hooks/useFrameHandler.js +176 -0
  24. package/dist/hooks/useRapier.d.ts +2 -0
  25. package/dist/hooks/useRapier.js +4 -0
  26. package/dist/hooks/useRigidBody.d.ts +2 -0
  27. package/dist/hooks/useRigidBody.js +4 -0
  28. package/dist/index.d.ts +12 -0
  29. package/dist/index.js +13 -0
  30. package/dist/lib/applyTransforms.d.ts +3 -0
  31. package/dist/lib/applyTransforms.js +17 -0
  32. package/dist/lib/createCollidersFromChildren.d.ts +16 -0
  33. package/dist/lib/createCollidersFromChildren.js +94 -0
  34. package/dist/lib/createRapierContext.d.ts +16 -0
  35. package/dist/lib/createRapierContext.js +56 -0
  36. package/dist/lib/getWorldTransforms.d.ts +41 -0
  37. package/dist/lib/getWorldTransforms.js +55 -0
  38. package/dist/lib/parseRigidBodyType.d.ts +3 -0
  39. package/dist/lib/parseRigidBodyType.js +10 -0
  40. package/dist/lib/positionToVector3.d.ts +3 -0
  41. package/dist/lib/positionToVector3.js +8 -0
  42. package/dist/lib/rotationToEuler.d.ts +3 -0
  43. package/dist/lib/rotationToEuler.js +8 -0
  44. package/dist/lib/rotationToQuaternion.d.ts +3 -0
  45. package/dist/lib/rotationToQuaternion.js +10 -0
  46. package/dist/lib/scaleColliderArgs.d.ts +5 -0
  47. package/dist/lib/scaleColliderArgs.js +25 -0
  48. package/dist/lib/scaleToVector3.d.ts +3 -0
  49. package/dist/lib/scaleToVector3.js +16 -0
  50. package/dist/recipes/BasicPlayerController.svelte +129 -0
  51. package/dist/recipes/BasicPlayerController.svelte.d.ts +29 -0
  52. package/dist/types/components.d.ts +131 -0
  53. package/dist/types/components.js +1 -0
  54. package/dist/types/types.d.ts +38 -0
  55. package/dist/types/types.js +1 -0
  56. package/package.json +50 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Grischa Erbe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ ![Threlte Logo](https://user-images.githubusercontent.com/46897060/178455971-434f4c5d-6c26-4d34-acdc-b4b50e2a8a2c.png)
2
+
3
+ <h1 align="center">@threlte/rapier</h1>
4
+
5
+ Provides easy to use components and hooks to use the [rapier](https://rapier.rs/) physics engine in threlte.
6
+
7
+ ## Official Documentation
8
+
9
+ Visit [threlte.xyz](https://threlte.xyz)
10
+
11
+ ## Support
12
+
13
+ Join the [Discord server](https://discord.gg/EqUBCfCaGm)
14
+
15
+ ---
16
+
17
+ ### License
18
+
19
+ The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
@@ -0,0 +1,103 @@
1
+ # @threlte/extras
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 7a3fa6b: # NEW PACKAGE: @threlte/rapier
8
+
9
+ This package provides easy to use components and hooks to use the [rapier](https://rapier.rs/) physics engine in threlte.
10
+
11
+ It comes with several components to get you started: [`<World>`](https://threlte.xyz/rapier/world), [`<RigidBody>`](https://threlte.xyz/rapier/rigid-body), [`<Collider>`](https://threlte.xyz/rapier/collider), [`<AutoColliders>`](https://threlte.xyz/rapier/auto-colliders), [`<CollisionGroups>`](https://threlte.xyz/rapier/collision-groups) and [`<Debug>`](https://threlte.xyz/rapier/debug).
12
+
13
+ It also features several handy hooks: [`<useRapier>`](https://threlte.xyz/rapier/use-rapier), [`<useCollisionGroups>`](https://threlte.xyz/rapier/use-collision-groups) and [`<useRigidBody>`](https://threlte.xyz/rapier/use-rigid-body).
14
+
15
+ ## 4.0.0
16
+
17
+ ### Major Changes
18
+
19
+ - 52e021c: # Breaking Change
20
+
21
+ The threlte repository has been moved to its own GitHub Organization: [https://github.com/threlte/threlte](https://github.com/threlte/threlte).
22
+ threlte consists now of two npm packages: `@threlte/core` and `@threlte/extras`, managed in a mono repository:
23
+
24
+ `@threlte/core` consists of components, hooks and other utilites that follow three.js principles, nomenclature and inheritance as closely as useful and possible. Therefore components that have been part of the package `threlte` have been moved to the new home of all kinds of useful abstractons: `@threlte/extras`.
25
+
26
+ `@threlte/extras` consists of useful abstractions and helpers that you may find yourself use all the time. These components do not need to follow three.js principles as strict as exports from `@threlte/core`, but they do where it makes sense.
27
+
28
+ ## The breaking changes in detail:
29
+
30
+ - Moved `<GLTF>` component as well as `useGltf` hook to `@threlte/extras`.
31
+ - Moved `<Text>` component to `@threlte/extras`.
32
+
33
+ ## How to update
34
+
35
+ Replace imports from `threlte` and `threlte/extras`:
36
+
37
+ 1. `npm rm threlte`
38
+ 2. `npm i -D @threlte/core @threlte/extras`
39
+ 3. Replace `import {…} from 'threlte'` with `import {…} from '@threlte/core'`
40
+ 4. Replace `import {…} from 'threlte/extras'` with `import {…} from '@threlte/extras'`
41
+
42
+ Specifically replace imports of `<GLTF>`, `useGltf` or `<Text>`:
43
+
44
+ 3. Replace `import { GLTF, useGltf, Text } from 'threlte'` with `import { GLTF, useGltf, Text } from '@threlte/extras'`
45
+
46
+ # Other changes
47
+
48
+ - The documentation is now hosted on Vercel and as such we are hoping for a Vercel Sponsorship for OSS. There have also been some style fixes and overhauls.
49
+
50
+ ## 3.13.10
51
+
52
+ ### Patch Changes
53
+
54
+ - 4de7371: added svelte identifier
55
+
56
+ ## 3.13.9
57
+
58
+ ### Patch Changes
59
+
60
+ - 41cc5a1: test
61
+
62
+ ## 3.13.8
63
+
64
+ ### Patch Changes
65
+
66
+ - 79a64f5: test
67
+
68
+ ## 3.13.7
69
+
70
+ ### Patch Changes
71
+
72
+ - test
73
+
74
+ ## 3.13.6
75
+
76
+ ### Patch Changes
77
+
78
+ - trying to delete
79
+
80
+ ## 3.13.5
81
+
82
+ ### Patch Changes
83
+
84
+ - 11aa5eb: yes
85
+
86
+ ## 3.13.4
87
+
88
+ ### Patch Changes
89
+
90
+ - 0c40456: added scripts to clean up packages
91
+ - 7cc4e5d: added node types
92
+
93
+ ## 3.13.3
94
+
95
+ ### Patch Changes
96
+
97
+ - a2a6d93: test
98
+
99
+ ## 3.13.2
100
+
101
+ ### Patch Changes
102
+
103
+ - 8dbf8cd: Test
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Grischa Erbe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/README.md ADDED
@@ -0,0 +1,19 @@
1
+ ![Threlte Logo](https://user-images.githubusercontent.com/46897060/178455971-434f4c5d-6c26-4d34-acdc-b4b50e2a8a2c.png)
2
+
3
+ <h1 align="center">@threlte/rapier</h1>
4
+
5
+ Provides easy to use components and hooks to use the [rapier](https://rapier.rs/) physics engine in threlte.
6
+
7
+ ## Official Documentation
8
+
9
+ Visit [threlte.xyz](https://threlte.xyz)
10
+
11
+ ## Support
12
+
13
+ Join the [Discord server](https://discord.gg/EqUBCfCaGm)
14
+
15
+ ---
16
+
17
+ ### License
18
+
19
+ The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
@@ -0,0 +1,74 @@
1
+ <script>import { ActiveCollisionTypes, ActiveEvents, CoefficientCombineRule } from '@dimforge/rapier3d-compat';
2
+ import { SceneGraphObject } from '@threlte/core';
3
+ import { createEventDispatcher, onDestroy, onMount } from 'svelte';
4
+ import { Object3D, Vector3 } from 'three';
5
+ import { useCollisionGroups } from '../../hooks/useCollisionGroups';
6
+ import { useRapier } from '../../hooks/useRapier';
7
+ import { useRigidBody } from '../../hooks/useRigidBody';
8
+ import { applyTransforms } from '../../lib/applyTransforms';
9
+ import { createCollidersFromChildren } from '../../lib/createCollidersFromChildren';
10
+ import { positionToVector3 } from '../../lib/positionToVector3';
11
+ export let shape = 'convexHull';
12
+ export let position = undefined;
13
+ export let rotation = undefined;
14
+ export let scale = undefined;
15
+ export let lookAt = undefined;
16
+ export let mass = undefined;
17
+ export let centerOfMass = undefined;
18
+ export let principalAngularInertia = undefined;
19
+ export let restitution = undefined;
20
+ export let restitutionCombineRule = undefined;
21
+ export let friction = undefined;
22
+ export let frictionCombineRule = undefined;
23
+ export let sensor = undefined;
24
+ const object = new Object3D();
25
+ /**
26
+ * Immediately apply transforms
27
+ */
28
+ applyTransforms(object, position, rotation, scale, lookAt);
29
+ object.updateWorldMatrix(true, false);
30
+ const rigidBody = useRigidBody();
31
+ const { world, addColliderToContext, removeColliderFromContext } = useRapier();
32
+ export let colliders = [];
33
+ const collisionGroups = useCollisionGroups();
34
+ const dispatcher = createEventDispatcher();
35
+ onMount(() => {
36
+ colliders = createCollidersFromChildren(object, shape, world, rigidBody);
37
+ colliders.forEach((c) => addColliderToContext(c, object, dispatcher));
38
+ collisionGroups.registerColliders(colliders);
39
+ });
40
+ $: {
41
+ if (colliders.length > 0) {
42
+ colliders.forEach((collider) => {
43
+ collider.setActiveEvents(ActiveEvents.COLLISION_EVENTS);
44
+ collider.setActiveCollisionTypes(ActiveCollisionTypes.ALL);
45
+ collider.setRestitution(restitution ?? 0);
46
+ collider.setRestitutionCombineRule(restitutionCombineRule ?? CoefficientCombineRule.Average);
47
+ collider.setFriction(friction ?? 0.7);
48
+ collider.setFrictionCombineRule(frictionCombineRule ?? CoefficientCombineRule.Average);
49
+ collider.setSensor(sensor ?? false);
50
+ const { x: cmx, y: cmy, z: cmz } = positionToVector3(centerOfMass) || new Vector3();
51
+ const { x: pix, y: piy, z: piz } = positionToVector3(principalAngularInertia) ||
52
+ new Vector3(mass ?? 1 * 0.2, mass ?? 1 * 0.2, mass ?? 1 * 0.2);
53
+ if (mass || centerOfMass || principalAngularInertia) {
54
+ collider.setDensity(0);
55
+ collider.setMassProperties(mass ?? 1, { x: cmx, y: cmy, z: cmz }, { x: pix, y: piy, z: piz }, { x: 0, y: 0, z: 0, w: 1 });
56
+ }
57
+ });
58
+ }
59
+ }
60
+ /**
61
+ * Cleanup
62
+ */
63
+ onDestroy(() => {
64
+ collisionGroups.removeColliders(colliders);
65
+ colliders.forEach((c) => {
66
+ removeColliderFromContext(c);
67
+ world.removeCollider(c, true);
68
+ });
69
+ });
70
+ </script>
71
+
72
+ <SceneGraphObject {object}>
73
+ <slot />
74
+ </SceneGraphObject>
@@ -0,0 +1,33 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import { type Collider } from '@dimforge/rapier3d-compat';
3
+ import type { AutoCollidersProperties } from '../../types/components';
4
+ import type { ColliderEventMap } from '../../types/types';
5
+ declare const __propDef: {
6
+ props: {
7
+ shape?: import("../../types/types").AutoCollidersShapes | undefined;
8
+ position?: AutoCollidersProperties['position'];
9
+ rotation?: AutoCollidersProperties['rotation'];
10
+ scale?: AutoCollidersProperties['scale'];
11
+ lookAt?: AutoCollidersProperties['lookAt'];
12
+ mass?: AutoCollidersProperties['mass'];
13
+ centerOfMass?: AutoCollidersProperties['centerOfMass'];
14
+ principalAngularInertia?: AutoCollidersProperties['principalAngularInertia'];
15
+ restitution?: AutoCollidersProperties['restitution'];
16
+ restitutionCombineRule?: AutoCollidersProperties['restitutionCombineRule'];
17
+ friction?: AutoCollidersProperties['friction'];
18
+ frictionCombineRule?: AutoCollidersProperties['frictionCombineRule'];
19
+ sensor?: AutoCollidersProperties['sensor'];
20
+ colliders?: Collider[] | undefined;
21
+ };
22
+ slots: {
23
+ default: {};
24
+ };
25
+ getters: {};
26
+ events: ColliderEventMap;
27
+ };
28
+ export declare type AutoCollidersProps = typeof __propDef.props;
29
+ export declare type AutoCollidersEvents = typeof __propDef.events;
30
+ export declare type AutoCollidersSlots = typeof __propDef.slots;
31
+ export default class AutoColliders extends SvelteComponentTyped<AutoCollidersProps, AutoCollidersEvents, AutoCollidersSlots> {
32
+ }
33
+ export {};
@@ -0,0 +1,119 @@
1
+ <script>import { ActiveCollisionTypes, ActiveEvents, CoefficientCombineRule, Collider, ColliderDesc } from '@dimforge/rapier3d-compat';
2
+ import { SceneGraphObject, TransformableObject, useFrame } from '@threlte/core';
3
+ import { createEventDispatcher, onDestroy, onMount } from 'svelte';
4
+ import { Object3D, Quaternion, Vector3 } from 'three';
5
+ import { useCollisionGroups } from '../../hooks/useCollisionGroups';
6
+ import { useRapier } from '../../hooks/useRapier';
7
+ import { useRigidBody } from '../../hooks/useRigidBody';
8
+ import { applyTransforms } from '../../lib/applyTransforms';
9
+ import { getWorldPosition, getWorldQuaternion } from '../../lib/getWorldTransforms';
10
+ import { positionToVector3 } from '../../lib/positionToVector3';
11
+ import { scaleColliderArgs } from '../../lib/scaleColliderArgs';
12
+ export let shape;
13
+ export let args;
14
+ export let position = undefined;
15
+ export let rotation = undefined;
16
+ export let scale = undefined;
17
+ export let lookAt = undefined;
18
+ export let mass = undefined;
19
+ export let centerOfMass = undefined;
20
+ export let principalAngularInertia = undefined;
21
+ export let restitution = undefined;
22
+ export let restitutionCombineRule = undefined;
23
+ export let friction = undefined;
24
+ export let frictionCombineRule = undefined;
25
+ export let sensor = undefined;
26
+ const object = new Object3D();
27
+ /**
28
+ * Immediately apply transforms
29
+ */
30
+ applyTransforms(object, position, rotation, scale, lookAt);
31
+ object.updateWorldMatrix(true, false);
32
+ const rigidBody = useRigidBody();
33
+ const isAttached = !!rigidBody;
34
+ const rapierContext = useRapier();
35
+ const { world } = rapierContext;
36
+ export let collider = undefined;
37
+ const collisionGroups = useCollisionGroups();
38
+ const dispatcher = createEventDispatcher();
39
+ /**
40
+ * Actual collider setup happens onMount as only then
41
+ * the transforms are finished.
42
+ */
43
+ onMount(() => {
44
+ const scale = object.getWorldScale(new Vector3());
45
+ const scaledArgs = scaleColliderArgs(shape, args, scale);
46
+ // @ts-ignore
47
+ const colliderDesc = ColliderDesc[shape](...scaledArgs);
48
+ collider = world.createCollider(colliderDesc, rigidBody);
49
+ /**
50
+ * Add collider to context
51
+ */
52
+ rapierContext.addColliderToContext(collider, object, dispatcher);
53
+ /**
54
+ * For use in conjunction with component <CollisionGroups>
55
+ */
56
+ collisionGroups.registerColliders([collider]);
57
+ if (isAttached) {
58
+ const rigidBodyWorldPos = new Vector3();
59
+ const rigidBodyWorldQuatInversed = new Quaternion();
60
+ object.traverseAncestors((child) => {
61
+ if (child.userData.isRigidBody) {
62
+ child.getWorldPosition(rigidBodyWorldPos);
63
+ child.getWorldQuaternion(rigidBodyWorldQuatInversed);
64
+ rigidBodyWorldQuatInversed.invert();
65
+ }
66
+ });
67
+ collider.setTranslationWrtParent(object.getWorldPosition(new Vector3()).sub(rigidBodyWorldPos));
68
+ collider.setRotationWrtParent(object.getWorldQuaternion(new Quaternion()).premultiply(rigidBodyWorldQuatInversed));
69
+ }
70
+ else {
71
+ collider.setTranslation(object.getWorldPosition(new Vector3()));
72
+ collider.setRotation(object.getWorldQuaternion(new Quaternion()));
73
+ }
74
+ });
75
+ $: {
76
+ if (collider) {
77
+ collider.setActiveEvents(ActiveEvents.COLLISION_EVENTS);
78
+ collider.setActiveCollisionTypes(ActiveCollisionTypes.ALL);
79
+ collider.setRestitution(restitution ?? 0);
80
+ collider.setRestitutionCombineRule(restitutionCombineRule ?? CoefficientCombineRule.Average);
81
+ collider.setFriction(friction ?? 0.7);
82
+ collider.setFrictionCombineRule(frictionCombineRule ?? CoefficientCombineRule.Average);
83
+ collider.setSensor(sensor ?? false);
84
+ const { x: cmx, y: cmy, z: cmz } = positionToVector3(centerOfMass) || new Vector3();
85
+ const { x: pix, y: piy, z: piz } = positionToVector3(principalAngularInertia) ||
86
+ new Vector3(mass ?? 1 * 0.2, mass ?? 1 * 0.2, mass ?? 1 * 0.2);
87
+ if (mass || centerOfMass || principalAngularInertia) {
88
+ collider.setDensity(0);
89
+ collider.setMassProperties(mass ?? 1, { x: cmx, y: cmy, z: cmz }, { x: pix, y: piy, z: piz }, { x: 0, y: 0, z: 0, w: 1 });
90
+ }
91
+ }
92
+ }
93
+ useFrame(() => {
94
+ if (!collider)
95
+ return;
96
+ collider.setTranslation(getWorldPosition(object));
97
+ collider.setRotation(getWorldQuaternion(object));
98
+ }, {
99
+ autostart: !isAttached
100
+ });
101
+ /**
102
+ * Cleanup
103
+ */
104
+ onDestroy(() => {
105
+ if (!collider)
106
+ return;
107
+ rapierContext.removeColliderFromContext(collider);
108
+ collisionGroups.removeColliders([collider]);
109
+ world.removeCollider(collider, true);
110
+ });
111
+ </script>
112
+
113
+ <SceneGraphObject {object}>
114
+ <slot />
115
+ </SceneGraphObject>
116
+
117
+ {#if !isAttached}
118
+ <TransformableObject {object} {position} {rotation} {scale} />
119
+ {/if}
@@ -0,0 +1,32 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import { CoefficientCombineRule, Collider, ColliderDesc } from '@dimforge/rapier3d-compat';
3
+ import type { ColliderEventMap } from '../../types/types';
4
+ declare class __sveltets_Render<Shape extends 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh', Args extends Parameters<typeof ColliderDesc[Shape]>> {
5
+ props(): {
6
+ shape: Shape;
7
+ args: Args;
8
+ position?: import("@threlte/core").Position | undefined;
9
+ rotation?: import("@threlte/core").Rotation | undefined;
10
+ scale?: import("@threlte/core").Scale | undefined;
11
+ lookAt?: import("@threlte/core").LookAt | undefined;
12
+ mass?: number | undefined;
13
+ centerOfMass?: import("@threlte/core").Position | undefined;
14
+ principalAngularInertia?: import("@threlte/core").Position | undefined;
15
+ restitution?: number | undefined;
16
+ restitutionCombineRule?: CoefficientCombineRule | undefined;
17
+ friction?: number | undefined;
18
+ frictionCombineRule?: CoefficientCombineRule | undefined;
19
+ sensor?: boolean | undefined;
20
+ collider?: Collider | undefined;
21
+ };
22
+ events(): ColliderEventMap;
23
+ slots(): {
24
+ default: {};
25
+ };
26
+ }
27
+ export declare type ColliderProps<Shape extends 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh', Args extends Parameters<typeof ColliderDesc[Shape]>> = ReturnType<__sveltets_Render<Shape, Args>['props']>;
28
+ export declare type ColliderEvents<Shape extends 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh', Args extends Parameters<typeof ColliderDesc[Shape]>> = ReturnType<__sveltets_Render<Shape, Args>['events']>;
29
+ export declare type ColliderSlots<Shape extends 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh', Args extends Parameters<typeof ColliderDesc[Shape]>> = ReturnType<__sveltets_Render<Shape, Args>['slots']>;
30
+ export default class Collider<Shape extends 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh', Args extends Parameters<typeof ColliderDesc[Shape]>> extends SvelteComponentTyped<ColliderProps<Shape, Args>, ColliderEvents<Shape, Args>, ColliderSlots<Shape, Args>> {
31
+ }
32
+ export {};
@@ -0,0 +1,31 @@
1
+ <script>import { setContext } from 'svelte';
2
+ import { writable } from 'svelte/store';
3
+ export let groups = undefined;
4
+ export let filter = undefined;
5
+ export let memberships = undefined;
6
+ const computeBitMask = (groups, filter, memberships) => {
7
+ if (groups !== undefined) {
8
+ // groups is setting the filter and memberships at once
9
+ const g = groups;
10
+ const mask = g.reduce((acc, f) => {
11
+ return acc | (1 << f);
12
+ }, 0) |
13
+ g.reduce((acc, m) => {
14
+ return acc | (1 << (m + 16));
15
+ }, 0);
16
+ return mask;
17
+ }
18
+ const mask = memberships.reduce((acc, f) => {
19
+ return acc | (1 << f);
20
+ }, 0) |
21
+ filter.reduce((acc, m) => {
22
+ return acc | (1 << (m + 16));
23
+ }, 0);
24
+ return mask;
25
+ };
26
+ const store = writable(computeBitMask(groups, filter, memberships));
27
+ $: store.set(computeBitMask(groups, filter, memberships));
28
+ setContext('threlte-rapier-collision-group', store);
29
+ </script>
30
+
31
+ <slot />
@@ -0,0 +1,21 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare class __sveltets_Render<Groups extends (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] | undefined, MembershipsAndFilter extends Groups extends undefined ? (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] : undefined> {
3
+ props(): {
4
+ groups: Groups;
5
+ } | {
6
+ filter: MembershipsAndFilter;
7
+ memberships: MembershipsAndFilter;
8
+ };
9
+ events(): {} & {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots(): {
13
+ default: {};
14
+ };
15
+ }
16
+ export declare type CollisionGroupsProps<Groups extends (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] | undefined, MembershipsAndFilter extends Groups extends undefined ? (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] : undefined> = ReturnType<__sveltets_Render<Groups, MembershipsAndFilter>['props']>;
17
+ export declare type CollisionGroupsEvents<Groups extends (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] | undefined, MembershipsAndFilter extends Groups extends undefined ? (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] : undefined> = ReturnType<__sveltets_Render<Groups, MembershipsAndFilter>['events']>;
18
+ export declare type CollisionGroupsSlots<Groups extends (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] | undefined, MembershipsAndFilter extends Groups extends undefined ? (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] : undefined> = ReturnType<__sveltets_Render<Groups, MembershipsAndFilter>['slots']>;
19
+ export default class CollisionGroups<Groups extends (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] | undefined, MembershipsAndFilter extends Groups extends undefined ? (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15)[] : undefined> extends SvelteComponentTyped<CollisionGroupsProps<Groups, MembershipsAndFilter>, CollisionGroupsEvents<Groups, MembershipsAndFilter>, CollisionGroupsSlots<Groups, MembershipsAndFilter>> {
20
+ }
21
+ export {};
@@ -0,0 +1,30 @@
1
+ <script>import { LineSegments, useFrame } from '@threlte/core';
2
+ import { onDestroy } from 'svelte';
3
+ import { BufferAttribute, BufferGeometry, LineBasicMaterial } from 'three';
4
+ import { useRapier } from '../../hooks/useRapier';
5
+ export let vertexColors = true;
6
+ const material = new LineBasicMaterial({
7
+ vertexColors,
8
+ ...$$props
9
+ });
10
+ const { world } = useRapier();
11
+ const buffers = world.debugRender();
12
+ const vertices = new BufferAttribute(buffers.vertices, 3);
13
+ const colors = new BufferAttribute(buffers.colors, 4);
14
+ const geometry = new BufferGeometry();
15
+ geometry.setAttribute('position', vertices);
16
+ geometry.setAttribute('color', colors);
17
+ useFrame(() => {
18
+ const buffers = world.debugRender();
19
+ const vertices = new BufferAttribute(buffers.vertices, 3);
20
+ const colors = new BufferAttribute(buffers.colors, 4);
21
+ geometry.setAttribute('position', vertices);
22
+ geometry.setAttribute('color', colors);
23
+ });
24
+ onDestroy(() => {
25
+ geometry.dispose();
26
+ material.dispose();
27
+ });
28
+ </script>
29
+
30
+ <LineSegments renderOrder={Infinity} {geometry} {material} />
@@ -0,0 +1,60 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ color?: import("three").ColorRepresentation | undefined;
5
+ linewidth?: number | undefined;
6
+ linecap?: string | undefined;
7
+ linejoin?: string | undefined;
8
+ alphaTest?: number | undefined;
9
+ alphaToCoverage?: boolean | undefined;
10
+ blendDst?: import("three").BlendingDstFactor | undefined;
11
+ blendDstAlpha?: number | undefined;
12
+ blendEquation?: import("three").BlendingEquation | undefined;
13
+ blendEquationAlpha?: number | undefined;
14
+ blending?: import("three").Blending | undefined;
15
+ blendSrc?: import("three").BlendingDstFactor | import("three").BlendingSrcFactor | undefined;
16
+ blendSrcAlpha?: number | undefined;
17
+ clipIntersection?: boolean | undefined;
18
+ clippingPlanes?: import("three").Plane[] | undefined;
19
+ clipShadows?: boolean | undefined;
20
+ colorWrite?: boolean | undefined;
21
+ defines?: any;
22
+ depthFunc?: import("three").DepthModes | undefined;
23
+ depthTest?: boolean | undefined;
24
+ depthWrite?: boolean | undefined;
25
+ name?: string | undefined;
26
+ opacity?: number | undefined;
27
+ polygonOffset?: boolean | undefined;
28
+ polygonOffsetFactor?: number | undefined;
29
+ polygonOffsetUnits?: number | undefined;
30
+ precision?: "highp" | "mediump" | "lowp" | null | undefined;
31
+ premultipliedAlpha?: boolean | undefined;
32
+ dithering?: boolean | undefined;
33
+ side?: import("three").Side | undefined;
34
+ shadowSide?: import("three").Side | undefined;
35
+ toneMapped?: boolean | undefined;
36
+ transparent?: boolean | undefined;
37
+ vertexColors?: boolean | undefined;
38
+ visible?: boolean | undefined;
39
+ format?: import("three").PixelFormat | undefined;
40
+ stencilWrite?: boolean | undefined;
41
+ stencilFunc?: import("three").StencilFunc | undefined;
42
+ stencilRef?: number | undefined;
43
+ stencilWriteMask?: number | undefined;
44
+ stencilFuncMask?: number | undefined;
45
+ stencilFail?: import("three").StencilOp | undefined;
46
+ stencilZFail?: import("three").StencilOp | undefined;
47
+ stencilZPass?: import("three").StencilOp | undefined;
48
+ userData?: any;
49
+ };
50
+ events: {
51
+ [evt: string]: CustomEvent<any>;
52
+ };
53
+ slots: {};
54
+ };
55
+ export declare type DebugProps = typeof __propDef.props;
56
+ export declare type DebugEvents = typeof __propDef.events;
57
+ export declare type DebugSlots = typeof __propDef.slots;
58
+ export default class Debug extends SvelteComponentTyped<DebugProps, DebugEvents, DebugSlots> {
59
+ }
60
+ export {};